DBA Data[Home] [Help]

PACKAGE BODY: APPS.EAM_PROCESS_WO_PUB

Source


1 PACKAGE BODY EAM_PROCESS_WO_PUB AS
2 /* $Header: EAMPWOPB.pls 120.40.12020000.4 2013/05/30 14:17:38 vboddapa ship $ */
3 /***************************************************************************
4 --
5 --  Copyright (c) 2002 Oracle Corporation, Redwood Shores, CA, USA
6 --  All rights reserved.
7 --
8 --  FILENAME
9 --
10 --      EAMPWOPB.pls
11 --
12 --  DESCRIPTION
13 --
14 --      Body of package EAM_PROCESS_WO_PUB
15 --
16 --  NOTES
17 --
18 --  HISTORY
19 --
20 --  30-JUN-2002    Kenichi Nagumo     Initial Creation
21 ***************************************************************************/
22 g_pkg_name    CONSTANT VARCHAR2(30):= 'EAM_PROCESS_WO_PUB';
23 
24          PROCEDURE DELETE_RELATIONSHIP
25          ( p_api_version                   IN NUMBER
26          , p_init_msg_list                 IN VARCHAR2 := FND_API.G_TRUE
27          , p_commit                        IN VARCHAR2 := FND_API.G_FALSE
28          , p_validation_level              IN NUMBER   := FND_API.G_VALID_LEVEL_FULL
29 
30          , p_parent_object_id              IN NUMBER
31          , p_parent_object_type_id         IN NUMBER
32          , p_child_object_id               IN NUMBER
33          , p_child_object_type_id          IN NUMBER
34          , p_new_parent_object_id          IN NUMBER
35          , p_new_parent_object_type_id     IN NUMBER
36 
37          , x_return_status                 OUT NOCOPY  VARCHAR2
38          , x_msg_count                     OUT NOCOPY  NUMBER
39          , x_msg_data                      OUT NOCOPY  VARCHAR2
40          ) IS
41          BEGIN
42            null;
43          END DELETE_RELATIONSHIP;
44 
45 	PROCEDURE PROCESS_MASTER_CHILD_WO
46         (  p_bo_identifier           IN  VARCHAR2 := 'EAM'
47          , p_api_version_number      IN  NUMBER := 1.0
48          , p_init_msg_list           IN  BOOLEAN := FALSE
49          , p_eam_wo_relations_tbl    IN  EAM_PROCESS_WO_PUB.eam_wo_relations_tbl_type
50          , p_eam_wo_tbl              IN  EAM_PROCESS_WO_PUB.eam_wo_tbl_type
51          , p_eam_op_tbl              IN  EAM_PROCESS_WO_PUB.eam_op_tbl_type
52          , p_eam_op_network_tbl      IN  EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
53          , p_eam_res_tbl             IN  EAM_PROCESS_WO_PUB.eam_res_tbl_type
54          , p_eam_res_inst_tbl        IN  EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
55          , p_eam_sub_res_tbl         IN  EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
56          , p_eam_mat_req_tbl         IN  EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
57          , p_eam_direct_items_tbl    IN  EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
58          , p_eam_res_usage_tbl       IN  EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
59 	 , p_eam_wo_comp_tbl         IN  EAM_PROCESS_WO_PUB.eam_wo_comp_tbl_type
60          , p_eam_wo_quality_tbl      IN  EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type
61          , p_eam_meter_reading_tbl   IN  EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type
62  	 , p_eam_counter_prop_tbl    IN  EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type
63          , p_eam_wo_comp_rebuild_tbl IN  EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type
64          , p_eam_wo_comp_mr_read_tbl IN  EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type
65          , p_eam_op_comp_tbl         IN  EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type
66 	 , p_eam_request_tbl         IN  EAM_PROCESS_WO_PUB.eam_request_tbl_type
67          , x_eam_wo_tbl              OUT NOCOPY EAM_PROCESS_WO_PUB.eam_wo_tbl_type
68          , x_eam_wo_relations_tbl    OUT NOCOPY EAM_PROCESS_WO_PUB.eam_wo_relations_tbl_type
69          , x_eam_op_tbl              OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_tbl_type
70          , x_eam_op_network_tbl      OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
71          , x_eam_res_tbl             OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_tbl_type
72          , x_eam_res_inst_tbl        OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
73          , x_eam_sub_res_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
74          , x_eam_mat_req_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
75          , x_eam_direct_items_tbl    OUT NOCOPY EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
76          , x_eam_res_usage_tbl       OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
77          , x_eam_wo_comp_tbl         OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_comp_tbl_type
78          , x_eam_wo_quality_tbl      OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type
79          , x_eam_meter_reading_tbl   OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type
80   	 , x_eam_counter_prop_tbl    OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type
81          , x_eam_wo_comp_rebuild_tbl OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type
82          , x_eam_wo_comp_mr_read_tbl OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type
83          , x_eam_op_comp_tbl         OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type
84 	 , x_eam_request_tbl         OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_request_tbl_type
85          , x_return_status           OUT NOCOPY VARCHAR2
86          , x_msg_count               OUT NOCOPY NUMBER
87          , p_commit                  IN  VARCHAR2 := 'N'
88          , p_debug                   IN  VARCHAR2 := 'N'
89          , p_output_dir              IN  VARCHAR2 := NULL
90          , p_debug_filename          IN  VARCHAR2 := 'EAM_WO_DEBUG.log'
91          , p_debug_file_mode         IN  VARCHAR2 := 'w'
92          )IS
93 
94         G_EXC_SEV_QUIT_OBJECT   EXCEPTION;
95         G_EXC_UNEXP_SKIP_OBJECT EXCEPTION;
96         l_Mesg_Token_Tbl        EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
97         l_other_message         VARCHAR2(50);
98         l_other_token_tbl       EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type;
99         l_Token_Tbl             EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type;
100         l_err_text              VARCHAR2(2000);
101         l_return_status         VARCHAR2(1) := null;
102         l_eam_return_status     VARCHAR2(1) := null;
103         l_msg_count             NUMBER;
104         l_msg_data              VARCHAR2(1000);
105         l_debug                 VARCHAR2(1) := p_debug;
106         l_output_dir            VARCHAR2(512) := p_output_dir;
107         l_debug_filename        VARCHAR2(512) := p_debug_filename;
108         l_debug_file_mode       VARCHAR2(512) := p_debug_file_mode;
109 
110         l_message_text  VARCHAR2(1000);
111         l_entity_index      NUMBER;
112         l_entity_id         VARCHAR2(100);
113         l_message_type      VARCHAR2(100);
114 
115         l_eam_wo_rec            EAM_PROCESS_WO_PUB.eam_wo_rec_type;
116         l_eam_wo_tbl            EAM_PROCESS_WO_PUB.eam_wo_tbl_type := p_eam_wo_tbl;
117         l_eam_wo_relations_tbl  EAM_PROCESS_WO_PUB.eam_wo_relations_tbl_type := p_eam_wo_relations_tbl;
118         l_eam_op_tbl            EAM_PROCESS_WO_PUB.eam_op_tbl_type := p_eam_op_tbl;
119         l_eam_op_network_tbl    EAM_PROCESS_WO_PUB.eam_op_network_tbl_type := p_eam_op_network_tbl;
120         l_eam_res_tbl           EAM_PROCESS_WO_PUB.eam_res_tbl_type := p_eam_res_tbl;
121         l_eam_res_inst_tbl      EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type := p_eam_res_inst_tbl;
122         l_eam_sub_res_tbl       EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type := p_eam_sub_res_tbl;
123         l_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type := p_eam_res_usage_tbl;
124         l_eam_mat_req_tbl       EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type := p_eam_mat_req_tbl;
125         l_eam_di_tbl		EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type := p_eam_direct_items_tbl;
126 
127 	l_eam_wo_comp_rec         EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type;
128 	l_eam_wo_comp_tbl         EAM_PROCESS_WO_PUB.eam_wo_comp_tbl_type := p_eam_wo_comp_tbl;
129 	l_eam_wo_quality_tbl      EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type := p_eam_wo_quality_tbl;
130 	l_eam_meter_reading_tbl   EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type := p_eam_meter_reading_tbl;
131 	l_eam_counter_prop_tbl    EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type := p_eam_counter_prop_tbl;
132 	l_eam_wo_comp_rebuild_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type := p_eam_wo_comp_rebuild_tbl;
133 	l_eam_wo_comp_mr_read_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type := p_eam_wo_comp_mr_read_tbl;
134 	l_eam_op_comp_tbl         EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type := p_eam_op_comp_tbl;
135 	l_eam_request_tbl         EAM_PROCESS_WO_PUB.eam_request_tbl_type := p_eam_request_tbl;
136 
137         l_eam_wo_rec_head         EAM_PROCESS_WO_PUB.eam_wo_rec_type;
138         l_eam_op_tbl_head         EAM_PROCESS_WO_PUB.eam_op_tbl_type;
139         l_eam_op_network_tbl_head EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
140         l_eam_res_tbl_head        EAM_PROCESS_WO_PUB.eam_res_tbl_type;
141         l_eam_res_inst_tbl_head   EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
142         l_eam_sub_res_tbl_head    EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
143         l_eam_res_usage_tbl_head  EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
144         l_eam_mat_req_tbl_head    EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
145         l_eam_di_tbl_head         EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
146 
147 	l_eam_wo_comp_rec_head		EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type;
148 	l_eam_wo_comp_tbl_head		EAM_PROCESS_WO_PUB.eam_wo_comp_tbl_type;
149 	l_eam_wo_quality_tbl_head	EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type;
150 	l_eam_meter_reading_tbl_head	EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type;
151 	l_eam_wo_comp_rebuild_tbl_head	EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type;
152 	l_eam_counter_prop_tbl_head	EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type;
153 	l_eam_wo_comp_mr_read_tbl_head	EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type;
154 	l_eam_op_comp_tbl_head		EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type;
155 	l_eam_request_tbl_head		EAM_PROCESS_WO_PUB.eam_request_tbl_type;
156 
157         l_out_eam_wo_rec            EAM_PROCESS_WO_PUB.eam_wo_rec_type;
158         l_out_eam_wo_tbl            EAM_PROCESS_WO_PUB.eam_wo_tbl_type;
159         l_out_eam_wo_relations_tbl  EAM_PROCESS_WO_PUB.eam_wo_relations_tbl_type;
160         l_out_eam_op_tbl            EAM_PROCESS_WO_PUB.eam_op_tbl_type;
161         l_out_eam_op_network_tbl    EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
162         l_out_eam_res_tbl           EAM_PROCESS_WO_PUB.eam_res_tbl_type;
163         l_out_eam_res_inst_tbl      EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
164         l_out_eam_sub_res_tbl       EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
165         l_out_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
166         l_out_eam_mat_req_tbl       EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
167         l_out_eam_di_tbl            EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
168         l_out_mesg_token_tbl        EAM_ERROR_MESSAGE_PVT.mesg_token_tbl_type;
169 
170 	l_out_eam_wo_comp_rec         EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type;
171 	l_out_eam_wo_comp_tbl         EAM_PROCESS_WO_PUB.eam_wo_comp_tbl_type;
172 	l_out_eam_wo_quality_tbl      EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type;
173 	l_out_eam_meter_reading_tbl   EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type;
174 	l_out_eam_wo_comp_rebuild_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type;
175 	l_out_eam_counter_prop_tbl    EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type;
176 	l_out_eam_wo_comp_mr_read_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type;
177 	l_out_eam_op_comp_tbl         EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type;
178 	l_out_eam_request_tbl         EAM_PROCESS_WO_PUB.eam_request_tbl_type;
179 
180         l_out_eam_wo_rec_main            EAM_PROCESS_WO_PUB.eam_wo_rec_type;
181         l_out_eam_wo_tbl_main            EAM_PROCESS_WO_PUB.eam_wo_tbl_type;
182         l_out_eam_wo_rel_tbl_main        EAM_PROCESS_WO_PUB.eam_wo_relations_tbl_type;
183         l_out_eam_op_tbl_main            EAM_PROCESS_WO_PUB.eam_op_tbl_type;
184         l_out_eam_op_network_tbl_main    EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
185         l_out_eam_res_tbl_main           EAM_PROCESS_WO_PUB.eam_res_tbl_type;
186         l_out_eam_res_inst_tbl_main      EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
187         l_out_eam_sub_res_tbl_main       EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
188         l_out_eam_res_usage_tbl_main     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
189         l_out_eam_mat_req_tbl_main       EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
190         l_out_eam_di_tbl_main            EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
191         l_out_mesg_token_tbl_main        EAM_ERROR_MESSAGE_PVT.mesg_token_tbl_type;
192 
193 	l_out_eam_wo_comp_rec_main	EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type;
194 	l_out_eam_wo_comp_tbl_main	EAM_PROCESS_WO_PUB.eam_wo_comp_tbl_type;
195 	l_out_eam_wo_quality_tbl_main	EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type;
196 	l_ou_eam_meter_reading_tbl_m	EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type;
197 	l_out_eam_counter_prop_tbl_m    EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type;
198 	l_ou_eam_wo_comp_rebuild_tbl_m	EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type;
199 	l_ou_eam_wo_comp_mr_read_tbl_m	EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type;
200 	l_out_eam_op_comp_tbl_main	EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type;
201 	l_out_eam_request_tbl_main	EAM_PROCESS_WO_PUB.eam_request_tbl_type;
202 
203         l_debug_flag            VARCHAR2(1) := p_debug;
204 
205         l_batch_id              NUMBER :=null;
206         l_header_id             NUMBER :=null;
207         l_header_id_tbl         EAM_PROCESS_WO_PUB.header_id_tbl_type;
208 
209 	l_wo_relationship_exc_tbl EAM_PROCESS_WO_PUB.wo_relationship_exc_tbl_type;
210 
211 	--Added for bug#4563210
212 	l_temp_wip_entity_id	NUMBER;
213 	l_wo_name		VARCHAR2(240);
214 
215 
216 
217 --	l_test_eam_wo_rec EAM_PROCESS_WO_PUB.eam_wo_rec_type;
218 
219 
220         BEGIN
221 
222 
223 	--
224         -- Initialize the message list if the user has set the Init Message List parameter
225         --
226         IF p_init_msg_list
227         THEN
228             EAM_ERROR_MESSAGE_PVT.Initialize;
229         END IF;
230 
231 
232 
233         SAVEPOINT EAM_PR_MASTER_CHILD_WO;
234 
235 
236         if p_eam_wo_tbl.count <> 0 then
237           l_eam_wo_rec := p_eam_wo_tbl(p_eam_wo_tbl.first);
238         end if;
239 
240 
241         -- Set the global variable for debug.
242         EAM_PROCESS_WO_PVT.Set_Debug(l_debug_flag);
243 
244         IF l_debug_flag = 'Y'
245         THEN
246 
247             IF trim(p_output_dir) IS NULL OR trim(p_output_dir) = ''
248             THEN
249 
250             -- If debug is Y then out dir must be specified
251 
252                 l_out_mesg_token_tbl := l_mesg_token_tbl;
253                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
254                 ( p_Message_text       => 'Debug is set to Y so an output directory' || ' must be specified. Debug will be turned' || ' off since no directory is specified'
255                 , p_Mesg_Token_Tbl     => l_mesg_token_tbl
256                 , x_Mesg_Token_Tbl     => l_out_mesg_token_tbl
257                 , p_Token_Tbl          => l_token_tbl
258                  );
259                 l_mesg_token_tbl := l_out_mesg_token_tbl;
260 
261                 l_out_eam_wo_rec            := l_eam_wo_rec;
262                 l_out_eam_op_tbl            := l_eam_op_tbl;
263                 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
264                 l_out_eam_res_tbl           := l_eam_res_tbl;
265                 l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
266                 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
267                 l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
268                 l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
269                 l_out_eam_di_tbl            := l_eam_di_tbl;
270 
271 		l_out_eam_wo_comp_rec         := l_eam_wo_comp_rec;
272 		l_out_eam_wo_quality_tbl      := l_eam_wo_quality_tbl;
273 		l_out_eam_meter_reading_tbl   := l_eam_meter_reading_tbl;
274 		l_out_eam_counter_prop_tbl    := l_eam_counter_prop_tbl;
275 		l_out_eam_wo_comp_rebuild_tbl := l_eam_wo_comp_rebuild_tbl;
276 		l_out_eam_wo_comp_mr_read_tbl := l_eam_wo_comp_mr_read_tbl;
277 		l_out_eam_op_comp_tbl         := l_eam_op_comp_tbl;
278 		l_out_eam_request_tbl         := l_eam_request_tbl;
279 
280                 EAM_ERROR_MESSAGE_PVT.Log_Error
281                 (  p_eam_wo_rec             => l_eam_wo_rec
282                 ,  p_eam_op_tbl             => l_eam_op_tbl
283                 ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
284                 ,  p_eam_res_tbl            => l_eam_res_tbl
285                 ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
286                 ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
287                 ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
288                 ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
289                 ,  p_eam_direct_items_tbl        => l_eam_di_tbl
290                 ,  p_Mesg_Token_Tbl         => l_Mesg_Token_Tbl
291                 ,  p_error_status           => 'W'
292                 ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_BO_LEVEL
293                 ,  x_eam_wo_rec             => l_out_eam_wo_rec
294                 ,  x_eam_op_tbl             => l_out_eam_op_tbl
295                 ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
296                 ,  x_eam_res_tbl            => l_out_eam_res_tbl
297                 ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
298                 ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
299                 ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
300                 ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
301                 ,  x_eam_direct_items_tbl        => l_out_eam_di_tbl
302                  );
303 
304                 l_eam_wo_rec            := l_out_eam_wo_rec;
305                 l_eam_op_tbl            := l_out_eam_op_tbl;
306                 l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
307                 l_eam_res_tbl           := l_out_eam_res_tbl;
308                 l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
309                 l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
310                 l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
311                 l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
312                 l_eam_di_tbl            := l_out_eam_di_tbl;
313 
314 		l_eam_wo_comp_rec         :=  l_out_eam_wo_comp_rec;
315 		l_eam_wo_quality_tbl      :=  l_out_eam_wo_quality_tbl;
316 		l_eam_meter_reading_tbl   :=  l_out_eam_meter_reading_tbl;
317 		l_eam_counter_prop_tbl    :=  l_out_eam_counter_prop_tbl;
318 		l_eam_wo_comp_rebuild_tbl :=  l_out_eam_wo_comp_rebuild_tbl;
319 		l_eam_wo_comp_mr_read_tbl :=  l_out_eam_wo_comp_mr_read_tbl;
320 		l_eam_op_comp_tbl         :=  l_out_eam_op_comp_tbl;
321 		l_eam_request_tbl         :=  l_out_eam_request_tbl;
322 
323 
324                 l_debug_flag := 'N';
325 
326             END IF;
327 
328             IF trim(p_debug_filename) IS NULL OR trim(p_debug_filename) = ''
329             THEN
330 
331                 l_out_mesg_token_tbl := l_mesg_token_tbl;
332                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
333                 ( p_Message_text       => 'Debug is set to Y so an output filename' || ' must be specified. Debug will be turned' || ' off since no filename is specified'
334                 , p_Mesg_Token_Tbl     => l_mesg_token_tbl
335                 , x_Mesg_Token_Tbl     => l_out_mesg_token_tbl
336                 , p_Token_Tbl          => l_token_tbl
337                  );
338                 l_mesg_token_tbl := l_out_mesg_token_tbl;
339 
340                 l_out_eam_wo_rec            := l_eam_wo_rec;
341                 l_out_eam_op_tbl            := l_eam_op_tbl;
342                 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
343                 l_out_eam_res_tbl           := l_eam_res_tbl;
344                 l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
345                 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
346                 l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
347                 l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
348                 l_out_eam_di_tbl            := l_eam_di_tbl;
349 
350 		l_out_eam_wo_comp_rec         := l_eam_wo_comp_rec;
351 		l_out_eam_wo_quality_tbl      := l_eam_wo_quality_tbl;
352 		l_out_eam_meter_reading_tbl   := l_eam_meter_reading_tbl;
353 		l_out_eam_counter_prop_tbl    := l_eam_counter_prop_tbl;
354 		l_out_eam_wo_comp_rebuild_tbl := l_eam_wo_comp_rebuild_tbl;
355 		l_out_eam_wo_comp_mr_read_tbl := l_eam_wo_comp_mr_read_tbl;
356 		l_out_eam_op_comp_tbl         := l_eam_op_comp_tbl;
357 		l_out_eam_request_tbl         := l_eam_request_tbl;
358 
359                 EAM_ERROR_MESSAGE_PVT.Log_Error
360                 (  p_eam_wo_rec             => l_eam_wo_rec
361                 ,  p_eam_op_tbl             => l_eam_op_tbl
362                 ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
363                 ,  p_eam_res_tbl            => l_eam_res_tbl
364                 ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
365                 ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
366                 ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
367                 ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
368                 ,  p_eam_direct_items_tbl   => l_eam_di_tbl
369                 ,  p_Mesg_Token_Tbl         => l_Mesg_Token_Tbl
370                 ,  p_error_status           => 'W'
371                 ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_BO_LEVEL
372                 ,  x_eam_wo_rec             => l_out_eam_wo_rec
373                 ,  x_eam_op_tbl             => l_out_eam_op_tbl
374                 ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
375                 ,  x_eam_res_tbl            => l_out_eam_res_tbl
376                 ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
377                 ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
378                 ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
379                 ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
380                 ,  x_eam_direct_items_tbl   => l_out_eam_di_tbl
381                  );
382 
383                 l_eam_wo_rec            := l_out_eam_wo_rec;
384                 l_eam_op_tbl            := l_out_eam_op_tbl;
385                 l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
386                 l_eam_res_tbl           := l_out_eam_res_tbl;
387                 l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
388                 l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
389                 l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
390                 l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
391                 l_eam_di_tbl            := l_out_eam_di_tbl;
392 
393 		l_eam_wo_comp_rec         :=  l_out_eam_wo_comp_rec;
394 		l_eam_wo_quality_tbl      :=  l_out_eam_wo_quality_tbl;
395 		l_eam_meter_reading_tbl   :=  l_out_eam_meter_reading_tbl;
396 		l_eam_counter_prop_tbl    :=  l_out_eam_counter_prop_tbl;
397 		l_eam_wo_comp_rebuild_tbl :=  l_out_eam_wo_comp_rebuild_tbl;
398 		l_eam_wo_comp_mr_read_tbl :=  l_out_eam_wo_comp_mr_read_tbl;
399 		l_eam_op_comp_tbl         :=  l_out_eam_op_comp_tbl;
400 		l_eam_request_tbl         :=  l_out_eam_request_tbl;
401 
402                 l_debug_flag := 'N';
403 
404             END IF;
405 
406             EAM_PROCESS_WO_PVT.Set_Debug(l_debug_flag);
407 
408             IF l_debug_flag = 'Y'
409             THEN
410                 l_out_mesg_token_tbl        := l_mesg_token_tbl;
411                 EAM_ERROR_MESSAGE_PVT.Open_Debug_Session
412                 (  p_debug_filename     => p_debug_filename
413                 ,  p_output_dir         => p_output_dir
414                 ,  p_debug_file_mode    => l_debug_file_mode
415                 ,  x_return_status      => l_return_status
416                 ,  p_mesg_token_tbl     => l_mesg_token_tbl
417                 ,  x_mesg_token_tbl     => l_out_mesg_token_tbl
418                  );
419                 l_mesg_token_tbl        := l_out_mesg_token_tbl;
420 
421                 IF l_return_status <> FND_API.G_RET_STS_SUCCESS
422                 THEN
423                     EAM_PROCESS_WO_PVT.Set_Debug('N');
424                 END IF;
425             END IF;
426 
427         END IF;
428 
429 
430 
431 
432         l_return_status     := FND_API.G_RET_STS_SUCCESS;
433         l_eam_return_status := FND_API.G_RET_STS_SUCCESS;
434         x_return_status     := FND_API.G_RET_STS_SUCCESS;
435 
436         l_eam_wo_tbl.delete;
437         l_eam_wo_relations_tbl.delete;
438         l_eam_op_tbl.delete;
439         l_eam_op_network_tbl.delete;
440         l_eam_res_tbl.delete;
441         l_eam_res_inst_tbl.delete;
442         l_eam_sub_res_tbl.delete;
443         l_eam_mat_req_tbl.delete;
444         l_eam_di_tbl.delete;
445         l_eam_res_usage_tbl.delete;
446 	l_eam_wo_comp_tbl.delete;
447 	l_eam_wo_quality_tbl.delete;
448 	l_eam_meter_reading_tbl.delete;
449 	l_eam_counter_prop_tbl.delete;
450 	l_eam_wo_comp_rebuild_tbl.delete;
451 	l_eam_wo_comp_mr_read_tbl.delete;
452 	l_eam_op_comp_tbl.delete;
453 	l_eam_request_tbl.delete;
454 
455         l_eam_wo_tbl            := p_eam_wo_tbl;
456         l_eam_wo_relations_tbl  := p_eam_wo_relations_tbl;
457         l_eam_op_tbl            := p_eam_op_tbl;
458         l_eam_op_network_tbl    := p_eam_op_network_tbl;
459         l_eam_res_tbl           := p_eam_res_tbl;
460         l_eam_res_inst_tbl      := p_eam_res_inst_tbl;
461         l_eam_sub_res_tbl       := p_eam_sub_res_tbl;
462         l_eam_mat_req_tbl       := p_eam_mat_req_tbl;
463         l_eam_di_tbl            := p_eam_direct_items_tbl;
464 	l_eam_res_usage_tbl     := p_eam_res_usage_tbl;
465 	l_eam_wo_comp_tbl	:= p_eam_wo_comp_tbl;
466 	l_eam_wo_quality_tbl	:= p_eam_wo_quality_tbl;
467 	l_eam_meter_reading_tbl := p_eam_meter_reading_tbl;
468 	l_eam_counter_prop_tbl  := p_eam_counter_prop_tbl;
469 	l_eam_wo_comp_rebuild_tbl := p_eam_wo_comp_rebuild_tbl;
470 	l_eam_wo_comp_mr_read_tbl := p_eam_wo_comp_mr_read_tbl;
471 	l_eam_op_comp_tbl	:= p_eam_op_comp_tbl;
472 	l_eam_request_tbl	:= p_eam_request_tbl;
473 
474         l_out_eam_wo_tbl.delete;
475         l_out_eam_wo_relations_tbl.delete;
476         l_out_eam_op_tbl.delete;
477         l_out_eam_op_network_tbl.delete;
478         l_out_eam_res_tbl.delete;
479         l_out_eam_res_inst_tbl.delete;
480         l_out_eam_sub_res_tbl.delete;
481         l_out_eam_mat_req_tbl.delete;
482         l_out_eam_di_tbl.delete;
483 	l_out_eam_res_usage_tbl.delete;
484 	l_out_eam_wo_comp_tbl.delete;
485 	l_out_eam_wo_quality_tbl.delete;
486 	l_out_eam_meter_reading_tbl.delete;
487 	l_out_eam_counter_prop_tbl.delete;
488 	l_out_eam_wo_comp_rebuild_tbl.delete;
489 	l_out_eam_wo_comp_mr_read_tbl.delete;
490 	l_out_eam_op_comp_tbl.delete;
491 	l_out_eam_request_tbl.delete;
492 
493 	l_out_eam_wo_tbl            := p_eam_wo_tbl;
494         l_out_eam_wo_relations_tbl  := p_eam_wo_relations_tbl;
495         l_out_eam_op_tbl            := p_eam_op_tbl;
496         l_out_eam_op_network_tbl    := p_eam_op_network_tbl;
497         l_out_eam_res_tbl           := p_eam_res_tbl;
498         l_out_eam_res_inst_tbl      := p_eam_res_inst_tbl;
499         l_out_eam_sub_res_tbl       := p_eam_sub_res_tbl;
500 	l_out_eam_res_usage_tbl     := p_eam_res_usage_tbl;
501         l_out_eam_mat_req_tbl       := p_eam_mat_req_tbl;
502         l_out_eam_di_tbl            := p_eam_direct_items_tbl;
503 	l_out_eam_wo_comp_tbl	    := p_eam_wo_comp_tbl;
504 	l_out_eam_wo_quality_tbl    := p_eam_wo_quality_tbl;
505 	l_out_eam_meter_reading_tbl := p_eam_meter_reading_tbl;
506 	l_out_eam_counter_prop_tbl  := p_eam_counter_prop_tbl;
507 	l_out_eam_wo_comp_rebuild_tbl := p_eam_wo_comp_rebuild_tbl;
508 	l_out_eam_wo_comp_mr_read_tbl := p_eam_wo_comp_mr_read_tbl;
509 	l_out_eam_op_comp_tbl	      := p_eam_op_comp_tbl;
510 	l_out_eam_request_tbl	      := p_eam_request_tbl;
511 
512         l_out_eam_wo_tbl_main.delete;
513         l_out_eam_wo_rel_tbl_main.delete;
514         l_out_eam_op_tbl_main.delete;
515         l_out_eam_op_network_tbl_main.delete;
516         l_out_eam_res_tbl_main.delete;
517         l_out_eam_res_inst_tbl_main.delete;
518         l_out_eam_sub_res_tbl_main.delete;
519         l_out_eam_mat_req_tbl_main.delete;
520         l_out_eam_di_tbl_main.delete;
521 	l_out_eam_res_usage_tbl_main.delete;
522 	l_out_eam_wo_comp_tbl_main.delete;
523 	l_out_eam_wo_quality_tbl_main.delete;
524 	l_ou_eam_meter_reading_tbl_m.delete;
525 	l_out_eam_counter_prop_tbl_m.delete;
526 	l_ou_eam_wo_comp_rebuild_tbl_m.delete;
527 	l_ou_eam_wo_comp_mr_read_tbl_m.delete;
528 	l_out_eam_op_comp_tbl_main.delete;
529 	l_out_eam_request_tbl_main.delete;
530 	l_out_eam_counter_prop_tbl_m.delete;
531 
532         l_out_eam_wo_tbl_main            := p_eam_wo_tbl;
533         l_out_eam_wo_rel_tbl_main        := p_eam_wo_relations_tbl;
534         l_out_eam_op_tbl_main            := p_eam_op_tbl;
535         l_out_eam_op_network_tbl_main    := p_eam_op_network_tbl;
536         l_out_eam_res_tbl_main           := p_eam_res_tbl;
537         l_out_eam_res_inst_tbl_main      := p_eam_res_inst_tbl;
538         l_out_eam_sub_res_tbl_main       := p_eam_sub_res_tbl;
539 	l_out_eam_res_usage_tbl_main     := p_eam_res_usage_tbl;
540         l_out_eam_mat_req_tbl_main       := p_eam_mat_req_tbl;
541         l_out_eam_di_tbl_main            := p_eam_direct_items_tbl;
542 	l_out_eam_wo_comp_tbl_main	 := p_eam_wo_comp_tbl;
543 	l_out_eam_wo_quality_tbl_main	 := p_eam_wo_quality_tbl;
544  	l_ou_eam_meter_reading_tbl_m	 := p_eam_meter_reading_tbl;
545         l_out_eam_counter_prop_tbl       := p_eam_counter_prop_tbl;
546 	l_ou_eam_wo_comp_rebuild_tbl_m	 := p_eam_wo_comp_rebuild_tbl;
547 	l_ou_eam_wo_comp_mr_read_tbl_m	 := p_eam_wo_comp_mr_read_tbl;
548 	l_out_eam_op_comp_tbl_main	 := p_eam_op_comp_tbl;
549 	l_out_eam_request_tbl_main	 := p_eam_request_tbl;
550 
551         x_eam_wo_tbl.delete;
552         x_eam_wo_relations_tbl.delete;
553         x_eam_op_tbl.delete;
554         x_eam_op_network_tbl.delete;
555         x_eam_res_tbl.delete;
556         x_eam_res_inst_tbl.delete;
557         x_eam_sub_res_tbl.delete;
558         x_eam_mat_req_tbl.delete;
559         x_eam_direct_items_tbl.delete;
560 	x_eam_res_usage_tbl.delete;
561 	x_eam_wo_comp_tbl.delete;
562 	x_eam_wo_quality_tbl.delete;
563 	x_eam_meter_reading_tbl.delete;
564 	x_eam_counter_prop_tbl.delete;
565 	x_eam_wo_comp_rebuild_tbl.delete;
566 	x_eam_wo_comp_mr_read_tbl.delete;
567 	x_eam_op_comp_tbl.delete;
568 
569         x_eam_wo_tbl              := p_eam_wo_tbl;
570         x_eam_wo_relations_tbl    := p_eam_wo_relations_tbl;
571         x_eam_op_tbl              := p_eam_op_tbl;
572         x_eam_op_network_tbl      := p_eam_op_network_tbl;
573         x_eam_res_tbl             := p_eam_res_tbl;
574         x_eam_res_inst_tbl        := p_eam_res_inst_tbl;
575         x_eam_sub_res_tbl         := p_eam_sub_res_tbl;
576 	x_eam_res_usage_tbl       := p_eam_res_usage_tbl;
577         x_eam_mat_req_tbl         := p_eam_mat_req_tbl;
578         x_eam_direct_items_tbl    := p_eam_direct_items_tbl;
579 	x_eam_res_usage_tbl	  := p_eam_res_usage_tbl;
580 	x_eam_wo_comp_tbl	  := p_eam_wo_comp_tbl;
581 	x_eam_wo_quality_tbl      := p_eam_wo_quality_tbl;
582 	x_eam_meter_reading_tbl   := p_eam_meter_reading_tbl;
583 	x_eam_counter_prop_tbl    := p_eam_counter_prop_tbl;
584 	x_eam_wo_comp_rebuild_tbl := p_eam_wo_comp_rebuild_tbl;
585 	x_eam_wo_comp_mr_read_tbl := p_eam_wo_comp_mr_read_tbl;
586 	x_eam_op_comp_tbl         := p_eam_op_comp_tbl;
587 
588 
589   IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN
590       EAM_ERROR_MESSAGE_PVT.Write_Debug('') ;
591       EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_MASTER_CHILD_WO : Start============================================================================') ;
592   END IF ;
593 
594   IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_MASTER_CHILD_WO : Calling CHECK_BO_NETWORK ...') ; END IF ;
595 
596 
597         CHECK_BO_NETWORK
598         ( p_eam_wo_tbl              => l_eam_wo_tbl
599         , p_eam_wo_relations_tbl    => l_eam_wo_relations_tbl
600         , p_eam_op_tbl              => l_eam_op_tbl
601         , p_eam_op_network_tbl      => l_eam_op_network_tbl
602         , p_eam_res_tbl             => l_eam_res_tbl
603         , p_eam_res_inst_tbl        => l_eam_res_inst_tbl
604         , p_eam_sub_res_tbl         => l_eam_sub_res_tbl
605         , p_eam_mat_req_tbl         => l_eam_mat_req_tbl
606         , p_eam_direct_items_tbl    => l_eam_di_tbl
607 	, p_eam_res_usage_tbl	    => l_eam_res_usage_tbl
608 	, p_eam_wo_comp_tbl         => l_eam_wo_comp_tbl
609         , p_eam_wo_quality_tbl      => l_eam_wo_quality_tbl
610         , p_eam_meter_reading_tbl   => l_eam_meter_reading_tbl
611         , p_eam_counter_prop_tbl    => l_eam_counter_prop_tbl
612         , p_eam_wo_comp_rebuild_tbl => l_eam_wo_comp_rebuild_tbl
613         , p_eam_wo_comp_mr_read_tbl => l_eam_wo_comp_mr_read_tbl
614         , p_eam_op_comp_tbl         => l_eam_op_comp_tbl
615 	, p_eam_request_tbl         => l_eam_request_tbl
616         , x_eam_wo_tbl              => l_out_eam_wo_tbl
617         , x_eam_wo_relations_tbl    => l_out_eam_wo_relations_tbl
618         , x_eam_op_tbl              => l_out_eam_op_tbl
619         , x_eam_op_network_tbl      => l_out_eam_op_network_tbl
620         , x_eam_res_tbl             => l_out_eam_res_tbl
621         , x_eam_res_inst_tbl        => l_out_eam_res_inst_tbl
622         , x_eam_sub_res_tbl         => l_out_eam_sub_res_tbl
623         , x_eam_mat_req_tbl         => l_out_eam_mat_req_tbl
624         , x_eam_direct_items_tbl    => l_out_eam_di_tbl
625 	, x_eam_res_usage_tbl	    => l_out_eam_res_usage_tbl
626 	, x_eam_wo_comp_tbl         => l_out_eam_wo_comp_tbl
627         , x_eam_wo_quality_tbl      => l_out_eam_wo_quality_tbl
628         , x_eam_meter_reading_tbl   => l_out_eam_meter_reading_tbl
629         , x_eam_counter_prop_tbl    => l_out_eam_counter_prop_tbl
630         , x_eam_wo_comp_rebuild_tbl => l_out_eam_wo_comp_rebuild_tbl
631         , x_eam_wo_comp_mr_read_tbl => l_out_eam_wo_comp_mr_read_tbl
632         , x_eam_op_comp_tbl         => l_out_eam_op_comp_tbl
633 	, x_eam_request_tbl         => l_out_eam_request_tbl
634         , x_batch_id                => l_batch_id
635         , x_header_id_tbl           => l_header_id_tbl
636         , x_return_status           => l_return_status
637         );
638 
639 
640         l_eam_wo_tbl           := l_out_eam_wo_tbl;
641         l_eam_wo_relations_tbl := l_out_eam_wo_relations_tbl;
642         l_eam_op_tbl           := l_out_eam_op_tbl;
643         l_eam_op_network_tbl   := l_out_eam_op_network_tbl;
644         l_eam_res_tbl          := l_out_eam_res_tbl;
645         l_eam_res_inst_tbl     := l_out_eam_res_inst_tbl;
646         l_eam_sub_res_tbl      := l_out_eam_sub_res_tbl;
647 	l_eam_res_usage_tbl    := l_out_eam_res_usage_tbl;
648         l_eam_mat_req_tbl      := l_out_eam_mat_req_tbl;
649         l_eam_di_tbl           := l_out_eam_di_tbl;
650 	l_eam_wo_comp_tbl         := l_out_eam_wo_comp_tbl;
651 	l_eam_wo_quality_tbl      := l_out_eam_wo_quality_tbl;
652 	l_eam_meter_reading_tbl   := l_out_eam_meter_reading_tbl;
653 	l_eam_counter_prop_tbl	  := l_out_eam_counter_prop_tbl;
654 	l_eam_wo_comp_rebuild_tbl := l_out_eam_wo_comp_rebuild_tbl;
655 	l_eam_wo_comp_mr_read_tbl := l_out_eam_wo_comp_mr_read_tbl;
656 	l_eam_op_comp_tbl         := l_out_eam_op_comp_tbl;
657 	l_eam_request_tbl         := l_out_eam_request_tbl;
658 
659         l_out_eam_wo_tbl.delete;
660         l_out_eam_wo_relations_tbl.delete;
661         l_out_eam_op_tbl.delete;
662         l_out_eam_op_network_tbl.delete;
663         l_out_eam_res_tbl.delete;
664         l_out_eam_res_inst_tbl.delete;
665         l_out_eam_sub_res_tbl.delete;
666 	l_out_eam_res_usage_tbl.delete;
667         l_out_eam_mat_req_tbl.delete;
668         l_out_eam_di_tbl.delete;
669 	l_out_eam_wo_comp_tbl.delete;
670 	l_out_eam_wo_quality_tbl.delete;
671 	l_out_eam_meter_reading_tbl.delete;
672 	l_out_eam_counter_prop_tbl.delete;
673 	l_out_eam_wo_comp_rebuild_tbl.delete;
674 	l_out_eam_wo_comp_mr_read_tbl.delete;
675 	l_out_eam_op_comp_tbl.delete;
676 	l_out_eam_request_tbl.delete;
677 
678 
679 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_MASTER_CHILD_WO : CHECK_BO_NETWORK completed with status ='||l_return_status) ; END IF ;
680 
681         if nvl(l_return_status,FND_API.G_RET_STS_ERROR) <> FND_API.G_RET_STS_SUCCESS then
682 
683                 l_out_mesg_token_tbl  := l_mesg_token_tbl;
684                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
685                 (  p_message_name  => 'EAM_WN_BO_NET_ERR'
686                 , p_token_tbl     => l_token_tbl
687                 , p_mesg_token_tbl     => l_mesg_token_tbl
688                 , x_mesg_token_tbl     => l_out_mesg_token_tbl
689                 );
690                 l_mesg_token_tbl      := l_out_mesg_token_tbl;
691 
692                 l_out_eam_wo_rec            := l_eam_wo_rec;
693                 l_out_eam_op_tbl            := l_eam_op_tbl;
694                 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
695                 l_out_eam_res_tbl           := l_eam_res_tbl;
696                 l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
697                 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
698                 l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
699                 l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
700                 l_out_eam_di_tbl            := l_eam_di_tbl;
701 
702 		l_out_eam_wo_comp_rec         := l_eam_wo_comp_rec;
703 		l_out_eam_wo_quality_tbl      := l_eam_wo_quality_tbl;
704 		l_out_eam_meter_reading_tbl   := l_eam_meter_reading_tbl;
705 		l_out_eam_counter_prop_tbl    := l_eam_counter_prop_tbl;
706 		l_out_eam_wo_comp_rebuild_tbl := l_eam_wo_comp_rebuild_tbl;
707 		l_out_eam_wo_comp_mr_read_tbl := l_eam_wo_comp_mr_read_tbl;
708 		l_out_eam_op_comp_tbl         := l_eam_op_comp_tbl;
709 		l_out_eam_request_tbl         := l_eam_request_tbl;
710 
711                 EAM_ERROR_MESSAGE_PVT.Log_Error
712                 (  p_eam_wo_rec             => l_eam_wo_rec
713                 ,  p_eam_op_tbl             => l_eam_op_tbl
714                 ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
715                 ,  p_eam_res_tbl            => l_eam_res_tbl
716                 ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
717                 ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
718                 ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
719                 ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
720                 ,  p_eam_direct_items_tbl   => l_eam_di_tbl
721                 ,  p_Mesg_Token_Tbl         => l_Mesg_Token_Tbl
722                 ,  p_error_status           => 'W'
723                 ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_BO_LEVEL
724                 ,  x_eam_wo_rec             => l_out_eam_wo_rec
725                 ,  x_eam_op_tbl             => l_out_eam_op_tbl
726                 ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
727                 ,  x_eam_res_tbl            => l_out_eam_res_tbl
728                 ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
729                 ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
730                 ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
731                 ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
732                 ,  x_eam_direct_items_tbl   => l_out_eam_di_tbl
733                  );
734 
735                 l_eam_wo_rec            := l_out_eam_wo_rec;
736                 l_eam_op_tbl            := l_out_eam_op_tbl;
737                 l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
738                 l_eam_res_tbl           := l_out_eam_res_tbl;
739                 l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
740                 l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
741                 l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
742                 l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
743                 l_eam_di_tbl            := l_out_eam_di_tbl;
744 
745 		l_eam_wo_comp_rec         :=  l_out_eam_wo_comp_rec;
746 		l_eam_wo_quality_tbl      :=  l_out_eam_wo_quality_tbl;
747 		l_eam_meter_reading_tbl   :=  l_out_eam_meter_reading_tbl;
748 		l_eam_counter_prop_tbl    :=  l_out_eam_counter_prop_tbl;
749 		l_eam_wo_comp_rebuild_tbl :=  l_out_eam_wo_comp_rebuild_tbl;
750 		l_eam_wo_comp_mr_read_tbl :=  l_out_eam_wo_comp_mr_read_tbl;
751 		l_eam_op_comp_tbl         :=  l_out_eam_op_comp_tbl;
752 		l_eam_request_tbl         :=  l_out_eam_request_tbl;
753 
754                 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y'
755                 THEN
756                    EAM_ERROR_MESSAGE_PVT.Dump_Message_List;
757                    EAM_ERROR_MESSAGE_PVT.Close_Debug_Session;
758                 END IF;
759 
760 
761                 l_eam_return_status := FND_API.G_RET_STS_ERROR;
762                 x_return_status     := FND_API.G_RET_STS_ERROR;
763                 x_msg_count := EAM_ERROR_MESSAGE_PVT.Get_Message_Count;
764                 return;
765         end if;
766 
767 
768         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y'
769         THEN
770             EAM_ERROR_MESSAGE_PVT.Dump_Message_List;
771             EAM_ERROR_MESSAGE_PVT.Close_Debug_Session;
772         END IF;
773 
774 
775 
776         -- Start Processing each of the work orders
777 
778         if l_header_id_tbl.count > 0 then
779 
780 
781 
782           for i in l_header_id_tbl.first..l_header_id_tbl.last loop
783 
784             l_header_id := l_header_id_tbl(i).header_id;
785 
786             l_eam_wo_rec_head.transaction_type := null;
787             if l_eam_wo_tbl.count > 0 then
788             for j in l_eam_wo_tbl.first..l_eam_wo_tbl.last loop
789               if l_eam_wo_tbl(j).header_id = l_header_id then
790                 l_eam_wo_rec_head := l_eam_wo_tbl(j);
791               end if;
792             end loop;
793 
794           end if;
795 
796           if l_eam_op_tbl.count > 0 then
797             l_eam_op_tbl_head.delete;
798             for j in l_eam_op_tbl.first..l_eam_op_tbl.last loop
799               if l_eam_op_tbl(j).header_id = l_header_id then
800                 l_eam_op_tbl_head(l_eam_op_tbl_head.count+1) := l_eam_op_tbl(j);
801               end if;
802             end loop;
803           end if;
804 
805           if l_eam_op_network_tbl.count > 0 then
806             l_eam_op_network_tbl_head.delete;
807             for j in l_eam_op_network_tbl.first..l_eam_op_network_tbl.last loop
808               if l_eam_op_network_tbl(j).header_id = l_header_id then
809                 l_eam_op_network_tbl_head(l_eam_op_network_tbl_head.count+1) := l_eam_op_network_tbl(j);
810               end if;
811             end loop;
812           end if;
813 
814           if l_eam_res_tbl.count > 0 then
815             l_eam_res_tbl_head.delete;
816             for j in l_eam_res_tbl.first..l_eam_res_tbl.last loop
817               if l_eam_res_tbl(j).header_id = l_header_id then
818                 l_eam_res_tbl_head(l_eam_res_tbl_head.count+1) := l_eam_res_tbl(j);
819               end if;
820             end loop;
821           end if;
822 
823           if l_eam_res_inst_tbl.count > 0 then
824             l_eam_res_inst_tbl_head.delete;
825             for j in l_eam_res_inst_tbl.first..l_eam_res_inst_tbl.last loop
826               if l_eam_res_inst_tbl(j).header_id = l_header_id then
827                 l_eam_res_inst_tbl_head(l_eam_res_inst_tbl_head.count+1) := l_eam_res_inst_tbl(j);
828               end if;
829             end loop;
830           end if;
831 
832           if l_eam_sub_res_tbl.count > 0 then
833             l_eam_sub_res_tbl_head.delete;
834             for j in l_eam_sub_res_tbl.first..l_eam_sub_res_tbl.last loop
835               if l_eam_sub_res_tbl(j).header_id = l_header_id then
836                 l_eam_sub_res_tbl_head(l_eam_sub_res_tbl_head.count+1) := l_eam_sub_res_tbl(j);
837               end if;
838             end loop;
839           end if;
840 
841           if l_eam_mat_req_tbl.count > 0 then
842             l_eam_mat_req_tbl_head.delete;
843             for j in l_eam_mat_req_tbl.first..l_eam_mat_req_tbl.last loop
844               if l_eam_mat_req_tbl(j).header_id = l_header_id then
845                 l_eam_mat_req_tbl_head(l_eam_mat_req_tbl_head.count+1) := l_eam_mat_req_tbl(j);
846               end if;
847             end loop;
848           end if;
849 
850           if l_eam_di_tbl.count > 0 then
851             l_eam_di_tbl_head.delete;
852             for j in l_eam_di_tbl.first..l_eam_di_tbl.last loop
853               if l_eam_di_tbl(j).header_id = l_header_id then
854                 l_eam_di_tbl_head(l_eam_di_tbl_head.count+1) := l_eam_di_tbl(j);
855               end if;
856             end loop;
857           end if;
858 
859 	if l_eam_res_usage_tbl.count > 0 then
860             l_eam_res_usage_tbl_head.delete;
861             for j in l_eam_res_usage_tbl.first..l_eam_res_usage_tbl.last loop
862               if l_eam_res_usage_tbl(j).header_id = l_header_id then
863                 l_eam_res_usage_tbl_head(l_eam_res_usage_tbl_head.count+1) := l_eam_res_usage_tbl(j);
864               end if;
865             end loop;
866           end if;
867 
868 	 l_eam_wo_comp_rec_head.transaction_type := null;
869             if l_eam_wo_comp_tbl.count > 0 then
870             for j in l_eam_wo_comp_tbl.first..l_eam_wo_comp_tbl.last loop
871               if l_eam_wo_comp_tbl(j).header_id = l_header_id then
872                 l_eam_wo_comp_rec_head := l_eam_wo_comp_tbl(j);
873               end if;
874             end loop;
875 
876           end if;
877 
878 /*	 if l_eam_wo_comp_tbl.count > 0 then
879             l_eam_wo_comp_tbl_head.delete;
880             for j in l_eam_wo_comp_tbl.first..l_eam_wo_comp_tbl.last loop
881               if l_eam_wo_comp_tbl(j).header_id = l_header_id then
882                 l_eam_wo_comp_tbl_head(l_eam_wo_comp_tbl_head.count+1) := l_eam_wo_comp_tbl(j);
883               end if;
884             end loop;
885           end if;
886 */
887 
888 
889 	 if l_eam_wo_quality_tbl.count > 0 then
890             l_eam_wo_quality_tbl_head.delete;
891             for j in l_eam_wo_quality_tbl.first..l_eam_wo_quality_tbl.last loop
892               if l_eam_wo_quality_tbl(j).header_id = l_header_id then
893                 l_eam_wo_quality_tbl_head(l_eam_wo_quality_tbl_head.count+1) := l_eam_wo_quality_tbl(j);
894               end if;
895             end loop;
896           end if;
897 
898 	  if l_eam_meter_reading_tbl.count > 0 then
899             l_eam_meter_reading_tbl_head.delete;
900             for j in l_eam_meter_reading_tbl.first..l_eam_meter_reading_tbl.last loop
901               if l_eam_meter_reading_tbl(j).header_id = l_header_id then
902                 l_eam_meter_reading_tbl_head(l_eam_meter_reading_tbl_head.count+1) := l_eam_meter_reading_tbl(j);
903               end if;
904             end loop;
905           end if;
906 
907 	  if l_eam_counter_prop_tbl.count > 0 then
908             l_eam_counter_prop_tbl_head.delete;
909             for j in l_eam_counter_prop_tbl.first..l_eam_counter_prop_tbl.last loop
910               if l_eam_counter_prop_tbl(j).header_id = l_header_id then
911                 l_eam_counter_prop_tbl_head(l_eam_counter_prop_tbl_head.count+1) := l_eam_counter_prop_tbl(j);
912               end if;
913             end loop;
914           end if;
915 
916 	  if l_eam_wo_comp_rebuild_tbl.count > 0 then
917             l_eam_wo_comp_rebuild_tbl_head.delete;
918             for j in l_eam_wo_comp_rebuild_tbl.first..l_eam_wo_comp_rebuild_tbl.last loop
919               if l_eam_wo_comp_rebuild_tbl(j).header_id = l_header_id then
920                 l_eam_wo_comp_rebuild_tbl_head(l_eam_wo_comp_rebuild_tbl_head.count+1) := l_eam_wo_comp_rebuild_tbl(j);
921               end if;
922             end loop;
923           end if;
924 
925 	   if l_eam_wo_comp_mr_read_tbl.count > 0 then
926             l_eam_wo_comp_mr_read_tbl_head.delete;
927             for j in l_eam_wo_comp_mr_read_tbl.first..l_eam_wo_comp_mr_read_tbl.last loop
928               if l_eam_wo_comp_mr_read_tbl(j).header_id = l_header_id then
929                 l_eam_wo_comp_mr_read_tbl_head(l_eam_wo_comp_mr_read_tbl_head.count+1) := l_eam_wo_comp_mr_read_tbl(j);
930               end if;
931             end loop;
932           end if;
933 
934 	   if l_eam_op_comp_tbl.count > 0 then
935             l_eam_op_comp_tbl_head.delete;
936             for j in l_eam_op_comp_tbl.first..l_eam_op_comp_tbl.last loop
937               if l_eam_op_comp_tbl(j).header_id = l_header_id then
938                 l_eam_op_comp_tbl_head(l_eam_op_comp_tbl_head.count+1) := l_eam_op_comp_tbl(j);
939               end if;
940             end loop;
941           end if;
942 
943 	   if l_eam_request_tbl.count > 0 then
944             l_eam_request_tbl_head.delete;
945 
946             for j in l_eam_request_tbl.first..l_eam_request_tbl.last loop
947 	    	if l_eam_request_tbl(j).header_id = l_header_id then
948 	      	    l_eam_request_tbl_head(l_eam_request_tbl_head.count+1) := l_eam_request_tbl(j);
949 		end if;
950             end loop;
951           end if;
952 
953           SAVEPOINT Single_WO_Process;
954 
955 
956           -- Insert a dummy message into the message stack before each work order
957           -- is processed. If the WO got processed without errors, then this dummy message
958           -- is deleted. Else it stays there and serves as a seperator between
959           -- the messages generated by different work orders.
960           l_mesg_token_tbl.delete;
961           l_token_tbl.delete;
962 
963           l_token_tbl(1).token_name  := 'Header Id';
964           l_token_tbl(1).token_value :=  l_eam_wo_rec_head.header_id;
965 
966           l_out_mesg_token_tbl  := l_mesg_token_tbl;
967           EAM_ERROR_MESSAGE_PVT.Add_Error_Token
968                 (  p_message_name  => 'EAM_WN_GEN_WARNING'
969                 , p_token_tbl     => l_token_tbl
970                 , p_mesg_token_tbl     => l_mesg_token_tbl
971                 , x_mesg_token_tbl     => l_out_mesg_token_tbl
972                 );
973           l_mesg_token_tbl      := l_out_mesg_token_tbl;
974 
975 
976           EAM_ERROR_MESSAGE_PVT.Translate_And_Insert_Messages
977           (  p_mesg_token_tbl     => l_mesg_token_tbl
978            , p_error_level        => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
979            , p_entity_index       => l_eam_wo_rec_head.row_id
980            , p_application_id     => 'EAM'
981            );
982 
983 
984 
985            PROCESS_WO
986            (  p_bo_identifier           => 'EAM'
987             , p_api_version_number      => 1.0
988             , p_init_msg_list           => FALSE
989             , p_commit                  => 'N'
990             , p_eam_wo_rec              => l_eam_wo_rec_head
991             , p_eam_op_tbl              => l_eam_op_tbl_head
992             , p_eam_op_network_tbl      => l_eam_op_network_tbl_head
993             , p_eam_res_tbl             => l_eam_res_tbl_head
994             , p_eam_res_inst_tbl        => l_eam_res_inst_tbl_head
995             , p_eam_sub_res_tbl         => l_eam_sub_res_tbl_head
996             , p_eam_res_usage_tbl       => l_eam_res_usage_tbl_head
997             , p_eam_mat_req_tbl         => l_eam_mat_req_tbl_head
998             , p_eam_direct_items_tbl    => l_eam_di_tbl
999   	    , p_eam_wo_comp_rec         => l_eam_wo_comp_rec_head
1000 	    , p_eam_wo_quality_tbl      => l_eam_wo_quality_tbl_head
1001 	    , p_eam_meter_reading_tbl   => l_eam_meter_reading_tbl_head
1002 	    , p_eam_counter_prop_tbl    => l_eam_counter_prop_tbl_head
1003 	    , p_eam_wo_comp_rebuild_tbl => l_eam_wo_comp_rebuild_tbl_head
1004 	    , p_eam_wo_comp_mr_read_tbl => l_eam_wo_comp_mr_read_tbl_head
1005   	    , p_eam_op_comp_tbl         => l_eam_op_comp_tbl_head
1006 	    , p_eam_request_tbl         => l_eam_request_tbl_head
1007             , x_eam_wo_rec              => l_out_eam_wo_rec
1008             , x_eam_op_tbl              => l_out_eam_op_tbl
1009             , x_eam_op_network_tbl      => l_out_eam_op_network_tbl
1010             , x_eam_res_tbl             => l_out_eam_res_tbl
1011             , x_eam_res_inst_tbl        => l_out_eam_res_inst_tbl
1012             , x_eam_sub_res_tbl         => l_out_eam_sub_res_tbl
1013             , x_eam_res_usage_tbl       => l_out_eam_res_usage_tbl
1014             , x_eam_mat_req_tbl         => l_out_eam_mat_req_tbl
1015             , x_eam_direct_items_tbl    => l_out_eam_di_tbl
1016 	    , x_eam_wo_comp_rec         => l_out_eam_wo_comp_rec
1017 	    , x_eam_wo_quality_tbl      => l_out_eam_wo_quality_tbl
1018 	    , x_eam_meter_reading_tbl   => l_out_eam_meter_reading_tbl
1019 	    , x_eam_counter_prop_tbl    => l_out_eam_counter_prop_tbl
1020 	    , x_eam_wo_comp_rebuild_tbl => l_out_eam_wo_comp_rebuild_tbl
1021 	    , x_eam_wo_comp_mr_read_tbl => l_out_eam_wo_comp_mr_read_tbl
1022 	    , x_eam_op_comp_tbl         => l_out_eam_op_comp_tbl
1023 	    , x_eam_request_tbl         => l_out_eam_request_tbl
1024             , x_return_status           => l_return_status
1025             , x_msg_count               => l_msg_count
1026             , p_debug                   => l_debug_flag
1027             , p_output_dir              => l_output_dir
1028             , p_debug_filename          => l_debug_filename
1029             , p_debug_file_mode         => 'a'
1030            );
1031 
1032 	--added for bug 4563210
1033 	if l_eam_wo_rec_head.transaction_type = EAM_PROCESS_WO_PUB.G_OPR_CREATE
1034                  and l_return_status = 'S' then
1035                          l_eam_wo_list(l_eam_wo_list.count + 1) := l_out_eam_wo_rec.wip_entity_name;
1036         end if;
1037 
1038 --   IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Size of the list of newly created work orders:'||l_eam_wo_list.count) ; END IF ;
1039 
1040            if l_out_eam_wo_rec.transaction_type is not null then
1041              l_eam_wo_tbl(l_out_eam_wo_rec.row_id) := l_out_eam_wo_rec;
1042            end if;
1043 
1044            if l_out_eam_op_tbl.count <> 0 then
1045              for j in l_out_eam_op_tbl.first..l_out_eam_op_tbl.last loop
1046                if l_out_eam_op_tbl(j).row_id is null then
1047                  l_out_eam_op_tbl(j).row_id := l_eam_op_tbl.count+1;
1048                end if;
1049                l_eam_op_tbl(l_out_eam_op_tbl(j).row_id) := l_out_eam_op_tbl(j);
1050              end loop;
1051            end if;
1052 
1053          if l_out_eam_op_network_tbl.count <> 0 then
1054            for j in l_out_eam_op_network_tbl.first..l_out_eam_op_network_tbl.last loop
1055              if l_out_eam_op_network_tbl(j).row_id is null then
1056                l_out_eam_op_network_tbl(j).row_id := l_eam_op_network_tbl.count+1;
1057              end if;
1058              l_eam_op_network_tbl(l_out_eam_op_network_tbl(j).row_id) := l_out_eam_op_network_tbl(j);
1059            end loop;
1060          end if;
1061 
1062          if l_out_eam_res_tbl.count <> 0 then
1063            for j in l_out_eam_res_tbl.first..l_out_eam_res_tbl.last loop
1064              if l_out_eam_res_tbl(j).row_id is null then
1065                l_out_eam_res_tbl(j).row_id := l_eam_res_tbl.count+1;
1066              end if;
1067              l_eam_res_tbl(l_out_eam_res_tbl(j).row_id) := l_out_eam_res_tbl(j);
1068            end loop;
1069          end if;
1070 
1071          if l_out_eam_res_inst_tbl.count <> 0 then
1072            for j in l_out_eam_res_inst_tbl.first..l_out_eam_res_inst_tbl.last loop
1073              if l_out_eam_res_inst_tbl(j).row_id is null then
1074                l_out_eam_res_inst_tbl(j).row_id := l_eam_res_inst_tbl.count+1;
1075              end if;
1076              l_eam_res_inst_tbl(l_out_eam_res_inst_tbl(j).row_id) := l_out_eam_res_inst_tbl(j);
1077            end loop;
1078          end if;
1079 
1080          if l_out_eam_sub_res_tbl.count <> 0 then
1081            for j in l_out_eam_sub_res_tbl.first..l_out_eam_sub_res_tbl.last loop
1082              if l_out_eam_sub_res_tbl(j).row_id is null then
1083                l_out_eam_sub_res_tbl(j).row_id := l_eam_sub_res_tbl.count+1;
1084              end if;
1085              l_eam_sub_res_tbl(l_out_eam_sub_res_tbl(j).row_id) := l_out_eam_sub_res_tbl(j);
1086            end loop;
1087          end if;
1088 
1089          if l_out_eam_mat_req_tbl.count <> 0 then
1090            for j in l_out_eam_mat_req_tbl.first..l_out_eam_mat_req_tbl.last loop
1091              if l_out_eam_mat_req_tbl(j).row_id is null then
1092                l_out_eam_mat_req_tbl(j).row_id := l_eam_mat_req_tbl.count+1;
1093              end if;
1094              l_eam_mat_req_tbl(l_out_eam_mat_req_tbl(j).row_id) := l_out_eam_mat_req_tbl(j);
1095            end loop;
1096          end if;
1097 
1098          if l_out_eam_di_tbl.count <> 0 then
1099            for j in l_out_eam_di_tbl.first..l_out_eam_di_tbl.last loop
1100              if l_out_eam_di_tbl(j).row_id is null then
1101                l_out_eam_di_tbl(j).row_id := l_eam_di_tbl.count+1;
1102              end if;
1103              l_eam_di_tbl(l_out_eam_di_tbl(j).row_id) := l_out_eam_di_tbl(j);
1104            end loop;
1105          end if;
1106 
1107          if l_out_eam_res_usage_tbl.count <> 0 then
1108            for j in l_out_eam_res_usage_tbl.first..l_out_eam_res_usage_tbl.last loop
1109              if l_out_eam_res_usage_tbl(j).row_id is null then
1110                l_out_eam_res_usage_tbl(j).row_id := l_eam_res_usage_tbl.count+1;
1111              end if;
1112              l_eam_res_usage_tbl(l_out_eam_res_usage_tbl(j).row_id) := l_out_eam_res_usage_tbl(j);
1113            end loop;
1114          end if;
1115 
1116 
1117 	 if l_out_eam_wo_comp_rec.transaction_type is not null then
1118              l_eam_wo_comp_tbl(l_out_eam_wo_comp_rec.row_id) := l_out_eam_wo_comp_rec;
1119          end if;
1120 
1121 	  if l_out_eam_wo_quality_tbl.count <> 0 then
1122            for j in l_out_eam_wo_quality_tbl.first..l_out_eam_wo_quality_tbl.last loop
1123              if l_out_eam_wo_quality_tbl(j).row_id is null then
1124                l_out_eam_wo_quality_tbl(j).row_id := l_eam_wo_quality_tbl.count+1;
1125              end if;
1126              l_eam_wo_quality_tbl(l_out_eam_wo_quality_tbl(j).row_id) := l_out_eam_wo_quality_tbl(j);
1127            end loop;
1128          end if;
1129 
1130 	if l_out_eam_meter_reading_tbl.count <> 0 then
1131            for j in l_out_eam_meter_reading_tbl.first..l_out_eam_meter_reading_tbl.last loop
1132              if l_out_eam_meter_reading_tbl(j).row_id is null then
1133                l_out_eam_meter_reading_tbl(j).row_id := l_eam_meter_reading_tbl.count+1;
1134              end if;
1135              l_eam_meter_reading_tbl(l_out_eam_meter_reading_tbl(j).row_id) := l_out_eam_meter_reading_tbl(j);
1136            end loop;
1137          end if;
1138 
1139 	if l_out_eam_counter_prop_tbl.count <> 0 then
1140            for j in l_out_eam_counter_prop_tbl.first..l_out_eam_counter_prop_tbl.last loop
1141              if l_out_eam_counter_prop_tbl(j).row_id is null then
1142                l_out_eam_counter_prop_tbl(j).row_id := l_eam_counter_prop_tbl.count+1;
1143              end if;
1144              l_eam_counter_prop_tbl(l_out_eam_counter_prop_tbl(j).row_id) := l_out_eam_counter_prop_tbl(j);
1145            end loop;
1146          end if;
1147 
1148 
1149 	if l_out_eam_wo_comp_rebuild_tbl.count <> 0 then
1150            for j in l_out_eam_wo_comp_rebuild_tbl.first..l_out_eam_wo_comp_rebuild_tbl.last loop
1151              if l_out_eam_wo_comp_rebuild_tbl(j).row_id is null then
1152                l_out_eam_wo_comp_rebuild_tbl(j).row_id := l_eam_wo_comp_rebuild_tbl.count+1;
1153              end if;
1154              l_eam_wo_comp_rebuild_tbl(l_out_eam_wo_comp_rebuild_tbl(j).row_id) := l_out_eam_wo_comp_rebuild_tbl(j);
1155            end loop;
1156          end if;
1157 
1158 	if l_out_eam_wo_comp_mr_read_tbl.count <> 0 then
1159            for j in l_out_eam_wo_comp_mr_read_tbl.first..l_out_eam_wo_comp_mr_read_tbl.last loop
1160              if l_out_eam_wo_comp_mr_read_tbl(j).row_id is null then
1161                l_out_eam_wo_comp_mr_read_tbl(j).row_id := l_eam_wo_comp_mr_read_tbl.count+1;
1162              end if;
1163              l_eam_wo_comp_mr_read_tbl(l_out_eam_wo_comp_mr_read_tbl(j).row_id) := l_out_eam_wo_comp_mr_read_tbl(j);
1164            end loop;
1165          end if;
1166 
1167 	if l_out_eam_op_comp_tbl.count <> 0 then
1168            for j in l_out_eam_op_comp_tbl.first..l_out_eam_op_comp_tbl.last loop
1169              if l_out_eam_op_comp_tbl(j).row_id is null then
1170                l_out_eam_op_comp_tbl(j).row_id := l_eam_op_comp_tbl.count+1;
1171              end if;
1172              l_eam_op_comp_tbl(l_out_eam_op_comp_tbl(j).row_id) := l_out_eam_op_comp_tbl(j);
1173            end loop;
1174          end if;
1175 
1176 	if l_out_eam_request_tbl.count <> 0 then
1177            for j in l_out_eam_request_tbl.first..l_out_eam_request_tbl.last loop
1178              if l_out_eam_request_tbl(j).row_id is null then
1179                l_out_eam_request_tbl(j).row_id := l_eam_request_tbl.count+1;
1180              end if;
1181              l_eam_request_tbl(l_out_eam_request_tbl(j).row_id) := l_out_eam_request_tbl(j);
1182            end loop;
1183          end if;
1184 
1185 
1186          -- IF WO creation/updation failed, then rollback
1187          -- till start of this current WO process start
1188          IF nvl(l_return_status,'Q') <> 'S' THEN
1189            rollback to Single_WO_Process;
1190 
1191           l_eam_return_status := FND_API.G_RET_STS_ERROR;
1192           x_return_status     := FND_API.G_RET_STS_ERROR;
1193 
1194           -- Also disregard all relations pertaining to this work
1195           -- order as not valid;
1196           if l_eam_wo_relations_tbl.count <> 0 then
1197           for j in l_eam_wo_relations_tbl.first..l_eam_wo_relations_tbl.last loop
1198 
1199             if l_eam_wo_relations_tbl(j).parent_header_id     = l_header_id or
1200                l_eam_wo_relations_tbl(j).child_header_id      = l_header_id or
1201                l_eam_wo_relations_tbl(j).top_level_header_id  = l_header_id then
1202               l_eam_wo_relations_tbl(j).return_status := FND_API.G_RET_STS_ERROR;
1203             end if;
1204 
1205           end loop;
1206           end if;
1207 
1208          ELSE
1209 
1210          -- Delete the general warning message from both the fnd and eam message stacks
1211          fnd_msg_pub.delete_msg(p_msg_index => fnd_msg_pub.Count_Msg);
1212 
1213          EAM_ERROR_MESSAGE_PVT.Delete_Message;
1214 
1215    	     x_msg_count := EAM_ERROR_MESSAGE_PVT.GET_MESSAGE_COUNT();
1216 
1217 
1218 
1219           -- Populate the wip_entity_id for newly created work orders
1220           -- into the corresponding records in the relations PL/SQL table
1221 
1222           if l_eam_wo_relations_tbl.count > 0 then
1223           for j in l_eam_wo_relations_tbl.first..l_eam_wo_relations_tbl.last loop
1224 
1225             if l_eam_wo_relations_tbl(j).parent_header_id = l_header_id then
1226               l_eam_wo_relations_tbl(j).parent_object_id := l_out_eam_wo_rec.wip_entity_id;
1227             end if;
1228 
1229             if l_eam_wo_relations_tbl(j).child_header_id = l_header_id then
1230               l_eam_wo_relations_tbl(j).child_object_id := l_out_eam_wo_rec.wip_entity_id;
1231             end if;
1232 
1233             if l_eam_wo_relations_tbl(j).top_level_header_id = l_header_id then
1234               l_eam_wo_relations_tbl(j).top_level_object_id := l_out_eam_wo_rec.wip_entity_id;
1235             end if;
1236 
1237           end loop;
1238           end if;
1239 
1240          END IF;
1241 
1242 
1243         end loop;
1244         end if;
1245 
1246 
1247 
1248 
1249 
1250 
1251 
1252 
1253         -- Set the global variable for debug.
1254         EAM_PROCESS_WO_PVT.Set_Debug(l_debug_flag);
1255 
1256         IF l_debug_flag = 'Y'
1257         THEN
1258 
1259             IF trim(p_output_dir) IS NULL OR trim(p_output_dir) = ''
1260             THEN
1261 
1262             -- If debug is Y then out dir must be specified
1263 
1264                 l_out_mesg_token_tbl := l_mesg_token_tbl;
1265                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
1266                 ( p_Message_text       => 'Debug is set to Y so an output directory' || ' must be specified. Debug will be turned' || ' off since no directory is specified'
1267                 , p_Mesg_Token_Tbl     => l_mesg_token_tbl
1268                 , x_Mesg_Token_Tbl     => l_out_mesg_token_tbl
1269                 , p_Token_Tbl          => l_token_tbl
1270                  );
1271                 l_mesg_token_tbl := l_out_mesg_token_tbl;
1272 
1273                 l_out_eam_wo_rec            := l_eam_wo_rec;
1274                 l_out_eam_op_tbl            := l_eam_op_tbl;
1275                 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
1276                 l_out_eam_res_tbl           := l_eam_res_tbl;
1277                 l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
1278                 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
1279                 l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
1280                 l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
1281                 l_out_eam_di_tbl            := l_eam_di_tbl;
1282 
1283                 EAM_ERROR_MESSAGE_PVT.Log_Error
1284                 (  p_eam_wo_rec             => l_eam_wo_rec
1285                 ,  p_eam_op_tbl             => l_eam_op_tbl
1286                 ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
1287                 ,  p_eam_res_tbl            => l_eam_res_tbl
1288                 ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
1289                 ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
1290                 ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
1291                 ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
1292                 ,  p_eam_direct_items_tbl   => l_eam_di_tbl
1293                 ,  p_Mesg_Token_Tbl         => l_Mesg_Token_Tbl
1294                 ,  p_error_status           => 'W'
1295                 ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_BO_LEVEL
1296                 ,  x_eam_wo_rec             => l_out_eam_wo_rec
1297                 ,  x_eam_op_tbl             => l_out_eam_op_tbl
1298                 ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
1299                 ,  x_eam_res_tbl            => l_out_eam_res_tbl
1300                 ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
1301                 ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
1302                 ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
1303                 ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
1304                 ,  x_eam_direct_items_tbl   => l_out_eam_di_tbl
1305                  );
1306 
1307                 l_eam_wo_rec            := l_out_eam_wo_rec;
1308                 l_eam_op_tbl            := l_out_eam_op_tbl;
1309                 l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
1310                 l_eam_res_tbl           := l_out_eam_res_tbl;
1311                 l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
1312                 l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
1313                 l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
1314                 l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
1315                 l_eam_di_tbl            := l_out_eam_di_tbl;
1316 
1317 		l_eam_wo_comp_rec         :=  l_out_eam_wo_comp_rec;
1318 		l_eam_wo_quality_tbl      :=  l_out_eam_wo_quality_tbl;
1319 		l_eam_meter_reading_tbl   :=  l_out_eam_meter_reading_tbl;
1320 		l_eam_counter_prop_tbl    :=  l_out_eam_counter_prop_tbl;
1321 		l_eam_wo_comp_rebuild_tbl :=  l_out_eam_wo_comp_rebuild_tbl;
1322 		l_eam_wo_comp_mr_read_tbl :=  l_out_eam_wo_comp_mr_read_tbl;
1323 		l_eam_op_comp_tbl         :=  l_out_eam_op_comp_tbl;
1324 		l_eam_request_tbl         :=  l_out_eam_request_tbl;
1325 
1326                 l_debug_flag := 'N';
1327 
1328             END IF;
1329 
1330             IF trim(p_debug_filename) IS NULL OR trim(p_debug_filename) = ''
1331             THEN
1332 
1333                 l_out_mesg_token_tbl := l_mesg_token_tbl;
1334                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
1335                 ( p_Message_text       => 'Debug is set to Y so an output filename' || ' must be specified. Debug will be turned' || ' off since no filename is specified'
1336                 , p_Mesg_Token_Tbl     => l_mesg_token_tbl
1337                 , x_Mesg_Token_Tbl     => l_out_mesg_token_tbl
1338                 , p_Token_Tbl          => l_token_tbl
1339                  );
1340                 l_mesg_token_tbl := l_out_mesg_token_tbl;
1341 
1342                 l_out_eam_wo_rec            := l_eam_wo_rec;
1343                 l_out_eam_op_tbl            := l_eam_op_tbl;
1344                 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
1345                 l_out_eam_res_tbl           := l_eam_res_tbl;
1346                 l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
1347                 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
1348                 l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
1349                 l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
1350                 l_out_eam_di_tbl            := l_eam_di_tbl;
1351 
1352 		l_out_eam_wo_comp_rec         := l_eam_wo_comp_rec;
1353 		l_out_eam_wo_quality_tbl      := l_eam_wo_quality_tbl;
1354 		l_out_eam_meter_reading_tbl   := l_eam_meter_reading_tbl;
1355 		l_out_eam_counter_prop_tbl    := l_eam_counter_prop_tbl;
1356 		l_out_eam_wo_comp_rebuild_tbl := l_eam_wo_comp_rebuild_tbl;
1357 		l_out_eam_wo_comp_mr_read_tbl := l_eam_wo_comp_mr_read_tbl;
1358 		l_out_eam_op_comp_tbl         := l_eam_op_comp_tbl;
1359 		l_out_eam_request_tbl         := l_eam_request_tbl;
1360 
1361                 EAM_ERROR_MESSAGE_PVT.Log_Error
1362                 (  p_eam_wo_rec             => l_eam_wo_rec
1363                 ,  p_eam_op_tbl             => l_eam_op_tbl
1364                 ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
1365                 ,  p_eam_res_tbl            => l_eam_res_tbl
1366                 ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
1367                 ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
1368                 ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
1369                 ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
1370                 ,  p_eam_direct_items_tbl   => l_eam_di_tbl
1371                 ,  p_Mesg_Token_Tbl         => l_Mesg_Token_Tbl
1372                 ,  p_error_status           => 'W'
1373                 ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_BO_LEVEL
1374                 ,  x_eam_wo_rec             => l_out_eam_wo_rec
1375                 ,  x_eam_op_tbl             => l_out_eam_op_tbl
1376                 ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
1377                 ,  x_eam_res_tbl            => l_out_eam_res_tbl
1378                 ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
1379                 ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
1380                 ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
1381                 ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
1382                 ,  x_eam_direct_items_tbl   => l_out_eam_di_tbl
1383                  );
1384 
1385                 l_eam_wo_rec            := l_out_eam_wo_rec;
1386                 l_eam_op_tbl            := l_out_eam_op_tbl;
1387                 l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
1388                 l_eam_res_tbl           := l_out_eam_res_tbl;
1389                 l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
1390                 l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
1391                 l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
1392                 l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
1393                 l_eam_di_tbl            := l_out_eam_di_tbl;
1394 
1395 		l_eam_wo_comp_rec         :=  l_out_eam_wo_comp_rec;
1396 		l_eam_wo_quality_tbl      :=  l_out_eam_wo_quality_tbl;
1397 		l_eam_meter_reading_tbl   :=  l_out_eam_meter_reading_tbl;
1398 		l_eam_counter_prop_tbl    :=  l_out_eam_counter_prop_tbl;
1399 		l_eam_wo_comp_rebuild_tbl :=  l_out_eam_wo_comp_rebuild_tbl;
1400 		l_eam_wo_comp_mr_read_tbl :=  l_out_eam_wo_comp_mr_read_tbl;
1401 		l_eam_op_comp_tbl         :=  l_out_eam_op_comp_tbl;
1402 		l_eam_request_tbl         :=  l_out_eam_request_tbl;
1403 
1404                 l_debug_flag := 'N';
1405 
1406             END IF;
1407 
1408             EAM_PROCESS_WO_PVT.Set_Debug(l_debug_flag);
1409 
1410             IF l_debug_flag = 'Y'
1411             THEN
1412                 l_out_mesg_token_tbl        := l_mesg_token_tbl;
1413                 EAM_ERROR_MESSAGE_PVT.Open_Debug_Session
1414                 (  p_debug_filename     => p_debug_filename
1415                 ,  p_output_dir         => p_output_dir
1416                 ,  p_debug_file_mode    => 'a'
1417                 ,  x_return_status      => l_return_status
1418                 ,  p_mesg_token_tbl     => l_mesg_token_tbl
1419                 ,  x_mesg_token_tbl     => l_out_mesg_token_tbl
1420                  );
1421                 l_mesg_token_tbl        := l_out_mesg_token_tbl;
1422 
1423                 IF l_return_status <> FND_API.G_RET_STS_SUCCESS
1424                 THEN
1425                     EAM_PROCESS_WO_PVT.Set_Debug('N');
1426                 END IF;
1427             END IF;
1428 
1429         END IF;
1430 
1431 
1432         if p_eam_wo_tbl.count <> 0 then
1433           l_eam_wo_rec := p_eam_wo_tbl(p_eam_wo_tbl.first);
1434         end if;
1435 
1436 
1437 
1438         if l_eam_wo_relations_tbl.count > 0 then
1439         -- Start processing the relationships
1440         for i in 1..l_eam_wo_relations_tbl.count loop
1441 
1442           if nvl(l_eam_wo_relations_tbl(i).return_status,'Z') = 'Z'  OR
1443              l_eam_wo_relations_tbl(i).return_status = '' OR
1444              l_eam_wo_relations_tbl(i).return_status = ' '  then
1445 
1446           if l_eam_wo_relations_tbl(i).transaction_type =
1447             EAM_PROCESS_WO_PUB.G_OPR_CREATE then
1448 
1449              /* Added for bug#4563210 - Start */
1450 
1451 
1452 	     l_temp_wip_entity_id := l_eam_wo_relations_tbl(i).PARENT_OBJECT_ID;
1453 
1454          IF ( EAM_PROCESS_WO_PVT.Get_Debug = 'Y') THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_MASTER_CHILD_WO : Calling the EAM_WO_NETWORK_DEFAULT_PVT.Check_Wo_Dates ') ; END IF ;
1455 
1456 	     FOR l_temp_index in 1..2 LOOP
1457 
1458 	      if (l_eam_wo_relations_tbl(i).parent_relationship_type = 1) then
1459 
1460 
1461 	          EAM_WO_NETWORK_DEFAULT_PVT.Check_Wo_Dates
1462 	          (
1463 	           p_api_version                   => 1.0,
1464 	           p_init_msg_list                 => FND_API.G_FALSE,
1465 	           p_commit                        => FND_API.G_FALSE,
1466 	           p_validation_level              => FND_API.G_VALID_LEVEL_FULL,
1467 	           p_wip_entity_id                 => l_temp_wip_entity_id,
1468 	           x_return_status                 => l_return_status,
1469 	           x_msg_count                     => l_msg_count,
1470 	           x_msg_data                      => l_msg_data
1471 	           );
1472 
1473             IF ( EAM_PROCESS_WO_PVT.Get_Debug = 'Y' AND l_temp_index = 1 ) THEN
1474 		EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_MASTER_CHILD_WO : Check_Wo_Dates for parent wo completed with status of '||l_return_status) ;
1475 	   END IF ;
1476             IF ( EAM_PROCESS_WO_PVT.Get_Debug = 'Y' AND l_temp_index = 2 ) THEN
1477 		EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_MASTER_CHILD_WO : Check_Wo_Dates for child wo completed with status of '||l_return_status) ;
1478 	     END IF ;
1479 
1480         	IF l_return_status = FND_API.G_RET_STS_ERROR OR
1481 		   l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1482 
1483 		   	--Before inserting the error message, insert the confirmation message of work order creation.
1484 				x_return_status     := l_return_status;
1485 				x_msg_count := EAM_ERROR_MESSAGE_PVT.Get_Message_Count;
1486 				l_eam_return_status := FND_API.G_RET_STS_ERROR;
1487 
1488 				if l_eam_wo_list.count > 0 then
1489 					for l_new_wo_list in l_eam_wo_list.first..l_eam_wo_list.last loop
1490 						eam_execution_jsp.add_message(p_app_short_name => 'EAM',
1491 								p_msg_name => 'EAM_CREATE_WORKORDER_CONFIRM',
1492 								p_token1 => 'WORKORDER', p_value1 => l_eam_wo_list(l_new_wo_list));
1493 					end loop;
1494 				end if;
1495 				l_eam_wo_list.delete;
1496 				--Insert the error message.
1497 				select wip_entity_name into l_wo_name
1498 				from wip_entities
1499 				where wip_entity_id = l_temp_wip_entity_id;
1500 
1501 				eam_execution_jsp.add_message(p_app_short_name => 'EAM',
1502 					      	p_msg_name => 'EAM_WO_CHK_DATES_ERR',
1503 						p_token1 => 'WORKORDER', p_value1 => l_wo_name);
1504 
1505 				x_msg_count := EAM_ERROR_MESSAGE_PVT.Get_Message_Count;
1506 				l_eam_return_status := FND_API.G_RET_STS_ERROR;
1507 		end if;
1508              end if;
1509               l_temp_wip_entity_id := l_eam_wo_relations_tbl(i).CHILD_OBJECT_ID;
1510              END LOOP;
1511 	    /* Added for bug#4563210 - End */
1512 
1513             if l_eam_wo_relations_tbl(i).parent_relationship_type in (1,3,4) then
1514 
1515              SAVEPOINT Add_WO_To_Network_Start;
1516 
1517          IF ( EAM_PROCESS_WO_PVT.Get_Debug = 'Y') THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_MASTER_CHILD_WO : Calling the AEAM_WO_NETWORK_DEFAULT_PVT.add_WO_To_Network ') ; END IF ;
1518 
1519               EAM_WO_NETWORK_DEFAULT_PVT.Add_WO_To_Network(
1520                 p_api_version                   => 1.0,
1521                 p_init_msg_list                 => FND_API.G_FALSE,
1522                 p_commit                        => FND_API.G_FALSE,
1523                 p_validation_level              => FND_API.G_VALID_LEVEL_FULL,
1524 
1525                 p_child_object_id               => l_eam_wo_relations_tbl(i).child_object_id,
1526                 p_child_object_type_id          => l_eam_wo_relations_tbl(i).child_object_type_id,
1527                 p_parent_object_id              => l_eam_wo_relations_tbl(i).parent_object_id,
1528                 p_parent_object_type_id         => l_eam_wo_relations_tbl(i).parent_object_type_id,
1529                 p_adjust_parent                 => l_eam_wo_relations_tbl(i).adjust_parent,
1530                 p_relationship_type             => l_eam_wo_relations_tbl(i).parent_relationship_type,
1531 
1532                 x_return_status                 => l_return_status,
1533                 x_msg_count                     => l_msg_count,
1534                 x_msg_data                      => l_msg_data,
1535                 x_mesg_token_tbl                => l_mesg_token_tbl
1536                );
1537 
1538                l_eam_wo_relations_tbl(i).return_status := l_return_status;
1539 
1540                if l_return_status <> 'S' then
1541 
1542                  l_eam_return_status := FND_API.G_RET_STS_ERROR;
1543                  x_return_status     := FND_API.G_RET_STS_ERROR;
1544 
1545                  rollback to Add_Wo_To_Network_Start;
1546 
1547                 l_out_eam_wo_rec            := l_eam_wo_rec;
1548                 l_out_eam_op_tbl            := l_eam_op_tbl;
1549                 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
1550                 l_out_eam_res_tbl           := l_eam_res_tbl;
1551                 l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
1552                 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
1553                 l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
1554                 l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
1555                 l_out_eam_di_tbl            := l_eam_di_tbl;
1556 
1557 		l_out_eam_wo_comp_rec         := l_eam_wo_comp_rec;
1558 		l_out_eam_wo_quality_tbl      := l_eam_wo_quality_tbl;
1559 		l_out_eam_meter_reading_tbl   := l_eam_meter_reading_tbl;
1560 		l_out_eam_counter_prop_tbl    := l_eam_counter_prop_tbl;
1561 		l_out_eam_wo_comp_rebuild_tbl := l_eam_wo_comp_rebuild_tbl;
1562 		l_out_eam_wo_comp_mr_read_tbl := l_eam_wo_comp_mr_read_tbl;
1563 		l_out_eam_op_comp_tbl         := l_eam_op_comp_tbl;
1564 		l_out_eam_request_tbl         := l_eam_request_tbl;
1565 
1566     EAM_ERROR_MESSAGE_PVT.Log_Error
1567         (  p_eam_wo_rec             => l_eam_wo_rec
1568         ,  p_eam_op_tbl             => l_eam_op_tbl
1569         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
1570         ,  p_eam_res_tbl            => l_eam_res_tbl
1571         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
1572         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
1573         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
1574         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
1575         ,  p_eam_direct_items_tbl   => l_eam_di_tbl
1576         ,  p_mesg_token_tbl         => l_mesg_token_tbl
1577         ,  p_error_status           => FND_API.G_RET_STS_ERROR
1578         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
1579         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
1580         ,  p_other_message          => l_other_message
1581         ,  p_other_token_tbl        => l_other_token_tbl
1582         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
1583         ,  x_eam_wo_rec             => l_out_eam_wo_rec
1584         ,  x_eam_op_tbl             => l_out_eam_op_tbl
1585         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
1586         ,  x_eam_res_tbl            => l_out_eam_res_tbl
1587         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
1588         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
1589         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
1590         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
1591         ,  x_eam_direct_items_tbl   => l_out_eam_di_tbl
1592        );
1593 
1594                 l_eam_wo_rec            := l_out_eam_wo_rec;
1595                 l_eam_op_tbl            := l_out_eam_op_tbl;
1596                 l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
1597                 l_eam_res_tbl           := l_out_eam_res_tbl;
1598                 l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
1599                 l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
1600                 l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
1601                 l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
1602                 l_eam_di_tbl            := l_out_eam_di_tbl;
1603 
1604 		l_eam_wo_comp_rec         :=  l_out_eam_wo_comp_rec;
1605 		l_eam_wo_quality_tbl      :=  l_out_eam_wo_quality_tbl;
1606 		l_eam_meter_reading_tbl   :=  l_out_eam_meter_reading_tbl;
1607 		l_eam_counter_prop_tbl    :=  l_out_eam_counter_prop_tbl;
1608 		l_eam_wo_comp_rebuild_tbl :=  l_out_eam_wo_comp_rebuild_tbl;
1609 		l_eam_wo_comp_mr_read_tbl :=  l_out_eam_wo_comp_mr_read_tbl;
1610 		l_eam_op_comp_tbl         :=  l_out_eam_op_comp_tbl;
1611 		l_eam_request_tbl         :=  l_out_eam_request_tbl;
1612 
1613 
1614                end if;
1615 
1616 
1617             elsif l_eam_wo_relations_tbl(i).parent_relationship_type = 2 then
1618 
1619               SAVEPOINT Add_Dependency_Start;
1620 
1621          IF ( EAM_PROCESS_WO_PVT.Get_Debug = 'Y') THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_MASTER_CHILD_WO : Calling the EAM_WO_NETWORK_DEFAULT_PVT.Add_Dependency') ; END IF ;
1622 
1623               EAM_WO_NETWORK_DEFAULT_PVT.Add_Dependency
1624               (
1625                 p_api_version                   => 1.0,
1626                 p_init_msg_list                 => FND_API.G_FALSE,
1627                 p_commit                        => FND_API.G_FALSE,
1628                 p_validation_level              => FND_API.G_VALID_LEVEL_FULL,
1629 
1630                 p_prior_object_id               => l_eam_wo_relations_tbl(i).parent_object_id,
1631                 p_prior_object_type_id          => l_eam_wo_relations_tbl(i).parent_object_type_id,
1632                 p_next_object_id                => l_eam_wo_relations_tbl(i).child_object_id,
1633                 p_next_object_type_id           => l_eam_wo_relations_tbl(i).child_object_type_id,
1634 
1635                 x_return_status                 => l_return_status,
1636                 x_msg_count                     => l_msg_count,
1637                 x_msg_data                      => l_msg_data,
1638                 x_mesg_token_tbl                => l_mesg_token_tbl
1639                );
1640 
1641                l_eam_wo_relations_tbl(i).return_status := l_return_status;
1642 
1643                if l_return_status <> 'S' then
1644 
1645                  l_eam_return_status := FND_API.G_RET_STS_ERROR;
1646                  x_return_status     := FND_API.G_RET_STS_ERROR;
1647 
1648 
1649                  rollback to Add_Dependency_Start;
1650 
1651                 l_out_eam_wo_rec            := l_eam_wo_rec;
1652                 l_out_eam_op_tbl            := l_eam_op_tbl;
1653                 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
1654                 l_out_eam_res_tbl           := l_eam_res_tbl;
1655                 l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
1656                 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
1657                 l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
1658                 l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
1659                 l_out_eam_di_tbl            := l_eam_di_tbl;
1660 
1661 		l_out_eam_wo_comp_rec         := l_eam_wo_comp_rec;
1662 		l_out_eam_wo_quality_tbl      := l_eam_wo_quality_tbl;
1663 		l_out_eam_meter_reading_tbl   := l_eam_meter_reading_tbl;
1664 		l_out_eam_counter_prop_tbl    := l_eam_counter_prop_tbl;
1665 		l_out_eam_wo_comp_rebuild_tbl := l_eam_wo_comp_rebuild_tbl;
1666 		l_out_eam_wo_comp_mr_read_tbl := l_eam_wo_comp_mr_read_tbl;
1667 		l_out_eam_op_comp_tbl         := l_eam_op_comp_tbl;
1668 		l_out_eam_request_tbl         := l_eam_request_tbl;
1669 
1670     EAM_ERROR_MESSAGE_PVT.Log_Error
1671         (  p_eam_wo_rec             => l_eam_wo_rec
1672         ,  p_eam_op_tbl             => l_eam_op_tbl
1673         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
1674         ,  p_eam_res_tbl            => l_eam_res_tbl
1675         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
1676         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
1677         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
1678         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
1679         ,  p_eam_direct_items_tbl   => l_eam_di_tbl
1680         ,  p_mesg_token_tbl         => l_mesg_token_tbl
1681         ,  p_error_status           => FND_API.G_RET_STS_ERROR
1682         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
1683         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
1684         ,  p_other_message          => l_other_message
1685         ,  p_other_token_tbl        => l_other_token_tbl
1686         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
1687         ,  x_eam_wo_rec             => l_out_eam_wo_rec
1688         ,  x_eam_op_tbl             => l_out_eam_op_tbl
1689         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
1690         ,  x_eam_res_tbl            => l_out_eam_res_tbl
1691         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
1692         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
1693         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
1694         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
1695         ,  x_eam_direct_items_tbl   => l_out_eam_di_tbl
1696        );
1697 
1698                 l_eam_wo_rec            := l_out_eam_wo_rec;
1699                 l_eam_op_tbl            := l_out_eam_op_tbl;
1700                 l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
1701                 l_eam_res_tbl           := l_out_eam_res_tbl;
1702                 l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
1703                 l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
1704                 l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
1705                 l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
1706                 l_eam_di_tbl            := l_out_eam_di_tbl;
1707 
1708 		l_eam_wo_comp_rec         :=  l_out_eam_wo_comp_rec;
1709 		l_eam_wo_quality_tbl      :=  l_out_eam_wo_quality_tbl;
1710 		l_eam_meter_reading_tbl   :=  l_out_eam_meter_reading_tbl;
1711 		l_eam_counter_prop_tbl    :=  l_out_eam_counter_prop_tbl;
1712 		l_eam_wo_comp_rebuild_tbl :=  l_out_eam_wo_comp_rebuild_tbl;
1713 		l_eam_wo_comp_mr_read_tbl :=  l_out_eam_wo_comp_mr_read_tbl;
1714 		l_eam_op_comp_tbl         :=  l_out_eam_op_comp_tbl;
1715 		l_eam_request_tbl         :=  l_out_eam_request_tbl;
1716 
1717                end if;
1718 
1719             end if;
1720 
1721           elsif l_eam_wo_relations_tbl(i).transaction_type =
1722             EAM_PROCESS_WO_PUB.G_OPR_DELETE then
1723 
1724             if l_eam_wo_relations_tbl(i).parent_relationship_type in (1,3,4) then
1725 
1726               SAVEPOINT Delink_Relation_Start;
1727 
1728          IF ( EAM_PROCESS_WO_PVT.Get_Debug = 'Y') THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_MASTER_CHILD_WO : Calling the Delink_Child_From_parent procedure ... ') ; END IF ;
1729 
1730               EAM_WO_NETWORK_DEFAULT_PVT.Delink_Child_From_Parent
1731               (
1732                 p_api_version                   => 1.0,
1733                 p_init_msg_list                 => FND_API.G_FALSE,
1734                 p_commit                        => FND_API.G_FALSE,
1735                 p_validation_level              => FND_API.G_VALID_LEVEL_FULL,
1736 
1737                 p_child_object_id               => l_eam_wo_relations_tbl(i).child_object_id,
1738                 p_child_object_type_id          => l_eam_wo_relations_tbl(i).child_object_type_id,
1739                 p_parent_object_id              => l_eam_wo_relations_tbl(i).parent_object_id,
1740                 p_parent_object_type_id         => l_eam_wo_relations_tbl(i).parent_object_type_id,
1741                 p_relationship_type             => l_eam_wo_relations_tbl(i).parent_relationship_type,
1742 
1743                 x_return_status                 => l_return_status,
1744                 x_msg_count                     => l_msg_count,
1745                 x_msg_data                      => l_msg_data ,
1746                 x_mesg_token_tbl                => l_mesg_token_tbl
1747               );
1748 
1749                l_eam_wo_relations_tbl(i).return_status := l_return_status;
1750 
1751 
1752 
1753                if l_return_status <> 'S' then
1754 
1755                  l_eam_return_status := FND_API.G_RET_STS_ERROR;
1756                  x_return_status     := FND_API.G_RET_STS_ERROR;
1757 
1758 
1759                  rollback to Delink_Relation_Start;
1760 
1761                 l_out_eam_wo_rec            := l_eam_wo_rec;
1762                 l_out_eam_op_tbl            := l_eam_op_tbl;
1763                 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
1764                 l_out_eam_res_tbl           := l_eam_res_tbl;
1765                 l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
1766                 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
1767                 l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
1768                 l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
1769                 l_out_eam_di_tbl            := l_eam_di_tbl;
1770 
1771 		l_out_eam_wo_comp_rec         := l_eam_wo_comp_rec;
1772 		l_out_eam_wo_quality_tbl      := l_eam_wo_quality_tbl;
1773 		l_out_eam_meter_reading_tbl   := l_eam_meter_reading_tbl;
1774 		l_out_eam_counter_prop_tbl    := l_eam_counter_prop_tbl;
1775 		l_out_eam_wo_comp_rebuild_tbl := l_eam_wo_comp_rebuild_tbl;
1776 		l_out_eam_wo_comp_mr_read_tbl := l_eam_wo_comp_mr_read_tbl;
1777 		l_out_eam_op_comp_tbl         := l_eam_op_comp_tbl;
1778 		l_out_eam_request_tbl         := l_eam_request_tbl;
1779 
1780     EAM_ERROR_MESSAGE_PVT.Log_Error
1781         (  p_eam_wo_rec             => l_eam_wo_rec
1782         ,  p_eam_op_tbl             => l_eam_op_tbl
1783         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
1784         ,  p_eam_res_tbl            => l_eam_res_tbl
1785         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
1786         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
1787         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
1788         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
1789         ,  p_eam_direct_items_tbl   => l_eam_di_tbl
1790         ,  p_mesg_token_tbl         => l_mesg_token_tbl
1791         ,  p_error_status           => FND_API.G_RET_STS_ERROR
1792         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
1793         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
1794         ,  p_other_message          => l_other_message
1795         ,  p_other_token_tbl        => l_other_token_tbl
1796         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
1797         ,  x_eam_wo_rec             => l_out_eam_wo_rec
1798         ,  x_eam_op_tbl             => l_out_eam_op_tbl
1799         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
1800         ,  x_eam_res_tbl            => l_out_eam_res_tbl
1801         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
1802         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
1803         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
1804         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
1805         ,  x_eam_direct_items_tbl   => l_out_eam_di_tbl
1806        );
1807 
1808                 l_eam_wo_rec            := l_out_eam_wo_rec;
1809                 l_eam_op_tbl            := l_out_eam_op_tbl;
1810                 l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
1811                 l_eam_res_tbl           := l_out_eam_res_tbl;
1812                 l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
1813                 l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
1814                 l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
1815                 l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
1816                 l_eam_di_tbl            := l_out_eam_di_tbl;
1817 
1818 		l_eam_wo_comp_rec         :=  l_out_eam_wo_comp_rec;
1819 		l_eam_wo_quality_tbl      :=  l_out_eam_wo_quality_tbl;
1820 		l_eam_meter_reading_tbl   :=  l_out_eam_meter_reading_tbl;
1821 		l_eam_counter_prop_tbl    :=  l_out_eam_counter_prop_tbl;
1822 		l_eam_wo_comp_rebuild_tbl :=  l_out_eam_wo_comp_rebuild_tbl;
1823 		l_eam_wo_comp_mr_read_tbl :=  l_out_eam_wo_comp_mr_read_tbl;
1824 		l_eam_op_comp_tbl         :=  l_out_eam_op_comp_tbl;
1825 		l_eam_request_tbl         :=  l_out_eam_request_tbl;
1826 
1827                end if;
1828 
1829 
1830             elsif l_eam_wo_relations_tbl(i).parent_relationship_type = 2 then
1831 
1832               SAVEPOINT Delete_Dependency_Start;
1833          IF ( EAM_PROCESS_WO_PVT.Get_Debug = 'Y') THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_MASTER_CHILD_WO : Calling the Delete_Dependency procedure ... ') ; END IF ;
1834 
1835               EAM_WO_NETWORK_DEFAULT_PVT.Delete_Dependency
1836               (
1837                 p_api_version                   => 1.0,
1838                 p_init_msg_list                 => FND_API.G_FALSE,
1839                 p_commit                        => FND_API.G_FALSE,
1840                 p_validation_level              => FND_API.G_VALID_LEVEL_FULL,
1841 
1842                 p_prior_object_id               => l_eam_wo_relations_tbl(i).parent_object_id,
1843                 p_prior_object_type_id          => l_eam_wo_relations_tbl(i).parent_object_type_id,
1844                 p_next_object_id                => l_eam_wo_relations_tbl(i).child_object_id,
1845                 p_next_object_type_id           => l_eam_wo_relations_tbl(i).child_object_type_id,
1846 
1847                 x_return_status                 => l_return_status,
1848                 x_msg_count                     => l_msg_count,
1849                 x_msg_data                      => l_msg_data,
1850                 x_mesg_token_tbl                => l_mesg_token_tbl
1851               );
1852 
1853                l_eam_wo_relations_tbl(i).return_status := l_return_status;
1854 
1855 
1856 
1857                if l_return_status <> 'S' then
1858 
1859                  l_eam_return_status := FND_API.G_RET_STS_ERROR;
1860                  x_return_status     := FND_API.G_RET_STS_ERROR;
1861 
1862 
1863                  rollback to Delete_Dependency_Start;
1864 
1865 
1866                 l_out_eam_wo_rec            := l_eam_wo_rec;
1867                 l_out_eam_op_tbl            := l_eam_op_tbl;
1868                 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
1869                 l_out_eam_res_tbl           := l_eam_res_tbl;
1870                 l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
1871                 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
1872                 l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
1873                 l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
1874                 l_out_eam_di_tbl            := l_eam_di_tbl;
1875 
1876 		l_out_eam_wo_comp_rec         := l_eam_wo_comp_rec;
1877 		l_out_eam_wo_quality_tbl      := l_eam_wo_quality_tbl;
1878 		l_out_eam_meter_reading_tbl   := l_eam_meter_reading_tbl;
1879 		l_out_eam_counter_prop_tbl    := l_eam_counter_prop_tbl;
1880 		l_out_eam_wo_comp_rebuild_tbl := l_eam_wo_comp_rebuild_tbl;
1881 		l_out_eam_wo_comp_mr_read_tbl := l_eam_wo_comp_mr_read_tbl;
1882 		l_out_eam_op_comp_tbl         := l_eam_op_comp_tbl;
1883 		l_out_eam_request_tbl         := l_eam_request_tbl;
1884 
1885     EAM_ERROR_MESSAGE_PVT.Log_Error
1886         (  p_eam_wo_rec             => l_eam_wo_rec
1887         ,  p_eam_op_tbl             => l_eam_op_tbl
1888         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
1889         ,  p_eam_res_tbl            => l_eam_res_tbl
1890         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
1891         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
1892         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
1893         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
1894         ,  p_eam_direct_items_tbl   => l_eam_di_tbl
1895         ,  p_mesg_token_tbl         => l_mesg_token_tbl
1896         ,  p_error_status           => FND_API.G_RET_STS_ERROR
1897         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
1898         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
1899         ,  p_other_message          => l_other_message
1900         ,  p_other_token_tbl        => l_other_token_tbl
1901         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
1902         ,  x_eam_wo_rec             => l_out_eam_wo_rec
1903         ,  x_eam_op_tbl             => l_out_eam_op_tbl
1904         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
1905         ,  x_eam_res_tbl            => l_out_eam_res_tbl
1906         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
1907         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
1908         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
1909         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
1910         ,  x_eam_direct_items_tbl   => l_out_eam_di_tbl
1911        );
1912 
1913                 l_eam_wo_rec            := l_out_eam_wo_rec;
1914                 l_eam_op_tbl            := l_out_eam_op_tbl;
1915                 l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
1916                 l_eam_res_tbl           := l_out_eam_res_tbl;
1917                 l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
1918                 l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
1919                 l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
1920                 l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
1921                 l_eam_di_tbl            := l_out_eam_di_tbl;
1922 
1923 		l_eam_wo_comp_rec         :=  l_out_eam_wo_comp_rec;
1924 		l_eam_wo_quality_tbl      :=  l_out_eam_wo_quality_tbl;
1925 		l_eam_meter_reading_tbl   :=  l_out_eam_meter_reading_tbl;
1926 		l_eam_counter_prop_tbl    :=  l_out_eam_counter_prop_tbl;
1927 		l_eam_wo_comp_rebuild_tbl :=  l_out_eam_wo_comp_rebuild_tbl;
1928 		l_eam_wo_comp_mr_read_tbl :=  l_out_eam_wo_comp_mr_read_tbl;
1929 		l_eam_op_comp_tbl         :=  l_out_eam_op_comp_tbl;
1930 		l_eam_request_tbl         :=  l_out_eam_request_tbl;
1931 
1932                end if;
1933 
1934 
1935             end if;
1936 
1937           end if;
1938 
1939           end if;
1940 
1941         end loop;
1942         end if;
1943 
1944 
1945         -- If there were any work orders processed, then
1946         -- Call Validate Structure. If it returns error, then rollback everything
1947 
1948         IF l_eam_wo_tbl.count <> 0  and l_eam_wo_tbl(l_eam_wo_tbl.first).validate_structure = 'Y' then -- added for bug# 3544860
1949 
1950          IF ( EAM_PROCESS_WO_PVT.Get_Debug = 'Y') THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_MASTER_CHILD_WO : Calling the Validate_Structure procedure ... ') ; END IF ;
1951 
1952     EAM_WO_NETWORK_VALIDATE_PVT.Validate_Structure
1953         (
1954         p_api_version                   => 1.0,
1955         p_init_msg_list                 => FND_API.G_FALSE,
1956         p_commit                        => FND_API.G_FALSE,
1957         p_validation_level              => FND_API.G_VALID_LEVEL_FULL,
1958 
1959         p_work_object_id                => l_eam_wo_tbl(l_eam_wo_tbl.first).wip_entity_id,
1960         p_work_object_type_id           => 1,
1961         p_exception_logging             => 'Y',
1962 
1963     	p_validate_status	        => 'N',
1964 	p_output_errors			=> 'N',
1965 
1966         x_return_status                 => l_return_status,
1967         x_msg_count                     => l_msg_count,
1968         x_msg_data                      => l_msg_data,
1969 	x_wo_relationship_exc_tbl	=> l_wo_relationship_exc_tbl
1970         );
1971 
1972 
1973     IF l_return_status = FND_API.G_RET_STS_ERROR OR
1974        l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1975 
1976 	x_return_status     := l_return_status; -- added for bug# 3544860
1977 
1978     l_out_mesg_token_tbl  := l_mesg_token_tbl;
1979     EAM_ERROR_MESSAGE_PVT.Add_Error_Token
1980       (  p_message_name  => 'EAM_WN_MAIN_VALIDATE_STRUCT'
1981        , p_token_tbl     => l_token_tbl
1982        , p_mesg_token_tbl     => l_mesg_token_tbl
1983        , x_mesg_token_tbl     => l_out_mesg_token_tbl
1984     );
1985     l_mesg_token_tbl      := l_out_mesg_token_tbl;
1986 
1987                 l_out_eam_wo_rec            := l_eam_wo_rec;
1988                 l_out_eam_op_tbl            := l_eam_op_tbl;
1989                 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
1990                 l_out_eam_res_tbl           := l_eam_res_tbl;
1991                 l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
1992                 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
1993                 l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
1994                 l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
1995                 l_out_eam_di_tbl            := l_eam_di_tbl;
1996 
1997 		l_out_eam_wo_comp_rec         := l_eam_wo_comp_rec;
1998 		l_out_eam_wo_quality_tbl      := l_eam_wo_quality_tbl;
1999 		l_out_eam_meter_reading_tbl   := l_eam_meter_reading_tbl;
2000 		l_out_eam_counter_prop_tbl    := l_eam_counter_prop_tbl;
2001 		l_out_eam_wo_comp_rebuild_tbl := l_eam_wo_comp_rebuild_tbl;
2002 		l_out_eam_wo_comp_mr_read_tbl := l_eam_wo_comp_mr_read_tbl;
2003 		l_out_eam_op_comp_tbl         := l_eam_op_comp_tbl;
2004 		l_out_eam_request_tbl         := l_eam_request_tbl;
2005 
2006 
2007     EAM_ERROR_MESSAGE_PVT.Log_Error
2008         (  p_eam_wo_rec             => l_eam_wo_rec
2009         ,  p_eam_op_tbl             => l_eam_op_tbl
2010         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
2011         ,  p_eam_res_tbl            => l_eam_res_tbl
2012         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
2013         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
2014         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
2015         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
2016         ,  p_eam_direct_items_tbl   => l_eam_di_tbl
2017         ,  p_mesg_token_tbl         => l_mesg_token_tbl
2018         ,  p_error_status           => FND_API.G_RET_STS_ERROR
2019         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
2020         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
2021         ,  p_other_message          => l_other_message
2022         ,  p_other_token_tbl        => l_other_token_tbl
2023         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
2024         ,  x_eam_wo_rec             => l_out_eam_wo_rec
2025         ,  x_eam_op_tbl             => l_out_eam_op_tbl
2026         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
2027         ,  x_eam_res_tbl            => l_out_eam_res_tbl
2028         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
2029         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
2030         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
2031         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
2032         ,  x_eam_direct_items_tbl   => l_out_eam_di_tbl
2033        );
2034 
2035                 l_eam_wo_rec            := l_out_eam_wo_rec;
2036                 l_eam_op_tbl            := l_out_eam_op_tbl;
2037                 l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
2038                 l_eam_res_tbl           := l_out_eam_res_tbl;
2039                 l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
2040                 l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
2041                 l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
2042                 l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
2043                 l_eam_di_tbl            := l_out_eam_di_tbl;
2044 
2045 		l_eam_wo_comp_rec         :=  l_out_eam_wo_comp_rec;
2046 		l_eam_wo_quality_tbl      :=  l_out_eam_wo_quality_tbl;
2047 		l_eam_meter_reading_tbl   :=  l_out_eam_meter_reading_tbl;
2048 		l_eam_counter_prop_tbl    :=  l_out_eam_counter_prop_tbl;
2049 		l_eam_wo_comp_rebuild_tbl :=  l_out_eam_wo_comp_rebuild_tbl;
2050 		l_eam_wo_comp_mr_read_tbl :=  l_out_eam_wo_comp_mr_read_tbl;
2051 		l_eam_op_comp_tbl         :=  l_out_eam_op_comp_tbl;
2052 		l_eam_request_tbl         :=  l_out_eam_request_tbl;
2053 
2054       ROLLBACK TO EAM_PR_MASTER_CHILD_WO;
2055 
2056     END IF;
2057 
2058         END IF;
2059 	-- end of fix for bug# 3544860
2060 
2061         x_eam_wo_tbl.delete;
2062         x_eam_wo_relations_tbl.delete;
2063         x_eam_op_tbl.delete;
2064         x_eam_op_network_tbl.delete;
2065         x_eam_res_tbl.delete;
2066         x_eam_res_inst_tbl.delete;
2067         x_eam_sub_res_tbl.delete;
2068         x_eam_mat_req_tbl.delete;
2069         x_eam_direct_items_tbl.delete;
2070 	x_eam_res_usage_tbl.delete;
2071 
2072 	 x_eam_res_usage_tbl.delete;
2073 	 x_eam_wo_comp_tbl.delete;
2074 	 x_eam_wo_quality_tbl.delete;
2075 	 x_eam_meter_reading_tbl.delete;
2076 	 x_eam_counter_prop_tbl.delete;
2077 	 x_eam_wo_comp_rebuild_tbl.delete;
2078 	 x_eam_wo_comp_mr_read_tbl.delete;
2079 	 x_eam_op_comp_tbl.delete;
2080 	 x_eam_request_tbl.delete;
2081 
2082 	x_eam_wo_tbl              := l_eam_wo_tbl;
2083         x_eam_wo_relations_tbl    := l_eam_wo_relations_tbl;
2084         x_eam_op_tbl              := l_eam_op_tbl;
2085         x_eam_op_network_tbl      := l_eam_op_network_tbl;
2086         x_eam_res_tbl             := l_eam_res_tbl;
2087         x_eam_res_inst_tbl        := l_eam_res_inst_tbl;
2088         x_eam_sub_res_tbl         := l_eam_sub_res_tbl;
2089         x_eam_mat_req_tbl         := l_eam_mat_req_tbl;
2090         x_eam_direct_items_tbl    := l_eam_di_tbl;
2091 
2092 	 x_eam_res_usage_tbl		:= l_eam_res_usage_tbl;
2093 	 x_eam_wo_comp_tbl		:= l_eam_wo_comp_tbl;
2094 	 x_eam_wo_quality_tbl		:= l_eam_wo_quality_tbl;
2095 	 x_eam_meter_reading_tbl	:= l_eam_meter_reading_tbl;
2096 	 x_eam_counter_prop_tbl		:= l_eam_counter_prop_tbl;
2097 	 x_eam_wo_comp_rebuild_tbl	:= l_eam_wo_comp_rebuild_tbl;
2098 	 x_eam_wo_comp_mr_read_tbl	:= l_eam_wo_comp_mr_read_tbl;
2099 	 x_eam_op_comp_tbl		:= l_eam_op_comp_tbl;
2100 	 x_eam_request_tbl		:= l_eam_request_tbl;
2101 
2102         if nvl(l_eam_return_status,FND_API.G_RET_STS_ERROR) <> FND_API.G_RET_STS_SUCCESS then
2103           x_return_status := FND_API.G_RET_STS_ERROR;
2104         end if;
2105 
2106         x_msg_count := EAM_ERROR_MESSAGE_PVT.Get_Message_Count;
2107 
2108         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y'
2109         THEN
2110             EAM_ERROR_MESSAGE_PVT.Dump_Message_List;
2111             EAM_ERROR_MESSAGE_PVT.Close_Debug_Session;
2112         END IF;
2113 
2114         -- Standard check of p_commit.
2115         IF p_commit = 'Y' THEN
2116                 COMMIT WORK;
2117         END IF;
2118 
2119          IF ( EAM_PROCESS_WO_PVT.Get_Debug = 'Y') THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_MASTER_CHILD_WO : End ==================================================== ') ; END IF ;
2120 
2121         EXCEPTION
2122 
2123           WHEN OTHERS THEN
2124 
2125         x_msg_count := EAM_ERROR_MESSAGE_PVT.Get_Message_Count;
2126 
2127       EAM_ERROR_MESSAGE_PVT.Add_Error_Token
2128         (  p_message_name  => 'EAM_WN_UNKNOWN_ERROR'
2129          , p_token_tbl     => l_token_tbl
2130          , p_mesg_token_tbl     => l_mesg_token_tbl
2131          , x_mesg_token_tbl     => l_out_mesg_token_tbl
2132       );
2133       l_mesg_token_tbl := l_out_mesg_token_tbl;
2134 
2135                 l_out_eam_wo_rec            := l_eam_wo_rec;
2136                 l_out_eam_op_tbl            := l_eam_op_tbl;
2137                 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
2138                 l_out_eam_res_tbl           := l_eam_res_tbl;
2139                 l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
2140                 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
2141                 l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
2142                 l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
2143                 l_out_eam_di_tbl            := l_eam_di_tbl;
2144 
2145 		l_out_eam_wo_comp_rec         := l_eam_wo_comp_rec;
2146 		l_out_eam_wo_quality_tbl      := l_eam_wo_quality_tbl;
2147 		l_out_eam_meter_reading_tbl   := l_eam_meter_reading_tbl;
2148 		l_out_eam_counter_prop_tbl    := l_eam_counter_prop_tbl;
2149 		l_out_eam_wo_comp_rebuild_tbl := l_eam_wo_comp_rebuild_tbl;
2150 		l_out_eam_wo_comp_mr_read_tbl := l_eam_wo_comp_mr_read_tbl;
2151 		l_out_eam_op_comp_tbl         := l_eam_op_comp_tbl;
2152 		l_out_eam_request_tbl         := l_eam_request_tbl;
2153 
2154 
2155                EAM_ERROR_MESSAGE_PVT.Log_Error
2156         (  p_eam_wo_rec             => l_eam_wo_rec
2157         ,  p_eam_op_tbl             => l_eam_op_tbl
2158         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
2159         ,  p_eam_res_tbl            => l_eam_res_tbl
2160         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
2161         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
2162         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
2163         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
2164         ,  p_eam_direct_items_tbl   => l_eam_di_tbl
2165         ,  p_mesg_token_tbl         => l_mesg_token_tbl
2166         ,  p_error_status           => FND_API.G_RET_STS_ERROR
2167         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
2168         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
2169         ,  p_other_message          => l_other_message
2170         ,  p_other_token_tbl        => l_other_token_tbl
2171         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
2172         ,  x_eam_wo_rec             => l_out_eam_wo_rec
2173         ,  x_eam_op_tbl             => l_out_eam_op_tbl
2174         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
2175         ,  x_eam_res_tbl            => l_out_eam_res_tbl
2176         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
2177         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
2178         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
2179         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
2180         ,  x_eam_direct_items_tbl   => l_out_eam_di_tbl
2181        );
2182 
2183                 l_eam_wo_rec            := l_out_eam_wo_rec;
2184                 l_eam_op_tbl            := l_out_eam_op_tbl;
2185                 l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
2186                 l_eam_res_tbl           := l_out_eam_res_tbl;
2187                 l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
2188                 l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
2189                 l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
2190                 l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
2191                 l_eam_di_tbl            := l_out_eam_di_tbl;
2192 
2193 		l_eam_wo_comp_rec         :=  l_out_eam_wo_comp_rec;
2194 		l_eam_wo_quality_tbl      :=  l_out_eam_wo_quality_tbl;
2195 		l_eam_meter_reading_tbl   :=  l_out_eam_meter_reading_tbl;
2196 		l_eam_counter_prop_tbl    :=  l_out_eam_counter_prop_tbl;
2197 		l_eam_wo_comp_rebuild_tbl :=  l_out_eam_wo_comp_rebuild_tbl;
2198 		l_eam_wo_comp_mr_read_tbl :=  l_out_eam_wo_comp_mr_read_tbl;
2199 		l_eam_op_comp_tbl         :=  l_out_eam_op_comp_tbl;
2200 		l_eam_request_tbl         :=  l_out_eam_request_tbl;
2201 
2202         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y'
2203         THEN
2204             EAM_ERROR_MESSAGE_PVT.Dump_Message_List;
2205             EAM_ERROR_MESSAGE_PVT.Close_Debug_Session;
2206         END IF;
2207 
2208 
2209      END PROCESS_MASTER_CHILD_WO;
2210 
2211 
2212 
2213 
2214 
2215 
2216 
2217 
2218 
2219 
2220         -- This procedure loops through all the input records and finds
2221         -- out the list of headers that the user has passed
2222 
2223         PROCEDURE CHECK_BO_NETWORK
2224         ( p_eam_wo_tbl              IN  EAM_PROCESS_WO_PUB.eam_wo_tbl_type
2225         , p_eam_wo_relations_tbl    IN  EAM_PROCESS_WO_PUB.eam_wo_relations_tbl_type
2226         , p_eam_op_tbl              IN  EAM_PROCESS_WO_PUB.eam_op_tbl_type
2227         , p_eam_op_network_tbl      IN  EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
2228         , p_eam_res_tbl             IN  EAM_PROCESS_WO_PUB.eam_res_tbl_type
2229         , p_eam_res_inst_tbl        IN  EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
2230         , p_eam_sub_res_tbl         IN  EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
2231         , p_eam_mat_req_tbl         IN  EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
2232         , p_eam_direct_items_tbl    IN  EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
2233         , p_eam_res_usage_tbl       IN  EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
2234 	, p_eam_wo_comp_tbl         IN  EAM_PROCESS_WO_PUB.eam_wo_comp_tbl_type
2235         , p_eam_wo_quality_tbl      IN  EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type
2236         , p_eam_meter_reading_tbl   IN  EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type
2237         , p_eam_counter_prop_tbl    IN  EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type
2238         , p_eam_wo_comp_rebuild_tbl IN  EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type
2239         , p_eam_wo_comp_mr_read_tbl IN  EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type
2240         , p_eam_op_comp_tbl         IN  EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type
2241 	, p_eam_request_tbl         IN  EAM_PROCESS_WO_PUB.eam_request_tbl_type
2242         , x_eam_wo_tbl              OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_tbl_type
2243         , x_eam_wo_relations_tbl    OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_relations_tbl_type
2244         , x_eam_op_tbl              OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_op_tbl_type
2245         , x_eam_op_network_tbl      OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
2246         , x_eam_res_tbl             OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_res_tbl_type
2247         , x_eam_res_inst_tbl        OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
2248         , x_eam_sub_res_tbl         OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
2249         , x_eam_mat_req_tbl         OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
2250         , x_eam_direct_items_tbl    OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
2251         , x_eam_res_usage_tbl       OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
2252 	, x_eam_wo_comp_tbl         OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_comp_tbl_type
2253         , x_eam_wo_quality_tbl      OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type
2254         , x_eam_meter_reading_tbl   OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type
2255         , x_eam_counter_prop_tbl    OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type
2256         , x_eam_wo_comp_rebuild_tbl OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type
2257         , x_eam_wo_comp_mr_read_tbl OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type
2258         , x_eam_op_comp_tbl         OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type
2259 	, x_eam_request_tbl         OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_request_tbl_type
2260         , x_batch_id                OUT NOCOPY NUMBER
2261         , x_header_id_tbl           OUT NOCOPY EAM_PROCESS_WO_PUB.header_id_tbl_type
2262         , x_return_status           OUT NOCOPY VARCHAR2
2263         ) IS
2264           l_batch_id                NUMBER;
2265           l_header_id_tbl           EAM_PROCESS_WO_PUB.header_id_tbl_type;
2266           l_count                   NUMBER;
2267           l_header_id               NUMBER;
2268           l_found                   VARCHAR2(1) := FND_API.G_FALSE;
2269           l_return_status           VARCHAR2(1);
2270 
2271           l_eam_wo_tbl              EAM_PROCESS_WO_PUB.eam_wo_tbl_type
2272                                     := p_eam_wo_tbl;
2273           l_eam_wo_relations_tbl    EAM_PROCESS_WO_PUB.eam_wo_relations_tbl_type
2274                                     := p_eam_wo_relations_tbl;
2275           l_eam_op_tbl              EAM_PROCESS_WO_PUB.eam_op_tbl_type
2276                                     := p_eam_op_tbl;
2277           l_eam_op_network_tbl      EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
2278                                     := p_eam_op_network_tbl;
2279           l_eam_res_tbl             EAM_PROCESS_WO_PUB.eam_res_tbl_type
2280                                     := p_eam_res_tbl;
2281           l_eam_res_inst_tbl        EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
2282                                     := p_eam_res_inst_tbl;
2283           l_eam_sub_res_tbl         EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
2284                                     := p_eam_sub_res_tbl;
2285           l_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
2286                                    := p_eam_res_usage_tbl;
2287           l_eam_mat_req_tbl         EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
2288                                     := p_eam_mat_req_tbl;
2289           l_eam_direct_items_tbl    EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
2290                                     := p_eam_direct_items_tbl;
2291 
2292 	l_eam_wo_comp_tbl         EAM_PROCESS_WO_PUB.eam_wo_comp_tbl_type
2293 					:= p_eam_wo_comp_tbl;
2294 	l_eam_wo_quality_tbl      EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type
2295 					:= p_eam_wo_quality_tbl;
2296 	l_eam_meter_reading_tbl   EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type
2297 					:= p_eam_meter_reading_tbl;
2298 	l_eam_counter_prop_tbl    EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type
2299 					:= p_eam_counter_prop_tbl;
2300 	l_eam_wo_comp_rebuild_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type
2301 					:= p_eam_wo_comp_rebuild_tbl;
2302 	l_eam_wo_comp_mr_read_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type
2303 					:= p_eam_wo_comp_mr_read_tbl;
2304 	l_eam_op_comp_tbl         EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type
2305 					:= p_eam_op_comp_tbl;
2306 	l_eam_request_tbl         EAM_PROCESS_WO_PUB.eam_request_tbl_type
2307 					:= p_eam_request_tbl;
2308 
2309         BEGIN
2310 
2311           l_return_status := FND_API.G_RET_STS_SUCCESS;
2312 
2313           l_batch_id := null;
2314 
2315           if l_eam_wo_tbl.count > 0 then
2316           FOR i in l_eam_wo_tbl.first..l_eam_wo_tbl.last LOOP
2317             IF l_eam_wo_tbl(i).batch_id is null or l_eam_wo_tbl(i).header_id is null then
2318               l_return_status := FND_API.G_RET_STS_ERROR;
2319               return;
2320             END IF;
2321             l_eam_wo_tbl(i).row_id := i;
2322             IF l_batch_id = null THEN
2323               l_batch_id := l_eam_wo_tbl(i).batch_id;
2324             ELSIF l_batch_id <> l_eam_wo_tbl(i).batch_id THEN
2325               l_return_status := FND_API.G_RET_STS_ERROR;
2326             END IF;
2327             l_header_id := l_eam_wo_tbl(i).header_id;
2328             l_found := FND_API.G_FALSE;
2329             if l_header_id_tbl.count > 0 then
2330             for j in l_header_id_tbl.first..l_header_id_tbl.last loop
2331               if l_header_id = l_header_id_tbl(j).header_id then
2332                 l_found := FND_API.G_TRUE;
2333               end if;
2334             end loop;
2335             end if;
2336             if l_found = FND_API.G_FALSE then
2337               l_header_id_tbl(l_header_id_tbl.count+1).header_id := l_header_id;
2338             end if;
2339           END LOOP;
2340           end if;
2341 
2342 
2343           if l_eam_op_tbl.count > 0 then
2344           FOR i in l_eam_op_tbl.first..l_eam_op_tbl.last LOOP
2345             IF l_eam_op_tbl(i).batch_id is null or l_eam_op_tbl(i).header_id is null then
2346               l_return_status := FND_API.G_RET_STS_ERROR;
2347               return;
2348             END IF;
2349             l_eam_op_tbl(i).row_id := i;
2350             IF l_batch_id = null THEN
2351               l_batch_id := l_eam_op_tbl(i).batch_id;
2352             ELSIF l_batch_id <> l_eam_op_tbl(i).batch_id THEN
2353               l_return_status := FND_API.G_RET_STS_ERROR;
2354             END IF;
2355             l_header_id := l_eam_op_tbl(i).header_id;
2356             l_found := FND_API.G_FALSE;
2357             if l_header_id_tbl.count > 0 then
2358             for j in l_header_id_tbl.first..l_header_id_tbl.last loop
2359               if l_header_id = l_header_id_tbl(j).header_id then
2360                 l_found := FND_API.G_TRUE;
2361               end if;
2362             end loop;
2363             end if;
2364             if l_found = FND_API.G_FALSE then
2365               l_header_id_tbl(l_header_id_tbl.count+1).header_id := l_header_id;
2366             end if;
2367           END LOOP;
2368           end if;
2369 
2370 
2371           if l_eam_op_network_tbl.count > 0 then
2372           FOR i in l_eam_op_network_tbl.first..l_eam_op_network_tbl.last LOOP
2373             IF l_eam_op_network_tbl(i).batch_id is null or l_eam_op_network_tbl(i).header_id is null then
2374               l_return_status := FND_API.G_RET_STS_ERROR;
2375               return;
2376             END IF;
2377             l_eam_op_network_tbl(i).row_id := i;
2378             IF l_batch_id = null THEN
2379               l_batch_id := l_eam_op_network_tbl(i).batch_id;
2380             ELSIF l_batch_id <> l_eam_op_network_tbl(i).batch_id THEN
2381               l_return_status := FND_API.G_RET_STS_ERROR;
2382             END IF;
2383             l_header_id := l_eam_op_network_tbl(i).header_id;
2384             l_found := FND_API.G_FALSE;
2385             if l_header_id_tbl.count > 0 then
2386             for j in l_header_id_tbl.first..l_header_id_tbl.last loop
2387               if l_header_id = l_header_id_tbl(j).header_id then
2388                 l_found := FND_API.G_TRUE;
2389               end if;
2390             end loop;
2391             end if;
2392             if l_found = FND_API.G_FALSE then
2393               l_header_id_tbl(l_header_id_tbl.count+1).header_id := l_header_id;
2394             end if;
2395           END LOOP;
2396           end if;
2397 
2398           if l_eam_res_tbl.count > 0 then
2399           FOR i in l_eam_res_tbl.first..l_eam_res_tbl.last LOOP
2400             IF l_eam_res_tbl(i).batch_id is null or l_eam_res_tbl(i).header_id is null then
2401               l_return_status := FND_API.G_RET_STS_ERROR;
2402               return;
2403             END IF;
2404             l_eam_res_tbl(i).row_id := i;
2405             IF l_batch_id = null THEN
2406               l_batch_id := l_eam_res_tbl(i).batch_id;
2407             ELSIF l_batch_id <> l_eam_res_tbl(i).batch_id THEN
2408               l_return_status := FND_API.G_RET_STS_ERROR;
2409             END IF;
2410             l_header_id := l_eam_res_tbl(i).header_id;
2411             l_found := FND_API.G_FALSE;
2412             if l_header_id_tbl.count > 0 then
2413             for j in l_header_id_tbl.first..l_header_id_tbl.last loop
2414               if l_header_id = l_header_id_tbl(j).header_id then
2415                 l_found := FND_API.G_TRUE;
2416               end if;
2417             end loop;
2418             end if;
2419             if l_found = FND_API.G_FALSE then
2420               l_header_id_tbl(l_header_id_tbl.count+1).header_id := l_header_id;
2421             end if;
2422           END LOOP;
2423           end if;
2424 
2425 	  if l_eam_res_inst_tbl.count > 0 then
2426           FOR i in l_eam_res_inst_tbl.first..l_eam_res_inst_tbl.last LOOP
2427             IF l_eam_res_inst_tbl(i).batch_id is null or l_eam_res_inst_tbl(i).header_id is null then
2428               l_return_status := FND_API.G_RET_STS_ERROR;
2429               return;
2430             END IF;
2431             l_eam_res_inst_tbl(i).row_id := i;
2432             IF l_batch_id = null THEN
2433               l_batch_id := l_eam_res_inst_tbl(i).batch_id;
2434             ELSIF l_batch_id <> l_eam_res_inst_tbl(i).batch_id THEN
2435               l_return_status := FND_API.G_RET_STS_ERROR;
2436             END IF;
2437             l_header_id := l_eam_res_inst_tbl(i).header_id;
2438             l_found := FND_API.G_FALSE;
2439             if l_header_id_tbl.count > 0 then
2440             for j in l_header_id_tbl.first..l_header_id_tbl.last loop
2441               if l_header_id = l_header_id_tbl(j).header_id then
2442                 l_found := FND_API.G_TRUE;
2443               end if;
2444             end loop;
2445             end if;
2446             if l_found = FND_API.G_FALSE then
2447               l_header_id_tbl(l_header_id_tbl.count+1).header_id := l_header_id;
2448             end if;
2449           END LOOP;
2450           end if;
2451 
2452           if l_eam_sub_res_tbl.count > 0 then
2453           FOR i in l_eam_sub_res_tbl.first..l_eam_sub_res_tbl.last LOOP
2454             IF l_eam_sub_res_tbl(i).batch_id is null or l_eam_sub_res_tbl(i).header_id is null then
2455               l_return_status := FND_API.G_RET_STS_ERROR;
2456               return;
2457             END IF;
2458             l_eam_sub_res_tbl(i).row_id := i;
2459             IF l_batch_id = null THEN
2460               l_batch_id := l_eam_sub_res_tbl(i).batch_id;
2461             ELSIF l_batch_id <> l_eam_sub_res_tbl(i).batch_id THEN
2462               l_return_status := FND_API.G_RET_STS_ERROR;
2463             END IF;
2464             l_header_id := l_eam_sub_res_tbl(i).header_id;
2465             l_found := FND_API.G_FALSE;
2466             if l_header_id_tbl.count > 0 then
2467             for j in l_header_id_tbl.first..l_header_id_tbl.last loop
2468               if l_header_id = l_header_id_tbl(j).header_id then
2469                 l_found := FND_API.G_TRUE;
2470               end if;
2471             end loop;
2472             end if;
2473             if l_found = FND_API.G_FALSE then
2474               l_header_id_tbl(l_header_id_tbl.count+1).header_id := l_header_id;
2475             end if;
2476           END LOOP;
2477           end if;
2478 
2479 	 if l_eam_res_usage_tbl.count > 0 then
2480           FOR i in l_eam_res_usage_tbl.first..l_eam_res_usage_tbl.last LOOP
2481             IF l_eam_res_usage_tbl(i).batch_id is null or l_eam_res_usage_tbl(i).header_id is null then
2482               l_return_status := FND_API.G_RET_STS_ERROR;
2483               return;
2484             END IF;
2485             l_eam_res_usage_tbl(i).row_id := i;
2486             IF l_batch_id = null THEN
2487               l_batch_id := l_eam_res_usage_tbl(i).batch_id;
2488             ELSIF l_batch_id <> l_eam_res_usage_tbl(i).batch_id THEN
2489               l_return_status := FND_API.G_RET_STS_ERROR;
2490             END IF;
2491             l_header_id := l_eam_res_usage_tbl(i).header_id;
2492             l_found := FND_API.G_FALSE;
2493             if l_header_id_tbl.count > 0 then
2494             for j in l_header_id_tbl.first..l_header_id_tbl.last loop
2495               if l_header_id = l_header_id_tbl(j).header_id then
2496                 l_found := FND_API.G_TRUE;
2497               end if;
2498             end loop;
2499             end if;
2500             if l_found = FND_API.G_FALSE then
2501               l_header_id_tbl(l_header_id_tbl.count+1).header_id := l_header_id;
2502             end if;
2503           END LOOP;
2504           end if;
2505 
2506           if l_eam_mat_req_tbl.count > 0 then
2507           FOR i in l_eam_mat_req_tbl.first..l_eam_mat_req_tbl.last LOOP
2508             IF l_eam_mat_req_tbl(i).batch_id is null or l_eam_mat_req_tbl(i).header_id is null then
2509               l_return_status := FND_API.G_RET_STS_ERROR;
2510               return;
2511             END IF;
2512             l_eam_mat_req_tbl(i).row_id := i;
2513             IF l_batch_id = null THEN
2514               l_batch_id := l_eam_mat_req_tbl(i).batch_id;
2515             ELSIF l_batch_id <> l_eam_mat_req_tbl(i).batch_id THEN
2516               l_return_status := FND_API.G_RET_STS_ERROR;
2517             END IF;
2518             l_header_id := l_eam_mat_req_tbl(i).header_id;
2519             l_found := FND_API.G_FALSE;
2520             if l_header_id_tbl.count > 0 then
2521             for j in l_header_id_tbl.first..l_header_id_tbl.last loop
2522               if l_header_id = l_header_id_tbl(j).header_id then
2523                 l_found := FND_API.G_TRUE;
2524               end if;
2525             end loop;
2526             end if;
2527             if l_found = FND_API.G_FALSE then
2528               l_header_id_tbl(l_header_id_tbl.count+1).header_id := l_header_id;
2529             end if;
2530           END LOOP;
2531           end if;
2532 
2533           if l_eam_direct_items_tbl.count > 0 then
2534           FOR i in l_eam_direct_items_tbl.first..l_eam_direct_items_tbl.last LOOP
2535             IF l_eam_direct_items_tbl(i).batch_id is null or l_eam_direct_items_tbl(i).header_id is null then
2536               l_return_status := FND_API.G_RET_STS_ERROR;
2537               return;
2538             END IF;
2539             l_eam_direct_items_tbl(i).row_id := i;
2540             IF l_batch_id = null THEN
2541               l_batch_id := l_eam_direct_items_tbl(i).batch_id;
2542             ELSIF l_batch_id <> l_eam_direct_items_tbl(i).batch_id THEN
2543               l_return_status := FND_API.G_RET_STS_ERROR;
2544             END IF;
2545             l_header_id := l_eam_direct_items_tbl(i).header_id;
2546             l_found := FND_API.G_FALSE;
2547             if l_header_id_tbl.count > 0 then
2548             for j in l_header_id_tbl.first..l_header_id_tbl.last loop
2549               if l_header_id = l_header_id_tbl(j).header_id then
2550                 l_found := FND_API.G_TRUE;
2551               end if;
2552             end loop;
2553             end if;
2554             if l_found = FND_API.G_FALSE then
2555               l_header_id_tbl(l_header_id_tbl.count+1).header_id := l_header_id;
2556             end if;
2557           END LOOP;
2558           end if;
2559 
2560 	if l_eam_wo_comp_tbl.count > 0 then
2561 
2562           FOR i in l_eam_wo_comp_tbl.first..l_eam_wo_comp_tbl.last LOOP
2563             IF l_eam_wo_comp_tbl(i).batch_id is null or l_eam_wo_comp_tbl(i).header_id is null then
2564               l_return_status := FND_API.G_RET_STS_ERROR;
2565               return;
2566             END IF;
2567             l_eam_wo_comp_tbl(i).row_id := i;
2568             IF l_batch_id = null THEN
2569               l_batch_id := l_eam_wo_comp_tbl(i).batch_id;
2570             ELSIF l_batch_id <> l_eam_wo_comp_tbl(i).batch_id THEN
2571               l_return_status := FND_API.G_RET_STS_ERROR;
2572             END IF;
2573             l_header_id := l_eam_wo_comp_tbl(i).header_id;
2574             l_found := FND_API.G_FALSE;
2575             if l_header_id_tbl.count > 0 then
2576             for j in l_header_id_tbl.first..l_header_id_tbl.last loop
2577               if l_header_id = l_header_id_tbl(j).header_id then
2578                 l_found := FND_API.G_TRUE;
2579               end if;
2580             end loop;
2581             end if;
2582             if l_found = FND_API.G_FALSE then
2583               l_header_id_tbl(l_header_id_tbl.count+1).header_id := l_header_id;
2584             end if;
2585           END LOOP;
2586           end if;
2587 
2588 	if l_eam_wo_quality_tbl.count > 0 then
2589           FOR i in l_eam_wo_quality_tbl.first..l_eam_wo_quality_tbl.last LOOP
2590             IF l_eam_wo_quality_tbl(i).batch_id is null or l_eam_wo_quality_tbl(i).header_id is null then
2591               l_return_status := FND_API.G_RET_STS_ERROR;
2592               return;
2593             END IF;
2594             l_eam_wo_quality_tbl(i).row_id := i;
2595             IF l_batch_id = null THEN
2596               l_batch_id := l_eam_wo_quality_tbl(i).batch_id;
2597             ELSIF l_batch_id <> l_eam_wo_quality_tbl(i).batch_id THEN
2598               l_return_status := FND_API.G_RET_STS_ERROR;
2599             END IF;
2600             l_header_id := l_eam_wo_quality_tbl(i).header_id;
2601             l_found := FND_API.G_FALSE;
2602             if l_header_id_tbl.count > 0 then
2603             for j in l_header_id_tbl.first..l_header_id_tbl.last loop
2604               if l_header_id = l_header_id_tbl(j).header_id then
2605                 l_found := FND_API.G_TRUE;
2606               end if;
2607             end loop;
2608             end if;
2609             if l_found = FND_API.G_FALSE then
2610               l_header_id_tbl(l_header_id_tbl.count+1).header_id := l_header_id;
2611             end if;
2612           END LOOP;
2613           end if;
2614 
2615 	  if l_eam_meter_reading_tbl.count > 0 then
2616           FOR i in l_eam_meter_reading_tbl.first..l_eam_meter_reading_tbl.last LOOP
2617             IF l_eam_meter_reading_tbl(i).batch_id is null or l_eam_meter_reading_tbl(i).header_id is null then
2618               l_return_status := FND_API.G_RET_STS_ERROR;
2619               return;
2620             END IF;
2621             l_eam_meter_reading_tbl(i).row_id := i;
2622             IF l_batch_id = null THEN
2623               l_batch_id := l_eam_meter_reading_tbl(i).batch_id;
2624             ELSIF l_batch_id <> l_eam_meter_reading_tbl(i).batch_id THEN
2625               l_return_status := FND_API.G_RET_STS_ERROR;
2626             END IF;
2627             l_header_id := l_eam_meter_reading_tbl(i).header_id;
2628             l_found := FND_API.G_FALSE;
2629             if l_header_id_tbl.count > 0 then
2630             for j in l_header_id_tbl.first..l_header_id_tbl.last loop
2631               if l_header_id = l_header_id_tbl(j).header_id then
2632                 l_found := FND_API.G_TRUE;
2633               end if;
2634             end loop;
2635             end if;
2636             if l_found = FND_API.G_FALSE then
2637               l_header_id_tbl(l_header_id_tbl.count+1).header_id := l_header_id;
2638             end if;
2639           END LOOP;
2640           end if;
2641 
2642 	 if l_eam_counter_prop_tbl.count > 0 then
2643           FOR i in l_eam_counter_prop_tbl.first..l_eam_counter_prop_tbl.last LOOP
2644             IF l_eam_counter_prop_tbl(i).batch_id is null or l_eam_counter_prop_tbl(i).header_id is null then
2645               l_return_status := FND_API.G_RET_STS_ERROR;
2646               return;
2647             END IF;
2648             l_eam_counter_prop_tbl(i).row_id := i;
2649             IF l_batch_id = null THEN
2650               l_batch_id := l_eam_counter_prop_tbl(i).batch_id;
2651             ELSIF l_batch_id <> l_eam_counter_prop_tbl(i).batch_id THEN
2652               l_return_status := FND_API.G_RET_STS_ERROR;
2653             END IF;
2654             l_header_id := l_eam_counter_prop_tbl(i).header_id;
2655             l_found := FND_API.G_FALSE;
2656             if l_header_id_tbl.count > 0 then
2657             for j in l_header_id_tbl.first..l_header_id_tbl.last loop
2658               if l_header_id = l_header_id_tbl(j).header_id then
2659                 l_found := FND_API.G_TRUE;
2660               end if;
2661             end loop;
2662             end if;
2663             if l_found = FND_API.G_FALSE then
2664               l_header_id_tbl(l_header_id_tbl.count+1).header_id := l_header_id;
2665             end if;
2666           END LOOP;
2667           end if;
2668 
2669 	   if l_eam_wo_comp_rebuild_tbl.count > 0 then
2670           FOR i in l_eam_wo_comp_rebuild_tbl.first..l_eam_wo_comp_rebuild_tbl.last LOOP
2671             IF l_eam_wo_comp_rebuild_tbl(i).batch_id is null or l_eam_wo_comp_rebuild_tbl(i).header_id is null then
2672               l_return_status := FND_API.G_RET_STS_ERROR;
2673               return;
2674             END IF;
2675             l_eam_wo_comp_rebuild_tbl(i).row_id := i;
2676             IF l_batch_id = null THEN
2677               l_batch_id := l_eam_wo_comp_rebuild_tbl(i).batch_id;
2678             ELSIF l_batch_id <> l_eam_wo_comp_rebuild_tbl(i).batch_id THEN
2679               l_return_status := FND_API.G_RET_STS_ERROR;
2680             END IF;
2681             l_header_id := l_eam_wo_comp_rebuild_tbl(i).header_id;
2682             l_found := FND_API.G_FALSE;
2683             if l_header_id_tbl.count > 0 then
2684             for j in l_header_id_tbl.first..l_header_id_tbl.last loop
2685               if l_header_id = l_header_id_tbl(j).header_id then
2686                 l_found := FND_API.G_TRUE;
2687               end if;
2688             end loop;
2689             end if;
2690             if l_found = FND_API.G_FALSE then
2691               l_header_id_tbl(l_header_id_tbl.count+1).header_id := l_header_id;
2692             end if;
2693           END LOOP;
2694           end if;
2695 
2696 	    if l_eam_wo_comp_mr_read_tbl.count > 0 then
2697           FOR i in l_eam_wo_comp_mr_read_tbl.first..l_eam_wo_comp_mr_read_tbl.last LOOP
2698             IF l_eam_wo_comp_mr_read_tbl(i).batch_id is null or l_eam_wo_comp_mr_read_tbl(i).header_id is null then
2699               l_return_status := FND_API.G_RET_STS_ERROR;
2700               return;
2701             END IF;
2702             l_eam_wo_comp_mr_read_tbl(i).row_id := i;
2703             IF l_batch_id = null THEN
2704               l_batch_id := l_eam_wo_comp_mr_read_tbl(i).batch_id;
2705             ELSIF l_batch_id <> l_eam_wo_comp_mr_read_tbl(i).batch_id THEN
2706               l_return_status := FND_API.G_RET_STS_ERROR;
2707             END IF;
2708             l_header_id := l_eam_wo_comp_mr_read_tbl(i).header_id;
2709             l_found := FND_API.G_FALSE;
2710             if l_header_id_tbl.count > 0 then
2711             for j in l_header_id_tbl.first..l_header_id_tbl.last loop
2712               if l_header_id = l_header_id_tbl(j).header_id then
2713                 l_found := FND_API.G_TRUE;
2714               end if;
2715             end loop;
2716             end if;
2717             if l_found = FND_API.G_FALSE then
2718               l_header_id_tbl(l_header_id_tbl.count+1).header_id := l_header_id;
2719             end if;
2720           END LOOP;
2721           end if;
2722 
2723 	    if l_eam_op_comp_tbl.count > 0 then
2724           FOR i in l_eam_op_comp_tbl.first..l_eam_op_comp_tbl.last LOOP
2725             IF l_eam_op_comp_tbl(i).batch_id is null or l_eam_op_comp_tbl(i).header_id is null then
2726               l_return_status := FND_API.G_RET_STS_ERROR;
2727               return;
2728             END IF;
2729             l_eam_op_comp_tbl(i).row_id := i;
2730             IF l_batch_id = null THEN
2731               l_batch_id := l_eam_op_comp_tbl(i).batch_id;
2732             ELSIF l_batch_id <> l_eam_op_comp_tbl(i).batch_id THEN
2733               l_return_status := FND_API.G_RET_STS_ERROR;
2734             END IF;
2735             l_header_id := l_eam_op_comp_tbl(i).header_id;
2736             l_found := FND_API.G_FALSE;
2737             if l_header_id_tbl.count > 0 then
2738             for j in l_header_id_tbl.first..l_header_id_tbl.last loop
2739               if l_header_id = l_header_id_tbl(j).header_id then
2740                 l_found := FND_API.G_TRUE;
2741               end if;
2742             end loop;
2743             end if;
2744             if l_found = FND_API.G_FALSE then
2745               l_header_id_tbl(l_header_id_tbl.count+1).header_id := l_header_id;
2746             end if;
2747           END LOOP;
2748           end if;
2749 
2750 	     if l_eam_request_tbl.count > 0 then
2751           FOR i in l_eam_request_tbl.first..l_eam_request_tbl.last LOOP
2752             IF l_eam_request_tbl(i).batch_id is null or l_eam_request_tbl(i).header_id is null then
2753               l_return_status := FND_API.G_RET_STS_ERROR;
2754               return;
2755             END IF;
2756             l_eam_request_tbl(i).row_id := i;
2757             IF l_batch_id = null THEN
2758               l_batch_id := l_eam_request_tbl(i).batch_id;
2759             ELSIF l_batch_id <> l_eam_request_tbl(i).batch_id THEN
2760               l_return_status := FND_API.G_RET_STS_ERROR;
2761             END IF;
2762             l_header_id := l_eam_request_tbl(i).header_id;
2763             l_found := FND_API.G_FALSE;
2764             if l_header_id_tbl.count > 0 then
2765             for j in l_header_id_tbl.first..l_header_id_tbl.last loop
2766               if l_header_id = l_header_id_tbl(j).header_id then
2767                 l_found := FND_API.G_TRUE;
2768               end if;
2769             end loop;
2770             end if;
2771             if l_found = FND_API.G_FALSE then
2772               l_header_id_tbl(l_header_id_tbl.count+1).header_id := l_header_id;
2773             end if;
2774           END LOOP;
2775           end if;
2776 
2777 
2778          -- If return status is not success, then set all records as unprocessed
2779          if l_return_status <> FND_API.G_RET_STS_SUCCESS then
2780 
2781            for i in l_eam_wo_tbl.first..l_eam_wo_tbl.last loop
2782              if l_eam_wo_tbl(i).transaction_type is not null then
2783                l_eam_wo_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2784              end if;
2785            end loop;
2786 
2787            for i in l_eam_wo_relations_tbl.first..l_eam_wo_relations_tbl.last loop
2788              if l_eam_wo_relations_tbl(i).transaction_type is not null then
2789                l_eam_wo_relations_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2790              end if;
2791            end loop;
2792 
2793            for i in l_eam_op_tbl.first..l_eam_op_tbl.last loop
2794              if l_eam_op_tbl(i).transaction_type is not null then
2795                l_eam_op_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2796              end if;
2797            end loop;
2798 
2799            for i in l_eam_op_network_tbl.first..l_eam_op_tbl.last loop
2800              if l_eam_op_network_tbl(i).transaction_type is not null then
2801                l_eam_op_network_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2802              end if;
2803            end loop;
2804 
2805            for i in l_eam_res_tbl.first..l_eam_res_tbl.last loop
2806              if l_eam_res_tbl(i).transaction_type is not null then
2807                l_eam_res_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2808              end if;
2809            end loop;
2810 
2811            for i in l_eam_res_inst_tbl.first..l_eam_res_inst_tbl.last loop
2812              if l_eam_res_inst_tbl(i).transaction_type is not null then
2813                l_eam_res_inst_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2814              end if;
2815            end loop;
2816 
2817            for i in l_eam_sub_res_tbl.first..l_eam_sub_res_tbl.last loop
2818              if l_eam_sub_res_tbl(i).transaction_type is not null then
2819                l_eam_sub_res_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2820              end if;
2821            end loop;
2822 
2823 
2824            for i in l_eam_res_usage_tbl.first..l_eam_res_usage_tbl.last loop
2825              if l_eam_res_usage_tbl(i).transaction_type is not null then
2826                l_eam_res_usage_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2827              end if;
2828            end loop;
2829 
2830            for i in l_eam_mat_req_tbl.first..l_eam_mat_req_tbl.last loop
2831              if l_eam_mat_req_tbl(i).transaction_type is not null then
2832                l_eam_mat_req_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2833              end if;
2834            end loop;
2835 
2836            for i in l_eam_direct_items_tbl.first..l_eam_direct_items_tbl.last loop
2837              if l_eam_direct_items_tbl(i).transaction_type is not null then
2838                l_eam_direct_items_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2839              end if;
2840 
2841 	  for i in l_eam_wo_comp_tbl.first..l_eam_wo_comp_tbl.last loop
2842              if l_eam_wo_comp_tbl(i).transaction_type is not null then
2843                l_eam_wo_comp_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2844              end if;
2845            end loop;
2846 
2847 	 for i in l_eam_wo_quality_tbl.first..l_eam_wo_quality_tbl.last loop
2848              if l_eam_wo_quality_tbl(i).transaction_type is not null then
2849                l_eam_wo_quality_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2850              end if;
2851            end loop;
2852 
2853 	 for i in l_eam_meter_reading_tbl.first..l_eam_meter_reading_tbl.last loop
2854              if l_eam_meter_reading_tbl(i).transaction_type is not null then
2855                l_eam_meter_reading_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2856              end if;
2857            end loop;
2858 
2859 	 for i in l_eam_counter_prop_tbl.first..l_eam_counter_prop_tbl.last loop
2860              if l_eam_counter_prop_tbl(i).transaction_type is not null then
2861                l_eam_counter_prop_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2862              end if;
2863            end loop;
2864 
2865 	 for i in l_eam_wo_comp_rebuild_tbl.first..l_eam_wo_comp_rebuild_tbl.last loop
2866              if l_eam_wo_comp_rebuild_tbl(i).transaction_type is not null then
2867                l_eam_wo_comp_rebuild_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2868              end if;
2869            end loop;
2870 
2871 	 for i in l_eam_wo_comp_mr_read_tbl.first..l_eam_wo_comp_mr_read_tbl.last loop
2872              if l_eam_wo_comp_mr_read_tbl(i).transaction_type is not null then
2873                l_eam_wo_comp_mr_read_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2874              end if;
2875            end loop;
2876 
2877 	 for i in l_eam_op_comp_tbl.first..l_eam_op_comp_tbl.last loop
2878              if l_eam_op_comp_tbl(i).transaction_type is not null then
2879                l_eam_op_comp_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2880              end if;
2881            end loop;
2882 
2883 	 for i in l_eam_request_tbl.first..l_eam_request_tbl.last loop
2884              if l_eam_request_tbl(i).transaction_type is not null then
2885                l_eam_request_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2886              end if;
2887            end loop;
2888 
2889            end loop;
2890 
2891          end if;
2892 
2893          x_eam_wo_tbl              := l_eam_wo_tbl;
2894          x_eam_wo_relations_tbl    := l_eam_wo_relations_tbl;
2895          x_eam_op_tbl              := l_eam_op_tbl;
2896          x_eam_op_network_tbl      := l_eam_op_network_tbl;
2897          x_eam_res_tbl             := l_eam_res_tbl;
2898          x_eam_res_inst_tbl        := l_eam_res_inst_tbl;
2899          x_eam_sub_res_tbl         := l_eam_sub_res_tbl;
2900 	 x_eam_res_usage_tbl	   := l_eam_res_usage_tbl;
2901          x_eam_res_usage_tbl       := l_eam_res_usage_tbl;
2902          x_eam_mat_req_tbl         := l_eam_mat_req_tbl;
2903          x_eam_direct_items_tbl    := l_eam_direct_items_tbl;
2904 
2905 	x_eam_wo_comp_tbl		:= l_eam_wo_comp_tbl        ;
2906 	x_eam_wo_quality_tbl     	:= l_eam_wo_quality_tbl     ;
2907 	x_eam_meter_reading_tbl  	:= l_eam_meter_reading_tbl  ;
2908 	x_eam_counter_prop_tbl   	:= l_eam_counter_prop_tbl   ;
2909 	x_eam_wo_comp_rebuild_tbl	:= l_eam_wo_comp_rebuild_tbl;
2910 	x_eam_wo_comp_mr_read_tbl	:= l_eam_wo_comp_mr_read_tbl;
2911 	x_eam_op_comp_tbl        	:= l_eam_op_comp_tbl        ;
2912 	x_eam_request_tbl        	:= l_eam_request_tbl     ;
2913 
2914           x_batch_id      := l_batch_id;
2915           x_header_id_tbl := l_header_id_tbl;
2916           x_return_status := l_return_status;
2917           return;
2918 
2919          EXCEPTION
2920 
2921            WHEN OTHERS THEN
2922              l_return_status := FND_API.G_RET_STS_ERROR;
2923          -- set all records as unprocessed
2924 
2925            for i in l_eam_wo_tbl.first..l_eam_wo_tbl.last loop
2926              if l_eam_wo_tbl(i).transaction_type is not null then
2927                l_eam_wo_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2928              end if;
2929            end loop;
2930 
2931            for i in l_eam_wo_relations_tbl.first..l_eam_wo_relations_tbl.last loop
2932              if l_eam_wo_relations_tbl(i).transaction_type is not null then
2933                l_eam_wo_relations_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2934              end if;
2935            end loop;
2936 
2937            for i in l_eam_op_tbl.first..l_eam_op_tbl.last loop
2938              if l_eam_op_tbl(i).transaction_type is not null then
2939                l_eam_op_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2940              end if;
2941            end loop;
2942 
2943            for i in l_eam_op_network_tbl.first..l_eam_op_tbl.last loop
2944              if l_eam_op_network_tbl(i).transaction_type is not null then
2945                l_eam_op_network_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2946              end if;
2947            end loop;
2948 
2949            for i in l_eam_res_tbl.first..l_eam_res_tbl.last loop
2950              if l_eam_res_tbl(i).transaction_type is not null then
2951                l_eam_res_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2952              end if;
2953            end loop;
2954 
2955            for i in l_eam_res_inst_tbl.first..l_eam_res_inst_tbl.last loop
2956              if l_eam_res_inst_tbl(i).transaction_type is not null then
2957                l_eam_res_inst_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2958              end if;
2959            end loop;
2960 
2961            for i in l_eam_sub_res_tbl.first..l_eam_sub_res_tbl.last loop
2962              if l_eam_sub_res_tbl(i).transaction_type is not null then
2963                l_eam_sub_res_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2964              end if;
2965            end loop;
2966 
2967            for i in l_eam_mat_req_tbl.first..l_eam_mat_req_tbl.last loop
2968              if l_eam_mat_req_tbl(i).transaction_type is not null then
2969                l_eam_mat_req_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2970              end if;
2971            end loop;
2972 
2973            for i in l_eam_direct_items_tbl.first..l_eam_direct_items_tbl.last loop
2974              if l_eam_direct_items_tbl(i).transaction_type is not null then
2975                l_eam_direct_items_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2976              end if;
2977            end loop;
2978 
2979            for i in l_eam_res_usage_tbl.first..l_eam_res_usage_tbl.last loop
2980              if l_eam_res_usage_tbl(i).transaction_type is not null then
2981                l_eam_res_usage_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2982              end if;
2983            end loop;
2984 
2985            for i in l_eam_wo_comp_tbl.first..l_eam_wo_comp_tbl.last loop
2986              if l_eam_wo_comp_tbl(i).transaction_type is not null then
2987                l_eam_wo_comp_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2988              end if;
2989            end loop;
2990 
2991            for i in l_eam_wo_quality_tbl.first..l_eam_wo_quality_tbl.last loop
2992              if l_eam_wo_quality_tbl(i).transaction_type is not null then
2993                l_eam_wo_quality_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
2994              end if;
2995            end loop;
2996 
2997 	   for i in l_eam_meter_reading_tbl.first..l_eam_meter_reading_tbl.last loop
2998              if l_eam_meter_reading_tbl(i).transaction_type is not null then
2999                l_eam_meter_reading_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
3000              end if;
3001            end loop;
3002 
3003 	   for i in l_eam_counter_prop_tbl.first..l_eam_counter_prop_tbl.last loop
3004              if l_eam_counter_prop_tbl(i).transaction_type is not null then
3005                l_eam_counter_prop_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
3006              end if;
3007            end loop;
3008 
3009            for i in l_eam_wo_comp_rebuild_tbl.first..l_eam_wo_comp_rebuild_tbl.last loop
3010              if l_eam_wo_comp_rebuild_tbl(i).transaction_type is not null then
3011                l_eam_wo_comp_rebuild_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
3012              end if;
3013            end loop;
3014 
3015            for i in l_eam_wo_comp_mr_read_tbl.first..l_eam_wo_comp_mr_read_tbl.last loop
3016              if l_eam_wo_comp_mr_read_tbl(i).transaction_type is not null then
3017                l_eam_wo_comp_mr_read_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
3018              end if;
3019            end loop;
3020 
3021            for i in l_eam_op_comp_tbl.first..l_eam_op_comp_tbl.last loop
3022              if l_eam_op_comp_tbl(i).transaction_type is not null then
3023                l_eam_op_comp_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
3024              end if;
3025            end loop;
3026 
3027            for i in l_eam_request_tbl.first..l_eam_request_tbl.last loop
3028              if l_eam_request_tbl(i).transaction_type is not null then
3029                l_eam_request_tbl(i).return_status := FND_API.G_RET_STS_ERROR;
3030              end if;
3031            end loop;
3032 
3033 
3034         END CHECK_BO_NETWORK;
3035 
3036 
3037 
3038 
3039     /********************************************************************
3040     * Procedure: Process_WO
3041     * Parameters IN:
3042     *         EAM Work Order column record
3043     *         Operation column table
3044     *         Operation Networks column Table
3045     *         Resource column Table
3046     *         Substitute Resource column table
3047     *         Material Requirements column table
3048     *         Direct Items column table
3049     * Parameters OUT:
3050     *         EAM Work Order column record
3051     *         Operation column table
3052     *         Operation Networks column Table
3053     *         Resource column Table
3054     *         Substitute Resource column table
3055     *         Material Requirements column table
3056     *         Direct Items column table
3057     * Purpose:
3058     *         This procedure is the driving procedure of the EAM
3059     *         business Obect. It will verify the integrity of the
3060     *         business object and will call the private API which
3061     *         further drive the business object to perform business
3062     *         logic validations.
3063     *********************************************************************/
3064 
3065       PROCEDURE PROCESS_WO
3066         (  p_bo_identifier           IN  VARCHAR2 := 'EAM'
3067          , p_api_version_number      IN  NUMBER := 1.0
3068          , p_init_msg_list           IN  BOOLEAN := FALSE
3069          , p_commit                  IN  VARCHAR2 := 'N'
3070          , p_eam_wo_rec              IN EAM_PROCESS_WO_PUB.eam_wo_rec_type
3071          , p_eam_op_tbl              IN EAM_PROCESS_WO_PUB.eam_op_tbl_type
3072          , p_eam_op_network_tbl      IN EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
3073          , p_eam_res_tbl             IN EAM_PROCESS_WO_PUB.eam_res_tbl_type
3074          , p_eam_res_inst_tbl        IN EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
3075          , p_eam_sub_res_tbl         IN EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
3076          , p_eam_res_usage_tbl       IN EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
3077          , p_eam_mat_req_tbl         IN EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
3078          , p_eam_direct_items_tbl    IN EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
3079          , p_eam_wo_comp_rec         IN  EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type
3080          , p_eam_wo_quality_tbl      IN  EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type
3081          , p_eam_meter_reading_tbl   IN  EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type
3082 	 , p_eam_counter_prop_tbl    IN  EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type
3083          , p_eam_wo_comp_rebuild_tbl IN  EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type
3084          , p_eam_wo_comp_mr_read_tbl IN  EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type
3085          , p_eam_op_comp_tbl         IN  EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type
3086 	 , p_eam_request_tbl         IN  EAM_PROCESS_WO_PUB.eam_request_tbl_type
3087          , x_eam_wo_rec              OUT NOCOPY EAM_PROCESS_WO_PUB.eam_wo_rec_type
3088          , x_eam_op_tbl              OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_tbl_type
3089          , x_eam_op_network_tbl      OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
3090          , x_eam_res_tbl             OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_tbl_type
3091          , x_eam_res_inst_tbl        OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
3092          , x_eam_sub_res_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
3093          , x_eam_res_usage_tbl       OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
3094          , x_eam_mat_req_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
3095          , x_eam_direct_items_tbl    OUT NOCOPY EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
3096  	 , x_eam_wo_comp_rec         OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type
3097          , x_eam_wo_quality_tbl      OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type
3098          , x_eam_meter_reading_tbl   OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type
3099  	 , x_eam_counter_prop_tbl    OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type
3100          , x_eam_wo_comp_rebuild_tbl OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type
3101          , x_eam_wo_comp_mr_read_tbl OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type
3102          , x_eam_op_comp_tbl         OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type
3103 	 , x_eam_request_tbl         OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_request_tbl_type
3104          , x_return_status           OUT NOCOPY VARCHAR2
3105          , x_msg_count               OUT NOCOPY NUMBER
3106          , p_debug                   IN  VARCHAR2 := 'N'
3107          , p_output_dir              IN  VARCHAR2 := NULL
3108          , p_debug_filename          IN  VARCHAR2 := 'EAM_WO_DEBUG.log'
3109          , p_debug_file_mode         IN  VARCHAR2 := 'w'
3110          ) IS
3111 
3112         G_EXC_SEV_QUIT_OBJECT   EXCEPTION;
3113         G_EXC_UNEXP_SKIP_OBJECT EXCEPTION;
3114         l_Mesg_Token_Tbl        EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
3115         l_other_message         VARCHAR2(50);
3116         l_Token_Tbl             EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type;
3117         l_err_text              VARCHAR2(2000);
3118         l_return_status         VARCHAR2(1);
3119         l_debug_file_mode       VARCHAR2(1) := p_debug_file_mode;
3120 		l_pending_flag          VARCHAR2(1);
3121 
3122 
3123         l_eam_wo_rec            EAM_PROCESS_WO_PUB.eam_wo_rec_type;
3124         l_eam_op_tbl            EAM_PROCESS_WO_PUB.eam_op_tbl_type;
3125         l_eam_op_network_tbl    EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
3126         l_eam_res_tbl           EAM_PROCESS_WO_PUB.eam_res_tbl_type;
3127         l_eam_res_inst_tbl      EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
3128         l_eam_sub_res_tbl       EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
3129         l_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
3130         l_eam_mat_req_tbl       EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
3131         l_eam_direct_items_tbl       EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
3132 
3133 	l_eam_wo_comp_rec         EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type;
3134 	l_eam_wo_quality_tbl      EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type;
3135 	l_eam_meter_reading_tbl   EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type;
3136  	l_eam_counter_prop_tbl    EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type;
3137 	l_eam_wo_comp_rebuild_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type;
3138 	l_eam_wo_comp_mr_read_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type;
3139 	l_eam_op_comp_tbl         EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type;
3140 	l_eam_request_tbl         EAM_PROCESS_WO_PUB.eam_request_tbl_type;
3141 
3142         l_out_eam_wo_rec            EAM_PROCESS_WO_PUB.eam_wo_rec_type;
3143         l_out_eam_op_tbl            EAM_PROCESS_WO_PUB.eam_op_tbl_type;
3144         l_out_eam_op_network_tbl    EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
3145         l_out_eam_res_tbl           EAM_PROCESS_WO_PUB.eam_res_tbl_type;
3146         l_out_eam_res_inst_tbl      EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
3147         l_out_eam_sub_res_tbl       EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
3148         l_out_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
3149         l_out_eam_mat_req_tbl       EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
3150         l_out_eam_direct_items_tbl       EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
3151         l_out_mesg_token_tbl        EAM_ERROR_MESSAGE_PVT.mesg_token_tbl_type;
3152 
3153 	l_out_eam_wo_comp_rec         EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type;
3154 	l_out_eam_wo_quality_tbl      EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type;
3155 	l_out_eam_meter_reading_tbl   EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type;
3156  	l_out_eam_counter_prop_tbl        EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type;
3157 	l_out_eam_wo_comp_rebuild_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type;
3158 	l_out_eam_wo_comp_mr_read_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type;
3159 	l_out_eam_op_comp_tbl         EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type;
3160 	l_out_eam_request_tbl         EAM_PROCESS_WO_PUB.eam_request_tbl_type;
3161 
3162         l_debug_flag            VARCHAR2(1) := p_debug;
3163 	l_msg_count		NUMBER;
3164         l_msg_data              VARCHAR2(4000); /* Failure Entry Project */
3165 
3166 
3167 
3168 		l_test_eam_wo_rec EAM_PROCESS_WO_PUB.eam_wo_rec_type;
3169 
3170 BEGIN
3171 
3172         l_eam_wo_rec            := p_eam_wo_rec;
3173         l_eam_op_tbl            := p_eam_op_tbl;
3174         l_eam_op_network_tbl    := p_eam_op_network_tbl;
3175         l_eam_res_tbl           := p_eam_res_tbl;
3176         l_eam_res_inst_tbl      := p_eam_res_inst_tbl;
3177         l_eam_sub_res_tbl       := p_eam_sub_res_tbl;
3178         l_eam_res_usage_tbl     := p_eam_res_usage_tbl;
3179         l_eam_mat_req_tbl       := p_eam_mat_req_tbl;
3180         l_eam_direct_items_tbl  := p_eam_direct_items_tbl;
3181 
3182 	l_eam_wo_comp_rec         := p_eam_wo_comp_rec;
3183 	l_eam_wo_quality_tbl      := p_eam_wo_quality_tbl;
3184 	l_eam_meter_reading_tbl   := p_eam_meter_reading_tbl;
3185 	l_eam_counter_prop_tbl    := p_eam_counter_prop_tbl;
3186 	l_eam_wo_comp_rebuild_tbl := p_eam_wo_comp_rebuild_tbl;
3187 	l_eam_wo_comp_mr_read_tbl := p_eam_wo_comp_mr_read_tbl;
3188 	l_eam_op_comp_tbl         := p_eam_op_comp_tbl;
3189 	l_eam_request_tbl     	  := p_eam_request_tbl;
3190 
3191 	-- begin bug 16006707
3192 	Begin
3193 
3194 		SELECT PENDING_FLAG INTO l_pending_flag
3195 		FROM EAM_WORK_ORDER_DETAILS
3196 		WHERE
3197 		WIP_ENTITY_ID=l_eam_wo_rec.wip_entity_id;
3198 
3199 		EXCEPTION WHEN NO_DATA_FOUND THEN
3200 			l_pending_flag:=null;
3201 	End;
3202 
3203 	IF l_pending_flag IS NOT NULL AND l_pending_flag='Y' AND l_eam_wo_rec.transaction_type=EAM_PROCESS_WO_PUB.G_OPR_UPDATE THEN
3204 
3205 		FND_MESSAGE.SET_NAME('EAM', 'EAM_UNAUTHORISED_UPDATE');
3206         FND_MSG_PUB.Add;
3207 		RAISE G_EXC_SEV_QUIT_OBJECT;
3208 
3209 	END IF;
3210 
3211 	IF l_pending_flag IS NOT NULL AND l_pending_flag='Y' AND l_eam_wo_rec.transaction_type=EAM_PROCESS_WO_PUB.G_WF_OPR_UPDATE THEN
3212 		l_eam_wo_rec.transaction_type:=EAM_PROCESS_WO_PUB.G_OPR_UPDATE;
3213 
3214 	END IF;
3215 	--end bug 16006707
3216 
3217 
3218 
3219         --
3220         -- Set Business Object Idenfier in the System Information record.
3221         --
3222         EAM_ERROR_MESSAGE_PVT.Set_Bo_Identifier
3223                     (p_bo_identifier    =>  p_bo_identifier);
3224 
3225         --
3226         -- Initialize the message list if the user has set the Init Message List parameter
3227         --
3228         IF p_init_msg_list
3229         THEN
3230             EAM_ERROR_MESSAGE_PVT.Initialize;
3231         END IF;
3232 
3233 	-- Set the global variable for debug.
3234         EAM_PROCESS_WO_PVT.Set_Debug(l_debug_flag);
3235 
3236         IF l_debug_flag = 'Y'
3237         THEN
3238 
3239             IF trim(p_output_dir) IS NULL OR trim(p_output_dir) = ''
3240             THEN
3241 
3242             -- If debug is Y then out dir must be specified
3243 
3244                 l_out_mesg_token_tbl := l_mesg_token_tbl;
3245                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
3246                 ( p_Message_text       => 'Debug is set to Y so an output directory' || ' must be specified. Debug will be turned' || ' off since no directory is specified'
3247                 , p_Mesg_Token_Tbl     => l_mesg_token_tbl
3248                 , x_Mesg_Token_Tbl     => l_out_mesg_token_tbl
3249                 , p_Token_Tbl          => l_token_tbl
3250                  );
3251                 l_mesg_token_tbl := l_out_mesg_token_tbl;
3252 
3253                 l_out_eam_wo_rec            := l_eam_wo_rec;
3254                 l_out_eam_op_tbl            := l_eam_op_tbl;
3255                 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
3256                 l_out_eam_res_tbl           := l_eam_res_tbl;
3257                 l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
3258                 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
3259                 l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
3260                 l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
3261                 l_out_eam_direct_items_tbl  := l_eam_direct_items_tbl;
3262 		l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
3263 
3264 		l_out_eam_wo_comp_rec          := l_eam_wo_comp_rec;
3265 		l_out_eam_wo_quality_tbl       := l_eam_wo_quality_tbl;
3266 		l_out_eam_meter_reading_tbl    := l_eam_meter_reading_tbl;
3267 		l_out_eam_wo_comp_rebuild_tbl  := l_eam_wo_comp_rebuild_tbl;
3268 		l_out_eam_counter_prop_tbl     := l_eam_counter_prop_tbl;
3269 		l_out_eam_wo_comp_mr_read_tbl  := l_eam_wo_comp_mr_read_tbl;
3270 		l_out_eam_op_comp_tbl          := l_eam_op_comp_tbl;
3271 		l_out_eam_request_tbl          := l_eam_request_tbl;
3272 
3273                 EAM_ERROR_MESSAGE_PVT.Log_Error
3274                 (  p_eam_wo_rec             => l_eam_wo_rec
3275                 ,  p_eam_op_tbl             => l_eam_op_tbl
3276                 ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
3277                 ,  p_eam_res_tbl            => l_eam_res_tbl
3278                 ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
3279                 ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
3280                 ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
3281                 ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
3282                 ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
3283                 ,  p_Mesg_Token_Tbl         => l_Mesg_Token_Tbl
3284                 ,  p_error_status           => 'W'
3285                 ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_BO_LEVEL
3286                 ,  x_eam_wo_rec             => l_out_eam_wo_rec
3287                 ,  x_eam_op_tbl             => l_out_eam_op_tbl
3288                 ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
3289                 ,  x_eam_res_tbl            => l_out_eam_res_tbl
3290                 ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
3291                 ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
3292                 ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
3293                 ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
3294                 ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
3295                  );
3296 
3297                 l_eam_wo_rec            := l_out_eam_wo_rec;
3298                 l_eam_op_tbl            := l_out_eam_op_tbl;
3299                 l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
3300                 l_eam_res_tbl           := l_out_eam_res_tbl;
3301                 l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
3302                 l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
3303                 l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
3304                 l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
3305                 l_eam_direct_items_tbl  := l_out_eam_direct_items_tbl;
3306 
3307 		l_eam_wo_comp_rec         := l_out_eam_wo_comp_rec        ;
3308 		l_eam_wo_quality_tbl      := l_out_eam_wo_quality_tbl     ;
3309 		l_eam_meter_reading_tbl   := l_out_eam_meter_reading_tbl  ;
3310 		l_eam_wo_comp_rebuild_tbl := l_out_eam_wo_comp_rebuild_tbl;
3311 		l_eam_counter_prop_tbl    := l_out_eam_counter_prop_tbl   ;
3312 		l_eam_wo_comp_mr_read_tbl := l_out_eam_wo_comp_mr_read_tbl;
3313 		l_eam_op_comp_tbl         := l_out_eam_op_comp_tbl        ;
3314 		l_eam_request_tbl         := l_out_eam_request_tbl        ;
3315 
3316                 l_debug_flag := 'N';
3317 
3318             END IF;
3319 
3320             IF trim(p_debug_filename) IS NULL OR trim(p_debug_filename) = ''
3321             THEN
3322 
3323                 l_out_mesg_token_tbl := l_mesg_token_tbl;
3324                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
3325                 ( p_Message_text       => 'Debug is set to Y so an output filename' || ' must be specified. Debug will be turned' || ' off since no filename is specified'
3326                 , p_Mesg_Token_Tbl     => l_mesg_token_tbl
3327                 , x_Mesg_Token_Tbl     => l_out_mesg_token_tbl
3328                 , p_Token_Tbl          => l_token_tbl
3329                  );
3330                 l_mesg_token_tbl := l_out_mesg_token_tbl;
3331 
3332                 l_out_eam_wo_rec            := l_eam_wo_rec;
3333                 l_out_eam_op_tbl            := l_eam_op_tbl;
3334                 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
3335                 l_out_eam_res_tbl           := l_eam_res_tbl;
3336                 l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
3337                 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
3338                 l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
3339                 l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
3340                 l_out_eam_direct_items_tbl  := l_eam_direct_items_tbl;
3341 
3342 		l_out_eam_wo_comp_rec          := l_eam_wo_comp_rec;
3343 		l_out_eam_wo_quality_tbl       := l_eam_wo_quality_tbl;
3344 		l_out_eam_meter_reading_tbl    := l_eam_meter_reading_tbl;
3345 		l_out_eam_wo_comp_rebuild_tbl  := l_eam_wo_comp_rebuild_tbl;
3346 		l_out_eam_counter_prop_tbl     := l_eam_counter_prop_tbl;
3347 		l_out_eam_wo_comp_mr_read_tbl  := l_eam_wo_comp_mr_read_tbl;
3348 		l_out_eam_op_comp_tbl          := l_eam_op_comp_tbl;
3349 		l_out_eam_request_tbl          := l_eam_request_tbl;
3350 
3351                 EAM_ERROR_MESSAGE_PVT.Log_Error
3352                 (  p_eam_wo_rec             => l_eam_wo_rec
3353                 ,  p_eam_op_tbl             => l_eam_op_tbl
3354                 ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
3355                 ,  p_eam_res_tbl            => l_eam_res_tbl
3356                 ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
3357                 ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
3358                 ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
3359                 ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
3360                 ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
3361                 ,  p_Mesg_Token_Tbl         => l_Mesg_Token_Tbl
3362                 ,  p_error_status           => 'W'
3363                 ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_BO_LEVEL
3364                 ,  x_eam_wo_rec             => l_out_eam_wo_rec
3365                 ,  x_eam_op_tbl             => l_out_eam_op_tbl
3366                 ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
3367                 ,  x_eam_res_tbl            => l_out_eam_res_tbl
3368                 ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
3369                 ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
3370                 ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
3371                 ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
3372                 ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
3373                  );
3374 
3375                 l_eam_wo_rec            := l_out_eam_wo_rec;
3376                 l_eam_op_tbl            := l_out_eam_op_tbl;
3377                 l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
3378                 l_eam_res_tbl           := l_out_eam_res_tbl;
3379                 l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
3380                 l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
3381                 l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
3382                 l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
3383                 l_eam_direct_items_tbl  := l_out_eam_direct_items_tbl;
3384 
3385 		l_eam_wo_comp_rec         := l_out_eam_wo_comp_rec        ;
3386 		l_eam_wo_quality_tbl      := l_out_eam_wo_quality_tbl     ;
3387 		l_eam_meter_reading_tbl   := l_out_eam_meter_reading_tbl  ;
3388 		l_eam_wo_comp_rebuild_tbl := l_out_eam_wo_comp_rebuild_tbl;
3389 		l_eam_counter_prop_tbl    := l_out_eam_counter_prop_tbl   ;
3390 		l_eam_wo_comp_mr_read_tbl := l_out_eam_wo_comp_mr_read_tbl;
3391 		l_eam_op_comp_tbl         := l_out_eam_op_comp_tbl        ;
3392 		l_eam_request_tbl         := l_out_eam_request_tbl        ;
3393 
3394 		l_debug_flag := 'N';
3395 
3396             END IF;
3397 
3398             EAM_PROCESS_WO_PVT.Set_Debug(l_debug_flag);
3399 
3400             IF l_debug_flag = 'Y'
3401             THEN
3402                 l_out_mesg_token_tbl        := l_mesg_token_tbl;
3403                 EAM_ERROR_MESSAGE_PVT.Open_Debug_Session
3404                 (  p_debug_filename     => p_debug_filename
3405                 ,  p_output_dir         => p_output_dir
3406                 ,  p_debug_file_mode    => l_debug_file_mode
3407                 ,  x_return_status      => l_return_status
3408                 ,  p_mesg_token_tbl     => l_mesg_token_tbl
3409                 ,  x_mesg_token_tbl     => l_out_mesg_token_tbl
3410                  );
3411                 l_mesg_token_tbl        := l_out_mesg_token_tbl;
3412 
3413                 IF l_return_status <> FND_API.G_RET_STS_SUCCESS
3414                 THEN
3415                     EAM_PROCESS_WO_PVT.Set_Debug('N');
3416                 END IF;
3417             END IF;
3418 
3419         END IF;
3420 
3421 IF EAM_PROCESS_WO_PVT.get_debug = 'Y' THEN
3422     EAM_ERROR_MESSAGE_PVT.write_debug('==================================================Work Order==============================================================');
3423     EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Start ========= fnd_global.user_id: '||FND_GLOBAL.user_id||' fnd_global.resp_id: '||fnd_global.resp_id||' login_id: '||FND_GLOBAL.login_id);
3424     EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Workorder: ' || p_eam_wo_rec.wip_entity_name||'  Wip Entity Id : '||p_eam_wo_rec.wip_entity_id);
3425     EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Transaction Type : '||l_eam_wo_rec.TRANSACTION_TYPE||' (1:Create / 2:Update / 3:Delete / 4:Complete / 5:UnComplete)');
3426     EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : System Status Id : '||p_eam_wo_rec.STATUS_TYPE||' User Defined Status Id : '||p_eam_wo_rec.USER_DEFINED_STATUS_ID);
3427     EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Scheduled Start date : '||to_char(p_eam_wo_rec.SCHEDULED_START_DATE,'DD-MON-YY HH:MI:SS'));
3428     EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Scheduled Completion Date : '||to_char(p_eam_wo_rec.SCHEDULED_COMPLETION_DATE,'DD-MON-YY HH:MI:SS'));
3429     EAM_ERROR_MESSAGE_PVT.write_debug('');
3430     EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Num of operations: ' || p_eam_op_tbl.COUNT);
3431     EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Num of resources: ' || p_eam_res_tbl.COUNT);
3432     EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Num of materials: ' || p_eam_mat_req_tbl.COUNT);
3433     EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Num of direct items: ' || p_eam_direct_items_tbl.COUNT);
3434     EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Num of sub resources: ' || p_eam_sub_res_tbl.COUNT);
3435     EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Num of resource inst: ' || p_eam_res_inst_tbl.COUNT);
3436     EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Num of op networks: ' || p_eam_op_network_tbl.COUNT);
3437 
3438     EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Workorder Completion Rec WipEntityId: ' || l_eam_wo_comp_rec.wip_entity_id);
3439     EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Num of qua records: ' || p_eam_wo_quality_tbl.COUNT);
3440     EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Num of meter rdg recs: ' || p_eam_meter_reading_tbl.COUNT);
3441     EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Num of counter prop recs: ' || p_eam_counter_prop_tbl.COUNT);
3442     EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Num of completion rebld recs: ' || p_eam_wo_comp_rebuild_tbl.COUNT);
3443     EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Num of completion meter rdg recs: ' || p_eam_wo_comp_mr_read_tbl.COUNT);
3444     EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Num of op completion recs: ' || p_eam_op_comp_tbl.COUNT);
3445     EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Num of work request recs: ' || p_eam_request_tbl.COUNT);
3446 END IF;
3447 
3448 
3449 
3450         --
3451         -- Verify if all the entity record(s) belong to the same business object
3452         --
3453 IF EAM_PROCESS_WO_PVT.get_debug = 'Y' then EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS__WO : Calling Check_BO_Record procedure, BO record validation'); END IF;
3454 
3455        CHECK_BO_RECORD
3456          ( p_eam_wo_rec                    =>  l_eam_wo_rec
3457          , p_eam_op_tbl                    =>  l_eam_op_tbl
3458          , p_eam_op_network_tbl            =>  l_eam_op_network_tbl
3459          , p_eam_res_tbl                   =>  l_eam_res_tbl
3460          , p_eam_res_inst_tbl              =>  l_eam_res_inst_tbl
3461          , p_eam_sub_res_tbl               =>  l_eam_sub_res_tbl
3462          , p_eam_res_usage_tbl             =>  l_eam_res_usage_tbl
3463          , p_eam_mat_req_tbl               =>  l_eam_mat_req_tbl
3464          , p_eam_direct_items_tbl          =>  l_eam_direct_items_tbl
3465  	 , p_eam_wo_comp_rec		   =>  l_eam_wo_comp_rec
3466 	 , p_eam_wo_quality_tbl		   =>  l_eam_wo_quality_tbl
3467 	 , p_eam_meter_reading_tbl	   =>  l_eam_meter_reading_tbl
3468 	 , p_eam_counter_prop_tbl	   =>  l_eam_counter_prop_tbl
3469 	 , p_eam_wo_comp_rebuild_tbl	   =>  l_eam_wo_comp_rebuild_tbl
3470 	 , p_eam_wo_comp_mr_read_tbl	   =>  l_eam_wo_comp_mr_read_tbl
3471 	 , p_eam_op_comp_tbl		   =>  l_eam_op_comp_tbl
3472 	 , p_eam_request_tbl		   =>  l_eam_request_tbl
3473          , x_return_status                 =>  l_return_status
3474        );
3475 
3476 
3477 
3478         IF l_return_status <> 'S' THEN
3479             RAISE G_EXC_SEV_QUIT_OBJECT;
3480         END IF;
3481 IF EAM_PROCESS_WO_PVT.get_debug = 'Y' then EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS__WO : BO record validation Successful'); END IF;
3482 
3483         --
3484         -- Call the Private API for performing further business rules validation
3485         --
3486 
3487 IF (p_eam_wo_rec.transaction_type IS NOT NULL)
3488    OR (p_eam_op_tbl.COUNT > 0) OR (p_eam_op_network_tbl.COUNT >0)
3489    OR (p_eam_res_tbl.COUNT >0) OR (p_eam_res_inst_tbl.COUNT >0) OR (p_eam_sub_res_tbl.COUNT >0)
3490    OR (p_eam_mat_req_tbl.COUNT >0) OR (p_eam_direct_items_tbl.COUNT >0) OR (p_eam_res_usage_tbl.COUNT>0)
3491 THEN
3492 
3493 IF EAM_PROCESS_WO_PVT.get_debug = 'Y' then EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS__WO : Calling the EAM_PROCESS_WO_PVT.PROCESS_WO procedure'); END IF;
3494 
3495 EAM_PROCESS_WO_PVT.PROCESS_WO
3496         (  p_api_version_number            =>  p_api_version_number
3497          , x_return_status                 =>  x_return_status
3498          , x_msg_count                     =>  x_msg_count
3499          , p_eam_wo_rec                    =>  l_eam_wo_rec
3500          , p_eam_op_tbl                    =>  p_eam_op_tbl
3501          , p_eam_op_network_tbl            =>  p_eam_op_network_tbl
3502          , p_eam_res_tbl                   =>  p_eam_res_tbl
3503          , p_eam_res_inst_tbl              =>  p_eam_res_inst_tbl
3504          , p_eam_sub_res_tbl               =>  p_eam_sub_res_tbl
3505          , p_eam_res_usage_tbl             =>  p_eam_res_usage_tbl
3506          , p_eam_mat_req_tbl               =>  p_eam_mat_req_tbl
3507          , p_eam_direct_items_tbl          =>  p_eam_direct_items_tbl
3508          , x_eam_wo_rec                    =>  x_eam_wo_rec
3509          , x_eam_op_tbl                    =>  x_eam_op_tbl
3510          , x_eam_op_network_tbl            =>  x_eam_op_network_tbl
3511          , x_eam_res_tbl                   =>  x_eam_res_tbl
3512          , x_eam_res_inst_tbl              =>  x_eam_res_inst_tbl
3513          , x_eam_sub_res_tbl               =>  x_eam_sub_res_tbl
3514          , x_eam_res_usage_tbl             =>  x_eam_res_usage_tbl
3515          , x_eam_mat_req_tbl               =>  x_eam_mat_req_tbl
3516          , x_eam_direct_items_tbl          =>  x_eam_direct_items_tbl
3517          );
3518 
3519         l_return_status := x_return_status;
3520         IF l_return_status <> 'S'
3521         THEN
3522 
3523         l_eam_wo_rec            := x_eam_wo_rec;
3524         l_eam_op_tbl            := x_eam_op_tbl;
3525         l_eam_op_network_tbl    := x_eam_op_network_tbl;
3526         l_eam_res_tbl           := x_eam_res_tbl;
3527         l_eam_res_inst_tbl      := x_eam_res_inst_tbl;
3528         l_eam_sub_res_tbl       := x_eam_sub_res_tbl;
3529         l_eam_res_usage_tbl     := x_eam_res_usage_tbl;
3530         l_eam_mat_req_tbl       := x_eam_mat_req_tbl;
3531         l_eam_direct_items_tbl  := x_eam_direct_items_tbl;
3532 
3533         -- Call Error Handler
3534 
3535         l_token_tbl(1).token_name := 'WIP_ENTITY_NAME';
3536         l_token_tbl(1).token_value := p_eam_wo_rec.wip_entity_name;
3537         l_token_tbl(2).token_name := 'ORGANIZATION_ID';
3538         l_token_tbl(2).token_value := p_eam_wo_rec.organization_id;
3539 
3540         l_out_eam_wo_rec            := l_eam_wo_rec;
3541         l_out_eam_op_tbl            := l_eam_op_tbl;
3542         l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
3543         l_out_eam_res_tbl           := l_eam_res_tbl;
3544         l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
3545         l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
3546         l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
3547         l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
3548         l_out_eam_direct_items_tbl  := l_eam_direct_items_tbl;
3549 
3550         EAM_ERROR_MESSAGE_PVT.Log_Error
3551         (  p_eam_wo_rec             => l_eam_wo_rec
3552         ,  p_eam_op_tbl             => l_eam_op_tbl
3553         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
3554         ,  p_eam_res_tbl            => l_eam_res_tbl
3555         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
3556         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
3557         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
3558         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
3559         ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
3560         ,  p_mesg_token_tbl         => l_mesg_token_tbl
3561         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
3562         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_ALL
3563         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_BO_LEVEL
3564         ,  p_other_message          => l_other_message
3565         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
3566         ,  p_other_token_tbl        => l_token_tbl
3567         ,  x_eam_wo_rec             => l_out_eam_wo_rec
3568         ,  x_eam_op_tbl             => l_out_eam_op_tbl
3569         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
3570         ,  x_eam_res_tbl            => l_out_eam_res_tbl
3571         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
3572         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
3573         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
3574         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
3575         ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
3576         );
3577 
3578         l_eam_wo_rec            := l_out_eam_wo_rec;
3579         l_eam_op_tbl            := l_out_eam_op_tbl;
3580         l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
3581         l_eam_res_tbl           := l_out_eam_res_tbl;
3582         l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
3583         l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
3584         l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
3585         l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
3586         l_eam_direct_items_tbl  := l_out_eam_direct_items_tbl;
3587 
3588         x_eam_wo_rec            := l_eam_wo_rec;
3589         x_eam_op_tbl            := l_eam_op_tbl;
3590         x_eam_op_network_tbl    := l_eam_op_network_tbl;
3591         x_eam_res_tbl           := l_eam_res_tbl;
3592         x_eam_res_inst_tbl      := l_eam_res_inst_tbl;
3593         x_eam_sub_res_tbl       := l_eam_sub_res_tbl;
3594         x_eam_res_usage_tbl     := l_eam_res_usage_tbl;
3595         x_eam_mat_req_tbl       := l_eam_mat_req_tbl;
3596         x_eam_direct_items_tbl  := l_eam_direct_items_tbl;
3597            END IF;
3598 
3599 --removed code for failure entry and shifted it to EAMVWOPB.pls
3600 
3601 
3602         x_return_status := l_return_status;
3603 
3604   IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN
3605   EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : End ======= Return Status from EAM_PROCESS_WO_PVT.PROCESS_WO : ' ||l_return_status||' Wip Entity Id: '||x_eam_wo_rec.wip_entity_id) ;
3606   END IF ;
3607 
3608         x_msg_count := EAM_ERROR_MESSAGE_PVT.Get_Message_Count;
3609 
3610         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y'
3611         THEN
3612             EAM_ERROR_MESSAGE_PVT.Dump_Message_List;
3613 	    IF p_eam_request_tbl.COUNT = 0 THEN
3614 	            EAM_ERROR_MESSAGE_PVT.Close_Debug_Session;
3615 	    END IF;
3616         END IF;
3617 
3618 
3619         -- Standard check of p_commit.
3620         IF p_commit = 'Y' THEN
3621                 COMMIT WORK;
3622         END IF;
3623 
3624 
3625 	IF p_eam_request_tbl.COUNT > 0 THEN
3626 		FOR mm in p_eam_request_tbl.FIRST..p_eam_request_tbl.LAST LOOP
3627 			IF p_eam_request_tbl(mm).wip_entity_id IS NULL THEN
3628 				l_eam_request_tbl(mm).wip_entity_id := x_eam_wo_rec.wip_entity_id;
3629 			END IF;
3630 		END LOOP;
3631 	END IF;
3632 
3633 END IF;
3634 
3635 	IF (p_eam_wo_comp_rec.transaction_type is not null) THEN
3636 	  IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Calling EAM_PROCESS_WO_PVT.COMP_UNCOMP_WORKORDER') ;   END IF ;
3637 
3638 
3639 		EAM_PROCESS_WO_PVT.COMP_UNCOMP_WORKORDER
3640 		(
3641 		  p_eam_wo_comp_rec            => p_eam_wo_comp_rec
3642 		, p_eam_wo_quality_tbl         => p_eam_wo_quality_tbl
3643 		, p_eam_meter_reading_tbl      => p_eam_meter_reading_tbl
3644 		, p_eam_counter_prop_tbl    => l_eam_counter_prop_tbl
3645 		, p_eam_wo_comp_rebuild_tbl    => p_eam_wo_comp_rebuild_tbl
3646 		, p_eam_wo_comp_mr_read_tbl    => p_eam_wo_comp_mr_read_tbl
3647 		, x_eam_wo_comp_rec            => x_eam_wo_comp_rec
3648 		, x_eam_wo_quality_tbl         => x_eam_wo_quality_tbl
3649 		, x_eam_meter_reading_tbl      => x_eam_meter_reading_tbl
3650 		, x_eam_counter_prop_tbl    => l_out_eam_counter_prop_tbl
3651 		, x_eam_wo_comp_rebuild_tbl    => x_eam_wo_comp_rebuild_tbl
3652 		, x_eam_wo_comp_mr_read_tbl    => x_eam_wo_comp_mr_read_tbl
3653 		, x_return_status              => l_return_status
3654 		, x_msg_count                  => l_msg_count
3655 		);
3656 
3657 	        x_return_status := l_return_status;
3658 		x_msg_count := l_msg_count;
3659 	  IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Return status from EAM_PROCESS_WO_PVT.COMP_UNCOMP_WORKORDER: '||l_return_status); END IF ;
3660 
3661 
3662 		 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y'
3663 	        THEN
3664 		    EAM_ERROR_MESSAGE_PVT.Dump_Message_List;
3665 	            EAM_ERROR_MESSAGE_PVT.Close_Debug_Session;
3666 	        END IF;
3667 
3668 
3669 	END IF;
3670 
3671 	IF p_eam_op_comp_tbl.COUNT > 0 THEN
3672 	  IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Calling EAM_PROCESS_WO_PVT.COMP_UNCOMP_OPERATION') ;   END IF ;
3673 
3674 		EAM_PROCESS_WO_PVT.COMP_UNCOMP_OPERATION
3675 		(
3676 		  p_eam_op_compl_tbl	    => p_eam_op_comp_tbl
3677 		, p_eam_wo_quality_tbl      => p_eam_wo_quality_tbl
3678 		, x_eam_op_comp_tbl         => x_eam_op_comp_tbl
3679 		, x_eam_wo_quality_tbl      => x_eam_wo_quality_tbl
3680 		, x_return_status           => l_return_status
3681 		, x_msg_count               => l_msg_count
3682 		);
3683 
3684 	        x_return_status := l_return_status;
3685 		x_msg_count := l_msg_count;
3686 	  IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Return status from EAM_PROCESS_WO_PVT.COMP_UNCOMP_OPERATION: '||l_return_status); END IF ;
3687 
3688 		 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y'
3689 	        THEN
3690 		    EAM_ERROR_MESSAGE_PVT.Dump_Message_List;
3691 	            EAM_ERROR_MESSAGE_PVT.Close_Debug_Session;
3692 	        END IF;
3693 
3694 
3695 	END IF;
3696 
3697 
3698 	IF p_eam_request_tbl.COUNT > 0 THEN
3699 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Calling EAM_PROCESS_WO_PVT.SERVICE_WORKREQUEST_ASSO'); END IF ;
3700 		EAM_PROCESS_WO_PVT.SERVICE_WORKREQUEST_ASSO
3701 		(
3702 		  p_eam_request_tbl	    => l_eam_request_tbl
3703 		, x_eam_request_tbl         => x_eam_request_tbl
3704 		, x_return_status           => l_return_status
3705 		, x_msg_count               => l_msg_count
3706 		);
3707 
3708 	        x_return_status := l_return_status;
3709 		x_msg_count := l_msg_count;
3710 
3711 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Return status from EAM_PROCESS_WO_PVT.SERVICE_WORKREQUEST_ASSO : '||l_return_status); END IF ;
3712 
3713 		 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y'
3714 	        THEN
3715 		    EAM_ERROR_MESSAGE_PVT.Dump_Message_List;
3716 	            EAM_ERROR_MESSAGE_PVT.Close_Debug_Session;
3717 	        END IF;
3718 
3719 
3720 	END IF;
3721 
3722     EXCEPTION
3723     WHEN G_EXC_SEV_QUIT_OBJECT THEN
3724 
3725         -- baroy
3726         -- This exception is raised only by the CHECK_BO_RECORD
3727         -- procedure. In that procedure, the error message has already
3728         -- been logged. There is no need to do it again.
3729 
3730 
3731 
3732         x_return_status := EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
3733         x_msg_count     := EAM_ERROR_MESSAGE_PVT.Get_Message_Count;
3734 
3735         x_eam_wo_rec            := l_eam_wo_rec;
3736         x_eam_op_tbl            := l_eam_op_tbl;
3737         x_eam_op_network_tbl    := l_eam_op_network_tbl;
3738         x_eam_res_tbl           := l_eam_res_tbl;
3739         x_eam_res_inst_tbl      := l_eam_res_inst_tbl;
3740         x_eam_sub_res_tbl       := l_eam_sub_res_tbl;
3741         x_eam_res_usage_tbl     := l_eam_res_usage_tbl;
3742         x_eam_mat_req_tbl       := l_eam_mat_req_tbl;
3743         x_eam_direct_items_tbl  := l_eam_direct_items_tbl;
3744 
3745 	x_eam_wo_comp_rec         := l_eam_wo_comp_rec;
3746 	x_eam_wo_quality_tbl      := l_eam_wo_quality_tbl;
3747 	x_eam_meter_reading_tbl   := l_eam_meter_reading_tbl;
3748 	x_eam_counter_prop_tbl    := l_eam_counter_prop_tbl;
3749 	x_eam_wo_comp_rebuild_tbl := l_eam_wo_comp_rebuild_tbl;
3750 	x_eam_wo_comp_mr_read_tbl := l_eam_wo_comp_mr_read_tbl;
3751 	x_eam_op_comp_tbl         := l_eam_op_comp_tbl;
3752 	x_eam_request_tbl     	  := l_eam_request_tbl;
3753 
3754         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y'
3755         THEN
3756             EAM_ERROR_MESSAGE_PVT.Dump_Message_List;
3757             EAM_ERROR_MESSAGE_PVT.Close_Debug_Session;
3758         END IF;
3759 
3760 
3761     WHEN G_EXC_UNEXP_SKIP_OBJECT THEN
3762 
3763     -- Call Error Handler
3764 
3765         l_out_eam_wo_rec            := l_eam_wo_rec;
3766         l_out_eam_op_tbl            := l_eam_op_tbl;
3767         l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
3768         l_out_eam_res_tbl           := l_eam_res_tbl;
3769         l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
3770         l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
3771         l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
3772         l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
3773         l_out_eam_direct_items_tbl  := l_eam_direct_items_tbl;
3774 
3775 	l_out_eam_wo_comp_rec          := l_eam_wo_comp_rec;
3776 	l_out_eam_wo_quality_tbl       := l_eam_wo_quality_tbl;
3777 	l_out_eam_meter_reading_tbl    := l_eam_meter_reading_tbl;
3778 	l_out_eam_wo_comp_rebuild_tbl  := l_eam_wo_comp_rebuild_tbl;
3779 	l_out_eam_counter_prop_tbl     := l_eam_counter_prop_tbl;
3780 	l_out_eam_wo_comp_mr_read_tbl  := l_eam_wo_comp_mr_read_tbl;
3781 	l_out_eam_op_comp_tbl          := l_eam_op_comp_tbl;
3782 	l_out_eam_request_tbl          := l_eam_request_tbl;
3783 
3784         EAM_ERROR_MESSAGE_PVT.Log_Error
3785         (  p_eam_wo_rec             => l_eam_wo_rec
3786         ,  p_eam_op_tbl             => l_eam_op_tbl
3787         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
3788         ,  p_eam_res_tbl            => l_eam_res_tbl
3789         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
3790         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
3791         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
3792         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
3793         ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
3794         ,  p_mesg_token_tbl         => l_mesg_token_tbl
3795         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
3796         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_BO_LEVEL
3797         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_NOT_PICKED
3798         ,  p_other_message          => l_other_message
3799         ,  p_other_token_tbl        => l_token_tbl
3800         ,  x_eam_wo_rec             => l_out_eam_wo_rec
3801         ,  x_eam_op_tbl             => l_out_eam_op_tbl
3802         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
3803         ,  x_eam_res_tbl            => l_out_eam_res_tbl
3804         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
3805         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
3806         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
3807         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
3808         ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
3809         );
3810 
3811         l_eam_wo_rec            := l_out_eam_wo_rec;
3812         l_eam_op_tbl            := l_out_eam_op_tbl;
3813         l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
3814         l_eam_res_tbl           := l_out_eam_res_tbl;
3815         l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
3816         l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
3817         l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
3818         l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
3819         l_eam_direct_items_tbl  := l_out_eam_direct_items_tbl;
3820 
3821 	l_eam_wo_comp_rec         := l_out_eam_wo_comp_rec        ;
3822 	l_eam_wo_quality_tbl      := l_out_eam_wo_quality_tbl     ;
3823 	l_eam_meter_reading_tbl   := l_out_eam_meter_reading_tbl  ;
3824 	l_eam_wo_comp_rebuild_tbl := l_out_eam_wo_comp_rebuild_tbl;
3825 	l_eam_counter_prop_tbl    := l_out_eam_counter_prop_tbl   ;
3826 	l_eam_wo_comp_mr_read_tbl := l_out_eam_wo_comp_mr_read_tbl;
3827 	l_eam_op_comp_tbl         := l_out_eam_op_comp_tbl        ;
3828 	l_eam_request_tbl         := l_out_eam_request_tbl        ;
3829 
3830         x_eam_wo_rec            := l_eam_wo_rec;
3831         x_eam_op_tbl            := l_eam_op_tbl;
3832         x_eam_op_network_tbl    := l_eam_op_network_tbl;
3833         x_eam_res_tbl           := l_eam_res_tbl;
3834         x_eam_res_inst_tbl      := l_eam_res_inst_tbl;
3835         x_eam_sub_res_tbl       := l_eam_sub_res_tbl;
3836         x_eam_res_usage_tbl     := l_eam_res_usage_tbl;
3837         x_eam_mat_req_tbl       := l_eam_mat_req_tbl;
3838         x_eam_direct_items_tbl  := l_eam_direct_items_tbl;
3839 
3840 	x_eam_wo_comp_rec         := l_eam_wo_comp_rec;
3841 	x_eam_wo_quality_tbl      := l_eam_wo_quality_tbl;
3842 	x_eam_meter_reading_tbl   := l_eam_meter_reading_tbl;
3843 	x_eam_counter_prop_tbl    := l_eam_counter_prop_tbl;
3844 	x_eam_wo_comp_rebuild_tbl := l_eam_wo_comp_rebuild_tbl;
3845 	x_eam_wo_comp_mr_read_tbl := l_eam_wo_comp_mr_read_tbl;
3846 	x_eam_op_comp_tbl         := l_eam_op_comp_tbl;
3847 	x_eam_request_tbl     	  := l_eam_request_tbl;
3848 
3849         x_return_status := EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED;
3850         x_msg_count     := EAM_ERROR_MESSAGE_PVT.Get_Message_Count;
3851 
3852         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y'
3853         THEN
3854             EAM_ERROR_MESSAGE_PVT.Dump_Message_List;
3855             EAM_ERROR_MESSAGE_PVT.Close_Debug_Session;
3856         END IF;
3857 
3858 
3859     WHEN OTHERS THEN
3860 
3861         -- Call Error Handler
3862 
3863       EAM_ERROR_MESSAGE_PVT.Add_Error_Token
3864         (  p_message_name  => 'EAM_PR_WO_UNKNOWN_ERROR'
3865          , p_token_tbl     => l_token_tbl
3866          , p_mesg_token_tbl     => l_mesg_token_tbl
3867          , x_mesg_token_tbl     => l_out_mesg_token_tbl
3868       );
3869       l_mesg_token_tbl := l_out_mesg_token_tbl;
3870 
3871       l_other_message := 'EAM_PR_WO_CSEV_SKIP';
3872 
3873         l_out_eam_wo_rec            := l_eam_wo_rec;
3874         l_out_eam_op_tbl            := l_eam_op_tbl;
3875         l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
3876         l_out_eam_res_tbl           := l_eam_res_tbl;
3877         l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
3878         l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
3879         l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
3880         l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
3881         l_out_eam_direct_items_tbl  := l_eam_direct_items_tbl;
3882 
3883 	l_out_eam_wo_comp_rec          := l_eam_wo_comp_rec;
3884 	l_out_eam_wo_quality_tbl       := l_eam_wo_quality_tbl;
3885 	l_out_eam_meter_reading_tbl    := l_eam_meter_reading_tbl;
3886 	l_out_eam_wo_comp_rebuild_tbl  := l_eam_wo_comp_rebuild_tbl;
3887 	l_out_eam_counter_prop_tbl     := l_eam_counter_prop_tbl;
3888 	l_out_eam_wo_comp_mr_read_tbl  := l_eam_wo_comp_mr_read_tbl;
3889 	l_out_eam_op_comp_tbl          := l_eam_op_comp_tbl;
3890 	l_out_eam_request_tbl          := l_eam_request_tbl;
3891 
3892         EAM_ERROR_MESSAGE_PVT.Log_Error
3893         (  p_eam_wo_rec             => l_eam_wo_rec
3894         ,  p_eam_op_tbl             => l_eam_op_tbl
3895         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
3896         ,  p_eam_res_tbl            => l_eam_res_tbl
3897         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
3898         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
3899         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
3900         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
3901         ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
3902         ,  p_mesg_token_tbl         => l_mesg_token_tbl
3903         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
3904         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_BO_LEVEL
3905         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
3906         ,  p_other_message          => l_other_message
3907         ,  x_eam_wo_rec             => l_out_eam_wo_rec
3908         ,  x_eam_op_tbl             => l_out_eam_op_tbl
3909         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
3910         ,  x_eam_res_tbl            => l_out_eam_res_tbl
3911         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
3912         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
3913         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
3914         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
3915         ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
3916         );
3917 
3918         l_eam_wo_rec            := l_out_eam_wo_rec;
3919         l_eam_op_tbl            := l_out_eam_op_tbl;
3920         l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
3921         l_eam_res_tbl           := l_out_eam_res_tbl;
3922         l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
3923         l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
3924         l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
3925         l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
3926         l_eam_direct_items_tbl  := l_out_eam_direct_items_tbl;
3927 
3928 	l_eam_wo_comp_rec         := l_out_eam_wo_comp_rec        ;
3929 	l_eam_wo_quality_tbl      := l_out_eam_wo_quality_tbl     ;
3930 	l_eam_meter_reading_tbl   := l_out_eam_meter_reading_tbl  ;
3931 	l_eam_wo_comp_rebuild_tbl := l_out_eam_wo_comp_rebuild_tbl;
3932 	l_eam_counter_prop_tbl    := l_out_eam_counter_prop_tbl   ;
3933 	l_eam_wo_comp_mr_read_tbl := l_out_eam_wo_comp_mr_read_tbl;
3934 	l_eam_op_comp_tbl         := l_out_eam_op_comp_tbl        ;
3935 	l_eam_request_tbl         := l_out_eam_request_tbl        ;
3936 
3937         x_eam_wo_rec            := l_eam_wo_rec;
3938         x_eam_op_tbl            := l_eam_op_tbl;
3939         x_eam_op_network_tbl    := l_eam_op_network_tbl;
3940         x_eam_res_tbl           := l_eam_res_tbl;
3941         x_eam_res_inst_tbl      := l_eam_res_inst_tbl;
3942         x_eam_sub_res_tbl       := l_eam_sub_res_tbl;
3943         x_eam_res_usage_tbl     := l_eam_res_usage_tbl;
3944         x_eam_mat_req_tbl       := l_eam_mat_req_tbl;
3945         x_eam_direct_items_tbl  := l_eam_direct_items_tbl;
3946 
3947 	x_eam_wo_comp_rec         := l_eam_wo_comp_rec;
3948 	x_eam_wo_quality_tbl      := l_eam_wo_quality_tbl;
3949 	x_eam_meter_reading_tbl   := l_eam_meter_reading_tbl;
3950 	x_eam_counter_prop_tbl    := l_eam_counter_prop_tbl;
3951 	x_eam_wo_comp_rebuild_tbl := l_eam_wo_comp_rebuild_tbl;
3952 	x_eam_wo_comp_mr_read_tbl := l_eam_wo_comp_mr_read_tbl;
3953 	x_eam_op_comp_tbl         := l_eam_op_comp_tbl;
3954 	x_eam_request_tbl     	  := l_eam_request_tbl;
3955 
3956         x_return_status := EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED;
3957         x_msg_count     := EAM_ERROR_MESSAGE_PVT.Get_Message_Count;
3958 
3959         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y'
3960         THEN
3961             EAM_ERROR_MESSAGE_PVT.Dump_Message_List;
3962             EAM_ERROR_MESSAGE_PVT.Close_Debug_Session;
3963         END IF;
3964 
3965 
3966 END PROCESS_WO;
3967 
3968 
3969 PROCEDURE PROCESS_WO
3970         (  p_bo_identifier           IN  VARCHAR2 := 'EAM'
3971          , p_api_version_number      IN  NUMBER := 1.0
3972          , p_init_msg_list           IN  BOOLEAN := FALSE
3973          , p_commit                  IN  VARCHAR2 := 'N'
3974          , p_eam_wo_rec              IN  EAM_PROCESS_WO_PUB.eam_wo_rec_type
3975          , p_eam_op_tbl              IN  EAM_PROCESS_WO_PUB.eam_op_tbl_type
3976          , p_eam_op_network_tbl      IN  EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
3977          , p_eam_res_tbl             IN  EAM_PROCESS_WO_PUB.eam_res_tbl_type
3978          , p_eam_res_inst_tbl        IN  EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
3979          , p_eam_sub_res_tbl         IN  EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
3980          , p_eam_res_usage_tbl       IN  EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
3981          , p_eam_mat_req_tbl         IN  EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
3982          , p_eam_direct_items_tbl    IN  EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
3983           , p_eam_wo_comp_rec         IN  EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type
3984          , p_eam_wo_quality_tbl      IN  EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type
3985          , p_eam_meter_reading_tbl   IN  EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type
3986           , p_eam_counter_prop_tbl    IN  EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type
3987          , p_eam_wo_comp_rebuild_tbl IN  EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type
3988          , p_eam_wo_comp_mr_read_tbl IN  EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type
3989          , p_eam_op_comp_tbl         IN  EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type
3990          , p_eam_request_tbl         IN  EAM_PROCESS_WO_PUB.eam_request_tbl_type
3991          , p_eam_permit_tbl          IN  EAM_PROCESS_PERMIT_PUB.eam_wp_tbl_type -- new param for safety permit
3992          , p_eam_permit_wo_assoc_tbl IN EAM_PROCESS_PERMIT_PUB.eam_wp_association_tbl_type -- new param for safety permit
3993          , x_eam_wo_rec              OUT NOCOPY EAM_PROCESS_WO_PUB.eam_wo_rec_type
3994          , x_eam_op_tbl              OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_tbl_type
3995          , x_eam_op_network_tbl      OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
3996          , x_eam_res_tbl             OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_tbl_type
3997          , x_eam_res_inst_tbl        OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
3998          , x_eam_sub_res_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
3999          , x_eam_res_usage_tbl       OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
4000          , x_eam_mat_req_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
4001          , x_eam_direct_items_tbl    OUT NOCOPY EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
4002         , x_eam_wo_comp_rec         OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type
4003          , x_eam_wo_quality_tbl      OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type
4004          , x_eam_meter_reading_tbl   OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type
4005         , x_eam_counter_prop_tbl    OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type
4006          , x_eam_wo_comp_rebuild_tbl OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type
4007          , x_eam_wo_comp_mr_read_tbl OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type
4008          , x_eam_op_comp_tbl         OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type
4009          , x_eam_request_tbl         OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_request_tbl_type
4010          , x_return_status           OUT NOCOPY VARCHAR2
4011          , x_msg_count               OUT NOCOPY NUMBER
4012          , p_debug                   IN  VARCHAR2 := 'N'
4013          , p_output_dir              IN  VARCHAR2 := NULL
4014          , p_debug_filename          IN  VARCHAR2 := 'EAM_WO_DEBUG.log'
4015          , p_debug_file_mode         IN  VARCHAR2 := 'w'
4016          ) IS
4017 
4018           l_eam_permit_tbl EAM_PROCESS_SAFETY_PUB.eam_wp_tbl_type;
4019           l_eam_permit_wo_assoc_tbl EAM_PROCESS_SAFETY_PUB.eam_safety_assoc_tbl_type;
4020           l_eam_work_clearance_tbl   EAM_PROCESS_SAFETY_PUB.eam_clearance_header_tbl_type ;
4021 		      l_eam_wc_wo_assoc_tbl      EAM_PROCESS_SAFETY_PUB.eam_safety_assoc_tbl_type;
4022 
4023 		 BEGIN
4024 
4025 	  IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Overloaded procedure for Safety Permits : Start ====================='); END IF ;
4026 
4027 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Overloaded procedure for Safety Permits : Preparing permit header and association tables'); END IF ;
4028 
4029 			-- copy old table in 12.1.3 code to 12.2 code.
4030 
4031 	IF(p_eam_permit_tbl IS NOT NULL AND p_eam_permit_tbl.COUNT>0) THEN
4032 
4033 		FOR i IN  p_eam_permit_tbl.FIRST ..  p_eam_permit_tbl.LAST LOOP
4034 			l_eam_permit_tbl(i).HEADER_ID:=         	    p_eam_permit_tbl(i).HEADER_ID;
4035 			l_eam_permit_tbl(i).BATCH_ID:=		            p_eam_permit_tbl(i).BATCH_ID;
4036 			l_eam_permit_tbl(i).ROW_ID:=	                p_eam_permit_tbl(i).ROW_ID;
4037 			l_eam_permit_tbl(i).TRANSACTION_TYPE:=          p_eam_permit_tbl(i).TRANSACTION_TYPE;
4038 			l_eam_permit_tbl(i).PERMIT_ID:= 	            p_eam_permit_tbl(i).PERMIT_ID;
4039 			l_eam_permit_tbl(i).PERMIT_NAME:=	            p_eam_permit_tbl(i).PERMIT_NAME;
4040 			l_eam_permit_tbl(i).PERMIT_TYPE:=               p_eam_permit_tbl(i).PERMIT_TYPE;
4041 			l_eam_permit_tbl(i).DESCRIPTION:=		        p_eam_permit_tbl(i).DESCRIPTION;
4042 			l_eam_permit_tbl(i).ORGANIZATION_ID:=           p_eam_permit_tbl(i).ORGANIZATION_ID;
4043 			l_eam_permit_tbl(i).STATUS_TYPE:=        	    p_eam_permit_tbl(i).STATUS_TYPE;
4044 			l_eam_permit_tbl(i).VALID_FROM:=                p_eam_permit_tbl(i).VALID_FROM;
4045 			l_eam_permit_tbl(i).VALID_TO:=                  p_eam_permit_tbl(i).VALID_TO;
4046 			l_eam_permit_tbl(i).PENDING_FLAG:=	            p_eam_permit_tbl(i).PENDING_FLAG;
4047 			l_eam_permit_tbl(i).COMPLETION_DATE:=           p_eam_permit_tbl(i).COMPLETION_DATE;
4048 			l_eam_permit_tbl(i).USER_DEFINED_STATUS_ID:=	p_eam_permit_tbl(i).USER_DEFINED_STATUS_ID;
4049 			l_eam_permit_tbl(i).ATTRIBUTE_CATEGORY:=        p_eam_permit_tbl(i).ATTRIBUTE_CATEGORY;
4050 			l_eam_permit_tbl(i).ATTRIBUTE1:=                p_eam_permit_tbl(i).ATTRIBUTE1;
4051 			l_eam_permit_tbl(i).ATTRIBUTE2:=                p_eam_permit_tbl(i).ATTRIBUTE2;
4052 			l_eam_permit_tbl(i).ATTRIBUTE3:=                p_eam_permit_tbl(i).ATTRIBUTE3;
4053 			l_eam_permit_tbl(i).ATTRIBUTE4:=                p_eam_permit_tbl(i).ATTRIBUTE4;
4054 			l_eam_permit_tbl(i).ATTRIBUTE5:=                p_eam_permit_tbl(i).ATTRIBUTE5;
4055 			l_eam_permit_tbl(i).ATTRIBUTE6:=                p_eam_permit_tbl(i).ATTRIBUTE6;
4056 			l_eam_permit_tbl(i).ATTRIBUTE7:=                p_eam_permit_tbl(i).ATTRIBUTE7;
4057 			l_eam_permit_tbl(i).ATTRIBUTE8:=                p_eam_permit_tbl(i).ATTRIBUTE8;
4058 			l_eam_permit_tbl(i).ATTRIBUTE9:=                p_eam_permit_tbl(i).ATTRIBUTE9;
4059 			l_eam_permit_tbl(i).ATTRIBUTE10:=               p_eam_permit_tbl(i).ATTRIBUTE10;
4060 			l_eam_permit_tbl(i).ATTRIBUTE11:=               p_eam_permit_tbl(i).ATTRIBUTE11;
4061 			l_eam_permit_tbl(i).ATTRIBUTE12:=               p_eam_permit_tbl(i).ATTRIBUTE12;
4062 			l_eam_permit_tbl(i).ATTRIBUTE13:=               p_eam_permit_tbl(i).ATTRIBUTE13;
4063 			l_eam_permit_tbl(i).ATTRIBUTE14:=               p_eam_permit_tbl(i).ATTRIBUTE14;
4064 			l_eam_permit_tbl(i).ATTRIBUTE15:=               p_eam_permit_tbl(i).ATTRIBUTE15;
4065 			l_eam_permit_tbl(i).ATTRIBUTE16:=	            p_eam_permit_tbl(i).ATTRIBUTE16;
4066 			l_eam_permit_tbl(i).ATTRIBUTE17:=	            p_eam_permit_tbl(i).ATTRIBUTE17;
4067 			l_eam_permit_tbl(i).ATTRIBUTE18:=	            p_eam_permit_tbl(i).ATTRIBUTE18;
4068 			l_eam_permit_tbl(i).ATTRIBUTE19:=	            p_eam_permit_tbl(i).ATTRIBUTE19;
4069 			l_eam_permit_tbl(i).ATTRIBUTE20:=	            p_eam_permit_tbl(i).ATTRIBUTE20;
4070 			l_eam_permit_tbl(i).ATTRIBUTE21:=	            p_eam_permit_tbl(i).ATTRIBUTE21;
4071 			l_eam_permit_tbl(i).ATTRIBUTE22:=	            p_eam_permit_tbl(i).ATTRIBUTE22;
4072 			l_eam_permit_tbl(i).ATTRIBUTE23:=	            p_eam_permit_tbl(i).ATTRIBUTE23;
4073 			l_eam_permit_tbl(i).ATTRIBUTE24:=	            p_eam_permit_tbl(i).ATTRIBUTE24;
4074 			l_eam_permit_tbl(i).ATTRIBUTE25:=	            p_eam_permit_tbl(i).ATTRIBUTE25;
4075 			l_eam_permit_tbl(i).ATTRIBUTE26:=	            p_eam_permit_tbl(i).ATTRIBUTE26;
4076 			l_eam_permit_tbl(i).ATTRIBUTE27:=	            p_eam_permit_tbl(i).ATTRIBUTE27;
4077 			l_eam_permit_tbl(i).ATTRIBUTE28:=	            p_eam_permit_tbl(i).ATTRIBUTE28;
4078 			l_eam_permit_tbl(i).ATTRIBUTE29:=	            p_eam_permit_tbl(i).ATTRIBUTE29;
4079 			l_eam_permit_tbl(i).ATTRIBUTE30:=	            p_eam_permit_tbl(i).ATTRIBUTE30;
4080 			l_eam_permit_tbl(i).APPROVED_BY:=     	        p_eam_permit_tbl(i).APPROVED_BY;
4081 			l_eam_permit_tbl(i).CREATED_BY:=                p_eam_permit_tbl(i).CREATED_BY;
4082 			l_eam_permit_tbl(i).CREATION_DATE:=             p_eam_permit_tbl(i).CREATION_DATE;
4083 			l_eam_permit_tbl(i).USER_ID:=                   p_eam_permit_tbl(i).USER_ID;
4084 			l_eam_permit_tbl(i).RESPONSIBILITY_ID:=         p_eam_permit_tbl(i).RESPONSIBILITY_ID;
4085 		END LOOP;
4086 
4087 	END IF;
4088 
4089 	IF(p_eam_permit_wo_assoc_tbl IS NOT NULL AND p_eam_permit_wo_assoc_tbl.COUNT>0) THEN
4090 
4091 		FOR i IN  p_eam_permit_wo_assoc_tbl.FIRST ..  p_eam_permit_wo_assoc_tbl.LAST LOOP
4092 			l_eam_permit_wo_assoc_tbl(i).HEADER_ID:=         	p_eam_permit_wo_assoc_tbl(i).HEADER_ID;
4093 			l_eam_permit_wo_assoc_tbl(i).BATCH_ID:=				p_eam_permit_wo_assoc_tbl(i).BATCH_ID;
4094 			l_eam_permit_wo_assoc_tbl(i).ROW_ID:=				p_eam_permit_wo_assoc_tbl(i).ROW_ID;
4095 			l_eam_permit_wo_assoc_tbl(i).TRANSACTION_TYPE:=     p_eam_permit_wo_assoc_tbl(i).TRANSACTION_TYPE;
4096 			l_eam_permit_wo_assoc_tbl(i).SAFETY_ASSOCIATION_ID:=p_eam_permit_wo_assoc_tbl(i).SAFETY_ASSOCIATION_ID;
4097 			l_eam_permit_wo_assoc_tbl(i).SOURCE_ID:=      		p_eam_permit_wo_assoc_tbl(i).SOURCE_ID;
4098 			l_eam_permit_wo_assoc_tbl(i).TARGET_REF_ID:= 		p_eam_permit_wo_assoc_tbl(i).TARGET_REF_ID;
4099 			l_eam_permit_wo_assoc_tbl(i).ASSOCIATION_TYPE:=     p_eam_permit_wo_assoc_tbl(i).ASSOCIATION_TYPE;
4100 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE_CATEGORY:=   p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE_CATEGORY;
4101 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE1:=           p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE1;
4102 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE2:=           p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE2;
4103 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE3:=           p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE3;
4104 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE4:=           p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE4;
4105 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE5:=           p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE5;
4106 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE6:=           p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE6;
4107 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE7:=           p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE7;
4108 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE8:=           p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE8;
4109 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE9:=           p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE9;
4110 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE10:=          p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE10;
4111 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE11:=          p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE11;
4112 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE12:=          p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE12;
4113 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE13:=          p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE13;
4114 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE14:=          p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE14;
4115 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE15:=          p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE15;
4116 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE16:=	        p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE16;
4117 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE17:=	        p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE17;
4118 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE18:=	        p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE18;
4119 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE19:=	        p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE19;
4120 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE20:=	        p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE20;
4121 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE21:=	        p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE21;
4122 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE22:=	        p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE22;
4123 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE23:=	        p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE23;
4124 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE24:=	        p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE24;
4125 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE25:=	        p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE25;
4126 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE26:=	        p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE26;
4127 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE27:=	        p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE27;
4128 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE28:=	        p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE28;
4129 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE29:=	        p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE29;
4130 			l_eam_permit_wo_assoc_tbl(i).ATTRIBUTE30:=	        p_eam_permit_wo_assoc_tbl(i).ATTRIBUTE30;
4131 			l_eam_permit_wo_assoc_tbl(i).CREATED_BY:=           p_eam_permit_wo_assoc_tbl(i).CREATED_BY;
4132 			l_eam_permit_wo_assoc_tbl(i).CREATION_DATE:=        p_eam_permit_wo_assoc_tbl(i).CREATION_DATE;
4133 		END LOOP;
4134 
4135 	   END IF;
4136 
4137 	   -- Delegate call to new signature
4138 
4139 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Overloaded procedure for Safety Permits : Calling PROCESS_WO with Permits and clearances'); END IF;
4140 
4141         PROCESS_WO
4142         (  p_bo_identifier           => p_bo_identifier
4143          , p_api_version_number      => p_api_version_number
4144          , p_init_msg_list           => p_init_msg_list
4145          , p_commit                  => p_commit
4146          , p_eam_wo_rec              => p_eam_wo_rec
4147          , p_eam_op_tbl              => p_eam_op_tbl
4148          , p_eam_op_network_tbl      => p_eam_op_network_tbl
4149          , p_eam_res_tbl             => p_eam_res_tbl
4150          , p_eam_res_inst_tbl        => p_eam_res_inst_tbl
4151          , p_eam_sub_res_tbl         => p_eam_sub_res_tbl
4152          , p_eam_res_usage_tbl       => p_eam_res_usage_tbl
4153          , p_eam_mat_req_tbl         => p_eam_mat_req_tbl
4154          , p_eam_direct_items_tbl    => p_eam_direct_items_tbl
4155           , p_eam_wo_comp_rec        => p_eam_wo_comp_rec
4156          , p_eam_wo_quality_tbl      => p_eam_wo_quality_tbl
4157          , p_eam_meter_reading_tbl   => p_eam_meter_reading_tbl
4158           , p_eam_counter_prop_tbl   => p_eam_counter_prop_tbl
4159          , p_eam_wo_comp_rebuild_tbl => p_eam_wo_comp_rebuild_tbl
4160          , p_eam_wo_comp_mr_read_tbl => p_eam_wo_comp_mr_read_tbl
4161          , p_eam_op_comp_tbl         => p_eam_op_comp_tbl
4162          , p_eam_request_tbl         => p_eam_request_tbl
4163          ,p_eam_permit_tbl           => l_eam_permit_tbl
4164 		    ,p_eam_permit_wo_assoc_tbl  => l_eam_permit_wo_assoc_tbl
4165 		    ,p_eam_work_clearance_tbl   => l_eam_work_clearance_tbl
4166 		    ,p_eam_wc_wo_assoc_tbl      => l_eam_wc_wo_assoc_tbl
4167          , x_eam_wo_rec              => x_eam_wo_rec
4168          , x_eam_op_tbl              => x_eam_op_tbl
4169          , x_eam_op_network_tbl      => x_eam_op_network_tbl
4170          , x_eam_res_tbl             => x_eam_res_tbl
4171          , x_eam_res_inst_tbl        => x_eam_res_inst_tbl
4172          , x_eam_sub_res_tbl         => x_eam_sub_res_tbl
4173          , x_eam_res_usage_tbl       => x_eam_res_usage_tbl
4174          , x_eam_mat_req_tbl         => x_eam_mat_req_tbl
4175          , x_eam_direct_items_tbl    => x_eam_direct_items_tbl
4176         , x_eam_wo_comp_rec         => x_eam_wo_comp_rec
4177          , x_eam_wo_quality_tbl      => x_eam_wo_quality_tbl
4178          , x_eam_meter_reading_tbl   => x_eam_meter_reading_tbl
4179         , x_eam_counter_prop_tbl    => x_eam_counter_prop_tbl
4180          , x_eam_wo_comp_rebuild_tbl => x_eam_wo_comp_rebuild_tbl
4181          , x_eam_wo_comp_mr_read_tbl => x_eam_wo_comp_mr_read_tbl
4182          , x_eam_op_comp_tbl         => x_eam_op_comp_tbl
4183          , x_eam_request_tbl         =>x_eam_request_tbl
4184          , x_return_status           =>x_return_status
4185          , x_msg_count               =>x_msg_count
4186          , p_debug                   =>p_debug
4187          , p_output_dir              =>p_output_dir
4188          , p_debug_filename          =>p_debug_filename
4189          , p_debug_file_mode         =>p_debug_file_mode
4190          );
4191 
4192 	 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Overloaded procedure for Safety Permits : End : Status : '||x_return_status); END IF;
4193 
4194 END PROCESS_WO;
4195 
4196 
4197 /*
4198 *  Overloaded procedure for safety (permits and clearances)
4199 *
4200 */
4201 
4202 PROCEDURE PROCESS_WO
4203         (  p_bo_identifier           IN  VARCHAR2 := 'EAM'
4204          , p_api_version_number      IN  NUMBER := 1.0
4205          , p_init_msg_list           IN  BOOLEAN := FALSE
4206          , p_commit                  IN  VARCHAR2 := 'N'
4207          , p_eam_wo_rec              IN  EAM_PROCESS_WO_PUB.eam_wo_rec_type
4208          , p_eam_op_tbl              IN  EAM_PROCESS_WO_PUB.eam_op_tbl_type
4209          , p_eam_op_network_tbl      IN  EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
4210          , p_eam_res_tbl             IN  EAM_PROCESS_WO_PUB.eam_res_tbl_type
4211          , p_eam_res_inst_tbl        IN  EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
4212          , p_eam_sub_res_tbl         IN  EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
4213          , p_eam_res_usage_tbl       IN  EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
4214          , p_eam_mat_req_tbl         IN  EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
4215          , p_eam_direct_items_tbl    IN  EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
4216           , p_eam_wo_comp_rec         IN  EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type
4217          , p_eam_wo_quality_tbl      IN  EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type
4218          , p_eam_meter_reading_tbl   IN  EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type
4219           , p_eam_counter_prop_tbl    IN  EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type
4220          , p_eam_wo_comp_rebuild_tbl IN  EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type
4221          , p_eam_wo_comp_mr_read_tbl IN  EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type
4222          , p_eam_op_comp_tbl         IN  EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type
4223          , p_eam_request_tbl         IN  EAM_PROCESS_WO_PUB.eam_request_tbl_type
4224          , p_eam_permit_tbl           IN  EAM_PROCESS_SAFETY_PUB.eam_wp_tbl_type
4225 		 , p_eam_permit_wo_assoc_tbl  IN EAM_PROCESS_SAFETY_PUB.eam_safety_assoc_tbl_type
4226 		 , p_eam_work_clearance_tbl   IN EAM_PROCESS_SAFETY_PUB.eam_clearance_header_tbl_type
4227 		 , p_eam_wc_wo_assoc_tbl      IN EAM_PROCESS_SAFETY_PUB.eam_safety_assoc_tbl_type
4228          , x_eam_wo_rec              OUT NOCOPY EAM_PROCESS_WO_PUB.eam_wo_rec_type
4229          , x_eam_op_tbl              OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_tbl_type
4230          , x_eam_op_network_tbl      OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
4231          , x_eam_res_tbl             OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_tbl_type
4232          , x_eam_res_inst_tbl        OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
4233          , x_eam_sub_res_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
4234          , x_eam_res_usage_tbl       OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
4235          , x_eam_mat_req_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
4236          , x_eam_direct_items_tbl    OUT NOCOPY EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
4237         , x_eam_wo_comp_rec         OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type
4238          , x_eam_wo_quality_tbl      OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type
4239          , x_eam_meter_reading_tbl   OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type
4240         , x_eam_counter_prop_tbl    OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type
4241          , x_eam_wo_comp_rebuild_tbl OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type
4242          , x_eam_wo_comp_mr_read_tbl OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type
4243          , x_eam_op_comp_tbl         OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type
4244          , x_eam_request_tbl         OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_request_tbl_type
4245          , x_return_status           OUT NOCOPY VARCHAR2
4246          , x_msg_count               OUT NOCOPY NUMBER
4247          , p_debug                   IN  VARCHAR2 := 'N'
4248          , p_output_dir              IN  VARCHAR2 := NULL
4249          , p_debug_filename          IN  VARCHAR2 := 'EAM_WO_DEBUG.log'
4250          , p_debug_file_mode         IN  VARCHAR2 := 'w'
4251          ) IS
4252 
4253          l_return_status VARCHAR2(1);
4254          l_permit_wo_association_tbl EAM_PROCESS_SAFETY_PUB.eam_safety_assoc_tbl_type;
4255 	 l_second_permit_wo_assoc_tbl EAM_PROCESS_SAFETY_PUB.eam_safety_assoc_tbl_type;
4256          l_permit_clearance_asso_tbl EAM_PROCESS_SAFETY_PUB.eam_safety_assoc_tbl_type;
4257          lx_permit_wo_association_tbl EAM_PROCESS_SAFETY_PUB.eam_safety_assoc_tbl_type;
4258          l_work_permit_header_rec    EAM_PROCESS_SAFETY_PUB.eam_wp_header_rec_type;
4259          lx_work_permit_header_rec   EAM_PROCESS_SAFETY_PUB.eam_wp_header_rec_type;
4260          l_permit_wo_association_rec EAM_PROCESS_SAFETY_PUB.eam_safety_assoc_rec_type;
4261          l_eam_work_clearance_rec    EAM_PROCESS_SAFETY_PUB.eam_clearance_header_rec_type;
4262          l_clearance_establish_tbl   EAM_PROCESS_SAFETY_PUB.eam_establishment_tbl_type;
4263          l_clearance_re_estabish_tbl EAM_PROCESS_SAFETY_PUB.eam_establishment_tbl_type;
4264          l_clearance_wo_asso_tbl     EAM_PROCESS_SAFETY_PUB.eam_safety_assoc_tbl_type;
4265          l_clearance_permit_asso_tbl EAM_PROCESS_SAFETY_PUB.eam_safety_assoc_tbl_type;
4266          l_eam_wc_wo_assoc_tbl  EAM_PROCESS_SAFETY_PUB.eam_safety_assoc_tbl_type;
4267          l_wip_entity_id  NUMBER;
4268          l_permit_id NUMBER;
4269          l_clearance_id NUMBER;
4270          l_organization_id NUMBER;
4271 	 i number;
4272 
4273 BEGIN
4274 
4275 	  IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Overloaded procedure for Safety Permits and Clearances : Start ==========='); END IF ;
4276 
4277 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Overloaded procedure for Safety Permits and Clearances : Calling plain PROCESS_WO'); END IF ;
4278 
4279 PROCESS_WO
4280         (  p_bo_identifier                 =>  p_bo_identifier
4281          , p_api_version_number            =>  p_api_version_number
4282          , p_commit                        =>  p_commit
4283          , p_init_msg_list                 =>  p_init_msg_list
4284          , p_eam_wo_rec                    =>  p_eam_wo_rec
4285          , p_eam_op_tbl                    =>  p_eam_op_tbl
4286          , p_eam_op_network_tbl            =>  p_eam_op_network_tbl
4287          , p_eam_res_tbl                   =>  p_eam_res_tbl
4288          , p_eam_res_inst_tbl              =>  p_eam_res_inst_tbl
4289          , p_eam_sub_res_tbl               =>  p_eam_sub_res_tbl
4290          , p_eam_res_usage_tbl             =>  p_eam_res_usage_tbl
4291          , p_eam_mat_req_tbl               =>  p_eam_mat_req_tbl
4292          , p_eam_direct_items_tbl          =>  p_eam_direct_items_tbl
4293          , p_eam_wo_comp_rec               =>  p_eam_wo_comp_rec
4294          , p_eam_wo_quality_tbl            =>  p_eam_wo_quality_tbl
4295          , p_eam_meter_reading_tbl         =>  p_eam_meter_reading_tbl
4296          , p_eam_counter_prop_tbl          =>  p_eam_counter_prop_tbl
4297          , p_eam_wo_comp_rebuild_tbl       =>  p_eam_wo_comp_rebuild_tbl
4298          , p_eam_wo_comp_mr_read_tbl       =>  p_eam_wo_comp_mr_read_tbl
4299          , p_eam_op_comp_tbl               =>  p_eam_op_comp_tbl
4300          , p_eam_request_tbl               =>  p_eam_request_tbl
4301          , x_eam_wo_rec                    =>  x_eam_wo_rec
4302          , x_eam_op_tbl                    =>  x_eam_op_tbl
4303          , x_eam_op_network_tbl            =>  x_eam_op_network_tbl
4304          , x_eam_res_tbl                   =>  x_eam_res_tbl
4305          , x_eam_res_inst_tbl              =>  x_eam_res_inst_tbl
4306          , x_eam_sub_res_tbl               =>  x_eam_sub_res_tbl
4307          , x_eam_res_usage_tbl             =>  x_eam_res_usage_tbl
4308          , x_eam_mat_req_tbl               =>  x_eam_mat_req_tbl
4309          , x_eam_direct_items_tbl          =>  x_eam_direct_items_tbl
4310          , x_eam_wo_comp_rec               =>  x_eam_wo_comp_rec
4311          , x_eam_wo_quality_tbl            =>  x_eam_wo_quality_tbl
4312          , x_eam_meter_reading_tbl         =>  x_eam_meter_reading_tbl
4313          , x_eam_counter_prop_tbl          =>  x_eam_counter_prop_tbl
4314          , x_eam_wo_comp_rebuild_tbl       =>  x_eam_wo_comp_rebuild_tbl
4315          , x_eam_wo_comp_mr_read_tbl       =>  x_eam_wo_comp_mr_read_tbl
4316          , x_eam_op_comp_tbl               =>  x_eam_op_comp_tbl
4317          , x_eam_request_tbl               =>  x_eam_request_tbl
4318          , x_return_status                 =>  l_return_status
4319          , x_msg_count                     =>  x_msg_count
4320          , p_debug                         =>  p_debug
4321          , p_output_dir                    =>  p_output_dir
4322          , p_debug_filename                =>  p_debug_filename
4323          , p_debug_file_mode               =>  p_debug_file_mode
4324          );
4325 
4326 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN
4327 EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Overloaded procedure for Safety Permits and Clearances : Return status from plain PROCESS_WO: '||l_return_status);
4328 END IF ;
4329 
4330         x_return_status := l_return_status ;
4331         IF x_return_status = 'E' THEN
4332               RETURN;
4333         END IF;
4334 
4335 
4336   /*Call the permit APIs only if work order creation was successful*/
4337 
4338         IF ((l_return_status = 'S') or (l_return_status is null)) THEN
4339 
4340         -- In case of update workorder x_eam_wo_rec.wip_entity_id might be null
4341         -- if there are no association records dummy record will be passed which contains wip_entity_id
4342 
4343             IF x_eam_wo_rec.wip_entity_id is not null THEN
4344               l_wip_entity_id :=x_eam_wo_rec.wip_entity_id;
4345             ELSIF p_eam_permit_wo_assoc_tbl.COUNT > 0 THEN
4346               l_wip_entity_id :=p_eam_permit_wo_assoc_tbl(1).TARGET_REF_ID;
4347             END IF;
4348 
4349 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN
4350 EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Permits and Clearances : Preparing Permit header ('||p_eam_permit_tbl.COUNT||') and association ('||p_eam_permit_wo_assoc_tbl.COUNT||') tables');
4351 END IF ;
4352 
4353             -- Process new permit records(create WO)
4354 
4355             IF p_eam_permit_tbl.COUNT > 0 THEN
4356                     FOR i in p_eam_permit_tbl.FIRST..p_eam_permit_tbl.LAST LOOP
4357 
4358                        l_work_permit_header_rec := p_eam_permit_tbl(i);
4359                        IF l_work_permit_header_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_CREATE THEN
4360                           --build association record using permit header record
4361 
4362                           l_permit_wo_association_rec.HEADER_ID               :=1;
4363                           l_permit_wo_association_rec.BATCH_ID                :=l_wip_entity_id;
4364                           l_permit_wo_association_rec.ROW_ID                  :=i;
4365                           l_permit_wo_association_rec.SAFETY_ASSOCIATION_ID   := null;
4366                           l_permit_wo_association_rec.SOURCE_ID               :=null;
4367                           l_permit_wo_association_rec.TARGET_REF_ID           := l_wip_entity_id;
4368                           l_permit_wo_association_rec.ASSOCIATION_TYPE        :=3;
4369                           l_permit_wo_association_rec.TRANSACTION_TYPE        :=EAM_PROCESS_WO_PVT.G_OPR_CREATE;
4370                           l_permit_wo_association_rec.ORGANIZATION_ID         :=l_work_permit_header_rec.ORGANIZATION_ID;
4371                           l_permit_wo_association_rec.ATTRIBUTE_CATEGORY      :=l_work_permit_header_rec.ATTRIBUTE_CATEGORY;
4372                           l_permit_wo_association_rec.ATTRIBUTE1              :=l_work_permit_header_rec.ATTRIBUTE1;
4373                           l_permit_wo_association_rec.ATTRIBUTE2              :=l_work_permit_header_rec.ATTRIBUTE2;
4374                           l_permit_wo_association_rec.ATTRIBUTE3              :=l_work_permit_header_rec.ATTRIBUTE3;
4375                           l_permit_wo_association_rec.ATTRIBUTE4              :=l_work_permit_header_rec.ATTRIBUTE4;
4376                           l_permit_wo_association_rec.ATTRIBUTE5              :=l_work_permit_header_rec.ATTRIBUTE5;
4377                           l_permit_wo_association_rec.ATTRIBUTE6              :=l_work_permit_header_rec.ATTRIBUTE6;
4378                           l_permit_wo_association_rec.ATTRIBUTE7              :=l_work_permit_header_rec.ATTRIBUTE7;
4379                           l_permit_wo_association_rec.ATTRIBUTE8              :=l_work_permit_header_rec.ATTRIBUTE8;
4380                           l_permit_wo_association_rec.ATTRIBUTE9              :=l_work_permit_header_rec.ATTRIBUTE9;
4381                           l_permit_wo_association_rec.ATTRIBUTE10             :=l_work_permit_header_rec.ATTRIBUTE10;
4382                           l_permit_wo_association_rec.ATTRIBUTE11             :=l_work_permit_header_rec.ATTRIBUTE11;
4383                           l_permit_wo_association_rec.ATTRIBUTE12             :=l_work_permit_header_rec.ATTRIBUTE12;
4384                           l_permit_wo_association_rec.ATTRIBUTE13             :=l_work_permit_header_rec.ATTRIBUTE13;
4385                           l_permit_wo_association_rec.ATTRIBUTE14             :=l_work_permit_header_rec.ATTRIBUTE14;
4386                           l_permit_wo_association_rec.ATTRIBUTE15             :=l_work_permit_header_rec.ATTRIBUTE15;
4387                           l_permit_wo_association_rec.ATTRIBUTE16              :=l_work_permit_header_rec.ATTRIBUTE16;
4388                           l_permit_wo_association_rec.ATTRIBUTE17             :=l_work_permit_header_rec.ATTRIBUTE17;
4389                           l_permit_wo_association_rec.ATTRIBUTE18             :=l_work_permit_header_rec.ATTRIBUTE18;
4390                           l_permit_wo_association_rec.ATTRIBUTE19             :=l_work_permit_header_rec.ATTRIBUTE19;
4391                           l_permit_wo_association_rec.ATTRIBUTE20             :=l_work_permit_header_rec.ATTRIBUTE20;
4392                           l_permit_wo_association_rec.ATTRIBUTE21             :=l_work_permit_header_rec.ATTRIBUTE21;
4393                           l_permit_wo_association_rec.ATTRIBUTE22             :=l_work_permit_header_rec.ATTRIBUTE22;
4394                           l_permit_wo_association_rec.ATTRIBUTE23             :=l_work_permit_header_rec.ATTRIBUTE23;
4395                           l_permit_wo_association_rec.ATTRIBUTE24             :=l_work_permit_header_rec.ATTRIBUTE24;
4396                           l_permit_wo_association_rec.ATTRIBUTE25             :=l_work_permit_header_rec.ATTRIBUTE25;
4397                           l_permit_wo_association_rec.ATTRIBUTE26             :=l_work_permit_header_rec.ATTRIBUTE26;
4398                           l_permit_wo_association_rec.ATTRIBUTE27             :=l_work_permit_header_rec.ATTRIBUTE27;
4399                           l_permit_wo_association_rec.ATTRIBUTE28             :=l_work_permit_header_rec.ATTRIBUTE28;
4400                           l_permit_wo_association_rec.ATTRIBUTE29             :=l_work_permit_header_rec.ATTRIBUTE29;
4401                           l_permit_wo_association_rec.ATTRIBUTE30             :=l_work_permit_header_rec.ATTRIBUTE30;
4402 
4403                           l_permit_wo_association_tbl(1) :=  l_permit_wo_association_rec;
4404 
4405                          --Nullifying the DFF attributes as these are for association DFF only. Bug 12604571
4406 
4407                           l_work_permit_header_rec.ATTRIBUTE_CATEGORY      :=NULL;
4408                           l_work_permit_header_rec.ATTRIBUTE1              :=NULL;
4409                           l_work_permit_header_rec.ATTRIBUTE2              :=NULL;
4410                           l_work_permit_header_rec.ATTRIBUTE3              :=NULL;
4411                           l_work_permit_header_rec.ATTRIBUTE4              :=NULL;
4412                           l_work_permit_header_rec.ATTRIBUTE5              :=NULL;
4413                           l_work_permit_header_rec.ATTRIBUTE6              :=NULL;
4414                           l_work_permit_header_rec.ATTRIBUTE7              :=NULL;
4415                           l_work_permit_header_rec.ATTRIBUTE8              :=NULL;
4416                           l_work_permit_header_rec.ATTRIBUTE9              :=NULL;
4417                           l_work_permit_header_rec.ATTRIBUTE10             :=NULL;
4418                           l_work_permit_header_rec.ATTRIBUTE11             :=NULL;
4419                           l_work_permit_header_rec.ATTRIBUTE12             :=NULL;
4420                           l_work_permit_header_rec.ATTRIBUTE13             :=NULL;
4421                           l_work_permit_header_rec.ATTRIBUTE14             :=NULL;
4422                           l_work_permit_header_rec.ATTRIBUTE15             :=NULL;
4423                           l_work_permit_header_rec.ATTRIBUTE16             :=NULL;
4424                           l_work_permit_header_rec.ATTRIBUTE17             :=NULL;
4425                           l_work_permit_header_rec.ATTRIBUTE18             :=NULL;
4426                           l_work_permit_header_rec.ATTRIBUTE19             :=NULL;
4427                           l_work_permit_header_rec.ATTRIBUTE20             :=NULL;
4428                           l_work_permit_header_rec.ATTRIBUTE21             :=NULL;
4429                           l_work_permit_header_rec.ATTRIBUTE22             :=NULL;
4430                           l_work_permit_header_rec.ATTRIBUTE23             :=NULL;
4431                           l_work_permit_header_rec.ATTRIBUTE24             :=NULL;
4432                           l_work_permit_header_rec.ATTRIBUTE25             :=NULL;
4433                           l_work_permit_header_rec.ATTRIBUTE26             :=NULL;
4434                           l_work_permit_header_rec.ATTRIBUTE27             :=NULL;
4435                           l_work_permit_header_rec.ATTRIBUTE28             :=NULL;
4436                           l_work_permit_header_rec.ATTRIBUTE29             :=NULL;
4437                           l_work_permit_header_rec.ATTRIBUTE30             :=NULL;
4438 
4439                         END IF; -- End if transaction_type
4440 
4441 
4442 
4443                        /*EAM_PROCESS_PERMIT_PVT.PROCESS_WORK_PERMIT(
4444                             p_bo_identifier              => p_bo_identifier
4445                           , p_api_version_number      	 => p_api_version_number
4446                           , p_init_msg_list           	 => TRUE
4447                           , p_commit                  	 => p_commit
4448                           , p_work_permit_header_rec  	 => l_work_permit_header_rec
4449                           , p_permit_wo_association_tbl  => l_permit_wo_association_tbl
4450                           , x_work_permit_header_rec  	 => lx_work_permit_header_rec
4451                           , x_return_status           	 => l_return_status
4452                           , x_msg_count               	 => x_msg_count
4453                           , p_debug                      => p_debug
4454                           , p_output_dir             	   => p_output_dir
4455                           , p_debug_filename          	 => p_debug_filename
4456                           , p_debug_file_mode        	   => p_debug_file_mode
4457                           );
4458 
4459                       */
4460 
4461 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN
4462 EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Permits and Clearances :Calling EAM_PROCESS_SAFETY_PUB.PROCESS_WORK_PERMIT Permit name: '||l_work_permit_header_rec.permit_name);
4463 END IF ;
4464 
4465                          EAM_PROCESS_SAFETY_PUB.PROCESS_WORK_PERMIT(
4466                             p_bo_identifier              => p_bo_identifier
4467                           , p_api_version_number      	 => p_api_version_number
4468                           , p_init_msg_list           	 => TRUE
4469                           , p_commit                  	 => p_commit
4470                           , p_work_permit_header_rec  	 => l_work_permit_header_rec
4471                           , p_permit_wo_association_tbl  => l_permit_wo_association_tbl
4472                           , p_permit_clearance_asso_tbl  => l_permit_clearance_asso_tbl
4473                           , x_return_status           	 => x_return_status
4474                           , x_msg_count               	 => x_msg_count
4475                           , p_debug                    => p_debug
4476                           , p_output_dir             	 => p_output_dir
4477                           , p_debug_filename           => p_debug_filename
4478                           , p_debug_file_mode        	 => p_debug_file_mode
4479                           ,x_permit_id                 =>l_permit_id
4480                         );
4481 
4482                        IF x_return_status = 'E' THEN
4483 
4484                                RETURN;
4485                        END IF;
4486 
4487                     END LOOP; --PERMIT LOOP
4488 
4489 
4490             END IF; -- End permits if.
4491 
4492              --check for work order/permit association for existing permit
4493 
4494             IF p_eam_permit_wo_assoc_tbl.COUNT > 0 THEN
4495 
4496                   SELECT ORGANIZATION_ID INTO  l_organization_id from wip_entities where wip_entity_id = l_wip_entity_id;
4497                    i :=1;
4498 
4499                      FOR j in p_eam_permit_wo_assoc_tbl.FIRST..p_eam_permit_wo_assoc_tbl.LAST LOOP
4500 
4501                         IF ( p_eam_permit_wo_assoc_tbl(j).SOURCE_ID IS NOT NULL) THEN  -- to not to process dummy record
4502                             l_second_permit_wo_assoc_tbl(i) :=p_eam_permit_wo_assoc_tbl(j);
4503                             l_second_permit_wo_assoc_tbl(i).TARGET_REF_ID :=l_wip_entity_id;
4504                             l_second_permit_wo_assoc_tbl(i).organization_id := l_organization_id;
4505 
4506                             i := i+1;
4507 
4508                            /*
4509                             EAM_PROCESS_PERMIT_PVT.PERMIT_WORK_ORDER_ASSOCIATION
4510                                    (   p_validation_level           => EAM_PROCESS_WO_PVT.G_OPR_UPDATE
4511                                      , p_organization_id	           => p_eam_wo_rec.organization_id
4512                                      , p_permit_wo_association_tbl  => l_permit_wo_association_tbl
4513                                      , p_work_permit_id             => l_permit_wo_association_tbl(1).SOURCE_ID
4514                                      , x_permit_wo_association_tbl  => lx_permit_wo_association_tbl
4515                                      , x_mesg_token_tbl             => l_out_Mesg_Token_Tbl
4516                                      , x_return_status              => l_return_status
4517                                     );
4518 
4519                            */
4520 
4521                         END IF;
4522                     END LOOP; --ASSOCIATION LOOP
4523 
4524 
4525                     EAM_PROCESS_SAFETY_PUB.PERMIT_WORK_ORDER_ASSOCIATION(
4526                        p_init_msg_list  => TRUE
4527                        , p_permit_wo_association_tbl => l_second_permit_wo_assoc_tbl
4528                        , p_debug                     => p_debug
4529                        , p_output_dir             	 => p_output_dir
4530                        , p_debug_filename          	 => p_debug_filename
4531                        , p_debug_file_mode        	 => p_debug_file_mode
4532                        , x_return_status             =>x_return_status
4533                        , x_msg_count                 =>x_msg_count
4534                     );
4535 
4536                    IF x_return_status = 'E' THEN
4537                          RETURN;
4538                    END IF;
4539           END IF;
4540 
4541 
4542              --check for work clearance
4543 
4544             IF p_eam_work_clearance_tbl.COUNT > 0 THEN
4545 
4546                  FOR i in p_eam_work_clearance_tbl.FIRST..p_eam_work_clearance_tbl.LAST LOOP
4547 
4548                    l_eam_work_clearance_rec := p_eam_work_clearance_tbl(i);
4549 
4550 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN
4551 EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Permits and Clearances :Calling EAM_PROCESS_SAFETY_PUB.PROCESS_WORK_CLEARANCE Clearance name: '||l_eam_work_clearance_rec.WORK_CLEARANCE_NAME);
4552 END IF ;
4553                    EAM_PROCESS_SAFETY_PUB.PROCESS_WORK_CLEARANCE(
4554                      p_init_msg_list  => TRUE
4555                    , p_work_clearance_header_rec => l_eam_work_clearance_rec
4556                    , p_clearance_establish_tbl  => l_clearance_establish_tbl
4557                    , p_clearance_re_estabish_tbl => l_clearance_re_estabish_tbl
4558                    , p_clearance_wo_asso_tbl => l_clearance_wo_asso_tbl
4559                    , p_clearance_permit_asso_tbl  => l_clearance_permit_asso_tbl
4560                    , p_debug                     => p_debug
4561                    , p_output_dir             	 => p_output_dir
4562                    , p_debug_filename          	 => p_debug_filename
4563                    , p_debug_file_mode        	 => p_debug_file_mode
4564                    , x_clearance_id              =>l_clearance_id
4565                    , x_return_status             =>x_return_status
4566                    , x_msg_count                  =>x_msg_count
4567 
4568                    )  ;
4569 
4570                    IF x_return_status = 'E' THEN
4571                        RETURN;
4572                    END IF;
4573                  END LOOP;
4574             END IF; --IF p_eam_work_clearance_tbl.COUNT > 0 THEN
4575 
4576 
4577            --check for work order/WC association
4578 
4579             IF p_eam_wc_wo_assoc_tbl.COUNT > 0 THEN
4580                  l_eam_wc_wo_assoc_tbl:= p_eam_wc_wo_assoc_tbl;
4581 
4582                  FOR i in p_eam_wc_wo_assoc_tbl.FIRST .. p_eam_wc_wo_assoc_tbl.LAST LOOP
4583 
4584                    l_eam_wc_wo_assoc_tbl(i).TARGET_REF_ID:= l_wip_entity_id;
4585 
4586                    EAM_PROCESS_SAFETY_PUB.CLEARANCE_WO_ASSOCIATION(
4587                       p_init_msg_list     => TRUE
4588                     , p_clearance_wo_asso_tbl  =>  l_eam_wc_wo_assoc_tbl
4589                     , p_debug                 => p_debug
4590                     , p_output_dir            => p_output_dir
4591                     , p_debug_filename        => p_debug_filename
4592                     , p_debug_file_mode       => p_debug_file_mode
4593                     , x_return_status         => x_return_status
4594                     , x_msg_count             => x_msg_count
4595                    )   ;
4596 
4597                    IF x_return_status = 'E' THEN
4598                       RETURN;
4599                    END IF;
4600                  END LOOP;
4601             END IF;
4602 
4603         END IF; -- if(l_return_staus='S'.....)
4604 
4605         x_return_status :='S'; -- Return success if the program is through other procedure calls.
4606 
4607 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.PROCESS_WO : Permits and Clearances :End :Status: '||x_return_status); END IF ;
4608 
4609 END PROCESS_WO;
4610 
4611 
4612  PROCEDURE EXPLODE_ACTIVITY
4613        (  p_api_version             IN  NUMBER   := 1.0
4614         , p_init_msg_list           IN  VARCHAR2 := fnd_api.g_false
4615         , p_commit                  IN  VARCHAR2 := fnd_api.g_false
4616         , p_validation_level        IN  NUMBER   := fnd_api.g_valid_level_full
4617         , p_organization_id         IN  NUMBER
4618         , p_asset_activity_id       IN  NUMBER
4619         , p_wip_entity_id           IN  NUMBER
4620         , p_start_date              IN  DATE
4621         , p_completion_date         IN  DATE
4622         , p_rev_datetime            IN  DATE     := SYSDATE
4623         , p_entity_type             IN  NUMBER   := 6
4624         , x_return_status           OUT NOCOPY VARCHAR2
4625         , x_msg_count               OUT NOCOPY NUMBER
4626         , x_msg_data                OUT NOCOPY VARCHAR2
4627         )
4628         IS
4629 
4630         l_eam_wo_rec            EAM_PROCESS_WO_PUB.eam_wo_rec_type;
4631         l_eam_op_tbl            EAM_PROCESS_WO_PUB.eam_op_tbl_type;
4632         l_eam_op_network_tbl    EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
4633         l_eam_res_tbl           EAM_PROCESS_WO_PUB.eam_res_tbl_type;
4634         l_eam_res_inst_tbl      EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
4635         l_eam_sub_res_tbl       EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
4636         l_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
4637         l_eam_mat_req_tbl       EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
4638         l_eam_direct_items_tbl       EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
4639 
4640         x_eam_wo_rec            EAM_PROCESS_WO_PUB.eam_wo_rec_type;
4641         x_eam_op_tbl            EAM_PROCESS_WO_PUB.eam_op_tbl_type;
4642         x_eam_op_network_tbl    EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
4643         x_eam_res_tbl           EAM_PROCESS_WO_PUB.eam_res_tbl_type;
4644         x_eam_res_inst_tbl      EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
4645         x_eam_sub_res_tbl       EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
4646         x_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
4647         x_eam_mat_req_tbl       EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
4648         x_eam_direct_items_tbl       EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
4649 
4650         BEGIN
4651 
4652         l_eam_wo_rec.WIP_ENTITY_ID                := p_wip_entity_id;
4653         l_eam_wo_rec.ORGANIZATION_ID              := p_organization_id;
4654         l_eam_wo_rec.ASSET_ACTIVITY_ID            := p_asset_activity_id;
4655         l_eam_wo_rec.REQUESTED_START_DATE         := p_start_date;
4656         l_eam_wo_rec.DUE_DATE                     := p_completion_date;
4657         l_eam_wo_rec.BOM_REVISION_DATE            := p_rev_datetime;
4658         l_eam_wo_rec.ROUTING_REVISION_DATE        := p_rev_datetime;
4659         l_eam_wo_rec.SOURCE_LINE_ID               := null;
4660         l_eam_wo_rec.SOURCE_CODE                  := 'EZ_WO';
4661         l_eam_wo_rec.RETURN_STATUS                := null;
4662         l_eam_wo_rec.TRANSACTION_TYPE             := 2;
4663 
4664 
4665         EAM_PROCESS_WO_PVT.PROCESS_WO
4666         ( p_api_version_number            =>  p_api_version
4667         , x_return_status                 =>  x_return_status
4668         , x_msg_count                     =>  x_msg_count
4669         , p_eam_wo_rec                    =>  l_eam_wo_rec
4670         , p_eam_op_tbl                    =>  l_eam_op_tbl
4671         , p_eam_op_network_tbl            =>  l_eam_op_network_tbl
4672         , p_eam_res_tbl                   =>  l_eam_res_tbl
4673         , p_eam_res_inst_tbl              =>  l_eam_res_inst_tbl
4674         , p_eam_sub_res_tbl               =>  l_eam_sub_res_tbl
4675         , p_eam_res_usage_tbl             =>  l_eam_res_usage_tbl
4676         , p_eam_mat_req_tbl               =>  l_eam_mat_req_tbl
4677         , p_eam_direct_items_tbl               =>  l_eam_direct_items_tbl
4678         , x_eam_wo_rec                    =>  x_eam_wo_rec
4679         , x_eam_op_tbl                    =>  x_eam_op_tbl
4680         , x_eam_op_network_tbl            =>  x_eam_op_network_tbl
4681         , x_eam_res_tbl                   =>  x_eam_res_tbl
4682         , x_eam_res_inst_tbl              =>  x_eam_res_inst_tbl
4683         , x_eam_sub_res_tbl               =>  x_eam_sub_res_tbl
4684         , x_eam_res_usage_tbl             =>  x_eam_res_usage_tbl
4685         , x_eam_mat_req_tbl               =>  x_eam_mat_req_tbl
4686         , x_eam_direct_items_tbl               =>  x_eam_direct_items_tbl
4687         );
4688 
4689 END EXPLODE_ACTIVITY;
4690 
4691 
4692 
4693 
4694 
4695 
4696 
4697 PROCEDURE CHECK_BO_RECORD
4698         ( p_eam_wo_rec              IN  EAM_PROCESS_WO_PUB.eam_wo_rec_type
4699         , p_eam_op_tbl              IN  EAM_PROCESS_WO_PUB.eam_op_tbl_type
4700         , p_eam_op_network_tbl      IN  EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
4701         , p_eam_res_tbl             IN  EAM_PROCESS_WO_PUB.eam_res_tbl_type
4702         , p_eam_res_inst_tbl        IN  EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
4703         , p_eam_sub_res_tbl         IN  EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
4704         , p_eam_res_usage_tbl       IN  EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
4705         , p_eam_mat_req_tbl         IN  EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
4706         , p_eam_direct_items_tbl    IN  EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
4707 	, p_eam_wo_comp_rec         IN  EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type
4708         , p_eam_wo_quality_tbl      IN  EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type
4709         , p_eam_meter_reading_tbl   IN  EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type
4710 	, p_eam_counter_prop_tbl    IN  EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type
4711         , p_eam_wo_comp_rebuild_tbl IN  EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type
4712         , p_eam_wo_comp_mr_read_tbl IN  EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type
4713         , p_eam_op_comp_tbl         IN  EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type
4714 	, p_eam_request_tbl         IN  EAM_PROCESS_WO_PUB.eam_request_tbl_type
4715         , x_return_status           OUT NOCOPY VARCHAR2
4716         )
4717         IS
4718 
4719         -- baroy
4720         l_wip_entity_id   NUMBER       := NULL;
4721         l_organization_id NUMBER       := NULL;
4722         l_other_message   VARCHAR2(50) := NULL;
4723         l_mesg_token_tbl  EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
4724         l_token_tbl       EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type;
4725 
4726         l_eam_wo_rec            EAM_PROCESS_WO_PUB.eam_wo_rec_type;
4727         l_eam_op_tbl            EAM_PROCESS_WO_PUB.eam_op_tbl_type;
4728         l_eam_op_network_tbl    EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
4729         l_eam_res_tbl           EAM_PROCESS_WO_PUB.eam_res_tbl_type;
4730         l_eam_res_inst_tbl      EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
4731         l_eam_sub_res_tbl       EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
4732         l_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
4733         l_eam_mat_req_tbl       EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
4734         l_eam_direct_items_tbl  EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
4735 
4736 	l_eam_wo_comp_rec         EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type;
4737 	l_eam_wo_quality_tbl      EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type;
4738 	l_eam_meter_reading_tbl   EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type;
4739         l_eam_counter_prop_tbl    EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type;
4740 	l_eam_wo_comp_rebuild_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type;
4741 	l_eam_wo_comp_mr_read_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type;
4742 	l_eam_op_comp_tbl         EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type;
4743 	l_eam_request_tbl         EAM_PROCESS_WO_PUB.eam_request_tbl_type ;
4744 
4745         l_out_eam_wo_rec            EAM_PROCESS_WO_PUB.eam_wo_rec_type;
4746         l_out_eam_op_tbl            EAM_PROCESS_WO_PUB.eam_op_tbl_type;
4747         l_out_eam_op_network_tbl    EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
4748         l_out_eam_res_tbl           EAM_PROCESS_WO_PUB.eam_res_tbl_type;
4749         l_out_eam_res_inst_tbl      EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
4750         l_out_eam_sub_res_tbl       EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
4751         l_out_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
4752         l_out_eam_mat_req_tbl       EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
4753         l_out_eam_direct_items_tbl  EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
4754 
4755 	l_out_eam_wo_comp_rec         EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type;
4756 	l_out_eam_wo_quality_tbl      EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type;
4757 	l_out_eam_meter_reading_tbl   EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type;
4758         l_out_eam_counter_prop_tbl    EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type;
4759 	l_out_eam_wo_comp_rebuild_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type;
4760 	l_out_eam_wo_comp_mr_read_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type;
4761 	l_out_eam_op_comp_tbl         EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type;
4762 	l_out_eam_request_tbl         EAM_PROCESS_WO_PUB.eam_request_tbl_type ;
4763 
4764         -- baroy
4765 
4766         BEGIN
4767 
4768 
4769            l_eam_wo_rec            := p_eam_wo_rec;
4770            l_eam_op_tbl            := p_eam_op_tbl;
4771            l_eam_op_network_tbl    := p_eam_op_network_tbl;
4772            l_eam_res_tbl           := p_eam_res_tbl;
4773            l_eam_res_inst_tbl      := p_eam_res_inst_tbl;
4774            l_eam_sub_res_tbl       := p_eam_sub_res_tbl;
4775            l_eam_res_usage_tbl     := p_eam_res_usage_tbl;
4776            l_eam_mat_req_tbl       := p_eam_mat_req_tbl;
4777            l_eam_direct_items_tbl  := p_eam_direct_items_tbl;
4778 
4779 	   l_eam_wo_comp_rec		:= p_eam_wo_comp_rec;
4780   	   l_eam_wo_quality_tbl		:= p_eam_wo_quality_tbl;
4781 	   l_eam_meter_reading_tbl	:= p_eam_meter_reading_tbl;
4782 	   l_eam_counter_prop_tbl	:= p_eam_counter_prop_tbl;
4783 	   l_eam_wo_comp_rebuild_tbl	:= p_eam_wo_comp_rebuild_tbl;
4784 	   l_eam_wo_comp_mr_read_tbl	:= p_eam_wo_comp_mr_read_tbl;
4785 	   l_eam_op_comp_tbl		:= p_eam_op_comp_tbl;
4786 	   l_eam_request_tbl		:= p_eam_request_tbl;
4787 
4788            -- baroy - If Parent record is null, then find the first non-null weid and orgid
4789            --         from the child tables
4790 
4791 
4792            IF p_eam_wo_rec.transaction_type is null and (p_eam_wo_comp_rec.transaction_type is null and p_eam_request_tbl.COUNT >0 )then
4793 
4794              FOR J in 1 .. 1 LOOP
4795 
4796                FOR I IN 1..p_eam_op_tbl.COUNT LOOP
4797                  -- If there is an entity with error, then flag it and exit.
4798                  IF p_eam_op_tbl(I).transaction_type is not null and
4799                     (p_eam_op_tbl(I).wip_entity_id is null or
4800                      p_eam_op_tbl(I).organization_id is null) then
4801                    l_other_message := 'EAM_WO_OP_REC_INVALID';
4802                    EXIT;
4803                  END IF;
4804                  IF p_eam_op_tbl(I).wip_entity_id is not null AND
4805                     p_eam_op_tbl(I).organization_Id is not null
4806                  THEN
4807                     l_wip_entity_id   := p_eam_op_tbl(I).wip_entity_id;
4808                     l_organization_id := p_eam_op_tbl(I).organization_id;
4809                     EXIT;
4810                  END IF;
4811                END LOOP;
4812                IF l_wip_entity_id is not null or
4813                   l_other_message is not null then exit; end if;
4814 
4815                FOR I IN 1..p_eam_op_network_tbl.COUNT LOOP
4816                  -- If there is an entity with error, then flag it and exit.
4817                  IF p_eam_op_network_tbl(I).transaction_type is not null and
4818                     (p_eam_op_network_tbl(I).wip_entity_id is null or
4819                      p_eam_op_network_tbl(I).organization_id is null) then
4820                    l_other_message := 'EAM_WO_OPN_REC_INVALID';
4821                    EXIT;
4822                  END IF;
4823                  IF p_eam_op_network_tbl(I).wip_entity_id is not null AND
4824                     p_eam_op_network_tbl(I).organization_id is not null
4825                  THEN
4826                     l_wip_entity_id   := p_eam_op_network_tbl(I).wip_entity_id;
4827                     l_organization_id := p_eam_op_network_tbl(I).organization_id;
4828                     EXIT;
4829                  END IF;
4830                END LOOP;
4831                IF l_wip_entity_id is not null or
4832                   l_other_message is not null then exit; end if;
4833 
4834                FOR I IN 1..p_eam_res_tbl.COUNT LOOP
4835                  -- If there is an entity with error, then flag it and exit.
4836                  IF p_eam_res_tbl(I).transaction_type is not null and
4837                     (p_eam_res_tbl(I).wip_entity_id is null or
4838                      p_eam_res_tbl(I).organization_id is null) then
4839                    l_other_message := 'EAM_WO_RES_REC_INVALID';
4840                    EXIT;
4841                  END IF;
4842                  IF p_eam_res_tbl(I).wip_entity_id is not null AND
4843                     p_eam_res_tbl(I).organization_id is not null
4844                  THEN
4845                     l_wip_entity_id   := p_eam_res_tbl(I).wip_entity_id;
4846                     l_organization_id := p_eam_res_tbl(I).organization_id;
4847                     EXIT;
4848                  END IF;
4849                END LOOP;
4850                IF l_wip_entity_id is not null or
4851                   l_other_message is not null then exit; end if;
4852 
4853                FOR I IN 1..p_eam_res_inst_tbl.COUNT LOOP
4854                  -- If there is an entity with error, then flag it and exit.
4855                  IF p_eam_res_inst_tbl(I).transaction_type is not null and
4856                     (p_eam_res_inst_tbl(I).wip_entity_id is null or
4857                      p_eam_res_inst_tbl(I).organization_id is null) then
4858                    l_other_message := 'EAM_WO_RESI_REC_INVALID';
4859                    EXIT;
4860                  END IF;
4861                  IF p_eam_res_inst_tbl(I).wip_entity_id is not null AND
4862                     p_eam_res_inst_tbl(I).organization_id is not null
4863                  THEN
4864                     l_wip_entity_id   := p_eam_res_inst_tbl(I).wip_entity_id;
4865                     l_organization_id := p_eam_res_inst_tbl(I).organization_id;
4866                     EXIT;
4867                  END IF;
4868                END LOOP;
4869                IF l_wip_entity_id is not null or
4870                   l_other_message is not null then exit; end if;
4871 
4872                FOR I IN 1..p_eam_sub_res_tbl.COUNT LOOP
4873                  -- If there is an entity with error, then flag it and exit.
4874                  IF p_eam_sub_res_tbl(I).transaction_type is not null and
4875                     (p_eam_sub_res_tbl(I).wip_entity_id is null or
4876                      p_eam_sub_res_tbl(I).organization_id is null) then
4877                    l_other_message := 'EAM_WO_SURES_REC_INVALID';
4878                    EXIT;
4879                  END IF;
4880                  IF p_eam_sub_res_tbl(I).wip_entity_id is not null AND
4881                     p_eam_sub_res_tbl(I).organization_id is not null
4882                  THEN
4883                     l_wip_entity_id   := p_eam_sub_res_tbl(I).wip_entity_id;
4884                     l_organization_id := p_eam_sub_res_tbl(I).organization_id;
4885                     EXIT;
4886                  END IF;
4887                END LOOP;
4888                IF l_wip_entity_id is not null or
4889                   l_other_message is not null then exit; end if;
4890 
4891                FOR I IN 1..p_eam_res_usage_tbl.COUNT LOOP
4892                  -- If there is an entity with error, then flag it and exit.
4893                  IF p_eam_res_usage_tbl(I).transaction_type is not null and
4894                     (p_eam_res_usage_tbl(I).wip_entity_id is null or
4895                      p_eam_res_usage_tbl(I).organization_id is null) then
4896                    l_other_message := 'EAM_WO_RESU_REC_INVALID';
4897                    EXIT;
4898                  END IF;
4899                  IF p_eam_res_usage_tbl(I).wip_entity_id is not null AND
4900                     p_eam_res_usage_tbl(I).organization_id is not null
4901                  THEN
4902                     l_wip_entity_id   := p_eam_res_usage_tbl(I).wip_entity_id;
4903                     l_organization_id := p_eam_res_usage_tbl(I).organization_id;
4904                     EXIT;
4905                  END IF;
4906                END LOOP;
4907                IF l_wip_entity_id is not null or
4908                   l_other_message is not null then exit; end if;
4909 
4910                FOR I IN 1..p_eam_direct_items_tbl.COUNT LOOP
4911                  -- If there is an entity with error, then flag it and exit.
4912                  IF p_eam_direct_items_tbl(I).transaction_type is not null and
4913                     (p_eam_direct_items_tbl(I).wip_entity_id is null or
4914                      p_eam_direct_items_tbl(I).organization_id is null) then
4915                    l_other_message := 'EAM_WO_DI_REC_INVALID';
4916                    EXIT;
4917                  END IF;
4918                  IF p_eam_direct_items_tbl(I).wip_entity_id is not null AND
4919                     p_eam_direct_items_tbl(I).organization_id is not null
4920                  THEN
4921                     l_wip_entity_id   := p_eam_direct_items_tbl(I).wip_entity_id;
4922                     l_organization_id := p_eam_direct_items_tbl(I).organization_id;
4923                     EXIT;
4924                  END IF;
4925                END LOOP;
4926                IF l_wip_entity_id is not null or
4927                   l_other_message is not null then exit; end if;
4928 
4929                FOR I IN 1..p_eam_mat_req_tbl.COUNT LOOP
4930                  -- If there is an entity with error, then flag it and exit.
4931                  IF p_eam_mat_req_tbl(I).transaction_type is not null and
4932                     (p_eam_mat_req_tbl(I).wip_entity_id is null or
4933                      p_eam_mat_req_tbl(I).organization_id is null) then
4934                    l_other_message := 'EAM_WO_MAT_REC_INVALID';
4935                    EXIT;
4936                  END IF;
4937                  IF p_eam_mat_req_tbl(I).wip_entity_id is not null AND
4938                     p_eam_mat_req_tbl(I).organization_id is not null
4939                  THEN
4940                     l_wip_entity_id   := p_eam_mat_req_tbl(I).wip_entity_id;
4941                     l_organization_id := p_eam_mat_req_tbl(I).organization_id;
4942                     EXIT;
4943                  END IF;
4944                END LOOP;
4945 
4946              END LOOP;
4947 
4948              -- If there is no weid even in the child tables, or if one of the
4949              -- entities had error in them, then return false
4950              IF (l_wip_entity_id is null or l_other_message is not null) --AND
4951                  --p_eam_wo_comp_rec.transaction_type IS NULL AND
4952                  --p_eam_op_comp_tbl.COUNT = 0 AND
4953                  --p_eam_request_tbl.COUNT = 0)
4954              then
4955 
4956              x_return_status := 'E';
4957 
4958                l_out_eam_wo_rec            := l_eam_wo_rec;
4959                l_out_eam_op_tbl            := l_eam_op_tbl;
4960                l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
4961                l_out_eam_res_tbl           := l_eam_res_tbl;
4962                l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
4963                l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
4964                l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
4965                l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
4966                l_out_eam_direct_items_tbl  := l_eam_direct_items_tbl;
4967 
4968                -- Log the error
4969                EAM_ERROR_MESSAGE_PVT.Log_Error
4970                  (  p_eam_wo_rec             => l_eam_wo_rec
4971                  ,  p_eam_op_tbl             => l_eam_op_tbl
4972                  ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
4973                  ,  p_eam_res_tbl            => l_eam_res_tbl
4974                  ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
4975                  ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
4976                  ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
4977                  ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
4978                  ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
4979                  ,  p_mesg_token_tbl         => l_mesg_token_tbl
4980                  ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
4981                  ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_ALL
4982                  ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_BO_LEVEL
4983                  ,  p_other_message          => l_other_message
4984                  ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
4985                  ,  p_other_token_tbl        => l_token_tbl
4986                  ,  x_eam_wo_rec             => l_out_eam_wo_rec
4987                  ,  x_eam_op_tbl             => l_out_eam_op_tbl
4988                  ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
4989                  ,  x_eam_res_tbl            => l_out_eam_res_tbl
4990                  ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
4991                  ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
4992                  ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
4993                  ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
4994                  ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
4995                );
4996 
4997                l_eam_wo_rec            := l_out_eam_wo_rec;
4998                l_eam_op_tbl            := l_out_eam_op_tbl;
4999                l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
5000                l_eam_res_tbl           := l_out_eam_res_tbl;
5001                l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
5002                l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
5003                l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
5004                l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
5005                l_eam_direct_items_tbl  := l_out_eam_direct_items_tbl;
5006 
5007              END IF;
5008 
5009              RETURN;
5010 
5011            ELSE
5012 
5013              l_wip_entity_id   := p_eam_wo_rec.wip_entity_id;
5014              l_organization_id := p_eam_wo_rec.organization_id;
5015            END IF;
5016            -- end - baroy
5017 
5018 IF EAM_PROCESS_WO_PVT.get_debug = 'Y' then EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.CHECK_BO_RECORD : Validating OP record'); END IF;
5019 
5020            FOR I IN 1..p_eam_op_tbl.COUNT LOOP
5021                IF p_eam_op_tbl(I).wip_entity_id is not null AND (
5022                   p_eam_op_tbl(I).wip_entity_id <> l_wip_entity_id OR
5023                   p_eam_op_tbl(I).organization_id <> l_organization_id)
5024                THEN
5025                   x_return_status := 'E';
5026                   l_other_message := 'EAM_WO_BO_REC_INVALID';
5027                END IF;
5028            END LOOP;
5029 
5030 IF EAM_PROCESS_WO_PVT.get_debug = 'Y' then EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.CHECK_BO_RECORD : Validating OPN record'); END IF;
5031 
5032            FOR I IN 1..p_eam_op_network_tbl.COUNT LOOP
5033                IF p_eam_op_network_tbl(I).wip_entity_id is not null AND (
5034                   p_eam_op_network_tbl(I).wip_entity_id <> l_wip_entity_id OR
5035                   p_eam_op_network_tbl(I).organization_id <> l_organization_id)
5036                THEN
5037                   x_return_status := 'E';
5038                   l_other_message := 'EAM_WO_BO_REC_INVALID';
5039                END IF;
5040            END LOOP;
5041 
5042 IF EAM_PROCESS_WO_PVT.get_debug = 'Y' then EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.CHECK_BO_RECORD : Validating RES record'); END IF;
5043 
5044            FOR I IN 1..p_eam_res_tbl.COUNT LOOP
5045 
5046                IF p_eam_res_tbl(I).wip_entity_id is not null AND (
5047                   p_eam_res_tbl(I).wip_entity_id <> l_wip_entity_id OR
5048                   p_eam_res_tbl(I).organization_id <> l_organization_id)
5049                THEN
5050 	          x_return_status := 'E';
5051                   l_other_message := 'EAM_WO_BO_REC_INVALID';
5052                END IF;
5053            END LOOP;
5054 
5055 IF EAM_PROCESS_WO_PVT.get_debug = 'Y' then EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.CHECK_BO_RECORD : Validating RES_INST record'); END IF;
5056 
5057            FOR I IN 1..p_eam_res_inst_tbl.COUNT LOOP
5058                IF p_eam_res_inst_tbl(I).wip_entity_id is not null AND (
5059                   p_eam_res_inst_tbl(I).wip_entity_id <> l_wip_entity_id OR
5060                   p_eam_res_inst_tbl(I).organization_id <> l_organization_id)
5061                THEN
5062                   x_return_status := 'E';
5063                   l_other_message := 'EAM_WO_BO_REC_INVALID';
5064                END IF;
5065            END LOOP;
5066 
5067 IF EAM_PROCESS_WO_PVT.get_debug = 'Y' then EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.CHECK_BO_RECORD : Validating SUB_RES record'); END IF;
5068 
5069            FOR I IN 1..p_eam_sub_res_tbl.COUNT LOOP
5070                IF p_eam_sub_res_tbl(I).wip_entity_id is not null AND (
5071                   p_eam_sub_res_tbl(I).wip_entity_id <> l_wip_entity_id OR
5072                   p_eam_sub_res_tbl(I).organization_id <> l_organization_id)
5073                THEN
5074                   x_return_status := 'E';
5075                   l_other_message := 'EAM_WO_BO_REC_INVALID';
5076                END IF;
5077            END LOOP;
5078 
5079 IF EAM_PROCESS_WO_PVT.get_debug = 'Y' then EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.CHECK_BO_RECORD : Validating RES_USAGE record'); END IF;
5080 
5081            FOR I IN 1..p_eam_res_usage_tbl.COUNT LOOP
5082                IF p_eam_res_usage_tbl(I).wip_entity_id is not null AND (
5083                   p_eam_res_usage_tbl(I).wip_entity_id <> l_wip_entity_id OR
5084                   p_eam_res_usage_tbl(I).organization_id <> l_organization_id)
5085                THEN
5086                   x_return_status := 'E';
5087                   l_other_message := 'EAM_WO_BO_REC_INVALID';
5088                END IF;
5089            END LOOP;
5090 
5091 IF EAM_PROCESS_WO_PVT.get_debug = 'Y' then EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.CHECK_BO_RECORD : Validating MAT_REQ record'); END IF;
5092 
5093            FOR I IN 1..p_eam_mat_req_tbl.COUNT LOOP
5094                IF p_eam_mat_req_tbl(I).wip_entity_id is not null AND (
5095                   p_eam_mat_req_tbl(I).wip_entity_id <> l_wip_entity_id OR
5096                   p_eam_mat_req_tbl(I).organization_id <> l_organization_id)
5097                THEN
5098                   x_return_status := 'E';
5099                   l_other_message := 'EAM_WO_BO_REC_INVALID';
5100                END IF;
5101            END LOOP;
5102 
5103 IF EAM_PROCESS_WO_PVT.get_debug = 'Y' then EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.CHECK_BO_RECORD : Validating DI record'); END IF;
5104 
5105            FOR I IN 1..p_eam_direct_items_tbl.COUNT LOOP
5106                IF p_eam_direct_items_tbl(I).wip_entity_id is not null AND (
5107                   p_eam_direct_items_tbl(I).wip_entity_id <> l_wip_entity_id OR
5108                   p_eam_direct_items_tbl(I).organization_id <> l_organization_id)
5109                THEN
5110                   x_return_status := 'E';
5111                   l_other_message := 'EAM_WO_BO_REC_INVALID';
5112                END IF;
5113            END LOOP;
5114 
5115            IF x_return_status = 'E' THEN
5116              -- Log the error
5117 
5118              l_out_eam_wo_rec            := l_eam_wo_rec;
5119              l_out_eam_op_tbl            := l_eam_op_tbl;
5120              l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
5121              l_out_eam_res_tbl           := l_eam_res_tbl;
5122              l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
5123              l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
5124              l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
5125              l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
5126              l_out_eam_direct_items_tbl  := l_eam_direct_items_tbl;
5127 
5128              EAM_ERROR_MESSAGE_PVT.Log_Error
5129                (  p_eam_wo_rec             => l_eam_wo_rec
5130                ,  p_eam_op_tbl             => l_eam_op_tbl
5131                ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
5132                ,  p_eam_res_tbl            => l_eam_res_tbl
5133                ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
5134                ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
5135                ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
5136                ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
5137                ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
5138                ,  p_mesg_token_tbl         => l_mesg_token_tbl
5139                ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
5140                ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_ALL
5141                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_BO_LEVEL
5142                ,  p_other_message          => l_other_message
5143                ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
5144                ,  p_other_token_tbl        => l_token_tbl
5145                ,  x_eam_wo_rec             => l_out_eam_wo_rec
5146                ,  x_eam_op_tbl             => l_out_eam_op_tbl
5147                ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
5148                ,  x_eam_res_tbl            => l_out_eam_res_tbl
5149                ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
5150                ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
5151                ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
5152                ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
5153                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
5154              );
5155 
5156              l_eam_wo_rec            := l_out_eam_wo_rec;
5157              l_eam_op_tbl            := l_out_eam_op_tbl;
5158              l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
5159              l_eam_res_tbl           := l_out_eam_res_tbl;
5160              l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
5161              l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
5162              l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
5163              l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
5164              l_eam_direct_items_tbl  := l_out_eam_direct_items_tbl;
5165 
5166              RETURN;
5167            END IF;
5168 
5169      -- Add check for work order completion reocrds.Need to add for operation
5170      -- comlpetions and work/service request records
5171 
5172      IF p_eam_wo_comp_rec.transaction_type IS NOT NULL THEN
5173 
5174 
5175 
5176 
5177 	  l_wip_entity_id   := p_eam_wo_comp_rec.wip_entity_id;
5178           l_organization_id := p_eam_wo_comp_rec.organization_id;
5179 
5180 	   l_eam_wo_quality_tbl		:= p_eam_wo_quality_tbl;
5181 	   l_eam_meter_reading_tbl	:= p_eam_meter_reading_tbl;
5182 	   l_eam_wo_comp_rebuild_tbl	:= p_eam_wo_comp_rebuild_tbl;
5183 	   l_eam_wo_comp_mr_read_tbl	:= p_eam_wo_comp_mr_read_tbl;
5184 
5185 
5186 	  IF EAM_PROCESS_WO_PVT.get_debug = 'Y' then EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.CHECK_BO_RECORD : Validating Quality record'); END IF;
5187 
5188            FOR I IN 1..l_eam_wo_quality_tbl.COUNT LOOP
5189                IF p_eam_wo_quality_tbl(I).wip_entity_id is not null AND (
5190                   p_eam_wo_quality_tbl(I).wip_entity_id <> l_wip_entity_id OR
5191                   p_eam_wo_quality_tbl(I).organization_id <> l_organization_id)
5192                THEN
5193                   x_return_status := 'E';
5194                   l_other_message := 'EAM_WO_BO_REC_INVALID';
5195                END IF;
5196            END LOOP;
5197 
5198    	  IF EAM_PROCESS_WO_PVT.get_debug = 'Y' then EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.CHECK_BO_RECORD : Validating Meter record'); END IF;
5199 
5200            FOR I IN 1..l_eam_meter_reading_tbl.COUNT LOOP
5201                IF p_eam_meter_reading_tbl(I).wip_entity_id is not null AND (
5202                   p_eam_meter_reading_tbl(I).wip_entity_id <> l_wip_entity_id
5203                   )
5204                THEN
5205                   x_return_status := 'E';
5206                   l_other_message := 'EAM_WO_BO_REC_INVALID';
5207                END IF;
5208            END LOOP;
5209 
5210 	   IF EAM_PROCESS_WO_PVT.get_debug = 'Y' then EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.CHECK_BO_RECORD : Validating Counter Properties record'); END IF;
5211 
5212            FOR I IN 1..l_eam_counter_prop_tbl.COUNT LOOP
5213                IF p_eam_counter_prop_tbl(I).wip_entity_id is not null AND (
5214                   p_eam_counter_prop_tbl(I).wip_entity_id <> l_wip_entity_id
5215                   )
5216                THEN
5217                   x_return_status := 'E';
5218                   l_other_message := 'EAM_WO_BO_REC_INVALID';
5219                END IF;
5220            END LOOP;
5221 
5222 
5223 	   IF EAM_PROCESS_WO_PVT.get_debug = 'Y' then EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.CHECK_BO_RECORD : Validating Meter Completion record'); END IF;
5224 
5225            FOR I IN 1..l_eam_wo_comp_rebuild_tbl.COUNT LOOP
5226                IF p_eam_wo_comp_rebuild_tbl(I).wip_entity_id is not null AND (
5227                   p_eam_wo_comp_rebuild_tbl(I).wip_entity_id <> l_wip_entity_id OR
5228                   p_eam_wo_comp_rebuild_tbl(I).organization_id <> l_organization_id)
5229                THEN
5230                   x_return_status := 'E';
5231                   l_other_message := 'EAM_WO_BO_REC_INVALID';
5232                END IF;
5233            END LOOP;
5234 
5235 	    IF EAM_PROCESS_WO_PVT.get_debug = 'Y' then EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.CHECK_BO_RECORD : Validating Rebuild Completion record'); END IF;
5236 
5237            FOR I IN 1..l_eam_wo_comp_mr_read_tbl.COUNT LOOP
5238                IF p_eam_wo_comp_mr_read_tbl(I).wip_entity_id is not null AND (
5239                   p_eam_wo_comp_mr_read_tbl(I).wip_entity_id <> l_wip_entity_id OR
5240                   p_eam_wo_comp_mr_read_tbl(I).organization_id <> l_organization_id)
5241                THEN
5242                   x_return_status := 'E';
5243                   l_other_message := 'EAM_WO_BO_REC_INVALID';
5244                END IF;
5245            END LOOP;
5246 
5247 	IF x_return_status = 'E' THEN
5248 	 -- Log the error
5249 
5250              /* l_out_eam_wo_rec            := l_eam_wo_rec;
5251              l_out_eam_op_tbl            := l_eam_op_tbl;
5252              l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
5253              l_out_eam_res_tbl           := l_eam_res_tbl;
5254              l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
5255              l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
5256              l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
5257              l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
5258              l_out_eam_direct_items_tbl  := l_eam_direct_items_tbl;
5259 
5260              EAM_ERROR_MESSAGE_PVT.Log_Error
5261                (  p_eam_wo_rec             => l_eam_wo_rec
5262                ,  p_eam_op_tbl             => l_eam_op_tbl
5263                ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
5264                ,  p_eam_res_tbl            => l_eam_res_tbl
5265                ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
5266                ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
5267                ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
5268                ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
5269                ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
5270                ,  p_mesg_token_tbl         => l_mesg_token_tbl
5271                ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
5272                ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_ALL
5273                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_BO_LEVEL
5274                ,  p_other_message          => l_other_message
5275                ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
5276                ,  p_other_token_tbl        => l_token_tbl
5277                ,  x_eam_wo_rec             => l_out_eam_wo_rec
5278                ,  x_eam_op_tbl             => l_out_eam_op_tbl
5279                ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
5280                ,  x_eam_res_tbl            => l_out_eam_res_tbl
5281                ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
5282                ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
5283                ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
5284                ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
5285                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
5286              );
5287 
5288              l_eam_wo_rec            := l_out_eam_wo_rec;
5289              l_eam_op_tbl            := l_out_eam_op_tbl;
5290              l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
5291              l_eam_res_tbl           := l_out_eam_res_tbl;
5292              l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
5293              l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
5294              l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
5295              l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
5296              l_eam_direct_items_tbl  := l_out_eam_direct_items_tbl; */
5297 
5298              RETURN;
5299       END IF;
5300     END IF;  -- End of check for work order completion record
5301 
5302 
5303            x_return_status := 'S';
5304 
5305 	   IF EAM_PROCESS_WO_PVT.get_debug = 'Y' then EAM_ERROR_MESSAGE_PVT.write_debug(to_char(sysdate,'DD-MON-YY HH:MI:SS')||' EAM_PROCESS_WO_PUB.CHECK_BO_RECORD : End === Status : '||x_return_status||' ==================='); END IF;
5306 
5307            RETURN;
5308 
5309 END CHECK_BO_RECORD;
5310 
5311 
5312 
5313 
5314  PROCEDURE COPY_WORKORDER
5315         (  p_bo_identifier           IN  VARCHAR2 := 'EAM'
5316          , p_api_version_number      IN  NUMBER := 1.0
5317          , p_init_msg_list           IN  VARCHAR2 := fnd_api.g_false
5318          , p_commit                  IN  VARCHAR2 := fnd_api.g_false
5319          , p_wip_entity_id           IN  NUMBER
5320          , p_organization_id         IN  NUMBER
5321          , x_eam_wo_rec              OUT NOCOPY EAM_PROCESS_WO_PUB.eam_wo_rec_type
5322          , x_eam_op_tbl              OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_tbl_type
5323          , x_eam_op_network_tbl      OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
5324          , x_eam_res_tbl             OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_tbl_type
5325          , x_eam_res_inst_tbl        OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
5326          , x_eam_res_usage_tbl       OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
5327          , x_eam_mat_req_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
5328          , x_eam_direct_items_tbl    OUT NOCOPY EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
5329          , x_return_status           OUT NOCOPY VARCHAR2
5330          , x_msg_count               OUT NOCOPY NUMBER
5331          ) IS
5332 
5333 	l_eam_wo_rec               EAM_PROCESS_WO_PUB.eam_wo_rec_type;
5334 	l_eam_op_tbl               EAM_PROCESS_WO_PUB.eam_op_tbl_type;
5335 	l_eam_op_network_tbl       EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
5336 	l_eam_res_tbl              EAM_PROCESS_WO_PUB.eam_res_tbl_type;
5337 	l_eam_sub_res_tbl	   EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
5338 	l_eam_res_inst_tbl         EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
5339 	l_eam_res_usage_tbl        EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
5340 	l_eam_mat_req_tbl          EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
5341 	l_eam_di_tbl		   EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
5342 	l_eam_wo_comp_rec               EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type;
5343 	l_eam_wo_quality_tbl            EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type;
5344 	l_eam_meter_reading_tbl         EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type;
5345 	l_eam_counter_prop_tbl		EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type;
5346 	l_eam_wo_comp_rebuild_tbl       EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type;
5347 	l_eam_wo_comp_mr_read_tbl       EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type;
5348 	l_eam_op_comp_tbl               EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type;
5349 	l_eam_request_tbl               EAM_PROCESS_WO_PUB.eam_request_tbl_type;
5350 
5351 	l_out_eam_wo_rec		EAM_PROCESS_WO_PUB.eam_wo_rec_type;
5352 	l_out_eam_op_tbl		EAM_PROCESS_WO_PUB.eam_op_tbl_type;
5353 	l_out_eam_op_network_tbl	EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
5354 	l_out_eam_res_tbl		EAM_PROCESS_WO_PUB.eam_res_tbl_type;
5355 	l_out_eam_res_inst_tbl		EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
5356 	l_out_eam_sub_res_tbl		EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
5357 	l_out_eam_res_usage_tbl		EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
5358 	l_out_eam_mat_req_tbl		EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
5359 	l_out_eam_di_tbl		EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
5360 	l_out_eam_wo_comp_rec           EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type;
5361 	l_out_eam_wo_quality_tbl        EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type;
5362 	l_out_eam_meter_reading_tbl     EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type;
5363 	l_out_eam_counter_prop_tbl	EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type;
5364 	l_out_eam_wo_comp_rebuild_tbl   EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type;
5365 	l_out_eam_wo_comp_mr_read_tbl   EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type;
5366 	l_out_eam_op_comp_tbl           EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type;
5367 	l_out_eam_request_tbl           EAM_PROCESS_WO_PUB.eam_request_tbl_type;
5368 
5369 	l_return_status			VARCHAR2(1);
5370 	l_msg_count			NUMBER;
5371 	l_output_dir			VARCHAR2(512);
5372 	l_op_count			NUMBER;
5373 	l_eam_op_rec               EAM_PROCESS_WO_PUB.eam_op_rec_type;
5374 	l_eam_op_network_rec       EAM_PROCESS_WO_PUB.eam_op_network_rec_type;
5375 	l_eam_res_rec              EAM_PROCESS_WO_PUB.eam_res_rec_type;
5376 	l_eam_res_inst_rec	   EAM_PROCESS_WO_PUB.eam_res_inst_rec_type;
5377 	l_eam_res_usage_rec        EAM_PROCESS_WO_PUB.eam_res_usage_rec_type;
5378 	l_eam_mat_req_rec          EAM_PROCESS_WO_PUB.eam_mat_req_rec_type;
5379 	l_eam_di_rec		   EAM_PROCESS_WO_PUB.eam_direct_items_rec_type;
5380 
5381 	TYPE wkorder_op_tbl_type            is TABLE OF number INDEX BY BINARY_INTEGER;
5382 	TYPE wkorder_op_netwrk_tbl_type     is TABLE OF number INDEX BY BINARY_INTEGER;
5383 
5384 	l_wkorder_op_tbl	     wkorder_op_tbl_type;
5385 	l_wkorder_op_netwrk_tbl	     wkorder_op_netwrk_tbl_type;
5386 
5387 	l_op_index		NUMBER;
5388 	l_op_res_index		NUMBER;
5389 	l_op_res_inst_index	NUMBER;
5390 	l_op_network_index	NUMBER;
5391 	l_op_material_index	NUMBER;
5392 	l_op_direct_item_index	NUMBER;
5393 
5394 	l_old_activity_id	NUMBER;
5395 
5396 	CURSOR l_operations is
5397 	select
5398 		wip_entity_id		,
5399 		organization_id		,
5400 		operation_seq_num 	,
5401 		standard_operation_id	,
5402 		department_id         	,
5403 		operation_sequence_id 	,
5404 		description           	,
5405 		minimum_transfer_quantity	,
5406 		count_point_type      ,
5407 		backflush_flag        ,
5408 		shutdown_type         ,
5409 		first_unit_start_date             ,
5410 		last_unit_completion_date        ,
5411 		attribute_category    ,
5412 		attribute1            ,
5413 		attribute2            ,
5414 		attribute3            ,
5415 		attribute4            ,
5416 		attribute5            ,
5417 		attribute6            ,
5418 		attribute7            ,
5419 		attribute8            ,
5420 		attribute9            ,
5421 		attribute10           ,
5422 		attribute11           ,
5423 		attribute12           ,
5424 		attribute13           ,
5425 		attribute14           ,
5426 		attribute15           ,
5427 		long_description
5428 	from wip_operations
5429 	where wip_entity_id = p_wip_entity_id;
5430 
5431 	CURSOR l_op_resources is
5432 	select
5433 		wor.wip_entity_id		    ,
5434 		wor.organization_id		    ,
5435 		wor.operation_seq_num               ,
5436 		wor.resource_seq_num                ,
5437 		wor.resource_id                     ,
5438 		wor.uom_code                        ,
5439 		wor.basis_type                      ,
5440 		wor.usage_rate_or_amount            ,
5441 		wor.activity_id                     ,
5442 		wor.scheduled_flag                  ,
5443 		wor.firm_flag			    ,
5444 		wor.assigned_units                  ,
5445 		wor.maximum_assigned_units          ,
5446 		wor.autocharge_type                 ,
5447 		wor.standard_rate_flag              ,
5448 		wor.applied_resource_units          ,
5449 		wor.applied_resource_value          ,
5450 		wor.start_date                      ,
5451 		wor.completion_date                 ,
5452 		wor.schedule_seq_num                ,
5453 		wor.substitute_group_num            ,
5454 		wor.replacement_group_num           ,
5455 		wor.attribute_category              ,
5456 		wor.attribute1                      ,
5457 		wor.attribute2                      ,
5458 		wor.attribute3                      ,
5459 		wor.attribute4                      ,
5460 		wor.attribute5                      ,
5461 		wor.attribute6                      ,
5462 		wor.attribute7                      ,
5463 		wor.attribute8                      ,
5464 		wor.attribute9                      ,
5465 		wor.attribute10                     ,
5466 		wor.attribute11                     ,
5467 		wor.attribute12                     ,
5468 		wor.attribute13                     ,
5469 		wor.attribute14                     ,
5470 		wor.attribute15                     ,
5471 		wor.department_id
5472 	 from   wip_operations wo,
5473 	        wip_operation_resources wor
5474 	 where wo.wip_entity_id = p_wip_entity_id
5475 	   and wor.wip_entity_id = p_wip_entity_id
5476 	   and wo.operation_seq_num = wor.operation_seq_num;
5477 
5478 	 CURSOR l_resource_instances is
5479 	 select
5480 		wori.wip_entity_id       	,
5481 		wori.organization_id     	,
5482 		wori.operation_seq_num   	,
5483 		wori.resource_seq_num    	,
5484 		wori.instance_id         	,
5485 		wori.serial_number      	,
5486 		wori.start_date       		,
5487 		wori.completion_date     	,
5488 		wori.batch_id
5489 	 from  wip_op_resource_instances wori,
5490 	       wip_operation_resources wor
5491 	 where wor.wip_entity_id = p_wip_entity_id
5492 	   and wori.wip_entity_id = p_wip_entity_id
5493 	   and wori.operation_seq_num = wor.operation_seq_num
5494 	   and wori.resource_seq_num = wor.resource_seq_num;
5495 
5496 	CURSOR l_op_network IS
5497 		SELECT
5498 			wip_entity_id		 ,
5499 			organization_id		 ,
5500 			prior_operation          ,
5501 			next_operation		 ,
5502 			attribute_category       ,
5503 			attribute1               ,
5504 			attribute2               ,
5505 			attribute3               ,
5506 			attribute4               ,
5507 			attribute5               ,
5508 			attribute6               ,
5509 			attribute7               ,
5510 			attribute8               ,
5511 			attribute9               ,
5512 			attribute10              ,
5513 			attribute11              ,
5514 			attribute12              ,
5515 			attribute13              ,
5516 			attribute14              ,
5517 			attribute15
5518 		FROM
5519 			wip_operation_networks
5520 	       WHERE    wip_entity_id = p_wip_entity_id;
5521 
5522 		 CURSOR l_op_material IS
5523 			SELECT
5524 			wip_entity_id              ,
5525 			organization_id            ,
5526 			operation_seq_num          ,
5527 			inventory_item_id          ,
5528 			quantity_per_assembly      ,
5529 			department_id              ,
5530 			wip_supply_type            ,
5531 			date_required              ,
5532 			required_quantity          ,
5533 			released_quantity          ,
5534 			quantity_issued            ,
5535 			supply_subinventory        ,
5536 			supply_locator_id          ,
5537 			mrp_net_flag               ,
5538 			mps_required_quantity      ,
5539 			mps_date_required          ,
5540 			component_sequence_id      ,
5541 			comments                   ,
5542 			attribute_category         ,
5543 			attribute1                 ,
5544 			attribute2                 ,
5545 			attribute3                 ,
5546 			attribute4                 ,
5547 			attribute5                 ,
5548 			attribute6                 ,
5549 			attribute7                 ,
5550 			attribute8                 ,
5551 			attribute9                 ,
5552 			attribute10                ,
5553 			attribute11                ,
5554 			attribute12                ,
5555 			attribute13                ,
5556 			attribute14                ,
5557 			attribute15                ,
5558 			auto_request_material      ,
5559 			suggested_vendor_name      ,
5560 			vendor_id                  ,
5561 			unit_price
5562 		  FROM  wip_requirement_operations wro
5563 		  WHERE wro.wip_entity_id = p_wip_entity_id
5564 		    AND wro.organization_id = p_organization_id;
5565 
5566 		    CURSOR l_op_direct_item IS
5567 			SELECT
5568 			description                    ,
5569 			purchasing_category_id         ,
5570 			direct_item_sequence_id        ,
5571 			operation_seq_num              ,
5572 			department_id                  ,
5573 			wip_entity_id                  ,
5574 			organization_id                ,
5575 			suggested_vendor_name	       ,
5576 			suggested_vendor_id            ,
5577 			suggested_vendor_site	       ,
5578 			suggested_vendor_site_id       ,
5579 			suggested_vendor_contact       ,
5580 			suggested_vendor_contact_id    ,
5581 			suggested_vendor_phone         ,
5582 			suggested_vendor_item_num      ,
5583 			unit_price                     ,
5584 			auto_request_material	       ,
5585 			required_quantity              ,
5586 			uom                            ,
5587 			need_by_date                   ,
5588 			attribute_category             ,
5589 			attribute1                     ,
5590 			attribute2                     ,
5591 			attribute3                     ,
5592 			attribute4                     ,
5593 			attribute5                     ,
5594 			attribute6                     ,
5595 			attribute7                     ,
5596 			attribute8                     ,
5597 			attribute9                     ,
5598 			attribute10                    ,
5599 			attribute11		       ,
5600 			attribute12                    ,
5601 			attribute13                    ,
5602 			attribute14                    ,
5603 			attribute15
5604 		FROM    wip_eam_direct_items wedi
5605                 WHERE   wedi.wip_entity_id = p_wip_entity_id
5606                 AND     wedi.organization_id = p_organization_id;
5607 
5608 	 BEGIN
5609 
5610 	l_op_index		:=1;
5611 	l_op_res_index		:=1;
5612 	l_op_res_inst_index	:=1;
5613 	l_op_network_index	:=1;
5614 	l_op_material_index	:=1;
5615 	l_op_direct_item_index	:=1;
5616 
5617  -- Get Work Order Header information
5618 	EAM_WO_UTILITY_PVT.Query_Row(
5619 		p_wip_entity_id     => p_wip_entity_id ,
5620 		p_organization_id   => p_organization_id,
5621 		x_eam_wo_rec        => l_eam_wo_rec,
5622 		x_Return_status     => l_Return_status
5623 	);
5624 
5625 	l_eam_wo_rec.header_id			:= 1;
5626 	l_eam_wo_rec.batch_id			:= 1;
5627 	l_eam_wo_rec.wip_entity_name		:= null;
5628 	l_eam_wo_rec.wip_entity_id		:= null;
5629 
5630 
5631 	l_old_activity_id			:= l_eam_wo_rec.asset_activity_id;
5632 	l_eam_wo_rec.asset_activity_id		:= null;
5633 	l_eam_wo_rec.transaction_type		:= EAM_PROCESS_WO_PVT.G_OPR_CREATE;
5634 	l_eam_wo_rec.return_status		:= null;
5635 
5636 	l_eam_wo_rec.date_released		:= null;
5637 	l_eam_wo_rec.cycle_id			:= null;
5638 	l_eam_wo_rec.seq_id			:= null;
5639 	l_eam_wo_rec.pm_schedule_id		:= null;
5640 	l_eam_wo_rec.parent_wip_entity_id	:= null;
5641 	l_eam_wo_rec.pending_flag               := null;
5642 	l_eam_wo_rec.status_type                := 17;  --draft
5643 	l_eam_wo_rec.user_defined_status_id     := 17;  --draft
5644 
5645 	FOR opRec IN l_operations LOOP
5646 
5647 		l_eam_op_rec.header_id		:= 1;
5648 		l_eam_op_rec.batch_id		:= 1;
5649 		l_eam_op_rec.wip_entity_id	:= null;
5650 		l_eam_op_rec.transaction_type	:= EAM_PROCESS_WO_PVT.G_OPR_CREATE;
5651 		l_eam_op_rec.return_status	:= null;
5652 
5653 		l_eam_op_rec.organization_id          := opRec.organization_id;
5654 		l_eam_op_rec.operation_seq_num        := opRec.operation_seq_num;
5655 		l_eam_op_rec.department_id            := opRec.department_id;
5656 		l_eam_op_rec.operation_sequence_id    := opRec.operation_sequence_id;
5657 		l_eam_op_rec.description              := opRec.description;
5658 		l_eam_op_rec.minimum_transfer_quantity:= opRec.minimum_transfer_quantity;
5659 		l_eam_op_rec.count_point_type         := opRec.count_point_type;
5660 		l_eam_op_rec.backflush_flag           := opRec.backflush_flag;
5661 		l_eam_op_rec.shutdown_type            := opRec.shutdown_type;
5662 		l_eam_op_rec.start_date               := opRec.first_unit_start_date;
5663 		l_eam_op_rec.completion_date          := opRec.last_unit_completion_date;
5664 		l_eam_op_rec.attribute_category       := opRec.attribute_category;
5665 		l_eam_op_rec.attribute1               := opRec.attribute1;
5666 		l_eam_op_rec.attribute2               := opRec.attribute2;
5667 		l_eam_op_rec.attribute3               := opRec.attribute3;
5668 		l_eam_op_rec.attribute4               := opRec.attribute4;
5669 		l_eam_op_rec.attribute5               := opRec.attribute5;
5670 		l_eam_op_rec.attribute6               := opRec.attribute6;
5671 		l_eam_op_rec.attribute7               := opRec.attribute7;
5672 		l_eam_op_rec.attribute8               := opRec.attribute8;
5673 		l_eam_op_rec.attribute9               := opRec.attribute9;
5674 		l_eam_op_rec.attribute10              := opRec.attribute10;
5675 		l_eam_op_rec.attribute11              := opRec.attribute11;
5676 		l_eam_op_rec.attribute12              := opRec.attribute12;
5677 		l_eam_op_rec.attribute13              := opRec.attribute13;
5678 		l_eam_op_rec.attribute14              := opRec.attribute14;
5679 		l_eam_op_rec.attribute15              := opRec.attribute15;
5680 		l_eam_op_rec.long_description         := opRec.long_description;
5681 
5682 		l_eam_op_tbl(l_op_index) := l_eam_op_rec;
5683 
5684 		l_op_index := l_op_index +1;
5685 	END LOOP;
5686 
5687 	FOR opRes IN l_op_resources LOOP
5688 		l_eam_res_rec.header_id		:= 1;
5689 		l_eam_res_rec.batch_id		:= 1;
5690 		l_eam_res_rec.wip_entity_id	:= null;
5691 		l_eam_res_rec.transaction_type	:= EAM_PROCESS_WO_PVT.G_OPR_CREATE;
5692 		l_eam_res_rec.return_status	:= null;
5693 
5694 		l_eam_res_rec.organization_id             := opRes.organization_id        ;
5695 		l_eam_res_rec.operation_seq_num           := opRes.operation_seq_num      ;
5696 		l_eam_res_rec.resource_seq_num            := opRes.resource_seq_num       ;
5697 		l_eam_res_rec.resource_id                 := opRes.resource_id            ;
5698 		l_eam_res_rec.uom_code                    := opRes.uom_code               ;
5699 		l_eam_res_rec.basis_type                  := opRes.basis_type             ;
5700 		l_eam_res_rec.usage_rate_or_amount        := opRes.usage_rate_or_amount   ;
5701 		l_eam_res_rec.activity_id                 := opRes.activity_id            ;
5702 		l_eam_res_rec.scheduled_flag              := opRes.scheduled_flag         ;
5703 		l_eam_res_rec.firm_flag			  := opRes.firm_flag		  ;
5704 		l_eam_res_rec.assigned_units              := opRes.assigned_units         ;
5705 		l_eam_res_rec.maximum_assigned_units      := opRes.maximum_assigned_units ;
5706 		l_eam_res_rec.autocharge_type             := opRes.autocharge_type        ;
5707 		l_eam_res_rec.standard_rate_flag          := opRes.standard_rate_flag     ;
5708 		l_eam_res_rec.start_date                  := opRes.start_date             ;
5709 		l_eam_res_rec.completion_date             := opRes.completion_date        ;
5710 		l_eam_res_rec.schedule_seq_num            := opRes.schedule_seq_num       ;
5711 		l_eam_res_rec.substitute_group_num        := opRes.substitute_group_num   ;
5712 		l_eam_res_rec.replacement_group_num       := opRes.replacement_group_num  ;
5713 		l_eam_res_rec.attribute_category          := opRes.attribute_category     ;
5714 		l_eam_res_rec.attribute1                  := opRes.attribute1             ;
5715 		l_eam_res_rec.attribute2                  := opRes.attribute2             ;
5716 		l_eam_res_rec.attribute3                  := opRes.attribute3             ;
5717 		l_eam_res_rec.attribute4                  := opRes.attribute4             ;
5718 		l_eam_res_rec.attribute5                  := opRes.attribute5             ;
5719 		l_eam_res_rec.attribute6                  := opRes.attribute6             ;
5720 		l_eam_res_rec.attribute7                  := opRes.attribute7             ;
5721 		l_eam_res_rec.attribute8                  := opRes.attribute8             ;
5722 		l_eam_res_rec.attribute9                  := opRes.attribute9             ;
5723 		l_eam_res_rec.attribute10                 := opRes.attribute10            ;
5724 		l_eam_res_rec.attribute11                 := opRes.attribute11            ;
5725 		l_eam_res_rec.attribute12                 := opRes.attribute12            ;
5726 		l_eam_res_rec.attribute13                 := opRes.attribute13            ;
5727 		l_eam_res_rec.attribute14                 := opRes.attribute14            ;
5728 		l_eam_res_rec.attribute15                 := opRes.attribute15            ;
5729 		l_eam_res_rec.department_id               := opRes.department_id          ;
5730 
5731 		l_eam_res_tbl(l_op_res_index) := l_eam_res_rec;
5732 
5733 		l_op_res_index := l_op_res_index +1;
5734 
5735 	END LOOP;
5736 
5737 	FOR opResInst IN l_resource_instances LOOP
5738 
5739 		l_eam_res_inst_rec.header_id		:= 1;
5740 		l_eam_res_inst_rec.batch_id		:= 1;
5741 		l_eam_res_inst_rec.wip_entity_id	:= null;
5742 		l_eam_res_inst_rec.transaction_type	:= EAM_PROCESS_WO_PVT.G_OPR_CREATE;
5743 		l_eam_res_inst_rec.return_status	:= null;
5744 
5745 		l_eam_res_inst_rec.organization_id     := opResInst.organization_id    ;
5746 		l_eam_res_inst_rec.operation_seq_num   := opResInst.operation_seq_num  ;
5747 		l_eam_res_inst_rec.resource_seq_num    := opResInst.resource_seq_num   ;
5748 		l_eam_res_inst_rec.instance_id         := opResInst.instance_id        ;
5749 		l_eam_res_inst_rec.serial_number       := opResInst.serial_number      ;
5750 		l_eam_res_inst_rec.start_date          := opResInst.start_date         ;
5751 		l_eam_res_inst_rec.completion_date     := opResInst.completion_date    ;
5752 		l_eam_res_inst_rec.top_level_batch_id  := opResInst.batch_id ;
5753 
5754 		l_eam_res_inst_tbl(l_op_res_inst_index) := l_eam_res_inst_rec;
5755 
5756 		l_op_res_inst_index := l_op_res_inst_index +1;
5757 	END LOOP;
5758 
5759 
5760  	FOR opNetwork IN l_op_network LOOP
5761 
5762 		l_eam_op_network_rec.header_id := 1;
5763 		l_eam_op_network_rec.batch_id := 1;
5764 		l_eam_op_network_rec.wip_entity_id := null;
5765 		l_eam_op_network_rec.transaction_type := EAM_PROCESS_WO_PVT.G_OPR_CREATE;
5766 		l_eam_op_network_rec.return_status	:= null;
5767 
5768 		l_eam_op_network_rec.organization_id     := opNetwork.organization_id     ;
5769 		l_eam_op_network_rec.prior_operation     := opNetwork.prior_operation     ;
5770 		l_eam_op_network_rec.next_operation      := opNetwork.next_operation      ;
5771 		l_eam_op_network_rec.attribute_category  := opNetwork.attribute_category  ;
5772 		l_eam_op_network_rec.attribute1          := opNetwork.attribute1          ;
5773 		l_eam_op_network_rec.attribute2          := opNetwork.attribute2          ;
5774 		l_eam_op_network_rec.attribute3          := opNetwork.attribute3          ;
5775 		l_eam_op_network_rec.attribute4          := opNetwork.attribute4          ;
5776 		l_eam_op_network_rec.attribute5          := opNetwork.attribute5          ;
5777 		l_eam_op_network_rec.attribute6          := opNetwork.attribute6          ;
5778 		l_eam_op_network_rec.attribute7          := opNetwork.attribute7          ;
5779 		l_eam_op_network_rec.attribute8          := opNetwork.attribute8          ;
5780 		l_eam_op_network_rec.attribute9          := opNetwork.attribute9          ;
5781 		l_eam_op_network_rec.attribute10         := opNetwork.attribute10         ;
5782 		l_eam_op_network_rec.attribute11         := opNetwork.attribute11         ;
5783 		l_eam_op_network_rec.attribute12         := opNetwork.attribute12         ;
5784 		l_eam_op_network_rec.attribute13         := opNetwork.attribute13         ;
5785 		l_eam_op_network_rec.attribute14         := opNetwork.attribute14         ;
5786 		l_eam_op_network_rec.attribute15         := opNetwork.attribute15         ;
5787 
5788 		l_eam_op_network_tbl(l_op_network_index) := l_eam_op_network_rec;
5789 
5790 		l_op_network_index := l_op_network_index +1;
5791 
5792 	END LOOP;
5793 
5794  	FOR opMaterial IN l_op_material LOOP
5795 
5796 		l_eam_mat_req_rec.header_id := 1;
5797 		l_eam_mat_req_rec.batch_id := 1;
5798 		l_eam_mat_req_rec.wip_entity_id := null;
5799 		l_eam_mat_req_rec.transaction_type := EAM_PROCESS_WO_PVT.G_OPR_CREATE;
5800 		l_eam_mat_req_rec.return_status	:= null;
5801 
5802 		l_eam_mat_req_rec.organization_id          := opMaterial.organization_id        ;
5803 		l_eam_mat_req_rec.operation_seq_num        := opMaterial.operation_seq_num      ;
5804 		l_eam_mat_req_rec.inventory_item_id        := opMaterial.inventory_item_id      ;
5805 		l_eam_mat_req_rec.quantity_per_assembly    := opMaterial.quantity_per_assembly  ;
5806 		l_eam_mat_req_rec.department_id            := opMaterial.department_id          ;
5807 		l_eam_mat_req_rec.wip_supply_type          := opMaterial.wip_supply_type        ;
5808 		l_eam_mat_req_rec.date_required            := opMaterial.date_required          ;
5809 		l_eam_mat_req_rec.required_quantity        := opMaterial.required_quantity      ;
5810 		l_eam_mat_req_rec.supply_subinventory      := opMaterial.supply_subinventory    ;
5811 		l_eam_mat_req_rec.supply_locator_id        := opMaterial.supply_locator_id      ;
5812 		l_eam_mat_req_rec.mrp_net_flag             := opMaterial.mrp_net_flag           ;
5813 		l_eam_mat_req_rec.component_sequence_id    := opMaterial.component_sequence_id  ;
5814 		l_eam_mat_req_rec.comments                 := opMaterial.comments               ;
5815 		l_eam_mat_req_rec.attribute_category       := opMaterial.attribute_category     ;
5816 		l_eam_mat_req_rec.attribute1               := opMaterial.attribute1             ;
5817 		l_eam_mat_req_rec.attribute2               := opMaterial.attribute2             ;
5818 		l_eam_mat_req_rec.attribute3               := opMaterial.attribute3             ;
5819 		l_eam_mat_req_rec.attribute4               := opMaterial.attribute4             ;
5820 		l_eam_mat_req_rec.attribute5               := opMaterial.attribute5             ;
5821 		l_eam_mat_req_rec.attribute6               := opMaterial.attribute6             ;
5822 		l_eam_mat_req_rec.attribute7               := opMaterial.attribute7             ;
5823 		l_eam_mat_req_rec.attribute8               := opMaterial.attribute8             ;
5824 		l_eam_mat_req_rec.attribute9               := opMaterial.attribute9             ;
5825 		l_eam_mat_req_rec.attribute10              := opMaterial.attribute10            ;
5826 		l_eam_mat_req_rec.attribute11              := opMaterial.attribute11            ;
5827 		l_eam_mat_req_rec.attribute12              := opMaterial.attribute12            ;
5828 		l_eam_mat_req_rec.attribute13              := opMaterial.attribute13            ;
5829 		l_eam_mat_req_rec.attribute14              := opMaterial.attribute14            ;
5830 		l_eam_mat_req_rec.attribute15              := opMaterial.attribute15            ;
5831 		l_eam_mat_req_rec.auto_request_material    := opMaterial.auto_request_material  ;
5832 		l_eam_mat_req_rec.suggested_vendor_name    := opMaterial.suggested_vendor_name  ;
5833 		l_eam_mat_req_rec.vendor_id                := opMaterial.vendor_id              ;
5834 		l_eam_mat_req_rec.unit_price               := opMaterial.unit_price             ;
5835 
5836 		l_eam_mat_req_tbl(l_op_material_index) := l_eam_mat_req_rec;
5837 
5838 		l_op_material_index := l_op_material_index +1;
5839 	END LOOP;
5840 
5841 	FOR opDirectItem IN l_op_direct_item LOOP
5842 
5843 		l_eam_di_rec.header_id := 1;
5844 		l_eam_di_rec.batch_id := 1;
5845 		l_eam_di_rec.wip_entity_id := null;
5846 		l_eam_di_rec.transaction_type := EAM_PROCESS_WO_PVT.G_OPR_CREATE;
5847 		l_eam_di_rec.return_status	:= null;
5848 
5849 		l_eam_di_rec.description                  := opDirectItem.description                  ;
5850 		l_eam_di_rec.purchasing_category_id       := opDirectItem.purchasing_category_id       ;
5851 		l_eam_di_rec.operation_seq_num            := opDirectItem.operation_seq_num            ;
5852 		l_eam_di_rec.department_id                := opDirectItem.department_id                ;
5853 		l_eam_di_rec.organization_id              := opDirectItem.organization_id              ;
5854 		l_eam_di_rec.suggested_vendor_name	  := opDirectItem.suggested_vendor_name	  ;
5855 		l_eam_di_rec.suggested_vendor_id          := opDirectItem.suggested_vendor_id          ;
5856 		l_eam_di_rec.suggested_vendor_site	  := opDirectItem.suggested_vendor_site	  ;
5857 		l_eam_di_rec.suggested_vendor_site_id     := opDirectItem.suggested_vendor_site_id     ;
5858 		l_eam_di_rec.suggested_vendor_contact     := opDirectItem.suggested_vendor_contact     ;
5859 		l_eam_di_rec.suggested_vendor_contact_id  := opDirectItem.suggested_vendor_contact_id  ;
5860 		l_eam_di_rec.suggested_vendor_phone       := opDirectItem.suggested_vendor_phone       ;
5861 		l_eam_di_rec.suggested_vendor_item_num    := opDirectItem.suggested_vendor_item_num    ;
5862 		l_eam_di_rec.unit_price                   := opDirectItem.unit_price                   ;
5863 		l_eam_di_rec.auto_request_material	  := opDirectItem.auto_request_material	  ;
5864 		l_eam_di_rec.required_quantity            := opDirectItem.required_quantity            ;
5865 		l_eam_di_rec.uom                          := opDirectItem.uom                          ;
5866 		l_eam_di_rec.need_by_date                 := opDirectItem.need_by_date                 ;
5867 		l_eam_di_rec.attribute_category           := opDirectItem.attribute_category           ;
5868 		l_eam_di_rec.attribute1                   := opDirectItem.attribute1                   ;
5869 		l_eam_di_rec.attribute2                   := opDirectItem.attribute2                   ;
5870 		l_eam_di_rec.attribute3                   := opDirectItem.attribute3                   ;
5871 		l_eam_di_rec.attribute4                   := opDirectItem.attribute4                   ;
5872 		l_eam_di_rec.attribute5                   := opDirectItem.attribute5                   ;
5873 		l_eam_di_rec.attribute6                   := opDirectItem.attribute6                   ;
5874 		l_eam_di_rec.attribute7                   := opDirectItem.attribute7                   ;
5875 		l_eam_di_rec.attribute8                   := opDirectItem.attribute8                   ;
5876 		l_eam_di_rec.attribute9                   := opDirectItem.attribute9                   ;
5877 		l_eam_di_rec.attribute10                  := opDirectItem.attribute10                  ;
5878 		l_eam_di_rec.attribute11                  := opDirectItem.attribute11                  ;
5879 		l_eam_di_rec.attribute12                  := opDirectItem.attribute12                  ;
5880 		l_eam_di_rec.attribute13                  := opDirectItem.attribute13                  ;
5881 		l_eam_di_rec.attribute14                  := opDirectItem.attribute14                  ;
5882 		l_eam_di_rec.attribute15                  := opDirectItem.attribute15                  ;
5883 
5884 		l_eam_di_tbl(l_op_direct_item_index) := l_eam_di_rec;
5885 
5886 		l_op_direct_item_index := l_op_direct_item_index +1;
5887 	END LOOP;
5888 
5889       EAM_WORKORDER_UTIL_PKG.log_path(l_output_dir);
5890 
5891 	 EAM_PROCESS_WO_PUB.Process_WO
5892                                    ( p_bo_identifier           => 'EAM'
5893                                    , p_init_msg_list           => TRUE
5894                                    , p_api_version_number      => 1.0
5895                                    , p_commit                  => 'N'
5896                                    , p_eam_wo_rec              => l_eam_wo_rec
5897                                    , p_eam_op_tbl              => l_eam_op_tbl
5898                                    , p_eam_op_network_tbl      => l_eam_op_network_tbl
5899                                    , p_eam_res_tbl             => l_eam_res_tbl
5900                                    , p_eam_res_inst_tbl        => l_eam_res_inst_tbl
5901                                    , p_eam_sub_res_tbl         => l_eam_sub_res_tbl
5902                                    , p_eam_res_usage_tbl       => l_eam_res_usage_tbl
5903                                    , p_eam_mat_req_tbl         => l_eam_mat_req_tbl
5904                                    , p_eam_direct_items_tbl    => l_eam_di_tbl
5905                                    , p_eam_wo_comp_rec         => l_eam_wo_comp_rec
5906                                    , p_eam_wo_quality_tbl      => l_eam_wo_quality_tbl
5907                                    , p_eam_meter_reading_tbl   => l_eam_meter_reading_tbl
5908 		 	           , p_eam_counter_prop_tbl    => l_eam_counter_prop_tbl
5909                                    , p_eam_wo_comp_rebuild_tbl => l_eam_wo_comp_rebuild_tbl
5910                                    , p_eam_wo_comp_mr_read_tbl => l_eam_wo_comp_mr_read_tbl
5911                                    , p_eam_op_comp_tbl         => l_eam_op_comp_tbl
5912                                    , p_eam_request_tbl         => l_eam_request_tbl
5913                                    , x_eam_wo_rec              => l_out_eam_wo_rec
5914                                    , x_eam_op_tbl              => l_out_eam_op_tbl
5915                                    , x_eam_op_network_tbl      => l_out_eam_op_network_tbl
5916                                    , x_eam_res_tbl             => l_out_eam_res_tbl
5917                                    , x_eam_res_inst_tbl        => l_out_eam_res_inst_tbl
5918                                    , x_eam_sub_res_tbl         => l_out_eam_sub_res_tbl
5919                                    , x_eam_res_usage_tbl       => l_out_eam_res_usage_tbl
5920                                    , x_eam_mat_req_tbl         => l_out_eam_mat_req_tbl
5921                                    , x_eam_direct_items_tbl    => l_out_eam_di_tbl
5922                                    , x_eam_wo_comp_rec         => l_out_eam_wo_comp_rec
5923                                    , x_eam_wo_quality_tbl      => l_out_eam_wo_quality_tbl
5924                                    , x_eam_meter_reading_tbl   => l_out_eam_meter_reading_tbl
5925 			           , x_eam_counter_prop_tbl    => l_out_eam_counter_prop_tbl
5926                                    , x_eam_wo_comp_rebuild_tbl => l_out_eam_wo_comp_rebuild_tbl
5927                                    , x_eam_wo_comp_mr_read_tbl => l_out_eam_wo_comp_mr_read_tbl
5928                                    , x_eam_op_comp_tbl         => l_out_eam_op_comp_tbl
5929                                    , x_eam_request_tbl         => l_out_eam_request_tbl
5930                                    , x_return_status           => x_return_status
5931                                    , x_msg_count               => x_msg_count
5932                                    , p_debug                   =>  NVL(fnd_profile.value('EAM_DEBUG'), 'N')
5933                                    , p_debug_filename          => 'CopyWorkOrder.log'
5934                                    , p_output_dir              => l_output_dir
5935                                    , p_debug_file_mode         => 'w'
5936                                );
5937 
5938 	update wip_discrete_jobs
5939 	   set primary_item_id = l_old_activity_id
5940 	 where wip_entity_id = l_out_eam_wo_rec.wip_entity_id;
5941 
5942        	update wip_entities
5943 	   set primary_item_id = l_old_activity_id
5944 	 where wip_entity_id = l_out_eam_wo_rec.wip_entity_id; /*added for bug 9974953*/
5945 
5946 	 update wip_operations wo
5947 	    set STANDARD_OPERATION_ID = ( select STANDARD_OPERATION_ID from wip_operations wo1
5948 					   where wo.OPERATION_SEQ_NUM = wo1.OPERATION_SEQ_NUM
5949 					   and wo1.wip_entity_id = p_wip_entity_id
5950 					   )
5951 	    where wip_entity_id = l_out_eam_wo_rec.wip_entity_id;
5952 
5953 	l_out_eam_wo_rec.asset_activity_id := l_old_activity_id;
5954 
5955 	x_eam_wo_rec		:=	l_out_eam_wo_rec;
5956 	x_eam_op_tbl            :=	l_out_eam_op_tbl;
5957 	x_eam_op_network_tbl    :=	l_out_eam_op_network_tbl;
5958 	x_eam_res_tbl           :=	l_out_eam_res_tbl;
5959 	x_eam_res_inst_tbl      :=	l_out_eam_res_inst_tbl;
5960 	x_eam_res_usage_tbl     :=	l_out_eam_res_usage_tbl;
5961 	x_eam_mat_req_tbl       :=	l_out_eam_mat_req_tbl;
5962 	x_eam_direct_items_tbl  :=	l_out_eam_di_tbl;
5963 
5964 	 END COPY_WORKORDER;
5965 
5966 
5967 
5968 
5969 
5970 	     /********************************************************************
5971     * Procedure: Process_WO
5972     * Parameters IN:
5973     *         EAM Work Order column record
5974     *         Operation column table
5975     *         Operation Networks column Table
5976     *         Resource column Table
5977     *         Substitute Resource column table
5978     *         Material Requirements column table
5979     *         Direct Items column table
5980     * Parameters OUT:
5981     *         EAM Work Order column record
5982     *         Operation column table
5983     *         Operation Networks column Table
5984     *         Resource column Table
5985     *         Substitute Resource column table
5986     *         Material Requirements column table
5987     *         Direct Items column table
5988     * Purpose:
5989     *         This procedure is the driving procedure of the EAM
5990     *         business Obect. It will verify the integrity of the
5991     *         business object and will call the private API which
5992     *         further drive the business object to perform business
5993     *         logic validations.
5994     *********************************************************************/
5995 
5996       PROCEDURE PROCESS_WO
5997         (  p_bo_identifier           IN  VARCHAR2 := 'EAM'
5998          , p_api_version_number      IN  NUMBER := 1.0
5999          , p_init_msg_list           IN  BOOLEAN := FALSE
6000          , p_commit                  IN  VARCHAR2 := 'N'
6001          , p_eam_wo_rec              IN EAM_PROCESS_WO_PUB.eam_wo_rec_type
6002          , p_eam_op_tbl              IN EAM_PROCESS_WO_PUB.eam_op_tbl_type
6003          , p_eam_op_network_tbl      IN EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
6004          , p_eam_res_tbl             IN EAM_PROCESS_WO_PUB.eam_res_tbl_type
6005          , p_eam_res_inst_tbl        IN EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
6006          , p_eam_sub_res_tbl         IN EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
6007          , p_eam_res_usage_tbl       IN EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
6008          , p_eam_mat_req_tbl         IN EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
6009          , p_eam_direct_items_tbl    IN EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
6010          , x_eam_wo_rec              OUT NOCOPY EAM_PROCESS_WO_PUB.eam_wo_rec_type
6011          , x_eam_op_tbl              OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_tbl_type
6012          , x_eam_op_network_tbl      OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
6013          , x_eam_res_tbl             OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_tbl_type
6014          , x_eam_res_inst_tbl        OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
6015          , x_eam_sub_res_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
6016          , x_eam_res_usage_tbl       OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
6017          , x_eam_mat_req_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
6018          , x_eam_direct_items_tbl    OUT NOCOPY EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
6019          , x_return_status           OUT NOCOPY VARCHAR2
6020          , x_msg_count               OUT NOCOPY NUMBER
6021          , p_debug                   IN  VARCHAR2 := 'N'
6022          , p_output_dir              IN  VARCHAR2 := NULL
6023          , p_debug_filename          IN  VARCHAR2 := 'EAM_WO_DEBUG.log'
6024          , p_debug_file_mode         IN  VARCHAR2 := 'w'
6025          )
6026 	 IS
6027 
6028 
6029 	l_eam_wo_comp_rec         EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type;
6030 	l_eam_wo_quality_tbl      EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type;
6031 	l_eam_meter_reading_tbl   EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type;
6032  	l_eam_counter_prop_tbl    EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type;
6033 	l_eam_wo_comp_rebuild_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type;
6034 	l_eam_wo_comp_mr_read_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type;
6035 	l_eam_op_comp_tbl         EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type;
6036 	l_eam_request_tbl         EAM_PROCESS_WO_PUB.eam_request_tbl_type;
6037 
6038    	l_out_eam_wo_comp_rec         EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type;
6039 	l_out_eam_wo_quality_tbl      EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type;
6040 	l_out_eam_meter_reading_tbl   EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type;
6041  	l_out_eam_counter_prop_tbl    EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type;
6042 	l_out_eam_wo_comp_rebuild_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type;
6043 	l_out_eam_wo_comp_mr_read_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type;
6044 	l_out_eam_op_comp_tbl         EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type;
6045 	l_out_eam_request_tbl         EAM_PROCESS_WO_PUB.eam_request_tbl_type;
6046 
6047 BEGIN
6048 
6049 	EAM_PROCESS_WO_PUB.PROCESS_WO(
6050 		  p_bo_identifier		=> p_bo_identifier
6051 		, p_api_version_number		=> p_api_version_number
6052 		, p_init_msg_list		=> p_init_msg_list
6053 		, p_commit			=> p_commit
6054 		, p_eam_wo_rec			=> p_eam_wo_rec
6055 		, p_eam_op_tbl			=> p_eam_op_tbl
6056 		, p_eam_op_network_tbl		=> p_eam_op_network_tbl
6057 		, p_eam_res_tbl			=> p_eam_res_tbl
6058 		, p_eam_res_inst_tbl		=> p_eam_res_inst_tbl
6059 		, p_eam_sub_res_tbl		=> p_eam_sub_res_tbl
6060 		, p_eam_res_usage_tbl		=> p_eam_res_usage_tbl
6061 		, p_eam_mat_req_tbl		=> p_eam_mat_req_tbl
6062 		, p_eam_direct_items_tbl	=> p_eam_direct_items_tbl
6063 		, p_eam_wo_comp_rec		=> l_eam_wo_comp_rec
6064 		, p_eam_wo_quality_tbl		=> l_eam_wo_quality_tbl
6065 		, p_eam_meter_reading_tbl	=> l_eam_meter_reading_tbl
6066 		, p_eam_counter_prop_tbl	=> l_eam_counter_prop_tbl
6067 		, p_eam_wo_comp_rebuild_tbl	=> l_eam_wo_comp_rebuild_tbl
6068 		, p_eam_wo_comp_mr_read_tbl	=> l_eam_wo_comp_mr_read_tbl
6069 		, p_eam_op_comp_tbl		=> l_eam_op_comp_tbl
6070 		, p_eam_request_tbl		=> l_eam_request_tbl
6071 		, x_eam_wo_rec			=> x_eam_wo_rec
6072 		, x_eam_op_tbl			=> x_eam_op_tbl
6073 		, x_eam_op_network_tbl		=> x_eam_op_network_tbl
6074 		, x_eam_res_tbl			=> x_eam_res_tbl
6075 		, x_eam_res_inst_tbl		=> x_eam_res_inst_tbl
6076 		, x_eam_sub_res_tbl		=> x_eam_sub_res_tbl
6077 		, x_eam_res_usage_tbl		=> x_eam_res_usage_tbl
6078 		, x_eam_mat_req_tbl		=> x_eam_mat_req_tbl
6079 		, x_eam_direct_items_tbl	=> x_eam_direct_items_tbl
6080 		, x_eam_wo_comp_rec		=> l_out_eam_wo_comp_rec
6081 		, x_eam_wo_quality_tbl		=> l_out_eam_wo_quality_tbl
6082 		, x_eam_meter_reading_tbl	=> l_out_eam_meter_reading_tbl
6083 		, x_eam_counter_prop_tbl	=> l_out_eam_counter_prop_tbl
6084 		, x_eam_wo_comp_rebuild_tbl	=> l_out_eam_wo_comp_rebuild_tbl
6085 		, x_eam_wo_comp_mr_read_tbl	=> l_out_eam_wo_comp_mr_read_tbl
6086 		, x_eam_op_comp_tbl		=> l_out_eam_op_comp_tbl
6087 		, x_eam_request_tbl		=> l_out_eam_request_tbl
6088 		, x_return_status		=> x_return_status
6089 		, x_msg_count			=> x_msg_count
6090 		, p_debug			=> p_debug
6091 		, p_output_dir			=> p_output_dir
6092 		, p_debug_filename		=> p_debug_filename
6093 		, p_debug_file_mode		=> p_debug_file_mode
6094 
6095 	);
6096 
6097 
6098 END PROCESS_WO;
6099 
6100 
6101 
6102 
6103 
6104 PROCEDURE PROCESS_MASTER_CHILD_WO
6105         (  p_bo_identifier           IN  VARCHAR2 := 'EAM'
6106          , p_api_version_number      IN  NUMBER := 1.0
6107          , p_init_msg_list           IN  BOOLEAN := FALSE
6108          , p_eam_wo_relations_tbl    IN  EAM_PROCESS_WO_PUB.eam_wo_relations_tbl_type
6109          , p_eam_wo_tbl              IN  EAM_PROCESS_WO_PUB.eam_wo_tbl_type
6110          , p_eam_op_tbl              IN  EAM_PROCESS_WO_PUB.eam_op_tbl_type
6111          , p_eam_op_network_tbl      IN  EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
6112          , p_eam_res_tbl             IN  EAM_PROCESS_WO_PUB.eam_res_tbl_type
6113          , p_eam_res_inst_tbl        IN  EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
6114          , p_eam_sub_res_tbl         IN  EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
6115          , p_eam_mat_req_tbl         IN  EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
6116          , p_eam_direct_items_tbl    IN  EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
6117          , x_eam_wo_tbl              OUT NOCOPY EAM_PROCESS_WO_PUB.eam_wo_tbl_type
6118          , x_eam_wo_relations_tbl    OUT NOCOPY EAM_PROCESS_WO_PUB.eam_wo_relations_tbl_type
6119          , x_eam_op_tbl              OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_tbl_type
6120          , x_eam_op_network_tbl      OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
6121          , x_eam_res_tbl             OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_tbl_type
6122          , x_eam_res_inst_tbl        OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
6123          , x_eam_sub_res_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
6124          , x_eam_mat_req_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
6125          , x_eam_direct_items_tbl    OUT NOCOPY EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
6126          , x_return_status           OUT NOCOPY VARCHAR2
6127          , x_msg_count               OUT NOCOPY NUMBER
6128          , p_commit                  IN  VARCHAR2 := 'N'
6129          , p_debug                   IN  VARCHAR2 := 'N'
6130          , p_output_dir              IN  VARCHAR2 := NULL
6131          , p_debug_filename          IN  VARCHAR2 := 'EAM_WO_DEBUG.log'
6132          , p_debug_file_mode         IN  VARCHAR2 := 'w'
6133          ) IS
6134 
6135         l_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
6136 
6137 	l_eam_wo_comp_rec         EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type;
6138 	l_eam_wo_comp_tbl         EAM_PROCESS_WO_PUB.eam_wo_comp_tbl_type;
6139 	l_eam_wo_quality_tbl      EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type;
6140 	l_eam_meter_reading_tbl   EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type;
6141 	l_eam_counter_prop_tbl    EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type;
6142 	l_eam_wo_comp_rebuild_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type;
6143 	l_eam_wo_comp_mr_read_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type;
6144 	l_eam_op_comp_tbl         EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type;
6145 	l_eam_request_tbl         EAM_PROCESS_WO_PUB.eam_request_tbl_type;
6146 
6147         l_out_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
6148 
6149 	l_out_eam_wo_comp_rec         EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type;
6150 	l_out_eam_wo_comp_tbl         EAM_PROCESS_WO_PUB.eam_wo_comp_tbl_type;
6151 	l_out_eam_wo_quality_tbl      EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type;
6152 	l_out_eam_meter_reading_tbl   EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type;
6153 	l_out_eam_wo_comp_rebuild_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type;
6154 	l_out_eam_counter_prop_tbl    EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type;
6155 	l_out_eam_wo_comp_mr_read_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type;
6156 	l_out_eam_op_comp_tbl         EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type;
6157 	l_out_eam_request_tbl         EAM_PROCESS_WO_PUB.eam_request_tbl_type;
6158 
6159 BEGIN
6160 	 EAM_PROCESS_WO_PUB.PROCESS_MASTER_CHILD_WO
6161 	(   p_bo_identifier			=> p_bo_identifier
6162 	  , p_api_version_number		=> p_api_version_number
6163 	  , p_init_msg_list			=> p_init_msg_list
6164 	  , p_eam_wo_relations_tbl		=> p_eam_wo_relations_tbl
6165 	  , p_eam_wo_tbl			=> p_eam_wo_tbl
6166 	  , p_eam_op_tbl			=> p_eam_op_tbl
6167 	  , p_eam_op_network_tbl		=> p_eam_op_network_tbl
6168 	  , p_eam_res_tbl			=> p_eam_res_tbl
6169 	  , p_eam_res_inst_tbl			=> p_eam_res_inst_tbl
6170 	  , p_eam_sub_res_tbl			=> p_eam_sub_res_tbl
6171 	  , p_eam_mat_req_tbl			=> p_eam_mat_req_tbl
6172 	  , p_eam_direct_items_tbl		=> p_eam_direct_items_tbl
6173 	  , p_eam_res_usage_tbl			=> l_eam_res_usage_tbl
6174 	  , p_eam_wo_comp_tbl			=> l_eam_wo_comp_tbl
6175 	  , p_eam_wo_quality_tbl      		=> l_eam_wo_quality_tbl
6176 	  , p_eam_meter_reading_tbl   		=> l_eam_meter_reading_tbl
6177 	  , p_eam_counter_prop_tbl    		=> l_eam_counter_prop_tbl
6178 	  , p_eam_wo_comp_rebuild_tbl 		=> l_eam_wo_comp_rebuild_tbl
6179 	  , p_eam_wo_comp_mr_read_tbl 		=> l_eam_wo_comp_mr_read_tbl
6180 	  , p_eam_op_comp_tbl         		=> l_eam_op_comp_tbl
6181 	  , p_eam_request_tbl         		=> l_eam_request_tbl
6182 	  , x_eam_wo_tbl              		=> x_eam_wo_tbl
6183 	  , x_eam_wo_relations_tbl    		=> x_eam_wo_relations_tbl
6184 	  , x_eam_op_tbl              		=> x_eam_op_tbl
6185 	  , x_eam_op_network_tbl      		=> x_eam_op_network_tbl
6186 	  , x_eam_res_tbl             		=> x_eam_res_tbl
6187 	  , x_eam_res_inst_tbl			=> x_eam_res_inst_tbl
6188 	  , x_eam_sub_res_tbl         		=> x_eam_sub_res_tbl
6189 	  , x_eam_mat_req_tbl         		=> x_eam_mat_req_tbl
6190 	  , x_eam_direct_items_tbl    		=> x_eam_direct_items_tbl
6191 	  , x_eam_res_usage_tbl       		=> l_out_eam_res_usage_tbl
6192 	  , x_eam_wo_comp_tbl         		=> l_out_eam_wo_comp_tbl
6193 	  , x_eam_wo_quality_tbl      		=> l_out_eam_wo_quality_tbl
6194 	  , x_eam_meter_reading_tbl   		=> l_out_eam_meter_reading_tbl
6195 	  , x_eam_counter_prop_tbl    		=> l_out_eam_counter_prop_tbl
6196 	  , x_eam_wo_comp_rebuild_tbl 		=> l_out_eam_wo_comp_rebuild_tbl
6197 	  , x_eam_wo_comp_mr_read_tbl 		=> l_out_eam_wo_comp_mr_read_tbl
6198 	  , x_eam_op_comp_tbl         		=> l_out_eam_op_comp_tbl
6199 	  , x_eam_request_tbl         		=> l_out_eam_request_tbl
6200 	  , x_return_status			=> x_return_status
6201 	  , x_msg_count               		=> x_msg_count
6202 	  , p_commit                  		=> p_commit
6203 	  , p_debug                   		=> p_debug
6204 	  , p_output_dir              		=> p_output_dir
6205 	  , p_debug_filename          		=> p_debug_filename
6206 	  , p_debug_file_mode         		=> p_debug_file_mode
6207 	);
6208 
6209 
6210 END PROCESS_MASTER_CHILD_WO;
6211 
6212 
6213 /* This procedure is used to make an entry in wip_eam_direct_items
6214 when a Purchase Requisition/Purchase Order is created  for description direct items in
6215 Purchasing using forms.This procedure is called from purchasing code.
6216 Bug 8450377
6217 */
6218 
6219 PROCEDURE UPDATE_WO_ADD_DES_DIR_ITEM
6220         (  p_wip_entity_id                IN  NUMBER
6221          , p_operation_seq_num            IN  NUMBER
6222          , p_inventory_item_id            IN  NUMBER
6223          , p_description                  IN  VARCHAR2
6224          , p_organization_id              IN  NUMBER
6225          , p_purchasing_category_id       IN  NUMBER
6226          , p_suggested_vendor_name        IN  VARCHAR2 := NULL
6227          , p_suggested_vendor_id          IN  NUMBER   := NULL
6228          , p_suggested_vendor_site        IN  VARCHAR2 := NULL
6229          , p_suggested_vendor_site_id     IN  NUMBER   := NULL
6230          , p_suggested_vendor_contact     IN  VARCHAR2 := NULL
6231          , p_suggested_vendor_contact_id  IN  NUMBER   := NULL
6232          , p_suggested_vendor_phone       IN  VARCHAR2 := NULL
6233          , p_suggested_vendor_item_num    IN  VARCHAR2 := NULL
6234          , p_required_quantity            IN  NUMBER
6235          , p_unit_price                   IN  NUMBER
6236          , p_uom                          IN  VARCHAR2
6237          , p_need_by_date                 IN  DATE
6238          , p_amount                       IN  NUMBER
6239          , p_order_type_lookup_code       IN  VARCHAR2
6240          , x_direct_item_sequence_id      IN OUT NOCOPY NUMBER
6241          , x_return_status                OUT NOCOPY VARCHAR2
6242          ) IS
6243 
6244          l_direct_item_sequence_id NUMBER := NULL;
6245          l_department_id NUMBER := NULL;
6246          l_uom_code VARCHAR2(100);
6247          l_count NUMBER;
6248 	 l_msg_data VARCHAR2(8000) := '';
6249 BEGIN
6250 
6251  --bug 12646632 Set the workorder estimation status if requisition is raised from iprocurement
6252  	   IF p_wip_entity_id is not null then
6253  	      EAM_AutomaticEst. Call_Validate_for_Reestimation(p_wip_entity_id,x_return_status,l_msg_data);
6254  	   END IF;
6255   --bug 12646632
6256 
6257  -- For non-stock direct items no need to populate wip_resource_seq_num.So returning null
6258   IF p_inventory_item_id is not null then
6259     x_direct_item_sequence_id := null;
6260     x_return_status := 'S';
6261     return;
6262   END IF;
6263 
6264   --If x_direct_item_sequence_id is not null,then requisition is being updated.In that case same value should be returned
6265     if x_direct_item_sequence_id is not null then
6266        select sum(count) into l_count from
6267        (
6268 	 select count(*) as count
6269 	 from wip_eam_direct_items wed
6270 	 where wed.wip_entity_id = p_wip_entity_id and
6271 	       wed.operation_seq_num = p_operation_seq_num and
6272 	       wed.direct_item_sequence_id = x_direct_item_sequence_id and
6273 	       wed.organization_id = p_organization_id
6274 
6275 	 union all
6276 
6277 	 SELECT count(*) as count
6278 	 FROM
6279 	   po_requisition_lines_all pr,
6280 	   wip_entities we
6281 	 WHERE
6282 	       pr.destination_organization_id = p_organization_id
6283 	 AND pr.item_id is null
6284 	 AND pr.wip_resource_seq_num = x_direct_item_sequence_id
6285 	 AND pr.destination_type_code = 'SHOP FLOOR'
6286 	 AND pr.wip_entity_id = we.wip_entity_id
6287 	 AND pr.wip_operation_seq_num = p_operation_seq_num
6288 	 AND pr.wip_entity_id = p_wip_entity_id
6289 	 AND we.entity_type in (6,7)
6290 
6291 	 union all
6292 	 SELECT count(*) as count
6293 	 FROM
6294 	   po_distributions_all pd,
6295 	   po_lines_all pl,
6296 	   wip_entities we
6297 	 WHERE
6298 	       pd.destination_organization_id = p_organization_id
6299 	 AND pd.po_line_id = pl.po_line_id(+)
6300 	 AND pl.item_id is null
6301 	 AND pd.wip_resource_seq_num = x_direct_item_sequence_id
6302 	 AND pd.destination_type_code = 'SHOP FLOOR'
6303 	 AND pd.wip_entity_id = we.wip_entity_id
6304 	 AND pd.wip_operation_seq_num = p_operation_seq_num
6305 	 AND pd.wip_entity_id = p_wip_entity_id
6306 	 AND we.entity_type in (6,7)
6307        ) ;
6308 
6309        if(l_count > 0) then
6310 	    x_return_status := 'S';
6311 	    return ;
6312        end if;
6313    end if;
6314 
6315   select count(*) into l_count from wip_eam_direct_items wed where
6316                         wed.wip_entity_id = p_wip_entity_id and
6317                         wed.operation_seq_num = p_operation_seq_num and
6318                         wed.description = p_description and
6319 			wed.organization_id = p_organization_id;
6320 
6321   --Entry is already there. return the direct item sequence id.
6322   if l_count > 0 then
6323     select max(direct_item_sequence_id) into x_direct_item_sequence_id
6324                         from wip_eam_direct_items wed where
6325                         wed.wip_entity_id = p_wip_entity_id and
6326                         wed.operation_seq_num = p_operation_seq_num and
6327                         wed.description = p_description and
6328 			wed.organization_id = p_organization_id;
6329     x_return_status := 'S';
6330     return;
6331   end if;
6332 
6333   select wip_eam_di_seq_id_s.nextval into l_direct_item_sequence_id from dual;
6334 
6335   IF (p_operation_seq_num is not null AND
6336    p_wip_entity_id is not null     AND
6337    p_organization_id is not null)
6338   THEN
6339   SELECT department_id INTO l_department_id
6340   FROM wip_operations
6341   WHERE wip_entity_id = p_wip_entity_id AND
6342         operation_seq_num = p_operation_seq_num AND
6343         organization_id = p_organization_id;
6344   END IF;
6345 
6346   IF(p_uom IS NOT null) THEN -- 9727518
6347   select distinct uom_code into l_uom_code from mtl_uom_conversions muc where muc.unit_of_measure = p_uom;
6348   END IF;
6349 
6350   INSERT INTO WIP_EAM_DIRECT_ITEMS
6351          (
6352            DESCRIPTION
6353          , PURCHASING_CATEGORY_ID
6354          , DIRECT_ITEM_SEQUENCE_ID
6355          , OPERATION_SEQ_NUM
6356          , DEPARTMENT_ID
6357          , WIP_ENTITY_ID
6358          , ORGANIZATION_ID
6359          , SUGGESTED_VENDOR_NAME
6360          , SUGGESTED_VENDOR_ID
6361          , SUGGESTED_VENDOR_SITE
6362          , SUGGESTED_VENDOR_SITE_ID
6363          , SUGGESTED_VENDOR_CONTACT
6364          , SUGGESTED_VENDOR_CONTACT_ID
6365          , SUGGESTED_VENDOR_PHONE
6366          , SUGGESTED_VENDOR_ITEM_NUM
6367          , UNIT_PRICE
6368          , AUTO_REQUEST_MATERIAL
6369          , REQUIRED_QUANTITY
6370          , UOM
6371          , NEED_BY_DATE
6372          , last_update_date
6373          , last_updated_by
6374          , creation_date
6375          , created_by
6376          , last_update_login
6377          , AMOUNT
6378          , ORDER_TYPE_LOOKUP_CODE)
6379 
6380          VALUES
6381          (
6382            p_description
6383          , p_purchasing_category_id
6384          , l_direct_item_sequence_id
6385          , p_operation_seq_num
6386          , l_department_id
6387          , p_wip_entity_id
6388          , p_organization_id
6389          , p_suggested_vendor_name
6390          , p_suggested_vendor_id
6391          , p_suggested_vendor_site
6392          , p_suggested_vendor_site_id
6393          , p_suggested_vendor_contact
6394          , p_suggested_vendor_contact_id
6395          , p_suggested_vendor_phone
6396          , p_suggested_vendor_item_num
6397          , p_unit_price
6398          , 'Y'
6399          , p_required_quantity
6400          , l_uom_code
6401          , p_need_by_date
6402          , SYSDATE
6403          , FND_GLOBAL.user_id
6404          , SYSDATE
6405          , FND_GLOBAL.user_id
6406          , FND_GLOBAL.login_id
6407          , p_amount
6408          , p_order_type_lookup_code);
6409 
6410          x_direct_item_sequence_id := l_direct_item_sequence_id;
6411          x_return_status := 'S';
6412 
6413       EXCEPTION
6414         WHEN OTHERS THEN
6415           x_return_status := 'E';
6416 
6417     END UPDATE_WO_ADD_DES_DIR_ITEM;
6418 
6419 END EAM_PROCESS_WO_PUB;