*&---------------------------------------------------------------------*
*& Report ZFIR093
*&---------------------------------------------------------------------*
*& Author : NathanSun
*& Create Date : 2018-11-06
*& Program Type : Report
*& Description : 关联方交易查询表-三单
*&---------------------------------------------------------------------*
REPORT ZFIR096.
*&---------------------------------------------------------------------*
*& 包含 ZFIR092_TOP
*&---------------------------------------------------------------------*
TABLES:VBAP,MSEG,BKPF,TVKO.
TYPE-POOLS:SLIS.
"定义ALV输出所需变量
DATA: S_LAYOUT TYPE SLIS_LAYOUT_ALV,
GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
TYPES: BEGIN OF GTS_DATA,
*SO2
VLFAG TYPE C, "标记字段
VKORG_SO2 TYPE TVKO-VKORG, "销售组织
VTEXT_SO2 TYPE TVKOT-VTEXT, "销售组织描述
KUNNR_SO2 TYPE VBAK-KUNNR, "SO2付款方
NAME1_SO2 TYPE KNA1-NAME1, "付款方名称
MATNR_SO2 TYPE VBAP-MATNR, "物料号
ARKTX_SO2 TYPE VBAP-ARKTX, "物料号描述
VBELN_SO2 TYPE VBAP-VBELN, "SO2销售订单
POSNR_SO2 TYPE VBAP-POSNR, "SO2行项目号
KLMENG_SO2 TYPE VBAP-KLMENG, "SO2订单数量
NETPR_SO2 TYPE VBAP-NETPR, "SO2销售单价
MEINS_SO2 TYPE VBAP-MEINS, "基本计量单位
VBELN_IM_SO2 TYPE MSEG-VBELN_IM, "SO2交货单
VBELP_IM_SO2 TYPE MSEG-VBELP_IM, "SO2行项目
BUDAT_MKPF_SO2 TYPE MSEG-BUDAT_MKPF, "SO2交货日期
MENDQ_DN_SO2 TYPE MSEG-MENGE, "SO2交货单当期交货数
NETDQ_SO2 TYPE VBAP-NETPR, "SO2交货单当期销售金额
MENLJ_DN_SO2 TYPE MSEG-MENGE, "SO2交货单累计数量
NETLJ_SO2 TYPE VBAP-NETPR, "SO2交货单累计金额
FKDAT_SO2 TYPE VBRK-FKDAT, "SO2开票日期
MENDQ_VF_SO2 TYPE VBRP-FKLMG, "SO2当期开票数量
DMBDQ_SO2 TYPE VBRP-NETWR, "SO2当期开票金额-未税
MENLJ_VF_SO2 TYPE VBRP-FKLMG, "SO2累计开票数量
DMBLJ_SO2 TYPE VBRP-NETWR, "SO2累计开票金额-未税 SHKZG
MBLNR_SO2 TYPE MSEG-MBLNR, "物料凭证编号
MJAHR_SO2 TYPE MSEG-MJAHR, "物料凭证年度
ZEILE_SO2 TYPE MSEG-ZEILE, "物料凭证中的项目
SHKZG_SO2 TYPE MSEG-SHKZG, "借方/贷方标识
VBELN_VF_SO2 TYPE VBRP-VBELN, "开票凭证
POSNR_VF_SO2 TYPE VBRP-POSNR, "开票项目
SHKZG_VF_SO2 TYPE VBRP-SHKZG, "退货项目
UMVKN_VF_SO2 TYPE VBRP-UMVKN, "销售数量转换为 SKU 的值(除数)
UMVKZ_VF_SO2 TYPE VBRP-UMVKZ, "销售数量转换成SKU的分子(因子)
KPEIN_SO2 TYPE VBAP-KPEIN, "SO2条件定价单位
UMZIN_SO2 TYPE VBAP-UMZIN, "用于将销售单位转换成基本单位的因子(目标数量)
UMZIZ_SO2 TYPE VBAP-UMZIZ, "用于将销售单位转换成基本单位的因子(目标数量)
*PO
EBELN_PO TYPE ZPO_CREATE_HIS-EBELN, "采购凭证
EBELP_PO TYPE ZPO_CREATE_HIS-EBELP, "采购凭证的项目编号
MENGE_PO TYPE EKPO-MENGE, "PO数量
UMREZ_PO TYPE EKPO-UMREZ, "有关订货价格单位转换为基本单位的分子
UMREN_PO TYPE EKPO-UMREN, "订单单位到基本单位转换的分母
MENDQ_PO TYPE MSEG-MENGE, "P0当期收货数量
DMBDQ_PO TYPE MSEG-DMBTR, "P0当期收货金额
MENLJ_PO TYPE MSEG-MENGE, "PO累计收货数量
DMBLJ_PO TYPE MSEG-DMBTR, "P0累计收货金额
SHKZG_PO TYPE MSEG-SHKZG, "借方/贷方标识
BUDAT_MKPF_PO TYPE MSEG-BUDAT_MKPF, "PO过帐日期
*SO1
VBELN_SO1 TYPE VBAP-VBELN, "SO1销售订单
POSNR_SO1 TYPE VBAP-POSNR, "SO1行项目
KUNNR_SO1 TYPE VBAK-KUNNR, "SO1客户
NAME1_SO1 TYPE KNA1-NAME1, "客户名称
KLMENG_SO1 TYPE VBAP-KLMENG, "SO1订单数量
NETPR_SO1 TYPE VBAP-NETPR, "SO1销售单价
MENDQ_SO1 TYPE MSEG-MENGE, "SO1DN当期数量
NETDQ_SO1 TYPE VBAP-NETPR, "SO1DN当期销售金额
MENLJ_SO1 TYPE MSEG-MENGE, "SO1DN累计数量
NETLJ_SO1 TYPE VBAP-NETPR, "SO1DN累计金额
MENDQ_VF_SO1 TYPE VBRP-FKLMG, "SO1当期开票数量
DMBDQ_VF_SO1 TYPE VBRP-NETWR, "SO1当期开票金额
MENLJ_VF_SO1 TYPE VBRP-FKLMG, "SO1累计开票数量
DMBLJ_VF_SO1 TYPE VBRP-NETWR, "SO1累计开票金额
MBLNR_SO1 TYPE MSEG-MBLNR, "物料凭证编号
MJAHR_SO1 TYPE MSEG-MJAHR, "物料凭证年度
ZEILE_SO1 TYPE MSEG-ZEILE, "物料凭证中的项目
VBELN_IM_SO1 TYPE MSEG-VBELN_IM, "SO1交货单
VBELP_IM_SO1 TYPE MSEG-VBELP_IM, "SO1行项目
BUDAT_DN_SO1 TYPE MSEG-BUDAT_MKPF, "SO1DN日期
SHKZG_SO1 TYPE MSEG-SHKZG, "借方/贷方标识
VBELN_VF_SO1 TYPE VBRP-VBELN, "开票凭证
POSNR_VF_SO1 TYPE VBRP-POSNR, "开票项目
SHKZG_VF_SO1 TYPE VBRP-SHKZG, "退货项目
UMVKN_VF_SO1 TYPE VBRP-UMVKN, "销售数量转换为 SKU 的值(除数)
UMVKZ_VF_SO1 TYPE VBRP-UMVKZ, "销售数量转换成SKU的分子(因子)
KPEIN_SO1 TYPE VBAP-KPEIN, "SO1条件定价单位
UMZIN_SO1 TYPE VBAP-UMZIN, "用于将销售单位转换成基本单位的因子(目标数量)
UMZIZ_SO1 TYPE VBAP-UMZIZ, "用于将销售单位转换成基本单位的因子(目标数量)
FKDAT_SO1 TYPE VBRK-FKDAT, "SO1开票日期
END OF GTS_DATA.
DATA: GT_DATA TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA_DN TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA_VF TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA_SO1 TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA_CO1 TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA_DN1 TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA_VF1 TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA_PO TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA_PC TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GS_DATA TYPE GTS_DATA .
DATA: LV_BUDAT TYPE BUDAT.
DATA: LV_BUDAH TYPE BUDAT.
DATA: LV_BUDAL TYPE BUDAT.
DATA: LV_BUDAF TYPE BUDAT.
DATA: P_GJAHU TYPE GJAHR.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
SELECT-OPTIONS: S_VKORG FOR TVKO-VKORG MODIF ID C1 OBLIGATORY. "公司代码
PARAMETERS: P_GJAHR TYPE GJAHR MODIF ID C1 OBLIGATORY . "会计年度
SELECT-OPTIONS: S_MONAT FOR BKPF-MONAT MODIF ID C1 OBLIGATORY NO-EXTENSION. "期间
SELECTION-SCREEN END OF BLOCK B1.
*&---------------------------------------------------------------------*
*& 包含 ZFIR092_FOM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form SCREEN_OUTPUT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM SCREEN_OUTPUT .
* LOOP AT SCREEN.
* CASE SCREEN-GROUP1.
* WHEN 'M1'.
* SCREEN-INPUT = '0'.
* ENDCASE.
* MODIFY SCREEN.
* ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SCREEN_SETTING
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM SCREEN_SETTING .
* AUTHORITY-CHECK OBJECT 'M_MATE_WRK'
* ID 'WERKS' FIELD P_WERKS.
* IF SY-SUBRC <> 0.
* MESSAGE '您没有工厂:'&& P_WERKS && ' 的权限!' TYPE 'E' .
* ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FOM_GETDATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FOM_GETDATA .
FIELD-SYMBOLS <FS> .
DATA: G_FIELD(40).
DATA: GT_TVKO TYPE TABLE OF TVKO WITH HEADER LINE.
*取所选期间的上/下限
LV_BUDAL = P_GJAHR && S_MONAT-LOW && '01' .
IF S_MONAT-HIGH IS NOT INITIAL.
LV_BUDAH = P_GJAHR && S_MONAT-HIGH && '01' .
ELSE .
LV_BUDAH = P_GJAHR && S_MONAT-LOW && '01' .
ENDIF.
CALL FUNCTION 'BKK_GET_MONTH_LASTDAY'
EXPORTING
I_DATE = LV_BUDAH
IMPORTING
E_DATE = LV_BUDAH
.
* SO1
CLEAR GT_DATA[].
SELECT
ZPO_CREATE_HIS~VBELN AS VBELN_SO1
ZPO_CREATE_HIS~POSNR AS POSNR_SO1
ZPO_CREATE_HIS~VBELN_NEW AS VBELN_SO2
ZPO_CREATE_HIS~POSNR AS POSNR_SO2
ZPO_CREATE_HIS~EBELN AS EBELN_PO
ZPO_CREATE_HIS~EBELP AS EBELP_PO
ZPO_CREATE_HIS~VKORG_NEW AS VKORG_SO2
VBAK~KUNNR AS KUNNR_SO2
VBAP~MATNR AS MATNR_SO2
VBAP~ARKTX AS ARKTX_SO2
VBAP~KLMENG AS KLMENG_SO2
VBAP~NETPR AS NETPR_SO2
VBAP~MEINS AS MEINS_SO2
LIPS~VBELN AS VBELN_IM_SO2
LIPS~POSNR AS VBELP_IM_SO2
INTO CORRESPONDING FIELDS OF TABLE GT_DATA[]
FROM ZPO_CREATE_HIS
INNER JOIN VBAP ON ZPO_CREATE_HIS~VBELN_NEW = VBAP~VBELN AND ZPO_CREATE_HIS~POSNR = VBAP~POSNR
INNER JOIN VBAK ON VBAK~VBELN = VBAP~VBELN
LEFT JOIN LIPS ON LIPS~VGBEL = VBAP~VBELN AND LIPS~VGPOS = VBAP~POSNR
WHERE ZPO_CREATE_HIS~VKORG_NEW IN S_VKORG
* AND ZPO_CREATE_HIS~VBELN_NEW = '0065000008'
.
SORT GT_DATA[] BY VBELN_SO2 POSNR_SO2 VBELN_IM_SO2 VBELP_IM_SO2 .
DELETE ADJACENT DUPLICATES FROM GT_DATA[] COMPARING VBELN_SO2 POSNR_SO2 VBELN_IM_SO2 VBELP_IM_SO2.
IF GT_DATA[] IS NOT INITIAL .
CLEAR GT_DATA_DN[] .
SELECT
MSEG~VBELN_IM AS VBELN_IM_SO2
MSEG~VBELP_IM AS VBELP_IM_SO2
MSEG~MBLNR AS MBLNR_SO2
MSEG~MJAHR AS MJAHR_SO2
MSEG~ZEILE AS ZEILE_SO2
MSEG~BUDAT_MKPF AS BUDAT_MKPF_SO2
MSEG~MENGE AS MENLJ_DN_SO2
MSEG~SHKZG AS SHKZG_SO2
INTO CORRESPONDING FIELDS OF TABLE GT_DATA_DN[]
FROM MSEG
FOR ALL ENTRIES IN GT_DATA[]
WHERE MSEG~VBELN_IM = GT_DATA-VBELN_IM_SO2
AND MSEG~VBELP_IM = GT_DATA-VBELP_IM_SO2
AND MSEG~VBELN_IM <> ''
AND MSEG~VBELP_IM <> ''
AND MSEG~BUDAT_MKPF <= LV_BUDAH
.
IF GT_DATA_DN[] IS NOT INITIAL.
CLEAR GT_DATA_VF[] .
SELECT
VBRK~FKDAT AS FKDAT_SO2
VBRP~VBELN AS VBELN_VF_SO2
VBRP~POSNR AS POSNR_VF_SO2
VBRP~VGBEL AS VBELN_IM_SO2
VBRP~VGPOS AS VBELP_IM_SO2
VBRP~FKLMG AS MENLJ_VF_SO2
VBRP~NETWR AS DMBLJ_SO2
VBRP~SHKZG AS SHKZG_VF_SO2
VBRP~UMVKN AS UMVKN_VF_SO2
VBRP~UMVKZ AS UMVKZ_VF_SO2
INTO CORRESPONDING FIELDS OF TABLE GT_DATA_VF[]
FROM VBRP
INNER JOIN VBRK ON VBRK~VBELN = VBRP~VBELN
FOR ALL ENTRIES IN GT_DATA_DN[]
WHERE VBRP~VGBEL = GT_DATA_DN-VBELN_IM_SO2
AND VBRP~VGPOS = GT_DATA_DN-VBELP_IM_SO2
AND VBRK~FKDAT <= LV_BUDAH
.
ENDIF.
*PO
CLEAR GT_DATA_PO[] .
SELECT
EKPO~EBELN AS EBELN_PO
EKPO~EBELP AS EBELP_PO
EKPO~MENGE AS MENGE_PO
EKPO~UMREZ AS UMREZ_PO
EKPO~UMREN AS UMREN_PO
MSEG~MENGE AS MENLJ_PO
MSEG~DMBTR AS DMBLJ_PO
MSEG~SHKZG AS SHKZG_PO
MSEG~BUDAT_MKPF AS BUDAT_MKPF_PO
INTO CORRESPONDING FIELDS OF TABLE GT_DATA_PO[]
FROM EKPO
INNER JOIN MSEG ON MSEG~EBELN = EKPO~EBELN AND MSEG~EBELP = EKPO~EBELP
FOR ALL ENTRIES IN GT_DATA[]
WHERE EKPO~EBELN = GT_DATA-EBELN_PO
AND EKPO~EBELP = GT_DATA-EBELP_PO
AND MSEG~BUDAT_MKPF <= LV_BUDAH
.
SORT GT_DATA_PO[] BY EBELN_PO EBELP_PO .
GT_DATA_PC[] = GT_DATA_PO[] .
DELETE ADJACENT DUPLICATES FROM GT_DATA_PO[] COMPARING EBELN_PO EBELP_PO.
LOOP AT GT_DATA_PO.
IF GT_DATA_PO-UMREN_PO <> 0."PO数量
GT_DATA_PO-MENGE_PO = GT_DATA_PO-MENGE_PO * GT_DATA_PO-UMREZ_PO / GT_DATA_PO-UMREN_PO .
ENDIF.
CLEAR GT_DATA_PO-MENDQ_PO ."P0当期收货数量
CLEAR GT_DATA_PO-DMBDQ_PO ."P0当期收货金额
CLEAR GT_DATA_PO-MENLJ_PO ."PO累计收货数量
CLEAR GT_DATA_PO-DMBLJ_PO ."P0累计收货金额
LOOP AT GT_DATA_PC WHERE EBELN_PO = GT_DATA_PO-EBELN_PO AND EBELP_PO = GT_DATA_PO-EBELP_PO .
IF GT_DATA_PC-SHKZG_PO = 'H' ."借贷H取负数
GT_DATA_PC-MENLJ_PO = GT_DATA_PC-MENLJ_PO * -1 .
ENDIF.
IF GT_DATA_PC-BUDAT_MKPF_PO >= LV_BUDAL."当期
GT_DATA_PO-MENDQ_PO = GT_DATA_PO-MENDQ_PO + GT_DATA_PC-MENLJ_PO ."P0当期收货数量
GT_DATA_PO-DMBDQ_PO = GT_DATA_PO-DMBDQ_PO + GT_DATA_PC-DMBLJ_PO ."P0当期收货金额
ENDIF.
GT_DATA_PO-MENLJ_PO = GT_DATA_PO-MENLJ_PO + GT_DATA_PC-MENLJ_PO ."PO累计收货数量
GT_DATA_PO-DMBLJ_PO = GT_DATA_PO-DMBLJ_PO + GT_DATA_PC-DMBLJ_PO ."P0累计收货金额
CLEAR GT_DATA_PC .
ENDLOOP.
MODIFY GT_DATA_PO .
CLEAR GT_DATA_PO .
ENDLOOP.
*SO1
CLEAR GT_DATA_SO1[].
SELECT
VBAK~KUNNR AS KUNNR_SO1
VBAP~VBELN AS VBELN_SO1
VBAP~POSNR AS POSNR_SO1
VBAP~KLMENG AS KLMENG_SO1
VBAP~NETPR AS NETPR_SO1
LIPS~VBELN AS VBELN_IM_SO1
LIPS~POSNR AS VBELP_IM_SO1
INTO CORRESPONDING FIELDS OF TABLE GT_DATA_SO1[]
FROM VBAP
INNER JOIN VBAK ON VBAK~VBELN = VBAP~VBELN
LEFT JOIN LIPS ON LIPS~VGBEL = VBAP~VBELN AND LIPS~VGPOS = VBAP~POSNR
FOR ALL ENTRIES IN GT_DATA[]
WHERE VBAP~VBELN = GT_DATA-VBELN_SO1
AND VBAP~POSNR = GT_DATA-POSNR_SO1
.
IF GT_DATA_SO1[] IS NOT INITIAL.
CLEAR GT_DATA_DN1[] .
SELECT
MSEG~VBELN_IM AS VBELN_IM_SO1
MSEG~VBELP_IM AS VBELP_IM_SO1
MSEG~MBLNR AS MBLNR_SO1
MSEG~MJAHR AS MJAHR_SO1
MSEG~ZEILE AS ZEILE_SO1
MSEG~BUDAT_MKPF AS BUDAT_DN_SO1
MSEG~MENGE AS MENLJ_SO1
MSEG~SHKZG AS SHKZG_SO1
INTO CORRESPONDING FIELDS OF TABLE GT_DATA_DN1[]
FROM MSEG
FOR ALL ENTRIES IN GT_DATA_SO1[]
WHERE MSEG~VBELN_IM = GT_DATA_SO1-VBELN_IM_SO1
AND MSEG~VBELP_IM = GT_DATA_SO1-VBELP_IM_SO1
AND MSEG~VBELN_IM <> ''
AND MSEG~VBELP_IM <> ''
AND MSEG~BUDAT_MKPF <= LV_BUDAH
.
IF GT_DATA_DN1[] IS NOT INITIAL .
CLEAR GT_DATA_VF1[] .
SELECT
VBRK~FKDAT AS FKDAT_SO1
VBRP~VBELN AS VBELN_VF_SO1
VBRP~POSNR AS POSNR_VF_SO1
VBRP~VGBEL AS VBELN_IM_SO1
VBRP~VGPOS AS VBELP_IM_SO1
VBRP~FKLMG AS MENLJ_VF_SO1
VBRP~NETWR AS DMBLJ_VF_SO1
VBRP~SHKZG AS SHKZG_VF_SO1
VBRP~UMVKN AS UMVKN_VF_SO1
VBRP~UMVKZ AS UMVKZ_VF_SO1
INTO CORRESPONDING FIELDS OF TABLE GT_DATA_VF1[]
FROM VBRP
INNER JOIN VBRK ON VBRK~VBELN = VBRP~VBELN
FOR ALL ENTRIES IN GT_DATA_DN1[]
WHERE VBRP~VGBEL = GT_DATA_DN1-VBELN_IM_SO1
AND VBRP~VGPOS = GT_DATA_DN1-VBELP_IM_SO1
AND VBRK~FKDAT <= LV_BUDAH
.
ENDIF.
SORT GT_DATA_SO1[] BY VBELN_SO1 POSNR_SO1 VBELN_IM_SO2 VBELP_IM_SO2 .
DELETE ADJACENT DUPLICATES FROM GT_DATA_SO1[] COMPARING VBELN_SO1 POSNR_SO1 VBELN_IM_SO2 VBELP_IM_SO2.
LOOP AT GT_DATA_SO1.
SELECT SINGLE NAME1 INTO GT_DATA_SO1-NAME1_SO1 FROM KNA1
WHERE KUNNR = GT_DATA_SO1-KUNNR_SO1
.
* SO1销售单价: VBAP-NETPR 除以 VBAP-KPEIN 乘以 VBAP-UMZIN 除以VBAP-UMZIZ
IF GT_DATA_SO1-KPEIN_SO1 * GT_DATA_SO1-UMZIZ_SO1 <> 0.
GT_DATA_SO1-NETPR_SO1 = GT_DATA_SO1-NETPR_SO1 * GT_DATA_SO1-UMZIN_SO1 / ( GT_DATA_SO1-KPEIN_SO1 * GT_DATA_SO1-UMZIZ_SO1 ) .
ENDIF.
CLEAR GT_DATA_SO1-MENDQ_SO1 . "SO1DN当期数量
CLEAR GT_DATA_SO1-NETDQ_SO1 . "SO1DN当期销售金额
CLEAR GT_DATA_SO1-MENLJ_SO1 . "SO1DN累计数量
CLEAR GT_DATA_SO1-NETLJ_SO1 . "SO1DN累计金额
LOOP AT GT_DATA_DN1 WHERE VBELN_IM_SO1 = GT_DATA_SO1-VBELN_IM_SO1 AND VBELP_IM_SO1 = GT_DATA_SO1-VBELP_IM_SO1.
IF GT_DATA_DN1-SHKZG_SO1 = 'S'."借贷S取负数
GT_DATA_DN1-MENLJ_SO1 = GT_DATA_DN1-MENLJ_SO1 * -1 .
ENDIF.
IF GT_DATA_DN1-BUDAT_DN_SO1 >= LV_BUDAL."当期
GT_DATA_SO1-MENDQ_SO1 = GT_DATA_SO1-MENDQ_SO1 + GT_DATA_DN1-MENLJ_SO1 ."SO1DN当期数量
ENDIF.
GT_DATA_SO1-MENLJ_SO1 = GT_DATA_SO1-MENLJ_SO1 + GT_DATA_DN1-MENLJ_SO1 ."SO1DN累计数量
CLEAR GT_DATA_DN1 .
ENDLOOP.
GT_DATA_SO1-NETDQ_SO1 = GT_DATA_SO1-MENDQ_SO1 * GT_DATA_SO1-NETPR_SO1 ."SO1DN当期销售金额
GT_DATA_SO1-NETLJ_SO1 = GT_DATA_SO1-MENLJ_SO1 * GT_DATA_SO1-NETPR_SO1 ."SO1DN累计金额
CLEAR GT_DATA_SO1-MENDQ_VF_SO1 . "SO1当期开票数量
CLEAR GT_DATA_SO1-DMBDQ_VF_SO1 . "SO1当期开票金额
CLEAR GT_DATA_SO1-MENLJ_VF_SO1 . "SO1累计开票数量
CLEAR GT_DATA_SO1-DMBLJ_VF_SO1 . "SO1累计开票金额
LOOP AT GT_DATA_VF1 WHERE VBELN_IM_SO1 = GT_DATA_SO1-VBELN_IM_SO1 AND VBELP_IM_SO1 = GT_DATA_SO1-VBELP_IM_SO1.
IF GT_DATA_VF1-SHKZG_VF_SO1 = 'X'."SHKZG等于X的取负数
GT_DATA_VF1-MENLJ_VF_SO1 = GT_DATA_VF1-MENLJ_VF_SO1 * -1 .
ENDIF.
* SO1开票金额: VBRP-NETWR 乘以 VBRP-UMVKN 除以 VBRP-UMVKZ,
IF GT_DATA_VF1-UMVKZ_VF_SO1 <> 0.
GT_DATA_VF1-DMBLJ_VF_SO1 = GT_DATA_VF1-DMBLJ_VF_SO1 * GT_DATA_VF1-UMVKN_VF_SO1 / GT_DATA_VF1-UMVKZ_VF_SO1 .
ENDIF.
IF GT_DATA_VF1-FKDAT_SO1 >= LV_BUDAL."当期
GT_DATA_SO1-MENDQ_VF_SO1 = GT_DATA_SO1-MENDQ_VF_SO1 + GT_DATA_VF1-MENLJ_VF_SO1 ."SO1当期开票数量
GT_DATA_SO1-DMBDQ_VF_SO1 = GT_DATA_SO1-DMBDQ_VF_SO1 + GT_DATA_VF1-DMBLJ_VF_SO1 ."SO1当期开票金额
ENDIF.
GT_DATA_SO1-MENLJ_VF_SO1 = GT_DATA_SO1-MENLJ_VF_SO1 + GT_DATA_VF1-MENLJ_VF_SO1 ."SO1累计开票数量
GT_DATA_SO1-DMBLJ_VF_SO1 = GT_DATA_SO1-DMBLJ_VF_SO1 + GT_DATA_VF1-DMBLJ_VF_SO1 ."SO1累计开票金额
CLEAR GT_DATA_VF1 .
ENDLOOP.
MODIFY GT_DATA_SO1 .
CLEAR GT_DATA_SO1 .
ENDLOOP.
SORT GT_DATA_SO1[] BY VBELN_SO1 POSNR_SO1 VBELN_IM_SO2 VBELP_IM_SO2 .
GT_DATA_CO1[] = GT_DATA_SO1[] .
DELETE ADJACENT DUPLICATES FROM GT_DATA_SO1[] COMPARING VBELN_SO1 POSNR_SO1 .
LOOP AT GT_DATA_SO1.
CLEAR GT_DATA_SO1-MENDQ_SO1 . "SO1DN当期数量
CLEAR GT_DATA_SO1-NETDQ_SO1 . "SO1DN当期销售金额
CLEAR GT_DATA_SO1-MENLJ_SO1 . "SO1DN累计数量
CLEAR GT_DATA_SO1-NETLJ_SO1 . "SO1DN累计金额
CLEAR GT_DATA_SO1-MENDQ_VF_SO1 . "SO1当期开票数量
CLEAR GT_DATA_SO1-DMBDQ_VF_SO1 . "SO1当期开票金额
CLEAR GT_DATA_SO1-MENLJ_VF_SO1 . "SO1累计开票数量
CLEAR GT_DATA_SO1-DMBLJ_VF_SO1 . "SO1累计开票金额
LOOP AT GT_DATA_CO1 WHERE VBELN_SO1 = GT_DATA_SO1-VBELN_SO1 AND POSNR_SO1 = GT_DATA_SO1-POSNR_SO1.
GT_DATA_SO1-MENDQ_SO1 = GT_DATA_SO1-MENDQ_SO1 + GT_DATA_CO1-MENDQ_SO1 . "SO1DN当期数量
GT_DATA_SO1-NETDQ_SO1 = GT_DATA_SO1-NETDQ_SO1 + GT_DATA_CO1-NETDQ_SO1 . "SO1DN当期销售金额
GT_DATA_SO1-MENLJ_SO1 = GT_DATA_SO1-MENLJ_SO1 + GT_DATA_CO1-MENLJ_SO1 . "SO1DN累计数量
GT_DATA_SO1-NETLJ_SO1 = GT_DATA_SO1-NETLJ_SO1 + GT_DATA_CO1-NETLJ_SO1 . "SO1DN累计金额
GT_DATA_SO1-MENDQ_VF_SO1 = GT_DATA_SO1-MENDQ_VF_SO1 + GT_DATA_CO1-MENDQ_VF_SO1 ."SO1当期开票数量
GT_DATA_SO1-DMBDQ_VF_SO1 = GT_DATA_SO1-DMBDQ_VF_SO1 + GT_DATA_CO1-DMBDQ_VF_SO1 ."SO1当期开票金额
GT_DATA_SO1-MENLJ_VF_SO1 = GT_DATA_SO1-MENLJ_VF_SO1 + GT_DATA_CO1-MENLJ_VF_SO1 ."SO1累计开票数量
GT_DATA_SO1-DMBLJ_VF_SO1 = GT_DATA_SO1-DMBLJ_VF_SO1 + GT_DATA_CO1-DMBLJ_VF_SO1 ."SO1累计开票金额
ENDLOOP.
MODIFY GT_DATA_SO1 .
CLEAR GT_DATA_SO1 .
ENDLOOP.
ENDIF.
LOOP AT GT_DATA.
SELECT SINGLE VTEXT INTO GT_DATA-VTEXT_SO2 FROM TVKOT
WHERE VKORG = GT_DATA-VKORG_SO2
AND SPRAS = 1
.
SELECT SINGLE NAME1 INTO GT_DATA-NAME1_SO2 FROM KNA1
WHERE KUNNR = GT_DATA-KUNNR_SO2
.
*SO2销售单价: VBAP-NETPR 除以 VBAP-KPEIN 乘以 VBAP-UMZIN 除以VBAP-UMZIZ
IF GT_DATA-KPEIN_SO2 * GT_DATA-UMZIZ_SO2 <> 0.
GT_DATA-NETPR_SO2 = GT_DATA-NETPR_SO2 * GT_DATA-UMZIN_SO2 / ( GT_DATA-KPEIN_SO2 * GT_DATA-UMZIZ_SO2 ) .
ENDIF.
CLEAR GT_DATA-MENDQ_DN_SO2 . "SO2交货单当期交货数
CLEAR GT_DATA-NETDQ_SO2 . "SO2交货单当期销售金额
CLEAR GT_DATA-MENLJ_DN_SO2 . "SO2交货单累计数量
CLEAR GT_DATA-NETLJ_SO2 . "SO2交货单累计金额
CLEAR GT_DATA-BUDAT_MKPF_SO2 ."SO2交货日期
LOOP AT GT_DATA_DN WHERE VBELN_IM_SO2 = GT_DATA-VBELN_IM_SO2 AND VBELP_IM_SO2 = GT_DATA-VBELP_IM_SO2.
GT_DATA-BUDAT_MKPF_SO2 = GT_DATA_DN-BUDAT_MKPF_SO2 ."SO2交货日期
IF GT_DATA_DN-SHKZG_SO2 = 'S'."借贷S取负数
GT_DATA_DN-MENLJ_DN_SO2 = GT_DATA_DN-MENLJ_DN_SO2 * -1 .
ENDIF.
GT_DATA-MENLJ_DN_SO2 = GT_DATA-MENLJ_DN_SO2 + GT_DATA_DN-MENLJ_DN_SO2 ."SO2交货单累计数量
IF GT_DATA_DN-BUDAT_MKPF_SO2 >= LV_BUDAL."当期
GT_DATA-MENDQ_DN_SO2 = GT_DATA-MENDQ_DN_SO2 + GT_DATA_DN-MENLJ_DN_SO2 ."SO2交货单当期交货数
ENDIF.
CLEAR GT_DATA_DN .
ENDLOOP.
GT_DATA-NETDQ_SO2 = GT_DATA-MENDQ_DN_SO2 * GT_DATA-NETPR_SO2 ."SO2交货单当期销售金额
GT_DATA-NETLJ_SO2 = GT_DATA-MENLJ_DN_SO2 * GT_DATA-NETPR_SO2 ."SO2交货单累计金额
CLEAR GT_DATA-FKDAT_SO2 . "SO2开票日期
CLEAR GT_DATA-MENDQ_VF_SO2 ."SO2当期开票数量
CLEAR GT_DATA-DMBDQ_SO2 . "SO2当期开票金额-未税
CLEAR GT_DATA-MENLJ_VF_SO2 ."SO2累计开票数量
CLEAR GT_DATA-DMBLJ_SO2 . "SO2累计开票金额-未税
LOOP AT GT_DATA_VF WHERE VBELN_IM_SO2 = GT_DATA-VBELN_IM_SO2 AND VBELP_IM_SO2 = GT_DATA-VBELP_IM_SO2.
GT_DATA-FKDAT_SO2 = GT_DATA_VF-FKDAT_SO2 ."SO2开票日期
IF GT_DATA_VF-SHKZG_VF_SO2 = 'X'."SHKZG等于X的取负数
GT_DATA_VF-MENLJ_VF_SO2 = GT_DATA_VF-MENLJ_VF_SO2 * -1 .
ENDIF.
*SO2开票金额-未税: VBRP-NETWR 乘以 VBRP-UMVKN 除以 VBRP-UMVKZ,
IF GT_DATA_VF-UMVKZ_VF_SO2 <> 0.
GT_DATA_VF-DMBLJ_SO2 = GT_DATA_VF-DMBLJ_SO2 * GT_DATA_VF-UMVKN_VF_SO2 / GT_DATA_VF-UMVKZ_VF_SO2 .
ENDIF.
IF GT_DATA_VF-FKDAT_SO2 >= LV_BUDAL."当期
GT_DATA-MENDQ_VF_SO2 = GT_DATA-MENDQ_VF_SO2 + GT_DATA_VF-MENLJ_VF_SO2 ."SO2当期开票数量
GT_DATA-DMBDQ_SO2 = GT_DATA-DMBDQ_SO2 + GT_DATA_VF-DMBLJ_SO2 ."SO2当期开票金额-未税
ENDIF.
GT_DATA-MENLJ_VF_SO2 = GT_DATA-MENLJ_VF_SO2 + GT_DATA_VF-MENLJ_VF_SO2 ."SO2累计开票数量
GT_DATA-DMBLJ_SO2 = GT_DATA-DMBLJ_SO2 + GT_DATA_VF-DMBLJ_SO2 ."SO2累计开票金额-未税
CLEAR GT_DATA_VF .
ENDLOOP.
CLEAR GT_DATA-MENGE_PO ."PO数量
CLEAR GT_DATA-MENDQ_PO ."P0当期收货数量
CLEAR GT_DATA-DMBDQ_PO ."P0当期收货金额
CLEAR GT_DATA-MENLJ_PO ."PO累计收货数量
CLEAR GT_DATA-DMBLJ_PO ."P0累计收货金额
CLEAR GT_DATA_PO .
READ TABLE GT_DATA_PO WITH KEY EBELN_PO = GT_DATA-EBELN_PO EBELP_PO = GT_DATA-EBELP_PO .
IF SY-SUBRC = 0.
GT_DATA-MENGE_PO = GT_DATA_PO-MENGE_PO ."PO数量
GT_DATA-MENDQ_PO = GT_DATA_PO-MENDQ_PO ."P0当期收货数量
GT_DATA-DMBDQ_PO = GT_DATA_PO-DMBDQ_PO ."P0当期收货金额
GT_DATA-MENLJ_PO = GT_DATA_PO-MENLJ_PO ."PO累计收货数量
GT_DATA-DMBLJ_PO = GT_DATA_PO-DMBLJ_PO ."P0累计收货金额
ENDIF.
* LOOP AT GT_DATA_PO WHERE EBELN_PO = GT_DATA-EBELN_PO AND EBELP_PO = GT_DATA-EBELP_PO .
* GT_DATA-MENGE_PO = GT_DATA_PO-MENGE_PO ."PO数量
* GT_DATA-MENDQ_PO = GT_DATA_PO-MENDQ_PO ."P0当期收货数量
* GT_DATA-DMBDQ_PO = GT_DATA_PO-DMBDQ_PO ."P0当期收货金额
* GT_DATA-MENLJ_PO = GT_DATA_PO-MENLJ_PO ."PO累计收货数量
* GT_DATA-DMBLJ_PO = GT_DATA_PO-DMBLJ_PO ."P0累计收货金额
* CLEAR GT_DATA_PO .
* ENDLOOP.
CLEAR GT_DATA_SO1 .
READ TABLE GT_DATA_SO1 WITH KEY VBELN_SO1 = GT_DATA-VBELN_SO1 POSNR_SO1 = GT_DATA-POSNR_SO1 .
IF SY-SUBRC = 0.
GT_DATA-KUNNR_SO1 = GT_DATA_SO1-KUNNR_SO1 . "SO1客户
GT_DATA-NAME1_SO1 = GT_DATA_SO1-NAME1_SO1 . "客户名称
GT_DATA-KLMENG_SO1 = GT_DATA_SO1-KLMENG_SO1 . "SO1订单数量
GT_DATA-NETPR_SO1 = GT_DATA_SO1-NETPR_SO1 . "SO1销售单价
GT_DATA-MENDQ_SO1 = GT_DATA_SO1-MENDQ_SO1 . "SO1DN当期数量
GT_DATA-NETDQ_SO1 = GT_DATA_SO1-NETDQ_SO1 . "SO1DN当期销售金额
GT_DATA-MENLJ_SO1 = GT_DATA_SO1-MENLJ_SO1 . "SO1DN累计数量
GT_DATA-NETLJ_SO1 = GT_DATA_SO1-NETLJ_SO1 . "SO1DN累计金额
GT_DATA-MENDQ_VF_SO1 = GT_DATA_SO1-MENDQ_VF_SO1 ."SO1当期开票数量
GT_DATA-DMBDQ_VF_SO1 = GT_DATA_SO1-DMBDQ_VF_SO1 ."SO1当期开票金额
GT_DATA-MENLJ_VF_SO1 = GT_DATA_SO1-MENLJ_VF_SO1 ."SO1累计开票数量
GT_DATA-DMBLJ_VF_SO1 = GT_DATA_SO1-DMBLJ_VF_SO1 ."SO1累计开票金额
ENDIF.
* LOOP AT GT_DATA_SO1 WHERE VBELN_SO1 = GT_DATA-VBELN_SO1 AND POSNR_SO1 = GT_DATA-POSNR_SO1 .
* GT_DATA-KUNNR_SO1 = GT_DATA_SO1-KUNNR_SO1 . "SO1客户
* GT_DATA-NAME1_SO1 = GT_DATA_SO1-NAME1_SO1 . "客户名称
* GT_DATA-KLMENG_SO1 = GT_DATA_SO1-KLMENG_SO1 . "SO1订单数量
* GT_DATA-NETPR_SO1 = GT_DATA_SO1-NETPR_SO1 . "SO1销售单价
* GT_DATA-MENDQ_SO1 = GT_DATA_SO1-MENDQ_SO1 . "SO1DN当期数量
* GT_DATA-NETDQ_SO1 = GT_DATA_SO1-NETDQ_SO1 . "SO1DN当期销售金额
* GT_DATA-MENLJ_SO1 = GT_DATA_SO1-MENLJ_SO1 . "SO1DN累计数量
* GT_DATA-NETLJ_SO1 = GT_DATA_SO1-NETLJ_SO1 . "SO1DN累计金额
* GT_DATA-MENDQ_VF_SO1 = GT_DATA_SO1-MENDQ_VF_SO1 ."SO1当期开票数量
* GT_DATA-DMBDQ_VF_SO1 = GT_DATA_SO1-DMBDQ_VF_SO1 ."SO1当期开票金额
* GT_DATA-MENLJ_VF_SO1 = GT_DATA_SO1-MENLJ_VF_SO1 ."SO1累计开票数量
* GT_DATA-DMBLJ_VF_SO1 = GT_DATA_SO1-DMBLJ_VF_SO1 ."SO1累计开票金额
* CLEAR GT_DATA_SO1 .
* ENDLOOP.
MODIFY GT_DATA .
CLEAR GT_DATA .
ENDLOOP.
ELSE .
MESSAGE 'NO_DATA!'TYPE'S'DISPLAY LIKE 'E'.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_DISPLAY
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_DISPLAY .
CLEAR S_LAYOUT.
S_LAYOUT-ZEBRA = 'X'.
S_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
* s_layout-box_fieldname = 'BOX'.
PERFORM FRM_FILL_FIELD .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IS_LAYOUT = S_LAYOUT
IT_FIELDCAT = GT_FIELDCAT
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = 'PF_STATUS_SET'
* i_callback_html_top_of_page = 'HTML_TOP_OF_PAGE'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
TABLES
T_OUTTAB = GT_DATA[].
ENDFORM.
FORM FRM_FILL_FIELD .
DATA: WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
DEFINE FILL_FIELD.
wa_fieldcat-fieldname = &1.
wa_fieldcat-seltext_l = &2.
IF wa_fieldcat-fieldname = 'MSLJH' or wa_fieldcat-fieldname = 'WCBJH'.
wa_fieldcat-EMPHASIZE = 'C600'. "设置字段的颜色
ENDIF.
IF wa_fieldcat-fieldname = 'MSLMB' or wa_fieldcat-fieldname = 'WCBMB'.
wa_fieldcat-EMPHASIZE = 'C710'. "设置字段的颜色
ENDIF.
IF wa_fieldcat-fieldname = 'MATNR_SO2' OR wa_fieldcat-fieldname = 'MATNR' .
wa_fieldcat-ref_tabname = 'MARA'.
wa_fieldcat-ref_fieldname = 'MATNR'.
ENDIF.
IF wa_fieldcat-fieldname = 'ARKTX_SO2' OR wa_fieldcat-fieldname = 'NAME1_SO2' .
wa_fieldcat-ref_tabname = 'VBAP'.
wa_fieldcat-ref_fieldname = 'ARKTX'.
ENDIF.
IF wa_fieldcat-fieldname = 'AUFNR' .
wa_fieldcat-ref_tabname = 'AUFK'.
wa_fieldcat-ref_fieldname = 'AUFNR'.
ENDIF.
APPEND wa_fieldcat TO gt_fieldcat.
CLEAR wa_fieldcat.
END-OF-DEFINITION.
FILL_FIELD :
'VKORG_SO2' '销售组织',
'VTEXT_SO2' '销售组织描述',
'KUNNR_SO2' 'SO2付款方',
'NAME1_SO2' '付款方名称',
'MATNR_SO2' '物料号',
'ARKTX_SO2' '物料号描述',
'VBELN_SO2' 'SO2销售订单',
'POSNR_SO2' 'SO2行项目号',
'KLMENG_SO2' 'SO2订单数量',
'NETPR_SO2' 'SO2销售单价',
'MEINS_SO2' '基本计量单位',
'VBELN_IM_SO2' 'SO2交货单',
'VBELP_IM_SO2' 'SO2交货行项目',
'BUDAT_MKPF_SO2' 'SO2交货日期',
'MENDQ_DN_SO2' 'SO2交货单当期交货数',
'NETDQ_SO2' 'SO2交货单当期销售金额',
'MENLJ_DN_SO2' 'SO2交货单累计数量',
'NETLJ_SO2' 'SO2交货单累计金额',
'FKDAT_SO2' 'SO2开票日期',
'MENDQ_VF_SO2' 'SO2当期开票数量',
'DMBDQ_SO2' 'SO2当期开票金额-未税',
'MENLJ_VF_SO2' 'SO2累计开票数量',
'DMBLJ_SO2' 'SO2累计开票金额-未税',
'EBELN_PO' '采购凭证',
'EBELP_PO' '采购凭证的项目编号',
'MENGE_PO' 'PO数量',
'MENDQ_PO' 'P0当期收货数量',
'DMBDQ_PO' 'P0当期收货金额',
'MENLJ_PO' 'PO累计收货数量',
'DMBLJ_PO' 'P0累计收货金额',
'VBELN_SO1' 'SO1销售订单',
'POSNR_SO1' 'SO1行项目',
'KUNNR_SO1' 'SO1客户',
'NAME1_SO1' '客户名称',
'KLMENG_SO1' 'SO1订单数量',
'NETPR_SO1' 'SO1销售单价',
'MENDQ_SO1' 'SO1DN当期数量',
'SO1DN当期数量' 'SO1DN当期销售金额',
'MENLJ_SO1' 'SO1DN累计数量',
'NETLJ_SO1' 'SO1DN累计金额',
'MENDQ_VF_SO1' 'SO1当期开票数量',
'DMBDQ_VF_SO1' 'SO1当期开票金额',
'MENLJ_VF_SO1' 'SO1累计开票数量',
'DMBLJ_VF_SO1' 'SO1累计开票金额'.
ENDFORM.
FORM PF_STATUS_SET USING RT_EXTAB TYPE SLIS_T_EXTAB.
SET PF-STATUS 'STANDARD_FULLSCREEN'.
ENDFORM.
FORM USER_COMMAND USING I_UCOMM LIKE SY-UCOMM
IS_SELFIELD TYPE SLIS_SELFIELD.
DATA: REF TYPE REF TO CL_GUI_ALV_GRID.
DATA : LV_STABLE TYPE LVC_S_STBL. "刷新稳定性
RANGES: L_WERKS FOR T001W-WERKS.
RANGES: L_MATNR FOR MARA-MATNR.
DATA:L_BUKRS TYPE T001K-BUKRS.
LV_STABLE-ROW = '1'.
LV_STABLE-COL = '1'.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = REF.
CALL METHOD REF->CHECK_CHANGED_DATA.
CASE I_UCOMM.
WHEN 'DEL_DJ'.
ENDCASE.
CALL METHOD REF->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LV_STABLE.
ENDFORM.
INITIALIZATION .
AT SELECTION-SCREEN OUTPUT.
PERFORM SCREEN_OUTPUT.
AT SELECTION-SCREEN.
PERFORM SCREEN_SETTING.
START-OF-SELECTION.
PERFORM FOM_GETDATA .
PERFORM FRM_DISPLAY.