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

Cobol - Explain complete concept of table handling in COBOL with an example?




533
views
asked mar August 3, 2014 02:36 AM  

Explain complete concept of table handling in COBOL with an example?


           

1 Answers



 
answered By Mswami   0  
TABLES:

An OCCURS clause is used to indicate the repeated occurrences of items of the same format in a structure. OCCURS clause is not valid for 01, 77, 88 levels.
It can be defined as elementary or group item. Initialization of large table occurrences with specific values are usually done using perform loops in procedure division. Simple tables can be initialized in the following way.


Example:

01 WEEK-ARRAY VALUE ‘MONTUEWEDTHUFRISATSUN’.
   05 WS-WEEK-DAYS OCCURS 7 TIMES PIC X(03).
 


Dynamic array is the array whose size is decided during runtime just before the access of first element of the array.

Example:

01 WS-MONTH-DAY-CAL.
 05 WS-DAYS OCCURS 31 TIMES DEPENDING ON WS-OCCURENCE.	
....
IF MONTH = ‘FEB’ MOVE ‘28’ to WS-OCCURRENCE.

Array Items can be accessed using INDEX or subscript and the difference between them are listed in the table. Relative subscripts and relative indexes are supported only in COBOL85. Literals used in relative subscripting/indexing must be an unsigned integer.


Example:

ADD WS-SAL(SUB) WS-SAL(SUB + 1) TO WS-SAL(SUB + 2).


Sometimes, you may face a question like how to randomly access the information in the sequential file of 50 records that contains all the designation and the respective lower and higher salary information.
Obviously, OS does not allow you to randomly access the sequence file. You have to do by yourself and the best way is, load the file into a working storage table in the first section of the program and then access as you wish.
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