View previous topic :: View next topic |
Author |
Message |
jim haire Beginner
Joined: 30 Dec 2002 Posts: 140 Topics: 40
|
Posted: Fri Jul 08, 2016 4:04 pm Post subject: Returning an item from an occurs clause with like names. |
|
|
To preface, we are on version 5 of COBOL.
There are 2 data structures. The 05 and 10 levels are in an INCLUDE member.
Code: |
01 RECORD-LAYOUT-IN.
05 MIDDLE-LEVEL.
10 FIELD-1 OCCURS 100 TIMES.
01 RECORD-LAYOUT-OUT.
05 MIDDLE-LEVEL.
10 FIELD-1 OCCURS 100 TIMES.
|
When trying to reference a value in the FIELD-1 array, we have tried coding the program as:
Code: |
MOVE FIELD-1 (SUB) of RECORD-LAYOUT-IN to ...
and
MOVE FIELD-1 of RECORD-LAYOUT-IN FIELD-1 (SUB) to ...
|
The first example returned the compiler error:
FIELD-1 was not a uniquely defined name. The definition to be
used could not be determined from the context. The reference to the name
was discarded.
The second example returned the compiler error:
FIELD-1 was not defined as a data-name.
What would the proper construct be to retrieve a FIELD-I value? |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Fri Jul 08, 2016 5:05 pm Post subject: Re: Returning an item from an occurs clause with like names. |
|
|
jim haire wrote: |
What would the proper construct be to retrieve a FIELD-I value? |
you need the array subscript on the highest level. Something like this
Code: |
MOVE FIELD-1 OF MIDDLE-LEVEL
OF RECORD-LAYOUT-IN(SUB) TO ....
|
_________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
NASCAR9 Intermediate
Joined: 08 Oct 2004 Posts: 274 Topics: 52 Location: California
|
Posted: Fri Jul 08, 2016 6:05 pm Post subject: |
|
|
Here's how we do it. But we are not COBOL 5
PP 5655-S71 IBM Enterprise COBOL for z/OS 4.2.0
Code: |
MOVE HOURS OF FUND1 (SYX) TO PRE-20-HOURS OF WORK1.
|
_________________ Thanks,
NASCAR9 |
|
Back to top |
|
|
William Collins Supermod
Joined: 03 Jun 2012 Posts: 437 Topics: 0
|
Posted: Sat Jul 09, 2016 1:39 pm Post subject: |
|
|
As Kolusu and NASCAR9 have indicated, you need to "qualify" before the subscripting (or reference-modification as well). The qualification is of the reference to the name. You break that if you do it after the subscripting (or reference-modification).
In my opinion, qualification is for the birds.
In your example, I'd make the names unique. Either with the editor ("hey, no, wait, I'm not allowed to do that, there are 700 programs using those copybooks!") or by COPY ... REPLACING FIELD-1 BY some-unique-name.
Code: | COPY COPY1 REPLACING FIELD-1 BY FIELD-2.
01 RECORD-LAYOUT-IN.
05 MIDDLE-LEVEL.
10 FIELD-1 OCCURS 100 TIMES.
15 PIC X.
01 RECORD-LAYOUT-OUT.
05 MIDDLE-LEVEL.
10 FIELD-1 OCCURS 100 TIMES.
15 PIC X.
01 SUBS.
05 SUBS1.
10 SUBA BINARY PIC 9(4).
05 SUBS2.
10 SUBA BINARY PIC 9(4).
PROCEDURE DIVISION.
MOVE FIELD-1
OF RECORD-LAYOUT-IN
( SUBA
OF SUBS1 )
TO FIELD-1
OF RECORD-LAYOUT-OUT
( SUBA
OF SUBS2 )
MOVE FIELD-2
( SUBC )
TO FIELD-1
( SUBD ) |
Even with formatting, the first is more unwieldy than the second, to my mind.
Of course the names are just for the example...
Qualification has been available, unchanged, on IBM COBOL compilers for probably the whole time IBM has made COBOL compilers.
What is new is a compiler option, I think from V5.2 onwards, which allows for things which couldn't previously be referenced through qualification (so not referenced at all) to now be referenced. See the documentation of QUALIFY(EXTEND) in a V5.2+ Programming Guide. This change does not affect any existing use of qualification, it extends qualification for situations which would not previously compile. |
|
Back to top |
|
|
jim haire Beginner
Joined: 30 Dec 2002 Posts: 140 Topics: 40
|
Posted: Tue Jul 12, 2016 1:15 pm Post subject: |
|
|
Thanks for the responses.
I believe we coded it as Kolusu recommended, but it was still failing. We'll look closer to see if there may be some other issue. |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Tue Jul 12, 2016 1:18 pm Post subject: |
|
|
jim haire wrote: | I believe we coded it as Kolusu recommended, but it was still failing. We'll look closer to see if there may be some other issue. |
Jim,
Can you show us the compiler listing of the error? _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
William Collins Supermod
Joined: 03 Jun 2012 Posts: 437 Topics: 0
|
Posted: Tue Jul 12, 2016 4:45 pm Post subject: |
|
|
Code: | MOVE FIELD-1 of RECORD-LAYOUT-IN FIELD-1 (SUB) to ... |
If you meant that example, the second reference to FIELD-1 is erroneous.
However, can't get the same message as you did with V4. The OF/IN is not optional, so the compiler should have given a different message.
The full code (definitions and usage in the PROCEDURE DIVISION) for that second example, and for whatever you have which is not working, and the full error messages, including error codes, would be useful.
If things are as you seem to have shown for the second example, I think you have touched on a "compiler anomaly"
Obviously, if they are not as they seem, then you probably haven't... |
|
Back to top |
|
|
|
|