Pages

Tuesday, November 2, 2010

COBOL Performance Tuning - The INITIALIZE Statement

The INITIALIZE statement in COBOL is really a convenient statement.  It will move SPACES to alpha numeric fields and ZEROS to numeric fields.  But with this convenience comes a cost when initializing large copybooks.

Here is what happens when you initialize a copybook.  The INITIALIZE statement will initialize each field that is defined with a PIC clause, except FILLER fields.  FILLER fields will remain LOW-VALUES or nulls.  The underlying Assembler code that is created for each field being initialized is at least 3 Assembler statements.  So, if you have a copybook with 500 individual fields being initialized, that becomes at least 1500 Assembler statements that are created when the code is compiled.  These 1500 Assembler statements will be executed each time that INITIALIZE statement is executed.

Here are some simple options to tune code where an INITIALIZE needs to be done.

  • Do not initialize the copybook at all.  You will have to determine if this is an option.
  • If the copybook contains entirely alpha numeric fields that can be initialized as spaces, move SPACES to the 01 level.  This will generate 3 Assembler statements.
  • If the copybook contains a mixture of alpha numeric and numeric, and all of the numeric fields need to be initialized with ZEROS, then perform the following:
    01  BIG-RECORD.              COPY BIGREC.
    .

    .
    .
    PROCEDURE DIVISION
    .
    .
    .
        MOVE SPACES TO BIG-RECORD.
        INITIALIZE BIG-RECORD
          REPLACING NUMERIC DATA BY ZEROES.

  • The previous INITIALIZE statement will only initialize the numeric fields with ZEROS.  This would have had to be done either way, so here the INITIALIZE statement with the REPLACING clause will save you several lines of COBOL code, and will create the same amount of underlying Assembler code.
  • Your FILLER fields will contain SPACES when initialized using the 2nd and 3rd options.
When large arrays are present, there is another technique that can be used in conjunction with this way of initializing fields.  This will be discussed in a later entry.

No comments:

Post a Comment