Returning an item from an occurs clause with like names.
Select messages from
# through # FAQ
[/[Print]\]

MVSFORUMS.com -> Application Programming

#1: Returning an item from an occurs clause with like names. Author: jim haire PostPosted: Fri Jul 08, 2016 4:04 pm
    —
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?

#2: Re: Returning an item from an occurs clause with like names. Author: kolusuLocation: San Jose PostPosted: Fri Jul 08, 2016 5:05 pm
    —
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 ....

#3:  Author: NASCAR9Location: California PostPosted: Fri Jul 08, 2016 6:05 pm
    —
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.                                   

#4:  Author: William Collins PostPosted: Sat Jul 09, 2016 1:39 pm
    —
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.

#5:  Author: jim haire PostPosted: Tue Jul 12, 2016 1:15 pm
    —
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.

#6:  Author: kolusuLocation: San Jose PostPosted: Tue Jul 12, 2016 1:18 pm
    —
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?

#7:  Author: William Collins PostPosted: Tue Jul 12, 2016 4:45 pm
    —
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" Smile

Obviously, if they are not as they seem, then you probably haven't...



MVSFORUMS.com -> Application Programming


output generated using printer-friendly topic mod. All times are GMT - 5 Hours

Page 1 of 1

Powered by phpBB © 2001, 2005 phpBB Group