08-15-2007 7:02 PM
I am using method set_selected_rows to select line of the table grid and then call the method get_selected_rows to check if the selection was done. It work but when it come back to the screen the line is not selected. I have set SEL_MODE to A and put my selection field in layout structure box_fname.
Regards.
08-17-2007 7:57 AM
Hi,
There are 2 solutions
a) Don't use Refresh table display after checking the Checkbax and doing your activities, if you comeback after this you will have the Checkbox still selected.
b) if you have to use refresh table display then use the method w_grid->set_selected_rows to set the selected rows.
The following code might help.
CALL METHOD w_grid->get_selected_rows
IMPORTING
et_index_rows = tl_row
et_row_no = tl_rid.
LOOP AT tl_row ASSIGNING <l_row>.
READ TABLE t_vbak ASSIGNING <l_vbak> INDEX <l_row>-index.
IF sy-subrc = 0.
SET PARAMETER ID 'AUN' FIELD <l_vbak>-vbeln.
CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
CALL METHOD w_grid->refresh_table_display.
CALL METHOD w_grid->set_selected_rows
EXPORTING
it_index_rows = tl_row
it_row_no = tl_rid.
ENDIF.
ENDLOOP.
08-15-2007 8:07 PM
Hi,
You need to use
CALL METHOD grid1->set_selected_rows
EXPORTING
IT_ROW_NO = lt_rowno[]
a®
08-16-2007 3:11 PM
As i say in my message i already use the method set_selected_rows to select lines of the table and it works because when i check with the method get_selected_rows i got the good results. My problem is that when the system re-display the table in the grid the lines are not selected. (Push bottom pressed)
08-16-2007 3:39 PM
Hello Daniel
Have you tried to call method <b>go_grid->refresh_table_display</b> at <b>PBO</b>, prior to displaying the ALV list and after calling method go_grid->set_selected_rows?
Regards
Uwe
08-16-2007 3:43 PM
08-16-2007 8:29 PM
Hello Daniel
The following sample report <b>ZUS_SDN_ALVGRID_EVENTS_4A</b> displays customers in two ALV lists on two screen (100 and 200). Enter 'NEXT' into the command field to switch 100 -> 200 screen, and enter 'BACK' (or F3) to return (200 -> 100). Method GET_SELECTED_ROWS is called at PAI before moving from 100 -> 200.
All selected rows on both ALV lists will be retained. As you can see there is no need for defining field BOX_FNAME in the layout.
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_ALVGRID_EVENTS_4A
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
* Both screens have the same flow logic and do not contain any elements:
*PROCESS BEFORE OUTPUT.
* MODULE STATUS_0100.
**
*PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0100.
REPORT zus_sdn_alvgrid_events_4a.
TYPE-POOLS: abap.
DATA:
gd_okcode TYPE ui_func,
*
gs_layout TYPE lvc_s_layo,
gt_fcat TYPE lvc_t_fcat,
go_docking1 TYPE REF TO cl_gui_docking_container,
go_docking2 TYPE REF TO cl_gui_docking_container,
go_grid1 TYPE REF TO cl_gui_alv_grid,
go_grid2 TYPE REF TO cl_gui_alv_grid.
DATA:
gt_customer1 TYPE STANDARD TABLE OF knb1,
gt_customer2 TYPE STANDARD TABLE OF knb1.
PARAMETERS:
p_bukrs TYPE bukrs DEFAULT '2000' OBLIGATORY.
*---------------------------------------------------------------------*
* CLASS lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING
e_row_id
e_column_id
es_row_no
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_hotspot_click.
* define local data
DATA:
ls_knb1 TYPE knb1,
ls_col_id TYPE lvc_s_col.
CASE sender.
WHEN go_grid1.
READ TABLE gt_customer1 INTO ls_knb1 INDEX e_row_id-index.
MESSAGE 'Do event handling for 1st ALV grid!' TYPE 'I'.
WHEN go_grid2.
READ TABLE gt_customer2 INTO ls_knb1 INDEX e_row_id-index.
MESSAGE 'Do event handling for 2nd ALV grid!' TYPE 'I'.
WHEN OTHERS.
RETURN.
ENDCASE.
CHECK ( ls_knb1-kunnr IS NOT INITIAL ).
CASE e_column_id-fieldname.
WHEN 'KUNNR'.
SET PARAMETER ID 'KUN' FIELD ls_knb1-kunnr.
SET PARAMETER ID 'BUK' FIELD ls_knb1-bukrs.
CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.
WHEN 'ERNAM'.
* SET PARAMETER ID 'USR' FIELD ls_knb1-ernam.
* NOTE: no parameter id available, yet simply show the priciple
CALL TRANSACTION 'SU01' AND SKIP FIRST SCREEN.
WHEN OTHERS.
* do nothing
ENDCASE.
* Set active cell to field BUKRS otherwise the focus is still on
* field KUNNR which will always raise event HOTSPOT_CLICK
ls_col_id-fieldname = 'BUKRS'.
CALL METHOD go_grid1->set_current_cell_via_id
EXPORTING
is_row_id = e_row_id
is_column_id = ls_col_id.
ENDMETHOD. "handle_hotspot_click
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
SELECT * FROM knb1 INTO TABLE gt_customer1
WHERE bukrs = p_bukrs
AND kunnr <= '0000300000'.
SELECT * FROM knb1 INTO TABLE gt_customer2
WHERE bukrs = p_bukrs
AND kunnr > '0000300000'.
* Create docking container
CREATE OBJECT go_docking1
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 OBJECT go_docking2
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.
go_docking1->set_extension( 99999 ).
go_docking2->set_extension( 99999 ).
* Create ALV grid
CREATE OBJECT go_grid1
EXPORTING
i_parent = go_docking1
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.
CREATE OBJECT go_grid2
EXPORTING
i_parent = go_docking2
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 event handler
SET HANDLER:
lcl_eventhandler=>handle_hotspot_click FOR ALL INSTANCES.
* Build fieldcatalog and set hotspot for field KUNNR
PERFORM build_fieldcatalog_knb1.
* Display data
gs_layout-cwidth_opt = abap_true.
gs_layout-sel_mode = 'A'.
CALL METHOD go_grid1->set_table_for_first_display
EXPORTING
is_layout = gs_layout
CHANGING
it_outtab = gt_customer1
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.
CALL METHOD go_grid2->set_table_for_first_display
EXPORTING
is_layout = gs_layout
CHANGING
it_outtab = gt_customer2
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.
* Link the docking container to the target dynpro
CALL METHOD go_docking1->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.
CALL METHOD go_docking2->link
EXPORTING
repid = syst-repid
dynnr = '0200'
* 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.
TRANSLATE gd_okcode TO UPPER CASE.
CASE gd_okcode.
WHEN 'BACK' OR
'END' OR
'CANC'.
CASE syst-dynnr.
WHEN '0100'.
SET SCREEN 0. LEAVE SCREEN.
WHEN '0200'.
SET SCREEN 100. LEAVE SCREEN.
ENDCASE.
WHEN 'NEXT'.
DATA:
gt_rows TYPE lvc_t_row.
CALL METHOD go_grid1->get_selected_rows
IMPORTING
et_index_rows = gt_rows
* ET_ROW_NO =
.
SET SCREEN 200. LEAVE SCREEN.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG_KNB1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_fieldcatalog_knb1 .
* define local data
DATA:
ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'KNB1'
* 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.
LOOP AT gt_fcat INTO ls_fcat
WHERE ( fieldname = 'KUNNR' OR
fieldname = 'ERNAM' ).
ls_fcat-hotspot = abap_true.
MODIFY gt_fcat FROM ls_fcat.
ENDLOOP.
ENDFORM. " BUILD_FIELDCATALOG_KNB1
Regards
Uwe
08-17-2007 7:57 AM
Hi,
There are 2 solutions
a) Don't use Refresh table display after checking the Checkbax and doing your activities, if you comeback after this you will have the Checkbox still selected.
b) if you have to use refresh table display then use the method w_grid->set_selected_rows to set the selected rows.
The following code might help.
CALL METHOD w_grid->get_selected_rows
IMPORTING
et_index_rows = tl_row
et_row_no = tl_rid.
LOOP AT tl_row ASSIGNING <l_row>.
READ TABLE t_vbak ASSIGNING <l_vbak> INDEX <l_row>-index.
IF sy-subrc = 0.
SET PARAMETER ID 'AUN' FIELD <l_vbak>-vbeln.
CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
CALL METHOD w_grid->refresh_table_display.
CALL METHOD w_grid->set_selected_rows
EXPORTING
it_index_rows = tl_row
it_row_no = tl_rid.
ENDIF.
ENDLOOP.