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

Date passing validation but bombing when moved into a date field 4

Status
Not open for further replies.

Reaper73

Programmer
Jun 20, 2005
11
US
I have an 8 char field with iso dates in it(20061030). My problem is this. The following date was in the field and passed validation but the program bombed when it tried to move the date into a date field.

Example:
8 char field (ISODATE): '2061031 '
rpg date field (RPGDATE) in *MDY format

c *iso0 Test(d) ISODATE 50
c If *in50=*on
c do something
c Endif

c *iso0 Move ISODATE RPGDATE

The test will not fail but the move will. I've tried this in free format with %DATE BIF and the RPGDATE field is loaded with '2061-03-01'.

Can some one explain what I am missing?

Thanks in advance.
 
You left a zero out - shouldn't '2061031 ' be '20061031'?

'2061031' is only valid for the format *LONGJUL (January 31, 2061).

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

 
No you miss understood me. The date in the field is '2061031 ' and it passes the test date op code for ISO.

Anyway I found the answer to the problem.

The test op code tested the date as 2061-03-01(don't ask me
where the 0 between the 3 and 1 came from) which is a valid date. However when the program tried to convert this to a MDY RPG date field it crashed. The reason for this is that the range for valid years for MDY date fields is 1940-2039 and the valid year range for ISO date fields is 0001-9999. You can find this in the ILE RPG Programming Reference for V5R3 chapter 10 under Date Data Type.

I believe this to be a problem within RPG itself. You shouldn't have something pass validation if it can not be used properly elsewhere.
 
The validation is working as designed. When you specify *ISO0, TEST(D). it checks the first 4 bytes for a valid year, the next two for a valid month, and the last two for a valid day within that month and year (including leap year rules for February). Apparently it just puts leading zeros on the day part of the tempoarary field it creates to do the validation.

You can make your validation a little more stringent by:

Code:
If        *in50=*on [b]or %len(%trim(ISODATE) < %len(isodate)[/b]

That will make sure that there are no blanks in ISODATE.

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

 
or if %check( '0123456789' : ISODATE ) > 0; // error
 
mercury2,

Actually, yours is a better way - it ensures that the date is numeric with no alpha or special characters.

Have another star.

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

 
... or, you could write a module (or service program) that looks like this (I did this before /FREE was an option):

P NumericData B export
D PI n
D DataToCheck 256 varying const

* Stand-alone fields
D ValidNumeric s n inz(*off)

* Determine if field strictly contains numbers
C if check('1234567890':DataToCheck) = *zero
C eval ValidNumeric = *on
C endif
C return ValidNumeric

P E


Then, say "if ValidNumeric(ISODATE)"...

This will allow you to easily use in other applications
 
Sorry... meant to say "if NumericData(ISODATE)"...
 
bwtc,

That beats the heck out of TESTN, for certain.

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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top