Skip to Content
0

event for checkbox changed in CL_GUI_ALV_GRID

Jul 10, 2017 at 11:07 AM

238

avatar image

Hello,

my CL_GUI_ALV_GRID includes a column of checkboxes. When a user is changing the value of a checkbox my programm has to modify a value in the same row.

I cannot find the event, which is fired, when the value of a checkbox in an CL_GUI_ALV_GRID object is changed.

Can anyone give me the name of this event?

Btw: I do not want to react on a "enter hit" or "button pressed" action.

Regards,

Hubert

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

5 Answers

Best Answer
Richard Harper Jul 10, 2017 at 12:01 PM
2

Try using the hotspot event.

Show 7 Share
10 |10000 characters needed characters left characters exceeded

Your idea seemed to be a solution.

Actually there is no information provided to the event handler, if the checkbox has been checked or unchecked.

Even the table which is displayed by ALV is not updated.

Trying to call method check_changed_data( ) for my CL_GUI_ALV_GRID object in event handler does not solve the problem.

0

(typed using chopsticks.....). That's correct. You use the (I think) get_select_cell method I think.

I'll check tomorrow. Send me a nudge because I'll of had a sleep by then.

Rich

0

I called get_select_cell method in event handler already.

check checkbox -> hotspot_click fired -> call get_select_cell => e_value = 0

uncheck checkbox -> hotspot_click fired -> call get_select_cell => e_value = 1

I don't know why, but it seems to me like e_value = 0 means checkbox not checked.

Nether the less:When we define e_value = 0 means checkbox checked, then everything should work fine.

Do you agree Richard?

0

So, I tried like described.

The problem now:

To show the value, which is derived from result of get_select_cell-method and displayed in another column of the same row, I have to call method refresh_table_display of CL_GUI_ALV_GRID object in my handler.

Now refresh_table_display cleans the checkbox again, so that always an unchecked chechbox is shown and get_select_cell does never yield another value than e_value = 0.

0

In the ALV Grid 0 = false or unchecked, 1 = true or checked. So to enable something you use 1, disable is 0.

As an aside this is the way I do it (I have a generic ALV Wrapper which takes all the grunt work out of things):

You are given the row and column id's when the event is called. If a column is defined as a hotspot then even sub total and total cells are clickable....

Method  Handle_HOTSPOT_CLICK.
*
*            Only handle normal rows
*
             If Me->Handle_Row( e_Row_Id ) = Abap_True.
*
*               For a normal row the Index value of the E_ROW_ID variable is
*               enough to define the row to use,  however for other types of
*               row the index has to be calculated.
*
*               For example if the field clicked is a sub-total field then
*               the row number is the index into a table containing the  rows
*               at that level.....
*


                Me->Hotspot_Process( i_Row_Index = Calculate_Row_Index( i_Row_Id = e_Row_Id
                                                                        i_Column = e_Column_Id-FieldName )
                                     i_Column    = e_Column_Id-FieldName ).
             EndIf.
EndMethod.

Handle_Row determines if it's just a normal row:

  method HANDLE_ROW.
*
         Data: ls_RowType Type RowType_Structure.
*
         r_Handle = Abap_False.
         ls_RowType = i_Row-RowType.
         If ' S' cs ls_RowType-Type.
            r_Handle = Abap_True.
         EndIf.
  endmethod.

Having decided that we want to process this as a hotspot, the actual application redefines what it wants to do with that hotspot. For example:

      Method Hotspot_Process.
*
             Field-Symbols: <f_Detail_Line> Type Detail_Line.
*
*            This method handles the clicks on the ident or the supplier
*            columns as they cannot be handled generically.
*
             Data: lt_Detail_Report Type Detail_Report.
*
             lt_Detail_Report = Me->Get_Detail_Report( ).
*
             Read Table lt_Detail_Report
                   Index i_Row_Index
                   Assigning <f_Detail_Line>.
             Case i_Column.
                  When 'IDENT'.
                        Case <f_Detail_Line>-Line_Type.
                             When c_lt_Journal.
                                  Me->Show_Journal_Entry( i_Ident = <f_Detail_Line>-Ident
                                                          i_Bukrs = <f_Detail_Line>-Bukrs
                                                          i_GJahr = <f_Detail_Line>-GJahr ).
                             When c_lt_Purchase_Order.
                                  Me->Show_Purchase_Order( i_Ident = <f_Detail_Line>-Ident
                                                           i_Item  = <f_Detail_Line>-Item ).
                        EndCase.
                  When 'LIFNR'.
                        Me->Show_Vendor( Exporting i_Bukrs = <f_Detail_Line>-Bukrs
                                                   i_Lifnr = <f_Detail_Line>-Lifnr ).
                  When Others.
*
*                       Not for us - is it a generic hotspot ?
*
                        Call Method Super->Hotspot_Process
                          Exporting
                             i_Row_Index = i_Row_Index
                             i_Column    = i_Column.
             EndCase.
      EndMethod.

The hotspot process method in the Super class reads a table of data element roll names using the clicked fields roll name. This table has entries for PID's, and transactions and if an entry is found then the relevant transaction is called.

This means that for every ALV grid I create, without even thinking about it I get drill down functionality in every grid. (There are other things that are required such as INIT_HOTSPOTS which modifies the field catalog and layout structures based upon the contents of the hotspot table and methods to handle headers and footers etc)

So if you're in this game for the long run it's advisable to start collecting together bits and bobs which make your life easier.

Rich

0

If its true that "In the ALV Grid 0 = false or unchecked, 1 = true or checked" I have to invert the definition since get_select_cell-method yields not an updated value when called in hotspot_click event handler.

Your wrapper above makes life definitely easier, but does not help me in any way.

If there are no other suggestions, I will have to create my own checkbox.

0

Thank you Richard!

I used the hotspot event with my own "checkbox".

1
Sandra Rossi Jul 11, 2017 at 05:31 AM
0

You may have a look at the demo program BCALV_EDIT_05, which shows how to handle checkboxes.

Show 3 Share
10 |10000 characters needed characters left characters exceeded

Checking or unchecking the checkbox is not handled in BCALV_EDIT_05.

0

It's handled, but I admit it's not the single click, it's the double click.

0

Yes, you are right.

But I mean double click on checkbox is at best unusual and I am looking for a checkbox changed event ...

1
biswa jena Jul 13, 2017 at 05:51 AM
0

go for style in oops abap .its having enable and disable method declare a chk in final table.

loop that internal table .

when final-chk = 'x'.

  1. lt_celltab TYPE lvc_t_styl,
  2. ls_celltab TYPE lvc_s_styl,

using event DATA_CHANGED.

Share
10 |10000 characters needed characters left characters exceeded
biswa jena Jul 13, 2017 at 06:12 AM
0
  1. when ' sy-ucomm '.
  2. DATA: L_VALID TYPE C,
  3. LT_ROW_NO TYPE LVC_T_ROID WITH HEADER LINE.
  4. CALL METHOD G_GRID->CHECK_CHANGED_DATA
  5. IMPORTING
  6. E_VALID = L_VALID.
  7. IF L_VALID EQ 'X'.
  8. LOOP AT output_table ............ where checkbox_column eq 'x'.
  9. "call the bapi for SO and Delivery.
  10. "pass the sales order number and delivery number
  11. MODIFY PT_OUTTAB FROM LS_OUTTAB ."modify the itab
  12. endloop.
  13. CALL METHOD G_GRID->REFRESH_TABLE_DISPLAY."call this method after the endloop.
  14. endif.
Show 1 Share
10 |10000 characters needed characters left characters exceeded

And how does it get here ? Btw, With Header line is obsolete.

0
biswa jena Jul 13, 2017 at 10:49 AM
0

Dear Hubert,

go through the following code u may have some idea.

In this post we will create an OO alv which is having the check boxes and icons, when the user checks the check box and executes it, then we will get a pop confirmation. Afterwards the the adjacent field value of the checked box will be modified at the runtime.

*********************************************************************************************************************

TYPE-POOLS cntl.

DATA: ok_code LIKE sy-ucomm,
g_repid LIKE sy-repid,
g_max TYPE i VALUE 50,
gs_layout TYPE lvc_s_layo,
gt_fcat TYPE lvc_t_fcat,
gs_fcat TYPE lvc_s_fcat,
gt_events TYPE cntl_simple_events,
custom_container TYPE REF TO cl_gui_custom_container,
grid1 TYPE REF TO cl_gui_alv_grid.


DATA: ls_edit TYPE lvc_s_styl,
lt_edit TYPE lvc_t_styl.

TYPES: BEGIN OF ty_outtab,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
fldate TYPE sflight-fldate,
price TYPE sflight-price,
light TYPE c,
checkbox TYPE c,
style TYPE lvc_t_styl,
END OF ty_outtab.


TYPES: BEGIN OF ty_outtab1,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
fldate TYPE sflight-fldate,
price TYPE sflight-price,
END OF ty_outtab1.

DATA: gt_outtab TYPE STANDARD TABLE OF ty_outtab,
wa_outtab TYPE ty_outtab,
gt_sflight TYPE STANDARD TABLE OF ty_outtab1,
gs_sflight TYPE ty_outtab1,
gt_sflight1 TYPE STANDARD TABLE OF ty_outtab,
gs_sflight1 TYPE ty_outtab.

DATA: ls_outtab LIKE LINE OF gt_sflight1.

*———————————————————————-*
* CLASS LCL_WRAPPER DEFINITION
*———————————————————————-*
*
*———————————————————————-*
CLASS lcl_wrapper DEFINITION.

PUBLIC SECTION.

METHODS : update_table1 FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed
e_onf4
e_onf4_before
e_onf4_after. “#EC CALLED

ENDCLASS. “LCL_WRAPPER DEFINITION

*———————————————————————-*
* CLASS LCL_WRAPPER IMPLEMENTATION
*———————————————————————-*
*
*———————————————————————-*
CLASS lcl_wrapper IMPLEMENTATION.

METHOD update_table1.

DATA : lv_count TYPE i.
DATA : lv_value TYPE char1.
DATA : lv_index TYPE sy-index.
DATA: ans TYPE char1.

DESCRIBE TABLE gt_sflight1 LINES lv_count.

DO lv_count TIMES.
CLEAR lv_value.
lv_index = sy-index.

CALL METHOD er_data_changed->get_cell_value
EXPORTING
* I_ROW_ID = lv_count
i_tabix = lv_index
i_fieldname = ‘CHECKBOX’
IMPORTING
e_value = lv_value.

IF lv_value = ‘X’ .

READ TABLE gt_sflight1 INTO gs_sflight1 INDEX lv_index.
wa_outtab-carrid = gs_sflight1-carrid .
wa_outtab-checkbox = ‘X’ .
APPEND wa_outtab TO gt_outtab.

CALL METHOD grid1->get_frontend_fieldcatalog
IMPORTING
et_fieldcatalog = gt_fcat[].


LOOP AT gt_fcat INTO gs_fcat .

IF gs_fcat-fieldname = ‘CHECKBOX’ .

gs_fcat-checkbox = ‘X’.
gs_fcat-edit = ”.

ENDIF .

MODIFY gt_fcat FROM gs_fcat .


ENDLOOP .

CALL METHOD grid1->set_frontend_fieldcatalog
EXPORTING
it_fieldcatalog = gt_fcat[].

CALL METHOD grid1->set_table_for_first_display
EXPORTING
* i_structure_name = ‘SFLIGHT’
is_layout = gs_layout
CHANGING it_outtab = gt_sflight1[]
it_fieldcatalog = gt_fcat .

CALL METHOD er_data_changed->modify_cell
EXPORTING
* I_ROW_ID = lv_count
i_tabix = lv_index
i_fieldname = ‘CONNID’
i_value = ‘00001’.
ENDIF.

ENDDO.
DO lv_count TIMES.
CLEAR lv_value.

lv_index = sy-index.

CALL METHOD er_data_changed->get_cell_value
EXPORTING
* I_ROW_ID = lv_count
i_tabix = lv_index
i_fieldname = ‘CHECKBOX’
IMPORTING
e_value = lv_value.
CALL METHOD er_data_changed->modify_cell
EXPORTING
* I_ROW_ID = lv_count
i_tabix = lv_index
i_fieldname = ‘CHECKBOX’
i_value = ”.

ENDDO.

ENDMETHOD. “UPDATE_TABLE1

ENDCLASS. “LCL_WRAPPER IMPLEMENTATION

DATA: g_lights_name TYPE lvc_cifnm VALUE ‘LIGHT’.
DATA : lo_wrapper TYPE REF TO lcl_wrapper.

START-OF-SELECTION.

CALL SCREEN 100.

*———————————————————————*
* FORM EXIT_PROGRAM *
*———————————————————————*
FORM exit_program.
CALL METHOD grid1->free.
CALL METHOD cl_gui_cfw=>flush.
IF sy-subrc NE 0.
* add your handling, for example
CALL FUNCTION ‘POPUP_TO_INFORM’
EXPORTING
titel = g_repid
txt2 = sy-subrc
txt1 = ‘Error in FLush’(500).
ENDIF.
LEAVE PROGRAM.
ENDFORM. “exit_program
*&———————————————————————*
*& Module PBO_100 OUTPUT
*&———————————————————————*
* text
*———————————————————————-*
MODULE pbo_100 OUTPUT.

DATA : lw_event TYPE cntl_simple_event.

SET PF-STATUS ‘MAIN100’.
SET TITLEBAR ‘MAIN100’.
g_repid = sy-repid.
IF custom_container IS INITIAL.

SELECT carrid
connid
fldate
price
FROM sflight INTO TABLE gt_sflight UP TO g_max ROWS.
LOOP AT gt_sflight INTO gs_sflight.
gs_sflight1-carrid = gs_sflight-carrid .
gs_sflight1-connid = gs_sflight-connid .
gs_sflight1-fldate = gs_sflight-fldate .
gs_sflight1-price = gs_sflight-price .
APPEND gs_sflight1 TO gt_sflight1.
CLEAR gs_sflight1.
ENDLOOP.

LOOP AT gt_sflight1 INTO gs_sflight1.
IF gs_sflight1-carrid = ‘AA’.
gs_sflight1-light = ‘1’.
ELSEIF gs_sflight1-carrid = ‘AZ’.
gs_sflight1-light = ‘3’.
ELSE.
gs_sflight1-light = ‘2’.
ENDIF.
MODIFY gt_sflight1 INDEX sy-tabix FROM gs_sflight1.
ENDLOOP.

PERFORM build_data .

CREATE OBJECT custom_container
EXPORTING
container_name = ‘OO_ALV’
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc NE 0.

* add your handling, for example
CALL FUNCTION ‘POPUP_TO_INFORM’
EXPORTING
titel = g_repid
txt2 = sy-subrc
txt1 = ‘The control could not be created’(510).
ENDIF.
* create an instance of alv control
CREATE OBJECT grid1
EXPORTING
i_parent = custom_container.

*……………………………………….
* set some layout-values (Structure LVC_S_LAYO)
*……………………………………….

LOOP AT gt_sflight1 INTO gs_sflight1.
IF gs_sflight1-carrid = ‘AA’.
ls_edit-style = cl_gui_alv_grid=>mc_style_enabled.
ELSEIF gs_sflight1-carrid = ‘AZ’.
ls_edit-style = cl_gui_alv_grid=>mc_style_disabled.
ENDIF.
ls_edit-fieldname = ‘CHECKBOX’.
INSERT ls_edit INTO TABLE lt_edit.
INSERT LINES OF lt_edit INTO TABLE ls_outtab-style.
MODIFY gt_sflight1 INDEX sy-tabix
FROM ls_outtab TRANSPORTING style .

CLEAR ls_outtab.
REFRESH lt_edit.
CLEAR ls_edit.
ENDLOOP.
gs_layout-grid_title = ‘Flights’(100).
gs_layout-excp_fname = g_lights_name.
gs_layout-no_rowmark = ‘X’.
gs_layout-stylefname = ‘STYLE’.

CALL METHOD grid1->get_registered_events
IMPORTING
events = gt_events
EXCEPTIONS
cntl_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

lw_event-eventid = 11.
lw_event-appl_event = ‘UPDATE_TABLE1’.

APPEND lw_event TO gt_events.

CALL METHOD grid1->set_registered_events
EXPORTING
events = gt_events
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 3
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL METHOD grid1->set_table_for_first_display
EXPORTING
* i_structure_name = ‘SFLIGHT’
is_layout = gs_layout
CHANGING it_outtab = gt_sflight1[]
it_fieldcatalog = gt_fcat .

CREATE OBJECT lo_wrapper.

SET HANDLER lo_wrapper->update_table1 FOR ALL INSTANCES.

ENDIF.
CALL METHOD cl_gui_control=>set_focus
EXPORTING
control = grid1.

* Control Framework flushes at the end of PBO automatically!
ENDMODULE. ” PBO_100 OUTPUT
*&———————————————————————*
*& Module PAI_100 INPUT
*&———————————————————————*
* text
*———————————————————————-*
MODULE pai_100 INPUT.

CASE ok_code.
WHEN ‘BACK’.
PERFORM exit_program.
WHEN ‘EXIT’.
PERFORM exit_program.
WHEN ‘SWITCH’.
* data: upcl1 TYPE REF TO UPDATE_TABLE1.
DATA: ans TYPE char1.
CALL FUNCTION ‘POPUP_FOR_INTERACTION’
EXPORTING
headline = ‘POPUP’
text1 = ‘lets do it’
* TEXT2 = ‘ ‘
* TEXT3 = ‘ ‘
* TEXT4 = ‘ ‘
* TEXT5 = ‘ ‘
* TEXT6 = ‘ ‘
* TICON = ‘I’
button_1 = ‘yes’
button_2 = ‘No’
* BUTTON_3 = ‘ ‘
IMPORTING
button_pressed = ans
.

IF ans = ‘1’.
CALL METHOD grid1->check_changed_data
* IMPORTING
* E_VALID = CHANGING
* C_REFRESH = ‘X’
.

ENDIF.

* PERFORM SWITCH_LED_STYLE.

CLEAR ok_code.
* p_selfield-refresh = ‘X’.
ENDCASE.
ENDMODULE. ” PAI_100 INPUT
*&———————————————————————*
*& Form SELECT_TABLE_SFLIGHT
*&———————————————————————*
* text
*———————————————————————-*
* <–P_GT_SFLIGHT text
*———————————————————————-*
*form build_data tables p_gt_outtab structure gt_outtab.
FORM build_data.

gs_fcat-fieldname = ‘CHECKBOX’.
gs_fcat-coltext = ‘Select Form’.
gs_fcat-col_pos = ‘2’.
gs_fcat-tabname = ‘GT_SFLIGHT1’.
* gs_fcat-input = ‘0’.
gs_fcat-edit = ‘X’.
gs_fcat-checkbox = ‘X’.
gs_fcat-outputlen = ’11’.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

gs_fcat-fieldname = ‘LIGHT’.
gs_fcat-coltext = ‘LIGHT’.
gs_fcat-col_pos = ‘1’.
gs_fcat-tabname = ‘GT_SFLIGHT1’.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
gs_fcat-fieldname = ‘CARRID’.
gs_fcat-coltext = ‘PLANE’.
gs_fcat-col_pos = ‘3’.
gs_fcat-tabname = ‘GT_SFLIGHT1’.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
gs_fcat-fieldname = ‘CONNID’.
gs_fcat-coltext = ‘PLANE AGA’.
gs_fcat-col_pos = ‘4’.
gs_fcat-tabname = ‘GT_SFLIGHT1’.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
gs_fcat-fieldname = ‘FLDATE’.
gs_fcat-coltext = ‘DATE’.
gs_fcat-col_pos = ‘5’.
gs_fcat-tabname = ‘GT_SFLIGHT1’.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
gs_fcat-fieldname = ‘PRICE’.
gs_fcat-coltext = ‘RATE’.
gs_fcat-col_pos = ‘6’.
gs_fcat-tabname = ‘GT_SFLIGHT1’.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

ENDFORM. ” SELECT_TABLE_SFLIGHT

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Thanks Biswa,

but I already implemented my own checkbox which fires an hotspot event.

Implementation is accepted, so my problem is solved.

0

I also wouldn't take the above as a good programming example.

0