RPG Restrict user entry of the special character '|' in any Name fields or any data entry fields

781 Views Asked by At

I want to restrict the user from entering the special character '|' (pipe) in any name field or data entry fields.

The check should happen from the screen itself and not through RPG/RPGLE program (as described here

How to prevent user from entering special characters (like symbols not visible in keyboard) in a text field (Character type)?)

I have tried using the VALUES() function in the display file,which only allows those characters mentioned in the function; for ex.

VALUES('A' 'B'...)

and not keeping '|' in it to disallow it, but it becomes very restricted, as one might disallow something which he should not.

2

There are 2 best solutions below

0
On

I think the easiest method would be to do an edit check at runtime instead of trying to get your workstation to do the edit.

2
On
  1. Why should this edit check happen at all? Is it because you are exporting a table and the export routine doesn't escape the pipe? If so, fix the export routine!
  2. Having said that, there are plenty of reasons one really doesn't want special characters in the data, and what we have learnt over the years is that application programs are not the only way to get data into a file. There are utilities like DBU and WRKDBF, there are transfer applications like FTP and Client Access file transfer, there are external protocols like ODBC which allow Excel, web applications, and other external applications which can reach into your database. Finally, there are stored procedures and other programs on your own system which can bring data from other files - files which have not been 'cleaned' of these special characters.

I think @david has the right answer - check the data at runtime. The way I would implement this is with a trigger. That way, no matter what tried to insert or update your field with a special character, the database itself would reject the attempt.