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

Module 6: Procedure Division


INITIALIZE verb

  • As name suggests, it is used to initialize an elementary item or a group item
  • It functions similar to VALUE clause. The difference is that VALUE can be used to initialize data item in WORKING-STORAGE SECTION and thus initialization in this case takes place only at the beginning of the program execution. Whereas, INITIALIZE can be used to initialize data item as and when necessary in PROCEDURE DIVISION.
  • FILLER items & OCCURS DEPENDING ON items are not affected
  • Syntax:-

    INITIALIZE data-item-1 REPLACING  { ALPHABETIC/              ALPHANUMERIC/              ALPHANUMERIC-EDITED/              NUMERIC/              NUMERIC-EDITED} DATA BY {data-item-2/literal-2}

  • When REPLACING option not specified, INITIALIZE sets the alphabetic, alphanumeric and alphanumeric-edited data items to SPACES and numeric, numeric-edited data item to ZEROES.
  • Example 1:-
    In DATA DIVISION,

    01 EMP-DATA. 05 EMP-ID PIC 9(5). 05 EMP-NAME PIC A(10). 05 EMP-ADDR PIC X(10). 05 EMP-SAL PIC Z9(3).9(2).

    In PROCEDURE DIVISION,
    • INITIALIZE EMP-ID
      This will move ZEROES to EMP-ID
    • INITIALIZE EMP-ID REPLACING NUMERIC DATA BY ‘12345’
      This will initialize EMP-ID to value ‘12345’
    • INITIALIZE EMP-AME INITIALIZE EMP-SAL.
      These statements will initialize EMP-NAME to SPACES and EMP-SAL to ZEROES
    • INITIALIZE EMP-DATA.
      This will initialize EMP-ID, EMP-SAL to ZEROES and EMP-NAME, EMP-ADDR to SPACES
    • INITIALIZE EMP-DATA REPLACING NUMERIC DATA BY ‘99999’ REPALCING ALPHABETIC DATA BY ‘STEVE’ REPLACING APLHANUMERIC DATA BY ‘NEW YORK’ REPLACING NUMERIC-EDITED DATA BY ‘1245.50’
      This will move ‘99999’ to EMP-ID, ‘STEVE’ to EMP-NAME, ‘NEW YORK’ TO EMP-ADDR and ‘1245.50’ TO EMP-SAL
  • Example 2:-
    In DATA DIVISION,

    01 X. 05 X1 PIC X(3). 05 X2 PIC X(10). 05 Y DEFINES X2. 10 Y1 PIC 9(5). 10 Y2 PIC 9(5).

    In PROCEDURE DIVISION,
    • INITIALIZE X.
      This will fill spaces in X1 and X2. It is important to notice here that X2 is not filled with zeroes.
    • INITIALIZE Y.
      This will fill zeroes in Y1 and Y2 and thus X2 will have zeroes
  • Example 3:-
    In DATA DIVISION,

    01 X. 05 I PIC 9(3) OCCURS 10 TIMES.

    In PROCEDURE DIVISION,
    INITIALIZE X.
    This will fill all elements of table with zero.






© copyright mainframebug.com
Privacy Policy