二维码

[BAPI] CO01创建生产订单BAPI_PRODORD_CREATE并下达BAPI_PRODORD_RELEASE

Twilight发表于 2018-05-04 15:54Twilight 最后回复于 2018-05-04 15:54 [复制链接] 8765 0

生产部门反应创建工单非常慢,是因为SAP创建生产订单时会检查物料,会花费大量时间,其次创建生产订单一次只能根据销售订单一个行项目创建,所以完成一个销售订单的排产就需要更长的时间。

优化建议:
1、OPJK - 关闭物料检查
ATP检查.jpg
2、OPKP - 生产订单创建并下达,一步执行
生产订单下达.jpg

程序代码:
  1. FUNCTION zppfm007.
  2. *"----------------------------------------------------------------------
  3. *"*"本地接口
  4. *"  IMPORTING
  5. *"     VALUE(I_HEADER) TYPE  ZPPS001 OPTIONAL
  6. *"  EXPORTING
  7. *"     VALUE(E_MESSAGE) TYPE  ZOTS001
  8. *"     VALUE(E_AUFNR) TYPE  AUFNR
  9. *"  TABLES
  10. *"      T_ITEM STRUCTURE  ZPPS003
  11. *"----------------------------------------------------------------------
  12.   DATA:ls_afpo TYPE afpo.
  13.   DATA:ls_message TYPE zots001.
  14.   DATA:ls_return TYPE bapiret2.
  15.   DATA:ls_orderdata TYPE bapi_pp_order_create.
  16.   DATA:lv_objnr TYPE jsto-objnr.
  17.   DATA:lv_bsark_e  TYPE vbkd-bsark_e.
  18.   DATA:lv_order_number TYPE aufnr.
  19.   DATA:lt_status TYPE TABLE OF jstat WITH HEADER LINE,
  20.        lt_orders  TYPE TABLE OF bapi_order_key WITH HEADER LINE,
  21.        lt_detail_return        TYPE TABLE OF        bapi_order_return WITH HEADER LINE.

  22.   FIELD-SYMBOLS:<fs_item> TYPE zpps003.

  23.   PERFORM frm_inputsap_matnr CHANGING i_header-matnr.
  24.   PERFORM frm_inputsap_vbeln CHANGING i_header-sales_order.

  25.   SELECT SINGLE bsark_e INTO lv_bsark_e FROM vbkd WHERE vbeln = i_header-sales_order.
  26.   CASE lv_bsark_e.
  27.     WHEN 'A001'.
  28.       i_header-order_type = 'SG01'.
  29.     WHEN 'A005'.
  30.       i_header-order_type = 'SG03'.
  31.     WHEN 'A002'.
  32.       i_header-order_type = 'SG05'.
  33.     WHEN 'A007'.
  34.       i_header-order_type = 'SG07'.
  35.     WHEN 'A006'.
  36.       i_header-order_type = 'SG09'.
  37.     WHEN 'A012'.
  38.       i_header-order_type = 'SG11'.
  39.     WHEN 'A009'.
  40.       i_header-order_type = 'SG13'.
  41.     WHEN 'A011'.
  42.       i_header-order_type = 'SG15'.
  43.     WHEN 'A010'.
  44.       i_header-order_type = 'SG17'.
  45.     WHEN 'A013'.
  46.       i_header-order_type = 'SG19'.
  47.     WHEN 'A003'.
  48.       i_header-order_type = 'SG21'.
  49.     WHEN 'A004'.
  50.       i_header-order_type = 'SG23'.
  51.   ENDCASE.

  52.   ls_orderdata-material       = i_header-matnr.
  53.   ls_orderdata-order_type     = i_header-order_type.
  54.   ls_orderdata-plant          = i_header-plant.
  55.   ls_orderdata-planning_plant = i_header-plant.
  56.   IF i_header-basic_start_date IS NOT INITIAL .
  57.     CONCATENATE i_header-basic_start_date+0(4) i_header-basic_start_date+5(2) i_header-basic_start_date+8(2) INTO ls_orderdata-basic_start_date.
  58.   ELSE .
  59.     ls_orderdata-basic_start_date = sy-datum.
  60.   ENDIF.
  61.   IF i_header-basic_end_date IS NOT INITIAL .
  62.     CONCATENATE i_header-basic_end_date+0(4) i_header-basic_end_date+5(2) i_header-basic_end_date+8(2) INTO ls_orderdata-basic_end_date.
  63.   ELSE .
  64.     ls_orderdata-basic_end_date = sy-datum .
  65.   ENDIF .
  66.   ls_orderdata-quantity         = i_header-quantity.
  67.   ls_orderdata-sales_order      = i_header-sales_order.
  68.   ls_orderdata-sales_order_item = i_header-sales_order_item.
  69.   ls_orderdata-storage_location = i_header-storage_location.
  70.   ls_orderdata-unloading_point  = i_header-unloading_point.

  71. *-->生产订单创建
  72.   CALL FUNCTION 'BAPI_PRODORD_CREATE'
  73.     EXPORTING
  74.       orderdata    = ls_orderdata
  75.     IMPORTING
  76.       return       = ls_return
  77.       order_number = lv_order_number.

  78.   IF lv_order_number IS INITIAL.
  79.     CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .

  80.     e_message-type = 'E'.
  81.     e_message-message = ls_return-message.
  82.   ELSE.
  83.     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  84.       EXPORTING
  85.         wait = 'X'.

  86. *-->修改生产订单组建
  87.     IF t_item[] IS NOT INITIAL.
  88.       LOOP AT t_item ASSIGNING <fs_item>.
  89.         PERFORM frm_inputsap_matnr CHANGING <fs_item>-matnr.
  90.       ENDLOOP.

  91.       WAIT UP TO 1 SECONDS.
  92.       CALL FUNCTION 'ZPPFM010'
  93.         EXPORTING
  94.           i_aufnr   = lv_order_number
  95.         IMPORTING
  96.           e_message = ls_message
  97.         TABLES
  98.           t_item    = t_item[].
  99.       IF e_message-type = 'E'.
  100.         MOVE-CORRESPONDING ls_message TO e_message.
  101.         e_aufnr = lv_order_number.
  102.         EXIT.
  103.       ENDIF.
  104.     ENDIF.

  105. *-->生产订单下达
  106.     WAIT UP TO 1 SECONDS.
  107.     CLEAR:lt_orders.
  108.     lt_orders-order_number = lv_order_number.
  109.     APPEND lt_orders .

  110.     CALL FUNCTION 'BAPI_PRODORD_RELEASE'
  111. *        IMPORTING
  112. *          return        = return
  113.       TABLES
  114.         detail_return = lt_detail_return
  115.         orders        = lt_orders[].
  116.     LOOP AT lt_detail_return WHERE type CA 'AEX'.
  117.       IF e_message-message IS INITIAL.
  118.         e_message-message = lt_detail_return-message.
  119.       ELSE.
  120.         e_message-message = e_message-message && '/' && lt_detail_return-message.
  121.       ENDIF.
  122.     ENDLOOP.
  123.     IF sy-subrc = 0.
  124.       CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .

  125.       e_message-type = 'E'.
  126.     ELSE.
  127.       CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  128.         EXPORTING
  129.           wait = 'X'.

  130.       e_message-type = 'S'.
  131.       e_message-message = '生产订单创建并下达成功'.
  132.       e_aufnr = lv_order_number.
  133.     ENDIF.
  134.   ENDIF.

  135. ENDFUNCTION.

  136. FORM frm_inputsap_matnr CHANGING pc_matnr TYPE char18.
  137.   CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
  138.     EXPORTING
  139.       input        = pc_matnr
  140.     IMPORTING
  141.       output       = pc_matnr
  142.     EXCEPTIONS
  143.       length_error = 1
  144.       OTHERS       = 2.
  145. ENDFORM.

  146. FORM frm_inputsap_vbeln CHANGING pc_vbeln TYPE char10.
  147.   CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  148.     EXPORTING
  149.       input  = pc_vbeln
  150.     IMPORTING
  151.       output = pc_vbeln.
  152. ENDFORM.
复制代码

最好使用STATUS_CHECK来判断生产订单的状态,更方便,更直接。
回复

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表