Custom Validation in TMG on Enter key

lightCustom Validation in TMG on Enter key

This post describes about how to validate newly created, changed & deleted entry in TMG. We have several events in TMG which can be used according to our requirement but there is not any event for Enter key. We need to write our code in PAI of generated screen. 

Requirement: If we create any new record in table ZMTEST, field CARRID should be validated from SFLIGHT table. If CARRID doesn’t exist in SFLIGHT, we need to display error message and data should not be saved.

Table: ZMTEST

1

Step 1: Create TMG for Table: ZMTEST and Double click on Generated screen number

2

Step 2: It will navigate you to Screen flow logic, Create a module in PAI. Double click on Module name to create PAI Module. Provide the Include Program name and Save. 

3

4

Step 3: Write below code in the created Module.

1

TOTAL: At Runtime it contains all the entries – Newly added & deleted along with the action performed – Insert, Update, Delete or None.

<VIM_TOTAL_STRUC>: will be assigned automatically inside loop and it will have same structure of table.

<ACTION>: it contains value of action performed. N: New, U: Updated, space: No change, D: Deleted and X: Deleted new entry.

2.jpg

VIM_ABORT_SAVING: Flag to abort the save.

3

Code:


MODULE common_validate INPUT.

* Local declarations
TYPES BEGIN OF ty_sflight,
                carrid TYPE s_carr_id,
                END OF ty_sflight.

DATA lt_zmtest   TYPE STANDARD TABLE OF zmtest,
               wa_zmtest   TYPE zmtest,
              lt_sflight  TYPE STANDARD TABLE OF ty_sflight.

FIELD-SYMBOLS <fs_zmtest>  TYPE zmtest.

* TOTAL: At Runtime it contains all the entries – Newly added &
* deleted along with the action performed – Insert, Update
* Delete or None

* <VIM_TOTAL_STRUC> will be assigned automatically inside loop
* and it will have same structure of table.

* <ACTION> it containg value of action performed.
* N: New, U: Updated, space: No change, D: Deleted
* and X: Deleted new entry.

* Here we are storing Newly created entries in table LT_ZMTEST
LOOP AT total.
   IF <vim_total_struc> IS ASSIGNED AND <action> ‘N’.
     MOVE-CORRESPONDING <vim_total_struc> TO wa_zmtest.
     APPEND wa_zmtest TO lt_zmtest.
     CLEAR wa_zmtest.
   ENDIF.
ENDLOOP.

* Extracting CARRID from Table SFLIGHT to vlidate newly
* added records
IF lt_zmtest[] IS NOT INITIAL.
SELECT carrid FROM sflight INTO TABLE lt_sflight
FOR ALL ENTRIES IN lt_zmtest
WHERE carrid EQ lt_zmtestcarrid.
IF sysubrc IS INITIAL.
SORT lt_sflight BY carrid.
ENDIF.

*   VIM_ABORT_SAVING: Flag to abort the save
UNASSIGN <fs_zmtest>.
LOOP AT lt_zmtest ASSIGNING <fs_zmtest>.
READ TABLE lt_sflight TRANSPORTING NO FIELDS WITH KEY carrid <fs_zmtest>carrid
BINARY SEARCH.
IF sysubrc IS NOT INITIAL.
  vim_abort_saving abap_true.
  MESSAGE e368(00WITH <fs_zmtest>carrid ‘does not exist in table Sflight’.
ENDIF.
ENDLOOP.
UNASSIGN <fs_zmtest>.
ENDIF.
ENDMODULE.                 ” COMMON_VALIDATE  INPUT


 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s