Field validation in AS/400

2610 pts.
Tags:
AS/400
AS/400 Fields
RPGLE
Hi, I want to throw error messages based on following validation on the display screen. 1) If field type is character and it's length is 50 and if someone put numeric value in it's first position then error message should be populated as following:-
"The value of 1 is not valid for this field"
It should accept only character value on it's first position and then from second position onwards. It should be able to accept any value in it including blanks. Any help with RPGLE program code would be much appreciated. Thanks


Software/Hardware used:
AS/400
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 18  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.
  • TheRealRaven
    What problem are you seeing? What code do you have so far? Is "!" valid in the first position? What about "<" or "?"?
    35,240 pointsBadges:
    report
  • 6r

    every thing is valid except numeric value  and blank value at first position and if some one put any value except character value then error message should be like "

    "The value of  ? is not valid for this field"

    another few examples :-for example if 2 is placed on first position then error message should be like:-

    "The value of 2 is not valid for this field"

    for example if 3 is placed on first position then error message should be like:-

    "The value of 3 is not valid for this field"

    for example if ? is placed on first position then error message should be like:-

    "The value of ? is not valid for this field"

    for example if ' is placed on first position then error message should be like:-

    "The value of ' is not valid for this field"

    for example if # is placed on first position then error message should be like:-

    "The value of # is not valid for this field"


    for example if @ is placed on first position then error message should be like:-

    "The value of @ is not valid for this field"

    Thanks

     

    2,610 pointsBadges:
    report
  • pdraebel
    You have to make a message with variable message data in it. The Message data is to get the erroneous characters into the message.
    Use QMHSNDMSG API to send the messages.
    7,545 pointsBadges:
    report
  • 6r

    Can someone please explain with program coding.

    Thanks

    2,610 pointsBadges:
    report
  • philpl1jb

     FirstChar is an alpha 1 long.  InString is your input value

    I'm assuming that you want the first char to be an ALPHA (A-Z)

    FirstChar = %subst( InString : 1 : 1);


    if FirstChar < 'A' or First Char > 'Z'

       ErrMsg = 'The value of  ' + FirstChar + ' is not valid for this field'



    54,090 pointsBadges:
    report
  • WilsonAlano
    Hi,

    Look for %Check() BIF to find the erroneous character and use ERRMSGID with message data on display file to display what you want.
    It's a little bit complicated to put an example here. Read the manuals and you you will find the soluction.

    Wilson
    2,710 pointsBadges:
    report
  • TheRealRaven

    every thing is valid except numeric value  and blank value at first position and if some one put any value except character value then error message should be like "

    "The value of  ? is not valid for this field"

    That is self-contradictory. First you say that only numerics and blanks are invalid, but then you show that a non-numeric character is invalid.

    Use %SUBST() to examine a one-character substring at the beginning of the 50-char variable. You can test the %SUBST() value with %CHECK() to see if the single character is in your list of valid characters.

    35,240 pointsBadges:
    report
  • TheRealRaven
    Coding [ FirstChar < 'A' or First Char > 'Z' ] might miss a number of invalid characters. The upper-case letters run as x'C1' to x'C9', then x'D1' to x'D9', and finally x'E2 to x'E9'. Invalid values are from x'CA' to x'D0' and x'DA' to x'E1'. By testing the range 'A' through 'Z', potential invalids could pass through.

    Unlikely in DSPF validation, but the code can apply to general validation. An explicit list of valid (or invalid) characters is better if gaps in (hex) values exist.
    35,240 pointsBadges:
    report
  • philpl1jb

    Thanks Real, I missed that point somewhere in the distant past.

    Looks like you create a string or constant of valid characters and use the %Check function .. as described above.


    54,090 pointsBadges:
    report
  • 6r

    and if someoneinput non numeric value then error message should be " attempted to input non numeric value in this field" then how to code for this?

    Thanks

     

    2,610 pointsBadges:
    report
  • TheRealRaven
    How is the input field defined?
    35,240 pointsBadges:
    report
  • pdraebel
    Assuming the input field is capable of Alfa input you would need a string with the valid numeric characters. %CHECK to see if invalid characters were entered and send the error message if the operator did enter Invalid Characters.
    7,545 pointsBadges:
    report
  • 6r

    It's packed field.

    Thanks

    2,610 pointsBadges:
    report
  • WilsonAlano
    Hi,

    Real, you don't need %SUBST to find the erroneous character. From ILE RPG  Manual
    "%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."

    6r, how can it be packed and have alphanumeric values on it?
    2,710 pointsBadges:
    report
  • TheRealRaven
    @WilsonAlano, Since only the first character of a 50-char variable is to be checked, a substring is needed.

    True, %SUBST() isn't specifically needed since a 1-char variable could OVERLAY the first character, or a MOVE or EVAL could be done into a second 1-char variable or some other method could be used to isolate that single character.

    But %CHECK() by itself against the 50-char variable isn't sufficient. A substring needs to be specified. %SUBST() seems most clear in intent in basic code.
    35,240 pointsBadges:
    report
  • TheRealRaven
    Hmmm... but thinking deeper, %CHECKR() might be used if start is set to (1). That should work in place of a substring.
    35,240 pointsBadges:
    report
  • pdraebel
    %CHECK would work. If the outcome is 1 than the error message should get triggered. I am not sure if that solution is the more performant though.
    7,545 pointsBadges:
    report
  • TheRealRaven
    I see what you're saying. Run the %CHECK() over the entire 50 characters and ignore errors that return a position greater than (1). The result is that the "substring" becomes hidden in the logic.

    Though it would technically work, it still relies on a "substring". But it also makes it more difficult for later developers who need to understand clearly what's being done.

    That could be compounded if the 49-character portion also needs its own separate %CHECK() with a longer valid-characters list. (And I suppose that could also run over the full field if errors that return (1) are ignored.)

    But you are right -- %CHECK() is technically sufficient.
    35,240 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.

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

Following

Share this item with your network: