Application Development 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: 

ALV grid check box

Former Member
0 Kudos
535

Hi,

I am using ALV gid with FM 'REUSE_ALV_GRID_DISPLAY_LVC'. I am displaying a check box on the screen. I have to know how many check box were selected.

Any idea how to get that.

I have used lay-box_fnname = checkbox and looped the itab in user command. But I am not getting the desired result. Please lte me know how its managed.

KK.

5 REPLIES 5

Former Member
0 Kudos
89

Hi Krishna,

For these kind of Scenarious What you need to do is:

1. Create a Field CHECKBOX in your internal table

2. Set this field as checkbox field in the layout by using lay-box_fnname = 'checkbox'

3.If you read the Internal table in the User command it will definetly update it. But check that you may be set the property of this field as checkbox in the fieldcatalog also. If you do that it won't work.

4. That too in the grid display it won't display the check box why because it shows one button for each row. if you want to select multiple rows then you need to select them using the Ctrl+ Mouse click on the button.

5. Definetly you will solve your problem with this inforamtion

Warm Regards,

Vijay

0 Kudos
89

Hi Vijay,

Thanks for reply. Points what you have suggested are fine and I tried them. But result is not giving the result what I wanted. Please tell me if we have any OO method to get the rows.

KK.

ashok_kumar24
Contributor
0 Kudos
89

Hi Krishna,

<b>Good check the following documentation and example links

---You have to modify the field Catalog fields (fields that you want to make editable).Set the field EDIT as 'X'.For example if you want to make the field below editable:

ls_fcat-fieldname = 'CARRID'.

...

...

ls_fcat-edit = 'X'.

APPEND ls_fcat TO pt_fieldcat.

---For check-box,add:

ls_fcat-checkbox = 'X'.

---Call the method below before you call the set_table_for_first_display/refresh_table_display.

CALL METHOD ALV_GRID_INSTANCE->set_ready_for_input

EXPORTING

i_ready_for_input = 0. ( For Display ) and ('1' for Edit )

After this put the set_table_for_first_display/refresh_table_display.

Please refer the links,

Good Luck and thanks

AK

Former Member
0 Kudos
89
REPORT ZALV_DISPLAY_CHANGE.

TABLES :T247.

TYPE-POOLS SLIS. "Type definitions for alv report

DATA: IT_FIELDCAT TYPE LVC_T_FCAT,
WA_FIELDCAT TYPE LVC_S_FCAT.

DATA: WA_LAYOUT TYPE LVC_S_LAYO.

DATA : BEGIN OF IT_FINAL OCCURS 0,
CHECK(1),
CELLTAB TYPE LVC_T_STYL, " Switch between display/change
MNR LIKE T247-MNR,
LTX LIKE T247-LTX,
END OF IT_FINAL.
DATA : WA_FINAL LIKE IT_FINAL.
DATA : W_REPID LIKE SY-REPID.

W_REPID = SY-REPID.

REFRESH IT_FINAL.
SELECT MNR LTX
FROM T247
INTO CORRESPONDING FIELDS OF TABLE IT_FINAL
WHERE SPRAS EQ 'E'.


WA_FIELDCAT-FIELDNAME = 'CHECK'.
WA_FIELDCAT-TABNAME = 'IT_FINAL'.
WA_FIELDCAT-CHECKBOX = 'X'.
WA_FIELDCAT-EDIT = 'X'..
WA_FIELDCAT-OUTPUTLEN = '3'.
WA_FIELDCAT-COL_POS = '1'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-FIELDNAME = 'MNR'.
WA_FIELDCAT-TABNAME = 'IT_FINAL'.
WA_FIELDCAT-OUTPUTLEN = '8'.
WA_FIELDCAT-COL_POS = '2'.
WA_FIELDCAT-REPTEXT = 'Month'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-FIELDNAME = 'LTX'.
WA_FIELDCAT-TABNAME = 'IT_FINAL'.
WA_FIELDCAT-OUTPUTLEN = '20'.
WA_FIELDCAT-COL_POS = '3'.
WA_FIELDCAT-REPTEXT = 'Month Desc'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.

DATA: WA_CELLTAB TYPE LVC_S_STYL,
IT_CELLTAB TYPE LVC_T_STYL,
L_INDEX TYPE I.
CLEAR : WA_CELLTAB,WA_FINAL,IT_CELLTAB.
REFRESH IT_CELLTAB.

*Initialize the celltab table
LOOP AT IT_FINAL INTO WA_FINAL.
L_INDEX = SY-TABIX.
WA_CELLTAB-FIELDNAME = 'CHECK'.
WA_CELLTAB-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED.
INSERT WA_CELLTAB INTO TABLE IT_CELLTAB.
INSERT LINES OF IT_CELLTAB INTO TABLE WA_FINAL-CELLTAB.
MODIFY IT_FINAL FROM WA_FINAL INDEX L_INDEX.
ENDLOOP.

*Make the first five 5 rows as disabled
CLEAR L_INDEX.
LOOP AT IT_FINAL INTO WA_FINAL.
L_INDEX = SY-TABIX.
IF SY-TABIX LE 5.
LOOP AT WA_FINAL-CELLTAB INTO WA_CELLTAB.
IF WA_CELLTAB-FIELDNAME EQ 'CHECK' .
WA_CELLTAB-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
MODIFY WA_FINAL-CELLTAB FROM WA_CELLTAB.
MODIFY IT_FINAL INDEX L_INDEX FROM WA_FINAL TRANSPORTING CELLTAB.
ENDIF.
ENDLOOP.
ENDIF.
ENDLOOP.


WA_LAYOUT-BOX_FNAME = 'CHECK'.
WA_LAYOUT-NO_ROWMARK = 'X'.
WA_LAYOUT-STYLEFNAME = 'CELLTAB'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
I_CALLBACK_PROGRAM = W_REPID
I_GRID_TITLE = 'GRID DISPLAY'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IS_LAYOUT_LVC = WA_LAYOUT
IT_FIELDCAT_LVC = IT_FIELDCAT
TABLES
T_OUTTAB = IT_FINAL
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.

FORM USER_COMMAND USING P_UCOMM TYPE SY-UCOMM
                        P_SELFLD TYPE SLIS_SELFIELD.

Data ref1 type ref to cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = ref1.
call method ref1->check_changed_data

CASE P_UCOMM.
  WHEN 'DELETE'.
      loop at it_final where check eq 'X'.
        count = count + 1.                       " Counts the no of checked records
      endloop.
ENDCASE.

ENDFORM.

Former Member
0 Kudos
89

Hi Krishna,

Use Method <b>get_selected_rows</b> of

Class <b> CL_GUI_ALV_GRID</b> : To get selected rows

<b>CL_GUI_ALV_GRID=>get_selected_rows</b>

Reward points if helpful.

Regards,

Hemant