*&---------------------------------------------------------------------*
*& Report Z_TEST
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z_TEST.
TYPE-POOLS:SLIS.
TABLES:VBAP,SSCRFIELDS.
DATA:GT_FIELDCAT TYPE LVC_T_FCAT.
*----------------------------------------------------------------------*
* 内表和工作区定义
*----------------------------------------------------------------------*
TYPES:BEGIN OF TY_ALV,
VBELN TYPE VBAP-VBELN,
POSNR TYPE VBAP-POSNR,
MATNR TYPE VBAP-MATNR,
CHARG TYPE VBAP-CHARG,
NETWR TYPE VBAP-NETWR,
KWMENG TYPE VBAP-KWMENG,
END OF TY_ALV.
DATA:GT_ALV TYPE TABLE OF TY_ALV,
WA_ALV TYPE TY_ALV.
*----------------------------------------------------------------------*
* 选择屏幕
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS:
S_VBELN FOR VBAP-VBELN. "订单号
SELECTION-SCREEN END OF BLOCK B1.
*----------------------------------------------------------------------*
* Initialization
*----------------------------------------------------------------------*
INITIALIZATION.
*----------------------------------------------------------------------*
* at selection screen
*----------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
AT SELECTION-SCREEN.
*----------------------------------------------------------------------*
* Event top of page
*----------------------------------------------------------------------*
TOP-OF-PAGE.
*----------------------------------------------------------------------*
* event Start of Selection
*----------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM FRM_GET_DATA.
PERFORM FRM_DISPLAY_ALV.
*----------------------------------------------------------------------*
*EVENT End-of selection
*----------------------------------------------------------------------*
END-OF-SELECTION.
*----------------------------------------------------------------------*
*EVENT End-of page
*----------------------------------------------------------------------*
END-OF-PAGE.
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
** forms
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_AUTHORITY
*&---------------------------------------------------------------------*
* " 检查权限
*----------------------------------------------------------------------*
FORM FRM_CHECK_AUTHORITY.
ENDFORM.
*----------------------------------------------------------------------*
** forms
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_DISPLAY_ALV
*&---------------------------------------------------------------------*
*& 显示ALV
*&---------------------------------------------------------------------*
FORM FRM_DISPLAY_ALV .
DATA:LS_LAYOUT TYPE LVC_S_LAYO.
LS_LAYOUT-ZEBRA = 'X'.
LS_LAYOUT-CWIDTH_OPT = 'X'.
LS_LAYOUT-SEL_MODE = 'D'.
PERFORM FRM_SET_FIELD USING 'VBELN' '销售订单号'.
PERFORM FRM_SET_FIELD USING 'POSNR' '行号'.
PERFORM FRM_SET_FIELD USING 'MATNR' '产品编码'.
PERFORM FRM_SET_FIELD USING 'CHARG' '批次'.
PERFORM FRM_SET_FIELD USING 'NETWR' '净值'.
PERFORM FRM_SET_FIELD USING 'KWMENG' '订单数量'.
SORT GT_ALV BY VBELN.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT_LVC = LS_LAYOUT
IT_FIELDCAT_LVC = GT_FIELDCAT[]
I_SAVE = 'U'
TABLES
T_OUTTAB = GT_ALV
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.
*&---------------------------------------------------------------------*
*& Form frm_set_field
*&---------------------------------------------------------------------*
*& 设置fieldcate
*&---------------------------------------------------------------------*
* -->i_fieldname 字段名
* -->i_seltext 文本
*&---------------------------------------------------------------------*
FORM FRM_SET_FIELD USING I_FIELDNAME
I_SELTEXT.
DATA:LS_FIELDCAT TYPE LVC_S_FCAT.
CLEAR:LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = I_FIELDNAME.
LS_FIELDCAT-SCRTEXT_L = I_SELTEXT.
LS_FIELDCAT-SCRTEXT_S = I_SELTEXT.
LS_FIELDCAT-SCRTEXT_M = I_SELTEXT.
APPEND LS_FIELDCAT TO GT_FIELDCAT .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_GET_DATA .
SELECT
VBAP~VBELN
VBAP~POSNR
VBAP~KWMENG
VBAP~MATNR
VBAP~NETWR
VBAP~CHARG
INTO CORRESPONDING FIELDS OF TABLE GT_ALV
FROM VBAP
WHERE VBAP~VBELN IN S_VBELN.
"整理数据
SORT: GT_ALV BY VBELN POSNR.
ENDFORM.
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/19548.html