Sort - Convert PD To ZD in Displayable Format (ZDF) : Cobol - Performance Improvement
Sort - Convert PD To ZD in Displayable Format (ZDF) : Cobol - Performance Improvement
In most of the scenarios, your input file has data either in Packed decimal (COMP-3) format
which is not in readable format. To change this to readable format, you need to convert
these numbers into ZONED Decimal (ZD) format. This can be accomplished using SORT.
PD to ZD
Suppose your input file has first 4 bytes in packed format and you want it in displayable
format
OUTREC FIELDS=(1,4,PD,TO=ZD,LENGTH=6)
But the above SORT card would have an Alphabet instead of number as the last byte in the
new ZD value. Use the below SORT card with ZDF option, to have the new ZD value as all
numeric.
OUTREC FIELDS=(1,4,PD,ZDF)
All the options provided below when applied to a COBOL program will improve its
performance.
1. INITIALIZE statement when converted to Machine code after the compile, it would
create move statements for each individual field in the GROUP variable separately.
Instead, we can make use of a single MOVE statement.
Also in your program, if you had to perform INITIALIZE to a group of variables multiple
times, it is advisable to have a separate section of the GROUP variable in the WORKING-
STORAGE section with all of the INDIVIDUAL fields INITIALIZED (using VALUES)
and MOVE this GROUP variable to the actual GROUP variable whenever required.
2. During Arithmetic Operations (with some limitations), COMP fields provide more
performance compared to COMP-3 which indeed provide more performance compared to
DISPLAY variables.
3. Index represent displacement value of the table entry from the beginning of the
table while subscripts represent the occurrence number of an element. The value of an
index has the element size factored into it, whereas the value of a subscript must be
multiplied by the element size when the subscript is used.
4. If SSRANGE is in effect at compile time, range-checking code is generated. This
would degrade performance. Also You can inhibit range checking by specifying the
CHECK(OFF) runtime option. Doing so leaves range-checking code dormant in the object
code. Optionally, the range-checking code can be used to aid in resolving unexpected
errors without recompilation.
BY RAJESHAR IN COBOL, DB2
≈ LEAVE A COMMENT
RESTART LOGIC IN COBOL DB2 Program
Suppose you have a COBOL DB2 program, in which you are reading data from input file
which has thousands of records and updating a DB2 table one record at a time.
Now you are planning to have restart logic. That is, say you have updated 10000 records
from the input file and the job abended. Here you do not want to start from the first and
again update the already updated records.
(NOTE: In COBOL IMS programs, this seems to be taken care by IMS itself)
So the restart logic can be as below so as to restart from a record near to the abended
record and not from the TOP.
Define a VSAM file and store the last updated KEY value in it whenever you issue a
COMMIT for the DB2.
Ex: Say you are committing your data after every 1000 records from input file, and then
update your VSAM file with the key of 1000 record.
Now say your program has abended at 5020 record, now in the VSAM file you will
have the key of the 5000 record. And all the initial 5000 records are committed in DB2.
So when you correct the issue and restart the program. The first thing you need to
do in the program is to read the VSAM file and get the key from it.
If the key is zeroes, it means we are running the job for the first time
If the key is greater than zeroes, then read just the input file(without doing any
other processing in the program, as we have already updated the data in DB2) till the
key is reached and start processing the record from the next record of the key.
In our example, VSAM file will have 5000 record. So till 5000 record, you will browse
through the input file and from 5001 record, you will start the processing.
Include/Omit are the first statements to be processed in a SORT job, even though you have
mentioned statements in any order.
As name suggests, INCLUDE is for including selecting records and OMIT is for omitting
unnecessary records. You can perform both inclusion and omission by both INCLUDE/OMIT
by using the operator NE (Not equal).
Suppose if you want to include records with first 2 chars as AR, the statements look as
below:
INCLUDE COND=(1,2,CH,EQ,C’AR’)
OMIT COND=(1,2,CH,NE,C’AR’)
You can even compare two fields to do omission/inclusion.
Suppose you want omit all the records for which the first 2 bytes is greater than 3rd and
4th byte together. Say 1-2 and 3-4 bytes all are of numeric data.
INCLUDE COND=(1,2,ZD,LE,3,2,ZD)
OMIT COND=(1,2,ZD,GT,3,2,ZD)
As both the fields are of same type, we can make use of FORMAT and write above
statements as
INCLUDE COND=(1,2,LE,3,2),FORMAT=ZD
OMIT COND=(1,2,GT,3,2),FORMAT=ZD
1. Character Strings
Say you want to include all records with ‘AR’ at first 2 bytes as shown above.
INCLUDE COND=(1,2,CH,EQ,C’AR’)
NOTE:
If you want to include a single apostrophe in the string, you must specify it
as two single apostrophes. For example, O’NEILL must be specified as
C’O”NEILL’.
1. Hexadecimal Strings
X’yy..yy’
where yy is a pair of hexadecimal digits. For example, X’7FB0′.
1. Decimal Numbers
n…n or ±n…n
You can do numeric tests in INCLUDE/OMIT. Suppose you want to include only records with
first 5 bytes being numeric.
INCLUDE COND=(1,5,FS,EQ,NUM)
Use FS format for the field if you want to test for character numerics (‘0’-‘9’ in every byte).
Use ZD format for the field if you want to test for zoned decimal numerics (‘0’-‘9′ in all non-
sign bytes; X’F0′-X’F9′, X’D0′-X’D9′ or X’C0′-X’C9’ in the sign byte).
Use PD format for the field if you want to test for packed decimal numerics (0-9 for all
digits; F, D or C for the sign).
Below is a INCLUDE statement, to include all the records with first 5 bytes as COBOL, CICS,
DB2 and VSAM.
INCLUDE COND=(1,5,CH,EQ,C’COBOL’,OR,
1,5,CH,EQ,C’CICS’,OR,
1,5,CH,EQ,C’DB2′,OR,
1,5,CH,EQ,C’VSAM’)
Instead, you can use one of the substring search capabilities of INCLUDE and OMIT to write
the statement in a simpler form as:
The length of each string must match the length of the field. Because you are searching for
5 characters, you must add a blank at the end of “VSAM” and “CICS” and 2 blanks at the
end of “DB2”, which are each four characters and 3 characters , but not for “COBOL”, which
is five characters.