abapdynprosap-data-dictionary

Highlight specific line when making before save validation in a maintenance view?


I have implemented the event 01 - Before saving the data in the database for a table in the Table Maintenance Generator TMG.

In the implementation code I am looping over the total table, checking for a certain field to satisfy some condition.

In case of the failed check be the field should be marked as wrong and the error message is given out using:

    MESSAGE 'Please correct this field' TYPE 'S' DISPLAY LIKE 'E'.
    vim_abort_saving = abap_true.

This works, but if there are, for example, 10 records given at once, I would like the program to mark all wrong lines, or fields, if that is possible.

I have searched for many solutions, but none have worked.

One idea was to use VIEW_SET_PF_STATUS which gives a similar effect that I want to achieve. But it does not work when I use this event in FORM.


Solution

  • The usual way to do error handling on a per-field level and direct the user specifically to the field where they made an invalid entry is by using a module that is executed specifically for a field. This is handled by the dynpro logic. In that case, you will see something like this in the PAI of the dynpro:

    LOOP AT itab INTO wa.
        FIELD dynp_field MODULE mod ON INPUT.
    ENDLOOP.
    

    This means that if the user entered something in a field dynp_field of the table bound to itab, then the module mod gets executed. wa will contain the current line of the table during the execution of the module. When you now create a MESSAGE ... TYPE 'E' during that module (TYPE 'E', not just DISPLAY LIKE 'E'!), then SAPGui will react to that by directing the user to that exact cell of the table while displaying the error message.

    You can find the LOOP that goes trough the EXTRACT (entries visible on the SM30 screen) table, by going to the generated screen in SE80, or Table->Table Maintenance Genarator and then click on your screen number.