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: 
Read only

Selecting Multiple Rows from ALV GRID Display

Former Member
0 Likes
16,473

Hi,

I am having a ALV GRID Display. I want to select multiple rows from the Output and move them to an internal table.

Please let me know how do I acheive this.

Thanks in advance,

Ishaq.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
5,207

Hi,

You can do this using check box.

giving piece of code....for sake of logic.

Use this logic...for ur requireemnt.

I made the code into bold...where it is required for Check Box.

TYPES : BEGIN OF st_ekko,

ebeln TYPE ekko-ebeln, "Purchasing Document Number

bstyp TYPE ekko-bstyp, "Purchasing Document Category

bsart TYPE ekko-bsart, "Purchasing Document Type

aedat TYPE ekko-aedat, "record created on

ernam TYPE ekko-ernam, "Person who Created the Object

check(1),

END OF st_ekko.

data : it_ekko TYPE STANDARD TABLE OF st_ekko.

wa_ekko LIKE LINE OF it_ekko.

it_newtab TYPE STANDARD TABLE OF st_ekko.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = sy-repid

i_callback_pf_status_set = 'SET_PF_STATUS'

i_callback_user_command = 'AT_USER_COMMAND'

i_callback_top_of_page = 'TOP_OF_PAGE'

is_layout = wa_layout

it_fieldcat = it_fieldcat

TABLES

t_outtab = it_ekko

EXCEPTIONS

program_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.

&----


*& Form POPULATE_LAYOUT

&----


FORM populate_layout.

wa_layout-colwidth_optimize = 'X'. "column width

wa_layout-zebra = 'X'.

  • wa_layout-no_hline = 'X'.

  • wa_layout-no_vline = 'X'.

  • wa_layout-cell_merge = 'X'.

wa_layout-box_fieldname = 'CHECK'.

wa_layout-box_tabname = 'IT_EKKO'.

wa_layout-window_titlebar = 'PURCHASE ORDER HEADER DETAILS'.

ENDFORM.

&----


*& Form AT_user_command

&----


FORM at_user_command USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

CASE r_ucomm.

WHEN 'DISP'.

LOOP AT it_ekko INTO wa_ekko WHERE check = 'X'.

append wa_ekko to it_newtab.

ENDLOOP.

ENDCASE.

ENDFORM.

Here, When he presses display button (DISP), the selected record will be erad and they will be appended to new internal table.

revert back if any problem.

Regards]

Sandeep REddy

5 REPLIES 5
Read only

Former Member
0 Likes
5,207

Hi Ali,

Iam not able to understand your requirement.

After getting the output you need to move in to Itab. ir before displaying the out put you need t move in ti itab.

let me know..

Read only

0 Likes
5,207

I want to move only those records, which the user selects and then move it to an internal table when the user selects a delete button.

Read only

Former Member
5,207

Hi,

You can pass value 'A' to the layout-sel_mode then you can able to select more than one record in the alv by pressing the control button and using the method GET_SELECTED_ROWS like belwo.

CALL METHOD o_alvgrid->get_selected_rows

IMPORTING et_index_rows = lt_rows.

Rgds,

Bujji

Read only

Former Member
0 Likes
5,208

Hi,

You can do this using check box.

giving piece of code....for sake of logic.

Use this logic...for ur requireemnt.

I made the code into bold...where it is required for Check Box.

TYPES : BEGIN OF st_ekko,

ebeln TYPE ekko-ebeln, "Purchasing Document Number

bstyp TYPE ekko-bstyp, "Purchasing Document Category

bsart TYPE ekko-bsart, "Purchasing Document Type

aedat TYPE ekko-aedat, "record created on

ernam TYPE ekko-ernam, "Person who Created the Object

check(1),

END OF st_ekko.

data : it_ekko TYPE STANDARD TABLE OF st_ekko.

wa_ekko LIKE LINE OF it_ekko.

it_newtab TYPE STANDARD TABLE OF st_ekko.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = sy-repid

i_callback_pf_status_set = 'SET_PF_STATUS'

i_callback_user_command = 'AT_USER_COMMAND'

i_callback_top_of_page = 'TOP_OF_PAGE'

is_layout = wa_layout

it_fieldcat = it_fieldcat

TABLES

t_outtab = it_ekko

EXCEPTIONS

program_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.

&----


*& Form POPULATE_LAYOUT

&----


FORM populate_layout.

wa_layout-colwidth_optimize = 'X'. "column width

wa_layout-zebra = 'X'.

  • wa_layout-no_hline = 'X'.

  • wa_layout-no_vline = 'X'.

  • wa_layout-cell_merge = 'X'.

wa_layout-box_fieldname = 'CHECK'.

wa_layout-box_tabname = 'IT_EKKO'.

wa_layout-window_titlebar = 'PURCHASE ORDER HEADER DETAILS'.

ENDFORM.

&----


*& Form AT_user_command

&----


FORM at_user_command USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

CASE r_ucomm.

WHEN 'DISP'.

LOOP AT it_ekko INTO wa_ekko WHERE check = 'X'.

append wa_ekko to it_newtab.

ENDLOOP.

ENDCASE.

ENDFORM.

Here, When he presses display button (DISP), the selected record will be erad and they will be appended to new internal table.

revert back if any problem.

Regards]

Sandeep REddy

Read only

Former Member
0 Likes
5,207

Hi,

Have a look on the following code. It displays the selected rows which hv been selected in basic list.

TABLES:

spfli.

TYPE-POOLS:

slis.

DATA:

BEGIN OF t_spfli OCCURS 0,

checkbox.

INCLUDE STRUCTURE spfli.

DATA: END OF t_spfli.

DATA:

t_sspfli LIKE STANDARD TABLE OF t_spfli .

DATA:

fs_spfli LIKE LINE OF t_sspfli.

DATA:

fs_layout TYPE slis_layout_alv,

w_program TYPE sy-repid.

SELECT *

FROM spfli

INTO CORRESPONDING FIELDS OF TABLE t_spfli.

*fs_layout-info_fieldname = 'COLOR'.

fs_layout-box_fieldname = 'CHECKBOX'.

w_program = sy-repid.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = w_program

i_callback_pf_status_set = 'FLIGHT'

i_callback_user_command = 'SPFLI_INFO'

i_structure_name = 'SPFLI'

is_layout = fs_layout

TABLES

t_outtab = t_spfli

EXCEPTIONS

program_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.

&----


*& Form FLIGHT

&----


  • text

----


  • -->RT_EXTAB text

----


FORM flight USING rt_extab TYPE slis_t_extab..

SET PF-STATUS 'FLIGHT' EXCLUDING rt_extab.

ENDFORM. "FLIGHT

&----


*& Form SPFLI_INFO

&----


  • text

----


  • -->UCOMM text

  • -->SELFIELD text

----


FORM spfli_info USING ucomm LIKE sy-ucomm

selfield TYPE slis_selfield.

selfield-refresh = 'X'.

CASE ucomm.

WHEN 'FLIGHT'.

LOOP AT t_spfli.

IF t_spfli-checkbox = 'X'.

t_spfli-checkbox = ' '.

  • t_spfli-color = 'C51'.

MODIFY t_spfli TRANSPORTING checkbox.

fs_spfli = t_spfli.

APPEND fs_spfli TO t_sspfli.

ENDIF.

ENDLOOP.

WHEN 'EXIT'.

LEAVE PROGRAM.

ENDCASE.

CLEAR fs_spfli.

fs_layout-info_fieldname = 'COLOR'.

  • fs_layout-confirmation_prompt = 'X'.

fs_layout-key_hotspot = 'X'.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = w_program

i_structure_name = 'SFLIGHT'

is_layout = fs_layout

TABLES

t_outtab = t_sspfli

EXCEPTIONS

program_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.

REFRESH t_sspfli.

ENDFORM. "SPFLI_INFO

Regards,

Chandu