*&----------------------------------------------------------------------*
REPORT ZZ_CGBB_01.
*声明表
TABLES: EKKO,
EKPO,
KONV,
MSEG,
MKPF.
*内表声明
DATA:
"表名
BEGIN OF GIT_EKKO OCCURS 0,
EBELN TYPE EKKO-EBELN, "采购凭证号
BUKRS TYPE EKKO-BUKRS, "公司代码
BSART TYPE EKKO-BSART, "采购凭证类型
KNUMV TYPE EKKO-KNUMV, "单据条件数
END OF GIT_EKKO,
BEGIN OF GIT_EKPO OCCURS 0,
EBELN TYPE EKPO-EBELN, "采购凭证号
EBELP TYPE EKPO-EBELP, "采购凭证的项目编号
EMATN TYPE EKPO-EMATN, "物料号
BUKRS TYPE EKPO-BUKRS, "公司代码
TXZ01 TYPE EKPO-TXZ01, "短文本
END OF GIT_EKPO,
BEGIN OF GIT_KONV OCCURS 0,
KNUMV TYPE KONV-KNUMV, "单据条件数
KPOSN TYPE KONV-KPOSN, "条件项目号
STUNR TYPE KONV-STUNR, "步骤编号
ZAEHK TYPE KONV-ZAEHK, "条件计数器
KSCHL TYPE KONV-KSCHL, "条件类型
KBETR TYPE KONV-KBETR, "价格
END OF GIT_KONV,
BEGIN OF GIT_MSEG OCCURS 0,
MBLNR TYPE MSEG-MBLNR, "物料凭证编号
MJAHR TYPE MSEG-MJAHR, "物料凭证年度
ZEILE TYPE MSEG-ZEILE, "物料凭证中的项目
MENGE TYPE MSEG-MENGE, "数量
MEINS TYPE MSEG-MEINS, "基本计量单位
EBELN TYPE MSEG-EBELN, "采购凭证号
EBELP TYPE MSEG-EBELP, "采购凭证的项目编号
END OF GIT_MSEG,
BEGIN OF GIT_MKPF OCCURS 0,
MBLNR TYPE MKPF-MBLNR, "物料凭证编号
MJAHR TYPE MKPF-MJAHR, "物料凭证年度
BUDAT TYPE MKPF-BUDAT, "凭证中的过帐日期
END OF GIT_MKPF,
BEGIN OF GIT_RESULT OCCURS 0,
EBELN TYPE EKKO-EBELN, "采购凭证号
EBELP TYPE EKPO-EBELP, "采购凭证的项目编号
BSART TYPE EKKO-BSART, "采购凭证类型
EMATN TYPE EKPO-EMATN, "物料号
TXZ01 TYPE EKPO-TXZ01, "短文本
BUDAT TYPE MKPF-BUDAT, "凭证中的过帐日期
MENGE TYPE MSEG-MENGE, "数量
MEINS TYPE MSEG-MEINS, "基本计量单位
JIAGE01 TYPE MSEG-MENGE, "PB00价格
JINE01 TYPE MSEG-MEINS, "PB00金额
JIAGE02 TYPE MSEG-MENGE, "折扣
JINE02 TYPE MSEG-MEINS, "折扣金额
END OF GIT_RESULT.
*变量申明
*RANGES: r_hkont FOR bseg-hkont. "G/L Account
*常量申明
*CONSTANTS:
*c_awtyp_vbrr TYPE bkpf-awtyp VALUE 'VBRR', "Refer. Transaction
TYPE-POOLS: slis. "引用ALV显示功能所需要的类型库
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv, "参考slis类型库中的t_fieldcat_alv定义变量。
prg LIKE sy-repid.
*选择屏幕申明
************************************************************************
* 选择屏幕申明 *
************************************************************************
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS:
s_BUKRS for EKKO-BUKRS OBLIGATORY, "Company code
s_BUDAT FOR MKPF-BUDAT,
s_EBELN FOR EKKO-EBELN,
s_BSART FOR EKKO-BSART,
s_EMATN FOR EKPO-EMATN.
SELECTION-SCREEN: END OF BLOCK b1.
*主程序
************************************************************************
* Start of selection *
************************************************************************
START-OF-SELECTION.
* Main process
PERFORM frm_main_process.
*&---------------------------------------------------------------------*
*& Form frm_main_process
*&---------------------------------------------------------------------*
* main process
*----------------------------------------------------------------------*
FORM frm_main_process .
* 取数
PERFORM frm_get_data.
* 整合数据
PERFORM frm_merge_data.
* 显示数据
PERFORM frm_display_data.
ENDFORM. " frm_main_process
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_GET_DATA .
SELECT
EBELN "采购凭证号
BUKRS ""公司代码
BSART "采购凭证类型
KNUMV "单据条件数
INTO CORRESPONDING FIELDS OF TABLE GIT_EKKO
FROM EKKO
WHERE EBELN IN S_EBELN "采购凭证号
AND BUKRS IN S_BUKRS "公司代码
AND BSART IN S_BSART. "采购凭证类型 屏幕选择里有的用in
IF GIT_EKKO[] IS NOT INITIAL.
SELECT
EBELN "采购凭证号
EBELP "采购凭证的项目编号
EMATN "物料号
TXZ01 "短文本
INTO CORRESPONDING FIELDS OF TABLE GIT_EKPO
FROM EKPO
FOR ALL ENTRIES IN GIT_EKKO
WHERE EMATN IN S_EMATN
AND EBELN = GIT_EKKO-EBELN.
IF GIT_EKPO[] IS NOT INITIAL.
SELECT
MBLNR "物料凭证编号
MJAHR "物料凭证年度
ZEILE "物料凭证中的项目
MENGE "数量
MEINS "基本计量单位
EBELN "采购凭证号
EBELP "采购凭证的项目编号
INTO CORRESPONDING FIELDS OF TABLE GIT_MSEG
FROM MSEG
FOR ALL ENTRIES IN GIT_EKPO
WHERE EBELP = GIT_EKPO-EBELP
AND EBELN = GIT_EKPO-EBELN.
IF GIT_EKPO[] IS NOT INITIAL.
SELECT
MBLNR "物料凭证编号
MJAHR "物料凭证年度
BUDAT "凭证中的过帐日期
INTO CORRESPONDING FIELDS OF TABLE GIT_MKPF
FROM MKPF
FOR ALL ENTRIES IN GIT_MSEG
WHERE MBLNR = GIT_MSEG-MBLNR
AND MJAHR = GIT_MSEG-MJAHR
and BUDAT in s_BUDAT.
endif.
endif.
endif.
IF GIT_EKKO[] IS NOT INITIAL.
SELECT
KNUMV "单据条件数
KPOSN "条件项目号
STUNR "步骤编号
ZAEHK "条件计数器
KSCHL "条件类型
KBETR "价格
INTO CORRESPONDING FIELDS OF TABLE GIT_KONV
FROM KONV
FOR ALL ENTRIES IN GIT_EKKO
WHERE KNUMV = GIT_EKKO-KNUMV
AND ( KSCHL = 'PB00' OR KSCHL = 'SKTO' ).
endif.
ENDFORM. " FRM_GET_DATA
*&---------------------------------------------------------------------*
*& Form FRM_MERGE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_MERGE_DATA .
SORT GIT_MKPF BY MBLNR MJAHR.
SORT GIT_EKPO BY EBELN EBELP.
SORT GIT_EKKO BY EBELN.
SORT GIT_KONV BY KNUMV.
LOOP AT GIT_MSEG INTO GIT_MSEG.
READ TABLE GIT_MKPF INTO GIT_MKPF
WITH KEY MBLNR = GIT_MSEG-MBLNR
MJAHR = GIT_MSEG-MJAHR
BINARY SEARCH.
IF SY-SUBRC = 0.
GIT_RESULT-EBELN = GIT_MSEG-EBELN. "采购凭证号
GIT_RESULT-EBELP = GIT_MSEG-EBELP. "采购凭证的项目编号
GIT_RESULT-BUDAT = GIT_MKPF-BUDAT. "凭证中的过帐日期
GIT_RESULT-MENGE = GIT_MSEG-MENGE. "数量
GIT_RESULT-MEINS = GIT_MSEG-MEINS. "基本计量单位
READ TABLE GIT_EKPO INTO GIT_EKPO
WITH KEY EBELN = GIT_MSEG-EBELN
EBELP = GIT_MSEG-EBELP
BINARY SEARCH.
IF SY-SUBRC = 0.
GIT_RESULT-TXZ01 = GIT_EKPO-TXZ01. "短文本
GIT_RESULT-EMATN = GIT_EKPO-EMATN. "物料号
READ TABLE GIT_EKKO INTO GIT_EKKO
WITH KEY EBELN = GIT_EKPO-EBELN
BINARY SEARCH.
IF SY-SUBRC = 0.
GIT_RESULT-BSART = GIT_EKKO-BSART. "采购凭证类型
READ TABLE GIT_KONV INTO GIT_KONV
WITH KEY KNUMV = GIT_EKKO-KNUMV
KSCHL = 'PB00'
BINARY SEARCH.
IF SY-SUBRC = 0.
GIT_RESULT-JIAGE01 = GIT_KONV-KBETR. "PB00价格
GIT_RESULT-JINE01 = GIT_KONV-KBETR * GIT_RESULT-MENGE. "PB00金额
clear GIT_KONV.
endif.
READ TABLE GIT_KONV INTO GIT_KONV
WITH KEY KNUMV = GIT_EKKO-KNUMV
KSCHL = 'SKTO'
BINARY SEARCH.
IF SY-SUBRC = 0.
GIT_RESULT-JIAGE01 = GIT_KONV-KBETR. "PB00价格
GIT_RESULT-JINE01 = GIT_KONV-KBETR * GIT_RESULT-MENGE. "PB00金额
clear GIT_KONV.
endif.
clear GIT_EKKO.
endif.
clear GIT_EKPO.
endif.
append git_result to git_result.
clear git_result.
clear GIT_MKPF.
endif.
clear git_mseg.
endLOOP.
ENDFORM. " FRM_MERGE_DATA
*&---------------------------------------------------------------------*
*& Form FRM_DISPLAY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_DISPLAY_DATA .
DATA gs_fieldcat LIKE LINE OF gt_fieldcat.
DEFINE fc.
gs_fieldcat-fieldname = &1.
if not &2 is initial.
gs_fieldcat-ref_tabname = &2.
gs_fieldcat-ref_fieldname = &3.
else.
gs_fieldcat-outputlen = &4.
gs_fieldcat-seltext_l = &5.
endif.
gs_fieldcat-lzero = &6.
append gs_fieldcat to gt_fieldcat.
clear gs_fieldcat.
END-OF-DEFINITION.
FC 'EBELN' '' '' '30' '采购凭证号' ''.
FC 'EBELP' '' '' '30' '采购凭证的项目编号' ''.
FC 'BSART' '' '' '30' '采购凭证类型' ''.
FC 'EMATN' '' '' '30' '物料号' ''.
FC 'TXZ01' '' '' '30' '短文本' ''.
FC 'BUDAT' '' '' '30' '凭证中的过帐日期' ''.
FC 'MENGE' '' '' '30' '数量' ''.
FC 'MEINS' '' '' '30' '基本计量单位' ''.
FC 'JIAGE01' '' '' '30' 'PB00价格' ''.
FC 'JINE01' '' '' '30' 'PB00金额' ''.
FC 'JIAGE02' '' '' '30' '折扣' ''.
FC 'JINE02' '' '' '30' '折扣金额' ''.
prg = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = prg
it_fieldcat = gt_fieldcat
* is_layout = ls_layout
* i_save = 'A'
TABLES
t_outtab = git_result.
ENDFORM. " FRM_DISPLAY_DATA
SAP abap采购报表开发
于 2022-02-17 16:04:31 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)