IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Regarding using array in subprogram


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
pradeep_singhm

New User


Joined: 01 Oct 2005
Posts: 9
Location: bangalore

PostPosted: Wed Nov 16, 2005 1:54 pm
Reply with quote

hi
friends

help me this is one of my interview questions

i have main program and subprogram ,
from main program
i am passing array to subprogram which has been declared with index.

so in subprogram how do you access the array which has the index

thanks in advance

regards
pradeep singh
Back to top
View user's profile Send private message
veenag_gopal

New User


Joined: 14 Nov 2005
Posts: 14
Location: India

PostPosted: Wed Nov 16, 2005 3:52 pm
Reply with quote

You can access the values of the array using the index in the sub program.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Wed Nov 16, 2005 11:43 pm
Reply with quote

Or. if performance isn't an issue, you can use a subscript.
Back to top
View user's profile Send private message
shammiullah

New User


Joined: 13 Jun 2005
Posts: 24

PostPosted: Thu Nov 17, 2005 12:21 am
Reply with quote

HI,
DO U GUYZ MEAN TO SAY THAT V CAN PASS THE INDEX VARIABLE ALONG WITH THE ARRAY FROM MAIN PROGRAM TO SUB PROGRAM.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Thu Nov 17, 2005 1:51 am
Reply with quote

I'm not sure about the index since it is part of the declaration of the table where a subscript is not.

Indexes are not like normal. everyday data items. We know you can't MOVE them or DISPLAY them. God knows what other restrictions there are. But, as they say, the system is the final arbiter of what will work or not.

If the test fails you still have the subscript approach to fall back on.
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Thu Dec 29, 2005 11:21 am
Reply with quote

Hi,

It's not possible to pass an index via linkage. The index is not part of the calling programs working storage.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Dec 31, 2005 11:06 pm
Reply with quote

Another approach would be to define a clone tbl in the sub's WS using an index, then pass the tbl to the sub from the main and move it to the clone tbl and use the index defined in the sub.
Back to top
View user's profile Send private message
ANIKET

New User


Joined: 28 Apr 2005
Posts: 11
Location: PUNE

PostPosted: Tue Jan 03, 2006 10:39 am
Reply with quote

Hi All,

You can access the array and its index in your subprogram by setting the address. You have to declare this array in linkage section of both main (calling) program and sub (called) program. In main program set the address of this array to one pointer and call the subprogram using this pointer. Now in your subprogram set the address stored in this pointer to pointer of array. Now you can access the data stored in array. You can also change the value stored in this index.
This is somewhat complicated but with performance in view, it is best way to access any data from one program to other without actual data transfer.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Fri Jan 06, 2006 6:24 am
Reply with quote

"Passing" data "to" a subpgm NEVER transferes the data. It always stays in the CALLer's module. It provides a pointer to the data by just following the rules for CALLing subs and using "USING" in the CALL and the PROC DIV stmt and coding the Linkage Section.

The problem w/"passing arrays" is the INDEX. You can't pass an INDEX as stated earlier.

If you're hell bent on using an INDEX for the passed arrray you can define a clone array in the sub w/an INDEX, then move the passed array to the clone array and use the INDEX to your heart's content. When finished move the array back and overlay the passed array (that is, if you changed it) and return to CALLer.

Personally, if the array access is not substantial I would use a subscript in the subpgm; it's simpler.

Remember the CALLer can still use an INDEX.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts How to go into a subprogram in IBM De... IBM Tools 5
No new posts COBOL Ascending and descending sort n... COBOL Programming 5
No new posts To find an array of words (sys-symbol... JCL & VSAM 9
No new posts How to move values from single dimens... COBOL Programming 1
No new posts array indexing PL/I & Assembler 4
Search our Forums:

Back to Top