Expert Answer Center > Experts On Demand > View Answer
EMAIL THIS
Experts on Demand
  EXPERTS ON DEMAND HOME     POSE A QUESTION     VIEW ANSWERS     BROWSE BY TOPIC        RSS FEEDS  
Can you provide one or more COBOL coding techniques or recommendations, based on your experience, where efficiencies can be gained? QUESTION POSED ON: 23 MAR 2005
QUESTION ANSWERED BY: Tom Ross 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
HomeExperts on DemandIT Expert Webcast SeriesExpert KnowledgebaseSite Index
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts