Maybe this is general ILE COBOL error handling, I don't know.
I'm trying to replace an inefficient call to an OPM CLP program that
uses CVTDAT to convert a date from *MDY to *YMD. The converted value is *not* used; the purpose of the call is only to see if the date in the parameter is a valid date value.
The calling program is currently OPM CBL, but it could easily be changed
to ILE CBLLE. I want to change the call to another ILE CBLLE program
that basically does the following:
move function convert-date-time
(Date-to-convert Date '%m%d%y')
to Rcv-date
Rcv-date is defined as:
77 Rcv-date format of date '%y%m%d'.
The conversion works great as long as Date-to-convert contains a valid
date in %m%d%y format (mmddyy). I'm *only* interested in calls where
the date is not valid. I want something like this:
move function convert-date-time
(Date-to-convert Date '%m%d%y')
to Rcv-date
on exception
move "Y" to error-sw
not on exception
move "N" to error-sw
end-move.
The MOVE statement doesn't allow the (NOT) ON EXCEPTION feature, so the
code fragment above won't work.
My IBM i COBOL skills are rusty, particularly with respect to ILE COBOL.
What is the easiest/cheapest/dirtiest way to handle the error if the
input date to the function won't convert?
Couple of options:
1) Write your own validation routine in COBOL
2) Use a date table and do a simple SQL/Keyed Read lookup to see if the key exists
3) Use the COBOL error response APIs to catch the exception and set a value which you subsequently check for the date validity. The routine doing the convert-date-time would need to be a nested program for that to work I guess.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 62:02:05 |
Calls: | 6,654 |
Files: | 12,200 |
Messages: | 5,331,623 |