Модуль GMD R12.GMD.A.6 (Разработка продукции УНП; Process Manufacturing Product Development)
Процедура для создания производственного задания (batch).
-------------------------------------------------------------------- -- Создание задания PROCEDURE xx_create_batch(p_org_id NUMBER, -- ID организации p_date DATE, -- Дата p_item INTEGER, -- продукт p_qnty NUMBER, -- количество p_new_batch_num IN OUT VARCHAR2, p_return_status IN OUT VARCHAR2, p_message_text IN OUT VARCHAR2) IS l_gme_batch_header gme_batch_header%ROWTYPE; l_gme_batch_header_out gme_batch_header%ROWTYPE; l_action_code VARCHAR2(50); l_use_workday_cal VARCHAR2(1) := 'T'; l_contiguity_override VARCHAR2(1) := 'T'; l_ignore_qty_cap VARCHAR2(1) := 'T'; l_msg_count NUMBER; l_message_list VARCHAR2(2000); l_return_status VARCHAR2(1); l_msg_data VARCHAR2(2000); l_msg_index NUMBER(5); l_date_chr VARCHAR2(11); l_date DATE; l_batch_size NUMBER; l_uom VARCHAR2(20); l_recipe_validity_rule_id NUMBER; l_exception_tbl gme_common_pvt.exceptions_tab; no_proc_finished EXCEPTION; BEGIN SAVEPOINT CREATE_BATCH_SP; p_return_status := 'S'; l_date_chr := to_char(p_date, 'dd.mm.yyyy'); -- gme_common_pvt.set_who; l_date := p_date; l_gme_batch_header.organization_id := p_org_id; l_gme_batch_header.batch_no := NULL; l_gme_batch_header.plan_start_date := to_date(l_date_chr || ' 00:00:00', 'dd.mm.yyyy hh24:mi:ss');--плановое начало l_gme_batch_header.plan_cmplt_date := to_date(l_date_chr || ' 23:59:00', 'dd.mm.yyyy hh24:mi:ss');--плановое завершение l_gme_batch_header.due_date := to_date(l_date_chr || ' 23:59:00', 'dd.mm.yyyy hh24:mi:ss');--нужное завершение l_gme_batch_header.batch_type := 0; --СПЗ l_action_code := 'PRODUCT'; l_batch_size := p_qnty; --ЕИ BEGIN SELECT v.PRIMARY_UOM_CODE INTO l_uom FROM mtl_system_items_vl v WHERE v.INVENTORY_ITEM_ID = p_item AND v.ORGANIZATION_ID = p_org_id; EXCEPTION WHEN OTHERS THEN l_uom := 'тм3'; END; --вычисляем правило применимости рецепта BEGIN SELECT grvr.recipe_validity_rule_id INTO l_recipe_validity_rule_id FROM gmd_recipes_b gr, fm_matl_dtl fmd, gmd_recipe_validity_rules grvr WHERE gr.formula_id = fmd.formula_id AND fmd.line_type = 1 AND fmd.inventory_item_id = p_item --item_id AND fmd.organization_id = p_org_id --org_id AND grvr.recipe_id = gr.recipe_id AND grvr.validity_rule_status = 700 AND gr.recipe_status = 700 AND (grvr.end_date IS NULL AND l_date >= grvr.start_date OR l_date BETWEEN grvr.start_date AND grvr.end_date); EXCEPTION WHEN TOO_MANY_ROWS THEN p_message_text := 'Существует более одного правила применимости для данного продукта'; RAISE no_proc_finished; WHEN NO_DATA_FOUND THEN p_message_text := 'Не найдено правило применимости для данного продукта'; RAISE no_proc_finished; WHEN OTHERS THEN p_message_text := 'Ошибка при определении правила применимости для данного продукта'; RAISE no_proc_finished; END; IF l_recipe_validity_rule_id IS NOT NULL THEN l_gme_batch_header.recipe_validity_rule_id := l_recipe_validity_rule_id; gme_api_main.create_batch( p_validation_level => 100, p_init_msg_list => 'T', x_message_count => l_msg_count, x_message_list => l_message_list, x_return_status => l_return_status, p_batch_header_rec => l_gme_batch_header, x_batch_header_rec => l_gme_batch_header_out, p_batch_size => l_batch_size, p_batch_size_uom => l_uom, p_creation_mode => l_action_code, p_recipe_id => NULL, p_recipe_no => NULL, p_recipe_version => NULL, p_product_no => NULL, p_product_id => NULL, p_ignore_qty_below_cap => l_ignore_qty_cap, p_use_workday_cal => l_use_workday_cal, p_contiguity_override => l_contiguity_override, p_use_least_cost_validity_rule => 'F', x_exception_material_tbl => l_exception_tbl); IF l_return_status = 'S' THEN p_new_batch_num := l_gme_batch_header_out.batch_no; ELSE gme_common_pvt.count_and_get(p_encoded => 'F', x_count => l_msg_index, x_data => l_msg_data); p_message_text := l_msg_data; RAISE no_proc_finished; END IF; ELSE p_message_text := 'Правило применимости для продукта не определено'; END IF; p_return_status := 'S'; -- EXCEPTION WHEN no_proc_finished THEN p_return_status := 'E'; ROLLBACK TO CREATE_BATCH_SP; WHEN OTHERS THEN p_message_text := 'Error: ' || substr(SQLERRM, 1, 200); p_return_status := 'E'; ROLLBACK TO CREATE_BATCH_SP; END XX_CREATE_BATCH;
Последние комментарии