I created a Z-table with table maintenance. I'd like to perform some validation on the entered data.
I know there are events for these : "If this pre-defined time is reached in extended table maintenance, the FORM routine specified for the current view and for this time is processed. This is useful, for example, for performing consistency checks before saving or specific actions when creating new entries."
I also found some info in the Online help:
However it's not clear which event I can use for validation.
I tried event 01, however when I added a message, in the SM30 in case of message, I got the SM30 initial screen.
Do you have any example about validation?
Thanks in advance,
Once you are on the table maintenance generator screen.
GOTO --> Enviornment --> Modification --> Events.
Here specify Event as '01' and the Subroutine name that will hold the data for the validation.
As you know we need to specify a function group.
GOTO SE80 and Open your function group.
Now in the PBO of the screen write a subroutine for the validation before saving an entry in the table.
Refer the code below for validation.
*& Form F9000_CHECK_BEFORE_SAVE
Subroutine called dynamically to check values before saving
TYPES : BEGIN OF ty_flmt,
zz_flmt_type TYPE zz_flmt_type,
zz_gsm_flmt_code TYPE zz_flmt_code,
END OF ty_flmt.
DATA : lit_flmt_code TYPE TABLE OF ty_flmt,
wa_flmt_code LIKE LINE OF lit_flmt_code.
DATA: lv_subrc TYPE sy-subrc VALUE '0',
lv_tabix TYPE sy-tabix,
lv_total_rec TYPE i,
lv_rec TYPE i,
flg_upd TYPE flag.
DESCRIBE TABLE total LINES lv_total_rec.
LOOP AT total.
lv_tabix = sy-tabix.
READ TABLE extract WITH KEY total.
IF sy-subrc EQ 0.
IF extract+3(10) IS INITIAL.
DELETE extract INDEX sy-tabix.
DELETE extract INDEX lv_tabix.
lv_subrc = '4'.
flg_upd = 'X'.
MESSAGE s119(zcrm_appl) DISPLAY LIKE 'S'.
SET SCREEN 0.
wa_flmt_code-zz_flmt_type = total+13(3).
wa_flmt_code-zz_gsm_flmt_code = total+16(10).
APPEND wa_flmt_code TO lit_flmt_code.
IF flg_upd IS INITIAL.
SORT lit_flmt_code BY zz_flmt_type zz_gsm_flmt_code.
DELETE ADJACENT DUPLICATES FROM lit_flmt_code.
DESCRIBE TABLE lit_flmt_code LINES lv_rec.
IF lv_total_rec <> lv_rec.
LOOP AT extract.
READ TABLE total WITH KEY extract.
IF sy-subrc EQ 0.
DELETE total INDEX sy-tabix.
DELETE extract INDEX 1.
lv_subrc = '4'.
MESSAGE s289(zcrm_appl) DISPLAY LIKE 'S'.
SET SCREEN 0.
sy-subrc = lv_subrc.
<b>Please reward points and close the thread.</b>
Thanks for your help and example.
It's not clear for me, why you define an event when you change the generated screen PBO after it.
I tried your way of error handling, the data is not saved, however the checked field gets greyed out, so it's not possible to correct the value.
FORM validate_data. BREAK-POINT. *======================================================================* * Validation of COMPANY_CODE IF zmy_table-company_code IS INITIAL. * Enter company code MESSAGE s430(fb) DISPLAY LIKE 'S'. SET SCREEN 0. sy-subrc = 4. ENDIF. * sy-subrc = 0. ENDFORM. "VALIDATE_DATA
To validate data entered in table maintenance for Z table, follow the steps :
1. Go t-code SE11 . Enter your table name. Click change.
2. Then Utilities - > Table Maintenance Generator .
Now you are on the Table Maintenance Generator . Enter the required values. the function group, whihc you enter should be activated.
Then, go to
Enviornment --> Modification --> Events.
You will see a pop up message .
Do not make any changes (SAP data).
Click on tab New Entries.
As you have mentioned that you want to perform consistency checks before saving, write 01 in 1st column ( 01 - Event before saving) . Give a suitable name BEF_SAVE . Press Enter. You will see a blue icon under the column Editor.
click on that editor.
A pop up message will come " Creating Subroutine BEF_SAVE " .
Click on include L***TOP. continue.
Write the routine for validation in this include.
wirte the code to validate.
Activate this . Go t-code SM30 . enter the table name. And then check if you have done the validation perfectly.
Thanks for your help.
Can you provide some more info about how to provide feedback to the user in the code validation and avoid dta a save?
If I use error message I'm kicked out to the initial screen of SM320 with the error message, however I'd like to stay in the maintance screen.
It's the same if I use Maintenance type one step or two step:-(
to give a feedback to the user , you can pop up a message like this :
Code to validate Data .
note : here you can create a message class by using the t-code SE91. Here you can cretae several messages.
There are six types of messages you can create.
they are : Error(E) , Warning(W), Status(S), information(I) , Termination (A)and Exit (x).
The message can be written where you have validated the data.
As the validation is being done in the event BEF_SAVE, the data will be saved if and only if correct entries have been made by the user.
Now can you tell me how you are validating your data? Then i can suggest you how to stop the data from being saved if any error occurs.
I got your requirement . I think you want to validate if the user has entered the data for
zmy_table-company_code . If not, you want to display the error message . After the error message is displayed , you want to reamin in the maintenance screen itself.
I am now working on the solution. Just hold on. You can further clarify me if i have got anything wrong.
Thanks a lot for your help, event 21 happens every time when the user hits enter, so it works really fine, exactly as I wanted.
Based on the online help "This event occurs when fields which are flagged in the Data Dictionary as 'hidden', are to be filled.". What is hidden field, and how can I set a field hidden?
You can create an hidden field only in the MAINTENACE VIEW.
The MAINTENANCE VIEW is a kind of view to update the database table. It usually uses it when it wants to update several tables in the same moments or it wants to update only some fields.
Here you can decide which fields of a table have to be inserted in the view and which ones have to be setted as HIDDEN FIELDS.
When it generates the table maitenance program, the hidden fields'll be shown and it has to use that event to fill them.