MIRO创建采购预制发票时,按采购订单拆分成多行应付账款

背景:因财务部门核算需要,创建采购预制发票时,需要将金额分摊到具体的采购订单上,所以生成预制发票时,要根据采购订单的不同拆分成多个应付账款行,SAP标准的功能不支持此业务,因此需要开发增强实现

1.SE37:AC_VENDOR_DIALOG_COMP_IMPORT中创建隐士增强点

FUNCTION zfmfi_miro_split.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  TABLES
*"      T_SPLTTAB STRUCTURE  ACSPLT OPTIONAL
*"----------------------------------------------------------------------
  DATA:lt_ydrseg TYPE TABLE OF mmcr_drseg.
  DATA:lv_ydrseg TYPE char30 VALUE '(SAPLMR1M)YDRSEG[]'.
  DATA:lv_rbkpv TYPE char20 VALUE '(SAPLMR1M)RBKPV'.
  DATA:ls_rbkpv TYPE rbkp_v.
  DATA:lv_lfdnr(3) TYPE n,
       lv_rmwwr    TYPE rbkp-rmwwr,
       lv_wrbtr    TYPE rseg-wrbtr.
  DATA:BEGIN OF ls_ebeln,
         ebeln TYPE ekpo-ebeln,
         wrbtr TYPE rseg-wrbtr,
       END OF ls_ebeln,

       lt_ebeln LIKE TABLE OF ls_ebeln.

  DATA:lv_tabix TYPE sy-tabix.

  CHECK sy-mandt = '320' OR sy-mandt = '620' OR sy-mandt = '820'.

*调用点 函数  AC_VENDOR_DIALOG_COMP_IMPORT 开头
*调用点 函数  AC_VENDOR_DIALOG_COMP_IMPORT 开头
*调用点 函数  AC_VENDOR_DIALOG_COMP_IMPORT 开头
*  CHECK t_splttab[] IS INITIAL.
*  IF t_splttab[] IS INITIAL.
    CLEAR t_splttab[].
    ASSIGN (lv_ydrseg) TO FIELD-SYMBOL(<fs_t_ydrseg>).
    CHECK sy-subrc EQ 0.
    ASSIGN (lv_rbkpv) TO FIELD-SYMBOL(<fs_rbkpv>).
    CHECK sy-subrc EQ 0.

    CHECK <fs_t_ydrseg> IS NOT INITIAL.

    MOVE-CORRESPONDING <fs_rbkpv> TO ls_rbkpv.
    IF ls_rbkpv-rmwwr IS  INITIAL.
      RETURN.
    ELSE.
      lv_rmwwr = ls_rbkpv-rmwwr.
    ENDIF.

*  "获取税码信息
    SELECT a003~mwskz,
           konp~kbetr
      FROM a003
     INNER JOIN konp ON konp~knumh = a003~knumh
                    AND konp~kschl = 'MWVS'
     WHERE a003~kappl = 'TX'
       AND a003~kschl = 'MWVS'
       AND a003~aland = 'CN'
       AND a003~mwskz LIKE 'J%'
      INTO TABLE @DATA(lt_a003).

    CLEAR lv_lfdnr.
    lt_ydrseg[] = CORRESPONDING #( <fs_t_ydrseg> ).

    READ TABLE lt_a003 INTO DATA(ls_a003) WITH KEY mwskz = lt_ydrseg[ 1 ]-mwskz.

    SORT lt_ydrseg BY ebeln ASCENDING.
    LOOP AT lt_ydrseg INTO DATA(ls_ydrseg) GROUP BY ls_ydrseg-ebeln INTO DATA(lt_gp).
      CLEAR lv_wrbtr.
      LOOP AT GROUP lt_gp INTO DATA(ls_gp).
        lv_wrbtr = lv_wrbtr + ls_gp-wrbtr.
      ENDLOOP.

      lv_wrbtr = lv_wrbtr * ( 1 + ls_a003-kbetr / 1000 ).

      lv_lfdnr = lv_lfdnr + 1.

      APPEND INITIAL LINE TO t_splttab ASSIGNING FIELD-SYMBOL(<fs_splttab>).
      <fs_splttab>-lfdnr = lv_lfdnr.
      <fs_splttab>-wtpnt = lv_lfdnr.
      <fs_splttab>-wrbtr = lv_wrbtr.

      lv_rmwwr = lv_rmwwr - lv_wrbtr.
***************ADD BY ZJ 20240320 MIRO-会计凭证拆分 采购订单没有带出问题 S
      APPEND INITIAL LINE TO lt_ebeln ASSIGNING FIELD-SYMBOL(<fs_ebeln>).
      <fs_ebeln>-ebeln = ls_gp-ebeln.
      <fs_ebeln>-wrbtr = lv_wrbtr.
***************ADD BY ZJ 20240320 MIRO-会计凭证拆分 采购订单没有带出问题 E
    ENDLOOP.

    IF lv_rmwwr IS NOT INITIAL.
      <fs_splttab>-wrbtr = <fs_splttab>-wrbtr + lv_rmwwr.
      <fs_ebeln>-wrbtr = <fs_ebeln>-wrbtr + lv_rmwwr.
*    lv_lfdnr = lv_lfdnr + 1.
*
*    APPEND INITIAL LINE TO t_splttab ASSIGNING <fs_splttab>.
*    <fs_splttab>-lfdnr = lv_lfdnr.
*    <fs_splttab>-wtpnt = lv_lfdnr.
*    <fs_splttab>-wrbtr = lv_rmwwr.
    ENDIF.
*  ELSE.
*    ASSIGN (lv_ydrseg) TO <fs_t_ydrseg>.
*    CHECK sy-subrc EQ 0.
*    ASSIGN (lv_rbkpv) TO <fs_rbkpv>.
*    CHECK sy-subrc EQ 0.
*
*    CHECK <fs_t_ydrseg> IS NOT INITIAL.
*
*    MOVE-CORRESPONDING <fs_rbkpv> TO ls_rbkpv.
*    IF ls_rbkpv-rmwwr IS  INITIAL.
*      RETURN.
*    ELSE.
*      lv_rmwwr = ls_rbkpv-rmwwr.
*    ENDIF.
*
*    CLEAR lv_lfdnr.
*    lt_ydrseg[] = CORRESPONDING #( <fs_t_ydrseg> ).
*
*
*    LOOP AT lt_ydrseg INTO ls_ydrseg GROUP BY ls_ydrseg-ebeln INTO lt_gp.
*      CLEAR lv_wrbtr.
*      LOOP AT GROUP lt_gp INTO ls_gp.
*
*      ENDLOOP.
****************ADD BY ZJ 20240320 MIRO-会计凭证拆分 采购订单没有带出问题 S
*      APPEND INITIAL LINE TO lt_ebeln ASSIGNING <fs_ebeln>.
*      <fs_ebeln>-ebeln = ls_gp-ebeln.
****************ADD BY ZJ 20240320 MIRO-会计凭证拆分 采购订单没有带出问题 E
*    ENDLOOP.
*
*    LOOP AT lt_ebeln ASSIGNING <fs_ebeln>.
*      READ TABLE t_splttab INDEX sy-tabix.
*      IF sy-subrc EQ 0.
*        <fs_ebeln>-wrbtr = t_splttab-wrbtr.
*      ENDIF.
*    ENDLOOP.
*  ENDIF.

  EXPORT lt_ebeln TO MEMORY ID 'ZFMFI_MIRO_SPLIT'."SE37--->ZSAMPLE_PROCESS_00001120_CN --->LINE:157
ENDFUNCTION.

 

posted @ 2024-08-13 15:00  阿胖的阿多  阅读(101)  评论(0编辑  收藏  举报