创建生产订单,创建订单长文本,订单下达
DATA:gs_bapi_pp_order_create TYPE bapi_pp_order_create. DATA:gt_bapi_order_key TYPE TABLE OF bapi_order_key, gs_bapi_order_key TYPE bapi_order_key, gt_order_return TYPE TABLE OF bapi_order_return WITH HEADER LINE. DATA:gs_return TYPE bapiret2, gt_return TYPE bssp_t_message, gw_return TYPE bssp_s_message, gv_order_number TYPE bapi_order_key-order_number. DATA:gt_tline TYPE TABLE OF tline, gw_tline TYPE tline. CLEAR:gt_return[],gs_return. DATA:gs_keko TYPE keko. DATA:gv_message TYPE string. DATA:lv_int TYPE i. DATA:g_fname TYPE thead-tdname. CLEAR:lv_int. LOOP AT gt_zstybcp INTO gw_zstybcp WHERE sel = 'X' AND aufnr = ''. lv_int = lv_int + 1. "add by ly 20151124 SELECT SINGLE * INTO CORRESPONDING FIELDS OF gs_keko FROM keko WHERE matnr = gw_zstybcp-matnr AND werks = gw_zstybcp-werks AND bwkey = gw_zstybcp-werks AND kadat LE sy-datum AND bidat GE sy-datum AND freig = 'X'. IF sy-subrc <> 0. gv_message = gv_message && ' ' && gw_zstybcp-matnr. * MESSAGE '物料' && gw_zstybcp-matnr && '请先下达标准成本估算!' TYPE 'S' DISPLAY LIKE 'E'. EXIT. ENDIF. "add by ly 20151124 ENDLOOP. "仅限选择一行,且选择行中的办成品油已生成生产订单,直接调用T-code 到修改界面 IF gv_message IS INITIAL. ELSE. MESSAGE '物料' && gv_message && '未下达标准成本估算!' TYPE 'S' DISPLAY LIKE 'E'. EXIT. ENDIF. IF lv_int <> 0. ELSE. MESSAGE '请选择调油半成品生产订单为空的行项目!' TYPE 'S' DISPLAY LIKE 'E'. EXIT. ENDIF. * PERFORM PRM_DATA_CHECK. LOOP AT gt_zstybcp INTO gw_zstybcp WHERE sel = 'X' AND aufnr = ''."ADD BY 20150716 LY FOR 批量创建 CLEAR:gs_return,gw_return,gt_order_return[],gt_bapi_order_key[],gs_bapi_order_key. gs_bapi_pp_order_create-material = gw_zstybcp-matnr."订单物料号 gs_bapi_pp_order_create-plant = gw_zstybcp-werks."订单工厂 gs_bapi_pp_order_create-planning_plant = gw_zstybcp-werks."计划工厂 gs_bapi_pp_order_create-basic_start_date = gw_zstybcp-gstrp."基础开始日期 gs_bapi_pp_order_create-basic_end_date = gw_zstybcp-gstrp."基准解释日期 gs_bapi_pp_order_create-quantity = gw_zstybcp-bdmng."订单数量 CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT' "单位 EXPORTING input = gw_zstybcp-meins * LANGUAGE = SY-LANGU IMPORTING output = gs_bapi_pp_order_create-quantity_uom EXCEPTIONS unit_not_found = 1 OTHERS = 2. IF sy-subrc <> 0. ENDIF. * GS_BAPI_PP_ORDER_CREATE-QUANTITY_UOM = GW_ZSTYBCP-MEINS."单位 gs_bapi_pp_order_create-goods_recipient = gw_zstybcp-wempf."收货方 * GS_BAPI_PP_ORDER_CREATE-GOODS_RECIPIENT = GW_ZSTYBCP-MEINS. gs_bapi_pp_order_create-order_type = 'DL02'. "调用订单创建函数创建调油半成品生产订单 CALL FUNCTION 'BAPI_PRODORD_CREATE' EXPORTING orderdata = gs_bapi_pp_order_create IMPORTING return = gs_return order_number = gv_order_number. IF gs_return-type IS NOT INITIAL."消息填表 gw_return-msgid = gs_return-id. gw_return-msgty = gs_return-type. gw_return-msgno = gs_return-number. gw_return-msgv1 = gs_return-message_v1. gw_return-msgv2 = gs_return-message_v2. gw_return-msgv3 = gs_return-message_v3. gw_return-msgv4 = gs_return-message_v4. APPEND gw_return TO gt_return. ENDIF. * APPEND GS_RETURN TO GT_RETURN."消息填表 IF gs_return-type = 'E' OR gs_return = 'A'. * CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. gw_zstybcp-icon = '@OA@'. gw_zstybcp-message = gs_return-message. ELSE. * CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' * EXPORTING * wait = 'X'. gw_zstybcp-icon = '@08@'. gw_zstybcp-message = '成功创建调油半成品生产订单'. gw_zstybcp-aufnr = gv_order_number. gw_zstybcp-psmng = gw_zstybcp-bdmng. gw_zstybcp-amein = gw_zstybcp-meins. CONCATENATE sy-mandt gv_order_number INTO g_fname. gw_tline-tdformat = 1. gw_tline-tdline = gw_zstybcp-ztiay. APPEND gw_tline TO gt_tline. CALL FUNCTION 'CREATE_TEXT' EXPORTING fid = 'KOPF' flanguage = sy-langu fname = g_fname fobject = 'AUFK' TABLES flines = gt_tline EXCEPTIONS no_init = 1 no_save = 2 OTHERS = 3. IF sy-subrc <> 0. ENDIF. IF sy-subrc = 0. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ENDIF. WAIT UP TO 1 SECONDS. UPDATE aufk SET ltext = '1' WHERE aufnr = gv_order_number. COMMIT WORK. gs_bapi_order_key-order_number = gv_order_number. APPEND gs_bapi_order_key TO gt_bapi_order_key. "ADD BY LY 20150610订单下达 CALL FUNCTION 'BAPI_PRODORD_RELEASE' * EXPORTING * RELEASE_CONTROL = '1' * WORK_PROCESS_GROUP = 'COWORK_BAPI' * WORK_PROCESS_MAX = 99 * IMPORTING * RETURN = TABLES orders = gt_bapi_order_key detail_return = gt_order_return. READ TABLE gt_order_return WITH KEY type = 'E'. IF sy-subrc <> 0. * CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' * EXPORTING * wait = 'X'. ELSE. * CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. CONCATENATE '订单' gv_order_number '下达失败,请手动下达!' INTO gw_return-msgv1. MESSAGE gw_return-msgv1 TYPE 'S' DISPLAY LIKE 'E'. ENDIF. ENDIF. MODIFY gt_zstybcp FROM gw_zstybcp. ENDLOOP. * IF GT_RETURN[] IS NOT INITIAL."消息显示 * CALL FUNCTION 'BSSP2_MESSAGE_POPUP' * EXPORTING * IT_MESSAGE = GT_RETURN * IF_SAVE_NECESSARY = ''. * ENDIF.
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/18708.html