ABAP:MIGO收货,冲销增强

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.

 3.ITEM检查增强:这里增强没有前台页面行项目数据 需要在自定义类中手动添加,初始化,行更新删除时都需要更新此全局表

 

 

*****ADD BY ZJ 20230420 S

*(1)移动类型601(交货)602(交货冲销)只能挂销售相关的成本中心
*(2)移动类型Z07(免费发货)只能挂销售相关的成本中心
*(3)移动类型Z15/Z16(研发领料) 不能挂生产订单
    IF sy-tcode EQ 'MIGO'.

      FIELD-SYMBOLS:<fv_bwart> TYPE mseg-bwart,
                    <fv_aufnr> TYPE mseg-aufnr,
                    <fv_kostl> TYPE mseg-kostl,
                    <fv_erfmg> TYPE mseg-erfmg.
      DATA:ls_bapiret2 TYPE bapiret2.


      LOOP AT gt_goitem INTO DATA(ls_goitem) WHERE take_it IS NOT INITIAL
                                               AND global_counter = i_line_id.
        IF ( ls_goitem-bwart EQ 'Z15' OR
              ls_goitem-bwart EQ 'Z16' ) AND
           ls_goitem-erfmg > 0.

          "当移动类型为Z15/时,检查内部订单MSEG-AUFNR关联COAS-AUFNR,COAS-AUTYP是否为“1"
          "如果不是1则报错,"请选择研发内部订单”
          SELECT SINGLE autyp
            INTO @DATA(lv_autyp)
            FROM coas
           WHERE aufnr EQ @ls_goitem-aufnr.

          IF lv_autyp NE '1'.
            ls_bapiret2-type       = 'E'.
            ls_bapiret2-id         = 'MM'.
            ls_bapiret2-number     = '899'.
            ls_bapiret2-message_v1 = '请选择研发内部订单'.
            APPEND ls_bapiret2 TO et_bapiret2.
            CLEAR  ls_bapiret2.
          ENDIF.

          "当移动类型为Z15时,检查成本中心MSEG-KOSTL关联 CSKS-KOSTL,
          "CSKS-KOSAR是否为“E”,如果不是V则报错“请选择研发相关成本中心”
          SELECT SINGLE kosar
            INTO @DATA(lv_kosar)
            FROM csks
           WHERE kostl EQ @ls_goitem-kostl.

          IF lv_kosar NE 'E'.
            ls_bapiret2-type       = 'E'.
            ls_bapiret2-id         = 'MM'.
            ls_bapiret2-number     = '899'.
            ls_bapiret2-message_v1 = '请选择研发相关成本中心'.
            APPEND ls_bapiret2 TO et_bapiret2.
            CLEAR  ls_bapiret2.
          ENDIF.
        ENDIF.
        CLEAR:ls_goitem.
      ENDLOOP.
    ENDIF.

*****ADD BY ZJ 20230420 E

4.行更新增强

 

  METHOD if_ex_mb_migo_badi~line_modify.

*[MOD-01]  10.11.2021 10:06:57  ysx 261发料 比较按比例发料数量和剩余发料数量,取小进行发料

    "当移动类型是101/Z10/511/531 时,取输入日期20200204的后6位作为批次编码的前6位,按照物料的维度,每个物料的流水码依次增加
    BREAK jt-tansh.

*    RETURN.

    DATA:lv_str   TYPE char10,
         lv_charg TYPE mseg-charg.
    DATA:lv_headn TYPE char3.
    DATA:lv_headm TYPE char4.
    DATA:lv_matnr TYPE mara-matnr.


    FIELD-SYMBOLS:<fs> TYPE bkpf-budat.

    lv_str = sy-datum+2(6) && '%'.

    ASSIGN ('(SAPLMIGO)GOHEAD-BUDAT') TO <fs> .

    IF cs_goitem-werks IS NOT INITIAL AND cs_goitem-matnr IS NOT INITIAL AND cs_goitem-vbeln IS INITIAL.
      SELECT SINGLE xchpf INTO @DATA(lv_xchpf) FROM mara WHERE matnr = @cs_goitem-matnr.
      SELECT SINGLE xchpf INTO @DATA(lv_xchpf1) FROM marc WHERE matnr = @cs_goitem-matnr AND werks = @cs_goitem-werks.

      IF lv_xchpf = 'X' AND lv_xchpf1 = 'X'.
        IF cs_goitem-bwart = '101' OR cs_goitem-bwart = 'Z10' OR cs_goitem-bwart = '511' OR cs_goitem-bwart = '531' OR ( cs_goitem-bwart = '501' AND cs_goitem-sobkz = 'B').

          " READ TABLE gt_matnr INTO DATA(ls_matnr) WITH KEY matnr = cs_goitem-matnr.
          " IF sy-subrc <> 0.

*------------------[MOD-02] YSX 03.11.2022 16:05:13   BEGIN--------"-增加凯研母卷料号判断,凯研母卷需要手动输入批次---------
          IF cs_goitem-werks = '8010'.
            CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
              EXPORTING
                input  = cs_goitem-matnr
              IMPORTING
                output = lv_matnr.

            lv_headn = lv_matnr(3).
            SELECT SINGLE * FROM makt INTO @DATA(lv_makt) WHERE matnr = @cs_goitem-matnr.
            IF sy-subrc = 0.
              lv_headm = lv_makt-maktx(4).
            ENDIF.

           "
            IF lv_headn <> '101' OR lv_headm <> '母卷-T'.
              SELECT MAX( charg ) INTO lv_charg
              FROM mseg
              WHERE matnr = cs_goitem-matnr
              AND charg LIKE lv_str.

              IF lv_charg+0(6) = <fs>+2(6).
                cs_goitem-charg = lv_charg + '0001'.
              ELSE.
                cs_goitem-charg = <fs>+2(6) && '0001'.
              ENDIF.
            ENDIF.

          ELSE.
            SELECT MAX( charg ) INTO lv_charg
            FROM mseg
            WHERE matnr = cs_goitem-matnr
            AND charg LIKE lv_str.

            IF lv_charg+0(6) = <fs>+2(6).
              cs_goitem-charg = lv_charg + '0001'.
            ELSE.
              cs_goitem-charg = <fs>+2(6) && '0001'.
            ENDIF.
          ENDIF.





          "  ELSE.
          " cs_goitem-charg = ls_matnr-charg + '0001'.
          "  ENDIF.

          " MOVE-CORRESPONDING cs_goitem TO ls_matnr.
          " APPEND ls_matnr TO gt_matnr.
          "CLEAR:ls_matnr.

        ENDIF.
      ENDIF.

    ENDIF.


*&---工单计划内发料增强---BEGIN---20210616------
    DATA:lv_flsl       TYPE mseg-menge,
         lv_sysl       TYPE mseg-menge,
         lv_line_id    TYPE mb_line_id,
         lv_charg_flag TYPE flag,
         lv_mstnr      TYPE mseg-menge,
         lv_zc         TYPE  goaction,
         lv_sw         TYPE  refdoc.
    FIELD-SYMBOLS:<fs_mtsnr> TYPE mtsnr1,
                  <fs_zc>    TYPE goaction,
                  <fs_sw>    TYPE refdoc.

    CLEAR:lv_flsl,lv_line_id,lv_charg_flag,lv_zc,lv_sw,lv_mstnr.
    ASSIGN ('(SAPLMIGO)GOHEAD-MTSNR')    TO <fs_mtsnr>.
    ASSIGN ('(SAPLMIGO)GODYNPRO-ACTION') TO <fs_zc>.
    ASSIGN ('(SAPLMIGO)GODYNPRO-REFDOC') TO <fs_sw>.



    IF <fs_zc> IS ASSIGNED.
      IF <fs_zc> IS NOT INITIAL.
        lv_zc = <fs_zc>.
      ENDIF.
    ENDIF.

    IF <fs_sw> IS ASSIGNED.
      IF <fs_sw> IS NOT INITIAL.
        lv_sw = <fs_sw>.
      ENDIF.
    ENDIF.

    IF ( cs_goitem-bwart = '261' AND lv_zc = 'A07' AND lv_sw = 'R08' )
       OR ( lv_zc = 'A07' AND lv_sw = 'R10' AND cs_goitem-bwart = 'Z03' ).
*&---数量检查
      IF cs_goitem-bwart = '261'.
        SELECT SINGLE COUNT(*) FROM aufk WHERE aufnr = cs_goitem-aufnr AND loekz = ''.
        IF sy-subrc = 0.
          SELECT SINGLE SUM( psmng ) FROM afpo INNER JOIN aufk ON afpo~aufnr = aufk~aufnr
             INTO @DATA(lv_psmng)
          WHERE
            aufk~loekz = ''          AND
            afpo~aufnr = @cs_goitem-aufnr.

          SELECT SINGLE SUM( wemng ) FROM afpo INNER JOIN aufk ON afpo~aufnr = aufk~aufnr
             INTO @DATA(lv_wemng)
          WHERE
            aufk~loekz = ''          AND
            afpo~aufnr = @cs_goitem-aufnr.
          lv_mstnr = <fs_mtsnr>.
          IF lv_mstnr > lv_psmng - lv_wemng.
            RETURN.
          ENDIF.
        ENDIF.
      ENDIF.

      IMPORT p_line_id TO lv_line_id FROM MEMORY ID 'LINE_ID'.
      SELECT SINGLE xchpf FROM marc INTO lv_charg_flag WHERE matnr = cs_goitem-matnr AND werks = cs_goitem-werks.
      IF lv_charg_flag IS NOT INITIAL.
        IF cs_goitem-xdetermination = 'X'.
          IF lv_line_id <> i_line_id OR ( lv_line_id = i_line_id AND cs_goitem-erfmg IS INITIAL ).

            IF <fs_mtsnr> IS ASSIGNED.
              IF <fs_mtsnr> IS NOT INITIAL.

                SELECT SINGLE bdmng INTO @DATA(lv_bdmng) FROM resb WHERE rsnum = @cs_goitem-rsnum AND rspos = @cs_goitem-rspos.
                SELECT SINGLE gamng INTO @DATA(lv_gamng) FROM afko INNER JOIN aufk ON afko~aufnr = aufk~aufnr
                  WHERE afko~aufnr = @cs_goitem-aufnr AND aufk~loekz = ''.
                "[MOD-01] YSX  取剩余发料数量
                SELECT SINGLE * INTO @DATA(lv_resb) FROM  resb WHERE rsnum = @cs_goitem-rsnum AND rspos = @cs_goitem-rspos.
                IF sy-subrc = 0.
                  lv_sysl = lv_resb-bdmng - lv_resb-enmng.
                ENDIF.

                IF lv_bdmng IS NOT INITIAL AND lv_gamng IS NOT INITIAL.
                  lv_flsl = <fs_mtsnr> / lv_gamng * lv_bdmng.
                  IF cs_goitem-erfme = 'EA' OR cs_goitem-erfme = 'ST'.
                    lv_flsl = ceil( lv_flsl ).
                  ENDIF.

                  "[MOD-01] YSX 实际发料数量取小
                  IF lv_flsl >= lv_sysl.
                    cs_goitem-erfmg = lv_sysl.
                  ELSE.
                    cs_goitem-erfmg = lv_flsl.
                  ENDIF.


                  FREE MEMORY ID 'LINE_ID'.
                  EXPORT p_line_id FROM i_line_id TO MEMORY ID 'LINE_ID'.
                ENDIF.
                CLEAR:lv_bdmng,lv_gamng.
                UNASSIGN <fs_mtsnr>.

              ENDIF.
            ENDIF.
          ENDIF.
        ENDIF.
      ELSE.
        IF lv_line_id <> i_line_id OR ( lv_line_id = i_line_id AND cs_goitem-erfmg IS INITIAL ).
          IF <fs_mtsnr> IS ASSIGNED.
            IF <fs_mtsnr> IS NOT INITIAL.
              SELECT SINGLE bdmng INTO @DATA(lv_bdmng_b) FROM resb WHERE rsnum = @cs_goitem-rsnum AND rspos = @cs_goitem-rspos.
              SELECT SINGLE gamng INTO @DATA(lv_gamng_b) FROM afko INNER JOIN aufk ON afko~aufnr = aufk~aufnr
                WHERE afko~aufnr = @cs_goitem-aufnr AND aufk~loekz = ''.
              "[MOD-01] YSX  取剩余发料数量
              SELECT SINGLE * INTO @DATA(lv_resb_b) FROM  resb WHERE rsnum = @cs_goitem-rsnum AND rspos = @cs_goitem-rspos.
              IF sy-subrc = 0.
                lv_sysl = lv_resb_b-bdmng - lv_resb_b-enmng.
              ENDIF.

              IF lv_bdmng_b IS NOT INITIAL AND lv_gamng_b IS NOT INITIAL.
                lv_flsl = <fs_mtsnr> / lv_gamng_b * lv_bdmng_b.
                IF cs_goitem-erfme = 'EA' OR cs_goitem-erfme = 'ST'.
                  lv_flsl = ceil( lv_flsl ).
                ENDIF.

                "[MOD-01] YSX 实际发料数量取小
                IF lv_flsl >= lv_sysl.
                  cs_goitem-erfmg = lv_sysl.
                ELSE.
                  cs_goitem-erfmg = lv_flsl.
                ENDIF.

                FREE MEMORY ID 'LINE_ID'.
                EXPORT p_line_id FROM i_line_id TO MEMORY ID 'LINE_ID'.
              ENDIF.
              CLEAR:lv_bdmng_b,lv_gamng_b.
              UNASSIGN <fs_mtsnr>.

            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.

*&---工单计划内发料增强---END-----20210616------



*    DATA:lv_str TYPE char10.
*
*    lv_str = sy-datum+2(6).
*
*    lv_str = lv_str && '%'.
*    select
*      matnr,
*      charg
*      into TABLE @data(lt_mseg)
*      from mseg
*      FOR ALL ENTRIES IN @it_mseg
*      WHERE matnr = @it_mseg-matnr
*      and charg like @lv_str.
*
*
*
*    LOOP AT it_mseg into DATA(ls_mseg).
*
*      sort lt_mseg by matnr CHARG DESCENDING.
*      "以物料的维度,加1,
*      READ TABLE lt_mseg into DATA(ls_mseg1) WITH KEY matnr = ls_mseg-matnr.
*      IF sy-subrc = 0.
*        ls_mseg-CHARG = ls_mseg1 + 1.
*      else.
*        ls_mseg-CHARG = sy-datum+2(6) && '0001'.
*      ENDIF.
*
*      MOVE-CORRESPONDING ls_mseg to ls_mseg1.
*      APPEND ls_mseg1 to lt_mseg.
*      CLEAR:ls_mseg1.
*
*      modify it_mseg from ls_mseg.
*      CLEAr:ls_mseg.
*    ENDLOOP.

  ENDMETHOD.

5.抬头检查增强

 

  METHOD IF_EX_MB_MIGO_BADI~CHECK_HEADER.
*&---校验填的物料单是否大于工单数量
    DATA:LV_FLSL     TYPE MSEG-MENGE,
         LV_MSTNR    TYPE MSEG-MENGE,
         LV_AUFNR    TYPE AUFNR,
         LV_BWART    TYPE BWART,
         LV_ZC       TYPE  GOACTION,
         LV_SW       TYPE  REFDOC,
         LS_BAPIRET2 TYPE BAPIRET2.

    FIELD-SYMBOLS:<FS_MTSNR> TYPE MTSNR1,
                  <FS_ZC>    TYPE GOACTION,
                  <FS_SW>    TYPE REFDOC,
                  <FS_AUFNR> TYPE AUFNR,
                  <FS_BWART> TYPE BWART.
    CLEAR:LV_MSTNR,LV_ZC,LV_SW,LV_AUFNR,LV_BWART.
    ASSIGN ('(SAPLMIGO)GOHEAD-MTSNR')          TO <FS_MTSNR>.
    ASSIGN ('(SAPLMIGO)GOITEM-AUFNR')          TO <FS_AUFNR>.
    ASSIGN ('(SAPLMIGO)GODEFAULT_TV-BWART')    TO <FS_BWART>.
    ASSIGN ('(SAPLMIGO)GODYNPRO-ACTION')       TO <FS_ZC>.
    ASSIGN ('(SAPLMIGO)GODYNPRO-REFDOC')       TO <FS_SW>.

    IF <FS_AUFNR> IS ASSIGNED .
      IF <FS_AUFNR> IS NOT INITIAL.
        LV_AUFNR = <FS_AUFNR>.
      ENDIF.
    ENDIF.

    IF <FS_BWART> IS ASSIGNED .
      IF <FS_BWART> IS NOT INITIAL.
        LV_BWART = <FS_BWART>.
      ENDIF.
    ENDIF.

    IF <FS_ZC> IS ASSIGNED .
      IF <FS_ZC> IS NOT INITIAL.
        LV_ZC = <FS_ZC>.
      ENDIF.
    ENDIF.

    IF <FS_SW> IS ASSIGNED .
      IF <FS_SW> IS NOT INITIAL.
        LV_SW = <FS_SW>.
      ENDIF.
    ENDIF.

    IF LV_BWART = '261' AND LV_ZC = 'A07' AND LV_SW = 'R08'.
      IF <FS_MTSNR> IS ASSIGNED.
        IF <FS_MTSNR> IS NOT INITIAL.
          SELECT SINGLE COUNT(*) FROM AUFK WHERE AUFNR = LV_AUFNR AND LOEKZ = ''.
          IF SY-SUBRC = 0.
            SELECT SINGLE SUM( PSMNG ) FROM AFPO INNER JOIN AUFK ON AFPO~AUFNR = AUFK~AUFNR
               INTO @DATA(LV_PSMNG)
            WHERE
              AUFK~LOEKZ = ''          AND
              AFPO~AUFNR = @LV_AUFNR.

            SELECT SINGLE SUM( WEMNG ) FROM AFPO INNER JOIN AUFK ON AFPO~AUFNR = AUFK~AUFNR
               INTO @DATA(LV_WEMNG)
            WHERE
              AUFK~LOEKZ = ''          AND
              AFPO~AUFNR = @LV_AUFNR.
            LV_MSTNR = <FS_MTSNR>.
            IF LV_MSTNR > LV_PSMNG - LV_WEMNG.
              LS_BAPIRET2-TYPE       = 'E'.
              LS_BAPIRET2-ID         = 'MM'.
              LS_BAPIRET2-NUMBER     = '899'.
              LS_BAPIRET2-MESSAGE_V1 = '套数不能大于工单的剩余交货数量'.
              APPEND LS_BAPIRET2 TO ET_BAPIRET2.
              CLEAR  LS_BAPIRET2.
            ENDIF.
            CLEAR:LV_PSMNG,LV_WEMNG.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDMETHOD.
posted @ 2022-12-06 16:08  阿胖的阿多  阅读(2171)  评论(0编辑  收藏  举报