메뉴 건너뛰기

SAP 한국 커뮤니티



REPORT z_demo_alv_event_exit_3

노름마치 2007.11.05 21:57 조회 수 : 2727

REPORT z_demo_alv_event_exit_3.
*>*********************************************************************
* This report reads and displays data from table TRDIR,               *
* using the FM : REUSE_ALV_GRID_DISPLAY                               *
* The field Counter is filled with the Sort Order                     *
*---------------------------------------------------------------------*
* Author : Michel PIOUD                                               *
* Email : mpioud@yahoo.fr  HomePage : http://www.geocities.com/mpioud *
***********************************************************************


SELECTION-SCREEN :
BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.            "#EC NEEDED
PARAMETERS p_max(3) TYPE n DEFAULT '99' OBLIGATORY.
SELECTION-SCREEN END OF LINE.


TYPE-POOLS slis.                       " ALV Global Types


*---------------------------------------------------------------------*
TYPES:
  BEGIN OF ty_trdir,
    name  TYPE trdir-name,             " ABAP program name
    cnam  TYPE trdir-cnam,             " Created by
    cdat  TYPE trdir-cdat,             " Created on
    unam  TYPE trdir-unam,             " Last changed by
    udat  TYPE trdir-udat,             " Last changed on
    accnt TYPE trdir-ldbname,
  END OF ty_trdir.


*---------------------------------------------------------------------*
DATA:
  gt_trdir TYPE TABLE OF ty_trdir.       " Data displayed


*---------------------------------------------------------------------*
INITIALIZATION.


  v_1 = 'Maximum of records to read'.


*---------------------------------------------------------------------*
START-OF-SELECTION.


  PERFORM f_read_data.


  PERFORM f_display_data.


*---------------------------------------------------------------------*
*       Form  f_read_data
*---------------------------------------------------------------------*
FORM f_read_data.


  SELECT name cnam cdat unam udat
    INTO TABLE gt_trdir
      UP TO p_max ROWS
    FROM trdir
   WHERE name LIKE 'Z%'.


  PERFORM f_update_counter.


ENDFORM.                               " F_READ_DATA
*---------------------------------------------------------------------*
*      Form  f_display_data
*---------------------------------------------------------------------*
FORM f_display_data.


* Macro definition
  DEFINE m_fieldcat.
    add 1 to ls_fieldcat-col_pos.
    ls_fieldcat-fieldname = &1.
    ls_fieldcat-ref_tabname = &2.
    append ls_fieldcat to lt_fieldcat.
  END-OF-DEFINITION.


  DEFINE m_event_exit.
    clear ls_event_exit.
    ls_event_exit-ucomm = &1.
    ls_event_exit-after = 'X'.
    append ls_event_exit to lt_event_exit.
  END-OF-DEFINITION.


  DATA :
    ls_layout     TYPE slis_layout_alv,
    ls_fieldcat   TYPE slis_fieldcat_alv,
    lt_fieldcat   TYPE slis_t_fieldcat_alv,
    ls_event_exit TYPE slis_event_exit,
    lt_event_exit TYPE slis_t_event_exit.


* Build Field Catalog
  m_fieldcat 'ACCNT' 'SOID'.
  m_fieldcat 'NAME'  'TRDIR'.
  m_fieldcat 'CNAM'  'TRDIR'.
  m_fieldcat 'CDAT'  'TRDIR'.
  m_fieldcat 'UNAM'  'TRDIR'.
  m_fieldcat 'UDAT'  'TRDIR'.


* Build Event Exit Table
  m_event_exit '&OUP'.                 " Sort up
  m_event_exit '&ODN'.                 " Sort Down


  ls_layout-zebra = 'X'.


  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            i_callback_program      = sy-cprog
            i_callback_user_command = 'USER_COMMAND'
            is_layout               = ls_layout
            it_fieldcat             = lt_fieldcat
            it_event_exit           = lt_event_exit
       TABLES
            t_outtab                = gt_trdir.


ENDFORM.                               " F_DISPLAY_DATA
*---------------------------------------------------------------------*
*       FORM USER_COMMAND                                             *
*---------------------------------------------------------------------*
FORM user_command USING u_ucomm     TYPE syucomm
                        us_selfield TYPE slis_selfield.     "#EC CALLED


  CASE u_ucomm.
    WHEN '&OUP' OR '&ODN'.             " Sort
      PERFORM f_update_counter.
  ENDCASE.


ENDFORM.                               " USER_COMMAND
*---------------------------------------------------------------------*
*       Form  F_UPDATE_COUNTER
*---------------------------------------------------------------------*
FORM f_update_counter.


  FIELD-SYMBOLS :
    <trdir>  TYPE ty_trdir.


  LOOP AT gt_trdir ASSIGNING <trdir>.
    <trdir>-accnt = sy-tabix.
  ENDLOOP.


ENDFORM.                               " F_UPDATE_COUNTER
******** END OF PROGRAM Z_DEMO_ALV_EVENT_EXIT_3 ***********************