Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

caslan (MIS)
30 Oct 01 21:37
I'M CURRENTLY WORKING ON AN INTERACTIVE PROGRAM PROJECT AND I WAS WANTING TO USE A COBOL FUNCTION TO TEST IF A DATE WAS A VALID DATE.  IS THERE ANY FUNCTION THAT ALLOWS THIS? MY SEARCH THUS FAR HAS BEEN FRUITLESS.
RonaldB (Programmer)
31 Oct 01 8:54
caslan,

first, please turn off your caps lock.
Second, there is no COBOL function that i know of that validates a date, other then maybe those added to the standard by a specific compiler manufacturer.
In my case, a separate utiliy program is used to perform date functions, which can be called from any COBOL program. If nothing like this is available already it will have to be constructed.

Regards,
Ronald.
BigMag (IS/IT--Management)
31 Oct 01 9:30
Mean and dirty:

use DB2 to validate

M.

(It wasn't me who said that!)

BigMag, The Netherlands.
someone@euronet.nl (no kidding!)

ceh4702 (Programmer)
31 Oct 01 15:59
The COBOL standard doesnt really have an intrinsic function that specifically tests the validity of a date.  There may be some compilers that have added functionality that can do that.  

There are some Intrinsic functions that do things like convert a date to a julian.  It might be possible to build a program that can be called to test dates or use DB2 to test dates if you can use that.  This is really a sorely needed function.  Probably the only reason COBOL doesnt have one built in, is that mission critical data is usually in a database that has that capability.

This doesnt help you much if you can't afford a big database package.

If you do not like my post feel free to point out your opinion or my errors.

NinaToo (Programmer)
1 Nov 01 10:30
Let me add to the other answers here. Both shops that I have worked at, my present shop and my previous shop, have had utility programs to call for checking date validity. I believe that such utility programs are commercially available.

However, as RonaldB said, you could construct your own utility program.

In order to construct your own program, first you need to figure out what date formats you will be using.

Will it be MM/DD/YYYY or else MM/DD/YY (with all digits).

Or it could be MONTH (spelled out) and then your date, then your year (either 2 digits or 4 digits). Example: "December 25, 2001"

Or else there is the Julian date format, which is formatted as CCYYDDD i.e. "1999364" which would be the year 1999 and the 364th day in that year -- which would be Dec. 30, 1999. This format is frequently used for elapsed time applications, as the dates can be directly subtracted from each other.

The utility program at my previous shop was written in-house. And first, the programmer would specify the format, and then the date would be passed. This program not only validated dates but would convert dates from one format to another.

After you decide on the format of the date to be validated, then each program must make sure that each date to be validated is in the proper format. Then code the program call so that the date will be passed to the utility program which you have constructed.

As far as constructing a utility program, I have a few ideas. The parameter of MONTHS could be specified as a SPECIAL-NAMES set of data, then code in the 12 months in whatever format you are using. Call this special name 'VALID'. Later on, the programmer can test the month against this constructed data-type i.e. IF TEST-MONTH VALID CONTINUE ELSE [do error routine].

The dates and years wouldn't need a SPECIAL-NAMES set, you could compare the passed data to the valid range of numerical values for either the day or the year.

Hope this helps, Nina Too

ceh4702 (Programmer)
1 Nov 01 12:37
We made a program in JAVA in which we had to make our own date object from scratch and validate it.  We used rule-based design techniques, to cover every possible combination.  It wasnt too hard, but takes careful thought and a logical approach.  Java has date objects built in, but we were suppose to do it the hard way and document all of the rules, because it was a software design class.

We also looked at the three inmates and 5 hats game.   That gets pretty interesting.  Maybe I will see if I have that at home.

If you do not like my post feel free to point out your opinion or my errors.

saginaw (Programmer)
2 Nov 01 1:26
I do not know of a COBOL or intrinsic function that provides a date validation routine. I have written callable programs that will validate, format and convert various dates. The following URL is more than what you were requesting but might be helpful.

http://www.simotime.com.cbldat01.htm

You can view the example on-line and then download the source code for free and it contains reasonable documentation.

Good Luck,

Saginaw
helpdesk@simotime.com
http://www.simotime.com

saginaw (Programmer)
2 Nov 01 1:28
Sorry, I got the URL wrong in the previous note...

http://www.simotime.com/cbldat01.htm

Better luck this time

Saginaw
helpdesk@simotime.com
http://www.simotime.com

CliveC (Programmer)
21 Nov 01 11:42
You can use intrinsic date function to test for a leap year which of course would only affect february. Take the Mar 1st date for the giving year, call to convert to integer date, subtract 1 and call to convert back. You will get either 29 or 28.
CliveC (Programmer)
21 Nov 01 16:32
I meant to include this example:       
IDENTIFICATION DIVISION.
       PROGRAM-ID.    LEAPYEAR.
       AUTHOR.        Clive Cummins.
       INSTALLATION.  www.tubularity.com
       DATE-WRITTEN.  Nov 21, 2001.
       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.
           EXHIBIT NAMED LEAP-YEAR-SW.

slade (Programmer)
22 Nov 01 13:19
Hi Clive,

Just curious; you use intrinsic functions, an LE COBOL feature, then end the code w/EXHIBIT which was dropped in COBOLII (I don't know the non-IBM M/F equiv versions).

Was this a misprint or is EXHIBIT still supported in your version of COBOL?

Thanx, Jack.
slade (Programmer)
22 Nov 01 21:32
Hi Caslan,

The key to verifying a date is the "30 days hath September.." part. That and the leap year calc.

What follows is what I use to do that.

Once you validate the month, you can use it as an index (subscript) into the table shown below. Yuo then use the table value to verify the DD portion of your date.

Regards, Jack.


           05  WS-DST-START-LONG.
               10  WDS-CCYY.
               20  WDS-CC                     PIC 9(02) VALUE 19.
               20  WDS-YY                     PIC 9(02).
               10  WDS-CCYY-NUM REDEFINES
                   WDS-CCYY                             PIC S9(04).
               10  WDS-MM                     PIC 9(02) VALUE 04.
               10  WDS-DD                     PIC 9(02) VALUE 01.
           05  FILLER      REDEFINES
               WS-DST-START-LONG.
               10  FILLER                               PIC XX.
               10  WS-DST-START                         PIC X(08).

           05  WS-LEAP-YR-IND             PIC  X(01).
               88  ITS-A-LEAP-YR                     VALUE 'L'.
               88  ITS-NOT-A-LEAP-YR                 VALUE 'N'.

           05  WS-REMAINDERS.
               10  WR-REMAINDER-4         PIC S9(01) COMP.
               88  DIVISIBLE-BY-4                    VALUE +0.
               10  WR-REMAINDER-100       PIC S9(02) COMP.
               88  DIVISIBLE-BY-100                  VALUE +0.
               10  WR-REMAINDER-400       PIC S9(03) COMP.
               88  DIVISIBLE-BY-400                  VALUE +0.

           05  WS-WORK-DATE.
               10  WS-MONTH                   PIC XX      VALUE SPACES.
               10  FILLER                     PIC X       VALUE '/'.
               10  WS-DAY                     PIC XX      VALUE SPACES.
               10  FILLER                     PIC X       VALUE '/'.
               10  WS-YEAR                    PIC XX      VALUE SPACES.
           05  WS-IT-DATE.
               10  WS-YY                      PIC S99     VALUE 0.
               10  WS-MM                      PIC S99     VALUE 0.
               10  WS-DD                      PIC S99     VALUE 0.
1     /
      *===============================================================
      *==================    END OF MOMTH TABLE    ===================
      *===============================================================
      *    NOTE: THIS IS A GENERALIZED TABLE TO BE USED FOR DATE     *
      *          MANIPULATION. EACH ENTRY CONTAINS THE NAME OF THE   *
      *          MONTH AND THE NUMBER OF DAYS IN EACH MONTH AND ITS  *
      *          IMMEDIATE NEIGHBORS. THE JAN-PREV-EOM FIELD CON-    *
      *          TAINS THE NUMBER OF DAYS IN THE PREVIOUS DECEMBER.  *
      *          THE DEC-NEXT-EOM FIELD CONTAINS THE NUMBER OF DAYS  *
      *          IN THE NEXT JANUARY.                                *
      *
      *          IN LEAP YEARS THE USER MUST INCREMENT THE FOLLOWING *
      *          FIELDS BY ONE:                                      *
      *                         JAN-NEXT-EOM-VAL                     *
      *                         FEB-EOM-VAL                          *
      *                         MAR-PREV-EOM-VAL                     *
      *===============================================================

       01  END-OF-MONTH-VALUES.
      *========================
           05  JAN-VALUES.
               10  JAN-NAME                PIC X(009) VALUE
               'JANUARY'.
               10  JAN-EOM-VAL             PIC 9(002) VALUE 31.
               10  JAN-PREV-EOM-VAL        PIC 9(002) VALUE 31.
               10  JAN-NEXT-EOM-VAL        PIC 9(002) VALUE 28.
           05  FEB-VALUES.
               10  FEB-NAME                PIC X(009) VALUE
               'FEBRUARY'.
               10  FEB-EOM-VAL             PIC 9(002) VALUE 28.
               10  FEB-PREV-EOM-VAL        PIC 9(002) VALUE 31.
               10  FEB-NEXT-EOM-VAL        PIC 9(002) VALUE 31.
           05  MAR-VALUES.
               10  MAR-NAME                PIC X(009) VALUE
               'MARCH'.
               10  MAR-EOM-VAL             PIC 9(002) VALUE 31.
               10  MAR-PREV-EOM-VAL        PIC 9(002) VALUE 28.
               10  MAR-NEXT-EOM-VAL        PIC 9(002) VALUE 30.
           05  APR-VALUES.
               10  APR-NAME                PIC X(009) VALUE
               'APRIL'.
               10  APR-EOM-VAL             PIC 9(002) VALUE 30.
               10  APR-PREV-EOM-VAL        PIC 9(002) VALUE 31.
               10  APR-NEXT-EOM-VAL        PIC 9(002) VALUE 31.
           05  MAY-VALUES.
               10  MAY-NAME                PIC X(009) VALUE
               'MAY'.
               10  MAY-EOM-VAL             PIC 9(002) VALUE 31.
               10  MAY-PREV-EOM-VAL        PIC 9(002) VALUE 30.
               10  MAY-NEXT-EOM-VAL        PIC 9(002) VALUE 30.
           05  JUN-VALUES.
               10  JUN-NAME                PIC X(009) VALUE
               'JUNE'.
               10  JUN-EOM-VAL             PIC 9(002) VALUE 30.
               10  JUN-PREV-EOM-VAL        PIC 9(002) VALUE 31.
               10  JUN-NEXT-EOM-VAL        PIC 9(002) VALUE 31.
           05  JUL-VALUES.
               10  JUL-NAME                PIC X(009) VALUE
               'JULY'.
               10  JUL-EOM-VAL             PIC 9(002) VALUE 31.
               10  JUL-PREV-EOM-VAL        PIC 9(002) VALUE 30.
               10  JUL-NEXT-EOM-VAL        PIC 9(002) VALUE 31.
           05  AUG-VALUES.
               10  AUG-NAME                PIC X(009) VALUE
               'AUGUST'.
               10  AUG-EOM-VAL             PIC 9(002) VALUE 31.
               10  AUG-PREV-EOM-VAL        PIC 9(002) VALUE 31.
               10  AUG-NEXT-EOM-VAL        PIC 9(002) VALUE 30.
           05  SEP-VALUES.
               10  SEP-NAME                PIC X(009) VALUE
               'SEPTEMBER'.
               10  SEP-EOM-VAL             PIC 9(002) VALUE 30.
               10  SEP-PREV-EOM-VAL        PIC 9(002) VALUE 31.
               10  SEP-NEXT-EOM-VAL        PIC 9(002) VALUE 31.
           05  OCT-VALUES.
               10  OCT-NAME                PIC X(009) VALUE
               'OCTOBER'.
               10  OCT-EOM-VAL             PIC 9(002) VALUE 31.
               10  OCT-PREV-EOM-VAL        PIC 9(002) VALUE 30.
               10  OCT-NEXT-EOM-VAL        PIC 9(002) VALUE 30.
           05  NOV-VALUES.
               10  NOV-NAME                PIC X(009) VALUE
               'NOVEMBER'.
               10  NOV-EOM-VAL             PIC 9(002) VALUE 30.
               10  NOV-PREV-EOM-VAL        PIC 9(002) VALUE 31.
               10  NOV-NEXT-EOM-VAL        PIC 9(002) VALUE 31.
           05  DEC-VALUES.
               10  DEC-NAME                PIC X(009) VALUE
               'DECEMBER'.
               10  DEC-EOM-VAL             PIC 9(002) VALUE 31.
               10  DEC-PREV-EOM-VAL        PIC 9(002) VALUE 30.
               10  DEC-NEXT-EOM-VAL        PIC 9(002) VALUE 31.

       01  EOM-TABLE REDEFINES
           END-OF-MONTH-VALUES.
           05  ET-MONTHLY-ENTRY     OCCURS 012  TIMES.
               10  ET-MONTH-NAME           PIC X(009).
               10  ET-EOM                  PIC 9(002).
               10  ET-PREV-EOM             PIC 9(002).
               10  ET-NEXT-EOM             PIC 9(002).

      ******************************************************************
      *  DETERMINE IF ITS A LEAP YEAR
      ******************************************************************
           SET     ITS-NOT-A-LEAP-YR    TO  TRUE
           DIVIDE  WDS-CCYY-NUM         BY  +4
           GIVING  WS-BIT-BUCKET
           REMAINDER WS-REMAINDER-4

           DIVIDE  WDS-CCYY-NUM         BY  +100
           GIVING  WS-BIT-BUCKET
           REMAINDER WS-REMAINDER-100

           DIVIDE  WDS-CCYY-NUM         BY  +400
           GIVING  WS-BIT-BUCKET
           REMAINDER WS-REMAINDER-400

           IF DIVISIBLE-BY-400
              OR
              (DIVISIBLE-BY-4 AND NOT DIVISIBLE-BY-100)
              SET ITS-A-LEAP-YR    TO TRUE
           END-IF
      ******************************************************************
      *  IF LEAP YR ADJUST YTD AND CALENDAR BY ONE.
      ******************************************************************
           IF      ITS-A-LEAP-YR
           ADD          +1              TO  WS-DAYS-TO-APR1
                                            WS-DAYS-TO-OCT31
                                            ET-NEXT-EOM(1)
                                            ET-EOM(2)
                                            ET-PREV-EOM(3)
           END-IF
           .

  
Crox (Programmer)
23 Nov 01 4:14
In CA-REALIA COBOL old and new statements are supported if you use the REALIA dialect options.  

examples:

 DIALECT-REALIA3
 DIALECT-REALIA4  
 DIALECT-REALIA           
 DIALECT-REALIA-74
 DIALECT-ANSI85                                    
 DIALECT-ANS                                      
 DIALECT-OSVS                                        
 DIALECT-VS2                                        
 DIALECT-SAA
 DIALECT-REALIA4-74
 DIALECT-ANSI85M
 DIALECT-ANSI85I
 DIALECT-ANSI74HI HIGH INTERMEDIATE LEVEL COBOL AS THE BASIS
 DIALECT-ANSI74LI
 DIALECT-ANSI74L     

So in DIALECT-REALIA which is default, EXHIBIT NAMED is still supported.

Regards,

   Crox
CliveC (Programmer)
23 Nov 01 10:11
I was using Micro Focus COBOL. If you dont' specify a directive file you could probably write a letter and get it to compile.

OT. I have just joined this forum and I find that some posts containing code are unreadable. Is there something I could change to make them readable
upset (TechnicalUser)
13 Dec 01 14:56
Hi I am astudent of MIS so I have to take COBOL. I have to do a program for validation of department and also the displaying of month from from the tables. I can't figure it out can anyone help me.
NinaToo (Programmer)
13 Dec 01 17:04
upset wrote:
-----------------------
Hi I am astudent of MIS so I have to take COBOL. I have to do a program for validation of department and also the displaying of month from from the tables. I can't figure it out can anyone help me
-----------------------

Can you be more specific? What kinds of tables, do they come from files, or DB2 or some other database? Is this a batch or online program? Are you supposed to write a report?

Hmmm.... So you "have" to take COBOL. You know, I said that myself many years ago in school.

And now I'm making some pretty good bucks in the COBOL field, and the language is incredibly flexible. You can do anything with it, including designing and running web sites.

When I lost my job last year, I didn't have to do a whole lot to get a new one. Just posted my resume on a couple of web sites and voila! Loads of calls. Didn't have to worry about age discrimination, sex discrimination or any of that. All they were worried about was do I know how to code in COBOL? So now I have a new, better job with a government agency.

Nina Too
slade (Programmer)
16 Dec 01 10:34
Hi Clive,

Just noticed your OT. I have the Emoticons/Smileys and Process TGML buttons checked and haven't experienced that problem. Maybe that's you answer, else maybe someone else will help.

Regards, Jack.    

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

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