Q

What are some COBOL coding techniques for performance?

Get performance tips to use when coding in COBOL.

Can you provide one or more COBOL coding techniques or recommendations, based on your experience, where efficiencies can be gained?

Yes, the biggest one would be to avoid using subscripts -- use indexes instead. By the way, all of my performance tips are available in the SHARE presentation called LE Performance Tips and Techniques.

COBOL coding tips -- table element references

Given these data descriptions:

77 SUB1 PIC S9(4) USAGE BINARY.
01 GRP1.
   05 TAB1 OCCURS 1000 INDEXED BY TABINDX.
      10 SALES PIC 9(7) PACKED-DECIMAL.
      10 EXPENSES PIC 9(7) PACKED-DECIMAL.
      10 INVENTORY PIC 9(7) PACKED-DECIMAL.

Slow code:

PERFORM VARYING SUB1
FROM 1 BY 1
UNTIL SUB1 > 1000
   COMPUTE SALES-TOTAL = SALES-TOTAL + SALES(SUB1)
   COMPUTE EXPENSE-TOTAL = EXPENSE-TOTAL + EXPENSES(SUB1)
   COMPUTE INVENTORY-TOTAL = INVENTORY-TOTAL + INVENTORY(SUB1)
END-PERFORM

Fast code:

PERFORM VARYING TABINDX
FROM 1 BY 1
UNTIL TABINDX > 1000
   COMPUTE SALES-TOTAL = SALES-TOTAL + SALES(TABINDX)
   COMPUTE EXPENSE-TOTAL = EXPENSE-TOTAL + EXPENSES(TABINDX)
   COMPUTE INVENTORY-TOTAL = INVENTORY-TOTAL + INVENTORY(TABINDX)
END-PERFORM
This was first published in March 2005
This Content Component encountered an error

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWindowsServer

SearchEnterpriseLinux

SearchServerVirtualization

SearchCloudComputing

Close