DBA Data[Home] [Help]

PACKAGE BODY: APPS.HZ_CONTACT_PREFERENCE_V2PUB

Source


1 PACKAGE BODY HZ_CONTACT_PREFERENCE_V2PUB AS
2 /* $Header: ARH2CTSB.pls 120.5 2005/12/07 19:30:29 acng ship $ */
3 
4 --------------------------------------
5 -- package global variable declaration
6 --------------------------------------
7 
8 G_DEBUG_COUNT             NUMBER := 0;
9 --G_DEBUG                   BOOLEAN := FALSE;
10 
11 ------------------------------------
12 -- declaration of private procedures
13 ------------------------------------
14 
15 /*PROCEDURE enable_debug;
16 
17 PROCEDURE disable_debug;
18 */
19 
20 PROCEDURE do_create_contact_preference(
21     p_contact_preference_rec            IN OUT NOCOPY  CONTACT_PREFERENCE_REC_TYPE,
22     x_contact_preference_id             OUT NOCOPY     NUMBER,
23     x_return_status                     IN OUT NOCOPY  VARCHAR2
24 );
25 
26 PROCEDURE do_update_contact_preference(
27     p_contact_preference_rec            IN OUT NOCOPY  CONTACT_PREFERENCE_REC_TYPE,
28     p_object_version_number             IN OUT NOCOPY  NUMBER,
29     x_return_status                     IN OUT NOCOPY  VARCHAR2
30 );
31 
32 --------------------------------------
33 -- private procedures and functions
34 --------------------------------------
35 
36 /**
37  * PRIVATE PROCEDURE enable_debug
38  *
39  * DESCRIPTION
40  *     Turn on debug mode.
41  *
42  * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
43  *     HZ_UTILITY_V2PUB.enable_debug
44  *
45  * MODIFICATION HISTORY
46  *
47  *   07-23-2001    Kate Shan             o Created.
48  *
49  */
50 
51 /*PROCEDURE enable_debug IS
52 
53 BEGIN
54 
55     G_DEBUG_COUNT := G_DEBUG_COUNT + 1;
56 
57     IF G_DEBUG_COUNT = 1 THEN
58         IF FND_PROFILE.value( 'HZ_API_FILE_DEBUG_ON' ) = 'Y' OR
59            FND_PROFILE.value( 'HZ_API_DBMS_DEBUG_ON' ) = 'Y'
60         THEN
61            HZ_UTILITY_V2PUB.enable_debug;
62            G_DEBUG := TRUE;
63         END IF;
64     END IF;
65 
66 END enable_debug;
67 */
68 
69 /**
70  * PRIVATE PROCEDURE disable_debug
71  *
72  * DESCRIPTION
73  *     Turn off debug mode.
74  *
75  * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
76  *     HZ_UTILITY_V2PUB.disable_debug
77  *
78  * MODIFICATION HISTORY
79  *
80  *   07-23-2001    Kate Shan                    o Created.
81  *
82  */
83 
84 /*PROCEDURE disable_debug IS
85 
86 BEGIN
87 
88     IF G_DEBUG THEN
89         G_DEBUG_COUNT := G_DEBUG_COUNT - 1;
90 
91         IF G_DEBUG_COUNT = 0 THEN
92             HZ_UTILITY_V2PUB.disable_debug;
93             G_DEBUG := FALSE;
94         END IF;
95     END IF;
96 
97 END disable_debug;
98 */
99 
100 /**
101 *  PROCEDURE
102 *              do_create_contact_preference
103 *
104 *  DESCRIPTION
105 *               Creates contact preference
106 *
107 *  SCOPE - PRIVATE
108 *
109 *  EXETERNAL PROCEDURES/FUNCTIONS ACCESSED
110 *
111 *  ARGUMENTS  : IN:
112 *               OUT:
113 *                     x_contact_preference_id        Contact Preference ID
114 *           IN/ OUT:
115 *                     p_contact_preference_rec       Contact Preference Record
116 *                     x_return_status                Return status after the call. The status can
117 *                                                    be FND_API.G_RET_STS_SUCCESS (success),
118 *                                                    FND_API.G_RET_STS_ERROR (error),
119 *                                                    FND_API.G_RET_STS_UNEXP_ERROR (unexpected error).
120 *
121 * RETURNS    : NONE
122 *
123 *  NOTES
124 *
125 *  MODIFICATION HISTORY
126 *    07-23-2001    Kate Shan           o Created.
127 *
128 */
129 
130 PROCEDURE do_create_contact_preference(
131     p_contact_preference_rec            IN OUT NOCOPY  CONTACT_PREFERENCE_REC_TYPE,
132     x_contact_preference_id             OUT NOCOPY     NUMBER,
133     x_return_status                     IN OUT NOCOPY  VARCHAR2
134 ) IS
135     l_debug_prefix                      VARCHAR2(30) := ''; --'do_create_contact_preference';
136 
137     l_dummy                             VARCHAR2(1);
138     l_rowid                             ROWID;
139 
140 BEGIN
141     -- Debug info.
142     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
143 	hz_utility_v2pub.debug(p_message=>'do_create_contact_preference (+)',
144 	                       p_prefix=>l_debug_prefix,
145 			       p_msg_level=>fnd_log.level_procedure);
146     END IF;
147 
148     ----------------------------------------------
149     -- if preference_start_date is null, give sysdate
150     ----------------------------------------------
151     IF p_contact_preference_rec.preference_start_date is null or
152        p_contact_preference_rec.preference_start_date = FND_API.G_MISS_DATE THEN
153            p_contact_preference_rec.preference_start_date := sysdate;
154     END IF;
155 
156 
157     -- Validate contact preference  record
158     HZ_CONTACT_PREFERENCE_VALIDATE.validate_contact_preference(
159         'C',
160         p_contact_preference_rec,
161         l_rowid,
162         x_return_status);
163 
164     IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
165         RAISE FND_API.G_EXC_ERROR;
166     END IF;
167 
168     -- Debug info.
169     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
170 	hz_utility_v2pub.debug(p_message=>'HZ_CONTACT_PREFERENCES_PKG.Insert_Row (+) ',
171 	                       p_prefix=>l_debug_prefix,
172 			       p_msg_level=>fnd_log.level_procedure);
173     END IF;
174 
175     -- call table handler to insert a row
176     HZ_CONTACT_PREFERENCES_PKG.Insert_Row (
177         X_Rowid                                 => l_rowid,
178         X_CONTACT_PREFERENCE_ID                 => p_contact_preference_rec.contact_preference_id,
179         X_CONTACT_LEVEL_TABLE                   => p_contact_preference_rec.contact_level_table,
180         X_CONTACT_LEVEL_TABLE_ID                => p_contact_preference_rec.contact_level_table_id,
181         X_CONTACT_TYPE                          => p_contact_preference_rec.contact_type,
182         X_PREFERENCE_CODE                       => p_contact_preference_rec.preference_code,
183         X_PREFERENCE_TOPIC_TYPE                => p_contact_preference_rec.preference_topic_type,
184         X_PREFERENCE_TOPIC_TYPE_ID             => p_contact_preference_rec.preference_topic_type_id,
185         X_PREFERENCE_TOPIC_TYPE_CODE           => p_contact_preference_rec.preference_topic_type_code,
186         X_PREFERENCE_START_DATE                 => p_contact_preference_rec.preference_start_date,
187         X_PREFERENCE_END_DATE                   => p_contact_preference_rec.preference_end_date,
188         X_PREFERENCE_START_TIME_HR              => p_contact_preference_rec.preference_start_time_hr,
189         X_PREFERENCE_END_TIME_HR                => p_contact_preference_rec.preference_end_time_hr,
190         X_PREFERENCE_START_TIME_MI              => p_contact_preference_rec.preference_start_time_mi,
191         X_PREFERENCE_END_TIME_MI                => p_contact_preference_rec.preference_end_time_mi,
192         X_MAX_NO_OF_INTERACTIONS                => p_contact_preference_rec.max_no_of_interactions,
193         X_MAX_NO_OF_INTERACT_UOM_CODE           => p_contact_preference_rec.max_no_of_interact_uom_code,
194         X_REQUESTED_BY                          => p_contact_preference_rec.requested_by,
195         X_REASON_CODE                           => p_contact_preference_rec.reason_code,
196         X_STATUS                                => p_contact_preference_rec.status,
197         X_OBJECT_VERSION_NUMBER                 => 1,
198         X_CREATED_BY_MODULE                     => p_contact_preference_rec.created_by_module,
199         X_APPLICATION_ID                        => p_contact_preference_rec.application_id
200     );
201 
202     -- Debug info.
203     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
204 	hz_utility_v2pub.debug(p_message=>'HZ_CONTACT_PREFERENCES_PKG.Insert_Row (-) ' ||
205 				 'x_contact_preference_id = ' || p_contact_preference_rec.contact_preference_id,
206 	                       p_prefix=>l_debug_prefix,
207 			       p_msg_level=>fnd_log.level_procedure);
208     END IF;
209 
210     -- assign the primary key back
211     x_contact_preference_id := p_contact_preference_rec.contact_preference_id;
212 
213     -- Debug info.
214     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
215 	hz_utility_v2pub.debug(p_message=>'do_create_contact_preference (-)',
216 	                       p_prefix=>l_debug_prefix,
217 			       p_msg_level=>fnd_log.level_procedure);
218     END IF;
219 
220 END do_create_contact_preference;
221 
222 
223 /**
224 *  PROCEDURE
225 *               do_update_contact_preference_
226 *
227 *  DESCRIPTION
228 *               Private procedure to update contact preference
229 *  EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
230 *      HZ_REGRISTRY_VALIDATE_V2PUB.validate_contact_preference
231 *      HZ_CONTACT_PREFERENCES_PKG.Update_Row
232 *
233 * SCOPE - PRIVATE
234 *
235 *  EXETERNAL PROCEDURES/FUNCTIONS ACCESSED
236 *
237 *  ARGUMENTS  : IN:
238 *               OUT:
239 *           IN/ OUT:
240 *                     p_contact_preference_rec   Contact preference record
241 *                     p_object_version_number    Used for locking the being updated record.
242 *                      x_return_status            Return status after the call. The status can
243 *                                                be FND_API.G_RET_STS_SUCCESS (success),
244 *                                                FND_API.G_RET_STS_ERROR (error),
245 *                                                FND_API.G_RET_STS_UNEXP_ERROR (unexpected error).
246 *
247 *  RETURNS    : NONE
248 *
249 *  NOTES
250 *
251 *  MODIFICATION HISTORY
252 *    07-23-2001    Kate Shan              o Created.
253 *
254 *
255 */
256 
257 PROCEDURE do_update_contact_preference(
258     p_contact_preference_rec            IN OUT NOCOPY  CONTACT_PREFERENCE_REC_TYPE,
259     p_object_version_number             IN OUT NOCOPY  NUMBER,
260     x_return_status                     IN OUT NOCOPY  VARCHAR2
261 ) IS
262     l_debug_prefix                              VARCHAR2(30) := ''; --'do_update_contact_preference';
263 
264     l_rowid                                     ROWID  := NULL;
265     l_object_version_number                     NUMBER;
266     l_party_id                                  NUMBER;
267     l_native_language                           VARCHAR2(1);
268     l_language_name                             VARCHAR2(4);
269 
270 BEGIN
271 
272     -- Debug info.
273     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
274 	hz_utility_v2pub.debug(p_message=>'do_update_contact_preference (+)',
275 	                       p_prefix=>l_debug_prefix,
276 			       p_msg_level=>fnd_log.level_procedure);
277     END IF;
278 
279     -- check whether record has been updated by another user
280     BEGIN
281         -- check last update date.
282         SELECT rowid, object_version_number
283         INTO l_rowid, l_object_version_number
284         FROM HZ_CONTACT_PREFERENCES
285         WHERE contact_preference_id = p_contact_preference_rec.contact_preference_id
286 
287         FOR UPDATE NOWAIT;
288 
289 	IF NOT (
290             ( p_object_version_number IS NULL AND l_object_version_number IS NULL ) OR
291             ( p_object_version_number IS NOT NULL AND
292               l_object_version_number IS NOT NULL AND
293               p_object_version_number = l_object_version_number ) )
294         THEN
295             FND_MESSAGE.SET_NAME('AR', 'HZ_API_RECORD_CHANGED');
296             FND_MESSAGE.SET_TOKEN('TABLE', 'hz_contact_preferences');
297             FND_MSG_PUB.ADD;
298             RAISE FND_API.G_EXC_ERROR;
299         END IF;
300 
301         p_object_version_number := nvl(l_object_version_number, 1) + 1;
302 
303     EXCEPTION WHEN NO_DATA_FOUND THEN
304         FND_MESSAGE.SET_NAME('AR', 'HZ_API_NO_RECORD');
305         FND_MESSAGE.SET_TOKEN('RECORD', 'contact_preference');
306         FND_MESSAGE.SET_TOKEN('VALUE', NVL(TO_CHAR( p_contact_preference_rec.contact_preference_id), 'null'));
307         FND_MSG_PUB.ADD;
308         RAISE FND_API.G_EXC_ERROR;
309     END;
310 
311     ----------------------------------------------
312     -- if preference_start_date is null, give sysdate
313     ----------------------------------------------
314     IF p_contact_preference_rec.preference_start_date = FND_API.G_MISS_DATE THEN
315            p_contact_preference_rec.preference_start_date := sysdate;
316     END IF;
317 
318     -- validate contact preference record
319     HZ_CONTACT_PREFERENCE_VALIDATE.validate_contact_preference(
320         'U',
321         p_contact_preference_rec,
322         l_rowid,
323         x_return_status);
324 
325     IF x_return_status = FND_API.G_RET_STS_ERROR THEN
326         RAISE FND_API.G_EXC_ERROR;
327     END IF;
328 
329     -- Debug info.
330     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
331 	hz_utility_v2pub.debug(p_message=>'HZ_CONTACT_PREFERENCES_PKG.Update_Row (+)',
332 	                       p_prefix=>l_debug_prefix,
333 			       p_msg_level=>fnd_log.level_procedure);
334     END IF;
335 
336     -- call table handler to update a row
337     HZ_CONTACT_PREFERENCES_PKG.Update_Row (
338         X_Rowid                                 => l_rowid,
339         X_CONTACT_PREFERENCE_ID                 => p_contact_preference_rec.contact_preference_id,
340         X_CONTACT_LEVEL_TABLE                   => p_contact_preference_rec.contact_level_table,
341         X_CONTACT_LEVEL_TABLE_ID                => p_contact_preference_rec.contact_level_table_id,
342         X_CONTACT_TYPE                          => p_contact_preference_rec.contact_type,
343         X_PREFERENCE_CODE                       => p_contact_preference_rec.preference_code,
344         X_PREFERENCE_TOPIC_TYPE                => p_contact_preference_rec.preference_topic_type,
345         X_PREFERENCE_TOPIC_TYPE_ID             => p_contact_preference_rec.preference_topic_type_id,
346         X_PREFERENCE_TOPIC_TYPE_CODE           => p_contact_preference_rec.preference_topic_type_code,
347         X_PREFERENCE_START_DATE                 => p_contact_preference_rec.preference_start_date,
348         X_PREFERENCE_END_DATE                   => p_contact_preference_rec.preference_end_date,
349         X_PREFERENCE_START_TIME_HR              => p_contact_preference_rec.preference_start_time_hr,
350         X_PREFERENCE_END_TIME_HR                => p_contact_preference_rec.preference_end_time_hr,
351         X_PREFERENCE_START_TIME_MI              => p_contact_preference_rec.preference_start_time_mi,
352         X_PREFERENCE_END_TIME_MI                => p_contact_preference_rec.preference_end_time_mi,
353         X_MAX_NO_OF_INTERACTIONS                => p_contact_preference_rec.max_no_of_interactions,
354         X_MAX_NO_OF_INTERACT_UOM_CODE           => p_contact_preference_rec.max_no_of_interact_uom_code,
355         X_REQUESTED_BY                          => p_contact_preference_rec.requested_by,
356         X_REASON_CODE                           => p_contact_preference_rec.reason_code,
357         X_STATUS                                => p_contact_preference_rec.status,
358         X_OBJECT_VERSION_NUMBER                 => p_object_version_number,
359         X_CREATED_BY_MODULE                     => p_contact_preference_rec.created_by_module,
360         X_APPLICATION_ID                        => p_contact_preference_rec.application_id
361     );
362 
363     -- Debug info.
364     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
365 	hz_utility_v2pub.debug(p_message=>'HZ_CONTACT_PREFERENCES_PKG.Update_Row (-)',
366 	                       p_prefix=>l_debug_prefix,
367 			       p_msg_level=>fnd_log.level_procedure);
368     END IF;
369 
370     -- Debug info.
371     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
372 	hz_utility_v2pub.debug(p_message=>'do_update_contact_preference (-)',
373 	                       p_prefix=>l_debug_prefix,
374 			       p_msg_level=>fnd_log.level_procedure);
375     END IF;
376 
377 END do_update_contact_preference;
378 
379 
380 ----------------------------
381 -- body of public procedures
382 ----------------------------
383 
384 /**
385  * PROCEDURE create_contact_preference
386  *
387  * DESCRIPTION
388  *     Creates contact preference
389  *
390  * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
391  *
392  * ARGUMENTS
393  *   IN:
394  *     p_init_msg_list                Initialize message stack if it is set to
395  *                                    FND_API.G_TRUE. Default is FND_API.G_FALSE.
396  *     p_contact_preference_rec       Contact preference record.
397  *   IN/OUT:
398  *   OUT:
399  *     x_contact_preference_id        contact preference ID.
400  *     x_return_status                Return status after the call. The status can
401  *                                    be FND_API.G_RET_STS_SUCCESS (success),
402  *                                    FND_API.G_RET_STS_ERROR (error),
403  *                                    FND_API.G_RET_STS_UNEXP_ERROR (unexpected error).
404  *     x_msg_count                    Number of messages in message stack.
405  *     x_msg_data                     Message text if x_msg_count is 1.
406  *
407  * NOTES
408  *
409  * MODIFICATION HISTORY
410  *
411  *   23-JUL-2001    Kate Shan         o Created.
412  *
413  */
414 
415 PROCEDURE create_contact_preference(
416     p_init_msg_list                         IN      VARCHAR2:= FND_API.G_FALSE,
417     p_contact_preference_rec                IN      CONTACT_PREFERENCE_REC_TYPE,
418     x_contact_preference_id                 OUT NOCOPY     NUMBER,
419     x_return_status                         OUT NOCOPY     VARCHAR2,
420     x_msg_count                             OUT NOCOPY     NUMBER,
421     x_msg_data                              OUT NOCOPY     VARCHAR2
422 ) IS
423 
424     l_contact_preference_rec                        CONTACT_PREFERENCE_REC_TYPE := p_contact_preference_rec;
425     l_debug_prefix		                    VARCHAR2(30) := '';
426 
427 BEGIN
428     --Standard start of API savepoint
429     SAVEPOINT create_contact_preference_pub;
430 
431     -- Check if API is called in debug mode. If yes, enable debug.
432     --enable_debug;
433 
434     -- Debug info.
435     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
436 	hz_utility_v2pub.debug(p_message=>'create_contact_preference (+) ',
437 	                       p_prefix=>l_debug_prefix,
438 			       p_msg_level=>fnd_log.level_procedure);
439     END IF;
440 
441     --Initialize message list if p_init_msg_list is set to TRUE.
442     IF FND_API.to_Boolean(p_init_msg_list) THEN
443         FND_MSG_PUB.initialize;
444     END IF;
445 
446     --Initialize API return status to success.
447     x_return_status := FND_API.G_RET_STS_SUCCESS;
448 
449     -- Call to business logic.
450     do_create_contact_preference(
451         l_contact_preference_rec,
452         x_contact_preference_id,
453         x_return_status);
454 
455    IF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
456      IF(HZ_UTILITY_V2PUB.G_EXECUTE_API_CALLOUTS in ('Y', 'EVENTS_ENABLED')) THEN
457        -- Invoke business event system.
458        HZ_BUSINESS_EVENT_V2PVT.create_contact_prefer_event (
459          l_contact_preference_rec );
460      END IF;
461 
462      IF(HZ_UTILITY_V2PUB.G_EXECUTE_API_CALLOUTS in ('EVENTS_ENABLED', 'BO_EVENTS_ENABLED')) THEN
463        HZ_POPULATE_BOT_PKG.pop_hz_contact_preferences(
464          p_operation             => 'I',
465          p_contact_preference_id => x_contact_preference_id);
466      END IF;
467    END IF;
468 
469     --Standard call to get message count and if count is 1, get message info.
470     FND_MSG_PUB.Count_And_Get(
471         p_encoded => FND_API.G_FALSE,
472         p_count => x_msg_count,
473         p_data  => x_msg_data);
474 
475     -- Debug info.
476     IF fnd_log.level_exception>=fnd_log.g_current_runtime_level THEN
477 	 hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
478 	                       p_msg_data=>x_msg_data,
479 			       p_msg_type=>'WARNING',
480 			       p_msg_level=>fnd_log.level_exception);
481     END IF;
482     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
483 	hz_utility_v2pub.debug(p_message=> 'create_contact_preference (-) ',
484 	                       p_prefix=>l_debug_prefix,
485 			       p_msg_level=>fnd_log.level_procedure);
486     END IF;
487 
488     -- Check if API is called in debug mode. If yes, disable debug.
489     --disable_debug;
490 
491 EXCEPTION
492     WHEN FND_API.G_EXC_ERROR THEN
493         ROLLBACK TO create_contact_preference_pub;
494         x_return_status := FND_API.G_RET_STS_ERROR;
495         FND_MSG_PUB.Count_And_Get(
496             p_encoded => FND_API.G_FALSE,
497             p_count => x_msg_count,
498             p_data  => x_msg_data);
499 
500         -- Debug info.
501 	IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
502 		 hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
503 	                       p_msg_data=>x_msg_data,
504 			       p_msg_type=>'ERROR',
505 			       p_msg_level=>fnd_log.level_error);
506         END IF;
507         IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
508 	    hz_utility_v2pub.debug(p_message=>'create_contact_preference (-) ' ,
509 	                       p_prefix=>l_debug_prefix,
510 			       p_msg_level=>fnd_log.level_procedure);
511         END IF;
512 
513         -- Check if API is called in debug mode. If yes, disable debug.
514         --disable_debug;
515 
516 
517     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
518         ROLLBACK TO create_contact_preference_pub;
519         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
520         FND_MSG_PUB.Count_And_Get(
521             p_encoded => FND_API.G_FALSE,
522             p_count => x_msg_count,
523             p_data  => x_msg_data);
524 
525         -- Debug info.
526 	IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
527             hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
528 	                       p_msg_data=>x_msg_data,
529 			       p_msg_type=>'UNEXPECTED ERROR',
530 			       p_msg_level=>fnd_log.level_error);
531         END IF;
532         IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
533 	   hz_utility_v2pub.debug(p_message=>'create_contact_preference (-)',
534 	                       p_prefix=>l_debug_prefix,
535 			       p_msg_level=>fnd_log.level_procedure);
536         END IF;
537 
538         -- Check if API is called in debug mode. If yes, disable debug.
539         --disable_debug;
540 
541     WHEN OTHERS THEN
542         ROLLBACK TO create_contact_preference_pub;
543         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
544         FND_MESSAGE.SET_NAME('AR', 'HZ_API_OTHERS_EXCEP');
545         FND_MESSAGE.SET_TOKEN('ERROR' ,SQLERRM);
546         FND_MSG_PUB.ADD;
547         FND_MSG_PUB.Count_And_Get(
548             p_encoded => FND_API.G_FALSE,
549             p_count => x_msg_count,
550             p_data  => x_msg_data);
551 
552         -- Debug info.
553 	IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
554              hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
555 	                       p_msg_data=>x_msg_data,
556 			       p_msg_type=>'SQL ERROR',
557 			       p_msg_level=>fnd_log.level_error);
558         END IF;
559         IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
560 	    hz_utility_v2pub.debug(p_message=>'create_contact_preference (-) ',
561 	                       p_prefix=>l_debug_prefix,
562 			       p_msg_level=>fnd_log.level_procedure);
563         END IF;
564 
565         -- Check if API is called in debug mode. If yes, disable debug.
566         --disable_debug;
567 
568 END create_contact_preference;
569 
570 
571 /**
572  * PROCEDURE update_contact_preference
573  *
574  * DESCRIPTION
575  *     Updates contact preference
576  *
577  * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
578  *
579  * ARGUMENTS
580  *   IN:
581  *     p_init_msg_list                Initialize message stack if it is set to
582  *                                    FND_API.G_TRUE. Default is FND_API.G_FALSE.
583  *     p_contact_preference_rec       Contact Preference record.
584  *   IN/OUT:
585  *     p_object_version_number        Used for locking the being updated record.
586  *   OUT:
587  *     x_return_status                Return status after the call. The status can
588  *                                    be FND_API.G_RET_STS_SUCCESS (success),
589  *                                    FND_API.G_RET_STS_ERROR (error),
590  *                                    FND_API.G_RET_STS_UNEXP_ERROR (unexpected error).
591  *     x_msg_count                    Number of messages in message stack.
592  *     x_msg_data                     Message text if x_msg_count is 1.
593  *
594  * NOTES
595  *
596  * MODIFICATION HISTORY
597  *
598  *   07-23-2001    Kate Shan        o Created.
599  *
600  */
601 
602 PROCEDURE  update_contact_preference(
603     p_init_msg_list                         IN      VARCHAR2:= FND_API.G_FALSE,
604     p_contact_preference_rec                IN      CONTACT_PREFERENCE_REC_TYPE,
605     p_object_version_number                 IN OUT NOCOPY  NUMBER,
606     x_return_status                         OUT NOCOPY     VARCHAR2,
607     x_msg_count                             OUT NOCOPY     NUMBER,
608     x_msg_data                              OUT NOCOPY     VARCHAR2
609 ) IS
610 
611     l_contact_preference_rec                        CONTACT_PREFERENCE_REC_TYPE := p_contact_preference_rec;
612     l_old_contact_preference_rec                    CONTACT_PREFERENCE_REC_TYPE;
613     l_debug_prefix				    VARCHAR2(30) := '';
614 
615 BEGIN
616 
617     --Standard start of API savepoint
618     SAVEPOINT update_contact_preference_pub;
619 
620     -- Check if API is called in debug mode. If yes, enable debug.
621     --enable_debug;
622 
623     -- Debug info.
624     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
625 	hz_utility_v2pub.debug(p_message=>'update_contact_preference (+)',
626 	                       p_prefix=>l_debug_prefix,
627 			       p_msg_level=>fnd_log.level_procedure);
628     END IF;
629 
630     --Initialize message list if p_init_msg_list is set to TRUE.
631     IF FND_API.to_Boolean(p_init_msg_list) THEN
632         FND_MSG_PUB.initialize;
633     END IF;
634 
635     --Initialize API return status to success.
636     x_return_status := FND_API.G_RET_STS_SUCCESS;
637 
638     --2290537
639     get_contact_preference_rec (
640       p_contact_preference_id    => p_contact_preference_rec.contact_preference_id,
641       x_contact_preference_rec   => l_old_contact_preference_rec,
642       x_return_status            => x_return_status,
643       x_msg_count                => x_msg_count,
644       x_msg_data                 => x_msg_data);
645 
646     IF x_return_status = FND_API.G_RET_STS_ERROR THEN
647         RAISE FND_API.G_EXC_ERROR;
648     ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
649         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
650     END IF;
651 
652     -- Call to business logic.
653     do_update_contact_preference(
654         l_contact_preference_rec,
655         p_object_version_number,
656         x_return_status);
657 
658    IF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
659      IF(HZ_UTILITY_V2PUB.G_EXECUTE_API_CALLOUTS in ('Y', 'EVENTS_ENABLED')) THEN
660        -- Invoke business event system.
661        HZ_BUSINESS_EVENT_V2PVT.update_contact_prefer_event (
662          l_contact_preference_rec , l_old_contact_preference_rec  );
663      END IF;
664 
665      IF(HZ_UTILITY_V2PUB.G_EXECUTE_API_CALLOUTS in ('EVENTS_ENABLED', 'BO_EVENTS_ENABLED')) THEN
666        HZ_POPULATE_BOT_PKG.pop_hz_contact_preferences(
667          p_operation             => 'U',
668          p_contact_preference_id => l_contact_preference_rec.contact_preference_id);
669      END IF;
670    END IF;
671 
672     --Standard call to get message count and if count is 1, get message info.
673     FND_MSG_PUB.Count_And_Get(
674         p_encoded => FND_API.G_FALSE,
675         p_count => x_msg_count,
676         p_data  => x_msg_data);
677 
678     -- Debug info.
679     IF fnd_log.level_exception>=fnd_log.g_current_runtime_level THEN
680 	 hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
681 	                       p_msg_data=>x_msg_data,
682 			       p_msg_type=>'WARNING',
683 			       p_msg_level=>fnd_log.level_exception);
684     END IF;
685     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
686 	hz_utility_v2pub.debug(p_message=>'update_contact_preference (-)',
687 	                       p_prefix=>l_debug_prefix,
688 			       p_msg_level=>fnd_log.level_procedure);
689     END IF;
690 
691     -- Check if API is called in debug mode. If yes, disable debug.
692     --disable_debug;
693 
694 EXCEPTION
695     WHEN FND_API.G_EXC_ERROR THEN
696         ROLLBACK TO update_contact_preference_pub;
697         x_return_status := FND_API.G_RET_STS_ERROR;
698         FND_MSG_PUB.Count_And_Get(
699             p_encoded => FND_API.G_FALSE,
700             p_count => x_msg_count,
701             p_data  => x_msg_data);
702 
703         -- Debug info.
704 	IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
705 		 hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
706 	                       p_msg_data=>x_msg_data,
707 			       p_msg_type=>'ERROR',
708 			       p_msg_level=>fnd_log.level_error);
709         END IF;
710         IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
711 	    hz_utility_v2pub.debug(p_message=>'update_contact_preference (-)',
712 	                       p_prefix=>l_debug_prefix,
713 			       p_msg_level=>fnd_log.level_procedure);
714         END IF;
715 
716         -- Check if API is called in debug mode. If yes, disable debug.
717         --disable_debug;
718 
719     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
720         ROLLBACK TO update_contact_preference_pub;
721         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
722         FND_MSG_PUB.Count_And_Get(
723             p_encoded => FND_API.G_FALSE,
724             p_count => x_msg_count,
725             p_data  => x_msg_data);
726 
727         -- Debug info.
728 	IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
729             hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
730 	                       p_msg_data=>x_msg_data,
731 			       p_msg_type=>'UNEXPECTED ERROR',
732 			       p_msg_level=>fnd_log.level_error);
733         END IF;
734         IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
735 	   hz_utility_v2pub.debug(p_message=>'update_contact_preference (-)',
736 	                       p_prefix=>l_debug_prefix,
737 			       p_msg_level=>fnd_log.level_procedure);
738         END IF;
739 
740         -- Check if API is called in debug mode. If yes, disable debug.
741         --disable_debug;
742 
743     WHEN OTHERS THEN
744         ROLLBACK TO update_contact_preference_pub;
745         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
746         FND_MESSAGE.SET_NAME('AR', 'HZ_API_OTHERS_EXCEP');
747         FND_MESSAGE.SET_TOKEN('ERROR' ,SQLERRM);
748         FND_MSG_PUB.ADD;
749         FND_MSG_PUB.Count_And_Get(
750             p_encoded => FND_API.G_FALSE,
751             p_count => x_msg_count,
752             p_data  => x_msg_data);
753 
754         -- Debug info.
755 	IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
756              hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
757 	                       p_msg_data=>x_msg_data,
758 			       p_msg_type=>'SQL ERROR',
759 			       p_msg_level=>fnd_log.level_error);
760         END IF;
761         IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
762 	    hz_utility_v2pub.debug(p_message=>'update_contact_preference (-)',
763 	                       p_prefix=>l_debug_prefix,
764 			       p_msg_level=>fnd_log.level_procedure);
765         END IF;
766 
767         -- Check if API is called in debug mode. If yes, disable debug.
768         --disable_debug;
769 
770 END update_contact_preference;
771 
772 /**
773  * PROCEDURE get_contact_preference_rec
774  *
775  * DESCRIPTION
776  *      Gets contact preference record
777  *
778  * EXTERNAL PROCEDURES/FUNCTIONS ACCESSED
779  *
780  * ARGUMENTS
781  *   IN:
782  *     p_init_msg_list                Initialize message stack if it is set to
783  *                                    FND_API.G_TRUE. Default is FND_API.G_FALSE.
784  *     p_contact_preference_id        Contact preference id.
785  *   IN/OUT:
786  *   OUT:
787  *     x_contact_preference_rec       Returned contact preference record.
788  *     x_return_status                Return status after the call. The status can
789  *                                    be FND_API.G_RET_STS_SUCCESS (success),
790  *                                    FND_API.G_RET_STS_ERROR (error),
791  *                                    FND_API.G_RET_STS_UNEXP_ERROR (unexpected error).
792  *     x_msg_count                    Number of messages in message stack.
793  *     x_msg_data                     Message text if x_msg_count is 1.
794  *
795  * NOTES
796  *
797  * MODIFICATION HISTORY
798  *
799  *   07-23-2001    Kate Shan         o Created.
800  *
801  */
802 
803 PROCEDURE get_contact_preference_rec (
804     p_init_msg_list                         IN     VARCHAR2 := FND_API.G_FALSE,
805     p_contact_preference_id                 IN     NUMBER,
806     x_contact_preference_rec                OUT    NOCOPY CONTACT_PREFERENCE_REC_TYPE,
807     x_return_status                         OUT NOCOPY    VARCHAR2,
808     x_msg_count                             OUT NOCOPY    NUMBER,
809     x_msg_data                              OUT NOCOPY    VARCHAR2
810 ) IS
811 l_debug_prefix				    VARCHAR2(30) := '';
812 BEGIN
813 
814     -- Check if API is called in debug mode. If yes, enable debug.
815     --enable_debug;
816 
817     -- Debug info.
818     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
819 	hz_utility_v2pub.debug(p_message=>'get_contact_preference_rec (+)',
820 	                       p_prefix=>l_debug_prefix,
821 			       p_msg_level=>fnd_log.level_procedure);
822     END IF;
823 
824     --Initialize message list if p_init_msg_list is set to TRUE.
825     IF FND_API.to_Boolean(p_init_msg_list) THEN
826         FND_MSG_PUB.initialize;
827     END IF;
828 
829     --Initialize API return status to success.
830     x_return_status := FND_API.G_RET_STS_SUCCESS;
831 
832     --Check whether primary key has been passed in.
833     IF p_contact_preference_id IS NULL OR
834        p_contact_preference_id = FND_API.G_MISS_NUM THEN
835         FND_MESSAGE.SET_NAME( 'AR', 'HZ_API_MISSING_COLUMN' );
836         FND_MESSAGE.SET_TOKEN( 'COLUMN', 'contact_preference_id' );
837         FND_MSG_PUB.ADD;
838         RAISE FND_API.G_EXC_ERROR;
839     END IF;
840 
841     x_contact_preference_rec.contact_preference_id := p_contact_preference_id;
842 
843     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
844 	hz_utility_v2pub.debug(p_message=>'HZ_CONTACT_PREFERENCES_PKG.Select_Row (+)',
845 	                       p_prefix=>l_debug_prefix,
846 			       p_msg_level=>fnd_log.level_procedure);
847     END IF;
848 
849     HZ_CONTACT_PREFERENCES_PKG.Select_Row (
850         X_CONTACT_PREFERENCE_ID                 => x_contact_preference_rec.contact_preference_id,
851         X_CONTACT_LEVEL_TABLE                   => x_contact_preference_rec.contact_level_table,
852         X_CONTACT_LEVEL_TABLE_ID                => x_contact_preference_rec.contact_level_table_id,
853         X_CONTACT_TYPE                          => x_contact_preference_rec.contact_type,
854         X_PREFERENCE_CODE                       => x_contact_preference_rec.preference_code,
855         X_PREFERENCE_TOPIC_TYPE                => x_contact_preference_rec.preference_topic_type,
856         X_PREFERENCE_TOPIC_TYPE_ID             => x_contact_preference_rec.preference_topic_type_id,
857         X_PREFERENCE_TOPIC_TYPE_CODE           => x_contact_preference_rec.preference_topic_type_code,
858         X_PREFERENCE_START_DATE                 => x_contact_preference_rec.preference_start_date,
859         X_PREFERENCE_END_DATE                   => x_contact_preference_rec.preference_end_date,
860         X_PREFERENCE_START_TIME_HR              => x_contact_preference_rec.preference_start_time_hr,
861         X_PREFERENCE_END_TIME_HR                => x_contact_preference_rec.preference_end_time_hr,
862         X_PREFERENCE_START_TIME_MI              => x_contact_preference_rec.preference_start_time_mi,
863         X_PREFERENCE_END_TIME_MI                => x_contact_preference_rec.preference_end_time_mi,
864         X_MAX_NO_OF_INTERACTIONS                => x_contact_preference_rec.max_no_of_interactions,
865         X_MAX_NO_OF_INTERACT_UOM_CODE           => x_contact_preference_rec.max_no_of_interact_uom_code,
866         X_REQUESTED_BY                          => x_contact_preference_rec.requested_by,
867         X_REASON_CODE                           => x_contact_preference_rec.reason_code,
868         X_STATUS                                => x_contact_preference_rec.status,
869         X_CREATED_BY_MODULE                     => x_contact_preference_rec.created_by_module,
870         X_APPLICATION_ID                        => x_contact_preference_rec.application_id
871     );
872 
873     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
874 	hz_utility_v2pub.debug(p_message=>'HZ_CONTACT_PREFERENCES_PKG.Select_Row (-)',
875 	                       p_prefix=>l_debug_prefix,
876 			       p_msg_level=>fnd_log.level_procedure);
877     END IF;
878 
879     --Standard call to get message count and if count is 1, get message info.
880     FND_MSG_PUB.Count_And_Get(
881         p_encoded => FND_API.G_FALSE,
882         p_count => x_msg_count,
883         p_data  => x_msg_data );
884 
885     -- Debug info.
886     IF fnd_log.level_exception>=fnd_log.g_current_runtime_level THEN
887 	 hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
888 	                       p_msg_data=>x_msg_data,
889 			       p_msg_type=>'WARNING',
890 			       p_msg_level=>fnd_log.level_exception);
891     END IF;
892     IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
893 	hz_utility_v2pub.debug(p_message=>'get_contact_preference_rec (-)',
894 	                       p_prefix=>l_debug_prefix,
895 			       p_msg_level=>fnd_log.level_procedure);
896     END IF;
897 
898     -- Check if API is called in debug mode. If yes, disable debug.
899     --disable_debug;
900 
901 
902 EXCEPTION
903     WHEN FND_API.G_EXC_ERROR THEN
904         x_return_status := FND_API.G_RET_STS_ERROR;
905 
906         FND_MSG_PUB.Count_And_Get(
907             p_encoded => FND_API.G_FALSE,
908             p_count => x_msg_count,
909             p_data  => x_msg_data );
910 
911         -- Debug info.
912 	IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
913 		 hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
914 	                       p_msg_data=>x_msg_data,
915 			       p_msg_type=>'ERROR',
916 			       p_msg_level=>fnd_log.level_error);
917         END IF;
918         IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
919 	    hz_utility_v2pub.debug(p_message=>'get_contact_preference_rec (-)',
920 	                       p_prefix=>l_debug_prefix,
921 			       p_msg_level=>fnd_log.level_procedure);
922         END IF;
923 
924         -- Check if API is called in debug mode. If yes, disable debug.
925         --disable_debug;
926 
927     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
928         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
929 
930         FND_MSG_PUB.Count_And_Get(
931             p_encoded => FND_API.G_FALSE,
932             p_count => x_msg_count,
933             p_data  => x_msg_data );
934 
935         -- Debug info.
936 	IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
937             hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
938 	                       p_msg_data=>x_msg_data,
939 			       p_msg_type=>'UNEXPECTED ERROR',
940 			       p_msg_level=>fnd_log.level_error);
941         END IF;
942         IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
943 	   hz_utility_v2pub.debug(p_message=>'get_contact_preference_rec (-)',
944 	                       p_prefix=>l_debug_prefix,
945 			       p_msg_level=>fnd_log.level_procedure);
946         END IF;
947 
948         -- Check if API is called in debug mode. If yes, disable debug.
949         --disable_debug;
950 
951     WHEN OTHERS THEN
952         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
953 
954         FND_MESSAGE.SET_NAME( 'AR', 'HZ_API_OTHERS_EXCEP' );
955         FND_MESSAGE.SET_TOKEN( 'ERROR' ,SQLERRM );
956         FND_MSG_PUB.ADD;
957 
958         FND_MSG_PUB.Count_And_Get(
959             p_encoded => FND_API.G_FALSE,
960             p_count => x_msg_count,
961             p_data  => x_msg_data );
962 
963         -- Debug info.
964 	IF fnd_log.level_error>=fnd_log.g_current_runtime_level THEN
965              hz_utility_v2pub.debug_return_messages(p_msg_count=>x_msg_count,
966 	                       p_msg_data=>x_msg_data,
967 			       p_msg_type=>'SQL ERROR',
968 			       p_msg_level=>fnd_log.level_error);
969         END IF;
970         IF fnd_log.level_procedure>=fnd_log.g_current_runtime_level THEN
971 	    hz_utility_v2pub.debug(p_message=>'get_contact_preference_rec (-)',
972 	                       p_prefix=>l_debug_prefix,
973 			       p_msg_level=>fnd_log.level_procedure);
974         END IF;
975 
976         -- Check if API is called in debug mode. If yes, disable debug.
977         --disable_debug;
978 
979 END get_contact_preference_rec;
980 
981 
982 END HZ_CONTACT_PREFERENCE_V2PUB;