Thursday, April 29, 2010

Effective initialization of internal tables in COBOL

Initializing internal tables in COBOL:

Click Here to Search This Site

If the internal table size is too high and the number of bytes to be initialized is very large then initialization of the internal table would be CPU intensive.

For optimizing this initialization process, a recommendation is explained below with an example

Eg: Consider an internal table- SAMPLE-TABLE which has 50,000 rows, with 100 bytes in each row. Lets say only 10 rows of the internal table are loaded with values, before initializing the table. If we use the command - INITIALIZE SAMPLE-TABLE for initializing, total of 50,000 rows would be moved with low-values or zeros with respect to their picture clause.
So here 50,000x100=50,00,000 bytes would be processed for initialization.

Instead we can have a counter variable to get the number of rows being loaded in the internal table and use the counter variable in a PERFORM loop to initialize only the rows which have been loaded. Syntax for this could be found below -

Counter Variable - CNTR would have the value 10.
we need to have the following PERFORM loop for efficient way of initializing
PERFORM INITIALIZE SAMPLE-TABLE(INDEX) until CNTR is greater than 10.

By doing so, only 10x100=1000 bytes would be processed for initializing the table and processing of 4,99,000 bytes would be avoided in initialization. If the initialization process comes in a perform loop of 10 executions, then 49,90,000 bytes would have been skipped in initializing process.

No comments:

Post a Comment