*&---------------------------------------------------------------------*
*& Report ZFIR121
*&---------------------------------------------------------------------*
*& Author : NathanSun
*& Create Date : 2019-02-19
*& Program Type : Report
*& Description : 开票后发出商品-差异处理
*&---------------------------------------------------------------------*
REPORT ZFIR121.
*&---------------------------------------------------------------------*
*& 包含 ZFIR092_TOP
*&---------------------------------------------------------------------*
TABLES:ACDOCA,BKPF,EKKN,VBAP.
TYPE-POOLS:SLIS.
"定义ALV输出所需变量
DATA: S_LAYOUT TYPE SLIS_LAYOUT_ALV,
GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: GT_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
DATA: U_BUDAT TYPE BUDAT.
DATA: N_BUDAT TYPE BUDAT.
DATA: Y_BUDAT TYPE BUDAT.
DATA: P_BUDAT TYPE ACDOCA-BUDAT.
TYPES: BEGIN OF GTS_DATA,
VGBEL TYPE VBRP-VGBEL, "交货单
VGPOS TYPE VBRP-VGPOS, "行项目
RACCT TYPE ACDOCA-RACCT, "成本科目
MATNR TYPE ACDOCA-MATNR, "物料
RBUKRS TYPE ACDOCA-RBUKRS, "公司代码
GJAHR TYPE ACDOCA-GJAHR, "年度
POPER TYPE ACDOCA-POPER, "期间
WERKS TYPE ACDOCA-WERKS, "工厂
PRCTR TYPE ACDOCA-PRCTR, "利润中心
ZUONR TYPE ACDOCA-ZUONR, "分配编号
MAKTG TYPE MAKT-MAKTG, "物料描述
HSL TYPE ACDOCA-HSL, "交货单发差金额
FTHSL TYPE ACDOCA-HSL, "分摊金额
RHCUR TYPE ACDOCA-RHCUR, "币别
AWREF TYPE ACDOCA-AWREF, "开票
AWITEM TYPE ACDOCA-AWITEM, "开票行项目
VBUND TYPE KNA1-VBUND, "贸易伙伴
FKDAT TYPE VBRK-FKDAT, "冲销时间
FKSTO TYPE VBRK-FKSTO, "取消发票
SFAKN TYPE VBRK-SFAKN, "已取消的出具发票凭证编号
KUNAG TYPE VBRK-KUNAG, "客户
FKLMG TYPE VBRP-FKLMG, "开票数量
YKLMG TYPE VBRP-FKLMG, "已开票数量
MEINS TYPE VBRP-MEINS, "单位
SHKZG TYPE VBRP-SHKZG, "退货项目
LGMNG TYPE LIPS-LGMNG, "交货数量
SHKZGL TYPE LIPS-SHKZG, "退货项目
WADAT_IST TYPE LIKP-WADAT_IST, "交货日期
BUDAT TYPE ACDOCA-BUDAT, "过账日期
BELNR TYPE ACDOCA-BELNR, "会计凭证
END OF GTS_DATA.
DATA: GLAG_N TYPE C .
DATA: GLAG_E TYPE C .
DATA: GT_DATA TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA_A TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GS_DATA TYPE GTS_DATA .
DATA: GT_REVERSAL TYPE TABLE OF BAPIACREV WITH HEADER LINE.
DATA: GT_ZTFI121 TYPE TABLE OF ZTFI121 WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS: P_BUKRS LIKE ACDOCA-RBUKRS MODIF ID C1 OBLIGATORY , "公司代码
P_GJAHR LIKE ACDOCA-GJAHR MODIF ID C1 OBLIGATORY , "年度
P_MONAT LIKE BKPF-MONAT MODIF ID C1 OBLIGATORY . "期间
SELECTION-SCREEN END OF BLOCK B1.
*&---------------------------------------------------------------------*
*& 包含 ZFIR101_CLASS
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
* CLASS DEMO DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS DEMO DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
MAIN.
ENDCLASS.
CLASS DEMO IMPLEMENTATION.
METHOD MAIN.
DATA(OUT) = CL_DEMO_OUTPUT=>NEW( ).
OUT->BEGIN_SECTION( `报错信息回执`
)->WRITE( GT_RETURN[] ).
OUT->DISPLAY( ).
ENDMETHOD.
ENDCLASS.
*&---------------------------------------------------------------------*
*& 包含 ZFIR092_FOM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_EXCLUDE_OPTION
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_EXCLUDE_OPTION .
ENDFORM.
*&---------------------------------------------------------------------*
*& 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 'F_BKPF_BUK'
ID 'BUKRS' FIELD P_BUKRS.
IF SY-SUBRC <> 0.
MESSAGE '您没有公司:'&& P_BUKRS && ' 的权限!' TYPE 'E' .
ENDIF.
* MESSAGE I000(0K) WITH TEXT-115 SPACE SPACE SPACE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FOM_GETDATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FOM_GETDATA .
FIELD-SYMBOLS <FS> .
DATA: G_FIELD(40).
*取所选期间的第一天
U_BUDAT = P_GJAHR && P_MONAT && '01' .
*取所选年度的第一天
Y_BUDAT = P_GJAHR && '01' && '01' .
*取所选期间的最后一天
CALL FUNCTION 'BKK_GET_MONTH_LASTDAY'
EXPORTING
I_DATE = U_BUDAT
IMPORTING
E_DATE = P_BUDAT
.
**取所选期间次月的第一天
N_BUDAT = P_BUDAT + 1 .
CLEAR GT_DATA[] .
SELECT
ACDOCA~RBUKRS
ACDOCA~GJAHR
ACDOCA~POPER
ACDOCA~WERKS
ACDOCA~PRCTR
ACDOCA~DOCLN
ACDOCA~MATNR
ACDOCA~RACCT
ACDOCA~RHCUR
ACDOCA~AWREF
ACDOCA~AWITEM
ACDOCA~ZUONR
VBRK~FKSTO
VBRK~KUNAG
* VBRK~SFAKN
VBRP~FKLMG
VBRP~MEINS
VBRP~VGBEL
VBRP~VGPOS
VBRP~SHKZG
LIPS~LGMNG
LIPS~SHKZG AS SHKZGL
LIKP~WADAT_IST
INTO CORRESPONDING FIELDS OF TABLE GT_DATA[]
FROM ACDOCA
INNER JOIN VBRP ON VBRP~VBELN = ACDOCA~AWREF AND VBRP~POSNR = ACDOCA~AWITEM
INNER JOIN VBRK ON VBRK~VBELN = ACDOCA~AWREF
INNER JOIN LIPS ON LIPS~VBELN = VBRP~VGBEL AND LIPS~POSNR = VBRP~VGPOS
INNER JOIN LIKP ON LIKP~VBELN = VBRP~VGBEL
WHERE ACDOCA~RBUKRS = P_BUKRS
AND ACDOCA~GJAHR = P_GJAHR
AND ACDOCA~BUDAT => U_BUDAT
AND ACDOCA~BUDAT <= P_BUDAT
AND ACDOCA~BLART = 'RV'
AND ( ACDOCA~RACCT LIKE '6401%' OR ACDOCA~RACCT LIKE '6402%' )
AND VBRK~FKDAT => U_BUDAT
AND VBRK~FKDAT <= P_BUDAT
* AND VBRK~FKSTO <> 'X'
AND VBRK~SFAKN = ''
* AND ACDOCA~USNAM NOT IN ('IT04','IT10','FI0029')
* AND VBRP~VGBEL = '8000018980'
* AND VBRP~VGPOS = '000100'
.
IF GT_DATA[] IS NOT INITIAL.
LOOP AT GT_DATA.
SELECT SINGLE MAKTG INTO GT_DATA-MAKTG FROM MAKT
WHERE MATNR = GT_DATA-MATNR
AND SPRAS = 1
.
SELECT SINGLE VBUND INTO GT_DATA-VBUND FROM KNA1
WHERE KUNNR = GT_DATA-KUNAG
.
GT_DATA-ZUONR = GT_DATA-VGBEL && GT_DATA-VGPOS .
IF GT_DATA-FKSTO = 'X'.
SELECT SINGLE FKDAT INTO GT_DATA-FKDAT FROM VBRK
WHERE SFAKN = GT_DATA-AWREF
.
IF GT_DATA-FKDAT+4(2) = P_MONAT.
DELETE GT_DATA .
ELSE .
MODIFY GT_DATA .
ENDIF.
ELSE .
MODIFY GT_DATA .
ENDIF.
CLEAR GT_DATA .
ENDLOOP.
*已开票数量:根据交货单(VBRP-VGBEL)、行项目(VBRP-VGPOS)、开票日期小于等于屏幕年度期间的前一期的最后一天;取数量(VBRP-FKLMG)、如果SHKZG等于X则对数量取负;
DATA GT_VBRP TYPE TABLE OF VBRP WITH HEADER LINE .
GT_DATA_A[] = GT_DATA[] .
SORT GT_DATA_A[] BY VGBEL VGPOS .
DELETE ADJACENT DUPLICATES FROM GT_DATA_A[] COMPARING VGBEL VGPOS.
*根据交货单、行项目、开票日期在屏幕年度期间内、已取消(FKSTO)等于X或取消票据(SFAKN)不等于空;取相关数据,如果SHKZG等于X则对数量取负,再根据交货单(VBRP-VGBEL)、行项目(VBRP-VGPOS)汇总数量赋给已开票数量。
CLEAR GT_VBRP[] .
SELECT
VBRP~VBELN
VBRP~POSNR
VBRP~VGBEL
VBRP~VGPOS
VBRP~FKLMG
VBRP~SHKZG
INTO CORRESPONDING FIELDS OF TABLE GT_VBRP[]
FROM VBRK
INNER JOIN VBRP ON VBRP~VBELN = VBRK~VBELN
FOR ALL ENTRIES IN GT_DATA_A[]
WHERE VBRP~VGBEL = GT_DATA_A-VGBEL
AND VBRP~VGPOS = GT_DATA_A-VGPOS
AND VBRK~FKDAT < U_BUDAT
AND VBRK~FKDAT => Y_BUDAT
AND VBRK~FKSTO <> 'X'
AND VBRK~SFAKN = ''
.
*交货单发差金额:根据公司代码、科目(ACDOCA- RACCT)等于1406010500、分配(ZUONR)等于交货单与行项目的组合,取金额(ACDOCA-HSL),按照交货单、行项目汇总金额赋给交货单发差金额;
DATA GT_ACDOCA TYPE TABLE OF ACDOCA WITH HEADER LINE .
CLEAR GT_ACDOCA[] .
SELECT
ACDOCA~RLDNR
ACDOCA~RBUKRS
ACDOCA~GJAHR
ACDOCA~BELNR
ACDOCA~DOCLN
ACDOCA~ZUONR
ACDOCA~HSL
INTO CORRESPONDING FIELDS OF TABLE GT_ACDOCA[]
FROM ACDOCA
FOR ALL ENTRIES IN GT_DATA_A[]
WHERE ACDOCA~ZUONR = GT_DATA_A-ZUONR
AND ACDOCA~RACCT = '1406010500'
.
LOOP AT GT_DATA_A.
CLEAR GT_DATA_A-YKLMG .
LOOP AT GT_VBRP WHERE VGBEL = GT_DATA_A-VGBEL AND VGPOS = GT_DATA_A-VGPOS.
IF GT_VBRP-SHKZG = 'X'.
GT_VBRP-FKLMG = GT_VBRP-FKLMG * -1 .
ENDIF.
GT_DATA_A-YKLMG = GT_DATA_A-YKLMG + GT_VBRP-FKLMG .
CLEAR GT_VBRP .
ENDLOOP.
CLEAR GT_DATA_A-HSL .
LOOP AT GT_ACDOCA WHERE ZUONR = GT_DATA_A-ZUONR .
GT_DATA_A-HSL = GT_DATA_A-HSL + GT_ACDOCA-HSL .
CLEAR GT_ACDOCA .
ENDLOOP.
MODIFY GT_DATA_A .
CLEAR GT_DATA_A .
ENDLOOP.
SORT GT_DATA[] BY VGBEL VGPOS .
LOOP AT GT_DATA.
*倒挤分摊金额:
DATA GV_HSLC TYPE ACDOCA-HSL.
DATA GV_YKLMG TYPE VBRP-FKLMG.
CLEAR GLAG_N .
CLEAR GLAG_E .
AT NEW VGPOS .
GLAG_N = 'X' .
ENDAT .
AT END OF VGPOS .
GLAG_E = 'X' .
ENDAT .
IF GT_DATA-SHKZG = 'X'.
GT_DATA-FKLMG = GT_DATA-FKLMG * -1 .
ENDIF.
IF GT_DATA-SHKZGL = 'X'.
GT_DATA-LGMNG = GT_DATA-LGMNG * -1 .
ENDIF.
READ TABLE GT_DATA_A WITH KEY VGBEL = GT_DATA-VGBEL VGPOS = GT_DATA-VGPOS .
IF SY-SUBRC = 0.
GT_DATA-YKLMG = GT_DATA_A-YKLMG . "已开票数量
GT_DATA-HSL = GT_DATA_A-HSL . "交货单发差金额
ENDIF.
IF GLAG_N IS NOT INITIAL.
GV_YKLMG = GT_DATA-LGMNG - GT_DATA-YKLMG .
GV_HSLC = GT_DATA-HSL .
ENDIF.
*分摊金额: 交货单发差金额 乘以 开票数量 除以 (交货数量 减去 已开票数量);如果交货单、行项目的交货数量减去已开票数量等于其 对应的相应开票的开票数量合计时,其对应的开票的分摊金额通过倒挤方式计算得到,避免分摊不净;
IF GLAG_E IS NOT INITIAL.
IF GV_YKLMG = GT_DATA-FKLMG.
GT_DATA-FTHSL = GV_HSLC .
ELSE .
GT_DATA-FTHSL = GT_DATA-HSL * GT_DATA-FKLMG / ( GT_DATA-LGMNG - GT_DATA-YKLMG ) .
ENDIF.
ELSE .
GT_DATA-FTHSL = GT_DATA-HSL * GT_DATA-FKLMG / ( GT_DATA-LGMNG - GT_DATA-YKLMG ) .
GV_HSLC = GV_HSLC - GT_DATA-FTHSL .
GV_YKLMG = GV_YKLMG - GT_DATA-FKLMG .
ENDIF.
*过账日期:默认屏幕年度、期间的最后一天
GT_DATA-BUDAT = P_BUDAT .
MODIFY GT_DATA .
CLEAR GT_DATA .
CLEAR GT_DATA_A .
ENDLOOP.
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 = 'PLNBEZ' OR wa_fieldcat-fieldname = 'MATNR' .
wa_fieldcat-ref_tabname = 'MARA'.
wa_fieldcat-ref_fieldname = 'MATNR'.
ENDIF.
IF wa_fieldcat-fieldname = 'ARKTX' OR wa_fieldcat-fieldname = 'WAKTX' .
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 :
'RBUKRS' '公司代码',
'GJAHR' '年度',
'POPER' '期间',
'WERKS' '工厂',
'PRCTR' '利润中心',
'KUNAG' '客户',
'VBUND' '贸易伙伴',
'MATNR' '物料',
'MAKTG' '物料描述',
'RACCT' '成本科目',
'RHCUR' '币别',
'AWREF' '开票',
'AWITEM' '开票行项目',
'FKLMG' '开票数量',
'YKLMG' '已开票数量',
'MEINS' '单位',
'VGBEL' '交货单',
'VGPOS' '行项目',
'LGMNG' '交货数量',
'WADAT_IST' '交货日期',
'HSL' '交货单发差金额',
'FTHSL' '分摊金额',
'BUDAT' '过账日期'.
* 'BELNR' '会计凭证'.
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 'POST_T'.
CLEAR GT_RETURN[] .
PERFORM FRM_DATA_POST_T .
LOOP AT GT_RETURN WHERE TYPE = 'E'.
ENDLOOP.
IF SY-SUBRC = 0.
DEMO=>MAIN( ).
ELSE .
MESSAGE '模拟过账成功,可以进行正式过账!' TYPE 'S' .
ENDIF.
WHEN 'POST'.
IF GT_RETURN[] IS INITIAL.
MESSAGE '请先进行模拟过账!' TYPE 'S' DISPLAY LIKE 'W'.
ELSE .
LOOP AT GT_RETURN WHERE TYPE = 'E'.
ENDLOOP.
IF SY-SUBRC = 0.
MESSAGE '模拟过账时出错!' TYPE 'S' DISPLAY LIKE 'E'.
ELSE .
CLEAR GT_ZTFI121 .
SELECT SINGLE * INTO CORRESPONDING FIELDS OF GT_ZTFI121 FROM ZTFI121
WHERE RBUKRS = P_BUKRS
AND FISCYEARPER = P_BUDAT(6)
.
DATA LV_FLAG TYPE C .
CLEAR LV_FLAG .
SELECT SINGLE ZFLAG INTO LV_FLAG FROM ZTIR094
WHERE ZPNAME = 'ZFI121'
.
IF LV_FLAG IS NOT INITIAL.
IF GT_ZTFI121 IS NOT INITIAL.
MESSAGE '当前选择的期间已经过账,不能重复执行!' TYPE 'S' DISPLAY LIKE 'E'.
ELSE .
CLEAR GT_RETURN[] .
PERFORM FRM_DATA_POST .
LOOP AT GT_RETURN WHERE TYPE = 'E'.
ENDLOOP.
IF SY-SUBRC = 0.
DEMO=>MAIN( ).
ELSE .
CLEAR GT_ZTFI121[].
LOOP AT GT_DATA.
MOVE-CORRESPONDING GT_DATA TO GT_ZTFI121 .
GT_ZTFI121-FISCYEARPER = P_BUDAT(6) .
APPEND GT_ZTFI121 .
CLEAR GT_ZTFI121 .
ENDLOOP.
MODIFY ZTFI121 FROM TABLE GT_ZTFI121[] .
COMMIT WORK .
MESSAGE '期间过账成功' TYPE 'S' .
ENDIF.
ENDIF.
ELSE .
CLEAR GT_RETURN[] .
PERFORM FRM_DATA_POST .
LOOP AT GT_RETURN WHERE TYPE = 'E'.
ENDLOOP.
IF SY-SUBRC = 0.
DEMO=>MAIN( ).
ELSE .
CLEAR GT_ZTFI121[].
LOOP AT GT_DATA.
MOVE-CORRESPONDING GT_DATA TO GT_ZTFI121 .
GT_ZTFI121-FISCYEARPER = P_BUDAT(6) .
APPEND GT_ZTFI121 .
CLEAR GT_ZTFI121 .
ENDLOOP.
MODIFY ZTFI121 FROM TABLE GT_ZTFI121[] .
COMMIT WORK .
MESSAGE '期间过账成功' TYPE 'S' .
ENDIF.
IF GT_ZTFI121 IS NOT INITIAL.
MESSAGE '当前选择的期间已经过账,未启用重复过帐检查!' TYPE 'W' .
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDCASE.
CALL METHOD REF->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LV_STABLE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_DATA_POST_T
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_DATA_POST_T .
DATA:
TEMP_MONTH(2), "输入月份
HEADER_TXT(25), "取会计年月+固定文本“制费及研发费分摊”
TEMP_AUT_MSG(30),
LAST_DATA LIKE SY-DATUM, "一个月的最后一天
TEMP_OBJ_KEY TYPE AWKEY, "是否生成
HEADER LIKE BAPIACHE09 OCCURS 0 WITH HEADER LINE,
WA_ACCOUNTGL LIKE BAPIACGL09 OCCURS 0 WITH HEADER LINE,
LT_ACCOUNTGL TYPE STANDARD TABLE OF BAPIACGL09,
WA_CURRENCY_AMOUNT LIKE BAPIACCR09 OCCURS 0 WITH HEADER LINE,
LT_CURRENCY_AMOUNT TYPE STANDARD TABLE OF BAPIACCR09 WITH HEADER LINE,
IT_EXTENSION2 TYPE STANDARD TABLE OF BAPIPAREX WITH HEADER LINE,
LT_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE,
GST_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE,
LS_ZFI002 TYPE ZFI002,
FT_FLAG , "= ‘X'表示分摊过
LV_ANSWER(1),
TEMP_BWTAR_AUFNR LIKE AFPO-AUFNR.
DATA: GS_EXTENSION2 TYPE ZSFI_EXTEN, "会计凭证过账增强extension2
LT_EXTENSION2 TYPE TABLE OF BAPIPAREX WITH HEADER LINE. "返回参数
DATA: LV_OBJ_TYPE LIKE BAPIACHE09-OBJ_TYPE,
LV_OBJ_KEY LIKE BAPIACHE09-OBJ_KEY,
LV_OBJ_SYS LIKE BAPIACHE09-OBJ_SYS.
DATA: LV_DMBTR TYPE BAPIWRBTR,
LV_LINES TYPE SY-TABIX,
ZCOUNT TYPE SY-TABIX,
ZCOUNTA TYPE SY-TABIX,
ZCOUNTB TYPE SY-TABIX,
ZCOUNTC TYPE SY-TABIX,
LV_WRBTR TYPE BSEG-WRBTR,
DO_POST TYPE CHAR1,
LS_EXTEN TYPE ZSFI_EXTEN.
DATA: LS_BKPF TYPE BKPF,
LS_REVERSAL TYPE BAPIACREV.
DATA: GV_OBJ_TYPE TYPE BAPIACHE09-OBJ_TYPE, "参考过程
GV_OBJ_KEY TYPE BAPIACHE09-OBJ_KEY, "对象键值
GV_OBJ_SYS TYPE BAPIACHE09-OBJ_SYS.
DATA LV_BELNR_01 TYPE BKPF-BELNR.
DATA LV_WAERS TYPE T001-WAERS.
CLEAR GST_RETURN[] .
*会计凭证抬头数据
CLEAR HEADER.
HEADER_TXT = '开票结转成本 ' .
HEADER-DOC_DATE = P_BUDAT. "凭证日期
HEADER-PSTNG_DATE = P_BUDAT. "凭证中的过帐日期
HEADER-USERNAME = SY-UNAME. "用户名
HEADER-DOC_TYPE = 'SA'. "凭证类型
HEADER-COMP_CODE = P_BUKRS. "公司代码
* HEADER-BUS_ACT = 'RFBU'. "业务事务
HEADER-FISC_YEAR = P_BUDAT(4). "财年
HEADER-FIS_PERIOD = P_BUDAT+4(2). "会计期间
HEADER-HEADER_TXT = HEADER_TXT. "凭证抬头文本
DATA LV_ROWCNT TYPE I.
DATA LV_ZCOUNT TYPE I.
DATA LV_ZCOUNT_01 TYPE I.
DESCRIBE TABLE GT_DATA[] LINES LV_ROWCNT.
CLEAR GST_RETURN .
IF LV_ROWCNT < 499.
LOOP AT GT_DATA.
* 写入分录1
ADD 1 TO LV_LINES.
CLEAR WA_CURRENCY_AMOUNT.
WA_CURRENCY_AMOUNT-ITEMNO_ACC = LV_LINES. "会计凭证行项目编号
WA_CURRENCY_AMOUNT-CURRENCY = GT_DATA-RHCUR. "货币码
WA_CURRENCY_AMOUNT-AMT_DOCCUR = GT_DATA-FTHSL * -1. "金额
APPEND WA_CURRENCY_AMOUNT TO LT_CURRENCY_AMOUNT .
CLEAR WA_ACCOUNTGL.
WA_ACCOUNTGL-ITEMNO_ACC = LV_LINES . "会计凭证行项目编号
WA_ACCOUNTGL-GL_ACCOUNT = '1406010500'. "科目
WA_ACCOUNTGL-ITEM_TEXT = HEADER_TXT. "项目文本
WA_ACCOUNTGL-PROFIT_CTR = GT_DATA-PRCTR. "利润中心
WA_ACCOUNTGL-PLANT = GT_DATA-WERKS. "工厂
WA_ACCOUNTGL-TRADE_ID = GT_DATA-VBUND. "贸易伙伴
WA_ACCOUNTGL-CUSTOMER = GT_DATA-KUNAG. "客户
WA_ACCOUNTGL-MATERIAL = GT_DATA-MATNR. "物料编号(18 个字符)
WA_ACCOUNTGL-BASE_UOM = GT_DATA-MEINS. "基本计量单位 个字符)
* WA_ACCOUNTGL-QUANTITY = GT_DATA-MENGE . "数量
WA_ACCOUNTGL-ALLOC_NMBR = GT_DATA-ZUONR . "分配号
APPEND WA_ACCOUNTGL TO LT_ACCOUNTGL.
CLEAR GS_EXTENSION2.
CLEAR LT_EXTENSION2.
GS_EXTENSION2-POSNR = LV_LINES.
IF GT_DATA-FTHSL > 0.
GS_EXTENSION2-BSCHL = '50'.
ELSE.
GS_EXTENSION2-BSCHL = '40'.
ENDIF.
GS_EXTENSION2-VBUND = GT_DATA-VBUND. "贸易伙伴
IF WA_ACCOUNTGL-ALLOC_NMBR IS NOT INITIAL.
* GS_EXTENSION2-MENGE = GT_DATA-ZMENGE. "数量
GS_EXTENSION2-MEINS = GT_DATA-MEINS. "基本计量单位
ENDIF.
LT_EXTENSION2-STRUCTURE = 'ZSFI_EXTEN'.
LT_EXTENSION2-VALUEPART1 = GS_EXTENSION2.
APPEND LT_EXTENSION2.
* 写入分录2
ADD 1 TO LV_LINES.
CLEAR WA_CURRENCY_AMOUNT.
WA_CURRENCY_AMOUNT-ITEMNO_ACC = LV_LINES. "会计凭证行项目编号
WA_CURRENCY_AMOUNT-CURRENCY = GT_DATA-RHCUR. "货币码
WA_CURRENCY_AMOUNT-AMT_DOCCUR = GT_DATA-FTHSL. "金额
APPEND WA_CURRENCY_AMOUNT TO LT_CURRENCY_AMOUNT .
CLEAR WA_ACCOUNTGL.
WA_ACCOUNTGL-ITEMNO_ACC = LV_LINES . "会计凭证行项目编号
WA_ACCOUNTGL-GL_ACCOUNT = GT_DATA-RACCT. "科目
WA_ACCOUNTGL-ITEM_TEXT = HEADER_TXT. "项目文本
WA_ACCOUNTGL-PROFIT_CTR = GT_DATA-PRCTR. "利润中心
WA_ACCOUNTGL-PLANT = GT_DATA-WERKS. "工厂
WA_ACCOUNTGL-TRADE_ID = GT_DATA-VBUND. "贸易伙伴
WA_ACCOUNTGL-CUSTOMER = GT_DATA-KUNAG. "客户
WA_ACCOUNTGL-MATERIAL = GT_DATA-MATNR. "物料编号(18 个字符)
WA_ACCOUNTGL-BASE_UOM = GT_DATA-MEINS. "基本计量单位 个字符)
* WA_ACCOUNTGL-QUANTITY = GT_DATA-MENGE . "数量
WA_ACCOUNTGL-ALLOC_NMBR = GT_DATA-ZUONR . "分配号
APPEND WA_ACCOUNTGL TO LT_ACCOUNTGL.
CLEAR GS_EXTENSION2.
CLEAR LT_EXTENSION2.
GS_EXTENSION2-POSNR = LV_LINES.
IF GT_DATA-FTHSL > 0.
GS_EXTENSION2-BSCHL = '40'.
ELSE.
GS_EXTENSION2-BSCHL = '50'.
ENDIF.
GS_EXTENSION2-VBUND = GT_DATA-VBUND. "贸易伙伴
IF WA_ACCOUNTGL-ALLOC_NMBR IS NOT INITIAL.
* GS_EXTENSION2-MENGE = GT_DATA-ZMENGE. "数量
GS_EXTENSION2-MEINS = GT_DATA-MEINS. "基本计量单位
ENDIF.
LT_EXTENSION2-STRUCTURE = 'ZSFI_EXTEN'.
LT_EXTENSION2-VALUEPART1 = GS_EXTENSION2.
APPEND LT_EXTENSION2.
ENDLOOP.
LOOP AT LT_CURRENCY_AMOUNT WHERE AMT_DOCCUR <> 0.
ENDLOOP.
IF SY-SUBRC = 0.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
EXPORTING
DOCUMENTHEADER = HEADER
* IMPORTING
* OBJ_TYPE = LV_OBJ_TYPE
* OBJ_KEY = LV_OBJ_KEY
* OBJ_SYS = LV_OBJ_SYS
TABLES
ACCOUNTGL = LT_ACCOUNTGL "总帐科目项
CURRENCYAMOUNT = LT_CURRENCY_AMOUNT "货币项目
EXTENSION2 = LT_EXTENSION2
RETURN = LT_RETURN. "返回值
CLEAR LT_RETURN.
LOOP AT LT_RETURN .
APPEND LT_RETURN TO GST_RETURN .
CLEAR LT_RETURN .
ENDLOOP.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
FREE:LT_ACCOUNTGL,LT_CURRENCY_AMOUNT,LT_RETURN.
ELSE .
LV_ZCOUNT = LV_ROWCNT.
CLEAR :LV_LINES,LV_ZCOUNT_01.
CLEAR ZCOUNT.
LOOP AT GT_DATA.
ZCOUNT = ZCOUNT + 1.
IF ZCOUNT > 499.
CLEAR:LT_ACCOUNTGL,LT_CURRENCY_AMOUNT,LT_EXTENSION2[],LT_RETURN.
LV_LINES = 0.
ZCOUNT = 1.
LV_ZCOUNT = LV_ROWCNT - LV_ZCOUNT_01.
CLEAR LV_LINES.
ENDIF.
LV_ZCOUNT_01 = LV_ZCOUNT_01 + 1.
* 写入借方
ADD 1 TO LV_LINES.
IF ( LV_ZCOUNT >= 499 AND ZCOUNT = 499 ) OR ( LV_ZCOUNT < 499 AND LV_ZCOUNT = ZCOUNT ) .
DO_POST = 'X'.
ENDIF.
* 写入分录1
CLEAR WA_CURRENCY_AMOUNT.
WA_CURRENCY_AMOUNT-ITEMNO_ACC = LV_LINES. "会计凭证行项目编号
WA_CURRENCY_AMOUNT-CURRENCY = GT_DATA-RHCUR. "货币码
WA_CURRENCY_AMOUNT-AMT_DOCCUR = GT_DATA-FTHSL * -1. "金额
APPEND WA_CURRENCY_AMOUNT TO LT_CURRENCY_AMOUNT .
CLEAR WA_ACCOUNTGL.
WA_ACCOUNTGL-ITEMNO_ACC = LV_LINES . "会计凭证行项目编号
WA_ACCOUNTGL-GL_ACCOUNT = '1406010500'. "科目
WA_ACCOUNTGL-ITEM_TEXT = HEADER_TXT. "项目文本
WA_ACCOUNTGL-PROFIT_CTR = GT_DATA-PRCTR. "利润中心
WA_ACCOUNTGL-PLANT = GT_DATA-WERKS. "工厂
WA_ACCOUNTGL-TRADE_ID = GT_DATA-VBUND. "贸易伙伴
WA_ACCOUNTGL-CUSTOMER = GT_DATA-KUNAG. "客户
WA_ACCOUNTGL-MATERIAL = GT_DATA-MATNR. "物料编号(18 个字符)
WA_ACCOUNTGL-BASE_UOM = GT_DATA-MEINS. "基本计量单位 个字符)
* WA_ACCOUNTGL-QUANTITY = GT_DATA-MENGE . "数量
WA_ACCOUNTGL-ALLOC_NMBR = GT_DATA-ZUONR . "分配号
APPEND WA_ACCOUNTGL TO LT_ACCOUNTGL.
CLEAR GS_EXTENSION2.
CLEAR LT_EXTENSION2.
GS_EXTENSION2-POSNR = LV_LINES.
IF GT_DATA-FTHSL > 0.
GS_EXTENSION2-BSCHL = '50'.
ELSE.
GS_EXTENSION2-BSCHL = '40'.
ENDIF.
GS_EXTENSION2-VBUND = GT_DATA-VBUND. "贸易伙伴
IF WA_ACCOUNTGL-ALLOC_NMBR IS NOT INITIAL.
* GS_EXTENSION2-MENGE = GT_DATA-ZMENGE. "数量
GS_EXTENSION2-MEINS = GT_DATA-MEINS. "基本计量单位
ENDIF.
LT_EXTENSION2-STRUCTURE = 'ZSFI_EXTEN'.
LT_EXTENSION2-VALUEPART1 = GS_EXTENSION2.
APPEND LT_EXTENSION2.
* 写入分录2
ADD 1 TO LV_LINES.
CLEAR WA_CURRENCY_AMOUNT.
WA_CURRENCY_AMOUNT-ITEMNO_ACC = LV_LINES. "会计凭证行项目编号
WA_CURRENCY_AMOUNT-CURRENCY = GT_DATA-RHCUR. "货币码
WA_CURRENCY_AMOUNT-AMT_DOCCUR = GT_DATA-FTHSL. "金额
APPEND WA_CURRENCY_AMOUNT TO LT_CURRENCY_AMOUNT .
CLEAR WA_ACCOUNTGL.
WA_ACCOUNTGL-ITEMNO_ACC = LV_LINES . "会计凭证行项目编号
WA_ACCOUNTGL-GL_ACCOUNT = GT_DATA-RACCT. "科目
WA_ACCOUNTGL-ITEM_TEXT = HEADER_TXT. "项目文本
WA_ACCOUNTGL-PROFIT_CTR = GT_DATA-PRCTR. "利润中心
WA_ACCOUNTGL-PLANT = GT_DATA-WERKS. "工厂
WA_ACCOUNTGL-TRADE_ID = GT_DATA-VBUND. "贸易伙伴
WA_ACCOUNTGL-CUSTOMER = GT_DATA-KUNAG. "客户
WA_ACCOUNTGL-MATERIAL = GT_DATA-MATNR. "物料编号(18 个字符)
WA_ACCOUNTGL-BASE_UOM = GT_DATA-MEINS. "基本计量单位 个字符)
* WA_ACCOUNTGL-QUANTITY = GT_DATA-MENGE . "数量
WA_ACCOUNTGL-ALLOC_NMBR = GT_DATA-ZUONR . "分配号
APPEND WA_ACCOUNTGL TO LT_ACCOUNTGL.
CLEAR GS_EXTENSION2.
CLEAR LT_EXTENSION2.
GS_EXTENSION2-POSNR = LV_LINES.
IF GT_DATA-FTHSL > 0.
GS_EXTENSION2-BSCHL = '40'.
ELSE.
GS_EXTENSION2-BSCHL = '50'.
ENDIF.
GS_EXTENSION2-VBUND = GT_DATA-VBUND. "贸易伙伴
IF WA_ACCOUNTGL-ALLOC_NMBR IS NOT INITIAL.
* GS_EXTENSION2-MENGE = GT_DATA-ZMENGE. "数量
GS_EXTENSION2-MEINS = GT_DATA-MEINS. "基本计量单位
ENDIF.
LT_EXTENSION2-STRUCTURE = 'ZSFI_EXTEN'.
LT_EXTENSION2-VALUEPART1 = GS_EXTENSION2.
APPEND LT_EXTENSION2.
IF DO_POST = 'X'.
LOOP AT LT_CURRENCY_AMOUNT WHERE AMT_DOCCUR <> 0.
ENDLOOP.
IF SY-SUBRC = 0.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
EXPORTING
DOCUMENTHEADER = HEADER
* IMPORTING
* OBJ_TYPE = LV_OBJ_TYPE
* OBJ_KEY = LV_OBJ_KEY
* OBJ_SYS = LV_OBJ_SYS
TABLES
ACCOUNTGL = LT_ACCOUNTGL "总帐科目项
CURRENCYAMOUNT = LT_CURRENCY_AMOUNT "货币项目
EXTENSION2 = LT_EXTENSION2
RETURN = LT_RETURN. "返回值
CLEAR LT_RETURN.
LOOP AT LT_RETURN .
APPEND LT_RETURN TO GST_RETURN .
CLEAR LT_RETURN .
ENDLOOP.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
FREE:LT_ACCOUNTGL,LT_CURRENCY_AMOUNT,LT_RETURN.
DO_POST = ''.
ENDIF.
ENDLOOP.
ENDIF.
SORT GST_RETURN[] BY MESSAGE .
DELETE ADJACENT DUPLICATES FROM GST_RETURN[] COMPARING MESSAGE.
LOOP AT GST_RETURN.
GST_RETURN-MESSAGE = '模拟过账:开票结转成本 ' && GST_RETURN-MESSAGE .
APPEND GST_RETURN TO GT_RETURN .
CLEAR GST_RETURN .
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_DATA_POST
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_DATA_POST .
DATA:
TEMP_MONTH(2), "输入月份
HEADER_TXT(25), "取会计年月+固定文本“制费及研发费分摊”
TEMP_AUT_MSG(30),
LAST_DATA LIKE SY-DATUM, "一个月的最后一天
TEMP_OBJ_KEY TYPE AWKEY, "是否生成
HEADER LIKE BAPIACHE09 OCCURS 0 WITH HEADER LINE,
WA_ACCOUNTGL LIKE BAPIACGL09 OCCURS 0 WITH HEADER LINE,
LT_ACCOUNTGL TYPE STANDARD TABLE OF BAPIACGL09,
WA_CURRENCY_AMOUNT LIKE BAPIACCR09 OCCURS 0 WITH HEADER LINE,
LT_CURRENCY_AMOUNT TYPE STANDARD TABLE OF BAPIACCR09 WITH HEADER LINE,
IT_EXTENSION2 TYPE STANDARD TABLE OF BAPIPAREX WITH HEADER LINE,
LT_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE,
GST_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE,
LS_ZFI002 TYPE ZFI002,
FT_FLAG , "= ‘X'表示分摊过
LV_ANSWER(1),
TEMP_BWTAR_AUFNR LIKE AFPO-AUFNR.
DATA: GS_EXTENSION2 TYPE ZSFI_EXTEN, "会计凭证过账增强extension2
LT_EXTENSION2 TYPE TABLE OF BAPIPAREX WITH HEADER LINE. "返回参数
DATA: LV_OBJ_TYPE LIKE BAPIACHE09-OBJ_TYPE,
LV_OBJ_KEY LIKE BAPIACHE09-OBJ_KEY,
LV_OBJ_SYS LIKE BAPIACHE09-OBJ_SYS.
DATA: LV_DMBTR TYPE BAPIWRBTR,
LV_LINES TYPE SY-TABIX,
ZCOUNT TYPE SY-TABIX,
ZCOUNTA TYPE SY-TABIX,
ZCOUNTB TYPE SY-TABIX,
ZCOUNTC TYPE SY-TABIX,
LV_WRBTR TYPE BSEG-WRBTR,
DO_POST TYPE CHAR1,
LS_EXTEN TYPE ZSFI_EXTEN.
DATA: LS_BKPF TYPE BKPF,
LS_REVERSAL TYPE BAPIACREV.
DATA: GV_OBJ_TYPE TYPE BAPIACHE09-OBJ_TYPE, "参考过程
GV_OBJ_KEY TYPE BAPIACHE09-OBJ_KEY, "对象键值
GV_OBJ_SYS TYPE BAPIACHE09-OBJ_SYS.
DATA LV_BELNR_01 TYPE BKPF-BELNR.
DATA LV_WAERS TYPE T001-WAERS.
CLEAR GST_RETURN[] .
*会计凭证抬头数据
CLEAR HEADER.
HEADER_TXT = '开票结转成本 ' .
HEADER-DOC_DATE = P_BUDAT. "凭证日期
HEADER-PSTNG_DATE = P_BUDAT. "凭证中的过帐日期
HEADER-USERNAME = SY-UNAME. "用户名
HEADER-DOC_TYPE = 'SA'. "凭证类型
HEADER-COMP_CODE = P_BUKRS. "公司代码
* HEADER-BUS_ACT = 'RFBU'. "业务事务
HEADER-FISC_YEAR = P_BUDAT(4). "财年
HEADER-FIS_PERIOD = P_BUDAT+4(2). "会计期间
HEADER-HEADER_TXT = HEADER_TXT. "凭证抬头文本
DATA LV_ROWCNT TYPE I.
DATA LV_ZCOUNT TYPE I.
DATA LV_ZCOUNT_01 TYPE I.
DESCRIBE TABLE GT_DATA[] LINES LV_ROWCNT.
CLEAR GST_RETURN .
IF LV_ROWCNT < 499.
LOOP AT GT_DATA.
* 写入分录1
ADD 1 TO LV_LINES.
CLEAR WA_CURRENCY_AMOUNT.
WA_CURRENCY_AMOUNT-ITEMNO_ACC = LV_LINES. "会计凭证行项目编号
WA_CURRENCY_AMOUNT-CURRENCY = GT_DATA-RHCUR. "货币码
WA_CURRENCY_AMOUNT-AMT_DOCCUR = GT_DATA-FTHSL * -1. "金额
APPEND WA_CURRENCY_AMOUNT TO LT_CURRENCY_AMOUNT .
CLEAR WA_ACCOUNTGL.
WA_ACCOUNTGL-ITEMNO_ACC = LV_LINES . "会计凭证行项目编号
WA_ACCOUNTGL-GL_ACCOUNT = '1406010500'. "科目
WA_ACCOUNTGL-ITEM_TEXT = HEADER_TXT. "项目文本
WA_ACCOUNTGL-PROFIT_CTR = GT_DATA-PRCTR. "利润中心
WA_ACCOUNTGL-PLANT = GT_DATA-WERKS. "工厂
WA_ACCOUNTGL-TRADE_ID = GT_DATA-VBUND. "贸易伙伴
WA_ACCOUNTGL-CUSTOMER = GT_DATA-KUNAG. "客户
WA_ACCOUNTGL-MATERIAL = GT_DATA-MATNR. "物料编号(18 个字符)
WA_ACCOUNTGL-BASE_UOM = GT_DATA-MEINS. "基本计量单位 个字符)
* WA_ACCOUNTGL-QUANTITY = GT_DATA-MENGE . "数量
WA_ACCOUNTGL-ALLOC_NMBR = GT_DATA-ZUONR . "分配号
APPEND WA_ACCOUNTGL TO LT_ACCOUNTGL.
CLEAR GS_EXTENSION2.
CLEAR LT_EXTENSION2.
GS_EXTENSION2-POSNR = LV_LINES.
IF GT_DATA-FTHSL > 0.
GS_EXTENSION2-BSCHL = '50'.
ELSE.
GS_EXTENSION2-BSCHL = '40'.
ENDIF.
GS_EXTENSION2-VBUND = GT_DATA-VBUND. "贸易伙伴
IF WA_ACCOUNTGL-ALLOC_NMBR IS NOT INITIAL.
* GS_EXTENSION2-MENGE = GT_DATA-ZMENGE. "数量
GS_EXTENSION2-MEINS = GT_DATA-MEINS. "基本计量单位
ENDIF.
LT_EXTENSION2-STRUCTURE = 'ZSFI_EXTEN'.
LT_EXTENSION2-VALUEPART1 = GS_EXTENSION2.
APPEND LT_EXTENSION2.
* 写入分录2
ADD 1 TO LV_LINES.
CLEAR WA_CURRENCY_AMOUNT.
WA_CURRENCY_AMOUNT-ITEMNO_ACC = LV_LINES. "会计凭证行项目编号
WA_CURRENCY_AMOUNT-CURRENCY = GT_DATA-RHCUR. "货币码
WA_CURRENCY_AMOUNT-AMT_DOCCUR = GT_DATA-FTHSL. "金额
APPEND WA_CURRENCY_AMOUNT TO LT_CURRENCY_AMOUNT .
CLEAR WA_ACCOUNTGL.
WA_ACCOUNTGL-ITEMNO_ACC = LV_LINES . "会计凭证行项目编号
WA_ACCOUNTGL-GL_ACCOUNT = GT_DATA-RACCT. "科目
WA_ACCOUNTGL-ITEM_TEXT = HEADER_TXT. "项目文本
WA_ACCOUNTGL-PROFIT_CTR = GT_DATA-PRCTR. "利润中心
WA_ACCOUNTGL-PLANT = GT_DATA-WERKS. "工厂
WA_ACCOUNTGL-TRADE_ID = GT_DATA-VBUND. "贸易伙伴
WA_ACCOUNTGL-CUSTOMER = GT_DATA-KUNAG. "客户
WA_ACCOUNTGL-MATERIAL = GT_DATA-MATNR. "物料编号(18 个字符)
WA_ACCOUNTGL-BASE_UOM = GT_DATA-MEINS. "基本计量单位 个字符)
* WA_ACCOUNTGL-QUANTITY = GT_DATA-MENGE . "数量
WA_ACCOUNTGL-ALLOC_NMBR = GT_DATA-ZUONR . "分配号
APPEND WA_ACCOUNTGL TO LT_ACCOUNTGL.
CLEAR GS_EXTENSION2.
CLEAR LT_EXTENSION2.
GS_EXTENSION2-POSNR = LV_LINES.
IF GT_DATA-FTHSL > 0.
GS_EXTENSION2-BSCHL = '40'.
ELSE.
GS_EXTENSION2-BSCHL = '50'.
ENDIF.
GS_EXTENSION2-VBUND = GT_DATA-VBUND. "贸易伙伴
IF WA_ACCOUNTGL-ALLOC_NMBR IS NOT INITIAL.
* GS_EXTENSION2-MENGE = GT_DATA-ZMENGE. "数量
GS_EXTENSION2-MEINS = GT_DATA-MEINS. "基本计量单位
ENDIF.
LT_EXTENSION2-STRUCTURE = 'ZSFI_EXTEN'.
LT_EXTENSION2-VALUEPART1 = GS_EXTENSION2.
APPEND LT_EXTENSION2.
ENDLOOP.
LOOP AT LT_CURRENCY_AMOUNT WHERE AMT_DOCCUR <> 0.
ENDLOOP.
IF SY-SUBRC = 0.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
DOCUMENTHEADER = HEADER
IMPORTING
OBJ_TYPE = LV_OBJ_TYPE
OBJ_KEY = LV_OBJ_KEY
OBJ_SYS = LV_OBJ_SYS
TABLES
ACCOUNTGL = LT_ACCOUNTGL "总帐科目项
CURRENCYAMOUNT = LT_CURRENCY_AMOUNT "货币项目
EXTENSION2 = LT_EXTENSION2
RETURN = LT_RETURN. "返回值
CLEAR LT_RETURN.
LOOP AT LT_RETURN .
APPEND LT_RETURN TO GST_RETURN .
CLEAR LT_RETURN .
ENDLOOP.
LOOP AT LT_RETURN WHERE TYPE = 'E'.
ENDLOOP.
IF SY-SUBRC = 0 .
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
ENDIF.
ENDIF .
FREE:LT_ACCOUNTGL,LT_CURRENCY_AMOUNT,LT_RETURN.
ELSE .
LV_ZCOUNT = LV_ROWCNT.
CLEAR :LV_LINES,LV_ZCOUNT_01.
CLEAR ZCOUNT.
LOOP AT GT_DATA.
ZCOUNT = ZCOUNT + 1.
IF ZCOUNT > 499.
CLEAR:LT_ACCOUNTGL,LT_CURRENCY_AMOUNT,LT_EXTENSION2[],LT_RETURN.
LV_LINES = 0.
ZCOUNT = 1.
LV_ZCOUNT = LV_ROWCNT - LV_ZCOUNT_01.
CLEAR LV_LINES.
ENDIF.
LV_ZCOUNT_01 = LV_ZCOUNT_01 + 1.
* 写入借方
ADD 1 TO LV_LINES.
IF ( LV_ZCOUNT >= 499 AND ZCOUNT = 499 ) OR ( LV_ZCOUNT < 499 AND LV_ZCOUNT = ZCOUNT ) .
DO_POST = 'X'.
ENDIF.
* 写入分录1
CLEAR WA_CURRENCY_AMOUNT.
WA_CURRENCY_AMOUNT-ITEMNO_ACC = LV_LINES. "会计凭证行项目编号
WA_CURRENCY_AMOUNT-CURRENCY = GT_DATA-RHCUR. "货币码
WA_CURRENCY_AMOUNT-AMT_DOCCUR = GT_DATA-FTHSL * -1. "金额
APPEND WA_CURRENCY_AMOUNT TO LT_CURRENCY_AMOUNT .
CLEAR WA_ACCOUNTGL.
WA_ACCOUNTGL-ITEMNO_ACC = LV_LINES . "会计凭证行项目编号
WA_ACCOUNTGL-GL_ACCOUNT = '1406010500'. "科目
WA_ACCOUNTGL-ITEM_TEXT = HEADER_TXT. "项目文本
WA_ACCOUNTGL-PROFIT_CTR = GT_DATA-PRCTR. "利润中心
WA_ACCOUNTGL-PLANT = GT_DATA-WERKS. "工厂
WA_ACCOUNTGL-TRADE_ID = GT_DATA-VBUND. "贸易伙伴
WA_ACCOUNTGL-CUSTOMER = GT_DATA-KUNAG. "客户
WA_ACCOUNTGL-MATERIAL = GT_DATA-MATNR. "物料编号(18 个字符)
WA_ACCOUNTGL-BASE_UOM = GT_DATA-MEINS. "基本计量单位 个字符)
* WA_ACCOUNTGL-QUANTITY = GT_DATA-MENGE . "数量
WA_ACCOUNTGL-ALLOC_NMBR = GT_DATA-ZUONR . "分配号
APPEND WA_ACCOUNTGL TO LT_ACCOUNTGL.
CLEAR GS_EXTENSION2.
CLEAR LT_EXTENSION2.
GS_EXTENSION2-POSNR = LV_LINES.
IF GT_DATA-FTHSL > 0.
GS_EXTENSION2-BSCHL = '50'.
ELSE.
GS_EXTENSION2-BSCHL = '40'.
ENDIF.
GS_EXTENSION2-VBUND = GT_DATA-VBUND. "贸易伙伴
IF WA_ACCOUNTGL-ALLOC_NMBR IS NOT INITIAL.
* GS_EXTENSION2-MENGE = GT_DATA-ZMENGE. "数量
GS_EXTENSION2-MEINS = GT_DATA-MEINS. "基本计量单位
ENDIF.
LT_EXTENSION2-STRUCTURE = 'ZSFI_EXTEN'.
LT_EXTENSION2-VALUEPART1 = GS_EXTENSION2.
APPEND LT_EXTENSION2.
* 写入分录2
ADD 1 TO LV_LINES.
CLEAR WA_CURRENCY_AMOUNT.
WA_CURRENCY_AMOUNT-ITEMNO_ACC = LV_LINES. "会计凭证行项目编号
WA_CURRENCY_AMOUNT-CURRENCY = GT_DATA-RHCUR. "货币码
WA_CURRENCY_AMOUNT-AMT_DOCCUR = GT_DATA-FTHSL. "金额
APPEND WA_CURRENCY_AMOUNT TO LT_CURRENCY_AMOUNT .
CLEAR WA_ACCOUNTGL.
WA_ACCOUNTGL-ITEMNO_ACC = LV_LINES . "会计凭证行项目编号
WA_ACCOUNTGL-GL_ACCOUNT = GT_DATA-RACCT. "科目
WA_ACCOUNTGL-ITEM_TEXT = HEADER_TXT. "项目文本
WA_ACCOUNTGL-PROFIT_CTR = GT_DATA-PRCTR. "利润中心
WA_ACCOUNTGL-PLANT = GT_DATA-WERKS. "工厂
WA_ACCOUNTGL-TRADE_ID = GT_DATA-VBUND. "贸易伙伴
WA_ACCOUNTGL-CUSTOMER = GT_DATA-KUNAG. "客户
WA_ACCOUNTGL-MATERIAL = GT_DATA-MATNR. "物料编号(18 个字符)
WA_ACCOUNTGL-BASE_UOM = GT_DATA-MEINS. "基本计量单位 个字符)
* WA_ACCOUNTGL-QUANTITY = GT_DATA-MENGE . "数量
WA_ACCOUNTGL-ALLOC_NMBR = GT_DATA-ZUONR . "分配号
APPEND WA_ACCOUNTGL TO LT_ACCOUNTGL.
CLEAR GS_EXTENSION2.
CLEAR LT_EXTENSION2.
GS_EXTENSION2-POSNR = LV_LINES.
IF GT_DATA-FTHSL > 0.
GS_EXTENSION2-BSCHL = '40'.
ELSE.
GS_EXTENSION2-BSCHL = '50'.
ENDIF.
GS_EXTENSION2-VBUND = GT_DATA-VBUND. "贸易伙伴
IF WA_ACCOUNTGL-ALLOC_NMBR IS NOT INITIAL.
* GS_EXTENSION2-MENGE = GT_DATA-ZMENGE. "数量
GS_EXTENSION2-MEINS = GT_DATA-MEINS. "基本计量单位
ENDIF.
LT_EXTENSION2-STRUCTURE = 'ZSFI_EXTEN'.
LT_EXTENSION2-VALUEPART1 = GS_EXTENSION2.
APPEND LT_EXTENSION2.
IF DO_POST = 'X'.
LOOP AT LT_CURRENCY_AMOUNT WHERE AMT_DOCCUR <> 0.
ENDLOOP.
IF SY-SUBRC = 0.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
DOCUMENTHEADER = HEADER
IMPORTING
OBJ_TYPE = LV_OBJ_TYPE
OBJ_KEY = LV_OBJ_KEY
OBJ_SYS = LV_OBJ_SYS
TABLES
ACCOUNTGL = LT_ACCOUNTGL "总帐科目项
CURRENCYAMOUNT = LT_CURRENCY_AMOUNT "货币项目
EXTENSION2 = LT_EXTENSION2
RETURN = LT_RETURN. "返回值
CLEAR LT_RETURN.
LOOP AT LT_RETURN .
APPEND LT_RETURN TO GST_RETURN .
CLEAR LT_RETURN .
ENDLOOP.
LOOP AT LT_RETURN WHERE TYPE = 'E'.
ENDLOOP.
IF SY-SUBRC = 0 .
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
ENDIF.
ENDIF .
CLEAR:LT_ACCOUNTGL[],LT_CURRENCY_AMOUNT[],LT_EXTENSION2[],LT_RETURN[].
CLEAR LV_LINES .
DO_POST = ''.
ENDIF.
ENDLOOP.
*
ENDIF.
SORT GST_RETURN[] BY MESSAGE .
DELETE ADJACENT DUPLICATES FROM GST_RETURN[] COMPARING MESSAGE.
LOOP AT GST_RETURN.
GST_RETURN-MESSAGE = '正式过账:开票结转成本 ' && GST_RETURN-MESSAGE .
APPEND GST_RETURN TO GT_RETURN .
CLEAR GST_RETURN .
ENDLOOP.
ENDFORM.
INITIALIZATION.
PERFORM FRM_EXCLUDE_OPTION.
AT SELECTION-SCREEN OUTPUT.
PERFORM SCREEN_OUTPUT.
AT SELECTION-SCREEN.
PERFORM SCREEN_SETTING.
START-OF-SELECTION.
PERFORM FOM_GETDATA.
PERFORM FRM_DISPLAY.
FI—开票后发出商品-差异处理(开发笔记)
最新推荐文章于 2024-03-12 13:54:26 发布