TestN in free format -- is this the proper way? - IBM AS400

This is a discussion on TestN in free format -- is this the proper way? - IBM AS400 ; How do I perform the equivalent of the TestN operation in /free? Here's what I'm going to try to do: D-Specs D fieldAlpha S 7A D fieldNumeric S 7S 0 C-Specs /free Monitor; fieldNumeric = fieldAlpha; On Error nnnn; (Error ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: TestN in free format -- is this the proper way?

  1. TestN in free format -- is this the proper way?

    How do I perform the equivalent of the TestN operation in /free?

    Here's what I'm going to try to do:

    D-Specs
    D fieldAlpha S 7A
    D fieldNumeric S 7S 0

    C-Specs
    /free
    Monitor;
    fieldNumeric = fieldAlpha;
    On Error nnnn;
    (Error handling goes here)
    EndMon;
    /end-free

    A couple questions/comments:
    1) Is this the proper way to do this?
    2) The only valid test would be if the GT ind were turned on. In other
    words if this were non-free:
    gt lt eq
    C TestN myAlpha 31 32 33
    Only if ind 31 were turned on would the TestN be a valid result -- no
    spaces allowed.
    3) So... I need to identify the error code(s) that would be returned
    (i.e. nnnn in my "On Error" code above) for:
    * Field is not numeric
    * Field contains blanks

    Thanks in advance!


  2. Re: TestN in free format -- is this the proper way?

    Chipper:

    If %Check('0123456789' : FieldAlpha) = 0
    // contains non-numeric data
    Else
    // contains numeric data
    Endif

    From the manual:
    %CHECK(comparator : base {: start})
    %CHECK returns the first position of the string base that contains a
    character that does not appear in string comparator. If all of the
    characters in base also appear in comparator, the function returns 0.

    Good Luck
    Bill


    "Chipper Miller" wrote in message
    news:1162502221.504985.21840@f16g2000cwb.googlegro ups.com...
    > How do I perform the equivalent of the TestN operation in /free?
    >
    > Here's what I'm going to try to do:
    >
    > D-Specs
    > D fieldAlpha S 7A
    > D fieldNumeric S 7S 0
    >
    > C-Specs
    > /free
    > Monitor;
    > fieldNumeric = fieldAlpha;
    > On Error nnnn;
    > (Error handling goes here)
    > EndMon;
    > /end-free
    >
    > A couple questions/comments:
    > 1) Is this the proper way to do this?
    > 2) The only valid test would be if the GT ind were turned on. In other
    > words if this were non-free:
    > gt lt eq
    > C TestN myAlpha 31 32 33
    > Only if ind 31 were turned on would the TestN be a valid result -- no
    > spaces allowed.
    > 3) So... I need to identify the error code(s) that would be returned
    > (i.e. nnnn in my "On Error" code above) for:
    > * Field is not numeric
    > * Field contains blanks
    >
    > Thanks in advance!
    >




  3. Re: TestN in free format -- is this the proper way?

    Bill --

    Thank you very much for your help! It never occurred to me to utilize
    the %Check Bif.

    -- Chipper


    Bill wrote:
    > Chipper:
    >
    > If %Check('0123456789' : FieldAlpha) = 0
    > // contains non-numeric data
    > Else
    > // contains numeric data
    > Endif
    >
    > From the manual:
    > %CHECK(comparator : base {: start})
    > %CHECK returns the first position of the string base that contains a
    > character that does not appear in string comparator. If all of the
    > characters in base also appear in comparator, the function returns 0.
    >
    > Good Luck
    > Bill
    >
    >
    > "Chipper Miller" wrote in message
    > news:1162502221.504985.21840@f16g2000cwb.googlegro ups.com...
    > >


    << snip >>


  4. Re: TestN in free format -- is this the proper way?

    You could also do it this way. This has the added advantage that
    fieldAlpha CAN have decimals, negative sign, and blanks.


    /free
    Monitor;
    fieldNumeric = %dec(fieldAlpha,9,2);
    On Error;
    (Error handling goes here)
    EndMon;
    /end-free


+ Reply to Thread