Back to Browse

COBOL Array handling

13.1K views
Jun 30, 2019
11:26

Arrays in COBOL are called as Tables. An array is a linear data structure and is a collection of homogenous data items that can be referred by a single data name. The data items contained in an array are called elements. The elements of an array are internally stored in contiguous memory locations. The elements of an array may be elementary or group items. How to declare Array/Table? 01 WS-TABLE. 05 WS-ROW1 PIC X(10) OCCURS 10 TIMES. If occurs clause is used only once in the table row, it is called as one dimension. Two-dimensional tables are created by having two OCCURS clauses describe entries. Three-dimensional tables have three OCCURS clauses. Example 1: One dimension WORKING-STORAGE SECTION. 01 AA. 05 WS-NAME PIC 9(10) OCCURS 10. 05 I PIC 9(1) VALUE 1. PROCEDURE DIVISION. MAIN-PARA. PERFORM PARA1 VARYING I FROM 1 BY 1 UNTIL I IS GREATER THAN OR EQUAL TO 5. STOP RUN. PARA1. MOVE '1' TO WS-NAME(I). DISPLAY I. DISPLAY 'WS-NAME ' WS-NAME(I). Output: 1 Example2: 2-dimensional array 01 WS-EMP-GROUP. 05 WS-EMP OCCURS 10 TIMES.  10 Departments 10 WS-DEPT PIC X(10) VALUE SPACES. 10 WS-EMP-PROJ OCCURS 5 TIMES.  Maximum of 5 employees in each department 15 WS-EMP-ID PIC 9(5) VALUE ZEROS. 15 WS-EMP1 PIC X(5) VALUE ZEROS. PROCEDURE DIVISION. MAIN-PARA. MOVE 'BANKA11111ARUNA' TO WS-EMP(1). MOVE 'MARKA22222BALAB' TO WS-EMP(2). DISPLAY '***********************'. DISPLAY WS-EMP(1). DISPLAY '***********************'. DISPLAY WS-EMP-ID(1,1). STOP RUN. Output: *********************** BANKA11111ARUNA *********************** 11111

Download

0 formats

No download links available.

COBOL Array handling | NatokHD