메뉴 건너뛰기

SAP 한국 커뮤니티



REPORT z_alv_table_event_form

노름마치 2007.11.05 21:55 조회 수 : 3289

REPORT z_alv_table_event_form.
*---------------------------------------------------------------------*
* This report displays Forms routines called from extended table      *
* (or view) maintenance - Double click on a line to display the form  *
*---------------------------------------------------------------------*
* Author : Michel PIOUD                                               *
* Email : mpioud@yahoo.fr  HomePage : http://www.geocities.com/mpioud *
*---------------------------------------------------------------------*
* Macro definition
DEFINE m_line.
  selection-screen :
    begin of line, comment 10(20) v_&1 for field &2.
  select-options &2 for &3.
  selection-screen end of line.
END-OF-DEFINITION.


TYPE-POOLS slis.           " ALV Global types


CONSTANTS :
  c_x VALUE 'X'.


TABLES tvimf.              " User routines called from view maintenance


SELECTION-SCREEN BEGIN OF BLOCK b0 WITH FRAME.
m_line 1 s_table tvimf-tabname.                             "#EC NEEDED
m_line 2 s_event tvimf-event.                               "#EC NEEDED
m_line 3 s_form  tvimf-formname.                            "#EC NEEDED
SELECTION-SCREEN END OF BLOCK b0.
SELECTION-SCREEN SKIP.


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
SELECTION-SCREEN :
BEGIN OF LINE, COMMENT 1(35) v_4 FOR FIELD p_max.           "#EC NEEDED
PARAMETERS p_max(3) TYPE n DEFAULT '200' OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b1.


DATA :
  t_bdcdata TYPE STANDARD TABLE OF bdcdata WITH HEADER LINE,
* Data to display
  t_data    TYPE STANDARD TABLE OF tvimf.


FIELD-SYMBOLS <data> TYPE tvimf.


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


  v_1 = 'Table or view'.
  v_2 = 'Event'.
  v_3 = 'Form name'.
  v_4 = 'Maximum number of selected entries'.


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


  PERFORM f_read_data.


  PERFORM f_display_data.


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


* Read_data
  SELECT * UP TO p_max ROWS
         INTO TABLE t_data
         FROM tvimf AS t
        WHERE tabname  IN s_table
          AND exists ( SELECT * FROM dd02l WHERE tabname = t~tabname )
          AND event    IN s_event
          AND formname IN s_form
        ORDER BY PRIMARY KEY.


  DESCRIBE TABLE t_data.


  SET TITLEBAR 'TITLE' WITH sy-tfill.


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


* Macro definition
  DEFINE m_sort.
    add 1 to ls_sort-spos.
    ls_sort-fieldname = &1.
    ls_sort-up = &2.
    append ls_sort to lt_sort.
  END-OF-DEFINITION.


  DATA:
    lt_sort   TYPE slis_t_sortinfo_alv,
    ls_sort   TYPE slis_sortinfo_alv,
    ls_layout TYPE slis_layout_alv.


  ls_layout-colwidth_optimize = c_x.
  ls_layout-zebra             = c_x.
  ls_layout-cell_merge        = c_x.


  m_sort 'TABNAME' c_x.
  m_sort 'EVENT'   c_x.


  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            i_callback_program      = sy-cprog
            i_callback_user_command = 'USER_COMMAND'
            is_layout               = ls_layout
            i_structure_name        = 'TVIMF'
            it_sort                 = lt_sort
            i_save                  = 'A'
       TABLES
            t_outtab                = t_data.


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 '&IC1'.                       " Pick
      READ TABLE t_data INDEX us_selfield-tabindex ASSIGNING <data>.
      CHECK sy-subrc EQ 0.
      PERFORM display_form.
  ENDCASE.


ENDFORM.                               " USER_COMMAND
*---------------------------------------------------------------------*
*       FORM DISPLAY_FORM                                             *
*---------------------------------------------------------------------*
FORM display_form.


  REFRESH t_bdcdata.


* Generate table view initial screen table/view
  PERFORM bdc_dynpro USING 'SAPMSVIM' '0050' '=SHOW'.
  PERFORM bdc_field  USING 'VIMDYNFLDS-ELEM_GEN' c_x.
  PERFORM bdc_field  USING 'VIMDYNFLDS-VIEWNAME' <data>-tabname.


* Events
  PERFORM bdc_dynpro USING 'SAPMSVIM' '0120' '=ADDR'.


* Find
  PERFORM bdc_dynpro USING 'SAPL0SVM' '0010' '=POSI'.


* Validate
  PERFORM bdc_dynpro USING 'SAPLSPO4' '0300' '=FURT'.
  PERFORM bdc_field  USING 'SVALD-VALUE(01)' <data>-event.


* Display form
  PERFORM bdc_dynpro USING 'SAPL0SVM' '0010' '=0001'.


  CALL TRANSACTION 'SE54' USING t_bdcdata
                           MODE 'E'.


ENDFORM.                               " DISPLAY_FORM
*--------------------------------------------------------------------*
*       FORM bdc_dynpro                                              *
*--------------------------------------------------------------------*
FORM bdc_dynpro USING u_program TYPE bdc_prog
                      u_dynpro  TYPE bdc_dynr
                      u_okcode  TYPE bdc_fval.


  CLEAR t_bdcdata.
  t_bdcdata-program  = u_program.
  t_bdcdata-dynpro   = u_dynpro.
  t_bdcdata-dynbegin = 'X'.
  APPEND t_bdcdata.


  PERFORM bdc_field USING 'BDC_OKCODE' u_okcode.


ENDFORM.
*---------------------------------------------------------------------*
*        FORM bdc_field                                               *
*---------------------------------------------------------------------*
FORM bdc_field USING u_fnam TYPE fnam_____4
                     u_fval.


  CLEAR t_bdcdata.
  t_bdcdata-fnam = u_fnam.
  t_bdcdata-fval = u_fval.
  APPEND t_bdcdata.


ENDFORM.
************** END OF PROGRAM Z_ALV_TABLE_EVENT_FORM ******************