BAPI_PRODORD_CREATE Create production order

Note

  1. This BAPI r3 does not, ecc has
  2. Comes with commit, the update module of update aufk in bapi will be triggered after execution
  3. Write to wbs report error 61 261, it is a bapi bug, there was a note1677892 in the early days, s4 still has bugs, please refer to lijun solution CO_KO1_CHECK_PROJN

**begin add by dlj 20190415 solves the inconsistency between bapi creation and front desk by clearing special inventory types

*wbs element is successfully created in the foreground, and an error is reported when BAPI is created

    DEFINE mc_range.

      &1-sign = &2.

      &1-option = &3.

      &1-low = &4.

      APPEND &1.

      CLEAR:&1.

    END-OF-DEFINITION.

 

    DATA:lt_tvarvc TYPE TABLE OF tvarvc,

         lr_typ    TYPE RANGE OF t003o-auart WITH HEADER LINE.

 

    SELECT * FROM tvarvc

      INTO TABLE lt_tvarvc

     WHERE name = 'ZPP_ORDER_TYPE_Q'.

 

    LOOP AT lt_tvarvc INTO DATA(ls_tvarvc).

      mc_range lr_typ ls_tvarvc-sign ls_tvarvc-opti ls_tvarvc-low.

    ENDLOOP.

 

    IF i_order_type IN lr_typ.

      CLEAR:e_sobkz.

    ENDIF.

*end add by dlj 20190415

 

DEMO

* BAPI

  data:

    ls_bapi_pp_order_create type bapi_pp_order_create,

    ls_return               type bapiret2,

    lv_order_number type bapi_order_key-order_number.

 

  loop at gt_alv where sel = 'X' and aufnr = ''.

    data (lv_tabix) = sy-tabix.

 

    clear:ls_return,lv_order_number,ls_bapi_pp_order_create.

    ls_bapi_pp_order_create-order_type = gt_alv-auart. "Order type

    ls_bapi_pp_order_create-material = gt_alv-matnr. "Order material number

* ls_bapi_pp_order_create-plant = gt_alv-werks. "Order Factory

    ls_bapi_pp_order_create-plant = '1021'. "Order factory

* ls_bapi_pp_order_create-planning_plant = gt_alv-werks. "Planning plant

    ls_bapi_pp_order_create-planning_plant = '1021'."Planning plant

    ls_bapi_pp_order_create-prod_version = gt_alv-verid. "Production version

    ls_bapi_pp_order_create-basic_start_date = gt_alv-mbdat. "Basic start date

    ls_bapi_pp_order_create-basic_end_date = gt_alv-mbdat. "Basic completion date

    ls_bapi_pp_order_create-quantity = gt_alv-psmng. "Order quantity

    ls_bapi_pp_order_create-quantity_uom = gt_alv-vrkme. "Unit

* ls_bapi_pp_order_create-sales_order = gt_alv-vbeln. "Sales order

* ls_bapi_pp_order_create-sales_order_item = gt_alv-posnr. "Sales order item

    ls_bapi_pp_order_create-storage_location = gt_alv-lgort_out. "Output storage location

    call function 'CONVERSION_EXIT_ABPSP_INPUT'

      exporting

        input     = gt_alv-posid

      importing

        output    = ls_bapi_pp_order_create-wbs_element

      exceptions

        not_found = 1.

* ls_bapi_pp_order_create-QUANTITY_UOM = gt_alv-MEINS. "Unit

* ls_bapi_pp_order_create-goods_recipient = gt_alv-wempf. "Recipient

*   ls_bapi_pp_order_create-GOODS_RECIPIENT = gt_alv-MEINS.

    ls_bapi_pp_order_create-order_type = gt_alv-auart.

 

    set update task local.

 

    call function 'BAPI_PRODORD_CREATE'

      exporting

        orderdata    = ls_bapi_pp_order_create

      importing

        return       = ls_return

        order_number = lv_order_number.

 

    if lv_order_number is not initial.

      gt_alv-rtype = 'S'.

      gt_alv-rtmsg ='Order created successfully'.

      gt_alv-aufnr = lv_order_number.

 

 

      call function 'BAPI_TRANSACTION_COMMIT'

        exporting

          wait = 'X'.

 

*Line body

      update aufk

      set zzvbeln = gt_alv-vbeln zzposnr = gt_alv-posnr zzline = gt_alv-xianb

      where aufnr = lv_order_number.

      commit work and wait.

 

*Modify consumption inventory location

      perform frm_pro_change using lv_order_number gt_alv-lgort_consu.

    else.

      call function 'BAPI_TRANSACTION_ROLLBACK'.

      gt_alv-rtype = 'E'.

      message id ls_return-id type ls_return-type number ls_return-number

        with ls_return-message_v1 ls_return-message_v2

             ls_return-message_v3 ls_return-message_v4

             into  gt_alv-rtmsg.

    endif.

 

    move-corresponding gt_alv to lt_zppd0011.

    lt_zppd0011-menge = gt_alv-menge + gt_alv-psmng. "The quantity of the order has been opened

    if lt_zppd0011-quantity = gt_alv-kwmeng_meins.

      lt_zppd0011-complete = 'X'.

    endif.

    lt_zppd0011-aenam = sy-uname.

    lt_zppd0011-aedat = sy-datum.

    lt_zppd0011-aezet = sy-uzeit.

    append lt_zppd0011.

    modify gt_alv index lv_tabix.

  endloop.

  if sy-subrc ne 0.

    message e001(00) with'Select at least one row of documents that were not created successfully'.

  endif.

 

Guess you like

Origin blog.csdn.net/cylcylcylcylwo/article/details/113929405