DBA Data[Home] [Help]

PACKAGE BODY: APPS.HZ_PARTY_V2PUB

Source


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