其他分享
首页 > 其他分享> > ME21N增强-采购订单不能重复采购同一个资产号

ME21N增强-采购订单不能重复采购同一个资产号

作者:互联网

  原本都是从采购申请转采购订单,现在上了BPM后,有直接创建采购订单的情况,采购订单也增加增强,不能重复采购同一个资产号

SE19->使用ME_PROCESS_PO_CUST实施,这里以前有实施了的,直接用

 

 IF_EX_ME_PROCESS_PO_CUST~PROCESS_ACCOUNT,跟其它为删除的采购订单做比对,这里ZMMT001是以前建立的,在采购申请的增强中用来临时跳过检查重复采购资产号的。PS:本来这个表应该加上次级资产编号和公司代码的,因为其它原因,这里就只用资产号了。

METHOD if_ex_me_process_po_cust~process_account.
*  IF ls_head-bsart EQ 'Z002'.

*    BREAK it0003.

  DATA:lc_account TYPE REF TO if_purchase_order_account_mm,
       lc_item    TYPE REF TO if_purchase_order_item_mm,
       ls_poitem  TYPE mepoitem, "po item datas
       ls_account TYPE mepoaccounting, "科目分配字段结构
       lv_sakto   TYPE saknr. "总帐科目编号

  CALL METHOD im_account->get_item
    RECEIVING
      re_item = lc_item.

  CALL METHOD lc_item->get_data
    RECEIVING
      re_data = ls_poitem.

  IF ls_poitem-loekz EQ ''.


    CALL METHOD im_account->get_data
      RECEIVING
        re_data = ls_account.

    IF ls_account-anln1 IS NOT INITIAL.
      SELECT COUNT(*)
      FROM zmmt001
     WHERE anln1 EQ ls_account-anln1.
      IF sy-subrc NE 0.
*    READ TABLE Gt_ekkn INTO DATA(Gs_ekkn) INDEX 1.
*    IF sy-subrc EQ 0.
        SELECT COUNT(*)
          FROM ekkn JOIN ekpo ON ekkn~ebeln EQ ekpo~ebeln
                             AND ekkn~ebelp EQ ekpo~ebelp
         WHERE ekkn~anln1 EQ @ls_account-anln1
           AND ekkn~anln2 EQ @ls_account-anln2
           AND ekkn~kokrs EQ @ls_account-kokrs
           AND ekkn~ebeln NE @ls_account-ebeln
           AND ekpo~loekz EQ ''.
        IF sy-subrc EQ 0.
          MESSAGE e009(zhele).
        ENDIF.
*    ENDIF.
*  ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.

ENDMETHOD.
View Code

IF_EX_ME_PROCESS_PO_CUST~CHECK,同一个采购订单也不能同时存在相同的资产号

DATA: lt_data TYPE purchase_order_items,
        ls_data TYPE purchase_order_item.
  DATA: ls_item TYPE mepoitem.
  DATA: lt_item TYPE mepoitem.

  DATA: ls_head TYPE mepoheader.
  DATA: lv_class TYPE REF TO if_purchase_order_item_mm.
  DATA: lv_account TYPE REF TO if_purchase_order_account_mm,
        lt_account TYPE purchase_order_accountings,
        ls_account TYPE purchase_order_accounting,
        ls_anln1   TYPE mepoaccounting,
        lt_anln1   TYPE TABLE OF mepoaccounting,
        lv_tabix1  TYPE sy-tabix,
        lv_tabix2  TYPE sy-tabix.

LOOP AT lt_data INTO ls_data.
    lv_class = ls_data-item.
    CALL METHOD lv_class->get_accountings
      RECEIVING
        re_accountings = lt_account.
    LOOP AT lt_account INTO ls_account.
      lv_account = ls_account-accounting.
      CALL METHOD lv_account->get_data
        RECEIVING
          re_data = ls_anln1.
      SELECT COUNT(*)
      FROM zmmt001
     WHERE anln1 EQ ls_anln1-anln1.
      IF sy-subrc NE 0.
        APPEND ls_anln1 TO lt_anln1[].
      ENDIF.
    ENDLOOP.

  ENDLOOP.
*    BREAK-POINT.
  DELETE lt_anln1 WHERE anln1 EQ ''.
  lv_tabix1 = lines( lt_anln1[] ).
  SORT lt_anln1 BY kokrs anln1 anln2.
  DELETE ADJACENT DUPLICATES FROM lt_anln1 COMPARING kokrs anln1 anln2.
  lv_tabix2 = lines( lt_anln1[] ).
  IF lv_tabix1 NE lv_tabix2.
    MESSAGE e009(zhele).
  ENDIF.
View Code

 

标签:account,同一个,ME21N,lv,lt,ls,anln1,采购,TYPE
来源: https://www.cnblogs.com/chaguoguo/p/16320853.html