Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 9: Array processing and Table handling


Single-Dimension Array

  • It is also referred to as single dimensional table or one dimensional table
  • It will be easier to understand it with example
  • Suppose, we have to store sales of laptops done in each quarter of year. In order to handle such scenarios, we can write below data declaration

    01 SALES-LAPTOP. 05 SALES-Q1 PIC 9(4). 05 SALES-Q2 PIC 9(4). 05 SALES-Q3 PIC 9(4). 05 SALES-Q4 PIC 9(4).

  • In above data declaration we can observe all elementary data items have same data type and size (i.e. PIC 9(4)).
  • Above situation can also be handled by alternative way of describing data as follows:-

    01 SALES-LAPTOP. 05 SALES PIC 9(4) OCCURS 4 TIMES.

  • Conceptual view of above declaration:-
  • You can see above method is more simpler
  • We will be describing OCCURS clause in next section. For now, just understand that the above shorter form of declaration will create single dimension array of SALES. That array will contain 4 occurrences of SALES data item, thus allowing us to store sales value for each of four quarter.
  • Definitely, the above alternative of data declaration using OCCURS clause has advantages such as:-
    • Data declaration is shorter than previous one (Imagine, If we had to store values month wise or day wise!)
    • Any occurrence(element) of array can be simply accessed by subscripting
  • OCCURS clause is described next






© copyright mainframebug.com
Privacy Policy