COBOL Optimization Ideas That Make Your Program Superior in Performance.
COBOL Tuning Ideas
Tip#1
If you are accessing ESDS VSAM file, then in COBOL do you know that the SELECT clause has something different about it!!
For ESDS,
SELECT FILE ASSIGN TO AS-DDNAME
Yes, the DDNAMEs should be prefixed with “AS-”
If you are not doing that then an S213 ABEND might occur when attempting to open the dataset.
TIP # 2
When writing a COBOL program that is to be used as a CICS application program, do not use the compiler option DYNAM. COBOL Optimization Ideas
Tip# 3
Do you know how COBOL Compiler finds a dataset as VSAM dataset?
When the ORGANIZATION clause is coded for a file, the COBOL compiler interprets it as a VSAM dataset. Hence, the ORGANIZATION clause should not be coded with a non-VSAM dataset.
TIP # 4
Do you know using an odd number of digits for PACKED DECIMAL (COMP-3) is 5% to 20% faster than using an even number of digits !!
TIP # 5
Performance considerations for indexes vs subscripts:
- using COMP to address a table is 30% slower than using indexes!
- using COMP-3 to address a table is 300% slower than using indexes !!
- using DISPLAY data items to address a table is 450% slower than sing indexes !!!
- (source: Cobol performance tuning manual)
TIP # 6
Rule of the THUMB:
For a table with less than 50 entries ==> go for SEARCH ( Sequential Search)
greater than 50 entries ==> go for SEARCH ALL ( Binary Search)
TIP # 7
In COBOL, why we READ FILE but WRITE RECORD?
You READ a FILE because you don’t know in advance:
1.whether there actually is a RECORD to read or not
2. For variable or undefined length files, how long the next RECORD will be if there is one. Write a RECORD because you know in advance the answer s to both of the above questions.
More : COBOL Date logic to find number of days
TIP # 8
Using OPEN OUTPUT to load a VSAM file will significantly improve the performance of your program. Using OPEN I-O or OPEN EXTEND will have a negative impact on your program’s performance.
TIP # 9
Avoid repetitive uses of the INITIALIZE statement. INITIALIZE once and move it to a second like-sized 01 level, then move the second 01 level to the first to initialize the fields.
TIP # 10
Consider using an in-line PERFORM instead of a SEARCH when you have less than 20 elements in a table.

TIP # 11
One can generate a complete listing of compiler diagnostic messages, with their explanations, by compiling a program with the program-id of ERRMSG specified in the PROGRAM-ID paragraph.
EX:
IDENTIFICATION DIVISION
PROGRAM-ID.ERRMSG.
ENVIRONMENT DIVISION.
DATA DIVISION.
PROCEDURE DIVISION.
STOP RUN.
TIP # 12
For KSDS or RRDS , when DELETE statement is used, the file must be
opened in I-O Mode.
TIP # 13
Performance Tuning Taking constant expressions out of a loop speeds up a program with no ill effects.
Example:
Move zero to total.
Perform varying I from 1 by 1 until I > 100
Compute total = total + item (i) * discount
End-perform
Remove multiply from loop
Move zero to total
Perform varying I from 1 by 1 until I > 100
Compute total = total + item (i)
End-perform
Compute total = total * discount
More: COBOL frequently asked questions with answers
TIP # 14
Sometimes my initialization doesn’t work when I use INITIALIZE verb? Is there anything that I should take care of?
When we use INITIALIZE verb to initialize group verbs, group elements which are FILLERs will not be initialized!
TIP # 15
I am using an internal sort in my COBOL Program. Is there any way to test the return code of sort operation?
The return-code or completion code is stored in a SORT-RETURN special register.
If SORT-RETURN = 0 (successful completion of SORT/MERGE)
If SORT-RETURN = 16 (Unsuccessful completion of SORT/MERGE)
TIP # 16
In general, it is an advantage to use COMP for numeric data and COMP-3 for decimal data.
TIP # 17
Here is one better way of INITIALIZATION of a record or group item.
INITIALIZE WS-RECORD
REPLACING ALPHANUMERIC DATA BY SPACES
NUMERIC DATA BY ZEROES.
TIP # 18
SEARCH ALL condition only test an equal condition.
TIP # 19
In the COBOL SELECT clause, I see sometimes see ASSIGN coded like this…
SELECT INFILE ASSIGN TO UT-S-INFILE
OR
SELECT INFILE ASSIGN TO DA-S-INFILE
What they mean actually…
The first part in DDNAME: - Device Class
UT stands for Utility (Tape or Sequential Disk)
DA stands for Direct-Access (disk)
The second part in DDNAME: - Method of Organization
S – Sequential (Printer, terminal, disk or tape)
I, R, D – Disk files to be accessed randomly
Related Posts
Handmade Gifts
You must be logged in to post a comment.