• ILE COBOL intrinsic function error handling

    From Jonathan Ball@21:1/5 to All on Mon Nov 12 21:21:23 2018
    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?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jonathan Ball@21:1/5 to Jonathan Ball on Mon Nov 12 22:56:35 2018
    On 11/12/2018 9:21 PM, Jonathan Ball wrote:
    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?

    What I'd like is something like an RPGLE MONITOR block:

    monitor;
    rcv_date = %date(indate:*mdy0);
    error_sw = 'N';
    on-error;
    error_sw = 'Y';
    endmon;

    I could probably sneak an RPGLE program/module into the mix and get away
    with it, but it's largely an IBM i COBOL arena, and I'd prefer to stick
    with it.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jon Paris@21:1/5 to All on Tue Nov 13 08:17:17 2018
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jonathan Ball@21:1/5 to Jon Paris on Wed Nov 14 17:40:49 2018
    On 11/13/2018 8:17 AM, Jon Paris wrote:
    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.


    Thanks for the suggestions. Speed was of the essence, so I wrote an
    RPGLE module incorporating what I suggested earlier:

    monitor;
    rcv_date = %date(indate:*mdy0);
    error_sw = 'N';
    on-error;
    error_sw = 'Y';
    endmon;

    It works great and is many times faster than the CLP that was using CVTDAT.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)