美文网首页
ABAP供应商银行数据创建2021-05-28

ABAP供应商银行数据创建2021-05-28

作者: JayDragon | 来源:发表于2021-05-28 10:46 被阅读0次

    需求描述:如图,要求国家、银行代码、银行账户、控制码相同,参考明细不同的情况下通过程序创建两条银行数据

    供应商银行细目.png

    问题描述:写出来的程序只会覆盖只留参考明细为14的那一条(图中为前台操作的效果)
    解决方案:暂时不知道为啥程序会覆盖的问题,所以想出一个方案就是每次移动银行账户的最后一位到参考明细
    整体代码如下:

    *获取系统已有的银行明细
      DATA :lt_bankdetails LIKE TABLE OF bapibus1006_bankdetails,
            lt_bkreturn    LIKE TABLE OF bapiret2.
      CALL FUNCTION 'BAPI_BUPA_BANKDETAILS_GET'
        EXPORTING
          businesspartner = lv_partner
        TABLES
          bankdetails     = lt_bankdetails
          return          = lt_bkreturn.
    
      LOOP AT lt_bankdetails INTO DATA(ls_bankdetails).
        ls_bank_adjust-task = 'U'.
        ls_bank_adjust-bkvid = ls_bankdetails-bankdetailid. "银行明细标识
        ls_bank_adjust-banks = ls_bankdetails-bank_ctry.    "银行国家代码
        ls_bank_adjust-bankk = ls_bankdetails-bank_key.     "银行代码
        ls_bank_adjust-bankn = ls_bankdetails-bank_acct.    "银行账户号码
        ls_bank_adjust-bkont = ls_bankdetails-ctrl_key.     "银行控制代码
        ls_bank_adjust-bkref = ls_bankdetails-bank_ref.     "银行帐户的参考规定
        ls_bank_adjust-koinh = ls_bankdetails-accountholder."帐户持有人姓名
        ls_bank_adjust-bankn_ref = ls_bankdetails-bank_acct && ls_bankdetails-bank_ref.
        APPEND ls_bank_adjust TO lt_bank_adjust.
        CLEAR ls_bank_adjust.
      ENDLOOP.
    
      LOOP AT lt_bank INTO DATA(ls_bank).
        CLEAR lv_bankn_ref.
        lv_bankn_ref = ls_bank-bankn && ls_bank-bkref.
        READ TABLE lt_bank_adjust INTO ls_bank_adjust WITH KEY bankn_ref = lv_bankn_ref
                                                               bankk     = ls_bank-bankk.
        IF sy-subrc <> 0.
          lv_bankn = ls_bank-bankn.
          lv_bkref = ls_bank-bkref.
          DO.
            LOOP AT lt_bank_adjust INTO ls_bank_adjust WHERE banks = ls_bank-banks
                                                          AND bankk = ls_bank-bankk
                                                          AND bankn = lv_bankn.
              DATA(lv_len) = strlen( lv_bankn ).
              lv_len = lv_len - 1.
              lv_bkref = lv_bankn+lv_len(1) && lv_bkref.
              lv_bankn = lv_bankn+0(lv_len).
            ENDLOOP.
            IF sy-subrc <> 0.
              EXIT.
            ENDIF.
          ENDDO.
          CLEAR ls_bank_adjust.
          MOVE-CORRESPONDING ls_bank TO ls_bank_adjust.
          ls_bank_adjust-task = 'I'.
          ls_bank_adjust-bankn = lv_bankn.
          ls_bank_adjust-bkref = lv_bkref.
          APPEND ls_bank_adjust TO lt_bank_adjust.
        ELSE.
          "如果银行代码不一样,则新增,否则就变更
          IF ls_bank-bankk <> ls_bank_adjust-bankk.
            CLEAR ls_bank_adjust.
            MOVE-CORRESPONDING ls_bank TO ls_bank_adjust.
            ls_bank_adjust-task = 'I'.
            APPEND ls_bank_adjust TO lt_bank_adjust.
          ELSE.
    *        ls_bank_adjust-bankn = ls_bank-bankn.
            ls_bank_adjust-bkont = ls_bank-bkont.
    *        ls_bank_adjust-bkref = ls_bank-bkref.
            ls_bank_adjust-koinh = ls_bank-koinh.
            MODIFY lt_bank_adjust FROM ls_bank_adjust INDEX sy-tabix.
          ENDIF.
        ENDIF.
        CLEAR: ls_bank,ls_bank_adjust.
      ENDLOOP.
      "调整后的银行数据
      LOOP AT lt_bank_adjust INTO ls_bank_adjust.
        ls_bankdetail-task                 = ls_bank_adjust-task.
        ls_bankdetail-data_key             = ls_bank_adjust-bkvid.
        ls_bankdetail-data-bank_ctry       = ls_bank_adjust-banks."银行国家
        ls_bankdetail-data-bank_key        = ls_bank_adjust-bankk."银行代码
        ls_bankdetail-data-bank_acct       = ls_bank_adjust-bankn."银行账户
        ls_bankdetail-data-bank_ref        = ls_bank_adjust-bkref."参考明细:银行账户多余内容放入此字段
        ls_bankdetail-data-ctrl_key        = ls_bank_adjust-bkont."控制码
        ls_bankdetail-data-accountholder   = ls_bank_adjust-koinh."帐户持有人姓名
    
        ls_bankdetail-datax-bank_ctry      = 'X'."银行国家
        ls_bankdetail-datax-bank_key       = 'X'."银行代码
        ls_bankdetail-datax-bank_acct      = 'X'."银行账户
        ls_bankdetail-datax-bank_ref       = 'X'."参考明细
        ls_bankdetail-datax-ctrl_key       = 'X'."控制码
        ls_bankdetail-datax-accountholder  = 'X'."帐户持有人姓名
    
        ls_bankdetail-currently_valid = 'X'."当前数据有效
    
        APPEND ls_bankdetail TO ls_master_data-partner-central_data-bankdetail-bankdetails.
        CLEAR: ls_bankdetail.
      ENDLOOP.
      ls_master_data-partner-central_data-bankdetail-current_state = 'X'.
    
    

    相关文章

      网友评论

          本文标题:ABAP供应商银行数据创建2021-05-28

          本文链接:https://www.haomeiwen.com/subject/iptssltx.html