how can i validate two dates

695 pts.
Tags:
RPG
RPG/400
hi, I want to validate two dates of type (date1=L) and (date2=char length is 8A ) can any one help me
ASKED: June 9, 2008  5:05 AM
UPDATED: April 25, 2010  10:30 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

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

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Sloopy
    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 pointsBadges:
    report
  • graybeard52
    >> 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 pointsBadges:
    report
  • Sloopy
    Sorry, Greybeard - I assumed that the TEST opcode was not available in free-format - but it is. :-)
    2,195 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following