To check user input, the S10 framework provides special "validate" methods that are automatically processed on the SAP server after input. The mechanism is described in detail in the validate methods documentation. We show it in this tutorial with the following example:
The following is to be checked:
- The specified time interval is correct
- For some absence types, the entry of a text is mandatory.
For easier orientation, here are the ABAP names of the individual attributes:
The definition of the attributes in the ABAP class definition:
awart type pa2001-awart,
begda type pa2001-begda,
beguz type pa2001-beguz,
endda type pa2001-endda,
enduz type pa2001-enduz,
text type string.
To validate the input data, we write two ABAP methods. The method name always starts with "validate_" and is otherwise arbitrary.
if begda gt endda.
s10errormessage( |End date is before start date| ).
if begda eq endda and beguz gt enduz.
s10errormessage( |Please check the times| ).
when '0410' or '0420' or '0430'.
if text is initial.
s10setfocus( 'text' ).
s10errormessage( |Please enter a text| ).
Now we still have to establish the reference of the checking methods to the input data. This is done in the declaration of the ABAP methods, in which we list the attributes to be checked as "importing" parameters:
begda type pa2001-begda
beguz type pa2001-beguz optional
endda type pa2001-endda
enduz type pa2001-enduz optional,
awart type pa2001-awart
text type string optional.
The addition optional
is interpreted by the S10 framework to mean that the check will run even if the attribute value is initial.
With this we are done and can test the checks, for example:
In addition to the described automatic checking of the data during input, you can run all validation methods of the class in ABAP using s10validate( ). It is advisable to do this with "Check" and "Save", since this performs all checks, regardless of whether the values were made by user input or were set in the program, e.g. from other database tables:
* check data
* execute all validation methods
s10infomessage( |Input data checked| ).
Saving the data in the SAP system is usually done by calling BAPIs or "Call Transaction Using...", during which all SAP checks are performed. However, it is convenient for the user if the checks are performed as early as possible when the data is entered and the reference of the error message to the input data is visible, and not only at the very end when "Save" is performed. The "validate" methods are the appropriate technique for this.