MM采购订单的增强user-exit:MM06E005(示例程序是下PO做成本MR21)

MM06E005      在采购凭证中的客户字段 EXIT_SAPMM06E_017


*&---------------------------------------------------------------------*
*&  包括                ZXM06U42
*&---------------------------------------------------------------------*
DATA:gt_mara LIKE TABLE OF mara,
      gs_mara LIKE mara,
      gs_mbew LIKE mbew,
      gs_marc LIKE marc,
      gs_marm LIKE marm,
      gs_mlhd LIKE mlhd,
      gs_mlit LIKE mlit,
      gt_bdc TYPE TABLE OF bdcdata,
      gs_bdc TYPE bdcdata,
      leadc(6) TYPE c,
      leadc2(10) TYPE c,
       endc2 TYPE n,
      endc TYPE n,
      stprs TYPE netpr,
      gt_bdcmsg TYPE TABLE OF bdcmsgcoll,
      gs_bdcmsg TYPE bdcmsgcoll,
netpr TYPE string .
IF i_ekpo IS NOT INITIAL.

  SELECT SINGLE FROM mara INTO gs_mara WHERE matnr = i_ekpo-matnr.
  IF gs_mara-mtart EQ 'SM01' .
    IF  gs_mara-vpsta CS 'B' .
      IF gs_mara-vpsta CS  'E'.
        SELECT SINGLE FROM marc INTO gs_marc WHERE matnr = i_ekpo-matnr.
        IF gs_marc-beskz = 'F' OR gs_marc-beskz = 'X'.
          SELECT SINGLE FROM mbew INTO gs_mbew WHERE  matnr = i_ekpo-matnr.
          IF gs_mbew-stprs <= '0.01' AND gs_mbew-zkprs <= '0.01'.

*            SELECT SINGLE * FROM marm INTO gs_marm WHERE meinh = i_ekpo-bprme AND matnr = i_ekpo-matnr.
            stprs = i_ekpo-netpr / i_ekpo-peinh.
            stprs = i_ekpo-bpumn * stprs / i_ekpo-bpumz.
            netpr = stprs .
            gs_bdc-program = 'SAPRCKM_MR21' .
            gs_bdc-dynpro = '0201' .
            gs_bdc-dynbegin = 'X'.
            APPEND gs_bdc TO gt_bdc.
            CLEAR gs_bdc.

            gs_bdc-fnam = 'BDC_CURSOR'.
            gs_bdc-fval = 'MR21HEAD-BUDAT'.
            APPEND gs_bdc TO gt_bdc.
            CLEAR gs_bdc.

            gs_bdc-fnam = 'BDC_OKCODE'.
            gs_bdc-fval = '=ENTR'.
            APPEND gs_bdc TO gt_bdc.
            CLEAR gs_bdc.

            gs_bdc-fnam = 'MR21HEAD-BUDAT'.
            gs_bdc-fval = sy-datum.
            APPEND gs_bdc TO gt_bdc.
            CLEAR gs_bdc.

            gs_bdc-fnam = 'MR21HEAD-BUKRS'.
            gs_bdc-fval = '1000'.
            APPEND gs_bdc TO gt_bdc.
            CLEAR gs_bdc.

            gs_bdc-fnam = 'MR21HEAD-WERKS'.
            gs_bdc-fval = '1000'.
            APPEND gs_bdc TO gt_bdc.
            CLEAR gs_bdc.

            gs_bdc-fnam = 'MR21HEAD-SCREEN_VARIANT'.
            gs_bdc-fval = 'MR21_LAGERMATERIAL_0250'.
            APPEND gs_bdc TO gt_bdc.
            CLEAR gs_bdc.
*            2
            gs_bdc-program = 'SAPRCKM_MR21' .
            gs_bdc-dynpro = '0201' .
            gs_bdc-dynbegin = 'X'.
            APPEND gs_bdc TO gt_bdc.
            CLEAR gs_bdc.
            gs_bdc-fnam = 'BDC_OKCODE'.
            gs_bdc-fval = '=ENTR'.
            APPEND gs_bdc TO gt_bdc.
            CLEAR gs_bdc.
            gs_bdc-fnam = 'BDC_CURSOR'.
            gs_bdc-fval = 'CKI_MR21_0250-MATNR(01)'.
            APPEND gs_bdc TO gt_bdc.
            CLEAR gs_bdc.
            gs_bdc-fnam = 'MR21HEAD-SCREEN_VARIANT'.
            gs_bdc-fval = 'MR21_LAGERMATERIAL_BWKEY_0250'.
            APPEND gs_bdc TO gt_bdc.
            CLEAR gs_bdc.
            gs_bdc-fnam = 'CKI_MR21_0250-MATNR(01)'.
            gs_bdc-fval = i_ekpo-matnr.
            APPEND gs_bdc TO gt_bdc.
            CLEAR gs_bdc.
            gs_bdc-fnam = 'BDC_OKCODE'.
            gs_bdc-fval = '=ENTR'.
            APPEND gs_bdc TO gt_bdc.
            CLEAR gs_bdc.
            gs_bdc-fnam = 'BDC_CURSOR'.
            gs_bdc-fval = 'CKI_MR21_0250-NEWVALPR(01)'.
            APPEND gs_bdc TO gt_bdc.
            CLEAR gs_bdc.
            gs_bdc-fnam = 'MR21HEAD-SCREEN_VARIANT'.
            gs_bdc-fval = 'MR21_LAGERMATERIAL_BWKEY_0250'.
            APPEND gs_bdc TO gt_bdc.
            CLEAR gs_bdc.
            gs_bdc-fnam = 'CKI_MR21_0250-NEWVALPR(01)'.

            gs_bdc-fval = netpr.

            APPEND gs_bdc TO gt_bdc.
            CLEAR: gs_bdc,stprs,netpr.
            gs_bdc-fnam = 'BDC_OKCODE'.
            gs_bdc-fval = '=SAVE'.
            APPEND gs_bdc TO gt_bdc.
            CLEAR: gs_bdc.
            gs_bdc-fnam = 'BDC_CURSOR'.
            gs_bdc-fval = 'CKI_MR21_0250-NEWVALPR(01)'.
            APPEND gs_bdc TO gt_bdc.
            CLEAR: gs_bdc.
            gs_bdc-fnam = 'MR21HEAD-SCREEN_VARIANT'.
            gs_bdc-fval = 'MR21_LAGERMATERIAL_BWKEY_0250'.
            APPEND gs_bdc TO gt_bdc.
            CLEAR: gs_bdc.

            CALL TRANSACTION 'MR21' USING gt_bdc MODE 'N'  MESSAGES INTO gt_bdcmsg.
            READ TABLE gt_bdcmsg INTO gs_bdcmsg INDEX 1.
            IF gs_bdcmsg-msgtyp EQ 'S'.
*              gs_mara-mstae = ''.
*              UPDATE mara FROM gs_mara.
              SUBMIT zmmrpt038 WITH s_matnr = i_ekpo-matnr AND RETURN.
            ELSE.
              SHIFT i_ekpo-matnr LEFT DELETING LEADING '0'.
              CONCATENATE i_ekpo-matnr ' 价格估算失败,请将价格提供给财务,由财务估算标准价格然后解冻,此物料暂时不能转采购订单。' INTO netpr.
              MESSAGE netpr TYPE 'E'.
            ENDIF.
            CLEAR: gs_mara,gs_mbew,gs_marc,gs_marm,gs_bdcmsg,netpr,gs_bdcmsg,gt_bdcmsg.
          ENDIF.

        ELSE.
          MESSAGE '此物料不是外购件,怎么能下PO的?' TYPE 'E'.
        ENDIF.
      ELSE.
        MESSAGE '此物料已经下PO,竟然没有采购视图' TYPE 'E'.
      ENDIF.
    ELSE.
      MESSAGE '此物料已经下PO,竟然没有会计视图' TYPE 'E'.
    ENDIF.
  ENDIF.
ENDIF.

你可能感兴趣的:(MM采购订单的增强user-exit:MM06E005(示例程序是下PO做成本MR21))