View previous topic :: View next topic
|
Author |
Message |
pradeep_singhm
New User
Joined: 01 Oct 2005 Posts: 9 Location: bangalore
|
|
|
|
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 |
|
|
veenag_gopal
New User
Joined: 14 Nov 2005 Posts: 14 Location: India
|
|
|
|
You can access the values of the array using the index in the sub program. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Or. if performance isn't an issue, you can use a subscript. |
|
Back to top |
|
|
shammiullah
New User
Joined: 13 Jun 2005 Posts: 24
|
|
|
|
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 |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
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 |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
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 |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
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 |
|
|
ANIKET
New User
Joined: 28 Apr 2005 Posts: 11 Location: PUNE
|
|
|
|
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 |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
"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 |
|
|
|