View previous topic :: View next topic
|
Author |
Message |
himanshu_pant
New User
Joined: 08 Jul 2014 Posts: 14 Location: India
|
|
|
|
Hi,
I am facing an issue. I need to have a group level variable in my code which is not present in the copybook.
for e.g,
The copybook copy1, the field has been defined as:
Code: |
05 ws-ele1 pic x(15).
05 ws-ele2 pic 9(03).
05 ws-array-element occurs 99 times.
10 ws-array-ele1 pic x(03).
10 ws-array-ele2 pic 9(03).
05 ws-ele3 pic s9(4) comp. |
I need to have in my code as:
Code: |
05 ws-ele1 pic x(15).
05 ws-ele2 pic 9(03).
05 ws-array.
10 ws-array-element occurs 99 times.
15 ws-array-ele1 pic x(3).
15 ws-array-ele2 pic 9(3).
05 ws-ele3 pic s9(4) comp. |
Can this be done using cobol copy replacing as I don't want to perform the loop and copy the element in a working storage array variable unless that is the only option and if number of array element changes, I would have to make corresponding changes in my program as well ?
I tried this with copy replacing but its giving me compilation [/color]error:
Code: |
COPY COPY1
REPLACING
== 05 ws-array-element == BY
== 05 ws-array.==
10 ws-array-element ==. |
Please advise.
Code'd |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
No.
I dislike tables which are defined like that, but other than editing the copybook you're not going to get it to look different, and as you have mentioned, there are potential problems if you try to define it how you want elsewhere.
What is the particular problem that it causes you. |
|
Back to top |
|
|
himanshu_pant
New User
Joined: 08 Jul 2014 Posts: 14 Location: India
|
|
|
|
Thanks Bill.
Actually I need to pass the entire array group element, ws-array in this case, to a subprogram. So if there is no other way, I guess I would define a working storage variable in my cobol program for that and fill it with each and every occurence of ws-array-element and then pass to the subprogram.
Regards,
Himanshu Pant |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
If that is what you want, the answer is simple:
Code: |
CALL sub-program USING ... ws-array-element ( 1 ) |
The address of the start of ws-array-element ( 1 ) is the same as the address of the start of the table (because it is the start of the table).
How does the sub-program know how many items are in the table? |
|
Back to top |
|
|
himanshu_pant
New User
Joined: 08 Jul 2014 Posts: 14 Location: India
|
|
|
|
Thanks Bill.
It really resolved my query. I think I only needed to pass the address of the array element because in my subprogram I have the follwing code:
call subprogram using copy1
ws-array-element(1).
SET RECORD-ADD TO ADDRESS OF REC-BYTE (REC-IDX).
SET CALC-FIELD-ADD TO ADDRESS OF CALC-FLD.
PERFORM UNTIL RECORD-ADD EQUAL CALC-FIELD-ADD
SET REC-IDX UP BY PLUS-ONE
SET RECORD-ADD TO ADDRESS OF REC-BYTE (REC-IDX)
END-PERFORM.
This loop is performed until the first field recieved from main program is equal to address of second field recieved.
Thank you.
Regards. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
OK. Now I don't know what you are doing. I think you may be wasting a lot of CPU.
Can you post the definitions of everything used in that code snippet, including their locations (WORKING-STORAGE or LINKAGE) and explain what it is you want to do with that table in the sub-program.
I have a feeling you are greatly overcomplicating a simple task. |
|
Back to top |
|
|
chrakesh
New User
Joined: 03 May 2010 Posts: 16 Location: india
|
|
|
|
Good. |
|
Back to top |
|
|
|