Ask the Expert

What are some COBOL coding techniques for performance?

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

Requires Free Membership to View

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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: