实例:ABAP Tree Control 使用与ALV Grid对象关联


Tree Control 是最常用的Windows控件之一,在其他语言中成为"Tree View"等,ABAP的 Tree Contiol 能实现类似的功能。

本文主要介绍一下内容:

1. 实例一个简单的 Tree Control,双击取得节点的Key 和 TEXT

2. 建立有数据表接口的Tree Control 对象

3. 通过右键菜单实现 Tree Control节点的 增 删 改 功能

4. Tree Control对象与ALV Grid对象关联

××××××××××××××××××××华丽的分割线×××××××××××××××××××××××

BEGIN

(一)实例一个简单的 Tree Control,双击取得节点的Key 和 TEXT.

1. 创建一个ABAP程序

2. 在程序中添加一个屏幕100,使用屏幕制作器,建立Screen,添加屏幕对象

    创建好的屏幕和对象界面如图:

   

    屏幕元素清单

   

 逻辑流程序

PROCESS BEFORE OUTPUT.
 MODULE STATUS_0100.
*
PROCESS AFTER INPUT.
 MODULE USER_COMMAND_0100.

  主程序

  1 *&---------------------------------------------------------------------*
  2 *& Report  ZHAIM_TREE_CONTROL
  3 *&
  4 *&---------------------------------------------------------------------*
  5 *&
  6 *&
  7 *&---------------------------------------------------------------------*
  8 
  9 REPORT  ZHAIM_TREE_CONTROL.
 10 * 功能码
 11 DATA: OK_CODE TYPE SY-UCOMM,
 12       SAVE_OK TYPE SY-UCOMM.
 13 * key text
 14 DATA: NODEKEY(20) TYPE C,
 15       NODETXT(20) TYPE C.
 16 
 17 * 定制控制对象
 18 DATA: WA_CONTAINER TYPE SCRFNAME VALUE 'TREE',
 19 * 客户对象
 20       WA_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
 21 * 实例化对象
 22       WA_TREE TYPE REF TO CL_GUI_SIMPLE_TREE.
 23 * 节点信息表
 24 DATA: IT_NODETABLE LIKE TABLE OF MTREESNODE,
 25       IW_NODETABLE TYPE MTREESNODE.
 26 
 27 DATA  WA_SPFLI TYPE TABLE OF SPFLI.
 28 
 29 *创建一个类,实现一个双击方法
 30 CLASS LCL_APPLICATION DEFINITION DEFERRED.
 31 
 32 *&---------------------------------------------------------------------*
 33 *&       Class (DEFINITION)  LCL_APPLICATION
 34 *&---------------------------------------------------------------------*
 35 *        Text
 36 *----------------------------------------------------------------------*
 37 CLASS LCL_APPLICATION DEFINITION.
 38   PUBLIC SECTION.
 39     METHODS HANDLE_NODE_DOUBLE_CLICK
 40         FOR EVENT NODE_DOUBLE_CLICK
 41         OF CL_GUI_SIMPLE_TREE
 42         IMPORTING NODE_KEY.
 43 ENDCLASS.               "LCL_APPLICATION
 44 *&---------------------------------------------------------------------*
 45 *&       Class (Implementation)  LCL_APPLICATION
 46 *&---------------------------------------------------------------------*
 47 *        Text
 48 *----------------------------------------------------------------------*
 49 CLASS LCL_APPLICATION IMPLEMENTATION.
 50 
 51   METHOD HANDLE_NODE_DOUBLE_CLICK.
 52 
 53     NODEKEY = NODE_KEY.
 54 
 55     READ TABLE IT_NODETABLE WITH KEY NODE_KEY = NODE_KEY INTO IW_NODETABLE.
 56 
 57     NODETXT = IW_NODETABLE-TEXT.
 58   ENDMETHOD.
 59 
 60 ENDCLASS.               "LCL_APPLICATION
 61 
 62 * 双击方法的类的实例化对象 准备在PBO中分配给TREE对象
 63 DATA: G_APPLICATION TYPE REF TO LCL_APPLICATION.
 64 
 65 
 66 START-OF-SELECTION.
 67 
 68   CREATE OBJECT G_APPLICATION.
 69 
 70   CALL SCREEN 100.
 71 
 72 
 73 *&---------------------------------------------------------------------*
 74 *&      Module  USER_COMMAND_0100  INPUT
 75 *&---------------------------------------------------------------------*
 76 *       text
 77 *----------------------------------------------------------------------*
 78 MODULE USER_COMMAND_0100 INPUT.
 79 
 80   SAVE_OK = OK_CODE.
 81 
 82   CLEAR OK_CODE.
 83 
 84   CASE SAVE_OK.
 85     WHEN 'BACK'.
 86       LEAVE PROGRAM.
 87     WHEN OTHERS.
 88   ENDCASE.
 89 
 90 ENDMODULE.                 " USER_COMMAND_0100  INPUT
 91 *&---------------------------------------------------------------------*
 92 *&      Module  STATUS_0100  OUTPUT
 93 *&---------------------------------------------------------------------*
 94 *       text
 95 *----------------------------------------------------------------------*
 96 MODULE STATUS_0100 OUTPUT.
 97   SET PF-STATUS 'TREECTRL_GUIS'.
 98   SET TITLEBAR 'TREE CONTROL'.
 99 IF WA_CUSTOM_CONTAINER IS INITIAL.
100   PERFORM FRM_CREATE_TREE.
101 ENDIF.
102 ENDMODULE.                 " STATUS_0100  OUTPUT
103 
104 *&---------------------------------------------------------------------*
105 *&      Form  FRM_CREATE_TREE
106 *&---------------------------------------------------------------------*
107 *       text
108 *----------------------------------------------------------------------*
109 *  -->  p1        text
110 *  <--  p2        text
111 *----------------------------------------------------------------------*
112 FORM FRM_CREATE_TREE .
113   DATA: EVENTS TYPE CNTL_SIMPLE_EVENTS,
114         EVENT1 TYPE CNTL_SIMPLE_EVENT.
115 * 定制控制对象,指定tree control的容器
116   CREATE OBJECT WA_CUSTOM_CONTAINER
117    EXPORTING
118 *    PARENT                      =
119     CONTAINER_NAME              = WA_CONTAINER " 定制对象名:TREE
120 *    STYLE                       =
121 *    LIFETIME                    = lifetime_default
122 *    REPID                       =
123 *    DYNNR                       =
124 *    NO_AUTODEF_PROGID_DYNNR     =
125   EXCEPTIONS
126     CNTL_ERROR                  = 1
127     CNTL_SYSTEM_ERROR           = 2
128     CREATE_ERROR                = 3
129     LIFETIME_ERROR              = 4
130     LIFETIME_DYNPRO_DYNPRO_LINK = 5
131     others                      = 6
132     .
133 
134 IF SY-SUBRC <> 0.
135 * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
136 *            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
137 ENDIF.
138 
139 * 定义树对象
140   CREATE OBJECT WA_TREE
141     EXPORTING
142 *      LIFETIME                    =
143       PARENT                      = WA_CUSTOM_CONTAINER
144 *      SHELLSTYLE                  =
145       NODE_SELECTION_MODE         = CL_GUI_SIMPLE_TREE=>NODE_SEL_MODE_SINGLE
146 *      HIDE_SELECTION              =
147 *      NAME                        =
148     EXCEPTIONS
149       LIFETIME_ERROR              = 1
150       CNTL_SYSTEM_ERROR           = 2
151       CREATE_ERROR                = 3
152       FAILED                      = 4
153       ILLEGAL_NODE_SELECTION_MODE = 5
154       others                      = 6
155       .
156   IF SY-SUBRC <> 0.
157 *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
158 *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
159   ENDIF.
160 
161 * 通过宏定义树 节点
162 DEFINE  CREATE_TREE.
163 
164   CLEAR IW_NODETABLE.
165 
166   IW_NODETABLE-NODE_KEY = &1.         "节点KEY值
167   IW_NODETABLE-RELATKEY = &2.         "相关联的节点KEY值
168   IW_NODETABLE-RELATSHIP = &3.        "关联关系
169   IW_NODETABLE-HIDDEN = &4.
170   IW_NODETABLE-DISABLED = &5.
171   IW_NODETABLE-ISFOLDER = &6.         "文件夹形式
172 *  图标,可以运行程序 SHOWICON 查阅
173   IW_NODETABLE-N_IMAGE = &7.          "图标
174   IW_NODETABLE-EXP_IMAGE = &7.        "图标
175 *  IW_NODETABLE-EXPANDER.
176   IW_NODETABLE-TEXT = &8.             "节点文本
177 
178   APPEND IW_NODETABLE TO IT_NODETABLE.
179 
180 END-OF-DEFINITION.
181 
182 CREATE_TREE 'CN'   ''       ''
183                                 '' '' 'X' '' '中国'.
184 CREATE_TREE 'BEIJING' 'CN' CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD '' '' 'X' '' '北京'.
185 CREATE_TREE 'FENGTAI' 'BEIJING' CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD '' '' '' '@6G@' '丰台区'.
186 CREATE_TREE 'HAIDIAN' 'BEIJING' CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD '' '' '' '@6G@' '海淀区'.
187 CREATE_TREE 'CHAOYANG' 'BEIJING' CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD '' '' '' '@6G@' '朝阳区'.
188 CREATE_TREE 'DONGCHENG' 'BEIJING' CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD '' '' '' '@6G@' '东城区'.
189 
190 CREATE_TREE 'SHENGHAI' 'CN' CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD '' '' 'X' '' '上海'.
191 CREATE_TREE 'QINGPU' 'SHENGHAI' CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD '' '' '' '@6F@' '青浦区'.
192 CREATE_TREE 'HONGKOU' 'SHENGHAI' CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD '' '' '' '@6F@' '虹口区'.
193 CREATE_TREE 'HUANGPU' 'SHENGHAI' CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD '' '' '' '@6F@' '黄浦区'.
194 
195 * 为TREE对象添加节点
196   CALL METHOD WA_TREE->ADD_NODES
197     EXPORTING
198       TABLE_STRUCTURE_NAME           = 'MTREESNODE'
199       NODE_TABLE                     =  IT_NODETABLE
200 *    EXCEPTIONS
201 *      ERROR_IN_IT_NODETABLE          = 1
202 *      FAILED                         = 2
203 *      DP_ERROR                       = 3
204 *      TABLE_STRUCTURE_NAME_NOT_FOUND = 4
205 *      others                         = 5
206           .
207   IF SY-SUBRC <> 0.
208 *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
209 *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
210   ENDIF.
211 
212 *定义双击事件
213   EVENT1-EVENTID = CL_GUI_SIMPLE_TREE=>EVENTID_NODE_DOUBLE_CLICK.
214   EVENT1-APPL_EVENT = 'X'.
215   APPEND EVENT1 TO EVENTS.
216 
217 * 添加事件内表
218   CALL METHOD WA_TREE->SET_REGISTERED_EVENTS
219     EXPORTING
220       EVENTS                    = EVENTS
221     EXCEPTIONS
222       CNTL_ERROR                = 1
223       CNTL_SYSTEM_ERROR         = 2
224       ILLEGAL_EVENT_COMBINATION = 3
225       others                    = 4
226           .
227   IF SY-SUBRC <> 0.
228 *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
229 *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
230   ENDIF.
231 *  将已定义的双击事件分配到树对象
232   SET HANDLER G_APPLICATION->HANDLE_NODE_DOUBLE_CLICK FOR WA_TREE.
233 ENDFORM.                    " FRM_CREATE_TREE

(二) 建立有数据接口的Tree Control 对象

从数据表中读取结构,并按照数据关系建立Tree Control,

提一下思路,不做具体事例。。。

将需要的表结构存储到内表中,然后LOOP这张内表,循环调用宏来填充节点内表:例如

DEFINE  CREATE_TREE.

  CLEAR IW_NODETABLE.

  IW_NODETABLE-NODE_KEY = &1.         "节点KEY值
  IW_NODETABLE-RELATKEY = &2.         "相关联的节点KEY值
  IW_NODETABLE-RELATSHIP = &3.        "关联关系
  IW_NODETABLE-HIDDEN = &4.
  IW_NODETABLE-DISABLED = &5.
  IW_NODETABLE-ISFOLDER = &6.         "文件夹形式
*  图标,可以运行程序 SHOWICON 查阅
  IW_NODETABLE-N_IMAGE = &7.          "图标
  IW_NODETABLE-EXP_IMAGE = &7.        "图标
*  IW_NODETABLE-EXPANDER.
  IW_NODETABLE-TEXT = &8.             "节点文本

  APPEND IW_NODETABLE TO IT_NODETABLE.

END-OF-DEFINITION.

LOOP AT  INTO .
   "循环调用宏
    CREATE_TREE ' '  ' '  ' '  ' '  ' '  .
     ...
ENDLOOP.

这样节点情况,也会根据数据情况来动态变化。

(三)通过右键菜单实现 Tree Control节点的 增 删 改 功能

 在OO的类中,添加两个方法

*&---------------------------------------------------------------------*
*&       Class (DEFINITION)  LCL_APPLICATION
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS LCL_APPLICATION DEFINITION.
  PUBLIC SECTION.

    METHODS:

     HANDLE_NODE_DOUBLE_CLICK
        FOR EVENT NODE_DOUBLE_CLICK
         OF CL_GUI_SIMPLE_TREE
         IMPORTING NODE_KEY,
*    构成右键菜单的方法           HANDLE_NODE_CONTEXT_MENU_REQ
        FOR EVENT NODE_CONTEXT_MENU_REQUEST
         OF CL_GUI_SIMPLE_TREE
         IMPORTING NODE_KEY MENU,
*    响应右键菜单的方法
     HANDLE_NODE_CONTEXT_MENU_SEL
        FOR EVENT NODE_CONTEXT_MENU_SELECT
         OF CL_GUI_SIMPLE_TREE
         IMPORTING NODE_KEY FCODE.

ENDCLASS.               "LCL_APPLICATION

 方法的实现

*&---------------------------------------------------------------------*
*&       Class (Implementation)  LCL_APPLICATION
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS LCL_APPLICATION IMPLEMENTATION.

  METHOD HANDLE_NODE_DOUBLE_CLICK.
    READ TABLE IT_NODETABLE WITH KEY NODE_KEY = NODE_KEY INTO IW_NODETABLE.
    L_KUNNRK = IW_NODETABLE-NODE_KEY.
    L_VTWEGK  = IW_NODETABLE-RELATKEY.
    CLEAR IW_NODETABLE.

    READ TABLE IT_NODETABLE WITH KEY NODE_KEY = L_VTWEGK INTO IW_NODETABLE.
    L_VKORGK = IW_NODETABLE-RELATKEY.
    CLEAR IW_NODETABLE.

    PERFORM FRM_GET_DATA USING L_KUNNRK L_VTWEGK L_VKORGK.

     CALL METHOD WA_ALVG->REFRESH_TABLE_DISPLAY
*      EXPORTING
*        IS_STABLE      =
*        I_SOFT_REFRESH =
*      EXCEPTIONS
*        FINISHED       = 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.


  ENDMETHOD.

  METHOD HANDLE_NODE_CONTEXT_MENU_REQ.
    CALL METHOD MENU->ADD_FUNCTION
      EXPORTING
        TEXT  = '增加本级节点'
        FCODE = 'CODE1'.

    CALL METHOD MENU->ADD_FUNCTION
      EXPORTING
        TEXT  = '增加子节点'
        FCODE = 'CODE2'.

    CALL METHOD MENU->ADD_FUNCTION
      EXPORTING
        TEXT  = '修改当前节点'
        FCODE = 'CODE3'.

    CALL METHOD MENU->ADD_FUNCTION
      EXPORTING
        TEXT  = '删除当前节点'
        FCODE = 'CODE4'.
  ENDMETHOD.

  METHOD HANDLE_NODE_CONTEXT_MENU_SEL.

    DATA STR1 TYPE TV_NODEKEY.

    CALL METHOD WA_TREE->GET_SELECTED_NODE
      IMPORTING
        NODE_KEY                   = STR1.

    IF SY-SUBRC = 0.

       READ TABLE IT_NODETABLE WITH KEY NODE_KEY = STR1 INTO IW_NODETABLE.


       IF FCODE = 'CODE4'.
          CALL METHOD WA_TREE->DELETE_NODE
            EXPORTING
              NODE_KEY          = IW_NODETABLE-NODE_KEY
              .
          DELETE IT_NODETABLE WHERE NODE_KEY = IW_NODETABLE-NODE_KEY.
       ENDIF.

    ENDIF.

  ENDMETHOD.
ENDCLASS.               "LCL_APPLICATION

(四) Tree Control对象与ALV Grid对象关联

附,源代码:

  1 *&---------------------------------------------------------------------*
  2 *& Report  ZHAIM_TREE_CONTROL
  3 *&
  4 *&---------------------------------------------------------------------*
  5 *&
  6 *&
  7 *&---------------------------------------------------------------------*
  8 
  9 REPORT  ZHAIM_TREE_CONTROL.
 10 * 功能码
 11 DATA: OK_CODE TYPE SY-UCOMM,
 12       SAVE_OK TYPE SY-UCOMM.
 13 
 14 
 15 * 定制控制对象
 16 DATA: WA_CONTAINER  TYPE SCRFNAME VALUE 'TREE',
 17       WA_CONTAINERA TYPE SCRFNAME VALUE 'ALVG',
 18 * 客户对象
 19       WA_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
 20       WA_CUSTOM_CNTNRALVG TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
 21 * 实例化对象
 22       WA_TREE TYPE REF TO CL_GUI_SIMPLE_TREE,
 23       WA_ALVG TYPE REF TO CL_GUI_ALV_GRID.
 24 * 节点信息表
 25 DATA: IT_NODETABLE TYPE STANDARD TABLE OF MTREESNODE,
 26       IW_NODETABLE TYPE MTREESNODE.
 27 
 28 DATA: IS_LAYOUT   TYPE LVC_S_LAYO,
 29       IT_FIELDCAT TYPE STANDARD TABLE OF LVC_S_FCAT,
 30       IW_FIELDCAT LIKE LINE OF IT_FIELDCAT .
 31 
 32 TYPES:BEGIN OF TY_VBAK ,
 33         VKORG  TYPE VBAK-VKORG ,
 34         VTWEG  TYPE VBAK-VTWEG ,
 35         KUNNR  TYPE VBAK-KUNNR ,
 36         VBELN  TYPE VBAK-VBELN ,
 37         VKORGT TYPE TVKOT-VTEXT,
 38         VTWEGT TYPE TVTWT-VTEXT,
 39       END OF TY_VBAK .
 40 
 41 DATA: IT_VBAK TYPE STANDARD TABLE OF TY_VBAK,
 42       IW_VBAK TYPE TY_VBAK.
 43 
 44 TYPES: BEGIN OF TY_VBAP ,
 45           VBELN TYPE VBAP-VBELN ,
 46           POSNR TYPE VBAP-POSNR ,
 47           MATNR TYPE VBAP-MATNR ,
 48           NETWR TYPE VBAP-NETWR ,
 49           WERKS TYPE VBAP-WERKS ,
 50           LSMENG TYPE VBAP-LSMENG ,
 51        END OF TY_VBAP .
 52 
 53 DATA: IT_VBAP TYPE STANDARD TABLE OF TY_VBAP,
 54       IW_VBAP TYPE TY_VBAP.
 55 
 56 DATA GS_LAYOUT   TYPE LVC_S_LAYO.
 57 DATA GT_FIELDCAT TYPE STANDARD TABLE OF LVC_S_FCAT .
 58 DATA GW_FIELDCAT LIKE LINE OF GT_FIELDCAT .
 59 * 通过宏定义树 节点
 60 DEFINE  CREATE_TREE.
 61 
 62   CLEAR IW_NODETABLE.
 63 
 64   IW_NODETABLE-NODE_KEY = &1.         "节点KEY值
 65   IW_NODETABLE-RELATKEY = &2.         "相关联的节点KEY值
 66   IW_NODETABLE-RELATSHIP = &3.        "关联关系
 67   IW_NODETABLE-HIDDEN = &4.
 68   IW_NODETABLE-DISABLED = &5.
 69   IW_NODETABLE-ISFOLDER = &6.         "文件夹形式
 70 *  图标,可以运行程序 SHOWICON 查阅
 71   IW_NODETABLE-N_IMAGE = &7.          "图标
 72   IW_NODETABLE-EXP_IMAGE = &7.        "图标
 73   IW_NODETABLE-TEXT = &8.             "节点文本
 74 
 75   CLEAR IW_NODETABLE-EXPANDER.
 76 
 77   APPEND IW_NODETABLE TO IT_NODETABLE.
 78 
 79 END-OF-DEFINITION.
 80 *创建一个类,实现一个双击方法
 81 CLASS LCL_APPLICATION DEFINITION  DEFERRED.
 82 
 83 *&---------------------------------------------------------------------*
 84 *&       Class (DEFINITION)  LCL_APPLICATION
 85 *&---------------------------------------------------------------------*
 86 *        Text
 87 *----------------------------------------------------------------------*
 88 CLASS LCL_APPLICATION DEFINITION .
 89   PUBLIC SECTION.
 90 
 91     DATA: L_KUNNRK  TYPE VBAK-KUNNR,
 92           L_VTWEGK  TYPE VBAK-VTWEG,
 93           L_VKORGK  TYPE VBAK-VKORG.
 94 
 95     METHODS:
 96      "双击方法
 97      HANDLE_NODE_DOUBLE_CLICK
 98         FOR EVENT NODE_DOUBLE_CLICK OF CL_GUI_SIMPLE_TREE
 99          IMPORTING NODE_KEY,
100      "ALV toolbar
101      HANDLE_TOOLBAR
102         FOR EVENT TOOLBAR OF CL_GUI_ALV_GRID
103         IMPORTING E_OBJECT E_INTERACTIVE,
104      "响应 toolbar功能的方法
105      HANDLE_USER_COMMAND
106         FOR EVENT USER_COMMAND OF CL_GUI_ALV_GRID
107         IMPORTING E_UCOMM,
108      "响应热键
109      HANDLE_HOTSPOT_CLICK
110         FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID
111         IMPORTING E_ROW_ID,
112      "构成右键菜单
113      HANDLE_NODE_CONTEXT_MENU_REQ
114         FOR EVENT NODE_CONTEXT_MENU_REQUEST OF CL_GUI_SIMPLE_TREE
115          IMPORTING NODE_KEY MENU,
116      "获取右键所选择的节点node_key
117      HANDLE_NODE_CONTEXT_MENU_SEL
118         FOR EVENT NODE_CONTEXT_MENU_SELECT OF CL_GUI_SIMPLE_TREE
119          IMPORTING NODE_KEY FCODE,
120 
121      HANDLE_DOUBLE_CLICK
122        FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
123      IMPORTING E_ROW.
124 
125 ENDCLASS.               "LCL_APPLICATION
126 *&---------------------------------------------------------------------*
127 *&       Class (Implementation)  LCL_APPLICATION
128 *&---------------------------------------------------------------------*
129 *        Text
130 *----------------------------------------------------------------------*
131 CLASS LCL_APPLICATION IMPLEMENTATION.
132 
133   METHOD HANDLE_NODE_DOUBLE_CLICK.
134     READ TABLE IT_NODETABLE WITH KEY NODE_KEY = NODE_KEY INTO IW_NODETABLE.
135     L_KUNNRK = IW_NODETABLE-NODE_KEY.
136     L_VTWEGK  = IW_NODETABLE-RELATKEY.
137     CLEAR IW_NODETABLE.
138 
139     READ TABLE IT_NODETABLE WITH KEY NODE_KEY = L_VTWEGK INTO IW_NODETABLE.
140     L_VKORGK = IW_NODETABLE-RELATKEY.
141     CLEAR IW_NODETABLE.
142 
143     PERFORM FRM_GET_DATA USING L_KUNNRK L_VTWEGK L_VKORGK.
144 
145     CALL METHOD WA_ALVG->REFRESH_TABLE_DISPLAY .
146 
147     IF SY-SUBRC <> 0.
148 *     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
149 *                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
150     ENDIF.
151   ENDMETHOD.
152 
153   METHOD HANDLE_TOOLBAR.
154     DATA: LS_TOOLBAR TYPE STB_BUTTON.
155     CLEAR LS_TOOLBAR-BUTN_TYPE.
156     APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
157     CLEAR LS_TOOLBAR.
158 
159     CLEAR LS_TOOLBAR.
160     LS_TOOLBAR-FUNCTION = 'SHOW_DATA'.
161     LS_TOOLBAR-ICON = ICON_PPE_VNODE.
162     LS_TOOLBAR-QUICKINFO = '明细信息'.
163     LS_TOOLBAR-TEXT = '明细信息'.
164     IF IT_VBAP IS INITIAL.
165       LS_TOOLBAR-DISABLED = 'X'.
166     ENDIF.
167 
168      APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
169 
170     CLEAR LS_TOOLBAR.
171     LS_TOOLBAR-FUNCTION = 'INFO'.
172     LS_TOOLBAR-ICON = ICON_PPE_VNODE.
173     LS_TOOLBAR-QUICKINFO = '信息'.
174     LS_TOOLBAR-TEXT = '信息'.
175     LS_TOOLBAR-DISABLED = 'X'.
176      APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
177   ENDMETHOD.
178 
179   METHOD HANDLE_USER_COMMAND.
180     DATA: LT_ROWS TYPE LVC_T_ROW.
181     CASE E_UCOMM.
182       WHEN 'SHOW_DATA'.
183         CALL METHOD WA_ALVG->GET_SELECTED_ROWS
184           IMPORTING
185             ET_INDEX_ROWS = LT_ROWS
186 *            ET_ROW_NO     =
187             .
188         CALL METHOD CL_GUI_CFW=>FLUSH
189 *          EXCEPTIONS
190 *            CNTL_SYSTEM_ERROR = 1
191 *            CNTL_ERROR        = 2
192 *            others            = 3
193                 .
194         IF LT_ROWS IS INITIAL.
195           MESSAGE S001(00) WITH '请选择行'.
196         ELSE.
197           PERFORM FRM_DETAILS TABLES LT_ROWS.
198         ENDIF.
199 
200     ENDCASE.
201   ENDMETHOD.
202 
203   METHOD HANDLE_HOTSPOT_CLICK.
204 
205           PERFORM FRM_HOTSPOT USING E_ROW_ID.
206 
207   ENDMETHOD.
208   METHOD HANDLE_NODE_CONTEXT_MENU_REQ.
209     CALL METHOD MENU->ADD_FUNCTION
210       EXPORTING
211         TEXT  = '增加本级节点'
212         FCODE = 'CODE1'.
213 
214     CALL METHOD MENU->ADD_FUNCTION
215       EXPORTING
216         TEXT  = '增加子节点'
217         FCODE = 'CODE2'.
218 
219     CALL METHOD MENU->ADD_FUNCTION
220       EXPORTING
221         TEXT  = '修改当前节点'
222         FCODE = 'CODE3'.
223 
224     CALL METHOD MENU->ADD_FUNCTION
225       EXPORTING
226         TEXT  = '删除当前节点'
227         FCODE = 'CODE4'.
228   ENDMETHOD.
229 
230   METHOD HANDLE_NODE_CONTEXT_MENU_SEL.
231     DATA STR1 TYPE TV_NODEKEY.
232     CALL METHOD WA_TREE->GET_SELECTED_NODE
233       IMPORTING
234         NODE_KEY                   = STR1.
235 
236     IF SY-SUBRC = 0.
237        READ TABLE IT_NODETABLE WITH KEY NODE_KEY = STR1 INTO IW_NODETABLE.
238        IF FCODE = 'CODE4'.
239           CALL METHOD WA_TREE->DELETE_NODE
240             EXPORTING
241               NODE_KEY          = IW_NODETABLE-NODE_KEY
242                             .
243           DELETE IT_NODETABLE WHERE NODE_KEY = IW_NODETABLE-NODE_KEY.
244        ENDIF.
245     ENDIF.
246   ENDMETHOD.
247 
248   METHOD HANDLE_DOUBLE_CLICK.
249     PERFORM FRM_DBLCLICK USING E_ROW.
250   ENDMETHOD.
251 ENDCLASS.               "LCL_APPLICATION
252 
253 * 双击方法的类的实例化对象 准备在PBO中分配给TREE对象
254 DATA: G_APPLICATION TYPE REF TO LCL_APPLICATION.
255 
256 
257 START-OF-SELECTION.
258 
259   "创建类对象
260   CREATE OBJECT G_APPLICATION.
261 
262   PERFORM FRM_GET_NODE_DATA.
263   CALL SCREEN 100.
264 
265 
266 *&---------------------------------------------------------------------*
267 *&      Module  STATUS_0100  OUTPUT
268 *&---------------------------------------------------------------------*
269 *       text
270 *----------------------------------------------------------------------*
271 MODULE STATUS_0100 OUTPUT.
272   SET PF-STATUS 'TREECTRL_GUIS'.
273   SET TITLEBAR 'TREE CONTROL'.
274 IF WA_CUSTOM_CONTAINER IS INITIAL.
275   PERFORM FRM_CREATE_TREE.
276 ENDIF.
277 ENDMODULE.                 " STATUS_0100  OUTPUT
278 
279 *&---------------------------------------------------------------------*
280 *&      Module  USER_COMMAND_0100  INPUT
281 *&---------------------------------------------------------------------*
282 *       text
283 *----------------------------------------------------------------------*
284 MODULE USER_COMMAND_0100 INPUT.
285 
286   SAVE_OK = OK_CODE.
287 
288   CLEAR OK_CODE.
289 
290   CASE SAVE_OK.
291     WHEN 'BACK'.
292       LEAVE PROGRAM.
293     WHEN OTHERS.
294   ENDCASE.
295 
296 ENDMODULE.                 " USER_COMMAND_0100  INPUT
297 
298 *&---------------------------------------------------------------------*
299 *&      Form  FRM_CREATE_TREE
300 *&---------------------------------------------------------------------*
301 *       text
302 *----------------------------------------------------------------------*
303 *  -->  p1        text
304 *  <--  p2        text
305 *----------------------------------------------------------------------*
306 FORM FRM_CREATE_TREE .
307   DATA: EVENTS TYPE CNTL_SIMPLE_EVENTS,
308         EVENT1 TYPE CNTL_SIMPLE_EVENT.
309 
310 * 定制控制对象,指定tree control的容器
311   CREATE OBJECT WA_CUSTOM_CONTAINER
312    EXPORTING
313 *    PARENT                      =
314     CONTAINER_NAME              = WA_CONTAINER " 定制对象名:TREE
315 *    STYLE                       =
316 *    LIFETIME                    = lifetime_default
317 *    REPID                       =
318 *    DYNNR                       =
319 *    NO_AUTODEF_PROGID_DYNNR     =
320     EXCEPTIONS
321       CNTL_ERROR                  = 1
322       CNTL_SYSTEM_ERROR           = 2
323       CREATE_ERROR                = 3
324       LIFETIME_ERROR              = 4
325       LIFETIME_DYNPRO_DYNPRO_LINK = 5
326       OTHERS                      = 6
327       .
328 
329     IF SY-SUBRC <> 0.
330 *     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
331 *                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
332     ENDIF.
333 
334 * 定制控制对象,指定ALV 的容器
335 CREATE OBJECT WA_CUSTOM_CNTNRALVG
336   EXPORTING
337 *    PARENT                      =
338     CONTAINER_NAME              = WA_CONTAINERA
339 *    STYLE                       =
340 *    LIFETIME                    = lifetime_default
341 *    REPID                       =
342 *    DYNNR                       =
343 *    NO_AUTODEF_PROGID_DYNNR     =
344 *  EXCEPTIONS
345 *    CNTL_ERROR                  = 1
346 *    CNTL_SYSTEM_ERROR           = 2
347 *    CREATE_ERROR                = 3
348 *    LIFETIME_ERROR              = 4
349 *    LIFETIME_DYNPRO_DYNPRO_LINK = 5
350 *    others                      = 6
351     .
352 IF SY-SUBRC <> 0.
353 * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
354 *            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
355 ENDIF.
356 
357 
358 
359 * 定义树对象
360   CREATE OBJECT WA_TREE
361     EXPORTING
362 *      LIFETIME                    =
363       PARENT                      = WA_CUSTOM_CONTAINER
364 *      SHELLSTYLE                  =
365       NODE_SELECTION_MODE         = CL_GUI_SIMPLE_TREE=>NODE_SEL_MODE_SINGLE
366 *      HIDE_SELECTION              =
367 *      NAME                        =
368     EXCEPTIONS
369       LIFETIME_ERROR              = 1
370       CNTL_SYSTEM_ERROR           = 2
371       CREATE_ERROR                = 3
372       FAILED                      = 4
373       ILLEGAL_NODE_SELECTION_MODE = 5
374       others                      = 6
375       .
376   IF SY-SUBRC <> 0.
377 *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
378 *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
379   ENDIF.
380 
381 * 定义ALV对象
382 
383   CREATE OBJECT WA_ALVG
384     EXPORTING
385 *      I_SHELLSTYLE      = 0
386 *      I_LIFETIME        =
387       I_PARENT          = WA_CUSTOM_CNTNRALVG
388 *      I_APPL_EVENTS     = space
389 *      I_PARENTDBG       =
390 *      I_APPLOGPARENT    =
391 *      I_GRAPHICSPARENT  =
392 *      I_NAME            =
393 *      I_FCAT_COMPLETE   = SPACE
394 *    EXCEPTIONS
395 *      ERROR_CNTL_CREATE = 1
396 *      ERROR_CNTL_INIT   = 2
397 *      ERROR_CNTL_LINK   = 3
398 *      ERROR_DP_CREATE   = 4
399 *      others            = 5
400       .
401   IF SY-SUBRC <> 0.
402 *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
403 *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
404   ENDIF.
405 
406 DATA: L_VKORGT TYPE TVKOT-VTEXT,
407       L_VTWEGT TYPE TVTWT-VTEXT,
408       L_VKORG  TYPE VBAK-VKORG,
409       L_VTWEG  TYPE VBAK-VTWEG,
410       L_KUNNR  TYPE VBAK-KUNNR.
411 
412 
413 LOOP AT IT_VBAK INTO IW_VBAK.
414   L_VKORG = IW_VBAK-VKORG.
415   L_VTWEG = IW_VBAK-VTWEG.
416   L_KUNNR = IW_VBAK-KUNNR.
417   L_VKORGT = IW_VBAK-VKORGT.
418   L_VTWEGT = IW_VBAK-VTWEGT.
419 
420   CREATE_TREE L_VKORG  '' '' '' '' 'X' '' L_VKORGT.
421   CREATE_TREE L_VTWEG L_VKORG  6 '' '' 'X' '' L_VTWEGT.
422   CREATE_TREE L_KUNNR L_VTWEG  6 '' '' '' '@5B@' IW_VBAK-KUNNR.
423 
424   CLEAR: L_VKORGT,
425          L_VTWEGT,
426          L_VKORG,
427          L_VTWEG,
428          L_KUNNR,
429          IW_VBAK.
430 ENDLOOP.
431 
432 * 为TREE对象添加节点
433   SORT IT_NODETABLE BY NODE_KEY RELATKEY.
434   DELETE ADJACENT DUPLICATES FROM IT_NODETABLE COMPARING NODE_KEY RELATKEY.
435 
436   SORT IT_NODETABLE BY RELATSHIP ASCENDING ISFOLDER DESCENDING.
437   CALL METHOD WA_TREE->ADD_NODES
438     EXPORTING
439       TABLE_STRUCTURE_NAME           = 'MTREESNODE'
440       NODE_TABLE                     =  IT_NODETABLE
441 *    EXCEPTIONS
442 *      ERROR_IN_IT_NODETABLE          = 1
443 *      FAILED                         = 2
444 *      DP_ERROR                       = 3
445 *      TABLE_STRUCTURE_NAME_NOT_FOUND = 4
446 *      others                         = 5
447           .
448   IF SY-SUBRC <> 0.
449 *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
450 *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
451   ENDIF.
452 
453    PERFORM FRM_SET_ALVTB .
454 
455 *定义双击事件
456   EVENT1-EVENTID = CL_GUI_SIMPLE_TREE=>EVENTID_NODE_DOUBLE_CLICK.
457   EVENT1-APPL_EVENT = 'X'.
458   APPEND EVENT1 TO EVENTS.
459 
460   EVENT1-EVENTID = CL_GUI_SIMPLE_TREE=>EVENTID_NODE_CONTEXT_MENU_REQ.
461   EVENT1-APPL_EVENT = ''.
462   APPEND EVENT1 TO EVENTS.
463 
464   CALL METHOD WA_TREE->SET_CTX_MENU_SELECT_EVENT_APPL
465     EXPORTING
466       APPL_EVENT = 'X'  .
467 
468 * 添加事件内表
469   CALL METHOD WA_TREE->SET_REGISTERED_EVENTS
470     EXPORTING
471       EVENTS                    = EVENTS
472     EXCEPTIONS
473       CNTL_ERROR                = 1
474       CNTL_SYSTEM_ERROR         = 2
475       ILLEGAL_EVENT_COMBINATION = 3
476       others                    = 4
477           .
478   IF SY-SUBRC <> 0.
479 *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
480 *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
481   ENDIF.
482 
483   SET HANDLER G_APPLICATION->HANDLE_DOUBLE_CLICK FOR WA_ALVG.
484   SET HANDLER G_APPLICATION->HANDLE_HOTSPOT_CLICK FOR WA_ALVG.
485   SET HANDLER G_APPLICATION->HANDLE_TOOLBAR FOR WA_ALVG.
486   SET HANDLER G_APPLICATION->HANDLE_USER_COMMAND FOR WA_ALVG.
487 *  将已定义的双击事件分配到树对象
488   SET HANDLER G_APPLICATION->HANDLE_NODE_DOUBLE_CLICK FOR WA_TREE.
489   SET HANDLER G_APPLICATION->HANDLE_NODE_CONTEXT_MENU_REQ FOR WA_TREE.
490   SET HANDLER G_APPLICATION->HANDLE_NODE_CONTEXT_MENU_SEL FOR WA_TREE.
491   "为ALV设置toolbar
492   CALL METHOD WA_ALVG->SET_TOOLBAR_INTERACTIVE
493       .
494 
495 ENDFORM.                    " FRM_CREATE_TREE
496 
497 
498 *&---------------------------------------------------------------------*
499 *&      Form  FRM_GET_DATA
500 *&---------------------------------------------------------------------*
501 *       text
502 *----------------------------------------------------------------------*
503 *      -->P_NODE_KEY  text
504 *      -->P_IW_NODETABLE_RELATKEY  text
505 *----------------------------------------------------------------------*
506 FORM FRM_GET_DATA  USING P_KUNNR
507                          P_VTWEG
508                          P_VKORG.
509 
510   CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
511   EXPORTING
512     INPUT  = P_KUNNR
513   IMPORTING
514     OUTPUT = P_KUNNR.
515 
516   SELECT
517      VBAP~VBELN
518      VBAP~POSNR
519      VBAP~MATNR
520      VBAP~NETWR
521      VBAP~WERKS
522      VBAP~LSMENG
523     INTO  TABLE IT_VBAP
524     FROM VBAP
525     INNER JOIN VBAK ON VBAP~VBELN = VBAK~VBELN
526        WHERE VBAK~VKORG = P_VKORG
527          AND VBAK~VTWEG = P_VTWEG
528          AND VBAK~KUNNR = P_KUNNR
529          AND VBAK~AUART NE 'Z001'.
530   IF IT_VBAP IS INITIAL.
531     MESSAGE S001(00) WITH '数据不存在或者尝试选择下级子节点'.
532     LEAVE TO SCREEN 100.
533   ENDIF.
534 
535   LOOP AT  IT_VBAP INTO IW_VBAP.
536     CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
537       EXPORTING
538         INPUT  = IW_VBAP-VBELN
539       IMPORTING
540         OUTPUT = IW_VBAP-VBELN.
541 
542     CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
543       EXPORTING
544         INPUT  = IW_VBAP-MATNR
545       IMPORTING
546         OUTPUT = IW_VBAP-MATNR.
547     MODIFY IT_VBAP FROM IW_VBAP .
548   ENDLOOP.
549 
550 ENDFORM.                    " GET_DATA
551 *&---------------------------------------------------------------------*
552 *&      Form  FRM_GET_NODE_DATA
553 *&---------------------------------------------------------------------*
554 *       text
555 *----------------------------------------------------------------------*
556 *  -->  p1        text
557 *  <--  p2        text
558 *----------------------------------------------------------------------*
559 FORM FRM_GET_NODE_DATA .
560 
561   SELECT A~VKORG
562          A~VTWEG
563          A~KUNNR
564          A~VBELN
565          B~VTEXT
566          C~VTEXT
567     INTO TABLE IT_VBAK
568     FROM VBAK AS A
569    INNER JOIN TVKOT AS B ON B~VKORG = A~VKORG
570    INNER JOIN TVTWT AS C ON C~VTWEG = A~VTWEG
571    WHERE B~SPRAS = '1' AND C~SPRAS = '1'.
572 
573   SORT IT_VBAK BY VKORG VTWEG KUNNR VBELN.
574   DELETE ADJACENT DUPLICATES FROM IT_VBAK COMPARING VKORG VTWEG KUNNR.
575 
576   IF SY-SUBRC <> 0.
577 
578   ENDIF.
579 
580   LOOP AT  IT_VBAK INTO IW_VBAK.
581     CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
582       EXPORTING
583         INPUT  = IW_VBAK-KUNNR
584       IMPORTING
585         OUTPUT = IW_VBAK-KUNNR.
586     MODIFY IT_VBAK FROM IW_VBAK.
587   ENDLOOP.
588 
589 ENDFORM.                    " FRM_GET_NODE_DATA
590 *&---------------------------------------------------------------------*
591 *&      Form  FRM_SET_ALVTB
592 *&---------------------------------------------------------------------*
593 *       text
594 *----------------------------------------------------------------------*
595 *  -->  p1        text
596 *  <--  p2        text
597 *----------------------------------------------------------------------*
598 FORM FRM_SET_ALVTB .
599   DATA: IT_TB_EXCLUDE TYPE UI_FUNCTIONS,
600         IW_TB_EXCLUDE LIKE LINE OF IT_TB_EXCLUDE.
601 
602   CLEAR GW_FIELDCAT .
603   GW_FIELDCAT-FIELDNAME = 'VBELN' .
604   GW_FIELDCAT-SCRTEXT_L = '销售订单' .
605   GW_FIELDCAT-HOTSPOT = 'X'.
606   GW_FIELDCAT-KEY = 'X'.
607   APPEND GW_FIELDCAT TO GT_FIELDCAT .
608 
609   CLEAR GW_FIELDCAT .
610   GW_FIELDCAT-FIELDNAME = 'POSNR' .
611   GW_FIELDCAT-SCRTEXT_L = '销售订单项目' .
612   APPEND GW_FIELDCAT TO GT_FIELDCAT .
613 
614   CLEAR GW_FIELDCAT .
615   GW_FIELDCAT-FIELDNAME = 'MATNR' .
616   GW_FIELDCAT-SCRTEXT_L = '物料编码' .
617   APPEND GW_FIELDCAT TO GT_FIELDCAT .
618 
619   CLEAR GW_FIELDCAT .
620   GW_FIELDCAT-FIELDNAME = 'NETWR' .
621   GW_FIELDCAT-SCRTEXT_L = '净价' .
622   APPEND GW_FIELDCAT TO GT_FIELDCAT .
623 
624   CLEAR GW_FIELDCAT .
625   GW_FIELDCAT-FIELDNAME = 'WERKS' .
626   GW_FIELDCAT-SCRTEXT_L = '工厂' .
627   APPEND GW_FIELDCAT TO GT_FIELDCAT .
628 
629   CLEAR GW_FIELDCAT .
630   GW_FIELDCAT-FIELDNAME = 'LSMENG' .
631   GW_FIELDCAT-SCRTEXT_L = '销售订单数量' .
632   APPEND GW_FIELDCAT TO GT_FIELDCAT .
633 
634   GS_LAYOUT-GRID_TITLE = 'SD分销渠道销售订单数据' .
635   "GS_LAYOUT-CWIDTH_OPT = 'X' .
636   GS_LAYOUT-ZEBRA = 'X'.
637 
638 
639   IW_TB_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW.
640   APPEND IW_TB_EXCLUDE TO IT_TB_EXCLUDE.
641   IW_TB_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY.
642   APPEND IW_TB_EXCLUDE TO IT_TB_EXCLUDE.
643   IW_TB_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY_ROW.
644   APPEND IW_TB_EXCLUDE TO IT_TB_EXCLUDE.
645   IW_TB_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_CUT.
646   APPEND IW_TB_EXCLUDE TO IT_TB_EXCLUDE.
647   IW_TB_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW.
648   APPEND IW_TB_EXCLUDE TO IT_TB_EXCLUDE.
649   IW_TB_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW.
650   APPEND IW_TB_EXCLUDE TO IT_TB_EXCLUDE.
651   IW_TB_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_MOVE_ROW.
652   APPEND IW_TB_EXCLUDE TO IT_TB_EXCLUDE.
653   IW_TB_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE.
654   APPEND IW_TB_EXCLUDE TO IT_TB_EXCLUDE.
655   IW_TB_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE_NEW_ROW.
656   APPEND IW_TB_EXCLUDE TO IT_TB_EXCLUDE.
657   IW_TB_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_UNDO.
658   APPEND IW_TB_EXCLUDE TO IT_TB_EXCLUDE.
659 
660   CALL METHOD WA_ALVG->SET_TABLE_FOR_FIRST_DISPLAY
661     EXPORTING
662 *      I_BUFFER_ACTIVE               =
663 *      I_BYPASSING_BUFFER            =
664 *      I_CONSISTENCY_CHECK           =
665 *      I_STRUCTURE_NAME              =
666 *      IS_VARIANT                    =
667 *      I_SAVE                        =
668 *      I_DEFAULT                     = 'X'
669       IS_LAYOUT                     = GS_LAYOUT
670 *      IS_PRINT                      =
671 *      IT_SPECIAL_GROUPS             =
672       IT_TOOLBAR_EXCLUDING          = IT_TB_EXCLUDE
673 *      IT_HYPERLINK                  =
674 *      IT_ALV_GRAPHICS               =
675 *      IT_EXCEPT_QINFO               =
676 *      IR_SALV_ADAPTER               =
677     CHANGING
678       IT_OUTTAB                     = IT_VBAP
679       IT_FIELDCATALOG               = GT_FIELDCAT
680 *      IT_SORT                       =
681 *      IT_FILTER                     =
682 *    EXCEPTIONS
683 *      INVALID_PARAMETER_COMBINATION = 1
684 *      PROGRAM_ERROR                 = 2
685 *      TOO_MANY_LINES                = 3
686 *      others                        = 4
687           .
688 IF SY-SUBRC <> 0.
689 * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
690 *            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
691 ENDIF.
692 
693 ENDFORM.                    " FRM_SET_ALVTB
694 *&---------------------------------------------------------------------*
695 *&      Form  FRM_DETAILS
696 *&---------------------------------------------------------------------*
697 *       text
698 *----------------------------------------------------------------------*
699 *      -->P_LT_ROWS  text
700 *----------------------------------------------------------------------*
701 FORM FRM_DETAILS  TABLES   P_LT_ROWS STRUCTURE LVC_S_ROW.
702   "插入正确名称 <...>.
703   DATA: L_INDEX TYPE LVC_INDEX.
704   DATA: IW_V1 LIKE LINE OF IT_VBAP.
705 
706   READ TABLE P_LT_ROWS INDEX 1.
707   IF SY-SUBRC = 0.
708     L_INDEX = P_LT_ROWS-INDEX.
709     CLEAR IW_V1.
710     READ TABLE IT_VBAP INDEX L_INDEX INTO IW_V1.
711 
712     SET PARAMETER ID: 'AUN' FIELD IW_V1-VBELN.
713 
714     CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
715   ENDIF.
716 ENDFORM.                    " FRM_DETAILS
717 *&---------------------------------------------------------------------*
718 *&      Form  FRM_HOTSPOT
719 *&---------------------------------------------------------------------*
720 *       text
721 *----------------------------------------------------------------------*
722 *      -->P_E_ROW_ID  text
723 *----------------------------------------------------------------------*
724 FORM FRM_HOTSPOT  USING    P_E_ROW_ID.
725   DATA: L_INDEX TYPE LVC_INDEX.
726   DATA: IW_V1 LIKE LINE OF IT_VBAP.
727   L_INDEX = P_E_ROW_ID.
728   CLEAR IW_V1.
729   READ TABLE IT_VBAP INDEX L_INDEX INTO IW_V1.
730 
731   SET PARAMETER ID: 'AUN' FIELD IW_V1-VBELN.
732 
733   CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
734 
735 ENDFORM.                    " FRM_HOTSPOT
736 *&---------------------------------------------------------------------*
737 *&      Form  FRM_DBLCLICK
738 *&---------------------------------------------------------------------*
739 *       text
740 *----------------------------------------------------------------------*
741 *      -->P_ROW_ID  text
742 *----------------------------------------------------------------------*
743 FORM FRM_DBLCLICK  USING P_E_ROW.
744   DATA: L_INDEX TYPE LVC_INDEX.
745   DATA: IW_V2 LIKE LINE OF IT_VBAP.
746   L_INDEX = P_E_ROW.
747   CLEAR IW_V2.
748   READ TABLE IT_VBAP INDEX L_INDEX INTO IW_V2.
749 
750   SET PARAMETER ID: 'AUN' FIELD IW_V2-VBELN.
751 
752   CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
753 ENDFORM.                    " FRM_DBLCLICK