12-21-2011 4:03 AM
Hi Everybody,
In my output ALV table, i have two cloumns with checkboxes. At time, user cannot check both the checkboxes, how to do this validation?
In my code i have used
CALL METHOD w_ref_alv_grid->check_changed_data
IMPORTING
e_valid = w_valid.
IF w_valid EQ 'X'.
But it is not triggering, when the user checks the checkbox, how to capture this event? how to do the validation?
Needy help will be appreciated.
12-21-2011 6:35 AM
No need of validation. When clicked remove the check from other one and place it in the clicked one. Check the example below :
CLASS lcl DEFINITION DEFERRED.
TYPE-POOLS: slis.
TYPES:BEGIN OF t_data,
chk1(4) TYPE c,
chk2(4) TYPE c,
matnr TYPE matnr,
END OF t_data.
DATA: i_fcat TYPE slis_t_fieldcat_alv ,
w_fcat LIKE LINE OF i_fcat,
it_data TYPE TABLE OF t_data,
wa TYPE t_data,
i_cat TYPE lvc_t_fcat,
w_cat TYPE lvc_s_fcat,
cont TYPE REF TO cl_gui_custom_container,
grid TYPE REF TO cl_gui_alv_grid,
receiver TYPE REF TO lcl.
CLASS lcl DEFINITION.
PUBLIC SECTION.
METHODS handle_hotspot_click FOR EVENT hotspot_click OF
cl_gui_alv_grid IMPORTING e_row_id e_column_id es_row_no.
ENDCLASS. "lcl DEFINITION
CLASS lcl IMPLEMENTATION.
METHOD handle_hotspot_click.
READ TABLE it_data INTO wa INDEX e_row_id.
CHECK sy-subrc = 0.
CASE e_column_id-fieldname.
WHEN 'CHK1'.
IF wa-chk1 = icon_radiobutton.
wa-chk1 = icon_wd_radio_button_empty.
MODIFY it_data from wa INDEX e_row_id.
ELSE.
wa-chk1 = icon_radiobutton.
wa-chk2 = icon_wd_radio_button_empty.
MODIFY it_data from wa INDEX e_row_id.
ENDIF.
WHEN 'CHK2'.
IF wa-chk2 = icon_radiobutton.
wa-chk2 = icon_wd_radio_button_empty.
MODIFY it_data from wa INDEX e_row_id.
ELSE.
wa-chk2 = icon_radiobutton.
wa-chk1 = icon_wd_radio_button_empty.
MODIFY it_data from wa INDEX e_row_id.
ENDIF.
ENDCASE.
CALL METHOD grid->refresh_table_display.
ENDMETHOD. "handle_hotspot_click
ENDCLASS. "lcl IMPLEMENTATION
START-OF-SELECTION.
CALL SCREEN 100.
MODULE fill_data OUTPUT.
IF i_cat IS INITIAL.
w_cat-fieldname = 'CHK1'.
w_cat-icon = 'X'.
w_cat-hotspot = 'X'.
APPEND w_cat TO i_cat.
CLEAR w_cat.
w_cat-fieldname = 'CHK2'.
w_cat-hotspot = 'X'.
w_cat-icon = 'X'.
APPEND w_cat TO i_cat.
CLEAR w_cat.
w_cat-fieldname = 'MATNR'.
APPEND w_cat TO i_cat.
ENDIF.
SELECT matnr FROM mara
INTO CORRESPONDING FIELDS OF TABLE it_data
UP TO 20 ROWS.
LOOP AT it_data INTO wa.
wa-chk1 = '@SR@'.
wa-chk2 = '@SR@'.
MODIFY it_data FROM wa INDEX sy-tabix.
ENDLOOP.
ENDMODULE. " fill_data OUTPUT
MODULE display OUTPUT.
IF cont IS INITIAL .
CREATE OBJECT cont
EXPORTING
container_name = 'CON'.
CREATE OBJECT grid
EXPORTING
i_parent = cont.
CALL METHOD grid->set_table_for_first_display
CHANGING
it_outtab = it_data[]
it_fieldcatalog = i_cat[].
CREATE OBJECT receiver.
SET HANDLER receiver->handle_hotspot_click FOR grid.
ENDIF.
ENDMODULE. "DISPLAY OUTPUT
12-21-2011 4:45 AM
Hi,
Put hot spot for the check box, In the event of hot spot click ,..
call method check_changed _data of alv grid which updates your internal table,
then loop the internal table and check if both the check boxes are selected or not., If selected display error message..
else instead of hot spot, which calls the event each time., put a save button, In on click of save button and do the same as above.,
hope this helps u.,
Thanks & Regards,
Kiran
12-21-2011 5:03 AM
12-21-2011 5:13 AM
Hi,
Go through the following Link,
http://wiki.sdn.sap.com/wiki/display/ABAP/ALVGridReport-withObjectOrientedSALVClasses
I hope it will give idea to you.
Warm Regards,
PavanKumar.G
12-21-2011 5:25 AM
Hi,
Try using ALV event 'DATA_CHANGED' for both the checkbox entry (checked/unchecked)
In the implementation method, update the internal table with the checkbox value and place the validation code for chkbox.
When the event is triggered for 1st chkbox, update the internal table. Now when the event gets triggered for 2nd checkbox, validation code executes as per your requirement.
Regards,
Sharin
12-21-2011 6:35 AM
No need of validation. When clicked remove the check from other one and place it in the clicked one. Check the example below :
CLASS lcl DEFINITION DEFERRED.
TYPE-POOLS: slis.
TYPES:BEGIN OF t_data,
chk1(4) TYPE c,
chk2(4) TYPE c,
matnr TYPE matnr,
END OF t_data.
DATA: i_fcat TYPE slis_t_fieldcat_alv ,
w_fcat LIKE LINE OF i_fcat,
it_data TYPE TABLE OF t_data,
wa TYPE t_data,
i_cat TYPE lvc_t_fcat,
w_cat TYPE lvc_s_fcat,
cont TYPE REF TO cl_gui_custom_container,
grid TYPE REF TO cl_gui_alv_grid,
receiver TYPE REF TO lcl.
CLASS lcl DEFINITION.
PUBLIC SECTION.
METHODS handle_hotspot_click FOR EVENT hotspot_click OF
cl_gui_alv_grid IMPORTING e_row_id e_column_id es_row_no.
ENDCLASS. "lcl DEFINITION
CLASS lcl IMPLEMENTATION.
METHOD handle_hotspot_click.
READ TABLE it_data INTO wa INDEX e_row_id.
CHECK sy-subrc = 0.
CASE e_column_id-fieldname.
WHEN 'CHK1'.
IF wa-chk1 = icon_radiobutton.
wa-chk1 = icon_wd_radio_button_empty.
MODIFY it_data from wa INDEX e_row_id.
ELSE.
wa-chk1 = icon_radiobutton.
wa-chk2 = icon_wd_radio_button_empty.
MODIFY it_data from wa INDEX e_row_id.
ENDIF.
WHEN 'CHK2'.
IF wa-chk2 = icon_radiobutton.
wa-chk2 = icon_wd_radio_button_empty.
MODIFY it_data from wa INDEX e_row_id.
ELSE.
wa-chk2 = icon_radiobutton.
wa-chk1 = icon_wd_radio_button_empty.
MODIFY it_data from wa INDEX e_row_id.
ENDIF.
ENDCASE.
CALL METHOD grid->refresh_table_display.
ENDMETHOD. "handle_hotspot_click
ENDCLASS. "lcl IMPLEMENTATION
START-OF-SELECTION.
CALL SCREEN 100.
MODULE fill_data OUTPUT.
IF i_cat IS INITIAL.
w_cat-fieldname = 'CHK1'.
w_cat-icon = 'X'.
w_cat-hotspot = 'X'.
APPEND w_cat TO i_cat.
CLEAR w_cat.
w_cat-fieldname = 'CHK2'.
w_cat-hotspot = 'X'.
w_cat-icon = 'X'.
APPEND w_cat TO i_cat.
CLEAR w_cat.
w_cat-fieldname = 'MATNR'.
APPEND w_cat TO i_cat.
ENDIF.
SELECT matnr FROM mara
INTO CORRESPONDING FIELDS OF TABLE it_data
UP TO 20 ROWS.
LOOP AT it_data INTO wa.
wa-chk1 = '@SR@'.
wa-chk2 = '@SR@'.
MODIFY it_data FROM wa INDEX sy-tabix.
ENDLOOP.
ENDMODULE. " fill_data OUTPUT
MODULE display OUTPUT.
IF cont IS INITIAL .
CREATE OBJECT cont
EXPORTING
container_name = 'CON'.
CREATE OBJECT grid
EXPORTING
i_parent = cont.
CALL METHOD grid->set_table_for_first_display
CHANGING
it_outtab = it_data[]
it_fieldcatalog = i_cat[].
CREATE OBJECT receiver.
SET HANDLER receiver->handle_hotspot_click FOR grid.
ENDIF.
ENDMODULE. "DISPLAY OUTPUT
12-21-2011 8:31 AM
Hi Keshav,
Thanks a lot for the quick response. Youe logic worked for my scenario. Thanks Everybody.