You are on page 1of 6

SELECT MSIB.ORGANIZATION_ID,HAOU.NAME WAREHOUSE, MSIB.INVENTORY_ITEM_ID,MSIB.SEG MENT1 "ITEM CODE",MSIB.DESCRIPTION, MSIB.PRIMARY_UNIT_OF_MEASURE UOM,Round(Nvl(CIC.ITEM_COST,0),2) ITEM_COST ,Nvl(MSIB.MIN_MINMAX_QUANTITY,0) MIN_MINMAX_QUANTITY,Nvl(MSIB.MAX_MINMAX_QUANTIT Y,0) MAX_MINMAX_QUANTITY, Nvl(MSIB.

MINIMUM_ORDER_QUANTITY,0) MINIMUM_ORDER_QUANTITY,Nvl(MSIB.MAXIMUM_ORDER _QUANTITY,0) MAXIMUM_ORDER_QUANTITY, Nvl(MOQD.TRANSACTION_QUANTITY,0) ONHAND_QTY FROM MTL_SYSTEM_ITEMS_B MSIB, MTL_ONHAND_QUANTITIES_DETAIL MOQD, CST_ITEM_COSTS CIC, HR_ALL_ORGANIZATION_UNITS HAOU WHERE MOQD.INVENTORY_ITEM_ID(+) = MSIB.INVENTORY_ITEM_ID AND CIC.INVENTORY_ITEM_ID(+) = MSIB.INVENTORY_ITEM_ID AND MOQD.ORGANIZATION_ID(+) = MSIB.ORGANIZATION_ID AND CIC.ORGANIZATION_ID(+) = MSIB.ORGANIZATION_ID AND MSIB.ORGANIZATION_ID = HAOU.ORGANIZATION_ID AND msib.organization_id != 0 and MSIB.SEGMENT1 in ('54520LH00114','54520LH00115','60620NE00044') and MSIB.ORGANIZATION_ID='1492' ----------------------SELECT * FROM ORG_ORGANIZATION_DEFINITIONS WHERE ORGANIZATION_CODE IN ('TWK','PAS','INT') SELECT INVENTORY_PLANNING_CODE,MSB.INVENTORY_ITEM_ID, ORGANIZATION_ID,SEGMENT1,D ESCRIPTION FROM mtl_system_items_b MSB ,xxx_item_master_stg stg WHERE stg.ITEM_CODE=MSB.SEGMENT1 AND ORGANIZATION_ID=1137 AND INVENTORY_PLANNING_CODE =6 ---------------------SELECT * FROM ORG_ORGANIZATION_DEFINITIONS WHERE ORGANIZATION_CODE IN ('TWK','PAS','INT') ----------------------mIN-MAX LOADING -declare l_err_flag varchar2(3); l_err_msg varchar2(2500); l_count number (2); l_category_set_id number (20); l_category_id number (20); l_org_id number (4); l_template_name varchar2(250); l_uom varchar2(20); l_item_type varchar2(20); l_organization_id number (10); --CURSOR TO FETCH THE DATA FROM STAGING TABLE cursor c1 is SELECT msb.organization_id,'PAS' organization_Code ,'Inventory Type' item_type ,upper(trim(msb.segment1))item_code , msb.description ,'Finished Good' template_name , upper(trim(PRIMARY_UOM_CODE)) uom ,mv.category_id category_id

,'Inventory' cat_set_name ,stg. MIN_MINMAX_QUANTITY ,stg.MAX_MINMAX_QUANTITY ,MSB.INVENTORY_ITEM_ID --,msb.* FROM mtl_system_items_b MSB ,mtl_categories_v MV ,mtl_item_categories A ,xxx_item_master_stg stg WHERE A.INVENTORY_ITEM_ID=MSB.INVENTORY_ITEM_ID AND MV.category_id=a.category_id and msb.organization_id=a.organization_id and upper(trim(msb.segment1)) =stg.item_code and msb.organization_id='1492' --and upper(trim(msb.segment1)) ='20590DD00005' and nvl(verify_flag,'N') = 'N' and STRUCTURE_NAME='Item Categories'; begin for c_rec in c1 loop begin --- initialize the variables l_err_flag :='Y'; l_err_msg := null; ---*********** MASTER ORGANIZATION VALIDATION --1 begin select TO_NUMBER(organization_id) into l_organization_id from org_organization_definitions WHERE organization_code = upper(trim(c_rec.organization_Code)); --The Code of O rganization . E.g 'PAS' for Passions {Picks By Hardcoding} exception when others then l_err_flag := 'Y'; l_err_msg := 'INVALID ORGANIZATION' ; end ; ---*********** ITEM TYPE VALIDATION --2 begin select lookup_code into l_item_type from fnd_lookup_values where lookup_type = 'ITEM_TYPE' and upper(meaning) = trim(upper(c_rec.item_type)); -- Item Type must exist E.g: 'Inventory Type','FA - Inventory' {Picks from Staging Table} exception when others then l_err_flag := 'N1'; l_err_msg := l_err_msg || 'INVALID ITEM TYPE' ; end ; ---*************** ITEM CODE VALIDATION --3 ----********** Check if Item Already exist for the Warehouse Organization begin l_count := 0; /* fOR New Items not to duplicate

select count(*) into l_count from mtl_system_items_b where upper(trim(segment1)) = upper(trim(c_rec.item_code)) --The zation . E.g 'PAS' for Passions {Picks By Hardcoding} --REPEATED PHASY and organization_id = l_organization_id; ---exist E.g: 'Inventory Type','FA - Inventory' {Picks from Staging TED COMMENT FOR EMPHASY if l_count > 0 then l_err_flag := 'N2'; l_err_msg :=l_err_msg || 'ITEM ALREADY EXISTING' ; end if; */ ----*********** VALIDATE THE DESCRIPTION if trim(c_rec.description) is null then E.g: 'Finished Goods -Test' {Picks from Staging Table} l_err_flag := 'N3'; l_err_msg := l_err_msg || 'INVALID DESCRIPTION'; end if; end; --- ITEM TEMPLATE VALIDATION

Code of Organi COMMENT FOR EM Item Type must Table} --REPEA

--Item Description

begin select template_name into l_template_name from mtl_item_templates where upper(trim(template_name)) = upper(trim(c_rec.template_name)); --template _name is same as Item th E.g: 'Finished Good','Purchased Item' {Picks from Stag ing Table} exception when others then l_err_flag := 'N4'; l_err_msg := l_err_msg||'INVALID TEMPLATE NAME'; end ; end; --- PRIMARY UOM VALIDATION begin select unit_of_measure into l_uom from mtl_units_of_measure where upper(trim(uom_code)) = upper(trim(c_rec.uom)); ---The Item's UOM. eg litr e, numbers exception when others then l_err_flag := 'N5'; l_err_msg := l_err_msg||'INVALID UOM'; end; --- ITEM CATEGORY VALIDATION begin select c_rec.category_id into l_category_id from dual; exception when others then

l_err_flag := 'N6'; l_err_msg :=l_err_msg||'INVALID CATEGORY'; end; /* select category_id into l_category_id from mtl_categories_v where segment1 =trim(c_rec.cat_segment1) --Category - Segment1 {Picks from Stag ing Table} and segment2 = trim(c_rec.cat_segment2) ; --Category - Segment2 {Picks from Stag ing Table} exception when others then l_err_flag := 'N'; l_err_msg :=l_err_msg||'INVALID CATEGORY'; end; */ ---************** ITEM CATEGORY SET VALIDATION begin select category_set_id -----1 into l_category_set_id from mtl_category_sets_tl where category_set_name = trim(c_rec.cat_set_name); --Category Set {Picks from Staging Table} -- 'Inventory' exception when others then l_err_flag := 'N7'; l_err_msg :=l_err_msg||'INVALID CATEGORY SET'; end; /* --- ITEM CATEGORY COMBINATION VALIDATION begin l_count := 0; select count(*) into l_count from mtl_category_set_valid_cats_v where category_set_id = l_category_set_id and category_id = l_category_id ; if l_count = 0 then l_err_flag := 'N8'; l_err_msg :=l_err_msg || 'INVALID CATEGORY COMBINATION' ; end if; exception when others then l_err_flag := 'N9'; l_err_msg :=l_err_msg||'INVALID CATEGORY COMBINATION'; end; */ ---- IF ALL VALIDATIONS ARE CORRECT, THEN INSERT DATA INTO INTERFACE TABLE ---- THEN BY USING IMPORT ITEM CONCURRENT PGM, IMPORT ITEMS FROM INTERFACE TABLE INTO BASE TABLE if l_err_flag='Y' then begin insert into mtl_system_items_interface (inventory_item_id, organization_id,

set_process_id, transaction_type, process_flag, min_minmax_quantity, max_minmax_quantity, inventory_planning_code ) select a.inventory_item_id, a.organization_id, 777 set_id, 'UPDATE' tran_type, 1 process_flag, b.MIN_MINMAX_QUANTITY, b.MAX_MINMAX_QUANTITY, 2 inventory_planning_code -- Min-Max from mtl_system_items_b a, xxx_item_master_stg b ,org_organization_definitions c where a.organization_id = c.organization_id and c.organization_code='PAS' and a.segment1 = b.item_code and a.segment1=c_rec.item_code order by item_code asc; /* insert into mtl_system_items_interface ( item_type ,process_flag ,segment1 ,description ,primary_unit_of_measure ,set_process_id ,template_name ,organization_id ,transaction_type ,MIN_MINMAX_QUANTITY ,MAX_MINMAX_QUANTITY ,INVENTORY_ITEM_ID ) values ( l_item_type ,1 ,c_rec.item_code ,c_rec.description ,l_uom ,3 ,l_template_name ,l_organization_id ,'UPDATE' ,c_rec.MIN_MINMAX_QUANTITY ,c_rec.MAX_MINMAX_QUANTITY ,c_rec.INVENTORY_ITEM_ID ); insert into mtl_item_categories_interface ( item_number ,category_set_id

,category_id ,process_flag ,organization_id ,set_process_id ,transaction_type ) values ( c_rec.item_code ,l_category_set_id ,l_category_id ,1 ,l_organization_id ,3 ,'CREATE' ); */ update xxx_item_master_stg set verify_flag = 'Y', err_msg = null where item_code = c_rec.item_code ; commit; exception when others then l_err_msg := sqlerrm; update xxx_item_master_stg set verify_flag = 'N10' ,err_msg = l_err_msg where item_code = c_rec.item_code ; end; commit; else update xxx_item_master_stg set verify_flag = 'N' ,err_msg = l_err_msg where item_code = c_rec.item_code ; end if; commit; end loop; commit; exception when others then dbms_output.put_line(sqlerrm); end;