matinal:BAPI_ACC_DOCUMENT_POST

338 篇文章 185 订阅

🚀欢迎来到本文🚀
🍉个人简介:matinal,目前职业是IT行业,一个正在慢慢前行的普通人。
🏀系列专栏:涵盖SAP各模块,Python,Excel,人工智能等
💡 其他专栏:一些平时学习的技术,感兴趣的小伙伴可以看看。

🍔公众号:matinal
🎁希望各位→点赞👍 + 收藏⭐️ + 留言📝 ​
⛱️万物从心起,心动则万物动🏄‍♂️


 前言:汇票凭证专用事务码是F-36,预制凭证是F-65

🦙(工作遇到傻逼,千万要远离。道路千万条,远离傻逼第一条)


汇票凭证专用事务码是F-36,预制凭证是F-65。

FB03查看银行承兑汇票凭证

 对于特殊总账类型为W或者S的,双击进入可见出票人出票行 票据号等信息

汇票的信息是保存在BSED里的,而bapi没有提供这些字段信息,所以需要走增强

解决办法:隐式增强+BADI

增强位置1: FI_DOCUMENT_CHECK

一进来,先检查是否是W类型特殊总账  export操作在 调用bapi的时候赋值,推荐使用function函数来做,看的比较直观

如果是,把char_w 改为U

 在函数最后,改回去

增强位置2:LFACIF5D

form最后的地方

把exten 数据传过来,传给bsed数据,传递数据可以用memory,也可以通过函数的方式,在函数组里建全局内表,然后调bapi的前面传数据过去,存到全局内表里,在增强里再调出来

 以上是关于汇票凭证的增强,预制凭证的话也需要做几个增强

增强BADI为ACC_DOCUMENT

 在自己代码里把增强结构加上

 以下是完整代码

FUNCTION ZFIFM0005.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(IS_HEADER) TYPE  ZFIS0007 OPTIONAL
*"  EXPORTING
*"     VALUE(ES_RETURN) TYPE  ZBCT0002
*"  TABLES
*"      IT_ITEMS STRUCTURE  ZFIS0008
*"----------------------------------------------------------------------
 
  DATA:
    LS_DOCUMENTHEADER    LIKE BAPIACHE09,
    LS_BAPIACGL09        LIKE BAPIACGL09,
    LS_CUSTOMERCPD       LIKE BAPIACAR09,
    LS_ZFIS002           TYPE ZFIS0002,
    LS_CURRENCYAMOUNT    TYPE BAPIACCR09,
    LS_EXTENSION2        TYPE  BAPIPAREX,
    LS_RETURN            TYPE BAPIRET2,
    LT_ACCOUNTGL         TYPE TABLE OF BAPIACGL09 WITH HEADER LINE,
    LT_ACCOUNTRECEIVABLE LIKE TABLE OF BAPIACAR09 WITH HEADER LINE,
    LT_CURRENCYAMOUNT    LIKE TABLE OF BAPIACCR09 WITH HEADER LINE,
    LT_RETURN            LIKE TABLE OF BAPIRET2   WITH HEADER LINE, "BAPIRET2
    LT_EXTENSION2        LIKE TABLE OF BAPIPAREX  WITH HEADER LINE.
 
  DATA M_CURR(13) TYPE C .
*
  DATA: LV_TYPE LIKE LS_DOCUMENTHEADER-OBJ_TYPE,
        LV_KEY  LIKE LS_DOCUMENTHEADER-OBJ_KEY,
        LV_SYS  LIKE LS_DOCUMENTHEADER-OBJ_SYS.
 
  DATA:LV_SGL_FLD TYPE CHAR1.
  DATA LV_UMSKZ TYPE UMSKZ. "特殊总账标识
  DATA LV_CUSTOMER TYPE KUNNR.
  DATA LV_ITEMNO_ACC TYPE POSNR_ACC .
  DATA LV_BLART      TYPE BLART.
 
  DATA LS_ZFIS0009 TYPE ZFIS0009.
  DATA LS_ZFIT0007 TYPE ZFIT0007.
  DATA LS_BKPF TYPE BKPF.
  DATA LS_ITEMS TYPE ZFIS0008.
  DATA LS_ITEMS2 TYPE ZFIS0008.
  DATA LV_MSG TYPE BAPI_MSG.
 
  CHECK IS_HEADER  IS NOT INITIAL
    AND IT_ITEMS[] IS NOT INITIAL.
 
* 如果没输过账日期,默认当天
  IF IS_HEADER-BUDAT IS INITIAL.
    IS_HEADER-BUDAT = SY-DATUM.
  ENDIF.
 
* 如果没输货币码,默认CNY
  IF IS_HEADER-WAERS IS INITIAL.
    IS_HEADER-WAERS = 'CNY'.
  ENDIF.
 
* 如果没输凭证类型,默认DZ
  IF IS_HEADER-WAERS IS INITIAL.
    IS_HEADER-BLART = 'DZ'.
  ENDIF.
 
  CLEAR LS_ZFIT0007.
  MOVE-CORRESPONDING IS_HEADER TO LS_ZFIT0007.
  LS_ZFIT0007-STMPS = SY-DATUM && SY-UZEIT.
 
  LS_DOCUMENTHEADER-HEADER_TXT = IS_HEADER-BKTXT.
  LS_DOCUMENTHEADER-COMP_CODE  = IS_HEADER-BUKRS.
  LS_DOCUMENTHEADER-DOC_DATE   = IS_HEADER-BUDAT.
  LS_DOCUMENTHEADER-DOC_TYPE   = IS_HEADER-BLART.
  LS_DOCUMENTHEADER-PSTNG_DATE = IS_HEADER-BUDAT.
  LS_DOCUMENTHEADER-USERNAME   = SY-UNAME.
  LS_DOCUMENTHEADER-FISC_YEAR  = IS_HEADER-BUDAT+0(4).
  LS_DOCUMENTHEADER-FIS_PERIOD = IS_HEADER-BUDAT+4(2).
*LS_DOCUMENTHEADER-BUS_ACT    = 'RFBU'.         "业务事务
 
  LOOP AT IT_ITEMS INTO LS_ITEMS.
*   行项目号
    LV_ITEMNO_ACC = SY-TABIX.
 
    CLEAR:LV_CUSTOMER,
          LV_SGL_FLD,
          LS_ZFIS002.
 
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        INPUT  = LS_ITEMS-NEWKO
      IMPORTING
        OUTPUT = LV_CUSTOMER.
 
*    PERFORM FRM_GET_BSCHL USING IS_HEADER-BLART LS_ITEMS-NEWUM CHANGING LV_BSCHL LV_CUSTOMER.
 
    LS_CUSTOMERCPD-ITEMNO_ACC = LV_ITEMNO_ACC.
 
*   判断记账码
    CASE LS_ITEMS-BSCHL.
      WHEN '09' OR '11'.
        CLEAR LS_CUSTOMERCPD.
        LS_CUSTOMERCPD-ITEMNO_ACC  = LV_ITEMNO_ACC.      "行项目
        LS_CUSTOMERCPD-CUSTOMER    = LV_CUSTOMER.        "客户编号
*        LS_CUSTOMERCPD-GL_ACCOUNT  = L_ZDHKONT.           "总分类帐帐目
        LS_CUSTOMERCPD-COMP_CODE = IS_HEADER-BUKRS.      "公司代码
        LS_CUSTOMERCPD-ALLOC_NMBR = LS_ITEMS-ZUONR.      "分配
        LS_CUSTOMERCPD-BLINE_DATE = LS_ITEMS-ZFBDT.      "基准日期
        LS_CUSTOMERCPD-ITEM_TEXT  = LS_ITEMS-SGTXT.      "项目文本
*       判断结算方式
        IF LS_ITEMS-BSCHL = '09'.
          IF IS_HEADER-CSSCODE IS NOT INITIAL.
*           商业承兑
            IF IS_HEADER-CSSCODE = '04'.
*              LS_CUSTOMERCPD-SP_GL_IND   = 'W'.    "特別总账标识
*             汇票需要的数据
              LV_SGL_FLD = 'W'.
              EXPORT LV_SGL_FLD TO MEMORY ID 'LV_SGL_FLD'.
              MOVE-CORRESPONDING LS_ITEMS TO LS_ZFIS0009.
              APPEND LS_ZFIS0009 TO GT_BSED.
*           银行承兑
            ELSEIF IS_HEADER-CSSCODE = '06'.
*              LS_CUSTOMERCPD-SP_GL_IND   = 'S'.    "特別总账标识
*             汇票需要的数据
              LV_SGL_FLD = 'S'.
              EXPORT LV_SGL_FLD TO MEMORY ID 'LV_SGL_FLD'.
              MOVE-CORRESPONDING LS_ITEMS TO LS_ZFIS0009.
              APPEND LS_ZFIS0009 TO GT_BSED.
            ENDIF.
          ENDIF.
        ENDIF.
 
        APPEND LS_CUSTOMERCPD TO LT_ACCOUNTRECEIVABLE.
      WHEN '40' OR '50'.
        CLEAR LS_BAPIACGL09.
        LS_BAPIACGL09-ITEMNO_ACC  = LV_ITEMNO_ACC.   "行项目
        LS_BAPIACGL09-GL_ACCOUNT = LV_CUSTOMER.      "总账科目
        LS_BAPIACGL09-PROFIT_CTR = LS_ITEMS-PRCTR.   "利润中心
        LS_BAPIACGL09-COMP_CODE  = IS_HEADER-BUKRS.  "公司代码
        LS_BAPIACGL09-VALUE_DATE = LS_ITEMS-VALUT.   "起息日
        LS_BAPIACGL09-ITEM_TEXT  = LS_ITEMS-SGTXT.   "行项目文本
 
        APPEND LS_BAPIACGL09 TO LT_ACCOUNTGL.
    ENDCASE.
 
    "贷项金额判断
    IF LS_ITEMS-BSCHL EQ 50 OR LS_ITEMS-BSCHL EQ 11.
      LS_ITEMS-WRBTR = -1 * LS_ITEMS-WRBTR.
    ENDIF.
 
    LS_CURRENCYAMOUNT-ITEMNO_ACC = LV_ITEMNO_ACC.
    LS_CURRENCYAMOUNT-CURRENCY   = IS_HEADER-WAERS.
    LS_CURRENCYAMOUNT-AMT_DOCCUR = LS_ITEMS-WRBTR.
    APPEND LS_CURRENCYAMOUNT TO LT_CURRENCYAMOUNT.
    CLEAR LS_CURRENCYAMOUNT.
*
******增强扩展字段
    LS_EXTENSION2-STRUCTURE = 'ZFIS0002' .
    LS_ZFIS002-POSNR = LV_ITEMNO_ACC .
    IF NOT LS_ITEMS-NEWUM IS INITIAL.
      LS_ZFIS002-UMSKZ = LS_ITEMS-NEWUM .
    ENDIF.
    LS_ZFIS002-RSTGR = LS_ITEMS-RSTGR."'A01'.
    LS_ZFIS002-BSCHL = LS_ITEMS-BSCHL. "LV_BSCHL .
    LS_EXTENSION2-VALUEPART1 = LS_ZFIS002 .
    APPEND LS_EXTENSION2 TO  LT_EXTENSION2.
    CLEAR  LS_EXTENSION2.
 
    CLEAR:LV_ITEMNO_ACC,LS_ITEMS.
 
  ENDLOOP.
 
  CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
    EXPORTING
      DOCUMENTHEADER    = LS_DOCUMENTHEADER
    TABLES
      ACCOUNTGL         = LT_ACCOUNTGL
      ACCOUNTRECEIVABLE = LT_ACCOUNTRECEIVABLE
      CURRENCYAMOUNT    = LT_CURRENCYAMOUNT
      RETURN            = LT_RETURN
      EXTENSION2        = LT_EXTENSION2.
 
  READ TABLE LT_RETURN INTO LS_RETURN WITH KEY TYPE = 'S'
                                             NUMBER = '614'.
 
  IF SY-SUBRC EQ 0 .
*   如果不是承兑,生成预制凭证
    IF IS_HEADER-CSSCODE IS INITIAL.
      CLEAR LS_EXTENSION2.
      LS_EXTENSION2-STRUCTURE = 'PARK'.
      LS_EXTENSION2-VALUEPART1 = 'PARK'.
      APPEND LS_EXTENSION2 TO LT_EXTENSION2.
    ENDIF.
 
    CLEAR LT_RETURN.
    CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
      EXPORTING
        DOCUMENTHEADER    = LS_DOCUMENTHEADER
      IMPORTING
        OBJ_TYPE          = LV_TYPE
        OBJ_KEY           = LV_KEY
        OBJ_SYS           = LV_SYS
      TABLES
        ACCOUNTGL         = LT_ACCOUNTGL
        ACCOUNTRECEIVABLE = LT_ACCOUNTRECEIVABLE
        CURRENCYAMOUNT    = LT_CURRENCYAMOUNT
        RETURN            = LT_RETURN
        EXTENSION2        = LT_EXTENSION2.
    IF LINE_EXISTS( LT_RETURN[ TYPE = 'S' ] ).
 
      ES_RETURN-TYPE = 'S'.
      ES_RETURN-MESSAGE = LV_KEY+0(10).
 
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          WAIT = 'X'.
 
      LS_ZFIT0007-BELNR   = LV_KEY+0(10).
      LS_ZFIT0007-TYPE    ='S'.
      LS_ZFIT0007-MESSAGE ='接口调用成功'.
    ELSE.
      SORT LT_RETURN BY TYPE ID NUMBER.
      DELETE ADJACENT DUPLICATES FROM  LT_RETURN COMPARING TYPE ID NUMBER.
 
      ES_RETURN-TYPE = 'E'.
      LOOP AT LT_RETURN INTO LS_RETURN.
        CALL FUNCTION 'MESSAGE_TEXT_BUILD'
          EXPORTING
            MSGID               = LS_RETURN-ID
            MSGNR               = LS_RETURN-NUMBER
            MSGV1               = LS_RETURN-MESSAGE_V1
            MSGV2               = LS_RETURN-MESSAGE_V2
            MSGV3               = LS_RETURN-MESSAGE_V3
            MSGV4               = LS_RETURN-MESSAGE_V4
          IMPORTING
            MESSAGE_TEXT_OUTPUT = LV_MSG.
 
        CONCATENATE ES_RETURN-MESSAGE LV_MSG INTO ES_RETURN-MESSAGE.
 
        CLEAR :LV_MSG,LS_RETURN.
 
      ENDLOOP.
 
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
 
      LS_ZFIT0007-BELNR   = SPACE.
      LS_ZFIT0007-TYPE    ='E'.
      LS_ZFIT0007-MESSAGE = ES_RETURN-MESSAGE.
 
    ENDIF.
  ELSE.
    ES_RETURN-TYPE = 'E'.
    LOOP AT LT_RETURN INTO LS_RETURN.
      CALL FUNCTION 'MESSAGE_TEXT_BUILD'
        EXPORTING
          MSGID               = LS_RETURN-ID
          MSGNR               = LS_RETURN-NUMBER
          MSGV1               = LS_RETURN-MESSAGE_V1
          MSGV2               = LS_RETURN-MESSAGE_V2
          MSGV3               = LS_RETURN-MESSAGE_V3
          MSGV4               = LS_RETURN-MESSAGE_V4
        IMPORTING
          MESSAGE_TEXT_OUTPUT = LV_MSG.
 
      CONCATENATE ES_RETURN-MESSAGE LV_MSG INTO ES_RETURN-MESSAGE.
 
      CLEAR :LV_MSG,LS_RETURN.
    ENDLOOP.
 
    LS_ZFIT0007-BELNR   = SPACE.
    LS_ZFIT0007-TYPE    ='E'.
    LS_ZFIT0007-MESSAGE = ES_RETURN-MESSAGE.
  ENDIF.
 
  MODIFY ZFIT0007 FROM LS_ZFIT0007.
ENDFUNCTION.

 怎么样,在了解此篇文章有何感想?


如果本文对大家有所帮助的话,还望各位能给我点赞、收藏并评论一下,感谢各位💕!!! 另如果大家有什么疑问或者建议的话,欢迎评论区留言。更多精彩内容->在这里

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值