上代码 干货来了
*&---------------------------------------------------------------------*
*& REPORT ZRPT_FI_IDOC_R
*&
*&---------------------------------------------------------------------*
*& author ABAP02
*& date 20240103
*& from
*& Tcode zidoc
*&---------------------------------------------------------------------*
REPORT ZRPT_FI_IDOC_R.
TABLES: EDIDS,EDID4,RBKP,LIKP,EKKO.
SELECTION-SCREEN BEGIN OF BLOCK 001 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS S_DOCNUM FOR EDIDS-DOCNUM. "IDOC号码
SELECT-OPTIONS S_CREDAT FOR EDIDS-CREDAT. "创建日期
SELECTION-SCREEN END OF BLOCK 001.
TYPES:
BEGIN OF TYP_DATA,
DOCNUM TYPE EDIDS-DOCNUM, "IDOC号码
CREDAT TYPE EDIDS-CREDAT, "创建日期
STATUS TYPE EDIDS-STATUS, "状态
VBELNR TYPE RBKP-BELNR, "销售发票
GJAHR TYPE VBRK-GJAHR, "销售发票
NETWR TYPE VBRK-NETWR, "不含税金额
MWSBK TYPE VBRK-MWSBK, "税额
NETWR1 TYPE VBRK-NETWR, "含税金额
ERNAME TYPE RBKP-ERNAME, "创建者
BELNR TYPE RBKP-BELNR, "采购发票
RMWWR TYPE RBKP-RMWWR , "总金额
WMWST1 TYPE RBKP-WMWST1, " 增值税
WMWST TYPE RBKP-WMWST1, "采购不含税金额
MWSKZ1 TYPE RBKP-MWSKZ1, "税码
ERFNAM TYPE RBKP-ERFNAM, "采购发票创建者
VBELN TYPE LIKP-VBELN, "交货单
EBELN TYPE EKKO-EBELN, "采购订单
BSART TYPE EKKO-BSART, "采购订单类型
END OF TYP_DATA.
DATA:
STDATUM LIKE SY-DATUM,
STUZEIT LIKE SY-UZEIT,
GT_DATA TYPE TABLE OF TYP_DATA,
GS_DATA TYPE TYP_DATA,
GT_FIELDCAT TYPE LVC_T_FCAT,
GS_FIELDCAT TYPE LVC_S_FCAT,
GS_LAYOUT TYPE LVC_S_LAYO.
INITIALIZATION.
%_S_DOCNUM_%_APP_%-TEXT = 'IDOC号码'.
%_S_CREDAT_%_APP_%-TEXT = '创建日期'.
START-OF-SELECTION.
STDATUM = SY-DATUM.
STUZEIT = SY-UZEIT.
PERFORM GET_DATA.
PERFORM PROCESS_DATA.
PERFORM WRITERPTRUNRECORD.
PERFORM DISPLAY_DATA.
*&---------------------------------------------------------------------*
*& FORM GET_DATA
*&---------------------------------------------------------------------*
* 获取数据
*----------------------------------------------------------------------*
FORM GET_DATA.
SELECT
EDIDS~DOCNUM "IDOC号码
EDIDS~CREDAT "创建日期
EDIDS~STATUS "状态
INTO TABLE GT_DATA
FROM EDIDS
WHERE EDIDS~DOCNUM IN S_DOCNUM
AND EDIDS~CREDAT IN S_CREDAT.
ENDFORM. "GET_DATA
*&---------------------------------------------------------------------*
*& FORM WRITERPTRUNRECORD
*&---------------------------------------------------------------------*
* 获取数据
*----------------------------------------------------------------------*
FORM WRITERPTRUNRECORD.
TYPES:BEGIN OF TYP_BW,
BUKRS LIKE T001-BUKRS,
WERKS LIKE T001W-WERKS,
END OF TYP_BW.
DATA:
GT_BW TYPE TABLE OF TYP_BW,
GS_BW TYPE TYP_BW.
GET TIME.
CALL FUNCTION 'ZSYS_RPT_RUNRECORD'
EXPORTING
TCODE = SY-TCODE
PROGRAMM = SY-CPROG
DATUMRST = STDATUM
UZEITRST = STUZEIT
BATCH = SY-BATCH
DATUMREND = SY-DATUM
UZEITREND = SY-UZEIT
DATUMC = '20240103'
RUNNER = SY-UNAME
RPTSRC = 'BC'.
ENDFORM. "WRITERPTRUNRECORD
*&---------------------------------------------------------------------*
*& FORM PROCESS_DATA
*&---------------------------------------------------------------------*
* 处理数据
*----------------------------------------------------------------------*
FORM PROCESS_DATA.
LOOP AT GT_DATA INTO GS_DATA.
"STATUS
SELECT STATUS INTO GS_DATA-STATUS UP TO 1 ROWS
FROM EDIDS WHERE DOCNUM = GS_DATA-DOCNUM
ORDER BY COUNTR DESCENDING.
ENDSELECT.
SELECT * INTO TABLE @DATA(LTEDID4)
FROM EDID4 WHERE DOCNUM = @GS_DATA-DOCNUM
AND SEGNAM = 'E1EDK02'.
LOOP AT LTEDID4 INTO DATA(LSEDID4).
IF LSEDID4-SDATA+0(3) = '009'.
GS_DATA-VBELNR = LSEDID4-SDATA+3(10)."销售发票
GS_DATA-GJAHR = LSEDID4-SDATA+44(4)."财年
ENDIF.
IF LSEDID4-SDATA+0(3) = '012'.
GS_DATA-VBELN = LSEDID4-SDATA+3(10)."交货单
ENDIF.
IF LSEDID4-SDATA+0(3) = '002'.
GS_DATA-EBELN = LSEDID4-SDATA+3(10)."采购订单
ENDIF.
ENDLOOP.
*采购发票
SELECT SINGLE BELNR ERFNAM RMWWR WMWST1 MWSKZ1 INTO
(GS_DATA-BELNR,GS_DATA-ERFNAM,GS_DATA-RMWWR,GS_DATA-WMWST1,GS_DATA-MWSKZ1)
FROM RBKP WHERE XBLNR = GS_DATA-VBELNR AND GJAHR = GS_DATA-GJAHR.
GS_DATA-WMWST = GS_DATA-RMWWR - GS_DATA-WMWST1.
* 销售发票和金额
SELECT SINGLE ERNAM NETWR MWSBK
INTO (GS_DATA-ERNAME,GS_DATA-NETWR,GS_DATA-MWSBK) FROM
VBRK WHERE VBELN = GS_DATA-VBELNR AND GJAHR = GS_DATA-GJAHR.
GS_DATA-NETWR1 = GS_DATA-NETWR + GS_DATA-MWSBK.
SELECT SINGLE BSART INTO GS_DATA-BSART FROM EKKO WHERE EBELN = GS_DATA-EBELN.
MODIFY GT_DATA FROM GS_DATA.
ENDLOOP.
ENDFORM. "PROCESS_DATA
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCAT
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
FORM BUILD_FIELDCAT USING P_FIELDNAME TYPE FIELDNAME
P_QFIELDNAME TYPE LVC_QFNAME
P_CFIELDNAME TYPE LVC_CFNAME
P_REF_TABLE TYPE LVC_RTNAME
P_REF_FIELD TYPE LVC_RFNAME
P_CONVEXIT TYPE CONVEXIT
P_EMPHASIZE TYPE LVC_EMPHSZ
P_SCRTEXT_L TYPE SCRTEXT_L
P_NO_ZERO TYPE XFLAG.
GS_FIELDCAT-FIELDNAME = P_FIELDNAME.
GS_FIELDCAT-QFIELDNAME = P_QFIELDNAME.
GS_FIELDCAT-CFIELDNAME = P_CFIELDNAME.
GS_FIELDCAT-REF_TABLE = P_REF_TABLE.
GS_FIELDCAT-REF_FIELD = P_REF_FIELD.
GS_FIELDCAT-CONVEXIT = P_CONVEXIT.
GS_FIELDCAT-EMPHASIZE = P_EMPHASIZE.
GS_FIELDCAT-SCRTEXT_L = P_SCRTEXT_L.
GS_FIELDCAT-NO_ZERO = P_NO_ZERO.
GS_FIELDCAT-COLDDICTXT = 'L'.
APPEND GS_FIELDCAT TO GT_FIELDCAT.
CLEAR: GS_FIELDCAT.
ENDFORM. "BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*& FORM DISPLAY_DATA
*&---------------------------------------------------------------------*
* 显示数据
*----------------------------------------------------------------------*
FORM DISPLAY_DATA.
PERFORM BUILD_FIELDCAT USING 'DOCNUM' '' '' '' '' '' '' 'IDOC号码' 'X'.
PERFORM BUILD_FIELDCAT USING 'CREDAT' '' '' '' '' '' '' '创建日期' ''.
PERFORM BUILD_FIELDCAT USING 'STATUS' '' '' '' '' '' '' '状态' ''.
PERFORM BUILD_FIELDCAT USING 'VBELNR' '' '' '' '' '' '' '销售发票' 'X'.
PERFORM BUILD_FIELDCAT USING 'GJAHR' '' '' '' '' '' '' '财年' 'X'.
PERFORM BUILD_FIELDCAT USING 'NETWR' '' '' '' '' '' '' '销售发票净额' 'X'.
PERFORM BUILD_FIELDCAT USING 'MWSBK' '' '' '' '' '' '' '销售发票税额' 'X'.
PERFORM BUILD_FIELDCAT USING 'NETWR1' '' '' '' '' '' '' '销售发票含税金额' 'X'.
PERFORM BUILD_FIELDCAT USING 'ERNAME' '' '' '' '' '' '' '销售发票创建人' ''.
PERFORM BUILD_FIELDCAT USING 'BELNR' '' '' '' '' '' '' '采购发票' 'X'.
PERFORM BUILD_FIELDCAT USING 'WMWST' '' '' '' '' '' '' '采购发票不含税净额' 'X'.
PERFORM BUILD_FIELDCAT USING 'WMWST1' '' '' '' '' '' '' '增值税税额' 'X'.
PERFORM BUILD_FIELDCAT USING 'RMWWR' '' '' '' '' '' '' '采购发票含税金额' 'X'.
PERFORM BUILD_FIELDCAT USING 'ERFNAM' '' '' '' '' '' '' '采购发票创建人' ''.
PERFORM BUILD_FIELDCAT USING 'VBELN' '' '' '' '' '' '' '交货单' 'X'.
PERFORM BUILD_FIELDCAT USING 'EBELN' '' '' '' '' '' '' '采购订单' 'X'.
PERFORM BUILD_FIELDCAT USING 'BSART' '' '' '' '' '' '' '采购订单类型' ''.
GS_LAYOUT-CWIDTH_OPT = 'X'.
GS_LAYOUT-ZEBRA = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
" I_CALLBACK_PF_STATUS_SET = 'PF_STATUS_ALV'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND_ALV'
IT_FIELDCAT_LVC = GT_FIELDCAT
IS_LAYOUT_LVC = GS_LAYOUT
I_DEFAULT = 'X'
I_SAVE = 'A'
TABLES
T_OUTTAB = GT_DATA
EXCEPTIONS
OTHERS = 1.
ENDFORM. "DISPLAY_DATA
**&---------------------------------------------------------------------*
**& FORM PF_STATUS_ALV
**&---------------------------------------------------------------------*
** TEXT
**----------------------------------------------------------------------*
*FORM PF_STATUS_ALV USING RT_EXTAB TYPE SLIS_T_EXTAB .
* SET PF-STATUS 'STATUS_ALV' EXCLUDING RT_EXTAB.
*ENDFORM. "PF_STATUS_ALV
*&---------------------------------------------------------------------*
*& FORM USER_COMMAND_ALV
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
FORM USER_COMMAND_ALV USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE R_UCOMM.
WHEN '&IC1'.
CASE RS_SELFIELD-FIELDNAME.
WHEN ''.
* CHECK RS_SELFIELD-VALUE IS NOT INITIAL.
* SET PARAMETER ID 'MBN' FIELD RS_SELFIELD-VALUE.
* CALL TRANSACTION 'MB03' AND SKIP FIRST SCREEN.
ENDCASE.
ENDCASE.
ENDFORM. "USER_COMMAND_ALV