Home > Software > Mainframe > Cobol
Interview Questions   Tutorials   Discussions   Programs   

Cobol - Write the syntax of a two dimensional array?




438
views
asked mar August 3, 2014 03:20 AM  

Write the syntax of a two dimensional array?


           

1 Answers



 
answered By Mswami   0  
Syntax:
WORKING-STORAGE SECTION.
01 MATA.
05 ROWA OCCURS 2 TIMES.
10 COLA OCCURS 2 TIMES PIC 9.


Example:

05 array-name occurs 4 times. 
10 ws-name-1 pic x(4). 
10 ws-name-2 pic x(4).
You can initialize it by using

PERFORM VARYING I FROM 1 BY UNTIL I>4 
   INITIALIZE WS-NAME-1(I) 
   INITIALIZE WS-NAME-2(I) 
END-PERFORM

1 more example:


01 X PIC 9 
01 Y PIC 9 
01 WS-GROUP-NAME 
05 WS-ARRAY OCCURS 7 TIMES 
10 WS-NAME PIC X(10) 
10 WS-DTLS OCCURS 5 TIMES 
15 WS-ID PIC X(5) 
15 WS-DEPT PIC X(6) 

PROCEDURE DIVISION 
1000-PARA. 
 PERFORM VARYING X FROM 1 BY 1 UNTIL X > 7 
  AFTER VARYING Y FROM 1 BY 1 UNTIL Y > 5 
  ACCEPT WS-NAME(X) 
  ACCEPT WS-ID(X,Y) 
  ACCEPT WS-DEPT (X,Y) 
 END-PERFORM. 
STOP RUN. 

flag   
   add comment

Your answer

Join with account you already have

FF

Preview


Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert