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:
For easier orientation, here are the ABAP names of the individual attributes:
The definition of the attributes in the ABAP class definition:
data: 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.
method validate_time. if begda gt endda. s10errormessage( |End date is before start date| ). endif. if begda eq endda and beguz gt enduz. s10errormessage( |Please check the times| ). endif. endmethod. method validate_text. case awart. when '0410' or '0420' or '0430'. if text is initial. s10setfocus( 'text' ). s10errormessage( |Please enter a text| ). endif. endcase. endmethod.
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:
methods: validate_time importing begda type pa2001-begda beguz type pa2001-beguz optional endda type pa2001-endda enduz type pa2001-enduz optional, validate_text importing awart type pa2001-awart text type string optional.
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 method check.
* execute all validation methods s10validate( ). s10infomessage( |Input data checked| ). endmethod.