首页 > 其他分享 >ABAP:MIGO收货,冲销增强

ABAP:MIGO收货,冲销增强

时间:2022-12-06 16:26:08浏览次数:51  
标签:lv 收货 mseg zsdt012 MIGO zsdt022 ABAP ls mkpf

1.MIGO前台增强:

1.SE18找到增强点:MB_GOODSMOVEMENT

 2.找到相应的BADI:右键创建实施

 

3.找到重写的方法

4.收货及冲销增强代码

LOOP AT xmkpf INTO ls_mkpf.

      LOOP AT xmseg INTO ls_mseg WHERE mblnr = ls_mkpf-mblnr AND mjahr = ls_mkpf-mjahr.
        IF ls_mseg-ebeln IS INITIAL OR ( ls_mseg-bwart <> '101' AND ls_mseg-bwart <> '123' ).
          CONTINUE.
        ENDIF.
        CLEAR:ls_zsdt008.
        SELECT SINGLE * INTO ls_zsdt008 FROM zsdt008 WHERE objkey = ls_mseg-ebeln AND objtype = 'PO' AND canum = '0010'.   """查询订单订单流程
        IF sy-subrc <> 0.
          CONTINUE.
        ENDIF.

        SELECT SINGLE * FROM zsdt014 INTO ls_zsdt014 WHERE zzrfcid = ls_zsdt008-zrfcid AND canum = '0010'."zrfcid = lv_zjylx AND canum = '0010' AND bsart = lv_bsart.
        IF sy-subrc <> 0.
          CONTINUE.
        ENDIF.
        lv_zjylx = ls_zsdt014-zrfcid.
*        SELECT * INTO TABLE lt_zsdt008 FROM zsdt008 WHERE zrfc_logid = lv_zrfc_logid AND objtype = 'PO'.

*        DELETE lt_zsdt008 WHERE objkey = ls_mseg-ebeln.
*        CLEAR:ls_ekko,ls_ekpo.
*        SELECT SINGLE * INTO ls_ekko FROM ekko WHERE ebeln = ls_zsdt008-objkey.
*        SELECT SINGLE * INTO ls_ekpo FROM ekpo WHERE ebeln = ls_zsdt008-objkey AND ebelp = ls_mseg-ebelp.


        CLEAR:ls_zsdt012.
        lv_zposnr = lv_zposnr + 10.
        ls_zsdt012-ebeln = ls_mseg-ebeln.
        ls_zsdt012-ebelp = ls_mseg-ebelp.
        ls_zsdt012-budat = ls_mkpf-budat.
        ls_zsdt012-bldat = ls_mkpf-bldat.
        ls_zsdt012-zocdqty = ls_mseg-menge.
        ls_zsdt012-charg = ls_mseg-charg.
        ls_zsdt012-mblnr = ls_mseg-mblnr.
        ls_zsdt012-mjahr = ls_mseg-mjahr.
        ls_zsdt012-zeile = ls_mseg-zeile.
        ls_zsdt012-xblnr = ls_mkpf-xblnr.
        ls_zsdt012-zrfcid = lv_zjylx.
        ls_zsdt012-zposnr = lv_zposnr.
        APPEND ls_zsdt012 TO lt_zsdt012.
      ENDLOOP.
    ENDLOOP.

    IF lt_zsdt012[] IS NOT INITIAL.
*      CALL FUNCTION 'ZMMFU002' IN BACKGROUND TASK
*        EXPORTING
*          iv_zjylx   = lv_zjylx
*        TABLES
*          it_zsdt012 = lt_zsdt012[].
      CALL FUNCTION 'ZMMFU010'
        EXPORTING
          iv_zjylx   = lv_zjylx
        TABLES
          it_zsdt012 = lt_zsdt012[].

    ENDIF.

    DATA:lv_posnr TYPE posnr.
    DATA:lv_zmblnr     TYPE zsdt013-zmblnr,
         lv_mblnr      TYPE mseg-mblnr,
         ls_zsdt023    TYPE zsdt023,
         ls_zsdt022    TYPE zsdt022,
         lt_zsdt022    TYPE TABLE OF zsdt022,
         lv_rfc_log_id TYPE zrfc_logid.
    LOOP AT xmkpf INTO ls_mkpf.
      CLEAR:lv_zmblnr,lv_mblnr,ls_zsdt023,ls_zsdt022,lt_zsdt022,lv_rfc_log_id.
      LOOP AT xmseg INTO ls_mseg WHERE mblnr = ls_mkpf-mblnr
                                      AND mjahr = ls_mkpf-mjahr
                                      AND ( bwart = '102' OR bwart = '122' ).

        CLEAR:lv_zjylx.

*          lv_zjylx = 'BUSP012'.




        SELECT SINGLE *
          INTO @DATA(ls_zsdt013_2)
          FROM zsdt013
         WHERE mblnr = @ls_mseg-lfbnr "冲销的物料凭证
           AND mjahr = @ls_mseg-lfbja.

        SELECT SINGLE *
          FROM zsdt023
          INTO ls_zsdt023
         WHERE zzrfcid = ls_zsdt013_2-zrfcid
           AND canum = '0010'.

        IF sy-subrc = 0.
          IF ls_zsdt013_2-zmblnr IS NOT INITIAL.

            lv_posnr = lv_posnr + 10.
            ls_zsdt022-zposnr = lv_posnr.
            ls_zsdt022-mblnr = ls_mseg-mblnr.
            ls_zsdt022-zeile = ls_mseg-lfpos.  "add  by 20221124
*            ls_zsdt022-zeile = ls_mseg-zeile.
            ls_zsdt022-mjahr = ls_mseg-mjahr.
            ls_zsdt022-budat = ls_mkpf-budat.
            ls_zsdt022-xblnr = ls_mkpf-xblnr.
            ls_zsdt022-bwart = ls_mseg-bwart.
            ls_zsdt022-menge = ls_mseg-menge.
            ls_zsdt022-grund = ls_mseg-grund.
            ls_zsdt022-zmblnr = ls_zsdt013_2-zmblnr.
            SELECT SINGLE ebeln ebelp matnr lgort charg werks
              INTO (
                     ls_zsdt022-ebeln,
                     ls_zsdt022-ebelp,
                     ls_zsdt022-matnr,
                     ls_zsdt022-lgort,
                     ls_zsdt022-charg,
                     ls_zsdt022-werks
                   )
              FROM mseg
             WHERE mblnr = ls_zsdt013_2-zmblnr
               AND mjahr = ls_mseg-lfbja
               AND zeile = ls_mseg-lfpos.



            APPEND ls_zsdt022 TO lt_zsdt022.
            CLEAR:ls_zsdt022.

          ENDIF.
        ENDIF.
      ENDLOOP.
      IF lt_zsdt022 IS NOT INITIAL.
*        CALL FUNCTION 'ZMMFU003' IN BACKGROUND TASK
*          EXPORTING
*            iv_zjylx   = ls_zsdt023-zrfcid
*          TABLES
*            it_zsdt022 = lt_zsdt022[].
        CALL FUNCTION 'ZMMFU009'
          EXPORTING
            iv_zjylx   = ls_zsdt023-zrfcid
          TABLES
            it_zsdt022 = lt_zsdt022[].

      ENDIF.
      CLEAR:ls_mkpf,lv_posnr.

2.MIGO BAPI增强:

1.SE19:创建BADI实施:

 

 2.BAPI收货及冲销代码:

DATA:ls_mseg TYPE mseg.
    DATA:ls_mkpf TYPE mkpf.
    DATA:ls_zsdt014 TYPE zsdt014.
    DATA:ls_zsdt012 TYPE zsdt012,
         lt_zsdt012 TYPE TABLE OF zsdt012.
    DATA:lv_zjylx TYPE zrfcid.
    DATA:ls_zsdt008 TYPE zsdt008.
    DATA:lv_zposnr TYPE zsdt012-zposnr.

    IF sy-tcode = 'MIGO'.
      ls_mkpf = is_mkpf.
      LOOP AT it_mseg INTO ls_mseg WHERE mblnr = ls_mkpf-mblnr AND mjahr = ls_mkpf-mjahr.
        IF ls_mseg-ebeln IS INITIAL OR ( ls_mseg-bwart <> '101' AND ls_mseg-bwart <> '123' ).
          CONTINUE.
        ENDIF.
        CLEAR:ls_zsdt008.
        SELECT SINGLE * INTO ls_zsdt008 FROM zsdt008 WHERE objkey = ls_mseg-ebeln AND objtype = 'PO' AND canum = '0010'.   """查询订单订单流程
        IF sy-subrc <> 0.
          CONTINUE.
        ENDIF.

        SELECT SINGLE * FROM zsdt014 INTO ls_zsdt014 WHERE zzrfcid = ls_zsdt008-zrfcid AND canum = '0010'."zrfcid = lv_zjylx AND canum = '0010' AND bsart = lv_bsart.
        IF sy-subrc <> 0.
          CONTINUE.
        ENDIF.
        lv_zjylx = ls_zsdt014-zrfcid.

        CLEAR:ls_zsdt012.
        lv_zposnr = lv_zposnr + 10.
        ls_zsdt012-ebeln = ls_mseg-ebeln.
        ls_zsdt012-ebelp = ls_mseg-ebelp.
        ls_zsdt012-budat = ls_mkpf-budat.
        ls_zsdt012-bldat = ls_mkpf-bldat.
        ls_zsdt012-zocdqty = ls_mseg-menge.
        ls_zsdt012-charg = ls_mseg-charg.
        ls_zsdt012-mblnr = ls_mseg-mblnr.
        ls_zsdt012-mjahr = ls_mseg-mjahr.
        ls_zsdt012-zeile = ls_mseg-zeile.
        ls_zsdt012-xblnr = ls_mkpf-xblnr.
        ls_zsdt012-zrfcid = lv_zjylx.
        ls_zsdt012-zposnr = lv_zposnr.
        APPEND ls_zsdt012 TO lt_zsdt012[].
      ENDLOOP.

      IF lt_zsdt012[] IS NOT INITIAL AND lv_zjylx IS NOT INITIAL.
        CALL FUNCTION 'ZMMFU002' IN BACKGROUND TASK
          EXPORTING
            iv_zjylx   = lv_zjylx
          TABLES
            it_zsdt012 = lt_zsdt012[].
      ENDIF.
    ENDIF.

*    ENDIF.

*    IF sy-uname = 'BASIS2'.

    IF sy-tcode = 'MIGO'.
      DATA:lv_posnr TYPE posnr.
      ls_mkpf = is_mkpf.
      LOOP AT it_mseg INTO ls_mseg WHERE mblnr = ls_mkpf-mblnr
                                      AND mjahr = ls_mkpf-mjahr
                                      AND ( bwart = '102' OR bwart = '122' ).

        CLEAR:lv_zjylx.

*          lv_zjylx = 'BUSP012'.

        DATA:lv_zmblnr     TYPE zsdt013-zmblnr,
             lv_mblnr      TYPE mseg-mblnr,
             ls_zsdt023    TYPE zsdt023,
             ls_zsdt022    TYPE zsdt022,
             lt_zsdt022    TYPE TABLE OF zsdt022,
             lv_rfc_log_id TYPE zrfc_logid.


        SELECT SINGLE *
          INTO @DATA(ls_zsdt013_2)
          FROM zsdt013
         WHERE mblnr = @ls_mseg-lfbnr "冲销的物料凭证
           AND mjahr = @ls_mseg-lfbja.

        SELECT SINGLE *
          FROM zsdt023
          INTO ls_zsdt023
         WHERE zzrfcid = ls_zsdt013_2-zrfcid
           AND canum = '0010'.

        IF sy-subrc = 0.
          IF ls_zsdt013_2-zmblnr IS NOT INITIAL.

            lv_posnr = lv_posnr + 10.
            ls_zsdt022-zposnr = lv_posnr.
            ls_zsdt022-mblnr = ls_mseg-mblnr.
            ls_zsdt022-zeile = ls_mseg-zeile.
            ls_zsdt022-mjahr = ls_mseg-mjahr.
            ls_zsdt022-budat = ls_mkpf-budat.
            ls_zsdt022-xblnr = ls_mkpf-xblnr.
            ls_zsdt022-bwart = ls_mseg-bwart.
            ls_zsdt022-menge = ls_mseg-menge.
            ls_zsdt022-grund = ls_mseg-grund.
            ls_zsdt022-zmblnr = ls_zsdt013_2-zmblnr.
            SELECT SINGLE ebeln ebelp matnr lgort charg werks
              INTO (
                     ls_zsdt022-ebeln,
                     ls_zsdt022-ebelp,
                     ls_zsdt022-matnr,
                     ls_zsdt022-lgort,
                     ls_zsdt022-charg,
                     ls_zsdt022-werks
                   )
              FROM mseg
             WHERE mblnr = ls_zsdt013_2-zmblnr
               AND mjahr = ls_mseg-lfbja
               AND zeile = ls_mseg-lfpos.

            APPEND ls_zsdt022 TO lt_zsdt022.
            CLEAR:ls_zsdt022.

          ENDIF.
        ENDIF.
      ENDLOOP.
      IF lt_zsdt022 IS NOT INITIAL.
        CALL FUNCTION 'ZMMFU003' IN BACKGROUND TASK
          EXPORTING
            iv_zjylx   = ls_zsdt023-zrfcid
          TABLES
            it_zsdt022 = lt_zsdt022[].
      ENDIF.

*      READ TABLE it_mseg INTO ls_mseg WITH KEY bwart = '102'.
*      IF sy-subrc = 0.

*        SELECT SINGLE zrfcid INTO lv_zjylx FROM zsdt013 WHERE mblnr = ls_mseg-smbln AND mjahr = ls_mseg-sjahr.
*        SELECT SINGLE * FROM zsdt023 INTO ls_zsdt023 WHERE zzrfcid = lv_zjylx AND canum = '0010'.
*        IF sy-subrc = 0.
*          IF lv_zmblnr IS NOT INITIAL.
*            ls_zsdt022-budat = is_mkpf-budat.
*            ls_zsdt022-mblnr = lv_zmblnr.
*            ls_zsdt022-mjahr = is_mkpf-mjahr.
*            ls_zsdt022-zrfcid = ls_zsdt023-zrfcid.
*            ls_zsdt022-zmblnr = ls_mseg-smbln.
*            APPEND ls_zsdt022 TO lt_zsdt022.
*
*
*            CALL FUNCTION 'ZMMFU003' IN BACKGROUND TASK
*              EXPORTING
*                iv_zjylx   = ls_zsdt023-zrfcid
*              TABLES
*                it_zsdt022 = lt_zsdt022[].
*          ENDIF.
*        ENDIF.
*      ENDIF.
    ENDIF.

 

标签:lv,收货,mseg,zsdt012,MIGO,zsdt022,ABAP,ls,mkpf
From: https://www.cnblogs.com/ap-ad-java-abap/p/16955482.html

相关文章

  • abap range结构四个字段含义
    定义range我们通常使用以下两种方法:data:gr_rantyperangeof...withheadline.data:begainofgr_ranoccur0,         signtypec,         ......
  • ABAP开发工具概述
    在学习这门语言之前,让我们先看看SAP的二次开发具有哪些工具和技术,这里给大家一个overview: 1、REPORT(报表):报表程序的主要作用是从数据库中抓取数据通过整理陈列出来,给......
  • ABAP 三种操作数据库的方法 OPEN SQL, EXEC SQL, ADBC
    OPENSQL这里就不多说了,可以执行大部分DML语句,但是却不支持DDL,DCL,UNIT,也没办法执行数据内嵌的函数。EXECSQL和ADBC是所谓的NativeSQL,这种方式直接进入指定数据库,不涉......
  • 我的ABAP学习历程
    在CSDN上混了3年了,但真正说起来,我的程序员历程却只有两年多一点。起初研究了半年的JAVA,从COREJAVA到JAVAME再到最后的JAVAEE,这里面的技术名目很多,特别是到了JAVAEE和W3C标......
  • ABAP-OpenSQL-select查询操作
    *&---------------------------------------------------------------------**&ReportZ13*&*&-----------------------------------------------------------------......
  • SAP ABAP Function Module 的动态调用方式使用方式介绍试读版
    在本教程前面的步骤7,我们介绍了ABAPFunctionModule的基本使用方法:​​7.ABAPfunctionmodule的使用​​最近我的知识星球有朋友提问:大佬,我想问一下动态获取到物料主......
  • SAP ABAP MIRO凭证拆分增强
    背景: 要求根据PO单汇总金额填入表头金额分摊页签,同时拆分BSEG表和ACDOCA表说明:两个增强点分别封装了冲销和过账函数,acdoca拆分通过memory传值注意:凭证拆分时,ct_bseg......
  • SAP ABAP ABVAN保存校验增强
    增强点:CL_FAA_BF_PAR_VAL_ACTIVATION 1IFsy-tcode='ABAVN'ORsy-ucomm='SAVE'.2ASSIGN('(SAPLAMDPS2I)RAIFP2-BUKRS')TO<fs_bukrs>.3IF<fs_buk......
  • ABAP学习(35):常用Function
    ABAPFunctionABAPCoding过程中比较好用的Function整理。1.获取Domain信息代码实例:"********************************获取domainFORM f_get_domain.  DATA:fs_......
  • XML 与ABAP对象转换
    sap与外部系统通过接口交互时,数据的传递通常有XML,JSON等格式,此处介绍XML与ABAP结构、内表互转的两种常用方法。A.一种是通过类cl_xml_document解析转换XML字符串,该方式......