MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to pass the Indexes to the SUB-PROGRAM ?

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
hisabarish
Beginner


Joined: 21 Jun 2005
Posts: 38
Topics: 11

PostPosted: Fri Jun 24, 2005 5:33 am    Post subject: How to pass the Indexes to the SUB-PROGRAM ? Reply with quote

I have a Main program which it is calling other sub-program. In the main program I am using occurs clause with Indexes. Now how to I pass the Indexes to the called program ie., sub-program.

In other words,

01 Tableitem.
02 eno pic 99 occurs 20 times indexed by I .

Now How to pass the data item eno and the index variable to the sub program
Pls. Revert me.
_________________
Sabari
Madras
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Fri Jun 24, 2005 9:24 am    Post subject: Reply with quote

Hisabarish,

Is this what you are looking for?

Mainpgm :

Code:

IDENTIFICATION DIVISION.                           
PROGRAM-ID.    MAIN.                               
ENVIRONMENT DIVISION.                               
DATA DIVISION.                                     
WORKING-STORAGE SECTION.                           
                                                   
01 TABLEITEM.                                       
   02 ENO PIC 99 OCCURS 20 TIMES INDEXED BY I.     
                                                   
01 W-VALUE  PIC 99 VALUE 01.                       
01 W-PGM    PIC X(08) VALUE 'PASSINDX'.             
                                                   
PROCEDURE DIVISION.                                 
                                                   
     PERFORM  VARYING  I FROM 1 BY 1 UNTIL I > 20   
        MOVE W-VALUE TO ENO(I)                     
        ADD +1 TO W-VALUE                           
     END-PERFORM                                   
                                                   
     CALL W-PGM  USING TABLEITEM                   
                                                   
     GOBACK.                                       



Subprogram:

Code:

IDENTIFICATION DIVISION.                         
PROGRAM-ID.    PASSINDX.                         
ENVIRONMENT DIVISION.                             
DATA DIVISION.                                   
                                                 
LINKAGE SECTION.                                 
01 TABLEITEM.                                     
   02 ENO PIC 99 OCCURS 20 TIMES INDEXED BY I.   
                                                 
PROCEDURE DIVISION USING TABLEITEM.
             
     PERFORM  VARYING  I FROM 1 BY 1 UNTIL I > 20
        DISPLAY ENO(I)                           
     END-PERFORM                                 

     GOBACK.                                     


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
hisabarish
Beginner


Joined: 21 Jun 2005
Posts: 38
Topics: 11

PostPosted: Sat Jun 25, 2005 2:20 am    Post subject: Reply with quote

Dear Kolusu,

Thankx for your answer. But i am expecting,

IDENTIFICATION DIVISION.
PROGRAM-ID. MAIN.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.

01 TABLEITEM.
02 ENO PIC 99 OCCURS 20 TIMES INDEXED BY I.

01 W-VALUE PIC 99 VALUE 01.
01 W-PGM PIC X( 08 ) VALUE 'PASSINDX'.

PROCEDURE DIVISION.

PERFORM VARYING I FROM 1 BY 1 UNTIL I > 10
MOVE W-VALUE TO ENO(I)
ADD +1 TO W-VALUE
END-PERFORM
DISPLAY
_________________
Sabari
Madras
Back to top
View user's profile Send private message
nadh
Intermediate


Joined: 08 Oct 2004
Posts: 192
Topics: 89

PostPosted: Wed Jun 29, 2005 4:27 am    Post subject: Reply with quote

Hi

you can code CALL W-PGM USING TABLEITEM INDEX-ITEM in main program.
In subprogram in linkage section you code

01 SUB-INDEX-ITEM USAGE IS INDEX.

this variable can receive the index value from the main program.

Hope this helps.

--------------------------
nadh
Back to top
View user's profile Send private message Send e-mail
dtf
Beginner


Joined: 10 Dec 2004
Posts: 110
Topics: 8
Location: Colorado USA

PostPosted: Wed Jun 29, 2005 2:39 pm    Post subject: Reply with quote

Nadh,

I really do not understand what you are saying. An INDEX cannot be passed. There are a couple of ways that you could pass the value of the index, however this is not going to allow you to manipulate an index that is defined in a main program from a sub program.

You can set the index to a data item, and pass this as a parameter. But again, this will not manipulate the index back in the main program.
________
iphone games


Last edited by dtf on Tue Feb 01, 2011 1:58 pm; edited 1 time in total
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Wed Jun 29, 2005 3:23 pm    Post subject: Reply with quote

Quote:

An INDEX cannot be passed.


dtf,

Hmm may be my intrepration is wrong , but you sure can pass an index. check this
Quote:

Direct references to an index data item can be made only in a SEARCH statement, a SET statement, a relation condition, the USING phrase of the Procedure Division header, or the USING phrase of the CALL or ENTRY statement.


The above is from

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/IGY3LR10/5.3.16.5?SHELF=&DT=20020920180651&CASE=

However I was never successful in passing the index

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dtf
Beginner


Joined: 10 Dec 2004
Posts: 110
Topics: 8
Location: Colorado USA

PostPosted: Thu Jun 30, 2005 10:28 am    Post subject: Reply with quote

Kolusu,

I read the link, and this is what I think........

I can define a variable and say "USAGE IS INDEX". I can pass this to a subroutine. However, this is not the same as

Code:

05  MY-TABLE-ITEMS       OCCURS 1000 INDEXED BY MTI-IDX. 


As far as I can tell and/or know, if I pass the table MY-TABLE-ITEMS, there is nothing that implies that I also get the setting of MTI-IDX passed to the subprogram. Also, I do not think that I can pass MTI-IDX as a parameter on my CALL statement.

In order for me to pass this, I'd have to use a SET statement, and set another variable (perhaps one whose USAGE IS INDEX) and then pass that. Upon entry to my subprogram and return to my main program, (assuming that I want my index to have that value), I would then have to set MTI-IDX to the value in that parameter.

Disclaimer: This is the way have always understood it to work. COBOL has changed a lot and I have not kept up with all of the nuances. I'd be very interested to know if the information I have provided is incorrect or incomplete.

Regards,
DTF
________
Mercedes-Benz M130 engine specifications
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group