ALV报表开发的模板
- 定义所使用的表
TABLES:MSEG,MKPF.
- 声明类型池
TYPE-POOLS: SLIS.
- 声明结构
DATA:BEGIN OF WA,
MBLNR LIKE MSEG-MBLNR,
BLART LIKE MKPF-BLART,
BUDAT LIKE MKPF-BUDAT,
MATNR LIKE MSEG-MATNR,
END OF WA.
- 声明内表
DATA:ITAB LIKE WA OCCURS 0 WITH HEADER LINE.
- ALV显示变量
DATA:GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
FIELDCATALOG LIKE GT_FIELDCAT,
G_REPID LIKE SY-REPID.
- 定义选择屏幕
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS P_WERKS LIKE MSEG-WERKS OBLIGATORY DEFAULT '1000'.
SELECT-OPTIONS:S_MBLNR FOR MSEG-MBLNR,
S_MATNR FOR MSEG-MATNR.
SELECTION-SCREEN END OF BLOCK B1.
- 执行主程度
START-OF-SELECTION.
PERFORM FRM_GET_DATA.
PERFORM FRM_DIS_DATA.
END-OF-SELECTION.
8.定义相关取数,显示数据的子程序
FORM FRM_DIS_DATA.
……
ENDFORM.
FORM FRM_DIS_DATA.
……
ENDFORM.
*---实际例子
*&---------------------------------------------------------------------*
*& REPORT YTEST30
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZKEVEN_CUSTLIST.
TABLES:MSEG,MKPF.
*-----------------------------------声明类型池----------
TYPE-POOLS: SLIS.
*----------------------------数据显示内容------------------
"声明结构
DATA:BEGIN OF WA,
MBLNR LIKE MSEG-MBLNR,
BLART LIKE MKPF-BLART,
BUDAT LIKE MKPF-BUDAT,
MATNR LIKE MSEG-MATNR,
END OF WA.
"声明内表
DATA:ITAB LIKE WA OCCURS 0 WITH HEADER LINE.
*-------------------ALV显示变量----------------------
DATA:GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
FIELDCATALOG LIKE GT_FIELDCAT,
G_REPID LIKE SY-REPID.
*-------------------选择屏幕----------------------
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS P_WERKS LIKE MSEG-WERKS OBLIGATORY DEFAULT '1000'.
SELECT-OPTIONS:S_MBLNR FOR MSEG-MBLNR,
S_MATNR FOR MSEG-MATNR.
SELECTION-SCREEN END OF BLOCK B1.
START-OF-SELECTION.
PERFORM FRM_GET_DATA.
PERFORM FRM_DIS_DATA.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& FORM FRM_GET_DATA
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM FRM_GET_DATA .
SELECT MKPF~BLART
MKPF~BUDAT
MSEG~MBLNR
MSEG~MATNR
INTO CORRESPONDING FIELDS OF TABLE ITAB FROM MKPF INNER JOIN MSEG ON MKPF~MANDT = MSEG~MANDT
AND MKPF~MBLNR = MSEG~MBLNR
AND MKPF~MJAHR = MSEG~MJAHR
WHERE MSEG~WERKS = P_WERKS
AND MSEG~MBLNR IN S_MBLNR
AND MSEG~MATNR IN S_MATNR.
ENDFORM. " FRM_GET_DATA
FORM FRM_DIS_DATA.
PERFORM FRM_BUILD_FIELD.
GS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
GS_LAYOUT-INFO_FIELDNAME = 'LINE_COL'.
GS_LAYOUT-ZEBRA = 'X'.
GS_LAYOUT-HEADER_TEXT = 'ALV TEST'.
G_REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
IS_LAYOUT = GS_LAYOUT
IT_FIELDCAT = GT_FIELDCAT[]
I_SAVE = 'A'
I_CALLBACK_USER_COMMAND = 'FRM_UCOMM' "实现双击事件
TABLES
T_OUTTAB = ITAB
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.
*----------------------------------------------------------------------*
***INCLUDE YTEST30_FRM_BUILD_FIELDF01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form frm_build_field
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_build_field .
FIELDCATALOG-FIELDNAME = 'MBLNR'.
FIELDCATALOG-SELTEXT_M = '物料凭证'.
FIELDCATALOG-COL_POS = 0.
FIELDCATALOG-KEY = ''.
APPEND FIELDCATALOG TO GT_FIELDCAT.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'BLART'.
FIELDCATALOG-SELTEXT_M = '物料凭证类型'.
FIELDCATALOG-COL_POS = 1.
FIELDCATALOG-KEY = ''.
APPEND FIELDCATALOG TO GT_FIELDCAT.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'BUDAT'.
FIELDCATALOG-SELTEXT_M = '过帐日期'.
FIELDCATALOG-COL_POS = 2.
FIELDCATALOG-KEY = ''.
APPEND FIELDCATALOG TO GT_FIELDCAT.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'MATNR'.
FIELDCATALOG-SELTEXT_M = '物料号'.
FIELDCATALOG-COL_POS = 3.
FIELDCATALOG-REF_TABNAME = 'MSEG'.
APPEND FIELDCATALOG TO GT_FIELDCAT.
CLEAR FIELDCATALOG.
ENDFORM. " frm_build_field
FORM FRM_UCOMM USING F_UCOMM LIKE SY-UCOMM"双击
F_SELFIELD TYPE SLIS_SELFIELD."行数
READ TABLE ITAB INDEX F_SELFIELD-TABINDEX.
IF F_UCOMM = '&IC1'."双击
IF F_SELFIELD-FIELDNAME = 'MATNR'.
SET PARAMETER ID 'MAT' FIELD F_SELFIELD-VALUE .
set parameter id 'MM5' field ' '.
set parameter id 'MXX' field 'K'.
CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN."跳过第一个屏幕
ENDIF.
ENDIF.
ENDFORM.