首页 > 其他分享 >ABAP:CO11N,CO13保存前增强

ABAP:CO11N,CO13保存前增强

时间:2023-05-26 11:45:54浏览次数:42  
标签:CO11N vornr lv aufnr ABAP confirmation EQ menge CO13

SE18:WORKORDER_CONFIRM

  METHOD if_ex_workorder_confirm~at_save.


    DATA: s_vornr TYPE RANGE OF resb-vornr .
    DATA: lv_vornr LIKE LINE OF s_vornr.

    DATA:lv_gmnga     TYPE afru-gmnga,
         lv_menge     TYPE mseg-menge,
         lv_menge_sum TYPE mseg-menge.
    DATA:lv_matnr TYPE mara-matnr.
    DATA:lv_string  TYPE string,
         lv_message TYPE bapi_msg.
    DATA:lt_mara TYPE TABLE OF mara,
         ls_mara LIKE LINE OF lt_mara.

    "[MOD-01]   07.02.2023 13:05:48  YSX 部分财务人员调账不需要执行齐套检查。
    AUTHORITY-CHECK OBJECT 'ZPP004'
     ID 'ZFLG_QX' FIELD 'X'.
    IF sy-subrc <> 0 AND sy-tcode EQ 'CO11N'.

      SELECT COUNT(*)
      FROM aufk
      WHERE aufnr = is_confirmation-aufnr
        AND auart NOT IN ( 'ZC04', 'ZC07',
                           'ZD04', 'ZD07',
                           'ZY04', 'ZY07' ).
      IF sy-subrc = 0.

        IF is_confirmation-werks = '8020'.
          lv_vornr-sign = 'I'.
          lv_vornr-option = 'EQ'.
          lv_vornr-low  = is_confirmation-vornr.
          APPEND lv_vornr TO s_vornr.
          CLEAR lv_vornr.
        ENDIF.

        SELECT
          bdmng,
          aufnr,
          matnr,
          charg,
          rsnum,
          werks,
          rspos,
          rsart,
          enmng
        FROM resb
        INTO TABLE @DATA(lt_resb)
        WHERE aufnr = @is_confirmation-aufnr
          AND vornr IN @s_vornr
          AND rgekz = ''
          AND xloek = ''
          AND dumps = ''
          AND schgt = ''
          AND kzear = ''
          AND shkzg <> 'S'
          AND bdmng > 0
          AND dbskz <> 'E'.

        IF lt_resb IS NOT INITIAL.
          SELECT
            aufnr,
            wemng,
            psmng
         FROM afpo
         INTO TABLE @DATA(lt_afpo)
         WHERE aufnr = @is_confirmation-aufnr.

          SELECT SINGLE
            SUM( gmnga )
          FROM afru
          INTO @DATA(lv_gmnga_a)
          WHERE aufnr = @is_confirmation-aufnr
            AND vornr = @is_confirmation-vornr
            AND stzhl = ''.

          SELECT SINGLE
            SUM( gmnga )
          FROM afru
          INTO @DATA(lv_gmnga_b)
         WHERE aufnr = @is_confirmation-aufnr
           AND vornr = @is_confirmation-vornr
           AND stzhl <> ''.

          CLEAR lv_gmnga.
          lv_gmnga = lv_gmnga_a - lv_gmnga_b.
          LOOP AT lt_resb ASSIGNING FIELD-SYMBOL(<ls_resb>).
            CLEAR lv_menge.
            READ TABLE lt_afpo ASSIGNING FIELD-SYMBOL(<ls_afpo>) WITH  KEY aufnr = <ls_resb>-aufnr.
            IF sy-subrc = 0.
              IF <ls_afpo>-psmng <> 0.
                SELECT SINGLE SUM( menge ) FROM mseg INTO @DATA(lv_menge_261)
                WHERE
                  rsnum = @<ls_resb>-rsnum AND
                  rspos = @<ls_resb>-rspos AND
                  bwart = '261'.

                SELECT SINGLE SUM( menge ) FROM mseg INTO @DATA(lv_menge_262)
                WHERE
                  rsnum = @<ls_resb>-rsnum AND
                  rspos = @<ls_resb>-rspos AND
                  bwart = '262'.
                lv_menge = lv_menge_261 - lv_menge_262.
                CLEAR:lv_menge_261,lv_menge_262.

                lv_menge_sum = ( lv_gmnga + is_confirmation-lmnga + is_confirmation-xmnga ) * <ls_resb>-bdmng / <ls_afpo>-psmng.

                IF lv_menge_sum > lv_menge.
*                lv_type = 'E'.

                  ls_mara-matnr = <ls_resb>-matnr.
                  APPEND ls_mara TO lt_mara.
                  CLEAR ls_mara.
*                CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
*                  EXPORTING
*                    input  = <ls_resb>-matnr
*                  IMPORTING
*                    output = lv_matnr.
*                es_return-type = 'E'.
*                PERFORM frm_alpha_output(zpub_f01) IF FOUND CHANGING <ls_resb>-matnr.
*                es_return-msg = '此工单未发料齐套!请检查发料' && <ls_resb>-matnr.
                ENDIF.
              ENDIF.
            ENDIF.
          ENDLOOP.
        ENDIF.
      ENDIF.

      IF lt_mara IS NOT INITIAL.

        LOOP AT lt_mara INTO ls_mara.
          CONCATENATE lv_string ls_mara-matnr ';' INTO lv_string.
        ENDLOOP.
        "此工单未发料齐套!请检查发料' && <ls_resb>-matnr.
        MESSAGE e005(zpp) DISPLAY LIKE 'E' WITH lv_string .

      ENDIF.
    ENDIF.

*****ADD BY ZJ 20230519 S 外协工序报工检查
    AUTHORITY-CHECK OBJECT 'ZPP004'
         ID 'ZFLG_QX' FIELD 'X'.
    IF sy-subrc <> 0.
      IF sy-tcode EQ 'CO11N' AND
         ( is_confirmation-werks EQ '8000' OR
           is_confirmation-werks EQ '8010' OR
           is_confirmation-werks EQ '8020' ).

        SELECT COUNT(*)
          FROM afko AS a
         INNER JOIN afvc AS b
            ON a~aufpl EQ b~aufpl
         WHERE a~aufnr EQ is_confirmation-aufnr
           AND b~steus EQ 'ZP02'.
        IF sy-subrc EQ 0.

          DATA:lv_menge2 TYPE eket-menge.

          "GMNGA数据
          SELECT SINGLE
             SUM( CASE stzhl
                    WHEN '00000000' THEN gmnga
                    ELSE gmnga * -1
                  END
                 )
            FROM afru
            INTO @DATA(lv_gmnga2)
           WHERE aufnr = @is_confirmation-aufnr
             AND vornr = @is_confirmation-vornr.
          "XMNGA数据
          SELECT SINGLE
             SUM( CASE stzhl
                    WHEN '00000000' THEN xmnga
                    ELSE xmnga * -1
                  END
                 )
            FROM afru
            INTO @DATA(lv_xmnga)
           WHERE aufnr = @is_confirmation-aufnr
             AND vornr = @is_confirmation-vornr.

          "查询EBAN是否下发采购订单
          SELECT c~ebeln
            FROM afko AS a
           INNER JOIN afvc AS b
              ON a~aufpl EQ b~aufpl
           INNER JOIN eban AS c
              ON b~banfn EQ c~banfn
             AND b~bnfpo EQ c~bnfpo
            INTO TABLE @DATA(lt_eban)
           WHERE a~aufnr EQ @is_confirmation-aufnr
             AND b~steus EQ 'ZP02'.

          "如果存在EBELN为空的数据
          READ TABLE lt_eban TRANSPORTING NO FIELDS
                             WITH KEY ebeln = ''.
          IF sy-subrc EQ 0.
            MESSAGE '工单外协工序收料不齐套' TYPE 'E'.
          ELSE.
            "查询EKET数据
            SELECT c~menge,c~wemng
              FROM afko AS a
              LEFT JOIN afvc AS b
                ON a~aufpl EQ b~aufpl
              LEFT JOIN eket AS c
                ON b~banfn EQ c~banfn
               AND b~bnfpo EQ c~bnfpo
              LEFT JOIN ekpo AS d
                ON d~banfn EQ c~banfn
               AND d~bnfpo EQ c~bnfpo
              INTO TABLE @DATA(lt_eket)
             WHERE a~aufnr EQ @is_confirmation-aufnr
               AND b~steus EQ 'ZP02'
               AND d~loekz NE 'L'
               AND d~retpo NE 'X'.

            LOOP AT lt_eket INTO DATA(ls_eket).

              lv_menge2 = lv_menge2 + ls_eket-wemng.

              CLEAR:ls_eket.
            ENDLOOP.

            lv_gmnga2 = lv_gmnga2 + lv_xmnga + is_confirmation-lmnga + is_confirmation-xmnga.

            IF lv_gmnga2 > lv_menge2.
              MESSAGE '工单外协工序收料不齐套' TYPE 'E'.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.

*****ADD BY ZJ 20230519 E 外协工序报工检查
  ENDMETHOD.

 

标签:CO11N,vornr,lv,aufnr,ABAP,confirmation,EQ,menge,CO13
From: https://www.cnblogs.com/ap-ad-java-abap/p/17434324.html

相关文章

  • ABAP新语法的坑
    1.问题描述新语法:SELECT或者READTABLE...INTODATA(变量名),直接将结果放到变量里面,不用声明变量的类型。看下面的代码,当READTABLElt_aufk没有查到值的时候,不会将空值INTO到结构变量ls_aufk2里面,ls_aufk2还是上一条记录的值。2.解决办法循环外面加上:CLEARls_aufk2."......
  • abap 宏的使用
    宏的使用宏(Macros)是一段独立的代码,能实现数据的运算和输出,功能与子程序类似,主要应用于同一程序中某些重复的运算,以简化代码。宏只能被本程序中定义于宏后面的语句调用。定义格式:DEFINEINCREMENT."INCREMENT是宏的名称.increment..."获取参数:第一个参数&1第......
  • ABAP 负号提前
    FUNCTION conversion_exit_z001_output.*"----------------------------------------------------------------------*"*"本地接口:*"  IMPORTING*"     REFERENCE(INPUT)*"  EXPORTING*"     REFERENCE(OUTPUT)*"---------------......
  • ABAP DEBUG技巧(持续更新)
    1.根据消息号查找WatchPoint  2.updatetast需要打开调试器的更新模式断点有时候打开也进不去需要watchpoint强制打进去函数或者程序的断点 执行程序前/H 打一个函数断点再执行update的函数 ......
  • ABAP-MD11计划订单创建
    1DATA:ls_returnTYPEbapireturn1,2ls_plafTYPEplaf,3ls_headerdataTYPEbapiplaf_i1.45ls_headerdata-pldord_profile=ls_plaf-paart.6ls_headerdata-plan_plant=ls_plaf-plwrk.7ls_headerdata-prod_plant=ls_plaf-pwwr......
  • ABAP-MD12删除计划订单
    1DATA:ls_returnTYPEbapireturn1,2ls_plafTYPEplaf.34CALLFUNCTION'BAPI_PLANNEDORDER_DELETE'5EXPORTING6plannedorder=ls_plaf-plnum7*USE_COLL_UPDATE=''8*LAST_ORDER=''......
  • ABAP-BAPI汇总
    MM模块MM01、MM02物料创建、物料修改BAPI_MATERIAL_SAVEDATABP供应商创建、供应商修改CVI_EI_INBOUND_MAINME11、ME12采购信息记录创建、采购信息记录修改ME_INFORECORD_MAINTAINME54N采购申请审批BAPI_REQUISITION_RELEASEMIGO-561期初库存批导BAPI_GO......
  • ABAP屏幕日期时间字段不显示
    内表日期和时间字段都有值,但是屏幕上面却不显示 将日期字段格式改成DATS时间字段格式改成TIMS重新查看结果,显示正常了。 ......
  • 使用 FOR ALL ENTRIES 将 ABAP 内表内容作为数据库表的读取条件之一试读版
    本教程之前的文章,我们已经介绍了如何用ST05事务码,对一个ABAP报表进行性能分析和优化的步骤。94.使用事务码ST05对SAPABAP数据库表访问性能调优的一个具体例子重构后的代码:REPORTzdb_optimization.DATA:lt_orderTYPETABLEOFzmyorder,ls_orderLIKE......
  • 在 ABAP 层执行 Open SQL 的幕后操作 - 武侠版
    在ABAP系统中使用事务码编写OPENSQL向数据库发起查询时,应用层和数据库层之间会发生一系列的交互。让我们详细介绍这个过程,并结合下面这张ABAP三层架构图:用户触发事务码:用户在ABAP系统中输入事务码,比如SE38(ABAP编辑器)或SE11(数据字典),并按下回车键。这将触发ABAP系统在应用层......