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: 

GET_SELECTED_ROWS not working second time

Hello,

I have seen many questions regarding the same but no solution work for me.

PROBLEM: GET_SELECTED_ROWS returns the selected index the first time when a button is triggered but does not return any value the second time even after refreshing the internal table and grid.

Even setting the SEL_MODE does not work for me.

CALL SCREEN 9000.
MODULE STATUS_9000 OUTPUT.
 SET PF-STATUS 'STATUS'.
 IF MATRL_R = 'X'.
 SET TITLEBAR 'TITLE'.
 ELSE.
 SET TITLEBAR 'TITLE1'.
 ENDIF.
 CREATE OBJECT CONTAINER
 EXPORTING
 CONTAINER_NAME = 'CCONTAINER'.
 CREATE OBJECT SPLITTER
 EXPORTING
 PARENT = CONTAINER
 ROWS = 2
 COLUMNS = 1.
 CALL METHOD SPLITTER->GET_CONTAINER
 EXPORTING
 ROW = 1
 COLUMN = 1
 RECEIVING
 CONTAINER = CONTAINER_1.
 CALL METHOD SPLITTER->GET_CONTAINER
 EXPORTING
 ROW = 2
 COLUMN = 1
 RECEIVING
 CONTAINER = CONTAINER_2.
 CREATE OBJECT GRID1
 EXPORTING
 I_PARENT = CONTAINER_1.
 CREATE OBJECT GRID2
 EXPORTING
 I_PARENT = CONTAINER_2.
 IF MATRL_R = 'X'.
 PERFORM M_OO.
 ELSE.
 PERFORM S_OO.
 ENDIF.
ENDMODULE. 

MODULE USER_COMMAND_9000 INPUT.
 CASE SY-UCOMM.
 WHEN 'BACK'.
 LEAVE TO SCREEN 0.
 WHEN 'CANCEL'.
 LEAVE PROGRAM.
 WHEN 'EXIT'.
 LEAVE TO SCREEN 0.
 WHEN 'DISPLAY' .
 IF MATRL_R = 'X'.
 PERFORM LINE_MATERIAL.
 CALL METHOD GRID2->REFRESH_TABLE_DISPLAY
 EXPORTING
 I_SOFT_REFRESH = 'X'.
 ELSE.
 PERFORM LINE_SALES.
 CALL METHOD GRID1->REFRESH_TABLE_DISPLAY
 EXPORTING
 I_SOFT_REFRESH = 'X'.
 ENDIF.
 CLEAR SY-UCOMM.
 ENDCASE.
ENDMODULE.
FORM M_OO.
 GS_LAYOUT-GRID_TITLE = 'Material Report'.
* gs_layout-SEL_MODE = 'A'.
 CALL METHOD GRID1->SET_TABLE_FOR_FIRST_DISPLAY
 EXPORTING
 IS_LAYOUT = GS_LAYOUT
 CHANGING
 IT_OUTTAB = IT_FINAL
 IT_FIELDCATALOG = IT_FCAT.
ENDFORM.
FORM S_OO.
 GS_LAYOUT-GRID_TITLE = 'Sales Report'.
* gs_layout-SEL_MODE = 'A'.
 CALL METHOD GRID1->SET_TABLE_FOR_FIRST_DISPLAY
 EXPORTING
 IS_LAYOUT = GS_LAYOUT
 CHANGING
 IT_FIELDCATALOG = IT_FCAT1
 IT_OUTTAB = IT_VBAK.
ENDFORM.
CALL METHOD GRID1->GET_SELECTED_ROWS
 IMPORTING
 ET_INDEX_ROWS = ROWS.
 LOOP AT ROWS INTO WA_ROWS.
 READ TABLE IT_MARA INTO WA_MARA INDEX WA_ROWS-INDEX.
 WA_FINAL-MATNR = WA_MARA-MATNR.
 WA_FINAL-ERSDA = WA_MARA-ERSDA.
 WA_FINAL-ERNAM = WA_MARA-ERNAM.
 WA_FINAL-LAEDA = WA_MARA-LAEDA.
 WA_FINAL-MTART = WA_MARA-MTART.
 WA_FINAL-MATKL = WA_MARA-MATKL.
 WA_FINAL-MEINS = WA_MARA-MEINS.
 READ TABLE IT_MARD INTO WA_MARD WITH KEY MATNR = WA_FINAL-MATNR.
 WA_FINAL-LGORT = WA_MARD-LGORT.
 WA_FINAL-WERKS = WA_MARD-WERKS.
 APPEND WA_FINAL TO IT_FINAL.
ENDLOOP.

For Full Code

Please Refer full-code.txt

THANK YOU

1 ACCEPTED SOLUTION

raymond_giuseppi
Active Contributor

First correct your code, you don't need to create again and again the same objects reference (container and grid) only create when initial/inactive.

Also

  • Check exception/return code after method call
  • Use call method cl_gui_cfw=>flush if you don't want to depend on PAI/PBO cycle and implicit call.
10 REPLIES 10

raymond_giuseppi
Active Contributor

First correct your code, you don't need to create again and again the same objects reference (container and grid) only create when initial/inactive.

Also

  • Check exception/return code after method call
  • Use call method cl_gui_cfw=>flush if you don't want to depend on PAI/PBO cycle and implicit call.

0 Kudos

-> you don't need to create again and again the same objects reference (container and grid) only create when initial/inactive.

Thank You, it worked.

IF GRID1 IS INITIAL AND GRID2 IS INITIAL.

hohoman
Active Participant
0 Kudos

If you're using the CL_SALV_TABLE Class with custom Container you have to call the method

GET_METADATA before you can access the selected rows a.s.o.

0 Kudos

Thank you for answering sir, but I'm not using CL_SALV_TABLE.

Sandra_Rossi
Active Contributor

Your code contains errors where you used GRID1 for GRID2 and vice versa.

Note that ET_INDEX_ROWS is deprecated, you should use ET_ROW_NO as per documentation (but it still works).

+ do what Raymond suggests.

0 Kudos

Got it, Thank You.

former_member617564
Participant

code.txt

Hi

Kindly find the corrected Code

Regards,

Chitme

0 Kudos

Thank you for answering chandchitme.

As I can see you have added:

  • CALL METHOD cl_gui_cfw=>flush.
  • gs_layout-SEL_MODE = 'D'.
  • AND an Internal table IT_FINAL2.

But it does not work the second time 😞

former_member617564
Participant

For me the code working fine and i am getting the values every time for the selected number of rows

Regards,

Chitme

0 Kudos

chandchitme

I'm really sorry, I forgot to uncomment a line. 😛

It works. Thank you so much.