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 my 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

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.