![]() |
COBOL 9's complement |
You can use a decimal calculator to convert from and to 9's complement dates:
9's comp | regular 01 Y2K-BEG-9COMP-DATE PIC X(06) VALUE '498768'. | 501231 01 Y2K-END-9COMP-DATE PIC X(06) VALUE '489898'. | 510101 01 Y2K-20-CENT-END-9COMP-DATE PIC X(06) VALUE '008768'. | 991231 01 Y2K-20-CENT-END-PLUS-1-9COMP PIC X(06) VALUE '008767'. | 991232 01 Y2K-20-CENT-BEG-9COMP-DATE PIC X(06) VALUE '999898'. | 000101 01 Y2K-20-CENT-BEG-MINUS-1-9COMP PIC X(06) VALUE '999899'. | 000100
To convert a regular date to a 9's complement date:
COMPUTE DATE-9COMP = 999999 - DATE-REG.
To convert a 9's complement date to a regular date:
COMPUTE DATE-REG = 999999 - DATE-9COMP.
(Of course, the variables used in arithmetic must be numeric.)
The sum of a regular date and its 9's complement will always
equal all 9s.
(Thanks for Bob King for this code.)
©1997 IBM Corporation