Top
NetCOBOL V11.0 Syntax Samples
FUJITSU Software

1.25.2 OCCURS clause (format 2) Variable Number of Occurrences

The OCCURS clause (format 2) is used when there is a variable number of occurrences for the data item that specifies the OCCURS clause.

The size of the data item that specifies the OCCURS clause is not variable -- the number of occurrences is variable.

000010 @OPTIONS MAIN
000020*----------------------------------------------------------------------
000030* OCCURS clause (format 2)
000040* The number of occurrences can change dynamically.
000050*----------------------------------------------------------------------
000060 IDENTIFICATION   DIVISION.
000070 PROGRAM-ID.      SAMPLE.
000080 DATA             DIVISION.
000090 WORKING-STORAGE SECTION.
000100*----------------------------------------------------------------------
000110* If the data name is specified in the DEPENDING ON clause, the number 
000120* of occurrences can be controlled dynamically when the program is
000125* executed.
000130*----------------------------------------------------------------------
000140 01 DSP-DATA.
000150    02            OCCURS 80 TIMES DEPENDING ON LEN.
000160      03            PIC X VALUE "*".
000170 77 LEN        PIC 9(2).
000180*----------------------------------------------------------------------
000190 PROCEDURE      DIVISION.
000200     DISPLAY "Display how many bytes? (1 to 80) >>" WITH NO ADVANCING.
000210     ACCEPT LEN.
000220*----------------------------------------------------------------------
000230* The value of the data (LEN) specified in the DEPENDING ON clause 
000235* becomes the number of occurrences.
000240*----------------------------------------------------------------------
000250     DISPLAY DSP-DATA.
000260*----------------------------------------------------------------------
000270 END PROGRAM SAMPLE.