Occurs 0 times in OCCURS DEPENDING ON.

All sort of Mainframes Interview Questions.
Post Reply
Bhaskar Vanjani
New Member
Posts: 1
Joined: Fri Dec 12, 2014 3:47 pm

Occurs 0 times in OCCURS DEPENDING ON.

Post by Bhaskar Vanjani »

Hi,

What is the answer for the question, the Occurs 0 times in OCCURS DEPENDING ON is acceptable or not? I think it is allowed but I was not sure about the answer. But if it is given how the table will look like?
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

Re: Occurs 0 times in OCCURS DEPENDING ON.

Post by nicc »

Have you looked it up in the manual? You should have before posting. So what is it in the manual that you do not understand?
Regards
Nic
User avatar
Akatsukami
Global Moderator
Global Moderator
Posts: 122
Joined: Tue Oct 20, 2015 3:20 am
Location: Bloomington, IL
Contact:

Re: Occurs 0 times in OCCURS DEPENDING ON.

Post by Akatsukami »

As the variable-length tables topic of the Enterprise COBOL for z/OS Language Reference manual states:
The value of integer-1 must be greater than or equal to zero
"I come to the conclusion that, men loving according to their own will and fearing according to that of the prince, a wise prince should establish himself on that which is in his own control and not in that of others." -- Niccolò Machiavelli
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 0 times in OCCURS DEPENDING ON.

Post by Robert Sample »

Zero is allowed because OCCURS DEPENDING ON can be used in an FD and the file may very well have no occurrences.

As for how the table will look, that depends upon where the table is located. In an FD or LINKAGE SECTION, the table will look like nothing because there will be no entries in it. In WORKING-STORAGE, since COBOL allocates the entire table in memory the table will look the same as if every element was defined.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Occurs 0 times in OCCURS DEPENDING ON.

Post by William Collins »

Code: Select all

01  some-table.
    05  some-non-OCCURS-stuff PIC X(10).
    05  the-OCCURS-BIT.
        10  FILLER OCCURS 0 TO 30 TIMES
              DEPENDING ON number-of-actual-entries-at-the-time.
            15  the-data-entry PIC XX.
That will define 70 bytes of storage. The LENGTH OF (or FUNCTION LENGTH (...)) of some-table will be 10 plus an amount related to the length of the entry (in this case two) and the value in number-of-actual-entries-at-the-time, which can be zero (length will be 10) to 30 (length will be 70, the maximum defined) and should not be more or less.

OCCURS DEPENDING ON with 0 TO ... has many uses.
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 “Interview Questions.”