ALV表格数据双击事件这个功能,财务部门的人需要的REPORT,大多都需要这个功能。
我从《SAP工程师突击》抄下这段代码来,运行调试通过。
效果如下图:
代码如下:
REPORT ZR_EXAMPLE_16.
TABLES:MARA.
TYPE-POOLS: SLIS.
SELECT-OPTIONS:MATNR FOR MARA-MATNR OBLIGATORY.
DATA:LT_MARA TYPE TABLE OF MARA WITH HEADER LINE,
FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
LAYOUT TYPE SLIS_LAYOUT_ALV,
W_REPID LIKE SY-REPID.
START-OF-SELECTION.
SELECT * FROM MARA INTO TABLE LT_MARA
WHERE MATNR IN MATNR.
W_REPID = SY-REPID.
* 定义热键显示字段,使双击事件有效
FIELDCAT-REF_TABNAME = 'LT_MARA'.
FIELDCAT-FIELDNAME = 'MATNR'.
FIELDCAT-HOTSPOT = 'X'.
APPEND FIELDCAT.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = W_REPID "定义回执程序
IS_LAYOUT = LAYOUT
I_STRUCTURE_NAME = 'MARA'
I_CALLBACK_USER_COMMAND = 'ALV_USER_COMMAND' "定义执行事件
IT_FIELDCAT = FIELDCAT[]
TABLES
T_OUTTAB = LT_MARA.
*---------------------------------------------------------------------*
* 事件触发子程序 *
*---------------------------------------------------------------------*
FORM ALV_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE R_UCOMM.
WHEN '&IC1'.
* 获取当前ALV所在行数据
READ TABLE LT_MARA INDEX RS_SELFIELD-TABINDEX.
SET PARAMETER ID: 'MAT' FIELD LT_MARA-MATNR.
CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
ENDCASE.
ENDFORM.