DBA Data[Home] [Help]

PACKAGE BODY: APPS.EAM_ACTIVITY_PUB

Source


1 PACKAGE BODY EAM_Activity_PUB AS
2 /* $Header: EAMPACTB.pls 120.3.12020000.2 2012/07/05 10:34:47 vpasupur ship $ */
3 
4 G_PKG_NAME 	CONSTANT VARCHAR2(30):='EAM_AssetActivity_PUB';
5 
6 
7 -- ======================================================================
8 -- Private Helper Functions
9 
10 PROCEDURE Validate_Copy_Activity_Options(
11 	p_bom_copy_option		IN	NUMBER,
12 	p_routing_copy_option		IN	NUMBER,
13 	p_association_copy_option	IN	NUMBER
14 )
15 IS
16 BEGIN
17 
18 	IF p_bom_copy_option NOT IN (1, 2) THEN
19 		FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_ACTCOPY_BOM_COPY_OPT');
20 --		FND_MESSAGE.SET_ENCODED('BOM Copy Option should be 1 (NONE) or 2 (ALL).');
21 		EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
22 		RAISE FND_API.G_EXC_ERROR;
23 	END IF;
24 
25 	IF p_routing_copy_option NOT IN (1, 2) THEN
26 		FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_ACTCOPY_RTG_COPY_OPT');
27 --		FND_MESSAGE.SET_ENCODED('Routing Copy Option should be 1 (NONE) or 2 (ALL).');
28 		EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
29 		RAISE FND_API.G_EXC_ERROR;
30 	END IF;
31 
32 	IF p_bom_copy_option NOT IN (1, 2) THEN
33 		FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_ACTCOPY_ASC_COPY_OPT');
34 --		FND_MESSAGE.SET_ENCODED('Association Copy Option should be 1 (NONE) or 2 (ALL).');
35 		EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
36 		RAISE FND_API.G_EXC_ERROR;
37 	END IF;
38 
39 END;
40 
41 PROCEDURE Validate_Copy_Options(
42 	p_work_order_rec		IN EAM_Activity_PUB.Work_Order_Rec_Type,
43 	p_operation_copy_option		IN NUMBER,
44 	p_material_copy_option		IN NUMBER,
45 	p_resource_copy_option		IN NUMBER,
46 	p_association_copy_option	IN NUMBER
47 )
48 IS
49 	l_activity_id_from_wo		NUMBER;
50 BEGIN
51 	-- Validate p_operation_copy_option, p_material_copy_option, and p_resource_copy_option
52 	IF p_operation_copy_option = 1 THEN
53 		-- p_operation_copy_option = 1 (NONE)
54 		-- p_material_copy_option and p_resource_copy_option both as to be 1 (NONE)
55 		IF p_material_copy_option <> 1 THEN
56 			-- Error: Material Copy Option has to be 1 (NONE) when Operation Copy Option is 1 (NONE).
57 			FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_MAT_COPY_OPT_NOT_NONE');
58 --			FND_MESSAGE.SET_ENCODED('Material Copy Option has to be 1 (NONE) when Operation Copy Option is 1 (NONE).');
59 			EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
60 			RAISE FND_API.G_EXC_ERROR;
61 		END IF;
62 		IF p_resource_copy_option <> 1 THEN
63 			-- Error: Resource Copy Option has to be 1 (NONE) when Operation Copy Option is 1 (NONE).
64 			FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_RES_COPY_OPT_NOT_NONE');
65 --			FND_MESSAGE.SET_ENCODED('Resource Copy Option has to be 1 (NONE) when Operation Copy Option is 1 (NONE).');
66 			EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
67 			RAISE FND_API.G_EXC_ERROR;
68 		END IF;
69 	ELSIF p_operation_copy_option = 2 THEN
70 		-- p_operation_copy_option = 2 (ALL)
71 		-- p_material_copy_option and p_resource_copy_option can be 1 (NONE), 2 (ISSUED), or 3 (ALL)
72 
73 		IF p_material_copy_option NOT IN (1, 2, 3) THEN
74 			-- Error: Material Copy Option should be either 1 (NONE), 2 (ISSUED), or 3 (ALL).
75 			FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_MAT_COPY_OPT_INVALID');
76 --			FND_MESSAGE.SET_ENCODED('Material Copy Option should be either 1 (NONE), 2 (ISSUED), or 3 (ALL).');
77 			RAISE FND_API.G_EXC_ERROR;
78 			EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
79 		END IF;
80 		IF p_resource_copy_option NOT IN (1, 2, 3) THEN
81 			-- Error: Resource Copy Option should be either 1 (NONE), 2 (ISSUED), or 3 (ALL).
82 			FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_RES_COPY_OPT_INVALID');
83 --			FND_MESSAGE.SET_ENCODED('Resource Copy Option should be either 1 (NONE), 2 (ISSUED), or 3 (ALL).');
84 			EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
85 			RAISE FND_API.G_EXC_ERROR;
86 		END IF;
87 	ELSE
88 		-- Error: Operation Copy Option should be either 1 (NONE), or 2 (ALL).
89 		FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_OP_COPY_OPT_INVALID');
90 --		FND_MESSAGE.SET_ENCODED('Operation Copy Option should be either 1 (NONE), or 2 (ALL).');
91 		EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
92 		RAISE FND_API.G_EXC_ERROR;
93 	END IF;
94 
95 	-- Validation of p_association_copy_option is independent of the others.
96 
97 	-- First need to find out if source Work Order as an Activity linked to it.
98 
99 
100 	-- 2003-01-10: Enchancement: if source Work Order has no Activity, treat Copy Option All as Current
101 	-- So don't have to check for source Work Order Activity any more.
102 
103 	/*
104 	l_activity_id_from_wo := EAM_ActivityUtilities_PVT.Get_Act_Id_From_Work_Order(p_work_order_rec.wip_entity_id);
105 	IF l_activity_id_from_wo IS NULL THEN
106 		-- No Activity linked to source Work Order
107 		IF p_association_copy_option NOT IN (1, 2) THEN
108 			-- Error: When Source Work Order is not linked to an Activity, Association Copy Option should be either 1 (NONE), or 2 (CURRENT).
109 			FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_ASSO_COPY_OPT_NO_ACT');
110 --			FND_MESSAGE.SET_ENCODED('When Source Work Order is not linked to an Activity, Association Copy Option should be either 1 (NONE), or 2 (CURRENT).');
111 			EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
112 			RAISE FND_API.G_EXC_ERROR;
113 		END IF;
114 	ELSE
115 		-- l_activity_id_from_wo IS NOT NULL
116 */
117 		IF p_association_copy_option NOT IN (1, 2, 3) THEN
118 			-- Error: Association Copy Option should be either 1 (NONE), 2 (CURRENT), or 3 (ALL).
119 			FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_ASSO_COPY_OPT_INVALID');
120 --			FND_MESSAGE.SET_ENCODED('Association Copy Option should be either 1 (NONE), 2 (CURRENT), or 3 (ALL).');
121 			EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
122 			RAISE FND_API.G_EXC_ERROR;
123 		END IF;
124 /*
125 	END IF;
126 */
127 END;
128 
129 -- ----------------------------------------------------------------------
130 PROCEDURE Create_Activity_Routing(
131 	p_target_item_rec			IN INV_Item_GRP.Item_Rec_Type,
132 	p_work_order_rec		IN EAM_Activity_PUB.Work_Order_Rec_Type,
133 	p_operation_copy_option		IN NUMBER,
134 	p_resource_copy_option		IN NUMBER,
135 
136 	x_rtg_header_rec		OUT NOCOPY	BOM_Rtg_Pub.Rtg_Header_Rec_Type,
137 	x_rtg_revision_tbl		OUT NOCOPY	BOM_Rtg_Pub.Rtg_Revision_Tbl_Type,
138 	x_operation_tbl			OUT NOCOPY	BOM_Rtg_Pub.Operation_Tbl_Type,
139 	x_op_resource_tbl		OUT NOCOPY	BOM_Rtg_Pub.Op_Resource_Tbl_Type,
140 	x_sub_resource_tbl		OUT NOCOPY	BOM_Rtg_Pub.Sub_Resource_Tbl_Type,
141 	x_op_network_tbl		OUT NOCOPY	BOM_Rtg_Pub.Op_Network_Tbl_Type,
142 	x_rtg_return_status		OUT NOCOPY	VARCHAR2,
143 	x_rtg_msg_count			OUT NOCOPY	NUMBER,
144 	x_rtg_msg_list			OUT NOCOPY	Error_Handler.Error_Tbl_Type
145 )
146 
147 IS
148 l_current_date			CONSTANT DATE := sysdate;
149 l_effectivity_date		CONSTANT DATE := l_current_date;
150 l_create_txn_type		CONSTANT VARCHAR(10) := 'CREATE';
151 
152 -- misc local var
153 l_x_pos				NUMBER;
154 l_y_pos				NUMBER;
155 
156 -- local variables for call the Routing Business Object API
157 l_rtg_header_rec		BOM_RTG_PUB.Rtg_Header_Rec_Type;
158 l_operation_tbl			BOM_RTG_PUB.Operation_Tbl_Type;
159 l_operation_tbl_index		BINARY_INTEGER;
160 l_op_resource_tbl		BOM_RTG_PUB.Op_Resource_Tbl_Type;
161 l_op_resource_tbl_index		BINARY_INTEGER;
162 l_op_network_tbl		BOM_RTG_PUB.Op_Network_Tbl_Type;
163 l_op_network_tbl_index		BINARY_INTEGER;
164 
165 l_x_rtg_header_rec		BOM_RTG_PUB.Rtg_Header_Rec_Type;
166 l_x_rtg_revision_tbl		BOM_RTG_PUB.Rtg_Revision_Tbl_Type;
167 l_x_operation_tbl		BOM_RTG_PUB.Operation_Tbl_Type;
168 l_x_op_resource_tbl		BOM_RTG_PUB.Op_Resource_Tbl_Type;
169 l_x_sub_resource_tbl		BOM_RTG_PUB.Sub_Resource_Tbl_Type;
170 l_x_op_network_tbl		BOM_RTG_PUB.Op_Network_Tbl_Type;
171 l_x_rtg_return_status		VARCHAR2(1);
172 l_x_rtg_msg_count		NUMBER;
173 l_x_rtg_msg_list		Error_Handler.Error_Tbl_Type;
174 l_code  varchar2(4); -- 13519051
175 l_st_op_id NUMBER; -- 13519051
176 
177 CURSOR wip_operation_cur (
178 	p_organization_id	IN	NUMBER
179 ,	p_wip_entity_id		IN	NUMBER
180 )
181 IS
182 	SELECT 	*
183 	FROM 	wip_operations
184 	WHERE	wip_entity_id = p_wip_entity_id
185 	AND	organization_id = p_organization_id;
186 
187 CURSOR wip_op_network_cur (
188 	p_organization_id	IN	NUMBER
189 	, p_wip_entity_id	IN	NUMBER
190 )
191 IS
192 	SELECT 	*
193 	FROM	wip_operation_networks
194 	WHERE	organization_id = p_organization_id
195 	AND	wip_entity_id = p_wip_entity_id;
196 
197 CURSOR wip_resource_cur (
198 	p_organization_id	IN	NUMBER
199 ,	p_wip_entity_id		IN	NUMBER
200 )
201 IS
202 	SELECT	*
203 	FROM	wip_operation_resources
204 	WHERE	organization_id = p_organization_id
205 	AND	wip_entity_id = p_wip_entity_id;
206 
207 BEGIN
208 	EAM_ActivityUtilities_PVT.Write_Debug('---------- Entering EAM_Activity_PUB.Create_Activity_Routing ----------');
209 	EAM_ActivityUtilities_PVT.Write_Debug('p_operation_copy_option=' || p_operation_copy_option);
210 	EAM_ActivityUtilities_PVT.Write_Debug('p_resource_copy_option=' || p_resource_copy_option);
211 	EAM_ActivityUtilities_PVT.Write_Debug('p_target_item_rec.organization_id=' || p_target_item_rec.organization_id);
212 	EAM_ActivityUtilities_PVT.Write_Debug('p_target_item_rec.organization_code=' || p_target_item_rec.organization_code);
213 	EAM_ActivityUtilities_PVT.Write_Debug('p_target_item_rec.inventory_item_id=' || p_target_item_rec.inventory_item_id);
214 	EAM_ActivityUtilities_PVT.Write_Debug('p_target_item_rec.item_number=' || p_target_item_rec.item_number);
215 	EAM_ActivityUtilities_PVT.Write_Debug('p_work_order_rec.organization_id=' || p_work_order_rec.organization_id);
216 	EAM_ActivityUtilities_PVT.Write_Debug('p_work_order_rec.organization_code=' || p_work_order_rec.organization_code);
217 	EAM_ActivityUtilities_PVT.Write_Debug('p_work_order_rec.wip_entity_id=' || p_work_order_rec.wip_entity_id);
218 	EAM_ActivityUtilities_PVT.Write_Debug('p_work_order_rec.wip_entity_name=' || p_work_order_rec.wip_entity_name);
219 
220 
221 	-- Create Operations
222 	-- We need 1 Routing Header, table of Operations and Operation Networks, and table of Resources
223 	IF p_operation_copy_option = 2 THEN
224 		-- p_operation_copy_option = 2 (ALL)
225 
226 		-- 2 a) Set up rtg_header_rec
227 		-- First initialize record fields to NULL
228 --		l_rtg_header_rec := NULL;
229 		-- populate fields
230 		l_rtg_header_rec.Assembly_Item_Name := p_target_item_rec.Item_Number;
231 		l_rtg_header_rec.Organization_Code := p_target_item_rec.Organization_Code;
232 		l_rtg_header_rec.Transaction_Type := l_create_txn_type;
233 
234 		-- 2 b) Create operations
235 		l_operation_tbl_index := 1;
236 		FOR l_wip_operation_row IN wip_operation_cur(p_work_order_rec.organization_id,
237 							     p_work_order_rec.wip_entity_id)
238 		LOOP
239 
240 		 -- added for bug#13519051
241     		IF l_wip_operation_row.standard_operation_id is not NULL THEN
242 				select operation_code into l_code
243 				  from bom_standard_operations
244 				 where standard_operation_id = l_wip_operation_row.standard_operation_id;
245 			ELSE
246 				l_code := NULL;
247 			END IF;
248 
249 			-- First initialize the fields of the record to NULL
250 --			l_operation_tbl(l_operation_tbl_index) := NULL;
251 			-- Then populate fields from cursor.
252 			l_operation_tbl(l_operation_tbl_index).Transaction_Type := l_create_txn_type;
253 			l_operation_tbl(l_operation_tbl_index).Organization_Code := l_rtg_header_rec.Organization_Code;
254 			l_operation_tbl(l_operation_tbl_index).Assembly_Item_Name := l_rtg_header_rec.Assembly_Item_Name;
255 			l_operation_tbl(l_operation_tbl_index).Operation_Sequence_Number := l_wip_operation_row.Operation_Seq_Num;
256 			l_operation_tbl(l_operation_tbl_index).standard_operation_code := l_code;  -- 13519051
257 			l_operation_tbl(l_operation_tbl_index).Start_Effective_Date := l_effectivity_date;
258 			l_operation_tbl(l_operation_tbl_index).Department_Code :=
259 				EAM_ActivityUtilities_PVT.Get_Department_Code(l_wip_operation_row.Organization_Id,
260 										l_wip_operation_row.department_id);
261 			l_operation_tbl(l_operation_tbl_index).Operation_Description := l_wip_operation_row.Description;
262 			l_operation_tbl(l_operation_tbl_index).Count_Point_Type := l_wip_operation_row.count_point_type;
263 			l_operation_tbl(l_operation_tbl_index).Backflush_Flag := l_wip_operation_row.Backflush_Flag;
264 			l_operation_tbl(l_operation_tbl_index).Minimum_Transfer_Quantity := l_wip_operation_row.Minimum_Transfer_Quantity;
265 			l_operation_tbl(l_operation_tbl_index).Shutdown_Type := l_wip_operation_row.Shutdown_Type;
266 			l_operation_tbl(l_operation_tbl_index).Yield := l_wip_operation_row.Operation_Yield;
267 			l_operation_tbl(l_operation_tbl_index).Op_Yield_Enabled_Flag := l_wip_operation_row.Operation_Yield_Enabled;
268 
269 			l_operation_tbl(l_operation_tbl_index).Attribute_Category := l_wip_operation_row.Attribute_Category;
270 			l_operation_tbl(l_operation_tbl_index).Attribute1 := l_wip_operation_row.Attribute1;
271 			l_operation_tbl(l_operation_tbl_index).Attribute2 := l_wip_operation_row.Attribute2;
272 			l_operation_tbl(l_operation_tbl_index).Attribute3 := l_wip_operation_row.Attribute3;
273 			l_operation_tbl(l_operation_tbl_index).Attribute4 := l_wip_operation_row.Attribute4;
274 			l_operation_tbl(l_operation_tbl_index).Attribute5 := l_wip_operation_row.Attribute5;
275 			l_operation_tbl(l_operation_tbl_index).Attribute6 := l_wip_operation_row.Attribute6;
276 			l_operation_tbl(l_operation_tbl_index).Attribute7 := l_wip_operation_row.Attribute7;
277 			l_operation_tbl(l_operation_tbl_index).Attribute8 := l_wip_operation_row.Attribute8;
278 			l_operation_tbl(l_operation_tbl_index).Attribute9 := l_wip_operation_row.Attribute9;
279 			l_operation_tbl(l_operation_tbl_index).Attribute10 := l_wip_operation_row.Attribute10;
280 			l_operation_tbl(l_operation_tbl_index).Attribute11 := l_wip_operation_row.Attribute11;
281 			l_operation_tbl(l_operation_tbl_index).Attribute12 := l_wip_operation_row.Attribute12;
282 			l_operation_tbl(l_operation_tbl_index).Attribute13 := l_wip_operation_row.Attribute13;
283 			l_operation_tbl(l_operation_tbl_index).Attribute14 := l_wip_operation_row.Attribute14;
284 			l_operation_tbl(l_operation_tbl_index).Attribute15 := l_wip_operation_row.Attribute15;
285 
286 			--Added for bug 7678514
287 			l_operation_tbl(l_operation_tbl_index).Long_Description :=l_wip_operation_row.Long_Description;
288 
289 			l_operation_tbl_index := l_operation_tbl_index + 1;
290 		END LOOP;
291 
292 		-- 2 c) Create Operation Networks
293 		l_op_network_tbl_index := 1;
294 		FOR l_wip_op_network_row IN wip_op_network_cur(p_work_order_rec.organization_id,
295 							       p_work_order_rec.wip_entity_id)
296 		LOOP
297 --			l_op_network_tbl(l_op_network_tbl_index) := NULL;
298 			l_op_network_tbl(l_op_network_tbl_index).Transaction_Type := l_create_txn_type;
299 			l_op_network_tbl(l_op_network_tbl_index).Organization_Code := l_rtg_header_rec.Organization_Code;
300 			l_op_network_tbl(l_op_network_tbl_index).Assembly_Item_Name := l_rtg_header_rec.Assembly_Item_Name;
301 			l_op_network_tbl(l_op_network_tbl_index).From_Op_Seq_Number := l_wip_op_network_row.Prior_Operation;
302 			l_op_network_tbl(l_op_network_tbl_index).From_Start_Effective_Date := l_effectivity_date;
303 			l_op_network_tbl(l_op_network_tbl_index).To_Op_Seq_Number := l_wip_op_network_row.Next_Operation;
304 			l_op_network_tbl(l_op_network_tbl_index).To_Start_Effective_Date := l_effectivity_date;
305 
306 			EAM_ActivityUtilities_PVT.Get_Op_Coordinates(
307 				p_organization_id => p_work_order_rec.organization_id,
308 				p_wip_entity_id => p_work_order_rec.wip_entity_id,
309 				p_operation_seq_num => l_wip_op_network_row.Prior_Operation,
310 				x_x_pos => l_x_pos,
311 				x_y_pos => l_y_pos
312 			);
313 			l_op_network_tbl(l_op_network_tbl_index).From_X_Coordinate := l_x_pos;
314 			l_op_network_tbl(l_op_network_tbl_index).From_Y_Coordinate := l_y_pos;
315 
316 			EAM_ActivityUtilities_PVT.Get_Op_Coordinates(
317 				p_organization_id => p_work_order_rec.organization_id,
318 				p_wip_entity_id => p_work_order_rec.wip_entity_id,
319 				p_operation_seq_num => l_wip_op_network_row.Next_Operation,
320 				x_x_pos => l_x_pos,
321 				x_y_pos => l_y_pos
322 			);
323 			l_op_network_tbl(l_op_network_tbl_index).To_X_Coordinate := l_x_pos;
324 			l_op_network_tbl(l_op_network_tbl_index).To_Y_Coordinate := l_y_pos;
325 
326 			l_op_network_tbl(l_op_network_tbl_index).Attribute_Category := l_wip_op_network_row.Attribute_Category;
327 			l_op_network_tbl(l_op_network_tbl_index).Attribute1 := l_wip_op_network_row.Attribute1;
328 			l_op_network_tbl(l_op_network_tbl_index).Attribute2 := l_wip_op_network_row.Attribute2;
329 			l_op_network_tbl(l_op_network_tbl_index).Attribute3 := l_wip_op_network_row.Attribute3;
330 			l_op_network_tbl(l_op_network_tbl_index).Attribute4 := l_wip_op_network_row.Attribute4;
331 			l_op_network_tbl(l_op_network_tbl_index).Attribute5 := l_wip_op_network_row.Attribute5;
332 			l_op_network_tbl(l_op_network_tbl_index).Attribute6 := l_wip_op_network_row.Attribute6;
333 			l_op_network_tbl(l_op_network_tbl_index).Attribute7 := l_wip_op_network_row.Attribute7;
334 			l_op_network_tbl(l_op_network_tbl_index).Attribute8 := l_wip_op_network_row.Attribute8;
335 			l_op_network_tbl(l_op_network_tbl_index).Attribute9 := l_wip_op_network_row.Attribute9;
336 			l_op_network_tbl(l_op_network_tbl_index).Attribute10 := l_wip_op_network_row.Attribute10;
337 			l_op_network_tbl(l_op_network_tbl_index).Attribute11 := l_wip_op_network_row.Attribute11;
338 			l_op_network_tbl(l_op_network_tbl_index).Attribute12 := l_wip_op_network_row.Attribute12;
339 			l_op_network_tbl(l_op_network_tbl_index).Attribute13 := l_wip_op_network_row.Attribute13;
340 			l_op_network_tbl(l_op_network_tbl_index).Attribute14 := l_wip_op_network_row.Attribute14;
341 			l_op_network_tbl(l_op_network_tbl_index).Attribute15 := l_wip_op_network_row.Attribute15;
342 
343 			l_op_network_tbl_index := l_op_network_tbl_index + 1;
344 		END LOOP;
345 
346 
347 	END IF;	-- p_operation_option = 2
348 
349 	-- 2 d) Create Resources
350 	IF p_resource_copy_option = 1 THEN
351 		-- p_resource_copy_option = 1 (NONE), do nothing
352 		NULL;
353 	ELSIF p_resource_copy_option in (2, 3) THEN
354 		-- p_resource_copy_option = 2 (ISSUED), or 3 (ALL)
355 		l_op_resource_tbl_index := 1;
356 		FOR l_wip_resource_row IN wip_resource_cur(p_work_order_rec.organization_id,
357 							   p_work_order_rec.wip_entity_id)
358 		LOOP
359 
360 		-- added for bug#13519051
361             select wo.standard_operation_id  into l_st_op_id
362               from wip_operations wo
363              where wo.wip_entity_id= l_wip_resource_row.wip_entity_id
364                and wo.operation_seq_num=l_wip_resource_row.operation_seq_num
365 			   and wo.organization_id=l_wip_resource_row.organization_id;
366 
367     IF l_st_op_id is NULL THEN
368 
369 			-- First initialize the fields of the record to be NULL
370 --			l_op_resource_tbl(l_op_resource_tbl_index) := NULL;
371 			-- Then populate fields from cursor.
372 			l_op_resource_tbl(l_op_resource_tbl_index).Transaction_Type := l_create_txn_type;
373 			l_op_resource_tbl(l_op_resource_tbl_index).Organization_Code := l_rtg_header_rec.Organization_Code;
374 			l_op_resource_tbl(l_op_resource_tbl_index).Assembly_Item_Name := l_rtg_header_rec.Assembly_Item_Name;
375 			l_op_resource_tbl(l_op_resource_tbl_index).Operation_Sequence_Number := l_wip_resource_row.Operation_Seq_Num;
376 			l_op_resource_tbl(l_op_resource_tbl_index).Resource_Code :=
377 				EAM_ActivityUtilities_PVT.Get_Resource_Code(l_wip_resource_row.Organization_Id,
378 										l_wip_resource_row.Resource_Id);
379 			l_op_resource_tbl(l_op_resource_tbl_index).Op_Start_Effective_Date := l_effectivity_date;
380 			l_op_resource_tbl(l_op_resource_tbl_index).Resource_Sequence_Number := l_wip_resource_row.Resource_Seq_Num;
381 
382 			IF p_resource_copy_option = 2 THEN
383 				-- p_resource_copy_option = 2 (ISSUED)
384 				l_op_resource_tbl(l_op_resource_tbl_index).Usage_Rate_Or_Amount :=
385 					l_wip_resource_row.Applied_Resource_Units;
386 			ELSE
387 				-- p_resource_copy_option = 3 (ALL)
388 				l_op_resource_tbl(l_op_resource_tbl_index).Usage_Rate_Or_Amount :=
389 					EAM_ActivityUtilities_PVT.Get_WO_Res_Scheduled_Units(
390 						l_wip_resource_row.Organization_Id,
391 						l_wip_resource_row.Wip_Entity_Id,
392 						l_wip_resource_row.Operation_Seq_Num,
393 						l_wip_resource_row.Resource_Seq_Num);
394 			END IF;
395 
396 			l_op_resource_tbl(l_op_resource_tbl_index).Activity :=
397 				EAM_ActivityUtilities_PVT.Get_Cost_Activity(l_wip_resource_row.Activity_Id);
398 			l_op_resource_tbl(l_op_resource_tbl_index).Schedule_Flag := l_wip_resource_row.Scheduled_Flag;
399 			l_op_resource_tbl(l_op_resource_tbl_index).Assigned_Units := l_wip_resource_row.Assigned_Units;
400 			l_op_resource_tbl(l_op_resource_tbl_index).Autocharge_Type := l_wip_resource_row.Autocharge_Type;
401 			l_op_resource_tbl(l_op_resource_tbl_index).Standard_Rate_Flag := l_wip_resource_row.Standard_Rate_Flag;
402 			l_op_resource_tbl(l_op_resource_tbl_index).Principle_Flag := l_wip_resource_row.Principle_Flag;
403 
404 			l_op_resource_tbl(l_op_resource_tbl_index).Attribute_Category := l_wip_resource_row.Attribute_Category;
405 			l_op_resource_tbl(l_op_resource_tbl_index).Attribute1 := l_wip_resource_row.Attribute1;
406 			l_op_resource_tbl(l_op_resource_tbl_index).Attribute2 := l_wip_resource_row.Attribute2;
407 			l_op_resource_tbl(l_op_resource_tbl_index).Attribute3 := l_wip_resource_row.Attribute3;
408 			l_op_resource_tbl(l_op_resource_tbl_index).Attribute4 := l_wip_resource_row.Attribute4;
409 			l_op_resource_tbl(l_op_resource_tbl_index).Attribute5 := l_wip_resource_row.Attribute5;
410 			l_op_resource_tbl(l_op_resource_tbl_index).Attribute6 := l_wip_resource_row.Attribute6;
411 			l_op_resource_tbl(l_op_resource_tbl_index).Attribute7 := l_wip_resource_row.Attribute7;
412 			l_op_resource_tbl(l_op_resource_tbl_index).Attribute8 := l_wip_resource_row.Attribute8;
413 			l_op_resource_tbl(l_op_resource_tbl_index).Attribute9 := l_wip_resource_row.Attribute9;
414 			l_op_resource_tbl(l_op_resource_tbl_index).Attribute10 := l_wip_resource_row.Attribute10;
415 			l_op_resource_tbl(l_op_resource_tbl_index).Attribute11 := l_wip_resource_row.Attribute11;
416 			l_op_resource_tbl(l_op_resource_tbl_index).Attribute12 := l_wip_resource_row.Attribute12;
417 			l_op_resource_tbl(l_op_resource_tbl_index).Attribute13 := l_wip_resource_row.Attribute13;
418 			l_op_resource_tbl(l_op_resource_tbl_index).Attribute14 := l_wip_resource_row.Attribute14;
419 			l_op_resource_tbl(l_op_resource_tbl_index).Attribute15 := l_wip_resource_row.Attribute15;
420         END IF;
421 			l_op_resource_tbl_index := l_op_resource_tbl_index + 1;
422 		END LOOP;
423 
424 	ELSE
425 		-- since we performed validation on p_resource_copy_option already, shouldn't reach here.
426 		NULL;
427 	END IF;
428 
429 	-- 2 e) Call the Routing Business Object API
430 	-- Only Call Routing Business Object API if operation tabel is not empty
431 	IF l_operation_tbl.FIRST IS NOT NULL THEN
432 		Error_Handler.initialize;
433 		-- log call to Process_Rtg API
434 		EAM_ActivityUtilities_PVT.Write_Debug('>>>>>>>>>>>>>>> BOM_RTG_PUB.Process_Rtg INPUT Parameters >>>>>>>>>>>>>>>');
435 		EAM_ActivityUtilities_PVT.Log_Process_Rtg_Parameters(l_rtg_header_rec,
436 								l_operation_tbl,
437 								l_op_resource_tbl,
438 								l_op_network_tbl);
439 
440 		EAM_ActivityUtilities_PVT.Write_Debug('********** Calling BOM_RTG_PUB.Process_Rtg **********');
441 		BOM_RTG_PUB.Process_Rtg(
442 			p_rtg_header_rec 	=> l_rtg_header_rec
443 			, p_operation_tbl	=> l_operation_tbl
444 			, p_op_resource_tbl	=> l_op_resource_tbl
445 			, p_op_network_tbl	=> l_op_network_tbl
446 			, x_rtg_header_rec	=> l_x_rtg_header_rec
447 			, x_rtg_revision_tbl	=> l_x_rtg_revision_tbl
448 			, x_operation_tbl	=> l_x_operation_tbl
449 			, x_op_resource_tbl	=> l_x_op_resource_tbl
450 			, x_sub_resource_tbl	=> l_x_sub_resource_tbl
451 			, x_op_network_tbl	=> l_x_op_network_tbl
452 			, x_return_status	=> l_x_rtg_return_status
453 			, x_msg_count		=> l_x_rtg_msg_count
454 		);
455 		EAM_ActivityUtilities_PVT.Write_Debug('********** Returned from BOM_RTG_PUB.Process_Rtg **********');
456 
457 		Error_Handler.Get_Message_List(l_x_rtg_msg_list);
458 
459 		-- log errors
460 		EAM_ActivityUtilities_PVT.Write_Debug('l_x_rtg_return_status=' || l_x_rtg_return_status);
461 		EAM_ActivityUtilities_PVT.Write_Debug('l_x_rtg_msg_count=' || l_x_rtg_msg_count);
462 		Error_Handler.Get_Message_List(l_x_rtg_msg_list);
463 		EAM_ActivityUtilities_PVT.Write_Debug('Results of BOM_RTG_PUB.Process_Rtg >>>>>');
464 		EAM_ActivityUtilities_PVT.Log_Bom_Error_Tbl(l_x_rtg_msg_list);
465 		EAM_ActivityUtilities_PVT.Write_Debug('End of Results of BOM_RTG_PUB.Process_Rtg <<<<<');
466 		EAM_ActivityUtilities_PVT.Write_Debug('<<<<<<<<<<<<<<< BOM_RTG_PUB.Process_Rtg OUTPUT Parameters <<<<<<<<<<<<<<<');
467 		EAM_ActivityUtilities_PVT.Log_Process_Rtg_Parameters(l_x_rtg_header_rec,
468 								l_x_operation_tbl,
469 								l_x_op_resource_tbl,
470 								l_x_op_network_tbl);
471 
472 		-- Assign outputs.
473 		x_rtg_header_rec := l_x_rtg_header_rec;
474 		x_rtg_revision_tbl := l_x_rtg_revision_tbl;
475 		x_operation_tbl	:= l_x_operation_tbl;
476 		x_op_resource_tbl := l_x_op_resource_tbl;
477 		x_sub_resource_tbl := l_x_sub_resource_tbl;
478 		x_op_network_tbl := l_x_op_network_tbl;
479 		x_rtg_return_status := l_x_rtg_return_status;
480 		x_rtg_msg_count	:= l_x_rtg_msg_count;
481 		x_rtg_msg_list	:= l_x_rtg_msg_list;
482 
483 	END IF;
484 
485 	EAM_ActivityUtilities_PVT.Write_Debug('---------- Exiting EAM_Activity_PUB.Create_Activity_Routing ----------');
486 END;
487 
488 -- ----------------------------------------------------------------------
489 PROCEDURE Create_Activity_BOM(
490 	p_target_item_rec			IN INV_Item_GRP.Item_Rec_Type,
491 	p_work_order_rec		IN EAM_Activity_PUB.Work_Order_Rec_Type,
492 	p_material_copy_option		IN NUMBER,
493 
494 	x_bom_header_rec		OUT NOCOPY	BOM_BO_PUB.BOM_Head_Rec_Type,
495 	x_bom_revision_tbl		OUT NOCOPY	BOM_BO_PUB.BOM_Revision_Tbl_Type,
496 	x_bom_component_tbl		OUT NOCOPY	BOM_BO_PUB.BOM_Comps_Tbl_Type,
497 	x_bom_ref_designator_tbl	OUT NOCOPY	BOM_BO_PUB.BOM_Ref_Designator_Tbl_Type,
498 	x_bom_sub_component_tbl		OUT NOCOPY	BOM_BO_PUB.BOM_Sub_Component_Tbl_Type,
499 	x_bom_return_status		OUT NOCOPY	VARCHAR2,
500 	x_bom_msg_count			OUT NOCOPY	NUMBER,
501 	x_bom_msg_list			OUT NOCOPY	Error_Handler.Error_Tbl_Type
502 )
503 IS
504 l_current_date			CONSTANT DATE := sysdate;
505 l_effectivity_date		CONSTANT DATE := l_current_date;
506 l_create_txn_type		CONSTANT VARCHAR(10) := 'CREATE';
507 -- local variabels for calling BOM Business Object API
508 l_bom_head_rec			BOM_BO_PUB.Bom_Head_Rec_Type;
509 l_bom_component_tbl		BOM_BO_PUB.Bom_Comps_Tbl_Type;
510 l_bom_comp_tbl_index		BINARY_INTEGER;
511 
512 l_x_bom_header_rec		BOM_BO_PUB.Bom_Head_Rec_Type;
513 l_x_bom_revision_tbl		BOM_BO_PUB.Bom_Revision_Tbl_Type;
514 l_x_bom_component_tbl		BOM_BO_PUB.Bom_Comps_Tbl_Type;
515 l_x_bom_ref_designator_tbl	BOM_BO_PUB.Bom_Ref_Designator_Tbl_Type;
516 l_x_bom_sub_component_tbl	BOM_BO_PUB.Bom_Sub_Component_Tbl_Type;
517 l_x_bom_return_status		VARCHAR2(1);
518 l_x_bom_msg_count		NUMBER;
519 l_x_bom_msg_list		Error_Handler.Error_Tbl_Type;
520 l_stock_enabled_flag		varchar2(1);
521 l_list_price_per_unit		number;
522 CURSOR wip_requirement_cur (
523 	p_organization_id	IN	NUMBER,
524 	p_wip_entity_id 	IN	NUMBER
525 )
526 IS
527 	SELECT	*
528 	FROM	wip_requirement_operations
529 	WHERE	wip_entity_id = p_wip_entity_id
530 	 AND	organization_id = p_organization_id;
531 
532 BEGIN
533 	IF p_material_copy_option = 1 THEN
534 		-- p_material_copy_option = 1 (NONE), do nothing
535 		NULL;
536 	ELSIF p_material_copy_option IN (2, 3) THEN
537 		-- We need 1 BOM Header (Assembly_Item_Rec_Type) and a table of Components ( Rev_Component_Rec_Type)
538 		-- 2 a) Create BOM Header
539 --		l_bom_head_rec := NULL;
540 		l_bom_head_rec.Assembly_Item_Name := p_target_item_rec.Item_Number;
541 		l_bom_head_rec.Transaction_Type := l_create_txn_type;
542 		l_bom_head_rec.Organization_Code := p_target_item_rec.Organization_Code;
543 		l_bom_head_rec.Assembly_Type := 1;
544 
545 		-- 2 b) Create table of Components
546 		l_bom_comp_tbl_index := 1;
547 		FOR l_wip_requirement_row IN wip_requirement_cur(p_work_order_rec.organization_id,
548 								 p_work_order_rec.wip_entity_id)
549 		LOOP
550 --			l_bom_component_tbl(l_bom_comp_tbl_index) := NULL;
551 			l_bom_component_tbl(l_bom_comp_tbl_index).Transaction_Type := l_create_txn_type;
552 			l_bom_component_tbl(l_bom_comp_tbl_index).Organization_Code := l_bom_head_rec.Organization_Code;
553 			l_bom_component_tbl(l_bom_comp_tbl_index).Assembly_Item_Name := l_bom_head_rec.Assembly_Item_Name;
554 			l_bom_component_tbl(l_bom_comp_tbl_index).Start_Effective_Date := l_effectivity_date;
555 			l_bom_component_tbl(l_bom_comp_tbl_index).Operation_Sequence_Number :=
556 				l_wip_requirement_row.Operation_Seq_Num;
557 			l_bom_component_tbl(l_bom_comp_tbl_index).Component_Item_Name :=
558 				EAM_ActivityUtilities_PVT.Get_Item_Concatenated_Segments(l_wip_requirement_row.organization_id,
559 											l_wip_requirement_row.inventory_item_id);
560 --			l_bom_component_tbl(l_bom_comp_tbl_index).Item_Sequence_Number :=
561 --				l_wip_requirement_row.Component_Sequence_Id;
562 --			l_bom_component_tbl(l_bom_comp_tbl_index).Item_Sequence_Number := l_bom_comp_tbl_index;
563 
564 			IF p_material_copy_option = 2 THEN
565 				-- p_material_copy_option = 2 (ISSUED)
566 				l_bom_component_tbl(l_bom_comp_tbl_index).Quantity_Per_Assembly :=
567 					l_wip_requirement_row.Quantity_Issued;
568 			ELSE
569 				-- p_material_copy_option = 3 (ALL)
570 				l_bom_component_tbl(l_bom_comp_tbl_index).Quantity_Per_Assembly :=
571 					l_wip_requirement_row.Required_Quantity;
572 			END IF;
573 
574 			l_bom_component_tbl(l_bom_comp_tbl_index).Wip_Supply_Type := l_wip_requirement_row.Wip_Supply_Type;
575 			l_bom_component_tbl(l_bom_comp_tbl_index).Supply_Subinventory := l_wip_requirement_row.Supply_Subinventory;
576 			l_bom_component_tbl(l_bom_comp_tbl_index).Location_Name :=
577 				EAM_ActivityUtilities_PVT.Get_Locator(l_wip_requirement_row.organization_id,
578 									l_wip_requirement_row.Supply_Subinventory,
579 									l_wip_requirement_row.Supply_Locator_Id);
580 			l_bom_component_tbl(l_bom_comp_tbl_index).Attribute_Category := l_wip_requirement_row.Attribute_Category;
581 			l_bom_component_tbl(l_bom_comp_tbl_index).Attribute1 := l_wip_requirement_row.Attribute1;
582 			l_bom_component_tbl(l_bom_comp_tbl_index).Attribute2 := l_wip_requirement_row.Attribute2;
583 			l_bom_component_tbl(l_bom_comp_tbl_index).Attribute3 := l_wip_requirement_row.Attribute3;
584 			l_bom_component_tbl(l_bom_comp_tbl_index).Attribute4 := l_wip_requirement_row.Attribute4;
585 			l_bom_component_tbl(l_bom_comp_tbl_index).Attribute5 := l_wip_requirement_row.Attribute5;
586 			l_bom_component_tbl(l_bom_comp_tbl_index).Attribute6 := l_wip_requirement_row.Attribute6;
587 			l_bom_component_tbl(l_bom_comp_tbl_index).Attribute7 := l_wip_requirement_row.Attribute7;
588 			l_bom_component_tbl(l_bom_comp_tbl_index).Attribute8 := l_wip_requirement_row.Attribute8;
589 			l_bom_component_tbl(l_bom_comp_tbl_index).Attribute9 := l_wip_requirement_row.Attribute9;
590 			l_bom_component_tbl(l_bom_comp_tbl_index).Attribute10 := l_wip_requirement_row.Attribute10;
591 			l_bom_component_tbl(l_bom_comp_tbl_index).Attribute11 := l_wip_requirement_row.Attribute11;
592 			l_bom_component_tbl(l_bom_comp_tbl_index).Attribute12 := l_wip_requirement_row.Attribute12;
593 			l_bom_component_tbl(l_bom_comp_tbl_index).Attribute13 := l_wip_requirement_row.Attribute13;
594 			l_bom_component_tbl(l_bom_comp_tbl_index).Attribute14 := l_wip_requirement_row.Attribute14;
595 			l_bom_component_tbl(l_bom_comp_tbl_index).Attribute15 := l_wip_requirement_row.Attribute15;
596 
597 			l_bom_component_tbl(l_bom_comp_tbl_index).Comments := l_wip_requirement_row.Comments;
598 
599 			-- sraval: added for Direct Items 11.5.10
600 			select stock_enabled_flag,list_price_per_unit
601 			into l_stock_enabled_flag,l_list_price_per_unit
602 			from mtl_system_items
603 			where inventory_item_id = l_wip_requirement_row.inventory_item_id
604 			and organization_id = l_wip_requirement_row.organization_id;
605 
606 			if l_stock_enabled_flag = 'N' then
607 				l_bom_component_tbl(l_bom_comp_tbl_index).suggested_vendor_name := l_wip_requirement_row.suggested_vendor_name;
608 				l_bom_component_tbl(l_bom_comp_tbl_index).unit_price := l_wip_requirement_row.unit_price;
609 			end if;
610 
611 			l_bom_comp_tbl_index := l_bom_comp_tbl_index + 1;
612 		END LOOP;
613 	ELSE
614 		-- p_material_copy_option NOT IN (1, 2, 3)
615 		-- Since we performed validation on p_material_copy_option in the beginning already, should not happen.
616 		NULL;
617 	END IF; -- p_material_copy_option
618 
619 	-- 2 c) Call the BOM Business Object API
620 
621 	-- Only call BOM Business Object API if Component Table is not empty
622 	IF l_bom_component_tbl.FIRST IS NOT NULL THEN
623 
624 		Error_Handler.initialize;
625 		-- log call to Process_BOM API
626 		EAM_ActivityUtilities_PVT.Write_Debug('>>>>>>>>>>>>>>> BOM_BO_PUB.Process_BOM INPUT Parameters >>>>>>>>>>>>>>>');
627 		EAM_ActivityUtilities_PVT.Log_Process_BOM_Parameters(l_bom_head_rec,
628 								l_bom_component_tbl);
629 
630 		EAM_ActivityUtilities_PVT.Write_Debug('********** Calling BOM_BO_PUB.Process_BOM **********');
631 		BOM_BO_PUB.Process_BOM(
632 			p_bom_header_rec 		=> l_bom_head_rec,
633 			p_bom_component_tbl 		=> l_bom_component_tbl,
634 			x_bom_header_rec 		=> l_x_bom_header_rec,
635 			x_bom_revision_tbl 		=> l_x_bom_revision_tbl,
636 			x_bom_component_tbl 		=> l_x_bom_component_tbl,
637 			x_bom_ref_designator_tbl 	=> l_x_bom_ref_designator_tbl,
638 			x_bom_sub_component_tbl		=> l_x_bom_sub_component_tbl,
639 			x_return_status			=> l_x_bom_return_status,
640 			x_msg_count			=> l_x_bom_msg_count
641 		);
642 		EAM_ActivityUtilities_PVT.Write_Debug('********** Returned from BOM_BO_PUB.Process_BOM **********');
643 
644 		Error_Handler.Get_Message_List(l_x_bom_msg_list);
645 
646 		-- log errors
647 		EAM_ActivityUtilities_PVT.Write_Debug('l_x_bom_return_status=' || l_x_bom_return_status);
648 		EAM_ActivityUtilities_PVT.Write_Debug('l_x_bom_msg_count=' || l_x_bom_msg_count);
649 		Error_Handler.Get_Message_List(l_x_bom_msg_list);
650 		EAM_ActivityUtilities_PVT.Write_Debug('Results of BOM_BO_PUB.Process_BOM >>>>>');
651 		EAM_ActivityUtilities_PVT.Log_Bom_Error_Tbl(l_x_bom_msg_list);
652 		EAM_ActivityUtilities_PVT.Write_Debug('End of Results of BOM_BO_PUB.Process_BOM <<<<<');
653 		EAM_ActivityUtilities_PVT.Write_Debug('<<<<<<<<<<<<<<< BOM_BO_PUB.Process_BOM OUTPUT Parameters <<<<<<<<<<<<<<<');
654 		EAM_ActivityUtilities_PVT.Log_Process_BOM_Parameters(l_x_bom_header_rec,
655 								l_x_bom_component_tbl);
656 
657 
658 		-- Assign outputs.
659 		x_bom_header_rec := l_x_bom_header_rec;
660 		x_bom_revision_tbl := l_x_bom_revision_tbl;
661 		x_bom_component_tbl := l_x_bom_component_tbl;
662 		x_bom_ref_designator_tbl := l_x_bom_ref_designator_tbl;
663 		x_bom_sub_component_tbl	:= l_x_bom_sub_component_tbl;
664 		x_bom_return_status := l_x_bom_return_status;
665 		x_bom_msg_count := l_x_bom_msg_count;
666 		x_bom_msg_list := l_x_bom_msg_list;
667 
668 	END IF;
669 
670 END;
671 -- ================================================================================
672 PROCEDURE Get_Errors
673 (	p_item_error_tbl			IN	INV_Item_GRP.Error_Tbl_Type ,
674 	x_error_msg_old				IN	VARCHAR2,
675 	x_error_msg_new				OUT NOCOPY	VARCHAR2
676 )
677 IS
678 	l_index BINARY_INTEGER;
679 	l_error_msg VARCHAR2(3000);
680 BEGIN
681 	l_error_msg:=x_error_msg_old;
682 	l_index:=p_item_error_tbl.FIRST;
683 	WHILE l_index IS NOT NULL
684 	LOOP
685 		l_error_msg:=l_error_msg||p_item_error_tbl(l_index).message_text;
686 		l_index:=p_item_error_tbl.NEXT(l_index);
687 	END LOOP;
688 	x_error_msg_new:=l_error_msg;
689 END;
690 -- ================================================================================
691 
692 -- ----------------------------------------------------------------------
693 PROCEDURE Create_Item(
694 	p_asset_activity		IN	INV_Item_GRP.Item_Rec_Type,
695 	p_template_id			IN	NUMBER 		:= NULL,
696         p_template_name			IN	VARCHAR2 	:= NULL,
697 
698 	x_curr_item_rec			OUT NOCOPY	INV_Item_GRP.Item_Rec_Type,
699 	x_curr_item_return_status	OUT NOCOPY	VARCHAR2,
700 	x_curr_item_error_tbl		OUT NOCOPY	INV_Item_GRP.Error_Tbl_Type,
701 
702 	x_master_item_rec		OUT NOCOPY	INV_Item_GRP.Item_Rec_Type,
703 	x_master_item_return_status	OUT NOCOPY	VARCHAR2,
704 	x_master_item_error_tbl		OUT NOCOPY	INV_Item_GRP.Error_Tbl_Type
705 )
706 IS
707 l_master_organization_id	NUMBER;
708 l_curr_organization_id		NUMBER;
709 l_item_rec			INV_Item_GRP.Item_rec_type;
710 l_validate_org_ret_sts		VARCHAR2(1);
711 
712 l_temp_org_id			NUMBER;
713 l_temp_org_code			VARCHAR2(3);
714 
715 -- local variables for calling INV_Item_GRP package
716 
717 l_x_curr_item_rec		INV_Item_GRP.Item_rec_type;
718 l_x_curr_item_return_status	VARCHAR2(1);
719 l_x_curr_item_error_tbl		INV_Item_GRP.Error_tbl_type;
720 
721 l_x_master_item_rec	INV_Item_GRP.Item_rec_type;
722 l_x_master_item_return_status	VARCHAR2(1);
723 l_x_master_item_error_tbl	INV_Item_GRP.Error_tbl_type;
724 l_error_string			VARCHAR(2000);
725 
726 BEGIN
727 	-- Step 2: Create Asset Activity. Call INV_Item_GRP package.
728 
729 	-- Copy input activity record to a working record
730 	l_item_rec := p_asset_activity;
731 
732 	-- Validate org id and org code
733 	EAM_ActivityUtilities_PVT.Validate_Organization(
734 		p_organization_id => l_item_rec.organization_id,
735 		p_organization_code => l_item_rec.organization_code,
736 		x_return_status => l_validate_org_ret_sts,
737 		x_organization_id => l_temp_org_id,
738 		x_organization_code => l_temp_org_code
739 	);
740 	l_item_rec.organization_id := l_temp_org_id;
741 	l_item_rec.organization_code := l_temp_org_code;
742 
743 	IF l_validate_org_ret_sts <> FND_API.G_RET_STS_SUCCESS THEN
744 		RAISE FND_API.G_EXC_ERROR;
745 	END IF;
746 
747 	-- ============================================================
748 	EAM_ActivityUtilities_PVT.Write_Debug('-------- Beginning EAM_Activity_PUB.Create_Item --------');
749 
750 	-- Save current org id
751 	l_curr_organization_id := l_item_rec.organization_id;
752 	EAM_ActivityUtilities_PVT.Write_Debug('l_curr_organization_id=' || l_curr_organization_id);
753 
754 	-- 2 a) Get master org id
755 	l_master_organization_id := EAM_ActivityUtilities_PVT.Get_Master_Org_Id(l_curr_organization_id);
756 	EAM_ActivityUtilities_PVT.Write_Debug('l_master_organization_id=' || l_master_organization_id);
757 
758 	-- Set attributes of l_item_rec
759 	l_item_rec.eam_item_type := 2; -- EAM Asset Activity
760 
761 	IF l_item_rec.inventory_item_flag IS NULL OR l_item_rec.inventory_item_flag = fnd_api.g_MISS_CHAR
762 	THEN
763 		l_item_rec.inventory_item_flag := 'Y';
764 	END IF;
765 
766 	IF l_item_rec.expense_account IS NULL OR l_item_rec.expense_account = fnd_api.g_MISS_NUM
767 	THEN
768 		-- In the Master Item form, Expense Account defaulted from Master Org. So should use Master Org.
769 		l_item_rec.expense_account := EAM_ActivityUtilities_PVT.Get_Expense_Account_Id(l_master_organization_id);
770 	END IF;
771 
772        /* Bug 13418048  Avoiding expense account required check as activity is not costed or purchased
773         -- Check that expense_account is not null
774 
775         IF l_item_rec.expense_account IS NULL OR l_item_rec.expense_account = fnd_api.g_MISS_NUM
776 	THEN
777 		FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_EXPENSE_ACCOUNT_NULL');
778 --		FND_MESSAGE.SET_ENCODED('Please define the Expense Account for the Organization.');
779 		EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
780 		RAISE FND_API.G_EXC_ERROR;
781 	END IF; */
782 
783 	IF l_item_rec.bom_enabled_flag IS NULL OR
784 		l_item_rec.bom_enabled_flag = fnd_api.g_MISS_CHAR
785 	THEN
786 		l_item_rec.bom_enabled_flag := 'Y';
787 	END IF;
788 
789 	-- 2 c) If current org is not master org, creat Activity in master org first
790 	IF l_curr_organization_id <> l_master_organization_id THEN
791 		-- set org to master org
792 		l_item_rec.organization_id := l_master_organization_id;
793 		l_item_rec.organization_code := NULL;
794 
795 		EAM_ActivityUtilities_PVT.Write_Debug('Creating MASTER Item...');
796 		EAM_ActivityUtilities_PVT.Write_Debug('>>>>>>>>>>>>>>> INV_Item_GRP.Create_Item INPUT Parameters >>>>>>>>>>>>>>>');
797 		EAM_ActivityUtilities_PVT.Write_Debug('p_template_id=' || p_template_id);
798 		EAM_ActivityUtilities_PVT.Write_Debug('p_template_name=' || p_template_name);
799 		EAM_ActivityUtilities_PVT.Log_Inv_Item_Rec(l_item_rec);
800 		INV_Item_GRP.Create_Item(
801 			p_Item_rec => l_item_rec,
802 			p_Template_Id => p_template_id,
803 			p_Template_Name => p_template_name,
804 			x_Item_rec => l_x_master_item_rec,
805 			x_return_status => l_x_master_item_return_status,
806 			x_Error_tbl => l_x_master_item_error_tbl
807 		);
808 		-- Assign outputs
809 		x_master_item_rec := l_x_master_item_rec;
810 		x_master_item_return_status := l_x_master_item_return_status;
811 		x_master_item_error_tbl := l_x_master_item_error_tbl;
812 
813 		-- log outputs
814 		EAM_ActivityUtilities_PVT.Write_Debug('l_x_master_item_return_status=' || l_x_master_item_return_status);
815 		EAM_ActivityUtilities_PVT.Write_Debug('Results of INV_Item_GRP.Create_Item (master item) >>>>>');
816 		EAM_ActivityUtilities_PVT.Log_Item_Error_Tbl(l_x_master_item_error_tbl);
817 		EAM_ActivityUtilities_PVT.Write_Debug('End of Results of INV_Item_GRP.Create_Item (master item) <<<<<');
818 		EAM_ActivityUtilities_PVT.Write_Debug('<<<<<<<<<<<<<<< INV_Item_GRP.Create_Item OUTPUT Parameters <<<<<<<<<<<<<<<');
819 		EAM_ActivityUtilities_PVT.Log_Inv_Item_Rec(l_x_master_item_rec);
820 
821 		IF l_x_master_item_return_status <> FND_API.G_RET_STS_SUCCESS THEN
822 			-- Create Item under master org fail, no use tyring to create it under child org.
823 			RETURN;
824 		END IF;
825 	ELSE
826 		-- Current Org is Master Org, no additional Item needs to be created.
827 		EAM_ActivityUtilities_PVT.Write_Debug('Current Org is Master Org, no additional Item needs to be created.');
828 		x_master_item_rec := l_x_master_item_rec; -- should be NULL
829 		x_master_item_return_status := FND_API.G_RET_STS_SUCCESS;
830 		x_master_item_error_tbl := l_x_master_item_error_tbl; -- should be NULL
831 	END IF;
832 
833 	-- 2 d) Create Activity in current org
834 	-- set org to current org
835 	l_item_rec.organization_id := l_curr_organization_id;
836 	l_item_rec.organization_code := NULL;
837 	/*Bug3269789 - Added below code since master items form uses exp acct of child org
838 	  when assigning to child org*/
839 	/*Bug#3269789 - start*/
840 	     l_item_rec.expense_account := EAM_ActivityUtilities_PVT.Get_Expense_Account_Id(l_curr_organization_id);
841 
842 	    /* Bug 13838073  Avoiding expense account required check as activity is not costed or purchased
843 
844            -- Check that expense_account is not null
845 	    IF l_item_rec.expense_account IS NULL OR l_item_rec.expense_account = fnd_api.g_MISS_NUM
846 	    THEN
847 	        FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_EXPENSE_ACCOUNT_NULL');
848 	--      FND_MESSAGE.SET_ENCODED('Please define the Expense Account for the Organization.');
849 	        EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
850 	        RAISE FND_API.G_EXC_ERROR;
851 	    END IF;*/
852 	/*Bug#3269789 - end*/
853 
854 	EAM_ActivityUtilities_PVT.Write_Debug('Creating CURRENT Item...');
855 	EAM_ActivityUtilities_PVT.Write_Debug('>>>>>>>>>>>>>>> INV_Item_GRP.Create_Item INPUT Parameters >>>>>>>>>>>>>>>');
856 	EAM_ActivityUtilities_PVT.Write_Debug('p_template_id=' || p_template_id);
857 	EAM_ActivityUtilities_PVT.Write_Debug('p_template_name=' || p_template_name);
858 	EAM_ActivityUtilities_PVT.Log_Inv_Item_Rec(l_item_rec);
859 	INV_Item_GRP.Create_Item(
860 		p_Item_rec => l_item_rec,
861 		p_Template_Id => p_template_id,
862 		p_Template_Name => p_template_name,
863 		x_Item_rec => l_x_curr_item_rec,
864 		x_return_status => l_x_curr_item_return_status,
865 		x_Error_tbl => l_x_curr_item_error_tbl
866 	);
867 	-- Assign outputs
868 	x_curr_item_rec := l_x_curr_item_rec;
869 	x_curr_item_return_status := l_x_curr_item_return_status;
870 	x_curr_item_error_tbl := l_x_curr_item_error_tbl;
871 
872 	-- log outputs
873 	EAM_ActivityUtilities_PVT.Write_Debug('l_x_curr_item_return_status=' || l_x_curr_item_return_status);
874 	EAM_ActivityUtilities_PVT.Write_Debug('Results of INV_Item_GRP.Create_Item (current item) >>>>>');
875 	EAM_ActivityUtilities_PVT.Log_Item_Error_Tbl(l_x_curr_item_error_tbl);
876 	EAM_ActivityUtilities_PVT.Write_Debug('End of Results of INV_Item_GRP.Create_Item (current item) <<<<<');
877 	EAM_ActivityUtilities_PVT.Write_Debug('<<<<<<<<<<<<<<< INV_Item_GRP.Create_Item OUTPUT Parameters <<<<<<<<<<<<<<<');
878 	EAM_ActivityUtilities_PVT.Log_Inv_Item_Rec(l_x_curr_item_rec);
879 
880 	-- ============================================================
881 	EAM_ActivityUtilities_PVT.Write_Debug('-------- Finished EAM_Activity_PUB.Create_Item --------');
882 END;
883 
884 -- ======================================================================
885 PROCEDURE Create_Activity
886 ( 	p_api_version           	IN	NUMBER				,
887   	p_init_msg_list			IN	VARCHAR2 := FND_API.G_FALSE	,
888 	p_commit	    		IN  	VARCHAR2 := FND_API.G_FALSE	,
889 	p_validation_level		IN  	NUMBER	:=
890 						FND_API.G_VALID_LEVEL_FULL	,
891 	x_return_status			OUT NOCOPY	VARCHAR2		  	,
892 	x_msg_count			OUT NOCOPY	NUMBER				,
893 	x_msg_data			OUT NOCOPY	VARCHAR2			,
894 
895 	p_asset_activity		IN	INV_Item_GRP.Item_Rec_Type,
896 	p_template_id			IN	NUMBER 		:= NULL,
897         p_template_name			IN	VARCHAR2 	:= NULL,
898 	p_activity_type_code		IN	VARCHAR2	:= NULL,
899 	p_activity_cause_code 		IN	VARCHAR2	:= NULL,
900 	p_shutdown_type_code		IN	VARCHAR2	:= NULL,
901 	p_notification_req_flag		IN	VARCHAR2	:= NULL,
902 	p_activity_source_code		IN	VARCHAR2	:= NULL,
903         p_work_order_rec		IN	EAM_Activity_PUB.Work_Order_Rec_Type,
904 	p_operation_copy_option		IN	NUMBER := 2, -- 1 (NONE) or 2 (ALL)
905  	p_material_copy_option		IN	NUMBER := 2, -- 1 (NONE), 2 (ISSUED), OR 3 (ALL)
906 	p_resource_copy_option		IN	NUMBER := 2, -- 1 (NONE), 2 (ISSUED), OR 3 (ALL)
907 	p_association_copy_option	IN	NUMBER := 2, -- 1 (NONE), 2 (CURRENT), OR 3 (ALL)
908 
909 --	x_inventory_item_id		OUT	NUMBER, -- the inventory_item_it the system has created
910 	x_work_order_rec		OUT	NOCOPY	EAM_Activity_PUB.Work_Order_Rec_Type,
911 
912 	x_curr_item_rec			OUT	NOCOPY	INV_Item_GRP.Item_Rec_Type,
913 	x_curr_item_return_status	OUT	NOCOPY	VARCHAR2,
914 	x_curr_item_error_tbl		OUT	NOCOPY	INV_Item_GRP.Error_Tbl_Type,
915 	x_master_item_rec		OUT	NOCOPY	INV_Item_GRP.Item_Rec_Type,
916 	x_master_item_return_status	OUT	NOCOPY	VARCHAR2,
917 	x_master_item_error_tbl		OUT	NOCOPY	INV_Item_GRP.Error_Tbl_Type,
918 
919 	x_rtg_header_rec		OUT	NOCOPY	BOM_Rtg_Pub.Rtg_Header_Rec_Type,
920 	x_rtg_revision_tbl		OUT	NOCOPY	BOM_Rtg_Pub.Rtg_Revision_Tbl_Type,
921 	x_operation_tbl			OUT	NOCOPY	BOM_Rtg_Pub.Operation_Tbl_Type,
922 	x_op_resource_tbl		OUT	NOCOPY	BOM_Rtg_Pub.Op_Resource_Tbl_Type,
923 	x_sub_resource_tbl		OUT	NOCOPY	BOM_Rtg_Pub.Sub_Resource_Tbl_Type,
924 	x_op_network_tbl		OUT	NOCOPY	BOM_Rtg_Pub.Op_Network_Tbl_Type,
925 	x_rtg_return_status		OUT	NOCOPY	VARCHAR2,
926 	x_rtg_msg_count			OUT	NOCOPY	NUMBER,
927 	x_rtg_msg_list			OUT	NOCOPY	Error_Handler.Error_Tbl_Type,
928 
929 	x_bom_header_rec		OUT	NOCOPY	BOM_BO_PUB.BOM_Head_Rec_Type,
930 	x_bom_revision_tbl		OUT	NOCOPY	BOM_BO_PUB.BOM_Revision_Tbl_Type,
931 	x_bom_component_tbl		OUT	NOCOPY	BOM_BO_PUB.BOM_Comps_Tbl_Type,
932 	x_bom_ref_designator_tbl	OUT	NOCOPY	BOM_BO_PUB.BOM_Ref_Designator_Tbl_Type,
933 	x_bom_sub_component_tbl		OUT	NOCOPY	BOM_BO_PUB.BOM_Sub_Component_Tbl_Type,
934 	x_bom_return_status		OUT	NOCOPY	VARCHAR2,
935 	x_bom_msg_count			OUT	NOCOPY	NUMBER,
936 	x_bom_msg_list			OUT	NOCOPY	Error_Handler.Error_Tbl_Type,
937 
938 	x_assoc_return_status		OUT	NOCOPY	VARCHAR2,
939 	x_assoc_msg_count		OUT	NOCOPY	NUMBER,
940 	x_assoc_msg_data		OUT	NOCOPY	VARCHAR2,
941 	x_act_num_association_tbl	OUT	NOCOPY	EAM_Activity_PUB.Activity_Association_Tbl_Type,
942 	x_activity_association_tbl	OUT	NOCOPY	EAM_Activity_PUB.Activity_Association_Tbl_Type
943 )
944 
945 IS
946 l_api_name			CONSTANT VARCHAR2(30)		:= 'Create_Activity';
947 l_api_version           	CONSTANT NUMBER 		:= 1.0;
948 
949 -- local variables for validating source Work Order
950 l_x_work_order_rec		EAM_Activity_PUB.Work_Order_Rec_Type;
951 l_x_work_order_ret_sts		VARCHAR2(1);
952 
953 -- local variables for calling INV_Item_GRP package
954 l_asset_activity		INV_Item_GRP.Item_rec_type;
955 l_x_curr_item_rec		INV_Item_GRP.Item_rec_type;
956 l_x_curr_item_return_status	VARCHAR2(1);
957 l_x_curr_item_error_tbl		INV_Item_GRP.Error_tbl_type;
958 l_x_master_item_rec		INV_Item_GRP.Item_rec_type;
959 l_x_master_item_return_status	VARCHAR2(1);
960 l_x_master_item_error_tbl	INV_Item_GRP.Error_tbl_type;
961 
962 -- local variabels for calling BOM Business Object API
963 l_x_bom_header_rec		BOM_BO_PUB.Bom_Head_Rec_Type;
964 l_x_bom_revision_tbl		BOM_BO_PUB.Bom_Revision_Tbl_Type;
965 l_x_bom_component_tbl		BOM_BO_PUB.Bom_Comps_Tbl_Type;
966 l_x_bom_ref_designator_tbl	BOM_BO_PUB.Bom_Ref_Designator_Tbl_Type;
967 l_x_bom_sub_component_tbl	BOM_BO_PUB.Bom_Sub_Component_Tbl_Type;
968 l_x_bom_return_status		VARCHAR2(1);
969 l_x_bom_msg_count		NUMBER;
970 l_x_bom_msg_list		Error_Handler.Error_Tbl_Type;
971 
972 -- local variables for call the Routing Business Object API
973 l_x_rtg_header_rec		BOM_RTG_PUB.Rtg_Header_Rec_Type;
974 l_x_rtg_revision_tbl		BOM_RTG_PUB.Rtg_Revision_Tbl_Type;
975 l_x_operation_tbl		BOM_RTG_PUB.Operation_Tbl_Type;
976 l_x_op_resource_tbl		BOM_RTG_PUB.Op_Resource_Tbl_Type;
977 l_x_sub_resource_tbl		BOM_RTG_PUB.Sub_Resource_Tbl_Type;
978 l_x_op_network_tbl		BOM_RTG_PUB.Op_Network_Tbl_Type;
979 l_x_rtg_return_status		VARCHAR2(1);
980 l_x_rtg_msg_count		NUMBER;
981 l_x_rtg_msg_list		Error_Handler.Error_Tbl_Type;
982 
983 -- local variables for call Association Creation package
984 l_x_assoc_return_status		VARCHAR2(1);
985 l_x_assoc_msg_count		NUMBER;
986 l_x_assoc_msg_data		VARCHAR2(20000);
987 l_x_act_num_association_tbl	EAM_Activity_PUB.Activity_Association_Tbl_Type;
988 l_x_activity_association_tbl	EAM_Activity_PUB.Activity_Association_Tbl_Type;
989 
990 
991 -- ======================================================================
992 BEGIN
993 	-- Standard Start of API savepoint
994     SAVEPOINT	Create_Activity_PUB;
995     -- Standard call to check for call compatibility.
996     IF NOT FND_API.Compatible_API_Call ( 	l_api_version        	,
997         	    	    	    	 	p_api_version        	,
998    	       	    	 			l_api_name 	    	,
999 		    	    	    	    	G_PKG_NAME )
1000 	THEN
1001 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1002 	END IF;
1003 	-- Initialize message list if p_init_msg_list is set to TRUE.
1004 	IF FND_API.to_Boolean( p_init_msg_list ) THEN
1005 		FND_MSG_PUB.initialize;
1006 	END IF;
1007 	--  Initialize API return status to success
1008     x_return_status := FND_API.G_RET_STS_SUCCESS;
1009 	-- API body
1010 
1011 	-- ============================================================
1012 	EAM_ActivityUtilities_PVT.Write_Debug('========== Entering EAM_Activity_PUB.Create_Activity ==========');
1013 	EAM_ActivityUtilities_PVT.Write_Debug('Organization_Id=' || p_asset_activity.Organization_Id);
1014 	EAM_ActivityUtilities_PVT.Write_Debug('Organization_Code=' || p_asset_activity.Organization_Code);
1015 	EAM_ActivityUtilities_PVT.Write_Debug('Inventory_Item_Id=' || p_asset_activity.Inventory_Item_Id);
1016 	EAM_ActivityUtilities_PVT.Write_Debug('Item Number=' || p_asset_activity.Item_Number);
1017 	EAM_ActivityUtilities_PVT.Write_Debug('Segment1=' || p_asset_activity.Segment1);
1018 	EAM_ActivityUtilities_PVT.Write_Debug('Segment2=' || p_asset_activity.Segment2);
1019 	EAM_ActivityUtilities_PVT.Write_Debug('Segment3=' || p_asset_activity.Segment3);
1020 	EAM_ActivityUtilities_PVT.Write_Debug('Segment4=' || p_asset_activity.Segment4);
1021 	EAM_ActivityUtilities_PVT.Write_Debug('Segment5=' || p_asset_activity.Segment5);
1022 	EAM_ActivityUtilities_PVT.Write_Debug('Segment6=' || p_asset_activity.Segment6);
1023 	EAM_ActivityUtilities_PVT.Write_Debug('Segment7=' || p_asset_activity.Segment7);
1024 	EAM_ActivityUtilities_PVT.Write_Debug('Segment8=' || p_asset_activity.Segment8);
1025 	EAM_ActivityUtilities_PVT.Write_Debug('Segment9=' || p_asset_activity.Segment9);
1026 	EAM_ActivityUtilities_PVT.Write_Debug('Segment10=' || p_asset_activity.Segment10);
1027 	EAM_ActivityUtilities_PVT.Write_Debug('Segment11=' || p_asset_activity.Segment11);
1028 	EAM_ActivityUtilities_PVT.Write_Debug('Segment12=' || p_asset_activity.Segment12);
1029 	EAM_ActivityUtilities_PVT.Write_Debug('Segment13=' || p_asset_activity.Segment13);
1030 	EAM_ActivityUtilities_PVT.Write_Debug('Segment14=' || p_asset_activity.Segment14);
1031 	EAM_ActivityUtilities_PVT.Write_Debug('Segment15=' || p_asset_activity.Segment15);
1032 	EAM_ActivityUtilities_PVT.Write_Debug('Segment16=' || p_asset_activity.Segment16);
1033 	EAM_ActivityUtilities_PVT.Write_Debug('Segment17=' || p_asset_activity.Segment17);
1034 	EAM_ActivityUtilities_PVT.Write_Debug('Segment18=' || p_asset_activity.Segment18);
1035 	EAM_ActivityUtilities_PVT.Write_Debug('Segment19=' || p_asset_activity.Segment19);
1036 	EAM_ActivityUtilities_PVT.Write_Debug('Segment20=' || p_asset_activity.Segment20);
1037 	EAM_ActivityUtilities_PVT.Write_Debug('Description=' || p_asset_activity.Description);
1038 
1039 	-- ============================================================
1040 	-- Step 1: Validate inputs
1041 	-- 1 a) Validate source Work Order
1042 	EAM_ActivityUtilities_PVT.Validate_Work_Order(
1043 		p_work_order_rec => p_work_order_rec,
1044 		x_return_status => l_x_work_order_ret_sts,
1045 		x_work_order_rec => l_x_work_order_rec
1046 	);
1047 	IF l_x_work_order_ret_sts <> FND_API.G_RET_STS_SUCCESS THEN
1048 		RAISE FND_API.G_EXC_ERROR;
1049 	END IF;
1050 	-- Set return parameter
1051 	x_work_order_rec := l_x_work_order_rec;
1052 
1053 	-- 1 b) Validate copy options
1054 	Validate_Copy_Options(
1055 		l_x_work_order_rec,
1056 		p_operation_copy_option,
1057 		p_material_copy_option,
1058 		p_resource_copy_option,
1059 		p_association_copy_option
1060 	);
1061 
1062 	-- ============================================================
1063 	-- Step 2: Create Asset Activity. Call INV_Item_GRP package.
1064 
1065 	l_asset_activity := p_asset_activity;
1066 
1067 	-- Get org id from work order
1068 	l_asset_activity.organization_id := l_x_work_order_rec.organization_id;
1069 
1070 	l_asset_activity.EAM_ACTIVITY_TYPE_CODE := p_activity_type_code;
1071 	l_asset_activity.EAM_ACTIVITY_CAUSE_CODE := p_activity_cause_code;
1072 	l_asset_activity.EAM_ACT_NOTIFICATION_FLAG := p_notification_req_flag;
1073 	l_asset_activity.EAM_ACT_SHUTDOWN_STATUS := p_shutdown_type_code;
1074 	l_asset_activity.EAM_ACTIVITY_SOURCE_CODE := p_activity_source_code;
1075 
1076 	Create_Item(
1077 		p_asset_activity => l_asset_activity,
1078 		p_template_id => p_template_id,
1079 		p_template_name => p_template_name,
1080 
1081 		x_curr_item_rec 		=> l_x_curr_item_rec,
1082 		x_curr_item_return_status 	=> l_x_curr_item_return_status,
1083 		x_curr_item_error_tbl 		=> l_x_curr_item_error_tbl,
1084 		x_master_item_rec 		=> l_x_master_item_rec,
1085 		x_master_item_return_status 	=> l_x_master_item_return_status,
1086 		x_master_item_error_tbl 	=> l_x_master_item_error_tbl
1087 	);
1088 
1089 	IF l_x_master_item_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1090 		FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_CR_ACT_MASTER_FAILED');
1091 --		FND_MESSAGE.SET_ENCODED('Create Activity under Master Organization failed.');
1092 		EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
1093 		RAISE FND_API.G_EXC_ERROR;
1094 	END IF;
1095 
1096 	IF l_x_curr_item_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1097 		FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_CR_ACT_CURRENT_FAILED');
1098 --		FND_MESSAGE.SET_ENCODED('Create Activity under Current Organization failed.');
1099 		EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
1100 		RAISE FND_API.G_EXC_ERROR;
1101 	END IF;
1102 
1103 -- Set the Activity Attributes in the Item Record, don't have to do it manually
1104 /*
1105 	-- Overwrite Activity Properties with user-supplied values
1106 	l_x_master_item_rec.EAM_ACTIVITY_TYPE_CODE := p_activity_type_code;
1107 	l_x_master_item_rec.EAM_ACTIVITY_CAUSE_CODE  := p_activity_cause_code;
1108 	l_x_master_item_rec.EAM_ACT_SHUTDOWN_STATUS := p_shutdown_type_code;
1109 	l_x_master_item_rec.EAM_ACT_NOTIFICATION_FLAG := p_notification_req_flag;
1110 
1111 	BEGIN
1112 		UPDATE	mtl_system_items
1113 		SET	EAM_ACTIVITY_TYPE_CODE = p_activity_type_code,
1114 			EAM_ACTIVITY_CAUSE_CODE = p_activity_cause_code,
1115 			EAM_ACT_SHUTDOWN_STATUS = p_shutdown_type_code,
1116 			EAM_ACT_NOTIFICATION_FLAG = p_notification_req_flag,
1117 			EAM_ACTIVITY_SOURCE_CODE = p_activity_source_code
1118 		WHERE	inventory_item_id = l_x_master_item_rec.inventory_item_id
1119 		AND	organization_id = l_x_master_item_rec.organization_id;
1120 	EXCEPTION
1121 		WHEN OTHERS THEN
1122 			IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1123 				FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_ACT_PROPERTIES');
1124 				FND_MSG_PUB.ADD;
1125 			END IF;
1126 			RAISE FND_API.G_EXC_ERROR;
1127 	END;
1128 
1129 	l_x_curr_item_rec.EAM_ACTIVITY_TYPE_CODE := p_activity_type_code;
1130 	l_x_curr_item_rec.EAM_ACTIVITY_CAUSE_CODE  := p_activity_cause_code;
1131 	l_x_curr_item_rec.EAM_ACT_SHUTDOWN_STATUS := p_shutdown_type_code;
1132 	l_x_curr_item_rec.EAM_ACT_NOTIFICATION_FLAG := p_notification_req_flag;
1133 
1134 	BEGIN
1135 		UPDATE	mtl_system_items
1136 		SET	EAM_ACTIVITY_TYPE_CODE = p_activity_type_code,
1137 			EAM_ACTIVITY_CAUSE_CODE = p_activity_cause_code,
1138 			EAM_ACT_SHUTDOWN_STATUS = p_shutdown_type_code,
1139 			EAM_ACT_NOTIFICATION_FLAG = p_notification_req_flag,
1140 			EAM_ACTIVITY_SOURCE_CODE = p_activity_source_code
1141 		WHERE	inventory_item_id = l_x_curr_item_rec.inventory_item_id
1142 		AND	organization_id = l_x_curr_item_rec.organization_id;
1143 	EXCEPTION
1144 		WHEN OTHERS THEN
1145 			IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1146 				FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_ACT_PROPERTIES');
1147 				FND_MSG_PUB.ADD;
1148 			END IF;
1149 			RAISE FND_API.G_EXC_ERROR;
1150 	END;
1151 */
1152 
1153 	-- Assign outputs
1154 	x_curr_item_rec 		:= l_x_curr_item_rec;
1155 	x_curr_item_return_status 	:= l_x_curr_item_return_status;
1156 	x_curr_item_error_tbl 		:= l_x_curr_item_error_tbl;
1157 	x_master_item_rec 		:= l_x_master_item_rec;
1158 	x_master_item_return_status 	:= l_x_master_item_return_status;
1159 	x_master_item_error_tbl 	:= l_x_master_item_error_tbl;
1160 
1161 	-- ============================================================
1162 	-- Step 3: Create Operations and Resources
1163 	Create_Activity_Routing(
1164 		p_target_item_rec => l_x_curr_item_rec
1165 		, p_work_order_rec => l_x_work_order_rec
1166 		, p_operation_copy_option => p_operation_copy_option
1167 		, p_resource_copy_option => p_resource_copy_option
1168 
1169 		, x_rtg_header_rec	=> l_x_rtg_header_rec
1170 		, x_rtg_revision_tbl	=> l_x_rtg_revision_tbl
1171 		, x_operation_tbl	=> l_x_operation_tbl
1172 		, x_op_resource_tbl	=> l_x_op_resource_tbl
1173 		, x_sub_resource_tbl	=> l_x_sub_resource_tbl
1174 		, x_op_network_tbl	=> l_x_op_network_tbl
1175 		, x_rtg_return_status	=> l_x_rtg_return_status
1176 		, x_rtg_msg_count	=> l_x_rtg_msg_count
1177 		, x_rtg_msg_list	=> l_x_rtg_msg_list
1178 	);
1179 	-- Assign outputs.
1180 	x_rtg_header_rec := l_x_rtg_header_rec;
1181 	x_rtg_revision_tbl := l_x_rtg_revision_tbl;
1182 	x_operation_tbl	:= l_x_operation_tbl;
1183 	x_op_resource_tbl := l_x_op_resource_tbl;
1184 	x_sub_resource_tbl := l_x_sub_resource_tbl;
1185 	x_op_network_tbl := l_x_op_network_tbl;
1186 	x_rtg_return_status := l_x_rtg_return_status;
1187 	x_rtg_msg_count	:= l_x_rtg_msg_count;
1188 	x_rtg_msg_list	:= l_x_rtg_msg_list;
1189 
1190 	-- Handle errors
1191 	IF l_x_rtg_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1192 		FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_RTG_BO_FAILED');
1193 --		FND_MESSAGE.SET_ENCODED('Call to Routing Business Object API Failed.');
1194 		EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
1195 		RAISE FND_API.G_EXC_ERROR;
1196 	END IF;
1197 
1198 
1199 	-- ============================================================
1200 	-- Step 4: Create BOM and attach it to the newly created Activity
1201 	Create_Activity_BOM(
1202 		p_target_item_rec => l_x_curr_item_rec
1203 		, p_work_order_rec => l_x_work_order_rec
1204 		, p_material_copy_option => p_material_copy_option,
1205 		x_bom_header_rec 		=> l_x_bom_header_rec,
1206 		x_bom_revision_tbl 		=> l_x_bom_revision_tbl,
1207 		x_bom_component_tbl 		=> l_x_bom_component_tbl,
1208 		x_bom_ref_designator_tbl 	=> l_x_bom_ref_designator_tbl,
1209 		x_bom_sub_component_tbl		=> l_x_bom_sub_component_tbl,
1210 		x_bom_return_status		=> l_x_bom_return_status,
1211 		x_bom_msg_count			=> l_x_bom_msg_count,
1212 		x_bom_msg_list			=> l_x_bom_msg_list
1213 	);
1214 	-- Assign outputs.
1215 	x_bom_header_rec := l_x_bom_header_rec;
1216 	x_bom_revision_tbl := l_x_bom_revision_tbl;
1217 	x_bom_component_tbl := l_x_bom_component_tbl;
1218 	x_bom_ref_designator_tbl := l_x_bom_ref_designator_tbl;
1219 	x_bom_sub_component_tbl	:= l_x_bom_sub_component_tbl;
1220 	x_bom_return_status := l_x_bom_return_status;
1221 	x_bom_msg_count := l_x_bom_msg_count;
1222 	x_bom_msg_list := l_x_bom_msg_list;
1223 
1224 	-- Handle errors
1225 	IF l_x_bom_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1226 		FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_BOM_BO_FAILED');
1227 --		FND_MESSAGE.SET_ENCODED('Call to Routing Business Object API Failed.');
1228 		EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
1229 		RAISE FND_API.G_EXC_ERROR;
1230 	END IF;
1231 
1232 
1233 	-- ============================================================
1234 	-- Step 5: Update Association to Asset Numbers for the newly created activity
1235 	IF p_association_copy_option <> 1 THEN
1236 		-- p_association_copy_option <> 1 (NONE), call private package to create association
1237 		EAM_ActivityAssociation_PVT.Create_Association(
1238 			p_api_version => 1.0,
1239 			x_return_status => l_x_assoc_return_status,
1240 			x_msg_count => l_x_assoc_msg_count,
1241 			x_msg_data => l_x_assoc_msg_data,
1242 
1243 			p_target_org_id => l_x_curr_item_rec.organization_id,
1244 			p_target_activity_id => l_x_curr_item_rec.inventory_item_id,
1245 
1246   			p_wip_entity_id	=> l_x_work_order_rec.wip_entity_id,
1247 			p_association_copy_option => p_association_copy_option,
1248 
1249 			x_act_num_association_tbl => l_x_act_num_association_tbl,
1250 			x_activity_association_tbl => l_x_activity_association_tbl
1251 		);
1252 		-- Assing outputs
1253 		x_assoc_return_status := l_x_assoc_return_status;
1254 		x_assoc_msg_count := l_x_assoc_msg_count;
1255 		x_assoc_msg_data := l_x_assoc_msg_data;
1256 		x_act_num_association_tbl := l_x_act_num_association_tbl;
1257 		x_activity_association_tbl := l_x_activity_association_tbl;
1258 
1259 		-- Handle error
1260 		IF l_x_assoc_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1261 			FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_CR_ASSOC_FAILED');
1262 --			FND_MESSAGE.SET_ENCODED('Create Activity Associations failed.');
1263 			EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
1264 			RAISE FND_API.G_EXC_ERROR;
1265 		END IF;
1266 
1267 	END IF;
1268 
1269 	-- ======================================================================
1270 
1271 	-- End of API body.
1272 	-- Standard check of p_commit.
1273 	IF FND_API.To_Boolean( p_commit ) THEN
1274 		COMMIT WORK;
1275 	END IF;
1276 	-- Standard call to get message count and if count is 1, get message info.
1277 	FND_MSG_PUB.Count_And_Get
1278     	(  	p_count         	=>      x_msg_count     	,
1279         	p_data          	=>      x_msg_data
1280     	);
1281 
1282 
1283 	EAM_ActivityUtilities_PVT.Write_Debug('========== Exiting EAM_Activity_PUB.Create_Activity ==========');
1284 
1285 	-- ======================================================================
1286 
1287 EXCEPTION
1288 	WHEN FND_API.G_EXC_ERROR THEN
1289 		ROLLBACK TO Create_Activity_PUB;
1290 		EAM_ActivityUtilities_PVT.Write_Debug('========== EAM_Activity_PUB.Create_Activity: EXPECTED_ERROR ==========');
1291 		x_return_status := FND_API.G_RET_STS_ERROR ;
1292 		FND_MSG_PUB.Count_And_Get
1293     		(  	p_count         	=>      x_msg_count     	,
1294         		p_data          	=>      x_msg_data
1295     		);
1296 	WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1297 		ROLLBACK TO Create_Activity_PUB;
1298 		EAM_ActivityUtilities_PVT.Write_Debug('========== EAM_Activity_PUB.Create_Activity: UNEXPECTED_ERROR ==========');
1299 		x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1300 		FND_MSG_PUB.Count_And_Get
1301     		(  	p_count         	=>      x_msg_count     	,
1302         		p_data          	=>      x_msg_data
1303     		);
1304 	WHEN OTHERS THEN
1305 		ROLLBACK TO Create_Activity_PUB;
1306 		x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1307   		IF 	FND_MSG_PUB.Check_Msg_Level
1308 			(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1309 		THEN
1310         		FND_MSG_PUB.Add_Exc_Msg
1311     	    		(	G_PKG_NAME  	    ,
1312     	    			l_api_name
1313 	    		);
1314 			-- log error message also
1315 			EAM_ActivityUtilities_PVT.Write_Debug(FND_MSG_PUB.Get(FND_MSG_PUB.G_LAST, FND_API.G_FALSE));
1316 		END IF;
1317 		EAM_ActivityUtilities_PVT.Write_Debug('========== EAM_Activity_PUB.Create_Activity: OTHER ERROR ==========');
1318 		FND_MSG_PUB.Count_And_Get
1319     		(  	p_count         	=>      x_msg_count     	,
1320         		p_data          	=>      x_msg_data
1321     		);
1322 END Create_Activity;
1323 
1324 -- ================================================================================
1325 
1326 PROCEDURE Copy_Activity
1327 ( 	p_api_version           	IN	NUMBER				,
1328   	p_init_msg_list			IN	VARCHAR2 := FND_API.G_FALSE	,
1329 	p_commit	    		IN  	VARCHAR2 := FND_API.G_FALSE	,
1330 	p_validation_level		IN  	NUMBER	:=
1331 						FND_API.G_VALID_LEVEL_FULL	,
1332 	x_return_status			OUT NOCOPY	VARCHAR2		  	,
1333 	x_msg_count			OUT NOCOPY	NUMBER				,
1334 	x_msg_data			OUT NOCOPY	VARCHAR2			,
1335 
1336 	-- target activity, need to set org, item name, description
1337 	p_asset_activity		IN	INV_Item_GRP.Item_Rec_Type,
1338 
1339 
1340 	p_template_id			IN	NUMBER 		:= NULL,
1341         p_template_name			IN	VARCHAR2 	:= NULL,
1342 	p_activity_type_code		IN	VARCHAR2	:= NULL,
1343 	p_activity_cause_code 		IN	VARCHAR2	:= NULL,
1344 	p_shutdown_type_code		IN	VARCHAR2	:= NULL,
1345 	p_notification_req_flag		IN	VARCHAR2	:= NULL,
1346 	p_activity_source_code		IN	VARCHAR2	:= NULL,
1347 
1348 	-- source Activity
1349 	p_source_org_id			IN	NUMBER,
1350 	p_source_activity_id		IN	NUMBER, -- inventory_item_id
1351 	-- source BOM
1352 	p_source_alt_bom_designator	IN	VARCHAR2	:= NULL,
1353 	p_source_bom_rev_date		IN 	DATE		:= sysdate,
1354 	-- source Routing
1355 	p_source_alt_rtg_designator	IN	VARCHAR2	:= NULL,
1356 	p_source_rtg_rev_date		IN	DATE		:= sysdate,
1357 
1358 	p_bom_copy_option		IN	NUMBER := 2, -- 1 (NONE) or 2 (ALL)
1359 	p_routing_copy_option		IN	NUMBER := 2, -- 1 (NONE) or 2 (ALL)
1360 	p_association_copy_option	IN	NUMBER := 2, -- 1 (NONE) or 2 (ALL)
1361 
1362 	x_curr_item_rec			OUT	NOCOPY	INV_Item_GRP.Item_Rec_Type,
1363 	x_curr_item_return_status	OUT	NOCOPY	VARCHAR2,
1364 	x_curr_item_error_tbl		OUT	NOCOPY	INV_Item_GRP.Error_Tbl_Type,
1365 	x_master_item_rec		OUT	NOCOPY	INV_Item_GRP.Item_Rec_Type,
1366 	x_master_item_return_status	OUT	NOCOPY	VARCHAR2,
1367 	x_master_item_error_tbl		OUT	NOCOPY	INV_Item_GRP.Error_Tbl_Type,
1368 
1369 	x_assoc_return_status		OUT	NOCOPY	VARCHAR2,
1370 	x_assoc_msg_count		OUT	NOCOPY	NUMBER,
1371 	x_assoc_msg_data		OUT	NOCOPY	VARCHAR2,
1372 	x_act_num_association_tbl	OUT	NOCOPY	EAM_Activity_PUB.Activity_Association_Tbl_Type,
1373 	x_activity_association_tbl	OUT	NOCOPY	EAM_Activity_PUB.Activity_Association_Tbl_Type
1374 )
1375 IS
1376 l_api_name			CONSTANT VARCHAR2(30)	:= 'Copy_Activity';
1377 l_api_version           	CONSTANT NUMBER 		:= 1.0;
1378 
1379 -- local variables
1380 l_create_txn_type		CONSTANT VARCHAR(10) := 'CREATE';
1381 
1382 -- local variables for validating source Work Order
1383 l_x_work_order_rec		EAM_Activity_PUB.Work_Order_Rec_Type;
1384 l_x_work_order_ret_sts		VARCHAR2(1);
1385 
1386 -- local variables for calling INV_Item_GRP package
1387 l_asset_activity		INV_Item_GRP.Item_rec_type;
1388 l_x_curr_item_rec		INV_Item_GRP.Item_rec_type;
1389 l_x_curr_item_return_status	VARCHAR2(1);
1390 l_x_curr_item_error_tbl		INV_Item_GRP.Error_tbl_type;
1391 l_x_master_item_rec		INV_Item_GRP.Item_rec_type;
1392 l_x_master_item_return_status	VARCHAR2(1);
1393 l_x_master_item_error_tbl	INV_Item_GRP.Error_tbl_type;
1394 
1395 -- local variables for calling copy_bill API
1396 l_source_bom_sequence_id	NUMBER;
1397 l_target_bom_sequence_id	NUMBER;
1398 l_copy_bill_error_msg		VARCHAR2(20000);
1399 
1400 l_bom_head_rec			BOM_BO_PUB.Bom_Head_Rec_Type;
1401 
1402 l_x_bom_header_rec		BOM_BO_PUB.Bom_Head_Rec_Type;
1403 l_x_bom_revision_tbl		BOM_BO_PUB.Bom_Revision_Tbl_Type;
1404 l_x_bom_component_tbl		BOM_BO_PUB.Bom_Comps_Tbl_Type;
1405 l_x_bom_ref_designator_tbl	BOM_BO_PUB.Bom_Ref_Designator_Tbl_Type;
1406 l_x_bom_sub_component_tbl	BOM_BO_PUB.Bom_Sub_Component_Tbl_Type;
1407 l_x_bom_return_status		VARCHAR2(1);
1408 l_x_bom_msg_count		NUMBER;
1409 l_x_bom_msg_list		Error_Handler.Error_Tbl_Type;
1410 
1411 -- local variables for call the Routing Business Object API
1412 l_source_rtg_sequence_id	NUMBER;
1413 l_target_rtg_sequence_id	NUMBER;
1414 
1415 l_rtg_header_rec		BOM_RTG_PUB.Rtg_Header_Rec_Type;
1416 
1417 l_x_rtg_header_rec		BOM_RTG_PUB.Rtg_Header_Rec_Type;
1418 l_x_rtg_revision_tbl		BOM_RTG_PUB.Rtg_Revision_Tbl_Type;
1419 l_x_operation_tbl		BOM_RTG_PUB.Operation_Tbl_Type;
1420 l_x_op_resource_tbl		BOM_RTG_PUB.Op_Resource_Tbl_Type;
1421 l_x_sub_resource_tbl		BOM_RTG_PUB.Sub_Resource_Tbl_Type;
1422 l_x_op_network_tbl		BOM_RTG_PUB.Op_Network_Tbl_Type;
1423 l_x_rtg_return_status		VARCHAR2(1);
1424 l_x_rtg_msg_count		NUMBER;
1425 l_x_rtg_msg_list		Error_Handler.Error_Tbl_Type;
1426 
1427 -- local variables for call Association Creation package
1428 l_x_assoc_return_status		VARCHAR2(1);
1429 l_x_assoc_msg_count		NUMBER;
1430 l_x_assoc_msg_data		VARCHAR2(20000);
1431 l_x_act_num_association_tbl	EAM_Activity_PUB.Activity_Association_Tbl_Type;
1432 l_x_activity_association_tbl	EAM_Activity_PUB.Activity_Association_Tbl_Type;
1433 
1434 BEGIN
1435 	-- Standard Start of API savepoint
1436     SAVEPOINT	Copy_Activity_PUB;
1437     -- Standard call to check for call compatibility.
1438     IF NOT FND_API.Compatible_API_Call ( 	l_api_version        	,
1439         	    	    	    	 	p_api_version        	,
1440    	       	    	 			l_api_name 	    	,
1441 		    	    	    	    	G_PKG_NAME )
1442 	THEN
1443 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1444 	END IF;
1445 	-- Initialize message list if p_init_msg_list is set to TRUE.
1446 	IF FND_API.to_Boolean( p_init_msg_list ) THEN
1447 		FND_MSG_PUB.initialize;
1448 	END IF;
1449 	--  Initialize API return status to success
1450     x_return_status := FND_API.G_RET_STS_SUCCESS;
1451 	-- API body
1452 
1453 	-- ============================================================
1454 	EAM_ActivityUtilities_PVT.Write_Debug('========== Entering EAM_Activity_PUB.Copy_Activity ==========');
1455 	EAM_ActivityUtilities_PVT.Write_Debug('Organization_Id=' || p_asset_activity.Organization_Id);
1456 	EAM_ActivityUtilities_PVT.Write_Debug('Organization_Code=' || p_asset_activity.Organization_Code);
1457 	EAM_ActivityUtilities_PVT.Write_Debug('Inventory_Item_Id=' || p_asset_activity.Inventory_Item_Id);
1458 	EAM_ActivityUtilities_PVT.Write_Debug('Item Number=' || p_asset_activity.Item_Number);
1459 	EAM_ActivityUtilities_PVT.Write_Debug('Segment1=' || p_asset_activity.Segment1);
1460 	EAM_ActivityUtilities_PVT.Write_Debug('Segment2=' || p_asset_activity.Segment2);
1461 	EAM_ActivityUtilities_PVT.Write_Debug('Segment3=' || p_asset_activity.Segment3);
1462 	EAM_ActivityUtilities_PVT.Write_Debug('Segment4=' || p_asset_activity.Segment4);
1463 	EAM_ActivityUtilities_PVT.Write_Debug('Segment5=' || p_asset_activity.Segment5);
1464 	EAM_ActivityUtilities_PVT.Write_Debug('Segment6=' || p_asset_activity.Segment6);
1465 	EAM_ActivityUtilities_PVT.Write_Debug('Segment7=' || p_asset_activity.Segment7);
1466 	EAM_ActivityUtilities_PVT.Write_Debug('Segment8=' || p_asset_activity.Segment8);
1467 	EAM_ActivityUtilities_PVT.Write_Debug('Segment9=' || p_asset_activity.Segment9);
1468 	EAM_ActivityUtilities_PVT.Write_Debug('Segment10=' || p_asset_activity.Segment10);
1469 	EAM_ActivityUtilities_PVT.Write_Debug('Segment11=' || p_asset_activity.Segment11);
1470 	EAM_ActivityUtilities_PVT.Write_Debug('Segment12=' || p_asset_activity.Segment12);
1471 	EAM_ActivityUtilities_PVT.Write_Debug('Segment13=' || p_asset_activity.Segment13);
1472 	EAM_ActivityUtilities_PVT.Write_Debug('Segment14=' || p_asset_activity.Segment14);
1473 	EAM_ActivityUtilities_PVT.Write_Debug('Segment15=' || p_asset_activity.Segment15);
1474 	EAM_ActivityUtilities_PVT.Write_Debug('Segment16=' || p_asset_activity.Segment16);
1475 	EAM_ActivityUtilities_PVT.Write_Debug('Segment17=' || p_asset_activity.Segment17);
1476 	EAM_ActivityUtilities_PVT.Write_Debug('Segment18=' || p_asset_activity.Segment18);
1477 	EAM_ActivityUtilities_PVT.Write_Debug('Segment19=' || p_asset_activity.Segment19);
1478 	EAM_ActivityUtilities_PVT.Write_Debug('Segment20=' || p_asset_activity.Segment20);
1479 	EAM_ActivityUtilities_PVT.Write_Debug('Description=' || p_asset_activity.Description);
1480 
1481 	-- ============================================================
1482 	-- Step 1: Validate inputs
1483 	-- 1 a) Validate ???
1484 
1485 	-- fixthis: any other inputs needed to be validated?
1486 
1487 	-- 1 b) Validate copy options
1488 	Validate_Copy_Activity_Options(
1489 		p_bom_copy_option,
1490 		p_routing_copy_option,
1491 		p_association_copy_option
1492 	);
1493 
1494 	-- ============================================================
1495 	-- Step 2: Create Asset Activity. Call INV_Item_GRP package.
1496 
1497 	l_asset_activity := p_asset_activity;
1498 
1499 	l_asset_activity.EAM_ACTIVITY_TYPE_CODE := p_activity_type_code;
1500 	l_asset_activity.EAM_ACTIVITY_CAUSE_CODE := p_activity_cause_code;
1501 	l_asset_activity.EAM_ACT_NOTIFICATION_FLAG := p_notification_req_flag;
1502 	l_asset_activity.EAM_ACT_SHUTDOWN_STATUS := p_shutdown_type_code;
1503 	l_asset_activity.EAM_ACTIVITY_SOURCE_CODE := p_activity_source_code;
1504 
1505 	Create_Item(
1506 		p_asset_activity => l_asset_activity,
1507 		p_template_id => p_template_id,
1508 		p_template_name => p_template_name,
1509 
1510 		x_curr_item_rec 		=> l_x_curr_item_rec,
1511 		x_curr_item_return_status 	=> l_x_curr_item_return_status,
1512 		x_curr_item_error_tbl 		=> l_x_curr_item_error_tbl,
1513 		x_master_item_rec 		=> l_x_master_item_rec,
1514 		x_master_item_return_status 	=> l_x_master_item_return_status,
1515 		x_master_item_error_tbl 	=> l_x_master_item_error_tbl
1516 	);
1517 
1518 	IF l_x_master_item_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1519 		FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_CR_ACT_MASTER_FAILED');
1520 --		FND_MESSAGE.SET_ENCODED('Create Activity under Master Organization failed.');
1521 		EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
1522 		RAISE FND_API.G_EXC_ERROR;
1523 	END IF;
1524 
1525 	IF l_x_curr_item_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1526 		FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_CR_ACT_CURRENT_FAILED');
1527 --		FND_MESSAGE.SET_ENCODED('Create Activity under Current Organization failed.');
1528 		EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
1529 		RAISE FND_API.G_EXC_ERROR;
1530 	END IF;
1531 
1532 -- Set the Activity Attributes in the Item Record, don't have to do it manually
1533 /*
1534 	-- Overwrite Activity Properties with user-supplied values
1535 	l_x_master_item_rec.EAM_ACTIVITY_TYPE_CODE := p_activity_type_code;
1536 	l_x_master_item_rec.EAM_ACTIVITY_CAUSE_CODE  := p_activity_cause_code;
1537 	l_x_master_item_rec.EAM_ACT_SHUTDOWN_STATUS := p_shutdown_type_code;
1538 	l_x_master_item_rec.EAM_ACT_NOTIFICATION_FLAG := p_notification_req_flag;
1539 
1540 	BEGIN
1541 		UPDATE	mtl_system_items
1542 		SET	EAM_ACTIVITY_TYPE_CODE = p_activity_type_code,
1543 			EAM_ACTIVITY_CAUSE_CODE = p_activity_cause_code,
1544 			EAM_ACT_SHUTDOWN_STATUS = p_shutdown_type_code,
1545 			EAM_ACT_NOTIFICATION_FLAG = p_notification_req_flag,
1546 			EAM_ACTIVITY_SOURCE_CODE = p_activity_source_code
1547 		WHERE	inventory_item_id = l_x_master_item_rec.inventory_item_id
1548 		AND	organization_id = l_x_master_item_rec.organization_id;
1549 	EXCEPTION
1550 		WHEN OTHERS THEN
1551 			IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1552 				FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_ACT_PROPERTIES');
1553 				FND_MSG_PUB.ADD;
1554 			END IF;
1555 			RAISE FND_API.G_EXC_ERROR;
1556 	END;
1557 
1558 	l_x_curr_item_rec.EAM_ACTIVITY_TYPE_CODE := p_activity_type_code;
1559 	l_x_curr_item_rec.EAM_ACTIVITY_CAUSE_CODE  := p_activity_cause_code;
1560 	l_x_curr_item_rec.EAM_ACT_SHUTDOWN_STATUS := p_shutdown_type_code;
1561 	l_x_curr_item_rec.EAM_ACT_NOTIFICATION_FLAG := p_notification_req_flag;
1562 
1563 	BEGIN
1564 		UPDATE	mtl_system_items
1565 		SET	EAM_ACTIVITY_TYPE_CODE = p_activity_type_code,
1566 			EAM_ACTIVITY_CAUSE_CODE = p_activity_cause_code,
1567 			EAM_ACT_SHUTDOWN_STATUS = p_shutdown_type_code,
1568 			EAM_ACT_NOTIFICATION_FLAG = p_notification_req_flag,
1569 			EAM_ACTIVITY_SOURCE_CODE = p_activity_source_code
1570 		WHERE	inventory_item_id = l_x_curr_item_rec.inventory_item_id
1571 		AND	organization_id = l_x_curr_item_rec.organization_id;
1572 	EXCEPTION
1573 		WHEN OTHERS THEN
1574 			IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1575 				FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_ACT_PROPERTIES');
1576 				FND_MSG_PUB.ADD;
1577 			END IF;
1578 			RAISE FND_API.G_EXC_ERROR;
1579 	END;
1580 */
1581 
1582 	-- Assign outputs
1583 	x_curr_item_rec 		:= l_x_curr_item_rec;
1584 	x_curr_item_return_status 	:= l_x_curr_item_return_status;
1585 	x_curr_item_error_tbl 		:= l_x_curr_item_error_tbl;
1586 	x_master_item_rec 		:= l_x_master_item_rec;
1587 	x_master_item_return_status 	:= l_x_master_item_return_status;
1588 	x_master_item_error_tbl 	:= l_x_master_item_error_tbl;
1589 
1590 	-- ============================================================
1591         -- Bug # 3662214 : Need to create Routing first and then BOM so
1592 	-- that operation sequence number in BOM is retained.
1593 
1594 	-- Step 3: Copy Routing
1595 	EAM_ActivityUtilities_PVT.Write_Debug('-------- Beginning Copy Routing --------');
1596 
1597 	-- 3 a) Check Routing Copy Option
1598 	EAM_ActivityUtilities_PVT.Write_Debug('p_routing_copy_option=' || p_routing_copy_option);
1599 	IF p_routing_copy_option = 2 THEN
1600 
1601 		-- 3 b) Check if Source has Routing (sequence id)
1602 		l_source_rtg_sequence_id := EAM_ActivityUtilities_PVT.Get_Rtg_Sequence_id(
1603 								p_organization_id => p_source_org_id,
1604 								p_assembly_item_id => p_source_activity_id,
1605 								p_alternate_rtg_designator => p_source_alt_rtg_designator);
1606 		EAM_ActivityUtilities_PVT.Write_Debug('l_source_rtg_sequence_id=' || l_source_rtg_sequence_id);
1607 
1608 		IF l_source_rtg_sequence_id IS NULL THEN
1609 			-- Source Activity does not have Routing, nothing to copy
1610 			NULL;
1611 		ELSE
1612 
1613 			-- 4 c) Create target Routing header
1614 
1615 --			l_rtg_header_rec := NULL;
1616 			-- populate fields
1617 			l_rtg_header_rec.Transaction_Type := l_create_txn_type;
1618 			l_rtg_header_rec.Assembly_Item_Name := l_x_curr_item_rec.Item_Number;
1619 			l_rtg_header_rec.Organization_Code := l_x_curr_item_rec.Organization_Code;
1620 
1621 			Error_Handler.initialize;
1622 			-- log call to Process_Rtg API
1623 			EAM_ActivityUtilities_PVT.Write_Debug('********** Calling BOM_RTG_PUB.Process_Rtg **********');
1624 			BOM_RTG_PUB.Process_Rtg(
1625 				p_rtg_header_rec 	=> l_rtg_header_rec
1626 				, x_rtg_header_rec	=> l_x_rtg_header_rec
1627 				, x_rtg_revision_tbl	=> l_x_rtg_revision_tbl
1628 				, x_operation_tbl	=> l_x_operation_tbl
1629 				, x_op_resource_tbl	=> l_x_op_resource_tbl
1630 				, x_sub_resource_tbl	=> l_x_sub_resource_tbl
1631 				, x_op_network_tbl	=> l_x_op_network_tbl
1632 				, x_return_status	=> l_x_rtg_return_status
1633 				, x_msg_count		=> l_x_rtg_msg_count
1634 			);
1635 			EAM_ActivityUtilities_PVT.Write_Debug('********** Returned from BOM_RTG_PUB.Process_Rtg **********');
1636 
1637 			-- log errors
1638 			EAM_ActivityUtilities_PVT.Write_Debug('l_x_rtg_return_status=' || l_x_rtg_return_status);
1639 			EAM_ActivityUtilities_PVT.Write_Debug('l_x_rtg_msg_count=' || l_x_rtg_msg_count);
1640 			Error_Handler.Get_Message_List(l_x_rtg_msg_list);
1641 			EAM_ActivityUtilities_PVT.Write_Debug('Results of BOM_RTG_PUB.Process_Rtg >>>>>');
1642 			EAM_ActivityUtilities_PVT.Log_Bom_Error_Tbl(l_x_rtg_msg_list);
1643 			EAM_ActivityUtilities_PVT.Write_Debug('End of Results of BOM_RTG_PUB.Process_Rtg <<<<<');
1644 
1645 			-- Handle errors
1646 			IF l_x_bom_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1647 				FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_BOM_BO_FAILED');
1648 		--		FND_MESSAGE.SET_ENCODED('Call to Routing Business Object API Failed.');
1649 				EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
1650 				RAISE FND_API.G_EXC_ERROR;
1651 			END IF;
1652 
1653 			l_target_rtg_sequence_id := EAM_ActivityUtilities_PVT.Get_Rtg_Sequence_id(
1654 							p_organization_id => l_x_curr_item_rec.organization_id,
1655 							p_assembly_item_id => l_x_curr_item_rec.inventory_item_id,
1656 							p_alternate_rtg_designator => NULL);
1657 			EAM_ActivityUtilities_PVT.Write_Debug('l_target_rtg_sequence_id=' || l_target_rtg_sequence_id);
1658 
1659 			-- 4 d) Call copy_routing API
1660 			-- log call to copy_routing API
1661 			EAM_ActivityUtilities_PVT.Write_Debug('********** Calling BOM_COPY_ROUTING.copy_routing **********');
1662 			BOM_COPY_ROUTING.copy_routing(
1663 				to_sequence_id		=>	l_target_rtg_sequence_id,
1664 				from_sequence_id	=>	l_source_rtg_sequence_id,
1665 				from_org_id		=>	p_source_org_id,
1666 				to_org_id		=>	l_x_curr_item_rec.organization_id,
1667 				user_id			=>	FND_GLOBAL.USER_ID,
1668 				to_item_id		=>	l_x_curr_item_rec.inventory_item_id,
1669 				direction		=>	1,
1670 				to_alternate		=>	NULL,
1671 				rev_date		=>	p_source_rtg_rev_date
1672 			);
1673 			EAM_ActivityUtilities_PVT.Write_Debug('********** Returned from BOM_COPY_ROUTING.copy_routing **********');
1674 
1675 			-- write copy_routing error message to fnd message stack and log file
1676 			EAM_ActivityUtilities_PVT.Write_Debug('Results of BOM_COPY_ROUTING.copy_routing >>>>>');
1677 			EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
1678 			EAM_ActivityUtilities_PVT.Write_Debug('End of Results of BOM_COPY_ROUTING.copy_routing <<<<<');
1679 
1680 		END IF; -- l_source_rtg_sequence_id IS NULL
1681 
1682 	END IF; -- p_routing_copy_option
1683 
1684 	EAM_ActivityUtilities_PVT.Write_Debug('-------- Finished Copy Routing --------');
1685 
1686 	-- ============================================================
1687 	-- Step 4: Copy BOM
1688 	EAM_ActivityUtilities_PVT.Write_Debug('-------- Beginning Copy BOM --------');
1689 
1690 	-- 4 a) Check BOM Copy Option
1691 	EAM_ActivityUtilities_PVT.Write_Debug('p_bom_copy_option=' || p_bom_copy_option);
1692 	IF p_bom_copy_option = 2 THEN
1693 
1694 		-- 4 b) Check if Source has BOM (sequence_id)
1695 		l_source_bom_sequence_id := EAM_ActivityUtilities_PVT.Get_Bom_Sequence_id(
1696 								p_organization_id => p_source_org_id,
1697 								p_assembly_item_id => p_source_activity_id,
1698 								p_alternate_bom_designator => p_source_alt_bom_designator);
1699 		EAM_ActivityUtilities_PVT.Write_Debug('l_source_bom_sequence_id=' || l_source_bom_sequence_id);
1700 
1701 		IF l_source_bom_sequence_id IS NULL THEN
1702 			-- Source Activity does not have BOM, nothing to copy
1703 			NULL;
1704 		ELSE
1705 
1706 			-- 3 c) Create target BOM header (and get bom sequence_id)
1707 --			l_bom_head_rec := NULL;
1708 			l_bom_head_rec.Transaction_Type := l_create_txn_type;
1709 			l_bom_head_rec.Assembly_Item_Name := l_x_curr_item_rec.Item_Number;
1710 			l_bom_head_rec.Organization_Code := l_x_curr_item_rec.Organization_Code;
1711 			l_bom_head_rec.Assembly_Type := 1;
1712 
1713 			-- Create empty BOM header through BOM Business Object API
1714 			Error_Handler.initialize;
1715 			-- log call to Process_BOM API
1716 			EAM_ActivityUtilities_PVT.Write_Debug('********** Calling BOM_BO_PUB.Process_BOM **********');
1717 			BOM_BO_PUB.Process_BOM(
1718 				p_bom_header_rec 		=> l_bom_head_rec,
1719 				x_bom_header_rec 		=> l_x_bom_header_rec,
1720 				x_bom_revision_tbl 		=> l_x_bom_revision_tbl,
1721 				x_bom_component_tbl 		=> l_x_bom_component_tbl,
1722 				x_bom_ref_designator_tbl 	=> l_x_bom_ref_designator_tbl,
1723 				x_bom_sub_component_tbl		=> l_x_bom_sub_component_tbl,
1724 				x_return_status			=> l_x_bom_return_status,
1725 				x_msg_count			=> l_x_bom_msg_count
1726 			);
1727 			EAM_ActivityUtilities_PVT.Write_Debug('********** Returned from BOM_BO_PUB.Process_BOM **********');
1728 
1729 			-- log errors
1730 			EAM_ActivityUtilities_PVT.Write_Debug('l_x_bom_return_status=' || l_x_bom_return_status);
1731 			EAM_ActivityUtilities_PVT.Write_Debug('l_x_bom_msg_count=' || l_x_bom_msg_count);
1732 			Error_Handler.Get_Message_List(l_x_bom_msg_list);
1733 			EAM_ActivityUtilities_PVT.Write_Debug('Results of BOM_BO_PUB.Process_BOM >>>>>');
1734 			EAM_ActivityUtilities_PVT.Log_Bom_Error_Tbl(l_x_bom_msg_list);
1735 			EAM_ActivityUtilities_PVT.Write_Debug('End of Results of BOM_BO_PUB.Process_BOM <<<<<');
1736 
1737 			-- Handle errors
1738 			IF l_x_rtg_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1739 				FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_RTG_BO_FAILED');
1740 --				FND_MESSAGE.SET_ENCODED('Call to Routing Business Object API Failed.');
1741 				EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
1742 				RAISE FND_API.G_EXC_ERROR;
1743 			END IF;
1744 
1745 			l_target_bom_sequence_id := EAM_ActivityUtilities_PVT.Get_Bom_Sequence_id(
1746 							p_organization_id => l_x_curr_item_rec.organization_id,
1747 							p_assembly_item_id => l_x_curr_item_rec.inventory_item_id,
1748 							p_alternate_bom_designator => NULL);
1749 			EAM_ActivityUtilities_PVT.Write_Debug('l_target_bom_sequence_id=' || l_target_bom_sequence_id);
1750 
1751 			-- 3 d) Call copy_bill API
1752 			-- log call to copy_bill API
1753 			EAM_ActivityUtilities_PVT.Write_Debug('********** Calling BOM_COPY_BILL.copy_bill **********');
1754   			BOM_COPY_BILL.copy_bill(
1755 				to_sequence_id		=>	l_target_bom_sequence_id,
1756 				from_sequence_id 	=>	l_source_bom_sequence_id,
1757 				from_org_id		=>	p_source_org_id,
1758 				to_org_id		=>	l_x_curr_item_rec.organization_id,
1759 				user_id			=>	FND_GLOBAL.USER_ID,
1760 				to_item_id		=>	l_x_curr_item_rec.inventory_item_id,
1761 				direction		=>	1,
1762 				to_alternate		=>	NULL,
1763 				rev_date		=>	p_source_bom_rev_date,
1764 				e_change_notice		=>	NULL,
1765 				rev_item_seq_id		=>	NULL,
1766 				bill_or_eco		=>	1,
1767 				eco_eff_date		=>	NULL,
1768 				from_item_id		=>	p_source_activity_id
1769 			);
1770 			EAM_ActivityUtilities_PVT.Write_Debug('********** Returned from BOM_COPY_BILL.copy_bill **********');
1771 
1772 			-- write copy_bill error message to fnd message stack and log file
1773 			EAM_ActivityUtilities_PVT.Write_Debug('Results of BOM_COPY_BILL.copy_bill >>>>>');
1774 			EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
1775 			EAM_ActivityUtilities_PVT.Write_Debug('End of Results of BOM_COPY_BILL.copy_bill <<<<<');
1776 
1777 
1778 		END IF; -- l_source_bom_sequence_id IS NULL
1779 
1780 	END IF; -- p_bom_copy_option = 2
1781 
1782 	EAM_ActivityUtilities_PVT.Write_Debug('-------- Finished Copy BOM --------');
1783 
1784 	-- ============================================================
1785 	-- Step 5: Update Association to Asset Numbers for the newly created activity
1786 	EAM_ActivityUtilities_PVT.Write_Debug('-------- Beginning Copy Association --------');
1787 
1788 	EAM_ActivityUtilities_PVT.Write_Debug('p_association_copy_option=' || p_association_copy_option);
1789 	IF p_association_copy_option <> 1 THEN
1790 		-- p_association_copy_option <> 1 (NONE), call private package to create association
1791 		EAM_ActivityUtilities_PVT.Write_Debug(
1792 			'********** Calling EAM_ActivityAssociation_PVT.Create_Association **********');
1793 		EAM_ActivityAssociation_PVT.Create_Association(
1794 			p_api_version => 1.0,
1795 			x_return_status => l_x_assoc_return_status,
1796 			x_msg_count => l_x_assoc_msg_count,
1797 			x_msg_data => l_x_assoc_msg_data,
1798 
1799 			p_target_org_id => l_x_curr_item_rec.organization_id,
1800 			p_target_activity_id => l_x_curr_item_rec.inventory_item_id,
1801   			p_wip_entity_id	=> NULL,
1802 			p_source_org_id => p_source_org_id,
1803 			p_source_activity_id => p_source_activity_id,
1804 			p_association_copy_option => p_association_copy_option,
1805 
1806 			x_act_num_association_tbl => l_x_act_num_association_tbl,
1807 			x_activity_association_tbl => l_x_activity_association_tbl
1808 		);
1809 		EAM_ActivityUtilities_PVT.Write_Debug(
1810 			'********** Returned from EAM_ActivityAssociation_PVT.Create_Association **********');
1811 		EAM_ActivityUtilities_PVT.Write_Debug('l_x_assoc_return_status=' || l_x_assoc_return_status);
1812 		EAM_ActivityUtilities_PVT.Write_Debug('l_x_assoc_msg_count=' || l_x_assoc_msg_count);
1813 		EAM_ActivityUtilities_PVT.Write_Debug('l_x_assoc_msg_data=' || l_x_assoc_msg_data);
1814 
1815 		-- Assing outputs
1816 		x_assoc_return_status := l_x_assoc_return_status;
1817 		x_assoc_msg_count := l_x_assoc_msg_count;
1818 		x_assoc_msg_data := l_x_assoc_msg_data;
1819 		x_act_num_association_tbl := l_x_act_num_association_tbl;
1820 		x_activity_association_tbl := l_x_activity_association_tbl;
1821 
1822 		-- Handle error
1823 		IF l_x_assoc_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1824 			FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_CR_ASSOC_FAILED');
1825 --			FND_MESSAGE.SET_ENCODED('Create Activity Associations failed.');
1826 			EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
1827 			RAISE FND_API.G_EXC_ERROR;
1828 		END IF;
1829 
1830 	END IF;
1831 
1832 	EAM_ActivityUtilities_PVT.Write_Debug('-------- Finished Copy Association --------');
1833 
1834 	-- ======================================================================
1835 
1836 
1837 	-- End of API body.
1838 	-- Standard check of p_commit.
1839 	IF FND_API.To_Boolean( p_commit ) THEN
1840 		COMMIT WORK;
1841 	END IF;
1842 	-- Standard call to get message count and if count is 1, get message info.
1843 	FND_MSG_PUB.Count_And_Get
1844     	(  	p_count         	=>      x_msg_count     	,
1845         	p_data          	=>      x_msg_data
1846     	);
1847 
1848 	EAM_ActivityUtilities_PVT.Write_Debug('========== Exiting EAM_Activity_PUB.Copy_Activity ==========');
1849 
1850 
1851 	-- ======================================================================
1852 EXCEPTION
1853     WHEN FND_API.G_EXC_ERROR THEN
1854 		ROLLBACK TO Copy_Activity_PUB;
1855 		EAM_ActivityUtilities_PVT.Write_Debug('========== EAM_Activity_PUB.Copy_Activity: EXPECTED_ERROR ==========');
1856 		x_return_status := FND_API.G_RET_STS_ERROR ;
1857 		FND_MSG_PUB.Count_And_Get
1858     		(  	p_count         	=>      x_msg_count     	,
1859         		p_data          	=>      x_msg_data
1860     		);
1861 	WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1862 		ROLLBACK TO Copy_Activity_PUB;
1863 		EAM_ActivityUtilities_PVT.Write_Debug('========== EAM_Activity_PUB.Copy_Activity: UNEXPECTED_ERROR ==========');
1864 		x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1865 		FND_MSG_PUB.Count_And_Get
1866     		(  	p_count         	=>      x_msg_count     	,
1867         		p_data          	=>      x_msg_data
1868     		);
1869 
1870 	WHEN OTHERS THEN
1871 		ROLLBACK TO Copy_Activity_PUB;
1872 		x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1873   		IF 	FND_MSG_PUB.Check_Msg_Level
1874 			(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1875 		THEN
1876         		FND_MSG_PUB.Add_Exc_Msg
1877     	    		(	G_PKG_NAME  	    ,
1878     	    			l_api_name
1879 	    		);
1880 			-- log error message also
1881 			EAM_ActivityUtilities_PVT.Write_Debug(FND_MSG_PUB.Get(FND_MSG_PUB.G_LAST, FND_API.G_FALSE));
1882 		END IF;
1883 		EAM_ActivityUtilities_PVT.Write_Debug('========== EAM_Activity_PUB.Copy_Activity: OTHER ERROR ==========');
1884 		FND_MSG_PUB.Count_And_Get
1885     		(  	p_count         	=>      x_msg_count     	,
1886         		p_data          	=>      x_msg_data
1887     		);
1888 END Copy_Activity;
1889 
1890 
1891 -- ================================================================================
1892 
1893 PROCEDURE Create_Activity_From_Form (
1894 	p_wip_entity_id			IN	NUMBER
1895 	, p_asset_activity		IN	VARCHAR2
1896 	, p_segment1			IN	VARCHAR2
1897 	, p_segment2			IN	VARCHAR2
1898 	, p_segment3			IN	VARCHAR2
1899 	, p_segment4			IN	VARCHAR2
1900 	, p_segment5			IN	VARCHAR2
1901 	, p_segment6			IN	VARCHAR2
1902 	, p_segment7			IN	VARCHAR2
1903 	, p_segment8			IN	VARCHAR2
1904 	, p_segment9			IN	VARCHAR2
1905 	, p_segment10			IN	VARCHAR2
1906 	, p_segment11			IN	VARCHAR2
1907 	, p_segment12			IN	VARCHAR2
1908 	, p_segment13			IN	VARCHAR2
1909 	, p_segment14			IN	VARCHAR2
1910 	, p_segment15			IN	VARCHAR2
1911 	, p_segment16			IN	VARCHAR2
1912 	, p_segment17			IN	VARCHAR2
1913 	, p_segment18			IN	VARCHAR2
1914 	, p_segment19			IN	VARCHAR2
1915 	, p_segment20			IN	VARCHAR2
1916 	, p_description			IN	VARCHAR2
1917 	, p_template_id			IN	NUMBER
1918 	, p_activity_type_code		IN	VARCHAR2
1919 	, p_activity_cause_code 	IN	VARCHAR2
1920 	, p_shutdown_type_code		IN	VARCHAR2
1921 	, p_notification_req_flag	IN	VARCHAR2
1922 	, p_activity_source_code	IN	VARCHAR2
1923 
1924 	, p_operation_copy_option	IN	NUMBER
1925 	, p_material_copy_option	IN	NUMBER
1926 	, p_resource_copy_option	IN	NUMBER
1927 	, p_association_copy_option	IN	NUMBER
1928 	, x_successful			OUT NOCOPY	BOOLEAN
1929 	)
1930 IS
1931 
1932 	l_create_activity_ver		NUMBER := 1.0;
1933 	l_x_return_status		VARCHAR2(1);
1934 	l_x_msg_count			NUMBER;
1935 	l_x_msg_data			VARCHAR2(20000);
1936 
1937 	l_asset_activity		INV_Item_GRP.Item_Rec_Type;
1938 	l_work_order_rec		EAM_Activity_PUB.Work_Order_Rec_Type;
1939 	l_x_inventory_item_id		NUMBER;
1940 	l_x_work_order_rec		EAM_Activity_PUB.Work_Order_Rec_Type;
1941 
1942 -- output variables of inv package
1943 	l_x_curr_item_rec		INV_Item_GRP.Item_Rec_Type;
1944 	l_x_curr_item_return_status	VARCHAR2(1);
1945 	l_x_curr_item_error_tbl		INV_Item_GRP.Error_Tbl_Type;
1946 	l_x_master_item_rec		INV_Item_GRP.Item_Rec_Type;
1947 	l_x_master_item_return_status	VARCHAR2(1);
1948 	l_x_master_item_error_tbl	INV_Item_GRP.Error_Tbl_Type;
1949 -- output variables of Routing Business Object API
1950 	l_x_rtg_header_rec		BOM_RTG_PUB.Rtg_Header_Rec_Type;
1951 	l_x_rtg_revision_tbl		BOM_RTG_PUB.Rtg_Revision_Tbl_Type;
1952 	l_x_operation_tbl		BOM_RTG_PUB.Operation_Tbl_Type;
1953 	l_x_op_resource_tbl		BOM_RTG_PUB.Op_Resource_Tbl_Type;
1954 	l_x_sub_resource_tbl		BOM_RTG_PUB.Sub_Resource_Tbl_Type;
1955 	l_x_op_network_tbl		BOM_RTG_PUB.Op_Network_Tbl_Type;
1956 	l_x_rtg_return_status		VARCHAR2(1);
1957 	l_x_rtg_msg_count		NUMBER;
1958 -- output variables of BOM Business Object API
1959 	l_x_bom_header_rec		BOM_BO_PUB.Bom_Head_Rec_Type;
1960 	l_x_bom_revision_tbl		BOM_BO_PUB.Bom_Revision_Tbl_Type;
1961 	l_x_bom_component_tbl		BOM_BO_PUB.Bom_Comps_Tbl_Type;
1962 	l_x_bom_ref_designator_tbl	BOM_BO_PUB.Bom_Ref_Designator_Tbl_Type;
1963 	l_x_bom_sub_component_tbl	BOM_BO_PUB.Bom_Sub_Component_Tbl_Type;
1964 	l_x_bom_return_status		VARCHAR2(1);
1965 	l_x_bom_msg_count		NUMBER;
1966 -- Routing and BOM common Error Handler
1967 	l_x_bom_error_list		Error_Handler.Error_Tbl_Type;
1968 	l_x_bom_error_count		INTEGER;
1969 	l_bom_error_count		INTEGER;
1970 	l_index				BINARY_INTEGER;
1971 	l_x_rtg_error_list		Error_Handler.Error_Tbl_Type;
1972 	l_x_rtg_error_count		INTEGER;
1973 -- Activity Association
1974 	l_x_assoc_return_status		VARCHAR2(1);
1975 	l_x_assoc_msg_count		NUMBER;
1976 	l_x_assoc_msg_data		VARCHAR2(20000);
1977 	l_x_act_num_association_tbl	EAM_Activity_PUB.Activity_Association_Tbl_Type;
1978 	l_x_activity_association_tbl	EAM_Activity_PUB.Activity_Association_Tbl_Type;
1979 
1980 BEGIN
1981 
1982 	EAM_ActivityUtilities_PVT.Open_Debug_Session;
1983 
1984 	-- 1: Step up activity parameters
1985 	l_work_order_rec.wip_entity_id := p_wip_entity_id;
1986 	l_asset_activity.Description := p_description;
1987 
1988 	-- 1.1: Set up Item Number. Use segments if specified.
1989 	IF 	p_segment1 IS NOT NULL OR
1990 		p_segment2 IS NOT NULL OR
1991 		p_segment3 IS NOT NULL OR
1992 		p_segment4 IS NOT NULL OR
1993 		p_segment5 IS NOT NULL OR
1994 		p_segment6 IS NOT NULL OR
1995 		p_segment7 IS NOT NULL OR
1996 		p_segment8 IS NOT NULL OR
1997 		p_segment9 IS NOT NULL OR
1998 		p_segment10 IS NOT NULL OR
1999 		p_segment11 IS NOT NULL OR
2000 		p_segment12 IS NOT NULL OR
2001 		p_segment13 IS NOT NULL OR
2002 		p_segment14 IS NOT NULL OR
2003 		p_segment15 IS NOT NULL OR
2004 		p_segment16 IS NOT NULL OR
2005 		p_segment17 IS NOT NULL OR
2006 		p_segment18 IS NOT NULL OR
2007 		p_segment19 IS NOT NULL OR
2008 		p_segment20 IS NOT NULL
2009 	THEN
2010 		l_asset_activity.Segment1 := p_segment1;
2011 		l_asset_activity.Segment2 := p_segment2;
2012 		l_asset_activity.Segment3 := p_segment3;
2013 		l_asset_activity.Segment4 := p_segment4;
2014 		l_asset_activity.Segment5 := p_segment5;
2015 		l_asset_activity.Segment6 := p_segment6;
2016 		l_asset_activity.Segment7 := p_segment7;
2017 		l_asset_activity.Segment8 := p_segment8;
2018 		l_asset_activity.Segment9 := p_segment9;
2019 		l_asset_activity.Segment10 := p_segment10;
2020 		l_asset_activity.Segment11 := p_segment11;
2021 		l_asset_activity.Segment12 := p_segment12;
2022 		l_asset_activity.Segment13 := p_segment13;
2023 		l_asset_activity.Segment14 := p_segment14;
2024 		l_asset_activity.Segment15 := p_segment15;
2025 		l_asset_activity.Segment16 := p_segment16;
2026 		l_asset_activity.Segment17 := p_segment17;
2027 		l_asset_activity.Segment18 := p_segment18;
2028 		l_asset_activity.Segment19 := p_segment19;
2029 		l_asset_activity.Segment20 := p_segment20;
2030 	ELSE
2031 		l_asset_activity.Item_Number := p_asset_activity;
2032 	END IF;
2033 
2034 	-- Set EAM attributes
2035 	l_asset_activity.EAM_ITEM_TYPE := 2; -- EAM Asset Activity
2036 
2037 	EAM_Activity_PUB.Create_Activity(
2038 		p_api_version => l_create_activity_ver,
2039 
2040 		x_return_status => l_x_return_status,
2041 		x_msg_count => l_x_msg_count,
2042 		x_msg_data => l_x_msg_data,
2043 
2044 		p_asset_activity => l_asset_activity,
2045 		p_template_id => p_template_id,
2046 
2047 		p_activity_type_code	=> p_activity_type_code,
2048 		p_activity_cause_code 	=> p_activity_cause_code,
2049 		p_shutdown_type_code	=> p_shutdown_type_code,
2050 		p_notification_req_flag	=> p_notification_req_flag,
2051  		p_activity_source_code => p_activity_source_code,
2052 
2053 		p_work_order_rec => l_work_order_rec,
2054 		p_operation_copy_option => p_operation_copy_option,
2055 		p_material_copy_option => p_material_copy_option,
2056 		p_resource_copy_option => p_resource_copy_option,
2057 		p_association_copy_option => p_association_copy_option,
2058 
2059 --		x_inventory_item_id => l_x_inventory_item_id,
2060 		x_work_order_rec => l_x_work_order_rec
2061 
2062 -- inv variables
2063 		, x_curr_item_rec => l_x_curr_item_rec
2064 		, x_curr_item_return_status => l_x_curr_item_return_status
2065 		, x_curr_item_error_tbl => l_x_curr_item_error_tbl
2066 		, x_master_item_rec => l_x_master_item_rec
2067 		, x_master_item_return_status => l_x_master_item_return_status
2068 		, x_master_item_error_tbl => l_x_master_item_error_tbl
2069 
2070 -- Routing outputs
2071 		, x_rtg_header_rec	=> l_x_rtg_header_rec
2072 		, x_rtg_revision_tbl	=> l_x_rtg_revision_tbl
2073 		, x_operation_tbl	=> l_x_operation_tbl
2074 		, x_op_resource_tbl	=> l_x_op_resource_tbl
2075 		, x_sub_resource_tbl	=> l_x_sub_resource_tbl
2076 		, x_op_network_tbl	=> l_x_op_network_tbl
2077 		, x_rtg_return_status	=> l_x_rtg_return_status
2078 		, x_rtg_msg_count	=> l_x_rtg_msg_count
2079 		, x_rtg_msg_list	=> l_x_rtg_error_list
2080 -- BOM outputs
2081 		, x_bom_header_rec 		=> l_x_bom_header_rec
2082 		, x_bom_revision_tbl 		=> l_x_bom_revision_tbl
2083 		, x_bom_component_tbl 		=> l_x_bom_component_tbl
2084 		, x_bom_ref_designator_tbl 	=> l_x_bom_ref_designator_tbl
2085 		, x_bom_sub_component_tbl	=> l_x_bom_sub_component_tbl
2086 		, x_bom_return_status		=> l_x_bom_return_status
2087 		, x_bom_msg_count		=> l_x_bom_msg_count
2088 		, x_bom_msg_list		=> l_x_bom_error_list
2089 
2090 		, x_assoc_return_status 	=> l_x_assoc_return_status
2091 		, x_assoc_msg_count		=> l_x_assoc_msg_count
2092 		, x_assoc_msg_data		=> l_x_assoc_msg_data
2093 		, x_act_num_association_tbl	=> l_x_act_num_association_tbl
2094 		, x_activity_association_tbl	=> l_x_activity_association_tbl
2095 
2096 	);
2097 
2098 	-- Assign outputs
2099 
2100 	IF l_x_return_status = FND_API.G_RET_STS_SUCCESS THEN
2101 		commit;
2102 		x_successful := TRUE;
2103 	ELSE
2104 		x_successful := FALSE;
2105 	END IF;
2106 
2107 	EAM_ActivityUtilities_PVT.Close_Debug_Session;
2108 
2109 END Create_Activity_From_Form;
2110 
2111 
2112 -- ================================================================================
2113 
2114 PROCEDURE Create_Activity_With_Template(
2115  	p_api_version           	IN	NUMBER				,
2116   	p_init_msg_list			IN	VARCHAR2 := FND_API.G_FALSE	,
2117 	p_commit	    		IN  	VARCHAR2 := FND_API.G_FALSE	,
2118 	p_validation_level		IN  	NUMBER	:=
2119 						FND_API.G_VALID_LEVEL_FULL	,
2120 	x_return_status			OUT NOCOPY	VARCHAR2		  	,
2121 	x_msg_count			OUT NOCOPY	NUMBER				,
2122 	x_msg_data			OUT NOCOPY	VARCHAR2			,
2123 
2124 	p_organization_id		IN	NUMBER 		:= NULL,
2125 	p_organization_code		IN	NUMBER		:= NULL,
2126 	p_asset_activity		IN	VARCHAR2,
2127 	p_segment1			IN	VARCHAR2,
2128 	p_segment2			IN	VARCHAR2,
2129 	p_segment3			IN	VARCHAR2,
2130 	p_segment4			IN	VARCHAR2,
2131 	p_segment5			IN	VARCHAR2,
2132 	p_segment6			IN	VARCHAR2,
2133 	p_segment7			IN	VARCHAR2,
2134 	p_segment8			IN	VARCHAR2,
2135 	p_segment9			IN	VARCHAR2,
2136 	p_segment10			IN	VARCHAR2,
2137 	p_segment11			IN	VARCHAR2,
2138 	p_segment12			IN	VARCHAR2,
2139 	p_segment13			IN	VARCHAR2,
2140 	p_segment14			IN	VARCHAR2,
2141 	p_segment15			IN	VARCHAR2,
2142 	p_segment16			IN	VARCHAR2,
2143 	p_segment17			IN	VARCHAR2,
2144 	p_segment18			IN	VARCHAR2,
2145 	p_segment19			IN	VARCHAR2,
2146 	p_segment20			IN	VARCHAR2,
2147 	p_description			IN	VARCHAR2,
2148 	p_template_id			IN	NUMBER 		:= NULL,
2149 	p_template_name			IN	VARCHAR2 	:= NULL,
2150 	p_activity_type_code		IN	VARCHAR2	:= NULL,
2151 	p_activity_cause_code 		IN	VARCHAR2	:= NULL,
2152 	p_shutdown_type_code		IN	VARCHAR2	:= NULL,
2153 	p_notification_req_flag		IN	VARCHAR2	:= NULL,
2154 	p_activity_source_code		IN	VARCHAR2	:= NULL,
2155 
2156 	x_curr_item_rec			OUT NOCOPY	INV_Item_GRP.Item_Rec_Type,
2157 	x_curr_item_return_status	OUT NOCOPY	VARCHAR2,
2158 	x_curr_item_error_tbl		OUT NOCOPY	INV_Item_GRP.Error_Tbl_Type,
2159 	x_master_item_rec		OUT NOCOPY	INV_Item_GRP.Item_Rec_Type,
2160 	x_master_item_return_status	OUT NOCOPY	VARCHAR2,
2161 	x_master_item_error_tbl		OUT NOCOPY	INV_Item_GRP.Error_Tbl_Type
2162 
2163 )
2164 IS
2165 
2166 l_asset_activity		INV_Item_GRP.Item_rec_type;
2167 
2168 l_api_name			CONSTANT VARCHAR2(30)	:= 'Create_Activity_With_Template';
2169 l_api_version           	CONSTANT NUMBER 	:= 1.0;
2170 
2171 l_x_curr_item_rec		INV_Item_GRP.Item_rec_type;
2172 l_x_curr_item_return_status	VARCHAR2(1);
2173 l_x_curr_item_error_tbl		INV_Item_GRP.Error_tbl_type;
2174 
2175 l_x_master_item_rec	INV_Item_GRP.Item_rec_type;
2176 l_x_master_item_return_status	VARCHAR2(1);
2177 l_x_master_item_error_tbl	INV_Item_GRP.Error_tbl_type;
2178 
2179 BEGIN
2180 	-- Standard Start of API savepoint
2181     SAVEPOINT	Create_Act_With_Templ_PUB;
2182     -- Standard call to check for call compatibility.
2183     IF NOT FND_API.Compatible_API_Call ( 	l_api_version        	,
2184         	    	    	    	 	p_api_version        	,
2185    	       	    	 			l_api_name 	    	,
2186 		    	    	    	    	G_PKG_NAME )
2187 	THEN
2188 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2189 	END IF;
2190 	-- Initialize message list if p_init_msg_list is set to TRUE.
2191 	IF FND_API.to_Boolean( p_init_msg_list ) THEN
2192 		FND_MSG_PUB.initialize;
2193 	END IF;
2194 	--  Initialize API return status to success
2195     x_return_status := FND_API.G_RET_STS_SUCCESS;
2196 	-- API body
2197 
2198 	-- ============================================================
2199 	EAM_ActivityUtilities_PVT.Write_Debug('========== Entering EAM_Activity_PUB.Create_Activity_With_Template ==========');
2200 	EAM_ActivityUtilities_PVT.Write_Debug('p_organization_id=' || p_organization_id);
2201 	EAM_ActivityUtilities_PVT.Write_Debug('p_organization_code=' || p_organization_code);
2202 	EAM_ActivityUtilities_PVT.Write_Debug('p_asset_activity=' || p_asset_activity);
2203 	EAM_ActivityUtilities_PVT.Write_Debug('p_segment1=' || p_segment1);
2204 	EAM_ActivityUtilities_PVT.Write_Debug('p_segment2=' || p_segment2);
2205 	EAM_ActivityUtilities_PVT.Write_Debug('p_segment3=' || p_segment3);
2206 	EAM_ActivityUtilities_PVT.Write_Debug('p_segment4=' || p_segment4);
2207 	EAM_ActivityUtilities_PVT.Write_Debug('p_segment5=' || p_segment5);
2208 	EAM_ActivityUtilities_PVT.Write_Debug('p_segment6=' || p_segment6);
2209 	EAM_ActivityUtilities_PVT.Write_Debug('p_segment7=' || p_segment7);
2210 	EAM_ActivityUtilities_PVT.Write_Debug('p_segment8=' || p_segment8);
2211 	EAM_ActivityUtilities_PVT.Write_Debug('p_segment9=' || p_segment9);
2212 	EAM_ActivityUtilities_PVT.Write_Debug('p_segment10=' || p_segment10);
2213 	EAM_ActivityUtilities_PVT.Write_Debug('p_segment11=' || p_segment11);
2214 	EAM_ActivityUtilities_PVT.Write_Debug('p_segment12=' || p_segment12);
2215 	EAM_ActivityUtilities_PVT.Write_Debug('p_segment13=' || p_segment13);
2216 	EAM_ActivityUtilities_PVT.Write_Debug('p_segment14=' || p_segment14);
2217 	EAM_ActivityUtilities_PVT.Write_Debug('p_segment15=' || p_segment15);
2218 	EAM_ActivityUtilities_PVT.Write_Debug('p_segment16=' || p_segment16);
2219 	EAM_ActivityUtilities_PVT.Write_Debug('p_segment17=' || p_segment17);
2220 	EAM_ActivityUtilities_PVT.Write_Debug('p_segment18=' || p_segment18);
2221 	EAM_ActivityUtilities_PVT.Write_Debug('p_segment19=' || p_segment19);
2222 	EAM_ActivityUtilities_PVT.Write_Debug('p_segment20=' || p_segment20);
2223 	EAM_ActivityUtilities_PVT.Write_Debug('p_description=' || p_description);
2224 
2225 	-- ============================================================
2226 	-- Create Asset Activity. Call INV_Item_GRP package.
2227 
2228 	l_asset_activity.organization_id := p_organization_id;
2229 	l_asset_activity.organization_code := p_organization_code;
2230 
2231 	-- Set up Item Number. Use segments if specified.
2232 	IF 	p_segment1 IS NOT NULL OR
2233 		p_segment2 IS NOT NULL OR
2234 		p_segment3 IS NOT NULL OR
2235 		p_segment4 IS NOT NULL OR
2236 		p_segment5 IS NOT NULL OR
2237 		p_segment6 IS NOT NULL OR
2238 		p_segment7 IS NOT NULL OR
2239 		p_segment8 IS NOT NULL OR
2240 		p_segment9 IS NOT NULL OR
2241 		p_segment10 IS NOT NULL OR
2242 		p_segment11 IS NOT NULL OR
2243 		p_segment12 IS NOT NULL OR
2244 		p_segment13 IS NOT NULL OR
2245 		p_segment14 IS NOT NULL OR
2246 		p_segment15 IS NOT NULL OR
2247 		p_segment16 IS NOT NULL OR
2248 		p_segment17 IS NOT NULL OR
2249 		p_segment18 IS NOT NULL OR
2250 		p_segment19 IS NOT NULL OR
2251 		p_segment20 IS NOT NULL
2252 	THEN
2253 		l_asset_activity.Segment1 := p_segment1;
2254 		l_asset_activity.Segment2 := p_segment2;
2255 		l_asset_activity.Segment3 := p_segment3;
2256 		l_asset_activity.Segment4 := p_segment4;
2257 		l_asset_activity.Segment5 := p_segment5;
2258 		l_asset_activity.Segment6 := p_segment6;
2259 		l_asset_activity.Segment7 := p_segment7;
2260 		l_asset_activity.Segment8 := p_segment8;
2261 		l_asset_activity.Segment9 := p_segment9;
2262 		l_asset_activity.Segment10 := p_segment10;
2263 		l_asset_activity.Segment11 := p_segment11;
2264 		l_asset_activity.Segment12 := p_segment12;
2265 		l_asset_activity.Segment13 := p_segment13;
2266 		l_asset_activity.Segment14 := p_segment14;
2267 		l_asset_activity.Segment15 := p_segment15;
2268 		l_asset_activity.Segment16 := p_segment16;
2269 		l_asset_activity.Segment17 := p_segment17;
2270 		l_asset_activity.Segment18 := p_segment18;
2271 		l_asset_activity.Segment19 := p_segment19;
2272 		l_asset_activity.Segment20 := p_segment20;
2273 	ELSE
2274 		l_asset_activity.Item_Number := p_asset_activity;
2275 	END IF;
2276 
2277 
2278 
2279 
2280 	l_asset_activity.description := p_description;
2281 
2282 	l_asset_activity.EAM_ACTIVITY_TYPE_CODE := p_activity_type_code;
2283 	l_asset_activity.EAM_ACTIVITY_CAUSE_CODE := p_activity_cause_code;
2284 	l_asset_activity.EAM_ACT_NOTIFICATION_FLAG := p_notification_req_flag;
2285 	l_asset_activity.EAM_ACT_SHUTDOWN_STATUS := p_shutdown_type_code;
2286 	l_asset_activity.EAM_ACTIVITY_SOURCE_CODE := p_activity_source_code;
2287 
2288 	Create_Item(
2289 		p_asset_activity => l_asset_activity,
2290 		p_template_id => p_template_id,
2291 		p_template_name => p_template_name,
2292 
2293 		x_curr_item_rec 		=> l_x_curr_item_rec,
2294 		x_curr_item_return_status 	=> l_x_curr_item_return_status,
2295 		x_curr_item_error_tbl 		=> l_x_curr_item_error_tbl,
2296 		x_master_item_rec 		=> l_x_master_item_rec,
2297 		x_master_item_return_status 	=> l_x_master_item_return_status,
2298 		x_master_item_error_tbl 	=> l_x_master_item_error_tbl
2299 	);
2300 	-- Assign outputs
2301 	x_curr_item_rec 		:= l_x_curr_item_rec;
2302 	x_curr_item_return_status 	:= l_x_curr_item_return_status;
2303 	x_curr_item_error_tbl 		:= l_x_curr_item_error_tbl;
2304 	x_master_item_rec 		:= l_x_master_item_rec;
2305 	x_master_item_return_status 	:= l_x_master_item_return_status;
2306 	x_master_item_error_tbl 	:= l_x_master_item_error_tbl;
2307 
2308 	IF l_x_master_item_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2309 		FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_CR_ACT_MASTER_FAILED');
2310 		EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
2311 		RAISE FND_API.G_EXC_ERROR;
2312 	END IF;
2313 
2314 	IF l_x_curr_item_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2315 		FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_CR_ACT_CURRENT_FAILED');
2316 		EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
2317 		RAISE FND_API.G_EXC_ERROR;
2318 	END IF;
2319 
2320 	-- =============================================================
2321 
2322 	-- End of API body.
2323 	-- Standard check of p_commit.
2324 	IF FND_API.To_Boolean( p_commit ) THEN
2325 		COMMIT WORK;
2326 	END IF;
2327 	-- Standard call to get message count and if count is 1, get message info.
2328 	FND_MSG_PUB.Count_And_Get
2329     	(  	p_count         	=>      x_msg_count     	,
2330         	p_data          	=>      x_msg_data
2331     	);
2332 
2333 
2334 	EAM_ActivityUtilities_PVT.Write_Debug('========== Exiting EAM_Activity_PUB.Create_Activity_With_Template ==========');
2335 
2336 	-- ======================================================================
2337 
2338 EXCEPTION
2339     WHEN FND_API.G_EXC_ERROR THEN
2340 		ROLLBACK TO Create_Act_With_Templ_PUB;
2341 		EAM_ActivityUtilities_PVT.Write_Debug(
2342 			'========== EAM_Activity_PUB.Create_Activity_With_Template: EXPECTED ERROR ==========');
2343 		x_return_status := FND_API.G_RET_STS_ERROR ;
2344 		FND_MSG_PUB.Count_And_Get
2345     		(  	p_count         	=>      x_msg_count     	,
2346         		p_data          	=>      x_msg_data
2347     		);
2348 	WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2349 		ROLLBACK TO Create_Act_With_Templ_PUB;
2350 		EAM_ActivityUtilities_PVT.Write_Debug(
2351 			'========== EAM_Activity_PUB.Create_Activity_With_Template: UNEXPECTED ERROR ==========');
2352 		x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2353 		FND_MSG_PUB.Count_And_Get
2354     		(  	p_count         	=>      x_msg_count     	,
2355         		p_data          	=>      x_msg_data
2356     		);
2357 	WHEN OTHERS THEN
2358 		ROLLBACK TO Create_Act_With_Templ_PUB;
2359 		EAM_ActivityUtilities_PVT.Write_Debug(
2360 			'========== EAM_Activity_PUB.Create_Activity_With_Template: OTHER ERROR ==========');
2361 		x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2362   		IF 	FND_MSG_PUB.Check_Msg_Level
2363 			(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2364 		THEN
2365         		FND_MSG_PUB.Add_Exc_Msg
2366     	    		(	G_PKG_NAME  	    ,
2367     	    			l_api_name
2368 	    		);
2369 		END IF;
2370 		FND_MSG_PUB.Count_And_Get
2371     		(  	p_count         	=>      x_msg_count     	,
2372         		p_data          	=>      x_msg_data
2373     		);
2374 END Create_Activity_With_Template;
2375 
2376 
2377 -- From Saurabh
2378 procedure create_bom_header(
2379 	p_target_item_rec		IN INV_Item_GRP.Item_Rec_Type,
2380 	--p_source_org_id			IN	NUMBER,
2381 	--p_source_activity_id		IN	NUMBER, -- inventory_item_id
2382 
2383 	--p_material_copy_option		IN NUMBER,
2384 
2385 	x_bom_header_rec		OUT NOCOPY	BOM_BO_PUB.BOM_Head_Rec_Type,
2386 	x_bom_revision_tbl		OUT NOCOPY	BOM_BO_PUB.BOM_Revision_Tbl_Type,
2387 	x_bom_component_tbl		OUT NOCOPY	BOM_BO_PUB.BOM_Comps_Tbl_Type,
2388 	x_bom_ref_designator_tbl	OUT NOCOPY	BOM_BO_PUB.BOM_Ref_Designator_Tbl_Type,
2389 	x_bom_sub_component_tbl		OUT NOCOPY	BOM_BO_PUB.BOM_Sub_Component_Tbl_Type,
2390 	x_bom_return_status		OUT NOCOPY	VARCHAR2,
2391 	x_bom_msg_count			OUT NOCOPY	NUMBER,
2392 	x_bom_msg_list			OUT NOCOPY	Error_Handler.Error_Tbl_Type
2393 
2394 )
2395 IS
2396 --l_current_date			CONSTANT DATE := sysdate;
2397 l_create_txn_type		CONSTANT VARCHAR(10) := 'CREATE';
2398 -- local variabels for calling BOM Business Object API
2399 l_bom_head_rec			BOM_BO_PUB.Bom_Head_Rec_Type;
2400 l_bom_component_tbl		BOM_BO_PUB.Bom_Comps_Tbl_Type;
2401 l_bom_comp_tbl_index		BINARY_INTEGER;
2402 
2403 l_x_bom_header_rec		BOM_BO_PUB.Bom_Head_Rec_Type;
2404 l_x_bom_revision_tbl		BOM_BO_PUB.Bom_Revision_Tbl_Type;
2405 l_x_bom_component_tbl		BOM_BO_PUB.Bom_Comps_Tbl_Type;
2406 l_x_bom_ref_designator_tbl	BOM_BO_PUB.Bom_Ref_Designator_Tbl_Type;
2407 l_x_bom_sub_component_tbl	BOM_BO_PUB.Bom_Sub_Component_Tbl_Type;
2408 l_x_bom_return_status		VARCHAR2(1);
2409 l_x_bom_msg_count		NUMBER;
2410 l_x_bom_msg_list		Error_Handler.Error_Tbl_Type;
2411 
2412 begin
2413 --        l_bom_head_rec := NULL;
2414 			l_bom_head_rec.Assembly_Item_Name := p_target_item_rec.Item_Number;
2415 			l_bom_head_rec.Transaction_Type := l_create_txn_type;
2416 			l_bom_head_rec.Organization_Code := p_target_item_rec.Organization_Code;
2417 			--l_bom_head_rec.Alternate_Bom_Code := l_bom_bom_row.alternate_bom_designator;
2418 			--l_bom_head_rec.Assembly_Type := l_bom_bom_row.assembly_type;
2419 
2420 -- fixthis??
2421 --			Common_Assembly_Name
2422 --			Common_Organization_Code
2423 
2424 			/*l_bom_head_rec.Attribute_Category := l_bom_bom_row.attribute_category;
2425 			l_bom_head_rec.Attribute1 := l_bom_bom_row.attribute1;
2426 			l_bom_head_rec.Attribute2 := l_bom_bom_row.attribute2;
2427 			l_bom_head_rec.Attribute3 := l_bom_bom_row.attribute3;
2428 			l_bom_head_rec.Attribute4 := l_bom_bom_row.attribute4;
2429 			l_bom_head_rec.Attribute5 := l_bom_bom_row.attribute5;
2430 			l_bom_head_rec.Attribute6 := l_bom_bom_row.attribute6;
2431 			l_bom_head_rec.Attribute7 := l_bom_bom_row.attribute7;
2432 			l_bom_head_rec.Attribute8 := l_bom_bom_row.attribute8;
2433 			l_bom_head_rec.Attribute9 := l_bom_bom_row.attribute9;
2434 			l_bom_head_rec.Attribute10 := l_bom_bom_row.attribute10;
2435 			l_bom_head_rec.Attribute11 := l_bom_bom_row.attribute11;
2436 			l_bom_head_rec.Attribute12 := l_bom_bom_row.attribute12;
2437 			l_bom_head_rec.Attribute13 := l_bom_bom_row.attribute13;
2438 			l_bom_head_rec.Attribute14 := l_bom_bom_row.attribute14;
2439 			l_bom_head_rec.Attribute15 := l_bom_bom_row.attribute15;
2440             */
2441 		--l_bom_head_rec.Alternate_Bom_Code := l_bom_bom_row.alternate_bom_designator;
2442 		--l_bom_head_rec.Assembly_Type := l_bom_bom_row.assembly_type;
2443 	-- log call to Process_BOM API
2444 	EAM_ActivityUtilities_PVT.Write_Debug('********** Calling BOM_BO_PUB.Process_BOM **********');
2445         BOM_BO_PUB.Process_BOM(
2446 					p_bom_header_rec 		=> l_bom_head_rec,
2447 					p_bom_component_tbl 		=> l_bom_component_tbl,
2448 					x_bom_header_rec 		=> l_x_bom_header_rec,
2449 					x_bom_revision_tbl 		=> l_x_bom_revision_tbl,
2450 					x_bom_component_tbl 		=> l_x_bom_component_tbl,
2451 					x_bom_ref_designator_tbl 	=> l_x_bom_ref_designator_tbl,
2452 					x_bom_sub_component_tbl		=> l_x_bom_sub_component_tbl,
2453 					x_return_status			=> l_x_bom_return_status,
2454 					x_msg_count			=> l_x_bom_msg_count
2455 				);
2456 	EAM_ActivityUtilities_PVT.Write_Debug('********** Returned from BOM_BO_PUB.Process_BOM **********');
2457 
2458         x_bom_header_rec := l_x_bom_header_rec;
2459 				x_bom_revision_tbl := l_x_bom_revision_tbl;
2460 				x_bom_component_tbl := l_x_bom_component_tbl;
2461 				x_bom_ref_designator_tbl := l_x_bom_ref_designator_tbl;
2462 				x_bom_sub_component_tbl	:= l_x_bom_sub_component_tbl;
2463 				x_bom_return_status := l_x_bom_return_status;
2464 				x_bom_msg_count := l_x_bom_msg_count;
2465 				Error_Handler.Get_Message_List(l_x_bom_msg_list);
2466 				x_bom_msg_list := l_x_bom_msg_list;
2467 end create_bom_header;
2468 
2469 procedure create_bom_header_form(
2470     --p_target_item_rec		IN INV_Item_GRP.Item_Rec_Type,
2471     p_inventory_item_name varchar2,
2472     p_organization_code varchar2,
2473     x_return_status     OUT NOCOPY	VARCHAR2
2474 )is
2475     l_target_item_rec INV_Item_GRP.Item_Rec_Type;
2476     x_bom_header_rec			BOM_BO_PUB.BOM_Head_Rec_Type;
2477 	x_bom_revision_tbl			BOM_BO_PUB.BOM_Revision_Tbl_Type;
2478 	x_bom_component_tbl			BOM_BO_PUB.BOM_Comps_Tbl_Type;
2479 	x_bom_ref_designator_tbl		BOM_BO_PUB.BOM_Ref_Designator_Tbl_Type;
2480 	x_bom_sub_component_tbl			BOM_BO_PUB.BOM_Sub_Component_Tbl_Type;
2481 	x_bom_return_status			VARCHAR2(1);
2482 	x_bom_msg_count				NUMBER;
2483 	x_bom_msg_list				Error_Handler.Error_Tbl_Type;
2484 
2485 begin
2486        l_target_item_rec.item_number := p_inventory_item_name;
2487        l_target_item_rec.organization_code := p_organization_code;
2488 
2489        EAM_ACTIVITY_PUB.create_bom_header(
2490             p_target_item_rec		=> l_target_item_rec,
2491 	        --p_source_org_id			IN	NUMBER,
2492 	        --p_source_activity_id		IN	NUMBER, -- inventory_item_id
2493 
2494 	        --p_material_copy_option		IN NUMBER,
2495 
2496 	       x_bom_header_rec		=> x_bom_header_rec,
2497 	       x_bom_revision_tbl		=> x_bom_revision_tbl,
2498 	       x_bom_component_tbl		=> x_bom_component_tbl,
2499 	       x_bom_ref_designator_tbl	=> x_bom_ref_designator_tbl,
2500 	       x_bom_sub_component_tbl	=> x_bom_sub_component_tbl	,
2501 	       x_bom_return_status	=> x_bom_return_status	,
2502 	       x_bom_msg_count	=> x_bom_msg_count		,
2503 	       x_bom_msg_list	=> x_bom_msg_list
2504         );
2505 
2506         x_return_status := x_bom_return_status;
2507 end create_bom_header_form;
2508 
2509 
2510 PROCEDURE Create_Activity_With_Template(
2511  	--p_api_version           	IN	NUMBER				,
2512   	--p_init_msg_list			IN	VARCHAR2 := FND_API.G_FALSE	,
2513 	--p_commit	    		IN  	VARCHAR2 := FND_API.G_FALSE	,
2514 	--p_validation_level		IN  	NUMBER	:=
2515 	--					FND_API.G_VALID_LEVEL_FULL	,
2516 	x_return_status			OUT NOCOPY	VARCHAR2		  	,
2517 	--x_msg_count			OUT	NUMBER				,
2518 	--x_msg_data			OUT	VARCHAR2			,
2519 
2520 	p_organization_id		IN	NUMBER 		:= NULL,
2521 	p_organization_code		IN	NUMBER		:= NULL,
2522 	p_asset_activity		IN	VARCHAR2,
2523 	p_segment1			IN	VARCHAR2,
2524 	p_segment2			IN	VARCHAR2,
2525 	p_segment3			IN	VARCHAR2,
2526 	p_segment4			IN	VARCHAR2,
2527 	p_segment5			IN	VARCHAR2,
2528 	p_segment6			IN	VARCHAR2,
2529 	p_segment7			IN	VARCHAR2,
2530 	p_segment8			IN	VARCHAR2,
2531 	p_segment9			IN	VARCHAR2,
2532 	p_segment10			IN	VARCHAR2,
2533 	p_segment11			IN	VARCHAR2,
2534 	p_segment12			IN	VARCHAR2,
2535 	p_segment13			IN	VARCHAR2,
2536 	p_segment14			IN	VARCHAR2,
2537 	p_segment15			IN	VARCHAR2,
2538 	p_segment16			IN	VARCHAR2,
2539 	p_segment17			IN	VARCHAR2,
2540 	p_segment18			IN	VARCHAR2,
2541 	p_segment19			IN	VARCHAR2,
2542 	p_segment20			IN	VARCHAR2,
2543 	p_description			IN	VARCHAR2,
2544 	p_template_id			IN	NUMBER 		:= NULL,
2545 	p_template_name			IN	VARCHAR2 	:= NULL,
2546 	p_activity_type_code		IN	VARCHAR2	:= NULL,
2547 	p_activity_cause_code 		IN	VARCHAR2	:= NULL,
2548 	p_shutdown_type_code		IN	VARCHAR2	:= NULL,
2549 	p_notification_req_flag		IN	VARCHAR2	:= NULL,
2550 	p_activity_source_code		IN	VARCHAR2	:= NULL
2551 
2552 	--x_curr_item_rec			OUT	INV_Item_GRP.Item_Rec_Type,
2553 	--x_curr_item_return_status	OUT	VARCHAR2,
2554 	--x_curr_item_error_tbl		OUT	INV_Item_GRP.Error_Tbl_Type,
2555 	--x_master_item_rec		OUT	INV_Item_GRP.Item_Rec_Type,
2556 	--x_master_item_return_status	OUT	VARCHAR2,
2557 	--x_master_item_error_tbl		OUT	INV_Item_GRP.Error_Tbl_Type
2558 )is
2559 l_asset_activity		INV_Item_GRP.Item_rec_type;
2560 
2561 l_api_name			CONSTANT VARCHAR2(30)	:= 'Create_Activity_With_Template';
2562 l_api_version           	CONSTANT NUMBER 	:= 1.0;
2563 l_init_msg_list         CONSTANT VARCHAR2(1) :=  FND_API.G_FALSE	;
2564 l_commit CONSTANT VARCHAR2(1) :=  FND_API.G_TRUE	;
2565 l_validation_level  NUMBER := FND_API.G_VALID_LEVEL_FULL;
2566 
2567 l_x_curr_item_rec		INV_Item_GRP.Item_rec_type;
2568 l_x_curr_item_return_status	VARCHAR2(1);
2569 l_x_curr_item_error_tbl		INV_Item_GRP.Error_tbl_type;
2570 
2571 l_x_master_item_rec	INV_Item_GRP.Item_rec_type;
2572 l_x_master_item_return_status	VARCHAR2(1);
2573 l_x_master_item_error_tbl	INV_Item_GRP.Error_tbl_type;
2574 l_msg_count number;
2575 l_msg_data varchar2(20000);
2576 begin
2577 
2578 
2579 	-- ============================================================
2580    	EAM_ActivityUtilities_PVT.Open_Debug_Session;
2581 
2582     create_activity_with_template(
2583         p_api_version => l_api_version,
2584   	    p_init_msg_list =>	l_init_msg_list,
2585 	    p_commit => l_commit,
2586 	    p_validation_level => l_validation_level,
2587             x_return_status => x_return_status,
2588             x_msg_count	=> l_msg_count,
2589 	    x_msg_data	=> l_msg_data,
2590             p_organization_id => p_organization_id,
2591 	    p_organization_code => p_organization_code,
2592 	    p_asset_activity => p_asset_activity,
2593             p_segment1 => p_segment1,
2594             p_segment2 => p_segment2,
2595             p_segment3 => p_segment3,
2596             p_segment4 => p_segment4,
2597             p_segment5 => p_segment5,
2598             p_segment6 => p_segment6,
2599             p_segment7 => p_segment7,
2600             p_segment8 => p_segment8,
2601             p_segment9 => p_segment9,
2602             p_segment10 => p_segment10,
2603             p_segment11 => p_segment11,
2604             p_segment12 => p_segment12,
2605             p_segment13 => p_segment13,
2606             p_segment14 => p_segment14,
2607             p_segment15 => p_segment15,
2608             p_segment16 => p_segment16,
2609             p_segment17 => p_segment17,
2610             p_segment18 => p_segment18,
2611             p_segment19 => p_segment19,
2612             p_segment20 => p_segment20,
2613 	    p_description => p_description,
2614 	    p_template_id => p_template_id,
2615 	    p_template_name => p_template_name,
2616 	    p_activity_type_code => p_activity_type_code,
2617 	    p_activity_cause_code => p_activity_cause_code,
2618 	    p_shutdown_type_code => p_shutdown_type_code,
2619 	    p_notification_req_flag => p_notification_req_flag,
2620 	    p_activity_source_code => p_activity_source_code,
2621             x_curr_item_rec => l_x_curr_item_rec,
2622 	    x_curr_item_return_status => l_x_curr_item_return_status,
2623 	    x_curr_item_error_tbl => l_x_curr_item_error_tbl,
2624 	    x_master_item_rec => l_x_master_item_rec,
2625 	    x_master_item_return_status	=> l_x_master_item_return_status,
2626 	    x_master_item_error_tbl => l_x_master_item_error_tbl
2627     );
2628 
2629     if (l_x_master_item_return_status = fnd_api.g_ret_sts_success AND l_x_curr_item_return_status = fnd_api.g_ret_sts_success) then
2630             commit;
2631     end if;
2632 
2633     /*if x_curr_item_return_status = FND_API.G_RET_STS_SUCCESS AND x_master_item_return_status = FND_API.G_RET_STS_SUCCESS then
2634             commit;
2635             x_success := TRUE;
2636     else
2637             x_success := FALSE;
2638     end if;*/
2639 
2640 	-- ============================================================
2641 	EAM_ActivityUtilities_PVT.Close_Debug_Session;
2642 
2643 end create_activity_with_template;
2644 
2645 PROCEDURE Create_Routing_Header(
2646 	p_target_item_rec			IN INV_Item_GRP.Item_Rec_Type,
2647 
2648 	x_rtg_header_rec		OUT NOCOPY	BOM_Rtg_Pub.Rtg_Header_Rec_Type,
2649 	x_rtg_revision_tbl		OUT NOCOPY	BOM_Rtg_Pub.Rtg_Revision_Tbl_Type,
2650 	x_operation_tbl			OUT NOCOPY	BOM_Rtg_Pub.Operation_Tbl_Type,
2651 	x_op_resource_tbl		OUT NOCOPY	BOM_Rtg_Pub.Op_Resource_Tbl_Type,
2652 	x_sub_resource_tbl		OUT NOCOPY	BOM_Rtg_Pub.Sub_Resource_Tbl_Type,
2653 	x_op_network_tbl		OUT NOCOPY	BOM_Rtg_Pub.Op_Network_Tbl_Type,
2654 	x_rtg_return_status		OUT NOCOPY	VARCHAR2,
2655 	x_rtg_msg_count			OUT NOCOPY	NUMBER,
2656 	x_rtg_msg_list			OUT NOCOPY	Error_Handler.Error_Tbl_Type
2657 )
2658 
2659 IS
2660 --l_current_date			CONSTANT DATE := sysdate;
2661 l_create_txn_type		CONSTANT VARCHAR(10) := 'CREATE';
2662 
2663 -- local variables for call the Routing Business Object API
2664 l_rtg_header_rec		BOM_RTG_PUB.Rtg_Header_Rec_Type;
2665 l_operation_tbl			BOM_RTG_PUB.Operation_Tbl_Type;
2666 l_op_resource_tbl		BOM_RTG_PUB.Op_Resource_Tbl_Type;
2667 l_op_network_tbl		BOM_RTG_PUB.Op_Network_Tbl_Type;
2668 
2669 
2670 l_x_rtg_header_rec		BOM_RTG_PUB.Rtg_Header_Rec_Type;
2671 l_x_rtg_revision_tbl		BOM_RTG_PUB.Rtg_Revision_Tbl_Type;
2672 l_x_operation_tbl		BOM_RTG_PUB.Operation_Tbl_Type;
2673 l_x_op_resource_tbl		BOM_RTG_PUB.Op_Resource_Tbl_Type;
2674 l_x_sub_resource_tbl		BOM_RTG_PUB.Sub_Resource_Tbl_Type;
2675 l_x_op_network_tbl		BOM_RTG_PUB.Op_Network_Tbl_Type;
2676 l_x_rtg_return_status		VARCHAR2(1);
2677 l_x_rtg_msg_count		NUMBER;
2678 l_x_rtg_msg_list		Error_Handler.Error_Tbl_Type;
2679 
2680 
2681 
2682 BEGIN
2683 
2684 	-- First initialize record fields to NULL
2685 --	l_rtg_header_rec := NULL;
2686 	-- populate fields
2687 	l_rtg_header_rec.Assembly_Item_Name := p_target_item_rec.Item_Number;
2688 	l_rtg_header_rec.Organization_Code := p_target_item_rec.Organization_Code;
2689 	l_rtg_header_rec.Transaction_Type := l_create_txn_type;
2690 
2691 	Error_Handler.initialize;
2692 	-- log call to Process_Rtg API
2693 	EAM_ActivityUtilities_PVT.Write_Debug('********** Calling BOM_RTG_PUB.Process_Rtg **********');
2694 	BOM_RTG_PUB.Process_Rtg(
2695 		p_rtg_header_rec 	=> l_rtg_header_rec
2696 		, p_operation_tbl	=> l_operation_tbl
2697 		, p_op_resource_tbl	=> l_op_resource_tbl
2698 		, p_op_network_tbl	=> l_op_network_tbl
2699 		, x_rtg_header_rec	=> l_x_rtg_header_rec
2700 		, x_rtg_revision_tbl	=> l_x_rtg_revision_tbl
2701 		, x_operation_tbl	=> l_x_operation_tbl
2702 		, x_op_resource_tbl	=> l_x_op_resource_tbl
2703 		, x_sub_resource_tbl	=> l_x_sub_resource_tbl
2704 		, x_op_network_tbl	=> l_x_op_network_tbl
2705 		, x_return_status	=> l_x_rtg_return_status
2706 		, x_msg_count		=> l_x_rtg_msg_count
2707 	);
2708 	EAM_ActivityUtilities_PVT.Write_Debug('********** Returned from BOM_RTG_PUB.Process_Rtg **********');
2709 
2710 	-- Assign outputs.
2711 	x_rtg_header_rec := l_x_rtg_header_rec;
2712 	x_rtg_revision_tbl := l_x_rtg_revision_tbl;
2713 	x_operation_tbl	:= l_x_operation_tbl;
2714 	x_op_resource_tbl := l_x_op_resource_tbl;
2715 	x_sub_resource_tbl := l_x_sub_resource_tbl;
2716 	x_op_network_tbl := l_x_op_network_tbl;
2717 	x_rtg_return_status := l_x_rtg_return_status;
2718 	x_rtg_msg_count	:= l_x_rtg_msg_count;
2719 	Error_Handler.Get_Message_List(l_x_rtg_msg_list);
2720 	x_rtg_msg_list	:= l_x_rtg_msg_list;
2721 
2722 
2723 END Create_Routing_Header;
2724 
2725 procedure create_routing_header_form(
2726     --p_target_item_rec		IN INV_Item_GRP.Item_Rec_Type,
2727     p_inventory_item_name varchar2,
2728     p_organization_code varchar2,
2729     x_return_status     OUT NOCOPY	VARCHAR2
2730 )is
2731     l_rtg_header_rec		BOM_RTG_PUB.Rtg_Header_Rec_Type;
2732     l_operation_tbl			BOM_RTG_PUB.Operation_Tbl_Type;
2733     l_operation_tbl_index		BINARY_INTEGER;
2734     l_op_resource_tbl		BOM_RTG_PUB.Op_Resource_Tbl_Type;
2735     l_op_resource_tbl_index		BINARY_INTEGER;
2736     l_op_network_tbl		BOM_RTG_PUB.Op_Network_Tbl_Type;
2737     l_op_network_tbl_index		BINARY_INTEGER;
2738 
2739     l_x_rtg_header_rec		BOM_RTG_PUB.Rtg_Header_Rec_Type;
2740     l_x_rtg_revision_tbl		BOM_RTG_PUB.Rtg_Revision_Tbl_Type;
2741     l_x_operation_tbl		BOM_RTG_PUB.Operation_Tbl_Type;
2742     l_x_op_resource_tbl		BOM_RTG_PUB.Op_Resource_Tbl_Type;
2743     l_x_sub_resource_tbl		BOM_RTG_PUB.Sub_Resource_Tbl_Type;
2744     l_x_op_network_tbl		BOM_RTG_PUB.Op_Network_Tbl_Type;
2745     l_x_rtg_return_status		VARCHAR2(1);
2746     l_x_rtg_msg_count		NUMBER;
2747     l_x_rtg_msg_list		Error_Handler.Error_Tbl_Type;
2748 
2749     l_target_item_rec INV_Item_GRP.Item_Rec_Type;
2750 
2751 begin
2752        l_target_item_rec.item_number := p_inventory_item_name;
2753        l_target_item_rec.organization_code := p_organization_code;
2754 
2755        EAM_ACTIVITY_PUB.create_routing_header(
2756             p_target_item_rec		=> l_target_item_rec,
2757 
2758 
2759 	       x_rtg_header_rec		=> l_x_rtg_header_rec,
2760 	       x_rtg_revision_tbl	=> l_x_rtg_revision_tbl,
2761 	       x_operation_tbl		=> l_x_operation_tbl,
2762 	       x_op_resource_tbl	=> l_x_op_resource_tbl,
2763 	       x_sub_resource_tbl	=> l_x_sub_resource_tbl,
2764 	       x_op_network_tbl		=> l_x_op_network_tbl,
2765 	       x_rtg_return_status	=> l_x_rtg_return_status,
2766 	       x_rtg_msg_count	=> l_x_rtg_msg_count,
2767 	       x_rtg_msg_list			=>	l_x_rtg_msg_list
2768         );
2769 
2770         x_return_status := l_x_rtg_return_status;
2771 
2772         --commit;
2773 end create_routing_header_form;
2774 
2775 
2776 -- From Saurabh
2777 -- package body
2778 -- wrapper API used to call Copy_Activity procedure from form
2779 procedure Copy_Activity(
2780     p_api_version           	IN	NUMBER				,
2781   	p_init_msg_list			IN	VARCHAR2 := FND_API.G_FALSE	,
2782 	p_commit	    		IN  	VARCHAR2 := FND_API.G_FALSE	,
2783 	p_validation_level		IN  	NUMBER	:=
2784 						FND_API.G_VALID_LEVEL_FULL	,
2785 	x_return_status			OUT NOCOPY	VARCHAR2		  	,
2786 	x_msg_count			OUT NOCOPY	NUMBER				,
2787 	x_msg_data			OUT NOCOPY	VARCHAR2			,
2788 
2789     	p_activity_item_name in varchar2,
2790 	p_segment1			IN	VARCHAR2,
2791 	p_segment2			IN	VARCHAR2,
2792 	p_segment3			IN	VARCHAR2,
2793 	p_segment4			IN	VARCHAR2,
2794 	p_segment5			IN	VARCHAR2,
2795 	p_segment6			IN	VARCHAR2,
2796 	p_segment7			IN	VARCHAR2,
2797 	p_segment8			IN	VARCHAR2,
2798 	p_segment9			IN	VARCHAR2,
2799 	p_segment10			IN	VARCHAR2,
2800 	p_segment11			IN	VARCHAR2,
2801 	p_segment12			IN	VARCHAR2,
2802 	p_segment13			IN	VARCHAR2,
2803 	p_segment14			IN	VARCHAR2,
2804 	p_segment15			IN	VARCHAR2,
2805 	p_segment16			IN	VARCHAR2,
2806 	p_segment17			IN	VARCHAR2,
2807 	p_segment18			IN	VARCHAR2,
2808 	p_segment19			IN	VARCHAR2,
2809 	p_segment20			IN	VARCHAR2,
2810 	p_activity_org_id in number,
2811 	p_activity_description in varchar2,
2812 
2813     	p_template_id			IN	NUMBER 		:= NULL,
2814         p_template_name			IN	VARCHAR2 	:= NULL,
2815         p_activity_type_code		IN	VARCHAR2	:= NULL,
2816 	p_activity_cause_code 		IN	VARCHAR2	:= NULL,
2817 	p_shutdown_type_code		IN	VARCHAR2	:= NULL,
2818 	p_notification_req_flag		IN	VARCHAR2	:= NULL,
2819 	p_activity_source_code		IN	VARCHAR2	:= NULL,
2820 
2821 	-- source Activity
2822 	p_source_org_id			IN	NUMBER,
2823 	p_source_activity_id		IN	NUMBER, -- inventory_item_id
2824     	p_bom_copy_option		IN	NUMBER := 2, -- 1 (NONE) or 2 (ALL)
2825 	p_routing_copy_option		IN	NUMBER := 2, -- 1 (NONE) or 2 (ALL)
2826 	p_association_copy_option	IN	NUMBER := 2 -- 1 (NONE) or 2 (ALL)
2827 
2828 )
2829 is
2830 	l_asset_activity		INV_Item_GRP.Item_Rec_Type;
2831 	l_x_curr_item_rec		INV_Item_GRP.Item_Rec_Type;
2832 	l_x_curr_item_return_status	VARCHAR2(1);
2833 	l_x_curr_item_error_tbl		INV_Item_GRP.Error_Tbl_Type;
2834 	l_x_master_item_rec		INV_Item_GRP.Item_Rec_Type;
2835 	l_x_master_item_return_status	VARCHAR2(1);
2836 	l_x_master_item_error_tbl	INV_Item_GRP.Error_Tbl_Type;
2837 
2838 	l_x_assoc_return_status		VARCHAR2(1);
2839 	l_x_assoc_msg_count		NUMBER;
2840 	l_x_assoc_msg_data		VARCHAR2(20000);
2841 	l_x_act_num_association_tbl	EAM_Activity_PUB.Activity_Association_Tbl_Type;
2842 	l_x_activity_association_tbl	EAM_Activity_PUB.Activity_Association_Tbl_Type;
2843 begin
2844 
2845 	EAM_ActivityUtilities_PVT.Open_Debug_Session;
2846 
2847 	-- Set up Item Number. Use segments if specified.
2848 	IF 	p_segment1 IS NOT NULL OR
2849 		p_segment2 IS NOT NULL OR
2850 		p_segment3 IS NOT NULL OR
2851 		p_segment4 IS NOT NULL OR
2852 		p_segment5 IS NOT NULL OR
2853 		p_segment6 IS NOT NULL OR
2854 		p_segment7 IS NOT NULL OR
2855 		p_segment8 IS NOT NULL OR
2856 		p_segment9 IS NOT NULL OR
2857 		p_segment10 IS NOT NULL OR
2858 		p_segment11 IS NOT NULL OR
2859 		p_segment12 IS NOT NULL OR
2860 		p_segment13 IS NOT NULL OR
2861 		p_segment14 IS NOT NULL OR
2862 		p_segment15 IS NOT NULL OR
2863 		p_segment16 IS NOT NULL OR
2864 		p_segment17 IS NOT NULL OR
2865 		p_segment18 IS NOT NULL OR
2866 		p_segment19 IS NOT NULL OR
2867 		p_segment20 IS NOT NULL
2868 	THEN
2869 		l_asset_activity.Segment1 := p_segment1;
2870 		l_asset_activity.Segment2 := p_segment2;
2871 		l_asset_activity.Segment3 := p_segment3;
2872 		l_asset_activity.Segment4 := p_segment4;
2873 		l_asset_activity.Segment5 := p_segment5;
2874 		l_asset_activity.Segment6 := p_segment6;
2875 		l_asset_activity.Segment7 := p_segment7;
2876 		l_asset_activity.Segment8 := p_segment8;
2877 		l_asset_activity.Segment9 := p_segment9;
2878 		l_asset_activity.Segment10 := p_segment10;
2879 		l_asset_activity.Segment11 := p_segment11;
2880 		l_asset_activity.Segment12 := p_segment12;
2881 		l_asset_activity.Segment13 := p_segment13;
2882 		l_asset_activity.Segment14 := p_segment14;
2883 		l_asset_activity.Segment15 := p_segment15;
2884 		l_asset_activity.Segment16 := p_segment16;
2885 		l_asset_activity.Segment17 := p_segment17;
2886 		l_asset_activity.Segment18 := p_segment18;
2887 		l_asset_activity.Segment19 := p_segment19;
2888 		l_asset_activity.Segment20 := p_segment20;
2889 	ELSE
2890 		l_asset_activity.item_number := p_activity_item_name;
2891 	END IF;
2892 
2893 	l_asset_activity.organization_id := p_activity_org_id;
2894 	l_asset_activity.description := p_activity_description;
2895 
2896 	EAM_ACTIVITY_PUB.Copy_Activity(
2897 		p_api_version           => p_api_version,
2898 	  	p_init_msg_list		=> p_init_msg_list,
2899 		p_commit	    	=> p_commit,
2900 		p_validation_level	=> p_validation_level,
2901 		x_return_status		=> x_return_status,
2902 		x_msg_count		=> x_msg_count,
2903 		x_msg_data		=> x_msg_data,
2904 
2905 		-- target activity, need to set org, item name, description
2906 		p_asset_activity	=> l_asset_activity,
2907 
2908 
2909 		p_template_id		=> p_template_id,
2910 	        p_template_name		=> p_template_name,
2911 	        p_activity_type_code	=> p_activity_type_code,
2912 		p_activity_cause_code 	=> p_activity_cause_code,
2913 		p_shutdown_type_code	=> p_shutdown_type_code,
2914 		p_notification_req_flag	=> p_notification_req_flag,
2915 		p_activity_source_code	=> p_activity_source_code,
2916 
2917 		-- source Activity
2918 		p_source_org_id		=> p_source_org_id	,
2919 		p_source_activity_id	=> p_source_activity_id	, -- inventory_item_id
2920 		-- source BOM
2921 		p_source_alt_bom_designator => NULL,
2922 		p_source_bom_rev_date	=> sysdate,
2923 		-- source Routing
2924 		p_source_alt_rtg_designator => NULL,
2925 		p_source_rtg_rev_date	=> sysdate,
2926 
2927 		p_bom_copy_option	=> p_bom_copy_option	, -- 1 (NONE) or 2 (ALL)
2928 		p_routing_copy_option	=> p_routing_copy_option	, -- 1 (NONE) or 2 (ALL)
2929 		p_association_copy_option => p_association_copy_option	, -- 1 (NONE) or 2 (ALL)
2930 
2931 		x_curr_item_rec		=>l_x_curr_item_rec	,
2932 		x_curr_item_return_status => l_x_curr_item_return_status		,
2933 		x_curr_item_error_tbl	=> l_x_curr_item_error_tbl,
2934 		x_master_item_rec	=> l_x_master_item_rec		,
2935 		x_master_item_return_status => l_x_master_item_return_status	,
2936 		x_master_item_error_tbl	=> l_x_master_item_error_tbl	,
2937 
2938 		x_assoc_return_status	=> l_x_assoc_return_status		,
2939 		x_assoc_msg_count	=> l_x_assoc_msg_count		,
2940 		x_assoc_msg_data	=> l_x_assoc_msg_data		,
2941 		x_act_num_association_tbl  => l_x_act_num_association_tbl		,
2942 		x_activity_association_tbl => l_x_activity_association_tbl
2943 	);
2944 
2945 	EAM_ActivityUtilities_PVT.Close_Debug_Session;
2946 
2947 end Copy_Activity;
2948 
2949 
2950 /* Procedure to assign the activity to the current maintenance organization */
2951 
2952 PROCEDURE Activity_org_assign
2953 ( 	p_api_version              IN	NUMBER				,
2954 	x_return_status		   OUT NOCOPY	VARCHAR2		,
2955 	x_msg_count		   OUT NOCOPY	NUMBER			,
2956 	x_msg_data		   OUT NOCOPY	VARCHAR2		,
2957 	p_org_id		   IN	NUMBER,
2958 	p_activity_id	           IN	NUMBER -- inventory_item_id
2959 )IS
2960 
2961  l_api_name       CONSTANT VARCHAR2(30) := 'Activity_org_assign';
2962  l_api_version    CONSTANT NUMBER       := 1.0;
2963  l_full_name      CONSTANT VARCHAR2(60) := g_pkg_name || '.' || l_api_name;
2964 
2965 
2966 l_master_organization_id	NUMBER;
2967 l_item_rec			INV_Item_GRP.Item_rec_type;
2968 
2969 -- local variables for calling INV_Item_GRP package
2970 
2971 l_x_item_rec		      INV_Item_GRP.Item_rec_type;
2972 l_x_return_status	      VARCHAR2(1);
2973 l_x_error_tbl		      INV_Item_GRP.Error_tbl_type;
2974 l_x_master_item_rec           INV_Item_GRP.Item_rec_type;
2975 l_x_master_item_return_status VARCHAR2(1);
2976 l_x_master_item_error_tbl     INV_Item_GRP.Error_tbl_type;
2977 l_error_string		      VARCHAR2(2000);
2978 l_msg_string		      VARCHAR2(200);
2979 
2980 
2981 BEGIN
2982   SAVEPOINT EAM_Activity_PUB;
2983   -- Standard call to check for call compatibility.
2984 --EAM_ActivityUtilities_PVT.Open_Debug_Session;
2985   IF NOT fnd_api.compatible_api_call(
2986             l_api_version
2987            ,p_api_version
2988            ,l_api_name
2989            ,g_pkg_name) THEN
2990        RAISE fnd_api.g_exc_unexpected_error;
2991   END IF;
2992 /*
2993   -- Initialize message list if p_init_msg_list is set to TRUE.
2994   IF fnd_api.to_boolean(p_init_msg_list) THEN
2995      fnd_msg_pub.initialize;
2996   END IF;
2997 */
2998   -- Get master org id
2999   l_master_organization_id := EAM_ActivityUtilities_PVT.Get_Master_Org_Id(p_org_id);
3000   EAM_ActivityUtilities_PVT.Write_Debug('l_master_organization_id=' || l_master_organization_id);
3001 
3002   BEGIN
3003     -- check if the activity exists in Master organization
3004     SELECT segment1, segment2, segment3, segment4, segment5, segment6, segment7,
3005            segment8, segment9, segment10, segment11, segment12, segment13, segment14,
3006 	   segment15, segment16, segment17, segment18, segment19, segment20, description,
3007            eam_activity_type_code, eam_activity_cause_code, eam_activity_source_code,
3008            eam_act_notification_flag, eam_act_shutdown_status, eam_item_type
3009       INTO l_item_rec.segment1, l_item_rec.segment2, l_item_rec.segment3, l_item_rec.segment4,
3010            l_item_rec.segment5, l_item_rec.segment6, l_item_rec.segment7, l_item_rec.segment8,
3011 	   l_item_rec.segment9, l_item_rec.segment10, l_item_rec.segment11, l_item_rec.segment12,
3012 	   l_item_rec.segment13, l_item_rec.segment14, l_item_rec.segment15, l_item_rec.segment16,
3013 	   l_item_rec.segment17, l_item_rec.segment18, l_item_rec.segment19, l_item_rec.segment20,
3014 	   l_item_rec.description, l_item_rec.eam_activity_type_code,
3015 	   l_item_rec.eam_activity_cause_code, l_item_rec.eam_activity_source_code,
3016 	   l_item_rec.eam_act_notification_flag, l_item_rec.eam_act_shutdown_status,
3017 	   l_item_rec.eam_item_type
3018       FROM mtl_system_items_b
3019      WHERE organization_id  = l_master_organization_id
3020        AND inventory_item_id = p_activity_id;
3021 
3022     -- Validate org id and org code
3023     EAM_ActivityUtilities_PVT.Validate_Organization(
3024 		p_organization_id => p_org_id,
3025 		p_organization_code => l_item_rec.organization_code,
3026 		x_return_status => l_x_return_status,
3027 		x_organization_id => l_item_rec.organization_id,
3028 		x_organization_code => l_item_rec.organization_code
3029 	);
3030 
3031     IF l_x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3032 
3033 	RAISE FND_API.G_EXC_ERROR;
3034     END IF;
3035 
3036 	-- ============================================================
3037     EAM_ActivityUtilities_PVT.Write_Debug('-------- Beginning EAM_Activity_PUB.Activity_org_assign --------');
3038 
3039 
3040    IF l_item_rec.inventory_item_flag IS NULL OR
3041        l_item_rec.inventory_item_flag = fnd_api.g_MISS_CHAR THEN
3042 		l_item_rec.inventory_item_flag := 'Y';
3043     END IF;
3044 /*
3045   IF l_item_rec.expense_account IS NULL OR l_item_rec.expense_account = fnd_api.g_MISS_NUM THEN
3046 	-- In the Master Item form, Expense Account defaulted from Master Org. So should use Master Org.
3047 	l_item_rec.expense_account := EAM_ActivityUtilities_PVT.Get_Expense_Account_Id(l_master_organization_id);
3048     END IF;
3049     -- Check that expense_account is not null
3050     IF l_item_rec.expense_account IS NULL OR l_item_rec.expense_account = fnd_api.g_MISS_NUM THEN
3051 	FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_EXPENSE_ACCOUNT_NULL');
3052         --FND_MESSAGE.SET_ENCODED('Please define the Expense Account for the Organization.');
3053 	EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
3054 
3055 	RAISE FND_API.G_EXC_ERROR;
3056 
3057     END IF;
3058 
3059 */ -- commented for BUG# 5484686
3060     IF l_item_rec.bom_enabled_flag IS NULL OR
3061        l_item_rec.bom_enabled_flag = fnd_api.g_MISS_CHAR THEN
3062 		l_item_rec.bom_enabled_flag := 'Y';
3063     END IF;
3064 
3065     EAM_ActivityUtilities_PVT.Write_Debug('>>>>>>>>>>>>>>> INV_Item_GRP.Create_Item INPUT Parameters >>>>>>>>>>>>>>>');
3066     EAM_ActivityUtilities_PVT.Log_Inv_Item_Rec(l_item_rec);
3067 
3068 
3069     INV_Item_GRP.Create_Item
3070                  (
3071 			p_Item_rec => l_item_rec,
3072 			p_Template_Id => 19,
3073 			p_Template_Name => null,
3074 			x_Item_rec => l_x_item_rec,
3075 			x_return_status => l_x_return_status,
3076 			x_Error_tbl => l_x_error_tbl
3077                  );
3078     Get_Errors
3079 	(
3080 	    p_item_error_tbl=>l_x_error_tbl,
3081 	    x_error_msg_old=>l_error_string,
3082 	    x_error_msg_new=>l_error_string
3083 	);
3084 
3085     -- log outputs
3086     EAM_ActivityUtilities_PVT.Write_Debug('l_x_return_status=' || l_x_return_status);
3087     EAM_ActivityUtilities_PVT.Write_Debug('Results of INV_Item_GRP.Create_Item >>>>>');
3088     EAM_ActivityUtilities_PVT.Log_Item_Error_Tbl(l_x_error_tbl);
3089     EAM_ActivityUtilities_PVT.Write_Debug('End of Results of INV_Item_GRP.Create_Item <<<<<');
3090     EAM_ActivityUtilities_PVT.Write_Debug('<<<<<<<<<<<<<<< INV_Item_GRP.Create_Item OUTPUT Parameters <<<<<<<<<<<<<<<');
3091     EAM_ActivityUtilities_PVT.Log_Inv_Item_Rec(l_x_item_rec);
3092 
3093   EXCEPTION
3094 	    WHEN NO_DATA_FOUND THEN
3095 		      -- There is no record in master org... so create in both ...
3096 		      SELECT segment1, segment2, segment3, segment4, segment5, segment6, segment7,
3097 			     segment8, segment9, segment10, segment11, segment12, segment13, segment14,
3098 			     segment15, segment16, segment17, segment18, segment19, segment20, description,
3099 			     eam_activity_type_code, eam_activity_cause_code, eam_activity_source_code,
3100 			     eam_act_notification_flag, eam_act_shutdown_status, eam_item_type
3101 			INTO l_item_rec.segment1, l_item_rec.segment2, l_item_rec.segment3, l_item_rec.segment4,
3102 			     l_item_rec.segment5, l_item_rec.segment6, l_item_rec.segment7, l_item_rec.segment8,
3103 			     l_item_rec.segment9, l_item_rec.segment10, l_item_rec.segment11, l_item_rec.segment12,
3104 			     l_item_rec.segment13, l_item_rec.segment14, l_item_rec.segment15, l_item_rec.segment16,
3105 			     l_item_rec.segment17, l_item_rec.segment18, l_item_rec.segment19, l_item_rec.segment20,
3106 			     l_item_rec.description, l_item_rec.eam_activity_type_code,
3107 			     l_item_rec.eam_activity_cause_code, l_item_rec.eam_activity_source_code,
3108 			     l_item_rec.eam_act_notification_flag, l_item_rec.eam_act_shutdown_status,
3109 			     l_item_rec.eam_item_type
3110 			FROM mtl_system_items_b
3111 		       WHERE inventory_item_id = p_activity_id
3112 			 AND ROWNUM = 1;
3113 
3114 		      l_item_rec.organization_id := p_org_id;
3115 		      EAM_ActivityUtilities_PVT.Write_Debug('Creating CURRENT Item...');
3116 		      EAM_ActivityUtilities_PVT.Write_Debug('>>>>>>>>>>>>>>> INV_Item_GRP.Create_Item INPUT Parameters >>>>>>>>>>>>>>>');
3117 		      EAM_ActivityUtilities_PVT.Log_Inv_Item_Rec(l_item_rec);
3118 
3119 		      Create_Item(
3120 				p_asset_activity => l_item_rec,
3121 				p_template_id => 19,
3122 				p_template_name => null,
3123 				x_curr_item_rec 		=> l_x_item_rec,
3124 				x_curr_item_return_status 	=> l_x_return_status,
3125 				x_curr_item_error_tbl 		=> l_x_error_tbl,
3126 				x_master_item_rec 		=> l_x_master_item_rec,
3127 				x_master_item_return_status 	=> l_x_master_item_return_status,
3128 				x_master_item_error_tbl 	=> l_x_master_item_error_tbl
3129 			);
3130 Get_Errors
3131 	(
3132 	    p_item_error_tbl=>l_x_master_item_error_tbl,
3133 	    x_error_msg_old=>l_error_string,
3134 	    x_error_msg_new=>l_error_string
3135 	);
3136 
3137   END;
3138 
3139   -- Assign outputs
3140   x_return_status := l_x_return_status;
3141 
3142   IF nvl(l_x_master_item_return_status, FND_API.G_RET_STS_SUCCESS)  <> FND_API.G_RET_STS_SUCCESS THEN
3143 	FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_CR_ACT_MASTER_FAILED');
3144 	l_msg_string:=FND_MESSAGE.GET;
3145 	--EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
3146 	RAISE FND_API.G_EXC_ERROR;
3147 
3148   END IF;
3149 
3150 
3151   IF l_x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3152 	FND_MESSAGE.SET_NAME('EAM', 'EAM_ABO_CR_ACT_CURRENT_FAILED');
3153 	l_msg_string:=FND_MESSAGE.GET;
3154 	--EAM_ActivityUtilities_PVT.Add_Message(FND_MSG_PUB.G_MSG_LVL_ERROR);
3155 	-- commented for BUG# 5484686
3156 	RAISE FND_API.G_EXC_ERROR;
3157   END IF;
3158 
3159 
3160   -- Standard call to get message count and if count is 1, get message info.
3161   --fnd_msg_pub.count_and_get(p_count => x_msg_count
3162   --                            ,p_data => x_msg_data);
3163   -- commented for BUG# 5484686
3164 
3165   EAM_ActivityUtilities_PVT.Write_Debug('-------- Finished EAM_Activity_PUB.Activity_org_assign --------');
3166 
3167   EXCEPTION
3168     WHEN fnd_api.g_exc_error THEN
3169          ROLLBACK TO EAM_Activity_PUB;
3170          x_return_status := fnd_api.g_ret_sts_error;
3171 
3172         -- fnd_msg_pub.count_and_get(p_count => x_msg_count
3173         --                          ,p_data => x_msg_data);
3174 	-- commented for BUG# 5484686
3175     WHEN fnd_api.g_exc_unexpected_error THEN
3176          ROLLBACK TO EAM_Activity_PUB;
3177          x_return_status := fnd_api.g_ret_sts_unexp_error;
3178 
3179          --fnd_msg_pub.count_and_get(p_count => x_msg_count
3180           --                        ,p_data => x_msg_data);
3181 	  -- commented for BUG# 5484686
3182     WHEN OTHERS THEN
3183          ROLLBACK TO EAM_Activity_PUB;
3184          x_return_status := fnd_api.g_ret_sts_unexp_error;
3185         /* IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
3186             fnd_msg_pub.add_exc_msg(g_pkg_name, l_api_name);
3187          END IF;*/
3188 	 -- fnd_msg_pub.count_and_get(p_count => x_msg_count
3189          --                         ,p_data => x_msg_data);
3190 	 -- commented for BUG# 5484686
3191 
3192 	 x_msg_data:=l_msg_string||l_error_string;
3193 
3194 END Activity_org_assign;
3195 
3196 END EAM_Activity_PUB;