Using COBOL intrinsic functions, we can find the last Date of the Month for any given Gregorian Date.
The below code is present in the above screenshot.
The below code is present in the above screenshot.
01 WS-MONTH-END-DD PIC X(24) VALUE
'312831303130313130313031'.
01 WS-TBL-MONTH-END REDEFINES WS-MONTH-END-DD.
05 TBL-MONTH-END-DAY PIC 9(02) OCCURS 12 TIMES.
01 WS-GREG-DATE.
05 WS-GREG-YEAR PIC 9(04).
05 WS-GREG-MNTH PIC 9(02).
05 WS-GREG-DAY PIC 9(02).
EVALUATE TRUE
WHEN FUNCTION MOD (WS-GREG-YEAR 4) NOT ZERO
WHEN FUNCTION MOD (WS-GREG-YEAR 100) ZERO
AND FUNCTION MOD (WS-GREG-YEAR 400) NOT ZERO
MOVE '28' TO WS-TBL-MONTH-END (3: 2)
WHEN OTHER
MOVE '29' TO WS-TBL-MONTH-END (3: 2)
END-EVALUATE
MOVE TBL-MONTH-END-DAY(WS-GREG-MNTH)
TO WS-GREG-DAY
DISPLAY 'LAST-DATE OF MONTH:' WS-GREG-DATE
No comments:
Post a Comment