Dear Readers
In this post we will look at a working sample code which can be used to create a customer (party, account, location, party site, account site and site uses)
DECLARE
p_org_id NUMBER
:=
204;
p_location_rec hz_location_v2pub.location_rec_type;
x_location_id NUMBER;
x_return_status VARCHAR2(2000);
x_msg_count NUMBER;
x_msg_data VARCHAR2(2000);
v_organization_rec hz_party_v2pub.organization_rec_type;
-- API Parameter
v_customer_account_rec hz_cust_account_v2pub.cust_account_rec_type;
-- API Parameter
v_party_rec hz_party_v2pub.party_rec_type;
v_customer_profile_rec hz_customer_profile_v2pub.customer_profile_rec_type;
v_location_rec hz_location_v2pub.location_rec_type;
v_party_site_rec hz_party_site_v2pub.party_site_rec_type;
v_party_site_use_rec hz_party_site_v2pub.party_site_use_rec_type;
v_customer_profile_amt hz_customer_profile_v2pub.cust_profile_amt_rec_type;
v_cust_acct_site_rec hz_cust_account_site_v2pub.cust_acct_site_rec_type;
v_customer_site_use_rec hz_cust_account_site_v2pub.cust_site_use_rec_type;
v_customer_ship_site_use_rec hz_cust_account_site_v2pub.cust_site_use_rec_type;
v_contact_point_rec hz_contact_point_v2pub.contact_point_rec_type;
v_phone_rec hz_contact_point_v2pub.phone_rec_type;
v_email_rec hz_contact_point_v2pub.email_rec_type;
v_person_rec hz_party_v2pub.person_rec_type;
v_org_contact_rec hz_party_contact_v2pub.org_contact_rec_type;
x_party_site_id NUMBER;
x_party_site_number VARCHAR2(2000);
v_party_tax_profile_id NUMBER;
x_cust_acct_site_id NUMBER;
x_site_use_id NUMBER;
x_contact_point_id NUMBER;
x_cust_account_id NUMBER;
x_account_number VARCHAR2(2000);
x_party_id NUMBER;
x_party_number VARCHAR2(2000);
x_profile_id NUMBER;
l_party_id NUMBER;
l_success NUMBER;
l_count NUMBER;
l_cust_acc_id NUMBER;
v_count NUMBER;
v_customer_account_id NUMBER;
x_cust_account_profile_id NUMBER;
v_cust_act_prof_amt_id NUMBER;
v_org_id NUMBER;
v_gl_id_rec NUMBER;
x_object_version_number NUMBER;
v_profile_class_id hz_cust_profile_classes.profile_class_id%TYPE;
lv_msg_index NUMBER;
BEGIN
FOR
lrec_stg IN
(
SELECT customer_name name
FROM xx_customer_staging_tbl stg
)
LOOP
v_profile_class_id :=
0;
v_organization_rec.organization_name :=
lrec_stg.name;
v_organization_rec.created_by_module :=
'TCA_V2_API';
v_organization_rec.known_as :=
lrec_stg.name;
v_customer_account_rec.account_name :=
lrec_stg.name;
v_customer_account_rec.customer_class_code :=
NULL;
v_customer_account_rec.created_by_module :=
'TCA_V2_API';
v_customer_profile_rec.profile_class_id :=
v_profile_class_id;
hz_cust_account_v2pub.create_cust_account
(
p_init_msg_list =>
FND_API.G_TRUE,
p_cust_account_rec =>
v_customer_account_rec, -- Customer Account Record
p_organization_rec =>
v_organization_rec, --
Party Organization Record
p_customer_profile_rec =>
v_customer_profile_rec, --
Customer Profile Record
p_create_profile_amt =>
fnd_api.g_true,
x_cust_account_id =>
l_cust_acc_id,
x_account_number =>
x_account_number,
x_party_id =>
x_party_id,
x_party_number =>
x_party_number,
x_profile_id =>
x_profile_id,
x_return_status =>
x_return_status,
x_msg_count =>
x_msg_count,
x_msg_data =>
x_msg_data
);
Dbms_Output.put_line('status
= ' || x_return_status);
Dbms_Output.put_line('x_msg_data
= ' || x_msg_data);
Dbms_Output.put_line('x_msg_count
= ' || x_msg_count);
IF
x_return_status != 'S' THEN
FOR
i IN 1 .. x_msg_count
LOOP
fnd_msg_pub.get
(
p_msg_index =>
i,
p_encoded =>
fnd_api.g_false,
p_data =>
x_msg_data,
p_msg_index_out =>
lv_msg_index
);
Dbms_Output.put_line(x_msg_data);
END
LOOP;
ROLLBACK;
RETURN;
END
IF;
v_location_rec.country :=
'US';
-- Country location code.
v_location_rec.address1 :=
'My
Home address something';
v_location_rec.county :=
'SANTA
CLARA';
v_location_rec.city :=
'San
Jose';
v_location_rec.postal_code :=
'95110';
v_location_rec.state :=
'CA';
v_location_rec.created_by_module
:=
'TCA_V2_API';
hz_location_v2pub.create_location
(
P_INIT_MSG_LIST =>
FND_API.G_TRUE,
P_LOCATION_REC =>
v_location_rec,
X_LOCATION_ID =>
X_LOCATION_ID,
X_RETURN_STATUS =>
X_RETURN_STATUS,
X_MSG_COUNT =>
X_MSG_COUNT,
X_MSG_DATA =>
X_MSG_DATA
);
Dbms_Output.put_line('status
= ' || x_return_status);
Dbms_Output.put_line('x_msg_data
= ' || x_msg_data);
Dbms_Output.put_line('x_msg_count
= ' || x_msg_count);
IF
x_return_status != 'S' THEN
FOR
i IN 1 .. x_msg_count
LOOP
fnd_msg_pub.get
(
p_msg_index =>
i,
p_encoded =>
fnd_api.g_false,
p_data =>
x_msg_data,
p_msg_index_out =>
lv_msg_index
);
Dbms_Output.put_line(x_msg_data);
END
LOOP;
ROLLBACK;
RETURN;
END
IF;
v_party_site_rec.party_id :=
x_party_id;
v_party_site_rec.location_id :=
x_location_id;
v_party_site_rec.party_site_number :=
NULL;
v_party_site_rec.identifying_address_flag
:=
'Y';
v_party_site_rec.created_by_module :=
'TCA_V2_API';
hz_party_site_v2pub.create_party_site
(
P_INIT_MSG_LIST =>
FND_API.G_TRUE,
P_PARTY_SITE_REC =>
v_party_site_rec,
X_PARTY_SITE_ID =>
X_PARTY_SITE_ID,
X_PARTY_SITE_NUMBER =>
X_PARTY_SITE_NUMBER,
X_RETURN_STATUS =>
X_RETURN_STATUS,
X_MSG_COUNT =>
X_MSG_COUNT,
X_MSG_DATA =>
X_MSG_DATA
);
Dbms_Output.put_line('status
= ' || x_return_status);
Dbms_Output.put_line('x_msg_data
= ' || x_msg_data);
Dbms_Output.put_line('x_msg_count
= ' || x_msg_count);
IF
x_return_status != 'S' THEN
FOR
i IN 1 .. x_msg_count
LOOP
fnd_msg_pub.get
(
p_msg_index =>
i,
p_encoded =>
fnd_api.g_false,
p_data =>
x_msg_data,
p_msg_index_out =>
lv_msg_index
);
Dbms_Output.put_line(x_msg_data);
END
LOOP;
ROLLBACK;
RETURN;
END
IF;
v_org_id :=
p_org_id;
v_cust_acct_site_rec.cust_account_id :=
l_cust_acc_id;
v_cust_acct_site_rec.party_site_id :=
x_party_site_id;
v_cust_acct_site_rec.org_id :=
p_org_id;
v_cust_acct_site_rec.created_by_module
:=
'TCA_V2_API';
hz_cust_account_site_v2pub.create_cust_acct_site
(
P_INIT_MSG_LIST =>
FND_API.G_TRUE,
P_CUST_ACCT_SITE_REC =>
v_cust_acct_site_rec,
X_CUST_ACCT_SITE_ID =>
X_CUST_ACCT_SITE_ID,
X_RETURN_STATUS =>
X_RETURN_STATUS,
X_MSG_COUNT =>
X_MSG_COUNT,
X_MSG_DATA =>
X_MSG_DATA
);
Dbms_Output.put_line('status
= ' || x_return_status);
Dbms_Output.put_line('x_msg_data
= ' || x_msg_data);
Dbms_Output.put_line('x_msg_count
= ' || x_msg_count);
IF
x_return_status != 'S' THEN
FOR
i IN 1 .. x_msg_count
LOOP
fnd_msg_pub.get
(
p_msg_index =>
i,
p_encoded =>
fnd_api.g_false,
p_data =>
x_msg_data,
p_msg_index_out =>
lv_msg_index
);
Dbms_Output.put_line(x_msg_data);
END
LOOP;
ROLLBACK;
RETURN;
END
IF;
v_customer_site_use_rec.cust_acct_site_id :=
x_cust_acct_site_id;
v_customer_site_use_rec.site_use_code :=
'BILL_TO';
--v_customer_site_use_rec.gl_id_rec :=
rec_cur.ar_receivable_account;--7006;
v_customer_site_use_rec.org_id :=
p_org_id;
v_customer_site_use_rec.created_by_module :=
'TCA_V2_API';
hz_cust_account_site_v2pub.create_cust_site_use
(
'T',
v_customer_site_use_rec,
v_customer_profile_rec,
'',
'',
x_site_use_id,
x_return_status,
x_msg_count,
x_msg_data
);
Dbms_Output.put_line('status
= ' || x_return_status);
Dbms_Output.put_line('x_msg_data
= ' || x_msg_data);
Dbms_Output.put_line('x_msg_count
= ' || x_msg_count);
IF
x_return_status != 'S' THEN
FOR
i IN 1 .. x_msg_count
LOOP
fnd_msg_pub.get
(
p_msg_index =>
i,
p_encoded =>
fnd_api.g_false,
p_data =>
x_msg_data,
p_msg_index_out =>
lv_msg_index
);
Dbms_Output.put_line(x_msg_data);
END
LOOP;
ROLLBACK;
RETURN;
END
IF;
v_customer_ship_site_use_rec.cust_acct_site_id :=
x_cust_acct_site_id;
v_customer_ship_site_use_rec.site_use_code :=
'SHIP_TO';
v_customer_ship_site_use_rec.org_id :=
p_org_id;
v_customer_ship_site_use_rec.created_by_module :=
'TCA_V2_API';
v_customer_ship_site_use_rec.primary_flag :=
'Y';
hz_cust_account_site_v2pub.create_cust_site_use
(
'T',
v_customer_ship_site_use_rec,
v_customer_profile_rec,
'',
'',
x_site_use_id,
x_return_status,
x_msg_count,
x_msg_data
);
Dbms_Output.put_line('status
= ' || x_return_status);
Dbms_Output.put_line('x_msg_data
= ' || x_msg_data);
Dbms_Output.put_line('x_msg_count
= ' || x_msg_count);
IF
x_return_status != 'S' THEN
FOR
i IN 1 .. x_msg_count
LOOP
fnd_msg_pub.get
(
p_msg_index =>
i,
p_encoded =>
fnd_api.g_false,
p_data =>
x_msg_data,
p_msg_index_out =>
lv_msg_index
);
Dbms_Output.put_line(x_msg_data);
END
LOOP;
ROLLBACK;
RETURN;
END
IF;
END
LOOP;
END;
Hope this will help
Cheers
A