DBA Data[Home] [Help]

PACKAGE BODY: APPS.AMS_COPYACTIVITIES_PVT

Source


1 PACKAGE BODY ams_copyactivities_pvt AS
2 /* $Header: amsvcpab.pls 120.6 2007/12/26 09:33:54 spragupa ship $ */
3 
4  g_pkg_name   CONSTANT VARCHAR2(30) := 'AMS_Copyactivities_PVT';
5 ---------------------------------------------------------------------
6 -- PROCEDURE
7 --    copy_deliverable
8 --
9 -- HISTORY
10 --  10/27/99  MPANDE  Created.
11 
12 --  07/11/2000 SKARUMUR Modified
13 
14 --  Copy Campaign: Included calls to copy Teams,Tasks ans Partners
15 
16 --  Included over loaded procedures to handle logging
17 
18 --  Messages.  Added 4 wrapper procedures
19 
20 --  Modified campaign creation to include new columns, Changed population
21 
22 --  of owner_user_id and user_status_id.  Using version to assure uniqueness
23 -- 17-Jul-2000 choang  Copy event header changes: 1) new owner_user_id
24 --                     should come from current user.  2) Forced commit
25 --                     in create event API call.
26 -- 17-Jul-2000 choang  Copy event offer changes: 1) new owner_user_id
27 --                     should come from current user.  2) added custom_setup_id
28 --                     to pass into create_eventoffer API.  3) Removed
29 --                     calls to create object attributes.
30 -- 25-Jan-2001 ptendulk  Modified Copy campaign procedure.
31 --                       Don't copy business units while copying campaign.
32 -- 17-Feb-2001 ptendulk  Added commit after each api to commit after success.
33 -- 21-Aug-2001 ptendulk  Modified the new campaign copy api added .
34 -- 05-Oct-2001 rrajesh   Modified the new campaign copy api added - to get the
35 --                       owner field from UI.
36 -- 18-OCT-2001 rrajesh   Modified attchment copy for CAMP and CSCH
37 --                       Added DELV and GEOS attributes to Campaign Copy
38 -- 22-OCT-2001 rrajesh   Bugfix: 2068786
39 -- 24-OCT-2001 rrajesh   fix:2072789
40 -- 29-OCT-2001 rrajesh   Bug fix: 2081684
41 -- 31-jan-2002 soagrawa  Fixed bug# 2207969 in copy_campaign_new
42 -- 07-feb-2002 soagrawa  Fixed bug# 2217842 in copy_campaign_new
43 -- 14-may-2002 mukumar   Commented act_resource_copy API since we are not supporting the resource copy
44 -- 07-jun-2002 aranka    Event data was not getting copied Bug #2401609
45 -- 13-aug-2002 soagrawa  Fixed bug# 2511347 in copy_campaign_new
46 -- 29-may-2003 soagrawa  Fixed bug# 2949268 in copy_schedule_Attributes
47 -- 05-oct-2003 sodixit   Modified copy_schedule_Attributes to copy target group and collateral for 11.5.10
48 -- 20-May-2004 dhsingh	 Modified copy_event_offer and copy_event_header for better performance
49 -- 05-Aug-2005 anchaudh  Added api for copy of collateral contents attached to the non-direct marketing activities.
50 -- 24-Apr-2006 vmodur    Bug 5171873 Set OVN for Copied EVEH, EVEO and EONE to 2 for DFF Copy Issue
51 -- 24-Dec-2007 spragupa	 ER - 6467510 - Extend Copy functionality to include TASKS for campaign schedules/activities
52 ---------------------------------------------------------------------
53 
54    g_file_name varchar2(30) := 'amsvcpab.pls';
55    AMS_DEBUG_HIGH_ON CONSTANT boolean := FND_MSG_PUB.CHECK_MSG_LEVEL(FND_MSG_PUB.G_MSG_LVL_DEBUG_HIGH);
56 AMS_DEBUG_LOW_ON CONSTANT boolean := FND_MSG_PUB.CHECK_MSG_LEVEL(FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW);
57 AMS_DEBUG_MEDIUM_ON CONSTANT boolean := FND_MSG_PUB.CHECK_MSG_LEVEL(FND_MSG_PUB.G_MSG_LVL_DEBUG_MEDIUM);
58 
59 PROCEDURE copy_event_header(
60       p_api_version         IN       NUMBER,
61       p_init_msg_list       IN       VARCHAR2 := fnd_api.g_false,
62       x_return_status       OUT NOCOPY      VARCHAR2,
63       x_msg_count           OUT NOCOPY      NUMBER,
64       x_msg_data            OUT NOCOPY      VARCHAR2,
65       x_eveh_id             OUT NOCOPY      NUMBER,
66       p_src_eveh_id         IN       NUMBER,
67       p_new_eveh_name       IN       VARCHAR2,
68       p_par_eveh_id         IN       NUMBER,
69       p_eveh_elements_rec   IN       eveh_elements_rec_type,
70       p_start_date          IN       DATE := NULL,
71       p_end_date            IN       DATE := NULL,
72       x_transaction_id      OUT NOCOPY      NUMBER,
73       p_source_code         IN       VARCHAR2 := NULL) IS
74       BEGIN
75 
76       AMS_CPYutility_pvt.refresh_log_mesg;
77           copy_event_header(
78                      p_api_version        => p_api_version,
79                      p_init_msg_list      => p_init_msg_list,
80                      x_return_status      => x_return_status,
81                      x_msg_count          => x_msg_count ,
82                      x_msg_data           => x_msg_data ,
83                      x_eveh_id            => x_eveh_id ,
84                      p_src_eveh_id        => p_src_eveh_id,
85                      p_new_eveh_name      => p_new_eveh_name,
86                      p_par_eveh_id        => p_par_eveh_id,
87                      p_eveh_elements_rec  => p_eveh_elements_rec,
88                      p_start_date         => p_start_date,
89                   p_end_date           => p_end_date ,
90                      p_source_code        => p_source_code);
91       AMS_CPYutility_pvt.insert_log_mesg(x_transaction_id);
92      END;
93 
94   PROCEDURE copy_event_offer(
95       p_api_version         IN       NUMBER,
96       p_init_msg_list       IN       VARCHAR2 := fnd_api.g_false,
97       x_return_status       OUT NOCOPY      VARCHAR2,
98       x_msg_count           OUT NOCOPY      NUMBER,
99       x_msg_data            OUT NOCOPY      VARCHAR2,
100       x_eveo_id             OUT NOCOPY      NUMBER,
101       p_src_eveo_id         IN       NUMBER,
102       p_event_header_id     IN       NUMBER,
103       p_new_eveo_name       IN       VARCHAR2 := NULL,
104       p_par_eveo_id         IN       NUMBER := NULL,
105       p_eveo_elements_rec   IN       eveo_elements_rec_type,
106       p_start_date          IN       DATE := NULL,
107       p_end_date            IN       DATE := NULL,
108       x_transaction_id      OUT NOCOPY      NUMBER ,
109       p_source_code         IN       VARCHAR2 :=NULL) IS
110     BEGIN
111          AMS_CPYutility_pvt.refresh_log_mesg;
112              copy_event_offer(
113                       p_api_version        => p_api_version,
114                       p_init_msg_list      => p_init_msg_list,
115                       x_return_status      => x_return_status,
116                       x_msg_count          => x_msg_count,
117                       x_msg_data           => x_msg_data,
118                       x_eveo_id            => x_eveo_id,
119                       p_src_eveo_id        => p_src_eveo_id,
120                       p_event_header_id    => p_event_header_id,
121                       p_new_eveo_name      => p_new_eveo_name,
122                       p_par_eveo_id        => p_par_eveo_id,
123                       p_eveo_elements_rec  => p_eveo_elements_rec,
124                       p_start_date         => p_start_date,
125                       p_end_date           => p_end_date,
126                       p_source_code        => p_source_code   );
127          AMS_CPYutility_pvt.insert_log_mesg(x_transaction_id);
128      END;
129    PROCEDURE copy_deliverables(
130       p_api_version         IN       NUMBER,
131       p_init_msg_list       IN       VARCHAR2 := fnd_api.g_false,
132       x_return_status       OUT NOCOPY      VARCHAR2,
133       x_msg_count           OUT NOCOPY      NUMBER,
134       x_msg_data            OUT NOCOPY      VARCHAR2,
135       x_deliverable_id      OUT NOCOPY      NUMBER,
136       p_src_deliv_id        IN       NUMBER,
137       p_new_deliv_name      IN       VARCHAR2,
138       p_new_deliv_code      IN       VARCHAR2 := NULL,
139       p_deli_elements_rec   IN       deli_elements_rec_type,
140       p_new_version         IN       VARCHAR2,
141       x_transaction_id      OUT NOCOPY      NUMBER) IS
142     BEGIN
143          AMS_CPYutility_pvt.refresh_log_mesg;
144 
145                copy_deliverables( p_api_version        => p_api_version,
146                          p_init_msg_list      => p_init_msg_list ,
147                          x_return_status      => x_return_status ,
148                          x_msg_count          => x_msg_count ,
149                          x_msg_data           => x_msg_data ,
150                          x_deliverable_id     => x_deliverable_id,
151                          p_src_deliv_id       => p_src_deliv_id ,
152                          p_new_deliv_name     => p_new_deliv_name,
153                          p_new_deliv_code     => p_new_deliv_code,
154                          p_deli_elements_rec  => p_deli_elements_rec,
155                          p_new_version        => p_new_version );
156 
157          AMS_CPYutility_pvt.insert_log_mesg(x_transaction_id);
158 
159     END;
160 
161    PROCEDURE copy_campaign(
162       p_api_version         IN       NUMBER,
163       p_init_msg_list       IN       VARCHAR2 := fnd_api.g_false,
164       x_return_status       OUT NOCOPY      VARCHAR2,
165       x_msg_count           OUT NOCOPY      NUMBER,
166       x_msg_data            OUT NOCOPY      VARCHAR2,
167       x_campaign_id         OUT NOCOPY      NUMBER,
168       p_src_camp_id         IN       NUMBER,
169       p_new_camp_name       IN       VARCHAR2 := NULL,
170       p_par_camp_id         IN       NUMBER := NULL,
171       p_source_code         IN       VARCHAR2 := NULL,
172       p_camp_elements_rec   IN       camp_elements_rec_type,
173       p_end_date            IN       DATE := NULL,
174       p_start_date          IN       DATE := NULL,
175     x_transaction_id      OUT NOCOPY      NUMBER) IS
176     BEGIN
177 
178       AMS_CPYutility_pvt.refresh_log_mesg;
179 
180             copy_campaign( p_api_version       => p_api_version,
181                       p_init_msg_list     => p_init_msg_list,
182                       x_return_status     => x_return_status,
183                       x_msg_count         => x_msg_count,
184                       x_msg_data          => x_msg_data ,
185                       x_campaign_id       => x_campaign_id,
186                       p_src_camp_id       => p_src_camp_id,
187                       p_new_camp_name     => p_new_camp_name,
188                       p_par_camp_id       => p_par_camp_id,
189                       p_source_code       => p_source_code,
190                       p_camp_elements_rec => p_camp_elements_rec,
191                       p_end_date          => p_end_date,
192                       p_start_date        => p_start_date );
193 
194       AMS_CPYutility_pvt.insert_log_mesg(x_transaction_id);
195 
196    END;
197 ---------------------------------------------------------------------
198 
199 -- Added by rrajesh on 08/14/01
200 -- to support the common copy functionality
201 
202 -- 21-Aug-2001   ptendulk    Modified to get data from screen
203 --                           Added Copy Schedule Routine.
204 -- 31-jan-2002   soagrawa    Fixed bug# 2207969
205 -- 07-feb-2002   soagrawa    Fixed bug# 2217842
206 -- 13-aug-2002   soagrawa    Fixed bug# 2511347
207 ---------------------------------------------------------------------
208 PROCEDURE copy_campaign_new(
209     p_api_version                IN   NUMBER,
210     p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE,
211     p_commit                     IN   VARCHAR2     := FND_API.G_FALSE,
212     p_validation_level           IN   NUMBER       := FND_API.G_VALID_LEVEL_FULL,
213 
214     x_return_status              OUT NOCOPY  VARCHAR2,
215     x_msg_count                  OUT NOCOPY  NUMBER,
216     x_msg_data                   OUT NOCOPY  VARCHAR2,
217 
218     p_source_object_id           IN   NUMBER,
219     p_attributes_table           IN   AMS_CpyUtility_PVT.copy_attributes_table_type,
220     p_copy_columns_table         IN   AMS_CpyUtility_PVT.copy_columns_table_type,
221 
222     x_new_object_id              OUT NOCOPY  NUMBER,
223     x_custom_setup_id            OUT NOCOPY  NUMBER
224      )
225 IS
226 
227    l_api_name                  CONSTANT VARCHAR2(30) := 'copy_campaign_new';
228    l_api_version_number        CONSTANT NUMBER   := 1.0;
229    l_return_status_full        VARCHAR2(1);
230    l_object_version_number     NUMBER := 1;
231    l_org_id                    NUMBER := FND_API.G_MISS_NUM;
232    l_campaign_id               NUMBER;
233    l_new_campaign_id           NUMBER;
234    l_dummy                     NUMBER;
235 
236    l_return_status             VARCHAR2(1);
237    l_custom_setup_id           NUMBER := 1;
238    l_campaign_name             VARCHAR(50);
239    l_country_name              VARCHAR(50);
240    l_coordinator_name          VARCHAR(50);
241 
242    l_date_number               NUMBER := 0;
243    l_errnum	               NUMBER;
244    l_errcode                   VARCHAR2(80);
245    l_errmsg                    VARCHAR2(3000);
246    l_msg_count	               NUMBER;
247    l_msg_data                  VARCHAR2(2000);
248 
249    -- Added by rrajesh on 08/31/01
250    l_new_schedule_id           NUMBER;
251    l_tmp_schedule_id           NUMBER;
252    -- soagrawa 07-feb-2002   bug# 2217842
253    -- changed buffer size for the following
254    x_schedule_ids              VARCHAR2(4000) := '';           --VARCHAR2(80);
255    l_schedule_ids              VARCHAR2(4000) := '';           --VARCHAR2(80);
256    l_index                     NUMBER := 1;
257    l_length                    NUMBER;
258    l_counter                   NUMBER;
259    l_str_schedule_id           VARCHAR(20);
260    -- end change 08/31/01
261 
262    CURSOR fetch_camp_details (camp_id NUMBER) IS
263    SELECT * FROM ams_campaigns_vl
264    WHERE campaign_id = camp_id ;
265 
266    l_reference_rec             fetch_camp_details%ROWTYPE;
267    l_camp_rec                  ams_campaign_pvt.camp_rec_type;
268    l_new_reference_rec         fetch_camp_details%ROWTYPE;
269 
270 BEGIN
271 
272    -- Standard Start of API savepoint
273    SAVEPOINT COPY_Camp_Common_PVT;
274 
275    -- Standard call to check for call compatibility.
276    IF NOT FND_API.Compatible_API_Call ( l_api_version_number,
277                                         p_api_version,
278                                         l_api_name,
279                                         G_PKG_NAME)
280    THEN
281        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
282    END IF;
283 
284    -- Initialize message list if p_init_msg_list is set to TRUE.
285    IF FND_API.to_Boolean( p_init_msg_list )
286    THEN
287       FND_MSG_PUB.initialize;
288    END IF;
289 
290    -- Debug Message
291    IF (AMS_DEBUG_HIGH_ON) THEN
292 
293        AMS_UTILITY_PVT.debug_message('Private API: ' || l_api_name || 'start');
294    END IF;
295 
296    -- Writing to PL/SQL table
297    --WRITE_TO_ACT_LOG('start new copy function','CAMP',1111);
298 
299    -- Initialize API return status to SUCCESS
300    x_return_status := FND_API.G_RET_STS_SUCCESS;
301 
302    --
303    -- Start of API body
304    --
305    OPEN fetch_camp_details(p_source_object_id);
306    FETCH fetch_camp_details INTO l_reference_rec;
307    CLOSE fetch_camp_details;
308 
309    l_camp_rec.campaign_id := null;
310 
311    -- Copying Campaign Details
312    -- a) Copying Fields from source Campaign Fields
313    l_camp_rec.global_flag              := l_reference_rec.global_flag;
314    l_camp_rec.custom_setup_id          := l_reference_rec.custom_setup_id;
315    l_camp_rec.business_unit_id         := null ;
316    l_camp_rec.private_flag             := l_reference_rec.private_flag;
317    l_camp_rec.partner_flag             := l_reference_rec.partner_flag;
318    l_camp_rec.template_flag            := l_reference_rec.template_flag;
319    l_camp_rec.cascade_source_code_flag := l_reference_rec.cascade_source_code_flag;
320    l_camp_rec.inherit_attributes_flag  := l_reference_rec.inherit_attributes_flag;
321    l_camp_rec.rollup_type              := l_reference_rec.rollup_type;
322    l_camp_rec.campaign_type            := l_reference_rec.campaign_type;
323    l_camp_rec.priority                 := l_reference_rec.priority;
324    l_camp_rec.fund_source_type         := l_reference_rec.fund_source_type;
325    l_camp_rec.fund_source_id           := l_reference_rec.fund_source_id;
326    l_camp_rec.application_id           := l_reference_rec.application_id;
327    l_camp_rec.media_id                 := l_reference_rec.media_id;
328    l_camp_rec.media_type_code          := l_reference_rec.media_type_code;
329    l_camp_rec.transaction_currency_code:= l_reference_rec.transaction_currency_code;
330    l_camp_rec.functional_currency_code :=  l_reference_rec.functional_currency_code;
331    -- Bugfix: 2068786. Modified by rrajesh on 10/22/01
332    --l_camp_rec.budget_amount_tc         := l_reference_rec.budget_amount_tc;
333    --l_camp_rec.budget_amount_fc         := l_reference_rec.budget_amount_fc;
334    l_camp_rec.budget_amount_tc         := null;
335    l_camp_rec.budget_amount_fc         := null;
336    -- End fix: 2068786
337    l_camp_rec.event_type               := l_reference_rec.event_type;
338    l_camp_rec.content_source           := l_reference_rec.content_source;
339    l_camp_rec.cc_call_strategy         := l_reference_rec.cc_call_strategy;
340    l_camp_rec.cc_manager_user_id       := l_reference_rec.cc_manager_user_id;
341    l_camp_rec.forecasted_revenue       := l_reference_rec.forecasted_revenue;
342    l_camp_rec.forecasted_cost          := l_reference_rec.forecasted_cost;
343    l_camp_rec.forecasted_response      := l_reference_rec.forecasted_response;
344    l_camp_rec.target_response          := l_reference_rec.target_response;
345    l_camp_rec.country_code             := l_reference_rec.country_code;
346    l_camp_rec.language_code            := l_reference_rec.language_code;
347    l_camp_rec.attribute_category       := l_reference_rec.attribute_category;
348    l_camp_rec.attribute1               := l_reference_rec.attribute1;
349    l_camp_rec.attribute2               := l_reference_rec.attribute2;
350    l_camp_rec.attribute3               := l_reference_rec.attribute3;
351    l_camp_rec.attribute4               := l_reference_rec.attribute4;
352    l_camp_rec.attribute5               := l_reference_rec.attribute5;
353    l_camp_rec.attribute6               := l_reference_rec.attribute6;
354    l_camp_rec.attribute7               := l_reference_rec.attribute7;
355    l_camp_rec.attribute8               := l_reference_rec.attribute8;
356    l_camp_rec.attribute9               := l_reference_rec.attribute9;
357    l_camp_rec.attribute10              := l_reference_rec.attribute10;
358    l_camp_rec.attribute11              := l_reference_rec.attribute11;
359    l_camp_rec.attribute12              := l_reference_rec.attribute12;
360    l_camp_rec.attribute13              := l_reference_rec.attribute13;
361    l_camp_rec.attribute14              := l_reference_rec.attribute14;
362    l_camp_rec.attribute15              := l_reference_rec.attribute15;
363    l_camp_rec.duration                 := l_reference_rec.duration;
364    l_camp_rec.duration_uom_code        := l_reference_rec.duration_uom_code;
365    l_camp_rec.campaign_theme           := l_reference_rec.campaign_theme;
366    l_camp_rec.description              := l_reference_rec.description;
367 
368 --aranka added 06/07/02
369    l_camp_rec.related_event_from       := l_reference_rec.related_event_from;
370    l_camp_rec.related_event_id         := l_reference_rec.related_event_id;
371 
372    -- b)   Null fields
373    l_camp_rec.start_period_name          := NULL;
374    l_camp_rec.end_period_name            := NULL;
375    l_camp_rec.forecasted_plan_start_date := NULL;
376    l_camp_rec.forecasted_plan_end_date   := NULL;
377    l_camp_rec.forecasted_exec_start_date := NULL;
378    l_camp_rec.forecasted_exec_end_date   := NULL;
379    l_camp_rec.actual_plan_start_date     := NULL;
380    l_camp_rec.actual_plan_end_date       := NULL;
381    l_camp_rec.channel_id                 := NULL;
382    l_camp_rec.arc_channel_from           := NULL;
383 
384    -- c)  Fields Different between source campaign and copied campaign
385    -- version to be taken from the screen: modified by soagrawa on 07-nov-2001, bug# 2082641
386    -- l_camp_rec.version_no                 := l_reference_rec.version_no;
387    l_camp_rec.object_version_number      := 1;
388    l_camp_rec.campaign_calendar          := FND_PROFILE.value('AMS_CAMPAIGN_DEFAULT_CALENDER');
389    l_camp_rec.city_id                    := TO_NUMBER(FND_PROFILE.value('AMS_SRCGEN_USER_CITY'));
390    -- Following line is commented out by rrajesh on 10/05/01.
391    -- getting owner from UI.
392    --l_camp_rec.owner_user_id              := l_reference_rec.owner_user_id;
393    l_camp_rec.user_status_id             := AMS_Utility_PVT.get_default_user_status('AMS_CAMPAIGN_STATUS','NEW');
394    l_camp_rec.status_code                := 'NEW';
395    l_camp_rec.status_date                := SYSDATE;
396 
397    -- l_date number is the difference between start date of source
398    -- Campaign and end data of source campaign date
399    l_date_number := ams_cpyutility_pvt.get_dates('CAMP',
400                                                  p_source_object_id,
401                                                  l_return_status);
402 
403    IF l_return_status = FND_API.G_RET_STS_ERROR THEN
404       RAISE FND_API.G_EXC_ERROR ;
405    ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
406       RAISE FND_API.G_EXC_UNEXPECTED_ERROR ;
407    END IF;
408 
409    -- Following code is added by ptendulk on 18Aug2001
410    AMS_CpyUtility_PVT.get_column_value ('newObjName', p_copy_columns_table, l_camp_rec.campaign_name);
411    l_camp_rec.campaign_name := NVL (l_camp_rec.campaign_name, l_reference_rec.campaign_name);
412 
413    AMS_CpyUtility_PVT.get_column_value ('startDate', p_copy_columns_table, l_camp_rec.actual_exec_start_date);
414    l_camp_rec.actual_exec_start_date := NVL (l_camp_rec.actual_exec_start_date, l_reference_rec.actual_exec_start_date);
415 
416    /* mayjain 8-Aug-2005
417    -- End date of copied(new) campaign is start date(user input)+l_date_number
418    l_camp_rec.actual_exec_end_date := l_camp_rec.actual_exec_start_date + l_date_number ;
419    */
420 
421 
422    AMS_CpyUtility_PVT.get_column_value ('newObjName', p_copy_columns_table, l_camp_rec.campaign_name);
423    l_camp_rec.campaign_name := NVL (l_camp_rec.campaign_name, l_reference_rec.campaign_name);
424 
425    AMS_CpyUtility_PVT.get_column_value ('sourceCode', p_copy_columns_table, l_camp_rec.source_code);
426 
427    -- Getting owner value from UI. Changed by rrajesh on 10/05.
428    AMS_CpyUtility_PVT.get_column_value ('ownerId', p_copy_columns_table, l_camp_rec.owner_user_id);
429 
430    -- version to be taken from the screen: modified by soagrawa on 07-nov-2001, bug# 2082641
431    AMS_CpyUtility_PVT.get_column_value ('versionNum', p_copy_columns_table, l_camp_rec.version_no);
432    l_camp_rec.version_no := NVL (l_camp_rec.version_no, l_reference_rec.version_no);
433 
434    /* mayjain 8-Aug-2005 */
435    /* changes foe R12 */
436    AMS_CpyUtility_PVT.get_column_value ('endDate', p_copy_columns_table, l_camp_rec.actual_exec_end_date);
437    --l_camp_rec.actual_exec_end_date := NVL (l_camp_rec.actual_exec_end_date, l_reference_rec.actual_exec_end_date);
438 
439    AMS_CpyUtility_PVT.get_column_value ('parentCampaignId', p_copy_columns_table, l_camp_rec.parent_campaign_id);
440    --l_camp_rec.parent_campaign_id := NVL (l_camp_rec.parent_campaign_id, l_reference_rec.parent_campaign_id);
441 
442    AMS_CpyUtility_PVT.get_column_value ('description', p_copy_columns_table, l_camp_rec.description);
443    --l_camp_rec.description := NVL (l_camp_rec.description, l_reference_rec.description);
444 
445    AMS_CpyUtility_PVT.get_column_value ('attribute_category', p_copy_columns_table, l_camp_rec.attribute_category);
446    --l_camp_rec.attribute_category := NVL (l_camp_rec.attribute_category, l_reference_rec.attribute_category);
447 
448    AMS_CpyUtility_PVT.get_column_value ('attribute1', p_copy_columns_table, l_camp_rec.attribute1);
449    --l_camp_rec.attribute1 := NVL (l_camp_rec.attribute1, l_reference_rec.attribute1);
450 
451    AMS_CpyUtility_PVT.get_column_value ('attribute2', p_copy_columns_table, l_camp_rec.attribute2);
452    --l_camp_rec.attribute2 := NVL (l_camp_rec.attribute2, l_reference_rec.attribute2);
453 
454    AMS_CpyUtility_PVT.get_column_value ('attribute3', p_copy_columns_table, l_camp_rec.attribute3);
455    --l_camp_rec.attribute3 := NVL (l_camp_rec.attribute3, l_reference_rec.attribute3);
456 
457    AMS_CpyUtility_PVT.get_column_value ('attribute4', p_copy_columns_table, l_camp_rec.attribute4);
458    --l_camp_rec.attribute4 := NVL (l_camp_rec.attribute1, l_reference_rec.attribute4);
459 
460    AMS_CpyUtility_PVT.get_column_value ('attribute5', p_copy_columns_table, l_camp_rec.attribute5);
461    --l_camp_rec.attribute5 := NVL (l_camp_rec.attribute5, l_reference_rec.attribute5);
462 
463    AMS_CpyUtility_PVT.get_column_value ('attribute6', p_copy_columns_table, l_camp_rec.attribute6);
464    --l_camp_rec.attribute6 := NVL (l_camp_rec.attribute6, l_reference_rec.attribute6);
465 
466    AMS_CpyUtility_PVT.get_column_value ('attribute7', p_copy_columns_table, l_camp_rec.attribute7);
467    --l_camp_rec.attribute7 := NVL (l_camp_rec.attribute7, l_reference_rec.attribute7);
468 
469    AMS_CpyUtility_PVT.get_column_value ('attribute8', p_copy_columns_table, l_camp_rec.attribute8);
470    --l_camp_rec.attribute8 := NVL (l_camp_rec.attribute8, l_reference_rec.attribute8);
471 
472    AMS_CpyUtility_PVT.get_column_value ('attribute9', p_copy_columns_table, l_camp_rec.attribute9);
473    --l_camp_rec.attribute9 := NVL (l_camp_rec.attribute9, l_reference_rec.attribute9);
474 
475    AMS_CpyUtility_PVT.get_column_value ('attribute10', p_copy_columns_table, l_camp_rec.attribute10);
476    --l_camp_rec.attribute10 := NVL (l_camp_rec.attribute10, l_reference_rec.attribute10);
477 
478    AMS_CpyUtility_PVT.get_column_value ('attribute11', p_copy_columns_table, l_camp_rec.attribute11);
479    --l_camp_rec.attribute11 := NVL (l_camp_rec.attribute11, l_reference_rec.attribute11);
480 
481    AMS_CpyUtility_PVT.get_column_value ('attribute12', p_copy_columns_table, l_camp_rec.attribute12);
482    --l_camp_rec.attribute12 := NVL (l_camp_rec.attribute12, l_reference_rec.attribute12);
483 
484    AMS_CpyUtility_PVT.get_column_value ('attribute13', p_copy_columns_table, l_camp_rec.attribute13);
485    --l_camp_rec.attribute13 := NVL (l_camp_rec.attribute13, l_reference_rec.attribute13);
486 
487    AMS_CpyUtility_PVT.get_column_value ('attribute14', p_copy_columns_table, l_camp_rec.attribute14);
488    --l_camp_rec.attribute14 := NVL (l_camp_rec.attribute14, l_reference_rec.attribute14);
489 
490    AMS_CpyUtility_PVT.get_column_value ('attribute15', p_copy_columns_table, l_camp_rec.attribute15);
491    --l_camp_rec.attribute15 := NVL (l_camp_rec.attribute15, l_reference_rec.attribute15);
492    /* mayjain 8-Aug-2005 */
493    /* changes foe R12 */
494 
495    -- ----------------------------
496    -- call create api
497    -- ----------------------------
498      ams_campaign_pub.create_campaign( p_api_version,
499        p_init_msg_list,
500        -- Bug fix: 2081684
501        -- p_commit,
502        FND_API.G_FALSE,
503        -- End Bug fix: 2081684
504        p_validation_level,
505        x_return_status,
506        x_msg_count,
507        x_msg_data,
508        l_camp_rec,
509        l_new_campaign_id );
510 
511    --WRITE_TO_ACT_LOG('new campaign created successfully','CAMP',1111);
512 
513    IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
514        RAISE FND_API.G_EXC_ERROR;
515    END IF;
516 
517    -- Attributes:
518    -- Access???
519    -- Messages        MESG
520    -- Attachments     ATCH
521    -- Products        PROD
522    -- Geo Area
523    -- Association
524    -- Market Segments         CELL
525    -- Tasks        TASK
526    -- Partners        PTNR
527    -- Schedules
528    -- Subcamp
529 
530    --WRITE_TO_ACT_LOG('Copy Sched Attrib'|| AMS_CpyUtility_PVT.is_copy_attribute ('CSCH', p_attributes_table), 'CAMP',1111);
531 
532    IF AMS_CpyUtility_PVT.is_copy_attribute ('CSCH', p_attributes_table) = FND_API.G_TRUE
533    THEN
534       IF ams_cpyutility_pvt.check_attrib_exists('CAMP', p_source_object_id ,'CSCH') = FND_API.G_TRUE -- Bug fix: 2081684
535       THEN
536       --Following code is modified by rrajesh on 08/31/01.
537       --To copy selected schedules
538       /*ams_copyelements_pvt.copy_act_schedules
539                               ( p_old_camp_id    =>   p_source_object_id,
540                                 p_new_camp_id    =>   l_new_campaign_id,
541                                 p_new_start_date =>   l_camp_rec.actual_exec_start_date,
542                                 x_return_status  =>   l_return_status,
543                                 x_msg_count      =>   l_msg_count,
544                                 x_msg_data       =>   l_msg_data );*/
545 
546        -- Get the Schedule Ids as comma separated variables.
547        IF (AMS_DEBUG_HIGH_ON) THEN
548 
549            AMS_UTILITY_PVT.debug_message('Getting scheduleid values');
550        END IF;
551        AMS_CpyUtility_PVT.get_column_value ('scheduleIdRec', p_copy_columns_table, x_schedule_ids);
552        l_schedule_ids := NVL (x_schedule_ids, '');
553 
554        IF (AMS_DEBUG_HIGH_ON) THEN
555 
556 
557 
558            AMS_UTILITY_PVT.debug_message('scheduleId Rec:' || l_schedule_ids ||';');
559 
560        END IF;
561 
562 	   -- added by soagrawa on 19-aug-2002
563 	   --if l_schedule_ids = 'undefined'
564 	   --then l_schedule_ids := '';
565 	   --end if;
566 
567        IF (AMS_DEBUG_HIGH_ON) THEN
568 
569 
570 
571            AMS_UTILITY_PVT.debug_message('scheduleId Rec:' || l_schedule_ids ||';');
572 
573        END IF;
574 
575        --WRITE_TO_ACT_LOG('Schedule Id Rec:'|| l_schedule_ids ,'CAMP',1111);
576 
577 
578 
579        -- Separate comma separated l_schedule_ids to number values and use for copy
580        l_counter := 0;
581 
582              LOOP
583                  l_length := nvl(LENGTH(nvl(l_schedule_ids,'')),0);
584                  EXIT WHEN l_length = 0;
585                  l_index := INSTR(l_schedule_ids,',');
586 
587                  --WRITE_TO_ACT_LOG('index:'|| l_index ,'CAMP',1111);
588                  IF l_index = 0 THEN
589                     IF  l_length > 0 THEN
590                        l_tmp_schedule_id := TO_NUMBER(l_schedule_ids);
591                        l_schedule_ids := '';
592                     END IF;
593                  ELSE
594                     l_str_schedule_id := SUBSTR(l_schedule_ids, 1, l_index-1);
595                     l_tmp_schedule_id := TO_NUMBER(l_str_schedule_id);
596                  END IF;
597                  IF l_tmp_schedule_id IS NOT NULL
598                  THEN
599                     --WRITE_TO_ACT_LOG('calling schedule copy for schedule id:' || l_tmp_schedule_id ,'CAMP',1111);
600                     IF (AMS_DEBUG_HIGH_ON) THEN
601 
602                         AMS_UTILITY_PVT.debug_message('calling schedule copy for schedule id:' || l_tmp_schedule_id);
603                     END IF;
604                     ams_copyelements_pvt.copy_selected_schedule
605                                     ( p_old_camp_id    =>   p_source_object_id,
606                                       p_new_camp_id    =>   l_new_campaign_id,
607                                       p_old_schedule_id=>   l_tmp_schedule_id,
608                                       p_new_start_date =>   l_camp_rec.actual_exec_start_date,
609                                       p_new_end_date   =>   l_camp_rec.actual_exec_end_date,
610                                       x_return_status  =>   l_return_status,
611                                       x_msg_count      =>   l_msg_count,
612                                       x_msg_data       =>   l_msg_data );
613                     --WRITE_TO_ACT_LOG('return status from ams_copyelements_pvt.copy_campaign_schedules'||x_return_status||':'||l_new_schedule_id,'CAMP',1111);
614                  END IF;
615                  -- EXIT WHEN LENGTH(l_schedule_ids) = 0;
616                  l_schedule_ids := SUBSTR(l_schedule_ids, l_index+1);
617                  l_counter := l_counter + 1;
618              END LOOP;
619              -- end modification. 08/31/01
620 
621    END IF; -- Bug fix: 2081684
622 
623    END IF;
624    --WRITE_TO_ACT_LOG('schedules copied succesfully','CAMP',1111);
625    IF AMS_CpyUtility_PVT.is_copy_attribute ('MESG', p_attributes_table) = FND_API.G_TRUE
626    THEN
627       IF ams_cpyutility_pvt.check_attrib_exists('CAMP', p_source_object_id ,'MESG') = FND_API.G_TRUE -- Bug fix: 2081684
628       THEN
629       ams_copyelements_pvt.copy_act_messages
630                               ( p_src_act_type  =>'CAMP',
631                                 p_src_act_id    =>p_source_object_id,
632                                 p_new_act_id    =>l_new_campaign_id,
633                                 p_errnum        =>l_errnum,
634                                 p_errcode       =>l_errcode,
635                                 p_errmsg        =>l_errmsg);
636       END IF;
637    END IF;
638    IF AMS_CpyUtility_PVT.is_copy_attribute ('ATCH', p_attributes_table) = FND_API.G_TRUE
639    THEN
640       -- modified by soagrawa on 31-jan-2002   bug#  2207969
641       IF ams_cpyutility_pvt.check_attrib_exists('AMS_CAMP', p_source_object_id ,'ATCH') = FND_API.G_TRUE -- Bug fix: 2081684
642       -- IF ams_cpyutility_pvt.check_attrib_exists('CAMP', p_source_object_id ,'ATCH') = FND_API.G_TRUE -- Bug fix: 2081684
643       THEN
644       -- Modified by rrajesh on 10/18/01
645       /*ams_copyelements_pvt.copy_act_attachments
646                               ( p_src_act_type  =>'CAMP',
647                                 p_src_act_id    =>p_source_object_id,
648                                 p_new_act_id    =>l_new_campaign_id,
649                                 p_errnum        =>l_errnum,
650                                 p_errcode       =>l_errcode,
651                                 p_errmsg        =>l_errmsg); */
652       ams_copyelements_pvt.copy_act_attachments
653                               ( p_src_act_type  =>'AMS_CAMP',
654                                 p_src_act_id    =>p_source_object_id,
655                                 p_new_act_id    =>l_new_campaign_id,
656                                 p_errnum        =>l_errnum,
657                                 p_errcode       =>l_errcode,
658                                 p_errmsg        =>l_errmsg);
659       -- end change 10/18/01
660       END IF;
661    END IF;
662    -- Added by rrajesh on 10/18/01
663    IF AMS_CpyUtility_PVT.is_copy_attribute ('GEOS', p_attributes_table) = FND_API.G_TRUE
664    THEN
665        IF ams_cpyutility_pvt.check_attrib_exists('CAMP', p_source_object_id ,'GEOS') = FND_API.G_TRUE -- Bug fix: 2081684
666        THEN
667        ams_copyelements_pvt.copy_act_geo_areas
668                             ( p_src_act_type   => 'CAMP',
669                               p_src_act_id     => p_source_object_id,
670                               p_new_act_id     => l_new_campaign_id,
671                               p_errnum         => l_errnum,
672                               p_errcode        => l_errcode,
673                               p_errmsg         => l_errmsg);
674        END IF;
675    END IF;
676    IF AMS_CpyUtility_PVT.is_copy_attribute ('DELV', p_attributes_table) = FND_API.G_TRUE
677    THEN
678        IF ams_cpyutility_pvt.check_attrib_exists('CAMP', p_source_object_id ,'DELV') = FND_API.G_TRUE -- Bug fix: 2081684
679        THEN
680        ams_copyelements_pvt.copy_object_associations
681                             ( p_src_act_type   => 'CAMP',
682                               p_src_act_id     =>p_source_object_id,
683                               p_new_act_id     =>l_new_campaign_id,
684                               p_errnum         => l_errnum,
685                               p_errcode        => l_errcode,
686                               p_errmsg         => l_errmsg);
687        END IF;
688    END IF;
689 
690    -- end change 10/18/01
691    IF AMS_CpyUtility_PVT.is_copy_attribute ('PROD', p_attributes_table) = FND_API.G_TRUE
692    THEN
693        IF ams_cpyutility_pvt.check_attrib_exists('CAMP', p_source_object_id ,'PROD') = FND_API.G_TRUE -- Bug fix: 2081684
694        THEN
695        ams_copyelements_pvt.copy_act_prod
696                             ( p_src_act_type   => 'CAMP',
697                               p_src_act_id     =>p_source_object_id,
698                               p_new_act_id     =>l_new_campaign_id,
699                               p_errnum         => l_errnum,
700                               p_errcode        => l_errcode,
701                               p_errmsg         => l_errmsg);
702        END IF;
703    END IF;
704    IF AMS_CpyUtility_PVT.is_copy_attribute ('CELL', p_attributes_table) = FND_API.G_TRUE
705    THEN
706        IF ams_cpyutility_pvt.check_attrib_exists('CAMP', p_source_object_id ,'CELL') = FND_API.G_TRUE -- Bug fix: 2081684
707        THEN
708        ams_copyelements_pvt.copy_act_market_segments
709                                      ( p_src_act_type =>'CAMP',
710                                        p_src_act_id   =>p_source_object_id,
711                                        p_new_act_id   =>l_new_campaign_id,
712                                        p_errnum       =>l_errnum,
713                                        p_errcode      =>l_errcode,
714                                        p_errmsg       =>l_errmsg);
715       END IF;
716    END IF;
717    IF AMS_CpyUtility_PVT.is_copy_attribute ('PTNR', p_attributes_table) = FND_API.G_TRUE
718    THEN
719         IF ams_cpyutility_pvt.check_attrib_exists('CAMP', p_source_object_id ,'PTNR') = FND_API.G_TRUE -- Bug fix: 2081684
720         THEN
721         -- Bug fix:2072789
722         /*ams_copyelements_pvt.copy_partners
723                                   (p_init_msg_list        => fnd_api.g_true,
724                                    p_api_version          => l_api_version_number,
725                                    x_return_status        => l_return_status,
726                                    x_msg_count            => l_msg_count,
727                                    x_msg_data             => l_msg_data,
728                                    p_old_camp_id          =>p_source_object_id,
729                                    p_new_camp_id          =>l_new_campaign_id); */
730         ams_copyelements_pvt.copy_partners
731                                   (p_api_version          => l_api_version_number,
732                                    p_init_msg_list        => fnd_api.g_true,
733                                    x_return_status        => l_return_status,
734                                    x_msg_count            => l_msg_count,
735                                    x_msg_data             => l_msg_data,
736                                    p_old_camp_id          =>p_source_object_id,
737                                    p_new_camp_id          =>l_new_campaign_id);
738         -- End fix:fix:2072789
739         END IF;
740    END IF;
741 
742    OPEN fetch_camp_details(l_new_campaign_id);
743    FETCH fetch_camp_details INTO l_new_reference_rec;
744    CLOSE fetch_camp_details;
745 
746    x_new_object_id    := l_new_campaign_id;
747    x_custom_setup_id  := l_new_reference_rec.custom_setup_id;
748 
749 
750    IF FND_API.to_Boolean( p_commit )
751    THEN
752       COMMIT WORK;
753    END IF;
754 
755    -- Debug Message
756    IF (AMS_DEBUG_HIGH_ON) THEN
757 
758        AMS_UTILITY_PVT.debug_message('Private API: ' || l_api_name || 'end');
759    END IF;
760 
761    -- Standard call to get message count and if count is 1, get message info.
762    FND_MSG_PUB.Count_And_Get
763         (p_count          =>   x_msg_count,
764          p_data           =>   x_msg_data
765       );
766    --WRITE_TO_ACT_LOG('All attributes copied succesfully','CAMP',1111);
767  EXCEPTION
768    WHEN FND_API.G_EXC_ERROR THEN
769       ROLLBACK TO COPY_Camp_Common_PVT;
770       x_return_status := FND_API.G_RET_STS_ERROR;
771       -- Standard call to get message count and if count=1, get the message
772       FND_MSG_PUB.Count_And_Get (
773              p_encoded => FND_API.G_FALSE,
774              p_count   => x_msg_count,
775              p_data    => x_msg_data
776       );
777    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
778       ROLLBACK TO COPY_Camp_Common_PVT;
779       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
780       -- Standard call to get message count and if count=1, get the message
781       FND_MSG_PUB.Count_And_Get (
782              p_encoded => FND_API.G_FALSE,
783              p_count => x_msg_count,
784              p_data  => x_msg_data
785       );
786    WHEN OTHERS THEN
787       ROLLBACK TO COPY_Camp_Common_PVT;
788       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
789       IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
790          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
791       END IF;
792       -- Standard call to get message count and if count=1, get the message
793       FND_MSG_PUB.Count_And_Get (
794              p_encoded => FND_API.G_FALSE,
795              p_count => x_msg_count,
796              p_data  => x_msg_data
797       );
798 
799 END;
800 -----------------------------------------------------------------------
801    PROCEDURE copy_deliverables(
802       p_api_version         IN       NUMBER,
803       p_init_msg_list       IN       VARCHAR2 := fnd_api.g_false,
804       x_return_status       OUT NOCOPY      VARCHAR2,
805       x_msg_count           OUT NOCOPY      NUMBER,
806       x_msg_data            OUT NOCOPY      VARCHAR2,
807       x_deliverable_id      OUT NOCOPY      NUMBER,
808       p_src_deliv_id        IN       NUMBER,
809       p_new_deliv_name      IN       VARCHAR2,
810       p_new_deliv_code      IN       VARCHAR2 := NULL,
811       p_deli_elements_rec   IN       deli_elements_rec_type,
812       p_new_version         IN       VARCHAR2)
813    IS
814       l_api_version   CONSTANT NUMBER       := 1.0;
815       l_api_name      CONSTANT VARCHAR2(30) := 'copy_deliverable';
816       l_full_name     CONSTANT VARCHAR2(60) := g_pkg_name || '.' || l_api_name;
817       l_return_status          VARCHAR2(1);
818       l_new_deliv_name         ams_deliverables_vl.deliverable_name%TYPE;
819       l_deli_count             NUMBER;
820       l_name                   VARCHAR2(80);
821       l_msg_count              NUMBER;
822       l_msg_data               VARCHAR2(512);
823       l_new_deliv_id           NUMBER;
824       l_deli_rec               ams_deliverable_pvt.deliv_rec_type;
825       l_mesg_text              VARCHAR2(2000);
826       p_errmsg                 VARCHAR2(3000);
827       l_deliv_rec              ams_deliverables_vl%ROWTYPE;
828       l_errcode                VARCHAR2(80);
829       l_errnum                 NUMBER;
830       l_errmsg                 VARCHAR2(3000);
831       l_deliv_count            NUMBER;
832       l_lookup_meaning         VARCHAR2(80);
833       l_counter                NUMBER;
834 
835       CURSOR c_deliv_name(l_deliv_name IN VARCHAR2)
836       IS
837          SELECT COUNT(*)   --deliverable_name
838            FROM ams_deliverables_vl
839           WHERE deliverable_name = l_deliv_name;
840    BEGIN
841       SAVEPOINT copy_deliverables;
842       IF (AMS_DEBUG_HIGH_ON) THEN
843 
844           ams_utility_pvt.debug_message(l_full_name || ': start');
845       END IF;
846 
847       IF fnd_api.to_boolean(p_init_msg_list)
848       THEN
849          fnd_msg_pub.initialize;
850       END IF;
851 
852       IF NOT fnd_api.compatible_api_call(
853             l_api_version,
854             p_api_version,
855             l_api_name,
856             g_pkg_name)
857       THEN
858          RAISE fnd_api.g_exc_unexpected_error;
859       END IF;
860 
861       x_return_status := fnd_api.g_ret_sts_success;
862       ----------------------- insert -----------------------
863       IF (AMS_DEBUG_HIGH_ON) THEN
864 
865           ams_utility_pvt.debug_message(l_full_name || ': copy');
866       END IF;
867 
868       BEGIN
869          ams_utility_pvt.get_lookup_meaning(
870             'AMS_SYS_ARC_QUALIFIER',
871             'DELV',
872             l_return_status,
873             l_lookup_meaning);
874          --  General Message saying copying has started
875          fnd_message.set_name('AMS', 'AMS_COPY_ELEMENTS');
876          fnd_message.set_token('ELEMENTS', l_lookup_meaning, TRUE);
877          l_mesg_text := fnd_message.get;
878          -- Writing to the Pl/SQLtable
879          ams_cpyutility_pvt.write_log_mesg('DELV', p_src_deliv_id,
880                                             l_mesg_text, 'GENERAL');
881          l_return_status := NULL;
882          l_msg_count := 0;
883          l_msg_data := NULL;
884          -- selects the deliverable to copy
885          SELECT *
886            INTO l_deliv_rec
887            FROM ams_deliverables_vl
888          WHERE  deliverable_id = p_src_deliv_id;
889          l_deli_rec.object_version_number := 1;
890          l_deli_rec.owner_user_id := fnd_global.user_id;
891          l_deli_rec.status_date := SYSDATE;
892          l_deli_rec.deliverable_code := p_new_deliv_code;
893          l_deli_rec.version := 1.0;
894          l_deli_rec.language_code := l_deliv_rec.language_code;
895          l_deli_rec.application_id := l_deliv_rec.application_id;
896          l_deli_rec.actual_avail_from_date := l_deliv_rec.actual_avail_from_date;
897          l_deli_rec.actual_avail_to_date := l_deliv_rec.actual_avail_to_date;
898          l_deli_rec.fund_source_id := NULL;   ---functionally cannot copy
899          l_deli_rec.fund_source_type := NULL;   -----functionally cannot copy
900          l_deli_rec.category_type_id := NULL;   ---functionally cannot copy
901          l_deli_rec.category_sub_type_id := NULL;   ---functionally cannot copy
902          l_deli_rec.can_fulfill_electronic_flag := 'N';
903          l_deli_rec.can_fulfill_physical_flag := 'N';
904          l_deli_rec.actual_avail_from_date := NULL;
905          l_deli_rec.actual_avail_to_date := NULL;
906          l_deli_rec.chargeback_amount := NULL;
907          l_deli_rec.chargeback_amount_curr_code := NULL;
908          l_deli_rec.non_inv_quantity_on_hand := NULL;
909          l_deli_rec.non_inv_quantity_on_order := NULL;
910          l_deli_rec.non_inv_quantity_on_reserve := NULL;
911          l_deli_rec.budget_amount_tc := NULL;
912          l_deli_rec.budget_amount_fc := NULL;
913          l_deli_rec.actual_cost := NULL;
914          l_deli_rec.deliverable_pick_flag := 'N';
915          l_deli_rec.actual_responses := NULL;
916          l_deli_rec.inventory_flag := l_deliv_rec.inventory_flag;
917          l_deli_rec.transaction_currency_code :=
918                                   l_deliv_rec.transaction_currency_code;
919          l_deli_rec.functional_currency_code :=
920                                   l_deliv_rec.functional_currency_code;
921          -- if the kit flag is on then copy the flag and copy the kits
922          l_deli_rec.kit_flag := p_deli_elements_rec.p_kitflag;
923          l_deli_rec.inventory_item_id := l_deliv_rec.inventory_item_id;
924          l_deli_rec.inventory_item_org_id := l_deliv_rec.inventory_item_org_id;
925          l_deli_rec.non_inv_ctrl_code := l_deliv_rec.non_inv_ctrl_code;
926          l_deli_rec.currency_code := l_deliv_rec.currency_code;
927          l_deli_rec.forecasted_cost := l_deliv_rec.forecasted_cost;
928          l_deli_rec.forecasted_responses := l_deliv_rec.forecasted_responses;
929          l_deli_rec.country := l_deliv_rec.country;
930          l_deli_rec.attribute_category := l_deliv_rec.attribute_category;
931          l_deli_rec.attribute1 := l_deliv_rec.attribute1;
932          l_deli_rec.attribute2 := l_deliv_rec.attribute2;
933          l_deli_rec.attribute3 := l_deliv_rec.attribute3;
934          l_deli_rec.attribute4 := l_deliv_rec.attribute4;
935          l_deli_rec.attribute5 := l_deliv_rec.attribute5;
936          l_deli_rec.attribute6 := l_deliv_rec.attribute6;
937          l_deli_rec.attribute7 := l_deliv_rec.attribute7;
938          l_deli_rec.attribute8 := l_deliv_rec.attribute8;
939          l_deli_rec.attribute9 := l_deliv_rec.attribute9;
940          l_deli_rec.attribute10 := l_deliv_rec.attribute10;
941          l_deli_rec.attribute11 := l_deliv_rec.attribute11;
942          l_deli_rec.attribute12 := l_deliv_rec.attribute12;
943          l_deli_rec.attribute13 := l_deliv_rec.attribute13;
944          l_deli_rec.attribute14 := l_deliv_rec.attribute14;
945          l_deli_rec.attribute15 := l_deliv_rec.attribute15;
946 
947          -- checks if deliv name is  null
948          IF p_new_deliv_name IS NULL
949          THEN
950             fnd_message.set_name('AMS', 'AMS_COPY_NAME');
951             l_new_deliv_name := fnd_message.get;
952             l_new_deliv_name :=
953                                SUBSTRB(l_new_deliv_name ||
954                                        l_deliv_rec.deliverable_name, 1, 240);
955          ELSE
956             l_new_deliv_name := p_new_deliv_name;
957          END IF;
958          -- checks if deilv of that name exists-------
959          l_counter := 0;
960 
961          LOOP
962             l_counter := l_counter + 1;
963             OPEN c_deliv_name(l_new_deliv_name);
964             FETCH c_deliv_name INTO l_deliv_count;
965             EXIT WHEN l_deliv_count = 0;
966             l_deli_rec.deliverable_name :=
967                SUBSTRB(l_new_deliv_name || '-' || l_counter, 1, 240);
968             l_new_deliv_name := l_deli_rec.deliverable_name;
969             CLOSE c_deliv_name;
970          END LOOP;
971 ---- IF DELIV NAME IS NEW THEN PUT THAT ---------------------------
972          l_deli_rec.deliverable_name := SUBSTR(l_new_deliv_name, 1, 240);
973 -------------calling create delivrable-------------
974          ams_deliverable_pvt.create_deliverable(
975             p_api_version => l_api_version,
976             x_return_status => l_return_status,
977             x_msg_count => l_msg_count,
978             x_msg_data => l_msg_data,
979             x_deliv_id => l_new_deliv_id,
980             p_deliv_rec => l_deli_rec);
981          x_deliverable_id := l_new_deliv_id;
982 
983          IF l_return_status = fnd_api.g_ret_sts_error
984              OR l_return_status = fnd_api.g_ret_sts_unexp_error
985          THEN
986             FOR l_counter IN 1 .. l_msg_count
987             LOOP
988               l_mesg_text := fnd_msg_pub.get(p_encoded => fnd_api.g_false);
989               p_errmsg := SUBSTR( l_mesg_text || ',): ' || l_counter ||
990                                  ' OF ' || l_msg_count, 1, 3000);
991               ams_cpyutility_pvt.write_log_mesg( 'DELV',
992                                                  p_src_deliv_id,
993                                                  p_errmsg,
994                                                  'ERROR');
995             END LOOP;
996             fnd_message.set_name('AMS', 'AMS_COPY_ERROR2');
997             fnd_message.set_token('ELEMENTS', l_lookup_meaning, TRUE);
998             l_mesg_text := fnd_message.get;
999             p_errmsg := SUBSTR( l_mesg_text || ' - ' ||
1000                                 ams_utility_pvt.get_object_name( 'DELV',
1001                                                  l_deli_rec.deliverable_id),
1002                                 1, 4000);
1003             ams_cpyutility_pvt.write_log_mesg('DELV',
1004                                          p_src_deliv_id, p_errmsg, 'ERROR');
1005             IF l_return_status = fnd_api.g_ret_sts_error  then
1006                RAISE fnd_api.g_exc_error;
1007             ELSE
1008                RAISE fnd_api.g_exc_unexpected_error;
1009             END IF;
1010          END IF;
1011       END;
1012 
1013       IF x_return_status = fnd_api.g_ret_sts_success
1014       THEN
1015          IF p_deli_elements_rec.p_attachments = 'Y'
1016          THEN
1017             l_errcode := NULL;
1018             l_errnum := 0;
1019             l_errmsg := NULL;
1020             ams_copyelements_pvt.copy_act_attachments(
1021                         p_src_act_type => 'DELV',
1022                         p_src_act_id   => p_src_deliv_id,
1023                         p_new_act_id   => l_new_deliv_id,
1024                         p_errnum       => l_errnum,
1025                         p_errcode      => l_errcode,
1026                         p_errmsg       => l_errmsg);
1027          END IF;
1028 -- If the user wants to copy access then the access flag should be 'Y' (Yes)
1029          IF p_deli_elements_rec.p_products = 'Y'
1030          THEN
1031             l_errcode := NULL;
1032             l_errnum := 0;
1033             l_errmsg := NULL;
1034 
1035             ams_copyelements_pvt.copy_act_prod(
1036                          p_src_act_type => 'DELV',
1037                          p_src_act_id   => p_src_deliv_id,
1038                          p_new_act_id   => l_new_deliv_id,
1039                          p_errnum       => l_errnum,
1040                          p_errcode      => l_errcode,
1041                          p_errmsg       => l_errmsg);
1042          END IF;
1043 -- If the user wants to copy access then the access flag should be 'Y' (Yes)
1044 
1045          IF p_deli_elements_rec.p_access = 'Y'
1046          THEN
1047             l_errcode := NULL;
1048             l_errnum := 0;
1049             l_errmsg := NULL;
1050             ams_copyelements_pvt.copy_act_access(
1051                      p_src_act_type => 'DELV',
1052                      p_src_act_id   => p_src_deliv_id,
1053                      p_new_act_id   => l_new_deliv_id,
1054                      p_errnum       => l_errnum,
1055                      p_errcode      => l_errcode,
1056                      p_errmsg       => l_errmsg);
1057       END IF;
1058 
1059          IF p_deli_elements_rec.p_kitflag = 'Y'
1060          THEN
1061             l_errcode := NULL;
1062             l_errnum := 0;
1063             l_errmsg := NULL;
1064             ams_copyelements_pvt.copy_deliv_kits( p_src_deliv_id,
1065                                       l_new_deliv_id,
1066                                       l_errnum,
1067                                       l_errcode,
1068                                       l_errmsg);
1069          END IF;
1070          -- If the user wants to copy geo_areas then the geo_area flag
1071          -- should be 'Y' (Yes)
1072          IF p_deli_elements_rec.p_geo_areas = 'Y'
1073          THEN
1074             l_errcode := NULL;
1075             l_errnum := 0;
1076             l_errmsg := NULL;
1077             ams_copyelements_pvt.copy_act_geo_areas(
1078                       p_src_act_type => 'DELV',
1079                       p_src_act_id   => p_src_deliv_id,
1080                       p_new_act_id   => l_new_deliv_id,
1081                       p_errnum       => l_errnum,
1082                       p_errcode      => l_errcode,
1083                       p_errmsg       => l_errmsg);
1084           END IF;
1085           -- If the user wants to copy object_associatiosn then the
1086           -- obj_asso flag should be 'Y' (Yes).It will copy all the
1087           -- associations of the deliverable
1088          IF p_deli_elements_rec.p_obj_asso = 'Y'
1089          THEN
1090             l_errcode := NULL;
1091             l_errnum := 0;
1092             l_errmsg := NULL;
1093             ams_copyelements_pvt.copy_object_associations(
1094                       p_src_act_type => 'DELV',
1095                       p_src_act_id   => p_src_deliv_id,
1096                       p_new_act_id   => l_new_deliv_id,
1097                       p_errnum       => l_errnum,
1098                       p_errcode      => l_errcode,
1099                       p_errmsg       => l_errmsg);
1100          END IF;
1101       END IF;
1102 
1103       IF   l_return_status  =  FND_API.G_RET_STS_SUCCESS  THEN
1104          COMMIT ;
1105       END IF ;
1106 
1107       IF (AMS_DEBUG_HIGH_ON) THEN
1108 
1109 
1110 
1111           ams_utility_pvt.debug_message(l_full_name || ': end');
1112 
1113       END IF;
1114    EXCEPTION
1115       WHEN fnd_api.g_exc_error
1116       THEN
1117          ROLLBACK TO copy_deliverables;
1118          x_return_status := fnd_api.g_ret_sts_error;
1119          fnd_msg_pub.count_and_get(
1120             p_encoded => fnd_api.g_false,
1121             p_count => x_msg_count,
1122             p_data => x_msg_data);
1123       WHEN fnd_api.g_exc_unexpected_error
1124       THEN
1125          ROLLBACK TO copy_deliverables;
1126          x_return_status := fnd_api.g_ret_sts_unexp_error;
1127          fnd_msg_pub.count_and_get(
1128             p_encoded => fnd_api.g_false,
1129             p_count => x_msg_count,
1130             p_data => x_msg_data);
1131       WHEN OTHERS
1132       THEN
1133          ROLLBACK TO copy_deliverables;
1134          x_return_status := fnd_api.g_ret_sts_unexp_error;
1135 
1136          IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
1137          THEN
1138             fnd_msg_pub.add_exc_msg(g_pkg_name, l_api_name);
1139          END IF;
1140 
1141          fnd_msg_pub.count_and_get(
1142             p_encoded => fnd_api.g_false,
1143             p_count => x_msg_count,
1144             p_data => x_msg_data);
1145    END copy_deliverables;
1146 
1147 
1148 
1149    PROCEDURE copy_event_offer(
1150       p_api_version         IN       NUMBER,
1151       p_init_msg_list       IN       VARCHAR2 := fnd_api.g_false,
1152       x_return_status       OUT NOCOPY      VARCHAR2,
1153       x_msg_count           OUT NOCOPY      NUMBER,
1154       x_msg_data            OUT NOCOPY      VARCHAR2,
1155       x_eveo_id             OUT NOCOPY      NUMBER,
1156       p_src_eveo_id         IN       NUMBER,
1157       p_event_header_id     IN       NUMBER,
1158       p_new_eveo_name       IN       VARCHAR2 := NULL,
1159       p_par_eveo_id         IN       NUMBER := NULL,
1160       p_eveo_elements_rec   IN       eveo_elements_rec_type,
1161       p_start_date          IN       DATE := NULL,
1162       p_end_date            IN       DATE := NULL,
1163       p_source_code         IN       VARCHAR2 := NUll)
1164    IS
1165       l_api_version   CONSTANT NUMBER       := 1.0;
1166       l_api_name      CONSTANT VARCHAR2(30) := 'copy_event_offer';
1167       l_full_name     CONSTANT VARCHAR2(60) := g_pkg_name || '.' || l_api_name;
1168       l_return_status          VARCHAR2(1);
1169       l_eveo_ele_rec           eveo_elements_rec_type;
1170       l_name                   VARCHAR2(80);
1171       l_msg_count              NUMBER;
1172       l_msg_data               VARCHAR2(512);
1173       --   l_new_camp_id  NUMBER;
1174       l_eveo_rec               ams_eventoffer_pvt.evo_rec_type;
1175       l_mesg_text              VARCHAR2(2000);
1176       p_errmsg                 VARCHAR2(3000);
1177       l_eventoffer_rec         ams_event_offers_vl%ROWTYPE;
1178       l_errcode                VARCHAR2(80);
1179       l_errnum                 NUMBER;
1180       l_errmsg                 VARCHAR2(3000);
1181       l_eveo_elements_rec      eveo_elements_rec_type;
1182       x_sub_eveo_id            NUMBER;
1183       l_new_eveo_name          ams_event_offers_vl.event_offer_name%TYPE;
1184       l_eveo_count             NUMBER;
1185       l_lookup_meaning         VARCHAR2(80);
1186       l_counter                NUMBER;
1187       l_date_number            NUMBER;
1188       l_custom_setup_id        NUMBER;
1189 
1190       CURSOR sub_eveo_cur
1191       IS
1192          SELECT   event_offer_id
1193          FROM     ams_event_offers_vl
1194          WHERE  parent_event_offer_id = p_src_eveo_id;
1195 
1196       CURSOR c_eveo_name(l_eveo_name IN VARCHAR2)
1197       IS
1198 --	 modified by dhsingh on 20.05.2004 for bug# 3631107
1199 --         SELECT   COUNT(*)
1200 --         FROM     ams_event_offers_vl
1201 --         WHERE  event_offer_name = l_eveo_name;
1202 	SELECT   COUNT(*)
1203 	FROM     ams_event_offers_all_tl
1204 	WHERE  event_offer_name = l_eveo_name;
1205 --	end of modification by dhsingh
1206 
1207       CURSOR c_obj_attr
1208       IS
1209          SELECT   custom_setup_id
1210          FROM     ams_object_attributes
1211          WHERE  object_id = p_src_eveo_id
1212             AND object_type = 'EVEO';
1213    BEGIN
1214       SAVEPOINT copy_event_offer;
1215       IF (AMS_DEBUG_HIGH_ON) THEN
1216 
1217           ams_utility_pvt.debug_message(l_full_name || ': start');
1218       END IF;
1219 
1220       IF fnd_api.to_boolean(p_init_msg_list)
1221       THEN
1222          fnd_msg_pub.initialize;
1223       END IF;
1224 
1225       IF NOT fnd_api.compatible_api_call(
1226             l_api_version,
1227             p_api_version,
1228             l_api_name,
1229             g_pkg_name)
1230       THEN
1231          RAISE fnd_api.g_exc_unexpected_error;
1232       END IF;
1233 
1234       x_return_status := fnd_api.g_ret_sts_success;
1235       ----------------------- insert -----------------------
1236       IF (AMS_DEBUG_HIGH_ON) THEN
1237 
1238           ams_utility_pvt.debug_message(l_full_name || ': start');
1239       END IF;
1240 
1241       BEGIN
1242          ams_utility_pvt.get_lookup_meaning(
1243             'AMS_SYS_ARC_QUALIFIER',
1244             'EVEO',
1245             l_return_status,
1246             l_lookup_meaning);
1247 --  General Message saying copying has started
1248          fnd_message.set_name('AMS', 'AMS_COPY_ELEMENTS');
1249          fnd_message.set_token('ELEMENTS', l_lookup_meaning, TRUE);
1250          l_mesg_text := fnd_message.get;
1251 -- Writing to the Pl/SQLtable
1252          ams_cpyutility_pvt.write_log_mesg('EVEO', p_src_eveo_id, l_mesg_text, 'GENERAL');
1253          l_return_status := NULL;
1254          l_msg_count := 0;
1255          l_msg_data := NULL;
1256 -- selects the event offers to copy
1257          SELECT   *
1258          INTO     l_eventoffer_rec
1259          FROM     ams_event_offers_vl
1260          WHERE  event_offer_id = p_src_eveo_id;
1261          l_eveo_rec.object_version_number := 2; -- Bug 5171873 cannot be 1
1262 
1263          l_eveo_rec.application_id := l_eventoffer_rec.application_id;
1264          l_eveo_rec.event_header_id := p_event_header_id;
1265          l_eveo_rec.private_flag := l_eventoffer_rec.private_flag;
1266 
1267          IF p_par_eveo_id IS NULL
1268          THEN
1269             l_eveo_rec.event_level := 'MAIN';
1270          ELSE
1271             l_eveo_rec.event_level := 'SUB';
1272          END IF;
1273 
1274          l_eveo_rec.user_status_id := 100;
1275          l_eveo_rec.system_status_code := 'NEW';
1276          l_eveo_rec.event_type_code := l_eventoffer_rec.event_type_code;
1277          l_eveo_rec.event_delivery_method_id :=
1278                                       l_eventoffer_rec.event_delivery_method_id;
1279          l_eveo_rec.event_required_flag := l_eventoffer_rec.event_required_flag;
1280          l_eveo_rec.event_language_code := l_eventoffer_rec.event_language_code;
1281          l_eveo_rec.event_location_id := l_eventoffer_rec.event_location_id;
1282          l_eveo_rec.overflow_flag := l_eventoffer_rec.overflow_flag;
1283          l_eveo_rec.partner_flag := l_eventoffer_rec.partner_flag;
1284          l_eveo_rec.event_standalone_flag :=
1285                                       l_eventoffer_rec.event_standalone_flag;
1286          l_eveo_rec.reg_required_flag := 'Y';
1287                                        --l_eventoffer_rec.reg_required_flag;
1288          l_eveo_rec.reg_charge_flag := l_eventoffer_rec.reg_charge_flag;
1289          l_eveo_rec.reg_invited_only_flag :=
1290                                       l_eventoffer_rec.reg_invited_only_flag;
1291          l_eveo_rec.reg_waitlist_allowed_flag :=
1292             l_eventoffer_rec.reg_waitlist_allowed_flag;
1293          l_eveo_rec.reg_overbook_allowed_flag :=
1294             l_eventoffer_rec.reg_overbook_allowed_flag;
1295          l_eveo_rec.parent_event_offer_id := p_par_eveo_id;
1296          l_eveo_rec.event_duration := l_eventoffer_rec.event_duration;
1297          l_eveo_rec.event_duration_uom_code :=
1298                               l_eventoffer_rec.event_duration_uom_code;
1299 
1300          IF p_start_date IS NOT NULL
1301          THEN
1302             l_eveo_rec.event_start_date := p_start_date;
1303          END IF;
1304 
1305          l_date_number :=
1306             ams_cpyutility_pvt.get_dates('EVEO',
1307                                          p_src_eveo_id, l_return_status);
1308 
1309          IF l_eventoffer_rec.event_end_date IS NOT NULL
1310          THEN
1311             l_eveo_rec.event_end_date := p_start_date + l_date_number;
1312          END IF;
1313 
1314          l_eveo_rec.event_start_date_time :=
1315                          l_eventoffer_rec.event_start_date_time;
1316          l_eveo_rec.event_end_date_time := l_eventoffer_rec.event_end_date_time;
1317          l_eveo_rec.reg_maximum_capacity :=
1318                           l_eventoffer_rec.reg_maximum_capacity;
1319          l_eveo_rec.reg_overbook_pct := l_eventoffer_rec.reg_overbook_pct;
1320          l_eveo_rec.reg_effective_capacity :=
1321                               l_eventoffer_rec.reg_effective_capacity;
1322          l_eveo_rec.reg_waitlist_pct := l_eventoffer_rec.reg_waitlist_pct;
1323          l_eveo_rec.reg_minimum_capacity :=
1324                           l_eventoffer_rec.reg_minimum_capacity;
1325          -- l_eveo_rec.REG_MINIMUM_REQ_BY_DATE   DATE,
1326          -- l_eveo_rec.INVENTORY_ITEM_ID         NUMBER,
1327          l_eveo_rec.organization_id := l_eventoffer_rec.organization_id;
1328          -- l_eveo_rec.PRICELIST_HEADER_ID       NUMBER,
1329          -- l_eveo_rec.PRICELIST_LINE_ID         NUMBER,
1330          l_eveo_rec.org_id := l_eventoffer_rec.org_id;
1331          l_eveo_rec.waitlist_action_type_code :=
1332             l_eventoffer_rec.waitlist_action_type_code;
1333          l_eveo_rec.stream_type_code := l_eventoffer_rec.stream_type_code;
1334          -- l_eveo_rec.owner_user_id :=     l_eventoffer_rec.owner_user_id;
1335          l_eveo_rec.owner_user_id :=
1336 			AMS_Utility_PVT.get_resource_id (FND_GLOBAL.user_id);
1337        -- changed again because eventsAPI has chaged--101;
1338 
1339          l_eveo_rec.event_full_flag := 'N';
1340          l_eveo_rec.source_code := p_source_code;
1341         -- l_eveo_rec.FORECASTED_REVENUE
1342         -- l_eveo_rec.ACTUAL_REVENUE
1343         -- l_eveo_rec.FORECASTED_COST
1344         -- l_eveo_rec.ACTUAL_COST
1345         -- l_eveo_rec.FUND_SOURCE_TYPE_CODE
1346         -- l_eveo_rec.FUND_SOURCE_ID
1347          l_eveo_rec.cert_credit_type_code :=
1348                          l_eventoffer_rec.cert_credit_type_code;
1349          l_eveo_rec.certification_credits :=
1350                          l_eventoffer_rec.certification_credits;
1351          l_eveo_rec.coordinator_id := l_eventoffer_rec.coordinator_id;
1352          l_eveo_rec.priority_type_code := l_eventoffer_rec.priority_type_code;
1353          -- l_eveo_rec.CANCELLATION_REASON_CODE
1354          l_eveo_rec.auto_register_flag := l_eventoffer_rec.auto_register_flag;
1355          l_eveo_rec.email := l_eventoffer_rec.email;
1356          l_eveo_rec.phone := l_eventoffer_rec.phone;
1357          -- l_eveo_rec.FUND_AMOUNT_TC            NUMBER,
1358          -- l_eveo_rec.FUND_AMOUNT_FC            NUMBER,
1359          -- l_eveo_rec.CURRENCY_CODE_TC          VARCHAR2(15),
1360          -- l_eveo_rec.CURRENCY_CODE_FC          VARCHAR2(15),
1361          l_eveo_rec.url := l_eventoffer_rec.url;
1362          l_eveo_rec.timezone_id := l_eventoffer_rec.timezone_id;
1363          l_eveo_rec.event_venue_id := l_eventoffer_rec.event_venue_id;
1364          -- l_eveo_rec.PRICELIST_HEADER_CURRENCY_CODE VARCHAR2(30),
1365          -- l_eveo_rec.PRICELIST_LIST_PRICE     NUMBER,
1366          l_eveo_rec.inbound_script_name := l_eventoffer_rec.inbound_script_name;
1367          l_eveo_rec.attribute_category := l_eventoffer_rec.attribute_category;
1368          l_eveo_rec.attribute1 := l_eventoffer_rec.attribute1;
1369          l_eveo_rec.attribute2 := l_eventoffer_rec.attribute2;
1370          l_eveo_rec.attribute3 := l_eventoffer_rec.attribute3;
1371          l_eveo_rec.attribute4 := l_eventoffer_rec.attribute4;
1372          l_eveo_rec.attribute5 := l_eventoffer_rec.attribute5;
1373          l_eveo_rec.attribute6 := l_eventoffer_rec.attribute6;
1374          l_eveo_rec.attribute7 := l_eventoffer_rec.attribute7;
1375          l_eveo_rec.attribute8 := l_eventoffer_rec.attribute8;
1376          l_eveo_rec.attribute9 := l_eventoffer_rec.attribute9;
1377          l_eveo_rec.attribute10 := l_eventoffer_rec.attribute10;
1378          l_eveo_rec.attribute11 := l_eventoffer_rec.attribute11;
1379          l_eveo_rec.attribute12 := l_eventoffer_rec.attribute12;
1380          l_eveo_rec.attribute13 := l_eventoffer_rec.attribute13;
1381          l_eveo_rec.attribute14 := l_eventoffer_rec.attribute14;
1382          l_eveo_rec.attribute15 := l_eventoffer_rec.attribute15;
1383 
1384          -- choang - 13-Jul-2000
1385          -- Added custom_setup_id
1386          OPEN c_obj_attr;
1387          FETCH c_obj_attr INTO l_custom_setup_id;
1388          CLOSE c_obj_attr;
1389          l_eveo_rec.custom_setup_id := l_custom_setup_id;
1390 
1391          IF p_new_eveo_name IS NULL
1392          THEN
1393             fnd_message.set_name('AMS', 'AMS_COPY_NAME');
1394             l_new_eveo_name := fnd_message.get;
1395             l_new_eveo_name :=
1396                SUBSTRB(l_new_eveo_name ||
1397                        l_eventoffer_rec.event_offer_name, 1, 240);
1398          ELSE
1399             l_new_eveo_name := SUBSTRB(p_new_eveo_name, 1, 240);
1400          END IF;
1401 -- checks if camp of that name exists-------
1402          l_counter := 0;
1403 
1404          LOOP
1405             l_counter := l_counter + 1;
1406             OPEN c_eveo_name(l_new_eveo_name);
1407             FETCH c_eveo_name INTO l_eveo_count;
1408             EXIT WHEN l_eveo_count = 0;
1409             l_eveo_rec.event_offer_name :=
1410                SUBSTRB(l_new_eveo_name || '-' || l_counter, 1, 240);
1411             l_new_eveo_name := l_eveo_rec.event_offer_name;
1412             CLOSE c_eveo_name;
1413          END LOOP;
1414         ---- IF eveo NAME IS NEW THEN PUT THAT ---------------------------
1415          l_eveo_rec.event_offer_name := l_new_eveo_name;
1416         /* IF   p_par_camp_id = NULL THEN
1417                      l_campaign_rec.parent_campaign_id  :=  NULL;
1418           ElSE
1419                      l_campaign_rec.parent_campaign_id  := p_par_camp_id;
1420           END IF;*/
1421 
1422          ams_eventoffer_pvt.create_event_offer(
1423             p_api_version => l_api_version,
1424             p_init_msg_list => fnd_api.g_true,
1425             p_commit => FND_API.g_true,
1426             x_return_status => l_return_status,
1427             x_msg_count => l_msg_count,
1428             x_msg_data => l_msg_data,
1429             x_evo_id => x_eveo_id,
1430             p_evo_rec => l_eveo_rec);
1431 
1432          IF l_return_status = fnd_api.g_ret_sts_error
1433              OR l_return_status = fnd_api.g_ret_sts_unexp_error
1434          THEN
1435            FOR l_counter IN 1 .. l_msg_count LOOP
1436               l_mesg_text := fnd_msg_pub.get(p_encoded => fnd_api.g_false);
1437               p_errmsg := SUBSTR( l_mesg_text || '): ' || l_counter || ' OF ' ||
1438                                  l_msg_count, 1, 3000);
1439               ams_cpyutility_pvt.write_log_mesg( 'EVEO',
1440                                                  p_src_eveo_id,
1441                                                  p_errmsg,
1442                                                  'ERROR');
1443             END LOOP;
1444             ---- if error then right a copy log message to the log table
1445             fnd_message.set_name('AMS', 'AMS_COPY_ERROR2');
1446             fnd_message.set_token('ELEMENTS', l_lookup_meaning, TRUE);
1447             l_mesg_text := fnd_message.get;
1448             p_errmsg := SUBSTR( l_mesg_text || ' - ' ||
1449             ams_utility_pvt.get_object_name('EVEO', p_src_eveo_id),
1450                                              1, 4000);
1451             ams_cpyutility_pvt.write_log_mesg('EVEO',
1452                                               p_src_eveo_id,
1453                                               p_errmsg,
1454                                               'ERROR');
1455             --  Is failed write a copy failed message in the log table
1456             IF l_return_status = fnd_api.g_ret_sts_error then
1457                RAISE fnd_api.g_exc_error;
1458             ELSE
1459                RAISE fnd_api.g_exc_unexpected_error;
1460             END IF;
1461          END IF;
1462       END;
1463       -- If the user wants to copy objectives then the objectives
1464       -- flag should be 'Y' (Yes)
1465       IF x_return_status = fnd_api.g_ret_sts_success
1466       THEN
1467          IF p_eveo_elements_rec.p_messages = 'Y'
1468          THEN
1469             l_errcode := NULL;
1470             l_errnum := 0;
1471             l_errmsg := NULL;
1472             ams_copyelements_pvt.copy_act_messages(
1473                           p_src_act_type => 'EVEO',
1474                           p_src_act_id   => p_src_eveo_id,
1475                           p_new_act_id   => x_eveo_id,
1476                           p_errnum       => l_errnum,
1477                           p_errcode      => l_errcode,
1478                           p_errmsg       => l_errmsg);
1479          END IF;
1480          -- If the user wants to copy access then the access flag
1481          -- should be 'Y' (Yes)
1482          IF p_eveo_elements_rec.p_products = 'Y'
1483          THEN
1484             l_errcode := NULL;
1485             l_errnum := 0;
1486             l_errmsg := NULL;
1487             ams_copyelements_pvt.copy_act_prod(
1488                p_src_act_type => 'EVEO',
1489                p_src_act_id   => p_src_eveo_id,
1490                p_new_act_id   => x_eveo_id,
1491                p_errnum       => l_errnum,
1492                p_errcode      => l_errcode,
1493                p_errmsg       => l_errmsg);
1494          END IF;
1495          -- If the user wants to copy geo_areas then the geo_area
1496          -- flag should be 'Y' (Yes)
1497          IF p_eveo_elements_rec.p_geo_areas = 'Y'
1498          THEN
1499             l_errcode := NULL;
1500             l_errnum := 0;
1501             l_errmsg := NULL;
1502             ams_copyelements_pvt.copy_act_geo_areas(
1503                p_src_act_type => 'EVEO',
1504                p_src_act_id   => p_src_eveo_id,
1505                p_new_act_id   => x_eveo_id,
1506                p_errnum       => l_errnum,
1507                p_errcode      => l_errcode,
1508                p_errmsg       => l_errmsg);
1509          END IF;
1510          -- If the user wants to copy object_associatiosn then the
1511          -- obj_asso flag should be 'Y' (Yes).It will copy all the
1512          -- associations of the campaign
1513          IF p_eveo_elements_rec.p_obj_asso = 'Y'
1514          THEN
1515             l_errcode := NULL;
1516             l_errnum := 0;
1517             l_errmsg := NULL;
1518             ams_copyelements_pvt.copy_object_associations(
1519                p_src_act_type => 'EVEO',
1520                p_src_act_id   => p_src_eveo_id,
1521                p_new_act_id   => x_eveo_id,
1522                p_errnum       => l_errnum,
1523                p_errcode      => l_errcode,
1524                p_errmsg       => l_errmsg);
1525          END IF;
1526          -- If the user wants to copy resources then the
1527          -- resources flag should be 'Y' (Yes)
1528 /*Commented by mukemar on may14 2002 we are not supporting the resource copy
1529      IF p_eveo_elements_rec.p_resources = 'Y'
1530          THEN
1531             l_errcode := NULL;
1532             l_errnum := 0;
1533             l_errmsg := NULL;
1534             ams_copyelements_pvt.copy_act_resources(
1535                      p_src_act_type => 'EVEO',
1536                      p_src_act_id   => p_src_eveo_id,
1537                      p_new_act_id   => x_eveo_id,
1538                      p_errnum       => l_errnum,
1539                      p_errcode      => l_errcode,
1540                      p_errmsg       => l_errmsg);
1541          END IF;
1542 */
1543 	 /*
1544          IF p_eveo_elements_rec.p_offers = 'Y'
1545          THEN
1546             l_errcode := NULL;
1547             l_errnum := 0;
1548             l_errmsg := NULL;
1549             ams_copyelements_pvt.copy_act_offers(
1550                      p_src_act_type => 'EVEO',
1551                      p_src_act_id   => p_src_eveo_id,
1552                      p_new_act_id   => x_eveo_id,
1553                      p_errnum       => l_errnum,
1554                      p_errcode      => l_errcode,
1555                      p_errmsg       => l_errmsg);
1556           END IF;  */
1557          -- If the user wants to copy geo_areas then the
1558          -- geo_area flag should be 'Y' (Yes)
1559          IF p_eveo_elements_rec.p_segments = 'Y'
1560          THEN
1561             l_errcode := NULL;
1562             l_errnum := 0;
1563             l_errmsg := NULL;
1564             ams_copyelements_pvt.copy_act_market_segments(
1565                      p_src_act_type => 'EVEO',
1566                      p_src_act_id   => p_src_eveo_id,
1567                      p_new_act_id   => x_eveo_id,
1568                      p_errnum       => l_errnum,
1569                      p_errcode      => l_errcode,
1570                      p_errmsg       => l_errmsg);
1571          END IF;
1572          IF p_eveo_elements_rec.p_attachments = 'Y'
1573          THEN
1574             l_errcode := NULL;
1575             l_errnum := 0;
1576             l_errmsg := NULL;
1577             ams_copyelements_pvt.copy_act_attachments(
1578                      p_src_act_type => 'EVEO',
1579                      p_src_act_id   => p_src_eveo_id,
1580                      p_new_act_id   => x_eveo_id,
1581                      p_errnum       => l_errnum,
1582                      p_errcode      => l_errcode,
1583                      p_errmsg       => l_errmsg);
1584          END IF;
1585 
1586          IF p_eveo_elements_rec.p_sub_eveo = 'Y'
1587          THEN
1588             FOR sub_eveo_rec IN sub_eveo_cur
1589             LOOP
1590                BEGIN
1591                   l_return_status := NULL;
1592                   l_msg_count := 0;
1593                   l_msg_data := NULL;
1594                   copy_event_offer(
1595                      p_api_version => 1,
1596                      p_init_msg_list => fnd_api.g_true,
1597                      x_return_status => l_return_status,
1598                      x_msg_data => l_msg_data,
1599                      x_msg_count => l_msg_count,
1600                      p_src_eveo_id => sub_eveo_rec.event_offer_id,
1601                      p_event_header_id => p_event_header_id,
1602                      p_new_eveo_name => NULL,
1603                      p_par_eveo_id => x_eveo_id,
1604                      x_eveo_id => x_sub_eveo_id,
1605                      p_eveo_elements_rec => l_eveo_elements_rec,
1606                      p_start_date => p_start_date);
1607                END;
1608             END LOOP;
1609          END IF;
1610       END IF;
1611 
1612       IF   l_return_status  =  FND_API.G_RET_STS_SUCCESS  THEN
1613          COMMIT ;
1614       END IF ;
1615 
1616    EXCEPTION
1617       WHEN fnd_api.g_exc_error
1618       THEN
1619          ROLLBACK TO copy_event_offer;
1620          x_return_status := fnd_api.g_ret_sts_error;
1621          fnd_msg_pub.count_and_get(
1622             p_encoded => fnd_api.g_false,
1623             p_count => x_msg_count,
1624             p_data => x_msg_data);
1625       WHEN fnd_api.g_exc_unexpected_error
1626       THEN
1627          ROLLBACK TO copy_event_offer;
1628          x_return_status := fnd_api.g_ret_sts_unexp_error;
1629          IF (AMS_DEBUG_HIGH_ON) THEN
1630 
1631              ams_utility_pvt.debug_message(l_full_name || ': debug');
1632          END IF;
1633          fnd_msg_pub.count_and_get(
1634             p_encoded => fnd_api.g_false,
1635             p_count => x_msg_count,
1636             p_data => x_msg_data);
1637       WHEN OTHERS
1638       THEN
1639          ROLLBACK TO copy_event_offer;
1640          x_return_status := fnd_api.g_ret_sts_unexp_error;
1641 
1642          IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
1643          THEN
1644             fnd_msg_pub.add_exc_msg(g_pkg_name, l_api_name);
1645          END IF;
1646 
1647          fnd_msg_pub.count_and_get(
1648             p_encoded => fnd_api.g_false,
1649             p_count => x_msg_count,
1650             p_data => x_msg_data);
1651    END copy_event_offer;
1652 
1653 
1654    PROCEDURE copy_event_header(
1655       p_api_version         IN       NUMBER,
1656       p_init_msg_list       IN       VARCHAR2 := fnd_api.g_false,
1657       x_return_status       OUT NOCOPY      VARCHAR2,
1658       x_msg_count           OUT NOCOPY      NUMBER,
1659       x_msg_data            OUT NOCOPY      VARCHAR2,
1660       x_eveh_id             OUT NOCOPY      NUMBER,
1661       p_src_eveh_id         IN       NUMBER,
1662       p_new_eveh_name       IN       VARCHAR2,
1663       p_par_eveh_id         IN       NUMBER := NULL,
1664       p_eveh_elements_rec   IN       eveh_elements_rec_type,
1665       p_start_date          IN       DATE := NULL,
1666       p_end_date            IN       DATE := NULL,
1667       p_source_code         IN       VARCHAR2:= NULL )
1668    IS
1669       l_api_version   CONSTANT NUMBER        := 1.0;
1670       l_api_name      CONSTANT VARCHAR2(30)  := 'copy_event_header';
1671       l_full_name     CONSTANT VARCHAR2(60)  := g_pkg_name || '.' || l_api_name;
1672       l_return_status          VARCHAR2(1);
1673       l_eveh_ele_rec           eveh_elements_rec_type;   --:= p_camp_rec;
1674       l_name                   VARCHAR2(80);
1675       l_msg_count              NUMBER;
1676       l_msg_data               VARCHAR2(512);
1677 --   l_new_camp_id  NUMBER;
1678       l_eveh_rec               ams_eventheader_pvt.evh_rec_type;
1679       l_mesg_text              VARCHAR2(2000);
1680       p_errmsg                 VARCHAR2(3000);
1681       l_eventheader_rec        ams_event_headers_vl%ROWTYPE;
1682       l_errcode                VARCHAR2(80);
1683       l_errnum                 NUMBER;
1684       l_errmsg                 VARCHAR2(3000);
1685       l_eveh_elements_rec      eveh_elements_rec_type;
1686       l_eveo_elements_rec      eveo_elements_rec_type;
1687       x_sub_eveh_id            NUMBER;
1688       l_new_eveh_name          ams_event_headers_vl.event_header_name%TYPE;
1689       l_eveh_count             NUMBER;
1690       l_lookup_meaning         VARCHAR2(80);
1691       x_eventoffer_id          NUMBER;
1692       l_counter                NUMBER;
1693       l_date_number            NUMBER;
1694       l_custom_setup_id        NUMBER;
1695 
1696       CURSOR sub_eveh_cur IS
1697       SELECT event_header_id
1698         FROM ams_event_headers_vl
1699        WHERE parent_event_header_id = p_src_eveh_id;
1700 
1701       CURSOR c_eveh_name(l_eveh_name IN VARCHAR2) IS
1702 --	modified by dhsingh on 20.05.2004 for bug# 3631107
1703 --      SELECT COUNT(*)
1704 --        FROM ams_event_headers_vl
1705 --       WHERE event_header_name = l_eveh_name;
1706 	SELECT COUNT(*)
1707 	FROM ams_event_headers_all_tl
1708 	WHERE event_header_name = l_eveh_name ;
1709 --	end of modification by dhsingh
1710 
1711       CURSOR sub_eveo_cur IS
1712       SELECT event_offer_id
1713         FROM ams_event_offers_vl
1714        WHERE event_header_id = p_src_eveh_id;
1715 
1716       CURSOR c_obj_attr IS
1717       SELECT custom_setup_id
1718         FROM ams_object_attributes
1719        WHERE object_id = p_src_eveh_id
1720          AND object_type = 'EVEH';
1721    BEGIN
1722       SAVEPOINT copy_event_header;
1723       IF (AMS_DEBUG_HIGH_ON) THEN
1724 
1725           ams_utility_pvt.debug_message(l_full_name || ': start');
1726       END IF;
1727 
1728       IF fnd_api.to_boolean(p_init_msg_list)
1729       THEN
1730          fnd_msg_pub.initialize;
1731       END IF;
1732 
1733       IF NOT fnd_api.compatible_api_call(
1734             l_api_version,
1735             p_api_version,
1736             l_api_name,
1737             g_pkg_name)
1738       THEN
1739          RAISE fnd_api.g_exc_unexpected_error;
1740       END IF;
1741 
1742       x_return_status := fnd_api.g_ret_sts_success;
1743       ----------------------- insert -----------------------
1744       IF (AMS_DEBUG_HIGH_ON) THEN
1745 
1746           ams_utility_pvt.debug_message(l_full_name || ': start');
1747       END IF;
1748 
1749       BEGIN
1750          ams_utility_pvt.get_lookup_meaning( 'AMS_SYS_ARC_QUALIFIER',
1751                                              'EVEH',
1752                                              l_return_status,
1753                                              l_lookup_meaning);
1754 --  General Message saying copying has started
1755          fnd_message.set_name('AMS', 'AMS_COPY_ELEMENTS');
1756          fnd_message.set_token('ELEMENTS', l_lookup_meaning, TRUE);
1757          l_mesg_text := fnd_message.get;
1758 -- Writing to the Pl/SQLtable
1759          ams_cpyutility_pvt.write_log_mesg('EVEH',
1760                                            p_src_eveh_id,
1761                                            l_mesg_text,
1762                                            'GENERAL');
1763          l_return_status := NULL;
1764          l_msg_count := 0;
1765          l_msg_data := NULL;
1766 -- selects the event offers to copy
1767          SELECT *
1768            INTO l_eventheader_rec
1769            FROM ams_event_headers_vl
1770           WHERE event_header_id = p_src_eveh_id;
1771          l_eveh_rec.object_version_number := 2; -- Bug 5171873 cannot be 1
1772 
1773          l_eveh_rec.application_id := l_eventheader_rec.application_id;
1774          l_eveh_rec.private_flag := l_eventheader_rec.private_flag;
1775 
1776          IF p_par_eveh_id IS NULL
1777          THEN
1778             l_eveh_rec.event_level := 'MAIN';
1779          ELSE
1780             l_eveh_rec.event_level := 'SUB';
1781          END IF;
1782 
1783          l_eveh_rec.stream_type_code := l_eventheader_rec.stream_type_code;
1784          l_eveh_rec.event_type_code := l_eventheader_rec.event_type_code;
1785          l_eveh_rec.overflow_flag := l_eventheader_rec.overflow_flag;
1786          l_eveh_rec.partner_flag := l_eventheader_rec.partner_flag;
1787          l_eveh_rec.event_standalone_flag :=  l_eventheader_rec.event_standalone_flag;
1788          l_eveh_rec.reg_required_flag := l_eventheader_rec.reg_required_flag;
1789          l_eveh_rec.reg_charge_flag := l_eventheader_rec.reg_charge_flag;
1790          l_eveh_rec.reg_invited_only_flag := l_eventheader_rec.reg_invited_only_flag;
1791          l_eveh_rec.parent_event_header_id := p_par_eveh_id;
1792          l_eveh_rec.duration := l_eventheader_rec.duration;
1793          l_eveh_rec.duration_uom_code := l_eventheader_rec.duration_uom_code;
1794          l_eveh_rec.source_code :=  p_source_code;
1795 
1796          -- get the custom_setup_id to determine
1797          -- the attributes the new copy of event
1798          -- headers will have.
1799          OPEN c_obj_attr;
1800          FETCH c_obj_attr INTO l_custom_setup_id;
1801          -- Let the event header api handle validation of custom_setup_id.
1802          CLOSE c_obj_attr;
1803 
1804     IF p_start_date IS NOT NULL
1805          THEN
1806             l_eveh_rec.active_from_date := p_start_date;
1807          END IF;
1808 
1809          l_date_number :=
1810             ams_cpyutility_pvt.get_dates('EVEH',
1811                                          p_src_eveh_id,
1812                                          l_return_status);
1813 
1814          IF l_eventheader_rec.active_to_date IS NOT NULL
1815          THEN
1816             l_eveh_rec.active_to_date := p_start_date + l_date_number;
1817          END IF;
1818 
1819          l_eveh_rec.reg_maximum_capacity :=
1820                               l_eventheader_rec.reg_maximum_capacity;
1821          l_eveh_rec.reg_minimum_capacity :=
1822                               l_eventheader_rec.reg_minimum_capacity;
1823          l_eveh_rec.org_id := l_eventheader_rec.org_id;
1824          l_eveh_rec.stream_type_code := l_eventheader_rec.stream_type_code;
1825          -- l_eveh_rec.owner_user_id := l_eventheader_rec.owner_user_id;
1826          l_eveh_rec.owner_user_id := AMS_Utility_PVT.get_resource_id (FND_GLOBAL.user_id);
1827 
1828          l_eveh_rec.user_status_id := 1;
1829          l_eveh_rec.system_status_code := 'NEW';
1830          l_eveh_rec.cert_credit_type_code :=
1831                                l_eventheader_rec.cert_credit_type_code;
1832          l_eveh_rec.certification_credits :=
1833                                l_eventheader_rec.certification_credits;
1834          l_eveh_rec.coordinator_id := l_eventheader_rec.coordinator_id;
1835          l_eveh_rec.priority_type_code := l_eventheader_rec.priority_type_code;
1836          l_eveh_rec.email := l_eventheader_rec.email;
1837          l_eveh_rec.phone := l_eventheader_rec.phone;
1838          l_eveh_rec.url := l_eventheader_rec.url;
1839          l_eveh_rec.inbound_script_name :=
1840                               l_eventheader_rec.inbound_script_name;
1841          l_eveh_rec.attribute_category := l_eventheader_rec.attribute_category;
1842          l_eveh_rec.attribute1 := l_eventheader_rec.attribute1;
1843          l_eveh_rec.attribute2 := l_eventheader_rec.attribute2;
1844          l_eveh_rec.attribute3 := l_eventheader_rec.attribute3;
1845          l_eveh_rec.attribute4 := l_eventheader_rec.attribute4;
1846          l_eveh_rec.attribute5 := l_eventheader_rec.attribute5;
1847          l_eveh_rec.attribute6 := l_eventheader_rec.attribute6;
1848          l_eveh_rec.attribute7 := l_eventheader_rec.attribute7;
1849          l_eveh_rec.attribute8 := l_eventheader_rec.attribute8;
1850          l_eveh_rec.attribute9 := l_eventheader_rec.attribute9;
1851          l_eveh_rec.attribute10 := l_eventheader_rec.attribute10;
1852          l_eveh_rec.attribute11 := l_eventheader_rec.attribute11;
1853          l_eveh_rec.attribute12 := l_eventheader_rec.attribute12;
1854          l_eveh_rec.attribute13 := l_eventheader_rec.attribute13;
1855          l_eveh_rec.attribute14 := l_eventheader_rec.attribute14;
1856          l_eveh_rec.attribute15 := l_eventheader_rec.attribute15;
1857 
1858          l_eveh_rec.custom_setup_id := l_custom_setup_id;
1859 
1860          IF p_new_eveh_name IS NULL
1861          THEN
1862             fnd_message.set_name('AMS', 'AMS_COPY_NAME');
1863             l_new_eveh_name := fnd_message.get;
1864             l_new_eveh_name :=
1865               SUBSTRB(l_new_eveh_name ||
1866                       l_eventheader_rec.event_header_name, 1, 240);
1867          ELSE
1868             l_new_eveh_name := SUBSTRB(p_new_eveh_name, 1, 240);
1869          END IF;
1870          -- checks if camp of that name exists-------
1871          l_counter := 1;
1872          LOOP
1873             l_counter := l_counter + 1;
1874             OPEN c_eveh_name(l_new_eveh_name);
1875             FETCH c_eveh_name INTO l_eveh_count;
1876             EXIT WHEN l_eveh_count = 0;
1877             l_eveh_rec.event_header_name :=
1878                SUBSTRB(l_new_eveh_name || '-' || l_counter, 1, 240);
1879             l_new_eveh_name := l_eveh_rec.event_header_name;
1880             CLOSE c_eveh_name;
1881          END LOOP;
1882          ---- IF eveh NAME IS NEW THEN PUT THAT ---------------------------
1883          l_eveh_rec.event_header_name := l_new_eveh_name;
1884 /*        IF   p_par_camp_id = NULL THEN
1885                      l_campaign_rec.parent_campaign_id  :=  NULL;
1886           ElSE
1887                      l_campaign_rec.parent_campaign_id  := p_par_camp_id;
1888           END IF;*/
1889 
1890          ams_eventheader_pvt.create_event_header(
1891             p_api_version => l_api_version,
1892             p_init_msg_list => fnd_api.g_true,
1893             p_commit => FND_API.g_true,
1894             x_return_status => l_return_status,
1895             x_msg_count => l_msg_count,
1896             x_msg_data => l_msg_data,
1897             x_evh_id => x_eveh_id,
1898             p_evh_rec => l_eveh_rec);
1899 
1900          IF l_return_status = fnd_api.g_ret_sts_error
1901              OR l_return_status = fnd_api.g_ret_sts_unexp_error
1902          THEN
1903             FOR l_counter IN 1 .. l_msg_count LOOP
1904                 l_mesg_text := fnd_msg_pub.get(p_encoded => fnd_api.g_false);
1905                 p_errmsg := SUBSTR( l_mesg_text || '): ' || l_counter ||
1906                                     ' OF ' || l_msg_count, 1, 3000);
1907                 ams_cpyutility_pvt.write_log_mesg( 'EVEH',
1908                                                    p_src_eveh_id,
1909                                                    p_errmsg,
1910                                                    'ERROR');
1911             END LOOP;
1912             fnd_message.set_name('AMS', 'AMS_COPY_ERROR2');
1913             fnd_message.set_token('ELEMENTS', l_lookup_meaning, TRUE);
1914             l_mesg_text := fnd_message.get;
1915             p_errmsg := SUBSTR( l_mesg_text || ' - ' ||
1916                            ams_utility_pvt.get_object_name('EVEH',
1917                              p_src_eveh_id), 1, 4000);
1918             ams_cpyutility_pvt.write_log_mesg('EVEH',
1919                                               p_src_eveh_id,
1920                                               p_errmsg,
1921                                               'ERROR');
1922            --  Is failed write a copy failed message in the log table
1923             IF l_return_status = fnd_api.g_ret_sts_error then
1924                RAISE fnd_api.g_exc_error;
1925             ELSE
1926                RAISE fnd_api.g_exc_unexpected_error;
1927             END IF;
1928          END IF;
1929       END;
1930       -- If the user wants to copy objectives then the
1931       -- objectives flag should be 'Y' (Yes)
1932       IF x_return_status = fnd_api.g_ret_sts_success
1933       THEN
1934          IF p_eveh_elements_rec.p_messages = 'Y'
1935          THEN
1936             l_errcode := NULL;
1937             l_errnum := 0;
1938             l_errmsg := NULL;
1939             ams_copyelements_pvt.copy_act_messages(
1940                         p_src_act_type => 'EVEH',
1941                         p_src_act_id   => p_src_eveh_id,
1942                         p_new_act_id   => x_eveh_id,
1943                         p_errnum       => l_errnum,
1944                         p_errcode      => l_errcode,
1945                         p_errmsg       => l_errmsg);
1946          END IF;
1947 -- If the user wants to copy access then the access flag should be 'Y' (Yes)
1948          IF p_eveh_elements_rec.p_products = 'Y'
1949          THEN
1950             l_errcode := NULL;
1951             l_errnum := 0;
1952             l_errmsg := NULL;
1953             ams_copyelements_pvt.copy_act_prod(
1954                             p_src_act_type => 'EVEH',
1955                             p_src_act_id   => p_src_eveh_id,
1956                             p_new_act_id   => x_eveh_id,
1957                             p_errnum       => l_errnum,
1958                             p_errcode      => l_errcode,
1959                             p_errmsg       => l_errmsg);
1960           END IF;
1961           -- If the user wants to copy geo_areas then
1962           -- the geo_area flag should be 'Y' (Yes)
1963          IF p_eveh_elements_rec.p_geo_areas = 'Y'
1964          THEN
1965             l_errcode := NULL;
1966             l_errnum := 0;
1967             l_errmsg := NULL;
1968             ams_copyelements_pvt.copy_act_geo_areas(
1969                         p_src_act_type => 'EVEH',
1970                         p_src_act_id   => p_src_eveh_id,
1971                         p_new_act_id   => x_eveh_id,
1972                         p_errnum       => l_errnum,
1973                         p_errcode      => l_errcode,
1974                         p_errmsg       => l_errmsg);
1975          END IF;
1976 -- If the user wants to copy object_associatiosn then the
1977 -- obj_asso flag should be 'Y' (Yes).It will copy all the
1978 -- associations of the campaign
1979          IF p_eveh_elements_rec.p_obj_asso = 'Y'
1980          THEN
1981             l_errcode := NULL;
1982             l_errnum := 0;
1983             l_errmsg := NULL;
1984             ams_copyelements_pvt.copy_object_associations(
1985                           p_src_act_type => 'EVEH',
1986                           p_src_act_id   => p_src_eveh_id,
1987                           p_new_act_id   => x_eveh_id,
1988                           p_errnum       => l_errnum,
1989                           p_errcode      => l_errcode,
1990                           p_errmsg       => l_errmsg);
1991          END IF;
1992          -- If the user wants to copy resources then the
1993          -- resources flag should be 'Y' (Yes)
1994 /*Commented by mukemar on may14 2002 we are not supporting the resource copy
1995 	 IF p_eveh_elements_rec.p_resources = 'Y'
1996          THEN
1997             l_errcode := NULL;
1998             l_errnum := 0;
1999             l_errmsg := NULL;
2000             ams_copyelements_pvt.copy_act_resources(
2001                            p_src_act_type => 'EVEH',
2002                            p_src_act_id   => p_src_eveh_id,
2003                            p_new_act_id   => x_eveh_id,
2004                            p_errnum       => l_errnum,
2005                            p_errcode      => l_errcode,
2006                            p_errmsg       => l_errmsg);
2007          END IF;
2008 */
2009 	    /*
2010          IF p_eveh_elements_rec.p_offers = 'Y'
2011          THEN
2012             l_errcode := NULL;
2013             l_errnum := 0;
2014             l_errmsg := NULL;
2015             ams_copyelements_pvt.copy_act_offers(
2016                            p_src_act_type => 'EVEH',
2017                            p_src_act_id   => p_src_eveh_id,
2018                            p_new_act_id   => x_eveh_id,
2019                            p_errnum       => l_errnum,
2020                            p_errcode      => l_errcode,
2021                            p_errmsg       => l_errmsg);
2022           END IF;  */
2023          -- If the user wants to copy geo_areas then the geo_area
2024          -- flag should be 'Y' (Yes)
2025          IF p_eveh_elements_rec.p_segments = 'Y'
2026          THEN
2027             l_errcode := NULL;
2028             l_errnum := 0;
2029             l_errmsg := NULL;
2030             ams_copyelements_pvt.copy_act_market_segments(
2031                    p_src_act_type => 'EVEH',
2032                    p_src_act_id   => p_src_eveh_id,
2033                    p_new_act_id   => x_eveh_id,
2034                    p_errnum       => l_errnum,
2035                    p_errcode      => l_errcode,
2036                    p_errmsg       => l_errmsg);
2037          END IF;
2038 
2039          IF p_eveh_elements_rec.p_attachments = 'Y'
2040          THEN
2041             l_errcode := NULL;
2042             l_errnum := 0;
2043             l_errmsg := NULL;
2044             ams_copyelements_pvt.copy_act_attachments(
2045                      p_src_act_type => 'EVEH',
2046                      p_src_act_id   => p_src_eveh_id,
2047                      p_new_act_id   => x_eveh_id,
2048                      p_errnum       => l_errnum,
2049                      p_errcode      => l_errcode,
2050                      p_errmsg       => l_errmsg);
2051          END IF;
2052 
2053          IF p_eveh_elements_rec.p_sub_eveh = 'Y'
2054          THEN
2055             FOR sub_eveh_rec IN sub_eveh_cur
2056             LOOP
2057                BEGIN
2058                   l_return_status := NULL;
2059                   l_msg_count := 0;
2060                   l_msg_data := NULL;
2061                   copy_event_header(
2062                      p_api_version => 1,
2063                      p_init_msg_list => fnd_api.g_true,
2064                      x_return_status => l_return_status,
2065                      x_msg_data => l_msg_data,
2066                      x_msg_count => l_msg_count,
2067                      p_src_eveh_id => sub_eveh_rec.event_header_id,
2068                      p_new_eveh_name => NULL,
2069                      p_par_eveh_id => x_eveh_id,
2070                      x_eveh_id => x_sub_eveh_id,
2071                      p_eveh_elements_rec => l_eveh_elements_rec,
2072                      p_start_date => p_start_date);
2073                END;
2074             END LOOP;
2075          END IF;
2076 
2077          IF p_eveh_elements_rec.p_event_offer = 'Y'
2078          THEN
2079             FOR sub_eveo_rec IN sub_eveo_cur
2080             LOOP
2081                BEGIN
2082                   l_return_status := NULL;
2083                   l_msg_count := 0;
2084                   l_msg_data := NULL;
2085                   copy_event_offer(
2086                      p_api_version => 1,
2087                      x_return_status => l_return_status,
2088                      p_init_msg_list => fnd_api.g_true,
2089                      x_msg_count => l_msg_data,
2090                      x_msg_data => l_msg_count,
2091                      x_eveo_id => x_eventoffer_id,
2092                      p_src_eveo_id => sub_eveo_rec.event_offer_id,
2093                      p_event_header_id => x_eveh_id,
2094                      p_eveo_elements_rec => l_eveo_elements_rec,
2095                      p_start_date => p_start_date);
2096                END;
2097             END LOOP;
2098          END IF;
2099       END IF;
2100       IF   l_return_status  =  FND_API.G_RET_STS_SUCCESS  THEN
2101          COMMIT ;
2102       END IF ;
2103    EXCEPTION
2104       WHEN fnd_api.g_exc_error
2105       THEN
2106          ROLLBACK TO copy_event_header;
2107          x_return_status := fnd_api.g_ret_sts_error;
2108          fnd_msg_pub.count_and_get(
2109             p_encoded => fnd_api.g_false,
2110             p_count => x_msg_count,
2111             p_data => x_msg_data);
2112       WHEN fnd_api.g_exc_unexpected_error
2113       THEN
2114          ROLLBACK TO copy_event_header;
2115          x_return_status := fnd_api.g_ret_sts_unexp_error;
2116          IF (AMS_DEBUG_HIGH_ON) THEN
2117 
2118              ams_utility_pvt.debug_message(l_full_name || ': debug');
2119          END IF;
2120          fnd_msg_pub.count_and_get(
2121             p_encoded => fnd_api.g_false,
2122             p_count => x_msg_count,
2123             p_data => x_msg_data);
2124       WHEN OTHERS
2125       THEN
2126          ROLLBACK TO copy_event_header;
2127          x_return_status := fnd_api.g_ret_sts_unexp_error;
2128 
2129          IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
2130          THEN
2131             fnd_msg_pub.add_exc_msg(g_pkg_name, l_api_name);
2132          END IF;
2133 
2134          fnd_msg_pub.count_and_get(
2135             p_encoded => fnd_api.g_false,
2136             p_count => x_msg_count,
2137             p_data => x_msg_data);
2138    END copy_event_header;
2139 
2140 PROCEDURE Copy_Campaign (
2141    p_api_version         IN       NUMBER,
2142    p_init_msg_list       IN       VARCHAR2 := FND_API.G_FALSE,
2143    -- Not being added since it involves changes in signature and class
2144    -- generated by rosseta To be implemented at later stage
2145    -- p_commit              IN       VARCHAR2 := FND_API.G_FALSE,
2146    -- p_validation_level    IN       NUMBER   := FND_API.G_VALID_LEVEL_FULL,
2147    x_return_status       OUT NOCOPY      VARCHAR2,
2148    x_msg_count           OUT NOCOPY      NUMBER,
2149    x_msg_data            OUT NOCOPY      VARCHAR2,
2150    x_campaign_id         OUT NOCOPY      NUMBER,
2151    p_src_camp_id         IN       NUMBER,
2152    p_new_camp_name       IN       VARCHAR2,
2153    p_par_camp_id         IN       NUMBER,
2154    p_source_code         IN       VARCHAR2 := NULL,
2155    p_camp_elements_rec   IN       camp_elements_rec_type,
2156    p_end_date            IN       DATE :=  FND_API.G_MISS_DATE,
2157    p_start_date          IN       DATE :=  FND_API.G_MISS_DATE)
2158 IS
2159    l_api_version       CONSTANT   NUMBER        := 1.0;
2160    l_api_name          CONSTANT   VARCHAR2(30)  := 'Copy_Campaign';
2161    l_full_name         CONSTANT   VARCHAR2(60)  := g_pkg_name ||'.'||l_api_name;
2162    l_return_status                VARCHAR2(1)   := FND_API.G_RET_STS_SUCCESS;
2163    l_lookup_meaning               VARCHAR2(80);
2164    -- Stores the resource Id
2165    l_owner_user_id                NUMBER        := FND_API.G_MISS_NUM;
2166    l_mesg_text                    VARCHAR2(2000);
2167 
2168    l_campaign_rec                 ams_campaigns_vl%ROWTYPE;
2169    l_user_status_id               number;
2170    l_camp_count                   number;
2171    l_camp_rec                     ams_campaign_pvt.camp_rec_type;
2172    l_date_number                  NUMBER  := 0;
2173    l_msg_count                    NUMBER;
2174    l_msg_data                     VARCHAR2(512);
2175    l_src_campaign_schedule_id     NUMBER;
2176    l_campaign_schedule_id         NUMBER;
2177    l_errnum                       NUMBER;
2178    l_errmsg                       VARCHAR2(3000);
2179    l_errcode                      VARCHAR2(80);
2180    x_sub_camp_id                  NUMBER;
2181    l_camp_elements_rec            camp_elements_rec_type;
2182 
2183    CURSOR cur_get_campaign IS
2184    SELECT *
2185      FROM ams_campaigns_vl
2186     WHERE campaign_id = p_src_camp_id;
2187 
2188    CURSOR cur_get_default_status IS
2189    SELECT user_status_id
2190      FROM ams_user_statuses_b
2191     WHERE system_status_code = 'NEW'
2192       AND enabled_flag = 'Y'
2193       AND sysdate between start_date_active AND NVL(end_date_active,sysdate)
2194       AND default_flag = 'Y'
2195       AND system_status_type = 'AMS_CAMPAIGN_STATUS';
2196 
2197    -- Used to bump up the version number if the name is same for the campaign
2198    CURSOR c_camp_name(l_campaign_name IN VARCHAR2) IS
2199    SELECT MAX(version_no)
2200      FROM ams_campaigns_vl
2201     WHERE campaign_name = l_campaign_name;
2202 
2203    CURSOR c_camp_sche(src_campaign_id IN NUMBER) IS
2204    SELECT schedule_id
2205      FROM ams_campaign_schedules_b
2206     WHERE campaign_id = src_campaign_id;
2207 
2208    CURSOR cur_get_tasks (p_src_camp_id NUMBER) IS
2209    SELECT task_id
2210      FROM jtf_tasks_b
2211     WHERE source_object_type_code = 'AMS_CAMP'
2212       AND source_object_id = p_src_camp_id;
2213 
2214    CURSOR sub_camp_cur IS
2215    SELECT campaign_id,
2216           campaign_name
2217      FROM ams_campaigns_vl
2218     WHERE parent_campaign_id = p_src_camp_id;
2219 
2220 BEGIN
2221    x_return_status := fnd_api.g_ret_sts_success;
2222    --Standard Start API savePoint
2223    SAVEPOINT Copy_Campaign_PVT;
2224    IF NOT FND_API.Compatible_API_CALL (l_api_version,
2225                                         p_api_version,
2226                                         l_api_name,
2227                                         G_PKG_NAME
2228                                        )
2229     THEN
2230        RAISE FND_API.G_EXC_UNEXPECTED_ERROR  ;
2231     END IF;
2232     -- Initialize the message List
2233     IF FND_API.to_Boolean( p_init_msg_list )
2234     THEN
2235        FND_MSG_PUB.initialize ;
2236     END IF;
2237     -- Lookup Meaning from ams_lookup for CAMP
2238     IF (AMS_DEBUG_HIGH_ON) THEN
2239 
2240         ams_utility_pvt.debug_message(l_full_name || ' :Start ');
2241     END IF;
2242     ams_utility_pvt.get_lookup_meaning( 'AMS_SYS_ARC_QUALIFIER',
2243                                         'CAMP',
2244                                         l_return_status,
2245                                         l_lookup_meaning);
2246     IF l_return_status = FND_API.G_RET_STS_ERROR THEN
2247        RAISE FND_API.G_EXC_ERROR ;
2248     ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2249        RAISE FND_API.G_EXC_UNEXPECTED_ERROR ;
2250     END IF;
2251 
2252     -- Start of Log
2253     -- General Message saying copying has started
2254     fnd_message.set_name('AMS','AMS_COPY_ELEMENTS');
2255     fnd_message.set_token('ELEMENTS',l_lookup_meaning,TRUE);
2256     l_mesg_text := fnd_message.get ;
2257 
2258     -- Writing to PL/SQL table
2259     ams_cpyutility_pvt.write_log_mesg( 'CAMP',
2260                                        p_src_camp_id,
2261                                        l_mesg_text,
2262                                        'GENERAL');
2263     -- Get the source campaign details
2264     open cur_get_campaign;
2265     fetch cur_get_campaign into l_campaign_rec;
2266     close cur_get_campaign;
2267 
2268     -- Call get_resource_id to get the resource id from jtf tables
2269     -- Returns -1 if the setup of resource was not done properly
2270     l_owner_user_id  := ams_utility_pvt.get_resource_id(FND_GLOBAL.USER_ID);
2271     IF l_owner_user_id  = -1 THEN
2272        RAISE FND_API.G_EXC_UNEXPECTED_ERROR ;
2273     END IF;
2274 
2275 
2276     -- Id for campaigns status  = 'NEW'
2277     OPEN cur_get_default_status;
2278     FETCH cur_get_default_status into l_user_status_id;
2279     CLOSE cur_get_default_status;
2280     IF l_user_status_id = FND_API.G_MISS_NUM then
2281        RAISE FND_API.G_EXC_UNEXPECTED_ERROR ;
2282     END IF;
2283 
2284     -- get the max version number of campaign if campaign name is same
2285     OPEN c_camp_name(p_new_camp_name);
2286     FETCH c_camp_name INTO l_camp_count;
2287     CLOSE c_camp_name;
2288 
2289 
2290     -- Copying Campaign Details
2291     -- a) Copying Fields from source Campaign Fields
2292     l_camp_rec.global_flag              := l_campaign_rec.global_flag;
2293     l_camp_rec.custom_setup_id          := l_campaign_rec.custom_setup_id;
2294 
2295     -- Start of code modified by ptendulk on 25-Jan-2001
2296     -- While copying the campaign do not copy the business unit.
2297     --
2298     l_camp_rec.business_unit_id         := null ;
2299     --l_camp_rec.business_unit_id         := l_campaign_rec.business_unit_id;
2300     -- End of code modified by ptendulk on 25-Jan-2001
2301     l_camp_rec.private_flag             := l_campaign_rec.private_flag;
2302     l_camp_rec.partner_flag             := l_campaign_rec.partner_flag;
2303     l_camp_rec.template_flag            := l_campaign_rec.template_flag;
2304     l_camp_rec.cascade_source_code_flag :=
2305                                      l_campaign_rec.cascade_source_code_flag;
2306     l_camp_rec.inherit_attributes_flag  :=
2307                                      l_campaign_rec.inherit_attributes_flag;
2308     l_camp_rec.rollup_type              := l_campaign_rec.rollup_type;
2309     l_camp_rec.campaign_type            := l_campaign_rec.campaign_type;
2310     l_camp_rec.priority                 := l_campaign_rec.priority;
2311     l_camp_rec.fund_source_type         := l_campaign_rec.fund_source_type;
2312     l_camp_rec.fund_source_id           := l_campaign_rec.fund_source_id;
2313     l_camp_rec.application_id           := l_campaign_rec.application_id;
2314     l_camp_rec.media_id                 := l_campaign_rec.media_id;
2315     -- Set to null
2316     -- l_camp_rec.channel_id               := l_campaign_rec.channel_id;
2317     -- l_camp_rec.arc_channel_from         := l_campaign_rec.arc_channel_from;
2318     --- Media Type code required for an execution camapign
2319     l_camp_rec.media_type_code          := l_campaign_rec.media_type_code;
2320     l_camp_rec.transaction_currency_code :=
2321                                  l_campaign_rec.transaction_currency_code;
2322     l_camp_rec.functional_currency_code :=
2323                                  l_campaign_rec.functional_currency_code;
2324     l_camp_rec.budget_amount_tc         := l_campaign_rec.budget_amount_tc;
2325     l_camp_rec.budget_amount_fc         := l_campaign_rec.budget_amount_fc;
2326     l_camp_rec.event_type               := l_campaign_rec.event_type;
2327     l_camp_rec.content_source           := l_campaign_rec.content_source;
2328     l_camp_rec.cc_call_strategy         := l_campaign_rec.cc_call_strategy;
2329     l_camp_rec.cc_manager_user_id       := l_campaign_rec.cc_manager_user_id;
2330     l_camp_rec.forecasted_revenue       := l_campaign_rec.forecasted_revenue;
2331     l_camp_rec.forecasted_cost          := l_campaign_rec.forecasted_cost;
2332     l_camp_rec.forecasted_response      := l_campaign_rec.forecasted_response;
2333     l_camp_rec.target_response          := l_campaign_rec.target_response;
2334     l_camp_rec.country_code             := l_campaign_rec.country_code;
2335     l_camp_rec.language_code            := l_campaign_rec.language_code;
2336     l_camp_rec.attribute_category       := l_campaign_rec.attribute_category;
2337     l_camp_rec.attribute1               := l_campaign_rec.attribute1;
2338     l_camp_rec.attribute2               := l_campaign_rec.attribute2;
2339     l_camp_rec.attribute3               := l_campaign_rec.attribute3;
2340     l_camp_rec.attribute4               := l_campaign_rec.attribute4;
2341     l_camp_rec.attribute5               := l_campaign_rec.attribute5;
2342     l_camp_rec.attribute6               := l_campaign_rec.attribute6;
2343     l_camp_rec.attribute7               := l_campaign_rec.attribute7;
2344     l_camp_rec.attribute8               := l_campaign_rec.attribute8;
2345     l_camp_rec.attribute9               := l_campaign_rec.attribute9;
2346     l_camp_rec.attribute10              := l_campaign_rec.attribute10;
2347     l_camp_rec.attribute11              := l_campaign_rec.attribute11;
2348     l_camp_rec.attribute12              := l_campaign_rec.attribute12;
2349     l_camp_rec.attribute13              := l_campaign_rec.attribute13;
2350     l_camp_rec.attribute14              := l_campaign_rec.attribute14;
2351     l_camp_rec.attribute15              := l_campaign_rec.attribute15;
2352     l_camp_rec.duration                 := l_campaign_rec.duration;
2353     l_camp_rec.duration_uom_code        := l_campaign_rec.duration_uom_code;
2354     l_camp_rec.source_code              := p_source_code;
2355     l_camp_rec.campaign_name            := p_new_camp_name;
2356     l_camp_rec.campaign_theme           := l_campaign_rec.campaign_theme;
2357     l_camp_rec.description              := l_campaign_rec.description;
2358 
2359 
2360     -- b)   Null fields
2361     l_camp_rec.start_period_name          := NULL;
2362     l_camp_rec.end_period_name            := NULL;
2363     l_camp_rec.forecasted_plan_start_date := NULL;
2364     l_camp_rec.forecasted_plan_end_date   := NULL;
2365     l_camp_rec.forecasted_exec_start_date := NULL;
2366     l_camp_rec.forecasted_exec_end_date   := NULL;
2367     l_camp_rec.actual_plan_start_date     := NULL;
2368     l_camp_rec.actual_plan_end_date       := NULL;
2369     l_camp_rec.channel_id                 := NULL;
2370     l_camp_rec.arc_channel_from           := NULL;
2371 
2372 
2373     -- c)  Fields Different between source campaign and copied campaign
2374     l_camp_rec.version_no                 := nvl(l_camp_count,0) + 1;
2375     l_camp_rec.object_version_number      := 1;
2376     -- default campaign calendar
2377     l_camp_rec.campaign_calendar          :=
2378                              FND_PROFILE.value('AMS_CAMPAIGN_DEFAULT_CALENDER');
2379     -- default country
2380     l_camp_rec.city_id                    :=
2381                            TO_NUMBER(FND_PROFILE.value('AMS_SRCGEN_USER_CITY'));
2382     l_camp_rec.owner_user_id              := l_owner_user_id;
2383     l_camp_rec.user_status_id             := l_user_status_id;
2384     l_camp_rec.status_code                := 'NEW';
2385     l_camp_rec.status_date                := SYSDATE;
2386     --l_camp_rec.active_flag              := l_campaign_rec.active_flag;
2387     --l_campaign_rec.parent_campaign_id
2388     l_camp_rec.parent_campaign_id         :=  p_par_camp_id;
2389 
2390     -- End Date Algorithm
2391     -- l_date number is the difference between start date of source
2392     -- Campaign and end data of source campaign date
2393     l_date_number := ams_cpyutility_pvt.get_dates('CAMP',
2394                                                   p_src_camp_id,
2395                                                   l_return_status);
2396 
2397     IF l_return_status = FND_API.G_RET_STS_ERROR THEN
2398        RAISE FND_API.G_EXC_ERROR ;
2399     ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2400        RAISE FND_API.G_EXC_UNEXPECTED_ERROR ;
2401     END IF;
2402 
2403     -- p_start_date is the user  input date
2404     IF p_start_date IS NOT NULL THEN
2405        l_camp_rec.actual_exec_start_date := p_start_date;
2406     END IF;
2407 
2408     -- End date of copied(new) campaign is start date(user input)+l_date_number
2409     IF l_campaign_rec.actual_exec_end_date IS NOT NULL THEN
2410        l_camp_rec.actual_exec_end_date := p_start_date + l_date_number;
2411     END IF;
2412     -- End of end date alogorithm
2413 
2414     --   Not copying Response related stuff
2415     --   l_camp_rec.dscript_name       := l_campaign_rec.dscript_name;
2416     --   l_camp_rec.inbound_url        := l_campaign_rec.inbound_url;
2417     --   l_camp_rec.inbound_email_id   := l_campaign_rec.inbound_email_id;
2418     --   l_camp_rec.inbound_phone_no   := l_campaign_rec.inbound_phone_no;
2419          ----Donot copy the ff_cols------
2420     /*
2421     l_camp_rec.ff_priority             := l_campaign_rec.ff_priority;
2422     l_camp_rec.ff_override_cover_letter  :=
2423                                        l_campaign_rec.ff_override_cover_letter;
2424     l_camp_rec.ff_ntf_on_send_flag     := l_campaign_rec.ff_ntf_on_send_flag;
2425     l_camp_rec.ff_ntf_complete_flag    := l_campaign_rec.ff_ntf_complete_flag;
2426     l_camp_rec.ff_ntf_exhausted_inv_flag :=
2427                                        l_campaign_rec.ff_ntf_exhausted_inv_flag;
2428     l_camp_rec.ff_ntf_bounced_address_flag      :=
2429                                     l_campaign_rec.ff_ntf_bounced_address_flag;
2430     l_camp_rec.ff_shipping_method      := l_campaign_rec.ff_shipping_method;
2431     l_camp_rec.ff_carrier              := l_campaign_rec.ff_carrier;
2432     l_camp_rec.ff_printing_option      := l_campaign_rec.ff_printing_option;
2433     l_camp_rec.ff_start_date           := l_campaign_rec.ff_start_date;
2434     l_camp_rec.ff_special_handling_text :=
2435                                  l_campaign_rec.ff_special_handling_text;
2436     */
2437     -- Calling create campaign API l_camp_rec (Campaign details)
2438     -- returns campaign Id of the new campaign
2439     ams_campaign_pvt.create_campaign( p_api_version    => l_api_version,
2440                                       p_init_msg_list  => fnd_api.g_true,
2441                                       p_commit         => FND_API.g_true,
2442                                       x_return_status  => l_return_status,
2443                                       x_msg_count      => l_msg_count,
2444                                       x_msg_data       => l_msg_data,
2445                                       x_camp_id        => x_campaign_id,
2446                                       p_camp_rec       => l_camp_rec);
2447 
2448      IF ( l_return_status = fnd_api.g_ret_sts_error ) OR
2449         ( l_return_status = fnd_api.g_ret_sts_error ) then
2450         FOR l_counter IN 1 .. l_msg_count
2451         LOOP
2452           l_mesg_text := fnd_msg_pub.get(p_encoded => fnd_api.g_false);
2453           l_errmsg := SUBSTR( l_mesg_text || '): ' || l_counter ||
2454                               ' OF ' || l_msg_count, 1, 3000);
2455           ams_cpyutility_pvt.write_log_mesg( 'CAMP',
2456                                              p_src_camp_id,
2457                                              l_errmsg,
2458                                              'ERROR');
2459         END LOOP;
2460         -- if error then right a copy log message to the log table
2461 
2462         fnd_message.set_name('AMS', 'AMS_COPY_ERROR2');
2463         fnd_message.set_token('ELEMENTS', l_lookup_meaning, TRUE);
2464         l_mesg_text := fnd_message.get;
2465         l_errmsg :=substr(l_mesg_text || ' - ' ||
2466                           ams_utility_pvt.get_object_name('CAMP',p_src_camp_id),
2467                           1, 4000);
2468         ams_cpyutility_pvt.write_log_mesg('CAMP',
2469                                           p_src_camp_id,
2470                                           l_errmsg ,
2471                                           'ERROR');
2472      END IF ;
2473 
2474      IF l_return_status = FND_API.G_RET_STS_ERROR THEN
2475         RAISE FND_API.G_EXC_ERROR ;
2476      ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2477         RAISE FND_API.G_EXC_UNEXPECTED_ERROR ;
2478      END IF;
2479      -- Schedules are not copied
2480      -- Copy the schedule
2481      -- IF p_camp_elements_rec.p_camp_sch = 'Y' THEN
2482      --    OPEN c_camp_sche(x_campaign_id);
2483      -- LOOP
2484      --    FETCH c_camp_sche INTO l_src_campaign_schedule_id;
2485      --    EXIT WHEN c_camp_sche%NOTFOUND;
2486      --       ams_copyelements_pvt.copy_campaign_schedules
2487      --                 ( p_init_msg_list        => fnd_api.g_true,
2488      --                   p_api_version          => l_api_version,
2489      --                   x_return_status        => l_return_status,
2490      --                   x_msg_count            => l_msg_count,
2491      --                   x_msg_data             => l_msg_data,
2492      --                   x_campaign_schedule_id => l_campaign_schedule_id,
2493      --                   p_src_camp_schedule_id => l_src_campaign_schedule_id,
2494      --                   p_new_camp_id          => x_campaign_id);
2495      --  END LOOP;
2496      --  CLOSE c_camp_sche;
2497      -- END IF;
2498 
2499       IF p_camp_elements_rec.p_access = 'Y' THEN
2500          ams_copyelements_pvt.copy_act_access
2501                         ( p_src_act_type => 'CAMP',
2502                           p_src_act_id   => p_src_camp_id,
2503                           p_new_act_id   => x_campaign_id,
2504                           p_errnum       => l_errnum,
2505                           p_errcode      => l_errcode,
2506                           p_errmsg       =>   l_errmsg);
2507       END IF;
2508 
2509 
2510        IF p_camp_elements_rec.p_messages = 'Y' THEN
2511           ams_copyelements_pvt.copy_act_messages
2512                               ( p_src_act_type  =>'CAMP',
2513                                 p_src_act_id    =>p_src_camp_id,
2514                                 p_new_act_id    =>x_campaign_id,
2515                                 p_errnum        =>l_errnum,
2516                                 p_errcode       =>l_errcode,
2517                                 p_errmsg        =>l_errmsg);
2518       END IF;
2519 
2520       IF p_camp_elements_rec.p_attachments = 'Y' THEN
2521           ams_copyelements_pvt.copy_act_attachments
2522                               ( p_src_act_type  =>'CAMP',
2523                                 p_src_act_id    =>p_src_camp_id,
2524                                 p_new_act_id    =>x_campaign_id,
2525                                 p_errnum        =>l_errnum,
2526                                 p_errcode       =>l_errcode,
2527                                 p_errmsg        =>l_errmsg);
2528       END IF;
2529 
2530 
2531 
2532         -- If the user wants to copy access then the access flag should
2533         -- be 'Y' (Yes)
2534          IF p_camp_elements_rec.p_products = 'Y' THEN
2535             ams_copyelements_pvt.copy_act_prod
2536                             ( p_src_act_type   => 'CAMP',
2537                               p_src_act_id     => p_src_camp_id,
2538                               p_new_act_id     => x_campaign_id,
2539                               p_errnum         => l_errnum,
2540                               p_errcode        => l_errcode,
2541                               p_errmsg         => l_errmsg);
2542       END IF;
2543 
2544         -- If the user wants to copy geo_areas then the geo_area
2545         -- flag should be 'Y' (Yes)
2546          IF p_camp_elements_rec.p_geo_areas = 'Y' THEN
2547             ams_copyelements_pvt.copy_act_geo_areas
2548                                ( p_src_act_type => 'CAMP',
2549                                  p_src_act_id   => p_src_camp_id,
2550                                  p_new_act_id   => x_campaign_id,
2551                                  p_errnum       => l_errnum,
2552                                  p_errcode      => l_errcode,
2553                                  p_errmsg       => l_errmsg);
2554        END IF;
2555 
2556 
2557       --If the user wants to copy object_associatiosn then the
2558       -- obj_asso flag should be 'Y' (Yes).
2559       --If will copy all the associations of the campaign
2560 
2561        IF p_camp_elements_rec.p_obj_asso = 'Y' THEN
2562 
2563         ams_copyelements_pvt.copy_object_associations
2564                                       ( p_src_act_type => 'CAMP',
2565                                         p_src_act_id   => p_src_camp_id,
2566                                         p_new_act_id   => x_campaign_id,
2567                                         p_errnum       => l_errnum,
2568                                         p_errcode      => l_errcode,
2569                                         p_errmsg       => l_errmsg);
2570        END IF;
2571 
2572 
2573     -- If the user wants to copy resources then the resources flag should
2574     -- be 'Y' (Yes)
2575     --    IF p_camp_elements_rec.p_resources = 'Y' THEN
2576     --
2577     --    ams_copyelements_pvt.copy_act_resources( p_src_act_type   => 'CAMP',
2578     --                          p_src_act_id     => p_src_camp_id,
2579     --                          p_new_act_id     => x_campaign_id,
2580     --                          p_errnum         => l_errnum,
2581     --                          p_errcode        => l_errcode,
2582     --                          p_errmsg         => l_errmsg);
2583     --     END IF;
2584 
2585 
2586     --   IF p_camp_elements_rec.p_offers = 'Y' THEN
2587 
2588     --  ams_copyelements_pvt.copy_act_offers
2589     --                          ( p_src_act_type =>'CAMP',
2590     --                            p_src_act_id   =>p_src_camp_id,
2591     --                            p_new_act_id   =>x_campaign_id,
2592     --                            p_errnum       =>l_errnum,
2593     --                            p_errcode      =>l_errcode,
2594     --                            p_errmsg       =>l_errmsg);
2595     --    END IF;
2596 
2597 
2598       IF p_camp_elements_rec.p_segments = 'Y' THEN
2599          ams_copyelements_pvt.copy_act_market_segments
2600                                      ( p_src_act_type =>'CAMP',
2601                                        p_src_act_id   =>p_src_camp_id,
2602                                        p_new_act_id   =>x_campaign_id,
2603                                        p_errnum       =>l_errnum,
2604                                        p_errcode      =>l_errcode,
2605                                        p_errmsg       =>l_errmsg);
2606        END IF;
2607 
2608 
2609        IF p_camp_elements_rec.p_tasks = 'Y' THEN
2610            FOR tasks_rec in cur_get_tasks(p_src_camp_id) LOOP
2611               ams_copyelements_pvt.copy_tasks
2612                                 (p_init_msg_list        => fnd_api.g_true,
2613                                  p_api_version          => l_api_version,
2614                                  x_return_status        => l_return_status,
2615                                  x_msg_count            => l_msg_count,
2616                                  x_msg_data             => l_msg_data,
2617                                  p_old_camp_id          => p_src_camp_id,
2618                                  p_new_camp_id          => x_campaign_id,
2619                                  p_task_id              => tasks_rec.task_id ,
2620                                  p_owner_id             =>  l_owner_user_id  ,
2621                                  p_actual_due_date      =>
2622                                                l_camp_rec.actual_exec_end_date );
2623            END LOOP;
2624          END IF;
2625 
2626        IF p_camp_elements_rec.p_partners = 'Y' THEN
2627 
2628         ams_copyelements_pvt.copy_partners
2629                                   (p_init_msg_list        => fnd_api.g_true,
2630                                    p_api_version          => l_api_version,
2631                                    x_return_status        => l_return_status,
2632                                    x_msg_count            => l_msg_count,
2633                                    x_msg_data             => l_msg_data,
2634                                    p_old_camp_id          => p_src_camp_id,
2635                                    p_new_camp_id          => x_campaign_id);
2636          END IF;
2637 
2638 
2639        IF p_camp_elements_rec.p_sub_camp = 'Y' THEN
2640             FOR sub_camp_rec IN sub_camp_cur  LOOP
2641 			commit;
2642                copy_campaign( p_api_version       => 1,
2643                               p_init_msg_list     => fnd_api.g_true,
2644                               x_return_status     => l_return_status,
2645                               x_msg_data          => l_msg_data,
2646                               x_msg_count         => l_msg_count,
2647                               p_src_camp_id       => sub_camp_rec.campaign_id,
2648                               p_new_camp_name     => sub_camp_rec.campaign_name,
2649                               p_par_camp_id       => x_campaign_id,
2650                               x_campaign_id       => x_sub_camp_id,
2651                               p_camp_elements_rec => p_camp_elements_rec,
2652                               p_start_date        => p_start_date);
2653             END LOOP;
2654 
2655    END IF;
2656     -- End of Log
2657     -- General Message saying copying has started
2658     fnd_message.set_name('AMS','AMS_END_COPY_ELEMENTS');
2659     fnd_message.set_token('ELEMENTS',l_lookup_meaning,TRUE);
2660     fnd_message.set_token('ELEMENT_NAME',p_new_camp_name,TRUE);
2661     l_mesg_text := fnd_message.get ;
2662 
2663     -- Writing to PL/SQL table
2664     ams_cpyutility_pvt.write_log_mesg( 'CAMP',
2665                                        p_src_camp_id,
2666                                        l_mesg_text,
2667                                        'GENERAL');
2668 
2669    IF   l_return_status  =  FND_API.G_RET_STS_SUCCESS  THEN
2670       COMMIT ;
2671    END IF ;
2672    EXCEPTION
2673        WHEN FND_API.G_EXC_ERROR THEN
2674           ROLLBACK TO Copy_Campaign_PVT;
2675           x_return_status := FND_API.G_RET_STS_ERROR ;
2676           FND_MSG_PUB.Count_and_Get ( p_count => x_msg_count,
2677                                       p_data  => x_msg_data
2678                                     );
2679        WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2680           ROLLBACK TO Copy_Campaign_PVT;
2681           x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2682           FND_MSG_PUB.Count_and_Get ( p_count => x_msg_count,
2683                                       p_data  => x_msg_data
2684                                     );
2685        WHEN OTHERS THEN
2686           ROLLBACK TO Copy_Campaign_PVT;
2687           x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2688           IF FND_MSG_PUB.Check_Msg_Level
2689                  (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )
2690           THEN
2691              FND_MSG_PUB.Add_Exc_MSG ( G_FILE_NAME,
2692                                        G_PKG_NAME,
2693                                        l_api_name
2694                                      );
2695            END IF;
2696            FND_MSG_PUB.Count_and_Get (p_count => x_msg_count,
2697                                       p_data  => x_msg_data
2698                                      );
2699 
2700 END Copy_Campaign;
2701 
2702 
2703 
2704 
2705 
2706 
2707    PROCEDURE copy_schedule_attributes (
2708       p_api_version     IN NUMBER,
2709       p_init_msg_list   IN VARCHAR2 := FND_API.G_FALSE,
2710       p_commit          IN VARCHAR2 := FND_API.G_FALSE,
2711       x_return_status   OUT NOCOPY VARCHAR2,
2712       x_msg_count       OUT NOCOPY NUMBER,
2713       x_msg_data        OUT NOCOPY VARCHAR2,
2714       p_object_type     IN VARCHAR2,
2715       p_src_object_id   IN NUMBER,
2716       p_tar_object_id   IN NUMBER,
2717       p_attr_list       IN schedule_attr_rec_type
2718    )
2719    IS
2720    L_API_NAME           CONSTANT VARCHAR2(30) := 'copy_schedule_attributes';
2721    L_API_VERSION_NUMBER CONSTANT NUMBER := 1.0;
2722    L_API_VERSION        CONSTANT NUMBER := 1.0;
2723    l_errnum                       NUMBER;
2724    l_errmsg                       VARCHAR2(3000);
2725    l_errcode                      VARCHAR2(80);
2726    l_return_status  VARCHAR2(1);
2727    l_msg_count      NUMBER;
2728    l_msg_data       VARCHAR2(2000);
2729 
2730    CURSOR c_rel_event_id(p_sch_id NUMBER) IS
2731    SELECT related_event_id
2732    FROM   ams_campaign_schedules_b
2733    WHERE  schedule_id = p_sch_id;
2734 
2735    l_src_eone_id  NUMBER;
2736    l_tar_eone_id  NUMBER;
2737 
2738 
2739 BEGIN
2740    -- Standard Start of API savepoint
2741    SAVEPOINT copy_schedule_savepoint;
2742 
2743    -- Standard call to check for call compatibility.
2744    IF NOT FND_API.Compatible_API_Call ( l_api_version_number,
2745                                         p_api_version,
2746                                         l_api_name,
2747                                         G_PKG_NAME)
2748    THEN
2749        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2750    END IF;
2751 
2752    -- Initialize message list if p_init_msg_list is set to TRUE.
2753    IF FND_API.to_Boolean( p_init_msg_list )THEN
2754       FND_MSG_PUB.initialize;
2755    END IF;
2756 
2757    IF (AMS_DEBUG_HIGH_ON) THEN
2758 
2759 
2760 
2761        AMS_UTILITY_PVT.debug_message('Private API: ' || l_api_name || ' start');
2762 
2763    END IF;
2764 
2765    -- Initialize API return status to SUCCESS
2766    x_return_status := FND_API.G_RET_STS_SUCCESS;
2767 
2768    --
2769    -- Start of API body.
2770    --
2771 
2772    -- start copying stuff
2773 
2774    -- Event Agenda    AGEN // Leave for later
2775 
2776    -- Attachments     ATCH
2777    IF p_attr_list.p_ATCH = 'Y'
2778    THEN
2779       --Modified by rrajesh on 10/18/01
2780        /*ams_copyelements_pvt.copy_act_attachments(
2781                          p_src_act_type => 'CSCH',
2782                          p_src_act_id   => p_src_object_id,
2783                          p_new_act_id   => p_tar_object_id,
2784                          p_errnum       => l_errnum,
2785                          p_errcode      => l_errcode,
2786                          p_errmsg       => l_errmsg);*/
2787        ams_copyelements_pvt.copy_act_attachments(
2788                          p_src_act_type => 'AMS_CSCH',
2789                          p_src_act_id   => p_src_object_id,
2790                          p_new_act_id   => p_tar_object_id,
2791                          p_errnum       => l_errnum,
2792                          p_errcode      => l_errcode,
2793                          p_errmsg       => l_errmsg);
2794       -- end change 10/18/01
2795    END IF;
2796 
2797    -- Event Category  CATG // Leave for later
2798    IF p_attr_list.p_CATG = 'Y'
2799    THEN
2800        ams_copyelements_pvt.copy_act_categories(
2801                          p_src_act_type => 'CSCH',
2802                          p_src_act_id   => p_src_object_id,
2803                          p_new_act_id   => p_tar_object_id,
2804                          p_errnum       => l_errnum,
2805                          p_errcode      => l_errcode,
2806                          p_errmsg       => l_errmsg);
2807    END IF;
2808 
2809    -- Market          CELL
2810    IF p_attr_list.p_CELL = 'Y'
2811    THEN
2812        ams_copyelements_pvt.copy_act_market_segments(
2813                          p_src_act_type => 'CSCH',
2814                          p_src_act_id   => p_src_object_id,
2815                          p_new_act_id   => p_tar_object_id,
2816                          p_errnum       => l_errnum,
2817                          p_errcode      => l_errcode,
2818                          p_errmsg       => l_errmsg);
2819    END IF;
2820 
2821    -- Deliverables    DELV
2822    IF p_attr_list.p_DELV = 'Y'
2823    THEN
2824        ams_copyelements_pvt.copy_object_associations(
2825                          p_src_act_type => 'CSCH',
2826                          p_src_act_id   => p_src_object_id,
2827                          p_new_act_id   => p_tar_object_id,
2828                          p_errnum       => l_errnum,
2829                          p_errcode      => l_errcode,
2830                          p_errmsg       => l_errmsg);
2831    END IF;
2832 
2833    -- Messages        MESG
2834    IF p_attr_list.p_MESG = 'Y'
2835    THEN
2836        ams_copyelements_pvt.copy_act_messages(
2837                          p_src_act_type => 'CSCH',
2838                          p_src_act_id   => p_src_object_id,
2839                          p_new_act_id   => p_tar_object_id,
2840                          p_errnum       => l_errnum,
2841                          p_errcode      => l_errcode,
2842                          p_errmsg       => l_errmsg);
2843    END IF;
2844 
2845    -- Products        PROD
2846    IF p_attr_list.p_PROD = 'Y'
2847    THEN
2848        ams_copyelements_pvt.copy_act_prod(
2849                          p_src_act_type => 'CSCH',
2850                          p_src_act_id   => p_src_object_id,
2851                          p_new_act_id   => p_tar_object_id,
2852                          p_errnum       => l_errnum,
2853                          p_errcode      => l_errcode,
2854                          p_errmsg       => l_errmsg);
2855    END IF;
2856 
2857 
2858     -- COLLAB - TASKS     TASK
2859     -- start add by spragupa on 23-nov-2007 for ER 6467510 - extens copy functionality for tasks
2860    IF p_attr_list.p_TASK = 'Y'
2861    THEN
2862        ams_copyelements_pvt.copy_act_task(
2863                          p_src_act_type => 'AMS_CSCH',
2864                          p_src_act_id   => p_src_object_id,
2865                          p_new_act_id   => p_tar_object_id,
2866                          p_errnum       => l_errnum,
2867                          p_errcode      => l_errcode,
2868                          p_errmsg       => l_errmsg);
2869    END IF;
2870 
2871     -- end add by spragupa on 23-nov-2007 for ER 6467510 - extens copy functionality for tasks
2872 
2873    -- Partners        PTNR
2874    IF p_attr_list.p_PTNR = 'Y'
2875    THEN
2876        ams_copyelements_pvt.copy_partners_generic(
2877                          p_api_version => l_api_version,
2878                          p_init_msg_list => fnd_api.g_false,
2879                          x_return_status   => l_return_status,
2880                          x_msg_count   => l_msg_count,
2881                          x_msg_data     =>  l_msg_data,
2882                          p_old_id      => p_src_object_id,
2883                          p_new_id      => p_tar_object_id,
2884                          p_type       => 'CSCH');
2885    END IF;
2886 
2887    -- Registration    REGS // Leave for later
2888 
2889    -- added by soagrawa on 25-jan-2002
2890    -- Content       CONTENT
2891    IF p_attr_list.p_CONTENT = 'Y'
2892    THEN
2893        ams_copyelements_pvt.copy_act_content(
2894                          p_src_act_type => 'AMS_CSCH',
2895                          p_src_act_id   => p_src_object_id,
2896                          p_new_act_id   => p_tar_object_id,
2897                          p_errnum       => l_errnum,
2898                          p_errcode      => l_errcode,
2899                          p_errmsg       => l_errmsg);
2900    END IF;
2901 
2902    -- added by sodixit on 04-oct-2003 for 11.5.10
2903    -- Copy Target Group
2904    IF p_attr_list.p_TGRP = 'Y'
2905    THEN
2906        AMS_Utility_PVT.debug_message (
2907 			FND_LOG.LEVEL_EVENT,
2908 			'ams.plsql.ams_copyactivities_pvt.copy_schedule_attributes',
2909 			'Calling ams_copyelements_pvt.copy_target_group');
2910        AMS_Utility_PVT.debug_message (
2911 			FND_LOG.LEVEL_EVENT,
2912 			'ams.plsql.ams_copyactivities_pvt.copy_schedule_attributes',
2913 			'p_src_object_id='||p_src_object_id);
2914        AMS_Utility_PVT.debug_message (
2915 			FND_LOG.LEVEL_EVENT,
2916 			'ams.plsql.ams_copyactivities_pvt.copy_schedule_attributes',
2917 			'p_tar_object_id='||p_tar_object_id);
2918        ams_copyelements_pvt.copy_target_group(
2919                         p_src_act_type => 'CSCH',
2920                          p_src_act_id   => p_src_object_id,
2921                          p_new_act_id   => p_tar_object_id,
2922                          p_errnum       => l_errnum,
2923                          p_errcode      => l_errcode,
2924                          p_errmsg       => l_errmsg);
2925    END IF;
2926 
2927    -- added by sodixit on 04-oct-2003 for 11.5.10
2928    -- Copy Collateral
2929    IF p_attr_list.p_COLT = 'Y'
2930    THEN
2931        AMS_Utility_PVT.debug_message (
2932 			FND_LOG.LEVEL_EVENT,
2933 			'ams.plsql.ams_copyactivities_pvt.copy_schedule_attributes',
2934 			'Calling ams_copyelements_pvt.copy_act_collateral');
2935        AMS_Utility_PVT.debug_message (
2936 			FND_LOG.LEVEL_EVENT,
2937 			'ams.plsql.ams_copyactivities_pvt.copy_schedule_attributes',
2938 			'p_src_object_id='||p_src_object_id);
2939        AMS_Utility_PVT.debug_message (
2940 			FND_LOG.LEVEL_EVENT,
2941 			'ams.plsql.ams_copyactivities_pvt.copy_schedule_attributes',
2942 			'p_tar_object_id='||p_tar_object_id);
2943        ams_copyelements_pvt.copy_act_collateral(
2944                          p_src_act_type => 'AMS_CSCH',
2945                          p_src_act_id   => p_src_object_id,
2946                          p_new_act_id   => p_tar_object_id,
2947                          p_errnum       => l_errnum,
2948                          p_errcode      => l_errcode,
2949                          p_errmsg       => l_errmsg);
2950        -- anchaudh added for copy of collateral contents attached to the non-direct marketing activities.
2951        ams_copyelements_pvt.copy_act_collateral(
2952                          p_src_act_type => 'AMS_COLLAT',
2953                          p_src_act_id   => p_src_object_id,
2954                          p_new_act_id   => p_tar_object_id,
2955                          p_errnum       => l_errnum,
2956                          p_errcode      => l_errcode,
2957                          p_errmsg       => l_errmsg);
2958    END IF;
2959 
2960    -- soagrawa added AGEN on 29-may-2003 for bug# 2949268
2961    -- Agenda       AGEN
2962    IF p_attr_list.p_AGEN = 'Y'
2963    THEN
2964 
2965       OPEN  c_rel_event_id (p_src_object_id);
2966       FETCH c_rel_event_id INTO l_src_eone_id;
2967       CLOSE c_rel_event_id;
2968 
2969       OPEN  c_rel_event_id (p_tar_object_id);
2970       FETCH c_rel_event_id INTO l_tar_eone_id;
2971       CLOSE c_rel_event_id;
2972 
2973       IF l_src_eone_id IS NOT NULL AND l_tar_eone_id IS NOT null
2974       THEN
2975          ams_eventschedule_copy_pvt.copy_event_schedule_agenda (
2976             p_src_act_type   => 'EONE',
2977             p_new_act_type   => 'EONE',
2978             p_src_act_id     => l_src_eone_id,
2979             p_new_act_id     => l_tar_eone_id,
2980             p_errnum         => l_errnum,
2981             p_errcode        => l_errcode,
2982             p_errmsg         => l_errmsg
2983          );
2984       END IF;
2985    END IF;
2986 
2987    --
2988    -- End of API body.
2989    --
2990 
2991    -- Standard check for p_commit
2992    IF FND_API.to_Boolean( p_commit ) THEN
2993       COMMIT WORK;
2994    END IF;
2995 
2996 
2997    -- Debug Message
2998    IF (AMS_DEBUG_HIGH_ON) THEN
2999 
3000        AMS_UTILITY_PVT.debug_message('Private API: ' || l_api_name || ' end');
3001    END IF;
3002 
3003    -- Standard call to get message count and if count is 1, get message info.
3004    FND_MSG_PUB.Count_And_Get (
3005       p_count  => x_msg_count,
3006       p_data   => x_msg_data
3007    );
3008 EXCEPTION
3009    WHEN FND_API.G_EXC_ERROR THEN
3010       ROLLBACK TO copy_schedule_savepoint;
3011       x_return_status := FND_API.G_RET_STS_ERROR;
3012       -- Standard call to get message count and if count=1, get the message
3013       FND_MSG_PUB.Count_And_Get (
3014          p_encoded => FND_API.G_FALSE,
3015          p_count   => x_msg_count,
3016          p_data    => x_msg_data
3017       );
3018    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3019       ROLLBACK TO copy_schedule_savepoint;
3020       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3021       -- Standard call to get message count and if count=1, get the message
3022       FND_MSG_PUB.Count_And_Get (
3023          p_encoded => FND_API.G_FALSE,
3024          p_count => x_msg_count,
3025          p_data  => x_msg_data
3026       );
3027    WHEN OTHERS THEN
3028       ROLLBACK TO copy_schedule_savepoint;
3029       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3030       IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
3031          FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
3032       END IF;
3033       -- Standard call to get message count and if count=1, get the message
3034       FND_MSG_PUB.Count_And_Get (
3035          p_encoded => FND_API.G_FALSE,
3036          p_count => x_msg_count,
3037          p_data  => x_msg_data
3038       );
3039 END copy_schedule_attributes;
3040 
3041 PROCEDURE WRITE_TO_ACT_LOG(p_msg_data in VARCHAR2,
3042                            p_arc_log_used_by in VARCHAR2 DEFAULT 'CAMP',
3043                            p_log_used_by_id in number)
3044                            IS
3045  PRAGMA AUTONOMOUS_TRANSACTION;
3046  l_return_status VARCHAR2(1);
3047 BEGIN
3048   AMS_UTILITY_PVT.CREATE_LOG(
3049                              x_return_status    => l_return_status,
3050                              p_arc_log_used_by  => 'CAMP',
3051                              p_log_used_by_id   => p_log_used_by_id,
3052                              p_msg_data         => p_msg_data);
3053   COMMIT;
3054 END WRITE_TO_ACT_LOG;
3055 
3056 
3057 END;