a. Convert a gregorian-date to julian-date and vice-versa
Code:
01 WS-GREGORIAN-DATE PIC 9(08).
01 WS-JULIAN-DATE PIC 9(07).
COMPUTE WS-JULIAN-DATE = FUNCTION DAY-OF-INTEGER
(FUNCTION INTEGER-OF-DATE
(WS-GREGORIAN-DATE))
COMPUTE WS-GREGORIAN-DATE = FUNCTION DATE-OF-INTEGER
(FUNCTION INTEGER-OF-DAY
(WS-JULIAN-DATE))
b. Find if the year is a leap year
Code:
01 WS-YEAR PIC 9(04).
EVALUATE TRUE
WHEN FUNCTION MOD (WS-YEAR 4) NOT ZERO
WHEN FUNCTION MOD (WS-YEAR 100) ZERO
AND FUNCTION MOD (WS-YEAR 400) NOT ZERO
DISPLAY 'IT IS NOT A LEAP YEAR ' WS-YEAR
WHEN OTHER
DISPLAY 'IT IS A LEAP YEAR ' WS-YEAR
END-EVALUATE
c. Add days to given gregorain date
Code:
01 WS-ADVANCE-DATE PIC 9(08).
01 WS-ADD-DAYS PIC 9(08).
01 WS-GREGORIAN-DATE PIC 9(08).
COMPUTE WS-ADVANCE-DATE = FUNCTION DATE-OF-INTEGER
(FUNCTION INTEGER-OF-DATE(WS-GREGORIAN-DATE) + WS-ADD-DAYS)
d. Subtract days to given gregorain date
Code:
01 WS-GREGORIAN-DATE PIC 9(08).
01 WS-SUB-DAYS PIC 9(08).
01 WS-RETARD-DATE PIC 9(08).
COMPUTE WS-RETARD-DATE = FUNCTION DATE-OF-INTEGER
(FUNCTION INTEGER-OF-DATE(WS-GREGORIAN-DATE) - WS-SUB-DAYS)
e. Difference between 2 dates
Code:
01 WS-DATE-DIFF PIC S9(08) COMP.
01 WS-DATE1 PIC 9(08).
01 WS-DATE2 PIC 9(08).
COMPUTE WS-DATE-DIFF = FUNCTION INTEGER-OF-DATE(WS-DATE2) -
FUNCTION INTEGER-OF-DATE(WS-DATE1)
f. Get the last day of the month
The only difference for the last day of month will occur only on a leap year. So all we will do is to check the year is a leap year or not.
Code:
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
g. Difference between 2 timestamps in seconds
We can use the language environment callable service CEESECS which will convert timestamp to seconds.
01 WS-SECOND1 COMP-2.
01 WS-SECOND2 COMP-2.
01 WS-TIMESTAMP-1 PIC X(26).
01 WS-TIMESTAMP-2 PIC X(26).
01 WS-FORMAT PIC X(26).
01 WS-DIFFERENCE PIC +9(09).
01 WS-FC-CODE.
05 FC-SEVERITY PIC S9(4) COMP.
05 FC-MESSAGE PIC S9(4) COMP.
05 FILLER PIC X(08).
MOVE '2004-03-23-15.35.39.838149' TO WS-TIMESTAMP-1
MOVE '2004-05-17-13.07.18.234567' TO WS-TIMESTAMP-2
MOVE 'YYYY-MM-DD-HH.MI.SS.999999' TO WS-FORMAT
CALL 'CEESECS' USING WS-TIMESTAMP-1,
WS-FORMAT,
WS-SECOND1,
WS-FC-CODE
IF FC-SEVERITY = +0
CONTINUE
ELSE
DISPLAY 'CEESECS ROUTINE ERROR'
PERFORM INHOUSE-ABEND-ROUTINE
END-IF
CALL 'CEESECS' USING WS-TIMESTAMP-2,
WS-FORMAT,
WS-SECOND2,
WS-FC-CODE
IF FC-SEVERITY = +0
CONTINUE
ELSE
DISPLAY 'CEESECS ROUTINE ERROR'
PERFORM INHOUSE-ABEND-ROUTINE
END-IF
COMPUTE WS-DIFFERENCE = WS-SECOND2 - WS-SECOND1
DISPLAY 'THE DIFFERENCE BETWEEN 2 TIMESTAMPS IS:'
WS-DIFFERENCE
Code:
01 WS-GREGORIAN-DATE PIC 9(08).
01 WS-JULIAN-DATE PIC 9(07).
COMPUTE WS-JULIAN-DATE = FUNCTION DAY-OF-INTEGER
(FUNCTION INTEGER-OF-DATE
(WS-GREGORIAN-DATE))
COMPUTE WS-GREGORIAN-DATE = FUNCTION DATE-OF-INTEGER
(FUNCTION INTEGER-OF-DAY
(WS-JULIAN-DATE))
b. Find if the year is a leap year
Code:
01 WS-YEAR PIC 9(04).
EVALUATE TRUE
WHEN FUNCTION MOD (WS-YEAR 4) NOT ZERO
WHEN FUNCTION MOD (WS-YEAR 100) ZERO
AND FUNCTION MOD (WS-YEAR 400) NOT ZERO
DISPLAY 'IT IS NOT A LEAP YEAR ' WS-YEAR
WHEN OTHER
DISPLAY 'IT IS A LEAP YEAR ' WS-YEAR
END-EVALUATE
c. Add days to given gregorain date
Code:
01 WS-ADVANCE-DATE PIC 9(08).
01 WS-ADD-DAYS PIC 9(08).
01 WS-GREGORIAN-DATE PIC 9(08).
COMPUTE WS-ADVANCE-DATE = FUNCTION DATE-OF-INTEGER
(FUNCTION INTEGER-OF-DATE(WS-GREGORIAN-DATE) + WS-ADD-DAYS)
d. Subtract days to given gregorain date
Code:
01 WS-GREGORIAN-DATE PIC 9(08).
01 WS-SUB-DAYS PIC 9(08).
01 WS-RETARD-DATE PIC 9(08).
COMPUTE WS-RETARD-DATE = FUNCTION DATE-OF-INTEGER
(FUNCTION INTEGER-OF-DATE(WS-GREGORIAN-DATE) - WS-SUB-DAYS)
e. Difference between 2 dates
Code:
01 WS-DATE-DIFF PIC S9(08) COMP.
01 WS-DATE1 PIC 9(08).
01 WS-DATE2 PIC 9(08).
COMPUTE WS-DATE-DIFF = FUNCTION INTEGER-OF-DATE(WS-DATE2) -
FUNCTION INTEGER-OF-DATE(WS-DATE1)
f. Get the last day of the month
The only difference for the last day of month will occur only on a leap year. So all we will do is to check the year is a leap year or not.
Code:
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
g. Difference between 2 timestamps in seconds
We can use the language environment callable service CEESECS which will convert timestamp to seconds.
01 WS-SECOND1 COMP-2.
01 WS-SECOND2 COMP-2.
01 WS-TIMESTAMP-1 PIC X(26).
01 WS-TIMESTAMP-2 PIC X(26).
01 WS-FORMAT PIC X(26).
01 WS-DIFFERENCE PIC +9(09).
01 WS-FC-CODE.
05 FC-SEVERITY PIC S9(4) COMP.
05 FC-MESSAGE PIC S9(4) COMP.
05 FILLER PIC X(08).
MOVE '2004-03-23-15.35.39.838149' TO WS-TIMESTAMP-1
MOVE '2004-05-17-13.07.18.234567' TO WS-TIMESTAMP-2
MOVE 'YYYY-MM-DD-HH.MI.SS.999999' TO WS-FORMAT
CALL 'CEESECS' USING WS-TIMESTAMP-1,
WS-FORMAT,
WS-SECOND1,
WS-FC-CODE
IF FC-SEVERITY = +0
CONTINUE
ELSE
DISPLAY 'CEESECS ROUTINE ERROR'
PERFORM INHOUSE-ABEND-ROUTINE
END-IF
CALL 'CEESECS' USING WS-TIMESTAMP-2,
WS-FORMAT,
WS-SECOND2,
WS-FC-CODE
IF FC-SEVERITY = +0
CONTINUE
ELSE
DISPLAY 'CEESECS ROUTINE ERROR'
PERFORM INHOUSE-ABEND-ROUTINE
END-IF
COMPUTE WS-DIFFERENCE = WS-SECOND2 - WS-SECOND1
DISPLAY 'THE DIFFERENCE BETWEEN 2 TIMESTAMPS IS:'
WS-DIFFERENCE
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.