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

Validations on ALV Grid

kasithunuguntla
Participant
0 Likes
2,571

Hi,

I have used ALV grid for accepting user inputs and therby triggering certain transactions. I have made some validations on the user inputs using event data_changed of CL_GUI_ALV_GRID.

handle_data_changed

FOR EVENT data_changed OF cl_gui_alv_grid

IMPORTING er_data_changed.

Program reports errors without any problem for the first time when the user enters data and press Enter key.

The problem is when the user changes data on the input screen, internal table er_data_changed will only get the changed values which can be validated. I want to get whole table to validate due to some dependencies.

For ex: I have validation on field Doc# which will check if the line item# entered on screen is valid. first time, it checks fine but if the user changes item# again, er_data_changed will only capture this field and I dont have any validation on this field.

Please let me know how to handle this issue.

Sample code given below:

LOOP AT er_data_changed->mt_good_cells INTO ls_good.

CASE ls_good-fieldname.

  • check if values in columns of this row was changed

WHEN 'VBELN'.

CALL METHOD check_item_no

EXPORTING

ps_good_item_no = ls_good

pr_data_changed = er_data_changed.

Regards

Kasi

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,477

Hello Kasi

The sample report BCALV_EDIT_03 describes how to verify modified values in an editable ALV grid. Here is part of the documentation (in the program header) that may be interesting for you:

*-----------------------------------------------------------------
* Essential steps (search for '§')
* ~~~~~~~~~~~~~~~
* 1.Set status of columns PLANETYPE and SEATSOCC to editable.
* 2.Optionally restrict generic functions to 'change only'.
*   (The user shall not be able to add new lines).
* 3.Optionally register ENTER to raise event DATA_CHANGED.
*   (Per default the user may check data by using the check icon).
* 4.Define and implement event handler to handle event DATA_CHANGED.
* 5.Loop over table MT_GOOD_CELLS to check all values that are
*   valid due to checks according to information of the DDIC.
* 6.Within a check cycle:
* 6a.Get new cell value to check it using method GET_CELL_VALUE.
*    (In this case SEATSOCC).
* 6b.If the value is valid you may want to change values of
*    other cells.
* 6c.If the value is not valid create an protocol entry in
*    the application log.
<b>* 6d.To access old values (which where not changed in this check cycle)
*    use your output table GT_OUTTAB.</b>
* 7.Display application log if an error has occured.
*-----------------------------------------------------------------------
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

Regards

Uwe

Hi,

I have used ALV grid for accepting user inputs and therby triggering certain transactions. I have made some validations on the user inputs using event data_changed of CL_GUI_ALV_GRID.

handle_data_changed

FOR EVENT data_changed OF cl_gui_alv_grid

IMPORTING er_data_changed.

Program reports errors without any problem for the first time when the user enters data and press Enter key.

The problem is when the user changes data on the input screen, internal table er_data_changed will only get the changed values which can be validated. I want to get whole table to validate due to some dependencies.

For ex: I have validation on field Doc# which will check if the line item# entered on screen is valid. first time, it checks fine but if the user changes item# again, er_data_changed will only capture this field and I dont have any validation on this field.

Please let me know how to handle this issue.

Sample code given below:

LOOP AT er_data_changed->mt_good_cells INTO ls_good.

CASE ls_good-fieldname.

  • check if values in columns of this row was changed

WHEN 'VBELN'.

CALL METHOD check_item_no

EXPORTING

ps_good_item_no = ls_good

pr_data_changed = er_data_changed.

Regards

Kasi

3 REPLIES 3
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,478

Hello Kasi

The sample report BCALV_EDIT_03 describes how to verify modified values in an editable ALV grid. Here is part of the documentation (in the program header) that may be interesting for you:

*-----------------------------------------------------------------
* Essential steps (search for '§')
* ~~~~~~~~~~~~~~~
* 1.Set status of columns PLANETYPE and SEATSOCC to editable.
* 2.Optionally restrict generic functions to 'change only'.
*   (The user shall not be able to add new lines).
* 3.Optionally register ENTER to raise event DATA_CHANGED.
*   (Per default the user may check data by using the check icon).
* 4.Define and implement event handler to handle event DATA_CHANGED.
* 5.Loop over table MT_GOOD_CELLS to check all values that are
*   valid due to checks according to information of the DDIC.
* 6.Within a check cycle:
* 6a.Get new cell value to check it using method GET_CELL_VALUE.
*    (In this case SEATSOCC).
* 6b.If the value is valid you may want to change values of
*    other cells.
* 6c.If the value is not valid create an protocol entry in
*    the application log.
<b>* 6d.To access old values (which where not changed in this check cycle)
*    use your output table GT_OUTTAB.</b>
* 7.Display application log if an error has occured.
*-----------------------------------------------------------------------
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

Regards

Uwe

Read only

0 Likes
1,477

Step 1 - Create a screen using screen painter in the report program.

Step 2 -Set the size of the screen.

Step 3 -Place a custom control on the screen set its name to ‘C_CONTAINER’ and set the size of the custom control .

Step 4 -Save and activate the screen.

Step 5 -Code the Data Declarations

o_container_alv type REF TO cl_gui_custom_container,

o_alv_grid TYPE REF TO cl_gui_alv_grid,

Step 6- Define the Receiver Class

*Event handler (local class) definition

CLASS lcl_event_receiver DEFINITION.

*Object for changed data

PUBLIC SECTION.

METHODS:

*Method to Handle Changed Data

handle_data_changed

FOR EVENT data_changed OF cl_gui_alv_grid

IMPORTING er_data_changed.

METHODS:

*Method that check data and display message

check_data

IMPORTING

pr_row TYPE lvc_s_modi

pr_msg TYPE symsgno

pr_data_changed TYPE REF TO cl_alv_changed_data_protocol.

ENDCLASS. "lcl_event_receiver DEFINITION

Step 7- Create the Reference and implement the Class

DATA:

*Object declaration for local class

o_event_receiver TYPE REF TO lcl_event_receiver.

*Event handler (local class) implementation

CLASS lcl_event_receiver IMPLEMENTATION.

*Method Check Data to display Error Message

METHOD check_data.

  • Get the particular cell value in this case it is

  • of labels

CALL METHOD pr_data_changed->get_cell_value

EXPORTING

i_row_id = pr_row-row_id

i_fieldname = c_labels

IMPORTING

e_value = v_value.

  • Checking if labels value is 0 or initial

IF v_value IS INITIAL OR v_value EQ 0 .

v_flg_check = c_flg_x.

*Call method to display message

CALL METHOD pr_data_changed->add_protocol_entry

EXPORTING

i_msgid = c_msg_id

i_msgty = c_msg_typ_e

i_msgno = pr_msg

i_msgv1 = pr_row-value

i_fieldname = pr_row-fieldname

i_row_id = pr_row-row_id.

ENDIF .

ENDMETHOD. "check_data

*Method to handle change data

METHOD handle_data_changed.

*Local Data Declarations

DATA:

l_rec_mod_cells TYPE lvc_s_modi.

*Loop at all modified lines of ALV grid

LOOP AT er_data_changed->mt_mod_cells INTO l_rec_mod_cells.

  • Check data needs to be fired only when we have checked

  • the checkbox

IF l_rec_mod_cells-fieldname = c_select AND

l_rec_mod_cells-value = c_flg_x.

CALL METHOD check_data

EXPORTING

pr_row = l_rec_mod_cells

pr_msg = c_203

pr_data_changed = er_data_changed.

ENDIF.

ENDLOOP.

ENDMETHOD. "handle_data_changed

ENDCLASS. "lcl_event_receiver IMPLEMENTATION

Step 8 - Display the ALV .PBO needs to implemented for the same

In PBO

Create the Object References

CREATE OBJECT o_container_alv

EXPORTING container_name = v_container_name.

CREATE OBJECT o_alv_grid

EXPORTING i_parent = o_container_alv.

If you wish you can exclude some of the Functionallity Like Create New

l_wa_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.

APPEND l_wa_exclude TO fp_i_exclude.

l_wa_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.

APPEND l_wa_exclude TO fp_i_exclude.

l_wa_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.

APPEND l_wa_exclude TO fp_i_exclude.

l_wa_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.

APPEND l_wa_exclude TO fp_i_exclude.

l_wa_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.

APPEND l_wa_exclude TO fp_i_exclude.

l_wa_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.

APPEND l_wa_exclude TO fp_i_exclude.

l_wa_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.

APPEND l_wa_exclude TO fp_i_exclude.

l_wa_exclude = cl_gui_alv_grid=>mc_fc_loc_paste.

APPEND l_wa_exclude TO fp_i_exclude.

l_wa_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.

APPEND l_wa_exclude TO fp_i_exclude.

l_wa_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.

APPEND l_wa_exclude TO fp_i_exclude.

Call The Method to display the ALV and set the handler for the Receiver Object

CALL METHOD o_alv_grid->set_table_for_first_display

EXPORTING

is_layout = l_rec_layout

it_toolbar_excluding = i_exclude

CHANGING

it_fieldcatalog = fp_i_field_cat

it_outtab = fp_i_final_data.

CREATE OBJECT o_event_receiver.

SET HANDLER o_event_receiver->handle_data_changed FOR o_alv_grid.

This receiver object handles the error if encountered

Read only

0 Likes
1,477

Thanks for your response. I have used exact similar coding posted by both of you. My situation is little bit different.

Event "Data_changed" has import parameter "er_data_changed" which will return only changed values from input screen for validation. I want to see all values because I have certain dependencies on my validations. for ex: I have written validation on field Doc# which will get and validate other values entered on the input screen (say for suppose if the order type, material number entered are correct for this Doc#). once I correct other values, I will see these values in "er_data_changed" but I dont have validations on these fields. my validation is limited to Doc# field which has not changed. So, the program will not re-check if what I have corrected is CORRECT.

The only option I could see is writing validation on every field but I am worried I have 33 fields.

I am hoping SAP would have provided er_get_all_data kind of parameter.

Any other work-around idea is well appreciated.

Regards

Kasi