Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code for leap-year check using intrinsic functions

Functions

Code for leap-year check using intrinsic functions

by  CliveC  Posted    (Edited  )
IDENTIFICATION DIVISION.
PROGRAM-ID. LEAPYEAR.
AUTHOR. CLIVE CUMMINS.
INSTALLATION. http://tubularity.com
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WORK-AREAS.
05 YEAR-IN-QUESTION PIC X(4).
05 LEAP-YEAR-SW PIC X(1).
88 LEAP-YEAR VALUE "Y".
05 WORK-DATE.
10 WORK-DATE-CCYY PIC 9(4).
10 WORK-DATE-MM PIC 9(2).
10 WORK-DATE-DD PIC 9(2).
05 WORK-DATE-NUM PIC 9(8).
05 WORK-DATE-INTEGER PIC 9(8).
PROCEDURE DIVISION.
ACCEPT YEAR-IN-QUESTION FROM COMMAND-LINE.
IF YEAR-IN-QUESTION NUMERIC
PERFORM CHECK-LEAP-YEAR
ELSE
DISPLAY "NON NUMERIC YEAR WAS INPUT".
GOBACK.
CHECK-LEAP-YEAR.
MOVE YEAR-IN-QUESTION TO WORK-DATE-CCYY.
MOVE 3 TO WORK-DATE-MM.
MOVE 1 TO WORK-DATE-DD.
MOVE WORK-DATE TO WORK-DATE-NUM.
MOVE FUNCTION INTEGER-OF-DATE (WORK-DATE-NUM)
TO WORK-DATE-INTEGER.
SUBTRACT 1 FROM WORK-DATE-INTEGER
MOVE FUNCTION DATE-OF-INTEGER (WORK-DATE-INTEGER)
TO WORK-DATE-NUM.
MOVE WORK-DATE-NUM TO WORK-DATE.
IF WORK-DATE-DD EQUAL 29
MOVE "Y" TO LEAP-YEAR-SW
ELSE
MOVE "N" TO LEAP-YEAR-SW.
DISPLAY YEAR-IN-QUESTION.
DISPLAY "LEAP-YEAR".
DISPLAY LEAP-YEAR-SW.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top