Page 1 of 1
Occurs 0 times in OCCURS DEPENDING ON.
Posted: Mon Nov 16, 2015 4:51 pm
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?
Re: Occurs 0 times in OCCURS DEPENDING ON.
Posted: Mon Nov 16, 2015 5:41 pm
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?
Re: Occurs 0 times in OCCURS DEPENDING ON.
Posted: Mon Nov 16, 2015 5:42 pm
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
Re: Occurs 0 times in OCCURS DEPENDING ON.
Posted: Mon Nov 16, 2015 7:05 pm
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.
Re: Occurs 0 times in OCCURS DEPENDING ON.
Posted: Mon Nov 16, 2015 8:56 pm
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.