I've used a utility package (vsmr) to read the values for a VSAM file and I have the copybook source code available to me.
If I have definitions like below (please excuse the formatting)
01 RECORD
05 RECORD-X PIC S9(3)V99 COMP-3
05 RECORD-Y PIC S9(3)V99 COMP-3
05 RECORD-Z PIC S9(3) COMP-3
05 RECORD-ALPHA PIC X(10)
and I have the following in data
00 20 0C 01 10 0C 01 00 0C
How do I determine the numeric value for RECORD-X?
I assume RECORD-X takes 3 bytes and the values 00 20 0C correspond to the value of RECORD-X, but I do not know how to convert this to a human readable value (algorithmically, not necessarily programatically).
I would also assume the values 01 10 0C correspond to the value for RECORD-Y. Are my assumptions correct?
COMP-3 is an implementation of Binary Coded Decimal (BCD). Each nibble in a byte corresponds to a digit, with the last nibble holding the sign. Where you have...
00 20 0C 01 10 0C 01 00 0C
...we can map the first three bytes to RECORD-X
and have a value of +002.00. Sign nibbles with a value of C, A, F, or E are arithmetically considered positive; sign nibbles with a value of B or D are arithmetically considered negative. The decimal point is not encoded in the data, you must have the field definition to know where it is.
IBM Enterprise COBOL has the concept of "preferred sign" which is C for positive and D for negative. There are optimizations you can take advantage of if you are certain your data is all "preferred sign."
Your assumption about RECORD-Y
is correct, its value is +11.00.
If you are writing COBOL, you need implement no algorithm to convert this to a human readable value, simply MOVE RECORD-X TO RECORD-X-DISPLAY
where RECORD-X-DISPLAY
is defined with PIC +999.99
.