|
|
发表于 2007/9/26 21:58:49
|
显示全部楼层
给你提供一段核心代码,请参考:
- PROCEDURE Import(p_User_Id IN NUMBER,
- p_Error_Flag OUT VARCHAR2,
- p_Error_Msg OUT VARCHAR2) IS
- Cust_Exception EXCEPTION;
- n_Dummy NUMBER;
- Vc_Error_Msg VARCHAR2(240);
- b_Cont_Flag BOOLEAN := TRUE;
- b_Cust_Header_Exist_Flag BOOLEAN;
- P_Cou_Code VARCHAR2(20);
- P_Rec_Id NUMBER;
- P_Rev_Id NUMBER;
- CURSOR Cust_Data IS
- SELECT t.ROWID, t. *
- FROM Cux.CUX_AR_CUSTOMERS_TEMP t
- WHERE (t.Record_Processed = 'N' AND t.Error_Flag = 'N')
- OR (t.Record_Processed IS NULL AND t.Error_Flag IS NULL)
- ORDER BY t.ROWID;
- Cci CUX_AR_CUSTOMERS_TEMP%ROWTYPE;
- v_Orig_System_Customer_Ref Ra_Customers_Interface.Orig_System_Customer_Ref%TYPE;
- v_Orig_System_Address_Ref Ra_Customers_Interface.Orig_System_Address_Ref%TYPE;
- v_Orig_System_Contact_Ref Ra_Contact_Phones_Int_All.Orig_System_Contact_Ref%TYPE;
- v_Orig_System_Telephone_Ref Ra_Contact_Phones_Int_All.Orig_System_Telephone_Ref%TYPE;
- Customer_Number Ra_Customers_Interface.CUSTOMER_NUMBER%TYPE;
- BEGIN
- /*******************************************************
- * loop for each row
- *******************************************************/
- FOR Cci IN Cust_Data LOOP
- BEGIN
- /*******************************************************
- * verify the system info
- *******************************************************/
- IF Cci.Business_Sys_Id IS NULL THEN
- Vc_Error_Msg := 'Bussiness_Sys_Id不能为空';
- RAISE Cust_Exception;
- END IF;
- IF Cci.Record_Type IS NULL THEN
- Vc_Error_Msg := 'Record_Type不能为空';
- RAISE Cust_Exception;
- END IF;
- /*******************************************************
- * begin to fill the columns interface table used
- *******************************************************/
- Customer_Number := Cci.Bs_Customer_Code;
- v_Orig_System_Customer_Ref := Cci.ORG_ID || Cci.Bs_Customer_Code;
- v_Orig_System_Address_Ref := Cci.Address1 || '-' ||
- Cci.Translated_Customer_Name || '-' ||
- Cci.Location;
- BEGIN
- /*******************************************************
- * verify Orig_system_customer_ref
- * one of the primary key
- *******************************************************/
- SELECT COUNT(1)
- INTO n_Dummy
- FROM Hz_Parties t
- WHERE t.Orig_System_Reference = v_Orig_System_Customer_Ref;
- IF n_Dummy > 0 THEN
- b_Cust_Header_Exist_Flag := TRUE;
- Vc_Error_Msg := 'The customer header (' ||
- v_Orig_System_Customer_Ref ||
- ') ORIG_SYSTEM_CUSTOMER_REF has already existed in the system!';
- RAISE Cust_Exception;
- ELSE
- b_Cust_Header_Exist_Flag := FALSE;
- END IF;
- --dbms_output.put_line(v_orig_system_customer_ref);
- /*******************************************************
- * verify customer_name
- * This column is required
- *******************************************************/
- IF Cci.Customer_Name IS NULL THEN
- Vc_Error_Msg := 'Customer_Name不能为空!';
- RAISE Cust_Exception;
- END IF;
- /*******************************************************
- * verify customer_number
- * This value must be unique within RA_CUSTOMERS.
- *******************************************************/
- SELECT COUNT(1)
- INTO n_Dummy
- FROM Ra_Customers t
- WHERE t.customer_number = Cci.Bs_Customer_Code;
- IF n_Dummy > 0 THEN
- b_Cust_Header_Exist_Flag := TRUE;
- Vc_Error_Msg := 'The customer header (' ||
- Customer_Number ||
- ') CUSTOMER_NUMBER has already existed in the system!' ||
- n_Dummy;
- RAISE Cust_Exception;
- ELSE
- b_Cust_Header_Exist_Flag := FALSE;
- END IF;
- END;
- /*******************************************************
- * get the county code from country description
- * You must enter values that have already been
- * defined in AR_LOCATION_VALUES if Address
- * Validation is set to ’Error’ and you are
- * calculating sales tax.
- * You must always enter a value for Country.
- *******************************************************/
- BEGIN
- SELECT TT.TERRITORY_CODE
- INTO P_COU_CODE
- FROM FND_TERRITORIES_VL TT
- WHERE TT.TERRITORY_SHORT_NAME = CCI.COUNTRY;
- --AND TT.LANGUAGE = USERENV('LANG') ;
- EXCEPTION
- WHEN OTHERS THEN
- Vc_Error_Msg := 'Country 字段无效!';
- RAISE Cust_Exception;
- END;
- /*******************************************************
- * get the Gl_Id_Rec code from Gl_Id_Rec
- *******************************************************/
- IF Cci.Gl_Id_Rec IS NOT NULL THEN
- BEGIN
- SELECT GLCC.CODE_COMBINATION_ID
- INTO P_Rec_Id
- FROM GL_CODE_COMBINATIONS GLCC
- WHERE GLCC.SEGMENT1 || '.' || GLCC.SEGMENT2 || '.' ||
- GLCC.SEGMENT3 || '.' || GLCC.SEGMENT4 || '.' ||
- GLCC.SEGMENT5 || '.' || GLCC.SEGMENT6 || '.' ||
- GLCC.SEGMENT7 || '.' || GLCC.SEGMENT8 = Cci.Gl_Id_Rec;
- EXCEPTION
- WHEN OTHERS THEN
- Vc_Error_Msg := 'Gl_Id_Rec 字段无效!';
- RAISE Cust_Exception;
- END;
- END IF;
- /*******************************************************
- * get the Gl_Id_Rev code from Gl_Id_Rev
- *******************************************************/
- IF Cci.Gl_Id_Rev IS NOT NULL THEN
- BEGIN
- SELECT GLCC.CODE_COMBINATION_ID
- INTO P_Rev_Id
- FROM GL_CODE_COMBINATIONS GLCC
- WHERE GLCC.SEGMENT1 || '.' || GLCC.SEGMENT2 || '.' ||
- GLCC.SEGMENT3 || '.' || GLCC.SEGMENT4 || '.' ||
- GLCC.SEGMENT5 || '.' || GLCC.SEGMENT6 || '.' ||
- GLCC.SEGMENT7 || '.' || GLCC.SEGMENT8 = Cci.Gl_Id_Rev;
- EXCEPTION
- WHEN OTHERS THEN
- Vc_Error_Msg := 'Gl_Id_Rev 字段无效!';
- RAISE Cust_Exception;
- END;
- END IF;
- /*******************************************************
- * insert telephone and fax records when
- * contract_last_name is not null, that is,
- * there must be a contract user
- *******************************************************/
- v_Orig_System_Contact_Ref := NULL;
- v_Orig_System_Telephone_Ref := NULL;
- IF Cci.Contact_Last_Name IS NOT NULL THEN
- BEGIN
- b_Cont_Flag := TRUE;
- v_Orig_System_Contact_Ref := v_Orig_System_Customer_Ref || '-' ||
- Cci.Contact_Last_Name;
- IF Cci.Telephone IS NOT NULL THEN
- v_Orig_System_Telephone_Ref := v_Orig_System_Contact_Ref || '-' ||
- Cci.Telephone || '-' || 'GEN';
- /*******************************************************
- * insert records --telephone
- *******************************************************/
- INSERT INTO Ra_Contact_Phones_Int_All
- (Orig_System_Customer_Ref,
- Orig_System_Contact_Ref,
- Orig_System_Telephone_Ref,
- Insert_Update_Flag,
- Contact_Last_Name,
- CONTACT_JOB_TITLE,
- Telephone,
- Telephone_Type,
- INTERFACE_STATUS,
- Org_Id,
- Email_Address,
- Creation_Date,
- Created_By,
- Last_Update_Date,
- Last_Updated_By)
- VALUES
- (v_Orig_System_Customer_Ref,
- v_Orig_System_Contact_Ref,
- v_Orig_System_Telephone_Ref,
- 'I',
- Cci.Contact_Last_Name,
- 'SOC', --称谓
- Cci.Telephone,
- 'GEN', --select ar_lookups.lookup_code, lookup_type
- --from ar_lookups
- --where lookup_type='COMMUNICATION_TYPE'
- 'A',
- Cci.Org_Id,
- Cci.e_Mail,
- SYSDATE,
- p_User_Id,
- SYSDATE,
- p_User_Id);
- END IF; --cci.telephone IS NOT NULL
- IF Cci.Fax IS NOT NULL THEN
- v_Orig_System_Telephone_Ref := v_Orig_System_Contact_Ref || '-' ||
- Cci.Fax || '-' || 'FAX';
- /*******************************************************
- * insert records --fax
- *******************************************************/
- INSERT INTO Ra_Contact_Phones_Int_All
- (Orig_System_Customer_Ref,
- Orig_System_Contact_Ref,
- Orig_System_Telephone_Ref,
- Insert_Update_Flag,
- Contact_Last_Name,
- CONTACT_JOB_TITLE,
- Telephone,
- Telephone_Type,
- Org_Id,
- Creation_Date,
- Created_By,
- Last_Update_Date,
- Last_Updated_By)
- VALUES
- (v_Orig_System_Customer_Ref,
- v_Orig_System_Contact_Ref,
- v_Orig_System_Telephone_Ref,
- 'I',
- Cci.Contact_Last_Name,
- 'SOC', --称谓
- Cci.Fax,
- 'FAX', --select ar_lookups.lookup_code, lookup_type
- --from ar_lookups
- --where lookup_type='COMMUNICATION_TYPE'
- Cci.Org_Id,
- SYSDATE,
- p_User_Id,
- SYSDATE,
- p_User_Id);
- END IF; --cci.FAX IS NOT NULL
- EXCEPTION
- WHEN OTHERS THEN
- b_Cont_Flag := FALSE;
- END; -- of cci.contact_last_name IS NOT NULL
- END IF;
- /************************************************************
- * insert records if previous telephone insert no error occurs
- ************************************************************/
- IF b_Cont_Flag THEN
- BEGIN
- INSERT INTO Ra_Customers_Interface_ALL
- (Orig_System_Customer_Ref,
- Site_Use_Code,
- Insert_Update_Flag,
- Customer_Name,
- Customer_Number,
- Customer_Status,
- Customer_Name_Phonetic,
- Org_Id, -- user info
- Location,
- Address1,
- Address2,
- Address3,
- Country,
- Province,
- City,
- Postal_Code, -- site info
- Customer_Attribute1,
- Customer_Attribute2,
- Customer_Attribute3, -- contract info
- Gl_Id_Rec,
- Gl_Id_Rev,
- Site_Use_Attribute1,
- Site_Use_Attribute2,
- Address_Attribute5, -- credit info
- Creation_Date,
- Created_By,
- Last_Update_Date,
- Last_Updated_By, -- insert info
- ORIG_SYSTEM_ADDRESS_REF,
- PRIMARY_SITE_USE_FLAG --在插入地址时必须输入 PRIMARY_SITE_USE_FLAG
- )
- VALUES
- (v_Orig_System_Customer_Ref,
- 'BILL_TO', --select AR_LOOKUPS.LOOKUP_CODE
- --from ar_lookups
- --where LOOKUP_TYPE = 'SITE_USE_CODE'
- 'I',
- Cci.Customer_Name,
- Cci.Bs_Customer_Code,
- 'A', --'A':Active,'D':Deleted,'I':Inactive
- Cci.Translated_Customer_Name,
- Cci.Org_Id,
- Cci.Location,
- Cci.Location,
- Cci.Address1,
- Cci.Address2,
- P_Cou_Code, --Country,
- Cci.Province,
- Cci.City,
- Cci.Postal_Code,
- Cci.Customer_Attribute1,
- Cci.Customer_Attribute4,
- Cci.Customer_Attribute3,
- P_Rec_Id, --Gl_Id_Rec,
- P_Rev_Id, --Gl_Id_Rev,
- Cci.Location1,
- Cci.Site_Use_Attribute2,
- Cci.Address_Attribute5,
- SYSDATE,
- p_User_Id,
- SYSDATE,
- p_User_Id,
- v_Orig_System_Address_Ref,
- 'Y');
- -- 一个客户头只需要一条Profile记录
- SELECT COUNT(1)
- INTO n_Dummy
- FROM Ra_Customer_Profiles_Int_All Cpi
- WHERE Cpi.Orig_System_Customer_Ref =
- v_Orig_System_Customer_Ref
- AND Cpi.Orig_System_Address_Ref IS NULL
- AND Cpi.Interface_Status IS NULL;
- --dbms_output.put_line(n_Dummy);
- IF n_Dummy = 0 AND b_Cust_Header_Exist_Flag = FALSE THEN
- INSERT INTO Ra_Customer_Profiles_Int_All
- (Orig_System_Customer_Ref,
- Insert_Update_Flag,
- Customer_Profile_Class_Name,
- Credit_Hold,
- Last_Updated_By,
- Last_Update_Date,
- Created_By,
- Creation_Date,
- Org_Id)
- VALUES
- (v_Orig_System_Customer_Ref,
- 'I',
- 'DEFAULT', --select Name
- --from ar_customer_profile_classes
- --where status='A'
- 'N', -- 'Y' or 'N'
- p_User_Id,
- SYSDATE,
- p_User_Id,
- SYSDATE,
- Cci.Org_Id);
- END IF;
- EXCEPTION
- WHEN OTHERS THEN
- p_Error_Flag := 'Y';
- p_Error_Msg := 'SQL error! ' || SQLCODE || SQLERRM;
- Vc_Error_Msg := p_Error_Msg;
- RAISE Cust_Exception;
- --RETURN;
- END;
- /*******************************************************
- * Update record status success
- *******************************************************/
- UPDATE CUX_AR_CUSTOMERS_TEMP
- SET Record_Processed = 'Y', Error_Flag = 'N'
- WHERE ROWID = Cci.ROWID;
- ELSE
- /*******************************************************
- * Update record status error
- *******************************************************/
- UPDATE CUX_AR_CUSTOMERS_TEMP
- SET Record_Processed = 'Y',
- Error_Flag = 'Y',
- Error_Message = 'Contact record insert fails'
- WHERE ROWID = Cci.ROWID;
- END IF;
- EXCEPTION
- WHEN Cust_Exception THEN
- --Dbms_Output.Put_Line('Cust import error:' || Vc_Error_Msg);
- UPDATE CUX_AR_CUSTOMERS_TEMP
- SET Record_Processed = 'Y',
- Error_Flag = 'Y',
- Error_Message = Vc_Error_Msg
- WHERE ROWID = Cci.ROWID;
- END;
- /*******************************************************
- * Commit this customer
- *******************************************************/
- COMMIT;
- END LOOP; -- FOR cci IN cust_data LOOP
- /*******************************************************
- * update procedure status if no errors
- *******************************************************/
- p_Error_Flag := 'N';
- p_Error_Msg := NULL;
- END Import;
复制代码 |
|