Theoretically, I studied like the end of character in comp-3 tells whether it is positive or negative value
Is this not applicable for new version of COBOL in mainframes?
01 WS-COMP3 PIC S9(5) COMP-3 VALUES -12.
DISPLAY WS-COMP3
OUTPUT: 0001K
For above piece of code, I am getting the end of character as K instead of D The value K is the substitution of -2 0 ==> } -1 ==> J, -2 ==> K ....
Using DISPLAY ...
with a numeric data type requires a conversion to a displayable type. The COBOL standard requires it.
A typical conversion for COMP-3
is to move the data item to an equivalent displayable format. For this case, PIC S9(5) COMP-3
is often converted to PIC S9(5) SIGN TRAILING
for display.
This conversion means the internally stored value will be converted so that individual digits, except the last, will be converted to displayable digits. The last will have the sign indicator changed to reflect the format for the particular implementation.
For IBM mainframes, the internal COMP-3 format for -12
is 00 01 2D
and will be converted to F0 F0 F0 F1 D2
which displays as 0001K
.
Many ASCII systems will provide a slightly different result. The same internal format will be converted to 30 30 30 31 x2
where the x
depends on the implementation's requirement. It may display as 0001B
or 0001r
or some other, such as SIGN SEPARATE
giving -00012
.
The actual conversion for any data type done by any COBOL implementation will be documented in the language reference.
From the 2002 standard, B.1 Implementor-defined language element list,
- DISPLAY statement (data conversion). This item is required. This item shall be documented in the implementor's user documentation. (14.8.10, DISPLAY statement, general rule 1)
DISPLAY statement, 14.8.10.3 General rules,
- The DISPLAY statement causes the content of each operand to be transferred to the hardware device in the order listed. If an operand is a zero-length data item, no data is transferred for that operand. Any conversion of data required between literal-1 or the data item referenced by identifier-1 and the hardware device is defined by the implementor.