下面开始干货:
之前发了一篇文章:
《DEMO:F-02固定资产 BAPI_ACC_DOCUMENT_POST》
有读者留言说最重要的增强部分没有写。
最初以为这个增强是最常规的增强,FICO项目机会都会用到就没有赘述。
可能确实有部分同行对这块不是很熟悉,所以重新调整这篇文章,加上增强部分:
新建结构:ZLM_ENHANCE_ACC_DOC
代码 主要修改部分:
另外完善了下代码:
SE19创建增强实例(大部分项目应该有已经实现的增强实例,不见得需要新建)。
添加过滤器值:BKPFF
激活
代码部分 (仅做参考):
METHOD IF_EX_ACC_DOCUMENT~CHANGE.
DATA:LS_VALUE TYPE ZLM_ENHANCE_ACC_DOC.
FIELD-SYMBOLS <LS_ACCIT> LIKE LINE OF C_ACCIT.
DATA:LS_EXTENSION LIKE LINE OF C_EXTENSION2.
CHECK SY-UNAME = 'LIUM'.
LOOP AT C_EXTENSION2 INTO LS_EXTENSION WHERE STRUCTURE = 'ZLM_ENHANCE_ACC_DOC'.
CLEAR LS_VALUE.
MOVE LS_EXTENSION-VALUEPART1 TO LS_VALUE.
READ TABLE C_ACCIT ASSIGNING <LS_ACCIT>
WITH KEY POSNR = LS_VALUE-POSNR.
CHECK SY-SUBRC = 0.
IF LS_VALUE-BSCHL = '50'.
<LS_ACCIT>-RSTGR = LS_VALUE-RSTGR."101
ELSEIF LS_VALUE-BSCHL = '70'.
<LS_ACCIT>-ANBWA = LS_VALUE-ANBWA."100
ENDIF.
ENDLOOP.
ENDMETHOD.
另外注意下是否原有增强实例会对这个有影响。
因为很多项目 这个增强内代码都会写成动态通用的。可能会有影响,自己查看下吧。
下面是程序完整代码:
*&---------------------------------------------------------------------*
*& Report ZLM_DEMO_F02_ANLN1
*&
*&---------------------------------------------------------------------*
REPORT ZLM_DEMO_F02_ANLN1.
PARAMETERS:
P_BUKRS TYPE BUKRS DEFAULT '9160'.
DATA:GS_HEADER TYPE BAPIACHE09.
DATA:GV_KEY TYPE BAPIACHE09-OBJ_KEY.
DATA:GT_GL TYPE TABLE OF BAPIACGL09.
DATA:GS_GL TYPE BAPIACGL09.
DATA:GT_CUR TYPE TABLE OF BAPIACCR09.
DATA:GS_CUR TYPE BAPIACCR09.
DATA:GT_EXT TYPE TABLE OF BAPIPAREX.
DATA:GS_EXT TYPE BAPIPAREX.
DATA:GT_RETURN TYPE TABLE OF BAPIRET2.
DATA:GS_RETURN TYPE BAPIRET2.
DATA:GS_ACC_POST TYPE ZLM_ENHANCE_ACC_DOC.
GS_HEADER-OBJ_TYPE = 'BKPFF '."参考交易
GS_HEADER-OBJ_KEY = 'RFBU '."字段参考关键
GS_HEADER-USERNAME = SY-UNAME."用户名
GS_HEADER-HEADER_TXT = 'TEST '."凭证抬头文本
GS_HEADER-COMP_CODE = P_BUKRS."公司代码
GS_HEADER-DOC_DATE = SY-DATUM."凭证中的凭证日期
GS_HEADER-PSTNG_DATE = SY-DATUM."凭证中的过帐日期
GS_HEADER-TRANS_DATE = SY-DATUM."换算日期
GS_HEADER-FISC_YEAR = SY-DATUM(4)."会计年度
GS_HEADER-FIS_PERIOD = SY-DATUM+4(2).."会计期间
GS_HEADER-DOC_TYPE = 'SA '."凭证类型
CLEAR:GT_GL[],GT_CUR[],GT_EXT[],GT_RETURN[].
CLEAR GS_GL.
GS_GL-ITEMNO_ACC = 1.
GS_GL-GL_ACCOUNT = '1601000060'.
GS_GL-ITEM_TEXT = '现支_固定资产测试'.
GS_GL-ACCT_TYPE = 'A'.
GS_GL-PROFIT_CTR = '0000999999'.
GS_GL-ALLOC_NMBR = '现支_固定资产测试'.
GS_GL-ASSET_NO = '600000000003'.
GS_GL-SUB_NUMBER = '0000'.
GS_GL-COMP_CODE = P_BUKRS.
APPEND GS_GL TO GT_GL.
CLEAR GS_ACC_POST.
GS_ACC_POST-POSNR = GS_GL-ITEMNO_ACC.
GS_ACC_POST-BSCHL = '70'.
GS_ACC_POST-ANBWA = '100'.
GS_EXT-STRUCTURE = 'ZLM_ENHANCE_ACC_DOC'.
GS_EXT-VALUEPART1 = GS_ACC_POST.
APPEND GS_EXT TO GT_EXT[].
CLEAR GS_GL.
GS_GL-ITEMNO_ACC = 2.
GS_GL-GL_ACCOUNT = '1002001002'.
GS_GL-ITEM_TEXT = '现支_固定资产测试'.
GS_GL-VALUE_DATE = SY-DATUM.
GS_GL-PROFIT_CTR = '0000999999'.
GS_GL-ALLOC_NMBR = '现支_固定资产测试'.
GS_GL-COMP_CODE = P_BUKRS.
APPEND GS_GL TO GT_GL.
CLEAR GS_ACC_POST.
GS_ACC_POST-POSNR = GS_GL-ITEMNO_ACC.
GS_ACC_POST-BSCHL = '50'.
GS_ACC_POST-RSTGR = '101'.
GS_EXT-STRUCTURE = 'ZLM_ENHANCE_ACC_DOC'.
GS_EXT-VALUEPART1 = GS_ACC_POST.
APPEND GS_EXT TO GT_EXT[].
CLEAR GS_CUR.
GS_CUR-ITEMNO_ACC = 1.
GS_CUR-CURRENCY = 'CNY'.
GS_CUR-AMT_DOCCUR = 1000.
APPEND GS_CUR TO GT_CUR.
CLEAR GS_CUR.
GS_CUR-ITEMNO_ACC = 2.
GS_CUR-CURRENCY = 'CNY'.
GS_CUR-AMT_DOCCUR = '-1000'.
APPEND GS_CUR TO GT_CUR.
"凭证数据检查-防止跳号
CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
EXPORTING
DOCUMENTHEADER = GS_HEADER
TABLES
ACCOUNTGL = GT_GL
CURRENCYAMOUNT = GT_CUR
RETURN = GT_RETURN
EXTENSION2 = GT_EXT.
LOOP AT GT_RETURN INTO GS_RETURN WHERE TYPE = 'E'.
WRITE GS_RETURN-MESSAGE.
ENDLOOP.
IF SY-SUBRC <> 0..
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
DOCUMENTHEADER = GS_HEADER
IMPORTING
OBJ_KEY = GV_KEY
TABLES
ACCOUNTGL = GT_GL
CURRENCYAMOUNT = GT_CUR
RETURN = GT_RETURN
EXTENSION2 = GT_EXT.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
WRITE GV_KEY.
ENDIF.