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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Validation

Status
Not open for further replies.

jsplice

Programmer
Jun 3, 2003
88
US
I found a thread dealing with date validation, but it is "in the archives," therefore I cannot post a reply to it. Anyhow, the thread I saw dealt with validating Dates entered on the display side. However, I need to validate a date on the RPG IV side. If I have an 8 digit date field that is coming from a file, can I simply move this value into an internal date field and have the system validate for me? If I get an error during the move, how would I catch this error without having the whole program crash? I wrote a simple process that will just validate the year to make sure it's between 1900 and 9999, the month is between 1-12, and the day is between 1-31. Obviously this won't work if someone enters a date of 02/31/2006 because it doesn't fully validate. Any suggestions?
 
This works for *USA dates. The date range here must be 1900 through 2899, because we use CYYMMDD dates in our database:

Code:
         Test(De) *USA Indate;                                         
         If Not %ERROR And (%SUBDT(%DATE(Indate:*USA):*YEARS) < 1900 Or
           %SUBDT(%DATE(Indate:*USA):*YEARS) > 2899);                  
           Date_OK = *OFF;                                                
         Else;                                                         
           Date_OK = (Not %ERROR);                                        
         Endif;

(Date_OK is an indicator).

Feles mala! Cur cista non uteris? Stramentum novum in ea posui!

 
Assumong you are on V5R1 or later, use the Monitor, On-Error, and Endmon opcodes to trap for errors in the move. But if you validate them like my example, you won't have any problems.

Feles mala! Cur cista non uteris? Stramentum novum in ea posui!

 
You can do it 2 ways. Either use TEST(D) command or use Monitor

MONITOR
EVAL DateField = %date(NumericField:*MDY)
ON-ERROR
-- your error specs --
ENDMON

The trick is to get the date format specified as the format of the imput field. The actual format of the date field doesn't matter.
 
*MDY has a 2-digit year (MM/DD/YY); *USA uses a 4 digit year (MM/DD/YYYY).

Feles mala! Cur cista non uteris? Stramentum novum in ea posui!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top