Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to validate data entered in table maintenance for Z table?

Peter_Inotai
Active Contributor
0 Kudos

Hi,

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:

http://help.sap.com/saphelp_47x200/helpdata/en/91/ca9f0ea9d111d1a5690000e82deaaa/frameset.htm

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,

Peter

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Peter,

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 continue.

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.

Form BEF_SAVE.

  • wirte the code to validate.

Endform.

Activate this . Go t-code SM30 . enter the table name. And then check if you have done the validation perfectly.

Regards,

Kunal.

18 REPLIES 18

naimesh_patel
Active Contributor
0 Kudos

Hello,

Try to use, the event 05 > when creating a new entry.

I assume your tabel doesn't contain any data.

Regards,

Naimesh

0 Kudos

Hi Naimesh,

Thanks.

Do you have example for event 05 how to handle messages?

Event 05 wouldn't work when they change an existing entry:-(

Regards,

Peter

former_member927251
Active Contributor
0 Kudos

Hi,

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

----


FORM f9000_check_before_save.

TYPES : BEGIN OF ty_flmt,

zz_flmt_type TYPE zz_flmt_type,

zz_gsm_flmt_code TYPE zz_flmt_code,

END OF ty_flmt.

  • Internal Table

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 total.

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.

ENDIF.

ENDIF.

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.

ENDLOOP.

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.

ENDIF.

ENDLOOP.

ENDIF.

ENDIF.

sy-subrc = lv_subrc.

ENDFORM.

<b>Please reward points and close the thread.</b>

Regards,

Amit Mishra

0 Kudos

Hi Amit,

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.

My code:

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

Thanks,

Peter

0 Kudos

Hi Peter,

We want our subroutine to be called when the Event gets triggered. That's why we link the event to the subroutine by going to the EVENT menu option.

Regards,

Amit Mishra

0 Kudos

Hi Amit,

Thanks for the clarification.

Actually then it's easier to put the form in a separate Z-include instead of putting in in the PBO.

It's still not working the way I'd like to:-(

I'm trying to check the SAP standard solutions based on table TVIMF.

Regards,

Peter

Former Member
0 Kudos

Hi Peter,

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 continue.

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.

Form BEF_SAVE.

  • wirte the code to validate.

Endform.

Activate this . Go t-code SM30 . enter the table name. And then check if you have done the validation perfectly.

Regards,

Kunal.

0 Kudos

Hi Kunal,

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:-(

Thanks,

Peter

0 Kudos

Hey Peter,

to give a feedback to the user , you can pop up a message like this :

Form BEF_SAVE.

  • Code to validate Data .

message i002(zmsg_clas).

Endform.

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).

Regards,

Kunal.

0 Kudos

Hi Kunal,

The problem, that info message keeps the current screen however it won't stop the flow and the incorrect data will be saved:-(

Peter

0 Kudos

Hi Peter,

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.

Regards,

Kunal.

0 Kudos

Hi Kunal,

You can find my source code above, but it doesn't work as I'd like to. Actually that's why I opened this thread:-)))

Thanks,

Peter

0 Kudos

Hi Peter,

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.

Regards,

Kunal.

0 Kudos

Hi Peter

A guy had your same problem, I suggested to use the event 21.

This event should be used to fill the hidden field, but you can use it to insert your validations too.

I did it and it works.

Max

0 Kudos

Hi Max,

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?

Thanks,

Peter

0 Kudos

Hi

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.

Max

0 Kudos

Hi Max,

Thanks, now I got it. Actually I don't need maintenance view in my case, but at least I know where it's coming from.

Peter

0 Kudos

Hi Max Bianchi,

Thanks for the suggestion.It works excellent in my case...