************************************************************************
*   INTERNAL TABLES
************************************************************************

DATA: lt_mapping  TYPE STANDARD TABLE OF zBarry_emp,
      lt_fieldcat TYPE lvc_t_fcat.

************************************************************************
*   WORK AREAS
************************************************************************
DATA: ls_fieldcat TYPE lvc_s_fcat,
      ls_mapping  TYPE zBarry_emp,
      lw_layout   TYPE lvc_s_layo.

************************************************************************
*   REFERENCE OBJECT
************************************************************************
DATA:  r_container TYPE REF TO cl_gui_custom_container,
       r_grid      TYPE REF TO cl_gui_alv_grid.


************************************************************************
*   Field symbol
************************************************************************

FIELD-SYMBOLS: <ls_fieldcat>   TYPE lvc_s_fcat.

************************************************************************
*   START-OF-SELECTION.
************************************************************************
START-OF-SELECTION.
  SELECT *
    FROM zBarry_emp
    INTO TABLE lt_mapping
    UP TO 20 ROWS.

* Call screen 200
  CALL SCREEN 200.

MODULE status_0200 OUTPUT.
  SET PF-STATUS 'PF-STATUS'.
  SET TITLEBAR 'TITLE'.

  CREATE OBJECT r_container
    EXPORTING
      container_name = 'CUSTOM_1'.

  CREATE OBJECT r_grid
    EXPORTING
      i_parent = r_container.


* create Field Catalog
  ls_fieldcat-fieldname = 'EMP_FNAME'.
  ls_fieldcat-tabname   = 'zBarry_emp'.
  ls_fieldcat-seltext   = 'Employee Name'.
  ls_fieldcat-edit      = 'X'.
  APPEND ls_fieldcat TO lt_fieldcat.
  CLEAR ls_fieldcat.

  ls_fieldcat-fieldname = 'EMP_LNAME'.
  ls_fieldcat-tabname   = 'zBarry_emp'.
  ls_fieldcat-seltext   = 'Employee Last Name'.
  ls_fieldcat-edit      = 'X'.
*ls_fieldcat-hotspot   = 'X'.
  APPEND ls_fieldcat TO lt_fieldcat.
  CLEAR ls_fieldcat.

  CALL METHOD r_grid->set_table_for_first_display
    EXPORTING
*     I_BUFFER_ACTIVE               =
*     I_BYPASSING_BUFFER            =
*     I_CONSISTENCY_CHECK           =
      i_structure_name              = 'zBarry_emp'
*     IS_VARIANT                    =
      i_save                        = 'A'
      i_default                     = abap_true
      is_layout                     = lw_layout
*     IS_PRINT                      =
*     IT_SPECIAL_GROUPS             =
*     IT_TOOLBAR_EXCLUDING          =
*     IT_HYPERLINK                  =
*     IT_ALV_GRAPHICS               =
*     IT_EXCEPT_QINFO               =
*     IR_SALV_ADAPTER               =
    CHANGING
      it_outtab                     = lt_mapping
      it_fieldcatalog               = lt_fieldcat
*     IT_SORT                       =
*     IT_FILTER                     =
    EXCEPTIONS
      invalid_parameter_combination = 1
      program_error                 = 2
      too_many_lines                = 3
      OTHERS                        = 4.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.




ENDMODULE.

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0200  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0200 INPUT.

  CASE sy-ucomm.
    WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
      LEAVE PROGRAM.
      LEAVE TO SCREEN 0.
    WHEN 'SAVE'.
      DATA: lt_t_row TYPE lvc_t_row,
            ls_t_row LIKE LINE OF lt_t_row
            .
      FIELD-SYMBOLS: <fs_changed_data> LIKE LINE OF lt_mapping.
      CALL METHOD r_grid->check_changed_data.
      CALL METHOD r_grid->get_selected_rows
        IMPORTING
          et_index_rows = lt_t_row.   " Indexes of Selected Rows

      LOOP AT lt_t_row INTO ls_t_row.

        READ TABLE lt_mapping ASSIGNING <fs_changed_data> INDEX ls_t_row-index.
        IF sy-subrc = 0.
          MODIFY zBarry_emp FROM  <fs_changed_data>.
        ENDIF.
      ENDLOOP.
  ENDCASE.
ENDMODULE.

 

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Translate »