Sunday, October 7, 2018

REUSE_ALV_GRID_DISPLAY_LVC and function exit

*&---------------------------------------------------------------------*
*& Report  ZLISTALV1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZLISTALV1.
    TYPE-POOLSslis.

    DATABEGIN OF itab OCCURS 0,
          a TYPE DECIMALS 2,
          b TYPE DECIMALS 2,
          TYPE c,
          END   OF itab.

    DATAls_fieldcat   TYPE lvc_t_fcat        WITH HEADER LINE,
          it_event_exit TYPE slis_t_event_exit WITH HEADER LINE.



    PERFORM build_data_tab.
    PERFORM build_fcat.
    PERFORM build_event_table.
    PERFORM alv_display.

**    *&---------------------------------------------------------------------*
**    *&      Form  build_data_tab
**    *&---------------------------------------------------------------------*
    FORM build_data_tab .
      itab-'1.12'.
      itab-'2.25'.
      itab-'+'.

      APPEND itab.
      APPEND itab.
      APPEND itab.
      APPEND itab.
    ENDFORM.                    " build_data_tab
*    *&---------------------------------------------------------------------*
*    *&      Form  build_fcat
*    *&---------------------------------------------------------------------*
    FORM build_fcat .
      ls_fieldcat-fieldname 'A'.
      ls_fieldcat-reptext 'FLD1'.
      APPEND ls_fieldcat.

      ls_fieldcat-fieldname 'B'.
      ls_fieldcat-reptext 'FLD2'.
      APPEND ls_fieldcat.

      ls_fieldcat-fieldname 'C'.
      ls_fieldcat-reptext 'FLD3'.
      APPEND ls_fieldcat.
    ENDFORM.                    " build_fcat
*    *&---------------------------------------------------------------------*
*    *&      Form  build_event_table
*    *&---------------------------------------------------------------------*
    FORM build_event_table .
      it_event_exit-ucomm  '&F03'.
      APPEND it_event_exit.
      it_event_exit-ucomm  '&F15'.
      APPEND it_event_exit.
      it_event_exit-ucomm  '&F12'.
      APPEND it_event_exit.
    ENDFORM.                    " build_event_table
*    *&---------------------------------------------------------------------*
*    *&      Form  alv_display
*    *&---------------------------------------------------------------------*
    FORM alv_display .
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
        EXPORTING
          i_callback_program      sy-repid
          i_callback_user_command 'USER_COMMAND'
          it_fieldcat_lvc         ls_fieldcat[]
          it_event_exit           it_event_exit[]
        TABLES
          t_outtab                itab[].
    ENDFORM.                    " alv_display
*    *&---------------------------------------------------------------------*
*    *&      Form  user_command
*    *&---------------------------------------------------------------------*
    FORM user_command  USING r_ucomm LIKE sy-ucomm
                             rs_selfield TYPE slis_selfield.
      CASE r_ucomm .
        WHEN '&F03'.
          MESSAGE 'U are going back' TYPE 'I'.
        WHEN '&F15'.
          MESSAGE 'U are about to exit' TYPE 'I'.
        WHEN '&F12'.
          MESSAGE 'U have clicked cancel button' TYPE 'I'.
      ENDCASE.
    ENDFORM.                    "user_command