695 pts.
 how can i validate two dates
hi, I want to validate two dates of type (date1=L) and (date2=char length is 8A ) can any one help me

Software/Hardware used:
ASKED: June 9, 2008  5:05 AM
UPDATED: April 25, 2010  10:30 PM

Answer Wiki:
Validate that's is a true date? True date fields must contain real dates. You cannot enter a "bad" date in a date field. To test the 8A date field - there are two ways 1. use the TEST(D) command 2. Use MONMSG, for example MONMSG EVAL datefield = %date(charfield:*MDY/) ON-ERROR .... send error message .... ENDMON The date format parm may need to be chnaged to whatever format the char field has. I usually use the MONMSG if the error condition is hardly ever goning to happen, and I need the datefield anyway. Its got more overhead than the TEST(D). ================================================================ One way to "validate" a Date field is to use INSERT or UPDATE to write the value to the file. SQL will validate on input to a file and won't allow you to put values into columns that violate the data type. Standard I/O validates on reads. Validation on input happens once. Validation on read happens every read. IOW, if you spend cycles and programmer time doing the validation, the CPU cycles are going to be automatically spent again if INSERT/UPDATE is used. And you still need to code for SQL error conditions anyway. Additional validation for other fields/columns should probably also be done by SQL, or at least by DB2. Essentially anything that could be done with DDS (and more) can be done with constraints, e.g., ADD CONSTRAINT REVENUE CHECK (SALARY + COMM > 30000) can ensure that SALARY and COMM can't be updated or inserted with a value that isn't greater than 30000 for the sum of the two. This ensures that DFU, CPYF, whatever, won't be corrupting your database; and you don't need to add any code except to test for errors on output and displaying any errors to the user. Rather than coding specific tests for each field and making database maintenance programs complex, just issue the I/O statement and report errors. Tom
Last Wiki Answer Submitted:  April 25, 2010  10:30 pm  by  graybeard52   3,115 pts.
All Answer Wiki Contributors:  graybeard52   3,115 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Please pardon my correction Graybeard, but that’s MONITOR, not MONMSG.

The decision whether to use TEST (D) or MONITOR may also be affected by whether you use free-format RPG or standard fixed-format. I don’t use free-format, but I have still used the MONITOR method, especially when I have to check and then compare two dates, since the code I need to write to process the exception is more complex using TEST (D) than MONITOR in that case.

Sloopy

 2,195 pts.

 

>> but that’s MONITOR, not MONMSG <<
Thanks!

>> may also be affected by whether you use free-format RPG or standard fixed-format. <<
Why? What’s the difference ?

 3,115 pts.

 

Sorry, Greybeard – I assumed that the TEST opcode was not available in free-format – but it is.

:-)

 2,195 pts.