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: 

Factory Method to display data in ALV

Former Member
0 Kudos

HI All,

I am using the factory method of ALV. I have a requirement wherein i have an internal table which is being displayed in the output using factory method. The user can select the rows of that internal table on the screen and when the user says process on the screen I need to get all the rows which the user has selected and later process those selected rows.Now my question how will i know which rows of the internal table have been selected.

Please provide me with the code if anyone has done it.

Thanks

2 REPLIES 2

Former Member
0 Kudos

Hi ,

If you are using OOPS ALV .

then use the method below to get selected rows from the AlV grid .

CALL METHOD list_viewer->get_selected_rows

IMPORTING et_index_rows = lt_rows.

If you are Function Module ALV then use Usercommand form use will get a structure rs_selfield will will have data.

Please reward if useful .

Also use BCALVGRID

Former Member
0 Kudos

Hi Anu,

this might help:

REPORT ybc_test05.

  • Example: ALV-List of T000 with the possibility to select various

  • lines and to precess them.

  • Additional to this source a GUI-Status has to be created

  • ( copy from SALV_TABLE_STANDARD in FM SALV_METADATA_STATUS )

  • and there an individual function must be defined.

DATA it_outtab TYPE TABLE OF t000.

DATA gr_table TYPE REF TO cl_salv_table.

CLASS lcl_handle_events DEFINITION DEFERRED.

DATA: gr_handle_events TYPE REF TO lcl_handle_events.

CLASS lcl_handle_events DEFINITION.

PUBLIC SECTION.

METHODS:

on_user_command

FOR EVENT added_function

OF cl_salv_events

IMPORTING e_salv_function.

ENDCLASS. "lcl_handle_events DEFINITION

CLASS lcl_handle_events IMPLEMENTATION.

METHOD on_user_command.

PERFORM user_command_objects USING e_salv_function.

ENDMETHOD. "on_user_command

ENDCLASS. "lcl_handle_events IMPLEMENTATION

START-OF-SELECTION.

SELECT * FROM t000

INTO TABLE it_outtab.

cl_salv_table=>factory(

IMPORTING r_salv_table = gr_table

CHANGING t_table = it_outtab ).

*.................. Allow to mark more than one line ................. *

DATA: lr_sel TYPE REF TO cl_salv_selections.

lr_sel = gr_table->get_selections( ).

lr_sel->set_selection_mode( if_salv_c_selection_mode=>multiple ).

*.................. Set_screen_status ................................ *

DATA: x_repid TYPE syrepid.

x_repid = sy-repid.

gr_table->set_screen_status(

pfstatus = 'SALV_TABLE_TEST05' "GUI-Status

report = x_repid ).

*... Enable Generic ALV functions

DATA: gr_functions TYPE REF TO cl_salv_functions_list.

gr_functions = gr_table->get_functions( ).

gr_functions->set_all( ).

*.................. Handle Event ..................................... *

DATA: lr_events TYPE REF TO cl_salv_events_table.

lr_events = gr_table->get_event( ).

CREATE OBJECT gr_handle_events.

SET HANDLER gr_handle_events->on_user_command FOR lr_events.

*.................. Display ALV ...................................... *

gr_table->display( ).

FORM user_command_objects USING u_comm TYPE salv_de_function.

DATA:

lv_row TYPE i .

CASE u_comm.

WHEN 'DO'. "individual function in GUI-Status

PERFORM get_selected_row USING gr_table

CHANGING lv_row.

ENDCASE.

ENDFORM. "user_command_objects

FORM get_selected_row USING ir_table TYPE REF TO cl_salv_table

CHANGING e_row TYPE i.

*.. get selected line.

DATA: lr_selection TYPE REF TO cl_salv_selections,

lt_selected_row TYPE salv_t_row,

ls_selected_row LIKE LINE OF lt_selected_row,

l_cell TYPE salv_s_cell.

ir_table->get_metadata( ).

lr_selection = ir_table->get_selections( ).

lt_selected_row = lr_selection->get_selected_rows( ).

DATA: wa_outtab TYPE t000.

LOOP AT lt_selected_row INTO ls_selected_row.

READ TABLE it_outtab INDEX ls_selected_row INTO wa_outtab.

CALL FUNCTION 'POPUP_TO_CONFIRM'

EXPORTING

text_question = wa_outtab-mtext.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDLOOP.

ENDFORM. "get_selected_row