137
create or replace PACKAGE BODY ss_pc_e_warehouse_iface_k IS /**** -- Procedure name : SS_PC_E_RUN_FTP_P -- Purpose : This is internal procedure to run "SS PC FTP Extraction Progra m" for FTP data file -- Parameter : -- - p_file_name data file name for FTP ****/  PROCEDURE ss_pc_e_run_ftp_p (  p_file_name VARCHAR2)  IS  PRAGMA AUTONOMOUS_TRANSACTION;  v_request_id NUMBER;  v_error_msg VARCHAR2 (2000);  BEGIN  -- run SS PC FTP Extraction Program to FTP the data file into FXPC serve r  v_request_id :=  fnd_request.submit_request  (application => 'S SINV'  ,program => 'S S_PC_E_FTP_ITSS_OUT_IN'  ,description => ''  ,argument1 => p_ file_name  ,argument2 => CH R  (0) );  COMMIT;  EXCEPTION  WHEN OTHERS  THEN  ROLLBACK;  v_error_msg := SUBSTR (SQLERRM  ,1  ,2000);  fnd_file.put_line (fnd_file.LOG  ,'Error in process call FTP program ');  fnd_file.put_line (fnd_file.LOG, 'Error message :' || v_error_msg);  RAISE;  END; /**** -- Procedure name : SS_PC_E_ITEM_EXTRACT_P -- Purpose : Extract item information (item code) from ITSS into data file. -- Parameter : -- - p_file_path -> output directory for generated data file ****/  PROCEDURE ss_pc_e_item_extract_p (  errbuf OUT VARCHAR2  ,retcode OUT VARCHAR2  ,p_file_path IN VARCHAR2)  IS  v_item_code mtl_system_items_b.segment1%TYPE;  v_count NUMBER;  l_file_name VARCHAR2 (100)

Raj Pandit

Embed Size (px)

Citation preview

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 1/137

create or replacePACKAGE BODY ss_pc_e_warehouse_iface_kIS/****-- Procedure name : SS_PC_E_RUN_FTP_P-- Purpose : This is internal procedure to run "SS PC FTP Extraction Program" for FTP data file-- Parameter :-- - p_file_name data file name for FTP****/  PROCEDURE ss_pc_e_run_ftp_p (  p_file_name VARCHAR2)  IS  PRAGMA AUTONOMOUS_TRANSACTION;  v_request_id NUMBER;  v_error_msg VARCHAR2 (2000);  BEGIN  -- run SS PC FTP Extraction Program to FTP the data file into FXPC server  v_request_id :=  fnd_request.submit_request  (application => 'SSINV'  ,program => 'S

S_PC_E_FTP_ITSS_OUT_IN'  ,description => ''  ,argument1 => p_ file_name  ,argument2 => CHR (0) );

  COMMIT;  EXCEPTION  WHEN OTHERS  THEN  ROLLBACK;

  v_error_msg := SUBSTR (SQLERRM  ,1  ,2000);  fnd_file.put_line (fnd_file.LOG  ,'Error in process call FTP program ');  fnd_file.put_line (fnd_file.LOG, 'Error message :' || v_error_msg);  RAISE;  END;

/****-- Procedure name : SS_PC_E_ITEM_EXTRACT_P-- Purpose : Extract item information (item code) from ITSS into data file.-- Parameter :

-- - p_file_path -> output directory for generated data file****/  PROCEDURE ss_pc_e_item_extract_p (  errbuf OUT VARCHAR2  ,retcode OUT VARCHAR2  ,p_file_path IN VARCHAR2)  IS  v_item_code mtl_system_items_b.segment1%TYPE;  v_count NUMBER;  l_file_name VARCHAR2 (100)

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 2/137

  := 'FXPC_ITSSLIVE_ITEMCODES.dat';  l_file_handler UTL_FILE.file_type;  l_file_heading VARCHAR2 (100);  l_file_trailer VARCHAR2 (100);  l_file_data VARCHAR2 (32767);  cnt NUMBER := 0;--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 18 Jun 2008 ---  v_error_msg VARCHAR2 (2000);  l_debug_state VARCHAR2 (2000);  v_user_id NUMBER  := fnd_profile.VALUE ('USER_ID');

  CURSOR c_inv_data  IS  SELECT item_code  FROM ss_pc_e_warehouse_data;/*  CURSOR c_inv_org IS  SELECT organization_id, organization_code, organization_name  FROM org_organization_definitions  WHERE organization_code in('AUS','AUW','HKW','HKS','KRS','KRW','PCM','PDF','SGS','SGW','TWS', 'TWW');

  CURSOR c_inv_cost(p_organization_id number) IS

  SELECT cic.inventory_item_id  FROM cst_item_costs cic  WHERE cic.cost_type_id=1075  AND cic.organization_id =p_organization_id  GROUP BY cic.inventory_item_id;*/--- **** End of Changes for ver 1.1 **** ----  BEGIN  l_debug_state :=  '001 - Truncate SS_PC_E_WAREHOUSE_DATA table';

  EXECUTE IMMEDIATE 'TRUNCATE TABLE FXAP.SS_PC_E_WAREHOUSE_DATA';

  l_debug_state := '002 - Open data file';  l_file_handler :=  UTL_FILE.fopen (p_file_path  ,l_file_name  ,'W'  ,32767);

  IF UTL_FILE.is_open (l_file_handler)  THEN  -- write header into data file  l_debug_state :=  '003 - Write header into data file';  l_file_heading :=

  '01'  || '|'  || 'ITEMCODE'  || '|'  || TO_CHAR (SYSDATE, 'RRRRMMDDHH24MISS')  || '|';  UTL_FILE.put_line (l_file_handler, l_file_heading);--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 18 Jun 2008 ---/*  FOR c_inv_org_rec in c_inv_org

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 3/137

  LOOP

  FOR c_inv_cost_rec in c_inv_cost(c_inv_org_rec.organization_id)  LOOP

  SELECT count(*)  INTO v_count  FROM FXAP.SS_PC_E_WAREHOUSE_DATA  WHERE inventory_item_id=c_inv_cost_rec.inventory_item_id;

  IF v_count =0 then  BEGIN  SELECT segment1  INTO v_item_code  FROM mtl_system_items_b  WHERE inventory_item_id=c_inv_cost_rec.inventory_item_id  AND organization_id=c_inv_org_rec.organization_id;  EXCEPTION  WHEN OTHERS then  v_item_code :=null;  END;

  BEGIN  INSERT into FXAP.SS_PC_E_WAREHOUSE_DATA(item_code,inventory_ite

m_id,  item_req,cost_req,qoh_req,po_req,po_receipt_req,so_req,so_shipped_req)  values(v_item_code,c_inv_cost_rec.inventory_item_id,  'N','N','N','N','N','N','N');  END;  l_file_rec :='02'||'|'||v_item_code;  Utl_File.put_line(l_file_handler,l_file_rec);  cnt := cnt +1;

  END IF;  END LOOP;  COMMIT;

  END LOOP;*/  l_debug_state :=  '004 - Insert item into staging table';

  -- query item to be extracted and inserted into staging table  INSERT INTO ss_pc_e_warehouse_data  (item_code  ,inventory_item_id  ,item_req  ,cost_req  ,qoh_req  ,po_req

  ,po_receipt_req  ,so_req  ,so_shipped_req  ,creation_date  ,created_by  ,last_update_date  ,last_updated_by)  SELECT msi.segment1  ,msi.inventory_item_id  ,'N'

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 4/137

  ,'N'  ,'N'  ,'N'  ,'N'  ,'N'  ,'N'  ,SYSDATE  ,v_user_id  ,SYSDATE  ,v_user_id  FROM cst_cost_types cct  ,cst_item_costs cic  ,mtl_parameters mp  ,mtl_system_items_b msi  WHERE cct.cost_type = 'P_XPC_JPY'  AND cic.cost_type_id = cct.cost_type_id  AND cic.organization_id = mp.organization_id  AND msi.organization_id = cic.organization_id  AND msi.inventory_item_id = cic.inventory_item_id  AND mp.organization_code IN (  SELECT ffv.flex_value  FROM fnd_flex_value_sets ffvs  ,fnd_flex_values ffv  WHERE ffvs.flex_value_set_name =

  'SS_PC_ITEM_EXTRACT_ORG'  AND ffv.flex_value_set_id =  ffvs.flex_value_set_id  AND ffv.enabled_flag = 'Y'  AND TRUNC (SYSDATE)  BETWEEN NVL (ffv.start_date_active  ,TRUNC (SYSDATE) )  AND NVL (ffv.end_date_active  ,SYSDATE) )  GROUP BY msi.segment1  ,msi.inventory_item_id;

  ---Added By Ni Nyoman Rai on 17-Apr-09

  /* INSERT INTO SS_PC_E_WAREHOUSE_DATA  (item_code, inventory_item_id, item_req,  cost_req, qoh_req, po_req,  po_receipt_req, so_req, so_shipped_req, additional_bom,  creation_date, created_by, last_update_date,  last_updated_by)  SELECT DISTINCT msi.segment1, msi.inventory_item_id, 'N', 'N', 'N', 'N', 'N',  'N', 'N', 'Y', SYSDATE , v_user_id  , SYSDATE ,v_user_id  FROM ((SELECT DISTINCT (component_item_id)  FROM bom_inventory_components bic,  bom_structures_b bom,

  mtl_parameters mp  WHERE bic.bill_sequence_id = bom.bill_sequence_id  AND bom.bill_sequence_id IN (SELECT DISTINCT (bill_sequence_id)  FROM bom_inventory_components bic,  ss_pc_e_warehouse_data spw  WHERE bic.component_item_id =

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 5/137

  spw.inventory_item_id  AND spw.additional_bom = 'N')  AND mp.organization_ id = bom.organization_id  AND mp.organization_ code IN (SELECT ffv.flex_value 

FROM fnd_flex_value_sets ffvs, 

fnd_flex_values ffv 

WHERE ffvs.flex_value_set_name ='SS_PC_ITEM_EXTRACT_ORG' 

AND ffv.flex_value_set_id = ffvs.flex_value_set_id 

AND ffv.enabled_flag = 'Y'))  UNION  (SELECT DISTINCT (component_item_id)  FROM bom_inventory_components bic,  bom_structures_b bom,  mtl_parameters mp  WHERE bic.bill_sequence_id = bom.bill_sequenc

e_id  AND bom.bill_sequence_id IN (SELECT DISTINCT (bill_sequence_id)  FROM bom_structures_b bom,  ss_pc_e_ warehouse_data spw  WHERE bom.assembly_item_id = spw.inventory_item_id  AND spw.additional_bom = 'N')  AND mp.organization_id = bom.organization_id

  AND mp.organization_code IN (SELECT ffv.flex_value  FROM fnd_flex_value_sets ffvs,  fnd_flex_values ffv  WHERE ffvs.flex_value_set_name ='SS_PC_ITEM_EXTRACT_ORG'  AND ffv.flex_value_set_id =ffvs.flex_value_set_id  AND ffv.enabled_flag = 'Y'))) comp,  mtl_system_items msi

  WHERE comp.component_item_id = msi.inventory_item_id  AND segment1 NOT IN (SELECT item_code  FROM ss_pc_e_warehouse_data spw  WHERE spw.additional_bom = 'N');*/

  ---End---  COMMIT;  -- query data from staging table and write into data file  l_debug_state :=  '005 - Write item code into data file';

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 6/137

  OPEN c_inv_data;

  IF c_inv_data%ISOPEN  THEN  BEGIN  LOOP  FETCH c_inv_data  INTO v_item_code;

  EXIT WHEN c_inv_data%NOTFOUND;  l_file_data :=  '02' || '|' || v_item_code;  UTL_FILE.put_line (l_file_handler, l_file_data);  cnt := cnt + 1;  END LOOP;

  CLOSE c_inv_data;  EXCEPTION  WHEN OTHERS  THEN  CLOSE c_inv_data;

  RAISE;

  END;  END IF;

--- **** End of Changes for ver 1.1 **** ----

  -- write trailer into data file  l_debug_state :=  '006 - Write trailer into data file';  l_file_trailer :=  '03'  || '|'  || cnt  || '|'

  || TO_CHAR (SYSDATE, 'RRRRMMDDHH24MISS')  || '|';  UTL_FILE.put_line (l_file_handler, l_file_trailer);  UTL_FILE.fclose (l_file_handler);  ELSE  fnd_file.put_line (fnd_file.LOG  , 'File :'  || l_file_name  || ' is not open for writing.');  raise_application_error (-20000  , 'File :'  || l_file_name  || ' is not open for writing.');

  END IF;

  -- send data file into FXPC server  ss_pc_e_warehouse_iface_k.ss_pc_e_run_ftp_p (l_file_name);  EXCEPTION  WHEN UTL_FILE.invalid_path  THEN  ROLLBACK;  raise_application_error  (-20001

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 7/137

  ,'Error while opening the file. Invalid Directory or File name.');  WHEN UTL_FILE.invalid_mode  THEN  ROLLBACK;  raise_application_error  (-20002  ,'Error while opening the file or checking if file is open. Invalid Mode.');  WHEN UTL_FILE.invalid_operation  THEN  ROLLBACK;  raise_application_error  (-20003  ,'Error while opening the file or writing a new line. Invalid Operation.');  WHEN UTL_FILE.invalid_filehandle  THEN  ROLLBACK;  raise_application_error  (-20004  ,'Error in checking if file is open or writing a new line. Invalid File Handle.');  WHEN UTL_FILE.write_error

  THEN  ROLLBACK;  raise_application_error  (-20005  ,'Error in closing file or writing a new line. OS error duringwrite operation.');  WHEN UTL_FILE.read_error  THEN  ROLLBACK;  raise_application_error (-20006, 'Error in defining file type.');  WHEN UTL_FILE.internal_error  THEN  ROLLBACK;

  raise_application_error (-20007, 'Error in defining file type.');  WHEN OTHERS  THEN  ROLLBACK;  v_error_msg := SUBSTR (SQLERRM  ,1  ,2000);  fnd_file.put_line (fnd_file.LOG  , 'Error in process :' || l_debug_state);  fnd_file.put_line (fnd_file.LOG, 'Error message :' || v_error_msg);  RAISE;  END ss_pc_e_item_extract_p;

/****-- Procedure name : SS_PC_E_INV_DETAILS_P-- Purpose : Extract detail item information from ITSS into data file.-- Parameter :-- - p_org_id -> extracted legal entity id-- - p_file_path -> output directory for generated data file-- - p_no_of_days -> number of days****/  PROCEDURE ss_pc_e_inv_details_p (  errbuf OUT VARCHAR2

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 8/137

  ,retcode OUT VARCHAR2  ,p_org_id IN VARCHAR2  ,p_file_path IN VARCHAR2  ,p_no_of_days IN NUMBER)  IS--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 18 Jun 2008 ---  CURSOR c_inv_org (  p_ou_id VARCHAR2)  IS  SELECT ood.organization_id  ,ood.organization_code  ,ood.organization_name  FROM org_organization_definitions ood  WHERE NVL (ood.disable_date, TRUNC (SYSDATE) ) = TRUNC (SYSDATE)  AND ood.legal_entity = p_ou_id;

  TYPE item_code_tab IS TABLE OF mtl_system_items_b.segment1%TYPE;

  TYPE item_description_tab IS TABLE OF VARCHAR2 (1000);

  TYPE item_status_tab IS TABLE OF mtl_system_items_b.inventory_item_status_code%TYPE;

  TYPE primary_uom_code_tab IS TABLE OF mtl_system_items_b.primary_uom_cod

e%TYPE;

  TYPE primary_uom_description_tab IS TABLE OF mtl_system_items_b.primary_ unit_of_measure%TYPE;

  TYPE super_category_tab IS TABLE OF mtl_categories_b.segment1%TYPE;

  TYPE category_tab IS TABLE OF mtl_categories_b.segment2%TYPE;

  TYPE sub_category_tab IS TABLE OF mtl_categories_b.segment3%TYPE;

  TYPE family_tab IS TABLE OF mtl_categories_b.segment4%TYPE;

  TYPE model_tab IS TABLE OF mtl_categories_b.segment5%TYPE;

  TYPE supplies_category_tab IS TABLE OF mtl_categories_b.segment6%TYPE;

  TYPE country_of_origin_tab IS TABLE OF mtl_system_items_b.attribute9%TYPE;

  TYPE primary_vendor_tab IS TABLE OF mtl_system_items_b.attribute12%TYPE;

  TYPE organization_id_tab IS TABLE OF mtl_system_items_b.organization_id%TYPE;

  TYPE organization_code_tab IS TABLE OF mtl_parameters.organization_code%

TYPE;

  TYPE item_creation_date_tab IS TABLE OF mtl_system_items_b.creation_date%TYPE;

  TYPE item_modified_date_tab IS TABLE OF mtl_system_items_b.last_update_date%TYPE;

  TYPE inventory_item_id_tab IS TABLE OF mtl_system_items_b.inventory_item _id%TYPE;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 9/137

  v_item_code item_code_tab;  v_item_description item_description_tab;  v_item_status item_status_tab;  v_primary_uom_code primary_uom_code_tab;  v_primary_uom_description primary_uom_description_tab;  v_super_category super_category_tab;  v_category category_tab;  v_sub_category sub_category_tab;  v_family family_tab;  v_model model_tab;  v_supplies_category supplies_category_tab;  v_country_of_origin country_of_origin_tab;  v_primary_vendor primary_vendor_tab;  v_organization_id organization_id_tab;  v_organization_code organization_code_tab;  v_item_creation_date item_creation_date_tab;  v_item_modified_date item_modified_date_tab;  v_inventory_item_id inventory_item_id_tab;/*  CURSOR c_inv_item IS  SELECT inventory_item_id,item_code  FROM FXAP.SS_PC_E_WAREHOUSE_DATA  WHERE item_req='Y'

  AND ROWNUM <1000 ;

  CURSOR c_inv_detail(p_item_id number,p_organization_id number,p_no_of_days number) IS  SELECT msi.Inventory_item_id,  msi.segment1 Item_code,  substr(msi.description,1,30) Item_Description,  msi.inventory_item_status_code Item_status,  msi.primary_uom_code,  msi.primary_unit_of_measure Primary_uom_description,  msi.attribute9 Country_of_origin,  msi.attribute12 primary_vendor,  msi.organization_id,

  msi.creation_date Item_creation_date,  msi.last_update_date Item_modified_Date  FROM mtl_system_items_b msi  WHERE msi.organization_id = p_organization_id  AND msi.inventory_item_id=p_item_id  AND (trunc(msi.creation_date) between (trunc(sysdate)-p_no_of_days) andtrunc(sysdate)  OR trunc(msi.last_update_date) between (trunc(sysdate)-p_no_of_days)and trunc(sysdate));*/--- **** End of Changes for ver 1.1 **** ----  l_file_name VARCHAR2 (100)  := 'FXPC_ITSSLIVE_ITEM.dat';

  l_file_handler UTL_FILE.file_type;  v_error_msg VARCHAR2 (2000);  l_debug_state VARCHAR2 (2000);  l_file_heading VARCHAR2 (100);  l_file_trailer VARCHAR2 (100);  l_file_data VARCHAR2 (32767);  v_cnt NUMBER := 0;  v_sql VARCHAR2 (32767);  v_no_of_days NUMBER;  v_testing VARCHAR2 (100);

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 10/137

  TYPE c_refc IS REF CURSOR;

  vc_cursor c_refc;--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 18 Jun 2008 ---/*  l_Err_Num NUMBER;  l_Err_Msg VARCHAR2(1000);  l_Item_super_category VARCHAR2(40);  l_Item_category VARCHAR2(40);  l_Item_sub_Category VARCHAR2(40);  l_Item_supplies_category VARCHAR2(40);  l_Item_family VARCHAR2(40);  l_Item_Model VARCHAR2(40);*/--- **** End of Changes for ver 1.1 **** ----  BEGIN  ---*** Begin Change for ver 2.1 **** Update by Ni Nyoman Rai on 29 Jan 2009 ---  ss_pc_e_insorg (p_org_id);  ---**** End of Changes for ver 2.1 **** ----  l_debug_state :=  '000 - Open FXPC_ITSSLIVE_ITEM.dat file for writing';  l_file_handler :=

  UTL_FILE.fopen (p_file_path  ,l_file_name  ,'W'  ,32767);

  -- get no of days  IF p_no_of_days IS NULL  THEN  BEGIN  SELECT NVL (nof_days, 0)  INTO v_no_of_days  FROM ss_pc_e_wh_data_parameters  WHERE interface_type = 'ITEMREQ';

  EXCEPTION  WHEN OTHERS  THEN  v_no_of_days := NULL;  END;  ELSE  v_no_of_days := p_no_of_days;  END IF;

  fnd_file.put_line (fnd_file.LOG, 'Number of days :' || v_no_of_days);

  IF UTL_FILE.is_open (l_file_handler)  THEN

  l_debug_state :=  '001 - Write header into data file';  l_file_heading :=  '01'  || '|'  || 'ITEM'  || '|'  || TO_CHAR (SYSDATE, 'RRRRMMDDHH24MISS');  UTL_FILE.put_line (l_file_handler, l_file_heading);

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 11/137

---*** Begin Change for ver 2.1 **** Update by Ni Nyoman Rai on 29 Jan 2009 ---  FOR i IN (SELECT orgid  FROM ss_pc_e_temp_org)  LOOP---**** End of Changes for ver 2.1 **** ----  FOR c_inv_org_rec IN c_inv_org (i.orgid)  LOOP--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 18 Jun 2008 ---/*  FOR c_inv_item_rec IN c_inv_item  LOOP  FOR c_inv_detail_rec IN c_inv_detail(c_inv_item_rec.inventory_item_id,c_inv_org_rec.organization_id,p_no_of_days)  LOOP  BEGIN  SELECT cat.segment1 , cat.segment2 , cat.segment3 ,cat.segment6 , cat.segment4 , cat.segment5  INTO l_Item_super_category,l_Item_category,l_Item_sub_Category,l_Item_supplies_category,l_Item_family,l_Item_Model  FROM mtl_categories cat,  mtl_item_categories micat  WHERE micat.inventory_item_id =c_inv_item_rec.inventory_item_id  AND micat.organization_id =c_inv_org_rec.organization_id

  AND micat.category_id = cat.category_id  AND micat.category_set_id = 1  AND cat.structure_id = 101;  EXCEPTION  WHEN NO_DATA_FOUND then  l_Item_super_category :=null;  WHEN OTHERS then  l_Item_super_category :=null;  END;

  l_file_rec :='02'||'|'||c_inv_detail_rec.Item_code||'|'||c_inv_detail_rec.Item_description||'|'||

  c_inv_detail_rec.Item_status||'|'||c_inv_detail_rec.Primary_uom_code||'|'||  c_inv_detail_rec.primary_uom_description||'|'||l_Item_ super_category||'|'||  l_Item_category||'|'||l_Item_sub_category||'|'||  l_Item_supplies_category||'|'||l_Item_family||'|'||  l_Item_model||'|'||c_inv_detail_rec.Country_of_origin||'|'||  c_inv_detail_rec.Primary_Vendor||'|'||c_inv_detail_rec.Organization_id||'|'||  c_inv_org_rec.organization_code||'|'||c_inv_org_rec.name||'|'||  c_inv_detail_rec.Item_creation_date||'|'||c_inv_detail

 _rec.Item_modified_Date;

  Utl_File.put_line(l_file_handler,l_file_rec);  v_cnt := v_cnt +1;  END LOOP;  END LOOP;*/  l_debug_state :=  '002 - Query item data for organization '  || c_inv_org_rec.organization_code;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 12/137

  v_sql :=  ' SELECT msi.segment1 item_code,  msi.description item_description,  msi.inventory_item_status_code item_status,  msi.primary_uom_code,  msi.primary_unit_of_measure primary_uom_description,  mc.segment1 super_category,  mc.segment2 category,  mc.segment3 sub_category,  mc.segment4 family,  mc.segment5 model,  mc.segment6 supplies_category,  msi.attribute9 country_of_origin,  msi.attribute12 primary_vendor,  msi.organization_id,  mp.organization_code,  msi.creation_date item_creation_date,  msi.last_update_date item_modified_date,  msi.inventory_item_id  FROM mtl_parameters mp,  mtl_system_items_b msi,  mtl_item_categories mic,  mtl_categories_b mc

  WHERE mp.organization_id = :p_orgid  AND msi.organization_id = mp.organization_id  AND mic.inventory_item_id = msi.inventory_item_id  AND mic.organization_id = msi.organization_id  AND mic.category_set_id = 1  AND mc.category_id = mic.category_id  AND mc.structure_id = 101  AND EXISTS (  SELECT 1  FROM ss_pc_e_warehouse_data ssp  WHERE ssp.item_req = ''Y'' '  ||  ---*** Begin Change for ver 2.2 **** Update by Ni Nyo

man Rai on 30 Jan 2009 ---  -- AND ssp.inventory_item_id = msi.inventory_item_id  'AND ssp.item_code = msi.segment1 ) ';

  ---**** End of Changes for ver 2.2 **** ----  IF v_no_of_days IS NOT NULL  THEN  v_sql :=  v_sql  || '  AND (trunc(msi.creation_date) BETWEEN (trunc(sysdate)- :p_num_days) AND trunc(sysdate)

  OR trunc(msi.last_update_date) BETWEEN (trunc(sysdate)- :p_num_days) AND trunc(sysdate)) ';

  OPEN vc_cursor FOR v_sql  USING c_inv_org_rec.organization_id  ,v_no_of_days  ,v_no_of_days;  ELSE  OPEN vc_cursor FOR v_sql  USING c_inv_org_rec.organization_id;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 13/137

  END IF;

  IF vc_cursor%ISOPEN  THEN  BEGIN  l_debug_state :=  '003 - Fetch item data for organization '  || c_inv_org_rec.organization_code;

  FETCH vc_cursor  BULK COLLECT INTO v_item_code  ,v_item_description  ,v_item_status  ,v_primary_uom_code  ,v_primary_uom_description  ,v_super_category  ,v_category  ,v_sub_category  ,v_family  ,v_model  ,v_supplies_category  ,v_country_of_origin  ,v_primary_vendor  ,v_organization_id

  ,v_organization_code  ,v_item_creation_date  ,v_item_modified_date  ,v_inventory_item_id;

  IF v_item_code.FIRST IS NOT NULL  THEN  FOR i IN 1 .. v_item_code.LAST  LOOP  l_debug_state :=  '004 - Construct item data for organization '  || c_inv_org_rec.organization_code

  || ' into data file ';  l_file_data :=  '02'  || '|'  || v_item_code (i)  || '|'  || v_item_description (i)  || '|'  || v_item_status (i)  || '|'  || v_primary_uom_code (i)  || '|'  || v_primary_uom_description (i)

  || '|'  || v_super_category (i)  || '|'  || v_category (i)  || '|'  || v_sub_category (i)  || '|'  || v_supplies_category (i)  || '|'  || v_family (i)

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 14/137

  || '|'  || v_model (i)  || '|'  || v_country_of_origin (i)  || '|'  || v_primary_vendor (i)  || '|'  || v_organization_id (i)  || '|'  || v_organization_code (i)  || '|'  || c_inv_org_rec.organization_name  || '|'  || v_item_creation_date (i)  || '|'  || v_item_modified_date (i);  l_debug_state :=  '005 - Write item data for organization '  || c_inv_org_rec.organization_code  || ' into data file ';  UTL_FILE.put_line (l_file_handler  ,l_file_data);  v_cnt :=

  v_cnt + 1;  END LOOP;  END IF;

  CLOSE vc_cursor;  EXCEPTION  WHEN OTHERS  THEN  IF vc_cursor%ISOPEN  THEN  CLOSE vc_cursor;  END IF;

  RAISE;  END;  END IF;  END LOOP;--- **** End of Changes for ver 1.1 **** ----  END LOOP;

--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 18 Jun 2008 ---  l_debug_state :=  '006 - Write trailer data into data file ';  l_file_trailer :=  '03'  || '|'

  || TO_CHAR (v_cnt)  || '|'  || TO_CHAR (SYSDATE, 'RRRRMMDDHH24MISS');  UTL_FILE.put_line (l_file_handler, l_file_trailer);  UTL_FILE.fclose (l_file_handler);  fnd_file.put_line (fnd_file.output, 'Number of rows ' || v_cnt);--- **** End of Changes for ver 1.1 **** ----  ELSE  fnd_file.put_line (fnd_file.LOG  , 'File :'

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 15/137

  || l_file_name  || ', is not open for writing.');  raise_application_error (-20000  , 'File :'  || l_file_name  || ' is not open for writing.');  END IF;

--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 18 Jun 2008 ---  -- send data file into FXPC server  ss_pc_e_warehouse_iface_k.ss_pc_e_run_ftp_p (l_file_name);--- **** End of Changes for ver 1.1 **** ----  EXCEPTION  WHEN UTL_FILE.invalid_path  THEN  ROLLBACK;  raise_application_error  (-20001  ,'Error while opening the file. Invalid Directory or File name.');  WHEN UTL_FILE.invalid_mode  THEN  ROLLBACK;  raise_application_error

  (-20002  ,'Error while opening the file or checking if file is open. Invalid Mode.');  WHEN UTL_FILE.invalid_operation  THEN  ROLLBACK;  raise_application_error  (-20003  ,'Error while opening the file or writing a new line. Invalid Operation.');  WHEN UTL_FILE.invalid_filehandle  THEN  ROLLBACK;

  raise_application_error  (-20004  ,'Error in checking if file is open or writing a new line. Invalid File Handle.');  WHEN UTL_FILE.write_error  THEN  ROLLBACK;  raise_application_error  (-20005  ,'Error in closing file or writing a new line. OS error duringwrite operation.');  WHEN UTL_FILE.read_error  THEN

  ROLLBACK;  raise_application_error (-20006, 'Error in defining file type.');  WHEN UTL_FILE.internal_error  THEN  ROLLBACK;  raise_application_error (-20007, 'Error in defining file type.');  WHEN OTHERS  THEN  ROLLBACK;  v_error_msg := SUBSTR (SQLERRM

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 16/137

  ,1  ,2000);  fnd_file.put_line (fnd_file.LOG  , 'Error in process :' || l_debug_state);  fnd_file.put_line (fnd_file.LOG, 'Error message :' || v_error_msg);  RAISE;  END ss_pc_e_inv_details_p;

/****-- Procedure name : SS_PC_E_COST_DETAILS_P-- Purpose : Extract detail cost information from ITSS into data file.-- Parameter :-- - p_org_id -> extracted legal entity id-- - p_file_path -> output directory for generated data file-- - p_no_of_days -> number of days****/  PROCEDURE ss_pc_e_cost_details_p (  errbuf OUT VARCHAR2  ,retcode OUT VARCHAR2  ,p_org_id IN VARCHAR2  ,p_file_path IN VARCHAR2  ,p_no_of_days IN NUMBER)  IS--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 18 Jun 2008 ---

  CURSOR c_inv_org (  p_ou_id NUMBER)  IS  SELECT ood.organization_id  ,ood.organization_code  ,ood.organization_name  ,gsb.currency_code  FROM org_organization_definitions ood  ,gl_sets_of_books gsb  WHERE NVL (ood.disable_date, TRUNC (SYSDATE) ) = TRUNC (SYSDATE)  AND ood.legal_entity = p_ou_id  AND gsb.set_of_books_id = ood.set_of_books_id;

/*  CURSOR c_inv_org IS  SELECT ood.organization_id,ood.organization_code ,ood.organization_namename,set_of_books_id  FROM org_organization_definitions ood  WHERE disable_date is null  AND legal_entity=p_org_id;

  CURSOR c_inv_item IS  SELECT inventory_item_id,item_code  FROM fxap.ss_pc_e_warehouse_data  WHERE cost_req='Y' ;

  CURSOR c_cost_detail (p_inventory_item_id number,p_organizaion_id number,p_no_of_days number) IS  SELECT nvl(cic.item_cost,0) item_cost,  msi.creation_date,  cic.last_update_date  FROM cst_item_costs cic,mtl_system_items_b msi  WHERE cic.cost_type_id=1075  AND cic.inventory_item_id =p_inventory_item_id  AND cic.organization_id =p_organizaion_id  AND cic.inventory_item_id=msi.inventory_item_id

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 17/137

  AND cic.organization_id=msi.organization_id  AND (trunc(msi.creation_date) between (trunc(sysdate)-p_no_of_days) andtrunc(sysdate)  OR trunc(cic.last_update_date) between (trunc(sysdate)-p_no_of_days) and trunc(sysdate));*/  l_file_name VARCHAR2 (100)  := 'FXPC_ITSSLIVE_COST.dat';  l_file_handler UTL_FILE.file_type;  v_error_msg VARCHAR2 (2000);  l_debug_state VARCHAR2 (2000);  l_file_heading VARCHAR2 (100);  l_file_trailer VARCHAR2 (100);  l_file_data VARCHAR2 (32767);  v_cnt NUMBER := 0;  v_sql VARCHAR2 (32767);  v_no_of_days NUMBER;

  TYPE c_refc IS REF CURSOR;

  vc_cursor c_refc;

  TYPE item_code_tab IS TABLE OF mtl_system_items_b.segment1%TYPE;

  TYPE item_cost_tab IS TABLE OF cst_item_costs.item_cost%TYPE;

  TYPE creation_date_tab IS TABLE OF mtl_system_items.creation_date%TYPE;

  TYPE last_update_date_tab IS TABLE OF cst_item_costs.last_update_date%TYPE;

  TYPE organization_id_tab IS TABLE OF mtl_parameters.organization_id%TYPE;

  v_item_code item_code_tab;  v_item_cost item_cost_tab;  v_creation_date creation_date_tab;

  v_last_update_date last_update_date_tab;  v_organization_id organization_id_tab;/*  File_Close Exception;  l_file_rec1 VARCHAR2(100);  l_file_rec2 VARCHAR2(100);  l_file_rec VARCHAR2(32767);  l_Err_Num NUMBER;  l_Err_Msg VARCHAR2(1000);  cnt NUMBER := 0;  l_currency_code VARCHAR2(3);*/--- **** End of Changes for ver 1.1 **** ----

  BEGIN  ---*** Begin Change for ver 2.1 **** Update by Ni Nyoman Rai on 29 Jan 2009 ---  ss_pc_e_insorg (p_org_id);  ---**** End of Changes for ver 2.1 **** ----  l_debug_state :=  '000 - Open FXPC_ITSSLIVE_COST.dat file for writing';  l_file_handler :=  UTL_FILE.fopen (p_file_path  ,l_file_name

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 18/137

  ,'W'  ,32767);

  -- get no of days  IF p_no_of_days IS NULL  THEN  BEGIN  SELECT NVL (nof_days, 0)  INTO v_no_of_days  FROM ss_pc_e_wh_data_parameters  WHERE interface_type = 'COSTREQ';  EXCEPTION  WHEN OTHERS  THEN  v_no_of_days := NULL;  END;  ELSE  v_no_of_days := p_no_of_days;  END IF;

  fnd_file.put_line (fnd_file.LOG, 'Number of days :' || v_no_of_days);

  IF UTL_FILE.is_open (l_file_handler)  THEN

  l_debug_state :=  '001 - Write header into data file';  l_file_heading :=  '01'  || '|'  || 'ITEM'  || '|'  || TO_CHAR (SYSDATE, 'RRRRMMDDHH24MISS');  UTL_FILE.put_line (l_file_handler, l_file_heading);

  FOR i IN (SELECT orgid  FROM ss_pc_e_temp_org)  LOOP

  FOR c_inv_org_rec IN c_inv_org (i.orgid)  LOOP/*  FOR c_inv_item_rec IN c_inv_item  LOOP

  FOR c_cost_detail_rec IN c_cost_detail( c_inv_item_rec.inventory_item_id,c_inv_org_rec.organization_id,p_no_of_days)  LOOP  BEGIN  SELECT currency_code INTO l_currency_code  FROM GL_SETS_OF_BOOKS  WHERE set_of_books_id=c_inv_org_rec.set_of_books_id;

  EXCEPTION  WHEN OTHERS THEN  l_currency_code :=NULL;  END;

  Utl_File.put_line(l_file_handler,l_file_rec);  l_file_rec :='02'||'|'||c_inv_item_rec.item_code||'|'||l_currency_code||'|'||c_cost_detail_rec.item_cost  ||'|'||c_inv_org_rec.organization_id||'|'||c_cost_detail

 _rec.creation_date

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 19/137

  ||'|'||c_cost_detail_rec.last_update_date;  cnt := cnt +1;

  END LOOP;

  END LOOP;*/  l_debug_state :=  '002 - Query cost data for organization '  || c_inv_org_rec.organization_code;  v_sql :=  ' SELECT msi.segment1 item_code,  nvl(cic.item_cost,0) item_cost,  msi.creation_date,  cic.last_update_date,  cic.organization_id  FROM mtl_parameters mp,  mtl_system_items_b msi,  cst_cost_types cct,  cst_item_costs cic  WHERE mp.organization_id = :p_org_id  AND msi.organization_id = mp.organization_id  AND EXISTS (SELECT 1  FROM ss_pc_e_warehouse_data ssp

  WHERE ssp.cost_req = ''Y''  AND ssp.item_code = msi.segment1 )  AND cct.cost_type = ''Frozen''  AND cic.cost_type_id = cct.cost_type_id  AND cic.inventory_item_id = msi.inventory_item_id  AND cic.organization_id = msi.organization_id ';

  -- AND cct.cost_type = ''P_XPC_JPY'' changed to 'Frozen' on24 Apr 2009 as William N requested  IF v_no_of_days IS NOT NULL  THEN  v_sql :=  v_sql

  || '  AND (trunc(msi.creation_date) BETWEEN (trunc(sysdate)- :p_num_days) AND trunc(sysdate)  OR trunc(cic.last_update_date) BETWEEN (trunc(sysdate)- :p_num_days) AND trunc(sysdate)) ';

  OPEN vc_cursor FOR v_sql  USING c_inv_org_rec.organization_id  ,v_no_of_days  ,v_no_of_days;  ELSE  OPEN vc_cursor FOR v_sql  USING c_inv_org_rec.organization_id;

  END IF;

  IF vc_cursor%ISOPEN  THEN  BEGIN  l_debug_state :=  '003 - Fetch cost data for organization '  || c_inv_org_rec.organization_code;

  FETCH vc_cursor

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 20/137

  BULK COLLECT INTO v_item_code  ,v_item_cost  ,v_creation_date  ,v_last_update_date  ,v_organization_id;

  IF v_item_code.FIRST IS NOT NULL  THEN  FOR i IN 1 .. v_item_code.LAST  LOOP  l_debug_state :=  '004 - Construct cost data for organization '  || c_inv_org_rec.organization_code  || ' into data file ';  l_file_data :=  '02'  || '|'  || v_item_code (i)  || '|'  || c_inv_org_rec.currency_code  || '|'  || v_item_cost (i)  || '|'

  || v_organization_id (i)  || '|'  || v_creation_date (i)  || '|'  || v_last_update_date (i);  l_debug_state :=  '005 - Write cost data for organization '  || c_inv_org_rec.organization_code  || ' into data file ';  UTL_FILE.put_line (l_file_handler  ,l_file_data);  v_cnt :=

  v_cnt + 1;  END LOOP;  END IF;

  CLOSE vc_cursor;  EXCEPTION  WHEN OTHERS  THEN  IF vc_cursor%ISOPEN  THEN  CLOSE vc_cursor;  END IF;

  RAISE;  END;  END IF;  END LOOP;  END LOOP;

  l_debug_state :=  '006 - Write trailer data into data file ';  l_file_trailer :=  '03'

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 21/137

  || '|'  || TO_CHAR (v_cnt)  || '|'  || TO_CHAR (SYSDATE, 'RRRRMMDDHH24MISS');  UTL_FILE.put_line (l_file_handler, l_file_trailer);  UTL_FILE.fclose (l_file_handler);  fnd_file.put_line (fnd_file.output, 'Number of rows ' || v_cnt);  ELSE  fnd_file.put_line (fnd_file.LOG  , 'File :'  || l_file_name  || ', is not open for writing.');  raise_application_error (-20000  , 'File :'  || l_file_name  || ' is not open for writing.');  END IF;

--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 18 Jun 2008 ---  -- send data file into FXPC server  ss_pc_e_warehouse_iface_k.ss_pc_e_run_ftp_p (l_file_name);--- **** End of Changes for ver 1.1 **** ----  EXCEPTION  WHEN UTL_FILE.invalid_path

  THEN  ROLLBACK;  raise_application_error  (-20001  ,'Error while opening the file. Invalid Directory or File name.');  WHEN UTL_FILE.invalid_mode  THEN  ROLLBACK;  raise_application_error  (-20002  ,'Error while opening the file or checking if file is open. Invalid Mode.');

  WHEN UTL_FILE.invalid_operation  THEN  ROLLBACK;  raise_application_error  (-20003  ,'Error while opening the file or writing a new line. Invalid Operation.');  WHEN UTL_FILE.invalid_filehandle  THEN  ROLLBACK;  raise_application_error  (-20004  ,'Error in checking if file is open or writing a new line. Inval

id File Handle.');  WHEN UTL_FILE.write_error  THEN  ROLLBACK;  raise_application_error  (-20005  ,'Error in closing file or writing a new line. OS error duringwrite operation.');  WHEN UTL_FILE.read_error  THEN

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 22/137

  ROLLBACK;  raise_application_error (-20006, 'Error in defining file type.');  WHEN UTL_FILE.internal_error  THEN  ROLLBACK;  raise_application_error (-20007, 'Error in defining file type.');  WHEN OTHERS  THEN  ROLLBACK;  v_error_msg := SUBSTR (SQLERRM  ,1  ,2000);  fnd_file.put_line (fnd_file.LOG  , 'Error in process :' || l_debug_state);  fnd_file.put_line (fnd_file.LOG, 'Error message :' || v_error_msg);  RAISE;  END ss_pc_e_cost_details_p;

/****-- Procedure name : SS_PC_E_ONHAND_QTY_P-- Purpose : Extract detail onhand item information from ITSS into data file.-- Parameter :-- - p_org_id -> extracted legal entity id

-- - p_file_path -> output directory for generated data file****/  PROCEDURE ss_pc_e_onhand_qty_p (  errbuf OUT VARCHAR2  ,retcode OUT VARCHAR2  ,p_org_id IN VARCHAR2  ,p_file_path IN VARCHAR2)  IS--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 18 Jun 2008 ---  l_file_name VARCHAR2 (100)  := 'FXPC_ITSSLIVE_QOH.dat';  l_file_handler UTL_FILE.file_type;  v_error_msg VARCHAR2 (2000);

  l_debug_state VARCHAR2 (2000);  l_file_heading VARCHAR2 (100);  l_file_trailer VARCHAR2 (100);  l_file_data VARCHAR2 (32767);  v_cnt NUMBER := 0;  v_sql VARCHAR2 (32767);

  TYPE c_refc IS REF CURSOR;

  vc_cursor c_refc;

  -- assumption, there is no transaction in master organization code, so there is no OHQ in master org

  CURSOR c_inv_org (  p_ou_id NUMBER)  IS  SELECT ood.organization_id  ,ood.organization_code  FROM org_organization_definitions ood  ,mtl_parameters mp  WHERE NVL (ood.disable_date, TRUNC (SYSDATE) ) = TRUNC (SYSDATE)  AND ood.legal_entity = p_ou_id  AND mp.organization_id = ood.organization_id

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 23/137

  AND mp.master_organization_id <> ood.organization_id;

  TYPE item_code_tab IS TABLE OF mtl_system_items_b.segment1%TYPE;

  TYPE organization_id_tab IS TABLE OF mtl_system_items_b.organization_id%TYPE;

  TYPE subinventory_code_tab IS TABLE OF mtl_onhand_quantities_detail.subinventory_code%TYPE;

  TYPE serial_number_tab IS TABLE OF mtl_serial_numbers.serial_number%TYPE;

  TYPE transaction_qty_tab IS TABLE OF mtl_onhand_quantities_detail.transaction_quantity%TYPE;

  TYPE availability_type_tab IS TABLE OF mtl_secondary_inventories.availability_type%TYPE;

  v_item_code item_code_tab;  v_organization_id organization_id_tab;  v_subinventory_code subinventory_code_tab;  v_serial_number serial_number_tab;  v_transaction_quantity transaction_qty_tab;

  v_net_flag CHAR (1);  v_availability_type availability_type_tab;/* CURSOR c_inv_org IS  SELECT organization_id  FROM org_organization_Definitions  WHERE disable_date is null  AND legal_entity = p_org_id;

 CURSOR c_inv_item IS  SELECT inventory_item_id,item_code  FROM ss_pc_e_warehouse_data  WHERE qoh_req = 'Y';

 CURSOR c_onhand_detail(p_item_id number,p_organization_id number) IS  SELECT moq.inventory_item_id,  moq.organization_id,  moq.subinventory_code,  null serial_number,  nvl(sum(moq.transaction_quantity),0) transaction_quantity,  msiv.availability_type  FROM mtl_onhand_quantities_detail moq,  mtl_serial_numbers msn,  mtl_secondary_inventories msiv  WHERE moq.inventory_item_id=p_item_id  AND moq.organization_id =p_organization_id

  AND TRUNC(moq.date_received) <= TRUNC(sysdate)  AND moq.subinventory_code=msiv.secondary_inventory_name  AND moq.organization_id=msiv.organization_id  AND moq.inventory_item_id=msn.inventory_item_id(+)  AND moq.organization_id =msn.current_organization_id(+)  AND moq.subinventory_code=msn.current_subinventory_code(+)  AND msn.serial_number is null  AND current_status(+) =3  GROUP BY moq.inventory_item_id,  moq.organization_id,

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 24/137

  moq.subinventory_code,  msiv.availability_type  UNION  SELECT moq.inventory_item_id,  moq.organization_id,  moq.subinventory_code,  msn.serial_number,  1 transaction_quantity,  msiv.availability_type  FROM mtl_onhand_quantities_detail moq,  mtl_serial_numbers msn,  mtl_secondary_inventories msiv  WHERE moq.inventory_item_id=p_item_id  AND moq.organization_id =p_organization_id  AND TRUNC(moq.date_received) <= TRUNC(sysdate)  AND moq.subinventory_code=msiv.secondary_inventory_name  AND moq.organization_id=msiv.organization_id  AND moq.inventory_item_id=msn.inventory_item_id(+)  AND moq.organization_id =msn.current_organization_id(+)  AND moq.subinventory_code=msn.current_subinventory_code(+)  AND msn.serial_number is not null  AND current_status(+) = 3  GROUP BY moq.inventory_item_id,  moq.organization_id,

  moq.subinventory_code,  msn.serial_number,  msiv.availability_type;

  File_Close Exception;  l_file_rec1 VARCHAR2(100);  l_file_rec2 VARCHAR2(100);  l_file_rec VARCHAR2(32767);  l_Err_Num NUMBER;  l_Err_Msg VARCHAR2(1000);  cnt NUMBER := 0;  l_item_code VARCHAR2(40);  l_net_flag VARCHAR2(1);

*/--- **** End of Changes for ver 1.1 **** ----  BEGIN  ---*** Begin Change for ver 2.1 **** Update by Ni Nyoman Rai on 29 Jan 2009 ---  ss_pc_e_insorg (p_org_id);  ---**** End of Changes for ver 2.1 **** ----  l_debug_state :=  '000 - Open FXPC_ITSSLIVE_QOH.dat file for writing';  l_file_handler :=  UTL_FILE.fopen (p_file_path  ,l_file_name  ,'W'

  ,32767);

  IF UTL_FILE.is_open (l_file_handler)  THEN  l_debug_state :=  '001 - Write header into data file';  l_file_heading :=  '01'  || '|'  || 'QOH'

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 25/137

  || '|'  || TO_CHAR (SYSDATE, 'RRRRMMDDHH24MISS');  UTL_FILE.put_line (l_file_handler, l_file_heading);

  FOR i IN (SELECT orgid  FROM ss_pc_e_temp_org)  LOOP  FOR c_inv_org_rec IN c_inv_org (i.orgid)  LOOP--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 18 Jun 2008 ---/*  FOR c_inv_item_rec IN c_inv_item  LOOP  FOR c_onhand_detail_rec IN c_onhand_detail(c_inv_item_rec.inventory_item_id,c_inv_org_rec.organization_id)  LOOP  BEGIN  SELECT msi.segment1  INTO l_item_code  FROM mtl_system_items_b msi  WHERE msi.inventory_item_id=c_onhand_detail_rec.inventory_item_id  and msi.organization_id=c_onhand_detail_rec.organization_id ;

  EXCEPTION  WHEN NO_DATA_FOUND then  l_item_code :=null;  WHEN OTHERS then  l_item_code :=null;  END;

  IF c_onhand_detail_rec.availability_type=1 then  l_net_flag :='Y';  ELSIF c_onhand_detail_rec.availability_type=2 then  l_net_flag :='N';  ELSE  l_net_flag :='N';

  END IF;

  l_file_rec :='02'||'|'||c_onhand_detail_rec.organization_id||'|'||  c_onhand_detail_rec.subinventory_code||'|'||  l_item_Code||'|'||  c_onhand_detail_rec.serial_number||'|'||  c_onhand_detail_rec.transaction_quantity||'|'||  l_net_flag;

  Utl_File.put_line(l_file_handler,l_file_rec);  cnt := cnt +1;

  END LOOP;  END LOOP;*/

  -- query for non serialized item  l_debug_state :=  '002 - Query QOH non serialized item data for organization '  || c_inv_org_rec.organization_code;  v_sql :=

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 26/137

  'SELECT msi.segment1 item_code,  moq.organization_id,  moq.subinventory_code,  null serial_number,  sum(moq.transaction_quantity) transaction_quantity,  msiv.availability_type  FROM ss_pc_e_warehouse_data ssp,  mtl_system_items_b msi,  mtl_secondary_inventories msiv,  mtl_onhand_quantities moq  WHERE ssp.qoh_req = ''Y'' '  ||  --AND ssp.inventory_item_id = msi.inventory_item_id  'AND ssp.item_code = msi.segment1  AND msi.organization_id = :p_org_id  AND msi.serial_number_control_code = 1 -- non serialized item  AND moq.inventory_item_id = msi.inventory_item_id  AND moq.organization_id = msi.organization_id  AND msiv.organization_id = moq.organization_id  AND msiv.secondary_inventory_name = moq.subinventory_code  GROUP BY msi.segment1,

  moq.organization_id,  moq.subinventory_code,  msiv.availability_type ';

  OPEN vc_cursor FOR v_sql USING  c_inv_org_rec.organization_id;

  IF vc_cursor%ISOPEN  THEN  BEGIN  l_debug_state :=  '003 - Fetch QOH non serialized item data for organization '

  || c_inv_org_rec.organization_code;

  FETCH vc_cursor  BULK COLLECT INTO v_item_code  ,v_organization_id  ,v_subinventory_code  ,v_serial_number  ,v_transaction_quantity  ,v_availability_type;

  IF v_item_code.FIRST IS NOT NULL  THEN  FOR i IN 1 .. v_item_code.LAST

  LOOP  l_debug_state :=  '004 - Construct QOH non serialized item data for organization '  || c_inv_org_rec.organization_code  || ' into data file ';

  IF v_availability_type (i) = 1  THEN  v_net_flag :=

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 27/137

  'Y';  ELSE  v_net_flag :=  'N';  END IF;

  l_file_data :=  '02'  || '|'  || v_organization_id (i)  || '|'  || v_subinventory_code (i)  || '|'  || v_item_code (i)  || '|'  || v_serial_number (i)  || '|'  || v_transaction_quantity (i)  || '|'  || v_net_flag;  l_debug_state :=  '005 - Write QOH non serialized itemdata for organization '  || c_inv_org_rec.organization_code

  || ' into data file ';  UTL_FILE.put_line (l_file_handler  ,l_file_data);  v_cnt :=  v_cnt + 1;  END LOOP;  END IF;

  CLOSE vc_cursor;  EXCEPTION  WHEN OTHERS  THEN  IF vc_cursor%ISOPEN

  THEN  CLOSE vc_cursor;  END IF;

  RAISE;  END;  END IF;

  -- query for serialized item  l_debug_state :=  '005 - Query QOH serialized item data for organization '  || c_inv_org_rec.organization_code;

  v_sql :=  'SELECT /*+ INDEX (msn MTL_SERIAL_NUMBERS_N6)*/  msi.segment1 item_code,  moq.organization_id,  moq.subinventory_code,  msn.serial_number,  1 transaction_quantity,  msiv.availability_type  FROM ss_pc_e_warehouse_data ssp,  mtl_system_items_b msi,

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 28/137

  mtl_onhand_quantities moq,  mtl_secondary_inventories msiv,  mtl_serial_numbers msn  WHERE ssp.qoh_req = ''Y''  AND msi.organization_id = :p_org_id '  ||  --AND msi.inventory_item_id = ssp.inventory_item_id  'AND msi.segment1 = ssp.item_code  AND msi.serial_number_control_code <> 1 -- serialized item  AND moq.inventory_item_id = msi.inventory_item_id  AND moq.organization_id = msi.organization_id  AND msiv.secondary_inventory_name = moq.subinventory_code  AND msiv.organization_id = moq.organization_id  AND msn.current_organization_id = moq.organization_id  AND msn.inventory_item_id = moq.inventory_item_id  AND msn.current_subinventory_code = moq.subinventory_code  AND msn.current_status = 3 -- Resides into store  GROUP BY msi.segment1,  moq.organization_id,  moq.subinventory_code,  msn.serial_number,

  msiv.availability_type';

  OPEN vc_cursor FOR v_sql USING  c_inv_org_rec.organization_id;

  IF vc_cursor%ISOPEN  THEN  BEGIN  l_debug_state :=  '006 - Fetch QOH serialized item data for organization '  || c_inv_org_rec.organization_code;

  FETCH vc_cursor  BULK COLLECT INTO v_item_code  ,v_organization_id  ,v_subinventory_code  ,v_serial_number  ,v_transaction_quantity  ,v_availability_type;

  IF v_item_code.FIRST IS NOT NULL  THEN  FOR i IN 1 .. v_item_code.LAST  LOOP  l_debug_state :=

  '007 - Construct QOH serialized itemdata for organization '  || c_inv_org_rec.organization_code  || ' into data file ';

  IF v_availability_type (i) = 1  THEN  v_net_flag :=  'Y';  ELSE

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 29/137

  v_net_flag :=  'N';  END IF;

  l_file_data :=  '02'  || '|'  || v_organization_id (i)  || '|'  || v_subinventory_code (i)  || '|'  || v_item_code (i)  || '|'  || v_serial_number (i)  || '|'  || v_transaction_quantity (i)  || '|'  || v_net_flag;  l_debug_state :=  '008 - Write QOH serialized item data for organization '  || c_inv_org_rec.organization_code  || ' into data file ';  UTL_FILE.put_line (l_file_handler

  ,l_file_data);  v_cnt :=  v_cnt + 1;  END LOOP;  END IF;

  CLOSE vc_cursor;  EXCEPTION  WHEN OTHERS  THEN  IF vc_cursor%ISOPEN  THEN  CLOSE vc_cursor;

  END IF;

  RAISE;  END;  END IF;--- **** End of Changes for ver 1.1 **** ----  END LOOP;  END LOOP;

  l_debug_state :=  '009 - Write trailer data into data file ';  l_file_trailer :=  '03'

  || '|'  || TO_CHAR (v_cnt)  || '|'  || TO_CHAR (SYSDATE, 'RRRRMMDDHH24MISS');  UTL_FILE.put_line (l_file_handler, l_file_trailer);  UTL_FILE.fclose (l_file_handler);  fnd_file.put_line (fnd_file.output, 'Number of rows ' || v_cnt);  ELSE  fnd_file.put_line (fnd_file.LOG  , 'File :'

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 30/137

  || l_file_name  || ', is not open for writing.');  raise_application_error (-20000  , 'File :'  || l_file_name  || ' is not open for writing.');  END IF;

--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 18 Jun 2008 ---  -- send data file into FXPC server  ss_pc_e_warehouse_iface_k.ss_pc_e_run_ftp_p (l_file_name);--- **** End of Changes for ver 1.1 **** ----  EXCEPTION  WHEN UTL_FILE.invalid_path  THEN  ROLLBACK;  raise_application_error  (-20001  ,'Error while opening the file. Invalid Directory or File name.');  WHEN UTL_FILE.invalid_mode  THEN  ROLLBACK;  raise_application_error

  (-20002  ,'Error while opening the file or checking if file is open. Invalid Mode.');  WHEN UTL_FILE.invalid_operation  THEN  ROLLBACK;  raise_application_error  (-20003  ,'Error while opening the file or writing a new line. Invalid Operation.');  WHEN UTL_FILE.invalid_filehandle  THEN  ROLLBACK;

  raise_application_error  (-20004  ,'Error in checking if file is open or writing a new line. Invalid File Handle.');  WHEN UTL_FILE.write_error  THEN  ROLLBACK;  raise_application_error  (-20005  ,'Error in closing file or writing a new line. OS error duringwrite operation.');  WHEN UTL_FILE.read_error  THEN

  ROLLBACK;  raise_application_error (-20006, 'Error in defining file type.');  WHEN UTL_FILE.internal_error  THEN  ROLLBACK;  raise_application_error (-20007, 'Error in defining file type.');  WHEN OTHERS  THEN  ROLLBACK;  v_error_msg := SUBSTR (SQLERRM

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 31/137

  ,1  ,2000);  fnd_file.put_line (fnd_file.LOG  , 'Error in process :' || l_debug_state);  fnd_file.put_line (fnd_file.LOG, 'Error message :' || v_error_msg);  RAISE;  END ss_pc_e_onhand_qty_p;

/****-- Procedure name : SS_PC_E_OUTSTAND_PO_P-- Purpose : Extract detail PO Outstanding information from ITSS into datafile.-- Parameter :-- - p_org_id -> extracted operating unit id-- - p_file_path -> output directory for generated data file-- HR_Operating_Units Column name Changed on 05-07-2012****/  PROCEDURE ss_pc_e_outstand_po_p (  errbuf OUT VARCHAR2  ,retcode OUT VARCHAR2  ,p_org_id IN VARCHAR2  ,p_file_path IN VARCHAR2)  IS/*

 CURSOR c_inv_org IS  SELECT organization_id ,organization_code,operating_unit  FROM org_organization_Definitions  WHERE disable_date is null  AND legal_entity=p_org_id;

 CURSOR c_inv_item IS  SELECT inventory_item_id,item_code  FROM FXAP.SS_PC_E_WAREHOUSE_DATA  WHERE po_req='Y'  and rownum <20001;*/--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 18 Jun 2008 ---

  CURSOR c_org_id  IS  SELECT hou.organization_id  FROM hr_operating_units hou  ---*** Begin Change for ver 2.1 **** Update by Ni Nyoman Rai on 02Feb 2009 ---  --WHERE hou.legal_entity_id = p_org_id

-- WHERE hou.legal_entity_id IN (SELECT orgid -- Commented CR 264977 by Karthikeyan on 06-Jul-2012 

where hou.default_legal_context_id in (SELECT orgid -- Added CR 2

64977 Karthikeyan on 06-Jul-2012  FROM ss_pc_e_temp_org)  AND TRUNC (SYSDATE) BETWEEN hou.date_from  AND NVL (hou.date_to, SYSDATE);

  ---**** End of Changes for ver 2.1 **** ----  CURSOR c_outstand_po ( 

p_ou_id NUMBER)  IS

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 32/137

  SELECT /*+ LEADING(pol) USE_HASH(ssp)*/  poh.segment1 po_number  ,poh.authorization_status order_status  ,poh.attribute5 po_type  ,poh.vendor_id  ,poh.vendor_site_id  ,poh.agent_id  ,poh.ship_to_location_id  ,poh.creation_date  ,poll.need_by_date  ,poll.promised_date  ,pol.line_num order_line_number  ,pol.item_id  ,poll.line_location_id  ,poll.ship_to_organization_id  ,poll.quantity order_quantity  ,poll.quantity_received received_quantity  ,poll.quantity_cancelled cancelled_quantity  , ( poll.quantity  - (poll.quantity_received + poll.quantity_cancelled) )  outstanding_quantity  ,poh.currency_code currency  ,pol.unit_price purchase_price  ,poll.ship_to_organization_id ship_to_warehouse

  ,poh.attribute9 ship_method  ,pv.vendor_name  ,pvs.vendor_site_code  ,papf.full_name buyer  ,hla.location_code  ,msi.segment1 item_code  ,mp.organization_code  ,pod.destination_subinventory  FROM ss_pc_e_warehouse_data ssp  ,po_headers_all poh  ,po_lines_all pol  ,po_line_locations_all poll  ,po_distributions_all pod

  ,po_vendors pv  ,po_vendor_sites_all pvs  ,per_all_people_f papf  ,hr_locations_all hla  ,mtl_system_items_b msi  ,mtl_parameters mp  WHERE ssp.po_req = 'Y'  AND pol.item_id = ssp.inventory_item_id  AND pol.org_id = p_ou_id  AND poh.po_header_id = pol.po_header_id  AND ( pol.closed_code IS NULL  OR pol.closed_code = 'OPEN')  AND ( pol.cancel_flag IS NULL

  OR pol.cancel_flag = 'N')  AND poll.po_header_id = pol.po_header_id --poh.po_header_id /*william 040510*/  AND poll.po_line_id = pol.po_line_id  AND poll.quantity  - (poll.quantity_received + poll.quantity_cancelled) > 0  AND pod.line_location_id = poll.line_location_id  AND pv.vendor_id = poh.vendor_id  AND pvs.vendor_site_id = poh.vendor_site_id  AND papf.person_id = poh.agent_id

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 33/137

  AND TRUNC (SYSDATE) BETWEEN papf.effective_start_date  AND papf.effective_end_date  AND hla.location_id = poll.ship_to_location_id  AND msi.inventory_item_id = pol.item_id  AND msi.organization_id = poll.ship_to_organization_id  AND mp.organization_id = poll.ship_to_organization_id;

/* original from Senthil  SELECT poh.segment1 Po_number,  poh.authorization_status Order_status,  poh.attribute5 Po_Type,  poh.vendor_id,  poh.vendor_site_id,  poh.agent_id,  poh.ship_to_location_id,  poh.creation_date,  poll.need_by_date,  poll.promised_date,  pol.line_num order_line_number,  pol.item_id,  poll.line_location_id,  poll.ship_to_organization_id,  poll.quantity order_quantity,  poll.quantity_received Received_quantity,

  poll.quantity_cancelled Cancelled_quantity,  (poll.quantity-(poll.quantity_received+poll.quantity_cancelled)) Outstanding_quantity,  poh.currency_code currency,  pol.unit_price Purchase_Price,  poll.ship_to_organization_id Ship_to_Warehouse,  poh.attribute9 ship_method  FROM po_headers_all poh,  po_lines_all pol,  po_line_locations_all poll,  FXAP.SS_PC_E_WAREHOUSE_DATA spw  WHERE pol.item_id = spw.inventory_item_id  AND spw.po_req = 'Y'

  AND (nvl(poh.cancel_flag,'N') <> 'Y' OR nvl(pol.cancel_flag,'N') <> 'Y')  AND (nvl(poh.closed_code,'OPEN') = 'OPEN' OR nvl(pol.closed_code,'OPEN') = 'OPEN')  AND poh.po_header_id = pol.po_header_id  AND poh.org_id = pol.org_id  AND pol.po_header_id = poll.po_header_id  AND pol.po_line_id = poll.po_line_id  AND pol.org_id = poll.org_id  AND poll.quantity-(poll.quantity_received+poll.quantity_cancelled) > 0;*/  l_file_name VARCHAR2 (100)  := 'FXPC_ITSSLIVE_PO.dat';  l_file_handler UTL_FILE.file_type;

  v_error_msg VARCHAR2 (2000);  l_debug_state VARCHAR2 (2000);  l_file_heading VARCHAR2 (100);  l_file_trailer VARCHAR2 (100);  l_file_data VARCHAR2 (32767);  v_cnt NUMBER := 0;

  TYPE po_number_tab IS TABLE OF po_headers_all.segment1%TYPE;

  TYPE order_status_tab IS TABLE OF po_headers_all.authorization_status%TY

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 34/137

PE;

  TYPE po_type_tab IS TABLE OF po_headers_all.attribute5%TYPE;

  TYPE vendor_id_tab IS TABLE OF po_headers_all.vendor_id%TYPE;

  TYPE vendor_site_id_tab IS TABLE OF po_headers_all.vendor_site_id%TYPE;

  TYPE agent_id_tab IS TABLE OF po_headers_all.agent_id%TYPE;

  TYPE ship_to_location_id_tab IS TABLE OF po_headers_all.ship_to_location _id%TYPE;

  TYPE creation_date_tab IS TABLE OF po_headers_all.creation_date%TYPE;

  TYPE need_by_date_tab IS TABLE OF po_line_locations_all.need_by_date%TYPE;

  TYPE promised_date_tab IS TABLE OF po_line_locations_all.promised_date%TYPE;

  TYPE order_line_number_tab IS TABLE OF po_lines_all.line_num%TYPE;

  TYPE item_id_tab IS TABLE OF po_lines_all.item_id%TYPE;

  TYPE line_location_id_tab IS TABLE OF po_line_locations_all.line_location_id%TYPE;

  TYPE ship_to_organization_id_tab IS TABLE OF po_line_locations_all.ship_ to_organization_id%TYPE;

  TYPE order_quantity_tab IS TABLE OF po_line_locations_all.quantity%TYPE;

  TYPE received_quantity_tab IS TABLE OF po_line_locations_all.quantity_received%TYPE;

  TYPE cancelled_quantity_tab IS TABLE OF po_line_locations_all.quantity_c

ancelled%TYPE;

  TYPE outstanding_quantity_tab IS TABLE OF po_line_locations_all.quantity _received%TYPE;

  TYPE currency_tab IS TABLE OF po_headers_all.currency_code%TYPE;

  TYPE purchase_price_tab IS TABLE OF po_lines_all.unit_price%TYPE;

  TYPE ship_to_warehouse_tab IS TABLE OF po_line_locations_all.ship_to_organization_id%TYPE;

  TYPE ship_method_tab IS TABLE OF po_headers_all.attribute9%TYPE;

  TYPE vendor_name_tab IS TABLE OF po_vendors.vendor_name%TYPE;

  TYPE vendor_site_code_tab IS TABLE OF po_vendor_sites.vendor_site_code%TYPE;

  TYPE buyer_tab IS TABLE OF per_all_people_f.full_name%TYPE;

  TYPE location_code_tab IS TABLE OF hr_locations_all.location_code%TYPE;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 35/137

  TYPE item_code_tab IS TABLE OF mtl_system_items_b.segment1%TYPE;

  TYPE organization_code_tab IS TABLE OF mtl_parameters.organization_code%TYPE;

  TYPE destination_subinventory_tab IS TABLE OF po_distributions_all.destination_subinventory%TYPE;

  v_po_number po_number_tab;  v_order_status order_status_tab;  v_po_type po_type_tab;  v_vendor_id vendor_id_tab;  v_vendor_site_id vendor_site_id_tab;  v_agent_id agent_id_tab;  v_ship_to_location_id ship_to_location_id_tab;  v_creation_date creation_date_tab;  v_need_by_date need_by_date_tab;  v_promised_date promised_date_tab;  v_order_line_number order_line_number_tab;  v_item_id item_id_tab;  v_line_location_id line_location_id_tab;  v_ship_to_organization_id ship_to_organization_id_tab;  v_order_quantity order_quantity_tab;  v_received_quantity received_quantity_tab;

  v_cancelled_quantity cancelled_quantity_tab;  v_outstanding_quantity outstanding_quantity_tab;  v_currency currency_tab;  v_purchase_price purchase_price_tab;  v_ship_to_warehouse ship_to_warehouse_tab;  v_ship_method ship_method_tab;  v_vendor_name vendor_name_tab;  v_vendor_site_code vendor_site_code_tab;  v_buyer buyer_tab;  v_location_code location_code_tab;  v_item_code item_code_tab;  v_organization_code organization_code_tab;  v_destination_subinventory destination_subinventory_tab;

--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 18 Jun 2008 ---/*  File_Close Exception;  l_file_rec1 VARCHAR2(100);  l_file_rec2 VARCHAR2(100);  l_file_rec VARCHAR2(32767);  l_Err_Num NUMBER;  l_Err_Msg VARCHAR2(1000);  cnt NUMBER := 0;  l_vendor_name VARCHAR2(80);  l_vendor_site_code VARCHAR2(15);  l_buyer VARCHAR2(240);  l_location_code VARCHAR2(80);

  l_item_code VARCHAR2(30);  l_subinventry VARCHAR2(30);  l_organization_code VARCHAR2(3);*/--- **** End of Changes for ver 1.1 **** ----  BEGIN  ---*** Begin Change for ver 2.1 **** Update by Ni Nyoman Rai on 29 Jan 2009 ---  ss_pc_e_insorg (p_org_id);  ---**** End of Changes for ver 2.1 **** ----

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 36/137

  l_debug_state :=  '000 - Open FXPC_ITSSLIVE_PO.dat file for writing';  l_file_handler :=  UTL_FILE.fopen (p_file_path  ,l_file_name  ,'W'  ,32767);

  IF UTL_FILE.is_open (l_file_handler)  THEN  l_debug_state :=  '001 - Write header into data file';  l_file_heading :=  '01'  || '|'  || 'PO'  || '|'  || TO_CHAR (SYSDATE, 'RRRRMMDDHH24MISS');  UTL_FILE.put_line (l_file_handler, l_file_heading);

--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 18 Jun 2008 ---/*  -- FOR c_inv_org_rec IN c_inv_org LOOP  --FOR c_inv_item_rec IN c_inv_item LOOP

  FOR c_po IN c_outstand_po LOOP  BEGIN  SELECT vendor_name  INTO l_vendor_name  FROM po_vendors  WHERE vendor_id=c_outstand_po_rec.vendor_id;  EXCEPTION  WHEN NO_DATA_FOUND then  l_vendor_name :=null;  WHEN OTHERS then  l_vendor_name :=null;  END;

  BEGIN  SELECT vendor_site_code  INTO l_vendor_site_code  FROM po_vendor_sites_all  WHERE vendor_site_id=c_outstand_po_rec.vendor_site_id;  EXCEPTION  WHEN NO_DATA_FOUND then  l_vendor_site_code :=null;  WHEN OTHERS then  l_vendor_site_code :=null;  END;  BEGIN  SELECT full_name

  INTO l_buyer  FROM hr_employees  WHERE employee_id=c_outstand_po_rec.agent_id;  EXCEPTION  WHEN NO_DATA_FOUND then  l_buyer :=null;  WHEN OTHERS then  l_buyer :=null;  END;  BEGIN

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 37/137

  SELECT location_code  INTO l_location_code  FROM hr_locations_all  WHERE location_id=c_outstand_po_rec.ship_to_location_id;  EXCEPTION  WHEN NO_DATA_FOUND then  l_location_code :=null;  WHEN OTHERS then  l_location_code :=null;  END;

  BEGIN  SELECT segment1  INTO l_item_code  FROM mtl_system_items_b  WHERE inventory_item_id=c_outstand_po_rec.item_id  and organization_id=c_outstand_po_rec.ship_to_organization_id;  EXCEPTION  WHEN NO_DATA_FOUND then  l_item_code:=null;  WHEN OTHERS then  l_item_code :=null;  END;  BEGIN

  select organization_code  into l_organization_code  from org_organization_definitions  where organization_id=c_outstand_po_rec.ship_to_organization_id;  EXCEPTION  WHEN NO_DATA_FOUND then  l_organization_code :=null;  WHEN OTHERS then  l_organization_code :=null;  END;

  BEGIN  SELECT destination_subinventory

  INTO l_subinventry  FROM po_distributions_all ps  WHERE ps.line_location_id=c_outstand_po_rec.line_location_id;  EXCEPTION  WHEN NO_DATA_FOUND then  l_subinventry :=null;  WHEN OTHERS then  l_subinventry :=null;

  END;

  l_file_rec :='02'||'|'||l_organization_code||'|'||c_outstand_po_rec.po_number||'|'||c_outstand_po_rec.order_status||'|'||

  c_outstand_po_rec.po_type||'|'||l_vendor_name||'|'||l_ vendor_site_code||'|'||  c_outstand_po_rec.creation_date||'|'||c_outstand_po_rec.need_by_date||'|'||  c_outstand_po_rec.promised_date||'|'||l_buyer||'|'||  c_outstand_po_rec.order_line_number||'|'||l_item_code||'|'||  c_outstand_po_rec.Order_quantity||'|'||c_outstand_po_rec.Received_quantity||'|'||  c_outstand_po_rec.Cancelled_quantity||'|'||c_outstand_ 

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 38/137

po_rec.Outstanding_quantity||'|'||  c_outstand_po_rec.currency||'|'||c_outstand_po_rec.Purchase_price||'|'||  l_subinventry||'|'||l_location_code||'|'||c_outstand_po_rec.ship_method;

  Utl_File.put_line(l_file_handler,l_file_rec);  cnt := cnt +1;  END LOOP;  --END LOOP;  -- END LOOP;*/  FOR vc_org IN c_org_id  LOOP  OPEN c_outstand_po (vc_org.organization_id);

  IF c_outstand_po%ISOPEN  THEN  BEGIN  l_debug_state :=  '002 - Fetch PO oustanding data ';

  FETCH c_outstand_po  BULK COLLECT INTO v_po_number

  ,v_order_status  ,v_po_type  ,v_vendor_id  ,v_vendor_site_id  ,v_agent_id  ,v_ship_to_location_id  ,v_creation_date  ,v_need_by_date  ,v_promised_date  ,v_order_line_number  ,v_item_id  ,v_line_location_id  ,v_ship_to_organization_id

  ,v_order_quantity  ,v_received_quantity  ,v_cancelled_quantity  ,v_outstanding_quantity  ,v_currency  ,v_purchase_price  ,v_ship_to_warehouse  ,v_ship_method  ,v_vendor_name  ,v_vendor_site_code  ,v_buyer  ,v_location_code  ,v_item_code

  ,v_organization_code  ,v_destination_subinventory;

  IF v_po_number.FIRST IS NOT NULL  THEN  FOR i IN 1 .. v_po_number.LAST  LOOP  l_debug_state :=  '003 - Construct PO outstanding data into variable ';

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 39/137

  l_file_data :=  '02'  || '|'  || v_organization_code (i)  || '|'  || v_po_number (i)  || '|'  || v_order_status (i)  || '|'  || v_po_type (i)  || '|'  || v_vendor_name (i)  || '|'  || v_vendor_site_code (i)  || '|'  || v_creation_date (i)  || '|'  || v_need_by_date (i)  || '|'  || v_promised_date (i)  || '|'  || v_buyer (i)  || '|'  || v_order_line_number (i)

  || '|'  || v_item_code (i)  || '|'  || v_order_quantity (i)  || '|'  || v_received_quantity (i)  || '|'  || v_cancelled_quantity (i)  || '|'  || v_outstanding_quantity (i)  || '|'  || v_currency (i)  || '|'

  || v_purchase_price (i)  || '|'  || v_destination_subinventory (i)  || '|'  || v_location_code (i)  || '|'  || v_ship_method (i);  l_debug_state :=  '004 - Write PO oustanding data into data file ';  UTL_FILE.put_line (l_file_handler  ,l_file_data);  v_cnt := v_cnt + 1;

  END LOOP;  END IF;

  CLOSE c_outstand_po;  EXCEPTION  WHEN OTHERS  THEN  IF c_outstand_po%ISOPEN  THEN  CLOSE c_outstand_po;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 40/137

  END IF;

  RAISE;  END;  END IF;  END LOOP;

--- **** End of Changes for ver 1.1 **** ----  l_debug_state :=  '005 - Write trailer data into data file ';  l_file_trailer :=  '03'  || '|'  || TO_CHAR (v_cnt)  || '|'  || TO_CHAR (SYSDATE, 'RRRRMMDDHH24MISS');  UTL_FILE.put_line (l_file_handler, l_file_trailer);  UTL_FILE.fclose (l_file_handler);  fnd_file.put_line (fnd_file.output, 'Number of rows ' || v_cnt);  ELSE  fnd_file.put_line (fnd_file.LOG  , 'File :'  || l_file_name  || ', is not open for writing.');

  raise_application_error (-20000  , 'File :'  || l_file_name  || ' is not open for writing.');  END IF;

--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 18 Jun 2008 ---  -- send data file into FXPC server  ss_pc_e_warehouse_iface_k.ss_pc_e_run_ftp_p (l_file_name);--- **** End of Changes for ver 1.1 **** ----  EXCEPTION  WHEN UTL_FILE.invalid_path  THEN

  ROLLBACK;  raise_application_error  (-20001  ,'Error while opening the file. Invalid Directory or File name.');  WHEN UTL_FILE.invalid_mode  THEN  ROLLBACK;  raise_application_error  (-20002  ,'Error while opening the file or checking if file is open. Invalid Mode.');  WHEN UTL_FILE.invalid_operation

  THEN  ROLLBACK;  raise_application_error  (-20003  ,'Error while opening the file or writing a new line. Invalid Operation.');  WHEN UTL_FILE.invalid_filehandle  THEN  ROLLBACK;  raise_application_error

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 41/137

  (-20004  ,'Error in checking if file is open or writing a new line. Invalid File Handle.');  WHEN UTL_FILE.write_error  THEN  ROLLBACK;  raise_application_error  (-20005  ,'Error in closing file or writing a new line. OS error duringwrite operation.');  WHEN UTL_FILE.read_error  THEN  ROLLBACK;  raise_application_error (-20006, 'Error in defining file type.');  WHEN UTL_FILE.internal_error  THEN  ROLLBACK;  raise_application_error (-20007, 'Error in defining file type.');  WHEN OTHERS  THEN  ROLLBACK;  v_error_msg := SUBSTR (SQLERRM  ,1  ,2000);

  fnd_file.put_line (fnd_file.LOG  , 'Error in process :' || l_debug_state);  fnd_file.put_line (fnd_file.LOG, 'Error message :' || v_error_msg);  RAISE;  END ss_pc_e_outstand_po_p;

/****-- Procedure name : SS_PC_E_PO_RECEIPT_P-- Purpose : Extract PO receiving information from ITSS into data file.-- Parameter :-- - p_org_id -> extracted legal entity id-- - p_file_path -> output directory for generated data file-- - p_no_of_days -> number of days

****/  PROCEDURE ss_pc_e_po_receipt_p (  errbuf OUT VARCHAR2  ,retcode OUT VARCHAR2  ,p_org_id IN VARCHAR2  ,p_file_path IN VARCHAR2  ,p_no_of_days IN NUMBER)  IS/*  CURSOR c_inv_org IS  SELECT organization_id ,organization_code,operating_unit  FROM org_organization_Definitions  WHERE disable_date is null

  AND legal_entity=p_org_id;

  CURSOR c_inv_item IS  SELECT inventory_item_id,item_code  FROM FXAP.SS_PC_E_WAREHOUSE_DATA  WHERE po_receipt_req='Y'  and rownum <20001;*/

  --- *** Begin Change for ver 1.1 **** Update by Willy Tan on 18 Jun 2008

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 42/137

 ---  l_file_name VARCHAR2 (100)  := 'FXPC_ITSSLIVE_PO_RECEIPT.dat';  l_file_handler UTL_FILE.file_type;  v_error_msg VARCHAR2 (2000);  l_debug_state VARCHAR2 (2000);  l_file_heading VARCHAR2 (100);  l_file_trailer VARCHAR2 (100);  l_file_data VARCHAR2 (32767);  v_cnt NUMBER := 0;  v_no_of_days NUMBER;

  TYPE organization_code_tab IS TABLE OF mtl_parameters.organization_code%TYPE;

  TYPE vendor_name_tab IS TABLE OF po_vendors.vendor_name%TYPE;

  TYPE vendor_site_code_tab IS TABLE OF po_vendor_sites_all.vendor_site_code%TYPE;

  TYPE order_status_tab IS TABLE OF po_headers_all.authorization_status%TYPE;

  TYPE po_type_tab IS TABLE OF po_headers_all.attribute5%TYPE;

  TYPE buyer_tab IS TABLE OF per_all_people_f.full_name%TYPE;

  TYPE po_number_tab IS TABLE OF po_headers_all.segment1%TYPE;

  TYPE creation_date_tab IS TABLE OF po_headers_all.creation_date%TYPE;

  TYPE order_line_number_tab IS TABLE OF po_lines_all.line_num%TYPE;

  TYPE currency_tab IS TABLE OF po_headers_all.currency_code%TYPE;

  TYPE unit_price_tab IS TABLE OF po_lines_all.unit_price%TYPE;

  TYPE item_code_tab IS TABLE OF mtl_system_items_b.segment1%TYPE;

  TYPE received_date_tab IS TABLE OF rcv_transactions.transaction_date%TYPE;

  TYPE promised_date_tab IS TABLE OF po_line_locations_all.promised_date%TYPE;

  TYPE need_by_date_tab IS TABLE OF po_line_locations_all.need_by_date%TYPE;

  TYPE quantity_tab IS TABLE OF po_line_locations_all.quantity%TYPE;

  TYPE received_quantity_tab IS TABLE OF po_line_locations_all.quantity_received%TYPE;

  TYPE cancelled_quantity_tab IS TABLE OF NUMBER;

  TYPE ship_method_tab IS TABLE OF po_headers_all.attribute9%TYPE;

  TYPE location_code_tab IS TABLE OF hr_locations_all.location_code%TYPE;

  TYPE subinventory_tab IS TABLE OF rcv_transactions.subinventory%TYPE;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 43/137

  TYPE cancelled_date_tab IS TABLE OF DATE;

  v_organization_code organization_code_tab;  v_vendor_name vendor_name_tab;  v_vendor_site_code vendor_site_code_tab;  v_order_status order_status_tab;  v_po_type po_type_tab;  v_buyer buyer_tab;  v_po_number po_number_tab;  v_creation_date creation_date_tab;  v_order_line_number order_line_number_tab;  v_currency currency_tab;  v_unit_price unit_price_tab;  v_item_code item_code_tab;  v_received_date received_date_tab;  v_promised_date promised_date_tab;  v_need_by_date need_by_date_tab;  v_quantity quantity_tab;  v_received_quantity received_quantity_tab;  v_cancelled_quantity cancelled_quantity_tab;  v_ship_method ship_method_tab;  v_location_code location_code_tab;  v_subinventory subinventory_tab;

  v_cancelled_date cancelled_date_tab;

  CURSOR c_org_id  IS  SELECT hou.organization_id  FROM hr_operating_units hou  ---*** Begin Change for ver 2.1 **** Update by Ni Nyoman Rai on 02Feb 2009 --- 

--WHERE hou.legal_entity_id IN (SELECT orgid -- Commented CR 264977 by Karthikeyan on 06-Jul-2012 

where hou.default_legal_context_id IN (SELECT orgid -- Added CR 264

977 by Karthikeyan on 06-Jul-2012  FROM ss_pc_e_temp_org)  -- WHERE hou.legal_entity_id = p_org_id  ---**** End of Changes for ver 2.1 **** ----  AND TRUNC (SYSDATE) BETWEEN hou.date_from  AND NVL (hou.date_to, SYSDATE);

  CURSOR c_po_receipt (  p_ou_id NUMBER  ,p_num_days NUMBER)  IS  -- query PO that has partial receive (including cancel PO with partial receive) or fully received

  SELECT /*+ LEADING(rt) USE_HASH(spw) */  mp.organization_code  ,pv.vendor_name  ,pvs.vendor_site_code  ,poh.authorization_status order_status  ,poh.attribute5 po_type  ,papf.full_name buyer  ,poh.segment1 po_number  ,poh.creation_date  ,pol.line_num order_line_number

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 44/137

  ,poh.currency_code currency  ,pol.unit_price  ,msi.segment1 item_code  ,rt.transaction_date received_date  ,poll.promised_date  ,poll.need_by_date  ,poll.quantity  ,SUM (mmt.transaction_quantity) received_quantity  ,0 cancelled_quantity  ,poh.attribute9 ship_method  ,hla.location_code  ,mmt.subinventory_code subinventory  ,NULL cancelled_date  FROM ss_pc_e_warehouse_data spw  ,po_lines_all pol  ,po_headers_all poh  ,po_line_locations_all poll  ,po_distributions_all pod  ,mtl_material_transactions mmt  ,rcv_transactions rt  ,po_vendors pv  ,po_vendor_sites_all pvs  ,per_all_people_f papf  ,mtl_system_items_b msi

  ,mtl_parameters mp  ,hr_locations_all hla  WHERE spw.po_receipt_req = 'Y'  AND pol.item_id = spw.inventory_item_id  AND pol.org_id = p_ou_id  AND poh.po_header_id = pol.po_header_id  AND poll.po_header_id = poh.po_header_id  AND poll.po_line_id = pol.po_line_id  AND pod.line_location_id = poll.line_location_id  AND mmt.inventory_item_id = spw.inventory_item_id  AND mmt.transaction_date BETWEEN (TRUNC (SYSDATE)  - p_num_days)  AND SYSDATE

  AND mmt.rcv_transaction_id = rt.transaction_id  AND rt.source_document_code = 'PO'  AND rt.po_line_location_id = poll.line_location_id  AND rt.po_header_id = poh.po_header_id  AND rt.po_line_id = pol.po_line_id  AND rt.destination_type_code = 'INVENTORY' /*William 040510 add for tuning purpose*/  AND rt.transaction_type IN  ('DELIVER', 'CORRECT', 'RETURN TO RECEIVING')  AND rt.transaction_date BETWEEN (TRUNC (SYSDATE) - p_num_days)  AND SYSDATE  AND rt.organization_id = poll.ship_to_organization_id  AND pv.vendor_id = poh.vendor_id

  AND pvs.vendor_site_id = poh.vendor_site_id  AND papf.person_id = poh.agent_id  AND TRUNC (SYSDATE) BETWEEN papf.effective_start_date  AND papf.effective_end_date  AND msi.inventory_item_id = pol.item_id  AND msi.organization_id = poll.ship_to_organization_id  AND mp.organization_id = poll.ship_to_organization_id  AND hla.location_id = poll.ship_to_location_id  GROUP BY mp.organization_code  ,pv.vendor_name

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 45/137

  ,pvs.vendor_site_code  ,poh.authorization_status  ,poh.attribute5  ,papf.full_name  ,poh.segment1  ,poh.creation_date  ,pol.line_num  ,poh.currency_code  ,pol.unit_price  ,msi.segment1  ,rt.transaction_date  ,poll.promised_date  ,poll.need_by_date  ,poll.quantity  ,poh.attribute9  ,hla.location_code  ,mmt.subinventory_code;

  CURSOR c_po_cancel (  p_ou_id NUMBER  ,p_num_days NUMBER)  IS  -- query cancel PO  SELECT /*+ LEADING(poll) USE_HASH(spw)*/

  mp.organization_code  ,pv.vendor_name  ,pvs.vendor_site_code  ,poh.authorization_status order_status  ,poh.attribute5 po_type  ,papf.full_name buyer  ,poh.segment1 po_number  ,poh.creation_date  ,pol.line_num order_line_number  ,poh.currency_code currency  ,pol.unit_price  ,msi.segment1 item_code  ,NULL received_date

  ,poll.promised_date  ,poll.need_by_date  ,poll.quantity  ,0 received_quantity  ,poll.quantity_cancelled cancelled_quantity  ,poh.attribute9 ship_method  ,hla.location_code  ,NULL subinventory  ,NVL (poll.cancel_date, poll.last_update_date)  cancelled_date  FROM ss_pc_e_warehouse_data spw  ,po_lines_all pol  ,po_headers_all poh

  ,po_line_locations_all poll  ,po_vendors pv  ,po_vendor_sites_all pvs  ,per_all_people_f papf  ,mtl_system_items_b msi  ,mtl_parameters mp  ,hr_locations_all hla  WHERE spw.po_receipt_req = 'Y'  AND pol.item_id = spw.inventory_item_id  AND pol.org_id = p_ou_id

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 46/137

  AND poh.po_header_id = pol.po_header_id  AND poll.po_header_id = poh.po_header_id  AND poll.po_line_id = pol.po_line_id  AND poll.cancel_flag = 'Y'  AND poll.quantity_cancelled > 0  AND NVL (poll.cancel_date, poll.last_update_date)  BETWEEN (TRUNC (SYSDATE) - p_num_days)  AND SYSDATE  AND pv.vendor_id = poh.vendor_id  AND pvs.vendor_site_id = poh.vendor_site_id  AND papf.person_id = poh.agent_id  AND TRUNC (SYSDATE) BETWEEN papf.effective_start_date  AND papf.effective_end_date  AND msi.inventory_item_id = pol.item_id  AND msi.organization_id = poll.ship_to_organization_id  AND mp.organization_id = poll.ship_to_organization_id  AND hla.location_id = poll.ship_to_location_id;/* Original from Senthil  CURSOR c_po_receipt_detail IS  SELECT \*+ leading(rt) *\ poh.vendor_id,  poh.vendor_site_id,  poh.authorization_status Order_status,  poh.attribute5 Po_Type,  poh.agent_id,

  poh.ship_to_location_id,  poh.segment1 Po_number,  poh.creation_date,  pol.line_num Order_line_number,  poh.currency_code currency,  pol.unit_price,  pol.item_id,  poll.ship_to_organization_id,  rt.transaction_date Received_date,  poll.promised_date,  poll.need_by_date,  poll.line_location_id,  sum(poll.quantity) quantity,

  sum(poll.quantity_received) Received_quantity,  0 Cancelled_quantity,  poh.attribute9 ship_method,  poll.ship_to_organization_id Ship_to_Warehouse,  rt.subinventory,  null cancelled_date  FROM po_headers_all poh,  po_lines_all pol,  po_line_locations_all poll,  rcv_transactions rt,  FXAP.SS_PC_E_WAREHOUSE_DATA spw  WHERE pol.item_id=spw.inventory_item_id  and spw.po_receipt_req='Y'

  --and poll.ship_to_organization_id=p_organization_id  --and poh.org_id=p_opco_id  and (nvl(poh.cancel_flag,'N') <> 'Y' OR nvl(pol.cancel_flag,'N') <>'Y')  and poh.po_header_id=pol.po_header_id  and poh.org_id=pol.org_id  and pol.po_header_id =poll.po_header_id  and pol.po_line_id = poll.po_line_id  and pol.org_id=poll.org_id  and pol.po_header_id =poll.po_header_id

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 47/137

  and pol.po_line_id = poll.po_line_id  and poll.line_location_id=rt.po_line_location_id  and rt.transaction_type='RECEIVE'  and rt.transaction_date between (trunc(sysdate)-(p_no_of_days)) and trunc(sysdate)  GROUP BY poh.vendor_id,  poh.vendor_site_id,  poh.authorization_status,  poh.attribute5,  poh.agent_id,  poh.ship_to_location_id,  poh.segment1,  poh.creation_date,  pol.line_num,  poh.currency_code,  pol.unit_price,  pol.item_id,  poll.ship_to_organization_id,  rt.transaction_date ,  poll.promised_date,  poll.need_by_date,  poll.line_location_id,  poh.attribute9,  poll.ship_to_organization_id,

  rt.subinventory  UNION ALL  SELECT poh.vendor_id,  poh.vendor_site_id,  poh.authorization_status Order_status,  poh.attribute5 Po_Type,  poh.agent_id,  poh.ship_to_location_id,  poh.segment1 Po_number,  poh.creation_date,  pol.line_num Order_line_number,  poh.currency_code currency,  pol.unit_price,

  pol.item_id,  poll.ship_to_organization_id,  null Received_date,  poll.promised_date,  poll.need_by_date,  poll.line_location_id,  sum(poll.quantity) quantity,  0 Received_quantity,  sum(poll.quantity_cancelled) Cancelled_quantity,  poh.attribute9 ship_method,  poll.ship_to_organization_id Ship_to_Warehouse,  to_char(NULL) subinventory,  poll.cancel_date cancelled_date

  FROM po_headers_all poh,  po_lines_all pol,  po_line_locations_all poll,  FXAP.SS_PC_E_WAREHOUSE_DATA spw  WHERE pol.item_id=spw.inventory_item_id  and spw.po_receipt_req='Y'  --and poll.ship_to_organization_id=p_organization_id  -- and poh.org_id=p_opco_id  and (nvl(poh.cancel_flag,'N') = 'Y' OR nvl(pol.cancel_flag,'N') = 'Y')

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 48/137

  and poh.po_header_id = pol.po_header_id  and poh.org_id=pol.org_id  and pol.po_header_id = poll.po_header_id  and pol.po_line_id = poll.po_line_id  and pol.org_id=poll.org_id  and trunc(poll.cancel_date) between (trunc(sysdate)-(p_no_of_days)) and trunc(sysdate)  and poll.quantity_cancelled > 0  GROUP BY poh.vendor_id,  poh.vendor_site_id,  poh.authorization_status,  poh.attribute5,  poh.agent_id,  poh.ship_to_location_id,  poh.segment1,  poh.creation_date,  pol.line_num,  poh.currency_code,  pol.unit_price,  pol.item_id,  poll.ship_to_organization_id,  poll.promised_date,  poll.need_by_date,  poll.line_location_id,

  poh.attribute9,  poll.ship_to_organization_id,  poll.cancel_date;

  File_Close Exception;  l_file_rec1 VARCHAR2(100);  l_file_rec2 VARCHAR2(100);  l_file_rec VARCHAR2(32767);  l_Err_Num NUMBER;  l_Err_Msg VARCHAR2(1000);  cnt NUMBER := 0;  l_vendor_name VARCHAR2(80);  l_vendor_site_code VARCHAR2(15);

  l_buyer VARCHAR2(240);  l_location_code VARCHAR2(80);  l_item_code VARCHAR2(30);  l_subinventry VARCHAR2(30);  l_organization_code VARCHAR2(3);*/--- **** End of Changes for ver 1.1 **** ----  BEGIN  ---*** Begin Change for ver 2.1 **** Update by Ni Nyoman Rai on 29 Jan 2009 ---  ss_pc_e_insorg (p_org_id);  ---**** End of Changes for ver 2.1 **** ----  l_debug_state :=

  '000 - Open FXPC_ITSSLIVE_PO_RECEIPT.dat file for writing';  l_file_handler :=  UTL_FILE.fopen (p_file_path  ,l_file_name  ,'W'  ,32767);

  -- get no of days  IF p_no_of_days IS NULL  THEN

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 49/137

  BEGIN  SELECT NVL (nof_days, 0)  INTO v_no_of_days  FROM ss_pc_e_wh_data_parameters  WHERE interface_type = 'RECEIPTREQ';  EXCEPTION  WHEN OTHERS  THEN  v_no_of_days := NULL;  END;  ELSE  v_no_of_days := p_no_of_days;  END IF;

  fnd_file.put_line (fnd_file.LOG, 'Number of days :' || v_no_of_days);

  IF UTL_FILE.is_open (l_file_handler)  THEN  l_debug_state :=  '001 - Write header into data file';  l_file_heading :=  '01'  || '|'  || 'PO RECEIPT'

  || '|'  || TO_CHAR (SYSDATE, 'RRRRMMDDHH24MISS');  UTL_FILE.put_line (l_file_handler, l_file_heading);

--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 18 Jun 2008 ---/*  -- FOR c_inv_org_rec IN c_inv_org LOOP  -- FOR c_inv_item_rec IN c_inv_item LOOP  FOR c_po_receipt IN c_po_receipt_detail LOOP  BEGIN  SELECT vendor_name  INTO l_vendor_name  FROM po_vendors

  WHERE vendor_id=c_po_receipt_detail_rec.vendor_id;  EXCEPTION  WHEN NO_DATA_FOUND then  l_vendor_name :=null;  WHEN OTHERS then  l_vendor_name :=null;  END;

  BEGIN  SELECT vendor_site_code  INTO l_vendor_site_code  FROM po_vendor_sites_all  WHERE vendor_site_id=c_po_receipt_detail_rec.vendor_site_id;

  EXCEPTION  WHEN NO_DATA_FOUND then  l_vendor_site_code :=null;  WHEN OTHERS then  l_vendor_site_code :=null;  END;  BEGIN  SELECT full_name  INTO l_buyer  FROM hr_employees

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 50/137

  WHERE employee_id=c_po_receipt_detail_rec.agent_id;  EXCEPTION  WHEN NO_DATA_FOUND then  l_buyer :=null;  WHEN OTHERS then  l_buyer :=null;  END;  BEGIN  SELECT location_code  INTO l_location_code  FROM hr_locations_all  WHERE location_id=c_po_receipt_detail_rec.ship_to_location_id;  EXCEPTION  WHEN NO_DATA_FOUND then  l_location_code :=null;  WHEN OTHERS then  l_location_code :=null;  END;

  BEGIN  SELECT segment1  INTO l_item_code  FROM mtl_system_items_b  WHERE inventory_item_id=c_po_receipt_detail_rec.item_id

  and organization_id=c_po_receipt_detail_rec.ship_to_organization_id;  EXCEPTION  WHEN NO_DATA_FOUND then  l_item_code:=null;  WHEN OTHERS then  l_item_code :=null;  END;

  BEGIN  select organization_code  into l_organization_code  from org_organization_definitions

  where organization_id=c_po_receipt_detail_rec.ship_to_organization_id;  EXCEPTION  WHEN NO_DATA_FOUND then  l_organization_code :=null;  WHEN OTHERS then  l_organization_code :=null;  END;

  IF c_po_receipt_detail_rec.subinventory is null then  BEGIN  SELECT destination_subinventory  INTO l_subinventry

  FROM po_distributions_all ps  WHERE ps.line_location_id=c_po_receipt_detail_rec.line_location_id;  EXCEPTION  WHEN NO_DATA_FOUND then  l_subinventry :=null;  WHEN OTHERS then  l_subinventry :=null;

  END;  END IF;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 51/137

  l_file_rec :='02'||'|'||l_organization_code||'|'||l_vendor_name||'|'||l _vendor_site_code||'|'||c_po_receipt_detail_rec.order_status||'|'||  c_po_receipt_detail_rec.po_type||'|'||l_buyer||'|'||  c_po_receipt_detail_rec.po_number||'|'||c_po_receipt_detail_rec.creation_date||'|'||  c_po_receipt_detail_rec.Order_line_number||'|'||c_po_receipt_detail_rec.currency||'|'||  c_po_receipt_detail_rec.unit_price||'|'||l_item_code||'|'||c_po_receipt_detail_rec.Received_date||'|'||  c_po_receipt_detail_rec.Promised_date||'|'||c_po_receipt_detail_rec.Need_by_date||'|'||c_po_receipt_detail_rec.quantity||'|'||  c_po_receipt_detail_rec.Received_quantity||'|'||c_po_receipt_detail_rec.Cancelled_quantity||'|'||  c_po_receipt_detail_rec.ship_method||'|'||  l_location_code||'|'||nvl(c_po_receipt_detail_rec.subinventory,l_subinventry)||'|'||c_po_receipt_detail_rec.cancelled_date;

  Utl_File.put_line(l_file_handler,l_file_rec);  cnt := cnt +1;  -- END LOOP;  -- END LOOP;  END LOOP;*/

  FOR vc_org IN c_org_id  LOOP  -- query PO that has partial receive (including cancel PO with partial receive) or fully received  OPEN c_po_receipt (vc_org.organization_id, v_no_of_days);

  IF c_po_receipt%ISOPEN  THEN  BEGIN  l_debug_state :=  '002 - Fetch PO receipt data ';

  FETCH c_po_receipt

  BULK COLLECT INTO v_organization_code  ,v_vendor_name  ,v_vendor_site_code  ,v_order_status  ,v_po_type  ,v_buyer  ,v_po_number  ,v_creation_date  ,v_order_line_number  ,v_currency  ,v_unit_price  ,v_item_code  ,v_received_date

  ,v_promised_date  ,v_need_by_date  ,v_quantity  ,v_received_quantity  ,v_cancelled_quantity  ,v_ship_method  ,v_location_code  ,v_subinventory  ,v_cancelled_date;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 52/137

  IF v_po_number.FIRST IS NOT NULL  THEN  FOR i IN 1 .. v_po_number.LAST  LOOP  l_debug_state :=  '003 - Construct PO receipt data into variable ';  l_file_data :=  '02'  || '|'  || v_organization_code (i)  || '|'  || v_vendor_name (i)  || '|'  || v_vendor_site_code (i)  || '|'  || v_order_status (i)  || '|'  || v_po_type (i)  || '|'  || v_buyer (i)  || '|'  || v_po_number (i)  || '|'

  || v_creation_date (i)  || '|'  || v_order_line_number (i)  || '|'  || v_currency (i)  || '|'  || v_unit_price (i)  || '|'  || v_item_code (i)  || '|'  || v_received_date (i)  || '|'  || v_promised_date (i)

  || '|'  || v_need_by_date (i)  || '|'  || v_quantity (i)  || '|'  || v_received_quantity (i)  || '|'  || v_cancelled_quantity (i)  || '|'  || v_ship_method (i)  || '|'  || v_location_code (i)  || '|'

  || v_subinventory (i)  || '|'  || v_cancelled_date (i);  l_debug_state :=  '004 - Write PO receipt data into data file';  UTL_FILE.put_line (l_file_handler  ,l_file_data);  v_cnt := v_cnt + 1;  END LOOP;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 53/137

  END IF;

  CLOSE c_po_receipt;  EXCEPTION  WHEN OTHERS  THEN  IF c_po_receipt%ISOPEN  THEN  CLOSE c_po_receipt;  END IF;

  RAISE;  END;  END IF;

  -- query cancel PO  OPEN c_po_cancel (vc_org.organization_id, v_no_of_days);

  IF c_po_cancel%ISOPEN  THEN  BEGIN  l_debug_state :=  '002 - Fetch PO cancel data ';

  FETCH c_po_cancel  BULK COLLECT INTO v_organization_code  ,v_vendor_name  ,v_vendor_site_code  ,v_order_status  ,v_po_type  ,v_buyer  ,v_po_number  ,v_creation_date  ,v_order_line_number  ,v_currency  ,v_unit_price  ,v_item_code

  ,v_received_date  ,v_promised_date  ,v_need_by_date  ,v_quantity  ,v_received_quantity  ,v_cancelled_quantity  ,v_ship_method  ,v_location_code  ,v_subinventory  ,v_cancelled_date;

  IF v_po_number.FIRST IS NOT NULL  THEN

  FOR i IN 1 .. v_po_number.LAST  LOOP  l_debug_state :=  '003 - Construct PO cancel data into variable ';  l_file_data :=  '02'  || '|'  || v_organization_code (i)  || '|'

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 54/137

  || v_vendor_name (i)  || '|'  || v_vendor_site_code (i)  || '|'  || v_order_status (i)  || '|'  || v_po_type (i)  || '|'  || v_buyer (i)  || '|'  || v_po_number (i)  || '|'  || v_creation_date (i)  || '|'  || v_order_line_number (i)  || '|'  || v_currency (i)  || '|'  || v_unit_price (i)  || '|'  || v_item_code (i)  || '|'  || v_received_date (i)  || '|'

  || v_promised_date (i)  || '|'  || v_need_by_date (i)  || '|'  || v_quantity (i)  || '|'  || v_received_quantity (i)  || '|'  || v_cancelled_quantity (i)  || '|'  || v_ship_method (i)  || '|'  || v_location_code (i)

  || '|'  || v_subinventory (i)  || '|'  || v_cancelled_date (i);  l_debug_state :=  '004 - Write PO cancel data into data file ';  UTL_FILE.put_line (l_file_handler  ,l_file_data);  v_cnt := v_cnt + 1;  END LOOP;  END IF;

  CLOSE c_po_cancel;  EXCEPTION  WHEN OTHERS  THEN  IF c_po_cancel%ISOPEN  THEN  CLOSE c_po_cancel;  END IF;

  RAISE;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 55/137

  END;  END IF;  END LOOP;

--- **** End of Changes for ver 1.1 **** ----  l_debug_state :=  '005 - Write trailer data into data file ';  l_file_trailer :=  '03'  || '|'  || TO_CHAR (v_cnt)  || '|'  || TO_CHAR (SYSDATE, 'RRRRMMDDHH24MISS');  UTL_FILE.put_line (l_file_handler, l_file_trailer);  UTL_FILE.fclose (l_file_handler);  fnd_file.put_line (fnd_file.output, 'Number of rows ' || v_cnt);  ELSE  fnd_file.put_line (fnd_file.LOG  , 'File :'  || l_file_name  || ', is not open for writing.');  raise_application_error (-20000  , 'File :'  || l_file_name

  || ' is not open for writing.');  END IF;

--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 18 Jun 2008 ---  -- send data file into FXPC server  ss_pc_e_warehouse_iface_k.ss_pc_e_run_ftp_p (l_file_name);--- **** End of Changes for ver 1.1 **** ----  EXCEPTION  WHEN UTL_FILE.invalid_path  THEN  ROLLBACK;  raise_application_error  (-20001

  ,'Error while opening the file. Invalid Directory or File name.');  WHEN UTL_FILE.invalid_mode  THEN  ROLLBACK;  raise_application_error  (-20002  ,'Error while opening the file or checking if file is open. Invalid Mode.');  WHEN UTL_FILE.invalid_operation  THEN  ROLLBACK;  raise_application_error

  (-20003  ,'Error while opening the file or writing a new line. Invalid Operation.');  WHEN UTL_FILE.invalid_filehandle  THEN  ROLLBACK;  raise_application_error  (-20004  ,'Error in checking if file is open or writing a new line. Invalid File Handle.');

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 56/137

  WHEN UTL_FILE.write_error  THEN  ROLLBACK;  raise_application_error  (-20005  ,'Error in closing file or writing a new line. OS error duringwrite operation.');  WHEN UTL_FILE.read_error  THEN  ROLLBACK;  raise_application_error (-20006, 'Error in defining file type.');  WHEN UTL_FILE.internal_error  THEN  ROLLBACK;  raise_application_error (-20007, 'Error in defining file type.');  WHEN OTHERS  THEN  ROLLBACK;  v_error_msg := SUBSTR (SQLERRM  ,1  ,2000);  fnd_file.put_line (fnd_file.LOG  , 'Error in process :' || l_debug_state);  fnd_file.put_line (fnd_file.LOG, 'Error message :' || v_error_msg);

  RAISE;  END ss_pc_e_po_receipt_p;

/****-- Procedure name : SS_PC_E_SO_IFACE_P-- Purpose : Extract SO outstanding information from ITSS into data file.-- Parameter :-- - p_org_id -> extracted legal entity id-- - p_file_path -> output directory for generated data file****/  PROCEDURE ss_pc_e_so_iface_p (  errbuf OUT VARCHAR2  ,retcode OUT VARCHAR2

  ,p_org_id IN VARCHAR2  ,p_file_path IN VARCHAR2)  IS/* Remark by Senthil  CURSOR c_inv_org IS  SELECT organization_id  FROM org_organization_Definitions  WHERE disable_date is null  AND legal_entity=p_org_id;

  CURSOR c_inv_item IS  SELECT inventory_item_id,item_code  FROM FXAP.SS_PC_E_WAREHOUSE_DATA

  WHERE so_req='Y'  and rownum <20001;*/

  --- *** Begin Change for ver 1.1 **** Update by Gunadi on 24 Jun 2008 ---  CURSOR c_org_id  IS  SELECT hou.organization_id  FROM hr_operating_units hou

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 57/137

  ---*** Begin Change for ver 2.1 **** Update by Ni Nyoman Rai on 29Jan 2009 ---  --WHERE hou.legal_entity_id IN (SELECT orgid -- Commented CR 264977 Karthikeyan on 06-Jul-2012 

where hou.default_legal_context_id IN (SELECT orgid -- Added CR 264977 Karthikeyan on 06-Jul-2012 

FROM ss_pc_e_temp_org)  --WHERE hou.legal_entity_id = p_org_id  AND TRUNC (SYSDATE) BETWEEN hou.date_from  AND NVL (hou.date_to, SYSDATE);

  ---**** End of Changes for ver 2.1 **** ----

  ---*** Begin Change for ver 2.1 **** Update by Ni Nyoman Rai on 30 Oct 2009 ---  CURSOR c_order_num  IS  SELECT order_number  ,top_model_line_id  FROM ss_pc_e_warehouse_data_temp  GROUP BY order_number  ,top_model_line_id

  ,org_id;

  CURSOR c_so_detail  IS  SELECT organization_code  ,order_number  ,ot_type  ,ot_line_type  ,prod_model  ,item  ,line_number  ,shipment_number  ,component_number

  ,transactional_curr_code  ,unit_list_price  ,unit_selling_price  ,extended_price  ,trx_cost  ,ordered_quantity  ,shipped_quantity  ,ordered_date  ,shipped_date  ,cust_po_number  ,item_categories  ,request_date  ,schedule_ship_date

  ,branch_segment  ,customer_number  ,customer_name  ,sales_channel_code  ,salesrep_name  ,bill2country  ,line_id  ,flow_status_code  ,org_id  FROM ss_pc_e_warehouse_data_temp

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 58/137

  WHERE open_flag = 'Y'  AND cancelled_flag = 'N'  ORDER BY order_number  ,top_model_line_id  ,line_id;

  /* SELECT mp.organization_code,  oeh.order_number,  oeh_type.name ot_type,  oel_type.name ot_line_type,  gcc.segment5 prod_model,  msi.segment1 item,  oel.line_number,  oel.shipment_number,  oel.component_number,  oeh.transactional_curr_code,  oel.unit_list_price,  oel.unit_selling_price,  oel.ordered_quantity * oel.unit_selling_price extended_price,  nvl(mmt.actual_cost,0) trx_cost,  DECODE(oel.line_category_code,'RETURN',oel.ordered_quantity*-1,oel.ordered_quantity) ordered_quantity,  NVL(DECODE(oel.line_category_code,'RETURN',oel.shipped_quant

ity*-1,oel.shipped_quantity),0) shipped_quantity,  oeh.ordered_date,  oel.actual_shipment_date shipped_date,  oeh.cust_po_number,  mc.segment1 item_categories,  oel.request_date,  oel.schedule_ship_date,  oeh.attribute12 branch_segment,  hca.account_number customer_number,  hp.party_name customer_name,  hca.sales_channel_code sales_channel_code,  rs.name salesrep_name,  ft.nls_territory bill2country,

  oel.line_id line_id,  oel.flow_status_code flow_status_code,  oel.org_id  FROM ss_pc_e_warehouse_data spw,  oe_order_lines_all oel,  oe_order_headers_all oeh,  mtl_system_items_b msi,  mtl_item_categories mic,  mtl_categories_b mc,  mtl_parameters mp,  oe_transaction_types_tl oeh_type,  oe_transaction_types_tl oel_type,  gl_code_combinations gcc,

  mtl_material_transactions mmt,  hz_cust_accounts hca,  hz_parties hp,  jtf_rs_salesreps rs,  fnd_territories ft  WHERE spw.so_req = 'Y'  AND oel.inventory_item_id = spw.inventory_item_id  AND oel.org_id = p_ou_id  AND oel.open_flag = 'Y'  AND oel.cancelled_flag = 'N'

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 59/137

  -- for testing purposed 27 Oct 2009  and oeh.order_number in (112, 113)  --  --AND oel.flow_status_code NOT IN('CLOSED','CANCELLED')  AND oeh.header_id = oel.header_id  AND msi.inventory_item_id = oel.inventory_item_id  AND msi.organization_id = oel.ship_from_org_id  AND mic.inventory_item_id = msi.inventory_item_id  AND mic.organization_id = msi.organization_id  AND mic.category_set_id = 1  AND mc.category_id = mic.category_id  AND mp.organization_id = oel.ship_from_org_id  AND oeh_type.transaction_type_id = oeh.order_type_id  AND oeh_type.language = USERENV('LANG')  AND oel_type.transaction_type_id = oel.line_type_id  AND oel_type.language = USERENV('LANG')  AND msi.cost_of_sales_account = gcc.code_combination_id  AND mmt.transaction_type_id(+) = 33  AND oel.line_id = mmt.trx_source_line_id (+)  AND hca.cust_account_id = oel.sold_to_org_id  AND hca.party_id = hp.party_id  AND oeh.salesrep_id = rs.salesrep_id(+)  AND oeh.org_id = rs.org_id(+)  AND hp.country = ft.territory_code(+);*/

  ---**** End of Changes for ver 2.1 **** ----  CURSOR c_ar_detail (  v_line_id IN NUMBER  ,v_order_number IN NUMBER  ,v_org_id IN NUMBER)  IS  SELECT ctl.trx_number  ,ctl.trx_date  , NVL (rat.segment1, '') || NVL (rat.segment2, '')  territory_name  FROM ra_customer_trx_lines_all ctla  ,ra_customer_trx_all ctl  ,ra_territories rat

  WHERE ctla.interface_line_attribute6 = TO_CHAR (v_line_id)  AND ctla.interface_line_attribute1 = TO_CHAR (v_order_number)  AND ctla.org_id = v_org_id  AND ctl.customer_trx_id = ctla.customer_trx_id  AND ctla.org_id = ctl.org_id  AND ctl.territory_id = rat.territory_id(+);

  TYPE organization_code_tab IS TABLE OF mtl_parameters.organization_code%TYPE;

  TYPE order_number_tab IS TABLE OF oe_order_headers_all.order_number%TYPE;

  TYPE ot_type_tab IS TABLE OF oe_transaction_types_tl.NAME%TYPE;

  TYPE ot_line_type_tab IS TABLE OF oe_transaction_types_tl.NAME%TYPE;

  TYPE prod_model_tab IS TABLE OF gl_code_combinations.segment5%TYPE;

  TYPE item_tab IS TABLE OF mtl_system_items_b.segment1%TYPE;

  TYPE line_number_tab IS TABLE OF oe_order_lines_all.line_number%TYPE;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 60/137

  TYPE shipment_number_tab IS TABLE OF oe_order_lines_all.shipment_number%TYPE;

  TYPE component_number_tab IS TABLE OF oe_order_lines_all.component_number%TYPE;

  TYPE transactional_curr_code_tab IS TABLE OF oe_order_headers_all.transactional_curr_code%TYPE;

  TYPE unit_list_price_tab IS TABLE OF oe_order_lines_all.unit_list_price%TYPE;

  TYPE unit_selling_price_tab IS TABLE OF oe_order_lines_all.unit_selling_ price%TYPE;

  TYPE extended_price_tab IS TABLE OF NUMBER;

  TYPE trx_cost_tab IS TABLE OF mtl_material_transactions.actual_cost%TYPE;

  TYPE ordered_quantity_tab IS TABLE OF oe_order_lines_all.ordered_quantity%TYPE;

  TYPE shipped_qty_tab IS TABLE OF oe_order_lines_all.shipped_quantity%TYP

E;

  TYPE ordered_date_tab IS TABLE OF oe_order_headers_all.ordered_date%TYPE;

  TYPE shipped_date_tab IS TABLE OF oe_order_lines_all.actual_shipment_date%TYPE;

  TYPE cust_po_number_tab IS TABLE OF oe_order_headers_all.cust_po_number%TYPE;

  TYPE item_categories_tab IS TABLE OF mtl_categories_b.segment1%TYPE;

  TYPE request_date_tab IS TABLE OF oe_order_lines_all.request_date%TYPE;

  TYPE schedule_ship_date_tab IS TABLE OF oe_order_lines_all.schedule_ship _date%TYPE;

  TYPE branch_segment_tab IS TABLE OF oe_order_headers_all.attribute12%TYPE;

  TYPE customer_number_tab IS TABLE OF hz_cust_accounts.account_number%TYPE;

  TYPE customer_name_tab IS TABLE OF hz_parties.party_name%TYPE;

  TYPE sales_channel_code_tab IS TABLE OF hz_cust_accounts.sales_channel_code%TYPE;

  TYPE salesrep_name_tab IS TABLE OF jtf_rs_salesreps.NAME%TYPE;

  TYPE bill2country_tab IS TABLE OF fnd_territories.nls_territory%TYPE;

  TYPE line_id_tab IS TABLE OF oe_order_lines_all.line_id%TYPE;

  TYPE flow_status_code_tab IS TABLE OF oe_order_lines_all.flow_status_cod

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 61/137

e%TYPE;

  TYPE org_id_tab IS TABLE OF oe_order_lines_all.org_id%TYPE;

  v_organization_code organization_code_tab;  v_order_number order_number_tab;  v_ot_type ot_type_tab;  v_ot_line_type ot_line_type_tab;  v_prod_model prod_model_tab;  v_item item_tab;  v_line_number line_number_tab;  v_shipment_number shipment_number_tab;  v_component_number component_number_tab;  v_so_display_line_num VARCHAR2 (10);  v_transactional_curr_code transactional_curr_code_tab;  v_unit_list_price unit_list_price_tab;  v_unit_selling_price unit_selling_price_tab;  v_extended_price extended_price_tab;  v_trx_cost trx_cost_tab;  v_ordered_quantity ordered_quantity_tab;  v_shipped_qty shipped_qty_tab;  v_ordered_date ordered_date_tab;  v_shipped_date shipped_date_tab;  v_cust_po_number cust_po_number_tab;

  v_item_categories item_categories_tab;  v_request_date request_date_tab;  v_schedule_ship_date schedule_ship_date_tab;  v_branch_segment branch_segment_tab;  v_customer_number customer_number_tab;  v_customer_name customer_name_tab;  v_sales_channel_code sales_channel_code_tab;  v_salesrep_name salesrep_name_tab;  v_bill2country bill2country_tab;  v_line_id line_id_tab;  v_flow_status_code flow_status_code_tab;  v_org_id org_id_tab;  --- **** End of Changes for ver 1.1 **** ----

  ---*** Begin Change for ver 2.1 **** Update by Ni Nyoman Rai on 30 Oct 2009 ---  v_link_to_line NUMBER;  b_inventory_item_id NUMBER;  b_line_number NUMBER;  b_shipment_number NUMBER;  b_component_number NUMBER;  b_unit_list_price NUMBER;  b_unit_selling_price NUMBER;  b_extended_price NUMBER;  b_ordered_quantity NUMBER;  b_shipped_quantity NUMBER;

  b_shipped_date DATE;  b_request_date DATE;  b_schedule_ship_date DATE;  b_line_id NUMBER;  b_flow_status_code VARCHAR2 (30);  b_organization_code VARCHAR2 (7);  b_ot_type VARCHAR2 (30);  b_ot_line_type VARCHAR2 (30);  b_prod_model VARCHAR2 (25);  b_item VARCHAR2 (40);

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 62/137

  b_trx_cost NUMBER;  b_ship_from_org_id NUMBER;  b_link_to_line_id NUMBER;  --- **** End of Changes for ver 2.1 **** ----

  /* Original from Senthil  CURSOR c_so_detail IS  SELECT oeh.order_number,  oel.line_number,  msi.cost_of_sales_account,  msi.segment1 item,  oeh.transactional_curr_code,  oel.Unit_list_price,  oel.unit_selling_price,  (nvl(oel.ordered_quantity,0) * nvl(oel.unit_selling_price,0)) extended_ price,  oel.ordered_quantity,  nvl(oel.shipped_quantity,0) shipped_qty,  oeh.ordered_date,  oel.actual_shipment_date Shipped_Date,  oeh.cust_po_number,  OEL.FLOW_STATUS_CODE LINE_STATUS,  msi.shippable_item_flag ,  mc.segment1 item_categories,

  oel.line_id,  oel.ship_from_org_id,  oel.inventory_item_id,  oeh.sold_to_org_id,  oel.invoice_to_contact_id,  oeh.sold_to_contact_id,  oeh.SalesRep_Id,  oeh.org_id,  oeh.order_type_id,  oel.line_type_id,  oel.request_date,  oel.schedule_ship_date,  oeh.attribute12 Branch_Segment

FROM oe_order_headers_all oeh  , oe_order_lines_all oel  , mtl_system_items msi  , mtl_item_categories mic  , mtl_categories mc  , fnd_lookup_values_vl lin_status  ,FXAP.SS_PC_E_WAREHOUSE_DATA spwWHERE oel.inventory_item_id=spw.inventory_item_idand spw.so_req='Y'and oel.open_flag='Y'and oeh.org_id=oel.org_idand oel.flow_status_code not in('CLOSED','CANCELLED')and lin_status.lookup_type= 'LINE_FLOW_STATUS'

and oeh.header_id = oel.header_idand oel.inventory_item_id = msi.inventory_item_idand oel.ship_from_org_id =msi.organization_idAND msi.inventory_item_id=mic.inventory_item_idAND msi.organization_id =mic.organization_idAND mic.category_set_id=1AND mic.category_id = mc.category_idAND mc.structure_id=101and oel.flow_status_code= lin_status.lookup_code;*/

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 63/137

  --- *** Begin Change for ver 1.1 **** Update by Willy Tan on 25 Jun 2008 ---  l_file_name VARCHAR2 (100)  := 'FXPC_ITSSLIVE_OM.dat';  l_file_handler UTL_FILE.file_type;  v_error_msg VARCHAR2 (2000);  l_debug_state VARCHAR2 (2000);  l_file_heading VARCHAR2 (100);  l_file_trailer VARCHAR2 (100);  l_file_data VARCHAR2 (32767);  v_cnt NUMBER := 0;  v_line_status VARCHAR (80);  l_trx_number VARCHAR2 (20);  l_trx_date DATE;  l_territory_name VARCHAR2 (500);/*  File_Close Exception;  l_file_rec1 VARCHAR2(100);  l_file_rec2 VARCHAR2(100);  l_file_rec VARCHAR2(32767);  l_Err_Num NUMBER;  l_Err_Msg VARCHAR2(1000);  cnt NUMBER := 0;

  l_territiory_id NUMBER;  l_salesrep_name VARCHAR2(240);  l_salesrep_no VARCHAR2(30);  l_gl_id_rev NUMBER;  l_customer_number VARCHAR2(30);  l_customer_name VARCHAR2(340);  l_sales_channel_code VARCHAR2(30);  l_bill_contact_phone VARCHAR2(30);  l_ship_contact_phone VARCHAR2(30);  l_ot_type VARCHAR2(240);  l_ot_line_type VARCHAR2(240);  l_trx_cost NUMBER;  v_prod_model VARCHAR2(10);

  l_country VARCHAR2(60);  l_bill2country VARCHAR2(250);  l_organization_code VARCHAR2(3);*/--- **** End of Changes for ver 1.1 **** ----  BEGIN  l_debug_state :=  '000 - Open FXPC_ITSSLIVE_OM.dat file for writing';  l_file_handler :=  UTL_FILE.fopen (p_file_path  ,l_file_name  ,'W'  ,32767);

  IF UTL_FILE.is_open (l_file_handler)  THEN  l_debug_state :=  '001 - Write header into data file';  l_file_heading :=  '01'  || '|'  || 'SO DETAILS'  || '|'

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 64/137

  || TO_CHAR (SYSDATE, 'RRRRMMDDHH24MISS');  UTL_FILE.put_line (l_file_handler, l_file_heading);

  --- *** Remarks for CR#264977 by Ni Nyoman Rai on 17-Nov-09 ***---  -- FOR vc_org IN c_org_id  --LOOP  --- *** End of Remarks for CR#264977 by Ni Nyoman Rai on 17-Nov-09 ***---  OPEN c_so_detail;

  IF c_so_detail%ISOPEN  THEN  BEGIN  l_debug_state :=  '002 - Fetch SO outstanding data ';

  FETCH c_so_detail  BULK COLLECT INTO v_organization_code  ,v_order_number  ,v_ot_type  ,v_ot_line_type  ,v_prod_model  ,v_item  ,v_line_number

  ,v_shipment_number  ,v_component_number  ,v_transactional_curr_code  ,v_unit_list_price  ,v_unit_selling_price  ,v_extended_price  ,v_trx_cost  ,v_ordered_quantity  ,v_shipped_qty  ,v_ordered_date  ,v_shipped_date  ,v_cust_po_number  ,v_item_categories

  ,v_request_date  ,v_schedule_ship_date  ,v_branch_segment  ,v_customer_number  ,v_customer_name  ,v_sales_channel_code  ,v_salesrep_name  ,v_bill2country  ,v_line_id  ,v_flow_status_code  ,v_org_id;

  IF v_order_number.FIRST IS NOT NULL

  THEN  FOR i IN 1 .. v_order_number.LAST  LOOP  l_trx_number := NULL;  l_trx_date := NULL;  l_territory_name := NULL;  l_debug_state :=  '003 - Query AR transactions information forline id '  || TO_CHAR (v_line_id (i) );

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 65/137

  FOR c_ar_detail_rec IN  c_ar_detail (v_line_id (i)  ,v_order_number (i)  ,v_org_id (i) )  LOOP  l_trx_number :=  c_ar_detail_rec.trx_number;  l_trx_date :=  c_ar_detail_rec.trx_date;  l_territory_name :=  c_ar_detail_rec.territory_name;  END LOOP;

  IF l_territory_name IS NULL  THEN  l_territory_name := 'n.a';  END IF;

  l_debug_state :=  '004 - Get order line status for line id '  || TO_CHAR (v_line_id (i) );

  BEGIN

  -- get sales order line status using API  v_line_status :=  oe_line_status_pub.get_line_status  (v_line_id (i)  ,v_flow_status_code (i) );  EXCEPTION  WHEN OTHERS  THEN  v_line_status := NULL;  END;

  v_so_display_line_num :=  TO_CHAR (v_line_number (i) );

  IF v_shipment_number (i) IS NOT NULL  THEN  v_so_display_line_num :=  v_so_display_line_num  || '.'  || TO_CHAR (v_shipment_number (i) );  END IF;

  IF v_component_number (i) IS NOT NULL  THEN  v_so_display_line_num :=  v_so_display_line_num

  || '..'  || TO_CHAR (v_component_number (i) );  END IF;

  l_debug_state :=  '005 - Construct SO outstanding information for line id '  || TO_CHAR (v_line_id (i) );  l_file_data :=  '02'

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 66/137

  || '|'  || v_organization_code (i)  || '|'  || v_order_number (i)  || '|'  || v_ot_type (i)  || '|'  || v_ot_line_type (i)  || '|'  || v_prod_model (i)  || '|'  || v_item (i)  || '|'  || v_so_display_line_num  || '|'  || v_transactional_curr_code (i)  || '|'  || v_unit_list_price (i)  || '|'  || v_unit_selling_price (i)  || '|'  || v_extended_price (i)  || '|'  || v_trx_cost (i)

  || '|'  || v_ordered_quantity (i)  || '|'  || v_shipped_qty (i)  || '|'  || v_customer_number (i)  || '|'  || v_customer_name (i)  || '|'  || v_bill2country (i)  || '|'  || l_territory_name  || '|'

  || v_sales_channel_code (i)  || '|'  || v_salesrep_name (i)  || '|'  || v_ordered_date (i)  || '|'  || v_shipped_date (i)  || '|'  || l_trx_number  || '|'  || l_trx_date  || '|'  || v_cust_po_number (i)

  || '|'  || v_item_categories (i)  || '|'  || v_line_status  || '|'  || v_request_date (i)  || '|'  || v_schedule_ship_date (i)  || '|'  || v_branch_segment (i);

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 67/137

  l_debug_state :=  '006 - Write SO oustanding data into data file ';  UTL_FILE.put_line (l_file_handler, l_file_data);  v_cnt := v_cnt + 1;  END LOOP;  END IF;

  CLOSE c_so_detail;  EXCEPTION  WHEN OTHERS  THEN  IF c_so_detail%ISOPEN  THEN  CLOSE c_so_detail;  END IF;

  RAISE;  END;  END IF;

  --END LOOP;--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 25 Jun 2008 ---/*

  --FOR c_inv_org_rec IN c_inv_org LOOP  -- FOR c_inv_item_rec IN c_inv_item LOOP  FOR c_so_detail_rec IN c_so_detail(p_org_id) LOOP  BEGIN  SELECT ctl.TRX_NUMBER ,ctl.TRX_DATE,ctl.territory_id  INTO l_trx_number,l_trx_date,l_territiory_id  FROM RA_CUSTOMER_TRX_LINES_ALL ctla ,RA_CUSTOMER_TRX_ALL ctl  WHERE ctla.org_id=c_so_detail_rec.org_id  AND ctla.interface_line_attribute6=to_char(c_so_detail_rec.line_id)  AND ctla.CUSTOMER_TRX_ID = ctl.CUSTOMER_TRX_ID  AND ctla.org_id=ctl.org_id;  EXCEPTION

  WHEN OTHERS then  l_trx_number :=null;  l_trx_date :=null;  l_territiory_id :=null;  END;

  BEGIN  SELECT rs.name salesrep,rs.salesrep_number,rs.gl_id_rev  INTO l_salesrep_name,l_salesrep_no,l_gl_id_rev  FROM jtf_rs_salesreps rs  WHERE salesrep_id=c_so_detail_rec.salesrep_id;  EXCEPTION  WHEN OTHERS THEN

  l_salesrep_name := null;  l_salesrep_no := null;  l_gl_id_rev := null;  END;

  BEGIN  SELECT hca.account_number, hp.party_name,hca.sales_channel_code,hp.country  INTO l_customer_number,l_customer_name,l_sales_channel_code,l_country

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 68/137

  FROM hz_cust_accounts hca,  hz_parties hp  WHERE hca.cust_account_id=c_so_detail_rec.sold_to_org_id  AND hca.party_id=hp.party_id;  EXCEPTION  WHEN OTHERS THEN  l_customer_number := null;  l_customer_name := null;  l_sales_channel_code := null;  END;

  IF c_so_detail_rec.invoice_to_contact_id is not null THEN  BEGIN  SELECT rpb.phone_number  INTO l_bill_contact_phone  FROM ra_phones rpb  WHERE rpb.contact_id =c_so_detail_rec.invoice_to_contact_id  AND (( rpb.phone_type IN ('GEN','TEL', 'MOBILE') and rpb.primary_flag = 'Y')  OR rpb.phone_type IS NULL);  EXCEPTION  WHEN OTHERS THEN  l_bill_contact_phone :=null;  END;

  END IF;

  IF c_so_detail_rec.sold_to_contact_id is not null THEN  BEGIN  SELECT rps.phone_number  INTO l_ship_contact_phone  FROM ra_phones rps  WHERE rps.contact_id =c_so_detail_rec.sold_to_contact_id  AND (( rps.phone_type IN ('GEN','TEL', 'MOBILE') and rps.primary_flag = 'Y')  OR rps.phone_type IS NULL) ;  EXCEPTION  WHEN OTHERS THEN

  l_ship_contact_phone :=null;  END;  END IF;

  BEGIN  SELECT name  INTO l_ot_type  FROM oe_transaction_types_tl tvh  WHERE tvh.transaction_type_id=c_so_detail_rec.order_type_id  AND tvh.LANGUAGE = USERENV('LANG');  EXCEPTION  WHEN OTHERS then  l_ot_type := null;

  END;

  BEGIN  SELECT name  INTO l_ot_line_type  FROM oe_transaction_types_tl tvl  WHERE tvl.transaction_type_id=c_so_detail_rec.line_type_id  AND tvl.LANGUAGE = USERENV('LANG');  EXCEPTION  WHEN OTHERS then

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 69/137

  l_ot_line_type :=null;  END;

  BEGIN  SELECT nvl(mmt.actual_cost,0)  INTO l_trx_cost  FROM mtl_material_transactions mmt  WHERE mmt.transaction_type_id = 33  AND mmt.trx_source_line_id = c_so_detail_rec.line_id  AND mmt.organization_id =c_so_detail_rec.ship_from_org_id ;  EXCEPTION  WHEN OTHERS then  l_trx_cost :=0;  END;

  IF l_gl_id_rev is not null then  BEGIN  SELECT segment5  INTO v_prod_model  FROM gl_code_combinations  WHERE code_combination_id=c_so_detail_rec.cost_of_sales_account;  EXCEPTION  WHEN OTHERS then

  v_prod_model :=null;  END;  END IF;

  IF l_country is not null then  BEGIN  SELECT nls_territory  INTO l_bill2country  FROM FND_TERRITORIES  WHERE territory_code =l_country;  EXCEPTION  WHEN OTHERS then  l_bill2country :=null;

  END;  END IF;

  IF l_territiory_id is not null then  BEGIN  SELECT NVL(SEGMENT1,'') || NVL(SEGMENT2,'')  INTO l_territory_name  FROM Ra_Territories  WHERE Territory_Id = l_territiory_id;  EXCEPTION  WHEN OTHERS then  l_territory_name :='n.a';  END;

  END IF;

  BEGIN  SELECT mp.organization_code  INTO l_organization_code  FROM mtl_parameters mp  WHERE organization_id=c_so_detail_rec.ship_from_org_id;  EXCEPTION  WHEN NO_DATA_FOUND then  l_organization_code :=null;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 70/137

  WHEN OTHERS then  l_organization_code :=null;  END;

  l_file_rec :='02'||'|'||l_organization_code||'|'||c_so_detail_rec.order_number||'|'||  l_ot_type||'|'||l_ot_line_type||'|'||  v_prod_model||'|'||c_so_detail_rec.item||'|'||c_so_detail_rec.line_number||'|'||  c_so_detail_rec.transactional_curr_code||'|'||c_so_detail_rec.Unit_list_price||'|'||  c_so_detail_rec.unit_selling_price||'|'||c_so_detail_rec.extended_price||'|'||  l_trx_cost||'|'||c_so_detail_rec.ordered_quantity||'|'||  c_so_detail_rec.shipped_qty||'|'||l_customer_number||'|'||l_customer_name||'|'||  l_bill2country||'|'||l_territory_name||'|'||l_sales_channel_code||'|'||  l_salesrep_name||'|'||c_so_detail_rec.ordered_date||'|'||c_so_detail_rec.shipped_date||'|'||  l_trx_number||'|'||l_trx_date||'|'||c_so_detail_rec.cust_po_number||'|'||  c_so_detail_rec.item_categories||'|'||c_so_detail_rec

.line_status||'|'||  c_so_detail_rec.request_date||'|'||c_so_detail_rec.schedule_ship_date||'|'||  c_so_detail_rec.branch_segment;

  Utl_File.put_line(l_file_handler,l_file_rec);  cnt := cnt +1;  END LOOP;  -- END LOOP;  -- END LOOP;

  */  --- *** Remarks for CR#264977 by Ni Nyoman Rai on 17-Nov-09 ***---

  /* FOR vc_org IN c_org_id LOOP  OPEN c_so_detail(vc_org.organization_id);  IF c_so_detail%ISOPEN THEN  BEGIN  l_debug_state := '002 - Fetch SO outstanding data ';  FETCH c_so_detail BULK COLLECT INTO  v_organization_code, v_order_number, v_ot_type,  v_ot_line_type, v_prod_model, v_item,  v_line_number, v_shipment_number, v_component_number,  v_transactional_curr_code, v_unit_list_price,  v_unit_selling_price, v_extended_price, v_trx_cost,  v_ordered_quantity, v_shipped_qty, v_ordered_date,  v_shipped_date, v_cust_po_number, v_item_categories,

  v_request_date, v_schedule_ship_date, v_branch_segment,  v_customer_number, v_customer_name, v_sales_channel_code,  v_salesrep_name, v_bill2country, v_line_id,  v_flow_status_code, v_org_id;

  IF v_order_number.FIRST IS NOT NULL THEN  FOR i IN 1..v_order_number.LAST LOOP  l_trx_number := NULL;  l_trx_date := NULL;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 71/137

  l_territory_name := NULL;

  l_debug_state := '003 - Query AR transactions information for line id '||to_char(v_line_id(i));  FOR c_ar_detail_rec IN c_ar_detail(v_line_id(i), v_order

 _number(i),v_org_id(i))  LOOP  l_trx_number := c_ar_detail_rec.trx_number;  l_trx_date := c_ar_detail_rec.trx_date;  l_territory_name := c_ar_detail_rec.territory_name;  END LOOP;

  IF l_territory_name IS NULL THEN  l_territory_name := 'n.a';  END IF;

  l_debug_state := '004 - Get order line status for line id '||to_char(v_line_id(i));  BEGIN  -- get sales order line status using API  v_line_status := oe_line_status_pub.get_line_status(v_line_id(i), v_flow_status_code(i));  EXCEPTION  WHEN OTHERS THEN

  v_line_status := NULL;  END;

  v_so_display_line_num := TO_CHAR(v_line_number(i));  IF v_shipment_number(i) IS NOT NULL THEN  v_so_display_line_num := v_so_display_line_num ||'.'||TO_CHAR(v_shipment_number(i));  END IF;

  IF v_component_number(i) IS NOT NULL THEN  v_so_display_line_num := v_so_display_line_num ||'..'||TO_CHAR(v_component_number(i));  END IF;

  l_debug_state := '005 - Construct SO outstanding information for line id '||to_char(v_line_id(i));  l_file_data := '02'||'|'||v_organization_code(i)||'|'||v

 _order_number(i)||'|'||  v_ot_type(i)||'|'||v_ot_line_type(i)||'|'||  v_prod_model(i)||'|'||v_item(i)||'|'||v_so

 _display_line_num||'|'||  v_transactional_curr_code(i)||'|'||v_unit_ list_price(i)||'|'||  v_unit_selling_price(i)||'|'||v_extended_price(i)||'|'||

  v_trx_cost(i)||'|'||v_ordered_quantity(i)||'|'||  v_shipped_qty(i)||'|'||v_customer_number(i)||'|'||v_customer_name(i)||'|'||  v_bill2country(i)||'|'||l_territory_name||'|'||v_sales_channel_code(i)||'|'||  v_salesrep_name(i)||'|'||v_ordered_date(i)||'|'||v_shipped_date(i)||'|'||  l_trx_number||'|'||l_trx_date||'|'||v_cust

 _po_number(i)||'|'||

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 72/137

  v_item_categories(i)||'|'||v_line_status||'|'||  v_request_date(i)||'|'||v_schedule_ship_date(i)||'|'||  v_branch_segment(i);

  l_debug_state := '006 - Write SO oustanding data into data file ';  utl_file.put_line(l_file_handler,l_file_data);  v_cnt := v_cnt +1;  END LOOP;  END IF;

  CLOSE c_so_detail;  EXCEPTION  WHEN OTHERS THEN  IF c_so_detail%ISOPEN THEN  CLOSE c_so_detail;  END IF;  RAISE;  END;  END IF;  END LOOP;  */

  --- *** End of Remarks for CR#264977 by Ni Nyoman Rai on 17-Nov-09 ***---

  -- **** End of Changes for ver 1.1 **** ----  l_debug_state :=  '007 - Write trailer data into data file ';  l_file_trailer :=  '03'  || '|'  || TO_CHAR (v_cnt)  || '|'  || TO_CHAR (SYSDATE, 'RRRRMMDDHH24MISS');  UTL_FILE.put_line (l_file_handler, l_file_trailer);  UTL_FILE.fclose (l_file_handler);

  fnd_file.put_line (fnd_file.output, 'Number of rows ' || v_cnt);  ELSE  fnd_file.put_line (fnd_file.LOG  , 'File :'  || l_file_name  || ', is not open for writing.');  raise_application_error (-20000  , 'File :'  || l_file_name  || ' is not open for writing.');  END IF;

--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 25 Jun 2008 ---

  -- send data file into FXPC server  ss_pc_e_warehouse_iface_k.ss_pc_e_run_ftp_p (l_file_name);--- **** End of Changes for ver 1.1 **** ----  EXCEPTION  WHEN UTL_FILE.invalid_path  THEN  ROLLBACK;  raise_application_error  (-20001  ,'Error while opening the file. Invalid Directory or File name.'

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 73/137

);  WHEN UTL_FILE.invalid_mode  THEN  ROLLBACK;  raise_application_error  (-20002  ,'Error while opening the file or checking if file is open. Invalid Mode.');  WHEN UTL_FILE.invalid_operation  THEN  ROLLBACK;  raise_application_error  (-20003  ,'Error while opening the file or writing a new line. Invalid Operation.');  WHEN UTL_FILE.invalid_filehandle  THEN  ROLLBACK;  raise_application_error  (-20004  ,'Error in checking if file is open or writing a new line. Invalid File Handle.');  WHEN UTL_FILE.write_error  THEN

  ROLLBACK;  raise_application_error  (-20005  ,'Error in closing file or writing a new line. OS error duringwrite operation.');  WHEN UTL_FILE.read_error  THEN  ROLLBACK;  raise_application_error (-20006, 'Error in defining file type.');  WHEN UTL_FILE.internal_error  THEN  ROLLBACK;  raise_application_error (-20007, 'Error in defining file type.');

  WHEN OTHERS  THEN  ROLLBACK;  v_error_msg := SUBSTR (SQLERRM  ,1  ,2000);  fnd_file.put_line (fnd_file.LOG  , 'Error in process :' || l_debug_state);  fnd_file.put_line (fnd_file.LOG, 'Error message :' || v_error_msg);  RAISE;  END ss_pc_e_so_iface_p;

/****

-- Procedure name : SS_PC_E_SO_SHIPPED_IFACE_P-- Purpose : Extract SO shipped and cancellation information from ITSS into data file.-- Parameter :-- - p_org_id -> extracted legal entity id-- - p_file_path -> output directory for generated data file-- - p_no_of_days -> number of days****/  PROCEDURE ss_pc_e_so_shipped_iface_p (  errbuf OUT VARCHAR2

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 74/137

  ,retcode OUT VARCHAR2  ,p_org_id IN VARCHAR2  ,p_file_path IN VARCHAR2  ,p_no_of_days IN NUMBER)  IS/* remark by Senthil  CURSOR c_inv_org IS  SELECT organization_id,operating_unit  FROM org_organization_Definitions  WHERE disable_date is null  AND legal_entity=p_org_id;

  CURSOR c_inv_item IS  SELECT inventory_item_id,item_code  FROM FXAP.SS_PC_E_WAREHOUSE_DATA  WHERE so_shipped_req='Y'  and rownum <500;*/

  /*  CURSOR c_so_detail ( p_ou_id NUMBER,  p_num_days NUMBER) IS  select \*+ parallel(wda,4) parallel(wdd,4) parallel(wnd,4) parallel(oel,4)  parallel(oeh,4) parallel(mic,8) parallel(msi,4) *\

  oeh.order_number,  oel.line_number,  msi.cost_of_sales_account,  msi.segment1 item,  oeh.transactional_curr_code,  oel.Unit_list_price,  oel.unit_selling_price,  sum(nvl(oel.ordered_quantity,0) * nvl(oel.unit_selling_price,0)) extended_price,  sum(oel.ordered_quantity) ordered_quantity,  sum(nvl(oel.shipped_quantity,0)) shipped_qty,  oeh.ordered_date,  oel.actual_shipment_date Shipped_Date,

  oeh.cust_po_number,  OEL.FLOW_STATUS_CODE LINE_STATUS,  msi.shippable_item_flag ,  mc.segment1 item_categories,  oel.line_id,  oel.ship_from_org_id,  oel.inventory_item_id,  oeh.sold_to_org_id,  oel.invoice_to_contact_id,  oeh.sold_to_contact_id,  oeh.SalesRep_Id,  oeh.org_id,  oeh.order_type_id,

  oel.line_type_id,  oel.request_date,  oel.schedule_ship_date,  oeh.attribute12 Branch_Segment  from oe_order_headers_all oeh,  oe_order_lines_all oel,  wsh_delivery_details wdd,  wsh_delivery_assignments wda,  wsh_new_deliveries wnd,  mtl_system_items msi,

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 75/137

  mtl_item_categories mic,  mtl_categories mc  where wnd.confirm_date is not null  and wnd.status_code='CL'  and oel.open_flag not in('Y')  and wdd.released_status='C'  and exists (select 1 from FXAP.SS_PC_E_WAREHOUSE_DATA spw  where spw.inventory_item_id=oel.inventory_item_id and so_shipped_req='Y')  and oeh.header_id = oel.header_id  and oel.header_id = wdd.source_header_id  and oel.line_id = wdd.source_line_id  and oel.inventory_item_id=wdd.inventory_item_id  and oel.ship_from_org_id=wdd.organization_id  and wdd.delivery_detail_id = wda.delivery_detail_id  and wda.delivery_id = wnd.delivery_id  and oel.inventory_item_id = msi.inventory_item_id  and oel.ship_from_org_id =msi.organization_id  and msi.inventory_item_id = mic.inventory_item_id  and msi.organization_id = mic.organization_id  and mic.category_id = mc.category_id  and mic.category_set_id = 1  and trunc(wnd.confirm_date) between (trunc(sysdate)-(p_no_of_days)) and trunc(sysdate)

  group by oeh.order_number,  oel.line_number,  msi.cost_of_sales_account,  msi.segment1,  oeh.transactional_curr_code,  oel.Unit_list_price,  oel.unit_selling_price,  oeh.ordered_date,  oel.actual_shipment_date,  oeh.cust_po_number,  OEL.FLOW_STATUS_CODE,  msi.shippable_item_flag ,  mc.segment1 ,

  oel.line_id,  oel.ship_from_org_id,  oel.inventory_item_id,  oeh.sold_to_org_id,  oel.invoice_to_contact_id,  oeh.sold_to_contact_id,  oeh.SalesRep_Id,  oeh.org_id,  oeh.order_type_id,  oel.line_type_id,  oel.request_date,  oel.schedule_ship_date,  oeh.attribute12

 --and trunc(oel.actual_shipment_date) between (trunc(sysdate)-(p_no_of_days)) and trunc(sysdate)  union all  SELECT \*+ ordered no_merge(mc) use_nl(lin_status,oel,spw,msi,mic) use_hash(mc) use_nl(oeh) *\oeh.order_number,  oel.line_number,  msi.cost_of_sales_account,  msi.segment1 item,  oeh.transactional_curr_code,  oel.Unit_list_price,

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 76/137

  oel.unit_selling_price,  (nvl(oel.ordered_quantity,0) * nvl(oel.unit_selling_price,0)) extended_ price,  oel.ordered_quantity,  nvl(oel.shipped_quantity,0) shipped_qty,  oeh.ordered_date,  oel.actual_shipment_date Shipped_Date,  oeh.cust_po_number,  OEL.FLOW_STATUS_CODE LINE_STATUS,  msi.shippable_item_flag ,  mc.segment1 item_categories,  oel.line_id,  oel.ship_from_org_id,  oel.inventory_item_id,  oeh.sold_to_org_id,  oel.invoice_to_contact_id,  oeh.sold_to_contact_id,  oeh.SalesRep_Id,  oeh.org_id,  oeh.order_type_id,  oel.line_type_id,  oel.request_date,  oel.schedule_ship_date,  oeh.attribute12 Branch_Segment

  FROM  fnd_lookup_values_vl lin_status  , oe_order_lines_all oel  , FXAP.SS_PC_E_WAREHOUSE_DATA spw  , mtl_system_items msi  , mtl_item_categories mic  , mtl_categories mc  , oe_order_headers_all oeh  WHERE spw.inventory_item_id=oel.inventory_item_id  and spw.so_shipped_req='Y'  and oel.open_flag not in('Y')  and oeh.org_id=oel.org_id  and lin_status.lookup_type= 'LINE_FLOW_STATUS'

  and oeh.header_id = oel.header_id  and oel.inventory_item_id = msi.inventory_item_id  and oel.ship_from_org_id =msi.organization_id  AND msi.inventory_item_id=mic.inventory_item_id  AND msi.organization_id =mic.organization_id  AND mic.category_set_id=1  AND mic.category_id = mc.category_id  AND mc.structure_id=101  and oel.flow_status_code= lin_status.lookup_code  and oel.flow_status_code='CANCELLED'  and trunc(oel.last_update_date) between (trunc(sysdate)-(120)) and trunc(sysdate);*/

  CURSOR c_org_id  IS  SELECT hou.organization_id  FROM hr_operating_units hou  --WHERE hou.legal_entity_id = p_org_id  ---*** Begin Change for ver 2.1 **** Update by Ni Nyoman Rai on 02Feb 2009 ---

-- WHERE hou.legal_entity_id IN (SELECT orgid -- Commented for CR 264977 by Karthikeyan on 05 Jul 2012

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 77/137

 WHERE hou.default_legal_context_id IN (SELECT orgid -- Added for CR

264977 by Karthikeyan on 05 Jul 2012  FROM ss_pc_e_temp_org)  AND TRUNC (SYSDATE) BETWEEN hou.date_from  AND NVL (hou.date_to, SYSDATE);

---**** End of Changes for ver 2.1 **** ---- 

CURSOR c_ar_detail (  v_line_id IN NUMBER  ,v_order_number IN NUMBER  ,v_org_id IN NUMBER)  IS  SELECT ctl.trx_number  ,ctl.trx_date  , NVL (rat.segment1, '') || NVL (rat.segment2, '')  territory_name  FROM ra_customer_trx_lines_all ctla  ,ra_customer_trx_all ctl  ,ra_territories rat

  WHERE ctla.interface_line_attribute6 = TO_CHAR (v_line_id)  AND ctla.interface_line_attribute1 = TO_CHAR (v_order_number)  AND ctla.org_id = v_org_id  AND ctl.customer_trx_id = ctla.customer_trx_id  AND ctla.org_id = ctl.org_id  AND ctl.territory_id = rat.territory_id(+);

--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 25 Jun 2008 ---  l_file_name VARCHAR2 (100)  := 'FXPC_ITSSLIVE_SHIPPED.dat';  l_file_handler UTL_FILE.file_type;  v_error_msg VARCHAR2 (2000);  l_debug_state VARCHAR2 (2000);

  l_file_heading VARCHAR2 (100);  l_file_trailer VARCHAR2 (100);  l_file_data VARCHAR2 (32767);  v_cnt NUMBER := 0;  v_line_status VARCHAR2 (80);  l_trx_number VARCHAR2 (20);  l_trx_date DATE;  l_territory_name VARCHAR2 (52);  v_sql VARCHAR2 (32767);  v_no_of_days NUMBER;

  TYPE c_refc IS REF CURSOR;

  vc_cursor c_refc;

  TYPE organization_code_tab IS TABLE OF mtl_parameters.organization_code%TYPE;

  TYPE order_number_tab IS TABLE OF oe_order_headers_all.order_number%TYPE;

  TYPE ot_type_tab IS TABLE OF oe_transaction_types_tl.NAME%TYPE;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 78/137

  TYPE ot_line_type_tab IS TABLE OF oe_transaction_types_tl.NAME%TYPE;

  TYPE prod_model_tab IS TABLE OF gl_code_combinations.segment5%TYPE;

  TYPE item_tab IS TABLE OF mtl_system_items_b.segment1%TYPE;

  TYPE line_number_tab IS TABLE OF oe_order_lines_all.line_number%TYPE;

  TYPE shipment_number_tab IS TABLE OF oe_order_lines_all.shipment_number%TYPE;

  TYPE component_number_tab IS TABLE OF oe_order_lines_all.component_number%TYPE;

  TYPE transactional_curr_code_tab IS TABLE OF oe_order_headers_all.transactional_curr_code%TYPE;

  TYPE unit_list_price_tab IS TABLE OF oe_order_lines_all.unit_list_price%TYPE;

  TYPE unit_selling_price_tab IS TABLE OF oe_order_lines_all.unit_selling_ price%TYPE;

  TYPE extended_price_tab IS TABLE OF NUMBER;

  TYPE trx_cost_tab IS TABLE OF NUMBER;

  TYPE line_category_tab IS TABLE OF oe_order_lines_all.line_category_code%TYPE;

  TYPE ordered_quantity_tab IS TABLE OF oe_order_lines_all.ordered_quantity%TYPE;

  TYPE ordered_shipped_qty_tab IS TABLE OF oe_order_lines_all.shipped_quantity%TYPE;

  TYPE transaction_type_id_tab IS TABLE OF NUMBER;

  TYPE mmt_shipped_qty_tab IS TABLE OF oe_order_lines_all.shipped_quantity%TYPE;

  TYPE account_number_tab IS TABLE OF hz_cust_accounts.account_number%TYPE;

  TYPE party_name_tab IS TABLE OF hz_parties.party_name%TYPE;

  TYPE fnd_territories_tab IS TABLE OF fnd_territories.nls_territory%TYPE;

  TYPE sales_channel_code_tab IS TABLE OF hz_cust_accounts.sales_channel_code%TYPE;

  TYPE salesrep_name_tab IS TABLE OF jtf_rs_salesreps.NAME%TYPE;

  TYPE ordered_date_tab IS TABLE OF oe_order_headers_all.ordered_date%TYPE;

  TYPE actual_shipment_date_tab IS TABLE OF oe_order_lines_all.actual_shipment_date%TYPE;

  TYPE cust_po_number_tab IS TABLE OF oe_order_headers_all.cust_po_number%

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 79/137

TYPE;

  TYPE segment1_tab IS TABLE OF mtl_categories.segment1%TYPE;

  TYPE request_date_tab IS TABLE OF oe_order_lines_all.request_date%TYPE;

  TYPE schedule_ship_date_tab IS TABLE OF oe_order_lines_all.schedule_ship _date%TYPE;

  TYPE attribute12_tab IS TABLE OF oe_order_headers_all.attribute12%TYPE;

  TYPE line_id_tab IS TABLE OF oe_order_lines_all.line_id%TYPE;

  TYPE flow_status_code_tab IS TABLE OF oe_order_lines_all.flow_status_code%TYPE;

  TYPE org_id_tab IS TABLE OF oe_order_lines_all.org_id%TYPE;

  -- added by edwin on 28 Sept 2009  TYPE link_to_line_id IS TABLE OF oe_order_lines_all.link_to_line_id%TYPE;

  l_link_to_line_id link_to_line_id;  --

  v_organization_code organization_code_tab;  v_order_number order_number_tab;  v_ot_type ot_type_tab;  v_ot_line_type ot_line_type_tab;  v_prod_model prod_model_tab;  v_item item_tab;  v_line_number line_number_tab;  v_shipment_number shipment_number_tab;  v_component_number component_number_tab;  v_so_display_line_num VARCHAR2 (10);  v_transactional_curr_code transactional_curr_code_tab;  v_unit_list_price unit_list_price_tab;  v_unit_selling_price unit_selling_price_tab;

  v_extended_price extended_price_tab;  v_trx_cost trx_cost_tab;  v_line_category_code line_category_tab;  v_ordered_quantity ordered_quantity_tab;  v_ordered_ship_qty ordered_shipped_qty_tab;  --v_transaction_type_id transaction_type_id_tab;  --v_mmt_shipped_qty mmt_shipped_qty_tab;  ---*** Added for CR#264977 **** Update by Ni Nyoman Rai on 19 Nov 2009 ---  v_transaction_type_idx mtl_material_transactions.transaction

 _type_id%TYPE;  v_mmt_shipped_qtyx mtl_material_transactions.transaction

 _quantity%TYPE;

  ---**** End of Changes for CR#264977 **** ----  v_customer_number account_number_tab;  v_customer_name party_name_tab;  v_bill2country fnd_territories_tab;  v_sales_channel_code sales_channel_code_tab;  v_salesrep_name salesrep_name_tab;  v_ordered_date ordered_date_tab;  v_shipped_date actual_shipment_date_tab;  v_cust_po_number cust_po_number_tab;  v_item_categories segment1_tab;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 80/137

  v_request_date request_date_tab;  v_schedule_ship_date schedule_ship_date_tab;  v_branch_segment attribute12_tab;  v_line_id line_id_tab;  v_flow_status_code flow_status_code_tab;  v_org_id org_id_tab;  v_so_ordered_qty oe_order_lines_all.ordered_quantity%TYPE;  v_so_shipped_qty oe_order_lines_all.shipped_quantity%TYPE;/*  l_file_handler Utl_File.File_type;  File_Close Exception;  l_file_rec1 VARCHAR2(100);  l_file_rec2 VARCHAR2(100);  l_file_rec VARCHAR2(32767);  l_Err_Num NUMBER;  l_Err_Msg VARCHAR2(1000);  cnt NUMBER := 0;  l_territiory_id NUMBER;  l_salesrep_name VARCHAR2(240);  l_salesrep_no VARCHAR2(30);  l_gl_id_rev NUMBER;  l_customer_number VARCHAR2(30);

  l_customer_name VARCHAR2(340);  l_sales_channel_code VARCHAR2(30);  l_bill_contact_phone VARCHAR2(30);  l_ship_contact_phone VARCHAR2(30);  l_ot_type VARCHAR2(240);  l_ot_line_type VARCHAR2(240);  l_trx_cost NUMBER;  v_prod_model VARCHAR2(10);  l_country VARCHAR2(60);  l_bill2country VARCHAR2(250);  l_organization_code VARCHAR2(3);  v_flag VARCHAR2(1);*/

--- **** End of Changes for ver 1.1 **** ----  BEGIN  ---*** Begin Change for ver 2.1 **** Update by Ni Nyoman Rai on 29 Jan 2009 ---  -- SS_PC_E_INSORG(p_org_id); --- *** Remarks for CR#264977 by Ni Nyoman Rai on 17-Nov-09 ***---  ---**** End of Changes for ver 2.1 **** ----  l_debug_state :=  '000 - Open FXPC_ITSSLIVE_SHIPPED.dat file for writing';  l_file_handler :=  UTL_FILE.fopen (p_file_path  ,l_file_name  ,'W'

  ,32767);

  -- get no of days  IF p_no_of_days IS NULL  THEN  BEGIN  SELECT NVL (nof_days, 0)  INTO v_no_of_days  FROM ss_pc_e_wh_data_parameters  WHERE interface_type = 'SHIPPEDREQ';

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 81/137

  EXCEPTION  WHEN OTHERS  THEN  v_no_of_days := NULL;  END;  ELSE  v_no_of_days := p_no_of_days;  END IF;

  fnd_file.put_line (fnd_file.LOG, 'Number of days :' || v_no_of_days);

  IF UTL_FILE.is_open (l_file_handler)  THEN  l_debug_state :=  '001 - Write header into data file';  l_file_heading :=  '01'  || '|'  || 'SO DETAILS'  || '|'  || TO_CHAR (SYSDATE, 'RRRRMMDDHH24MISS');  UTL_FILE.put_line (l_file_handler, l_file_heading);

--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 25 Jun 2008 ---

/*  -- FOR c_inv_org_rec IN c_inv_org LOOP  -- FOR c_inv_item_rec IN c_inv_item LOOP  FOR c_so_detail_rec IN c_so_detail(p_org_id, p_no_of_days) LOOP  IF c_so_detail%ROWCOUNT = 1 THEN  EXECUTE IMMEDIATE 'alter session set events ''10093 trace name context off ''';  END IF;

  BEGIN

  SELECT ctl.TRX_NUMBER ,ctl.TRX_DATE,ctl.territory_id  INTO l_trx_number,l_trx_date,l_territiory_id

  FROM RA_CUSTOMER_TRX_LINES_ALL ctla ,RA_CUSTOMER_TRX_ALL ctl  WHERE ctla.org_id=c_so_detail_rec.org_id  AND ctla.interface_line_attribute6=to_char(c_so_detail_rec.line_id)  AND ctla.CUSTOMER_TRX_ID = ctl.CUSTOMER_TRX_ID  AND ctla.org_id=ctl.org_id;  EXCEPTION  WHEN OTHERS then  l_trx_number :=null;  l_trx_date :=null;  l_territiory_id :=null;  END;

  BEGIN  SELECT rs.name salesrep,rs.salesrep_number,rs.gl_id_rev  INTO l_salesrep_name,l_salesrep_no,l_gl_id_rev  FROM jtf_rs_salesreps rs  WHERE salesrep_id=c_so_detail_rec.salesrep_id;  EXCEPTION  WHEN OTHERS then  l_salesrep_name :=null;  l_salesrep_no :=null;  l_gl_id_rev :=null;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 82/137

  END;

  BEGIN

  SELECT hca.account_number, hp.party_name,hca.sales_channel_code,hp.country  INTO l_customer_number,l_customer_name,l_sales_channel_code,l_country  FROM hz_cust_accounts hca,  hz_parties hp  WHERE hca.cust_account_id=c_so_detail_rec.sold_to_org_id  AND hca.party_id=hp.party_id;  EXCEPTION  WHEN OTHERS then  l_customer_number :=null;  l_customer_name :=null;  l_sales_channel_code :=null;  END;

  IF c_so_detail_rec.invoice_to_contact_id is not null then  BEGIN  SELECT rpb.phone_number  INTO l_bill_contact_phone  FROM ra_phones rpb  WHERE rpb.contact_id =c_so_detail_rec.invoice_to_contact_id

  AND (( rpb.phone_type IN ('GEN','TEL', 'MOBILE') and rpb.primary_flag = 'Y')  OR rpb.phone_type IS NULL);  EXCEPTION  WHEN OTHERS then  l_bill_contact_phone :=null;  END;  END IF;

  IF c_so_detail_rec.sold_to_contact_id is not null then  BEGIN  SELECT rps.phone_number  INTO l_ship_contact_phone

  FROM ra_phones rps  WHERE rps.contact_id =c_so_detail_rec.sold_to_contact_id  AND (( rps.phone_type IN ('GEN','TEL', 'MOBILE') and rps.primary_flag= 'Y')  OR rps.phone_type IS NULL) ;

  EXCEPTION  WHEN OTHERS then  l_ship_contact_phone :=null;  END;  END IF;

  BEGIN

  SELECT name  INTO l_ot_type  FROM oe_transaction_types_tl tvh  WHERE tvh.transaction_type_id=c_so_detail_rec.order_type_id  AND tvh.LANGUAGE = USERENV('LANG');  EXCEPTION  WHEN OTHERS then  l_ot_type :=null;  END;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 83/137

  BEGIN  SELECT name  INTO l_ot_line_type  FROM oe_transaction_types_tl tvl  WHERE tvl.transaction_type_id=c_so_detail_rec.line_type_id  AND tvl.LANGUAGE = USERENV('LANG');  EXCEPTION  WHEN OTHERS then  l_ot_line_type :=null;  END;

  BEGIN  SELECT nvl(mmt.actual_cost,0)  INTO l_trx_cost  FROM mtl_material_transactions mmt  WHERE mmt.transaction_type_id = 33  AND mmt.trx_source_line_id = c_so_detail_rec.line_id  AND mmt.organization_id =c_so_detail_rec.ship_from_org_id ;  EXCEPTION  WHEN OTHERS then  l_trx_cost :=0;  END;  IF l_gl_id_rev is not null then  BEGIN

  SELECT segment5  INTO v_prod_model  FROM gl_code_combinations  WHERE code_combination_id=c_so_detail_rec.cost_of_sales_account;  EXCEPTION  WHEN OTHERS then  v_prod_model :=null;  END;  END IF;  IF l_country is not null then  BEGIN  SELECT nls_territory

  INTO l_bill2country  FROM FND_TERRITORIES  WHERE territory_code =l_country;  EXCEPTION  WHEN OTHERS then  l_bill2country :=null;  END;  END IF;  IF l_territiory_id is not null then

  BEGIN  SELECT NVL(SEGMENT1,'') || NVL(SEGMENT2,'')  INTO l_territory_name

  FROM Ra_Territories  WHERE Territory_Id = l_territiory_id;  EXCEPTION  WHEN OTHERS then  l_territory_name :='n.a';  END;  END IF;

  BEGIN  SELECT mp.organization_code

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 84/137

  INTO l_organization_code  FROM mtl_parameters mp  WHERE organization_id=c_so_detail_rec.ship_from_org_id;  EXCEPTION  WHEN NO_DATA_FOUND then  l_organization_code :=null;  WHEN OTHERS then  l_organization_code :=null;

  END;

  l_file_rec :='02'||'|'||l_organization_code||'|'||c_so_detail_rec.order_ number||'|'||  l_ot_type||'|'||l_ot_line_type||'|'||  v_prod_model||'|'||c_so_detail_rec.item||'|'||c_so_detail_ rec.line_number||'|'||  c_so_detail_rec.transactional_curr_code||'|'||c_so_detail_ rec.Unit_list_price||'|'||  c_so_detail_rec.unit_selling_price||'|'||c_so_detail_rec.extended_price||'|'||  l_trx_cost||'|'||c_so_detail_rec.ordered_quantity||'|'||  c_so_detail_rec.shipped_qty||'|'||l_customer_number||'|'||l_customer_name||'|'||  l_bill2country||'|'||l_territory_name||'|'||l_sales_channe

l_code||'|'||  l_salesrep_name||'|'||c_so_detail_rec.ordered_date||'|'||c _so_detail_rec.shipped_date||'|'||  l_trx_number||'|'||l_trx_date||'|'||c_so_detail_rec.cust_po_number||'|'||  c_so_detail_rec.item_categories||'|'||c_so_detail_rec.line_status||'|'||  c_so_detail_rec.request_date||'|'||c_so_detail_rec.schedule_ship_date||'|'||  c_so_detail_rec.branch_segment ;

  Utl_File.put_line(l_file_handler,l_file_rec);  cnt := cnt +1;

-- END LOOP;  -- END LOOP;  --END LOOP;*/  -- FOR vc_org IN c_org_id LOOP  EXECUTE IMMEDIATE 'alter session set events ''10093 trace name context forever ''';

  -- query shipped SO  ---*** Begin Change for CR#264977 **** Update by Ni Nyoman Rai on 19 Nov 2009 ---  v_sql :=  ' SELECT spw.organization_code,

  spw.order_number,  spw.ot_type,  spw.ot_line_type,  spw.prod_model,  spw.item,  spw.line_number,  spw.shipment_number,  spw.component_number,  spw.transactional_curr_code,  spw.unit_list_price,

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 85/137

  spw.unit_selling_price,  spw.extended_price,  spw.trx_cost,  spw.line_category_code,  spw.ordered_quantity,  spw.shipped_quantity,  spw.customer_number,  spw.customer_name,  spw.bill2country,  spw.sales_channel_code,  spw.salesrep_name,  spw.ordered_date,  spw.shipped_date,  spw.cust_po_number,  spw.item_categories,  spw.request_date,  spw.schedule_ship_date,  spw.branch_segment,  spw.line_id,  spw.flow_status_code,  spw.org_id  FROM ss_pc_e_warehouse_data_temp spw  WHERE spw.open_flag = ''N''  AND spw.cancelled_flag = ''N''';

  --'SELECT /*+ parallel(oel,4) parallel(oeh,4) parallel(mic,8) parallel(msi,4) '||  --' parallel(mmt,4) full(mmt)*/ '||  --'SELECT /*+ parallel(oel,4) parallel(oeh,4) parallel(mic,8) parallel(msi,4) '||  -- ' parallel(mmt,4) full(mmt)*/ '||  /* ' mp.organization_code, '||  ' oeh.order_number, '||  ' oeh_type.name ot_type, '||  ' oel_type.name ot_line_type, '||  ' gcc.segment5 prod_model, '||  ' msi.segment1 item, '||

  ' oel.line_number, '||  ' oel.shipment_number, '||  ' oel.component_number, '||  ' oeh.transactional_curr_code, '||  ' oel.unit_list_price, '||  ' oel.unit_selling_price, '||  ' oel.ordered_quantity * oel.unit_selling_price extended_price, '||  ' nvl(mmt.actual_cost,0) trx_cost, '||  ' oel.line_category_code, '||  ' oel.ordered_quantity ordered_quantity, '||  ' oel.shipped_quantity ordered_shipped_quantity, '||  ' mmt.transaction_type_id, '||

  ' sum(abs(mmt.transaction_quantity)) mmt_quantity, '||  ' hca.account_number customer_number, '||  ' hp.party_name customer_name, '||  ' ft.nls_territory bill2country, '||  ' hca.sales_channel_code, '||  ' rs.name salesrep_name, '||  ' oeh.ordered_date, '||  ' oel.actual_shipment_date shipped_date, '||  ' oeh.cust_po_number cust_po_number, '||  ' mc.segment1 item_categories, '||

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 86/137

  ' oel.request_date, '||  ' oel.schedule_ship_date, '||  ' oeh.attribute12 branch_segment, '||  ' oel.line_id, '||  ' oel.flow_status_code, '||  ' oel.org_id '||  ' FROM ss_pc_e_warehouse_data spw, '||  ' oe_order_lines_all oel, '||  ' oe_order_headers_all oeh, '||  ' mtl_system_items_b msi, '||  ' mtl_item_categories mic, '||  ' mtl_categories_b mc, '||  ' mtl_parameters mp, '||  ' oe_transaction_types_tl oeh_type, '||  ' oe_transaction_types_tl oel_type, '||  ' gl_code_combinations gcc, '||  ' mtl_material_transactions mmt, '||  ' hz_cust_accounts hca, '||  ' hz_parties hp, '||  ' jtf_rs_salesreps rs, '||  ' fnd_territories ft '||  ' WHERE spw.so_shipped_req = ''Y'' '||  ' AND oel.org_id = :p_ou_id '||  ' AND oel.inventory_item_id = spw.inventory_item_id '||

  ' AND NVL(oel.actual_shipment_date,TRUNC(oel.last_update_date)) BETWEEN (trunc(sysdate)- :p_num_days) AND SYSDATE '||  ' AND oel.open_flag = ''N'' '||  ' AND oel.cancelled_flag = ''N'' '||  ' AND oeh.header_id = oel.header_id '||  ' AND msi.inventory_item_id = oel.inventory_item_id '||  ' AND msi.organization_id = oel.ship_from_org_id '||  ' AND mic.inventory_item_id = msi.inventory_item_id '||  ' AND mic.organization_id = msi.organization_id '||  ' AND mic.category_set_id = 1 '||  ' AND mc.category_id = mic.category_id '||  ' AND mp.organization_id = oel.ship_from_org_id '||  ' AND oeh_type.transaction_type_id = oeh.order_type_id '||

  ' AND oeh_type.language = USERENV(''LANG'') '||  ' AND oel_type.transaction_type_id = oel.line_type_id '||  ' AND oel_type.language = USERENV(''LANG'') '||  ' AND msi.cost_of_sales_account = gcc.code_combination_id '||  ' AND mmt.transaction_type_id(+) = 33 '||  ' AND oel.line_id = mmt.trx_source_line_id (+) '||  ' AND hca.cust_account_id = oel.sold_to_org_id '||  ' AND hca.party_id = hp.party_id '||  ' AND oeh.salesrep_id = rs.salesrep_id(+) '||  ' AND oeh.org_id = rs.org_id(+) '||  ' AND hp.country = ft.territory_code(+) '||  ' GROUP BY '||  ' mp.organization_code, '||

  ' oeh.order_number, '||  ' oeh_type.name, '||  ' oel_type.name, '||  ' gcc.segment5, '||  ' msi.segment1, '||  ' oel.line_number, '||  ' oel.shipment_number, '||  ' oel.component_number, '||  ' oeh.transactional_curr_code, '||  ' oel.unit_list_price, '||

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 87/137

  ' oel.unit_selling_price, '||  ' oel.ordered_quantity * oel.unit_selling_price, '||  ' nvl(mmt.actual_cost,0), '||  ' oel.line_category_code, '||  ' oel.ordered_quantity, '||  ' oel.shipped_quantity, '||  ' mmt.transaction_type_id, '||  ' hca.account_number, '||  ' hp.party_name, '||  ' ft.nls_territory, '||  ' hca.sales_channel_code, '||  ' rs.name, '||  ' oeh.ordered_date, '||  ' oel.actual_shipment_date, '||  ' oeh.cust_po_number, '||  ' mc.segment1, '||  ' oel.request_date, '||  ' oel.schedule_ship_date, '||  ' oeh.attribute12, '||  ' oel.line_id, '||  ' oel.flow_status_code, '||  ' oel.org_id ' ;*/

  --- *** End of Remarks for CR#264977 by Ni Nyoman Rai on 17-Nov-09 *

**---  -- OPEN vc_cursor FOR v_sql;

  -- USING vc_org.organization_id, v_no_of_days;---Remarks for CR#264977 by Ni Nyoman Rai on 17-Nov-09 ***---  OPEN vc_cursor FOR v_sql;

  IF vc_cursor%ISOPEN  THEN  BEGIN  l_debug_state :=  '002 - Fetch SO Shipped data';

  FETCH vc_cursor  BULK COLLECT INTO v_organization_code  ,v_order_number  ,v_ot_type  ,v_ot_line_type  ,v_prod_model  ,v_item  ,v_line_number  ,v_shipment_number  ,v_component_number  ,v_transactional_curr_code  ,v_unit_list_price  ,v_unit_selling_price

  ,v_extended_price  ,v_trx_cost  ,v_line_category_code  ,v_ordered_quantity  ,v_ordered_ship_qty  ,  --v_transaction_type_id,  --v_mmt_shipped_qty,  v_customer_number  ,v_customer_name

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 88/137

  ,v_bill2country  ,v_sales_channel_code  ,v_salesrep_name  ,v_ordered_date  ,v_shipped_date  ,v_cust_po_number  ,v_item_categories  ,v_request_date  ,v_schedule_ship_date  ,v_branch_segment  ,v_line_id  ,v_flow_status_code  ,v_org_id;

  EXECUTE IMMEDIATE 'alter session set events ''10093 trace name context off ''';

  IF v_organization_code.FIRST IS NOT NULL  THEN  FOR i IN 1 .. v_organization_code.LAST  LOOP  l_trx_number := NULL;  l_trx_date := NULL;  l_territory_name := NULL;

  l_debug_state :=  '003 - Query AR transaction information for line id '  || TO_CHAR (v_line_id (i) );

  FOR c_ar_detail_rec IN  c_ar_detail (v_line_id (i)  ,v_order_number (i)  ,v_org_id (i) )  LOOP  l_trx_number :=  c_ar_detail_rec.trx_number;  l_trx_date :=

  c_ar_detail_rec.trx_date;  l_territory_name :=  c_ar_detail_rec.territory_name;  END LOOP;

  IF l_territory_name IS NULL  THEN  l_territory_name := 'n.a';  END IF;

  l_debug_state :=  '004 - Get line status for line id '  || TO_CHAR (v_line_id (i) );

  BEGIN  -- get sales order line status using API  v_line_status :=  oe_line_status_pub.get_line_status  (v_line_id (i)  ,v_flow_status_code (i) );  EXCEPTION  WHEN OTHERS  THEN

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 89/137

  v_line_status := NULL;  END;

  /* IF v_line_category_code (i) = 'RETURN'  THEN  v_so_ordered_qty :=  v_ordered_quantity (i);  --* -1;  ELSE*/ /*Remark for case id:362206 on 23-Aug-2010 by Ni Nyoman Rai*/  v_so_ordered_qty := v_ordered_quantity (i);  -- END IF; /*Remark for case id:362206 on 23-Aug-2010 by Ni Nyoman Rai*/

  ---*** Begin Change for CR#264977 **** Update by NiNyoman Rai on 19 Nov 2009 ---  BEGIN  SELECT transaction_type_id  INTO v_transaction_type_idx  FROM mtl_material_transactions  WHERE trx_source_line_id = v_line_id (i);  EXCEPTION  WHEN OTHERS  THEN

  v_transaction_type_idx := NULL;  END;

  IF v_line_category_code (i) = 'RETURN'  THEN  v_so_shipped_qty :=  v_ordered_ship_qty (i);  --* -1; */Remark for case id:362206 on 23-Aug-2010 by Ni Nyoman Rai*/  ELSIF v_transaction_type_idx = 33  THEN  BEGIN  SELECT SUM (ABS (transaction_quantity) )

  INTO v_mmt_shipped_qtyx  FROM mtl_material_transactions  WHERE trx_source_line_id = v_line_id (i)  AND transaction_type_id =  v_transaction_type_idx;  EXCEPTION  WHEN OTHERS  THEN  v_mmt_shipped_qtyx :=  NULL;  END;

  v_so_shipped_qty :=

  v_mmt_shipped_qtyx;  ELSE  v_so_shipped_qty :=  v_ordered_ship_qty (i);  END IF;

  /* IF v_line_category_code(i) = 'RETURN' THEN  v_so_shipped_qty := v_ordered_ship_qty(i) * -1;  ELSIF v_transaction_type_id(i) = 33 THEN  v_so_shipped_qty := v_mmt_shipped_qty(i);

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 90/137

  ELSE  v_so_shipped_qty := v_ordered_ship_qty(i);  END IF;*/

  ---**** End of Changes for CR#264977 **** ----  v_so_display_line_num :=  TO_CHAR (v_line_number (i) );

  IF v_shipment_number (i) IS NOT NULL  THEN  v_so_display_line_num :=  v_so_display_line_num  || '.'  || TO_CHAR (v_shipment_number (i) );  END IF;

  IF v_component_number (i) IS NOT NULL  THEN  v_so_display_line_num :=  v_so_display_line_num  || '..'  || TO_CHAR (v_component_number (i) );  END IF;

  l_debug_state :=  '005 - Construct SO Shipped data for line id'  || TO_CHAR (v_line_id (i) );  l_file_data :=  '02'  || '|'  || v_organization_code (i)  || '|'  || v_order_number (i)  || '|'  || v_ot_type (i)  || '|'

  || v_ot_line_type (i)  || '|'  || v_prod_model (i)  || '|'  || v_item (i)  || '|'  || v_so_display_line_num  || '|'  || v_transactional_curr_code (i)  || '|'  || v_unit_list_price (i)  || '|'  || v_unit_selling_price (i)

  || '|'  || v_extended_price (i)  || '|'  || v_trx_cost (i)  || '|'  || v_so_ordered_qty  || '|'  || v_so_shipped_qty  || '|'  || v_customer_number (i)

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 91/137

  || '|'  || v_customer_name (i)  || '|'  || v_bill2country (i)  || '|'  || l_territory_name  || '|'  || v_sales_channel_code (i)  || '|'  || v_salesrep_name (i)  || '|'  || v_ordered_date (i)  || '|'  || v_shipped_date (i)  || '|'  || l_trx_number  || '|'  || l_trx_date  || '|'  || v_cust_po_number (i)  || '|'  || v_item_categories (i)  || '|'  || v_line_status

  || '|'  || v_request_date (i)  || '|'  || v_schedule_ship_date (i)  || '|'  || v_branch_segment (i);  l_debug_state :=  '006 - Write SO Shipped data for line id '  || TO_CHAR (v_line_id (i) )  || ' into data file ';  UTL_FILE.put_line (l_file_handler, l_file_data);  v_cnt := v_cnt + 1;  END LOOP;

  END IF;

  CLOSE vc_cursor;  EXCEPTION  WHEN OTHERS  THEN  IF vc_cursor%ISOPEN  THEN  CLOSE vc_cursor;  END IF;

  RAISE;  END;

  END IF;

  -- query cancel SO-- v_sql := 'SELECT /*+ ORDERED NO_MERGE(mc) USE_NL(oel,oeh,spw,msi,mic,hca,hp,rs,oeh_type,oel_type,gcc) USE_HASH(mc) */  v_sql :=  'SELECT spw.organization_code,  spw.order_number,  spw.ot_type,  spw.ot_line_type,

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 92/137

  spw.prod_model,  spw.item,  spw.line_number,  spw.shipment_number,  spw.component_number,  spw.transactional_curr_code,  spw.unit_list_price,  spw.unit_selling_price,  spw.extended_price,  0 trx_cost,  spw.ordered_quantity,  spw.shipped_quantity,  spw.customer_number,  spw.customer_name,  spw.bill2country,  spw.sales_channel_code,  spw.salesrep_name,  spw.ordered_date,  spw.shipped_date,  spw.cust_po_number,  spw.item_categories,  spw.request_date,  spw.schedule_ship_date,  spw.branch_segment,

  spw.line_id,  spw.flow_status_code,  spw.org_id  FROM ss_pc_e_warehouse_data_temp spw  WHERE spw.open_flag = ''N''  AND spw.cancelled_flag = ''Y''  AND spw.flow_status_code = ''CANCELLED''';

  ---*** Begin Change for CR#264977 **** Update by Ni Nyoman Rai on 19 Nov 2009 ---  -- 'SELECT /*+ ORDERED */  /* mp.organization_code,  oeh.order_number,

  oeh_type.name ot_type,  oel_type.name ot_line_type,  gcc.segment5 prod_model,  msi.segment1 item,  oel.line_number,  oel.shipment_number,  oel.component_number,  oeh.transactional_curr_code,  oel.unit_list_price,  oel.unit_selling_price,  oel.ordered_quantity * oel.unit_selling_price extended_price,  0 trx_cost,

  DECODE(oel.line_category_code,''RETURN'',oel.ordered _quantity*-1,oel.ordered_quantity) ordered_quantity,  DECODE(oel.line_category_code,''RETURN'',oel.shipped

 _quantity*-1,oel.shipped_quantity) shipped_quantity,  hca.account_number customer_number,  hp.party_name customer_name,  ft.nls_territory bill2country,  hca.sales_channel_code,  rs.name salesrep_name,  oeh.ordered_date,

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 93/137

  oel.actual_shipment_date shipped_date,  oeh.cust_po_number cust_po_number,  mc.segment1 item_categories,  oel.request_date,  oel.schedule_ship_date,  oeh.attribute12 branch_segment,  oel.line_id,  oel.flow_status_code,  oel.org_id  FROM oe_order_lines_all oel,  ss_pc_e_warehouse_data spw,  oe_order_headers_all oeh,  mtl_system_items_b msi,  mtl_item_categories mic,  mtl_categories_b mc,  mtl_parameters mp,  oe_transaction_types_tl oeh_type,  oe_transaction_types_tl oel_type,  gl_code_combinations gcc,  hz_cust_accounts hca,  hz_parties hp,  jtf_rs_salesreps rs,  fnd_territories ft  WHERE TRUNC(oel.last_update_date) BETWEEN (trunc(sysdate)-

:p_num_days) AND SYSDATE  AND oel.open_flag = ''N''  AND oel.cancelled_flag = ''Y''  AND oel.flow_status_code = ''CANCELLED''  AND oel.inventory_item_id = spw.inventory_item_id  AND oel.org_id = :p_ou_id  AND spw.so_shipped_req = ''Y''  AND oeh.header_id = oel.header_id  AND msi.inventory_item_id = oel.inventory_item_id  AND msi.organization_id = oel.ship_from_org_id  AND mic.inventory_item_id = msi.inventory_item_id  AND mic.organization_id = msi.organization_id  AND mic.category_set_id = 1

  AND mc.category_id = mic.category_id  AND mp.organization_id = oel.ship_from_org_id  AND oeh_type.transaction_type_id = oeh.order_type_id  AND oeh_type.language = USERENV(''LANG'')  AND oel_type.transaction_type_id = oel.line_type_id  AND oel_type.language = USERENV(''LANG'')  AND msi.cost_of_sales_account = gcc.code_combination_id  AND hca.cust_account_id = oel.sold_to_org_id  AND hca.party_id = hp.party_id  AND oeh.salesrep_id = rs.salesrep_id(+)  AND oeh.org_id = rs.org_id(+)  AND hp.country = ft.territory_code(+)';*/  ---**** End of Changes for CR#264977 **** ----

  OPEN vc_cursor FOR v_sql;

  -- USING v_no_of_days, vc_org.organization_id; --Remarks for CR#264977 **** Update by Ni Nyoman Rai on 19 Nov 2009 ---  IF vc_cursor%ISOPEN  THEN  BEGIN  l_debug_state :=  '002 - Fetch SO Cancellation data';

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 94/137

  FETCH vc_cursor  BULK COLLECT INTO v_organization_code  ,v_order_number  ,v_ot_type  ,v_ot_line_type  ,v_prod_model  ,v_item  ,v_line_number  ,v_shipment_number  ,v_component_number  ,v_transactional_curr_code  ,v_unit_list_price  ,v_unit_selling_price  ,v_extended_price  ,v_trx_cost  ,v_ordered_quantity  ,v_ordered_ship_qty  ,v_customer_number  ,v_customer_name  ,v_bill2country  ,v_sales_channel_code  ,v_salesrep_name  ,v_ordered_date  ,v_shipped_date

  ,v_cust_po_number  ,v_item_categories  ,v_request_date  ,v_schedule_ship_date  ,v_branch_segment  ,v_line_id  ,v_flow_status_code  ,v_org_id;

  IF v_organization_code.FIRST IS NOT NULL  THEN  FOR i IN 1 .. v_organization_code.LAST  LOOP

  l_trx_number := NULL;  l_trx_date := NULL;  l_territory_name := NULL;  l_debug_state :=  '003 - Query AR transaction information for line id '  || TO_CHAR (v_line_id (i) );

  FOR c_ar_detail_rec IN  c_ar_detail (v_line_id (i)  ,v_order_number (i)  ,v_org_id (i) )  LOOP

  l_trx_number :=  c_ar_detail_rec.trx_number;  l_trx_date :=  c_ar_detail_rec.trx_date;  l_territory_name :=  c_ar_detail_rec.territory_name;  END LOOP;

  IF l_territory_name IS NULL  THEN

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 95/137

  l_territory_name := 'n.a';  END IF;

  l_debug_state :=  '004 - Get line status for line id '  || TO_CHAR (v_line_id (i) );

  BEGIN  -- get sales order line status using API  v_line_status :=  oe_line_status_pub.get_line_status  (v_line_id (i)  ,v_flow_status_code (i) );  EXCEPTION  WHEN OTHERS  THEN  v_line_status := NULL;  END;

  v_so_display_line_num :=  TO_CHAR (v_line_number (i) );

  IF v_shipment_number (i) IS NOT NULL  THEN

  v_so_display_line_num :=  v_so_display_line_num  || '.'  || TO_CHAR (v_shipment_number (i) );  END IF;

  IF v_component_number (i) IS NOT NULL  THEN  v_so_display_line_num :=  v_so_display_line_num  || '..'  || TO_CHAR (v_component_number (i) );  END IF;

  l_debug_state :=  '005 - Construct SO Cancellation data for line id '  || TO_CHAR (v_line_id (i) );  l_file_data :=  '02'  || '|'  || v_organization_code (i)  || '|'  || v_order_number (i)  || '|'  || v_ot_type (i)

  || '|'  || v_ot_line_type (i)  || '|'  || v_prod_model (i)  || '|'  || v_item (i)  || '|'  || v_so_display_line_num  || '|'  || v_transactional_curr_code (i)

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 96/137

  || '|'  || v_unit_list_price (i)  || '|'  || v_unit_selling_price (i)  || '|'  || v_extended_price (i)  || '|'  || v_trx_cost (i)  || '|'  || v_ordered_quantity (i)  || '|'  || v_ordered_ship_qty (i)  || '|'  || v_customer_number (i)  || '|'  || v_customer_name (i)  || '|'  || v_bill2country (i)  || '|'  || l_territory_name  || '|'  || v_sales_channel_code (i)  || '|'  || v_salesrep_name (i)

  || '|'  || v_ordered_date (i)  || '|'  || v_shipped_date (i)  || '|'  || l_trx_number  || '|'  || l_trx_date  || '|'  || v_cust_po_number (i)  || '|'  || v_item_categories (i)  || '|'

  || v_line_status  || '|'  || v_request_date (i)  || '|'  || v_schedule_ship_date (i)  || '|'  || v_branch_segment (i);  l_debug_state :=  '006 - Write SO Cancellation data for line id '  || TO_CHAR (v_line_id (i) )  || ' into data file ';  UTL_FILE.put_line (l_file_handler, l_file_data);

  v_cnt := v_cnt + 1;  END LOOP;  END IF;

  CLOSE vc_cursor;  EXCEPTION  WHEN OTHERS  THEN  IF vc_cursor%ISOPEN  THEN

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 97/137

  CLOSE vc_cursor;  END IF;

  RAISE;  END;  END IF;

  -- END LOOP;--- **** End of Changes for ver 1.1 **** ----  l_debug_state :=  '007 - Write trailer data into data file ';  l_file_trailer :=  '03'  || '|'  || TO_CHAR (v_cnt)  || '|'  || TO_CHAR (SYSDATE, 'RRRRMMDDHH24MISS');  UTL_FILE.put_line (l_file_handler, l_file_trailer);  UTL_FILE.fclose (l_file_handler);  fnd_file.put_line (fnd_file.output, 'Number of rows ' || v_cnt);  ELSE  fnd_file.put_line (fnd_file.LOG  , 'File :'  || l_file_name

  || ', is not open for writing.');  raise_application_error (-20000  , 'File :'  || l_file_name  || ' is not open for writing.');  END IF;

--- *** Begin Change for ver 1.1 **** Update by Willy Tan on 25 Jun 2008 ---  -- send data file into FXPC server  ss_pc_e_warehouse_iface_k.ss_pc_e_run_ftp_p (l_file_name);--- **** End of Changes for ver 1.1 **** ----  EXCEPTION  WHEN UTL_FILE.invalid_path

  THEN  ROLLBACK;  raise_application_error  (-20001  ,'Error while opening the file. Invalid Directory or File name.');  WHEN UTL_FILE.invalid_mode  THEN  ROLLBACK;  raise_application_error  (-20002  ,'Error while opening the file or checking if file is open. Invalid Mode.');

  WHEN UTL_FILE.invalid_operation  THEN  ROLLBACK;  raise_application_error  (-20003  ,'Error while opening the file or writing a new line. Invalid Operation.');  WHEN UTL_FILE.invalid_filehandle  THEN  ROLLBACK;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 98/137

  raise_application_error  (-20004  ,'Error in checking if file is open or writing a new line. Invalid File Handle.');  WHEN UTL_FILE.write_error  THEN  ROLLBACK;  raise_application_error  (-20005  ,'Error in closing file or writing a new line. OS error duringwrite operation.');  WHEN UTL_FILE.read_error  THEN  ROLLBACK;  raise_application_error (-20006, 'Error in defining file type.');  WHEN UTL_FILE.internal_error  THEN  ROLLBACK;  raise_application_error (-20007, 'Error in defining file type.');  WHEN OTHERS  THEN  ROLLBACK;  v_error_msg := SUBSTR (SQLERRM  ,1

  ,2000);  fnd_file.put_line (fnd_file.LOG  , 'Error in process :' || l_debug_state);  fnd_file.put_line (fnd_file.LOG, 'Error message :' || v_error_msg);  RAISE;  END ss_pc_e_so_shipped_iface_p;

/****-- Procedure name : SS_PC_E_WH_SO_DETAILS-- Purpose : Extract SO shipped and cancellation information from ITSS into staging table.-- Parameter :-- - p_org_id -> extracted legal entity id

-- - p_no_of_days -> number of days****/  PROCEDURE ss_pc_e_wh_so_details (  errbuf OUT VARCHAR2  ,retcode OUT VARCHAR2  ,p_org_id IN VARCHAR2)  IS  TYPE c_refc IS REF CURSOR;

  vc_cursor c_refc;  n_header_id DBMS_SQL.number_table;  n_line_number DBMS_SQL.number_table;  n_shipment_number DBMS_SQL.number_table;

  n_component_number DBMS_SQL.number_table;  n_unit_list_price DBMS_SQL.number_table;  n_unit_selling_price DBMS_SQL.number_table;  n_extended_price DBMS_SQL.number_table;  n_ordered_quantity DBMS_SQL.number_table;  n_shipped_quantity DBMS_SQL.number_table;  n_shipped_date DBMS_SQL.date_table;  n_request_date DBMS_SQL.date_table;  n_schedule_ship_date DBMS_SQL.date_table;  n_line_id DBMS_SQL.number_table;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 99/137

  n_flow_status_code DBMS_SQL.varchar2_table;  n_org_id DBMS_SQL.number_table;  n_link_to_line_id DBMS_SQL.number_table;  n_top_model_line_id DBMS_SQL.number_table;  n_inventory_item_id DBMS_SQL.number_table;  n_ship_from_org_id DBMS_SQL.number_table;  n_line_type_id DBMS_SQL.number_table;  n_sold_to_org_id DBMS_SQL.number_table;  n_open_flag DBMS_SQL.varchar2_table;  n_cancelled_flag DBMS_SQL.varchar2_table;  n_line_category_code DBMS_SQL.varchar2_table;  v_link_to_line NUMBER;  b_inventory_item_id NUMBER;  b_line_number NUMBER;  b_shipment_number NUMBER;  b_component_number NUMBER;  b_unit_list_price NUMBER;  b_unit_selling_price NUMBER;  b_extended_price NUMBER;  b_ordered_quantity NUMBER;  b_shipped_quantity NUMBER;  b_shipped_date DATE;  b_request_date DATE;  b_schedule_ship_date DATE;

  b_line_id NUMBER;  b_flow_status_code VARCHAR2 (30);  b_organization_code VARCHAR2 (7);  b_ot_type VARCHAR2 (30);  b_ot_line_type VARCHAR2 (30);  b_prod_model VARCHAR2 (25);  b_item VARCHAR2 (40);  b_trx_cost NUMBER;  b_ship_from_org_id NUMBER;  b_link_to_line_id NUMBER;  b_open_flag VARCHAR2 (1);  b_cancelled_flag VARCHAR2 (1);  b_line_category_code VARCHAR2 (30);

  v_sql VARCHAR2 (32767);  v_no_of_days NUMBER;  m_organization_code mtl_parameters.organization_code%TYPE;  m_order_number oe_order_headers_all.order_number%TYPE;  m_ot_type oe_transaction_types_tl.NAME%TYPE;  m_ot_line_type oe_transaction_types_tl.NAME%TYPE;  m_prod_model gl_code_combinations.segment5%TYPE;  m_item mtl_system_items.segment1%TYPE;  m_transactional_curr_code oe_order_headers_all.transactional_curr_code%TYPE;  m_trx_cost mtl_material_transactions.actual_cost

%TYPE;  m_ordered_date oe_order_headers_all.ordered_date%TYPE;  m_cust_po_number oe_order_headers_all.cust_po_number%TYPE;  m_item_categories mtl_categories_b.segment1%TYPE;  m_branch_segment oe_order_headers_all.attribute12%TYPE;  m_account_number hz_cust_accounts.account_number%TYPE;  m_party_name hz_parties.party_name%TYPE;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 100/137

  m_sales_channel_code hz_cust_accounts.sales_channel_code%TYPE;  m_salesrep_name jtf_rs_salesreps.NAME%TYPE;  m_bill2country fnd_territories.nls_territory%TYPE;

  CURSOR c_org_id  IS  SELECT hou.organization_id  FROM hr_operating_units hou 

where hou.default_legal_context_id IN (SELECT orgid --- Added CR 264977 karthikeyan on 06-Jul-2012  -- WHERE hou.legal_entity_id IN (SELECT orgid -- Commented CR 264977 Karthikeyan on 06-Jul-2012  FROM ss_pc_e_temp_org)  AND TRUNC (SYSDATE) BETWEEN hou.date_from  AND NVL (hou.date_to, SYSDATE);

  CURSOR c_order_num  IS  SELECT order_number  ,top_model_line_id  FROM ss_pc_e_warehouse_data_temp  GROUP BY order_number

  ,top_model_line_id  ,org_id;  BEGIN  EXECUTE IMMEDIATE 'TRUNCATE TABLE FXAP.SS_PC_E_WAREHOUSE_DATA_TEMP';

  ss_pc_e_insorg (p_org_id);

  BEGIN  SELECT NVL (nof_days, 0)  INTO v_no_of_days  FROM ss_pc_e_wh_data_parameters  WHERE interface_type = 'SHIPPEDREQ';  EXCEPTION

  WHEN OTHERS  THEN  v_no_of_days := NULL;  END;

  v_sql :=  'select oel.header_id,  oel.line_number,  oel.shipment_number,  oel.component_number,  oel.unit_list_price,  oel.unit_selling_price,  oel.ordered_quantity * oel.unit_selling_price extended_pric

e,  DECODE(oel.line_category_code,''RETURN'',oel.ordered_quantity*-1,oel.ordered_quantity) ordered_quantity,  NVL(DECODE(oel.line_category_code,''RETURN'',oel.shipped_quantity*-1,oel.shipped_quantity),0) shipped_quantity,  oel.actual_shipment_date shipped_date,  oel.request_date,  oel.schedule_ship_date,  oel.line_id line_id,  oel.flow_status_code flow_status_code,

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 101/137

  oel.org_id, oel.link_to_line_id,oel.top_model_line_id,  oel.inventory_item_id,  oel.ship_from_org_id,  oel.line_type_id,  oel.sold_to_org_id,  oel.open_flag,  oel.cancelled_flag,  oel.line_category_code  from ss_pc_e_warehouse_data spw,  oe_order_lines_all oel  where spw.so_req = ''Y''  and oel.inventory_item_id = spw.inventory_item_id  and oel.org_id = :aa  AND oel.open_flag = ''Y''  AND oel.cancelled_flag = ''N''  UNION  select oel.header_id,  oel.line_number,  oel.shipment_number,  oel.component_number,  oel.unit_list_price,  oel.unit_selling_price,  oel.ordered_quantity * oel.unit_selling_price extended_price,

  DECODE(oel.line_category_code,''RETURN'',oel.ordered_quantity*-1,oel.ordered_quantity) ordered_quantity,  NVL(DECODE(oel.line_category_code,''RETURN'',oel.shipped_quantity*-1,oel.shipped_quantity),0) shipped_quantity,  oel.actual_shipment_date shipped_date,  oel.request_date,  oel.schedule_ship_date,  oel.line_id line_id,  oel.flow_status_code flow_status_code,  oel.org_id, oel.link_to_line_id,oel.top_model_line_id,  oel.inventory_item_id,  oel.ship_from_org_id,  oel.line_type_id,

  oel.sold_to_org_id,  oel.open_flag,  oel.cancelled_flag,  oel.line_category_code  from ss_pc_e_warehouse_data spw,  oe_order_lines_all oel  where spw.so_shipped_req = ''Y''  and oel.inventory_item_id = spw.inventory_item_id  and oel.org_id = :bb  AND oel.open_flag = ''N''  AND NVL(oel.actual_shipment_date,TRUNC(oel.last_update_date)) BETWEEN (trunc(sysdate)- :p_num_days) AND SYSDATE';

  FOR vc_org IN c_org_id  LOOP  OPEN vc_cursor FOR v_sql  USING vc_org.organization_id  ,vc_org.organization_id  ,v_no_of_days;

  IF vc_cursor%ISOPEN  THEN  BEGIN

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 102/137

  LOOP  FETCH vc_cursor  BULK COLLECT INTO n_header_id  ,n_line_number  ,n_shipment_number  ,n_component_number  ,n_unit_list_price  ,n_unit_selling_price  ,n_extended_price  ,n_ordered_quantity  ,n_shipped_quantity  ,n_shipped_date  ,n_request_date  ,n_schedule_ship_date  ,n_line_id  ,n_flow_status_code  ,n_org_id  ,n_link_to_line_id  ,n_top_model_line_id  ,n_inventory_item_id  ,n_ship_from_org_id  ,n_line_type_id  ,n_sold_to_org_id  ,n_open_flag

  ,n_cancelled_flag  ,n_line_category_code LIMIT 5000;

  FOR i IN 1 .. n_line_id.COUNT  LOOP  BEGIN  SELECT mp.organization_code  ,oeh.order_number  ,oeh_type.NAME ot_type  ,oel_type.NAME ot_line_type  ,gcc.segment5 prod_model  ,msi.segment1 item  ,oeh.transactional_curr_code

  ,oeh.ordered_date  ,oeh.cust_po_number  ,mc.segment1 item_categories  ,oeh.attribute12 branch_segment  ,hca.account_number  ,hp.party_name  ,hca.sales_channel_code  ,rs.NAME salesrep_name  ,ft.nls_territory bill2country  INTO m_organization_code  ,m_order_number  ,m_ot_type  ,m_ot_line_type

  ,m_prod_model  ,m_item  ,m_transactional_curr_code  ,m_ordered_date  ,m_cust_po_number  ,m_item_categories  ,m_branch_segment  ,m_account_number  ,m_party_name  ,m_sales_channel_code

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 103/137

  ,m_salesrep_name  ,m_bill2country  FROM oe_order_headers_all oeh  ,oe_transaction_types_tl oeh_type  ,oe_transaction_types_tl oel_type  ,mtl_system_items_b msi  ,mtl_item_categories mic  ,mtl_categories_b mc  ,mtl_parameters mp  ,gl_code_combinations gcc  ,hz_cust_accounts hca  ,hz_parties hp  ,jtf_rs_salesreps rs  ,fnd_territories ft  WHERE oeh.header_id = n_header_id (i)  AND oeh_type.transaction_type_id =  oeh.order_type_id  AND oeh_type.LANGUAGE = USERENV ('LANG')  AND oel_type.transaction_type_id =  n_line_type_id (i)  AND oel_type.LANGUAGE = USERENV ('LANG')  AND msi.inventory_item_id =  n_inventory_item_id (i)  AND msi.organization_id =

  n_ship_from_org_id (i)  AND mp.organization_id =  n_ship_from_org_id (i)  AND mic.inventory_item_id =  n_inventory_item_id (i)  AND mic.category_set_id = 1  AND mic.organization_id =  n_ship_from_org_id (i)  AND mc.category_id = mic.category_id  AND gcc.code_combination_id =  msi.cost_of_sales_account  AND hca.cust_account_id =  n_sold_to_org_id (i)

  AND hca.party_id = hp.party_id  AND oeh.salesrep_id = rs.salesrep_id(+)  AND oeh.org_id = rs.org_id(+)  AND hp.country = ft.territory_code(+);  EXCEPTION  WHEN OTHERS  THEN  NULL;  END;

  BEGIN  SELECT NVL (mmt.actual_cost, 0)  INTO m_trx_cost

  FROM mtl_material_transactions mmt  WHERE mmt.trx_source_line_id(+) =  n_line_id (i)  AND mmt.transaction_type_id(+) = 33;  EXCEPTION  WHEN OTHERS  THEN  m_trx_cost := 0;  END;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 104/137

  INSERT INTO ss_pc_e_warehouse_data_temp  (organization_code  ,order_number  ,ot_type  ,ot_line_type  ,prod_model  ,item  ,line_number  ,shipment_number  ,component_number  ,transactional_curr_code  ,unit_list_price  ,unit_selling_price  ,extended_price  ,trx_cost  ,ordered_quantity  ,shipped_quantity  ,ordered_date  ,shipped_date  ,cust_po_number  ,item_categories  ,request_date  ,schedule_ship_date  ,branch_segment

  ,customer_number  ,customer_name  ,sales_channel_code  ,salesrep_name  ,bill2country  ,line_id  ,flow_status_code  ,org_id  ,link_to_line_id  ,top_model_line_id  ,open_flag  ,cancelled_flag  ,line_category_code)

  VALUES (m_organization_code  ,m_order_number  ,m_ot_type  ,m_ot_line_type  ,m_prod_model  ,m_item  ,n_line_number (i)  ,n_shipment_number (i)  ,n_component_number (i)  ,m_transactional_curr_code  ,n_unit_list_price (i)  ,n_unit_selling_price (i)  ,n_extended_price (i)

  ,m_trx_cost  ,n_ordered_quantity (i)  ,n_shipped_quantity (i)  ,m_ordered_date  ,n_shipped_date (i)  ,m_cust_po_number  ,m_item_categories  ,n_request_date (i)  ,n_schedule_ship_date (i)  ,m_branch_segment

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 105/137

  ,m_account_number  ,m_party_name  ,m_sales_channel_code  ,m_salesrep_name  ,m_bill2country  ,n_line_id (i)  ,n_flow_status_code (i)  ,n_org_id (i)  ,n_link_to_line_id (i)  ,n_top_model_line_id (i)  ,n_open_flag (i)  ,n_cancelled_flag (i)  ,n_line_category_code (i) );

  COMMIT;  END LOOP;

  EXIT WHEN vc_cursor%NOTFOUND;  END LOOP;

  CLOSE vc_cursor;  EXCEPTION  WHEN OTHERS  THEN

  IF vc_cursor%ISOPEN  THEN  CLOSE vc_cursor;  END IF;  END;  END IF;

  FOR ord IN c_order_num  LOOP  BEGIN  SELECT link_to_line_id  INTO v_link_to_line  FROM (SELECT NVL (link_to_line_id, 0) link_to_line_id

  FROM ss_pc_e_warehouse_data_temp  WHERE order_number = ord.order_number  AND top_model_line_id = ord.top_model_line_id  AND org_id = vc_org.organization_id  ORDER BY top_model_line_id  ,line_id)  WHERE ROWNUM = 1;  EXCEPTION  WHEN OTHERS  THEN  v_link_to_line := 0;  END;

  IF v_link_to_line <> 0  THEN  BEGIN  SELECT oel.inventory_item_id  ,oel.line_number  ,oel.shipment_number  ,oel.component_number  ,oel.unit_list_price  ,oel.unit_selling_price  , oel.ordered_quantity * oel.unit_selling_price

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 106/137

  extended_price  ,DECODE (oel.line_category_code  ,'RETURN', oel.ordered_quantity * -1  ,oel.ordered_quantity) ordered_quantity  ,NVL (DECODE (oel.line_category_code  ,'RETURN', oel.shipped_quantity  * -1  ,oel.shipped_quantity)  ,0) shipped_quantity  ,oel.actual_shipment_date shipped_date  ,oel.request_date  ,oel.schedule_ship_date  ,oel.line_id line_id  ,oel.flow_status_code flow_status_code  ,oel.ship_from_org_id  ,oel.link_to_line_id  ,oeh_type.NAME ot_type  ,oel_type.NAME ot_line_type  ,mp.organization_code  ,oel.open_flag  ,oel.cancelled_flag  ,oel.line_category_code  INTO b_inventory_item_id  ,b_line_number

  ,b_shipment_number  ,b_component_number  ,b_unit_list_price  ,b_unit_selling_price  ,b_extended_price  ,b_ordered_quantity  ,b_shipped_quantity  ,b_shipped_date  ,b_request_date  ,b_schedule_ship_date  ,b_line_id  ,b_flow_status_code  ,b_ship_from_org_id

  ,b_link_to_line_id  ,b_ot_type  ,b_ot_line_type  ,b_organization_code  ,b_open_flag  ,b_cancelled_flag  ,b_line_category_code  FROM oe_order_lines_all oel  ,oe_order_headers_all oeh  ,oe_transaction_types_tl oeh_type  ,oe_transaction_types_tl oel_type  ,mtl_parameters mp  WHERE oeh.order_number = ord.order_number

  AND oeh.org_id = vc_org.organization_id  AND oel.line_id = v_link_to_line  AND oel.header_id = oeh.header_id  AND oeh_type.transaction_type_id =  oeh.order_type_id  AND oeh_type.LANGUAGE = USERENV ('LANG')  AND oel_type.transaction_type_id = oel.line_type_id  AND oel_type.LANGUAGE = USERENV ('LANG')  AND mp.organization_id = oel.ship_from_org_id  AND ROWNUM = 1;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 107/137

  EXCEPTION  WHEN NO_DATA_FOUND  THEN  b_inventory_item_id := NULL;  b_line_number := NULL;  b_shipment_number := NULL;  b_component_number := NULL;  b_unit_list_price := NULL;  b_unit_selling_price := NULL;  b_extended_price := NULL;  b_ordered_quantity := NULL;  b_shipped_quantity := NULL;  b_shipped_date := NULL;  b_request_date := NULL;  b_schedule_ship_date := NULL;  b_line_id := NULL;  b_flow_status_code := NULL;  b_ship_from_org_id := NULL;  b_ot_type := NULL;  b_ot_line_type := NULL;  b_organization_code := NULL;  b_open_flag := NULL;  b_cancelled_flag := NULL;  b_line_category_code := NULL;

  END;

  BEGIN  SELECT mmt.actual_cost  INTO b_trx_cost  FROM mtl_material_transactions mmt  WHERE mmt.transaction_type_id = 33  AND mmt.trx_source_line_id = v_link_to_line;  EXCEPTION  WHEN OTHERS  THEN  b_trx_cost := 0;  END;

  BEGIN  SELECT msi.segment1  ,gcc.segment5  INTO b_item  ,b_prod_model  FROM mtl_system_items msi  ,gl_code_combinations gcc  WHERE inventory_item_id = b_inventory_item_id  AND organization_id = b_ship_from_org_id  AND gcc.code_combination_id =  msi.cost_of_sales_account;  EXCEPTION

  WHEN OTHERS  THEN  b_item := NULL;  b_prod_model := NULL;  END;

  INSERT INTO ss_pc_e_warehouse_data_temp  (organization_code  ,order_number  ,ot_type

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 108/137

  ,ot_line_type  ,prod_model  ,item  ,line_number  ,shipment_number  ,component_number  ,transactional_curr_code  ,unit_list_price  ,unit_selling_price  ,extended_price  ,trx_cost  ,ordered_quantity  ,shipped_quantity  ,ordered_date  ,shipped_date  ,cust_po_number  ,item_categories  ,request_date  ,schedule_ship_date  ,branch_segment  ,customer_number  ,customer_name  ,sales_channel_code  ,salesrep_name

  ,bill2country  ,line_id  ,flow_status_code  ,org_id  ,link_to_line_id  ,open_flag  ,cancelled_flag  ,line_category_code  ,top_model_line_id)  SELECT b_organization_code  ,ord.order_number  ,b_ot_type  ,b_ot_line_type

  ,b_prod_model  ,b_item  ,line_number  ,shipment_number  ,b_component_number  ,transactional_curr_code  ,unit_list_price  ,b_unit_selling_price  ,b_extended_price  ,b_trx_cost  ,b_ordered_quantity  ,b_shipped_quantity  ,ordered_date

  ,b_shipped_date  ,cust_po_number  ,item_categories  ,b_request_date  ,b_schedule_ship_date  ,branch_segment  ,customer_number  ,customer_name  ,sales_channel_code  ,salesrep_name

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 109/137

  ,bill2country  ,b_line_id  ,b_flow_status_code  ,vc_org.organization_id  ,b_link_to_line_id  ,b_open_flag  ,b_cancelled_flag  ,b_line_category_code  ,ord.top_model_line_id  FROM ss_pc_e_warehouse_data_temp  WHERE order_number = ord.order_number  AND top_model_line_id = ord.top_model_line_id  AND org_id = vc_org.organization_id  AND ROWNUM = 1;

  COMMIT;  END IF;  END LOOP;  END LOOP;  END ss_pc_e_wh_so_details;

  PROCEDURE ss_load_item_codes (  p_file_path IN VARCHAR2  ,p_master_org_id IN NUMBER)

  IS  CURSOR c1 (  in_v_current_opco_code VARCHAR2)  IS  SELECT ROWID row_id  ,file_name  FROM ss_incoming_files  WHERE picked_flag = 'N'  AND opco_code = in_v_current_opco_code  AND file_name LIKE 'FXPC_ITSSLIVE%REQ%';

  l_debug_state VARCHAR2 (2000);  v_infilename VARCHAR2 (100);

  v_current_opco_code VARCHAR2 (20);  v_filetype UTL_FILE.file_type;  v_item_filename VARCHAR2 (30);  v_nof_days NUMBER;  v_item_code VARCHAR2 (30);  v_file_location VARCHAR2 (200);  v_record_type VARCHAR2 (10);  v_open_result BOOLEAN;  v_data_line VARCHAR2 (2000);  v_wh_count NUMBER := 0;  v_err_msg VARCHAR2 (200);  v_item_count NUMBER := 0;  v_cost_count NUMBER := 0;

  v_qoh_count NUMBER := 0;  v_po_count NUMBER := 0;  v_po_receipt_count NUMBER := 0;  v_so_count NUMBER := 0;  v_so_shipped_count NUMBER := 0;  v_user_id NUMBER  := fnd_profile.VALUE ('USER_ID');  l_master_org_id NUMBER;

  -- variable for bulk collection

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 110/137

  TYPE item_code_tab IS TABLE OF VARCHAR2 (40);

  tab_item item_code_tab := item_code_tab ();  v_err_cnt NUMBER;  dml_errors EXCEPTION;  PRAGMA EXCEPTION_INIT (dml_errors, -24381);  PRAGMA AUTONOMOUS_TRANSACTION;  BEGIN  l_debug_state := '000 - Get opco code ';  l_master_org_id := p_master_org_id;

  BEGIN  SELECT SUBSTR (NAME  ,1  , INSTR (NAME, ' ') - 1) opco_code  INTO v_current_opco_code  FROM hr_all_organization_units  WHERE organization_id = fnd_profile.VALUE ('ORG_ID');  EXCEPTION  WHEN NO_DATA_FOUND  THEN  raise_application_error (-20000, 'Invalid profile Org ID.');  END;

  l_debug_state :=  '001 - Clear SS_PC_E_WH_DATA_PARAMETERS table ';

  EXECUTE IMMEDIATE 'TRUNCATE TABLE FXAP.SS_PC_E_WH_DATA_PARAMETERS';

  v_file_location :=  p_file_path || v_current_opco_code || '/in';

  FOR r_incoming IN c1 (v_current_opco_code)  LOOP  BEGIN  v_infilename := r_incoming.file_name;  v_err_cnt := 0;

  -- clear the array of item code  IF tab_item.FIRST IS NOT NULL  THEN  tab_item.DELETE;  END IF;

  fnd_file.put_line  (fnd_file.output  ,'----------------------------------------------------------------');  fnd_file.put_line (fnd_file.output  , 'Processing File : ' || v_infilename);

  fnd_file.put_line (fnd_file.output  , 'Start Date : '  || TO_CHAR (SYSDATE  ,'DD-MON-RRRR HH24:MI:SS') );

  /**************** ITEM Interface ******************/  IF v_infilename = 'FXPC_ITSSLIVE_ITEM_REQ.dat'  THEN  l_debug_state :=  '002 - Opening file ' || v_infilename;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 111/137

  v_filetype :=  UTL_FILE.fopen (v_file_location  ,v_infilename  ,'r'  ,32767);

  IF UTL_FILE.is_open (v_filetype)  THEN  LOOP  BEGIN  l_debug_state :=  '003 - Read data in file '  || v_infilename;  UTL_FILE.get_line (v_filetype, v_data_line);

  IF v_data_line IS NULL  THEN  EXIT;  ELSE  v_record_type :=  RTRIM (LTRIM (SUBSTR (v_data_line  ,1  ,2) ) );

  IF v_record_type = '01'  THEN  v_item_filename :=  RTRIM  (LTRIM  (SUBSTR  (v_data_line  ,4  , ( INSTR  (v_data_line  ,'|'  ,1  ,2)

  - 4) ) ) );  v_nof_days :=  RTRIM  (LTRIM  (SUBSTR  (v_data_line  , ( INSTR  (v_data_line  ,'|'  ,1  ,2)  + 1)  , ( INSTR

  (v_data_line  ,'|'  ,1  ,3)  - ( INSTR  (v_data_line  ,'|'  ,1  ,2)

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 112/137

  + 1) ) ) ) );  l_debug_state :=  '004 - Insert no of days from file '  || v_infilename;

  INSERT INTO ss_pc_e_wh_data_parameters  (interface_type  ,nof_days  ,creation_date  ,created_by  ,last_update_date  ,last_updated_by)  VALUES (v_item_filename  ,v_nof_days  ,SYSDATE  ,v_user_id  ,SYSDATE  ,v_user_id);

  v_wh_count :=  v_wh_count + 1;  ELSIF v_record_type = '02'  THEN

  v_item_code :=  REPLACE  (REPLACE  (RTRIM  (LTRIM  (SUBSTR  (v_data_line  ,4  ,30) ) )  ,CHR (10)  ,'')  ,CHR (13)  ,'');

  l_debug_state :=  '005 - Insert item code from file '  || v_infilename  || ' into collection ';  tab_item.EXTEND;  tab_item (tab_item.COUNT) :=  v_item_code;  END IF;  END IF;  EXCEPTION  WHEN NO_DATA_FOUND  THEN

  EXIT; -- no data due to end of data file  WHEN OTHERS  THEN  fnd_file.put_line (fnd_file.output  ,l_debug_state);  fnd_file.put_line (fnd_file.output  , 'Error message :'  || SQLERRM);  EXIT;  END;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 113/137

  END LOOP;

  -- close the data file  UTL_FILE.fclose (v_filetype);  END IF;

  IF tab_item.FIRST IS NOT NULL  THEN  v_item_count := tab_item.COUNT;

  BEGIN  FORALL i IN tab_item.FIRST .. tab_item.LAST  UPDATE fxap.ss_pc_e_warehouse_data  SET item_req = 'Y'  ,last_update_date = SYSDATE  ,last_updated_by = v_user_id  WHERE item_code = tab_item (i);  FORALL i IN tab_item.FIRST .. tab_item.LAST  INSERT INTO fxap.ss_pc_e_warehouse_data  (item_code  ,inventory_item_id  ,item_req  ,cost_req  ,qoh_req

  ,po_req  ,po_receipt_req  ,so_req  ,so_shipped_req  ,creation_date  ,created_by  ,last_update_date  ,last_updated_by)  SELECT msi.segment1  ,msi.inventory_item_id  ,'Y'  ,'N'  ,'N'

  ,'N'  ,'N'  ,'N'  ,'N'  ,SYSDATE  ,v_user_id  ,SYSDATE  ,v_user_id  FROM mtl_system_items_b msi  WHERE msi.organization_id =  l_master_org_id  --p_master_org_id  AND msi.segment1 = tab_item (i)

  AND NOT EXISTS (  SELECT 1  FROM fxap.ss_pc_e_warehouse_data ssp  WHERE ssp.item_code =  tab_item (i) );  EXCEPTION  WHEN dml_errors  THEN

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 114/137

  v_err_cnt :=  SQL%BULK_EXCEPTIONS.COUNT;  fnd_file.put_line (fnd_file.output  , ' Number of errors is '  || v_err_cnt);  END;

  -- clear the item code array  tab_item.DELETE;  END IF;

  UPDATE ss_incoming_files  SET when_processed = SYSDATE  WHERE ROWID = r_incoming.row_id;

  fnd_file.put_line (fnd_file.output  , 'End Date : '  || TO_CHAR (SYSDATE  ,'DD-MON-RRRR HH24:MI:SS') );  fnd_file.put_line (fnd_file.output  , 'Total data loaded : '  || TO_CHAR (v_item_count - v_err_cnt)  || ' records');  fnd_file.put_line (fnd_file.output

  ,'Completed Processing File');  COMMIT;  END IF;

  /**************** COST Interface ******************/  IF v_infilename = 'FXPC_ITSSLIVE_COST_REQ.dat'  THEN  l_debug_state :=  '002 - Opening file ' || v_infilename;  v_filetype :=  UTL_FILE.fopen (v_file_location  ,v_infilename  ,'r'

  ,32767);

  IF UTL_FILE.is_open (v_filetype)  THEN  LOOP  BEGIN  l_debug_state :=  '003 - Read data in file '  || v_infilename;  UTL_FILE.get_line (v_filetype, v_data_line);

  IF v_data_line IS NULL  THEN

  EXIT;  ELSE  v_record_type :=  RTRIM (LTRIM (SUBSTR (v_data_line  ,1  ,2) ) );

  IF v_record_type = '01'  THEN  v_item_filename :=

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 115/137

  RTRIM  (LTRIM  (SUBSTR  (v_data_line  ,4  , ( INSTR  (v_data_line  ,'|'  ,1  ,2)  - 4) ) ) );  v_nof_days :=  RTRIM  (LTRIM  (SUBSTR  (v_data_line  , ( INSTR  (v_data_line  ,'|'  ,1  ,2)  + 1)  , ( INSTR  (v_data_line

  ,'|'  ,1  ,3)  - ( INSTR  (v_data_line  ,'|'  ,1  ,2)  + 1) ) ) ) );  l_debug_state :=  '004 - Insert no of days from file '

  || v_infilename;

  INSERT INTO ss_pc_e_wh_data_parameters  (interface_type  ,nof_days  ,creation_date  ,created_by  ,last_update_date  ,last_updated_by)  VALUES (v_item_filename  ,v_nof_days  ,SYSDATE  ,v_user_id

  ,SYSDATE  ,v_user_id);

  v_wh_count :=  v_wh_count + 1;  ELSIF v_record_type = '02'  THEN  v_item_code :=  REPLACE  (REPLACE

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 116/137

  (RTRIM  (LTRIM  (SUBSTR  (v_data_line  ,4  ,30) ) )  ,CHR (10)  ,'')  ,CHR (13)  ,'');  l_debug_state :=  '005 - Insert item code from file '  || v_infilename  || ' into collection ';  tab_item.EXTEND;  tab_item (tab_item.COUNT) :=  v_item_code;  END IF;  END IF;  EXCEPTION  WHEN NO_DATA_FOUND  THEN  EXIT; -- no data due to end of data file

  WHEN OTHERS  THEN  fnd_file.put_line (fnd_file.output  ,l_debug_state);  fnd_file.put_line (fnd_file.output  , 'Error message :'  || SQLERRM);  EXIT;  END;  END LOOP;

  UTL_FILE.fclose (v_filetype);  END IF;

  IF tab_item.FIRST IS NOT NULL  THEN  v_cost_count := tab_item.COUNT;

  BEGIN  -- update the flag for existing item code  FORALL i IN tab_item.FIRST .. tab_item.LAST  UPDATE ss_pc_e_warehouse_data  SET cost_req = 'Y'  ,last_update_date = SYSDATE  ,last_updated_by = v_user_id  WHERE item_code = tab_item (i);

  FORALL i IN tab_item.FIRST .. tab_item.LAST  INSERT INTO ss_pc_e_warehouse_data  (item_code  ,inventory_item_id  ,item_req  ,cost_req  ,qoh_req  ,po_req  ,po_receipt_req  ,so_req

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 117/137

  ,so_shipped_req  ,creation_date  ,created_by  ,last_update_date  ,last_updated_by)  SELECT msi.segment1  ,msi.inventory_item_id  ,'N'  ,'Y'  ,'N'  ,'N'  ,'N'  ,'N'  ,'N'  ,SYSDATE  ,v_user_id  ,SYSDATE  ,v_user_id  FROM mtl_system_items_b msi  WHERE msi.organization_id =  p_master_org_id  AND msi.segment1 = tab_item (i)  AND NOT EXISTS (  SELECT 1

  FROM ss_pc_e_warehouse_data ssp  WHERE ssp.item_code =  tab_item (i) );  EXCEPTION  WHEN dml_errors  THEN  v_err_cnt :=  SQL%BULK_EXCEPTIONS.COUNT;  fnd_file.put_line (fnd_file.output  , ' Number of errors is '  || v_err_cnt);  END;

  tab_item.DELETE;  END IF;

  UPDATE ss_incoming_files  SET when_processed = SYSDATE  WHERE ROWID = r_incoming.row_id;

  fnd_file.put_line (fnd_file.output  , 'End Date : '  || TO_CHAR (SYSDATE  ,'DD-MON-RRRR HH24:MI:SS') );  fnd_file.put_line (fnd_file.output

  , 'Total data loaded : '  || TO_CHAR (v_cost_count - v_err_cnt)  || ' records');  fnd_file.put_line (fnd_file.output  ,'Completed Processing File');  COMMIT;  END IF;

  /**************** QOH Interface ******************/  IF v_infilename = 'FXPC_ITSSLIVE_QOH_REQ.dat'

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 118/137

  THEN  l_debug_state :=  '002 - Opening file ' || v_infilename;  v_filetype :=  UTL_FILE.fopen (v_file_location  ,v_infilename  ,'r'  ,32767);

  IF UTL_FILE.is_open (v_filetype)  THEN  LOOP  BEGIN  l_debug_state :=  '003 - Read data in file '  || v_infilename;  UTL_FILE.get_line (v_filetype, v_data_line);

  IF v_data_line IS NULL  THEN  EXIT;  ELSE  v_record_type :=  RTRIM (LTRIM (SUBSTR (v_data_line

  ,1  ,2) ) );

  IF v_record_type = '01'  THEN  v_item_filename :=  RTRIM  (LTRIM  (SUBSTR  (v_data_line  ,4  , ( INSTR  (v_data_line

  ,'|'  ,1  ,2)  - 4) ) ) );  v_nof_days :=  RTRIM  (LTRIM  (SUBSTR  (v_data_line  , ( INSTR  (v_data_line  ,'|'  ,1

  ,2)  + 1)  , ( INSTR  (v_data_line  ,'|'  ,1  ,3)  - ( INSTR  (v_data_line

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 119/137

  ,'|'  ,1  ,2)  + 1) ) ) ) );  l_debug_state :=  '004 - Insert no of days from file '  || v_infilename;

  INSERT INTO ss_pc_e_wh_data_parameters  (interface_type  ,nof_days  ,creation_date  ,created_by  ,last_update_date  ,last_updated_by)  VALUES (v_item_filename  ,v_nof_days  ,SYSDATE  ,v_user_id  ,SYSDATE  ,v_user_id);

  v_wh_count :=

  v_wh_count + 1;  ELSIF v_record_type = '02'  THEN  v_item_code :=  REPLACE  (REPLACE  (RTRIM  (LTRIM  (SUBSTR  (v_data_line  ,4  ,30) ) )  ,CHR (10)

  ,'')  ,CHR (13)  ,'');  l_debug_state :=  '005 - Insert item code from file '  || v_infilename  || ' into collection ';  tab_item.EXTEND;  tab_item (tab_item.COUNT) :=  v_item_code;  END IF;  END IF;

  EXCEPTION  WHEN NO_DATA_FOUND  THEN  EXIT; -- no data due to end of data file  WHEN OTHERS  THEN  fnd_file.put_line (fnd_file.output  ,l_debug_state);  fnd_file.put_line (fnd_file.output  , 'Error message :'

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 120/137

  || SQLERRM);  EXIT;  END;  END LOOP;

  UTL_FILE.fclose (v_filetype);  END IF;

  IF tab_item.FIRST IS NOT NULL  THEN  v_qoh_count := tab_item.COUNT;

  BEGIN  -- update the flag for existing item code  FORALL i IN tab_item.FIRST .. tab_item.LAST  UPDATE ss_pc_e_warehouse_data  SET qoh_req = 'Y'  ,last_update_date = SYSDATE  ,last_updated_by = v_user_id  WHERE item_code = tab_item (i);  FORALL i IN tab_item.FIRST .. tab_item.LAST  INSERT INTO ss_pc_e_warehouse_data  (item_code  ,inventory_item_id

  ,item_req  ,cost_req  ,qoh_req  ,po_req  ,po_receipt_req  ,so_req  ,so_shipped_req  ,creation_date  ,created_by  ,last_update_date  ,last_updated_by)  SELECT msi.segment1  ,msi.inventory_item_id

  ,'N'  ,'N'  ,'Y'  ,'N'  ,'N'  ,'N'  ,'N'  ,SYSDATE  ,v_user_id  ,SYSDATE  ,v_user_id  FROM mtl_system_items_b msi  WHERE msi.organization_id =

  p_master_org_id  AND msi.segment1 = tab_item (i)  AND NOT EXISTS (  SELECT 1  FROM ss_pc_e_warehouse_data ssp  WHERE ssp.item_code =  tab_item (i) );  EXCEPTION  WHEN dml_errors

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 121/137

  THEN  v_err_cnt :=  SQL%BULK_EXCEPTIONS.COUNT;  fnd_file.put_line (fnd_file.output  , ' Number of errors is '  || v_err_cnt);  END;

  -- clear the item code array  tab_item.DELETE;  END IF;

  UPDATE ss_incoming_files  SET when_processed = SYSDATE  WHERE ROWID = r_incoming.row_id;

  fnd_file.put_line (fnd_file.output  , 'End Date : '  || TO_CHAR (SYSDATE  ,'DD-MON-RRRR HH24:MI:SS') );  fnd_file.put_line (fnd_file.output  , 'Total data loaded : '  || TO_CHAR (v_qoh_count - v_err_cnt)  || ' records');

  fnd_file.put_line (fnd_file.output  ,'Completed Processing File');  COMMIT;  END IF;

  /**************** PO Interface ******************/  IF v_infilename = 'FXPC_ITSSLIVE_PO_REQ.dat'  THEN  l_debug_state :=  '002 - Opening file ' || v_infilename;  v_filetype :=  UTL_FILE.fopen (v_file_location  ,v_infilename

  ,'r'  ,32767);

  IF UTL_FILE.is_open (v_filetype)  THEN  LOOP  BEGIN  l_debug_state :=  '003 - Read data in file '  || v_infilename;  UTL_FILE.get_line (v_filetype, v_data_line);

  IF v_data_line IS NULL

  THEN  EXIT;  ELSE  v_record_type :=  RTRIM (LTRIM (SUBSTR (v_data_line  ,1  ,2) ) );

  IF v_record_type = '01'  THEN

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 122/137

  v_item_filename :=  RTRIM  (LTRIM  (SUBSTR  (v_data_line  ,4  , ( INSTR  (v_data_line  ,'|'  ,1  ,2)  - 4) ) ) );  v_nof_days :=  RTRIM  (LTRIM  (SUBSTR  (v_data_line  , ( INSTR  (v_data_line  ,'|'  ,1  ,2)  + 1)  , ( INSTR

  (v_data_line  ,'|'  ,1  ,3)  - ( INSTR  (v_data_line  ,'|'  ,1  ,2)  + 1) ) ) ) );  l_debug_state :=  '004 - Insert no of days from fil

e '  || v_infilename;

  INSERT INTO ss_pc_e_wh_data_parameters  (interface_type  ,nof_days  ,creation_date  ,created_by  ,last_update_date  ,last_updated_by)  VALUES (v_item_filename  ,v_nof_days  ,SYSDATE

  ,v_user_id  ,SYSDATE  ,v_user_id);

  v_wh_count :=  v_wh_count + 1;  ELSIF v_record_type = '02'  THEN  v_item_code :=  REPLACE

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 123/137

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 124/137

  ,so_shipped_req  ,creation_date  ,created_by  ,last_update_date  ,last_updated_by)  SELECT msi.segment1  ,msi.inventory_item_id  ,'N'  ,'N'  ,'N'  ,'Y'  ,'N'  ,'N'  ,'N'  ,SYSDATE  ,v_user_id  ,SYSDATE  ,v_user_id  FROM mtl_system_items_b msi  WHERE msi.organization_id =  p_master_org_id  AND msi.segment1 = tab_item (i)  AND NOT EXISTS (  SELECT 1

  FROM ss_pc_e_warehouse_data ssp  WHERE ssp.item_code =  tab_item (i) );  EXCEPTION  WHEN dml_errors  THEN  v_err_cnt :=  SQL%BULK_EXCEPTIONS.COUNT;  fnd_file.put_line (fnd_file.output  , ' Number of errors is '  || v_err_cnt);  END;

  -- clear the item code array  tab_item.DELETE;  END IF;

  UPDATE ss_incoming_files  SET when_processed = SYSDATE  WHERE ROWID = r_incoming.row_id;

  fnd_file.put_line (fnd_file.output  , 'End Date : '  || TO_CHAR (SYSDATE  ,'DD-MON-RRRR HH24:MI:SS') );

  fnd_file.put_line (fnd_file.output  , 'Total data loaded : '  || TO_CHAR (v_po_count - v_err_cnt)  || ' records');  fnd_file.put_line (fnd_file.output  ,'Completed Processing File');  COMMIT;  END IF;

  /**************** PO RECEIPT Interface ******************/

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 125/137

  IF v_infilename = 'FXPC_ITSSLIVE_PO_RECEIPT_REQ.dat'  THEN  l_debug_state :=  '002 - Opening file ' || v_infilename;  v_filetype :=  UTL_FILE.fopen (v_file_location  ,v_infilename  ,'r'  ,32767);

  IF UTL_FILE.is_open (v_filetype)  THEN  LOOP  BEGIN  l_debug_state :=  '003 - Read data in file '  || v_infilename;  UTL_FILE.get_line (v_filetype, v_data_line);

  IF v_data_line IS NULL  THEN  EXIT;  ELSE  v_record_type :=

  RTRIM (LTRIM (SUBSTR (v_data_line  ,1  ,2) ) );

  IF v_record_type = '01'  THEN  v_item_filename :=  RTRIM  (LTRIM  (SUBSTR  (v_data_line  ,4  , ( INSTR

  (v_data_line  ,'|'  ,1  ,2)  - 4) ) ) );  v_nof_days :=  RTRIM  (LTRIM  (SUBSTR  (v_data_line  , ( INSTR  (v_data_line  ,'|'

  ,1  ,2)  + 1)  , ( INSTR  (v_data_line  ,'|'  ,1  ,3)  - ( INSTR  (v_data_li

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 126/137

ne  ,'|'  ,1  ,2)  + 1) ) ) ) );  l_debug_state :=  '004 - Insert no of days from file '  || v_infilename;

  INSERT INTO ss_pc_e_wh_data_parameters  (interface_type  ,nof_days  ,creation_date  ,created_by  ,last_update_date  ,last_updated_by)  VALUES (v_item_filename  ,v_nof_days  ,SYSDATE  ,v_user_id  ,SYSDATE  ,v_user_id);

  v_wh_count :=  v_wh_count + 1;  ELSIF v_record_type = '02'  THEN  v_item_code :=  REPLACE  (REPLACE  (RTRIM  (LTRIM  (SUBSTR  (v_data_line  ,4  ,30) ) )

  ,CHR (10)  ,'')  ,CHR (13)  ,'');  l_debug_state :=  '005 - Insert item code from file '  || v_infilename  || ' into collection ';  tab_item.EXTEND;  tab_item (tab_item.COUNT) :=  v_item_code;  END IF;

  END IF;  EXCEPTION  WHEN NO_DATA_FOUND  THEN  EXIT; -- no data due to end of data file  WHEN OTHERS  THEN  fnd_file.put_line (fnd_file.output  ,l_debug_state);  fnd_file.put_line (fnd_file.output

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 127/137

  , 'Error message :'  || SQLERRM);  EXIT;  END;  END LOOP;

  -- close the data file  UTL_FILE.fclose (v_filetype);  END IF;

  IF tab_item.FIRST IS NOT NULL  THEN  v_po_receipt_count := tab_item.COUNT;

  BEGIN  -- update the flag for existing item code  FORALL i IN tab_item.FIRST .. tab_item.LAST  UPDATE ss_pc_e_warehouse_data  SET po_receipt_req = 'Y'  ,last_update_date = SYSDATE  ,last_updated_by = v_user_id  WHERE item_code = tab_item (i);  FORALL i IN tab_item.FIRST .. tab_item.LAST  INSERT INTO ss_pc_e_warehouse_data

  (item_code  ,inventory_item_id  ,item_req  ,cost_req  ,qoh_req  ,po_req  ,po_receipt_req  ,so_req  ,so_shipped_req  ,creation_date  ,created_by  ,last_update_date  ,last_updated_by)

  SELECT msi.segment1  ,msi.inventory_item_id  ,'N'  ,'N'  ,'N'  ,'N'  ,'Y'  ,'N'  ,'N'  ,SYSDATE  ,v_user_id  ,SYSDATE  ,v_user_id

  FROM mtl_system_items_b msi  WHERE msi.organization_id =  p_master_org_id  AND msi.segment1 = tab_item (i)  AND NOT EXISTS (  SELECT 1  FROM ss_pc_e_warehouse_data ssp  WHERE ssp.item_code =  tab_item (i) );

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 128/137

  EXCEPTION  WHEN dml_errors  THEN  v_err_cnt :=  SQL%BULK_EXCEPTIONS.COUNT;  fnd_file.put_line (fnd_file.output  , ' Number of errors is '  || v_err_cnt);  END;

  -- clear the item code array  tab_item.DELETE;  END IF;

  UPDATE ss_incoming_files  SET when_processed = SYSDATE  WHERE ROWID = r_incoming.row_id;

  fnd_file.put_line (fnd_file.output  , 'End Date : '  || TO_CHAR (SYSDATE  ,'DD-MON-RRRR HH24:MI:SS') );  fnd_file.put_line (fnd_file.output  , 'Total data loaded : '

  || TO_CHAR ( v_po_receipt_count  - v_err_cnt)  || ' records');  fnd_file.put_line (fnd_file.output  ,'Completed Processing File');  COMMIT;  END IF;

  /**************** SO Interface ******************/  IF v_infilename = 'FXPC_ITSSLIVE_SO_REQ.dat'  THEN  l_debug_state :=  '002 - Opening file ' || v_infilename;

  v_filetype :=  UTL_FILE.fopen (v_file_location  ,v_infilename  ,'r'  ,32767);

  IF UTL_FILE.is_open (v_filetype)  THEN  LOOP  BEGIN  l_debug_state :=  '003 - Read data in file '  || v_infilename;

  UTL_FILE.get_line (v_filetype, v_data_line);

  IF v_data_line IS NULL  THEN  EXIT;  ELSE  v_record_type :=  RTRIM (LTRIM (SUBSTR (v_data_line  ,1  ,2) ) );

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 129/137

  IF v_record_type = '01'  THEN  v_item_filename :=  RTRIM  (LTRIM  (SUBSTR  (v_data_line  ,4  , ( INSTR  (v_data_line  ,'|'  ,1  ,2)  - 4) ) ) );  v_nof_days :=  RTRIM  (LTRIM  (SUBSTR  (v_data_line  , ( INSTR  (v_data_line  ,'|'  ,1

  ,2)  + 1)  , ( INSTR  (v_data_line  ,'|'  ,1  ,3)  - ( INSTR  (v_data_line  ,'|'  ,1  ,2)

  + 1) ) ) ) );  l_debug_state :=  '004 - Insert no of days from file '  || v_infilename;

  INSERT INTO ss_pc_e_wh_data_parameters  (interface_type  ,nof_days  ,creation_date  ,created_by  ,last_update_date  ,last_updated_by)

  VALUES (v_item_filename  ,v_nof_days  ,SYSDATE  ,v_user_id  ,SYSDATE  ,v_user_id);

  v_wh_count :=  v_wh_count + 1;  ELSIF v_record_type = '02'

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 130/137

  THEN  v_item_code :=  REPLACE  (REPLACE  (RTRIM  (LTRIM  (SUBSTR  (v_data_line  ,4  ,30) ) )  ,CHR (10)  ,'')  ,CHR (13)  ,'');  l_debug_state :=  '005 - Insert item code from file '  || v_infilename  || ' into collection ';  tab_item.EXTEND;  tab_item (tab_item.COUNT) :=  v_item_code;  END IF;  END IF;

  EXCEPTION  WHEN NO_DATA_FOUND  THEN  EXIT; -- no data due to end of data file  WHEN OTHERS  THEN  fnd_file.put_line (fnd_file.output  ,l_debug_state);  fnd_file.put_line (fnd_file.output  , 'Error message :'  || SQLERRM);  EXIT;  END;

  END LOOP;

  UTL_FILE.fclose (v_filetype);  END IF;

  IF tab_item.FIRST IS NOT NULL  THEN  -- total item in the data file  v_so_count := tab_item.COUNT;

  BEGIN  -- update the flag for existing item code  FORALL i IN tab_item.FIRST .. tab_item.LAST

  UPDATE ss_pc_e_warehouse_data  SET so_req = 'Y'  ,last_update_date = SYSDATE  ,last_updated_by = v_user_id  WHERE item_code = tab_item (i);  -- insert record for new item code  FORALL i IN tab_item.FIRST .. tab_item.LAST  INSERT INTO ss_pc_e_warehouse_data  (item_code  ,inventory_item_id

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 131/137

  ,item_req  ,cost_req  ,qoh_req  ,po_req  ,po_receipt_req  ,so_req  ,so_shipped_req  ,creation_date  ,created_by  ,last_update_date  ,last_updated_by)  SELECT msi.segment1  ,msi.inventory_item_id  ,'N'  ,'N'  ,'N'  ,'N'  ,'N'  ,'Y'  ,'N'  ,SYSDATE  ,v_user_id  ,SYSDATE  ,v_user_id

  FROM mtl_system_items_b msi  WHERE msi.organization_id =  p_master_org_id  AND msi.segment1 = tab_item (i)  AND NOT EXISTS (  SELECT 1  FROM ss_pc_e_warehouse_data ssp  WHERE ssp.item_code =  tab_item (i) );  EXCEPTION  WHEN dml_errors  THEN

  v_err_cnt :=  SQL%BULK_EXCEPTIONS.COUNT;  fnd_file.put_line (fnd_file.output  , ' Number of errors is '  || v_err_cnt);  END;

  -- clear the item code array  tab_item.DELETE;  END IF;

  UPDATE ss_incoming_files  SET when_processed = SYSDATE

  WHERE ROWID = r_incoming.row_id;

  fnd_file.put_line (fnd_file.output  , 'End Date : '  || TO_CHAR (SYSDATE  ,'DD-MON-RRRR HH24:MI:SS') );  fnd_file.put_line (fnd_file.output  , 'Total data loaded : '  || TO_CHAR (v_so_count - v_err_cnt)  || ' records');

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 132/137

  fnd_file.put_line (fnd_file.output  ,'Completed Processing File');  COMMIT;  END IF;

  /**************** SO Interface ******************/  IF v_infilename = 'FXPC_ITSSLIVE_SHIPPED_REQ.dat'  THEN  l_debug_state :=  '002 - Opening file ' || v_infilename;  v_filetype :=  UTL_FILE.fopen (v_file_location  ,v_infilename  ,'r'  ,32767);

  IF UTL_FILE.is_open (v_filetype)  THEN  LOOP  BEGIN  l_debug_state :=  '003 - Read data in file '  || v_infilename;  UTL_FILE.get_line (v_filetype, v_data_line);

  IF v_data_line IS NULL  THEN  EXIT;  ELSE  v_record_type :=  RTRIM (LTRIM (SUBSTR (v_data_line  ,1  ,2) ) );

  IF v_record_type = '01'  THEN  v_item_filename :=

  RTRIM  (LTRIM  (SUBSTR  (v_data_line  ,4  , ( INSTR  (v_data_line  ,'|'  ,1  ,2)  - 4) ) ) );  v_nof_days :=  RTRIM

  (LTRIM  (SUBSTR  (v_data_line  , ( INSTR  (v_data_line  ,'|'  ,1  ,2)  + 1)  , ( INSTR

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 133/137

  (v_data_line  ,'|'  ,1  ,3)  - ( INSTR  (v_data_line  ,'|'  ,1  ,2)  + 1) ) ) ) );  l_debug_state :=  '004 - Insert no of days from file '  || v_infilename;

  INSERT INTO ss_pc_e_wh_data_parameters  (interface_type  ,nof_days  ,creation_date  ,created_by  ,last_update_date  ,last_updated_by)  VALUES (v_item_filename

  ,v_nof_days  ,SYSDATE  ,v_user_id  ,SYSDATE  ,v_user_id);

  v_wh_count :=  v_wh_count + 1;  ELSIF v_record_type = '02'  THEN  v_item_code :=  REPLACE  (REPLACE

  (RTRIM  (LTRIM  (SUBSTR  (v_data_line  ,4  ,30) ) )  ,CHR (10)  ,'')  ,CHR (13)  ,'');  l_debug_state :=  '005 - Insert item code from file '

  || v_infilename  || ' into collection ';  tab_item.EXTEND;  tab_item (tab_item.COUNT) :=  v_item_code;  END IF;  END IF;  EXCEPTION  WHEN NO_DATA_FOUND  THEN

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 134/137

  EXIT; -- no data due to end of data file  WHEN OTHERS  THEN  fnd_file.put_line (fnd_file.output  ,l_debug_state);  fnd_file.put_line (fnd_file.output  , 'Error message :'  || SQLERRM);  EXIT;  END;  END LOOP;

  -- close the data file  UTL_FILE.fclose (v_filetype);  END IF;

  IF tab_item.FIRST IS NOT NULL  THEN  v_so_shipped_count := tab_item.COUNT;

  BEGIN  -- update the flag for existing item code  FORALL i IN tab_item.FIRST .. tab_item.LAST  UPDATE ss_pc_e_warehouse_data

  SET so_shipped_req = 'Y'  ,last_update_date = SYSDATE  ,last_updated_by = v_user_id  WHERE item_code = tab_item (i);  FORALL i IN tab_item.FIRST .. tab_item.LAST  INSERT INTO ss_pc_e_warehouse_data  (item_code  ,inventory_item_id  ,item_req  ,cost_req  ,qoh_req  ,po_req  ,po_receipt_req

  ,so_req  ,so_shipped_req  ,creation_date  ,created_by  ,last_update_date  ,last_updated_by)  SELECT msi.segment1  ,msi.inventory_item_id  ,'N'  ,'N'  ,'N'  ,'N'  ,'N'

  ,'N'  ,'Y'  ,SYSDATE  ,v_user_id  ,SYSDATE  ,v_user_id  FROM mtl_system_items_b msi  WHERE msi.organization_id =  p_master_org_id  AND msi.segment1 = tab_item (i)

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 135/137

  AND NOT EXISTS (  SELECT 1  FROM ss_pc_e_warehouse_data ssp  WHERE ssp.item_code =  tab_item (i) );  EXCEPTION  WHEN dml_errors  THEN  v_err_cnt :=  SQL%BULK_EXCEPTIONS.COUNT;  fnd_file.put_line (fnd_file.output  , ' Number of errors is '  || v_err_cnt);  END;

  tab_item.DELETE;  END IF;

  UPDATE ss_incoming_files  SET when_processed = SYSDATE  WHERE ROWID = r_incoming.row_id;

  fnd_file.put_line (fnd_file.output

  , 'End Date : '  || TO_CHAR (SYSDATE  ,'DD-MON-RRRR HH24:MI:SS') );  fnd_file.put_line (fnd_file.output  , 'Total data loaded : '  || TO_CHAR ( v_so_shipped_count  - v_err_cnt)  || ' records');  fnd_file.put_line (fnd_file.output  ,'Completed Processing File');  COMMIT;  END IF;  END;

  END LOOP;

  COMMIT;  END ss_load_item_codes;

  PROCEDURE main_load (  errbuff OUT VARCHAR2  ,retcode OUT NUMBER  ,p_file_path IN VARCHAR2  ,p_master_org_id IN VARCHAR2)  IS  l_detail NUMBER;  l_end NUMBER;

  i NUMBER;  l_start NUMBER;  l_validate NUMBER := 0;  l_file_path VARCHAR2 (32767);  l_test NUMBER;

  TYPE t_master_org_id IS TABLE OF ss_pc_e_temp_org.master_org_id%TYPE;

  lt_master_org_id t_master_org_id;  l_master_org_id VARCHAR2 (100);

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 136/137

  BEGIN  l_end := 1;  l_start := 1;  i := 0;  l_master_org_id := p_master_org_id;

  DELETE ss_pc_e_temp_org  WHERE master_org_id IS NOT NULL;

  LOOP  i := i + 1;  l_end :=  INSTR (l_master_org_id  ,','  ,1  ,i);

  IF l_end <> 0  THEN  l_detail :=  SUBSTR (l_master_org_id  ,l_start  , l_end - l_start);  ELSE

  l_detail :=  SUBSTR (l_master_org_id, l_start);  END IF;

  BEGIN  SELECT 1  INTO l_test  FROM ss_pc_e_temp_org  WHERE master_org_id = TO_NUMBER (l_detail)  AND orgid IS NULL;  EXCEPTION  WHEN NO_DATA_FOUND  THEN

  INSERT INTO ss_pc_e_temp_org  (orgid  ,master_org_id)  VALUES (NULL  ,l_detail);  END;

  l_start := l_end + 1;  EXIT WHEN l_end = 0;  END LOOP;

  l_file_path := p_file_path;

  BEGIN  SELECT master_org_id  BULK COLLECT INTO lt_master_org_id  FROM ss_pc_e_temp_org  WHERE orgid IS NULL;

  IF SQL%ROWCOUNT = 0  THEN  -- the line is not machine or access. it will defaulted to access.  RAISE NO_DATA_FOUND;

7/25/2019 Raj Pandit

http://slidepdf.com/reader/full/raj-pandit 137/137

  END IF;  EXCEPTION  WHEN NO_DATA_FOUND  THEN  l_validate := 1;  END;

  IF l_validate <> 1  THEN  FOR j IN 1 .. lt_master_org_id.LAST  LOOP  ss_pc_e_warehouse_iface_k.ss_load_item_codes  (l_file_path  ,lt_master_org_id (j) );  END LOOP;  END IF;  END main_load;END ss_pc_e_warehouse_iface_k;