ABAP:生产订单CO01/CO02/CO03保存前增强

T-Code:SMOD-PPCO0007(Header字段),PPCO0001,PPCO0012(屏幕增强)

*&---------------------------------------------------------------------*
*& 包含               ZXCO1U06
*&---------------------------------------------------------------------*
*[MOD-01]  18.09.2021 17:51:22  ysx 检查工单所有工序的工序控制码,有且只能是最后一道工序的控制码为ZP04
*[MOD-02] 31.08.2022 14:19:42  YSX 已下达工单保存判断工序是否状态为删除_ysx_pkm_20220831

DATA:lv_order TYPE cobrb-objnr.
DATA:lt_afvg TYPE TABLE OF afvgdget WITH HEADER LINE.
DATA:lt_afvg_old TYPE TABLE OF afvgd WITH HEADER LINE.
DATA: lv_line TYPE i.
DATA: lt_resbd TYPE TABLE OF resbdget WITH HEADER LINE.

SELECT SINGLE *  FROM zbasis_zq  INTO @DATA(lv_zbasis_zq) WHERE zkhd = @sy-mandt.
CASE lv_zbasis_zq-zkzma.
  WHEN 'Z001'. "凯卓威

    "校验结算规则是否维护订单
    IF header_imp-auart = 'ZK07' .

      CONCATENATE 'OR' header_imp-aufnr INTO lv_order.
      ASSIGN ('(SAPLKOBS)COBL-VORGN') TO FIELD-SYMBOL(<fs_str2>) .
      IF sy-subrc = 0..
        IF <fs_str2> IS  INITIAL..
          SELECT SINGLE * FROM cobrb INTO @DATA(ls_cobrb)  WHERE objnr = @lv_order.
          IF sy-subrc = 0  .
            IF ls_cobrb-aufnr IS INITIAL .
*        MESSAGE '订单未维护' TYPE 'E'.
              MESSAGE e000(zpp) .
            ENDIF.
          ELSE.
            MESSAGE e000(zpp) .

          ENDIF.

        ELSE.
          ASSIGN ('(SAPLKOBS)COBL-AUFNR') TO FIELD-SYMBOL(<fs_str>) .
          IF sy-subrc = 0.
            IF <fs_str> IS  INITIAL.
              MESSAGE e000(zpp).
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.

    ENDIF.
*    ASSIGN ('(SAPLKOBS)COBL-AUFNR') TO FIELD-SYMBOL(<fs_str>) .
*
**  IMPORT i_aufk FROM MEMORY ID 'KO'.
*    IF sy-subrc = 0.
*      IF <fs_str> IS  INITIAL.
*        SELECT SINGLE * FROM cobrb INTO @DATA(ls_cobrb)  WHERE objnr = @lv_order.
*        IF sy-subrc = 0  .
*          IF ls_cobrb-aufnr IS INITIAL .
**        MESSAGE '订单未维护' TYPE 'E'.
*            MESSAGE e000(zpp) .
*          ENDIF.
*        ELSE.
*          MESSAGE e000(zpp) .
*        ENDIF.
*
*      ENDIF.
*    ENDIF.

*ADD BY JT-WUW 20210517-保存校验反冲料组件库存地点不为空

    CALL FUNCTION 'CO_BC_RESBD_OF_ORDER_GET'
      EXPORTING
        aufnr_act = header_imp-aufnr
      TABLES
        resbd_get = lt_resbd.

    LOOP AT lt_resbd WHERE rgekz = abap_true
                       AND xloek = space.
      IF lt_resbd-lgort IS INITIAL.
*    反冲组件&1库存地点为空!
        MESSAGE e001(zpp) WITH lt_resbd-matnr.
      ENDIF.
    ENDLOOP.
*END ADD


    "[MOD-01] YSX 有且只能是最后一道工序的控制码为ZP04
    CASE header_imp-auart.
      WHEN 'ZD04' OR  'ZD07' OR 'ZD08' OR 'ZY04' OR 'ZY07'
        OR 'ZY08' OR 'ZC04' OR 'ZC07' OR 'ZC08' .

      WHEN OTHERS.

        CALL FUNCTION 'CO_BO_OPR_OF_ORDER_GET'
          EXPORTING
            aufnr_imp = header_imp-aufnr
          TABLES
            afvgd_get = lt_afvg.
*   AFVGT_OLD =.

        "考虑:重读后历史工序删除后进行判断
*    SORT lt_afvg BY vornr rueck ASCENDING.
*    DELETE ADJACENT DUPLICATES FROM lt_afvg COMPARING  vornr.
        DELETE lt_afvg WHERE vbkz = 'D'.

        SORT lt_afvg BY vornr DESCENDING.

        READ TABLE lt_afvg INTO DATA(ls_afvg) INDEX 1.
        IF sy-subrc = 0.
          IF ls_afvg-steus <> 'ZP04'.
            MESSAGE e002(zpp) WITH header_imp-matnr.
          ELSE.
            LOOP AT lt_afvg INTO DATA(ls_afvg_l).
              IF ls_afvg_l-steus = 'ZP04' AND sy-tabix <> '1'  .
                MESSAGE e002(zpp) WITH header_imp-matnr.
              ENDIF.
            ENDLOOP.

          ENDIF.
        ENDIF.

    ENDCASE.

  WHEN 'K001'. "凯迪

    "用于订单状态修改时,实时变更模具平台自建表的状态.
    "add by jt-tansh 20210127
    IF header_imp-sttxt CS 'REL'.
      "update zppt001 set zmjzt = '05' WHERE aufnr = HEADER_IMP-aufnr.
    ELSEIF header_imp-sttxt CS 'DLV'.
      SELECT SINGLE * INTO @DATA(ls_zppt001) FROM zppt001  WHERE aufnr = @header_imp-aufnr.
      IF sy-subrc = 0.
        ls_zppt001-zmjzt = '07'."完模入库
        MODIFY zppt001 FROM ls_zppt001 .
      ENDIF.

    ENDIF.


    "校验结算规则是否维护订单
    IF header_imp-auart = 'ZD09' .

      CONCATENATE 'OR' header_imp-aufnr INTO lv_order.
      ASSIGN ('(SAPLKOBS)COBL-VORGN') TO <fs_str2> .
      IF sy-subrc = 0..
        IF <fs_str2> IS  INITIAL..
          SELECT SINGLE * FROM cobrb INTO ls_cobrb  WHERE objnr = lv_order.
          IF sy-subrc = 0  .
            IF ls_cobrb-aufnr IS INITIAL .
*        MESSAGE '订单未维护' TYPE 'E'.
              MESSAGE e000(zpp) .
            ENDIF.
          ELSE.
            MESSAGE e000(zpp) .

          ENDIF.

        ELSE.
          ASSIGN ('(SAPLKOBS)COBL-AUFNR') TO <fs_str> .
          IF sy-subrc = 0.
            IF <fs_str> IS  INITIAL.
              MESSAGE e000(zpp).
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.

    ENDIF.
*    ASSIGN ('(SAPLKOBS)COBL-AUFNR') TO FIELD-SYMBOL(<fs_str>) .
*
**  IMPORT i_aufk FROM MEMORY ID 'KO'.
*    IF sy-subrc = 0.
*      IF <fs_str> IS  INITIAL.
*        SELECT SINGLE * FROM cobrb INTO @DATA(ls_cobrb)  WHERE objnr = @lv_order.
*        IF sy-subrc = 0  .
*          IF ls_cobrb-aufnr IS INITIAL .
**        MESSAGE '订单未维护' TYPE 'E'.
*            MESSAGE e000(zpp) .
*          ENDIF.
*        ELSE.
*          MESSAGE e000(zpp) .
*        ENDIF.
*
*      ENDIF.
*    ENDIF.

*ADD BY JT-WUW 20210517-保存校验反冲料组件库存地点不为空

    CALL FUNCTION 'CO_BC_RESBD_OF_ORDER_GET'
      EXPORTING
        aufnr_act = header_imp-aufnr
      TABLES
        resbd_get = lt_resbd.

    LOOP AT lt_resbd WHERE rgekz = abap_true
                       AND xloek = space.
      IF lt_resbd-lgort IS INITIAL.
*    反冲组件&1库存地点为空!
        MESSAGE e001(zpp) WITH lt_resbd-matnr.
      ENDIF.
    ENDLOOP.
*END ADD


    "[MOD-01] YSX 有且只能是最后一道工序的控制码为ZP04
    CASE header_imp-auart.
      WHEN 'ZD04' OR  'ZD07' OR 'ZD08' OR 'ZY04' OR 'ZY07'
        OR 'ZY08' OR 'ZC04' OR 'ZC07' OR 'ZC08' .

      WHEN OTHERS.

        CALL FUNCTION 'CO_BO_OPR_OF_ORDER_GET'
          EXPORTING
            aufnr_imp = header_imp-aufnr
          TABLES
            afvgd_get = lt_afvg
            afvgt_old = lt_afvg_old.

        "考虑:重读后历史工序删除后进行判断
*    SORT lt_afvg BY vornr rueck ASCENDING.
*    DELETE ADJACENT DUPLICATES FROM lt_afvg COMPARING  vornr.
        DELETE lt_afvg WHERE vbkz = 'D'.

        SORT lt_afvg BY vornr DESCENDING.

        "[MOD-02]   31.08.2022 14:20:01  YSX
        LOOP AT lt_afvg INTO ls_afvg.
          "判断该工序状态是否已经删除
          SELECT COUNT(*) FROM jest  WHERE objnr = @ls_afvg-objnr
                                      AND stat = 'I0013'
                                      AND inact IS INITIAL .

          IF sy-subrc = 0.
            DELETE lt_afvg  WHERE vornr = ls_afvg-vornr.

            CONTINUE.
          ENDIF.

          "判断是否逻辑删除
          CALL FUNCTION 'STATUS_CHECK'
            EXPORTING
              objnr             = ls_afvg-objnr
              status            = 'I0013'
            EXCEPTIONS
              object_not_found  = 01
              status_not_active = 02.
          IF sy-subrc = 0.
            DELETE lt_afvg  WHERE vornr = ls_afvg-vornr.
          ENDIF.
        ENDLOOP.

        READ TABLE lt_afvg INTO ls_afvg INDEX 1.
        IF sy-subrc = 0.
          IF ls_afvg-steus <> 'ZP04'.
            MESSAGE e002(zpp) WITH header_imp-matnr.
          ELSE.
            LOOP AT lt_afvg INTO ls_afvg_l.
              IF ls_afvg_l-steus = 'ZP04' AND sy-tabix <> '1'  .
                MESSAGE e002(zpp) WITH header_imp-matnr.
              ENDIF.
            ENDLOOP.
          ENDIF.
        ENDIF.
    ENDCASE.
  WHEN OTHERS.
ENDCASE.

 在创建/修改生产订单时,有需求是进行组件数据校验,不满足条件时,要报错

在PPCO0001里面进行MESSAGE TYPE E的话 会程序DUMP,因为增强在COMMIT阶段,会DUMP报错COMMIT被终止了

 解决方案1:在PPCO0001中,报S类型消息DISPLAY LIKE E,然后LEVAE TO 'CO01'

MESSAGE lv_str TYPE S DISPLAY LIKE 'E'.
LEAVE TO TRANSACTION 'CO01'.

解决方案2:在PPCO0007中,调用函数'CO_BC_RESBD_OF_ORDER_GET',获取作业中的订单号对应的组件,进行报错操作

IF sy-tcode EQ 'CO01'.

  CALL FUNCTION 'CO_BC_RESBD_OF_ORDER_GET'
    EXPORTING
      aufnr_act = header_imp-aufnr
    TABLES
      resbd_get = lt_resbd2.

  "查询组件对应的物料组
  WITH +i AS ( SELECT DISTINCT matnr
                 FROM @lt_resbd2 AS k )
SELECT i~matnr,a~matkl
  FROM +i AS i
  LEFT JOIN mara AS a
    ON a~matnr EQ i~matnr
 WHERE matkl EQ '431001'
  INTO TABLE @DATA(lt_mara).
  SORT lt_mara BY matnr.

  "查询组件对应的MKAL记录
  WITH +i AS ( SELECT DISTINCT k~matnr
                 FROM @lt_resbd2 AS k
                 LEFT JOIN mara AS a
                   ON k~matnr EQ a~matnr
                WHERE a~matkl EQ '431001' )
SELECT i~matnr,a~prfg_f,a~adatu,a~bdatu
  FROM +i AS i
  LEFT JOIN mkal AS a
    ON i~matnr EQ a~matnr
 WHERE EXISTS ( SELECT matnr
                  FROM mkal
                 WHERE matnr = i~matnr )
  INTO TABLE @DATA(lt_mkal).
  SORT lt_mkal BY matnr.

  AUTHORITY-CHECK OBJECT 'ZPP_EXIT'
     ID 'WERKS' FIELD header_imp-werks
     ID 'DISPO' FIELD header_imp-dispo
     ID 'ZFLAG_EXIT' FIELD 'X'.
  IF sy-subrc EQ 0.
    LOOP AT lt_resbd2 INTO DATA(ls_resbd).
      "查询组件对应的物料组,如果是431001则继续进行判断
      READ TABLE lt_mara TRANSPORTING NO FIELDS
                         WITH KEY matnr = ls_resbd-matnr
                         BINARY SEARCH.
      IF sy-subrc EQ 0.
        "查询MKAL是否存在记录
        READ TABLE lt_mkal TRANSPORTING NO FIELDS
                           WITH KEY matnr = ls_resbd-matnr
                           BINARY SEARCH.
        IF sy-subrc NE 0.
          "不存在记录 报错"虚拟键缺失生产版本
          MESSAGE '虚拟键' && ls_resbd-matnr && '缺失生产版本' TYPE 'E'.
        ELSE.
          LOOP AT lt_mkal TRANSPORTING NO FIELDS WHERE matnr = ls_resbd-matnr
                                                   AND prfg_f EQ '1'
                                                   AND adatu <= header_imp-plauf
                                                   AND bdatu >= header_imp-plauf.
            EXIT.
          ENDLOOP.
          IF sy-subrc NE 0.
            "不存在符合条件的记录 报错:虚拟键存在不可用生产版本
            MESSAGE '虚拟键' && ls_resbd-matnr && '存在不可用生产版本' TYPE 'E'.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDLOOP.
  ENDIF.

ENDIF.

 生产订单创建时,有需求需要自定义生产订单编号,可在三代增强BADI:WORKORDER_UPDATE~NUMBER_SWITCH中实现

SE18-BADI:WORKORDER_UPDATE


 

  METHOD IF_EX_WORKORDER_UPDATE~NUMBER_SWITCH.

    DATA : LS_ZPPT008 TYPE ZPPT008 .
    DATA : LS_CAUFVD TYPE CAUFVD .
    DATA : LV_FIELD(50) TYPE C .
    DATA : LV_ZQDSZ(2) TYPE C .

    FIELD-SYMBOLS : <LV_F> TYPE ANY  .


    IF I_AUFNR_OLD+0(1) = '%' .
      LV_FIELD = '(SAPLCOKO1)CAUFVD' .
      ASSIGN (LV_FIELD) TO <LV_F> .
      IF SY-SUBRC = 0 .
        LS_CAUFVD = <LV_F> .

        DO 100 TIMES.
          CALL FUNCTION 'ENQUEUE_EZPPT008'
            EXPORTING
              WERKS          = LS_CAUFVD-WERKS
              BUDAT          = SY-DATUM
            EXCEPTIONS
              FOREIGN_LOCK   = 1
              SYSTEM_FAILURE = 2
              OTHERS         = 3.
          IF SY-SUBRC =  0.
            CLEAR LS_ZPPT008 .
            SELECT SINGLE *
              INTO LS_ZPPT008
              FROM ZPPT008
              WHERE WERKS = LS_CAUFVD-WERKS
                AND BUDAT = SY-DATUM .
            LS_ZPPT008-WERKS = LS_CAUFVD-WERKS .
            LS_ZPPT008-BUDAT = SY-DATUM .
            LS_ZPPT008-VALUE = LS_ZPPT008-VALUE + 1 .
            MODIFY ZPPT008 FROM LS_ZPPT008 .
            LV_ZQDSZ = LS_CAUFVD-WERKS+0(1) && LS_CAUFVD-WERKS+2(1).
*            I_AUFNR_CHANGE = LS_CAUFVD-WERKS+2(2) &&  SY-DATUM+2(6) && LS_ZPPT008-VALUE .
            I_AUFNR_CHANGE = LV_ZQDSZ &&  SY-DATUM+2(6) && LS_ZPPT008-VALUE .
            CALL FUNCTION 'DEQUEUE_EZPPT008'
              EXPORTING
                WERKS = LS_CAUFVD-WERKS
                BUDAT = SY-DATUM.
            EXIT .
          ELSE .
            WAIT UP TO '0.1' SECONDS .
          ENDIF.
        ENDDO.

      ENDIF .
    ENDIF .



  ENDMETHOD.

 

 

 

posted @ 2023-10-11 13:37  阿胖的阿多  阅读(2658)  评论(0编辑  收藏  举报