TEST-DATE-YYYYMMDD function tests whether a date in form (YYYYMMDD) is a valid date in the Gregorian calendar.
Argument to this function must be an integer and it should be of the form YYYYMMDD.
Function returns following values
- If the value of argument is less than 16010000 or greater than 99999999, the returned value is 1,which means the year is not within the range of 1601 to 9999.
- Returned value is 2, when the month is not within the range of 1 to 12.
- Returned value is 3, when the day is not valid for the given year and month.
- Otherwise, the returned value is 0 (zero) , which means the date is valid.
Sample COBOL code is below
IDENTIFICATION DIVISION.
PROGRAM-ID. DTCONV.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 WS-WORK-AREA.
05 WS-GREG-DATE PIC 9(10).
01 RC PIC 9(5).
PROCEDURE DIVISION.
******** Example 1
******** returns 0 because the date is valid
MOVE 19950215 TO WS-GREG-DATE
COMPUTE RC = FUNCTION TEST-DATE-YYYYMMDD(WS-GREG-DATE)
DISPLAY RC
******** Example 2
******** returns 1 because the year is invalid and the value of argument
******** is less than 16010000.
MOVE 12950215 TO WS-GREG-DATE
COMPUTE RC = FUNCTION TEST-DATE-YYYYMMDD(WS-GREG-DATE)
DISPLAY RC
******** Example 3
******** returns 1 because the year is invalid and the value of argument
******** is greater than 99999999.
MOVE 912950215 TO WS-GREG-DATE
COMPUTE RC = FUNCTION TEST-DATE-YYYYMMDD(WS-GREG-DATE)
DISPLAY RC
******** Example 4
******** returns 2 because the month is not within the range
******** of 1 to 12
MOVE 19921415 TO WS-GREG-DATE
COMPUTE RC = FUNCTION TEST-DATE-YYYYMMDD(WS-GREG-DATE)
DISPLAY RC
******** Example 5
******** returns 3 because the day is invalid
MOVE 19950240 TO WS-GREG-DATE
COMPUTE RC = FUNCTION TEST-DATE-YYYYMMDD(WS-GREG-DATE)
DISPLAY RC
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.