DBA Data[Home] [Help]

PACKAGE BODY: APPS.HZ_PARTY_V2PUB

Source


1 PACKAGE BODY HZ_PARTY_V2PUB AS
2 /*$Header: ARH2PASB.pls 120.58.12000000.2 2007/06/20 23:14:58 awu ship $ */
3 
4   --------------------------------------
5   -- declaration of private global varibles
6   --------------------------------------
7 
8   g_debug_count                        NUMBER := 0;
9   --g_debug                              BOOLEAN := FALSE;
10 
11   g_pkg_name                           CONSTANT VARCHAR2(30) := 'HZ_PARTY_V2PUB';
12 
13   g_profile_fmt_bkwd_compatible
14              CONSTANT VARCHAR2(30) := 'HZ_FMT_BKWD_COMPATIBLE';
15 
16   g_apps_context                       CONSTANT VARCHAR2(30) := 'dnb_used';
17 
18   TYPE party_dup_rec_type IS RECORD(
19     sic_code                           VARCHAR2(30),
20     sic_code_type                      VARCHAR2(30),
21     hq_branch_ind                      VARCHAR2(2),
22     tax_reference                      VARCHAR2(50),
23     jgzz_fiscal_code                   VARCHAR2(20),
24     duns_number_c                      VARCHAR2(30),
25     pre_name_adjunct                   VARCHAR2(30),
26     first_name                         VARCHAR2(150),
27     middle_name                        VARCHAR2(60),
28     last_name                          VARCHAR2(150),
29     name_suffix                        VARCHAR2(30),
30     title                              VARCHAR2(60),
31     academic_title                     VARCHAR2(260),
32     previous_last_name                 VARCHAR2(150),
33     known_as                           VARCHAR2(240),
34     known_as2                          VARCHAR2(240),
35     known_as3                          VARCHAR2(240),
36     known_as4                          VARCHAR2(240),
37     known_as5                          VARCHAR2(240),
38     person_iden_type                   VARCHAR2(30),
39     person_identifier                  VARCHAR2(60),
40     country                            VARCHAR2(60),
41     address1                           VARCHAR2(240),
42     address2                           VARCHAR2(240),
43     address3                           VARCHAR2(240),
44     address4                           VARCHAR2(240),
45     city                               VARCHAR2(60),
46     postal_code                        VARCHAR2(60),
47     state                              VARCHAR2(60),
48     province                           VARCHAR2(60),
49     county                             VARCHAR2(60),
50     url                                VARCHAR2(2000),
51     email_address                      VARCHAR2(2000),
52     next_fy_potential_revenue          NUMBER,
53     mission_statement                  VARCHAR2(2000),
54     organization_name_phonetic         VARCHAR2(320),
55     person_first_name_phonetic         VARCHAR2(60),
56     person_last_name_phonetic          VARCHAR2(60),
57     middle_name_phonetic               VARCHAR2(60),
58     language_name                      VARCHAR2(4),
59     analysis_fy                        VARCHAR2(5),
60     fiscal_yearend_month               VARCHAR2(30),
61     employees_total                    NUMBER,
62     curr_fy_potential_revenue          NUMBER,
63     year_established                   NUMBER,
64     gsa_indicator_flag                 VARCHAR2(1),
65     created_by_module                  VARCHAR2(150),
66     application_id                     NUMBER
67   );
68 
69   -- Bug 2197181: added for mix-n-match project.
70 
71   g_per_mixnmatch_enabled              VARCHAR2(1);
72   g_per_entity_attr_id                 NUMBER;
73   g_per_selected_datasources           VARCHAR2(600);
74 
75   g_org_mixnmatch_enabled              VARCHAR2(1);
76   g_org_entity_attr_id                 NUMBER;
77   g_org_selected_datasources           VARCHAR2(600);
78 
79   g_resource_busy                      EXCEPTION;
80   PRAGMA EXCEPTION_INIT(g_resource_busy, -00054);
81 
82   --------------------------------------
83   -- declaration of private procedures and functions
84   --------------------------------------
85 
86   --PROCEDURE enable_debug;
87 
88   --PROCEDURE disable_debug;
89 
90   PROCEDURE do_create_person_profile(
91     p_person_rec                       IN     PERSON_REC_TYPE,
92     p_party_id                         IN     NUMBER,
93     x_profile_id                       OUT    NOCOPY NUMBER,
94     p_version_number                   IN     NUMBER,
95     x_rowid                            OUT    NOCOPY ROWID
96   );
97 
98   PROCEDURE do_update_person_profile(
99     p_person_rec                       IN     PERSON_REC_TYPE,
100     p_old_person_rec                   IN     PERSON_REC_TYPE,
101     p_data_source_type                 IN     VARCHAR2,
102     x_profile_id                       OUT    NOCOPY NUMBER
103   );
104 
105   PROCEDURE do_create_org_profile(
106     p_organization_rec                 IN     ORGANIZATION_REC_TYPE,
107     p_party_id                         IN     NUMBER,
108     x_profile_id                       OUT    NOCOPY NUMBER,
109     p_version_number                   IN     NUMBER,
110     x_rowid                            OUT    NOCOPY ROWID
111   );
112 
113   PROCEDURE do_update_org_profile(
114     p_organization_rec                 IN     ORGANIZATION_REC_TYPE,
115     p_old_organization_rec             IN     ORGANIZATION_REC_TYPE,
116     p_data_source_type                 IN     VARCHAR2,
117     x_profile_id                       OUT    NOCOPY NUMBER
118   );
119 
120   PROCEDURE do_create_party_profile (
121     p_party_type                       IN     VARCHAR2,
122     p_party_id                         IN     NUMBER,
123     p_person_rec                       IN OUT NOCOPY PERSON_REC_TYPE,
124     p_organization_rec                 IN OUT NOCOPY ORGANIZATION_REC_TYPE,
125     p_content_source_type              IN     VARCHAR2,
126     p_actual_content_source            IN     VARCHAR2,
127     x_profile_id                       OUT    NOCOPY NUMBER
128   );
129 
130   PROCEDURE do_update_party_profile (
131     p_party_type                       IN     VARCHAR2,
132     p_person_rec                       IN     PERSON_REC_TYPE,
133     p_old_person_rec                   IN     PERSON_REC_TYPE := G_MISS_PERSON_REC,
134     p_organization_rec                 IN     ORGANIZATION_REC_TYPE,
135     p_old_organization_rec             IN     ORGANIZATION_REC_TYPE := G_MISS_ORGANIZATION_REC,
136     p_data_source_type                 IN     VARCHAR2,
137     x_profile_id                       OUT    NOCOPY NUMBER
138   );
139 
140   PROCEDURE do_get_party_profile (
141     p_party_type                       IN     VARCHAR2,
142     p_party_id                         IN     NUMBER,
143     p_data_source_type                 IN     VARCHAR2,
144     x_person_rec                       OUT    NOCOPY PERSON_REC_TYPE,
145     x_organization_rec                 OUT    NOCOPY ORGANIZATION_REC_TYPE
146   );
147 
148   PROCEDURE do_create_update_party_only(
149     p_create_update_flag               IN     VARCHAR2,
150     p_party_type                       IN     VARCHAR2,
151     -- p_party_id is used in update mode only.
152     p_party_id                         IN     NUMBER := NULL,
153     p_check_object_version_number      IN     VARCHAR2 := 'Y',
154     p_party_object_version_number      IN OUT NOCOPY NUMBER,
155     p_person_rec                       IN     PERSON_REC_TYPE := G_MISS_PERSON_REC,
156     p_old_person_rec                   IN     PERSON_REC_TYPE := G_MISS_PERSON_REC,
157     p_organization_rec                 IN     ORGANIZATION_REC_TYPE := G_MISS_ORGANIZATION_REC,
158     p_old_organization_rec             IN     ORGANIZATION_REC_TYPE := G_MISS_ORGANIZATION_REC,
159     p_group_rec                        IN     GROUP_REC_TYPE := G_MISS_GROUP_REC,
160     p_old_group_rec                    IN     GROUP_REC_TYPE := G_MISS_GROUP_REC,
161     -- x_party_id and x_party_number are used in create mode.
162     x_party_id                         OUT    NOCOPY NUMBER,
163     x_party_number                     OUT    NOCOPY VARCHAR2
164   );
165 
166   PROCEDURE do_create_party (
167     p_party_type                       IN     VARCHAR2,
168     p_party_usage_code                 IN     VARCHAR2,
169     p_person_rec                       IN OUT NOCOPY PERSON_REC_TYPE,
170     p_organization_rec                 IN OUT NOCOPY ORGANIZATION_REC_TYPE,
171     p_group_rec                        IN OUT NOCOPY GROUP_REC_TYPE,
172     x_party_id                         OUT    NOCOPY NUMBER,
173     x_party_number                     OUT    NOCOPY VARCHAR2,
174     x_profile_id                       OUT    NOCOPY NUMBER,
175     x_return_status                    IN OUT NOCOPY VARCHAR2
176   );
177 
178   PROCEDURE do_update_party (
179     p_party_type                       IN     VARCHAR2,
180     p_person_rec                       IN OUT NOCOPY PERSON_REC_TYPE,
181     p_old_person_rec                   IN     PERSON_REC_TYPE := G_MISS_PERSON_REC,
182     p_organization_rec                 IN OUT NOCOPY ORGANIZATION_REC_TYPE,
183     p_old_organization_rec             IN     ORGANIZATION_REC_TYPE := G_MISS_ORGANIZATION_REC,
184     p_group_rec                        IN OUT NOCOPY GROUP_REC_TYPE,
185     p_old_group_rec                    IN     GROUP_REC_TYPE := G_MISS_GROUP_REC,
186     p_party_object_version_number      IN OUT NOCOPY NUMBER,
187     x_profile_id                       OUT    NOCOPY NUMBER,
188     x_return_status                    IN OUT NOCOPY VARCHAR2
189   );
190 
191   FUNCTION party_exists(
192     p_party_type                       IN     VARCHAR2,
193     p_party_id                         IN     NUMBER,
194     x_party_number                     OUT    NOCOPY VARCHAR2
195   ) RETURN VARCHAR2;
196 
197   FUNCTION party_profile_exists(
198     p_party_type                       IN     VARCHAR2,
199     p_party_id                         IN     NUMBER,
200     p_data_source_type                 IN     VARCHAR2
201   ) RETURN VARCHAR2;
202 
203   FUNCTION reset_sst_to_userentered(
204     p_party_type                       IN     VARCHAR2,
205     p_party_id                         IN     NUMBER
206   ) RETURN VARCHAR2;
207 
208   FUNCTION do_create_person_name(
209     p_person_rec                       IN     PERSON_REC_TYPE
210   ) RETURN VARCHAR2;
211 
212   FUNCTION do_create_party_name(
213     p_person_first_name                IN     VARCHAR2,
214     p_person_last_name                 IN     VARCHAR2
215   ) RETURN VARCHAR2;
216 
217   PROCEDURE do_update_party_rel_name(
218     p_party_id                         IN     NUMBER,
219     p_party_name                       IN     HZ_PARTIES.PARTY_NAME%TYPE
220   );
221 
222   PROCEDURE do_process_classification(
223     p_create_update_flag               IN     VARCHAR2,
224     p_party_type                       IN     VARCHAR2,
225     p_organization_rec                 IN     ORGANIZATION_REC_TYPE := G_MISS_ORGANIZATION_REC,
226     p_old_organization_rec             IN     ORGANIZATION_REC_TYPE := G_MISS_ORGANIZATION_REC,
227     p_person_rec                       IN     PERSON_REC_TYPE := G_MISS_PERSON_REC,
228     p_old_person_rec                   IN     PERSON_REC_TYPE := G_MISS_PERSON_REC,
229     p_group_rec                        IN     GROUP_REC_TYPE := G_MISS_GROUP_REC,
230     p_old_group_rec                    IN     GROUP_REC_TYPE := G_MISS_GROUP_REC,
231     p_data_source_type                 IN     VARCHAR2,
232     x_return_status                    IN OUT NOCOPY VARCHAR2
233   );
234 
235   -- Bug 3868940
236   /*
237   PROCEDURE org_rec_to_cr_rec(
238     p_create_update_flag               IN     VARCHAR2,
239     p_organization_rec                 IN     ORGANIZATION_REC_TYPE,
240     x_credit_rating_rec                OUT    NOCOPY hz_party_info_pub.credit_ratings_rec_type
241   );
242   */
243 
244   PROCEDURE populate_credit_rating(
245     p_create_update_flag               IN     VARCHAR2,
246     p_organization_rec                 IN     ORGANIZATION_REC_TYPE,
247     x_return_status                    IN OUT NOCOPY VARCHAR2
248   );
249 
250 ---Bug No: 2771835------------------------------------------
251 PROCEDURE update_party_search(p_party_id          IN  NUMBER,
252                               p_old_party_name    IN  VARCHAR2,
253                               p_new_party_name    IN  VARCHAR2,
254                               p_old_tax_reference IN  VARCHAR2,
255                               p_new_tax_reference IN  VARCHAR2);
256 FUNCTION isModified(p_old_value VARCHAR2,p_new_value VARCHAR2)
257 RETURN BOOLEAN;
258 PROCEDURE update_rel_person_search(p_old_person_rec IN  HZ_PARTY_V2PUB.PERSON_REC_TYPE,
259                                    p_new_person_rec IN  HZ_PARTY_V2PUB.PERSON_REC_TYPE);
260 -------------------------Bug 4586451
261 PROCEDURE validate_party_name (
262     p_party_id                    IN     NUMBER,
263     p_party_name                  IN     VARCHAR2,
264     x_return_status               IN OUT NOCOPY VARCHAR2
265 );
266 ---------------------------------Bug 4586451
267 
268 ---End of Bug No: 2771835---------------------------------------
269 
270   --------------------------------------
271   -- private procedures and functions
272   --------------------------------------
273 
274   /**
275    * PRIVATE PROCEDURE enable_debug
276    *
277    * DESCRIPTION
278    *     Turn on debug mode.
279    *
280    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
281    *     hz_utility_v2pub.enable_debug
282    *
283    * MODIFICATION HISTORY
284    *
285    *   07-23-2001    Jianying Huang      o Created.
286    *
287    */
288 
289   /*PROCEDURE enable_debug IS
290 
291   BEGIN
292     g_debug_count := g_debug_count + 1;
293 
294     IF g_debug_count = 1 THEN
295       IF fnd_profile.value('HZ_API_FILE_DEBUG_ON') = 'Y' OR
296          fnd_profile.value('HZ_API_DBMS_DEBUG_ON') = 'Y'
297       THEN
298         hz_utility_v2pub.enable_debug;
299         g_debug := TRUE;
300       END IF;
301     END IF;
302   END enable_debug;
303   */
304   /**
305    * PRIVATE PROCEDURE disable_debug
306    *
307    * DESCRIPTION
308    *     Turn off debug mode.
309    *
310    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
311    *     hz_utility_v2pub.disable_debug
312    *
313    * MODIFICATION HISTORY
314    *
315    *   07-23-2001    Jianying Huang      o Created.
316    *
317    */
318 
319   /*PROCEDURE disable_debug IS
320 
321   BEGIN
322 
323     IF g_debug THEN
324       g_debug_count := g_debug_count - 1;
325 
326       IF g_debug_count = 0 THEN
327         hz_utility_v2pub.disable_debug;
328         g_debug := FALSE;
329       END IF;
330     END IF;
331 
332   END disable_debug;
333   */
334 
335   /**
336    * PRIVATE FUNCTION party_exists
337    *
338    * DESCRIPTION
339    *    Returns if party exists based on the party type
340    *    and party_id.
341    *
342    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
343    *
344    * ARGUMENTS
345    *     IN:
346    *       p_party_type
347    *       p_party_id
348    *     OUT:
349    *       x_party_number
350    *     IN/ OUT:
351    *
352    * NOTES
353    *
354    * MODIFICATION HISTORY
355    */
356 
357   FUNCTION party_exists(
358     p_party_type                       IN     VARCHAR2,
359     p_party_id                         IN     NUMBER,
360     x_party_number                     OUT    NOCOPY VARCHAR2
361   ) RETURN VARCHAR2 IS
362 
363     CURSOR c_party_exists IS
364       SELECT party_type, party_number
365       FROM hz_parties
366       WHERE party_id = p_party_id;
367 
368     l_party_type                       VARCHAR2(30);
369     l_party_number                     HZ_PARTIES.PARTY_NUMBER%TYPE;
370     l_debug_prefix                     VARCHAR2(30) := '';
371   BEGIN
372     -- Debug info.
373 
374     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
375       hz_utility_v2pub.debug(p_message=>'party exists (+)',
376                              p_prefix=>l_debug_prefix,
377                              p_msg_level=>fnd_log.level_procedure);
378     END IF;
379 
380 
381 
382     OPEN c_party_exists;
383     FETCH c_party_exists INTO l_party_type, l_party_number;
384 
385     IF c_party_exists%NOTFOUND THEN
386       l_party_type := NULL;
387     END IF;
388     CLOSE c_party_exists;
389 
390     -- Debug info.
391     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
392         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,
393                                p_message=>'party exists (-)',
394                                p_msg_level=>fnd_log.level_procedure);
395     END IF;
396 
397 
398     IF l_party_type IS NULL THEN
399       x_party_number := NULL;
400       RETURN 'N';
401     ELSIF l_party_type = p_party_type THEN
402       x_party_number := l_party_number;
403       RETURN 'Y';
404     ELSE
405       /* new message */
406       fnd_message.set_name('AR','HZ_DUP_PARTY_WITH_PARTY_TYPE');
407       fnd_message.set_token('PARTY_ID', p_party_id);
408       fnd_message.set_token('PARTY_TYPE', l_party_type);
409       fnd_msg_pub.add;
410       RAISE FND_API.G_EXC_ERROR;
411     END IF;
412 
413   END party_exists;
414 
415   /**
416    * PRIVATE FUNCTION do_create_person_name
417    *
418    * DESCRIPTION
419    *     Creates person name.
420    *
421    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
422    *
423    * ARGUMENTS
424    *     IN:
425    *       p_party_id
426    *       p_party_name
427    *     OUT:
428    *     IN/ OUT:
429    *
430    * NOTES
431    *
432    * MODIFICATION HISTORY
433    * 02-21-2002    Chris Saulit        o Modify do_create_person_name to
434    *                                     call the new name formatting routine.
435    *                                     Base Bug #2221071
436    */
437 
438   FUNCTION do_create_person_name (
439     p_person_rec                       IN     PERSON_REC_TYPE
440   ) RETURN VARCHAR2 IS
441 
442  -- l_person_name                      hz_person_profiles.person_name%TYPE;
443     l_person_name                      VARCHAR2(454); --Type Length changed as per bug #5227963
444     l_debug_prefix                     VARCHAR2(30) := '';
445 
446   BEGIN
447 
448     -- Debug info.
449     /*IF g_debug THEN
450       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_create_person_name (+)');
451     END IF;
452     */
453     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
454         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_create_person_name (+)',
455                                p_msg_level=>fnd_log.level_procedure);
456     END IF;
457 
458     --
459     --  Check "backwards compatability" profile option and determine
460     --  whether to stick with the old-style name formatting, or call
461     --  the new dynamic name formatting routines.
462     --
463 
464     -- use new routines
465 
466     IF nvl(fnd_profile.value(g_profile_fmt_bkwd_compatible),'Y') = 'N' THEN
467 
468       --
469       --  Invoke the person name formatting API
470       --
471 
472       DECLARE
473 
474         l_line_cnt            NUMBER;
475         l_return_status       VARCHAR2(1);
476         l_msg_cnt             NUMBER;
477         l_msg_data            VARCHAR2(2000);
478 
479         l_formatted_lines_cnt NUMBER;
480         l_formatted_name_tbl  hz_format_pub.string_tbl_type;
481 
482       BEGIN
483 
484         hz_format_pub.format_name (
485           -- input parameters
486           p_person_title                => p_person_rec.person_title,
487           p_person_first_name           => p_person_rec.person_first_name,
488           p_person_middle_name          => p_person_rec.person_middle_name,
489           p_person_last_name            => p_person_rec.person_last_name,
490           p_person_name_suffix          => p_person_rec.person_name_suffix,
491           p_person_known_as             => p_person_rec.known_as,
492           p_first_name_phonetic         => p_person_rec.person_first_name_phonetic,
493           p_middle_name_phonetic        => p_person_rec.middle_name_phonetic,
494           p_last_name_phonetic          => p_person_rec.person_last_name_phonetic,
495           -- output parameters
496           x_return_status               => l_return_status,
497           x_msg_count                   => l_msg_cnt,
498           x_msg_data                    => l_msg_data,
499           x_formatted_name              => l_person_name,
500           x_formatted_lines_cnt         => l_formatted_lines_cnt,
501           x_formatted_name_tbl          => l_formatted_name_tbl
502         );
503 
504         -- If there are any errors, ignore them.  Not serious enough
505         -- to abort the transaction.  Messages will be on the stack.
506         -- If person name has not been determined, it will default
507         -- to the original logic below.
508 
509       EXCEPTION
510         WHEN OTHERS THEN NULL;
511       END;
512 
513     END IF;
514 
515     IF l_person_name IS NULL THEN
516 
517       --
518       --  Preserve backwards compatibility and use the original logic
519       --
520 
521       IF p_person_rec.person_title IS NOT NULL AND
522          p_person_rec.person_title <> FND_API.G_MISS_CHAR
523       THEN
524         l_person_name := p_person_rec.person_title;
525       END IF;
526 
527       IF p_person_rec.person_first_name IS NOT NULL AND
528          p_person_rec.person_first_name <> FND_API.G_MISS_CHAR
529       THEN
530         IF l_person_name IS NOT NULL THEN
531           l_person_name := l_person_name || ' ' || p_person_rec.person_first_name;
532         ELSE
533           l_person_name := p_person_rec.person_first_name;
534         END IF;
535       END IF;
536 
537       IF p_person_rec.person_middle_name IS NOT NULL AND
538          p_person_rec.person_middle_name <> FND_API.G_MISS_CHAR
539       THEN
540         IF l_person_name IS NOT NULL THEN
541           l_person_name := l_person_name || ' ' || p_person_rec.person_middle_name;
542         ELSE
543           l_person_name := p_person_rec.person_middle_name;
544         END IF;
545       END IF;
546 
547       IF p_person_rec.person_last_name IS NOT NULL AND
548          p_person_rec.person_last_name <> FND_API.G_MISS_CHAR
549       THEN
550         IF l_person_name IS NOT NULL THEN
551           l_person_name := l_person_name || ' ' || p_person_rec.person_last_name;
552         ELSE
553           l_person_name := p_person_rec.person_last_name;
554         END IF;
555       END IF;
556 
557       IF p_person_rec.person_name_suffix IS NOT NULL AND
558          p_person_rec.person_name_suffix <> FND_API.G_MISS_CHAR
559       THEN
560         IF l_person_name IS NOT NULL THEN
561           l_person_name := l_person_name || ' ' || p_person_rec.person_name_suffix;
562         ELSE
563           l_person_name := p_person_rec.person_name_suffix;
564         END IF;
565       END IF;
566     END IF;
567 
568     -- Debug info.
569     /*IF g_debug THEN
570       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'l_person_name = '||l_person_name);
571       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_create_person_name (-)');
572     END IF;
573     */
574     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
575         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_create_person_name (-)',
576                                p_msg_level=>fnd_log.level_procedure);
577     END IF;
578     IF fnd_log.level_statement>=fnd_log.g_current_runtime_level THEN
579            hz_utility_v2pub.debug(p_message=>'l_person_name = '||l_person_name,
580                                   p_prefix =>l_debug_prefix,
581                                   p_msg_level=>fnd_log.level_statement);
582     END IF;
583 
584     RETURN(SUBSTRB(l_person_name, 1, 450));
585 
586   END do_create_person_name;
587 
588   /**
589    * PRIVATE FUNCTION do_create_party_name
590    *
591    * DESCRIPTION
592    *     Creates party name.
593    *
594    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
595    *
596    * ARGUMENTS
597    *     IN:
598    *       p_person_first_name
599    *       p_person_last_name
600    *     OUT:
601    *     IN/ OUT:
602    *
603    * NOTES
604    *
605    * MODIFICATION HISTORY
606    */
607 
608   FUNCTION do_create_party_name (
609     p_person_first_name                IN     VARCHAR2,
610     p_person_last_name                 IN     VARCHAR2
611   ) RETURN VARCHAR2 IS
612 
613     l_party_name                       HZ_PARTIES.PARTY_NAME%TYPE;
614     l_debug_prefix                     VARCHAR2(30) := '';
615   BEGIN
616 
617     -- Debug info.
618     /*IF g_debug THEN
619       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_create_party_name (+)');
620     END IF;
621     */
622     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
623         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_create_party_name (+)',
624                                p_msg_level=>fnd_log.level_procedure);
625     END IF;
626 
627     IF p_person_first_name IS NOT NULL AND
628        p_person_first_name <> FND_API.G_MISS_CHAR
629     THEN
630       l_party_name := p_person_first_name;
631     END IF;
632 
633     IF p_person_last_name IS NOT NULL AND
634        p_person_last_name <> FND_API.G_MISS_CHAR
635     THEN
636       IF l_party_name IS NOT NULL THEN
637         l_party_name := l_party_name||' '||p_person_last_name;
638       ELSE
639         l_party_name := p_person_last_name;
640       END IF;
641     END IF;
642 
643     -- Debug info.
644     /*IF g_debug THEN
645       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'l_party_name = '||l_party_name);
646       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_create_party_name (-)');
647     END IF;*/
648     IF fnd_log.level_statement>=fnd_log.g_current_runtime_level THEN
649            hz_utility_v2pub.debug(p_message=>'l_party_name = '||l_party_name,
650                                   p_prefix =>l_debug_prefix,
651                                   p_msg_level=>fnd_log.level_statement);
652     END IF;
653     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
654         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_create_party_name (-)',
655                                p_msg_level=>fnd_log.level_procedure);
656     END IF;
657 
658 
659     RETURN l_party_name;
660 
661   END do_create_party_name;
662 
663   /**
664    * PRIVATE PROCEDURE do_update_party_rel_name
665    *
666    * DESCRIPTION
667    *     update party relationships' party name when subject or object
668    *     party's name has been changed. The procedure should be
669    *     a recursive one because we might have a party relationship
670    *     whose subject or object party is a relationship too.
671    *
672    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
673    *
674    * ARGUMENTS
675    *     IN:
676    *       p_party_id
677    *       p_party_name
678    *     OUT:
679    *     IN/ OUT:
680    *
681    * NOTES
682    *
683    * MODIFICATION HISTORY
684    *
685    */
686 
687   PROCEDURE do_update_party_rel_name(
688     p_party_id                         IN     NUMBER,
689     p_party_name                       IN     HZ_PARTIES.PARTY_NAME%TYPE
690   ) IS
691 
692     l_party_name                       HZ_PARTIES.party_name%TYPE;
693 
694     CURSOR c_party_rels IS
695       SELECT r.party_id, r.object_id, o.party_name, r.subject_id, s.party_name,
696              rel.party_number, rel.party_name
697       FROM hz_relationships r, hz_parties s, hz_parties o, hz_parties rel
698       WHERE (r.subject_id = p_party_id OR r.object_id = p_party_id)
699       AND r.party_id IS NOT NULL
700       AND r.subject_table_name = 'HZ_PARTIES'
701       AND r.object_table_name = 'HZ_PARTIES'
702       AND r.directional_flag = 'F'
703       AND r.subject_id = s.party_id
704       AND r.object_id = o.party_id
705       AND r.party_id = rel.party_id;
706 
707     TYPE IDlist IS TABLE OF NUMBER(15);
708     TYPE NAMElist IS TABLE OF HZ_PARTIES.PARTY_NAME%TYPE;
709     TYPE NUMBERlist IS TABLE OF HZ_PARTIES.PARTY_NUMBER%TYPE;
710 
711     i_party_id                         IDlist;
712     i_object_id                        IDlist;
713     i_object_name                      NAMElist;
714     i_subject_id                       IDlist;
715     i_subject_name                     NAMElist;
716     i_party_number                     NUMBERlist;
717     i_party_name                       NAMElist;
718     l_dummy                            VARCHAR2(1);
719     l_debug_prefix                     VARCHAR2(30) := '';
720 
721   BEGIN
722 
723     -- Debug info.
724     /*IF g_debug THEN
725       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_update_party_rel_name (+)');
726     END IF;
727     */
728     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
729         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_update_party_rel_name (+)',
730                                p_msg_level=>fnd_log.level_procedure);
731     END IF;
732 
733 
734     OPEN c_party_rels;
735     FETCH c_party_rels BULK COLLECT INTO
736       i_party_id,i_object_id,i_object_name,i_subject_id,i_subject_name,
737       i_party_number, i_party_name;
738     CLOSE c_party_rels;
739 
740     FOR i IN 1..i_party_id.COUNT LOOP
741       l_party_name := SUBSTRB(i_subject_name(i) || '-' ||
742                              i_object_name(i)  || '-' ||
743                              i_party_number(i), 1, 360);
744 
745       IF l_party_name <> i_party_name(i) THEN
746         --check if party is locked by any one else.
747         BEGIN
748           SELECT 'Y'
749           INTO   l_dummy
750           FROM   hz_parties
751           WHERE  PARTY_ID = i_party_id(i)
752           FOR UPDATE NOWAIT;
753         EXCEPTION
754           WHEN OTHERS THEN
755             fnd_message.set_name('AR', 'HZ_API_RECORD_CHANGED');
756             fnd_message.set_token('TABLE', 'HZ_PARTIES');
757             fnd_msg_pub.add;
758             RAISE FND_API.G_EXC_ERROR;
759         END;
760 
761         UPDATE hz_parties
762         SET party_name = l_party_name
763         WHERE party_id = i_party_id(i);
764       END IF;
765 
766       --recursively update those party relationships' name whose
767       --subject or object party might also be a party relationship.
768 
769       do_update_party_rel_name(i_party_id(i), l_party_name);
770 
771     END LOOP;
772 
773     -- Debug info.
774 
775     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
776         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_update_party_rel_name (-)',
777                                p_msg_level=>fnd_log.level_procedure);
778     END IF;
779 
780   END do_update_party_rel_name;
781 
782   /**
783    * PRIVATE FUNCTION party_profile_exists
784    *
785    * DESCRIPTION
786    *    Returns if a party profile exists based
787    *    on the type, id and data source.
788    *
789    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
790    *
791    * ARGUMENTS
792    *     IN:
793    *       p_party_type
794    *       p_party_id
795    *       p_data_source_type
796    *     OUT:
797    *     IN/ OUT:
798    *
799    * NOTES
800    *
801    * MODIFICATION HISTORY
802    */
803 
804   FUNCTION party_profile_exists(
805     p_party_type                    IN     VARCHAR2,
806     p_party_id                      IN     NUMBER,
807     p_data_source_type              IN     VARCHAR2
808   ) RETURN VARCHAR2 IS
809 
810     CURSOR c_org_profile_exists IS
811       SELECT 'Y'
812       FROM hz_organization_profiles
813       WHERE party_id = p_party_id
814       AND actual_content_source = p_data_source_type
815       AND effective_end_date IS NULL;
816 
817     CURSOR c_per_profile_exists IS
818       SELECT 'Y'
819       FROM hz_person_profiles
820       WHERE party_id = p_party_id
821       AND actual_content_source = p_data_source_type
822       AND effective_end_date IS NULL;
823 
824     l_dummy                         VARCHAR2(1);
825     l_debug_prefix                     VARCHAR2(30) := '';
826   BEGIN
827 
828     -- Debug info.
829     /*IF g_debug THEN
830       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'party profile exists (+)');
831     END IF;
832     */
833     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
834         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'party profile exists (+)',
835                                p_msg_level=>fnd_log.level_procedure);
836     END IF;
837 
838     IF p_party_type = 'PERSON' THEN
839 
840       OPEN c_per_profile_exists;
841       FETCH c_per_profile_exists INTO l_dummy;
842 
843       IF c_per_profile_exists%NOTFOUND THEN
844         l_dummy := 'N';
845       END IF;
846       CLOSE c_per_profile_exists;
847 
848     ELSIF p_party_type = 'ORGANIZATION' THEN
849 
850       OPEN c_org_profile_exists;
851       FETCH c_org_profile_exists INTO l_dummy;
852 
853       IF c_org_profile_exists%NOTFOUND THEN
854         l_dummy := 'N';
855       END IF;
856       CLOSE c_org_profile_exists;
857 
858     END IF;
859 
860     -- Debug info.
861     /*IF g_debug THEN
862       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'party profile exists (-)');
863     END IF;
864     */
865     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
866         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'party profile exists (-)',
867                                p_msg_level=>fnd_log.level_procedure);
868     END IF;
869 
870     RETURN l_dummy;
871 
872   END party_profile_exists;
873 
874   /**
875    * PRIVATE FUNCTION reset_sst_to_userentered
876    *
877    * DESCRIPTION
878    *    Returns 'Y' if a sst profile has been re-set
879    *    to user-entered profile.
880    *
881    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
882    *
883    * ARGUMENTS
884    *     IN:
885    *       p_party_type
886    *       p_party_id
887    *     OUT:
888    *     IN/ OUT:
889    *
890    * NOTES
891    *
892    * MODIFICATION HISTORY
893    */
894 
895   FUNCTION reset_sst_to_userentered(
896     p_party_type                    IN     VARCHAR2,
897     p_party_id                      IN     NUMBER
898   ) RETURN VARCHAR2 IS
899   l_debug_prefix                       VARCHAR2(30) := '';
900   BEGIN
901 
902     -- Debug info.
903     /*IF g_debug THEN
904       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'reset_sst_to_userentered (+)');
905     END IF;
906     */
907     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
908         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'reset_sst_to_userentered (+)',
909                                p_msg_level=>fnd_log.level_procedure);
910     END IF;
911 
912     IF p_party_type = 'PERSON' THEN
913 
914       UPDATE hz_person_profiles
915       SET actual_content_source = G_MISS_CONTENT_SOURCE_TYPE
916       WHERE party_id = p_party_id
917       AND actual_content_source = G_SST_SOURCE_TYPE
918       AND effective_end_date IS NULL
919       AND NOT EXISTS (
920         SELECT 'Y'
921         FROM hz_person_profiles
922         WHERE party_id = p_party_id
923         AND actual_content_source = G_MISS_CONTENT_SOURCE_TYPE
924         AND effective_end_date IS NULL );
925 
926     ELSIF p_party_type = 'ORGANIZATION' THEN
927 
928       UPDATE hz_organization_profiles
929       SET actual_content_source = G_MISS_CONTENT_SOURCE_TYPE
930       WHERE party_id = p_party_id
931       AND actual_content_source = G_SST_SOURCE_TYPE
932       AND effective_end_date IS NULL
933       AND NOT EXISTS (
934         SELECT 'Y'
935         FROM hz_organization_profiles
936         WHERE party_id = p_party_id
937         AND actual_content_source = G_MISS_CONTENT_SOURCE_TYPE
938         AND effective_end_date IS NULL );
939 
940     END IF;
941 
942     -- Debug info.
943     /*IF g_debug THEN
944       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'reset_sst_to_userentered (-)');
945     END IF;
946     */
947 /*
948     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
949         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'reset_sst_to_userentered (-)',
950                                p_msg_level=>fnd_log.level_procedure);
951     END IF;
952 */
953     IF SQL%NOTFOUND THEN
954       RETURN 'N';
955     ELSE
956       RETURN 'Y';
957     END IF;
958 
959   END reset_sst_to_userentered;
960 
961   /**
962    * PRIVATE PROCEDURE do_process_classification
963    *
964    * DESCRIPTION
965    *    Processes classification related columns.
966    *
967    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
968    *
969    * ARGUMENTS
970    *     IN:
971    *       p_create_update_flag
972    *       p_organization_rec
973    *       p_old_organization_rec
974    *       p_data_source_type
975    *     OUT:
976    *     IN/ OUT:
977    *       x_return_status
978    *
979    * NOTES
980    *
981    * MODIFICATION HISTORY
982    */
983 
984   PROCEDURE do_process_classification(
985     p_create_update_flag            IN     VARCHAR2,
986     p_party_type                    IN     VARCHAR2,
987     p_organization_rec              IN     ORGANIZATION_REC_TYPE := G_MISS_ORGANIZATION_REC,
988     p_old_organization_rec          IN     ORGANIZATION_REC_TYPE := G_MISS_ORGANIZATION_REC,
989     p_person_rec                    IN     PERSON_REC_TYPE := G_MISS_PERSON_REC,
990     p_old_person_rec                IN     PERSON_REC_TYPE := G_MISS_PERSON_REC,
991     p_group_rec                     IN     GROUP_REC_TYPE := G_MISS_GROUP_REC,
992     p_old_group_rec                 IN     GROUP_REC_TYPE := G_MISS_GROUP_REC,
993     p_data_source_type              IN     VARCHAR2,
994     x_return_status                 IN OUT NOCOPY VARCHAR2
995   ) IS
996 
997     l_code_assignment_id            NUMBER;
998     l_msg_count                     NUMBER;
999     l_msg_data                      VARCHAR2(2000);
1000     l_sic_code                      HZ_PARTIES.SIC_CODE%TYPE;
1001     l_sic_code_type                 HZ_PARTIES.SIC_CODE_TYPE%TYPE;
1002     l_data_source_type              VARCHAR2(30);
1003     l_party_rec                     PARTY_REC_TYPE;
1004     l_old_party_rec                 PARTY_REC_TYPE;
1005 
1006     -- Bug 3040565 : Added a locla variable to store local_activity_code_type
1007 
1008    l_local_activity_code_type    varchar2(30);
1009    l_debug_prefix                      VARCHAR2(30) := '';
1010    --4232060
1011    l_created_by_module varchar2(150);
1012   BEGIN
1013     -- Debug info.
1014     /*IF g_debug THEN
1015       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_process_classification (+)');
1016       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'party_id = '||p_organization_rec.party_rec.party_id);
1017     END IF;
1018     */
1019     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
1020         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_process_classification (+)',
1021                                p_msg_level=>fnd_log.level_procedure);
1022     END IF;
1023     IF fnd_log.level_statement>=fnd_log.g_current_runtime_level THEN
1024            hz_utility_v2pub.debug(p_message=>'party_id = '||p_organization_rec.party_rec.party_id,
1025                                   p_prefix =>l_debug_prefix,
1026                                   p_msg_level=>fnd_log.level_statement);
1027     END IF;
1028 
1029     IF p_data_source_type = G_SST_SOURCE_TYPE THEN
1030       l_data_source_type := G_MISS_CONTENT_SOURCE_TYPE;
1031     ELSE
1032       l_data_source_type := p_data_source_type;
1033     END IF;
1034 
1035     IF p_party_type = 'PERSON' THEN
1036       l_party_rec := p_person_rec.party_rec;
1037       l_old_party_rec := p_old_person_rec.party_rec;
1038       --4621564
1039       IF p_old_person_rec.created_by_module = fnd_api.g_miss_char THEN
1040           l_created_by_module := 'TCA_V2_API';
1041       ELSE
1042           l_created_by_module := p_old_person_rec.created_by_module;
1043       END IF;
1044       --4232060
1045       l_created_by_module := nvl(p_person_rec.created_by_module,l_created_by_module);
1046     ELSIF p_party_type = 'ORGANIZATION' THEN
1047       l_party_rec := p_organization_rec.party_rec;
1048       l_old_party_rec := p_old_organization_rec.party_rec;
1049       --4621564
1050       IF p_old_organization_rec.created_by_module = fnd_api.g_miss_char THEN
1051           l_created_by_module := 'TCA_V2_API';
1052       ELSE
1053           l_created_by_module := p_old_organization_rec.created_by_module;
1054       END IF;
1055       --4232060
1056       l_created_by_module := nvl(p_organization_rec.created_by_module,l_created_by_module);
1057     ELSE
1058       l_party_rec := p_group_rec.party_rec;
1059       l_old_party_rec := p_old_group_rec.party_rec;
1060       --4621564
1061       IF p_old_group_rec.created_by_module = fnd_api.g_miss_char THEN
1062           l_created_by_module := 'TCA_V2_API';
1063       ELSE
1064           l_created_by_module := p_old_group_rec.created_by_module;
1065       END IF;
1066       --4232060
1067       l_created_by_module := nvl(p_group_rec.created_by_module,l_created_by_module);
1068     END IF;
1069 
1070     -- call hz_classification_v2pub.set_primary_code_assignment when
1071     -- CATEGORY_CODE is specified for a user entered party.
1072     -- you can have customer category for a person not just organization.
1073     -- we should remove category_code from the party_rec once CRM uptake the
1074     -- new TCA classification model. Other application should not use the
1075     -- the category code column in the party table.
1076 
1077     -- We do not need to change the content source logic because of the mix-n-match.
1078     -- Mapping API is not populating party_rec.category_code.
1079 
1080     IF (p_create_update_flag = 'C' AND
1081         l_party_rec.category_code IS NOT NULL AND
1082         l_party_rec.category_code <> FND_API.G_MISS_CHAR) OR
1083        (p_create_update_flag = 'U'AND
1084         l_party_rec.category_code IS NOT NULL AND
1085         -- Bug 3876180.
1086         -- l_party_rec.category_code <> FND_API.G_MISS_CHAR AND
1087         l_party_rec.category_code <> l_old_party_rec.category_code) AND
1088        l_data_source_type = G_MISS_CONTENT_SOURCE_TYPE
1089     THEN
1090        hz_classification_v2pub.set_primary_code_assignment(
1091         p_owner_table_name          => 'HZ_PARTIES',
1092         p_owner_table_id            => l_party_rec.party_id,
1093         p_class_category            => 'CUSTOMER_CATEGORY',
1094         p_class_code                => l_party_rec.category_code,
1095         p_content_source_type       => l_data_source_type,
1096         -- Bug 3856348
1097       --  p_created_by_module         => nvl(p_organization_rec.created_by_module,
1098         --                               p_old_organization_rec.created_by_module),
1099         --4232060
1100         p_created_by_module         => l_created_by_module,
1101         x_code_assignment_id        => l_code_assignment_id,
1102         x_return_status             => x_return_status,
1103         x_msg_count                 => l_msg_count,
1104         x_msg_data                  => l_msg_data );
1105 
1106       IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1107         RAISE FND_API.G_EXC_ERROR;
1108       END IF;
1109     END IF;
1110 
1111     IF p_party_type = 'ORGANIZATION' THEN
1112 
1113       -- sic_code_type is required for entering sic_code. When inserting
1114       -- sic_code_type is required for entering sic_code and vice versa.
1115       -- That means, for both of them, we either provide values or leave
1116       -- them NULL.
1117       IF p_create_update_flag = 'C' THEN
1118         l_sic_code := NVL(p_organization_rec.sic_code, FND_API.G_MISS_CHAR);
1119         l_sic_code_type := NVL(p_organization_rec.sic_code_type, FND_API.G_MISS_CHAR);
1120       ELSE
1121         l_sic_code := NVL(p_organization_rec.sic_code, p_old_organization_rec.sic_code);
1122         l_sic_code_type := NVL(p_organization_rec.sic_code_type, p_old_organization_rec.sic_code_type);
1123       END IF;
1124 
1125       IF (l_sic_code_type = FND_API.G_MISS_CHAR AND
1126           l_sic_code <> FND_API.G_MISS_CHAR) OR
1127          (l_sic_code = FND_API.G_MISS_CHAR AND
1128           l_sic_code_type <> FND_API.G_MISS_CHAR)
1129       THEN
1130         fnd_message.set_name('AR', 'HZ_API_SIC_CODE_TYPE_REQUIRED');
1131         fnd_msg_pub.add;
1132         RAISE FND_API.G_EXC_ERROR;
1133       END IF;
1134 
1135       -- the sic_code_type ='OTHER' is allowed only when
1136       -- comming data source = G_MISS_CONTENT_SOURCE_TYPE
1137 
1138       IF l_sic_code_type = 'OTHER' AND
1139          l_data_source_type <> G_MISS_CONTENT_SOURCE_TYPE
1140       THEN
1141         fnd_message.set_name('AR', 'HZ_API_SIC_CODE_TYPE_OTHER');
1142         fnd_msg_pub.add;
1143         RAISE FND_API.G_EXC_ERROR;
1144       END IF;
1145 
1146       -- call hz_classification_v2pub.set_primary_code_assignment.
1147       -- if sic_code_type is not 'OTHER', then make the sic_code as the primary
1148       -- industrial class code for the party by calling
1149       -- hz_classification_v2pub.set_primary_code_assignment.
1150       -- if local_activity_code has a value, call
1151       -- hz_classification_v2pub.set_primary_code_assignment.
1152 
1153      IF l_sic_code=FND_API.G_MISS_CHAR
1154         AND l_sic_code_type=FND_API.G_MISS_CHAR
1155         AND p_old_organization_rec.sic_code_type IS NOT NULL
1156         AND p_old_organization_rec.sic_code_type<>FND_API.G_MISS_CHAR
1157      THEN
1158        l_sic_code_type := p_old_organization_rec.sic_code_type;
1159      END IF;
1160 
1161 
1162       IF --l_sic_code <> FND_API.G_MISS_CHAR AND ( bug 3876180 )
1163          l_sic_code_type <> FND_API.G_MISS_CHAR AND
1164          l_sic_code_type <> 'OTHER' AND
1165          (p_create_update_flag = 'C' OR
1166           (p_create_update_flag = 'U' AND
1167            NVL(p_organization_rec.sic_code, FND_API.G_MISS_CHAR) <>
1168                p_old_organization_rec.sic_code
1169            OR -- Bug 4043346
1170            NVL(p_organization_rec.sic_code_type, FND_API.G_MISS_CHAR) <>
1171                p_old_organization_rec.sic_code_type))
1172       THEN
1173          hz_classification_v2pub.set_primary_code_assignment(
1174           p_owner_table_name          => 'HZ_PARTIES',
1175           p_owner_table_id            => p_organization_rec.party_rec.party_id,
1176           p_class_category            => l_sic_code_type,
1177           p_class_code                => l_sic_code,
1178           p_content_source_type       => l_data_source_type,
1179           -- Bug 3856348
1180         --  p_created_by_module         => nvl(p_organization_rec.created_by_module,
1181           --                             p_old_organization_rec.created_by_module),
1182           --bug 4232060
1183           p_created_by_module         => l_created_by_module,
1184           x_code_assignment_id        => l_code_assignment_id,
1185           x_return_status             => x_return_status,
1186           x_msg_count                 => l_msg_count,
1187           x_msg_data                  => l_msg_data );
1188 
1189         IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1190           RAISE FND_API.G_EXC_ERROR;
1191         END IF;
1192       END IF;
1193 
1194       IF (p_create_update_flag = 'C' AND
1195           p_organization_rec.local_activity_code IS NOT NULL AND
1196           p_organization_rec.local_activity_code <> FND_API.G_MISS_CHAR) OR
1197          (p_create_update_flag = 'U'AND
1198           p_organization_rec.local_activity_code IS NOT NULL AND
1199           p_organization_rec.local_activity_code <> FND_API.G_MISS_CHAR AND
1200           p_organization_rec.local_activity_code <> p_old_organization_rec.local_activity_code)
1201       THEN
1202 
1203       -- Bug 3040565 : Modified the parameter p_class_category to set_primary_code_assignment to pass
1204       --                 actual local_activity_code_type.
1205         l_local_activity_code_type := nvl(p_organization_rec.local_activity_code_type, p_old_organization_rec.local_activity_code_type);
1206 
1207         if(l_local_activity_code_type = '4' OR l_local_activity_code_type = '5') then
1208                 l_local_activity_code_type := 'NACE';
1209         end if;
1210 
1211         hz_classification_v2pub.set_primary_code_assignment(
1212           p_owner_table_name          => 'HZ_PARTIES',
1213           p_owner_table_id            => p_organization_rec.party_rec.party_id,
1214 
1215 --          p_class_category            => 'NACE',
1216 
1217           p_class_category            => l_local_activity_code_type,
1218 
1219           p_class_code                => p_organization_rec.local_activity_code,
1220           p_content_source_type       => l_data_source_type,
1221           -- Bug 3856348
1222           --p_created_by_module         => nvl(p_organization_rec.created_by_module,
1223           --                           p_old_organization_rec.created_by_module),
1224           --bug 4232060
1225           p_created_by_module         => l_created_by_module,
1226           x_code_assignment_id        => l_code_assignment_id,
1227           x_return_status             => x_return_status,
1228           x_msg_count                 => l_msg_count,
1229           x_msg_data                  => l_msg_data );
1230 
1231         IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1232           RAISE FND_API.G_EXC_ERROR;
1233         END IF;
1234       END IF;
1235     END IF;
1236 
1237     -- Debug info.
1238     /*IF g_debug THEN
1239       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_process_classification (-)');
1240     END IF;
1241     */
1242     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
1243         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_process_classification (-)',
1244                                p_msg_level=>fnd_log.level_procedure);
1245     END IF;
1246 
1247   END do_process_classification;
1248 
1249   /**
1250    * PRIVATE PROCEDURE do_create_person_profile
1251    *
1252    * DESCRIPTION
1253    *     Creates person profile.
1254    *
1255    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
1256    *     hz_person_profiles_pkg.Insert_Row
1257    *
1258    * ARGUMENTS
1259    *     IN:
1260    *       p_party_id
1261    *     OUT:
1262    *       x_profile_id
1263    *     IN/ OUT:
1264    *       p_person_rec
1265    *
1266    * NOTES
1267    *
1268    * MODIFICATION HISTORY
1269    *
1270    *    06-MAY-2003    Sisir    o Bug 2970763: Modified for profile
1271    *                              versioning project;added version_number
1272    *                              as parameter.
1273    */
1274 
1275   PROCEDURE do_create_person_profile(
1276     p_person_rec                       IN     PERSON_REC_TYPE,
1277     p_party_id                         IN     NUMBER,
1278     x_profile_id                       OUT    NOCOPY NUMBER,
1279     p_version_number                   IN     NUMBER,
1280     x_rowid                            OUT    NOCOPY ROWID
1281   ) IS
1282 
1283     l_person_profile_id                NUMBER;
1284     l_rowid                            ROWID := NULL;
1285 
1286     l_debug_prefix                     VARCHAR2(30) := '';
1287 
1288   BEGIN
1289 
1290     -- Debug info.
1291     /*IF g_debug THEN
1292       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_create_person_profile (+)');
1293     END IF;
1294     */
1295     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
1296         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_create_person_profile (+)',
1297                                p_msg_level=>fnd_log.level_procedure);
1298     END IF;
1299 
1300     -- Debug info.
1301     /*IF g_debug THEN
1302       hz_utility_v2pub.debug (
1303         'hz_person_profiles_pkg.Insert_Row (+)', l_debug_prefix);
1304     END IF;
1305     */
1306 
1307     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
1308         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'hz_person_profiles_pkg.Insert_Row (+)',
1309                                p_msg_level=>fnd_log.level_procedure);
1310     END IF;
1311 
1312     -- call table-handler.
1313     HZ_person_profiles_pkg.Insert_Row (
1314       x_rowid                                 => l_rowid,
1315       x_person_profile_id                     => l_person_profile_id,
1316       x_party_id                              => p_party_id,
1317       x_person_name                           => do_create_person_name(p_person_rec),
1318       x_attribute_category                    => p_person_rec.attribute_category,
1319       x_attribute1                            => p_person_rec.attribute1,
1320       x_attribute2                            => p_person_rec.attribute2,
1321       x_attribute3                            => p_person_rec.attribute3,
1322       x_attribute4                            => p_person_rec.attribute4,
1323       x_attribute5                            => p_person_rec.attribute5,
1324       x_attribute6                            => p_person_rec.attribute6,
1325       x_attribute7                            => p_person_rec.attribute7,
1326       x_attribute8                            => p_person_rec.attribute8,
1327       x_attribute9                            => p_person_rec.attribute9,
1328       x_attribute10                           => p_person_rec.attribute10,
1329       x_attribute11                           => p_person_rec.attribute11,
1330       x_attribute12                           => p_person_rec.attribute12,
1331       x_attribute13                           => p_person_rec.attribute13,
1332       x_attribute14                           => p_person_rec.attribute14,
1333       x_attribute15                           => p_person_rec.attribute15,
1334       x_attribute16                           => p_person_rec.attribute16,
1335       x_attribute17                           => p_person_rec.attribute17,
1336       x_attribute18                           => p_person_rec.attribute18,
1337       x_attribute19                           => p_person_rec.attribute19,
1338       x_attribute20                           => p_person_rec.attribute20,
1339       x_internal_flag                         => p_person_rec.internal_flag,
1340       x_person_pre_name_adjunct               => p_person_rec.person_pre_name_adjunct,
1341       x_person_first_name                     => p_person_rec.person_first_name,
1342       x_person_middle_name                    => p_person_rec.person_middle_name,
1343       x_person_last_name                      => p_person_rec.person_last_name,
1344       x_person_name_suffix                    => p_person_rec.person_name_suffix,
1345       x_person_title                          => p_person_rec.person_title,
1346       x_person_academic_title                 => p_person_rec.person_academic_title,
1347       x_person_previous_last_name             => p_person_rec.person_previous_last_name,
1348       x_person_initials                       => p_person_rec.person_initials,
1349       x_known_as                              => p_person_rec.known_as,
1350       x_person_name_phonetic                  => p_person_rec.person_name_phonetic,
1351       x_person_first_name_phonetic            => p_person_rec.person_first_name_phonetic,
1352       x_person_last_name_phonetic             => p_person_rec.person_last_name_phonetic,
1353       x_tax_reference                         => p_person_rec.tax_reference,
1354       x_jgzz_fiscal_code                      => p_person_rec.jgzz_fiscal_code,
1355       x_person_iden_type                      => p_person_rec.person_iden_type,
1356       x_person_identifier                     => p_person_rec.person_identifier,
1357       x_date_of_birth                         => p_person_rec.date_of_birth,
1358       x_place_of_birth                        => p_person_rec.place_of_birth,
1359       x_date_of_death                         => p_person_rec.date_of_death,
1360       x_deceased_flag                         => p_person_rec.deceased_flag,
1361       x_gender                                => p_person_rec.gender,
1362       x_declared_ethnicity                    => p_person_rec.declared_ethnicity,
1363       x_marital_status                        => p_person_rec.marital_status,
1364       x_marital_status_eff_date               => p_person_rec.marital_status_effective_date,
1365       x_personal_income                       => p_person_rec.personal_income,
1366       x_head_of_household_flag                => p_person_rec.head_of_household_flag,
1367       x_household_income                      => p_person_rec.household_income,
1368       x_household_size                        => p_person_rec.household_size,
1369       x_rent_own_ind                          => p_person_rec.rent_own_ind,
1370       x_last_known_gps                        => p_person_rec.last_known_gps,
1371       x_effective_start_date                  => trunc(hz_utility_pub.creation_date),
1372       x_effective_end_date                    => null,
1373       x_content_source_type                   => p_person_rec.content_source_type,
1374       x_known_as2                             => p_person_rec.known_as2,
1375       x_known_as3                             => p_person_rec.known_as3,
1376       x_known_as4                             => p_person_rec.known_as4,
1377       x_known_as5                             => p_person_rec.known_as5,
1378       x_middle_name_phonetic                  => p_person_rec.middle_name_phonetic,
1379       x_object_version_number                 => 1,
1380       x_created_by_module                     => p_person_rec.created_by_module,
1381       x_application_id                        => p_person_rec.application_id,
1382       x_actual_content_source                 => p_person_rec.actual_content_source,
1383       x_version_number                        => p_version_number
1384     );
1385 
1386     x_profile_id := l_person_profile_id;
1387     x_rowid := l_rowid;
1388 
1389     -- Debug info.
1390     /*IF g_debug THEN
1391       hz_utility_v2pub.debug (
1392         'hz_person_profiles_pkg.Insert_Row (-) ' ||
1393         'x_profile_id = ' || x_profile_id, l_debug_prefix);
1394     END IF;
1395     */
1396 
1397     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
1398         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'hz_person_profiles_pkg.Insert_Row (-) '||'x_profile_id = ' || x_profile_id,
1399                                p_msg_level=>fnd_log.level_procedure);
1400     END IF;
1401 
1402     -- Debug info.
1403     /*IF g_debug THEN
1404       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_create_person_profile (-)');
1405     END IF;*/
1406 
1407     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
1408         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_create_person_profile (-)',
1409                                p_msg_level=>fnd_log.level_procedure);
1410     END IF;
1411 
1412   END do_create_person_profile;
1413 
1414   /**
1415    * PRIVATE PROCEDURE do_update_person_profile
1416    *
1417    * DESCRIPTION
1418    *     Updates person profile.
1419    *
1420    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
1421    *     hz_person_profiles_pkg.Update_Row
1422    *
1423    * ARGUMENTS
1424    *     IN:
1425    *       p_data_source_type
1426    *     OUT:
1427    *       x_profile_id
1428    *     IN/ OUT:
1429    *       p_person_rec
1430    *       p_old_person_rec
1431    *
1432    * NOTES
1433    *
1434    * MODIFICATION HISTORY
1435    *
1436    */
1437 
1438   PROCEDURE do_update_person_profile(
1439     p_person_rec                       IN     PERSON_REC_TYPE,
1440     p_old_person_rec                   IN     PERSON_REC_TYPE,
1441     p_data_source_type                 IN     VARCHAR2,
1442     x_profile_id                       OUT    NOCOPY NUMBER
1443   ) IS
1444 
1445     l_rowid                            ROWID := NULL;
1446     l_person_profile_id                NUMBER;
1447     l_effective_start_date             DATE;
1448     l_object_version_number            NUMBER;
1449     l_person_name                      HZ_PERSON_PROFILES.PERSON_NAME%TYPE;
1450     l_person_rec                       PERSON_REC_TYPE;
1451     l_version_number                   NUMBER;
1452 
1453     CURSOR c_person IS
1454       SELECT person_profile_id, rowid,object_version_number,
1455              version_number, effective_start_date
1456       FROM hz_person_profiles
1457       WHERE party_id = p_person_rec.party_rec.party_id
1458       AND actual_content_source = p_data_source_type
1459       AND effective_end_date is null
1460       FOR UPDATE NOWAIT;
1461 
1462     l_debug_prefix                     VARCHAR2(30) := '';
1463     l_create_update_flag               VARCHAR2(1);
1464     l_return_status                    VARCHAR2(1);
1465 
1466   BEGIN
1467 
1468     -- Debug info.
1469     /*IF g_debug THEN
1470       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_update_person_profile (+)');
1471     END IF;
1472     */
1473 
1474     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
1475         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_update_person_profile (+)',
1476                                p_msg_level=>fnd_log.level_procedure);
1477     END IF;
1478 
1479     OPEN c_person;
1480     FETCH c_person INTO
1481       l_person_profile_id, l_rowid,l_object_version_number,
1482       l_version_number, l_effective_start_date;
1483 
1484     IF c_person%NOTFOUND THEN
1485       fnd_message.set_name('AR', 'HZ_NO_PROFILE_PRESENT');
1486       fnd_message.set_token('PARTY_ID', TO_CHAR(p_person_rec.party_rec.party_id));
1487       fnd_message.set_token('CONTENT_SOURCE_TYPE', p_data_source_type);
1488       fnd_msg_pub.add;
1489       RAISE fnd_api.g_exc_error;
1490     END IF;
1491     CLOSE c_person;
1492 
1493 
1494     IF fnd_profile.value ('HZ_PROFILE_VERSION') = 'NEW_VERSION' THEN
1495         -- Always End date the existing profile and create a new profile
1496         l_create_update_flag := 'C';
1497 
1498     ELSIF fnd_profile.value ('HZ_PROFILE_VERSION') = 'NO_VERSION' THEN
1499         -- Always update the existing profile
1500         l_create_update_flag := 'U';
1501 
1502     ELSE
1503         IF TRUNC (l_effective_start_date) < TRUNC (SYSDATE) THEN
1504         -- End date the existing profile and create a new profile
1505                 l_create_update_flag := 'C';
1506         ELSE
1507         -- Same day,so update the existing profile
1508                 l_create_update_flag := 'U';
1509         END IF;
1510     END IF;
1511 
1512     IF l_create_update_flag = 'C' THEN
1513         -- Always End date the existing profile and create a new profile
1514        l_version_number :=  nvl(l_version_number,1)+1;
1515 
1516         UPDATE hz_person_profiles
1517         SET    effective_end_date = decode(trunc(effective_start_date),trunc(sysdate),trunc(sysdate),TRUNC (SYSDATE-1)),
1518                object_version_number = NVL(l_object_version_number, 1) + 1
1519                --,version_number = NVL(version_number,1)+1
1520         WHERE rowid = l_rowid;
1521 
1522       -- create a new record with same data as current profile
1523       do_create_person_profile(
1524         p_person_rec            => p_old_person_rec,
1525         p_party_id              => p_person_rec.party_rec.party_id,
1526         x_profile_id            => x_profile_id,
1527         p_version_number        => l_version_number,
1528         x_rowid                 => l_rowid );
1529       l_object_version_number := 2;
1530 
1531       --
1532       -- copy extent data for extensibility project.
1533       --
1534       IF p_data_source_type = G_SST_SOURCE_TYPE THEN
1535         HZ_EXTENSIBILITY_PVT.copy_person_extent_data (
1536           p_old_profile_id          => l_person_profile_id,
1537           p_new_profile_id          => x_profile_id,
1538           x_return_status           => l_return_status
1539         );
1540 
1541         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1542           RAISE FND_API.G_EXC_ERROR;
1543         END IF;
1544       END IF;
1545 
1546     ELSE
1547       x_profile_id := l_person_profile_id;
1548       l_object_version_number := NVL(l_object_version_number, 1) + 1;
1549       l_version_number  :=  nvl(l_version_number,1)+1;
1550     END IF;
1551 /*
1552     IF TRUNC(l_effective_start_date) < TRUNC(SYSDATE) THEN
1553       UPDATE hz_person_profiles
1554       SET effective_end_date = TRUNC(SYSDATE-1),
1555           object_version_number = NVL(object_version_number, 1) + 1
1556       WHERE rowid = l_rowid;
1557 
1558       -- create a new record with same data as current profile
1559       do_create_person_profile(
1560         p_person_rec            => p_old_person_rec,
1561         p_party_id              => p_person_rec.party_rec.party_id,
1562         x_profile_id            => x_profile_id,
1563         x_rowid                 => l_rowid );
1564 
1565       l_object_version_number := 2;
1566     ELSE
1567       x_profile_id := l_person_profile_id;
1568       l_object_version_number := NVL(l_object_version_number, 1) + 1;
1569     END IF;
1570 */
1571     IF p_person_rec.person_title IS NULL AND
1572        p_person_rec.person_first_name IS NULL AND
1573        p_person_rec.person_middle_name IS NULL AND
1574        p_person_rec.person_last_name IS NULL AND
1575        p_person_rec.person_name_suffix IS NULL AND
1576        p_person_rec.known_as IS NULL AND
1577        p_person_rec.person_first_name_phonetic IS NULL AND
1578        p_person_rec.middle_name_phonetic IS NULL AND
1579        p_person_rec.person_last_name_phonetic IS NULL
1580 
1581     THEN
1582       l_person_name := NULL;
1583     ELSE
1584       l_person_rec.person_title :=
1585         NVL(p_person_rec.person_title, p_old_person_rec.person_title);
1586       l_person_rec.person_first_name :=
1587         NVL(p_person_rec.person_first_name, p_old_person_rec.person_first_name);
1588       l_person_rec.person_middle_name :=
1589         NVL(p_person_rec.person_middle_name, p_old_person_rec.person_middle_name);
1590       l_person_rec.person_last_name :=
1591         NVL(p_person_rec.person_last_name, p_old_person_rec.person_last_name);
1592       l_person_rec.person_name_suffix :=
1593         NVL(p_person_rec.person_name_suffix, p_old_person_rec.person_name_suffix);
1594       -- Bug 3999044
1595       l_person_rec.known_as :=
1596         NVL(p_person_rec.known_as,p_old_person_rec.known_as);
1597       l_person_rec.person_first_name_phonetic:=
1598         NVL(p_person_rec.person_first_name_phonetic,p_old_person_rec.person_first_name_phonetic);
1599       l_person_rec.middle_name_phonetic:=
1600         NVL(p_person_rec.middle_name_phonetic,p_old_person_rec.middle_name_phonetic);
1601       l_person_rec.person_last_name_phonetic :=
1602         NVL(p_person_rec.person_last_name_phonetic,p_old_person_rec.person_last_name_phonetic);
1603 
1604 
1605       l_person_name := do_create_person_name(l_person_rec);
1606     END IF;
1607 
1608     -- Debug info.
1609     /*IF g_debug THEN
1610       hz_utility_v2pub.debug ('profile_id = '||x_profile_id, l_debug_prefix);
1611       hz_utility_v2pub.debug (
1612         'hz_person_profiles_pkg.Update_Row (+) ',l_debug_prefix);
1613     END IF;
1614     */
1615     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
1616         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'hz_person_profiles_pkg.Update_Row (+)',
1617                                p_msg_level=>fnd_log.level_procedure);
1618     END IF;
1619     IF fnd_log.level_statement>=fnd_log.g_current_runtime_level THEN
1620            hz_utility_v2pub.debug(p_message=>'profile_id = '||x_profile_id,
1621                                   p_prefix =>l_debug_prefix,
1622                                   p_msg_level=>fnd_log.level_statement);
1623     END IF;
1624 
1625     -- call table-handler.
1626     HZ_person_profiles_pkg.Update_Row (
1627       x_rowid                                 => l_rowid,
1628       x_person_profile_id                     => x_profile_id,
1629       x_party_id                              => null,
1630       x_person_name                           => l_person_name,
1631       x_attribute_category                    => p_person_rec.attribute_category,
1632       x_attribute1                            => p_person_rec.attribute1,
1633       x_attribute2                            => p_person_rec.attribute2,
1634       x_attribute3                            => p_person_rec.attribute3,
1635       x_attribute4                            => p_person_rec.attribute4,
1636       x_attribute5                            => p_person_rec.attribute5,
1637       x_attribute6                            => p_person_rec.attribute6,
1638       x_attribute7                            => p_person_rec.attribute7,
1639       x_attribute8                            => p_person_rec.attribute8,
1640       x_attribute9                            => p_person_rec.attribute9,
1641       x_attribute10                           => p_person_rec.attribute10,
1642       x_attribute11                           => p_person_rec.attribute11,
1643       x_attribute12                           => p_person_rec.attribute12,
1644       x_attribute13                           => p_person_rec.attribute13,
1645       x_attribute14                           => p_person_rec.attribute14,
1646       x_attribute15                           => p_person_rec.attribute15,
1647       x_attribute16                           => p_person_rec.attribute16,
1648       x_attribute17                           => p_person_rec.attribute17,
1649       x_attribute18                           => p_person_rec.attribute18,
1650       x_attribute19                           => p_person_rec.attribute19,
1651       x_attribute20                           => p_person_rec.attribute20,
1652       x_internal_flag                         => p_person_rec.internal_flag,
1653       x_person_pre_name_adjunct               => p_person_rec.person_pre_name_adjunct,
1654       x_person_first_name                     => p_person_rec.person_first_name,
1655       x_person_middle_name                    => p_person_rec.person_middle_name,
1656       x_person_last_name                      => p_person_rec.person_last_name,
1657       x_person_name_suffix                    => p_person_rec.person_name_suffix,
1658       x_person_title                          => p_person_rec.person_title,
1659       x_person_academic_title                 => p_person_rec.person_academic_title,
1660       x_person_previous_last_name             => p_person_rec.person_previous_last_name,
1661       x_person_initials                       => p_person_rec.person_initials,
1662       x_known_as                              => p_person_rec.known_as,
1663       x_person_name_phonetic                  => p_person_rec.person_name_phonetic,
1664       x_person_first_name_phonetic            => p_person_rec.person_first_name_phonetic,
1665       x_person_last_name_phonetic             => p_person_rec.person_last_name_phonetic,
1666       x_tax_reference                         => p_person_rec.tax_reference,
1667       x_jgzz_fiscal_code                      => p_person_rec.jgzz_fiscal_code,
1668       x_person_iden_type                      => p_person_rec.person_iden_type,
1669       x_person_identifier                     => p_person_rec.person_identifier,
1670       x_date_of_birth                         => p_person_rec.date_of_birth,
1671       x_place_of_birth                        => p_person_rec.place_of_birth,
1672       x_date_of_death                         => p_person_rec.date_of_death,
1673       x_deceased_flag                         => p_person_rec.deceased_flag,
1674       x_gender                                => p_person_rec.gender,
1675       x_declared_ethnicity                    => p_person_rec.declared_ethnicity,
1676       x_marital_status                        => p_person_rec.marital_status,
1677       x_marital_status_eff_date               => p_person_rec.marital_status_effective_date,
1678       x_personal_income                       => p_person_rec.personal_income,
1679       x_head_of_household_flag                => p_person_rec.head_of_household_flag,
1680       x_household_income                      => p_person_rec.household_income,
1681       x_household_size                        => p_person_rec.household_size,
1682       x_rent_own_ind                          => p_person_rec.rent_own_ind,
1683       x_last_known_gps                        => p_person_rec.last_known_gps,
1684       x_effective_start_date                  => null,
1685       x_effective_end_date                    => null,
1686       x_content_source_type                   => null, -- the column is non-updateable
1687       x_known_as2                             => p_person_rec.known_as2,
1688       x_known_as3                             => p_person_rec.known_as3,
1689       x_known_as4                             => p_person_rec.known_as4,
1690       x_known_as5                             => p_person_rec.known_as5,
1691       x_middle_name_phonetic                  => p_person_rec.middle_name_phonetic,
1692       x_object_version_number                 => l_object_version_number,
1693       x_created_by_module                     => p_person_rec.created_by_module,
1694       x_application_id                        => p_person_rec.application_id,
1695       x_actual_content_source                 => null,  -- the column is non-updateable
1696       x_version_number                        => l_version_number
1697     );
1698 
1699     -- Debug info.
1700     /*IF g_debug THEN
1701         hz_utility_v2pub.debug (
1702             'hz_person_profiles_pkg.Update_Row (-) ',
1703             l_debug_prefix);
1704     END IF;
1705     */
1706     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
1707         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'hz_person_profiles_pkg.Update_Row (-)',
1708                                p_msg_level=>fnd_log.level_procedure);
1709 
1710     END IF;
1711 
1712     -- Debug info.
1713     /*IF g_debug THEN
1714         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_update_person_profile (-)');
1715     END IF;
1716     */
1717     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
1718         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_update_person_profile (-)',
1719                                p_msg_level=>fnd_log.level_procedure);
1720     END IF;
1721 
1722   EXCEPTION
1723     WHEN g_resource_busy THEN
1724       fnd_message.set_name('AR', 'HZ_API_RECORD_CHANGED');
1725       fnd_message.set_token('TABLE', 'HZ_PERSON_PROFILES');
1726       fnd_msg_pub.add;
1727       RAISE fnd_api.g_exc_error;
1728 
1729   END do_update_person_profile;
1730 
1731   /**
1732    * PRIVATE PROCEDURE do_create_org_profile
1733    *
1734    * DESCRIPTION
1735    *     Creates organization profile.
1736    *
1737    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
1738    *     hz_organization_profiles_pkg.Insert_Row
1739    *
1740    * ARGUMENTS
1741    *     IN:
1742    *       p_party_id
1743    *     OUT:
1744    *       x_profile_id
1745    *     IN/ OUT:
1746    *       p_organization_rec
1747    *
1748    * NOTES
1749    *
1750    * MODIFICATION HISTORY
1751    *   26-NOV-2001        Joe del Callar        Bug 2116225: added support
1752    *                                            for banks.
1753    *                                            Bug 2117973: modified to
1754    *                                            conform to PL/SQL coding stds
1755    */
1756 
1757   PROCEDURE do_create_org_profile(
1758     p_organization_rec                 IN     ORGANIZATION_REC_TYPE,
1759     p_party_id                         IN     NUMBER,
1760     x_profile_id                       OUT    NOCOPY NUMBER,
1761     p_version_number                   IN     NUMBER,
1762     x_rowid                            OUT    NOCOPY ROWID
1763   ) IS
1764 
1765     l_organization_profile_id          NUMBER;
1766     l_rowid                            ROWID := NULL;
1767 
1768     l_debug_prefix                     VARCHAR2(30) := '';
1769 
1770   BEGIN
1771 
1772     -- Debug info.
1773     /*IF g_debug THEN
1774       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_create_org_profile (+)');
1775     END IF;
1776     */
1777     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
1778         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_create_org_profile (+)',
1779                                p_msg_level=>fnd_log.level_procedure);
1780     END IF;
1781 
1782     -- Debug info.
1783     /*IF g_debug THEN
1784       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'hz_organization_profiles_pkg.Insert_Row (+)',
1785                              l_debug_prefix);
1786     END IF;
1787     */
1788     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
1789         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'hz_organization_profiles_pkg.Insert_Row (+)',
1790                                p_msg_level=>fnd_log.level_procedure);
1791     END IF;
1792 
1793     -- call table-handler.
1794     HZ_organization_profiles_pkg.insert_row(
1795       x_rowid                             => l_rowid,
1796       x_organization_profile_id           => l_organization_profile_id,
1797       x_party_id                          => p_party_id,
1798       x_organization_name                 => p_organization_rec.organization_name,
1799       x_attribute_category                => p_organization_rec.attribute_category,
1800       x_attribute1                        => p_organization_rec.attribute1,
1801       x_attribute2                        => p_organization_rec.attribute2,
1802       x_attribute3                        => p_organization_rec.attribute3,
1803       x_attribute4                        => p_organization_rec.attribute4,
1804       x_attribute5                        => p_organization_rec.attribute5,
1805       x_attribute6                        => p_organization_rec.attribute6,
1806       x_attribute7                        => p_organization_rec.attribute7,
1807       x_attribute8                        => p_organization_rec.attribute8,
1808       x_attribute9                        => p_organization_rec.attribute9,
1809       x_attribute10                       => p_organization_rec.attribute10,
1810       x_attribute11                       => p_organization_rec.attribute11,
1811       x_attribute12                       => p_organization_rec.attribute12,
1812       x_attribute13                       => p_organization_rec.attribute13,
1813       x_attribute14                       => p_organization_rec.attribute14,
1814       x_attribute15                       => p_organization_rec.attribute15,
1815       x_attribute16                       => p_organization_rec.attribute16,
1816       x_attribute17                       => p_organization_rec.attribute17,
1817       x_attribute18                       => p_organization_rec.attribute18,
1818       x_attribute19                       => p_organization_rec.attribute19,
1819       x_attribute20                       => p_organization_rec.attribute20,
1820       x_enquiry_duns                      => p_organization_rec.enquiry_duns,
1821       x_ceo_name                          => p_organization_rec.ceo_name,
1822       x_ceo_title                         => p_organization_rec.ceo_title,
1823       x_principal_name                    => p_organization_rec.principal_name,
1824       x_principal_title                   => p_organization_rec.principal_title,
1825       x_legal_status                      => p_organization_rec.legal_status,
1826       x_control_yr                        => p_organization_rec.control_yr,
1827       x_employees_total                   => p_organization_rec.employees_total,
1828       x_hq_branch_ind                     => p_organization_rec.hq_branch_ind,
1829       x_branch_flag                       => p_organization_rec.branch_flag,
1830       x_oob_ind                           => p_organization_rec.oob_ind,
1831       x_line_of_business                  => p_organization_rec.line_of_business,
1832       x_cong_dist_code                    => p_organization_rec.cong_dist_code,
1833       x_sic_code                          => p_organization_rec.sic_code,
1834       x_import_ind                        => p_organization_rec.import_ind,
1835       x_export_ind                        => p_organization_rec.export_ind,
1836       x_labor_surplus_ind                 => p_organization_rec.labor_surplus_ind,
1837       x_debarment_ind                     => p_organization_rec.debarment_ind,
1838       x_minority_owned_ind                => p_organization_rec.minority_owned_ind,
1839       x_minority_owned_type               => p_organization_rec.minority_owned_type,
1840       x_woman_owned_ind                   => p_organization_rec.woman_owned_ind,
1841       x_disadv_8a_ind                     => p_organization_rec.disadv_8a_ind,
1842       x_small_bus_ind                     => p_organization_rec.small_bus_ind,
1843       x_rent_own_ind                      => p_organization_rec.rent_own_ind,
1844       x_debarments_count                  => p_organization_rec.debarments_count,
1845       x_debarments_date                   => p_organization_rec.debarments_date,
1846       x_failure_score                     => p_organization_rec.failure_score,
1847       x_failure_score_override_code       => p_organization_rec.failure_score_override_code,
1848       x_failure_score_commentary          => p_organization_rec.failure_score_commentary,
1849       x_global_failure_score              => p_organization_rec.global_failure_score,
1850       x_db_rating                         => p_organization_rec.db_rating,
1851       x_credit_score                      => p_organization_rec.credit_score,
1852       x_credit_score_commentary           => p_organization_rec.credit_score_commentary,
1853       x_paydex_score                      => p_organization_rec.paydex_score,
1854       x_paydex_three_months_ago           => p_organization_rec.paydex_three_months_ago,
1855       x_paydex_norm                       => p_organization_rec.paydex_norm,
1856       x_best_time_contact_begin           => p_organization_rec.best_time_contact_begin,
1857       x_best_time_contact_end             => p_organization_rec.best_time_contact_end,
1858       x_organization_name_phonetic        => p_organization_rec.organization_name_phonetic,
1859       x_tax_reference                     => p_organization_rec.tax_reference,
1860       x_gsa_indicator_flag                => p_organization_rec.gsa_indicator_flag,
1861       x_jgzz_fiscal_code                  => p_organization_rec.jgzz_fiscal_code,
1862       x_analysis_fy                       => p_organization_rec.analysis_fy,
1863       x_fiscal_yearend_month              => p_organization_rec.fiscal_yearend_month,
1864       x_curr_fy_potential_revenue         => p_organization_rec.curr_fy_potential_revenue,
1865       x_next_fy_potential_revenue         => p_organization_rec.next_fy_potential_revenue,
1866       x_year_established                  => p_organization_rec.year_established,
1867       x_mission_statement                 => p_organization_rec.mission_statement,
1868       x_organization_type                 => p_organization_rec.organization_type,
1869       x_business_scope                    => p_organization_rec.business_scope,
1870       x_corporation_class                 => p_organization_rec.corporation_class,
1871       x_known_as                          => p_organization_rec.known_as,
1872       x_local_bus_iden_type               => p_organization_rec.local_bus_iden_type,
1873       x_local_bus_identifier              => p_organization_rec.local_bus_identifier,
1874       x_pref_functional_currency          => p_organization_rec.pref_functional_currency,
1875       x_registration_type                 => p_organization_rec.registration_type,
1876       x_total_employees_text              => p_organization_rec.total_employees_text,
1877       x_total_employees_ind               => p_organization_rec.total_employees_ind,
1878       x_total_emp_est_ind                 => p_organization_rec.total_emp_est_ind,
1879       x_total_emp_min_ind                 => p_organization_rec.total_emp_min_ind,
1880       x_parent_sub_ind                    => p_organization_rec.parent_sub_ind,
1881       x_incorp_year                       => p_organization_rec.incorp_year,
1882       x_content_source_type               => p_organization_rec.content_source_type,
1883       x_content_source_number             => p_organization_rec.content_source_number,
1884       x_effective_start_date              => TRUNC(hz_utility_pub.creation_date),
1885       x_effective_end_date                => NULL,
1886       x_sic_code_type                     => p_organization_rec.sic_code_type,
1887       x_public_private_ownership          => p_organization_rec.public_private_ownership_flag,
1888       x_local_activity_code_type          => p_organization_rec.local_activity_code_type,
1889       x_local_activity_code               => p_organization_rec.local_activity_code,
1890       x_emp_at_primary_adr                => p_organization_rec.emp_at_primary_adr,
1891       x_emp_at_primary_adr_text           => p_organization_rec.emp_at_primary_adr_text,
1892       x_emp_at_primary_adr_est_ind        => p_organization_rec.emp_at_primary_adr_est_ind,
1893       x_emp_at_primary_adr_min_ind        => p_organization_rec.emp_at_primary_adr_min_ind,
1894       x_internal_flag                     => p_organization_rec.internal_flag,
1895       x_high_credit                       => p_organization_rec.high_credit,
1896       x_avg_high_credit                   => p_organization_rec.avg_high_credit,
1897       x_total_payments                    => p_organization_rec.total_payments,
1898       x_known_as2                         => p_organization_rec.known_as2,
1899       x_known_as3                         => p_organization_rec.known_as3,
1900       x_known_as4                         => p_organization_rec.known_as4,
1901       x_known_as5                         => p_organization_rec.known_as5,
1902       x_credit_score_class                => p_organization_rec.credit_score_class,
1903       x_credit_score_natl_percentile      => p_organization_rec.credit_score_natl_percentile,
1904       x_credit_score_incd_default         => p_organization_rec.credit_score_incd_default,
1905       x_credit_score_age                  => p_organization_rec.credit_score_age,
1906       x_credit_score_date                 => p_organization_rec.credit_score_date,
1907       x_failure_score_class               => p_organization_rec.failure_score_class,
1908       x_failure_score_incd_default        => p_organization_rec.failure_score_incd_default,
1909       x_failure_score_age                 => p_organization_rec.failure_score_age,
1910       x_failure_score_date                => p_organization_rec.failure_score_date,
1911       x_failure_score_commentary2         => p_organization_rec.failure_score_commentary2,
1912       x_failure_score_commentary3         => p_organization_rec.failure_score_commentary3,
1913       x_failure_score_commentary4         => p_organization_rec.failure_score_commentary4,
1914       x_failure_score_commentary5         => p_organization_rec.failure_score_commentary5,
1915       x_failure_score_commentary6         => p_organization_rec.failure_score_commentary6,
1916       x_failure_score_commentary7         => p_organization_rec.failure_score_commentary7,
1917       x_failure_score_commentary8         => p_organization_rec.failure_score_commentary8,
1918       x_failure_score_commentary9         => p_organization_rec.failure_score_commentary9,
1919       x_failure_score_commentary10        => p_organization_rec.failure_score_commentary10,
1920       x_credit_score_commentary2          => p_organization_rec.credit_score_commentary2,
1921       x_credit_score_commentary3          => p_organization_rec.credit_score_commentary3,
1922       x_credit_score_commentary4          => p_organization_rec.credit_score_commentary4,
1923       x_credit_score_commentary5          => p_organization_rec.credit_score_commentary5,
1924       x_credit_score_commentary6          => p_organization_rec.credit_score_commentary6,
1925       x_credit_score_commentary7          => p_organization_rec.credit_score_commentary7,
1926       x_credit_score_commentary8          => p_organization_rec.credit_score_commentary8,
1927       x_credit_score_commentary9          => p_organization_rec.credit_score_commentary9,
1928       x_credit_score_commentary10         => p_organization_rec.credit_score_commentary10,
1929       x_maximum_credit_recomm             => p_organization_rec.maximum_credit_recommendation,
1930       x_maximum_credit_currency_code      => p_organization_rec.maximum_credit_currency_code,
1931       x_displayed_duns_party_id           => p_organization_rec.displayed_duns_party_id,
1932       x_failure_score_natnl_perc          => p_organization_rec.failure_score_natnl_percentile,
1933       x_duns_number_c                     => p_organization_rec.duns_number_c,
1934       x_bank_or_branch_number             => NULL,
1935       x_bank_code                         => NULL,
1936       x_branch_code                       => NULL,
1937       x_object_version_number             => 1,
1938       x_created_by_module                 => p_organization_rec.created_by_module,
1939       x_application_id                    => p_organization_rec.application_id,
1940       x_do_not_confuse_with               => p_organization_rec.do_not_confuse_with,
1941       x_actual_content_source             => p_organization_rec.actual_content_source,
1942       x_version_number                    => p_version_number,
1943       x_home_country                      => p_organization_rec.home_country
1944     );
1945 
1946     x_profile_id := l_organization_profile_id;
1947     x_rowid := l_rowid;
1948 
1949 
1950     -- Debug info.
1951     /*IF g_debug THEN
1952       hz_utility_v2pub.debug ('hz_organization_profiles_pkg.Insert_Row (-) ',
1953                               l_debug_prefix);
1954     END IF;
1955     */
1956     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
1957         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'hz_organization_profiles_pkg.Insert_Row (-) ',
1958                                p_msg_level=>fnd_log.level_procedure);
1959     END IF;
1960 
1961     -- Debug info.
1962     /*IF g_debug THEN
1963       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_create_org_profile (-)');
1964     END IF;
1965     */
1966     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
1967         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_create_org_profile (-)',
1968                                p_msg_level=>fnd_log.level_procedure);
1969     END IF;
1970 
1971   END do_create_org_profile;
1972 
1973   /**
1974    * PRIVATE PROCEDURE do_update_org_profile
1975    *
1976    * DESCRIPTION
1977    *     Updates organization profile.
1978    *
1979    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
1980    *     hz_organization_profiles_pkg.Update_Row
1981    *
1982    * ARGUMENTS
1983    *     IN:
1984    *       p_party_id
1985    *       p_data_source_type
1986    *     OUT:
1987    *       x_profile_id
1988    *     IN/ OUT:
1989    *       p_organization_rec
1990    *       p_old_organization_rec
1991    *
1992    * NOTES
1993    *
1994    * MODIFICATION HISTORY
1995    *   26-NOV-2001        Joe del Callar       Bug 2116225: modified for
1996    *                                           consolidated bank support.
1997    *                                           Bug 2117973: modified to conform
1998    *                                           to PL/SQL coding standards.
1999    *                                           Changed selects into cursors.
2000    */
2001 
2002   PROCEDURE do_update_org_profile(
2003     p_organization_rec                 IN     ORGANIZATION_REC_TYPE,
2004     p_old_organization_rec             IN     ORGANIZATION_REC_TYPE,
2005     p_data_source_type                 IN     VARCHAR2,
2006     x_profile_id                       OUT    NOCOPY NUMBER
2007   ) IS
2008 
2009     l_rowid                            ROWID := NULL;
2010     l_object_version_number            NUMBER;
2011     l_version_number                   NUMBER;
2012     l_organization_profile_id          NUMBER;
2013     l_effective_start_date             DATE;
2014 
2015     CURSOR c_org IS
2016       SELECT rowid, organization_profile_id,object_version_number,
2017              version_number,effective_start_date
2018       FROM hz_organization_profiles
2019       WHERE party_id = p_organization_rec.party_rec.party_id
2020       AND actual_content_source = p_data_source_type
2021       AND effective_end_date is null
2022       FOR UPDATE NOWAIT;
2023 
2024     l_debug_prefix                     VARCHAR2(30);
2025     l_create_update_flag               VARCHAR2(1);
2026     l_return_status                    VARCHAR2(1);
2027 -- Bug 3560323 : Added local variable for business report
2028     l_business_report   CLOB;
2029   BEGIN
2030 
2031     -- Debug info.
2032     /*IF g_debug THEN
2033       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_update_org_profile (+)');
2034     END IF;
2035     */
2036     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
2037         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_update_org_profile (+)',
2038                                p_msg_level=>fnd_log.level_procedure);
2039     END IF;
2040 
2041     OPEN c_org;
2042     FETCH c_org INTO
2043       l_rowid, l_organization_profile_id,l_object_version_number,
2044       l_version_number,l_effective_start_date;
2045 
2046     IF c_org%NOTFOUND THEN
2047       fnd_message.set_name('AR', 'HZ_NO_PROFILE_PRESENT');
2048       fnd_message.set_token('PARTY_ID', TO_CHAR(p_organization_rec.party_rec.party_id));
2049       fnd_message.set_token('CONTENT_SOURCE_TYPE', p_data_source_type);
2050       fnd_msg_pub.add;
2051       RAISE fnd_api.g_exc_error;
2052     END IF;
2053     CLOSE c_org;
2054 
2055     IF fnd_profile.value ('HZ_PROFILE_VERSION') = 'NEW_VERSION' THEN
2056         -- Always End date the existing profile and create a new profile
2057         l_create_update_flag := 'C';
2058 
2059     ELSIF fnd_profile.value ('HZ_PROFILE_VERSION') = 'NO_VERSION' THEN
2060         -- Always update the existing profile
2061         l_create_update_flag := 'U';
2062 
2063     ELSE
2064         IF TRUNC (l_effective_start_date) < TRUNC (SYSDATE) THEN
2065         -- End date the existing profile and create a new profile
2066                 l_create_update_flag := 'C';
2067         ELSE
2068         -- Same day,so update the existing profile
2069                 l_create_update_flag := 'U';
2070         END IF;
2071     END IF;
2072 
2073     IF l_create_update_flag = 'C' THEN
2074         -- Always End date the existing profile and create a new profile
2075        --l_object_version_number := NVL(l_object_version_number, 1) + 1;
2076        l_version_number :=  nvl(l_version_number,1)+1;
2077 
2078         UPDATE hz_organization_profiles
2079         SET    effective_end_date = decode(trunc(effective_start_date),trunc(sysdate),trunc(sysdate),TRUNC (SYSDATE-1)),
2080                object_version_number = NVL(l_object_version_number, 1) + 1
2081                --,version_number = NVL(version_number,1)+1
2082         WHERE rowid = l_rowid;
2083 
2084 -- Bug 3560323 : Get business report from previous org profile to copy to new org profile
2085         BEGIN
2086                 SELECT business_report INTO l_business_report
2087                 FROM hz_organization_profiles
2088                 WHERE rowid = l_rowid;
2089         EXCEPTION
2090                 WHEN NO_DATA_FOUND THEN
2091                         NULL;
2092                 WHEN OTHERS THEN
2093                         NULL;
2094         END;
2095 
2096       -- create a new record with same data as current profile
2097       do_create_org_profile(
2098         p_organization_rec           => p_old_organization_rec,
2099         p_party_id                   => p_organization_rec.party_rec.party_id,
2100         x_profile_id                 => x_profile_id,
2101         p_version_number             => l_version_number,
2102         x_rowid                      => l_rowid );
2103 
2104       l_object_version_number := 2;
2105 
2106 -- Bug 3560323 : Update the new org profile with previous business report
2107         UPDATE hz_organization_profiles
2108         SET business_report = l_business_report
2109         WHERE organization_profile_id = x_profile_id;
2110 
2111       --
2112       -- copy extent data for extensibility project.
2113       --
2114       IF p_data_source_type = G_SST_SOURCE_TYPE THEN
2115         HZ_EXTENSIBILITY_PVT.copy_org_extent_data (
2116           p_old_profile_id          => l_organization_profile_id,
2117           p_new_profile_id          => x_profile_id,
2118           x_return_status           => l_return_status
2119         );
2120 
2121         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2122           RAISE FND_API.G_EXC_ERROR;
2123         END IF;
2124       END IF;
2125 
2126     ELSE
2127       x_profile_id := l_organization_profile_id;
2128       l_object_version_number := NVL(l_object_version_number, 1) + 1;
2129       l_version_number  :=  nvl(l_version_number,1)+1;
2130     END IF;
2131 
2132 /*
2133     IF TRUNC(l_effective_start_date) < TRUNC(SYSDATE) THEN
2134       UPDATE hz_organization_profiles
2135       SET effective_end_date = TRUNC(SYSDATE-1),
2136           object_version_number = NVL(object_version_number, 1) + 1
2137       WHERE rowid = l_rowid;
2138 
2139       -- create a new record with same data as current profile
2140       do_create_org_profile(
2141         p_organization_rec           => p_old_organization_rec,
2142         p_party_id                   => p_organization_rec.party_rec.party_id,
2143         x_profile_id                 => x_profile_id,
2144         x_rowid                      => l_rowid );
2145 
2146       l_object_version_number := 2;
2147     ELSE
2148       x_profile_id := l_organization_profile_id;
2149       l_object_version_number := NVL(l_object_version_number, 1) + 1;
2150     END IF;
2151 */
2152     -- Debug info.
2153     /*IF g_debug THEN
2154       hz_utility_v2pub.debug ('profile_id = '||x_profile_id, l_debug_prefix);
2155       hz_utility_v2pub.debug ('hz_organization_profiles_pkg.Update_Row (+) ',
2156                               l_debug_prefix);
2157     END IF;
2158     */
2159     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
2160         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'hz_organization_profiles_pkg.Update_Row (+) ',
2161                                p_msg_level=>fnd_log.level_procedure);
2162     END IF;
2163     IF fnd_log.level_statement>=fnd_log.g_current_runtime_level THEN
2164            hz_utility_v2pub.debug(p_message=>'profile_id = '||x_profile_id,
2165                                   p_prefix =>l_debug_prefix,
2166                                   p_msg_level=>fnd_log.level_statement);
2167     END IF;
2168 
2169     -- call table-handler.
2170     HZ_organization_profiles_pkg.update_row (
2171       x_rowid                             => l_rowid,
2172       x_organization_profile_id           => x_profile_id,
2173       x_party_id                          => NULL,
2174       x_organization_name                 => p_organization_rec.organization_name,
2175       x_attribute_category                => p_organization_rec.attribute_category,
2176       x_attribute1                        => p_organization_rec.attribute1,
2177       x_attribute2                        => p_organization_rec.attribute2,
2178       x_attribute3                        => p_organization_rec.attribute3,
2179       x_attribute4                        => p_organization_rec.attribute4,
2180       x_attribute5                        => p_organization_rec.attribute5,
2181       x_attribute6                        => p_organization_rec.attribute6,
2182       x_attribute7                        => p_organization_rec.attribute7,
2183       x_attribute8                        => p_organization_rec.attribute8,
2184       x_attribute9                        => p_organization_rec.attribute9,
2185       x_attribute10                       => p_organization_rec.attribute10,
2186       x_attribute11                       => p_organization_rec.attribute11,
2187       x_attribute12                       => p_organization_rec.attribute12,
2188       x_attribute13                       => p_organization_rec.attribute13,
2189       x_attribute14                       => p_organization_rec.attribute14,
2190       x_attribute15                       => p_organization_rec.attribute15,
2191       x_attribute16                       => p_organization_rec.attribute16,
2192       x_attribute17                       => p_organization_rec.attribute17,
2193       x_attribute18                       => p_organization_rec.attribute18,
2194       x_attribute19                       => p_organization_rec.attribute19,
2195       x_attribute20                       => p_organization_rec.attribute20,
2196       x_enquiry_duns                      => p_organization_rec.enquiry_duns,
2197       x_ceo_name                          => p_organization_rec.ceo_name,
2198       x_ceo_title                         => p_organization_rec.ceo_title,
2199       x_principal_name                    => p_organization_rec.principal_name,
2200       x_principal_title                   => p_organization_rec.principal_title,
2201       x_legal_status                      => p_organization_rec.legal_status,
2202       x_control_yr                        => p_organization_rec.control_yr,
2203       x_employees_total                   => p_organization_rec.employees_total,
2204       x_hq_branch_ind                     => p_organization_rec.hq_branch_ind,
2205       x_branch_flag                       => p_organization_rec.branch_flag,
2206       x_oob_ind                           => p_organization_rec.oob_ind,
2207       x_line_of_business                  => p_organization_rec.line_of_business,
2208       x_cong_dist_code                    => p_organization_rec.cong_dist_code,
2209       x_sic_code                          => p_organization_rec.sic_code,
2210       x_import_ind                        => p_organization_rec.import_ind,
2211       x_export_ind                        => p_organization_rec.export_ind,
2212       x_labor_surplus_ind                 => p_organization_rec.labor_surplus_ind,
2213       x_debarment_ind                     => p_organization_rec.debarment_ind,
2214       x_minority_owned_ind                => p_organization_rec.minority_owned_ind,
2215       x_minority_owned_type               => p_organization_rec.minority_owned_type,
2216       x_woman_owned_ind                   => p_organization_rec.woman_owned_ind,
2217       x_disadv_8a_ind                     => p_organization_rec.disadv_8a_ind,
2218       x_small_bus_ind                     => p_organization_rec.small_bus_ind,
2219       x_rent_own_ind                      => p_organization_rec.rent_own_ind,
2220       x_debarments_count                  => p_organization_rec.debarments_count,
2221       x_debarments_date                   => p_organization_rec.debarments_date,
2222       x_failure_score                     => p_organization_rec.failure_score,
2223       x_failure_score_override_code       => p_organization_rec.failure_score_override_code,
2224       x_failure_score_commentary          => p_organization_rec.failure_score_commentary,
2225       x_global_failure_score              => p_organization_rec.global_failure_score,
2226       x_db_rating                         => p_organization_rec.db_rating,
2227       x_credit_score                      => p_organization_rec.credit_score,
2228       x_credit_score_commentary           => p_organization_rec.credit_score_commentary,
2229       x_paydex_score                      => p_organization_rec.paydex_score,
2230       x_paydex_three_months_ago           => p_organization_rec.paydex_three_months_ago,
2231       x_paydex_norm                       => p_organization_rec.paydex_norm,
2232       x_best_time_contact_begin           => p_organization_rec.best_time_contact_begin,
2233       x_best_time_contact_end             => p_organization_rec.best_time_contact_end,
2234       x_organization_name_phonetic        => p_organization_rec.organization_name_phonetic,
2235       x_tax_reference                     => p_organization_rec.tax_reference,
2236       x_gsa_indicator_flag                => p_organization_rec.gsa_indicator_flag,
2237       x_jgzz_fiscal_code                  => p_organization_rec.jgzz_fiscal_code,
2238       x_analysis_fy                       => p_organization_rec.analysis_fy,
2239       x_fiscal_yearend_month              => p_organization_rec.fiscal_yearend_month,
2240       x_curr_fy_potential_revenue         => p_organization_rec.curr_fy_potential_revenue,
2241       x_next_fy_potential_revenue         => p_organization_rec.next_fy_potential_revenue,
2242       x_year_established                  => p_organization_rec.year_established,
2243       x_mission_statement                 => p_organization_rec.mission_statement,
2244       x_organization_type                 => p_organization_rec.organization_type,
2245       x_business_scope                    => p_organization_rec.business_scope,
2246       x_corporation_class                 => p_organization_rec.corporation_class,
2247       x_known_as                          => p_organization_rec.known_as,
2248       x_local_bus_iden_type               => p_organization_rec.local_bus_iden_type,
2249       x_local_bus_identifier              => p_organization_rec.local_bus_identifier,
2250       x_pref_functional_currency          => p_organization_rec.pref_functional_currency,
2251       x_registration_type                 => p_organization_rec.registration_type,
2252       x_total_employees_text              => p_organization_rec.total_employees_text,
2253       x_total_employees_ind               => p_organization_rec.total_employees_ind,
2254       x_total_emp_est_ind                 => p_organization_rec.total_emp_est_ind,
2255       x_total_emp_min_ind                 => p_organization_rec.total_emp_min_ind,
2256       x_parent_sub_ind                    => p_organization_rec.parent_sub_ind,
2257       x_incorp_year                       => p_organization_rec.incorp_year,
2258       x_content_source_type               => null, -- the column is non-updateable
2259       x_content_source_number             => p_organization_rec.content_source_number,
2260       x_effective_start_date              => NULL,
2261       x_effective_end_date                => NULL,
2262       x_sic_code_type                     => p_organization_rec.sic_code_type,
2263       x_public_private_ownership          => p_organization_rec.public_private_ownership_flag,
2264       x_local_activity_code_type          => p_organization_rec.local_activity_code_type,
2265       x_local_activity_code               => p_organization_rec.local_activity_code,
2266       x_emp_at_primary_adr                => p_organization_rec.emp_at_primary_adr,
2267       x_emp_at_primary_adr_text           => p_organization_rec.emp_at_primary_adr_text,
2268       x_emp_at_primary_adr_est_ind        => p_organization_rec.emp_at_primary_adr_est_ind,
2269       x_emp_at_primary_adr_min_ind        => p_organization_rec.emp_at_primary_adr_min_ind,
2270       x_internal_flag                     => p_organization_rec.internal_flag,
2271       x_high_credit                       => p_organization_rec.high_credit,
2272       x_avg_high_credit                   => p_organization_rec.avg_high_credit,
2273       x_total_payments                    => p_organization_rec.total_payments,
2274       x_known_as2                         => p_organization_rec.known_as2,
2275       x_known_as3                         => p_organization_rec.known_as3,
2276       x_known_as4                         => p_organization_rec.known_as4,
2277       x_known_as5                         => p_organization_rec.known_as5,
2278       x_credit_score_class                => p_organization_rec.credit_score_class,
2279       x_credit_score_natl_percentile      => p_organization_rec.credit_score_natl_percentile,
2280       x_credit_score_incd_default         => p_organization_rec.credit_score_incd_default,
2281       x_credit_score_age                  => p_organization_rec.credit_score_age,
2282       x_credit_score_date                 => p_organization_rec.credit_score_date,
2283       x_failure_score_class               => p_organization_rec.failure_score_class,
2284       x_failure_score_incd_default        => p_organization_rec.failure_score_incd_default,
2285       x_failure_score_age                 => p_organization_rec.failure_score_age,
2286       x_failure_score_date                => p_organization_rec.failure_score_date,
2287       x_failure_score_commentary2         => p_organization_rec.failure_score_commentary2,
2288       x_failure_score_commentary3         => p_organization_rec.failure_score_commentary3,
2289       x_failure_score_commentary4         => p_organization_rec.failure_score_commentary4,
2290       x_failure_score_commentary5         => p_organization_rec.failure_score_commentary5,
2291       x_failure_score_commentary6         => p_organization_rec.failure_score_commentary6,
2292       x_failure_score_commentary7         => p_organization_rec.failure_score_commentary7,
2293       x_failure_score_commentary8         => p_organization_rec.failure_score_commentary8,
2294       x_failure_score_commentary9         => p_organization_rec.failure_score_commentary9,
2295       x_failure_score_commentary10        => p_organization_rec.failure_score_commentary10,
2296       x_credit_score_commentary2          => p_organization_rec.credit_score_commentary2,
2297       x_credit_score_commentary3          => p_organization_rec.credit_score_commentary3,
2298       x_credit_score_commentary4          => p_organization_rec.credit_score_commentary4,
2299       x_credit_score_commentary5          => p_organization_rec.credit_score_commentary5,
2300       x_credit_score_commentary6          => p_organization_rec.credit_score_commentary6,
2301       x_credit_score_commentary7          => p_organization_rec.credit_score_commentary7,
2302       x_credit_score_commentary8          => p_organization_rec.credit_score_commentary8,
2303       x_credit_score_commentary9          => p_organization_rec.credit_score_commentary9,
2304       x_credit_score_commentary10         => p_organization_rec.credit_score_commentary10,
2305       x_maximum_credit_recomm             => p_organization_rec.maximum_credit_recommendation,
2306       x_maximum_credit_currency_code      => p_organization_rec.maximum_credit_currency_code,
2307       x_displayed_duns_party_id           => p_organization_rec.displayed_duns_party_id,
2308       x_failure_score_natnl_perc          => p_organization_rec.failure_score_natnl_percentile,
2309       x_duns_number_c                     => p_organization_rec.duns_number_c,
2310       x_object_version_number             => l_object_version_number,
2311       x_created_by_module                 => p_organization_rec.created_by_module,
2312       x_application_id                    => p_organization_rec.application_id,
2313       x_do_not_confuse_with               => p_organization_rec.do_not_confuse_with,
2314       x_actual_content_source             => null, -- the column is non-updateable
2315       x_version_number                    => l_version_number,
2316       x_home_country                      => p_organization_rec.home_country
2317     );
2318 
2319     -- Debug info.
2320     /*IF g_debug THEN
2321       hz_utility_v2pub.debug ('hz_organization_profiles_pkg.Update_Row (-) ',
2322                               l_debug_prefix);
2323     END IF;
2324     */
2325     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
2326         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'hz_organization_profiles_pkg.Update_Row (-) ',
2327                                p_msg_level=>fnd_log.level_procedure);
2328     END IF;
2329 
2330     -- Debug info.
2331     /*IF g_debug THEN
2332       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_update_org_profile (-)');
2333     END IF;
2334     */
2335     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
2336         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_update_org_profile (-)',
2337                                p_msg_level=>fnd_log.level_procedure);
2338     END IF;
2339 
2340   EXCEPTION
2341     WHEN g_resource_busy THEN
2342       fnd_message.set_name('AR', 'HZ_API_RECORD_CHANGED');
2343       fnd_message.set_token('TABLE', 'HZ_ORGANIZATION_PROFILES');
2344       fnd_msg_pub.add;
2345       RAISE fnd_api.g_exc_error;
2346 
2347   END do_update_org_profile;
2348 
2349   /**
2350    * PRIVATE PROCEDURE do_create_party_profile
2351    *
2352    * DESCRIPTION
2353    *     Creates party profile.
2354    *
2355    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
2356    *
2357    * ARGUMENTS
2358    *     IN:
2359    *       p_party_id
2360    *       p_party_type
2361    *       p_content_source_type
2362    *       p_actual_content_source
2363    *     OUT:
2364    *       x_profile_id
2365    *     IN/ OUT:
2366    *       p_person_rec
2367    *       p_organization_rec
2368    *
2369    * NOTES
2370    *
2371    * MODIFICATION HISTORY
2372    */
2373 
2374   PROCEDURE do_create_party_profile (
2375     p_party_type                       IN     VARCHAR2,
2376     p_party_id                         IN     NUMBER,
2377     p_person_rec                       IN OUT NOCOPY PERSON_REC_TYPE,
2378     p_organization_rec                 IN OUT NOCOPY ORGANIZATION_REC_TYPE,
2379     p_content_source_type              IN     VARCHAR2,
2380     p_actual_content_source            IN     VARCHAR2,
2381     x_profile_id                       OUT    NOCOPY NUMBER
2382   ) IS
2383 
2384     l_rowid                         ROWID := NULL;
2385     l_debug_prefix                     VARCHAR2(30) := '';
2386 
2387     --  Bug 4239442 : Added cursor and variables
2388     l_orig_sys_reference_rec HZ_ORIG_SYSTEM_REF_PUB.ORIG_SYS_REFERENCE_REC_TYPE;
2389     l_orig_system HZ_ORIG_SYS_REFERENCES.ORIG_SYSTEM%TYPE;
2390     l_orig_system_reference HZ_ORIG_SYS_REFERENCES.ORIG_SYSTEM_REFERENCE%TYPE;
2391     l_created_by_module HZ_ORIG_SYS_REFERENCES.CREATED_BY_MODULE%TYPE;
2392     l_exists VARCHAR2(1);
2393     l_return_status                    VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
2394     l_msg_count                        NUMBER;
2395     l_msg_data                         VARCHAR2(2000);
2396 
2397     CURSOR c_check_party_mapping
2398     IS
2399     SELECT 'Y'
2400     FROM hz_orig_sys_references
2401     WHERE owner_table_id = p_party_id
2402     AND   owner_table_name = 'HZ_PARTIES'
2403     AND   orig_system = l_orig_system
2404     AND   orig_system_reference = l_orig_system_reference
2405     AND   trunc(nvl(end_date_active, sysdate)) >= trunc(sysdate)
2406     AND   status = 'A';
2407 
2408   BEGIN
2409 
2410     -- Debug info.
2411     /*IF g_debug THEN
2412         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_create_party_profile (+)');
2413     END IF;
2414     */
2415     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
2416         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_create_party_profile (+)',
2417                                p_msg_level=>fnd_log.level_procedure);
2418     END IF;
2419 
2420     IF p_party_type = 'PERSON' THEN
2421       p_person_rec.content_source_type := p_content_source_type;
2422       p_person_rec.actual_content_source := p_actual_content_source;
2423 
2424       do_create_person_profile (
2425         p_person_rec               => p_person_rec,
2426         p_party_id                 => p_party_id,
2427         x_profile_id               => x_profile_id,
2428         p_version_number           => 1,
2429         x_rowid                    => l_rowid );
2430 
2431       --  Bug 4239442 : assign required vlaues to local variable
2432       l_orig_system := p_person_rec.party_rec.orig_system;
2433       l_orig_system_reference := p_person_rec.party_rec.orig_system_reference;
2434       l_created_by_module := p_person_rec.created_by_module;
2435 
2436     ELSIF p_party_type = 'ORGANIZATION' THEN
2437       p_organization_rec.content_source_type := p_content_source_type;
2438       p_organization_rec.actual_content_source := p_actual_content_source;
2439 
2440       do_create_org_profile (
2441         p_organization_rec         => p_organization_rec,
2442         p_party_id                 => p_party_id,
2443         x_profile_id               => x_profile_id,
2444         p_version_number           => 1,
2445         x_rowid                    => l_rowid );
2446 
2447       --  Bug 4239442 : assign required vlaues to local variable
2448       l_orig_system := p_organization_rec.party_rec.orig_system;
2449       l_orig_system_reference := p_organization_rec.party_rec.orig_system_reference;
2450       l_created_by_module := p_organization_rec.created_by_module;
2451 
2452     END IF;
2453 
2454     /* Bug 4239442 : If orig_system is passed by the user
2455      * check if there is already any MOSR entry for same
2456      * OS, OSR for same party. If not, create a new entry
2457      * If it is already existing, the call may be due to
2458      * HZ_PROFILE_VERSION profile setup
2459      */
2460     if l_orig_system is not null and
2461        l_orig_system <>fnd_api.g_miss_char
2462     then
2463        open c_check_party_mapping;
2464        fetch c_check_party_mapping into l_exists;
2465        if c_check_party_mapping%NOTFOUND then
2466           l_orig_sys_reference_rec.orig_system := l_orig_system ;
2467           l_orig_sys_reference_rec.orig_system_reference := l_orig_system_reference;
2468           l_orig_sys_reference_rec.owner_table_name := 'HZ_PARTIES';
2469           l_orig_sys_reference_rec.owner_table_id := p_party_id;
2470           l_orig_sys_reference_rec.created_by_module := nvl(l_created_by_module, 'TCA_V2_API');
2471 
2472           hz_orig_system_ref_pub.create_orig_system_reference(
2473                         FND_API.G_FALSE,
2474                         l_orig_sys_reference_rec,
2475                         l_return_status,
2476                         l_msg_count,
2477                         l_msg_data);
2478 
2479           IF l_return_status <> fnd_api.g_ret_sts_success THEN
2480              RAISE FND_API.G_EXC_ERROR;
2481           END IF;
2482         end if;
2483     end if;
2484 
2485     -- Debug info.
2486     /*IF g_debug THEN
2487         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_create_party_profile (-)');
2488     END IF;
2489     */
2490     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
2491         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_create_party_profile (-)',
2492                                p_msg_level=>fnd_log.level_procedure);
2493     END IF;
2494 
2495   END do_create_party_profile;
2496 
2497   /**
2498    * PRIVATE PROCEDURE do_update_party_profile
2499    *
2500    * DESCRIPTION
2501    *     Updates party profile.
2502    *
2503    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
2504    *
2505    * ARGUMENTS
2506    *     IN:
2507    *       p_party_type
2508    *       p_data_source_type
2509    *       p_person_rec
2510    *       p_old_person_rec
2511    *       p_organization_rec
2512    *       p_old_organization_rec
2513    *     OUT:
2514    *       x_profile_id
2515    *     IN/ OUT:
2516    *
2517    * NOTES
2518    *
2519    * MODIFICATION HISTORY
2520    */
2521 
2522   PROCEDURE do_update_party_profile (
2523     p_party_type                       IN     VARCHAR2,
2524     p_person_rec                       IN     PERSON_REC_TYPE,
2525     p_old_person_rec                   IN     PERSON_REC_TYPE := G_MISS_PERSON_REC,
2526     p_organization_rec                 IN     ORGANIZATION_REC_TYPE,
2527     p_old_organization_rec             IN     ORGANIZATION_REC_TYPE := G_MISS_ORGANIZATION_REC,
2528     p_data_source_type                 IN     VARCHAR2,
2529     x_profile_id                       OUT    NOCOPY NUMBER
2530   ) IS
2531   l_debug_prefix                       VARCHAR2(30) := '';
2532   BEGIN
2533 
2534     -- Debug info.
2535     /*IF g_debug THEN
2536       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_update_party_profile (+)');
2537       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'party_type = '||p_party_type);
2538     END IF;
2539     */
2540     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
2541         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_update_party_profile (+)',
2542                                p_msg_level=>fnd_log.level_procedure);
2543 
2544     END IF;
2545     IF fnd_log.level_statement>=fnd_log.g_current_runtime_level THEN
2546            hz_utility_v2pub.debug(p_message=>'party_type = '||p_party_type,
2547                                   p_prefix =>l_debug_prefix,
2548                                   p_msg_level=>fnd_log.level_statement);
2549     END IF;
2550 
2551     IF p_party_type = 'PERSON' THEN
2552       do_update_person_profile (
2553         p_person_rec                  => p_person_rec,
2554         p_old_person_rec              => p_old_person_rec,
2555         p_data_source_type            => p_data_source_type,
2556         x_profile_id                  => x_profile_id );
2557 
2558     ELSIF p_party_type = 'ORGANIZATION' THEN
2559       do_update_org_profile (
2560         p_organization_rec            => p_organization_rec,
2561         p_old_organization_rec        => p_old_organization_rec,
2562         p_data_source_type            => p_data_source_type,
2563         x_profile_id                  => x_profile_id );
2564 
2565     END IF;
2566 
2567     -- Debug info.
2568     /*IF g_debug THEN
2569       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_update_party_profile (-)');
2570     END IF;
2571     */
2572     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
2573         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_update_party_profile (-)',
2574                                p_msg_level=>fnd_log.level_procedure);
2575     END IF;
2576 
2577   END do_update_party_profile;
2578 
2579   /**
2580    * PRIVATE PROCEDURE do_get_party_profile
2581    *
2582    * DESCRIPTION
2583    *     Gets party profile.
2584    *
2585    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
2586    *
2587    * ARGUMENTS
2588    *     IN:
2589    *       p_party_type
2590    *       p_party_id
2591    *       p_data_source_type
2592    *     OUT:
2593    *       x_person_rec
2594    *       x_organization_rec
2595    *     IN/ OUT:
2596    *
2597    * NOTES
2598    *
2599    * MODIFICATION HISTORY
2600    */
2601 
2602   PROCEDURE do_get_party_profile (
2603     p_party_type                       IN     VARCHAR2,
2604     p_party_id                         IN     NUMBER,
2605     p_data_source_type                 IN     VARCHAR2,
2606     x_person_rec                       OUT    NOCOPY PERSON_REC_TYPE,
2607     x_organization_rec                 OUT    NOCOPY ORGANIZATION_REC_TYPE
2608   ) IS
2609 
2610     l_return_status                    VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
2611     l_msg_count                        NUMBER;
2612     l_msg_data                         VARCHAR2(2000);
2613     l_debug_prefix                     VARCHAR2(30) := '';
2614   BEGIN
2615 
2616     -- Debug info.
2617     /*IF g_debug THEN
2618       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_get_party_profile (+)');
2619       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'party_type = '||p_party_type);
2620     END IF;
2621     */
2622     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
2623         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_get_party_profile (+)',
2624                                p_msg_level=>fnd_log.level_procedure);
2625     END IF;
2626     IF fnd_log.level_statement>=fnd_log.g_current_runtime_level THEN
2627            hz_utility_v2pub.debug(p_message=>'party_type = '||p_party_type,
2628                                   p_prefix =>l_debug_prefix,
2629                                   p_msg_level=>fnd_log.level_statement);
2630     END IF;
2631 
2632     IF p_party_type = 'PERSON' THEN
2633       get_person_rec (
2634         p_party_id                           => p_party_id,
2635         p_content_source_type                => p_data_source_type,
2636         x_person_rec                         => x_person_rec,
2637         x_return_status                      => l_return_status,
2638         x_msg_count                          => l_msg_count,
2639         x_msg_data                           => l_msg_data);
2640 
2641     ELSIF p_party_type = 'ORGANIZATION' THEN
2642       get_organization_rec (
2643         p_party_id                           => p_party_id,
2644         p_content_source_type                => p_data_source_type,
2645         x_organization_rec                   => x_organization_rec,
2646         x_return_status                      => l_return_status,
2647         x_msg_count                          => l_msg_count,
2648         x_msg_data                           => l_msg_data);
2649 
2650     END IF;
2651 
2652     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2653       RAISE FND_API.G_EXC_ERROR;
2654     END IF;
2655 
2656     -- Debug info.
2657     /*IF g_debug THEN
2658         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_get_party_profile (-)');
2659     END IF;
2660     */
2661     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
2662         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_get_party_profile (-)',
2663                                p_msg_level=>fnd_log.level_procedure);
2664     END IF;
2665 
2666   END do_get_party_profile;
2667 
2668   /**
2669    * PRIVATE PROCEDURE do_create_update_party_only
2670    *
2671    * DESCRIPTION
2672    *     Creates / Updates only party.
2673    *
2674    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
2675    *
2676    * ARGUMENTS
2677    *     IN:
2678    *       p_create_update_flag
2679    *       p_party_type
2680    *       p_party_id
2681    *       p_check_object_version_number
2682    *     OUT:
2683    *     IN/ OUT:
2684    *       p_party_object_version_number
2685    *       p_person_rec
2686    *       p_organization_rec
2687    *       p_group_rec
2688    *       x_party_id
2689    *       x_party_number
2690    *
2691    * NOTES
2692    *
2693    * MODIFICATION HISTORY
2694    */
2695 
2696   PROCEDURE do_create_update_party_only(
2697     p_create_update_flag               IN     VARCHAR2,
2698     p_party_type                       IN     VARCHAR2,
2699     -- p_party_id is used in update mode only.
2700     p_party_id                         IN     NUMBER := NULL,
2701     p_check_object_version_number      IN     VARCHAR2 := 'Y',
2702     p_party_object_version_number      IN OUT NOCOPY NUMBER,
2703     p_person_rec                       IN     PERSON_REC_TYPE := G_MISS_PERSON_REC,
2704     p_old_person_rec                   IN     PERSON_REC_TYPE := G_MISS_PERSON_REC,
2705     p_organization_rec                 IN     ORGANIZATION_REC_TYPE := G_MISS_ORGANIZATION_REC,
2706     p_old_organization_rec             IN     ORGANIZATION_REC_TYPE := G_MISS_ORGANIZATION_REC,
2707     p_group_rec                        IN     GROUP_REC_TYPE := G_MISS_GROUP_REC,
2708     p_old_group_rec                    IN     GROUP_REC_TYPE := G_MISS_GROUP_REC,
2709     -- x_party_id and x_party_number are used in create mode.
2710     x_party_id                         OUT    NOCOPY NUMBER,
2711     x_party_number                     OUT    NOCOPY VARCHAR2
2712   ) IS
2713 
2714     l_party_rec                        PARTY_REC_TYPE;
2715     l_old_party_rec                    PARTY_REC_TYPE;
2716     l_party_dup_rec                    PARTY_DUP_REC_TYPE;
2717     l_person_rec                       PERSON_REC_TYPE;
2718 
2719     db_party_name                      HZ_PARTIES.PARTY_NAME%TYPE;
2720     db_created_by_module               HZ_PARTIES.CREATED_BY_MODULE%TYPE;
2721     l_party_name                       HZ_PARTIES.PARTY_NAME%TYPE;
2722     l_first_name                       HZ_PARTIES.PERSON_FIRST_NAME%TYPE;
2723     l_last_name                        HZ_PARTIES.PERSON_LAST_NAME%TYPE;
2724     l_customer_key                     HZ_PARTIES.CUSTOMER_KEY%TYPE;
2725     l_party_object_version_number      NUMBER;
2726     l_rowid                            ROWID := NULL;
2727     l_process_party_name               VARCHAR2(1);
2728     l_dummy                            VARCHAR2(1);
2729     l_return_status                    VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
2730     l_context                          VARCHAR2(1);
2731 
2732     l_debug_prefix                     VARCHAR2(30);
2733      l_orig_sys_reference_rec    HZ_ORIG_SYSTEM_REF_PUB.ORIG_SYS_REFERENCE_REC_TYPE;
2734 
2735     l_msg_count number;
2736     l_msg_data varchar2(2000);
2737     l_created_by_module varchar2(150);
2738 
2739 --  Bug 4490715 : Used to store party_tax_profile_id for update
2740     L_PARTY_TAX_PROFILE_ID      ZX_PARTY_TAX_PROFILE.PARTY_TAX_PROFILE_ID%TYPE;
2741 
2742     CURSOR c_party IS
2743       SELECT party_name, object_version_number, rowid,
2744              created_by_module
2745       FROM   hz_parties
2746       WHERE  party_id = p_party_id
2747       FOR UPDATE NOWAIT;
2748 
2749     CURSOR c_party_number_exists (
2750       p_party_number          VARCHAR2
2751     ) IS
2752       SELECT 'Y'
2753       FROM hz_parties
2754       WHERE party_number = p_party_number;
2755 
2756   BEGIN
2757 
2758     -- Debug info.
2759     /*IF g_debug THEN
2760       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_create_update_party_only (+)');
2761     END IF;
2762     */
2763     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
2764         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_create_update_party_only (+)',
2765                                p_msg_level=>fnd_log.level_procedure);
2766     END IF;
2767 
2768     IF p_party_type = 'PERSON' THEN
2769       l_old_party_rec := p_old_person_rec.party_rec;
2770       l_party_rec := p_person_rec.party_rec;
2771       l_created_by_module := p_person_rec.created_by_module;
2772     ELSIF p_party_type = 'ORGANIZATION' THEN
2773       l_old_party_rec := p_old_organization_rec.party_rec;
2774       l_party_rec := p_organization_rec.party_rec;
2775        l_created_by_module := p_organization_rec.created_by_module;
2776     ELSIF p_party_type = 'GROUP' THEN
2777       l_old_party_rec := p_old_group_rec.party_rec;
2778       l_party_rec := p_group_rec.party_rec;
2779        l_created_by_module := p_group_rec.created_by_module;
2780     END IF;
2781 
2782  -- moved the mosr logic to update_xxx due to get_rec need party_id
2783 /*    if p_create_update_flag = 'U' THEN
2784       IF (l_party_rec.orig_system is not null
2785          and l_party_rec.orig_system <>fnd_api.g_miss_char)
2786        and (l_party_rec.orig_system_reference is not null
2787          and l_party_rec.orig_system_reference <>fnd_api.g_miss_char)
2788        and (l_party_rec.party_id = FND_API.G_MISS_NUM or l_party_rec.party_id is null) THEN
2789            hz_orig_system_ref_pub.get_owner_table_id
2790                         (p_orig_system => l_party_rec.orig_system,
2791                         p_orig_system_reference => l_party_rec.orig_system_reference,
2792                         p_owner_table_name => 'HZ_PARTIES',
2793                         x_owner_table_id => l_party_rec.party_id,
2794                         x_return_status => l_return_status);
2795             IF l_return_status <> fnd_api.g_ret_sts_success THEN
2796                 RAISE FND_API.G_EXC_ERROR;
2797             END IF;
2798       END IF;
2799    end if;
2800 */
2801     -- check party number in creation mode and
2802     -- lock record in update mode.
2803 
2804     IF p_create_update_flag = 'C' THEN
2805 
2806       -- if GENERATE_PARTY_NUMBER is 'N', then if party_number is
2807       -- not passed or is a duplicate raise error.
2808 
2809       IF NVL(fnd_profile.value('HZ_GENERATE_PARTY_NUMBER'), 'Y') = 'N' THEN
2810 
2811         IF l_party_rec.party_number = FND_API.G_MISS_CHAR OR
2812            l_party_rec.party_number IS NULL
2813         THEN
2814           fnd_message.set_name('AR', 'HZ_API_MISSING_COLUMN');
2815           fnd_message.set_token('COLUMN', 'party number');
2816           fnd_msg_pub.add;
2817           RAISE FND_API.G_EXC_ERROR;
2818         END IF;
2819 
2820         OPEN c_party_number_exists(l_party_rec.party_number);
2821         FETCH c_party_number_exists INTO l_dummy;
2822 
2823         IF NOT c_party_number_exists%NOTFOUND THEN
2824           fnd_message.set_name('AR', 'HZ_API_DUPLICATE_COLUMN');
2825           fnd_message.set_token('COLUMN', 'party_number');
2826           fnd_msg_pub.add;
2827           RAISE FND_API.G_EXC_ERROR;
2828         END IF;
2829         CLOSE c_party_number_exists;
2830 
2831       ELSE -- GENERATE_PARTY_NUMBER is 'Y'
2832 
2833         IF l_party_rec.party_number <> FND_API.G_MISS_CHAR AND
2834            l_party_rec.party_number IS NOT NULL
2835         THEN
2836           fnd_message.set_name('AR', 'HZ_API_PARTY_NUMBER_AUTO_ON');
2837           fnd_msg_pub.add;
2838           RAISE FND_API.G_EXC_ERROR;
2839         END IF;
2840 
2841       END IF;
2842 
2843     ELSE -- update mode
2844 
2845       -- check whether record has been updated by another user.
2846       -- if not, lock it.
2847 
2848       OPEN c_party;
2849       FETCH c_party INTO
2850         db_party_name, l_party_object_version_number, l_rowid, db_created_by_module;
2851 
2852       IF c_party%NOTFOUND THEN
2853         fnd_message.set_name('AR', 'HZ_API_NO_RECORD');
2854         fnd_message.set_token('RECORD', 'party');
2855         fnd_message.set_token('VALUE', NVL(TO_CHAR(p_party_id), 'NULL'));
2856         fnd_msg_pub.add;
2857         RAISE fnd_api.g_exc_error;
2858       ELSIF p_check_object_version_number = 'Y' AND
2859             NOT ((p_party_object_version_number IS NULL AND
2860                  l_party_object_version_number IS NULL) OR
2861                 (p_party_object_version_number IS NOT NULL AND
2862                  l_party_object_version_number IS NOT NULL AND
2863                  p_party_object_version_number = l_party_object_version_number))
2864       THEN
2865         fnd_message.set_name('AR', 'HZ_API_RECORD_CHANGED');
2866         fnd_message.set_token('TABLE', 'HZ_PARTIES');
2867         fnd_msg_pub.add;
2868         RAISE fnd_api.g_exc_error;
2869       END IF;
2870       CLOSE c_party;
2871 
2872       p_party_object_version_number := nvl(l_party_object_version_number, 1)+1;
2873 
2874     END IF;
2875 
2876 
2877     -- Construct dup rec.
2878 
2879     IF p_party_type = 'PERSON' THEN
2880 
2881       IF p_create_update_flag = 'C' THEN
2882 
2883         --  Check "backwards compatability" profile option and determine
2884         --  whether to stick with the old-style name formatting, or call
2885         --  the new dynamic name formatting routines.
2886 
2887         -- use new routines
2888 
2889         IF nvl(fnd_profile.value(g_profile_fmt_bkwd_compatible),'Y') = 'N' THEN
2890 
2891           -- use the new name formatting routine
2892 
2893           l_party_name := substrb( do_create_person_name(p_person_rec), 1, 360 );
2894 
2895         ELSE
2896           -- party_name is the concatenation of person_first_name, '.', and
2897           -- person_last_name
2898 
2899           l_party_name :=
2900             do_create_party_name(p_person_rec.person_first_name, p_person_rec.person_last_name);
2901         END IF;
2902 
2903         l_first_name := p_person_rec.person_first_name;
2904         l_last_name := p_person_rec.person_last_name;
2905 
2906       ELSE -- p_create_update_flag = 'U'
2907 
2908         -- Bug 3999044
2909         IF p_person_rec.person_title IS NULL AND
2910            p_person_rec.person_first_name IS NULL AND
2911            p_person_rec.person_middle_name IS NULL AND
2912            p_person_rec.person_last_name IS NULL AND
2913            p_person_rec.person_name_suffix IS NULL AND
2914            p_person_rec.known_as IS NULL AND
2915            p_person_rec.person_first_name_phonetic IS NULL AND
2916            p_person_rec.middle_name_phonetic IS NULL AND
2917            p_person_rec.person_last_name_phonetic IS NULL
2918         THEN
2919           l_process_party_name := 'N';
2920         ELSE
2921           l_person_rec.person_title :=
2922             NVL(p_person_rec.person_title, p_old_person_rec.person_title);
2923           l_person_rec.person_first_name :=
2924             NVL(p_person_rec.person_first_name, p_old_person_rec.person_first_name);
2925           l_person_rec.person_middle_name :=
2926             NVL(p_person_rec.person_middle_name, p_old_person_rec.person_middle_name);
2927           l_person_rec.person_last_name :=
2928             NVL(p_person_rec.person_last_name, p_old_person_rec.person_last_name);
2929           l_person_rec.person_name_suffix :=
2930             NVL(p_person_rec.person_name_suffix, p_old_person_rec.person_name_suffix);
2931           l_person_rec.known_as :=
2932             NVL(p_person_rec.known_as,p_old_person_rec.known_as);
2933           l_person_rec.person_first_name_phonetic:=
2934             NVL(p_person_rec.person_first_name_phonetic,p_old_person_rec.person_first_name_phonetic);
2935           l_person_rec.middle_name_phonetic:=
2936             NVL(p_person_rec.middle_name_phonetic,p_old_person_rec.middle_name_phonetic);
2937           l_person_rec.person_last_name_phonetic :=
2938             NVL(p_person_rec.person_last_name_phonetic,p_old_person_rec.person_last_name_phonetic);
2939 
2940           l_process_party_name := 'Y';
2941         END IF;
2942 
2943         IF l_process_party_name = 'Y' THEN
2944 
2945           --  Check "backwards compatability" profile option and determine
2946           --  whether to stick with the old-style name formatting, or call
2947           --  the new dynamic name formatting routines.
2948 
2949           -- use new routines
2950 
2951           IF nvl(fnd_profile.value(g_profile_fmt_bkwd_compatible),'Y') = 'N' THEN
2952 
2953             -- use the new name formatting routine
2954             l_party_name := substrb( do_create_person_name(l_person_rec), 1, 360 );
2955 
2956           ELSE
2957 
2958             IF p_person_rec.person_first_name IS NULL AND
2959                p_person_rec.person_last_name IS NULL
2960             THEN
2961               l_party_name := NULL;
2962             ELSE
2963               l_party_name :=
2964                 do_create_party_name(l_person_rec.person_first_name, l_person_rec.person_last_name);
2965             END IF;
2966 
2967           END IF;
2968         END IF;
2969 
2970         l_first_name := l_person_rec.person_first_name;
2971         l_last_name := l_person_rec.person_last_name;
2972       END IF;
2973 
2974       l_party_dup_rec.created_by_module := p_person_rec.created_by_module;
2975       l_party_dup_rec.application_id := p_person_rec.application_id;
2976       l_party_dup_rec.tax_reference := p_person_rec.tax_reference;
2977       l_party_dup_rec.jgzz_fiscal_code := p_person_rec.jgzz_fiscal_code;
2978       l_party_dup_rec.pre_name_adjunct := p_person_rec.person_pre_name_adjunct;
2979       l_party_dup_rec.first_name := p_person_rec.person_first_name;
2980       l_party_dup_rec.middle_name := p_person_rec.person_middle_name;
2981       l_party_dup_rec.last_name := p_person_rec.person_last_name;
2982       l_party_dup_rec.name_suffix := p_person_rec.person_name_suffix;
2983       l_party_dup_rec.title := p_person_rec.person_title;
2984       l_party_dup_rec.academic_title := p_person_rec.person_academic_title;
2985       l_party_dup_rec.previous_last_name := p_person_rec.person_previous_last_name;
2986       l_party_dup_rec.known_as := p_person_rec.known_as;
2987       l_party_dup_rec.known_as2 := p_person_rec.known_as2;
2988       l_party_dup_rec.known_as3 := p_person_rec.known_as3;
2989       l_party_dup_rec.known_as4 := p_person_rec.known_as4;
2990       l_party_dup_rec.known_as5 := p_person_rec.known_as5;
2991       l_party_dup_rec.person_iden_type := p_person_rec.person_iden_type;
2992       l_party_dup_rec.person_identifier := p_person_rec.person_identifier;
2993       l_party_dup_rec.person_first_name_phonetic := p_person_rec.person_first_name_phonetic;
2994       l_party_dup_rec.person_last_name_phonetic := p_person_rec.person_last_name_phonetic;
2995       l_party_dup_rec.middle_name_phonetic := p_person_rec.middle_name_phonetic;
2996 
2997       -- generate customer key
2998 
2999       IF l_party_name IS NOT NULL AND
3000          l_party_name <> FND_API.G_MISS_CHAR AND
3001          l_party_name <> NVL(db_party_name, FND_API.G_MISS_CHAR)
3002       THEN
3003         l_customer_key := HZ_FUZZY_PUB.generate_key (
3004           p_key_type          => 'PERSON',
3005           p_first_name        => l_first_name,
3006           p_last_name         => l_last_name);
3007       END IF;
3008 
3009       -- Debug info.
3010       /*IF g_debug THEN
3011         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'Generated person key : '||l_customer_key);
3012       END IF;*/
3013 
3014       IF fnd_log.level_statement>=fnd_log.g_current_runtime_level THEN
3015         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'Generated person key : '||l_customer_key,
3016                                p_msg_level=>fnd_log.level_statement);
3017       END IF;
3018 
3019     ELSIF p_party_type = 'ORGANIZATION' THEN
3020 
3021       l_party_name := p_organization_rec.organization_name;
3022       l_party_dup_rec.created_by_module := p_organization_rec.created_by_module;
3023       l_party_dup_rec.application_id := p_organization_rec.application_id;
3024       l_party_dup_rec.sic_code := p_organization_rec.sic_code;
3025       l_party_dup_rec.sic_code_type := p_organization_rec.sic_code_type;
3026       l_party_dup_rec.hq_branch_ind := p_organization_rec.hq_branch_ind;
3027       l_party_dup_rec.tax_reference := p_organization_rec.tax_reference;
3028       l_party_dup_rec.jgzz_fiscal_code := p_organization_rec.jgzz_fiscal_code;
3029       l_party_dup_rec.duns_number_c := p_organization_rec.duns_number_c;
3030       l_party_dup_rec.known_as := p_organization_rec.known_as;
3031       l_party_dup_rec.known_as2 := p_organization_rec.known_as2;
3032       l_party_dup_rec.known_as3 := p_organization_rec.known_as3;
3033       l_party_dup_rec.known_as4 := p_organization_rec.known_as4;
3034       l_party_dup_rec.known_as5 := p_organization_rec.known_as5;
3035       l_party_dup_rec.fiscal_yearend_month := p_organization_rec.fiscal_yearend_month;
3036       l_party_dup_rec.employees_total := p_organization_rec.employees_total;
3037       l_party_dup_rec.curr_fy_potential_revenue := p_organization_rec.curr_fy_potential_revenue;
3038       l_party_dup_rec.next_fy_potential_revenue := p_organization_rec.next_fy_potential_revenue;
3039       l_party_dup_rec.year_established := p_organization_rec.year_established;
3040       l_party_dup_rec.gsa_indicator_flag := p_organization_rec.gsa_indicator_flag;
3041       l_party_dup_rec.mission_statement := p_organization_rec.mission_statement;
3042       l_party_dup_rec.organization_name_phonetic := p_organization_rec.organization_name_phonetic;
3043       l_party_dup_rec.analysis_fy := p_organization_rec.analysis_fy;
3044 
3045        -- generate customer key
3046 
3047       IF l_party_name IS NOT NULL AND
3048          l_party_name <> FND_API.G_MISS_CHAR AND
3049          l_party_name <> NVL(db_party_name, FND_API.G_MISS_CHAR)
3050       THEN
3051         l_customer_key := hz_fuzzy_pub.generate_key (
3052           p_key_type          => 'ORGANIZATION',
3053           p_party_name        => p_organization_rec.organization_name );
3054       END IF;
3055 
3056       -- Debug info.
3057       /*IF g_debug THEN
3058         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'Generated organization key : '||l_customer_key);
3059       END IF;
3060       */
3061       IF fnd_log.level_statement>=fnd_log.g_current_runtime_level THEN
3062         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'Generated organization key : '||l_customer_key,
3063                                p_msg_level=>fnd_log.level_statement);
3064       END IF;
3065 
3066     ELSIF p_party_type = 'GROUP' THEN
3067 
3068       l_party_name := p_group_rec.group_name;
3069       l_party_dup_rec.created_by_module := p_group_rec.created_by_module;
3070       l_party_dup_rec.application_id := p_group_rec.application_id;
3071       -- Bug 2467872
3072       l_party_dup_rec.mission_statement := p_group_rec.mission_statement;
3073 
3074       -- generate customer key
3075 
3076       IF l_party_name IS NOT NULL AND
3077          l_party_name <> FND_API.G_MISS_CHAR AND
3078          l_party_name <> NVL(db_party_name, FND_API.G_MISS_CHAR)
3079       THEN
3080         l_customer_key := HZ_FUZZY_PUB.generate_key (
3081           p_key_type          => 'GROUP',
3082           p_party_name        => p_group_rec.group_name );
3083       END IF;
3084 
3085       -- Debug info.
3086       /*IF g_debug THEN
3087         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'Generated group key : '||l_customer_key);
3088       END IF;
3089       */
3090       IF fnd_log.level_statement>=fnd_log.g_current_runtime_level THEN
3091         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'Generated group key : '||l_customer_key,
3092                                p_msg_level=>fnd_log.level_statement);
3093       END IF;
3094 
3095     END IF;
3096 
3097 
3098     -- validate party record.
3099     HZ_registry_validate_v2pub.validate_party(
3100        p_create_update_flag, l_party_rec, l_old_party_rec,
3101        NVL(db_created_by_module, fnd_api.g_miss_char), l_return_status);
3102     IF l_return_status <> fnd_api.g_ret_sts_success THEN
3103       RAISE FND_API.G_EXC_ERROR;
3104     END IF;
3105 
3106     -- call table handlers
3107 
3108     IF p_create_update_flag = 'C' THEN
3109 
3110       -- Debug info.
3111       /*IF g_debug THEN
3112         hz_utility_v2pub.debug (
3113           'hz_parties_pkg.Insert_Row (+)',l_debug_prefix);
3114       END IF;
3115       */
3116       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
3117         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'hz_parties_pkg.Insert_Row (+)',
3118                                p_msg_level=>fnd_log.level_procedure);
3119       END IF;
3120 
3121       -- this is for handling orig_system_reference defaulting
3122       IF l_party_rec.party_id = FND_API.G_MISS_NUM THEN
3123         l_party_rec.party_id := NULL;
3124       END IF;
3125 
3126       hz_parties_pkg.insert_row (
3127         x_party_id                              => l_party_rec.party_id,
3128         x_party_number                          => l_party_rec.party_number,
3129         x_party_name                            => l_party_name,
3130         x_party_type                            => p_party_type,
3131         x_validated_flag                        => l_party_rec.validated_flag,
3132         x_attribute_category                    => l_party_rec.attribute_category,
3133         x_attribute1                            => l_party_rec.attribute1,
3134         x_attribute2                            => l_party_rec.attribute2,
3135         x_attribute3                            => l_party_rec.attribute3,
3136         x_attribute4                            => l_party_rec.attribute4,
3137         x_attribute5                            => l_party_rec.attribute5,
3138         x_attribute6                            => l_party_rec.attribute6,
3139         x_attribute7                            => l_party_rec.attribute7,
3140         x_attribute8                            => l_party_rec.attribute8,
3141         x_attribute9                            => l_party_rec.attribute9,
3142         x_attribute10                           => l_party_rec.attribute10,
3143         x_attribute11                           => l_party_rec.attribute11,
3144         x_attribute12                           => l_party_rec.attribute12,
3145         x_attribute13                           => l_party_rec.attribute13,
3146         x_attribute14                           => l_party_rec.attribute14,
3147         x_attribute15                           => l_party_rec.attribute15,
3148         x_attribute16                           => l_party_rec.attribute16,
3149         x_attribute17                           => l_party_rec.attribute17,
3150         x_attribute18                           => l_party_rec.attribute18,
3151         x_attribute19                           => l_party_rec.attribute19,
3152         x_attribute20                           => l_party_rec.attribute20,
3153         x_attribute21                           => l_party_rec.attribute21,
3154         x_attribute22                           => l_party_rec.attribute22,
3155         x_attribute23                           => l_party_rec.attribute23,
3156         x_attribute24                           => l_party_rec.attribute24,
3157         x_orig_system_reference                 => l_party_rec.orig_system_reference,
3158         x_sic_code                              => l_party_dup_rec.sic_code,
3159         x_hq_branch_ind                         => l_party_dup_rec.hq_branch_ind,
3160         x_customer_key                          => l_customer_key,
3161         x_tax_reference                         => l_party_dup_rec.tax_reference,
3162         x_jgzz_fiscal_code                      => l_party_dup_rec.jgzz_fiscal_code,
3163         x_person_pre_name_adjunct               => l_party_dup_rec.pre_name_adjunct,
3164         x_person_first_name                     => l_party_dup_rec.first_name,
3165         x_person_middle_name                    => l_party_dup_rec.middle_name,
3166         x_person_last_name                      => l_party_dup_rec.last_name,
3167         x_person_name_suffix                    => l_party_dup_rec.name_suffix,
3168         x_person_title                          => l_party_dup_rec.title,
3169         x_person_academic_title                 => l_party_dup_rec.academic_title,
3170         x_person_previous_last_name             => l_party_dup_rec.previous_last_name,
3171         x_known_as                              => l_party_dup_rec.known_as,
3172         x_person_iden_type                      => l_party_dup_rec.person_iden_type,
3173         x_person_identifier                     => l_party_dup_rec.person_identifier,
3174         x_group_type                            => p_group_rec.group_type,
3175         x_country                               => null,
3176         x_address1                              => null,
3177         x_address2                              => null,
3178         x_address3                              => null,
3179         x_address4                              => null,
3180         x_city                                  => null,
3181         x_postal_code                           => null,
3182         x_state                                 => null,
3183         x_province                              => null,
3184         x_status                                => l_party_rec.status,
3185         x_county                                => null,
3186         x_sic_code_type                         => l_party_dup_rec.sic_code_type,
3187         x_url                                   => null,
3188         x_email_address                         => null,
3189         x_analysis_fy                           => l_party_dup_rec.analysis_fy,
3190         x_fiscal_yearend_month                  => l_party_dup_rec.fiscal_yearend_month,
3191         x_employees_total                       => l_party_dup_rec.employees_total,
3192         x_curr_fy_potential_revenue             => l_party_dup_rec.curr_fy_potential_revenue,
3193         x_next_fy_potential_revenue             => l_party_dup_rec.next_fy_potential_revenue,
3194         x_year_established                      => l_party_dup_rec.year_established,
3195         x_gsa_indicator_flag                    => l_party_dup_rec.gsa_indicator_flag,
3196         x_mission_statement                     => l_party_dup_rec.mission_statement,
3197         x_organization_name_phonetic            => l_party_dup_rec.organization_name_phonetic,
3198         x_person_first_name_phonetic            => l_party_dup_rec.person_first_name_phonetic,
3199         x_person_last_name_phonetic             => l_party_dup_rec.person_last_name_phonetic,
3200         x_language_name                         => null,
3201         x_category_code                         => l_party_rec.category_code,
3202         x_salutation                            => l_party_rec.salutation,
3203         x_known_as2                             => l_party_dup_rec.known_as2,
3204         x_known_as3                             => l_party_dup_rec.known_as3,
3205         x_known_as4                             => l_party_dup_rec.known_as4,
3206         x_known_as5                             => l_party_dup_rec.known_as5,
3207         x_object_version_number                 => 1,
3208         x_duns_number_c                         => l_party_dup_rec.duns_number_c,
3209         x_created_by_module                     => l_party_dup_rec.created_by_module,
3210         x_application_id                        => l_party_dup_rec.application_id
3211       );
3212 
3213 
3214       -- Debug info.
3215       /*IF g_debug THEN
3216         hz_utility_v2pub.debug (
3217           'hz_parties_pkg.Insert_Row (-)', l_debug_prefix);
3218       END IF;
3219       */
3220       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
3221         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'hz_parties_pkg.Insert_Row (-)',
3222                                p_msg_level=>fnd_log.level_procedure);
3223       END IF;
3224 
3225       if l_party_rec.orig_system is not null
3226          and l_party_rec.orig_system <>fnd_api.g_miss_char
3227          --  Bug 4239442 : create MOSR entry only for GROUP party
3228          and p_party_type not in ('PERSON', 'ORGANIZATION')
3229       then
3230                 l_orig_sys_reference_rec.orig_system := l_party_rec.orig_system;
3231                 l_orig_sys_reference_rec.orig_system_reference := l_party_rec.orig_system_reference;
3232                 l_orig_sys_reference_rec.owner_table_name := 'HZ_PARTIES';
3233                 l_orig_sys_reference_rec.owner_table_id := l_party_rec.party_id;
3234                 l_orig_sys_reference_rec.created_by_module := l_created_by_module;
3235 
3236                 hz_orig_system_ref_pub.create_orig_system_reference(
3237                         FND_API.G_FALSE,
3238                         l_orig_sys_reference_rec,
3239                         l_return_status,
3240                         l_msg_count,
3241                         l_msg_data);
3242                  IF l_return_status <> fnd_api.g_ret_sts_success THEN
3243                         RAISE FND_API.G_EXC_ERROR;
3244                 END IF;
3245       end if;
3246 
3247       x_party_id := l_party_rec.party_id;
3248       x_party_number := l_party_rec.party_number;
3249 
3250 --  Bug 4490715 : If party is PERSON / ORGANIZATION call eTax
3251 --                procedure to populate ZX_PARTY_TAX_PROFILE
3252       IF p_party_type IN ('PERSON', 'ORGANIZATION') THEN
3253         ZX_PARTY_TAX_PROFILE_PKG.insert_row (
3254          P_COLLECTING_AUTHORITY_FLAG => null,
3255          P_PROVIDER_TYPE_CODE => null,
3256          P_CREATE_AWT_DISTS_TYPE_CODE => null,
3257          P_CREATE_AWT_INVOICES_TYPE_COD => null,
3258          P_TAX_CLASSIFICATION_CODE => null,
3259          P_SELF_ASSESS_FLAG => null,
3260          P_ALLOW_OFFSET_TAX_FLAG => null,
3261          P_REP_REGISTRATION_NUMBER => l_party_dup_rec.tax_reference,
3262          P_EFFECTIVE_FROM_USE_LE => null,
3263          P_RECORD_TYPE_CODE => null,
3264          P_REQUEST_ID => null,
3265          P_ATTRIBUTE1 => null,
3266          P_ATTRIBUTE2 => null,
3267          P_ATTRIBUTE3 => null,
3268          P_ATTRIBUTE4 => null,
3269          P_ATTRIBUTE5 => null,
3270          P_ATTRIBUTE6 => null,
3271          P_ATTRIBUTE7 => null,
3272          P_ATTRIBUTE8 => null,
3273          P_ATTRIBUTE9 => null,
3274          P_ATTRIBUTE10 => null,
3275          P_ATTRIBUTE11 => null,
3276          P_ATTRIBUTE12 => null,
3277          P_ATTRIBUTE13 => null,
3278          P_ATTRIBUTE14 => null,
3279          P_ATTRIBUTE15 => null,
3280          P_ATTRIBUTE_CATEGORY => null,
3281          P_PARTY_ID => x_party_id,
3282          P_PROGRAM_LOGIN_ID => null,
3283          P_PARTY_TYPE_CODE => 'THIRD_PARTY',
3284          P_SUPPLIER_FLAG => null,
3285          P_CUSTOMER_FLAG => null,
3286          P_SITE_FLAG => null,
3287          P_PROCESS_FOR_APPLICABILITY_FL => null,
3288          P_ROUNDING_LEVEL_CODE => null,
3289          P_ROUNDING_RULE_CODE => null,
3290          P_WITHHOLDING_START_DATE => null,
3291          P_INCLUSIVE_TAX_FLAG => null,
3292          P_ALLOW_AWT_FLAG => null,
3293          P_USE_LE_AS_SUBSCRIBER_FLAG => null,
3294          P_LEGAL_ESTABLISHMENT_FLAG => null,
3295          P_FIRST_PARTY_LE_FLAG => null,
3296          P_REPORTING_AUTHORITY_FLAG => null,
3297          X_RETURN_STATUS => l_return_status,
3298          P_REGISTRATION_TYPE_CODE => null,--4742586
3299          P_COUNTRY_CODE => null--4742586
3300          );
3301         IF l_return_status <> fnd_api.g_ret_sts_success THEN
3302           RAISE FND_API.G_EXC_ERROR;
3303         END IF;
3304       END IF;
3305 
3306     ELSE -- p_create_update_flag = 'U'
3307 
3308       -- Debug info.
3309       /*IF g_debug THEN
3310         hz_utility_v2pub.debug (
3311           'hz_parties_pkg.Update_Row (+)',l_debug_prefix);
3312       END IF;
3313       */
3314       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
3315         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'hz_parties_pkg.Update_Row (+)',
3316                                p_msg_level=>fnd_log.level_procedure);
3317       END IF;
3318 
3319       if (l_party_rec.orig_system is not null
3320          and l_party_rec.orig_system <>fnd_api.g_miss_char)
3321         and (l_party_rec.orig_system_reference is not null
3322          and l_party_rec.orig_system_reference <>fnd_api.g_miss_char)
3323       then
3324                 l_party_rec.orig_system_reference := null;
3325                 -- In mosr, we have bypassed osr nonupdateable validation
3326                 -- but we should not update existing osr, set it to null
3327       end if;
3328       -- call table handler to update the record
3329       hz_parties_pkg.update_row (
3330         x_rowid                                 => l_rowid,
3331         x_party_id                              => l_party_rec.party_id,
3332         x_party_number                          => l_party_rec.party_number,
3333         x_party_name                            => l_party_name,
3334         x_party_type                            => p_party_type,
3335         x_validated_flag                        => l_party_rec.validated_flag,
3336         x_attribute_category                    => l_party_rec.attribute_category,
3337         x_attribute1                            => l_party_rec.attribute1,
3338         x_attribute2                            => l_party_rec.attribute2,
3339         x_attribute3                            => l_party_rec.attribute3,
3340         x_attribute4                            => l_party_rec.attribute4,
3341         x_attribute5                            => l_party_rec.attribute5,
3342         x_attribute6                            => l_party_rec.attribute6,
3343         x_attribute7                            => l_party_rec.attribute7,
3344         x_attribute8                            => l_party_rec.attribute8,
3345         x_attribute9                            => l_party_rec.attribute9,
3346         x_attribute10                           => l_party_rec.attribute10,
3347         x_attribute11                           => l_party_rec.attribute11,
3348         x_attribute12                           => l_party_rec.attribute12,
3349         x_attribute13                           => l_party_rec.attribute13,
3350         x_attribute14                           => l_party_rec.attribute14,
3351         x_attribute15                           => l_party_rec.attribute15,
3352         x_attribute16                           => l_party_rec.attribute16,
3353         x_attribute17                           => l_party_rec.attribute17,
3354         x_attribute18                           => l_party_rec.attribute18,
3355         x_attribute19                           => l_party_rec.attribute19,
3356         x_attribute20                           => l_party_rec.attribute20,
3357         x_attribute21                           => l_party_rec.attribute21,
3358         x_attribute22                           => l_party_rec.attribute22,
3359         x_attribute23                           => l_party_rec.attribute23,
3360         x_attribute24                           => l_party_rec.attribute24,
3361         x_orig_system_reference                 => l_party_rec.orig_system_reference,
3362         x_sic_code                              => l_party_dup_rec.sic_code,
3363         x_hq_branch_ind                         => l_party_dup_rec.hq_branch_ind,
3364         x_customer_key                          => l_customer_key,
3365         x_tax_reference                         => l_party_dup_rec.tax_reference,
3366         x_jgzz_fiscal_code                      => l_party_dup_rec.jgzz_fiscal_code,
3367         x_person_pre_name_adjunct               => l_party_dup_rec.pre_name_adjunct,
3368         x_person_first_name                     => l_party_dup_rec.first_name,
3369         x_person_middle_name                    => l_party_dup_rec.middle_name,
3370         x_person_last_name                      => l_party_dup_rec.last_name,
3371         x_person_name_suffix                    => l_party_dup_rec.name_suffix,
3372         x_person_title                          => l_party_dup_rec.title,
3373         x_person_academic_title                 => l_party_dup_rec.academic_title,
3374         x_person_previous_last_name             => l_party_dup_rec.previous_last_name,
3375         x_known_as                              => l_party_dup_rec.known_as,
3376         x_person_iden_type                      => l_party_dup_rec.person_iden_type,
3377         x_person_identifier                     => l_party_dup_rec.person_identifier,
3378         x_group_type                            => p_group_rec.group_type,
3379         x_country                               => null,
3380         x_address1                              => null,
3381         x_address2                              => null,
3382         x_address3                              => null,
3383         x_address4                              => null,
3384         x_city                                  => null,
3385         x_postal_code                           => null,
3386         x_state                                 => null,
3387         x_province                              => null,
3388         x_status                                => l_party_rec.status,
3389         x_county                                => null,
3390         x_sic_code_type                         => l_party_dup_rec.sic_code_type,
3391         x_url                                   => null,
3392         x_email_address                         => null,
3393         x_analysis_fy                           => l_party_dup_rec.analysis_fy,
3394         x_fiscal_yearend_month                  => l_party_dup_rec.fiscal_yearend_month,
3395         x_employees_total                       => l_party_dup_rec.employees_total,
3396         x_curr_fy_potential_revenue             => l_party_dup_rec.curr_fy_potential_revenue,
3397         x_next_fy_potential_revenue             => l_party_dup_rec.next_fy_potential_revenue,
3398         x_year_established                      => l_party_dup_rec.year_established,
3399         x_gsa_indicator_flag                    => l_party_dup_rec.gsa_indicator_flag,
3400         x_mission_statement                     => l_party_dup_rec.mission_statement,
3401         x_organization_name_phonetic            => l_party_dup_rec.organization_name_phonetic,
3402         x_person_first_name_phonetic            => l_party_dup_rec.person_first_name_phonetic,
3403         x_person_last_name_phonetic             => l_party_dup_rec.person_last_name_phonetic,
3404         x_language_name                         => null,
3405         x_category_code                         => l_party_rec.category_code,
3406         x_salutation                            => l_party_rec.salutation,
3407         x_known_as2                             => l_party_dup_rec.known_as2,
3408         x_known_as3                             => l_party_dup_rec.known_as3,
3409         x_known_as4                             => l_party_dup_rec.known_as4,
3410         x_known_as5                             => l_party_dup_rec.known_as5,
3411         x_object_version_number                 => p_party_object_version_number,
3412         x_duns_number_c                         => l_party_dup_rec.duns_number_c,
3413         x_created_by_module                     => l_party_dup_rec.created_by_module,
3414         x_application_id                        => l_party_dup_rec.application_id
3415       );
3416 
3417       --Bug 1417600: Update party name for parties of type RELATIONSHIP
3418       --when subject or ojbect party's name has been changed.
3419 
3420       IF l_party_name IS NOT NULL AND
3421          l_party_name <> FND_API.G_MISS_CHAR AND
3422          l_party_name <> NVL(db_party_name, FND_API.G_MISS_CHAR)
3423       THEN
3424          do_update_party_rel_name(l_party_rec.party_id, l_party_name);
3425       END IF;
3426 
3427       -- Debug info.
3428       /*IF g_debug THEN
3429         hz_utility_v2pub.debug (
3430           'hz_parties_pkg.Update_Row (-)',l_debug_prefix);
3431       END IF;
3432       */
3433       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
3434         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'hz_parties_pkg.Update_Row (-)',
3435                                p_msg_level=>fnd_log.level_procedure);
3436       END IF;
3437 
3438 --  Bug 4490715 : If party is PERSON / ORGANIZATION call eTax
3439 --                procedure to populate ZX_PARTY_TAX_PROFILE
3440 --                Call only when tax_reference is not NULL
3441       IF l_party_dup_rec.tax_reference IS NOT NULL THEN
3442       IF p_party_type IN ('PERSON', 'ORGANIZATION') THEN
3443         BEGIN
3444 --  Get PARTY_TAX_PROFILE_ID to pass to update procedure
3445           SELECT PARTY_TAX_PROFILE_ID INTO L_PARTY_TAX_PROFILE_ID
3446           FROM ZX_PARTY_TAX_PROFILE
3447           WHERE PARTY_ID = p_party_id
3448           AND PARTY_TYPE_CODE = 'THIRD_PARTY'
3449           AND ROWNUM = 1;
3450         EXCEPTION
3451           WHEN NO_DATA_FOUND THEN
3452             fnd_message.set_name('AR', 'HZ_API_NO_RECORD');
3453             fnd_message.set_token('RECORD', 'ZX_PARTY_TAX_PROFILE');
3454             fnd_message.set_token('VALUE', to_char(p_party_id) || ', THIRD_PARTY');
3455             fnd_msg_pub.add;
3456             RAISE FND_API.G_EXC_ERROR;
3457         END;
3458 
3459         ZX_PARTY_TAX_PROFILE_PKG.update_row (
3460          P_PARTY_TAX_PROFILE_ID => L_PARTY_TAX_PROFILE_ID,
3461          P_COLLECTING_AUTHORITY_FLAG => null,
3462          P_PROVIDER_TYPE_CODE => null,
3463          P_CREATE_AWT_DISTS_TYPE_CODE => null,
3464          P_CREATE_AWT_INVOICES_TYPE_COD => null,
3465          P_TAX_CLASSIFICATION_CODE => null,
3466          P_SELF_ASSESS_FLAG => null,
3467          P_ALLOW_OFFSET_TAX_FLAG => null,
3468          P_REP_REGISTRATION_NUMBER => l_party_dup_rec.tax_reference,
3469          P_EFFECTIVE_FROM_USE_LE => null,
3470          P_RECORD_TYPE_CODE => null,
3471          P_REQUEST_ID => null,
3472          P_ATTRIBUTE1 => null,
3473          P_ATTRIBUTE2 => null,
3474          P_ATTRIBUTE3 => null,
3475          P_ATTRIBUTE4 => null,
3476          P_ATTRIBUTE5 => null,
3477          P_ATTRIBUTE6 => null,
3478          P_ATTRIBUTE7 => null,
3479          P_ATTRIBUTE8 => null,
3480          P_ATTRIBUTE9 => null,
3481          P_ATTRIBUTE10 => null,
3482          P_ATTRIBUTE11 => null,
3483          P_ATTRIBUTE12 => null,
3484          P_ATTRIBUTE13 => null,
3485          P_ATTRIBUTE14 => null,
3486          P_ATTRIBUTE15 => null,
3487          P_ATTRIBUTE_CATEGORY => null,
3488          P_PARTY_ID => null,
3489          P_PROGRAM_LOGIN_ID => null,
3490          P_PARTY_TYPE_CODE => null,
3491          P_SUPPLIER_FLAG => null,
3492          P_CUSTOMER_FLAG => null,
3493          P_SITE_FLAG => null,
3494          P_PROCESS_FOR_APPLICABILITY_FL => null,
3495          P_ROUNDING_LEVEL_CODE => null,
3496          P_ROUNDING_RULE_CODE => null,
3497          P_WITHHOLDING_START_DATE => null,
3498          P_INCLUSIVE_TAX_FLAG => null,
3499          P_ALLOW_AWT_FLAG => null,
3500          P_USE_LE_AS_SUBSCRIBER_FLAG => null,
3501          P_LEGAL_ESTABLISHMENT_FLAG => null,
3502          P_FIRST_PARTY_LE_FLAG => null,
3503          P_REPORTING_AUTHORITY_FLAG => null,
3504          X_RETURN_STATUS => l_return_status,
3505          P_REGISTRATION_TYPE_CODE => null,--4742586
3506          P_COUNTRY_CODE => null--4742586
3507          );
3508         IF l_return_status <> fnd_api.g_ret_sts_success THEN
3509           RAISE FND_API.G_EXC_ERROR;
3510         END IF;
3511       END IF;
3512       END IF;
3513     END IF;
3514 -- Making call to iprocurement if party name is updated for supplier usage. Bug No.4444588
3515 IF p_create_update_flag = 'U' THEN
3516     DECLARE
3517        l_party_usage_code VARCHAR2(30);
3518        l_temp VARCHAR2(2):= '';
3519        l_return_status VARCHAR2(2000);
3520 
3521      BEGIN
3522         IF p_party_type = 'ORGANIZATION'
3523            AND p_organization_rec.organization_name <> p_old_organization_rec.organization_name THEN
3524               SELECT 'Y' INTO l_temp FROM hz_party_usg_assignments WHERE party_id=p_party_id AND party_usage_code='SUPPLIER'
3525               AND ROWNUM=1;
3526               IF l_temp ='Y' THEN
3527                 ICX_CAT_POPULATE_ITEM_GRP.populateVendorNameChanges
3528                         (
3529                          P_API_VERSION       => 1.0,
3530                          P_COMMIT            => FND_API.G_FALSE,
3531                          P_INIT_MSG_LIST     => FND_API.G_FALSE,
3532                          P_VALIDATION_LEVEL  => FND_API.G_VALID_LEVEL_FULL,
3533                          X_RETURN_STATUS     => l_return_status,
3534                          P_VENDOR_ID          => p_party_id ,
3535                          P_VENDOR_NAME        => p_organization_rec.organization_name
3536                          ) ;
3537               END IF;
3538         END IF;
3539 
3540      EXCEPTION
3541         WHEN OTHERS THEN NULL;
3542 
3543      END;
3544 END IF;
3545 ------------------------------------------Bug 4444588
3546 
3547 
3548 
3549 
3550 
3551     -- Debug info.
3552     /*IF g_debug THEN
3553       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_create_update_party_only (-)');
3554     END IF;
3555     */
3556     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
3557         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_create_update_party_only (-)',
3558                                p_msg_level=>fnd_log.level_procedure);
3559     END IF;
3560 
3561 
3562   EXCEPTION
3563     WHEN g_resource_busy THEN
3564       fnd_message.set_name('AR', 'HZ_API_RECORD_CHANGED');
3565       fnd_message.set_token('TABLE', 'hz_parties');
3566       fnd_msg_pub.add;
3567       RAISE fnd_api.g_exc_error;
3568 
3569   END do_create_update_party_only;
3570 
3571   /**
3572    * PRIVATE PROCEDURE do_create_party
3573    *
3574    * DESCRIPTION
3575    *     Creates party.
3576    *
3577    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
3578    *     hz_parties_pkg.Insert_Row
3579    *
3580    * ARGUMENTS
3581    *     IN:
3582    *       p_party_type
3583    *     OUT:
3584    *       x_party_id
3585    *       x_party_number
3586    *       x_profile_id
3587    *     IN/ OUT:
3588    *       p_person_rec
3589    *       p_organization_rec
3590    *       p_group_rec
3591    *       x_return_status
3592    *
3593    * NOTES
3594    *
3595    * MODIFICATION HISTORY
3596    *   02-21-2002    Chris Saulit        o Modify to use new name formatting.
3597    *                                       Base Bug #2221071
3598    *   04-Mar-2003   Porkodi C           o Bug 2794173, Default value will be assigned to deceased_flag
3599    *                                       depending on the date_of_death value.
3600    *   26-Sep-2003   Rajib Ranjan Borah  o Bug Number 3099624.Sensitive HR data will not
3601    *                                       be inserted into HZ_PERSON_PROFILES table.
3602    *   02-APR-2004   Rajib Ranjan Borah  o Bug 3317806. If local_activity_code is invalid with respect
3603    *                                       to the position of the decimal point, replace this with
3604    *                                       the correct value from fnd_lookup_values provided that the
3605    *                                       actual_content_source for this record is not 'USER_ENTERED'.
3606    *   31-DEC-2004   Rajib Ranjan Borah  o SSM SST Integration and Extension.
3607    *                                       Call HZ_MIXNM_UTILITY.create_exceptions if actual_content_source
3608    *                                       is some third party content source and no prior profile exists..
3609    */
3610 
3611   PROCEDURE do_create_party(
3612     p_party_type                       IN     VARCHAR2,
3613     p_party_usage_code                 IN     VARCHAR2,
3614     p_person_rec                       IN OUT NOCOPY PERSON_REC_TYPE,
3615     p_organization_rec                 IN OUT NOCOPY ORGANIZATION_REC_TYPE,
3616     p_group_rec                        IN OUT NOCOPY GROUP_REC_TYPE,
3617     x_party_id                         OUT    NOCOPY NUMBER,
3618     x_party_number                     OUT    NOCOPY VARCHAR2,
3619     x_profile_id                       OUT    NOCOPY NUMBER,
3620     x_return_status                    IN OUT NOCOPY VARCHAR2
3621   ) IS
3622 
3623     l_sst_person_rec                   PERSON_REC_TYPE;
3624     l_new_sst_person_rec               PERSON_REC_TYPE;
3625     l_sst_organization_rec             ORGANIZATION_REC_TYPE;
3626     l_new_sst_organization_rec         ORGANIZATION_REC_TYPE;
3627 
3628     l_party_id                         NUMBER;
3629     l_party_number                     HZ_PARTIES.PARTY_NUMBER%TYPE;
3630     l_content_source_type              VARCHAR2(30);
3631     l_actual_content_source            VARCHAR2(30);
3632     l_data_source_type                 VARCHAR2(30);
3633     l_data_source_from                 VARCHAR2(30);
3634     l_profile_id                       NUMBER;
3635     l_party_object_version_number      NUMBER;
3636 
3637     l_datasource_selected              VARCHAR2(1) := 'N';
3638     l_mixnmatch_enabled                VARCHAR2(1);
3639     l_selected_datasources             VARCHAR2(600);
3640     l_create_update_sst_flag           VARCHAR2(1) := 'C';
3641     l_party_create_update_flag         VARCHAR2(1);
3642 
3643     l_debug_prefix                     VARCHAR2(30);
3644     l_party_usg_assignment_rec         HZ_PARTY_USG_ASSIGNMENT_PVT.party_usg_assignment_rec_type;
3645     l_msg_count                        NUMBER;
3646     l_msg_data                         VARCHAR2(2000);
3647   ------------------------Bug No. 4586451
3648     l_validation_level                 NUMBER;
3649   ------------------------------Bug No.4586451
3650   BEGIN
3651 
3652     -- Debug info.
3653     /*IF g_debug THEN
3654       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_create_party (+)');
3655     END IF;
3656     */
3657     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
3658         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_create_party (+)',
3659                                p_msg_level=>fnd_log.level_procedure);
3660      END IF;
3661 
3662     -- assign party record and find the data source.
3663 
3664     IF p_party_type = 'PERSON' THEN
3665 
3666       l_party_id := p_person_rec.party_rec.party_id;
3667 
3668       -- Find the real data source
3669 
3670       l_data_source_type :=
3671         HZ_MIXNM_UTILITY.FindDataSource (
3672           p_content_source_type           => p_person_rec.content_source_type,
3673           p_actual_content_source         => p_person_rec.actual_content_source,
3674           p_def_actual_content_source     => G_SST_SOURCE_TYPE,
3675           x_data_source_from              => l_data_source_from );
3676 
3677       --2794173, Setting the default value for the deceased_flag
3678       IF (p_person_rec.deceased_flag  is NULL or p_person_rec.deceased_flag = fnd_api.g_miss_char) then
3679          IF (p_person_rec.date_of_death is NULL or p_person_rec.date_of_death = fnd_api.g_miss_date) then
3680             p_person_rec.deceased_flag := 'N';
3681          ELSE
3682             p_person_rec.deceased_flag := 'Y';
3683          END IF;
3684       END IF;
3685 
3686     --Bug Number 3099624.
3687     --If the profile option 'HZ_PROTECT_HR_PERSON_INFO' is set to 'Y',then ,sensitive
3688     --information like gender,marital status,date of birth and place of birth will not
3689     --be propagated into HZ_PERSON_PROFILES.
3690     IF  (p_person_rec.party_rec.orig_system_reference LIKE 'PER%')
3691                                 AND
3692         (FND_PROFILE.VALUE('HZ_CREATED_BY_MODULE')LIKE '%HR API%')
3693                                 AND
3694         (fnd_profile.value('HZ_PROTECT_HR_PERSON_INFO')='Y')
3695     THEN
3696         p_person_rec.gender         := NULL;
3697         p_person_rec.marital_status := NULL;
3698         p_person_rec.date_of_birth  := NULL;
3699         p_person_rec.place_of_birth := NULL;
3700     END IF;
3701     --End of code added for Bug Number 3099624
3702 
3703       -- Validate person record.
3704 
3705       HZ_registry_validate_v2pub.validate_person(
3706         'C', p_person_rec, G_MISS_PERSON_REC, x_return_status);
3707 
3708       IF x_return_status <> fnd_api.g_ret_sts_success THEN
3709         RAISE FND_API.G_EXC_ERROR;
3710       END IF;
3711 
3712       l_mixnmatch_enabled := g_per_mixnmatch_enabled;
3713       l_selected_datasources := g_per_selected_datasources;
3714 
3715     ELSIF p_party_type = 'ORGANIZATION' THEN
3716 
3717       l_party_id := p_organization_rec.party_rec.party_id;
3718 
3719 
3720       -- Find the real data source
3721 
3722       l_data_source_type :=
3723         HZ_MIXNM_UTILITY.FindDataSource(
3724           p_content_source_type           => p_organization_rec.content_source_type,
3725           p_actual_content_source         => p_organization_rec.actual_content_source,
3726           p_def_actual_content_source     => G_SST_SOURCE_TYPE,
3727           x_data_source_from              => l_data_source_from );
3728 
3729 
3730       -- Validate organization record.
3731 
3732       HZ_registry_validate_v2pub.validate_organization(
3733         'C', p_organization_rec, G_MISS_ORGANIZATION_REC, x_return_status);
3734 
3735       IF x_return_status <> fnd_api.g_ret_sts_success THEN
3736         RAISE FND_API.G_EXC_ERROR;
3737       END IF;
3738 
3739 
3740       -- Bug 3317806 For non user entered data ( actual_content_source <> 'USER_ENTERED' ) ,
3741       -- if local_activity_code_type = 'NACE' and the local_activity_code is invalid with
3742       -- respect to the position of the decimal point, then replace this with the valid value.
3743       IF p_organization_rec.actual_content_source <> 'USER_ENTERED' AND
3744          p_organization_rec.local_activity_code_type in ( 'NACE' ,'4', '5') AND
3745          p_organization_rec.local_activity_code IS NOT NULL
3746       THEN
3747           SELECT lookup_code
3748           INTO   p_organization_rec.local_activity_code
3749           FROM   FND_LOOKUP_VALUES
3750           WHERE  lookup_type = 'NACE'
3751             AND  replace (lookup_code,'.','') = replace (p_organization_rec.local_activity_code,'.','')
3752             AND  rownum = 1;
3753           -- No need to handle no_data_found as this validation is already done in HZ_REGISTRY_VALIDATE_V2PUB.
3754       END IF;
3755 
3756 
3757       l_mixnmatch_enabled := g_org_mixnmatch_enabled;
3758       l_selected_datasources := g_org_selected_datasources;
3759 
3760     ELSIF p_party_type = 'GROUP' THEN
3761       IF p_group_rec.party_rec.party_id IS NOT NULL AND
3762          p_group_rec.party_rec.party_id <> FND_API.G_MISS_NUM AND
3763          party_exists(p_party_type, p_group_rec.party_rec.party_id, l_party_number) = 'Y'
3764       THEN
3765         fnd_message.set_name('AR', 'HZ_API_DUPLICATE_COLUMN');
3766         fnd_message.set_token('COLUMN', 'party_id');
3767         fnd_msg_pub.add;
3768         RAISE FND_API.G_EXC_ERROR;
3769       END IF;
3770 
3771       -- Validate group record.
3772 
3773       HZ_registry_validate_v2pub.validate_group(
3774         'C', p_group_rec, G_MISS_GROUP_REC, x_return_status);
3775 
3776       IF x_return_status <> fnd_api.g_ret_sts_success THEN
3777         RAISE FND_API.G_EXC_ERROR;
3778       END IF;
3779 
3780       -- Create group party.
3781 
3782       do_create_update_party_only(
3783         p_create_update_flag             => 'C',
3784         p_party_type                     => p_party_type,
3785         p_group_rec                      => p_group_rec,
3786         x_party_id                       => x_party_id,
3787         x_party_number                   => x_party_number,
3788         p_party_object_version_number    => l_party_object_version_number);
3789     END IF;
3790 
3791     IF p_party_type IN ('PERSON', 'ORGANIZATION') THEN
3792 
3793       -- Debug info.
3794       /*IF g_debug THEN
3795         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'l_mixnmatch_enabled = '||l_mixnmatch_enabled);
3796         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'l_selected_datasources = '||l_selected_datasources);
3797       END IF;
3798       */
3799       IF fnd_log.level_statement>=fnd_log.g_current_runtime_level THEN
3800         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'l_mixnmatch_enabled = '||l_mixnmatch_enabled,
3801                                p_msg_level=>fnd_log.level_statement);
3802         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'l_selected_datasources = '||l_selected_datasources,
3803                                p_msg_level=>fnd_log.level_statement);
3804       END IF;
3805 
3806       -- If data source is SST or user-entered, we need to check if the party exist.
3807       -- If party exists, error out. Otherwise, create the SST profile and new party.
3808 
3809       IF l_data_source_type = G_SST_SOURCE_TYPE OR
3810          l_data_source_type = G_MISS_CONTENT_SOURCE_TYPE
3811       THEN
3812         l_data_source_type := G_SST_SOURCE_TYPE;
3813 
3814         IF l_party_id IS NOT NULL AND
3815            l_party_id <> FND_API.G_MISS_NUM AND
3816            party_exists(p_party_type, l_party_id, l_party_number) = 'Y'
3817         THEN
3818           fnd_message.set_name('AR', 'HZ_API_DUPLICATE_COLUMN');
3819           fnd_message.set_token('COLUMN', 'party_id');
3820           fnd_msg_pub.add;
3821           RAISE FND_API.G_EXC_ERROR;
3822         END IF;
3823 
3824         -- party does not exist, create new party.
3825 
3826         l_party_create_update_flag := 'C';
3827 
3828         do_create_update_party_only(
3829           p_create_update_flag             => 'C',
3830           p_party_type                     => p_party_type,
3831           p_person_rec                     => p_person_rec,
3832           p_organization_rec               => p_organization_rec,
3833           x_party_id                       => x_party_id,
3834           x_party_number                   => x_party_number,
3835           p_party_object_version_number    => l_party_object_version_number);
3836 
3837         -- create a SST profile with content_source_type = user entered and
3838         -- actual_content_source = SST.
3839 
3840         l_actual_content_source := G_SST_SOURCE_TYPE;
3841         l_content_source_type := G_MISS_CONTENT_SOURCE_TYPE;
3842 
3843         do_create_party_profile(
3844           p_party_type                     => p_party_type,
3845           p_party_id                       => x_party_id,
3846           p_person_rec                     => p_person_rec,
3847           p_organization_rec               => p_organization_rec,
3848           p_content_source_type            => l_content_source_type,
3849           p_actual_content_source          => l_actual_content_source,
3850           x_profile_id                     => x_profile_id );
3851 /* Bug 4244112 : do not populate for just UE record
3852         IF l_mixnmatch_enabled = 'Y' THEN
3853                 HZ_MIXNM_UTILITY.populateMRRExc(
3854                         'HZ_'||p_party_type||'_PROFILES',
3855                         l_content_source_type,
3856                         x_party_id);
3857         END IF;
3858 */
3859       ELSE -- other third party data source
3860 
3861         -- find if data source is selected
3862 
3863         IF l_mixnmatch_enabled = 'Y' THEN
3864           l_datasource_selected :=
3865             HZ_MIXNM_UTILITY.isDataSourceSelected(
3866 -- Bug 4376604 : pass entity type
3867               p_party_type,
3868               l_data_source_type);
3869         END IF;
3870 
3871         -- Debug info.
3872         /*IF g_debug THEN
3873           hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'l_datasource_selected = '||l_datasource_selected);
3874         END IF;
3875         */
3876         IF fnd_log.level_statement>=fnd_log.g_current_runtime_level THEN
3877            hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'l_datasource_selected = '||l_datasource_selected,
3878                                p_msg_level=>fnd_log.level_statement);
3879         END IF;
3880 
3881         -- Error out NOCOPY if the profile with this data source already exists.
3882 
3883         IF l_party_id IS NOT NULL AND
3884            l_party_id <> FND_API.G_MISS_NUM AND
3885            party_exists(p_party_type, l_party_id, l_party_number) = 'Y'
3886         THEN
3887           IF party_profile_exists(
3888                p_party_type, l_party_id, l_data_source_type) = 'Y'
3889           THEN
3890             fnd_message.set_name('AR', 'HZ_API_DUPLICATE_COLUMN');
3891             fnd_message.set_token('COLUMN', 'party_id,'||l_data_source_from);
3892             fnd_msg_pub.add;
3893             RAISE FND_API.G_EXC_ERROR;
3894           ELSE
3895             x_party_id := l_party_id;
3896             x_party_number := l_party_number;
3897           END IF;
3898         ELSE  -- party does not exist
3899 
3900           -- if mix-n-match is enabled and the data source is a ranked
3901           -- data source, we are going to create 3 profiles: user-entered,
3902           -- SST and third party profile. We first create a user-entered
3903           -- profile with content_source_type = 'USER_ENTERED' and
3904           -- actual_content_source = 'USER_ENTERED' using the third party
3905           -- record. This is to make sure that a party must have an user-entered
3906           -- profile. Otherwise, we are going to create 2 profiles: SST and
3907           -- third party profile. We first create a SST profile with
3908           -- content_source_type = 'USER_ENTERED' and actual_content_source = 'SST'.
3909 
3910           -- create a new party.
3911 
3912           l_party_create_update_flag := 'C';
3913 
3914           do_create_update_party_only(
3915             p_create_update_flag             => 'C',
3916             p_party_type                     => p_party_type,
3917             p_person_rec                     => p_person_rec,
3918             p_organization_rec               => p_organization_rec,
3919             x_party_id                       => x_party_id,
3920             x_party_number                   => x_party_number,
3921             p_party_object_version_number    => l_party_object_version_number);
3922 
3923           -- create user-entered / SST profile.
3924 
3925           l_content_source_type := G_MISS_CONTENT_SOURCE_TYPE;
3926           IF l_mixnmatch_enabled = 'Y' /*AND
3927              l_datasource_selected = 'Y'*/
3928           THEN
3929             l_actual_content_source := G_MISS_CONTENT_SOURCE_TYPE;
3930           ELSE
3931             l_actual_content_source := G_SST_SOURCE_TYPE;
3932           END IF;
3933 
3934           do_create_party_profile(
3935             p_party_type                     => p_party_type,
3936             p_party_id                       => x_party_id,
3937             p_person_rec                     => p_person_rec,
3938             p_organization_rec               => p_organization_rec,
3939             p_content_source_type            => l_content_source_type,
3940             p_actual_content_source          => l_actual_content_source,
3941             x_profile_id                     => l_profile_id );
3942 
3943         END IF;
3944 
3945         -- create a third party profile with both content_source_type and
3946         -- actual_content_source are third party data source.
3947 
3948         l_content_source_type := l_data_source_type;
3949         l_actual_content_source := l_data_source_type;
3950 
3951         do_create_party_profile (
3952           p_party_type                       => p_party_type,
3953           p_party_id                         => x_party_id,
3954           p_person_rec                       => p_person_rec,
3955           p_organization_rec                 => p_organization_rec,
3956           p_content_source_type              => l_content_source_type,
3957           p_actual_content_source            => l_actual_content_source,
3958           x_profile_id                       => x_profile_id );
3959 
3960         -- If mix-n-match is enabled and the third party data source is
3961         -- ranked, generate SST profile based on the setup.
3962 
3963         IF l_mixnmatch_enabled = 'Y' THEN
3964 
3965           -- The SST profile will have content_source_type = 'USER_ENTERED'
3966           -- and actual_content_source = 'SST'.
3967 
3968           l_actual_content_source := G_SST_SOURCE_TYPE;
3969           l_content_source_type := G_MISS_CONTENT_SOURCE_TYPE;
3970 
3971           -- if a new party was created, we do not need to generate SST profile
3972           -- because the SST = user-entered = third party profile.
3973           -- We only need to create a SST profile based on the record.
3974 
3975           IF l_party_create_update_flag = 'C' THEN
3976             do_create_party_profile (
3977               p_party_type                       => p_party_type,
3978               p_party_id                         => x_party_id,
3979               p_person_rec                       => p_person_rec,
3980               p_organization_rec                 => p_organization_rec,
3981               p_content_source_type              => l_content_source_type,
3982               p_actual_content_source            => l_actual_content_source,
3983               x_profile_id                       => l_profile_id );
3984 
3985             -- SSM SST Integration and Extension
3986             HZ_MIXNM_UTILITY.create_exceptions (
3987               p_party_type                       => p_party_type,
3988               p_organization_rec                 => p_organization_rec,
3989               p_person_rec                       => p_person_rec,
3990               p_third_party_content_source       => l_data_source_type,
3991               p_party_id                         => x_party_id);
3992 
3993                 HZ_MIXNM_UTILITY.populateMRRExc(
3994                         'HZ_'||p_party_type||'_PROFILES',
3995                         l_data_source_type,
3996                         x_party_id);
3997           ELSE -- need to generate SST profile.
3998 
3999             -- get SST profile
4000 
4001             do_get_party_profile (
4002               p_party_type                       => p_party_type,
4003               p_party_id                         => x_party_id,
4004               p_data_source_type                 => G_SST_SOURCE_TYPE,
4005               x_person_rec                       => l_sst_person_rec,
4006               x_organization_rec                 => l_sst_organization_rec );
4007 
4008             -- check if the party has user-entered profile. If the function
4009             -- return 'Y', means this is the first time we purchase third party
4010             -- for this party and we should create a SST profile. Otherwise, we
4011             -- have to update the existing SST.
4012 
4013             IF reset_sst_to_userentered(p_party_type, x_party_id) = 'Y' THEN
4014               l_create_update_sst_flag := 'C';
4015               l_new_sst_person_rec := l_sst_person_rec;
4016               l_new_sst_organization_rec := l_sst_organization_rec;
4017         -- Bug 4244112 : populate when first third party profile is created
4018                 HZ_MIXNM_UTILITY.populateMRRExc(
4019                         'HZ_'||p_party_type||'_PROFILES',
4020                         l_data_source_type,
4021                         x_party_id);
4022             ELSE
4023               l_create_update_sst_flag := 'U';
4024 
4025               -- SSM SST Integration and Extension
4026 
4027               l_new_sst_person_rec.party_rec.party_id := x_party_id;
4028               l_new_sst_organization_rec.party_rec.party_id := x_party_id;
4029 
4030             END IF;
4031 
4032             IF l_datasource_selected = 'Y' THEN
4033               -- return SST record which we need to use either
4034               -- generate a SST profile or update an existing SST profile.
4035 
4036               HZ_MIXNM_UTILITY.updateSSTProfile(
4037                 p_create_update_flag         => 'C',
4038                 p_create_update_sst_flag     => l_create_update_sst_flag,
4039                 p_raise_error_flag           => 'N',
4040                 p_party_type                 => p_party_type,
4041                 p_party_id                   => x_party_id,
4042                 p_new_person_rec             => p_person_rec,
4043                 p_sst_person_rec             => l_sst_person_rec,
4044                 p_new_sst_person_rec         => l_new_sst_person_rec,
4045                 p_new_organization_rec       => p_organization_rec,
4046                 p_sst_organization_rec       => l_sst_organization_rec,
4047                 p_new_sst_organization_rec   => l_new_sst_organization_rec,
4048                 p_data_source_type           => l_data_source_type,
4049                 x_return_status              => x_return_status );
4050 
4051               IF x_return_status <> fnd_api.g_ret_sts_success THEN
4052                 RAISE FND_API.G_EXC_ERROR;
4053               END IF;
4054             END IF;
4055 
4056             -- Create SST profile.
4057 
4058             IF l_create_update_sst_flag = 'C' THEN
4059               do_create_party_profile (
4060                 p_party_type                       => p_party_type,
4061                 p_party_id                         => x_party_id,
4062                 p_person_rec                       => l_new_sst_person_rec,
4063                 p_organization_rec                 => l_new_sst_organization_rec,
4064                 p_content_source_type              => l_content_source_type,
4065                 p_actual_content_source            => l_actual_content_source,
4066                 x_profile_id                       => l_profile_id );
4067 
4068             ELSE  -- update SST profile.
4069               do_update_party_profile(
4070                 p_party_type                       => p_party_type,
4071                 p_person_rec                       => l_new_sst_person_rec,
4072                 p_old_person_rec                   => l_sst_person_rec,
4073                 p_organization_rec                 => l_new_sst_organization_rec,
4074                 p_old_organization_rec             => l_sst_organization_rec,
4075                 p_data_source_type                 => G_SST_SOURCE_TYPE,
4076                 x_profile_id                       => l_profile_id );
4077 
4078             END IF;
4079 
4080             -- denormalize SST to the party.
4081 
4082             l_party_create_update_flag := 'U';
4083 
4084             do_create_update_party_only(
4085               p_create_update_flag             => 'U',
4086               p_party_type                     => p_party_type,
4087               p_party_id                       => x_party_id,
4088               p_person_rec                     => l_new_sst_person_rec,
4089               p_old_person_rec                 => l_sst_person_rec,
4090               p_organization_rec               => l_new_sst_organization_rec,
4091               p_old_organization_rec           => l_sst_organization_rec,
4092               p_check_object_version_number    => 'N',
4093               p_party_object_version_number    => l_party_object_version_number,
4094               x_party_id                       => l_party_id,
4095               x_party_number                   => l_party_number);
4096           END IF;
4097         END IF;
4098       END IF;
4099     END IF;
4100 
4101     -- we need to pass some attributes back to person/organization/group record.
4102 
4103     IF p_party_type = 'PERSON' THEN
4104       p_person_rec.party_rec.party_id := x_party_id;
4105       p_person_rec.party_rec.party_number := x_party_number;
4106       p_person_rec.actual_content_source := l_data_source_type;
4107     ELSIF p_party_type = 'ORGANIZATION' THEN
4108       p_organization_rec.party_rec.party_id := x_party_id;
4109       p_organization_rec.party_rec.party_number := x_party_number;
4110       p_organization_rec.actual_content_source := l_data_source_type;
4111     ELSE -- group
4112       p_group_rec.party_rec.party_id := x_party_id;
4113       p_group_rec.party_rec.party_number := x_party_number;
4114       l_data_source_type := G_MISS_CONTENT_SOURCE_TYPE;
4115     END IF;
4116 
4117     -- process classification related attributes.
4118 
4119     do_process_classification(
4120       p_create_update_flag            => 'C',
4121       p_party_type                    => p_party_type,
4122       p_organization_rec              => p_organization_rec,
4123       p_old_organization_rec          => G_MISS_ORGANIZATION_REC,
4124       p_person_rec                    => p_person_rec,
4125       p_old_person_rec                => G_MISS_PERSON_REC,
4126       p_group_rec                     => p_group_rec,
4127       p_old_group_rec                 => G_MISS_GROUP_REC,
4128       p_data_source_type              => l_data_source_type,
4129       x_return_status                 => x_return_status );
4130 
4131     -- Invoke Business Event System (BES) and DQM
4132     -- BES and DQM will only be called when SST (i.e. party) is touched).
4133     -- We will pass SST info. into update event.
4134 
4135     IF l_party_create_update_flag IS NOT NULL THEN
4136       IF p_party_type = 'ORGANIZATION' THEN
4137 
4138         -- BES
4139 
4140         IF l_party_create_update_flag = 'C' THEN
4141           IF(HZ_UTILITY_V2PUB.G_EXECUTE_API_CALLOUTS in ('Y', 'EVENTS_ENABLED')) THEN
4142             HZ_BUSINESS_EVENT_V2PVT.create_organization_event(p_organization_rec);
4143           END IF;
4144 
4145           IF(HZ_UTILITY_V2PUB.G_EXECUTE_API_CALLOUTS in ('EVENTS_ENABLED', 'BO_EVENTS_ENABLED')) THEN
4146             -- populate function for integration service
4147             HZ_POPULATE_BOT_PKG.pop_hz_organization_profiles(
4148               p_operation               => 'I',
4149               p_organization_profile_id => x_profile_id);
4150           END IF;
4151         ELSE
4152           l_new_sst_organization_rec.party_rec.orig_system := p_organization_rec.party_rec.orig_system;
4153           l_sst_organization_rec.party_rec.orig_system := p_organization_rec.party_rec.orig_system;
4154           IF(HZ_UTILITY_V2PUB.G_EXECUTE_API_CALLOUTS in ('Y', 'EVENTS_ENABLED')) THEN
4155             HZ_BUSINESS_EVENT_V2PVT.update_organization_event(
4156               l_new_sst_organization_rec, l_sst_organization_rec);
4157           END IF;
4158 
4159           IF(HZ_UTILITY_V2PUB.G_EXECUTE_API_CALLOUTS in ('EVENTS_ENABLED', 'BO_EVENTS_ENABLED')) THEN
4160             -- populate function for integration service
4161             HZ_POPULATE_BOT_PKG.pop_hz_organization_profiles(
4162               p_operation               => 'U',
4163               p_organization_profile_id => x_profile_id);
4164           END IF;
4165         END IF;
4166 
4167         -- DQM
4168         --Bug 4866187
4169         --Bug 5370799
4170 	IF (p_organization_rec.party_rec.orig_system IS NULL OR
4171 	p_organization_rec.party_rec.orig_system=FND_API.G_MISS_CHAR )  THEN
4172 	HZ_DQM_SYNC.sync_org(x_party_id, l_party_create_update_flag);
4173         END IF;
4174       ELSIF p_party_type = 'PERSON' THEN
4175 
4176         -- BES
4177 
4178         IF l_party_create_update_flag = 'C' THEN
4179           IF(HZ_UTILITY_V2PUB.G_EXECUTE_API_CALLOUTS in ('Y', 'EVENTS_ENABLED')) THEN
4180             HZ_BUSINESS_EVENT_V2PVT.create_person_event(p_person_rec);
4181           END IF;
4182 
4183           IF(HZ_UTILITY_V2PUB.G_EXECUTE_API_CALLOUTS in ('EVENTS_ENABLED', 'BO_EVENTS_ENABLED')) THEN
4184             -- populate function for integration service
4185             HZ_POPULATE_BOT_PKG.pop_hz_person_profiles(
4186               p_operation         => 'I',
4187               p_person_profile_id => x_profile_id);
4188           END IF;
4189         ELSE
4190           l_new_sst_person_rec.party_rec.orig_system := p_person_rec.party_rec.orig_system;
4191           l_sst_person_rec.party_rec.orig_system := p_person_rec.party_rec.orig_system;
4192           IF(HZ_UTILITY_V2PUB.G_EXECUTE_API_CALLOUTS in ('Y', 'EVENTS_ENABLED')) THEN
4193             HZ_BUSINESS_EVENT_V2PVT.update_person_event(
4194               l_new_sst_person_rec, l_sst_person_rec);
4195           END IF;
4196 
4197           IF(HZ_UTILITY_V2PUB.G_EXECUTE_API_CALLOUTS in ('EVENTS_ENABLED', 'BO_EVENTS_ENABLED')) THEN
4198             -- populate function for integration service
4199             HZ_POPULATE_BOT_PKG.pop_hz_person_profiles(
4200               p_operation         => 'U',
4201               p_person_profile_id => x_profile_id);
4202           END IF;
4203         END IF;
4204 
4205         -- DQM
4206 	--Bug 4866187
4207         --Bug 5370799
4208         IF (p_person_rec.party_rec.orig_system IS NULL OR p_person_rec.party_rec.orig_system=FND_API.G_MISS_CHAR ) THEN
4209 	HZ_DQM_SYNC.sync_person(x_party_id, l_party_create_update_flag);
4210 	END IF;
4211 
4212       END IF;
4213     END IF;
4214 
4215     --
4216     -- added for R12 party usage project
4217     --
4218     IF p_party_type IN ('PERSON', 'ORGANIZATION') THEN
4219 
4220       -- set party usage code
4221 
4222       IF l_party_create_update_flag = 'C' THEN
4223         l_party_usg_assignment_rec.party_usage_code :=
4224             NVL(p_party_usage_code, fnd_profile.value('HZ_PARTY_USAGE_DEFAULT'));
4225       ELSE
4226         l_party_usg_assignment_rec.party_usage_code := p_party_usage_code;
4227       END IF;
4228 
4229       IF l_party_usg_assignment_rec.party_usage_code IS NOT NULL THEN
4230         l_party_usg_assignment_rec.party_id := x_party_id;
4231 
4232         -- per talk with Maria, we will create an active usage assignment
4233         -- no matter the party created is inactive or not. this is because
4234         -- we don't inactivate / reactivate usage assignments in update party
4235         -- api because we don't know who have end-date the usage assignments.
4236         -- all of queries should filter out party with status I before it goes
4237         -- to assignment table.
4238 
4239         -- set created by module
4240         IF p_party_type = 'PERSON' THEN
4241           l_party_usg_assignment_rec.created_by_module := p_person_rec.created_by_module;
4242         ELSE
4243           l_party_usg_assignment_rec.created_by_module := p_organization_rec.created_by_module;
4244         END IF;
4245 -------------------------Bug No. 4586451
4246 
4247      IF p_party_type = 'ORGANIZATION' THEN
4248         IF p_organization_rec.actual_content_source NOT IN (G_SST_SOURCE_TYPE,G_MISS_CONTENT_SOURCE_TYPE) THEN
4249             l_validation_level  := HZ_PARTY_USG_ASSIGNMENT_PVT.G_VALID_LEVEL_THIRD_MEDIUM ;
4250         ELSE
4251             l_validation_level :=HZ_PARTY_USG_ASSIGNMENT_PVT.G_VALID_LEVEL_MEDIUM;
4252         END IF;
4253      END IF;
4254 ------------------------Bug No. 4586451
4255 
4256 
4257 
4258 
4259         HZ_PARTY_USG_ASSIGNMENT_PVT.assign_party_usage (
4260           p_validation_level          => l_validation_level,
4261           p_party_usg_assignment_rec  => l_party_usg_assignment_rec,
4262           x_return_status             => x_return_status,
4263           x_msg_count                 => l_msg_count,
4264           x_msg_data                  => l_msg_data
4265         );
4266 
4267 
4268         IF x_return_status <> fnd_api.g_ret_sts_success THEN
4269           RAISE FND_API.G_EXC_ERROR;
4270         END IF;
4271       END IF;
4272     END IF;
4273 
4274     -- Debug info.
4275     /*IF g_debug THEN
4276       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_create_party (-)');
4277     END IF;
4278     */
4279     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
4280         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_create_party (-)',
4281                                p_msg_level=>fnd_log.level_procedure);
4282     END IF;
4283 
4284   END do_create_party;
4285 
4286   /**
4287    * PRIVATE PROCEDURE do_update_party
4288    *
4289    * DESCRIPTION
4290    *     Updates party.
4291    *
4292    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
4293    *     hz_parties_pkg.Update_Row
4294    *
4295    * ARGUMENTS
4296    *     IN:
4297    *       p_party_type
4298    *     OUT:
4299    *       x_profile_id
4300    *     IN/ OUT:
4301    *       p_person_rec
4302    *       p_old_person_rec
4303    *       p_organization_rec
4304    *       p_old_organization_rec
4305    *       p_group_rec
4306    *       p_party_object_version_number
4307    *       x_return_status
4308    *
4309    * NOTES
4310    *
4311    * MODIFICATION HISTORY
4312    *   02-21-2002    Chris Saulit        o Modify to use new name formatting.
4313    *                                       Base Bug #2221071
4314    *   04-Mar-2003   Porkodi C           o Bug 2794173, Default value will be assigned to deceased_flag
4315    *                                       depending on the date_of_death value.
4316    *   26-Sep-2003   Rajib Ranjan Borah  o Bug Number 3099624.Sensitive HR data will not
4317    *                                       be updated into HZ_PERSON_PROFILES table.
4318    *   02-APR-2004   Rajib Ranjan Borah  o Bug 3317806. If local_activity_code is invalid with respect
4319    *                                       to the position of the decimal point, replace this with
4320    *                                       the correct value from fnd_lookup_values provided that the
4321    *                                       actual_content_source for this record is not 'USER_ENTERED'.
4322    */
4323 
4324   PROCEDURE do_update_party (
4325     p_party_type                       IN     VARCHAR2,
4326     p_person_rec                       IN OUT NOCOPY PERSON_REC_TYPE,
4327     p_old_person_rec                   IN     PERSON_REC_TYPE := G_MISS_PERSON_REC,
4328     p_organization_rec                 IN OUT NOCOPY ORGANIZATION_REC_TYPE,
4329     p_old_organization_rec             IN     ORGANIZATION_REC_TYPE := G_MISS_ORGANIZATION_REC,
4330     p_group_rec                        IN OUT NOCOPY GROUP_REC_TYPE,
4331     p_old_group_rec                    IN     GROUP_REC_TYPE := G_MISS_GROUP_REC,
4332     p_party_object_version_number      IN OUT NOCOPY NUMBER,
4333     x_profile_id                       OUT    NOCOPY NUMBER,
4334     x_return_status                    IN OUT NOCOPY VARCHAR2
4335   ) IS
4336 
4337     l_sst_person_rec                   PERSON_REC_TYPE;
4338     l_new_sst_person_rec               PERSON_REC_TYPE;
4339     l_sst_organization_rec             ORGANIZATION_REC_TYPE;
4340     l_new_sst_organization_rec         ORGANIZATION_REC_TYPE;
4341     l_ue_person_rec                    PERSON_REC_TYPE;
4342     l_ue_organization_rec              ORGANIZATION_REC_TYPE;
4343 
4344     l_party_id                         NUMBER;
4345     l_party_number                     HZ_PARTIES.PARTY_NUMBER%TYPE;
4346     l_data_source_type                 VARCHAR2(30);
4347     l_profile_id                       NUMBER;
4348 
4349     l_user_entered_profile_exists      VARCHAR2(1);
4350     l_update_sst_profile               VARCHAR2(1) := 'N';
4351     l_update_party                     VARCHAR2(1) := 'N';
4352     l_datasource_selected              VARCHAR2(1);
4353     l_mixnmatch_enabled                VARCHAR2(1);
4354     l_selected_datasources             VARCHAR2(600);
4355     l_coming_data_source               VARCHAR2(30);
4356     l_raise_error                      VARCHAR2(1);
4357     l_dummy_id                         NUMBER;
4358 
4359     l_debug_prefix                     VARCHAR2(30);
4360 
4361     --Bug No:2771835----------------
4362     l_old_party_name                   HZ_PARTIES.PARTY_NAME%TYPE;
4363     l_new_party_name                   HZ_PARTIES.PARTY_NAME%TYPE;
4364     l_old_tax_reference                HZ_PARTIES.TAX_REFERENCE%TYPE;
4365     l_new_tax_reference                HZ_PARTIES.TAX_REFERENCE%TYPE;
4366     -------------Bug 4586451
4367     l_return_status                    VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
4368    -------------------------Bug No. 4586451
4369 
4370     CURSOR c_party_name(p_party_id NUMBER) IS
4371      SELECT party_name,tax_reference FROM HZ_PARTIES
4372      WHERE PARTY_ID=p_party_id;
4373 
4374     ---End of Bug No:2771835---------
4375 
4376   BEGIN
4377 
4378     -- Debug info.
4379     /*IF g_debug THEN
4380       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_update_party (+)');
4381     END IF;
4382     */
4383     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
4384         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_update_party (+)',
4385                                p_msg_level=>fnd_log.level_procedure);
4386     END IF;
4387 
4388     -- assign party record and find the data source.
4389 
4390     IF p_party_type = 'PERSON' THEN
4391 
4392       l_party_id := p_person_rec.party_rec.party_id;
4393       l_data_source_type := p_old_person_rec.actual_content_source;
4394 
4395       ------Bug No:2771835---------------
4396       OPEN  c_party_name(l_party_id);
4397       FETCH c_party_name INTO l_old_party_name,l_old_tax_reference;
4398       CLOSE c_party_name;
4399       ------End Bug No:2771835-----------
4400       -- 2794173, Setting the default value for the deceased_flag
4401       IF (p_person_rec.deceased_flag is NULL  and p_person_rec.date_of_death is not  NULL) then
4402           IF p_person_rec.date_of_death= FND_API.G_MISS_DATE then
4403              p_person_rec.deceased_flag := 'N';
4404 
4405           ELSE
4406              p_person_rec.deceased_flag := 'Y';
4407           END IF;
4408       END IF;
4409 
4410       IF (p_person_rec.deceased_flag = fnd_api.g_miss_char) then
4411           p_person_rec.deceased_flag := 'N';
4412       END IF;
4413 
4414       IF (p_person_rec.deceased_flag = 'N' and p_person_rec.date_of_death is null) then
4415          p_person_rec.date_of_death := fnd_api.g_miss_date;
4416       end if;
4417 
4418 
4419     --Bug Number 3099624.
4420     --If the profile option 'HZ_PROTECT_HR_PERSON_INFO'  is set to 'Y',then ,sensitive
4421     --information like gender,marital status,date of birth and place of birth will not
4422     --be updated into HZ_PERSON_PROFILES and the old values will be retained for these
4423     --columns.
4424     IF  (NVL(p_person_rec.party_rec.orig_system_reference,p_old_person_rec.party_rec.orig_system_reference) LIKE 'PER%')
4425                                 AND
4426         (FND_PROFILE.VALUE('HZ_CREATED_BY_MODULE')LIKE '%HR API%')
4427                                 AND
4428         (fnd_profile.value('HZ_PROTECT_HR_PERSON_INFO')='Y')
4429     THEN
4430         p_person_rec.gender         := NULL;
4431         p_person_rec.marital_status := NULL;
4432         p_person_rec.date_of_birth  := NULL;
4433         p_person_rec.place_of_birth := NULL;
4434     END IF;
4435     --End of code added for Bug Number 3099624.
4436 
4437 
4438 
4439       -- Validate person record.
4440 
4441       HZ_registry_validate_v2pub.validate_person(
4442         'U', p_person_rec, p_old_person_rec, x_return_status);
4443 
4444       IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4445         RAISE FND_API.G_EXC_ERROR;
4446       END IF;
4447 
4448       l_mixnmatch_enabled := g_per_mixnmatch_enabled;
4449       l_selected_datasources := g_per_selected_datasources;
4450 
4451     ELSIF p_party_type = 'ORGANIZATION' THEN
4452 
4453       l_party_id := p_organization_rec.party_rec.party_id;
4454       l_data_source_type := p_old_organization_rec.actual_content_source;
4455 
4456       ------Bug No:2771835---------------
4457       l_old_party_name    := p_old_organization_rec.organization_name;
4458       l_old_tax_reference := p_old_organization_rec.tax_reference;
4459       ------End Bug No:2771835-----------
4460 
4461       -- Validate organization record.
4462 
4463 
4464       HZ_registry_validate_v2pub.validate_organization(
4465         'U', p_organization_rec, p_old_organization_rec, x_return_status);
4466 
4467       IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4468         RAISE FND_API.G_EXC_ERROR;
4469       END IF;
4470 
4471       -- Bug 3317806 For non user entered data ( actual_content_source <> 'USER_ENTERED' ) ,
4472       -- if local_activity_code_type = 'NACE' and the local_activity_code is invalid with
4473       -- respect to the position of the decimal point, then replace this with the valid value.
4474       IF NVL(p_organization_rec.actual_content_source,p_old_organization_rec.actual_content_source) <> 'USER_ENTERED' AND
4475          NVL(p_organization_rec.local_activity_code_type, p_old_organization_rec.local_activity_code) in ( 'NACE' ,'4', '5') AND
4476          p_organization_rec.local_activity_code IS NOT NULL
4477       THEN
4478           SELECT lookup_code
4479           INTO   p_organization_rec.local_activity_code
4480           FROM   FND_LOOKUP_VALUES
4481           WHERE  lookup_type = 'NACE'
4482             AND  replace (lookup_code,'.','') = replace (p_organization_rec.local_activity_code,'.','')
4483             AND  rownum = 1;
4484           -- No need to handle no_data_found as this validation is already done in HZ_REGISTRY_VALIDATE_V2PUB.
4485       END IF;
4486 
4487 
4488       l_mixnmatch_enabled := g_org_mixnmatch_enabled;
4489       l_selected_datasources := g_org_selected_datasources;
4490 
4491     ELSIF p_party_type = 'GROUP' THEN
4492 
4493       l_data_source_type := G_MISS_CONTENT_SOURCE_TYPE;
4494       ------Bug No:2771835---------------
4495       l_old_party_name := p_old_group_rec.group_name;
4496       ------End Bug No:2771835-----------
4497 
4498 
4499       -- Validate group record.
4500 
4501       HZ_registry_validate_v2pub.validate_group(
4502          'U', p_group_rec, p_old_group_rec, x_return_status);
4503 
4504       IF x_return_status <> fnd_api.g_ret_sts_success THEN
4505         RAISE FND_API.G_EXC_ERROR;
4506       END IF;
4507 
4508       -- update group party.
4509 
4510       do_create_update_party_only(
4511         p_create_update_flag             => 'U',
4512         p_party_type                     => p_party_type,
4513         p_party_id                       => p_group_rec.party_rec.party_id,
4514         p_party_object_version_number    => p_party_object_version_number,
4515         p_group_rec                      => p_group_rec,
4516         p_old_group_rec                  => p_old_group_rec,
4517         x_party_id                       => l_party_id,
4518         x_party_number                   => l_party_number );
4519     END IF;
4520 
4521     IF p_party_type IN ('PERSON', 'ORGANIZATION') THEN
4522 
4523       -- Debug info.
4524       /*IF g_debug THEN
4525         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'l_mixnmatch_enabled = '||l_mixnmatch_enabled);
4526         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'l_data_source_type = '||l_data_source_type);
4527       END IF;
4528       */
4529       IF fnd_log.level_statement>=fnd_log.g_current_runtime_level THEN
4530            hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'l_mixnmatch_enabled = '||l_mixnmatch_enabled,
4531                                p_msg_level=>fnd_log.level_statement);
4532            hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'l_data_source_type = '||l_data_source_type,
4533                                p_msg_level=>fnd_log.level_statement);
4534 
4535       END IF;
4536 
4537       -- if mix-n-match is not enabled or we are updating third party profile or
4538       -- we are updating SST and SST was not generated, we need to update the
4539       -- profile.
4540 
4541       l_user_entered_profile_exists :=
4542         party_profile_exists(p_party_type, l_party_id, G_MISS_CONTENT_SOURCE_TYPE);
4543 
4544       IF l_mixnmatch_enabled = 'N' OR
4545          (l_data_source_type = G_SST_SOURCE_TYPE AND
4546           l_user_entered_profile_exists = 'N') OR
4547          l_data_source_type <> G_SST_SOURCE_TYPE
4548       THEN
4549         do_update_party_profile (
4550           p_party_type                       => p_party_type,
4551           p_person_rec                       => p_person_rec,
4552           p_old_person_rec                   => p_old_person_rec,
4553           p_organization_rec                 => p_organization_rec,
4554           p_old_organization_rec             => p_old_organization_rec,
4555           p_data_source_type                 => l_data_source_type,
4556           x_profile_id                       => x_profile_id );
4557       END IF;
4558 
4559       -- if user is updating SST profile, we need to update party.
4560       -- if mix-n-match is enabled and the SST profile was generated
4561       -- (i.e. has user-entered profile), we need to update SST profile
4562       -- as well as user-entered profile.
4563 
4564       IF l_data_source_type = G_SST_SOURCE_TYPE THEN
4565         l_sst_person_rec := p_old_person_rec;
4566         l_sst_organization_rec := p_old_organization_rec;
4567 
4568         l_update_party := 'Y';
4569 
4570         l_new_sst_person_rec := p_person_rec;
4571         l_new_sst_organization_rec := p_organization_rec;
4572 
4573         IF l_mixnmatch_enabled = 'Y' AND
4574            l_user_entered_profile_exists = 'Y'
4575         THEN
4576           l_update_sst_profile := 'Y';
4577           l_raise_error := 'Y';
4578           l_coming_data_source := G_MISS_CONTENT_SOURCE_TYPE;
4579         END IF;
4580 
4581       ELSIF l_mixnmatch_enabled = 'Y' THEN
4582 
4583         -- if the data source is selected, we need to check
4584         -- if we need to propagate the change to SST profile,
4585         -- and the party.
4586 
4587         l_datasource_selected :=
4588           HZ_MIXNM_UTILITY.isDataSourceSelected(
4589 -- Bug 4376604 : pass entity type
4590               p_party_type,
4591             l_data_source_type);
4592 
4593         -- Debug info.
4594         /*IF g_debug THEN
4595           hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'l_datasource_selected = '||l_datasource_selected);
4596         END IF;
4597         */
4598         IF fnd_log.level_statement>=fnd_log.g_current_runtime_level THEN
4599            hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'l_datasource_selected = '||l_datasource_selected,
4600                                p_msg_level=>fnd_log.level_statement);
4601         END IF;
4602 
4603         IF l_datasource_selected = 'Y' THEN
4604           l_update_sst_profile := 'Y';
4605           l_raise_error := 'N';
4606           l_coming_data_source := l_data_source_type;
4607 
4608           do_get_party_profile (
4609             p_party_type                       => p_party_type,
4610             p_party_id                         => l_party_id,
4611             p_data_source_type                 => G_SST_SOURCE_TYPE,
4612             x_person_rec                       => l_sst_person_rec,
4613             x_organization_rec                 => l_sst_organization_rec);
4614         END IF;
4615       END IF;
4616 
4617       IF l_update_sst_profile = 'Y' THEN
4618 
4619         -- return SST record which we need to use to update an existing
4620         -- SST profile.
4621 
4622         HZ_MIXNM_UTILITY.updateSSTProfile (
4623           p_create_update_flag                 => 'U',
4624           p_create_update_sst_flag             => 'U',
4625           p_raise_error_flag                   => l_raise_error,
4626           p_party_type                         => p_party_type,
4627           p_party_id                           => l_party_id,
4628           p_new_person_rec                     => p_person_rec,
4629           p_old_person_rec                     => p_old_person_rec,
4630           p_sst_person_rec                     => l_sst_person_rec,
4631           p_new_sst_person_rec                 => l_new_sst_person_rec,
4632           p_new_organization_rec               => p_organization_rec,
4633           p_old_organization_rec               => p_old_organization_rec,
4634           p_sst_organization_rec               => l_sst_organization_rec,
4635           p_new_sst_organization_rec           => l_new_sst_organization_rec,
4636           p_data_source_type                   => l_data_source_type,
4637           x_return_status                      => x_return_status );
4638 
4639         IF x_return_status <> fnd_api.g_ret_sts_success THEN
4640           RAISE FND_API.G_EXC_ERROR;
4641         END IF;
4642 
4643         l_new_sst_person_rec.party_rec.party_id := l_party_id;
4644         l_new_sst_organization_rec.party_rec.party_id := l_party_id;
4645 
4646         -- update SST profile.
4647 
4648         do_update_party_profile (
4649           p_party_type                       => p_party_type,
4650           p_person_rec                       => l_new_sst_person_rec,
4651           p_old_person_rec                   => l_sst_person_rec,
4652           p_organization_rec                 => l_new_sst_organization_rec,
4653           p_old_organization_rec             => l_sst_organization_rec,
4654           p_data_source_type                 => G_SST_SOURCE_TYPE,
4655           x_profile_id                       => l_profile_id );
4656 
4657         -- if user is updating SST profile, update user-entered profile too.
4658 
4659         IF l_data_source_type = G_SST_SOURCE_TYPE THEN
4660           x_profile_id := l_profile_id;
4661 
4662           do_get_party_profile (
4663             p_party_type                       => p_party_type,
4664             p_party_id                         => l_party_id,
4665             p_data_source_type                 => G_MISS_CONTENT_SOURCE_TYPE,
4666             x_person_rec                       => l_ue_person_rec,
4667             x_organization_rec                 => l_ue_organization_rec);
4668 
4669           do_update_party_profile (
4670             p_party_type                       => p_party_type,
4671             p_person_rec                       => l_new_sst_person_rec,
4672             p_old_person_rec                   => l_ue_person_rec,
4673             p_organization_rec                 => l_new_sst_organization_rec,
4674             p_old_organization_rec             => l_ue_organization_rec,
4675             p_data_source_type                 => G_MISS_CONTENT_SOURCE_TYPE,
4676             x_profile_id                       => l_profile_id );
4677         END IF;
4678 
4679         l_update_party := 'Y';
4680       END IF;
4681 
4682       IF l_update_party = 'Y' THEN
4683 
4684         -- Debug info.
4685         /*IF g_debug THEN
4686           hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'l_party_id = '||l_party_id);
4687         END IF;
4688         */
4689         IF fnd_log.level_statement>=fnd_log.g_current_runtime_level THEN
4690            hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'l_party_id = '||l_party_id,
4691                                p_msg_level=>fnd_log.level_statement);
4692         END IF;
4693 ---------------Bug 4586451
4694 IF p_party_type ='ORGANIZATION'AND
4695  p_organization_rec.organization_name <>FND_API.G_MISS_CHAR AND
4696  p_organization_rec.organization_name IS NOT NULL AND
4697  p_organization_rec.organization_name<>p_old_organization_rec.organization_name AND
4698  nvl(p_organization_rec.actual_content_source,p_old_organization_rec.actual_content_source) IN (G_SST_SOURCE_TYPE,G_MISS_CONTENT_SOURCE_TYPE) THEN
4699          validate_party_name (
4700                    p_party_id                    => l_party_id,
4701                    p_party_name                  => p_organization_rec.organization_name,
4702                    x_return_status               => l_return_status);
4703 END IF;
4704 
4705 IF l_return_status <> fnd_api.g_ret_sts_success THEN
4706       RAISE FND_API.G_EXC_ERROR;
4707 END IF;
4708 
4709 ----------------Bug4586451
4710 
4711        l_sst_person_rec.party_rec := p_old_person_rec.party_rec;
4712        l_new_sst_person_rec.party_rec := p_person_rec.party_rec;
4713        l_sst_organization_rec.party_rec := p_old_organization_rec.party_rec;
4714        l_new_sst_organization_rec.party_rec := p_organization_rec.party_rec;
4715 
4716         do_create_update_party_only(
4717           p_create_update_flag             => 'U',
4718           p_party_type                     => p_party_type,
4719           p_party_id                       => l_party_id,
4720           p_party_object_version_number    => p_party_object_version_number,
4721           p_person_rec                     => l_new_sst_person_rec,
4722           p_old_person_rec                 => l_sst_person_rec,
4723           p_organization_rec               => l_new_sst_organization_rec,
4724           p_old_organization_rec           => l_sst_organization_rec,
4725           x_party_id                       => l_dummy_id,
4726           x_party_number                   => l_party_number );
4727       END IF;
4728     END IF;
4729 
4730     -- process classification related attributes.
4731 
4732     do_process_classification(
4733       p_create_update_flag               => 'U',
4734       p_party_type                    => p_party_type,
4735       p_organization_rec                 => p_organization_rec,
4736       p_old_organization_rec             => p_old_organization_rec,
4737       p_person_rec                       => p_person_rec,
4738       p_old_person_rec                   => p_old_person_rec,
4739       p_group_rec                        => p_group_rec,
4740       p_old_group_rec                    => p_old_group_rec,
4741       p_data_source_type                 => l_data_source_type,
4742       x_return_status                    => x_return_status );
4743 
4744      ---Bug No: 2771835----------
4745      OPEN  c_party_name(l_party_id);
4746      FETCH c_party_name INTO l_new_party_name,l_new_tax_reference;
4747      CLOSE c_party_name;
4748      update_party_search(l_party_id,l_old_party_name,l_new_party_name,l_old_tax_reference,l_new_tax_reference);
4749      IF p_party_type='PERSON' THEN
4750        update_rel_person_search(p_old_person_rec,p_person_rec);
4751      END IF;
4752      ---End Bug No: 2771835-------
4753 
4754     -- Invoke business event system and DQM
4755     -- BES and DQM will only be called when SST (i.e. party) is touched).
4756     -- We will pass SST info. into update event.
4757 
4758     IF l_update_party = 'Y' THEN
4759       IF p_party_type = 'ORGANIZATION' THEN
4760         l_new_sst_organization_rec.party_rec.orig_system := p_organization_rec.party_rec.orig_system;
4761         l_sst_organization_rec.party_rec.orig_system := p_organization_rec.party_rec.orig_system;
4762         -- BES
4763 
4764         IF(HZ_UTILITY_V2PUB.G_EXECUTE_API_CALLOUTS in ('EVENTS_ENABLED', 'Y')) THEN
4765           HZ_BUSINESS_EVENT_V2PVT.update_organization_event(
4766             l_new_sst_organization_rec, l_sst_organization_rec);
4767         END IF;
4768 
4769         IF(HZ_UTILITY_V2PUB.G_EXECUTE_API_CALLOUTS in ('EVENTS_ENABLED', 'BO_EVENTS_ENABLED')) THEN
4770           -- populate function for integration service
4771           HZ_POPULATE_BOT_PKG.pop_hz_organization_profiles(
4772             p_operation               => 'U',
4773             p_organization_profile_id => x_profile_id);
4774         END IF;
4775 
4776         -- DQM
4777         HZ_DQM_SYNC.sync_org(l_party_id, 'U');
4778 
4779       ELSIF p_party_type = 'PERSON' THEN
4780         l_new_sst_person_rec.party_rec.orig_system := p_person_rec.party_rec.orig_system;
4781         l_sst_person_rec.party_rec.orig_system := p_person_rec.party_rec.orig_system;
4782         -- BES
4783 
4784         IF(HZ_UTILITY_V2PUB.G_EXECUTE_API_CALLOUTS in ('EVENTS_ENABLED', 'Y')) THEN
4785           HZ_BUSINESS_EVENT_V2PVT.update_person_event(
4786             l_new_sst_person_rec, l_sst_person_rec);
4787         END IF;
4788 
4789         IF(HZ_UTILITY_V2PUB.G_EXECUTE_API_CALLOUTS in ('EVENTS_ENABLED', 'BO_EVENTS_ENABLED')) THEN
4790           -- populate function for integration service
4791           HZ_POPULATE_BOT_PKG.pop_hz_person_profiles(
4792             p_operation         => 'U',
4793             p_person_profile_id => x_profile_id);
4794         END IF;
4795 
4796         -- DQM
4797         HZ_DQM_SYNC.sync_person(l_party_id, 'U');
4798 
4799       END IF;
4800     END IF;
4801 
4802     -- Debug info.
4803     /*IF g_debug THEN
4804         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'do_update_party (-)');
4805     END IF;
4806     */
4807     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
4808         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'do_update_party (-)',
4809                                p_msg_level=>fnd_log.level_procedure);
4810     END IF;
4811 
4812 
4813   END do_update_party;
4814 
4815   --------------------------------------
4816   -- public procedures and functions
4817   --------------------------------------
4818 
4819   /**
4820    * PROCEDURE create_person
4821    *
4822    * DESCRIPTION
4823    *     Creates person.
4824    *
4825    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
4826    *     HZ_BUSINESS_EVENT_V2PVT.create_person_event
4827    *
4828    * ARGUMENTS
4829    *   IN:
4830    *     p_init_msg_list      Initialize message stack if it is set to
4831    *                          FND_API.G_TRUE. Default is fnd_api.g_false.
4832    *     p_person_rec         Person record.
4833    *     p_party_usage_code   Party Usage Code
4834    *   IN/OUT:
4835    *   OUT:
4836    *     x_party_id           Party ID.
4837    *     x_party_number       Party number.
4838    *     x_profile_id         Person profile ID.
4839    *     x_return_status      Return status after the call. The status can
4840    *                          be FND_API.G_RET_STS_SUCCESS (success),
4841    *                          fnd_api.g_ret_sts_error (error),
4842    *                          fnd_api.g_ret_sts_unexp_error (unexpected error).
4843    *     x_msg_count          Number of messages in message stack.
4844    *     x_msg_data           Message text if x_msg_count is 1.
4845    *
4846    * NOTES
4847    *
4848    * MODIFICATION HISTORY
4849    *
4850    *   07-23-2001    Indrajit Sen        o Created.
4851    *
4852    */
4853 
4854   PROCEDURE create_person (
4855     p_init_msg_list                    IN     VARCHAR2 := fnd_api.g_false,
4856     p_person_rec                       IN     PERSON_REC_TYPE,
4857     p_party_usage_code                 IN     VARCHAR2,
4858     x_party_id                         OUT    NOCOPY NUMBER,
4859     x_party_number                     OUT    NOCOPY VARCHAR2,
4860     x_profile_id                       OUT    NOCOPY NUMBER,
4861     x_return_status                    OUT    NOCOPY VARCHAR2,
4862     x_msg_count                        OUT    NOCOPY NUMBER,
4863     x_msg_data                         OUT    NOCOPY VARCHAR2
4864   ) IS
4865 
4866     l_context                          VARCHAR2(30);
4867     l_api_name                         CONSTANT VARCHAR2(30) := 'create_person';
4868     l_person_rec                       PERSON_REC_TYPE := p_person_rec;
4869 
4870     dss_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
4871     dss_msg_count     NUMBER := 0;
4872     dss_msg_data      VARCHAR2(2000):= null;
4873     l_test_security   VARCHAR2(1):= 'F';
4874     l_debug_prefix                      VARCHAR2(30) := '';
4875 
4876   BEGIN
4877 
4878     -- standard start of API savepoint
4879     SAVEPOINT create_person;
4880 
4881     -- Check if API is called in debug mode. If yes, enable debug.
4882     --enable_debug;
4883 
4884     -- Debug info.
4885     /*IF g_debug THEN
4886       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'create_person (+)');
4887     END IF;
4888     */
4889     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
4890         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'create_person (+)',
4891                                p_msg_level=>fnd_log.level_procedure);
4892     END IF;
4893 
4894 
4895     -- initialize message list if p_init_msg_list is set to TRUE.
4896     IF FND_API.to_Boolean(p_init_msg_list) THEN
4897       FND_MSG_PUB.initialize;
4898     END IF;
4899 
4900     -- initialize API return status to success.
4901     x_return_status := FND_API.G_RET_STS_SUCCESS;
4902 
4903     -- enable policy function if it is disabled.
4904 
4905     l_context := NVL(SYS_CONTEXT('hz', g_apps_context), 'N');
4906     IF l_context = 'N' THEN
4907       hz_common_pub.disable_cont_source_security;
4908     END IF;
4909 
4910     -- cache if mix-n-match is enabled
4911 
4912     -- IF g_per_mixnmatch_enabled IS NULL THEN
4913     HZ_MIXNM_UTILITY.LoadDataSources(
4914       'HZ_PERSON_PROFILES', g_per_entity_attr_id,
4915       g_per_mixnmatch_enabled, g_per_selected_datasources);
4916     -- END IF;
4917 
4918     -- call to business logic.
4919     do_create_party(
4920       p_party_type            => 'PERSON',
4921       p_party_usage_code      => p_party_usage_code,
4922       p_person_rec            => l_person_rec,
4923       x_party_id              => x_party_id,
4924       x_party_number          => x_party_number,
4925       x_profile_id            => x_profile_id,
4926       x_return_status         => x_return_status,
4927       p_organization_rec      => G_MISS_ORGANIZATION_REC,
4928       p_group_rec             => G_MISS_GROUP_REC );
4929 
4930     -- Bug 2486394 Check if the DSS security is granted to the user
4931     -- Bug 3818648: check dss profile before call test_instance.
4932     --
4933     IF NVL(fnd_profile.value('HZ_DSS_ENABLED'), 'N') = 'Y' THEN
4934       l_test_security :=
4935            hz_dss_util_pub.test_instance(
4936                   p_operation_code     => 'INSERT',
4937                   p_db_object_name     => 'HZ_PARTIES',
4938                   p_instance_pk1_value => x_party_id,
4939                   p_user_name          => fnd_global.user_name,
4940                   x_return_status      => dss_return_status,
4941                   x_msg_count          => dss_msg_count,
4942                   x_msg_data           => dss_msg_data);
4943 
4944       if dss_return_status <> fnd_api.g_ret_sts_success THEN
4945          RAISE FND_API.G_EXC_ERROR;
4946       end if;
4947 
4948       if (l_test_security <> 'T' OR l_test_security <> FND_API.G_TRUE) then
4949          --
4950          -- Bug 3835601: replaced the dss message with a more user friendly message
4951          --
4952          FND_MESSAGE.SET_NAME('AR', 'HZ_DSS_NO_INSERT_PRIVILEGE');
4953          FND_MESSAGE.SET_TOKEN('ENTITY_NAME',
4954                                hz_dss_util_pub.get_display_name(null, 'PERSON'));
4955          FND_MSG_PUB.ADD;
4956          RAISE FND_API.G_EXC_ERROR;
4957       end if;
4958     END IF;
4959 
4960     -- enable policy function if it was enabled before calling
4961     -- this procedure.
4962 
4963     IF l_context = 'N' THEN
4964       hz_common_pub.enable_cont_source_security;
4965     END IF;
4966 
4967     --Standard call to get message count and if count is 1, get message info.
4968     fnd_msg_pub.count_and_get(
4969       p_encoded                      => fnd_api.g_false,
4970       p_count                        => x_msg_count,
4971       p_data                         => x_msg_data);
4972 
4973     -- Debug info.
4974     /*IF g_debug THEN
4975       hz_utility_v2pub.debug_return_messages (
4976         x_msg_count, x_msg_data, 'WARNING');
4977       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'create_person (-)');
4978     END IF;
4979     */
4980     IF  fnd_log.level_exception>=fnd_log.g_current_runtime_level THEN
4981          hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
4982                                p_msg_data=>x_msg_data,
4983                                p_msg_type=>'WARNING',
4984                                p_msg_level=>fnd_log.level_exception);
4985     END IF;
4986     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
4987          hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'create_person (-)',
4988                                 p_msg_level=>fnd_log.level_procedure);
4989     END IF;
4990 
4991     -- Check if API is called in debug mode. If yes, disable debug.
4992     --disable_debug;
4993 
4994   EXCEPTION
4995     WHEN FND_API.G_EXC_ERROR THEN
4996       ROLLBACK TO create_person;
4997 
4998       IF l_context = 'N' THEN
4999         hz_common_pub.enable_cont_source_security;
5000       END IF;
5001 
5002       x_return_status := fnd_api.g_ret_sts_error;
5003 
5004       fnd_msg_pub.count_and_get(
5005         p_encoded                    => fnd_api.g_false,
5006         p_count                      => x_msg_count,
5007         p_data                       => x_msg_data);
5008 
5009       -- Debug info.
5010       /*IF g_debug THEN
5011         hz_utility_v2pub.debug_return_messages (
5012           x_msg_count, x_msg_data, 'ERROR');
5013         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'create_person (-)');
5014       END IF;*/
5015 
5016       IF fnd_log.level_error >= fnd_log.g_current_runtime_level THEN
5017         hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
5018                                p_msg_data=>x_msg_data,
5019                                p_msg_type=>'ERROR',
5020                                p_msg_level=>fnd_log.level_error);
5021       END IF;
5022       IF fnd_log.level_procedure >= fnd_log.g_current_runtime_level THEN
5023         hz_utility_v2pub.debug(p_message=>'create_person (-)',
5024                                p_prefix=>l_debug_prefix,
5025                                p_msg_level=>fnd_log.level_procedure);
5026        END IF;
5027 
5028       -- Check if API is called in debug mode. If yes, disable debug.
5029       --disable_debug;
5030 
5031     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5032       ROLLBACK TO create_person;
5033 
5034       IF l_context = 'N' THEN
5035         hz_common_pub.enable_cont_source_security;
5036       END IF;
5037 
5038       x_return_status := fnd_api.g_ret_sts_unexp_error;
5039 
5040       fnd_msg_pub.count_and_get(
5041         p_encoded                    => fnd_api.g_false,
5042         p_count                      => x_msg_count,
5043         p_data                       => x_msg_data);
5044 
5045       -- Debug info.
5046       /*IF g_debug THEN
5047         hz_utility_v2pub.debug_return_messages (
5048           x_msg_count, x_msg_data, 'UNEXPECTED ERROR');
5049         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'create_person (-)');
5050       END IF;
5051       */
5052       IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
5053         hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
5054                                p_msg_data=>x_msg_data,
5055                                p_msg_type=>'UNEXPECTED ERROR',
5056                                p_msg_level=>fnd_log.level_error);
5057       END IF;
5058       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
5059         hz_utility_v2pub.debug(p_message=>'create_person (-)',
5060                                p_prefix=>l_debug_prefix,
5061                                p_msg_level=>fnd_log.level_procedure);
5062       END IF;
5063 
5064       -- Check if API is called in debug mode. If yes, disable debug.
5065       --disable_debug;
5066 
5067     WHEN OTHERS THEN
5068       ROLLBACK TO create_person;
5069 
5070       IF l_context = 'N' THEN
5071         hz_common_pub.enable_cont_source_security;
5072       END IF;
5073 
5074       x_return_status := fnd_api.g_ret_sts_unexp_error;
5075 
5076       fnd_message.set_name('AR', 'HZ_API_OTHERS_EXCEP');
5077       fnd_message.set_token('ERROR',SQLERRM);
5078       fnd_msg_pub.add;
5079 
5080       fnd_msg_pub.count_and_get(
5081         p_encoded                    => fnd_api.g_false,
5082         p_count                      => x_msg_count,
5083         p_data                       => x_msg_data);
5084 
5085       -- Debug info.
5086       /*IF g_debug THEN
5087         hz_utility_v2pub.debug_return_messages (
5088           x_msg_count, x_msg_data, 'SQL ERROR');
5089         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'create_person (-)');
5090       END IF;
5091       */
5092       IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
5093         hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
5094                                p_msg_data=>x_msg_data,
5095                                p_msg_type=>'SQL ERROR',
5096                                p_msg_level=>fnd_log.level_error);
5097       END IF;
5098       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
5099         hz_utility_v2pub.debug(p_message=>'create_person (-)',
5100                                p_prefix=>l_debug_prefix,
5101                                p_msg_level=>fnd_log.level_procedure);
5102       END IF;
5103 
5104 
5105       -- Check if API is called in debug mode. If yes, disable debug.
5106       --disable_debug;
5107 
5108   END create_person;
5109 
5110   /**
5111    * PROCEDURE create_person
5112    *
5113    * DESCRIPTION
5114    *     Creates person.
5115    *
5116    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
5117    *     HZ_BUSINESS_EVENT_V2PVT.create_person_event
5118    *
5119    * ARGUMENTS
5120    *   IN:
5121    *     p_init_msg_list      Initialize message stack if it is set to
5122    *                          FND_API.G_TRUE. Default is fnd_api.g_false.
5123    *     p_person_rec         Person record.
5124    *   IN/OUT:
5125    *   OUT:
5126    *     x_party_id           Party ID.
5127    *     x_party_number       Party number.
5128    *     x_profile_id         Person profile ID.
5129    *     x_return_status      Return status after the call. The status can
5130    *                          be FND_API.G_RET_STS_SUCCESS (success),
5131    *                          fnd_api.g_ret_sts_error (error),
5132    *                          fnd_api.g_ret_sts_unexp_error (unexpected error).
5133    *     x_msg_count          Number of messages in message stack.
5134    *     x_msg_data           Message text if x_msg_count is 1.
5135    *
5136    * NOTES
5137    *
5138    * MODIFICATION HISTORY
5139    *
5140    *   07-23-2001    Indrajit Sen        o Created.
5141    *
5142    */
5143 
5144   PROCEDURE create_person (
5145     p_init_msg_list                    IN     VARCHAR2 := fnd_api.g_false,
5146     p_person_rec                       IN     PERSON_REC_TYPE,
5147     x_party_id                         OUT    NOCOPY NUMBER,
5148     x_party_number                     OUT    NOCOPY VARCHAR2,
5149     x_profile_id                       OUT    NOCOPY NUMBER,
5150     x_return_status                    OUT    NOCOPY VARCHAR2,
5151     x_msg_count                        OUT    NOCOPY NUMBER,
5152     x_msg_data                         OUT    NOCOPY VARCHAR2
5153   ) IS
5154 
5155   BEGIN
5156 
5157     create_person (
5158       p_init_msg_list             => p_init_msg_list,
5159       p_person_rec                => p_person_rec,
5160       p_party_usage_code          => null,
5161       x_party_id                  => x_party_id,
5162       x_party_number              => x_party_number,
5163       x_profile_id                => x_profile_id,
5164       x_return_status             => x_return_status,
5165       x_msg_count                 => x_msg_count,
5166       x_msg_data                  => x_msg_data
5167     );
5168 
5169   END create_person;
5170 
5171   /**
5172    * PROCEDURE update_person
5173    *
5174    * DESCRIPTION
5175    *     Updates person.
5176    *
5177    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
5178    *     HZ_BUSINESS_EVENT_V2PVT.update_person_event
5179    *
5180    * ARGUMENTS
5181    *   IN:
5182    *     p_init_msg_list      Initialize message stack if it is set to
5183    *                          FND_API.G_TRUE. Default is fnd_api.g_false.
5184    *     p_person_rec         Person record.
5185    *   IN/OUT:
5186    *     p_party_object_version_number  Used for locking the being updated record.
5187    *   OUT:
5188    *     x_profile_id         Person profile ID.
5189    *     x_return_status      Return status after the call. The status can
5190    *                          be FND_API.G_RET_STS_SUCCESS (success),
5191    *                          fnd_api.g_ret_sts_error (error),
5192    *                          fnd_api.g_ret_sts_unexp_error (unexpected error).
5193    *     x_msg_count          Number of messages in message stack.
5194    *     x_msg_data           Message text if x_msg_count is 1.
5195    *
5196    * NOTES
5197    *
5198    * MODIFICATION HISTORY
5199    *
5200    *   07-23-2001    Indrajit Sen        o Created.
5201    *
5202    */
5203 
5204   PROCEDURE update_person (
5205     p_init_msg_list                    IN     VARCHAR2 := fnd_api.g_false,
5206     p_person_rec                       IN     PERSON_REC_TYPE,
5207     p_party_object_version_number      IN OUT NOCOPY NUMBER,
5208     x_profile_id                       OUT NOCOPY    NUMBER,
5209     x_return_status                    OUT NOCOPY    VARCHAR2,
5210     x_msg_count                        OUT NOCOPY    NUMBER,
5211     x_msg_data                         OUT NOCOPY    VARCHAR2
5212   ) IS
5213 
5214     l_api_name                         CONSTANT VARCHAR2(30) := 'update_person';
5215     l_person_rec                       PERSON_REC_TYPE := p_person_rec;
5216     l_old_person_rec                   PERSON_REC_TYPE;
5217     l_data_source_from                 VARCHAR2(30);
5218     l_context                          VARCHAR2(30);
5219 
5220     dss_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
5221     dss_msg_count     NUMBER := 0;
5222     dss_msg_data      VARCHAR2(2000):= null;
5223     l_test_security   VARCHAR2(1):= 'F';
5224     l_debug_prefix                     VARCHAR2(30) := '';
5225 
5226   BEGIN
5227 
5228     -- standard start of API savepoint
5229     SAVEPOINT update_person;
5230 
5231     -- Check if API is called in debug mode. If yes, enable debug.
5232     --enable_debug;
5233 
5234     -- Debug info.
5235     /*IF g_debug THEN
5236       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'update_person (+)');
5237     END IF;
5238     */
5239     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
5240         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'update_person (+)',
5241                                p_msg_level=>fnd_log.level_procedure);
5242     END IF;
5243 
5244     -- initialize message list if p_init_msg_list is set to TRUE.
5245     IF FND_API.to_Boolean(p_init_msg_list) THEN
5246       FND_MSG_PUB.initialize;
5247     END IF;
5248 
5249     -- initialize API return status to success.
5250     x_return_status := FND_API.G_RET_STS_SUCCESS;
5251 
5252     -- enable policy function if it is disabled.
5253 
5254     l_context := NVL(SYS_CONTEXT('hz', g_apps_context), 'N');
5255     IF l_context = 'N' THEN
5256       hz_common_pub.disable_cont_source_security;
5257     END IF;
5258 
5259 
5260 /**
5261     get_person_rec is checking if the person party has been
5262     passed in.
5263 
5264     -- make sure PEROSN party has been passed in
5265     BEGIN
5266       SELECT 1 INTO l_count
5267       FROM   HZ_PARTIES
5268       WHERE  PARTY_ID = p_person_rec.party_rec.party_id
5269       AND    PARTY_TYPE = 'PERSON';
5270     EXCEPTION
5271       WHEN NO_DATA_FOUND THEN
5272         fnd_message.set_name('AR', 'HZ_API_NO_RECORD');
5273         fnd_message.set_token('RECORD', 'person');
5274         fnd_message.set_token('VALUE', to_char(p_person_rec.party_rec.party_id));
5275         fnd_msg_pub.add;
5276         RAISE FND_API.G_EXC_ERROR;
5277     END;
5278 **/
5279 
5280      IF (l_person_rec.party_rec.orig_system is not null
5281          and l_person_rec.party_rec.orig_system <>fnd_api.g_miss_char)
5282        and (l_person_rec.party_rec.orig_system_reference is not null
5283          and l_person_rec.party_rec.orig_system_reference <>fnd_api.g_miss_char)
5284        and (l_person_rec.party_rec.party_id = FND_API.G_MISS_NUM or l_person_rec.party_rec.party_id is null) THEN
5285 
5286         hz_orig_system_ref_pub.get_owner_table_id
5287                         (p_orig_system => l_person_rec.party_rec.orig_system,
5288                         p_orig_system_reference => l_person_rec.party_rec.orig_system_reference,
5289                         p_owner_table_name => 'HZ_PARTIES',
5290                         x_owner_table_id => l_person_rec.party_rec.party_id,
5291                         x_return_status => x_return_status);
5292 
5293             IF x_return_status <> fnd_api.g_ret_sts_success THEN
5294                 RAISE FND_API.G_EXC_ERROR;
5295             END IF;
5296     END IF;
5297     -- cache if mix-n-match is enabled
5298 
5299     -- IF g_per_mixnmatch_enabled IS NULL THEN
5300     HZ_MIXNM_UTILITY.LoadDataSources(
5301       'HZ_PERSON_PROFILES', g_per_entity_attr_id,
5302       g_per_mixnmatch_enabled, g_per_selected_datasources);
5303     -- END IF;
5304 
5305     -- Get old records. Will be used by business event system.
5306     get_person_rec (
5307         p_party_id                   => l_person_rec.party_rec.party_id,
5308         p_content_source_type        => HZ_MIXNM_UTILITY.FindDataSource(
5309                                           p_content_source_type           => l_person_rec.content_source_type,
5310                                           p_actual_content_source         => l_person_rec.actual_content_source,
5311                                           p_def_actual_content_source     => G_SST_SOURCE_TYPE,
5312                                           x_data_source_from              => l_data_source_from ),
5313         x_person_rec                 => l_old_person_rec,
5314         x_return_status              => x_return_status,
5315         x_msg_count                  => x_msg_count,
5316         x_msg_data                   => x_msg_data);
5317 
5318     IF x_return_status = fnd_api.g_ret_sts_error THEN
5319       RAISE FND_API.G_EXC_ERROR;
5320     ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
5321       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5322     END IF;
5323 
5324     -- Bug 2486394 Check if the DSS security is granted to the user
5325     -- Bug 3818648: check dss profile before call test_instance.
5326     --
5327     IF NVL(fnd_profile.value('HZ_DSS_ENABLED'), 'N') = 'Y' THEN
5328       l_test_security :=
5329            hz_dss_util_pub.test_instance(
5330                   p_operation_code     => 'UPDATE',
5331                   p_db_object_name     => 'HZ_PARTIES',
5332                   p_instance_pk1_value => l_person_rec.party_rec.party_id,
5333                   p_user_name          => fnd_global.user_name,
5334                   x_return_status      => dss_return_status,
5335                   x_msg_count          => dss_msg_count,
5336                   x_msg_data           => dss_msg_data);
5337 
5338       if dss_return_status <> fnd_api.g_ret_sts_success THEN
5339          RAISE FND_API.G_EXC_ERROR;
5340       end if;
5341 
5342       if (l_test_security <> 'T' OR l_test_security <> FND_API.G_TRUE) then
5343          --
5344          -- Bug 3835601: replaced the dss message with a more user friendly message
5345          --
5346          FND_MESSAGE.SET_NAME('AR', 'HZ_DSS_NO_UPDATE_PRIVILEGE');
5347          FND_MESSAGE.SET_TOKEN('ENTITY_NAME',
5348                                hz_dss_util_pub.get_display_name(null, 'PERSON'));
5349          FND_MSG_PUB.ADD;
5350          RAISE FND_API.G_EXC_ERROR;
5351       end if;
5352     END IF;
5353 
5354     -- call to business logic.
5355     do_update_party(
5356       p_party_type                   => 'PERSON',
5357       p_person_rec                   => l_person_rec,
5358       p_old_person_rec               => l_old_person_rec,
5359       p_party_object_version_number  => p_party_object_version_number,
5360       x_profile_id                   => x_profile_id,
5361       x_return_status                => x_return_status,
5362       p_organization_rec             => G_MISS_ORGANIZATION_REC,
5363       p_group_rec                    => G_MISS_GROUP_REC );
5364 
5365     -- enable policy function if it was enabled before calling
5366     -- this procedure.
5367 
5368     IF l_context = 'N' THEN
5369       hz_common_pub.enable_cont_source_security;
5370     END IF;
5371 
5372     --Standard call to get message count and if count is 1, get message info.
5373     fnd_msg_pub.count_and_get(
5374       p_encoded                      => fnd_api.g_false,
5375       p_count                        => x_msg_count,
5376       p_data                         => x_msg_data);
5377 
5378     -- Debug info.
5379     /*IF g_debug THEN
5380       hz_utility_v2pub.debug_return_messages (
5381         x_msg_count, x_msg_data, 'WARNING');
5382       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'update_person (-)');
5383     END IF;
5384     */
5385     IF  fnd_log.level_exception>=fnd_log.g_current_runtime_level THEN
5386          hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
5387                                p_msg_data=>x_msg_data,
5388                                p_msg_type=>'WARNING',
5389                                p_msg_level=>fnd_log.level_exception);
5390     END IF;
5391     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
5392          hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'update_person (-)',
5393                                 p_msg_level=>fnd_log.level_procedure);
5394     END IF;
5395 
5396 
5397     -- Check if API is called in debug mode. If yes, disable debug.
5398     --disable_debug;
5399 
5400   EXCEPTION
5401     WHEN FND_API.G_EXC_ERROR THEN
5402       ROLLBACK TO update_person;
5403 
5404       IF l_context = 'N' THEN
5405         hz_common_pub.enable_cont_source_security;
5406       END IF;
5407 
5408       x_return_status := fnd_api.g_ret_sts_error;
5409 
5410       fnd_msg_pub.count_and_get(
5411         p_encoded                    => fnd_api.g_false,
5412         p_count                      => x_msg_count,
5413         p_data                       => x_msg_data);
5414 
5415       -- Debug info.
5416       /*IF g_debug THEN
5417         hz_utility_v2pub.debug_return_messages (
5418           x_msg_count, x_msg_data, 'ERROR');
5419         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'update_person (-)');
5420       END IF;
5421       */
5422       IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
5423         hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
5424                                p_msg_data=>x_msg_data,
5425                                p_msg_type=>'ERROR',
5426                                p_msg_level=>fnd_log.level_error);
5427       END IF;
5428       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
5429         hz_utility_v2pub.debug(p_message=>'update_person (-)',
5430                                p_prefix=>l_debug_prefix,
5431                                p_msg_level=>fnd_log.level_procedure);
5432       END IF;
5433 
5434 
5435       -- Check if API is called in debug mode. If yes, disable debug.
5436       --disable_debug;
5437 
5438     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5439       ROLLBACK TO update_person;
5440 
5441       IF l_context = 'N' THEN
5442         hz_common_pub.enable_cont_source_security;
5443       END IF;
5444 
5445       x_return_status := fnd_api.g_ret_sts_unexp_error;
5446 
5447       fnd_msg_pub.count_and_get(
5448         p_encoded                    => fnd_api.g_false,
5449         p_count                      => x_msg_count,
5450         p_data                       => x_msg_data);
5451 
5452       -- Debug info.
5453       /*IF g_debug THEN
5454         hz_utility_v2pub.debug_return_messages (
5455           x_msg_count, x_msg_data, 'UNEXPECTED ERROR');
5456         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'update_person (-)');
5457       END IF;
5458       */
5459        IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
5460          hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
5461                                p_msg_data=>x_msg_data,
5462                                p_msg_type=>'UNEXPECTED ERROR',
5463                                p_msg_level=>fnd_log.level_error);
5464        END IF;
5465        IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
5466          hz_utility_v2pub.debug(p_message=>'update_person (-)',
5467                                p_prefix=>l_debug_prefix,
5468                                p_msg_level=>fnd_log.level_procedure);
5469        END IF;
5470       -- Check if API is called in debug mode. If yes, disable debug.
5471       --disable_debug;
5472 
5473     WHEN OTHERS THEN
5474       ROLLBACK TO update_person;
5475 
5476       IF l_context = 'N' THEN
5477         hz_common_pub.enable_cont_source_security;
5478       END IF;
5479 
5480       x_return_status := fnd_api.g_ret_sts_unexp_error;
5481 
5482       fnd_message.set_name('AR', 'HZ_API_OTHERS_EXCEP');
5483       fnd_message.set_token('ERROR',SQLERRM);
5484       fnd_msg_pub.add;
5485 
5486       fnd_msg_pub.count_and_get(
5487         p_encoded                    => fnd_api.g_false,
5488         p_count                      => x_msg_count,
5489         p_data                       => x_msg_data);
5490 
5491       -- Debug info.
5492       /*IF g_debug THEN
5493         hz_utility_v2pub.debug_return_messages (
5494           x_msg_count, x_msg_data, 'SQL ERROR');
5495         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'update_person (-)');
5496       END IF;
5497       */
5498       IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
5499         hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
5500                                p_msg_data=>x_msg_data,
5501                                p_msg_type=>'SQL ERROR',
5502                                p_msg_level=>fnd_log.level_error);
5503       END IF;
5504       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
5505         hz_utility_v2pub.debug(p_message=>'update_person (-)',
5506                                p_prefix=>l_debug_prefix,
5507                                p_msg_level=>fnd_log.level_procedure);
5508       END IF;
5509 
5510       -- Check if API is called in debug mode. If yes, disable debug.
5511       --disable_debug;
5512 
5513   END update_person;
5514 
5515   /**
5516    * PROCEDURE create_group
5517    *
5518    * DESCRIPTION
5519    *     Creates group.
5520    *
5521    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
5522    *     HZ_BUSINESS_EVENT_V2PVT.create_group_event
5523    *
5524    * ARGUMENTS
5525    *   IN:
5526    *     p_init_msg_list      Initialize message stack if it is set to
5527    *                          FND_API.G_TRUE. Default is fnd_api.g_false.
5528    *     p_group_rec          Group record.
5529    *   IN/OUT:
5530    *   OUT:
5531    *     x_party_id           Party ID.
5532    *     x_party_number       Party number.
5533    *     x_return_status      Return status after the call. The status can
5534    *                          be FND_API.G_RET_STS_SUCCESS (success),
5535    *                          fnd_api.g_ret_sts_error (error),
5536    *                          fnd_api.g_ret_sts_unexp_error (unexpected error).
5537    *     x_msg_count          Number of messages in message stack.
5538    *     x_msg_data           Message text if x_msg_count is 1.
5539    *
5540    * NOTES
5541    *
5542    * MODIFICATION HISTORY
5543    *
5544    *   07-23-2001    Indrajit Sen        o Created.
5545    *
5546    */
5547   PROCEDURE create_group (
5548     p_init_msg_list                    IN      VARCHAR2 := fnd_api.g_false,
5549     p_group_rec                        IN      GROUP_REC_TYPE,
5550     x_party_id                         OUT NOCOPY     NUMBER,
5551     x_party_number                     OUT NOCOPY     VARCHAR2,
5552     x_return_status                    OUT NOCOPY     VARCHAR2,
5553     x_msg_count                        OUT NOCOPY     NUMBER,
5554     x_msg_data                         OUT NOCOPY     VARCHAR2
5555   ) IS
5556 
5557     l_context                          VARCHAR2(30);
5558     l_api_name                         CONSTANT VARCHAR2(30) := 'create_group';
5559     l_profile_id                       NUMBER;
5560     l_group_rec                        GROUP_REC_TYPE := p_group_rec;
5561 
5562    dss_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
5563    dss_msg_count     NUMBER := 0;
5564    dss_msg_data      VARCHAR2(2000):= null;
5565    l_test_security   VARCHAR2(1):= 'F';
5566    l_debug_prefix                      VARCHAR2(30) := '';
5567   BEGIN
5568 
5569     -- standard start of API savepoint
5570     SAVEPOINT create_group;
5571 
5572     -- Check if API is called in debug mode. If yes, enable debug.
5573     --enable_debug;
5574 
5575     -- Debug info.
5576     /*IF g_debug THEN
5577       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'create_group (+)');
5578     END IF;
5579     */
5580     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
5581         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'create_group (+)',
5582                                p_msg_level=>fnd_log.level_procedure);
5583     END IF;
5584 
5585     -- initialize message list if p_init_msg_list is set to TRUE.
5586     IF FND_API.to_Boolean(p_init_msg_list) THEN
5587       FND_MSG_PUB.initialize;
5588     END IF;
5589 
5590     -- initialize API return status to success.
5591     x_return_status := FND_API.G_RET_STS_SUCCESS;
5592 
5593     -- enable policy function if it is disabled.
5594 
5595     l_context := NVL(SYS_CONTEXT('hz', g_apps_context), 'N');
5596     IF l_context = 'N' THEN
5597       hz_common_pub.disable_cont_source_security;
5598     END IF;
5599 
5600     -- call to business logic.
5601     do_create_party(
5602       p_party_type                      => 'GROUP',
5603       p_party_usage_code                => null,
5604       p_group_rec                       => l_group_rec,
5605       x_party_id                        => x_party_id,
5606       x_party_number                    => x_party_number,
5607       x_profile_id                      => l_profile_id,
5608       x_return_status                   => x_return_status,
5609       p_organization_rec                => G_MISS_ORGANIZATION_REC,
5610       p_person_rec                      => G_MISS_PERSON_REC );
5611 
5612     -- Bug 2486394 Check if the DSS security is granted to the user
5613     -- Bug 3818648: check dss profile before call test_instance.
5614     --
5615     IF NVL(fnd_profile.value('HZ_DSS_ENABLED'), 'N') = 'Y' THEN
5616       l_test_security :=
5617            hz_dss_util_pub.test_instance(
5618                   p_operation_code     => 'INSERT',
5619                   p_db_object_name     => 'HZ_PARTIES',
5620                   p_instance_pk1_value => x_party_id,
5621                   p_user_name          => fnd_global.user_name,
5622                   x_return_status      => dss_return_status,
5623                   x_msg_count          => dss_msg_count,
5624                   x_msg_data           => dss_msg_data);
5625 
5626       if dss_return_status <> fnd_api.g_ret_sts_success THEN
5627          RAISE FND_API.G_EXC_ERROR;
5628       end if;
5629 
5630       if (l_test_security <> 'T' OR l_test_security <> FND_API.G_TRUE) then
5631          --
5632          -- Bug 3835601: replaced the dss message with a more user friendly message
5633          --
5634          FND_MESSAGE.SET_NAME('AR', 'HZ_DSS_NO_INSERT_PRIVILEGE');
5635          FND_MESSAGE.SET_TOKEN('ENTITY_NAME',
5636                                hz_dss_util_pub.get_display_name('HZ_PARTIES', null));
5637          FND_MSG_PUB.ADD;
5638          RAISE FND_API.G_EXC_ERROR;
5639       end if;
5640     END IF;
5641 
5642     -- Invoke business event system.
5643     IF(HZ_UTILITY_V2PUB.G_EXECUTE_API_CALLOUTS in ('Y', 'EVENTS_ENABLED')) THEN
5644       HZ_BUSINESS_EVENT_V2PVT.create_group_event (l_group_rec);
5645     END IF;
5646 
5647     -- enable policy function if it was enabled before calling
5648     -- this procedure.
5649 
5650     IF l_context = 'N' THEN
5651       hz_common_pub.enable_cont_source_security;
5652     END IF;
5653 
5654     --Standard call to get message count and if count is 1, get message info.
5655     fnd_msg_pub.count_and_get(
5656       p_encoded                      => fnd_api.g_false,
5657       p_count                        => x_msg_count,
5658       p_data                         => x_msg_data);
5659 
5660     -- Debug info.
5661     /*IF g_debug THEN
5662       hz_utility_v2pub.debug_return_messages (
5663         x_msg_count, x_msg_data, 'WARNING');
5664       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'create_group (-)');
5665     END IF;
5666     */
5667     IF  fnd_log.level_exception>=fnd_log.g_current_runtime_level THEN
5668          hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
5669                                p_msg_data=>x_msg_data,
5670                                p_msg_type=>'WARNING',
5671                                p_msg_level=>fnd_log.level_exception);
5672      END IF;
5673      IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
5674          hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'create_group (-)',
5675                                 p_msg_level=>fnd_log.level_procedure);
5676      END IF;
5677 
5678 
5679     -- Check if API is called in debug mode. If yes, disable debug.
5680     --disable_debug;
5681 
5682   EXCEPTION
5683     WHEN FND_API.G_EXC_ERROR THEN
5684       ROLLBACK TO create_group;
5685 
5686       IF l_context = 'N' THEN
5687         hz_common_pub.enable_cont_source_security;
5688       END IF;
5689 
5690       x_return_status := fnd_api.g_ret_sts_error;
5691 
5692       fnd_msg_pub.count_and_get(
5693         p_encoded                    => fnd_api.g_false,
5694         p_count                      => x_msg_count,
5695         p_data                       => x_msg_data);
5696 
5697       -- Debug info.
5698       /*IF g_debug THEN
5699         hz_utility_v2pub.debug_return_messages (
5700           x_msg_count, x_msg_data, 'ERROR');
5701         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'create_group (-)');
5702       END IF;
5703       */
5704       IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
5705         hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
5706                                p_msg_data=>x_msg_data,
5707                                p_msg_type=>'ERROR',
5708                                p_msg_level=>fnd_log.level_error);
5709       END IF;
5710       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
5711         hz_utility_v2pub.debug(p_message=>'create_group (-)',
5712                                p_prefix=>l_debug_prefix,
5713                                p_msg_level=>fnd_log.level_procedure);
5714       END IF;
5715 
5716       -- Check if API is called in debug mode. If yes, disable debug.
5717       --disable_debug;
5718 
5719     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5720       ROLLBACK TO create_group;
5721 
5722       IF l_context = 'N' THEN
5723         hz_common_pub.enable_cont_source_security;
5724       END IF;
5725 
5726       x_return_status := fnd_api.g_ret_sts_unexp_error;
5727 
5728       fnd_msg_pub.count_and_get(
5729         p_encoded                    => fnd_api.g_false,
5730         p_count                      => x_msg_count,
5731         p_data                       => x_msg_data);
5732 
5733       -- Debug info.
5734       /*IF g_debug THEN
5735         hz_utility_v2pub.debug_return_messages (
5736           x_msg_count, x_msg_data, 'UNEXPECTED ERROR');
5737         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'create_group (-)');
5738       END IF;
5739       */
5740       IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
5741         hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
5742                                p_msg_data=>x_msg_data,
5743                                p_msg_type=>'UNEXPECTED ERROR',
5744                                p_msg_level=>fnd_log.level_error);
5745       END IF;
5746       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
5747         hz_utility_v2pub.debug(p_message=>'create_group (-)',
5748                                p_prefix=>l_debug_prefix,
5749                                p_msg_level=>fnd_log.level_procedure);
5750       END IF;
5751 
5752       -- Check if API is called in debug mode. If yes, disable debug.
5753       --disable_debug;
5754 
5755     WHEN OTHERS THEN
5756       ROLLBACK TO create_group;
5757 
5758       IF l_context = 'N' THEN
5759         hz_common_pub.enable_cont_source_security;
5760       END IF;
5761 
5762       x_return_status := fnd_api.g_ret_sts_unexp_error;
5763 
5764       fnd_message.set_name('AR', 'HZ_API_OTHERS_EXCEP');
5765       fnd_message.set_token('ERROR',SQLERRM);
5766       fnd_msg_pub.add;
5767 
5768       fnd_msg_pub.count_and_get(
5769         p_encoded                    => fnd_api.g_false,
5770         p_count                      => x_msg_count,
5771         p_data                       => x_msg_data);
5772 
5773       -- Debug info.
5774       /*IF g_debug THEN
5775         hz_utility_v2pub.debug_return_messages (
5776           x_msg_count, x_msg_data, 'SQL ERROR');
5777         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'create_group (-)');
5778       END IF;
5779       */
5780       IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
5781         hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
5782                                p_msg_data=>x_msg_data,
5783                                p_msg_type=>'SQL ERROR',
5784                                p_msg_level=>fnd_log.level_error);
5785       END IF;
5786       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
5787         hz_utility_v2pub.debug(p_message=>'create_group (-)',
5788                                p_prefix=>l_debug_prefix,
5789                                p_msg_level=>fnd_log.level_procedure);
5790     END IF;
5791 
5792       -- Check if API is called in debug mode. If yes, disable debug.
5793       --disable_debug;
5794 
5795   END create_group;
5796 
5797   /**
5798    * PROCEDURE update_group
5799    *
5800    * DESCRIPTION
5801    *     Updates group.
5802    *
5803    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
5804    *     HZ_BUSINESS_EVENT_V2PVT.update_group_event
5805    *
5806    * ARGUMENTS
5807    *   IN:
5808    *     p_init_msg_list      Initialize message stack if it is set to
5809    *                          FND_API.G_TRUE. Default is fnd_api.g_false.
5810    *     p_group_rec          Group record.
5811    *   IN/OUT:
5812    *     p_party_object_version_number  Used for locking the being updated record.
5813    *   OUT:
5814    *     x_return_status      Return status after the call. The status can
5815    *                          be FND_API.G_RET_STS_SUCCESS (success),
5816    *                          fnd_api.g_ret_sts_error (error),
5817    *                          fnd_api.g_ret_sts_unexp_error (unexpected error).
5818    *     x_msg_count          Number of messages in message stack.
5819    *     x_msg_data           Message text if x_msg_count is 1.
5820    *
5821    * NOTES
5822    *
5823    * MODIFICATION HISTORY
5824    *
5825    *   07-23-2001    Indrajit Sen        o Created.
5826    *
5827    */
5828 
5829   PROCEDURE update_group (
5830     p_init_msg_list                    IN     VARCHAR2 := fnd_api.g_false,
5831     p_group_rec                        IN     GROUP_REC_TYPE,
5832     p_party_object_version_number      IN OUT NOCOPY NUMBER,
5833     x_return_status                    OUT NOCOPY    VARCHAR2,
5834     x_msg_count                        OUT NOCOPY    NUMBER,
5835     x_msg_data                         OUT NOCOPY    VARCHAR2
5836   ) IS
5837 
5838     l_context                          VARCHAR2(30);
5839     l_api_name                         CONSTANT VARCHAR2(30) := 'update_group';
5840     l_profile_id                       NUMBER;
5841     l_group_rec                        GROUP_REC_TYPE := p_group_rec;
5842     l_old_group_rec                    GROUP_REC_TYPE := p_group_rec;
5843 
5844    dss_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
5845    dss_msg_count     NUMBER := 0;
5846    dss_msg_data      VARCHAR2(2000):= null;
5847    l_test_security   VARCHAR2(1):= 'F';
5848    l_debug_prefix                      VARCHAR2(30) := '';
5849 
5850   BEGIN
5851 
5852     -- standard start of API savepoint
5853     SAVEPOINT update_group;
5854 
5855     -- Check if API is called in debug mode. If yes, enable debug.
5856     --enable_debug;
5857 
5858     -- Debug info.
5859     /*IF g_debug THEN
5860       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'update_group (+)');
5861     END IF;
5862     */
5863     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
5864         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'update_group (+)',
5865                                p_msg_level=>fnd_log.level_procedure);
5866     END IF;
5867 
5868 
5869     -- initialize message list if p_init_msg_list is set to TRUE.
5870     IF FND_API.to_Boolean(p_init_msg_list) THEN
5871       FND_MSG_PUB.initialize;
5872     END IF;
5873 
5874     -- initialize API return status to success.
5875     x_return_status := FND_API.G_RET_STS_SUCCESS;
5876 
5877     -- enable policy function if it is disabled.
5878 
5879     l_context := NVL(SYS_CONTEXT('hz', g_apps_context), 'N');
5880     IF l_context = 'N' THEN
5881       hz_common_pub.disable_cont_source_security;
5882     END IF;
5883 
5884     /**
5885     get_group_rec is checking if the group party has been
5886     passed in.
5887 
5888     -- make sure GROUP party has been passed in
5889     BEGIN
5890       SELECT 1 INTO l_count
5891       FROM   HZ_PARTIES
5892       WHERE  PARTY_ID = p_group_rec.party_rec.party_id
5893       AND    PARTY_TYPE = 'GROUP';
5894     EXCEPTION
5895       WHEN NO_DATA_FOUND THEN
5896         fnd_message.set_name('AR', 'HZ_API_NO_RECORD');
5897         fnd_message.set_token('RECORD', 'group');
5898         fnd_message.set_token('VALUE', to_char(p_group_rec.party_rec.party_id));
5899         fnd_msg_pub.add;
5900         RAISE FND_API.G_EXC_ERROR;
5901     END;
5902     **/
5903 
5904       IF (l_group_rec.party_rec.orig_system is not null
5905          and l_group_rec.party_rec.orig_system <>fnd_api.g_miss_char)
5906        and (l_group_rec.party_rec.orig_system_reference is not null
5907          and l_group_rec.party_rec.orig_system_reference <>fnd_api.g_miss_char)
5908        and (l_group_rec.party_rec.party_id = FND_API.G_MISS_NUM or l_group_rec.party_rec.party_id is null) THEN
5909 
5910         hz_orig_system_ref_pub.get_owner_table_id
5911                         (p_orig_system => l_group_rec.party_rec.orig_system,
5912                         p_orig_system_reference => l_group_rec.party_rec.orig_system_reference,
5913                         p_owner_table_name => 'HZ_PARTIES',
5914                         x_owner_table_id => l_group_rec.party_rec.party_id,
5915                         x_return_status => x_return_status);
5916 
5917             IF x_return_status <> fnd_api.g_ret_sts_success THEN
5918                 RAISE FND_API.G_EXC_ERROR;
5919             END IF;
5920       END IF;
5921 
5922     -- Get old records. Will be used by validation.
5923     get_group_rec (
5924       p_party_id                     => l_group_rec.party_rec.party_id,
5925       x_group_rec                    => l_old_group_rec,
5926       x_return_status                => x_return_status,
5927       x_msg_count                    => x_msg_count,
5928       x_msg_data                     => x_msg_data);
5929 
5930     IF x_return_status = fnd_api.g_ret_sts_error THEN
5931       RAISE fnd_api.g_exc_error;
5932     ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
5933       RAISE fnd_api.g_exc_unexpected_error;
5934     END IF;
5935 
5936     -- Bug 2486394 Check if the DSS security is granted to the user
5937     -- Bug 3818648: check dss profile before call test_instance.
5938     --
5939     IF NVL(fnd_profile.value('HZ_DSS_ENABLED'), 'N') = 'Y' THEN
5940       l_test_security :=
5941            hz_dss_util_pub.test_instance(
5942                   p_operation_code     => 'UPDATE',
5943                   p_db_object_name     => 'HZ_PARTIES',
5944                   p_instance_pk1_value => l_group_rec.party_rec.party_id,
5945                   p_user_name          => fnd_global.user_name,
5946                   x_return_status      => dss_return_status,
5947                   x_msg_count          => dss_msg_count,
5948                   x_msg_data           => dss_msg_data);
5949 
5950       if dss_return_status <> fnd_api.g_ret_sts_success THEN
5951          RAISE FND_API.G_EXC_ERROR;
5952       end if;
5953 
5954       if (l_test_security <> 'T' OR l_test_security <> FND_API.G_TRUE) then
5955          --
5956          -- Bug 3835601: replaced the dss message with a more user friendly message
5957          --
5958          FND_MESSAGE.SET_NAME('AR', 'HZ_DSS_NO_UPDATE_PRIVILEGE');
5959          FND_MESSAGE.SET_TOKEN('ENTITY_NAME',
5960                                hz_dss_util_pub.get_display_name('HZ_PARTIES', null));
5961          FND_MSG_PUB.ADD;
5962          RAISE FND_API.G_EXC_ERROR;
5963       end if;
5964     END IF;
5965 
5966     -- call to business logic.
5967     do_update_party(
5968       p_party_type                      => 'GROUP',
5969       p_group_rec                       => l_group_rec,
5970       p_old_group_rec                   => l_old_group_rec,
5971       p_party_object_version_number     => p_party_object_version_number,
5972       x_profile_id                      => l_profile_id,
5973       x_return_status                   => x_return_status,
5974       p_organization_rec                => G_MISS_ORGANIZATION_REC,
5975       p_person_rec                      => G_MISS_PERSON_REC );
5976 
5977     -- Invoke business event system.
5978     IF(HZ_UTILITY_V2PUB.G_EXECUTE_API_CALLOUTS in ('Y', 'EVENTS_ENABLED')) THEN
5979       HZ_BUSINESS_EVENT_V2PVT.update_group_event (l_group_rec , l_old_group_rec);
5980     END IF;
5981 
5982     -- enable policy function if it was enabled before calling
5983     -- this procedure.
5984 
5985     IF l_context = 'N' THEN
5986       hz_common_pub.enable_cont_source_security;
5987     END IF;
5988 
5989     --Standard call to get message count and if count is 1, get message info.
5990     fnd_msg_pub.count_and_get(
5991       p_encoded                      => fnd_api.g_false,
5992       p_count                        => x_msg_count,
5993       p_data                         => x_msg_data);
5994 
5995     -- Debug info.
5996     /*IF g_debug THEN
5997         hz_utility_v2pub.debug_return_messages (
5998             x_msg_count, x_msg_data, 'WARNING');
5999         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'update_group (-)');
6000     END IF;
6001     */
6002     IF fnd_log.level_exception>=fnd_log.g_current_runtime_level THEN
6003          hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
6004                                p_msg_data=>x_msg_data,
6005                                p_msg_type=>'WARNING',
6006                                p_msg_level=>fnd_log.level_exception);
6007     END IF;
6008     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
6009          hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'update_group (-)',
6010                                 p_msg_level=>fnd_log.level_procedure);
6011     END IF;
6012 
6013     -- Check if API is called in debug mode. If yes, disable debug.
6014     --disable_debug;
6015 
6016   EXCEPTION
6017     WHEN FND_API.G_EXC_ERROR THEN
6018       ROLLBACK TO update_group;
6019 
6020       IF l_context = 'N' THEN
6021         hz_common_pub.enable_cont_source_security;
6022       END IF;
6023 
6024       x_return_status := fnd_api.g_ret_sts_error;
6025 
6026       fnd_msg_pub.count_and_get(
6027         p_encoded                    => fnd_api.g_false,
6028         p_count                      => x_msg_count,
6029         p_data                       => x_msg_data);
6030 
6031       -- Debug info.
6032       /*IF g_debug THEN
6033         hz_utility_v2pub.debug_return_messages (
6034           x_msg_count, x_msg_data, 'ERROR');
6035         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'update_group (-)');
6036       END IF;
6037       */
6038       IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
6039         hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
6040                                p_msg_data=>x_msg_data,
6041                                p_msg_type=>'ERROR',
6042                                p_msg_level=>fnd_log.level_error);
6043       END IF;
6044       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
6045         hz_utility_v2pub.debug(p_message=>'update_group (-)',
6046                                p_prefix=>l_debug_prefix,
6047                                p_msg_level=>fnd_log.level_procedure);
6048     END IF;
6049 
6050       -- Check if API is called in debug mode. If yes, disable debug.
6051       --disable_debug;
6052 
6053     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6054       ROLLBACK TO update_group;
6055 
6056       IF l_context = 'N' THEN
6057         hz_common_pub.enable_cont_source_security;
6058       END IF;
6059 
6060       x_return_status := fnd_api.g_ret_sts_unexp_error;
6061 
6062       fnd_msg_pub.count_and_get(
6063         p_encoded                    => fnd_api.g_false,
6064         p_count                      => x_msg_count,
6065         p_data                       => x_msg_data);
6066 
6067       -- Debug info.
6068       /*IF g_debug THEN
6069         hz_utility_v2pub.debug_return_messages (
6070           x_msg_count, x_msg_data, 'UNEXPECTED ERROR');
6071         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'update_group (-)');
6072       END IF;
6073       */
6074       IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
6075         hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
6076                                p_msg_data=>x_msg_data,
6077                                p_msg_type=>'UNEXPECTED ERROR',
6078                                p_msg_level=>fnd_log.level_error);
6079       END IF;
6080       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
6081         hz_utility_v2pub.debug(p_message=>'update_group (-)',
6082                                p_prefix=>l_debug_prefix,
6083                                p_msg_level=>fnd_log.level_procedure);
6084     END IF;
6085 
6086       -- Check if API is called in debug mode. If yes, disable debug.
6087       --disable_debug;
6088 
6089     WHEN OTHERS THEN
6090       ROLLBACK TO update_group;
6091 
6092       IF l_context = 'N' THEN
6093         hz_common_pub.enable_cont_source_security;
6094       END IF;
6095 
6096       x_return_status := fnd_api.g_ret_sts_unexp_error;
6097 
6098       fnd_message.set_name('AR', 'HZ_API_OTHERS_EXCEP');
6099       fnd_message.set_token('ERROR',SQLERRM);
6100       fnd_msg_pub.add;
6101 
6102       fnd_msg_pub.count_and_get(
6103         p_encoded                    => fnd_api.g_false,
6104         p_count                      => x_msg_count,
6105         p_data                       => x_msg_data);
6106 
6107       -- Debug info.
6108       /*IF g_debug THEN
6109         hz_utility_v2pub.debug_return_messages (
6110           x_msg_count, x_msg_data, 'SQL ERROR');
6111         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'update_group (-)');
6112       END IF;
6113       */
6114       IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
6115         hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
6116                                p_msg_data=>x_msg_data,
6117                                p_msg_type=>'SQL ERROR',
6118                                p_msg_level=>fnd_log.level_error);
6119       END IF;
6120       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
6121         hz_utility_v2pub.debug(p_message=>'update_group (-)',
6122                                p_prefix=>l_debug_prefix,
6123                                p_msg_level=>fnd_log.level_procedure);
6124       END IF;
6125 
6126 
6127       -- Check if API is called in debug mode. If yes, disable debug.
6128       --disable_debug;
6129 
6130   END update_group;
6131 
6132   /**
6133    * PROCEDURE create_organization
6134    *
6135    * DESCRIPTION
6136    *     Creates organization.
6137    *
6138    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
6139    *     HZ_BUSINESS_EVENT_V2PVT.create_organization_event
6140    *
6141    * ARGUMENTS
6142    *   IN:
6143    *     p_init_msg_list      Initialize message stack if it is set to
6144    *                          FND_API.G_TRUE. Default is fnd_api.g_false.
6145    *     p_organization_rec   Organization record.
6146    *     p_party_usage_code   Party Usage Code.
6147    *   IN/OUT:
6148    *   OUT:
6149    *     x_party_id           Party ID.
6150    *     x_party_number       Party number.
6151    *     x_profile_id         Organization profile ID.
6152    *     x_return_status      Return status after the call. The status can
6153    *                          be FND_API.G_RET_STS_SUCCESS (success),
6154    *                          fnd_api.g_ret_sts_error (error),
6155    *                          fnd_api.g_ret_sts_unexp_error (unexpected error).
6156    *     x_msg_count          Number of messages in message stack.
6157    *     x_msg_data           Message text if x_msg_count is 1.
6158    *
6159    * NOTES
6160    *
6161    * MODIFICATION HISTORY
6162    *
6163    *   07-23-2001    Indrajit Sen        o Created.
6164    *   26-NOV-2001   Joe del Callar      Bug 2117973: modified to conform to
6165    *                                     PL/SQL coding standards.
6166    *                                     Changed select...intos into cursors.
6167    *
6168    */
6169 
6170   PROCEDURE create_organization (
6171     p_init_msg_list                    IN     VARCHAR2 := fnd_api.g_false,
6172     p_organization_rec                 IN     ORGANIZATION_REC_TYPE,
6173     p_party_usage_code                 IN     VARCHAR2,
6174     x_return_status                    OUT    NOCOPY VARCHAR2,
6175     x_msg_count                        OUT    NOCOPY NUMBER,
6176     x_msg_data                         OUT    NOCOPY VARCHAR2,
6177     x_party_id                         OUT    NOCOPY NUMBER,
6178     x_party_number                     OUT    NOCOPY VARCHAR2,
6179     x_profile_id                       OUT    NOCOPY NUMBER
6180   ) IS
6181 
6182     l_api_name                        CONSTANT VARCHAR2(30)  := 'create_organization';
6183     l_organization_rec                ORGANIZATION_REC_TYPE := p_organization_rec;
6184     l_context                         VARCHAR2(30);
6185 
6186    dss_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
6187    dss_msg_count     NUMBER := 0;
6188    dss_msg_data      VARCHAR2(2000):= null;
6189    l_test_security   VARCHAR2(1):= 'F';
6190    l_debug_prefix                      VARCHAR2(30) := '';
6191 
6192   BEGIN
6193 
6194     -- standard start of API savepoint
6195     SAVEPOINT create_organization;
6196 
6197     -- Check if API is called in debug mode. If yes, enable debug.
6198     --enable_debug;
6199 
6200     -- Debug info.
6201     /*IF g_debug THEN
6202       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'create_organization (+)');
6203     END IF;
6204     */
6205 
6206     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
6207         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'create_organization (+)',
6208                                p_msg_level=>fnd_log.level_procedure);
6209     END IF;
6210 
6211 
6212     -- initialize message list if p_init_msg_list is set to TRUE.
6213     IF fnd_api.to_boolean(p_init_msg_list) THEN
6214       fnd_msg_pub.initialize;
6215     END IF;
6216 
6217     -- initialize API return status to success.
6218     x_return_status := FND_API.G_RET_STS_SUCCESS;
6219 
6220     -- Debug info.
6221     /*IF g_debug THEN
6222       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'before LoadDataSources (+)');
6223     END IF;
6224     */
6225     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
6226         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'before LoadDataSources (+)',
6227                                p_msg_level=>fnd_log.level_procedure);
6228     END IF;
6229 
6230     -- enable policy function if it is disabled.
6231 
6232     l_context := NVL(SYS_CONTEXT('hz', g_apps_context), 'N');
6233     IF l_context = 'N' THEN
6234       hz_common_pub.disable_cont_source_security;
6235     END IF;
6236 
6237     -- cache if mix-n-match is enabled
6238 
6239     -- IF g_org_mixnmatch_enabled IS NULL THEN
6240     HZ_MIXNM_UTILITY.LoadDataSources(
6241       'HZ_ORGANIZATION_PROFILES', g_org_entity_attr_id,
6242       g_org_mixnmatch_enabled, g_org_selected_datasources);
6243     -- END IF;
6244 
6245     -- Debug info.
6246     /*IF g_debug THEN
6247       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'after LoadDataSources (+)');
6248     END IF;
6249     */
6250     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
6251         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'after LoadDataSources (+)',
6252                                p_msg_level=>fnd_log.level_procedure);
6253     END IF;
6254 
6255     -- call to business logic.
6256     do_create_party(
6257       p_party_type                    => 'ORGANIZATION',
6258       p_party_usage_code              => p_party_usage_code,
6259       p_organization_rec              => l_organization_rec,
6260       x_party_id                      => x_party_id,
6261       x_party_number                  => x_party_number,
6262       x_profile_id                    => x_profile_id,
6263       x_return_status                 => x_return_status,
6264       p_person_rec                    => G_MISS_PERSON_REC,
6265       p_group_rec                     => G_MISS_GROUP_REC );
6266 
6267     -- call to insert credit related columns to hz_credit_ratings.
6268 
6269     IF l_organization_rec.actual_content_source IN
6270       (G_MISS_CONTENT_SOURCE_TYPE, G_SST_SOURCE_TYPE)
6271     THEN
6272       populate_credit_rating(
6273         p_create_update_flag      => 'C',
6274         p_organization_rec        => l_organization_rec,
6275         x_return_status           => x_return_status );
6276 
6277       IF x_return_status <> fnd_api.g_ret_sts_success THEN
6278         RAISE fnd_api.g_exc_error;
6279       END IF;
6280     END IF;
6281 
6282     -- Bug 2486394 -Check if the DSS security is granted to the user
6283     -- Bug 3818648: check dss profile before call test_instance.
6284     --
6285     IF NVL(fnd_profile.value('HZ_DSS_ENABLED'), 'N') = 'Y' THEN
6286       l_test_security :=
6287            hz_dss_util_pub.test_instance(
6288                   p_operation_code     => 'INSERT',
6289                   p_db_object_name     => 'HZ_PARTIES',
6290                   p_instance_pk1_value => x_party_id,
6291                   p_user_name          => fnd_global.user_name,
6292                   x_return_status      => dss_return_status,
6293                   x_msg_count          => dss_msg_count,
6294                   x_msg_data           => dss_msg_data);
6295 
6296       if dss_return_status <> fnd_api.g_ret_sts_success THEN
6297          RAISE FND_API.G_EXC_ERROR;
6298       end if;
6299 
6300       if (l_test_security <> 'T' OR l_test_security <> FND_API.G_TRUE) then
6301          --
6302          -- Bug 3835601: replaced the dss message with a more user friendly message
6303          --
6304          FND_MESSAGE.SET_NAME('AR', 'HZ_DSS_NO_INSERT_PRIVILEGE');
6305          FND_MESSAGE.SET_TOKEN('ENTITY_NAME',
6306                                hz_dss_util_pub.get_display_name(null, 'ORGANIZATION'));
6307          FND_MSG_PUB.ADD;
6308          RAISE FND_API.G_EXC_ERROR;
6309       end if;
6310     END IF;
6311 
6312     -- enable policy function if it was enabled before calling
6313     -- this procedure.
6314 
6315     IF l_context = 'N' THEN
6316       hz_common_pub.enable_cont_source_security;
6317     END IF;
6318 
6319     --Standard call to get message count and if count is 1, get message info.
6320     fnd_msg_pub.count_and_get(
6321       p_encoded                      => fnd_api.g_false,
6322       p_count                        => x_msg_count,
6323       p_data                         => x_msg_data);
6324 
6325     -- Debug info.
6326     /*IF g_debug THEN
6327       hz_utility_v2pub.debug_return_messages(x_msg_count,
6328                                              x_msg_data, 'WARNING');
6329       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'create_organization (-)');
6330     END IF;
6331     */
6332     IF fnd_log.level_exception>=fnd_log.g_current_runtime_level THEN
6333          hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
6334                                p_msg_data=>x_msg_data,
6335                                p_msg_type=>'WARNING',
6336                                p_msg_level=>fnd_log.level_exception);
6337     END IF;
6338     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
6339          hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'create_organization (-)',
6340                                 p_msg_level=>fnd_log.level_procedure);
6341     END IF;
6342 
6343 
6344     -- Check if API is called in debug mode. If yes, disable debug.
6345     --disable_debug;
6346 
6347   EXCEPTION
6348     WHEN fnd_api.g_exc_error THEN
6349       ROLLBACK TO create_organization;
6350 
6351       IF l_context = 'N' THEN
6352         hz_common_pub.enable_cont_source_security;
6353       END IF;
6354 
6355       x_return_status := fnd_api.g_ret_sts_error;
6356 
6357       fnd_msg_pub.count_and_get(
6358         p_encoded                    => fnd_api.g_false,
6359         p_count                      => x_msg_count,
6360         p_data                       => x_msg_data);
6361 
6362       -- Debug info.
6363       /*IF g_debug THEN
6364         hz_utility_v2pub.debug_return_messages (
6365           x_msg_count, x_msg_data, 'ERROR');
6366         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'create_organization (-)');
6367       END IF;
6368       */
6369       IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
6370         hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
6371                                p_msg_data=>x_msg_data,
6372                                p_msg_type=>'ERROR',
6373                                p_msg_level=>fnd_log.level_error);
6374       END IF;
6375       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
6376         hz_utility_v2pub.debug(p_message=>'create_organization (-)',
6377                                p_prefix=>l_debug_prefix,
6378                                p_msg_level=>fnd_log.level_procedure);
6379       END IF;
6380 
6381       -- Check if API is called in debug mode. If yes, disable debug.
6382       --disable_debug;
6383 
6384     WHEN fnd_api.g_exc_unexpected_error THEN
6385       ROLLBACK TO create_organization;
6386 
6387       IF l_context = 'N' THEN
6388         hz_common_pub.enable_cont_source_security;
6389       END IF;
6390 
6391       x_return_status := fnd_api.g_ret_sts_unexp_error;
6392 
6393       fnd_msg_pub.count_and_get(
6394         p_encoded                    => fnd_api.g_false,
6395         p_count                      => x_msg_count,
6396         p_data                       => x_msg_data);
6397 
6398       -- Debug info.
6399       /*IF g_debug THEN
6400         hz_utility_v2pub.debug_return_messages (
6401           x_msg_count, x_msg_data, 'UNEXPECTED ERROR');
6402         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'create_organization (-)');
6403       END IF;
6404       */
6405       IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
6406         hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
6407                                p_msg_data=>x_msg_data,
6408                                p_msg_type=>'UNEXPECTED ERROR',
6409                                p_msg_level=>fnd_log.level_error);
6410       END IF;
6411       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
6412         hz_utility_v2pub.debug(p_message=>'create_organization (-)',
6413                                p_prefix=>l_debug_prefix,
6414                                p_msg_level=>fnd_log.level_procedure);
6415       END IF;
6416 
6417       -- Check if API is called in debug mode. If yes, disable debug.
6418       --disable_debug;
6419 
6420     WHEN OTHERS THEN
6421       ROLLBACK TO create_organization;
6422 
6423       IF l_context = 'N' THEN
6424         hz_common_pub.enable_cont_source_security;
6425       END IF;
6426 
6427       x_return_status := fnd_api.g_ret_sts_unexp_error;
6428 
6429       fnd_message.set_name('AR', 'HZ_API_OTHERS_EXCEP');
6430       fnd_message.set_token('ERROR',SQLERRM);
6431       fnd_msg_pub.add;
6432 
6433       fnd_msg_pub.count_and_get(
6434         p_encoded                    => fnd_api.g_false,
6435         p_count                      => x_msg_count,
6436         p_data                       => x_msg_data);
6437 
6438       -- Debug info.
6439       /*IF g_debug THEN
6440         hz_utility_v2pub.debug_return_messages (
6441           x_msg_count, x_msg_data, 'SQL ERROR');
6442         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'create_organization (-)');
6443       END IF;
6444       */
6445       IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
6446         hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
6447                                p_msg_data=>x_msg_data,
6448                                p_msg_type=>'SQL ERROR',
6449                                p_msg_level=>fnd_log.level_error);
6450       END IF;
6451       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
6452         hz_utility_v2pub.debug(p_message=>'create_organization (-)',
6453                                p_prefix=>l_debug_prefix,
6454                                p_msg_level=>fnd_log.level_procedure);
6455       END IF;
6456 
6457       -- Check if API is called in debug mode. If yes, disable debug.
6458       --disable_debug;
6459 
6460   END create_organization;
6461 
6462   /**
6463    * PROCEDURE create_organization
6464    *
6465    * DESCRIPTION
6466    *     Creates organization.
6467    *
6468    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
6469    *     HZ_BUSINESS_EVENT_V2PVT.create_organization_event
6470    *
6471    * ARGUMENTS
6472    *   IN:
6473    *     p_init_msg_list      Initialize message stack if it is set to
6474    *                          FND_API.G_TRUE. Default is fnd_api.g_false.
6475    *     p_organization_rec   Organization record.
6476    *   IN/OUT:
6477    *   OUT:
6478    *     x_party_id           Party ID.
6479    *     x_party_number       Party number.
6480    *     x_profile_id         Organization profile ID.
6481    *     x_return_status      Return status after the call. The status can
6482    *                          be FND_API.G_RET_STS_SUCCESS (success),
6483    *                          fnd_api.g_ret_sts_error (error),
6484    *                          fnd_api.g_ret_sts_unexp_error (unexpected error).
6485    *     x_msg_count          Number of messages in message stack.
6486    *     x_msg_data           Message text if x_msg_count is 1.
6487    *
6488    * NOTES
6489    *
6490    * MODIFICATION HISTORY
6491    *
6492    *   07-23-2001    Indrajit Sen        o Created.
6493    *   26-NOV-2001   Joe del Callar      Bug 2117973: modified to conform to
6494    *                                     PL/SQL coding standards.
6495    *                                     Changed select...intos into cursors.
6496    *
6497    */
6498 
6499   PROCEDURE create_organization (
6500     p_init_msg_list                    IN     VARCHAR2 := fnd_api.g_false,
6501     p_organization_rec                 IN     ORGANIZATION_REC_TYPE,
6502     x_return_status                    OUT    NOCOPY VARCHAR2,
6503     x_msg_count                        OUT    NOCOPY NUMBER,
6504     x_msg_data                         OUT    NOCOPY VARCHAR2,
6505     x_party_id                         OUT    NOCOPY NUMBER,
6506     x_party_number                     OUT    NOCOPY VARCHAR2,
6507     x_profile_id                       OUT    NOCOPY NUMBER
6508   ) IS
6509 
6510   BEGIN
6511 
6512     create_organization (
6513       p_init_msg_list             => p_init_msg_list,
6514       p_organization_rec          => p_organization_rec,
6515       p_party_usage_code          => null,
6516       x_return_status             => x_return_status,
6517       x_msg_count                 => x_msg_count,
6518       x_msg_data                  => x_msg_data,
6519       x_party_id                  => x_party_id,
6520       x_party_number              => x_party_number,
6521       x_profile_id                => x_profile_id
6522     );
6523 
6524   END create_organization;
6525 
6526   /**
6527    * PROCEDURE update_organization
6528    *
6529    * DESCRIPTION
6530    *     Updates organization.
6531    *
6532    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
6533    *     HZ_BUSINESS_EVENT_V2PVT.update_organization_event
6534    *
6535    * ARGUMENTS
6536    *   IN:
6537    *     p_init_msg_list      Initialize message stack if it is set to
6538    *                          FND_API.G_TRUE. Default is fnd_api.g_false.
6539    *     p_organization_rec   Organization record.
6540    *   IN/OUT:
6541    *     p_party_object_version_number  Used for locking the being updated record.
6542    *   OUT:
6543    *     x_profile_id         Organization profile ID.
6544    *     x_return_status      Return status after the call. The status can
6545    *                          be fnd_api.g_ret_sts_success (success),
6546    *                          fnd_api.g_ret_sts_error (error),
6547    *                          fnd_api.g_ret_sts_unexp_error (unexpected error).
6548    *     x_msg_count          Number of messages in message stack.
6549    *     x_msg_data           Message text if x_msg_count is 1.
6550    *
6551    * NOTES
6552    *
6553    * MODIFICATION HISTORY
6554    *
6555    *   07-23-2001    Indrajit Sen        o Created.
6556    *   26-NOV-2001   Joe del Callar      Bug 2117973: modified to conform to
6557    *                                     PL/SQL coding standards.
6558    *                                     Changed select...intos into cursors.
6559    *   09-03-2002    Jyoti Pandey        Added Data security Functionality
6560    *
6561    */
6562 
6563   PROCEDURE update_organization (
6564     p_init_msg_list                    IN     VARCHAR2 := fnd_api.g_false,
6565     p_organization_rec                 IN     ORGANIZATION_REC_TYPE,
6566     p_party_object_version_number      IN OUT NOCOPY NUMBER,
6567     x_profile_id                       OUT NOCOPY    NUMBER,
6568     x_return_status                    OUT NOCOPY    VARCHAR2,
6569     x_msg_count                        OUT NOCOPY    NUMBER,
6570     x_msg_data                         OUT NOCOPY    VARCHAR2
6571   ) IS
6572 
6573     l_api_name                         CONSTANT VARCHAR2(30) := 'update_organization';
6574     l_organization_rec                 ORGANIZATION_REC_TYPE := p_organization_rec;
6575     l_old_organization_rec             ORGANIZATION_REC_TYPE;
6576     l_data_source_from                 VARCHAR2(30);
6577     l_context                          VARCHAR2(30);
6578     l_create_update_flag               VARCHAR2(1);
6579 
6580     dss_return_status VARCHAR2(1) := 'F';
6581     dss_msg_count     NUMBER := 0;
6582     dss_msg_data      VARCHAR2(2000):= null;
6583     l_test_security   VARCHAR2(1):= 'F';
6584     l_debug_prefix                     VARCHAR2(30) := '';
6585 /**
6586     CURSOR c_orgchk IS
6587       SELECT 1
6588       FROM   hz_parties hp
6589       WHERE  hp.party_id = l_organization_rec.party_rec.party_id
6590       AND    hp.party_type = 'ORGANIZATION';
6591 **/
6592 
6593   BEGIN
6594     --Standard start of API savepoint
6595     SAVEPOINT update_organization;
6596 
6597     -- Check if API is called in debug mode. If yes, enable debug.
6598     --enable_debug;
6599 
6600     -- Debug info.
6601     /*IF g_debug THEN
6602       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'update_organization (+)');
6603     END IF;
6604     */
6605 
6606     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
6607         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'update_organization (+)',
6608                                p_msg_level=>fnd_log.level_procedure);
6609     END IF;
6610 
6611 
6612     -- initialize message list if p_init_msg_list is set to TRUE.
6613     IF fnd_api.to_boolean(p_init_msg_list) THEN
6614       fnd_msg_pub.initialize;
6615     END IF;
6616 
6617     -- initialize API return status to success.
6618     x_return_status := fnd_api.g_ret_sts_success;
6619 
6620     -- enable policy function if it is disabled.
6621 
6622     l_context := NVL(SYS_CONTEXT('hz', g_apps_context), 'N');
6623     IF l_context = 'N' THEN
6624       hz_common_pub.disable_cont_source_security;
6625     END IF;
6626 
6627 /**
6628     get_organization_rec is checking if the organization party has been
6629     passed in.
6630 
6631     -- make sure ORGANIZATION party has been passed in
6632     OPEN c_orgchk;
6633     FETCH c_orgchk INTO l_count;
6634     IF c_orgchk%NOTFOUND THEN
6635       CLOSE c_orgchk;
6636       fnd_message.set_name('AR', 'HZ_API_NO_RECORD');
6637       fnd_message.set_token('RECORD', 'organization');
6638       fnd_message.set_token('VALUE',TO_CHAR(l_organization_rec.party_rec.party_id));
6639       fnd_msg_pub.add;
6640       RAISE fnd_api.g_exc_error;
6641     END IF;
6642     CLOSE c_orgchk;
6643 **/
6644 
6645     IF (l_organization_rec.party_rec.orig_system is not null
6646          and l_organization_rec.party_rec.orig_system <>fnd_api.g_miss_char)
6647        and (l_organization_rec.party_rec.orig_system_reference is not null
6648          and l_organization_rec.party_rec.orig_system_reference <>fnd_api.g_miss_char)
6649        and (l_organization_rec.party_rec.party_id = FND_API.G_MISS_NUM or l_organization_rec.party_rec.party_id is null) THEN
6650 
6651         hz_orig_system_ref_pub.get_owner_table_id
6652                         (p_orig_system => l_organization_rec.party_rec.orig_system,
6653                         p_orig_system_reference => l_organization_rec.party_rec.orig_system_reference,
6654                         p_owner_table_name => 'HZ_PARTIES',
6655                         x_owner_table_id => l_organization_rec.party_rec.party_id,
6656                         x_return_status => x_return_status);
6657 
6658             IF x_return_status <> fnd_api.g_ret_sts_success THEN
6659                 RAISE FND_API.G_EXC_ERROR;
6660             END IF;
6661       END IF;
6662 
6663 
6664     -- cache if mix-n-match is enabled
6665 
6666     -- IF g_org_mixnmatch_enabled IS NULL THEN
6667     HZ_MIXNM_UTILITY.LoadDataSources(
6668       'HZ_ORGANIZATION_PROFILES', g_org_entity_attr_id,
6669       g_org_mixnmatch_enabled, g_org_selected_datasources);
6670     -- END IF;
6671 
6672     -- Get old records. Will be used by business event system.
6673     get_organization_rec (
6674       p_party_id                     => l_organization_rec.party_rec.party_id,
6675       p_content_source_type          => HZ_MIXNM_UTILITY.FindDataSource(
6676                                           p_content_source_type           => l_organization_rec.content_source_type,
6677                                           p_actual_content_source         => l_organization_rec.actual_content_source,
6678                                           p_def_actual_content_source     => G_SST_SOURCE_TYPE,
6679                                           x_data_source_from              => l_data_source_from ),
6680       x_organization_rec             => l_old_organization_rec,
6681       x_return_status                => x_return_status,
6682       x_msg_count                    => x_msg_count,
6683       x_msg_data                     => x_msg_data);
6684 
6685     IF x_return_status = fnd_api.g_ret_sts_error THEN
6686       RAISE fnd_api.g_exc_error;
6687     ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
6688       RAISE fnd_api.g_exc_unexpected_error;
6689     END IF;
6690 
6691     --- Bug 2486394 Check if the DSS security is granted to the user
6692     -- Bug 3818648: check dss profile before call test_instance.
6693     --
6694     IF NVL(fnd_profile.value('HZ_DSS_ENABLED'), 'N') = 'Y' THEN
6695       l_test_security :=
6696            hz_dss_util_pub.test_instance(
6697                   p_operation_code     => 'UPDATE',
6698                   p_db_object_name     => 'HZ_PARTIES',
6699                   p_instance_pk1_value => l_organization_rec.party_rec.party_id,
6700                   p_user_name          => fnd_global.user_name,
6701                   x_return_status      => dss_return_status,
6702                   x_msg_count          => dss_msg_count,
6703                   x_msg_data           => dss_msg_data);
6704 
6705       if dss_return_status <> fnd_api.g_ret_sts_success THEN
6706          RAISE FND_API.G_EXC_ERROR;
6707       end if;
6708 
6709       if (l_test_security <> 'T' OR l_test_security <> FND_API.G_TRUE) then
6710          --
6711          -- Bug 3835601: replaced the message with a more user friendly message
6712          --
6713          FND_MESSAGE.SET_NAME('AR', 'HZ_DSS_NO_UPDATE_PRIVILEGE');
6714          FND_MESSAGE.SET_TOKEN('ENTITY_NAME',
6715                                hz_dss_util_pub.get_display_name(null, 'ORGANIZATION'));
6716          FND_MSG_PUB.ADD;
6717          RAISE FND_API.G_EXC_ERROR;
6718       end if;
6719     END IF;
6720 
6721     -- call to business logic.
6722     do_update_party(
6723       p_party_type                   => 'ORGANIZATION',
6724       p_organization_rec             => l_organization_rec,
6725       p_old_organization_rec         => l_old_organization_rec,
6726       p_party_object_version_number  => p_party_object_version_number,
6727       x_profile_id                   => x_profile_id,
6728       x_return_status                => x_return_status,
6729       p_person_rec                   => G_MISS_PERSON_REC,
6730       p_group_rec                    => G_MISS_GROUP_REC );
6731 
6732 
6733     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
6734         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'Before the Supplier Denorm Call',
6735                                p_msg_level=>fnd_log.level_procedure);
6736     END IF;
6737 
6738     AP_TCA_SUPPLIER_SYNC_PKG.SYNC_Supplier(x_return_status => x_return_status,
6739                                            x_msg_count     => x_msg_count,
6740                                            x_msg_data      => x_msg_data,
6741                                            x_party_id      => l_organization_rec.party_rec.party_id);
6742 
6743     IF x_return_status = fnd_api.g_ret_sts_error THEN
6744       RAISE fnd_api.g_exc_error;
6745     ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
6746       RAISE fnd_api.g_exc_unexpected_error;
6747     END IF;
6748 
6749     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
6750         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'After the Supplier Denorm Call',
6751                                p_msg_level=>fnd_log.level_procedure);
6752     END IF;
6753 
6754     IF l_old_organization_rec.actual_content_source IN
6755       (G_MISS_CONTENT_SOURCE_TYPE, G_SST_SOURCE_TYPE)
6756     THEN
6757        -- Bug 3868940
6758         BEGIN
6759         SELECT 'U' INTO l_create_update_flag
6760         FROM hz_credit_ratings
6761         WHERE party_id = p_organization_rec.party_rec.party_id
6762         AND actual_content_source = G_MISS_CONTENT_SOURCE_TYPE
6763         AND ROWNUM = 1;
6764         l_organization_rec.created_by_module:=NULL;
6765         EXCEPTION
6766         WHEN NO_DATA_FOUND THEN
6767           l_create_update_flag := 'C';
6768           l_organization_rec.created_by_module:=l_old_organization_rec.created_by_module;
6769         END;
6770 
6771         populate_credit_rating(
6772         p_create_update_flag           => l_create_update_flag,
6773         p_organization_rec             => l_organization_rec,
6774         x_return_status                => x_return_status );
6775 
6776       IF x_return_status <> fnd_api.g_ret_sts_success THEN
6777         RAISE fnd_api.g_exc_error;
6778       END IF;
6779     END IF;
6780 
6781 
6782     -- enable policy function if it was enabled before calling
6783     -- this procedure.
6784 
6785     IF l_context = 'N' THEN
6786       hz_common_pub.enable_cont_source_security;
6787     END IF;
6788 
6789     --Standard call to get message count and if count is 1, get message info.
6790     fnd_msg_pub.count_and_get(
6791       p_encoded                      => fnd_api.g_false,
6792       p_count                        => x_msg_count,
6793       p_data                         => x_msg_data);
6794 
6795     -- Debug info.
6796     /*IF g_debug THEN
6797       hz_utility_v2pub.debug_return_messages (
6798         x_msg_count, x_msg_data, 'WARNING');
6799       hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'update_organization (-)');
6800     END IF;
6801     */
6802     IF fnd_log.level_exception>=fnd_log.g_current_runtime_level THEN
6803          hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
6804                                p_msg_data=>x_msg_data,
6805                                p_msg_type=>'WARNING',
6806                                p_msg_level=>fnd_log.level_exception);
6807     END IF;
6808     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
6809          hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'update_organization (-)',
6810                                 p_msg_level=>fnd_log.level_procedure);
6811     END IF;
6812 
6813     -- Check if API is called in debug mode. If yes, disable debug.
6814     --disable_debug;
6815 
6816   EXCEPTION
6817     WHEN fnd_api.g_exc_error THEN
6818       ROLLBACK TO update_organization;
6819 
6820       IF l_context = 'N' THEN
6821         hz_common_pub.enable_cont_source_security;
6822       END IF;
6823 
6824       x_return_status := fnd_api.g_ret_sts_error;
6825 
6826       fnd_msg_pub.count_and_get(
6827         p_encoded                    => fnd_api.g_false,
6828         p_count                      => x_msg_count,
6829         p_data                       => x_msg_data);
6830 
6831       -- Debug info.
6832       /*IF g_debug THEN
6833         hz_utility_v2pub.debug_return_messages (
6834           x_msg_count, x_msg_data, 'ERROR');
6835         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'update_organization (-)');
6836       END IF;
6837       */
6838       IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
6839         hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
6840                                p_msg_data=>x_msg_data,
6841                                p_msg_type=>'ERROR',
6842                                p_msg_level=>fnd_log.level_error);
6843       END IF;
6844       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
6845         hz_utility_v2pub.debug(p_message=>'update_organization (-)',
6846                                p_prefix=>l_debug_prefix,
6847                                p_msg_level=>fnd_log.level_procedure);
6848       END IF;
6849 
6850       -- Check if API is called in debug mode. If yes, disable debug.
6851       --disable_debug;
6852 
6853     WHEN fnd_api.g_exc_unexpected_error THEN
6854       ROLLBACK TO update_organization;
6855 
6856       IF l_context = 'N' THEN
6857         hz_common_pub.enable_cont_source_security;
6858       END IF;
6859 
6860       x_return_status := fnd_api.g_ret_sts_unexp_error;
6861 
6862       fnd_msg_pub.count_and_get(
6863         p_encoded                    => fnd_api.g_false,
6864         p_count                      => x_msg_count,
6865         p_data                       => x_msg_data);
6866 
6867       -- Debug info.
6868       /*IF g_debug THEN
6869         hz_utility_v2pub.debug_return_messages (
6870           x_msg_count, x_msg_data, 'UNEXPECTED ERROR');
6871         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'update_organization (-)');
6872       END IF;
6873       */
6874       IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
6875         hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
6876                                p_msg_data=>x_msg_data,
6877                                p_msg_type=>'UNEXPECTED ERROR',
6878                                p_msg_level=>fnd_log.level_error);
6879       END IF;
6880       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
6881         hz_utility_v2pub.debug(p_message=>'update_organization (-)',
6882                                p_prefix=>l_debug_prefix,
6883                                p_msg_level=>fnd_log.level_procedure);
6884       END IF;
6885 
6886 
6887       -- Check if API is called in debug mode. If yes, disable debug.
6888       --disable_debug;
6889 
6890     WHEN OTHERS THEN
6891       ROLLBACK TO update_organization;
6892 
6893       IF l_context = 'N' THEN
6894         hz_common_pub.enable_cont_source_security;
6895       END IF;
6896 
6897       x_return_status := fnd_api.g_ret_sts_unexp_error;
6898 
6899       fnd_message.set_name('AR', 'HZ_API_OTHERS_EXCEP');
6900       fnd_message.set_token('ERROR',SQLERRM);
6901       fnd_msg_pub.add;
6902 
6903       fnd_msg_pub.count_and_get(
6904         p_encoded                    => fnd_api.g_false,
6905         p_count                      => x_msg_count,
6906         p_data                       => x_msg_data);
6907 
6908       -- Debug info.
6909       /*IF g_debug THEN
6910         hz_utility_v2pub.debug_return_messages (
6911           x_msg_count, x_msg_data, 'SQL ERROR');
6912         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'update_organization (-)');
6913       END IF;
6914       */
6915       IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
6916         hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
6917                                p_msg_data=>x_msg_data,
6918                                p_msg_type=>'SQL ERROR',
6919                                p_msg_level=>fnd_log.level_error);
6920       END IF;
6921       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
6922         hz_utility_v2pub.debug(p_message=>'update_organization (-)',
6923                                p_prefix=>l_debug_prefix,
6924                                p_msg_level=>fnd_log.level_procedure);
6925       END IF;
6926 
6927       -- Check if API is called in debug mode. If yes, disable debug.
6928       --disable_debug;
6929 
6930   END update_organization;
6931 
6932   /**
6933    * PROCEDURE get_organization_rec
6934    *
6935    * DESCRIPTION
6936    *     Gets organization record.
6937    *
6938    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
6939    *     hz_organization_profiles_pkg.Select_Row
6940    *
6941    * ARGUMENTS
6942    *   IN:
6943    *     p_init_msg_list      Initialize message stack if it is set to
6944    *                          FND_API.G_TRUE. Default is fnd_api.g_false.
6945    *     p_party_id           Party ID.
6946    *     p_content_source_type Content source type.
6947    *   IN/OUT:
6948    *   OUT:
6949    *     x_organization_rec   Returned organization record.
6950    *     x_return_status      Return status after the call. The status can
6951    *                          be fnd_api.g_ret_sts_success (success),
6952    *                          fnd_api.g_ret_sts_error (error),
6953    *                          fnd_api.g_ret_sts_unexp_error (unexpected error).
6954    *     x_msg_count          Number of messages in message stack.
6955    *     x_msg_data           Message text if x_msg_count is 1.
6956    *
6957    * NOTES
6958    *
6959    * MODIFICATION HISTORY
6960    *
6961    *   07-23-2001    Indrajit Sen        o Created.
6962    *   26-NOV-2001   Joe del Callar      o Bug 2116225: modified for
6963    *                                       consolidated bank support.
6964    *                                       Bug 2117973: modified to conform to
6965    *                                       PL/SQL coding standards.
6966    *                                       Changed select...intos into cursors.
6967    *
6968    */
6969 
6970   PROCEDURE get_organization_rec (
6971     p_init_msg_list                    IN     VARCHAR2 := fnd_api.g_false,
6972     p_party_id                         IN     NUMBER,
6973     p_content_source_type              IN     VARCHAR2 := g_miss_content_source_type,
6974     x_organization_rec                 OUT    NOCOPY ORGANIZATION_REC_TYPE,
6975     x_return_status                    OUT NOCOPY    VARCHAR2,
6976     x_msg_count                        OUT NOCOPY    NUMBER,
6977     x_msg_data                         OUT NOCOPY    VARCHAR2
6978   ) IS
6979 
6980     l_api_name                         CONSTANT VARCHAR2(30) := 'get_organization_rec';
6981 
6982     l_profile_id                       NUMBER;
6983     l_party_id                         NUMBER;
6984     l_effective_start_date             DATE;
6985     l_effective_end_date               DATE;
6986 
6987     -- Bug 2116225: added these local dummy variables to fetch the bank data.
6988     l_bank_code                        VARCHAR2(30);
6989     l_branch_code                      VARCHAR2(30);
6990     l_bank_or_branch_number            VARCHAR2(60);
6991     l_debug_prefix                     VARCHAR2(30) := '';
6992 
6993     CURSOR c_org_ue IS
6994       SELECT NVL(org2.organization_profile_id,org1.organization_profile_id)
6995       FROM
6996         hz_organization_profiles org1,
6997         (SELECT organization_profile_id, party_id
6998          FROM hz_organization_profiles
6999          WHERE party_id = p_party_id
7000          AND actual_content_source = G_MISS_CONTENT_SOURCE_TYPE
7001          AND effective_end_date IS NULL) org2
7002       WHERE org1.party_id = p_party_id
7003       AND org1.actual_content_source = 'SST'
7004       AND org1.effective_end_date IS NULL
7005       AND org1.party_id = org2.party_id (+);
7006 
7007     CURSOR c_org IS
7008       SELECT organization_profile_id
7009       FROM hz_organization_profiles
7010       WHERE party_id = p_party_id
7011       AND actual_content_source = p_content_source_type
7012       AND effective_end_date IS NULL;
7013 
7014     l_error                            BOOLEAN := FALSE;
7015     l_context                          VARCHAR2(30);
7016 
7017   BEGIN
7018 
7019     --Initialize message list if p_init_msg_list is set to TRUE.
7020     IF fnd_api.to_boolean(p_init_msg_list) THEN
7021       fnd_msg_pub.initialize;
7022     END IF;
7023 
7024     --Initialize API return status to success.
7025     x_return_status := fnd_api.g_ret_sts_success;
7026 
7027     -- enable policy function if it is disabled.
7028 
7029     l_context := NVL(SYS_CONTEXT('hz', g_apps_context), 'N');
7030     IF l_context = 'N' THEN
7031       hz_common_pub.disable_cont_source_security;
7032     END IF;
7033 
7034     --Check whether primary key has been passed in.
7035     IF p_party_id IS NULL OR
7036        p_party_id = fnd_api.g_miss_num
7037     THEN
7038       fnd_message.set_name('AR', 'HZ_API_MISSING_COLUMN');
7039       fnd_message.set_token('COLUMN', 'p_party_id');
7040       fnd_msg_pub.add;
7041       RAISE fnd_api.g_exc_error;
7042     END IF;
7043 
7044     IF p_content_source_type IS NULL OR
7045        p_content_source_type = fnd_api.g_miss_char
7046     THEN
7047       fnd_message.set_name('AR', 'HZ_API_MISSING_COLUMN');
7048       fnd_message.set_token('COLUMN', 'p_content_source_type');
7049       fnd_msg_pub.add;
7050       RAISE fnd_api.g_exc_error;
7051     END IF;
7052 
7053     IF p_content_source_type = G_MISS_CONTENT_SOURCE_TYPE THEN
7054       OPEN c_org_ue;
7055       FETCH c_org_ue INTO l_profile_id;
7056 
7057       IF c_org_ue%NOTFOUND THEN
7058         l_error := TRUE;
7059       END IF;
7060       CLOSE c_org_ue;
7061     ELSE
7062       OPEN c_org;
7063       FETCH c_org INTO l_profile_id;
7064 
7065       IF c_org%NOTFOUND THEN
7066         l_error := TRUE;
7067       END IF;
7068       CLOSE c_org;
7069     END IF;
7070 
7071     IF l_error THEN
7072       fnd_message.set_name('AR', 'HZ_NO_PROFILE_PRESENT');
7073       fnd_message.set_token('PARTY_ID', TO_CHAR(p_party_id));
7074       fnd_message.set_token('CONTENT_SOURCE_TYPE', p_content_source_type);
7075       fnd_msg_pub.add;
7076       RAISE fnd_api.g_exc_error;
7077     END IF;
7078 
7079     hz_organization_profiles_pkg.Select_Row (
7080       x_organization_profile_id      => l_profile_id,
7081       x_party_id                     => l_party_id,
7082       x_organization_name            => x_organization_rec.organization_name,
7083       x_attribute_category           => x_organization_rec.attribute_category,
7084       x_attribute1                   => x_organization_rec.attribute1,
7085       x_attribute2                   => x_organization_rec.attribute2,
7086       x_attribute3                   => x_organization_rec.attribute3,
7087       x_attribute4                   => x_organization_rec.attribute4,
7088       x_attribute5                   => x_organization_rec.attribute5,
7089       x_attribute6                   => x_organization_rec.attribute6,
7090       x_attribute7                   => x_organization_rec.attribute7,
7091       x_attribute8                   => x_organization_rec.attribute8,
7092       x_attribute9                   => x_organization_rec.attribute9,
7093       x_attribute10                  => x_organization_rec.attribute10,
7094       x_attribute11                  => x_organization_rec.attribute11,
7095       x_attribute12                  => x_organization_rec.attribute12,
7096       x_attribute13                  => x_organization_rec.attribute13,
7097       x_attribute14                  => x_organization_rec.attribute14,
7098       x_attribute15                  => x_organization_rec.attribute15,
7099       x_attribute16                  => x_organization_rec.attribute16,
7100       x_attribute17                  => x_organization_rec.attribute17,
7101       x_attribute18                  => x_organization_rec.attribute18,
7102       x_attribute19                  => x_organization_rec.attribute19,
7103       x_attribute20                  => x_organization_rec.attribute20,
7104       x_enquiry_duns                 => x_organization_rec.enquiry_duns,
7105       x_ceo_name                     => x_organization_rec.ceo_name,
7106       x_ceo_title                    => x_organization_rec.ceo_title,
7107       x_principal_name               => x_organization_rec.principal_name,
7108       x_principal_title              => x_organization_rec.principal_title,
7109       x_legal_status                 => x_organization_rec.legal_status,
7110       x_control_yr                   => x_organization_rec.control_yr,
7111       x_employees_total              => x_organization_rec.employees_total,
7112       x_hq_branch_ind                => x_organization_rec.hq_branch_ind,
7113       x_branch_flag                  => x_organization_rec.branch_flag,
7114       x_oob_ind                      => x_organization_rec.oob_ind,
7115       x_line_of_business             => x_organization_rec.line_of_business,
7116       x_cong_dist_code               => x_organization_rec.cong_dist_code,
7117       x_sic_code                     => x_organization_rec.sic_code,
7118       x_import_ind                   => x_organization_rec.import_ind,
7119       x_export_ind                   => x_organization_rec.export_ind,
7120       x_labor_surplus_ind            => x_organization_rec.labor_surplus_ind,
7121       x_debarment_ind                => x_organization_rec.debarment_ind,
7122       x_minority_owned_ind           => x_organization_rec.minority_owned_ind,
7123       x_minority_owned_type          => x_organization_rec.minority_owned_type,
7124       x_woman_owned_ind              => x_organization_rec.woman_owned_ind,
7125       x_disadv_8a_ind                => x_organization_rec.disadv_8a_ind,
7126       x_small_bus_ind                => x_organization_rec.small_bus_ind,
7127       x_rent_own_ind                 => x_organization_rec.rent_own_ind,
7128       x_debarments_count             => x_organization_rec.debarments_count,
7129       x_debarments_date              => x_organization_rec.debarments_date,
7130       x_failure_score                => x_organization_rec.failure_score,
7131       x_failure_score_override_code  => x_organization_rec.failure_score_override_code,
7132       x_failure_score_commentary     => x_organization_rec.failure_score_commentary,
7133       x_global_failure_score         => x_organization_rec.global_failure_score,
7134       x_db_rating                    => x_organization_rec.db_rating,
7135       x_credit_score                 => x_organization_rec.credit_score,
7136       x_credit_score_commentary      => x_organization_rec.credit_score_commentary,
7137       x_paydex_score                 => x_organization_rec.paydex_score,
7138       x_paydex_three_months_ago      => x_organization_rec.paydex_three_months_ago,
7139       x_paydex_norm                  => x_organization_rec.paydex_norm,
7140       x_best_time_contact_begin      => x_organization_rec.best_time_contact_begin,
7141       x_best_time_contact_end        => x_organization_rec.best_time_contact_end,
7142       x_organization_name_phonetic   => x_organization_rec.organization_name_phonetic,
7143       x_tax_reference                => x_organization_rec.tax_reference,
7144       x_gsa_indicator_flag           => x_organization_rec.gsa_indicator_flag,
7145       x_jgzz_fiscal_code             => x_organization_rec.jgzz_fiscal_code,
7146       x_analysis_fy                  => x_organization_rec.analysis_fy,
7147       x_fiscal_yearend_month         => x_organization_rec.fiscal_yearend_month,
7148       x_curr_fy_potential_revenue    => x_organization_rec.curr_fy_potential_revenue,
7149       x_next_fy_potential_revenue    => x_organization_rec.next_fy_potential_revenue,
7150       x_year_established             => x_organization_rec.year_established,
7151       x_mission_statement            => x_organization_rec.mission_statement,
7152       x_organization_type            => x_organization_rec.organization_type,
7153       x_business_scope               => x_organization_rec.business_scope,
7154       x_corporation_class            => x_organization_rec.corporation_class,
7155       x_known_as                     => x_organization_rec.known_as,
7156       x_local_bus_iden_type          => x_organization_rec.local_bus_iden_type,
7157       x_local_bus_identifier         => x_organization_rec.local_bus_identifier,
7158       x_pref_functional_currency     => x_organization_rec.pref_functional_currency,
7159       x_registration_type            => x_organization_rec.registration_type,
7160       x_total_employees_text         => x_organization_rec.total_employees_text,
7161       x_total_employees_ind          => x_organization_rec.total_employees_ind,
7162       x_total_emp_est_ind            => x_organization_rec.total_emp_est_ind,
7163       x_total_emp_min_ind            => x_organization_rec.total_emp_min_ind,
7164       x_parent_sub_ind               => x_organization_rec.parent_sub_ind,
7165       x_incorp_year                  => x_organization_rec.incorp_year,
7166       x_content_source_type          => x_organization_rec.content_source_type,
7167       x_content_source_number        => x_organization_rec.content_source_number,
7168       x_effective_start_date         => l_effective_start_date,
7169       x_effective_end_date           => l_effective_end_date,
7170       x_sic_code_type                => x_organization_rec.sic_code_type,
7171       x_public_private_ownership     => x_organization_rec.public_private_ownership_flag,
7172       x_local_activity_code_type     => x_organization_rec.local_activity_code_type,
7173       x_local_activity_code          => x_organization_rec.local_activity_code,
7174       x_emp_at_primary_adr           => x_organization_rec.emp_at_primary_adr,
7175       x_emp_at_primary_adr_text      => x_organization_rec.emp_at_primary_adr_text,
7176       x_emp_at_primary_adr_est_ind   => x_organization_rec.emp_at_primary_adr_est_ind,
7177       x_emp_at_primary_adr_min_ind   => x_organization_rec.emp_at_primary_adr_min_ind,
7178       x_internal_flag                => x_organization_rec.internal_flag,
7179       x_high_credit                  => x_organization_rec.high_credit,
7180       x_avg_high_credit              => x_organization_rec.avg_high_credit,
7181       x_total_payments               => x_organization_rec.total_payments,
7182       x_known_as2                    => x_organization_rec.known_as2,
7183       x_known_as3                    => x_organization_rec.known_as3,
7184       x_known_as4                    => x_organization_rec.known_as4,
7185       x_known_as5                    => x_organization_rec.known_as5,
7186       x_credit_score_class           => x_organization_rec.credit_score_class,
7187       x_credit_score_natl_percentile => x_organization_rec.credit_score_natl_percentile,
7188       x_credit_score_incd_default    => x_organization_rec.credit_score_incd_default,
7189       x_credit_score_age             => x_organization_rec.credit_score_age,
7190       x_credit_score_date            => x_organization_rec.credit_score_date,
7191       x_failure_score_class          => x_organization_rec.failure_score_class,
7192       x_failure_score_incd_default   => x_organization_rec.failure_score_incd_default,
7193       x_failure_score_age            => x_organization_rec.failure_score_age,
7194       x_failure_score_date           => x_organization_rec.failure_score_date,
7195       x_failure_score_commentary2    => x_organization_rec.failure_score_commentary2,
7196       x_failure_score_commentary3    => x_organization_rec.failure_score_commentary3,
7197       x_failure_score_commentary4    => x_organization_rec.failure_score_commentary4,
7198       x_failure_score_commentary5    => x_organization_rec.failure_score_commentary5,
7199       x_failure_score_commentary6    => x_organization_rec.failure_score_commentary6,
7200       x_failure_score_commentary7    => x_organization_rec.failure_score_commentary7,
7201       x_failure_score_commentary8    => x_organization_rec.failure_score_commentary8,
7202       x_failure_score_commentary9    => x_organization_rec.failure_score_commentary9,
7203       x_failure_score_commentary10   => x_organization_rec.failure_score_commentary10,
7204       x_credit_score_commentary2     => x_organization_rec.credit_score_commentary2,
7205       x_credit_score_commentary3     => x_organization_rec.credit_score_commentary3,
7206       x_credit_score_commentary4     => x_organization_rec.credit_score_commentary4,
7207       x_credit_score_commentary5     => x_organization_rec.credit_score_commentary5,
7208       x_credit_score_commentary6     => x_organization_rec.credit_score_commentary6,
7209       x_credit_score_commentary7     => x_organization_rec.credit_score_commentary7,
7210       x_credit_score_commentary8     => x_organization_rec.credit_score_commentary8,
7211       x_credit_score_commentary9     => x_organization_rec.credit_score_commentary9,
7212       x_credit_score_commentary10    => x_organization_rec.credit_score_commentary10,
7213       x_maximum_credit_recomm        => x_organization_rec.maximum_credit_recommendation,
7214       x_maximum_credit_currency_code => x_organization_rec.maximum_credit_currency_code,
7215       x_displayed_duns_party_id      => x_organization_rec.displayed_duns_party_id,
7216       x_failure_score_natnl_perc     => x_organization_rec.failure_score_natnl_percentile,
7217       x_duns_number_c                => x_organization_rec.duns_number_c,
7218       x_bank_or_branch_number        => l_bank_or_branch_number,
7219       x_bank_code                    => l_bank_code,
7220       x_branch_code                  => l_branch_code,
7221       x_created_by_module            => x_organization_rec.created_by_module,
7222       x_application_id               => x_organization_rec.application_id,
7223       x_do_not_confuse_with          => x_organization_rec.do_not_confuse_with,
7224       x_actual_content_source        => x_organization_rec.actual_content_source,
7225       x_home_country                 => x_organization_rec.home_country
7226     );
7227 
7228     -- Get the party record component of organization
7229     get_party_rec(
7230       p_party_id                     => p_party_id,
7231       x_party_rec                    => x_organization_rec.party_rec,
7232       x_return_status                => x_return_status,
7233       x_msg_count                    => x_msg_count,
7234       x_msg_data                     => x_msg_data);
7235 
7236     -- enable policy function if it was enabled before calling
7237     -- this procedure.
7238 
7239     IF l_context = 'N' THEN
7240       hz_common_pub.enable_cont_source_security;
7241     END IF;
7242 
7243     --Standard call to get message count and if count is 1, get message info.
7244     fnd_msg_pub.count_and_get(
7245       p_encoded                      => fnd_api.g_false,
7246       p_count                        => x_msg_count,
7247       p_data                         => x_msg_data);
7248 
7249   EXCEPTION
7250     WHEN fnd_api.g_exc_error THEN
7251       IF l_context = 'N' THEN
7252         hz_common_pub.enable_cont_source_security;
7253       END IF;
7254 
7255       x_return_status := fnd_api.g_ret_sts_error;
7256 
7257       fnd_msg_pub.count_and_get(
7258         p_encoded                    => fnd_api.g_false,
7259         p_count                      => x_msg_count,
7260         p_data                       => x_msg_data);
7261 
7262     WHEN fnd_api.g_exc_unexpected_error THEN
7263       IF l_context = 'N' THEN
7264         hz_common_pub.enable_cont_source_security;
7265       END IF;
7266 
7267       x_return_status := fnd_api.g_ret_sts_unexp_error;
7268 
7269       fnd_msg_pub.count_and_get(
7270         p_encoded                    => fnd_api.g_false,
7271         p_count                      => x_msg_count,
7272         p_data                       => x_msg_data);
7273 
7274     WHEN OTHERS THEN
7275       IF l_context = 'N' THEN
7276         hz_common_pub.enable_cont_source_security;
7277       END IF;
7278 
7279       x_return_status := fnd_api.g_ret_sts_unexp_error;
7280 
7281       fnd_message.set_name('AR', 'HZ_API_OTHERS_EXCEP');
7282       fnd_message.set_token('ERROR',SQLERRM);
7283       fnd_msg_pub.add;
7284 
7285       fnd_msg_pub.count_and_get(
7286         p_encoded                    => fnd_api.g_false,
7287         p_count                      => x_msg_count,
7288         p_data                       => x_msg_data);
7289 
7290   END get_organization_rec;
7291 
7292   /**
7293    * PROCEDURE get_person_rec
7294    *
7295    * DESCRIPTION
7296    *     Gets person record.
7297    *
7298    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
7299    *     hz_person_profiles_pkg.Select_Row
7300    *
7301    * ARGUMENTS
7302    *   IN:
7303    *     p_init_msg_list       Initialize message stack if it is set to
7304    *                           FND_API.G_TRUE. Default is fnd_api.g_false.
7305    *     p_party_id            Party ID.
7306    *     p_content_source_type Content source type.
7307    *   IN/OUT:
7308    *   OUT:
7309    *     x_person_rec          Returned person record.
7310    *     x_return_status       Return status after the call. The status can
7311    *                           be fnd_api.g_ret_sts_success (success),
7312    *                           fnd_api.g_ret_sts_error (error),
7313    *                           fnd_api.g_ret_sts_unexp_error (unexpected error)
7314    *     x_msg_count           Number of messages in message stack.
7315    *     x_msg_data            Message text if x_msg_count is 1.
7316    *
7317    * NOTES
7318    *
7319    * MODIFICATION HISTORY
7320    *
7321    *   07-23-2001    Indrajit Sen        o Created.
7322    *
7323    */
7324 
7325   PROCEDURE get_person_rec (
7326     p_init_msg_list                    IN     VARCHAR2 := fnd_api.g_false,
7327     p_party_id                         IN     NUMBER,
7328     p_content_source_type              IN     VARCHAR2 := G_MISS_CONTENT_SOURCE_TYPE,
7329     x_person_rec                       OUT    NOCOPY PERSON_REC_TYPE,
7330     x_return_status                    OUT NOCOPY    VARCHAR2,
7331     x_msg_count                        OUT NOCOPY    NUMBER,
7332     x_msg_data                         OUT NOCOPY    VARCHAR2
7333   ) IS
7334 
7335     l_api_name                         CONSTANT VARCHAR2(30) := 'get_person_profile_rec';
7336 
7337     l_profile_id                       NUMBER;
7338     l_party_id                         NUMBER;
7339     l_effective_start_date             DATE;
7340     l_effective_end_date               DATE;
7341     l_debug_prefix                     VARCHAR2(30) := '';
7342 
7343     CURSOR c_per_ue IS
7344       SELECT NVL(per2.person_profile_id,per1.person_profile_id)
7345       FROM
7346         hz_person_profiles per1,
7347         (SELECT person_profile_id, party_id
7348          FROM hz_person_profiles
7349          WHERE party_id = p_party_id
7350          AND actual_content_source = G_MISS_CONTENT_SOURCE_TYPE
7351          AND effective_end_date IS NULL) per2
7352       WHERE per1.party_id = p_party_id
7353       AND per1.actual_content_source = 'SST'
7354       AND per1.effective_end_date IS NULL
7355       AND per1.party_id = per2.party_id (+);
7356 
7357     CURSOR c_per IS
7358       SELECT person_profile_id
7359       FROM hz_person_profiles
7360       WHERE party_id = p_party_id
7361       AND actual_content_source = p_content_source_type
7362       AND effective_end_date IS NULL;
7363 
7364     l_error                            BOOLEAN := FALSE;
7365     l_context                          VARCHAR2(30);
7366 
7367   BEGIN
7368 
7369     --Initialize message list if p_init_msg_list is set to TRUE.
7370     IF fnd_api.to_boolean(p_init_msg_list) THEN
7371       fnd_msg_pub.initialize;
7372     END IF;
7373 
7374     --Initialize API return status to success.
7375     x_return_status := fnd_api.g_ret_sts_success;
7376 
7377     -- enable policy function if it is disabled.
7378 
7379     l_context := NVL(SYS_CONTEXT('hz', g_apps_context), 'N');
7380     IF l_context = 'N' THEN
7381       hz_common_pub.disable_cont_source_security;
7382     END IF;
7383 
7384     --Check whether primary key has been passed in.
7385     IF p_party_id IS NULL OR
7386        p_party_id = fnd_api.g_miss_num
7387     THEN
7388       fnd_message.set_name('AR', 'HZ_API_MISSING_COLUMN');
7389       fnd_message.set_token('COLUMN', 'p_party_id');
7390       fnd_msg_pub.add;
7391       RAISE fnd_api.g_exc_error;
7392     END IF;
7393 
7394     IF p_content_source_type IS NULL OR
7395        p_content_source_type = FND_API.G_MISS_CHAR
7396     THEN
7397       fnd_message.set_name('AR', 'HZ_API_MISSING_COLUMN');
7398       fnd_message.set_token('COLUMN', 'p_content_source_type');
7399       fnd_msg_pub.add;
7400       RAISE fnd_api.g_exc_error;
7401     END IF;
7402 
7403     IF p_content_source_type = G_MISS_CONTENT_SOURCE_TYPE THEN
7404       OPEN c_per_ue;
7405       FETCH c_per_ue INTO l_profile_id;
7406 
7407       IF c_per_ue%NOTFOUND THEN
7408         l_error := TRUE;
7409       END IF;
7410       CLOSE c_per_ue;
7411     ELSE
7412       OPEN c_per;
7413       FETCH c_per INTO l_profile_id;
7414 
7415       IF c_per%NOTFOUND THEN
7416         l_error := TRUE;
7417       END IF;
7418       CLOSE c_per;
7419     END IF;
7420 
7421     IF l_error THEN
7422       fnd_message.set_name('AR', 'HZ_NO_PROFILE_PRESENT');
7423       fnd_message.set_token('PARTY_ID', TO_CHAR(p_party_id));
7424       fnd_message.set_token('CONTENT_SOURCE_TYPE', p_content_source_type);
7425       fnd_msg_pub.add;
7426       RAISE fnd_api.g_exc_error;
7427     END IF;
7428 
7429     HZ_person_profiles_pkg.Select_Row (
7430       x_person_profile_id            => l_profile_id,
7431       x_party_id                     => l_party_id,
7432       x_attribute_category           => x_person_rec.attribute_category,
7433       x_attribute1                   => x_person_rec.attribute1,
7434       x_attribute2                   => x_person_rec.attribute2,
7435       x_attribute3                   => x_person_rec.attribute3,
7436       x_attribute4                   => x_person_rec.attribute4,
7437       x_attribute5                   => x_person_rec.attribute5,
7438       x_attribute6                   => x_person_rec.attribute6,
7439       x_attribute7                   => x_person_rec.attribute7,
7440       x_attribute8                   => x_person_rec.attribute8,
7441       x_attribute9                   => x_person_rec.attribute9,
7442       x_attribute10                  => x_person_rec.attribute10,
7443       x_attribute11                  => x_person_rec.attribute11,
7444       x_attribute12                  => x_person_rec.attribute12,
7445       x_attribute13                  => x_person_rec.attribute13,
7446       x_attribute14                  => x_person_rec.attribute14,
7447       x_attribute15                  => x_person_rec.attribute15,
7448       x_attribute16                  => x_person_rec.attribute16,
7449       x_attribute17                  => x_person_rec.attribute17,
7450       x_attribute18                  => x_person_rec.attribute18,
7451       x_attribute19                  => x_person_rec.attribute19,
7452       x_attribute20                  => x_person_rec.attribute20,
7453       x_person_pre_name_adjunct      => x_person_rec.person_pre_name_adjunct,
7454       x_person_first_name            => x_person_rec.person_first_name,
7455       x_person_middle_name           => x_person_rec.person_middle_name,
7456       x_person_last_name             => x_person_rec.person_last_name,
7457       x_person_name_suffix           => x_person_rec.person_name_suffix,
7458       x_person_title                 => x_person_rec.person_title,
7459       x_person_academic_title        => x_person_rec.person_academic_title,
7460       x_person_previous_last_name    => x_person_rec.person_previous_last_name,
7461       x_person_initials              => x_person_rec.person_initials,
7462       x_known_as                     => x_person_rec.known_as,
7463       x_person_name_phonetic         => x_person_rec.person_name_phonetic,
7464       x_person_first_name_phonetic   => x_person_rec.person_first_name_phonetic,
7465       x_person_last_name_phonetic    => x_person_rec.person_last_name_phonetic,
7466       x_tax_reference                => x_person_rec.tax_reference,
7467       x_jgzz_fiscal_code             => x_person_rec.jgzz_fiscal_code,
7468       x_person_iden_type             => x_person_rec.person_iden_type,
7469       x_person_identifier            => x_person_rec.person_identifier,
7470       x_date_of_birth                => x_person_rec.date_of_birth,
7471       x_place_of_birth               => x_person_rec.place_of_birth,
7472       x_date_of_death                => x_person_rec.date_of_death,
7473       x_deceased_flag                 => x_person_rec.deceased_flag,
7474       x_gender                       => x_person_rec.gender,
7475       x_declared_ethnicity           => x_person_rec.declared_ethnicity,
7476       x_marital_status               => x_person_rec.marital_status,
7477       x_marital_status_eff_date      => x_person_rec.marital_status_effective_date,
7478       x_personal_income              => x_person_rec.personal_income,
7479       x_head_of_household_flag       => x_person_rec.head_of_household_flag,
7480       x_household_income             => x_person_rec.household_income,
7481       x_household_size               => x_person_rec.household_size,
7482       x_rent_own_ind                 => x_person_rec.rent_own_ind,
7483       x_last_known_gps               => x_person_rec.last_known_gps,
7484       x_effective_start_date         => l_effective_start_date,
7485       x_effective_end_date           => l_effective_end_date,
7486       x_content_source_type          => x_person_rec.content_source_type,
7487       x_internal_flag                => x_person_rec.internal_flag,
7488       x_known_as2                    => x_person_rec.known_as2,
7489       x_known_as3                    => x_person_rec.known_as3,
7490       x_known_as4                    => x_person_rec.known_as4,
7491       x_known_as5                    => x_person_rec.known_as5,
7492       x_middle_name_phonetic         => x_person_rec.middle_name_phonetic,
7493       x_created_by_module            => x_person_rec.created_by_module,
7494       x_application_id               => x_person_rec.application_id,
7495       x_actual_content_source        => x_person_rec.actual_content_source
7496     );
7497 
7498     -- Get the party record component of person
7499     get_party_rec(
7500       p_party_id                     => p_party_id,
7501       x_party_rec                    => x_person_rec.party_rec,
7502       x_return_status                => x_return_status,
7503       x_msg_count                    => x_msg_count,
7504       x_msg_data                     => x_msg_data);
7505 
7506     -- enable policy function if it was enabled before calling
7507     -- this procedure.
7508 
7509     IF l_context = 'N' THEN
7510       hz_common_pub.enable_cont_source_security;
7511     END IF;
7512 
7513     --Standard call to get message count and if count is 1, get message info.
7514     fnd_msg_pub.count_and_get(
7515       p_encoded                      => fnd_api.g_false,
7516       p_count                        => x_msg_count,
7517       p_data                         => x_msg_data);
7518 
7519   EXCEPTION
7520     WHEN fnd_api.g_exc_error THEN
7521       IF l_context = 'N' THEN
7522         hz_common_pub.enable_cont_source_security;
7523       END IF;
7524 
7525       x_return_status := fnd_api.g_ret_sts_error;
7526 
7527       fnd_msg_pub.count_and_get(
7528         p_encoded                    => fnd_api.g_false,
7529         p_count                      => x_msg_count,
7530         p_data                       => x_msg_data);
7531 
7532     WHEN fnd_api.g_exc_unexpected_error THEN
7533       IF l_context = 'N' THEN
7534         hz_common_pub.enable_cont_source_security;
7535       END IF;
7536 
7537       x_return_status := fnd_api.g_ret_sts_unexp_error;
7538 
7539       fnd_msg_pub.count_and_get(
7540         p_encoded                    => fnd_api.g_false,
7541         p_count                      => x_msg_count,
7542         p_data                       => x_msg_data);
7543 
7544     WHEN OTHERS THEN
7545       IF l_context = 'N' THEN
7546         hz_common_pub.enable_cont_source_security;
7547       END IF;
7548 
7549       x_return_status := fnd_api.g_ret_sts_unexp_error;
7550 
7551       fnd_message.set_name('AR', 'HZ_API_OTHERS_EXCEP');
7552       fnd_message.set_token('ERROR',SQLERRM);
7553       fnd_msg_pub.add;
7554 
7555       fnd_msg_pub.count_and_get(
7556         p_encoded                    => fnd_api.g_false,
7557         p_count                      => x_msg_count,
7558         p_data                       => x_msg_data);
7559 
7560   END get_person_rec;
7561 
7562   /**
7563    * PROCEDURE get_group_rec
7564    *
7565    * DESCRIPTION
7566    *     Gets group record.
7567    *
7568    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
7569    *
7570    * ARGUMENTS
7571    *   IN:
7572    *     p_init_msg_list      Initialize message stack if it is set to
7573    *                          FND_API.G_TRUE. Default is fnd_api.g_false.
7574    *     p_party_id           Party ID.
7575    *   IN/OUT:
7576    *   OUT:
7577    *     x_group_rec          Returned group record.
7578    *     x_return_status      Return status after the call. The status can
7579    *                          be fnd_api.g_ret_sts_success (success),
7580    *                          fnd_api.g_ret_sts_error (error),
7581    *                          fnd_api.g_ret_sts_unexp_error (unexpected error).
7582    *     x_msg_count          Number of messages in message stack.
7583    *     x_msg_data           Message text if x_msg_count is 1.
7584    *
7585    * NOTES
7586    *
7587    * MODIFICATION HISTORY
7588    *
7589    *   04-25-2002    Jianying Huang    o Created.
7590    *
7591    */
7592 
7593   PROCEDURE get_group_rec (
7594     p_init_msg_list                    IN     VARCHAR2 := fnd_api.g_false,
7595     p_party_id                         IN     NUMBER,
7596     x_group_rec                        OUT    NOCOPY GROUP_REC_TYPE,
7597     x_return_status                    OUT NOCOPY    VARCHAR2,
7598     x_msg_count                        OUT NOCOPY    NUMBER,
7599     x_msg_data                         OUT NOCOPY    VARCHAR2
7600   ) IS
7601 
7602     l_api_name                         CONSTANT VARCHAR2(30) := 'get_group_rec';
7603 
7604     x_party_dup_rec                    PARTY_DUP_REC_TYPE;
7605     l_party_name                       HZ_PARTIES.PARTY_NAME%TYPE;
7606     l_party_type                       HZ_PARTIES.PARTY_TYPE%TYPE;
7607     l_customer_key                     HZ_PARTIES.CUSTOMER_KEY%TYPE;
7608     l_country                          HZ_PARTIES.COUNTRY%TYPE;
7609     l_address1                         HZ_PARTIES.ADDRESS1%TYPE;
7610     l_address2                         HZ_PARTIES.ADDRESS2%TYPE;
7611     l_address3                         HZ_PARTIES.ADDRESS3%TYPE;
7612     l_address4                         HZ_PARTIES.ADDRESS4%TYPE;
7613     l_city                             HZ_PARTIES.CITY%TYPE;
7614     l_state                            HZ_PARTIES.STATE%TYPE;
7615     l_postal_code                      HZ_PARTIES.POSTAL_CODE%TYPE;
7616     l_province                         HZ_PARTIES.PROVINCE%TYPE;
7617     l_county                           HZ_PARTIES.COUNTY%TYPE;
7618     l_url                              HZ_PARTIES.URL%TYPE;
7619     l_email_address                    HZ_PARTIES.EMAIL_ADDRESS%TYPE;
7620     l_language_name                    HZ_PARTIES.LANGUAGE_NAME%TYPE;
7621     l_debug_prefix                     VARCHAR2(30) := '';
7622 
7623     CURSOR c_group IS
7624       SELECT 'Y'
7625       FROM hz_parties
7626       WHERE party_id = p_party_id
7627       AND party_type = 'GROUP';
7628 
7629     l_dummy                            VARCHAR2(1);
7630     l_error                            BOOLEAN := FALSE;
7631 
7632   BEGIN
7633 
7634     --Initialize message list if p_init_msg_list is set to TRUE.
7635     IF fnd_api.to_boolean(p_init_msg_list) THEN
7636       fnd_msg_pub.initialize;
7637     END IF;
7638 
7639     --Initialize API return status to success.
7640     x_return_status := fnd_api.g_ret_sts_success;
7641 
7642     --Check whether primary key has been passed in.
7643     IF p_party_id IS NULL OR
7644        p_party_id = fnd_api.g_miss_num
7645     THEN
7646       fnd_message.set_name('AR', 'HZ_API_MISSING_COLUMN');
7647       fnd_message.set_token('COLUMN', 'party_id');
7648       fnd_msg_pub.add;
7649       RAISE fnd_api.g_exc_error;
7650     END IF;
7651 
7652     OPEN c_group;
7653     FETCH c_group INTO l_dummy;
7654     IF c_group%NOTFOUND THEN
7655       l_error := TRUE;
7656     END IF;
7657     CLOSE c_group;
7658 
7659     IF l_error THEN
7660       fnd_message.set_name('AR', 'HZ_API_NO_RECORD');
7661       fnd_message.set_token('RECORD', 'group');
7662       fnd_message.set_token('VALUE', to_char(p_party_id));
7663       fnd_msg_pub.add;
7664       RAISE fnd_api.g_exc_error;
7665     END IF;
7666 
7667     x_group_rec.party_rec.party_id := p_party_id;
7668 
7669     hz_parties_pkg.Select_Row (
7670       x_party_id                     => x_group_rec.party_rec.party_id,
7671       x_party_number                 => x_group_rec.party_rec.party_number,
7672       x_party_name                   => x_group_rec.group_name,
7673       x_party_type                   => l_party_type,
7674       x_validated_flag               => x_group_rec.party_rec.validated_flag,
7675       x_attribute_category           => x_group_rec.party_rec.attribute_category,
7676       x_attribute1                   => x_group_rec.party_rec.attribute1,
7677       x_attribute2                   => x_group_rec.party_rec.attribute2,
7678       x_attribute3                   => x_group_rec.party_rec.attribute3,
7679       x_attribute4                   => x_group_rec.party_rec.attribute4,
7680       x_attribute5                   => x_group_rec.party_rec.attribute5,
7681       x_attribute6                   => x_group_rec.party_rec.attribute6,
7682       x_attribute7                   => x_group_rec.party_rec.attribute7,
7683       x_attribute8                   => x_group_rec.party_rec.attribute8,
7684       x_attribute9                   => x_group_rec.party_rec.attribute9,
7685       x_attribute10                  => x_group_rec.party_rec.attribute10,
7686       x_attribute11                  => x_group_rec.party_rec.attribute11,
7687       x_attribute12                  => x_group_rec.party_rec.attribute12,
7688       x_attribute13                  => x_group_rec.party_rec.attribute13,
7689       x_attribute14                  => x_group_rec.party_rec.attribute14,
7690       x_attribute15                  => x_group_rec.party_rec.attribute15,
7691       x_attribute16                  => x_group_rec.party_rec.attribute16,
7692       x_attribute17                  => x_group_rec.party_rec.attribute17,
7693       x_attribute18                  => x_group_rec.party_rec.attribute18,
7694       x_attribute19                  => x_group_rec.party_rec.attribute19,
7695       x_attribute20                  => x_group_rec.party_rec.attribute20,
7696       x_attribute21                  => x_group_rec.party_rec.attribute21,
7697       x_attribute22                  => x_group_rec.party_rec.attribute22,
7698       x_attribute23                  => x_group_rec.party_rec.attribute23,
7699       x_attribute24                  => x_group_rec.party_rec.attribute24,
7700       x_orig_system_reference        => x_group_rec.party_rec.orig_system_reference,
7701       x_sic_code                     => x_party_dup_rec.sic_code,
7702       x_hq_branch_ind                => x_party_dup_rec.hq_branch_ind,
7703       x_customer_key                 => l_customer_key,
7704       x_tax_reference                => x_party_dup_rec.tax_reference,
7705       x_jgzz_fiscal_code             => x_party_dup_rec.jgzz_fiscal_code,
7706       x_person_pre_name_adjunct      => x_party_dup_rec.pre_name_adjunct,
7707       x_person_first_name            => x_party_dup_rec.first_name,
7708       x_person_middle_name           => x_party_dup_rec.middle_name,
7709       x_person_last_name             => x_party_dup_rec.last_name,
7710       x_person_name_suffix           => x_party_dup_rec.name_suffix,
7711       x_person_title                 => x_party_dup_rec.title,
7712       x_person_academic_title        => x_party_dup_rec.academic_title,
7713       x_person_previous_last_name    => x_party_dup_rec.previous_last_name,
7714       x_known_as                     => x_party_dup_rec.known_as,
7715       x_person_iden_type             => x_party_dup_rec.person_iden_type,
7716       x_person_identifier            => x_party_dup_rec.person_identifier,
7717       x_group_type                   => x_group_rec.group_type,
7718       x_country                      => l_country,
7719       x_address1                     => l_address1,
7720       x_address2                     => l_address2,
7721       x_address3                     => l_address3,
7722       x_address4                     => l_address4,
7723       x_city                         => l_city,
7724       x_postal_code                  => l_postal_code,
7725       x_state                        => l_state,
7726       x_province                     => l_province,
7727       x_status                       => x_group_rec.party_rec.status,
7728       x_county                       => l_county,
7729       x_sic_code_type                => x_party_dup_rec.sic_code_type,
7730       x_url                          => l_url,
7731       x_email_address                => l_email_address,
7732       x_analysis_fy                  => x_party_dup_rec.analysis_fy,
7733       x_fiscal_yearend_month         => x_party_dup_rec.fiscal_yearend_month,
7734       x_employees_total              => x_party_dup_rec.employees_total,
7735       x_curr_fy_potential_revenue    => x_party_dup_rec.curr_fy_potential_revenue,
7736       x_next_fy_potential_revenue    => x_party_dup_rec.next_fy_potential_revenue,
7737       x_year_established             => x_party_dup_rec.year_established,
7738       x_gsa_indicator_flag           => x_party_dup_rec.gsa_indicator_flag,
7739       -- Bug 2467872
7740       x_mission_statement            => x_group_rec.mission_statement,
7741       x_organization_name_phonetic   => x_party_dup_rec.organization_name_phonetic,
7742       x_person_first_name_phonetic   => x_party_dup_rec.person_first_name_phonetic,
7743       x_person_last_name_phonetic    => x_party_dup_rec.person_last_name_phonetic,
7744       x_language_name                => l_language_name,
7745       x_category_code                => x_group_rec.party_rec.category_code,
7746       x_salutation                   => x_group_rec.party_rec.salutation,
7747       x_known_as2                    => x_party_dup_rec.known_as2,
7748       x_known_as3                    => x_party_dup_rec.known_as3,
7749       x_known_as4                    => x_party_dup_rec.known_as4,
7750       x_known_as5                    => x_party_dup_rec.known_as5,
7751       x_duns_number_c                => x_party_dup_rec.duns_number_c,
7752       x_created_by_module            => x_group_rec.created_by_module,
7753       x_application_id               => x_group_rec.application_id
7754     );
7755 
7756     --Standard call to get message count and if count is 1, get message info.
7757     fnd_msg_pub.count_and_get(
7758       p_encoded                      => fnd_api.g_false,
7759       p_count                        => x_msg_count,
7760       p_data                         => x_msg_data);
7761 
7762   EXCEPTION
7763     WHEN fnd_api.g_exc_error THEN
7764       x_return_status := fnd_api.g_ret_sts_error;
7765 
7766       fnd_msg_pub.count_and_get(
7767         p_encoded                    => fnd_api.g_false,
7768         p_count                      => x_msg_count,
7769         p_data                       => x_msg_data);
7770 
7771     WHEN fnd_api.g_exc_unexpected_error THEN
7772       x_return_status := fnd_api.g_ret_sts_unexp_error;
7773 
7774       fnd_msg_pub.count_and_get(
7775         p_encoded                    => fnd_api.g_false,
7776         p_count                      => x_msg_count,
7777         p_data                       => x_msg_data);
7778 
7779     WHEN OTHERS THEN
7780       x_return_status := fnd_api.g_ret_sts_unexp_error;
7781 
7782       fnd_message.set_name('AR', 'HZ_API_OTHERS_EXCEP');
7783       fnd_message.set_token('ERROR',SQLERRM);
7784       fnd_msg_pub.add;
7785 
7786       fnd_msg_pub.count_and_get(
7787         p_encoded                    => fnd_api.g_false,
7788         p_count                      => x_msg_count,
7789         p_data                       => x_msg_data);
7790 
7791   END get_group_rec;
7792 
7793   /**
7794    * PROCEDURE get_party_rec
7795    *
7796    * DESCRIPTION
7797    *     Gets party record.
7798    *
7799    * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
7800    *
7801    * ARGUMENTS
7802    *   IN:
7803    *     p_init_msg_list      Initialize message stack if it is set to
7804    *                          FND_API.G_TRUE. Default is fnd_api.g_false.
7805    *     p_party_id           Party ID.
7806    *   IN/OUT:
7807    *   OUT:
7808    *     x_party_rec          Returned party record.
7809    *     x_return_status      Return status after the call. The status can
7810    *                          be fnd_api.g_ret_sts_success (success),
7811    *                          fnd_api.g_ret_sts_error (error),
7812    *                          fnd_api.g_ret_sts_unexp_error (unexpected error).
7813    *     x_msg_count          Number of messages in message stack.
7814    *     x_msg_data           Message text if x_msg_count is 1.
7815    *
7816    * NOTES
7817    *
7818    * MODIFICATION HISTORY
7819    *
7820    *   07-23-2001    Indrajit Sen        o Created.
7821    *
7822    */
7823 
7824   PROCEDURE get_party_rec (
7825     p_init_msg_list                    IN     VARCHAR2 := fnd_api.g_false,
7826     p_party_id                         IN     NUMBER,
7827     x_party_rec                        OUT    NOCOPY PARTY_REC_TYPE,
7828     x_return_status                    OUT NOCOPY    VARCHAR2,
7829     x_msg_count                        OUT NOCOPY    NUMBER,
7830     x_msg_data                         OUT NOCOPY    VARCHAR2
7831   ) IS
7832 
7833     l_api_name                         CONSTANT VARCHAR2(30) := 'get_party_rec';
7834 
7835     x_party_dup_rec                    PARTY_DUP_REC_TYPE;
7836     l_party_name                       HZ_PARTIES.PARTY_NAME%TYPE;
7837     l_party_type                       HZ_PARTIES.PARTY_TYPE%TYPE;
7838     l_customer_key                     HZ_PARTIES.CUSTOMER_KEY%TYPE;
7839     l_group_type                       HZ_PARTIES.GROUP_TYPE%TYPE;
7840     l_country                          HZ_PARTIES.COUNTRY%TYPE;
7841     l_address1                         HZ_PARTIES.ADDRESS1%TYPE;
7842     l_address2                         HZ_PARTIES.ADDRESS2%TYPE;
7843     l_address3                         HZ_PARTIES.ADDRESS3%TYPE;
7844     l_address4                         HZ_PARTIES.ADDRESS4%TYPE;
7845     l_city                             HZ_PARTIES.CITY%TYPE;
7846     l_state                            HZ_PARTIES.STATE%TYPE;
7847     l_postal_code                      HZ_PARTIES.POSTAL_CODE%TYPE;
7848     l_province                         HZ_PARTIES.PROVINCE%TYPE;
7849     l_county                           HZ_PARTIES.COUNTY%TYPE;
7850     l_url                              HZ_PARTIES.URL%TYPE;
7851     l_email_address                    HZ_PARTIES.EMAIL_ADDRESS%TYPE;
7852     l_language_name                    HZ_PARTIES.LANGUAGE_NAME%TYPE;
7853     l_created_by_module                HZ_PARTIES.CREATED_BY_MODULE%TYPE;
7854     l_application_id                   NUMBER;
7855     l_debug_prefix                     VARCHAR2(30) := '';
7856   BEGIN
7857 
7858     --Initialize message list if p_init_msg_list is set to TRUE.
7859     IF fnd_api.to_boolean(p_init_msg_list) THEN
7860       fnd_msg_pub.initialize;
7861     END IF;
7862 
7863     --Initialize API return status to success.
7864     x_return_status := fnd_api.g_ret_sts_success;
7865 
7866     --Check whether primary key has been passed in.
7867     IF p_party_id IS NULL OR
7868        p_party_id = fnd_api.g_miss_num
7869     THEN
7870       fnd_message.set_name('AR', 'HZ_API_MISSING_COLUMN');
7871       fnd_message.set_token('COLUMN', 'party_id');
7872       fnd_msg_pub.add;
7873       RAISE fnd_api.g_exc_error;
7874     END IF;
7875 
7876     x_party_rec.party_id := p_party_id;
7877 
7878     hz_parties_pkg.Select_Row (
7879       x_party_id                     => x_party_rec.party_id,
7880       x_party_number                 => x_party_rec.party_number,
7881       x_party_name                   => l_party_name,
7882       x_party_type                   => l_party_type,
7883       x_validated_flag               => x_party_rec.validated_flag,
7884       x_attribute_category           => x_party_rec.attribute_category,
7885       x_attribute1                   => x_party_rec.attribute1,
7886       x_attribute2                   => x_party_rec.attribute2,
7887       x_attribute3                   => x_party_rec.attribute3,
7888       x_attribute4                   => x_party_rec.attribute4,
7889       x_attribute5                   => x_party_rec.attribute5,
7890       x_attribute6                   => x_party_rec.attribute6,
7891       x_attribute7                   => x_party_rec.attribute7,
7892       x_attribute8                   => x_party_rec.attribute8,
7893       x_attribute9                   => x_party_rec.attribute9,
7894       x_attribute10                  => x_party_rec.attribute10,
7895       x_attribute11                  => x_party_rec.attribute11,
7896       x_attribute12                  => x_party_rec.attribute12,
7897       x_attribute13                  => x_party_rec.attribute13,
7898       x_attribute14                  => x_party_rec.attribute14,
7899       x_attribute15                  => x_party_rec.attribute15,
7900       x_attribute16                  => x_party_rec.attribute16,
7901       x_attribute17                  => x_party_rec.attribute17,
7902       x_attribute18                  => x_party_rec.attribute18,
7903       x_attribute19                  => x_party_rec.attribute19,
7904       x_attribute20                  => x_party_rec.attribute20,
7905       x_attribute21                  => x_party_rec.attribute21,
7906       x_attribute22                  => x_party_rec.attribute22,
7907       x_attribute23                  => x_party_rec.attribute23,
7908       x_attribute24                  => x_party_rec.attribute24,
7909       x_orig_system_reference        => x_party_rec.orig_system_reference,
7910       x_sic_code                     => x_party_dup_rec.sic_code,
7911       x_hq_branch_ind                => x_party_dup_rec.hq_branch_ind,
7912       x_customer_key                 => l_customer_key,
7913       x_tax_reference                => x_party_dup_rec.tax_reference,
7914       x_jgzz_fiscal_code             => x_party_dup_rec.jgzz_fiscal_code,
7915       x_person_pre_name_adjunct      => x_party_dup_rec.pre_name_adjunct,
7916       x_person_first_name            => x_party_dup_rec.first_name,
7917       x_person_middle_name           => x_party_dup_rec.middle_name,
7918       x_person_last_name             => x_party_dup_rec.last_name,
7919       x_person_name_suffix           => x_party_dup_rec.name_suffix,
7920       x_person_title                 => x_party_dup_rec.title,
7921       x_person_academic_title        => x_party_dup_rec.academic_title,
7922       x_person_previous_last_name    => x_party_dup_rec.previous_last_name,
7923       x_known_as                     => x_party_dup_rec.known_as,
7924       x_person_iden_type             => x_party_dup_rec.person_iden_type,
7925       x_person_identifier            => x_party_dup_rec.person_identifier,
7926       x_group_type                   => l_group_type,
7927       x_country                      => l_country,
7928       x_address1                     => l_address1,
7929       x_address2                     => l_address2,
7930       x_address3                     => l_address3,
7931       x_address4                     => l_address4,
7932       x_city                         => l_city,
7933       x_postal_code                  => l_postal_code,
7934       x_state                        => l_state,
7935       x_province                     => l_province,
7936       x_status                       => x_party_rec.status,
7937       x_county                       => l_county,
7938       x_sic_code_type                => x_party_dup_rec.sic_code_type,
7939       x_url                          => l_url,
7940       x_email_address                => l_email_address,
7941       x_analysis_fy                  => x_party_dup_rec.analysis_fy,
7942       x_fiscal_yearend_month         => x_party_dup_rec.fiscal_yearend_month,
7943       x_employees_total              => x_party_dup_rec.employees_total,
7944       x_curr_fy_potential_revenue    => x_party_dup_rec.curr_fy_potential_revenue,
7945       x_next_fy_potential_revenue    => x_party_dup_rec.next_fy_potential_revenue,
7946       x_year_established             => x_party_dup_rec.year_established,
7947       x_gsa_indicator_flag           => x_party_dup_rec.gsa_indicator_flag,
7948       x_mission_statement            => x_party_dup_rec.mission_statement,
7949       x_organization_name_phonetic   => x_party_dup_rec.organization_name_phonetic,
7950       x_person_first_name_phonetic   => x_party_dup_rec.person_first_name_phonetic,
7951       x_person_last_name_phonetic    => x_party_dup_rec.person_last_name_phonetic,
7952       x_language_name                => l_language_name,
7953       x_category_code                => x_party_rec.category_code,
7954       x_salutation                   => x_party_rec.salutation,
7955       x_known_as2                    => x_party_dup_rec.known_as2,
7956       x_known_as3                    => x_party_dup_rec.known_as3,
7957       x_known_as4                    => x_party_dup_rec.known_as4,
7958       x_known_as5                    => x_party_dup_rec.known_as5,
7959       x_duns_number_c                => x_party_dup_rec.duns_number_c,
7960       x_created_by_module            => l_created_by_module,
7961       x_application_id               => l_application_id
7962     );
7963 
7964     --Standard call to get message count and if count is 1, get message info.
7965     fnd_msg_pub.count_and_get(
7966       p_encoded                      => fnd_api.g_false,
7967       p_count                        => x_msg_count,
7968       p_data                         => x_msg_data);
7969 
7970   EXCEPTION
7971     WHEN fnd_api.g_exc_error THEN
7972       x_return_status := fnd_api.g_ret_sts_error;
7973 
7974       fnd_msg_pub.count_and_get(
7975         p_encoded                    => fnd_api.g_false,
7976         p_count                      => x_msg_count,
7977         p_data                       => x_msg_data);
7978 
7979     WHEN fnd_api.g_exc_unexpected_error THEN
7980       x_return_status := fnd_api.g_ret_sts_unexp_error;
7981 
7982       fnd_msg_pub.count_and_get(
7983         p_encoded                    => fnd_api.g_false,
7984         p_count                      => x_msg_count,
7985         p_data                       => x_msg_data);
7986 
7987     WHEN OTHERS THEN
7988       x_return_status := fnd_api.g_ret_sts_unexp_error;
7989 
7990       fnd_message.set_name('AR', 'HZ_API_OTHERS_EXCEP');
7991       fnd_message.set_token('ERROR',SQLERRM);
7992       fnd_msg_pub.add;
7993 
7994       fnd_msg_pub.count_and_get(
7995         p_encoded                    => fnd_api.g_false,
7996         p_count                      => x_msg_count,
7997         p_data                       => x_msg_data);
7998 
7999   END get_party_rec;
8000 
8001   /**
8002    * The following code might be removed when we stop supporting those
8003    * obsolete columns.
8004    */
8005 
8006   /**
8007    * insert credit related data to hz_credit_rating
8008    */
8009 
8010 /*  24-Sep-2004     V.Ravichandran     o Bug 3868940 : Defaulted the rated_as_of_date to sysdate
8011  *                                       while creating a credit_rating in populate_credit_rating()
8012  *                                       procedure and retained its previous value while updating
8013  *                                       a credit rating populate_credit_rating procedure.
8014  *                                       Called HZ_PARTY_INFO_V2PUB.create/update_credit_rating
8015  *                                       from populate_credit_rating() procedure directly
8016  *                                       instead of calling the V1 APIs
8017  *                                       HZ_PARTY_INFO_PUB.create/updating_credit_rating
8018  *                                       Commented out the procedure org_rec_to_cr_rec.
8019  */
8020 
8021 
8022   PROCEDURE  populate_credit_rating(
8023     p_create_update_flag               IN     VARCHAR2,
8024     p_organization_rec                 IN     ORGANIZATION_REC_TYPE,
8025     x_return_status                    IN OUT NOCOPY VARCHAR2
8026   ) IS
8027 
8028     l_credit_rating_rec                HZ_PARTY_INFO_V2PUB.credit_rating_rec_type;
8029     l_last_update_date                 DATE := sysdate;
8030     l_credit_rating_id                 NUMBER;
8031     l_rated_as_of_date                 DATE;
8032     l_exist                            VARCHAR2(1);
8033     l_msg_count                        NUMBER;
8034     l_msg_data                         VARCHAR2(2000);
8035     l_debug_prefix                     VARCHAR2(30) := '';
8036     l_object_version_number              NUMBER;
8037 BEGIN
8038 
8039    IF p_organization_rec.actual_content_source IN
8040          (G_MISS_CONTENT_SOURCE_TYPE, G_SST_SOURCE_TYPE) AND
8041        ( p_create_update_flag = 'C' AND
8042          NOT(
8043              ( p_organization_rec.AVG_HIGH_CREDIT is null OR
8044                p_organization_rec.AVG_HIGH_CREDIT = FND_API.G_MISS_NUM ) AND
8045              ( p_organization_rec.CREDIT_SCORE is null OR
8046                p_organization_rec.CREDIT_SCORE = FND_API.G_MISS_CHAR) AND
8047              ( p_organization_rec.CREDIT_SCORE_AGE is null OR
8048                p_organization_rec.CREDIT_SCORE_AGE = FND_API.G_MISS_NUM) AND
8049              ( p_organization_rec.CREDIT_SCORE_CLASS is null OR
8050                p_organization_rec.CREDIT_SCORE_CLASS = FND_API.G_MISS_NUM) AND
8051              ( p_organization_rec.CREDIT_SCORE_COMMENTARY is null OR
8052                p_organization_rec.CREDIT_SCORE_COMMENTARY = FND_API.G_MISS_CHAR) AND
8053              ( p_organization_rec.CREDIT_SCORE_COMMENTARY2 is null OR
8054                p_organization_rec.CREDIT_SCORE_COMMENTARY2 = FND_API.G_MISS_CHAR) AND
8055              ( p_organization_rec.CREDIT_SCORE_COMMENTARY3 is null OR
8056                p_organization_rec.CREDIT_SCORE_COMMENTARY3 = FND_API.G_MISS_CHAR) AND
8057              ( p_organization_rec.CREDIT_SCORE_COMMENTARY4 is null OR
8058                p_organization_rec.CREDIT_SCORE_COMMENTARY4 = FND_API.G_MISS_CHAR) AND
8059              ( p_organization_rec.CREDIT_SCORE_COMMENTARY5 is null OR
8060                p_organization_rec.CREDIT_SCORE_COMMENTARY5 = FND_API.G_MISS_CHAR) AND
8061              ( p_organization_rec.CREDIT_SCORE_COMMENTARY6 is null OR
8062                p_organization_rec.CREDIT_SCORE_COMMENTARY6 = FND_API.G_MISS_CHAR) AND
8063              ( p_organization_rec.CREDIT_SCORE_COMMENTARY7 is null OR
8064                p_organization_rec.CREDIT_SCORE_COMMENTARY7 = FND_API.G_MISS_CHAR) AND
8065              ( p_organization_rec.CREDIT_SCORE_COMMENTARY8 is null OR
8066                p_organization_rec.CREDIT_SCORE_COMMENTARY8 = FND_API.G_MISS_CHAR) AND
8067              ( p_organization_rec.CREDIT_SCORE_COMMENTARY9 is null OR
8068                p_organization_rec.CREDIT_SCORE_COMMENTARY9 = FND_API.G_MISS_CHAR) AND
8069              ( p_organization_rec.CREDIT_SCORE_COMMENTARY10 is null OR
8070                p_organization_rec.CREDIT_SCORE_COMMENTARY10 = FND_API.G_MISS_CHAR) AND
8071              ( p_organization_rec.CREDIT_SCORE_DATE is null OR
8072                p_organization_rec.CREDIT_SCORE_DATE = FND_API.G_MISS_DATE) AND
8073              ( p_organization_rec.CREDIT_SCORE_INCD_DEFAULT is null OR
8074                p_organization_rec.CREDIT_SCORE_INCD_DEFAULT = FND_API.G_MISS_NUM) AND
8075              ( p_organization_rec.CREDIT_SCORE_NATL_PERCENTILE is null OR
8076                p_organization_rec.CREDIT_SCORE_NATL_PERCENTILE = FND_API.G_MISS_NUM) AND
8077              ( p_organization_rec.DB_RATING is null OR
8078                p_organization_rec.DB_RATING = FND_API.G_MISS_CHAR) AND
8079              ( p_organization_rec.DEBARMENT_IND is null OR
8080                p_organization_rec.DEBARMENT_IND = FND_API.G_MISS_CHAR) AND
8081              ( p_organization_rec.DEBARMENTS_COUNT is null OR
8082                p_organization_rec.DEBARMENTS_COUNT = FND_API.G_MISS_NUM) AND
8083              ( p_organization_rec.DEBARMENTS_DATE is null OR
8084                p_organization_rec.DEBARMENTS_DATE = FND_API.G_MISS_DATE) AND
8085              ( p_organization_rec.HIGH_CREDIT is null OR
8086                p_organization_rec.HIGH_CREDIT = FND_API.G_MISS_NUM) AND
8087              ( p_organization_rec.MAXIMUM_CREDIT_CURRENCY_CODE is null OR
8088                p_organization_rec.MAXIMUM_CREDIT_CURRENCY_CODE = FND_API.G_MISS_CHAR) AND
8089              ( p_organization_rec.MAXIMUM_CREDIT_RECOMMENDATION is null OR
8090                p_organization_rec.MAXIMUM_CREDIT_RECOMMENDATION = FND_API.G_MISS_NUM) AND
8091              ( p_organization_rec.PAYDEX_NORM is null OR
8092                p_organization_rec.PAYDEX_NORM = FND_API.G_MISS_CHAR) AND
8093              ( p_organization_rec.PAYDEX_SCORE is null OR
8094                p_organization_rec.PAYDEX_SCORE = FND_API.G_MISS_CHAR) AND
8095              ( p_organization_rec.PAYDEX_THREE_MONTHS_AGO  is null OR
8096                p_organization_rec.PAYDEX_THREE_MONTHS_AGO  = FND_API.G_MISS_CHAR) AND
8097              ( p_organization_rec.FAILURE_SCORE is null OR
8098                p_organization_rec.FAILURE_SCORE = FND_API.G_MISS_CHAR ) AND
8099              ( p_organization_rec.FAILURE_SCORE_AGE is null OR
8100                p_organization_rec.FAILURE_SCORE_AGE = FND_API.G_MISS_NUM) AND
8101              ( p_organization_rec.FAILURE_SCORE_CLASS is null OR
8102                p_organization_rec.FAILURE_SCORE_CLASS = FND_API.G_MISS_NUM) AND
8103              ( p_organization_rec.FAILURE_SCORE_COMMENTARY is null OR
8104                p_organization_rec.FAILURE_SCORE_COMMENTARY = FND_API.G_MISS_CHAR) AND
8105              ( p_organization_rec.FAILURE_SCORE_COMMENTARY2 is null OR
8106                p_organization_rec.FAILURE_SCORE_COMMENTARY2 = FND_API.G_MISS_CHAR) AND
8107              ( p_organization_rec.FAILURE_SCORE_COMMENTARY3 is null OR
8108                p_organization_rec.FAILURE_SCORE_COMMENTARY3 = FND_API.G_MISS_CHAR) AND
8109              ( p_organization_rec.FAILURE_SCORE_COMMENTARY4 is null OR
8110                p_organization_rec.FAILURE_SCORE_COMMENTARY4 = FND_API.G_MISS_CHAR) AND
8111              ( p_organization_rec.FAILURE_SCORE_COMMENTARY5 is null OR
8112                p_organization_rec.FAILURE_SCORE_COMMENTARY5 = FND_API.G_MISS_CHAR) AND
8113              ( p_organization_rec.FAILURE_SCORE_COMMENTARY6 is null OR
8114                p_organization_rec.FAILURE_SCORE_COMMENTARY6 = FND_API.G_MISS_CHAR) AND
8115              ( p_organization_rec.FAILURE_SCORE_COMMENTARY7 is null OR
8116                p_organization_rec.FAILURE_SCORE_COMMENTARY7 = FND_API.G_MISS_CHAR) AND
8117              ( p_organization_rec.FAILURE_SCORE_COMMENTARY8 is null OR
8118                p_organization_rec.FAILURE_SCORE_COMMENTARY8 = FND_API.G_MISS_CHAR) AND
8119              ( p_organization_rec.FAILURE_SCORE_COMMENTARY9 is null OR
8120                p_organization_rec.FAILURE_SCORE_COMMENTARY9 = FND_API.G_MISS_CHAR) AND
8121              ( p_organization_rec.FAILURE_SCORE_COMMENTARY10 is null OR
8122                p_organization_rec.FAILURE_SCORE_COMMENTARY10 = FND_API.G_MISS_CHAR) AND
8123              ( p_organization_rec.FAILURE_SCORE_DATE is null OR
8124                p_organization_rec.FAILURE_SCORE_DATE = FND_API.G_MISS_DATE) AND
8125              ( p_organization_rec.FAILURE_SCORE_INCD_DEFAULT is null OR
8126                p_organization_rec.FAILURE_SCORE_INCD_DEFAULT = FND_API.G_MISS_NUM) AND
8127              ( p_organization_rec.FAILURE_SCORE_NATNL_PERCENTILE is null OR
8128                p_organization_rec.FAILURE_SCORE_NATNL_PERCENTILE = FND_API.G_MISS_NUM) AND
8129              ( p_organization_rec.FAILURE_SCORE_OVERRIDE_CODE is null OR
8130                p_organization_rec.FAILURE_SCORE_OVERRIDE_CODE = FND_API.G_MISS_CHAR) AND
8131              ( p_organization_rec.GLOBAL_FAILURE_SCORE is null OR
8132                p_organization_rec.GLOBAL_FAILURE_SCORE = FND_API.G_MISS_CHAR)
8133             ) ) OR
8134        ( p_create_update_flag = 'U' AND
8135            (   p_organization_rec.AVG_HIGH_CREDIT is not null OR
8136             p_organization_rec.CREDIT_SCORE  is not null OR
8137             p_organization_rec.CREDIT_SCORE_AGE is not null OR
8138             p_organization_rec.CREDIT_SCORE_CLASS is not null OR
8139             p_organization_rec.CREDIT_SCORE_COMMENTARY is not null OR
8140             p_organization_rec.CREDIT_SCORE_COMMENTARY2 is not null OR
8141             p_organization_rec.CREDIT_SCORE_COMMENTARY3 is not null OR
8142             p_organization_rec.CREDIT_SCORE_COMMENTARY4 is not null OR
8143             p_organization_rec.CREDIT_SCORE_COMMENTARY5 is not null OR
8144             p_organization_rec.CREDIT_SCORE_COMMENTARY6 is not null OR
8145             p_organization_rec.CREDIT_SCORE_COMMENTARY7 is not null OR
8146             p_organization_rec.CREDIT_SCORE_COMMENTARY8 is not null OR
8147             p_organization_rec.CREDIT_SCORE_COMMENTARY9 is not null OR
8148             p_organization_rec.CREDIT_SCORE_COMMENTARY10 is not null OR
8149             p_organization_rec.CREDIT_SCORE_DATE is not null OR
8150             p_organization_rec.CREDIT_SCORE_INCD_DEFAULT is not null OR
8151             p_organization_rec.CREDIT_SCORE_NATL_PERCENTILE is not null OR
8152             p_organization_rec.DB_RATING is not null OR
8153             p_organization_rec.DEBARMENT_IND is not null OR
8154             p_organization_rec.DEBARMENTS_COUNT is not null OR
8155             p_organization_rec.DEBARMENTS_DATE is not null OR
8156             p_organization_rec.HIGH_CREDIT is not null OR
8157             p_organization_rec.MAXIMUM_CREDIT_CURRENCY_CODE is not null OR
8158             p_organization_rec.MAXIMUM_CREDIT_RECOMMENDATION is not null OR
8159             p_organization_rec.PAYDEX_NORM is not null OR
8160             p_organization_rec.PAYDEX_SCORE is not null OR
8161             p_organization_rec.PAYDEX_THREE_MONTHS_AGO is not null OR
8162             p_organization_rec.FAILURE_SCORE  is not null OR
8163             p_organization_rec.FAILURE_SCORE_AGE is not null OR
8164             p_organization_rec.FAILURE_SCORE_CLASS is not null OR
8165             p_organization_rec.FAILURE_SCORE_COMMENTARY  is not null OR
8166             p_organization_rec.FAILURE_SCORE_COMMENTARY2 is not null OR
8167             p_organization_rec.FAILURE_SCORE_COMMENTARY3 is not null OR
8168             p_organization_rec.FAILURE_SCORE_COMMENTARY4 is not null OR
8169             p_organization_rec.FAILURE_SCORE_COMMENTARY5 is not null OR
8170             p_organization_rec.FAILURE_SCORE_COMMENTARY6 is not null OR
8171             p_organization_rec.FAILURE_SCORE_COMMENTARY7 is not null OR
8172             p_organization_rec.FAILURE_SCORE_COMMENTARY8 is not null OR
8173             p_organization_rec.FAILURE_SCORE_COMMENTARY9 is not null OR
8174             p_organization_rec.FAILURE_SCORE_COMMENTARY10 is not null OR
8175             p_organization_rec.FAILURE_SCORE_DATE         is not null OR
8176             p_organization_rec.FAILURE_SCORE_INCD_DEFAULT is not null OR
8177             p_organization_rec.FAILURE_SCORE_NATNL_PERCENTILE is not null OR
8178             p_organization_rec.FAILURE_SCORE_OVERRIDE_CODE is not null OR
8179             p_organization_rec.GLOBAL_FAILURE_SCORE
8180            is not null) )
8181     THEN
8182       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
8183         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'copy record from ORGANIZATION_REC_TYPE '||
8184                                'to CREDIT_RATINGS_REC_TYPE  (+)',
8185                                p_msg_level=>fnd_log.level_procedure);
8186       END IF;
8187 
8188 
8189       l_credit_rating_rec.PARTY_ID :=  p_organization_rec.party_rec.PARTY_ID;
8190       l_credit_rating_rec.AVG_HIGH_CREDIT :=  p_organization_rec.AVG_HIGH_CREDIT;
8191       l_credit_rating_rec.CREDIT_SCORE := p_organization_rec.CREDIT_SCORE;
8192       l_credit_rating_rec.CREDIT_SCORE_AGE := p_organization_rec.CREDIT_SCORE_AGE;
8193       l_credit_rating_rec.CREDIT_SCORE_CLASS := p_organization_rec.CREDIT_SCORE_CLASS;
8194       l_credit_rating_rec.CREDIT_SCORE_COMMENTARY := p_organization_rec.CREDIT_SCORE_COMMENTARY;
8195       l_credit_rating_rec.CREDIT_SCORE_COMMENTARY2 := p_organization_rec.CREDIT_SCORE_COMMENTARY2;
8196       l_credit_rating_rec.CREDIT_SCORE_COMMENTARY3 := p_organization_rec.CREDIT_SCORE_COMMENTARY3;
8197       l_credit_rating_rec.CREDIT_SCORE_COMMENTARY4 := p_organization_rec.CREDIT_SCORE_COMMENTARY4;
8198       l_credit_rating_rec.CREDIT_SCORE_COMMENTARY5 := p_organization_rec.CREDIT_SCORE_COMMENTARY5;
8199       l_credit_rating_rec.CREDIT_SCORE_COMMENTARY6 := p_organization_rec.CREDIT_SCORE_COMMENTARY6;
8200       l_credit_rating_rec.CREDIT_SCORE_COMMENTARY7 := p_organization_rec.CREDIT_SCORE_COMMENTARY7;
8201       l_credit_rating_rec.CREDIT_SCORE_COMMENTARY8 := p_organization_rec.CREDIT_SCORE_COMMENTARY8;
8202       l_credit_rating_rec.CREDIT_SCORE_COMMENTARY9 := p_organization_rec.CREDIT_SCORE_COMMENTARY9;
8203       l_credit_rating_rec.CREDIT_SCORE_COMMENTARY10 := p_organization_rec.CREDIT_SCORE_COMMENTARY10;
8204       l_credit_rating_rec.CREDIT_SCORE_DATE := p_organization_rec.CREDIT_SCORE_DATE;
8205       l_credit_rating_rec.CREDIT_SCORE_INCD_DEFAULT := p_organization_rec.CREDIT_SCORE_INCD_DEFAULT;
8206       l_credit_rating_rec.CREDIT_SCORE_NATL_PERCENTILE := p_organization_rec.CREDIT_SCORE_NATL_PERCENTILE;
8207       l_credit_rating_rec.RATING := p_organization_rec.DB_RATING;
8208       l_credit_rating_rec.DEBARMENT_IND := p_organization_rec.DEBARMENT_IND;
8209       l_credit_rating_rec.DEBARMENTS_COUNT := p_organization_rec.DEBARMENTS_COUNT;
8210       l_credit_rating_rec.DEBARMENTS_DATE := p_organization_rec.DEBARMENTS_DATE;
8211       l_credit_rating_rec.HIGH_CREDIT := p_organization_rec.HIGH_CREDIT;
8212       l_credit_rating_rec.MAXIMUM_CREDIT_CURRENCY_CODE := p_organization_rec.MAXIMUM_CREDIT_CURRENCY_CODE;
8213       l_credit_rating_rec.MAXIMUM_CREDIT_RCMD := p_organization_rec.MAXIMUM_CREDIT_RECOMMENDATION;
8214       l_credit_rating_rec.PAYDEX_NORM := p_organization_rec.PAYDEX_NORM;
8215       l_credit_rating_rec.PAYDEX_SCORE := p_organization_rec.PAYDEX_SCORE;
8216       l_credit_rating_rec.PAYDEX_THREE_MONTHS_AGO := p_organization_rec.PAYDEX_THREE_MONTHS_AGO;
8217       l_credit_rating_rec.FAILURE_SCORE := p_organization_rec.FAILURE_SCORE;
8218       l_credit_rating_rec.FAILURE_SCORE_AGE := p_organization_rec.FAILURE_SCORE_AGE;
8219       l_credit_rating_rec.FAILURE_SCORE_CLASS := p_organization_rec.FAILURE_SCORE_CLASS;
8220       l_credit_rating_rec.FAILURE_SCORE_COMMENTARY := p_organization_rec.FAILURE_SCORE_COMMENTARY;
8221       l_credit_rating_rec.FAILURE_SCORE_COMMENTARY2 := p_organization_rec.FAILURE_SCORE_COMMENTARY2;
8222       l_credit_rating_rec.FAILURE_SCORE_COMMENTARY3 := p_organization_rec.FAILURE_SCORE_COMMENTARY3;
8223       l_credit_rating_rec.FAILURE_SCORE_COMMENTARY4 := p_organization_rec.FAILURE_SCORE_COMMENTARY4;
8224       l_credit_rating_rec.FAILURE_SCORE_COMMENTARY5 := p_organization_rec.FAILURE_SCORE_COMMENTARY5;
8225       l_credit_rating_rec.FAILURE_SCORE_COMMENTARY6 := p_organization_rec.FAILURE_SCORE_COMMENTARY6;
8226       l_credit_rating_rec.FAILURE_SCORE_COMMENTARY7 := p_organization_rec.FAILURE_SCORE_COMMENTARY7;
8227       l_credit_rating_rec.FAILURE_SCORE_COMMENTARY8 := p_organization_rec.FAILURE_SCORE_COMMENTARY8;
8228       l_credit_rating_rec.FAILURE_SCORE_COMMENTARY9 := p_organization_rec.FAILURE_SCORE_COMMENTARY9;
8229       l_credit_rating_rec.FAILURE_SCORE_COMMENTARY10 := p_organization_rec.FAILURE_SCORE_COMMENTARY10;
8230       l_credit_rating_rec.FAILURE_SCORE_DATE := p_organization_rec.FAILURE_SCORE_DATE;
8231       l_credit_rating_rec.FAILURE_SCORE_INCD_DEFAULT := p_organization_rec.FAILURE_SCORE_INCD_DEFAULT;
8232       l_credit_rating_rec.FAILURE_SCORE_NATNL_PERCENTILE := p_organization_rec.FAILURE_SCORE_NATNL_PERCENTILE;
8233       l_credit_rating_rec.FAILURE_SCORE_OVERRIDE_CODE := p_organization_rec.FAILURE_SCORE_OVERRIDE_CODE;
8234       l_credit_rating_rec.GLOBAL_FAILURE_SCORE := p_organization_rec.GLOBAL_FAILURE_SCORE;
8235       l_credit_rating_rec.created_by_module := p_organization_rec.created_by_module;
8236 
8237       IF p_create_update_flag='C'
8238       THEN
8239       l_credit_rating_rec.rated_as_of_date := sysdate;
8240       ELSE
8241       l_credit_rating_rec.rated_as_of_date := to_date(null);
8242       END IF;
8243 
8244       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
8245         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'copy record from ORGANIZATION_REC_TYPE '||
8246                                'to CREDIT_RATINGS_REC_TYPE (-)',
8247                                p_msg_level=>fnd_log.level_procedure);
8248       END IF;
8249 
8250 
8251 
8252       IF p_create_update_flag='C'  THEN
8253         /*IF g_debug THEN
8254           hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'call to create credit_rating (+)');
8255         END IF;
8256         */
8257         IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
8258             hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'call to create credit_rating (+)',
8259                                p_msg_level=>fnd_log.level_procedure);
8260         END IF;
8261         /*
8262         org_rec_to_cr_rec(
8263          p_create_update_flag               => 'C',
8264          p_organization_rec                 => p_organization_rec,
8265          x_credit_rating_rec                => l_credit_rating_rec );
8266 
8267         HZ_PARTY_INFO_PUB.create_credit_ratings(
8268           p_api_version           => 1,
8269           p_credit_ratings_rec    => l_credit_rating_rec,
8270           x_return_status         => x_return_status,
8271           x_msg_count             => l_msg_count,
8272           x_msg_data              => l_msg_data,
8273           x_credit_rating_id      => l_credit_rating_id
8274         );
8275         */
8276         HZ_PARTY_INFO_V2PUB.create_credit_rating(
8277            p_init_msg_list      => 'F',
8278            p_credit_rating_rec  => l_credit_rating_rec,
8279            x_credit_rating_id   => l_credit_rating_id,
8280            x_return_status      => x_return_status,
8281            x_msg_count          => l_msg_count,
8282            x_msg_data           => l_msg_data
8283         );
8284 
8285 
8286         /*IF g_debug THEN
8287           hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'call to create credit_rating (-)');
8288           hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'x_return_status = '||x_return_status);
8289         END IF;
8290         */
8291         IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
8292            hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'call to create credit_rating (-)',
8293                                p_msg_level=>fnd_log.level_procedure);
8294 
8295         END IF;
8296         IF fnd_log.level_statement>=fnd_log.g_current_runtime_level THEN
8297            hz_utility_v2pub.debug(p_message=>'x_return_status = '||x_return_status,
8298                                   p_prefix =>l_debug_prefix,
8299                                   p_msg_level=>fnd_log.level_statement);
8300         END IF;
8301       ELSE
8302         /*IF g_debug THEN
8303           hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'call to update credit rating (+)');
8304         END IF;
8305         */
8306         IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
8307                 hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'call to update credit rating (+)',
8308                                p_msg_level=>fnd_log.level_procedure);
8309         END IF;
8310 
8311         -- get the latest record for one party_id
8312 
8313         SELECT MAX(rated_as_of_date)
8314         INTO l_rated_as_of_date
8315         FROM hz_credit_ratings
8316         WHERE party_id = p_organization_rec.party_rec.party_id
8317         AND actual_content_source = G_MISS_CONTENT_SOURCE_TYPE;
8318 
8319         /*IF g_debug THEN
8320           hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'l_rated_as_of_date = ' || l_rated_as_of_date);
8321           hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'p_organization_rec.party_rec.party_id = ' ||
8322                                   p_organization_rec.party_rec.party_id);
8323         END IF;
8324         */
8325         IF fnd_log.level_statement>=fnd_log.g_current_runtime_level THEN
8326            hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'l_rated_as_of_date = ' || l_rated_as_of_date,
8327                                p_msg_level=>fnd_log.level_statement);
8328            hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'p_organization_rec.party_rec.party_id = ' ||
8329                                   p_organization_rec.party_rec.party_id,
8330                                p_msg_level=>fnd_log.level_statement);
8331 
8332         END IF;
8333 
8334 
8335         BEGIN
8336           SELECT credit_rating_id, last_update_date,object_version_number
8337           INTO l_credit_rating_id, l_last_update_date,l_object_version_number
8338           FROM hz_credit_ratings
8339           WHERE party_id = p_organization_rec.party_rec.party_id
8340           AND actual_content_source =  G_MISS_CONTENT_SOURCE_TYPE
8341           AND(rated_as_of_date = l_rated_as_of_date OR
8342               (rated_as_of_date is null AND
8343                l_rated_as_of_date is null));
8344         EXCEPTION
8345           WHEN TOO_MANY_ROWS THEN
8346             SELECT credit_rating_id, last_update_date,object_version_number
8347             INTO l_credit_rating_id, l_last_update_date,l_object_version_number
8348             FROM hz_credit_ratings
8349             WHERE party_id = p_organization_rec.party_rec.party_id
8350             AND actual_content_source = G_MISS_CONTENT_SOURCE_TYPE
8351             AND (rated_as_of_date = l_rated_as_of_date OR
8352                  (rated_as_of_date is null AND
8353                   l_rated_as_of_date is null))
8354             AND last_update_date = (
8355               SELECT MAX(last_update_date)
8356               FROM hz_credit_ratings
8357               WHERE party_id = p_organization_rec.party_rec.party_id
8358               AND actual_content_source = G_MISS_CONTENT_SOURCE_TYPE
8359               AND (rated_as_of_date = l_rated_as_of_date OR
8360                    (rated_as_of_date is null AND
8361                     l_rated_as_of_date is null)))
8362             AND ROWNUM = 1;
8363         END;
8364 
8365         /*IF g_debug THEN
8366           hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'l_credit_rating_id = ' || l_credit_rating_id);
8367         END IF;
8368         */
8369         IF fnd_log.level_statement>=fnd_log.g_current_runtime_level THEN
8370            hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'l_credit_rating_id = ' || l_credit_rating_id,
8371                                p_msg_level=>fnd_log.level_statement);
8372         END IF;
8373         /*
8374         org_rec_to_cr_rec (
8375           p_create_update_flag               => 'U',
8376           p_organization_rec                 => p_organization_rec,
8377           x_credit_rating_rec                => l_credit_rating_rec );
8378         */
8379         l_credit_rating_rec.credit_rating_id := l_credit_rating_id;
8380 
8381         /*IF g_debug THEN
8382           hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'l_credit_rating_rec.credit_rating_id= ' ||
8383                                   l_credit_rating_rec.credit_rating_id);
8384         END IF;
8385         */
8386         IF fnd_log.level_statement>=fnd_log.g_current_runtime_level THEN
8387            hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'l_credit_rating_rec.credit_rating_id= ' ||
8388                                   l_credit_rating_rec.credit_rating_id,
8389                                p_msg_level=>fnd_log.level_statement);
8390         END IF;
8391         /*
8392         HZ_PARTY_INFO_PUB.update_credit_ratings(
8393           p_api_version           => 1,
8394           p_credit_ratings_rec    => l_credit_rating_rec,
8395           p_last_update_date      => l_last_update_date,
8396           x_return_status         => x_return_status,
8397           x_msg_count             => l_msg_count,
8398           x_msg_data              => l_msg_data);
8399         */
8400         HZ_PARTY_INFO_V2PUB.update_credit_rating(
8401            p_init_msg_list      => 'F',
8402            p_credit_rating_rec  => l_credit_rating_rec,
8403            p_object_version_number=> l_object_version_number,
8404            x_return_status      => x_return_status,
8405            x_msg_count          => l_msg_count,
8406            x_msg_data           => l_msg_data
8407         );
8408 
8409         /*IF g_debug THEN
8410           hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'call to update credit rating (-)');
8411           hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'x_return_status = '||x_return_status);
8412         END IF;
8413         */
8414         IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
8415              hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'call to update credit rating (-)',
8416                                p_msg_level=>fnd_log.level_procedure);
8417         END IF;
8418         IF fnd_log.level_statement>=fnd_log.g_current_runtime_level THEN
8419            hz_utility_v2pub.debug(p_message=>'x_return_status = '||x_return_status,
8420                                   p_prefix =>l_debug_prefix,
8421                                   p_msg_level=>fnd_log.level_statement);
8422         END IF;
8423       END IF;
8424 
8425       IF x_return_status <> fnd_api.g_ret_sts_success THEN
8426         RAISE fnd_api.g_exc_error;
8427       END IF;
8428     END IF;
8429 
8430   END populate_credit_rating;
8431 
8432   /**
8433    * Convert organization record to v1 credit rating record.
8434    */
8435 
8436   -- Bug 3868940: Commented out org_rec_to_cr_rec
8437 
8438   /*
8439   PROCEDURE  org_rec_to_cr_rec(
8440     p_create_update_flag            IN     VARCHAR2,
8441     p_organization_rec              IN     ORGANIZATION_REC_TYPE,
8442     x_credit_rating_rec             OUT    NOCOPY HZ_PARTY_INFO_PUB.CREDIT_RATINGS_REC_TYPE
8443   ) IS
8444   l_debug_prefix                       VARCHAR2(30) := '';
8445   BEGIN
8446 
8447     IF p_create_update_flag = 'C' THEN
8448 
8449       /*IF g_debug THEN
8450         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'copy record from ORGANIZATION_REC_TYPE '||
8451                                'to CREDIT_RATINGS_REC_TYPE  for create (+)');
8452       END IF;
8453       */
8454       /*
8455       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
8456         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'copy record from ORGANIZATION_REC_TYPE '||
8457                                'to CREDIT_RATINGS_REC_TYPE  for create (+)',
8458                                p_msg_level=>fnd_log.level_procedure);
8459       END IF;
8460 
8461       x_credit_rating_rec.PARTY_ID :=  p_organization_rec.party_rec.PARTY_ID;
8462       x_credit_rating_rec.AVG_HIGH_CREDIT :=  p_organization_rec.AVG_HIGH_CREDIT;
8463       x_credit_rating_rec.CREDIT_SCORE := p_organization_rec.CREDIT_SCORE;
8464       x_credit_rating_rec.CREDIT_SCORE_AGE := p_organization_rec.CREDIT_SCORE_AGE;
8465       x_credit_rating_rec.CREDIT_SCORE_CLASS := p_organization_rec.CREDIT_SCORE_CLASS;
8466       x_credit_rating_rec.CREDIT_SCORE_COMMENTARY := p_organization_rec.CREDIT_SCORE_COMMENTARY;
8467       x_credit_rating_rec.CREDIT_SCORE_COMMENTARY2 := p_organization_rec.CREDIT_SCORE_COMMENTARY2;
8468       x_credit_rating_rec.CREDIT_SCORE_COMMENTARY3 := p_organization_rec.CREDIT_SCORE_COMMENTARY3;
8469       x_credit_rating_rec.CREDIT_SCORE_COMMENTARY4 := p_organization_rec.CREDIT_SCORE_COMMENTARY4;
8470       x_credit_rating_rec.CREDIT_SCORE_COMMENTARY5 := p_organization_rec.CREDIT_SCORE_COMMENTARY5;
8471       x_credit_rating_rec.CREDIT_SCORE_COMMENTARY6 := p_organization_rec.CREDIT_SCORE_COMMENTARY6;
8472       x_credit_rating_rec.CREDIT_SCORE_COMMENTARY7 := p_organization_rec.CREDIT_SCORE_COMMENTARY7;
8473       x_credit_rating_rec.CREDIT_SCORE_COMMENTARY8 := p_organization_rec.CREDIT_SCORE_COMMENTARY8;
8474       x_credit_rating_rec.CREDIT_SCORE_COMMENTARY9 := p_organization_rec.CREDIT_SCORE_COMMENTARY9;
8475       x_credit_rating_rec.CREDIT_SCORE_COMMENTARY10 := p_organization_rec.CREDIT_SCORE_COMMENTARY10;
8476       x_credit_rating_rec.CREDIT_SCORE_DATE := p_organization_rec.CREDIT_SCORE_DATE;
8477       x_credit_rating_rec.CREDIT_SCORE_INCD_DEFAULT := p_organization_rec.CREDIT_SCORE_INCD_DEFAULT;
8478       x_credit_rating_rec.CREDIT_SCORE_NATL_PERCENTILE := p_organization_rec.CREDIT_SCORE_NATL_PERCENTILE;
8479       x_credit_rating_rec.RATING := p_organization_rec.DB_RATING;
8480       x_credit_rating_rec.DEBARMENT_IND := p_organization_rec.DEBARMENT_IND;
8481       x_credit_rating_rec.DEBARMENTS_COUNT := p_organization_rec.DEBARMENTS_COUNT;
8482       x_credit_rating_rec.DEBARMENTS_DATE := p_organization_rec.DEBARMENTS_DATE;
8483       x_credit_rating_rec.HIGH_CREDIT := p_organization_rec.HIGH_CREDIT;
8484       x_credit_rating_rec.MAXIMUM_CREDIT_CURRENCY_CODE := p_organization_rec.MAXIMUM_CREDIT_CURRENCY_CODE;
8485       x_credit_rating_rec.MAXIMUM_CREDIT_RCMD := p_organization_rec.MAXIMUM_CREDIT_RECOMMENDATION;
8486       x_credit_rating_rec.PAYDEX_NORM := p_organization_rec.PAYDEX_NORM;
8487       x_credit_rating_rec.PAYDEX_SCORE := p_organization_rec.PAYDEX_SCORE;
8488       x_credit_rating_rec.PAYDEX_THREE_MONTHS_AGO := p_organization_rec.PAYDEX_THREE_MONTHS_AGO;
8489       x_credit_rating_rec.rated_as_of_date := sysdate;
8490       x_credit_rating_rec.FAILURE_SCORE := p_organization_rec.FAILURE_SCORE;
8491       x_credit_rating_rec.FAILURE_SCORE_AGE := p_organization_rec.FAILURE_SCORE_AGE;
8492       x_credit_rating_rec.FAILURE_SCORE_CLASS := p_organization_rec.FAILURE_SCORE_CLASS;
8493       x_credit_rating_rec.FAILURE_SCORE_COMMENTARY := p_organization_rec.FAILURE_SCORE_COMMENTARY;
8494       x_credit_rating_rec.FAILURE_SCORE_COMMENTARY2 := p_organization_rec.FAILURE_SCORE_COMMENTARY2;
8495       x_credit_rating_rec.FAILURE_SCORE_COMMENTARY3 := p_organization_rec.FAILURE_SCORE_COMMENTARY3;
8496       x_credit_rating_rec.FAILURE_SCORE_COMMENTARY4 := p_organization_rec.FAILURE_SCORE_COMMENTARY4;
8497       x_credit_rating_rec.FAILURE_SCORE_COMMENTARY5 := p_organization_rec.FAILURE_SCORE_COMMENTARY5;
8498       x_credit_rating_rec.FAILURE_SCORE_COMMENTARY6 := p_organization_rec.FAILURE_SCORE_COMMENTARY6;
8499       x_credit_rating_rec.FAILURE_SCORE_COMMENTARY7 := p_organization_rec.FAILURE_SCORE_COMMENTARY7;
8500       x_credit_rating_rec.FAILURE_SCORE_COMMENTARY8 := p_organization_rec.FAILURE_SCORE_COMMENTARY8;
8501       x_credit_rating_rec.FAILURE_SCORE_COMMENTARY9 := p_organization_rec.FAILURE_SCORE_COMMENTARY9;
8502       x_credit_rating_rec.FAILURE_SCORE_COMMENTARY10 := p_organization_rec.FAILURE_SCORE_COMMENTARY10;
8503       x_credit_rating_rec.FAILURE_SCORE_DATE := p_organization_rec.FAILURE_SCORE_DATE;
8504       x_credit_rating_rec.FAILURE_SCORE_INCD_DEFAULT := p_organization_rec.FAILURE_SCORE_INCD_DEFAULT;
8505       x_credit_rating_rec.FAILURE_SCORE_NATNL_PERCENTILE := p_organization_rec.FAILURE_SCORE_NATNL_PERCENTILE;
8506       x_credit_rating_rec.FAILURE_SCORE_OVERRIDE_CODE := p_organization_rec.FAILURE_SCORE_OVERRIDE_CODE;
8507       x_credit_rating_rec.GLOBAL_FAILURE_SCORE := p_organization_rec.GLOBAL_FAILURE_SCORE;
8508 
8509 
8510       /*IF g_debug THEN
8511         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'copy record from ORGANIZATION_REC_TYPE '||
8512                                'to CREDIT_RATINGS_REC_TYPE for create (-)');
8513       END IF;
8514       */
8515       /*
8516       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
8517         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'copy record from ORGANIZATION_REC_TYPE '||
8518                                'to CREDIT_RATINGS_REC_TYPE for create (-)',
8519                                p_msg_level=>fnd_log.level_procedure);
8520       END IF;
8521     ELSE
8522       /*IF g_debug THEN
8523         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'copy record from ORGANIZATION_REC_TYPE '||
8524                                'to CREDIT_RATINGS_REC_TYPE for update(+)');
8525       END IF;
8526       */
8527       /*
8528       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
8529         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'copy record from ORGANIZATION_REC_TYPE '||
8530                                'to CREDIT_RATINGS_REC_TYPE for update(+)',
8531                                p_msg_level=>fnd_log.level_procedure);
8532       END IF;
8533 
8534       IF p_organization_rec.AVG_HIGH_CREDIT =  FND_API.G_MISS_NUM THEN
8535         x_credit_rating_rec.AVG_HIGH_CREDIT := NULL;
8536       ELSIF p_organization_rec.AVG_HIGH_CREDIT is not null THEN
8537         x_credit_rating_rec.AVG_HIGH_CREDIT := p_organization_rec.AVG_HIGH_CREDIT;
8538       END IF;
8539 
8540       IF p_organization_rec.CREDIT_SCORE = FND_API.G_MISS_CHAR THEN
8541         x_credit_rating_rec.CREDIT_SCORE := NULL;
8542       ELSIF p_organization_rec.CREDIT_SCORE is not null THEN
8543         x_credit_rating_rec.CREDIT_SCORE := p_organization_rec.CREDIT_SCORE;
8544       END IF;
8545 
8546       IF p_organization_rec.CREDIT_SCORE_AGE = FND_API.G_MISS_NUM THEN
8547         x_credit_rating_rec.CREDIT_SCORE_AGE := NULL;
8548       ELSIF p_organization_rec.CREDIT_SCORE_AGE is not null THEN
8549         x_credit_rating_rec.CREDIT_SCORE_AGE := p_organization_rec.CREDIT_SCORE_AGE;
8550       END IF;
8551 
8552       IF p_organization_rec.CREDIT_SCORE_CLASS = FND_API.G_MISS_NUM THEN
8553         x_credit_rating_rec.CREDIT_SCORE_CLASS := NULL;
8554       ELSIF p_organization_rec.CREDIT_SCORE_CLASS is not null THEN
8555         x_credit_rating_rec.CREDIT_SCORE_CLASS := p_organization_rec.CREDIT_SCORE_CLASS;
8556       END IF;
8557 
8558       IF p_organization_rec.CREDIT_SCORE_COMMENTARY = FND_API.G_MISS_CHAR THEN
8559         x_credit_rating_rec.CREDIT_SCORE_COMMENTARY := NULL;
8560       ELSIF p_organization_rec.CREDIT_SCORE_COMMENTARY is not null THEN
8561         x_credit_rating_rec.CREDIT_SCORE_COMMENTARY := p_organization_rec.CREDIT_SCORE_COMMENTARY;
8562       END IF;
8563 
8564       IF p_organization_rec.CREDIT_SCORE_COMMENTARY2 = FND_API.G_MISS_CHAR THEN
8565         x_credit_rating_rec.CREDIT_SCORE_COMMENTARY2 := NULL;
8566       ELSIF p_organization_rec.CREDIT_SCORE_COMMENTARY2 is not null THEN
8567         x_credit_rating_rec.CREDIT_SCORE_COMMENTARY2 := p_organization_rec.CREDIT_SCORE_COMMENTARY2;
8568       END IF;
8569 
8570       IF p_organization_rec.CREDIT_SCORE_COMMENTARY3 = FND_API.G_MISS_CHAR THEN
8571         x_credit_rating_rec.CREDIT_SCORE_COMMENTARY3 := NULL;
8572       ELSIF p_organization_rec.CREDIT_SCORE_COMMENTARY3 is not null THEN
8573         x_credit_rating_rec.CREDIT_SCORE_COMMENTARY3 := p_organization_rec.CREDIT_SCORE_COMMENTARY3;
8574       END IF;
8575 
8576       IF p_organization_rec.CREDIT_SCORE_COMMENTARY4 = FND_API.G_MISS_CHAR THEN
8577         x_credit_rating_rec.CREDIT_SCORE_COMMENTARY4 := NULL;
8578       ELSIF p_organization_rec.CREDIT_SCORE_COMMENTARY4 is not null THEN
8579         x_credit_rating_rec.CREDIT_SCORE_COMMENTARY4 := p_organization_rec.CREDIT_SCORE_COMMENTARY4;
8580       END IF;
8581 
8582       IF p_organization_rec.CREDIT_SCORE_COMMENTARY5 = FND_API.G_MISS_CHAR THEN
8583         x_credit_rating_rec.CREDIT_SCORE_COMMENTARY5 := NULL;
8584       ELSIF p_organization_rec.CREDIT_SCORE_COMMENTARY5 is not null THEN
8585         x_credit_rating_rec.CREDIT_SCORE_COMMENTARY5 := p_organization_rec.CREDIT_SCORE_COMMENTARY5;
8586       END IF;
8587 
8588       IF p_organization_rec.CREDIT_SCORE_COMMENTARY6 = FND_API.G_MISS_CHAR THEN
8589         x_credit_rating_rec.CREDIT_SCORE_COMMENTARY6 := NULL;
8590       ELSIF p_organization_rec.CREDIT_SCORE_COMMENTARY6 is not null THEN
8591         x_credit_rating_rec.CREDIT_SCORE_COMMENTARY6 := p_organization_rec.CREDIT_SCORE_COMMENTARY6;
8592       END IF;
8593 
8594       IF p_organization_rec.CREDIT_SCORE_COMMENTARY7 = FND_API.G_MISS_CHAR THEN
8595         x_credit_rating_rec.CREDIT_SCORE_COMMENTARY7 := NULL;
8596       ELSIF p_organization_rec.CREDIT_SCORE_COMMENTARY7 is not null THEN
8597         x_credit_rating_rec.CREDIT_SCORE_COMMENTARY7 := p_organization_rec.CREDIT_SCORE_COMMENTARY7;
8598       END IF;
8599 
8600       IF p_organization_rec.CREDIT_SCORE_COMMENTARY8 = FND_API.G_MISS_CHAR THEN
8601         x_credit_rating_rec.CREDIT_SCORE_COMMENTARY8 := NULL;
8602       ELSIF p_organization_rec.CREDIT_SCORE_COMMENTARY8 is not null THEN
8603         x_credit_rating_rec.CREDIT_SCORE_COMMENTARY8 := p_organization_rec.CREDIT_SCORE_COMMENTARY8;
8604       END IF;
8605 
8606       IF p_organization_rec.CREDIT_SCORE_COMMENTARY9 = FND_API.G_MISS_CHAR THEN
8607         x_credit_rating_rec.CREDIT_SCORE_COMMENTARY9 := NULL;
8608       ELSIF p_organization_rec.CREDIT_SCORE_COMMENTARY9 is not null THEN
8609         x_credit_rating_rec.CREDIT_SCORE_COMMENTARY9 := p_organization_rec.CREDIT_SCORE_COMMENTARY9;
8610       END IF;
8611 
8612       IF p_organization_rec.CREDIT_SCORE_COMMENTARY10 = FND_API.G_MISS_CHAR THEN
8613         x_credit_rating_rec.CREDIT_SCORE_COMMENTARY10 := NULL;
8614       ELSIF p_organization_rec.CREDIT_SCORE_COMMENTARY10 is not null THEN
8615         x_credit_rating_rec.CREDIT_SCORE_COMMENTARY10 := p_organization_rec.CREDIT_SCORE_COMMENTARY10;
8616       END IF;
8617 
8618       IF p_organization_rec.CREDIT_SCORE_DATE = FND_API.G_MISS_DATE THEN
8619         x_credit_rating_rec.CREDIT_SCORE_DATE := NULL;
8620       ELSIF p_organization_rec.CREDIT_SCORE_DATE is not null THEN
8621         x_credit_rating_rec.CREDIT_SCORE_DATE := p_organization_rec.CREDIT_SCORE_DATE;
8622       END IF;
8623 
8624       IF p_organization_rec.CREDIT_SCORE_INCD_DEFAULT = FND_API.G_MISS_NUM THEN
8625         x_credit_rating_rec.CREDIT_SCORE_INCD_DEFAULT := NULL;
8626       ELSIF p_organization_rec.CREDIT_SCORE_INCD_DEFAULT is not null THEN
8627         x_credit_rating_rec.CREDIT_SCORE_INCD_DEFAULT := p_organization_rec.CREDIT_SCORE_INCD_DEFAULT;
8628       END IF;
8629 
8630       IF p_organization_rec.CREDIT_SCORE_NATL_PERCENTILE = FND_API.G_MISS_NUM THEN
8631         x_credit_rating_rec.CREDIT_SCORE_NATL_PERCENTILE := NULL;
8632       ELSIF p_organization_rec.CREDIT_SCORE_NATL_PERCENTILE is not null THEN
8633         x_credit_rating_rec.CREDIT_SCORE_NATL_PERCENTILE := p_organization_rec.CREDIT_SCORE_NATL_PERCENTILE;
8634       END IF;
8635 
8636       IF p_organization_rec.DB_RATING = FND_API.G_MISS_CHAR THEN
8637         x_credit_rating_rec.RATING := NULL;
8638       ELSIF p_organization_rec.DB_RATING is not null THEN
8639         x_credit_rating_rec.RATING := p_organization_rec.DB_RATING;
8640       END IF;
8641 
8642       IF p_organization_rec.DEBARMENT_IND = FND_API.G_MISS_CHAR THEN
8643         x_credit_rating_rec.DEBARMENT_IND := NULL;
8644       ELSIF p_organization_rec.DEBARMENT_IND is not null THEN
8645         x_credit_rating_rec.DEBARMENT_IND := p_organization_rec.DEBARMENT_IND;
8646       END IF;
8647 
8648       IF p_organization_rec.DEBARMENTS_COUNT = FND_API.G_MISS_NUM THEN
8649         x_credit_rating_rec.DEBARMENTS_COUNT := NULL;
8650       ELSIF p_organization_rec.DEBARMENTS_COUNT is not null THEN
8651         x_credit_rating_rec.DEBARMENTS_COUNT := p_organization_rec.DEBARMENTS_COUNT;
8652       END IF;
8653 
8654       IF p_organization_rec.DEBARMENTS_DATE = FND_API.G_MISS_DATE THEN
8655         x_credit_rating_rec.DEBARMENTS_DATE := NULL;
8656       ELSIF p_organization_rec.DEBARMENTS_DATE is not null THEN
8657         x_credit_rating_rec.DEBARMENTS_DATE := p_organization_rec.DEBARMENTS_DATE;
8658       END IF;
8659 
8660       IF p_organization_rec.HIGH_CREDIT = FND_API.G_MISS_NUM THEN
8661         x_credit_rating_rec.HIGH_CREDIT := NULL;
8662       ELSIF p_organization_rec.HIGH_CREDIT is not null THEN
8663         x_credit_rating_rec.HIGH_CREDIT := p_organization_rec.HIGH_CREDIT;
8664       END IF;
8665 
8666       IF p_organization_rec.MAXIMUM_CREDIT_CURRENCY_CODE = FND_API.G_MISS_CHAR THEN
8667         x_credit_rating_rec.MAXIMUM_CREDIT_CURRENCY_CODE := NULL;
8668       ELSIF p_organization_rec.MAXIMUM_CREDIT_CURRENCY_CODE is not null THEN
8669         x_credit_rating_rec.MAXIMUM_CREDIT_CURRENCY_CODE := p_organization_rec.MAXIMUM_CREDIT_CURRENCY_CODE;
8670       END IF;
8671 
8672       IF p_organization_rec.MAXIMUM_CREDIT_RECOMMENDATION = FND_API.G_MISS_NUM THEN
8673         x_credit_rating_rec.MAXIMUM_CREDIT_RCMD := NULL;
8674       ELSIF p_organization_rec.MAXIMUM_CREDIT_RECOMMENDATION is not null THEN
8675         x_credit_rating_rec.MAXIMUM_CREDIT_RCMD := p_organization_rec.MAXIMUM_CREDIT_RECOMMENDATION;
8676       END IF;
8677 
8678       IF p_organization_rec.PAYDEX_NORM = FND_API.G_MISS_CHAR THEN
8679         x_credit_rating_rec.PAYDEX_NORM := NULL;
8680       ELSIF p_organization_rec.PAYDEX_NORM is not null THEN
8681         x_credit_rating_rec.PAYDEX_NORM := p_organization_rec.PAYDEX_NORM;
8682       END IF;
8683 
8684       IF p_organization_rec.PAYDEX_SCORE = FND_API.G_MISS_CHAR THEN
8685         x_credit_rating_rec.PAYDEX_SCORE := NULL;
8686       ELSIF p_organization_rec.PAYDEX_SCORE is not null THEN
8687         x_credit_rating_rec.PAYDEX_SCORE := p_organization_rec.PAYDEX_SCORE;
8688       END IF;
8689 
8690       IF p_organization_rec.PAYDEX_THREE_MONTHS_AGO = FND_API.G_MISS_CHAR THEN
8691         x_credit_rating_rec.PAYDEX_THREE_MONTHS_AGO := NULL;
8692       ELSIF p_organization_rec.PAYDEX_THREE_MONTHS_AGO is not null THEN
8693         x_credit_rating_rec.PAYDEX_THREE_MONTHS_AGO := p_organization_rec.PAYDEX_THREE_MONTHS_AGO;
8694       END IF;
8695 
8696       IF p_organization_rec.FAILURE_SCORE = FND_API.G_MISS_CHAR THEN
8697         x_credit_rating_rec.FAILURE_SCORE := NULL;
8698       ELSIF p_organization_rec.FAILURE_SCORE is not null THEN
8699         x_credit_rating_rec.FAILURE_SCORE := p_organization_rec.FAILURE_SCORE;
8700       END IF;
8701 
8702       IF p_organization_rec.FAILURE_SCORE_AGE = FND_API.G_MISS_NUM THEN
8703         x_credit_rating_rec.FAILURE_SCORE_AGE := NULL;
8704       ELSIF p_organization_rec.FAILURE_SCORE_AGE is not null THEN
8705         x_credit_rating_rec.FAILURE_SCORE_AGE := p_organization_rec.FAILURE_SCORE_AGE;
8706       END IF;
8707 
8708       IF p_organization_rec.FAILURE_SCORE_CLASS = FND_API.G_MISS_NUM THEN
8709         x_credit_rating_rec.FAILURE_SCORE_CLASS := NULL;
8710       ELSIF p_organization_rec.FAILURE_SCORE_CLASS is not null THEN
8711         x_credit_rating_rec.FAILURE_SCORE_CLASS := p_organization_rec.FAILURE_SCORE_CLASS;
8712       END IF;
8713 
8714       IF p_organization_rec.FAILURE_SCORE_COMMENTARY = FND_API.G_MISS_CHAR THEN
8715         x_credit_rating_rec.FAILURE_SCORE_COMMENTARY := NULL;
8716       ELSIF p_organization_rec.FAILURE_SCORE_COMMENTARY is not null THEN
8717         x_credit_rating_rec.FAILURE_SCORE_COMMENTARY := p_organization_rec.FAILURE_SCORE_COMMENTARY;
8718       END IF;
8719 
8720       IF p_organization_rec.FAILURE_SCORE_COMMENTARY2 = FND_API.G_MISS_CHAR THEN
8721         x_credit_rating_rec.FAILURE_SCORE_COMMENTARY2 := NULL;
8722       ELSIF p_organization_rec.FAILURE_SCORE_COMMENTARY2 is not null THEN
8723         x_credit_rating_rec.FAILURE_SCORE_COMMENTARY2 := p_organization_rec.FAILURE_SCORE_COMMENTARY2;
8724       END IF;
8725 
8726       IF p_organization_rec.FAILURE_SCORE_COMMENTARY3 = FND_API.G_MISS_CHAR THEN
8727         x_credit_rating_rec.FAILURE_SCORE_COMMENTARY3 := NULL;
8728       ELSIF p_organization_rec.FAILURE_SCORE_COMMENTARY3 is not null THEN
8729         x_credit_rating_rec.FAILURE_SCORE_COMMENTARY3 := p_organization_rec.FAILURE_SCORE_COMMENTARY3;
8730       END IF;
8731 
8732       IF p_organization_rec.FAILURE_SCORE_COMMENTARY4 = FND_API.G_MISS_CHAR THEN
8733         x_credit_rating_rec.FAILURE_SCORE_COMMENTARY4 := NULL;
8734       ELSIF p_organization_rec.FAILURE_SCORE_COMMENTARY4 is not null THEN
8735         x_credit_rating_rec.FAILURE_SCORE_COMMENTARY4 := p_organization_rec.FAILURE_SCORE_COMMENTARY4;
8736       END IF;
8737 
8738       IF p_organization_rec.FAILURE_SCORE_COMMENTARY5 = FND_API.G_MISS_CHAR THEN
8739         x_credit_rating_rec.FAILURE_SCORE_COMMENTARY5 := NULL;
8740       ELSIF p_organization_rec.FAILURE_SCORE_COMMENTARY5 is not null THEN
8741         x_credit_rating_rec.FAILURE_SCORE_COMMENTARY5 := p_organization_rec.FAILURE_SCORE_COMMENTARY5;
8742       END IF;
8743 
8744       IF p_organization_rec.FAILURE_SCORE_COMMENTARY6 = FND_API.G_MISS_CHAR THEN
8745         x_credit_rating_rec.FAILURE_SCORE_COMMENTARY6 := NULL;
8746       ELSIF p_organization_rec.FAILURE_SCORE_COMMENTARY6 is not null THEN
8747         x_credit_rating_rec.FAILURE_SCORE_COMMENTARY6 := p_organization_rec.FAILURE_SCORE_COMMENTARY6;
8748       END IF;
8749 
8750       IF p_organization_rec.FAILURE_SCORE_COMMENTARY7 = FND_API.G_MISS_CHAR THEN
8751         x_credit_rating_rec.FAILURE_SCORE_COMMENTARY7 := NULL;
8752       ELSIF p_organization_rec.FAILURE_SCORE_COMMENTARY7 is not null THEN
8753         x_credit_rating_rec.FAILURE_SCORE_COMMENTARY7 := p_organization_rec.FAILURE_SCORE_COMMENTARY7;
8754       END IF;
8755 
8756       IF p_organization_rec.FAILURE_SCORE_COMMENTARY8 = FND_API.G_MISS_CHAR THEN
8757         x_credit_rating_rec.FAILURE_SCORE_COMMENTARY8 := NULL;
8758       ELSIF p_organization_rec.FAILURE_SCORE_COMMENTARY8 is not null THEN
8759         x_credit_rating_rec.FAILURE_SCORE_COMMENTARY8 := p_organization_rec.FAILURE_SCORE_COMMENTARY8;
8760       END IF;
8761 
8762       IF p_organization_rec.FAILURE_SCORE_COMMENTARY9 = FND_API.G_MISS_CHAR THEN
8763         x_credit_rating_rec.FAILURE_SCORE_COMMENTARY9 := NULL;
8764       ELSIF p_organization_rec.FAILURE_SCORE_COMMENTARY9 is not null THEN
8765         x_credit_rating_rec.FAILURE_SCORE_COMMENTARY9 := p_organization_rec.FAILURE_SCORE_COMMENTARY9;
8766       END IF;
8767 
8768       IF p_organization_rec.FAILURE_SCORE_COMMENTARY10 = FND_API.G_MISS_CHAR THEN
8769         x_credit_rating_rec.FAILURE_SCORE_COMMENTARY10 := NULL;
8770       ELSIF p_organization_rec.FAILURE_SCORE_COMMENTARY10 is not null THEN
8771         x_credit_rating_rec.FAILURE_SCORE_COMMENTARY10 := p_organization_rec.FAILURE_SCORE_COMMENTARY10;
8772       END IF;
8773 
8774       IF p_organization_rec.FAILURE_SCORE_DATE = FND_API.G_MISS_DATE THEN
8775         x_credit_rating_rec.FAILURE_SCORE_DATE := NULL;
8776       ELSIF p_organization_rec.FAILURE_SCORE_DATE is not null THEN
8777         x_credit_rating_rec.FAILURE_SCORE_DATE := p_organization_rec.FAILURE_SCORE_DATE;
8778       END IF;
8779 
8780       IF p_organization_rec.FAILURE_SCORE_INCD_DEFAULT = FND_API.G_MISS_NUM THEN
8781         x_credit_rating_rec.FAILURE_SCORE_INCD_DEFAULT := NULL;
8782       ELSIF p_organization_rec.FAILURE_SCORE_INCD_DEFAULT is not null THEN
8783         x_credit_rating_rec.FAILURE_SCORE_INCD_DEFAULT := p_organization_rec.FAILURE_SCORE_INCD_DEFAULT;
8784       END IF;
8785 
8786       IF p_organization_rec.FAILURE_SCORE_NATNL_PERCENTILE = FND_API.G_MISS_NUM THEN
8787         x_credit_rating_rec.FAILURE_SCORE_NATNL_PERCENTILE := NULL;
8788       ELSIF p_organization_rec.FAILURE_SCORE_NATNL_PERCENTILE is not null THEN
8789         x_credit_rating_rec.FAILURE_SCORE_NATNL_PERCENTILE := p_organization_rec.FAILURE_SCORE_NATNL_PERCENTILE;
8790       END IF;
8791 
8792       IF p_organization_rec.FAILURE_SCORE_OVERRIDE_CODE = FND_API.G_MISS_CHAR THEN
8793         x_credit_rating_rec.FAILURE_SCORE_OVERRIDE_CODE := NULL;
8794       ELSIF p_organization_rec.FAILURE_SCORE_OVERRIDE_CODE is not null THEN
8795         x_credit_rating_rec.FAILURE_SCORE_OVERRIDE_CODE := p_organization_rec.FAILURE_SCORE_OVERRIDE_CODE;
8796       END IF;
8797 
8798       IF p_organization_rec.GLOBAL_FAILURE_SCORE = FND_API.G_MISS_CHAR THEN
8799         x_credit_rating_rec.GLOBAL_FAILURE_SCORE := NULL;
8800       ELSIF p_organization_rec.GLOBAL_FAILURE_SCORE is not null THEN
8801         x_credit_rating_rec.GLOBAL_FAILURE_SCORE := p_organization_rec.GLOBAL_FAILURE_SCORE;
8802       END IF;
8803 
8804       x_credit_rating_rec.rated_as_of_date := sysdate;
8805 
8806       /*IF g_debug THEN
8807         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,'copy record from ORGANIZATION_REC_TYPE '||
8808                                'to CREDIT_RATINGS_REC_TYPE for update(-)');
8809       END IF;
8810       */
8811       /*
8812       IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
8813         hz_utility_v2pub.debug(p_prefix=>l_debug_prefix,p_message=>'copy record from ORGANIZATION_REC_TYPE '||
8814                                'to CREDIT_RATINGS_REC_TYPE for update(-)',
8815                                p_msg_level=>fnd_log.level_procedure);
8816       END IF;
8817     END IF;
8818 
8819   END org_rec_to_cr_rec;
8820 */
8821 
8822 
8823 
8824    /*----------------------------------------------------------------------------*
8825  | procedure                                                                   |
8826  |    update_party_search                                                   |
8827  |                                                                            |
8828  | DESCRIPTION                                                                |
8829  |    This procedure updates the address_text column of                       |
8830  |    hz_cust_acct_sites_all with the NULL value                              |
8831  |    only to change the address_text column status                           |
8832  |    so that interMedia index can be created on it to perform text searches. |
8833  |                                                                            |
8834  | NOTE :- After Calling this procedure the user has to execute the            |
8835  |         Customer Text Data Creation concurrent program to see the changes. |
8836  |                                                                            |
8837  | PARAMETERS                                                                 |
8838  |   INPUT                                                                    |
8839  |    p_party_id                                                              |
8840  |    p_old_party_name                                                        |
8841  |    p_new_party_name                                                        |
8842  |    p_old_tax_reference                                                     |
8843  |    p_new_tax_reference                                                     |
8844  |                                                                            |
8845  |   OUTPUT                                                                   |
8846  |                                                                            |
8847  |                                                                            |
8848  | HISTORY                                                                    |
8849  |    15-Mar-2004    Ramesh Ch   Created                                      |
8850  *----------------------------------------------------------------------------*/
8851 
8852 PROCEDURE update_party_search(p_party_id          IN  NUMBER,
8853                               p_old_party_name    IN  VARCHAR2,
8854                               p_new_party_name    IN  VARCHAR2,
8855                               p_old_tax_reference IN  VARCHAR2,
8856                               p_new_tax_reference IN  VARCHAR2)
8857 IS
8858 CURSOR c_cust_acct_sites(p_party_id NUMBER) IS
8859     SELECT ac.CUST_ACCT_SITE_ID
8860     FROM HZ_PARTIES p, HZ_CUST_ACCOUNTS c,
8861          HZ_CUST_ACCT_SITES_ALL ac
8862     WHERE p.party_id=p_party_id
8863     AND p.party_id = c.party_id
8864     AND c.cust_account_id = ac.cust_account_id;
8865 TYPE siteidtab IS TABLE OF HZ_CUST_ACCT_SITES_ALL.CUST_ACCT_SITE_ID%TYPE;
8866 l_siteidtab siteidtab;
8867 
8868 BEGIN
8869  SAVEPOINT update_party_search;
8870 
8871  IF(    isModified(p_old_party_name,p_new_party_name)
8872     OR  isModified(p_old_tax_reference,p_new_tax_reference)
8873  ) THEN
8874     OPEN c_cust_acct_sites(p_party_id);
8875     FETCH c_cust_acct_sites BULK COLLECT INTO l_siteidtab;
8876     CLOSE c_cust_acct_sites;
8877     IF l_siteidtab.COUNT >0 THEN
8878      FORALL i IN l_siteidtab.FIRST..l_siteidtab.LAST
8879       update HZ_CUST_ACCT_SITES_ALL set address_text=NULL where cust_acct_site_id=l_siteidtab(i);
8880     END IF;
8881  END IF;
8882 EXCEPTION
8883  WHEN OTHERS THEN
8884    ROLLBACK TO update_party_search;
8885    RAISE;
8886 END;
8887 
8888 FUNCTION isModified(p_old_value IN VARCHAR2,p_new_value IN VARCHAR2) RETURN BOOLEAN
8889 IS
8890 BEGIN
8891   IF p_new_value IS NOT NULL AND p_new_value <> FND_API.G_MISS_CHAR THEN
8892      RETURN NVL(NOT (p_old_value=p_new_value),TRUE);
8893   ELSIF (p_old_value IS NOT NULL AND p_old_value <> FND_API.G_MISS_CHAR)
8894          AND p_new_value = FND_API.G_MISS_CHAR THEN
8895      RETURN TRUE;
8896   ELSE
8897     RETURN FALSE;
8898   END IF;
8899 END;
8900 
8901 /*----------------------------------------------------------------------------*
8902  | procedure                                                                   |
8903  |    update_rel_person_search                                                |
8904  |                                                                            |
8905  | DESCRIPTION                                                                |
8906  |    This procedure updates the address_text column of                       |
8907  |    hz_cust_acct_sites_all with the NULL value                              |
8908  |    only to change the address_text column status                           |
8909  |    so that interMedia index can be created on it to perform text searches. |
8910  |                                                                            |
8911  | NOTE :- After Calling this procedure the user has to execute the            |
8912  |         Customer Text Data Creation concurrent program to see the changes. |
8913  |                                                                            |
8914  | PARAMETERS                                                                 |
8915  |   INPUT                                                                    |
8916  |    p_old_person_rec                                                        |
8917  |    p_new_person_rec                                                        |
8918  |                                                                            |
8919  |   OUTPUT                                                                   |
8920  |                                                                            |
8921  |                                                                            |
8922  | HISTORY                                                                    |
8923  |    15-Mar-2004    Ramesh Ch   Created                                      |
8924  *----------------------------------------------------------------------------*/
8925 
8926 PROCEDURE update_rel_person_search(p_old_person_rec IN  HZ_PARTY_V2PUB.PERSON_REC_TYPE,
8927                                    p_new_person_rec IN  HZ_PARTY_V2PUB.PERSON_REC_TYPE)
8928 IS
8929    ---(Party level relationship )
8930     CURSOR c_party_cust_acct_sites(p_party_id NUMBER) IS
8931       SELECT distinct ac.CUST_ACCT_SITE_ID
8932       FROM HZ_PARTIES p, HZ_CUST_ACCOUNT_ROLES ar,
8933          HZ_RELATIONSHIPS rel,HZ_CUST_ACCT_SITES_ALL ac
8934       WHERE rel.subject_id=p_party_id
8935       AND ar.ROLE_TYPE = 'CONTACT'
8936       AND rel.party_id=ar.party_id
8937       AND rel.subject_id=p.party_id
8938       AND ar.cust_account_id = ac.cust_account_id
8939       AND (ar.cust_acct_site_id is null);
8940 
8941    ----(Site Level relationship)
8942     CURSOR c_site_cust_acct_sites(p_party_id NUMBER) IS
8943       SELECT distinct ac.CUST_ACCT_SITE_ID
8944       FROM HZ_PARTIES p, HZ_CUST_ACCOUNT_ROLES ar,
8945           HZ_RELATIONSHIPS rel,HZ_CUST_ACCT_SITES_ALL ac
8946       WHERE rel.subject_id=p_party_id
8947       AND ar.ROLE_TYPE = 'CONTACT'
8948       AND ar.party_id = rel.party_id
8949       AND p.party_id = rel.subject_id
8950       AND ar.cust_account_id = ac.cust_account_id
8951       AND ar.cust_acct_site_id = ac.cust_acct_site_id;
8952 
8953     TYPE siteidtab IS TABLE OF HZ_CUST_ACCT_SITES_ALL.CUST_ACCT_SITE_ID%TYPE;
8954     l_siteidtab siteidtab;
8955 
8956 BEGIN
8957  SAVEPOINT update_rel_person_search;
8958  IF(    isModified(p_old_person_rec.person_first_name,p_new_person_rec.person_first_name)
8959     OR  isModified(p_old_person_rec.person_last_name,p_new_person_rec.person_last_name)
8960  ) THEN
8961     ---Process party level relationship's records.
8962     OPEN c_party_cust_acct_sites(p_old_person_rec.party_rec.party_id);
8963     FETCH c_party_cust_acct_sites BULK COLLECT INTO l_siteidtab;
8964     CLOSE c_party_cust_acct_sites;
8965     IF l_siteidtab.COUNT >0 THEN
8966      FORALL i IN l_siteidtab.FIRST..l_siteidtab.LAST
8967        update HZ_CUST_ACCT_SITES_ALL set address_text=NULL where cust_acct_site_id=l_siteidtab(i);
8968     END IF;
8969     ---Process site level relationship's records.
8970     OPEN c_site_cust_acct_sites(p_old_person_rec.party_rec.party_id);
8971     FETCH c_site_cust_acct_sites BULK COLLECT INTO l_siteidtab;
8972     CLOSE c_site_cust_acct_sites;
8973     IF l_siteidtab.COUNT >0 THEN
8974      FORALL i IN l_siteidtab.FIRST..l_siteidtab.LAST
8975        update HZ_CUST_ACCT_SITES_ALL set address_text=NULL where cust_acct_site_id=l_siteidtab(i);
8976     END IF;
8977  END IF;
8978 EXCEPTION
8979  WHEN OTHERS THEN
8980    ROLLBACK TO update_rel_person_search;
8981    RAISE;
8982 END;
8983 
8984 ----------------------------Bug 4586451
8985 /**
8986  * PRIVATE PROCEDURE validate_party_name
8987  *
8988  * DESCRIPTION
8989  *     Validate party name.
8990  *
8991  * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
8992  *
8993  * ARGUMENTS
8994  *     IN:
8995  *     OUT:
8996  *     IN/ OUT:
8997  *
8998  * NOTES
8999  *
9000  * MODIFICATION HISTORY
9001  */
9002 
9003 PROCEDURE validate_party_name (
9004     p_party_id                    IN     NUMBER,
9005     p_party_name                  IN     VARCHAR2,
9006     x_return_status               IN OUT NOCOPY VARCHAR2
9007 ) IS
9008 
9009     c_supplier_code               CONSTANT VARCHAR2(30) := 'SUPPLIER';
9010 
9011     CURSOR c_supplier (
9012       p_party_id                  NUMBER
9013     ) IS
9014     SELECT null
9015     FROM   hz_party_usg_assignments pu
9016     WHERE  pu.party_id = p_party_id
9017     AND    pu.party_usage_code = c_supplier_code
9018     AND    ROWNUM = 1;
9019 
9020     l_dummy                       VARCHAR2(1);
9021 
9022 BEGIN
9023 
9024     IF fnd_log.level_procedure >= fnd_log.g_current_runtime_level THEN
9025       hz_utility_v2pub.debug (
9026         p_message                 => 'validate_party_name (+)',
9027         p_prefix                  => '',
9028         p_msg_level               => fnd_log.level_procedure
9029       );
9030     END IF;
9031 
9032     -- check if the party is supplier
9033 
9034 
9035     OPEN c_supplier(p_party_id);
9036     FETCH c_supplier INTO l_dummy;
9037     IF c_supplier%FOUND THEN
9038 
9039 
9040 
9041       -- check uniqueness across supplier parties
9042       hz_party_usg_assignment_pvt.validate_supplier_name (
9043         p_party_id                => p_party_id,
9044         p_party_name              => p_party_name,
9045         x_return_status           => x_return_status);
9046     END IF;
9047     CLOSE c_supplier;
9048 
9049     IF fnd_log.level_procedure >= fnd_log.g_current_runtime_level THEN
9050       hz_utility_v2pub.debug (
9051         p_message                 => 'validate_party_name (-)',
9052         p_prefix                  => '',
9053         p_msg_level               => fnd_log.level_procedure
9054       );
9055     END IF;
9056 
9057 END validate_party_name;
9058 -------------------------------Bug No. 4586451
9059 
9060 END HZ_PARTY_V2PUB;