*&---------------------------------------------------------------------*
*& Report ZFIR123
*&---------------------------------------------------------------------*
*& Author : NathanSun
*& Create Date : 2019-03-14
*& Program Type : Report
*& Description : 交货单冲销发出商品-差异处理
*&---------------------------------------------------------------------*
REPORT ZFIR123.
*&---------------------------------------------------------------------*
*& 包含 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.
DATA: GT_SETLEAF TYPE TABLE OF ZSETLEAF WITH HEADER LINE.
TYPES: BEGIN OF GTS_DATA,
RBUKRS TYPE T001-BUKRS, "公司代码
GJAHR TYPE BKPF-GJAHR, "财年
MONAT TYPE BKPF-MONAT, "会计期间
WERKS TYPE ACDOCA-WERKS, "工厂
PRCTR TYPE ACDOCA-PRCTR, "利润中心
KUNNR TYPE ACDOCA-KUNNR, "客户
RASSC TYPE ACDOCA-RASSC, "贸易伙伴
MATNR TYPE ACDOCA-MATNR, "物料
RACCT TYPE ACDOCA-RACCT, "差异科目
RHCUR TYPE ACDOCA-RHCUR, "公司代码货币
VBELN_IM TYPE MSEG-VBELN_IM, "交货单
VBELP_IM TYPE MSEG-VBELP_IM, "行项目
ZUONR TYPE ACDOCA-ZUONR, "分配
MSL TYPE ACDOCA-MSL, "数量
RUNIT TYPE ACDOCA-RUNIT, "单位
HSL TYPE ACDOCA-HSL, "冲回金额
BUDAT TYPE ACDOCA-BUDAT, "过账日期
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: GT_DATA_B 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_ZTFI123 TYPE TABLE OF ZTFI123 WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS: P_BUKRS LIKE ACDOCA-RBUKRS MODIF ID C1 OBLIGATORY , "公司代码
P_GJAHR LIKE BKPF-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_SETLEAF[] .
SELECT * INTO CORRESPONDING FIELDS OF TABLE GT_SETLEAF[] FROM SETLEAF
WHERE SETNAME = 'ZFI002'
.
FIELD-SYMBOLS <GS_DATA> LIKE GT_DATA .
FIELD-SYMBOLS <GS_SETLEAF> LIKE GT_SETLEAF .
IF GT_SETLEAF[] IS NOT INITIAL.
LOOP AT GT_SETLEAF ASSIGNING <GS_SETLEAF>.
<GS_SETLEAF>-BWART = <GS_SETLEAF>-VALFROM .
ENDLOOP.
FREE <GS_SETLEAF> .
CLEAR GT_DATA_A[] .
SELECT BUKRS AS RBUKRS VBELN_IM VBELP_IM INTO CORRESPONDING FIELDS OF TABLE GT_DATA_A[] FROM MSEG
FOR ALL ENTRIES IN GT_SETLEAF[]
WHERE BWART = GT_SETLEAF-BWART
AND BUKRS = P_BUKRS
AND BUDAT_MKPF >= U_BUDAT
AND BUDAT_MKPF <= P_BUDAT
AND SMBLN <> ''
.
LOOP AT GT_DATA_A ASSIGNING <GS_DATA>.
<GS_DATA>-ZUONR = <GS_DATA>-VBELN_IM && <GS_DATA>-VBELP_IM .
ENDLOOP.
FREE <GS_DATA> .
ENDIF.
IF GT_DATA_A[] IS NOT INITIAL.
SORT GT_DATA_A[] BY RBUKRS VBELN_IM VBELP_IM .
DELETE ADJACENT DUPLICATES FROM GT_DATA_A[] COMPARING VBELN_IM VBELP_IM.
CLEAR GT_DATA[] .
SELECT
ACDOCA~RBUKRS
ACDOCA~WERKS
ACDOCA~KUNNR
ACDOCA~RASSC
ACDOCA~MATNR
ACDOCA~RACCT
ACDOCA~RHCUR
ACDOCA~ZUONR
ACDOCA~MSL
ACDOCA~RUNIT
ACDOCA~HSL
ACDOCA~BUDAT
INTO CORRESPONDING FIELDS OF TABLE GT_DATA[]
FROM ACDOCA
FOR ALL ENTRIES IN GT_DATA_A[]
WHERE ACDOCA~ZUONR = GT_DATA_A-ZUONR
AND ACDOCA~RBUKRS = P_BUKRS
AND ACDOCA~RACCT = '1406010500'
AND ACDOCA~BUDAT >= U_BUDAT
AND ACDOCA~BUDAT <= P_BUDAT
.
SORT GT_DATA[] BY ZUONR .
GT_DATA_B[] = GT_DATA[] .
DELETE ADJACENT DUPLICATES FROM GT_DATA[] COMPARING ZUONR.
LOOP AT GT_DATA ASSIGNING <GS_DATA> .
CLEAR <GS_DATA>-MSL.
CLEAR <GS_DATA>-HSL.
LOOP AT GT_DATA_B WHERE ZUONR = <GS_DATA>-ZUONR.
<GS_DATA>-MSL = <GS_DATA>-MSL + GT_DATA_B-MSL .
<GS_DATA>-HSL = <GS_DATA>-HSL + GT_DATA_B-HSL .
ENDLOOP.
<GS_DATA>-VBELN_IM = <GS_DATA>-ZUONR(10) .
<GS_DATA>-VBELN_IM = <GS_DATA>-ZUONR+10(6) .
<GS_DATA>-MSL = ABS( <GS_DATA>-MSL ) .
<GS_DATA>-BUDAT = P_BUDAT .
<GS_DATA>-MONAT = P_MONAT .
ENDLOOP.
FREE <GS_DATA> .
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' '财年',
'MONAT' '会计期间',
'WERKS' '工厂',
'PRCTR' '利润中心',
'KUNNR' '客户',
'RASSC' '贸易伙伴',
'MATNR' '物料',
'RACCT' '差异科目',
'RHCUR' '公司代码货币',
'VBELN_IM' '交货单',
'VBELP_IM' '行项目',
'ZUONR' '分配',
'MSL' '数量',
'RUNIT' '单位',
'HSL' '冲回金额',
'BUDAT' '过账日期'.
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_ZTFI123 .
SELECT SINGLE * INTO CORRESPONDING FIELDS OF GT_ZTFI123 FROM ZTFI123
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 = 'ZFI123'
.
IF LV_FLAG IS NOT INITIAL.
IF GT_ZTFI123 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_ZTFI123[].
LOOP AT GT_DATA.
MOVE-CORRESPONDING GT_DATA TO GT_ZTFI123 .
GT_ZTFI123-FISCYEARPER = P_BUDAT(6) .
APPEND GT_ZTFI123 .
CLEAR GT_ZTFI123 .
ENDLOOP.
MODIFY ZTFI123 FROM TABLE GT_ZTFI123[] .
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_ZTFI123[].
LOOP AT GT_DATA.
MOVE-CORRESPONDING GT_DATA TO GT_ZTFI123 .
GT_ZTFI123-FISCYEARPER = P_BUDAT(6) .
APPEND GT_ZTFI123 .
CLEAR GT_ZTFI123 .
ENDLOOP.
MODIFY ZTFI123 FROM TABLE GT_ZTFI123[] .
COMMIT WORK .
MESSAGE '期间过账成功' TYPE 'S' .
ENDIF.
IF GT_ZTFI123 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 = '物料账发出商品差异分摊到DN冲回 ' .
HEADER-DOC_DATE = P_BUDAT. "凭证日期
HEADER-PSTNG_DATE = P_BUDAT. "凭证中的过帐日期
HEADER-USERNAME = SY-UNAME. "用户名
HEADER-DOC_TYPE = 'ML'. "凭证类型
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-HSL * -1 . "金额
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-RASSC. "贸易伙伴
WA_ACCOUNTGL-CUSTOMER = GT_DATA-KUNNR. "客户
WA_ACCOUNTGL-MATERIAL = GT_DATA-MATNR. "物料编号(18 个字符)
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-HSL > 0.
GS_EXTENSION2-BSCHL = '50'.
ELSE.
GS_EXTENSION2-BSCHL = '40'.
ENDIF.
IF WA_ACCOUNTGL-ALLOC_NMBR IS NOT INITIAL.
GS_EXTENSION2-MENGE = GT_DATA-MSL. "数量
GS_EXTENSION2-MEINS = GT_DATA-RUNIT. "基本计量单位
ENDIF.
GS_EXTENSION2-VBUND = GT_DATA-RASSC. "贸易伙伴
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-HSL. "金额
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-RASSC. "贸易伙伴
WA_ACCOUNTGL-CUSTOMER = GT_DATA-KUNNR. "客户
WA_ACCOUNTGL-MATERIAL = GT_DATA-MATNR. "物料编号(18 个字符)
APPEND WA_ACCOUNTGL TO LT_ACCOUNTGL.
CLEAR GS_EXTENSION2.
CLEAR LT_EXTENSION2.
GS_EXTENSION2-POSNR = LV_LINES.
IF GT_DATA-HSL > 0.
GS_EXTENSION2-BSCHL = '40'.
ELSE.
GS_EXTENSION2-BSCHL = '50'.
ENDIF.
GS_EXTENSION2-VBUND = GT_DATA-RASSC. "贸易伙伴
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
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-HSL * -1 . "金额
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-RASSC. "贸易伙伴
WA_ACCOUNTGL-CUSTOMER = GT_DATA-KUNNR. "客户
WA_ACCOUNTGL-MATERIAL = GT_DATA-MATNR. "物料编号(18 个字符)
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-HSL > 0.
GS_EXTENSION2-BSCHL = '50'.
ELSE.
GS_EXTENSION2-BSCHL = '40'.
ENDIF.
IF WA_ACCOUNTGL-ALLOC_NMBR IS NOT INITIAL.
GS_EXTENSION2-MENGE = GT_DATA-MSL. "数量
GS_EXTENSION2-MEINS = GT_DATA-RUNIT. "基本计量单位
ENDIF.
GS_EXTENSION2-VBUND = GT_DATA-RASSC. "贸易伙伴
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-HSL. "金额
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-RASSC. "贸易伙伴
WA_ACCOUNTGL-CUSTOMER = GT_DATA-KUNNR. "客户
WA_ACCOUNTGL-MATERIAL = GT_DATA-MATNR. "物料编号(18 个字符)
APPEND WA_ACCOUNTGL TO LT_ACCOUNTGL.
CLEAR GS_EXTENSION2.
CLEAR LT_EXTENSION2.
GS_EXTENSION2-POSNR = LV_LINES.
IF GT_DATA-HSL > 0.
GS_EXTENSION2-BSCHL = '40'.
ELSE.
GS_EXTENSION2-BSCHL = '50'.
ENDIF.
GS_EXTENSION2-VBUND = GT_DATA-RASSC. "贸易伙伴
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 = '模拟过账:物料账发出商品差异分摊到DN冲回 ' && 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 = '物料账发出商品差异分摊到DN冲回 ' .
HEADER-DOC_DATE = P_BUDAT. "凭证日期
HEADER-PSTNG_DATE = P_BUDAT. "凭证中的过帐日期
HEADER-USERNAME = SY-UNAME. "用户名
HEADER-DOC_TYPE = 'ML'. "凭证类型
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-HSL * -1 . "金额
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-RASSC. "贸易伙伴
WA_ACCOUNTGL-CUSTOMER = GT_DATA-KUNNR. "客户
WA_ACCOUNTGL-MATERIAL = GT_DATA-MATNR. "物料编号(18 个字符)
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-HSL > 0.
GS_EXTENSION2-BSCHL = '50'.
ELSE.
GS_EXTENSION2-BSCHL = '40'.
ENDIF.
IF WA_ACCOUNTGL-ALLOC_NMBR IS NOT INITIAL.
GS_EXTENSION2-MENGE = GT_DATA-MSL. "数量
GS_EXTENSION2-MEINS = GT_DATA-RUNIT. "基本计量单位
ENDIF.
GS_EXTENSION2-VBUND = GT_DATA-RASSC. "贸易伙伴
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-HSL. "金额
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-RASSC. "贸易伙伴
WA_ACCOUNTGL-CUSTOMER = GT_DATA-KUNNR. "客户
WA_ACCOUNTGL-MATERIAL = GT_DATA-MATNR. "物料编号(18 个字符)
APPEND WA_ACCOUNTGL TO LT_ACCOUNTGL.
CLEAR GS_EXTENSION2.
CLEAR LT_EXTENSION2.
GS_EXTENSION2-POSNR = LV_LINES.
IF GT_DATA-HSL > 0.
GS_EXTENSION2-BSCHL = '40'.
ELSE.
GS_EXTENSION2-BSCHL = '50'.
ENDIF.
GS_EXTENSION2-VBUND = GT_DATA-RASSC. "贸易伙伴
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
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-HSL * -1 . "金额
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-RASSC. "贸易伙伴
WA_ACCOUNTGL-CUSTOMER = GT_DATA-KUNNR. "客户
WA_ACCOUNTGL-MATERIAL = GT_DATA-MATNR. "物料编号(18 个字符)
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-HSL > 0.
GS_EXTENSION2-BSCHL = '50'.
ELSE.
GS_EXTENSION2-BSCHL = '40'.
ENDIF.
IF WA_ACCOUNTGL-ALLOC_NMBR IS NOT INITIAL.
GS_EXTENSION2-MENGE = GT_DATA-MSL. "数量
GS_EXTENSION2-MEINS = GT_DATA-RUNIT. "基本计量单位
ENDIF.
GS_EXTENSION2-VBUND = GT_DATA-RASSC. "贸易伙伴
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-HSL. "金额
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-RASSC. "贸易伙伴
WA_ACCOUNTGL-CUSTOMER = GT_DATA-KUNNR. "客户
WA_ACCOUNTGL-MATERIAL = GT_DATA-MATNR. "物料编号(18 个字符)
APPEND WA_ACCOUNTGL TO LT_ACCOUNTGL.
CLEAR GS_EXTENSION2.
CLEAR LT_EXTENSION2.
GS_EXTENSION2-POSNR = LV_LINES.
IF GT_DATA-HSL > 0.
GS_EXTENSION2-BSCHL = '40'.
ELSE.
GS_EXTENSION2-BSCHL = '50'.
ENDIF.
GS_EXTENSION2-VBUND = GT_DATA-RASSC. "贸易伙伴
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 = '正式过账:物料账发出商品差异分摊到DN冲回 ' && 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-交货单冲销发出商品-差异处理(开发笔记)
最新推荐文章于 2022-09-22 10:22:44 发布