BAPI_PRODORD_CREATE_FROM_REF Create production order with reference

  1. Reference creation can modify the order type
  2. Comes with commit, no need to commit, if there is any uncommitted before the call, commit first
  3. If an error (forward push plan) is reported, then return to the previous screen and dump
  4. WBS elements on the "Assignment" tab will not be copied
  5. Suggest direct BDC

 

 

DEMO

loop at gt_alv2 where aufnr_new is initial.

 

*Refer to creating a new ticket

* BAPI

    data ls_refcopy      type bapi_order_copy.

    data lv_order_number type bapi_order_copy-order_number.

    data lv_order_type   type bapi_order_copy-order_type.

    data ls_return       type bapiret2.

 

    clear:ls_refcopy,lv_order_type,ls_return.

    ls_refcopy-reference_order = gt_alv2-aufnr.

    ls_refcopy-basic_end_date = gt_alv2-gltrp_new.

 

    set update task local.

    call function 'BAPI_PRODORD_CREATE_FROM_REF'

      exporting

        refcopy = ls_refcopy

      importing

        order_number = lv_order_number

        order_type   = lv_order_type

        return       = ls_return.

 

    if lv_order_number is not initial.

      perform frm_lock using lv_order_number.

      gt_alv2-rtype = 'S'.

      gt_alv2-rtmsg ='The order was created successfully;'.

      gt_alv2-aufnr_new = lv_order_number.

 

      call function 'BAPI_TRANSACTION_COMMIT'

        exporting

          wait = 'X'.

 

*Modify the number of work orders

      perform frm_pro_quantity_change using lv_order_number gt_alv2-gamng_new changing gt_alv2-rtype gt_alv2-rtmsg.

    else.

      call function 'BAPI_TRANSACTION_ROLLBACK'.

      gt_alv2-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_alv2-rtmsg.

    endif.

    modify gt_alv2.

  endloop.

 

*Modify the original work order quantity

  read table gt_alv2 into data(ls_alv2) with key rtype = 'E'.

  if sy-subrc ne 0.

    read table gt_alv2 into ls_alv2 index 1.

    if ls_alv2-gamng_new = 0. "Tap to delete the logo

      perform frm_pro_del using ls_alv2-aufnr changing ls_alv2-rtype ls_alv2-rtmsg.

    else. "Modify the quantity

      perform frm_pro_quantity_change using ls_alv2-aufnr ls_alv2-gamng_new changing ls_alv2-rtype ls_alv2-rtmsg.

    endif.

    modify gt_alv2 from ls_alv2 index 1 transporting rtype rtmsg.

  endif.

 

form frm_lock  using uv_key .

 

  data mode_aufk type enqmode.

  data mandt     type aufk-mandt.

  data aufnr     type aufk-aufnr.

 

  aufnr = uv_key.

 

  call function 'ENQUEUE_ESORDER'

    exporting

      mode_aufk = 'E'

      mandt = sew-mandt

      aufnr = aufnr

      x_aufnr = ''

      _scope         = '1'

      _wait          = ' '

      _collect       = ' '

    exceptions

      foreign_lock   = 1

      system_failure = 2.

  if sy-subrc ne 0.

* cv_rtype = 'E'.

    message id sy-msgid

      type sy-msgty

      number sy-msgno

      with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4

*       into cv_rtmsg

       .

    return.

  endif.

endform.

 

Guess you like

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