×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

COBOL General discussion FAQ

Functions

Code for leap-year check using intrinsic functions by CliveC
Posted: 12 Dec 01 (Edited 2 Aug 02)

       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.

Back to COBOL General discussion FAQ Index
Back to COBOL General discussion Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close