COBOL tips for performance improvements
- Always consider using SEARCH ALL option instead of checking long table by coding.
- Internal SORT is usually uses longer CPU than External SORT.
- Always consider using Evaluate, it creates program more modular.
- Avoid using go to statement as they create irregular flow.
- Initializing field is more efficient as follows:
INITIALIZE WS-CHARC with SPACES
INITIALIZE WS-NUMERIC with ZEROS
- Unnecessary computations should be eliminated.
INITIALIZE PIN-TOTAL
PERFORM VARYING I FROM 1 BY 1 UNTIL I = 40
COMPUTE PIN-TOTAL = PIN-TOTAL + ITEM(I)
END-PERFORM
COMPUTE PIN-TOTAL = PIN-TOTAL * PERCENT DIS
Inefficient Code
INITIALIZE PIN-TOTAL
PERFORM VARYING I FROM 1 BY 1 UNTIL I = 40
COMPUTE PIN-TOTAL = PIN-TOTAL + ITEM (I) * PERCENT DIS
END-PERFORM
- When using PERFORM VARYING clause, using COMP data types is efficient than USAGE DISPLAY for the loop control variables.
- Check boundary always for any arrays. If you expect 100 occurs then always have that check, this helps to know if arrays limit is reached.
- If you need any specific data from file, always load the array with that field instead of complete data from file.
This is really good and useful stuff. Keep up the good work
ReplyDelete