create or replace package body xx ap supplier sites pkg · pdf...

57
create or replace PACKAGE BODY xx_ap_supplier_sites_pkg AS /***************************************************************************** Name:xx_ap_supplier_sites_pkg Date:16-July-2007 Description:This Package used for Importing Suppliers and Supplier Sites for Data Migration. Author:TCS Maintainance Name Date Description TCS 06-Aug-0207 Incorporated Pay Group Lookup Code Validation fetch the contacts *******************************************************************************/ /*Function to get the code combination id */ FUNCTION xx_create_get_gl_ccid_fnc(p_concat_segments VARCHAR2) RETURN NUMBER IS lv_ccid NUMBER; lv_structure NUMBER; BEGIN SELECT id_flex_num INTO lv_structure FROM fnd_id_flex_structures WHERE id_flex_code = 'GL#' AND id_flex_structure_code = 'PH_ACCOUNTING_FLEXFIELD'; lv_ccid := fnd_flex_ext.get_ccid('SQLGL', 'GL#', lv_structure, to_char(sysdate, 'DD-MON-YYYY'), p_concat_segments); RETURN(lv_ccid); fnd_file.put_line(fnd_file.output,'CCID RETURN: ' || lv_ccid); EXCEPTION WHEN OTHERS THEN fnd_file.put_line(fnd_file.output,'DEBUG ERROR: ' || SQLERRM); fnd_file.put_line(fnd_file.log,'ERROR: ' || SQLERRM); END xx_create_get_gl_ccid_fnc; /*==================================================== --FUNCTION ccid ==================================================== */ PROCEDURE xx_ph_ap_load_supp_stg_prc (errbuf OUT VARCHAR2, retcode OUT NUMBER, p_load_id IN NUMBER,p_load_id1 IN NUMBER,p_load_id2 IN NUMBER)

Upload: phungdat

Post on 27-Mar-2018

219 views

Category:

Documents


1 download

TRANSCRIPT

create or replacePACKAGE BODY xx_ap_supplier_sites_pkg AS

/*****************************************************************************

Name:xx_ap_supplier_sites_pkg

Date:16-July-2007

Description:This Package used for Importing Suppliers and Supplier Sites for Data Migration.

Author:TCS

Maintainance

Name Date DescriptionTCS 06-Aug-0207 Incorporated Pay Group Lookup Code Validation fetch the contacts

*******************************************************************************/ /*Function to get the code combination id */ FUNCTION xx_create_get_gl_ccid_fnc(p_concat_segments VARCHAR2) RETURN NUMBER IS lv_ccid NUMBER; lv_structure NUMBER;

BEGIN SELECT id_flex_num INTO lv_structure FROM fnd_id_flex_structures WHERE id_flex_code = 'GL#' AND id_flex_structure_code = 'PH_ACCOUNTING_FLEXFIELD';

lv_ccid := fnd_flex_ext.get_ccid('SQLGL', 'GL#', lv_structure, to_char(sysdate, 'DD-MON-YYYY'), p_concat_segments); RETURN(lv_ccid); fnd_file.put_line(fnd_file.output,'CCID RETURN: ' || lv_ccid); EXCEPTION WHEN OTHERS THEN fnd_file.put_line(fnd_file.output,'DEBUG ERROR: ' || SQLERRM); fnd_file.put_line(fnd_file.log,'ERROR: ' || SQLERRM); END xx_create_get_gl_ccid_fnc;

/*==================================================== --FUNCTION ccid ==================================================== */

PROCEDURE xx_ph_ap_load_supp_stg_prc (errbuf OUT VARCHAR2, retcode OUT NUMBER, p_load_id IN NUMBER,p_load_id1 IN NUMBER,p_load_id2 IN NUMBER)

IS

l_ln_user_id NUMBER := fnd_global.user_id;l_ln_responsibility_id NUMBER := fnd_global.resp_id;l_ln_application_id NUMBER := fnd_global.prog_appl_id;l_request_id NUMBER ;l_login_id NUMBER ;l_count NUMBER ;l_count1 NUMBER ;lv_SiteContact NUMBER;v_err varchar2(4000);

BEGIN

-- fnd_global.apps_initialize(l_ln_user_id,l_ln_responsibility_id,l_ln_application_id); COMMIT; l_request_id := to_number(fnd_global.conc_request_id); l_login_id :=to_number(fnd_profile.value('LOGIN_ID')); fnd_file.put_line(fnd_file.log,'Start Inserting Data ***********');

BEGIN INSERT INTO xx_ap_suppliers_stg( supplier_transaction_id,vendor_name,vendor_alternate_name,vendor_type_lookup_code,customer_number,tax_registration_no,processing_status,component_name,conc_req_id,last_updated_date,last_updated_by,creation_date,created_by,last_update_login,attribute31,attribute32,attribute33,attribute34,attribute35,attribute36,attribute37,attribute38,attribute39,attribute40)SELECTxx_ap_suppliers_stg_s.nextval,TRIM(vendor_name),vendor_alternate_name,vendor_type_lookup_code,customer_number

,tax_registration_no,'N','AP_SUPPLIERS',l_request_id,sysdate,l_ln_user_id,sysdate,l_ln_user_id,l_login_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULLFROM ods_sap.stg_ap_gbl_supplier_temp@crystalWHERE load_id = NVL(p_load_id, load_id);

EXCEPTIONWHEN OTHERS THENfnd_file.put_line(fnd_file.LOG,'Error While inserting records into Supplier Staging Table '||SQLERRM );

END;

SELECT count(*) INTO l_count FROM xx_ap_suppliers_stg;

fnd_file.put_line(fnd_file.OUTPUT,'TOTAL NUMBER OF RECORDS INSERTED INTO SUPPLIER STAGING TABLE :'||l_count );

BEGIN INSERT INTO xx_ap_supplier_sites_stg(supplier_site_transaction_id,vendor_site_code,vendor_name,vendor_alternate_name,operating_unit,address_line1,address_line2,address_line3,city,state,zip,province,country,ship_to_location_code,bill_to_location_code,email_address,purchasing_site_flag

,pay_site_flag,rfq_only_site_flag,payment_method_lookup_code,liability_account_segment1,liability_account_segment2,liability_account_segment3,liability_account_segment4,liability_account_segment5,liability_account_segment6,pay_group_lookup_code,payment_priority,term_name,terms_date_basis,pay_date_basis,invoice_currency_code,payment_currency_code,future_dated_payment_account,bank_name,bank_account_number,match_option,instruction_for_charges,delivery_method,previous_master_record,alternate_payee,pay_alone,processing_status,component_name,conc_req_id,last_updated_date,last_updated_by,creation_date,created_by,last_update_login,attribute31,attribute32,attribute33,attribute34,attribute35,attribute36,attribute37,attribute38,attribute39,attribute40)

SELECT xx_ap_supplier_sites_stg_s.nextval,vendor_site_code,TRIM(vendor_name),vndr_alternate_name,operating_unit,address_line_1,address_line_2,address_line_3,city,state,zip

,province,country,ship_to_location_code,bill_to_location_code,email_address,purchasing_site_flag,pay_site_flag,rfq_only_site_flag,payment_method_lookup_code,liability_account_segment1,liability_account_segment2,liability_account_segment3,liability_account_segment4,liability_account_segment5,liability_account_segment6,pay_group_lookup_code,payment_priority,terms_name,terms_date_basis,pay_date_basis,invoice_currency_code,'SGD'--payment_currency_code,future_dated_payment_account,bank_name,bank_account_number,match_option,instruction_for_charges,delivery_method,previous_master_record,alternate_payee,decode('YES','Y','NO','N'),'N','AP SUPPLIER SITES',l_request_id,sysdate,l_ln_user_id,sysdate,l_ln_user_id,l_login_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULLFROM ods_sap.stg_ap_site_supplier_temp@crystalWHERE load_id = NVL(p_load_id1, load_id)AND TRIM(operating_unit) IN ('PHSPL','PLS','MRA','MEMHL','PGH')AND TRIM(vendor_name) IN(SELECT TRIM(vendor_name) FROM xx_ap_suppliers_stg);

EXCEPTION

WHEN OTHERS THENfnd_file.put_line(fnd_file.log,'Error While inserting records into Sites Staging Table '||SQLERRM );

END;

SELECT count(*) INTO l_count1 FROM xx_ap_supplier_sites_stg;

fnd_file.put_line(fnd_file.OUTPUT,'TOTAL NUMBER OF RECORDS INSERTED INTO SUPPLIER SITES STAGING TABLE :'||l_count1 );-- call the third one.. BEGIN INSERT INTO xx_ap_supp_contacts_stg ( contact_transaction_id ,vendor_name ,vendor_id ,vendor_site_code ,vendor_site_id ,operating_unit ,org_id ,first_name ,middle_name ,last_name ,prefix ,area_code ,department ,phone ,fax_area_code ,fax ,alt_area_code ,alt_phone ,processing_status ,component_name ,conc_req_id ,last_updated_date ,last_updated_by,creation_date,created_by,last_update_login,attribute31,attribute32,attribute33,attribute34,attribute35,attribute36,attribute37,attribute38,attribute39,attribute40)SELECTxx_ap_supp_con_stg_s.nextval,TRIM(vendor_name),NULL

,TRIM(vendor_site_code),NULL,TRIM(operating_unit),NULL,first_name,middle_name,last_name,prefix,area_code,department,phone--decode(TRIM(phone),'/',NULL,phone),fax_area_code,fax ,alt_area_code ,alt_phone,'N','AP_SUPPLIER_CONTACTS',l_request_id,sysdate,l_ln_user_id,sysdate,l_ln_user_id,l_login_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULLFROM ods_sap.stg_ap_site_supplier_temp@crystalWHERE TRIM(vendor_name) IN(SELECT TRIM(vendor_name) FROM xx_ap_supplier_sites_stg)AND last_name IS NOT NULLAND load_id = NVL(p_load_id2, load_id);

INSERT INTO xx_ap_supp_contacts_stg ( contact_transaction_id ,vendor_name ,vendor_id ,vendor_site_code ,vendor_site_id ,operating_unit ,org_id ,first_name ,middle_name ,last_name --,prefix ,area_code ,department ,phone ,fax_area_code

,fax ,alt_area_code ,alt_phone ,processing_status ,component_name ,conc_req_id ,last_updated_date ,last_updated_by,creation_date,created_by,last_update_login,attribute31,attribute32,attribute33,attribute34,attribute35,attribute36,attribute37,attribute38,attribute39,attribute40)SELECT xx_ap_supp_con_stg_s.nextval,TRIM(vendor_name),NULL,TRIM(vendor_site_code),NULL,TRIM(operating_unit),NULL,first_name1,middle_name1,last_name1--,prefix,area_code1,department1,phone1--decode(TRIM(phone1),'/',NULL,phone1),fax_area_code1,fax1 ,alt_area_code1 ,alt_phone1,'N','AP_SUPPLIER_CONTACTS',l_request_id,sysdate,l_ln_user_id,sysdate,l_ln_user_id,l_login_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL

,NULL,NULLFROM ods_sap.stg_ap_site_supplier_temp@crystalWHERE TRIM(vendor_name) IN(SELECT TRIM(vendor_name) FROM xx_ap_supplier_sites_stg)AND last_name1 IS NOT NULLAND load_id = NVL(p_load_id2, load_id);

COMMIT;SELECT count(*)INTO lv_SiteContactFROM xx_ap_supp_contacts_stg;END;

fnd_file.put_line(fnd_file.OUTPUT,'TOTAL NUMBER OF RECORDS INSERTED INTO SUPPLIER CONTACTS STAGING TABLE :'||lv_SiteContact );

COMMIT;END xx_ph_ap_load_supp_stg_prc ;/*************************************************************************************************//* This procedure is used to update the Bank and Bank Acounts into po_vendor_sites_all Base Table */PROCEDURE xx_ph_ap_update_banks_prc(errbuf OUT VARCHAR2, retcode OUT NUMBER ) AS

l_count NUMBER:=NULL; l_count1 NUMBER:=NULL; l_count2 NUMBER:=NULL; l_bank_account_id NUMBER:=NULL; l_request_id NUMBER := to_number(fnd_global.conc_request_id); l_vendor_site_id NUMBER := NULL; l_vendor_id NUMBER :=NULL; l_bank_name VARCHAR2(60):=NULL; l_bank_account_number VARCHAR2(60) :=NULL; l_err_code VARCHAR2(2000) :=NULL; l_login_id NUMBER :=to_number(fnd_profile.value('LOGIN_ID')); l_user_id NUMBER := fnd_global.user_id;

CURSOR cur_upd_banks IS SELECT apss.* FROM xx_ap_supplier_sites_stg apss,xx_ap_suppliers_stg aps WHERE apss.vendor_name=aps.vendor_name AND apss.processing_status = 'V' AND aps.processing_status = 'V'; BEGIN

FOR cur_update_banks_rec IN cur_upd_banks LOOP BEGIN l_bank_account_id:=NULL;

SELECT bank_account_id INTO l_bank_account_id FROM ap_bank_accounts_all WHERE bank_account_name=TRIM(cur_update_banks_rec.bank_name) AND bank_account_num=TRIM(cur_update_banks_rec.bank_account_number) AND org_id=TRIM(cur_update_banks_rec.org_id); EXCEPTION WHEN NO_DATA_FOUND THEN fnd_file.PUT_LINE(fnd_file.LOG,'Not a valid Bank and Bank Accounts Name'); l_err_code := 'Not a valid Bank and Bank Accounts Name'; xxph_common_dmg_pkg.insert_error_message_prc(NULL,cur_update_banks_rec.component_name,'VENDOR_SITE_CODE',cur_update_banks_rec.bank_name, 'VALIDATION', l_err_code, NULL); WHEN TOO_MANY_ROWS THEN fnd_file.PUT_LINE(fnd_file.LOG,'Too Many Rows While Validating Bank and Bank Accounts Name'); l_err_code := 'Too Many Rows While Validating Bank and Bank Accounts Name'; xxph_common_dmg_pkg.insert_error_message_prc(NULL,cur_update_banks_rec.component_name,'VENDOR_SITE_CODE',cur_update_banks_rec.bank_name, 'VALIDATION', l_err_code, NULL); WHEN OTHERS THEN fnd_file.PUT_LINE(fnd_file.LOG,'Other Errors While Validating Bank and Bank Accounts Name'); l_err_code := 'Other Errors While Validating Bank and Bank Accounts Name'|| SQLERRM; xxph_common_dmg_pkg.insert_error_message_prc(NULL,cur_update_banks_rec.component_name,'VENDOR_SITE_CODE',cur_update_banks_rec.bank_name, 'VALIDATION', l_err_code, NULL); END; IF l_bank_account_id IS NOT NULL THEN BEGIN l_count :=NULL; l_vendor_site_id := NULL; l_vendor_id:=NULL; l_err_code :=NULL; SELECT COUNT(1),a.vendor_id,b.vendor_site_id INTO l_count,l_vendor_id,l_vendor_site_id FROM po_vendor_sites_all b,po_vendors a WHERE a.vendor_name=TRIM(cur_update_banks_rec.vendor_name) AND b.vendor_site_code=TRIM(cur_update_banks_rec.vendor_site_code) AND a.vendor_id=b.vendor_id GROUP BY a.vendor_id,b.vendor_site_id;

EXCEPTION WHEN NO_DATA_FOUND THEN fnd_file.PUT_LINE(fnd_file.LOG,'Not A Valid Vendor and Vendor Site Code'); l_err_code := 'Not A Valid Vendor and Vendor Site Code'; xxph_common_dmg_pkg.insert_error_message_prc(NULL,cur_update_banks_rec.component_name,'VENDOR_SITE_CODE',cur_update_banks_rec.vendor_site_code, 'VALIDATION', l_err_code, NULL); WHEN TOO_MANY_ROWS THEN fnd_file.PUT_LINE(fnd_file.LOG,'Too Many Rows While Validating Vendor and Vendor Site Code'); l_err_code := 'Too Many Rows While Validating Vendor and Vendor Site Code'; xxph_common_dmg_pkg.insert_error_message_prc(NULL,cur_update_banks_rec.component_name,'VENDOR_SITE_CODE',cur_update_banks_rec.vendor_site_code, 'VALIDATION', l_err_code, NULL); WHEN OTHERS THEN fnd_file.PUT_LINE(fnd_file.LOG,'Other Errors While Validating Vendor and Vendor Site Code'|| SQLERRM ); l_err_code := 'Other Errors While Validating Vendor and Vendor Site Code'|| SQLERRM; xxph_common_dmg_pkg.insert_error_message_prc(NULL,cur_update_banks_rec.component_name,'VENDOR_SITE_CODE',cur_update_banks_rec.vendor_site_code, 'VALIDATION', l_err_code, NULL); END; END IF; IF l_count>0 THEN BEGIN l_bank_name :=NULL; l_bank_account_number :=NULL; SELECT bank_name,bank_account_number INTO l_bank_name,l_bank_account_number FROM xx_ap_supplier_sites_stg WHERE TRIM(vendor_site_code)=TRIM(cur_update_banks_rec.vendor_site_code) AND TRIM(vendor_name)=TRIM(cur_update_banks_rec.vendor_name) AND processing_status='V'; fnd_file.put_line(fnd_file.output,l_bank_name ||l_bank_account_number); EXCEPTION WHEN NO_DATA_FOUND THEN fnd_file.PUT_LINE(fnd_file.LOG,' Bank and Bank Account Number While Fetching '); l_err_code := ' Bank and Bank Account Number While Fetching '; xxph_common_dmg_pkg.insert_error_message_prc(NULL,cur_update_banks_rec.component_name,'BANK and BANK ACCOUNTS

NUMBER',cur_update_banks_rec.bank_account_number, 'VALIDATION', l_err_code, NULL); WHEN TOO_MANY_ROWS THEN fnd_file.PUT_LINE(fnd_file.LOG,' Too Many Values when Fetching Bank and Bank Account Number'); l_err_code := ' Too Many Values when Fetching Bank and Bank Account Number'; xxph_common_dmg_pkg.insert_error_message_prc(NULL,cur_update_banks_rec.component_name,'BANK and BANK ACCOUNTS NUMBER',cur_update_banks_rec.bank_account_number, 'VALIDATION', l_err_code, NULL); WHEN OTHERS THEN fnd_file.PUT_LINE(fnd_file.LOG,' Other Errors when Fetching Bank and Bank Account Number'|| SQLERRM); l_err_code := ' Other Errors when Fetching Bank and Bank Account Number'|| SQLERRM; xxph_common_dmg_pkg.insert_error_message_prc(NULL,cur_update_banks_rec.component_name,'BANK and BANK ACCOUNTS NUMBER',cur_update_banks_rec.bank_account_number, 'VALIDATION', l_err_code, NULL); END; END IF; IF (l_bank_account_id IS NOT NULL) THEN BEGIN INSERT INTO ap_bank_account_uses_all( bank_account_uses_id ,last_update_date ,last_updated_by ,creation_date ,last_update_login ,start_date ,created_by ,vendor_id ,vendor_site_id ,external_bank_account_id ,primary_flag ,org_id ,request_id ) VALUES( ap_bank_account_uses_s.nextval ,sysdate ,l_user_id ,sysdate ,l_login_id ,sysdate ,l_user_id ,l_vendor_id

,l_vendor_site_id ,l_bank_account_id ,'Y' ,cur_update_banks_rec.org_id ,l_request_id ); COMMIT; fnd_file.PUT_LINE(fnd_file.OUTPUT,'Inserted Into Base Tables'||l_bank_name ||l_bank_account_number); EXCEPTION WHEN OTHERS THEN fnd_file.PUT_LINE(fnd_file.OUTPUT,' Error when Inserting into Oracle Table '|| SQLERRM); l_err_code := ' Error when Inserting into Oracle Table '|| SQLERRM; xxph_common_dmg_pkg.insert_error_message_prc(NULL,cur_update_banks_rec.component_name,'INSERTION ERROR',cur_update_banks_rec.bank_account_number, 'INSERTION', l_err_code, NULL); END; END IF;END LOOP;

BEGIN SELECT COUNT(1) INTO l_count2 FROM xx_ap_supplier_sites_stg WHERE processing_status='V'; fnd_file.put_line(fnd_file.OUTPUT,'Total Records Selected For Tagging :' || l_count2); ENd; BEGIN SELECT COUNT(1) INTO l_count1 FROM ap_bank_accounts_all WHERE request_id =l_request_id; fnd_file.put_line(fnd_file.OUTPUT,'Total Records Tagged Sucessfully :' || l_count1); END;

END xx_ph_ap_update_banks_prc;

/***************************Procedure to update the Supplier staging table with error status*****************/ PROCEDURE xx_ph_su_upd_fail_prc(p_rowid IN rowid, p_err_msg IN VARCHAR2) AS l_user_id NUMBER; l_login_id NUMBER; l_errbuff VARCHAR2(500); l_retcode VARCHAR2(50);

BEGIN l_user_id := NVL(fnd_profile.VALUE('USER_ID'), -1); l_login_id := NVL(fnd_profile.VALUE('LOGIN_ID'), -1);

UPDATE xx_ap_suppliers_stg SET last_updated_by = l_user_id, last_updated_date = sysdate, last_update_login = l_login_id, processing_status = 'E' WHERE rowid = p_rowid;

COMMIT; fnd_file.PUT_LINE(fnd_file.LOG, 'Updated suppliers processing status as E');

EXCEPTION WHEN others THEN fnd_file.PUT_LINE(fnd_file.LOG, 'Error While Updating Error Flag in staging Table for rowid' || p_rowid || ' ' || sqlerrm);

END xx_ph_su_upd_fail_prc;

--****************Procedure to update the Supplier Sites staging table with error status************/ PROCEDURE xx_ph_si_upd_fail_prc(p_rowid IN rowid, p_err_msg IN VARCHAR2) AS l_user_id NUMBER; l_login_id NUMBER; l_errbuff VARCHAR2(500); l_retcode VARCHAR2(50);

BEGIN l_user_id := NVL(fnd_profile.VALUE('USER_ID'), -1); l_login_id := NVL(fnd_profile.VALUE('LOGIN_ID'), -1);

UPDATE xx_ap_supplier_sites_stg SET last_updated_by = l_user_id, last_updated_date = sysdate, last_update_login = l_login_id, processing_status = 'E' WHERE rowid = p_rowid; COMMIT; fnd_file.PUT_LINE(fnd_file.LOG, 'updated supplier sties processing status as E');

EXCEPTION WHEN others THEN fnd_file.PUT_LINE(fnd_file.LOG, 'Error While Updating Error Flag in staging Table for rowid' || p_rowid || ' ' || sqlerrm);

END xx_ph_si_upd_fail_prc;

/**********************************Procedure for Validating Supplier Sites Table*******/

PROCEDURE xx_ph_ap_supp_valid_dat_prc (p_request IN NUMBER)IS

/**************************Local Variables****************************************/

l_count NUMBER := 0; l_count1 NUMBER := 0; l_status VARCHAR2(1) := 'N'; l_error_code VARCHAR2(2000) := NULL; l_supp_code VARCHAR2(2000) := NULL; l_vendor_type_lookup_code VARCHAR2(100) := NULL; l_org_id NUMBER; l_terms_id NUMBER; l_term_name VARCHAR2(30); l_term_date_basis VARCHAR2(30); l_payment_priority NUMBER :=NULL; l_country VARCHAR2(30); l_count_sg1 NUMBER; l_count_sg2 NUMBER; l_count_sg3 NUMBER; l_count_sg4 NUMBER; l_count_sg5 NUMBER; l_count_sg6 NUMBER; l_delivery_method NUMBER:=NULL; l_pay_group VARCHAR2(30); l_match_option VARCHAR2(20); l_pay_date_basis VARCHAR2(30); l_liability_account_id NUMBER; l_prepayment_account_id NUMBER; l_invoice_currency_code VARCHAR2(15); l_payment_currency_code VARCHAR2(15); l_payment_code VARCHAR2(15); l_request_id NUMBER := fnd_global.conc_request_id;

/************************Cursor For Supplier Staging Table*****************************/ CURSOR cur_new_vendors IS SELECT a.*, a.rowid FROM xx_ap_suppliers_stg a WHERE processing_status = 'N' AND conc_req_id=p_request;

/************************Cursor For Supplier Sites Staging Table*****************************/ CURSOR cur_new_ven_sites(l_vendor_name IN VARCHAR2) IS SELECT b.*, b.rowid FROM xx_ap_supplier_sites_stg b WHERE TRIM(b.vendor_name) = TRIM(l_vendor_name) AND processing_status = 'N' AND conc_req_id=p_request; /************************Validating Supplier Staging Table Fields*****************************/

BEGIN

FOR cur_xxph_suppliers_rec IN cur_new_vendors LOOP l_supp_code := NULL; l_error_code := NULL;

IF TRIM(cur_xxph_suppliers_rec.vendor_name) IS NULL THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Vendor Name Do not Exist',1,100),'') ,40,' '));

l_supp_code := 'Vendor name Do not Exist'; xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_suppliers_rec.supplier_transaction_id, cur_xxph_suppliers_rec.component_name, 'VENDOR_NAME', cur_xxph_suppliers_rec.vendor_name, 'DATA', l_supp_code, NULL); xx_ph_su_upd_fail_prc(cur_xxph_suppliers_rec.rowid, l_supp_code); ELSE l_count := NULL; SELECT COUNT(*) INTO l_count FROM po_vendors WHERE TRIM(UPPER(vendor_name)) = UPPER(TRIM(cur_xxph_suppliers_rec.vendor_name));

IF(l_count > 0) THEN

l_supp_code := 'Vendor Name already exists with this name in Oracle ERP'; xx_ph_su_upd_fail_prc(cur_xxph_suppliers_rec.rowid, l_supp_code); fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Vendor Name already exists with this name in Oracle ERP',1,40),'') ,40,' ')); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_suppliers_rec.supplier_transaction_id, cur_xxph_suppliers_rec.component_name, 'VENDOR_NAME', cur_xxph_suppliers_rec.vendor_name, 'DATA', l_supp_code, NULL); END IF;

BEGIN

l_count := 0; SELECT COUNT(1) INTO l_count FROM xx_ap_suppliers_stg WHERE TRIM(UPPER(vendor_name)) = UPPER(TRIM(cur_xxph_suppliers_rec.vendor_name)) AND processing_status = 'N';

IF(l_count > 1) THEN l_supp_code := 'Duplicate vendor Name Exists'; xx_ph_su_upd_fail_prc(cur_xxph_suppliers_rec.rowid, l_supp_code); fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Duplicate vendor Name Exists',1,100),'') ,80,' ')); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_suppliers_rec.supplier_transaction_id, cur_xxph_suppliers_rec.component_name, 'VENDOR_NAME', cur_xxph_suppliers_rec.vendor_name, 'DATA', l_supp_code, NULL); END IF;

END; END IF;

IF TRIM(cur_xxph_suppliers_rec.vendor_alternate_name) IS NULL THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Vendor Alternate Name Do not Exist',1,100),'') ,80,' ')); l_supp_code := 'Vendor Alternate Name Do not Exist'; xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_suppliers_rec.supplier_transaction_id, cur_xxph_suppliers_rec.component_name, 'VENDOR_ALTERNATE_NAME', cur_xxph_suppliers_rec.vendor_alternate_name, 'DATA', l_supp_code, NULL); xx_ph_su_upd_fail_prc(cur_xxph_suppliers_rec.rowid, l_supp_code); END IF;

BEGIN

l_vendor_type_lookup_code := NULL;

SELECT DISTINCT (lookup_code) INTO l_vendor_type_lookup_code FROM fnd_lookup_values WHERE lookup_type='VENDOR TYPE' AND enabled_flag='Y' AND UPPER(meaning) = TRIM(UPPER(cur_xxph_suppliers_rec.vendor_type_lookup_code));

UPDATE xx_ap_suppliers_stg SET vendor_type_lookup_code = l_vendor_type_lookup_code WHERE rowid = cur_xxph_suppliers_rec.rowid;

EXCEPTION

WHEN NO_DATA_FOUND THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Not a Valid Vendor type lookup code',1,40),'') ,40,' ')); l_supp_code := 'Not a Valid Vendor type lookup code'; xx_ph_su_upd_fail_prc(cur_xxph_suppliers_rec.rowid, l_supp_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_suppliers_rec.supplier_transaction_id, cur_xxph_suppliers_rec.component_name, 'VENDOR_TYPE_LOOKUP_CODE', cur_xxph_suppliers_rec.vendor_type_lookup_code, 'VALIDATION', l_supp_code, NULL);

WHEN TOO_MANY_ROWS THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Too Many Values for Vendor type lookup code',1,40),'') ,40,' ')); l_supp_code := 'Too Many Values for Vendor type lookup code '; xx_ph_su_upd_fail_prc(cur_xxph_suppliers_rec.rowid, l_supp_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_suppliers_rec.supplier_transaction_id, cur_xxph_suppliers_rec.component_name, 'VENDOR_TYPE_LOOKUP_CODE', cur_xxph_suppliers_rec.vendor_type_lookup_code, 'VALIDATION', l_supp_code, NULL);

WHEN OTHERS THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Other errors While Validating Vendor type lookup code',1,40),'') ,40,' ')); l_supp_code := 'Other errors While Validating Vendor type lookup code' || sqlerrm;

xx_ph_su_upd_fail_prc(cur_xxph_suppliers_rec.rowid, l_supp_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_suppliers_rec.supplier_transaction_id, cur_xxph_suppliers_rec.component_name, 'VENDOR_TYPE_LOOKUP_CODE', cur_xxph_suppliers_rec.vendor_type_lookup_code, 'VALIDATION', l_supp_code, NULL);

END;

/************************Validating Supplier Sites Staging Table Fields*****************************/

FOR cur_xxph_supplier_sites_rec IN cur_new_ven_sites(TRIM(cur_xxph_suppliers_rec.vendor_name)) LOOP

l_error_code := NULL;

IF TRIM(cur_xxph_supplier_sites_rec.vendor_site_code) IS NULL THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Vendor Site code Do not Exist',1,40),'') ,40,' ')); l_error_code := 'Vendor Site code Do not Exist'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'VENDOR_SITE_CODE', cur_xxph_supplier_sites_rec.vendor_site_code, 'DATA', l_error_code, NULL);

ELSE l_count1 := 0; SELECT COUNT(1) INTO l_count1 FROM xx_ap_supplier_sites_stg WHERE TRIM(vendor_site_code) = TRIM(cur_xxph_supplier_sites_rec.vendor_site_code) AND TRIM(vendor_name) = TRIM(cur_xxph_supplier_sites_rec.vendor_name) AND processing_status = 'N';

IF(l_count1 > 1) THEN l_error_code := 'Duplicate Vendor Site Code Exists'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Duplicate Vendor Site Code Exists',1,40),'') ,40,' ')); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'VENDOR_SITE_CODE', cur_xxph_supplier_sites_rec.vendor_site_code, 'DATA', l_error_code, NULL);

END IF;

END IF;

IF TRIM(cur_xxph_supplier_sites_rec.country) IS NULL THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Country Do not Exist',1,100),'') ,80,' ')); l_error_code := 'Country Do not Exist'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'COUNTRY', cur_xxph_supplier_sites_rec.country, 'DATA', l_error_code, NULL);

END IF;

IF TRIM(cur_xxph_supplier_sites_rec.pay_site_flag) IS NULL THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Pay Site Flag Do not Exist',1,100),'') ,80,' ')); l_error_code := 'Pay Site Flag Do not Exist'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'PAY SITE FLAG', cur_xxph_supplier_sites_rec.pay_site_flag, 'DATA', l_error_code, NULL);

END IF; IF TRIM(cur_xxph_supplier_sites_rec.payment_method_lookup_code) IS NULL THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Payment Method Lookup Code Do not Exist',1,100),'') ,80,' ')); l_error_code := 'Payment Method Lookup Code Do not Exist'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'PAYMENT_METHOD_LOOKUP_CODE', cur_xxph_supplier_sites_rec.payment_method_lookup_code, 'DATA', l_error_code, NULL);

END IF;

IF TRIM(cur_xxph_supplier_sites_rec.liability_account_segment1) IS NULL THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Liability account segment1 Do not Exist',1,100),'') ,80,' ')); l_error_code := 'Liability Account Segment1 Do not Exist'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'LIABILITY_ACCOUNT_SEGMENT1',

cur_xxph_supplier_sites_rec.liability_account_segment1, 'DATA', l_error_code, NULL); END IF;

BEGIN l_count_sg1:=NULL; SELECT COUNT (1) INTO l_count_sg1 FROM fnd_flex_values_vl b, fnd_flex_value_sets a WHERE a. flex_value_set_name = 'PH_COMPANY' AND a. flex_value_set_id = b.flex_value_set_id AND NVL(b .enabled_flag, 'N' ) = 'Y' AND NVL(b .end_date_active, trunc(SYSDATE)) >= trunc(SYSDATE) AND b.flex_value =to_char(cur_xxph_supplier_sites_rec.liability_account_segment1) AND b.summary_flag='Y';

IF l_count_sg1 > 0 THEN l_error_code := 'Parent account should not take For Segment1'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid,l_error_code) ; xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment1',cur_xxph_supplier_sites_rec.liability_account_segment1,'VALIDATION', l_error_code,NULL); fnd_file.put_line (fnd_file.log, l_error_code); END IF;

END;

IF TRIM(cur_xxph_supplier_sites_rec.liability_account_segment2) IS NULL THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Liability account segment2 Do not Exist',1,100),'') ,40,' ')); l_error_code := 'Liability Account Segment2 Do not Exist';

xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'LIABILITY_ACCOUNT_SEGMENT2', cur_xxph_supplier_sites_rec.liability_account_segment2, 'DATA', l_error_code, NULL);

END IF;

BEGIN l_count_sg2:=NULL; SELECT COUNT (1) INTO l_count_sg2 FROM fnd_flex_values_vl b, fnd_flex_value_sets a WHERE a. flex_value_set_name = 'PH_DIVISION' AND a. flex_value_set_id = b.flex_value_set_id AND NVL(b .enabled_flag, 'N' ) = 'Y' AND NVL(b .end_date_active, trunc(SYSDATE)) >= trunc(SYSDATE)

AND b.flex_value =to_char(cur_xxph_supplier_sites_rec.liability_account_segment2) AND b.summary_flag='Y';

IF l_count_sg2 > 0 THEN l_error_code := 'Parent account should not take For Segment2'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code) ; xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment2',cur_xxph_supplier_sites_rec.liability_account_segment2,'VALIDATION', l_error_code,NULL); fnd_file.put_line (fnd_file.log, l_error_code); END IF;

END;

IF TRIM(cur_xxph_supplier_sites_rec.liability_account_segment3) IS NULL THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Liability account segment3 Do not Exist',1,40),'') ,40,' ')); l_error_code := 'Liability Account Segment3 Do not Exist';

xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'LIABILITY_ACCOUNT_SEGMENT3', cur_xxph_supplier_sites_rec.liability_account_segment3, 'DATA', l_error_code, NULL);

END IF;

BEGIN l_count_sg3:=NULL; SELECT COUNT (1) INTO l_count_sg3 FROM fnd_flex_values_vl b, fnd_flex_value_sets a WHERE a. flex_value_set_name = 'PH_COST_CENTRE' AND a. flex_value_set_id = b.flex_value_set_id AND NVL(b .enabled_flag, 'N' ) = 'Y' AND NVL(b .end_date_active, trunc(SYSDATE)) >= trunc(SYSDATE) AND b.flex_value =to_char(cur_xxph_supplier_sites_rec.liability_account_segment3) AND b.summary_flag='Y';

IF l_count_sg3 > 0 THEN l_error_code := 'Parent account should not take For Segment3'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid,l_error_code) ; xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment3',cur_xxph_supplier_sites_rec.liability_account_segment3,'VALIDATION', l_error_code,NULL); fnd_file.put_line (fnd_file.log, l_error_code);

END IF;

END;

IF TRIM(cur_xxph_supplier_sites_rec.liability_account_segment4) IS NULL THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Liability account segment4 Do not Exist',1,40),'') ,40,' ')); l_error_code := 'Liability Account Segment4 Do not Exist';

xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'LIABILITY_ACCOUNT_SEGMENT4', cur_xxph_supplier_sites_rec.liability_account_segment4, 'DATA', l_error_code, NULL);

END IF;

BEGIN l_count_sg4:=NULL; SELECT COUNT (1) INTO l_count_sg4 FROM fnd_flex_values_vl b, fnd_flex_value_sets a WHERE a. flex_value_set_name = 'PH_ACCOUNT' AND a. flex_value_set_id = b.flex_value_set_id AND NVL(b .enabled_flag, 'N' ) = 'Y' AND NVL(b .end_date_active, trunc(SYSDATE)) >= trunc(SYSDATE) AND b.flex_value =to_char(cur_xxph_supplier_sites_rec.liability_account_segment4) AND b.summary_flag='Y';

IF l_count_sg4 > 0 THEN l_error_code := 'Parent account should not take For Segment4'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid,l_error_code) ; xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment4',cur_xxph_supplier_sites_rec.liability_account_segment4,'VALIDATION', l_error_code,NULL); fnd_file.put_line (fnd_file.log, l_error_code); END IF;

END;

IF TRIM(cur_xxph_supplier_sites_rec.liability_account_segment5) IS NULL THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Liability account segment5 Do not Exist',1,40),'') ,40,' ')); l_error_code := 'Liability Account Segment5 Do not Exist';

xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code);

xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'LIABILITY_ACCOUNT_SEGMENT5', cur_xxph_supplier_sites_rec.liability_account_segment5, 'DATA', l_error_code, NULL);

END IF;

BEGIN l_count_sg5:=NULL; SELECT COUNT (1) INTO l_count_sg5 FROM fnd_flex_values_vl b, fnd_flex_value_sets a WHERE a. flex_value_set_name = 'PH_MOV_CODE' AND a. flex_value_set_id = b.flex_value_set_id AND NVL(b .enabled_flag, 'N' ) = 'Y' AND NVL(b .end_date_active, trunc(SYSDATE)) >= trunc(SYSDATE) AND b.flex_value =to_char(cur_xxph_supplier_sites_rec.liability_account_segment5) AND b.summary_flag='Y';

IF l_count_sg5 > 0 THEN l_error_code := 'Parent account should not take For Segment5'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid,l_error_code) ; xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment5',cur_xxph_supplier_sites_rec.liability_account_segment5,'VALIDATION', l_error_code,NULL); fnd_file.put_line (fnd_file.log, l_error_code); END IF;

END;

IF TRIM(cur_xxph_supplier_sites_rec.liability_account_segment6) IS NULL THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Liability account segment6 Do not Exist',1,40),'') ,40,' '));

l_error_code := 'Segment6 Do not Exist';

xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'LIABILITY_ACCOUNT_SEGMENT6', cur_xxph_supplier_sites_rec.liability_account_segment6, 'DATA', l_error_code, NULL);

END IF;

BEGIN l_count_sg6:=NULL; SELECT COUNT (1)

INTO l_count_sg6 FROM fnd_flex_values_vl b, fnd_flex_value_sets a WHERE a. flex_value_set_name = 'PH_STAT_CODE' AND a. flex_value_set_id = b.flex_value_set_id AND NVL(b .enabled_flag, 'N' ) = 'Y' AND NVL(b .end_date_active, trunc(SYSDATE)) >= trunc(SYSDATE) AND b.flex_value =to_char(cur_xxph_supplier_sites_rec.liability_account_segment6) AND b.summary_flag='Y';

IF l_count_sg6 > 0 THEN l_error_code := 'Parent account should not take For Segment6'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid,l_error_code) ; xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment6',cur_xxph_supplier_sites_rec.liability_account_segment6,'VALIDATION', l_error_code,NULL); fnd_file.put_line (fnd_file.log, l_error_code); END IF;

END; IF TRIM(cur_xxph_supplier_sites_rec.payment_priority) IS NULL THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Payment Priority Do not Exist',1,100),'') ,40,' ')); l_error_code := 'Payment Priority Do Not Exist'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'PAYMENT_PRIORITY', cur_xxph_supplier_sites_rec.payment_priority, 'DATA', l_error_code, NULL);

ELSIF

((cur_xxph_supplier_sites_rec.payment_priority < 1) OR (cur_xxph_supplier_sites_rec.payment_priority > 99)) THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Payment Priority Is Not Valid',1,100),'') ,40,' '));

l_error_code := 'Payment Priority Is Not Valid'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'PAYMENT_PRIORITY', cur_xxph_supplier_sites_rec.payment_priority, 'DATA', l_error_code, NULL);

END IF;

IF TRIM(cur_xxph_supplier_sites_rec.term_name) IS NULL THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Terms Name Do not Exist',1,100),'') ,40,' '));

l_error_code := 'Terms Name Do not Exist'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'TERM_NAME', cur_xxph_supplier_sites_rec.term_name, 'DATA', l_error_code, NULL);

END IF;

IF TRIM(cur_xxph_supplier_sites_rec.terms_date_basis) IS NULL THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Terms Date Basis Name Do not Exist',1,40),'') ,40,' ')); l_error_code := 'Terms Date Basis Do not Exist';

xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'TERMS_DATE_BASIS', cur_xxph_supplier_sites_rec.terms_date_basis, 'DATA', l_error_code, NULL);

END IF;

IF TRIM(cur_xxph_supplier_sites_rec.pay_date_basis) IS NULL THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Pay Date Basis Name Do not Exist',1,40),'') ,40,' ')); l_error_code := 'Pay Date Basis Do not Exist';

xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'PAY_DATE_BASIS', cur_xxph_supplier_sites_rec.pay_date_basis, 'DATA', l_error_code, NULL);

END IF;

IF TRIM(cur_xxph_supplier_sites_rec.invoice_currency_code) IS NULL THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Invoice_Currency_Code Do not Exist',1,40),'') ,40,' '));

l_error_code := 'Invoice_Currency_Code Do not Exist'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code);

xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'INVOICE_CURRENCY_CODE', cur_xxph_supplier_sites_rec.invoice_currency_code, 'DATA', l_error_code, NULL);

END IF;

IF TRIM(cur_xxph_supplier_sites_rec.match_option) IS NULL THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Match Option Do not Exist',1,40),'') ,40,' '));

l_error_code := 'Match Option Do not Exist'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'MATCH_OPTION', cur_xxph_supplier_sites_rec.match_option, 'DATA', l_error_code, NULL);

END IF;

l_match_option:=0; SELECT match_option INTO l_match_option FROM xx_ap_supplier_sites_stg WHERE rowid = cur_xxph_supplier_sites_rec.rowid;

IF l_match_option='Purchase Order' THEN

UPDATE xx_ap_supplier_sites_stg SET match_option='P' WHERE rowid = cur_xxph_supplier_sites_rec.rowid; ELSIF

l_match_option='Receipt' THEN

UPDATE xx_ap_supplier_sites_stg SET match_option='R' WHERE rowid = cur_xxph_supplier_sites_rec.rowid;

END IF; COMMIT;/*************************************************************************************/

--Start Check for valid segments

/***************************************************************************************/

BEGIN --segment1 l_count_sg1:=NULL; SELECT COUNT (1) INTO l_count_sg1 FROM fnd_flex_values_vl b, fnd_flex_value_sets a WHERE a. flex_value_set_name = 'PH_COMPANY' AND a. flex_value_set_id = b.flex_value_set_id AND NVL(b .enabled_flag, 'N' ) = 'Y' AND NVL(b .end_date_active, trunc(SYSDATE)) >= trunc(SYSDATE) AND b.flex_value =to_char(cur_xxph_supplier_sites_rec.liability_account_segment1);

IF l_count_sg1 = 0 THEN l_error_code := 'Invalid value For Segment1'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid,l_error_code) ; xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment1',cur_xxph_supplier_sites_rec.liability_account_segment1,'VALIDATION', l_error_code,NULL); fnd_file.put_line (fnd_file.log, l_error_code); END IF;

EXCEPTION WHEN NO_DATA_FOUND THEN l_error_code := 'Unable To Find value For Segment1'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment1',cur_xxph_supplier_sites_rec.liability_account_segment1,'VALIDATION', l_error_code,NULL); fnd_file.put_line(fnd_file.log, l_error_code); WHEN TOO_MANY_ROWS THEN l_error_code := 'TOO MANY ROWS To Find value For Segment1'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment1',cur_xxph_supplier_sites_rec.liability_account_segment1,'VALIDATION', l_error_code,NULL); fnd_file.put_line(fnd_file.log, l_error_code);

WHEN OTHERS THEN l_error_code := 'Unknown error in finding value For Segment1' ||SQLERRM; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment1',cur_xxph_supplier_sites_rec.liability_account_segment1,'VALIDATION', l_error_code,NULL); fnd_file.put_line(fnd_file.log, l_error_code);

END;

BEGIN l_count_sg2:=NULL; SELECT COUNT (1) INTO l_count_sg2 FROM fnd_flex_values_vl b, fnd_flex_value_sets a WHERE a. flex_value_set_name = 'PH_DIVISION' AND a. flex_value_set_id = b.flex_value_set_id AND NVL(b .enabled_flag, 'N' ) = 'Y' AND NVL(b .end_date_active, trunc(SYSDATE)) >= trunc(SYSDATE) AND b.flex_value =to_char(cur_xxph_supplier_sites_rec.liability_account_segment2);

IF l_count_sg2 = 0 THEN l_error_code := 'Invalid value For Segment2'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid,l_error_code) ; xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'liability_account_segment2',cur_xxph_supplier_sites_rec.liability_account_segment2,'VALIDATION', l_error_code,NULL); fnd_file.put_line (fnd_file.log, l_error_code); END IF;

EXCEPTION WHEN NO_DATA_FOUND THEN l_error_code := 'Unable To Find value For Segment2'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment2',cur_xxph_supplier_sites_rec.liability_account_segment2,'VALIDATION', l_error_code,NULL); fnd_file.put_line(fnd_file.log, l_error_code); WHEN TOO_MANY_ROWS THEN l_error_code := 'TOO MANY ROWS To Find value For Segment2'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment2',cur_xxph_supplier_sites_rec.liability_account_segment2,'VALIDATION', l_error_code,NULL); fnd_file.put_line(fnd_file.log, l_error_code);

WHEN OTHERS THEN l_error_code := 'Unknown error in finding value For Segment2' ||SQLERRM; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment2',cur_xxph_supplier_sites_rec.liability_account_segment2,'VALIDATION', l_error_code,NULL); fnd_file.put_line(fnd_file.log, l_error_code);

END;

BEGIN l_count_sg3:=NULL; SELECT COUNT (1) INTO l_count_sg3 FROM fnd_flex_values_vl b, fnd_flex_value_sets a WHERE a. flex_value_set_name = 'PH_COST_CENTRE' AND a. flex_value_set_id = b.flex_value_set_id AND NVL(b .enabled_flag, 'N' ) = 'Y' AND NVL(b .end_date_active, trunc(SYSDATE)) >= trunc(SYSDATE) AND b.flex_value =to_char(cur_xxph_supplier_sites_rec.liability_account_segment3);

IF l_count_sg3 = 0 THEN l_error_code := 'Invalid value For Segment3'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid,l_error_code) ; xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment3',cur_xxph_supplier_sites_rec.liability_account_segment3,'VALIDATION', l_error_code,NULL); fnd_file.put_line (fnd_file.log, l_error_code); END IF;

EXCEPTION WHEN NO_DATA_FOUND THEN l_error_code := 'Unable To Find value For Segment3'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment3',cur_xxph_supplier_sites_rec.liability_account_segment3,'VALIDATION', l_error_code,NULL); fnd_file.put_line(fnd_file.log, l_error_code); WHEN TOO_MANY_ROWS THEN l_error_code := 'TOO MANY ROWS To Find value For Segment3'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment3',cur_xxph_supplier_sites_rec.liability_account_segment3,'VALIDATION', l_error_code,NULL); fnd_file.put_line(fnd_file.log, l_error_code);

WHEN OTHERS THEN l_error_code := 'Unknown error in finding value For Segment3' ||SQLERRM; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment3',cur_xxph_supplier_sites_rec.liability_account_segment3,'VALIDATION', l_error_code,NULL); fnd_file.put_line(fnd_file.log, l_error_code);

END;

BEGIN l_count_sg4:=NULL; SELECT COUNT (1) INTO l_count_sg4 FROM fnd_flex_values_vl b, fnd_flex_value_sets a WHERE a. flex_value_set_name = 'PH_ACCOUNT' AND a. flex_value_set_id = b.flex_value_set_id AND NVL(b .enabled_flag, 'N' ) = 'Y' AND NVL(b .end_date_active, trunc(SYSDATE)) >= trunc(SYSDATE) AND b.flex_value =to_char(cur_xxph_supplier_sites_rec.liability_account_segment4);

IF l_count_sg4 = 0 THEN l_error_code := 'Invalid value For Segment4'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid,l_error_code) ; xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment4',cur_xxph_supplier_sites_rec.liability_account_segment4,'VALIDATION', l_error_code,NULL); fnd_file.put_line (fnd_file.log, l_error_code); END IF;

EXCEPTION WHEN NO_DATA_FOUND THEN l_error_code := 'Unable To Find value For Segment4'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment4',cur_xxph_supplier_sites_rec.liability_account_segment4,'VALIDATION', l_error_code,NULL); fnd_file.put_line(fnd_file.log, l_error_code); WHEN TOO_MANY_ROWS THEN l_error_code := 'TOO MANY ROWS To Find value For Segment4'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment4',cur_xxph_supplier_sites_rec.liability_account_segment2,'VALIDATION', l_error_code,NULL); fnd_file.put_line(fnd_file.log, l_error_code);

WHEN OTHERS THEN l_error_code := 'Unknown error in finding value For Segment4' ||SQLERRM; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name,

'Liability_account_segment4',cur_xxph_supplier_sites_rec.liability_account_segment4,'VALIDATION', l_error_code,NULL); fnd_file.put_line(fnd_file.log, l_error_code);

END;

BEGIN l_count_sg5:=NULL; SELECT COUNT (1) INTO l_count_sg5 FROM fnd_flex_values_vl b, fnd_flex_value_sets a WHERE a. flex_value_set_name = 'PH_MOV_CODE' AND a. flex_value_set_id = b.flex_value_set_id AND NVL(b .enabled_flag, 'N' ) = 'Y' AND NVL(b .end_date_active, trunc(SYSDATE)) >= trunc(SYSDATE) AND b.flex_value =to_char(cur_xxph_supplier_sites_rec.liability_account_segment5);

IF l_count_sg5 = 0 THEN l_error_code := 'Invalid value For Segment5'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid,l_error_code) ; xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment5',cur_xxph_supplier_sites_rec.liability_account_segment5,'VALIDATION', l_error_code,NULL); fnd_file.put_line (fnd_file.log, l_error_code); END IF;

EXCEPTION WHEN NO_DATA_FOUND THEN l_error_code := 'Unable To Find value For Segment5'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment5',cur_xxph_supplier_sites_rec.liability_account_segment5,'VALIDATION', l_error_code,NULL); fnd_file.put_line(fnd_file.log, l_error_code); WHEN TOO_MANY_ROWS THEN l_error_code := 'TOO MANY ROWS To Find value For Segment5'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment5',cur_xxph_supplier_sites_rec.liability_account_segment5,'VALIDATION', l_error_code,NULL); fnd_file.put_line(fnd_file.log, l_error_code);

WHEN OTHERS THEN l_error_code := 'Unknown error in finding value For Segment5' ||SQLERRM; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code);

xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment5',cur_xxph_supplier_sites_rec.liability_account_segment5,'VALIDATION', l_error_code,NULL); fnd_file.put_line(fnd_file.log, l_error_code);

END;

BEGIN l_count_sg6:=NULL; SELECT COUNT (1) INTO l_count_sg6 FROM fnd_flex_values_vl b, fnd_flex_value_sets a WHERE a. flex_value_set_name = 'PH_STAT_CODE' AND a. flex_value_set_id = b.flex_value_set_id AND NVL(b .enabled_flag, 'N' ) = 'Y' AND NVL(b .end_date_active, trunc(SYSDATE)) >= trunc(SYSDATE) AND b.flex_value =to_char(cur_xxph_supplier_sites_rec.liability_account_segment6);

IF l_count_sg6 = 0 THEN l_error_code := 'Invalid value For Segment6'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid,l_error_code) ; xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment6',cur_xxph_supplier_sites_rec.liability_account_segment6,'VALIDATION', l_error_code,NULL); fnd_file.put_line (fnd_file.log, l_error_code); END IF;

EXCEPTION WHEN NO_DATA_FOUND THEN l_error_code := 'Unable To Find value For Segment6'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment6',cur_xxph_supplier_sites_rec.liability_account_segment6,'VALIDATION', l_error_code,NULL); fnd_file.put_line(fnd_file.log, l_error_code); WHEN TOO_MANY_ROWS THEN l_error_code := 'TOO MANY ROWS To Find value For Segment6'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment6',cur_xxph_supplier_sites_rec.liability_account_segment6,'VALIDATION', l_error_code,NULL); fnd_file.put_line(fnd_file.log, l_error_code);

WHEN OTHERS THEN l_error_code := 'Unknown error in finding value For Segment6' ||SQLERRM;

xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id,cur_xxph_supplier_sites_rec.component_name, 'Liability_account_segment6',cur_xxph_supplier_sites_rec.liability_account_segment6,'VALIDATION', l_error_code,NULL); fnd_file.put_line(fnd_file.log, l_error_code);

END; /***********************Validating Liability Segments******************************************/

BEGIN l_liability_account_id := 0;

l_liability_account_id := xx_create_get_gl_ccid_fnc(TRIM(cur_xxph_supplier_sites_rec.liability_account_segment1) || '-' || TRIM(cur_xxph_supplier_sites_rec.liability_account_segment2) || '-' || TRIM(cur_xxph_supplier_sites_rec.liability_account_segment3) || '-' || TRIM(cur_xxph_supplier_sites_rec.liability_account_segment4) || '-' || TRIM(cur_xxph_supplier_sites_rec.liability_account_segment5) || '-' || TRIM(cur_xxph_supplier_sites_rec.liability_account_segment6));

UPDATE xx_ap_supplier_sites_stg SET liability_account_id = l_liability_account_id WHERE rowid = cur_xxph_supplier_sites_rec.rowid; COMMIT;

EXCEPTION

WHEN NO_DATA_FOUND THEN fnd_file.PUT_LINE(fnd_file.LOG,'Not a Valid Liability Code Combination Account '); l_error_code := 'Not a Valid Liability Code Combination Account '; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'LIABILITY_CODE_COMBINATION_ID', l_liability_account_id, 'VALIDATION', l_error_code, NULL);

WHEN TOO_MANY_ROWS THEN fnd_file.PUT_LINE(fnd_file.LOG, 'Too Many Rows While Validating Liability Code Combination id'); l_error_code := 'More than one row of Liability Code Combination id'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'LIABILITY_CODE_COMBINATION_ID', l_liability_account_id, 'VALIDATION', l_error_code, NULL);

WHEN OTHERS THEN fnd_file.PUT_LINE(fnd_file.LOG, 'Other errors While Validating Liability Code Combination id');

xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); l_error_code := 'Other errors While Validating Liability Code Combination id' || sqlerrm; xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'LIABILITY_CODE_COMBINATION_ID', l_liability_account_id, 'VALIDATION', l_error_code, NULL);

END;

/***************************Validating Term Date Basis************************************/

BEGIN

l_term_date_basis := 0; SELECT DISTINCT lookup_code INTO l_term_date_basis FROM fnd_lookup_values WHERE lookup_type = 'TERMS DATE BASIS' AND enabled_flag = 'Y' AND(UPPER(meaning) = TRIM(UPPER(cur_xxph_supplier_sites_rec.terms_date_basis)) OR UPPER(description) = TRIM(UPPER(cur_xxph_supplier_sites_rec.terms_date_basis)) OR UPPER(lookup_code) = TRIM(UPPER(cur_xxph_supplier_sites_rec.terms_date_basis)));

UPDATE xx_ap_supplier_sites_stg SET terms_date_basis = l_term_date_basis WHERE rowid = cur_xxph_supplier_sites_rec.rowid;

EXCEPTION WHEN NO_DATA_FOUND THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Not a Valid Terms Date Basis',1,40),'') ,40,' '));

l_error_code := 'Not a Valid Terms Date Basis'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'TERMS_DATE_BASIS', cur_xxph_supplier_sites_rec.terms_date_basis, 'VALIDATION', l_error_code, NULL);

WHEN TOO_MANY_ROWS THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Too Many Rows found While Validating Terms Date Basis',1,40),'') ,40,' ')); l_error_code := 'Too Many Rows found While Validating Terms Date Basis';

xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name,

'TERMS_DATE_BASIS', cur_xxph_supplier_sites_rec.terms_date_basis, 'VALIDATION', l_error_code, NULL);

WHEN OTHERS THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Other errors While Validating Terms Date Basis',1,40),'') ,40,' ')); xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code);

l_error_code := 'Other errors While Validating Terms Date Basis' || sqlerrm; xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'TERMS_DATE_BASIS', cur_xxph_supplier_sites_rec.terms_date_basis, 'VALIDATION', l_error_code, NULL);

END;

/**********************************Validating Pay Date Basis*****************************/

BEGIN

l_pay_date_basis := 0; SELECT DISTINCT UPPER(lookup_code) INTO l_pay_date_basis FROM fnd_lookup_values WHERE lookup_type = 'PAY DATE BASIS' AND enabled_flag = 'Y' AND UPPER(meaning) = TRIM(UPPER(cur_xxph_supplier_sites_rec.pay_date_basis)); -- Updating the staging table with Pay Date Basis

UPDATE xx_ap_supplier_sites_stg SET pay_date_basis = l_pay_date_basis WHERE rowid = cur_xxph_supplier_sites_rec.rowid;

EXCEPTION WHEN NO_DATA_FOUND THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Not a Valid Pay Date Basis',1,40),'') ,40,' '));

l_error_code := 'Not a Valid Pay Date Basis'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'PAY_DATE_BASIS', cur_xxph_supplier_sites_rec.pay_date_basis, 'VALIDATION', l_error_code, NULL);

WHEN TOO_MANY_ROWS THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Too Many Rows found While Validating Pay Date Basis',1,40),'') ,40,' '));

l_error_code := 'Too Many Rows found While Validating Pay Date Basis'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'PAY_DATE_BASIS', cur_xxph_supplier_sites_rec.pay_date_basis, 'VALIDATION', l_error_code, NULL);

WHEN OTHERS THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Other errors While Validating Pay Date Basis',1,40),'') ,40,' ')); xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); l_error_code := 'Other errors While Validating Pay Date Basis' || sqlerrm;

xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'PAY_DATE_BASIS', cur_xxph_supplier_sites_rec.pay_date_basis, 'VALIDATION', l_error_code, NULL);

END;

/****************************Validating Invoice Currency Code*******************************/

BEGIN l_invoice_currency_code := 0; SELECT currency_code INTO l_invoice_currency_code FROM fnd_currencies WHERE currency_code = TRIM(cur_xxph_supplier_sites_rec.invoice_currency_code) AND enabled_flag = 'Y' AND NVL(start_date_active, sysdate) <= sysdate AND NVL(end_date_active, sysdate) >= sysdate;

EXCEPTION

WHEN NO_DATA_FOUND THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Not a Valid Invoice currnecy Code',1,40),'') ,40,' ')); l_error_code := 'Not a Valid Invoice currnecy Code';

xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'INVOICE CURRENCY CODE', cur_xxph_supplier_sites_rec.invoice_currency_code, 'VALIDATION', l_error_code, NULL);

WHEN TOO_MANY_ROWS THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Too Many Rows While Validating Invoice currnecy Code',1,40),'') ,40,' '));

l_error_code := 'Too Many Rows While Validating Invoice currnecy Code';

xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'INVOICE CURRENCY CODE', cur_xxph_supplier_sites_rec.invoice_currency_code, 'VALIDATION', l_error_code, NULL);

WHEN OTHERS THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Other errors While Validating Invoice currnecy Code',1,40),'') ,40,' ')); xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code);

l_error_code := 'Other errors While Validating Invoice currnecy Code' || sqlerrm; xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'INVOICE CURRENCY CODE', cur_xxph_supplier_sites_rec.invoice_currency_code, 'VALIDATION', l_error_code, NULL); END;

/************************Validating Payment Currency Code**********************************/

BEGIN l_payment_currency_code := 0; SELECT currency_code INTO l_payment_currency_code FROM fnd_currencies WHERE currency_code = TRIM(cur_xxph_supplier_sites_rec.payment_currency_code) AND enabled_flag = 'Y' AND NVL(start_date_active, sysdate) <= sysdate AND NVL(end_date_active, sysdate) >= sysdate;

EXCEPTION

WHEN NO_DATA_FOUND THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Not a Valid Invoice currnecy Code',1,40),'') ,40,' ')); l_error_code := 'Not a Valid Invoice currnecy Code'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'PAYMENT CURRENCY CODE', cur_xxph_supplier_sites_rec.payment_currency_code, 'VALIDATION', l_error_code, NULL);

WHEN TOO_MANY_ROWS THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Too Many Rows While Validating Invoice currnecy Code',1,40),'') ,40,' '));

l_error_code := 'Too Many Rows While Validating Invoice currnecy Code'; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'PAYMENT CURRENCY CODE', cur_xxph_supplier_sites_rec.payment_currency_code, 'VALIDATION', l_error_code, NULL);

WHEN OTHERS THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Other errors While Validating Invoice currnecy Code',1,40),'') ,40,' ')); xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); l_error_code := 'Other errors While Validating Invoice currnecy Code' || sqlerrm; xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'PAYMENT CURRENCY CODE', cur_xxph_supplier_sites_rec.payment_currency_code, 'VALIDATION', l_error_code, NULL); END;

/************************Validating Operating Unit**********************************/

BEGIN l_org_id := 0;

SELECT oracle_org_id INTO l_org_id FROM xxph_ou_mapping WHERE sap_ou=TRIM(cur_xxph_supplier_sites_rec.operating_unit);

UPDATE xx_ap_supplier_sites_stg SET org_id = l_org_id WHERE rowid = cur_xxph_supplier_sites_rec.rowid;

EXCEPTION

WHEN NO_DATA_FOUND THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Not a Valid Operating Unit',1,40),'') ,40,' ')); l_error_code := 'Not a Valid Operating Unit'; xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'OPERATING_UNIT', cur_xxph_supplier_sites_rec.operating_unit, 'VALIDATION', l_error_code, NULL); xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code);

WHEN TOO_MANY_ROWS THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Too Many Rows when Validating Operating Unit',1,40),'') ,40,' ')); l_error_code := 'TOO MANY ROWS when validating Operating Unit';

xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'OPERATING_UNIT', cur_xxph_supplier_sites_rec.operating_unit, 'VALIDATION', l_error_code, NULL); xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code);

WHEN OTHERS THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('OTHER ERRORS when validating Operating Unit',1,40),'') ,40,' ')); l_error_code := 'OTHER ERRORS when validating Operating Unit' || sqlerrm; xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'OPERATING_UNIT', cur_xxph_supplier_sites_rec.operating_unit, 'VALIDATION', l_error_code, NULL); xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code);

END;

/************************Validating Terms Name**********************************/ ------vell sir this is error ......even oracle does not validate this ------you are not doing validation....rather you are retriving the value. only.. ------ this is totally wrong approach ------ take a case ....if corresponding record does not have value this should not return.... BEGIN l_terms_id := 0; l_term_name := 0; SELECT term_id, name INTO l_terms_id, l_term_name FROM ap_terms WHERE UPPER(name) = TRIM(UPPER(cur_xxph_supplier_sites_rec.term_name)); -- Updating the staging table with terms_id

UPDATE xx_ap_supplier_sites_stg SET terms_id = l_terms_id, term_name = l_term_name WHERE rowid = cur_xxph_supplier_sites_rec.rowid;

EXCEPTION

WHEN NO_DATA_FOUND THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Not a Valid Terms Name',1,100),'') ,40,' ')); l_error_code := 'Not a Valid Terms Name '; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code);

xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'TERM NAME', cur_xxph_supplier_sites_rec.term_name, 'VALIDATION', l_error_code, NULL);

WHEN TOO_MANY_ROWS THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Too Many Rows While Validating Terms Name',1,100),'') ,40,' ')); l_error_code := 'Too Many Rows While Validating Terms Name '; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'TERM NAME', cur_xxph_supplier_sites_rec.term_name, 'VALIDATION', l_error_code, NULL);

WHEN OTHERS THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Other errors While Validating Terms Name',1,100),'') ,40,' '));

l_error_code := 'Other errors While Validating Terms Id ' || sqlerrm; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'TERM NAME', cur_xxph_supplier_sites_rec.term_name, 'VALIDATION', l_error_code, NULL); END;

/*************************Validating Country********************/

BEGIN SELECT DISTINCT territory_code INTO l_country FROM fnd_territories WHERE UPPER(nls_territory) = TRIM(UPPER(cur_xxph_supplier_sites_rec.country)) OR UPPER(territory_code) = TRIM(UPPER(cur_xxph_supplier_sites_rec.country)) OR UPPER(iso_territory_code) = TRIM(UPPER(cur_xxph_supplier_sites_rec.country)); -- Updating the Staging table with Country Code

UPDATE xx_ap_supplier_sites_stg SET country = l_country WHERE rowid = cur_xxph_supplier_sites_rec.rowid;

EXCEPTION

WHEN NO_DATA_FOUND THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Not a Valid Validating Country',1,40),'') ,40,' '));

l_error_code := 'Not a Valid Validating Country ';

xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'COUNTRY', cur_xxph_supplier_sites_rec.country, 'VALIDATION', l_error_code, NULL);

WHEN TOO_MANY_ROWS THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Too Many Rows found While Validating Country',1,40),'') ,40,' '));

l_error_code := 'Too Many Rows found While Validating Country '; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'COUNTRY', cur_xxph_supplier_sites_rec.country, 'VALIDATION', l_error_code, NULL);

WHEN OTHERS THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Other Errors when Validating Country ',1,40),'') ,40,' ')); l_error_code := 'Other Errors when Validating Country ';

xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'COUNTRY', cur_xxph_supplier_sites_rec.country, 'VALIDATION', l_error_code, NULL);

END;

/****************************Pay Group Lookup Code********************************************/ IF TRIM(cur_xxph_supplier_sites_rec.pay_group_lookup_code) IS NOT NULL THEN BEGIN SELECT DISTINCT UPPER(lookup_code) INTO l_pay_group FROM FND_LOOKUP_VALUES WHERE lookup_type = 'PAY GROUP' AND UPPER(meaning) = trim(UPPER(cur_xxph_supplier_sites_rec.pay_group_lookup_code));

UPDATE xx_ap_supplier_sites_stg SET pay_group_lookup_code =l_pay_group WHERE rowid = cur_xxph_supplier_sites_rec.rowid; COMMIT;

EXCEPTION

WHEN NO_DATA_FOUND THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Not a Valid Pay Group Lookup Code',1,1000),'') ,40,' ')); l_error_code := 'Not a Valid Pay Group Lookup Code '; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'PAY_GROUP_LOOKUP_CODE', cur_xxph_supplier_sites_rec.pay_group_lookup_code, 'VALIDATION', l_error_code, NULL);

WHEN TOO_MANY_ROWS THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Too Many Rows While Validating Pay Group Lookup Code',1,100),'') ,40,' ')); l_error_code := 'Too Many Rows While Validating Pay Group Lookup Code '; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'PAY_GROUP_LOOKUP_CODE', cur_xxph_supplier_sites_rec.pay_group_lookup_code, 'VALIDATION', l_error_code, NULL);

WHEN OTHERS THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Other Errors While Validating Pay Group Lookup Code ',1,100),'') ,40,' ')); l_error_code := 'Other Errors found While Validating Pay Group Lookup Code '; xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'PAY_GROUP_LOOKUP_CODE', cur_xxph_supplier_sites_rec.pay_group_lookup_code, 'VALIDATION', l_error_code, NULL);

END; END IF; /****************************Payment Type Lookup Code********************************************/

BEGIN SELECT DISTINCT UPPER(lookup_code) INTO l_payment_code FROM fnd_lookup_values WHERE lookup_type like 'PAYMENT_METHOD' AND UPPER(meaning) = trim(UPPER(cur_xxph_supplier_sites_rec.payment_method_lookup_code));

UPDATE xx_ap_supplier_sites_stg SET payment_method_lookup_code = l_payment_code WHERE rowid = cur_xxph_supplier_sites_rec.rowid;

EXCEPTION

WHEN NO_DATA_FOUND THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Not a Valid Payment Method Lookup Code ',1,100),'') ,40,' ')); l_error_code := 'Not a Valid Payment Method Lookup Code ';

xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'PAYMENT_METHOD_LOOKUP_CODE', cur_xxph_supplier_sites_rec.payment_method_lookup_code, 'VALIDATION', l_error_code, NULL);

WHEN TOO_MANY_ROWS THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Too MAny Rows While Validating Payment Method Lookup Code ',1,100),'') ,40,' ')); l_error_code := 'Too MAny Rows While Validating Payment Method Lookup Code ';

xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'PAYMENT_METHOD_LOOKUP_CODE', cur_xxph_supplier_sites_rec.payment_method_lookup_code, 'VALIDATION', l_error_code, NULL);

WHEN OTHERS THEN fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Other Error While Validating Payment Method Lookup Code ',1,100),'') ,40,' ')); l_error_code := 'Other Error While Validating Payment Method Lookup Code ';

xx_ph_si_upd_fail_prc(cur_xxph_supplier_sites_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_supplier_sites_rec.supplier_site_transaction_id, cur_xxph_supplier_sites_rec.component_name, 'PAYMENT_METHOD_LOOKUP_CODE', cur_xxph_supplier_sites_rec.payment_method_lookup_code, 'VALIDATION', l_error_code, NULL);

END; /************************Updating the Processing Status of Supplier Sites Staging Table*****************************/ fnd_file.PUT_LINE(fnd_file.LOG, 'l_error_code in sites cursor' || l_error_code);

IF l_error_code IS NOT NULL THEN

UPDATE xx_ap_supplier_sites_stg SET processing_status = 'E' --'E' for Eroor records WHERE rowid = cur_xxph_supplier_sites_rec.rowid;

UPDATE xx_ap_suppliers_stg SET processing_status = 'E' WHERE rowid = cur_xxph_suppliers_rec.rowid; ELSE

UPDATE xx_ap_supplier_sites_stg SET processing_status = 'V' -- 'V' for valid records. WHERE rowid = cur_xxph_supplier_sites_rec.rowid; END IF;

/************************Updating the Processing Status of Supplier Staging Table*****************************/ fnd_file.PUT_LINE(fnd_file.LOG, 'l_supp_code' || l_supp_code);

IF l_supp_code IS NOT NULL THEN

UPDATE xx_ap_suppliers_stg SET processing_status = 'E' --'E' for Error records WHERE rowid = cur_xxph_suppliers_rec.rowid;

ELSE

UPDATE xx_ap_suppliers_stg SET processing_status = 'V' -- 'V' for valid records. WHERE rowid = cur_xxph_suppliers_rec.rowid AND processing_status <> 'E';

END IF; END LOOP; END LOOP;

COMMIT;

END xx_ph_ap_supp_valid_dat_prc;

/*******************************Procedure for Inserting records into Ineterface Tables***************************************************/

PROCEDURE xx_ph_ap_supp_insert_dat_prc IS

l_error_code VARCHAR2(2000) := NULL;

/**************************Cursor for Suppliers Staging Table********************************/ CURSOR cur_insert_vendors IS SELECT aa.*, aa.rowid FROM xx_ap_suppliers_stg aa WHERE aa.processing_status = 'V';

/**************************Cursor for Suppliers Sites Staging Table********************************/ CURSOR cur_insert_ven_sites(l_vendor_name1 IN VARCHAR2,l_vendor_alternate_name1 IN VARCHAR2) IS SELECT bb.*, bb.rowid FROM xx_ap_supplier_sites_stg bb WHERE bb.vendor_name = l_vendor_name1 AND bb.vendor_alternate_name=l_vendor_alternate_name1 AND bb.processing_status = 'V';

/****************Inserting into Supplier Interface Tables *****************************/

BEGIN

FOR cur_xxph_ins_sup_rec IN cur_insert_vendors LOOP

BEGIN

INSERT INTO ap_suppliers_int(vendor_interface_id, last_update_date, last_updated_by, vendor_name, vendor_name_alt, customer_num , creation_date, created_by, vendor_type_lookup_code) VALUES(ap_suppliers_int_s.nextval, cur_xxph_ins_sup_rec.last_updated_date, cur_xxph_ins_sup_rec.last_updated_by, cur_xxph_ins_sup_rec.vendor_name, cur_xxph_ins_sup_rec.vendor_alternate_name, cur_xxph_ins_sup_rec.customer_number,cur_xxph_ins_sup_rec.creation_date, cur_xxph_ins_sup_rec.created_by, cur_xxph_ins_sup_rec.vendor_type_lookup_code);

EXCEPTION WHEN OTHERS THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Errors while Inserting into Supplier Interface Tables ',1,60),'') ,60,' ')); l_error_code := 'Errors While Inserting into Supplier Interface Tables' || sqlerrm;

xx_ph_su_upd_fail_prc(cur_xxph_ins_sup_rec.rowid, l_error_code); xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_ins_sup_rec.supplier_transaction_id, cur_xxph_ins_sup_rec.component_name, 'FAILED WHILE INSERTING INTO SUPPLIERS TABLE', cur_xxph_ins_sup_rec.vendor_name, 'INSERTING', l_error_code, NULL);

END;

FOR cur_xxph_ins_sup_sites_rec IN cur_insert_ven_sites((cur_xxph_ins_sup_rec.vendor_name),(cur_xxph_ins_sup_rec.vendor_alternate_name)) LOOP

BEGIN

INSERT

INTO ap_supplier_sites_int(vendor_interface_id, accts_pay_code_combination_id, last_update_date, last_updated_by, creation_date, created_by, vendor_site_code, address_line1, address_line2, address_line3, city, state, zip, province, country, ship_to_location_code, bill_to_location_code, org_id, payment_method_lookup_code, terms_date_basis, pay_group_lookup_code, payment_priority, terms_id, terms_name, pay_date_basis_lookup_code, invoice_currency_code, payment_currency_code, match_option,rfq_only_site_flag ,purchasing_site_flag ,pay_site_flag ,exclusive_payment_flag, attribute_category, attribute1, attribute2, attribute8, attribute9) VALUES(ap_suppliers_int_s.currval,cur_xxph_ins_sup_sites_rec.liability_account_id, cur_xxph_ins_sup_sites_rec.last_updated_date, cur_xxph_ins_sup_sites_rec.last_updated_by, cur_xxph_ins_sup_sites_rec.creation_date, cur_xxph_ins_sup_sites_rec.created_by, cur_xxph_ins_sup_sites_rec.vendor_site_code, cur_xxph_ins_sup_sites_rec.address_line1, cur_xxph_ins_sup_sites_rec.address_line2, cur_xxph_ins_sup_sites_rec.address_line3, cur_xxph_ins_sup_sites_rec.city, cur_xxph_ins_sup_sites_rec.state, cur_xxph_ins_sup_sites_rec.zip, cur_xxph_ins_sup_sites_rec.province, cur_xxph_ins_sup_sites_rec.country, cur_xxph_ins_sup_sites_rec.ship_to_location_code, cur_xxph_ins_sup_sites_rec.bill_to_location_code, cur_xxph_ins_sup_sites_rec.org_id, cur_xxph_ins_sup_sites_rec.payment_method_lookup_code, cur_xxph_ins_sup_sites_rec.terms_date_basis, cur_xxph_ins_sup_sites_rec.pay_group_lookup_code, cur_xxph_ins_sup_sites_rec.payment_priority, cur_xxph_ins_sup_sites_rec.terms_id, cur_xxph_ins_sup_sites_rec.term_name, cur_xxph_ins_sup_sites_rec.pay_date_basis, cur_xxph_ins_sup_sites_rec.invoice_currency_code, cur_xxph_ins_sup_sites_rec.payment_currency_code, cur_xxph_ins_sup_sites_rec.match_option, cur_xxph_ins_sup_sites_rec.rfq_only_site_flag , cur_xxph_ins_sup_sites_rec.purchasing_site_flag ,cur_xxph_ins_sup_sites_rec.pay_site_flag,cur_xxph_ins_sup_sites_rec.pay_alone ,'Vendor Site Info', cur_xxph_ins_sup_sites_rec.delivery_method, cur_xxph_ins_sup_sites_rec.instruction_for_charges, cur_xxph_ins_sup_sites_rec.previous_master_record, cur_xxph_ins_sup_sites_rec.alternate_payee);

EXCEPTION WHEN OTHERS THEN

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Errors while Inserting into Supplier Sites Interface Tables ',1,60),'') ,60,' ')); l_error_code := 'Errors While Inserting into Supplier Sites Interface Tables' || sqlerrm; xx_ph_si_upd_fail_prc(cur_xxph_ins_sup_sites_rec.rowid, l_error_code);

xxph_common_dmg_pkg.insert_error_message_prc(cur_xxph_ins_sup_sites_rec.vendor_site_code, cur_xxph_ins_sup_sites_rec.component_name, 'FAILED WHILE INERTING INTO SUPPLIER SITES TABLE',

cur_xxph_ins_sup_sites_rec.vendor_site_code, 'ORACLE EROOR', l_error_code, NULL);

END; END LOOP; END LOOP; COMMIT; END xx_ph_ap_supp_insert_dat_prc;

/*******************************Procedure for Output Error Table***********************************/

PROCEDURE xx_output_report_prc(p_request_id IN NUMBER) IS

--Cursor to fetch all the valid records processed through this request CURSOR cur_valid_suppliers(p_conc_req_id NUMBER) IS SELECT aps.*, aps.rowid FROM xx_ap_suppliers_stg aps WHERE aps.processing_status = 'V' AND aps.conc_req_id = p_conc_req_id;

CURSOR cur_valid_supp_sites(p_conc_req_id NUMBER) IS SELECT apss.*, apss.rowid FROM xx_ap_supplier_sites_stg apss WHERE apss.processing_status = 'V' AND apss.conc_req_id = p_conc_req_id;

--cursor to fetch all the error records obtained through this request CURSOR cur_error_supp_records(p_conc_req_id NUMBER) IS SELECT xxe.error_column, xxe.error_value, xxe.error_type, xxe.error_messg, aps.vendor_name, aps.supplier_transaction_id FROM xx_ap_suppliers_stg aps, xx_ph_all_errors xxe WHERE aps.supplier_transaction_id = xxe.transaction_id AND aps.component_name = xxe.component_name AND xxe.conc_req_id = p_conc_req_id;

CURSOR cur_error_site_records(p_conc_req_id NUMBER) IS SELECT xxe.error_column, xxe.error_value, xxe.error_type, xxe.error_messg, apss.vendor_name, apss.vendor_site_code, apss.supplier_site_transaction_id FROM xx_ap_supplier_sites_stg apss, xx_ph_all_errors xxe WHERE apss.supplier_site_transaction_id = xxe.transaction_id AND apss.component_name = xxe.component_name AND xxe.conc_req_id = p_conc_req_id;

l_count NUMBER; l_count_records NUMBER; l_success_records NUMBER; l_error_records NUMBER; l_count_site_records NUMBER; l_success_site_records NUMBER; l_error_site_records NUMBER;

BEGIN l_count := NULL; fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('-----Start Output Report-----',1,100),'') ,80,' ')); fnd_file.put_line(fnd_file.OUTPUT,RPAD(NVL(SUBSTR('-----Start Output Report-----',1,100),'') ,80,' '));

FOR valid_supplier_rec IN cur_valid_suppliers(p_request_id) LOOP

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Vendor_name' || valid_supplier_rec.vendor_name,1,100),'') ,80,' ')); SELECT COUNT(1) INTO l_count FROM po_vendors WHERE vendor_name = valid_supplier_rec.vendor_name; fnd_file.PUT_LINE(fnd_file.LOG, 'Suppliers count' || l_count);

IF(l_count > 0) THEN

/* Update the staging table with processed status for records that are present in standard table */

UPDATE xx_ap_suppliers_stg SET processing_status = 'P' WHERE rowid = valid_supplier_rec.rowid;

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Updated the Processing status of supplier staging table as P',1,100),'') ,80,' '));

END IF;

IF(l_count = 0) THEN

/* Update the staging table with error status for records that are not present in standard table */

UPDATE xx_ap_suppliers_stg SET processing_status = 'E' WHERE rowid = valid_supplier_rec.rowid;

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Updated the Processing status of supplier staging table as E',1,100),'') ,80,' '));

-- fnd_file.put_line(fnd_file.OUTPUT,RPAD(NVL(SUBSTR('Updated the Processing status of supplier staging table as E',1,100),'') ,60,' ')); END IF;

END LOOP; COMMIT; fnd_file.PUT_LINE(fnd_file.OUTPUT,RPAD(NVL(SUBSTR('Supplier Transaction Id',1,100),'') ,80,' ')||RPAD(NVL(SUBSTR('Vendor Name',1,100),'') ,80,' ') ||RPAD(NVL(SUBSTR('Error_Value',1,100),'') ,80,' ') ||RPAD(NVL(SUBSTR('Error_Record_Type' ,1,100),'') ,80,' ') ||RPAD(NVL(SUBSTR('Error_Message',1,100),'') ,80,' '));

FOR error_supp_records_rec IN cur_error_supp_records(p_request_id) LOOP

fnd_file.put_line(fnd_file.OUTPUT,RPAD(NVL(SUBSTR(error_supp_records_rec.supplier_transaction_id,1,100),'') ,80,' ')|| RPAD(NVL(SUBSTR(error_supp_records_rec.vendor_name,1,100),'') ,80,' ')||RPAD(NVL(SUBSTR(error_supp_records_rec.error_column,1,100),'') ,80,' ')||RPAD(NVL(SUBSTR(error_supp_records_rec.error_value,1,100),'') ,80,' ')||RPAD(NVL(SUBSTR(error_supp_records_rec.error_type,1,100),'') ,80,' ')||RPAD(NVL(SUBSTR(error_supp_records_rec.error_messg,1,100),'') ,80,' '));

END LOOP;

FOR valid_supp_sites_rec IN cur_valid_supp_sites(p_request_id) LOOP

--To check whether the record exists in standard Table l_count := NULL;

SELECT COUNT(1) INTO l_count FROM po_vendor_sites_all a, po_vendors b WHERE a.vendor_site_code = valid_supp_sites_rec.vendor_site_code AND a.vendor_id = b.vendor_id AND b.vendor_name = valid_supp_sites_rec.vendor_name;

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Supplier sites count',1,100),'') ,80,' '));

--

IF(l_count = 0) THEN

/* Update the staging table with error status for records that are not present in standard table */

UPDATE xx_ap_supplier_sites_stg SET processing_status = 'E' WHERE rowid = valid_supp_sites_rec.rowid;

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Updated the Processing status of supplier sites staging table as P',1,100),'') ,80,' '));

END IF;

IF(l_count > 0) THEN

/* Update the staging table with processed status for records that are present in standard table */

UPDATE xx_ap_supplier_sites_stg SET processing_status = 'P' WHERE rowid = valid_supp_sites_rec.rowid;

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('Updated the Processing status of supplier sites staging table as P',1,100),'') ,80,' '));

END IF;

END LOOP;

COMMIT;

fnd_file.put_line(fnd_file.OUTPUT,RPAD(NVL(SUBSTR('Supplier Site Transaction Id',1,100),'') ,80,' ')||RPAD(NVL(SUBSTR('Vendor Name',1,100),'') ,80,' ')||RPAD(NVL(SUBSTR('Vendor Site Code',1,100),'') ,80,' ')||RPAD(NVL(SUBSTR('Error_Column',1,100),'') ,80,' ')||RPAD(NVL(SUBSTR('Error_Value' ,1,100),'') ,80,' ')||RPAD(NVL(SUBSTR('Error_Record_Type',1,100),'') ,80,' ')||RPAD(NVL(SUBSTR('Error_Message ',1,100),'') ,80,' ')); FOR error_site_records_rec IN cur_error_site_records(p_request_id) LOOP

fnd_file.put_line(fnd_file.OUTPUT,RPAD(NVL(SUBSTR(error_site_records_rec.supplier_site_transaction_id ,1,100),'') ,80,' ')||RPAD(NVL(SUBSTR(error_site_records_rec.vendor_name,1,100),'') ,80,' ')||RPAD(NVL(SUBSTR(error_site_records_rec.vendor_site_code,1,100),'') ,80,' ')||RPAD(NVL(SUBSTR(error_site_records_rec.error_column ,1,100),'') ,80,' ')||RPAD(NVL(SUBSTR( error_site_records_rec.error_value,1,100),'') ,80,' ')||RPAD(NVL(SUBSTR(error_site_records_rec.error_type,1,100),'') ,80,' ')||RPAD(NVL(SUBSTR(error_site_records_rec.error_messg,1,100),'') ,80,' ')); END LOOP;

/*********************************************Count For Supplier Table*******************************/ SELECT COUNT(*) INTO l_count_records FROM xx_ap_suppliers_stg aps WHERE aps.conc_req_id = p_request_id;

fnd_file.put_line(fnd_file.OUTPUT,'Total Records Selected Into Suppliers Table :'|| l_count_records); SELECT COUNT(*) INTO l_success_records FROM xx_ap_suppliers_stg aps WHERE aps.conc_req_id = p_request_id AND processing_status = 'P';

fnd_file.put_line(fnd_file.OUTPUT,'Total Records Processed Sucessfully Into Suppliers Table :'|| l_success_records); SELECT COUNT(*) INTO l_error_records FROM xx_ap_suppliers_stg aps WHERE aps.conc_req_id = p_request_id AND processing_status = 'E';

fnd_file.put_line(fnd_file.OUTPUT,'Total Records Processed with Error :' || l_error_records );

/***************************************Count For Supplier Sites Table************************/ SELECT COUNT(1) INTO l_count_site_records FROM xx_ap_supplier_sites_stg apss WHERE apss.conc_req_id = p_request_id;

fnd_file.put_line(fnd_file.OUTPUT,'Total Records Selected Into Supplier Sites Table :' || l_count_site_records); SELECT COUNT(1) INTO l_success_site_records FROM xx_ap_supplier_sites_stg apss WHERE apss.conc_req_id = p_request_id AND processing_status = 'P';

fnd_file.put_line(fnd_file.OUTPUT,'Total Records Processed Sucessfully Into Supplier Sites Table :' || l_success_site_records);

SELECT COUNT(1) INTO l_error_site_records FROM xx_ap_supplier_sites_stg apss WHERE apss.conc_req_id = p_request_id AND processing_status = 'E';

fnd_file.put_line(fnd_file.OUTPUT,'Total Records Processed with Error :' || l_error_site_records);

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('-----End Of Output Report-----',1,100),'') ,80,' '));

fnd_file.put_line(fnd_file.OUTPUT,RPAD(NVL(SUBSTR('-----End Of Output Report-----',1,100),'') ,80,' '));

END xx_output_report_prc; --------Valid error report--------------------------------------------------------------------------------- PROCEDURE xx_output_report_valid_prc(p_request_id IN NUMBER) IS

--cursor to fetch all the error records obtained through this request CURSOR cur_error_supp_records(p_conc_req_id NUMBER) IS SELECT xxe.error_column, xxe.error_value, xxe.error_type, xxe.error_messg, aps.vendor_name, aps.supplier_transaction_id FROM xx_ap_suppliers_stg aps, xx_ph_all_errors xxe WHERE aps.supplier_transaction_id = xxe.transaction_id AND aps.component_name = xxe.component_name AND xxe.conc_req_id = p_conc_req_id;

CURSOR cur_error_site_records(p_conc_req_id NUMBER) IS SELECT xxe.error_column, xxe.error_value, xxe.error_type, xxe.error_messg, apss.vendor_name, apss.vendor_site_code, apss.supplier_site_transaction_id FROM xx_ap_supplier_sites_stg apss, xx_ph_all_errors xxe WHERE apss.supplier_site_transaction_id = xxe.transaction_id AND apss.component_name = xxe.component_name AND xxe.conc_req_id = p_conc_req_id;

l_count NUMBER; l_count_records NUMBER; l_success_records NUMBER; l_error_records NUMBER; l_count_site_records NUMBER; l_success_site_records NUMBER; l_error_site_records NUMBER;

BEGIN l_count := NULL;

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('-----Start Output Report-----',1,100),'') ,60,' '));

fnd_file.put_line(fnd_file.OUTPUT,RPAD(NVL(SUBSTR('-----Start Output Report-----',1,100),'') ,60,' '));

fnd_file.put_line(fnd_file.OUTPUT,RPAD(NVL(SUBSTR(' Supplier Transaction Id' ,1,100),' ') ,80,' ')||RPAD(NVL(SUBSTR('Vendor Name',1,100),' ') ,80,' ')||RPAD(NVL(SUBSTR('Error Column',1,100),' ') ,80,' ')||RPAD(NVL(SUBSTR('Error Record Type',1,100),' ') ,80,' ')||RPAD(NVL(SUBSTR('Error Type',1,100),'') ,80,' ')||RPAD(NVL(SUBSTR('Error Message',1,250),' ') ,80,' '));

FOR error_supp_records_rec IN cur_error_supp_records(p_request_id)

LOOP

fnd_file.put_line(fnd_file.OUTPUT,RPAD(NVL(SUBSTR( error_supp_records_rec.supplier_transaction_id ,1,100),' ') ,80,' ')||RPAD(NVL(SUBSTR(error_supp_records_rec.vendor_name,1,100),' ') ,80,' ')||RPAD(NVL(SUBSTR( error_supp_records_rec.error_column ,1,100),' ') ,80,' ')||RPAD(NVL(SUBSTR(error_supp_records_rec.error_value,1,100),' ') ,80,' ')||RPAD(NVL(SUBSTR(error_supp_records_rec.error_type ,1,100),'') ,80,' ')||RPAD(NVL(SUBSTR(error_supp_records_rec.error_messg,1,250),' ') ,80,' ')); END LOOP;

fnd_file.put_line(fnd_file.OUTPUT,RPAD(NVL(SUBSTR('Supplier Site Transaction Id ',1,100),'') ,80,' ')||RPAD(NVL(SUBSTR('Vendor Name',1,100),'') ,80,' ')||RPAD(NVL(SUBSTR('Vendor Site Name',1,100),'') ,80,' ')||RPAD(NVL(SUBSTR( 'Error_Column' ,1,100),'') ,80,' ')||RPAD(NVL(SUBSTR('Error_Value',1,100),'') ,80,' ')||RPAD(NVL(SUBSTR( 'Error_Record_Type' ,1,100),'') ,80,' ')||RPAD(NVL(SUBSTR('Error_Message',1,100),'') ,80,' ')); FOR error_site_records_rec IN cur_error_site_records(p_request_id) LOOP

fnd_file.put_line(fnd_file.OUTPUT,RPAD(NVL(SUBSTR(error_site_records_rec.supplier_site_transaction_id,1,100),'') ,80,' ')||RPAD(NVL(SUBSTR(error_site_records_rec.vendor_name,1,100),'') ,80,' ')||RPAD(NVL(SUBSTR(error_site_records_rec.vendor_site_code,1,100),'') ,80,' ')||RPAD(NVL(SUBSTR( error_site_records_rec.error_column ,1,100),'') ,80,' ')||RPAD(NVL(SUBSTR(error_site_records_rec.error_value,1,100),'') ,80,' ')||RPAD(NVL(SUBSTR(error_site_records_rec.error_type ,1,100),'') ,80,' ')||RPAD(NVL(SUBSTR(error_site_records_rec.error_messg,1,100),'') ,80,' ')); END LOOP;

/*********************************************Count For Supplier and Supplier Sites Table*******************************/

SELECT COUNT(*) INTO l_count_records FROM xx_ap_suppliers_stg aps WHERE aps.conc_req_id = p_request_id;

fnd_file.put_line(fnd_file.OUTPUT,'Total Records Selected Into Suppliers Table :' || l_count_records); SELECT COUNT(*) INTO l_success_records

FROM xx_ap_suppliers_stg aps WHERE aps.conc_req_id = p_request_id AND processing_status = 'V';

fnd_file.put_line(fnd_file.OUTPUT,'Total Records Validated In Suppliers Table :' || l_success_records); SELECT COUNT(*) INTO l_error_records FROM xx_ap_suppliers_stg aps WHERE aps.conc_req_id = p_request_id AND processing_status = 'E';

fnd_file.put_line(fnd_file.OUTPUT,'Total Records Processed with Error :' || l_error_records);

SELECT COUNT(1) INTO l_count_site_records FROM xx_ap_supplier_sites_stg apss WHERE apss.conc_req_id = p_request_id;

fnd_file.put_line(fnd_file.OUTPUT,'Total Records Selected Into Supplier Sites Table :' || l_count_site_records );

SELECT COUNT(1) INTO l_success_site_records FROM xx_ap_supplier_sites_stg apss WHERE apss.conc_req_id = p_request_id AND processing_status = 'V';

fnd_file.put_line(fnd_file.OUTPUT,'Total Records Validated Supplier Sites Table :' || l_success_site_records );

SELECT COUNT(1) INTO l_error_site_records FROM xx_ap_supplier_sites_stg apss WHERE apss.conc_req_id = p_request_id AND processing_status = 'E';

fnd_file.put_line(fnd_file.OUTPUT,'Total Records Processed with Error :' || l_error_site_records );

fnd_file.put_line(fnd_file.LOG,RPAD(NVL(SUBSTR('-----End Of Output Report-----' ,1,100),'') ,80,' '));

fnd_file.put_line(fnd_file.OUTPUT,RPAD(NVL(SUBSTR('-----End Of Output Report-----', 1,100),'') ,80,' '));

END xx_output_report_valid_prc;

/******************************************MAIN PROCEDURE*******************************************/

PROCEDURE xx_ph_ap_suppliers_mains_prc(errbuf OUT VARCHAR2, retcode OUT NUMBER, p_commit IN VARCHAR2, p_import_options IN VARCHAR2, p_batch_size IN NUMBER, p_print_exceptions_only IN VARCHAR2, p_debug_switch IN VARCHAR2, p_trace_switch IN VARCHAR2) IS

l_conc_request_id NUMBER := fnd_global.conc_request_id; l_ln_user_id NUMBER := fnd_global.user_id; l_ln_responsibility_id NUMBER := fnd_global.resp_id; l_ln_application_id NUMBER := fnd_global.resp_appl_id; l_req_id1 NUMBER := 0; l_req_id2 NUMBER := 0; l_interval NUMBER := 15; l_max_wait NUMBER := 3000; x_phase VARCHAR2(240); x_status VARCHAR2(240); x_dev_phase VARCHAR2(240); x_dev_status VARCHAR2(240); x_message VARCHAR2(3000); l_wait_status BOOLEAN;/**********************************Updating the staging tables with Concurrent Request id ************************************/

BEGIN UPDATE xx_ap_suppliers_stg SET conc_req_id = l_conc_request_id WHERE processing_status = 'N'; --COMMIT;

UPDATE xx_ap_supplier_sites_stg SET conc_req_id = l_conc_request_id WHERE processing_status = 'N';

COMMIT;

/**********************************Updating the processing status to V with refernce to Concurrent Request Id*********************************/

IF (p_commit='YES') THEN UPDATE xx_ap_suppliers_stg SET conc_req_id = l_conc_request_id WHERE processing_status = 'V'; COMMIT;

END IF;

IF (p_commit='YES') THEN UPDATE xx_ap_supplier_sites_stg SET conc_req_id = l_conc_request_id WHERE processing_status = 'V';

COMMIT;

END IF;

IF UPPER(p_commit) = 'YES' THEN

/************************************Calling the Validation Procedure**********************************/ xx_ph_ap_supp_valid_dat_prc(l_conc_request_id);

/************************************Calling the Insertion Procedure**********************************/ xx_ph_ap_supp_insert_dat_prc;

/**********************Submitting the Request for SUPPLIER OPEN IMPORT PROGRAM**********************************/ l_req_id1 := fnd_request.submit_request(

application => 'SQLAP',

program => 'APXSUIMP',

argument1 => p_import_options, --'NEW',------Import Options

argument2 => p_batch_size, --'1000',-------Batch Size

argument3 => p_print_exceptions_only, --'N',-------Print Exceptions Only

argument4 => p_debug_switch, -- 'N',------Debug Switch

argument5 => p_trace_switch -- 'N'---------Trace Switch ); COMMIT;

/**********************Submitting the Request for SUPPLIER SITES OPEN IMPORT PROGRAM**********************************/ l_req_id2 := fnd_request.submit_request(application => 'SQLAP',

PROGRAM => 'APXSSIMP',

argument1 => p_import_options, --'NEW',------Import Options

argument2 => p_batch_size, --'1000',-------Batch Size

argument3 => p_print_exceptions_only, --'N',-------Print Exceptions Only

argument4 => p_debug_switch, -- 'N',------Debug Switch

argument5 => p_trace_switch -- 'N'---------Trace Switch ); COMMIT;

fnd_file.put_line(fnd_file.OUTPUT,RPAD(NVL(SUBSTR('l_req_id1 For Suppliers Request' || l_req_id1,1,60),'') ,60,' '));

fnd_file.put_line(fnd_file.OUTPUT,RPAD(NVL(SUBSTR('l_req_id2 For Sites Request' || l_req_id2,1,60),'') ,60,' '));

IF(l_req_id2 = 0) THEN

fnd_file.put_line(fnd_file.OUTPUT,RPAD(NVL(SUBSTR('Failed To submit Post Supplier Request' || l_req_id2,1,60),'') ,60,' ')); ELSE l_wait_status := fnd_concurrent.wait_for_request(l_req_id2, l_interval, l_max_wait, x_phase, x_status, x_dev_phase, x_dev_status, x_message); END IF;

COMMIT;

/**********************Calling the Procedure for generation Output report**********************************/ xx_output_report_prc(l_conc_request_id); ELSE

/**********************Calling the Validation Procedure **********************************/ xx_ph_ap_supp_valid_dat_prc(l_conc_request_id);

/**********************Calling the Procedure for generation of Validation report**********************************/ xx_output_report_valid_prc(l_conc_request_id);

END IF;

END xx_ph_ap_suppliers_mains_prc;

/**********************************************************************************************/

END xx_ap_supplier_sites_pkg; /show errors;