‎2008 Mar 14 12:51 PM
Hi
I am using method get_selected_rows of cl_gui_alv_grid.
here is the code
DATA: lt_index_rows TYPE lvc_t_row,
lt_row_no TYPE lvc_t_roid.
DATA: l_selected_row TYPE lvc_s_row,
l_tabix TYPE sytabix.
CALL METHOD grid1->get_selected_rows
IMPORTING
et_index_rows = lt_index_rows
et_row_no = lt_row_no.
but it's not working. it's not going inside the method.
lt_index_rows is remaining as initial and there are no entries in lt_row_no .
what could be reason?
Thanks and regards
Badhri
‎2008 Mar 14 6:10 PM
Try to give this way
ALL METHOD grid1->get_selected_rows
IMPORTING
et_index_rows = lt_index_rows[] "<<<
et_row_no = lt_row_no.
a®
‎2008 Mar 14 7:49 PM
Hello Badhri
Do you have a selection mode (LVC_S_LAYO-SEL_MODE) which allows multiple selection on your ALV list? If you you should have a "marking" column on the left border of the ALV grid.
If your list does not allow to select multiple rows then I expect that this method does not make sense in this context and, therefore, returns nothing.
Regards
Uwe
‎2008 Mar 17 3:27 AM
Hi Badri,
Did you pass the selection mode
LVC_S_LAYO-SEL_MODE = 'X'
which allows multiple selection on your ALV list?
If you have not done that, then your list will not allow to select multiple rows. In that case, the get_selected_rows method does not make any sense and therefore returns nothing.
Hope this helps.
Thanks
Balaji
‎2008 Mar 17 4:48 AM
‎2008 Mar 31 5:49 PM
Before createing control, please check control is initial.
IF control is INITIAL.
create_control.
ENDIF.
I feel this will help you.
Regards,
Subramanian.
‎2008 Mar 17 5:11 AM
Hi Badri,
CALL METHOD grid1->get_selected_rows
IMPORTING
et_index_rows = lt_index_rows
et_row_no = lt_row_no.
Make sure that this call is made in the PAI of the ALV screen,
If this is not in the PAI then its not going to be helpful.
Also, its better if it is done before the CASE statemet (if any ....for user commands) .
Regds,
Gaurav
‎2008 Mar 31 10:57 PM
Hello Badri
The following sample report ZUS_SDN_ALV_EDITABLE_1E shows how this method works and the effect of the layout attribute NO_ROWMARK.
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_ALV_EDITABLE_1E
*&
*&---------------------------------------------------------------------*
*& Thread: method get_selected_rows not working
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="782759"></a>
*&---------------------------------------------------------------------*
* Flow logic of screen '100' (no elements, ok-code => gd_okcode ):
**PROCESS BEFORE OUTPUT.
** MODULE STATUS_0100.
***
**PROCESS AFTER INPUT.
** MODULE USER_COMMAND_0100.
*&---------------------------------------------------------------------*
REPORT zus_sdn_alv_editable_1e.
TYPE-POOLS: abap.
CONSTANTS:
gc_tabname TYPE tabname VALUE 'KNB1'.
TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE knb1.
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
DATA:
gd_okcode TYPE ui_func,
*
gt_fcat TYPE lvc_t_fcat,
gs_layout TYPE lvc_s_layo,
gs_variant TYPE disvariant,
go_docking TYPE REF TO cl_gui_docking_container,
go_grid TYPE REF TO cl_gui_alv_grid.
DATA:
gs_outtab TYPE ty_s_outtab,
gt_outtab TYPE ty_t_outtab.
" 'X' = no rowmark, no selection of rows possible
PARAMETER:
p_nomark AS CHECKBOX DEFAULT ' '.
*---------------------------------------------------------------------*
* CLASS lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING
er_data_changed
e_onf4
e_onf4_before
e_onf4_after
e_ucomm
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_data_changed.
* define local data
DATA: ld_answer(1) TYPE c.
" Triggers PAI -> required for list refresh
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'REFRESH'
* IMPORTING
* rc =
.
ENDMETHOD. "handle_data_changed
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
SELECT * FROM (gc_tabname)
INTO CORRESPONDING FIELDS OF TABLE gt_outtab UP TO 99 ROWS.
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
OTHERS = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Create ALV grid
CREATE OBJECT go_grid
EXPORTING
i_parent = go_docking
EXCEPTIONS
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
SET HANDLER:
lcl_eventhandler=>handle_data_changed FOR go_grid.
" Triggers event DATA_CHANGED by pushing ENTER
CALL METHOD go_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter
EXCEPTIONS
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.
* Build fieldcatalog and set hotspot for field KUNNR
PERFORM build_fieldcatalog.
PERFORM set_layout_and_variant.
gs_layout-no_rowmark = p_nomark.
* Display data
CALL METHOD go_grid->set_table_for_first_display
EXPORTING
is_layout = gs_layout
is_variant = gs_variant
i_save = 'A'
CHANGING
it_outtab = gt_outtab
it_fieldcatalog = gt_fcat
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* NOTE:
* Documenation of I_SAVE ("An Easy Reference for ALV Grid Control")
*I_SAVE
*Determines the options available to the user for saving a layout:
*? 'X': global saving only
*? 'U': user-specific saving only
*? 'A': corresponds to 'X' and 'U'
*? SPACE: no saving
* Link the docking container to the target dynpro
CALL METHOD go_docking->link
EXPORTING
repid = syst-repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* ok-code field = GD_OKCODE
CALL SCREEN '0100'.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
go_grid->check_changed_data( ).
CASE gd_okcode.
WHEN 'BACK' OR
'EXIT' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
WHEN 'REFRESH'.
CALL METHOD go_grid->refresh_table_display
* EXPORTING
* is_stable =
* i_soft_refresh =
* EXCEPTIONS
* finished = 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.
WHEN OTHERS.
PERFORM get_selected_rows.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_fieldcatalog .
* define local data
DATA:
ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = gc_tabname
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ls_fcat-edit = abap_true.
MODIFY gt_fcat FROM ls_fcat
TRANSPORTING edit
WHERE ( key NE abap_true ).
ENDFORM. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form SET_LAYOUT_AND_VARIANT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM set_layout_and_variant .
CLEAR: gs_layout,
gs_variant.
gs_layout-cwidth_opt = abap_true.
gs_layout-zebra = abap_true.
*
gs_variant-report = syst-repid.
gs_variant-handle = 'GRID'.
ENDFORM. " SET_LAYOUT_AND_VARIANT
*&---------------------------------------------------------------------*
*& Form GET_SELECTED_ROWS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_selected_rows .
* define local data
DATA: lt_rows TYPE lvc_t_row,
ls_row TYPE lvc_s_row,
ls_outtab TYPE ty_s_outtab,
lt_outtab TYPE ty_t_outtab.
CALL METHOD go_grid->get_selected_rows
IMPORTING
et_index_rows = lt_rows
* et_row_no =
.
LOOP AT lt_rows INTO ls_row.
READ TABLE gt_outtab INTO ls_outtab INDEX ls_row-index.
APPEND ls_outtab TO lt_outtab.
ENDLOOP.
IF ( lt_outtab IS INITIAL ).
MESSAGE 'No rows selected' TYPE 'I'.
ELSE.
CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
EXPORTING
i_title = 'Selected Rows'
* I_SELECTION = 'X'
i_allow_no_selection = 'X'
i_zebra = 'X'
i_tabname = 'KNB1'
i_structure_name = 'KNB1'
TABLES
t_outtab = lt_outtab
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.
ENDIF.
ENDFORM. " GET_SELECTED_ROWS
Regards
Uwe
‎2008 Sep 25 1:18 PM
Hi,
try this code if required.
REPORT ygrid.
INCLUDE <icon>.
CLASS lcl_event_receiver DEFINITION DEFERRED.
DATA: ok_code LIKE sy-ucomm,
gt_vbak TYPE TABLE OF vbak,
gt_vbap TYPE TABLE OF vbap,
g_repid LIKE sy-repid,
g_max TYPE i VALUE 100,
gs_layout TYPE lvc_s_layo,
cont_on_main TYPE scrfname VALUE 'BCALVGRID_CUSTOM1',
cont_on_dialog TYPE scrfname VALUE 'BCALVGRID_CUSTOM2',
grid1 TYPE REF TO cl_gui_alv_grid,
grid2 TYPE REF TO cl_gui_alv_grid,
custom_container1 TYPE REF TO cl_gui_custom_container,
custom_container2 TYPE REF TO cl_gui_custom_container,
event_receiver TYPE REF TO lcl_event_receiver.
SET SCREEN 100.
----
CLASS lcl_event_receiver DEFINITION
----
*
----
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive,
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
PRIVATE SECTION.
ENDCLASS. "lcl_event_receiver DEFINITION
----
CLASS lcl_event_receiver IMPLEMENTATION
----
*
----
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_toolbar.
DATA: ls_toolbar TYPE stb_button.
CLEAR ls_toolbar.
MOVE 3 TO ls_toolbar-butn_type.
APPEND ls_toolbar TO e_object->mt_toolbar.
CLEAR ls_toolbar.
MOVE 'ITEMS' TO ls_toolbar-function.
MOVE icon_employee TO ls_toolbar-icon.
MOVE 'SHOW DETAILS'(111) TO ls_toolbar-quickinfo.
MOVE 'Detail'(112) TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD. "handle_toolbar
METHOD handle_user_command.
DATA: lt_rows TYPE lvc_t_row.
CASE e_ucomm.
WHEN 'ITEMS'.
CALL METHOD grid1->get_selected_rows
IMPORTING
et_index_rows = lt_rows.
CALL METHOD cl_gui_cfw=>flush.
IF sy-subrc NE 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = g_repid
txt2 = sy-subrc
txt1 = 'Error in Flush'.
ELSE.
PERFORM show_items TABLES lt_rows.
ENDIF.
ENDCASE.
ENDMETHOD. "handle_user_command
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
MODULE status_0100 OUTPUT.
SET PF-STATUS 'CUSTOM100'.
SET TITLEBAR 'xxx'.
g_repid = sy-repid.
IF custom_container1 IS INITIAL.
PERFORM select_table_vbak CHANGING gt_vbak.
CREATE OBJECT custom_container1
EXPORTING
container_name = cont_on_main
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6.
IF sy-subrc <> 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = g_repid
txt1 = 'The control could not be created'
txt2 = sy-subrc.
ENDIF.
CREATE OBJECT grid1
EXPORTING
i_parent = custom_container1.
gs_layout-grid_title = 'SALES HEADER'.
gs_layout-sel_mode = 'A'.
CALL METHOD grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'VBAK'
is_layout = gs_layout
CHANGING
it_outtab = gt_vbak.
*CREATE OBJECT event_receiver.
CREATE OBJECT event_receiver.
SET HANDLER event_receiver->handle_user_command FOR grid1.
SET HANDLER event_receiver->handle_toolbar FOR grid1.
CALL METHOD grid1->set_toolbar_interactive
.
ENDIF.
CALL METHOD cl_gui_control=>set_focus
EXPORTING
control = grid1.
module USER_COMMAND_0100 input.
CASE ok_code.
WHEN 'EXIT'.
PERFORM exit_program.
ENDCASE.
CLEAR ok_code.
endmodule.
form exit_program .
CALL METHOD custom_container1->free.
IF not custom_container2 is initial.
CALL METHOD custom_container2->free.
ENDIF.
CALL METHOD cl_gui_cfw=>flush.
IF sy-subrc ne 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = g_repid
txt1 = 'Error in Flush'
txt2 = sy-subrc
.
endif.
LEAVE PROGRAM.
MODULE status_0101 OUTPUT.
SET PF-STATUS 'xxxxxxxx'.
SET TITLEBAR 'xxx'.
IF custom_container2 IS INITIAL.
CREATE OBJECT custom_container2
EXPORTING
container_name = cont_on_dialog
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6.
IF sy-subrc <> 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = g_repid
txt1 = 'The control could not be created'(510)
txt2 = sy-subrc.
ENDIF.
CREATE OBJECT grid2
EXPORTING
i_parent = custom_container2.
gs_layout-grid_title = 'ITEM DETAILS'(101).
gs_layout-sel_mode = ' '.
CALL METHOD grid2->set_table_for_first_display
EXPORTING
i_structure_name = 'VBAP'
is_layout = gs_layout
CHANGING
it_outtab = gt_vbap.
ELSE.
CALL METHOD grid2->refresh_table_display.
ENDIF.
CALL METHOD cl_gui_control=>set_focus
EXPORTING
control = grid2.
CALL METHOD cl_gui_cfw=>flush.
IF sy-subrc NE 0.
add your handling, for example
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = g_repid
txt2 = sy-subrc
txt1 = 'Error in Flush'(500).
ENDIF.
ENDMODULE. " STATUS_0101 OUTPUT
module USER_COMMAND_0101 input.
CASE ok_code.
WHEN 'RETURN'.
LEAVE TO SCREEN 0.
ENDCASE.
CLEAR ok_code.
endmodule. " USER_COMMAND_0101 INPUT
FORM select_table_vbak CHANGING p_gt_vbak LIKE gt_vbak[].
SELECT * FROM vbak INTO TABLE p_gt_vbak UP TO g_max ROWS.
ENDFORM. " select_table_VBAK
FORM show_items TABLES p_et_rows STRUCTURE lvc_s_row.
DATA: ls_selected_line LIKE lvc_s_row,
lf_row_index TYPE lvc_index,
ls_vbak LIKE LINE OF gt_vbak.
CLEAR gt_vbap[].
LOOP AT p_et_rows INTO ls_selected_line.
lf_row_index = ls_selected_line-index.
READ TABLE gt_vbak INDEX lf_row_index INTO ls_vbak.
PERFORM select_table_vbap USING ls_vbak
CHANGING gt_vbap.
ENDLOOP.
call dialog screen and display new alv control
CALL SCREEN 101 STARTING AT 10 5.
ENDFORM. " show_ITEMS
‎2008 Sep 26 9:39 AM
Hi Badhri,
yesterday I had the same problem. Looking into this forum didn't helped me.
But today I figured out a simple but logical probelm.
How do you create your objects for alv grid?
Olaf
...Sometimes you don't see abap, because of to much abap in front of you...
‎2008 Sep 26 9:48 AM
Hi Badhri,
yesterday I had the same problem. Looking into this forum didn't helped me.
But today I figured it out with an example report from sap (BCALV_EDIT_05) . It is a simple but logical problem.
How do you create your objects for alv grid? You can see the correct object generation in the coding of Mani Nandiwada who first checks if a container is initial and creates the object only if this is the case (look for: IF custom_container2 IS INITIAL.)
Olaf
Edited by: Olaf Bahrenburg on Sep 26, 2008 10:49 AM
‎2012 Sep 29 1:08 AM
Hi Badri,
If get_selected_rows remains empty after the second selection than the problem can be the missing call of CL_GUI_ALV_GRID>->refresh_table_display in your PBO.
In this case in your PBO you have explicit call refresh_table_display it is not enough to call once set_table_for_first_display...I guess that's why you don't get the selected rows or cells.
Best Regards:
Szilard