View previous topic :: View next topic |
Author |
Message |
hisabarish Beginner
Joined: 21 Jun 2005 Posts: 38 Topics: 11
|
Posted: Fri Jun 24, 2005 5:33 am Post subject: How to pass the Indexes to the SUB-PROGRAM ? |
|
|
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 |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12372 Topics: 75 Location: San Jose
|
Posted: Fri Jun 24, 2005 9:24 am Post subject: |
|
|
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 |
|
|
hisabarish Beginner
Joined: 21 Jun 2005 Posts: 38 Topics: 11
|
Posted: Sat Jun 25, 2005 2:20 am Post subject: |
|
|
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 |
|
|
nadh Intermediate
Joined: 08 Oct 2004 Posts: 192 Topics: 89
|
Posted: Wed Jun 29, 2005 4:27 am Post subject: |
|
|
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 |
|
|
dtf Beginner
Joined: 10 Dec 2004 Posts: 110 Topics: 8 Location: Colorado USA
|
Posted: Wed Jun 29, 2005 2:39 pm Post subject: |
|
|
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 |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12372 Topics: 75 Location: San Jose
|
|
Back to top |
|
|
dtf Beginner
Joined: 10 Dec 2004 Posts: 110 Topics: 8 Location: Colorado USA
|
Posted: Thu Jun 30, 2005 10:28 am Post subject: |
|
|
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 |
|
|
|
|