Pages

Showing posts with label INITIALIZE Statement. Show all posts
Showing posts with label INITIALIZE Statement. Show all posts

Sunday, November 14, 2010

COBOL Performance Tuning - INITIALIZE Statement And Large Arrays

We have covered the INITIALIZE statement and initializing large arrays, so now let's put them together.

Say you have a large copybook with a large array in it.

01  LARGE-RECORD.
(several 05 levels)
    05  MY-TABLE.
        10  TABLE-ENTRY OCCURS 999 TIMES.
(multiple fields here)
(more 05 levels)

Using the above copybook, you would have to modify it so that you can initialize parts of the copybook, but not the array, as you want to use a separate routine to do that.  Here is what I would do:

01  LARGE-RECORD.
  03  LARGE-RECORD-PART-1.
(several 05 levels)
  03  LARGE-RECORD-PART-2.
    05  MY-TABLE.
        10  TABLE-ENTRY OCCURS 999 TIMES.
(multiple fields here)
  03  LARGE-RECORD-PART-3
(more 05 levels)

Now you can initialize LARGE-RECORD like this:

MOVE SPACES TO LARGE-RECORD.
INITIALIZE LARGE-RECORD-PART-1
    REPLACING NUMERIC DATA BY ZEROS.
INITIALIZE LARGE-RECORD-PART-3
    REPLACING NUMERIC DATA BY ZEROS.

You would then initialize MY-TABLE as discussed in COBOL Performance Tuning - Large Arrays.

Contact me if you know of other ways (especially better ones) of accomplishing this objective.

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.