DBA Data[Home] [Help]

PACKAGE BODY: APPS.GME_API_MAIN

Source


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