ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Date Validation and Conversion in COBOL 400

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Date Validation and Conversion in COBOL 400

    Hi,

    We are using ILE COBOL for programming. We need to perform Date validation and conversion in ILE COBOL.

    I know we have intrinsic functions such as TEST-DATE-TIME and CONVERT-DATE-TIME but we could not see much examples in IBM reference manual so wanted to check if someone can help us with code sample.

    We need to check if the character variable has valid date or not and then convert the date into MMDDYY format if it is valid.

    Character variable can have date in the formats MMDDYYYY or MM-DD-YYYY or MM/DD/YY etc.

    Please let us know if there is any sample code which does the above checks and validation.

    Thanks in advance.

    Thanks,
    Ravindra

  • #2
    Re: Date Validation and Conversion in COBOL 400

    Since your date format can have different layouts, you could always use a numeric class test in conjunction with reference modification...probably take a couple minutes or less to pound out the code and check for the three examples you provided.

    Comment


    • #3
      Re: Date Validation and Conversion in COBOL 400

      (Yeah, I know it's old. But no one posted examples.) Here are a few simple examples based on the suggested formats:
      Code:
             WORKING-STORAGE SECTION.
      
             01  OK                          pic x(1).
             01  DATE-chk                    pic x(10).
      
             Procedure Division.
      
             00-Main-driver.
      
                 move    "01-31-2013"    to  DATE-chk
                 if function TEST-DATE-TIME (DATE-chk DATE '%m-%d-%Y') = B'1'
                     display "01-31-2013 is OK".
      
                 move    '01/31/2013'    to  DATE-chk
                 if function TEST-DATE-TIME (DATE-chk DATE '%m/%d/%Y') = B'1'
                     display "01/31/13 is OK 1".
      
                 move    '01/31/13'      to  DATE-chk
                 if function TEST-DATE-TIME (DATE-chk DATE '%m/%d/%y') = B'1'
                     display "01/31/13 is OK 1".
                 if function TEST-DATE-TIME (DATE-chk DATE '%D') = B'1'
                     display "01/31/13 is OK 2".
      
                 move    '01312013'      to  DATE-chk
                 if function TEST-DATE-TIME (DATE-chk DATE '%m%d%Y') = B'1'
                     display "01312013 is OK".
      
                 ACCEPT OK  .
      
                 goback.
             00-Main-driver-exit.  exit.
      The DATE 'format' characters can be found in Table 5 of the FORMAT clause in the COBOL Reference. Comparing characters from here against the table should clear up how they work.

      Tom
      Tom

      There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

      Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

      Comment

      Working...
      X