r12 item conversion

22
create table xxaa_items_conv_stg ( status_stg varchar2(7) ,transaction_id_stg number ,ls_item_number varchar2(40) ,ls_description varchar2(240) ,ls_organization_code varchar2(3) ,ls_template_name varchar2(40) ,ls_pr_unit_of_measure varchar2(25) ,ls_item_type varchar2(30) ,ls_cos_account varchar2(160) ,ls_expense_account varchar2(240) ,ls_sales_account varchar2(160) ,organization_id number ,template_id number ,inventory_item_id number , pr_uom_code varchar2(30) ,cos_account_id number , expense_account_id number , sales_account_id number ,created_by number ,creation_date date ,error_code varchar2(200) ); create sequence xxaa_item_conv_s start with 1 increment by 1; create or replace trigger xxaa_items_conv_trg before insert on item_con_stg for each row begin if :new.transaction_id_stg is null then select xxaa_item_conv_s.nextval, 'N' into :new.transaction_id_stg, :new.status_stg from dual; end if; end; / /**************************************************************** description : conversion error table *****************************************************************/ create unique index xxaa_items_conv_cu01 on xxaa_items_conv_stg(transaction _id_s tg); create index xxaa_items_conv_cn01 on xxaa_items_conv_stg(status_stg); create index xxaa_items_conv_cn02 on xxaa_items_conv_stg(ls_item_number);

Upload: shameemfics

Post on 04-Jun-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 1/22

create table xxaa_items_conv_stg(status_stg varchar2(7),transaction_id_stg number,ls_item_number varchar2(40),ls_description varchar2(240),ls_organization_code varchar2(3),ls_template_name varchar2(40),ls_pr_unit_of_measure varchar2(25),ls_item_type varchar2(30),ls_cos_account varchar2(160),ls_expense_account varchar2(240),ls_sales_account varchar2(160),organization_id number,template_id number,inventory_item_id number, pr_uom_code varchar2(30),cos_account_id number, expense_account_id number, sales_account_id number,created_by number,creation_date date,error_code varchar2(200));

create sequence xxaa_item_conv_sstart with 1increment by 1;

create or replace trigger xxaa_items_conv_trgbefore inserton item_con_stgfor each rowbeginif :new.transaction_id_stg is null

thenselect xxaa_item_conv_s.nextval, 'N'into :new.transaction_id_stg, :new.status_stgfrom dual;end if;end;/

/****************************************************************description : conversion error table*****************************************************************/

create unique index xxaa_items_conv_cu01 on xxaa_items_conv_stg(transaction_id_stg);

create index xxaa_items_conv_cn01 on xxaa_items_conv_stg(status_stg);

create index xxaa_items_conv_cn02 on xxaa_items_conv_stg(ls_item_number);

Page 2: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 2/22

create index xxaa_items_conv_cn03 on xxaa_items_conv_stg(ls_item_number,ls_organization_code);

create sequence xxaa_items_conv_sstart with 1increment by 1;

desc xxaa_items_conv_stg

create or replace trigger xxaa_items_conv_trgbefore inserton xxaa_items_conv_stgfor each rowbeginif :new.transaction_id_stg is nullthenselect xxaa_items_conv_s.nextval,'N',sysdateinto :new.transaction_id_stg, :new.status_stg,:new.creation_date

from dual;end if;end;

create table xxaa_items_err_log(application varchar (80),file_name varchar (80),object_name varchar (80),package_name varchar (50),procedure_name varchar (50),table_name varchar (50),column_name varchar (50),

column_value varchar (2000),error_date date,error_message varchar (2000),transaction_id_stg number);

drop synonym xxaa_items_err_log;

create synonym xxaa_items_err_logs for xxaa_items_err_log;

commit ;

staging table data for item conversion

item number,description,organization code,primary uom,template name,cos account,expense account,sales account

Page 3: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 3/22

apps_item_1,apps_item_test1,v1,each,finished good,01-120-mad3-mad3-000,01-120-mad2-mad2-000,01-600-5110-0000-000apps_item_2,apps_item_test2,v1,each,finished good,01-510-4110-0000-000,01-540-7530-0000-000,01-510-5110-0000-000apps_item_3,apps_item_test3,v1,each,finished good,01-530-4110-0000-000,01-540-7530-0000-000,01-520-5110-0000-000apps_item_4,apps_item_test4,v1,each,finished good,01-600-4110-0000-000,01-510-7620-0000-000,01-600-5110-0000-000apps_item_5,apps_item_test5,v1,each,finished good,01-120-mad3-mad3-000,01-000-1570-0000-000,01-600-5110-0000-000apps_item_6,apps_item_test6,v1,each,finished good,01-530-4110-0000-000,01-120-mad2-mad2-000,01-510-5110-0000-000apps_item_7,apps_item_test7,v1,kgs,finished good,01-120-mad3-mad3-000,01-510-7620-0000-000,01-600-5110-0000-000apps_item_8,,v1,each,finished good,01-530-4110-0000-001,01-540-7530-0000-000,01-510-5110-0000-000apps_item_9,apps_item_test9,v1,each,finished good,01-120-mad3-mad3-000,01-120-12d2-mad3-000,01-600-5110-0000-000apps_item_10,apps_item_test10,v1,each,finished good,01-530-4110-0000-000,01-120-12i2-0000-000,01-522-5110-0000-000

creation of error tables data

/****************************************************************file_name : xxaa_err_codes_script.sqldescription : error codes script fileobject names : items,qoh,boms ,customers,open ar,orders, service contracts,install base,service request  ,knowledge base,projects.*****************************************************************/

insert into xxaa_error_codesvalues ('CUS100', 'Customer Number Is Null.');

insert into xxaa_error_codesvalues ('CUS101', 'Customer Name Is Null.');

insert into xxaa_error_codesvalues ('CUS102', 'Party Type Does Not Exist in Oracle.');

insert into xxaa_error_codesvalues ('CUS103', 'Profile Class Code Does Not Exist In Oracle.');

insert into xxaa_error_codesvalues ('CUS104', 'Primary Salesrep Does Not Exist In Oracle.');

insert into xxaa_error_codesvalues ('CUS105', 'Freight Terms Code Does Not Exist In Oracle.');

insert into xxaa_error_codesvalues ('CUS106', 'Order Type Does Not Exist in Oracle.');

Page 4: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 4/22

insert into xxaa_error_codesvalues ('CUS107', 'Ship Method Code Does Not Exist In Oracle.');

insert into xxaa_error_codesvalues ('CUS108', 'Customer Site Cannot Be Without Customer Header.');

insert into xxaa_error_codesvalues ('CUS109', 'Customer Address Line 1 Cannot be Null.');

insert into xxaa_error_codesvalues ('CUS110', 'Customer Address City Cannot be Null.');

insert into xxaa_error_codesvalues ('CUS111', 'Customer Address State Cannot be Null.');

insert into xxaa_error_codesvalues ('CUS112', 'Customer Address County Cannot be Null.');

insert into xxaa_error_codesvalues ('CUS113', 'Customer Address Postal Code Cannot be Null.');

insert into xxaa_error_codesvalues ('CUS114', 'Customer Address Bill To Flag Cannot be Null.');

insert into xxaa_error_codesvalues ('CUS115', 'Customer Address Ship To Flag Cannot be Null.');

insert into xxaa_error_codesvalues ('CUS116', 'Customer Address Primary Flag Cannot be Null.');

insert into xxaa_error_codesvalues ('CUS117', 'Customer Name Does not exist in Oracle.');

insert into xxaa_error_codesvalues ('CUS118', 'Customer Number Does not exist in Oracle.');

insert into xxaa_error_codesvalues ('CUS119', 'Customer Number Does not exist in Sites Legacy file.');

insert into xxaa_error_codesvalues ('CUS120', 'Customer Class Does Not Exist in Oracle.');

insert into xxaa_error_codesvalues ('CUS121', 'FOB Does Not Exist in Oracle.');

Page 5: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 5/22

insert into xxaa_error_codesvalues ('CUS122', 'Customer Address Country cannot be Null.');

insert into xxaa_error_codesvalues ('CUS123', 'Customer Type Does not Exists in Oracle.');

insert into xxaa_error_codesvalues ('CUS124', 'Party Xref Id Cannot Be Null');

insert into xxaa_error_codesvalues ('CUS125', 'Site Xref Id Cannot Be Null.');

insert into xxaa_error_codesvalues ('CUS126', 'Customer Already Exists In Oracle');

insert into xxaa_error_codesvalues ('CUS127', 'Secondary Party Xref Id Cannot be Null');

insert into xxaa_error_codesvalues ('CUS128', 'Relationship Type Doesnot Exists in Oracle.');

insert into xxaa_error_codesvalues ('CUS129', 'Party Xref Id Does Not Exist in Oracle.');

insert into xxaa_error_codesvalues ('CUS130', 'Secondary Party Xref Id Does Not Exist in Oracle.');

insert into xxaa_error_codesvalues ('CUS131', 'Duplicate Party Xref Id Present in Data File.');

insert into xxaa_error_codesvalues ('CUS132', 'Duplicate Site Xref Id Present in Data File.');

insert into xxaa_error_codesvalues ('CUS134', 'Contact Points Without Contact Record.');

insert into xxaa_error_codesvalues ('CUS135','Duplicate Combination of Party Site Xref Id and Contact Id .');

insert into xxaa_error_codesvalues ('CUS136','Duplicate Combination of Contact Id and Contact Detail Id.');

Page 6: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 6/22

insert into xxaa_error_codesvalues ('CUS137', 'Contact Id Cannot Be Null.');

insert into xxaa_error_codesvalues ('CUS138','Both Contact First Name and Contact Last Name Cannot Be Null.');

insert into xxaa_error_codesvalues ('CUS141', 'Contact Detail Id Cannot Be Null.');

insert into xxaa_error_codesvalues ('CUS142', 'Phone Number Cannot Be Null.');

insert into xxaa_error_codesvalues ('CUS143', 'Phone Line Type Cannot Be Null.');

insert into xxaa_error_codesvalues ('CUS146', 'Phone Line Type Does Not Exist in Oracle.');

insert into xxaa_error_codesvalues ('CUS148','No Party Site Id Exists in Oracle with Given Party Site Xref Id.');

insert into xxaa_error_codesvalues ('CUS149','No Cust Acct Site Id and Cust Account Id Exists with the Party Site Id.');

insert into xxaa_error_codesvalues ('CUS150',

'Revenue Code Combination Segments Deos Not Exist in Oracle.');

insert into xxaa_error_codesvalues ('CUS151', 'Email Address Cannot Be Null.');

insert into xxaa_error_codesvalues ('CUS152', 'Party Header Without Party Site Record.');

insert into xxaa_error_codesvalues ('CUS153', 'Party Site Without Party Header Record.');

insert into xxaa_error_codesvalues ('CUS154', 'Corresponding Party Site Record Failed Validation.');

insert into xxaa_error_codesvalues ('CUS155', 'Corresponding Party Record Failed Validation.');

Page 7: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 7/22

insert into xxaa_error_codesvalues ('CUS156','Duplicate Combination of Party Xref Id and Secondaty Party Xref Id.');

insert into xxaa_error_codesvalues ('CUS157', 'Party Site Xref Id Does Not Exist in Oracle.');

insert into xxaa_error_codesvalues ('CUS158','Corresponding Contact Point Record Failed Validation.');

insert into xxaa_error_codesvalues ('CUS159', 'Corresponding Contact Record Failed Validation.');

--commit ;

insert into xxaa_error_codesvalues ('ITM102', 'Primary Unit Of Measure Code Cannot Be Null.');

insert into xxaa_error_codesvalues ('ITM103', 'Primary Unit of Measure does not exist in Oracle.');

insert into xxaa_error_codesvalues ('ITM105','Weight unit of Measure code does not exist in Oracle.');

insert into xxaa_error_codesvalues ('ITM106',

'Volumne unit of Measure code does not exist in Oracle.');

insert into xxaa_error_codesvalues ('ITM109', 'Cost Of Sales Account Segments Cannot Be Null.');

insert into xxaa_error_codesvalues ('ITM110','Combination of Cost Sales Account Segments is Invalid.');

insert into xxaa_error_codes

values ('ITM111', 'Sales Account Segments Cannot Be Null.');

insert into xxaa_error_codesvalues ('ITM112', 'Combination of Sales Account Segments is Invalid.');

insert into xxaa_error_codesvalues ('ITM113', 'Expense Account Segments Cannot Be Null.');

Page 8: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 8/22

insert into xxaa_error_codesvalues ('ITM114', 'Combination of Expense Account Segments is Invalid.');

insert into xxaa_error_codesvalues ('ITM115', 'Item Catalog Group does not exist in Oracle.');

insert into xxaa_error_codesvalues ('ITM116', 'Item Number does not exist in the Org.');

insert into xxaa_error_codesvalues ('ITM117', 'Item Description Cannot Be Null.');

insert into xxaa_error_codesvalues ('ITM121', 'Duplicate Combination of Item and Organization');

insert into xxaa_error_codesvalues ('ITM122', 'Cost Type Cannot Be Null');

insert into xxaa_error_codesvalues ('ITM123', 'Cost Type Does not Exists in Oracle');

insert into xxaa_error_codesvalues ('ITM100', 'Item Number Cannot Be NULL.');

insert into xxaa_error_codesvalues ('ITM101', 'Item Number Does Not Exists In Master Org.');

insert into xxaa_error_codesvalues ('ITM104','Subinventory code is either NULL OR Invalid for the given organization.');

insert into xxaa_error_codesvalues ('ITM107', 'Template cannot be NULL.');

insert into xxaa_error_codesvalues ('ITM108', 'Template does not exist in Oracle.');

insert into xxaa_error_codesvalues ('ITM118', 'Planner Code Does not exist in Oracle.');

insert into xxaa_error_codesvalues ('ITM119', 'Buyer Id Does not exist in Oracle.');

insert into xxaa_error_codesvalues ('ITM120', 'Transaction UOM Does not Exist in Oracle.');

Page 9: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 9/22

insert into xxaa_error_codesvalues ('ITM124', 'Item Category Cannot Be Null');

insert into xxaa_error_codesvalues ('ITM125', 'Item Category Does not Exists in Oracle');

insert into xxaa_error_codesvalues ('ITM126','Combination of Locator Segments Does Not Exists In Oracle');

insert into xxaa_error_codesvalues ('ITM127', 'Transaction Quantity Cannot be Zero or Negetive');

insert into xxaa_error_codesvalues ('ITM128','Serial Number is not required as the Item is not under Serial Control');

insert into xxaa_error_codesvalues ('ITM129','Serial Number is required as the Item is under Serial Control');

insert into xxaa_error_codesvalues ('ITM131', 'COS Account Does not Exists In Oracle');

insert into xxaa_error_codesvalues ('ITM132', 'Sales Account Does not Exists In Oracle');

commit ;

insert into xxaa_error_codesvalues ('ORG100', 'Organization Code Cannot Be NULL.');

insert into xxaa_error_codesvalues ('ORG101', 'Organization Code does not exist in Oracle.');

insert into xxaa_error_codesvalues ('OPU100', 'Operating Unit cannot be NULL.');

insert into xxaa_error_codesvalues ('OPU101', 'Operating Unit is invalid.');

commit ;

commit ;

Page 10: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 10/22

creation of package specification.

create or replace package xxaa_item_con_pkgas/******************************************************************************business objects :items**file name :xxaa_items_conv_pkg.pks**file type :package specification**version :1**purpose :convert legacy items data into oracle*****************************************************************************/procedure map(p_transaction_id_from number,p_transaction_id_to number);

procedure validate(p_transaction_id_from number,p_transaction_id_to number);

procedure load(p_transaction_id_from number,p_transaction_id_to number);

procedure error_log_write;

end xxaa_items_conv_pkg;

implementation of pacakge body.

create or replace package body xxaa_items_conv_pkg

as/**************************************************************************** business object: oracle items for conversion** file name: xxaa_items_conv_pkg.pkb** file type: package body** version: 1** purpose: to convert the items data into oracle**************************************************************************/g_application_name varchar2 (80);g_file_name varchar2 (80);g_object_name varchar2 (80);

g_package_name varchar2 (80);g_procedure_name varchar2 (80);g_table_name varchar2 (80);g_column_name varchar2 (80);g_column_value varchar2 (1000);g_error_date date default sysdate;g_error_message varchar2 (1000);g_sql_code varchar2 (100);g_sql_message varchar2 (2000);g_global_print_mode number;

Page 11: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 11/22

g_transaction_id number;

/***------------------------------------------------------------------------** procedure name: map** purpose :procedure to map the staging table fields.**------------------------------------------------------------------------*/procedure map (p_transaction_id_from number, p_transaction_id_to number)isbegin/*===================================================  default organization code to v1====================================================*/update xxaa_items_conv_stgset ls_organization_code = 'V1';

commit;

/*================================================================update status of the duplicate records (records given in data file and already p

resent in oracle)================================================================*/update xxaa_items_conv_stg aset status_stg = 'ME',error_code = error_code || 'ITM121;;'where ls_item_number in (select segment1from mtl_system_items_b mwhere m.segment1 = a.ls_item_numberand m.organization_id in (select organization_idfrom mtl_parameters pwhere p.organization_code in

('V1')))and transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;

commit;

/*===============================================  default cost of sales account================================================*/update xxaa_items_conv_stgset ls_cos_account = '01-600-5110-0000-000';

commit;

/*===============================================  default expense account==============================================*/update xxaa_items_conv_stgset ls_expense_account = '01-000-2440-0000-000';

Page 12: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 12/22

commit;

/*================================================  default sales account==================================================*/update xxaa_items_conv_stgset ls_sales_account = '01-110-9110-0000-000';

commit;

/*=================================================  default template name to 'finish good' if it is null==================================================*/update xxaa_items_conv_stgset ls_template_name = 'Finished Good'where ls_template_name is null;

commit;

/*===============================================  default primary unit of measure================================================*/update xxaa_items_conv_stgset ls_pr_unit_of_measure = 'Each'where ls_pr_unit_of_measure is null;

commit;

/*==================================================  update status of records that are successfully mapped===================================================*/update xxaa_items_conv_stgset status_stg = 'M'where status_stg = 'N';

commit;end map;

/*

**------------------------------------------------------------------------** procedure name: validate** purpose :procedure to validate the staging table fields.**------------------------------------------------------------------------*/procedure validate (p_transaction_id_from number, p_transaction_id_to number)isl_organization_id number;l_template_id number;l_planner_code varchar2 (50);

Page 13: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 13/22

l_buyer_id number;l_subinv_name varchar2 (100);l_sa_id number;l_cogs_id number;l_primary_uom mtl_units_of_measure.uom_code%type;l_buyer_name po_agents_name_v.full_name%type;l_buyer_id po_agents_name_v.buyer_id%type;l_planner_code mtl_planners.planner_code%type;l_cos_account_id number;l_expense_account_id number;l_sales_account_id number;

cursor cur_org_codeisselect distinct ls_organization_codefrom xxaa_items_conv_stgwhere ls_organization_code is not nulland transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;

cursor cur_uom_codeis

select distinct ls_pr_unit_of_measurefrom xxaa_items_conv_stgwhere transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;

cursor cur_item_templateisselect distinct ls_template_namefrom xxaa_items_conv_stgwhere ls_template_name is not nulland transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;

cursor cur_item_cos_accountisselect distinct ls_cos_accountfrom xxaa_items_conv_stgwhere 1 = 1and transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;

cursor cur_item_expense_accountis

select distinct ls_expense_accountfrom xxaa_items_conv_stgwhere 1 = 1and transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;

cursor cur_item_sales_accountisselect distinct ls_sales_account

Page 14: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 14/22

from xxaa_items_conv_stgwhere 1 = 1and transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;beging_application_name := 'INVENTORY';g_object_name := 'ITEMS';g_package_name := 'XXAA_ITEMS_CONV_PKG';g_procedure_name := 'VALIDATE';g_table_name := 'XXAA_ITEMS_CONV_STG';g_file_name := 'Items.csv';

/*======================================  validation for organization if it is null======================================*/beginupdate xxaa_items_conv_stgset status_stg = 'VE',error_code = error_code || 'ORG100;;'where ls_organization_code is nulland transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;exception

when otherstheng_column_name := 'LS ORGANIZATION CODE';g_error_message := 'Organization code is null' || sqlerrm;error_log_write;end;

commit;

/*==================================================  validation for organization id

==================================================*/for org_code_rec in cur_org_codeloopbeging_column_name := 'LS ORGANIZATION CODE';g_column_value := org_code_rec.ls_organization_code;

select organization_idinto l_organization_idfrom mtl_parameterswhere organization_code = org_code_rec.ls_organization_code;

update xxaa_items_conv_stgset organization_id = l_organization_idwhere ls_organization_code = org_code_rec.ls_organization_codeand transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;exceptionwhen no_data_foundthenupdate xxaa_items_conv_stg

Page 15: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 15/22

set status_stg = 'VE',error_code = error_code || 'ORG101;;'where ls_organization_code = org_code_rec.ls_organization_codeand transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;when othersthenupdate xxaa_items_conv_stgset status_stg = 'VE'where ls_organization_code = org_code_rec.ls_organization_codeand transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;

g_error_message :='Unexpected error occurred in organization validation ->'|| sqlerrm;error_log_write;end;end loop;

commit;

/*==========================================  validation for primary uom code=======================================*/for uom_code_rec in cur_uom_codeloopbeging_column_name := 'LS_PR_UNIT_OF_MEASURE';g_column_value := uom_code_rec.ls_pr_unit_of_measure;

select uom_codeinto l_primary_uomfrom mtl_units_of_measure

where nvl (disable_date, sysdate + 1) > sysdateand unit_of_measure =ltrim (rtrim (uom_code_rec.ls_pr_unit_of_measure));

update xxaa_items_conv_stgset pr_uom_code = l_primary_uomwhere ls_pr_unit_of_measure = uom_code_rec.ls_pr_unit_of_measureand transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;exceptionwhen no_data_foundthen

update xxaa_items_conv_stgset status_stg = 'VE',error_code = error_code || 'ITM130;;'where ls_pr_unit_of_measure =uom_code_rec.ls_pr_unit_of_measureand transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;when othersthenupdate xxaa_items_conv_stg

Page 16: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 16/22

set status_stg = 'VE'where ls_pr_unit_of_measure =uom_code_rec.ls_pr_unit_of_measureand transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;

g_error_message :='Unexpected error occurred in Primary UOM validation ->'|| sqlerrm;error_log_write;end;end loop;

commit;

/*==========================================  validation for template id============================================*/for item_template_rec in cur_item_templateloopbegin

g_column_name := 'LS TEMPLATE NAME';g_column_value := item_template_rec.ls_template_name;

select template_idinto l_template_idfrom mtl_item_templateswhere template_name = item_template_rec.ls_template_name;

update xxaa_items_conv_stgset template_id = l_template_idwhere ls_template_name = item_template_rec.ls_template_name

and transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;exceptionwhen no_data_foundthenupdate xxaa_items_conv_stgset status_stg = 'VE',error_code = error_code || 'ITM108;;'where ls_template_name = item_template_rec.ls_template_nameand transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;when othersthen

update xxaa_items_conv_stgset status_stg = 'VE'where ls_template_name = item_template_rec.ls_template_nameand transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;

g_error_message :='Unexpected error occurred in Template Name validation ->'|| sqlerrm;

Page 17: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 17/22

error_log_write;end;end loop;

commit;

/*================================================  validation for cos account==================================================*/for item_cos_account_rec in cur_item_cos_accountloopif item_cos_account_rec.ls_cos_account is not nullthenbeging_column_name := 'LS COS ACCOUNT';g_column_value := item_cos_account_rec.ls_cos_account;

select code_combination_idinto l_cos_account_idfrom gl_code_combinations_kfvwhere 1 = 1

and chart_of_accounts_id = 101and concatenated_segments =item_cos_account_rec.ls_cos_accountand enabled_flag = 'Y';

update xxaa_items_conv_stgset cos_account_id = l_cos_account_idwhere ls_cos_account = item_cos_account_rec.ls_cos_accountand transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;exceptionwhen no_data_found

thenupdate xxaa_items_conv_stgset status_stg = 'VE',error_code = error_code || 'ITM102;;'where ls_cos_account = item_cos_account_rec.ls_cos_accountand transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;when othersthenupdate xxaa_items_conv_stgset status_stg = 'VE'where ls_cos_account = item_cos_account_rec.ls_cos_accountand transaction_id_stg between p_transaction_id_from

and p_transaction_id_to;

g_error_message :='Unexpected error occurred in COS Account validation ->'|| sqlerrm;error_log_write;end;end if;end loop;

Page 18: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 18/22

commit;

/*=====================================================  validation for expense account======================================================*/for item_expense_account_rec in cur_item_expense_accountloopif item_expense_account_rec.ls_expense_account is not nullthenbeging_column_name := 'LS EXPENSE ACCOUNT';g_column_value := item_expense_account_rec.ls_expense_account;

select code_combination_idinto l_expense_account_idfrom gl_code_combinations_kfvwhere 1 = 1and chart_of_accounts_id = 101and concatenated_segments =item_expense_account_rec.ls_expense_account

and enabled_flag = 'Y';

update xxaa_items_conv_stgset expense_account_id = l_expense_account_idwhere ls_expense_account =item_expense_account_rec.ls_expense_accountand transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;exceptionwhen no_data_foundthenupdate xxaa_items_conv_stg

set status_stg = 'VE',error_code = error_code || 'ITM132;;'where ls_expense_account =item_expense_account_rec.ls_expense_accountand transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;when othersthenupdate xxaa_items_conv_stgset status_stg = 'VE'where ls_expense_account =item_expense_account_rec.ls_expense_accountand transaction_id_stg between p_transaction_id_from

and p_transaction_id_to;

g_error_message :='Unexpected error occurred in Expense Account validation ->'|| sqlerrm;error_log_write;end;end if;end loop;

Page 19: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 19/22

commit;

/*=====================================================  validation for sales account======================================================*/for item_sales_account_rec in cur_item_sales_accountloopbeging_column_name := 'LS SALES ACCOUNT';g_column_value := item_sales_account_rec.ls_sales_account;

select code_combination_idinto l_sales_account_idfrom gl_code_combinations_kfvwhere enabled_flag = 'Y'and concatenated_segments =item_sales_account_rec.ls_sales_account;--and organization_id = item_subinv_rec.organization_id;update xxaa_items_conv_stgset sales_account_id = l_sales_account_id

where ls_sales_account = item_sales_account_rec.ls_sales_accountand transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;exceptionwhen no_data_foundthenupdate xxaa_items_conv_stgset status_stg = 'VE',error_code = error_code || 'ITM112;;'where ls_sales_account =item_sales_account_rec.ls_sales_accountand transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;

when othersthenupdate xxaa_items_conv_stgset status_stg = 'VE'where ls_sales_account =item_sales_account_rec.ls_sales_accountand transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;g_error_message :='Unexpected error occurred in Sales Account validation ->'|| sqlerrm;error_log_write;end;

end loop;

commit;

update xxaa_items_conv_stgset status_stg = 'V'where status_stg = 'M'and transaction_id_stg between p_transaction_id_from

Page 20: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 20/22

and p_transaction_id_to;

commit;end validate;

/***------------------------------------------------------------------------** procedure name: load** purpose :procedure to write the errored data into the errors table.**------------------------------------------------------------------------*/procedure load (p_transaction_id_from number, p_transaction_id_to number)isl_transaction_type varchar2 (10) := 'CREATE';l_process_flag number := 1;l_user_id number;l_creation_date date := sysdate;l_last_update_date date := sysdate;l_organization_id number;

cursor cur_items

isselect *from xxaa_items_conv_stgwhere status_stg = 'V'and transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;

beging_application_name := 'INVENTORY';g_object_name := 'ITEMS';g_package_name := 'XXAA_ITEMS_CONV_PKG';g_procedure_name := 'LOAD';g_table_name := 'XXAA_ITEMS_CONV_STG';

g_file_name := 'Items.csv';

beginselect user_idinto l_user_idfrom fnd_userwhere user_name = 'TESTING';exceptionwhen no_data_foundthenl_user_id := 0;end;

for items_rec in cur_itemsloopbegininsert into mtl_system_items_interface(creation_date, created_by, segment1,description,organization_id, primary_uom_code,template_id, cost_of_sales_account,

Page 21: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 21/22

expense_account,sales_account, last_update_date,last_updated_by, process_flag, set_process_id,transaction_type, attribute14)values (sysdate, l_user_id, items_rec.ls_item_number,items_rec.ls_description,items_rec.organization_id, items_rec.pr_uom_code,items_rec.template_id, items_rec.cos_account_id,items_rec.expense_account_id,items_rec.sales_account_id, l_last_update_date,l_user_id, l_process_flag, 112,--mod (items_rec.transaction_id_stg, 5),l_transaction_type, items_rec.transaction_id_stg);exceptionwhen othersthenupdate xxaa_items_conv_stgset status_stg = 'LE'where status_stg = 'V'and transaction_id_stg = items_rec.transaction_id_stg;

commit;g_error_message :='Unexpected error occurred in load procedure ->' || sqlerrm;dbms_output.put_line (sqlerrm);error_log_write;end;end loop;

update xxaa_items_conv_stgset status_stg = 'L'where status_stg = 'V'and transaction_id_stg between p_transaction_id_fromand p_transaction_id_to;

commit;exceptionwhen otherstheng_error_message :='Unexpected error occurred in load procedure ->' || sqlerrm;error_log_write;end load;

/***------------------------------------------------------------------------

** procedure name: error_log_write** purpose :procedure to write the errored data into the errors table.**------------------------------------------------------------------------*/procedure error_log_writeisbegininsert into xxaa_items_err_log(application, file_name, object_name,package_name, procedure_name, table_name,

Page 22: R12 Item Conversion

8/14/2019 R12 Item Conversion

http://slidepdf.com/reader/full/r12-item-conversion 22/22

column_name, column_value, error_date,error_message, transaction_id_stg)values (g_application_name, g_file_name, g_object_name,g_package_name, g_procedure_name, g_table_name,g_column_name, g_column_value, g_error_date,g_error_message, g_transaction_id);

commit;exceptionwhen othersthenfnd_file.put_line (fnd_file.log, 'ERROR_LOG_WRITE#' || sqlerrm);dbms_output.put_line ('ERROR_LOG_WRITE#' || sqlerrm);end error_log_write;

/* procedure val_error_rep isbeginnull;end val_error_rep;procedure load_error_rep is

beginnull;end load_error_rep;*/

end xxaa_items_conv_pkg;