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: 

Checkbox to select a bunch of records in ALV grid display ..

Jay_Kamdar
Participant
0 Kudos
7,149

Hello Experts ,

I have a requirement where in an alv grid display the user should be able to CHECK a block of records having the same value .

Please refer the sketch of the proposed screen below:

Scenario :

All the data will be displayed initially with blank Reference No. field ;

When the user clicks on a certain button a reference no is generated on the screen for a bunch of records;

Multiple records can have the same reference no.

So, when the reference no. is generated the user must be able to CHECK one reference no. rather than checking every record with same reference no.

Is this possible?

If yes then kindly answer ....

ORDER DETAILS
MarkReference No.Brand CodeDealer CodeDealer NameDealer LocationZoneLSP Total
R0001 SCROLL BAR
R0002
R0003
R0004
R0005
R0006
R0007
R0008
R0009
R0010
SCROLL BAR

Regards,

Jay Kamdar.

1 ACCEPTED SOLUTION

former_member215424
Active Participant
0 Kudos
2,629

Hi Jay,

U can try the below logic.

When a Mark field is checked for one reference no. entry on the ALV grid display, write a user command event handler.

in that handler form the logic could be : loop at the internal table used to display in the grid where the MARK field is checked, if so store the reference no. of the row. then LOOP again the same table with same reference no. but for which MARK field is not checked, inside the loop , move 'X' to MARK field.

EX: Below is the snippet

FORM user_command  USING r_ucomm LIKE sy-ucomm

REFRESH : it_data1.

CASE r_ucomm.

WHEN 'CHECK'.

IF alv_list IS NOT INITIAL.

       LOOP AT it_data INTO wa_data WHERE mark = 'X'.

   r_refno = wa_data-refno.

   LOOP AT it_data INTO wa_data2 WHERE refno = r_refno and MARK NE 'X'.

      wa_data2-mark = 'X'.

      MODIFY  it_data INDEX sy-tabix FROM wa_data2.

       ENDLOOP.

ENDLOOP.

14 REPLIES 14

former_member215424
Active Participant
0 Kudos
2,630

Hi Jay,

U can try the below logic.

When a Mark field is checked for one reference no. entry on the ALV grid display, write a user command event handler.

in that handler form the logic could be : loop at the internal table used to display in the grid where the MARK field is checked, if so store the reference no. of the row. then LOOP again the same table with same reference no. but for which MARK field is not checked, inside the loop , move 'X' to MARK field.

EX: Below is the snippet

FORM user_command  USING r_ucomm LIKE sy-ucomm

REFRESH : it_data1.

CASE r_ucomm.

WHEN 'CHECK'.

IF alv_list IS NOT INITIAL.

       LOOP AT it_data INTO wa_data WHERE mark = 'X'.

   r_refno = wa_data-refno.

   LOOP AT it_data INTO wa_data2 WHERE refno = r_refno and MARK NE 'X'.

      wa_data2-mark = 'X'.

      MODIFY  it_data INDEX sy-tabix FROM wa_data2.

       ENDLOOP.

ENDLOOP.

0 Kudos
2,629

Thank you

Former Member
0 Kudos
2,629

First add a row selector or row selection button into your ALV.

You can process the selected rows in the callback user command subroutine.

In that loop through the table to find the matching reference of the selected row and then mark the matching ones as selected.

krishna_k19
Contributor
0 Kudos
2,629

Hi,

  if suppose your having one ref.no three time (R0001,R0001,R0001)  so if you selected one ref.no then inside system has to be consider has  3 line times.

Means these 3 line items data should be present in the ALV Table(means which table your display as a final)

so then after use AT User command command like this.

FORM user_command  USING r_ucomm LIKE sy-ucomm

                                            sel_field like slis_selfield.

slis_selfield -- this one contains the fields data based on this you can mark the remaining 2 line items .

loop it_final into wa_final where field = sel_field-value. "field.

if wa_final-mark ne 'X'.

  wa_final-mark = 'X'.

modify it_final from wa_final transporting mark.

endloop.

pls check.

thanks in advance,

krishna



former_member184569
Active Contributor
0 Kudos
2,629

First to handle event with checkbox, set hotspot in the field catalog for checkbox field.

   CLEAR gs_fcat.

   gs_fcat-fieldname  = 'CHECKBOX'.

   gs_fcat-seltext_m  = 'Select'.

   gs_fcat-checkbox  = 'X'.

   gs_fcat-hotspot     = 'X'.

   APPEND gs_fcat TO gt_fcat.

   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

     EXPORTING

       i_callback_program           = gv_repid

       i_callback_user_command = 'USER_COMMAND'

       is_layout                          = gs_layout

       it_fieldcat                         = gt_fcat

     TABLES

       t_outtab                           = gt_scarr.

FORM user_command USING r_ucomm LIKE sy-ucomm

                         rs_selfield TYPE slis_selfield.

case r_ucomm.

  when '&IC1'.

DATA: lr_grid TYPE REF TO cl_gui_alv_grid.

    "Reference to the ALV grid object

   DATA: lr_grid TYPE REF TO cl_gui_alv_grid.

   CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

     IMPORTING

       e_grid = lr_grid.

    CALL METHOD lr_grid->check_changed_data.

* Write the code to set checkbox = 'X' for all the records with same ref no. You can use the logic Shruti suggested.

* loop at the alv data table, if check box = 'X', set the checkbox of all records with same reference number to 'X'

   "Calling method to refresh the data in the ALV

   CALL METHOD lr_grid->refresh_table_display.

endcase.

ENDFORM.                    "user_command

0 Kudos
2,629

Thank you

0 Kudos
2,629

Hello,

I am using the method set_table_for_first_display of class cl_gui_alv_grid to display the ALV grid in the screen,

how will i get the user command when the user marks a record ?

Please help .

0 Kudos
2,629

Here the user command is triggered by the hotspot attribute of the checkbox.

So if you are using the OOPs method, just handle the hotspot click event.

METHODS: handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid.

Check this code.

http://wiki.scn.sap.com/wiki/display/Snippets/How+to+Add+button+and+hotspot+in+ALV+OOPS

0 Kudos
2,629

Thank you

0 Kudos
2,363

Hii Krishna,

I Have written same logic to get select record but my program is going to dump after CALL METHOD ref_grid->CHECK_CHANGED_DATA. 

    DATA ref_grid TYPE REF TO cl_gui_alv_grid"new
    IF ref_grid IS INITIAL.
      CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
      IMPORTING
        e_grid ref_grid.
    ENDIF.
    IF ref_grid IS BOUND.
        CALL METHOD ref_grid->CHECK_CHANGED_DATA.
    ENDIF.

This Logic i have written can you give my suggestion on this.

Former Member
0 Kudos
2,629

Hi jay ,

To achieve the above requirement three simple steps :

1 ) To achieve the check all option place buttons in application toolbar using menu painter and name it accordingly  like select all / deselect all .

2 ) For selecting particular reference number you can use filter option .By default it would available in the normal ALV Grid display application tool bar .

3 ) use this function module to get the value in the grid display after filtering process REUSE_ALV_GRID_LAYOUT_INFO_GET.

Steps to use the report after development .

1 ) Normal alv grid list display with all refernece numbers . (ie inital output screen).

2 )Use the filter option in the application toolbar to filter particular reference document alone .

By the required reference document alone selected .

3 ) The using the REUSE_ALV_GRID_LAYOUT_INFO_GET function module you could get the values in the grid list display after filtering .

4) Then you can use the select all option to select all / select particular records based on the user requirement .

attached a simple screen shot for reference

Feel free to contact for any clarifications.

Regards,

Sanjith N

0 Kudos
2,629

Thanks but the requirement is different than your suggestion .

krishnakumarn
Product and Topic Expert
Product and Topic Expert
0 Kudos
2,629

Hi Jay,

Display the reference-id as hotspot ,Define a handler for hot spot link in such a way that all the check box with the same reference-id will get automatically get selected.

I hope this will resolve your issue.

Thanks & Regards,

Krishna N

0 Kudos
2,629

Thank you