销售\请款订单范例
REPORT Y001.
TABLES:BKPF,"会计文件表头
VBRK,"请款文件:表头资料
VBAK."销售文件:表头资料
DATA:BEGIN OF ITAB OCCURS 0,
BUKRS LIKE BKPF-BUKRS, "公司代码
BELNR LIKE BKPF-BELNR, "会计文件号码
GJAHR LIKE BKPF-GJAHR, "会计年度
BUDAT LIKE BKPF-BUDAT, "过账日期
BLDAT LIKE BKPF-BLDAT, "文件日期
XBLNR LIKE BKPF-XBLNR, "参考文件号码
VBELN LIKE VBRK-VBELN, "请款文件(发票号码)
KUNRG LIKE VBRK-KUNRG, "请款人(客户代码)
VKORG LIKE VBRK-VKORG, "销售组织
VTWEG LIKE VBRK-VTWEG, "配销通路
NAME1 TYPE KNA1-NAME1, "客户名称
AUBEL LIKE VBRP-AUBEL, "销售文件
BSTKD LIKE VBKD-BSTKD, "客户采购单号码
BSTNK LIKE VBAK-BSTNK, "客户采购单号码
NETWR LIKE VBRK-NETWR, "净价值
WAERK LIKE VBRK-WAERK, "SD文件币别
SELFI,
END OF ITAB.
*&--------------------画屏区域-----------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK FRAME1 WITH FRAME TITLE TEXT-000 .
SELECT-OPTIONS: R_BUKRS FOR BKPF-BUKRS, "OBLIGATORY DEFAULT '1010', "公司代码
R_VKORG FOR VBRK-VKORG,
R_VTWEG FOR VBRK-VTWEG,
R_BUDAT FOR BKPF-BUDAT.
SELECTION-SCREEN END OF BLOCK FRAME1.
*&-------------------------程序主区域-------------------------------------*
AT SELECTION-SCREEN OUTPUT."用户操作后屏幕输出事件
AT SELECTION-SCREEN. "用户回车或单击后发生事件,不考滤屏幕输出
START-OF-SELECTION. "正式程序运行到输出结果事件
PERFORM GET_DATA. "取数据
PERFORM REPORT_DATA."显示数据
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM GET_DATA.
SELECT A~BUKRS A~BELNR A~GJAHR A~BUDAT A~BLDAT
A~XBLNR B~VBELN B~VKORG B~VTWEG B~KUNRG B~NETWR B~WAERK
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM BKPF AS A JOIN VBRK AS B ON A~XBLNR = B~VBELN
WHERE A~BUKRS IN R_BUKRS
AND B~VKORG IN R_VKORG
AND B~VTWEG IN R_VTWEG
AND A~BUDAT IN R_BUDAT.
LOOP AT ITAB.
SELECT SINGLE AUBEL INTO ITAB-AUBEL FROM VBRP WHERE VBELN = ITAB-VBELN."取销售订单号
SELECT SINGLE BSTNK INTO ITAB-BSTNK FROM VBAK WHERE VBELN = ITAB-AUBEL."通过销售订单号取PO号
SELECT SINGLE NAME1 INTO ITAB-NAME1 FROM KNA1 WHERE KUNNR = ITAB-KUNRG.
MODIFY ITAB.
ENDLOOP.
ENDFORM. "GET_DATA
*&---------------------ALV变量声明区域---------------------------------*
TYPE-POOLS:SLIS.
DATA: FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
DATA: LAYOUT TYPE SLIS_LAYOUT_ALV .
DATA: S_VARIANT LIKE DISVARIANT.
*&-------------------------ALV数据展示区域----------------------------------*
FORM REPORT_DATA .
* 设置要显示的字段列表
PERFORM SET_FIELDCAT.
* 给表格布局参数赋值
LAYOUT-GET_SELINFOS = 'X'.
LAYOUT-COLWIDTH_OPTIMIZE = 'X'. "列宽度自动根据内容优化
LAYOUT-DETAIL_POPUP = 'X'.
LAYOUT-NO_KEYFIX = 'X'.
LAYOUT-BOX_FIELDNAME = 'SELFI'.
S_VARIANT-REPORT = SY-REPID.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' "REUSE_ALV_LIST_DISPLAY
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID "当前的程序名
IS_LAYOUT = LAYOUT "表格样式 布局
IT_FIELDCAT = FIELDCAT[] "要显示的列名,必填
I_SAVE = 'A'
IS_VARIANT = S_VARIANT
TABLES
T_OUTTAB = ITAB "ALV数据输出使用的内表 必填
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM. " ALV_REPORT_DATA
*&---------------------------------------------------------------------*
FORM SET_FIELDCAT .
REFRESH FIELDCAT.
PERFORM INPUT_FIELDCAT USING 'BLDAT' '文件日期' '' '' '' '' ''.
PERFORM INPUT_FIELDCAT USING 'BELNR' '会计文件号码' '' '' '' '' ''.
PERFORM INPUT_FIELDCAT USING 'VBELN' '请款文件' '' '' '' '' ''.
PERFORM INPUT_FIELDCAT USING 'AUBEL' '销售文件' '' '' '' '' ''.
PERFORM INPUT_FIELDCAT USING 'KUNRG' '请款人' '' '' '' '' ''.
PERFORM INPUT_FIELDCAT USING 'NAME1' '客户全称' '' '' '' '' ''.
PERFORM INPUT_FIELDCAT USING 'BSTNK' '客户采购单号码' '' '' '' '' ''.
PERFORM INPUT_FIELDCAT USING 'NETWR' '净价' '' '' '' '' ''.
PERFORM INPUT_FIELDCAT USING 'WAERK' '货币' '' '' '' '' ''.
ENDFORM. " SET_FIELDCAT
*------------------------------------------------------------------------*
FORM INPUT_FIELDCAT USING ZID WENB KEYS GD COLOR REFTAB REFFILE.
ADD 1 TO FIELDCAT-COL_POS.
FIELDCAT-FIELDNAME = ZID. " 对应的内表中的字段名称
FIELDCAT-SELTEXT_M = WENB. "ALV中显示的字段名称
FIELDCAT-KEY = KEYS.
FIELDCAT-FIX_COLUMN = GD .
FIELDCAT-EMPHASIZE = COLOR. "列颜色
FIELDCAT-REF_TABNAME = REFTAB.
FIELDCAT-REF_FIELDNAME = REFFILE.
APPEND FIELDCAT.
CLEAR FIELDCAT.
ENDFORM. "INPUT_FIELDCAT
*&---------------------------------------------------------------------*
*& FORM SET_PF_STATUS
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* -->T_EXTAB TEXT
*----------------------------------------------------------------------*
FORM SET_PF_STATUS USING T_EXTAB TYPE SLIS_T_EXTAB.
DATA: S_EXTAB TYPE SLIS_EXTAB. "要被排除的按钮的列表
SET PF-STATUS 'STANDARD_FULLSCREEN' EXCLUDING T_EXTAB.
ENDFORM. " SET_PF_STATUS