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

Module 9: Array processing and Table handling


SUBSCRIPT

  • We already discussed in OCCURS clause section, how array elements can be accessed using a subscript
  • Subscript refer to the position of the element in array
  • To access first element of table SALES, we can use SALES(1), to access second element we can use SALES(2) and so on.
  • Value (1,2 etc.) is referred to as subscript
  • Subscript can also be declared in WORKING-STORAGE SECTION and that subscript data item can be used to access elements of array
  • Example:-
    In DATA DIVISION,

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

    In PROCEDURE DIVISION,

    MOVE 2 TO SUB DISPLAY ‘SALES OF QUARTER 2: ’ SALES-LAPTOP(SUB).

    Above code will display element of array that is at second position
  • The subscript refer to the position of array element where the element exist
  • Subscript’s highest value is the value specified by the integer in OCCURS clause. The subscript’s lowest value is ‘1’.
  • In one more way, array elements can be accessed i.e. by using INDEX which is explained in next section along with its differentiation with subscript






© copyright mainframebug.com
Privacy Policy