ITPub博客

首页 > Linux操作系统 > Linux操作系统 > ALV小结之四:交互式ALV

ALV小结之四:交互式ALV

原创 Linux操作系统 作者:qy1141 时间:2009-06-04 09:47:04 0 删除 编辑

创建交互式列表,捕获User_Command事件即可,代码如下:

TYPE-POOLS: slis.
TABLES : aufk,
         afih.

DATA: BEGIN OF headertab OCCURS 0,
       aufnr LIKE aufk-aufnr,
       auart LIKE aufk-auart,
       autyp LIKE aufk-autyp,
      END OF headertab.

DATA: i_fieldcat TYPE slis_t_fieldcat_alv,
      a_fieldcat TYPE slis_fieldcat_alv.
DATA: v_repid LIKE sy-repid.

START-OF-SELECTION.
  v_repid = sy-repid.
  PERFORM. get_data.
  PERFORM. set_alv_layout.
  PERFORM. dis_alv_grid.

*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. get_data .
  SELECT * FROM aufk INTO CORRESPONDING FIELDS OF  TABLE headertab
  WHERE auart = 'PM01' AND autyp = '30'.
ENDFORM.                    " get_data
*&---------------------------------------------------------------------*
*&      Form  set_alv_layout
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. set_alv_layout .
  a_fieldcat-col_pos = 1.
  a_fieldcat-fieldname = 'AUFNR'.
  a_fieldcat-seltext_m = '订单号'.
  APPEND  a_fieldcat TO i_fieldcat.

  a_fieldcat-col_pos = 2.
  a_fieldcat-fieldname = 'AUART'.
  a_fieldcat-seltext_m = '订单类型'.
  APPEND  a_fieldcat TO i_fieldcat.

  a_fieldcat-col_pos = 3.
  a_fieldcat-fieldname = 'AUTYP'.
  a_fieldcat-seltext_m = '订单类别'.
  APPEND  a_fieldcat TO i_fieldcat.

ENDFORM.                    " set_alv_layout
*&---------------------------------------------------------------------*
*&      Form  dis_alv_grid
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. dis_alv_grid .
  DATA:
    lth_layout TYPE slis_layout_alv.
  lth_layout-detail_popup = 'X'.
  lth_layout-colwidth_optimize = 'X'.
  lth_layout-zebra = 'X'.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
   i_callback_program             = v_repid
   i_callback_user_command        = 'USER_COMMAND'
   is_layout                      = lth_layout
   it_fieldcat                    = i_fieldcat
   i_save                         = 'A'
  TABLES
   t_outtab                       = headertab
* EXCEPTIONS
*   PROGRAM_ERROR                  = 1
*   OTHERS                         = 2
  .
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDFORM.                    " dis_alv_grid
*&---------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM. user_command USING r_ucomm LIKE sy-ucomm
                        rs_selfield TYPE slis_selfield.
  CASE r_ucomm.
    WHEN '&IC1'.
      CASE rs_selfield-fieldname.
        WHEN 'AUFNR'.
          SET PARAMETER ID: 'ANR' FIELD rs_selfield-value.
          CALL TRANSACTION 'IW32' AND SKIP FIRST SCREEN.
      ENDCASE.
  ENDCASE.
ENDFORM.                    "USER_COMMAND

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/11377579/viewspace-605072/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-05-11

  • 博文量
    13
  • 访问量
    40847