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 grid validation

suganya_rangarajan
Participant
0 Kudos

Hi,

I am using ALV class functions to display a table entry.Not just display the entry but I can also create/update record using ALV.now when I enter datas in a column in ALV i want that column to be checked against another table field. At the table level I can do foreign key and validate the entries but before updating in database I want the entries to be validated.Can anyone tell me how to achieve this?

Thanks

Suganya

1 REPLY 1

Former Member
0 Kudos

Hi Suganya,

You can validate the data using the class method data_changed. Here is an example:

CLASS lcl_event_handler DEFINITION.

PUBLIC SECTION.

CLASS-METHODS:

data_changed FOR EVENT data_changed OF cl_gui_alv_grid

IMPORTING er_data_changed.

ENDCLASS. "lcl_event_handler DEFINITION

CLASS lcl_event_handler IMPLEMENTATION.

METHOD data_changed.

g_save = 'X'.

PERFORM data_changed USING er_data_changed.

ENDMETHOD. "data_changed

ENDCLASS. "lcl_event_handler IMPLEMENTATION

FORM data_changed USING p_er_data_changed TYPE REF TO

cl_alv_changed_data_protocol.

                    • Internal Tables **********

DATA: ls_mod_cells TYPE lvc_s_modi OCCURS 0 WITH HEADER LINE.

                    • Work Areas / Header Lines **********

DATA: lh_screen TYPE z1274_1.

                    • Variables **********

DATA: ls_cells TYPE lvc_s_modi.

DATA: ls_delete TYPE lvc_s_moce.

DATA: l_atinn LIKE cabn-atinn.

MOVE p_er_data_changed->mt_good_cells TO ls_mod_cells[].

LOOP AT ls_mod_cells.

READ TABLE t_screen INTO lh_screen INDEX ls_mod_cells-row_id.

IF sy-subrc = 0.

CASE ls_mod_cells-fieldname.

WHEN 'MTART'.

CALL METHOD p_er_data_changed->get_cell_value

EXPORTING

i_row_id = ls_mod_cells-row_id

i_fieldname = ls_mod_cells-fieldname

IMPORTING

e_value = lh_screen-mtart.

IF NOT lh_screen-mtart IS INITIAL.

SELECT SINGLE mtbez

INTO lh_screen-mtbez

FROM t134t

WHERE spras = sy-langu

AND mtart = lh_screen-mtart.

IF sy-subrc <> 0.

CALL METHOD p_er_data_changed->add_protocol_entry

EXPORTING

i_msgid = 'Z1'

i_msgno = '007'

i_msgty = 'E'

i_msgv1 = 'Invalid Material Type.'

i_msgv2 = ' '

i_fieldname = ls_mod_cells-fieldname

i_row_id = ls_mod_cells-row_id.

ELSE.

CALL METHOD p_er_data_changed->modify_cell

EXPORTING

i_row_id = ls_mod_cells-row_id

i_fieldname = 'MTBEZ'

i_value = lh_screen-mtbez.

ENDIF.

ENDIF.

WHEN 'ATINN'.

CALL METHOD p_er_data_changed->get_cell_value

EXPORTING

i_row_id = ls_mod_cells-row_id

i_fieldname = ls_mod_cells-fieldname

IMPORTING

e_value = lh_screen-atinn.

IF NOT lh_screen-atinn IS INITIAL.

SELECT SINGLE atnam

INTO lh_screen-atnam

FROM cabn

WHERE atinn = lh_screen-atinn.

IF sy-subrc <> 0.

CALL METHOD p_er_data_changed->add_protocol_entry

EXPORTING

i_msgid = 'Z1'

i_msgno = '007'

i_msgty = 'E'

i_msgv1 = 'Invalid Characteristic.'

i_msgv2 = ' '

i_fieldname = ls_mod_cells-fieldname

i_row_id = ls_mod_cells-row_id.

ELSE.

CALL METHOD p_er_data_changed->modify_cell

EXPORTING

i_row_id = ls_mod_cells-row_id

i_fieldname = 'ATNAM'

i_value = lh_screen-atnam.

ENDIF.

ENDIF.

ENDCASE.

ENDIF.

ENDLOOP.

ENDFORM. " DATA_CHANGED