Mainframe-COBOL Occurs, Indexed By,USAGE is Index (2 of 2)

NoSql Interview Questions-Hadoop, Big DataRead my previous post-1. This post is an advanced topic for Tables/arrays.

OCCURS depending ON. Best example to create variable array:

01 ORG-LIMIT PIC 99 COMP VALUE 50.
01 DIVISION-NAME-TABLE.
05 DIVISION-ENTRY OCCURS 1 TO 50 TIMES DEPENDING ON ORG- LIMIT  INDEXED BY DIV-IX.
10 DIVISION-CODE PIC X(5).
10 DIVISION-NAME PIC X(30).

Perform VARYING…AFTER in Multi dimensional Tables:

The AFTER clause of the PERFORM…VARYING statement was designed specifically to support multidimensional tables in COBOL. It pre-dates the inline PERFORM statement (which was added with the 1985 Standard):

  • Perform…Varying

PERFORM
VARYING ROW-NR FROM 3 BY 2 UNTIL ROW-NR > 9
PERFORM VARYING COL-NR FROM 12 BY 2 UNTIL COL-NR > 18
ADD 1 TO CTR
MOVE CTR TO SCREEN-CHAR (ROW-NR COL-NR).

  • Perform…Varying…After

PERFORM
VARYING ROW-NR FROM 3 BY 2 UNTIL ROW-NR > 9
AFTER COL-NR FROM 12 BY 2 UNTIL COL-NR > 18
ADD 1 TO CTR
MOVE CTR TO SCREEN-CHAR (ROW-NR COL-NR).

In the above logic ROW-NR and COL-NR are two indexed/subscripts referencing two arrays. So, the above PERFORM statement work for multi dimensional Table.

How to initialize or increment or decrement of an Index:

SET index TO positive integer

Example: SET IX-1  to 1;  (For initialization)

SET IX-1 UP BY 1; (For increment)

SET IX-1 DOWN BY 1; (For decrement)

How to initialize or increment or decrement of an Subscript:

Examples:

MOVE 1  TO SUB-1 (For initialization)

ADD 1 TO SUB-1 (For increment)

SUBTRACT  1  FROM SUB-1 (For decrement)

Advertisements

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.