Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Regarding using array in subprogram

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Regarding using array in subprogram
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    Post subject: Regarding using array in subprogram
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    Post subject:
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    Post subject:
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    Post subject:
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: 1187
Location: Bangalore,India

PostPosted: Thu Dec 29, 2005 11:21 am    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Dynamic array request/response contai... Suja.Sai CICS 2 Tue Jan 24, 2017 11:37 am
No new posts Is possible to call subprogram from c... cmsmoon COBOL Programming 3 Fri Aug 05, 2016 6:46 pm
No new posts Unstring list of values into an array. Roshnii COBOL Programming 8 Mon Jun 27, 2016 6:25 pm
No new posts COBOL Program to Read Array data raj4neo COBOL Programming 8 Sat Aug 15, 2015 12:28 am
No new posts Checking for High-Values in an array amitc23 COBOL Programming 10 Wed Aug 05, 2015 4:09 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us