MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Returning an item from an occurs clause with like names.

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
jim haire
Beginner


Joined: 30 Dec 2002
Posts: 140
Topics: 40

PostPosted: Fri Jul 08, 2016 4:04 pm    Post subject: Returning an item from an occurs clause with like names. Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12357
Topics: 75
Location: San Jose

PostPosted: Fri Jul 08, 2016 5:05 pm    Post subject: Re: Returning an item from an occurs clause with like names. Reply with quote

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 - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Fri Jul 08, 2016 6:05 pm    Post subject: Reply with quote

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
View user's profile Send private message
William Collins
Supermod


Joined: 03 Jun 2012
Posts: 437
Topics: 0

PostPosted: Sat Jul 09, 2016 1:39 pm    Post subject: Reply with quote

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
View user's profile Send private message
jim haire
Beginner


Joined: 30 Dec 2002
Posts: 140
Topics: 40

PostPosted: Tue Jul 12, 2016 1:15 pm    Post subject: Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12357
Topics: 75
Location: San Jose

PostPosted: Tue Jul 12, 2016 1:18 pm    Post subject: Reply with quote

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 - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
William Collins
Supermod


Joined: 03 Jun 2012
Posts: 437
Topics: 0

PostPosted: Tue Jul 12, 2016 4:45 pm    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group