Step 1: Identify Where to Add Validation
In Module Pool (ABAP Dynpro) programming, validations are usually added in:
-
PBO (Process Before Output) – usually for initial field checks or setting default values.
-
PAI (Process After Input) – most common place for validations after the user inputs data and presses a button.
The PAI module is triggered when a user interacts with a screen element (like pressing Enter, or a function key).
Step 2: Define Field in Screen
Suppose you have a screen (0100) with a field S_MATNR (Material Number).
-
Go to Screen Painter (SE51).
-
Add your input field (
S_MATNR) and assign a name. -
Assign a Module in the PAI Flow Logic (we’ll validate in this module):
Step 3: Write Validation Logic in ABAP Module
Go to your program and write the module:
MODULE validate_material INPUT.
” Check if field is empty
IF s_matnr IS INITIAL.
MESSAGE ‘Material number cannot be empty’ TYPE ‘E’.
ENDIF.
” Check if material exists in MARA table
DATA: lv_count TYPE i.
SELECT COUNT(*) INTO lv_count
FROM mara
WHERE matnr = s_matnr.
IF lv_count = 0.
MESSAGE ‘Material does not exist’ TYPE ‘E’.
ENDIF.
ENDMODULE.
Step 4: Optional – Validate on Field Exit
If you want validation when leaving a field, you can use Field Exit or MODULE … AT EXIT-COMMAND:
MODULE validate_matnr_onexit INPUT.
IF s_matnr IS INITIAL.
MESSAGE ‘Material cannot be empty’ TYPE ‘E’.
ENDIF.
ENDMODULE.
Step 5: Common Validation Techniques
-
Check for mandatory fields →
IS INITIAL. -
Check for valid values in DB →
SELECTfrom tables (MARA, KNA1, etc.). -
Cross-field validation → compare values of multiple fields.
-
Custom messages → Use
MESSAGEstatement with message class.
MODULE validate_data INPUT.
IF s_qty <= 0.
MESSAGE ‘Quantity must be greater than zero’ TYPE ‘E’.
ENDIF.
IF s_matnr IS INITIAL AND s_kunnr IS INITIAL.
MESSAGE ‘Material or Customer must be entered’ TYPE ‘E’.
ENDIF.
ENDMODULE.