Create OPM Batch – New Materials Operations-Activities-Routings-Resources-Transactions on OPM

This post I will show a API to create Operations, Activities, Generic Resources and Routings on OPM.

Create OPM Batch

DECLARE
    l_api_version                NUMBER := 2.0;
    l_validation_level           NUMBER DEFAULT GME_COMMON_PVT.G_MAX_ERRORS;
    p_init_msg_list              BOOLEAN DEFAULT FALSE;
    P_batch_type                 NUMBER := 0;
    p_batch_qty                  NUMBER := 5;
    l_batch_header               gme_batch_header%ROWTYPE;
    x_batch_header               gme_batch_header%ROWTYPE;
    l_message_count              NUMBER;
    l_message_list               VARCHAR2 (500);
    l_return_status              VARCHAR2 (1);
    l_msg_index_out              NUMBER;
    lo_exception_material_tbl    GME_COMMON_PVT.EXCEPTIONS_TAB;
    v_organizacao                VARCHAR2(500);
    v_unidade_medida             VARCHAR2(500);
    v_receita                    VARCHAR2(500);
    v_versao_receita             NUMBER;
    v_produto                    VARCHAR2(500);
   
BEGIN

    l_batch_header.batch_no                  := NULL;
    l_batch_header.plan_start_date           := TO_DATE ('15-MAR-2019 12:00:00', 'DD-MON-YYYY HH24:MI:SS');
    l_batch_header.plan_cmplt_date           := TO_DATE ('30-MAR-2019 12:00:00', 'DD-MON-YYYY HH24:MI:SS');
    l_batch_header.due_date                  := TO_DATE ('30-MAR-2019 12:00:00', 'DD-MON-YYYY HH24:MI:SS');
    l_batch_header.update_inventory_ind      := 'Y';
    l_batch_header.recipe_validity_rule_id   := 131; -- da regra de validade ( produção, planejamento )
    l_batch_header.batch_type                := 0;
    v_organizacao                            := '013';
    v_unidade_medida                         := 'UN';
    v_receita                                := '999997';
    v_versao_receita                         := 1;
    v_produto                                := '999998';
   
    fnd_global.apps_initialize (user_id        => 1154,
                                resp_id        => 23326,
                                resp_appl_id   => 553);
   --------------------------------------------
    gme_api_pub.create_batch ( p_api_version                    => l_api_version,
                               p_validation_level               => l_validation_level,
                               p_init_msg_list                  => FND_API.G_TRUE,
                               p_commit                         => FND_API.G_TRUE,
                               x_message_count                  => l_message_count,
                               x_message_list                   => l_message_list,
                               x_return_status                  => l_return_status,
                               p_org_code                       => v_organizacao,
                               p_batch_header_rec               => l_batch_header,
                               x_batch_header_rec               => x_batch_header,
                               p_batch_size                     => p_batch_qty,
                               p_batch_size_uom                 => v_unidade_medida,
                               p_creation_mode                  => 'RECIPE',
                               p_recipe_id                      => NULL,
                               p_recipe_no                      => v_receita,
                               p_recipe_version                 => v_versao_receita,
                               p_product_no                     => v_produto,
                               p_item_revision                  => NULL,
                               p_product_id                     => NULL,
                               p_ignore_qty_below_cap           => FND_API.G_TRUE,
                               p_use_workday_cal                => FND_API.G_FALSE,
                               p_contiguity_override            => FND_API.G_TRUE,
                               p_use_least_cost_validity_rule   => FND_API.G_FALSE,
                               x_exception_material_tbl         => lo_exception_material_tbl);
                               
    ------------------------------------------
    gme_debug.display_messages (l_message_count);
    DBMS_OUTPUT.put_line ('x_message_count =' || TO_CHAR (l_message_count));
    DBMS_OUTPUT.put_line ( 'x_message_list ='|| LENGTH (l_message_list)|| SUBSTR (l_message_list, LENGTH (l_message_list) - 20, 20));
    DBMS_OUTPUT.put_line ('x_message_list =' || l_message_list);
    DBMS_OUTPUT.put_line ('x_return_status =' || l_return_status);
    DBMS_OUTPUT.put_line ('x_batch_header.batch_id= ' || TO_CHAR (x_batch_header.batch_id));
    DBMS_OUTPUT.put_line (SUBSTR ('x_batch_header.plant_code =' || x_batch_header.plant_code,1,255));
    DBMS_OUTPUT.put_line (SUBSTR ('x_batch_header.batch_no =' || x_batch_header.batch_no, 1, 255));
   
END;

OPM Batch created.

Sem título

Create Formule

DECLARE
mjil_fml_tabtype apps.gmd_formula_pub.formula_insert_hdr_tbl_type;
cnt NUMBER := 1;
l_return_status VARCHAR2 (1);
l_msg_count NUMBER;
l_msg_data VARCHAR2 (1000);
l_out_index NUMBER := 0;
BEGIN

fnd_global.apps_initialize (user_id => 1154,
resp_id => 23326,
resp_appl_id => 553);

mjil_fml_tabtype(cnt).formula_no := 'TESTE_API3';
mjil_fml_tabtype(cnt).formula_vers := 1; -- i.formula_vers;
mjil_fml_tabtype(cnt).formula_type := 0; --i.formula_type;
mjil_fml_tabtype(cnt).formula_desc1 := 'Teste Importação Formula'; --j.FORMULA_DESC1;
mjil_fml_tabtype(cnt).inactive_ind := 0; -- i.inactive_ind;
mjil_fml_tabtype(cnt).owner_organization_id := 83;
mjil_fml_tabtype(cnt).formula_status := 100; -- 'Approved for General Use';
mjil_fml_tabtype(cnt).line_no := 1; -- i.line_no;
mjil_fml_tabtype(cnt).line_type := -1; -- i.line_type;
mjil_fml_tabtype(cnt).item_no := '999997'; --i.item_no;
mjil_fml_tabtype(cnt).qty := 10; --i.qty;
mjil_fml_tabtype(cnt).detail_uom := 'UN'; -- i.detail_uom;
mjil_fml_tabtype(cnt).release_type := 1; --i.release_type;
mjil_fml_tabtype(cnt).scrap_factor := 0; -- i.scrap_factor;
mjil_fml_tabtype(cnt).scale_type_hdr := 1; -- i.scale_type_hdr;
mjil_fml_tabtype(cnt).scale_type_dtl := 1; -- i.scale_type_dtl;
mjil_fml_tabtype(cnt).cost_alloc := 1; -- i.cost_alloc;
mjil_fml_tabtype(cnt).phantom_type := 0; --i.phantom_type;
mjil_fml_tabtype(cnt).rework_type := 0; -- i.rework_type;
mjil_fml_tabtype(cnt).contribute_yield_ind := 'Y';
mjil_fml_tabtype(cnt).contribute_step_qty_ind := 'Y';
mjil_fml_tabtype(cnt).delete_mark := 0;

cnt := cnt + 1;

mjil_fml_tabtype(cnt).formula_no := 'TESTE_API3';
mjil_fml_tabtype(cnt).formula_vers := 1; -- i.formula_vers;
mjil_fml_tabtype(cnt).formula_type := 0; --i.formula_type;
mjil_fml_tabtype(cnt).formula_desc1 := 'Teste Importação Formula'; --j.FORMULA_DESC1;
mjil_fml_tabtype(cnt).inactive_ind := 0; -- i.inactive_ind;
mjil_fml_tabtype(cnt).owner_organization_id := 83;
mjil_fml_tabtype(cnt).formula_status := 100; -- 'Approved for General Use';
mjil_fml_tabtype(cnt).line_no := 2; -- i.line_no;
mjil_fml_tabtype(cnt).line_type := 1; -- i.line_type;
mjil_fml_tabtype(cnt).item_no := '999998'; --i.item_no;
mjil_fml_tabtype(cnt).qty := 10; --i.qty;
mjil_fml_tabtype(cnt).detail_uom := 'UN'; -- i.detail_uom;
mjil_fml_tabtype(cnt).release_type := 1; --i.release_type;
mjil_fml_tabtype(cnt).scrap_factor := 0; -- i.scrap_factor;
mjil_fml_tabtype(cnt).scale_type_hdr := 1; -- i.scale_type_hdr;
mjil_fml_tabtype(cnt).scale_type_dtl := 1; -- i.scale_type_dtl;
mjil_fml_tabtype(cnt).cost_alloc := 1; -- i.cost_alloc;
mjil_fml_tabtype(cnt).phantom_type := 0; --i.phantom_type;
mjil_fml_tabtype(cnt).rework_type := 0; -- i.rework_type;
mjil_fml_tabtype(cnt).contribute_yield_ind := 'Y';
mjil_fml_tabtype(cnt).contribute_step_qty_ind := 'Y';
mjil_fml_tabtype(cnt).delete_mark := 0;

gmd_formula_pub.insert_formula (p_api_version => 1,
p_init_msg_list => fnd_api.g_true,
p_commit => fnd_api.g_true,
p_called_from_forms => 'NO',
x_return_status => l_return_status,
x_msg_count => l_msg_count,
x_msg_data => l_msg_data,
p_formula_header_tbl => mjil_fml_tabtype);

COMMIT;


DBMS_OUTPUT.put_line ('Return status - ' || l_return_status);
DBMS_OUTPUT.put_line ('Message count - ' || l_msg_count);

FOR i IN 1 .. l_msg_count
LOOP
fnd_msg_pub.get (p_msg_index => i,
p_encoded => 'F',
p_data => l_msg_data,
p_msg_index_out => l_out_index);
DBMS_OUTPUT.put_line ('Message Text-* ' || l_msg_data);
END LOOP;
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.put_line ('Return status 1 - ' || SQLERRM);
DBMS_OUTPUT.put_line ('Message count 1 - ' || l_msg_count);

FOR i IN 1 .. l_msg_count
LOOP
fnd_msg_pub.get (p_msg_index => i,
p_encoded => 'F',
p_data => l_msg_data,
p_msg_index_out => l_out_index);
DBMS_OUTPUT.put_line ('Message Text ' || l_msg_data);
END LOOP;
END;

Formule Created

Sem título

Create Recipe / Validate Rule / Plant-Laboratory

DECLARE
l_recipe_tbl GMD_RECIPE_HEADER.recipe_tbl;
l_recipe_flex GMD_RECIPE_HEADER.recipe_flex;
l_recipe_vr_tbl GMD_RECIPE_DETAIL.recipe_vr_tbl;
l_recipe_flex_tbl GMD_RECIPE_DETAIL.recipe_flex;
l_recipe_mtl_tbl GMD_RECIPE_DETAIL.recipe_mtl_tbl;
l_recipe_dtl_tbl GMD_RECIPE_DETAIL.recipe_detail_tbl;
l_return_status VARCHAR2(10);
l_msg_ind VARCHAR2(240);
l_msg_data VARCHAR2(2000);
l_msg_count NUMBER; 
l_count NUMBER;
v_recipe_id NUMBER;

BEGIN 
FND_GLOBAL.apps_initialize (user_id => 1154,
resp_id => 22883,
resp_appl_id => 552); 

--------------- CABEÇALHO DA RECEITA --------------------
BEGIN 
l_recipe_tbl(1).recipe_no := 'TESTE_14';
l_recipe_tbl(1).recipe_version := 1;
l_recipe_tbl(1).recipe_description := 'Receita Criada por API';
l_recipe_tbl(1).creation_organization_id := 83;
l_recipe_tbl(1).owner_organization_id := 83;
l_recipe_tbl(1).formula_id := 1;
l_recipe_tbl(1).recipe_type := 1;
l_recipe_tbl(1).owner_id := 1154;
l_recipe_tbl(1).routing_id := 1;

BEGIN
GMD_RECIPE_HEADER.create_recipe_header (p_api_version => 1.0,
p_init_msg_list => 'T',
p_commit => 'F',
p_called_from_forms => 'NO',
x_return_status => l_return_status,
x_msg_count => l_msg_count,
x_msg_data => l_msg_data,
p_recipe_header_tbl => l_recipe_tbl,
p_recipe_header_flex => l_recipe_flex ); 

dbms_output.put_line ('Criação Cabeçalho Receita: ' || l_return_status || ' : ' || l_msg_data);
EXCEPTION WHEN OTHERS THEN
dbms_output.put_line ('Erro na Criação Cabeçalho Receita: '|| SQLCODE|| '-'|| SQLERRM);
END;

IF l_return_status <> 'S' THEN

FOR i IN 1 .. l_msg_count
LOOP
FND_MSG_PUB.get (p_msg_index => i,
p_encoded => 'F',
p_data => l_msg_data,
p_msg_index_out => l_msg_ind );
dbms_output.put_line ('Mensagem: ' || l_msg_data);
END LOOP;
ELSE
COMMIT;
END IF;
END;
------------------------------------------------ 
----------- REGRA DE VALIDADE ------------------
BEGIN

SELECT recipe_id
INTO v_recipe_id
FROM gmd_recipes_b
WHERE recipe_no = l_recipe_tbl(1).recipe_no
AND recipe_version = l_recipe_tbl(1).recipe_version;

l_count := 1;

l_recipe_vr_tbl (l_count).recipe_validity_rule_id := NULL;
l_recipe_vr_tbl (l_count).recipe_id := v_recipe_id;
l_recipe_vr_tbl (l_count).recipe_no := l_recipe_tbl(1).recipe_no;
l_recipe_vr_tbl (l_count).recipe_version := l_recipe_tbl(1).recipe_version;
l_recipe_vr_tbl (l_count).user_id := 1154;
l_recipe_vr_tbl (l_count).user_name := 'ALEX.PAGLIARINI';
l_recipe_vr_tbl (l_count).orgn_code := '013';
l_recipe_vr_tbl (l_count).inventory_item_id := 1002;
l_recipe_vr_tbl (l_count).revision := NULL;
l_recipe_vr_tbl (l_count).item_no := '999998';
l_recipe_vr_tbl (l_count).recipe_use := 0;
l_recipe_vr_tbl (l_count).preference := 1;
l_recipe_vr_tbl (l_count).start_date := SYSDATE;
l_recipe_vr_tbl (l_count).end_date := NULL;
l_recipe_vr_tbl (l_count).min_qty := 0;
l_recipe_vr_tbl (l_count).max_qty := 999999999;
l_recipe_vr_tbl (l_count).std_qty := 12000;
l_recipe_vr_tbl (l_count).detail_uom := 'KG';
l_recipe_vr_tbl (l_count).inv_min_qty := NULL;
l_recipe_vr_tbl (l_count).inv_max_qty := NULL;
l_recipe_vr_tbl (l_count).text_code := NULL;
l_recipe_vr_tbl (l_count).created_by := 1154;
l_recipe_vr_tbl (l_count).delete_mark := 0;
l_recipe_vr_tbl (l_count).planned_process_loss := NULL;
l_recipe_vr_tbl (l_count).validity_rule_status := 100;
l_recipe_vr_tbl (l_count).organization_id := 83;
l_recipe_vr_tbl (l_count).fixed_process_loss := NULL;
l_recipe_vr_tbl (l_count).fixed_process_loss_uom := NULL;

BEGIN
GMD_RECIPE_DETAIL.create_recipe_vr ( p_api_version => 1.0,
p_init_msg_list => 'F',
p_commit => 'F',
p_called_from_forms => 'NO',
x_return_status => l_return_status,
x_msg_count => l_msg_count,
x_msg_data => l_msg_data,
p_recipe_vr_tbl => l_recipe_vr_tbl,
p_recipe_vr_flex => l_recipe_flex_tbl);
dbms_output.put_line ('Criação Regra de Validade: '|| l_return_status);
EXCEPTION WHEN OTHERS THEN
dbms_output.put_line ('Erro na Criação Regra de Validade: '|| SQLCODE|| '-'|| SQLERRM);
END;

IF l_return_status <> 'S' THEN

FOR i IN 1 .. l_msg_count
LOOP
fnd_msg_pub.get ( p_msg_index => i,
p_encoded => 'F',
p_data => l_msg_data,
p_msg_index_out => l_msg_ind );
dbms_output.put_line ('Mensagem: ' || l_msg_data);
END LOOP;
ELSE
COMMIT;
END IF;

END;
--------------------------------------------------
----------- Planta / Laboratório ------------------
BEGIN 
l_recipe_dtl_tbl(1).recipe_no := l_recipe_tbl(1).recipe_no;
l_recipe_dtl_tbl(1).recipe_version := l_recipe_tbl(1).recipe_version;
l_recipe_dtl_tbl(1).user_name := 'ALEX.PAGLIARINI'; 
l_recipe_dtl_tbl(1).orgn_code := '013';
l_recipe_dtl_tbl(1).organization_id := 83;
l_recipe_dtl_tbl(1).process_loss := 0;
l_recipe_dtl_tbl(1).step_qty := 1; 

BEGIN 
GMD_RECIPE_DETAIL.create_recipe_process_loss ( p_api_version => 1.0,
p_init_msg_list => 'T',
p_commit => 'F',
p_called_from_forms => 'NO',
x_return_status => l_return_status,
x_msg_count => l_msg_count,
x_msg_data => l_msg_data,
p_recipe_detail_tbl => l_recipe_dtl_tbl); 

dbms_output.put_line ('Criação Planta Laboratorio: '|| l_return_status);
EXCEPTION WHEN OTHERS THEN
dbms_output.put_line ('Erro na Criação Planta Laboratorio: '|| SQLCODE|| '-'|| SQLERRM);
END;

IF l_return_status <> 'S' THEN

FOR i IN 1 .. l_msg_count
LOOP
fnd_msg_pub.get ( p_msg_index => i,
p_encoded => 'F',
p_data => l_msg_data,
p_msg_index_out => l_msg_ind );
dbms_output.put_line ('Mensagem: ' || l_msg_data);
END LOOP;
ELSE
COMMIT;
END IF;
EXCEPTION WHEN OTHERS THEN
dbms_output.put_line ('Error: '|| SQLCODE|| SQLERRM);
END;
--------------------------------------------------------------
l_recipe_tbl.DELETE;
l_recipe_vr_tbl.DELETE;
l_recipe_dtl_tbl.DELETE;

EXCEPTION WHEN OTHERS THEN
dbms_output.put_line ('Erro: ' || SQLERRM || ', ' || SQLCODE); 
END;

Recipe / Validate Rule / Plant-Laboratory created.

Sem título

Release Batch

DECLARE
l_batch_header gme_batch_header%ROWTYPE;
x_batch_header gme_batch_header%ROWTYPE;
p_batch_header gme_batch_header%ROWTYPE;
x_message_count NUMBER;
x_message_list VARCHAR2(2000);
x_return_status VARCHAR2(1);
l_material_detail gme_material_details%ROWTYPE;
x_material_detail gme_material_details%ROWTYPE;
lt_exception_material_tbl GME_COMMON_PVT.exceptions_tab; 
l_msg_index_out NUMBER;

BEGIN

l_batch_header.batch_type := 0;
l_batch_header.batch_id := 2004;
l_batch_header.plan_start_date := SYSDATE;
l_batch_header.plan_cmplt_date := SYSDATE;
l_batch_header.due_date := SYSDATE;
l_batch_header.update_inventory_ind := 'Y';
l_batch_header.actual_start_date := SYSDATE;

gme_api_pub.release_batch (p_api_version => 2.0,
p_validation_level => 100,
p_init_msg_list => fnd_api.g_false,
p_commit => fnd_api.g_false,
x_message_count => x_message_count,
x_message_list => x_message_list,
x_return_status => x_return_status,
p_batch_header_rec => l_batch_header,
p_org_code => '013',
p_ignore_exception => 'T',
p_validate_flexfields => fnd_api.g_false,
x_batch_header_rec => x_batch_header,
x_exception_material_tbl => lt_exception_material_tbl );

IF x_return_status = FND_API.g_ret_sts_success THEN
dbms_output.put_line('Batch Released');

GME_API_PUB.save_batch (p_header_id => NULL
,p_table => NULL
,p_commit => FND_API.g_false
,x_return_status => x_return_status);

IF x_return_status = fnd_api.g_ret_sts_success THEN
COMMIT; 
ELSE
RAISE fnd_api.g_exc_error;
END IF;

ELSE
dbms_output.put_line('Batch Release failed');

IF X_message_count = 1 THEN
DBMS_OUTPUT.PUT_LINE('Error:'||X_message_list);
ELSE
FOR i IN 1..x_message_count
LOOP
FND_MSG_PUB.get (p_msg_index => i,
p_data => X_message_list,
p_msg_index_out => l_msg_index_out);
DBMS_OUTPUT.PUT_LINE('Error: '||X_message_list);
END LOOP; 
END IF;

END IF;

EXCEPTION WHEN OTHERS THEN
dbms_output.put_line('Error '||TO_CHAR(SQLCODE)||': '||SQLERRM);
RAISE;
END;

Released batch

Sem título

Add Ingredient / Product / By Product

DECLARE
v_batchstep_no NUMBER;
v_message_count NUMBER;
v_message_list VARCHAR2(1000);
v_return_status VARCHAR2(1000);
v_gme_master gme_batch_header%ROWTYPE;
v_gme_detail gme_material_details%ROWTYPE;
v_material_detail_rec gme_material_details%ROWTYPE;
l_user_id NUMBER;
l_resp_id NUMBER;
l_resp_appl_id NUMBER;
v_material_cnt NUMBER;
v_organizacao VARCHAR2(400);

BEGIN

FND_GLOBAL.apps_initialize (user_id => 1154,
resp_id => 23326,
resp_appl_id => 553);
SELECT *
INTO v_gme_master
FROM gme_batch_header
WHERE batch_id = 5002; 

v_batchstep_no := 10;
v_organizacao := '013';
v_material_detail_rec.inventory_item_id := 2001;
v_material_detail_rec.line_no := 2;
v_material_detail_rec.line_type := -1; -- -1 adiciona como ingrediente, 1 adiciona como produto, 2 adiciona como residuo
v_material_detail_rec.plan_qty := 100;
v_material_detail_rec.actual_qty := 0;
v_material_detail_rec.release_type := 1;
v_material_detail_rec.scrap_factor := 0;
v_material_detail_rec.scale_type := 1;
v_material_detail_rec.phantom_type := 0;
v_material_detail_rec.contribute_yield_ind := 'Y';
v_material_detail_rec.contribute_step_qty_ind := 'Y';
v_material_detail_rec.wip_plan_qty := 100;
v_material_detail_rec.original_qty := 100;
v_material_detail_rec.dispense_ind := 'N';
v_material_detail_rec.dtl_um := 'UN';
v_material_detail_rec.material_requirement_date := SYSDATE;

GME_API_PUB.insert_material_line(p_api_version => 2.0,
p_validation_level => GME_COMMON_PVT.g_max_errors,
p_init_msg_list => FND_API.g_false,
p_commit => FND_API.g_false,
p_batch_header_rec => v_gme_master,
p_material_detail_rec => v_material_detail_rec,
p_locator_code => NULL,
p_org_code => v_organizacao,
p_batchstep_no => v_batchstep_no,
p_validate_flexfields => FND_API.g_false,
x_material_detail_rec => v_gme_detail,
x_message_count => v_message_count,
x_message_list => v_message_list,
x_return_status => v_return_status);

IF v_return_status = FND_API.g_ret_sts_success THEN

dbms_output.put_line('Material line inserted for item id '||v_material_detail_rec.item_id);

GME_API_PUB.save_batch (p_header_id => NULL
,p_table => NULL
,p_commit => FND_API.g_false
,x_return_status => v_return_status);

IF v_return_status = fnd_api.g_ret_sts_success THEN 
COMMIT;
ELSE
RAISE fnd_api.g_exc_error;
END IF;

ELSE
dbms_output.put_line('Material line insertion failed');
DBMS_OUTPUT.PUT_LINE('Error:'||v_message_list);
END IF;

EXCEPTION WHEN OTHERS THEN
dbms_output.put_line('Error '||TO_CHAR(SQLCODE)||': '||SQLERRM);
RAISE;

END;

Create Transactions

DECLARE
p_api_version NUMBER DEFAULT 2.0;
p_validation_level NUMBER DEFAULT GME_COMMON_PVT.G_MAX_ERRORS;
p_init_msg_list BOOLEAN DEFAULT FALSE;
P_batch_type NUMBER DEFAULT 0;
p_orgn_code VARCHAR2(4) ;
lx_message_count varchar2(1000);
lx_message_list varchar2(10000);
lx_return_status varchar2(1000);
l_mmti_rec mtl_transactions_interface%ROWTYPE;
l_mmli_tbl gme_common_pvt.mtl_trans_lots_inter_tbl;
lx_mmt_rec mtl_material_transactions%ROWTYPE;
lx_mmln_tbl gme_common_pvt.mtl_trans_lots_num_tbl;
g_debug_point VARCHAR2 (100);
g_debug VARCHAR2 (5) := fnd_profile.VALUE ('AFLOG_LEVEL');
l_transaction_interface_id NUMBER := NULL;
l_user_id NUMBER:= 1110;
x_return_status VARCHAR2 (2000);
vBatchId NUMBER;
vTransactionTypeId NUMBER;
vStatus VARCHAR2(2000);
vItemCode VARCHAR2(30);
vLinesProcessed NUMBER := 0;

BEGIN

fnd_profile.initialize (1154);
fnd_global.apps_initialize(user_id => 1154,
resp_id => 23326,
resp_appl_id => 553 );
x_return_status := fnd_api.g_ret_sts_success;
fnd_msg_pub.initialize;
gme_common_pvt.g_error_count := 0;
gme_common_pvt.set_timestamp;
gme_common_pvt.g_move_to_temp := fnd_api.g_false;


SELECT mtl_material_transactions_s.NEXTVAL
INTO l_transaction_interface_id
FROM DUAL;

vLinesProcessed := vLinesProcessed + 1;

SELECT h.batch_id,
material_detail_id,
a.inventory_item_id,
a.organization_id
INTO vbatchid, 
l_mmti_rec.trx_source_line_id,
l_mmti_rec.inventory_item_id,
l_mmti_rec.organization_id
FROM gme_batch_header h,
gme_material_details a
WHERE h.batch_id = a.batch_id
AND batch_no = 14 -- numero da OP
AND line_type IN (1)
AND inventory_item_id = 1002;

l_mmti_rec.transaction_header_id := l_transaction_interface_id;
l_mmti_rec.transaction_source_id := l_transaction_interface_id;
l_mmti_rec.subinventory_code := 'PAE';
--l_mmti_rec.locator_id := i.locator_id;
l_mmti_rec.inventory_item_id := l_mmti_rec.inventory_item_id;
p_orgn_code := '013';
l_mmti_rec.source_header_id := vbatchid;
l_mmti_rec.transaction_source_id := vbatchid; -- Batch_id
l_mmti_rec.transaction_quantity := 1;
l_mmti_rec.transaction_uom := 'UN';
l_mmti_rec.primary_quantity := 1;
l_mmti_rec.source_code := 'OPM';
l_mmti_rec.attribute1 := 'Teste por API'; -- tentamos usar o transaction reference porém não popula o campo
l_mmti_rec.transaction_source_type_id := 5; -- Job or Schedule
l_mmti_rec.wip_entity_type := 9;
l_mmti_rec.transaction_action_id := 31;-- WIP ISSUE 1 ------- WIP COMPLETION 31
l_mmti_rec.transaction_type_id := 44;-- WIP ISSUE 35 ---- WIP COMPLETION 44
l_mmti_rec.transaction_date := SYSDATE;

---------------------------------------Lot Details
-- l_mmli_tbl(1).last_update_date := gme_common_pvt.g_timestamp ;
-- l_mmli_tbl(1).last_updated_by := gme_common_pvt.g_user_ident ;
-- l_mmli_tbl(1).creation_date := gme_common_pvt.g_timestamp ;
-- l_mmli_tbl(1).created_by := gme_common_pvt.g_user_ident ;
-- l_mmli_tbl(1).lot_number := i.lot_number;
-- l_mmli_tbl(1).transaction_quantity := i.primary_quantity;
---------------------------------------------------

gme_api_pub.create_material_txn ( p_api_version => 2.0,
p_validation_level => gme_common_pvt.g_max_errors,
p_init_msg_list => fnd_api.g_false,
p_commit => fnd_api.g_false,
x_message_count => lx_message_count,
x_message_list => lx_message_list,
x_return_status => lx_return_status,
p_org_code => p_orgn_code,
p_mmti_rec => l_mmti_rec,
p_mmli_tbl => l_mmli_tbl,
p_batch_no => NULL,
p_line_no => NULL,
p_line_type => NULL,
p_create_lot => fnd_api.g_true,
p_generate_lot => NULL,
p_generate_parent_lot => NULL,
x_mmt_rec => lx_mmt_rec,
x_mmln_tbl => lx_mmln_tbl );

COMMIT;

gme_debug.display_messages(lx_message_count);

dbms_output.put_line('x_return_status ='||lx_return_status);

IF lx_message_count >=1 THEN
FOR I IN 1..lx_message_count
LOOP
dbms_output.put_line(I||'. '||SUBSTR(FND_MSG_PUB.Get(p_encoded => FND_API.G_FALSE ),1, 255));
END LOOP;
END IF;

END;

Deixe uma resposta

Powered by WordPress.com. Tema: Baskerville 2 por Anders Noren

Acima ↑

%d blogueiros gostam disto: