4
Row Selection in REUSE_ALV_GRID_DISPLAY By default, when you use function module REUSE_ALV_GRID_DISPLAY to display an ALV, it doesn’t come with a Row-Selector. This is fine until you face the need of performing certain task on user-selected rows. Then the user would ask for a Row-Selector. In this post, we would see how can we add this Row-Selector i.e. ‘Row Selection Button’ in an ALV displayed using REUSE_ALV_GRID_DISPLAY and also how to process the selected rows. First, we would see how to add the Row-Selector / Row selection button to ALV. Step 1: Add a new character field of length 1 in your output internal table, say ‘SEL’. This field is used by ALV to store the information if a particular row is selected or not selected. Suppose, earlier, you were using internal table lt_outtab for your ALV display. So, now, you would need a new output table lt_outtab_new with the above mentioned field. This is how you would do it. DATA:

Row Selection in REUSE

  • Upload
    suresh

  • View
    18

  • Download
    0

Embed Size (px)

DESCRIPTION

ABAP and ALV

Citation preview

Page 1: Row Selection in REUSE

Row Selection in REUSE_ALV_GRID_DISPLAYBy default, when you use function module REUSE_ALV_GRID_DISPLAY to display an ALV, it doesn’t come with a Row-Selector. This is fine until you face the need of performing certain task on user-selected rows. Then the user would ask for a Row-Selector. In this post, we would see how can we add this Row-Selector i.e. ‘Row Selection Button’ in an ALV displayed using REUSE_ALV_GRID_DISPLAY and also how to process the selected rows.

First, we would see how to add the Row-Selector / Row selection button to ALV.

Step 1: Add a new character field of length 1 in your output internal table, say ‘SEL’. This field is used by ALV to store the information if a particular row is selected or not selected.

Suppose, earlier, you were using internal table lt_outtab for your ALV display. So, now, you would need a new output table lt_outtab_new with the above mentioned field. This is how you would do it.

DATA:

lt_outtab TYPE STANDARD TABLE OF xyz,

ls_outtab TYPE xyz.

TYPES:

BEGIN OF str_xyz,

Page 2: Row Selection in REUSE

sel  TYPE c.

INCLUDE STRUCTURE xyz.

TYPES: END OF str_xyz.

DATA:

lt_outtab_new TYPE STANDARD TABLE OF str_xyz,

ls_outtab_new TYPE str_xyz.

………………………………………………

………………………………………………

* Moving your output data from old output table to new output table.

LOOP AT lt_outtab INTO ls_outtab.

MOVE-CORRESPONDING ls_outtab TO ls_outtab_new.

APPEND ls_outtab_new TO lt_outtab_new.

ENDLOOP.

Step 2: Inform the ALV frameowrk about the name of the newly added field in your output internal table, which ALV should use for storing the information about whether a row is selected or not. You can pass this information to ALV framework by setting attribure BOX_FIELDNAME of the ALV Layout.

DATA: ls_layout TYPE slis_layout_alv.

ls_layout-box_fieldname = ‘SEL’.

Step 3: Use REUSE_ALV_GRID_DISPLAY to display your ALV with the new output internal table and updated ALV layout.

CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’

EXPORTING

i_callback_program = sy-repid

i_callback_user_command = ‘USER_COMMAND’

Page 3: Row Selection in REUSE

is_layout = ls_layout

………………………………….

………………………………….

TABLES

t_outtab = lt_outtab_new.

This is all you need to do in order to get the Row-Selector displayed.

Next, you need to perform tasks on the selected rows. How to handle this?

You can process the selected rows in the callback user command subroutine (in our example, USER_COMMAND) in the callback program (in our example, sy-repid) which you pass to FM REUSE_ALV_GRID_DISPLAY through parameters i_callback_user_command & i_callback_program.

All the rows which have been selected by user will have the newly added box-field (in our example, SEL) marked as ‘X’.

You can then have the a logic to perform various tasks on the selected rows based on your needs.

FORM user_command

USING

r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

LOOP AT lt_outtab_new INTO ls_outtab_new WHERE sel = ‘X’.

…………………………………………….

…………………………………………….

ENDLOOP.

ENDFORM.

This is how you add a Row-Selector to your ALV and handle the selected rows in your user command callback.

Page 4: Row Selection in REUSE