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: 

ALV check on cell values

sergio_atzori
Explorer
0 Kudos

Hi all,

I'm looking to a more consistent way to check a cell value within ALV grid (with objects),

As far as today I've used an immediate check with handle data changed method

on class lcl_event_receiver,

Issue is:

check work for real just the first time, then if I make something else on other cell check and error message on previous imput error (with display protocol method) get completely lost,

I realy can't help having the error message always stuck till the user makes proper corrections,

I would like having the blocking message popping out if user try doing anything else, just as happening when a field is checked by a control table,

(but in this case a can't use a control table since I have to make some other round

to check may values)

Does anyone know how to make it? or just have some good example?

ps. note I also took care of setting the proper methods after dipalying the ALVgrid

( I mean: register_edit_event with evt_enter, evt_modified...etc )

Thank you,

Kr Sergio,

2 REPLIES 2

uwe_schieferstein
Active Contributor
0 Kudos

Hello Sergio

You could solve your problem as following: instead of doing all the validation in event handler method lcl_event_handler=>HANLDE_DATA_CHANGED simply call this method at PAI when the user pushes the SAVE button, e.g:

DATA:
  go_data_changed    TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
...

PROCESS AFTER INPUT.

  CASE gd_okcode.
    WHEN 'BACK'   OR
               'EXIT'      OR
               'CANC'.
      set screen 0. leave screen.  " no validation at all

    WHEN 'SAVE'.
      CLEAR: go_data_changed.  " initialize ref variable for data change object

      call method lcl_event_handler=>handle_data_changed
              EXPORTING
                er_data_changed = go_data_changed
                e_ucomm           = gd_okcode.  " = 'SAVE'

    WHEN OTHERS.
    ENDCASE.

    CLEAR: gd_okcode.

In you event handler method you do the following check:

METHOD handle_data_changed.

  IF ( e_ucomm = 'SAVE'     AND
        er_data_changed IS NOT BOUND ).
*   NOTE: er_data_changed is always bound when the event handler method is
*              triggered through event DATA_CHANGED. Thus, we know that
*   the method was called from PAI.

*   Create data changed instance
     CREATE OBJECT er_data_changed.

*   Do all your validation and collect the error messages in er_data_changed
*   using method ADD_PROTOCOL_ENTRY.
*   Finally, use method DISPLAY_PROTOCOL to show the error log.

*   In order to prevent saving the data at PAI you need to set, for example, a static
*   flag in your event handler class:
      lcl_event_handler=>validation_failed = abap_true.

  ENDIF.

ENDMETHOD.

Regards

Uwe

0 Kudos

'got it, Thank you,

Kind regards, Sergio