Application Development and Automation 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: 
Read only

Validate ALV entry

Former Member
0 Likes
508

Hello.

I'm using an ALV display with a custom field catalog to allow a user to edit data via the ALV display (certain fields).

I create my container and fieldcatalog in the PAI of my screen and use CALL METHOD grid1->refresh_table_display to display it, I can edit the contents of the table displayed in the ALV just fine. Now I want to validate the edits as they happen and pop a message and disallow the edit by a rule/validation I define. Can someone show me how/where/what to insert a validation routine into this?

Thanks!

1 ACCEPTED SOLUTION
Read only

former_member125661
Contributor
0 Likes
472

Handle the data_changed event in the grid.

Whenever you make changes in the data in ALV Grid this event would be triggered. Here you can perform additional validations that you may need to perform.

code METHODS handle_data_changed

FOR EVENT data_changed OF cl_gui_alv_grid

IMPORTING er_data_changed.[/code]

Implementation:

code METHOD handle_data_changed.

PERFORM validations USING er_data_changed.

ENDMETHOD.[/code]

codeFORM validations USING er_data_changed TYPE REF TO cl_alv_changed_data_protocol.

DATA: ls_good TYPE lvc_s_modi.

DATA wa LIKE LINE OF lt_good_cells.

CALL METHOD g_grid->register_edit_event

EXPORTING

i_event_id = cl_gui_alv_grid=>mc_evt_modified.

LOOP AT er_data_changed->mt_good_cells INTO ls_good.

CASE ls_good-fieldname.

WHEN 'FIELDNAME'. "Your fieldname

CALL METHOD er_data_changed->get_cell_value "Get the changed value

EXPORTING

i_row_id = ls_good-row_id

i_fieldname = ls_good-fieldname

IMPORTING

e_value = temp. "Your temp variable

"Make your validations here.

ENDCASE.

[/code]

3 REPLIES 3
Read only

former_member125661
Contributor
0 Likes
473

Handle the data_changed event in the grid.

Whenever you make changes in the data in ALV Grid this event would be triggered. Here you can perform additional validations that you may need to perform.

code METHODS handle_data_changed

FOR EVENT data_changed OF cl_gui_alv_grid

IMPORTING er_data_changed.[/code]

Implementation:

code METHOD handle_data_changed.

PERFORM validations USING er_data_changed.

ENDMETHOD.[/code]

codeFORM validations USING er_data_changed TYPE REF TO cl_alv_changed_data_protocol.

DATA: ls_good TYPE lvc_s_modi.

DATA wa LIKE LINE OF lt_good_cells.

CALL METHOD g_grid->register_edit_event

EXPORTING

i_event_id = cl_gui_alv_grid=>mc_evt_modified.

LOOP AT er_data_changed->mt_good_cells INTO ls_good.

CASE ls_good-fieldname.

WHEN 'FIELDNAME'. "Your fieldname

CALL METHOD er_data_changed->get_cell_value "Get the changed value

EXPORTING

i_row_id = ls_good-row_id

i_fieldname = ls_good-fieldname

IMPORTING

e_value = temp. "Your temp variable

"Make your validations here.

ENDCASE.

[/code]

Read only

0 Likes
472

Shareen - This code worked nicely, could I ask one additional question in my validation routine if I decide that an entry is invalid can I reset the value back to the original from this method?

Read only

former_member125661
Contributor
0 Likes
472

Joseph,

Also forgot to mention..Some standard validations are done by the ALV grid if fieldcatalog is referenced to a DDIC structure..Suppose there is a qty field and you try to key in some character, the ALV grid will do the validation itself. (THis is as good as cllicking on standard button 'Check' in the ALV grid.