Occurs are not allowed at 01/77, why?

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
cobollearn
Registered Member
Posts: 25
Joined: Tue Jul 09, 2013 6:31 pm

Occurs are not allowed at 01/77, why?

Post by cobollearn »

Hi,

Occurs are not allowed at 01/77, why? I've read couple of reference in google but they are very clear. Can someone please help here.

Thanks.
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1891
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Occurs are not allowed at 01/77, why?

Post by Robert Sample »

In COBOL, a variable must be able to be uniquely identified; this is done via qualification such as

Code: Select all

MOVE 1 TO VAR-X OF VAR-01
If the 01-level variable VAR-01 could have OCCURS, which VAR-01 is the qualification referring to?
Other potential reasons include:
- an 01 level represents a logical record; OCCURS would be defining multiple logical records which doesn't make sense.
- COBOL states a table occurs within a group. There is no level number that can be used to group 01 / 77 items

And the ultimate, complete, total answer to your question is:
The COBOL rule is that OCCURS is not allowed for 01 / 77 levels.
The rules are the rules, and it is not always possible to know why something is the rule -- remember COBOL dates back more than 50 years at this point, and the actual reason(s) may be lost in the history somewhere.
Priya
Registered Member
Posts: 50
Joined: Tue Jul 02, 2013 11:43 pm

Re: Occurs are not allowed at 01/77, why?

Post by Priya »

Can we say that -- "01 Level" represents a "record occurrence" so every next 01-level is a next record. If tables are allowed at 01 level - we'll never know if it's "record-occurrence" or "a repetition of similar fields" in a single record!?
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1891
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Occurs are not allowed at 01/77, why?

Post by Robert Sample »

The 01 level in an FD of the FILE SECTION defines a record -- period. Multiple 01 levels in an FD define the same data in multiple ways. In WORKING-STORAGE or LINKAGE, however, the record concept does not really apply since neither is associated with a file. But both handle all data in an 01 level as a unit, which means the processing at the 01 level occurs as if it were a record.
Priya
Registered Member
Posts: 50
Joined: Tue Jul 02, 2013 11:43 pm

Re: Occurs are not allowed at 01/77, why?

Post by Priya »

Thanks Robert - this is helpful.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM COBOL, GnuCOBOL (OpenCOBOL), OOCobol.”