Tuesday, June 4, 2019

SALV get selected rows

Sometimes the backend doesn't return the selected rows of an SALV. For my case get_metadata( ) was the solution:
  go_salv->get_metadata( ).
  lt_row = go_salv->get_selections( )->get_selected_rows( ).

The complete Dynpro Logic:
  go_cc            TYPE REF TO cl_gui_custom_container,
  go_salv          TYPE REF TO cl_salv_table.


FORM dialog_select_peg CHANGING ct_pegging.
...
  CALL SCREEN 0200 STARTING AT 40 8.
...
ENDFORM.


FORM dynp_0200_pbo_alv.
  CHECK go_cc IS NOT BOUND. " run only once per dynpro live-cycle
  go_cc = NEW cl_gui_custom_container( 'CC' ).
  TRY.
      cl_salv_table=>factory(
         EXPORTING r_container = go_cc
         IMPORTING r_salv_table = go_salv
         CHANGING t_table = gt_dynp_0200_peg
      ).
      " setup alv
      go_salv->get_columns( )->set_optimize( abap_true ).
      go_salv->get_selections( )->set_selection_mode( if_salv_c_selection_mode=>cell ). " if_salv_c_selection_mode=>multiple
      go_salv->get_functions( )->set_all( ). " activate toolbar
      " display alv
      go_salv->display( ).
    CATCH       cx_salv_msg
      cx_salv_not_found
      cx_salv_data_error
      cx_salv_existing
      cx_salv_wrong_call INTO DATA(lo_x).
      MESSAGE lo_x TYPE 'E'.
  ENDTRY.
ENDFORM.


FORM dynp_0200_handle_selection.
  DATA:
    lt_row     TYPE salv_t_row.

  " get indexes of selected rows
  go_salv->get_metadata( ).
  lt_row = go_salv->get_selections( )->get_selected_rows( ).
...
ENDFORM.


FORM dynp_0200_exit.
  IF go_cc IS BOUND.
    go_cc->free( ).
    FREE go_cc.
  ENDIF.
ENDFORM.

MODULE status_0200 OUTPUT.
  SET PF-STATUS '0100'.
  SET TITLEBAR '0200'.

  PERFORM dynp_0200_pbo_alv.
ENDMODULE.


MODULE user_command_0200 INPUT.
  CASE sy-ucomm.
    WHEN 'OK'.
      PERFORM dynp_0200_handle_selection.
      PERFORM dynp_0200_exit.
      LEAVE TO SCREEN 0.

    WHEN 'CANCEL'.
      CLEAR gt_dynp_0200_peg.
      PERFORM dynp_0200_exit.
      LEAVE TO SCREEN 0.
  ENDCASE.
ENDMODULE.

SAP ABAP: Determine Timezone for Plant

    DATA:       lt_tzone TYPE STANDARD TABLE OF tznzone WITH DEFAULT KEY,       l_tzone  TYPE tznzone.     " get time zone for plant   ...