Professional Documents
Culture Documents
Custom Validation On Table Maintenance Generator (SM30) : Monday, July 5, 2021 10:18 AM
Custom Validation On Table Maintenance Generator (SM30) : Monday, July 5, 2021 10:18 AM
http://saptechnical.com/Tutorials/ABAP/TableMaintenance/events
.htm
Custom Validation on Table Maintenance
Generator (SM30)
To add a validation to prevent invalid data input while using table maintenance
transaction (SM30) is a common situation. However, it may be tricky at first if we
don’t know the trick behind. So, below is the step to add the custom validation.
REPORT THIS AD
form f_validate_entry.
DATA lwa_row TYPE ztesttable.
LOOP AT total.
clear lwa_row.
if <vim_total_struc> is ASSIGNED.
MOVE-CORRESPONDING <vim_total_struc> to lwa_row.
endif.
if <action> NE 'D' and <action> is NOT INITIAL and <action> NE 'X'.
if lwa_row-curr NE 'USD' and lwa_row-curr NE 'IDR'.
MESSAGE 'Currency must be USD or IDR' TYPE 'S' DISPLAY LIKE 'E'.
There are some global variable used in this code, which make it tricky if we don’t
know what it contains. Variable ‘total’ will contain all entries in the table: new
entries, newly deleted entries, and existing entries, along with the action
performed on that entry (Insert/Update/Delete/None). However, this variable
come with only one field struct, so we have to do string offset, which is not really
elegant way. Fortunately, in each loop of ‘total’, it will automatically assign itself to
<vim_total_struc> which have the same struct with the table. From there, we
could validate the entry. There’s also <action> variable, which also automatically
assigned during loop, that show the action performed for that entries (value list as
below) The variable ‘vim_abort_saving’ will be flag to abort the save.
N = New entry
U = Updated entry
D = Deleted entry
From <https://musicodez.wordpress.com/2010/09/13/custom-validation-on-table-maintenance-
generator-sm30/>
Resolution:
Buat event 05 pada table maintenance generator dengan subroutine F_VALIDATE. Cara membuat event sama seperti
yang pernah disampaikan pada postingan ini di step no.4.
Structure table ZDT0150:
Source code:
1 *&---------------------------------------------------------------------*
2 *& Form f_validate
3 *&---------------------------------------------------------------------*
4 * text
5 *----------------------------------------------------------------------*
6 FORM f_validate.
7 DATA: ld_pertext(7),
8 ld_dattext(10).
9 CALL FUNCTION 'CONVERSION_EXIT_PERI6_OUTPUT'
10 EXPORTING
11 input = zdt0150-spmon
12 IMPORTING
13 output = ld_pertext
14 EXCEPTIONS
15 OTHERS = 1.
16 IF zdt0150-spmon <> zdt0150-datab(6).
17 WRITE zdt0150-datab TO ld_dattext DD/MM/YYYY.
18 MESSAGE e006(aq) WITH 'Date' ld_dattext 'is not in period' ld_pertext.
19 ENDIF.
20 IF zdt0150-spmon <> zdt0150-datbi(6).
21 WRITE zdt0150-datbi TO ld_dattext DD/MM/YYYY.
22 MESSAGE e006(aq) WITH 'Date' ld_dattext 'is not in period' ld_pertext.
23 ENDIF.
24 ENDFORM. "f_validate
From <https://belajarabap.wordpress.com/2019/03/08/using-event-5-in-table-maintenance-generator-for-data-validation/>