DBA Data[Home] [Help]

PACKAGE BODY: APPS.GME_API_MAIN

Source


1 PACKAGE BODY gme_api_main AS
2 /*  $Header: GMEMAPIB.pls 120.33.12010000.1 2008/07/25 10:28:49 appldev ship $    */
3    g_debug               VARCHAR2 (5)  := fnd_profile.VALUE ('AFLOG_LEVEL');
4    g_pkg_name   CONSTANT VARCHAR2 (30) := 'gme_api_main';
5 
6 /*************************************************************************/
7    PROCEDURE create_batch (
8       p_validation_level         IN              NUMBER
9             := gme_common_pvt.g_max_errors
10      ,p_init_msg_list            IN              VARCHAR2 := fnd_api.g_false
11      ,x_message_count            OUT NOCOPY      NUMBER
12      ,x_message_list             OUT NOCOPY      VARCHAR2
13      ,x_return_status            OUT NOCOPY      VARCHAR2
14      ,p_batch_header_rec         IN              gme_batch_header%ROWTYPE
15      ,x_batch_header_rec         OUT NOCOPY      gme_batch_header%ROWTYPE
16      ,p_batch_size               IN              NUMBER
17      ,p_batch_size_uom           IN              VARCHAR2
18      ,p_creation_mode            IN              VARCHAR2
19      ,p_recipe_id                IN              NUMBER := NULL
20      ,p_recipe_no                IN              VARCHAR2 := NULL
21      ,p_recipe_version           IN              NUMBER := NULL
22      ,p_product_no               IN              VARCHAR2 := NULL
23      ,p_product_id               IN              NUMBER := NULL
24      ,p_ignore_qty_below_cap     IN              VARCHAR2 := fnd_api.g_true
25      ,p_use_workday_cal          IN              VARCHAR2 := fnd_api.g_true
26      ,p_contiguity_override      IN              VARCHAR2 := fnd_api.g_false
27      ,p_use_least_cost_validity_rule     IN      VARCHAR2 := fnd_api.g_false
28      ,x_exception_material_tbl   OUT NOCOPY      gme_common_pvt.exceptions_tab)
29    IS
30       l_api_name      CONSTANT VARCHAR2 (30) := 'CREATE_BATCH';
31       setup_failure            EXCEPTION;
32       batch_creation_failure   EXCEPTION;
33       invalid_batch            EXCEPTION;
34    BEGIN
35       SAVEPOINT create_batch;
36 
37       IF (g_debug IS NOT NULL) THEN
38          gme_debug.log_initialize ('CreateBatch');
39       END IF;
40 
41       IF g_debug <= gme_debug.g_log_procedure THEN
42          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
43                              || l_api_name);
44       END IF;
45 
46       IF NOT gme_common_pvt.g_setup_done THEN
47          gme_common_pvt.g_setup_done :=
48                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
49 
50          IF NOT gme_common_pvt.g_setup_done THEN
51             x_return_status := fnd_api.g_ret_sts_error;
52             RAISE setup_failure;
53          END IF;
54       END IF;
55 
56       /* Set the return status to success initially */
57       x_return_status := fnd_api.g_ret_sts_success;
58 
59       -- Initialize message list and count if needed
60       IF p_init_msg_list = fnd_api.g_true THEN
61          fnd_msg_pub.initialize;
62          gme_common_pvt.g_error_count := 0;
63       END IF;
64 
65       gme_common_pvt.set_timestamp;
66       gme_create_batch_pvt.create_batch
67                         (p_validation_level            => p_validation_level
68                         ,p_batch_header_rec            => p_batch_header_rec
69                         ,p_batch_size                  => p_batch_size
70                         ,p_batch_size_uom              => p_batch_size_uom
71                         ,p_creation_mode               => p_creation_mode
72                         ,p_ignore_qty_below_cap        => p_ignore_qty_below_cap
73                         ,p_use_workday_cal             => p_use_workday_cal
74                         ,p_contiguity_override         => p_contiguity_override
75                         ,p_use_least_cost_validity_rule => p_use_least_cost_validity_rule
76                         ,x_batch_header_rec            => x_batch_header_rec
77                         ,x_exception_material_tbl      => x_exception_material_tbl
78                         ,x_return_status               => x_return_status);
79 
80       IF x_return_status <> fnd_api.g_ret_sts_success THEN
81          RAISE batch_creation_failure;
82       END IF;            /* IF x_return_status <> FND_API.G_RET_STS_SUCCESS */
83 
84       IF x_message_count = 0 THEN
85          gme_common_pvt.log_message ('GME_API_BATCH_CREATED');
86       END IF;
87 
88       gme_common_pvt.count_and_get (x_count        => x_message_count
89                                    ,p_encoded      => fnd_api.g_false
90                                    ,x_data         => x_message_list);
91 
92       IF (g_debug IS NOT NULL) THEN
93          gme_debug.put_line (   'Completed '
94                              || l_api_name
95                              || ' at '
96                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
97       END IF;
98 
99       IF g_debug <= gme_debug.g_log_procedure THEN
100          gme_debug.put_line ('Exiting api ' || g_pkg_name || '.' || l_api_name);
101       END IF;
102    EXCEPTION
103       WHEN batch_creation_failure THEN
104          IF x_return_status NOT IN (gme_common_pvt.g_inv_short_err) THEN
105             ROLLBACK TO SAVEPOINT create_batch;
106             x_batch_header_rec := NULL;
107          END IF;
108 
109          gme_common_pvt.count_and_get (x_count        => x_message_count
110                                       ,p_encoded      => fnd_api.g_false
111                                       ,x_data         => x_message_list);
112       WHEN setup_failure THEN
113          ROLLBACK TO SAVEPOINT create_batch;
114          x_batch_header_rec := NULL;
115          gme_common_pvt.count_and_get (x_count        => x_message_count
116                                       ,p_encoded      => fnd_api.g_false
117                                       ,x_data         => x_message_list);
118          x_return_status := fnd_api.g_ret_sts_error;
119       WHEN OTHERS THEN
120          IF g_debug <= gme_debug.g_log_unexpected THEN
121             gme_debug.put_line (   'When others exception in '
122                                 || g_pkg_name
123                                 || '.'
124                                 || l_api_name
125                                 || ' Error is '
126                                 || SQLERRM);
127          END IF;
128 
129          ROLLBACK TO SAVEPOINT create_batch;
130          x_batch_header_rec := NULL;
131          gme_common_pvt.count_and_get (x_count        => x_message_count
132                                       ,p_encoded      => fnd_api.g_false
133                                       ,x_data         => x_message_list);
134          x_return_status := fnd_api.g_ret_sts_unexp_error;
135    END create_batch;
136 
137 /*************************************************************************/
138    PROCEDURE create_phantom (
139       p_validation_level         IN              NUMBER
140             := gme_common_pvt.g_max_errors
141      ,p_init_msg_list            IN              VARCHAR2 := fnd_api.g_false
142      ,x_message_count            OUT NOCOPY      NUMBER
143      ,x_message_list             OUT NOCOPY      VARCHAR2
144      ,x_return_status            OUT NOCOPY      VARCHAR2
145      ,p_material_detail_rec      IN              gme_material_details%ROWTYPE
146      ,p_batch_header_rec         IN              gme_batch_header%ROWTYPE --Bug#6738476
147      ,p_batch_no                 IN              VARCHAR2 DEFAULT NULL
148      ,x_material_detail_rec      OUT NOCOPY      gme_material_details%ROWTYPE
149      ,p_validity_rule_id         IN              NUMBER
150      ,p_use_workday_cal          IN              VARCHAR2 := fnd_api.g_true
151      ,p_contiguity_override      IN              VARCHAR2 := fnd_api.g_true
152      ,p_use_least_cost_validity_rule     IN      VARCHAR2 := fnd_api.g_false
153      ,x_exception_material_tbl   OUT NOCOPY      gme_common_pvt.exceptions_tab)
154    IS
155       l_api_name        CONSTANT VARCHAR2 (30)            := 'CREATE_PHANTOM';
156       setup_failure              EXCEPTION;
157       phantom_creation_failure   EXCEPTION;
158       l_batch_header             gme_batch_header%ROWTYPE;
159    BEGIN
160       /* Set the save point initially */
161       SAVEPOINT create_phantom;
162 
163       IF (g_debug IS NOT NULL) THEN
164          gme_debug.log_initialize ('CreatePhantom');
165       END IF;
166 
167       IF g_debug <= gme_debug.g_log_procedure THEN
168          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
169                              || l_api_name);
170       END IF;
171 
172       IF NOT gme_common_pvt.g_setup_done THEN
173          gme_common_pvt.g_setup_done :=
174                  gme_common_pvt.setup (p_material_detail_rec.organization_id);
175 
176          IF NOT gme_common_pvt.g_setup_done THEN
177             x_return_status := fnd_api.g_ret_sts_error;
178             RAISE setup_failure;
179          END IF;
180       END IF;
181 
182       -- Initialize message list and count if needed
183       IF p_init_msg_list = fnd_api.g_true THEN
184          fnd_msg_pub.initialize;
185          gme_common_pvt.g_error_count := 0;
186       END IF;
187 
188       /* Set the return status to success initially */
189       x_return_status := fnd_api.g_ret_sts_success;
190       gme_common_pvt.set_timestamp;
191       gme_phantom_pvt.create_phantom
192                         (p_material_detail_rec         => p_material_detail_rec
193                         ,p_batch_header_rec             => p_batch_header_rec --Bug#6738476
194                         ,p_batch_no                    => p_batch_no
195                         ,x_material_detail_rec         => x_material_detail_rec
196                         ,p_validity_rule_id            => p_validity_rule_id
197                         ,p_use_workday_cal             => p_use_workday_cal
198                         ,p_contiguity_override         => p_contiguity_override
199                         ,p_use_least_cost_validity_rule => p_use_least_cost_validity_rule
200                         ,x_exception_material_tbl      => x_exception_material_tbl
201                         ,x_return_status               => x_return_status);
202 
203       IF x_return_status <> fnd_api.g_ret_sts_success THEN
204          RAISE phantom_creation_failure;
205       END IF;
206 
207       IF (g_debug <= gme_debug.g_log_procedure) THEN
208          gme_debug.put_line (   'Completed '
209                              || l_api_name
210                              || ' at '
211                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
212       END IF;
213    EXCEPTION
214       WHEN phantom_creation_failure OR setup_failure THEN
215          ROLLBACK TO SAVEPOINT create_phantom;
216          x_material_detail_rec := NULL;
217          gme_common_pvt.count_and_get (x_count        => x_message_count
218                                       ,p_encoded      => fnd_api.g_false
219                                       ,x_data         => x_message_list);
220       WHEN OTHERS THEN
221          IF g_debug <= gme_debug.g_log_unexpected THEN
222             gme_debug.put_line (   'When others exception in '
223                                 || g_pkg_name
224                                 || '.'
225                                 || l_api_name
226                                 || ' Error is '
227                                 || SQLERRM);
228          END IF;
229 
230          ROLLBACK TO SAVEPOINT create_phantom;
231          x_material_detail_rec := NULL;
232          fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
233          gme_common_pvt.count_and_get (x_count        => x_message_count
234                                       ,p_encoded      => fnd_api.g_false
235                                       ,x_data         => x_message_list);
236          x_return_status := fnd_api.g_ret_sts_unexp_error;
237    END create_phantom;
238 
239    PROCEDURE scale_batch (
240       p_validation_level         IN              NUMBER
241      ,p_init_msg_list            IN              VARCHAR2
242      ,p_batch_header_rec         IN              gme_batch_header%ROWTYPE
243      ,p_scale_factor             IN              NUMBER
244      ,p_primaries                IN              VARCHAR2
245      ,p_qty_type                 IN              NUMBER
246      ,p_recalc_dates             IN              VARCHAR2
247      ,p_use_workday_cal          IN              VARCHAR2
248      ,p_contiguity_override      IN              VARCHAR2
249      ,x_exception_material_tbl   OUT NOCOPY      gme_common_pvt.exceptions_tab
250      ,x_batch_header_rec         OUT NOCOPY      gme_batch_header%ROWTYPE
251      ,x_message_count            OUT NOCOPY      NUMBER
252      ,x_message_list             OUT NOCOPY      VARCHAR2
253      ,x_return_status            OUT NOCOPY      VARCHAR2)
254    IS
255       l_api_name   CONSTANT VARCHAR2 (30) := 'SCALE_BATCH';
256       scale_batch_failed    EXCEPTION;
257       batch_save_failed     EXCEPTION;
258       batch_fetch_error     EXCEPTION;
259       setup_failure         EXCEPTION;
260    BEGIN
261       /* Set the savepoint before proceeding */
262       SAVEPOINT scale_batch;
263 
264       IF (g_debug IS NOT NULL) THEN
265          gme_debug.log_initialize ('ScaleBatch');
266       END IF;
267 
268       IF g_debug <= gme_debug.g_log_procedure THEN
269          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
270                              || l_api_name);
271       END IF;
272 
273       /* Setup the common constants used accross the apis */
274       IF NOT gme_common_pvt.g_setup_done THEN
275          gme_common_pvt.g_setup_done :=
276                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
277 
278          IF NOT gme_common_pvt.g_setup_done THEN
279             x_return_status := fnd_api.g_ret_sts_error;
280             RAISE setup_failure;
281          END IF;
282       END IF;
283 
284 
285       /* Initialize message list and count if needed */
286       IF p_init_msg_list = fnd_api.g_true THEN
287          fnd_msg_pub.initialize;
288          gme_common_pvt.g_error_count := 0;
289       END IF;
290 
291       x_batch_header_rec := p_batch_header_rec;
292       gme_common_pvt.set_timestamp;
293 
294       gme_scale_batch_pvt.scale_batch
295                         (p_batch_header_rec            => p_batch_header_rec
296                         ,p_scale_factor                => p_scale_factor
297                         ,p_primaries                   => p_primaries
298                         ,p_qty_type                    => p_qty_type
299                         ,p_recalc_dates                => p_recalc_dates
300                         ,p_use_workday_cal             => p_use_workday_cal
301                         ,p_contiguity_override         => p_contiguity_override
302                         ,x_exception_material_tbl      => x_exception_material_tbl
303                         ,x_batch_header_rec            => x_batch_header_rec
304                         ,x_return_status               => x_return_status);
305       x_message_count := 0;
306       -- pawan kumar bug 5358705 add condition for different return status  'c' and 'w'
307       IF x_return_status NOT IN (fnd_api.g_ret_sts_success, 'C', 'W') THEN
308          RAISE scale_batch_failed;
309       END IF;
310        gme_common_pvt.log_message ('GME_SCALE_SUCCESS');
311       IF (g_debug <= gme_debug.g_log_procedure) THEN
312          gme_debug.put_line (   'Completed '
313                              || l_api_name
314                              || ' at '
315                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
316       END IF;
317    EXCEPTION
318       WHEN setup_failure THEN
319          ROLLBACK TO SAVEPOINT scale_batch;
320          x_batch_header_rec := NULL;
321          x_return_status := fnd_api.g_ret_sts_error;
322          gme_common_pvt.count_and_get (x_count        => x_message_count
323                                       ,p_encoded      => fnd_api.g_false
324                                       ,x_data         => x_message_list);
328          gme_common_pvt.count_and_get (x_count        => x_message_count
325       WHEN scale_batch_failed THEN
326          ROLLBACK TO SAVEPOINT scale_batch;
327          x_batch_header_rec := NULL;
329                                       ,p_encoded      => fnd_api.g_false
330                                       ,x_data         => x_message_list);
331       WHEN batch_save_failed OR batch_fetch_error THEN
332          ROLLBACK TO SAVEPOINT scale_batch;
333          x_batch_header_rec := NULL;
334          gme_common_pvt.count_and_get (x_count        => x_message_count
335                                       ,p_encoded      => fnd_api.g_false
336                                       ,x_data         => x_message_list);
337       WHEN OTHERS THEN
338          ROLLBACK TO SAVEPOINT scale_batch;
339          x_batch_header_rec := NULL;
340          fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
341          gme_common_pvt.count_and_get (x_count        => x_message_count
342                                       ,p_encoded      => fnd_api.g_false
343                                       ,x_data         => x_message_list);
344          x_return_status := fnd_api.g_ret_sts_unexp_error;
345    END scale_batch;
346 
347 /*************************************************************************/
348    PROCEDURE theoretical_yield_batch (
349       p_validation_level   IN              NUMBER
350      ,p_init_msg_list      IN              VARCHAR2
351      ,p_batch_header_rec   IN              gme_batch_header%ROWTYPE
352      ,p_scale_factor       IN              NUMBER
353      ,x_message_count      OUT NOCOPY      NUMBER
354      ,x_message_list       OUT NOCOPY      VARCHAR2
355      ,x_return_status      OUT NOCOPY      VARCHAR2)
356    IS
357       l_api_name        CONSTANT VARCHAR2 (30) := 'THEORETICAL_YIELD_BATCH';
358       theoretical_yield_failed   EXCEPTION;
359       setup_failure              EXCEPTION;
360       batch_fetch_error          EXCEPTION;
361       batch_save_failed          EXCEPTION;
362    BEGIN
363       /* Set the savepoint before proceeding */
364       SAVEPOINT theoretical_yield_batch;
365 
366       IF (g_debug IS NOT NULL) THEN
367          gme_debug.log_initialize ('TheoreticalYieldBatch');
368       END IF;
369 
370       IF g_debug <= gme_debug.g_log_procedure THEN
371          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
372                              || l_api_name);
373       END IF;
374 
375       /* Setup the common constants used accross the apis */
376       IF NOT gme_common_pvt.g_setup_done THEN
377          gme_common_pvt.g_setup_done :=
378             gme_common_pvt.setup
379                               (p_org_id      => p_batch_header_rec.organization_id);
380 
381          IF NOT gme_common_pvt.g_setup_done THEN
382             RAISE setup_failure;
383          END IF;
384       END IF;
385 
386       /* Initialize message list and count if needed */
387       IF p_init_msg_list = fnd_api.g_true THEN
388          fnd_msg_pub.initialize;
389          gme_common_pvt.g_error_count := 0;
390       END IF;
391 
392       gme_common_pvt.set_timestamp;
393       gme_scale_batch_pvt.theoretical_yield_batch
394                                     (p_batch_header_rec      => p_batch_header_rec
395                                     ,p_scale_factor          => p_scale_factor
396                                     ,x_return_status         => x_return_status);
397 
398       IF x_return_status <> fnd_api.g_ret_sts_success THEN
399          RAISE theoretical_yield_failed;
400       END IF;
401 
402       gme_common_pvt.count_and_get (x_count        => x_message_count
403                                    ,p_encoded      => fnd_api.g_false
404                                    ,x_data         => x_message_list);
405 
406       IF (g_debug <= gme_debug.g_log_procedure) THEN
407          gme_debug.put_line (   'Completed '
408                              || l_api_name
409                              || ' at '
410                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
411       END IF;
412    EXCEPTION
413       WHEN setup_failure THEN
414          ROLLBACK TO SAVEPOINT theoretical_yield_batch;
415          x_return_status := fnd_api.g_ret_sts_error;
416          gme_common_pvt.count_and_get (x_count        => x_message_count
417                                       ,p_encoded      => fnd_api.g_false
418                                       ,x_data         => x_message_list);
419       WHEN theoretical_yield_failed OR batch_save_failed THEN
420          ROLLBACK TO SAVEPOINT theoretical_yield_batch;
421          gme_common_pvt.count_and_get (x_count        => x_message_count
422                                       ,p_encoded      => fnd_api.g_false
423                                       ,x_data         => x_message_list);
424       WHEN OTHERS THEN
425          ROLLBACK TO SAVEPOINT theoretical_yield_batch;
426          fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
427          gme_common_pvt.count_and_get (x_count        => x_message_count
428                                       ,p_encoded      => fnd_api.g_false
429                                       ,x_data         => x_message_list);
430          x_return_status := fnd_api.g_ret_sts_unexp_error;
431    END theoretical_yield_batch;
432 
433 /*************************************************************************/
434    PROCEDURE insert_material_line (
435       p_validation_level      IN              NUMBER
436             := gme_common_pvt.g_max_errors
437      ,p_init_msg_list         IN              VARCHAR2 := fnd_api.g_false
438      ,x_message_count         OUT NOCOPY      NUMBER
439      ,x_message_list          OUT NOCOPY      VARCHAR2
440      ,x_return_status         OUT NOCOPY      VARCHAR2
441      ,p_batch_header_rec      IN              gme_batch_header%ROWTYPE
442      ,p_material_detail_rec   IN              gme_material_details%ROWTYPE
443      ,p_batch_step_id         IN              NUMBER := NULL
444      ,p_trans_id              IN              NUMBER
445      ,x_transacted            OUT NOCOPY      VARCHAR2
446      ,x_material_detail_rec   OUT NOCOPY      gme_material_details%ROWTYPE)
447    IS
448       l_api_name    CONSTANT VARCHAR2 (30) := 'insert_material_line_form';
449 
450       l_batch_step_rec       gme_batch_steps%ROWTYPE;
451       setup_failure          EXCEPTION;
452       ins_mtl_line_failure   EXCEPTION;
453 
454       -- Bug 5903208
455       gmf_cost_failure         EXCEPTION;
456       l_message_count		   NUMBER;
457       l_message_list		   VARCHAR2(2000);
458    BEGIN
459 
460       /* Set the return status to success initially */
461       x_return_status := fnd_api.g_ret_sts_success;
462 
463       SAVEPOINT insert_material_line1;
464 
465       IF (g_debug IS NOT NULL) THEN
466          gme_debug.log_initialize ('InsertMaterialLineForm');
467       END IF;
468 
469       IF g_debug <= gme_debug.g_log_procedure THEN
470          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
471                              || l_api_name);
472       END IF;
473 
474       IF NOT gme_common_pvt.g_setup_done THEN
475          gme_common_pvt.g_setup_done :=
476                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
477 
478          IF NOT gme_common_pvt.g_setup_done THEN
479             x_return_status := fnd_api.g_ret_sts_error;
480             RAISE setup_failure;
481          END IF;
482       END IF;
483 
484       -- Initialize message list and count if needed
485       IF p_init_msg_list = fnd_api.g_true THEN
486          fnd_msg_pub.initialize;
487          gme_common_pvt.g_error_count := 0;
488       END IF;
489 
490       gme_common_pvt.set_timestamp;
491 
492       IF p_batch_step_id IS NOT NULL THEN
493         l_batch_step_rec.batchstep_id := p_batch_step_id;
494 
495         IF NOT gme_batch_steps_dbl.fetch_row(l_batch_step_rec, l_batch_step_rec) THEN
496            RAISE fnd_api.g_exc_error;
497         END IF;
498       END IF;
499 
500       insert_material_line    (p_validation_level         => p_validation_level
501                               ,p_init_msg_list            => p_init_msg_list
502                               ,x_message_count            => x_message_count
503                               ,x_message_list             => x_message_list
504                               ,x_return_status            => x_return_status
505                               ,p_batch_header_rec         => p_batch_header_rec
506                               ,p_material_detail_rec      => p_material_detail_rec
507                               ,p_batch_step_rec           => l_batch_step_rec
508                               ,p_trans_id                 => p_trans_id
509                               ,x_transacted               => x_transacted
510                               ,x_material_detail_rec      => x_material_detail_rec);
511 
512       IF x_return_status <> fnd_api.g_ret_sts_success THEN
513          RAISE ins_mtl_line_failure;
514       END IF;            /* IF x_return_status <> FND_API.G_RET_STS_SUCCESS */
515 
516       --
517       -- Bug 5903208 -- call to GMF
521         p_batch_id      =>    p_batch_header_rec.batch_id,
518       GMF_VIB.Update_Batch_Requirements
519       ( p_api_version   =>    1.0,
520         p_init_msg_list =>    FND_API.G_FALSE,
522         x_return_status =>    x_return_status,
523         x_msg_count     =>    l_message_count,
524         x_msg_data      =>    l_message_list);
525 
526       IF x_return_status <> FND_API.G_RET_STS_SUCCESS
527       THEN
528          RAISE gmf_cost_failure;
529       END IF;
530       -- NEW
531       GME_ERES_PKG.INSERT_EVENT(P_EVENT_NAME              => gme_common_pvt.G_BATCHMTL_ADDED
532                                ,P_EVENT_KEY               => x_material_detail_rec.batch_id||'-'||x_material_detail_rec.material_detail_id
533                                ,P_USER_KEY_LABEL          => FND_MESSAGE.GET_STRING('GME','GME_PSIG_BATCH_MATL_LABEL')
534                                ,P_USER_KEY_VALUE          => gme_common_pvt.g_organization_code ||
535                                                              '-'||p_batch_header_rec.batch_no||'-'|| x_material_detail_rec.Line_no
536                                                              ||'-'||GME_ERES_PKG.GET_ITEM_NUMBER(x_material_detail_rec.organization_id,x_material_detail_rec.inventory_item_id)
537                                ,P_POST_OP_API             => 'NONE'
538                                ,P_PARENT_EVENT            => NULL
539                                ,P_PARENT_EVENT_KEY        => NULL
540                                ,P_PARENT_ERECORD_ID       => NULL
541                                ,X_STATUS                  => x_return_status);
542       IF x_return_status <> fnd_api.g_ret_sts_success THEN
543          RAISE ins_mtl_line_failure;
544       END IF;
545 
546       gme_common_pvt.count_and_get (x_count        => x_message_count
547                                    ,p_encoded      => fnd_api.g_false
548                                    ,x_data         => x_message_list);
549 
550       IF (g_debug IS NOT NULL) THEN
551          gme_debug.put_line (   'Completed '
552                              || l_api_name
553                              || ' at '
554                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
555       END IF;
556       IF (x_return_status IS NULL) THEN
557         x_return_status := fnd_api.g_ret_sts_success;
558       END IF;
559    EXCEPTION
560       WHEN   gmf_cost_failure THEN
561         -- Bug 5903208
562         x_return_status := FND_API.G_RET_STS_ERROR;
563 
564       WHEN ins_mtl_line_failure THEN
565          IF x_return_status NOT IN (gme_common_pvt.g_inv_short_err) THEN
566             ROLLBACK TO SAVEPOINT insert_material_line1;
567             x_material_detail_rec := NULL;
568          END IF;
569 
570          gme_common_pvt.count_and_get (x_count        => x_message_count
571                                       ,p_encoded      => fnd_api.g_false
572                                       ,x_data         => x_message_list);
573       WHEN setup_failure THEN
574          ROLLBACK TO SAVEPOINT insert_material_line1;
575          x_material_detail_rec := NULL;
576          gme_common_pvt.count_and_get (x_count        => x_message_count
577                                       ,p_encoded      => fnd_api.g_false
578                                       ,x_data         => x_message_list);
579          x_return_status := fnd_api.g_ret_sts_error;
580       WHEN OTHERS THEN
581          ROLLBACK TO SAVEPOINT insert_material_line1;
582          x_material_detail_rec := NULL;
583 
584          IF (g_debug <= gme_debug.g_log_unexpected) THEN
585             gme_debug.put_line (   g_pkg_name
586                                 || '.'
587                                 || l_api_name
588                                 || ':'
589                                 || 'When others exception:'
590                                 || SQLERRM);
591          END IF;
592 
593          gme_common_pvt.count_and_get (x_count        => x_message_count
594                                       ,p_encoded      => fnd_api.g_false
595                                       ,x_data         => x_message_list);
596          x_return_status := fnd_api.g_ret_sts_unexp_error;
597    END insert_material_line;
598 
599 /*************************************************************************/
600    PROCEDURE insert_material_line (
601       p_validation_level      IN              NUMBER
602             := gme_common_pvt.g_max_errors
603      ,p_init_msg_list         IN              VARCHAR2 := fnd_api.g_false
604      ,x_message_count         OUT NOCOPY      NUMBER
605      ,x_message_list          OUT NOCOPY      VARCHAR2
606      ,x_return_status         OUT NOCOPY      VARCHAR2
607      ,p_batch_header_rec      IN              gme_batch_header%ROWTYPE
608      ,p_material_detail_rec   IN              gme_material_details%ROWTYPE
609      ,p_batch_step_rec        IN              gme_batch_steps%ROWTYPE
610      ,p_trans_id              IN              NUMBER
611      ,x_transacted            OUT NOCOPY      VARCHAR2
612      ,x_material_detail_rec   OUT NOCOPY      gme_material_details%ROWTYPE)
613    IS
614       l_api_name    CONSTANT VARCHAR2 (30) := 'insert_material_line';
615       setup_failure          EXCEPTION;
616       ins_mtl_line_failure   EXCEPTION;
617    BEGIN
618 
619       /* Set the return status to success initially */
620       x_return_status := fnd_api.g_ret_sts_success;
621 
622       SAVEPOINT insert_material_line;
623 
624       IF (g_debug IS NOT NULL) THEN
628       IF g_debug <= gme_debug.g_log_procedure THEN
625          gme_debug.log_initialize ('InsertMaterialLine');
626       END IF;
627 
629          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
630                              || l_api_name);
631       END IF;
632 
633       IF NOT gme_common_pvt.g_setup_done THEN
634          gme_common_pvt.g_setup_done :=
635                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
636 
637          IF NOT gme_common_pvt.g_setup_done THEN
638             x_return_status := fnd_api.g_ret_sts_error;
639             RAISE setup_failure;
640          END IF;
641       END IF;
642 
643       -- Initialize message list and count if needed
644       IF p_init_msg_list = fnd_api.g_true THEN
645          fnd_msg_pub.initialize;
646          gme_common_pvt.g_error_count := 0;
647       END IF;
648 
649       gme_common_pvt.set_timestamp;
650 
651       gme_material_detail_pvt.insert_material_line
652                               (p_batch_header_rec         => p_batch_header_rec
653                               ,p_material_detail_rec      => p_material_detail_rec
654                               ,p_batch_step_rec           => p_batch_step_rec
655                               ,p_trans_id                 => p_trans_id
656                               ,x_transacted               => x_transacted
657                               ,x_material_detail_rec      => x_material_detail_rec
658                               ,x_return_status            => x_return_status);
659 
660       IF x_return_status <> fnd_api.g_ret_sts_success THEN
661          RAISE ins_mtl_line_failure;
662       END IF;            /* IF x_return_status <> FND_API.G_RET_STS_SUCCESS */
663 
664       gme_common_pvt.log_message ('GME_MTL_LINE_INSERTED');
665 
666 
667       gme_common_pvt.count_and_get (x_count        => x_message_count
668                                    ,p_encoded      => fnd_api.g_false
669                                    ,x_data         => x_message_list);
670 
671       IF (g_debug IS NOT NULL) THEN
672          gme_debug.put_line (   'Completed '
673                              || l_api_name
674                              || ' at '
675                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
676       END IF;
677       IF (x_return_status IS NULL) THEN
678         x_return_status := fnd_api.g_ret_sts_success;
679       END IF;
680    EXCEPTION
681       WHEN ins_mtl_line_failure THEN
682          IF x_return_status NOT IN (gme_common_pvt.g_inv_short_err) THEN
683             ROLLBACK TO SAVEPOINT insert_material_line;
684             x_material_detail_rec := NULL;
685          END IF;
686 
687          gme_common_pvt.count_and_get (x_count        => x_message_count
688                                       ,p_encoded      => fnd_api.g_false
689                                       ,x_data         => x_message_list);
690       WHEN setup_failure THEN
691          ROLLBACK TO SAVEPOINT insert_material_line;
692          x_material_detail_rec := NULL;
693          gme_common_pvt.count_and_get (x_count        => x_message_count
694                                       ,p_encoded      => fnd_api.g_false
695                                       ,x_data         => x_message_list);
696          x_return_status := fnd_api.g_ret_sts_error;
697       WHEN OTHERS THEN
698          ROLLBACK TO SAVEPOINT insert_material_line;
699          x_material_detail_rec := NULL;
700 
701          IF (g_debug <= gme_debug.g_log_unexpected) THEN
702             gme_debug.put_line (   g_pkg_name
703                                 || '.'
704                                 || l_api_name
705                                 || ':'
706                                 || 'When others exception:'
707                                 || SQLERRM);
708          END IF;
709 
710          gme_common_pvt.count_and_get (x_count        => x_message_count
711                                       ,p_encoded      => fnd_api.g_false
712                                       ,x_data         => x_message_list);
713          x_return_status := fnd_api.g_ret_sts_unexp_error;
714    END insert_material_line;
715 
716 /*************************************************************************/
717    PROCEDURE update_material_line (
718       p_validation_level             IN              NUMBER
719             := gme_common_pvt.g_max_errors
720      ,p_init_msg_list                IN              VARCHAR2
721             := fnd_api.g_false
722      ,x_message_count                OUT NOCOPY      NUMBER
723      ,x_message_list                 OUT NOCOPY      VARCHAR2
724      ,x_return_status                OUT NOCOPY      VARCHAR2
725      ,p_batch_header_rec             IN              gme_batch_header%ROWTYPE
726      ,p_material_detail_rec          IN              gme_material_details%ROWTYPE
727      ,p_batch_step_id                IN              NUMBER := NULL
728      ,p_scale_phantom                IN              VARCHAR2 := fnd_api.g_false
729      ,p_trans_id                     IN              NUMBER
730      ,x_transacted                   OUT NOCOPY      VARCHAR2
731      ,x_material_detail_rec          OUT NOCOPY      gme_material_details%ROWTYPE)
732    IS
733       l_api_name    CONSTANT VARCHAR2 (30) := 'update_material_line_form';
734 
735       l_stored_material_detail_rec   gme_material_details%ROWTYPE;
736       l_in_batch_step_rec            gme_batch_steps%ROWTYPE;
740    BEGIN
737       l_batch_step_rec               gme_batch_steps%ROWTYPE;
738       upd_mtl_line_failure   EXCEPTION;
739       setup_failure          EXCEPTION;
741 
742       /* Set the return status to success initially */
743       x_return_status := fnd_api.g_ret_sts_success;
744 
745       SAVEPOINT update_material_line1;
746 
747       IF (g_debug IS NOT NULL) THEN
748          gme_debug.log_initialize ('UpdateMaterialLineForm');
749       END IF;
750 
751       IF g_debug <= gme_debug.g_log_procedure THEN
752          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
753                              || l_api_name);
754       END IF;
755 
756       IF NOT gme_common_pvt.g_setup_done THEN
757          gme_common_pvt.g_setup_done :=
758                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
759 
760          IF NOT gme_common_pvt.g_setup_done THEN
761             x_return_status := fnd_api.g_ret_sts_error;
762             RAISE setup_failure;
763          END IF;
764       END IF;
765 
766       -- Initialize message list and count if needed
767       IF p_init_msg_list = fnd_api.g_true THEN
768          fnd_msg_pub.initialize;
769          gme_common_pvt.g_error_count := 0;
770       END IF;
771 
772       gme_common_pvt.set_timestamp;
773 
774       IF p_batch_step_id IS NOT NULL THEN
775         l_batch_step_rec.batchstep_id := p_batch_step_id;
776 
777         IF NOT gme_batch_steps_dbl.fetch_row(l_batch_step_rec, l_batch_step_rec) THEN
778            RAISE fnd_api.g_exc_error;
779         END IF;
780       END IF;
781 
782       l_stored_material_detail_rec.material_detail_id := p_material_detail_rec.material_detail_id;
783 
784       IF NOT gme_material_details_dbl.fetch_row
785                 (l_stored_material_detail_rec,l_stored_material_detail_rec) THEN
786          RAISE fnd_api.g_exc_error;
787       END IF;
788 
789       update_material_line
790                 (p_validation_level                => p_validation_level
791                 ,p_init_msg_list                   => p_init_msg_list
792                 ,x_message_count                   => x_message_count
793                 ,x_message_list                    => x_message_list
794                 ,x_return_status                   => x_return_status
795                 ,p_batch_header_rec                => p_batch_header_rec
796                 ,p_material_detail_rec             => p_material_detail_rec
797                 ,p_stored_material_detail_rec      => l_stored_material_detail_rec
798                 ,p_batch_step_rec                  => l_batch_step_rec
799                 ,p_scale_phantom                   => p_scale_phantom
800                 ,p_trans_id                        => p_trans_id
801                 ,x_transacted                      => x_transacted
802                 ,x_material_detail_rec             => x_material_detail_rec);
803 
804       IF x_return_status <> fnd_api.g_ret_sts_success THEN
805          RAISE upd_mtl_line_failure;
806       END IF;            /* IF x_return_status <> FND_API.G_RET_STS_SUCCESS */
807 
808       -- NEW
809       GME_ERES_PKG.INSERT_EVENT(P_EVENT_NAME              => gme_common_pvt.G_BATCHMTL_UPDATED
810                                ,P_EVENT_KEY               => p_material_detail_rec.batch_id||'-'||p_material_detail_rec.material_detail_id
811                                ,P_USER_KEY_LABEL          => FND_MESSAGE.GET_STRING('GME','GME_PSIG_BATCH_MATL_LABEL')
812                                ,P_USER_KEY_VALUE          => gme_common_pvt.g_organization_code ||
813                                                              '-'||p_batch_header_rec.batch_no||'-'|| p_material_detail_rec.Line_no
814                                                              ||'-'||GME_ERES_PKG.GET_ITEM_NUMBER(p_material_detail_rec.organization_id,p_material_detail_rec.inventory_item_id)
815                                ,P_POST_OP_API             => 'NONE'
816                                ,P_PARENT_EVENT            => NULL
817                                ,P_PARENT_EVENT_KEY        => NULL
818                                ,P_PARENT_ERECORD_ID       => NULL
819                                ,X_STATUS                  => x_return_status);
820 
821       IF x_return_status <> fnd_api.g_ret_sts_success THEN
822          RAISE upd_mtl_line_failure;
823       END IF;
824 
825       gme_common_pvt.count_and_get (x_count        => x_message_count
826                                    ,p_encoded      => fnd_api.g_false
827                                    ,x_data         => x_message_list);
828 
829       IF (g_debug IS NOT NULL) THEN
830          gme_debug.put_line (   'Completed '
831                              || l_api_name
832                              || ' at '
833                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
834       END IF;
835       IF (x_return_status IS NULL) THEN
836         x_return_status := fnd_api.g_ret_sts_success;
837       END IF;
838    EXCEPTION
839       WHEN upd_mtl_line_failure THEN
840          IF x_return_status NOT IN (gme_common_pvt.g_inv_short_err) THEN
841             ROLLBACK TO SAVEPOINT update_material_line1;
842             x_material_detail_rec := NULL;
843          END IF;
844 
845          gme_common_pvt.count_and_get (x_count        => x_message_count
846                                       ,p_encoded      => fnd_api.g_false
847                                       ,x_data         => x_message_list);
848       WHEN setup_failure THEN
852                                       ,p_encoded      => fnd_api.g_false
849          ROLLBACK TO SAVEPOINT update_material_line1;
850          x_material_detail_rec := NULL;
851          gme_common_pvt.count_and_get (x_count        => x_message_count
853                                       ,x_data         => x_message_list);
854          x_return_status := fnd_api.g_ret_sts_error;
855       WHEN OTHERS THEN
856          ROLLBACK TO SAVEPOINT update_material_line1;
857          x_material_detail_rec := NULL;
858 
859          IF (g_debug <= gme_debug.g_log_unexpected) THEN
860             gme_debug.put_line (   g_pkg_name
861                                 || '.'
862                                 || l_api_name
863                                 || ':'
864                                 || 'When others exception:'
865                                 || SQLERRM);
866          END IF;
867 
868          gme_common_pvt.count_and_get (x_count        => x_message_count
869                                       ,p_encoded      => fnd_api.g_false
870                                       ,x_data         => x_message_list);
871          x_return_status := fnd_api.g_ret_sts_unexp_error;
872    END update_material_line;
873 
874 /*************************************************************************/
875    PROCEDURE update_material_line (
876       p_validation_level             IN              NUMBER
877             := gme_common_pvt.g_max_errors
878      ,p_init_msg_list                IN              VARCHAR2
879             := fnd_api.g_false
880      ,x_message_count                OUT NOCOPY      NUMBER
881      ,x_message_list                 OUT NOCOPY      VARCHAR2
882      ,x_return_status                OUT NOCOPY      VARCHAR2
883      ,p_batch_header_rec             IN              gme_batch_header%ROWTYPE
884      ,p_material_detail_rec          IN              gme_material_details%ROWTYPE
885      ,p_stored_material_detail_rec   IN              gme_material_details%ROWTYPE
886      ,p_batch_step_rec               IN              gme_batch_steps%ROWTYPE
887      ,p_scale_phantom                IN              VARCHAR2
888             := fnd_api.g_false
889      ,p_trans_id                     IN              NUMBER
890      ,x_transacted                   OUT NOCOPY      VARCHAR2
891      ,x_material_detail_rec          OUT NOCOPY      gme_material_details%ROWTYPE)
892    IS
893       l_api_name    CONSTANT VARCHAR2 (30) := 'update_material_line';
894       upd_mtl_line_failure   EXCEPTION;
895       setup_failure          EXCEPTION;
896    BEGIN
897       SAVEPOINT update_material_line;
898 
899       IF (g_debug IS NOT NULL) THEN
900          gme_debug.log_initialize ('UpdateMaterialLine');
901       END IF;
902 
903       IF g_debug <= gme_debug.g_log_procedure THEN
904          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
905                              || l_api_name);
906       END IF;
907 
908       IF NOT gme_common_pvt.g_setup_done THEN
909          gme_common_pvt.g_setup_done :=
910                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
911 
912          IF NOT gme_common_pvt.g_setup_done THEN
913             x_return_status := fnd_api.g_ret_sts_error;
914             RAISE setup_failure;
915          END IF;
916       END IF;
917 
918       /* Set the return status to success initially */
919       x_return_status := fnd_api.g_ret_sts_success;
920 
921       -- Initialize message list and count if needed
922       IF p_init_msg_list = fnd_api.g_true THEN
923          fnd_msg_pub.initialize;
924          gme_common_pvt.g_error_count := 0;
925       END IF;
926 
927       gme_common_pvt.set_timestamp;
928       gme_material_detail_pvt.update_material_line
929                 (p_batch_header_rec                => p_batch_header_rec
930                 ,p_material_detail_rec             => p_material_detail_rec
931                 ,p_stored_material_detail_rec      => p_stored_material_detail_rec
932                 ,p_batch_step_rec                  => p_batch_step_rec
933                 ,p_scale_phantom                   => p_scale_phantom
934                 ,p_trans_id                        => p_trans_id
935                 ,x_transacted                      => x_transacted
936                 ,x_return_status                   => x_return_status
937                 ,x_material_detail_rec             => x_material_detail_rec);
938 
939       IF x_return_status <> fnd_api.g_ret_sts_success THEN
940          RAISE upd_mtl_line_failure;
941       END IF;            /* IF x_return_status <> FND_API.G_RET_STS_SUCCESS */
942 
943       gme_common_pvt.log_message ('GME_MTL_LINE_UPDATED');
944 
945 
946       gme_common_pvt.count_and_get (x_count        => x_message_count
947                                    ,p_encoded      => fnd_api.g_false
948                                    ,x_data         => x_message_list);
949 
950       IF (g_debug IS NOT NULL) THEN
951          gme_debug.put_line (   'Completed '
952                              || l_api_name
953                              || ' at '
954                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
955       END IF;
956       IF (x_return_status IS NULL) THEN
957         x_return_status := fnd_api.g_ret_sts_success;
958       END IF;
959    EXCEPTION
960       WHEN upd_mtl_line_failure THEN
961          IF x_return_status NOT IN (gme_common_pvt.g_inv_short_err) THEN
965 
962             ROLLBACK TO SAVEPOINT update_material_line;
963             x_material_detail_rec := NULL;
964          END IF;
966          gme_common_pvt.count_and_get (x_count        => x_message_count
967                                       ,p_encoded      => fnd_api.g_false
968                                       ,x_data         => x_message_list);
969       WHEN setup_failure THEN
970          ROLLBACK TO SAVEPOINT update_material_line;
971          x_material_detail_rec := NULL;
972          gme_common_pvt.count_and_get (x_count        => x_message_count
973                                       ,p_encoded      => fnd_api.g_false
974                                       ,x_data         => x_message_list);
975          x_return_status := fnd_api.g_ret_sts_error;
976       WHEN OTHERS THEN
977          ROLLBACK TO SAVEPOINT update_material_line;
978          x_material_detail_rec := NULL;
979 
980          IF (g_debug <= gme_debug.g_log_unexpected) THEN
981             gme_debug.put_line (   g_pkg_name
982                                 || '.'
983                                 || l_api_name
984                                 || ':'
985                                 || 'When others exception:'
986                                 || SQLERRM);
987          END IF;
988 
989          gme_common_pvt.count_and_get (x_count        => x_message_count
990                                       ,p_encoded      => fnd_api.g_false
991                                       ,x_data         => x_message_list);
992          x_return_status := fnd_api.g_ret_sts_unexp_error;
993    END update_material_line;
994 
995 /*************************************************************************/
996    PROCEDURE delete_material_line (
997       p_validation_level      IN              NUMBER
998             := gme_common_pvt.g_max_errors
999      ,p_init_msg_list         IN              VARCHAR2 := fnd_api.g_false
1000      ,x_message_count         OUT NOCOPY      NUMBER
1001      ,x_message_list          OUT NOCOPY      VARCHAR2
1002      ,x_return_status         OUT NOCOPY      VARCHAR2
1003      ,p_batch_header_rec      IN              gme_batch_header%ROWTYPE
1004      ,p_material_detail_rec   IN              gme_material_details%ROWTYPE
1005      ,p_batch_step_id         IN              NUMBER := NULL
1006      ,x_transacted            OUT NOCOPY      VARCHAR2)
1007    IS
1008       l_api_name    CONSTANT VARCHAR2 (30) := 'delete_material_line_form';
1009 
1010       l_batch_step_rec       gme_batch_steps%ROWTYPE;
1011 
1012       del_mtl_line_failure   EXCEPTION;
1013       setup_failure          EXCEPTION;
1014 
1015       -- Bug 5903208
1016       gmf_cost_failure         EXCEPTION;
1017       l_message_count		   NUMBER;
1018       l_message_list		   VARCHAR2(2000);
1019 
1020    BEGIN
1021 
1022       /* Set the return status to success initially */
1023       x_return_status := fnd_api.g_ret_sts_success;
1024 
1025       SAVEPOINT delete_material_line1;
1026 
1027       IF (g_debug IS NOT NULL) THEN
1028          gme_debug.log_initialize ('DeleteMaterialLineForm');
1029       END IF;
1030 
1031       IF g_debug <= gme_debug.g_log_procedure THEN
1032          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
1033                              || l_api_name);
1034       END IF;
1035 
1036       IF NOT gme_common_pvt.g_setup_done THEN
1037          gme_common_pvt.g_setup_done :=
1038                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
1039 
1040          IF NOT gme_common_pvt.g_setup_done THEN
1041             x_return_status := fnd_api.g_ret_sts_error;
1042             RAISE setup_failure;
1043          END IF;
1044       END IF;
1045 
1046       -- Initialize message list and count if needed
1047       IF p_init_msg_list = fnd_api.g_true THEN
1048          fnd_msg_pub.initialize;
1049          gme_common_pvt.g_error_count := 0;
1050       END IF;
1051 
1052       gme_common_pvt.set_timestamp;
1053 
1054       IF p_batch_step_id IS NOT NULL THEN
1055         l_batch_step_rec.batchstep_id := p_batch_step_id;
1056 
1057         IF NOT gme_batch_steps_dbl.fetch_row(l_batch_step_rec, l_batch_step_rec) THEN
1058            RAISE fnd_api.g_exc_error;
1059         END IF;
1060       END IF;
1061 
1062       delete_material_line (
1063           p_validation_level       => p_validation_level
1064          ,p_init_msg_list          => p_init_msg_list
1065          ,x_message_count          => x_message_count
1066          ,x_message_list           => x_message_list
1067          ,x_return_status          => x_return_status
1068          ,p_batch_header_rec       => p_batch_header_rec
1069          ,p_material_detail_rec    => p_material_detail_rec
1070          ,p_batch_step_rec         => l_batch_step_rec
1071          ,x_transacted             => x_transacted);
1072 
1073       IF x_return_status <> fnd_api.g_ret_sts_success THEN
1074          RAISE del_mtl_line_failure;
1075       END IF;            /* IF x_return_status <> FND_API.G_RET_STS_SUCCESS */
1076 
1077       --
1078       -- Bug 5903208 -- call to GMF
1079       --
1080       GMF_VIB.Update_Batch_Requirements
1081       ( p_api_version   =>    1.0,
1082         p_init_msg_list =>    FND_API.G_FALSE,
1083         p_batch_id      =>    p_batch_header_rec.batch_id,
1084         x_return_status =>    x_return_status,
1085         x_msg_count     =>    l_message_count,
1086         x_msg_data      =>    l_message_list);
1090       END IF;
1087       IF x_return_status <> FND_API.G_RET_STS_SUCCESS
1088       THEN
1089          RAISE gmf_cost_failure;
1091       -- End Bug 5903208
1092 
1093       -- NEW
1094       GME_ERES_PKG.INSERT_EVENT(P_EVENT_NAME              => gme_common_pvt.G_BATCHMTL_REMOVED
1095                                ,P_EVENT_KEY               => p_material_detail_rec.batch_id||'-'||p_material_detail_rec.material_detail_id
1096                                ,P_USER_KEY_LABEL          => FND_MESSAGE.GET_STRING('GME','GME_PSIG_BATCH_MATL_LABEL')
1097                                ,P_USER_KEY_VALUE          => gme_common_pvt.g_organization_code ||
1098                                                              '-'||p_batch_header_rec.batch_no||'-'|| p_material_detail_rec.Line_no
1099                                                              ||'-'||GME_ERES_PKG.GET_ITEM_NUMBER(p_material_detail_rec.organization_id,p_material_detail_rec.inventory_item_id)
1100                                ,P_POST_OP_API             => 'NONE'
1101                                ,P_PARENT_EVENT            => NULL
1102                                ,P_PARENT_EVENT_KEY        => NULL
1103                                ,P_PARENT_ERECORD_ID       => NULL
1104                                ,X_STATUS                  => x_return_status);
1105 
1106       IF x_return_status <> fnd_api.g_ret_sts_success THEN
1107          RAISE del_mtl_line_failure;
1108       END IF;
1109 
1110       gme_common_pvt.count_and_get (x_count        => x_message_count
1111                                    ,p_encoded      => fnd_api.g_false
1112                                    ,x_data         => x_message_list);
1113 
1114       IF (g_debug IS NOT NULL) THEN
1115          gme_debug.put_line (   'Completed '
1116                              || l_api_name
1117                              || ' at '
1118                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
1119       END IF;
1120       IF (x_return_status IS NULL) THEN
1121         x_return_status := fnd_api.g_ret_sts_success;
1122       END IF;
1123    EXCEPTION
1124       WHEN   gmf_cost_failure THEN
1125         -- Bug 5903208
1126         x_return_status := FND_API.G_RET_STS_ERROR;
1127 
1128       WHEN del_mtl_line_failure THEN
1129          IF x_return_status NOT IN (gme_common_pvt.g_inv_short_err) THEN
1130             ROLLBACK TO SAVEPOINT delete_material_line1;
1131          END IF;
1132 
1133          gme_common_pvt.count_and_get (x_count        => x_message_count
1134                                       ,p_encoded      => fnd_api.g_false
1135                                       ,x_data         => x_message_list);
1136       WHEN setup_failure THEN
1137          ROLLBACK TO SAVEPOINT delete_material_line1;
1138          gme_common_pvt.count_and_get (x_count        => x_message_count
1139                                       ,p_encoded      => fnd_api.g_false
1140                                       ,x_data         => x_message_list);
1141          x_return_status := fnd_api.g_ret_sts_error;
1142       WHEN OTHERS THEN
1143          ROLLBACK TO SAVEPOINT delete_material_line1;
1144 
1145          IF (g_debug <= gme_debug.g_log_unexpected) THEN
1146             gme_debug.put_line (   g_pkg_name
1147                                 || '.'
1148                                 || l_api_name
1149                                 || ':'
1150                                 || 'When others exception:'
1151                                 || SQLERRM);
1152          END IF;
1153 
1154          gme_common_pvt.count_and_get (x_count        => x_message_count
1155                                       ,p_encoded      => fnd_api.g_false
1156                                       ,x_data         => x_message_list);
1157          x_return_status := fnd_api.g_ret_sts_unexp_error;
1158    END delete_material_line;
1159 
1160 /*************************************************************************/
1161    PROCEDURE delete_material_line (
1162       p_validation_level      IN              NUMBER
1163             := gme_common_pvt.g_max_errors
1164      ,p_init_msg_list         IN              VARCHAR2 := fnd_api.g_false
1165      ,x_message_count         OUT NOCOPY      NUMBER
1166      ,x_message_list          OUT NOCOPY      VARCHAR2
1167      ,x_return_status         OUT NOCOPY      VARCHAR2
1168      ,p_batch_header_rec      IN              gme_batch_header%ROWTYPE
1169      ,p_material_detail_rec   IN              gme_material_details%ROWTYPE
1170      ,p_batch_step_rec        IN              gme_batch_steps%ROWTYPE
1171      ,x_transacted            OUT NOCOPY      VARCHAR2)
1172    IS
1173       l_api_name    CONSTANT VARCHAR2 (30) := 'delete_material_line';
1174       del_mtl_line_failure   EXCEPTION;
1175       setup_failure          EXCEPTION;
1176    BEGIN
1177 
1178       /* Set the return status to success initially */
1179       x_return_status := fnd_api.g_ret_sts_success;
1180 
1181       SAVEPOINT delete_material_line;
1182 
1183       IF (g_debug IS NOT NULL) THEN
1184          gme_debug.log_initialize ('DeleteMaterialLine');
1185       END IF;
1186 
1187       IF g_debug <= gme_debug.g_log_procedure THEN
1188          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
1189                              || l_api_name);
1190       END IF;
1191 
1192       IF NOT gme_common_pvt.g_setup_done THEN
1193          gme_common_pvt.g_setup_done :=
1194                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
1195 
1196          IF NOT gme_common_pvt.g_setup_done THEN
1197             x_return_status := fnd_api.g_ret_sts_error;
1201 
1198             RAISE setup_failure;
1199          END IF;
1200       END IF;
1202       -- Initialize message list and count if needed
1203       IF p_init_msg_list = fnd_api.g_true THEN
1204          fnd_msg_pub.initialize;
1205          gme_common_pvt.g_error_count := 0;
1206       END IF;
1207 
1208       gme_common_pvt.set_timestamp;
1209       gme_material_detail_pvt.delete_material_line
1210                               (p_batch_header_rec         => p_batch_header_rec
1211                               ,p_material_detail_rec      => p_material_detail_rec
1212                               ,p_batch_step_rec           => p_batch_step_rec
1213                               ,x_transacted               => x_transacted
1214                               ,x_return_status            => x_return_status);
1215 
1216       IF x_return_status <> fnd_api.g_ret_sts_success THEN
1217          RAISE del_mtl_line_failure;
1218       END IF;            /* IF x_return_status <> FND_API.G_RET_STS_SUCCESS */
1219 
1220       gme_common_pvt.log_message ('GME_MTL_LINE_DELETED');
1221 
1222       gme_common_pvt.count_and_get (x_count        => x_message_count
1223                                    ,p_encoded      => fnd_api.g_false
1224                                    ,x_data         => x_message_list);
1225 
1226       IF (g_debug IS NOT NULL) THEN
1227          gme_debug.put_line (   'Completed '
1228                              || l_api_name
1229                              || ' at '
1230                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
1231       END IF;
1232       IF (x_return_status IS NULL) THEN
1233         x_return_status := fnd_api.g_ret_sts_success;
1234       END IF;
1235    EXCEPTION
1236       WHEN del_mtl_line_failure THEN
1237          IF x_return_status NOT IN (gme_common_pvt.g_inv_short_err) THEN
1238             ROLLBACK TO SAVEPOINT delete_material_line;
1239          END IF;
1240 
1241          gme_common_pvt.count_and_get (x_count        => x_message_count
1242                                       ,p_encoded      => fnd_api.g_false
1243                                       ,x_data         => x_message_list);
1244       WHEN setup_failure THEN
1245          ROLLBACK TO SAVEPOINT delete_material_line;
1246          gme_common_pvt.count_and_get (x_count        => x_message_count
1247                                       ,p_encoded      => fnd_api.g_false
1248                                       ,x_data         => x_message_list);
1249          x_return_status := fnd_api.g_ret_sts_error;
1250       WHEN OTHERS THEN
1251          ROLLBACK TO SAVEPOINT delete_material_line;
1252 
1253          IF (g_debug <= gme_debug.g_log_unexpected) THEN
1254             gme_debug.put_line (   g_pkg_name
1255                                 || '.'
1256                                 || l_api_name
1257                                 || ':'
1258                                 || 'When others exception:'
1259                                 || SQLERRM);
1260          END IF;
1261 
1262          gme_common_pvt.count_and_get (x_count        => x_message_count
1263                                       ,p_encoded      => fnd_api.g_false
1264                                       ,x_data         => x_message_list);
1265          x_return_status := fnd_api.g_ret_sts_unexp_error;
1266    END delete_material_line;
1267 
1268 /*************************************************************************/
1269    PROCEDURE reschedule_batch (
1270       p_validation_level      IN              NUMBER
1271      ,p_init_msg_list         IN              VARCHAR2
1272      ,p_batch_header_rec      IN              gme_batch_header%ROWTYPE
1273      ,p_use_workday_cal       IN              VARCHAR2
1274      ,p_contiguity_override   IN              VARCHAR2
1275      ,x_message_count         OUT NOCOPY      NUMBER
1276      ,x_message_list          OUT NOCOPY      VARCHAR2
1277      ,x_return_status         OUT NOCOPY      VARCHAR2
1278      ,x_batch_header_rec      OUT NOCOPY      gme_batch_header%ROWTYPE)
1279    IS
1280       l_api_name       CONSTANT VARCHAR2 (30) := 'RESCHEDULE_BATCH';
1281       reschedule_batch_failed   EXCEPTION;
1282       setup_failure             EXCEPTION;
1283    BEGIN
1284       /* Set the savepoint before proceeding */
1285       SAVEPOINT reschedule_batch;
1286 
1287       IF (g_debug IS NOT NULL) THEN
1288          gme_debug.log_initialize ('RescheduleBatch');
1289       END IF;
1290 
1291       IF (NVL (g_debug, 0) IN
1292                        (gme_debug.g_log_statement, gme_debug.g_log_procedure) ) THEN
1293          gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
1294                              || 'Entering');
1295       END IF;
1296 
1297       IF NOT gme_common_pvt.g_setup_done THEN
1298          gme_common_pvt.g_setup_done :=
1299                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
1300 
1301          IF NOT gme_common_pvt.g_setup_done THEN
1302             x_return_status := fnd_api.g_ret_sts_error;
1303             RAISE setup_failure;
1304          END IF;
1305       END IF;
1306 
1307       /* Initialize message list and count if needed */
1308       IF p_init_msg_list = fnd_api.g_true THEN
1309          fnd_msg_pub.initialize;
1310          gme_common_pvt.g_error_count := 0;
1311       END IF;
1312 
1313       gme_common_pvt.set_timestamp;
1314 
1315       IF (NVL (g_debug, 0) = gme_debug.g_log_statement) THEN
1316          gme_debug.put_line (   g_pkg_name
1317                              || '.'
1321       END IF;
1318                              || l_api_name
1319                              || ':'
1320                              || 'Calling Pvt Reschedule Batch');
1322 
1323       gme_reschedule_batch_pvt.reschedule_batch
1324                               (p_batch_header_rec         => p_batch_header_rec
1325                               ,p_use_workday_cal          => p_use_workday_cal
1326                               ,p_contiguity_override      => p_contiguity_override
1327                               ,x_batch_header_rec         => x_batch_header_rec
1328                               ,x_return_status            => x_return_status);
1329 
1330       IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
1331          gme_debug.put_line
1332                        (   'Came back from Pvt Reschedule Batch with status '
1333                         || x_return_status);
1334       END IF;
1335       IF x_return_status NOT IN (fnd_api.g_ret_sts_success, 'C') THEN
1336          RAISE reschedule_batch_failed;
1337       END IF;
1338 
1339       gme_common_pvt.count_and_get (x_count        => x_message_count
1340                                    ,p_encoded      => fnd_api.g_false
1341                                    ,x_data         => x_message_list);
1342 
1343       IF g_debug <= gme_debug.g_log_procedure THEN
1344          gme_debug.put_line (   g_pkg_name
1345                              || '.'
1346                              || l_api_name
1347                              || ':'
1348                              || 'Exiting with '
1349                              || x_return_status
1350                              || ' at '
1351                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
1352       END IF;
1353    EXCEPTION
1354       WHEN setup_failure THEN
1355          ROLLBACK TO SAVEPOINT reschedule_batch;
1356          x_batch_header_rec := NULL;
1357          x_return_status := fnd_api.g_ret_sts_error;
1358          gme_common_pvt.count_and_get (x_count        => x_message_count
1359                                       ,p_encoded      => fnd_api.g_false
1360                                       ,x_data         => x_message_list);
1361       WHEN reschedule_batch_failed THEN
1362          ROLLBACK TO SAVEPOINT reschedule_batch;
1363          x_batch_header_rec := NULL;
1364          gme_common_pvt.count_and_get (x_count        => x_message_count
1365                                       ,p_encoded      => fnd_api.g_false
1366                                       ,x_data         => x_message_list);
1367       WHEN OTHERS THEN
1368          ROLLBACK TO SAVEPOINT reschedule_batch;
1369          x_batch_header_rec := NULL;
1370          fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
1371          gme_common_pvt.count_and_get (x_count        => x_message_count
1372                                       ,p_encoded      => fnd_api.g_false
1373                                       ,x_data         => x_message_list);
1374          x_return_status := fnd_api.g_ret_sts_unexp_error;
1375    END reschedule_batch;
1376 
1377 /*************************************************************************/
1378    PROCEDURE reschedule_step (
1379       p_validation_level        IN              NUMBER
1380      ,p_init_msg_list           IN              VARCHAR2
1381      ,p_batch_header_rec        IN              gme_batch_header%ROWTYPE
1382      ,p_batch_step_rec          IN              gme_batch_steps%ROWTYPE
1383      ,p_reschedule_preceding    IN              VARCHAR2
1384      ,p_reschedule_succeeding   IN              VARCHAR2
1385      ,p_use_workday_cal         IN              VARCHAR2
1386      ,p_contiguity_override     IN              VARCHAR2
1387      ,x_message_count           OUT NOCOPY      NUMBER
1388      ,x_message_list            OUT NOCOPY      VARCHAR2
1389      ,x_return_status           OUT NOCOPY      VARCHAR2
1390      ,x_batch_step_rec          OUT NOCOPY      gme_batch_steps%ROWTYPE)
1391    IS
1392       l_api_name      CONSTANT VARCHAR2 (30)             := 'RESCHEDULE_STEP';
1393       l_diff                   NUMBER                           := 0;
1394       l_diff_cmplt             NUMBER                           := 0;
1395       l_batch_step             gme_batch_steps%ROWTYPE;
1396       l_step_tbl               gme_reschedule_step_pvt.step_tab;
1397       setup_failure            EXCEPTION;
1398       reschedule_step_failed   EXCEPTION;
1399       expected_error           EXCEPTION;
1400    BEGIN
1401       /* Set the savepoint before proceeding */
1402       SAVEPOINT reschedule_batch_step;
1403 
1404       IF (g_debug IS NOT NULL) THEN
1405          gme_debug.log_initialize ('RescheduleStep');
1406       END IF;
1407 
1408       IF (NVL (g_debug, 0) IN
1409                        (gme_debug.g_log_statement, gme_debug.g_log_procedure) ) THEN
1410          gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
1411                              || 'Entering');
1412       END IF;
1413 
1414       IF NOT gme_common_pvt.g_setup_done THEN
1415          gme_common_pvt.g_setup_done :=
1416                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
1417 
1418          IF NOT gme_common_pvt.g_setup_done THEN
1419             x_return_status := fnd_api.g_ret_sts_error;
1420             RAISE setup_failure;
1421          END IF;
1422       END IF;
1423 
1424       /* Initialize message list and count if needed */
1425       IF p_init_msg_list = fnd_api.g_true THEN
1426          fnd_msg_pub.initialize;
1427          gme_common_pvt.g_error_count := 0;
1428       END IF;
1429 
1433          gme_debug.put_line (   g_pkg_name
1430       gme_common_pvt.set_timestamp;
1431 
1432       IF (NVL (g_debug, 0) = gme_debug.g_log_statement) THEN
1434                              || '.'
1435                              || l_api_name
1436                              || ':'
1437                              || 'Calling Pvt Reschedule Step');
1438       END IF;
1439 
1440       gme_reschedule_step_pvt.reschedule_step
1441                           (p_batch_step_rec             => p_batch_step_rec
1442                           ,p_source_step_id_tbl         => l_step_tbl
1443                           ,p_contiguity_override        => p_contiguity_override
1444                           ,p_reschedule_preceding       => p_reschedule_preceding
1445                           ,p_reschedule_succeeding      => p_reschedule_succeeding
1446                           ,p_use_workday_cal            => p_use_workday_cal
1447                           ,x_batch_step_rec             => x_batch_step_rec
1448                           ,x_return_status              => x_return_status);
1449 
1450       IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
1451          gme_debug.put_line
1452                         (   'Came back from Pvt Reschedule Step with status '
1453                          || x_return_status);
1454       END IF;
1455 
1456       IF x_return_status = fnd_api.g_ret_sts_success THEN
1457          -- OM-GME integration - call in private layer at the end
1458          -- need to retrieve batch header record here... it's already retrieved in pvt.
1459          NULL;
1460       ELSE
1461          RAISE reschedule_step_failed;
1462       END IF;
1463 
1464          gme_common_pvt.log_message ('GME_API_STEP_RESCH');
1465 
1466 
1467       gme_common_pvt.count_and_get (x_count        => x_message_count
1468                                    ,p_encoded      => fnd_api.g_false
1469                                    ,x_data         => x_message_list);
1470 
1471       IF g_debug <= gme_debug.g_log_procedure THEN
1472          gme_debug.put_line (   g_pkg_name
1473                              || '.'
1474                              || l_api_name
1475                              || ':'
1476                              || 'Exiting with '
1477                              || x_return_status
1478                              || ' at '
1479                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
1480       END IF;
1481    EXCEPTION
1482       WHEN reschedule_step_failed OR setup_failure THEN
1483          ROLLBACK TO SAVEPOINT reschedule_batch_step;
1484          x_batch_step_rec := NULL;
1485          gme_common_pvt.count_and_get (x_count        => x_message_count
1486                                       ,p_encoded      => fnd_api.g_false
1487                                       ,x_data         => x_message_list);
1488       WHEN expected_error THEN
1489          ROLLBACK TO SAVEPOINT reschedule_batch_step;
1490          x_batch_step_rec := NULL;
1491          x_return_status := fnd_api.g_ret_sts_error;
1492       WHEN OTHERS THEN
1493          ROLLBACK TO SAVEPOINT reschedule_batch_step;
1494          x_batch_step_rec := NULL;
1495          fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
1496          gme_common_pvt.count_and_get (x_count        => x_message_count
1497                                       ,p_encoded      => fnd_api.g_false
1498                                       ,x_data         => x_message_list);
1499          x_return_status := fnd_api.g_ret_sts_unexp_error;
1500    END reschedule_step;
1501 
1502 /*************************************************************************/
1503    PROCEDURE create_batch_reservations (
1504       p_init_msg_list      IN              VARCHAR2 := fnd_api.g_false
1505      ,p_batch_header_rec   IN              gme_batch_header%ROWTYPE
1506      ,x_message_count      OUT NOCOPY      NUMBER
1507      ,x_message_list       OUT NOCOPY      VARCHAR2
1508      ,x_return_status      OUT NOCOPY      VARCHAR2)
1509    IS
1510       l_api_name          CONSTANT VARCHAR2 (30)
1511                                                := 'CREATE_BATCH_RESERVATIONS';
1512       setup_failure                EXCEPTION;
1513       batch_reservations_failure   EXCEPTION;
1514    BEGIN
1515       IF g_debug <= gme_debug.g_log_procedure THEN
1516          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
1517                              || l_api_name);
1518       END IF;
1519 
1520       SAVEPOINT create_batch_reservations;
1521 
1522       IF (g_debug IS NOT NULL) THEN
1523          gme_debug.log_initialize ('CreateBatchReservations');
1524       END IF;
1525 
1526       IF NOT gme_common_pvt.g_setup_done THEN
1527          gme_common_pvt.g_setup_done :=
1528                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
1529 
1530          IF NOT gme_common_pvt.g_setup_done THEN
1531             RAISE setup_failure;
1532          END IF;
1533       END IF;
1534 
1535       /* Set the return status to success initially */
1536       x_return_status := fnd_api.g_ret_sts_success;
1537 
1538       -- Initialize message list and count if needed
1539       IF p_init_msg_list = fnd_api.g_true THEN
1540          fnd_msg_pub.initialize;
1541          gme_common_pvt.g_error_count := 0;
1542       END IF;
1543 
1544       gme_common_pvt.set_timestamp;
1545       gme_reservations_pvt.create_batch_reservations
1546                                    (p_batch_id           => p_batch_header_rec.batch_id
1550       IF x_return_status <> fnd_api.g_ret_sts_success THEN
1547                                    ,p_timefence          => 1000000
1548                                    ,x_return_status      => x_return_status);
1549 
1551          gme_common_pvt.log_message ('GME_BATCH_HL_RESERVATION_FAIL');
1552          RAISE batch_reservations_failure;
1553       END IF;
1554 
1555       gme_common_pvt.log_message ('GME_BATCH_HI_RESR_CREATED');
1556 
1557       IF (g_debug IS NOT NULL) THEN
1558          gme_debug.put_line (   'Completed '
1559                              || l_api_name
1560                              || ' at '
1561                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
1562       END IF;
1563 
1564       IF g_debug <= gme_debug.g_log_procedure THEN
1565          gme_debug.put_line ('Exiting api ' || g_pkg_name || '.' || l_api_name);
1566       END IF;
1567    EXCEPTION
1568       WHEN batch_reservations_failure THEN
1569          ROLLBACK TO SAVEPOINT create_batch_reservations;
1570          gme_common_pvt.count_and_get (x_count        => x_message_count
1571                                       ,p_encoded      => fnd_api.g_false
1572                                       ,x_data         => x_message_list);
1573       WHEN OTHERS THEN
1574          IF g_debug <= gme_debug.g_log_unexpected THEN
1575             gme_debug.put_line (   'When others exception in '
1576                                 || g_pkg_name
1577                                 || '.'
1578                                 || l_api_name
1579                                 || ' Error is '
1580                                 || SQLERRM);
1581          END IF;
1582 
1583          ROLLBACK TO SAVEPOINT create_batch_reservations;
1584          gme_common_pvt.count_and_get (x_count        => x_message_count
1585                                       ,p_encoded      => fnd_api.g_false
1586                                       ,x_data         => x_message_list);
1587          x_return_status := fnd_api.g_ret_sts_unexp_error;
1588    END create_batch_reservations;
1589 
1590    PROCEDURE create_line_reservations (
1591       p_init_msg_list   IN              VARCHAR2 := fnd_api.g_false
1592      ,p_matl_dtl_rec    IN              gme_material_details%ROWTYPE
1593      ,x_message_count   OUT NOCOPY      NUMBER
1594      ,x_message_list    OUT NOCOPY      VARCHAR2
1595      ,x_return_status   OUT NOCOPY      VARCHAR2)
1596    IS
1597       l_api_name        CONSTANT VARCHAR2 (30) := 'CREATE_LINE_RESERVATIONS';
1598       l_location_control_code    NUMBER;
1599       l_restrict_locators_code   NUMBER;
1600       l_open_qty                 NUMBER;
1601       /* Bug 5441643 Added NVL condition for location control code*/
1602       CURSOR cur_get_item (v_org_id NUMBER, v_inventory_item_id NUMBER)
1603       IS
1604          SELECT NVL(location_control_code,1) location_control_code, restrict_locators_code
1605            FROM mtl_system_items_kfv
1606           WHERE organization_id = v_org_id
1607             AND inventory_item_id = v_inventory_item_id;
1608 
1609       setup_failure              EXCEPTION;
1610       get_open_qty_failure       EXCEPTION;
1611       line_reservation_failure   EXCEPTION;
1612    BEGIN
1613       IF g_debug <= gme_debug.g_log_procedure THEN
1614          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
1615                              || l_api_name);
1616       END IF;
1617 
1618       SAVEPOINT create_line_reservations;
1619 
1620       IF (g_debug IS NOT NULL) THEN
1621          gme_debug.log_initialize ('CreateLineReservations');
1622       END IF;
1623 
1624       IF NOT gme_common_pvt.g_setup_done THEN
1625          gme_common_pvt.g_setup_done :=
1626                         gme_common_pvt.setup (p_matl_dtl_rec.organization_id);
1627 
1628          IF NOT gme_common_pvt.g_setup_done THEN
1629             RAISE setup_failure;
1630          END IF;
1631       END IF;
1632 
1633       /* Set the return status to success initially */
1634       x_return_status := fnd_api.g_ret_sts_success;
1635 
1636       -- Initialize message list and count if needed
1637       IF p_init_msg_list = fnd_api.g_true THEN
1638          fnd_msg_pub.initialize;
1639          gme_common_pvt.g_error_count := 0;
1640       END IF;
1641 
1642       gme_common_pvt.set_timestamp;
1643 
1644       OPEN cur_get_item (p_matl_dtl_rec.organization_id
1645                         ,p_matl_dtl_rec.inventory_item_id);
1646 
1647       FETCH cur_get_item
1648        INTO l_location_control_code, l_restrict_locators_code;
1649 
1650       CLOSE cur_get_item;
1651 
1652       -- Use Suggestions mode (S) in the called by param to assess the total
1653       -- unreserved quantity
1654       /* Bug 5441643 Added NVL condition for location control code*/
1655       gme_common_pvt.get_open_qty
1656                         (p_mtl_dtl_rec                 => p_matl_dtl_rec
1657                         ,p_called_by                   => 'S'
1658                         ,p_item_location_control       => NVL(l_location_control_code,1)
1659                         ,p_item_restrict_locators      => l_restrict_locators_code
1660                         ,x_open_qty                    => l_open_qty
1661                         ,x_return_status               => x_return_status);
1662 
1663       IF (g_debug <= gme_debug.g_log_statement) THEN
1664          gme_debug.put_line (   g_pkg_name
1665                              || '.'
1666                              || l_api_name
1670                              || 'get_open_qty returns open_qty: '
1667                              || ':'
1668                              || 'get_open_qty returns status: '
1669                              || x_return_status
1671                              || l_open_qty);
1672       END IF;
1673 
1674       IF x_return_status <> fnd_api.g_ret_sts_success THEN
1675          RAISE get_open_qty_failure;
1676       END IF;
1677 
1678       /* Create a high level reservation (at organization level) for the outstanding qty */
1679       gme_reservations_pvt.create_material_reservation
1680                                            (p_matl_dtl_rec       => p_matl_dtl_rec
1681                                            ,p_resv_qty           => l_open_qty
1682                                            ,x_return_status      => x_return_status);
1683 
1684       IF (g_debug <= gme_debug.g_log_statement) THEN
1685          gme_debug.put_line (   g_pkg_name
1686                              || '.'
1687                              || l_api_name
1688                              || ':'
1689                              || 'create_material_reservations returns status: '
1690                              || x_return_status);
1691       END IF;
1692 
1693       IF x_return_status <> fnd_api.g_ret_sts_success THEN
1694          gme_common_pvt.log_message ('GME_LINE_HL_RESERVATION_FAIL');
1695          RAISE line_reservation_failure;
1696       END IF;
1697 
1698       gme_common_pvt.log_message ('GME_LINE_HI_RESR_CREATED');
1699       IF (g_debug IS NOT NULL) THEN
1700          gme_debug.put_line (   'Completed '
1701                              || l_api_name
1702                              || ' at '
1703                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
1704       END IF;
1705 
1706       IF g_debug <= gme_debug.g_log_procedure THEN
1707          gme_debug.put_line ('Exiting api ' || g_pkg_name || '.' || l_api_name);
1708       END IF;
1709    EXCEPTION
1710       WHEN setup_failure OR get_open_qty_failure OR line_reservation_failure THEN
1711          ROLLBACK TO SAVEPOINT create_line_reservations;
1712          gme_common_pvt.count_and_get (x_count        => x_message_count
1713                                       ,p_encoded      => fnd_api.g_false
1714                                       ,x_data         => x_message_list);
1715          x_return_status := fnd_api.g_ret_sts_error;
1716       WHEN OTHERS THEN
1717          IF g_debug <= gme_debug.g_log_unexpected THEN
1718             gme_debug.put_line (   'When others exception in '
1719                                 || g_pkg_name
1720                                 || '.'
1721                                 || l_api_name
1722                                 || ' Error is '
1723                                 || SQLERRM);
1724          END IF;
1725 
1726          ROLLBACK TO SAVEPOINT create_line_reservations;
1727          gme_common_pvt.count_and_get (x_count        => x_message_count
1728                                       ,p_encoded      => fnd_api.g_false
1729                                       ,x_data         => x_message_list);
1730          x_return_status := fnd_api.g_ret_sts_unexp_error;
1731    END create_line_reservations;
1732 
1733 /*************************************************************************/
1734    PROCEDURE release_batch (
1735       p_validation_level         IN              NUMBER
1736             := gme_common_pvt.g_max_errors
1737      ,p_init_msg_list            IN              VARCHAR2 := fnd_api.g_false
1738      ,x_message_count            OUT NOCOPY      NUMBER
1739      ,x_message_list             OUT NOCOPY      VARCHAR2
1740      ,x_return_status            OUT NOCOPY      VARCHAR2
1741      ,p_batch_header_rec         IN              gme_batch_header%ROWTYPE
1742      ,x_batch_header_rec         OUT NOCOPY      gme_batch_header%ROWTYPE
1743      ,x_exception_material_tbl   OUT NOCOPY      gme_common_pvt.exceptions_tab
1744      ,p_ignore_exception         IN              VARCHAR2 := NULL) --Bug#5186328
1745    IS
1746       l_api_name     CONSTANT VARCHAR2 (30) := 'RELEASE_BATCH';
1747       setup_failure           EXCEPTION;
1748       batch_release_failure   EXCEPTION;
1749       batch_release_exception  EXCEPTION;
1750    BEGIN
1751       IF g_debug <= gme_debug.g_log_procedure THEN
1752          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
1753                              || l_api_name);
1754       END IF;
1755 
1756       SAVEPOINT release_batch;
1757 
1758       IF (g_debug IS NOT NULL) THEN
1759          gme_debug.log_initialize ('ReleaseBatch');
1760       END IF;
1761 
1762       IF NOT gme_common_pvt.g_setup_done THEN
1763          gme_common_pvt.g_setup_done :=
1764                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
1765 
1766          IF NOT gme_common_pvt.g_setup_done THEN
1767             x_return_status := fnd_api.g_ret_sts_error;
1768             RAISE setup_failure;
1769          END IF;
1770       END IF;
1771 
1772       /* Set the return status to success initially */
1773       x_return_status := fnd_api.g_ret_sts_success;
1774 
1775       -- Initialize message list and count if needed
1776       IF p_init_msg_list = fnd_api.g_true THEN
1777          fnd_msg_pub.initialize;
1778          gme_common_pvt.g_error_count := 0;
1779       END IF;
1780 
1781       gme_common_pvt.set_timestamp;
1782       gme_release_batch_pvt.release_batch
1783                          (p_batch_header_rec            => p_batch_header_rec
1787                          ,x_exception_material_tbl      => x_exception_material_tbl);
1784                          ,p_phantom_product_id          => NULL
1785                          ,x_batch_header_rec            => x_batch_header_rec
1786                          ,x_return_status               => x_return_status
1788 
1789       IF x_return_status NOT IN (fnd_api.g_ret_sts_success, gme_common_pvt.g_exceptions_err) THEN
1790          RAISE batch_release_failure;
1791       END IF;            /* IF x_return_status NOT IN */
1792 
1793       /*Bug#5186328 rework if return status is X then log message saying batch has exceptions*/
1794       IF NVL(p_ignore_exception,fnd_api.g_false) = fnd_api.g_false AND
1795          x_return_status = gme_common_pvt.g_exceptions_err THEN
1796          gme_common_pvt.log_message('GME_MATERIAL_EXCEPTIONS');
1797       ELSE
1798        gme_common_pvt.log_message ('GME_API_BATCH_RELEASED');
1799       END IF;
1800 
1801 
1802       gme_common_pvt.count_and_get (x_count        => x_message_count
1803                                    ,p_encoded      => fnd_api.g_false
1804                                    ,x_data         => x_message_list);
1805 
1806       IF (g_debug IS NOT NULL) THEN
1807          gme_debug.put_line (   'Completed '
1808                              || l_api_name
1809                              || ' at '
1810                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
1811       END IF;
1812 
1813       IF g_debug <= gme_debug.g_log_procedure THEN
1814          gme_debug.put_line ('Exiting api ' || g_pkg_name || '.' || l_api_name);
1815       END IF;
1816    EXCEPTION
1817       WHEN batch_release_failure THEN
1818          ROLLBACK TO SAVEPOINT release_batch;
1819          x_batch_header_rec := NULL;
1820          gme_common_pvt.count_and_get (x_count        => x_message_count
1821                                       ,p_encoded      => fnd_api.g_false
1822                                       ,x_data         => x_message_list);
1823       WHEN setup_failure THEN
1824          ROLLBACK TO SAVEPOINT release_batch;
1825          x_batch_header_rec := NULL;
1826          gme_common_pvt.count_and_get (x_count        => x_message_count
1827                                       ,p_encoded      => fnd_api.g_false
1828                                       ,x_data         => x_message_list);
1829          x_return_status := fnd_api.g_ret_sts_error;
1830       WHEN OTHERS THEN
1831          IF g_debug <= gme_debug.g_log_unexpected THEN
1832             gme_debug.put_line (   'When others exception in '
1833                                 || g_pkg_name
1834                                 || '.'
1835                                 || l_api_name
1836                                 || ' Error is '
1837                                 || SQLERRM);
1838          END IF;
1839 
1840          ROLLBACK TO SAVEPOINT release_batch;
1841          x_batch_header_rec := NULL;
1842          gme_common_pvt.count_and_get (x_count        => x_message_count
1843                                       ,p_encoded      => fnd_api.g_false
1844                                       ,x_data         => x_message_list);
1845          x_return_status := fnd_api.g_ret_sts_unexp_error;
1846    END release_batch;
1847 
1848 /*************************************************************************/
1849    PROCEDURE release_step (
1850       p_validation_level         IN              NUMBER
1851             := gme_common_pvt.g_max_errors
1852      ,p_init_msg_list            IN              VARCHAR2 := fnd_api.g_false
1853      ,x_message_count            OUT NOCOPY      NUMBER
1854      ,x_message_list             OUT NOCOPY      VARCHAR2
1855      ,x_return_status            OUT NOCOPY      VARCHAR2
1856      ,p_batch_step_rec           IN              gme_batch_steps%ROWTYPE
1857      ,p_batch_header_rec         IN              gme_batch_header%ROWTYPE
1858      ,x_batch_step_rec           OUT NOCOPY      gme_batch_steps%ROWTYPE
1859      ,x_exception_material_tbl   OUT NOCOPY      gme_common_pvt.exceptions_tab
1860      ,p_ignore_exception         IN              VARCHAR2 := NULL) --Bug#5186328
1861    IS
1862       l_api_name    CONSTANT VARCHAR2 (30) := 'RELEASE_STEP';
1863       setup_failure          EXCEPTION;
1864       step_release_failure   EXCEPTION;
1865       step_release_exception EXCEPTION;
1866    BEGIN
1867       IF g_debug <= gme_debug.g_log_procedure THEN
1868          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
1869                              || l_api_name);
1870       END IF;
1871 
1872       SAVEPOINT release_step;
1873 
1874       IF (g_debug IS NOT NULL) THEN
1875          gme_debug.log_initialize ('ReleaseStep');
1876       END IF;
1877 
1878       IF NOT gme_common_pvt.g_setup_done THEN
1879          gme_common_pvt.g_setup_done :=
1880                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
1881 
1882          IF NOT gme_common_pvt.g_setup_done THEN
1883             x_return_status := fnd_api.g_ret_sts_error;
1884             RAISE setup_failure;
1885          END IF;
1886       END IF;
1887 
1888       /* Set the return status to success initially */
1889       x_return_status := fnd_api.g_ret_sts_success;
1890 
1891       -- Initialize message list and count if needed
1892       IF p_init_msg_list = fnd_api.g_true THEN
1893          fnd_msg_pub.initialize;
1894          gme_common_pvt.g_error_count := 0;
1895       END IF;
1896 
1897       gme_common_pvt.set_timestamp;
1898       gme_release_batch_step_pvt.release_step
1902                         ,x_exception_material_tbl      => x_exception_material_tbl
1899                         (p_batch_step_rec              => p_batch_step_rec
1900                         ,p_batch_header_rec            => p_batch_header_rec
1901                         ,x_batch_step_rec              => x_batch_step_rec
1903                         ,x_return_status               => x_return_status);
1904 
1905       IF x_return_status NOT IN (fnd_api.g_ret_sts_success, gme_common_pvt.g_exceptions_err) THEN
1906          RAISE step_release_failure;
1907       END IF;            /* IF x_return_status NOT IN */
1908 
1909       /*Bug#5186328 rework if return status is X then log message saying batch has exceptions*/
1910       IF NVL(p_ignore_exception,fnd_api.g_false) = fnd_api.g_false AND
1911          x_return_status = gme_common_pvt.g_exceptions_err THEN
1912          gme_common_pvt.log_message('GME_MATERIAL_EXCEPTIONS');
1913       ELSE
1914          gme_common_pvt.log_message ('GME_API_STEP_RELEASED');
1915       END IF;
1916 
1917 
1918       gme_common_pvt.count_and_get (x_count        => x_message_count
1919                                    ,p_encoded      => fnd_api.g_false
1920                                    ,x_data         => x_message_list);
1921 
1922       IF (g_debug IS NOT NULL) THEN
1923          gme_debug.put_line (   'Completed '
1924                              || l_api_name
1925                              || ' at '
1926                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
1927       END IF;
1928 
1929       IF g_debug <= gme_debug.g_log_procedure THEN
1930          gme_debug.put_line ('Exiting api ' || g_pkg_name || '.' || l_api_name);
1931       END IF;
1932    EXCEPTION
1933       WHEN step_release_failure THEN
1934          ROLLBACK TO SAVEPOINT release_step;
1935          x_batch_step_rec := NULL;
1936          gme_common_pvt.count_and_get (x_count        => x_message_count
1937                                       ,p_encoded      => fnd_api.g_false
1938                                       ,x_data         => x_message_list);
1939       WHEN setup_failure THEN
1940          ROLLBACK TO SAVEPOINT release_step;
1941          x_batch_step_rec := NULL;
1942          gme_common_pvt.count_and_get (x_count        => x_message_count
1943                                       ,p_encoded      => fnd_api.g_false
1944                                       ,x_data         => x_message_list);
1945          x_return_status := fnd_api.g_ret_sts_error;
1946       WHEN OTHERS THEN
1947          IF g_debug <= gme_debug.g_log_unexpected THEN
1948             gme_debug.put_line (   'When others exception in '
1949                                 || g_pkg_name
1950                                 || '.'
1951                                 || l_api_name
1952                                 || ' Error is '
1953                                 || SQLERRM);
1954          END IF;
1955 
1956          ROLLBACK TO SAVEPOINT release_step;
1957          x_batch_step_rec := NULL;
1958          gme_common_pvt.count_and_get (x_count        => x_message_count
1959                                       ,p_encoded      => fnd_api.g_false
1960                                       ,x_data         => x_message_list);
1961          x_return_status := fnd_api.g_ret_sts_unexp_error;
1962    END release_step;
1963 
1964 /*************************************************************************/
1965    PROCEDURE complete_batch (
1966       p_validation_level         IN              NUMBER
1967             := gme_common_pvt.g_max_errors
1968      ,p_init_msg_list            IN              VARCHAR2 := fnd_api.g_false
1969      ,x_message_count            OUT NOCOPY      NUMBER
1970      ,x_message_list             OUT NOCOPY      VARCHAR2
1971      ,x_return_status            OUT NOCOPY      VARCHAR2
1972      ,p_batch_header_rec         IN              gme_batch_header%ROWTYPE
1973      ,x_batch_header_rec         OUT NOCOPY      gme_batch_header%ROWTYPE
1974      ,x_exception_material_tbl   OUT NOCOPY      gme_common_pvt.exceptions_tab
1975      ,p_ignore_exception         IN              VARCHAR2 := NULL) --Bug#5186328
1976    IS
1977       l_api_name      CONSTANT VARCHAR2 (30) := 'COMPLETE_BATCH';
1978       setup_failure            EXCEPTION;
1979       batch_complete_failure   EXCEPTION;
1980       batch_complete_exception EXCEPTION;
1981    BEGIN
1982       IF g_debug <= gme_debug.g_log_procedure THEN
1983          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
1984                              || l_api_name);
1985       END IF;
1986 
1987       SAVEPOINT complete_batch;
1988 
1989       IF (g_debug IS NOT NULL) THEN
1990          gme_debug.log_initialize ('CompleteBatch');
1991       END IF;
1992 
1993       IF NOT gme_common_pvt.g_setup_done THEN
1994          gme_common_pvt.g_setup_done :=
1995                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
1996 
1997          IF NOT gme_common_pvt.g_setup_done THEN
1998             x_return_status := fnd_api.g_ret_sts_error;
1999             RAISE setup_failure;
2000          END IF;
2001       END IF;
2002 
2003       /* Set the return status to success initially */
2004       x_return_status := fnd_api.g_ret_sts_success;
2005 
2006       -- Initialize message list and count if needed
2007       IF p_init_msg_list = fnd_api.g_true THEN
2008          fnd_msg_pub.initialize;
2009          gme_common_pvt.g_error_count := 0;
2010       END IF;
2011 
2012       gme_common_pvt.set_timestamp;
2013       gme_complete_batch_pvt.complete_batch
2017                         ,x_return_status               => x_return_status);
2014                         (p_batch_header_rec            => p_batch_header_rec
2015                         ,x_exception_material_tbl      => x_exception_material_tbl
2016                         ,x_batch_header_rec            => x_batch_header_rec
2018 
2019       IF x_return_status NOT IN(fnd_api.g_ret_sts_success, gme_common_pvt.g_exceptions_err) THEN
2020          RAISE batch_complete_failure;
2021       END IF;            /* IF x_return_status NOT IN */
2022 
2023       /*Bug#5186328 rework if return status is X then log message saying batch has exceptions*/
2024       IF NVL(p_ignore_exception,fnd_api.g_false) = fnd_api.g_false AND
2025          x_return_status = gme_common_pvt.g_exceptions_err THEN
2026          gme_common_pvt.log_message('GME_MATERIAL_EXCEPTIONS');
2027       ELSE
2028          gme_common_pvt.log_message ('GME_API_BATCH_COMPLETED');
2029       END IF;
2030 
2031       gme_common_pvt.count_and_get (x_count        => x_message_count
2032                                    ,p_encoded      => fnd_api.g_false
2033                                    ,x_data         => x_message_list);
2034 
2035       IF (g_debug IS NOT NULL) THEN
2036          gme_debug.put_line (   'Completed '
2037                              || l_api_name
2038                              || ' at '
2039                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
2040       END IF;
2041 
2042       IF g_debug <= gme_debug.g_log_procedure THEN
2043          gme_debug.put_line ('Exiting api ' || g_pkg_name || '.' || l_api_name);
2044       END IF;
2045    EXCEPTION
2046       WHEN batch_complete_failure THEN
2047          ROLLBACK TO SAVEPOINT complete_batch;
2048          x_batch_header_rec := NULL;
2049          gme_common_pvt.count_and_get (x_count        => x_message_count
2050                                       ,p_encoded      => fnd_api.g_false
2051                                       ,x_data         => x_message_list);
2052       WHEN setup_failure THEN
2053          ROLLBACK TO SAVEPOINT complete_batch;
2054          x_batch_header_rec := NULL;
2055          gme_common_pvt.count_and_get (x_count        => x_message_count
2056                                       ,p_encoded      => fnd_api.g_false
2057                                       ,x_data         => x_message_list);
2058          x_return_status := fnd_api.g_ret_sts_error;
2059       WHEN OTHERS THEN
2060          IF g_debug <= gme_debug.g_log_unexpected THEN
2061             gme_debug.put_line (   'When others exception in '
2062                                 || g_pkg_name
2063                                 || '.'
2064                                 || l_api_name
2065                                 || ' Error is '
2066                                 || SQLERRM);
2067          END IF;
2068 
2069          ROLLBACK TO SAVEPOINT complete_batch;
2070          x_batch_header_rec := NULL;
2071          gme_common_pvt.count_and_get (x_count        => x_message_count
2072                                       ,p_encoded      => fnd_api.g_false
2073                                       ,x_data         => x_message_list);
2074          x_return_status := fnd_api.g_ret_sts_unexp_error;
2075    END complete_batch;
2076 
2077 /*************************************************************************/
2078    PROCEDURE complete_step (
2079       p_validation_level         IN              NUMBER
2080             := gme_common_pvt.g_max_errors
2081      ,p_init_msg_list            IN              VARCHAR2 := fnd_api.g_false
2082      ,x_message_count            OUT NOCOPY      NUMBER
2083      ,x_message_list             OUT NOCOPY      VARCHAR2
2084      ,x_return_status            OUT NOCOPY      VARCHAR2
2085      ,p_batch_step_rec           IN              gme_batch_steps%ROWTYPE
2086      ,p_batch_header_rec         IN              gme_batch_header%ROWTYPE
2087      ,x_batch_step_rec           OUT NOCOPY      gme_batch_steps%ROWTYPE
2088      ,x_exception_material_tbl   OUT NOCOPY      gme_common_pvt.exceptions_tab
2089      ,p_ignore_exception         IN              VARCHAR2 := NULL)  --Bug#5186328
2090    IS
2091       l_api_name     CONSTANT VARCHAR2 (30) := 'COMPLETE_STEP';
2092       setup_failure           EXCEPTION;
2093       step_complete_failure   EXCEPTION;
2094       step_complete_exception EXCEPTION;
2095    BEGIN
2096       IF g_debug <= gme_debug.g_log_procedure THEN
2097          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
2098                              || l_api_name);
2099       END IF;
2100 
2101       SAVEPOINT complete_step;
2102 
2103       IF (g_debug IS NOT NULL) THEN
2104          gme_debug.log_initialize ('CompleteStep');
2105       END IF;
2106 
2107       IF NOT gme_common_pvt.g_setup_done THEN
2108          gme_common_pvt.g_setup_done :=
2109                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
2110 
2111          IF NOT gme_common_pvt.g_setup_done THEN
2112             x_return_status := fnd_api.g_ret_sts_error;
2113             RAISE setup_failure;
2114          END IF;
2115       END IF;
2116 
2117       /* Set the return status to success initially */
2118       x_return_status := fnd_api.g_ret_sts_success;
2119 
2120       -- Initialize message list and count if needed
2121       IF p_init_msg_list = fnd_api.g_true THEN
2122          fnd_msg_pub.initialize;
2123          gme_common_pvt.g_error_count := 0;
2124       END IF;
2125 
2126       gme_common_pvt.set_timestamp;
2127       gme_complete_batch_step_pvt.complete_step
2131                         ,x_exception_material_tbl      => x_exception_material_tbl
2128                         (p_batch_step_rec              => p_batch_step_rec
2129                         ,p_batch_header_rec            => p_batch_header_rec
2130                         ,x_batch_step_rec              => x_batch_step_rec
2132                         ,x_return_status               => x_return_status);
2133 
2134       IF x_return_status NOT IN (fnd_api.g_ret_sts_success, gme_common_pvt.g_exceptions_err) THEN
2135          RAISE step_complete_failure;
2136       END IF;            /* IF x_return_status NOT IN */
2137 
2138 
2139       /*Bug#5186328 rework if return status is X then log message saying batch has exceptions*/
2140       IF NVL(p_ignore_exception,fnd_api.g_false) = fnd_api.g_false AND
2141          x_return_status = gme_common_pvt.g_exceptions_err THEN
2142          gme_common_pvt.log_message('GME_MATERIAL_EXCEPTIONS');
2143       ELSE
2144          gme_common_pvt.log_message ('GME_API_STEP_COMPLETED');
2145       END IF;
2146 
2147       gme_common_pvt.count_and_get (x_count        => x_message_count
2148                                    ,p_encoded      => fnd_api.g_false
2149                                    ,x_data         => x_message_list);
2150 
2151       IF (g_debug IS NOT NULL) THEN
2152          gme_debug.put_line (   'Completed '
2153                              || l_api_name
2154                              || ' at '
2155                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
2156       END IF;
2157 
2158       IF g_debug <= gme_debug.g_log_procedure THEN
2159          gme_debug.put_line ('Exiting api ' || g_pkg_name || '.' || l_api_name);
2160       END IF;
2161    EXCEPTION
2162       WHEN step_complete_failure THEN
2163          ROLLBACK TO SAVEPOINT complete_step;
2164          x_batch_step_rec := NULL;
2165          gme_common_pvt.count_and_get (x_count        => x_message_count
2166                                       ,p_encoded      => fnd_api.g_false
2167                                       ,x_data         => x_message_list);
2168       WHEN setup_failure THEN
2169          ROLLBACK TO SAVEPOINT complete_step;
2170          x_batch_step_rec := NULL;
2171          gme_common_pvt.count_and_get (x_count        => x_message_count
2172                                       ,p_encoded      => fnd_api.g_false
2173                                       ,x_data         => x_message_list);
2174          x_return_status := fnd_api.g_ret_sts_error;
2175       WHEN OTHERS THEN
2176          IF g_debug <= gme_debug.g_log_unexpected THEN
2177             gme_debug.put_line (   'When others exception in '
2178                                 || g_pkg_name
2179                                 || '.'
2180                                 || l_api_name
2181                                 || ' Error is '
2182                                 || SQLERRM);
2183          END IF;
2184 
2185          ROLLBACK TO SAVEPOINT complete_step;
2186          x_batch_step_rec := NULL;
2187          gme_common_pvt.count_and_get (x_count        => x_message_count
2188                                       ,p_encoded      => fnd_api.g_false
2189                                       ,x_data         => x_message_list);
2190          x_return_status := fnd_api.g_ret_sts_unexp_error;
2191    END complete_step;
2192 
2193 /*************************************************************************/
2194    PROCEDURE delete_step (
2195       p_validation_level   IN              NUMBER
2196             := gme_common_pvt.g_max_errors
2197      ,p_init_msg_list      IN              VARCHAR2 := fnd_api.g_false
2198      ,x_message_count      OUT NOCOPY      NUMBER
2199      ,x_message_list       OUT NOCOPY      VARCHAR2
2200      ,x_return_status      OUT NOCOPY      VARCHAR2
2201      ,p_batch_step_rec     IN              gme_batch_steps%ROWTYPE
2202      ,p_batch_header_rec   IN              gme_batch_header%ROWTYPE)
2203    IS
2204       l_api_name   CONSTANT VARCHAR2 (30) := 'DELETE_STEP';
2205       delete_step_failed    EXCEPTION;
2206       batch_save_failed     EXCEPTION;
2207       setup_failure         EXCEPTION;
2208    BEGIN
2209       /* Set the savepoint before proceeding */
2210       SAVEPOINT delete_step;
2211 
2212       /* Setup the common constants used accross the apis */
2213       IF (g_debug IS NOT NULL) THEN
2214          gme_debug.log_initialize ('DeleteStep');
2215       END IF;
2216 
2217       IF g_debug <= gme_debug.g_log_procedure THEN
2218          gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
2219                              || 'Entering');
2220       END IF;
2221 
2222       /* Set the return status to success initially */
2223       x_return_status := fnd_api.g_ret_sts_success;
2224 
2225       IF NOT gme_common_pvt.g_setup_done THEN
2226          gme_common_pvt.g_setup_done :=
2227                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
2228 
2229          IF NOT gme_common_pvt.g_setup_done THEN
2230             x_return_status := fnd_api.g_ret_sts_error;
2231             RAISE setup_failure;
2232          END IF;
2233       END IF;
2234       /* Initialize message list and count if needed */
2235       IF p_init_msg_list = fnd_api.g_true THEN
2236          fnd_msg_pub.initialize;
2237          gme_common_pvt.g_error_count := 0;
2238       END IF;
2239 
2240       /* Punit Kumar */
2241       gme_common_pvt.set_timestamp;
2242       gme_delete_batch_step_pvt.delete_step
2243                                         (x_return_status       => x_return_status
2247       IF x_return_status = fnd_api.g_ret_sts_success THEN
2244                                         ,p_batch_step_rec      => p_batch_step_rec
2245                                         ,p_reroute_flag        => FALSE);
2246 
2248          NULL;
2249       ELSE
2250          RAISE delete_step_failed;
2251       END IF;
2252             -- NEW
2253             GME_ERES_PKG.INSERT_EVENT(P_EVENT_NAME        => gme_common_pvt.G_BATCHSTEP_REMOVED
2254                                ,P_EVENT_KEY               => p_batch_step_rec.batch_id||'-'||p_batch_step_rec.BATCHSTEP_id
2255                                ,P_USER_KEY_LABEL          => FND_MESSAGE.GET_STRING('GME','GME_PSIG_BATCH_STEP_LABEL')
2256                                ,P_USER_KEY_VALUE          => gme_common_pvt.g_organization_code ||
2257                                                              '-'||p_batch_header_rec.batch_no||'-'|| p_batch_step_rec.BATCHSTEP_NO
2258                                                              ||'-'||GME_ERES_PKG.GET_OPRN_NO(p_batch_step_rec.OPRN_ID)
2259                                ,P_POST_OP_API             => 'NONE'
2260                                ,P_PARENT_EVENT            => NULL
2261                                ,P_PARENT_EVENT_KEY        => NULL
2262                                ,P_PARENT_ERECORD_ID       => NULL
2263                                ,X_STATUS                  => x_return_status);
2264       IF x_return_status <> fnd_api.g_ret_sts_success THEN
2265          RAISE delete_step_failed;
2266       END IF;
2267 
2268 
2269 
2270          gme_common_pvt.log_message ('GME_API_STEP_DELETE');
2271 
2272 
2273       IF (g_debug <= gme_debug.g_log_procedure) THEN
2274          gme_debug.put_line (   'Completed '
2275                              || l_api_name
2276                              || ' at '
2277                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
2278       END IF;
2279 
2280       gme_common_pvt.count_and_get (x_count        => x_message_count
2281                                    ,p_encoded      => fnd_api.g_false
2282                                    ,x_data         => x_message_list);
2283    EXCEPTION
2284       WHEN setup_failure THEN
2285          ROLLBACK TO SAVEPOINT delete_step;
2286          x_return_status := fnd_api.g_ret_sts_error;
2287          gme_common_pvt.count_and_get (x_count        => x_message_count
2288                                       ,p_encoded      => fnd_api.g_false
2289                                       ,x_data         => x_message_list);
2290       WHEN delete_step_failed OR batch_save_failed THEN
2291          ROLLBACK TO SAVEPOINT delete_step;
2292          gme_common_pvt.count_and_get (x_count        => x_message_count
2293                                       ,p_encoded      => fnd_api.g_false
2294                                       ,x_data         => x_message_list);
2295       WHEN OTHERS THEN
2296          ROLLBACK TO SAVEPOINT delete_step;
2297          fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
2298          gme_common_pvt.count_and_get (x_count        => x_message_count
2299                                       ,p_encoded      => fnd_api.g_false
2300                                       ,x_data         => x_message_list);
2301          x_return_status := fnd_api.g_ret_sts_unexp_error;
2302    END delete_step;
2303 
2304 /*************************************************************************
2305   Procedure: insert_step
2306 
2307    Modification History :
2308    Punit Kumar 07-Apr-2005 Convergence Changes
2309 /*************************************************************************/
2310    PROCEDURE insert_step (
2311       p_validation_level   IN              NUMBER
2312             := gme_common_pvt.g_max_errors
2313      ,p_init_msg_list      IN              VARCHAR2 := fnd_api.g_false
2314      ,x_message_count      OUT NOCOPY      NUMBER
2315      ,x_message_list       OUT NOCOPY      VARCHAR2
2316      ,x_return_status      OUT NOCOPY      VARCHAR2
2317      ,p_batch_header_rec   IN              gme_batch_header%ROWTYPE
2318      ,p_batch_step_rec     IN              gme_batch_steps%ROWTYPE
2319      ,x_batch_step         OUT NOCOPY      gme_batch_steps%ROWTYPE)
2320    IS
2321       l_api_name   CONSTANT VARCHAR2 (30)              := 'INSERT_STEP';
2322       l_batch_header        gme_batch_header%ROWTYPE;
2323       insert_step_failed    EXCEPTION;
2324       batch_save_failed     EXCEPTION;
2325       setup_failure         EXCEPTION;
2326 
2327       -- Bug 5903208
2328       gmf_cost_failure         EXCEPTION;
2329       l_message_count		   NUMBER;
2330       l_message_list		   VARCHAR2(2000);
2331 
2332    BEGIN
2333       /* Set the savepoint before proceeding */
2334       SAVEPOINT insert_step;
2335 
2336       /* Initialize message list and count if needed */
2337       IF (g_debug IS NOT NULL) THEN
2338          gme_debug.log_initialize ('InsertStep');
2339       END IF;
2340 
2341       IF g_debug <= gme_debug.g_log_procedure THEN
2342          gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
2343                              || 'Entering');
2344       END IF;
2345 
2346       /* Set the return status to success initially */
2347       x_return_status := fnd_api.g_ret_sts_success;
2348 
2349       IF NOT gme_common_pvt.g_setup_done THEN
2350          gme_common_pvt.g_setup_done :=
2351                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
2352 
2353          IF NOT gme_common_pvt.g_setup_done THEN
2354             x_return_status := fnd_api.g_ret_sts_error;
2355             RAISE setup_failure;
2359          fnd_msg_pub.initialize;
2356          END IF;
2357       END IF;
2358       IF p_init_msg_list = fnd_api.g_true THEN
2360          gme_common_pvt.g_error_count := 0;
2361       END IF;
2362 
2363       /* Punit Kumar */
2364       gme_common_pvt.set_timestamp;
2365       gme_insert_step_pvt.insert_batch_step
2366                                     (p_gme_batch_header      => p_batch_header_rec
2367                                     ,p_gme_batch_step        => p_batch_step_rec
2368                                     ,x_gme_batch_step        => x_batch_step
2369                                     ,x_return_status         => x_return_status);
2370 
2371       IF x_return_status <> fnd_api.g_ret_sts_success THEN
2372          RAISE insert_step_failed;
2373       END IF;
2374 
2375       --
2376       -- Bug 5903208 -- call to GMF
2377       --
2378       GMF_VIB.Update_Batch_Requirements
2379       ( p_api_version   =>    1.0,
2380         p_init_msg_list =>    FND_API.G_FALSE,
2381         p_batch_id      =>    p_batch_header_rec.batch_id,
2382         x_return_status =>    x_return_status,
2383         x_msg_count     =>    l_message_count,
2384         x_msg_data      =>    l_message_list);
2385       IF x_return_status <> FND_API.G_RET_STS_SUCCESS
2386       THEN
2387          RAISE gmf_cost_failure;
2388       END IF;
2389       -- End Bug 5903208
2390 
2391       -- NEW
2392       GME_ERES_PKG.INSERT_EVENT(P_EVENT_NAME              => gme_common_pvt.G_BATCHSTEP_ADDED
2393                                ,P_EVENT_KEY               => x_batch_step.batch_id||'-'||x_batch_step.BATCHSTEP_id
2394                                ,P_USER_KEY_LABEL          => FND_MESSAGE.GET_STRING('GME','GME_PSIG_BATCH_STEP_LABEL')
2395                                ,P_USER_KEY_VALUE          => gme_common_pvt.g_organization_code ||
2396                                                              '-'||p_batch_header_rec.batch_no||'-'|| x_batch_step.BATCHSTEP_NO
2397                                                              ||'-'||GME_ERES_PKG.GET_OPRN_NO(x_batch_step.OPRN_ID)
2398                                ,P_POST_OP_API             => 'NONE'
2399                                ,P_PARENT_EVENT            => NULL
2400                                ,P_PARENT_EVENT_KEY        => NULL
2401                                ,P_PARENT_ERECORD_ID       => NULL
2402                                ,X_STATUS                  => x_return_status);
2403       IF x_return_status <> fnd_api.g_ret_sts_success THEN
2404          RAISE insert_step_failed;
2405       END IF;
2406       gme_common_pvt.log_message ('GME_INSERT_STEP');
2407       IF (g_debug <= gme_debug.g_log_procedure) THEN
2408          gme_debug.put_line (   'Completed '
2409                              || l_api_name
2410                              || ' at '
2411                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
2412       END IF;
2413    EXCEPTION
2414       WHEN   gmf_cost_failure THEN
2415         -- Bug 5903208
2416         x_return_status := FND_API.G_RET_STS_ERROR;
2417 
2418       WHEN setup_failure THEN
2419          ROLLBACK TO SAVEPOINT insert_step;
2420          x_batch_step := NULL;
2421          x_return_status := fnd_api.g_ret_sts_error;
2422          gme_common_pvt.count_and_get (x_count        => x_message_count
2423                                       ,p_encoded      => fnd_api.g_false
2424                                       ,x_data         => x_message_list);
2425       WHEN insert_step_failed OR batch_save_failed THEN
2426          ROLLBACK TO SAVEPOINT insert_step;
2427          x_batch_step := NULL;
2428          gme_common_pvt.count_and_get (x_count        => x_message_count
2429                                       ,p_encoded      => fnd_api.g_false
2430                                       ,x_data         => x_message_list);
2431       WHEN OTHERS THEN
2432          ROLLBACK TO SAVEPOINT insert_step;
2433          x_batch_step := NULL;
2434          fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
2435          gme_common_pvt.count_and_get (x_count        => x_message_count
2436                                       ,p_encoded      => fnd_api.g_false
2437                                       ,x_data         => x_message_list);
2438          x_return_status := fnd_api.g_ret_sts_unexp_error;
2439    END insert_step;
2440 
2441 
2442       PROCEDURE revert_batch (
2443       p_validation_level       	IN              NUMBER := gme_common_pvt.g_max_errors
2444      ,p_init_msg_list          	IN              VARCHAR2 := FND_API.G_FALSE
2445      ,x_message_count          	OUT NOCOPY      NUMBER
2446      ,x_message_list           	OUT NOCOPY      VARCHAR2
2447      ,x_return_status          	OUT NOCOPY      VARCHAR2
2448      ,p_batch_header_rec       	IN              gme_batch_header%ROWTYPE
2449      ,x_batch_header_rec      	OUT NOCOPY 	gme_batch_header%ROWTYPE)
2450      IS
2451 
2452       l_api_name      CONSTANT VARCHAR2 (30) := 'REVERT_BATCH';
2453       setup_failure            	EXCEPTION;
2454       batch_revert_failure	EXCEPTION;
2455 
2456      BEGIN
2457 
2458      SAVEPOINT revert_batch;
2459 
2460       IF (g_debug IS NOT NULL) THEN
2461          gme_debug.log_initialize ('RevertBatch');
2462       END IF;
2463 
2464       IF g_debug <= gme_debug.g_log_procedure THEN
2465          gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
2466                              || 'Entering');
2467       END IF;
2468 
2469       /* Set the return status to success initially */
2470       x_return_status := fnd_api.g_ret_sts_success;
2474                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
2471 
2472       IF NOT gme_common_pvt.g_setup_done THEN
2473          gme_common_pvt.g_setup_done :=
2475 
2476          IF NOT gme_common_pvt.g_setup_done THEN
2477             x_return_status := fnd_api.g_ret_sts_error;
2478             RAISE setup_failure;
2479          END IF;
2480       END IF;
2481 
2482       -- Initialize message list and count if needed
2483       IF p_init_msg_list = fnd_api.g_true THEN
2484          fnd_msg_pub.initialize;
2485          gme_common_pvt.g_error_count := 0;
2486       END IF;
2487 
2488       gme_common_pvt.set_timestamp;
2489 
2490       IF g_debug <= gme_debug.g_log_statement THEN
2491          gme_debug.put_line (   g_pkg_name
2492                              || '.'
2493                              || l_api_name
2494                              || ':'
2495                              || 'calling revert batch pvt');
2496       END IF;
2497 
2498       gme_revert_batch_pvt.revert_batch
2499                                     (p_batch_header_rec      => p_batch_header_rec,
2500                                      x_batch_header_rec      => x_batch_header_rec,
2501                                      x_return_status         => x_return_status);
2502 
2503       IF (g_debug <= gme_debug.g_log_procedure) THEN
2504          gme_debug.put_line (   g_pkg_name
2505                              || '.'
2506                              || l_api_name
2507                              || ':'
2508                              || 'x_return_status='
2509                              || x_return_status);
2510       END IF;
2511 
2512       IF x_return_status <> fnd_api.g_ret_sts_success THEN
2513          RAISE batch_revert_failure;
2514       END IF;            /* IF x_return_status <> FND_API.G_RET_STS_SUCCESS */
2515 
2516 
2517       gme_common_pvt.log_message ('GME_API_BATCH_UNCERTIFIED');
2518 
2519 
2520       gme_common_pvt.count_and_get (x_count        => x_message_count,
2521                                     p_encoded      => fnd_api.g_false,
2522                                     x_data         => x_message_list);
2523 
2524       IF (g_debug IS NOT NULL) THEN
2525          gme_debug.put_line (   'Completed '
2526                              || l_api_name
2527                              || ' at '
2528                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
2529       END IF;
2530 
2531       IF g_debug <= gme_debug.g_log_procedure THEN
2532          gme_debug.put_line (   'Exiting api '
2533                              || g_pkg_name
2534                              || '.'
2535                              || l_api_name
2536                              || x_return_status);
2537       END IF;
2538    EXCEPTION
2539       WHEN batch_revert_failure THEN
2540          ROLLBACK TO SAVEPOINT revert_batch;
2541          x_batch_header_rec := NULL;
2542          gme_common_pvt.count_and_get (x_count        => x_message_count,
2543                                        p_encoded      => fnd_api.g_false,
2544                                        x_data         => x_message_list);
2545       WHEN setup_failure THEN
2546          ROLLBACK TO SAVEPOINT revert_batch;
2547          x_batch_header_rec := NULL;
2548          gme_common_pvt.count_and_get (x_count        => x_message_count,
2549                                        p_encoded      => fnd_api.g_false,
2550                                        x_data         => x_message_list);
2551          x_return_status := fnd_api.g_ret_sts_error;
2552       WHEN OTHERS THEN
2553          IF g_debug <= gme_debug.g_log_unexpected THEN
2554             gme_debug.put_line (   'When others exception in '
2555                                 || g_pkg_name
2556                                 || '.'
2557                                 || l_api_name
2558                                 || ' Error is '
2559                                 || SQLERRM);
2560          END IF;
2561 
2562          ROLLBACK TO SAVEPOINT revert_batch;
2563          x_batch_header_rec := NULL;
2564          gme_common_pvt.count_and_get (x_count        => x_message_count,
2565                                        p_encoded      => fnd_api.g_false,
2566                                        x_data         => x_message_list);
2567          x_return_status := fnd_api.g_ret_sts_unexp_error ;
2568 
2569 
2570  END revert_batch;
2571 
2572 PROCEDURE revert_step (
2573       p_validation_level       	IN              NUMBER := gme_common_pvt.g_max_errors
2574      ,p_init_msg_list          	IN              VARCHAR2 := FND_API.G_FALSE
2575      ,x_message_count          	OUT NOCOPY      NUMBER
2576      ,x_message_list           	OUT NOCOPY      VARCHAR2
2577      ,x_return_status          	OUT NOCOPY      VARCHAR2
2578      ,p_batch_step_rec        	IN         gme_batch_steps%ROWTYPE
2579      ,p_batch_header_rec        IN 	   gme_batch_header%ROWTYPE
2580      ,x_batch_step_rec        	OUT NOCOPY gme_batch_steps%ROWTYPE)IS
2581 
2582 
2583       l_api_name      CONSTANT VARCHAR2 (30) := 'REVERT_STEP';
2584       setup_failure            	EXCEPTION;
2585       step_revert_failure	EXCEPTION;
2586 
2587      BEGIN
2588 
2589      SAVEPOINT revert_step;
2590 
2591       IF (g_debug IS NOT NULL) THEN
2592          gme_debug.log_initialize ('RevertStep');
2593       END IF;
2594 
2595       IF g_debug <= gme_debug.g_log_procedure THEN
2596          gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
2600       /* Set the return status to success initially */
2597                              || 'Entering');
2598       END IF;
2599 
2601       x_return_status := fnd_api.g_ret_sts_success;
2602 
2603       IF NOT gme_common_pvt.g_setup_done THEN
2604          gme_common_pvt.g_setup_done :=
2605                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
2606 
2607          IF NOT gme_common_pvt.g_setup_done THEN
2608             x_return_status := fnd_api.g_ret_sts_error;
2609             RAISE setup_failure;
2610          END IF;
2611       END IF;
2612 
2613       -- Initialize message list and count if needed
2614       IF p_init_msg_list = fnd_api.g_true THEN
2615          fnd_msg_pub.initialize;
2616          gme_common_pvt.g_error_count := 0;
2617       END IF;
2618 
2619       gme_common_pvt.set_timestamp;
2620 
2621       IF g_debug <= gme_debug.g_log_statement THEN
2622          gme_debug.put_line (   g_pkg_name
2623                              || '.'
2624                              || l_api_name
2625                              || ':'
2626                              || 'calling revert step pvt');
2627       END IF;
2628 
2629       gme_revert_step_pvt.revert_step
2630                                     (p_batch_step_rec      	=> p_batch_step_rec,
2631                                      p_batch_header_rec      	=> p_batch_header_rec,
2632                                      x_batch_step_rec      	=> x_batch_step_rec,
2633                                      x_return_status         	=> x_return_status);
2634 
2635       IF (g_debug <= gme_debug.g_log_procedure) THEN
2636          gme_debug.put_line (   g_pkg_name
2637                              || '.'
2638                              || l_api_name
2639                              || ':'
2640                              || 'x_return_status='
2641                              || x_return_status);
2642       END IF;
2643 
2644       IF x_return_status <> fnd_api.g_ret_sts_success THEN
2645          RAISE step_revert_failure;
2646       END IF;            /* IF x_return_status <> FND_API.G_RET_STS_SUCCESS */
2647 
2648 
2649          gme_common_pvt.log_message ('GME_BATCH_STEP_UNCERTIFIED');
2650 
2651 
2652       gme_common_pvt.count_and_get (x_count        => x_message_count,
2653                                     p_encoded      => fnd_api.g_false,
2654                                     x_data         => x_message_list);
2655 
2656       IF (g_debug IS NOT NULL) THEN
2657          gme_debug.put_line (   'Completed '
2658                              || l_api_name
2659                              || ' at '
2660                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
2661       END IF;
2662 
2663       IF g_debug <= gme_debug.g_log_procedure THEN
2664          gme_debug.put_line (   'Exiting api '
2665                              || g_pkg_name
2666                              || '.'
2667                              || l_api_name
2668                              || x_return_status);
2669       END IF;
2670    EXCEPTION
2671       WHEN step_revert_failure THEN
2672          ROLLBACK TO SAVEPOINT revert_step;
2673          x_batch_step_rec := NULL;
2674          gme_common_pvt.count_and_get (x_count        => x_message_count,
2675                                        p_encoded      => fnd_api.g_false,
2676                                        x_data         => x_message_list);
2677       WHEN setup_failure THEN
2678          ROLLBACK TO SAVEPOINT revert_step;
2679          x_batch_step_rec := NULL;
2680          gme_common_pvt.count_and_get (x_count        => x_message_count,
2681                                        p_encoded      => fnd_api.g_false,
2682                                        x_data         => x_message_list);
2683          x_return_status := fnd_api.g_ret_sts_error;
2684       WHEN OTHERS THEN
2685          IF g_debug <= gme_debug.g_log_unexpected THEN
2686             gme_debug.put_line (   'When others exception in '
2687                                 || g_pkg_name
2688                                 || '.'
2689                                 || l_api_name
2690                                 || ' Error is '
2691                                 || SQLERRM);
2692          END IF;
2693 
2694          ROLLBACK TO SAVEPOINT revert_step;
2695          x_batch_step_rec := NULL;
2696          gme_common_pvt.count_and_get (x_count        => x_message_count,
2697                                        p_encoded      => fnd_api.g_false,
2698                                        x_data         => x_message_list);
2699          x_return_status := fnd_api.g_ret_sts_unexp_error ;
2700   END revert_step;
2701 /*************************************************************************/
2702    PROCEDURE close_batch (
2703       p_validation_level   IN              NUMBER
2704      ,p_init_msg_list      IN              VARCHAR2
2705      ,x_message_count      OUT NOCOPY      NUMBER
2706      ,x_message_list       OUT NOCOPY      VARCHAR2
2707      ,x_return_status      OUT NOCOPY      VARCHAR2
2708      ,p_batch_header_rec   IN              gme_batch_header%ROWTYPE
2709      ,x_batch_header_rec   OUT NOCOPY      gme_batch_header%ROWTYPE)
2710    IS
2711       l_api_name   CONSTANT VARCHAR2 (30) := 'CLOSE_BATCH';
2712       setup_failure         EXCEPTION;
2713       batch_close_failure   EXCEPTION;
2714       batch_save_failed     EXCEPTION;
2715    BEGIN
2716       IF g_debug <= gme_debug.g_log_procedure THEN
2717          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
2721       /* Set the savepoint before proceeding */
2718                              || l_api_name);
2719       END IF;
2720 
2722       SAVEPOINT close_batch;
2723 
2724       IF (g_debug IS NOT NULL) THEN
2725          gme_debug.log_initialize ('CloseBatch');
2726       END IF;
2727 
2728       IF NOT gme_common_pvt.g_setup_done THEN
2729          gme_common_pvt.g_setup_done :=
2730                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
2731 
2732          IF NOT gme_common_pvt.g_setup_done THEN
2733             x_return_status := fnd_api.g_ret_sts_error;
2734             RAISE setup_failure;
2735          END IF;
2736       END IF;
2737 
2738       /* Initialize message list and count if needed */
2739       IF p_init_msg_list = fnd_api.g_true THEN
2740          fnd_msg_pub.initialize;
2741          gme_common_pvt.g_error_count := 0;
2742       END IF;
2743 
2744       gme_common_pvt.set_timestamp;
2745 
2746       IF g_debug <= gme_debug.g_log_procedure THEN
2747          gme_debug.put_line ('Calling gme_close_batch_pvt.close_batch.');
2748       END IF;
2749 
2750       gme_close_batch_pvt.close_batch
2751                                     (p_batch_header_rec      => p_batch_header_rec
2752                                     ,x_batch_header_rec      => x_batch_header_rec
2753                                     ,x_return_status         => x_return_status);
2754 
2755       IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
2756          gme_debug.put_line (   'Came back from Pvt Close Batch with status '
2757                              || x_return_status);
2758       END IF;
2759 
2760       IF x_return_status = fnd_api.g_ret_sts_success THEN
2761          /* This comment has to be removed after this api  becomes available.
2762          GME_TRANS_ENGINE_PVT.inform_OM
2763                    ( p_action              => 'DELETE'
2764                    , p_trans_id            => NULL
2765                    , p_trans_id_reversed   => NULL
2766                    , p_gme_batch_hdr       => x_batch_header
2767                    , p_gme_matl_dtl        => NULL
2768                    );
2769          */
2770          NULL;
2771       ELSE
2772          RAISE batch_close_failure;
2773       END IF;
2774 
2775 
2776        gme_common_pvt.log_message ('GME_API_BATCH_CLOSED');
2777 
2778 
2779       gme_common_pvt.count_and_get (x_count        => x_message_count
2780                                    ,p_encoded      => fnd_api.g_false
2781                                    ,x_data         => x_message_list);
2782 
2783       IF g_debug <= gme_debug.g_log_procedure THEN
2784          gme_debug.put_line (   'Completed '
2785                              || l_api_name
2786                              || ' at '
2787                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
2788       END IF;
2789    EXCEPTION
2790       WHEN setup_failure OR batch_close_failure OR batch_save_failed THEN
2791          ROLLBACK TO SAVEPOINT close_batch;
2792          x_batch_header_rec := NULL;
2793          gme_common_pvt.count_and_get (x_count        => x_message_count
2794                                       ,p_encoded      => fnd_api.g_false
2795                                       ,x_data         => x_message_list);
2796       WHEN OTHERS THEN
2797          ROLLBACK TO SAVEPOINT close_batch;
2798          x_batch_header_rec := NULL;
2799          fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
2800          gme_common_pvt.count_and_get (x_count        => x_message_count
2801                                       ,p_encoded      => fnd_api.g_false
2802                                       ,x_data         => x_message_list);
2803          x_return_status := fnd_api.g_ret_sts_unexp_error;
2804    END close_batch;
2805 
2806 /*************************************************************************/
2807    PROCEDURE close_step (
2808       p_validation_level   IN              NUMBER
2809             := gme_common_pvt.g_max_errors
2810      ,                                                       /* Punit Kumar */
2811       p_init_msg_list      IN              VARCHAR2 := fnd_api.g_false
2812      ,x_message_count      OUT NOCOPY      NUMBER
2813      ,x_message_list       OUT NOCOPY      VARCHAR2
2814      ,x_return_status      OUT NOCOPY      VARCHAR2
2815      ,p_batch_header_rec   IN              gme_batch_header%ROWTYPE
2816      ,p_batch_step_rec     IN              gme_batch_steps%ROWTYPE
2817      ,p_delete_pending     IN              VARCHAR2 := fnd_api.g_false
2818      ,x_batch_step_rec     OUT NOCOPY      gme_batch_steps%ROWTYPE)
2819    IS
2820       l_api_name   CONSTANT VARCHAR2 (30)              := 'CLOSE_STEP';
2821       setup_failure         EXCEPTION;
2822       batch_save_failed     EXCEPTION;
2823       step_close_failed     EXCEPTION;
2824       l_batch_hdr           gme_batch_header%ROWTYPE;
2825    BEGIN
2826       /* Set the savepoint before proceeding */
2827       SAVEPOINT close_batch_step;
2828 
2829       IF (g_debug IS NOT NULL) THEN
2830          gme_debug.log_initialize ('CloseStep');
2831       END IF;
2832 
2833       IF g_debug <= gme_debug.g_log_procedure THEN
2834          gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
2835                              || 'Entering');
2836       END IF;
2837 
2838       /* Set the return status to success initially */
2839       x_return_status := fnd_api.g_ret_sts_success;
2840 
2841       IF NOT gme_common_pvt.g_setup_done THEN
2845          IF NOT gme_common_pvt.g_setup_done THEN
2842          gme_common_pvt.g_setup_done :=
2843                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
2844 
2846             x_return_status := fnd_api.g_ret_sts_error;
2847             RAISE setup_failure;
2848          END IF;
2849       END IF;
2850       /* Initialize message list and count if needed */
2851       IF p_init_msg_list = fnd_api.g_true THEN
2852          fnd_msg_pub.initialize;
2853          gme_common_pvt.g_error_count := 0;
2854       END IF;
2855 
2856       gme_common_pvt.set_timestamp;
2857 
2858       gme_close_step_pvt.close_step (p_batch_step_rec      => p_batch_step_rec
2859                                     ,p_delete_pending      => p_delete_pending
2860                                     ,x_batch_step_rec      => x_batch_step_rec
2861                                     ,x_return_status       => x_return_status);
2862 
2863       IF x_return_status = fnd_api.g_ret_sts_success THEN
2864          NULL;
2865       ELSE
2866          RAISE step_close_failed;
2867       END IF;
2868 
2869       IF (g_debug <= gme_debug.g_log_procedure) THEN
2870          gme_debug.put_line (   'Completed '
2871                              || l_api_name
2872                              || ' at '
2873                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
2874       END IF;
2875 
2876 
2877       gme_common_pvt.log_message ('GME_BATCH_STEP_CLOSED');
2878 
2879 
2880       gme_common_pvt.count_and_get (x_count        => x_message_count
2881                                    ,p_encoded      => fnd_api.g_false
2882                                    ,x_data         => x_message_list);
2883    EXCEPTION
2884       WHEN setup_failure OR step_close_failed OR batch_save_failed THEN
2885          ROLLBACK TO SAVEPOINT close_batch_step;
2886          x_batch_step_rec := NULL;
2887          /*N Punit Kumar */
2888          gme_common_pvt.count_and_get (x_count        => x_message_count
2889                                       ,p_encoded      => fnd_api.g_false
2890                                       ,x_data         => x_message_list);
2891       WHEN OTHERS THEN
2892          ROLLBACK TO SAVEPOINT close_batch_step;
2893          x_batch_step_rec := NULL;
2894          fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
2895          /*N Punit Kumar */
2896          gme_common_pvt.count_and_get (x_count        => x_message_count
2897                                       ,p_encoded      => fnd_api.g_false
2898                                       ,x_data         => x_message_list);
2899          x_return_status := fnd_api.g_ret_sts_unexp_error;
2900    END close_step;
2901 
2902 /*************************************************************************/
2903    PROCEDURE reopen_batch (
2904       p_validation_level   IN              NUMBER
2905             := gme_common_pvt.g_max_errors
2906      ,
2907       p_init_msg_list      IN              VARCHAR2 := fnd_api.g_false
2908      ,x_message_count      OUT NOCOPY      NUMBER
2909      ,x_message_list       OUT NOCOPY      VARCHAR2
2910      ,x_return_status      OUT NOCOPY      VARCHAR2
2911      ,p_batch_header_rec   IN              gme_batch_header%ROWTYPE
2912      ,p_reopen_steps       IN              VARCHAR2 := fnd_api.g_false
2913      ,x_batch_header_rec   OUT NOCOPY      gme_batch_header%ROWTYPE)
2914    IS
2915       l_api_name    CONSTANT VARCHAR2 (30) := 'REOPEN_BATCH';
2916       setup_failure          EXCEPTION;
2917       batch_save_failed      EXCEPTION;
2918       batch_reopen_failure   EXCEPTION;
2919    BEGIN
2920       /* Set the save point before processing */
2921       SAVEPOINT reopen_batch;
2922 
2923       IF (g_debug IS NOT NULL) THEN
2924          gme_debug.log_initialize ('ReopenBatch');
2925       END IF;
2926 
2927       IF (g_debug <= gme_debug.g_log_procedure) THEN
2928          gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
2929                              || 'Entering');
2930       END IF;
2931 
2932       /* Initialize message list and count if needed*/
2933       IF p_init_msg_list = fnd_api.g_true THEN
2934          fnd_msg_pub.initialize;
2935          gme_common_pvt.g_error_count := 0;
2936       END IF;
2937 
2938       /* Set the success staus to success inititally*/
2939       x_return_status := fnd_api.g_ret_sts_success;
2940 
2941       -- Pawan kumar added for bug 4956087
2942       IF NOT gme_common_pvt.g_setup_done THEN
2943          gme_common_pvt.g_setup_done :=
2944                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
2945 
2946          IF NOT gme_common_pvt.g_setup_done THEN
2947             x_return_status := fnd_api.g_ret_sts_error;
2948             RAISE setup_failure;
2949          END IF;
2950       END IF;
2951       gme_common_pvt.set_timestamp;
2952 
2953       IF (g_debug <= gme_debug.g_log_procedure) THEN
2954         gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
2955                              || 'calling private layer');
2956       END IF;
2957 
2958       gme_reopen_batch_pvt.reopen_batch
2959                                     (p_batch_header_rec      => p_batch_header_rec
2960                                     ,p_reopen_steps          => p_reopen_steps
2961                                     ,x_batch_header_rec      => x_batch_header_rec
2962                                     ,x_return_status         => x_return_status);
2963 
2964       IF (g_debug <= gme_debug.g_log_procedure) THEN
2968 
2965          gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
2966                              || 'after private layer with sts'||x_return_status);
2967       END IF;
2969       IF (x_return_status = fnd_api.g_ret_sts_success) THEN
2970          NULL;
2971       ELSE
2972          RAISE batch_reopen_failure;
2973       END IF;
2974 
2975          gme_common_pvt.log_message ('GME_API_BATCH_REOPENED');
2976 
2977 
2978       IF (g_debug <= gme_debug.g_log_procedure) THEN
2979          gme_debug.put_line (   'Completed '
2980                              || l_api_name
2981                              || ' at '
2982                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
2983       END IF;
2984 
2985 
2986       gme_common_pvt.count_and_get (x_count        => x_message_count
2987                                    ,p_encoded      => fnd_api.g_false
2988                                    ,x_data         => x_message_list);
2989 
2990 
2991    EXCEPTION
2992       WHEN setup_failure THEN
2993          ROLLBACK TO SAVEPOINT reopen_batch;
2994          x_batch_header_rec := NULL;
2995 
2996          IF (g_debug <= gme_debug.g_log_procedure) THEN
2997             gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
2998              ||'reopen_batch error : SETUP_FAILURE'
2999                                );
3000          END IF;
3001 
3002          x_return_status := fnd_api.g_ret_sts_error;
3003          /*N Punit Kumar */
3004          gme_common_pvt.count_and_get (x_count        => x_message_count
3005                                       ,p_encoded      => fnd_api.g_false
3006                                       ,x_data         => x_message_list);
3007       WHEN batch_reopen_failure OR batch_save_failed THEN
3008          ROLLBACK TO SAVEPOINT reopen_batch;
3009          x_batch_header_rec := NULL;
3010 
3011          IF (g_debug <= gme_debug.g_log_procedure) THEN
3012             gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
3013                || 'reopen_batch error : BATCH_REOPEN_FAILURE OR BATCH_SAVE_FAILED OR ERROR_CHECK_PHANT.'
3014               );
3015          END IF;
3016 
3017          /*N Punit Kumar */
3018          gme_common_pvt.count_and_get (x_count        => x_message_count
3019                                       ,p_encoded      => fnd_api.g_false
3020                                       ,x_data         => x_message_list);
3021          x_return_status := fnd_api.g_ret_sts_error;
3022       WHEN OTHERS THEN
3023          ROLLBACK TO SAVEPOINT reopen_batch;
3024          x_batch_header_rec := NULL;
3025 
3026          IF (g_debug <= gme_debug.g_log_unexpected) THEN
3027             gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
3028             ||'reopen_batch error : OTHERS.' || SQLCODE
3029                                );
3030          END IF;
3031 
3032          fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
3033 
3034          gme_common_pvt.count_and_get (x_count        => x_message_count
3035                                       ,p_encoded      => fnd_api.g_false
3036                                       ,x_data         => x_message_list);
3037          x_return_status := fnd_api.g_ret_sts_unexp_error;
3038    END reopen_batch;
3039 
3040 /*************************************************************************/
3041    PROCEDURE reopen_step (
3042       p_validation_level   IN              NUMBER
3043             := gme_common_pvt.g_max_errors
3044      ,                                                       /* Punit Kumar */
3045       p_init_msg_list      IN              VARCHAR2 := fnd_api.g_false
3046      ,x_message_count      OUT NOCOPY      NUMBER
3047      ,x_message_list       OUT NOCOPY      VARCHAR2
3048      ,x_return_status      OUT NOCOPY      VARCHAR2
3049      ,p_batch_header_rec   IN              gme_batch_header%ROWTYPE
3050      ,p_batch_step_rec     IN              gme_batch_steps%ROWTYPE
3051      ,x_batch_step_rec     OUT NOCOPY      gme_batch_steps%ROWTYPE)
3052    IS
3053       l_api_name   CONSTANT VARCHAR2 (30)              := 'REOPEN_STEP';
3054       setup_failure         EXCEPTION;
3055       step_save_failed      EXCEPTION;
3056       step_reopen_failure   EXCEPTION;
3057       l_batch_header        gme_batch_header%ROWTYPE;
3058    BEGIN
3059       -- Set the save point before proceeding
3060       SAVEPOINT reopen_batch_step;
3061 
3062       /* Initialize message list and count if needed*/
3063       IF p_init_msg_list = fnd_api.g_true THEN
3064          fnd_msg_pub.initialize;
3065          gme_common_pvt.g_error_count := 0;                 /* Punit Kumar */
3066       END IF;
3067 
3068       IF (g_debug IS NOT NULL) THEN
3069          gme_debug.log_initialize ('ReopenStep');
3070       END IF;
3071 
3072       IF (g_debug <= gme_debug.g_log_procedure) THEN
3073         gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
3074                              || 'entering');
3075       END IF;
3076       IF NOT gme_common_pvt.g_setup_done THEN
3077          gme_common_pvt.g_setup_done :=
3078                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
3079 
3080          IF NOT gme_common_pvt.g_setup_done THEN
3081             x_return_status := fnd_api.g_ret_sts_error;
3082             RAISE setup_failure;
3083          END IF;
3084       END IF;
3085       /* Set the success staus to success inititally*/
3086       x_return_status := fnd_api.g_ret_sts_success;
3087       /* Punit Kumar */
3091         gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
3088       gme_common_pvt.set_timestamp;
3089 
3090       IF (g_debug <= gme_debug.g_log_procedure) THEN
3092                              || 'calling private layer');
3093       END IF;
3094 
3095       gme_reopen_step_pvt.reopen_step (p_batch_step_rec      => p_batch_step_rec
3096                                       ,x_batch_step_rec      => x_batch_step_rec
3097                                       ,x_return_status       => x_return_status);
3098 
3099       IF (g_debug <= gme_debug.g_log_procedure) THEN
3100         gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
3101                              || 'existing private layer with status'||x_return_status );
3102       END IF;
3103 
3104       IF (x_return_status = fnd_api.g_ret_sts_success) THEN
3105          NULL;
3106       ELSE
3107          RAISE step_reopen_failure;
3108       END IF;
3109 
3110 
3111          gme_common_pvt.log_message ('GME_API_STEP_REOPENED');
3112 
3113 
3114       IF (g_debug <= gme_debug.g_log_procedure) THEN
3115          gme_debug.put_line (   'Completed '
3116                              || l_api_name
3117                              || ' at '
3118                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
3119       END IF;
3120 
3121       gme_common_pvt.count_and_get (x_count        => x_message_count
3122                                    ,p_encoded      => fnd_api.g_false
3123                                    ,x_data         => x_message_list);
3124 
3125       IF (g_debug <= gme_debug.g_log_procedure) THEN
3126          gme_debug.put_line ('Normal end of Public Reopen_Step.'
3127                             ,gme_debug.g_log_procedure
3128                             ,'reopen_batch');
3129       END IF;
3130    EXCEPTION
3131       WHEN setup_failure THEN
3132          ROLLBACK TO SAVEPOINT reopen_batch_step;
3133          x_batch_step_rec := NULL;
3134 
3135          IF (g_debug <= gme_debug.g_log_procedure) THEN
3136              gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
3137                              ||'reopen_step error : SETUP_FAILURE.'
3138                                );
3139          END IF;
3140 
3141          x_return_status := fnd_api.g_ret_sts_error;
3142          /* Punit Kumar */
3143          gme_common_pvt.count_and_get (x_count        => x_message_count
3144                                       ,p_encoded      => fnd_api.g_false
3145                                       ,x_data         => x_message_list);
3146       WHEN step_reopen_failure OR step_save_failed THEN
3147          ROLLBACK TO SAVEPOINT reopen_batch_step;
3148          x_batch_step_rec := NULL;
3149 
3150          IF (g_debug <= gme_debug.g_log_procedure) THEN
3151              gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
3152                              ||
3153                'reopen_step error : STEP_REOPEN_FAILURE OR STEP_SAVE_FAILED.'
3154               );
3155          END IF;
3156 
3157          /* Punit Kumar */
3158          gme_common_pvt.count_and_get (x_count        => x_message_count
3159                                       ,p_encoded      => fnd_api.g_false
3160                                       ,x_data         => x_message_list);
3161          x_return_status := fnd_api.g_ret_sts_error;
3162       WHEN OTHERS THEN
3163          ROLLBACK TO SAVEPOINT reopen_batch_step;
3164          x_batch_step_rec := NULL;
3165 
3166         IF (g_debug <= gme_debug.g_log_unexpected) THEN
3167             gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
3168             ||'reopen_step error : OTHERS.' || SQLCODE
3169                                );
3170          END IF;
3171 
3172          fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
3173          /* Punit Kumar */
3174          gme_common_pvt.count_and_get (x_count        => x_message_count
3175                                       ,p_encoded      => fnd_api.g_false
3176                                       ,x_data         => x_message_list);
3177          x_return_status := fnd_api.g_ret_sts_unexp_error;
3178    END reopen_step;
3179 
3180 /*================================================================================
3181     Procedure
3182       incremental_backflush
3183     Description
3184       This procedure is used to incrementally backflush the qty to the material line.
3185 
3186     Parameters
3187       p_batch_header_rec (R)    The batch header record
3188       p_material_detail_rec (R) The material detail record
3189       p_qty (R)                 The quantity to apply incrementally as follows:
3190       p_qty_type (R)            0 - By increment qty
3191                                 1 - New actual qty
3192                                 2 - % of Plan
3193       p_trans_date              Transaction date to record for the incremental backflush
3194       x_exception_material_tab  Table of materials that could not be consumed or yielded
3195                                 for the calculated incremental quantity
3196       x_return_status           result of the API call
3197                                 S - Success
3198                                 E - Error
3199                                 U - Unexpected Error
3200                                 X - Batch Exception
3201 
3202    HISTORY
3203 
3204   ================================================================================*/
3205    PROCEDURE incremental_backflush (
3206       p_validation_level         IN              NUMBER
3210      ,x_message_list             OUT NOCOPY      VARCHAR2
3207             := gme_common_pvt.g_max_errors
3208      ,p_init_msg_list            IN              VARCHAR2 := fnd_api.g_false
3209      ,x_message_count            OUT NOCOPY      NUMBER
3211      ,x_return_status            OUT NOCOPY      VARCHAR2
3212      ,p_batch_header_rec         IN              gme_batch_header%ROWTYPE
3213      ,p_material_detail_rec      IN              gme_material_details%ROWTYPE
3214      ,p_qty                      IN              NUMBER
3215      ,p_qty_type                 IN              NUMBER
3216      ,p_trans_date               IN              DATE
3217      ,x_exception_material_tbl   OUT NOCOPY      gme_common_pvt.exceptions_tab )
3218    IS
3219       l_api_name            CONSTANT VARCHAR2 (30) := 'INCREMENTAL_BACKFLUSH';
3220       l_trans_date                   DATE;
3221 
3222       l_backflush_rsrc_usg_ind       NUMBER;
3223 
3224       incremental_backflush_failed   EXCEPTION;
3225       setup_failure                  EXCEPTION;
3226    BEGIN
3227       /* Set the savepoint */
3228       SAVEPOINT incremental_backflush;
3229 
3230       IF (g_debug IS NOT NULL) THEN
3231          gme_debug.log_initialize ('IncrementalBackflush');
3232       END IF;
3233       /* Set the return status to success initially */
3234       x_return_status := fnd_api.g_ret_sts_success;
3235 
3236       /* Setup the common constants used across the apis */
3237      IF NOT gme_common_pvt.g_setup_done THEN
3238          gme_common_pvt.g_setup_done :=
3239                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
3240 
3241          IF NOT gme_common_pvt.g_setup_done THEN
3242             x_return_status := fnd_api.g_ret_sts_error;
3243             RAISE setup_failure;
3244          END IF;
3245       END IF;
3246 
3247       /* Initialize message list and count if needed */
3248       IF p_init_msg_list = fnd_api.g_true THEN
3249          fnd_msg_pub.initialize;
3250          gme_common_pvt.g_error_count := 0;
3251       END IF;
3252 
3253       gme_common_pvt.set_timestamp;
3254 
3255       l_trans_date := p_trans_date;
3256 
3257       IF l_trans_date IS NULL THEN
3258          l_trans_date := gme_common_pvt.g_timestamp;
3259       END IF;
3260 
3261       -- does backflush resource usage need to be performed?
3262       IF (p_batch_header_rec.batch_status = gme_common_pvt.g_step_wip AND
3263            p_material_detail_rec.line_type = gme_common_pvt.g_line_type_prod AND
3264            gme_common_pvt.g_backflush_rsrc_usg_ind = 1) THEN
3265         l_backflush_rsrc_usg_ind := 1;
3266       ELSE
3267         l_backflush_rsrc_usg_ind := 0;
3268       END IF;
3269 
3270       gme_incremental_backflush_pvt.incremental_backflush
3271                         (p_batch_header_rec            => p_batch_header_rec
3272                         ,p_material_detail_rec         => p_material_detail_rec
3273                         ,p_qty                         => p_qty
3274                         ,p_qty_type                    => p_qty_type
3275                         ,p_trans_date                  => l_trans_date
3276                         ,p_backflush_rsrc_usg_ind      => l_backflush_rsrc_usg_ind
3277                         ,x_exception_material_tbl      => x_exception_material_tbl
3278                         ,x_return_status               => x_return_status);
3279 
3280       IF x_return_status NOT IN
3281                  (fnd_api.g_ret_sts_success, gme_common_pvt.g_exceptions_err) THEN
3282          IF ( NVL(G_DEBUG,-1) = GME_DEBUG.G_LOG_STATEMENT ) THEN
3283            gme_debug.put_line (g_pkg_name||'.'||l_api_name||' after gme_incremental_backflush_pvt.incremental_backflush; x_return_status= '||x_return_status);
3284          END IF;
3285          RAISE incremental_backflush_failed;
3286       END IF;    /* IF x_return_status NOT IN */
3287 
3288      /*Bug#5277982 if there are any exceptions then we give message saying IB done with exceptions*/
3289       IF x_exception_material_tbl.COUNT > 0  THEN
3290        gme_common_pvt.log_message('GME_IB_EXCEPTIONS');
3291       ELSE
3292        gme_common_pvt.log_message ('GME_API_PARTIAL_CERTIFIED');
3293       END IF;
3294 
3295       IF (g_debug <= gme_debug.g_log_procedure) THEN
3296          gme_debug.put_line (   'gme_api_main: Completed '
3297                              || l_api_name
3298                              || ' at '
3299                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
3300       END IF;
3301 
3302       gme_common_pvt.count_and_get (x_count        => x_message_count
3303                                    ,p_encoded      => fnd_api.g_false
3304                                    ,x_data         => x_message_list);
3305    EXCEPTION
3306       WHEN setup_failure THEN
3307          ROLLBACK TO SAVEPOINT incremental_backflush;
3308          x_return_status := fnd_api.g_ret_sts_error;
3309          gme_common_pvt.count_and_get (x_count        => x_message_count
3310                                       ,p_encoded      => fnd_api.g_false
3311                                       ,x_data         => x_message_list);
3312       WHEN incremental_backflush_failed THEN
3313          ROLLBACK TO SAVEPOINT incremental_backflush;
3314          gme_common_pvt.count_and_get (x_count        => x_message_count
3315                                       ,p_encoded      => fnd_api.g_false
3316                                       ,x_data         => x_message_list);
3317          IF ( NVL(G_DEBUG,-1) = GME_DEBUG.G_LOG_STATEMENT ) THEN
3321          ROLLBACK TO SAVEPOINT incremental_backflush;
3318            gme_debug.put_line (g_pkg_name||'.'||l_api_name||' in exception block; x_return_status= '||x_return_status);
3319          END IF;
3320       WHEN OTHERS THEN
3322          fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
3323          gme_common_pvt.count_and_get (x_count        => x_message_count
3324                                       ,p_encoded      => fnd_api.g_false
3325                                       ,x_data         => x_message_list);
3326          x_return_status := fnd_api.g_ret_sts_unexp_error;
3327    END incremental_backflush;
3328 
3329     /*================================================================================
3330      Procedure
3331        reroute_batch
3332      Description
3333        This procedure reroutes batch (typically change the route associated with the batch).
3334 
3335      Parameters
3336        p_batch_header_rec (R)    The batch header row to identify the batch
3337                                  Following columns are used from this row.
3338                                  batch_id  (R)
3339        p_validity_rule_id (R)    Recipe validity rule id for the new recipe.
3340 
3341        x_batch_header_rec        The batch header that is returned, with all the data
3342        x_return_status           outcome of the API call
3343                                  S - Success
3344                                  E - Error
3345                                  U - Unexpected Error
3346                                  C - No continous periods found
3347    ================================================================================*/
3348    PROCEDURE reroute_batch (
3349       p_validation_level      IN              NUMBER
3350             := gme_common_pvt.g_max_errors
3351      ,p_init_msg_list         IN              VARCHAR2 DEFAULT fnd_api.g_false
3352      ,p_batch_header_rec      IN              gme_batch_header%ROWTYPE
3353      ,p_validity_rule_id      IN              NUMBER
3354      ,p_use_workday_cal       IN              VARCHAR2 DEFAULT fnd_api.g_false
3355      ,p_contiguity_override   IN              VARCHAR2 DEFAULT fnd_api.g_false
3356      ,x_message_count         OUT NOCOPY      NUMBER
3357      ,x_message_list          OUT NOCOPY      VARCHAR2
3358      ,x_return_status         OUT NOCOPY      VARCHAR2
3359      ,x_batch_header_rec      OUT NOCOPY      gme_batch_header%ROWTYPE)
3360    IS
3361       l_api_name    CONSTANT VARCHAR2 (30) := 'REROUTE_BATCH';
3362       no_continous_periods   EXCEPTION;
3363       setup_failure          EXCEPTION;
3364    BEGIN
3365       /* Set savepoint here */
3366       SAVEPOINT reroute_batch_main;
3367 
3368       IF (g_debug IS NOT NULL) THEN
3369          gme_debug.log_initialize ('RerouteBatch');
3370       END IF;
3371 
3372       IF (NVL (g_debug, 0) IN
3373                        (gme_debug.g_log_statement, gme_debug.g_log_procedure) ) THEN
3374          gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
3375                              || 'Entering');
3376       END IF;
3377 
3378       IF (fnd_api.to_boolean (p_init_msg_list) ) THEN
3379          fnd_msg_pub.initialize;
3380          gme_common_pvt.g_error_count := 0;
3381       END IF;
3382 
3383       /* Set the return status to success initially */
3384       x_return_status := fnd_api.g_ret_sts_success;
3385 
3386       IF NOT gme_common_pvt.g_setup_done THEN
3387          gme_common_pvt.g_setup_done :=
3388                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
3389 
3390          IF NOT gme_common_pvt.g_setup_done THEN
3391             x_return_status := fnd_api.g_ret_sts_error;
3392             RAISE setup_failure;
3393          END IF;
3394       END IF;
3395 
3396       gme_common_pvt.set_timestamp;
3397       gme_reroute_batch_pvt.reroute_batch
3398                               (p_batch_header_rec         => p_batch_header_rec
3399                               ,p_validity_rule_id         => p_validity_rule_id
3400                               ,p_use_workday_cal          => p_use_workday_cal
3401                               ,p_contiguity_override      => p_contiguity_override
3402                               ,x_return_status            => x_return_status
3403                               ,x_batch_header_rec         => x_batch_header_rec);
3404 
3405       IF (x_return_status = 'C') THEN
3406          RAISE no_continous_periods;
3407       ELSIF (x_return_status = fnd_api.g_ret_sts_error) THEN
3408          RAISE fnd_api.g_exc_error;
3409       ELSIF (x_return_status = fnd_api.g_ret_sts_unexp_error) THEN
3410          RAISE fnd_api.g_exc_unexpected_error;
3411       ELSE
3412          --FPBug#5040865 Begin
3413          IF x_batch_header_rec.batch_type = 0 THEN
3414            FND_MESSAGE.SET_NAME('GME','GME_BATCH');
3415          ELSE
3416            FND_MESSAGE.SET_NAME('GME','GME_FIRM_PLAN_ORDER');
3417          END IF;
3418          gme_common_pvt.log_message ('GME_API_BATCH_REROUTED','DOC',FND_MESSAGE.GET);
3419         --FPBug#5040865 End
3420       END IF;
3421 
3422       gme_common_pvt.count_and_get (x_count        => x_message_count
3423                                    ,p_encoded      => fnd_api.g_false
3424                                    ,x_data         => x_message_list);
3425 
3426       IF (NVL (g_debug, 0) IN
3427                        (gme_debug.g_log_statement, gme_debug.g_log_procedure) ) THEN
3428          gme_debug.put_line (   g_pkg_name
3429                              || '.'
3430                              || l_api_name
3434       END IF;
3431                              || ':'
3432                              || 'Exiting with '
3433                              || x_return_status);
3435    EXCEPTION
3436       WHEN setup_failure THEN
3437          ROLLBACK TO SAVEPOINT reroute_batch_main;
3438          x_batch_header_rec := NULL;
3439          gme_common_pvt.count_and_get (x_count        => x_message_count
3440                                       ,p_encoded      => fnd_api.g_false
3441                                       ,x_data         => x_message_list);
3442          x_return_status := fnd_api.g_ret_sts_error;
3443       WHEN no_continous_periods THEN
3444          gme_common_pvt.count_and_get (x_count        => x_message_count
3445                                       ,p_encoded      => fnd_api.g_false
3446                                       ,x_data         => x_message_list);
3447       WHEN fnd_api.g_exc_error THEN
3448          ROLLBACK TO SAVEPOINT reroute_batch_main;
3449          x_batch_header_rec := NULL;
3450          x_return_status := fnd_api.g_ret_sts_error;
3451          gme_common_pvt.count_and_get (x_count        => x_message_count
3452                                       ,p_encoded      => fnd_api.g_false
3453                                       ,x_data         => x_message_list);
3454       WHEN fnd_api.g_exc_unexpected_error THEN
3455          ROLLBACK TO SAVEPOINT reroute_batch_main;
3456          x_batch_header_rec := NULL;
3457          x_return_status := fnd_api.g_ret_sts_unexp_error;
3458 
3459          IF (NVL (g_debug, 0) > 0) THEN
3460             gme_debug.put_line (   g_pkg_name
3461                                 || '.'
3462                                 || l_api_name
3463                                 || ':'
3464                                 || 'UNEXPECTED:'
3465                                 || SQLERRM);
3466          END IF;
3467 
3468          gme_common_pvt.count_and_get (x_count        => x_message_count
3469                                       ,p_encoded      => fnd_api.g_false
3470                                       ,x_data         => x_message_list);
3471       WHEN OTHERS THEN
3472          ROLLBACK TO SAVEPOINT reroute_batch_main;
3473          fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
3474          x_batch_header_rec := NULL;
3475          x_return_status := fnd_api.g_ret_sts_unexp_error;
3476 
3477          IF (NVL (g_debug, 0) > 0) THEN
3478             gme_debug.put_line (   g_pkg_name
3479                                 || '.'
3480                                 || l_api_name
3481                                 || ':'
3482                                 || 'OTHERS:'
3483                                 || SQLERRM);
3484          END IF;
3485 
3486          gme_common_pvt.count_and_get (x_count        => x_message_count
3487                                       ,p_encoded      => fnd_api.g_false
3488                                       ,x_data         => x_message_list);
3489    END reroute_batch;
3490 
3491    /*================================================================================
3492      Procedure
3493        cancel_batch
3494      Description
3495        This procedure cancels batch and all the phantom batches.
3496         It also cancels all the steps.
3497 
3498      Parameters
3499        p_batch_header (R)        The batch header row to identify the batch
3500                                  Following columns are used from this row.
3501                                  batch_id  (R)
3502        x_batch_header            The batch header that is returned, with all the data
3503        x_return_status           outcome of the API call
3504                                  S - Success
3505                                  E - Error
3506                                  U - Unexpected Error
3507    ================================================================================*/
3508    PROCEDURE cancel_batch (
3509       p_validation_level   IN              NUMBER
3510             := gme_common_pvt.g_max_errors
3511      ,p_init_msg_list      IN              VARCHAR2 := fnd_api.g_false
3512      ,x_message_count      OUT NOCOPY      NUMBER
3513      ,x_message_list       OUT NOCOPY      VARCHAR2
3514      ,x_return_status      OUT NOCOPY      VARCHAR2
3515      ,p_batch_header_rec   IN              gme_batch_header%ROWTYPE
3516      ,x_batch_header_rec   OUT NOCOPY      gme_batch_header%ROWTYPE)
3517    IS
3518       l_api_name    CONSTANT VARCHAR2 (30) := 'CANCEL_BATCH';
3519       setup_failure          EXCEPTION;
3520       batch_cancel_failure   EXCEPTION;
3521    BEGIN
3522       SAVEPOINT cancel_batch;
3523 
3524       IF (g_debug IS NOT NULL) THEN
3525          gme_debug.log_initialize ('CancelBatch');
3526       END IF;
3527 
3528       IF g_debug <= gme_debug.g_log_procedure THEN
3529          gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
3530                              || 'Entering');
3531       END IF;
3532 
3533       /* Set the return status to success initially */
3534       x_return_status := fnd_api.g_ret_sts_success;
3535 
3536       IF NOT gme_common_pvt.g_setup_done THEN
3537          gme_common_pvt.g_setup_done :=
3538                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
3539 
3540          IF NOT gme_common_pvt.g_setup_done THEN
3541             x_return_status := fnd_api.g_ret_sts_error;
3542             RAISE setup_failure;
3543          END IF;
3544       END IF;
3545 
3546       -- Initialize message list and count if needed
3550       END IF;
3547       IF p_init_msg_list = fnd_api.g_true THEN
3548          fnd_msg_pub.initialize;
3549          gme_common_pvt.g_error_count := 0;
3551 
3552       gme_common_pvt.set_timestamp;
3553 
3554       IF g_debug <= gme_debug.g_log_statement THEN
3555          gme_debug.put_line (   g_pkg_name
3556                              || '.'
3557                              || l_api_name
3558                              || ':'
3559                              || 'calling pvt cancel');
3560       END IF;
3561 
3562       gme_cancel_batch_pvt.cancel_batch
3563                                     (p_batch_header_rec      => p_batch_header_rec
3564                                     ,x_batch_header_rec      => x_batch_header_rec
3565                                     ,x_return_status         => x_return_status);
3566 
3567       IF (g_debug <= gme_debug.g_log_procedure) THEN
3568          gme_debug.put_line (   g_pkg_name
3569                              || '.'
3570                              || l_api_name
3571                              || ':'
3572                              || 'x_return_status='
3573                              || x_return_status);
3574       END IF;
3575 
3576       IF x_return_status <> fnd_api.g_ret_sts_success THEN
3577          RAISE batch_cancel_failure;
3578       END IF;            /* IF x_return_status <> FND_API.G_RET_STS_SUCCESS */
3579 
3580       --FPBug#5040865 Begin
3581       IF x_batch_header_rec.batch_type = 0 THEN
3582        FND_MESSAGE.SET_NAME('GME','GME_BATCH');
3583       ELSE
3584        FND_MESSAGE.SET_NAME('GME','GME_FIRM_PLAN_ORDER');
3585       END IF;
3586       gme_common_pvt.log_message ('GME_API_BATCH_CANCELLED','DOC',FND_MESSAGE.GET);
3587       --FPBug#5040865 End
3588 
3589       gme_common_pvt.count_and_get (x_count        => x_message_count
3590                                    ,p_encoded      => fnd_api.g_false
3591                                    ,x_data         => x_message_list);
3592 
3593       IF (g_debug IS NOT NULL) THEN
3594          gme_debug.put_line (   'Completed '
3595                              || l_api_name
3596                              || ' at '
3597                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
3598       END IF;
3599 
3600       IF g_debug <= gme_debug.g_log_procedure THEN
3601          gme_debug.put_line (   'Exiting api '
3602                              || g_pkg_name
3603                              || '.'
3604                              || l_api_name
3605                              || x_return_status);
3606       END IF;
3607    EXCEPTION
3608       WHEN batch_cancel_failure THEN
3609          ROLLBACK TO SAVEPOINT cancel_batch;
3610          x_batch_header_rec := NULL;
3611          gme_common_pvt.count_and_get (x_count        => x_message_count
3612                                       ,p_encoded      => fnd_api.g_false
3613                                       ,x_data         => x_message_list);
3614       WHEN setup_failure THEN
3615          ROLLBACK TO SAVEPOINT cancel_batch;
3616          x_batch_header_rec := NULL;
3617          gme_common_pvt.count_and_get (x_count        => x_message_count
3618                                       ,p_encoded      => fnd_api.g_false
3619                                       ,x_data         => x_message_list);
3620          x_return_status := fnd_api.g_ret_sts_error;
3621       WHEN OTHERS THEN
3622          IF g_debug <= gme_debug.g_log_unexpected THEN
3623             gme_debug.put_line (   'When others exception in '
3624                                 || g_pkg_name
3625                                 || '.'
3626                                 || l_api_name
3627                                 || ' Error is '
3628                                 || SQLERRM);
3629          END IF;
3630 
3631          ROLLBACK TO SAVEPOINT cancel_batch;
3632          x_batch_header_rec := NULL;
3633          gme_common_pvt.count_and_get (x_count        => x_message_count
3634                                       ,p_encoded      => fnd_api.g_false
3635                                       ,x_data         => x_message_list);
3636          x_return_status := fnd_api.g_ret_sts_unexp_error;
3637    END cancel_batch;
3638 
3639     /*================================================================================
3640      Procedure
3641        terminate_batch
3642 
3643      Description
3644        This procedure terminates batch and all the phantom batches.
3645         It also terminates all the steps.
3646 
3647      Parameters
3648        p_batch_header (R)        The batch header row to identify the batch
3649                                  Following columns are used from this row.
3650                                  batch_id  (R)
3651        p_reason_name             Reason to terminate the batch
3652        x_batch_header            The batch header that is returned, with all the data
3653        x_return_status           outcome of the API call
3654                                  S - Success
3655                                  E - Error
3656                                  U - Unexpected Error
3657    ================================================================================*/
3658    PROCEDURE terminate_batch (
3659       p_validation_level   IN              NUMBER
3660             := gme_common_pvt.g_max_errors
3661      ,p_init_msg_list      IN              VARCHAR2 := fnd_api.g_false
3662      ,x_message_count      OUT NOCOPY      NUMBER
3663      ,x_message_list       OUT NOCOPY      VARCHAR2
3664      ,x_return_status      OUT NOCOPY      VARCHAR2
3668       l_api_name       CONSTANT VARCHAR2 (30) := 'TERMINATE_BATCH';
3665      ,p_batch_header_rec   IN              gme_batch_header%ROWTYPE
3666      ,x_batch_header_rec   OUT NOCOPY      gme_batch_header%ROWTYPE)
3667    IS
3669       setup_failure             EXCEPTION;
3670       batch_terminate_failure   EXCEPTION;
3671    BEGIN
3672       /* Set the save point before processing */
3673       SAVEPOINT terminate_batch;
3674 
3675       IF (g_debug IS NOT NULL) THEN
3676          gme_debug.log_initialize ('TerminateBatch');
3677       END IF;
3678 
3679       IF (g_debug <= gme_debug.g_log_procedure) THEN
3680          gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
3681                              || 'Entering');
3682       END IF;
3683 
3684       /* Set the return status to success initially */
3685       x_return_status := fnd_api.g_ret_sts_success;
3686 
3687       IF NOT gme_common_pvt.g_setup_done THEN
3688          gme_common_pvt.g_setup_done :=
3689                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
3690 
3691          IF NOT gme_common_pvt.g_setup_done THEN
3692             x_return_status := fnd_api.g_ret_sts_error;
3693             RAISE setup_failure;
3694          END IF;
3695       END IF;
3696 
3697       -- Initialize message list and count if needed
3698       IF p_init_msg_list = fnd_api.g_true THEN
3699          fnd_msg_pub.initialize;
3700          gme_common_pvt.g_error_count := 0;
3701       END IF;
3702 
3703       gme_common_pvt.set_timestamp;
3704 
3705       IF g_debug <= gme_debug.g_log_statement THEN
3706          gme_debug.put_line (   g_pkg_name
3707                              || '.'
3708                              || l_api_name
3709                              || ':'
3710                              || 'Call Private Terminate_Batch');
3711       END IF;
3712 
3713       gme_terminate_batch_pvt.terminate_batch
3714                                     (p_batch_header_rec      => p_batch_header_rec
3715                                     ,x_batch_header_rec      => x_batch_header_rec
3716                                     ,x_return_status         => x_return_status);
3717 
3718       IF (g_debug <= gme_debug.g_log_procedure) THEN
3719          gme_debug.put_line (   g_pkg_name
3720                              || '.'
3721                              || l_api_name
3722                              || ':'
3723                              || 'x_return_status='
3724                              || x_return_status);
3725       END IF;
3726 
3727       IF x_return_status <> fnd_api.g_ret_sts_success THEN
3728          RAISE batch_terminate_failure;
3729       END IF;            /* IF x_return_status <> FND_API.G_RET_STS_SUCCESS */
3730 
3731          gme_common_pvt.log_message ('GME_API_BATCH_TERMINATED');
3732 
3733 
3734       gme_common_pvt.count_and_get (x_count        => x_message_count
3735                                    ,p_encoded      => fnd_api.g_false
3736                                    ,x_data         => x_message_list);
3737 
3738       IF (g_debug IS NOT NULL) THEN
3739          gme_debug.put_line (   'Completed '
3740                              || l_api_name
3741                              || ' at '
3742                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
3743       END IF;
3744 
3745       IF g_debug <= gme_debug.g_log_procedure THEN
3746          gme_debug.put_line (   g_pkg_name
3747                              || '.'
3748                              || l_api_name
3749                              || ':'
3750                              || 'Exiting api with return status='
3751                              || x_return_status);
3752       END IF;
3753    EXCEPTION
3754       WHEN setup_failure THEN
3755          ROLLBACK TO SAVEPOINT terminate_batch;
3756          x_batch_header_rec := NULL;
3757 
3758          IF (g_debug <= gme_debug.g_log_procedure) THEN
3759             gme_debug.put_line (   g_pkg_name
3760                                 || '.'
3761                                 || l_api_name
3762                                 || ':'
3763                                 || 'SETUP_FAILURE.');
3764          END IF;
3765 
3766          x_return_status := fnd_api.g_ret_sts_error;
3767          gme_common_pvt.count_and_get (x_count        => x_message_count
3768                                       ,p_encoded      => fnd_api.g_false
3769                                       ,x_data         => x_message_list);
3770       WHEN batch_terminate_failure THEN
3771          ROLLBACK TO SAVEPOINT terminate_batch;
3772          x_batch_header_rec := NULL;
3773 
3774          IF (g_debug <= gme_debug.g_log_procedure) THEN
3775             gme_debug.put_line
3776                              (   g_pkg_name
3777                               || '.'
3778                               || l_api_name
3779                               || ':'
3780                               || 'BATCH_TERMINATE_FAILURE OR BATCH_SAVE_FAILED.');
3781          END IF;
3782 
3783          gme_common_pvt.count_and_get (x_count        => x_message_count
3784                                       ,p_encoded      => fnd_api.g_false
3785                                       ,x_data         => x_message_list);
3786       WHEN OTHERS THEN
3787          ROLLBACK TO SAVEPOINT terminate_batch;
3788          x_batch_header_rec := NULL;
3789 
3790          IF (g_debug <= gme_debug.g_log_unexpected) THEN
3794                                 || l_api_name
3791             gme_debug.put_line (   'When others exception in '
3792                                 || g_pkg_name
3793                                 || '.'
3795                                 || ' Error is '
3796                                 || SQLERRM);
3797          END IF;
3798 
3799          fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
3800          gme_common_pvt.count_and_get (x_count        => x_message_count
3801                                       ,p_encoded      => fnd_api.g_false
3802                                       ,x_data         => x_message_list);
3803          x_return_status := fnd_api.g_ret_sts_unexp_error;
3804    END terminate_batch;
3805 
3806 /*************************************************************************/
3807    PROCEDURE unrelease_batch (
3808       p_validation_level        IN              NUMBER
3809             := gme_common_pvt.g_max_errors
3810      ,p_init_msg_list           IN              VARCHAR2 := fnd_api.g_false
3811      ,x_message_count           OUT NOCOPY      NUMBER
3812      ,x_message_list            OUT NOCOPY      VARCHAR2
3813      ,x_return_status           OUT NOCOPY      VARCHAR2
3814      ,p_batch_header_rec        IN              gme_batch_header%ROWTYPE
3815      ,x_batch_header_rec        OUT NOCOPY      gme_batch_header%ROWTYPE
3816      ,p_create_resv_pend_lots   IN              NUMBER)
3817    IS
3818       l_api_name       CONSTANT VARCHAR2 (30) := 'UNRELEASE_BATCH';
3819       setup_failure             EXCEPTION;
3820       batch_unrelease_failure   EXCEPTION;
3821    BEGIN
3822       IF g_debug <= gme_debug.g_log_procedure THEN
3823          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
3824                              || l_api_name);
3825       END IF;
3826 
3827       SAVEPOINT unrelease_batch;
3828 
3829       IF (g_debug IS NOT NULL) THEN
3830          gme_debug.log_initialize ('UnreleaseBatch');
3831       END IF;
3832 
3833       IF NOT gme_common_pvt.g_setup_done THEN
3834          gme_common_pvt.g_setup_done :=
3835                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
3836 
3837          IF NOT gme_common_pvt.g_setup_done THEN
3838             x_return_status := fnd_api.g_ret_sts_error;
3839             RAISE setup_failure;
3840          END IF;
3841       END IF;
3842 
3843       /* Set the return status to success initially */
3844       x_return_status := fnd_api.g_ret_sts_success;
3845 
3846       -- Initialize message list and count if needed
3847       IF p_init_msg_list = fnd_api.g_true THEN
3848          fnd_msg_pub.initialize;
3849          gme_common_pvt.g_error_count := 0;
3850       END IF;
3851 
3852       gme_common_pvt.set_timestamp;
3853       gme_common_pvt.reset_txn_hdr_tbl; -- nsinghi bug#5176319
3854       gme_unrelease_batch_pvt.unrelease_batch
3855                           (p_batch_header_rec           => p_batch_header_rec
3856                           ,p_create_resv_pend_lots      => p_create_resv_pend_lots
3857                           ,x_batch_header_rec           => x_batch_header_rec
3858                           ,x_return_status              => x_return_status);
3859 
3860       IF x_return_status <> fnd_api.g_ret_sts_success THEN
3861          RAISE batch_unrelease_failure;
3862       END IF;            /* IF x_return_status <> FND_API.G_RET_STS_SUCCESS */
3863 
3864          gme_common_pvt.log_message ('GME_API_BATCH_UNRELEASED');
3865 
3866       gme_common_pvt.count_and_get (x_count        => x_message_count
3867                                    ,p_encoded      => fnd_api.g_false
3868                                    ,x_data         => x_message_list);
3869 
3870       IF (g_debug IS NOT NULL) THEN
3871          gme_debug.put_line (   'Completed '
3872                              || l_api_name
3873                              || ' at '
3874                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
3875       END IF;
3876 
3877       IF g_debug <= gme_debug.g_log_procedure THEN
3878          gme_debug.put_line ('Exiting api ' || g_pkg_name || '.' || l_api_name);
3879       END IF;
3880    EXCEPTION
3881       WHEN batch_unrelease_failure THEN
3882          ROLLBACK TO SAVEPOINT unrelease_batch;
3883          x_batch_header_rec := NULL;
3884          gme_common_pvt.count_and_get (x_count        => x_message_count
3885                                       ,p_encoded      => fnd_api.g_false
3886                                       ,x_data         => x_message_list);
3887       WHEN setup_failure THEN
3888          ROLLBACK TO SAVEPOINT unrelease_batch;
3889          x_batch_header_rec := NULL;
3890          gme_common_pvt.count_and_get (x_count        => x_message_count
3891                                       ,p_encoded      => fnd_api.g_false
3892                                       ,x_data         => x_message_list);
3893          x_return_status := fnd_api.g_ret_sts_error;
3894       WHEN OTHERS THEN
3895          IF g_debug <= gme_debug.g_log_unexpected THEN
3896             gme_debug.put_line (   'When others exception in '
3897                                 || g_pkg_name
3898                                 || '.'
3899                                 || l_api_name
3900                                 || ' Error is '
3901                                 || SQLERRM);
3902          END IF;
3903 
3904          ROLLBACK TO SAVEPOINT unrelease_batch;
3905          x_batch_header_rec := NULL;
3906          gme_common_pvt.count_and_get (x_count        => x_message_count
3910    END unrelease_batch;
3907                                       ,p_encoded      => fnd_api.g_false
3908                                       ,x_data         => x_message_list);
3909          x_return_status := fnd_api.g_ret_sts_unexp_error;
3911 
3912 /*************************************************************************/
3913    PROCEDURE unrelease_step (
3914       p_validation_level        IN              NUMBER
3915             := gme_common_pvt.g_max_errors
3916      ,p_init_msg_list           IN              VARCHAR2 := fnd_api.g_false
3917      ,x_message_count           OUT NOCOPY      NUMBER
3918      ,x_message_list            OUT NOCOPY      VARCHAR2
3919      ,x_return_status           OUT NOCOPY      VARCHAR2
3920      ,p_batch_step_rec          IN              gme_batch_steps%ROWTYPE
3921      ,p_batch_header_rec        IN              gme_batch_header%ROWTYPE
3922      ,x_batch_step_rec          OUT NOCOPY      gme_batch_steps%ROWTYPE
3923      ,p_create_resv_pend_lots   IN              NUMBER)
3924    IS
3925       l_api_name      CONSTANT VARCHAR2 (30) := 'UNRELEASE_STEP';
3926       setup_failure            EXCEPTION;
3927       step_unrelease_failure   EXCEPTION;
3928    BEGIN
3929       IF g_debug <= gme_debug.g_log_procedure THEN
3930          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
3931                              || l_api_name);
3932       END IF;
3933 
3934       SAVEPOINT unrelease_step;
3935 
3936       IF (g_debug IS NOT NULL) THEN
3937          gme_debug.log_initialize ('UnreleaseStep');
3938       END IF;
3939 
3940       IF NOT gme_common_pvt.g_setup_done THEN
3941          gme_common_pvt.g_setup_done :=
3942                     gme_common_pvt.setup (p_batch_header_rec.organization_id);
3943 
3944          IF NOT gme_common_pvt.g_setup_done THEN
3945             x_return_status := fnd_api.g_ret_sts_error;
3946             RAISE setup_failure;
3947          END IF;
3948       END IF;
3949 
3950       /* Set the return status to success initially */
3951       x_return_status := fnd_api.g_ret_sts_success;
3952 
3953       -- Initialize message list and count if needed
3954       IF p_init_msg_list = fnd_api.g_true THEN
3955          fnd_msg_pub.initialize;
3956          gme_common_pvt.g_error_count := 0;
3957       END IF;
3958 
3959       gme_common_pvt.set_timestamp;
3960       gme_common_pvt.reset_txn_hdr_tbl; -- nsinghi bug#5176319
3961       gme_unrelease_step_pvt.unrelease_step
3962            (p_batch_step_rec             => p_batch_step_rec
3963            ,p_update_inventory_ind       => p_batch_header_rec.update_inventory_ind
3964            ,p_create_resv_pend_lots      => p_create_resv_pend_lots
3965            ,p_from_unrelease_batch       => 0
3966            ,x_batch_step_rec             => x_batch_step_rec
3967            ,x_return_status              => x_return_status);
3968 
3969       IF x_return_status <> fnd_api.g_ret_sts_success THEN
3970          RAISE step_unrelease_failure;
3971       END IF;            /* IF x_return_status <> FND_API.G_RET_STS_SUCCESS */
3972 
3973 
3974          gme_common_pvt.log_message ('GME_BATCH_STEP_UNRELEASED');
3975 
3976       gme_common_pvt.count_and_get (x_count        => x_message_count
3977                                    ,p_encoded      => fnd_api.g_false
3978                                    ,x_data         => x_message_list);
3979 
3980       IF (g_debug IS NOT NULL) THEN
3981          gme_debug.put_line (   'Completed '
3982                              || l_api_name
3983                              || ' at '
3984                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
3985       END IF;
3986 
3987       IF g_debug <= gme_debug.g_log_procedure THEN
3988          gme_debug.put_line ('Exiting api ' || g_pkg_name || '.' || l_api_name);
3989       END IF;
3990    EXCEPTION
3991       WHEN step_unrelease_failure THEN
3992          ROLLBACK TO SAVEPOINT unrelease_step;
3993          x_batch_step_rec := NULL;
3994          gme_common_pvt.count_and_get (x_count        => x_message_count
3995                                       ,p_encoded      => fnd_api.g_false
3996                                       ,x_data         => x_message_list);
3997       WHEN setup_failure THEN
3998          ROLLBACK TO SAVEPOINT unrelease_step;
3999          x_batch_step_rec := NULL;
4000          gme_common_pvt.count_and_get (x_count        => x_message_count
4001                                       ,p_encoded      => fnd_api.g_false
4002                                       ,x_data         => x_message_list);
4003          x_return_status := fnd_api.g_ret_sts_error;
4004       WHEN OTHERS THEN
4005          IF g_debug <= gme_debug.g_log_unexpected THEN
4006             gme_debug.put_line (   'When others exception in '
4007                                 || g_pkg_name
4008                                 || '.'
4009                                 || l_api_name
4010                                 || ' Error is '
4011                                 || SQLERRM);
4012          END IF;
4013 
4014          ROLLBACK TO SAVEPOINT unrelease_step;
4015          x_batch_step_rec := NULL;
4016          gme_common_pvt.count_and_get (x_count        => x_message_count
4017                                       ,p_encoded      => fnd_api.g_false
4018                                       ,x_data         => x_message_list);
4019          x_return_status := fnd_api.g_ret_sts_unexp_error;
4020    END unrelease_step;
4021 
4022 /*************************************************************************/
4023    PROCEDURE auto_detail_line (
4027      ,x_return_status         OUT NOCOPY      VARCHAR2
4024       p_init_msg_list         IN              VARCHAR2 := fnd_api.g_false
4025      ,x_message_count         OUT NOCOPY      NUMBER
4026      ,x_message_list          OUT NOCOPY      VARCHAR2
4028      ,p_material_detail_rec   IN              gme_material_details%ROWTYPE)
4029    IS
4030       l_api_name   CONSTANT VARCHAR2 (30) := 'AUTO_DETAIL_LINE';
4031       setup_failure         EXCEPTION;
4032       auto_detail_failure   EXCEPTION;
4033    BEGIN
4034       /* Set the save point initially */
4035       SAVEPOINT auto_detail_line;
4036 
4037       IF (g_debug IS NOT NULL) THEN
4038          gme_debug.log_initialize ('AutoDetailLine');
4039       END IF;
4040 
4041       IF g_debug <= gme_debug.g_log_procedure THEN
4042          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
4043                              || l_api_name);
4044       END IF;
4045 
4046       IF NOT gme_common_pvt.g_setup_done THEN
4047          gme_common_pvt.g_setup_done :=
4048                  gme_common_pvt.setup (p_material_detail_rec.organization_id);
4049 
4050          IF NOT gme_common_pvt.g_setup_done THEN
4051             x_return_status := fnd_api.g_ret_sts_error;
4052             RAISE setup_failure;
4053          END IF;
4054       END IF;
4055 
4056       -- Initialize message list and count if needed
4057       IF p_init_msg_list = fnd_api.g_true THEN
4058          fnd_msg_pub.initialize;
4059          gme_common_pvt.g_error_count := 0;
4060       END IF;
4061 
4062       /* Set the return status to success initially */
4063       x_return_status := fnd_api.g_ret_sts_success;
4064       /* Set the timestamp  */
4065       gme_common_pvt.set_timestamp;
4066       gme_reservations_pvt.auto_detail_line
4067                              (p_material_details_rec      => p_material_detail_rec
4068                              ,x_return_status             => x_return_status);
4069 
4070       IF x_return_status <> fnd_api.g_ret_sts_success THEN
4071          RAISE auto_detail_failure;
4072       END IF;
4073 
4074        gme_common_pvt.log_message ('GME_BATCH_AUTO_DETAIL_LINE');
4075 
4076       IF (g_debug <= gme_debug.g_log_procedure) THEN
4077          gme_debug.put_line (   'Completed '
4078                              || l_api_name
4079                              || ' at '
4080                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
4081       END IF;
4082    EXCEPTION
4083       WHEN auto_detail_failure OR setup_failure THEN
4084          ROLLBACK TO SAVEPOINT auto_detail_line;
4085          gme_common_pvt.count_and_get (x_count        => x_message_count
4086                                       ,p_encoded      => fnd_api.g_false
4087                                       ,x_data         => x_message_list);
4088       WHEN OTHERS THEN
4089          IF g_debug <= gme_debug.g_log_unexpected THEN
4090             gme_debug.put_line (   'When others exception in '
4091                                 || g_pkg_name
4092                                 || '.'
4093                                 || l_api_name
4094                                 || ' Error is '
4095                                 || SQLERRM);
4096          END IF;
4097 
4098          ROLLBACK TO SAVEPOINT auto_detail_line;
4099          fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
4100          gme_common_pvt.count_and_get (x_count        => x_message_count
4101                                       ,p_encoded      => fnd_api.g_false
4102                                       ,x_data         => x_message_list);
4103          x_return_status := fnd_api.g_ret_sts_unexp_error;
4104    END auto_detail_line;
4105    /*************************************************************************/
4106    PROCEDURE auto_detail_batch(
4107       p_init_msg_list            IN              VARCHAR2 := FND_API.G_FALSE,
4108       x_message_count            OUT NOCOPY      NUMBER,
4109       x_message_list             OUT NOCOPY      VARCHAR2,
4110       x_return_status            OUT NOCOPY      VARCHAR2,
4111       p_batch_rec                IN              gme_batch_header%ROWTYPE) IS
4112 
4113       l_api_name        CONSTANT VARCHAR2 (30)   := 'AUTO_DETAIL_BATCH';
4114 
4115 
4116       setup_failure              EXCEPTION;
4117       auto_detail_failure        EXCEPTION;
4118    BEGIN
4119       /* Set the save point initially */
4120       SAVEPOINT auto_detail_batch;
4121 
4122       IF (g_debug IS NOT NULL) THEN
4123          gme_debug.log_initialize ('AutoDetailBatch');
4124       END IF;
4125 
4126       IF g_debug <= gme_debug.g_log_procedure THEN
4127          gme_debug.put_line ('Entering api ' || g_pkg_name || '.' || l_api_name);
4128       END IF;
4129 
4130       IF NOT gme_common_pvt.g_setup_done THEN
4131          gme_common_pvt.g_setup_done :=
4132                  gme_common_pvt.setup (p_batch_rec.organization_id);
4133 
4134          IF NOT gme_common_pvt.g_setup_done THEN
4135             x_return_status := fnd_api.g_ret_sts_error;
4136             RAISE setup_failure;
4137          END IF;
4138       END IF;
4139 
4140       -- Initialize message list and count if needed
4141       IF p_init_msg_list = fnd_api.g_true THEN
4142          fnd_msg_pub.initialize;
4143          gme_common_pvt.g_error_count := 0;
4144       END IF;
4145 
4146       /* Set the return status to success initially */
4147       x_return_status := fnd_api.g_ret_sts_success;
4148 
4149       /* Set the timestamp  */
4153                                             ,x_return_status => x_return_status);
4150       gme_common_pvt.set_timestamp;
4151 
4152       gme_reservations_pvt.auto_detail_batch(p_batch_rec => p_batch_rec
4154 
4155       IF x_return_status <> fnd_api.g_ret_sts_success THEN
4156          RAISE auto_detail_failure;
4157       END IF;
4158       gme_common_pvt.log_message ('GME_BATCH_AUTO_DETAIL_BATCH');
4159       IF (g_debug <= gme_debug.g_log_procedure) THEN
4160          gme_debug.put_line (   'Completed '
4161                              || l_api_name
4162                              || ' at '
4163                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
4164       END IF;
4165    EXCEPTION
4166       WHEN auto_detail_failure OR setup_failure THEN
4167          ROLLBACK TO SAVEPOINT auto_detail_batch;
4168          gme_common_pvt.count_and_get (x_count        => x_message_count,
4169                                        p_encoded      => fnd_api.g_false,
4170                                        x_data         => x_message_list);
4171       WHEN OTHERS THEN
4172          IF g_debug <= gme_debug.g_log_unexpected THEN
4173             gme_debug.put_line (   'When others exception in '
4174                                 || g_pkg_name
4175                                 || '.'
4176                                 || l_api_name
4177                                 || ' Error is '
4178                                 || SQLERRM);
4179          END IF;
4180 
4181          ROLLBACK TO SAVEPOINT auto_detail_batch;
4182          fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
4183          gme_common_pvt.count_and_get (x_count        => x_message_count,
4184                                        p_encoded      => fnd_api.g_false,
4185                                        x_data         => x_message_list);
4186          x_return_status := fnd_api.g_ret_sts_unexp_error;
4187    END auto_detail_batch;
4188 
4189 /*************************************************************************/
4190    PROCEDURE create_pending_product_lot (
4191       p_validation_level        IN              NUMBER
4192             := gme_common_pvt.g_max_errors
4193      ,p_init_msg_list           IN              VARCHAR2 := fnd_api.g_false
4194      ,x_message_count           OUT NOCOPY      NUMBER
4195      ,x_message_list            OUT NOCOPY      VARCHAR2
4196      ,x_return_status           OUT NOCOPY      VARCHAR2
4197      ,p_org_id                  IN              NUMBER
4198      ,p_pending_product_lots_rec IN  gme_pending_product_lots%ROWTYPE
4199      ,x_pending_product_lots_rec OUT NOCOPY  gme_pending_product_lots%ROWTYPE)
4200    IS
4201       l_api_name       CONSTANT VARCHAR2 (30) := 'create_pending_product_lot';
4202       setup_failure             EXCEPTION;
4203       create_pp_lot_failure     EXCEPTION;
4204    BEGIN
4205       IF g_debug <= gme_debug.g_log_procedure THEN
4206          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
4207                              || l_api_name);
4208       END IF;
4209 
4210       SAVEPOINT create_pp_lot;
4211 
4212       IF (g_debug IS NOT NULL) THEN
4213          gme_debug.log_initialize ('CreatePendingProdLot');
4214       END IF;
4215 
4216       IF NOT gme_common_pvt.g_setup_done THEN
4217          gme_common_pvt.g_setup_done :=
4218                     gme_common_pvt.setup (p_org_id);
4219 
4220          IF NOT gme_common_pvt.g_setup_done THEN
4221             x_return_status := fnd_api.g_ret_sts_error;
4222             RAISE setup_failure;
4223          END IF;
4224       END IF;
4225 
4226       /* Set the return status to success initially */
4227       x_return_status := fnd_api.g_ret_sts_success;
4228 
4229       -- Initialize message list and count if needed
4230       IF p_init_msg_list = fnd_api.g_true THEN
4231          fnd_msg_pub.initialize;
4232          gme_common_pvt.g_error_count := 0;
4233       END IF;
4234 
4235       gme_common_pvt.set_timestamp;
4236       gme_pending_product_lots_pvt.create_pending_product_lot
4237                           (p_pending_product_lots_rec      => p_pending_product_lots_rec
4238                           ,x_pending_product_lots_rec      => x_pending_product_lots_rec
4239                           ,x_return_status                 => x_return_status);
4240 
4241       IF x_return_status <> fnd_api.g_ret_sts_success THEN
4242          RAISE create_pp_lot_failure;
4243       END IF;            /* IF x_return_status <> FND_API.G_RET_STS_SUCCESS */
4244 
4245 
4246       gme_common_pvt.log_message ('GME_API_PP_LOT_CREATED');
4247 
4248       gme_common_pvt.count_and_get (x_count        => x_message_count
4249                                    ,p_encoded      => fnd_api.g_false
4250                                    ,x_data         => x_message_list);
4251 
4252       IF (g_debug IS NOT NULL) THEN
4253          gme_debug.put_line (   'Completed '
4254                              || l_api_name
4255                              || ' at '
4256                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
4257       END IF;
4258 
4259       IF g_debug <= gme_debug.g_log_procedure THEN
4260          gme_debug.put_line ('Exiting api ' || g_pkg_name || '.' || l_api_name);
4261       END IF;
4262    EXCEPTION
4263       WHEN create_pp_lot_failure THEN
4264          ROLLBACK TO SAVEPOINT create_pp_lot;
4265          x_pending_product_lots_rec := NULL;
4266          gme_common_pvt.count_and_get (x_count        => x_message_count
4267                                       ,p_encoded      => fnd_api.g_false
4271          x_pending_product_lots_rec := NULL;
4268                                       ,x_data         => x_message_list);
4269       WHEN setup_failure THEN
4270          ROLLBACK TO SAVEPOINT create_pp_lot;
4272          gme_common_pvt.count_and_get (x_count        => x_message_count
4273                                       ,p_encoded      => fnd_api.g_false
4274                                       ,x_data         => x_message_list);
4275          x_return_status := fnd_api.g_ret_sts_error;
4276       WHEN OTHERS THEN
4277          IF g_debug <= gme_debug.g_log_unexpected THEN
4278             gme_debug.put_line (   'When others exception in '
4279                                 || g_pkg_name
4280                                 || '.'
4281                                 || l_api_name
4282                                 || ' Error is '
4283                                 || SQLERRM);
4284          END IF;
4285 
4286          ROLLBACK TO SAVEPOINT create_pp_lot;
4287          x_pending_product_lots_rec := NULL;
4288          gme_common_pvt.count_and_get (x_count        => x_message_count
4289                                       ,p_encoded      => fnd_api.g_false
4290                                       ,x_data         => x_message_list);
4291          x_return_status := fnd_api.g_ret_sts_unexp_error;
4292    END create_pending_product_lot;
4293 
4294    PROCEDURE update_pending_product_lot (
4295       p_validation_level           IN              NUMBER
4296             := gme_common_pvt.g_max_errors
4297      ,p_init_msg_list              IN              VARCHAR2 := fnd_api.g_false
4298      ,x_message_count              OUT NOCOPY      NUMBER
4299      ,x_message_list               OUT NOCOPY      VARCHAR2
4300      ,x_return_status              OUT NOCOPY      VARCHAR2
4301      ,p_org_id                     IN              NUMBER
4302      ,p_pending_product_lots_rec   IN  gme_pending_product_lots%ROWTYPE
4303      ,x_pending_product_lots_rec   IN  OUT NOCOPY  gme_pending_product_lots%ROWTYPE)
4304    IS
4305       l_api_name       CONSTANT VARCHAR2 (30) := 'update_pending_product_lot';
4306       setup_failure             EXCEPTION;
4307       update_pp_lot_failure     EXCEPTION;
4308    BEGIN
4309       IF g_debug <= gme_debug.g_log_procedure THEN
4310          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
4311                              || l_api_name);
4312       END IF;
4313 
4314       SAVEPOINT update_pp_lot;
4315 
4316       IF (g_debug IS NOT NULL) THEN
4317          gme_debug.log_initialize ('UpdatePendingProdLot');
4318       END IF;
4319 
4320       IF NOT gme_common_pvt.g_setup_done THEN
4321          gme_common_pvt.g_setup_done :=
4322                     gme_common_pvt.setup (p_org_id);
4323 
4324          IF NOT gme_common_pvt.g_setup_done THEN
4325             x_return_status := fnd_api.g_ret_sts_error;
4326             RAISE setup_failure;
4327          END IF;
4328       END IF;
4329 
4330       /* Set the return status to success initially */
4331       x_return_status := fnd_api.g_ret_sts_success;
4332 
4333       -- Initialize message list and count if needed
4334       IF p_init_msg_list = fnd_api.g_true THEN
4335          fnd_msg_pub.initialize;
4336          gme_common_pvt.g_error_count := 0;
4337       END IF;
4338 
4339       gme_common_pvt.set_timestamp;
4340       gme_pending_product_lots_pvt.update_pending_product_lot
4341                           (p_pending_product_lots_rec      => p_pending_product_lots_rec
4342                           ,x_pending_product_lots_rec      => x_pending_product_lots_rec
4343                           ,x_return_status                 => x_return_status);
4344 
4345       IF x_return_status <> fnd_api.g_ret_sts_success THEN
4346          RAISE update_pp_lot_failure;
4347       END IF;            /* IF x_return_status <> FND_API.G_RET_STS_SUCCESS */
4348 
4349 
4350      gme_common_pvt.log_message ('GME_API_PP_LOT_UPDATED');
4351 
4352 
4353       gme_common_pvt.count_and_get (x_count        => x_message_count
4354                                    ,p_encoded      => fnd_api.g_false
4355                                    ,x_data         => x_message_list);
4356 
4357       IF (g_debug IS NOT NULL) THEN
4358          gme_debug.put_line (   'Completed '
4359                              || l_api_name
4360                              || ' at '
4361                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
4362       END IF;
4363 
4364       IF g_debug <= gme_debug.g_log_procedure THEN
4365          gme_debug.put_line ('Exiting api ' || g_pkg_name || '.' || l_api_name);
4366       END IF;
4367    EXCEPTION
4368       WHEN update_pp_lot_failure THEN
4369          ROLLBACK TO SAVEPOINT update_pp_lot;
4370          x_pending_product_lots_rec := NULL;
4371          gme_common_pvt.count_and_get (x_count        => x_message_count
4372                                       ,p_encoded      => fnd_api.g_false
4373                                       ,x_data         => x_message_list);
4374       WHEN setup_failure THEN
4375          ROLLBACK TO SAVEPOINT update_pp_lot;
4376          x_pending_product_lots_rec := NULL;
4377          gme_common_pvt.count_and_get (x_count        => x_message_count
4378                                       ,p_encoded      => fnd_api.g_false
4379                                       ,x_data         => x_message_list);
4380          x_return_status := fnd_api.g_ret_sts_error;
4381       WHEN OTHERS THEN
4382          IF g_debug <= gme_debug.g_log_unexpected THEN
4383             gme_debug.put_line (   'When others exception in '
4384                                 || g_pkg_name
4385                                 || '.'
4386                                 || l_api_name
4387                                 || ' Error is '
4388                                 || SQLERRM);
4389          END IF;
4390 
4391          ROLLBACK TO SAVEPOINT update_pp_lot;
4392          x_pending_product_lots_rec := NULL;
4393          gme_common_pvt.count_and_get (x_count        => x_message_count
4394                                       ,p_encoded      => fnd_api.g_false
4395                                       ,x_data         => x_message_list);
4396          x_return_status := fnd_api.g_ret_sts_unexp_error;
4397    END update_pending_product_lot;
4398 
4399    PROCEDURE delete_pending_product_lot (
4400       p_validation_level           IN              NUMBER
4401             := gme_common_pvt.g_max_errors
4402      ,p_init_msg_list              IN              VARCHAR2 := fnd_api.g_false
4403      ,x_message_count              OUT NOCOPY      NUMBER
4404      ,x_message_list               OUT NOCOPY      VARCHAR2
4405      ,x_return_status              OUT NOCOPY      VARCHAR2
4406      ,p_org_id                     IN              NUMBER
4407      ,p_pending_product_lots_rec   IN  gme_pending_product_lots%ROWTYPE)
4408    IS
4409       l_api_name       CONSTANT VARCHAR2 (30) := 'delete_pending_product_lot';
4410       setup_failure             EXCEPTION;
4411       delete_pp_lot_failure     EXCEPTION;
4412    BEGIN
4413       IF g_debug <= gme_debug.g_log_procedure THEN
4414          gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
4415                              || l_api_name);
4416       END IF;
4417 
4418       SAVEPOINT delete_pp_lot;
4419 
4420       IF (g_debug IS NOT NULL) THEN
4421          gme_debug.log_initialize ('DeletePendingProdLot');
4422       END IF;
4423 
4424       IF NOT gme_common_pvt.g_setup_done THEN
4425          gme_common_pvt.g_setup_done :=
4426                     gme_common_pvt.setup (p_org_id);
4427 
4428          IF NOT gme_common_pvt.g_setup_done THEN
4429             x_return_status := fnd_api.g_ret_sts_error;
4430             RAISE setup_failure;
4431          END IF;
4432       END IF;
4433 
4434       /* Set the return status to success initially */
4435       x_return_status := fnd_api.g_ret_sts_success;
4436 
4437       -- Initialize message list and count if needed
4438       IF p_init_msg_list = fnd_api.g_true THEN
4439          fnd_msg_pub.initialize;
4440          gme_common_pvt.g_error_count := 0;
4441       END IF;
4442 
4443       gme_common_pvt.set_timestamp;
4444       gme_pending_product_lots_pvt.delete_pending_product_lot
4445                           (p_pending_product_lots_rec      => p_pending_product_lots_rec
4446                           ,x_return_status                 => x_return_status);
4447 
4448       IF x_return_status <> fnd_api.g_ret_sts_success THEN
4449          RAISE delete_pp_lot_failure;
4450       END IF;            /* IF x_return_status <> FND_API.G_RET_STS_SUCCESS */
4451 
4452          gme_common_pvt.log_message ('GME_API_PP_LOT_DELETED');
4453 
4454 
4455       gme_common_pvt.count_and_get (x_count        => x_message_count
4456                                    ,p_encoded      => fnd_api.g_false
4457                                    ,x_data         => x_message_list);
4458 
4459       IF (g_debug IS NOT NULL) THEN
4460          gme_debug.put_line (   'Completed '
4461                              || l_api_name
4462                              || ' at '
4463                              || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
4464       END IF;
4465 
4466       IF g_debug <= gme_debug.g_log_procedure THEN
4467          gme_debug.put_line ('Exiting api ' || g_pkg_name || '.' || l_api_name);
4468       END IF;
4469    EXCEPTION
4470       WHEN delete_pp_lot_failure THEN
4471          ROLLBACK TO SAVEPOINT delete_pp_lot;
4472          gme_common_pvt.count_and_get (x_count        => x_message_count
4473                                       ,p_encoded      => fnd_api.g_false
4474                                       ,x_data         => x_message_list);
4475       WHEN setup_failure THEN
4476          ROLLBACK TO SAVEPOINT delete_pp_lot;
4477          gme_common_pvt.count_and_get (x_count        => x_message_count
4478                                       ,p_encoded      => fnd_api.g_false
4479                                       ,x_data         => x_message_list);
4480          x_return_status := fnd_api.g_ret_sts_error;
4481       WHEN OTHERS THEN
4482          IF g_debug <= gme_debug.g_log_unexpected THEN
4483             gme_debug.put_line (   'When others exception in '
4484                                 || g_pkg_name
4485                                 || '.'
4486                                 || l_api_name
4487                                 || ' Error is '
4488                                 || SQLERRM);
4489          END IF;
4490 
4491          ROLLBACK TO SAVEPOINT delete_pp_lot;
4492          gme_common_pvt.count_and_get (x_count        => x_message_count
4493                                       ,p_encoded      => fnd_api.g_false
4494                                       ,x_data         => x_message_list);
4495          x_return_status := fnd_api.g_ret_sts_unexp_error;
4496    END delete_pending_product_lot;
4497 
4498 END gme_api_main;