How to prevent user from entering special characters (like symbols not visible in keyboard) in a text field (Character type) in AS400 ?? Visibly most of the time there is no issue for iseries/as400 in accepting it and saving it into the file but sometimes when the data is handled in downstream reporting system it get rejected with different error in their system. Is there a way to prevent from the entry point itself ?
eg: In Address field of a Customer, end user copy paste (ctrl + c ctrl + v ) details from a webpage or a document causing entry of junk characters or null values which get stored without issue but later cause problem in other reporting applications.
Not sure if you're asking how to find the characters within the program that accepts the data, or how to prevent all programs from writing such data. I'll assume it's the latter.
The only way I know to do this with certainty, is with a trigger program; the system doesn't have a blacklist of characters that are/not allowed in fields (and you wouldn't want that anyway).
Hopefully there are only a few tables (files) that concern you in this manner, and you could write a trigger program, to be attached BEFORE_UPDATE and BEFORE_INSERT for each table, that checks the fields in question and either:
If you have a lot of files like this, a generic trigger can be set up that will determine the layout of the table in question (the table name is a parameter to the trigger) using the Retrieve Fields API. Be wary of a performance hit.
Validate the screen field using the
%CHECK
function and display an error when invalid content is present.Alternately you could iterate through the screen field removing any characters which are not present in the allowed character set prior to saving the record.
Most issues related to invalid characters are listed here. You could use it on any character field with the %XLATE opcode. Example:
In your "D" specs use this...
And, in your code...