27 мая 2019

Подтверждение производственного заказа (BAPI BAPI_PRODORDCONF_CREATE_HDR)

Пример использования BAPI BAPI_PRODORDCONF_CREATE_HDR.


  DATA:
    lv_aufnr TYPE aufk-aufnr,
    lv_quan TYPE bapi_pp_hdrlevel-yield,
    ls_aufk TYPE aufk,
    ls_afko TYPE afko,
    lt_afpo TYPE TABLE OF afpo,
    lt_resb TYPE TABLE OF resb,
    lv_index TYPE i,
    ls_return TYPE bapiret1,
    lt_athdrlevels TYPE TABLE OF bapi_pp_hdrlevel,
    lt_goodsmovements TYPE TABLE OF bapi2017_gm_item_create,
    lt_link_conf TYPE TABLE OF bapi_link_conf_goodsmov,
    lt_detail_return TYPE TABLE OF bapi_coru_return.

  FIELD-SYMBOLS:
    <lfs_afpo> LIKE LINE OF lt_afpo,
    <lfs_resb> LIKE LINE OF lt_resb,
    <lfs_athdrlevels> LIKE LINE OF lt_athdrlevels,
    <lfs_goodsmovements> LIKE LINE OF lt_goodsmovements,
    <lfs_link_conf> LIKE LINE OF lt_link_conf,
    <lfs_detail_return> LIKE LINE OF lt_detail_return.

  lv_aufnr = ''. " Номер заказа
  lv_quan = 10. " Кол-во

  " Данные заказа

  SELECT SINGLE *
    FROM aufk
    INTO CORRESPONDING FIELDS OF ls_aufk
    WHERE aufnr EQ lv_aufnr.

  IF sy-subrc NE 0.
    EXIT.
  ENDIF.

  SELECT SINGLE *
    FROM afko
    INTO CORRESPONDING FIELDS OF ls_afko
    WHERE aufnr EQ lv_aufnr.

  IF sy-subrc NE 0.
    EXIT.
  ENDIF.

  SELECT *
    FROM afpo
    INTO CORRESPONDING FIELDS OF TABLE lt_afpo
    WHERE aufnr EQ lv_aufnr
      AND xloek EQ space.

  IF sy-subrc NE 0.
    EXIT.
  ENDIF.

  SELECT *
    FROM resb
    INTO CORRESPONDING FIELDS OF TABLE lt_resb
    WHERE aufnr EQ lv_aufnr
      AND xloek EQ space.

  IF sy-subrc NE 0.
    EXIT.
  ENDIF.

  READ TABLE lt_afpo ASSIGNING <lfs_afpo> INDEX 1.
  CHECK sy-subrc EQ 0.
  
  INSERT INITIAL LINE INTO TABLE lt_athdrlevels ASSIGNING <lfs_athdrlevels>.
  <lfs_athdrlevels>-orderid = lv_aufnr.
  <lfs_athdrlevels>-fin_conf = ''.
  <lfs_athdrlevels>-clear_res = 'X'.
  <lfs_athdrlevels>-postg_date = sy-datum.
  <lfs_athdrlevels>-conf_quan_unit = <lfs_afpo>-amein. " ЕИ
  <lfs_athdrlevels>-yield = lv_quan.

  " Если нужно явно указать поступление ГП и списание компонентов
  
  " Поступление ГП

  INSERT INITIAL LINE INTO TABLE lt_goodsmovements ASSIGNING <lfs_goodsmovements>.
  <lfs_goodsmovements>-material = <lfs_afpo>-matnr.
  <lfs_goodsmovements>-plant = ls_aufk-werks.
  <lfs_goodsmovements>-stge_loc = <lfs_afpo>-lgort.
  <lfs_goodsmovements>-batch = ''.
  <lfs_goodsmovements>-move_type = '131'.
  <lfs_goodsmovements>-entry_qnt = lv_quan.
  <lfs_goodsmovements>-entry_uom = <lfs_afpo>-amein.
  <lfs_goodsmovements>-no_more_gr = ''.
  <lfs_goodsmovements>-orderid = lv_aufnr.
  <lfs_goodsmovements>-order_itno = <lfs_afpo>-posnr.
  <lfs_goodsmovements>-mvt_ind = 'F'.
  <lfs_goodsmovements>-ref_doc_it = '0001'.

  ADD 1 TO lv_index.
  INSERT INITIAL LINE INTO TABLE lt_link_conf ASSIGNING <lfs_link_conf>.
  <lfs_link_conf>-index_confirm = 1.
  <lfs_link_conf>-index_goodsmov = lv_index.

  " Списание компонентов

  LOOP AT lt_resb ASSIGNING <lfs_resb>
    WHERE bdmng GT 0.
    INSERT INITIAL LINE INTO TABLE lt_goodsmovements ASSIGNING <lfs_goodsmovements>.
    <lfs_goodsmovements>-material = <lfs_resb>-matnr.
    <lfs_goodsmovements>-plant = <lfs_resb>-werks.
    <lfs_goodsmovements>-stge_loc = <lfs_resb>-lgort.
    <lfs_goodsmovements>-batch = ''.
    <lfs_goodsmovements>-move_type = '261'.
    <lfs_goodsmovements>-entry_qnt = lv_quan * <lfs_resb>-bdmng / <lfs_afpo>-psmng.
    <lfs_goodsmovements>-entry_uom = <lfs_resb>-meins.
    <lfs_goodsmovements>-orderid = lv_aufnr.
    <lfs_goodsmovements>-reserv_no = <lfs_resb>-rsnum.
    <lfs_goodsmovements>-res_item = <lfs_resb>-rspos.
    <lfs_goodsmovements>-withdrawn = 'X'.
    <lfs_goodsmovements>-ref_doc_it = '0001'.

    ADD 1 TO lv_index.
    INSERT INITIAL LINE INTO TABLE lt_link_conf ASSIGNING <lfs_link_conf>.
    <lfs_link_conf>-index_confirm = 1.
    <lfs_link_conf>-index_goodsmov = lv_index.
  ENDLOOP.
  
  CALL FUNCTION 'BAPI_PRODORDCONF_CREATE_HDR'
    EXPORTING
      post_wrong_entries    = '2'
*     testrun               =
    IMPORTING
      return                = ls_return
    TABLES
      athdrlevels           = lt_athdrlevels
      goodsmovements        = lt_goodsmovements
      link_conf_goodsmov    = lt_link_conf
      detail_return         = lt_detail_return
*     characteristics_batch =
*     link_gm_char_batch    =
    .

Комментариев нет:

Отправить комментарий