The 19 best informative COBOL really useful tuning tips

cobol-tips
cobol-tips

Tip#1
If you are accessing ESDS VSAM file, then in COBOL do you know
that 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 data set.

TIP # 2
When writing a COBOL program that is to be used as a CICS application program,do not use the
compiler option DYNAM.
TIP # 040
COBOL
MERGE statement can have OUTPUT PROCEDURE but not INPUT PROCEDURE !!

still-learn-cobol
still-learn-cobol

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 using 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 W RITE RECO RD?
You READ a FI LE becaus e you don’t know in advance:
1.whether ther e actually is a RECORD to read or not
2. For var iable or undefined length files , how long the nex t RECORD will be,
if ther e is one.
You Wr ite a RECORD becaus e you know in advance the answer s to both of
the above ques tions .

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 freaquently asked questions with answers

TIP # 14
Sometimes my initialization doesn’t work when I use INTIALIZE 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 internal sort in my COBOL Program. Is there anyway 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 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.
INTIALIZE WS-RECORD
REPLACING ALPHANUMERIC DATA BY SPACES
NUMERIC DATA BY ZEROES.

TIP # 18
SEARCH ALL condition only test an equal condition.
100 COOL MAI NFRAME T I PS

TIP # 19
In 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…
First part in DDNAME: – Device Class
UT stands for Utility (Tape or Sequential Disk)
DA stands for Direct-Access (disk)
Second part in DDNAME: – Method of Organization
S – Sequential (Printer, terminal, disk or tape)
I, R, D – Disk files to be accessed randomly

Advertisements

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.