DBA Data[Home] [Help]

PACKAGE BODY: APPS.CSP_SHIP_TO_ADDRESS_PVT

Source


1 PACKAGE BODY CSP_SHIP_TO_ADDRESS_PVT AS
2 /*$Header: cspvstab.pls 120.20.12020000.6 2013/02/21 10:01:40 vmandava ship $*/
3 ------------------------------------------------------------------------------------------------------------------------
4 --
5 -- Procedure Name   : Main procedure name is ship_to_address_handler.  All calling programs should call it directly.
6 --                    It can handle the following situations:
7 --                    1. Create an inventory location.
8 --                    2. Modify an inventory location.
9 --                    3. Create site location, party, party site, party site use, customer account, customer profile,
10 --                       customer account site, customer account site use, location association, ... for a ship to
11 --                       address.
12 --                       The ship to address (inventory location) will be set to be linked to a customer.  Order Entry
13 --                       will pick up the right ship to address and customer at a later time.
14 -- Version          : 1.0
15 --
16 -- Modification History
17 -- Person      Date         Comments
18 -- ---------   -----------  ------------------------------------------
19 -- iouyang     01-May-2001  New
20 --
21 ------------------------------------------------------------------------------------------------------------------------
22 
23 G_PKG_NAME  CONSTANT    VARCHAR2(30) := 'CSP_SHIP_TO_ADDRESS_PUB';
24 G_FILE_NAME CONSTANT    VARCHAR2(30) := 'cspvstab.pls';
25 
26 
27 --------------------------------------------------------------------------------
28 --
29 -- Procedure Name   : do_create_rs_cust_relation
30 -- Purpose          : Create a relationship between a resource and a customer
31 --                    in table csp_rs_cust_relations.
32 --
33 PROCEDURE do_rs_cust_relations
34    (p_resource_type         IN VARCHAR2
35    ,p_resource_id           IN NUMBER
36    ,p_customer_id           IN NUMBER) IS
37 
38    l_rs_cust_relation_id   csp_rs_cust_relations.rs_cust_relation_id%TYPE := NULL;
39    l_resource_type         csp_rs_cust_relations.resource_type%TYPE;
40    l_resource_id           csp_rs_cust_relations.resource_id%TYPE;
41    l_customer_id           csp_rs_cust_relations.customer_id%TYPE;
42    l_CREATED_BY            number;
43    l_CREATION_DATE         date;
44    l_ATTRIBUTE_CATEGORY    varchar2(30);
45    l_ATTRIBUTE1            varchar2(150);
46    l_ATTRIBUTE2            varchar2(150);
47    l_ATTRIBUTE3            varchar2(150);
48    l_ATTRIBUTE4            varchar2(150);
49    l_ATTRIBUTE5            varchar2(150);
50    l_ATTRIBUTE6            varchar2(150);
51    l_ATTRIBUTE7            varchar2(150);
52    l_ATTRIBUTE8            varchar2(150);
53    l_ATTRIBUTE9            varchar2(150);
54    l_ATTRIBUTE10           varchar2(150);
55    l_ATTRIBUTE11           varchar2(150);
56    l_ATTRIBUTE12           varchar2(150);
57    l_ATTRIBUTE13           varchar2(150);
58    l_ATTRIBUTE14           varchar2(150);
59    l_ATTRIBUTE15           varchar2(150);
60 
61    CURSOR l_rs_relation_csr IS
62       select rs_cust_relation_id,
63 		customer_id,
64 created_by,
65 creation_date,
66 attribute_category,
67 attribute1,
68 attribute2,
69 attribute3,
70 attribute4,
71 attribute5,
72 attribute6,
73 attribute7,
74 attribute8,
75 attribute9,
76 attribute10,
77 attribute11,
78 attribute12,
79 attribute13,
80 attribute14,
81 attribute15
82        from csp_rs_cust_relations
83 where resource_type = p_resource_type and resource_id = p_resource_id;
84 
85 BEGIN
86    csp_ship_to_address_pvt.g_rs_cust_relation_id := null;
87    OPEN l_rs_relation_csr;
88    FETCH l_rs_relation_csr INTO l_rs_cust_relation_id,
89 l_customer_id,
90 l_created_by,
91 l_creation_date,
92 l_attribute_category,
93 l_attribute1,
94 l_attribute2,
95 l_attribute3,
96 l_attribute4,
97 l_attribute5,
98 l_attribute6,
99 l_attribute7,
100 l_attribute8,
101 l_attribute9,
102 l_attribute10,
103 l_attribute11,
104 l_attribute12,
105 l_attribute13,
106 l_attribute14,
107 l_attribute15;
108    IF l_rs_relation_csr%FOUND THEN
109       CLOSE l_rs_relation_csr;
110       IF l_customer_id IS NULL THEN
111          csp_rs_cust_relations_pkg.update_row(
112          p_RS_CUST_RELATION_ID      => l_rs_cust_relation_id,
113          p_RESOURCE_TYPE            => p_resource_type,
114          p_RESOURCE_ID              => p_resource_id,
115          p_CUSTOMER_ID              => p_customer_id,
116          p_CREATED_BY               => l_created_by,
117          p_CREATION_DATE            => l_creation_date,
118          p_LAST_UPDATED_BY          => nvl(fnd_global.user_id, 1),
119          p_LAST_UPDATE_DATE         => sysdate,
120          p_LAST_UPDATE_LOGIN        => nvl(fnd_global.user_id, 1),
121          p_ATTRIBUTE_CATEGORY       => l_attribute_category,
122          p_ATTRIBUTE1               => l_attribute1,
123          p_ATTRIBUTE2               => l_attribute2,
124          p_ATTRIBUTE3               => l_attribute3,
125          p_ATTRIBUTE4               => l_attribute4,
126          p_ATTRIBUTE5               => l_attribute5,
127          p_ATTRIBUTE6               => l_attribute6,
128          p_ATTRIBUTE7               => l_attribute7,
129          p_ATTRIBUTE8               => l_attribute8,
130          p_ATTRIBUTE9               => l_attribute9,
131          p_ATTRIBUTE10              => l_attribute10,
132          p_ATTRIBUTE11              => l_attribute11,
133          p_ATTRIBUTE12              => l_attribute12,
134          p_ATTRIBUTE13              => l_attribute13,
135          p_ATTRIBUTE14              => l_attribute14,
136          p_ATTRIBUTE15              => l_attribute15);
137       END IF;
138    ELSE
139       CLOSE l_rs_relation_csr;
140       csp_rs_cust_relations_pkg.insert_row(
141          px_RS_CUST_RELATION_ID     => l_rs_cust_relation_id,
142          p_RESOURCE_TYPE            => p_resource_type,
143          p_RESOURCE_ID              => p_resource_id,
144          p_CUSTOMER_ID              => p_customer_id,
145          p_CREATED_BY               => nvl(fnd_global.user_id, 1),
146          p_CREATION_DATE            => sysdate,
147          p_LAST_UPDATED_BY          => nvl(fnd_global.user_id, 1),
148          p_LAST_UPDATE_DATE         => sysdate,
149          p_LAST_UPDATE_LOGIN        => nvl(fnd_global.user_id, 1),
150          p_ATTRIBUTE_CATEGORY       => NULL,
151          p_ATTRIBUTE1               => NULL,
152          p_ATTRIBUTE2               => NULL,
153          p_ATTRIBUTE3               => NULL,
154          p_ATTRIBUTE4               => NULL,
155          p_ATTRIBUTE5               => NULL,
156          p_ATTRIBUTE6               => NULL,
157          p_ATTRIBUTE7               => NULL,
158          p_ATTRIBUTE8               => NULL,
159          p_ATTRIBUTE9               => NULL,
160          p_ATTRIBUTE10              => NULL,
161          p_ATTRIBUTE11              => NULL,
162          p_ATTRIBUTE12              => NULL,
163          p_ATTRIBUTE13              => NULL,
164          p_ATTRIBUTE14              => NULL,
165          p_ATTRIBUTE15              => NULL);
166 
167    END IF;
168          csp_ship_to_address_pvt.g_rs_cust_relation_id := l_rs_cust_relation_id;
169 
170 END do_rs_cust_relations;
171 
172 
173 
174 --------------------------------------------------------------------------------
175 --
176 -- Procedure Name   : do_create_ship_to_location
177 -- Purpose          : It takes location code, description, and address fields
178 --                    to create a new inventory location.
179 --                    Return location_id.
180 --
181 PROCEDURE do_create_ship_to_location
182    (p_location_id            OUT NOCOPY NUMBER
183    ,p_style                  IN VARCHAR2
184    ,p_address_line_1         IN VARCHAR2
185    ,p_address_line_2         IN VARCHAR2
186    ,p_address_line_3         IN VARCHAR2
187    ,p_country                IN VARCHAR2
188    ,p_postal_code            IN VARCHAR2
189    ,p_region_1               IN VARCHAR2
190    ,p_region_2               IN VARCHAR2
191    ,p_region_3               IN VARCHAR2
192    ,p_town_or_city           IN VARCHAR2
193    ,p_tax_name               IN VARCHAR2
194    ,p_telephone_number_1     IN VARCHAR2
195    ,p_telephone_number_2     IN VARCHAR2
196    ,p_telephone_number_3     IN VARCHAR2
197    ,p_loc_information13      IN VARCHAR2
198    ,p_loc_information14      IN VARCHAR2
199    ,p_loc_information15      IN VARCHAR2
200    ,p_loc_information16      IN VARCHAR2
201    ,p_loc_information17      IN VARCHAR2
202    ,p_loc_information18      IN VARCHAR2
203    ,p_loc_information19      IN VARCHAR2
204    ,p_loc_information20      IN VARCHAR2
205    ,p_attribute_category     IN VARCHAR2
206    ,p_attribute1             IN VARCHAR2
207    ,p_attribute2             IN VARCHAR2
208    ,p_attribute3             IN VARCHAR2
209    ,p_attribute4             IN VARCHAR2
210    ,p_attribute5             IN VARCHAR2
211    ,p_attribute6             IN VARCHAR2
212    ,p_attribute7             IN VARCHAR2
213    ,p_attribute8             IN VARCHAR2
214    ,p_attribute9             IN VARCHAR2
215    ,p_attribute10             IN VARCHAR2
216    ,p_attribute11             IN VARCHAR2
217    ,p_attribute12             IN VARCHAR2
218    ,p_attribute13            IN VARCHAR2
219    ,p_attribute14             IN VARCHAR2
220    ,p_attribute15             IN VARCHAR2
221    ,p_attribute16             IN VARCHAR2
222    ,p_attribute17             IN VARCHAR2
223    ,p_attribute18             IN VARCHAR2
224    ,p_attribute19             IN VARCHAR2
225    ,p_attribute20             IN VARCHAR2
226    ,p_object_version_number  OUT NOCOPY NUMBER
227    ,x_return_status          OUT NOCOPY VARCHAR2
228    ,x_msg_count              OUT NOCOPY NUMBER
229    ,x_msg_data               OUT NOCOPY VARCHAR2 ) IS
230 
231    l_api_version_number    CONSTANT NUMBER := 1.0;
232    l_api_name              CONSTANT VARCHAR2(30) := 'do_create_ship_to_location';
233    EXCP_USER_DEFINED       EXCEPTION;
234 
235    l_validate                   BOOLEAN := false;
236    l_effective_date             DATE := sysdate;
237    l_location_id                hr_locations_all.location_id%TYPE;
238    l_language                   hr_locations_all_tl.language%TYPE;
239    l_location_code              hr_locations_all.location_code%TYPE := NULL;
240    l_description                hr_locations_all.description%TYPE := NULL;
241    l_bill_to_site_flag          hr_locations_all.bill_to_site_flag%TYPE := 'Y';
242    l_ship_to_site_flag          hr_locations_all.ship_to_site_flag%TYPE := 'Y';
243    l_tp_header_id               hr_locations_all.tp_header_id%TYPE := NULL;
244    l_ece_tp_location_code       hr_locations_all.ece_tp_location_code%TYPE := NULL;
245    l_designated_receiver_id     hr_locations_all.designated_receiver_id%TYPE := NULL;
246    l_in_organization_flag       hr_locations_all.in_organization_flag%TYPE := 'N';
247    l_inactive_date              hr_locations_all.inactive_date%TYPE := NULL;
248    l_operating_unit_id          NUMBER := NULL;
249    l_inventory_organization_id  hr_locations_all.inventory_organization_id%TYPE := NULL;
250    l_office_site_flag           hr_locations_all.office_site_flag%TYPE := 'N';
251    l_receiving_site_flag        hr_locations_all.receiving_site_flag%TYPE := 'Y';
252    l_ship_to_location_id        hr_locations_all.ship_to_location_id%TYPE := NULL;
253 
254    l_in_hr_loc_hook_rec   hr_location_record.location_rectype;
255    l_out_hr_loc_hook_rec   hr_location_record.location_rectype;
256 
257 BEGIN
258 
259     if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
260        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
261                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
262                   'Begin...');
263     end if;
264 
265    SAVEPOINT do_create_ship_to_location_PUB;
266 
267    -- Initialize
268    x_return_status := FND_API.G_RET_STS_SUCCESS;
269    select userenv('LANG') into l_language from dual;
270 
271     if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
272        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
273                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
274                   'l_language = ' || l_language);
275     end if;
276 
277    -- Assign location code
278    select csp_location_id_s1.NEXTVAL into l_location_code from dual;
279    l_location_code := 'CSP' || l_location_code;
280 
281     if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
282        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
283                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
284                   'l_location_code = ' || l_location_code);
285     end if;
286 
287    -- Default location description to address 1.
288    --l_description := p_address_line_1;
289 
290    l_in_hr_loc_hook_rec.location_code := l_location_code;
291    l_in_hr_loc_hook_rec.description := l_description;
292    l_in_hr_loc_hook_rec.tp_header_id := l_tp_header_id;
293    l_in_hr_loc_hook_rec.ece_tp_location_code := l_ece_tp_location_code;
294    l_in_hr_loc_hook_rec.address_line_1 := p_address_line_1;
295    l_in_hr_loc_hook_rec.address_line_2 := p_address_line_2;
296    l_in_hr_loc_hook_rec.address_line_3 := p_address_line_3;
297    l_in_hr_loc_hook_rec.bill_to_site_flag := l_bill_to_site_flag;
298    l_in_hr_loc_hook_rec.country := p_country;
299    l_in_hr_loc_hook_rec.designated_receiver_id := l_designated_receiver_id;
300    l_in_hr_loc_hook_rec.in_organization_flag := l_in_organization_flag;
301    l_in_hr_loc_hook_rec.inactive_date := l_inactive_date;
302    l_in_hr_loc_hook_rec.inventory_organization_id := l_inventory_organization_id;
303    l_in_hr_loc_hook_rec.office_site_flag := l_office_site_flag;
304    l_in_hr_loc_hook_rec.postal_code := p_postal_code;
305    l_in_hr_loc_hook_rec.receiving_site_flag := l_receiving_site_flag;
306    l_in_hr_loc_hook_rec.region_1 := p_region_1;
307    l_in_hr_loc_hook_rec.region_2 := p_region_2;
308    l_in_hr_loc_hook_rec.region_3 := p_region_3;
309    l_in_hr_loc_hook_rec.ship_to_location_id := l_ship_to_location_id;
310    l_in_hr_loc_hook_rec.ship_to_site_flag := l_ship_to_site_flag;
311    l_in_hr_loc_hook_rec.style := p_style;
312    l_in_hr_loc_hook_rec.tax_name := p_tax_name;
313    l_in_hr_loc_hook_rec.telephone_number_1 := p_telephone_number_1;
314    l_in_hr_loc_hook_rec.telephone_number_2 := p_telephone_number_2;
315    l_in_hr_loc_hook_rec.telephone_number_3 := p_telephone_number_3;
316    l_in_hr_loc_hook_rec.town_or_city := p_town_or_city;
317    l_in_hr_loc_hook_rec.loc_information13 := p_loc_information13;
318    l_in_hr_loc_hook_rec.loc_information14 := p_loc_information14;
319    l_in_hr_loc_hook_rec.loc_information15 := p_loc_information15;
320    l_in_hr_loc_hook_rec.loc_information16 := p_loc_information16;
321    l_in_hr_loc_hook_rec.loc_information17 := p_loc_information17;
322    l_in_hr_loc_hook_rec.loc_information18 := p_loc_information18;
323    l_in_hr_loc_hook_rec.loc_information19 := p_loc_information19;
324    l_in_hr_loc_hook_rec.loc_information20 := p_loc_information20;
325    l_in_hr_loc_hook_rec.attribute1 := p_attribute1;
326    l_in_hr_loc_hook_rec.attribute2 := p_attribute2;
327    l_in_hr_loc_hook_rec.attribute3 := p_attribute3;
328    l_in_hr_loc_hook_rec.attribute4 := p_attribute4;
329    l_in_hr_loc_hook_rec.attribute5 := p_attribute5;
330    l_in_hr_loc_hook_rec.attribute6 := p_attribute6;
331    l_in_hr_loc_hook_rec.attribute7 := p_attribute7;
332    l_in_hr_loc_hook_rec.attribute8 := p_attribute8;
333    l_in_hr_loc_hook_rec.attribute9 := p_attribute9;
334    l_in_hr_loc_hook_rec.attribute10 := p_attribute10;
335    l_in_hr_loc_hook_rec.attribute11 := p_attribute11;
336    l_in_hr_loc_hook_rec.attribute12 := p_attribute12;
337    l_in_hr_loc_hook_rec.attribute13 := p_attribute13;
338    l_in_hr_loc_hook_rec.attribute14 := p_attribute14;
339    l_in_hr_loc_hook_rec.attribute15 := p_attribute15;
340    l_in_hr_loc_hook_rec.attribute16 := p_attribute16;
341    l_in_hr_loc_hook_rec.attribute17 := p_attribute17;
342    l_in_hr_loc_hook_rec.attribute18 := p_attribute18;
343    l_in_hr_loc_hook_rec.attribute19 := p_attribute19;
344    l_in_hr_loc_hook_rec.attribute20 := p_attribute20;
345    l_in_hr_loc_hook_rec.attribute_category := p_attribute_category;
346 
347     if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
348        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
349                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
350                   'Before calling CSP_HR_LOC_CUST.user_hook...');
351        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
352                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
353                   'l_in_hr_loc_hook_rec.location_code = ' || l_in_hr_loc_hook_rec.location_code);
354        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
355                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
356                   'l_in_hr_loc_hook_rec.description = ' || l_in_hr_loc_hook_rec.description);
357        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
358                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
359                   'l_in_hr_loc_hook_rec.tp_header_id = ' || l_in_hr_loc_hook_rec.tp_header_id);
360        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
361                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
362                   'l_in_hr_loc_hook_rec.ece_tp_location_code = ' || l_in_hr_loc_hook_rec.ece_tp_location_code);
363        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
364                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
365                   'l_in_hr_loc_hook_rec.address_line_1 = ' || l_in_hr_loc_hook_rec.address_line_1);
366        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
367                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
368                   'l_in_hr_loc_hook_rec.address_line_2 = ' || l_in_hr_loc_hook_rec.address_line_2);
369        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
370                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
371                   'l_in_hr_loc_hook_rec.address_line_3 = ' || l_in_hr_loc_hook_rec.address_line_3);
372        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
373                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
374                   'l_in_hr_loc_hook_rec.bill_to_site_flag = ' || l_in_hr_loc_hook_rec.bill_to_site_flag);
375        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
376                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
377                   'l_in_hr_loc_hook_rec.country = ' || l_in_hr_loc_hook_rec.country);
378        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
379                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
380                   'l_in_hr_loc_hook_rec.designated_receiver_id = ' || l_in_hr_loc_hook_rec.designated_receiver_id);
381        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
382                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
383                   'l_in_hr_loc_hook_rec.in_organization_flag = ' || l_in_hr_loc_hook_rec.in_organization_flag);
384        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
385                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
386                   'l_in_hr_loc_hook_rec.inactive_date = ' || l_in_hr_loc_hook_rec.inactive_date);
387        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
388                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
389                   'l_in_hr_loc_hook_rec.inventory_organization_id = ' || l_in_hr_loc_hook_rec.inventory_organization_id);
390        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
391                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
392                   'l_in_hr_loc_hook_rec.office_site_flag = ' || l_in_hr_loc_hook_rec.office_site_flag);
393        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
394                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
395                   'l_in_hr_loc_hook_rec.postal_code = ' || l_in_hr_loc_hook_rec.postal_code);
396        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
397                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
398                   'l_in_hr_loc_hook_rec.receiving_site_flag = ' || l_in_hr_loc_hook_rec.receiving_site_flag);
399        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
400                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
401                   'l_in_hr_loc_hook_rec.region_1 = ' || l_in_hr_loc_hook_rec.region_1);
402        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
403                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
404                   'l_in_hr_loc_hook_rec.region_2 = ' || l_in_hr_loc_hook_rec.region_2);
405        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
406                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
407                   'l_in_hr_loc_hook_rec.region_3 = ' || l_in_hr_loc_hook_rec.region_3);
408        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
409                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
410                   'l_in_hr_loc_hook_rec.ship_to_location_id = ' || l_in_hr_loc_hook_rec.ship_to_location_id);
411        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
412                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
413                   'l_in_hr_loc_hook_rec.ship_to_site_flag = ' || l_in_hr_loc_hook_rec.ship_to_site_flag);
414        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
415                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
416                   'l_in_hr_loc_hook_rec.style = ' || l_in_hr_loc_hook_rec.style);
417        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
418                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
419                   'l_in_hr_loc_hook_rec.tax_name = ' || l_in_hr_loc_hook_rec.tax_name);
420        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
421                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
422                   'l_in_hr_loc_hook_rec.telephone_number_1 = ' || l_in_hr_loc_hook_rec.telephone_number_1);
423        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
424                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
425                   'l_in_hr_loc_hook_rec.telephone_number_2 = ' || l_in_hr_loc_hook_rec.telephone_number_2);
426        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
427                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
428                   'l_in_hr_loc_hook_rec.telephone_number_3 = ' || l_in_hr_loc_hook_rec.telephone_number_3);
429        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
430                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
431                   'l_in_hr_loc_hook_rec.town_or_city = ' || l_in_hr_loc_hook_rec.town_or_city);
432        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
433                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
434                   'l_in_hr_loc_hook_rec.loc_information13 = ' || l_in_hr_loc_hook_rec.loc_information13);
435        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
436                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
437                   'l_in_hr_loc_hook_rec.loc_information14 = ' || l_in_hr_loc_hook_rec.loc_information14);
438        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
439                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
440                   'l_in_hr_loc_hook_rec.loc_information15 = ' || l_in_hr_loc_hook_rec.loc_information15);
441        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
442                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
443                   'l_in_hr_loc_hook_rec.loc_information16 = ' || l_in_hr_loc_hook_rec.loc_information16);
444        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
445                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
446                   'l_in_hr_loc_hook_rec.loc_information17 = ' || l_in_hr_loc_hook_rec.loc_information17);
447        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
448                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
449                   'l_in_hr_loc_hook_rec.loc_information18 = ' || l_in_hr_loc_hook_rec.loc_information18);
450        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
451                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
452                   'l_in_hr_loc_hook_rec.loc_information19 = ' || l_in_hr_loc_hook_rec.loc_information19);
453        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
454                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
455                   'l_in_hr_loc_hook_rec.loc_information20 = ' || l_in_hr_loc_hook_rec.loc_information20);
456        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
457                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
458                   'l_in_hr_loc_hook_rec.attribute1 = ' || l_in_hr_loc_hook_rec.attribute1);
459        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
460                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
461                   'l_in_hr_loc_hook_rec.attribute2 = ' || l_in_hr_loc_hook_rec.attribute2);
462        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
463                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
464                   'l_in_hr_loc_hook_rec.attribute3 = ' || l_in_hr_loc_hook_rec.attribute3);
465        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
466                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
467                   'l_in_hr_loc_hook_rec.attribute4 = ' || l_in_hr_loc_hook_rec.attribute4);
468        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
469                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
470                   'l_in_hr_loc_hook_rec.attribute5 = ' || l_in_hr_loc_hook_rec.attribute5);
471        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
472                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
473                   'l_in_hr_loc_hook_rec.attribute6 = ' || l_in_hr_loc_hook_rec.attribute6);
474        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
475                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
476                   'l_in_hr_loc_hook_rec.attribute7 = ' || l_in_hr_loc_hook_rec.attribute7);
477        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
478                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
479                   'l_in_hr_loc_hook_rec.attribute8 = ' || l_in_hr_loc_hook_rec.attribute8);
480        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
481                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
482                   'l_in_hr_loc_hook_rec.attribute9 = ' || l_in_hr_loc_hook_rec.attribute9);
483        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
484                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
485                   'l_in_hr_loc_hook_rec.attribute10 = ' || l_in_hr_loc_hook_rec.attribute10);
486        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
487                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
488                   'l_in_hr_loc_hook_rec.attribute11 = ' || l_in_hr_loc_hook_rec.attribute11);
489        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
490                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
491                   'l_in_hr_loc_hook_rec.attribute12 = ' || l_in_hr_loc_hook_rec.attribute12);
492        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
493                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
494                   'l_in_hr_loc_hook_rec.attribute13 = ' || l_in_hr_loc_hook_rec.attribute13);
495        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
496                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
497                   'l_in_hr_loc_hook_rec.attribute14 = ' || l_in_hr_loc_hook_rec.attribute14);
498        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
499                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
500                   'l_in_hr_loc_hook_rec.attribute15 = ' || l_in_hr_loc_hook_rec.attribute15);
501        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
502                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
503                   'l_in_hr_loc_hook_rec.attribute16 = ' || l_in_hr_loc_hook_rec.attribute16);
504        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
505                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
506                   'l_in_hr_loc_hook_rec.attribute17 = ' || l_in_hr_loc_hook_rec.attribute17);
507        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
508                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
509                   'l_in_hr_loc_hook_rec.attribute18 = ' || l_in_hr_loc_hook_rec.attribute18);
510        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
511                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
512                   'l_in_hr_loc_hook_rec.attribute19 = ' || l_in_hr_loc_hook_rec.attribute19);
513        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
514                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
515                   'l_in_hr_loc_hook_rec.attribute20 = ' || l_in_hr_loc_hook_rec.attribute20);
516        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
517                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
518                   'l_in_hr_loc_hook_rec.attribute_category = ' || l_in_hr_loc_hook_rec.attribute_category);
519     end if;
520 
521     l_out_hr_loc_hook_rec := CSP_HR_LOC_CUST.user_hook(l_in_hr_loc_hook_rec);
522 
523     if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
524        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
525                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
526                   'After calling CSP_HR_LOC_CUST.user_hook...');
527        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
528                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
529                   'l_out_hr_loc_hook_rec.location_code = ' || l_out_hr_loc_hook_rec.location_code);
530        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
531                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
532                   'l_out_hr_loc_hook_rec.description = ' || l_out_hr_loc_hook_rec.description);
533        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
534                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
535                   'l_out_hr_loc_hook_rec.tp_header_id = ' || l_out_hr_loc_hook_rec.tp_header_id);
536        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
537                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
538                   'l_out_hr_loc_hook_rec.ece_tp_location_code = ' || l_out_hr_loc_hook_rec.ece_tp_location_code);
539        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
540                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
541                   'l_out_hr_loc_hook_rec.address_line_1 = ' || l_out_hr_loc_hook_rec.address_line_1);
542        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
543                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
544                   'l_out_hr_loc_hook_rec.address_line_2 = ' || l_out_hr_loc_hook_rec.address_line_2);
545        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
546                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
547                   'l_out_hr_loc_hook_rec.address_line_3 = ' || l_out_hr_loc_hook_rec.address_line_3);
548        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
549                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
550                   'l_out_hr_loc_hook_rec.bill_to_site_flag = ' || l_out_hr_loc_hook_rec.bill_to_site_flag);
551        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
552                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
553                   'l_out_hr_loc_hook_rec.country = ' || l_out_hr_loc_hook_rec.country);
554        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
555                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
556                   'l_out_hr_loc_hook_rec.designated_receiver_id = ' || l_out_hr_loc_hook_rec.designated_receiver_id);
557        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
558                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
559                   'l_out_hr_loc_hook_rec.in_organization_flag = ' || l_out_hr_loc_hook_rec.in_organization_flag);
560        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
561                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
562                   'l_out_hr_loc_hook_rec.inactive_date = ' || l_out_hr_loc_hook_rec.inactive_date);
563        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
564                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
565                   'l_out_hr_loc_hook_rec.inventory_organization_id = ' || l_out_hr_loc_hook_rec.inventory_organization_id);
566        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
567                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
568                   'l_out_hr_loc_hook_rec.office_site_flag = ' || l_out_hr_loc_hook_rec.office_site_flag);
569        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
570                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
571                   'l_out_hr_loc_hook_rec.postal_code = ' || l_out_hr_loc_hook_rec.postal_code);
572        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
573                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
574                   'l_out_hr_loc_hook_rec.receiving_site_flag = ' || l_out_hr_loc_hook_rec.receiving_site_flag);
575        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
576                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
577                   'l_out_hr_loc_hook_rec.region_1 = ' || l_out_hr_loc_hook_rec.region_1);
578        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
579                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
580                   'l_out_hr_loc_hook_rec.region_2 = ' || l_out_hr_loc_hook_rec.region_2);
581        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
582                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
583                   'l_out_hr_loc_hook_rec.region_3 = ' || l_out_hr_loc_hook_rec.region_3);
584        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
585                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
586                   'l_out_hr_loc_hook_rec.ship_to_location_id = ' || l_out_hr_loc_hook_rec.ship_to_location_id);
587        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
588                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
589                   'l_out_hr_loc_hook_rec.ship_to_site_flag = ' || l_out_hr_loc_hook_rec.ship_to_site_flag);
590        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
591                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
592                   'l_out_hr_loc_hook_rec.style = ' || l_out_hr_loc_hook_rec.style);
593        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
594                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
595                   'l_out_hr_loc_hook_rec.tax_name = ' || l_out_hr_loc_hook_rec.tax_name);
596        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
597                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
598                   'l_out_hr_loc_hook_rec.telephone_number_1 = ' || l_out_hr_loc_hook_rec.telephone_number_1);
599        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
600                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
601                   'l_out_hr_loc_hook_rec.telephone_number_2 = ' || l_out_hr_loc_hook_rec.telephone_number_2);
602        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
603                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
604                   'l_out_hr_loc_hook_rec.telephone_number_3 = ' || l_out_hr_loc_hook_rec.telephone_number_3);
605        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
606                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
607                   'l_out_hr_loc_hook_rec.town_or_city = ' || l_out_hr_loc_hook_rec.town_or_city);
608        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
609                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
610                   'l_out_hr_loc_hook_rec.loc_information13 = ' || l_out_hr_loc_hook_rec.loc_information13);
611        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
612                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
613                   'l_out_hr_loc_hook_rec.loc_information14 = ' || l_out_hr_loc_hook_rec.loc_information14);
614        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
615                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
616                   'l_out_hr_loc_hook_rec.loc_information15 = ' || l_out_hr_loc_hook_rec.loc_information15);
617        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
618                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
619                   'l_out_hr_loc_hook_rec.loc_information16 = ' || l_out_hr_loc_hook_rec.loc_information16);
620        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
621                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
622                   'l_out_hr_loc_hook_rec.loc_information17 = ' || l_out_hr_loc_hook_rec.loc_information17);
623        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
624                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
625                   'l_out_hr_loc_hook_rec.loc_information18 = ' || l_out_hr_loc_hook_rec.loc_information18);
626        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
627                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
628                   'l_out_hr_loc_hook_rec.loc_information19 = ' || l_out_hr_loc_hook_rec.loc_information19);
629        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
630                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
631                   'l_out_hr_loc_hook_rec.loc_information20 = ' || l_out_hr_loc_hook_rec.loc_information20);
632        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
633                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
634                   'l_out_hr_loc_hook_rec.attribute1 = ' || l_out_hr_loc_hook_rec.attribute1);
635        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
636                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
637                   'l_out_hr_loc_hook_rec.attribute2 = ' || l_out_hr_loc_hook_rec.attribute2);
638        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
639                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
640                   'l_out_hr_loc_hook_rec.attribute3 = ' || l_out_hr_loc_hook_rec.attribute3);
641        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
642                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
643                   'l_out_hr_loc_hook_rec.attribute4 = ' || l_out_hr_loc_hook_rec.attribute4);
644        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
645                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
646                   'l_out_hr_loc_hook_rec.attribute5 = ' || l_out_hr_loc_hook_rec.attribute5);
647        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
648                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
649                   'l_out_hr_loc_hook_rec.attribute6 = ' || l_out_hr_loc_hook_rec.attribute6);
650        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
651                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
652                   'l_out_hr_loc_hook_rec.attribute7 = ' || l_out_hr_loc_hook_rec.attribute7);
653        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
654                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
655                   'l_out_hr_loc_hook_rec.attribute8 = ' || l_out_hr_loc_hook_rec.attribute8);
656        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
657                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
658                   'l_out_hr_loc_hook_rec.attribute9 = ' || l_out_hr_loc_hook_rec.attribute9);
659        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
660                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
661                   'l_out_hr_loc_hook_rec.attribute10 = ' || l_out_hr_loc_hook_rec.attribute10);
662        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
663                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
664                   'l_out_hr_loc_hook_rec.attribute11 = ' || l_out_hr_loc_hook_rec.attribute11);
665        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
666                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
667                   'l_out_hr_loc_hook_rec.attribute12 = ' || l_out_hr_loc_hook_rec.attribute12);
668        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
669                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
670                   'l_out_hr_loc_hook_rec.attribute13 = ' || l_out_hr_loc_hook_rec.attribute13);
671        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
672                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
673                   'l_out_hr_loc_hook_rec.attribute14 = ' || l_out_hr_loc_hook_rec.attribute14);
674        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
675                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
676                   'l_out_hr_loc_hook_rec.attribute15 = ' || l_out_hr_loc_hook_rec.attribute15);
677        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
678                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
679                   'l_out_hr_loc_hook_rec.attribute16 = ' || l_out_hr_loc_hook_rec.attribute16);
680        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
681                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
682                   'l_out_hr_loc_hook_rec.attribute17 = ' || l_out_hr_loc_hook_rec.attribute17);
683        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
684                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
685                   'l_out_hr_loc_hook_rec.attribute18 = ' || l_out_hr_loc_hook_rec.attribute18);
686        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
687                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
688                   'l_out_hr_loc_hook_rec.attribute19 = ' || l_out_hr_loc_hook_rec.attribute19);
689        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
690                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
691                   'l_out_hr_loc_hook_rec.attribute20 = ' || l_out_hr_loc_hook_rec.attribute20);
692        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
693                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
694                   'l_out_hr_loc_hook_rec.attribute_category = ' || l_out_hr_loc_hook_rec.attribute_category);
695     end if;
696 
697     if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
698        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
699                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
700                   'Before calling hr_location_api.create_location...');
701     end if;
702 
703    hr_location_api.create_location(
704       p_effective_date              => l_effective_date,
705       p_location_code               => l_location_code,
706       p_description                 => l_description,
707       p_tp_header_id                => l_tp_header_id,
708       p_ece_tp_location_code        => l_ece_tp_location_code,
709       p_address_line_1              => p_address_line_1,
710       p_address_line_2              => p_address_line_2,
711       p_address_line_3              => p_address_line_3,
712       p_bill_to_site_flag           => l_bill_to_site_flag,
713       p_country                     => p_country,
714       p_designated_receiver_id      => l_designated_receiver_id,
715       p_in_organization_flag        => l_in_organization_flag,
716       p_inactive_date               => l_inactive_date,
717       p_operating_unit_id           => l_operating_unit_id,
718       p_inventory_organization_id   => l_inventory_organization_id,
719       p_office_site_flag            => l_office_site_flag,
720       p_postal_code                 => p_postal_code,
721       p_receiving_site_flag         => l_receiving_site_flag,
722       p_region_1                    => p_region_1,
723       p_region_2                    => p_region_2,
724       p_region_3                    => p_region_3,
725       p_ship_to_location_id         => l_ship_to_location_id,
726       p_ship_to_site_flag           => l_ship_to_site_flag,
727       p_style                       => p_style,
728       p_tax_name                    => p_tax_name,
729       p_telephone_number_1          => p_telephone_number_1,
730       p_telephone_number_2          => p_telephone_number_2,
731       p_telephone_number_3          => p_telephone_number_3,
732       p_town_or_city                => p_town_or_city,
733       p_loc_information13           => p_loc_information13,
734       p_loc_information14           => p_loc_information14,
735       p_loc_information15           => p_loc_information15,
736       p_loc_information16           => p_loc_information16,
737       p_loc_information17           => p_loc_information17,
738       p_loc_information18           => p_loc_information18,
739       p_loc_information19           => p_loc_information19,
740       p_loc_information20           => p_loc_information20,
741       p_location_id                 => p_location_id,
742       p_object_version_number       => p_object_version_number,
743       p_attribute1                  => l_out_hr_loc_hook_rec.attribute1,
744       p_attribute2                  => l_out_hr_loc_hook_rec.attribute2,
745       p_attribute3                  => l_out_hr_loc_hook_rec.attribute3,
746       p_attribute4                  => l_out_hr_loc_hook_rec.attribute4,
747       p_attribute5                  => l_out_hr_loc_hook_rec.attribute5,
748       p_attribute6                  => l_out_hr_loc_hook_rec.attribute6,
749       p_attribute7                  => l_out_hr_loc_hook_rec.attribute7,
750       p_attribute8                  => l_out_hr_loc_hook_rec.attribute8,
751       p_attribute9                  => l_out_hr_loc_hook_rec.attribute9,
752       p_attribute10                  => l_out_hr_loc_hook_rec.attribute10,
753       p_attribute11                  => l_out_hr_loc_hook_rec.attribute11,
754       p_attribute12                  => l_out_hr_loc_hook_rec.attribute12,
755       p_attribute13                  => l_out_hr_loc_hook_rec.attribute13,
756       p_attribute14                  => l_out_hr_loc_hook_rec.attribute14,
757       p_attribute15                  => l_out_hr_loc_hook_rec.attribute15,
758       p_attribute16                  => l_out_hr_loc_hook_rec.attribute16,
759       p_attribute17                  => l_out_hr_loc_hook_rec.attribute17,
760       p_attribute18                  => l_out_hr_loc_hook_rec.attribute18,
761       p_attribute19                  => l_out_hr_loc_hook_rec.attribute19,
762       p_attribute20                  => l_out_hr_loc_hook_rec.attribute20,
763       p_attribute_category          => l_out_hr_loc_hook_rec.attribute_category
764    );
765 
766     if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
767        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
768                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
769                   'After calling hr_location_api.create_location...');
770        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
771                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
772                   'x_msg_count=' || x_msg_count || ', x_msg_data=' || x_msg_data);
773     end if;
774 
775    fnd_msg_pub.count_and_get
776       ( p_count => x_msg_count
777       , p_data  => x_msg_data);
778 
779     if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
780        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
781                   'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
782                   'x_msg_count=' || x_msg_count || ', x_msg_data=' || x_msg_data);
783     end if;
784 
785    -- Exception Block
786    EXCEPTION
787       WHEN EXCP_USER_DEFINED THEN
788 
789           if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
790              FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
791                         'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
792                         'In EXCP_USER_DEFINED block');
793           end if;
794 
795          Rollback to do_create_ship_to_location_PUB;
796          x_return_status := FND_API.G_RET_STS_ERROR;
797          JTF_PLSQL_API.HANDLE_EXCEPTIONS(
798             P_API_NAME => L_API_NAME
799            ,P_PKG_NAME => G_PKG_NAME
800            ,P_EXCEPTION_LEVEL => FND_MSG_PUB.G_MSG_LVL_ERROR
801            ,P_PACKAGE_TYPE => JTF_PLSQL_API.G_PUB
802            ,X_MSG_COUNT    => x_MSG_COUNT
803            ,X_MSG_DATA     => x_MSG_DATA
804            ,X_RETURN_STATUS => x_RETURN_STATUS);
805       WHEN FND_API.G_EXC_ERROR THEN
806 
807           if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
808              FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
809                         'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
810                         'In FND_API.G_EXC_ERROR block');
811           end if;
812 
813          JTF_PLSQL_API.HANDLE_EXCEPTIONS(
814             P_API_NAME => L_API_NAME
815            ,P_PKG_NAME => G_PKG_NAME
816            ,P_EXCEPTION_LEVEL => FND_MSG_PUB.G_MSG_LVL_ERROR
817            ,P_PACKAGE_TYPE => JTF_PLSQL_API.G_PUB
818            ,X_MSG_COUNT    => x_MSG_COUNT
819            ,X_MSG_DATA     => x_MSG_DATA
820            ,X_RETURN_STATUS => x_RETURN_STATUS);
821       WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
822 
823           if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
824              FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
825                         'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
826                         'In FND_API.G_EXC_UNEXPECTED_ERROR block');
827           end if;
828 
829          JTF_PLSQL_API.HANDLE_EXCEPTIONS(
830             P_API_NAME => L_API_NAME
831            ,P_PKG_NAME => G_PKG_NAME
832            ,P_EXCEPTION_LEVEL => FND_MSG_PUB.G_MSG_LVL_ERROR
833            ,P_PACKAGE_TYPE => JTF_PLSQL_API.G_PUB
834            ,X_MSG_COUNT    => x_MSG_COUNT
835            ,X_MSG_DATA     => x_MSG_DATA
836            ,X_RETURN_STATUS => x_RETURN_STATUS);
837       WHEN OTHERS THEN
838 
839           if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
840              FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
841                         'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
842                         'In OTHERS block');
843              FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
844                         'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.do_create_ship_to_location',
845                         'sqlerrm = ' || sqlerrm);
846           end if;
847 
848          Rollback to do_create_ship_to_location_PUB;
849          FND_MESSAGE.SET_NAME('CSP', 'CSP_UNEXPECTED_EXEC_ERRORS');
850          FND_MESSAGE.SET_TOKEN('ROUTINE', l_api_name, false);
851          FND_MESSAGE.SET_TOKEN('SQLERRM', sqlerrm, false);
852          FND_MSG_PUB.ADD;
853          fnd_msg_pub.count_and_get
854            ( p_count => x_msg_count
855            , p_data  => x_msg_data);
856          x_return_status := FND_API.G_RET_STS_ERROR;
857 
858 END do_create_ship_to_location;
859 
860 
861 --------------------------------------------------------------------------------
862 --
863 -- Procedure Name   : do_update_ship_to_location
864 -- Purpose          : It updates the address fields based on the location id
865 --                    passed in.
866 --
867 PROCEDURE do_update_ship_to_location
868    (p_location_id            IN NUMBER
869    ,p_style                  IN VARCHAR2
870    ,p_address_line_1         IN VARCHAR2
871    ,p_address_line_2         IN VARCHAR2
872    ,p_address_line_3         IN VARCHAR2
873    ,p_country                IN VARCHAR2
874    ,p_postal_code            IN VARCHAR2
875    ,p_region_1               IN VARCHAR2
876    ,p_region_2               IN VARCHAR2
877    ,p_region_3               IN VARCHAR2
878    ,p_town_or_city           IN VARCHAR2
879    ,p_tax_name               IN VARCHAR2
880    ,p_telephone_number_1     IN VARCHAR2
881    ,p_telephone_number_2     IN VARCHAR2
882    ,p_telephone_number_3     IN VARCHAR2
883    ,p_loc_information13      IN VARCHAR2
884    ,p_loc_information14      IN VARCHAR2
885    ,p_loc_information15      IN VARCHAR2
886    ,p_loc_information16      IN VARCHAR2
887    ,p_loc_information17      IN VARCHAR2
888    ,p_loc_information18      IN VARCHAR2
889    ,p_loc_information19      IN VARCHAR2
890    ,p_loc_information20      IN VARCHAR2
891    ,p_attribute_category     IN VARCHAR2
892    ,p_attribute1             IN VARCHAR2
893    ,p_attribute2             IN VARCHAR2
894    ,p_attribute3             IN VARCHAR2
895    ,p_attribute4             IN VARCHAR2
896    ,p_attribute5             IN VARCHAR2
897    ,p_attribute6             IN VARCHAR2
898    ,p_attribute7             IN VARCHAR2
899    ,p_attribute8             IN VARCHAR2
900    ,p_attribute9             IN VARCHAR2
901    ,p_attribute10             IN VARCHAR2
902    ,p_attribute11             IN VARCHAR2
903    ,p_attribute12             IN VARCHAR2
904    ,p_attribute13            IN VARCHAR2
905    ,p_attribute14             IN VARCHAR2
906    ,p_attribute15             IN VARCHAR2
907    ,p_attribute16             IN VARCHAR2
908    ,p_attribute17             IN VARCHAR2
909    ,p_attribute18             IN VARCHAR2
910    ,p_attribute19             IN VARCHAR2
911    ,p_attribute20             IN VARCHAR2
912    ,p_object_version_number  IN OUT NOCOPY NUMBER
913    ,x_return_status          OUT NOCOPY VARCHAR2
914    ,x_msg_count              OUT NOCOPY NUMBER
915    ,x_msg_data               OUT NOCOPY VARCHAR2 ) IS
916 
917    l_api_version_number         CONSTANT NUMBER := 1.0;
918    l_api_name                   CONSTANT VARCHAR2(30) := 'do_update_ship_to_location';
919    l_language                   VARCHAR2(4);
920    EXCP_USER_DEFINED            EXCEPTION;
921 
922    l_object_version_number      hr_locations_all.object_version_number%TYPE := NULL;
923 
924 BEGIN
925      SAVEPOINT do_update_ship_to_location_PUB;
926 
927    -- initialize
928    x_return_status := FND_API.G_RET_STS_SUCCESS;
929    select userenv('LANG') into l_language from dual;
930 
931 /*   OPEN l_inv_location_csr;
932    FETCH l_inv_location_csr INTO
933 l_location_code,
934 l_tp_header_id,
935 l_ece_tp_location_code,
936 l_bill_to_site_flag,
937 l_designated_receiver_id,
938 l_in_organization_flag,
939 l_inactive_date,
940 l_inventory_organization_id,
941 l_office_site_flag,
942 l_receiving_site_flag,
943 l_ship_to_location_id,
944 l_ship_to_site_flag,
945 l_attribute_category,
946 l_attribute1,
947 l_attribute2,
948 l_attribute3,
949 l_attribute4,
950 l_attribute5,
951 l_attribute6,
952 l_attribute7,
953 l_attribute8,
954 l_attribute9,
955 l_attribute10,
956 l_attribute11,
957 l_attribute12,
958 l_attribute13,
959 l_attribute14,
960 l_attribute15,
961 l_attribute16,
962 l_attribute17,
963 l_attribute18,
964 l_attribute19,
965 l_attribute20,
966 l_global_attribute_category,
967 l_global_attribute1,
968 l_global_attribute2,
969 l_global_attribute3,
970 l_global_attribute4,
971 l_global_attribute5,
972 l_global_attribute6,
973 l_global_attribute7,
974 l_global_attribute8,
975 l_global_attribute9,
976 l_global_attribute10,
977 l_global_attribute11,
978 l_global_attribute12,
979 l_global_attribute13,
980 l_global_attribute14,
981 l_global_attribute15,
982 l_global_attribute16,
983 l_global_attribute17,
984 l_global_attribute18,
985 l_global_attribute19,
986 l_global_attribute20,
987 l_object_version_number;
988    IF l_inv_location_csr%NOTFOUND THEN
989       CLOSE l_inv_location_csr;
990       FND_MESSAGE.SET_NAME ('CSP', 'CSP_INV_LOC_NOT_FOUND');
991       FND_MESSAGE.SET_TOKEN('TSK_ASSGN_ID', p_location_id, TRUE);
992       FND_MSG_PUB.ADD;
993       RAISE EXCP_USER_DEFINED;
994    END IF;
995    CLOSE l_inv_location_csr;
996 
997    -- Default location description to address 1.
998    l_description := p_address_line_1;
999 */
1000    l_object_version_number := p_object_version_number;
1001 
1002    hr_location_api.update_location
1003      (p_validate                    => false,
1004       p_effective_date              => sysdate,
1005 --      p_language_code               => l_language,
1006       p_location_id                 => p_location_id,
1007 --      p_location_code               => l_location_code,
1008       p_description                 => p_address_line_1,
1009 --      p_tp_header_id                => l_tp_header_id,
1010 --      p_ece_tp_location_code        => l_ece_tp_location_code,
1011       p_address_line_1              => p_address_line_1,
1012       p_address_line_2              => p_address_line_2,
1013       p_address_line_3              => p_address_line_3,
1014 --      p_bill_to_site_flag           => l_bill_to_site_flag,
1015       p_country                     => p_country,
1016 --      p_designated_receiver_id      => l_designated_receiver_id,
1017 --      p_in_organization_flag        => l_in_organization_flag,
1018 --      p_inactive_date               => l_inactive_date,
1019 --      p_operating_unit_id           => l_operating_unit_id,
1020 --      p_inventory_organization_id   => l_inventory_organization_id,
1021 --      p_office_site_flag            => l_office_site_flag,
1022       p_postal_code                 => p_postal_code,
1023 --      p_receiving_site_flag         => l_receiving_site_flag,
1024       p_region_1                    => p_region_1,
1025       p_region_2                    => p_region_2,
1026       p_region_3                    => p_region_3,
1027 --      p_ship_to_location_id         => l_ship_to_location_id,
1028 --      p_ship_to_site_flag           => l_ship_to_site_flag,
1029       p_style                       => p_style,
1030       p_tax_name                    => p_tax_name,
1031       p_telephone_number_1          => p_telephone_number_1,
1032       p_telephone_number_2          => p_telephone_number_2,
1033       p_telephone_number_3          => p_telephone_number_3,
1034       p_town_or_city                => p_town_or_city,
1035       p_loc_information13           => p_loc_information13,
1036       p_loc_information14           => p_loc_information14,
1037       p_loc_information15           => p_loc_information15,
1038       p_loc_information16           => p_loc_information16,
1039       p_loc_information17           => p_loc_information17,
1040       p_loc_information18           => p_loc_information18,
1041       p_loc_information19           => p_loc_information19,
1042       p_loc_information20           => p_loc_information20,
1043       p_object_version_number       => l_object_version_number,
1044       p_attribute1                  => p_attribute1,
1045       p_attribute2                  => p_attribute2,
1046       p_attribute3                  => p_attribute3,
1047       p_attribute4                  => p_attribute4,
1048       p_attribute5                  => p_attribute5,
1049       p_attribute6                  => p_attribute6,
1050       p_attribute7                  => p_attribute7,
1051       p_attribute8                  => p_attribute8,
1052       p_attribute9                  => p_attribute9,
1053       p_attribute10                  => p_attribute10,
1054       p_attribute11                  => p_attribute11,
1055       p_attribute12                  => p_attribute12,
1056       p_attribute13                  => p_attribute13,
1057       p_attribute14                  => p_attribute14,
1058       p_attribute15                  => p_attribute15,
1059       p_attribute16                  => p_attribute16,
1060       p_attribute17                  => p_attribute17,
1061       p_attribute18                  => p_attribute18,
1062       p_attribute19                  => p_attribute19,
1063       p_attribute20                  => p_attribute20,
1064       p_attribute_category          => p_attribute_category
1065    );
1066 
1067    p_object_version_number := l_object_version_number;
1068    fnd_msg_pub.count_and_get
1069       ( p_count => x_msg_count
1070       , p_data  => x_msg_data);
1071 
1072    -- Exception Block
1073    EXCEPTION
1074       WHEN EXCP_USER_DEFINED THEN
1075          Rollback to do_update_ship_to_location_PUB;
1076          x_return_status := FND_API.G_RET_STS_ERROR;
1077          JTF_PLSQL_API.HANDLE_EXCEPTIONS(
1078             P_API_NAME => L_API_NAME
1079            ,P_PKG_NAME => G_PKG_NAME
1080            ,P_EXCEPTION_LEVEL => FND_MSG_PUB.G_MSG_LVL_ERROR
1081            ,P_PACKAGE_TYPE => JTF_PLSQL_API.G_PUB
1082            ,X_MSG_COUNT    => x_MSG_COUNT
1083            ,X_MSG_DATA     => x_MSG_DATA
1084            ,X_RETURN_STATUS => x_RETURN_STATUS);
1085       WHEN FND_API.G_EXC_ERROR THEN
1086          JTF_PLSQL_API.HANDLE_EXCEPTIONS(
1087             P_API_NAME => L_API_NAME
1088            ,P_PKG_NAME => G_PKG_NAME
1089            ,P_EXCEPTION_LEVEL => FND_MSG_PUB.G_MSG_LVL_ERROR
1090            ,P_PACKAGE_TYPE => JTF_PLSQL_API.G_PUB
1091            ,X_MSG_COUNT    => x_MSG_COUNT
1092            ,X_MSG_DATA     => x_MSG_DATA
1093            ,X_RETURN_STATUS => x_RETURN_STATUS);
1094       WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1095          JTF_PLSQL_API.HANDLE_EXCEPTIONS(
1096             P_API_NAME => L_API_NAME
1097            ,P_PKG_NAME => G_PKG_NAME
1098            ,P_EXCEPTION_LEVEL => FND_MSG_PUB.G_MSG_LVL_ERROR
1099            ,P_PACKAGE_TYPE => JTF_PLSQL_API.G_PUB
1100            ,X_MSG_COUNT    => x_MSG_COUNT
1101            ,X_MSG_DATA     => x_MSG_DATA
1102            ,X_RETURN_STATUS => x_RETURN_STATUS);
1103       WHEN OTHERS THEN
1104          Rollback to do_update_ship_to_location_PUB;
1105          FND_MESSAGE.SET_NAME('CSP', 'CSP_UNEXPECTED_EXEC_ERRORS');
1106          FND_MESSAGE.SET_TOKEN('ROUTINE', l_api_name, false);
1107          FND_MESSAGE.SET_TOKEN('SQLERRM', sqlerrm, false);
1108          FND_MSG_PUB.ADD;
1109          fnd_msg_pub.count_and_get
1110            ( p_count => x_msg_count
1111            , p_data  => x_msg_data);
1112          x_return_status := FND_API.G_RET_STS_ERROR;
1113 
1114 END do_update_ship_to_location;
1115 
1116 
1117 
1118 ------------------------------------------------------------------------------------------
1119 -- Procedure Name   : do_create_site_use
1120 -- Purpose          : It will create a ship to site use that link to
1121 --                    an inventory location.
1122 --
1123 PROCEDURE do_create_site_use
1124    (p_customer_id            IN NUMBER
1125    ,p_party_id               IN NUMBER
1126    ,p_address_id             IN NUMBER
1127    ,p_location_id            IN NUMBER
1128    ,p_inv_location_id        IN NUMBER
1129    ,p_primary_flag           IN VARCHAR2
1130    ,p_status                 IN VARCHAR2
1131    ,p_bill_to_create		  IN VARCHAR2 := 'Y'
1132    ,x_return_status          OUT NOCOPY VARCHAR2
1133    ,x_msg_count              OUT NOCOPY NUMBER
1134    ,x_msg_data               OUT NOCOPY VARCHAR2 ) IS
1135 
1136    l_api_version_number      CONSTANT NUMBER := 1.0;
1137    l_api_name                CONSTANT VARCHAR2(30) := 'do_create_site_use';
1138    l_language                VARCHAR2(4);
1139    EXCP_USER_DEFINED         EXCEPTION;
1140 
1141    s_location_id             hr_locations.location_id%TYPE := p_location_id;
1142    s_site_use_id             hz_cust_site_uses_all.site_use_id%TYPE := NULL;
1143    b_site_use_id             hz_cust_site_uses_all.site_use_id%TYPE := NULL;
1144    s_primary_flag            hz_cust_site_uses_all.primary_flag%TYPE := NULL;
1145    s_status                  hz_cust_site_uses_all.status%TYPE := NULL;
1146 
1147    CURSOR l_primary_party_site_use_csr IS
1148       select primary_per_type
1149 from hz_party_site_uses
1150 where site_use_type = 'SHIP_TO'
1151 and primary_per_type = 'Y'
1152 and (party_site_id in
1153 (select party_site_id
1154 from hz_party_sites where party_id = p_party_id and status = 'A'));
1155 
1156 cursor cr_get_primary_bill_to_id (v_address_id number) is
1157 select site_use_id
1158 from HZ_CUST_SITE_USES
1159 where cust_acct_site_id in (
1160   select hsc1.cust_acct_site_id
1161   from hz_cust_acct_sites hsc1, hz_cust_acct_sites hsc2
1162   where hsc1.cust_account_id = hsc2.cust_account_id
1163   and hsc2.cust_acct_site_id = v_address_id
1164   and hsc1.cust_acct_site_id <> v_address_id
1165 )
1166 and primary_flag = 'Y'
1167 and status = 'A';
1168 
1169 BEGIN
1170    SAVEPOINT do_create_site_use_PUB;
1171 
1172    IF p_primary_flag IS NULL THEN
1173       -- Check if there is an existing primary ship to party site use
1174       -- Set the primary_per_type to 'Y' only if there is no existing one
1175       OPEN l_primary_party_site_use_csr;
1176       FETCH l_primary_party_site_use_csr INTO s_primary_flag;
1177       IF l_primary_party_site_use_csr%NOTFOUND THEN
1178          CLOSE l_primary_party_site_use_csr;
1179          s_primary_flag := 'Y';
1180       ELSE
1181          CLOSE l_primary_party_site_use_csr;
1182          s_primary_flag := 'N';
1183       END IF;
1184    ELSE
1185       s_primary_flag := p_primary_flag;
1186    END IF;
1187 
1188    IF p_status IS NULL THEN
1189       s_status := 'A';
1190    ELSE
1191       s_status := p_status;
1192    END IF;
1193 
1194    s_location_id := null;
1195 
1196    -- Create Bill To site use first for billing purpose.
1197    b_site_use_id := null;
1198    if nvl(p_bill_to_create, 'Y') <> 'Y' then
1199 		open cr_get_primary_bill_to_id(p_address_id);
1200 		fetch cr_get_primary_bill_to_id into b_site_use_id;
1201 		close cr_get_primary_bill_to_id;
1202    end if;
1203 
1204    if b_site_use_id is null then
1205    arh_csu_pkg.Insert_Row(
1206          X_Site_Use_Id                  => b_site_use_id,
1207          X_Last_Update_Date             => sysdate,
1208          X_Last_Updated_By              => nvl(fnd_global.user_id,1),
1209          X_Creation_Date                => sysdate,
1210          X_Created_By                   => nvl(fnd_global.user_id,1),
1211          X_Site_Use_Code                => 'BILL_TO',
1212          x_customer_id	                => p_customer_id,
1213          X_Address_Id                   => p_address_id,
1214          X_Primary_Flag                 => 'N',
1215          X_Status                       => 'A',
1216          X_Location                     => s_location_id,
1217          X_Last_Update_Login            => nvl(fnd_global.user_id,1),
1218          X_Contact_Id                   => null,
1219          X_Bill_To_Site_Use_Id          => null,
1220          X_Sic_Code                     => null,
1221          X_Payment_Term_Id              => null,
1222          X_Gsa_Indicator                => 'N',
1223          X_Ship_Partial                 => 'N',
1224          X_Ship_Via                     => null,
1225          X_Fob_Point                    => null,
1226          X_Order_Type_Id                => null,
1227          X_Price_List_Id                => null,
1228          X_Freight_Term                 => null,
1229          X_Warehouse_Id                 => null,
1230          X_Territory_Id                 => null,
1231          X_Tax_Code                     => null,
1232          X_Tax_Reference                => null,
1233          X_Demand_Class_Code            => null,
1234          x_inventory_location_id        => null,
1235          x_inventory_organization_id    => null,
1236          X_Attribute_Category           => null,
1237          X_Attribute1                   => null,
1238          X_Attribute2                   => null,
1239          X_Attribute3                   => null,
1240          X_Attribute4                   => null,
1241          X_Attribute5                   => null,
1242          X_Attribute6                   => null,
1243          X_Attribute7                   => null,
1244          X_Attribute8                   => null,
1245          X_Attribute9                   => null,
1246          X_Attribute10                  => null,
1247          X_Attribute11                  => null,
1248          X_Attribute12                  => null,
1249          X_Attribute13                  => null,
1250          X_Attribute14                  => null,
1251          X_Attribute15                  => null,
1252          X_Attribute16                  => null,
1253          X_Attribute17                  => null,
1254          X_Attribute18                  => null,
1255          X_Attribute19                  => null,
1256          X_Attribute20                  => null,
1257          X_Attribute21                  => null,
1258          X_Attribute22                  => null,
1259          X_Attribute23                  => null,
1260          X_Attribute24                  => null,
1261          X_Attribute25                  => null,
1262          X_Tax_Classification           => null,
1263          X_Tax_Header_Level_Flag        => null,
1264          X_Tax_Rounding_Rule            => null,
1265          X_Global_Attribute_Category    => null,
1266          X_Global_Attribute1            => null,
1267          X_Global_Attribute2            => null,
1268          X_Global_Attribute3            => null,
1269          X_Global_Attribute4            => null,
1270          X_Global_Attribute5            => null,
1271          X_Global_Attribute6            => null,
1272          X_Global_Attribute7            => null,
1273          X_Global_Attribute8            => null,
1274          X_Global_Attribute9            => null,
1275          X_Global_Attribute10           => null,
1276          X_Global_Attribute11           => null,
1277          X_Global_Attribute12           => null,
1278          X_Global_Attribute13           => null,
1279          X_Global_Attribute14           => null,
1280          X_Global_Attribute15           => null,
1281          X_Global_Attribute16           => null,
1282          X_Global_Attribute17           => null,
1283          X_Global_Attribute18           => null,
1284          X_Global_Attribute19           => null,
1285          X_Global_Attribute20           => null,
1286          X_Primary_Salesrep_Id          => null,
1287          X_Finchrg_Receivables_Trx_Id   => null,
1288          X_GL_ID_Rec                    => null,
1289          X_GL_ID_Rev                    => null,
1290          X_GL_ID_Tax                    => null,
1291          X_GL_ID_Freight                => null,
1292          X_GL_ID_Clearing               => null,
1293          X_GL_ID_Unbilled               => null,
1294          X_GL_ID_Unearned               => null,
1295          X_GL_ID_Unpaid_rec             => null,
1296          X_GL_ID_remittance             => null,
1297          X_GL_ID_factor                 => null,
1298          X_DATES_NEGATIVE_TOLERANCE     => null,
1299          X_DATES_POSITIVE_TOLERANCE     => null,
1300          X_DATE_TYPE_PREFERENCE         => null,
1301          X_OVER_SHIPMENT_TOLERANCE      => null,
1302          X_UNDER_SHIPMENT_TOLERANCE     => null,
1303          X_ITEM_CROSS_REF_PREF          => null,
1304          X_OVER_RETURN_TOLERANCE        => null,
1305          X_UNDER_RETURN_TOLERANCE       => null,
1306          X_SHIP_SETS_INCLUDE_LINES_FLAG => 'N',
1307          X_ARRIVALSETS_INCL_LINES_FLAG  => 'N',
1308          X_SCHED_DATE_PUSH_FLAG         => 'N',
1309          X_INVOICE_QUANTITY_RULE        => null,
1310          x_msg_count                    => x_msg_count,
1311          x_msg_data                     => x_msg_data,
1312          x_return_status                => x_return_status);
1313 
1314       IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1315          Rollback to do_create_site_use_PUB;
1316          /*FND_MESSAGE.SET_NAME ('CSP', 'CSP_SITE_USE_API_ERROR');
1317          FND_MESSAGE.SET_TOKEN ('TEXT', x_msg_data);
1318          FND_MSG_PUB.ADD;*/
1319          RAISE EXCP_USER_DEFINED;
1320       END IF;
1321      END IF;
1322       s_location_id := null;
1323 
1324    -- Create Ship To site use to link to the inventory location and link the bill to location to the bill to site.
1325    arh_csu_pkg.Insert_Row(
1326          X_Site_Use_Id                  => s_site_use_id,
1327          X_Last_Update_Date             => sysdate,
1328          X_Last_Updated_By              => nvl(fnd_global.user_id,1),
1329          X_Creation_Date                => sysdate,
1330          X_Created_By                   => nvl(fnd_global.user_id,1),
1331          X_Site_Use_Code                => 'SHIP_TO',
1332          x_customer_id	                => p_customer_id,
1333          X_Address_Id                   => p_address_id,
1334          X_Primary_Flag                 => s_primary_flag,
1335          X_Status                       => s_status,
1336          X_Location                     => s_location_id,
1337          X_Last_Update_Login            => nvl(fnd_global.user_id,1),
1338          X_Contact_Id                   => null,
1339 --         X_Bill_To_Site_Use_Id          => null,
1340          X_Bill_To_Site_Use_Id          => b_site_use_id,
1341          X_Sic_Code                     => null,
1342          X_Payment_Term_Id              => null,
1343          X_Gsa_Indicator                => 'N',
1344          X_Ship_Partial                 => 'N',
1345          X_Ship_Via                     => null,
1346          X_Fob_Point                    => null,
1347          X_Order_Type_Id                => null,
1348          X_Price_List_Id                => null,
1349          X_Freight_Term                 => null,
1350          X_Warehouse_Id                 => null,
1351          X_Territory_Id                 => null,
1352          X_Tax_Code                     => null,
1353          X_Tax_Reference                => null,
1354          X_Demand_Class_Code            => null,
1355          x_inventory_location_id        => p_inv_location_id,
1356          x_inventory_organization_id    => null,
1357          X_Attribute_Category           => null,
1358          X_Attribute1                   => null,
1359          X_Attribute2                   => null,
1360          X_Attribute3                   => null,
1361          X_Attribute4                   => null,
1362          X_Attribute5                   => null,
1363          X_Attribute6                   => null,
1364          X_Attribute7                   => null,
1365          X_Attribute8                   => null,
1366          X_Attribute9                   => null,
1367          X_Attribute10                  => null,
1368          X_Attribute11                  => null,
1369          X_Attribute12                  => null,
1370          X_Attribute13                  => null,
1371          X_Attribute14                  => null,
1372          X_Attribute15                  => null,
1373          X_Attribute16                  => null,
1374          X_Attribute17                  => null,
1375          X_Attribute18                  => null,
1376          X_Attribute19                  => null,
1377          X_Attribute20                  => null,
1378          X_Attribute21                  => null,
1379          X_Attribute22                  => null,
1380          X_Attribute23                  => null,
1381          X_Attribute24                  => null,
1382          X_Attribute25                  => null,
1383          X_Tax_Classification           => null,
1384          X_Tax_Header_Level_Flag        => null,
1385          X_Tax_Rounding_Rule            => null,
1386          X_Global_Attribute_Category    => null,
1387          X_Global_Attribute1            => null,
1388          X_Global_Attribute2            => null,
1389          X_Global_Attribute3            => null,
1390          X_Global_Attribute4            => null,
1391          X_Global_Attribute5            => null,
1392          X_Global_Attribute6            => null,
1393          X_Global_Attribute7            => null,
1394          X_Global_Attribute8            => null,
1395          X_Global_Attribute9            => null,
1396          X_Global_Attribute10           => null,
1397          X_Global_Attribute11           => null,
1398          X_Global_Attribute12           => null,
1399          X_Global_Attribute13           => null,
1400          X_Global_Attribute14           => null,
1401          X_Global_Attribute15           => null,
1402          X_Global_Attribute16           => null,
1403          X_Global_Attribute17           => null,
1404          X_Global_Attribute18           => null,
1405          X_Global_Attribute19           => null,
1406          X_Global_Attribute20           => null,
1407          X_Primary_Salesrep_Id          => null,
1408          X_Finchrg_Receivables_Trx_Id   => null,
1409          X_GL_ID_Rec                    => null,
1410          X_GL_ID_Rev                    => null,
1411          X_GL_ID_Tax                    => null,
1412          X_GL_ID_Freight                => null,
1413          X_GL_ID_Clearing               => null,
1414          X_GL_ID_Unbilled               => null,
1415          X_GL_ID_Unearned               => null,
1416          X_GL_ID_Unpaid_rec             => null,
1417          X_GL_ID_remittance             => null,
1418          X_GL_ID_factor                 => null,
1419          X_DATES_NEGATIVE_TOLERANCE     => null,
1420          X_DATES_POSITIVE_TOLERANCE     => null,
1421          X_DATE_TYPE_PREFERENCE         => null,
1422          X_OVER_SHIPMENT_TOLERANCE      => null,
1423          X_UNDER_SHIPMENT_TOLERANCE     => null,
1424          X_ITEM_CROSS_REF_PREF          => null,
1425          X_OVER_RETURN_TOLERANCE        => null,
1426          X_UNDER_RETURN_TOLERANCE       => null,
1427          X_SHIP_SETS_INCLUDE_LINES_FLAG => 'N',
1428          X_ARRIVALSETS_INCL_LINES_FLAG  => 'N',
1429          X_SCHED_DATE_PUSH_FLAG         => 'N',
1430          X_INVOICE_QUANTITY_RULE        => null,
1431          x_msg_count                    => x_msg_count,
1432          x_msg_data                     => x_msg_data,
1433          x_return_status                => x_return_status);
1434 
1435       IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1436          Rollback to do_create_site_use_PUB;
1437         /*FND_MESSAGE.SET_NAME ('CSP', 'CSP_SITE_USE_API_ERROR');
1438          FND_MESSAGE.SET_TOKEN ('TEXT', x_msg_data);
1439          FND_MSG_PUB.ADD;*/
1440          RAISE EXCP_USER_DEFINED;
1441       END IF;
1442 
1443    -- Exception Block
1444    EXCEPTION
1445       WHEN EXCP_USER_DEFINED THEN
1446          Rollback to do_create_site_use_PUB;
1447          x_return_status := FND_API.G_RET_STS_ERROR;
1448          JTF_PLSQL_API.HANDLE_EXCEPTIONS(
1449             P_API_NAME => L_API_NAME
1450            ,P_PKG_NAME => G_PKG_NAME
1451            ,P_EXCEPTION_LEVEL => FND_MSG_PUB.G_MSG_LVL_ERROR
1452            ,P_PACKAGE_TYPE => JTF_PLSQL_API.G_PUB
1453            ,X_MSG_COUNT    => x_MSG_COUNT
1454            ,X_MSG_DATA     => x_MSG_DATA
1455            ,X_RETURN_STATUS => x_RETURN_STATUS);
1456       WHEN FND_API.G_EXC_ERROR THEN
1457          JTF_PLSQL_API.HANDLE_EXCEPTIONS(
1458             P_API_NAME => L_API_NAME
1459            ,P_PKG_NAME => G_PKG_NAME
1460            ,P_EXCEPTION_LEVEL => FND_MSG_PUB.G_MSG_LVL_ERROR
1461            ,P_PACKAGE_TYPE => JTF_PLSQL_API.G_PUB
1462            ,X_MSG_COUNT    => x_MSG_COUNT
1463            ,X_MSG_DATA     => x_MSG_DATA
1464            ,X_RETURN_STATUS => x_RETURN_STATUS);
1465       WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1466          JTF_PLSQL_API.HANDLE_EXCEPTIONS(
1467             P_API_NAME => L_API_NAME
1468            ,P_PKG_NAME => G_PKG_NAME
1469            ,P_EXCEPTION_LEVEL => FND_MSG_PUB.G_MSG_LVL_ERROR
1470            ,P_PACKAGE_TYPE => JTF_PLSQL_API.G_PUB
1471            ,X_MSG_COUNT    => x_MSG_COUNT
1472            ,X_MSG_DATA     => x_MSG_DATA
1473            ,X_RETURN_STATUS => x_RETURN_STATUS);
1474       WHEN OTHERS THEN
1475          Rollback to do_create_site_use_PUB;
1476          FND_MESSAGE.SET_NAME('CSP', 'CSP_UNEXPECTED_EXEC_ERRORS');
1477          FND_MESSAGE.SET_TOKEN('ROUTINE', l_api_name, false);
1478          FND_MESSAGE.SET_TOKEN('SQLERRM', sqlerrm, false);
1479          FND_MSG_PUB.ADD;
1480          fnd_msg_pub.count_and_get
1481            ( p_count => x_msg_count
1482            , p_data  => x_msg_data);
1483          x_return_status := FND_API.G_RET_STS_ERROR;
1484 
1485 END do_create_site_use;
1486 
1487 
1488 
1489 ------------------------------------------------------------------------------------------
1490 -- Procedure Name   : do_update_site_use
1491 -- Purpose          : It will update a ship to site use that link to
1492 --                    an inventory location.
1493 --
1494 ------------------------------------------------------------------------------------------
1495 -- Procedure Name   : do_update_site_use
1496 -- Purpose          : It will update a ship to site use that link to
1497 --                    an inventory location.
1498 --
1499 PROCEDURE do_update_site_use
1500    (p_site_use_id            IN NUMBER
1501    ,p_primary_flag           IN VARCHAR2
1502    ,p_status                 IN VARCHAR2
1503    ,p_customer_id            IN NUMBER
1504    ,p_inv_location_id        IN NUMBER
1505    ,x_return_status          OUT NOCOPY VARCHAR2
1506    ,x_msg_count              OUT NOCOPY NUMBER
1507    ,x_msg_data               OUT NOCOPY VARCHAR2 ) IS
1508 
1509    l_api_version_number      CONSTANT NUMBER := 1.0;
1510    l_api_name                CONSTANT VARCHAR2(30) := 'do_update_site_use';
1511    l_language                VARCHAR2(4);
1512    EXCP_USER_DEFINED         EXCEPTION;
1513 
1514    l_site_use_id                    hz_cust_site_uses_all.site_use_id%TYPE;
1515    s_cust_acct_site_id              hz_cust_site_uses_all.cust_acct_site_id%TYPE;
1516    s_creation_date                  hz_cust_site_uses_all.creation_date%TYPE;
1517    s_created_by                     hz_cust_site_uses_all.created_by%TYPE;
1518    s_site_use_code                  hz_cust_site_uses_all.site_use_code%TYPE;
1519    s_primary_flag                   hz_cust_site_uses_all.primary_flag%TYPE;
1520    s_status                         hz_cust_site_uses_all.status%TYPE;
1521    s_location                       hz_cust_site_uses_all.location%TYPE;
1522    s_last_update_login              hz_cust_site_uses_all.last_update_login%TYPE;
1523    s_contact_id                     hz_cust_site_uses_all.contact_id%TYPE;
1524    s_bill_to_site_use_id            hz_cust_site_uses_all.bill_to_site_use_id%TYPE;
1525    s_orig_system_reference          hz_cust_site_uses_all.orig_system_reference%TYPE;
1526    s_sic_code                       hz_cust_site_uses_all.sic_code%TYPE;
1527    s_payment_term_id                hz_cust_site_uses_all.payment_term_id%TYPE;
1528    s_gsa_indicator                  hz_cust_site_uses_all.gsa_indicator%TYPE;
1529    s_ship_partial                   hz_cust_site_uses_all.ship_partial%TYPE;
1530    s_ship_via                       hz_cust_site_uses_all.ship_via%TYPE;
1531    s_fob_point                      hz_cust_site_uses_all.fob_point%TYPE;
1532    s_order_type_id                  hz_cust_site_uses_all.order_type_id%TYPE;
1533    s_price_list_id                  hz_cust_site_uses_all.price_list_id%TYPE;
1534    s_freight_term                   hz_cust_site_uses_all.freight_term%TYPE;
1535    s_warehouse_id                   hz_cust_site_uses_all.warehouse_id%TYPE;
1536    s_territory_id                   hz_cust_site_uses_all.territory_id%TYPE;
1537    s_attribute_category             hz_cust_site_uses_all.attribute_category%TYPE;
1538    s_attribute1                     hz_cust_site_uses_all.attribute1%TYPE;
1539    s_attribute2                     hz_cust_site_uses_all.attribute2%TYPE;
1540    s_attribute3                     hz_cust_site_uses_all.attribute3%TYPE;
1541    s_attribute4                     hz_cust_site_uses_all.attribute4%TYPE;
1542    s_attribute5                     hz_cust_site_uses_all.attribute5%TYPE;
1543    s_attribute6                     hz_cust_site_uses_all.attribute6%TYPE;
1544    s_attribute7                     hz_cust_site_uses_all.attribute7%TYPE;
1545    s_attribute8                     hz_cust_site_uses_all.attribute8%TYPE;
1546    s_attribute9                     hz_cust_site_uses_all.attribute9%TYPE;
1547    s_attribute10                    hz_cust_site_uses_all.attribute10%TYPE;
1548    s_request_id                     hz_cust_site_uses_all.request_id%TYPE;
1549    s_program_application_id         hz_cust_site_uses_all.program_application_id%TYPE;
1550    s_program_id                     hz_cust_site_uses_all.program_id%TYPE;
1551    s_program_update_date            hz_cust_site_uses_all.program_update_date%TYPE;
1552    s_tax_reference                  hz_cust_site_uses_all.tax_reference%TYPE;
1553    s_sort_priority                  hz_cust_site_uses_all.sort_priority%TYPE;
1554    s_tax_code                       hz_cust_site_uses_all.tax_code%TYPE;
1555    s_attribute11                    hz_cust_site_uses_all.attribute11%TYPE;
1556    s_attribute12                    hz_cust_site_uses_all.attribute12%TYPE;
1557    s_attribute13                    hz_cust_site_uses_all.attribute13%TYPE;
1558    s_attribute14                    hz_cust_site_uses_all.attribute14%TYPE;
1559    s_attribute15                    hz_cust_site_uses_all.attribute15%TYPE;
1560    s_attribute16                    hz_cust_site_uses_all.attribute16%TYPE;
1561    s_attribute17                    hz_cust_site_uses_all.attribute17%TYPE;
1562    s_attribute18                    hz_cust_site_uses_all.attribute18%TYPE;
1563    s_attribute19                    hz_cust_site_uses_all.attribute19%TYPE;
1564    s_attribute20                    hz_cust_site_uses_all.attribute20%TYPE;
1565    s_attribute21                    hz_cust_site_uses_all.attribute21%TYPE;
1566    s_attribute22                    hz_cust_site_uses_all.attribute22%TYPE;
1567    s_attribute23                    hz_cust_site_uses_all.attribute23%TYPE;
1568    s_attribute24                    hz_cust_site_uses_all.attribute24%TYPE;
1569    s_attribute25                    hz_cust_site_uses_all.attribute25%TYPE;
1570    s_last_accrue_charge_date        DATE;
1571    s_snd_last_accrue_charge_date    DATE;
1572    s_last_unaccrue_charge_date      DATE;
1573    s_snd_last_unaccrue_chrg_date    DATE;
1574    s_demand_class_code              hz_cust_site_uses_all.demand_class_code%TYPE;
1575    s_org_id                         hz_cust_site_uses_all.org_id%TYPE;
1576    s_tax_header_level_flag          hz_cust_site_uses_all.tax_header_level_flag%TYPE;
1577    s_tax_rounding_rule              hz_cust_site_uses_all.tax_rounding_rule%TYPE;
1578    s_wh_update_date                 hz_cust_site_uses_all.wh_update_date%TYPE;
1579    s_global_attribute1              hz_cust_site_uses_all.global_attribute1%TYPE;
1580    s_global_attribute2              hz_cust_site_uses_all.global_attribute2%TYPE;
1581    s_global_attribute3              hz_cust_site_uses_all.global_attribute3%TYPE;
1582    s_global_attribute4              hz_cust_site_uses_all.global_attribute4%TYPE;
1583    s_global_attribute5              hz_cust_site_uses_all.global_attribute5%TYPE;
1584    s_global_attribute6              hz_cust_site_uses_all.global_attribute6%TYPE;
1585    s_global_attribute7              hz_cust_site_uses_all.global_attribute7%TYPE;
1586    s_global_attribute8              hz_cust_site_uses_all.global_attribute8%TYPE;
1587    s_global_attribute9              hz_cust_site_uses_all.global_attribute9%TYPE;
1588    s_global_attribute10             hz_cust_site_uses_all.global_attribute10%TYPE;
1589    s_global_attribute11             hz_cust_site_uses_all.global_attribute11%TYPE;
1590    s_global_attribute12             hz_cust_site_uses_all.global_attribute12%TYPE;
1591    s_global_attribute13             hz_cust_site_uses_all.global_attribute13%TYPE;
1592    s_global_attribute14             hz_cust_site_uses_all.global_attribute14%TYPE;
1593    s_global_attribute15             hz_cust_site_uses_all.global_attribute15%TYPE;
1594    s_global_attribute16             hz_cust_site_uses_all.global_attribute16%TYPE;
1595    s_global_attribute17             hz_cust_site_uses_all.global_attribute17%TYPE;
1596    s_global_attribute18             hz_cust_site_uses_all.global_attribute18%TYPE;
1597    s_global_attribute19             hz_cust_site_uses_all.global_attribute19%TYPE;
1598    s_global_attribute20             hz_cust_site_uses_all.global_attribute20%TYPE;
1599    s_global_attribute_category      hz_cust_site_uses_all.global_attribute_category%TYPE;
1600    s_primary_salesrep_id            hz_cust_site_uses_all.primary_salesrep_id%TYPE;
1601    s_finchrg_receivables_trx_id     hz_cust_site_uses_all.finchrg_receivables_trx_id%TYPE;
1602    s_dates_negative_tolerance       hz_cust_site_uses_all.dates_negative_tolerance%TYPE;
1603    s_dates_positive_tolerance       hz_cust_site_uses_all.dates_positive_tolerance%TYPE;
1604    s_date_type_preference           hz_cust_site_uses_all.date_type_preference%TYPE;
1605    s_over_shipment_tolerance        hz_cust_site_uses_all.over_shipment_tolerance%TYPE;
1606    s_under_shipment_tolerance       hz_cust_site_uses_all.under_shipment_tolerance%TYPE;
1607    s_item_cross_ref_pref            hz_cust_site_uses_all.item_cross_ref_pref%TYPE;
1608    s_over_return_tolerance          hz_cust_site_uses_all.over_return_tolerance%TYPE;
1609    s_under_return_tolerance         hz_cust_site_uses_all.under_return_tolerance%TYPE;
1610    s_ship_sets_include_lines_flag   hz_cust_site_uses_all.ship_sets_include_lines_flag%TYPE;
1611    s_arv_include_lines_flag         hz_cust_site_uses_all.arrivalsets_include_lines_flag%TYPE;
1612    s_sched_date_push_flag           hz_cust_site_uses_all.sched_date_push_flag%TYPE;
1613    s_invoice_quantity_rule          hz_cust_site_uses_all.invoice_quantity_rule%TYPE;
1614    s_pricing_event                  hz_cust_site_uses_all.pricing_event%TYPE;
1615    s_gl_id_rec                      hz_cust_site_uses_all.gl_id_rec%TYPE;
1616    s_gl_id_rev                      hz_cust_site_uses_all.gl_id_rev%TYPE;
1617    s_gl_id_tax                      hz_cust_site_uses_all.gl_id_tax%TYPE;
1618    s_gl_id_freight                  hz_cust_site_uses_all.gl_id_freight%TYPE;
1619    s_gl_id_clearing                 hz_cust_site_uses_all.gl_id_clearing%TYPE;
1620    s_gl_id_unbilled                 hz_cust_site_uses_all.gl_id_unbilled%TYPE;
1621    s_gl_id_unearned                 hz_cust_site_uses_all.gl_id_unearned%TYPE;
1622    s_gl_id_unpaid_rec               hz_cust_site_uses_all.gl_id_unpaid_rec%TYPE;
1623    s_gl_id_remittance               hz_cust_site_uses_all.gl_id_remittance%TYPE;
1624    s_gl_id_factor                   hz_cust_site_uses_all.gl_id_factor%TYPE;
1625    s_tax_classification             hz_cust_site_uses_all.tax_classification%TYPE;
1626    s_last_update_date               DATE;
1627    s_last_updated_by                NUMBER;
1628 
1629    CURSOR l_cust_site_use_csr IS
1630       select cust_acct_site_id,
1631 last_update_date,
1632 last_updated_by,
1633 creation_date,
1634 created_by,
1635 site_use_code,
1636 primary_flag,
1637 status,
1638 location,
1639 last_update_login,
1640 contact_id,
1641 bill_to_site_use_id,
1642 orig_system_reference,
1643 sic_code,
1644 payment_term_id,
1645 gsa_indicator,
1646         ship_partial,
1647 ship_via,
1648 fob_point,
1649 order_type_id,
1650 price_list_id,
1651 freight_term,
1652 warehouse_id,
1653 territory_id,
1654 attribute_category,
1655 attribute1,
1656 attribute2,
1657 attribute3,
1658 attribute4,
1659 attribute5,
1660 attribute6,
1661 attribute7,
1662         attribute8,
1663 attribute9,
1664 attribute10,
1665 request_id,
1666 program_application_id,
1667 program_id,
1668 program_update_date,
1669 tax_reference,
1670 sort_priority,
1671 tax_code,
1672 attribute11,
1673 attribute12,
1674 attribute13,
1675 attribute14,
1676 attribute15,
1677         attribute16,
1678 attribute17,
1679 attribute18,
1680 attribute19,
1681 attribute20,
1682 attribute21,
1683 attribute22,
1684 attribute23,
1685 attribute24,
1686 attribute25,
1687 last_accrue_charge_date,
1688 second_last_accrue_charge_date,
1689 last_unaccrue_charge_date,
1690         second_last_unaccrue_chrg_date,
1691 demand_class_code,
1692 org_id,
1693 tax_header_level_flag,
1694 tax_rounding_rule,
1695 wh_update_date,
1696 global_attribute1,
1697 global_attribute2,
1698 global_attribute3,
1699 global_attribute4,
1700 global_attribute5,
1701         global_attribute6,
1702 global_attribute7,
1703 global_attribute8,
1704 global_attribute9,
1705 global_attribute10,
1706 global_attribute11,
1707 global_attribute12,
1708 global_attribute13,
1709 global_attribute14,
1710 global_attribute15,
1711 global_attribute16,
1712         global_attribute17,
1713 global_attribute18,
1714 global_attribute19,
1715 global_attribute20,
1716 global_attribute_category,
1717 primary_salesrep_id,
1718 finchrg_receivables_trx_id,
1719 dates_negative_tolerance,
1720 dates_positive_tolerance,
1721 date_type_preference,
1722         over_shipment_tolerance,
1723 under_shipment_tolerance,
1724 item_cross_ref_pref,
1725 over_return_tolerance,
1726 under_return_tolerance,
1727 ship_sets_include_lines_flag,
1728 arrivalsets_include_lines_flag,
1729 sched_date_push_flag,
1730 invoice_quantity_rule,
1731         pricing_event,
1732 gl_id_rec,
1733 gl_id_rev,
1734 gl_id_tax,
1735 gl_id_freight,
1736 gl_id_clearing,
1737 gl_id_unbilled,
1738 gl_id_unearned,
1739 gl_id_unpaid_rec,
1740 gl_id_remittance,
1741 gl_id_factor,
1742 tax_classification
1743       from hz_cust_site_uses
1744 where site_use_id = p_site_use_id and site_use_code = 'SHIP_TO';
1745 
1746 CURSOR get_bill_to_site_use_id IS
1747       select bill_to_site_use_id
1748       from hz_cust_site_uses
1749 where site_use_id = p_site_use_id and site_use_code = 'SHIP_TO';
1750 
1751 l_Bill_to_site_use_id NUMBER;
1752 
1753    CURSOR l_cust_Bill_to_site_use_csr IS
1754       select cust_acct_site_id,
1755 last_update_date,
1756 last_updated_by,
1757 creation_date,
1758 created_by,
1759 site_use_code,
1760 primary_flag,
1761 status,
1762 location,
1763 last_update_login,
1764 contact_id,
1765 bill_to_site_use_id,
1766 orig_system_reference,
1767 sic_code,
1768 payment_term_id,
1769 gsa_indicator,
1770         ship_partial,
1771 ship_via,
1772 fob_point,
1773 order_type_id,
1774 price_list_id,
1775 freight_term,
1776 warehouse_id,
1777 territory_id,
1778 attribute_category,
1779 attribute1,
1780 attribute2,
1781 attribute3,
1782 attribute4,
1783 attribute5,
1784 attribute6,
1785 attribute7,
1786         attribute8,
1787 attribute9,
1788 attribute10,
1789 request_id,
1790 program_application_id,
1791 program_id,
1792 program_update_date,
1793 tax_reference,
1794 sort_priority,
1795 tax_code,
1796 attribute11,
1797 attribute12,
1798 attribute13,
1799 attribute14,
1800 attribute15,
1801         attribute16,
1802 attribute17,
1803 attribute18,
1804 attribute19,
1805 attribute20,
1806 attribute21,
1807 attribute22,
1808 attribute23,
1809 attribute24,
1810 attribute25,
1811 last_accrue_charge_date,
1812 second_last_accrue_charge_date,
1813 last_unaccrue_charge_date,
1814         second_last_unaccrue_chrg_date,
1815 demand_class_code,
1816 org_id,
1817 tax_header_level_flag,
1818 tax_rounding_rule,
1819 wh_update_date,
1820 global_attribute1,
1821 global_attribute2,
1822 global_attribute3,
1823 global_attribute4,
1824 global_attribute5,
1825         global_attribute6,
1826 global_attribute7,
1827 global_attribute8,
1828 global_attribute9,
1829 global_attribute10,
1830 global_attribute11,
1831 global_attribute12,
1832 global_attribute13,
1833 global_attribute14,
1834 global_attribute15,
1835 global_attribute16,
1836         global_attribute17,
1837 global_attribute18,
1838 global_attribute19,
1839 global_attribute20,
1840 global_attribute_category,
1841 primary_salesrep_id,
1842 finchrg_receivables_trx_id,
1843 dates_negative_tolerance,
1844 dates_positive_tolerance,
1845 date_type_preference,
1846         over_shipment_tolerance,
1847 under_shipment_tolerance,
1848 item_cross_ref_pref,
1849 over_return_tolerance,
1850 under_return_tolerance,
1851 ship_sets_include_lines_flag,
1852 arrivalsets_include_lines_flag,
1853 sched_date_push_flag,
1854 invoice_quantity_rule,
1855         pricing_event,
1856 gl_id_rec,
1857 gl_id_rev,
1858 gl_id_tax,
1859 gl_id_freight,
1860 gl_id_clearing,
1861 gl_id_unbilled,
1862 gl_id_unearned,
1863 gl_id_unpaid_rec,
1864 gl_id_remittance,
1865 gl_id_factor,
1866 tax_classification
1867       from hz_cust_site_uses
1868 where site_use_id = l_bill_to_site_use_id and site_use_code = 'BILL_TO';
1869 
1870 
1871 BEGIN
1872    SAVEPOINT do_update_site_use_PUB;
1873 
1874    open get_bill_to_site_use_id;
1875    fetch get_bill_to_site_use_id INTO l_bill_to_site_use_id;
1876    CLose get_bill_to_site_use_id;
1877    if l_bill_to_site_use_id  IS NOT NULL and p_status = 'A' THEN
1878         open l_cust_Bill_to_site_use_csr;
1879    fetch l_cust_Bill_to_site_use_csr into
1880 s_cust_acct_site_id,
1881 s_last_update_date,
1882 s_last_updated_by,
1883 s_creation_date,
1884 s_created_by,
1885 s_site_use_code,
1886 s_primary_flag,
1887 s_status,
1888 s_location,
1889 s_last_update_login,
1890 s_contact_id,
1891 s_bill_to_site_use_id,
1892 s_orig_system_reference,
1893 s_sic_code,
1894 s_payment_term_id,
1895 s_gsa_indicator,
1896         s_ship_partial,
1897 s_ship_via,
1898 s_fob_point,
1899 s_order_type_id,
1900 s_price_list_id,
1901 s_freight_term,
1902 s_warehouse_id,
1903 s_territory_id,
1904 s_attribute_category,
1905 s_attribute1,
1906 s_attribute2,
1907 s_attribute3,
1908 s_attribute4,
1909 s_attribute5,
1910 s_attribute6,
1911 s_attribute7,
1912         s_attribute8,
1913 s_attribute9,
1914 s_attribute10,
1915 s_request_id,
1916 s_program_application_id,
1917 s_program_id,
1918 s_program_update_date,
1919 s_tax_reference,
1920 s_sort_priority,
1921 s_tax_code,
1922 s_attribute11,
1923 s_attribute12,
1924 s_attribute13,
1925 s_attribute14,
1926 s_attribute15,
1927         s_attribute16,
1928 s_attribute17,
1929 s_attribute18,
1930 s_attribute19,
1931 s_attribute20,
1932 s_attribute21,
1933 s_attribute22,
1934 s_attribute23,
1935 s_attribute24,
1936 s_attribute25,
1937 s_last_accrue_charge_date,
1938 s_snd_last_accrue_charge_date,
1939 s_last_unaccrue_charge_date,
1940         s_snd_last_unaccrue_chrg_date,
1941 s_demand_class_code,
1942 s_org_id,
1943 s_tax_header_level_flag,
1944 s_tax_rounding_rule,
1945 s_wh_update_date,
1946 s_global_attribute1,
1947 s_global_attribute2,
1948 s_global_attribute3,
1949 s_global_attribute4,
1950 s_global_attribute5,
1951         s_global_attribute6,
1952 s_global_attribute7,
1953 s_global_attribute8,
1954 s_global_attribute9,
1955 s_global_attribute10,
1956 s_global_attribute11,
1957 s_global_attribute12,
1958 s_global_attribute13,
1959 s_global_attribute14,
1960 s_global_attribute15,
1961 s_global_attribute16,
1962         s_global_attribute17,
1963 s_global_attribute18,
1964 s_global_attribute19,
1965 s_global_attribute20,
1966 s_global_attribute_category,
1967 s_primary_salesrep_id,
1968 s_finchrg_receivables_trx_id,
1969 s_dates_negative_tolerance,
1970 s_dates_positive_tolerance,
1971 s_date_type_preference,
1972         s_over_shipment_tolerance,
1973 s_under_shipment_tolerance,
1974 s_item_cross_ref_pref,
1975 s_over_return_tolerance,
1976 s_under_return_tolerance,
1977 s_ship_sets_include_lines_flag,
1978 s_arv_include_lines_flag,
1979 s_sched_date_push_flag,
1980 s_invoice_quantity_rule,
1981         s_pricing_event,
1982 s_gl_id_rec,
1983 s_gl_id_rev,
1984 s_gl_id_tax,
1985 s_gl_id_freight,
1986 s_gl_id_clearing,
1987 s_gl_id_unbilled,
1988 s_gl_id_unearned,
1989 s_gl_id_unpaid_rec,
1990 s_gl_id_remittance,
1991 s_gl_id_factor,
1992 s_tax_classification;
1993      IF l_cust_Bill_to_site_use_csr%FOUND THEN
1994         close l_cust_Bill_to_site_use_csr;
1995 
1996         -- Update site use for ship_to
1997         arh_csu_pkg.Update_Row(
1998            X_Site_Use_Id            => l_Bill_to_site_use_id,
1999            X_Last_Update_Date       => s_last_update_date,
2000            X_Last_Updated_By        => nvl(fnd_global.user_id, 1),
2001            X_Site_Use_Code          => s_site_use_code,
2002 		   X_customer_id			=> p_customer_id,
2003            X_Address_Id             => s_cust_acct_site_id,
2004            X_Primary_Flag           => p_primary_flag,
2005            X_Status                 => p_status,
2006            X_Location               => s_location,
2007            X_Last_Update_Login      => s_last_update_login,
2008            X_Contact_Id             => s_Contact_Id,
2009            X_Bill_To_Site_Use_Id    => s_Bill_To_Site_Use_Id,
2010            X_Sic_Code               => s_Sic_Code,
2011            X_Payment_Term_Id        => s_Payment_Term_Id,
2012            X_Gsa_Indicator          => s_Gsa_Indicator,
2013            X_Ship_Partial           => s_Ship_Partial,
2014            X_Ship_Via               => s_Ship_Via,
2015            X_Fob_Point              => s_Fob_Point,
2016            X_Order_Type_Id          => s_Order_Type_Id,
2017            X_Price_List_Id          => s_Price_List_Id,
2018            X_Freight_Term           => s_Freight_Term,
2019            X_Warehouse_Id           => s_Warehouse_Id,
2020            X_Territory_Id           => s_Territory_Id,
2021            X_Tax_Code               => s_Tax_Code,
2022            X_Tax_Reference          => s_Tax_Reference,
2023            X_Demand_Class_Code      => s_Demand_Class_Code,
2024 		   x_inventory_location_id	=> p_inv_location_id,
2025 		   x_inventory_organization_id	=> null,
2026            X_Attribute_Category     => s_attribute_category,
2027            X_Attribute1             => s_attribute1,
2028            X_Attribute2             => s_attribute2,
2029            X_Attribute3             => s_attribute3,
2030            X_Attribute4             => s_attribute4,
2031            X_Attribute5             => s_attribute5,
2032            X_Attribute6             => s_attribute6,
2033            X_Attribute7             => s_attribute7,
2034            X_Attribute8             => s_attribute8,
2035            X_Attribute9             => s_attribute9,
2036            X_Attribute10            => s_attribute10,
2037            X_Attribute11            => s_attribute11,
2038            X_Attribute12            => s_attribute12,
2039            X_Attribute13            => s_attribute13,
2040            X_Attribute14            => s_attribute14,
2041            X_Attribute15            => s_attribute15,
2042            X_Attribute16            => s_attribute16,
2043            X_Attribute17            => s_attribute17,
2044            X_Attribute18            => s_attribute18,
2045            X_Attribute19            => s_attribute19,
2046            X_Attribute20            => s_attribute20,
2047            X_Attribute21            => s_attribute21,
2048            X_Attribute22            => s_attribute22,
2049            X_Attribute23            => s_attribute23,
2050            X_Attribute24            => s_attribute24,
2051            X_Attribute25            => s_attribute25,
2052            X_Tax_Classification     => s_Tax_Classification,
2053            X_Tax_Header_Level_Flag  => s_Tax_Header_Level_Flag,
2054            X_Tax_Rounding_Rule      => s_Tax_Rounding_Rule,
2055            X_Global_Attribute_Category  => s_global_attribute_category,
2056            X_Global_Attribute1      => s_global_attribute1,
2057            X_Global_Attribute2      => s_global_attribute2,
2058            X_Global_Attribute3      => s_global_attribute3,
2059            X_Global_Attribute4      => s_global_attribute4,
2060            X_Global_Attribute5      => s_global_attribute5,
2061            X_Global_Attribute6      => s_global_attribute6,
2062            X_Global_Attribute7      => s_global_attribute7,
2063            X_Global_Attribute8      => s_global_attribute8,
2064            X_Global_Attribute9      => s_global_attribute9,
2065            X_Global_Attribute10     => s_global_attribute10,
2066            X_Global_Attribute11     => s_global_attribute11,
2067            X_Global_Attribute12     => s_global_attribute12,
2068            X_Global_Attribute13     => s_global_attribute13,
2069            X_Global_Attribute14     => s_global_attribute14,
2070            X_Global_Attribute15     => s_global_attribute15,
2071            X_Global_Attribute16     => s_global_attribute16,
2072            X_Global_Attribute17     => s_global_attribute17,
2073            X_Global_Attribute18     => s_global_attribute18,
2074            X_Global_Attribute19     => s_global_attribute19,
2075            X_Global_Attribute20     => s_global_attribute20,
2076            X_Primary_Salesrep_Id    => s_primary_salesrep_id,
2077            X_Finchrg_Receivables_Trx_Id  => s_Finchrg_Receivables_Trx_Id,
2078   		   X_GL_ID_Rec			    => s_GL_ID_Rec,
2079 		   X_GL_ID_Rev			    => s_GL_ID_Rev,
2080 		   X_GL_ID_Tax			    => s_GL_ID_Tax,
2081 		   X_GL_ID_Freight			=> s_GL_ID_Freight,
2082 		   X_GL_ID_Clearing			=> s_GL_ID_Clearing,
2083 		   X_GL_ID_Unbilled			=> s_GL_ID_Unbilled,
2084 		   X_GL_ID_Unearned 		=> s_GL_ID_Unearned,
2085            X_GL_ID_Unpaid_rec       => s_GL_ID_Unpaid_rec,
2086            X_GL_ID_Remittance       => s_GL_ID_Remittance,
2087            X_GL_ID_Factor           => s_GL_ID_Factor,
2088            X_DATES_NEGATIVE_TOLERANCE  => s_DATES_NEGATIVE_TOLERANCE,
2089            X_DATES_POSITIVE_TOLERANCE  => s_DATES_POSITIVE_TOLERANCE,
2090            X_DATE_TYPE_PREFERENCE      => s_DATE_TYPE_PREFERENCE,
2091            X_OVER_SHIPMENT_TOLERANCE   => s_OVER_SHIPMENT_TOLERANCE,
2092            X_UNDER_SHIPMENT_TOLERANCE  => s_UNDER_SHIPMENT_TOLERANCE,
2093            X_ITEM_CROSS_REF_PREF       => s_ITEM_CROSS_REF_PREF,
2094            X_OVER_RETURN_TOLERANCE     => s_OVER_RETURN_TOLERANCE,
2095            X_UNDER_RETURN_TOLERANCE    => s_UNDER_RETURN_TOLERANCE,
2096            X_SHIP_SETS_INCLUDE_LINES_FLAG   => s_SHIP_SETS_INCLUDE_LINES_FLAG,
2097            X_ARRIVALSETS_INCL_LINES_FLAG    => s_arv_include_lines_flag,
2098            X_SCHED_DATE_PUSH_FLAG           => s_SCHED_DATE_PUSH_FLAG,
2099            X_INVOICE_QUANTITY_RULE          => s_INVOICE_QUANTITY_RULE,
2100            x_msg_count               => x_msg_count,
2101            x_msg_data                => x_msg_data,
2102            x_return_status           => x_return_status);
2103 
2104       IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2105          Rollback to do_update_site_use_PUB;
2106         /* FND_MESSAGE.SET_NAME ('CSP', 'CSP_SITE_USE_API_ERROR');
2107          FND_MESSAGE.SET_TOKEN ('TEXT', x_msg_data);
2108          FND_MSG_PUB.ADD;*/
2109          RAISE EXCP_USER_DEFINED;
2110       END IF;
2111     ELSE
2112       close l_cust_Bill_to_site_use_csr;
2113     END IF;
2114     END IF;
2115 
2116 
2117    l_site_use_id := p_site_use_id;
2118 
2119    open l_cust_site_use_csr;
2120    fetch l_cust_site_use_csr into
2121 s_cust_acct_site_id,
2122 s_last_update_date,
2123 s_last_updated_by,
2124 s_creation_date,
2125 s_created_by,
2126 s_site_use_code,
2127 s_primary_flag,
2128 s_status,
2129 s_location,
2130 s_last_update_login,
2131 s_contact_id,
2132 s_bill_to_site_use_id,
2133 s_orig_system_reference,
2134 s_sic_code,
2135 s_payment_term_id,
2136 s_gsa_indicator,
2137         s_ship_partial,
2138 s_ship_via,
2139 s_fob_point,
2140 s_order_type_id,
2141 s_price_list_id,
2142 s_freight_term,
2143 s_warehouse_id,
2144 s_territory_id,
2145 s_attribute_category,
2146 s_attribute1,
2147 s_attribute2,
2148 s_attribute3,
2149 s_attribute4,
2150 s_attribute5,
2151 s_attribute6,
2152 s_attribute7,
2153         s_attribute8,
2154 s_attribute9,
2155 s_attribute10,
2156 s_request_id,
2157 s_program_application_id,
2158 s_program_id,
2159 s_program_update_date,
2160 s_tax_reference,
2161 s_sort_priority,
2162 s_tax_code,
2163 s_attribute11,
2164 s_attribute12,
2165 s_attribute13,
2166 s_attribute14,
2167 s_attribute15,
2168         s_attribute16,
2169 s_attribute17,
2170 s_attribute18,
2171 s_attribute19,
2172 s_attribute20,
2173 s_attribute21,
2174 s_attribute22,
2175 s_attribute23,
2176 s_attribute24,
2177 s_attribute25,
2178 s_last_accrue_charge_date,
2179 s_snd_last_accrue_charge_date,
2180 s_last_unaccrue_charge_date,
2181         s_snd_last_unaccrue_chrg_date,
2182 s_demand_class_code,
2183 s_org_id,
2184 s_tax_header_level_flag,
2185 s_tax_rounding_rule,
2186 s_wh_update_date,
2187 s_global_attribute1,
2188 s_global_attribute2,
2189 s_global_attribute3,
2190 s_global_attribute4,
2191 s_global_attribute5,
2192         s_global_attribute6,
2193 s_global_attribute7,
2194 s_global_attribute8,
2195 s_global_attribute9,
2196 s_global_attribute10,
2197 s_global_attribute11,
2198 s_global_attribute12,
2199 s_global_attribute13,
2200 s_global_attribute14,
2201 s_global_attribute15,
2202 s_global_attribute16,
2203         s_global_attribute17,
2204 s_global_attribute18,
2205 s_global_attribute19,
2206 s_global_attribute20,
2207 s_global_attribute_category,
2208 s_primary_salesrep_id,
2209 s_finchrg_receivables_trx_id,
2210 s_dates_negative_tolerance,
2211 s_dates_positive_tolerance,
2212 s_date_type_preference,
2213         s_over_shipment_tolerance,
2214 s_under_shipment_tolerance,
2215 s_item_cross_ref_pref,
2216 s_over_return_tolerance,
2217 s_under_return_tolerance,
2218 s_ship_sets_include_lines_flag,
2219 s_arv_include_lines_flag,
2220 s_sched_date_push_flag,
2221 s_invoice_quantity_rule,
2222         s_pricing_event,
2223 s_gl_id_rec,
2224 s_gl_id_rev,
2225 s_gl_id_tax,
2226 s_gl_id_freight,
2227 s_gl_id_clearing,
2228 s_gl_id_unbilled,
2229 s_gl_id_unearned,
2230 s_gl_id_unpaid_rec,
2231 s_gl_id_remittance,
2232 s_gl_id_factor,
2233 s_tax_classification;
2234      IF l_cust_site_use_csr%FOUND THEN
2235         close l_cust_site_use_csr;
2236         -- Update site use
2237         arh_csu_pkg.Update_Row(
2238            X_Site_Use_Id            => l_site_use_id,
2239            X_Last_Update_Date       => s_last_update_date,
2240            X_Last_Updated_By        => nvl(fnd_global.user_id, 1),
2241            X_Site_Use_Code          => s_site_use_code,
2242 		   X_customer_id			=> p_customer_id,
2243            X_Address_Id             => s_cust_acct_site_id,
2244            X_Primary_Flag           => p_primary_flag,
2245            X_Status                 => p_status,
2246            X_Location               => s_location,
2247            X_Last_Update_Login      => s_last_update_login,
2248            X_Contact_Id             => s_Contact_Id,
2249            X_Bill_To_Site_Use_Id    => s_Bill_To_Site_Use_Id,
2250            X_Sic_Code               => s_Sic_Code,
2251            X_Payment_Term_Id        => s_Payment_Term_Id,
2252            X_Gsa_Indicator          => s_Gsa_Indicator,
2253            X_Ship_Partial           => s_Ship_Partial,
2254            X_Ship_Via               => s_Ship_Via,
2255            X_Fob_Point              => s_Fob_Point,
2256            X_Order_Type_Id          => s_Order_Type_Id,
2257            X_Price_List_Id          => s_Price_List_Id,
2258            X_Freight_Term           => s_Freight_Term,
2259            X_Warehouse_Id           => s_Warehouse_Id,
2260            X_Territory_Id           => s_Territory_Id,
2261            X_Tax_Code               => s_Tax_Code,
2262            X_Tax_Reference          => s_Tax_Reference,
2263            X_Demand_Class_Code      => s_Demand_Class_Code,
2264 		   x_inventory_location_id	=> p_inv_location_id,
2265 		   x_inventory_organization_id	=> null,
2266            X_Attribute_Category     => s_attribute_category,
2267            X_Attribute1             => s_attribute1,
2268            X_Attribute2             => s_attribute2,
2269            X_Attribute3             => s_attribute3,
2270            X_Attribute4             => s_attribute4,
2271            X_Attribute5             => s_attribute5,
2272            X_Attribute6             => s_attribute6,
2273            X_Attribute7             => s_attribute7,
2274            X_Attribute8             => s_attribute8,
2275            X_Attribute9             => s_attribute9,
2276            X_Attribute10            => s_attribute10,
2277            X_Attribute11            => s_attribute11,
2278            X_Attribute12            => s_attribute12,
2279            X_Attribute13            => s_attribute13,
2280            X_Attribute14            => s_attribute14,
2281            X_Attribute15            => s_attribute15,
2282            X_Attribute16            => s_attribute16,
2283            X_Attribute17            => s_attribute17,
2284            X_Attribute18            => s_attribute18,
2285            X_Attribute19            => s_attribute19,
2286            X_Attribute20            => s_attribute20,
2287            X_Attribute21            => s_attribute21,
2288            X_Attribute22            => s_attribute22,
2289            X_Attribute23            => s_attribute23,
2290            X_Attribute24            => s_attribute24,
2291            X_Attribute25            => s_attribute25,
2292            X_Tax_Classification     => s_Tax_Classification,
2293            X_Tax_Header_Level_Flag  => s_Tax_Header_Level_Flag,
2294            X_Tax_Rounding_Rule      => s_Tax_Rounding_Rule,
2295            X_Global_Attribute_Category  => s_global_attribute_category,
2296            X_Global_Attribute1      => s_global_attribute1,
2297            X_Global_Attribute2      => s_global_attribute2,
2298            X_Global_Attribute3      => s_global_attribute3,
2299            X_Global_Attribute4      => s_global_attribute4,
2300            X_Global_Attribute5      => s_global_attribute5,
2301            X_Global_Attribute6      => s_global_attribute6,
2302            X_Global_Attribute7      => s_global_attribute7,
2303            X_Global_Attribute8      => s_global_attribute8,
2304            X_Global_Attribute9      => s_global_attribute9,
2305            X_Global_Attribute10     => s_global_attribute10,
2306            X_Global_Attribute11     => s_global_attribute11,
2307            X_Global_Attribute12     => s_global_attribute12,
2308            X_Global_Attribute13     => s_global_attribute13,
2309            X_Global_Attribute14     => s_global_attribute14,
2310            X_Global_Attribute15     => s_global_attribute15,
2311            X_Global_Attribute16     => s_global_attribute16,
2312            X_Global_Attribute17     => s_global_attribute17,
2313            X_Global_Attribute18     => s_global_attribute18,
2314            X_Global_Attribute19     => s_global_attribute19,
2315            X_Global_Attribute20     => s_global_attribute20,
2316            X_Primary_Salesrep_Id    => s_primary_salesrep_id,
2317            X_Finchrg_Receivables_Trx_Id  => s_Finchrg_Receivables_Trx_Id,
2318   		   X_GL_ID_Rec			    => s_GL_ID_Rec,
2319 		   X_GL_ID_Rev			    => s_GL_ID_Rev,
2320 		   X_GL_ID_Tax			    => s_GL_ID_Tax,
2321 		   X_GL_ID_Freight			=> s_GL_ID_Freight,
2322 		   X_GL_ID_Clearing			=> s_GL_ID_Clearing,
2323 		   X_GL_ID_Unbilled			=> s_GL_ID_Unbilled,
2324 		   X_GL_ID_Unearned 		=> s_GL_ID_Unearned,
2325            X_GL_ID_Unpaid_rec       => s_GL_ID_Unpaid_rec,
2326            X_GL_ID_Remittance       => s_GL_ID_Remittance,
2327            X_GL_ID_Factor           => s_GL_ID_Factor,
2328            X_DATES_NEGATIVE_TOLERANCE  => s_DATES_NEGATIVE_TOLERANCE,
2329            X_DATES_POSITIVE_TOLERANCE  => s_DATES_POSITIVE_TOLERANCE,
2330            X_DATE_TYPE_PREFERENCE      => s_DATE_TYPE_PREFERENCE,
2331            X_OVER_SHIPMENT_TOLERANCE   => s_OVER_SHIPMENT_TOLERANCE,
2332            X_UNDER_SHIPMENT_TOLERANCE  => s_UNDER_SHIPMENT_TOLERANCE,
2333            X_ITEM_CROSS_REF_PREF       => s_ITEM_CROSS_REF_PREF,
2334            X_OVER_RETURN_TOLERANCE     => s_OVER_RETURN_TOLERANCE,
2335            X_UNDER_RETURN_TOLERANCE    => s_UNDER_RETURN_TOLERANCE,
2336            X_SHIP_SETS_INCLUDE_LINES_FLAG   => s_SHIP_SETS_INCLUDE_LINES_FLAG,
2337            X_ARRIVALSETS_INCL_LINES_FLAG    => s_arv_include_lines_flag,
2338            X_SCHED_DATE_PUSH_FLAG           => s_SCHED_DATE_PUSH_FLAG,
2339            X_INVOICE_QUANTITY_RULE          => s_INVOICE_QUANTITY_RULE,
2340            x_msg_count               => x_msg_count,
2341            x_msg_data                => x_msg_data,
2342            x_return_status           => x_return_status);
2343 
2344       IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2345          Rollback to do_update_site_use_PUB;
2346         /* FND_MESSAGE.SET_NAME ('CSP', 'CSP_SITE_USE_API_ERROR');
2347          FND_MESSAGE.SET_TOKEN ('TEXT', x_msg_data);
2348          FND_MSG_PUB.ADD;*/
2349          RAISE EXCP_USER_DEFINED;
2350       END IF;
2351    ELSE
2352       close l_cust_site_use_csr;
2353    END IF;
2354    if l_bill_to_site_use_id  IS NOT NULL and p_status = 'I' THEN
2355         open l_cust_Bill_to_site_use_csr;
2356    fetch l_cust_Bill_to_site_use_csr into
2357 s_cust_acct_site_id,
2358 s_last_update_date,
2359 s_last_updated_by,
2360 s_creation_date,
2361 s_created_by,
2362 s_site_use_code,
2363 s_primary_flag,
2364 s_status,
2365 s_location,
2366 s_last_update_login,
2367 s_contact_id,
2368 s_bill_to_site_use_id,
2369 s_orig_system_reference,
2370 s_sic_code,
2371 s_payment_term_id,
2372 s_gsa_indicator,
2373         s_ship_partial,
2374 s_ship_via,
2375 s_fob_point,
2376 s_order_type_id,
2377 s_price_list_id,
2378 s_freight_term,
2379 s_warehouse_id,
2380 s_territory_id,
2381 s_attribute_category,
2382 s_attribute1,
2383 s_attribute2,
2384 s_attribute3,
2385 s_attribute4,
2386 s_attribute5,
2387 s_attribute6,
2388 s_attribute7,
2389         s_attribute8,
2390 s_attribute9,
2391 s_attribute10,
2392 s_request_id,
2393 s_program_application_id,
2394 s_program_id,
2395 s_program_update_date,
2396 s_tax_reference,
2397 s_sort_priority,
2398 s_tax_code,
2399 s_attribute11,
2400 s_attribute12,
2401 s_attribute13,
2402 s_attribute14,
2403 s_attribute15,
2404         s_attribute16,
2405 s_attribute17,
2406 s_attribute18,
2407 s_attribute19,
2408 s_attribute20,
2409 s_attribute21,
2410 s_attribute22,
2411 s_attribute23,
2412 s_attribute24,
2413 s_attribute25,
2414 s_last_accrue_charge_date,
2415 s_snd_last_accrue_charge_date,
2416 s_last_unaccrue_charge_date,
2417         s_snd_last_unaccrue_chrg_date,
2418 s_demand_class_code,
2419 s_org_id,
2420 s_tax_header_level_flag,
2421 s_tax_rounding_rule,
2422 s_wh_update_date,
2423 s_global_attribute1,
2424 s_global_attribute2,
2425 s_global_attribute3,
2426 s_global_attribute4,
2427 s_global_attribute5,
2428         s_global_attribute6,
2429 s_global_attribute7,
2430 s_global_attribute8,
2431 s_global_attribute9,
2432 s_global_attribute10,
2433 s_global_attribute11,
2434 s_global_attribute12,
2435 s_global_attribute13,
2436 s_global_attribute14,
2437 s_global_attribute15,
2438 s_global_attribute16,
2439         s_global_attribute17,
2440 s_global_attribute18,
2441 s_global_attribute19,
2442 s_global_attribute20,
2443 s_global_attribute_category,
2444 s_primary_salesrep_id,
2445 s_finchrg_receivables_trx_id,
2446 s_dates_negative_tolerance,
2447 s_dates_positive_tolerance,
2448 s_date_type_preference,
2449         s_over_shipment_tolerance,
2450 s_under_shipment_tolerance,
2451 s_item_cross_ref_pref,
2452 s_over_return_tolerance,
2453 s_under_return_tolerance,
2454 s_ship_sets_include_lines_flag,
2455 s_arv_include_lines_flag,
2456 s_sched_date_push_flag,
2457 s_invoice_quantity_rule,
2458         s_pricing_event,
2459 s_gl_id_rec,
2460 s_gl_id_rev,
2461 s_gl_id_tax,
2462 s_gl_id_freight,
2463 s_gl_id_clearing,
2464 s_gl_id_unbilled,
2465 s_gl_id_unearned,
2466 s_gl_id_unpaid_rec,
2467 s_gl_id_remittance,
2468 s_gl_id_factor,
2469 s_tax_classification;
2470      IF l_cust_Bill_to_site_use_csr%FOUND THEN
2471         close l_cust_Bill_to_site_use_csr;
2472 
2473         -- Update site use for ship_to
2474         arh_csu_pkg.Update_Row(
2475            X_Site_Use_Id            => l_Bill_to_site_use_id,
2476            X_Last_Update_Date       => s_last_update_date,
2477            X_Last_Updated_By        => nvl(fnd_global.user_id, 1),
2478            X_Site_Use_Code          => s_site_use_code,
2479 		   X_customer_id			=> p_customer_id,
2480            X_Address_Id             => s_cust_acct_site_id,
2481            X_Primary_Flag           => p_primary_flag,
2482            X_Status                 => p_status,
2483            X_Location               => s_location,
2484            X_Last_Update_Login      => s_last_update_login,
2485            X_Contact_Id             => s_Contact_Id,
2486            X_Bill_To_Site_Use_Id    => s_Bill_To_Site_Use_Id,
2487            X_Sic_Code               => s_Sic_Code,
2488            X_Payment_Term_Id        => s_Payment_Term_Id,
2489            X_Gsa_Indicator          => s_Gsa_Indicator,
2490            X_Ship_Partial           => s_Ship_Partial,
2491            X_Ship_Via               => s_Ship_Via,
2492            X_Fob_Point              => s_Fob_Point,
2493            X_Order_Type_Id          => s_Order_Type_Id,
2494            X_Price_List_Id          => s_Price_List_Id,
2495            X_Freight_Term           => s_Freight_Term,
2496            X_Warehouse_Id           => s_Warehouse_Id,
2497            X_Territory_Id           => s_Territory_Id,
2498            X_Tax_Code               => s_Tax_Code,
2499            X_Tax_Reference          => s_Tax_Reference,
2500            X_Demand_Class_Code      => s_Demand_Class_Code,
2501 		   x_inventory_location_id	=> p_inv_location_id,
2502 		   x_inventory_organization_id	=> null,
2503            X_Attribute_Category     => s_attribute_category,
2504            X_Attribute1             => s_attribute1,
2505            X_Attribute2             => s_attribute2,
2506            X_Attribute3             => s_attribute3,
2507            X_Attribute4             => s_attribute4,
2508            X_Attribute5             => s_attribute5,
2509            X_Attribute6             => s_attribute6,
2510            X_Attribute7             => s_attribute7,
2511            X_Attribute8             => s_attribute8,
2512            X_Attribute9             => s_attribute9,
2513            X_Attribute10            => s_attribute10,
2514            X_Attribute11            => s_attribute11,
2515            X_Attribute12            => s_attribute12,
2516            X_Attribute13            => s_attribute13,
2517            X_Attribute14            => s_attribute14,
2518            X_Attribute15            => s_attribute15,
2519            X_Attribute16            => s_attribute16,
2520            X_Attribute17            => s_attribute17,
2521            X_Attribute18            => s_attribute18,
2522            X_Attribute19            => s_attribute19,
2523            X_Attribute20            => s_attribute20,
2524            X_Attribute21            => s_attribute21,
2525            X_Attribute22            => s_attribute22,
2526            X_Attribute23            => s_attribute23,
2527            X_Attribute24            => s_attribute24,
2528            X_Attribute25            => s_attribute25,
2529            X_Tax_Classification     => s_Tax_Classification,
2530            X_Tax_Header_Level_Flag  => s_Tax_Header_Level_Flag,
2531            X_Tax_Rounding_Rule      => s_Tax_Rounding_Rule,
2532            X_Global_Attribute_Category  => s_global_attribute_category,
2533            X_Global_Attribute1      => s_global_attribute1,
2534            X_Global_Attribute2      => s_global_attribute2,
2535            X_Global_Attribute3      => s_global_attribute3,
2536            X_Global_Attribute4      => s_global_attribute4,
2537            X_Global_Attribute5      => s_global_attribute5,
2538            X_Global_Attribute6      => s_global_attribute6,
2539            X_Global_Attribute7      => s_global_attribute7,
2540            X_Global_Attribute8      => s_global_attribute8,
2541            X_Global_Attribute9      => s_global_attribute9,
2542            X_Global_Attribute10     => s_global_attribute10,
2543            X_Global_Attribute11     => s_global_attribute11,
2544            X_Global_Attribute12     => s_global_attribute12,
2545            X_Global_Attribute13     => s_global_attribute13,
2546            X_Global_Attribute14     => s_global_attribute14,
2547            X_Global_Attribute15     => s_global_attribute15,
2548            X_Global_Attribute16     => s_global_attribute16,
2549            X_Global_Attribute17     => s_global_attribute17,
2550            X_Global_Attribute18     => s_global_attribute18,
2551            X_Global_Attribute19     => s_global_attribute19,
2552            X_Global_Attribute20     => s_global_attribute20,
2553            X_Primary_Salesrep_Id    => s_primary_salesrep_id,
2554            X_Finchrg_Receivables_Trx_Id  => s_Finchrg_Receivables_Trx_Id,
2555   		   X_GL_ID_Rec			    => s_GL_ID_Rec,
2556 		   X_GL_ID_Rev			    => s_GL_ID_Rev,
2557 		   X_GL_ID_Tax			    => s_GL_ID_Tax,
2558 		   X_GL_ID_Freight			=> s_GL_ID_Freight,
2559 		   X_GL_ID_Clearing			=> s_GL_ID_Clearing,
2560 		   X_GL_ID_Unbilled			=> s_GL_ID_Unbilled,
2561 		   X_GL_ID_Unearned 		=> s_GL_ID_Unearned,
2562            X_GL_ID_Unpaid_rec       => s_GL_ID_Unpaid_rec,
2563            X_GL_ID_Remittance       => s_GL_ID_Remittance,
2564            X_GL_ID_Factor           => s_GL_ID_Factor,
2565            X_DATES_NEGATIVE_TOLERANCE  => s_DATES_NEGATIVE_TOLERANCE,
2566            X_DATES_POSITIVE_TOLERANCE  => s_DATES_POSITIVE_TOLERANCE,
2567            X_DATE_TYPE_PREFERENCE      => s_DATE_TYPE_PREFERENCE,
2568            X_OVER_SHIPMENT_TOLERANCE   => s_OVER_SHIPMENT_TOLERANCE,
2569            X_UNDER_SHIPMENT_TOLERANCE  => s_UNDER_SHIPMENT_TOLERANCE,
2570            X_ITEM_CROSS_REF_PREF       => s_ITEM_CROSS_REF_PREF,
2571            X_OVER_RETURN_TOLERANCE     => s_OVER_RETURN_TOLERANCE,
2572            X_UNDER_RETURN_TOLERANCE    => s_UNDER_RETURN_TOLERANCE,
2573            X_SHIP_SETS_INCLUDE_LINES_FLAG   => s_SHIP_SETS_INCLUDE_LINES_FLAG,
2574            X_ARRIVALSETS_INCL_LINES_FLAG    => s_arv_include_lines_flag,
2575            X_SCHED_DATE_PUSH_FLAG           => s_SCHED_DATE_PUSH_FLAG,
2576            X_INVOICE_QUANTITY_RULE          => s_INVOICE_QUANTITY_RULE,
2577            x_msg_count               => x_msg_count,
2578            x_msg_data                => x_msg_data,
2579            x_return_status           => x_return_status);
2580 
2581       IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2582          Rollback to do_update_site_use_PUB;
2583         /* FND_MESSAGE.SET_NAME ('CSP', 'CSP_SITE_USE_API_ERROR');
2584          FND_MESSAGE.SET_TOKEN ('TEXT', x_msg_data);
2585          FND_MSG_PUB.ADD;*/
2586          RAISE EXCP_USER_DEFINED;
2587       END IF;
2588     ELSE
2589       close l_cust_Bill_to_site_use_csr;
2590     END IF;
2591     END IF;
2592 
2593 
2594    -- Exception Block
2595    EXCEPTION
2596       WHEN EXCP_USER_DEFINED THEN
2597          Rollback to do_update_site_use_PUB;
2598          x_return_status := FND_API.G_RET_STS_ERROR;
2599         JTF_PLSQL_API.HANDLE_EXCEPTIONS(
2600             P_API_NAME => L_API_NAME
2601            ,P_PKG_NAME => G_PKG_NAME
2602            ,P_EXCEPTION_LEVEL => FND_MSG_PUB.G_MSG_LVL_ERROR
2603            ,P_PACKAGE_TYPE => JTF_PLSQL_API.G_PUB
2604            ,X_MSG_COUNT    => x_MSG_COUNT
2605            ,X_MSG_DATA     => x_MSG_DATA
2606            ,X_RETURN_STATUS => x_RETURN_STATUS);
2607       WHEN FND_API.G_EXC_ERROR THEN
2608          JTF_PLSQL_API.HANDLE_EXCEPTIONS(
2609             P_API_NAME => L_API_NAME
2610            ,P_PKG_NAME => G_PKG_NAME
2611            ,P_EXCEPTION_LEVEL => FND_MSG_PUB.G_MSG_LVL_ERROR
2612            ,P_PACKAGE_TYPE => JTF_PLSQL_API.G_PUB
2613            ,X_MSG_COUNT    => x_MSG_COUNT
2614            ,X_MSG_DATA     => x_MSG_DATA
2615            ,X_RETURN_STATUS => x_RETURN_STATUS);
2616       WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2617          JTF_PLSQL_API.HANDLE_EXCEPTIONS(
2618             P_API_NAME => L_API_NAME
2619            ,P_PKG_NAME => G_PKG_NAME
2620            ,P_EXCEPTION_LEVEL => FND_MSG_PUB.G_MSG_LVL_ERROR
2621            ,P_PACKAGE_TYPE => JTF_PLSQL_API.G_PUB
2622            ,X_MSG_COUNT    => x_MSG_COUNT
2623            ,X_MSG_DATA     => x_MSG_DATA
2624            ,X_RETURN_STATUS => x_RETURN_STATUS);
2625       WHEN OTHERS THEN
2626          Rollback to do_update_site_use_PUB;
2627          FND_MESSAGE.SET_NAME('CSP', 'CSP_UNEXPECTED_EXEC_ERRORS');
2628          FND_MESSAGE.SET_TOKEN('ROUTINE', l_api_name, FALSE);
2629          FND_MESSAGE.SET_TOKEN('SQLERRM', sqlerrm, FALSE);
2630          FND_MSG_PUB.ADD;
2631          fnd_msg_pub.count_and_get
2632            ( p_count => x_msg_count
2633            , p_data  => x_msg_data);
2634          x_return_status := FND_API.G_RET_STS_ERROR;
2635 
2636 END do_update_site_use;
2637 ------------------------------------------------------------------------------------------
2638 -- Procedure Name   : ship_to_address_handler
2639 -- Purpose          : If address fields is not blank:
2640 --                      If location_id is blank, create a new inventory location.
2641 --                      else update the existing inventory location with the addresses feed in.
2642 --                    If task_assignment_id is not blank, or resource_type and resource_id is not blank,
2643 --                    (only use task_assignment_id to retrieve resource_type and resource_id if the
2644 --                     resource_type and resource_id pass in are blank).
2645 --                    create party, customer, account, site location, party site, party site use,
2646 --                    account site, account site use, location association, ...
2647 --                    Return error if address fields and task_assignment_id are both blank.
2648 
2649 --                    The address information passed in must be validated before passing in.
2650 --                    It will not create an inventory location if the address is not valid.
2651 --                    Required fields are varied depends on the country.  The country field
2652 --                    is used to check if there is a address passed in.
2653 --
2654 PROCEDURE ship_to_address_handler
2655   (p_task_assignment_id      IN NUMBER
2656   ,p_resource_type           IN VARCHAR2
2657   ,p_resource_id             IN NUMBER
2658   ,p_customer_id             OUT NOCOPY NUMBER
2659   ,p_location_id             IN OUT NOCOPY NUMBER
2660   ,p_style                   IN VARCHAR2
2661   ,p_address_line_1          IN VARCHAR2
2662   ,p_address_line_2          IN VARCHAR2
2663   ,p_address_line_3          IN VARCHAR2
2664   ,p_country                 IN VARCHAR2
2665   ,p_postal_code             IN VARCHAR2
2666   ,p_region_1                IN VARCHAR2
2667   ,p_region_2                IN VARCHAR2
2668   ,p_region_3                IN VARCHAR2
2669   ,p_town_or_city            IN VARCHAR2
2670   ,p_tax_name                IN VARCHAR2
2671   ,p_telephone_number_1      IN VARCHAR2
2672   ,p_telephone_number_2      IN VARCHAR2
2673   ,p_telephone_number_3      IN VARCHAR2
2674   ,p_loc_information13       IN VARCHAR2
2675   ,p_loc_information14       IN VARCHAR2
2676   ,p_loc_information15       IN VARCHAR2
2677   ,p_loc_information16       IN VARCHAR2
2678   ,p_loc_information17       IN VARCHAR2
2679   ,p_loc_information18       IN VARCHAR2
2680   ,p_loc_information19       IN VARCHAR2
2681   ,p_loc_information20       IN VARCHAR2
2682   ,p_timezone                IN VARCHAR2
2683   ,p_primary_flag            IN VARCHAR2
2684   ,p_status                  IN VARCHAR2
2685   ,p_object_version_number   IN OUT NOCOPY NUMBER
2686   ,p_api_version_number      IN NUMBER
2687   ,p_init_msg_list           IN VARCHAR2
2688   ,p_commit                  IN VARCHAR2
2689   ,p_attribute_category     IN VARCHAR2
2690    ,p_attribute1             IN VARCHAR2
2691    ,p_attribute2             IN VARCHAR2
2692    ,p_attribute3             IN VARCHAR2
2693    ,p_attribute4             IN VARCHAR2
2694    ,p_attribute5             IN VARCHAR2
2695    ,p_attribute6             IN VARCHAR2
2696    ,p_attribute7             IN VARCHAR2
2697    ,p_attribute8             IN VARCHAR2
2698    ,p_attribute9             IN VARCHAR2
2699    ,p_attribute10             IN VARCHAR2
2700    ,p_attribute11             IN VARCHAR2
2701    ,p_attribute12             IN VARCHAR2
2702    ,p_attribute13            IN VARCHAR2
2703    ,p_attribute14             IN VARCHAR2
2704    ,p_attribute15             IN VARCHAR2
2705    ,p_attribute16             IN VARCHAR2
2706    ,p_attribute17             IN VARCHAR2
2707    ,p_attribute18             IN VARCHAR2
2708    ,p_attribute19             IN VARCHAR2
2709    ,p_attribute20             IN VARCHAR2
2710     ,p_bill_to_create		  IN VARCHAR2 := 'Y'
2711     ,p_province                IN VARCHAR2 DEFAULT NULL
2712 	,p_address_lines_phonetic  IN VARCHAR2 DEFAULT NULL
2713          ,p_address_line_4          IN VARCHAR2 DEFAULT NULL
2714   ,x_return_status           OUT NOCOPY VARCHAR2
2715   ,x_msg_count               OUT NOCOPY NUMBER
2716   ,x_msg_data                OUT NOCOPY VARCHAR2) IS
2717 
2718    l_api_version_number         CONSTANT NUMBER := 1.0;
2719    l_api_name                   CONSTANT VARCHAR2(30) := 'ship_to_address_handler';
2720    EXCP_USER_DEFINED            EXCEPTION;
2721 
2722    l_customer_profile_class_id      AR_CUSTOMER_PROFILE_CLASSES_V.customer_profile_class_id%TYPE := 0;  -- internal customer
2723    l_customer_id                    hz_cust_accounts.cust_account_id%TYPE := NULL;
2724    t_customer_id                    hz_cust_accounts.cust_account_id%TYPE := NULL;
2725    l_location_id                    hr_locations_all.location_id%TYPE := NULL;
2726    l_inv_location_id                hr_locations_all.location_id%TYPE := NULL;
2727    l_resource_id                    jtf_task_assignments.resource_id%TYPE := NULL;
2728    l_resource_type                  jtf_task_assignments.resource_type_code%TYPE := NULL;
2729    l_resource_name                  jtf_rs_resource_extns_vl.resource_name%TYPE := NULL;
2730    l_party_id                       hz_parties.party_id%TYPE := NULL;
2731    l_first_name                     hz_parties.person_first_name%TYPE := NULL;
2732    l_middle_name                    hz_parties.person_middle_name%TYPE := NULL;
2733    l_last_name                      hz_parties.person_last_name%TYPE := NULL;
2734    l_account_number                 hz_cust_accounts.account_number%TYPE := NULL;
2735    l_customer_number                hz_cust_accounts.account_number%TYPE := NULL;
2736    l_Attribute_Category             hz_cust_accounts.attribute_category%TYPE := NULL;
2737    l_Attribute1                     hz_cust_accounts.attribute1%TYPE := NULL;
2738    l_Attribute2                     hz_cust_accounts.attribute2%TYPE := NULL;
2739    l_Attribute3                     hz_cust_accounts.attribute3%TYPE := NULL;
2740    l_Attribute4                     hz_cust_accounts.attribute4%TYPE := NULL;
2741    l_Attribute5                     hz_cust_accounts.attribute5%TYPE := NULL;
2742    l_Attribute6                     hz_cust_accounts.attribute6%TYPE := NULL;
2743    l_Attribute7                     hz_cust_accounts.attribute7%TYPE := NULL;
2744    l_Attribute8                     hz_cust_accounts.attribute8%TYPE := NULL;
2745    l_Attribute9                     hz_cust_accounts.attribute9%TYPE := NULL;
2746    l_Attribute10                    hz_cust_accounts.attribute10%TYPE := NULL;
2747    l_Attribute11                    hz_cust_accounts.attribute11%TYPE := NULL;
2748    l_Attribute12                    hz_cust_accounts.attribute12%TYPE := NULL;
2749    l_Attribute13                    hz_cust_accounts.attribute13%TYPE := NULL;
2750    l_Attribute14                    hz_cust_accounts.attribute14%TYPE := NULL;
2751    l_Attribute15                    hz_cust_accounts.attribute15%TYPE := NULL;
2752    l_Attribute16                    hz_cust_accounts.attribute16%TYPE := NULL;
2753    l_Attribute17                    hz_cust_accounts.attribute17%TYPE := NULL;
2754    l_Attribute18                    hz_cust_accounts.attribute18%TYPE := NULL;
2755    l_Attribute19                    hz_cust_accounts.attribute19%TYPE := NULL;
2756    l_Attribute20                    hz_cust_accounts.attribute20%TYPE := NULL;
2757    l_global_attribute_category      hz_cust_accounts.global_attribute_category%TYPE := NULL;
2758    l_global_attribute1              hz_cust_accounts.attribute1%TYPE := NULL;
2759    l_global_attribute2              hz_cust_accounts.attribute2%TYPE := NULL;
2760    l_global_attribute3              hz_cust_accounts.attribute3%TYPE := NULL;
2761    l_global_attribute4              hz_cust_accounts.attribute4%TYPE := NULL;
2762    l_global_attribute5              hz_cust_accounts.attribute5%TYPE := NULL;
2763    l_global_attribute6              hz_cust_accounts.attribute6%TYPE := NULL;
2764    l_global_attribute7              hz_cust_accounts.attribute7%TYPE := NULL;
2765    l_global_attribute8              hz_cust_accounts.attribute8%TYPE := NULL;
2766    l_global_attribute9              hz_cust_accounts.attribute9%TYPE := NULL;
2767    l_global_attribute10             hz_cust_accounts.attribute10%TYPE := NULL;
2768    l_global_attribute11             hz_cust_accounts.attribute11%TYPE := NULL;
2769    l_global_attribute12             hz_cust_accounts.attribute12%TYPE := NULL;
2770    l_global_attribute13             hz_cust_accounts.attribute13%TYPE := NULL;
2771    l_global_attribute14             hz_cust_accounts.attribute14%TYPE := NULL;
2772    l_global_attribute15             hz_cust_accounts.attribute15%TYPE := NULL;
2773    l_global_attribute16             hz_cust_accounts.attribute16%TYPE := NULL;
2774    l_global_attribute17             hz_cust_accounts.attribute17%TYPE := NULL;
2775    l_global_attribute18             hz_cust_accounts.attribute18%TYPE := NULL;
2776    l_global_attribute19             hz_cust_accounts.attribute19%TYPE := NULL;
2777    l_global_attribute20             hz_cust_accounts.attribute20%TYPE := NULL;
2778    l_jgzz_attribute_category        hz_cust_accounts.global_attribute_category%TYPE := NULL;
2779    l_jgzz_attribute1                hz_cust_accounts.attribute1%TYPE := NULL;
2780    l_jgzz_attribute2                hz_cust_accounts.attribute2%TYPE := NULL;
2781    l_jgzz_attribute3                hz_cust_accounts.attribute3%TYPE := NULL;
2782    l_jgzz_attribute4                hz_cust_accounts.attribute4%TYPE := NULL;
2783    l_jgzz_attribute5                hz_cust_accounts.attribute5%TYPE := NULL;
2784    l_jgzz_attribute6                hz_cust_accounts.attribute6%TYPE := NULL;
2785    l_jgzz_attribute7                hz_cust_accounts.attribute7%TYPE := NULL;
2786    l_jgzz_attribute8                hz_cust_accounts.attribute8%TYPE := NULL;
2787    l_jgzz_attribute9                hz_cust_accounts.attribute9%TYPE := NULL;
2788    l_jgzz_attribute10               hz_cust_accounts.attribute10%TYPE := NULL;
2789    l_jgzz_attribute11               hz_cust_accounts.attribute11%TYPE := NULL;
2790    l_jgzz_attribute12               hz_cust_accounts.attribute12%TYPE := NULL;
2791    l_jgzz_attribute13               hz_cust_accounts.attribute13%TYPE := NULL;
2792    l_jgzz_attribute14               hz_cust_accounts.attribute14%TYPE := NULL;
2793    l_jgzz_attribute15               hz_cust_accounts.attribute15%TYPE := NULL;
2794    l_orig_system_reference          hz_cust_accounts.orig_system_reference%TYPE := NULL;
2795    l_status                         hz_cust_accounts.status%TYPE := 'A';  -- Active
2796    l_customer_type                  hz_cust_accounts.customer_type%TYPE := 'I';  -- Internal
2797    l_customer_class_code            hz_cust_accounts.customer_class_code%TYPE := NULL;
2798    l_primary_salesrep_id            hz_cust_accounts.primary_salesrep_id%TYPE := NULL;
2799    l_sales_channel_code             hz_cust_accounts.sales_channel_code%TYPE := NULL;
2800    l_order_type_id                  hz_cust_accounts.order_type_id%TYPE := NULL;
2801    l_price_list_id                  hz_cust_accounts.price_list_id%TYPE := NULL;
2802    l_category_code                  hz_cust_accounts.subcategory_code%TYPE := NULL;
2803    l_reference_use_flag             VARCHAR2(1) := 'N';
2804    l_tax_code                       hz_cust_accounts.tax_code%TYPE := NULL;
2805    l_third_party_flag               VARCHAR2(1) := 'N';
2806    l_competitor_flag                VARCHAR2(1) := 'N';
2807    l_fob_point                      hz_cust_accounts.fob_point%TYPE := NULL;
2808    l_tax_header_level_flag          hz_cust_accounts.tax_header_level_flag%TYPE := NULL;
2809    l_tax_rounding_rule              hz_cust_accounts.tax_rounding_rule%TYPE := NULL;
2810    l_account_name                   hz_cust_accounts.account_name%TYPE := NULL;
2811    l_freight_term                   hz_cust_accounts.freight_term%TYPE := NULL;
2812    l_ship_partial                   hz_cust_accounts.ship_partial%TYPE := NULL;
2813    l_ship_via                       hz_cust_accounts.ship_via%TYPE := NULL;
2814    l_warehouse_id                   hz_cust_accounts.warehouse_id%TYPE := NULL;
2815    l_payment_term_id                hz_cust_accounts.payment_term_id%TYPE := NULL;
2816    l_DATES_NEGATIVE_TOLERANCE       hz_cust_accounts.DATES_NEGATIVE_TOLERANCE%TYPE := NULL;
2817    l_DATES_POSITIVE_TOLERANCE       hz_cust_accounts.DATES_POSITIVE_TOLERANCE%TYPE := NULL;
2818    l_DATE_TYPE_PREFERENCE           hz_cust_accounts.DATE_TYPE_PREFERENCE%TYPE := NULL;
2819    l_OVER_SHIPMENT_TOLERANCE        hz_cust_accounts.OVER_SHIPMENT_TOLERANCE%TYPE := NULL;
2820    l_UNDER_SHIPMENT_TOLERANCE       hz_cust_accounts.UNDER_SHIPMENT_TOLERANCE%TYPE := NULL;
2821    l_ITEM_CROSS_REF_PREF            hz_cust_accounts.ITEM_CROSS_REF_PREF%TYPE := NULL;
2822    l_OVER_RETURN_TOLERANCE          hz_cust_accounts.OVER_RETURN_TOLERANCE%TYPE := NULL;
2823    l_UNDER_RETURN_TOLERANCE         hz_cust_accounts.UNDER_RETURN_TOLERANCE%TYPE := NULL;
2824    l_SHIP_SETS_INCLUDE_LINES_FLAG   hz_cust_accounts.SHIP_SETS_INCLUDE_LINES_FLAG%TYPE := 'N';
2825    l_ARRIVALSETS_INCL_LINES_FLAG    hz_cust_accounts.ARRIVALSETS_INCLUDE_LINES_FLAG%TYPE := 'N';
2826    l_SCHED_DATE_PUSH_FLAG           hz_cust_accounts.SCHED_DATE_PUSH_FLAG%TYPE := 'N';
2827    l_INVOICE_QUANTITY_RULE          hz_cust_accounts.INVOICE_QUANTITY_RULE%TYPE := NULL;
2828    l_party_number                   hz_parties.party_number%TYPE := NULL;
2829    l_customer_key                   hz_parties.customer_key%TYPE := NULL;
2830    l_person_profile_id              hz_person_profiles.person_profile_id%TYPE := NULL;
2831    l_pre_name_adjunct               hz_parties.person_pre_name_adjunct%TYPE := NULL;
2832    l_name_suffix                    hz_parties.person_name_suffix%TYPE := NULL;
2833    l_tax_reference                  hz_person_profiles.tax_reference%TYPE := NULL;
2834    l_taxpayer_id                    hz_parties.jgzz_fiscal_code%TYPE := NULL;
2835    l_party_name_phonetic            hz_parties.organization_name_phonetic%TYPE := NULL;
2836    l_customer_profile_id            hz_customer_profiles.cust_account_profile_id%TYPE := NULL;
2837    l_collector_id                   hz_customer_profiles.collector_id%TYPE := NULL;
2838    l_collector_name                 VARCHAR2(80) := NULL;
2839    l_credit_analyst_id              hz_customer_profiles.credit_analyst_id%TYPE := NULL;
2840    l_credit_checking                hz_customer_profiles.credit_checking%TYPE := 'Y';
2841    l_next_credit_review_date        hz_customer_profiles.next_credit_review_date%TYPE := NULL;
2842    l_tolerance                      hz_customer_profiles.tolerance%TYPE := 0;
2843    l_discount_terms                 hz_customer_profiles.discount_terms%TYPE := 'Y';
2844    l_dunning_letters                hz_customer_profiles.dunning_letters%TYPE := 'Y';
2845    l_interest_charges               hz_customer_profiles.interest_charges%TYPE := 'Y';
2846    l_send_statements                hz_customer_profiles.send_statements%TYPE := 'Y';
2847    l_statement_cycle_name           VARCHAR2(80) := NULL;
2848    l_standard_terms_name            VARCHAR2(80) := NULL;
2849    l_credit_balance_statements      hz_customer_profiles.credit_balance_statements%TYPE := 'Y';
2850    l_credit_hold                    hz_customer_profiles.credit_hold%TYPE := 'N';
2851    l_profile_class_id               hz_customer_profiles.profile_class_id%TYPE := 0;
2852    l_site_use_id                    hz_customer_profiles.site_use_id%TYPE := NULL;
2853    l_credit_rating                  hz_customer_profiles.credit_rating%TYPE := NULL;
2854    l_risk_code                      hz_customer_profiles.risk_code%TYPE := NULL;
2855    l_standard_terms                 hz_customer_profiles.standard_terms%TYPE := NULL;
2856    l_override_terms                 hz_customer_profiles.override_terms%TYPE := 'Y';
2857    l_dunning_letter_set_id          hz_customer_profiles.dunning_letter_set_id%TYPE := NULL;
2858    l_dunning_letter_set_name        VARCHAR2(80) := NULL;
2859    l_interest_period_days           hz_customer_profiles.interest_period_days%TYPE := NULL;
2860    l_payment_grace_days             hz_customer_profiles.payment_grace_days%TYPE := 0;
2861    l_discount_grace_days            hz_customer_profiles.discount_grace_days%TYPE := 0;
2862    l_statement_cycle_id             hz_customer_profiles.statement_cycle_id%TYPE := NULL;
2863    l_account_status                 hz_customer_profiles.account_status%TYPE := NULL;
2864    l_percent_collectable            hz_customer_profiles.percent_collectable%TYPE := NULL;
2865    l_autocash_hierarchy_id          hz_customer_profiles.autocash_hierarchy_id%TYPE := NULL;
2866    l_auto_rec_incl_disputed_flag    hz_customer_profiles.auto_rec_incl_disputed_flag%TYPE := 'Y';
2867    l_autocash_hierarchy_name        VARCHAR2(80) := NULL;
2868    l_autocash_hierarchy_name_adr    VARCHAR2(80) := NULL;
2869    l_tax_printing_option            hz_customer_profiles.tax_printing_option%TYPE := NULL;
2870    l_charge_on_fin_charge_flag      hz_customer_profiles.charge_on_finance_charge_flag%TYPE := 'N';
2871    l_grouping_rule_id               hz_customer_profiles.grouping_rule_id%TYPE := NULL;
2872    l_grouping_rule_name             VARCHAR2(80) := NULL;
2873    l_clearing_days                  hz_customer_profiles.clearing_days%TYPE := NULL;
2874    l_cons_inv_flag                  hz_customer_profiles.cons_inv_flag%TYPE := 'N';
2875    l_cons_inv_type                  hz_customer_profiles.cons_inv_type%TYPE := NULL;
2876    l_autocash_hier_id_for_adr       hz_customer_profiles.autocash_hierarchy_id_for_adr%TYPE := NULL;
2877    l_lockbox_matching_option        hz_customer_profiles.lockbox_matching_option%TYPE := NULL;
2878    l_lockbox_matching_name          VARCHAR2(80) := NULL;
2879 
2880    s_Address_Id                     hz_locations.location_id%TYPE := NULL;
2881    s_Status                         hz_party_sites.Status%TYPE := 'A';
2882    s_Orig_System_Reference          hz_locations.Orig_System_Reference%TYPE := NULL;
2883    s_Country                        hz_locations.Country%TYPE := NULL;
2884    s_Address1                       hz_locations.Address1%TYPE := NULL;
2885    s_Address2                       hz_locations.Address2%TYPE := NULL;
2886    s_Address3                       hz_locations.Address3%TYPE := NULL;
2887    s_Address4                       hz_locations.Address4%TYPE := NULL;
2888    s_City                           hz_locations.City%TYPE := NULL;
2889    s_Postal_Code                    hz_locations.Postal_Code%TYPE := NULL;
2890    s_State                          hz_locations.State%TYPE := NULL;
2891    s_Province                       hz_locations.Province%TYPE := NULL;
2892    s_County                         hz_locations.County%TYPE := NULL;
2893    s_Last_Update_Login              hz_locations.Last_Update_Login%TYPE := nvl(fnd_global.user_id,1);
2894    s_Address_Key                    hz_locations.Address_Key%TYPE := NULL;
2895    s_Language                       hz_locations.Language%TYPE := NULL;
2896    s_Attribute_Category             hz_locations.Attribute_Category%TYPE := NULL;
2897    s_Attribute1                     hz_locations.Attribute1%TYPE := NULL;
2898    s_Attribute2                     hz_locations.Attribute2%TYPE := NULL;
2899    s_Attribute3                     hz_locations.Attribute3%TYPE := NULL;
2900    s_Attribute4                     hz_locations.Attribute4%TYPE := NULL;
2901    s_Attribute5                     hz_locations.Attribute5%TYPE := NULL;
2902    s_Attribute6                     hz_locations.Attribute6%TYPE := NULL;
2903    s_Attribute7                     hz_locations.Attribute7%TYPE := NULL;
2904    s_Attribute8                     hz_locations.Attribute8%TYPE := NULL;
2905    s_Attribute9                     hz_locations.Attribute9%TYPE := NULL;
2906    s_Attribute10                    hz_locations.Attribute10%TYPE := NULL;
2907    s_Attribute11                    hz_locations.Attribute11%TYPE := NULL;
2908    s_Attribute12                    hz_locations.Attribute12%TYPE := NULL;
2909    s_Attribute13                    hz_locations.Attribute13%TYPE := NULL;
2910    s_Attribute14                    hz_locations.Attribute14%TYPE := NULL;
2911    s_Attribute15                    hz_locations.Attribute15%TYPE := NULL;
2912    s_Attribute16                    hz_locations.Attribute16%TYPE := NULL;
2913    s_Attribute17                    hz_locations.Attribute17%TYPE := NULL;
2914    s_Attribute18                    hz_locations.Attribute18%TYPE := NULL;
2915    s_Attribute19                    hz_locations.Attribute19%TYPE := NULL;
2916    s_Attribute20                    hz_locations.Attribute20%TYPE := NULL;
2917    s_Global_Attribute_Category      hz_locations.Global_Attribute_Category%TYPE := NULL;
2918    s_Global_Attribute1              hz_locations.Global_Attribute1%TYPE := NULL;
2919    s_Global_Attribute2              hz_locations.Global_Attribute2%TYPE := NULL;
2920    s_Global_Attribute3              hz_locations.Global_Attribute3%TYPE := NULL;
2921    s_Global_Attribute4              hz_locations.Global_Attribute4%TYPE := NULL;
2922    s_Global_Attribute5              hz_locations.Global_Attribute5%TYPE := NULL;
2923    s_Global_Attribute6              hz_locations.Global_Attribute6%TYPE := NULL;
2924    s_Global_Attribute7              hz_locations.Global_Attribute7%TYPE := NULL;
2925    s_Global_Attribute8              hz_locations.Global_Attribute8%TYPE := NULL;
2926    s_Global_Attribute9              hz_locations.Global_Attribute9%TYPE := NULL;
2927    s_Global_Attribute10             hz_locations.Global_Attribute10%TYPE := NULL;
2928    s_Global_Attribute11             hz_locations.Global_Attribute11%TYPE := NULL;
2929    s_Global_Attribute12             hz_locations.Global_Attribute12%TYPE := NULL;
2930    s_Global_Attribute13             hz_locations.Global_Attribute13%TYPE := NULL;
2931    s_Global_Attribute14             hz_locations.Global_Attribute14%TYPE := NULL;
2932    s_Global_Attribute15             hz_locations.Global_Attribute15%TYPE := NULL;
2933    s_Global_Attribute16             hz_locations.Global_Attribute16%TYPE := NULL;
2934    s_Global_Attribute17             hz_locations.Global_Attribute17%TYPE := NULL;
2935    s_Global_Attribute18             hz_locations.Global_Attribute18%TYPE := NULL;
2936    s_Global_Attribute19             hz_locations.Global_Attribute19%TYPE := NULL;
2937    s_Global_Attribute20             hz_locations.Global_Attribute20%TYPE := NULL;
2938 
2939    s_Address_warning                BOOLEAN;
2940    s_Address_Lines_Phonetic         hz_locations.Address_Lines_Phonetic%TYPE := NULL;
2941    s_Party_site_id                  hz_party_sites.Party_site_id%TYPE := NULL;
2942    s_Party_id                       hz_party_sites.Party_id%TYPE := NULL;
2943    s_Location_id                    hz_party_sites.Location_id%TYPE := NULL;
2944    s_Party_Site_Number              hz_party_sites.Party_Site_Number%TYPE := NULL;
2945    s_Identifying_address_flag       hz_party_sites.Identifying_address_flag%TYPE := 'N';
2946    s_Cust_acct_site_id              hz_cust_acct_sites_all.Cust_acct_site_id%TYPE := NULL;
2947    s_Cust_account_id                hz_cust_acct_sites_all.Cust_account_id%TYPE := NULL;
2948    s_su_Bill_To_Flag                hz_cust_acct_sites_all.Bill_To_Flag%TYPE := 'Y';
2949    s_su_Ship_To_Flag                hz_cust_acct_sites_all.Ship_To_Flag%TYPE := 'Y';
2950    s_su_Market_Flag                 hz_cust_acct_sites_all.Market_Flag%TYPE := 'Y';
2951    s_su_stmt_flag                   VARCHAR2(1) := 'N';
2952    s_su_dun_flag                    VARCHAR2(1) := 'N';
2953    s_su_legal_flag                  VARCHAR2(1) := 'N';
2954    s_Customer_Category              hz_cust_acct_sites_all.Customer_Category_code%TYPE := NULL;
2955    s_Key_Account_Flag               hz_cust_acct_sites_all.Key_Account_Flag%TYPE := 'N';
2956    s_Territory_id                   hz_cust_acct_sites_all.Territory_id%TYPE := NULL;
2957    s_ece_tp_location_code           hz_cust_acct_sites_all.ece_tp_location_code%TYPE := NULL;
2958    s_address_mode                   fnd_territories.address_style%TYPE := 'STANDARD';
2959    s_territory                      hz_cust_acct_sites_all.territory%TYPE := NULL;
2960    s_translated_customer_name       hz_cust_acct_sites_all.translated_customer_name%TYPE := NULL;
2961    s_sales_tax_geo_code             hz_locations.sales_tax_geocode%TYPE := NULL;
2962    s_sale_tax_inside_city_limits    hz_locations.sales_tax_inside_city_limits%TYPE := '1';
2963    s_ADDRESSEE                      VARCHAR2(50) := NULL;
2964    s_shared_party_site              VARCHAR2(1) := 'N';
2965    s_update_account_site            VARCHAR2(1) := 'N';
2966    s_create_location_party_site     VARCHAR2(1) := 'N';
2967    t_site_use_id                    hz_cust_site_uses_all.site_use_id%TYPE;
2968    t_cust_acct_site_id              hz_cust_site_uses_all.cust_acct_site_id%TYPE;
2969    t_primary_flag                   hz_cust_site_uses_all.primary_flag%TYPE;
2970    t_status                         hz_cust_site_uses_all.status%TYPE;
2971    t_address_id                     po_location_associations_all.address_id%TYPE;
2972    t_site_loc_id                    hr_locations.location_id%TYPE;
2973    t_orig_system_reference          hz_locations.orig_system_reference%TYPE;
2974    t_last_update_date               DATE;
2975    t_party_site_last_update_date    DATE;
2976    t_loc_last_update_date           DATE;
2977    t_party_id                       hz_cust_accounts.party_id%TYPE;
2978    t_party_site_id                  hz_party_sites.party_site_id%TYPE;
2979    t_party_site_number              hz_party_sites.party_site_number%TYPE;
2980    t_Bill_To_Flag                   hz_cust_acct_sites_all.Bill_To_Flag%TYPE;
2981    t_Ship_To_Flag                   hz_cust_acct_sites_all.Ship_To_Flag%TYPE;
2982    t_Market_Flag                    hz_cust_acct_sites_all.Market_Flag%TYPE;
2983    t_Customer_Category              hz_cust_acct_sites_all.Customer_Category_code%TYPE;
2984    t_Key_Account_Flag               hz_cust_acct_sites_all.Key_Account_Flag%TYPE;
2985    t_territory_id                   hz_cust_acct_sites_all.territory_id%TYPE;
2986    t_territory                      hz_cust_acct_sites_all.territory%TYPE;
2987    t_ece_tp_location_code           hz_cust_acct_sites_all.ece_tp_location_code%TYPE;
2988    t_translated_customer_name       hz_cust_acct_sites_all.translated_customer_name%TYPE;
2989 --   l_sql_str                        varchar2(1000);
2990 --   l_where_clause                   varchar2(500);
2991    t_inv_location_id                csp_requirement_headers.ship_to_location_id%TYPE;
2992    l_timezone_id                    csp_requirement_headers.timezone_id%TYPE;
2993    l_rs_cust_relation_id			number;
2994    l_process_type                   varchar2(30);
2995    l_column_NAME                    varchar2(30);
2996    l_org_id number;
2997 
2998 
2999       CURSOR c_party_id IS
3000     select papf.party_id
3001    from   jtf_rs_resource_extns jrre,
3002           per_all_people_f papf
3003    where  papf.person_id = jrre.source_id
3004    and    jrre.resource_id = l_resource_id
3005    and    decode(l_resource_type,'RS_EMPLOYEE','EMPLOYEE',null) = jrre.category
3006    and    trunc(sysdate) between trunc(papf.effective_start_date) and
3007                                  trunc(papf.effective_end_date)
3008    and    jrre.category = 'EMPLOYEE'
3009    UNION ALL
3010     select hp.party_id
3011    from   jtf_rs_resource_extns jrre,
3012           hz_parties hp
3013    where  hp.party_id = jrre.source_id
3014    and    jrre.resource_id = l_resource_id
3015    and jrre.category = 'PARTY';
3016 
3017 
3018    CURSOR l_resource_id_csr IS
3019       select resource_type_code, resource_id from jtf_task_assignments where task_assignment_id = p_task_assignment_id and assignee_role = 'ASSIGNEE';
3020 
3021    CURSOR l_customer_id_csr IS
3022    select rs_cust_relation_id,
3023 		customer_id
3024    from   csp_rs_cust_relations
3025    where  resource_type = l_resource_type
3026    and    resource_id = l_resource_id;
3027 
3028    CURSOR l_party_id_csr IS
3029       select party_id from hz_cust_accounts where cust_account_id = l_customer_id;
3030 
3031    CURSOR l_requirement_hdr_csr IS
3032 --      select ship_to_location_id from csp_requirement_headers where task_assignment_id = p_task_assignment_id;
3033       select ship_to_location_id,
3034 timezone_id
3035 from csp_requirement_headers
3036 where task_assignment_id = p_task_assignment_id;
3037 
3038    CURSOR l_resource_name_csr IS
3039       select resource_name,
3040 source_first_name,
3041 source_middle_name,
3042 source_last_name
3043 from jtf_rs_resource_extns_vl
3044 where category = substr(l_resource_type, 4) and resource_id = l_resource_id;
3045 
3046 --   CURSOR l_sql_str_csr IS
3047 --      select 'select '||select_id||' select_id, '||select_name||' select_name '|| 'from '||from_table sql_str, where_clause
3048 --      from jtf_objects_vl where object_code = l_resource_type;
3049 
3050    CURSOR l_party_number_csr IS
3051       select hz_parties_s.nextval from dual;
3052 
3053    CURSOR l_customer_number_csr IS
3054       select hz_cust_accounts_s.nextval from dual;
3055 
3056    CURSOR l_party_site_number_csr IS
3057       select hz_party_sites_s.nextval from dual;
3058 
3059    CURSOR l_po_loc_association_csr IS
3060       select p.customer_id,
3061 p.address_id,
3062 p.site_use_id,
3063 ps.location_id,
3064 p.address_id,
3065 ps.identifying_address_flag,
3066 ps.status,
3067 z.orig_system_reference,
3068 ps.party_id,
3069 c.party_site_id,
3070 ps.party_site_number,
3071 c.bill_to_flag,
3072 c.market_flag,
3073 c.ship_to_flag,
3074 c.customer_category_code,
3075 c.key_account_flag,
3076 c.territory_id,
3077 c.territory,
3078 c.ece_tp_location_code,
3079 c.translated_customer_name,
3080 c.last_update_date,
3081 ps.last_update_date,
3082 z.last_update_date
3083         from po_location_associations p, hz_locations z, hz_cust_acct_sites c, hz_party_sites ps
3084         where p.address_id = c.cust_acct_site_id and c.party_site_id = ps.party_site_id and ps.location_id = z.location_id and p.location_id = l_inv_location_id;
3085 
3086    CURSOR l_inv_loc_csr IS
3087       select address_line_1, address_line_2, address_line_3, town_or_city, country, postal_code, region_1, region_2, region_3, attribute_category,
3088         attribute1, attribute2, attribute3, attribute4, attribute5, attribute6, attribute7, attribute8, attribute9, attribute10, attribute11,
3089         attribute12, attribute13, attribute14, attribute15, attribute16, attribute17, attribute18, attribute19, attribute20, global_attribute_category,
3090         global_attribute1, global_attribute2, global_attribute3, global_attribute4, global_attribute5, global_attribute6, global_attribute7,
3091         global_attribute8, global_attribute9, global_attribute10, global_attribute11, global_attribute12, global_attribute13, global_attribute14,
3092         global_attribute15, global_attribute16, global_attribute17, global_attribute18, global_attribute19, global_attribute20 from hr_locations where location_id = l_inv_location_id;
3093 
3094    CURSOR l_identify_address_flag_csr IS
3095       select identifying_address_flag from hz_party_sites where party_id = l_party_id and identifying_address_flag = 'Y' and status = 'A';
3096 
3097     Cursor province_enabled IS
3098     select APPLICATION_COLUMN_NAME
3099     from FND_DESCR_FLEX_COL_USAGE_VL
3100     where DESCRIPTIVE_FLEXFIELD_NAME like 'Address Location'
3101     and upper(END_USER_COLUMN_NAME) like 'PROVINCE'
3102     and  DESCRIPTIVE_FLEX_CONTEXT_CODE = p_style;
3103 
3104    CURSOR l_cust_acct_site(p_cust_acct_site_id number) IS
3105       select attribute_category,
3106              attribute1,attribute2,attribute3,attribute4,attribute5,
3107              attribute6,attribute7,attribute8,attribute9,attribute10,
3108              attribute11,attribute12,attribute13,attribute14,attribute15,
3109              attribute16,attribute17,attribute18,attribute19,attribute20
3110       from hz_cust_acct_sites_all where cust_acct_site_id = p_cust_acct_site_id;
3111 
3112 
3113 	cursor c_check_hz_party_rule is
3114 	SELECT 1
3115 	FROM hz_party_usage_rules
3116 	WHERE party_usage_rule_type  = 'CANNOT_COEXIST'
3117 	AND party_usage_code         = 'SUPPLIER'
3118 	AND RELATED_PARTY_USAGE_CODE = 'CUSTOMER'
3119 	AND EXISTS
3120 	  (SELECT 1
3121 	  FROM hz_party_usg_assignments
3122 	  WHERE party_id       = l_party_id
3123 	  AND party_usage_code = 'SUPPLIER'
3124 	  )
3125 	AND NVL(EFFECTIVE_START_DATE, sysdate-1) < sysdate
3126 	AND NVL(effective_end_date, sysdate  +1) > sysdate;
3127 
3128 	l_module_name varchar2(100);
3129 
3130 BEGIN
3131    SAVEPOINT ship_to_address_handler_PUB;
3132 
3133    l_module_name := 'csp.plsql.csp_ship_to_address_pvt.ship_to_address_handler1';
3134 
3135 	if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
3136 		FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
3137 			l_module_name,
3138 			'Begin... p_resource_type=' || p_resource_type
3139 			|| ', p_resource_id=' || p_resource_id
3140 			|| ', p_location_id=' || p_location_id
3141 			|| ', p_timezone=' || p_timezone
3142 			|| ', p_primary_flag=' || p_primary_flag
3143 			|| ', p_status=' || p_status
3144 			|| ', p_object_version_number=' || p_object_version_number);
3145 	end if;
3146 
3147    -- initialize message list
3148    FND_MSG_PUB.initialize;
3149 
3150    IF NOT FND_API.Compatible_API_Call ( l_api_version_number,
3151                                         p_api_version_number,
3152                                         l_api_name,
3153                                         G_PKG_NAME) THEN
3154       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3155    END IF;
3156 
3157    x_return_status := FND_API.G_RET_STS_SUCCESS;
3158    select userenv('LANG') into s_language from dual;
3159    csp_ship_to_address_pvt.g_rs_cust_relation_id := null;
3160    csp_ship_to_address_pvt.call_internal_hook('CSP_SHIP_TO_ADDRESS_PVT','SHIP_TO_ADDRESS_HANDLER','B',x_return_status);
3161 
3162    -- If task assignment id and addresses are both null, return error.
3163    IF (p_task_assignment_id IS NULL) and (p_country IS NULL) THEN
3164       FND_MESSAGE.SET_NAME ('CSP', 'CSP_TSK_ASSGN_ID_OR_ADDR_REQD');
3165       FND_MSG_PUB.ADD;
3166       RAISE EXCP_USER_DEFINED;
3167    END IF;
3168 
3169 
3170    -- If address fields are not null:
3171    --   If location_id is null, create a new inventory location.
3172    --   If location_id is not null, update the existing inventory location.
3173    IF p_country IS NOT NULL THEN
3174    BEGIN
3175       IF p_location_id IS NULL THEN
3176          do_create_ship_to_location(
3177          p_location_id            => p_location_id,
3178          p_style                  => p_style,
3179          p_address_line_1         => p_address_line_1,
3180          p_address_line_2         => p_address_line_2,
3181          p_address_line_3         => p_address_line_3,
3182          p_country                => p_country,
3183          p_postal_code            => p_postal_code,
3184          p_region_1               => p_region_1,
3185          p_region_2               => p_region_2,
3186          p_region_3               => p_region_3,
3187          p_town_or_city           => p_town_or_city,
3188          p_tax_name               => p_tax_name,
3189          p_telephone_number_1     => p_telephone_number_1,
3190          p_telephone_number_2     => p_telephone_number_2,
3191          p_telephone_number_3     => p_telephone_number_3,
3192          p_loc_information13      => p_loc_information13,
3193          p_loc_information14      => p_loc_information14,
3194          p_loc_information15      => p_loc_information15,
3195          p_loc_information16      => p_loc_information16,
3196          p_loc_information17      => p_loc_information17,
3197          p_loc_information18      => p_loc_information18,
3198          p_loc_information19      => p_loc_information19,
3199          p_loc_information20      => p_loc_information20,
3200          p_object_version_number  => p_object_version_number,
3201          p_attribute1                  => p_attribute1,
3202       p_attribute2                  => p_attribute2,
3203       p_attribute3                  => p_attribute3,
3204       p_attribute4                  => p_attribute4,
3205       p_attribute5                  => p_attribute5,
3206       p_attribute6                  => p_attribute6,
3207       p_attribute7                  => p_attribute7,
3208       p_attribute8                  => p_attribute8,
3209       p_attribute9                  => p_attribute9,
3210       p_attribute10                  => p_attribute10,
3211       p_attribute11                  => p_attribute11,
3212       p_attribute12                  => p_attribute12,
3213       p_attribute13                  => p_attribute13,
3214       p_attribute14                  => p_attribute14,
3215       p_attribute15                  => p_attribute15,
3216       p_attribute16                  => p_attribute16,
3217       p_attribute17                  => p_attribute17,
3218       p_attribute18                  => p_attribute18,
3219       p_attribute19                  => p_attribute19,
3220       p_attribute20                  => p_attribute20,
3221       p_attribute_category          => p_attribute_category,
3222          x_return_status          => x_return_status,
3223          x_msg_count              => x_msg_count,
3224          x_msg_data               => x_msg_data);
3225          l_process_type := 'INSERT';
3226       ELSE
3227          do_update_ship_to_location(
3228          p_location_id            => p_location_id,
3229          p_style                  => p_style,
3230          p_address_line_1         => p_address_line_1,
3231          p_address_line_2         => p_address_line_2,
3232          p_address_line_3         => p_address_line_3,
3233          p_country                => p_country,
3234          p_postal_code            => p_postal_code,
3235          p_region_1               => p_region_1,
3236          p_region_2               => p_region_2,
3237          p_region_3               => p_region_3,
3238          p_town_or_city           => p_town_or_city,
3239          p_tax_name               => p_tax_name,
3240          p_telephone_number_1     => p_telephone_number_1,
3241          p_telephone_number_2     => p_telephone_number_2,
3242          p_telephone_number_3     => p_telephone_number_3,
3243          p_loc_information13      => p_loc_information13,
3244          p_loc_information14      => p_loc_information14,
3245          p_loc_information15      => p_loc_information15,
3246          p_loc_information16      => p_loc_information16,
3247          p_loc_information17      => p_loc_information17,
3248          p_loc_information18      => p_loc_information18,
3249          p_loc_information19      => p_loc_information19,
3250          p_loc_information20      => p_loc_information20,
3251          p_object_version_number  => p_object_version_number,
3252          p_attribute1                  => p_attribute1,
3253       p_attribute2                  => p_attribute2,
3254       p_attribute3                  => p_attribute3,
3255       p_attribute4                  => p_attribute4,
3256       p_attribute5                  => p_attribute5,
3257       p_attribute6                  => p_attribute6,
3258       p_attribute7                  => p_attribute7,
3259       p_attribute8                  => p_attribute8,
3260       p_attribute9                  => p_attribute9,
3261       p_attribute10                  => p_attribute10,
3262       p_attribute11                  => p_attribute11,
3263       p_attribute12                  => p_attribute12,
3264       p_attribute13                  => p_attribute13,
3265       p_attribute14                  => p_attribute14,
3266       p_attribute15                  => p_attribute15,
3267       p_attribute16                  => p_attribute16,
3268       p_attribute17                  => p_attribute17,
3269       p_attribute18                  => p_attribute18,
3270       p_attribute19                  => p_attribute19,
3271       p_attribute20                  => p_attribute20,
3272       p_attribute_category          => p_attribute_category,
3273          x_return_status          => x_return_status,
3274          x_msg_count              => x_msg_count,
3275          x_msg_data               => x_msg_data);
3276          l_process_type := 'UPDATE';
3277       END IF;
3278       l_inv_location_id := p_location_id;
3279       IF x_return_status in ('E','U') THEN
3280          Rollback to ship_to_address_handler_PUB;
3281          /*FND_MESSAGE.SET_NAME ('CSP', 'CSP_STA_API_ERROR');
3282          FND_MESSAGE.SET_TOKEN ('TEXT', x_msg_data);
3283          FND_MSG_PUB.ADD;*/
3284          RAISE EXCP_USER_DEFINED;
3285       END IF;
3286 
3287    END;
3288    END IF;
3289 
3290    -- If p_task_assignment_id is not null or (resource_type and resource_id are not null), it will
3291    -- create account if the engineer doesn't exist in the customer table yet, then create sites.
3292    IF (p_task_assignment_id IS NOT NULL) or
3293       (p_resource_type IS NOT NULL and p_resource_id IS NOT NULL) THEN
3294    BEGIN
3295       IF p_resource_type IS NOT NULL and p_resource_id IS NOT NULL THEN
3296          l_resource_type := p_resource_type;
3297          l_resource_id := p_resource_id;
3298       ELSE
3299          -- Use task_assignment_id to retrieve resource_type, and resource_id
3300          OPEN l_resource_id_csr;
3301          FETCH l_resource_id_csr INTO l_resource_type, l_resource_id;
3302          IF l_resource_id_csr%NOTFOUND THEN
3303             CLOSE l_resource_id_csr;
3304             FND_MESSAGE.SET_NAME ('CSP', 'CSP_RESOURCE_ID_MISSING');
3305             FND_MESSAGE.SET_TOKEN('TSK_ASSGN_ID', p_task_assignment_id, false);
3306             FND_MSG_PUB.ADD;
3307             RAISE EXCP_USER_DEFINED;
3308          END IF;
3309          CLOSE l_resource_id_csr;
3310       END IF;
3311 
3312       IF p_task_assignment_id IS NOT NULL THEN
3313 --      IF l_inv_location_id IS NULL THEN
3314          -- Use task_assignment_id to retrieve inventory_location_id from csp_requirement_headers
3315          OPEN l_requirement_hdr_csr;
3316 --         FETCH l_requirement_hdr_csr INTO l_inv_location_id;
3317          FETCH l_requirement_hdr_csr INTO t_inv_location_id, l_timezone_id;
3318          IF l_requirement_hdr_csr%NOTFOUND THEN
3319             CLOSE l_requirement_hdr_csr;
3320 --            FND_MESSAGE.SET_NAME ('CSP', 'CSP_INV_LOC_MISSING');
3321 --            FND_MESSAGE.SET_TOKEN('TSK_ASSGN_ID', p_task_assignment_id, TRUE);
3322 --            FND_MSG_PUB.ADD;
3323 --            RAISE EXCP_USER_DEFINED;
3324             t_inv_location_id := null;
3325             l_timezone_id := null;
3326          ELSE
3327             CLOSE l_requirement_hdr_csr;
3328          END IF;
3329       END IF;
3330 
3331       IF l_inv_location_id IS NULL THEN
3332          l_inv_location_id := t_inv_location_id;
3333       END IF;
3334 
3335       IF p_timezone IS NOT NULL THEN
3336          l_timezone_id := p_timezone;
3337       END IF;
3338 
3339       IF l_inv_location_id IS NULL THEN
3340          FND_MESSAGE.SET_NAME ('CSP', 'CSP_INV_LOC_MISSING');
3341          FND_MESSAGE.SET_TOKEN('TSK_ASSGN_ID', p_task_assignment_id, false);
3342          FND_MSG_PUB.ADD;
3343          RAISE EXCP_USER_DEFINED;
3344       END IF;
3345 
3346 -- Get party_id if it exists for this resource
3347       open  c_party_id;
3348       fetch c_party_id into l_party_id;
3349       close c_party_id;
3350 
3351 	if l_resource_type = 'RS_EMPLOYEE' then
3352 		open c_check_hz_party_rule;
3353 		if c_check_hz_party_rule%notfound then
3354 			close c_check_hz_party_rule;
3355 		else
3356 			l_party_id := null;
3357 		end if;
3358 		close c_check_hz_party_rule;
3359 	end if;
3360 
3361       -- Retrieve customer_id from CSP_RS_CUST_RELATIONS
3362       -- If found, no need to create new customer account for this resource
3363       OPEN l_customer_id_csr;
3364       FETCH l_customer_id_csr INTO l_rs_cust_relation_id,l_customer_id;
3365 	 csp_ship_to_address_pvt.g_rs_cust_relation_id := l_rs_cust_relation_id;
3366       IF l_customer_id_csr%FOUND and l_customer_id IS NOT NULL THEN
3367          CLOSE l_customer_id_csr;
3368 
3369          -- Use the customer_id to retrieve party_id from hz_cust_accounts
3370          OPEN l_party_id_csr;
3371          FETCH l_party_id_csr INTO l_party_id;
3372          IF l_party_id_csr%NOTFOUND THEN
3373             CLOSE l_party_id_csr;
3374             FND_MESSAGE.SET_NAME ('CSP', 'CSP_PARTY_ID_MISSING');
3375             FND_MESSAGE.SET_TOKEN('RESOURCE_ID', l_resource_id, false);
3376             FND_MESSAGE.SET_TOKEN('CUST_ID', l_customer_id, false);
3377             FND_MSG_PUB.ADD;
3378             RAISE EXCP_USER_DEFINED;
3379          END IF;
3380          CLOSE l_party_id_csr;
3381 
3382       ELSE
3383          CLOSE l_customer_id_csr;
3384          l_customer_id := null;
3385 
3386          -- prepare to create account
3387          -- retrieve resource name information to create new account
3388          OPEN l_resource_name_csr;
3389          FETCH l_resource_name_csr INTO l_resource_name, l_first_name, l_middle_name, l_last_name;
3390          IF l_resource_name_csr%FOUND AND (l_first_name IS NULL and l_last_name IS NULL) THEN
3391             l_first_name := l_resource_name;
3392             l_last_name := l_resource_name;
3393          END IF;
3394          IF l_resource_name_csr%NOTFOUND THEN
3395 --            CLOSE l_resource_name_csr;
3396 --            FND_MESSAGE.SET_NAME ('CSP', 'CSP_RESOURCE_NAME_MISSING');
3397 --            FND_MESSAGE.SET_TOKEN('TSK_ASSGN_ID', p_task_assignment_id, TRUE);
3398 --            FND_MESSAGE.SET_TOKEN('RESOURCE_CODE', l_resource_type, TRUE);
3399 --            FND_MESSAGE.SET_TOKEN('RESOURCE_ID', l_resource_id, TRUE);
3400 --            FND_MSG_PUB.ADD;
3401 --            RAISE EXCP_USER_DEFINED;
3402             l_resource_name := csp_pick_utils.get_object_name(l_resource_type, l_resource_id);
3403             l_first_name := l_resource_name;
3404             l_last_name := l_resource_name;
3405          END IF;
3406          CLOSE l_resource_name_csr;
3407 
3408          -- Create profile
3409 --         hzp_cprof_pkg.create_profile_from_class
3410          csp_customer_account_pvt.create_profile_from_class
3411             (x_customer_profile_class_id            => l_customer_profile_class_id,
3412              x_customer_profile_id                  => l_customer_profile_id,
3413              x_customer_id                          => l_customer_id,
3414              x_site_use_id                          => l_site_use_id,
3415              x_collector_id                         => l_collector_id,
3416              x_collector_name                       => l_collector_name,
3417              x_credit_checking                      => l_credit_checking,
3418              x_tolerance                            => l_tolerance,
3419              x_interest_charges                     => l_interest_charges,
3420              x_charge_on_fin_charge_flag            => l_charge_on_fin_charge_flag,
3421              x_interest_period_days                 => l_interest_period_days,
3422              x_discount_terms                       => l_discount_terms,
3423              x_discount_grace_days                  => l_discount_grace_days,
3424              x_statements                           => l_send_statements,
3425              x_statement_cycle_id                   => l_statement_cycle_id,
3426              x_statement_cycle_name                 => l_statement_cycle_name,
3427              x_credit_balance_statements            => l_credit_balance_statements,
3428              x_standard_terms                       => l_standard_terms,
3429              x_standard_terms_name                  => l_standard_terms_name,
3430              x_override_terms                       => l_override_terms,
3431              x_payment_grace_days                   => l_payment_grace_days,
3432              x_dunning_letters                      => l_dunning_letters,
3433              x_dunning_letter_set_id                => l_dunning_letter_set_id,
3434              x_dunning_letter_set_name              => l_dunning_letter_set_name,
3435              x_autocash_hierarchy_id                => l_autocash_hierarchy_id,
3436              x_autocash_hierarchy_name              => l_autocash_hierarchy_name,
3437              x_auto_rec_incl_disputed_flag          => l_auto_rec_incl_disputed_flag,
3438              x_tax_printing_option                  => l_tax_printing_option,
3439              x_grouping_rule_id                     => l_grouping_rule_id,
3440              x_grouping_rule_name                   => l_grouping_rule_name,
3441              x_cons_inv_flag                        => l_cons_inv_flag,
3442              x_cons_inv_type                        => l_cons_inv_type,
3443              x_attribute_category                   => l_attribute_category,
3444              x_attribute1                           => l_attribute1,
3445              x_attribute2                           => l_attribute2,
3446              x_attribute3                           => l_attribute3,
3447              x_attribute4                           => l_attribute4,
3448              x_attribute5                           => l_attribute5,
3449              x_attribute6                           => l_attribute6,
3450              x_attribute7                           => l_attribute7,
3451              x_attribute8                           => l_attribute8,
3452              x_attribute9                           => l_attribute9,
3453              x_attribute10                          => l_attribute10,
3454              x_attribute11                          => l_attribute11,
3455              x_attribute12                          => l_attribute12,
3456              x_attribute13                          => l_attribute13,
3457              x_attribute14                          => l_attribute14,
3458              x_attribute15                          => l_attribute15,
3459              x_jgzz_attribute_category              => l_jgzz_attribute_category,
3460              x_jgzz_attribute1                      => l_jgzz_attribute1,
3461              x_jgzz_attribute2                      => l_jgzz_attribute2,
3462              x_jgzz_attribute3                      => l_jgzz_attribute3,
3463              x_jgzz_attribute4                      => l_jgzz_attribute4,
3464              x_jgzz_attribute5                      => l_jgzz_attribute5,
3465              x_jgzz_attribute6                      => l_jgzz_attribute6,
3466              x_jgzz_attribute7                      => l_jgzz_attribute7,
3467              x_jgzz_attribute8                      => l_jgzz_attribute8,
3468              x_jgzz_attribute9                      => l_jgzz_attribute9,
3469              x_jgzz_attribute10                     => l_jgzz_attribute10,
3470              x_jgzz_attribute11                     => l_jgzz_attribute11,
3471              x_jgzz_attribute12                     => l_jgzz_attribute12,
3472              x_jgzz_attribute13                     => l_jgzz_attribute13,
3473              x_jgzz_attribute14                     => l_jgzz_attribute14,
3474              x_jgzz_attribute15                     => l_jgzz_attribute15,
3475              x_global_attribute_category            => l_global_attribute_category,
3476              x_global_attribute1                    => l_global_attribute1,
3477              x_global_attribute2                    => l_global_attribute2,
3478              x_global_attribute3                    => l_global_attribute3,
3479              x_global_attribute4                    => l_global_attribute4,
3480              x_global_attribute5                    => l_global_attribute5,
3481              x_global_attribute6                    => l_global_attribute6,
3482              x_global_attribute7                    => l_global_attribute7,
3483              x_global_attribute8                    => l_global_attribute8,
3484              x_global_attribute9                    => l_global_attribute9,
3485              x_global_attribute10                   => l_global_attribute10,
3486              x_global_attribute11                   => l_global_attribute11,
3487              x_global_attribute12                   => l_global_attribute12,
3488              x_global_attribute13                   => l_global_attribute13,
3489              x_global_attribute14                   => l_global_attribute14,
3490              x_global_attribute15                   => l_global_attribute15,
3491              x_global_attribute16                   => l_global_attribute16,
3492              x_global_attribute17                   => l_global_attribute17,
3493              x_global_attribute18                   => l_global_attribute18,
3494              x_global_attribute19                   => l_global_attribute19,
3495              x_global_attribute20                   => l_global_attribute20,
3496              x_lockbox_matching_option              => l_lockbox_matching_option,
3497              x_lockbox_matching_name                => l_lockbox_matching_name,
3498              x_autocash_hierarchy_id_adr            => l_autocash_hierarchy_id,
3499              x_autocash_hierarchy_name_adr          => l_autocash_hierarchy_name_adr,
3500              x_return_status                        => x_return_status,
3501              x_msg_count                            => x_msg_count,
3502              x_msg_data                             => x_msg_data);
3503 
3504          IF x_return_status in ('E','U') THEN
3505             Rollback to ship_to_address_handler_PUB;
3506            /* FND_MESSAGE.SET_NAME ('CSP', 'CSP_PROF_API_ERROR');
3507             FND_MESSAGE.SET_TOKEN ('TEXT', x_msg_data);
3508             FND_MSG_PUB.ADD;*/
3509             RAISE EXCP_USER_DEFINED;
3510          END IF;
3511 
3512          -- if auto generate customer number is no, pass the customer number to the API
3513          IF nvl(arp_standard.sysparm.generate_customer_number,'Y') <> 'N' THEN
3514             l_customer_number := NULL;
3515          ELSE
3516             OPEN  l_customer_number_csr;
3517             FETCH l_customer_number_csr into l_customer_number;
3518             CLOSE l_customer_number_csr;
3519          END IF;
3520 
3521          -- if the party number generation profile is yes or null, pass the party number to the api
3522          IF  fnd_profile.value('HZ_GENERATE_PARTY_NUMBER') <> 'N' THEN
3523             l_party_number := NULL;
3524          ELSE
3525             OPEN  l_party_number_csr;
3526             FETCH l_party_number_csr into l_party_number;
3527             CLOSE l_party_number_csr;
3528          END IF;
3529 
3530 --         hz_acct_create_pkg.insert_person_row
3531          csp_customer_account_pvt.insert_person_row
3532            (c_cust_account_id                   => l_customer_id,
3533             c_party_id                          => l_party_id,
3534             c_account_number                    => l_customer_number,
3535             c_Attribute_Category                => null,
3536             c_Attribute1                        => null,
3537             c_Attribute2                        => null,
3538             c_Attribute3                        => null,
3539             c_Attribute4                        => null,
3540             c_Attribute5                        => null,
3541             c_Attribute6                        => null,
3542             c_Attribute7                        => null,
3543             c_Attribute8                        => null,
3544             c_Attribute9                        => null,
3545             c_Attribute10                       => null,
3546             c_Attribute11                       => null,
3547             c_Attribute12                       => null,
3548             c_Attribute13                       => null,
3549             c_Attribute14                       => null,
3550             c_Attribute15                       => null,
3551             c_Attribute16                       => null,
3552             c_Attribute17                       => null,
3553             c_Attribute18                       => null,
3554             c_Attribute19                       => null,
3555             c_Attribute20                       => null,
3556             c_global_attribute_category         => l_global_attribute_category,
3557             c_global_attribute1                 => l_global_attribute1,
3558             c_global_attribute2                 => l_global_attribute2,
3559             c_global_attribute3                 => l_global_attribute3,
3560             c_global_attribute4                 => l_global_attribute4,
3561             c_global_attribute5                 => l_global_attribute5,
3562             c_global_attribute6                 => l_global_attribute6,
3563             c_global_attribute7                 => l_global_attribute7,
3564             c_global_attribute8                 => l_global_attribute8,
3565             c_global_attribute9                 => l_global_attribute9,
3566             c_global_attribute10                => l_global_attribute10,
3567             c_global_attribute11                => l_global_attribute11,
3568             c_global_attribute12                => l_global_attribute12,
3569             c_global_attribute13                => l_global_attribute13,
3570             c_global_attribute14                => l_global_attribute14,
3571             c_global_attribute15                => l_global_attribute15,
3572             c_global_attribute16                => l_global_attribute16,
3573             c_global_attribute17                => l_global_attribute17,
3574             c_global_attribute18                => l_global_attribute18,
3575             c_global_attribute19                => l_global_attribute19,
3576             c_global_attribute20                => l_global_attribute20,
3577             c_orig_system_reference             => l_orig_system_reference,
3578             c_status                            => l_status,
3579             c_customer_type                     => l_customer_type,
3580             c_customer_class_code               => l_customer_class_code,
3581             c_primary_salesrep_id               => l_primary_salesrep_id,
3582             c_sales_channel_code                => l_sales_channel_code,
3583             c_order_type_id                     => l_order_type_id,
3584             c_price_list_id                     => l_price_list_id,
3585             c_category_code                     => l_category_code,
3586             c_reference_use_flag                => l_reference_use_flag,
3587             c_tax_code                          => l_tax_code,
3588             c_third_party_flag                  => l_third_party_flag,
3589             c_competitor_flag                   => l_competitor_flag,
3590             c_fob_point                         => l_fob_point,
3591             c_tax_header_level_flag             => l_tax_header_level_flag,
3592             c_tax_rounding_rule                 => l_tax_rounding_rule,
3593             c_account_name                      => l_account_name,
3594             c_freight_term                      => l_freight_term,
3595             c_ship_partial                      => l_ship_partial,
3596             c_ship_via                          => l_ship_via,
3597             c_warehouse_id                      => l_warehouse_id,
3598             c_payment_term_id                   => l_payment_term_id,
3599             c_DATES_NEGATIVE_TOLERANCE          => l_DATES_NEGATIVE_TOLERANCE,
3600             c_DATES_POSITIVE_TOLERANCE          => l_DATES_POSITIVE_TOLERANCE,
3601             c_DATE_TYPE_PREFERENCE              => l_DATE_TYPE_PREFERENCE,
3602             c_OVER_SHIPMENT_TOLERANCE           => l_OVER_SHIPMENT_TOLERANCE,
3603             c_UNDER_SHIPMENT_TOLERANCE          => l_UNDER_SHIPMENT_TOLERANCE,
3604             c_ITEM_CROSS_REF_PREF               => l_ITEM_CROSS_REF_PREF,
3605             c_OVER_RETURN_TOLERANCE             => l_OVER_RETURN_TOLERANCE,
3606             c_UNDER_RETURN_TOLERANCE            => l_UNDER_RETURN_TOLERANCE,
3607             c_SHIP_SETS_INCLUDE_LINES_FLAG      => l_SHIP_SETS_INCLUDE_LINES_FLAG,
3608             c_ARRIVALSETS_INCL_LINES_FLAG       => l_ARRIVALSETS_INCL_LINES_FLAG,
3609             c_SCHED_DATE_PUSH_FLAG              => l_SCHED_DATE_PUSH_FLAG,
3610             c_INVOICE_QUANTITY_RULE             => l_INVOICE_QUANTITY_RULE,
3611             t_party_id                          => l_party_id,
3612             t_party_number                      => l_party_number,
3613             t_customer_key                      => l_customer_key,
3614             t_Attribute_Category                => l_Attribute_Category,
3615             t_Attribute1                        => l_Attribute1,
3616             t_Attribute2                        => l_Attribute2,
3617             t_Attribute3                        => l_Attribute3,
3618             t_Attribute4                        => l_Attribute4,
3619             t_Attribute5                        => l_Attribute5,
3620             t_Attribute6                        => l_Attribute6,
3621             t_Attribute7                        => l_Attribute7,
3622             t_Attribute8                        => l_Attribute8,
3623             t_Attribute9                        => l_Attribute9,
3624             t_Attribute10                       => l_Attribute10,
3625             t_Attribute11                       => l_Attribute11,
3626             t_Attribute12                       => l_Attribute12,
3627             t_Attribute13                       => l_Attribute13,
3628             t_Attribute14                       => l_Attribute14,
3629             t_Attribute15                       => l_Attribute15,
3630             t_Attribute16                       => l_Attribute16,
3631             t_Attribute17                       => l_Attribute17,
3632             t_Attribute18                       => l_Attribute18,
3633             t_Attribute19                       => l_Attribute19,
3634             t_Attribute20                       => l_Attribute20,
3635             t_global_attribute_category         => l_global_attribute_category,
3636             t_global_attribute1                 => l_global_attribute1,
3637             t_global_attribute2                 => l_global_attribute2,
3638             t_global_attribute3                 => l_global_attribute3,
3639             t_global_attribute4                 => l_global_attribute4,
3640             t_global_attribute5                 => l_global_attribute5,
3641             t_global_attribute6                 => l_global_attribute6,
3642             t_global_attribute7                 => l_global_attribute7,
3643             t_global_attribute8                 => l_global_attribute8,
3644             t_global_attribute9                 => l_global_attribute9,
3645             t_global_attribute10                => l_global_attribute10,
3646             t_global_attribute11                => l_global_attribute11,
3647             t_global_attribute12                => l_global_attribute12,
3648             t_global_attribute13                => l_global_attribute13,
3649             t_global_attribute14                => l_global_attribute14,
3650             t_global_attribute15                => l_global_attribute15,
3651             t_global_attribute16                => l_global_attribute16,
3652             t_global_attribute17                => l_global_attribute17,
3653             t_global_attribute18                => l_global_attribute18,
3654             t_global_attribute19                => l_global_attribute19,
3655             t_global_attribute20                => l_global_attribute20,
3656             o_pre_name_adjunct                  => l_pre_name_adjunct,
3657             o_first_name                        => l_first_name,
3658             o_middle_name                       => l_middle_name,
3659             o_last_name                         => l_last_name,
3660             o_name_suffix                       => l_name_suffix,
3661             o_tax_reference                     => l_tax_reference,
3662             o_taxpayer_id                       => l_taxpayer_id,
3663             o_party_name_phonetic               => l_party_name_phonetic,
3664             p_cust_account_profile_id           => l_customer_profile_id,
3665             p_cust_account_id                   => l_customer_id,
3666             p_status                            => l_status,
3667             p_collector_id                      => l_collector_id,
3668             p_credit_analyst_id                 => l_credit_analyst_id,
3669             p_credit_checking                   => l_credit_checking,
3670             p_next_credit_review_date           => l_next_credit_review_date,
3671             p_tolerance                         => l_tolerance,
3672             p_discount_terms                    => l_discount_terms,
3673             p_dunning_letters                   => l_dunning_letters,
3674             p_interest_charges                  => l_interest_charges,
3675             p_send_statements                   => l_send_statements,
3676             p_credit_balance_statements         => l_credit_balance_statements,
3677             p_credit_hold                       => l_credit_hold,
3678             p_profile_class_id                  => l_customer_profile_class_id,
3679             p_site_use_id                       => l_site_use_id,
3680             p_credit_rating                     => l_credit_rating,
3681             p_risk_code                         => l_risk_code,
3682             p_standard_terms                    => l_standard_terms,
3683             p_override_terms                    => l_override_terms,
3684             p_dunning_letter_set_id             => l_dunning_letter_set_id,
3685             p_interest_period_days              => l_interest_period_days,
3686             p_payment_grace_days                => l_payment_grace_days,
3687             p_discount_grace_days               => l_discount_grace_days,
3688             p_statement_cycle_id                => l_statement_cycle_id,
3689             p_account_status                    => l_account_status,
3690             p_percent_collectable               => l_percent_collectable,
3691             p_autocash_hierarchy_id             => l_autocash_hierarchy_id,
3692             p_Attribute_Category                => l_Attribute_Category,
3693             p_Attribute1                        => l_Attribute1,
3694             p_Attribute2                        => l_Attribute2,
3695             p_Attribute3                        => l_Attribute3,
3696             p_Attribute4                        => l_Attribute4,
3697             p_Attribute5                        => l_Attribute5,
3698             p_Attribute6                        => l_Attribute6,
3699             p_Attribute7                        => l_Attribute7,
3700             p_Attribute8                        => l_Attribute8,
3701             p_Attribute9                        => l_Attribute9,
3702             p_Attribute10                       => l_Attribute10,
3703             p_Attribute11                       => l_Attribute11,
3704             p_Attribute12                       => l_Attribute12,
3705             p_Attribute13                       => l_Attribute13,
3706             p_Attribute14                       => l_Attribute14,
3707             p_Attribute15                       => l_Attribute15,
3708             p_auto_rec_incl_disputed_flag       => l_auto_rec_incl_disputed_flag,
3709             p_tax_printing_option               => l_tax_printing_option,
3710             p_charge_on_fin_charge_flag         => l_charge_on_fin_charge_flag,
3711             p_grouping_rule_id                  => l_grouping_rule_id,
3712             p_clearing_days                     => l_clearing_days,
3713             p_jgzz_attribute_category           => l_jgzz_attribute_category,
3714             p_jgzz_attribute1                   => l_jgzz_attribute1,
3715             p_jgzz_attribute2                   => l_jgzz_attribute2,
3716             p_jgzz_attribute3                   => l_jgzz_attribute3,
3717             p_jgzz_attribute4                   => l_jgzz_attribute4,
3718             p_jgzz_attribute5                   => l_jgzz_attribute5,
3719             p_jgzz_attribute6                   => l_jgzz_attribute6,
3720             p_jgzz_attribute7                   => l_jgzz_attribute7,
3721             p_jgzz_attribute8                   => l_jgzz_attribute8,
3722             p_jgzz_attribute9                   => l_jgzz_attribute9,
3723             p_jgzz_attribute10                  => l_jgzz_attribute10,
3724             p_jgzz_attribute11                  => l_jgzz_attribute11,
3725             p_jgzz_attribute12                  => l_jgzz_attribute12,
3726             p_jgzz_attribute13                  => l_jgzz_attribute13,
3727             p_jgzz_attribute14                  => l_jgzz_attribute14,
3728             p_jgzz_attribute15                  => l_jgzz_attribute15,
3729             p_global_attribute_category         => l_global_attribute_category,
3730             p_global_attribute1                 => l_global_attribute1,
3731             p_global_attribute2                 => l_global_attribute2,
3732             p_global_attribute3                 => l_global_attribute3,
3733             p_global_attribute4                 => l_global_attribute4,
3734             p_global_attribute5                 => l_global_attribute5,
3735             p_global_attribute6                 => l_global_attribute6,
3736             p_global_attribute7                 => l_global_attribute7,
3737             p_global_attribute8                 => l_global_attribute8,
3738             p_global_attribute9                 => l_global_attribute9,
3739             p_global_attribute10                => l_global_attribute10,
3740             p_global_attribute11                => l_global_attribute11,
3741             p_global_attribute12                => l_global_attribute12,
3742             p_global_attribute13                => l_global_attribute13,
3743             p_global_attribute14                => l_global_attribute14,
3744             p_global_attribute15                => l_global_attribute15,
3745             p_global_attribute16                => l_global_attribute16,
3746             p_global_attribute17                => l_global_attribute17,
3747             p_global_attribute18                => l_global_attribute18,
3748             p_global_attribute19                => l_global_attribute19,
3749             p_global_attribute20                => l_global_attribute20,
3750             p_cons_inv_flag                     => l_cons_inv_flag,
3751             p_cons_inv_type                     => l_cons_inv_type,
3752             p_autocash_hier_id_for_adr          => l_autocash_hier_id_for_adr,
3753             p_lockbox_matching_option           => l_lockbox_matching_option,
3754             o_person_profile_id                 => l_person_profile_id,
3755             x_msg_count                         => x_msg_count,
3756             x_msg_data                          => x_msg_data,
3757             x_return_status                     => x_return_status);
3758 
3759          IF x_return_status in ('E','U') THEN
3760             Rollback to ship_to_address_handler_PUB;
3761             /*FND_MESSAGE.SET_NAME ('CSP', 'CSP_CUST_API_ERROR');
3762             FND_MESSAGE.SET_TOKEN ('TEXT', x_msg_data);
3763             FND_MSG_PUB.ADD;*/
3764             RAISE EXCP_USER_DEFINED;
3765          ELSE
3766             -- Create/update resource customer relationship in csp_rs_cust_relations.
3767             do_rs_cust_relations(l_resource_type, l_resource_id, l_customer_id);
3768          END IF;
3769       END IF;
3770 
3771       -- Select inventory location information
3772       OPEN l_inv_loc_csr;
3773       FETCH l_inv_loc_csr INTO s_address1, s_address2, s_address3, s_city, s_country, s_postal_code, s_county, s_state, s_province, s_attribute_category,
3774         s_attribute1, s_attribute2, s_attribute3, s_attribute4, s_attribute5, s_attribute6, s_attribute7, s_attribute8, s_attribute9, s_attribute10, s_attribute11,
3775         s_attribute12, s_attribute13, s_attribute14, s_attribute15, s_attribute16, s_attribute17, s_attribute18, s_attribute19, s_attribute20, s_global_attribute_category,
3776         s_global_attribute1, s_global_attribute2, s_global_attribute3, s_global_attribute4, s_global_attribute5, s_global_attribute6, s_global_attribute7,
3777         s_global_attribute8, s_global_attribute9, s_global_attribute10, s_global_attribute11, s_global_attribute12, s_global_attribute13, s_global_attribute14,
3778         s_global_attribute15, s_global_attribute16, s_global_attribute17, s_global_attribute18, s_global_attribute19, s_global_attribute20;
3779       IF l_inv_loc_csr%NOTFOUND THEN
3780          CLOSE l_inv_loc_csr;
3781          FND_MESSAGE.SET_NAME ('CSP', 'CSP_INV_LOC_NOT_FOUND');
3782          FND_MESSAGE.SET_TOKEN ('LOC_ID', 'l_inv_location_id',false);
3783          FND_MSG_PUB.ADD;
3784          RAISE EXCP_USER_DEFINED;
3785       END IF;
3786       CLOSE l_inv_loc_csr;
3787       s_province := p_province;
3788       s_address_lines_phonetic := p_address_lines_phonetic;
3789       s_address4 := p_address_line_4;
3790       /* As part of bug fix  following code is included for canadian address ,
3791       Provice is stored in region_1 not in Region_3 of hr_locations_v*/
3792       l_column_NAME := null;
3793       OPEN province_enabled;
3794       FETCH province_enabled INTO l_column_NAME;
3795       CLOSE province_enabled;
3796       IF l_column_NAME IS NOT NULL AND UPPER(l_column_NAME) = 'REGION_1' THEN
3797             s_province := s_county;
3798             s_county := null;
3799       ELSIF l_column_NAME IS NOT NULL AND UPPER(l_column_NAME) = 'REGION_2' THEN
3800             s_province := s_state;
3801             s_state := null;
3802       END IF;
3803       -- Check if the inventory location has been assoicated to another customer site.
3804       -- If it is associated to the same customer, fine.  No need to create new site and site use.  Just update it.
3805       -- If it is associated to a different customer, stop with error message.
3806       OPEN l_po_loc_association_csr;
3807       FETCH l_po_loc_association_csr INTO
3808 t_customer_id,
3809 t_cust_acct_site_id,
3810 t_site_use_id,
3811 t_site_loc_id,
3812 t_cust_acct_site_id,
3813 t_primary_flag,
3814 t_status,
3815 t_orig_system_reference,
3816 t_party_id,
3817 t_party_site_id,
3818 t_party_site_number,
3819 t_bill_to_flag,
3820 t_market_flag,
3821 t_ship_to_flag,
3822 t_customer_category,
3823 t_key_account_flag,
3824 t_territory_id,
3825 t_territory,
3826 t_ece_tp_location_code,
3827 t_translated_customer_name,
3828 t_last_update_date,
3829 t_party_site_last_update_date,
3830 t_loc_last_update_date;
3831       IF l_po_loc_association_csr%FOUND THEN
3832          CLOSE l_po_loc_association_csr;
3833          IF t_customer_id <> l_customer_id THEN
3834             FND_MESSAGE.SET_NAME ('CSP', 'CSP_INV_LOC_HAS_ASSIGNED');
3835             FND_MESSAGE.SET_TOKEN ('LOC_ID', 'l_inv_location_id',false);
3836             FND_MESSAGE.SET_TOKEN ('CUSTOMER_ID', 't_customer_id',false);
3837             FND_MSG_PUB.ADD;
3838             RAISE EXCP_USER_DEFINED;
3839          ELSE
3840             IF p_status IS NOT NULL THEN
3841                t_status := p_status;
3842             END IF;
3843 
3844             IF p_primary_flag IS NOT NULL THEN
3845                t_primary_flag := p_primary_flag;
3846             END IF;
3847 
3848 	     IF l_timezone_id IS NOT NULL THEN
3849                update hz_locations set time_zone = l_timezone_id where location_id = t_site_loc_id;
3850             END IF;
3851 
3852          open  l_cust_acct_site(t_cust_acct_site_id);
3853          fetch l_cust_acct_site into l_attribute_category,
3854                                      l_attribute1,l_attribute2,l_attribute3,
3855                                      l_attribute4,l_attribute5,l_attribute6,
3856                                      l_attribute7,l_attribute8,l_attribute9,
3857                                      l_attribute10,l_attribute11,l_attribute12,
3858                                      l_attribute13,l_attribute14,l_attribute15,
3859                                      l_attribute16,l_attribute17,l_attribute18,
3860                                      l_attribute19,l_attribute20;
3861          close l_cust_acct_site;
3862 
3863             -- If p_primary_flag is not null or p_status is not null, calling from the
3864             -- Resource Ship To Address and Subinventory Assignments form, update it.
3865          IF p_status = 'I' THEN
3866             IF p_primary_flag IS NOT NULL or p_status IS NOT NULL THEN
3867                do_update_site_use
3868                  (p_site_use_id            => t_site_use_id
3869                  ,p_primary_flag           => p_primary_flag
3870                  ,p_status                 => p_status
3871                  ,p_customer_id            => l_customer_id
3872                  ,p_inv_location_id        => l_inv_location_id
3873                  ,x_return_status          => x_return_status
3874                  ,x_msg_count              => x_msg_count
3875                  ,x_msg_data               => x_msg_data);
3876             END IF;
3877 
3878             IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3879                Rollback to ship_to_address_handler_PUB;
3880                /*FND_MESSAGE.SET_NAME ('CSP', 'CSP_SITE_USE_API_ERROR');
3881                FND_MESSAGE.SET_TOKEN ('TEXT', x_msg_data);
3882                FND_MSG_PUB.ADD;*/
3883                RAISE EXCP_USER_DEFINED;
3884             END IF;
3885 
3886 
3887 			select last_update_date into t_last_update_date from hz_cust_acct_sites where CUST_ACCT_SITE_ID = t_cust_acct_site_id;
3888 
3889 
3890             -- Update the site location and related tables.
3891             arh_addr_pkg.update_row (
3892               X_Address_Id                          => t_cust_acct_site_id,
3893               X_Last_Update_Date                    => t_last_update_date,
3894               X_party_site_Last_Update_Date         => t_party_site_last_update_date,
3895               X_loc_Last_Update_Date                => t_loc_last_update_date,
3896               X_Last_Updated_By                     => nvl(fnd_global.user_id, 1),
3897               X_Status                              => t_status,
3898               X_Orig_System_Reference               => t_orig_system_reference,
3899               X_Country                             => s_country,
3900               X_Address1                            => s_address1,
3901               X_Address2                            => s_address2,
3902               X_Address3                            => s_address3,
3903               X_Address4                            => s_address4,
3904               X_City                                => s_city,
3905               X_Postal_Code                         => s_postal_code,
3906               X_State                               => s_state,
3907               X_Province                            => s_province,
3908               X_County                              => s_county,
3909               X_Last_Update_Login                   => nvl(fnd_global.user_id,1),
3910               X_Address_Key                         => s_address_key,
3911               X_Language                            => null,--s_language,
3912               X_Attribute_Category                  => l_attribute_category,
3913               X_Attribute1                          => l_attribute1,
3914               X_Attribute2                          => l_attribute2,
3915               X_Attribute3                          => l_attribute3,
3916               X_Attribute4                          => l_attribute4,
3917               X_Attribute5                          => l_attribute5,
3918               X_Attribute6                          => l_attribute6,
3919               X_Attribute7                          => l_attribute7,
3920               X_Attribute8                          => l_attribute8,
3921               X_Attribute9                          => l_attribute9,
3922               X_Attribute10                         => l_attribute10,
3923               X_Attribute11                         => l_attribute11,
3924               X_Attribute12                         => l_attribute12,
3925               X_Attribute13                         => l_attribute13,
3926               X_Attribute14                         => l_attribute14,
3927               X_Attribute15                         => l_attribute15,
3928               X_Attribute16                         => l_attribute16,
3929               X_Attribute17                         => l_attribute17,
3930               X_Attribute18                         => l_attribute18,
3931               X_Attribute19                         => l_attribute19,
3932               X_Attribute20                         => l_attribute20,
3933               X_Address_warning                     => s_address_warning,
3934               X_Address_Lines_Phonetic              => s_address_lines_phonetic,
3935               X_Global_Attribute_Category           => s_global_attribute_category,
3936               X_Global_Attribute1                   => s_global_attribute1,
3937               X_Global_Attribute2                   => s_global_attribute2,
3938               X_Global_Attribute3                   => s_global_attribute3,
3939               X_Global_Attribute4                   => s_global_attribute4,
3940               X_Global_Attribute5                   => s_global_attribute5,
3941               X_Global_Attribute6                   => s_global_attribute6,
3942               X_Global_Attribute7                   => s_global_attribute7,
3943               X_Global_Attribute8                   => s_global_attribute8,
3944               X_Global_Attribute9                   => s_global_attribute9,
3945               X_Global_Attribute10                  => s_global_attribute10,
3946               X_Global_Attribute11                  => s_global_attribute11,
3947               X_Global_Attribute12                  => s_global_attribute12,
3948               X_Global_Attribute13                  => s_global_attribute13,
3949               X_Global_Attribute14                  => s_global_attribute14,
3950               X_Global_Attribute15                  => s_global_attribute15,
3951               X_Global_Attribute16                  => s_global_attribute16,
3952               X_Global_Attribute17                  => s_global_attribute17,
3953               X_Global_Attribute18                  => s_global_attribute18,
3954               X_Global_Attribute19                  => s_global_attribute19,
3955               X_Global_Attribute20                  => s_global_attribute20,
3956               X_Party_site_id                       => t_party_site_id,
3957               X_Party_id                            => t_party_id,
3958               X_Location_id                         => t_site_loc_id,
3959               X_Party_Site_Number                   => t_party_site_number,
3960               X_Identifying_address_flag            => t_primary_flag,
3961               X_Cust_acct_site_id                   => t_cust_acct_site_id,
3962               X_Cust_account_id                     => l_customer_id,
3963               X_su_Bill_To_Flag                     => t_bill_to_flag,
3964               X_su_Ship_To_Flag                     => t_ship_to_flag,
3965               X_su_Market_Flag                      => t_market_flag,
3966               X_su_stmt_flag                        => s_su_stmt_flag,
3967               X_su_dun_flag                         => s_su_dun_flag,
3968               X_su_legal_flag                       => s_su_legal_flag,
3969               X_Customer_Category                   => t_customer_category,
3970               X_Key_Account_Flag                    => t_key_account_flag,
3971               X_Territory_id                        => t_territory_id,
3972               X_ece_tp_location_code                => t_ece_tp_location_code,
3973               x_address_mode                        => s_address_mode,
3974               X_Territory                           => t_territory,
3975               X_Translated_Customer_Name            => t_translated_customer_name,
3976               X_Sales_Tax_Geocode                   => s_sales_tax_geo_code,
3977               X_Sales_Tax_Inside_City_Limits        => s_sale_tax_inside_city_limits,
3978               x_ADDRESSEE                           => s_addressee,
3979               x_msg_count                           => x_msg_count,
3980               x_msg_data                            => x_msg_data,
3981               x_return_status                       => x_return_status);
3982 
3983             IF x_return_status in ('E','U') THEN
3984                Rollback to ship_to_address_handler_PUB;
3985                /*FND_MESSAGE.SET_NAME ('CSP', 'CSP_ADDR_API_ERROR');
3986                FND_MESSAGE.SET_TOKEN ('TEXT', x_msg_data);
3987                FND_MSG_PUB.ADD;*/
3988                RAISE EXCP_USER_DEFINED;
3989             END IF;
3990          ELSE
3991               arh_addr_pkg.update_row (
3992               X_Address_Id                          => t_cust_acct_site_id,
3993               X_Last_Update_Date                    => t_last_update_date,
3994               X_party_site_Last_Update_Date         => t_party_site_last_update_date,
3995               X_loc_Last_Update_Date                => t_loc_last_update_date,
3996               X_Last_Updated_By                     => nvl(fnd_global.user_id, 1),
3997               X_Status                              => t_status,
3998               X_Orig_System_Reference               => t_orig_system_reference,
3999               X_Country                             => s_country,
4000               X_Address1                            => s_address1,
4001               X_Address2                            => s_address2,
4002               X_Address3                            => s_address3,
4003               X_Address4                            => s_address4,
4004               X_City                                => s_city,
4005               X_Postal_Code                         => s_postal_code,
4006               X_State                               => s_state,
4007               X_Province                            => s_province,
4008               X_County                              => s_county,
4009               X_Last_Update_Login                   => nvl(fnd_global.user_id,1),
4010               X_Address_Key                         => s_address_key,
4011               X_Language                            => null,--s_language,
4012               X_Attribute_Category                  => l_attribute_category,
4013               X_Attribute1                          => l_attribute1,
4014               X_Attribute2                          => l_attribute2,
4015               X_Attribute3                          => l_attribute3,
4016               X_Attribute4                          => l_attribute4,
4017               X_Attribute5                          => l_attribute5,
4018               X_Attribute6                          => l_attribute6,
4019               X_Attribute7                          => l_attribute7,
4020               X_Attribute8                          => l_attribute8,
4021               X_Attribute9                          => l_attribute9,
4022               X_Attribute10                         => l_attribute10,
4023               X_Attribute11                         => l_attribute11,
4024               X_Attribute12                         => l_attribute12,
4025               X_Attribute13                         => l_attribute13,
4026               X_Attribute14                         => l_attribute14,
4027               X_Attribute15                         => l_attribute15,
4028               X_Attribute16                         => l_attribute16,
4029               X_Attribute17                         => l_attribute17,
4030               X_Attribute18                         => l_attribute18,
4031               X_Attribute19                         => l_attribute19,
4032               X_Attribute20                         => l_attribute20,
4033               X_Address_warning                     => s_address_warning,
4034               X_Address_Lines_Phonetic              => s_address_lines_phonetic,
4035               X_Global_Attribute_Category           => s_global_attribute_category,
4036               X_Global_Attribute1                   => s_global_attribute1,
4037               X_Global_Attribute2                   => s_global_attribute2,
4038               X_Global_Attribute3                   => s_global_attribute3,
4039               X_Global_Attribute4                   => s_global_attribute4,
4040               X_Global_Attribute5                   => s_global_attribute5,
4041               X_Global_Attribute6                   => s_global_attribute6,
4042               X_Global_Attribute7                   => s_global_attribute7,
4043               X_Global_Attribute8                   => s_global_attribute8,
4044               X_Global_Attribute9                   => s_global_attribute9,
4045               X_Global_Attribute10                  => s_global_attribute10,
4046               X_Global_Attribute11                  => s_global_attribute11,
4047               X_Global_Attribute12                  => s_global_attribute12,
4048               X_Global_Attribute13                  => s_global_attribute13,
4049               X_Global_Attribute14                  => s_global_attribute14,
4050               X_Global_Attribute15                  => s_global_attribute15,
4051               X_Global_Attribute16                  => s_global_attribute16,
4052               X_Global_Attribute17                  => s_global_attribute17,
4053               X_Global_Attribute18                  => s_global_attribute18,
4054               X_Global_Attribute19                  => s_global_attribute19,
4055               X_Global_Attribute20                  => s_global_attribute20,
4056               X_Party_site_id                       => t_party_site_id,
4057               X_Party_id                            => t_party_id,
4058               X_Location_id                         => t_site_loc_id,
4059               X_Party_Site_Number                   => t_party_site_number,
4060               X_Identifying_address_flag            => t_primary_flag,
4061               X_Cust_acct_site_id                   => t_cust_acct_site_id,
4062               X_Cust_account_id                     => l_customer_id,
4063               X_su_Bill_To_Flag                     => t_bill_to_flag,
4064               X_su_Ship_To_Flag                     => t_ship_to_flag,
4065               X_su_Market_Flag                      => t_market_flag,
4066               X_su_stmt_flag                        => s_su_stmt_flag,
4067               X_su_dun_flag                         => s_su_dun_flag,
4068               X_su_legal_flag                       => s_su_legal_flag,
4069               X_Customer_Category                   => t_customer_category,
4070               X_Key_Account_Flag                    => t_key_account_flag,
4071               X_Territory_id                        => t_territory_id,
4072               X_ece_tp_location_code                => t_ece_tp_location_code,
4073               x_address_mode                        => s_address_mode,
4074               X_Territory                           => t_territory,
4075               X_Translated_Customer_Name            => t_translated_customer_name,
4076               X_Sales_Tax_Geocode                   => s_sales_tax_geo_code,
4077               X_Sales_Tax_Inside_City_Limits        => s_sale_tax_inside_city_limits,
4078               x_ADDRESSEE                           => s_addressee,
4079               x_msg_count                           => x_msg_count,
4080               x_msg_data                            => x_msg_data,
4081               x_return_status                       => x_return_status);
4082 
4083             IF x_return_status in ('E','U') THEN
4084                Rollback to ship_to_address_handler_PUB;
4085                /*FND_MESSAGE.SET_NAME ('CSP', 'CSP_ADDR_API_ERROR');
4086                FND_MESSAGE.SET_TOKEN ('TEXT', x_msg_data);
4087                FND_MSG_PUB.ADD;*/
4088                RAISE EXCP_USER_DEFINED;
4089             END IF;
4090             IF p_primary_flag IS NOT NULL or p_status IS NOT NULL THEN
4091                do_update_site_use
4092                  (p_site_use_id            => t_site_use_id
4093                  ,p_primary_flag           => p_primary_flag
4094                  ,p_status                 => p_status
4095                  ,p_customer_id            => l_customer_id
4096                  ,p_inv_location_id        => l_inv_location_id
4097                  ,x_return_status          => x_return_status
4098                  ,x_msg_count              => x_msg_count
4099                  ,x_msg_data               => x_msg_data);
4100             END IF;
4101 
4102             IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4103                Rollback to ship_to_address_handler_PUB;
4104                /*FND_MESSAGE.SET_NAME ('CSP', 'CSP_SITE_USE_API_ERROR');
4105                FND_MESSAGE.SET_TOKEN ('TEXT', x_msg_data);
4106                FND_MSG_PUB.ADD;*/
4107                RAISE EXCP_USER_DEFINED;
4108             END IF;
4109 
4110          END IF;
4111          END IF;
4112       ELSE
4113          CLOSE l_po_loc_association_csr;
4114 
4115          -- If the party site number generation profile is yes or null, pass the party site number to the api
4116          IF fnd_profile.value('HZ_GENERATE_PARTY_SITE_NUMBER') <> 'N' THEN
4117             s_party_site_number := NULL;
4118          ELSE
4119             OPEN  l_party_site_number_csr;
4120             FETCH l_party_site_number_csr into s_party_site_number;
4121             CLOSE l_party_site_number_csr;
4122          END IF;
4123 
4124          IF p_primary_flag is not null THEN
4125             s_identifying_address_flag := p_primary_flag;
4126          ELSE
4127             -- Check if there is an existing party site with identifying address flag set to 'Y'
4128             -- Set the identifying address flag to 'Y' only if there is no existing one
4129             OPEN l_identify_address_flag_csr;
4130             FETCH l_identify_address_flag_csr INTO s_identifying_address_flag;
4131             IF l_identify_address_flag_csr%NOTFOUND THEN
4132                CLOSE l_identify_address_flag_csr;
4133                s_identifying_address_flag := 'Y';
4134             ELSE
4135                CLOSE l_identify_address_flag_csr;
4136                s_identifying_address_flag := 'N';
4137             END IF;
4138          END IF;
4139 
4140          IF p_status is not null THEN
4141             s_status := p_status;
4142          END IF;
4143 
4144 
4145 
4146           SELECT TO_NUMBER(DECODE(SUBSTRB(USERENV('CLIENT_INFO'),1,1), ' ', NULL,
4147 	        SUBSTRB(USERENV('CLIENT_INFO'),1,10)))
4148           INTO l_org_id
4149           FROM DUAL;
4150 
4151           mo_global.set_policy_context('S', l_org_id);
4152 
4153          -- create sites
4154           arh_addr_pkg.insert_row(
4155             X_Address_Id                     => s_cust_acct_site_id,
4156             X_Last_Update_Date               => sysdate,
4157             X_Last_Updated_By                => nvl(fnd_global.user_id,1),
4158             X_Creation_Date                  => sysdate,
4159             X_Created_By                     => nvl(fnd_global.user_id,1),
4160             X_Status                         => s_status,
4161             X_Orig_System_Reference          => s_orig_system_reference,
4162             X_Country                        => s_country,
4163             X_Address1                       => s_address1,
4164             X_Address2                       => s_address2,
4165             X_Address3                       => s_address3,
4166             X_Address4                       => s_address4,
4167             X_City                           => s_city,
4168             X_Postal_Code                    => s_postal_code,
4169             X_State                          => s_state,
4170             X_Province                       => s_province,
4171             X_County                         => s_county,
4172             X_Last_Update_Login              => nvl(fnd_global.user_id,1),
4173             X_Address_Key                    => s_address_key,
4174             X_Language                       => null,--s_language,
4175             X_Attribute_Category             => null,
4176             X_Attribute1                     => null,
4177             X_Attribute2                     => null,
4178             X_Attribute3                     => null,
4179             X_Attribute4                     => null,
4180             X_Attribute5                     => null,
4181             X_Attribute6                     => null,
4182             X_Attribute7                     => null,
4183             X_Attribute8                     => null,
4184             X_Attribute9                     => null,
4185             X_Attribute10                    => null,
4186             X_Attribute11                    => null,
4187             X_Attribute12                    => null,
4188             X_Attribute13                    => null,
4189             X_Attribute14                    => null,
4190             X_Attribute15                    => null,
4191             X_Attribute16                    => null,
4192             X_Attribute17                    => null,
4193             X_Attribute18                    => null,
4194             X_Attribute19                    => null,
4195             X_Attribute20                    => null,
4196             X_Address_warning                => s_address_warning,
4197             X_Address_Lines_Phonetic         => s_Address_Lines_Phonetic,
4198             X_Global_Attribute_Category      => s_global_attribute_category,
4199             X_Global_Attribute1              => s_global_attribute1,
4200             X_Global_Attribute2              => s_global_attribute2,
4201             X_Global_Attribute3              => s_global_attribute3,
4202             X_Global_Attribute4              => s_global_attribute4,
4203             X_Global_Attribute5              => s_global_attribute5,
4204             X_Global_Attribute6              => s_global_attribute6,
4205             X_Global_Attribute7              => s_global_attribute7,
4206             X_Global_Attribute8              => s_global_attribute8,
4207             X_Global_Attribute9              => s_global_attribute9,
4208             X_Global_Attribute10             => s_global_attribute10,
4209             X_Global_Attribute11             => s_global_attribute11,
4210             X_Global_Attribute12             => s_global_attribute12,
4211             X_Global_Attribute13             => s_global_attribute13,
4212             X_Global_Attribute14             => s_global_attribute14,
4213             X_Global_Attribute15             => s_global_attribute15,
4214             X_Global_Attribute16             => s_global_attribute16,
4215             X_Global_Attribute17             => s_global_attribute17,
4216             X_Global_Attribute18             => s_global_attribute18,
4217             X_Global_Attribute19             => s_global_attribute19,
4218             X_Global_Attribute20             => s_global_attribute20,
4219             X_Party_site_id                  => s_party_site_id,
4220             X_Party_id                       => l_party_id,
4221             X_Location_id                    => s_location_id,
4222             X_Party_Site_Number              => s_party_site_number,
4223             X_Identifying_address_flag       => s_identifying_address_flag,
4224             X_Cust_acct_site_id              => s_address_id,
4225             X_Cust_account_id                => l_customer_id,
4226             X_su_Bill_To_Flag                => s_su_bill_to_flag,
4227             X_su_Ship_To_Flag                => s_su_ship_to_flag,
4228             X_su_Market_Flag                 => s_su_market_flag,
4229             X_su_stmt_flag                   => s_su_stmt_flag,
4230             X_su_dun_flag                    => s_su_dun_flag,
4231             X_su_legal_flag                  => s_su_legal_flag,
4232             X_Customer_Category              => s_customer_category,
4233             X_Key_Account_Flag               => s_key_account_flag,
4234             X_Territory_id                   => s_territory_id,
4235             X_ece_tp_location_code           => s_ece_tp_location_code,
4236             x_address_mode                   => s_address_mode,
4237             x_territory                      => s_territory,
4238             x_translated_customer_name       => s_translated_customer_name,
4239             x_sales_tax_geo_code             => s_sales_tax_geo_code,
4240             x_sale_tax_inside_city_limits    => s_sale_tax_inside_city_limits,
4241             x_ADDRESSEE                      => s_addressee,
4242             x_shared_party_site              => s_shared_party_site,
4243             x_update_account_site            => s_update_account_site,
4244             x_create_location_party_site     => s_create_location_party_site,
4245             x_msg_count                      => x_msg_count,
4246             x_msg_data                       => x_msg_data,
4247             x_return_status                  => x_return_status);
4248 
4249          IF x_return_status in ('E','U') THEN
4250             Rollback to ship_to_address_handler_PUB;
4251             /*FND_MESSAGE.SET_NAME ('CSP', 'CSP_ADDR_API_ERROR');
4252             FND_MESSAGE.SET_TOKEN ('TEXT', x_msg_data);
4253             FND_MSG_PUB.ADD;*/
4254             RAISE EXCP_USER_DEFINED;
4255          END IF;
4256 
4257          IF l_timezone_id IS NOT NULL THEN
4258             update hz_locations set time_zone = l_timezone_id where location_id = s_location_id;
4259          END IF;
4260 
4261           -- Create site use to link to the inventory location
4262           do_create_site_use(
4263              p_customer_id              => l_customer_id,
4264              p_party_id                 => l_party_id,
4265              p_address_id               => s_address_id,
4266              p_location_id              => s_location_id,
4267              p_inv_location_id          => l_inv_location_id,
4268              p_primary_flag             => s_identifying_address_flag,
4269              p_status                   => s_status,
4270 	     p_bill_to_create			=> p_bill_to_create,
4271              x_return_status            => x_return_status,
4272              x_msg_count                => x_msg_count,
4273              x_msg_data                 => x_msg_data);
4274 
4275          IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4276             Rollback to ship_to_address_handler_PUB;
4277             /*FND_MESSAGE.SET_NAME ('CSP', 'CSP_SITE_USE_API_ERROR');
4278             FND_MESSAGE.SET_TOKEN ('TEXT', x_msg_data);
4279             FND_MSG_PUB.ADD;*/
4280             RAISE EXCP_USER_DEFINED;
4281          END IF;
4282       END IF;
4283    END;
4284    END IF;
4285 
4286    -- Return location_id and customer_id.
4287    p_location_id := l_inv_location_id;
4288    p_customer_id := l_customer_id;
4289 
4290 --   -- Create or update resource/customer relationship record in csp_rs_cust_relations
4291 --   do_rs_cust_relations(l_resource_type, l_resource_id, l_resource_name, l_customer_id);
4292   csp_ship_to_address_pvt.g_inv_loc_id := l_inv_location_id;
4293   IF l_process_type = 'INSERT' THEN
4294    csp_ship_to_address_pvt.call_internal_hook('CSP_SHIP_TO_ADDRESS_PVT','SHIP_TO_ADDRESS_HANDLER','A',x_return_status);
4295   ELSIF l_process_type = 'UPDATE' THEN
4296    csp_ship_to_address_pvt.call_internal_hook('CSP_SHIP_TO_ADDRESS_PVT','UPDATE_LOCATION','A',x_return_status);
4297   END IF;
4298    -- If no error occurs, commit.
4299    IF p_commit = FND_API.G_TRUE THEN
4300       COMMIT;
4301    END IF;
4302 
4303    fnd_msg_pub.count_and_get
4304       ( p_count => x_msg_count
4305       , p_data  => x_msg_data);
4306 
4307    -- Exception Block --
4308   EXCEPTION
4309       WHEN EXCP_USER_DEFINED THEN
4310          Rollback to ship_to_address_handler_PUB;
4311          x_return_status := FND_API.G_RET_STS_ERROR;
4312         JTF_PLSQL_API.HANDLE_EXCEPTIONS(
4313             P_API_NAME => L_API_NAME
4314            ,P_PKG_NAME => G_PKG_NAME
4315            ,P_EXCEPTION_LEVEL => FND_MSG_PUB.G_MSG_LVL_ERROR
4316            ,P_PACKAGE_TYPE => JTF_PLSQL_API.G_PUB
4317            ,X_MSG_COUNT    => X_MSG_COUNT
4318            ,X_MSG_DATA     => X_MSG_DATA
4319            ,X_RETURN_STATUS => X_RETURN_STATUS);
4320       WHEN FND_API.G_EXC_ERROR THEN
4321          JTF_PLSQL_API.HANDLE_EXCEPTIONS(
4322             P_API_NAME => L_API_NAME
4323            ,P_PKG_NAME => G_PKG_NAME
4324            ,P_EXCEPTION_LEVEL => FND_MSG_PUB.G_MSG_LVL_ERROR
4325            ,P_PACKAGE_TYPE => JTF_PLSQL_API.G_PUB
4326            ,X_MSG_COUNT    => X_MSG_COUNT
4327            ,X_MSG_DATA     => X_MSG_DATA
4328            ,X_RETURN_STATUS => X_RETURN_STATUS);
4329       WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4330          JTF_PLSQL_API.HANDLE_EXCEPTIONS(
4331             P_API_NAME => L_API_NAME
4332             ,P_PKG_NAME => G_PKG_NAME
4333             ,P_EXCEPTION_LEVEL => FND_MSG_PUB.G_MSG_LVL_ERROR
4334             ,P_PACKAGE_TYPE => JTF_PLSQL_API.G_PUB
4335             ,X_MSG_COUNT    => X_MSG_COUNT
4336             ,X_MSG_DATA     => X_MSG_DATA
4337             ,X_RETURN_STATUS => X_RETURN_STATUS);
4338       WHEN OTHERS THEN
4339          Rollback to ship_to_address_handler_PUB;
4340          FND_MESSAGE.SET_NAME('CSP', 'CSP_UNEXPECTED_EXEC_ERRORS');
4341          FND_MESSAGE.SET_TOKEN('ROUTINE', l_api_name, false);
4342          FND_MESSAGE.SET_TOKEN('SQLERRM', sqlerrm, false);
4343          FND_MSG_PUB.ADD;
4344          fnd_msg_pub.count_and_get
4345            ( p_count => x_msg_count
4346            , p_data  => x_msg_data);
4347          x_return_status := FND_API.G_RET_STS_ERROR;
4348 
4349 END ship_to_address_handler;
4350 
4351 
4352 ------------------------------------------------------------------------------------------
4353 -- Procedure Name   : site_to_invloc_linkage
4354 -- Purpose          : This procedure will create a new inventory location and link the
4355 --                    site use id passed in to the new inventory location.
4356 -- Note             : Before calling this proceudre, make sure the site_use is not linked to
4357 --                    any inventory location yet.
4358 --
4359 /* commented for bug
4360 
4361   PROCEDURE site_to_invloc_linkage
4362   (p_customer_id             IN NUMBER
4363   ,p_address_id              IN NUMBER
4364   ,p_site_use_id             IN NUMBER
4365   ,p_location_id             OUT NOCOPY NUMBER
4366   ,p_style                   IN VARCHAR2
4367   ,p_address_line_1          IN VARCHAR2
4368   ,p_address_line_2          IN VARCHAR2
4369   ,p_address_line_3          IN VARCHAR2
4370   ,p_country                 IN VARCHAR2
4371   ,p_postal_code             IN VARCHAR2
4372   ,p_region_1                IN VARCHAR2
4373   ,p_region_2                IN VARCHAR2
4374   ,p_region_3                IN VARCHAR2
4375   ,p_town_or_city            IN VARCHAR2
4376   ,p_tax_name                IN VARCHAR2
4377   ,p_telephone_number_1      IN VARCHAR2
4378   ,p_telephone_number_2      IN VARCHAR2
4379   ,p_telephone_number_3      IN VARCHAR2
4380   ,p_loc_information13       IN VARCHAR2
4381   ,p_loc_information14       IN VARCHAR2
4382   ,p_loc_information15       IN VARCHAR2
4383   ,p_loc_information16       IN VARCHAR2
4384   ,p_loc_information17       IN VARCHAR2
4385   ,p_loc_information18       IN VARCHAR2
4386   ,p_loc_information19       IN VARCHAR2
4387   ,p_loc_information20       IN VARCHAR2
4388   ,p_api_version_number      IN NUMBER
4389   ,p_init_msg_list           IN VARCHAR2
4390   ,p_attribute_category     IN VARCHAR2
4391    ,p_attribute1             IN VARCHAR2
4392    ,p_attribute2             IN VARCHAR2
4393    ,p_attribute3             IN VARCHAR2
4394    ,p_attribute4             IN VARCHAR2
4395    ,p_attribute5             IN VARCHAR2
4396    ,p_attribute6             IN VARCHAR2
4397    ,p_attribute7             IN VARCHAR2
4398    ,p_attribute8             IN VARCHAR2
4399    ,p_attribute9             IN VARCHAR2
4400    ,p_attribute10             IN VARCHAR2
4401    ,p_attribute11             IN VARCHAR2
4402    ,p_attribute12             IN VARCHAR2
4403    ,p_attribute13            IN VARCHAR2
4404    ,p_attribute14             IN VARCHAR2
4405    ,p_attribute15             IN VARCHAR2
4406    ,p_attribute16             IN VARCHAR2
4407    ,p_attribute17             IN VARCHAR2
4408    ,p_attribute18             IN VARCHAR2
4409    ,p_attribute19             IN VARCHAR2
4410    ,p_attribute20             IN VARCHAR2
4411   ,x_return_status           OUT NOCOPY VARCHAR2
4412   ,x_msg_count               OUT NOCOPY NUMBER
4413   ,x_msg_data                OUT NOCOPY VARCHAR2) IS
4414 
4415    l_api_version_number      CONSTANT NUMBER := 1.0;
4416    l_api_name                CONSTANT VARCHAR2(30) := 'site_to_invloc_linkage';
4417    EXCP_USER_DEFINED         EXCEPTION;
4418    l_inv_loc_id              hr_locations.location_id%type;
4419    l_object_version_number   hr_locations.object_version_number%type;
4420 
4421 BEGIN
4422    SAVEPOINT site_to_invloc_linkage_PUB;
4423 
4424    -- initialize message list
4425    FND_MSG_PUB.initialize;
4426 
4427    IF NOT FND_API.Compatible_API_Call ( l_api_version_number,
4428                                         p_api_version_number,
4429                                         l_api_name,
4430                                         G_PKG_NAME) THEN
4431       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4432    END IF;
4433 
4434    x_return_status := FND_API.G_RET_STS_SUCCESS;
4435 
4436    -- If site use id is null, return error.
4437    IF p_site_use_id IS NULL THEN
4438       FND_MESSAGE.SET_NAME ('CSP', 'CSP_SITE_USE_ID_REQD');
4439       FND_MSG_PUB.ADD;
4440       RAISE EXCP_USER_DEFINED;
4441    END IF;
4442 
4443    -- If address fields are not null, create a new inventory location.  Otherwise, return error.
4444    IF p_country IS NOT NULL THEN
4445       do_create_ship_to_location(
4446       p_location_id            => p_location_id,
4447       p_style                  => p_style,
4448       p_address_line_1         => p_address_line_1,
4449       p_address_line_2         => p_address_line_2,
4450       p_address_line_3         => p_address_line_3,
4451       p_country                => p_country,
4452       p_postal_code            => p_postal_code,
4453       p_region_1               => p_region_1,
4454       p_region_2               => p_region_2,
4455       p_region_3               => p_region_3,
4456       p_town_or_city           => p_town_or_city,
4457       p_tax_name               => p_tax_name,
4458       p_telephone_number_1     => p_telephone_number_1,
4459       p_telephone_number_2     => p_telephone_number_2,
4460       p_telephone_number_3     => p_telephone_number_3,
4461       p_loc_information13      => p_loc_information13,
4462       p_loc_information14      => p_loc_information14,
4463       p_loc_information15      => p_loc_information15,
4464       p_loc_information16      => p_loc_information16,
4465       p_loc_information17      => p_loc_information17,
4466       p_loc_information18      => p_loc_information18,
4467       p_loc_information19      => p_loc_information19,
4468       p_loc_information20      => p_loc_information20,
4469       p_object_version_number  => l_object_version_number,
4470        p_attribute1                  => p_attribute1,
4471       p_attribute2                  => p_attribute2,
4472       p_attribute3                  => p_attribute3,
4473       p_attribute4                  => p_attribute4,
4474       p_attribute5                  => p_attribute5,
4475       p_attribute6                  => p_attribute6,
4476       p_attribute7                  => p_attribute7,
4477       p_attribute8                  => p_attribute8,
4478       p_attribute9                  => p_attribute9,
4479       p_attribute10                  => p_attribute10,
4480       p_attribute11                  => p_attribute11,
4481       p_attribute12                  => p_attribute12,
4482       p_attribute13                  => p_attribute13,
4483       p_attribute14                  => p_attribute14,
4484       p_attribute15                  => p_attribute15,
4485       p_attribute16                  => p_attribute16,
4486       p_attribute17                  => p_attribute17,
4487       p_attribute18                  => p_attribute18,
4488       p_attribute19                  => p_attribute19,
4489       p_attribute20                  => p_attribute20,
4490       p_attribute_category          => p_attribute_category,
4491       x_return_status          => x_return_status,
4492       x_msg_count              => x_msg_count,
4493       x_msg_data               => x_msg_data);
4494 
4495       l_inv_loc_id := p_location_id;
4496       IF x_return_status in ('E','U') THEN
4497          Rollback to site_to_invloc_linkage_PUB;
4498          /*FND_MESSAGE.SET_NAME ('CSP', 'CSP_STA_API_ERROR');
4499          FND_MESSAGE.SET_TOKEN ('TEXT', x_msg_data);
4500          FND_MSG_PUB.ADD;*/
4501   /*       RAISE EXCP_USER_DEFINED;
4502       ELSE
4503 
4504          -- Create the linkage between the site use and the inventory location.
4505          arp_clas_pkg.insert_po_loc_associations(
4506             p_inventory_location_id       => l_inv_loc_id,
4507             p_inventory_organization_id   => null,
4508             p_customer_id                 => p_customer_id,
4509             p_address_id                  => p_address_id,
4510             p_site_use_id                 => p_site_use_id);
4511 
4512       END IF;
4513    ELSE
4514       Rollback to site_to_invloc_linkage_PUB;
4515       FND_MESSAGE.SET_NAME ('CSP', 'CSP_ADDRESS_REQD');
4516       FND_MESSAGE.SET_TOKEN ('TEXT', x_msg_data,false);
4517       FND_MSG_PUB.ADD;
4518       RAISE EXCP_USER_DEFINED;
4519    END IF;
4520 
4521    EXCEPTION
4522       WHEN EXCP_USER_DEFINED THEN
4523          x_return_status := FND_API.G_RET_STS_ERROR;
4524          fnd_msg_pub.count_and_get
4525          ( p_count   => x_msg_count
4526          , p_data    => x_msg_data);
4527       WHEN FND_API.G_EXC_ERROR THEN
4528          JTF_PLSQL_API.HANDLE_EXCEPTIONS(
4529             P_API_NAME => L_API_NAME
4530            ,P_PKG_NAME => G_PKG_NAME
4531            ,P_EXCEPTION_LEVEL => FND_MSG_PUB.G_MSG_LVL_ERROR
4532            ,P_PACKAGE_TYPE => JTF_PLSQL_API.G_PUB
4533            ,X_MSG_COUNT    => x_MSG_COUNT
4534            ,X_MSG_DATA     => x_MSG_DATA
4535            ,X_RETURN_STATUS => x_RETURN_STATUS);
4536       WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4537          JTF_PLSQL_API.HANDLE_EXCEPTIONS(
4538             P_API_NAME => L_API_NAME
4539            ,P_PKG_NAME => G_PKG_NAME
4540            ,P_EXCEPTION_LEVEL => FND_MSG_PUB.G_MSG_LVL_ERROR
4541            ,P_PACKAGE_TYPE => JTF_PLSQL_API.G_PUB
4542            ,X_MSG_COUNT    => x_MSG_COUNT
4543            ,X_MSG_DATA     => x_MSG_DATA
4544            ,X_RETURN_STATUS => x_RETURN_STATUS);
4545       WHEN OTHERS THEN
4546          Rollback to site_to_invloc_linkage_PUB;
4547          FND_MESSAGE.SET_NAME('CSP', 'CSP_UNEXPECTED_EXEC_ERRORS');
4548          FND_MESSAGE.SET_TOKEN('ROUTINE', l_api_name, false);
4549          FND_MESSAGE.SET_TOKEN('SQLERRM', sqlerrm, false);
4550          FND_MSG_PUB.ADD;
4551          fnd_msg_pub.count_and_get
4552            ( p_count => x_msg_count
4553            , p_data  => x_msg_data);
4554          x_return_status := FND_API.G_RET_STS_ERROR;
4555 
4556 END site_to_invloc_linkage; */
4557 PROCEDURE site_to_invloc_linkage
4558   (p_customer_id             IN NUMBER
4559   ,p_address_id              IN NUMBER
4560   ,p_site_use_id             IN NUMBER
4561   ,p_location_id             OUT NOCOPY NUMBER
4562   ,p_style                   IN VARCHAR2
4563   ,p_address_line_1          IN VARCHAR2
4564   ,p_address_line_2          IN VARCHAR2
4565   ,p_address_line_3          IN VARCHAR2
4566   ,p_country                 IN VARCHAR2
4567   ,p_postal_code             IN VARCHAR2
4568   ,p_region_1                IN VARCHAR2
4569   ,p_region_2                IN VARCHAR2
4570   ,p_region_3                IN VARCHAR2
4571   ,p_town_or_city            IN VARCHAR2
4572   ,p_tax_name                IN VARCHAR2
4573   ,p_telephone_number_1      IN VARCHAR2
4574   ,p_telephone_number_2      IN VARCHAR2
4575   ,p_telephone_number_3      IN VARCHAR2
4576   ,p_loc_information13       IN VARCHAR2
4577   ,p_loc_information14       IN VARCHAR2
4578   ,p_loc_information15       IN VARCHAR2
4579   ,p_loc_information16       IN VARCHAR2
4580   ,p_loc_information17       IN VARCHAR2
4581   ,p_loc_information18       IN VARCHAR2
4582   ,p_loc_information19       IN VARCHAR2
4583   ,p_loc_information20       IN VARCHAR2
4584   ,p_api_version_number      IN NUMBER
4585   ,p_init_msg_list           IN VARCHAR2
4586   ,p_attribute_category     IN VARCHAR2
4587    ,p_attribute1             IN VARCHAR2
4588    ,p_attribute2             IN VARCHAR2
4589    ,p_attribute3             IN VARCHAR2
4590    ,p_attribute4             IN VARCHAR2
4591    ,p_attribute5             IN VARCHAR2
4592    ,p_attribute6             IN VARCHAR2
4593    ,p_attribute7             IN VARCHAR2
4594    ,p_attribute8             IN VARCHAR2
4595    ,p_attribute9             IN VARCHAR2
4596    ,p_attribute10             IN VARCHAR2
4597    ,p_attribute11             IN VARCHAR2
4598    ,p_attribute12             IN VARCHAR2
4599    ,p_attribute13            IN VARCHAR2
4600    ,p_attribute14             IN VARCHAR2
4601    ,p_attribute15             IN VARCHAR2
4602    ,p_attribute16             IN VARCHAR2
4603    ,p_attribute17             IN VARCHAR2
4604    ,p_attribute18             IN VARCHAR2
4605    ,p_attribute19             IN VARCHAR2
4606    ,p_attribute20             IN VARCHAR2
4607   ,x_return_status           OUT NOCOPY VARCHAR2
4608   ,x_msg_count               OUT NOCOPY NUMBER
4609   ,x_msg_data                OUT NOCOPY VARCHAR2) IS
4610 
4611    l_api_version_number      CONSTANT NUMBER := 1.0;
4612    l_api_name                CONSTANT VARCHAR2(30) := 'site_to_invloc_linkage';
4613    EXCP_USER_DEFINED         EXCEPTION;
4614    l_inv_loc_id              hr_locations.location_id%type;
4615    l_object_version_number   hr_locations.object_version_number%type;
4616  l_town_or_city varchar2(30);
4617    l_region_1 varchar2(120);
4618    cursor get_csp_location is
4619    select STYLE,ADDRESS_LINE_1,ADDRESS_LINE_2,ADDRESS_LINE_3,TOWN_OR_CITY,COUNTRY
4620         ,POSTAL_CODE,REGION_1,REGION_2,REGION_3,TELEPHONE_NUMBER_1,TELEPHONE_NUMBER_2,TELEPHONE_NUMBER_3,LOC_INFORMATION13
4621         ,LOC_INFORMATION14,LOC_INFORMATION15,LOC_INFORMATION16,LOC_INFORMATION17,LOC_INFORMATION18,LOC_INFORMATION19
4622         ,LOC_INFORMATION20,ATTRIBUTE_CATEGORY,ATTRIBUTE1,ATTRIBUTE2,ATTRIBUTE3,ATTRIBUTE4,ATTRIBUTE5
4623         ,ATTRIBUTE6,ATTRIBUTE7,ATTRIBUTE8,ATTRIBUTE9,ATTRIBUTE10,ATTRIBUTE11,ATTRIBUTE12,ATTRIBUTE13,ATTRIBUTE14,ATTRIBUTE15
4624         ,ATTRIBUTE16,ATTRIBUTE17,ATTRIBUTE18,ATTRIBUTE19,ATTRIBUTE20,TAX_NAME
4625     from hr_locations
4626     where location_code like 'CSP%'
4627     and country = p_country ;
4628 
4629     cursor get_country_location is
4630    select STYLE,ADDRESS_LINE_1,ADDRESS_LINE_2,ADDRESS_LINE_3,TOWN_OR_CITY,COUNTRY
4631         ,POSTAL_CODE,REGION_1,REGION_2,REGION_3,TELEPHONE_NUMBER_1,TELEPHONE_NUMBER_2,TELEPHONE_NUMBER_3,LOC_INFORMATION13
4632         ,LOC_INFORMATION14,LOC_INFORMATION15,LOC_INFORMATION16,LOC_INFORMATION17,LOC_INFORMATION18,LOC_INFORMATION19
4633         ,LOC_INFORMATION20,ATTRIBUTE_CATEGORY,ATTRIBUTE1,ATTRIBUTE2,ATTRIBUTE3,ATTRIBUTE4,ATTRIBUTE5
4634         ,ATTRIBUTE6,ATTRIBUTE7,ATTRIBUTE8,ATTRIBUTE9,ATTRIBUTE10,ATTRIBUTE11,ATTRIBUTE12,ATTRIBUTE13,ATTRIBUTE14,ATTRIBUTE15
4635         ,ATTRIBUTE16,ATTRIBUTE17,ATTRIBUTE18,ATTRIBUTE19,ATTRIBUTE20,TAX_NAME
4636     from hr_locations
4637     where country = p_country ;
4638 
4639     csp_location_rec get_csp_location%ROWTYPE;
4640      l_org_id   number;
4641      l_ou_id    number;
4642      l_cust_acct_id number;     -- bug # 12545721
4643 BEGIN
4644 
4645    if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
4646      FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4647                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4648                      'Begin');
4649    end if;
4650 
4651    SAVEPOINT site_to_invloc_linkage_PUB;
4652 
4653    -- initialize message list
4654    FND_MSG_PUB.initialize;
4655 
4656    IF NOT FND_API.Compatible_API_Call ( l_api_version_number,
4657                                         p_api_version_number,
4658                                         l_api_name,
4659                                         G_PKG_NAME) THEN
4660 
4661    if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
4662      FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4663                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4664                      'In FND_API.Compatible_API_Call');
4665    end if;
4666 
4667       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4668    END IF;
4669 
4670    x_return_status := FND_API.G_RET_STS_SUCCESS;
4671 
4672    -- If site use id is null, return error.
4673    IF p_site_use_id IS NULL THEN
4674       FND_MESSAGE.SET_NAME ('CSP', 'CSP_SITE_USE_ID_REQD');
4675       FND_MSG_PUB.ADD;
4676        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
4677           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4678                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4679                      'In CSP_SITE_USE_ID_REQD error');
4680        end if;
4681       RAISE EXCP_USER_DEFINED;
4682    END IF;
4683  IF fnd_profile.value('CSP_INTRANSIT_LOCATION_USED') = 'Y' THEN
4684          if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
4685           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4686                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4687                      'In CSP_INTRANSIT_LOCATION_USED condition');
4688        end if;
4689    -- If address fields are not null, create a new inventory location.  Otherwise, return error.
4690    IF p_country IS NOT NULL THEN
4691        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
4692           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4693                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4694                      'In CSP_INTRANSIT_LOCATION_USED : p_country condition');
4695        end if;
4696         if  p_country = 'US' THEN
4697            l_town_or_city := initcap(p_town_or_city);
4698            l_region_1 :=initcap(p_region_1);
4699         else
4700             l_town_or_city := p_town_or_city;
4701            l_region_1 :=p_region_1;
4702         end if;
4703        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
4704           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4705                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4706                      'l_town_or_city = ' || l_town_or_city
4707                      || ', l_region_1' || l_region_1);
4708           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4709                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4710                      'Before calling do_create_ship_to_location');
4711        end if;
4712       do_create_ship_to_location(
4713       p_location_id            => p_location_id,
4714       p_style                  => p_style,
4715       p_address_line_1         => p_address_line_1,
4716       p_address_line_2         => p_address_line_2,
4717       p_address_line_3         => p_address_line_3,
4718       p_country                => p_country,
4719       p_postal_code            => p_postal_code,
4720       p_region_1               => l_region_1,
4721       p_region_2               => p_region_2,
4722       p_region_3               => p_region_3,
4723       p_town_or_city           => l_town_or_city,
4724       p_tax_name               => p_tax_name,
4725       p_telephone_number_1     => p_telephone_number_1,
4726       p_telephone_number_2     => p_telephone_number_2,
4727       p_telephone_number_3     => p_telephone_number_3,
4728       p_loc_information13      => p_loc_information13,
4729       p_loc_information14      => p_loc_information14,
4730       p_loc_information15      => p_loc_information15,
4731       p_loc_information16      => p_loc_information16,
4732       p_loc_information17      => p_loc_information17,
4733       p_loc_information18      => p_loc_information18,
4734       p_loc_information19      => p_loc_information19,
4735       p_loc_information20      => p_loc_information20,
4736       p_object_version_number  => l_object_version_number,
4737        p_attribute1                  => p_attribute1,
4738       p_attribute2                  => p_attribute2,
4739       p_attribute3                  => p_attribute3,
4740       p_attribute4                  => p_attribute4,
4741       p_attribute5                  => p_attribute5,
4742       p_attribute6                  => p_attribute6,
4743       p_attribute7                  => p_attribute7,
4744       p_attribute8                  => p_attribute8,
4745       p_attribute9                  => p_attribute9,
4746       p_attribute10                  => p_attribute10,
4747       p_attribute11                  => p_attribute11,
4748       p_attribute12                  => p_attribute12,
4749       p_attribute13                  => p_attribute13,
4750       p_attribute14                  => p_attribute14,
4751       p_attribute15                  => p_attribute15,
4752       p_attribute16                  => p_attribute16,
4753       p_attribute17                  => p_attribute17,
4754       p_attribute18                  => p_attribute18,
4755       p_attribute19                  => p_attribute19,
4756       p_attribute20                  => p_attribute20,
4757       p_attribute_category          => p_attribute_category,
4758       x_return_status          => x_return_status,
4759       x_msg_count              => x_msg_count,
4760       x_msg_data               => x_msg_data);
4761 
4762        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
4763           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4764                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4765                      'After do_create_ship_to_location... x_return_status = ' || x_return_status);
4766        end if;
4767 
4768       l_inv_loc_id := p_location_id;
4769       IF x_return_status in ('E','U') THEN
4770          Rollback to site_to_invloc_linkage_PUB;
4771          /*FND_MESSAGE.SET_NAME ('CSP', 'CSP_STA_API_ERROR');
4772          FND_MESSAGE.SET_TOKEN ('TEXT', x_msg_data);
4773          FND_MSG_PUB.ADD;*/
4774          RAISE EXCP_USER_DEFINED;
4775       ELSE
4776 
4777        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
4778           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4779                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4780                      'p_address_id = ' || p_address_id);
4781        end if;
4782 
4783            SELECT  org_id
4784            INTO    l_org_id
4785            FROM    HZ_CUST_ACCT_SITES_ALL
4786            WHERE   cust_acct_site_id = p_address_id;
4787 
4788        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
4789           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4790                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4791                      'l_org_id = ' || l_org_id);
4792        end if;
4793 
4794            /*
4795            select operating_unit
4796            into l_ou_id
4797            from org_organization_Definitions
4798            where organization_id = l_org_id;
4799            */
4800            l_ou_id := l_org_id;
4801 
4802        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
4803           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4804                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4805                      'l_ou_id = ' || l_ou_id);
4806        end if;
4807 
4808           SELECT TO_NUMBER(DECODE(SUBSTRB(USERENV('CLIENT_INFO'),1,1), ' ', NULL, SUBSTRB(USERENV('CLIENT_INFO'),1,10)))
4809           INTO   l_org_id
4810           FROM   dual;
4811 
4812        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
4813           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4814                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4815                      'l_org_id = ' || l_org_id);
4816        end if;
4817 
4818           mo_global.set_policy_context('S', l_ou_id);
4819 
4820        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
4821           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4822                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4823                      'Before calling arp_clas_pkg.insert_po_loc_associations');
4824        end if;
4825 
4826        select cust_account_id into l_cust_acct_id
4827         from hz_cust_acct_sites_all
4828         where cust_acct_site_id = p_address_id;
4829 
4830        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
4831           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4832                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4833                      'l_cust_acct_id = ' || l_cust_acct_id);
4834        end if;
4835 
4836          -- Create the linkage between the site use and the inventory location.
4837          arp_clas_pkg.insert_po_loc_associations(
4838             p_inventory_location_id       => l_inv_loc_id,
4839             p_inventory_organization_id   => null,
4840             p_customer_id                 => l_cust_acct_id,
4841             p_address_id                  => p_address_id,
4842             p_site_use_id                 => p_site_use_id,
4843             x_return_status               => x_return_status,
4844              x_msg_count                   => x_msg_count,
4845              x_msg_data                    => x_msg_data);
4846 
4847           mo_global.set_policy_context('S', l_org_id);
4848 
4849        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
4850           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4851                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4852                      'After calling arp_clas_pkg.insert_po_loc_associations');
4853           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4854                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4855                      'x_return_status = ' || x_return_status);
4856        end if;
4857 
4858        IF x_return_status in ('E','U') THEN
4859           Rollback to site_to_invloc_linkage_PUB;
4860           RAISE EXCP_USER_DEFINED;
4861        END IF;
4862 
4863       END IF;
4864    ELSE
4865       Rollback to site_to_invloc_linkage_PUB;
4866        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
4867           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4868                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4869                      'p_country is NULL');
4870        end if;
4871       FND_MESSAGE.SET_NAME ('CSP', 'CSP_ADDRESS_REQD');
4872       FND_MESSAGE.SET_TOKEN ('TEXT', x_msg_data);
4873       FND_MSG_PUB.ADD;
4874       RAISE EXCP_USER_DEFINED;
4875    END IF;
4876  ELSE
4877        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
4878           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4879                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4880                      'Else part : CSP_INTRANSIT_LOCATION_USED is N');
4881        end if;
4882 
4883    OPEN  get_csp_location;
4884    FETCH get_csp_location INTO csp_location_rec;
4885    CLOSE get_csp_location;
4886 
4887        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
4888           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4889                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4890                      'csp_location_rec.country = ' || csp_location_rec.country);
4891        end if;
4892 
4893    IF csp_location_rec.country IS NULL THEN
4894       OPEN  get_country_location;
4895       FETCH get_country_location INTO csp_location_rec;
4896       CLOSE get_country_location;
4897    END IF;
4898      csp_location_rec.ADDRESS_LINE_1 := FND_MESSAGE.GET_STRING('CSP', 'CSP_ADDRESS_DESC');
4899 
4900    -- If address fields are not null, create a new inventory location.  Otherwise, return error.
4901    IF p_country IS NOT NULL THEN
4902 
4903        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
4904           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4905                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4906                      'p_country is NOT NULL and p_country = ' || p_country);
4907           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4908                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4909                      'Before calling do_create_ship_to_location...');
4910        end if;
4911 
4912      do_create_ship_to_location(
4913       p_location_id            => p_location_id,
4914       p_style                  => csp_location_rec.style,
4915       p_address_line_1         => csp_location_rec.ADDRESS_LINE_1 ,
4916       p_address_line_2         => csp_location_rec.ADDRESS_LINE_2,
4917       p_address_line_3         => csp_location_rec.ADDRESS_LINE_3,
4918       p_country                => csp_location_rec.country,
4919       p_postal_code            => csp_location_rec.postal_code,
4920       p_region_1               => csp_location_rec.region_1,
4921       p_region_2               => csp_location_rec.region_2,
4922       p_region_3               => csp_location_rec.region_3,
4923       p_town_or_city           => csp_location_rec.town_or_city,
4924       p_tax_name               => csp_location_rec.tax_name,
4925       p_telephone_number_1     => csp_location_rec.telephone_number_1,
4926       p_telephone_number_2     => csp_location_rec.telephone_number_2,
4927       p_telephone_number_3     =>csp_location_rec.telephone_number_3,
4928       p_loc_information13      => csp_location_rec.loc_information13,
4929       p_loc_information14      => csp_location_rec.loc_information14,
4930       p_loc_information15      => csp_location_rec.loc_information15,
4931       p_loc_information16      => csp_location_rec.loc_information16,
4932       p_loc_information17      => csp_location_rec.loc_information17,
4933       p_loc_information18      => csp_location_rec.loc_information18,
4934       p_loc_information19      => csp_location_rec.loc_information19,
4935       p_loc_information20      => csp_location_rec.loc_information20,
4936       p_object_version_number  => l_object_version_number,
4937        p_attribute1                  => csp_location_rec.attribute1,
4938       p_attribute2                  => csp_location_rec.attribute2,
4939       p_attribute3                  => csp_location_rec.attribute3,
4940       p_attribute4                  => csp_location_rec.attribute4,
4941       p_attribute5                  => csp_location_rec.attribute5,
4942       p_attribute6                  => csp_location_rec.attribute6,
4943       p_attribute7                  => csp_location_rec.attribute7,
4944       p_attribute8                  => csp_location_rec.attribute8,
4945       p_attribute9                  => csp_location_rec.attribute9,
4946       p_attribute10                  => csp_location_rec.attribute10,
4947       p_attribute11                  => csp_location_rec.attribute11,
4948       p_attribute12                  => csp_location_rec.attribute12,
4949       p_attribute13                  => csp_location_rec.attribute13,
4950       p_attribute14                  => csp_location_rec.attribute14,
4951       p_attribute15                  => csp_location_rec.attribute15,
4952       p_attribute16                  => csp_location_rec.attribute16,
4953       p_attribute17                  => csp_location_rec.attribute17,
4954       p_attribute18                  => csp_location_rec.attribute18,
4955       p_attribute19                  => csp_location_rec.attribute19,
4956       p_attribute20                  => csp_location_rec.attribute20,
4957       p_attribute_category          => csp_location_rec.attribute_category,
4958       x_return_status          => x_return_status,
4959       x_msg_count              => x_msg_count,
4960       x_msg_data               => x_msg_data);
4961 
4962        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
4963           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4964                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4965                      'After do_create_ship_to_location... with x_return_status = ' || x_return_status);
4966        end if;
4967 
4968       l_inv_loc_id := p_location_id;
4969       IF x_return_status in ('E','U') THEN
4970          Rollback to site_to_invloc_linkage_PUB;
4971          /*FND_MESSAGE.SET_NAME ('CSP', 'CSP_STA_API_ERROR');
4972          FND_MESSAGE.SET_TOKEN ('TEXT', x_msg_data);
4973          FND_MSG_PUB.ADD;*/
4974          RAISE EXCP_USER_DEFINED;
4975       ELSE
4976 
4977        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
4978           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4979                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4980                      'p_address_id = ' || p_address_id);
4981        end if;
4982 
4983            SELECT  org_id
4984            INTO    l_org_id
4985            FROM    HZ_CUST_ACCT_SITES_ALL
4986            WHERE   cust_acct_site_id = p_address_id;
4987 
4988        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
4989           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4990                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
4991                      'l_org_id = ' || l_org_id);
4992        end if;
4993 
4994            /*
4995            select operating_unit
4996            into l_ou_id
4997            from org_organization_Definitions
4998            where organization_id = l_org_id;
4999            */
5000            l_ou_id := l_org_id;
5001 
5002        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5003           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5004                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
5005                      'l_ou_id = ' || l_ou_id);
5006        end if;
5007 
5008           SELECT TO_NUMBER(DECODE(SUBSTRB(USERENV('CLIENT_INFO'),1,1), ' ', NULL, SUBSTRB(USERENV('CLIENT_INFO'),1,10)))
5009           INTO   l_org_id
5010           FROM   dual;
5011 
5012        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5013           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5014                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
5015                      'l_org_id = ' || l_org_id);
5016        end if;
5017 
5018           mo_global.set_policy_context('S', l_ou_id);
5019 
5020        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5021           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5022                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
5023                      'Before arp_clas_pkg.insert_po_loc_associations...');
5024        end if;
5025 
5026          -- Create the linkage between the site use and the inventory location.
5027          arp_clas_pkg.insert_po_loc_associations(
5028             p_inventory_location_id       => l_inv_loc_id,
5029             p_inventory_organization_id   => null,
5030             p_customer_id                 => p_customer_id,
5031             p_address_id                  => p_address_id,
5032             p_site_use_id                 => p_site_use_id,
5033             x_return_status               => x_return_status,
5034              x_msg_count                   => x_msg_count,
5035              x_msg_data                    => x_msg_data);
5036 
5037           mo_global.set_policy_context('S', l_org_id);
5038 
5039        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5040           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5041                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
5042                      'After arp_clas_pkg.insert_po_loc_associations...');
5043           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5044                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
5045                      'x_return_status = ' || x_return_status);
5046        end if;
5047 
5048        IF x_return_status in ('E','U') THEN
5049           Rollback to site_to_invloc_linkage_PUB;
5050           RAISE EXCP_USER_DEFINED;
5051        END IF;
5052 
5053       END IF;
5054    ELSE
5055       Rollback to site_to_invloc_linkage_PUB;
5056        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5057           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5058                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
5059                      'p_country is NULL...');
5060        end if;
5061       /*FND_MESSAGE.SET_NAME ('CSP', 'CSP_ADDRESS_REQD');
5062       FND_MESSAGE.SET_TOKEN ('TEXT', x_msg_data);
5063       FND_MSG_PUB.ADD;*/
5064       RAISE EXCP_USER_DEFINED;
5065    END IF;
5066  END IF;
5067    EXCEPTION
5068       WHEN EXCP_USER_DEFINED THEN
5069          x_return_status := FND_API.G_RET_STS_ERROR;
5070          fnd_msg_pub.count_and_get
5071          ( p_count   => x_msg_count
5072          , p_data    => x_msg_data);
5073        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5074           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5075                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
5076                      'In EXCP_USER_DEFINED block');
5077        end if;
5078       WHEN FND_API.G_EXC_ERROR THEN
5079          JTF_PLSQL_API.HANDLE_EXCEPTIONS(
5080             P_API_NAME => L_API_NAME
5081            ,P_PKG_NAME => G_PKG_NAME
5082            ,P_EXCEPTION_LEVEL => FND_MSG_PUB.G_MSG_LVL_ERROR
5083            ,P_PACKAGE_TYPE => JTF_PLSQL_API.G_PUB
5084            ,X_MSG_COUNT    => x_MSG_COUNT
5085            ,X_MSG_DATA     => x_MSG_DATA
5086            ,X_RETURN_STATUS => x_RETURN_STATUS);
5087        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5088           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5089                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
5090                      'In FND_API.G_EXC_ERROR block');
5091        end if;
5092       WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5093          JTF_PLSQL_API.HANDLE_EXCEPTIONS(
5094             P_API_NAME => L_API_NAME
5095            ,P_PKG_NAME => G_PKG_NAME
5096            ,P_EXCEPTION_LEVEL => FND_MSG_PUB.G_MSG_LVL_ERROR
5097            ,P_PACKAGE_TYPE => JTF_PLSQL_API.G_PUB
5098            ,X_MSG_COUNT    => x_MSG_COUNT
5099            ,X_MSG_DATA     => x_MSG_DATA
5100            ,X_RETURN_STATUS => x_RETURN_STATUS);
5101        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5102           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5103                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
5104                      'In FND_API.G_EXC_UNEXPECTED_ERROR block');
5105        end if;
5106       WHEN OTHERS THEN
5107          Rollback to site_to_invloc_linkage_PUB;
5108        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5109           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5110                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.site_to_invloc_linkage',
5111                      'In Others block... sqlerrm = ' || sqlerrm);
5112        end if;
5113          FND_MESSAGE.SET_NAME('CSP', 'CSP_UNEXPECTED_EXEC_ERRORS');
5114          FND_MESSAGE.SET_TOKEN('ROUTINE', l_api_name, FALSE);
5115          FND_MESSAGE.SET_TOKEN('SQLERRM', sqlerrm, FALSE);
5116          FND_MSG_PUB.ADD;
5117          fnd_msg_pub.count_and_get
5118            ( p_count => x_msg_count
5119            , p_data  => x_msg_data);
5120          x_return_status := FND_API.G_RET_STS_ERROR;
5121 
5122 END site_to_invloc_linkage;
5123    PROCEDURE call_internal_hook (
5124       p_package_name      IN       VARCHAR2,
5125       p_api_name          IN       VARCHAR2,
5126       p_processing_type   IN       VARCHAR2,
5127       x_return_status     OUT NOCOPY      VARCHAR2
5128    )
5129    IS
5130       CURSOR c1
5131       IS
5132          SELECT hook_package, hook_api
5133            FROM jtf_hooks_data
5134           WHERE package_name = p_package_name
5135             AND api_name = p_api_name
5136             AND execute_flag = 'Y'
5137             AND processing_type = p_processing_type
5138           ORDER BY execution_order;
5139 
5140       v_cursorid   INTEGER;
5141       v_blockstr   VARCHAR2(2000);
5142       v_dummy      INTEGER;
5143 	  l_module_name VARCHAR2(100)	:= 'csp.plsql.csp_ship_to_address_pvt.call_internal_hook';
5144    BEGIN
5145 
5146 	if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5147 		FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5148 			l_module_name,
5149 			'BEGIN...');
5150 	end if;
5151 
5152       x_return_status := fnd_api.g_ret_sts_success;
5153 
5154       FOR i IN c1
5155       LOOP
5156          v_cursorid := DBMS_SQL.open_cursor;
5157          v_blockstr :=
5158             ' begin ' || i.hook_package || '.' || i.hook_api || '(:1); end; ';
5159 
5160 		if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5161 			FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5162 				l_module_name,
5163 				'calling hook API...');
5164 			FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5165 				l_module_name,
5166 				'i.hook_package = ' || i.hook_package);
5167 			FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5168 				l_module_name,
5169 				'i.hook_api = ' || i.hook_api);
5170 		end if;
5171 
5172          DBMS_SQL.parse (v_cursorid, v_blockstr, DBMS_SQL.v7);
5173          DBMS_SQL.bind_variable (v_cursorid, ':1', x_return_status, 20);
5174          v_dummy := DBMS_SQL.execute (v_cursorid);
5175          DBMS_SQL.variable_value (v_cursorid, ':1', x_return_status);
5176          DBMS_SQL.close_cursor (v_cursorid);
5177 
5178 		if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5179 			FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5180 				l_module_name,
5181 				'x_return_status = ' || x_return_status);
5182 		end if;
5183 
5184          IF NOT (x_return_status = fnd_api.g_ret_sts_success)
5185          THEN
5186             fnd_message.set_name ('JTF', 'JTF_TASK_MISSING_RETURN_STATUS');
5187             fnd_message.set_token (
5188                'P_PROCEDURE',
5189                i.hook_package || '.' || i.hook_api,false
5190             );
5191             fnd_msg_pub.add;
5192             x_return_status := fnd_api.g_ret_sts_unexp_error;
5193             RAISE fnd_api.g_exc_unexpected_error;
5194             x_return_status := fnd_api.g_ret_sts_unexp_error;
5195             RAISE fnd_api.g_exc_unexpected_error;
5196          END IF;
5197 
5198          IF x_return_status IS NULL
5199          THEN
5200             fnd_message.set_name ('JTF', 'JTF_TASK_MISSING_RETURN_STATUS');
5201             fnd_msg_pub.add;
5202             x_return_status := fnd_api.g_ret_sts_unexp_error;
5203             RAISE fnd_api.g_exc_unexpected_error;
5204          END IF;
5205       END LOOP;
5206    EXCEPTION
5207       WHEN fnd_api.g_exc_unexpected_error
5208       THEN
5209          x_return_status := fnd_api.g_ret_sts_unexp_error;
5210       WHEN OTHERS
5211       THEN
5212          fnd_message.set_name ('JTF', 'JTF_TASK_UNKNOWN_ERROR');
5213          fnd_message.set_token ('P_TEXT', SQLCODE || SQLERRM,false);
5214          fnd_msg_pub.add;
5215          x_return_status := fnd_api.g_ret_sts_unexp_error;
5216    END;
5217 
5218    PROCEDURE cust_inv_loc_link
5219    (     p_api_version              IN NUMBER
5220         ,p_Init_Msg_List            IN VARCHAR2     := FND_API.G_FALSE
5221         ,p_commit                   IN VARCHAR2     := FND_API.G_FALSE
5222         ,px_location_id             IN OUT NOCOPY NUMBER
5223         ,p_party_site_id            IN NUMBER
5224         ,p_cust_account_id          IN NUMBER
5225         ,p_customer_id              IN NUMBER
5226 		,p_org_id					IN NUMBER		:= NULL
5227         ,p_attribute_category       IN VARCHAR2
5228         ,p_attribute1               IN VARCHAR2
5229         ,p_attribute2               IN VARCHAR2
5230         ,p_attribute3               IN VARCHAR2
5231         ,p_attribute4               IN VARCHAR2
5232         ,p_attribute5               IN VARCHAR2
5233         ,p_attribute6               IN VARCHAR2
5234         ,p_attribute7               IN VARCHAR2
5235         ,p_attribute8               IN VARCHAR2
5236         ,p_attribute9               IN VARCHAR2
5237         ,p_attribute10              IN VARCHAR2
5238         ,p_attribute11              IN VARCHAR2
5239         ,p_attribute12              IN VARCHAR2
5240         ,p_attribute13              IN VARCHAR2
5241         ,p_attribute14              IN VARCHAR2
5242         ,p_attribute15              IN VARCHAR2
5243         ,p_attribute16              IN VARCHAR2
5244         ,p_attribute17              IN VARCHAR2
5245         ,p_attribute18              IN VARCHAR2
5246         ,p_attribute19              IN VARCHAR2
5247         ,p_attribute20              IN VARCHAR2
5248         ,x_return_status            OUT NOCOPY VARCHAR2
5249         ,x_msg_count                OUT NOCOPY NUMBER
5250         ,x_msg_data                 OUT NOCOPY VARCHAR2
5251     ) IS
5252     l_location_id 	        NUMBER := px_location_id;
5253     l_return_status	        VARCHAR2(1);
5254     l_msg_count 		    NUMBER;
5255     l_msg_data		        VARCHAR2(2000);
5256     l_msg			        VARCHAR2(2000);
5257     l_site_use_id		    NUMBER;
5258     l_address_id		    NUMBER;
5259     l_api_version_number    NUMBER := 1.0;
5260     l_api_name              CONSTANT VARCHAR2(30) := 'cust_inv_loc_link';
5261     --l_party_site_id 	    NUMBER := to_number(Name_In('csp_requirement_headers.party_site_id'));
5262     --l_account_id 		    NUMBER := to_number(Name_In('csp_requirement_headers.account_id'));
5263     l_org_id 		        NUMBER;
5264     l_inv_location_id	    NUMBER;
5265     l_inv_loc		        NUMBER;
5266     l_Return_val 		    BOOLEAN := FALSE;
5267     l_pay_application_id	CONSTANT NUMBER := 801;
5268     l_status 		        VARCHAR2(10);
5269     l_industry		        VARCHAR2(10);
5270     l_state		            VARCHAR2(30);
5271     l_state_code		    NUMBER;
5272     l_county		        VARCHAR2(30);
5273     l_county_code		    NUMBER;
5274     l_city		            VARCHAR2(30);
5275     l_city_code		        NUMBER;
5276     l_state_abbrev	        VARCHAR2(30);
5277     l_county_name		    VARCHAR2(240);
5278     l_city_name		        VARCHAr2(240);
5279 
5280     CURSOR  site_use_cur IS
5281         SELECT c_site_use.site_use_id, c_acct_site.cust_acct_site_id
5282         FROM hz_cust_site_uses_all c_site_use,
5283     	 hz_cust_acct_sites_all c_acct_site
5284         WHERE c_site_use.site_use_code = 'SHIP_TO'
5285         AND c_site_use.status = 'A'
5286         AND c_site_use.cust_acct_site_id = c_acct_site.cust_acct_site_id
5287         AND c_acct_site.cust_account_id = p_cust_account_id
5288         AND c_acct_site.party_site_id = p_party_site_id
5289         AND c_acct_site.org_id = l_org_id;
5290 
5291       CURSOR invloc_check_cur IS
5292         SELECT location_id
5293         FROM po_location_associations_all
5294         WHERE site_use_id = l_site_use_id;
5295 
5296    /*   CURSOR po_loc_assoc_exists_cur IS
5297         SELECT location_id
5298         FROM po_location_Associations_all
5299         WHERE location_id = l_inv_location_id;
5300    */
5301 
5302       CURSOR address_cur IS
5303         SELECT country, address1, address2, address3,
5304                address4, city, postal_code, state,
5305                province, county
5306         FROM hz_locations
5307         WHERE location_id = px_location_id;
5308 
5309       address_rec   address_cur%ROWTYPE;
5310 
5311   BEGIN
5312     SAVEPOINT cust_inv_loc_link_PUB;
5313 
5314     IF (px_location_id IS NOT NULL) THEN
5315 
5316       /*OPEN po_loc_Assoc_exists_cur;
5317       FETCH po_loc_Assoc_exists_cur INTO l_inv_loc;
5318 
5319       IF (po_loc_assoc_exists_cur%NOTFOUND) THEN
5320       */
5321 	  -- bug 11829269
5322       IF(p_cust_account_id IS NOT NULL and p_party_site_id IS NOT NULL) THEN
5323 		BEGIN
5324 			if p_org_id is null then
5325 				/*
5326                 SELECT TO_NUMBER(DECODE(SUBSTRB(USERENV('CLIENT_INFO'),1,1), ' ', NULL,
5327 					SUBSTRB(USERENV('CLIENT_INFO'),1,10)))
5328 				INTO l_org_id
5329 				FROM DUAL;*/
5330                 l_org_id := mo_global.get_current_org_id;
5331 
5332                 if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5333                     FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5334                         'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.cust_inv_loc_link',
5335                         'l_org_id = ' || l_org_id);
5336                 end if;
5337 
5338                 if l_org_id is null then
5339                     po_moac_utils_pvt.INITIALIZE;
5340                     l_org_id := mo_global.get_current_org_id;
5341                 end if;
5342 			else
5343 				l_org_id := p_org_id;
5344 			end if;
5345         END;
5346 
5347        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5348           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5349                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.cust_inv_loc_link',
5350                      'l_org_id = ' || l_org_id);
5351        end if;
5352 
5353         OPEN site_use_cur;
5354         FETCH site_use_cur INTO l_site_use_id, l_address_id;
5355         CLOSE site_use_cur;
5356 
5357        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5358           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5359                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.cust_inv_loc_link',
5360                      'l_site_use_id = ' || l_site_use_id);
5361           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5362                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.cust_inv_loc_link',
5363                      'l_address_id = ' || l_address_id);
5364        end if;
5365 
5366         -- do a check to see if inventory location already exists, execute foll.code
5367         -- only if it does not exist. If inventory_location exists,
5368         -- copy that to ship_to_location_id
5369         OPEN invloc_check_cur;
5370         FETCH invloc_check_cur into l_inv_location_id;
5371         OPEN address_cur;
5372         FETCH address_cur INTO address_rec;
5373         CLOSE address_cur;
5374         IF (invloc_check_cur%NOTFOUND) THEN
5375           IF (address_rec.country like 'US%') THEN
5376             l_state := address_rec.state;
5377             l_county := address_rec.county;
5378             l_city := address_rec.city;
5379             BEGIN
5380               select city_name, county_name, state_abbrev
5381               into l_city_name, l_county_name, l_state_abbrev
5382               from pay_us_city_names ct,
5383                    pay_us_states st,
5384                    pay_us_counties c
5385               where ct.state_code = st.state_code
5386               and   ct.county_code = c.county_code
5387               and   c.state_code = st.state_code
5388               and   st.state_abbrev = l_state
5389               and   upper(c.county_name) = upper(l_county)
5390               and   upper(ct.city_name) = upper(l_city);
5391             EXCEPTION
5392               when no_data_found then
5393                 null;
5394             END;
5395 
5396           END IF;
5397 
5398        if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5399           FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5400                      'csp.plsql.CSP_SHIP_TO_ADDRESS_PVT.cust_inv_loc_link',
5401                      'Before calling site_to_invloc_linkage...');
5402        end if;
5403 
5404           site_to_invloc_linkage(
5405        	    p_customer_id		=> p_customer_id,
5406 	        p_address_id		=> l_address_id,
5407 	        p_site_use_id		=> l_site_use_id,
5408             p_location_id		=> l_location_id,
5409             p_style		        => 'GENERIC', -- address_Rec.country,
5410             p_address_line_1	=> address_rec.address1,
5411             p_address_line_2	=> address_rec.address2,
5412             p_address_line_3	=> address_rec.address3,
5413             p_country		    => address_rec.country,
5414 	        p_postal_code	    => address_rec.postal_code,
5415             p_region_1		    => nvl(l_county_name, address_rec.county),
5416             p_region_2		    => nvl(l_state_Abbrev, address_rec.state),
5417 	        p_region_3		    => null,
5418             p_town_or_city	    => nvl(l_city_name, address_rec.city),
5419             p_tax_name		    => null,
5420             p_telephone_number_1	=> null,
5421             p_telephone_number_2	=> null,
5422             p_telephone_number_3	=> null,
5423             p_loc_information13	=> null,
5424 	        p_loc_information14	=> null,
5425 	        p_loc_information15	=> null,
5426 	        p_loc_information16	=> null,
5427 	        p_loc_information17	=> null,
5428 	        p_loc_information18	=> null,
5429 	        p_loc_information19	=> null,
5430 	        p_loc_information20	=> null,
5431 	        p_api_version_number => l_api_version_number,
5432 	        p_init_msg_list	    => 'T'
5433              ,P_ATTRIBUTE_CATEGORY => null --Name_In('HR_DESC_FLEX.attribute_category')
5434 	       ,P_ATTRIBUTE1		=> null --Name_In('HR_DESC_FLEX.Attribute1')
5435 	       ,P_ATTRIBUTE2		=> null --Name_In('HR_DESC_FLEX.Attribute2')
5436 	       ,P_ATTRIBUTE3		=> null --Name_In('HR_DESC_FLEX.Attribute3')
5437 	       ,P_ATTRIBUTE4		=> null --Name_In('HR_DESC_FLEX.Attribute4')
5438 	       ,P_ATTRIBUTE5		=> null --Name_In('HR_DESC_FLEX.Attribute5')
5439 	       ,P_ATTRIBUTE6		=> null --Name_In('HR_DESC_FLEX.Attribute6')
5440 	       ,P_ATTRIBUTE7		=> null --Name_In('HR_DESC_FLEX.Attribute7')
5441 	       ,P_ATTRIBUTE8		=> null --Name_In('HR_DESC_FLEX.Attribute8')
5442 	       ,P_ATTRIBUTE9		=> null --Name_In('HR_DESC_FLEX.Attribute9')
5443 	       ,P_ATTRIBUTE10		=> null --Name_In('HR_DESC_FLEX.Attribute10')
5444 	       ,P_ATTRIBUTE11		=> null --Name_In('HR_DESC_FLEX.Attribute11')
5445 	       ,P_ATTRIBUTE12		 => null --('HR_DESC_FLEX.Attribute12')
5446 	       ,P_ATTRIBUTE13		 => null --Name_In('HR_DESC_FLEX.Attribute13')
5447 	       ,P_ATTRIBUTE14		 => null --Name_In('HR_DESC_FLEX.Attribute14')
5448 	       ,P_ATTRIBUTE15		 => null --Name_In('HR_DESC_FLEX.Attribute15')
5449 	       ,P_ATTRIBUTE16		 => null --Name_In('HR_DESC_FLEX.Attribute16')
5450 	       ,P_ATTRIBUTE17		 => null --Name_In('HR_DESC_FLEX.Attribute17')
5451 	       ,P_ATTRIBUTE18		 => null --Name_In('HR_DESC_FLEX.Attribute18')
5452 	       ,P_ATTRIBUTE19		 => null --Name_In('HR_DESC_FLEX.Attribute19')
5453 	       ,P_ATTRIBUTE20		 => null --Name_In('HR_DESC_FLEX.Attribute20')
5454 	       ,x_return_status	     => l_return_status
5455 	       ,X_MSG_COUNT          => l_msg_count
5456  	       ,X_MSG_DATA           => l_msg_data
5457           );
5458 
5459           IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5460               RAISE FND_API.G_EXC_ERROR;
5461           END IF;
5462           px_location_id := l_location_id;
5463         ELSE
5464           px_location_id := l_inv_location_id;
5465         END IF;
5466       ELSE
5467         -- not sure how to get cust_site_use_id if cust acct is null
5468         null;
5469       END IF;
5470     END If;
5471   EXCEPTION
5472     WHEN FND_API.G_EXC_ERROR THEN
5473         JTF_PLSQL_API.HANDLE_EXCEPTIONS(
5474              P_API_NAME => L_API_NAME
5475             ,P_PKG_NAME => G_PKG_NAME
5476             ,P_EXCEPTION_LEVEL => FND_MSG_PUB.G_MSG_LVL_ERROR
5477             ,P_PACKAGE_TYPE => JTF_PLSQL_API.G_PUB
5478             ,X_MSG_COUNT    => X_MSG_COUNT
5479             ,X_MSG_DATA     => X_MSG_DATA
5480             ,X_RETURN_STATUS => X_RETURN_STATUS);
5481     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5482         JTF_PLSQL_API.HANDLE_EXCEPTIONS(
5483              P_API_NAME => L_API_NAME
5484             ,P_PKG_NAME => G_PKG_NAME
5485             ,P_EXCEPTION_LEVEL => FND_MSG_PUB.G_MSG_LVL_ERROR
5486             ,P_PACKAGE_TYPE => JTF_PLSQL_API.G_PUB
5487             ,X_MSG_COUNT    => X_MSG_COUNT
5488             ,X_MSG_DATA     => X_MSG_DATA
5489             ,X_RETURN_STATUS => X_RETURN_STATUS);
5490     WHEN OTHERS THEN
5491       Rollback to cust_inv_loc_link_pub;
5492       FND_MESSAGE.SET_NAME('CSP', 'CSP_UNEXPECTED_EXEC_ERRORS');
5493       FND_MESSAGE.SET_TOKEN('ROUTINE', l_api_name, false);
5494       FND_MESSAGE.SET_TOKEN('SQLERRM', sqlerrm, false);
5495       FND_MSG_PUB.ADD;
5496       fnd_msg_pub.count_and_get
5497               ( p_count => x_msg_count
5498               , p_data  => x_msg_data);
5499       x_return_status := FND_API.G_RET_STS_ERROR;
5500 
5501   END;
5502 
5503 	-- bug # 8333969
5504    PROCEDURE rs_primary_ship_to_addr
5505    (
5506       p_api_version        IN NUMBER
5507       ,p_Init_Msg_List     IN VARCHAR2     := FND_API.G_FALSE
5508       ,p_commit            IN VARCHAR2     := FND_API.G_FALSE
5509       ,p_rs_type				IN	VARCHAR2
5510       ,p_rs_id					IN	NUMBER
5511       ,p_rs_site_use_id		IN	NUMBER
5512       ,x_return_status     OUT NOCOPY VARCHAR2
5513       ,x_msg_count         OUT NOCOPY NUMBER
5514       ,x_msg_data          OUT NOCOPY VARCHAR2
5515    ) IS
5516 
5517    l_old_site_use_id    NUMBER;
5518    l_customer_id        NUMBER;
5519    l_old_inv_loc_id     NUMBER;
5520    l_old_status         VARCHAR2(1);
5521    l_new_inv_loc_id     NUMBER;
5522    l_new_status         VARCHAR2(1);
5523 
5524    CURSOR rs_current_primary_addr IS
5525       SELECT
5526         site_use_id,
5527         customer_id,
5528         inv_loc_id,
5529         status
5530       FROM
5531         csp_rs_ship_to_addresses_v
5532       WHERE
5533         resource_id = p_rs_id
5534         AND resource_type = p_rs_type
5535         AND primary_flag = 'Y';
5536 
5537    CURSOR rs_get_ship_to_addr IS
5538       SELECT
5539         customer_id,
5540         inv_loc_id,
5541         status
5542       FROM
5543         csp_rs_ship_to_addresses_v
5544       WHERE
5545         resource_id = p_rs_id
5546         AND resource_type = p_rs_type
5547         AND site_use_id = p_rs_site_use_id;
5548 
5549    BEGIN
5550 
5551       if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5552          FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5553                     'csp.plsql.'|| G_PKG_NAME ||'.rs_primary_ship_to_addr',
5554                     'Begin');
5555 
5556          FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5557                     'csp.plsql.'|| G_PKG_NAME ||'.rs_primary_ship_to_addr',
5558                     'Parameters are: '
5559                     || 'p_api_version=' || p_api_version
5560                     || ',p_Init_Msg_List=' || p_Init_Msg_List
5561                     || ',p_commit=' || p_commit
5562                     || ',p_rs_type=' || p_rs_type
5563                     || ',p_rs_id=' || p_rs_id
5564                     || ',p_rs_site_use_id=' || p_rs_site_use_id);
5565       end if;
5566 
5567       x_return_status := FND_API.G_RET_STS_SUCCESS;
5568 
5569       IF FND_API.to_Boolean(p_Init_Msg_List)
5570       THEN
5571          FND_MSG_PUB.initialize;
5572       END IF;
5573 
5574 
5575       /*
5576          Logic in brief
5577          1. Get current Primary Ship To address
5578          2. If New site_use_id is same as old primary site_use_id then return
5579          3. Make old primary site_use_id as non primary
5580          4. Update customer account site record to non primary
5581          5. Make new site_use_id as primary
5582          6. Update customer account site record to primary
5583          7. COMMIT is required
5584       */
5585 
5586       -- Step 1: Get current Primary Ship To address
5587       open rs_current_primary_addr;
5588       fetch rs_current_primary_addr into l_old_site_use_id,
5589                                           l_customer_id,
5590                                           l_old_inv_loc_id,
5591                                           l_old_status;
5592       close rs_current_primary_addr;
5593 
5594       if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5595          FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5596                     'csp.plsql.'|| G_PKG_NAME ||'.rs_primary_ship_to_addr',
5597                     'l_old_site_use_id=' || l_old_site_use_id
5598                     || ',l_customer_id=' || l_customer_id
5599                     || ',l_old_inv_loc_id=' || l_old_inv_loc_id
5600                     || ',l_old_status=' || l_old_status);
5601       end if;
5602 
5603       -- Step 2: If New site_use_id is same as old primary site_use_id then return
5604       IF l_old_site_use_id = p_rs_site_use_id THEN
5605          return;
5606       END IF;
5607 
5608       -- Step 3: Make old primary site_use_id as non primary
5609       DO_UPDATE_SITE_USE(
5610          P_SITE_USE_ID => l_old_site_use_id,
5611          P_PRIMARY_FLAG => 'N',
5612          P_STATUS => l_old_status,
5613          P_CUSTOMER_ID => l_customer_id,
5614          P_INV_LOCATION_ID => l_old_inv_loc_id,
5615          X_RETURN_STATUS => x_return_status,
5616          X_MSG_COUNT => x_msg_count,
5617          X_MSG_DATA => x_msg_data
5618       );
5619 
5620       if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5621          FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5622                     'csp.plsql.'|| G_PKG_NAME ||'.rs_primary_ship_to_addr',
5623                     'x_return_status=' || x_return_status
5624                     || ',x_msg_count=' || x_msg_count
5625                     || ',x_msg_data=' || x_msg_data);
5626       end if;
5627 
5628       -- Step 4: Update customer account site record to non primary
5629       IF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
5630          update HZ_CUST_ACCT_SITES_ALL
5631             set bill_to_flag = 'Y',
5632             ship_to_flag = 'Y'
5633          where cust_account_id = l_customer_id
5634          and cust_acct_site_id = (
5635             select cust_acct_site_id from HZ_CUST_SITE_USES_ALL
5636             where site_use_id = l_old_site_use_id);
5637       ELSE
5638          return;
5639       END IF;
5640 
5641       -- Step 5: Make new site_use_id as primary
5642       open rs_get_ship_to_addr;
5643       fetch rs_get_ship_to_addr into l_customer_id,
5644                                        l_new_inv_loc_id,
5645                                        l_new_status;
5646       close rs_get_ship_to_addr;
5647 
5648       if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5649          FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5650                     'csp.plsql.'|| G_PKG_NAME ||'.rs_primary_ship_to_addr',
5651                     'p_rs_site_use_id=' || p_rs_site_use_id
5652                     || ',l_customer_id=' || l_customer_id
5653                     || ',l_new_inv_loc_id=' || l_new_inv_loc_id
5654                     || ',l_new_status=' || l_new_status);
5655       end if;
5656 
5657       DO_UPDATE_SITE_USE(
5658          P_SITE_USE_ID => p_rs_site_use_id,
5659          P_PRIMARY_FLAG => 'Y',
5660          P_STATUS => l_new_status,
5661          P_CUSTOMER_ID => l_customer_id,
5662          P_INV_LOCATION_ID => l_new_inv_loc_id,
5663          X_RETURN_STATUS => x_return_status,
5664          X_MSG_COUNT => x_msg_count,
5665          X_MSG_DATA => x_msg_data
5666       );
5667 
5668       if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5669          FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5670                     'csp.plsql.'|| G_PKG_NAME ||'.rs_primary_ship_to_addr',
5671                     'x_return_status=' || x_return_status
5672                     || ',x_msg_count=' || x_msg_count
5673                     || ',x_msg_data=' || x_msg_data);
5674       end if;
5675 
5676       -- Step 6: Update customer account site record to primary
5677       IF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
5678          update HZ_CUST_ACCT_SITES_ALL
5679             set bill_to_flag = 'P',
5680             ship_to_flag = 'P'
5681          where cust_account_id = l_customer_id
5682          and cust_acct_site_id = (
5683             select cust_acct_site_id from HZ_CUST_SITE_USES_ALL
5684             where site_use_id = p_rs_site_use_id);
5685       ELSE
5686          return;
5687       END IF;
5688 
5689       -- Step 7: COMMIT if requried
5690       IF p_commit = FND_API.G_TRUE THEN
5691          COMMIT;
5692       END IF;
5693 
5694    END;  -- End of rs_primary_ship_to_addr
5695 
5696    PROCEDURE rs_inactivate_ship_to
5697    (
5698       p_api_version        IN NUMBER
5699       ,p_Init_Msg_List     IN VARCHAR2     := FND_API.G_FALSE
5700       ,p_commit            IN VARCHAR2     := FND_API.G_FALSE
5701       ,p_rs_type				IN	VARCHAR2
5702       ,p_rs_id					IN	NUMBER
5703       ,p_rs_site_use_id		IN	NUMBER
5704       ,x_return_status     OUT NOCOPY VARCHAR2
5705       ,x_msg_count         OUT NOCOPY NUMBER
5706       ,x_msg_data          OUT NOCOPY VARCHAR2
5707    ) IS
5708 
5709    l_customer_id     NUMBER;
5710    l_inv_loc_id      NUMBER;
5711    l_primary_flag    VARCHAR(1);
5712 
5713    CURSOR rs_get_ship_to_addr IS
5714    SELECT
5715      customer_id,
5716      inv_loc_id,
5717      primary_flag
5718    FROM
5719      csp_rs_ship_to_addresses_v
5720    WHERE
5721      resource_id = p_rs_id
5722      AND resource_type = p_rs_type
5723      AND site_use_id = p_rs_site_use_id;
5724 
5725    BEGIN
5726 
5727       if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5728          FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5729                     'csp.plsql.'|| G_PKG_NAME ||'.rs_inactivate_ship_to',
5730                     'Begin');
5731 
5732          FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5733                     'csp.plsql.'|| G_PKG_NAME ||'.rs_inactivate_ship_to',
5734                     'Parameters are: '
5735                     || 'p_api_version=' || p_api_version
5736                     || ',p_Init_Msg_List=' || p_Init_Msg_List
5737                     || ',p_commit=' || p_commit
5738                     || ',p_rs_type=' || p_rs_type
5739                     || ',p_rs_id=' || p_rs_id
5740                     || ',p_rs_site_use_id=' || p_rs_site_use_id);
5741       end if;
5742 
5743       x_return_status := FND_API.G_RET_STS_SUCCESS;
5744 
5745       IF FND_API.to_Boolean(p_Init_Msg_List)
5746       THEN
5747          FND_MSG_PUB.initialize;
5748       END IF;
5749 
5750       /*
5751          Logic in brief
5752          1. Get ship_to address detail
5753          2. Call DO_UPDATE_SITE_USE to update it
5754          3. COMMIT if required
5755       */
5756 
5757       -- Step 1: Get ship_to address detail
5758       open rs_get_ship_to_addr;
5759       fetch rs_get_ship_to_addr into l_customer_id,
5760                                        l_inv_loc_id,
5761                                        l_primary_flag;
5762       close rs_get_ship_to_addr;
5763 
5764       if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5765          FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5766                     'csp.plsql.'|| G_PKG_NAME ||'.rs_primary_ship_to_addr',
5767                     'p_rs_site_use_id=' || p_rs_site_use_id
5768                     || ',l_customer_id=' || l_customer_id
5769                     || ',l_inv_loc_id=' || l_inv_loc_id
5770                     || ',l_primary_flag=' || l_primary_flag);
5771       end if;
5772 
5773       -- Step 2: Call DO_UPDATE_SITE_USE to update it
5774       DO_UPDATE_SITE_USE(
5775          P_SITE_USE_ID => p_rs_site_use_id,
5776          P_PRIMARY_FLAG => l_primary_flag,
5777          P_STATUS => 'I',
5778          P_CUSTOMER_ID => l_customer_id,
5779          P_INV_LOCATION_ID => l_inv_loc_id,
5780          X_RETURN_STATUS => x_return_status,
5781          X_MSG_COUNT => x_msg_count,
5782          X_MSG_DATA => x_msg_data
5783       );
5784 
5785       if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5786          FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5787                     'csp.plsql.'|| G_PKG_NAME ||'.rs_primary_ship_to_addr',
5788                     'x_return_status=' || x_return_status
5789                     || ',x_msg_count=' || x_msg_count
5790                     || ',x_msg_data=' || x_msg_data);
5791       end if;
5792 
5793       -- Step 3: COMMIT if required
5794       IF x_return_status = FND_API.G_RET_STS_SUCCESS
5795          AND p_commit = FND_API.G_TRUE
5796       THEN
5797          COMMIT;
5798       END IF;
5799 
5800    END;  -- End of rs_inactivate_ship_to
5801 
5802 procedure copy_hz_cust_site (
5803 				p_src_org_id				IN NUMBER
5804 				,p_dest_org_id				IN NUMBER
5805 				,p_cust_site_id				IN NUMBER
5806 				,p_hr_location_id			IN NUMBER
5807 				,p_customer_id				IN NUMBER
5808 				,x_return_status           OUT NOCOPY VARCHAR2
5809 				,x_msg_count               OUT NOCOPY NUMBER
5810 				,x_msg_data                OUT NOCOPY VARCHAR2
5811 				) IS
5812 	l_module_name	VARCHAR2(100)	:= 'csp.plsql.csp_ship_to_address_pvt.copy_hz_cust_site';
5813 	l_current_org_id	NUMBER;
5814 	l_msg varchar2(2000);
5815 	v_cust_acct_site_rec  hz_cust_account_site_v2pub.cust_acct_site_rec_type;
5816 	x_cust_acct_site_id NUMBER;
5817 	l_cust_acct_site_use_id NUMBER;
5818 	v_cust_site_use_rec hz_cust_account_site_v2pub.CUST_SITE_USE_REC_TYPE;
5819 	v_customer_profile_rec  HZ_CUSTOMER_PROFILE_V2PUB.CUSTOMER_PROFILE_REC_TYPE;
5820 	v_ship_bill_site  number;
5821 	v_bill_site_id number;
5822 	l_existing_bill_to number;
5823 	v_bill_acct_site_rec hz_cust_account_site_v2pub.cust_acct_site_rec_type;
5824 	x_bill_acct_site_id number;
5825 	l_bill_acct_site_use_id number;
5826 	v_bill_site_use_rec hz_cust_account_site_v2pub.CUST_SITE_USE_REC_TYPE;
5827 	v_bill_cust_profile_rec HZ_CUSTOMER_PROFILE_V2PUB.CUSTOMER_PROFILE_REC_TYPE;
5828 	x_site_use_id NUMBER;
5829 	temp_ship_to_use_id number;
5830 
5831 	cursor get_cust_acct_site_uses is
5832 		select site_use_id
5833 		from hz_cust_site_uses_all
5834 		where cust_acct_site_id = p_cust_site_id;
5835 
5836    cursor get_bill_site_id is
5837 		select cust_acct_site_id
5838 		from HZ_CUST_SITE_USES_ALL
5839 		where site_use_code = 'BILL_TO'
5840 		and site_use_id = v_ship_bill_site;
5841 
5842    cursor check_bill_to_location is
5843 		select newu.site_use_id
5844 		from HZ_CUST_SITE_USES_ALL orgu,
5845 		HZ_CUST_ACCT_SITES_ALL orgs,
5846 		HZ_CUST_SITE_USES_ALL newu,
5847 		HZ_CUST_ACCT_SITES_ALL news
5848 		where orgu.site_use_code = 'BILL_TO'
5849 		and orgu.site_use_id = v_ship_bill_site
5850 		and orgu.cust_acct_site_id = orgs.cust_acct_site_id
5851 		and news.party_site_id = orgs.party_site_id
5852 		and news.cust_acct_site_id = newu.cust_acct_site_id
5853 		and newu.site_use_code = 'BILL_TO'
5854 		and newu.location = orgu.location
5855 		and news.org_id = p_dest_org_id;
5856 
5857 BEGIN
5858 
5859 	if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5860 		 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5861 			l_module_name,
5862 			'Begin... p_src_org_id=' || p_src_org_id
5863 			|| ', p_dest_org_id=' || p_dest_org_id
5864 			|| ', p_cust_site_id=' || p_cust_site_id
5865 			|| ', p_hr_location_id=' || p_hr_location_id
5866 			|| ', p_customer_id=' || p_customer_id);
5867 	end if;
5868 
5869 	x_return_status := FND_API.G_RET_STS_SUCCESS;
5870 	l_current_org_id := mo_global.get_current_org_id;
5871 
5872 	if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5873 		 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5874 			l_module_name,
5875 			'l_current_org_id = ' || l_current_org_id);
5876 	end if;
5877 
5878 	-- get cust_site record in src ou
5879 	po_moac_utils_pvt.set_org_context(p_src_org_id);
5880 	hz_cust_account_site_v2pub.get_cust_acct_site_rec (
5881 						  p_init_msg_list => FND_API.G_TRUE,
5882 						  p_cust_acct_site_id => p_cust_site_id,
5883 						  x_cust_acct_site_rec => v_cust_acct_site_rec,
5884 						  x_return_status => x_return_status,
5885 						  x_msg_count => x_msg_count,
5886 						  x_msg_data => x_msg_data);
5887 	po_moac_utils_pvt.set_org_context(l_current_org_id);
5888 
5889 	IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5890 		l_msg := x_msg_data;
5891 		FND_MESSAGE.SET_NAME('CSP', 'CSP_COPY_SITE_ERRORS');
5892 		FND_MESSAGE.SET_TOKEN('CSP_MSG', l_msg, FALSE);
5893 		FND_MSG_PUB.ADD;
5894 		fnd_msg_pub.count_and_get
5895 			( p_count => x_msg_count
5896 			, p_data  => x_msg_data);
5897 		x_return_status := FND_API.G_RET_STS_ERROR;
5898 		RAISE FND_API.G_EXC_ERROR;
5899 	END IF; -- IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5900 
5901 	if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5902 		FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5903 						l_module_name,
5904 						'populated v_cust_acct_site_rec');
5905 	end if;
5906 
5907 	v_cust_acct_site_rec.cust_acct_site_id := NULL;
5908 	v_cust_acct_site_rec.tp_header_id := NULL;
5909 	v_cust_acct_site_rec.language := NULL;
5910 	v_cust_acct_site_rec.created_by_module := 'CSPSHIPAD';
5911 	v_cust_acct_site_rec.org_id := p_dest_org_id;
5912 
5913 	-- now create same site in source ou
5914 	po_moac_utils_pvt.set_org_context(p_dest_org_id);
5915 	hz_cust_account_site_v2pub.create_cust_acct_site (
5916 													p_init_msg_list => FND_API.G_TRUE,
5917 													p_cust_acct_site_rec => v_cust_acct_site_rec,
5918 													x_cust_acct_site_id => x_cust_acct_site_id,
5919 													x_return_status => x_return_status,
5920 													x_msg_count => x_msg_count,
5921 													x_msg_data => x_msg_data);
5922 	po_moac_utils_pvt.set_org_context(l_current_org_id);
5923 
5924 	IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5925 		l_msg := x_msg_data;
5926 		FND_MESSAGE.SET_NAME('CSP', 'CSP_COPY_SITE_ERRORS');
5927 		FND_MESSAGE.SET_TOKEN('CSP_MSG', l_msg, FALSE);
5928 		FND_MSG_PUB.ADD;
5929 		fnd_msg_pub.count_and_get
5930 			( p_count => x_msg_count
5931 			, p_data  => x_msg_data);
5932 		x_return_status := FND_API.G_RET_STS_ERROR;
5933 		RAISE FND_API.G_EXC_ERROR;
5934 	END IF; -- IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5935 
5936 	if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5937 		FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5938 							l_module_name,
5939 							'x_cust_acct_site_id=' || x_cust_acct_site_id);
5940 	end if;
5941 
5942 	-- now fetch all site uses records and copy them to source ou
5943 	OPEN get_cust_acct_site_uses;
5944 	LOOP
5945 		FETCH get_cust_acct_site_uses into l_cust_acct_site_use_id;
5946 		EXIT WHEN get_cust_acct_site_uses%NOTFOUND;
5947 
5948 		po_moac_utils_pvt.set_org_context(p_src_org_id);
5949 		hz_cust_account_site_v2pub.get_cust_site_use_rec (
5950 						p_init_msg_list => FND_API.G_TRUE,
5951 						p_site_use_id => l_cust_acct_site_use_id,
5952 						x_cust_site_use_rec => v_cust_site_use_rec,
5953 						x_customer_profile_rec => v_customer_profile_rec,
5954 						x_return_status => x_return_status,
5955 						x_msg_count => x_msg_count,
5956 						x_msg_data => x_msg_data);
5957 		po_moac_utils_pvt.set_org_context(l_current_org_id);
5958 
5959 		IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5960 			l_msg := x_msg_data;
5961 			FND_MESSAGE.SET_NAME('CSP', 'CSP_COPY_SITE_ERRORS');
5962 			FND_MESSAGE.SET_TOKEN('CSP_MSG', l_msg, FALSE);
5963 			FND_MSG_PUB.ADD;
5964 			fnd_msg_pub.count_and_get
5965 				  ( p_count => x_msg_count
5966 				  , p_data  => x_msg_data);
5967 			x_return_status := FND_API.G_RET_STS_ERROR;
5968 			RAISE FND_API.G_EXC_ERROR;
5969 		END IF; -- IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5970 
5971 		if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5972 			FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5973 							l_module_name,
5974 							'populated v_cust_site_use_rec');
5975 		end if;
5976 
5977 		v_cust_site_use_rec.site_use_id := NULL;
5978 		v_cust_site_use_rec.primary_flag := 'N';
5979 		v_cust_site_use_rec.created_by_module := 'CSPSHIPAD';
5980 		v_cust_site_use_rec.org_id := p_dest_org_id;
5981 		v_cust_site_use_rec.cust_acct_site_id := x_cust_acct_site_id;
5982 
5983 		if v_cust_site_use_rec.site_use_code = 'SHIP_TO' then
5984 			if v_cust_site_use_rec.bill_to_site_use_id is not null then
5985 				v_ship_bill_site := v_cust_site_use_rec.bill_to_site_use_id;
5986 
5987 				open get_bill_site_id;
5988 				fetch get_bill_site_id into v_bill_site_id;
5989 				close get_bill_site_id;
5990 
5991 				if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
5992 					FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
5993 						l_module_name,
5994 						'v_bill_site_id = ' || v_bill_site_id);
5995 				end if;
5996 
5997 				if v_bill_site_id <> p_cust_site_id then
5998 
5999 					open check_bill_to_location;
6000 					fetch check_bill_to_location into l_existing_bill_to;
6001 					close check_bill_to_location;
6002 
6003 					if l_existing_bill_to is null then
6004 
6005 						-- do lots of stuff here
6006 						po_moac_utils_pvt.set_org_context(p_src_org_id);
6007 						hz_cust_account_site_v2pub.get_cust_acct_site_rec (
6008 							p_init_msg_list => FND_API.G_TRUE,
6009 							p_cust_acct_site_id => v_bill_site_id,
6010 							x_cust_acct_site_rec => v_bill_acct_site_rec,
6011 							x_return_status => x_return_status,
6012 							x_msg_count => x_msg_count,
6013 							x_msg_data => x_msg_data);
6014 						po_moac_utils_pvt.set_org_context(l_current_org_id);
6015 
6016 						IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6017 							l_msg := x_msg_data;
6018 							FND_MESSAGE.SET_NAME('CSP', 'CSP_COPY_SITE_ERRORS');
6019 							FND_MESSAGE.SET_TOKEN('CSP_MSG', l_msg, FALSE);
6020 							FND_MSG_PUB.ADD;
6021 							fnd_msg_pub.count_and_get
6022 								( p_count => x_msg_count
6023 								, p_data  => x_msg_data);
6024 							x_return_status := FND_API.G_RET_STS_ERROR;
6025 							RAISE FND_API.G_EXC_ERROR;
6026 						END IF; -- IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6027 
6028 						if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
6029 							FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
6030 								l_module_name,
6031 								'populated v_bill_acct_site_rec');
6032 						end if;
6033 
6034 						v_bill_acct_site_rec.cust_acct_site_id := NULL;
6035 						v_bill_acct_site_rec.tp_header_id := NULL;
6036 						v_bill_acct_site_rec.language := NULL;
6037 						v_bill_acct_site_rec.created_by_module := 'CSPSHIPAD';
6038 						v_bill_acct_site_rec.org_id := p_dest_org_id;
6039 
6040 						-- now create same site in source ou
6041 						po_moac_utils_pvt.set_org_context(p_dest_org_id);
6042 						hz_cust_account_site_v2pub.create_cust_acct_site (
6043 							 p_init_msg_list => FND_API.G_TRUE,
6044 							 p_cust_acct_site_rec => v_bill_acct_site_rec,
6045 							 x_cust_acct_site_id => x_bill_acct_site_id,
6046 							 x_return_status => x_return_status,
6047 							 x_msg_count => x_msg_count,
6048 							 x_msg_data => x_msg_data);
6049 						po_moac_utils_pvt.set_org_context(l_current_org_id);
6050 
6051 						IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6052 							l_msg := x_msg_data;
6053 							FND_MESSAGE.SET_NAME('CSP', 'CSP_COPY_SITE_ERRORS');
6054 							FND_MESSAGE.SET_TOKEN('CSP_MSG', l_msg, FALSE);
6055 							FND_MSG_PUB.ADD;
6056 							fnd_msg_pub.count_and_get
6057 								( p_count => x_msg_count
6058 								, p_data  => x_msg_data);
6059 							x_return_status := FND_API.G_RET_STS_ERROR;
6060 							RAISE FND_API.G_EXC_ERROR;
6061 						END IF; -- IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6062 
6063 						if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
6064 							FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
6065 								l_module_name,
6066 								'x_bill_acct_site_id=' || x_bill_acct_site_id);
6067 						end if;
6068 
6069 						l_bill_acct_site_use_id := v_ship_bill_site;
6070 
6071 						po_moac_utils_pvt.set_org_context(p_src_org_id);
6072 						hz_cust_account_site_v2pub.get_cust_site_use_rec (
6073 							p_init_msg_list => FND_API.G_TRUE,
6074 							p_site_use_id => l_bill_acct_site_use_id,
6075 							x_cust_site_use_rec => v_bill_site_use_rec,
6076 							x_customer_profile_rec => v_bill_cust_profile_rec,
6077 							x_return_status => x_return_status,
6078 							x_msg_count => x_msg_count,
6079 							x_msg_data => x_msg_data);
6080 						po_moac_utils_pvt.set_org_context(l_current_org_id);
6081 
6082 						IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6083 							l_msg := x_msg_data;
6084 							FND_MESSAGE.SET_NAME('CSP', 'CSP_COPY_SITE_ERRORS');
6085 							FND_MESSAGE.SET_TOKEN('CSP_MSG', l_msg, FALSE);
6086 							FND_MSG_PUB.ADD;
6087 							fnd_msg_pub.count_and_get
6088 								( p_count => x_msg_count
6089 								, p_data  => x_msg_data);
6090 							x_return_status := FND_API.G_RET_STS_ERROR;
6091 							RAISE FND_API.G_EXC_ERROR;
6092 						END IF; -- IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6093 
6094 						if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
6095 							FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
6096 								l_module_name,
6097 								'populated v_bill_site_use_rec');
6098 						end if;
6099 
6100 						v_bill_site_use_rec.site_use_id := NULL;
6101 						v_bill_site_use_rec.primary_flag := 'N';
6102 						v_bill_site_use_rec.created_by_module := 'CSPSHIPAD';
6103 						v_bill_site_use_rec.org_id := p_dest_org_id;
6104 						v_bill_site_use_rec.cust_acct_site_id := x_bill_acct_site_id;
6105 
6106 						po_moac_utils_pvt.set_org_context(p_dest_org_id);
6107 						hz_cust_account_site_v2pub.create_cust_site_use (
6108 							 p_init_msg_list => FND_API.G_TRUE,
6109 							 p_cust_site_use_rec => v_bill_site_use_rec,
6110 							 p_customer_profile_rec => v_bill_cust_profile_rec,
6111 							 p_create_profile => FND_API.G_FALSE,
6112 							 p_create_profile_amt => FND_API.G_FALSE,
6113 							 x_site_use_id => x_site_use_id,
6114 							 x_return_status => x_return_status,
6115 							 x_msg_count => x_msg_count,
6116 							 x_msg_data => x_msg_data);
6117 						po_moac_utils_pvt.set_org_context(l_current_org_id);
6118 
6119 						IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6120 							l_msg := x_msg_data;
6121 							FND_MESSAGE.SET_NAME('CSP', 'CSP_COPY_SITE_ERRORS');
6122 							FND_MESSAGE.SET_TOKEN('CSP_MSG', l_msg, FALSE);
6123 							FND_MSG_PUB.ADD;
6124 							fnd_msg_pub.count_and_get
6125 								( p_count => x_msg_count
6126 								, p_data  => x_msg_data);
6127 							x_return_status := FND_API.G_RET_STS_ERROR;
6128 							po_moac_utils_pvt.set_org_context(l_current_org_id);
6129 							RAISE FND_API.G_EXC_ERROR;
6130 						END IF; -- IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6131 
6132 						if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
6133 							FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
6134 								l_module_name,
6135 								'x_site_use_id=' || x_site_use_id);
6136 						end if;
6137 
6138 						v_cust_site_use_rec.bill_to_site_use_id := x_site_use_id;
6139 
6140 					else
6141 						v_cust_site_use_rec.bill_to_site_use_id := l_existing_bill_to;
6142 					end if;
6143 				else
6144 					v_cust_site_use_rec.bill_to_site_use_id := null;
6145 				end if;
6146 			end if;
6147 		end if;
6148 
6149 		if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
6150 			FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
6151 								l_module_name,
6152 								'v_cust_site_use_rec.site_use_code=' || v_cust_site_use_rec.site_use_code
6153 								|| ', v_cust_site_use_rec.bill_to_site_use_id=' || v_cust_site_use_rec.bill_to_site_use_id);
6154 		end if;
6155 
6156 		po_moac_utils_pvt.set_org_context(p_dest_org_id);
6157 		hz_cust_account_site_v2pub.create_cust_site_use (
6158 											  p_init_msg_list => FND_API.G_TRUE,
6159 											  p_cust_site_use_rec => v_cust_site_use_rec,
6160 											  p_customer_profile_rec => v_customer_profile_rec,
6161 											  p_create_profile => FND_API.G_FALSE,
6162 											  p_create_profile_amt => FND_API.G_FALSE,
6163 											  x_site_use_id => x_site_use_id,
6164 											  x_return_status => x_return_status,
6165 											  x_msg_count => x_msg_count,
6166 											  x_msg_data => x_msg_data);
6167 		po_moac_utils_pvt.set_org_context(l_current_org_id);
6168 
6169 		IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6170 			l_msg := x_msg_data;
6171 			FND_MESSAGE.SET_NAME('CSP', 'CSP_COPY_SITE_ERRORS');
6172 			FND_MESSAGE.SET_TOKEN('CSP_MSG', l_msg, FALSE);
6173 			FND_MSG_PUB.ADD;
6174 			fnd_msg_pub.count_and_get
6175 				( p_count => x_msg_count
6176 				, p_data  => x_msg_data);
6177 			x_return_status := FND_API.G_RET_STS_ERROR;
6178 			po_moac_utils_pvt.set_org_context(l_current_org_id);
6179 			RAISE FND_API.G_EXC_ERROR;
6180 		END IF; -- IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6181 
6182 		if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
6183 			FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
6184 						l_module_name,
6185 						'x_site_use_id=' || x_site_use_id);
6186 		end if;
6187 
6188 		if v_cust_site_use_rec.site_use_code = 'SHIP_TO' then
6189 			temp_ship_to_use_id := x_site_use_id;
6190 		end if;
6191 
6192 	END LOOP;
6193 	close get_cust_acct_site_uses;
6194 
6195 	if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
6196 		FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
6197 			l_module_name,
6198 			'x_cust_acct_site_id=' || x_cust_acct_site_id
6199 			|| ', temp_ship_to_use_id=' || temp_ship_to_use_id);
6200 	end if;
6201 
6202 	-- update inventory_location link for this new site_use
6203 	po_moac_utils_pvt.set_org_context(p_dest_org_id);
6204 	arp_clas_pkg.insert_po_loc_associations(
6205 		p_inventory_location_id       => p_hr_location_id,
6206 		p_inventory_organization_id   => p_dest_org_id,
6207 		p_customer_id                 => p_customer_id,
6208 		p_address_id                  => x_cust_acct_site_id,
6209 		p_site_use_id                 => temp_ship_to_use_id,
6210 		x_return_status               => x_return_status,
6211 		x_msg_count                   => x_msg_count,
6212 		x_msg_data                    => x_msg_data);
6213 	po_moac_utils_pvt.set_org_context(l_current_org_id);
6214 
6215 	if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
6216 		FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
6217 			l_module_name,
6218 			'arp_clas_pkg.insert_po_loc_associations... x_return_status=' || x_return_status);
6219 	end if;
6220 
6221 	IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6222 		l_msg := x_msg_data;
6223 		FND_MESSAGE.SET_NAME('CSP', 'CSP_COPY_SITE_ERRORS');
6224 		FND_MESSAGE.SET_TOKEN('CSP_MSG', l_msg, FALSE);
6225 		FND_MSG_PUB.ADD;
6226 		fnd_msg_pub.count_and_get
6227 			( p_count => x_msg_count
6228 			, p_data  => x_msg_data);
6229 		x_return_status := FND_API.G_RET_STS_ERROR;
6230 		RAISE FND_API.G_EXC_ERROR;
6231 	END IF; -- IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6232 
6233 	if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
6234 		FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
6235 			l_module_name,
6236 			'Done!!!');
6237 	end if;
6238 END;
6239 
6240 PROCEDURE ship_to_address_handler
6241    (p_resource_type           IN VARCHAR2
6242    ,p_resource_id             IN NUMBER
6243    ,p_location_id             IN OUT NOCOPY NUMBER
6244    ,p_timezone                IN VARCHAR2
6245    ,p_primary_flag            IN VARCHAR2
6246    ,p_status                  IN VARCHAR2
6247    ,x_return_status           OUT NOCOPY VARCHAR2
6248    ,x_msg_count               OUT NOCOPY NUMBER
6249    ,x_msg_data                OUT NOCOPY VARCHAR2
6250    ) IS
6251 
6252 	v_location_id	NUMBER;
6253 	v_customer_id	NUMBER;
6254 	l_address_line_1 VARCHAR2(240);
6255 	l_address_line_2 VARCHAR2(240);
6256 	l_address_line_3 VARCHAR2(240);
6257 	l_town_or_city VARCHAR2(30);
6258 	l_postal_code VARCHAR2(30);
6259 	l_country VARCHAR2(60);
6260 	l_style VARCHAR2(7);
6261 	l_region_1 VARCHAR2(120);
6262 	l_region_2 VARCHAR2(120);
6263 	l_region_3 VARCHAR2(120);
6264 	l_tax_name VARCHAR2(15);
6265 	l_telephone_number_1 VARCHAR2(60);
6266 	l_telephone_number_2 VARCHAR2(60);
6267 	l_telephone_number_3 VARCHAR2(60);
6268 	l_loc_information13 VARCHAR2(150);
6269 	l_loc_information14 VARCHAR2(150);
6270 	l_loc_information15 VARCHAR2(150);
6271 	l_loc_information16 VARCHAR2(150);
6272 	l_loc_information17 VARCHAR2(150);
6273 	l_loc_information18 VARCHAR2(150);
6274 	l_loc_information19 VARCHAR2(150);
6275 	l_loc_information20 VARCHAR2(150);
6276 	l_object_version_number NUMBER;
6277 	l_attribute_category VARCHAR2(30);
6278 	l_attribute1 VARCHAR2(150);
6279 	l_attribute2 VARCHAR2(150);
6280 	l_attribute3 VARCHAR2(150);
6281 	l_attribute4 VARCHAR2(150);
6282 	l_attribute5 VARCHAR2(150);
6283 	l_attribute6 VARCHAR2(150);
6284 	l_attribute7 VARCHAR2(150);
6285 	l_attribute8 VARCHAR2(150);
6286 	l_attribute9 VARCHAR2(150);
6287 	l_attribute10 VARCHAR2(150);
6288 	l_attribute11 VARCHAR2(150);
6289 	l_attribute12 VARCHAR2(150);
6290 	l_attribute13 VARCHAR2(150);
6291 	l_attribute14 VARCHAR2(150);
6292 	l_attribute15 VARCHAR2(150);
6293 	l_attribute16 VARCHAR2(150);
6294 	l_attribute17 VARCHAR2(150);
6295 	l_attribute18 VARCHAR2(150);
6296 	l_attribute19 VARCHAR2(150);
6297 	l_attribute20 VARCHAR2(150);
6298 	l_module_name VARCHAR2(150);
6299 
6300    cursor get_loc_details is
6301 	SELECT
6302 		hra.address_line_1,
6303 		hra.address_line_2,
6304 		hra.address_line_3,
6305 		hra.town_or_city,
6306 		hra.postal_code,
6307 		hra.country,
6308 		hra.style,
6309 		hra.region_1,
6310 		hra.region_2,
6311 		hra.region_3,
6312 		hra.tax_name,
6313 		hra.telephone_number_1,
6314 		hra.telephone_number_2,
6315 		hra.telephone_number_3,
6316 		hra.loc_information13,
6317 		hra.loc_information14,
6318 		hra.loc_information15,
6319 		hra.loc_information16,
6320 		hra.loc_information17,
6321 		hra.loc_information18,
6322 		hra.loc_information19,
6323 		hra.loc_information20,
6324 		hra.object_version_number,
6325 		hra.attribute_category,
6326 		hra.attribute1,
6327 		hra.attribute2,
6328 		hra.attribute3,
6329 		hra.attribute4,
6330 		hra.attribute5,
6331 		hra.attribute6,
6332 		hra.attribute7,
6333 		hra.attribute8,
6334 		hra.attribute9,
6335 		hra.attribute10,
6336 		hra.attribute11,
6337 		hra.attribute12,
6338 		hra.attribute13,
6339 		hra.attribute14,
6340 		hra.attribute15,
6341 		hra.attribute16,
6342 		hra.attribute17,
6343 		hra.attribute18,
6344 		hra.attribute19,
6345 		hra.attribute20
6346 	  FROM hr_locations_all hra
6347 	  where hra.location_id = p_location_id;
6348 BEGIN
6349 	l_module_name := 'csp.plsql.csp_ship_to_address_pvt.ship_to_address_handler2';
6350 	v_location_id := p_location_id;
6351 
6352 	if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
6353 		FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
6354 			l_module_name,
6355 			'Begin... p_resource_type=' || p_resource_type
6356 			|| ', p_resource_id=' || p_resource_id
6357 			|| ', v_location_id=' || v_location_id
6358 			|| ', p_timezone=' || p_timezone
6359 			|| ', p_primary_flag=' || p_primary_flag
6360 			|| ', p_status=' || p_status);
6361 	end if;
6362 
6363 	x_return_status := FND_API.G_RET_STS_SUCCESS;
6364 
6365 	if p_location_id is not null then
6366 		open get_loc_details;
6367 		fetch get_loc_details into
6368 			l_address_line_1,
6369 			l_address_line_2,
6370 			l_address_line_3,
6371 			l_town_or_city,
6372 			l_postal_code,
6373 			l_country,
6374 			l_style,
6375 			l_region_1,
6376 			l_region_2,
6377 			l_region_3,
6378 			l_tax_name,
6379 			l_telephone_number_1,
6380 			l_telephone_number_2,
6381 			l_telephone_number_3,
6382 			l_loc_information13,
6383 			l_loc_information14,
6384 			l_loc_information15,
6385 			l_loc_information16,
6386 			l_loc_information17,
6387 			l_loc_information18,
6388 			l_loc_information19,
6389 			l_loc_information20,
6390 			l_object_version_number,
6391 			l_attribute_category,
6392 			l_attribute1,
6393 			l_attribute2,
6394 			l_attribute3,
6395 			l_attribute4,
6396 			l_attribute5,
6397 			l_attribute6,
6398 			l_attribute7,
6399 			l_attribute8,
6400 			l_attribute9,
6401 			l_attribute10,
6402 			l_attribute11,
6403 			l_attribute12,
6404 			l_attribute13,
6405 			l_attribute14,
6406 			l_attribute15,
6407 			l_attribute16,
6408 			l_attribute17,
6409 			l_attribute18,
6410 			l_attribute19,
6411 			l_attribute20;
6412 		close get_loc_details;
6413 
6414 		ship_to_address_handler(
6415 			p_task_assignment_id		=> null,
6416 			p_resource_type			=> p_resource_type,
6417 			p_resource_id			=> p_resource_id,
6418 			p_customer_id			=> v_customer_id,
6419 			p_location_id			=> v_location_id,
6420 			p_style				=> l_style,
6421 			p_address_line_1			=> l_address_line_1,
6422 			p_address_line_2			=> l_address_line_2,
6423 			p_address_line_3			=> l_address_line_3,
6424 			p_country				=> l_country,
6425 			p_postal_code			=> l_postal_code,
6426 			p_region_1			=> l_region_1,
6427 			p_region_2			=> l_region_2,
6428 			p_region_3			=> l_region_3,
6429 			p_town_or_city			=> l_town_or_city,
6430 			p_tax_name			=> l_tax_name,
6431 			p_telephone_number_1		=> l_telephone_number_1,
6432 			p_telephone_number_2		=> l_telephone_number_2,
6433 			p_telephone_number_3		=> l_telephone_number_3,
6434 			p_loc_information13		=> l_loc_information13,
6435 			p_loc_information14		=> l_loc_information14,
6436 			p_loc_information15		=> l_loc_information15,
6437 			p_loc_information16		=> l_loc_information16,
6438 			p_loc_information17		=> l_loc_information17,
6439 			p_loc_information18		=> l_loc_information18,
6440 			p_loc_information19		=> l_loc_information19,
6441 			p_loc_information20		=> l_loc_information20,
6442 			p_timezone			=> p_timezone,
6443 			p_primary_flag			=> p_primary_flag,
6444 			p_status				=> p_status,
6445 			p_object_version_number		=> l_object_version_number,
6446 			p_api_version_number		=> 1.0,
6447 			p_init_msg_list			=> 'Y',
6448 			p_commit				=> 'F',
6449 			p_attribute_category		=> l_attribute_category,
6450 			p_attribute1			=> l_attribute1,
6451 			p_attribute2			=> l_attribute2,
6452 			p_attribute3			=> l_attribute3,
6453 			p_attribute4			=> l_attribute4,
6454 			p_attribute5			=> l_attribute5,
6455 			p_attribute6			=> l_attribute6,
6456 			p_attribute7			=> l_attribute7,
6457 			p_attribute8			=> l_attribute8,
6458 			p_attribute9			=> l_attribute9,
6459 			p_attribute10			=> l_attribute10,
6460 			p_attribute11			=> l_attribute11,
6461 			p_attribute12			=> l_attribute12,
6462 			p_attribute13			=> l_attribute13,
6463 			p_attribute14			=> l_attribute14,
6464 			p_attribute15			=> l_attribute15,
6465 			p_attribute16			=> l_attribute16,
6466 			p_attribute17			=> l_attribute17,
6467 			p_attribute18			=> l_attribute18,
6468 			p_attribute19			=> l_attribute19,
6469 			p_attribute20			=> l_attribute20,
6470 			x_return_status			=> x_return_status,
6471 			x_msg_count			=> x_msg_count,
6472 			x_msg_data			=> x_msg_data
6473 			);
6474 
6475 		if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
6476 			FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
6477 				l_module_name,
6478 				'x_return_status=' || x_return_status);
6479 		end if;
6480 
6481 	end if;
6482 
6483 	if(FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) then
6484 		FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
6485 			l_module_name,
6486 			'Done!!!');
6487 	end if;
6488 
6489 END;
6490 
6491 END CSP_SHIP_TO_ADDRESS_PVT;