【FI】制造费用尾差结转
SAP的标准成本中心实际/计划/差异报表“S_ALR_87013611”在每月月结处理完毕之后,有存在尾差的情况,某些集团公司由于生产成本中心有上百个,逐个确认耗时费劲,则会按照一定的规则自动生成一张结转凭证。
【开发思路】
1、根据成本中心组获取成本中心信息
IF NOT P_KOSET IS INITIAL.
PERFORM DISSOLVE_SET TABLES LR_COSEL
USING P_KOSET
'0101'
'KOSTL'
P_KOKRS
'FMOP'
CHANGING GT_GROUPS[].
LT_SUB = GT_GROUPS[ 1 ]-SUB.
CLEAR LR_COSEL.
LR_COSEL-FIELD = 'KOKRS'.
LR_COSEL-SIGN = 'I'.
LR_COSEL-OPTION = 'EQ'.
LR_COSEL-LOW = P_KOKRS.
APPEND LR_COSEL.
SORT LR_COSEL BY HIGH LOW.
LS_OBART-SIGN = 'I'.
LS_OBART-OPTION = 'EQ'.
LS_OBART-LOW = 'KS'.
APPEND LS_OBART TO LR_OBART.
CALL FUNCTION 'ROMU_OM_CONVERT_TO_OBJNR'
TABLES
I_COSEL = LR_COSEL
R_OBJNR = LR_OBJNR
R_OBART = LR_OBART.
IF SY-SUBRC = 0.
ENDIF.
ENDIF.
2、从成本控制对象: 期间和凭证抬头相关的行项目表“COVP”中获取费用明细信息
SELECT * FROM COVP
INTO TABLE LT_COVP
WHERE KOKRS = P_KOKRS
AND GJAHR = P_GJAHR
AND PERIO = P_PERIO
AND LEDNR = '00'
AND WRTTP = '04'
AND OBJNR IN LR_OBJNR
3、整理内表,自动生成结转凭证,保存Log信息
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
DOCUMENTHEADER = LS_HEADER
IMPORTING
OBJ_TYPE = LV_OBJTYP
OBJ_KEY = LV_OBJKEY
OBJ_SYS = LV_OBJSYS
TABLES
ACCOUNTGL = LT_GLACCT
ACCOUNTRECEIVABLE = LT_ACCOUNTRECEIVE
ACCOUNTPAYABLE = LT_ACCOUNTPAYABLE
CURRENCYAMOUNT = LT_CURRENCYAMOUNT
RETURN = LT_RETURN.
LOOP AT LT_RETURN INTO LS_RETURN
WHERE TYPE = 'E' OR
TYPE = 'X' OR
TYPE = 'A'.
EXIT.
ENDLOOP.
IF SY-SUBRC = 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
LOOP AT LT_RETURN INTO LS_RETURN
WHERE TYPE = 'E' OR
TYPE = 'X' OR
TYPE = 'A'.
LV_MESSAGE = LV_MESSAGE && LS_RETURN-MESSAGE && ';'.
ENDLOOP.
GT_BAPIRET[] = LT_RETURN[].
PERFORM DISPLAY_ERROR.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
"凭证 + 公司代码 + 年度
LV_BELNR = LV_OBJKEY+0(10).
ENDIF.
【完整代码】
链接:下载Download
文章评论