[Home] [Help]
PACKAGE BODY: APPS.GME_API_PUB
Source
1 PACKAGE BODY gme_api_pub AS
2 /* $Header: GMEPAPIB.pls 120.62.12010000.1 2008/07/25 10:29:12 appldev ship $ */
3 g_debug VARCHAR2 (5) := NVL(fnd_profile.VALUE ('AFLOG_LEVEL'),-1);
4 g_pkg_name CONSTANT VARCHAR2 (30) := 'GME_API_PUB';
5
6 PROCEDURE gme_when_others (
7 p_api_name IN VARCHAR2
8 ,x_message_count OUT NOCOPY NUMBER
9 ,x_message_list OUT NOCOPY VARCHAR2
10 ,x_return_status OUT NOCOPY VARCHAR2
11 )
12 IS
13 l_api_name CONSTANT VARCHAR2 (30) := 'gme_when_others';
14 BEGIN
15 IF g_debug <= gme_debug.g_log_procedure THEN
16 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
17 || l_api_name);
18 END IF;
19 IF g_debug <= gme_debug.g_log_unexpected THEN
20 gme_debug.put_line(g_pkg_name||'.'||p_api_name||':'||'When others exception:'||SQLERRM);
21 END IF;
22 fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
23 gme_common_pvt.count_and_get (x_count => x_message_count
24 ,p_encoded => fnd_api.g_false
25 ,x_data => x_message_list);
26 x_return_status := fnd_api.g_ret_sts_unexp_error;
27
28 END gme_when_others ;
29
30
31 /*************************************************************************/
32 /* Bug 5255959 added p_clear_qty_cache parameter */
33 PROCEDURE save_batch (
34 p_header_id IN NUMBER DEFAULT NULL
35 ,p_table IN NUMBER DEFAULT NULL
36 ,p_commit IN VARCHAR2 := fnd_api.g_false
37 ,x_return_status OUT NOCOPY VARCHAR2
38 --Bug#5584699 Changed variable from boolean to varchar2
39 ,p_clear_qty_cache IN VARCHAR2 := FND_API.g_true)
40 --,p_clear_qty_cache IN BOOLEAN DEFAULT TRUE)
41 IS
42 l_api_name CONSTANT VARCHAR2 (30) := 'SAVE_BATCH';
43 l_header_id NUMBER;
44 l_trans_count NUMBER;
45 l_msg_count NUMBER;
46 l_msg_data VARCHAR2 (2000);
47
48 error_save_batch EXCEPTION;
49
50 CURSOR header_cursor
51 IS
52 SELECT DISTINCT doc_id batch_id
53 FROM gme_resource_txns_gtmp
54 ORDER BY batch_id;
55 BEGIN
56 IF g_debug <= gme_debug.g_log_procedure THEN
57 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
58 || l_api_name);
59 END IF;
60
61 IF g_debug <= gme_debug.g_log_statement THEN
62 gme_debug.put_line ('p_header_id = ' || p_header_id);
63 gme_debug.put_line ('p_table = ' || p_table);
64 END IF;
65
66 x_return_status := fnd_api.g_ret_sts_success;
67
68 FOR header_row IN header_cursor LOOP
69 -- Check that there is one and only one primary resource
70 IF gme_common_pvt.g_check_primary_rsrc = 1
71 AND p_commit = fnd_api.g_true THEN
72 gme_resource_engine_pvt.check_primary_resource
73 (p_batch_id => header_row.batch_id
74 ,p_batchstep_id => NULL
75 ,x_return_status => x_return_status);
76
77 IF x_return_status <> fnd_api.g_ret_sts_success THEN
78 RAISE error_save_batch;
79 END IF;
80 END IF; -- IF gme_common_pvt.g_check_primary_rsrc = 1 THEN
81
82 gme_resource_engine_pvt.consolidate_batch_resources
83 (header_row.batch_id
84 ,x_return_status);
85
86 IF x_return_status <> fnd_api.g_ret_sts_success THEN
87 RAISE error_save_batch;
88 END IF;
89 END LOOP;
90
91 l_header_id := NVL (p_header_id, gme_common_pvt.g_transaction_header_id);
92
93
94 IF (NVL (l_header_id, 0) <> 0) THEN
95 /* Bug 5255959 added p_clear_qty_cache parameter */
96 gme_transactions_pvt.process_transactions
97 (p_api_version => 2.0
98 ,p_init_msg_list => fnd_api.g_false
99 ,p_commit => fnd_api.g_false
100 ,p_validation_level => fnd_api.g_valid_level_full
101 ,p_table => p_table
102 ,p_header_id => l_header_id
103 ,x_return_status => x_return_status
104 ,x_msg_count => l_msg_count
105 ,x_msg_data => l_msg_data
106 ,x_trans_count => l_trans_count
107 ,p_clear_qty_cache => p_clear_qty_cache);
108
109 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
110 IF g_debug <= gme_debug.g_log_statement THEN
111 gme_debug.put_line( g_pkg_name
112 || '.'
113 || l_api_name
114 || ':'
115 || 'Return status from process_transactions '
116 || x_return_status);
117 END IF;
118
119 RAISE error_save_batch;
120 END IF;
121 END IF; /* IF (NVL (l_header_id, 0) <> 0) */
122
123 IF p_commit = fnd_api.g_true THEN
124 COMMIT;
125 END IF;
126
127 IF g_debug <= gme_debug.g_log_procedure THEN
128 gme_debug.put_line ('Exiting api ' || g_pkg_name || '.' || l_api_name);
129 END IF;
130 EXCEPTION
131 WHEN error_save_batch THEN
132 gme_common_pvt.count_and_get (x_count => l_msg_count
133 ,p_encoded => fnd_api.g_false
134 ,x_data => l_msg_data);
135 WHEN OTHERS THEN
136 gme_when_others ( p_api_name => l_api_name
137 ,x_message_count => l_msg_count
138 ,x_message_list => l_msg_data
139 ,x_return_status => x_return_status );
140 END save_batch;
141
142 /*************************************************************************/
143 PROCEDURE create_batch (
144 p_api_version IN NUMBER
145 ,p_validation_level IN NUMBER
146 := gme_common_pvt.g_max_errors
147 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
148 ,p_commit IN VARCHAR2 := fnd_api.g_false
149 ,x_message_count OUT NOCOPY NUMBER
150 ,x_message_list OUT NOCOPY VARCHAR2
151 ,x_return_status OUT NOCOPY VARCHAR2
152 ,p_org_code IN VARCHAR2 := NULL
153 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
154 ,x_batch_header_rec OUT NOCOPY gme_batch_header%ROWTYPE
155 ,p_batch_size IN NUMBER := NULL
156 ,p_batch_size_uom IN VARCHAR2 := NULL
157 ,p_creation_mode IN VARCHAR2
158 ,p_recipe_id IN NUMBER := NULL
159 ,p_recipe_no IN VARCHAR2 := NULL
160 ,p_recipe_version IN NUMBER := NULL
161 ,p_product_no IN VARCHAR2 := NULL
162 ,p_item_revision IN VARCHAR2 := NULL
163 ,p_product_id IN NUMBER := NULL
164 ,p_ignore_qty_below_cap IN VARCHAR2 := fnd_api.g_true
165 ,p_use_workday_cal IN VARCHAR2 := fnd_api.g_true
166 ,p_contiguity_override IN VARCHAR2 := fnd_api.g_true
167 ,p_use_least_cost_validity_rule IN VARCHAR2 := fnd_api.g_false
168 ,x_exception_material_tbl OUT NOCOPY gme_common_pvt.exceptions_tab)
169 IS
170 l_api_name CONSTANT VARCHAR2 (30) := 'CREATE_BATCH';
171 l_batch_header gme_batch_header%ROWTYPE;
172 l_return_status VARCHAR2 (1);
173 l_object_type VARCHAR2 (10);
174 l_total_input NUMBER;
175 l_total_output NUMBER;
176 l_item_id NUMBER;
177 l_item_rec mtl_system_items_b%ROWTYPE;
178 l_product_qty NUMBER;
179 l_recipe_use NUMBER;
180 l_status_type VARCHAR2 (10);
181 l_return_code NUMBER (5);
182 l_msg_count NUMBER;
183 l_msg_list VARCHAR2 (2000);
184 l_validity_tbl gmd_validity_rules.recipe_validity_tbl;
185 l_use VARCHAR2 (1);
186 l_contiguity_override VARCHAR2 (1);
187 l_cmplt_date DATE;
188 l_exists NUMBER;
189
190 CURSOR cur_validity_item (v_vrule_id NUMBER)
191 IS
192 SELECT inventory_item_id
193 FROM gmd_recipe_validity_rules
194 WHERE recipe_validity_rule_id = v_vrule_id;
195
196 CURSOR get_item_id(v_item_no VARCHAR2)
197 IS
198 SELECT inventory_item_id
199 FROM mtl_system_items_kfv
200 WHERE concatenated_segments = v_item_no;
201
202 CURSOR cur_validate_uom (v_uom_code VARCHAR2)
203 IS
204 SELECT 1
205 FROM DUAL
206 WHERE EXISTS (SELECT 1
207 FROM mtl_units_of_measure
208 WHERE uom_code = v_uom_code);
209 BEGIN
210 IF (g_debug <> -1) THEN
211 gme_debug.log_initialize ('CreateBatch');
212 END IF;
213
214 IF g_debug <= gme_debug.g_log_procedure THEN
215 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
216 || l_api_name);
217 END IF;
218
219 /* Set the return status to success initially */
220 x_return_status := fnd_api.g_ret_sts_success;
221
222 IF p_init_msg_list = fnd_api.g_true THEN
223 fnd_msg_pub.initialize;
224 END IF;
225
226 IF NOT fnd_api.compatible_api_call (2.0
227 ,p_api_version
228 ,'create_batch'
229 ,g_pkg_name) THEN
230 RAISE fnd_api.g_exc_error;
231 END IF;
232
233 l_batch_header := p_batch_header_rec;
234
235 IF (l_batch_header.organization_id IS NULL AND p_org_code IS NULL) THEN
236 fnd_message.set_name ('INV', 'INV_ORG_REQUIRED');
237 fnd_msg_pub.ADD;
238 RAISE fnd_api.g_exc_error;
239 END IF;
240
241 IF (l_batch_header.batch_type NOT IN
242 (gme_common_pvt.g_doc_type_batch, gme_common_pvt.g_doc_type_fpo) ) THEN
243 gme_common_pvt.log_message ('GME_INVALID_BATCH_TYPE');
244 RAISE fnd_api.g_exc_error;
245 END IF;
246
247 IF (p_contiguity_override NOT IN (fnd_api.g_true, fnd_api.g_false) ) THEN
248 gme_common_pvt.log_message ('GME_INVALID_FIELD'
249 ,'FIELD'
250 ,'p_contiguity_override');
251 RAISE fnd_api.g_exc_error;
252 ELSE
253 l_contiguity_override := p_contiguity_override;
254 END IF;
255
256 IF (p_use_workday_cal NOT IN (fnd_api.g_true, fnd_api.g_false) ) THEN
257 gme_common_pvt.log_message ('GME_INVALID_FIELD'
258 ,'FIELD'
259 ,'p_use_workday_cal');
260 RAISE fnd_api.g_exc_error;
261 END IF;
262
263 IF (p_ignore_qty_below_cap NOT IN (fnd_api.g_true, fnd_api.g_false) ) THEN
264 gme_common_pvt.log_message ('GME_INVALID_FIELD'
265 ,'FIELD'
266 ,'p_ignore_qty_below_cap');
267 RAISE fnd_api.g_exc_error;
268 END IF;
269
270 IF (p_creation_mode NOT IN ('INPUT', 'OUTPUT', 'RECIPE', 'PRODUCT') ) THEN
271 gme_common_pvt.log_message ('GME_API_UNSUPPORTED_MODE'
272 ,'MODE'
273 ,p_creation_mode);
274 RAISE fnd_api.g_exc_error;
275 ELSIF (p_creation_mode IN ('INPUT', 'OUTPUT', 'PRODUCT') ) THEN
276 IF (p_batch_size IS NULL) THEN
277 gme_common_pvt.log_message ('GME_FIELD_VALUE_REQUIRED'
278 ,'FIELD_NAME'
279 ,'p_batch_size');
280 RAISE fnd_api.g_exc_error;
281 ELSIF (p_batch_size < 0) THEN
282 gme_common_pvt.log_message ('GME_INVALID_FIELD'
283 ,'FIELD'
284 ,'p_batch_size');
285 RAISE fnd_api.g_exc_error;
286 END IF;
287
288 IF (p_batch_size_uom IS NULL) THEN
289 gme_common_pvt.log_message ('GME_FIELD_VALUE_REQUIRED'
290 ,'FIELD_NAME'
291 ,'p_batch_size_uom');
292 RAISE fnd_api.g_exc_error;
293 ELSE
294 OPEN cur_validate_uom (p_batch_size_uom);
295
296 FETCH cur_validate_uom
297 INTO l_exists;
298
299 IF (cur_validate_uom%NOTFOUND) THEN
300 gme_common_pvt.log_message ('GME_INVALID_FIELD'
301 ,'FIELD'
302 ,'p_batch_size_uom');
303 CLOSE cur_validate_uom;
304 RAISE fnd_api.g_exc_error;
305 END IF;
306
307 CLOSE cur_validate_uom;
308 END IF;
309 END IF;
310
311 IF g_debug <= gme_debug.g_log_statement THEN
312 gme_debug.put_line ('Finished parameter validation');
313 END IF;
314
315 gme_common_pvt.g_error_count := 0;
316 gme_common_pvt.g_setup_done :=
317 gme_common_pvt.setup (p_org_id => l_batch_header.organization_id
318 ,p_org_code => p_org_code);
319
320 IF NOT gme_common_pvt.g_setup_done THEN
321 RAISE fnd_api.g_exc_error;
322 ELSE
323 l_batch_header.organization_id := gme_common_pvt.g_organization_id;
324 END IF;
325
326 IF g_debug <= gme_debug.g_log_statement THEN
327 gme_debug.put_line ('Finished setup');
328 END IF;
329
330 IF (gme_common_pvt.g_lab_ind = 0 AND l_batch_header.laboratory_ind = 1) THEN
331 gme_common_pvt.log_message ('GME_NOT_LAB_ORG');
332 RAISE fnd_api.g_exc_error;
333 END IF;
334
335 IF (gme_common_pvt.g_plant_ind = 0 AND l_batch_header.batch_type = 10) THEN
336 gme_common_pvt.log_message ('GME_FPO_NO_CREATE');
337 RAISE fnd_api.g_exc_error;
338 END IF;
339
340 IF (gme_common_pvt.g_lab_ind = 1 AND gme_common_pvt.g_plant_ind = 1) THEN
341 IF (l_batch_header.laboratory_ind = 1) THEN
342 l_object_type := 'L';
343 ELSE
344 IF (l_batch_header.batch_type = gme_common_pvt.g_doc_type_fpo) THEN
345 l_object_type := fnd_api.g_false;
346 ELSE
347 l_object_type := 'P';
348 END IF;
349 END IF;
350 ELSIF (gme_common_pvt.g_lab_ind = 1) THEN
351 l_object_type := 'L';
352 ELSIF (gme_common_pvt.g_plant_ind = 1) THEN
353 IF (l_batch_header.batch_type = 10) THEN
354 l_object_type := fnd_api.g_false;
355 ELSE
356 l_object_type := 'P';
357 END IF;
358 END IF;
359
360 IF g_debug <= gme_debug.g_log_statement THEN
361 gme_debug.put_line ('Finished lab_ind plant_ind setup');
362 END IF;
363
364 IF NVL (gme_common_pvt.g_validate_plan_dates_ind, 0) = 1 THEN
365 l_cmplt_date := NULL;
366 ELSE
367 l_cmplt_date := p_batch_header_rec.plan_cmplt_date;
368 END IF;
369
370 IF p_batch_header_rec.recipe_validity_rule_id IS NULL THEN
371 IF p_creation_mode = 'PRODUCT' THEN
372 l_product_qty := p_batch_size;
373 /*Bug#5256138 Begin item validation check starts. If we don't pass any VR and if we use PRODUCT MODE
374 then only we need to do the item validation. IF VR is provided tht will be used directly */
375 IF p_product_no IS NOT NULL THEN
376 OPEN get_item_id(p_product_no);
377 FETCH get_item_id INTO l_item_id;
378 CLOSE get_item_id;
379 ELSIF p_product_id IS NOT NULL THEN
380 l_item_id := p_product_id;
381 ELSE
382 gme_common_pvt.log_message ('GME_FIELD_VALUE_REQUIRED'
383 ,'FIELD_NAME'
384 ,'p_product_no or p_product_id');
385 RAISE fnd_api.g_exc_error;
386 END IF;
387 --All error messages will be logged in this procedure itself..
388 gme_material_detail_pvt.validate_item_id(
389 p_org_id => l_batch_header.organization_id
390 ,p_item_id => l_item_id
391 ,x_item_rec => l_item_rec
392 ,x_return_status => l_return_status);
393
394 IF l_return_status <> fnd_api.g_ret_sts_success THEN
395 RAISE fnd_api.g_exc_error;
396 END IF;
397 --Bug#5256138 End
398 ELSIF p_creation_mode = 'OUTPUT' THEN
399 l_total_output := p_batch_size;
400 ELSIF p_creation_mode = 'INPUT' THEN
401 l_total_input := p_batch_size;
402 END IF;
403
404 gmd_val_data_pub.get_val_data
405 (p_api_version => 1.0
406 ,p_object_type => l_object_type
407 ,p_recipe_no => p_recipe_no
408 ,p_recipe_version => p_recipe_version
409 ,p_recipe_id => p_recipe_id
410 ,p_total_input => l_total_input
411 ,p_total_output => l_total_output
412 ,p_item_id => p_product_id
413 ,p_item_no => p_product_no
414 ,p_product_qty => l_product_qty
415 ,p_uom => p_batch_size_uom
416 ,p_recipe_use => l_recipe_use
417 ,p_organization_id => l_batch_header.organization_id
418 ,p_start_date => p_batch_header_rec.plan_start_date
419 ,p_end_date => l_cmplt_date
420 ,p_status_type => l_status_type
421 ,p_least_cost_validity => p_use_least_cost_validity_rule
422 ,p_revision => p_item_revision --nsinghi bug#5436643 Pass Revision Number
423 ,x_return_status => l_return_status
424 ,x_msg_count => l_msg_count
425 ,x_msg_data => l_msg_list
426 ,x_return_code => l_return_code
427 ,x_recipe_validity_out => l_validity_tbl);
428
429 IF l_return_status <> fnd_api.g_ret_sts_success THEN
430 RAISE fnd_api.g_exc_error;
431 ELSIF l_validity_tbl.COUNT = 0 THEN
432 fnd_message.set_name ('GMD', 'GMD_NO_VLDTY_RLE_CRIT');
433 fnd_msg_pub.ADD;
434 RAISE fnd_api.g_exc_error;
435 ELSE
436 l_batch_header.recipe_validity_rule_id :=
437 l_validity_tbl (1).recipe_validity_rule_id;
438 END IF;
439 ELSE
440 IF (p_product_id IS NULL) THEN
441 OPEN cur_validity_item
442 (p_batch_header_rec.recipe_validity_rule_id);
443
444 FETCH cur_validity_item
445 INTO l_item_id;
446
447 CLOSE cur_validity_item;
448 ELSE
449 l_item_id := p_product_id;
450 END IF;
451
452 IF NOT (gme_common_pvt.validate_validity_rule
453 (p_validity_rule_id => l_batch_header.recipe_validity_rule_id
454 ,p_organization_id => l_batch_header.organization_id
455 ,p_prim_product_id => l_item_id
456 ,p_qty => p_batch_size
457 ,p_uom => p_batch_size_uom
458 ,p_object_type => l_object_type
459 ,p_start_date => p_batch_header_rec.plan_start_date
460 ,p_cmplt_date => p_batch_header_rec.plan_cmplt_date
461 ,p_creation_mode => p_creation_mode) ) THEN
462 RAISE fnd_api.g_exc_error;
463 END IF;
464 END IF;
465
466 IF g_debug <= gme_debug.g_log_statement THEN
467 gme_debug.put_line ('Finished validity rule stuff');
468 END IF;
469
470 IF p_use_workday_cal IS NOT NULL THEN
471 l_use := p_use_workday_cal;
472
473 IF l_use = fnd_api.g_true THEN
474 IF (gme_common_pvt.g_calendar_code IS NOT NULL) THEN
475 IF (p_batch_header_rec.plan_start_date IS NOT NULL) THEN
476 IF NOT gmp_calendar_api.is_working_daytime
477 (1.0
478 ,FALSE
479 ,gme_common_pvt.g_calendar_code
480 ,p_batch_header_rec.plan_start_date
481 ,0
482 ,l_return_status) THEN
483 gme_common_pvt.log_message
484 ('GME_NON_WORKING_TIME'
485 ,'PDATE'
486 ,fnd_date.date_to_displaydt
487 (p_batch_header_rec.plan_start_date) );
488 RAISE fnd_api.g_exc_error;
489 END IF;
490 END IF;
491
492 IF (p_batch_header_rec.plan_cmplt_date IS NOT NULL) THEN
493 IF NOT gmp_calendar_api.is_working_daytime
494 (1.0
495 ,FALSE
496 ,gme_common_pvt.g_calendar_code
497 ,p_batch_header_rec.plan_cmplt_date
498 ,1
499 ,l_return_status) THEN
500 gme_common_pvt.log_message
501 ('GME_NON_WORKING_TIME'
502 ,'PDATE'
503 ,TO_CHAR (p_batch_header_rec.plan_cmplt_date
504 ,'DD-MON-YYYY HH24:MI:SS') );
505 RAISE fnd_api.g_exc_error;
506 END IF;
507 END IF;
508
509 IF p_batch_header_rec.plan_cmplt_date IS NULL
510 AND p_batch_header_rec.plan_start_date IS NULL THEN
511 IF NOT gmp_calendar_api.is_working_daytime
512 (1.0
513 ,FALSE
514 ,gme_common_pvt.g_calendar_code
515 ,SYSDATE
516 ,0
517 ,l_return_status) THEN
518 gme_common_pvt.log_message
519 ('GME_NON_WORKING_TIME'
520 ,'PDATE'
521 ,TO_CHAR (SYSDATE
522 ,'DD-MON-YYYY HH24:MI:SS') );
523 RAISE fnd_api.g_exc_error;
524 END IF;
525 END IF;
526 END IF;
527 END IF;
528 END IF;
529
530 IF g_debug <= gme_debug.g_log_statement THEN
531 gme_debug.put_line ('calling main');
532 END IF;
533
534 gme_api_main.create_batch
535 (p_validation_level => p_validation_level
536 ,p_init_msg_list => fnd_api.g_false
537 ,x_message_count => x_message_count
538 ,x_message_list => x_message_list
539 ,x_return_status => x_return_status
540 ,p_batch_header_rec => l_batch_header
541 ,x_batch_header_rec => x_batch_header_rec
542 ,p_batch_size => p_batch_size
543 ,p_batch_size_uom => p_batch_size_uom
544 ,p_creation_mode => p_creation_mode
545 ,p_recipe_id => p_recipe_id
546 ,p_recipe_no => p_recipe_no
547 ,p_recipe_version => p_recipe_version
548 ,p_product_no => p_product_no
549 ,p_product_id => p_product_id
550 ,p_ignore_qty_below_cap => p_ignore_qty_below_cap
551 ,p_use_workday_cal => l_use
552 ,p_contiguity_override => l_contiguity_override
553 ,p_use_least_cost_validity_rule => p_use_least_cost_validity_rule
554 ,x_exception_material_tbl => x_exception_material_tbl);
555
556 IF ( x_return_status <> fnd_api.g_ret_sts_success
557 AND x_return_status <> gme_common_pvt.g_inv_short_err) THEN
558 RAISE fnd_api.g_exc_error;
559 END IF;
560
561 IF (p_commit = fnd_api.g_true) THEN
562 COMMIT;
563 END IF;
564
565 gme_common_pvt.log_message ('GME_API_BATCH_CREATED');
566 gme_common_pvt.count_and_get (x_count => x_message_count
567 ,p_encoded => fnd_api.g_false
568 ,x_data => x_message_list);
569
570 IF g_debug <= gme_debug.g_log_procedure THEN
571 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
572 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
573 END IF;
574 EXCEPTION
575 WHEN fnd_api.g_exc_error THEN
576 x_batch_header_rec := NULL;
577 x_return_status := fnd_api.g_ret_sts_error;
578 gme_common_pvt.count_and_get (x_count => x_message_count
579 ,p_encoded => fnd_api.g_false
580 ,x_data => x_message_list);
581 WHEN OTHERS THEN
582 x_batch_header_rec := NULL;
583 gme_when_others ( p_api_name => l_api_name
584 ,x_message_count => x_message_count
585 ,x_message_list => x_message_list
586 ,x_return_status => x_return_status );
587 END create_batch;
588
589 /*************************************************************************/
590 PROCEDURE create_phantom (
591 p_api_version IN NUMBER
592 ,p_validation_level IN NUMBER
593 := gme_common_pvt.g_max_errors
594 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
595 ,p_commit IN VARCHAR2 := fnd_api.g_false
596 ,x_message_count OUT NOCOPY NUMBER
597 ,x_message_list OUT NOCOPY VARCHAR2
598 ,x_return_status OUT NOCOPY VARCHAR2
599 ,p_material_detail_rec IN gme_material_details%ROWTYPE
600 ,p_batch_header_rec IN gme_batch_header%ROWTYPE --Bug#6738476
601 ,p_org_code IN VARCHAR2
602 ,p_batch_no IN VARCHAR2 DEFAULT NULL
603 ,x_material_detail_rec OUT NOCOPY gme_material_details%ROWTYPE
604 ,p_validity_rule_id IN NUMBER
605 ,p_use_workday_cal IN VARCHAR2 := fnd_api.g_true
606 ,p_contiguity_override IN VARCHAR2 := fnd_api.g_true
607 ,p_use_least_cost_validity_rule IN VARCHAR2 := fnd_api.g_false
608 ,x_exception_material_tbl OUT NOCOPY gme_common_pvt.exceptions_tab)
609 IS
610 l_api_name CONSTANT VARCHAR2 (30) := 'CREATE_PHANTOM';
611 phantom_creation_failure EXCEPTION;
612 l_batch_header gme_batch_header%ROWTYPE;
613 l_material_detail gme_material_details%ROWTYPE;
614 BEGIN
615 IF (g_debug <> -1) THEN
616 gme_debug.log_initialize ('CreatePhantom');
617 END IF;
618
619 IF g_debug <= gme_debug.g_log_procedure THEN
620 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
621 || l_api_name);
622 END IF;
623
624 x_return_status := fnd_api.g_ret_sts_success;
625
626 /* Set savepoint here */
627 SAVEPOINT create_phantom;
628
629 IF p_init_msg_list = fnd_api.g_true THEN
630 fnd_msg_pub.initialize;
631 gme_common_pvt.g_error_count := 0;
632 END IF;
633
634 IF NOT fnd_api.compatible_api_call (2.0
635 ,p_api_version
636 ,'create_phantom'
637 ,g_pkg_name) THEN
638 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
639 RAISE fnd_api.g_exc_error;
640 END IF;
641
642 IF (p_material_detail_rec.organization_id IS NULL AND p_org_code IS NULL) THEN
643 fnd_message.set_name ('INV', 'INV_ORG_REQUIRED');
644 fnd_msg_pub.ADD;
645 RAISE fnd_api.g_exc_error;
646 END IF;
647
648 IF (p_contiguity_override NOT IN (fnd_api.g_true, fnd_api.g_false) ) THEN
649 gme_common_pvt.log_message ('GME_INVALID_FIELD'
650 ,'FIELD'
651 ,'p_contiguity_override');
652 RAISE fnd_api.g_exc_error;
653 END IF;
654
655 IF (p_use_workday_cal NOT IN (fnd_api.g_true, fnd_api.g_false) ) THEN
656 gme_common_pvt.log_message ('GME_INVALID_FIELD'
657 ,'FIELD'
658 ,'p_use_workday_cal');
659 RAISE fnd_api.g_exc_error;
660 END IF;
661
662 l_material_detail := p_material_detail_rec;
663 gme_common_pvt.g_setup_done :=
664 gme_common_pvt.setup (p_material_detail_rec.organization_id
665 ,p_org_code);
666
667 IF NOT gme_common_pvt.g_setup_done THEN
668 RAISE fnd_api.g_exc_error;
669 ELSE
670 l_material_detail.organization_id :=
671 gme_common_pvt.g_organization_id;
672 END IF;
673
674 gme_api_main.create_phantom
675 (p_validation_level => p_validation_level
676 ,p_init_msg_list => fnd_api.g_false
677 ,x_message_count => x_message_count
678 ,x_message_list => x_message_list
679 ,x_return_status => x_return_status
680 ,p_material_detail_rec => l_material_detail
681 ,p_batch_header_rec => p_batch_header_rec
682 ,p_batch_no => p_batch_no
683 ,x_material_detail_rec => x_material_detail_rec
684 ,p_validity_rule_id => p_validity_rule_id
685 ,p_use_workday_cal => p_use_workday_cal
686 ,p_contiguity_override => p_contiguity_override
687 ,p_use_least_cost_validity_rule => p_use_least_cost_validity_rule
688 ,x_exception_material_tbl => x_exception_material_tbl);
689
690 IF x_return_status <> fnd_api.g_ret_sts_success THEN
691 RAISE phantom_creation_failure;
692 END IF;
693
694 IF (p_commit = fnd_api.g_true) THEN
695 COMMIT;
696 END IF;
697
698 IF g_debug <= gme_debug.g_log_procedure THEN
699 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
700 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
701 END IF;
702 EXCEPTION
703 WHEN phantom_creation_failure THEN
704 ROLLBACK TO SAVEPOINT create_phantom;
705 x_material_detail_rec := NULL;
706 gme_common_pvt.count_and_get (x_count => x_message_count
707 ,p_encoded => fnd_api.g_false
708 ,x_data => x_message_list);
709 WHEN fnd_api.g_exc_error THEN
710 ROLLBACK TO SAVEPOINT create_phantom;
711 x_material_detail_rec := NULL;
712 x_return_status := fnd_api.g_ret_sts_error;
713 gme_common_pvt.count_and_get (x_count => x_message_count
714 ,p_encoded => fnd_api.g_false
715 ,x_data => x_message_list);
716 WHEN OTHERS THEN
717 ROLLBACK TO SAVEPOINT create_phantom;
718 x_material_detail_rec := NULL;
719 gme_when_others ( p_api_name => l_api_name
720 ,x_message_count => x_message_count
721 ,x_message_list => x_message_list
722 ,x_return_status => x_return_status );
723 END create_phantom;
724
725 /*************************************************************************/
726 PROCEDURE scale_batch (
727 p_api_version IN NUMBER
728 ,p_validation_level IN NUMBER
729 ,p_init_msg_list IN VARCHAR2
730 ,p_commit IN VARCHAR2
731 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
732 ,p_org_code IN VARCHAR2
733 ,p_ignore_exception IN VARCHAR2
734 ,p_scale_factor IN NUMBER
735 ,p_primaries IN VARCHAR2
736 ,p_qty_type IN NUMBER
737 ,p_recalc_dates IN VARCHAR2
738 ,p_use_workday_cal IN VARCHAR2
739 ,p_contiguity_override IN VARCHAR2
740 ,x_exception_material_tbl OUT NOCOPY gme_common_pvt.exceptions_tab
741 ,x_message_count OUT NOCOPY NUMBER
742 ,x_message_list OUT NOCOPY VARCHAR2
743 ,x_return_status OUT NOCOPY VARCHAR2
744 ,x_batch_header_rec OUT NOCOPY gme_batch_header%ROWTYPE)
745 IS
746 l_api_name CONSTANT VARCHAR2 (30) := 'SCALE_BATCH';
747 scale_batch_failed EXCEPTION;
748 l_batch_header_rec gme_batch_header%ROWTYPE;
749 l_return_status VARCHAR2(1);
750
751 BEGIN
752 IF (g_debug <> -1) THEN
753 gme_debug.log_initialize ('ScaleBatch');
754 END IF;
755
756 IF g_debug <= gme_debug.g_log_procedure THEN
757 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
758 || l_api_name);
759 END IF;
760
761 /* Set the return status to success initially */
762 x_return_status := fnd_api.g_ret_sts_success;
763
764 /* Set savepoint here */
765 SAVEPOINT scale_batch;
766
767 -- Initialize message list and count if needed
768 IF p_init_msg_list = fnd_api.g_true THEN
769 fnd_msg_pub.initialize;
770 END IF;
771
772 /* Make sure we are call compatible */
773 IF NOT fnd_api.compatible_api_call (2.0
774 ,p_api_version
775 ,'scale_batch'
776 ,g_pkg_name) THEN
777 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
778 RAISE fnd_api.g_exc_error;
779 END IF;
780 gme_common_pvt.validate_batch
781 (p_batch_header_rec => p_batch_header_rec
782 ,p_org_code => p_org_code
783 ,p_batch_type => nvl(p_batch_header_rec.batch_type,gme_common_pvt.g_doc_type_batch)
784 ,x_batch_header_rec => l_batch_header_rec
785 ,x_message_count => x_message_count
786 ,x_message_list => x_message_list
787 ,x_return_status => x_return_status );
788
789 IF x_return_status <> fnd_api.g_ret_sts_success THEN
790 IF (g_debug = gme_debug.g_log_statement) THEN
791 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
792 || ': batch validate error ');
793 END IF;
794 RAISE fnd_api.g_exc_error;
795 END IF;
796
797 /* Check for p_qty_type */
798 IF (p_qty_type NOT IN (0, 1) ) THEN
799 gme_common_pvt.log_message ('GME_INVALID_QUANTITY_TYPE');
800 RAISE fnd_api.g_exc_error;
801 END IF;
802
803 /* Check for p_recalc_dates */
804 IF (p_recalc_dates NOT IN (fnd_api.g_true, fnd_api.g_false) ) THEN
805 gme_common_pvt.log_message ('GME_INVALID_FIELD'
806 ,'FIELD'
807 ,'p_recalc_dates');
808 RAISE fnd_api.g_exc_error;
809 END IF;
810
811 /* Check for p_use_workday_cal */
812 IF (p_use_workday_cal NOT IN (fnd_api.g_true, fnd_api.g_false) ) THEN
813 gme_common_pvt.log_message ('GME_INVALID_FIELD'
814 ,'FIELD'
815 ,'p_use_workday_cal');
816 RAISE fnd_api.g_exc_error;
817 END IF;
818
819 /* Check for p_contiguity_override */
820 IF (p_contiguity_override NOT IN (fnd_api.g_true, fnd_api.g_false) ) THEN
821 gme_common_pvt.log_message ('GME_INVALID_FIELD'
822 ,'FIELD'
823 ,'p_contiguity_override');
824 RAISE fnd_api.g_exc_error;
825 END IF;
826
827 x_batch_header_rec := l_batch_header_rec;
828 gme_api_main.scale_batch
829 (p_validation_level => p_validation_level
830 ,p_init_msg_list => fnd_api.g_false
831 ,x_message_count => x_message_count
832 ,x_message_list => x_message_list
833 ,x_return_status => x_return_status
834 ,p_batch_header_rec => l_batch_header_rec
835 ,x_batch_header_rec => x_batch_header_rec
836 ,p_scale_factor => p_scale_factor
837 ,p_primaries => p_primaries
838 ,p_qty_type => p_qty_type
839 ,p_recalc_dates => p_recalc_dates
840 ,p_use_workday_cal => p_use_workday_cal
841 ,p_contiguity_override => p_contiguity_override
842 ,x_exception_material_tbl => x_exception_material_tbl);
843 x_message_count := 0;
844
845 --Bug#5459105 Begin
846 IF x_return_status = fnd_api.g_ret_sts_success THEN
847 IF p_commit = fnd_api.g_true THEN
848 gme_api_pub.save_batch (p_header_id => NULL
849 ,p_table => NULL
850 ,p_commit => fnd_api.g_false
851 ,x_return_status => x_return_status);
852
853 IF x_return_status = fnd_api.g_ret_sts_success THEN
854 COMMIT;
855 ELSE
856 RAISE fnd_api.g_exc_error;
857 END IF;
858 END IF;
859 ELSE
860 RAISE scale_batch_failed;
861 END IF;
862 --Bug#5459105 End
863
864 gme_common_pvt.log_message ('GME_SCALE_SUCCESS');
865 gme_common_pvt.count_and_get (x_count => x_message_count
866 ,p_encoded => fnd_api.g_false
867 ,x_data => x_message_list);
868
869 IF g_debug <= gme_debug.g_log_procedure THEN
870 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
871 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
872 END IF;
873 EXCEPTION
874 WHEN scale_batch_failed THEN
875 ROLLBACK TO SAVEPOINT scale_batch;
876 x_batch_header_rec := NULL;
877 gme_common_pvt.count_and_get (x_count => x_message_count
878 ,p_encoded => fnd_api.g_false
879 ,x_data => x_message_list);
880 WHEN fnd_api.g_exc_error THEN
881 ROLLBACK TO SAVEPOINT scale_batch;
882 x_batch_header_rec := NULL;
883 x_return_status := fnd_api.g_ret_sts_error;
884 gme_common_pvt.count_and_get (x_count => x_message_count
885 ,p_encoded => fnd_api.g_false
886 ,x_data => x_message_list);
887 WHEN OTHERS THEN
888 ROLLBACK TO SAVEPOINT scale_batch;
889 x_batch_header_rec := NULL;
890 gme_when_others ( p_api_name => l_api_name
891 ,x_message_count => x_message_count
892 ,x_message_list => x_message_list
893 ,x_return_status => x_return_status );
894 END scale_batch;
895
896 /*************************************************************************/
897
898 PROCEDURE theoretical_yield_batch (
899 p_api_version IN NUMBER := 2.0
900 ,p_validation_level IN NUMBER
901 ,p_init_msg_list IN VARCHAR2
902 ,p_commit IN VARCHAR2
903 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
904 ,p_org_code IN VARCHAR2
905 ,p_scale_factor IN NUMBER
906 ,x_message_count OUT NOCOPY NUMBER
907 ,x_message_list OUT NOCOPY VARCHAR2
908 ,x_return_status OUT NOCOPY VARCHAR2)
909 IS
910 l_api_name CONSTANT VARCHAR2 (30) := 'THEORETICAL_YIELD_BATCH';
911 theoretical_yield_failed EXCEPTION;
912 l_batch_header_rec gme_batch_header%ROWTYPE;
913 l_return_status VARCHAR2(1);
914 BEGIN
915 IF (g_debug <> -1) THEN
916 gme_debug.log_initialize ('TheoreticalYieldBatch');
917 END IF;
918
919 IF g_debug <= gme_debug.g_log_procedure THEN
920 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
921 || l_api_name);
922 END IF;
923
924 /* Set the return status to success initially */
925 x_return_status := fnd_api.g_ret_sts_success;
926
927 /* Set savepoint here */
928 SAVEPOINT theoretical_yield_batch;
929
930 /* Initialize message list and count if needed */
931 IF p_init_msg_list = fnd_api.g_true THEN
932 fnd_msg_pub.initialize;
933 END IF;
934
935 /* Make sure we are call compatible */
936 IF NOT fnd_api.compatible_api_call (2.0
937 ,p_api_version
938 ,'theoretical_yield_batch'
939 ,g_pkg_name) THEN
940 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
941 RAISE fnd_api.g_exc_error;
942 END IF;
943 gme_common_pvt.validate_batch
944 (p_batch_header_rec => p_batch_header_rec
945 ,p_org_code => p_org_code
946 ,p_batch_type => nvl(p_batch_header_rec.batch_type,gme_common_pvt.g_doc_type_batch)
947 ,x_batch_header_rec => l_batch_header_rec
948 ,x_message_count => x_message_count
949 ,x_message_list => x_message_list
950 ,x_return_status => x_return_status );
951
952 IF x_return_status <> fnd_api.g_ret_sts_success THEN
953 IF (g_debug = gme_debug.g_log_statement) THEN
954 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
955 || ': batch validate error ');
956 END IF;
957 RAISE fnd_api.g_exc_error;
958 END IF;
959 gme_api_main.theoretical_yield_batch
960 (p_validation_level => p_validation_level
961 ,p_init_msg_list => fnd_api.g_false
962 ,x_message_count => x_message_count
963 ,x_message_list => x_message_list
964 ,p_batch_header_rec => l_batch_header_rec
965 ,p_scale_factor => p_scale_factor
966 ,x_return_status => x_return_status);
967
968 --Bug#5459105 Begin
969 IF x_return_status = fnd_api.g_ret_sts_success THEN
970 IF p_commit = fnd_api.g_true THEN
971 gme_api_pub.save_batch (p_header_id => NULL
972 ,p_table => NULL
973 ,p_commit => fnd_api.g_false
974 ,x_return_status => x_return_status);
975
976 IF x_return_status = fnd_api.g_ret_sts_success THEN
977 COMMIT;
978 ELSE
979 RAISE fnd_api.g_exc_error;
980 END IF;
981 END IF;
982 ELSE
983 RAISE theoretical_yield_failed;
984 END IF;
985 --Bug#5459105 End
986
987 IF g_debug <= gme_debug.g_log_procedure THEN
988 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
989 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
990 END IF;
991 EXCEPTION
992 WHEN fnd_api.g_exc_error THEN
993 ROLLBACK TO SAVEPOINT theoretical_yield_batch;
994 x_return_status := fnd_api.g_ret_sts_error;
995 gme_common_pvt.count_and_get (x_count => x_message_count
996 ,p_encoded => fnd_api.g_false
997 ,x_data => x_message_list);
998 WHEN theoretical_yield_failed THEN
999 ROLLBACK TO SAVEPOINT theoretical_yield_batch;
1000 gme_common_pvt.count_and_get (x_count => x_message_count
1001 ,p_encoded => fnd_api.g_false
1002 ,x_data => x_message_list);
1003 WHEN OTHERS THEN
1004 ROLLBACK TO SAVEPOINT theoretical_yield_batch;
1005 gme_when_others ( p_api_name => l_api_name
1006 ,x_message_count => x_message_count
1007 ,x_message_list => x_message_list
1008 ,x_return_status => x_return_status );
1009 END theoretical_yield_batch;
1010
1011 /*##########################################################################
1012 # PROCEDURE
1013 # update_actual_rsrc_usage
1014 # DESCRIPTION
1015 #
1016 # HISTORY :
1017 # 10-MAR-2005 Punit Kumar Convergence changes
1018 #########################################################################*/
1019 PROCEDURE update_actual_rsrc_usage (
1020 p_api_version IN NUMBER := 2.0
1021 ,p_validation_level IN NUMBER := gme_common_pvt.g_max_errors
1022 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
1023 ,p_commit IN VARCHAR2 := fnd_api.g_false
1024 ,p_org_code IN VARCHAR2
1025 ,p_batch_no IN VARCHAR2 := NULL
1026 ,p_batchstep_no IN NUMBER := NULL
1027 ,p_activity IN VARCHAR2 := NULL
1028 ,p_resource IN VARCHAR2 := NULL
1029 ,p_instance_no IN NUMBER := NULL
1030 ,p_reason_name IN VARCHAR2 := NULL
1031 ,p_rsrc_txn_rec IN gme_resource_txns%ROWTYPE
1032 ,p_validate_flexfields IN VARCHAR2 := fnd_api.g_false
1033 ,x_rsrc_txn_rec IN OUT NOCOPY gme_resource_txns%ROWTYPE
1034 ,x_message_count OUT NOCOPY NUMBER
1035 ,x_message_list OUT NOCOPY VARCHAR2
1036 ,x_return_status OUT NOCOPY VARCHAR2)
1037 IS
1038 l_api_name CONSTANT VARCHAR2(30) := 'UPDATE_ACTUAL_RSRC_USAGE';
1039
1040 l_batch_header gme_batch_header%ROWTYPE;
1041 l_poc_trans_id NUMBER;
1042 l_line_id NUMBER;
1043 l_inv_trans_count NUMBER;
1044 l_rsrc_trans_count NUMBER;
1045 l_return_status VARCHAR2 (2);
1046 /*start, Punit Kumar*/
1047 l_rsrc_txn_rec gme_resource_txns%ROWTYPE;
1048
1049 /*end */
1050 CURSOR cur_get_trans_id (v_line_id NUMBER)
1051 IS
1052 SELECT r.*
1053 FROM gme_resource_txns_gtmp t, gme_resource_txns r
1054 WHERE action_code = 'NONE' AND t.line_id = v_line_id
1055 AND t.poc_trans_id = r.poc_trans_id;
1056
1057 update_rsrc_usage EXCEPTION;
1058 BEGIN
1059 /* Set the savepoint */
1060 SAVEPOINT update_actual_rsrc_usage;
1061 IF g_debug <> -1 THEN
1062 gme_debug.log_initialize ('UpdateResource');
1063 END IF;
1064 /* Set the return status to success initially */
1065 x_return_status := fnd_api.g_ret_sts_success;
1066 /* Initialize message list and count if needed */
1067 IF p_init_msg_list = fnd_api.g_true THEN
1068 fnd_msg_pub.initialize;
1069 gme_common_pvt.g_error_count := 0;
1070 END IF;
1071
1072 l_rsrc_txn_rec := p_rsrc_txn_rec ;
1073 IF (l_rsrc_txn_rec.organization_id IS NULL AND p_org_code IS NULL) THEN
1074 gme_common_pvt.log_message(p_product_code => 'INV'
1075 ,p_message_code => 'INV_ORG_REQUIRED');
1076 RAISE fnd_api.g_exc_error;
1077 END IF;
1078 /* Setup the common constants used accross the apis */
1079 gme_common_pvt.g_setup_done :=
1080 gme_common_pvt.setup (p_org_id => l_rsrc_txn_rec.organization_id
1081 ,p_org_code => p_org_code);
1082
1083 IF NOT gme_common_pvt.g_setup_done THEN
1084 RAISE fnd_api.g_exc_error;
1085 ELSE
1086 l_rsrc_txn_rec.organization_id := gme_common_pvt.g_organization_id;
1087 END IF;
1088
1089 /* Make sure we are call compatible */
1090 IF NOT fnd_api.compatible_api_call (2.0
1091 ,p_api_version
1092 ,'update_actual_resource_usage'
1093 ,g_pkg_name) THEN
1094 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
1095 RAISE fnd_api.g_exc_error;
1096 END IF;
1097
1098 IF p_validate_flexfields = 'T' THEN
1099 gme_common_pvt.g_flex_validate_prof := 1;
1100 ELSE
1101 gme_common_pvt.g_flex_validate_prof := 0;
1102 END IF;
1103 gme_common_pvt.set_timestamp;
1104
1105 IF g_debug <= gme_debug.g_log_procedure THEN
1106 gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
1107 ||'BEFORE CALLING gme_resource_engine_pvt.update_actual_resource_usagep ' );
1108 END IF;
1109
1110 gme_resource_engine_pvt.update_actual_resource_usage
1111 (p_org_code => p_org_code
1112 ,p_batch_no => p_batch_no
1113 ,p_batchstep_no => p_batchstep_no
1114 ,p_activity => p_activity
1115 ,p_resource => p_resource
1116 ,p_instance_no => p_instance_no
1117 ,p_reason_name => p_reason_name
1118 ,p_rsrc_txn_rec => p_rsrc_txn_rec
1119 ,x_rsrc_txn_rec => x_rsrc_txn_rec
1120 ,x_return_status => x_return_status);
1121
1122 gme_common_pvt.g_flex_validate_prof := 0;
1123
1124 l_batch_header.batch_id := x_rsrc_txn_rec.doc_id;
1125
1126 IF x_return_status = fnd_api.g_ret_sts_success THEN
1127 IF p_commit = fnd_api.g_true THEN
1128 gme_api_pub.save_batch (p_header_id => NULL
1129 ,p_table => NULL
1130 ,p_commit => fnd_api.g_false
1131 ,x_return_status => x_return_status);
1132
1133 IF x_return_status = fnd_api.g_ret_sts_success THEN
1134 COMMIT;
1135 ELSE
1136 RAISE fnd_api.g_exc_error;
1137 END IF;
1138 END IF;
1139 ELSE
1140 RAISE update_rsrc_usage;
1141 END IF;
1142
1143 /* In order to get the poc_trans_id */
1144 /* Lets now load the transactions associated with the batch into the temporary table */
1145 IF p_commit = fnd_api.g_true THEN
1146 IF NOT (gme_batch_header_dbl.fetch_row (l_batch_header
1147 ,l_batch_header) ) THEN
1148 RAISE fnd_api.g_exc_error;
1149 END IF;
1150 gme_trans_engine_util.load_rsrc_trans
1151 (p_batch_row => l_batch_header
1152 ,x_rsc_row_count => l_rsrc_trans_count
1153 ,x_return_status => x_return_status);
1154
1155 IF x_return_status <> fnd_api.g_ret_sts_success THEN
1156 RAISE fnd_api.g_exc_error;
1157 END IF;
1158
1159 OPEN cur_get_trans_id (x_rsrc_txn_rec.line_id);
1160 FETCH cur_get_trans_id INTO x_rsrc_txn_rec;
1161 CLOSE cur_get_trans_id;
1162 END IF;
1163
1164 IF g_debug <= gme_debug.g_log_procedure THEN
1165 gme_debug.put_line ( 'Actual rsrc usage at '
1166 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
1167 END IF;
1168
1169 gme_common_pvt.log_message ('PM_SAVED_CHANGES');
1170 gme_common_pvt.count_and_get (x_count => x_message_count
1171 ,p_encoded => fnd_api.g_false
1172 ,x_data => x_message_list);
1173 EXCEPTION
1174 WHEN fnd_api.g_exc_error THEN
1175 x_return_status := fnd_api.g_ret_sts_error;
1176 ROLLBACK TO SAVEPOINT update_actual_rsrc_usage;
1177 gme_common_pvt.count_and_get (x_count => x_message_count
1178 ,p_encoded => fnd_api.g_false
1179 ,x_data => x_message_list);
1180 WHEN update_rsrc_usage THEN
1181 ROLLBACK TO SAVEPOINT update_actual_rsrc_usage;
1182 gme_common_pvt.count_and_get (x_count => x_message_count
1183 ,p_encoded => fnd_api.g_false
1184 ,x_data => x_message_list);
1185 WHEN OTHERS THEN
1186 ROLLBACK TO SAVEPOINT update_actual_rsrc_usage;
1187 gme_when_others ( p_api_name => l_api_name
1188 ,x_message_count => x_message_count
1189 ,x_message_list => x_message_list
1190 ,x_return_status => x_return_status );
1191 END update_actual_rsrc_usage;
1192
1193 /*##########################################################################
1194 # PROCEDURE
1195 # insert_incr_actual_rsrc_txn
1196 # DESCRIPTION
1197 # HISTORY
1198 # 10-MAR-2005 Punit Kumar
1199 # Convergence changes
1200 #########################################################################*/
1201 PROCEDURE insert_incr_actual_rsrc_txn (
1202 p_api_version IN NUMBER := 2.0
1203 ,p_validation_level IN NUMBER := gme_common_pvt.g_max_errors
1204 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
1205 ,p_commit IN VARCHAR2 := fnd_api.g_false
1206 ,p_org_code IN VARCHAR2
1207 ,p_batch_no IN VARCHAR2 := NULL
1208 ,p_batchstep_no IN NUMBER := NULL
1209 ,p_activity IN VARCHAR2 := NULL
1210 ,p_resource IN VARCHAR2 := NULL
1211 ,p_instance_no IN NUMBER := NULL
1212 ,p_reason_name IN VARCHAR2 := NULL
1213 ,p_rsrc_txn_rec IN gme_resource_txns%ROWTYPE
1214 ,p_validate_flexfields IN VARCHAR2 := fnd_api.g_false
1215 ,x_rsrc_txn_rec IN OUT NOCOPY gme_resource_txns%ROWTYPE
1216 ,x_message_count OUT NOCOPY NUMBER
1217 ,x_message_list OUT NOCOPY VARCHAR2
1218 ,x_return_status OUT NOCOPY VARCHAR2)
1219 IS
1220 l_api_name CONSTANT VARCHAR2(30) := 'INSERT_INCR_ACTUAL_RSRC_TXN';
1221 l_batch_header gme_batch_header%ROWTYPE;
1222 l_rsrc_txn_rec gme_resource_txns%ROWTYPE;
1223 BEGIN
1224 /* Set the savepoint */
1225 SAVEPOINT insert_incr_actual_rsrc_txn;
1226
1227 IF g_debug <> -1 THEN
1228 gme_debug.log_initialize ('InsertIncr');
1229 END IF;
1230 /* Set the return status to success initially */
1231 x_return_status := fnd_api.g_ret_sts_success;
1232 /* Initialize message list and count if needed */
1233 IF p_init_msg_list = fnd_api.g_true THEN
1234 fnd_msg_pub.initialize;
1235 gme_common_pvt.g_error_count := 0;
1236 END IF;
1237
1238 l_rsrc_txn_rec := p_rsrc_txn_rec ;
1239 IF (l_rsrc_txn_rec.organization_id IS NULL AND p_org_code IS NULL) THEN
1240 gme_common_pvt.log_message(p_product_code => 'INV'
1241 ,p_message_code => 'INV_ORG_REQUIRED');
1242 RAISE fnd_api.g_exc_error;
1243 END IF;
1244 gme_common_pvt.g_setup_done :=
1245 gme_common_pvt.setup (p_org_id => l_rsrc_txn_rec.organization_id
1246 ,p_org_code => p_org_code);
1247
1248 IF NOT gme_common_pvt.g_setup_done THEN
1249 RAISE fnd_api.g_exc_error;
1250 ELSE
1251 l_rsrc_txn_rec.organization_id := gme_common_pvt.g_organization_id;
1252 END IF;
1253
1254 /* Make sure we are call compatible */
1255 IF NOT fnd_api.compatible_api_call (2.0
1256 ,p_api_version
1257 ,'insert_incr_actual_rsrc_txn'
1258 ,g_pkg_name) THEN
1259 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
1260 RAISE fnd_api.g_exc_error;
1261 END IF;
1262
1263 /*Validate if org_code or organization_id is passed, or give error.*/
1264 IF p_validate_flexfields = 'T' THEN
1265 gme_common_pvt.g_flex_validate_prof := 1;
1266 ELSE
1267 gme_common_pvt.g_flex_validate_prof := 0;
1268 END IF;
1269 gme_common_pvt.set_timestamp;
1270 IF g_debug <= gme_debug.g_log_procedure THEN
1271 gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
1272 ||'BEFORE CALLING gme_resource_engine_pvt.insert_incr_actual_rsrc_txnp ' );
1273 END IF;
1274 gme_resource_engine_pvt.insert_incr_actual_rsrc_txn
1275 (p_org_code => p_org_code
1276 ,p_batch_no => p_batch_no
1277 ,p_batchstep_no => p_batchstep_no
1278 ,p_activity => p_activity
1279 ,p_resource => p_resource
1280 ,p_instance_no => p_instance_no
1281 ,p_reason_name => p_reason_name
1282 ,p_rsrc_txn_rec => p_rsrc_txn_rec
1283 ,x_rsrc_txn_rec => x_rsrc_txn_rec
1284 ,x_return_status => x_return_status);
1285 --Reset flex global
1286 gme_common_pvt.g_flex_validate_prof := 0;
1287 l_batch_header.batch_id := x_rsrc_txn_rec.doc_id;
1288
1289 IF x_return_status = fnd_api.g_ret_sts_success THEN
1290 IF p_commit = fnd_api.g_true THEN
1291 gme_api_pub.save_batch (p_header_id => NULL
1292 ,p_table => NULL
1293 ,p_commit => fnd_api.g_false
1294 ,x_return_status => x_return_status);
1295
1296 IF x_return_status = fnd_api.g_ret_sts_success THEN
1297 COMMIT;
1298 ELSE
1299 RAISE fnd_api.g_exc_error;
1300 END IF;
1301 END IF;
1302 ELSE
1303 RAISE fnd_api.g_exc_error;
1304 END IF;
1305
1306 IF g_debug <= gme_debug.g_log_procedure THEN
1307 gme_debug.put_line ( 'Insert Incr Actual rsrc usage at '
1308 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
1309 END IF;
1310
1311 gme_common_pvt.log_message ('PM_SAVED_CHANGES');
1312 gme_common_pvt.count_and_get (x_count => x_message_count
1313 ,p_encoded => fnd_api.g_false
1314 ,x_data => x_message_list);
1315 EXCEPTION
1316 WHEN fnd_api.g_exc_error THEN
1317 x_return_status := fnd_api.g_ret_sts_error;
1318 ROLLBACK TO SAVEPOINT insert_incr_actual_rsrc_txn;
1319 gme_common_pvt.count_and_get (x_count => x_message_count
1320 ,p_encoded => fnd_api.g_false
1321 ,x_data => x_message_list);
1322 WHEN OTHERS THEN
1323 ROLLBACK TO SAVEPOINT insert_incr_actual_rsrc_txn;
1324 gme_when_others ( p_api_name => l_api_name
1325 ,x_message_count => x_message_count
1326 ,x_message_list => x_message_list
1327 ,x_return_status => x_return_status );
1328 END insert_incr_actual_rsrc_txn;
1329
1330 /*##########################################################################
1331 # PROCEDURE
1332 # insert_timed_actual_rsrc_txn
1333 # DESCRIPTION
1334 # This procedure calculates the resource usage based on
1335 # difference of p_end_date and p_start_date converted in resource UOM.
1336 # HISTORY
1337 # 10-MAR-2005 Punit Kumar
1338 # Convergence changes
1339 #########################################################################*/
1340 PROCEDURE insert_timed_actual_rsrc_txn (
1341 p_api_version IN NUMBER := 2.0
1342 ,p_validation_level IN NUMBER := gme_common_pvt.g_max_errors
1343 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
1344 ,p_commit IN VARCHAR2 := fnd_api.g_false
1345 ,p_org_code IN VARCHAR2
1346 ,p_batch_no IN VARCHAR2 := NULL
1347 ,p_batchstep_no IN NUMBER := NULL
1348 ,p_activity IN VARCHAR2 := NULL
1349 ,p_resource IN VARCHAR2 := NULL
1350 ,p_instance_no IN NUMBER := NULL
1351 ,p_reason_name IN VARCHAR2 := NULL
1352 ,p_rsrc_txn_rec IN gme_resource_txns%ROWTYPE
1353 ,p_validate_flexfields IN VARCHAR2 := fnd_api.g_false
1354 ,x_rsrc_txn_rec IN OUT NOCOPY gme_resource_txns%ROWTYPE
1355 ,x_message_count OUT NOCOPY NUMBER
1356 ,x_message_list OUT NOCOPY VARCHAR2
1357 ,x_return_status OUT NOCOPY VARCHAR2)
1358 IS
1359 l_api_name CONSTANT VARCHAR2(30) := 'INSERT_TIMED_ACTUAL_RSRC_TXN';
1360 l_batch_header gme_batch_header%ROWTYPE;
1361 l_rsrc_txn_rec gme_resource_txns%ROWTYPE;
1362
1363 BEGIN
1364 /* Set the savepoint */
1365 SAVEPOINT insert_timed_actual_rsrc_txn;
1366 /* Set the return status to success initially */
1367 x_return_status := fnd_api.g_ret_sts_success;
1368 IF g_debug <> -1 THEN
1369 gme_debug.log_initialize ('InsertTimed');
1370 END IF;
1371
1372 /* Initialize message list and count if needed */
1373 IF p_init_msg_list = fnd_api.g_true THEN
1374 fnd_msg_pub.initialize;
1375 gme_common_pvt.g_error_count := 0;
1376 END IF;
1377 l_rsrc_txn_rec := p_rsrc_txn_rec ;
1378 IF (l_rsrc_txn_rec.organization_id IS NULL AND p_org_code IS NULL) THEN
1379 gme_common_pvt.log_message(p_product_code => 'INV'
1380 ,p_message_code => 'INV_ORG_REQUIRED');
1381 RAISE fnd_api.g_exc_error;
1382 END IF;
1383
1384 gme_common_pvt.g_setup_done :=
1385 gme_common_pvt.setup (p_org_id => l_rsrc_txn_rec.organization_id
1386 ,p_org_code => p_org_code);
1387
1388 IF NOT gme_common_pvt.g_setup_done THEN
1389 RAISE fnd_api.g_exc_error;
1390 ELSE
1391 l_rsrc_txn_rec.organization_id := gme_common_pvt.g_organization_id;
1392 END IF;
1393
1394 /* Make sure we are call compatible */
1395 IF NOT fnd_api.compatible_api_call (2.0
1396 ,p_api_version
1397 ,'insert_timed_actual_rsrc_txn'
1398 ,g_pkg_name) THEN
1399 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
1400 RAISE fnd_api.g_exc_error;
1401 END IF;
1402
1403 gme_common_pvt.set_timestamp;
1404
1405 IF p_validate_flexfields = 'T' THEN
1406 gme_common_pvt.g_flex_validate_prof := 1;
1407 ELSE
1408 gme_common_pvt.g_flex_validate_prof := 0;
1409 END IF;
1410
1411 IF g_debug <= gme_debug.g_log_procedure THEN
1412 gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
1413 ||'BEFORE CALLING gme_resource_engine_pvt.insert_timed_actual_rsrc_txnp ');
1414 END IF;
1415
1416 gme_resource_engine_pvt.insert_timed_actual_rsrc_txn
1417 (p_org_code => p_org_code
1418 ,p_batch_no => p_batch_no
1419 ,p_batchstep_no => p_batchstep_no
1420 ,p_activity => p_activity
1421 ,p_resource => p_resource
1422 ,p_instance_no => p_instance_no
1423 ,p_reason_name => p_reason_name
1424 ,p_rsrc_txn_rec => p_rsrc_txn_rec
1425 ,x_rsrc_txn_rec => x_rsrc_txn_rec
1426 ,x_return_status => x_return_status);
1427 --Reset flex global
1428 gme_common_pvt.g_flex_validate_prof := 0;
1429 l_batch_header.batch_id := x_rsrc_txn_rec.doc_id;
1430
1431 IF x_return_status = fnd_api.g_ret_sts_success THEN
1432 IF p_commit = fnd_api.g_true THEN
1433 gme_api_pub.save_batch (p_header_id => NULL
1434 ,p_table => NULL
1435 ,p_commit => fnd_api.g_false
1436 ,x_return_status => x_return_status);
1437
1438 IF x_return_status = fnd_api.g_ret_sts_success THEN
1439 COMMIT;
1440 ELSE
1441 RAISE fnd_api.g_exc_error;
1442 END IF;
1443 END IF;
1444 ELSE
1445 RAISE fnd_api.g_exc_error;
1446 END IF;
1447
1448 IF g_debug <= gme_debug.g_log_procedure THEN
1449 gme_debug.put_line ( 'Insert timed Actual rsrc usage at '
1450 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
1451 END IF;
1452
1453 gme_common_pvt.log_message ('PM_SAVED_CHANGES');
1454 gme_common_pvt.count_and_get (x_count => x_message_count
1455 ,p_encoded => fnd_api.g_false
1456 ,x_data => x_message_list);
1457 EXCEPTION
1458 WHEN fnd_api.g_exc_error THEN
1459 x_return_status := fnd_api.g_ret_sts_error;
1460 ROLLBACK TO SAVEPOINT insert_timed_actual_rsrc_txn;
1461 gme_common_pvt.count_and_get (x_count => x_message_count
1462 ,p_encoded => fnd_api.g_false
1463 ,x_data => x_message_list);
1464 WHEN OTHERS THEN
1465 ROLLBACK TO SAVEPOINT insert_timed_actual_rsrc_txn;
1466 gme_when_others ( p_api_name => l_api_name
1467 ,x_message_count => x_message_count
1468 ,x_message_list => x_message_list
1469 ,x_return_status => x_return_status );
1470 END insert_timed_actual_rsrc_txn;
1471
1472 /*##########################################################################
1473 # PROCEDURE
1474 # start_cmplt_actual_rsrc_txn
1475 # DESCRIPTION
1476 # This Api is used to state that a resource has started, and
1477 # creates a transaction row in the resource transactions table.
1478 # At a later time this transaction is updated with the usage
1479 # by calling gme_api_pub.end_cmplt_actual_rsrc_txn (It passes
1480 # the end date and the usage is calculated as diferrence between
1481 # end_date and start_date)
1482 # HISTORY
1483 # 10-MAR-2005 Punit Kumar
1484 # Convergence changes
1485 # Pawan kumar corrected check for organization_id and various parameters
1486 #########################################################################*/
1487 PROCEDURE start_cmplt_actual_rsrc_txn (
1488 p_api_version IN NUMBER := 2.0
1489 ,p_validation_level IN NUMBER
1490 := gme_common_pvt.g_max_errors
1491 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
1492 ,p_commit IN VARCHAR2 := fnd_api.g_false
1493 ,p_org_code IN VARCHAR2
1494 ,p_batch_no IN VARCHAR2 := NULL
1495 ,p_batchstep_no IN NUMBER := NULL
1496 ,p_activity IN VARCHAR2 := NULL
1497 ,p_resource IN VARCHAR2 := NULL
1498 ,p_instance_no IN NUMBER
1499 ,p_reason_name IN VARCHAR2 := NULL
1500 ,p_rsrc_txn_rec IN gme_resource_txns%ROWTYPE
1501 ,p_validate_flexfields IN VARCHAR2 := fnd_api.g_false
1502 ,x_rsrc_txn_rec IN OUT NOCOPY gme_resource_txns%ROWTYPE
1503 ,x_message_count OUT NOCOPY NUMBER
1504 ,x_message_list OUT NOCOPY VARCHAR2
1505 ,x_return_status OUT NOCOPY VARCHAR2)
1506 IS
1507 l_api_name CONSTANT VARCHAR2(30) := 'START_CMPLT_ACTUAL_RSRC_TXN';
1508 l_batch_header gme_batch_header%ROWTYPE;
1509 l_rsrc_txn_rec gme_resource_txns%ROWTYPE;
1510
1511 BEGIN
1512 /* Set the savepoint */
1513 SAVEPOINT start_cmplt_actual_rsrc_txn;
1514 /* Set the return status to success initially */
1515 x_return_status := fnd_api.g_ret_sts_success;
1516 IF g_debug <> -1 THEN
1517 gme_debug.log_initialize ('StartCmplt');
1518 END IF;
1519
1520 /* Initialize message list and count if needed */
1521 IF p_init_msg_list = fnd_api.g_true THEN
1522 fnd_msg_pub.initialize;
1523 gme_common_pvt.g_error_count := 0;
1524 END IF;
1525 l_rsrc_txn_rec := p_rsrc_txn_rec ;
1526 IF (l_rsrc_txn_rec.organization_id IS NULL AND p_org_code IS NULL) THEN
1527 gme_common_pvt.log_message(p_product_code => 'INV'
1528 ,p_message_code => 'INV_ORG_REQUIRED');
1529 RAISE fnd_api.g_exc_error;
1530 END IF;
1531 gme_common_pvt.g_setup_done :=
1532 gme_common_pvt.setup (p_org_id => l_rsrc_txn_rec.organization_id
1533 ,p_org_code => p_org_code);
1534 IF NOT gme_common_pvt.g_setup_done THEN
1535 RAISE fnd_api.g_exc_error;
1536 ELSE
1537 l_rsrc_txn_rec.organization_id := gme_common_pvt.g_organization_id;
1538 END IF;
1539
1540 /* Make sure we are call compatible */
1541 IF NOT fnd_api.compatible_api_call (2.0,p_api_version,
1542 'start_cmplt_actual_rsrc_txn',g_pkg_name) THEN
1543 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
1544 RAISE fnd_api.g_exc_error;
1545 END IF;
1546 gme_common_pvt.set_timestamp;
1547 IF p_validate_flexfields = 'T' THEN
1548 gme_common_pvt.g_flex_validate_prof := 1;
1549 ELSE
1550 gme_common_pvt.g_flex_validate_prof := 0;
1551 END IF;
1552
1553 IF g_debug <= gme_debug.g_log_procedure THEN
1554 gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
1555 ||'BEFORE CALLING gme_resource_engine_pvt.start_cmplt_actual_rsrc_txnp ' );
1556 END IF;
1557
1558 gme_resource_engine_pvt.start_cmplt_actual_rsrc_txn
1559 (p_org_code => p_org_code
1560 ,p_batch_no => p_batch_no
1561 ,p_batchstep_no => p_batchstep_no
1562 ,p_activity => p_activity
1563 ,p_resource => p_resource
1564 ,p_instance_no => p_instance_no
1565 ,p_reason_name => p_reason_name
1566 ,p_rsrc_txn_rec => l_rsrc_txn_rec
1567 ,x_rsrc_txn_rec => x_rsrc_txn_rec
1568 ,x_return_status => x_return_status);
1569 -----Reset flex global
1570 gme_common_pvt.g_flex_validate_prof := 0;
1571 l_batch_header.batch_id := x_rsrc_txn_rec.doc_id;
1572
1573 /*end */
1574 IF x_return_status = fnd_api.g_ret_sts_success THEN
1575 IF p_commit = fnd_api.g_true THEN
1576 gme_api_pub.save_batch (p_header_id => NULL
1577 ,p_table => NULL
1578 ,p_commit => fnd_api.g_false
1579 ,x_return_status => x_return_status);
1580
1581 IF x_return_status = fnd_api.g_ret_sts_success THEN
1582 COMMIT;
1583 ELSE
1584 RAISE fnd_api.g_exc_error;
1585 END IF;
1586 END IF;
1587 ELSE
1588 RAISE fnd_api.g_exc_error;
1589 END IF;
1590
1591 IF g_debug <= gme_debug.g_log_procedure THEN
1592 gme_debug.put_line ( 'start Actual rsrc txn at '
1593 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
1594 END IF;
1595
1596 gme_common_pvt.log_message ('PM_SAVED_CHANGES');
1597 gme_common_pvt.count_and_get (x_count => x_message_count
1598 ,p_encoded => fnd_api.g_false
1599 ,x_data => x_message_list);
1600 EXCEPTION
1601 WHEN fnd_api.g_exc_error THEN
1602 x_return_status := fnd_api.g_ret_sts_error;
1603 ROLLBACK TO SAVEPOINT start_cmplt_actual_rsrc_txn;
1604 gme_common_pvt.count_and_get (x_count => x_message_count
1605 ,p_encoded => fnd_api.g_false
1606 ,x_data => x_message_list);
1607 WHEN OTHERS THEN
1608 ROLLBACK TO SAVEPOINT start_cmplt_actual_rsrc_txn;
1609 gme_when_others ( p_api_name => l_api_name
1610 ,x_message_count => x_message_count
1611 ,x_message_list => x_message_list
1612 ,x_return_status => x_return_status );
1613 END start_cmplt_actual_rsrc_txn;
1614
1615 /*##########################################################################
1616 # PROCEDURE
1617 # end_cmplt_actual_rsrc_txn
1618 # DESCRIPTION
1619 # This particular procedure is used to end a started completed
1620 # rsrc txn row and calculates the usage from rsrc txn date,
1621 # for non asqc batch and batch step is in WIP or Completed state
1622 # HISTORY :
1623 # 10-MAR-2005 Punit Kumar
1624 # Convergence changes
1625 #########################################################################*/
1626 PROCEDURE end_cmplt_actual_rsrc_txn (
1627 p_api_version IN NUMBER := 2.0
1628 ,p_validation_level IN NUMBER := gme_common_pvt.g_max_errors
1629 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
1630 ,p_commit IN VARCHAR2 := fnd_api.g_false
1631 ,p_instance_no IN NUMBER := NULL
1632 ,p_reason_name IN VARCHAR2 := NULL
1633 ,p_rsrc_txn_rec IN gme_resource_txns%ROWTYPE
1634 ,p_validate_flexfields IN VARCHAR2 := fnd_api.g_false
1635 ,x_rsrc_txn_rec IN OUT NOCOPY gme_resource_txns%ROWTYPE
1636 ,x_message_count OUT NOCOPY NUMBER
1637 ,x_message_list OUT NOCOPY VARCHAR2
1638 ,x_return_status OUT NOCOPY VARCHAR2)
1639 IS
1640 l_api_name CONSTANT VARCHAR2(30) := 'END_CMPLT_ACTUAL_RSRC_TXN';
1641 l_batch_header gme_batch_header%ROWTYPE;
1642 l_rsrc_txn_rec gme_resource_txns%ROWTYPE;
1643 BEGIN
1644 /* Set the savepoint */
1645 SAVEPOINT end_cmplt_actual_rsrc_txn;
1646
1647 IF g_debug <> -1 THEN
1648 gme_debug.log_initialize ('EndCmplt');
1649 END IF;
1650
1651 /* Initialize message list and count if needed */
1652 IF p_init_msg_list = fnd_api.g_true THEN
1653 fnd_msg_pub.initialize;
1654 gme_common_pvt.g_error_count := 0;
1655 END IF;
1656 /* Set the return status to success initially */
1657 x_return_status := fnd_api.g_ret_sts_success;
1658 l_rsrc_txn_rec := p_rsrc_txn_rec;
1659 IF (l_rsrc_txn_rec.organization_id IS NULL ) THEN
1660 gme_common_pvt.log_message(p_product_code => 'INV'
1661 ,p_message_code => 'INV_ORG_REQUIRED');
1662 RAISE fnd_api.g_exc_error;
1663 END IF;
1664 /* Setup the common constants used accross the apis */
1665 gme_common_pvt.g_setup_done :=
1666 gme_common_pvt.setup (p_org_id => l_rsrc_txn_rec.organization_id
1667 ,p_org_code => null);
1668
1669 IF NOT gme_common_pvt.g_setup_done THEN
1670 RAISE fnd_api.g_exc_error;
1671 ELSE
1672 l_rsrc_txn_rec.organization_id := gme_common_pvt.g_organization_id;
1673 END IF;
1674
1675 /* Make sure we are call compatible */
1676 IF NOT fnd_api.compatible_api_call (2.0
1677 ,p_api_version
1678 ,'end_cmplt_actual_rsrc_txn'
1679 ,g_pkg_name) THEN
1680 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
1681 RAISE fnd_api.g_exc_error;
1682 END IF;
1683 gme_common_pvt.set_timestamp;
1684 IF p_validate_flexfields = 'T' THEN
1685 gme_common_pvt.g_flex_validate_prof := 1;
1686 ELSE
1687 gme_common_pvt.g_flex_validate_prof := 0;
1688 END IF;
1689
1690 IF g_debug <= gme_debug.g_log_procedure THEN
1691 gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
1692 ||'CALLING gme_resource_engine_pvt.end_cmplt_actual_rsrc_txnp ');
1693 END IF;
1694
1695 gme_resource_engine_pvt.end_cmplt_actual_rsrc_txn
1696 (p_instance_no => p_instance_no
1697 ,p_reason_name => p_reason_name
1698 ,p_rsrc_txn_rec => p_rsrc_txn_rec
1699 ,x_rsrc_txn_rec => x_rsrc_txn_rec
1700 ,x_return_status => x_return_status);
1701
1702 gme_common_pvt.g_flex_validate_prof := 0;
1703 l_batch_header.batch_id := x_rsrc_txn_rec.doc_id;
1704
1705 /* end */
1706 IF x_return_status = fnd_api.g_ret_sts_success THEN
1707 IF p_commit = fnd_api.g_true THEN
1708 gme_api_pub.save_batch (p_header_id => NULL
1709 ,p_table => NULL
1710 ,p_commit => fnd_api.g_false
1711 ,x_return_status => x_return_status);
1712
1713 IF x_return_status = fnd_api.g_ret_sts_success THEN
1714 COMMIT;
1715 ELSE
1716 RAISE fnd_api.g_exc_error;
1717 END IF;
1718 END IF;
1719 ELSE
1720 RAISE fnd_api.g_exc_error;
1721 END IF;
1722
1723 IF g_debug <= gme_debug.g_log_procedure THEN
1724 gme_debug.put_line ( 'Insert Incr Actual rsrc usage at '
1725 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
1726 END IF;
1727
1728 gme_common_pvt.log_message ('PM_SAVED_CHANGES');
1729 gme_common_pvt.count_and_get (x_count => x_message_count
1730 ,p_encoded => fnd_api.g_false
1731 ,x_data => x_message_list);
1732 EXCEPTION
1733 WHEN fnd_api.g_exc_error THEN
1734 x_return_status := fnd_api.g_ret_sts_error;
1735 ROLLBACK TO SAVEPOINT end_cmplt_actual_rsrc_txn;
1736 gme_common_pvt.count_and_get (x_count => x_message_count
1737 ,p_encoded => fnd_api.g_false
1738 ,x_data => x_message_list);
1739 WHEN OTHERS THEN
1740 ROLLBACK TO SAVEPOINT end_cmplt_actual_rsrc_txn;
1741 gme_when_others ( p_api_name => l_api_name
1742 ,x_message_count => x_message_count
1743 ,x_message_list => x_message_list
1744 ,x_return_status => x_return_status );
1745 END end_cmplt_actual_rsrc_txn;
1746
1747 /*************************************************************************/
1748 PROCEDURE reschedule_batch (
1749 p_api_version IN NUMBER := 2.0
1750 ,p_validation_level IN NUMBER
1751 ,p_init_msg_list IN VARCHAR2
1752 ,p_commit IN VARCHAR2
1753 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
1754 ,p_use_workday_cal IN VARCHAR2
1755 ,p_contiguity_override IN VARCHAR2
1756 ,p_org_code IN VARCHAR2
1757 ,x_message_count OUT NOCOPY NUMBER
1758 ,x_message_list OUT NOCOPY VARCHAR2
1759 ,x_return_status OUT NOCOPY VARCHAR2
1760 ,x_batch_header_rec OUT NOCOPY gme_batch_header%ROWTYPE)
1761 IS
1762 l_api_name CONSTANT VARCHAR2 (30) := 'RESCHEDULE_BATCH';
1763 reschedule_batch_failed EXCEPTION;
1764 batch_save_failed EXCEPTION;
1765 l_return_status VARCHAR2 (1);
1766 l_use VARCHAR2 (1);
1767 l_batch_header_rec gme_batch_header%ROWTYPE;
1768 BEGIN
1769 IF g_debug <> -1 THEN
1770 gme_debug.log_initialize ('RescheduleBatch');
1771 END IF;
1772
1773 IF (g_debug IN (gme_debug.g_log_statement, gme_debug.g_log_procedure) ) THEN
1774 gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
1775 || 'Entering');
1776 END IF;
1777
1778 /* Set the return status to success initially */
1779 x_return_status := fnd_api.g_ret_sts_success;
1780
1781 /* Set savepoint here */
1782 SAVEPOINT reschedule_batch;
1783
1784 /* Initialize message list and count if needed */
1785 IF p_init_msg_list = fnd_api.g_true THEN
1786 fnd_msg_pub.initialize;
1787 END IF;
1788 gme_common_pvt.validate_batch
1789 (p_batch_header_rec => p_batch_header_rec
1790 ,p_org_code => p_org_code
1791 ,p_batch_type => nvl(p_batch_header_rec.batch_type,gme_common_pvt.g_doc_type_batch)
1792 ,x_batch_header_rec => l_batch_header_rec
1793 ,x_message_count => x_message_count
1794 ,x_message_list => x_message_list
1795 ,x_return_status => x_return_status );
1796
1797 IF x_return_status <> fnd_api.g_ret_sts_success THEN
1798 IF (g_debug = gme_debug.g_log_statement) THEN
1799 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
1800 || ': batch validate error ');
1801 END IF;
1802 RAISE fnd_api.g_exc_error;
1803 END IF;
1804
1805 /* Make sure we are call compatible */
1806 IF NOT fnd_api.compatible_api_call (2.0
1807 ,p_api_version
1808 ,'reschedule_batch'
1809 ,g_pkg_name) THEN
1810 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
1811 RAISE fnd_api.g_exc_error;
1812 END IF;
1813
1814 IF g_debug <= gme_debug.g_log_procedure THEN
1815 gme_debug.put_line ( ' Value of Plan_start_date : ' || TO_CHAR
1816 (l_batch_header_rec.plan_start_date ,'DD-MON-YYYY HH24:MI:SS') || ',
1817 Plan_cmplt_date : ' || TO_CHAR (l_batch_header_rec.plan_cmplt_date
1818 ,'DD-MON-YYYY HH24:MI:SS') || ', Batch_status '
1819 || l_batch_header_rec.batch_status);
1820 END IF;
1821
1822 IF l_batch_header_rec.plan_start_date IS NULL
1823 AND l_batch_header_rec.plan_cmplt_date IS NULL THEN
1824 gme_common_pvt.log_message ('GME_NO_NULL_DATES');
1825 RAISE fnd_api.g_exc_error;
1826 END IF;
1827
1828 IF (l_batch_header_rec.batch_status = gme_common_pvt.g_batch_pending) THEN
1829 IF l_batch_header_rec.plan_start_date IS NOT NULL
1830 AND l_batch_header_rec.plan_cmplt_date IS NOT NULL
1831 AND l_batch_header_rec.plan_start_date >
1832 l_batch_header_rec.plan_cmplt_date THEN
1833 --Bug#5439736 replaced the message
1834 gme_common_pvt.log_message ('GME_CMPLT_START_DT');
1835 RAISE fnd_api.g_exc_error;
1836 END IF;
1837 ELSIF (l_batch_header_rec.batch_status = gme_common_pvt.g_batch_wip) THEN
1838 IF l_batch_header_rec.plan_cmplt_date IS NULL THEN
1839 gme_common_pvt.log_message ('GME_NO_CMPLTDATE_FOR_WIP');
1840 RAISE fnd_api.g_exc_error;
1841 ELSE
1842 IF NVL (l_batch_header_rec.plan_start_date
1843 ,l_batch_header_rec.plan_start_date) <>
1844 l_batch_header_rec.plan_start_date THEN
1845 gme_common_pvt.log_message ('GME_NO_PLAN_DT_UPD');
1846 RAISE fnd_api.g_exc_error;
1847 END IF;
1848
1849 IF l_batch_header_rec.plan_cmplt_date <
1850 l_batch_header_rec.plan_start_date THEN
1851 gme_common_pvt.log_message ('GME_CMPLT_START_DT');
1852 RAISE fnd_api.g_exc_error;
1853 END IF;
1854 END IF;
1855 ELSE /* batch status other than pending, WIP */
1856 -- Batch cannot be rescheduled. Batch must have a status of pending or WIP to be rescheduled.
1857 gme_common_pvt.log_message ('GME_API_INV_BATCH_RESCHED');
1858 RAISE fnd_api.g_exc_error;
1859 END IF;
1860 /* Check plan_start_date > plan_cmplt_date if batch_status = pending */
1861 IF p_use_workday_cal IS NOT NULL THEN
1862 IF p_use_workday_cal IN (fnd_api.g_true, fnd_api.g_false) THEN
1863 l_use := p_use_workday_cal;
1864 ELSE
1865 gme_common_pvt.log_message ('GME_INVALID_VALUE_SPECIFIED'
1866 ,'FIELD_NAME'
1867 ,'p_use_workday_cal');
1868 RAISE fnd_api.g_exc_error;
1869 END IF;
1870 IF p_contiguity_override IS NOT NULL THEN
1871 IF p_contiguity_override NOT IN
1872 (fnd_api.g_true, fnd_api.g_false) THEN
1873 gme_common_pvt.log_message ('GME_INVALID_VALUE_SPECIFIED'
1874 ,'FIELD_NAME'
1875 ,'p_contiguity_override');
1876 RAISE fnd_api.g_exc_error;
1877 END IF;
1878 END IF;
1879 ELSE
1880 l_use := fnd_api.g_false;
1881 END IF; /* p_use_workday_cal IS NOT NULL */
1882
1883 IF l_use = fnd_api.g_true THEN
1884 IF (gme_common_pvt.g_calendar_code IS NOT NULL) THEN
1885 -- Check if plan_start_date falls on non working day for pending batch.
1886 IF l_batch_header_rec.batch_status =
1887 gme_common_pvt.g_batch_pending
1888 AND l_batch_header_rec.plan_start_date IS NOT NULL THEN
1889 IF NOT gmp_calendar_api.is_working_daytime
1890 (1.0
1891 ,FALSE
1892 ,gme_common_pvt.g_calendar_code
1893 ,l_batch_header_rec.plan_start_date
1894 ,0
1895 ,l_return_status) THEN
1896 gme_common_pvt.log_message
1897 ('GME_NON_WORKING_TIME'
1898 ,'PDATE'
1899 ,TO_CHAR (l_batch_header_rec.plan_start_date
1900 ,'DD-MON-YYYY HH24:MI:SS') );
1901 RAISE fnd_api.g_exc_error;
1902 END IF;
1903 END IF;
1904
1905 /* l_batch_header_rec.batch_status = gme_common_pvt.g_batch_pending */
1906
1907 -- Check if plan_cmplt_date falls on non working day for pending and WIP batch.
1908 IF l_batch_header_rec.batch_status IN
1909 (gme_common_pvt.g_batch_pending
1910 ,gme_common_pvt.g_batch_wip)
1911 AND l_batch_header_rec.plan_cmplt_date IS NOT NULL THEN
1912 IF NOT gmp_calendar_api.is_working_daytime
1913 (1.0
1914 ,FALSE
1915 ,gme_common_pvt.g_calendar_code
1916 ,l_batch_header_rec.plan_cmplt_date
1917 ,1
1918 ,l_return_status) THEN
1919 gme_common_pvt.log_message
1920 ('GME_NON_WORKING_TIME'
1921 ,'PDATE'
1922 ,TO_CHAR (l_batch_header_rec.plan_cmplt_date
1923 ,'DD-MON-YYYY HH24:MI:SS') );
1924 RAISE fnd_api.g_exc_error;
1925 END IF;
1926 END IF;
1927
1928 /* l_batch_header_rec.batch_status IN (gme_common_pvt.g_batch_pending, gme_common_pvt.g_batch_wip) */
1929 IF l_batch_header_rec.plan_cmplt_date IS NULL
1930 AND l_batch_header_rec.plan_start_date IS NULL THEN
1931 IF NOT gmp_calendar_api.is_working_daytime
1932 (1.0
1933 ,FALSE
1934 ,gme_common_pvt.g_calendar_code
1935 ,SYSDATE
1936 ,0
1937 ,l_return_status) THEN
1938 gme_common_pvt.log_message ('GME_NON_WORKING_TIME' ,'PDATE'
1939 ,TO_CHAR (SYSDATE,'DD-MON-YYYY HH24:MI:SS') );
1940 RAISE fnd_api.g_exc_error;
1941 END IF;
1942 END IF; /* l_batch_header_rec.plan_cmplt_date IS NULL */
1943 END IF; /* (gme_common_pvt.g_calendar_code IS NOT NULL) */
1944 END IF; /* l_use = FND_API.G_TRUE */
1945
1946 IF (g_debug = gme_debug.g_log_statement) THEN
1947 gme_debug.put_line ( g_pkg_name || '.' || l_api_name || ':'
1948 || 'Calling Main Reschedule Batch');
1949 END IF;
1950
1951 l_batch_header_rec.plan_start_date := p_batch_header_rec.plan_start_date;
1952 gme_api_main.reschedule_batch
1953 (p_validation_level => p_validation_level
1954 ,p_init_msg_list => fnd_api.g_false
1955 ,p_batch_header_rec => l_batch_header_rec
1956 ,p_use_workday_cal => l_use
1957 ,p_contiguity_override => p_contiguity_override
1958 ,x_message_count => x_message_count
1959 ,x_message_list => x_message_list
1960 ,x_return_status => x_return_status
1961 ,x_batch_header_rec => x_batch_header_rec);
1962
1963 IF (g_debug = gme_debug.g_log_statement) THEN
1964 gme_debug.put_line
1965 ( 'Came back from Main Reschedule Batch with status '
1966 || x_return_status);
1967 END IF;
1968
1969 IF x_return_status <> fnd_api.g_ret_sts_success THEN
1970 RAISE reschedule_batch_failed;
1971 ELSE
1972 IF p_commit = fnd_api.g_true THEN
1973 gme_api_pub.save_batch (p_header_id => NULL
1974 ,p_table => NULL
1975 ,p_commit => fnd_api.g_false
1976 ,x_return_status => x_return_status);
1977
1978 IF x_return_status = fnd_api.g_ret_sts_success THEN
1979 COMMIT;
1980 ELSE
1981 RAISE fnd_api.g_exc_error;
1982 END IF;
1983 END IF;
1984 END IF;
1985
1986 IF g_debug <= gme_debug.g_log_procedure THEN
1987 gme_debug.put_line ( g_pkg_name || '.' || l_api_name || ':' ||
1988 'Exiting with ' || x_return_status || ' at '
1989 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
1990 END IF;
1991 EXCEPTION
1992 WHEN fnd_api.g_exc_error THEN
1993 ROLLBACK TO SAVEPOINT reschedule_batch;
1994 x_batch_header_rec := NULL;
1995 x_return_status := fnd_api.g_ret_sts_error;
1996 gme_common_pvt.count_and_get (x_count => x_message_count
1997 ,p_encoded => fnd_api.g_false
1998 ,x_data => x_message_list);
1999 WHEN reschedule_batch_failed THEN
2000 ROLLBACK TO SAVEPOINT reschedule_batch;
2001 x_batch_header_rec := NULL;
2002 gme_common_pvt.count_and_get (x_count => x_message_count
2003 ,p_encoded => fnd_api.g_false
2004 ,x_data => x_message_list);
2005 WHEN OTHERS THEN
2006 ROLLBACK TO SAVEPOINT reschedule_batch;
2007 x_batch_header_rec := NULL;
2008 gme_when_others ( p_api_name => l_api_name
2009 ,x_message_count => x_message_count
2010 ,x_message_list => x_message_list
2011 ,x_return_status => x_return_status );
2012 END reschedule_batch;
2013
2014 /*************************************************************************/
2015 PROCEDURE reschedule_step (
2016 p_api_version IN NUMBER := 2.0
2017 ,p_validation_level IN NUMBER
2018 ,p_init_msg_list IN VARCHAR2
2019 ,p_commit IN VARCHAR2
2020 ,p_batch_step_rec IN gme_batch_steps%ROWTYPE
2021 ,p_use_workday_cal IN VARCHAR2
2022 ,p_contiguity_override IN VARCHAR2
2023 ,p_org_code IN VARCHAR2
2024 ,p_batch_no IN VARCHAR2
2025 ,p_batch_type IN NUMBER
2026 ,p_reschedule_preceding IN VARCHAR2
2027 ,p_reschedule_succeeding IN VARCHAR2
2028 ,x_message_count OUT NOCOPY NUMBER
2029 ,x_message_list OUT NOCOPY VARCHAR2
2030 ,x_return_status OUT NOCOPY VARCHAR2
2031 ,x_batch_step_rec OUT NOCOPY gme_batch_steps%ROWTYPE)
2032 IS
2033 l_api_name CONSTANT VARCHAR2 (30) := 'RESCHEDULE_STEP';
2034 l_diff NUMBER := 0;
2035 l_diff_cmplt NUMBER := 0;
2036 reschedule_step_failed EXCEPTION;
2037 l_batch_header_rec gme_batch_header%ROWTYPE;
2038 l_batch_step_rec gme_batch_steps%ROWTYPE;
2039 l_use VARCHAR2 (1);
2040 l_return_status VARCHAR2 (1);
2041 l_reschedule_preceding VARCHAR2 (1);
2042 l_reschedule_succeeding VARCHAR2 (1);
2043 BEGIN
2044 IF g_debug <> -1 THEN
2045 gme_debug.log_initialize ('RescheduleStep');
2046 END IF;
2047
2048 IF (g_debug IN
2049 (gme_debug.g_log_statement, gme_debug.g_log_procedure) ) THEN
2050 gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
2051 || 'Entering');
2052 END IF;
2053
2054 /* Set the return status to success initially */
2055 x_return_status := fnd_api.g_ret_sts_success;
2056
2057 /* Set savepoint here */
2058 SAVEPOINT reschedule_step;
2059
2060 /* Initialize message list and count if needed */
2061 IF p_init_msg_list = fnd_api.g_true THEN
2062 fnd_msg_pub.initialize;
2063 END IF;
2064
2065 /* Validate Input parameters */
2066 gme_common_pvt.Validate_batch_step (
2067 p_batch_step_rec => p_batch_step_rec
2068 ,p_org_code => p_org_code
2069 ,p_batch_no => p_batch_no
2070 ,x_batch_step_rec => l_batch_step_rec
2071 ,x_batch_header_rec => l_batch_header_rec
2072 ,x_message_count => x_message_count
2073 ,x_message_list => x_message_list
2074 ,x_return_status => x_return_status) ;
2075
2076 IF x_return_status <> fnd_api.g_ret_sts_success THEN
2077 IF (g_debug = gme_debug.g_log_statement) THEN
2078 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
2079 || ': batch step validate error ');
2080 END IF;
2081 RAISE fnd_api.g_exc_error;
2082 END IF;
2083
2084 /* Make sure we are call compatible */
2085 IF NOT fnd_api.compatible_api_call (2.0
2086 ,p_api_version
2087 ,'reschedule_batch_step'
2088 ,g_pkg_name) THEN
2089 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
2090 RAISE fnd_api.g_exc_error;
2091 END IF;
2092
2093 /* Navin: Check whether both l_batch_step_rec.plan_start_date, l_batch_step_rec.plan_cmplt_date are null. If so, RAISE error; */
2094 IF p_batch_step_rec.plan_start_date IS NULL
2095 AND p_batch_step_rec.plan_cmplt_date IS NULL THEN
2096 -- Both planned start and planned completion dates cannot be null.
2097 gme_common_pvt.log_message ('GME_NO_NULL_DATES');
2098 RAISE fnd_api.g_exc_error;
2099 END IF;
2100
2101 IF p_batch_type = gme_common_pvt.g_doc_type_fpo THEN
2102 -- You cannot reschedule steps for firm planned orders.
2103 gme_common_pvt.log_message ('GME_FPO_STEP_RESCH_ERR');
2104 -- Navin: PENDING: New Message
2105 RAISE fnd_api.g_exc_error;
2106 END IF;
2107
2108 IF p_reschedule_preceding NOT IN (fnd_api.g_true, fnd_api.g_false) THEN
2109 gme_common_pvt.log_message ('GME_INVALID_VALUE_SPECIFIED'
2110 ,'FIELD_NAME'
2111 ,'p_reschedule_preceding');
2112 RAISE fnd_api.g_exc_error;
2113 END IF;
2114
2115 IF p_reschedule_succeeding NOT IN (fnd_api.g_true, fnd_api.g_false) THEN
2116 gme_common_pvt.log_message ('GME_INVALID_VALUE_SPECIFIED'
2117 ,'FIELD_NAME'
2118 ,'p_reschedule_succeeding');
2119 RAISE fnd_api.g_exc_error;
2120 END IF;
2121
2122 l_batch_step_rec.plan_start_date := p_batch_step_rec.plan_start_date;
2123 l_batch_step_rec.plan_cmplt_date := p_batch_step_rec.plan_cmplt_date;
2124 /* Navin: Check plan_start_date > plan_cmplt_date if step_status = pending */
2125 IF (l_batch_step_rec.step_status = gme_common_pvt.g_batch_pending) THEN
2126 IF l_batch_step_rec.plan_start_date IS NOT NULL
2127 AND l_batch_step_rec.plan_cmplt_date IS NOT NULL
2128 AND l_batch_step_rec.plan_start_date >
2129 l_batch_step_rec.plan_cmplt_date THEN
2130 -- The planned start cannot be greater than the planned completion date.
2131 gme_common_pvt.log_message ('GME_CMPLT_START_DT');
2132 -- Navin: PENDING: New Message
2133 RAISE fnd_api.g_exc_error;
2134 END IF;
2135 ELSIF (l_batch_step_rec.step_status = gme_common_pvt.g_batch_wip) THEN
2136 IF l_batch_step_rec.plan_cmplt_date IS NULL THEN
2137 -- Planned completion dates cannot be null for a batch with status of WIP.
2138 gme_common_pvt.log_message ('GME_NO_CMPLTDATE_FOR_WIP');
2139 -- Navin: PENDING: New Message
2140 RAISE fnd_api.g_exc_error;
2141 ELSE
2142 IF NVL (l_batch_step_rec.plan_start_date
2143 ,l_batch_step_rec.plan_start_date) <>
2144 l_batch_step_rec.plan_start_date THEN
2145 -- Cannot update planned start date.
2146 gme_common_pvt.log_message ('GME_NO_PLAN_DT_UPD');
2147 -- Navin: PENDING: New Message
2148 RAISE fnd_api.g_exc_error;
2149 END IF;
2150
2151 IF l_batch_step_rec.plan_cmplt_date <
2152 l_batch_step_rec.plan_start_date THEN
2153 -- Planned completion date cannot be earlier than the planned start date.
2154 gme_common_pvt.log_message ('GME_CMPLT_START_DT');
2155 -- Navin: PENDING: New Message
2156 RAISE fnd_api.g_exc_error;
2157 END IF;
2158 END IF;
2159 ELSE /*step status other than pending, WIP */
2160 --Bug#5439736
2161 gme_common_pvt.log_message ('GME_API_INV_STEP_STAT_RESCH');
2162 RAISE fnd_api.g_exc_error;
2163 END IF;
2164
2165 -- When enforce_step_dependency option is enforced then override Reschedule_preceding, Reschedule_succeeding fields.
2166 IF l_batch_header_rec.enforce_step_dependency = 1 THEN
2167 l_reschedule_preceding := fnd_api.g_true;
2168 l_reschedule_succeeding := fnd_api.g_true;
2169 ELSE
2170 l_reschedule_preceding := p_reschedule_preceding;
2171 l_reschedule_succeeding := p_reschedule_succeeding;
2172 END IF;
2173
2174 IF p_use_workday_cal IS NOT NULL THEN
2175 IF p_use_workday_cal IN (fnd_api.g_true, fnd_api.g_false) THEN
2176 l_use := p_use_workday_cal;
2177 ELSE
2178 gme_common_pvt.log_message ('GME_INVALID_VALUE_SPECIFIED'
2179 ,'FIELD_NAME'
2180 ,'p_use_workday_cal');
2181 RAISE fnd_api.g_exc_error;
2182 END IF;
2183
2184 IF p_contiguity_override IS NOT NULL THEN
2185 IF p_contiguity_override NOT IN
2186 (fnd_api.g_true, fnd_api.g_false) THEN
2187 gme_common_pvt.log_message ('GME_INVALID_VALUE_SPECIFIED'
2188 ,'FIELD_NAME'
2189 ,'p_contiguity_override');
2190 RAISE fnd_api.g_exc_error;
2191 END IF;
2192 END IF; /* p_contiguity_override */
2193 ELSE
2194 l_use := fnd_api.g_false;
2195 END IF; /* p_use_workday_cal IS NOT NULL */
2196
2197 IF l_use = fnd_api.g_true THEN
2198 IF (gme_common_pvt.g_calendar_code IS NOT NULL) THEN
2199 -- Check if plan_start_date falls on non working day for pending batch step.
2200 IF l_batch_step_rec.step_status =
2201 gme_common_pvt.g_step_pending
2202 AND l_batch_step_rec.plan_start_date IS NOT NULL THEN
2203 IF NOT gmp_calendar_api.is_working_daytime
2204 (1.0
2205 ,FALSE
2206 ,gme_common_pvt.g_calendar_code
2207 ,l_batch_step_rec.plan_start_date
2208 ,0
2209 ,l_return_status) THEN
2210 gme_common_pvt.log_message
2211 ('GME_NON_WORKING_TIME'
2212 ,'PDATE'
2213 ,TO_CHAR (l_batch_step_rec.plan_start_date
2214 ,'DD-MON-YYYY HH24:MI:SS') );
2215 RAISE fnd_api.g_exc_error;
2216 END IF;
2217 END IF;
2218
2219 -- Check if plan_cmplt_date falls on non working day for pending and WIP batch step.
2220 IF l_batch_step_rec.step_status IN
2221 (gme_common_pvt.g_step_pending
2222 ,gme_common_pvt.g_step_wip)
2223 AND l_batch_step_rec.plan_cmplt_date IS NOT NULL THEN
2224 gme_debug.put_line ('in cmplt');
2225
2226 IF NOT gmp_calendar_api.is_working_daytime
2227 (1.0
2228 ,FALSE
2229 ,gme_common_pvt.g_calendar_code
2230 ,l_batch_step_rec.plan_cmplt_date
2231 ,1
2232 ,l_return_status) THEN
2233 gme_common_pvt.log_message
2234 ('GME_NON_WORKING_TIME'
2235 ,'PDATE'
2236 ,TO_CHAR (l_batch_step_rec.plan_cmplt_date
2237 ,'DD-MON-YYYY HH24:MI:SS') );
2238 RAISE fnd_api.g_exc_error;
2239 END IF;
2240 END IF;
2241
2242 IF l_batch_step_rec.plan_cmplt_date IS NULL
2243 AND l_batch_step_rec.plan_start_date IS NULL THEN
2244 IF NOT gmp_calendar_api.is_working_daytime
2245 (1.0
2246 ,FALSE
2247 ,gme_common_pvt.g_calendar_code
2248 ,SYSDATE
2249 ,0
2250 ,l_return_status) THEN
2251 gme_common_pvt.log_message
2252 ('GME_NON_WORKING_TIME'
2253 ,'PDATE'
2254 ,TO_CHAR (SYSDATE
2255 ,'DD-MON-YYYY HH24:MI:SS') );
2256 RAISE fnd_api.g_exc_error;
2257 END IF;
2258 END IF; /* l_batch_step_rec.plan_cmplt_date IS NULL */
2259 END IF; /* (gme_common_pvt.g_calendar_code IS NOT NULL) */
2260 END IF; /* l_use = FND_API.G_TRUE */
2261
2262 IF (g_debug = gme_debug.g_log_statement) THEN
2263 gme_debug.put_line ( g_pkg_name
2264 || '.'
2265 || l_api_name
2266 || ':'
2267 || 'Calling Main Reschedule Step');
2268 END IF;
2269
2270 gme_api_main.reschedule_step
2271 (p_validation_level => p_validation_level
2272 ,p_init_msg_list => fnd_api.g_false
2273 ,p_batch_header_rec => l_batch_header_rec
2274 ,p_batch_step_rec => l_batch_step_rec
2275 ,p_reschedule_preceding => p_reschedule_preceding
2276 ,p_reschedule_succeeding => p_reschedule_succeeding
2277 ,p_use_workday_cal => l_use
2278 ,p_contiguity_override => p_contiguity_override
2279 ,x_message_count => x_message_count
2280 ,x_message_list => x_message_list
2281 ,x_return_status => x_return_status
2282 ,x_batch_step_rec => x_batch_step_rec);
2283
2284 IF (g_debug = gme_debug.g_log_statement) THEN
2285 gme_debug.put_line
2286 ( 'Came back from Main Reschedule Step with status '
2287 || x_return_status);
2288 END IF;
2289
2290 IF x_return_status <> fnd_api.g_ret_sts_success THEN
2291 RAISE reschedule_step_failed;
2292 ELSE
2293 IF p_commit = fnd_api.g_true THEN
2294 gme_api_pub.save_batch (p_header_id => NULL
2295 ,p_table => NULL
2296 ,p_commit => fnd_api.g_false
2297 ,x_return_status => x_return_status);
2298
2299 IF x_return_status = fnd_api.g_ret_sts_success THEN
2300 COMMIT;
2301 ELSE
2302 RAISE fnd_api.g_exc_error;
2303 END IF;
2304 END IF;
2305 END IF;
2306
2307 IF g_debug <= gme_debug.g_log_procedure THEN
2308 gme_debug.put_line ( g_pkg_name
2309 || '.'
2310 || l_api_name
2311 || ':'
2312 || 'Exiting with '
2313 || x_return_status
2314 || ' at '
2315 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
2316 END IF;
2317 EXCEPTION
2318 WHEN reschedule_step_failed THEN
2319 ROLLBACK TO SAVEPOINT reschedule_step;
2320 x_batch_step_rec := NULL;
2321 gme_common_pvt.count_and_get (x_count => x_message_count
2322 ,p_encoded => fnd_api.g_false
2323 ,x_data => x_message_list);
2324 WHEN fnd_api.g_exc_error THEN
2325 ROLLBACK TO SAVEPOINT reschedule_step;
2326 x_return_status := fnd_api.g_ret_sts_error;
2327 gme_common_pvt.count_and_get (x_count => x_message_count
2328 ,p_encoded => fnd_api.g_false
2329 ,x_data => x_message_list);
2330 WHEN OTHERS THEN
2331 ROLLBACK TO SAVEPOINT reschedule_step;
2332 x_batch_step_rec := NULL;
2333 gme_when_others ( p_api_name => l_api_name
2334 ,x_message_count => x_message_count
2335 ,x_message_list => x_message_list
2336 ,x_return_status => x_return_status );
2337 END reschedule_step;
2338
2339 /*************************************************************************/
2340 PROCEDURE create_batch_reservations (
2341 p_api_version IN NUMBER := 2.0
2342 ,p_validation_level IN NUMBER
2343 := gme_common_pvt.g_max_errors
2344 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
2345 ,p_commit IN VARCHAR2 := fnd_api.g_false
2346 ,p_batch_rec IN gme_batch_header%ROWTYPE
2347 ,p_org_code IN VARCHAR2
2348 ,x_message_count OUT NOCOPY NUMBER
2349 ,x_message_list OUT NOCOPY VARCHAR2
2350 ,x_return_status OUT NOCOPY VARCHAR2)
2351 IS
2352 l_api_name CONSTANT VARCHAR2 (30) := 'CREATE_BATCH_RESERVATIONS';
2353 l_batch_header_rec gme_batch_header%ROWTYPE;
2354 BEGIN
2355 IF g_debug <= gme_debug.g_log_procedure THEN
2356 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
2357 || l_api_name);
2358 END IF;
2359
2360 /* Set the savepoint */
2361 SAVEPOINT create_batch_reservations;
2362 /* Set the return status to success initially */
2363 x_return_status := fnd_api.g_ret_sts_success;
2364
2365 IF g_debug <> -1 THEN
2366 gme_debug.log_initialize ('CreateBatchReservations');
2367 END IF;
2368
2369 /* Make sure we are call compatible */
2370 IF NOT fnd_api.compatible_api_call (2.0
2371 ,p_api_version
2372 ,'insert_batchstep_resource'
2373 ,g_pkg_name) THEN
2374 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
2375 RAISE fnd_api.g_exc_error;
2376 END IF;
2377
2378 /* Initialize message list and count if needed */
2379 IF p_init_msg_list = fnd_api.g_true THEN
2380 fnd_msg_pub.initialize;
2381 END IF;
2382
2383 gme_common_pvt.set_timestamp;
2384
2385 /* IF p_batch_rec.batch_no IS NULL AND p_batch_rec.batch_id IS NULL THEN
2386 gme_common_pvt.log_message ('GME_MISSING_BATCH_IDENTIFIER');
2387 RAISE fnd_api.g_exc_error;
2388 END IF; */
2389 gme_common_pvt.validate_batch
2390 (p_batch_header_rec => p_batch_rec
2391 ,p_org_code => p_org_code
2392 ,p_batch_type => gme_common_pvt.g_doc_type_batch
2393 ,x_batch_header_rec => l_batch_header_rec
2394 ,x_message_count => x_message_count
2395 ,x_message_list => x_message_list
2396 ,x_return_status => x_return_status );
2397
2398 IF x_return_status <> fnd_api.g_ret_sts_success THEN
2399 IF (g_debug = gme_debug.g_log_statement) THEN
2400 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
2401 || ': batch validate error ');
2402 END IF;
2403 RAISE fnd_api.g_exc_error;
2404 END IF;
2405
2406 /* Verify Batch to be in pending or WIP status */
2407 IF l_batch_header_rec.batch_status NOT IN
2408 (gme_common_pvt.g_batch_pending, gme_common_pvt.g_batch_wip) THEN
2409 gme_common_pvt.log_message ('GME_INVALID_BATCH_STATUS'
2410 ,'PROCESS'
2411 ,'CREATE_LINE_RESERVATIONS');
2412 RAISE fnd_api.g_exc_error;
2413 END IF;
2414
2415 gme_api_main.create_batch_reservations
2416 (p_init_msg_list => p_init_msg_list
2417 ,p_batch_header_rec => l_batch_header_rec
2418 ,x_message_count => x_message_count
2419 ,x_message_list => x_message_list
2420 ,x_return_status => x_return_status);
2421
2422 IF (g_debug = gme_debug.g_log_statement) THEN
2423 gme_debug.put_line ( 'create batch reservations returns '
2424 || x_return_status);
2425 END IF;
2426
2427 IF x_return_status <> fnd_api.g_ret_sts_success THEN
2428 RAISE fnd_api.g_exc_error;
2429 END IF;
2430
2431 IF p_commit = fnd_api.g_true THEN
2432 COMMIT;
2433 END IF;
2434
2435 gme_debug.put_line ( 'End of Create_Batch_Reservations at '
2436 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
2437 gme_common_pvt.log_message ('PM_SAVED_CHANGES');
2438 EXCEPTION
2439 WHEN fnd_api.g_exc_error THEN
2440 x_return_status := fnd_api.g_ret_sts_error;
2441 ROLLBACK TO SAVEPOINT create_batch_reservations;
2442 gme_common_pvt.count_and_get(x_count => x_message_count
2443 ,p_encoded => fnd_api.g_false
2444 ,x_data => x_message_list);
2445 WHEN OTHERS THEN
2446 ROLLBACK TO SAVEPOINT create_batch_reservations;
2447 gme_when_others ( p_api_name => l_api_name
2448 ,x_message_count => x_message_count
2449 ,x_message_list => x_message_list
2450 ,x_return_status => x_return_status );
2451 END create_batch_reservations;
2452 /*************************************************************************/
2453 PROCEDURE create_line_reservations (
2454 p_api_version IN NUMBER := 2.0
2455 ,p_validation_level IN NUMBER
2456 := gme_common_pvt.g_max_errors
2457 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
2458 ,p_commit IN VARCHAR2 := fnd_api.g_false
2459 ,p_material_detail_id IN NUMBER
2460 ,p_org_code IN VARCHAR2
2461 ,p_batch_no IN VARCHAR2
2462 ,p_line_no IN NUMBER
2463 ,x_message_count OUT NOCOPY NUMBER
2464 ,x_message_list OUT NOCOPY VARCHAR2
2465 ,x_return_status OUT NOCOPY VARCHAR2)
2466 IS
2467 l_api_name CONSTANT VARCHAR2 (30)
2468 := 'CREATE_LINE_RESERVATIONS';
2469 l_material_details_rec gme_material_details%ROWTYPE;
2470 l_material_details_rec_out gme_material_details%ROWTYPE;
2471 l_batch_header_rec gme_batch_header%ROWTYPE;
2472 BEGIN
2473 IF g_debug <= gme_debug.g_log_procedure THEN
2474 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
2475 || l_api_name);
2476 END IF;
2477
2478 /* Set the savepoint */
2479 SAVEPOINT create_line_reservations;
2480 /* Set the return status to success initially */
2481 x_return_status := fnd_api.g_ret_sts_success;
2482
2483 IF g_debug <> -1 THEN
2484 gme_debug.log_initialize ('CreateLineReservations');
2485 END IF;
2486
2487 /* Make sure we are call compatible */
2488 IF NOT fnd_api.compatible_api_call (2.0
2489 ,p_api_version
2490 ,'insert_batchstep_resource'
2491 ,g_pkg_name) THEN
2492 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
2493 RAISE fnd_api.g_exc_error;
2494 END IF;
2495
2496 /* Initialize message list and count if needed */
2497 IF p_init_msg_list = fnd_api.g_true THEN
2498 fnd_msg_pub.initialize;
2499 END IF;
2500
2501 gme_common_pvt.set_timestamp;
2502 l_material_details_rec.material_detail_id := p_material_detail_id;
2503 l_material_details_rec.line_no := p_line_no;
2504 /* Ensure line_type is populated. Reservations only permitted for ingredient lines. */
2505 /* Line type is needed for retrieval based on key values */
2506 l_material_details_rec.line_type := -1;
2507
2508 gme_common_pvt.Validate_material_detail
2509 (p_material_detail_rec => l_material_details_rec
2510 ,p_org_code => p_org_code
2511 ,p_batch_no => p_batch_no
2512 ,p_batch_type => 0
2513 ,x_batch_header_rec => l_batch_header_rec
2514 ,x_material_detail_rec => l_material_details_rec_out
2515 ,x_message_count => x_message_count
2516 ,x_message_list => x_message_list
2517 ,x_return_status => x_return_status );
2518 IF x_return_status <> fnd_api.g_ret_sts_success THEN
2519 IF (g_debug = gme_debug.g_log_statement) THEN
2520 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
2521 || ': batch mateiral validate error ');
2522 END IF;
2523 RAISE fnd_api.g_exc_error;
2524 END IF;
2525 l_material_details_rec := l_material_details_rec_out;
2526
2527 /* Reservation cannot be against a phantom */
2528 IF l_material_details_rec.phantom_type IN (1, 2) THEN
2529 gme_common_pvt.log_message ('GME_INVALID_RSV_FOR_PHANTOM');
2530 RAISE fnd_api.g_exc_error;
2531 END IF;
2532
2533 /* Reservation cannot be against a phantom */
2534 IF l_material_details_rec.line_type <> -1 THEN
2535 gme_common_pvt.log_message ('GME_INVALID_LINE_FOR_RSV');
2536 RAISE fnd_api.g_exc_error;
2537 END IF;
2538
2539 /* Verify that update_inventory is permitted for this batch */
2540 IF l_batch_header_rec.update_inventory_ind <> 'Y' THEN
2541 gme_common_pvt.log_message ('GME_INVENTORY_UPDATE_BLOCKED');
2542 RAISE fnd_api.g_exc_error;
2543 END IF;
2544
2545 -- gme_debug.put_line(l_batch_header_rec.batch_status);
2546
2547 /* Verify Batch to be in pending or WIP status */
2548 IF l_batch_header_rec.batch_status NOT IN
2549 (gme_common_pvt.g_batch_pending, gme_common_pvt.g_batch_wip) THEN
2550 gme_common_pvt.log_message ('GME_INVALID_BATCH_STATUS'
2551 ,'PROCESS'
2552 ,'CREATE_RESERVATION');
2553 RAISE fnd_api.g_exc_error;
2554 END IF;
2555
2556 IF l_batch_header_rec.batch_type = gme_common_pvt.g_doc_type_fpo THEN
2557 gme_common_pvt.log_message ('GME_FPO_RESERVATION_ERROR');
2558 RAISE fnd_api.g_exc_error;
2559 END IF;
2560 gme_api_main.create_line_reservations
2561 (p_init_msg_list => p_init_msg_list
2562 ,p_matl_dtl_rec => l_material_details_rec
2563 ,x_message_count => x_message_count
2564 ,x_message_list => x_message_list
2565 ,x_return_status => x_return_status);
2566
2567 IF (g_debug = gme_debug.g_log_statement) THEN
2568 gme_debug.put_line ( 'create line reservation returns '
2569 || x_return_status);
2570 END IF;
2571
2572 IF x_return_status <> fnd_api.g_ret_sts_success THEN
2573 RAISE fnd_api.g_exc_error;
2574 END IF;
2575
2576 IF p_commit = fnd_api.g_true THEN
2577 COMMIT;
2578 END IF;
2579
2580 gme_debug.put_line ( 'End of Create_Line_Reservations at '
2581 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
2582 gme_common_pvt.log_message ('PM_SAVED_CHANGES');
2583 EXCEPTION
2584 WHEN fnd_api.g_exc_error THEN
2585 x_return_status := fnd_api.g_ret_sts_error;
2586 ROLLBACK TO SAVEPOINT create_line_reservations;
2587 gme_common_pvt.count_and_get(x_count => x_message_count
2588 ,p_encoded => fnd_api.g_false
2589 ,x_data => x_message_list);
2590 WHEN OTHERS THEN
2591 ROLLBACK TO SAVEPOINT create_line_reservations;
2592 gme_when_others ( p_api_name => l_api_name
2593 ,x_message_count => x_message_count
2594 ,x_message_list => x_message_list
2595 ,x_return_status => x_return_status );
2596 END create_line_reservations;
2597
2598 /*************************************************************************/
2599 PROCEDURE insert_process_parameter (
2600 p_api_version IN NUMBER := 2.0
2601 ,p_validation_level IN NUMBER
2602 ,p_init_msg_list IN VARCHAR2
2603 ,p_commit IN VARCHAR2
2604 ,x_message_count OUT NOCOPY NUMBER
2605 ,x_message_list OUT NOCOPY VARCHAR2
2606 ,x_return_status OUT NOCOPY VARCHAR2
2607 ,p_batch_no IN VARCHAR2
2608 ,p_org_code IN VARCHAR2
2609 ,p_validate_flexfields IN VARCHAR2
2610 ,p_batchstep_no IN NUMBER
2611 ,p_activity IN VARCHAR2
2612 ,p_parameter IN VARCHAR2
2613 ,p_process_param_rec IN gme_process_parameters%ROWTYPE
2614 ,x_process_param_rec OUT NOCOPY gme_process_parameters%ROWTYPE)
2615 IS
2616 insert_parameter_failed EXCEPTION;
2617 l_api_name CONSTANT VARCHAR2 (30) := 'INSERT_PROCESS_PARAMETER';
2618 BEGIN
2619 IF (g_debug IN
2620 (gme_debug.g_log_statement, gme_debug.g_log_procedure) ) THEN
2621 gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
2622 || 'Entering');
2623 END IF;
2624
2625 SAVEPOINT insert_process_parameter;
2626
2627 IF (g_debug <> -1) THEN
2628 gme_debug.log_initialize ('InsertProcessParameters');
2629 END IF;
2630
2631 /* Set the return status to success initially */
2632 x_return_status := fnd_api.g_ret_sts_success;
2633
2634 IF p_init_msg_list = fnd_api.g_true THEN
2635 fnd_msg_pub.initialize;
2636 END IF;
2637 -- Make sure we are call compatible
2638 IF NOT fnd_api.compatible_api_call (2.0
2639 ,p_api_version
2640 ,'Insert_process_parameter'
2641 ,g_pkg_name) THEN
2642 x_return_status := fnd_api.g_ret_sts_error;
2643 gme_common_pvt.log_message ('PM_INVALID_PHANTOM_ACTION');
2644 RAISE fnd_api.g_exc_error;
2645 END IF;
2646
2647 gme_common_pvt.g_setup_done := gme_common_pvt.setup (p_org_code => p_org_code);
2648
2649 IF NOT gme_common_pvt.g_setup_done THEN
2650 IF (g_debug = gme_debug.g_log_statement) THEN
2651 gme_debug.put_line (g_pkg_name||'.'||l_api_name|| ':set up problem ');
2652 END IF;
2653 RAISE fnd_api.g_exc_error;
2654 END IF;
2655 IF (g_debug <= gme_debug.g_log_procedure) THEN
2656 gme_debug.put_line ('Calling Insert process parameters');
2657 END IF;
2658
2659 gme_common_pvt.set_timestamp;
2660 gme_process_parameters_pvt.insert_process_parameter
2661 (p_batch_no => p_batch_no
2662 ,p_org_code => p_org_code
2663 ,p_validate_flexfields => p_validate_flexfields
2664 ,p_batchstep_no => p_batchstep_no
2665 ,p_activity => p_activity
2666 ,p_parameter => p_parameter
2667 ,p_process_param_rec => p_process_param_rec
2668 ,x_process_param_rec => x_process_param_rec
2669 ,x_return_status => x_return_status);
2670
2671 IF (g_debug = gme_debug.g_log_statement) THEN
2672 gme_debug.put_line
2673 ( 'Came back from Pvt insert process parameter with status '
2674 || x_return_status);
2675 END IF;
2676
2677 IF x_return_status = fnd_api.g_ret_sts_success THEN
2678 IF p_commit = fnd_api.g_true THEN
2679 COMMIT;
2680 gme_common_pvt.log_message ('PM_SAVED_CHANGES');
2681 END IF;
2682 ELSE
2683 RAISE insert_parameter_failed;
2684 END IF;
2685
2686 IF g_debug <= gme_debug.g_log_procedure THEN
2687 gme_debug.put_line ( g_pkg_name
2688 || '.'
2689 || l_api_name
2690 || ' : Exiting with '
2691 || x_return_status
2692 || ' at '
2693 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
2694 END IF;
2695 EXCEPTION
2696 WHEN fnd_api.g_exc_error THEN
2697 x_return_status := fnd_api.g_ret_sts_error;
2698 ROLLBACK TO SAVEPOINT insert_process_parameter;
2699 gme_common_pvt.count_and_get (x_count => x_message_count
2700 ,p_encoded => fnd_api.g_false
2701 ,x_data => x_message_list);
2702 WHEN insert_parameter_failed THEN
2703 ROLLBACK TO SAVEPOINT insert_process_parameter;
2704 gme_common_pvt.count_and_get (x_count => x_message_count
2705 ,p_encoded => fnd_api.g_false
2706 ,x_data => x_message_list);
2707 WHEN OTHERS THEN
2708 ROLLBACK TO SAVEPOINT insert_process_parameter;
2709 gme_when_others ( p_api_name => l_api_name
2710 ,x_message_count => x_message_count
2711 ,x_message_list => x_message_list
2712 ,x_return_status => x_return_status );
2713 END insert_process_parameter;
2714
2715 /*************************************************************************/
2716 PROCEDURE update_process_parameter (
2717 p_api_version IN NUMBER
2718 ,p_validation_level IN NUMBER
2719 ,p_init_msg_list IN VARCHAR2
2720 ,p_commit IN VARCHAR2
2721 ,x_message_count OUT NOCOPY NUMBER
2722 ,x_message_list OUT NOCOPY VARCHAR2
2723 ,x_return_status OUT NOCOPY VARCHAR2
2724 ,p_batch_no IN VARCHAR2
2725 ,p_org_code IN VARCHAR2
2726 ,p_validate_flexfields IN VARCHAR2
2727 ,p_batchstep_no IN NUMBER
2728 ,p_activity IN VARCHAR2
2729 ,p_parameter IN VARCHAR2
2730 ,p_process_param_rec IN gme_process_parameters%ROWTYPE
2731 ,x_process_param_rec OUT NOCOPY gme_process_parameters%ROWTYPE)
2732 IS
2733 update_parameter_failed EXCEPTION;
2734 l_api_name CONSTANT VARCHAR2 (30) := 'UPDATE_PROCESS_PARAMETER';
2735 BEGIN
2736 IF (g_debug IN
2737 (gme_debug.g_log_statement, gme_debug.g_log_procedure) ) THEN
2738 gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
2739 || 'Entering');
2740 END IF;
2741
2742 SAVEPOINT update_process_parameter;
2743
2744 IF (g_debug <> -1) THEN
2745 gme_debug.log_initialize ('UpdateProcessParameter');
2746 END IF;
2747
2748 /* Initially let us assign the return status to success */
2749 x_return_status := fnd_api.g_ret_sts_success;
2750
2751 IF p_init_msg_list = fnd_api.g_true THEN
2752 fnd_msg_pub.initialize;
2753 gme_common_pvt.g_error_count := 0;
2754 END IF;
2755
2756 -- Make sure we are call compatible
2757 IF NOT fnd_api.compatible_api_call (2.0
2758 ,p_api_version
2759 ,'Insert_process_parameter'
2760 ,g_pkg_name) THEN
2761 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
2762 RAISE fnd_api.g_exc_error;
2763 END IF;
2764
2765 gme_common_pvt.g_setup_done := gme_common_pvt.setup (p_org_code => p_org_code);
2766
2767 IF NOT gme_common_pvt.g_setup_done THEN
2768 x_return_status := fnd_api.g_ret_sts_error;
2769 RAISE fnd_api.g_exc_error;
2770 END IF;
2771
2772 gme_common_pvt.set_timestamp;
2773 gme_process_parameters_pvt.update_process_parameter
2774 (p_batch_no => p_batch_no
2775 ,p_org_code => p_org_code
2776 ,p_validate_flexfields => p_validate_flexfields
2777 ,p_batchstep_no => p_batchstep_no
2778 ,p_activity => p_activity
2779 ,p_parameter => p_parameter
2780 ,p_process_param_rec => p_process_param_rec
2781 ,x_process_param_rec => x_process_param_rec
2782 ,x_return_status => x_return_status);
2783
2784 IF (g_debug = gme_debug.g_log_statement) THEN
2785 gme_debug.put_line
2786 ( 'Came back from Pvt update process parameter with status '
2787 || x_return_status);
2788 END IF;
2789
2790 IF x_return_status = fnd_api.g_ret_sts_success THEN
2791 IF p_commit = fnd_api.g_true THEN
2792 COMMIT;
2793 gme_common_pvt.log_message ('PM_SAVED_CHANGES');
2794 END IF;
2795 ELSE
2796 RAISE update_parameter_failed;
2797 END IF;
2798
2799 IF g_debug <= gme_debug.g_log_procedure THEN
2800 gme_debug.put_line ( g_pkg_name
2801 || '.'
2802 || l_api_name
2803 || ':'
2804 || 'Exiting with '
2805 || x_return_status
2806 || ' at '
2807 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
2808 END IF;
2809 EXCEPTION
2810 WHEN fnd_api.g_exc_error THEN
2811 x_return_status := fnd_api.g_ret_sts_error;
2812 ROLLBACK TO SAVEPOINT update_process_parameter;
2813 gme_common_pvt.count_and_get (x_count => x_message_count
2814 ,p_encoded => fnd_api.g_false
2815 ,x_data => x_message_list);
2816 WHEN update_parameter_failed THEN
2817 ROLLBACK TO SAVEPOINT update_process_parameter;
2818 gme_common_pvt.count_and_get (x_count => x_message_count
2819 ,p_encoded => fnd_api.g_false
2820 ,x_data => x_message_list);
2821 WHEN OTHERS THEN
2822 ROLLBACK TO SAVEPOINT update_process_parameter;
2823 gme_when_others ( p_api_name => l_api_name
2824 ,x_message_count => x_message_count
2825 ,x_message_list => x_message_list
2826 ,x_return_status => x_return_status );
2827 END update_process_parameter;
2828
2829 /*************************************************************************/
2830 PROCEDURE delete_process_parameter (
2831 p_api_version IN NUMBER
2832 ,p_validation_level IN NUMBER
2833 ,p_init_msg_list IN VARCHAR2
2834 ,p_commit IN VARCHAR2
2835 ,x_message_count OUT NOCOPY NUMBER
2836 ,x_message_list OUT NOCOPY VARCHAR2
2837 ,x_return_status OUT NOCOPY VARCHAR2
2838 ,p_batch_no IN VARCHAR2
2839 ,p_org_code IN VARCHAR2
2840 ,p_batchstep_no IN NUMBER
2841 ,p_activity IN VARCHAR2
2842 ,p_parameter IN VARCHAR2
2843 ,p_process_param_rec IN gme_process_parameters%ROWTYPE)
2844 IS
2845 delete_parameter_failed EXCEPTION;
2846 l_api_name CONSTANT VARCHAR2 (30) := 'DELETE_PROCESS_PARAMETER';
2847 BEGIN
2848 IF (g_debug IN
2849 (gme_debug.g_log_statement, gme_debug.g_log_procedure) ) THEN
2850 gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
2851 || 'Entering');
2852 END IF;
2853
2854 SAVEPOINT delete_process_parameter;
2855
2856 IF (g_debug <> -1) THEN
2857 gme_debug.log_initialize ('DeleteProcessParameter');
2858 END IF;
2859
2860 /* Set the return status to success initially */
2861 x_return_status := fnd_api.g_ret_sts_success;
2862
2863 IF p_init_msg_list = fnd_api.g_true THEN
2864 fnd_msg_pub.initialize;
2865 gme_common_pvt.g_error_count := 0;
2866 END IF;
2867
2868 -- Make sure we are call compatible
2869 IF NOT fnd_api.compatible_api_call (2.0
2870 ,p_api_version
2871 ,'Insert_process_parameter'
2872 ,g_pkg_name) THEN
2873 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
2874 RAISE fnd_api.g_exc_error;
2875 END IF;
2876
2877 gme_common_pvt.g_setup_done := gme_common_pvt.setup (p_org_code => p_org_code);
2878
2879 IF NOT gme_common_pvt.g_setup_done THEN
2880 x_return_status := fnd_api.g_ret_sts_error;
2881 RAISE fnd_api.g_exc_error;
2882 END IF;
2883
2884 IF (g_debug <= gme_debug.g_log_procedure) THEN
2885 gme_debug.put_line ('Calling Insert process parameters');
2886 END IF;
2887
2888 gme_common_pvt.set_timestamp;
2889 gme_process_parameters_pvt.delete_process_parameter
2890 (p_batch_no => p_batch_no
2891 ,p_org_code => p_org_code
2892 ,p_batchstep_no => p_batchstep_no
2893 ,p_activity => p_activity
2894 ,p_parameter => p_parameter
2895 ,p_process_param_rec => p_process_param_rec
2896 ,x_return_status => x_return_status);
2897
2898 IF (g_debug = gme_debug.g_log_statement) THEN
2899 gme_debug.put_line
2900 ( 'Came back from Pvt delete process parameter with status '
2901 || x_return_status);
2902 END IF;
2903
2904 IF x_return_status = fnd_api.g_ret_sts_success THEN
2905 IF p_commit = fnd_api.g_true THEN
2906 COMMIT;
2907 gme_common_pvt.log_message ('PM_SAVED_CHANGES');
2908 END IF;
2909 ELSE
2910 RAISE delete_parameter_failed;
2911 END IF;
2912
2913 IF g_debug <= gme_debug.g_log_procedure THEN
2914 gme_debug.put_line ( g_pkg_name || '.' || l_api_name || ':' ||
2915 'Exiting with ' || x_return_status || ' at '
2916 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
2917 END IF;
2918 EXCEPTION
2919 WHEN fnd_api.g_exc_error THEN
2920 x_return_status := fnd_api.g_ret_sts_error;
2921 ROLLBACK TO SAVEPOINT delete_process_parameter;
2922 gme_common_pvt.count_and_get (x_count => x_message_count
2923 ,p_encoded => fnd_api.g_false
2924 ,x_data => x_message_list);
2925 WHEN delete_parameter_failed THEN
2926 ROLLBACK TO SAVEPOINT delete_process_parameter;
2927 gme_common_pvt.count_and_get (x_count => x_message_count
2928 ,p_encoded => fnd_api.g_false
2929 ,x_data => x_message_list);
2930 WHEN OTHERS THEN
2931 ROLLBACK TO SAVEPOINT delete_process_parameter;
2932 gme_when_others ( p_api_name => l_api_name
2933 ,x_message_count => x_message_count
2934 ,x_message_list => x_message_list
2935 ,x_return_status => x_return_status );
2936 END delete_process_parameter;
2937
2938 /*************************************************************************/
2939 PROCEDURE delete_step (
2940 p_api_version IN NUMBER := 2.0
2941 ,p_validation_level IN NUMBER
2942 := gme_common_pvt.g_max_errors
2943 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
2944 ,p_commit IN VARCHAR2
2945 ,p_org_code IN VARCHAR2
2946 ,p_batch_no IN VARCHAR2
2947 ,x_message_count OUT NOCOPY NUMBER
2948 ,x_message_list OUT NOCOPY VARCHAR2
2949 ,x_return_status OUT NOCOPY VARCHAR2
2950 ,p_batch_step_rec IN gme_batch_steps%ROWTYPE)
2951 IS
2952 l_api_name CONSTANT VARCHAR2 (30) := 'DELETE_STEP';
2953 l_batch_header_rec gme_batch_header%rowtype;
2954 delete_step_failed EXCEPTION;
2955 BEGIN
2956 /* Set the return status to success initially */
2957 x_return_status := fnd_api.g_ret_sts_success;
2958
2959 /* Set savepoint here */
2960 SAVEPOINT delete_step;
2961
2962 /* Initialize message list and count if needed */
2963 IF p_init_msg_list = fnd_api.g_true THEN
2964 fnd_msg_pub.initialize;
2965 gme_common_pvt.g_error_count := 0;
2966 END IF;
2967
2968 /* Setup the common constants used accross the apis */
2969 gme_common_pvt.g_setup_done := gme_common_pvt.setup (p_org_code => p_org_code);
2970
2971 IF NOT gme_common_pvt.g_setup_done THEN
2972 RAISE fnd_api.g_exc_error;
2973 END IF;
2974
2975 /* Make sure we are call compatible */
2976 IF NOT fnd_api.compatible_api_call (2
2977 ,p_api_version
2978 ,'delete_step'
2979 ,g_pkg_name) THEN
2980 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
2981 RAISE fnd_api.g_exc_error;
2982 END IF;
2983 gme_api_main.delete_step (p_validation_level => p_validation_level
2984 ,p_init_msg_list => fnd_api.g_false
2985 ,x_message_count => x_message_count
2986 ,x_message_list => x_message_list
2987 ,x_return_status => x_return_status
2988 ,p_batch_header_rec => l_batch_header_rec
2989 ,p_batch_step_rec => p_batch_step_rec);
2990
2991 IF x_return_status <> fnd_api.g_ret_sts_success THEN
2992 RAISE delete_step_failed;
2993 ELSE
2994 IF p_commit = fnd_api.g_true THEN
2995 gme_api_pub.save_batch (p_header_id => null
2996 ,p_table => 1
2997 ,p_commit => fnd_api.g_false
2998 ,x_return_status => x_return_status);
2999
3000 IF x_return_status = fnd_api.g_ret_sts_success THEN
3001 COMMIT;
3002 ELSE
3003 RAISE fnd_api.g_exc_error;
3004 END IF;
3005 END IF;
3006 END IF;
3007
3008 IF g_debug <= gme_debug.g_log_procedure THEN
3009 gme_debug.put_line ( 'Completed ' || l_api_name || ' at ' || TO_CHAR
3010 (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
3011 END IF;
3012 EXCEPTION
3013 WHEN fnd_api.g_exc_error THEN
3014 ROLLBACK TO SAVEPOINT delete_step;
3015 x_return_status := fnd_api.g_ret_sts_error;
3016 gme_common_pvt.count_and_get (x_count => x_message_count
3017 ,p_encoded => fnd_api.g_false
3018 ,x_data => x_message_list);
3019 WHEN delete_step_failed THEN
3020 ROLLBACK TO SAVEPOINT delete_step;
3021 gme_common_pvt.count_and_get (x_count => x_message_count
3022 ,p_encoded => fnd_api.g_false
3023 ,x_data => x_message_list);
3024 WHEN OTHERS THEN
3025 ROLLBACK TO SAVEPOINT delete_step;
3026 gme_when_others ( p_api_name => l_api_name
3027 ,x_message_count => x_message_count
3028 ,x_message_list => x_message_list
3029 ,x_return_status => x_return_status );
3030 END delete_step;
3031
3032 /*************************************************************************
3033 * PROCEURE
3034 * insert_step
3035 * History
3036 * Punit Kumar 07-Apr-2005
3037 * Convergence Changes
3038 * SivakumarG 16-NOV-2005 FPBug#4395561
3039 * Added new argument p_validate_flexfields
3040 /*************************************************************************/
3041 PROCEDURE insert_step (
3042 p_api_version IN NUMBER := 2.0
3043 ,p_validation_level IN NUMBER := gme_common_pvt.g_max_errors
3044 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
3045 ,p_commit IN VARCHAR2
3046 ,p_org_code IN VARCHAR2
3047 ,p_validate_flexfields IN VARCHAR2 := fnd_api.g_false
3048 ,p_oprn_no IN VARCHAR2
3049 ,p_oprn_vers IN NUMBER
3050 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
3051 ,p_batch_step_rec IN gme_batch_steps%ROWTYPE
3052 ,x_batch_step_rec OUT NOCOPY gme_batch_steps%ROWTYPE
3053 ,x_message_count OUT NOCOPY NUMBER
3054 ,x_message_list OUT NOCOPY VARCHAR2
3055 ,x_return_status OUT NOCOPY VARCHAR2)
3056 IS
3057 l_api_name CONSTANT VARCHAR2 (30) := 'INSERT_STEP';
3058 insert_step_failed EXCEPTION;
3059 l_batch_header_rec gme_batch_header%ROWTYPE;
3060 l_oprn_no VARCHAR2 (16);
3061 /* The operation number for the step */
3062 l_oprn_vers NUMBER;
3063 /* The operation version for the step */
3064 l_org_id NUMBER;
3065 l_verify_oprn NUMBER := NULL;
3066
3067 CURSOR get_oprn (l_oprn_id NUMBER)
3068 IS
3069 SELECT oprn_no, oprn_vers
3070 FROM gmd_operations_b
3071 WHERE oprn_id = l_oprn_id;
3072
3073 CURSOR verify_oprn (
3074 l_oprn_no VARCHAR2
3075 ,l_oprn_vers NUMBER
3076 ,l_org_id NUMBER)
3077 IS
3078 SELECT 1
3079 FROM DUAL
3080 WHERE EXISTS (
3081 SELECT 1
3082 FROM gmd_operations_b
3083 WHERE oprn_no = l_oprn_no
3084 AND oprn_vers = l_oprn_vers
3085 AND owner_organization_id = l_org_id);
3086 BEGIN
3087 /* Set the return status to success initially */
3088 x_return_status := fnd_api.g_ret_sts_success;
3089
3090 /* Set savepoint here */
3091 SAVEPOINT insert_step;
3092
3093 /* Initialize message list and count if needed */
3094 IF p_init_msg_list = fnd_api.g_true THEN
3095 fnd_msg_pub.initialize;
3096 gme_common_pvt.g_error_count := 0;
3097 END IF;
3098 gme_common_pvt.g_setup_done :=
3099 gme_common_pvt.setup (p_org_id => p_batch_header_rec.organization_id
3100 ,p_org_code => p_org_code);
3101
3102 IF NOT gme_common_pvt.g_setup_done THEN
3103 RAISE fnd_api.g_exc_error;
3104 END IF;
3105
3106 /* Make sure we are call compatible */
3107 IF NOT fnd_api.compatible_api_call (2
3108 ,p_api_version
3109 ,'insert_step'
3110 ,g_pkg_name) THEN
3111 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
3112 RAISE fnd_api.g_exc_error;
3113 END IF;
3114
3115 IF (p_batch_step_rec.batch_id IS NOT NULL) THEN
3116 l_batch_header_rec.batch_id := p_batch_step_rec.batch_id;
3117
3118 IF NOT (gme_batch_header_dbl.fetch_row (l_batch_header_rec
3119 ,l_batch_header_rec) ) THEN
3120 RAISE fnd_api.g_exc_error;
3121 END IF;
3122 ELSE
3123 IF NOT (gme_batch_header_dbl.fetch_row (p_batch_header_rec
3124 ,l_batch_header_rec) ) THEN
3125 RAISE fnd_api.g_exc_error;
3126 END IF;
3127 END IF;
3128
3129 /* Bug 2766460 Added check not to allow insert step if batch is completed/closed or cancelled */
3130 IF (l_batch_header_rec.batch_status IN (gme_common_pvt.g_batch_cancelled,
3131 gme_common_pvt.g_batch_completed,
3132 gme_common_pvt.g_batch_closed) ) THEN
3133 gme_common_pvt.log_message ('GME_INV_STATUS_INSERT_STEP');
3134 RAISE fnd_api.g_exc_error;
3135 END IF;
3136
3137 -- Bug 2979072 Stop insert if there is no routing associated with this batch.
3138 IF (l_batch_header_rec.routing_id IS NULL) THEN
3139 gme_common_pvt.log_message
3140 (p_message_code => 'GME_API_NO_ROUTING_ASSOCIATED');
3141 RAISE fnd_api.g_exc_error;
3142 END IF;
3143
3144 /* Punit Kumar , bringing this code from GMEVINSB.pls*/
3145 IF (p_batch_step_rec.steprelease_type NOT IN (1, 2) ) THEN
3146 gme_common_pvt.log_message ('GME_INVALID_STEPRELEASE');
3147 RAISE fnd_api.g_exc_error;
3148 END IF;
3149
3150 /* End Bug 2397077 */
3151 IF (l_batch_header_rec.batch_status = gme_common_pvt.g_batch_closed)
3152 OR (l_batch_header_rec.batch_status = gme_common_pvt.g_batch_cancelled) THEN
3153 -- Closed or cancelled batch not valid for step insert...
3154 gme_common_pvt.log_message ('GME_INV_STATUS_INSERT_STEP');
3155 RAISE fnd_api.g_exc_error;
3156 END IF;
3157
3158 IF p_batch_step_rec.oprn_id IS NOT NULL THEN
3159 OPEN get_oprn (p_batch_step_rec.oprn_id);
3160
3161 FETCH get_oprn
3162 INTO l_oprn_no, l_oprn_vers;
3163
3164 CLOSE get_oprn;
3165
3166 IF NVL (l_oprn_no, 0) = NVL (p_oprn_no, 0)
3167 AND NVL (l_oprn_vers, 0) = NVL (p_oprn_vers, 0) THEN
3168 IF g_debug <= gme_debug.g_log_procedure THEN
3169 gme_debug.put_line (' oprn_no and oprn_vers are valid');
3170 END IF;
3171 ELSE
3172 IF g_debug <= gme_debug.g_log_procedure THEN
3173 gme_debug.put_line (' oprn_no and oprn_vers are NOT valid');
3174 RAISE insert_step_failed;
3175 END IF;
3176 END IF;
3177 ELSE
3178 IF p_oprn_no IS NOT NULL AND p_oprn_vers IS NOT NULL THEN
3179 OPEN verify_oprn (p_oprn_no
3180 ,p_oprn_vers
3181 ,p_batch_header_rec.organization_id);
3182
3183 FETCH verify_oprn
3184 INTO l_verify_oprn;
3185
3186 CLOSE verify_oprn;
3187
3188 IF l_verify_oprn IS NULL THEN
3189 IF g_debug <= gme_debug.g_log_procedure THEN
3190 gme_debug.put_line
3191 ('oprn_no and oprn_vers passed in are wrong and hence an error condition ');
3192 END IF;
3193
3194 RAISE insert_step_failed;
3195 END IF;
3196 ELSE
3197 IF g_debug <= gme_debug.g_log_procedure THEN
3198 gme_debug.put_line
3199 (' Both oprn_no and oprn_vers are null hence oprn_no and oprn_vers cannot be validated ');
3200 END IF;
3201
3202 RAISE insert_step_failed;
3203 END IF;
3204 END IF;
3205
3206 IF p_validate_flexfields = fnd_api.g_true THEN
3207 gme_common_pvt.g_flex_validate_prof := 1;
3208 ELSE
3209 gme_common_pvt.g_flex_validate_prof := 0;
3210 END IF;
3211 gme_api_main.insert_step (p_validation_level => p_validation_level
3212 ,p_init_msg_list => fnd_api.g_false
3213 ,x_message_count => x_message_count
3214 ,x_message_list => x_message_list
3215 ,x_return_status => x_return_status
3216 ,p_batch_header_rec => l_batch_header_rec
3217 ,p_batch_step_rec => p_batch_step_rec
3218 ,x_batch_step => x_batch_step_rec);
3219
3220 gme_common_pvt.g_flex_validate_prof := 0;
3221
3222 IF x_return_status <> fnd_api.g_ret_sts_success THEN
3223 RAISE insert_step_failed;
3224 ELSE
3225 IF p_commit = fnd_api.g_true THEN
3226 gme_api_pub.save_batch (p_header_id => null
3227 ,p_table => 1
3228 ,p_commit => fnd_api.g_false
3229 ,x_return_status => x_return_status);
3230
3231 IF x_return_status = fnd_api.g_ret_sts_success THEN
3232 COMMIT;
3233 ELSE
3234 RAISE fnd_api.g_exc_error;
3235 END IF;
3236 END IF;
3237 END IF;
3238
3239 gme_common_pvt.count_and_get (x_count => x_message_count
3240 ,p_encoded => fnd_api.g_false
3241 ,x_data => x_message_list);
3242
3243 IF g_debug <= gme_debug.g_log_procedure THEN
3244 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
3245 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
3246 END IF;
3247 EXCEPTION
3248 WHEN fnd_api.g_exc_error THEN
3249 ROLLBACK TO SAVEPOINT insert_step;
3250 x_return_status := fnd_api.g_ret_sts_error;
3251 gme_common_pvt.count_and_get (x_count => x_message_count
3252 ,p_encoded => fnd_api.g_false
3253 ,x_data => x_message_list);
3254 WHEN insert_step_failed THEN
3255 ROLLBACK TO SAVEPOINT insert_step;
3256 x_batch_step_rec := NULL;
3257 gme_common_pvt.count_and_get (x_count => x_message_count
3258 ,p_encoded => fnd_api.g_false
3259 ,x_data => x_message_list);
3260 WHEN OTHERS THEN
3261 ROLLBACK TO SAVEPOINT insert_step;
3262 x_batch_step_rec := NULL;
3263 gme_when_others ( p_api_name => l_api_name
3264 ,x_message_count => x_message_count
3265 ,x_message_list => x_message_list
3266 ,x_return_status => x_return_status );
3267 END insert_step;
3268
3269 /*================================================================================
3270 Procedure
3271 insert_material_line
3272 Description
3273 This procedure is used to insert a material line
3274
3275 Parameters
3276 p_batch_header_rec (R) batch for which material line has to be updated
3277 p_material_detail_rec (R) material line details that has to be inserted
3278 p_locator_code (O) Default Consumption/Yield Locator Code
3279 p_org_code (O) organization code
3280 p_batchstep_no(O) batch step no
3281 p_validate_flexfields (O) Whether to validate the flexfields
3282 x_material_detail_rec inserted material detail record
3283 x_return_status outcome of the API call
3284 S - Success
3285 E - Error
3286 U - Unexpected Error
3287 HISTORY
3288 SivakumarG Bug#5078853 02-MAR-2006
3289 Procedure Created
3290 ================================================================================*/
3291 PROCEDURE insert_material_line (
3292 p_api_version IN NUMBER := 2.0
3293 ,p_validation_level IN NUMBER := gme_common_pvt.g_max_errors
3294 ,p_init_msg_list IN VARCHAR2 DEFAULT fnd_api.g_false
3295 ,p_commit IN VARCHAR2 DEFAULT fnd_api.g_false
3296 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
3297 ,p_material_detail_rec IN gme_material_details%ROWTYPE
3298 ,p_locator_code IN VARCHAR2
3299 ,p_org_code IN VARCHAR2
3300 ,p_batchstep_no IN NUMBER := NULL
3301 ,p_validate_flexfields IN VARCHAR2 DEFAULT fnd_api.g_false
3302 ,x_material_detail_rec OUT NOCOPY gme_material_details%ROWTYPE
3303 ,x_message_count OUT NOCOPY NUMBER
3304 ,x_message_list OUT NOCOPY VARCHAR2
3305 ,x_return_status OUT NOCOPY VARCHAR2 )
3306 IS
3307 /* get the locator id */
3308 CURSOR c_get_locator(v_org_id NUMBER,v_sub_inv VARCHAR2) IS
3309 SELECT inventory_location_id locator_id
3310 FROM mtl_item_locations_kfv
3311 WHERE organization_id = v_org_id
3312 AND subinventory_code = v_sub_inv
3313 AND concatenated_segments = p_locator_code;
3314
3315 l_api_name CONSTANT VARCHAR2 (30) := 'INSERT_MATERIAL_LINE';
3316 l_batch_header_rec gme_batch_header%ROWTYPE;
3317 l_return_status VARCHAR2(1);
3318 l_batch_step_rec gme_batch_steps%ROWTYPE;
3319 l_material_detail_rec gme_material_details%ROWTYPE;
3320 p_trans_id NUMBER;
3321 l_locator_id NUMBER;
3322
3323 x_transacted VARCHAR2(30);
3324
3325 BEGIN
3326 IF (g_debug <> -1) THEN
3327 gme_debug.log_initialize ('INSERT_MATERIAL_LINE');
3328 END IF;
3329
3330 IF g_debug <= gme_debug.g_log_procedure THEN
3331 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'|| l_api_name);
3332 END IF;
3333
3334 /* Set the return status to success initially */
3335 x_return_status := fnd_api.g_ret_sts_success;
3336
3337 /* Set savepoint here */
3338 SAVEPOINT insert_material_line;
3339
3340 /* Make sure we are call compatible */
3341 IF NOT fnd_api.compatible_api_call (2.0
3342 ,p_api_version
3343 ,'insert_material_line'
3344 ,g_pkg_name) THEN
3345 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
3346 RAISE fnd_api.g_exc_error;
3347 END IF;
3348
3349 /* Initialize message list and count if needed */
3350 IF p_init_msg_list = fnd_api.g_true THEN
3351 fnd_msg_pub.initialize;
3352 END IF;
3353
3354 /* intialize local variable */
3355 l_material_detail_rec := p_material_detail_rec;
3356 gme_common_pvt.validate_batch
3357 (p_batch_header_rec => p_batch_header_rec
3358 ,p_org_code => p_org_code
3359 ,p_batch_type => nvl(p_batch_header_rec.batch_type,gme_common_pvt.g_doc_type_batch)
3360 ,x_batch_header_rec => l_batch_header_rec
3361 ,x_message_count => x_message_count
3362 ,x_message_list => x_message_list
3363 ,x_return_status => x_return_status );
3364
3365 IF x_return_status <> fnd_api.g_ret_sts_success THEN
3366 IF (g_debug = gme_debug.g_log_statement) THEN
3367 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
3368 || ': batch validate error ');
3369 END IF;
3370 RAISE fnd_api.g_exc_error;
3371 END IF;
3372
3373 /*for ASQC batches batchstep_no is required */
3374 IF l_batch_header_rec.automatic_step_calculation <> 0 AND
3375 p_batchstep_no IS NULL THEN
3376 gme_common_pvt.log_message('GME_ASQC_STEP_REQUIRED');
3377 RAISE fnd_api.g_exc_error;
3378 END IF;
3379
3380 IF l_batch_header_rec.poc_ind = 'Y' AND
3381 p_batchstep_no IS NOT NULL THEN
3382 l_batch_step_rec.batch_id := l_batch_header_rec.batch_id;
3383 l_batch_step_rec.batchstep_no := p_batchstep_no;
3384 IF NOT gme_batch_steps_dbl.fetch_row(l_batch_step_rec, l_batch_step_rec) THEN
3385 RAISE fnd_api.g_exc_error;
3386 END IF;
3387 END IF;
3388
3389 --validate batch for insertion of material line
3390 gme_material_detail_pvt.validate_batch_for_matl_ins
3391 (p_batch_header_rec => l_batch_header_rec
3392 ,p_batch_step_rec => l_batch_step_rec
3393 ,x_return_status => x_return_status );
3394
3395 IF x_return_status <> fnd_api.g_ret_sts_success THEN
3396 RAISE fnd_api.g_exc_error;
3397 END IF;
3398
3399 /* getting the locator for entered subinventory */
3400 IF l_material_detail_rec.subinventory IS NOT NULL AND
3401 p_locator_code IS NOT NULL THEN
3402 IF p_locator_code = fnd_api.g_miss_char THEN
3403 l_material_detail_rec.locator_id := fnd_api.g_miss_num;
3404 ELSE
3405 OPEN c_get_locator(l_batch_header_rec.organization_id, l_material_detail_rec.subinventory);
3406 FETCH c_get_locator INTO l_locator_id;
3407 IF c_get_locator%NOTFOUND THEN
3408 CLOSE c_get_locator;
3409 gme_common_pvt.log_message(p_product_code => 'INV'
3410 ,p_message_code => 'INV_INVALID_LOCATION');
3411 RAISE fnd_api.g_exc_error;
3412 END IF;
3413 CLOSE c_get_locator;
3414 l_material_detail_rec.locator_id := l_locator_id;
3415 END IF;
3416 END IF;
3417
3418 --setting global flex validate
3419 IF p_validate_flexfields = FND_API.G_TRUE THEN
3420 gme_common_pvt.g_flex_validate_prof := 1;
3421 ELSE
3422 gme_common_pvt.g_flex_validate_prof := 0;
3423 END IF;
3424
3425 --validate individual fields
3426 gme_material_detail_pvt.validate_material_for_ins (
3427 p_batch_header_rec => l_batch_header_rec
3428 ,p_material_detail_rec => l_material_detail_rec
3429 ,p_batch_step_rec => l_batch_step_rec
3430 ,x_material_detail_rec => x_material_detail_rec
3431 ,x_return_status => x_return_status);
3432
3433 IF x_return_status <> fnd_api.g_ret_sts_success THEN
3434 RAISE fnd_api.g_exc_error;
3435 END IF;
3436 gme_common_pvt.g_flex_validate_prof := 0;
3437 gme_common_pvt.set_timestamp;
3438 gme_common_pvt.g_move_to_temp := fnd_api.g_false;
3439 --calling insert material line new API
3440 l_material_detail_rec := x_material_detail_rec;
3441
3442 gme_api_main.insert_material_line (
3443 p_validation_level => p_validation_level
3444 ,p_init_msg_list => p_init_msg_list
3445 ,x_message_count => x_message_count
3446 ,x_message_list => x_message_list
3447 ,x_return_status => x_return_status
3448 ,p_batch_header_rec => l_batch_header_rec
3449 ,p_material_detail_rec => l_material_detail_rec
3450 ,p_batch_step_rec => l_batch_step_rec
3451 ,p_trans_id => NULL
3452 ,x_transacted => x_transacted
3453 ,x_material_detail_rec => x_material_detail_rec);
3454
3455 IF x_return_status <> fnd_api.g_ret_sts_success THEN
3456 RAISE fnd_api.g_exc_error;
3457 ELSE
3458 IF p_commit = fnd_api.g_true THEN
3459 gme_api_pub.save_batch (p_header_id => NULL
3460 ,p_table => 1
3461 ,p_commit => fnd_api.g_false
3462 ,x_return_status => x_return_status);
3463
3464 IF x_return_status = fnd_api.g_ret_sts_success THEN
3465 COMMIT;
3466 ELSE
3467 RAISE fnd_api.g_exc_error;
3468 END IF;
3469 END IF;
3470 NULL;
3471 END IF;
3472
3473 IF g_debug <= gme_debug.g_log_procedure THEN
3474 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
3475 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
3476 END IF;
3477
3478 EXCEPTION
3479 WHEN fnd_api.g_exc_error THEN
3480 ROLLBACK TO SAVEPOINT insert_material_line;
3481 x_return_status := fnd_api.g_ret_sts_error;
3482 x_material_detail_rec := NULL;
3483 gme_common_pvt.count_and_get (x_count => x_message_count
3484 ,p_encoded => fnd_api.g_false
3485 ,x_data => x_message_list);
3486 WHEN OTHERS THEN
3487 ROLLBACK TO SAVEPOINT insert_material_line;
3488 x_material_detail_rec := NULL;
3489 gme_when_others ( p_api_name => l_api_name
3490 ,x_message_count => x_message_count
3491 ,x_message_list => x_message_list
3492 ,x_return_status => x_return_status );
3493 END insert_material_line;
3494
3495 /*================================================================================
3496 Procedure
3497 update_material_line
3498 Description
3499 This procedure is used to update a material line
3500
3501 Parameters
3502 p_batch_header_rec (R) batch for which material line has to be updated
3503 p_material_detail_rec (R) material line that has to be updated
3504 p_locator_code (O) Default Consumption/Yield Locator Code
3505 p_org_code (O) organization code
3506 p_scale_phantom (O) to scale phantom product only or total batch
3507 p_validate_flexfields (O) Whether to validate the flexfields
3508 x_material_detail_rec updated material detail record
3509 x_return_status outcome of the API call
3510 S - Success
3511 E - Error
3512 U - Unexpected Error
3513 HISTORY
3514 SivakumarG Bug#5078853 02-MAR-2006
3515 Procedure Created
3516 ================================================================================*/
3517 PROCEDURE update_material_line (
3518 p_api_version IN NUMBER := 2.0
3519 ,p_validation_level IN NUMBER := gme_common_pvt.g_max_errors
3520 ,p_init_msg_list IN VARCHAR2 DEFAULT fnd_api.g_false
3521 ,p_commit IN VARCHAR2 DEFAULT fnd_api.g_false
3522 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
3523 ,p_material_detail_rec IN gme_material_details%ROWTYPE
3524 ,p_locator_code IN VARCHAR2
3525 ,p_org_code IN VARCHAR2
3526 ,p_scale_phantom IN VARCHAR2 DEFAULT fnd_api.g_false
3527 ,p_validate_flexfields IN VARCHAR2 DEFAULT fnd_api.g_false
3528 ,x_material_detail_rec OUT NOCOPY gme_material_details%ROWTYPE
3529 ,x_message_count OUT NOCOPY NUMBER
3530 ,x_message_list OUT NOCOPY VARCHAR2
3531 ,x_return_status OUT NOCOPY VARCHAR2 )
3532 IS
3533 /* get the locator id */
3534 CURSOR c_get_locator(v_org_id NUMBER,v_sub_inv VARCHAR2,v_locator VARCHAR2) IS
3535 SELECT inventory_location_id locator_id
3536 FROM mtl_item_locations_kfv
3537 WHERE organization_id = v_org_id
3538 AND subinventory_code = v_sub_inv
3539 AND concatenated_segments = v_locator;
3540
3541 CURSOR c_get_step_id(v_mat_id NUMBER) IS
3542 SELECT batchstep_id
3543 FROM gme_batch_step_items
3544 WHERE material_detail_id = v_mat_id;
3545
3546 l_api_name CONSTANT VARCHAR2 (30) := 'UPDATE_MATERIAL_LINE';
3547 l_batch_header_rec gme_batch_header%ROWTYPE;
3548 l_return_status VARCHAR2(1);
3549 l_batch_step_rec gme_batch_steps%ROWTYPE;
3550 l_material_detail_rec gme_material_details%ROWTYPE;
3551 l_stored_material_detail_rec gme_material_details%ROWTYPE;
3552 p_trans_id NUMBER;
3553 l_subinventory VARCHAR2(30);
3554 l_locator_id NUMBER;
3555 l_batchstep_id NUMBER;
3556
3557 x_transacted VARCHAR2(30);
3558 x_batch_header_rec gme_batch_header%ROWTYPE;
3559
3560
3561 BEGIN
3562
3563 IF (g_debug <> -1) THEN
3564 gme_debug.log_initialize ('UPADATE_MATERIAL_LINE');
3565 END IF;
3566 IF g_debug <= gme_debug.g_log_procedure THEN
3567 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'|| l_api_name);
3568 END IF;
3569
3570 /* Set the return status to success initially */
3571 x_return_status := fnd_api.g_ret_sts_success;
3572
3573 /* Set savepoint here */
3574 SAVEPOINT update_material_line;
3575
3576 /* Make sure we are call compatible */
3577 IF NOT fnd_api.compatible_api_call (2.0
3578 ,p_api_version
3579 ,'update_material_line'
3580 ,g_pkg_name) THEN
3581 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
3582 RAISE fnd_api.g_exc_error;
3583 END IF;
3584
3585 /* Initialize message list and count if needed */
3586 IF p_init_msg_list = fnd_api.g_true THEN
3587 fnd_msg_pub.initialize;
3588 END IF;
3589
3590 /*validatep p_scale_phantom procedure */
3591 IF (p_scale_phantom NOT IN (fnd_api.g_true, fnd_api.g_false) ) THEN
3592 gme_common_pvt.log_message ('GME_INVALID_FIELD'
3593 ,'FIELD'
3594 ,'p_scale_phantom');
3595 RAISE fnd_api.g_exc_error;
3596 END IF;
3597
3598 /* assigning local variables */
3599 l_material_detail_rec := p_material_detail_rec;
3600 gme_common_pvt.Validate_material_detail
3601 (p_material_detail_rec => l_material_detail_rec
3602 ,p_org_code => p_org_code
3603 ,p_batch_no => p_batch_header_rec.batch_no
3604 ,p_batch_type => nvl(p_batch_header_rec.batch_type,gme_common_pvt.g_doc_type_batch)
3605 ,x_batch_header_rec => l_batch_header_rec
3606 ,x_material_detail_rec => l_stored_material_detail_rec
3607 ,x_message_count => x_message_count
3608 ,x_message_list => x_message_list
3609 ,x_return_status => x_return_status );
3610 IF x_return_status <> fnd_api.g_ret_sts_success THEN
3611 IF (g_debug = gme_debug.g_log_statement) THEN
3612 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
3613 || ': batch mateiral validate error ');
3614 END IF;
3615 RAISE fnd_api.g_exc_error;
3616 END IF;
3617
3618 /* get the batch step record if the material line is associated to step*/
3619 IF l_batch_header_rec.poc_ind = 'Y' THEN --routing is there
3620 OPEN c_get_step_id(l_stored_material_detail_rec.material_detail_id);
3621 FETCH c_get_step_id INTO l_batchstep_id;
3622 IF c_get_step_id%FOUND THEN
3623 l_batch_step_rec.batchstep_id := l_batchstep_id;
3624
3625 IF NOT gme_batch_steps_dbl.fetch_row(l_batch_step_rec, l_batch_step_rec) THEN
3626 CLOSE c_get_step_id;
3627 RAISE fnd_api.g_exc_error;
3628 END IF;
3629 END IF;
3630 CLOSE c_get_step_id;
3631 END IF;
3632
3633
3634 --validate batch for update of material line
3635 gme_material_detail_pvt.validate_batch_for_matl_ins
3636 (p_batch_header_rec => l_batch_header_rec
3637 ,p_batch_step_rec => l_batch_step_rec
3638 ,x_return_status => l_return_status );
3639
3640 IF l_return_status <> fnd_api.g_ret_sts_success THEN
3641 RAISE fnd_api.g_exc_error;
3642 END IF;
3643
3644 /*updating the locator will have meaning only sub inv is existing already */
3645 l_subinventory := NVL(l_material_detail_rec.subinventory, l_stored_material_detail_rec.subinventory);
3646 IF l_subinventory IS NOT NULL AND p_locator_code IS NOT NULL THEN
3647 IF p_locator_code = fnd_api.g_miss_char THEN
3648 l_material_detail_rec.locator_id := fnd_api.g_miss_num;
3649 ELSE
3650 OPEN c_get_locator(l_stored_material_detail_rec.organization_id, l_subinventory,p_locator_code);
3651 FETCH c_get_locator INTO l_locator_id;
3652 IF c_get_locator%NOTFOUND THEN
3653 CLOSE c_get_locator;
3654 gme_common_pvt.log_message(p_product_code => 'INV'
3655 ,p_message_code => 'INV_INVALID_LOCATION');
3656 RAISE fnd_api.g_exc_error;
3657 END IF;
3658 CLOSE c_get_locator;
3659 l_material_detail_rec.locator_id := l_locator_id;
3660 END IF;
3661 END IF;
3662
3663 --setting global flex validate
3664 IF p_validate_flexfields = FND_API.G_TRUE THEN
3665 gme_common_pvt.g_flex_validate_prof := 1;
3666 ELSE
3667 gme_common_pvt.g_flex_validate_prof := 0;
3668 END IF;
3669
3670 --validate and pop material line
3671 gme_material_detail_pvt.val_and_pop_material_for_upd
3672 ( p_batch_header_rec => l_batch_header_rec
3673 ,p_material_detail_rec => l_material_detail_rec
3674 ,p_stored_material_detail_rec => l_stored_material_detail_rec
3675 ,p_batch_step_rec => l_batch_step_rec
3676 ,x_material_detail_rec => x_material_detail_rec
3677 ,x_return_status => l_return_status );
3678
3679 --resetting global flex validate after validating
3680 gme_common_pvt.g_flex_validate_prof := 0;
3681
3682 IF l_return_status <> fnd_api.g_ret_sts_success THEN
3683 RAISE fnd_api.g_exc_error;
3684 END IF;
3685 gme_common_pvt.g_move_to_temp := fnd_api.g_false;
3686 gme_common_pvt.set_timestamp;
3687 --calling update material line new API
3688 l_material_detail_rec := x_material_detail_rec;
3689
3690 gme_api_main.update_material_line (
3691 p_validation_level => p_validation_level
3692 ,p_init_msg_list => p_init_msg_list
3693 ,x_message_count => x_message_count
3694 ,x_message_list => x_message_list
3695 ,x_return_status => x_return_status
3696 ,p_batch_header_rec => l_batch_header_rec
3697 ,p_material_detail_rec => l_material_detail_rec
3698 ,p_stored_material_detail_rec => l_stored_material_detail_rec
3699 ,p_batch_step_rec => l_batch_step_rec
3700 ,p_scale_phantom => p_scale_phantom
3701 ,p_trans_id => NULL
3702 ,x_transacted => x_transacted
3703 ,x_material_detail_rec => x_material_detail_rec);
3704
3705
3706
3707 IF x_return_status <> fnd_api.g_ret_sts_success THEN
3708 RAISE fnd_api.g_exc_error;
3709 ELSE
3710 IF p_commit = fnd_api.g_true THEN
3711 gme_api_pub.save_batch (p_header_id => NULL
3712 ,p_table => 1
3713 ,p_commit => fnd_api.g_false
3714 ,x_return_status => x_return_status);
3715
3716 IF x_return_status = fnd_api.g_ret_sts_success THEN
3717 COMMIT;
3718 ELSE
3719 RAISE fnd_api.g_exc_error;
3720 END IF;
3721 END IF;
3722 NULL;
3723 END IF;
3724
3725 IF g_debug <= gme_debug.g_log_procedure THEN
3726 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
3727 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
3728 END IF;
3729
3730 EXCEPTION
3731 WHEN fnd_api.g_exc_error THEN
3732 ROLLBACK TO SAVEPOINT update_material_line;
3733 x_return_status := fnd_api.g_ret_sts_error;
3734 x_material_detail_rec := NULL;
3735 gme_common_pvt.count_and_get (x_count => x_message_count
3736 ,p_encoded => fnd_api.g_false
3737 ,x_data => x_message_list);
3738 WHEN OTHERS THEN
3739 ROLLBACK TO SAVEPOINT update_material_line;
3740 x_material_detail_rec := NULL;
3741 gme_when_others ( p_api_name => l_api_name
3742 ,x_message_count => x_message_count
3743 ,x_message_list => x_message_list
3744 ,x_return_status => x_return_status );
3745 END update_material_line;
3746
3747 /*================================================================================
3748 Procedure
3749 delete_material_line
3750 Description
3751 This procedure is used to delete a material line
3752
3753 Parameters
3754 p_batch_header_rec (R) batch for which material line has to be updated
3755 p_material_detail_rec (R) material line that has to be updated
3756 p_org_code (O) organization code
3757 x_return_status outcome of the API call
3758 S - Success
3759 E - Error
3760 U - Unexpected Error
3761 HISTORY
3762 SivakumarG Bug#5078853 02-MAR-2006
3763 Procedure Created
3764 ================================================================================*/
3765 PROCEDURE delete_material_line (
3766 p_api_version IN NUMBER := 2.0
3767 ,p_validation_level IN NUMBER := gme_common_pvt.g_max_errors
3768 ,p_init_msg_list IN VARCHAR2 DEFAULT fnd_api.g_false
3769 ,p_commit IN VARCHAR2 DEFAULT fnd_api.g_false
3770 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
3771 ,p_material_detail_rec IN gme_material_details%ROWTYPE
3772 ,p_org_code IN VARCHAR2
3773 ,x_message_count OUT NOCOPY NUMBER
3774 ,x_message_list OUT NOCOPY VARCHAR2
3775 ,x_return_status OUT NOCOPY VARCHAR2 )
3776 IS
3777 CURSOR c_get_step_id(v_mat_id NUMBER) IS
3778 SELECT batchstep_id
3779 FROM gme_batch_step_items
3780 WHERE material_detail_id = v_mat_id;
3781
3782 l_api_name CONSTANT VARCHAR2 (30) := 'DELETE_MATERIAL_LINE';
3783 l_batch_header_rec gme_batch_header%ROWTYPE;
3784 l_return_status VARCHAR2(1);
3785 l_batch_step_rec gme_batch_steps%ROWTYPE;
3786 l_material_detail_rec gme_material_details%ROWTYPE;
3787
3788 l_batchstep_id NUMBER;
3789 x_transacted VARCHAR2(30);
3790 x_batch_header_rec gme_batch_header%ROWTYPE;
3791
3792 BEGIN
3793 IF (g_debug <> -1) THEN
3794 gme_debug.log_initialize ('DELETE_MATERIAL_LINE');
3795 END IF;
3796 IF g_debug <= gme_debug.g_log_procedure THEN
3797 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'|| l_api_name);
3798 END IF;
3799
3800 /* Set the return status to success initially */
3801 x_return_status := fnd_api.g_ret_sts_success;
3802
3803 /* Set savepoint here */
3804 SAVEPOINT delete_material_line;
3805
3806 /* Make sure we are call compatible */
3807 IF NOT fnd_api.compatible_api_call (2.0
3808 ,p_api_version
3809 ,'delete_material_line'
3810 ,g_pkg_name) THEN
3811 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
3812 RAISE fnd_api.g_exc_error;
3813 END IF;
3814
3815 /* Initialize message list and count if needed */
3816 IF p_init_msg_list = fnd_api.g_true THEN
3817 fnd_msg_pub.initialize;
3818 END IF;
3819
3820 gme_common_pvt.Validate_material_detail
3821 (p_material_detail_rec => p_material_detail_rec
3822 ,p_org_code => p_org_code
3823 ,p_batch_no => p_batch_header_rec.batch_no
3824 ,p_batch_type => nvl(p_batch_header_rec.batch_type,gme_common_pvt.g_doc_type_batch)
3825 ,x_batch_header_rec => l_batch_header_rec
3826 ,x_material_detail_rec => l_material_detail_rec
3827 ,x_message_count => x_message_count
3828 ,x_message_list => x_message_list
3829 ,x_return_status => x_return_status );
3830 IF x_return_status <> fnd_api.g_ret_sts_success THEN
3831 IF (g_debug = gme_debug.g_log_statement) THEN
3832 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
3833 || ': batch mateiral validate error ');
3834 END IF;
3835 RAISE fnd_api.g_exc_error;
3836 END IF;
3837
3838 /* get the batch step record if the material line is associated to step*/
3839 IF l_batch_header_rec.poc_ind = 'Y' THEN --routing is there
3840 OPEN c_get_step_id(l_material_detail_rec.material_detail_id);
3841 FETCH c_get_step_id INTO l_batchstep_id;
3842 IF c_get_step_id%FOUND THEN
3843 l_batch_step_rec.batchstep_id := l_batchstep_id;
3844
3845 IF NOT gme_batch_steps_dbl.fetch_row(l_batch_step_rec, l_batch_step_rec) THEN
3846 CLOSE c_get_step_id;
3847 RAISE fnd_api.g_exc_error;
3848 END IF;
3849 END IF;
3850 CLOSE c_get_step_id;
3851 END IF;
3852
3853 --calling validate material (includes batch status check)
3854 gme_material_detail_pvt.validate_material_for_del (
3855 p_batch_header_rec => l_batch_header_rec
3856 ,p_material_detail_rec => l_material_detail_rec
3857 ,p_batch_step_rec => l_batch_step_rec
3858 ,x_return_status => x_return_status);
3859
3860 IF x_return_status <> fnd_api.g_ret_sts_success THEN
3861 RAISE fnd_api.g_exc_error;
3862 END IF;
3863 gme_common_pvt.g_move_to_temp := fnd_api.g_false;
3864 --calling delete material line
3865 gme_api_main.delete_material_line (
3866 p_validation_level => p_validation_level
3867 ,p_init_msg_list => p_init_msg_list
3868 ,x_message_count => x_message_count
3869 ,x_message_list => x_message_list
3870 ,x_return_status => x_return_status
3871 ,p_batch_header_rec => l_batch_header_rec
3872 ,p_material_detail_rec => l_material_detail_rec
3873 ,p_batch_step_rec => l_batch_step_rec
3874 ,x_transacted => x_transacted );
3875
3876 IF x_return_status <> fnd_api.g_ret_sts_success THEN
3877 RAISE fnd_api.g_exc_error;
3878 END IF;
3879
3880 IF g_debug <= gme_debug.g_log_procedure THEN
3881 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
3882 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
3883 END IF;
3884
3885 EXCEPTION
3886 WHEN fnd_api.g_exc_error THEN
3887 ROLLBACK TO SAVEPOINT delete_material_line;
3888 x_return_status := fnd_api.g_ret_sts_error;
3889 gme_common_pvt.count_and_get (x_count => x_message_count
3890 ,p_encoded => fnd_api.g_false
3891 ,x_data => x_message_list);
3892 WHEN OTHERS THEN
3893 ROLLBACK TO SAVEPOINT delete_material_line;
3894 gme_when_others ( p_api_name => l_api_name
3895 ,x_message_count => x_message_count
3896 ,x_message_list => x_message_list
3897 ,x_return_status => x_return_status );
3898 END delete_material_line;
3899
3900 /*================================================================================
3901 Procedure
3902 revert_batch
3903 Description
3904 This procedure reverts a completed batch to WIP and all the phantom batches.
3905
3906 Parameters
3907 p_batch_header (R) The batch header row to identify the batch
3908 Following columns are used from this row.
3909 batch_id (R)
3910 p_org_code The name of organization to which this batch belongs
3911
3912 x_batch_header The batch header that is returned, with all the data
3913 x_return_status outcome of the API call
3914 S - Success
3915 E - Error
3916 U - Unexpected Error
3917 ================================================================================*/
3918
3919 PROCEDURE revert_batch (
3920 p_api_version IN NUMBER := 2.0
3921 ,p_validation_level IN NUMBER
3922 ,p_init_msg_list IN VARCHAR2
3923 ,p_commit IN VARCHAR2
3924 ,x_message_count OUT NOCOPY NUMBER
3925 ,x_message_list OUT NOCOPY VARCHAR2
3926 ,x_return_status OUT NOCOPY VARCHAR2
3927 ,p_org_code IN VARCHAR2
3928 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
3929 ,x_batch_header_rec OUT NOCOPY gme_batch_header%ROWTYPE)IS
3930
3931 l_api_name CONSTANT VARCHAR2 (30) := 'REVERT_BATCH';
3932 l_batch_header_rec gme_batch_header%ROWTYPE;
3933 batch_revert_failure EXCEPTION;
3934 BEGIN
3935 IF (g_debug <> -1) THEN
3936 gme_debug.log_initialize('RevertBatch');
3937 END IF;
3938 IF g_debug <= gme_debug.g_log_procedure THEN
3939 gme_debug.put_line('Entering api '||g_pkg_name||'.'||l_api_name);
3940 END IF;
3941 /* Set the return status to success initially */
3942 x_return_status := FND_API.G_RET_STS_SUCCESS;
3943
3944 IF p_init_msg_list = FND_API.G_TRUE THEN
3945 fnd_msg_pub.initialize;
3946 END IF;
3947
3948 /* Set savepoint here */
3949 SAVEPOINT revert_batch;
3950
3951 IF NOT FND_API.compatible_api_call(2.0, p_api_version, 'revert_to_wip_batch', g_pkg_name ) THEN
3952 x_return_status := FND_API.G_RET_STS_ERROR;
3953 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
3954 RAISE FND_API.g_exc_error;
3955 END IF;
3956 -- fetch and validate the batch
3957 gme_common_pvt.validate_batch
3958 (p_batch_header_rec => p_batch_header_rec
3959 ,p_org_code => p_org_code
3960 ,p_batch_type => nvl(p_batch_header_rec.batch_type,gme_common_pvt.g_doc_type_batch)
3961 ,x_batch_header_rec => l_batch_header_rec
3962 ,x_message_count => x_message_count
3963 ,x_message_list => x_message_list
3964 ,x_return_status => x_return_status );
3965
3966 IF x_return_status <> fnd_api.g_ret_sts_success THEN
3967 IF (g_debug = gme_debug.g_log_statement) THEN
3968 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
3969 || ': batch validate error ');
3970 END IF;
3971 RAISE fnd_api.g_exc_error;
3972 END IF;
3973
3974 IF (l_batch_header_rec.batch_type <> gme_common_pvt.g_doc_type_batch) THEN
3975 gme_common_pvt.log_message('GME_INVALID_BATCH_TYPE');
3976 RAISE fnd_api.g_exc_error;
3977 END IF;
3978 IF (l_batch_header_rec.batch_status <> gme_common_pvt.g_batch_completed) THEN
3979 gme_common_pvt.log_message('GME_API_INVALID_BATCH_UNCERT');
3980 RAISE fnd_api.g_exc_error;
3981 END IF;
3982 IF (NVL(l_batch_header_rec.terminated_ind, 0) = 1) THEN
3983 gme_common_pvt.log_message('GME_API_REV_WIP_TERM_ERROR');
3984 RAISE fnd_api.g_exc_error;
3985 END IF;
3986
3987 IF g_debug <= gme_debug.g_log_statement THEN
3988 gme_debug.put_line('calling main revert');
3989 END IF;
3990 --Bug#5327296
3991 gme_common_pvt.g_move_to_temp := fnd_api.g_false;
3992 gme_api_main.revert_batch
3993 (p_validation_level => p_validation_level,
3994 p_init_msg_list => FND_API.G_FALSE,
3995 x_message_count => x_message_count,
3996 x_message_list => x_message_list,
3997 x_return_status => x_return_status,
3998 p_batch_header_rec => l_batch_header_rec,
3999 x_batch_header_rec => x_batch_header_rec
4000 );
4001
4002
4003 IF g_debug <= gme_debug.g_log_statement THEN
4004 gme_debug.put_line(g_pkg_name|| '.'|| l_api_name||
4005 ':'||'return_status from main'||x_return_status );
4006 END IF;
4007
4008 IF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
4009 IF p_commit = FND_API.G_TRUE THEN
4010 gme_api_pub.save_batch (p_header_id => NULL,
4011 p_table => gme_common_pvt.g_interface_table,
4012 p_commit => p_commit,
4013 x_return_status => x_return_status);
4014
4015 IF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
4016 COMMIT;
4017 ELSE
4018 RAISE fnd_api.g_exc_error;
4019 END IF;
4020 END IF;
4021 ELSE
4022 RAISE batch_revert_failure;
4023 END IF;
4024
4025 gme_common_pvt.count_and_get (
4026 x_count => x_message_count,
4027 p_encoded => FND_API.g_false,
4028 x_data => x_message_list
4029 );
4030
4031 IF g_debug <= gme_debug.g_log_procedure THEN
4032 gme_debug.put_line ('Completed '|| l_api_name|| ' at '|| TO_CHAR
4033 (SYSDATE, 'MM/DD/YYYY HH24:MI:SS'));
4034 END IF;
4035
4036 EXCEPTION
4037 WHEN batch_revert_failure THEN
4038 ROLLBACK TO SAVEPOINT revert_batch;
4039 x_batch_header_rec := NULL;
4040 gme_common_pvt.count_and_get(x_count => x_message_count,
4041 p_encoded => FND_API.g_false,
4042 x_data => x_message_list);
4043 WHEN FND_API.g_exc_error THEN
4044 ROLLBACK TO SAVEPOINT revert_batch;
4045 x_return_status := fnd_api.g_ret_sts_error;
4046 x_batch_header_rec := NULL;
4047 gme_common_pvt.count_and_get (x_count => x_message_count
4048 ,p_encoded => fnd_api.g_false
4049 ,x_data => x_message_list);
4050 WHEN OTHERS THEN
4051 ROLLBACK TO SAVEPOINT revert_batch;
4052 x_batch_header_rec := NULL;
4053 gme_when_others ( p_api_name => l_api_name
4054 ,x_message_count => x_message_count
4055 ,x_message_list => x_message_list
4056 ,x_return_status => x_return_status );
4057 END revert_batch ;
4058 /*================================================================================
4059 Procedure
4060 revert_step
4061 Description
4062 This procedure reverts a step to WIP.
4063
4064 Parameters
4065 p_batch_step (R) The batch step row to identify the step
4066 Following columns are used from this row.
4067 batchstep_id (R)
4068 actual_start_date (O) (In case of direct completion)
4069 actual_cmplt_date (O)
4070 p_org_code The name of organization to which this batch belongs
4071 p_batch_no batch number to which this step belongs
4072 x_batch_step The batch step that is returned, with all the data
4073 x_return_status outcome of the API call
4074 S - Success
4075 E - Error
4076 U - Unexpected Error
4077 ================================================================================*/
4078
4079 PROCEDURE revert_step (
4080 p_api_version IN NUMBER := 2.0
4081 ,p_validation_level IN NUMBER
4082 ,p_init_msg_list IN VARCHAR2
4083 ,p_commit IN VARCHAR2
4084 ,x_message_count OUT NOCOPY NUMBER
4085 ,x_message_list OUT NOCOPY VARCHAR2
4086 ,x_return_status OUT NOCOPY VARCHAR2
4087 ,p_org_code IN VARCHAR2
4088 ,p_batch_no IN VARCHAR2
4089 ,p_batch_step_rec IN gme_batch_steps%ROWTYPE
4090 ,x_batch_step_rec OUT NOCOPY gme_batch_steps%ROWTYPE)IS
4091
4092 l_api_name CONSTANT VARCHAR2 (30) := 'REVERT_STEP';
4093 l_batch_step_rec gme_batch_steps%ROWTYPE;
4094 l_batch_header_rec gme_batch_header%rowtype;
4095
4096 step_revert_failure EXCEPTION;
4097 BEGIN
4098 IF (g_debug <> -1) THEN
4099 gme_debug.log_initialize('RevertStep');
4100 END IF;
4101
4102 IF g_debug <= gme_debug.g_log_procedure THEN
4103 gme_debug.put_line('Entering api '||g_pkg_name||'.'||l_api_name);
4104 END IF;
4105
4106 /* Set the return status to success initially */
4107 x_return_status := FND_API.G_RET_STS_SUCCESS;
4108
4109 /* Set savepoint here */
4110 SAVEPOINT revert_step;
4111
4112 IF p_init_msg_list = FND_API.G_TRUE THEN
4113 fnd_msg_pub.initialize;
4114 END IF;
4115
4116 IF NOT FND_API.compatible_api_call(2.0, p_api_version, 'revert_step', g_pkg_name ) THEN
4117 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
4118 RAISE fnd_api.g_exc_error;
4119 END IF;
4120
4121 /* Validate Input parameters */
4122 gme_common_pvt.Validate_batch_step (
4123 p_batch_step_rec => p_batch_step_rec
4124 ,p_org_code => p_org_code
4125 ,p_batch_no => p_batch_no
4126 ,x_batch_step_rec => l_batch_step_rec
4127 ,x_batch_header_rec => l_batch_header_rec
4128 ,x_message_count => x_message_count
4129 ,x_message_list => x_message_list
4130 ,x_return_status => x_return_status );
4131
4132 IF x_return_status <> fnd_api.g_ret_sts_success THEN
4133 IF (g_debug = gme_debug.g_log_statement) THEN
4134 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
4135 || ': batch step validate error ');
4136 END IF;
4137 RAISE fnd_api.g_exc_error;
4138 END IF;
4139
4140 IF (l_batch_header_rec.batch_status <> 2) THEN
4141 gme_common_pvt.log_message ('GME_API_INV_BATCH_UNCERT_STEP');
4142 RAISE fnd_api.g_exc_error;
4143 END IF;
4144
4145 IF (l_batch_step_rec.step_status <> 3) THEN
4146 gme_common_pvt.log_message ('GME_API_INV_STEP_STAT_UNCERT');
4147 RAISE fnd_api.g_exc_error;
4148 END IF;
4149
4150 --Bug#5327296
4151 gme_common_pvt.g_move_to_temp := fnd_api.g_false;
4152 gme_api_main.revert_step
4153 (p_validation_level => p_validation_level,
4154 p_init_msg_list => FND_API.G_FALSE,
4155 x_message_count => x_message_count,
4156 x_message_list => x_message_list,
4157 x_return_status => x_return_status,
4158 p_batch_step_rec => l_batch_step_rec,
4159 p_batch_header_rec => l_batch_header_rec,
4160 x_batch_step_rec => x_batch_step_rec
4161 );
4162
4163 IF g_debug <= gme_debug.g_log_statement THEN
4164 gme_debug.put_line(g_pkg_name|| '.'|| l_api_name|| ':'||'return_status from main'||x_return_status );
4165 END IF;
4166
4167 IF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
4168 IF p_commit = FND_API.G_TRUE THEN
4169 gme_api_pub.save_batch (p_header_id => NULL,
4170 p_table => gme_common_pvt.g_interface_table,
4171 p_commit => FND_API.G_FALSE,
4172 x_return_status => x_return_status);
4173 IF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
4174 COMMIT;
4175 ELSE
4176 RAISE fnd_api.g_exc_error;
4177 END IF;
4178 END IF;
4179 ELSE
4180 RAISE step_revert_failure;
4181 END IF;
4182
4183 gme_common_pvt.count_and_get (
4184 x_count => x_message_count,
4185 p_encoded => FND_API.g_false,
4186 x_data => x_message_list
4187 );
4188
4189 IF g_debug <= gme_debug.g_log_procedure THEN
4190 gme_debug.put_line ('Completed '|| l_api_name|| ' at '|| TO_CHAR
4191 (SYSDATE, 'MM/DD/YYYY HH24:MI:SS'));
4192 END IF;
4193 EXCEPTION
4194 WHEN step_revert_failure THEN
4195 ROLLBACK TO SAVEPOINT revert_step;
4196 x_batch_step_rec := NULL;
4197 gme_common_pvt.count_and_get(x_count => x_message_count,
4198 p_encoded => FND_API.g_false,
4199 x_data => x_message_list);
4200 WHEN FND_API.g_exc_error THEN
4201 ROLLBACK TO SAVEPOINT revert_step;
4202 x_batch_step_rec := NULL;
4203 x_return_status := fnd_api.g_ret_sts_error;
4204 gme_common_pvt.count_and_get (x_count => x_message_count
4205 ,p_encoded => fnd_api.g_false
4206 ,x_data => x_message_list);
4207 WHEN OTHERS THEN
4208 ROLLBACK TO SAVEPOINT revert_step;
4209 x_batch_step_rec := NULL;
4210 gme_when_others ( p_api_name => l_api_name
4211 ,x_message_count => x_message_count
4212 ,x_message_list => x_message_list
4213 ,x_return_status => x_return_status );
4214 END revert_step ;
4215 /*************************************************************************/
4216 PROCEDURE close_batch (
4217 p_api_version IN NUMBER
4218 ,p_validation_level IN NUMBER
4219 ,p_init_msg_list IN VARCHAR2
4220 ,p_commit IN VARCHAR2
4221 ,x_message_count OUT NOCOPY NUMBER
4222 ,x_message_list OUT NOCOPY VARCHAR2
4223 ,x_return_status OUT NOCOPY VARCHAR2
4224 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
4225 ,x_batch_header_rec OUT NOCOPY gme_batch_header%ROWTYPE
4226 ,p_org_code IN VARCHAR2)
4227 IS
4228 l_api_name CONSTANT VARCHAR2 (30) := 'CLOSE_BATCH';
4229 l_batch_header_rec gme_batch_header%ROWTYPE;
4230
4231 batch_close_failure EXCEPTION;
4232 BEGIN
4233 IF g_debug <= gme_debug.g_log_procedure THEN
4234 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
4235 || l_api_name);
4236 END IF;
4237
4238 /* Set the return status to success initially */
4239 x_return_status := fnd_api.g_ret_sts_success;
4240
4241 /* Set savepoint here */
4242 SAVEPOINT close_batch_pub;
4243
4244 /* Initialize message list and count if needed */
4245 IF p_init_msg_list = fnd_api.g_true THEN
4246 fnd_msg_pub.initialize;
4247 END IF;
4248
4249 /* Make sure we are call compatible */
4250 IF NOT fnd_api.compatible_api_call (2
4251 ,p_api_version
4252 ,'close_batch'
4253 ,g_pkg_name) THEN
4254 x_return_status := fnd_api.g_ret_sts_error;
4255 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
4256 RAISE fnd_api.g_exc_error;
4257 END IF;
4258 gme_common_pvt.validate_batch
4259 (p_batch_header_rec => p_batch_header_rec
4260 ,p_org_code => p_org_code
4261 ,p_batch_type => nvl(p_batch_header_rec.batch_type,gme_common_pvt.g_doc_type_batch)
4262 ,x_batch_header_rec => l_batch_header_rec
4263 ,x_message_count => x_message_count
4264 ,x_message_list => x_message_list
4265 ,x_return_status => x_return_status );
4266
4267 IF x_return_status <> fnd_api.g_ret_sts_success THEN
4268 IF (g_debug = gme_debug.g_log_statement) THEN
4269 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
4270 || ': batch validate error ');
4271 END IF;
4272 RAISE fnd_api.g_exc_error;
4273 END IF;
4274
4275
4276 IF (l_batch_header_rec.batch_status <> gme_common_pvt.g_batch_completed) THEN
4277 gme_common_pvt.log_message ('GME_CLOSE_STATUS_ERR');
4278 RAISE fnd_api.g_exc_error;
4279 END IF;
4280
4281 IF (p_batch_header_rec.batch_close_date IS NULL) THEN
4282 l_batch_header_rec.batch_close_date := SYSDATE;
4283 ELSIF (p_batch_header_rec.batch_close_date <
4284 l_batch_header_rec.actual_cmplt_date) THEN
4285 gme_common_pvt.log_message ('GME_INVALID_DATE_RANGE' ,'DATE1' ,'Close
4286 date' ,'DATE2','completion date');
4287 RAISE fnd_api.g_exc_error;
4288 ELSIF (p_batch_header_rec.batch_close_date > SYSDATE) THEN
4289 gme_common_pvt.log_message(p_product_code => 'GMA'
4290 ,p_message_code => 'SY_NOFUTUREDATE');
4291 RAISE fnd_api.g_exc_error;
4292 ELSE
4293 l_batch_header_rec.batch_close_date :=
4294 p_batch_header_rec.batch_close_date;
4295 END IF;
4296
4297 IF g_debug <= gme_debug.g_log_procedure THEN
4298 gme_debug.put_line ('Calling gme_api_main.close_batch.');
4299 END IF;
4300
4301 gme_api_main.close_batch (p_validation_level => p_validation_level
4302 ,p_init_msg_list => fnd_api.g_false
4303 ,x_message_count => x_message_count
4304 ,x_message_list => x_message_list
4305 ,x_return_status => x_return_status
4306 ,p_batch_header_rec => l_batch_header_rec
4307 ,x_batch_header_rec => x_batch_header_rec);
4308
4309 IF (g_debug = gme_debug.g_log_statement) THEN
4310 gme_debug.put_line('Came back from Main Close Batch with status '
4311 || x_return_status);
4312 END IF;
4313
4314 IF x_return_status <> fnd_api.g_ret_sts_success THEN
4315 RAISE batch_close_failure;
4316 ELSE
4317 IF (g_debug = gme_debug.g_log_statement) THEN
4318 gme_debug.put_line ('Calling save_batch.');
4319 END IF;
4320
4321 gme_api_pub.save_batch (p_header_id => null
4322 ,p_table => 1
4323 ,p_commit => fnd_api.g_false
4324 ,x_return_status => x_return_status);
4325
4326 IF (g_debug = gme_debug.g_log_statement) THEN
4327 gme_debug.put_line ( 'Came back from save_batch with status '
4328 || x_return_status);
4329 END IF;
4330
4331 IF x_return_status <> fnd_api.g_ret_sts_success THEN
4332 RAISE fnd_api.g_exc_error;
4333 END IF;
4334
4335 IF p_commit = fnd_api.g_true THEN
4336 COMMIT;
4337 END IF;
4338 END IF;
4339
4340 IF g_debug <= gme_debug.g_log_procedure THEN
4341 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
4342 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
4343 END IF;
4344 EXCEPTION
4345 WHEN batch_close_failure THEN
4346 ROLLBACK TO SAVEPOINT close_batch_pub;
4347 x_batch_header_rec := NULL;
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 WHEN FND_API.g_exc_error THEN
4352 ROLLBACK TO SAVEPOINT close_batch_pub;
4353 x_batch_header_rec := NULL;
4354 x_return_status := fnd_api.g_ret_sts_error;
4355 gme_common_pvt.count_and_get (x_count => x_message_count
4356 ,p_encoded => fnd_api.g_false
4357 ,x_data => x_message_list);
4358 WHEN OTHERS THEN
4359 ROLLBACK TO SAVEPOINT close_batch_pub;
4360 x_batch_header_rec := NULL;
4361 gme_when_others ( p_api_name => l_api_name
4362 ,x_message_count => x_message_count
4363 ,x_message_list => x_message_list
4364 ,x_return_status => x_return_status );
4365 END close_batch;
4366 /*************************************************************************/
4367 PROCEDURE close_step (
4368 p_api_version IN NUMBER := 2
4369 /* Punit Kumar */
4370 ,p_validation_level IN NUMBER := gme_common_pvt.g_max_errors
4371 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
4372 ,p_commit IN VARCHAR2
4373 ,x_message_count OUT NOCOPY NUMBER
4374 ,x_message_list OUT NOCOPY VARCHAR2
4375 ,x_return_status OUT NOCOPY VARCHAR2
4376 ,p_batch_step_rec IN gme_batch_steps%ROWTYPE
4377 ,p_delete_pending IN VARCHAR2 := fnd_api.g_false
4378 ,p_org_code IN VARCHAR2
4379 ,p_batch_no IN VARCHAR2
4380 ,x_batch_step_rec OUT NOCOPY gme_batch_steps%ROWTYPE)
4381 IS
4382 l_api_name CONSTANT VARCHAR2 (30) := 'CLOSE_STEP';
4383
4384 l_batch_header_rec gme_batch_header%ROWTYPE;
4385 l_batch_step_rec gme_batch_steps%ROWTYPE;
4386
4387 step_close_failed EXCEPTION;
4388 BEGIN
4389 IF g_debug <= gme_debug.g_log_procedure THEN
4390 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
4391 || l_api_name);
4392 END IF;
4393 /* Set the return status to success initially */
4394 x_return_status := fnd_api.g_ret_sts_success;
4395
4396 /* Set savepoint here */
4397 SAVEPOINT close_step_pub;
4398
4399 /* Initialize message list and count if needed */
4400 IF p_init_msg_list = fnd_api.g_true THEN
4401 fnd_msg_pub.initialize;
4402 END IF;
4403
4404 /* Make sure we are call compatible */
4405 IF NOT fnd_api.compatible_api_call (2
4406 ,p_api_version
4407 ,'close_batch_step'
4408 ,g_pkg_name) THEN
4409 x_return_status := fnd_api.g_ret_sts_error;
4410 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
4411 RAISE fnd_api.g_exc_error;
4412 END IF;
4413
4414 /* Validate Input parameters */
4415 gme_common_pvt.Validate_batch_step (
4416 p_batch_step_rec => p_batch_step_rec
4417 ,p_org_code => p_org_code
4418 ,p_batch_no => p_batch_no
4419 ,x_batch_step_rec => l_batch_step_rec
4420 ,x_batch_header_rec => l_batch_header_rec
4421 ,x_message_count => x_message_count
4422 ,x_message_list => x_message_list
4423 ,x_return_status => x_return_status );
4424
4425 IF x_return_status <> fnd_api.g_ret_sts_success THEN
4426 IF (g_debug = gme_debug.g_log_statement) THEN
4427 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
4428 || ': batch step validate error ');
4429 END IF;
4430 RAISE fnd_api.g_exc_error;
4431 END IF;
4432
4433 /* Bug 2404169 all date and status checks */
4434 IF (p_batch_step_rec.step_close_date IS NULL) THEN
4435 l_batch_step_rec.step_close_date := SYSDATE;
4436 ELSIF (p_batch_step_rec.step_close_date <
4437 NVL (l_batch_step_rec.actual_cmplt_date
4438 ,p_batch_step_rec.step_close_date) ) THEN
4439 gme_common_pvt.log_message ('GME_INVALID_DATE_RANGE'
4440 ,'DATE1'
4441 ,'Close date'
4442 ,'DATE2'
4443 ,'completion date');
4444 RAISE fnd_api.g_exc_error;
4445 ELSIF (p_batch_step_rec.step_close_date > SYSDATE) THEN
4446 gme_common_pvt.log_message(p_product_code => 'GMA'
4447 ,p_message_code => 'SY_NOFUTUREDATE');
4448 RAISE fnd_api.g_exc_error;
4449 ELSE
4450 l_batch_step_rec.step_close_date := p_batch_step_rec.step_close_date;
4451 END IF;
4452
4453 IF (l_batch_step_rec.step_status <> 3) THEN
4454 gme_common_pvt.log_message ('PC_STEP_STATUS_ERR');
4455 RAISE fnd_api.g_exc_error;
4456 END IF;
4457
4458 gme_api_main.close_step (p_validation_level => p_validation_level
4459 ,p_init_msg_list => fnd_api.g_false
4460 ,x_message_count => x_message_count
4461 ,x_message_list => x_message_list
4462 ,x_return_status => x_return_status
4463 ,p_batch_header_rec => l_batch_header_rec
4464 ,p_batch_step_rec => l_batch_step_rec
4465 ,p_delete_pending => p_delete_pending
4466 ,x_batch_step_rec => x_batch_step_rec);
4467
4468 IF x_return_status <> fnd_api.g_ret_sts_success THEN
4469 RAISE step_close_failed;
4470 ELSE
4471 IF p_commit = fnd_api.g_true THEN
4472 gme_api_pub.save_batch (p_header_id => null
4473 ,p_table => 1
4474 ,p_commit => fnd_api.g_false
4475 ,x_return_status => x_return_status);
4476
4477 IF x_return_status = fnd_api.g_ret_sts_success THEN
4478 COMMIT;
4479 ELSE
4480 RAISE fnd_api.g_exc_error;
4481 END IF;
4482 END IF;
4483 END IF;
4484
4485 IF g_debug <= gme_debug.g_log_procedure THEN
4486 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
4487 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
4488 END IF;
4489 EXCEPTION
4490 WHEN step_close_failed THEN
4491 ROLLBACK TO SAVEPOINT close_step_pub;
4492 x_batch_step_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 WHEN fnd_api.g_exc_error THEN
4497 ROLLBACK TO SAVEPOINT close_step_pub;
4498 x_batch_step_rec := NULL;
4499 x_return_status := fnd_api.g_ret_sts_error;
4500 gme_common_pvt.count_and_get (x_count => x_message_count
4501 ,p_encoded => fnd_api.g_false
4502 ,x_data => x_message_list);
4503 WHEN OTHERS THEN
4504 ROLLBACK TO SAVEPOINT close_step_pub;
4505 x_batch_step_rec := NULL;
4506 gme_when_others ( p_api_name => l_api_name
4507 ,x_message_count => x_message_count
4508 ,x_message_list => x_message_list
4509 ,x_return_status => x_return_status );
4510 END close_step;
4511
4512 /*************************************************************************/
4513 PROCEDURE reopen_batch (
4514 p_api_version IN NUMBER := 2
4515 ,p_validation_level IN NUMBER
4516 := gme_common_pvt.g_max_errors
4517 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
4518 ,p_commit IN VARCHAR2
4519 ,x_message_count OUT NOCOPY NUMBER
4520 ,x_message_list OUT NOCOPY VARCHAR2
4521 ,x_return_status OUT NOCOPY VARCHAR2
4522 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
4523 ,p_org_code IN VARCHAR2
4524 ,p_reopen_steps IN VARCHAR2 := fnd_api.g_false
4525 ,x_batch_header_rec OUT NOCOPY gme_batch_header%ROWTYPE)
4526 IS
4527 l_api_name CONSTANT VARCHAR2 (30) := 'REOPEN_BATCH';
4528 l_batch_header_rec gme_batch_header%ROWTYPE;
4529 batch_reopen_failure EXCEPTION;
4530 BEGIN
4531 IF g_debug <= gme_debug.g_log_procedure THEN
4532 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
4533 || l_api_name);
4534 END IF;
4535 /* Set the success staus to success inititally*/
4536 x_return_status := fnd_api.g_ret_sts_success;
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 END IF;
4541
4542 /* Make sure we are call compatible */
4543 IF NOT fnd_api.compatible_api_call (2.0 /* Punit Kumar */
4544 ,p_api_version
4545 ,'reopen_batch'
4546 ,g_pkg_name) THEN
4547 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
4548 RAISE fnd_api.g_exc_error;
4549 END IF;
4550 gme_common_pvt.validate_batch
4551 (p_batch_header_rec => p_batch_header_rec
4552 ,p_org_code => p_org_code
4553 ,p_batch_type => nvl(p_batch_header_rec.batch_type,gme_common_pvt.g_doc_type_batch)
4554 ,x_batch_header_rec => l_batch_header_rec
4555 ,x_message_count => x_message_count
4556 ,x_message_list => x_message_list
4557 ,x_return_status => x_return_status );
4558
4559 IF x_return_status <> fnd_api.g_ret_sts_success THEN
4560 IF (g_debug = gme_debug.g_log_statement) THEN
4561 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
4562 || ': batch validate error ');
4563 END IF;
4564 RAISE fnd_api.g_exc_error;
4565 END IF;
4566 gme_api_main.reopen_batch (p_validation_level => p_validation_level
4567 ,p_init_msg_list => fnd_api.g_false
4568 ,x_message_count => x_message_count
4569 ,x_message_list => x_message_list
4570 ,x_return_status => x_return_status
4571 ,p_batch_header_rec => l_batch_header_rec
4572 ,p_reopen_steps => p_reopen_steps
4573 ,x_batch_header_rec => x_batch_header_rec);
4574
4575 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
4576 RAISE batch_reopen_failure;
4577 ELSE
4578 IF p_commit = fnd_api.g_true THEN
4579 gme_api_pub.save_batch
4580 (p_header_id => null
4581 ,p_table => 1
4582 ,p_commit => fnd_api.g_false
4583 ,x_return_status => x_return_status);
4584
4585 IF x_return_status = fnd_api.g_ret_sts_success THEN
4586 COMMIT;
4587 ELSE
4588 RAISE fnd_api.g_exc_error;
4589 END IF;
4590 END IF;
4591 END IF;
4592
4593 IF g_debug <= gme_debug.g_log_procedure THEN
4594 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
4595 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
4596 END IF;
4597 EXCEPTION
4598 WHEN batch_reopen_failure THEN
4599 x_batch_header_rec := NULL;
4600 gme_common_pvt.count_and_get (x_count => x_message_count
4601 ,p_encoded => fnd_api.g_false
4602 ,x_data => x_message_list);
4603 x_return_status := fnd_api.g_ret_sts_error;
4604 WHEN fnd_api.g_exc_error THEN
4605 x_batch_header_rec := NULL;
4606 x_return_status := fnd_api.g_ret_sts_error;
4607 gme_common_pvt.count_and_get (x_count => x_message_count
4608 ,p_encoded => fnd_api.g_false
4609 ,x_data => x_message_list);
4610 WHEN OTHERS THEN
4611 x_batch_header_rec := NULL;
4612 gme_when_others ( p_api_name => l_api_name
4613 ,x_message_count => x_message_count
4614 ,x_message_list => x_message_list
4615 ,x_return_status => x_return_status );
4616 END reopen_batch;
4617
4618 /*************************************************************************/
4619 PROCEDURE reopen_step (
4620 p_api_version IN NUMBER := 2
4621 ,p_validation_level IN NUMBER := gme_common_pvt.g_max_errors
4622 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
4623 ,p_commit IN VARCHAR2
4624 ,x_message_count OUT NOCOPY NUMBER
4625 ,x_message_list OUT NOCOPY VARCHAR2
4626 ,x_return_status OUT NOCOPY VARCHAR2
4627 ,p_org_code IN VARCHAR2
4628 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
4629 ,p_batch_step_rec IN gme_batch_steps%ROWTYPE
4630 ,x_batch_step_rec OUT NOCOPY gme_batch_steps%ROWTYPE)
4631 IS
4632 l_api_name CONSTANT VARCHAR2 (30):= 'REOPEN_STEP';
4633 l_batch_header_rec gme_batch_header%ROWTYPE;
4634 l_batch_step_rec gme_batch_steps%ROWTYPE;
4635 step_reopen_failure EXCEPTION;
4636 BEGIN
4637 IF g_debug <= gme_debug.g_log_procedure THEN
4638 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
4639 || l_api_name);
4640 END IF;
4641 /* Initialize message list and count if needed*/
4642 IF p_init_msg_list = fnd_api.g_true THEN
4643 fnd_msg_pub.initialize;
4644 END IF;
4645
4646 /* Make sure we are call compatible */
4647 IF NOT fnd_api.compatible_api_call (2
4648 ,p_api_version
4649 ,'reopen_step'
4650 ,g_pkg_name) THEN
4651 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
4652 RAISE fnd_api.g_exc_error;
4653 END IF;
4654
4655 /* Set the success staus to success inititally*/
4656 x_return_status := fnd_api.g_ret_sts_success;
4657 gme_common_pvt.Validate_batch_step (
4658 p_batch_step_rec => p_batch_step_rec
4659 ,p_org_code => p_org_code
4660 ,p_batch_no => p_batch_header_rec.batch_no
4661 ,x_batch_step_rec => l_batch_step_rec
4662 ,x_batch_header_rec => l_batch_header_rec
4663 ,x_message_count => x_message_count
4664 ,x_message_list => x_message_list
4665 ,x_return_status => x_return_status );
4666
4667 IF x_return_status <> fnd_api.g_ret_sts_success THEN
4668 IF (g_debug = gme_debug.g_log_statement) THEN
4669 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
4670 || ': batch step validate error ');
4671 END IF;
4672 RAISE fnd_api.g_exc_error;
4673 END IF;
4674 gme_api_main.reopen_step (p_validation_level => p_validation_level
4675 ,p_init_msg_list => fnd_api.g_false
4676 ,x_message_count => x_message_count
4677 ,x_message_list => x_message_list
4678 ,x_return_status => x_return_status
4679 ,p_batch_header_rec => l_batch_header_rec
4680 ,p_batch_step_rec => l_batch_step_rec
4681 ,x_batch_step_rec => x_batch_step_rec);
4682
4683 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
4684 RAISE step_reopen_failure;
4685 ELSE
4686 IF p_commit = fnd_api.g_true THEN
4687 gme_api_pub.save_batch (p_header_id => null
4688 ,p_table => 1
4689 ,p_commit => fnd_api.g_false
4690 ,x_return_status => x_return_status);
4691 IF x_return_status = fnd_api.g_ret_sts_success THEN
4692 COMMIT;
4693 ELSE
4694 RAISE fnd_api.g_exc_error;
4695 END IF;
4696 END IF;
4697 END IF;
4698
4699 IF g_debug <= gme_debug.g_log_procedure THEN
4700 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
4701 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
4702 END IF;
4703 EXCEPTION
4704 WHEN step_reopen_failure THEN
4705 x_batch_step_rec := NULL;
4706 gme_common_pvt.count_and_get (x_count => x_message_count
4707 ,p_encoded => fnd_api.g_false
4708 ,x_data => x_message_list);
4709 x_return_status := fnd_api.g_ret_sts_error;
4710 WHEN fnd_api.g_exc_error THEN
4711 x_batch_step_rec := NULL;
4712 x_return_status := fnd_api.g_ret_sts_error;
4713 gme_common_pvt.count_and_get (x_count => x_message_count
4714 ,p_encoded => fnd_api.g_false
4715 ,x_data => x_message_list);
4716 WHEN OTHERS THEN
4717 x_batch_step_rec := NULL;
4718 gme_when_others ( p_api_name => l_api_name
4719 ,x_message_count => x_message_count
4720 ,x_message_list => x_message_list
4721 ,x_return_status => x_return_status );
4722 END reopen_step;
4723
4724 /*************************************************************************/
4725 PROCEDURE incremental_backflush
4726 (p_api_version IN NUMBER
4727 ,p_validation_level IN NUMBER := gme_common_pvt.g_max_errors
4728 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
4729 ,p_commit IN VARCHAR2 := fnd_api.g_false
4730 ,x_message_count OUT NOCOPY NUMBER
4731 ,x_message_list OUT NOCOPY VARCHAR2
4732 ,x_return_status OUT NOCOPY VARCHAR2
4733 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
4734 ,p_org_code IN VARCHAR2
4735 ,p_material_detail_rec IN gme_material_details%ROWTYPE
4736 ,p_qty IN NUMBER
4737 ,p_qty_type IN NUMBER
4738 ,p_trans_date IN DATE
4739 ,p_ignore_exception IN VARCHAR2 := fnd_api.g_false
4740 ,p_adjust_cmplt IN VARCHAR2 := fnd_api.g_true
4741 ,x_exception_material_tbl OUT NOCOPY gme_common_pvt.exceptions_tab)
4742 IS
4743 l_api_name CONSTANT VARCHAR2 (30) := 'INCREMENTAL_BACKFLUSH';
4744 l_material_detail_rec gme_material_details%ROWTYPE;
4745 l_batch_header_rec gme_batch_header%ROWTYPE;
4746 l_exception_material_tbl gme_common_pvt.exceptions_tab;
4747
4748 error_incr_backflush EXCEPTION;
4749 BEGIN
4750 IF (g_debug <> -1) THEN
4751 gme_debug.log_initialize ('IncrementalBackflush');
4752 END IF;
4753
4754 IF g_debug <= gme_debug.g_log_procedure THEN
4755 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
4756 || l_api_name);
4757 END IF;
4758
4759 /* Set the return status to success initially */
4760 x_return_status := fnd_api.g_ret_sts_success;
4761
4762 IF p_init_msg_list = fnd_api.g_true THEN
4763 fnd_msg_pub.initialize;
4764 END IF;
4765 IF NOT fnd_api.compatible_api_call (2.0
4766 ,p_api_version
4767 ,'incremental_backflush'
4768 ,g_pkg_name) THEN
4769 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
4770 RAISE fnd_api.g_exc_error;
4771 END IF;
4772
4773 /* Retrieve Batch Header and Material Detail Record */
4774 gme_common_pvt.Validate_material_detail
4775 (p_material_detail_rec => p_material_detail_rec
4776 ,p_org_code => p_org_code
4777 ,p_batch_no => p_batch_header_rec.batch_no
4778 ,p_batch_type => nvl(p_batch_header_rec.batch_type,gme_common_pvt.g_doc_type_batch)
4779 ,x_batch_header_rec => l_batch_header_rec
4780 ,x_material_detail_rec => l_material_detail_rec
4781 ,x_message_count => x_message_count
4782 ,x_message_list => x_message_list
4783 ,x_return_status => x_return_status );
4784 IF x_return_status <> fnd_api.g_ret_sts_success THEN
4785 IF (g_debug = gme_debug.g_log_statement) THEN
4786 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
4787 || ': batch mateiral validate error ');
4788 END IF;
4789 RAISE fnd_api.g_exc_error;
4790 END IF;
4791 -- Validations
4792 IF p_trans_date IS NOT NULL THEN
4793 IF p_trans_date > SYSDATE THEN
4794 gme_common_pvt.log_message(p_product_code => 'GMA'
4795 ,p_message_code => 'SY_NOFUTUREDATE');
4796 RAISE fnd_api.g_exc_error;
4797 END IF;
4798 END IF;
4799
4800 /*Bug#5277982 if the batch is completed then we should not allow +veIB through API. so restricting this in public layer.
4801 we have to consider wip plan qty for new actual calculation
4802 0 - By increment qty,1 - New actual qty, 2 - % of Plan
4803 */
4804 IF l_batch_header_rec.batch_status = 3 THEN /*other batch status will be validated in the below validate procedure */
4805 IF (p_qty_type = 0 AND p_qty > 0) OR
4806 (p_qty_type = 1 AND p_qty > l_material_detail_rec.actual_qty) OR
4807 (p_qty_type = 2 AND (l_material_detail_rec.wip_plan_qty *p_qty/100) > l_material_detail_rec.actual_qty) THEN
4808 gme_common_pvt.log_message('GME_IB_NOT_ALLOWED');
4809 RAISE fnd_api.g_exc_error;
4810 END IF;
4811 END IF;
4812
4813 gme_incremental_backflush_pvt.validate_material_for_IB
4814 (p_material_detail_rec => l_material_detail_rec
4815 ,p_batch_header_rec => l_batch_header_rec
4816 ,p_adjust_cmplt => p_adjust_cmplt
4817 ,x_return_status => x_return_status);
4818
4819 IF x_return_status <> fnd_api.g_ret_sts_success THEN
4820 RAISE fnd_api.g_exc_error;
4821 END IF;
4822
4823 gme_incremental_backflush_pvt.validate_qty_for_IB
4824 (p_qty_type => p_qty_type
4825 ,p_qty => p_qty
4826 ,p_actual_qty => l_material_detail_rec.actual_qty
4827 ,x_return_status => x_return_status);
4828
4829 IF x_return_status <> fnd_api.g_ret_sts_success THEN
4830 RAISE fnd_api.g_exc_error;
4831 END IF;
4832
4833 gme_common_pvt.g_move_to_temp := fnd_api.g_false;
4834
4835 /* Invoke main */
4836 gme_api_main.incremental_backflush
4837 (p_validation_level => p_validation_level
4838 ,p_init_msg_list => fnd_api.g_false
4839 ,x_message_count => x_message_count
4840 ,x_message_list => x_message_list
4841 ,x_return_status => x_return_status
4842 ,p_batch_header_rec => l_batch_header_rec
4843 ,p_material_detail_rec => l_material_detail_rec
4844 ,p_qty => p_qty
4845 ,p_qty_type => p_qty_type
4846 ,p_trans_date => p_trans_date
4847 ,x_exception_material_tbl => l_exception_material_tbl);
4848
4849 IF p_ignore_exception = fnd_api.g_true AND x_return_status = gme_common_pvt.g_exceptions_err THEN
4850 x_return_status := fnd_api.g_ret_sts_success;
4851 ELSIF x_return_status = gme_common_pvt.g_exceptions_err THEN
4852 x_exception_material_tbl := l_exception_material_tbl;
4853 END IF;
4854
4855 IF x_return_status <> fnd_api.g_ret_sts_success THEN
4856 RAISE error_incr_backflush;
4857 END IF;
4858
4859 /* Invoke save_batch */
4860 gme_api_pub.save_batch
4861 (p_header_id => gme_common_pvt.g_transaction_header_id
4862 ,p_table => 1
4863 ,p_commit => p_commit
4864 ,x_return_status => x_return_status);
4865
4866 IF x_return_status <> fnd_api.g_ret_sts_success THEN
4867 RAISE fnd_api.g_exc_error;
4868 END IF;
4869
4870 IF g_debug <= gme_debug.g_log_procedure THEN
4871 gme_debug.put_line ( ' Completed '
4872 || l_api_name
4873 || ' at '
4874 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
4875 END IF;
4876 EXCEPTION
4877 WHEN error_incr_backflush THEN
4878 gme_common_pvt.count_and_get (x_count => x_message_count
4879 ,p_encoded => fnd_api.g_false
4880 ,x_data => x_message_list);
4881 WHEN fnd_api.g_exc_error THEN
4882 x_return_status := fnd_api.g_ret_sts_error;
4883 fnd_msg_pub.count_and_get (p_count => x_message_count
4884 ,p_encoded => fnd_api.g_false
4885 ,p_data => x_message_list);
4886 WHEN OTHERS THEN
4887 gme_when_others ( p_api_name => l_api_name
4888 ,x_message_count => x_message_count
4889 ,x_message_list => x_message_list
4890 ,x_return_status => x_return_status );
4891 END incremental_backflush;
4892
4893 /*************************************************************************/
4894 PROCEDURE create_material_txn (
4895 p_api_version IN NUMBER := 2.0
4896 ,p_validation_level IN NUMBER
4897 := gme_common_pvt.g_max_errors
4898 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
4899 ,p_commit IN VARCHAR2 := fnd_api.g_false
4900 ,x_message_count OUT NOCOPY NUMBER
4901 ,x_message_list OUT NOCOPY VARCHAR2
4902 ,x_return_status OUT NOCOPY VARCHAR2
4903 ,p_org_code IN VARCHAR2 := NULL
4904 ,p_mmti_rec IN mtl_transactions_interface%ROWTYPE
4905 ,p_mmli_tbl IN gme_common_pvt.mtl_trans_lots_inter_tbl
4906 ,p_batch_no IN VARCHAR2 := NULL
4907 ,p_line_no IN NUMBER := NULL
4908 ,p_line_type IN NUMBER := NULL
4909 ,p_create_lot IN VARCHAR2 := NULL
4910 ,p_generate_lot IN VARCHAR2 := NULL
4911 ,p_generate_parent_lot IN VARCHAR2 := NULL
4912 ,x_mmt_rec OUT NOCOPY mtl_material_transactions%ROWTYPE
4913 ,x_mmln_tbl OUT NOCOPY gme_common_pvt.mtl_trans_lots_num_tbl)
4914 IS
4915 CURSOR cur_get_item_rec (v_item_id NUMBER, v_org_id NUMBER)
4916 IS
4917 SELECT *
4918 FROM mtl_system_items_b
4919 WHERE inventory_item_id = v_item_id AND organization_id = v_org_id;
4920
4921 CURSOR cur_get_trans (v_header_id IN NUMBER)
4922 IS
4923 SELECT *
4924 FROM mtl_material_transactions
4925 WHERE transaction_set_id = v_header_id;
4926
4927 l_api_name CONSTANT VARCHAR2 (30) := 'CREATE_MATERIAL_TXN';
4928 l_mmti_rec mtl_transactions_interface%ROWTYPE;
4929 l_mmli_tbl gme_common_pvt.mtl_trans_lots_inter_tbl;
4930 l_mat_dtl_rec gme_material_details%ROWTYPE;
4931 l_mat_dtl_rec_out gme_material_details%ROWTYPE;
4932 l_batch_header_rec gme_batch_header%ROWTYPE;
4933 l_item_rec mtl_system_items_b%ROWTYPE;
4934 l_lot_rec mtl_lot_numbers%ROWTYPE;
4935 l_parent_gen_lot VARCHAR2 (2000) DEFAULT NULL;
4936 l_gen_lot VARCHAR2 (80) DEFAULT NULL;
4937 l_msg_count NUMBER;
4938 l_row_id ROWID;
4939 l_api_version NUMBER;
4940 l_source NUMBER;
4941 l_msg_data VARCHAR2 (2000);
4942 l_msg_index NUMBER (5);
4943 l_txn_count NUMBER;
4944 l_header_id NUMBER;
4945 l_return_status VARCHAR2 (1);
4946 l_trans_date DATE ;
4947 x_lot_rec mtl_lot_numbers%ROWTYPE;
4948
4949 create_txn_fail EXCEPTION;
4950 BEGIN
4951 IF (g_debug <> -1) THEN
4952 gme_debug.log_initialize ('CreateTxn');
4953 END IF;
4954
4955 IF g_debug <= gme_debug.g_log_procedure THEN
4956 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
4957 || l_api_name);
4958 END IF;
4959
4960 /* Set the return status to success initially */
4961 x_return_status := fnd_api.g_ret_sts_success;
4962
4963 /* Set savepoint here */
4964 SAVEPOINT create_material_txn;
4965
4966 IF p_init_msg_list = fnd_api.g_true THEN
4967 fnd_msg_pub.initialize;
4968 END IF;
4969
4970 IF NOT fnd_api.compatible_api_call (2.0
4971 ,p_api_version
4972 ,'create_material_txn'
4973 ,g_pkg_name) THEN
4974 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
4975 RAISE fnd_api.g_exc_error;
4976 END IF;
4977
4978 l_mmti_rec := p_mmti_rec;
4979 l_mmli_tbl := p_mmli_tbl;
4980
4981 IF (l_mmti_rec.organization_id IS NULL AND p_org_code IS NULL) THEN
4982 fnd_message.set_name ('INV', 'INV_ORG_REQUIRED');
4983 fnd_msg_pub.ADD;
4984 RAISE fnd_api.g_exc_error;
4985 END IF;
4986
4987 /* gme_common_pvt.g_error_count := 0;
4988 gme_common_pvt.g_setup_done :=
4989 gme_common_pvt.setup (p_org_id => l_mmti_rec.organization_id
4990 ,p_org_code => p_org_code);
4991
4992 IF NOT gme_common_pvt.g_setup_done THEN
4993 RAISE fnd_api.g_exc_error;
4994 ELSE
4995 l_mmti_rec.organization_id := gme_common_pvt.g_organization_id;
4996 END IF;*/
4997 gme_common_pvt.set_timestamp;
4998 /* Bug 5358129 added code so line type line no combo will also retrieve material */
4999 l_mat_dtl_rec.material_detail_id := l_mmti_rec.trx_source_line_id;
5000 l_mat_dtl_rec.line_no := p_line_no;
5001 l_mat_dtl_rec.line_type := p_line_type;
5002 gme_common_pvt.Validate_material_detail
5003 (p_material_detail_rec => l_mat_dtl_rec
5004 ,p_org_code => p_org_code
5005 ,p_batch_no => p_batch_no
5006 ,p_batch_type => gme_common_pvt.g_doc_type_batch
5007 ,x_batch_header_rec => l_batch_header_rec
5008 ,x_material_detail_rec => l_mat_dtl_rec_out
5009 ,x_message_count => x_message_count
5010 ,x_message_list => x_message_list
5011 ,x_return_status => x_return_status );
5012 IF x_return_status <> fnd_api.g_ret_sts_success THEN
5013 IF (g_debug = gme_debug.g_log_statement) THEN
5014 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
5015 || ': batch mateiral validate error ');
5016 END IF;
5017 RAISE fnd_api.g_exc_error;
5018 ELSE
5019 l_mat_dtl_rec := l_mat_dtl_rec_out;
5020 l_mmti_rec.trx_source_line_id := l_mat_dtl_rec.material_detail_id;
5021 l_mmti_rec.transaction_source_id := l_batch_header_rec.batch_id;
5022 END IF;
5023
5024 OPEN cur_get_item_rec (l_mmti_rec.inventory_item_id, l_mmti_rec.organization_id);
5025 FETCH cur_get_item_rec INTO l_item_rec;
5026 IF cur_get_item_rec%NOTFOUND THEN
5027 CLOSE cur_get_item_rec;
5028 gme_common_pvt.log_message ('PM_INVALID_ITEM');
5029 IF (g_debug = gme_debug.g_log_statement) THEN
5030 gme_debug.put_line('Item cursor fetch no record in mtl_system_items_b: ');
5031 gme_debug.put_line('inventory_item_id = '|| TO_CHAR (l_mmti_rec.inventory_item_id) );
5032 gme_debug.put_line('organization_id = '|| TO_CHAR (l_mmti_rec.organization_id) );
5033 END IF;
5034 RAISE fnd_api.g_exc_error;
5035 END IF;
5036 CLOSE cur_get_item_rec;
5037
5038 /*Bug#5394232 Begin
5039 if we don't pass any date to this procedure then we have to default the trans date*/
5040 IF l_mmti_rec.transaction_date IS NULL THEN
5041 gme_common_pvt.fetch_trans_date(
5042 p_material_detail_id => l_mat_dtl_rec.material_detail_id
5043 ,p_invoke_mode => 'T'
5044 ,x_trans_date => l_trans_date
5045 ,x_return_status => l_return_status );
5046
5047 IF l_return_status <> fnd_api.g_ret_sts_success THEN
5048 RAISE fnd_api.g_exc_error;
5049 END IF;
5050 --initializing the transaction date according to default rules
5051 l_mmti_rec.transaction_date := l_trans_date;
5052 ELSE
5053 /* transaction date can't be in future and should not be less than actual start date of the batch*/
5054 IF l_mmti_rec.transaction_date < l_batch_header_rec.actual_start_date OR
5055 l_mmti_rec.transaction_date > SYSDATE THEN
5056 gme_common_pvt.log_message('GME_NOT_VALID_TRANS_DATE');
5057 RAISE fnd_api.g_exc_error;
5058 END IF;
5059 END IF;
5060 --Bug#5394232 End
5061
5062 -- code for lot creation
5063 IF l_mat_dtl_rec.line_type IN (1, 2) THEN
5064 -- code for lot creation
5065 IF l_item_rec.lot_control_code = 2 THEN -- lot control
5066 IF p_generate_lot = fnd_api.g_true AND
5067 p_create_lot = fnd_api.g_false THEN
5068 RAISE fnd_api.g_exc_error;
5069 END IF;
5070
5071 IF p_generate_parent_lot = fnd_api.g_true THEN
5072 l_parent_gen_lot :=
5073 inv_lot_api_pub.auto_gen_lot
5074 (p_org_id => l_mmti_rec.organization_id
5075 ,p_inventory_item_id => l_mmti_rec.inventory_item_id
5076 ,p_lot_generation => NULL
5077 ,p_lot_uniqueness => NULL
5078 ,p_lot_prefix => NULL
5079 ,p_zero_pad => NULL
5080 ,p_lot_length => NULL
5081 ,p_transaction_date => NULL
5082 ,p_revision => NULL
5083 ,p_subinventory_code => NULL
5084 ,p_locator_id => NULL
5085 ,p_transaction_type_id => NULL
5086 ,p_transaction_action_id => NULL
5087 ,p_transaction_source_type_id => NULL
5088 ,p_lot_number => NULL
5089 ,p_api_version => 1.0
5090 ,p_init_msg_list => fnd_api.g_false
5091 ,p_commit => fnd_api.g_false
5092 ,p_validation_level => NULL
5093 ,p_parent_lot_number => NULL
5094 ,x_return_status => l_return_status
5095 ,x_msg_count => l_msg_count
5096 ,x_msg_data => l_msg_data);
5097
5098 IF l_return_status <> fnd_api.g_ret_sts_success THEN
5099 RAISE fnd_api.g_exc_error;
5100 END IF;
5101
5102 IF (g_debug = gme_debug.g_log_statement) THEN
5103 gme_debug.put_line ( 'lot_gen'
5104 || ':'
5105 || 'l_parent_gen_lot '
5106 || l_return_status);
5107 END IF;
5108 END IF; -- p_generate_parent_lot
5109
5110 FOR i IN 1 .. l_mmli_tbl.COUNT LOOP
5111 IF p_create_lot = fnd_api.g_true
5112 AND l_mmli_tbl (i).lot_number IS NULL THEN
5113 IF p_generate_lot = fnd_api.g_true THEN
5114 l_gen_lot :=
5115 inv_lot_api_pub.auto_gen_lot
5116 (p_org_id => l_mmti_rec.organization_id
5117 ,p_inventory_item_id => l_mmti_rec.inventory_item_id
5118 ,p_lot_generation => NULL
5119 ,p_lot_uniqueness => NULL
5120 ,p_lot_prefix => NULL
5121 ,p_zero_pad => NULL
5122 ,p_lot_length => NULL
5123 ,p_transaction_date => NULL
5124 ,p_revision => NULL
5125 ,p_subinventory_code => NULL
5126 ,p_locator_id => NULL
5127 ,p_transaction_type_id => NULL
5128 ,p_transaction_action_id => NULL
5129 ,p_transaction_source_type_id => NULL
5130 ,p_lot_number => NULL
5131 ,p_api_version => 1.0
5132 ,p_init_msg_list => fnd_api.g_false
5133 ,p_commit => fnd_api.g_false
5134 ,p_validation_level => NULL
5135 ,p_parent_lot_number => l_parent_gen_lot
5136 ,x_return_status => l_return_status
5137 ,x_msg_count => l_msg_count
5138 ,x_msg_data => l_msg_data);
5139
5140 IF l_return_status <> fnd_api.g_ret_sts_success THEN
5141 RAISE fnd_api.g_exc_error;
5142 END IF;
5143
5144 IF (g_debug = gme_debug.g_log_statement) THEN
5145 gme_debug.put_line ( 'lot_gen'
5146 || ':'
5147 || 'l_parent_gen_lot '
5148 || l_return_status);
5149 END IF;
5150 END IF; -- p_generate_lot
5151
5152 l_lot_rec.parent_lot_number := l_parent_gen_lot;
5153 l_lot_rec.organization_id := l_mmti_rec.organization_id;
5154 l_lot_rec.inventory_item_id := l_mmti_rec.inventory_item_id;
5155 l_lot_rec.lot_number := l_gen_lot;
5156 inv_lot_api_pub.create_inv_lot
5157 (x_return_status => l_return_status
5158 ,x_msg_count => l_msg_count
5159 ,x_msg_data => l_msg_data
5160 ,x_row_id => l_row_id
5161 ,x_lot_rec => x_lot_rec
5162 ,p_lot_rec => l_lot_rec
5163 ,p_source => l_source
5164 ,p_api_version => l_api_version
5165 ,p_init_msg_list => fnd_api.g_true
5166 ,p_commit => fnd_api.g_false
5167 ,p_validation_level => fnd_api.g_valid_level_full
5168 ,p_origin_txn_id => 1);
5169
5170 IF l_return_status = fnd_api.g_ret_sts_error THEN
5171 RAISE fnd_api.g_exc_error;
5172 END IF;
5173
5174 l_mmli_tbl (i).lot_number := x_lot_rec.lot_number;
5175 END IF; -- p_create_lot
5176 END LOOP;
5177 END IF; -- for lot_control
5178 END IF; -- for line_type
5179
5180 gme_common_pvt.g_move_to_temp := fnd_api.g_false;
5181 /* Bug 5554841 Migration will call this with existing header ID*/
5182 --gme_common_pvt.g_transaction_header_id := NULL;
5183 gme_transactions_pvt.create_material_txn
5184 (p_mmti_rec => l_mmti_rec
5185 ,p_mmli_tbl => l_mmli_tbl
5186 ,x_return_status => l_return_status);
5187
5188 IF l_return_status = fnd_api.g_ret_sts_success THEN
5189 IF g_debug <= gme_debug.g_log_procedure THEN
5190 gme_debug.put_line ( 'before save batch'
5191 || gme_common_pvt.g_transaction_header_id);
5192 END IF;
5193 l_header_id := gme_common_pvt.g_transaction_header_id;
5194 gme_api_pub.save_batch
5195 (p_header_id => gme_common_pvt.g_transaction_header_id
5196 ,p_table => 1
5197 ,p_commit => p_commit
5198 ,x_return_status => x_return_status);
5199
5200 IF g_debug <= gme_debug.g_log_procedure THEN
5201 gme_debug.put_line ( 'return from save batch with'
5202 || x_return_status);
5203 END IF;
5204
5205 IF x_return_status <> fnd_api.g_ret_sts_success THEN
5206 RAISE fnd_api.g_exc_error;
5207 END IF;
5208 ELSE
5209 RAISE create_txn_fail;
5210 END IF;
5211 IF g_debug <= gme_debug.g_log_procedure THEN
5212 gme_debug.put_line ( 'l_header_id'
5213 || l_header_id);
5214 END IF;
5215 -- get all the transactions from the mmt
5216 OPEN cur_get_trans (l_header_id);
5217
5218 FETCH cur_get_trans
5219 INTO x_mmt_rec;
5220
5221 CLOSE cur_get_trans;
5222
5223 -- for lots with this transaction
5224 gme_transactions_pvt.get_lot_trans
5225 (p_transaction_id => x_mmt_rec.transaction_id
5226 ,x_mmln_tbl => x_mmln_tbl
5227 ,x_return_status => x_return_status);
5228
5229 IF g_debug <= gme_debug.g_log_procedure THEN
5230 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
5231 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
5232 END IF;
5233 EXCEPTION
5234 WHEN create_txn_fail THEN
5235 ROLLBACK TO SAVEPOINT create_material_txn;
5236 gme_common_pvt.count_and_get (x_count => x_message_count
5237 ,p_encoded => fnd_api.g_false
5238 ,x_data => x_message_list);
5239 /* Bug 5554841 have to set x_return_status*/
5240 x_return_status := l_return_status;
5241 WHEN fnd_api.g_exc_error THEN
5242 ROLLBACK TO SAVEPOINT create_material_txn;
5243 x_return_status := fnd_api.g_ret_sts_error;
5244 gme_common_pvt.count_and_get (x_count => x_message_count
5245 ,p_encoded => fnd_api.g_false
5246 ,x_data => x_message_list);
5247 WHEN OTHERS THEN
5248 ROLLBACK TO SAVEPOINT create_material_txn;
5249 gme_when_others ( p_api_name => l_api_name
5250 ,x_message_count => x_message_count
5251 ,x_message_list => x_message_list
5252 ,x_return_status => x_return_status );
5253 END create_material_txn;
5254
5255 /*************************************************************************/
5256 PROCEDURE update_material_txn (
5257 p_api_version IN NUMBER := 2.0
5258 ,p_validation_level IN NUMBER
5259 := gme_common_pvt.g_max_errors
5260 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
5261 ,p_commit IN VARCHAR2 := fnd_api.g_false
5262 ,x_message_count OUT NOCOPY NUMBER
5263 ,x_message_list OUT NOCOPY VARCHAR2
5264 ,x_return_status OUT NOCOPY VARCHAR2
5265 ,p_transaction_id IN NUMBER
5266 ,p_mmti_rec IN mtl_transactions_interface%ROWTYPE
5267 ,p_mmli_tbl IN gme_common_pvt.mtl_trans_lots_inter_tbl
5268 ,p_create_lot IN VARCHAR2 := NULL
5269 ,p_generate_lot IN VARCHAR2 := NULL
5270 ,p_generate_parent_lot IN VARCHAR2 := NULL
5271 ,x_mmt_rec OUT NOCOPY mtl_material_transactions%ROWTYPE
5272 ,x_mmln_tbl OUT NOCOPY gme_common_pvt.mtl_trans_lots_num_tbl)
5273 IS
5274 CURSOR cur_get_item_rec (v_item_id NUMBER, v_org_id NUMBER)
5275 IS
5276 SELECT *
5277 FROM mtl_system_items_b
5278 WHERE inventory_item_id = v_item_id AND organization_id = v_org_id;
5279
5280 CURSOR cur_get_trans (v_header_id IN NUMBER)
5281 IS
5282 SELECT *
5283 FROM mtl_material_transactions
5284 WHERE transaction_set_id = v_header_id;
5285
5286 CURSOR cur_trans_org (v_transaction_id IN NUMBER)
5287 IS
5288 SELECT organization_id, transaction_source_id, trx_source_line_id, transaction_type_id
5289 FROM mtl_material_transactions
5290 WHERE transaction_id = v_transaction_id;
5291
5292 l_api_name CONSTANT VARCHAR2 (30) := 'UPDATE_MATERIAL_TXN';
5293 l_transaction_id NUMBER;
5294 l_mmt_rec mtl_material_transactions%ROWTYPE;
5295 l_mmln_tbl gme_common_pvt.mtl_trans_lots_num_tbl;
5296 l_mmti_rec mtl_transactions_interface%ROWTYPE;
5297 l_mmli_tbl gme_common_pvt.mtl_trans_lots_inter_tbl;
5298 l_mat_dtl_rec gme_material_details%ROWTYPE;
5299 l_item_rec mtl_system_items_b%ROWTYPE;
5300 l_msg_count NUMBER;
5301 l_msg_data VARCHAR2 (2000);
5302 l_msg_index NUMBER (5);
5303 l_txn_count NUMBER;
5304 l_orgn_id NUMBER;
5305 l_lot_rec mtl_lot_numbers%ROWTYPE;
5306 l_return_status VARCHAR2 (1);
5307 l_parent_gen_lot VARCHAR2 (2000) DEFAULT NULL;
5308 l_gen_lot VARCHAR2 (80) DEFAULT NULL;
5309 l_row_id ROWID;
5310 l_api_version NUMBER;
5311 l_source NUMBER;
5312 l_header_id NUMBER;
5313 x_lot_rec mtl_lot_numbers%ROWTYPE;
5314 l_batch_id NUMBER;
5315 l_material_detail_id NUMBER;
5316 l_txn_type_id NUMBER;
5317 update_txn_fail EXCEPTION;
5318 update_txn_mismatch EXCEPTION;
5319 BEGIN
5320 IF (g_debug <> -1) THEN
5321 gme_debug.log_initialize ('UpdateTxn');
5322 END IF;
5323
5324 IF g_debug <= gme_debug.g_log_procedure THEN
5325 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
5326 || l_api_name);
5327 END IF;
5328
5329 /* Set the savepoint */
5330 SAVEPOINT update_transaction;
5331 /* Set the return status to success initially */
5332 x_return_status := fnd_api.g_ret_sts_success;
5333
5334 IF p_init_msg_list = fnd_api.g_true THEN
5335 fnd_msg_pub.initialize;
5336 END IF;
5337
5338 IF NOT fnd_api.compatible_api_call (2.0
5339 ,p_api_version
5340 ,'update_material_txn'
5341 ,g_pkg_name) THEN
5342 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
5343 RAISE fnd_api.g_exc_error;
5344 END IF;
5345
5346 IF (p_transaction_id IS NULL) THEN
5347 gme_common_pvt.log_message ('GME_FIELD_VALUE_REQUIRED'
5348 ,'FIELD_NAME'
5349 ,'p_transaction_id');
5350 RAISE fnd_api.g_exc_error;
5351 END IF;
5352
5353 OPEN cur_trans_org (p_transaction_id);
5354 FETCH cur_trans_org INTO l_orgn_id, l_batch_id, l_material_detail_id, l_txn_type_id;
5355 CLOSE cur_trans_org;
5356
5357 l_mmti_rec := p_mmti_rec;
5358 l_mmli_tbl := p_mmli_tbl;
5359 gme_common_pvt.g_error_count := 0;
5360 gme_common_pvt.g_setup_done := gme_common_pvt.setup(p_org_id => l_orgn_id);
5361
5362 IF NOT gme_common_pvt.g_setup_done THEN
5363 RAISE fnd_api.g_exc_error;
5364 ELSE
5365 l_orgn_id := gme_common_pvt.g_organization_id;
5366 END IF;
5367
5368 gme_common_pvt.set_timestamp;
5369 l_mat_dtl_rec.material_detail_id := l_mmti_rec.trx_source_line_id;
5370
5371 IF NOT gme_material_details_dbl.fetch_row
5372 (p_material_detail => l_mat_dtl_rec
5373 ,x_material_detail => l_mat_dtl_rec) THEN
5374 RAISE fnd_api.g_exc_error;
5375 END IF;
5376 /* Added for bug 5597385 */
5377 IF (l_mat_dtl_rec.organization_id <> l_orgn_id
5378 OR l_mat_dtl_rec.batch_id <> l_batch_id
5379 OR l_mat_dtl_rec.material_detail_id <> l_material_detail_id
5380 OR l_mmti_rec.transaction_type_id <> l_txn_type_id) THEN
5381 RAISE update_txn_mismatch;
5382 END IF;
5383 -- code for lot creation
5384 IF l_mat_dtl_rec.line_type IN (1, 2) THEN
5385 OPEN cur_get_item_rec (l_mmti_rec.inventory_item_id
5386 ,l_mmti_rec.organization_id);
5387
5388 FETCH cur_get_item_rec INTO l_item_rec;
5389 IF cur_get_item_rec%NOTFOUND THEN
5390 CLOSE cur_get_item_rec;
5391 gme_common_pvt.log_message ('PM_INVALID_ITEM');
5392
5393 IF (g_debug = gme_debug.g_log_statement) THEN
5394 gme_debug.put_line
5395 ('Item cursor fetch no record in mtl_system_items_b: ');
5396 gme_debug.put_line ( 'inventory_item_id = '
5397 || TO_CHAR (l_mmti_rec.inventory_item_id) );
5398 gme_debug.put_line ( 'organization_id = '
5399 || TO_CHAR (l_mmti_rec.organization_id) );
5400 END IF;
5401 RAISE fnd_api.g_exc_error;
5402 END IF;
5403 CLOSE cur_get_item_rec;
5404
5405 -- code for lot creation
5406 IF l_item_rec.lot_control_code = 2 THEN -- lot control
5407 IF p_generate_lot = fnd_api.g_true
5408 AND p_create_lot = fnd_api.g_false THEN
5409 RAISE fnd_api.g_exc_error;
5410 END IF;
5411
5412 IF p_generate_parent_lot = fnd_api.g_true THEN
5413 l_parent_gen_lot :=
5414 inv_lot_api_pub.auto_gen_lot
5415 (p_org_id => l_mmti_rec.organization_id
5416 ,p_inventory_item_id => l_mmti_rec.inventory_item_id
5417 ,p_lot_generation => NULL
5418 ,p_lot_uniqueness => NULL
5419 ,p_lot_prefix => NULL
5420 ,p_zero_pad => NULL
5421 ,p_lot_length => NULL
5422 ,p_transaction_date => NULL
5423 ,p_revision => NULL
5424 ,p_subinventory_code => NULL
5425 ,p_locator_id => NULL
5426 ,p_transaction_type_id => NULL
5427 ,p_transaction_action_id => NULL
5428 ,p_transaction_source_type_id => NULL
5429 ,p_lot_number => NULL
5430 ,p_api_version => 1.0
5431 ,p_init_msg_list => fnd_api.g_false
5432 ,p_commit => fnd_api.g_false
5433 ,p_validation_level => NULL
5434 ,p_parent_lot_number => NULL
5435 ,x_return_status => l_return_status
5436 ,x_msg_count => l_msg_count
5437 ,x_msg_data => l_msg_data);
5438
5439 IF l_return_status <> fnd_api.g_ret_sts_success THEN
5440 RAISE fnd_api.g_exc_error;
5441 END IF;
5442
5443 IF (g_debug = gme_debug.g_log_statement) THEN
5444 gme_debug.put_line ( 'lot_gen'
5445 || ':'
5446 || 'l_parent_gen_lot '
5447 || l_return_status);
5448 END IF;
5449 END IF; -- p_generate_parent_lot
5450
5451 FOR i IN 1 .. l_mmli_tbl.COUNT LOOP
5452 IF p_create_lot = fnd_api.g_true
5453 AND l_mmli_tbl (i).lot_number IS NULL THEN
5454 IF p_generate_lot = fnd_api.g_true THEN
5455 l_gen_lot :=
5456 inv_lot_api_pub.auto_gen_lot
5457 (p_org_id => l_mmti_rec.organization_id
5458 ,p_inventory_item_id => l_mmti_rec.inventory_item_id
5459 ,p_lot_generation => NULL
5460 ,p_lot_uniqueness => NULL
5461 ,p_lot_prefix => NULL
5462 ,p_zero_pad => NULL
5463 ,p_lot_length => NULL
5464 ,p_transaction_date => NULL
5465 ,p_revision => NULL
5466 ,p_subinventory_code => NULL
5467 ,p_locator_id => NULL
5468 ,p_transaction_type_id => NULL
5469 ,p_transaction_action_id => NULL
5470 ,p_transaction_source_type_id => NULL
5471 ,p_lot_number => NULL
5472 ,p_api_version => 1.0
5473 ,p_init_msg_list => fnd_api.g_false
5474 ,p_commit => fnd_api.g_false
5475 ,p_validation_level => NULL
5476 ,p_parent_lot_number => l_parent_gen_lot
5477 ,x_return_status => l_return_status
5478 ,x_msg_count => l_msg_count
5479 ,x_msg_data => l_msg_data);
5480
5481 IF l_return_status <> fnd_api.g_ret_sts_success THEN
5482 RAISE fnd_api.g_exc_error;
5483 END IF;
5484
5485 IF (g_debug = gme_debug.g_log_statement) THEN
5486 gme_debug.put_line ( 'lot_gen'
5487 || ':'
5488 || 'l_parent_gen_lot '
5489 || l_return_status);
5490 END IF;
5491 END IF; -- p_generate_lot
5492
5493 l_lot_rec.parent_lot_number := l_parent_gen_lot;
5494 l_lot_rec.organization_id := l_mmti_rec.organization_id;
5495 l_lot_rec.inventory_item_id := l_mmti_rec.inventory_item_id;
5496 l_lot_rec.lot_number := l_gen_lot;
5497 inv_lot_api_pub.create_inv_lot
5498 (x_return_status => l_return_status
5499 ,x_msg_count => l_msg_count
5500 ,x_msg_data => l_msg_data
5501 ,x_row_id => l_row_id
5502 ,x_lot_rec => x_lot_rec
5503 ,p_lot_rec => l_lot_rec
5504 ,p_source => l_source
5505 ,p_api_version => l_api_version
5506 ,p_init_msg_list => fnd_api.g_true
5507 ,p_commit => fnd_api.g_false
5508 ,p_validation_level => fnd_api.g_valid_level_full
5509 ,p_origin_txn_id => 1);
5510
5511 IF l_return_status = fnd_api.g_ret_sts_error THEN
5512 RAISE fnd_api.g_exc_error;
5513 END IF;
5514
5515 l_mmli_tbl (i).lot_number := x_lot_rec.lot_number;
5516 END IF; -- p_create_lot
5517 END LOOP;
5518 END IF; -- for lot_control
5519 END IF; -- for line_type
5520
5521 gme_common_pvt.g_move_to_temp := fnd_api.g_false;
5522 gme_common_pvt.g_transaction_header_id := NULL;
5523 gme_transactions_pvt.update_material_txn
5524 (p_transaction_id => p_transaction_id
5525 ,p_mmti_rec => l_mmti_rec
5526 ,p_mmli_tbl => l_mmli_tbl
5527 ,x_return_status => l_return_status);
5528
5529 IF l_return_status = fnd_api.g_ret_sts_success THEN
5530 IF g_debug <= gme_debug.g_log_procedure THEN
5531 gme_debug.put_line ( 'before save batch'
5532 || gme_common_pvt.g_transaction_header_id);
5533 END IF;
5534 l_header_id:= gme_common_pvt.g_transaction_header_id;
5535 gme_api_pub.save_batch
5536 (p_header_id => gme_common_pvt.get_txn_header_id
5537 ,p_table => 1
5538 ,p_commit => p_commit
5539 ,x_return_status => x_return_status);
5540
5541 IF g_debug <= gme_debug.g_log_procedure THEN
5542 gme_debug.put_line ( 'return from save batch with'
5543 || x_return_status);
5544 END IF;
5545
5546 IF x_return_status <> fnd_api.g_ret_sts_success THEN
5547 RAISE fnd_api.g_exc_error;
5548 END IF;
5549 ELSE
5550 RAISE update_txn_fail;
5551 END IF;
5552
5553 IF g_debug <= gme_debug.g_log_procedure THEN
5554 gme_debug.put_line ( 'l_header_id'
5555 || l_header_id);
5556 END IF;
5557 -- get all the transactions from the mmt
5558 OPEN cur_get_trans (l_header_id);
5559
5560 FETCH cur_get_trans
5561 INTO x_mmt_rec;
5562
5563 CLOSE cur_get_trans;
5564
5565 -- for lots with this transaction
5566 gme_transactions_pvt.get_lot_trans
5567 (p_transaction_id => x_mmt_rec.transaction_id
5568 ,x_mmln_tbl => x_mmln_tbl
5569 ,x_return_status => x_return_status);
5570
5571 IF g_debug <= gme_debug.g_log_procedure THEN
5572 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
5573 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
5574 END IF;
5575 EXCEPTION
5576 WHEN update_txn_mismatch THEN
5577 ROLLBACK TO SAVEPOINT update_transaction;
5578 gme_common_pvt.log_message('GME_TXN_UPDATE_MISMATCH');
5579 x_return_status := fnd_api.g_ret_sts_error;
5580 gme_common_pvt.count_and_get (x_count => x_message_count
5581 ,p_encoded => fnd_api.g_false
5582 ,x_data => x_message_list);
5583 WHEN update_txn_fail THEN
5584 ROLLBACK TO SAVEPOINT update_transaction;
5585 gme_common_pvt.count_and_get (x_count => x_message_count
5586 ,p_encoded => fnd_api.g_false
5587 ,x_data => x_message_list);
5588 WHEN fnd_api.g_exc_error THEN
5589 ROLLBACK TO SAVEPOINT update_transaction;
5590 x_return_status := fnd_api.g_ret_sts_error;
5591 gme_common_pvt.count_and_get (x_count => x_message_count
5592 ,p_encoded => fnd_api.g_false
5593 ,x_data => x_message_list);
5594 WHEN OTHERS THEN
5595 gme_when_others ( p_api_name => l_api_name
5596 ,x_message_count => x_message_count
5597 ,x_message_list => x_message_list
5598 ,x_return_status => x_return_status );
5599 END update_material_txn;
5600
5601 /*************************************************************************/
5602 PROCEDURE delete_material_txn (
5603 p_api_version IN NUMBER := 2.0
5604 ,p_validation_level IN NUMBER
5605 := gme_common_pvt.g_max_errors
5606 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
5607 ,p_commit IN VARCHAR2 := fnd_api.g_false
5608 ,x_message_count OUT NOCOPY NUMBER
5609 ,x_message_list OUT NOCOPY VARCHAR2
5610 ,x_return_status OUT NOCOPY VARCHAR2
5611 ,p_transaction_id IN NUMBER)
5612 IS
5613 l_api_name CONSTANT VARCHAR2 (30) := 'DELETE_MATERIAL_TXN';
5614 l_transaction_id NUMBER;
5615 l_msg_count NUMBER;
5616 l_msg_data VARCHAR2 (2000);
5617 l_msg_index NUMBER (5);
5618 l_txn_count NUMBER;
5619 l_return_status VARCHAR2 (1) := fnd_api.g_ret_sts_success;
5620 l_orgn_id NUMBER;
5621
5622 setup_failure EXCEPTION;
5623 error_condition EXCEPTION;
5624
5625
5626 delete_txn_fail EXCEPTION;
5627 batch_save_failed EXCEPTION;
5628
5629 CURSOR cur_trans_org (v_transaction_id IN NUMBER)
5630 IS
5631 SELECT organization_id
5632 FROM mtl_material_transactions
5633 WHERE transaction_id = v_transaction_id;
5634 BEGIN
5635 IF (g_debug <> -1) THEN
5636 gme_debug.log_initialize ('DeleteTxn');
5637 END IF;
5638
5639 IF g_debug <= gme_debug.g_log_procedure THEN
5640 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
5641 || l_api_name);
5642 END IF;
5643
5644 /* Set the savepoint */
5645 SAVEPOINT delete_transaction;
5646
5647 /* Set the return status to success initially */
5648 x_return_status := fnd_api.g_ret_sts_success;
5649
5650 IF p_init_msg_list = fnd_api.g_true THEN
5651 fnd_msg_pub.initialize;
5652 END IF;
5653
5654 IF NOT fnd_api.compatible_api_call (2.0
5655 ,p_api_version
5656 ,'delete_material_txn'
5657 ,g_pkg_name) THEN
5658 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
5659 RAISE fnd_api.g_exc_error;
5660 END IF;
5661
5662 IF (p_transaction_id IS NULL) THEN
5663 gme_common_pvt.log_message ('GME_FIELD_VALUE_REQUIRED'
5664 ,'FIELD_NAME'
5665 ,'p_transaction_id');
5666 RAISE fnd_api.g_exc_error;
5667 END IF;
5668
5669 OPEN cur_trans_org (p_transaction_id);
5670 FETCH cur_trans_org INTO l_orgn_id;
5671
5672 CLOSE cur_trans_org;
5673
5674 gme_common_pvt.g_error_count := 0;
5675 gme_common_pvt.g_setup_done :=
5676 gme_common_pvt.setup (p_org_id => l_orgn_id);
5677
5678 IF NOT gme_common_pvt.g_setup_done THEN
5679 RAISE fnd_api.g_exc_error;
5680 ELSE
5681 l_orgn_id := gme_common_pvt.g_organization_id;
5682 END IF;
5683
5684 gme_common_pvt.set_timestamp;
5685 gme_common_pvt.g_move_to_temp := fnd_api.g_false;
5686 gme_common_pvt.g_transaction_header_id := NULL;
5687 l_transaction_id := p_transaction_id;
5688 gme_transactions_pvt.delete_material_txn
5689 (p_transaction_id => l_transaction_id
5690 ,x_return_status => x_return_status);
5691
5692 IF x_return_status = fnd_api.g_ret_sts_success THEN
5693 IF (p_commit = fnd_api.g_true) THEN
5694 gme_api_pub.save_batch
5695 (p_header_id => gme_common_pvt.get_txn_header_id
5696 ,p_table => 1
5697 ,p_commit => p_commit
5698 ,x_return_status => x_return_status);
5699
5700 IF x_return_status = fnd_api.g_ret_sts_success THEN
5701 COMMIT;
5702 ELSE
5703 RAISE fnd_api.g_exc_error;
5704 END IF;
5705 END IF;
5706 ELSE
5707 RAISE delete_txn_fail;
5708 END IF;
5709
5710 IF g_debug <= gme_debug.g_log_procedure THEN
5711 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
5712 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
5713 END IF;
5714 EXCEPTION
5715 WHEN delete_txn_fail THEN
5716 ROLLBACK TO SAVEPOINT delete_transaction;
5717 gme_common_pvt.count_and_get (x_count => x_message_count
5718 ,p_encoded => fnd_api.g_false
5719 ,x_data => x_message_list);
5720 WHEN fnd_api.g_exc_error THEN
5721 ROLLBACK TO SAVEPOINT delete_transaction;
5722 x_return_status := fnd_api.g_ret_sts_error;
5723 gme_common_pvt.count_and_get (x_count => x_message_count
5724 ,p_encoded => fnd_api.g_false
5725 ,x_data => x_message_list);
5726 WHEN OTHERS THEN
5727 gme_when_others ( p_api_name => l_api_name
5728 ,x_message_count => x_message_count
5729 ,x_message_list => x_message_list
5730 ,x_return_status => x_return_status );
5731 END delete_material_txn;
5732 /*================================================================================
5733 Procedure
5734 reroute_batch
5735 Description
5736 This procedure reroutes batch (typically change the route associated with the batch).
5737 Parameters
5738 p_batch_header_rec (R) The batch header row to identify the batch
5739 Following columns are used from this row.
5740 batch_id (R)
5741 p_org_code (R) if batch_no is specified instead of batch_id
5742 on batch header row
5743 p_validity_rule_id (R) Recipe validity rule id for the new recipe.
5744 x_batch_header_rec The batch header that is returned, with all the data
5745 x_return_status outcome of the API call
5746 S - Success
5747 E - Error
5748 U - Unexpected Error
5749 C - No continous periods found
5750 ================================================================================*/
5751 PROCEDURE reroute_batch (
5752 p_api_version IN NUMBER := 2.0
5753 ,p_validation_level IN NUMBER
5754 := gme_common_pvt.g_max_errors
5755 ,p_init_msg_list IN VARCHAR2 DEFAULT fnd_api.g_false
5756 ,p_commit IN VARCHAR2 DEFAULT fnd_api.g_false
5757 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
5758 ,p_validity_rule_id IN NUMBER
5759 ,p_org_code IN VARCHAR2
5760 ,p_use_workday_cal IN VARCHAR2 DEFAULT fnd_api.g_false
5761 ,p_contiguity_override IN VARCHAR2 DEFAULT fnd_api.g_false
5762 ,x_message_count OUT NOCOPY NUMBER
5763 ,x_message_list OUT NOCOPY VARCHAR2
5764 ,x_return_status OUT NOCOPY VARCHAR2
5765 ,x_batch_header_rec OUT NOCOPY gme_batch_header%ROWTYPE)
5766 IS
5767 l_api_name CONSTANT VARCHAR2 (30) := 'REROUTE_BATCH';
5768 l_batch_header_rec gme_batch_header%ROWTYPE;
5769
5770 reroute_batch_failed EXCEPTION;
5771 BEGIN
5772 IF (g_debug <> -1) THEN
5773 gme_debug.log_initialize ('RerouteBatch');
5774 END IF;
5775
5776 IF g_debug <= gme_debug.g_log_procedure THEN
5777 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
5778 || l_api_name);
5779 END IF;
5780 /* Set the return status to success initially */
5781 x_return_status := fnd_api.g_ret_sts_success;
5782
5783 /* Set savepoint here */
5784 SAVEPOINT reroute_batch_pub;
5785
5786 IF (fnd_api.to_boolean (p_init_msg_list) ) THEN
5787 fnd_msg_pub.initialize;
5788 gme_common_pvt.g_error_count := 0;
5789 END IF;
5790
5791 -- Standard call to check for call compatibility.
5792 IF NOT fnd_api.compatible_api_call (2.0
5793 ,p_api_version
5794 ,l_api_name
5795 ,g_pkg_name) THEN
5796 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
5797 RAISE fnd_api.g_exc_error;
5798 END IF;
5799
5800 --FPBug#4585491 Begin
5801 /* Check for p_use_workday_cal */
5802 IF (p_use_workday_cal NOT IN (fnd_api.g_true, fnd_api.g_false) ) THEN
5803 gme_common_pvt.log_message ('GME_INVALID_FIELD'
5804 ,'FIELD'
5805 ,'p_use_workday_cal');
5806 RAISE fnd_api.g_exc_error;
5807 END IF;
5808
5809 /* Check for p_contiguity_override */
5810 IF (p_contiguity_override NOT IN (fnd_api.g_true, fnd_api.g_false) ) THEN
5811 gme_common_pvt.log_message ('GME_INVALID_FIELD'
5812 ,'FIELD'
5813 ,'p_contiguity_override');
5814 RAISE fnd_api.g_exc_error;
5815 END IF;
5816 --FPBug#4585491 End
5817
5818 /* Set the return status to success initially */
5819 x_return_status := fnd_api.g_ret_sts_success;
5820
5821 /* Get the Batch header */
5822 gme_common_pvt.validate_batch
5823 (p_batch_header_rec => p_batch_header_rec
5824 ,p_org_code => p_org_code
5825 ,p_batch_type => nvl(p_batch_header_rec.batch_type,gme_common_pvt.g_doc_type_batch)
5826 ,x_batch_header_rec => l_batch_header_rec
5827 ,x_message_count => x_message_count
5828 ,x_message_list => x_message_list
5829 ,x_return_status => x_return_status );
5830
5831 IF x_return_status <> fnd_api.g_ret_sts_success THEN
5832 IF (g_debug = gme_debug.g_log_statement) THEN
5833 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
5834 || ': batch validate error ');
5835 END IF;
5836 RAISE fnd_api.g_exc_error;
5837 END IF;
5838
5839 gme_reroute_batch_pvt.validate_validity_id_from_pub
5840 (p_batch_header_rec => l_batch_header_rec
5841 ,p_validity_rule_id => p_validity_rule_id
5842 ,x_return_status => x_return_status);
5843
5844 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
5845 RAISE fnd_api.g_exc_error;
5846 ELSIF (x_return_status = fnd_api.g_ret_sts_unexp_error) THEN
5847 RAISE fnd_api.g_exc_unexpected_error;
5848 END IF;
5849
5850 gme_api_main.reroute_batch
5851 (p_validation_level => p_validation_level
5852 ,p_init_msg_list => fnd_api.g_false
5853 ,p_batch_header_rec => l_batch_header_rec
5854 ,p_validity_rule_id => p_validity_rule_id
5855 ,p_use_workday_cal => p_use_workday_cal
5856 ,p_contiguity_override => p_contiguity_override
5857 ,x_message_count => x_message_count
5858 ,x_message_list => x_message_list
5859 ,x_return_status => x_return_status
5860 ,x_batch_header_rec => x_batch_header_rec);
5861
5862 IF (x_return_status = 'C') THEN
5863 RAISE fnd_api.g_exc_error; --message will be set on stack in pvt layer itself
5864 ELSIF (x_return_status = fnd_api.g_ret_sts_error) THEN
5865 RAISE reroute_batch_failed;
5866 ELSIF (x_return_status = fnd_api.g_ret_sts_unexp_error) THEN
5867 RAISE fnd_api.g_exc_unexpected_error;
5868 END IF;
5869 gme_api_pub.save_batch
5870 (p_header_id => NULL
5871 ,p_table => gme_common_pvt.g_interface_table
5872 ,p_commit => p_commit
5873 ,x_return_status => x_return_status);
5874
5875 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
5876 RAISE fnd_api.g_exc_error;
5877 ELSIF (x_return_status = fnd_api.g_ret_sts_unexp_error) THEN
5878 RAISE fnd_api.g_exc_unexpected_error;
5879 END IF;
5880
5881 IF (fnd_api.to_boolean (p_commit) ) THEN
5882 COMMIT WORK;
5883 END IF;
5884
5885 gme_common_pvt.count_and_get (x_count => x_message_count
5886 ,p_encoded => fnd_api.g_false
5887 ,x_data => x_message_list);
5888
5889 IF g_debug <= gme_debug.g_log_procedure THEN
5890 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
5891 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
5892 END IF;
5893 EXCEPTION
5894 WHEN reroute_batch_failed THEN
5895 ROLLBACK TO SAVEPOINT reroute_batch_pub;
5896 x_batch_header_rec := NULL;
5897 gme_common_pvt.count_and_get (x_count => x_message_count
5898 ,p_encoded => fnd_api.g_false
5899 ,x_data => x_message_list);
5900 WHEN fnd_api.g_exc_error THEN
5901 ROLLBACK TO SAVEPOINT reroute_batch_pub;
5902 x_batch_header_rec := NULL;
5903 x_return_status := fnd_api.g_ret_sts_error;
5904 gme_common_pvt.count_and_get (x_count => x_message_count
5905 ,p_encoded => fnd_api.g_false
5906 ,x_data => x_message_list);
5907 WHEN fnd_api.g_exc_unexpected_error THEN
5908 ROLLBACK TO SAVEPOINT reroute_batch_pub;
5909 x_batch_header_rec := NULL;
5910 x_return_status := fnd_api.g_ret_sts_unexp_error;
5911
5912 IF (g_debug > 0) THEN gme_debug.put_line ( g_pkg_name || '.' ||
5913 l_api_name || ':' || 'UNEXPECTED:' || SQLERRM);
5914 END IF;
5915 gme_common_pvt.count_and_get (x_count => x_message_count
5916 ,p_encoded => fnd_api.g_false
5917 ,x_data => x_message_list);
5918 WHEN OTHERS THEN
5919 ROLLBACK TO SAVEPOINT reroute_batch_pub;
5920 x_batch_header_rec := NULL;
5921 gme_when_others ( p_api_name => l_api_name
5922 ,x_message_count => x_message_count
5923 ,x_message_list => x_message_list
5924 ,x_return_status => x_return_status );
5925 END reroute_batch;
5926
5927 /*================================================================================
5928 Procedure
5929 cancel_batch
5930 Description
5931 This procedure cancels batch and all the phantom batches.
5932 It also cancels all the steps.
5933
5934 Parameters
5935 p_batch_header (R) The batch header row to identify the batch
5936 Following columns are used from this row.
5937 batch_id (R)
5938 p_org_code The name of organization to which this batch belongs
5939 x_batch_header The batch header that is returned, with all the data
5940 x_return_status outcome of the API call
5941 S - Success
5942 E - Error
5943 U - Unexpected Error
5944 ================================================================================*/
5945 PROCEDURE cancel_batch (
5946 p_api_version IN NUMBER := 2.0
5947 ,p_validation_level IN NUMBER
5948 := gme_common_pvt.g_max_errors
5949 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
5950 ,p_commit IN VARCHAR2 := fnd_api.g_false
5951 ,x_message_count OUT NOCOPY NUMBER
5952 ,x_message_list OUT NOCOPY VARCHAR2
5953 ,x_return_status OUT NOCOPY VARCHAR2
5954 ,p_org_code IN VARCHAR2
5955 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
5956 ,x_batch_header_rec OUT NOCOPY gme_batch_header%ROWTYPE)
5957 IS
5958 l_api_name CONSTANT VARCHAR2 (30) := 'CANCEL_BATCH';
5959 l_batch_header_rec gme_batch_header%ROWTYPE;
5960
5961 batch_cancel_failure EXCEPTION;
5962 BEGIN
5963 IF (g_debug <> -1) THEN
5964 gme_debug.log_initialize ('CancelBatch');
5965 END IF;
5966
5967 IF g_debug <= gme_debug.g_log_procedure THEN
5968 gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
5969 || 'Entering');
5970 END IF;
5971
5972 /* Set the return status to success initially */
5973 x_return_status := fnd_api.g_ret_sts_success;
5974
5975 /* Set savepoint here */
5976 SAVEPOINT cancel_batch_pub;
5977
5978 IF p_init_msg_list = fnd_api.g_true THEN
5979 fnd_msg_pub.initialize;
5980 END IF;
5981
5982 IF NOT fnd_api.compatible_api_call (2.0
5983 ,p_api_version
5984 ,'cancel_batch'
5985 ,g_pkg_name) THEN
5986 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
5987 RAISE fnd_api.g_exc_error;
5988 END IF;
5989
5990 --fetch the batch
5991 gme_common_pvt.validate_batch
5992 (p_batch_header_rec => p_batch_header_rec
5993 ,p_org_code => p_org_code
5994 ,p_batch_type => nvl(p_batch_header_rec.batch_type,gme_common_pvt.g_doc_type_batch)
5995 ,x_batch_header_rec => l_batch_header_rec
5996 ,x_message_count => x_message_count
5997 ,x_message_list => x_message_list
5998 ,x_return_status => x_return_status );
5999
6000 IF x_return_status <> fnd_api.g_ret_sts_success THEN
6001 IF (g_debug = gme_debug.g_log_statement) THEN
6002 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
6003 || ': batch validate error ');
6004 END IF;
6005 RAISE fnd_api.g_exc_error;
6006 END IF;
6007
6008
6009 IF (l_batch_header_rec.batch_type <> gme_common_pvt.g_doc_type_batch) THEN
6010 gme_common_pvt.log_message ('GME_INVALID_BATCH_TYPE');
6011 RAISE fnd_api.g_exc_error;
6012 END IF;
6013
6014 gme_common_pvt.g_error_count := 0;
6015
6016 /* Check for batch status */
6017 IF l_batch_header_rec.batch_status <> gme_common_pvt.g_batch_pending THEN
6018 gme_common_pvt.log_message ('GME_API_INVALID_BATCH_CANCEL');
6019 RAISE fnd_api.g_exc_error;
6020 END IF;
6021
6022 IF g_debug <= gme_debug.g_log_statement THEN
6023 gme_debug.put_line ( g_pkg_name || '.' || l_api_name || ':'
6024 || 'calling main cancel');
6025 END IF;
6026
6027 gme_api_main.cancel_batch (p_validation_level => p_validation_level
6028 ,p_init_msg_list => fnd_api.g_false
6029 ,x_message_count => x_message_count
6030 ,x_message_list => x_message_list
6031 ,x_return_status => x_return_status
6032 ,p_batch_header_rec => l_batch_header_rec
6033 ,x_batch_header_rec => x_batch_header_rec);
6034
6035 IF g_debug <= gme_debug.g_log_statement THEN
6036 gme_debug.put_line ( g_pkg_name || '.' || l_api_name || ':' ||
6037 'return_status from main'|| x_return_status);
6038 END IF;
6039
6040 IF x_return_status = fnd_api.g_ret_sts_success THEN
6041 IF p_commit = fnd_api.g_true THEN
6042 gme_api_pub.save_batch
6043 (p_header_id => NULL
6044 ,p_table => gme_common_pvt.g_interface_table
6045 ,p_commit => p_commit
6046 ,x_return_status => x_return_status);
6047
6048 IF x_return_status = fnd_api.g_ret_sts_success THEN
6049 COMMIT;
6050 ELSE
6051 RAISE fnd_api.g_exc_error;
6052 END IF;
6053 END IF;
6054 ELSE
6055 RAISE batch_cancel_failure;
6056 END IF;
6057
6058 gme_common_pvt.count_and_get (x_count => x_message_count
6059 ,p_encoded => fnd_api.g_false
6060 ,x_data => x_message_list);
6061
6062 IF g_debug <= gme_debug.g_log_procedure THEN
6063 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
6064 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
6065 END IF;
6066 EXCEPTION
6067 WHEN batch_cancel_failure THEN
6068 ROLLBACK TO SAVEPOINT cancel_batch_pub;
6069 x_batch_header_rec := NULL;
6070 gme_common_pvt.count_and_get (x_count => x_message_count
6071 ,p_encoded => fnd_api.g_false
6072 ,x_data => x_message_list);
6073 WHEN fnd_api.g_exc_error THEN
6074 ROLLBACK TO SAVEPOINT cancel_batch_pub;
6075 x_return_status := fnd_api.g_ret_sts_error;
6076 x_batch_header_rec := NULL;
6077 gme_common_pvt.count_and_get (x_count => x_message_count
6078 ,p_encoded => fnd_api.g_false
6079 ,x_data => x_message_list);
6080 WHEN OTHERS THEN
6081 ROLLBACK TO SAVEPOINT cancel_batch_pub;
6082 x_batch_header_rec := NULL;
6083 gme_when_others ( p_api_name => l_api_name
6084 ,x_message_count => x_message_count
6085 ,x_message_list => x_message_list
6086 ,x_return_status => x_return_status );
6087 END cancel_batch;
6088
6089 /*================================================================================
6090 Procedure
6091 terminate_batch
6092
6093 Description
6094 This procedure terminates batch and all the phantom batches.
6095 It also terminates all the steps.
6096
6097 Parameters
6098 p_batch_header (R) The batch header row to identify the batch
6099 Following columns are used from this row.
6100 batch_id (R)
6101 p_org_code The name of organization to which this batch belongs
6102 p_reason_name Reason to terminate the batch
6103 x_batch_header The batch header that is returned, with all the data
6104 x_return_status outcome of the API call
6105 S - Success
6106 E - Error
6107 U - Unexpected Error
6108 ================================================================================*/
6109 PROCEDURE terminate_batch (
6110 p_api_version IN NUMBER := 2.0
6111 ,p_validation_level IN NUMBER
6112 := gme_common_pvt.g_max_errors
6113 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
6114 ,p_commit IN VARCHAR2 := fnd_api.g_false
6115 ,x_message_count OUT NOCOPY NUMBER
6116 ,x_message_list OUT NOCOPY VARCHAR2
6117 ,x_return_status OUT NOCOPY VARCHAR2
6118 ,p_org_code IN VARCHAR2
6119 ,p_reason_name IN VARCHAR2
6120 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
6121 ,x_batch_header_rec OUT NOCOPY gme_batch_header%ROWTYPE)
6122 IS
6123 CURSOR cur_val_reason_id (v_reason_id NUMBER)
6124 IS
6125 SELECT 1
6126 FROM mtl_transaction_reasons
6127 WHERE NVL (disable_date, SYSDATE + 1) > SYSDATE
6128 AND reason_id = v_reason_id;
6129
6130 CURSOR cur_val_reason_name (v_reason_name VARCHAR)
6131 IS
6132 SELECT reason_id
6133 FROM mtl_transaction_reasons
6134 WHERE NVL (disable_date, SYSDATE + 1) > SYSDATE
6135 AND reason_name = v_reason_name;
6136
6137 i NUMBER;
6138 l_api_name CONSTANT VARCHAR2 (30) := 'TERMINATE_BATCH';
6139 l_batch_header_rec gme_batch_header%ROWTYPE;
6140 l_reason_valid NUMBER;
6141
6142 batch_terminate_failure EXCEPTION;
6143 BEGIN
6144 IF (g_debug <> -1) THEN
6145 gme_debug.log_initialize ('TerminateBatch');
6146 END IF;
6147
6148 IF g_debug <= gme_debug.g_log_procedure THEN
6149 gme_debug.put_line (g_pkg_name || '.' || l_api_name || ':'
6150 || 'Entering');
6151 END IF;
6152
6153 /* Set the return status to success initially */
6154 x_return_status := fnd_api.g_ret_sts_success;
6155
6156 /* Set savepoint here */
6157 SAVEPOINT terminate_batch;
6158
6159 IF p_init_msg_list = fnd_api.g_true THEN
6160 fnd_msg_pub.initialize;
6161 END IF;
6162
6163 IF NOT fnd_api.compatible_api_call (2.0
6164 ,p_api_version
6165 ,'terminate_batch'
6166 ,g_pkg_name) THEN
6167 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
6168 RAISE fnd_api.g_exc_error;
6169 END IF;
6170 --Bug#5281136 Fetching the batch before checking for the reason_id or reason name.
6171 --fetch the batch
6172 gme_common_pvt.validate_batch
6173 (p_batch_header_rec => p_batch_header_rec
6174 ,p_org_code => p_org_code
6175 ,p_batch_type => nvl(p_batch_header_rec.batch_type,gme_common_pvt.g_doc_type_batch)
6176 ,x_batch_header_rec => l_batch_header_rec
6177 ,x_message_count => x_message_count
6178 ,x_message_list => x_message_list
6179 ,x_return_status => x_return_status );
6180
6181 IF x_return_status <> fnd_api.g_ret_sts_success THEN
6182 IF (g_debug = gme_debug.g_log_statement) THEN
6183 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
6184 || ': batch validate error ');
6185 END IF;
6186 RAISE fnd_api.g_exc_error;
6187 END IF;
6188
6189 /* Check for reason id */
6190 IF p_batch_header_rec.terminate_reason_id IS NOT NULL THEN
6191 OPEN cur_val_reason_id (p_batch_header_rec.terminate_reason_id);
6192
6193 FETCH cur_val_reason_id
6194 INTO l_reason_valid;
6195
6196 CLOSE cur_val_reason_id;
6197
6198 IF l_reason_valid = 1 THEN
6199 l_batch_header_rec.terminate_reason_id :=
6200 p_batch_header_rec.terminate_reason_id;
6201 ELSE
6202 gme_common_pvt.log_message(p_product_code => 'INV'
6203 ,p_message_code => 'INV_LOTC_REASONID_INVALID');
6204 RAISE FND_API.g_exc_error;
6205 END IF;
6206 ELSIF p_reason_name IS NOT NULL THEN
6207 i := 0;
6208 FOR get_rec IN cur_val_reason_name (p_reason_name) LOOP
6209 i := i + 1;
6210 l_batch_header_rec.terminate_reason_id := get_rec.reason_id;
6211 END LOOP;
6212
6213 IF i > 1 THEN
6214 gme_common_pvt.log_message('GME_REASON_NAME_NOT_UNIQUE');
6215 RAISE FND_API.g_exc_error;
6216 ELSIF i = 0 THEN
6217 gme_common_pvt.log_message('GME_INVALID_REASON_NAME');
6218 RAISE FND_API.g_exc_error;
6219 END IF;
6220 END IF;
6221
6222
6223 IF (l_batch_header_rec.batch_type <> gme_common_pvt.g_doc_type_batch) THEN
6224 gme_common_pvt.log_message ('GME_INVALID_BATCH_TYPE');
6225 RAISE fnd_api.g_exc_error;
6226 END IF;
6227
6228 gme_common_pvt.g_error_count := 0;
6229
6230 /* Check for batch status */
6231 IF l_batch_header_rec.batch_status <> gme_common_pvt.g_batch_wip THEN
6232 gme_common_pvt.log_message ('GME_INVALID_BSTAT_TERM');
6233
6234 IF (g_debug <= gme_debug.g_log_statement) THEN
6235 gme_debug.put_line ( g_pkg_name || '.' || l_api_name || ':'
6236 || 'INVALID_BATCH_STATUS');
6237 END IF;
6238
6239 RAISE fnd_api.g_exc_error;
6240 END IF;
6241
6242 /* check for dates*/
6243 /* Completion date cannot be greater than start date or in future */
6244 IF p_batch_header_rec.actual_cmplt_date IS NULL THEN
6245 l_batch_header_rec.actual_cmplt_date := SYSDATE;
6246 ELSIF (p_batch_header_rec.actual_cmplt_date <
6247 l_batch_header_rec.actual_start_date) THEN
6248 gme_common_pvt.log_message ('GME_INVALID_DATE_RANGE' ,'DATE1'
6249 ,'Termination date' ,'DATE2','Start date');
6250 x_return_status := fnd_api.g_ret_sts_error;
6251 RAISE fnd_api.g_exc_error;
6252 ELSIF (p_batch_header_rec.actual_cmplt_date > SYSDATE) THEN
6253 gme_common_pvt.log_message(p_product_code => 'GMA'
6254 ,p_message_code => 'SY_NOFUTUREDATE');
6255 x_return_status := fnd_api.g_ret_sts_error;
6256 RAISE fnd_api.g_exc_error;
6257 ELSE
6258 l_batch_header_rec.actual_cmplt_date :=
6259 p_batch_header_rec.actual_cmplt_date;
6260 END IF;
6261
6262 IF g_debug <= gme_debug.g_log_statement THEN
6263 gme_debug.put_line ('calling main terminate');
6264 END IF;
6265
6266 gme_api_main.terminate_batch (p_validation_level => p_validation_level
6267 ,p_init_msg_list => fnd_api.g_false
6268 ,x_message_count => x_message_count
6269 ,x_message_list => x_message_list
6270 ,x_return_status => x_return_status
6271 ,p_batch_header_rec => l_batch_header_rec
6272 ,x_batch_header_rec => x_batch_header_rec);
6273
6274 IF g_debug <= gme_debug.g_log_statement THEN
6275 gme_debug.put_line ( g_pkg_name
6276 || '.'
6277 || l_api_name
6278 || ':'
6279 || 'return_status from main'
6280 || x_return_status);
6281 END IF;
6282
6283 IF x_return_status = fnd_api.g_ret_sts_success THEN
6284 IF p_commit = fnd_api.g_true THEN
6285 gme_api_pub.save_batch
6286 (p_header_id => NULL
6287 ,p_table => gme_common_pvt.g_interface_table
6288 ,p_commit => p_commit
6289 ,x_return_status => x_return_status);
6290
6291 IF x_return_status = fnd_api.g_ret_sts_success THEN
6292 COMMIT;
6293 ELSE
6294 RAISE fnd_api.g_exc_error;
6295 END IF;
6296 END IF;
6297 ELSE
6298 RAISE batch_terminate_failure;
6299 END IF;
6300
6301 gme_common_pvt.count_and_get (x_count => x_message_count
6302 ,p_encoded => fnd_api.g_false
6303 ,x_data => x_message_list);
6304
6305 IF g_debug <= gme_debug.g_log_procedure THEN
6306 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
6307 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
6308 END IF;
6309 EXCEPTION
6310 WHEN batch_terminate_failure THEN
6311 ROLLBACK TO SAVEPOINT terminate_batch;
6312 x_batch_header_rec := NULL;
6313 gme_common_pvt.count_and_get (x_count => x_message_count
6314 ,p_encoded => fnd_api.g_false
6315 ,x_data => x_message_list);
6316 WHEN fnd_api.g_exc_error THEN
6317 ROLLBACK TO SAVEPOINT terminate_batch;
6318 x_batch_header_rec := NULL;
6319 x_return_status := fnd_api.g_ret_sts_error;
6320 gme_common_pvt.count_and_get (x_count => x_message_count
6321 ,p_encoded => fnd_api.g_false
6322 ,x_data => x_message_list);
6323 WHEN OTHERS THEN
6324 ROLLBACK TO SAVEPOINT terminate_batch;
6325 IF g_debug <= gme_debug.g_log_unexpected THEN
6326 gme_debug.put_line ( g_pkg_name
6327 || '.'
6328 || l_api_name
6329 || ':'
6330 || 'When others exception:'
6331 || SQLERRM);
6332 END IF;
6333 x_batch_header_rec := NULL;
6334 gme_when_others ( p_api_name => l_api_name
6335 ,x_message_count => x_message_count
6336 ,x_message_list => x_message_list
6337 ,x_return_status => x_return_status );
6338 END terminate_batch;
6339
6340 /*************************************************************************/
6341 PROCEDURE convert_dtl_reservation (
6342 p_api_version IN NUMBER := 2.0
6343 ,p_validation_level IN NUMBER
6344 := gme_common_pvt.g_max_errors
6345 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
6346 ,p_commit IN VARCHAR2 := fnd_api.g_false
6347 ,x_message_count OUT NOCOPY NUMBER
6348 ,x_message_list OUT NOCOPY VARCHAR2
6349 ,x_return_status OUT NOCOPY VARCHAR2
6350 ,p_reservation_rec IN mtl_reservations%ROWTYPE
6351 ,p_qty_convert IN NUMBER := NULL)
6352 IS
6353 l_api_name CONSTANT VARCHAR2 (30) := 'CONVERT_DTL_RESERVATION';
6354 l_material_details_rec gme_material_details%ROWTYPE;
6355 l_reservation_rec mtl_reservations%ROWTYPE;
6356 l_valid_status VARCHAR2(1);
6357
6358 detail_reservation_error EXCEPTION;
6359
6360 CURSOR cur_fetch_reservation (v_reservation_id NUMBER)
6361 IS
6362 SELECT *
6363 FROM mtl_reservations
6364 WHERE reservation_id = v_reservation_id;
6365 BEGIN
6366 IF (g_debug <> -1) THEN
6367 gme_debug.log_initialize ('ConvertDtlReservation');
6368 END IF;
6369
6370 IF g_debug <= gme_debug.g_log_procedure THEN
6371 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
6372 || l_api_name);
6373 END IF;
6374
6375 /* Set the savepoint */
6376 SAVEPOINT convert_dtl_reservation;
6377
6378 /* Set the return status to success initially */
6379 x_return_status := fnd_api.g_ret_sts_success;
6380
6381 IF p_init_msg_list = fnd_api.g_true THEN
6382 fnd_msg_pub.initialize;
6383 END IF;
6384
6385 IF NOT fnd_api.compatible_api_call (2.0
6386 ,p_api_version
6387 ,'convert_dtl_reservation'
6388 ,g_pkg_name) THEN
6389 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
6390 RAISE fnd_api.g_exc_error;
6391 END IF;
6392
6393 IF g_debug <= gme_debug.g_log_statement THEN
6394 gme_debug.put_line ( g_pkg_name || '.' || l_api_name || ' Input
6395 reservation_id is '|| p_reservation_rec.reservation_id);
6396 END IF;
6397
6398 /* Verify that the reservation exists */
6399 OPEN cur_fetch_reservation (p_reservation_rec.reservation_id);
6400
6401 FETCH cur_fetch_reservation
6402 INTO l_reservation_rec;
6403
6404 IF cur_fetch_reservation%NOTFOUND THEN
6405 CLOSE cur_fetch_reservation;
6406
6407 gme_common_pvt.log_message ('GME_NO_DATA_FOUND'
6408 ,'TABLE_NAME'
6409 ,'MTL_RESERVATIONS');
6410
6411 IF g_debug <= gme_debug.g_log_statement THEN gme_debug.put_line (
6412 g_pkg_name || '.' || l_api_name || ' Retrieval failure against
6413 mtl_reservations using id of ' || p_reservation_rec.reservation_id);
6414 END IF;
6415
6416 RAISE fnd_api.g_exc_error;
6417 END IF;
6418 CLOSE cur_fetch_reservation;
6419
6420 /* Do setups appropriate to the organization */
6421 gme_common_pvt.g_setup_done :=
6422 gme_common_pvt.setup (p_org_id => l_reservation_rec.organization_id
6423 ,p_org_code => NULL);
6424
6425 IF NOT gme_common_pvt.g_setup_done THEN
6426 RAISE fnd_api.g_exc_error;
6427 END IF;
6428
6429 gme_common_pvt.set_timestamp;
6430 /* Verify that we have a valid row in gme_material_details */
6431 l_material_details_rec.material_detail_id :=
6432 l_reservation_rec.demand_source_line_id;
6433
6434 IF NOT (gme_material_details_dbl.fetch_row (l_material_details_rec
6435 ,l_material_details_rec) ) THEN
6436 RAISE fnd_api.g_exc_error;
6437 END IF;
6438
6439 /* Validate the demand source - it must be a valid ingredient line */
6440 IF g_debug <= gme_debug.g_log_statement THEN
6441 gme_debug.put_line
6442 ( g_pkg_name
6443 || '.'
6444 || l_api_name
6445 || ' Invoke validate_supply_demand for demand line of '
6446 || l_material_details_rec.material_detail_id);
6447 END IF;
6448
6449 GME_API_GRP.validate_supply_demand(
6450 x_return_status => x_return_status,
6451 x_msg_count => x_message_count,
6452 x_msg_data => x_message_list,
6453 x_valid_status => l_valid_status,
6454 p_organization_id => l_material_details_rec.organization_id,
6455 p_item_id => l_material_details_rec.inventory_item_id,
6456 p_supply_demand_code => 2, -- signals DEMAND
6457 p_supply_demand_type_id => INV_RESERVATION_GLOBAL.g_source_type_wip,
6458 p_supply_demand_header_id => l_material_details_rec.batch_id,
6459 p_supply_demand_line_id => l_material_details_rec.material_detail_id,
6460 p_supply_demand_line_detail => FND_API.G_MISS_NUM,
6461 p_demand_ship_date => NULL,
6462 p_expected_receipt_date => NULL,
6463 p_api_version_number => 1.0,
6464 p_init_msg_lst => FND_API.G_FALSE );
6465
6466 IF g_debug <= gme_debug.g_log_statement THEN
6467 gme_debug.put_line
6468 ( g_pkg_name
6469 || '.'
6470 || l_api_name
6471 || ' Return status from gme_api_grp.validate_supply_demand is '
6472 || x_return_status);
6473 END IF;
6474
6475 IF x_return_status <> FND_API.G_RET_STS_SUCCESS
6476 OR l_valid_status <> 'Y' THEN
6477 RAISE fnd_api.g_exc_error;
6478 END IF;
6479
6480 /* Invoke private layer to process transactions */
6481 gme_reservations_pvt.convert_dtl_reservation
6482 (p_reservation_rec => l_reservation_rec
6483 ,p_material_details_rec => l_material_details_rec
6484 ,p_qty_convert => p_qty_convert
6485 ,x_message_count => x_message_count
6486 ,x_message_list => x_message_list
6487 ,x_return_status => x_return_status);
6488
6489 IF g_debug <= gme_debug.g_log_statement THEN
6490 gme_debug.put_line
6491 ( g_pkg_name
6492 || '.'
6493 || l_api_name
6494 || ' Return status from gme_reservations_pvt.convert_dtl_reservation is '
6495 || x_return_status);
6496 END IF;
6497
6498 IF x_return_status <> fnd_api.g_ret_sts_success THEN
6499 RAISE detail_reservation_error;
6500 END IF;
6501 gme_api_pub.save_batch
6502 (p_header_id => gme_common_pvt.g_transaction_header_id
6503 ,p_table => 1
6504 ,p_commit => p_commit
6505 ,x_return_status => x_return_status);
6506
6507 IF g_debug <= gme_debug.g_log_statement THEN
6508 gme_debug.put_line
6509 ( g_pkg_name
6510 || '.'
6511 || l_api_name
6512 || ' return status from gme_api_pub.save_batch is '
6513 || x_return_status);
6514 END IF;
6515
6516 IF x_return_status <> fnd_api.g_ret_sts_success THEN
6517 RAISE fnd_api.g_exc_error;
6518 END IF;
6519
6520 IF g_debug <= gme_debug.g_log_procedure THEN
6521 gme_debug.put_line ( ' Completed '
6522 || l_api_name
6523 || ' at '
6524 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
6525 END IF;
6526 EXCEPTION
6527 WHEN detail_reservation_error THEN
6528 ROLLBACK TO SAVEPOINT convert_dtl_reservation;
6529 gme_common_pvt.count_and_get (x_count => x_message_count
6530 ,p_encoded => fnd_api.g_false
6531 ,x_data => x_message_list);
6532 WHEN OTHERS THEN
6533 ROLLBACK TO SAVEPOINT convert_dtl_reservation;
6534 gme_when_others ( p_api_name => l_api_name
6535 ,x_message_count => x_message_count
6536 ,x_message_list => x_message_list
6537 ,x_return_status => x_return_status );
6538 END convert_dtl_reservation;
6539
6540 /*************************************************************************/
6541 PROCEDURE insert_batchstep_resource (
6542 p_api_version IN NUMBER
6543 ,p_validation_level IN NUMBER
6544 := gme_common_pvt.g_max_errors
6545 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
6546 ,p_commit IN VARCHAR2 := fnd_api.g_false
6547 ,p_batchstep_resource_rec IN gme_batch_step_resources%ROWTYPE
6548 ,p_org_code IN VARCHAR2 := NULL
6549 ,p_batch_no IN VARCHAR2 := NULL
6550 ,p_batchstep_no IN NUMBER := NULL
6551 ,p_activity IN VARCHAR2 := NULL
6552 ,p_ignore_qty_below_cap IN VARCHAR2 := fnd_api.g_false
6553 ,p_validate_flexfields IN VARCHAR2 := fnd_api.g_false
6554 ,x_batchstep_resource_rec OUT NOCOPY gme_batch_step_resources%ROWTYPE
6555 ,x_message_count OUT NOCOPY NUMBER
6556 ,x_message_list OUT NOCOPY VARCHAR2
6557 ,x_return_status OUT NOCOPY VARCHAR2)
6558 IS
6559 l_api_name CONSTANT VARCHAR2 (30)
6560 := 'INSERT_BATCHSTEP_RESOURCE';
6561 l_batch_header gme_batch_header%ROWTYPE;
6562 l_batchstep_resource_rec gme_batch_step_resources%ROWTYPE;
6563 l_batchstep_resource_rec_out gme_batch_step_resources%ROWTYPE;
6564 l_table NUMBER;
6565 l_step_status NUMBER;
6566 l_dummy NUMBER;
6567 l_batch_id NUMBER;
6568 l_batchstep_id NUMBER;
6569 l_rsrc_id NUMBER;
6570 l_delete_mark NUMBER;
6571 l_min_capacity NUMBER;
6572 l_max_capacity NUMBER;
6573 l_max_step_capacity NUMBER;
6574 l_capacity_constraint NUMBER;
6575 l_capacity_um VARCHAR2 (3);
6576 l_usage_uom VARCHAR2 (3);
6577 l_capacity_tolerance NUMBER;
6578 l_return_status VARCHAR2 (2);
6579
6580 insert_rsrc_failed EXCEPTION;
6581
6582 /* Cursor Declarations */
6583 CURSOR cur_validate_activity (v_activity_id NUMBER)
6584 IS
6585 SELECT batchstep_id, batch_id
6586 FROM gme_batch_step_activities
6587 WHERE batchstep_activity_id = v_activity_id;
6588
6589 CURSOR cur_validate_batch_type (v_activity_id NUMBER)
6590 IS
6591 SELECT 1
6592 FROM gme_batch_header a, gme_batch_step_activities b
6593 WHERE a.batch_id = b.batch_id
6594 AND b.batchstep_activity_id = v_activity_id
6595 AND a.batch_type = 10;
6596
6597 CURSOR cur_get_rsrc_dtl (v_resources VARCHAR2, v_organization_id VARCHAR2)
6598 IS
6599 SELECT min_capacity, max_capacity, capacity_constraint, capacity_um
6600 ,usage_uom, delete_mark, capacity_tolerance
6601 FROM cr_rsrc_dtl
6602 WHERE resources = v_resources
6603 AND organization_id = v_organization_id;
6604
6605 CURSOR cur_get_rsrc_hdr (v_resources VARCHAR2)
6606 IS
6607 SELECT min_capacity, max_capacity, capacity_constraint, capacity_um
6608 ,std_usage_uom, delete_mark, capacity_tolerance
6609 FROM cr_rsrc_mst
6610 WHERE resources = v_resources;
6611
6612 CURSOR cur_get_step_status (v_batch_id NUMBER, v_batchstep_id NUMBER)
6613 IS
6614 SELECT step_status
6615 FROM gme_batch_steps
6616 WHERE batch_id = v_batch_id AND batchstep_id = v_batchstep_id;
6617 BEGIN
6618 IF (g_debug <> -1) THEN
6619 gme_debug.log_initialize ('InsertBatchstepResource');
6620 END IF;
6621
6622 IF g_debug <= gme_debug.g_log_procedure THEN
6623 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
6624 || l_api_name);
6625 END IF;
6626
6627 /* Set the savepoint */
6628 SAVEPOINT insert_batchstep_rsrc;
6629
6630 /* Set the return status to success initially */
6631 x_return_status := fnd_api.g_ret_sts_success;
6632
6633 /* Make sure we are call compatible */
6634 IF NOT fnd_api.compatible_api_call (2.0
6635 ,p_api_version
6636 ,'insert_batchstep_resource'
6637 ,g_pkg_name) THEN
6638 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
6639 RAISE fnd_api.g_exc_error;
6640 END IF;
6641
6642 /* Initialize message list and count if needed */
6643 IF p_init_msg_list = fnd_api.g_true THEN
6644 fnd_msg_pub.initialize;
6645 gme_common_pvt.g_error_count := 0;
6646 END IF;
6647
6648 /* Setup the common constants used across the apis */
6649 /* This will raise an error if both organization_id and org_code are null values */
6650 IF g_debug <= gme_debug.g_log_statement THEN
6651 gme_debug.put_line ( g_pkg_name || '.' || l_api_name ||
6652 'Invoking setup for org_id ' ||
6653 p_batchstep_resource_rec.organization_id ||
6654 ' org_code ' || p_org_code);
6655 END IF;
6656
6657 gme_common_pvt.g_setup_done :=
6658 gme_common_pvt.setup
6659 (p_org_id => p_batchstep_resource_rec.organization_id
6660 ,p_org_code => p_org_code);
6661
6662 IF NOT gme_common_pvt.g_setup_done THEN
6663 RAISE fnd_api.g_exc_error;
6664 END IF;
6665
6666 gme_common_pvt.set_timestamp;
6667 gme_common_pvt.g_check_primary_rsrc := 1;
6668 l_batchstep_resource_rec := p_batchstep_resource_rec;
6669 l_batchstep_resource_rec.organization_id :=
6670 gme_common_pvt.g_organization_id;
6671
6672 IF l_batchstep_resource_rec.resources IS NULL THEN
6673 gme_common_pvt.log_message ('GME_FIELD_VALUE_REQUIRED'
6674 ,'FIELD_NAME'
6675 ,'RESOURCES');
6676 RAISE fnd_api.g_exc_error;
6677 END IF;
6678
6679 IF l_batchstep_resource_rec.batchstep_activity_id IS NOT NULL THEN
6680 -- validate the key provided
6681 IF g_debug <= gme_debug.g_log_statement THEN
6682 gme_debug.put_line
6683 ( g_pkg_name
6684 || '.'
6685 || l_api_name
6686 || ' validate batchstep activity id'
6687 || l_batchstep_resource_rec.batchstep_activity_id);
6688 END IF;
6689
6690 OPEN cur_validate_activity
6691 (l_batchstep_resource_rec.batchstep_activity_id);
6692
6693 FETCH cur_validate_activity
6694 INTO l_batchstep_id, l_batch_id;
6695
6696 IF cur_validate_activity%NOTFOUND THEN
6697 CLOSE cur_validate_activity;
6698
6699 gme_common_pvt.log_message
6700 ('GME_ACTID_NOT_FOUND'
6701 ,'BATCHSTEP_ACT_ID'
6702 ,l_batchstep_resource_rec.batchstep_activity_id);
6703 RAISE fnd_api.g_exc_error;
6704 END IF;
6705
6706 CLOSE cur_validate_activity;
6707
6708 -- make sure activity id does not belong to an FPO
6709 IF g_debug <= gme_debug.g_log_statement THEN
6710 gme_debug.put_line ( g_pkg_name
6711 || '.'
6712 || l_api_name
6713 || ' validate for FPO');
6714 END IF;
6715
6716 OPEN cur_validate_batch_type
6717 (l_batchstep_resource_rec.batchstep_activity_id);
6718
6719 FETCH cur_validate_batch_type
6720 INTO l_dummy;
6721
6722 IF cur_validate_batch_type%FOUND THEN
6723 CLOSE cur_validate_batch_type;
6724
6725 gme_common_pvt.log_message ('GME_FPO_RSRC_NO_EDIT');
6726 RAISE fnd_api.g_exc_error;
6727 END IF;
6728
6729 CLOSE cur_validate_batch_type;
6730 ELSE
6731 /* User supplies EITHER internal identifiers via p_batchstep_resource_rec OR a
6732 series of keys. In the case of the latter, these must be validated and converted to
6733 internal identifiers for ongoing processing */
6734 IF g_debug <= gme_debug.g_log_statement THEN
6735 gme_debug.put_line ( g_pkg_name
6736 || '.'
6737 || l_api_name
6738 || ' Invoke validate_param');
6739 END IF;
6740
6741 gme_batchstep_rsrc_pvt.validate_param
6742 (p_org_code => gme_common_pvt.g_organization_code
6743 ,p_batch_no => p_batch_no
6744 ,p_batchstep_no => p_batchstep_no
6745 ,p_activity => p_activity
6746 ,p_resource => l_batchstep_resource_rec.resources
6747 ,x_organization_id => l_batchstep_resource_rec.organization_id
6748 ,x_batch_id => l_batchstep_resource_rec.batch_id
6749 ,x_batchstep_id => l_batchstep_resource_rec.batchstep_id
6750 ,x_activity_id => l_batchstep_resource_rec.batchstep_activity_id
6751 ,x_rsrc_id => l_rsrc_id
6752 ,x_step_status => l_step_status
6753 ,x_return_status => l_return_status);
6754
6755 IF g_debug <= gme_debug.g_log_statement THEN
6756 gme_debug.put_line ( g_pkg_name
6757 || '.'
6758 || l_api_name
6759 || ' validate_param returns '
6760 || l_return_status);
6761 END IF;
6762
6763 IF l_return_status <> fnd_api.g_ret_sts_success THEN
6764 RAISE fnd_api.g_exc_error;
6765 END IF;
6766
6767 IF g_debug <= gme_debug.g_log_statement THEN
6768 gme_debug.put_line (g_pkg_name || '.' || l_api_name || ' batch_id
6769 => ' || l_batchstep_resource_rec.batch_id);
6770 gme_debug.put_line (g_pkg_name || '.' || l_api_name || ' batchstep_id => ' ||
6771 l_batchstep_resource_rec.batchstep_id);
6772 gme_debug.put_line ( g_pkg_name || '.' || l_api_name || ' batchstep_activity_id => '
6773 || l_batchstep_resource_rec.batchstep_activity_id);
6774 gme_debug.put_line ( g_pkg_name || '.' || l_api_name || ' rsrc_id => ' || l_rsrc_id);
6775 gme_debug.put_line ( g_pkg_name || '.' || l_api_name || ' step_status => '
6776 || l_step_status);
6777 END IF;
6778 END IF;
6779
6780 IF g_debug <= gme_debug.g_log_statement THEN
6781 gme_debug.put_line ( g_pkg_name
6782 || '.'
6783 || l_api_name
6784 || ' proceed with resource validation for '
6785 || l_batchstep_resource_rec.resources);
6786 END IF;
6787
6788 OPEN cur_get_rsrc_dtl (l_batchstep_resource_rec.resources
6789 ,l_batchstep_resource_rec.organization_id);
6790
6791 FETCH cur_get_rsrc_dtl
6792 INTO l_min_capacity, l_max_capacity, l_capacity_constraint
6793 ,l_capacity_um, l_usage_uom, l_delete_mark, l_capacity_tolerance;
6794
6795 IF (cur_get_rsrc_dtl%NOTFOUND) THEN
6796 OPEN cur_get_rsrc_hdr (l_batchstep_resource_rec.resources);
6797
6798 FETCH cur_get_rsrc_hdr
6799 INTO l_min_capacity, l_max_capacity, l_capacity_constraint
6800 ,l_capacity_um, l_usage_uom, l_delete_mark
6801 ,l_capacity_tolerance;
6802
6803 IF g_debug <= gme_debug.g_log_procedure THEN
6804 gme_debug.put_line ('after rsrc hdr fetch ');
6805 END IF;
6806
6807 IF cur_get_rsrc_hdr%NOTFOUND OR l_delete_mark = 1 THEN
6808 CLOSE cur_get_rsrc_dtl;
6809
6810 CLOSE cur_get_rsrc_hdr;
6811
6812 fnd_message.set_name ('GMD', 'FM_BAD_RESOURCE');
6813 fnd_msg_pub.ADD;
6814 RAISE fnd_api.g_exc_error;
6815 END IF;
6816 CLOSE cur_get_rsrc_hdr;
6817 END IF;
6818
6819 CLOSE cur_get_rsrc_dtl;
6820
6821 IF g_debug <= gme_debug.g_log_statement THEN
6822 gme_debug.put_line ( g_pkg_name
6823 || '.'
6824 || l_api_name
6825 || ' retrieve step status for batchstep_id'
6826 || l_batchstep_resource_rec.batchstep_id);
6827 END IF;
6828
6829 OPEN cur_get_step_status (l_batchstep_resource_rec.batch_id
6830 ,l_batchstep_resource_rec.batchstep_id);
6831
6832 FETCH cur_get_step_status
6833 INTO l_step_status;
6834
6835 IF cur_get_step_status%NOTFOUND THEN
6836 CLOSE cur_get_step_status;
6837
6838 gme_common_pvt.log_message ('GME_NO_DATA_FOUND'
6839 ,'TABLE_NAME'
6840 ,'GME_BATCH_STEPS');
6841 RAISE fnd_api.g_exc_error;
6842 END IF;
6843
6844 IF g_debug <= gme_debug.g_log_statement THEN
6845 gme_debug.put_line ( g_pkg_name || '.' || l_api_name || ' step_status
6846 is ' || l_step_status);
6847 END IF;
6848
6849 CLOSE cur_get_step_status;
6850
6851 IF g_debug <= gme_debug.g_log_statement THEN
6852 gme_debug.put_line ( g_pkg_name
6853 || '.'
6854 || l_api_name
6855 || ' Invoke validate_rsrc_param');
6856 END IF;
6857
6858 --FPBug#4395561 Start setting global flex validate variable
6859 IF p_validate_flexfields = FND_API.G_TRUE THEN
6860 gme_common_pvt.g_flex_validate_prof := 1;
6861 ELSE
6862 gme_common_pvt.g_flex_validate_prof := 0;
6863 END IF;
6864 --FPBug#4395561 End
6865
6866 gme_batchstep_rsrc_pvt.validate_rsrc_param
6867 (p_batchstep_resource_rec => l_batchstep_resource_rec
6868 ,p_activity_id => l_batchstep_resource_rec.batchstep_activity_id
6869 ,p_ignore_qty_below_cap => p_ignore_qty_below_cap
6870 ,p_validate_flexfield => p_validate_flexfields
6871 ,p_action => 'INSERT'
6872 ,x_batchstep_resource_rec => l_batchstep_resource_rec_out
6873 ,x_step_status => l_step_status
6874 ,x_return_status => l_return_status);
6875
6876 IF g_debug <= gme_debug.g_log_statement THEN
6877 gme_debug.put_line ( g_pkg_name
6878 || '.'
6879 || l_api_name
6880 || ' validate_rsrc_param returns '
6881 || l_return_status);
6882 END IF;
6883
6884 --FPBug#4395561 resetting globla flex field variable
6885 gme_common_pvt.g_flex_validate_prof := 0;
6886
6887 IF l_return_status <> fnd_api.g_ret_sts_success THEN
6888 RAISE fnd_api.g_exc_error;
6889 END IF;
6890
6891 -- Set capacity data
6892 IF g_debug <= gme_debug.g_log_statement THEN
6893 gme_debug.put_line ( g_pkg_name || '.' || l_api_name ||
6894 ' set capacity data as follows ');
6895 gme_debug.put_line ( g_pkg_name || '.' || l_api_name ||
6896 ' usage_um => ' || l_usage_uom);
6897 gme_debug.put_line ( g_pkg_name || '.' || l_api_name ||
6898 ' capacity_um => ' || l_capacity_um);
6899 gme_debug.put_line ( g_pkg_name || '.' || l_api_name ||
6900 ' min_capacity => ' || l_min_capacity);
6901 gme_debug.put_line ( g_pkg_name || '.' || l_api_name || '
6902 max_capacity => ' || l_max_capacity);
6903 gme_debug.put_line ( g_pkg_name || '.' || l_api_name ||
6904 ' capacity tolerance => '|| l_capacity_tolerance);
6905 END IF;
6906
6907 l_batchstep_resource_rec := l_batchstep_resource_rec_out;
6908 l_batchstep_resource_rec.usage_um := l_usage_uom;
6909 l_batchstep_resource_rec.capacity_um := l_capacity_um;
6910 l_batchstep_resource_rec.min_capacity := l_min_capacity;
6911 l_batchstep_resource_rec.max_capacity := l_max_capacity;
6912 l_batchstep_resource_rec.capacity_tolerance := l_capacity_tolerance;
6913
6914 IF l_batchstep_resource_rec.offset_interval IS NULL THEN
6915 l_batchstep_resource_rec.offset_interval := 0;
6916 END IF;
6917
6918 IF g_debug <= gme_debug.g_log_statement THEN
6919 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
6920 || ' invoke private layer insert_batchstep_rsrc');
6921 END IF;
6922
6923 gme_batchstep_rsrc_pvt.insert_batchstep_rsrc
6924 (p_batchstep_resource_rec => l_batchstep_resource_rec
6925 ,x_batchstep_resource_rec => x_batchstep_resource_rec
6926 ,x_return_status => x_return_status);
6927
6928 IF g_debug <= gme_debug.g_log_statement THEN
6929 gme_debug.put_line ( g_pkg_name || '.' || l_api_name || '
6930 insert_batchstep_rsrc returns '|| x_return_status);
6931 END IF;
6932
6933 IF x_return_status = fnd_api.g_ret_sts_success THEN
6934 IF g_debug <= gme_debug.g_log_statement THEN
6935 gme_debug.put_line ( g_pkg_name
6936 || '.'
6937 || l_api_name
6938 || ' invoke save_batch');
6939 END IF;
6940
6941 gme_api_pub.save_batch (p_header_id => NULL
6942 ,p_table => NULL
6943 ,p_commit => p_commit
6944 ,x_return_status => x_return_status);
6945
6946 IF g_debug <= gme_debug.g_log_statement THEN
6947 gme_debug.put_line ( g_pkg_name || '.' || l_api_name || '
6948 save_batch returns '|| x_return_status);
6949 END IF;
6950
6951 IF x_return_status <> fnd_api.g_ret_sts_success THEN
6952 RAISE fnd_api.g_exc_error;
6953 END IF;
6954 ELSE
6955 RAISE insert_rsrc_failed;
6956 END IF;
6957
6958 IF g_debug <= gme_debug.g_log_procedure THEN
6959 gme_debug.put_line ( ' Completed ' || g_pkg_name || '.' || l_api_name
6960 || ' at ' || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
6961 END IF;
6962
6963 gme_common_pvt.log_message ('PM_SAVED_CHANGES');
6964 gme_common_pvt.count_and_get(x_count => x_message_count
6965 ,p_encoded => fnd_api.g_false
6966 ,x_data => x_message_list);
6967 EXCEPTION
6968 WHEN insert_rsrc_failed THEN
6969 ROLLBACK TO SAVEPOINT insert_batchstep_rsrc;
6970 gme_common_pvt.count_and_get(x_count => x_message_count
6971 ,p_encoded => fnd_api.g_false
6972 ,x_data => x_message_list);
6973 WHEN fnd_api.g_exc_error THEN
6974 x_return_status := fnd_api.g_ret_sts_error;
6975 ROLLBACK TO SAVEPOINT insert_batchstep_rsrc;
6976 gme_common_pvt.count_and_get(x_count => x_message_count
6977 ,p_encoded => fnd_api.g_false
6978 ,x_data => x_message_list);
6979 WHEN OTHERS THEN
6980 ROLLBACK TO SAVEPOINT insert_batchstep_rsrc;
6981 gme_when_others ( p_api_name => l_api_name
6982 ,x_message_count => x_message_count
6983 ,x_message_list => x_message_list
6984 ,x_return_status => x_return_status );
6985 END insert_batchstep_resource;
6986
6987 /*************************************************************************/
6988 PROCEDURE update_batchstep_resource (
6989 p_api_version IN NUMBER
6990 ,p_validation_level IN NUMBER := gme_common_pvt.g_max_errors
6991 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
6992 ,p_commit IN VARCHAR2 := fnd_api.g_false
6993 ,p_batchstep_resource_rec IN gme_batch_step_resources%ROWTYPE
6994 ,p_org_code IN VARCHAR2 := NULL
6995 ,p_batch_no IN VARCHAR2 := NULL
6996 ,p_batchstep_no IN NUMBER := NULL
6997 ,p_activity IN VARCHAR2 := NULL
6998 ,p_ignore_qty_below_cap IN VARCHAR2 := fnd_api.g_false
6999 ,p_validate_flexfields IN VARCHAR2 := fnd_api.g_false
7000 ,x_batchstep_resource_rec OUT NOCOPY gme_batch_step_resources%ROWTYPE
7001 ,x_message_count OUT NOCOPY NUMBER
7002 ,x_message_list OUT NOCOPY VARCHAR2
7003 ,x_return_status OUT NOCOPY VARCHAR2)
7004 IS
7005 l_api_name CONSTANT VARCHAR2 (30)
7006 := 'UPDATE_BATCHSTEP_RESOURCE';
7007 l_batch_header gme_batch_header%ROWTYPE;
7008 l_batchstep_resource_rec gme_batch_step_resources%ROWTYPE;
7009 l_batchstep_resource_rec_out gme_batch_step_resources%ROWTYPE;
7010 l_cons_batchstep_resource_rec gme_batch_step_resources%ROWTYPE;
7011 l_return_status VARCHAR2 (2);
7012 l_step_status NUMBER;
7013
7014 CURSOR cur_get_batchstep_status (
7015 v_batchstep_id NUMBER
7016 ,v_batch_id NUMBER)
7017 IS
7018 SELECT step_status
7019 FROM gme_batch_steps
7020 WHERE batchstep_id = v_batchstep_id AND batch_id = v_batch_id;
7021
7022 update_rsrc_failed EXCEPTION;
7023 BEGIN
7024 /* Set the savepoint */
7025 SAVEPOINT update_batchstep_rsrc;
7026
7027 IF (g_debug <> -1) THEN
7028 gme_debug.log_initialize ('UpdateBatchstepResource');
7029 END IF;
7030
7031 IF g_debug <= gme_debug.g_log_procedure THEN
7032 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
7033 || l_api_name);
7034 END IF;
7035
7036 /* Set the return status to success initially */
7037 x_return_status := fnd_api.g_ret_sts_success;
7038
7039 /* Make sure we are call compatible */
7040 IF NOT fnd_api.compatible_api_call (2.0
7041 ,p_api_version
7042 ,'update_batchstep_resource'
7043 ,g_pkg_name) THEN
7044 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
7045 RAISE fnd_api.g_exc_error;
7046 END IF;
7047
7048 gme_common_pvt.set_timestamp;
7049
7050 /* Initialize message list and count if needed */
7051 IF p_init_msg_list = fnd_api.g_true THEN
7052 fnd_msg_pub.initialize;
7053 gme_common_pvt.g_error_count := 0;
7054 END IF;
7055
7056 l_batchstep_resource_rec := p_batchstep_resource_rec;
7057 gme_common_pvt.g_check_primary_rsrc := 1;
7058
7059 /* Retrieve the row to be updated */
7060 IF g_debug <= gme_debug.g_log_statement THEN
7061 gme_debug.put_line ( g_pkg_name
7062 || '.'
7063 || l_api_name
7064 || 'Invoke get_batchstep_rsrc');
7065 END IF;
7066
7067 IF NOT gme_common_pvt.get_batchstep_rsrc
7068 (p_batchstep_rsrc_rec => l_batchstep_resource_rec
7069 ,p_org_code => p_org_code
7070 ,p_batch_no => p_batch_no
7071 ,p_batchstep_no => p_batchstep_no
7072 ,p_activity => p_activity
7073 ,p_resource => l_batchstep_resource_rec.resources
7074 ,x_batchstep_rsrc_rec => l_batchstep_resource_rec_out) THEN
7075 IF g_debug <= gme_debug.g_log_statement THEN
7076 gme_debug.put_line ( g_pkg_name
7077 || '.'
7078 || l_api_name
7079 || ' get_batchstep_rsrc failed to retrieve row');
7080 END IF;
7081
7082 RAISE fnd_api.g_exc_error;
7083 END IF;
7084
7085 /* Make sure the essential keys are populated from the retrieved row */
7086 /* Don't overwrite any other input data which carries the updates */
7087 l_batchstep_resource_rec.organization_id :=
7088 l_batchstep_resource_rec_out.organization_id;
7089 l_batchstep_resource_rec.batchstep_resource_id :=
7090 l_batchstep_resource_rec_out.batchstep_resource_id;
7091 l_batchstep_resource_rec.batch_id :=
7092 l_batchstep_resource_rec_out.batch_id;
7093 l_batchstep_resource_rec.batchstep_id :=
7094 l_batchstep_resource_rec_out.batchstep_id;
7095 l_batchstep_resource_rec.batchstep_activity_id :=
7096 l_batchstep_resource_rec_out.batchstep_activity_id;
7097 l_batchstep_resource_rec.resources :=
7098 l_batchstep_resource_rec_out.resources;
7099
7100 IF g_debug <= gme_debug.g_log_statement THEN
7101 gme_debug.put_line ( g_pkg_name
7102 || '.'
7103 || l_api_name
7104 || ' batchstep_resource_id is '
7105 || l_batchstep_resource_rec.batchstep_resource_id);
7106 END IF;
7107
7108 /* Setup the common constants used accross the apis */
7109 /* This will raise an error if both organization_id and org_code are null values */
7110 IF g_debug <= gme_debug.g_log_statement THEN
7111 gme_debug.put_line ( g_pkg_name
7112 || '.'
7113 || l_api_name
7114 || ' Invoking setup for org_id '
7115 || p_batchstep_resource_rec.organization_id
7116 || ' org_code '
7117 || p_org_code);
7118 END IF;
7119
7120 gme_common_pvt.g_setup_done :=
7121 gme_common_pvt.setup
7122 (p_org_id => l_batchstep_resource_rec.organization_id
7123 ,p_org_code => p_org_code);
7124
7125 IF NOT gme_common_pvt.g_setup_done THEN
7126 IF g_debug <= gme_debug.g_log_statement THEN
7127 gme_debug.put_line ( g_pkg_name
7128 || '.'
7129 || l_api_name
7130 || ' setup failure ');
7131 END IF;
7132
7133 RAISE fnd_api.g_exc_error;
7134 END IF;
7135
7136 /* Establish the step_status of the batchstep */
7137 IF g_debug <= gme_debug.g_log_statement THEN
7138 gme_debug.put_line ( g_pkg_name
7139 || '.'
7140 || l_api_name
7141 || ' retrieve step status for batchstep_id '
7142 || l_batchstep_resource_rec.batchstep_id);
7143 END IF;
7144
7145 OPEN cur_get_batchstep_status (l_batchstep_resource_rec.batchstep_id
7146 ,l_batchstep_resource_rec.batch_id);
7147
7148 FETCH cur_get_batchstep_status
7149 INTO l_step_status;
7150
7151 IF cur_get_batchstep_status%NOTFOUND THEN
7152 CLOSE cur_get_batchstep_status;
7153
7154 gme_common_pvt.log_message ('GME_BATCH_STEP_NOT_FOUND'
7155 ,'STEP_ID'
7156 ,l_batchstep_resource_rec.batchstep_id);
7157 RAISE fnd_api.g_exc_error;
7158 END IF;
7159
7160 IF g_debug <= gme_debug.g_log_statement THEN
7161 gme_debug.put_line ( g_pkg_name
7162 || '.'
7163 || l_api_name
7164 || ' step_status is '
7165 || l_step_status);
7166 END IF;
7167
7168 CLOSE cur_get_batchstep_status;
7169
7170 --FPBug#4395561 Start setting global flex validate variable
7171 IF p_validate_flexfields = FND_API.G_TRUE THEN
7172 gme_common_pvt.g_flex_validate_prof := 1;
7173 ELSE
7174 gme_common_pvt.g_flex_validate_prof := 0;
7175 END IF;
7176 --FPBug#4395561 End
7177
7178 gme_batchstep_rsrc_pvt.validate_rsrc_param
7179 (p_batchstep_resource_rec => l_batchstep_resource_rec
7180 ,p_activity_id => l_batchstep_resource_rec.batchstep_activity_id
7181 ,p_ignore_qty_below_cap => p_ignore_qty_below_cap
7182 ,p_validate_flexfield => p_validate_flexfields
7183 ,p_action => 'UPDATE'
7184 ,x_batchstep_resource_rec => l_batchstep_resource_rec_out
7185 ,x_step_status => l_step_status
7186 ,x_return_status => l_return_status);
7187
7188 IF g_debug <= gme_debug.g_log_statement THEN
7189 gme_debug.put_line ('val rsrc param returns ' || l_return_status);
7190 END IF;
7191
7192 --FPBug#4395561 resetting global flex field validate
7193 gme_common_pvt.g_flex_validate_prof := 0;
7194
7195 IF l_return_status <> fnd_api.g_ret_sts_success THEN
7196 RAISE fnd_api.g_exc_error;
7197 END IF;
7198
7199 l_batchstep_resource_rec := l_batchstep_resource_rec_out;
7200
7201 IF g_debug <= gme_debug.g_log_statement THEN
7202 gme_debug.put_line
7203 ( g_pkg_name
7204 || '.'
7205 || l_api_name
7206 || ' Invoke gme_batchstep_rsrc_pvt.update_batchstep_rsrc');
7207 END IF;
7208
7209 gme_batchstep_rsrc_pvt.update_batchstep_rsrc
7210 (p_batchstep_resource_rec => l_batchstep_resource_rec
7211 ,x_batchstep_resource_rec => x_batchstep_resource_rec
7212 ,x_return_status => x_return_status);
7213
7214 IF g_debug <= gme_debug.g_log_statement THEN
7215 gme_debug.put_line ( g_pkg_name
7216 || '.'
7217 || l_api_name
7218 || ' update_batchstep_rsrc returns '
7219 || x_return_status);
7220 END IF;
7221
7222 IF x_return_status = fnd_api.g_ret_sts_success THEN
7223 IF g_debug <= gme_debug.g_log_statement THEN
7224 gme_debug.put_line ( g_pkg_name
7225 || '.'
7226 || l_api_name
7227 || ' invoke save_batch with commit ='
7228 || p_commit);
7229 END IF;
7230
7231 gme_api_pub.save_batch
7232 (p_header_id => gme_common_pvt.g_transaction_header_id
7233 ,p_table => null
7234 ,p_commit => p_commit
7235 ,x_return_status => x_return_status);
7236
7237 IF g_debug <= gme_debug.g_log_statement THEN
7238 gme_debug.put_line ( g_pkg_name
7239 || '.'
7240 || l_api_name
7241 || ' save_batch return_status is '
7242 || x_return_status);
7243 END IF;
7244
7245 IF x_return_status <> fnd_api.g_ret_sts_success THEN
7246 RAISE fnd_api.g_exc_error;
7247 END IF;
7248 ELSE
7249 RAISE update_rsrc_failed;
7250 END IF;
7251
7252 gme_common_pvt.log_message ('PM_SAVED_CHANGES');
7253 gme_common_pvt.count_and_get(x_count => x_message_count
7254 ,p_encoded => fnd_api.g_false
7255 ,x_data => x_message_list);
7256
7257 IF g_debug <= gme_debug.g_log_procedure THEN
7258 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
7259 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
7260 END IF;
7261 EXCEPTION
7262 WHEN update_rsrc_failed THEN
7263 ROLLBACK TO SAVEPOINT update_batchstep_rsrc;
7264 gme_common_pvt.count_and_get(x_count => x_message_count
7265 ,p_encoded => fnd_api.g_false
7266 ,x_data => x_message_list);
7267 WHEN fnd_api.g_exc_error THEN
7268 x_return_status := fnd_api.g_ret_sts_error;
7269 ROLLBACK TO SAVEPOINT update_batchstep_rsrc;
7270 gme_common_pvt.count_and_get(x_count => x_message_count
7271 ,p_encoded => fnd_api.g_false
7272 ,x_data => x_message_list);
7273 WHEN OTHERS THEN
7274 ROLLBACK TO SAVEPOINT update_batchstep_rsrc;
7275 gme_when_others ( p_api_name => l_api_name
7276 ,x_message_count => x_message_count
7277 ,x_message_list => x_message_list
7278 ,x_return_status => x_return_status );
7279 END update_batchstep_resource;
7280
7281 /*************************************************************************/
7282 PROCEDURE delete_batchstep_resource (
7283 p_api_version IN NUMBER := 2.0
7284 ,p_validation_level IN NUMBER
7285 := gme_common_pvt.g_max_errors
7286 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
7287 ,p_commit IN VARCHAR2 := fnd_api.g_false
7288 ,p_batchstep_resource_id IN NUMBER := NULL
7289 ,p_org_code IN VARCHAR2 := NULL
7290 ,p_batch_no IN VARCHAR2 := NULL
7291 ,p_batchstep_no IN NUMBER := NULL
7292 ,p_activity IN VARCHAR2 := NULL
7293 ,p_resource IN VARCHAR2 := NULL
7294 ,x_message_count OUT NOCOPY NUMBER
7295 ,x_message_list OUT NOCOPY VARCHAR2
7296 ,x_return_status OUT NOCOPY VARCHAR2)
7297 IS
7298 l_api_name CONSTANT VARCHAR2 (30) := 'DELETE_BATCHSTEP_RESOURCE';
7299 l_step_status NUMBER;
7300 l_batch_status NUMBER;
7301 l_organization_id NUMBER;
7302 l_rsrc_id NUMBER;
7303 l_activity_id NUMBER;
7304 l_dummy NUMBER;
7305 l_batch_id NUMBER;
7306 l_batchstep_id NUMBER;
7307 l_return_status VARCHAR2 (2);
7308 l_batchstep_resource_rec gme_batch_step_resources%ROWTYPE;
7309
7310 CURSOR cur_get_step_dtl (v_batchstep_rsrc_id NUMBER)
7311 IS
7312 SELECT c.organization_id, a.step_status, a.batch_id, a.batchstep_id
7313 ,b.batchstep_activity_id, c.batch_status
7314 FROM gme_batch_steps a
7315 ,gme_batch_step_resources b
7316 ,gme_batch_header c
7317 WHERE a.batch_id = b.batch_id
7318 AND a.batchstep_id = b.batchstep_id
7319 AND b.batchstep_resource_id = v_batchstep_rsrc_id
7320 AND a.batch_id = c.batch_id;
7321
7322 CURSOR cur_validate_batch_type (v_rsrc_id NUMBER)
7323 IS
7324 SELECT 1
7325 FROM gme_batch_header a, gme_batch_step_resources b
7326 WHERE a.batch_id = b.batch_id
7327 AND b.batchstep_resource_id = v_rsrc_id
7328 AND a.batch_type = 10;
7329
7330 delete_rsrc_failed EXCEPTION;
7331 BEGIN
7332 /* Set the savepoint */
7333 SAVEPOINT delete_batchstep_rsrc;
7334
7335 IF g_debug <> -1 THEN
7336 gme_debug.log_initialize ('DeleteBatchstepResource');
7337 END IF;
7338
7339 IF g_debug <= gme_debug.g_log_procedure THEN
7340 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
7341 || l_api_name);
7342 END IF;
7343
7344 /* Set the return status to success initially */
7345 x_return_status := fnd_api.g_ret_sts_success;
7346
7347 /* Make sure we are call compatible */
7348 IF NOT fnd_api.compatible_api_call (2.0
7349 ,p_api_version
7350 ,'delete_batchstep_resource'
7351 ,g_pkg_name) THEN
7352 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
7353 RAISE fnd_api.g_exc_error;
7354 END IF;
7355
7356 gme_common_pvt.set_timestamp;
7357
7358 /* Initialize message list and count if needed */
7359 IF p_init_msg_list = fnd_api.g_true THEN
7360 fnd_msg_pub.initialize;
7361 gme_common_pvt.g_error_count := 0;
7362 END IF;
7363
7364 gme_common_pvt.g_check_primary_rsrc := 1;
7365
7366 IF (g_debug <= gme_debug.g_log_statement) THEN
7367 gme_debug.put_line ( g_pkg_name
7368 || '.'
7369 || l_api_name
7370 || ':'
7371 || 'input data - p_batchstep_resource_id is : '
7372 || p_batchstep_resource_id
7373 || 'input data - p_resource is : '
7374 || p_resource);
7375 END IF;
7376
7377 /* Report error if insufficient data to pinpoint batchstep resource */
7378 IF (p_batchstep_resource_id IS NULL AND p_resource IS NULL) THEN
7379 gme_common_pvt.log_message ('GME_FIELD_VALUE_REQUIRED'
7380 ,'FIELD_NAME'
7381 ,'RESOURCES');
7382 RAISE fnd_api.g_exc_error;
7383 END IF;
7384
7385 /* validate key values where no internal ID provided */
7386 IF p_batchstep_resource_id IS NULL THEN
7387 IF g_debug <= gme_debug.g_log_statement THEN
7388 gme_debug.put_line ( g_pkg_name
7389 || '.'
7390 || l_api_name
7391 || ' Invoke validate param ');
7392 END IF;
7393
7394 gme_batchstep_rsrc_pvt.validate_param
7395 (p_org_code => p_org_code
7396 ,p_batch_no => p_batch_no
7397 ,p_batchstep_no => p_batchstep_no
7398 ,p_activity => p_activity
7399 ,p_resource => p_resource
7400 ,x_organization_id => l_organization_id
7401 ,x_batch_id => l_batch_id
7402 ,x_batchstep_id => l_batchstep_id
7403 ,x_activity_id => l_activity_id
7404 ,x_rsrc_id => l_rsrc_id
7405 ,x_step_status => l_step_status
7406 ,x_return_status => l_return_status);
7407
7408 IF g_debug <= gme_debug.g_log_statement THEN
7409 gme_debug.put_line ( g_pkg_name
7410 || '.'
7411 || l_api_name
7412 || ':'
7413 || 'validate_param returns status : '
7414 || l_return_status
7415 || 'validate_param returns rsrc_id : '
7416 || l_rsrc_id );
7417 END IF;
7418
7419 IF l_return_status <> fnd_api.g_ret_sts_success THEN
7420 RAISE fnd_api.g_exc_error;
7421 END IF;
7422 ELSE
7423 IF g_debug <= gme_debug.g_log_statement THEN
7424 gme_debug.put_line ( g_pkg_name
7425 || '.'
7426 || l_api_name
7427 || 'Working with Input batchstep resource id : '
7428 || p_batchstep_resource_id);
7429 END IF;
7430
7431 l_rsrc_id := p_batchstep_resource_id;
7432 END IF;
7433
7434 IF g_debug <= gme_debug.g_log_statement THEN
7435 gme_debug.put_line ( g_pkg_name
7436 || '.'
7437 || l_api_name
7438 || ' retrieve batch step detail using id => '
7439 || l_rsrc_id);
7440 END IF;
7441
7442 OPEN cur_get_step_dtl (l_rsrc_id);
7443
7444 FETCH cur_get_step_dtl
7445 INTO l_organization_id, l_step_status, l_batch_id, l_batchstep_id
7446 ,l_activity_id, l_batch_status;
7447
7448 IF cur_get_step_dtl%NOTFOUND THEN
7449 CLOSE cur_get_step_dtl;
7450
7451 gme_common_pvt.log_message ('GME_INVALID_RSRC_ID');
7452 RAISE fnd_api.g_exc_error;
7453 END IF;
7454
7455 CLOSE cur_get_step_dtl;
7456
7457 /* Setup the common constants used across the apis */
7458 /* This will raise an error if both organization_id and org_code are null values */
7459 IF g_debug <= gme_debug.g_log_statement THEN
7460 gme_debug.put_line ( g_pkg_name
7461 || '.'
7462 || l_api_name
7463 || ' invoke setup using org_id => '
7464 || l_organization_id
7465 || ' and org_code => '
7466 || p_org_code);
7467 END IF;
7468
7469 gme_common_pvt.g_setup_done :=
7470 gme_common_pvt.setup (p_org_id => l_organization_id
7471 ,p_org_code => p_org_code);
7472
7473 IF NOT gme_common_pvt.g_setup_done THEN
7474 RAISE fnd_api.g_exc_error;
7475 END IF;
7476
7477 /* Validations prior to deletion */
7478 IF g_debug <= gme_debug.g_log_statement THEN
7479 gme_debug.put_line ( g_pkg_name
7480 || '.'
7481 || l_api_name
7482 || ' start of validations');
7483 END IF;
7484
7485 /* make sure resource id does not belong to an FPO */
7486 OPEN cur_validate_batch_type (l_rsrc_id);
7487
7488 FETCH cur_validate_batch_type
7489 INTO l_dummy;
7490
7491 IF cur_validate_batch_type%FOUND THEN
7492 CLOSE cur_validate_batch_type;
7493 gme_common_pvt.log_message ('GME_FPO_RSRC_NO_EDIT');
7494 RAISE fnd_api.g_exc_error;
7495 END IF;
7496
7497 CLOSE cur_validate_batch_type;
7498
7499 IF g_debug <= gme_debug.g_log_statement THEN
7500 gme_debug.put_line ( g_pkg_name
7501 || '.'
7502 || l_api_name
7503 || ' validate batch_status of '
7504 || l_batch_status);
7505 gme_debug.put_line ( g_pkg_name
7506 || '.'
7507 || l_api_name
7508 || ' validate step_status of '
7509 || l_step_status);
7510 END IF;
7511
7512 IF l_batch_status <> gme_common_pvt.g_batch_pending THEN
7513 gme_common_pvt.log_message ('PM_WRONG_STATUS');
7514 RAISE fnd_api.g_exc_error;
7515 ELSIF l_step_status <> gme_common_pvt.g_step_pending THEN
7516 gme_common_pvt.log_message ('PC_STEP_STATUS_ERR');
7517 RAISE fnd_api.g_exc_error;
7518 END IF;
7519
7520 /* Ensure that the batchstep_resource_rec is sufficiently populated for deletion to proceed */
7521 l_batchstep_resource_rec.organization_id := l_organization_id;
7522 l_batchstep_resource_rec.batch_id := l_batch_id;
7523 l_batchstep_resource_rec.batchstep_id := l_batchstep_id;
7524 l_batchstep_resource_rec.batchstep_activity_id := l_activity_id;
7525 l_batchstep_resource_rec.batchstep_resource_id := l_rsrc_id;
7526
7527 IF g_debug <= gme_debug.g_log_statement THEN
7528 gme_debug.put_line ( g_pkg_name || '.' || l_api_name ||
7529 ' invoke gme_batchstep_rsrc_pvt.delete_batchstep_rsrc ');
7530 gme_debug.put_line ( g_pkg_name || '.' || l_api_name ||
7531 'organization_id => ' || l_organization_id);
7532 gme_debug.put_line ( g_pkg_name || '.' || l_api_name ||
7533 ' batch_id => ' || l_batch_id);
7534 gme_debug.put_line ( g_pkg_name || '.' || l_api_name ||
7535 'batchstep_id => ' || l_batchstep_id);
7536 gme_debug.put_line ( g_pkg_name || '.' || l_api_name ||
7537 ' activity_id => ' || l_activity_id);
7538 gme_debug.put_line ( g_pkg_name || '.' || l_api_name ||
7539 'batchstep_resource_id => ' || l_rsrc_id);
7540 END IF;
7541
7542 gme_batchstep_rsrc_pvt.delete_batchstep_rsrc
7543 (p_batchstep_resource_rec => l_batchstep_resource_rec
7544 ,x_return_status => x_return_status);
7545
7546 IF g_debug <= gme_debug.g_log_statement THEN
7547 gme_debug.put_line ( g_pkg_name || '.' || l_api_name || ' return
7548 status from delete is ' || x_return_status);
7549 END IF;
7550
7551 IF x_return_status = fnd_api.g_ret_sts_success THEN
7552 IF g_debug <= gme_debug.g_log_statement THEN
7553 gme_debug.put_line ( g_pkg_name || '.' || l_api_name || ' invoke
7554 save_batch tith commit set ' || p_commit);
7555 END IF;
7556
7557 gme_api_pub.save_batch
7558 (p_header_id => gme_common_pvt.g_transaction_header_id
7559 ,p_table => null
7560 ,p_commit => p_commit
7561 ,x_return_status => x_return_status);
7562
7563 IF g_debug <= gme_debug.g_log_statement THEN
7564 gme_debug.put_line ( g_pkg_name || '.' || l_api_name || ' return
7565 status from save_batch is '
7566 || x_return_status);
7567 END IF;
7568
7569 IF x_return_status <> fnd_api.g_ret_sts_success THEN
7570 RAISE fnd_api.g_exc_error;
7571 END IF;
7572 ELSE
7573 RAISE delete_rsrc_failed;
7574 END IF;
7575
7576 IF g_debug <= gme_debug.g_log_procedure THEN
7577 gme_debug.put_line ( ' Completed ' || l_api_name || ' at '
7578 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
7579 END IF;
7580 gme_common_pvt.log_message ('PM_SAVED_CHANGES');
7581 gme_common_pvt.count_and_get(x_count => x_message_count
7582 ,p_encoded => fnd_api.g_false
7583 ,x_data => x_message_list);
7584 EXCEPTION
7585 WHEN delete_rsrc_failed THEN
7586 ROLLBACK TO SAVEPOINT delete_batchstep_rsrc;
7587 gme_common_pvt.count_and_get(x_count => x_message_count
7588 ,p_encoded => fnd_api.g_false
7589 ,x_data => x_message_list);
7590 WHEN fnd_api.g_exc_error THEN
7591 x_return_status := fnd_api.g_ret_sts_error;
7592 ROLLBACK TO SAVEPOINT delete_batchstep_rsrc;
7593 gme_common_pvt.count_and_get(x_count => x_message_count
7594 ,p_encoded => fnd_api.g_false
7595 ,x_data => x_message_list);
7596 WHEN OTHERS THEN
7597 ROLLBACK TO SAVEPOINT delete_batchstep_rsrc;
7598 gme_when_others ( p_api_name => l_api_name
7599 ,x_message_count => x_message_count
7600 ,x_message_list => x_message_list
7601 ,x_return_status => x_return_status );
7602 END delete_batchstep_resource;
7603
7604 /*************************************************************************/
7605 PROCEDURE auto_detail_line (
7606 p_api_version IN NUMBER := 2.0
7607 ,p_validation_level IN NUMBER
7608 := gme_common_pvt.g_max_errors
7609 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
7610 ,p_commit IN VARCHAR2 := fnd_api.g_false
7611 ,x_message_count OUT NOCOPY NUMBER
7612 ,x_message_list OUT NOCOPY VARCHAR2
7613 ,x_return_status OUT NOCOPY VARCHAR2
7614 ,p_material_detail_id IN NUMBER
7615 ,p_org_code IN VARCHAR2
7616 ,p_batch_no IN VARCHAR2
7617 ,p_line_no IN NUMBER)
7618 IS
7619 l_api_name CONSTANT VARCHAR2 (30) := 'AUTO_DETAIL_LINE';
7620 l_material_details_rec gme_material_details%ROWTYPE;
7621 l_material_details_rec_out gme_material_details%ROWTYPE;
7622 l_reservation_rec mtl_reservations%ROWTYPE;
7623 l_batch_header_rec gme_batch_header%ROWTYPE;
7624 l_valid_status VARCHAR2(1);
7625
7626 CURSOR cur_fetch_reservation (v_reservation_id NUMBER)
7627 IS
7628 SELECT *
7629 FROM mtl_reservations
7630 WHERE reservation_id = v_reservation_id;
7631
7632 auto_detail_error EXCEPTION;
7633 BEGIN
7634 IF (g_debug <> -1) THEN
7635 gme_debug.log_initialize ('AutoDetailLine');
7636 END IF;
7637
7638 IF g_debug <= gme_debug.g_log_procedure THEN
7639 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
7640 || l_api_name);
7641 END IF;
7642
7643 /* Set the savepoint */
7644 SAVEPOINT auto_detail_line;
7645 /* Set the return status to success initially */
7646 x_return_status := fnd_api.g_ret_sts_success;
7647
7648 IF p_init_msg_list = fnd_api.g_true THEN
7649 fnd_msg_pub.initialize;
7650 END IF;
7651
7652 IF NOT fnd_api.compatible_api_call (2.0
7653 ,p_api_version
7654 ,'auto_detail_line'
7655 ,g_pkg_name) THEN
7656 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
7657 RAISE fnd_api.g_exc_error;
7658 END IF;
7659
7660 IF g_debug <= gme_debug.g_log_statement THEN
7661 gme_debug.put_line (
7662 g_pkg_name || '.' || l_api_name ||
7663 ' input material_detail_id is ' || p_material_detail_id ||
7664 ' input batch_no is ' || p_batch_no ||
7665 ' input org_code is ' || p_org_code ||
7666 ' input line_no is ' || p_line_no);
7667 END IF;
7668
7669 l_material_details_rec.material_detail_id := p_material_detail_id;
7670 l_material_details_rec.line_no := p_line_no;
7671 /* Ensure line_type is populated. Reservations only permitted for ingredient lines. */
7672 l_material_details_rec.line_type := -1;
7673 gme_common_pvt.Validate_material_detail
7674 (p_material_detail_rec => l_material_details_rec
7675 ,p_org_code => p_org_code
7676 ,p_batch_no => p_batch_no
7677 ,p_batch_type => 0
7678 ,x_batch_header_rec => l_batch_header_rec
7679 ,x_material_detail_rec => l_material_details_rec_out
7680 ,x_message_count => x_message_count
7681 ,x_message_list => x_message_list
7682 ,x_return_status => x_return_status );
7683 IF x_return_status <> fnd_api.g_ret_sts_success THEN
7684 IF (g_debug = gme_debug.g_log_statement) THEN
7685 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
7686 || ': batch mateiral validate error ');
7687 END IF;
7688 RAISE fnd_api.g_exc_error;
7689 ELSE
7690 l_material_details_rec := l_material_details_rec_out;
7691 END IF;
7692 gme_common_pvt.set_timestamp;
7693
7694 /* Validate the demand source - it must be a valid ingredient line */
7695 IF g_debug <= gme_debug.g_log_statement THEN
7696 gme_debug.put_line
7697 ( g_pkg_name
7698 || '.'
7699 || l_api_name
7700 || ' Invoke validate_supply_demand for demand line of '
7701 || l_material_details_rec.material_detail_id);
7702 END IF;
7703
7704 GME_API_GRP.validate_supply_demand(
7705 x_return_status => x_return_status,
7706 x_msg_count => x_message_count,
7707 x_msg_data => x_message_list,
7708 x_valid_status => l_valid_status,
7709 p_organization_id => l_material_details_rec.organization_id,
7710 p_item_id => l_material_details_rec.inventory_item_id,
7711 p_supply_demand_code => 2, -- signals DEMAND
7712 p_supply_demand_type_id => INV_RESERVATION_GLOBAL.g_source_type_wip,
7713 p_supply_demand_header_id => l_material_details_rec.batch_id,
7714 p_supply_demand_line_id => l_material_details_rec.material_detail_id,
7715 p_supply_demand_line_detail => FND_API.G_MISS_NUM,
7716 p_demand_ship_date => NULL,
7717 p_expected_receipt_date => NULL,
7718 p_api_version_number => 1.0,
7719 p_init_msg_lst => FND_API.G_FALSE );
7720
7721 IF g_debug <= gme_debug.g_log_statement THEN
7722 gme_debug.put_line
7723 ( g_pkg_name
7724 || '.'
7725 || l_api_name
7726 || ' Return status from gme_api_grp.validate_supply_demand is '
7727 || x_return_status);
7728 gme_debug.put_line(g_pkg_name
7729 ||'.'
7730 ||l_api_name
7731 || ' valid status is '
7732 || l_valid_status);
7733 END IF;
7734
7735 IF x_return_status <> FND_API.G_RET_STS_SUCCESS
7736 OR l_valid_status <> 'Y' THEN
7737 RAISE fnd_api.g_exc_error;
7738 END IF;
7739
7740 /* Invoke auto_detail_line to create detailed level reservations */
7741 gme_api_main.auto_detail_line
7742 (p_init_msg_list => fnd_api.g_false
7743 ,p_material_detail_rec => l_material_details_rec
7744 ,x_message_count => x_message_count
7745 ,x_message_list => x_message_list
7746 ,x_return_status => x_return_status);
7747
7748 IF g_debug <= gme_debug.g_log_statement THEN
7749 gme_debug.put_line ( g_pkg_name || '.' || l_api_name ||
7750 ' Return status from GME_API_MAIN.Auto_Detail_Line is '
7751 || x_return_status);
7752 END IF;
7753
7754 IF x_return_status <> fnd_api.g_ret_sts_success THEN
7755 RAISE auto_detail_error;
7756 END IF;
7757
7758 /* COMMIT handling */
7759 IF p_commit = fnd_api.g_true THEN
7760 COMMIT;
7761 END IF;
7762
7763 IF g_debug <= gme_debug.g_log_procedure THEN
7764 gme_debug.put_line ( ' Completed '
7765 || g_pkg_name
7766 || '.'
7767 || l_api_name
7768 || ' at '
7769 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
7770 END IF;
7771 EXCEPTION
7772 WHEN auto_detail_error THEN
7773 ROLLBACK TO SAVEPOINT auto_detail_line;
7774 gme_common_pvt.count_and_get (x_count => x_message_count
7775 ,p_encoded => fnd_api.g_false
7776 ,x_data => x_message_list);
7777 WHEN fnd_api.g_exc_error THEN
7778 x_return_status := fnd_api.g_ret_sts_error;
7779 ROLLBACK TO SAVEPOINT auto_detail_line;
7780 gme_common_pvt.count_and_get (x_count => x_message_count
7781 ,p_encoded => fnd_api.g_false
7782 ,x_data => x_message_list);
7783 WHEN OTHERS THEN
7784 ROLLBACK TO SAVEPOINT auto_detail_line;
7785 gme_when_others ( p_api_name => l_api_name
7786 ,x_message_count => x_message_count
7787 ,x_message_list => x_message_list
7788 ,x_return_status => x_return_status );
7789 END auto_detail_line;
7790
7791 /*************************************************************************/
7792 PROCEDURE auto_detail_batch (p_api_version IN NUMBER := 2.0
7793 ,p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE
7794 ,p_commit IN VARCHAR2 := FND_API.G_FALSE
7795 ,x_message_count OUT NOCOPY NUMBER
7796 ,x_message_list OUT NOCOPY VARCHAR2
7797 ,x_return_status OUT NOCOPY VARCHAR2
7798 ,p_org_code IN VARCHAR2
7799 ,p_batch_rec IN GME_BATCH_HEADER%ROWTYPE) IS
7800
7801 l_api_name CONSTANT VARCHAR2 (30) := 'AUTO_DETAIL_BATCH';
7802 l_batch_rec GME_BATCH_HEADER%ROWTYPE;
7803 l_batch_header_rec GME_BATCH_HEADER%ROWTYPE;
7804
7805 auto_detail_error EXCEPTION;
7806 BEGIN
7807 IF (g_debug <> -1) THEN
7808 gme_debug.log_initialize ('AutoDetailBatch');
7809 END IF;
7810
7811 IF g_debug <= gme_debug.g_log_procedure THEN
7812 gme_debug.put_line('Entering api '||g_pkg_name||'.'||l_api_name);
7813 END IF;
7814
7815 /* Set the savepoint */
7816 SAVEPOINT auto_detail_batch;
7817
7818 /* Set the return status to success initially */
7819 x_return_status := FND_API.G_RET_STS_SUCCESS;
7820
7821 IF p_init_msg_list = FND_API.G_TRUE THEN
7822 fnd_msg_pub.initialize;
7823 END IF;
7824
7825 IF NOT FND_API.compatible_api_call(2.0
7826 ,p_api_version
7827 ,'auto_detail_batch'
7828 ,g_pkg_name ) THEN
7829 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
7830 RAISE fnd_api.g_exc_error;
7831 END IF;
7832
7833 IF g_debug <= gme_debug.g_log_statement THEN
7834 gme_debug.put_line( g_pkg_name
7835 ||'.'
7836 ||l_api_name
7837 || 'Retrieve batch header row'
7838 || ' Input org_code is '
7839 ||p_org_code
7840 ||' Input org_id is '
7841 ||p_batch_rec.organization_id
7842 ||' Input batch_no is '
7843 ||p_batch_rec.batch_no
7844 ||' Input batch_id is '
7845 ||p_batch_rec.batch_id );
7846 END IF;
7847
7848 l_batch_rec := p_batch_rec;
7849 /* Check setup is done. For all profile/parameter values based on orgn_code/organization_id. */
7850 IF p_org_code is NOT NULL and p_batch_rec.organization_id is NULL THEN
7851 gme_common_pvt.g_setup_done :=
7852 gme_common_pvt.setup (p_org_id => l_batch_header_rec.organization_id,
7853 p_org_code => p_org_code);
7854
7855 IF NOT gme_common_pvt.g_setup_done THEN
7856 RAISE fnd_api.g_exc_error;
7857 ELSE
7858 l_batch_rec.organization_id := gme_common_pvt.g_organization_id;
7859 IF g_debug <= gme_debug.g_log_statement THEN
7860 gme_debug.put_line( g_pkg_name
7861 ||'.'
7862 ||l_api_name
7863 || ' Organization_id set to '
7864 ||gme_common_pvt.g_organization_id);
7865 END IF;
7866 END IF;
7867 END IF;
7868
7869 IF l_batch_rec.batch_type is NULL THEN
7870 l_batch_rec.batch_type := gme_common_pvt.g_doc_type_batch;
7871 END IF;
7872
7873 IF (NOT gme_batch_header_dbl.fetch_row (l_batch_rec,
7874 l_batch_header_rec) ) THEN
7875 RAISE fnd_api.g_exc_error;
7876 END IF;
7877
7878 /* Validate for organization */
7879 IF (l_batch_header_rec.organization_id IS NULL AND p_org_code IS NULL) THEN
7880 fnd_message.set_name ('INV', 'INV_ORG_REQUIRED');
7881 fnd_msg_pub.ADD;
7882 RAISE fnd_api.g_exc_error;
7883 END IF;
7884
7885 /* Check setup is done. For all profile/parameter values based on orgn_code/organization_id. */
7886 gme_common_pvt.g_setup_done :=
7887 gme_common_pvt.setup (p_org_id => l_batch_header_rec.organization_id,
7888 p_org_code => p_org_code);
7889
7890 IF NOT gme_common_pvt.g_setup_done THEN
7891 RAISE fnd_api.g_exc_error;
7892 END IF;
7893
7894 /* Verify that update_inventory is permitted for this batch */
7895 IF l_batch_header_rec.update_inventory_ind <> 'Y' THEN
7896 gme_common_pvt.log_message ('GME_INVENTORY_UPDATE_BLOCKED');
7897 RAISE fnd_api.g_exc_error;
7898 END IF;
7899
7900 /* Verify Batch to be in pending or WIP status */
7901 IF l_batch_header_rec.batch_status NOT IN
7902 (gme_common_pvt.g_batch_pending, gme_common_pvt.g_batch_wip) THEN
7903 gme_common_pvt.log_message ('GME_INVALID_BATCH_STATUS','PROCESS','AUTO_DETAIL_BATCH');
7904 RAISE fnd_api.g_exc_error;
7905 END IF;
7906
7907 /* Reservations not permitted for FPOs */
7908 IF l_batch_header_rec.batch_type = gme_common_pvt.g_doc_type_fpo THEN
7909 gme_common_pvt.log_message ('GME_FPO_RESERVATION_ERROR');
7910 RAISE fnd_api.g_exc_error;
7911 END IF;
7912
7913 gme_common_pvt.set_timestamp;
7914
7915 /* Invoke auto_detail_batch to create detailed level reservations */
7916 GME_API_MAIN.Auto_Detail_Batch(p_init_msg_list => FND_API.G_FALSE
7917 ,x_message_count => x_message_count
7918 ,x_message_list => x_message_list
7919 ,x_return_status => x_return_status
7920 ,p_batch_rec => l_batch_header_rec);
7921
7922 IF g_debug <= gme_debug.g_log_statement THEN
7923 gme_debug.put_line( g_pkg_name
7924 ||'.'
7925 ||l_api_name
7926 ||' Return status from GME_API_MAIN.Auto_Detail_Batch is '
7927 ||x_return_status);
7928 END IF;
7929
7930 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7931 RAISE auto_detail_error;
7932 END IF;
7933
7934 /* COMMIT handling */
7935 IF p_commit = FND_API.G_TRUE THEN
7936 COMMIT;
7937 END IF;
7938
7939 IF g_debug <= gme_debug.g_log_procedure THEN
7940 gme_debug.put_line ( ' Completed '
7941 ||g_pkg_name
7942 ||'.'
7943 || l_api_name
7944 || ' at '
7945 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS'));
7946 END IF;
7947
7948 EXCEPTION
7949 WHEN auto_detail_error THEN
7950 ROLLBACK TO SAVEPOINT auto_detail_batch;
7951 gme_common_pvt.count_and_get(x_count => x_message_count,
7952 p_encoded => FND_API.g_false,
7953 x_data => x_message_list);
7954 WHEN fnd_api.g_exc_error THEN
7955 x_return_status := FND_API.g_ret_sts_error;
7956 ROLLBACK TO SAVEPOINT auto_detail_batch;
7957 gme_common_pvt.count_and_get(x_count => x_message_count,
7958 p_encoded => FND_API.g_false,
7959 x_data => x_message_list);
7960 WHEN OTHERS THEN
7961 ROLLBACK TO SAVEPOINT auto_detail_batch;
7962 gme_when_others ( p_api_name => l_api_name
7963 ,x_message_count => x_message_count
7964 ,x_message_list => x_message_list
7965 ,x_return_status => x_return_status );
7966 END auto_detail_batch;
7967
7968 /*================================================================================
7969 Procedure
7970 insert_batchstep_activity
7971 Description
7972 This procedure is used to insert an activity for a step
7973
7974 Parameters
7975 p_batchstep_activity_rec (R) activity to be inserted for a step
7976 p_batchstep_resource_tbl (R) one or more resources to be inserted for the activity
7977 p_org_code (O) organization code
7978 p_batch_no (O) batch number
7979 p_batchstep_no(O) batch step number
7980 p_ignore_qty_below_cap (O) controls - allow rsrc_qty going below rsrc capacity
7981 p_validate_flexfield (O) Whether to validate the flexfields
7982 x_batchstep_activity_rec newly inserted activity row, can be used for update etc
7983 x_return_status outcome of the API call
7984 S - Success
7985 E - Error
7986 U - Unexpected Error
7987 HISTORY
7988 Sivakumar.G FPBug#4395561 16-NOV-2005
7989 Code changes made to set global flex field validate flag
7990 ================================================================================*/
7991 PROCEDURE insert_batchstep_activity (
7992 p_api_version IN NUMBER ,
7993 p_validation_level IN NUMBER
7994 := gme_common_pvt.g_max_errors,
7995 p_init_msg_list IN VARCHAR2
7996 DEFAULT fnd_api.g_false,
7997 p_commit IN VARCHAR2
7998 DEFAULT fnd_api.g_false,
7999 p_org_code IN VARCHAR2,
8000 p_batchstep_activity_rec IN gme_batch_step_activities%ROWTYPE,
8001 p_batchstep_resource_tbl IN gme_create_step_pvt.resources_tab,
8002 p_batch_no IN VARCHAR2 := NULL,
8003 p_batchstep_no IN NUMBER := NULL,
8004 p_ignore_qty_below_cap IN VARCHAR2
8005 DEFAULT fnd_api.g_false,
8006 p_validate_flexfield IN VARCHAR2
8007 DEFAULT fnd_api.g_false,
8008 x_batchstep_activity_rec OUT NOCOPY gme_batch_step_activities%ROWTYPE,
8009 x_message_count OUT NOCOPY NUMBER,
8010 x_message_list OUT NOCOPY VARCHAR2,
8011 x_return_status OUT NOCOPY VARCHAR2
8012 )
8013 IS
8014 l_api_name CONSTANT VARCHAR2 (30) := 'INSERT_BATCHSTEP_ACTIVITY';
8015
8016 insert_activity_failed EXCEPTION;
8017 BEGIN
8018 /* Set savepoint here */
8019 SAVEPOINT insert_activity_pub;
8020
8021 IF (g_debug <> -1)
8022 THEN
8023 gme_debug.log_initialize ('InsertBatchstepActivity');
8024 END IF;
8025
8026 IF g_debug <= gme_debug.g_log_procedure THEN
8027 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
8028 || l_api_name);
8029 END IF;
8030
8031 IF (fnd_api.to_boolean (p_init_msg_list))
8032 THEN
8033 fnd_msg_pub.initialize;
8034 gme_common_pvt.g_error_count := 0;
8035 END IF;
8036
8037 -- Standard call to check for call compatibility.
8038 IF NOT fnd_api.compatible_api_call (2.0,
8039 p_api_version,
8040 l_api_name,
8041 g_pkg_name
8042 ) THEN
8043 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
8044 RAISE fnd_api.g_exc_error;
8045 END IF;
8046
8047 /* Set the return status to success initially */
8048 x_return_status := fnd_api.g_ret_sts_success;
8049
8050 /* Setup the common constants used accross the apis */
8051 IF (NOT gme_common_pvt.setup (p_org_id => NULL,
8052 p_org_code => p_org_code)
8053 )THEN
8054 RAISE fnd_api.g_exc_error;
8055 END IF;
8056
8057 --FPBug#4395561 Start setting global flex validate variable
8058 IF p_validate_flexfield = FND_API.G_TRUE THEN
8059 gme_common_pvt.g_flex_validate_prof := 1;
8060 ELSE
8061 gme_common_pvt.g_flex_validate_prof := 0;
8062 END IF;
8063 --FPBug#4395561 End
8064
8065 gme_common_pvt.set_timestamp;
8066 gme_batchstep_act_pvt.insert_batchstep_activity (p_batchstep_activity_rec => p_batchstep_activity_rec,
8067 p_batchstep_resource_tbl => p_batchstep_resource_tbl,
8068 p_org_code => p_org_code,
8069 p_batch_no => p_batch_no,
8070 p_batchstep_no => p_batchstep_no,
8071 p_ignore_qty_below_cap => p_ignore_qty_below_cap,
8072 p_validate_flexfield => p_validate_flexfield,
8073 x_batchstep_activity_rec => x_batchstep_activity_rec,
8074 x_return_status => x_return_status
8075 );
8076 --FPBug#4395561 resetting global flex field validate
8077 gme_common_pvt.g_flex_validate_prof := 0;
8078
8079 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
8080 RAISE insert_activity_failed;
8081 END IF;
8082
8083 gme_api_pub.save_batch (x_return_status => x_return_status);
8084
8085 IF (x_return_status = fnd_api.g_ret_sts_success) THEN
8086 COMMIT WORK;
8087 ELSE
8088 RAISE fnd_api.g_exc_error;
8089 END IF;
8090
8091 gme_common_pvt.count_and_get (x_count => x_message_count,
8092 p_encoded => fnd_api.g_false,
8093 x_data => x_message_list
8094 );
8095
8096 IF g_debug <= gme_debug.g_log_procedure THEN
8097 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
8098 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
8099 END IF;
8100 EXCEPTION
8101 WHEN insert_activity_failed THEN
8102 ROLLBACK TO SAVEPOINT insert_activity_pub;
8103 gme_common_pvt.count_and_get (x_count => x_message_count,
8104 p_encoded => fnd_api.g_false,
8105 x_data => x_message_list
8106 );
8107 WHEN fnd_api.g_exc_error THEN
8108 ROLLBACK TO SAVEPOINT insert_activity_pub;
8109 x_return_status := fnd_api.g_ret_sts_error;
8110 gme_common_pvt.count_and_get (x_count => x_message_count,
8111 p_encoded => fnd_api.g_false,
8112 x_data => x_message_list
8113 );
8114 WHEN OTHERS THEN
8115 ROLLBACK TO SAVEPOINT insert_activity_pub;
8116 gme_when_others ( p_api_name => l_api_name
8117 ,x_message_count => x_message_count
8118 ,x_message_list => x_message_list
8119 ,x_return_status => x_return_status );
8120 END insert_batchstep_activity;
8121
8122 /*================================================================================
8123 Procedure
8124 update_batchstep_activity
8125 Description
8126 This procedure is used to update an activity for a step
8127
8128 Parameters
8129 p_batchstep_activity (R) activity to be updated
8130 p_org_code (O) organization code
8131 p_batch_no (O) batch number
8132 p_batchstep_no(O) batch step number
8133 p_validate_flexfield (O) Whether to validate the flexfields
8134 x_batchstep_activity updated activity row
8135 x_return_status outcome of the API call
8136 S - Success
8137 E - Error
8138 U - Unexpected Error
8139 HISTORY
8140 Sivakumar.G FPBug#4395561 16-NOV-2005
8141 Code changes made to set global flex field validate flag
8142 ================================================================================*/
8143 PROCEDURE update_batchstep_activity (
8144 p_api_version IN NUMBER ,
8145 p_validation_level IN NUMBER
8146 := gme_common_pvt.g_max_errors,
8147 p_init_msg_list IN VARCHAR2
8148 DEFAULT fnd_api.g_false,
8149 p_commit IN VARCHAR2
8150 DEFAULT fnd_api.g_false,
8151 p_org_code IN VARCHAR2,
8152 p_batchstep_activity_rec IN gme_batch_step_activities%ROWTYPE,
8153 p_batch_no IN VARCHAR2 := NULL,
8154 p_batchstep_no IN NUMBER := NULL,
8155 p_validate_flexfield IN VARCHAR2
8156 DEFAULT fnd_api.g_false,
8157 x_batchstep_activity_rec OUT NOCOPY gme_batch_step_activities%ROWTYPE,
8158 x_message_count OUT NOCOPY NUMBER,
8159 x_message_list OUT NOCOPY VARCHAR2,
8160 x_return_status OUT NOCOPY VARCHAR2
8161 )
8162 IS
8163 l_api_name CONSTANT VARCHAR2 (30) := 'UPDATE_BATCHSTEP_ACTIVITY';
8164 update_activity_failed EXCEPTION;
8165 BEGIN
8166 /* Set savepoint here */
8167 SAVEPOINT update_activity_pub;
8168
8169 IF (g_debug <> -1) THEN
8170 gme_debug.log_initialize ('UpdateBatchstepActivity');
8171 END IF;
8172 IF g_debug <= gme_debug.g_log_procedure THEN
8173 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
8174 || l_api_name);
8175 END IF;
8176
8177 IF (fnd_api.to_boolean (p_init_msg_list)) THEN
8178 fnd_msg_pub.initialize;
8179 gme_common_pvt.g_error_count := 0;
8180 END IF;
8181
8182 -- Standard call to check for call compatibility.
8183 IF NOT fnd_api.compatible_api_call (2.0,
8184 p_api_version,
8185 l_api_name,
8186 g_pkg_name
8187 ) THEN
8188 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
8189 RAISE fnd_api.g_exc_error;
8190 END IF;
8191
8192 /* Set the return status to success initially */
8193 x_return_status := fnd_api.g_ret_sts_success;
8194
8195 /* Setup the common constants used accross the apis */
8196 IF (NOT gme_common_pvt.setup (p_org_id => NULL,
8197 p_org_code => p_org_code)) THEN
8198 RAISE fnd_api.g_exc_error;
8199 END IF;
8200
8201 --FPBug#4395561 Start setting global flex validate variable
8202 IF p_validate_flexfield = FND_API.G_TRUE THEN
8203 gme_common_pvt.g_flex_validate_prof := 1;
8204 ELSE
8205 gme_common_pvt.g_flex_validate_prof := 0;
8206 END IF;
8207 --FPBug#4395561 End
8208
8209 gme_common_pvt.set_timestamp;
8210 gme_batchstep_act_pvt.update_batchstep_activity (p_batchstep_activity_rec => p_batchstep_activity_rec,
8211 p_org_code => p_org_code,
8212 p_batch_no => p_batch_no,
8213 p_batchstep_no => p_batchstep_no,
8214 p_validate_flexfield => p_validate_flexfield,
8215 x_batchstep_activity_rec => x_batchstep_activity_rec,
8216 x_return_status => x_return_status
8217 );
8218 --FPBug#4395561 resetting global flex-field validate variable
8219 gme_common_pvt.g_flex_validate_prof := 0;
8220
8221 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
8222 RAISE update_activity_failed;
8223 END IF;
8224
8225 gme_api_pub.save_batch (x_return_status => x_return_status);
8226
8227 IF (x_return_status = fnd_api.g_ret_sts_success) THEN
8228 COMMIT WORK;
8229 ELSE
8230 RAISE fnd_api.g_exc_error;
8231 END IF;
8232
8233 gme_common_pvt.count_and_get (x_count => x_message_count,
8234 p_encoded => fnd_api.g_false,
8235 x_data => x_message_list
8236 );
8237 IF g_debug <= gme_debug.g_log_procedure THEN
8238 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
8239 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
8240 END IF;
8241 EXCEPTION
8242 WHEN update_activity_failed THEN
8243 ROLLBACK TO SAVEPOINT update_activity_pub;
8244 gme_common_pvt.count_and_get (x_count => x_message_count,
8245 p_encoded => fnd_api.g_false,
8246 x_data => x_message_list
8247 );
8248 WHEN fnd_api.g_exc_error THEN
8249 ROLLBACK TO SAVEPOINT update_activity_pub;
8250 x_return_status := fnd_api.g_ret_sts_error;
8251 gme_common_pvt.count_and_get (x_count => x_message_count,
8252 p_encoded => fnd_api.g_false,
8253 x_data => x_message_list
8254 );
8255 WHEN OTHERS THEN
8256 ROLLBACK TO SAVEPOINT update_activity_pub;
8257 gme_when_others ( p_api_name => l_api_name
8258 ,x_message_count => x_message_count
8259 ,x_message_list => x_message_list
8260 ,x_return_status => x_return_status );
8261 END update_batchstep_activity;
8262
8263 /*================================================================================
8264 Procedure
8265 delete_batchstep_activity
8266 Description
8267 This procedure is used to delete an activity from a step. Note that either the
8268 activity_id must be provided or the combination of organization_code, batch_no, batchstep_no,
8269 and activity in order to uniquely identify an activity to be deleted.
8270
8271 Parameters
8272 p_batchstep_activity_id (O) activity_id to be deleted
8273 p_org_code (O) organization code
8274 p_batch_no (O) batch number
8275 p_batchstep_no(O) batch step number
8276 p_activity(O) activity
8277 x_return_status outcome of the API call
8278 S - Success
8279 E - Error
8280 U - Unexpected Error
8281 ================================================================================*/
8282 PROCEDURE delete_batchstep_activity (
8283 p_api_version IN NUMBER := 2.0,
8284 p_validation_level IN NUMBER
8285 := gme_common_pvt.g_max_errors,
8286 p_init_msg_list IN VARCHAR2
8287 DEFAULT fnd_api.g_false,
8288 p_commit IN VARCHAR2
8289 DEFAULT fnd_api.g_false,
8290 p_org_code IN VARCHAR2,
8291 p_batchstep_activity_id IN NUMBER := NULL,
8292 p_batch_no IN VARCHAR2 := NULL,
8293 p_batchstep_no IN NUMBER := NULL,
8294 p_activity IN VARCHAR2 := NULL,
8295 x_message_count OUT NOCOPY NUMBER,
8296 x_message_list OUT NOCOPY VARCHAR2,
8297 x_return_status OUT NOCOPY VARCHAR2
8298 )
8299 IS
8300 l_api_name CONSTANT VARCHAR2 (30) := 'DELETE_BATCHSTEP_ACTIVITY';
8301
8302 delete_activity_failed EXCEPTION;
8303 BEGIN
8304 /* Set savepoint here */
8305 SAVEPOINT delete_activity_pub;
8306
8307 IF (g_debug <> -1) THEN
8308 gme_debug.log_initialize ('CreatePhantom');
8309 END IF;
8310
8311 IF g_debug <= gme_debug.g_log_procedure THEN
8312 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
8313 || l_api_name);
8314 END IF;
8315
8316 IF (fnd_api.to_boolean (p_init_msg_list))
8317 THEN
8318 fnd_msg_pub.initialize;
8319 gme_common_pvt.g_error_count := 0;
8320 END IF;
8321
8322 -- Standard call to check for call compatibility.
8323 IF NOT fnd_api.compatible_api_call (2.0,
8324 p_api_version,
8325 l_api_name,
8326 g_pkg_name) THEN
8327 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
8328 RAISE fnd_api.g_exc_error;
8329 END IF;
8330
8331 /* Set the return status to success initially */
8332 x_return_status := fnd_api.g_ret_sts_success;
8333
8334 /* Setup the common constants used accross the apis */
8335 IF (NOT gme_common_pvt.setup (p_org_id => NULL,
8336 p_org_code => p_org_code)) THEN
8337 RAISE fnd_api.g_exc_error;
8338 END IF;
8339
8340 gme_common_pvt.set_timestamp;
8341 gme_batchstep_act_pvt.delete_batchstep_activity (p_batchstep_activity_id => p_batchstep_activity_id,
8342 p_org_code => p_org_code,
8343 p_batch_no => p_batch_no,
8344 p_batchstep_no => p_batchstep_no,
8345 p_activity => p_activity,
8346 x_return_status => x_return_status
8347 );
8348 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
8349 RAISE delete_activity_failed;
8350 END IF;
8351
8352 gme_api_pub.save_batch (x_return_status => x_return_status);
8353
8354 IF (x_return_status = fnd_api.g_ret_sts_success) THEN
8355 COMMIT;
8356 ELSE
8357 RAISE fnd_api.g_exc_error;
8358 END IF;
8359
8360 gme_common_pvt.count_and_get (x_count => x_message_count,
8361 p_encoded => fnd_api.g_false,
8362 x_data => x_message_list
8363 );
8364
8365 IF g_debug <= gme_debug.g_log_procedure THEN
8366 gme_debug.put_line ( 'Completed ' || l_api_name || ' at '
8367 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
8368 END IF;
8369 EXCEPTION
8370 WHEN delete_activity_failed THEN
8371 ROLLBACK TO SAVEPOINT delete_activity_pub;
8372 gme_common_pvt.count_and_get (x_count => x_message_count,
8373 p_encoded => fnd_api.g_false,
8374 x_data => x_message_list
8375 );
8376 WHEN fnd_api.g_exc_error THEN
8377 ROLLBACK TO SAVEPOINT delete_activity_pub;
8378 x_return_status := fnd_api.g_ret_sts_error;
8379 gme_common_pvt.count_and_get (x_count => x_message_count,
8380 p_encoded => fnd_api.g_false,
8381 x_data => x_message_list
8382 );
8383 WHEN OTHERS THEN
8384 ROLLBACK TO SAVEPOINT delete_activity_pub;
8385 gme_when_others ( p_api_name => l_api_name
8386 ,x_message_count => x_message_count
8387 ,x_message_list => x_message_list
8388 ,x_return_status => x_return_status );
8389 END delete_batchstep_activity;
8390
8391 /*************************************************************************/
8392 PROCEDURE convert_fpo (
8393 p_api_version IN NUMBER := 2.0,
8394 p_validation_level IN NUMBER := gme_common_pvt.g_max_errors,
8395 p_init_msg_list IN VARCHAR2 := fnd_api.g_false,
8396 p_commit IN VARCHAR2 := fnd_api.g_false,
8397 x_message_count OUT NOCOPY NUMBER,
8398 x_message_list OUT NOCOPY VARCHAR2,
8399 p_enforce_vldt_check IN VARCHAR2 := fnd_api.g_true,
8400 x_return_status OUT NOCOPY VARCHAR2,
8401 p_org_code IN VARCHAR2 := NULL,
8402 p_batch_header IN gme_batch_header%ROWTYPE,
8403 x_batch_header OUT NOCOPY gme_batch_header%ROWTYPE,
8404 p_batch_size IN NUMBER,
8405 p_num_batches IN NUMBER,
8406 p_validity_rule_id IN NUMBER,
8407 p_validity_rule_tab IN gme_common_pvt.recipe_validity_rule_tab,
8408 p_leadtime IN NUMBER DEFAULT 0,
8409 p_batch_offset IN NUMBER DEFAULT 0,
8410 p_offset_type IN NUMBER DEFAULT 0,
8411 p_plan_start_date IN gme_batch_header.plan_start_date%TYPE,
8412 p_plan_cmplt_date IN gme_batch_header.plan_cmplt_date%TYPE,
8413 p_use_shop_cal IN VARCHAR2 := fnd_api.g_false,
8414 p_contiguity_override IN VARCHAR2 := fnd_api.g_true,
8415 p_use_for_all IN VARCHAR2 := fnd_api.g_true
8416 ) IS
8417 l_api_name CONSTANT VARCHAR2 (30) := 'CONVERT_FPO';
8418 l_batch_header gme_batch_header%ROWTYPE;
8419
8420 convert_fpo_failed EXCEPTION;
8421 BEGIN
8422 /* Set the savepoint before proceeding */
8423 SAVEPOINT convert_fpo;
8424
8425 IF (g_debug <> -1) THEN
8426 gme_debug.log_initialize ('ConvertFPO');
8427 END IF;
8428
8429 IF g_debug <= gme_debug.g_log_procedure THEN
8430 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
8431 || l_api_name);
8432 END IF;
8433
8434 /* Set the return status to success initially */
8435 x_return_status := fnd_api.g_ret_sts_success;
8436
8437 IF p_init_msg_list = fnd_api.g_true THEN
8438 fnd_msg_pub.initialize;
8439 END IF;
8440
8441 IF NOT fnd_api.compatible_api_call (2.0
8442 ,p_api_version
8443 ,'convertFPO'
8444 ,g_pkg_name) THEN
8445 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
8446 RAISE fnd_api.g_exc_error;
8447 END IF;
8448
8449
8450 IF (p_batch_header.organization_id IS NULL AND p_org_code IS NULL) THEN
8451 fnd_message.set_name ('INV', 'INV_ORG_REQUIRED');
8452 fnd_msg_pub.ADD;
8453 RAISE fnd_api.g_exc_error;
8454 END IF;
8455
8456 /* Use local variable, so that user does not have to pass batch_type value 10 */
8457 l_batch_header := p_batch_header;
8458 l_batch_header.batch_type := 10;
8459
8460 /* Check for phantom batch */
8461 IF gme_phantom_pvt.is_phantom (
8462 p_batch_header => l_batch_header,
8463 x_return_status => x_return_status
8464 ) THEN
8465 gme_common_pvt.log_message ('PM_INVALID_PHANTOM_ACTION');
8466 RAISE fnd_api.g_exc_error;
8467 ELSIF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8468 RAISE fnd_api.g_exc_error;
8469 END IF;
8470
8471 IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
8472 gme_debug.put_line (g_pkg_name ||
8473 '.' ||
8474 l_api_name ||
8475 ' Do setup for org using org_code of '||
8476 p_org_code ||
8477 ' and organization_id of '||
8478 l_batch_header.organization_id);
8479 END IF;
8480
8481 /* Setup the common constants used accross the apis */
8482 gme_common_pvt.g_setup_done :=
8483 gme_common_pvt.setup (p_org_id => l_batch_header.organization_id
8484 ,p_org_code => p_org_code);
8485
8486 IF NOT gme_common_pvt.g_setup_done THEN
8487 RAISE fnd_api.g_exc_error;
8488 ELSE
8489 l_batch_header.organization_id := gme_common_pvt.g_organization_id;
8490 END IF;
8491
8492 gme_common_pvt.set_timestamp;
8493
8494 gme_convert_fpo_pvt.convert_fpo_main (
8495 p_batch_header => l_batch_header,
8496 p_batch_size => p_batch_size,
8497 p_num_batches => p_num_batches,
8498 p_validity_rule_id => p_validity_rule_id,
8499 p_validity_rule_tab => p_validity_rule_tab,
8500 p_enforce_vldt_check => p_enforce_vldt_check,
8501 p_leadtime => p_leadtime,
8502 p_batch_offset => p_batch_offset,
8503 p_offset_type => p_offset_type,
8504 p_plan_start_date => p_plan_start_date,
8505 p_plan_cmplt_date => p_plan_cmplt_date,
8506 p_use_shop_cal => p_use_shop_cal,
8507 p_contiguity_override => p_contiguity_override,
8508 x_return_status => x_return_status,
8509 x_batch_header => x_batch_header,
8510 p_use_for_all => p_use_for_all
8511 );
8512
8513 IF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
8514 IF p_commit = fnd_api.g_true THEN
8515 gme_api_pub.save_batch (p_header_id => NULL
8516 ,p_table => NULL
8517 ,p_commit => p_commit
8518 ,x_return_status => x_return_status);
8519
8520 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8521 RAISE fnd_api.g_exc_error;
8522 ELSE
8523 gme_common_pvt.log_message ('GME_API_BATCH_CREATED');
8524 END IF;
8525 END IF;
8526 ELSE
8527 RAISE convert_fpo_failed;
8528 END IF;
8529
8530 gme_common_pvt.count_and_get (x_count => x_message_count,
8531 p_encoded => FND_API.g_false,
8532 x_data => x_message_list);
8533 IF g_debug <= gme_debug.g_log_procedure THEN
8534 gme_debug.put_line ( 'Completed ' || l_api_name || ' at ' || TO_CHAR
8535 (SYSDATE, 'MM/DD/YYYY HH24:MI:SS'));
8536 END IF;
8537 EXCEPTION
8538 WHEN convert_fpo_failed THEN
8539 ROLLBACK TO SAVEPOINT convert_fpo;
8540 x_batch_header := NULL;
8541 gme_common_pvt.count_and_get (x_count => x_message_count,
8542 p_encoded => FND_API.g_false,
8543 x_data => x_message_list);
8544 WHEN fnd_api.g_exc_error THEN
8545 ROLLBACK TO SAVEPOINT convert_fpo;
8546 x_batch_header := NULL;
8547 x_return_status := fnd_api.g_ret_sts_error;
8548 gme_common_pvt.count_and_get (x_count => x_message_count,
8549 p_encoded => FND_API.g_false,
8550 x_data => x_message_list);
8551 WHEN OTHERS THEN
8552 ROLLBACK TO SAVEPOINT convert_fpo;
8553 x_batch_header := NULL;
8554 gme_when_others ( p_api_name => l_api_name
8555 ,x_message_count => x_message_count
8556 ,x_message_list => x_message_list
8557 ,x_return_status => x_return_status );
8558 END convert_fpo;
8559
8560 /*================================================================================
8561 Procedure
8562 create_pending_product_lot
8563 Description
8564 This procedure is used to create a pending product lot record for a specified
8565 material detail record.
8566 Following key sequences can be specified:
8567 material_detail_id OR
8568 batch_id, line_no, line_type OR
8569 batch_no, org_code, line_no, line_type (batch_type is assumed to be Batch)
8570
8571 Parameters
8572 p_batch_header_rec (O) batch header record
8573 p_org_code (O) organization code
8574 p_material_detail_rec (O) material detail record
8575 p_pending_product_lots_rec (R) pending product lots record
8576 p_create_lot (O) This indicates whether to create the lot if the lot does
8577 not exist. Default to False, do not create the lot. This
8578 applies to products and by-products only.
8579 p_generate_lot (O) This indicates to generate a lot if there is nothing passed
8580 in the lot number field of p_pending_product_lots_rec. Default
8581 to False, do not generate the lot. This applies to products and
8582 by-products only.
8583 p_generate_parent_lot (O) This indicates to generate a parent lot. Default
8584 to False, do not generate the parent lot. This applies to products and
8585 by-products only.
8586 x_return_status outcome of the API call
8587 S - Success
8588 E - Error
8589 U - Unexpected Error
8590
8591 Modification History
8592 Bug#4486074 Namit S. Added the p_expiration_Date parameter.
8593 ================================================================================*/
8594
8595 PROCEDURE create_pending_product_lot
8596 (p_api_version IN NUMBER
8597 ,p_validation_level IN NUMBER
8598 := gme_common_pvt.g_max_errors
8599 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
8600 ,p_commit IN VARCHAR2 := fnd_api.g_false
8601 ,x_message_count OUT NOCOPY NUMBER
8602 ,x_message_list OUT NOCOPY VARCHAR2
8603 ,x_return_status OUT NOCOPY VARCHAR2
8604 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
8605 ,p_org_code IN VARCHAR2
8606 ,p_create_lot IN VARCHAR2 := fnd_api.g_false
8607 ,p_generate_lot IN VARCHAR2 := fnd_api.g_false
8608 ,p_generate_parent_lot IN VARCHAR2 := fnd_api.g_false
8609 ,p_material_detail_rec IN gme_material_details%ROWTYPE
8610 /* nsinghi bug#4486074 Added the p_expiration_dt parameter. */
8611 ,p_expiration_date IN mtl_lot_numbers.expiration_date%TYPE := NULL
8612 ,p_pending_product_lots_rec IN gme_pending_product_lots%ROWTYPE
8613 ,x_pending_product_lots_rec OUT NOCOPY gme_pending_product_lots%ROWTYPE)
8614 IS
8615 l_api_name CONSTANT VARCHAR2 (30) := 'CREATE_PENDING_PRODUCT_LOT';
8616
8617 l_pending_product_lots_rec gme_pending_product_lots%ROWTYPE;
8618 l_material_detail_rec gme_material_details%ROWTYPE;
8619 l_in_material_detail_rec gme_material_details%ROWTYPE;
8620 l_batch_header_rec gme_batch_header%ROWTYPE;
8621 l_batch_id NUMBER;
8622 l_matl_dtl_id NUMBER;
8623
8624 error_create_pp_lot EXCEPTION;
8625 BEGIN
8626 IF (g_debug <> -1) THEN
8627 gme_debug.log_initialize ('CreatePendingProdLot');
8628 END IF;
8629
8630 IF g_debug <= gme_debug.g_log_procedure THEN
8631 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
8632 || l_api_name);
8633 END IF;
8634
8635 /* Set the return status to success initially */
8636 x_return_status := fnd_api.g_ret_sts_success;
8637
8638 /* Set savepoint here */
8639 SAVEPOINT create_pending_product_lot;
8640
8641 IF p_init_msg_list = fnd_api.g_true THEN
8642 fnd_msg_pub.initialize;
8643 END IF;
8644
8645 IF NOT fnd_api.compatible_api_call (2.0
8646 ,p_api_version
8647 ,'create_pending_prod_lot'
8648 ,g_pkg_name) THEN
8649 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
8650 RAISE fnd_api.g_exc_error;
8651 END IF;
8652
8653 l_batch_id := NVL(p_pending_product_lots_rec.batch_id,
8654 NVL(p_material_detail_rec.batch_id, p_batch_header_rec.batch_id));
8655 l_matl_dtl_id := NVL(p_pending_product_lots_rec.material_detail_id, p_material_detail_rec.material_detail_id);
8656
8657 l_in_material_detail_rec := p_material_detail_rec;
8658 l_in_material_detail_rec.batch_id := l_batch_id;
8659 l_in_material_detail_rec.material_detail_id := l_matl_dtl_id;
8660
8661 /* Retrieve Batch Header and Material Detail Record */
8662 gme_common_pvt.Validate_material_detail
8663 (p_material_detail_rec => l_in_material_detail_rec
8664 ,p_org_code => p_org_code
8665 ,p_batch_no => p_batch_header_rec.batch_no
8666 ,p_batch_type => gme_common_pvt.g_doc_type_batch
8667 ,x_batch_header_rec => l_batch_header_rec
8668 ,x_material_detail_rec => l_material_detail_rec
8669 ,x_message_count => x_message_count
8670 ,x_message_list => x_message_list
8671 ,x_return_status => x_return_status );
8672 IF x_return_status <> fnd_api.g_ret_sts_success THEN
8673 IF (g_debug = gme_debug.g_log_statement) THEN
8674 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
8675 || ': batch mateiral validate error ');
8676 END IF;
8677 RAISE fnd_api.g_exc_error;
8678 END IF;
8679
8680 -- Validations
8681 gme_pending_product_lots_pvt.validate_material_for_create
8682 (p_batch_header_rec => l_batch_header_rec
8683 ,p_material_detail_rec => l_material_detail_rec
8684 ,x_return_status => x_return_status);
8685
8686 IF x_return_status <> fnd_api.g_ret_sts_success THEN
8687 RAISE fnd_api.g_exc_error;
8688 END IF;
8689
8690 gme_pending_product_lots_pvt.validate_record_for_create
8691 (p_material_detail_rec => l_material_detail_rec
8692 ,p_pending_product_lots_rec => p_pending_product_lots_rec
8693 ,p_create_lot => p_create_lot
8694 ,p_generate_lot => p_generate_lot
8695 ,p_generate_parent_lot => p_generate_parent_lot
8696 ,x_pending_product_lots_rec => l_pending_product_lots_rec
8697 ,x_return_status => x_return_status
8698 /* nsinghi bug#4486074 Added the following parameter. */
8699 ,p_expiration_date => p_expiration_date);
8700
8701 IF x_return_status <> fnd_api.g_ret_sts_success THEN
8702 RAISE fnd_api.g_exc_error;
8703 END IF;
8704
8705 /* Invoke main */
8706 gme_api_main.create_pending_product_lot
8707 (p_validation_level => p_validation_level
8708 ,p_init_msg_list => fnd_api.g_false
8709 ,x_message_count => x_message_count
8710 ,x_message_list => x_message_list
8711 ,x_return_status => x_return_status
8712 ,p_org_id => l_batch_header_rec.organization_id
8713 ,p_pending_product_lots_rec => l_pending_product_lots_rec
8714 ,x_pending_product_lots_rec => x_pending_product_lots_rec);
8715
8716
8717 IF g_debug <= gme_debug.g_log_statement THEN
8718 gme_debug.put_line
8719 ( g_pkg_name
8720 || '.'
8721 || l_api_name
8722 || ' Return status from gme_api_main.create_pending_product_lot is '
8723 || x_return_status);
8724 END IF;
8725
8726 IF x_return_status <> fnd_api.g_ret_sts_success THEN
8727 RAISE error_create_pp_lot;
8728 END IF;
8729
8730 gme_api_pub.save_batch
8731 (p_header_id => gme_common_pvt.g_transaction_header_id
8732 ,p_table => 1
8733 ,p_commit => p_commit
8734 ,x_return_status => x_return_status);
8735
8736 IF g_debug <= gme_debug.g_log_statement THEN
8737 gme_debug.put_line
8738 ( g_pkg_name
8739 || '.'
8740 || l_api_name
8741 || ' Return status from gme_api_pub.save_batch is '
8742 || x_return_status);
8743 END IF;
8744
8745 IF x_return_status <> fnd_api.g_ret_sts_success THEN
8746 RAISE fnd_api.g_exc_error;
8747 END IF;
8748
8749 IF g_debug <= gme_debug.g_log_procedure THEN
8750 gme_debug.put_line ( ' Completed '
8751 || l_api_name
8752 || ' at '
8753 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
8754 END IF;
8755
8756 EXCEPTION
8757 WHEN error_create_pp_lot THEN
8758 ROLLBACK TO SAVEPOINT create_pending_product_lot;
8759 gme_common_pvt.count_and_get (x_count => x_message_count
8760 ,p_encoded => fnd_api.g_false
8761 ,x_data => x_message_list);
8762 WHEN fnd_api.g_exc_error THEN
8763 ROLLBACK TO SAVEPOINT create_pending_product_lot;
8764 x_return_status := fnd_api.g_ret_sts_error;
8765 gme_common_pvt.count_and_get (x_count => x_message_count
8766 ,p_encoded => fnd_api.g_false
8767 ,x_data => x_message_list);
8768 WHEN OTHERS THEN
8769 ROLLBACK TO SAVEPOINT create_pending_product_lot;
8770 gme_when_others ( p_api_name => l_api_name
8771 ,x_message_count => x_message_count
8772 ,x_message_list => x_message_list
8773 ,x_return_status => x_return_status );
8774 END create_pending_product_lot;
8775
8776 /*================================================================================
8777 Procedure
8778 update_pending_product_lot
8779 Description
8780 This procedure is used to update a pending product lot record for a specified
8781 pending product lot record
8782 Following key sequences can be specified:
8783 pending_product_lot_id OR
8784 batch_id, line_no, line_type, sequence OR
8785 batch_no, org_code, line_no, line_type, sequence (batch_type is assumed to be Batch)
8786
8787 Parameters
8788 p_batch_header_rec (O) batch header record
8789 p_org_code (O) organization code
8790 p_material_detail_rec (O) material detail record
8791 p_pending_product_lots_rec (R) pending product lots record
8792 x_return_status outcome of the API call
8793 S - Success
8794 E - Error
8795 U - Unexpected Error
8796 ================================================================================*/
8797
8798 PROCEDURE update_pending_product_lot
8799 (p_api_version IN NUMBER
8800 ,p_validation_level IN NUMBER
8801 := gme_common_pvt.g_max_errors
8802 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
8803 ,p_commit IN VARCHAR2 := fnd_api.g_false
8804 ,x_message_count OUT NOCOPY NUMBER
8805 ,x_message_list OUT NOCOPY VARCHAR2
8806 ,x_return_status OUT NOCOPY VARCHAR2
8807 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
8808 ,p_org_code IN VARCHAR2
8809 ,p_material_detail_rec IN gme_material_details%ROWTYPE
8810 ,p_pending_product_lots_rec IN gme_pending_product_lots%ROWTYPE
8811 ,x_pending_product_lots_rec OUT NOCOPY gme_pending_product_lots%ROWTYPE)
8812 IS
8813 l_api_name CONSTANT VARCHAR2 (30) := 'UPDATE_PENDING_PRODUCT_LOT';
8814
8815 l_pending_product_lots_rec gme_pending_product_lots%ROWTYPE;
8816 l_db_pending_product_lots_rec gme_pending_product_lots%ROWTYPE;
8817 l_in_material_detail_rec gme_material_details%ROWTYPE;
8818 l_in_batch_header_rec gme_batch_header%ROWTYPE;
8819 l_material_detail_rec gme_material_details%ROWTYPE;
8820 l_batch_header_rec gme_batch_header%ROWTYPE;
8821 l_batch_id NUMBER;
8822 l_matl_dtl_id NUMBER;
8823
8824 error_update_pp_lot EXCEPTION;
8825 BEGIN
8826 IF (g_debug <> -1) THEN
8827 gme_debug.log_initialize ('UpdatePendingProdLot');
8828 END IF;
8829
8830 IF g_debug <= gme_debug.g_log_procedure THEN
8831 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
8832 || l_api_name);
8833 END IF;
8834
8835 /* Set the return status to success initially */
8836 x_return_status := fnd_api.g_ret_sts_success;
8837
8838 /* Set savepoint here */
8839 SAVEPOINT update_pending_product_lot;
8840
8841 IF p_init_msg_list = fnd_api.g_true THEN
8842 fnd_msg_pub.initialize;
8843 END IF;
8844
8845 IF NOT fnd_api.compatible_api_call (2.0
8846 ,p_api_version
8847 ,'update_pending_prod_lot'
8848 ,g_pkg_name) THEN
8849 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
8850 RAISE fnd_api.g_exc_error;
8851 END IF;
8852
8853 IF p_pending_product_lots_rec.pending_product_lot_id IS NOT NULL THEN
8854 IF NOT gme_pending_product_lots_dbl.fetch_row
8855 (p_pending_product_lots_rec => p_pending_product_lots_rec
8856 ,x_pending_product_lots_rec => l_db_pending_product_lots_rec) THEN
8857 x_return_status := fnd_api.g_ret_sts_error;
8858 RAISE fnd_api.g_exc_error;
8859 END IF;
8860
8861 l_in_material_detail_rec.material_detail_id := l_db_pending_product_lots_rec.material_detail_id;
8862 l_in_material_detail_rec.batch_id := l_db_pending_product_lots_rec.batch_id;
8863 gme_common_pvt.Validate_material_detail
8864 (p_material_detail_rec => l_in_material_detail_rec
8865 ,p_org_code => NULL
8866 ,p_batch_no => NULL
8867 ,p_batch_type => NULL
8868 ,x_batch_header_rec => l_batch_header_rec
8869 ,x_material_detail_rec => l_material_detail_rec
8870 ,x_message_count => x_message_count
8871 ,x_message_list => x_message_list
8872 ,x_return_status => x_return_status );
8873 IF x_return_status <> fnd_api.g_ret_sts_success THEN
8874 IF (g_debug = gme_debug.g_log_statement) THEN
8875 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
8876 || ': batch mateiral validate error ');
8877 END IF;
8878 RAISE fnd_api.g_exc_error;
8879 END IF;
8880
8881 ELSE
8882 l_batch_id := NVL(p_pending_product_lots_rec.batch_id,
8883 NVL(p_material_detail_rec.batch_id, p_batch_header_rec.batch_id));
8884 l_matl_dtl_id := NVL(p_pending_product_lots_rec.material_detail_id, p_material_detail_rec.material_detail_id);
8885
8886 l_in_material_detail_rec := p_material_detail_rec;
8887 l_in_material_detail_rec.batch_id := l_batch_id;
8888 l_in_material_detail_rec.material_detail_id := l_matl_dtl_id;
8889
8890 /* Retrieve Batch Header and Material Detail Record */
8891 gme_common_pvt.Validate_material_detail
8892 (p_material_detail_rec => l_in_material_detail_rec
8893 ,p_org_code => p_org_code
8894 ,p_batch_no => p_batch_header_rec.batch_no
8895 ,p_batch_type => gme_common_pvt.g_doc_type_batch
8896 ,x_batch_header_rec => l_batch_header_rec
8897 ,x_material_detail_rec => l_material_detail_rec
8898 ,x_message_count => x_message_count
8899 ,x_message_list => x_message_list
8900 ,x_return_status => x_return_status );
8901 IF x_return_status <> fnd_api.g_ret_sts_success THEN
8902 IF (g_debug = gme_debug.g_log_statement) THEN
8903 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
8904 || ': batch mateiral validate error ');
8905 END IF;
8906 RAISE fnd_api.g_exc_error;
8907 END IF;
8908 END IF;
8909
8910 -- Validations
8911 gme_pending_product_lots_pvt.validate_material_for_update
8912 (p_batch_header_rec => l_batch_header_rec
8913 ,p_material_detail_rec => l_material_detail_rec
8914 ,x_return_status => x_return_status);
8915
8916 IF x_return_status <> fnd_api.g_ret_sts_success THEN
8917 RAISE fnd_api.g_exc_error;
8918 END IF;
8919
8920 gme_pending_product_lots_pvt.validate_record_for_update
8921 (p_material_detail_rec => l_material_detail_rec
8922 ,p_db_pending_product_lots_rec => l_db_pending_product_lots_rec
8923 ,p_pending_product_lots_rec => p_pending_product_lots_rec
8924 ,x_pending_product_lots_rec => l_pending_product_lots_rec
8925 ,x_return_status => x_return_status);
8926
8927 IF x_return_status <> fnd_api.g_ret_sts_success THEN
8928 RAISE fnd_api.g_exc_error;
8929 END IF;
8930
8931 /* Invoke main */
8932 gme_api_main.update_pending_product_lot
8933 (p_validation_level => p_validation_level
8934 ,p_init_msg_list => fnd_api.g_false
8935 ,x_message_count => x_message_count
8936 ,x_message_list => x_message_list
8937 ,x_return_status => x_return_status
8938 ,p_org_id => l_batch_header_rec.organization_id
8939 ,p_pending_product_lots_rec => l_pending_product_lots_rec
8940 ,x_pending_product_lots_rec => x_pending_product_lots_rec);
8941
8942
8943 IF g_debug <= gme_debug.g_log_statement THEN
8944 gme_debug.put_line
8945 ( g_pkg_name
8946 || '.'
8947 || l_api_name
8948 || ' Return status from gme_api_main.update_pending_product_lot is '
8949 || x_return_status);
8950 END IF;
8951
8952 IF x_return_status <> fnd_api.g_ret_sts_success THEN
8953 RAISE error_update_pp_lot;
8954 END IF;
8955
8956 /* Invoke save_batch */
8957 IF g_debug <= gme_debug.g_log_statement THEN
8958 gme_debug.put_line
8959 ( g_pkg_name
8960 || '.'
8961 || l_api_name
8962 || ' About to invoke save_batch with header_id of '
8963 || gme_common_pvt.g_transaction_header_id);
8964 END IF;
8965
8966 gme_api_pub.save_batch
8967 (p_header_id => gme_common_pvt.g_transaction_header_id
8968 ,p_table => 1
8969 ,p_commit => p_commit
8970 ,x_return_status => x_return_status);
8971
8972 IF g_debug <= gme_debug.g_log_statement THEN
8973 gme_debug.put_line
8974 ( g_pkg_name
8975 || '.'
8976 || l_api_name
8977 || ' Return status from gme_api_pub.save_batch is '
8978 || x_return_status);
8979 END IF;
8980
8981 IF x_return_status <> fnd_api.g_ret_sts_success THEN
8982 RAISE fnd_api.g_exc_error;
8983 END IF;
8984
8985 IF g_debug <= gme_debug.g_log_procedure THEN
8986 gme_debug.put_line ( ' Completed '
8987 || l_api_name
8988 || ' at '
8989 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
8990 END IF;
8991 EXCEPTION
8992 WHEN error_update_pp_lot THEN
8993 ROLLBACK TO SAVEPOINT update_pending_product_lot;
8994 x_pending_product_lots_rec := NULL;
8995 gme_common_pvt.count_and_get (x_count => x_message_count
8996 ,p_encoded => fnd_api.g_false
8997 ,x_data => x_message_list);
8998 WHEN fnd_api.g_exc_error THEN
8999 ROLLBACK TO SAVEPOINT update_pending_product_lot;
9000 x_pending_product_lots_rec := NULL;
9001 x_return_status := fnd_api.g_ret_sts_error;
9002 gme_common_pvt.count_and_get (x_count => x_message_count
9003 ,p_encoded => fnd_api.g_false
9004 ,x_data => x_message_list);
9005 WHEN OTHERS THEN
9006 ROLLBACK TO SAVEPOINT update_pending_product_lot;
9007 x_pending_product_lots_rec := NULL;
9008 gme_when_others ( p_api_name => l_api_name
9009 ,x_message_count => x_message_count
9010 ,x_message_list => x_message_list
9011 ,x_return_status => x_return_status );
9012 END update_pending_product_lot;
9013
9014 /*================================================================================
9015 Procedure
9016 Delete_pending_product_lot
9017 Description
9018 This procedure is used to delete a pending product lot record for a specified
9019 pending product lot record
9020 Following key sequences can be specified:
9021 pending_product_lot_id OR
9022 batch_id, line_no, line_type, sequence OR
9023 batch_no, org_code, line_no, line_type, sequence (batch_type is assumed to be Batch)
9024
9025 Parameters
9026 p_batch_header_rec (O) batch header record
9027 p_org_code (O) organization code
9028 p_material_detail_rec (O) material detail record
9029 p_pending_product_lots_rec (R) pending product lots record
9030 x_return_status outcome of the API call
9031 S - Success
9032 E - Error
9033 U - Unexpected Error
9034 ================================================================================*/
9035
9036 PROCEDURE delete_pending_product_lot
9037 (p_api_version IN NUMBER
9038 ,p_validation_level IN NUMBER
9039 := gme_common_pvt.g_max_errors
9040 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
9041 ,p_commit IN VARCHAR2 := fnd_api.g_false
9042 ,x_message_count OUT NOCOPY NUMBER
9043 ,x_message_list OUT NOCOPY VARCHAR2
9044 ,x_return_status OUT NOCOPY VARCHAR2
9045 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
9046 ,p_org_code IN VARCHAR2
9047 ,p_material_detail_rec IN gme_material_details%ROWTYPE
9048 ,p_pending_product_lots_rec IN gme_pending_product_lots%ROWTYPE)
9049 IS
9050 l_api_name CONSTANT VARCHAR2 (30) := 'DELETE_PENDING_PRODUCT_LOT';
9051
9052 l_pending_product_lots_rec gme_pending_product_lots%ROWTYPE;
9053 l_db_pending_product_lots_rec gme_pending_product_lots%ROWTYPE;
9054 l_in_material_detail_rec gme_material_details%ROWTYPE;
9055 l_in_batch_header_rec gme_batch_header%ROWTYPE;
9056 l_material_detail_rec gme_material_details%ROWTYPE;
9057 l_batch_header_rec gme_batch_header%ROWTYPE;
9058 l_batch_id NUMBER;
9059 l_matl_dtl_id NUMBER;
9060
9061 invalid_version EXCEPTION;
9062 setup_failure EXCEPTION;
9063 fetch_error EXCEPTION;
9064 batch_save_failed EXCEPTION;
9065 error_validation EXCEPTION;
9066 error_delete_pp_lot EXCEPTION;
9067
9068 BEGIN
9069 IF (g_debug <> -1) THEN
9070 gme_debug.log_initialize ('DeletePendingProdLot');
9071 END IF;
9072
9073 IF g_debug <= gme_debug.g_log_procedure THEN
9074 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
9075 || l_api_name);
9076 END IF;
9077
9078 /* Set the return status to success initially */
9079 x_return_status := fnd_api.g_ret_sts_success;
9080
9081 /* Set savepoint here */
9082 SAVEPOINT delete_pending_product_lot;
9083
9084 IF p_init_msg_list = fnd_api.g_true THEN
9085 fnd_msg_pub.initialize;
9086 END IF;
9087
9088 IF NOT fnd_api.compatible_api_call (2.0
9089 ,p_api_version
9090 ,'delete_pending_prod_lot'
9091 ,g_pkg_name) THEN
9092 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
9093 RAISE fnd_api.g_exc_error;
9094 END IF;
9095
9096 IF p_pending_product_lots_rec.pending_product_lot_id IS NOT NULL THEN
9097 IF NOT gme_pending_product_lots_dbl.fetch_row
9098 (p_pending_product_lots_rec => p_pending_product_lots_rec
9099 ,x_pending_product_lots_rec => l_db_pending_product_lots_rec) THEN
9100 x_return_status := fnd_api.g_ret_sts_error;
9101 RAISE fnd_api.g_exc_error;
9102 END IF;
9103
9104 l_in_material_detail_rec.material_detail_id := l_db_pending_product_lots_rec.material_detail_id;
9105 l_in_material_detail_rec.batch_id := l_db_pending_product_lots_rec.batch_id;
9106 gme_common_pvt.Validate_material_detail
9107 (p_material_detail_rec => l_in_material_detail_rec
9108 ,p_org_code => NULL
9109 ,p_batch_no => NULL
9110 ,p_batch_type => NULL
9111 ,x_batch_header_rec => l_batch_header_rec
9112 ,x_material_detail_rec => l_material_detail_rec
9113 ,x_message_count => x_message_count
9114 ,x_message_list => x_message_list
9115 ,x_return_status => x_return_status );
9116 IF x_return_status <> fnd_api.g_ret_sts_success THEN
9117 IF (g_debug = gme_debug.g_log_statement) THEN
9118 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
9119 || ': batch mateiral validate error ');
9120 END IF;
9121 RAISE fnd_api.g_exc_error;
9122 END IF;
9123 ELSE
9124 l_batch_id := NVL(p_pending_product_lots_rec.batch_id,
9125 NVL(p_material_detail_rec.batch_id, p_batch_header_rec.batch_id));
9126 l_matl_dtl_id := NVL(p_pending_product_lots_rec.material_detail_id, p_material_detail_rec.material_detail_id);
9127
9128 l_in_material_detail_rec := p_material_detail_rec;
9129 l_in_material_detail_rec.batch_id := l_batch_id;
9130 l_in_material_detail_rec.material_detail_id := l_matl_dtl_id;
9131
9132 /* Retrieve Batch Header and Material Detail Record */
9133 gme_common_pvt.Validate_material_detail
9134 (p_material_detail_rec => l_in_material_detail_rec
9135 ,p_org_code => p_org_code
9136 ,p_batch_no => p_batch_header_rec.batch_no
9137 ,p_batch_type => gme_common_pvt.g_doc_type_batch
9138 ,x_batch_header_rec => l_batch_header_rec
9139 ,x_material_detail_rec => l_material_detail_rec
9140 ,x_message_count => x_message_count
9141 ,x_message_list => x_message_list
9142 ,x_return_status => x_return_status );
9143 IF x_return_status <> fnd_api.g_ret_sts_success THEN
9144 IF (g_debug = gme_debug.g_log_statement) THEN
9145 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
9146 || ': batch mateiral validate error ');
9147 END IF;
9148 RAISE fnd_api.g_exc_error;
9149 END IF;
9150 END IF;
9151 -- Validations
9152 gme_pending_product_lots_pvt.validate_material_for_delete
9153 (p_batch_header_rec => l_batch_header_rec
9154 ,p_material_detail_rec => l_material_detail_rec
9155 ,x_return_status => x_return_status);
9156
9157 IF x_return_status <> fnd_api.g_ret_sts_success THEN
9158 RAISE fnd_api.g_exc_error;
9159 END IF;
9160
9161 gme_pending_product_lots_pvt.validate_record_for_delete
9162 (p_material_detail_rec => l_material_detail_rec
9163 ,p_db_pending_product_lots_rec => l_db_pending_product_lots_rec
9164 ,p_pending_product_lots_rec => p_pending_product_lots_rec
9165 ,x_pending_product_lots_rec => l_pending_product_lots_rec
9166 ,x_return_status => x_return_status);
9167
9168 IF x_return_status <> fnd_api.g_ret_sts_success THEN
9169 RAISE fnd_api.g_exc_error;
9170 END IF;
9171
9172 /* Invoke main */
9173 gme_api_main.delete_pending_product_lot
9174 (p_validation_level => p_validation_level
9175 ,p_init_msg_list => fnd_api.g_false
9176 ,x_message_count => x_message_count
9177 ,x_message_list => x_message_list
9178 ,x_return_status => x_return_status
9179 ,p_org_id => l_batch_header_rec.organization_id
9180 ,p_pending_product_lots_rec => l_pending_product_lots_rec);
9181
9182
9183 IF g_debug <= gme_debug.g_log_statement THEN
9184 gme_debug.put_line
9185 ( g_pkg_name
9186 || '.'
9187 || l_api_name
9188 || ' Return status from gme_api_main.delete_pending_product_lot is '
9189 || x_return_status);
9190 END IF;
9191
9192 IF x_return_status <> fnd_api.g_ret_sts_success THEN
9193 RAISE error_delete_pp_lot;
9194 END IF;
9195
9196 /* Invoke save_batch */
9197 IF g_debug <= gme_debug.g_log_statement THEN
9198 gme_debug.put_line
9199 ( g_pkg_name
9200 || '.'
9201 || l_api_name
9202 || ' About to invoke save_batch with header_id of '
9203 || gme_common_pvt.g_transaction_header_id);
9204 END IF;
9205
9206 gme_api_pub.save_batch
9207 (p_header_id => gme_common_pvt.g_transaction_header_id
9208 ,p_table => 1
9209 ,p_commit => p_commit
9210 ,x_return_status => x_return_status);
9211
9212 IF g_debug <= gme_debug.g_log_statement THEN
9213 gme_debug.put_line
9214 ( g_pkg_name
9215 || '.'
9216 || l_api_name
9217 || ' Return status from gme_api_pub.save_batch is '
9218 || x_return_status);
9219 END IF;
9220
9221 IF x_return_status <> fnd_api.g_ret_sts_success THEN
9222 RAISE fnd_api.g_exc_error;
9223 END IF;
9224
9225 IF g_debug <= gme_debug.g_log_procedure THEN
9226 gme_debug.put_line ( ' Completed '
9227 || l_api_name
9228 || ' at '
9229 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
9230 END IF;
9231
9232 EXCEPTION
9233 WHEN error_delete_pp_lot THEN
9234 ROLLBACK TO SAVEPOINT delete_pending_product_lot;
9235 gme_common_pvt.count_and_get (x_count => x_message_count
9236 ,p_encoded => fnd_api.g_false
9237 ,x_data => x_message_list);
9238 WHEN fnd_api.g_exc_error THEN
9239 ROLLBACK TO SAVEPOINT delete_pending_product_lot;
9240 x_return_status := fnd_api.g_ret_sts_error;
9241 gme_common_pvt.count_and_get (x_count => x_message_count
9242 ,p_encoded => fnd_api.g_false
9243 ,x_data => x_message_list);
9244 WHEN OTHERS THEN
9245 ROLLBACK TO SAVEPOINT delete_pending_product_lot;
9246 gme_when_others ( p_api_name => l_api_name
9247 ,x_message_count => x_message_count
9248 ,x_message_list => x_message_list
9249 ,x_return_status => x_return_status );
9250 END delete_pending_product_lot;
9251
9252 /*================================================================================
9253 Procedure
9254 unrelease_batch
9255 Description
9256 This procedure is used to unrelease a WIP batch.
9257 One of the following key sequences must be specified:
9258 batch_id OR
9259 batch_no, org_code batch_type assumed to be batch
9260
9261 Parameters
9262 p_batch_id (O) batch ID to identify the batch
9263 p_batch_no (O) batch number to identify the batch in combination with p_org_code
9264 p_org_code (O) organization code to identigy the batch is combination with p_batch_no
9265 p_create_resv_pend_lots (R) indicates whether to create reservations or pending product lots
9266 depending on the line type.
9267 x_batch_header_rec Output batch header record after unrelease
9268 x_return_status outcome of the API call
9269 S - Success
9270 E - Error
9271 U - Unexpected Error
9272 ================================================================================*/
9273 PROCEDURE unrelease_batch
9274 (p_api_version IN NUMBER
9275 ,p_validation_level IN NUMBER
9276 := gme_common_pvt.g_max_errors
9277 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
9278 ,p_commit IN VARCHAR2 := fnd_api.g_false
9279 ,x_message_count OUT NOCOPY NUMBER
9280 ,x_message_list OUT NOCOPY VARCHAR2
9281 ,x_return_status OUT NOCOPY VARCHAR2
9282 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
9283 ,p_org_code IN VARCHAR2
9284 ,p_create_resv_pend_lots IN NUMBER
9285 ,x_batch_header_rec OUT NOCOPY gme_batch_header%ROWTYPE)
9286 IS
9287 l_api_name CONSTANT VARCHAR2 (30) := 'UNRELEASE_BATCH';
9288
9289 l_in_batch_header_rec gme_batch_header%ROWTYPE;
9290 l_batch_header_rec gme_batch_header%ROWTYPE;
9291
9292 error_unrelease_batch EXCEPTION;
9293 BEGIN
9294 IF (g_debug <> -1) THEN
9295 gme_debug.log_initialize ('UnreleaseBatch');
9296 END IF;
9297
9298 IF g_debug <= gme_debug.g_log_procedure THEN
9299 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
9300 || l_api_name);
9301 END IF;
9302
9303 /* Set the return status to success initially */
9304 x_return_status := fnd_api.g_ret_sts_success;
9305
9306 /* Set savepoint here */
9307 SAVEPOINT unrelease_batch;
9308
9309 IF p_init_msg_list = fnd_api.g_true THEN
9310 fnd_msg_pub.initialize;
9311 END IF;
9312
9313 IF NOT fnd_api.compatible_api_call (2.0
9314 ,p_api_version
9315 ,'unrelease_batch'
9316 ,g_pkg_name) THEN
9317 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
9318 RAISE fnd_api.g_exc_error;
9319 END IF;
9320
9321
9322 --l_in_batch_header_rec.batch_type := gme_common_pvt.g_doc_type_batch;
9323 gme_common_pvt.validate_batch
9324 (p_batch_header_rec => p_batch_header_rec
9325 ,p_org_code => p_org_code
9326 ,p_batch_type => nvl(p_batch_header_rec.batch_type,gme_common_pvt.g_doc_type_batch)
9327 ,x_batch_header_rec => l_batch_header_rec
9328 ,x_message_count => x_message_count
9329 ,x_message_list => x_message_list
9330 ,x_return_status => x_return_status );
9331
9332 IF x_return_status <> fnd_api.g_ret_sts_success THEN
9333 IF (g_debug = gme_debug.g_log_statement) THEN
9334 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
9335 || ': batch validate error ');
9336 END IF;
9337 RAISE fnd_api.g_exc_error;
9338 END IF;
9339
9340
9341 -- Validations
9342 gme_unrelease_batch_pvt.validate_batch_for_unrelease
9343 (p_batch_hdr_rec => l_batch_header_rec
9344 ,x_return_status => x_return_status);
9345
9346 IF x_return_status <> fnd_api.g_ret_sts_success THEN
9347 RAISE fnd_api.g_exc_error;
9348 END IF;
9349
9350 gme_common_pvt.g_move_to_temp := fnd_api.g_false;
9351
9352 /* Invoke main */
9353 gme_api_main.unrelease_batch
9354 (p_validation_level => p_validation_level
9355 ,p_init_msg_list => fnd_api.g_false
9356 ,x_message_count => x_message_count
9357 ,x_message_list => x_message_list
9358 ,x_return_status => x_return_status
9359 ,p_batch_header_rec => l_batch_header_rec
9360 ,x_batch_header_rec => x_batch_header_rec
9361 ,p_create_resv_pend_lots => p_create_resv_pend_lots);
9362
9363 IF g_debug <= gme_debug.g_log_statement THEN
9364 gme_debug.put_line ( g_pkg_name || '.' || l_api_name ||
9365 ' Return status from main.unrelease_batch is '|| x_return_status);
9366 END IF;
9367
9368 IF x_return_status <> fnd_api.g_ret_sts_success THEN
9369 RAISE error_unrelease_batch;
9370 END IF;
9371
9372 /* Invoke save_batch */
9373 gme_api_pub.save_batch
9374 (p_header_id => gme_common_pvt.g_transaction_header_id
9375 ,p_table => 1
9376 ,p_commit => p_commit
9377 ,x_return_status => x_return_status);
9378
9379 IF g_debug <= gme_debug.g_log_statement THEN
9380 gme_debug.put_line ( g_pkg_name || '.' || l_api_name ||
9381 ' Return status from gme_api_pub.save_batch is '
9382 || x_return_status);
9383 END IF;
9384
9385 IF x_return_status <> fnd_api.g_ret_sts_success THEN
9386 RAISE fnd_api.g_exc_error;
9387 END IF;
9388
9389 IF g_debug <= gme_debug.g_log_procedure THEN
9390 gme_debug.put_line ( ' Completed ' || l_api_name || ' at '
9391 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
9392 END IF;
9393
9394 EXCEPTION
9395 WHEN error_unrelease_batch THEN
9396 ROLLBACK TO SAVEPOINT unrelease_batch;
9397 x_batch_header_rec := NULL;
9398 gme_common_pvt.count_and_get (x_count => x_message_count
9399 ,p_encoded => fnd_api.g_false
9400 ,x_data => x_message_list);
9401 WHEN fnd_api.g_exc_error THEN
9402 ROLLBACK TO SAVEPOINT unrelease_batch;
9403 x_batch_header_rec := NULL;
9404 x_return_status := fnd_api.g_ret_sts_error;
9405 gme_common_pvt.count_and_get (x_count => x_message_count
9406 ,p_encoded => fnd_api.g_false
9407 ,x_data => x_message_list);
9408 WHEN OTHERS THEN
9409 ROLLBACK TO SAVEPOINT unrelease_batch;
9410 x_batch_header_rec := NULL;
9411 gme_when_others ( p_api_name => l_api_name
9412 ,x_message_count => x_message_count
9413 ,x_message_list => x_message_list
9414 ,x_return_status => x_return_status );
9415 END unrelease_batch;
9416
9417 /*================================================================================
9418 Procedure
9419 unrelease_step
9420 Description
9421 This procedure is used to unrelease a WIP step.
9422 One of the following key sequences must be specified:
9423 batchstep_id OR
9424 batch_id, batchstep_no OR
9425 batch_no, org_code, batchstep_no batch_type assumed to be batch
9426
9427 Parameters
9428 p_batchstep_id (O) batch step ID to identify the step
9429 p_batch_id (O) batch ID to identify the step
9430 p_batchstep_no (O) step number to identify the step
9431 p_batch_no (O) batch number to identify the step
9432 p_org_code (O) organization code to identify the step
9433 p_create_resv_pend_lots (R) indicates whether to create reservations or pending product lots
9434 depending on the line type associated to the step.
9435 x_batch_step_rec Output step record after unrelease
9436 x_return_status outcome of the API call
9437 S - Success
9438 E - Error
9439 U - Unexpected Error
9440 ================================================================================*/
9441 PROCEDURE unrelease_step
9442 (p_api_version IN NUMBER
9443 ,p_validation_level IN NUMBER
9444 := gme_common_pvt.g_max_errors
9445 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
9446 ,p_commit IN VARCHAR2 := fnd_api.g_false
9447 ,x_message_count OUT NOCOPY NUMBER
9448 ,x_message_list OUT NOCOPY VARCHAR2
9449 ,x_return_status OUT NOCOPY VARCHAR2
9450 ,p_batch_step_rec IN gme_batch_steps%ROWTYPE
9451 ,p_batch_no IN VARCHAR2
9452 ,p_org_code IN VARCHAR2
9453 ,p_create_resv_pend_lots IN NUMBER
9454 ,x_batch_step_rec OUT NOCOPY gme_batch_steps%ROWTYPE)
9455 IS
9456 l_api_name CONSTANT VARCHAR2 (30) := 'UNRELEASE_STEP';
9457
9458 l_in_batch_step_rec gme_batch_steps%ROWTYPE;
9459 l_batch_step_rec gme_batch_steps%ROWTYPE;
9460 l_in_batch_header_rec gme_batch_header%ROWTYPE;
9461 l_batch_header_rec gme_batch_header%ROWTYPE;
9462
9463 error_unrelease_step EXCEPTION;
9464 BEGIN
9465 IF (g_debug <> -1) THEN
9466 gme_debug.log_initialize ('UnreleaseStep');
9467 END IF;
9468
9469 IF g_debug <= gme_debug.g_log_procedure THEN
9470 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
9471 || l_api_name);
9472 END IF;
9473
9474 /* Set the return status to success initially */
9475 x_return_status := fnd_api.g_ret_sts_success;
9476
9477 /* Set savepoint here */
9478 SAVEPOINT unrelease_step;
9479
9480 IF p_init_msg_list = fnd_api.g_true THEN
9481 fnd_msg_pub.initialize;
9482 END IF;
9483
9484 IF NOT fnd_api.compatible_api_call (2.0
9485 ,p_api_version
9486 ,'unrelease_step'
9487 ,g_pkg_name) THEN
9488 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
9489 RAISE fnd_api.g_exc_error;
9490 END IF;
9491
9492 /* Validate Input parameters */
9493 gme_common_pvt.Validate_batch_step (
9494 p_batch_step_rec => p_batch_step_rec
9495 ,p_org_code => p_org_code
9496 ,p_batch_no => p_batch_no
9497 ,x_batch_step_rec => l_batch_step_rec
9498 ,x_batch_header_rec => l_batch_header_rec
9499 ,x_message_count => x_message_count
9500 ,x_message_list => x_message_list
9501 ,x_return_status => x_return_status) ;
9502
9503 IF x_return_status <> fnd_api.g_ret_sts_success THEN
9504 IF (g_debug = gme_debug.g_log_statement) THEN
9505 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
9506 || ': batch step validate error ');
9507 END IF;
9508 RAISE fnd_api.g_exc_error;
9509 END IF;
9510
9511 -- Validations
9512 gme_unrelease_step_pvt.validate_step_for_unrelease
9513 (p_batch_hdr_rec => l_batch_header_rec
9514 ,p_batch_step_rec => l_batch_step_rec
9515 ,x_return_status => x_return_status);
9516
9517 IF x_return_status <> fnd_api.g_ret_sts_success THEN
9518 RAISE fnd_api.g_exc_error;
9519 END IF;
9520
9521 gme_common_pvt.g_move_to_temp := fnd_api.g_false;
9522
9523 /* Invoke main */
9524 gme_api_main.unrelease_step
9525 (p_validation_level => p_validation_level
9526 ,p_init_msg_list => fnd_api.g_false
9527 ,x_message_count => x_message_count
9528 ,x_message_list => x_message_list
9529 ,x_return_status => x_return_status
9530 ,p_batch_step_rec => l_batch_step_rec
9531 ,p_batch_header_rec => l_batch_header_rec
9532 ,x_batch_step_rec => x_batch_step_rec
9533 ,p_create_resv_pend_lots => p_create_resv_pend_lots);
9534
9535 IF g_debug <= gme_debug.g_log_statement THEN
9536 gme_debug.put_line
9537 ( g_pkg_name
9538 || '.'
9539 || l_api_name
9540 || ' Return status from gme_api_main.unrelease_step is '
9541 || x_return_status);
9542 END IF;
9543
9544 IF x_return_status <> fnd_api.g_ret_sts_success THEN
9545 RAISE error_unrelease_step;
9546 END IF;
9547
9548 /* Invoke save_batch */
9549 IF g_debug <= gme_debug.g_log_statement THEN
9550 gme_debug.put_line
9551 ( g_pkg_name
9552 || '.'
9553 || l_api_name
9554 || ' About to invoke save_batch with header_id of '
9555 || gme_common_pvt.g_transaction_header_id);
9556 END IF;
9557
9558 gme_api_pub.save_batch
9559 (p_header_id => gme_common_pvt.g_transaction_header_id
9560 ,p_table => 1
9561 ,p_commit => p_commit
9562 ,x_return_status => x_return_status);
9563
9564 IF g_debug <= gme_debug.g_log_statement THEN
9565 gme_debug.put_line
9566 ( g_pkg_name
9567 || '.'
9568 || l_api_name
9569 || ' Return status from gme_api_pub.save_batch is '
9570 || x_return_status);
9571 END IF;
9572
9573 IF x_return_status <> fnd_api.g_ret_sts_success THEN
9574 RAISE fnd_api.g_exc_error;
9575 END IF;
9576
9577 IF g_debug <= gme_debug.g_log_procedure THEN
9578 gme_debug.put_line ( ' Completed '
9579 || l_api_name
9580 || ' at '
9581 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
9582 END IF;
9583
9584 EXCEPTION
9585 WHEN error_unrelease_step THEN
9586 ROLLBACK TO SAVEPOINT unrelease_step;
9587 x_batch_step_rec := NULL;
9588 gme_common_pvt.count_and_get (x_count => x_message_count
9589 ,p_encoded => fnd_api.g_false
9590 ,x_data => x_message_list);
9591 WHEN fnd_api.g_exc_error THEN
9592 ROLLBACK TO SAVEPOINT unrelease_step;
9593 x_batch_step_rec := NULL;
9594 x_return_status := fnd_api.g_ret_sts_error;
9595 gme_common_pvt.count_and_get (x_count => x_message_count
9596 ,p_encoded => fnd_api.g_false
9597 ,x_data => x_message_list);
9598 WHEN OTHERS THEN
9599 ROLLBACK TO SAVEPOINT unrelease_step;
9600 x_batch_step_rec := NULL;
9601 gme_when_others ( p_api_name => l_api_name
9602 ,x_message_count => x_message_count
9603 ,x_message_list => x_message_list
9604 ,x_return_status => x_return_status );
9605 END unrelease_step;
9606
9607 /*================================================================================
9608 Procedure
9609 complete_batch
9610 Description
9611 This procedure is used to complete a batch
9612 One of the following key sequences must be specified:
9613 batch_id OR
9614 batch_no, org_code, batch_type assumed to be batch
9615
9616 Parameters
9617 p_batch_header_rec (O) batch header to identify the batch to complete;
9618 p_org_code (O) organization code to identify the batch is conjunction with batch_no in p_batch_header_rec
9619 p_ignore_exception (O) indicates whether to ignore exceptions; if exceptions are ignored,
9620 x_exception_material_tbl won't be populated even if exceptions were found
9621 p_validate_flexfields (O) indicates whether to validate flexfields... Defaults to fnd_api.g_false;
9622 this is used for direct completion only because of release batch
9623 x_batch_header_rec Output batch header record after complete
9624 x_exception_material_tbl Batch exceptions found in complete batch
9625 x_return_status outcome of the API call
9626 S - Success
9627 E - Error
9628 U - Unexpected Error
9629 X - Batch Exception
9630 ================================================================================*/
9631 PROCEDURE complete_batch
9632 (p_api_version IN NUMBER
9633 ,p_validation_level IN NUMBER
9634 := gme_common_pvt.g_max_errors
9635 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
9636 ,p_commit IN VARCHAR2 := fnd_api.g_false
9637 ,x_message_count OUT NOCOPY NUMBER
9638 ,x_message_list OUT NOCOPY VARCHAR2
9639 ,x_return_status OUT NOCOPY VARCHAR2
9640 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
9641 ,p_org_code IN VARCHAR2
9642 ,p_ignore_exception IN VARCHAR2 := fnd_api.g_false
9643 ,p_validate_flexfields IN VARCHAR2 := fnd_api.g_false
9644 ,x_batch_header_rec OUT NOCOPY gme_batch_header%ROWTYPE
9645 ,x_exception_material_tbl OUT NOCOPY gme_common_pvt.exceptions_tab)
9646 IS
9647 l_api_name CONSTANT VARCHAR2 (30) := 'COMPLETE_BATCH';
9648
9649 l_in_batch_header_rec gme_batch_header%ROWTYPE;
9650 l_batch_header_rec gme_batch_header%ROWTYPE;
9651 l_exception_material_tbl gme_common_pvt.exceptions_tab;
9652
9653 error_complete_batch EXCEPTION;
9654 BEGIN
9655 IF (g_debug <> -1) THEN
9656 gme_debug.log_initialize ('CompleteBatch');
9657 END IF;
9658
9659 IF g_debug <= gme_debug.g_log_procedure THEN
9660 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
9661 || l_api_name);
9662 END IF;
9663
9664 /* Set the return status to success initially */
9665 x_return_status := fnd_api.g_ret_sts_success;
9666
9667 /* Set savepoint here */
9668 SAVEPOINT complete_batch;
9669
9670 IF p_init_msg_list = fnd_api.g_true THEN
9671 fnd_msg_pub.initialize;
9672 END IF;
9673
9674 IF NOT fnd_api.compatible_api_call (2.0
9675 ,p_api_version
9676 ,'complete_batch'
9677 ,g_pkg_name) THEN
9678 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
9679 RAISE fnd_api.g_exc_error;
9680 END IF;
9681
9682
9683 --l_in_batch_header_rec.batch_type := gme_common_pvt.g_doc_type_batch;
9684 gme_common_pvt.validate_batch
9685 (p_batch_header_rec => p_batch_header_rec
9686 ,p_org_code => p_org_code
9687 ,p_batch_type => nvl(p_batch_header_rec.batch_type,gme_common_pvt.g_doc_type_batch)
9688 ,x_batch_header_rec => l_batch_header_rec
9689 ,x_message_count => x_message_count
9690 ,x_message_list => x_message_list
9691 ,x_return_status => x_return_status );
9692
9693 IF x_return_status <> fnd_api.g_ret_sts_success THEN
9694 IF (g_debug = gme_debug.g_log_statement) THEN
9695 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
9696 || ': batch validate error ');
9697 END IF;
9698 RAISE fnd_api.g_exc_error;
9699 END IF;
9700
9701 -- Validations
9702 IF l_batch_header_rec.batch_status = gme_common_pvt.g_batch_pending THEN
9703 IF p_validate_flexfields = fnd_api.g_true THEN
9704 gme_common_pvt.g_flex_validate_prof := 1;
9705 ELSE
9706 gme_common_pvt.g_flex_validate_prof := 0;
9707 END IF;
9708
9709 l_in_batch_header_rec := l_batch_header_rec;
9710 l_in_batch_header_rec.actual_start_date := p_batch_header_rec.actual_start_date;
9711 -- call release batch validation... output batch header will have actual start date filled in
9712 NULL;
9713
9714 IF x_return_status <> fnd_api.g_ret_sts_success THEN
9715 RAISE fnd_api.g_exc_error;
9716 END IF;
9717
9718 -- reset flex global
9719 gme_common_pvt.g_flex_validate_prof := 0;
9720 END IF;
9721
9722 l_in_batch_header_rec := l_batch_header_rec;
9723 -- Bug 6828656
9724 -- Reassign actual_start_date
9725 l_in_batch_header_rec.actual_start_date := p_batch_header_rec.actual_start_date;
9726 l_in_batch_header_rec.actual_cmplt_date := p_batch_header_rec.actual_cmplt_date;
9727 -- output batch header contains the actual complete date
9728 gme_complete_batch_pvt.validate_batch_for_complete
9729 (p_batch_header_rec => l_in_batch_header_rec
9730 ,x_batch_header_rec => l_batch_header_rec
9731 ,x_return_status => x_return_status);
9732
9733 IF x_return_status <> fnd_api.g_ret_sts_success THEN
9734 RAISE fnd_api.g_exc_error;
9735 END IF;
9736
9737 gme_common_pvt.g_move_to_temp := fnd_api.g_false;
9738
9739 /* Invoke main */
9740 gme_api_main.complete_batch
9741 (p_validation_level => p_validation_level
9742 ,p_init_msg_list => fnd_api.g_false
9743 ,x_message_count => x_message_count
9744 ,x_message_list => x_message_list
9745 ,x_return_status => x_return_status
9746 ,p_batch_header_rec => l_batch_header_rec
9747 ,x_batch_header_rec => x_batch_header_rec
9748 ,x_exception_material_tbl => l_exception_material_tbl
9749 ,p_ignore_exception => p_ignore_exception); --Bug#5186328
9750
9751 IF g_debug <= gme_debug.g_log_statement THEN
9752 gme_debug.put_line
9753 ( g_pkg_name
9754 || '.'
9755 || l_api_name
9756 || ' Return status from gme_api_main.complete_batch is '
9757 || x_return_status);
9758 END IF;
9759
9760 IF p_ignore_exception = fnd_api.g_true AND x_return_status = gme_common_pvt.g_exceptions_err THEN
9761 x_return_status := fnd_api.g_ret_sts_success;
9762 ELSIF x_return_status = gme_common_pvt.g_exceptions_err THEN
9763 x_exception_material_tbl := l_exception_material_tbl;
9764 END IF;
9765
9766 IF x_return_status <> fnd_api.g_ret_sts_success THEN
9767 RAISE error_complete_batch;
9768 END IF;
9769
9770 /* Invoke save_batch */
9771 IF g_debug <= gme_debug.g_log_statement THEN
9772 gme_debug.put_line
9773 ( g_pkg_name
9774 || '.'
9775 || l_api_name
9776 || ' About to invoke save_batch with header_id of '
9777 || gme_common_pvt.g_transaction_header_id);
9778 END IF;
9779
9780 gme_api_pub.save_batch
9781 (p_header_id => gme_common_pvt.g_transaction_header_id
9782 ,p_table => 1
9783 ,p_commit => p_commit
9784 ,x_return_status => x_return_status);
9785
9786 IF g_debug <= gme_debug.g_log_statement THEN
9787 gme_debug.put_line
9788 ( g_pkg_name
9789 || '.'
9790 || l_api_name
9791 || ' Return status from gme_api_pub.save_batch is '
9792 || x_return_status);
9793 END IF;
9794
9795 IF x_return_status <> fnd_api.g_ret_sts_success THEN
9796 RAISE fnd_api.g_exc_error;
9797 END IF;
9798
9799 IF g_debug <= gme_debug.g_log_procedure THEN
9800 gme_debug.put_line ( ' Completed '
9801 || l_api_name
9802 || ' at '
9803 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
9804 END IF;
9805
9806 EXCEPTION
9807 WHEN error_complete_batch THEN
9808 ROLLBACK TO SAVEPOINT complete_batch;
9809 x_batch_header_rec := NULL;
9810 gme_common_pvt.count_and_get (x_count => x_message_count
9811 ,p_encoded => fnd_api.g_false
9812 ,x_data => x_message_list);
9813 WHEN fnd_api.g_exc_error THEN
9814 ROLLBACK TO SAVEPOINT complete_batch;
9815 x_batch_header_rec := NULL;
9816 x_return_status := fnd_api.g_ret_sts_error;
9817 gme_common_pvt.count_and_get (x_count => x_message_count
9818 ,p_encoded => fnd_api.g_false
9819 ,x_data => x_message_list);
9820 WHEN OTHERS THEN
9821 ROLLBACK TO SAVEPOINT complete_batch;
9822 gme_when_others ( p_api_name => l_api_name
9823 ,x_message_count => x_message_count
9824 ,x_message_list => x_message_list
9825 ,x_return_status => x_return_status );
9826 END complete_batch;
9827
9828 /*================================================================================
9829 Procedure
9830 complete_step
9831 Description
9832 This procedure is used to complete a step
9833 One of the following key sequences must be specified:
9834 batchstep_id
9835 batch_id, batchstep_no OR
9836 batch_no, org_code, batchstep_no batch_type assumed to be batch
9837
9838 Parameters
9839 p_batch step_rec (O) batch step to identify the step to complete.
9840 p_batch_no (O) batch_no to identify the step
9841 p_org_code (O) organization code to identify the step is conjunction with batch_no in p_batch_header_rec
9842 p_ignore_exception (O) indicates whether to ignore exceptions; if exceptions are ignored,
9843 x_exception_material_tbl won't be populated ever if exceptions were found
9844 p_override_quality (O) Override quality indicator; defaults to fnd_api.g_false
9845 p_validate_flexfields (O) indicates whether to validate flexfields... Defaults to fnd_api.g_false;
9846 this is used for direct step completion (pending_batch) only, because of release batch
9847 x_batch_step_rec Output batch step record after complete
9848 x_exception_material_tbl Material exceptions found in complete step (only those associated to step)
9849 x_return_status outcome of the API call
9850 S - Success
9851 E - Error
9852 U - Unexpected Error
9853 X - Batch Exception
9854 ================================================================================*/
9855 PROCEDURE complete_step
9856 (p_api_version IN NUMBER
9857 ,p_validation_level IN NUMBER
9858 := gme_common_pvt.g_max_errors
9859 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
9860 ,p_commit IN VARCHAR2 := fnd_api.g_false
9861 ,x_message_count OUT NOCOPY NUMBER
9862 ,x_message_list OUT NOCOPY VARCHAR2
9863 ,x_return_status OUT NOCOPY VARCHAR2
9864 ,p_batch_step_rec IN gme_batch_steps%ROWTYPE
9865 ,p_batch_no IN VARCHAR2
9866 ,p_org_code IN VARCHAR2
9867 ,p_ignore_exception IN VARCHAR2 := fnd_api.g_false
9868 ,p_override_quality IN VARCHAR2 := fnd_api.g_false
9869 ,p_validate_flexfields IN VARCHAR2 := fnd_api.g_false
9870 ,x_batch_step_rec OUT NOCOPY gme_batch_steps%ROWTYPE
9871 ,x_exception_material_tbl OUT NOCOPY gme_common_pvt.exceptions_tab)
9872 IS
9873 l_api_name CONSTANT VARCHAR2 (30) := 'COMPLETE_STEP';
9874
9875 l_in_batch_step_rec gme_batch_steps%ROWTYPE;
9876 l_batch_step_rec gme_batch_steps%ROWTYPE;
9877 l_in_batch_header_rec gme_batch_header%ROWTYPE;
9878 l_batch_header_rec gme_batch_header%ROWTYPE;
9879 l_calc_batch_start_date DATE;
9880
9881 l_exception_material_tbl gme_common_pvt.exceptions_tab;
9882
9883 error_complete_step EXCEPTION;
9884 BEGIN
9885 IF (g_debug <> -1) THEN
9886 gme_debug.log_initialize ('CompleteStep');
9887 END IF;
9888
9889 IF g_debug <= gme_debug.g_log_procedure THEN
9890 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
9891 || l_api_name);
9892 END IF;
9893
9894 /* Set the return status to success initially */
9895 x_return_status := fnd_api.g_ret_sts_success;
9896
9897 /* Set savepoint here */
9898 SAVEPOINT complete_step;
9899
9900 IF p_init_msg_list = fnd_api.g_true THEN
9901 fnd_msg_pub.initialize;
9902 END IF;
9903
9904 IF NOT fnd_api.compatible_api_call (2.0
9905 ,p_api_version
9906 ,'complete_step'
9907 ,g_pkg_name) THEN
9908 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
9909 RAISE fnd_api.g_exc_error;
9910 END IF;
9911
9912 /* Validate Input parameters */
9913 gme_common_pvt.Validate_batch_step (
9914 p_batch_step_rec => p_batch_step_rec
9915 ,p_org_code => p_org_code
9916 ,p_batch_no => p_batch_no
9917 ,x_batch_step_rec => l_batch_step_rec
9918 ,x_batch_header_rec => l_batch_header_rec
9919 ,x_message_count => x_message_count
9920 ,x_message_list => x_message_list
9921 ,x_return_status => x_return_status) ;
9922
9923 IF x_return_status <> fnd_api.g_ret_sts_success THEN
9924 IF (g_debug = gme_debug.g_log_statement) THEN
9925 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
9926 || ': batch step validate error ');
9927 END IF;
9928 RAISE fnd_api.g_exc_error;
9929 END IF;
9930 -- Validations
9931
9932 IF l_batch_header_rec.batch_type = gme_common_pvt.g_doc_type_fpo THEN
9933 gme_common_pvt.log_message('GME_API_INVALID_BATCH_TYPE');
9934 RAISE fnd_api.g_exc_error;
9935 END IF;
9936
9937 -- current Step Status must be Pending or WIP
9938 IF (l_batch_step_rec.step_status NOT IN (gme_common_pvt.g_step_pending, gme_common_pvt.g_step_WIP)) THEN
9939 gme_common_pvt.log_message('GME_API_INV_STAT_STEP_CERT');
9940 RAISE fnd_api.g_exc_error;
9941 END IF;
9942
9943 IF l_batch_header_rec.batch_status NOT IN
9944 (gme_common_pvt.g_batch_pending, gme_common_pvt.g_batch_wip) THEN
9945 gme_common_pvt.log_message ('GME_API_INV_BATCH_CERT_STEP');
9946 RAISE fnd_api.g_exc_error;
9947 END IF;
9948
9949 --Bug#5109119 checking for parameter value 1 instead of Y
9950 IF l_batch_header_rec.batch_status = gme_common_pvt.g_batch_pending AND
9951 (gme_common_pvt.g_step_controls_batch_sts_ind <> 1 OR
9952 l_batch_header_rec.parentline_id IS NOT NULL) THEN
9953 gme_common_pvt.log_message ('GME_API_INV_BATCH_CMPL_STEP');
9954 RAISE fnd_api.g_exc_error;
9955 END IF;
9956
9957 l_in_batch_step_rec := l_batch_step_rec;
9958 l_in_batch_step_rec.actual_cmplt_date := p_batch_step_rec.actual_cmplt_date;
9959 -- output step contains the actual complete date
9960 gme_complete_batch_step_pvt.validate_step_for_complete
9961 (p_batch_header_rec => l_batch_header_rec
9962 ,p_batch_step_rec => l_in_batch_step_rec
9963 ,p_override_quality => p_override_quality
9964 ,x_batch_step_rec => l_batch_step_rec
9965 ,x_return_status => x_return_status);
9966
9967 IF x_return_status <> fnd_api.g_ret_sts_success THEN
9968 RAISE fnd_api.g_exc_error;
9969 END IF;
9970
9971 IF l_batch_step_rec.step_status = gme_common_pvt.g_step_pending THEN
9972 -- call release step validation; use step actual cmplt date
9973 -- if step actual start date is NULL and batch is Pending
9974 NULL;
9975 END IF; -- IF l_batch_step_rec.step_status = gme_common_pvt.g_step_pending
9976
9977 gme_complete_batch_step_pvt.validate_step_cmplt_date
9978 (p_batch_step_rec => l_batch_step_rec
9979 ,p_batch_header_rec => l_batch_header_rec
9980 ,x_batch_start_date => l_calc_batch_start_date
9981 ,x_return_status => x_return_status);
9982
9983 IF (x_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9984 RAISE fnd_api.g_exc_error;
9985 END IF;
9986
9987 -- needed for release batch AND/OR release step (release step is in private to take care of dependent steps)
9988 IF p_validate_flexfields = fnd_api.g_true THEN
9989 gme_common_pvt.g_flex_validate_prof := 1;
9990 ELSE
9991 gme_common_pvt.g_flex_validate_prof := 0;
9992 END IF;
9993
9994 IF l_batch_header_rec.batch_status = gme_common_pvt.g_batch_pending THEN
9995 l_in_batch_header_rec := l_batch_header_rec;
9996 l_in_batch_header_rec.actual_start_date := l_calc_batch_start_date;
9997 -- call release batch validation...
9998 NULL;
9999
10000 IF x_return_status <> fnd_api.g_ret_sts_success THEN
10001 RAISE fnd_api.g_exc_error;
10002 END IF;
10003 END IF;
10004
10005 gme_common_pvt.g_move_to_temp := fnd_api.g_false;
10006
10007 /* Invoke main */
10008 gme_api_main.complete_step
10009 (p_validation_level => p_validation_level
10010 ,p_init_msg_list => fnd_api.g_false
10011 ,x_message_count => x_message_count
10012 ,x_message_list => x_message_list
10013 ,x_return_status => x_return_status
10014 ,p_batch_step_rec => l_batch_step_rec
10015 ,p_batch_header_rec => l_batch_header_rec
10016 ,x_batch_step_rec => x_batch_step_rec
10017 ,x_exception_material_tbl => l_exception_material_tbl
10018 ,p_ignore_exception => p_ignore_exception); --Bug#5186328
10019
10020 IF g_debug <= gme_debug.g_log_statement THEN
10021 gme_debug.put_line
10022 ( g_pkg_name
10023 || '.'
10024 || l_api_name
10025 || ' Return status from gme_api_main.complete_step is '
10026 || x_return_status);
10027 END IF;
10028
10029 IF p_ignore_exception = fnd_api.g_true AND x_return_status = gme_common_pvt.g_exceptions_err THEN
10030 x_return_status := fnd_api.g_ret_sts_success;
10031 ELSIF x_return_status = gme_common_pvt.g_exceptions_err THEN
10032 x_exception_material_tbl := l_exception_material_tbl;
10033 END IF;
10034
10035 IF x_return_status <> fnd_api.g_ret_sts_success THEN
10036 RAISE error_complete_step;
10037 END IF;
10038 -- reset flex global
10039 gme_common_pvt.g_flex_validate_prof := 0;
10040
10041 /* Invoke save_batch */
10042 gme_api_pub.save_batch
10043 (p_header_id => gme_common_pvt.g_transaction_header_id
10044 ,p_table => 1
10045 ,p_commit => p_commit
10046 ,x_return_status => x_return_status);
10047
10048 IF g_debug <= gme_debug.g_log_statement THEN
10049 gme_debug.put_line
10050 ( g_pkg_name
10051 || '.'
10052 || l_api_name
10053 || ' Return status from gme_api_pub.save_batch is '
10054 || x_return_status);
10055 END IF;
10056
10057 IF x_return_status <> fnd_api.g_ret_sts_success THEN
10058 RAISE fnd_api.g_exc_error;
10059 END IF;
10060
10061 IF g_debug <= gme_debug.g_log_procedure THEN
10062 gme_debug.put_line ( ' Completed '
10063 || l_api_name
10064 || ' at '
10065 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
10066 END IF;
10067 EXCEPTION
10068 WHEN error_complete_step THEN
10069 ROLLBACK TO SAVEPOINT complete_step;
10070 x_batch_step_rec := NULL;
10071 gme_common_pvt.count_and_get (x_count => x_message_count
10072 ,p_encoded => fnd_api.g_false
10073 ,x_data => x_message_list);
10074 WHEN fnd_api.g_exc_error THEN
10075 ROLLBACK TO SAVEPOINT complete_step;
10076 x_batch_step_rec := NULL;
10077 x_return_status := fnd_api.g_ret_sts_error;
10078 gme_common_pvt.count_and_get (x_count => x_message_count
10079 ,p_encoded => fnd_api.g_false
10080 ,x_data => x_message_list);
10081 WHEN OTHERS THEN
10082 ROLLBACK TO SAVEPOINT complete_step;
10083 x_batch_step_rec := NULL;
10084 gme_when_others ( p_api_name => l_api_name
10085 ,x_message_count => x_message_count
10086 ,x_message_list => x_message_list
10087 ,x_return_status => x_return_status );
10088 END complete_step;
10089
10090 /*================================================================================
10091 Procedure
10092 release_batch
10093 Description
10094 This procedure is used to release a batch
10095 One of the following key sequences must be specified:
10096 batch_id OR
10097 batch_no, org_code, batch_type assumed to be batch
10098
10099 Parameters
10100 p_batch_header_rec (O) batch header to identify the batch to release;
10101 p_org_code (O) organization code to identify the batch is conjunction with batch_no in p_batch_header_rec
10102 p_ignore_exception (O) indicates whether to ignore exceptions; if exceptions are ignored,
10103 x_exception_material_tbl won't be populated even if exceptions were found
10104 p_validate_flexfields (O) indicates whether to validate flexfields... Defaults to fnd_api.g_false;
10105 x_batch_header_rec Output batch header record after release
10106 x_exception_material_tbl Batch exceptions found in release batch
10107 x_return_status outcome of the API call
10108 S - Success
10109 E - Error
10110 U - Unexpected Error
10111 X - Batch Exception
10112 ================================================================================*/
10113 PROCEDURE release_batch
10114 (p_api_version IN NUMBER
10115 ,p_validation_level IN NUMBER
10116 := gme_common_pvt.g_max_errors
10117 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
10118 ,p_commit IN VARCHAR2 := fnd_api.g_false
10119 ,x_message_count OUT NOCOPY NUMBER
10120 ,x_message_list OUT NOCOPY VARCHAR2
10121 ,x_return_status OUT NOCOPY VARCHAR2
10122 ,p_batch_header_rec IN gme_batch_header%ROWTYPE
10123 ,p_org_code IN VARCHAR2
10124 ,p_ignore_exception IN VARCHAR2 := fnd_api.g_false
10125 ,p_validate_flexfields IN VARCHAR2 := fnd_api.g_false
10126 ,x_batch_header_rec OUT NOCOPY gme_batch_header%ROWTYPE
10127 ,x_exception_material_tbl OUT NOCOPY gme_common_pvt.exceptions_tab)
10128 IS
10129 l_api_name CONSTANT VARCHAR2 (30) := 'RELEASE_BATCH';
10130
10131 l_in_batch_header_rec gme_batch_header%ROWTYPE;
10132 l_batch_header_rec gme_batch_header%ROWTYPE;
10133 l_exception_material_tbl gme_common_pvt.exceptions_tab;
10134
10135 error_release_batch EXCEPTION;
10136 BEGIN
10137 IF (g_debug <> -1) THEN
10138 gme_debug.log_initialize ('ReleaseBatch');
10139 END IF;
10140
10141 IF g_debug <= gme_debug.g_log_procedure THEN
10142 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
10143 || l_api_name);
10144 END IF;
10145
10146 /* Set the return status to success initially */
10147 x_return_status := fnd_api.g_ret_sts_success;
10148
10149 /* Set savepoint here */
10150 SAVEPOINT release_batch;
10151
10152 IF p_init_msg_list = fnd_api.g_true THEN
10153 fnd_msg_pub.initialize;
10154 END IF;
10155
10156 IF NOT fnd_api.compatible_api_call (2.0
10157 ,p_api_version
10158 ,'release_batch'
10159 ,g_pkg_name) THEN
10160 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
10161 RAISE fnd_api.g_exc_error;
10162 END IF;
10163
10164 gme_common_pvt.validate_batch
10165 (p_batch_header_rec => p_batch_header_rec
10166 ,p_org_code => p_org_code
10167 ,p_batch_type => nvl(p_batch_header_rec.batch_type,gme_common_pvt.g_doc_type_batch)
10168 ,x_batch_header_rec => l_batch_header_rec
10169 ,x_message_count => x_message_count
10170 ,x_message_list => x_message_list
10171 ,x_return_status => x_return_status );
10172
10173 IF x_return_status <> fnd_api.g_ret_sts_success THEN
10174 IF (g_debug = gme_debug.g_log_statement) THEN
10175 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
10176 || ': batch validate error ');
10177 END IF;
10178 RAISE fnd_api.g_exc_error;
10179 END IF;
10180 -- Validations
10181 IF p_validate_flexfields = fnd_api.g_true THEN
10182 gme_common_pvt.g_flex_validate_prof := 1;
10183 ELSE
10184 gme_common_pvt.g_flex_validate_prof := 0;
10185 END IF;
10186
10187 l_in_batch_header_rec := l_batch_header_rec;
10188 l_in_batch_header_rec.actual_start_date := p_batch_header_rec.actual_start_date;
10189 -- call release batch validation...output batch header will have actual start date filled in
10190
10191 gme_release_batch_pvt.validate_batch_for_release (
10192 p_batch_header_rec => l_in_batch_header_rec
10193 ,x_batch_header_rec => l_batch_header_rec
10194 ,x_return_status => x_return_status);
10195
10196 IF x_return_status <> fnd_api.g_ret_sts_success THEN
10197 RAISE fnd_api.g_exc_error;
10198 END IF;
10199
10200 -- reset flex global
10201 gme_common_pvt.g_flex_validate_prof := 0;
10202
10203 gme_common_pvt.g_move_to_temp := fnd_api.g_false;
10204 IF g_debug <= gme_debug.g_log_statement THEN
10205 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
10206 || 'batch_id '||l_batch_header_rec.batch_id);
10207 END IF;
10208 /* Invoke main */
10209 gme_api_main.release_batch
10210 (p_validation_level => p_validation_level
10211 ,p_init_msg_list => fnd_api.g_false
10212 ,x_message_count => x_message_count
10213 ,x_message_list => x_message_list
10214 ,x_return_status => x_return_status
10215 ,p_batch_header_rec => l_batch_header_rec
10216 ,p_ignore_exception => p_ignore_exception --Bug#5186328
10217 ,x_batch_header_rec => x_batch_header_rec
10218 ,x_exception_material_tbl => l_exception_material_tbl);
10219
10220 IF g_debug <= gme_debug.g_log_statement THEN
10221 gme_debug.put_line ( g_pkg_name || '.' || l_api_name ||
10222 ' Return status from gme_api_main.release_batch is '
10223 || x_return_status);
10224 END IF;
10225
10226 IF p_ignore_exception = fnd_api.g_true AND x_return_status = gme_common_pvt.g_exceptions_err THEN
10227 x_return_status := fnd_api.g_ret_sts_success;
10228 ELSIF x_return_status = gme_common_pvt.g_exceptions_err THEN
10229 x_exception_material_tbl := l_exception_material_tbl;
10230 END IF;
10231
10232 IF x_return_status <> fnd_api.g_ret_sts_success THEN
10233 RAISE error_release_batch;
10234 END IF;
10235
10236 /* Invoke save_batch */
10237 IF g_debug <= gme_debug.g_log_statement THEN
10238 gme_debug.put_line ( g_pkg_name || '.' || l_api_name || ' About to
10239 invoke save_batch with header_id of ' || gme_common_pvt.g_transaction_header_id);
10240 END IF;
10241
10242 gme_api_pub.save_batch
10243 (p_header_id => gme_common_pvt.g_transaction_header_id
10244 ,p_table => 1
10245 ,p_commit => p_commit
10246 ,x_return_status => x_return_status);
10247
10248 IF g_debug <= gme_debug.g_log_statement THEN
10249 gme_debug.put_line ( g_pkg_name || '.' || l_api_name ||
10250 ' Return status from gme_api_pub.save_batch is ' || x_return_status);
10251 END IF;
10252
10253 IF x_return_status <> fnd_api.g_ret_sts_success THEN
10254 RAISE fnd_api.g_exc_error;
10255 END IF;
10256
10257 IF g_debug <= gme_debug.g_log_procedure THEN
10258 gme_debug.put_line ( ' Completed ' || l_api_name || ' at '
10259 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
10260 END IF;
10261 EXCEPTION
10262 WHEN error_release_batch THEN
10263 ROLLBACK TO SAVEPOINT release_batch;
10264 x_batch_header_rec := NULL;
10265 gme_common_pvt.count_and_get (x_count => x_message_count
10266 ,p_encoded => fnd_api.g_false
10267 ,x_data => x_message_list);
10268 WHEN fnd_api.g_exc_error THEN
10269 ROLLBACK TO SAVEPOINT release_batch;
10270 x_batch_header_rec := NULL;
10271 x_return_status := fnd_api.g_ret_sts_error;
10272 gme_common_pvt.count_and_get (x_count => x_message_count
10273 ,p_encoded => fnd_api.g_false
10274 ,x_data => x_message_list);
10275 WHEN OTHERS THEN
10276 ROLLBACK TO SAVEPOINT release_batch;
10277 x_batch_header_rec := NULL;
10278 gme_when_others ( p_api_name => l_api_name
10279 ,x_message_count => x_message_count
10280 ,x_message_list => x_message_list
10281 ,x_return_status => x_return_status );
10282 END release_batch;
10283
10284 /*================================================================================
10285 Procedure
10286 release_step
10287 Description
10288 This procedure is used to release a step
10289 One of the following key sequences must be specified:
10290 batchstep_id
10291 batch_id, batchstep_no OR
10292 batch_no, org_code, batchstep_no batch_type assumed to be batch
10293
10294 Parameters
10295 p_batch step_rec (O) batch step to identify the step to release.
10296 p_batch_no (O) batch_no to identify the step
10297 p_org_code (O) organization code to identify the step is conjunction with batch_no in p_batch_header_rec
10298 p_ignore_exception (O) indicates whether to ignore exceptions; if exceptions are ignored,
10299 x_exception_material_tbl won't be populated ever if exceptions were found
10300 p_validate_flexfields (O) indicates whether to validate flexfields... Defaults to fnd_api.g_false;
10301 x_batch_step_rec Output batch step record after release
10302 x_exception_material_tbl Material exceptions found in release step (only those associated to step and processed dep steps)
10303 x_return_status outcome of the API call
10304 S - Success
10305 E - Error
10306 U - Unexpected Error
10307 X - Batch Exception
10308 ================================================================================*/
10309 PROCEDURE release_step
10310 (p_api_version IN NUMBER
10311 ,p_validation_level IN NUMBER
10312 := gme_common_pvt.g_max_errors
10313 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
10314 ,p_commit IN VARCHAR2 := fnd_api.g_false
10315 ,x_message_count OUT NOCOPY NUMBER
10316 ,x_message_list OUT NOCOPY VARCHAR2
10317 ,x_return_status OUT NOCOPY VARCHAR2
10318 ,p_batch_step_rec IN gme_batch_steps%ROWTYPE
10319 ,p_batch_no IN VARCHAR2
10320 ,p_org_code IN VARCHAR2
10321 ,p_ignore_exception IN VARCHAR2 := fnd_api.g_false
10322 ,p_validate_flexfields IN VARCHAR2 := fnd_api.g_false
10323 ,x_batch_step_rec OUT NOCOPY gme_batch_steps%ROWTYPE
10324 ,x_exception_material_tbl OUT NOCOPY gme_common_pvt.exceptions_tab)
10325 IS
10326 l_api_name CONSTANT VARCHAR2 (30) := 'RELEASE_STEP';
10327
10328 l_in_batch_step_rec gme_batch_steps%ROWTYPE;
10329 l_batch_step_rec gme_batch_steps%ROWTYPE;
10330 l_in_batch_header_rec gme_batch_header%ROWTYPE;
10331 l_batch_header_rec gme_batch_header%ROWTYPE;
10332
10333 l_exception_material_tbl gme_common_pvt.exceptions_tab;
10334
10335 error_release_step EXCEPTION;
10336 BEGIN
10337 IF (g_debug <> -1) THEN
10338 gme_debug.log_initialize ('ReleaseStep');
10339 END IF;
10340
10341 IF g_debug <= gme_debug.g_log_procedure THEN
10342 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
10343 || l_api_name);
10344 END IF;
10345
10346 /* Set the return status to success initially */
10347 x_return_status := fnd_api.g_ret_sts_success;
10348
10349 /* Set savepoint here */
10350 SAVEPOINT release_step;
10351
10352 IF p_init_msg_list = fnd_api.g_true THEN
10353 fnd_msg_pub.initialize;
10354 END IF;
10355
10356 IF NOT fnd_api.compatible_api_call (2.0
10357 ,p_api_version
10358 ,'release_step'
10359 ,g_pkg_name) THEN
10360 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
10361 RAISE fnd_api.g_exc_error;
10362 END IF;
10363 /* Validate Input parameters */
10364 gme_common_pvt.Validate_batch_step (
10365 p_batch_step_rec => p_batch_step_rec
10366 ,p_org_code => p_org_code
10367 ,p_batch_no => p_batch_no
10368 ,x_batch_step_rec => l_batch_step_rec
10369 ,x_batch_header_rec => l_batch_header_rec
10370 ,x_message_count => x_message_count
10371 ,x_message_list => x_message_list
10372 ,x_return_status => x_return_status );
10373
10374 IF x_return_status <> fnd_api.g_ret_sts_success THEN
10375 IF (g_debug = gme_debug.g_log_statement) THEN
10376 gme_debug.put_line ( g_pkg_name || '.' || l_api_name
10377 || ': batch step validate error ');
10378 END IF;
10379 RAISE fnd_api.g_exc_error;
10380 END IF;
10381 -- Validations
10382 IF l_batch_header_rec.batch_type = gme_common_pvt.g_doc_type_fpo THEN
10383 gme_common_pvt.log_message('GME_API_INVALID_BATCH_TYPE');
10384 RAISE fnd_api.g_exc_error;
10385 END IF;
10386 -- current Step Status must be Pending
10387 IF (l_batch_step_rec.step_status <> gme_common_pvt.g_step_pending) THEN
10388 gme_common_pvt.log_message('GME_API_INV_STAT_STEP_REL');
10389 RAISE fnd_api.g_exc_error;
10390 END IF;
10391
10392 IF l_batch_header_rec.batch_status NOT IN
10393 (gme_common_pvt.g_batch_pending, gme_common_pvt.g_batch_wip) THEN
10394 gme_common_pvt.log_message ('GME_API_INV_BATCH_REL_STEP');
10395 RAISE fnd_api.g_exc_error;
10396 END IF;
10397
10398 --Pawan kumar changed to number for g_step_controls_batch_sts
10399 IF l_batch_header_rec.batch_status = gme_common_pvt.g_batch_pending AND
10400 (gme_common_pvt.g_step_controls_batch_sts_ind <> 1 OR
10401 l_batch_header_rec.parentline_id IS NOT NULL) THEN
10402 gme_common_pvt.log_message ('GME_API_INV_BATCH_REL_STEP');
10403 RAISE fnd_api.g_exc_error;
10404 END IF;
10405
10406 l_in_batch_step_rec := l_batch_step_rec;
10407 l_in_batch_step_rec.actual_start_date := p_batch_step_rec.actual_start_date;
10408 -- output step contains the actual complete date
10409 gme_release_batch_step_pvt.validate_step_for_release
10410 (p_batch_header_rec => l_batch_header_rec
10411 ,p_batch_step_rec => l_in_batch_step_rec
10412 ,x_batch_step_rec => l_batch_step_rec
10413 ,x_return_status => x_return_status);
10414
10415 IF x_return_status <> fnd_api.g_ret_sts_success THEN
10416 RAISE fnd_api.g_exc_error;
10417 END IF;
10418
10419 -- needed for release batch AND/OR release step (release step is in private to take care of dependent steps)
10420 IF p_validate_flexfields = fnd_api.g_true THEN
10421 gme_common_pvt.g_flex_validate_prof := 1;
10422 ELSE
10423 gme_common_pvt.g_flex_validate_prof := 0;
10424 END IF;
10425
10426 IF l_batch_header_rec.batch_status = gme_common_pvt.g_batch_pending THEN
10427 l_in_batch_header_rec := l_batch_header_rec;
10428 l_in_batch_header_rec.actual_start_date := l_batch_step_rec.actual_start_date;
10429
10430 -- call release batch validation... output batch header will have actual start date filled in
10431 gme_release_batch_pvt.validate_batch_for_release
10432 (p_batch_header_rec => l_in_batch_header_rec
10433 ,x_batch_header_rec => l_batch_header_rec
10434 ,x_return_status => x_return_status);
10435
10436 IF x_return_status <> fnd_api.g_ret_sts_success THEN
10437 RAISE fnd_api.g_exc_error;
10438 END IF;
10439 END IF;
10440
10441 gme_common_pvt.g_move_to_temp := fnd_api.g_false;
10442
10443 /* Invoke main */
10444 gme_api_main.release_step
10445 (p_validation_level => p_validation_level
10446 ,p_init_msg_list => fnd_api.g_false
10447 ,x_message_count => x_message_count
10448 ,x_message_list => x_message_list
10449 ,x_return_status => x_return_status
10450 ,p_batch_step_rec => l_batch_step_rec
10451 ,p_batch_header_rec => l_batch_header_rec
10452 ,p_ignore_exception => p_ignore_exception --Bug#5186328
10453 ,x_batch_step_rec => x_batch_step_rec
10454 ,x_exception_material_tbl => l_exception_material_tbl);
10455
10456 IF g_debug <= gme_debug.g_log_statement THEN
10457 gme_debug.put_line ( g_pkg_name || '.' || l_api_name || ' Return
10458 status from gme_api_main.release_step is ' || x_return_status);
10459 END IF;
10460
10461 -- reset flex global
10462 gme_common_pvt.g_flex_validate_prof := 0;
10463
10464 IF p_ignore_exception = fnd_api.g_true AND x_return_status = gme_common_pvt.g_exceptions_err THEN
10465 x_return_status := fnd_api.g_ret_sts_success;
10466 ELSIF x_return_status = gme_common_pvt.g_exceptions_err THEN
10467 x_exception_material_tbl := l_exception_material_tbl;
10468 END IF;
10469
10470 IF x_return_status <> fnd_api.g_ret_sts_success THEN
10471 RAISE error_release_step;
10472 END IF;
10473
10474 /* Invoke save_batch */
10475 IF g_debug <= gme_debug.g_log_statement THEN
10476 gme_debug.put_line ( g_pkg_name || '.' || l_api_name || ' About to
10477 invoke save_batch with header_id of ' || gme_common_pvt.g_transaction_header_id);
10478 END IF;
10479
10480 gme_api_pub.save_batch
10481 (p_header_id => gme_common_pvt.g_transaction_header_id
10482 ,p_table => 1
10483 ,p_commit => p_commit
10484 ,x_return_status => x_return_status);
10485
10486 IF g_debug <= gme_debug.g_log_statement THEN
10487 gme_debug.put_line ( g_pkg_name || '.' || l_api_name || ' Return
10488 status from gme_api_pub.save_batch is ' || x_return_status);
10489 END IF;
10490
10491 IF x_return_status <> fnd_api.g_ret_sts_success THEN
10492 RAISE fnd_api.g_exc_error;
10493 END IF;
10494
10495 IF g_debug <= gme_debug.g_log_procedure THEN
10496 gme_debug.put_line ( ' Completed ' || l_api_name || ' at '
10497 || TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI:SS') );
10498 END IF;
10499
10500 EXCEPTION
10501 WHEN error_release_step THEN
10502 ROLLBACK TO SAVEPOINT release_step;
10503 x_batch_step_rec := NULL;
10504 gme_common_pvt.count_and_get (x_count => x_message_count
10505 ,p_encoded => fnd_api.g_false
10506 ,x_data => x_message_list);
10507 WHEN fnd_api.g_exc_error THEN
10508 ROLLBACK TO SAVEPOINT release_step;
10509 x_batch_step_rec := NULL;
10510 x_return_status := fnd_api.g_ret_sts_error;
10511 gme_common_pvt.count_and_get (x_count => x_message_count
10512 ,p_encoded => fnd_api.g_false
10513 ,x_data => x_message_list);
10514 WHEN OTHERS THEN
10515 ROLLBACK TO SAVEPOINT release_step;
10516 x_batch_step_rec := NULL;
10517 gme_when_others ( p_api_name => l_api_name
10518 ,x_message_count => x_message_count
10519 ,x_message_list => x_message_list
10520 ,x_return_status => x_return_status );
10521 END release_step;
10522
10523 /*================================================================================
10524 Procedure
10525 process_group
10526 Description
10527 This procedure is used to perform mass batch actions on group of batches.
10528 Required parameters are - group_name, org_code, action and on_error_flag.
10529
10530 Parameters
10531 p_group_name Group name to identify the group of batches to process.
10532 Set of batches can grouped under a group name which can be created
10533 from the batch group management form.
10534 p_org_code organization code to identify the group_name is conjunction with group_name in p_batch_header_rec
10535 p_action Identifies what batch action to perform
10536 Valid values from lookup type GME_BATCH_GROUP_ACTION (3,4,5,6,7,8,9,10,11)
10537 p_on_error_flag Indicates whether to continue or stop processing in case of an error.
10538 Valid values are 'STOP' OR 'CONTINUE'
10539 x_return_status outcome of the API call
10540 S - Success
10541 E - Error
10542 U - Unexpected Error
10543 X - Batch Exception
10544 ================================================================================*/
10545 PROCEDURE process_group
10546 (p_api_version IN NUMBER
10547 ,p_validation_level IN NUMBER
10548 := gme_common_pvt.g_max_errors
10549 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
10550 ,p_commit IN VARCHAR2 := fnd_api.g_false
10551 ,p_group_name IN VARCHAR2
10552 ,p_org_code IN VARCHAR2
10553 ,p_action IN NUMBER
10554 ,p_on_error_flag IN VARCHAR2
10555 ,x_message_count OUT NOCOPY NUMBER
10556 ,x_message_list OUT NOCOPY VARCHAR2
10557 ,x_return_status OUT NOCOPY VARCHAR2)
10558 IS
10559 l_api_name CONSTANT VARCHAR2 (30) := 'PROCESS_GROUP';
10560 l_action NUMBER;
10561 l_group_id NUMBER;
10562 l_group_name VARCHAR2(32);
10563 l_org_id NUMBER;
10564 i NUMBER := 0;
10565 success_count NUMBER := 0;
10566 failed_count NUMBER := 0;
10567 l_batch_header_rec gme_batch_header%ROWTYPE;
10568 l_in_batch_header_rec gme_batch_header%ROWTYPE;
10569 l_exception_material_tbl gme_common_pvt.exceptions_tab;
10570 error_process_group EXCEPTION;
10571
10572 CURSOR get_organization (l_org_code IN VARCHAR2)
10573 IS
10574 SELECT organization_id
10575 FROM mtl_parameters
10576 WHERE organization_code = p_org_code;
10577
10578 CURSOR get_group_id (l_org_id IN NUMBER, l_group_name IN VARCHAR2)
10579 IS
10580 SELECT group_id
10581 FROM gme_batch_groups_b
10582 WHERE organization_id = l_org_id AND group_name = l_group_name;
10583
10584 CURSOR validate_lookup_code(l_lookup_code IN NUMBER)
10585 IS
10586 SELECT lookup_code FROM gem_lookups
10587 WHERE lookup_type = 'GME_BATCH_GROUP_ACTION'
10588 AND lookup_code = l_lookup_code
10589 AND lookup_code NOT IN (1,2);
10590
10591 CURSOR get_associated_batches (l_group_id IN NUMBER)
10592 IS
10593 SELECT batch_id
10594 FROM gme_batch_groups_association
10595 WHERE group_id = l_group_id;
10596
10597 CURSOR get_batch_status (l_batch_id IN NUMBER, l_org_id IN NUMBER)
10598 IS
10599 SELECT batch_status
10600 FROM gme_batch_header
10601 WHERE batch_id = l_batch_id
10602 and organization_id = l_org_id;
10603
10604 BEGIN
10605 IF (g_debug <> -1) THEN
10606 gme_debug.log_initialize ('ProcessGroup');
10607 END IF;
10608
10609 IF g_debug <= gme_debug.g_log_procedure THEN
10610 gme_debug.put_line ('Entering api ' || g_pkg_name || '.'
10611 || l_api_name);
10612 END IF;
10613
10614 /* Set the return status to success initially */
10615 x_return_status := fnd_api.g_ret_sts_success;
10616
10617 /* Set savepoint here */
10618 /* SAVEPOINT process_group; */
10619
10620 IF p_init_msg_list = fnd_api.g_true THEN
10621 fnd_msg_pub.initialize;
10622 END IF;
10623
10624 IF NOT fnd_api.compatible_api_call (2.0
10625 ,p_api_version
10626 ,'process_group'
10627 ,g_pkg_name) THEN
10628 gme_common_pvt.log_message ('GME_INVALID_API_VERSION');
10629 RAISE fnd_api.g_exc_error;
10630 END IF;
10631
10632 /* Validate Input parameters */
10633
10634
10635 IF (p_org_code IS NULL) THEN
10636 fnd_message.set_name ('INV', 'INV_ORG_REQUIRED');
10637 fnd_msg_pub.ADD;
10638 RAISE fnd_api.g_exc_error;
10639 END IF;
10640
10641 IF (p_group_name IS NULL) THEN
10642 fnd_message.set_name ('GME', 'GME_GROUP_REQUIRED');
10643 fnd_msg_pub.ADD;
10644 RAISE fnd_api.g_exc_error;
10645 END IF;
10646
10647 IF (p_action IS NULL) THEN
10648 fnd_message.set_name ('GME', 'GME_ACTION_REQUIRED');
10649 fnd_msg_pub.ADD;
10650 RAISE fnd_api.g_exc_error;
10651 END IF;
10652
10653 IF (p_on_error_flag IS NULL) THEN
10654 fnd_message.set_name ('GME', 'GME_ERR_FLAG_REQUIRED');
10655 fnd_msg_pub.ADD;
10656 RAISE fnd_api.g_exc_error;
10657 END IF;
10658
10659 OPEN get_organization (p_org_code);
10660
10661 FETCH get_organization INTO l_org_id;
10662
10663 IF get_organization%NOTFOUND THEN
10664 CLOSE get_organization;
10665 gme_common_pvt.log_message ('GME_INVALID_ORG');
10666 RAISE fnd_api.g_exc_error;
10667 END IF;
10668
10669 CLOSE get_organization;
10670
10671 OPEN get_group_id (l_org_id, p_group_name);
10672
10673 FETCH get_group_id INTO l_group_id;
10674
10675 IF get_group_id%NOTFOUND THEN
10676 CLOSE get_group_id;
10677 gme_common_pvt.log_message ('GME_INVALID_GROUP');
10678 RAISE fnd_api.g_exc_error;
10679 END IF;
10680
10681 CLOSE get_group_id;
10682
10683 OPEN validate_lookup_code(p_action);
10684 FETCH validate_lookup_code INTO l_action;
10685
10686 IF validate_lookup_code%NOTFOUND THEN
10687 CLOSE validate_lookup_code;
10688 gme_common_pvt.log_message ('GME_INVALID_GROUP_ACTION');
10689 RAISE fnd_api.g_exc_error;
10690 END IF;
10691
10692 CLOSE validate_lookup_code;
10693
10694 IF (p_on_error_flag <> 'STOP' AND p_on_error_flag <> 'CONTINUE') THEN
10695 gme_common_pvt.log_message ('GME_INVALID_ERR_FLAG');
10696 RAISE fnd_api.g_exc_error;
10697 END IF;
10698
10699 i := 0;
10700 FOR get_rec IN get_associated_batches(l_group_id) LOOP
10701 BEGIN
10702 i := i+1;
10703 l_in_batch_header_rec.batch_id := get_rec.batch_id;
10704 -- DBMS_OUTPUT.put_line ('batch_id is ' || l_in_batch_header_rec.batch_id);
10705 IF (p_action = 3) THEN
10706 gme_api_pub.auto_detail_batch
10707 (p_api_version => 2.0,
10708 p_init_msg_list => 'T',
10709 p_commit => 'T',
10710 x_message_count => x_message_count,
10711 x_message_list => x_message_list,
10712 x_return_status => x_return_status,
10713 p_batch_rec => l_in_batch_header_rec,
10714 p_org_code => NULL
10715 );
10716 ELSIF (p_action = 4) THEN
10717 gme_api_pub.release_batch
10718 (p_api_version => 2.0,
10719 p_validation_level => 100,
10720 p_init_msg_list => 'T',
10721 p_commit => 'T',
10722 x_message_count => x_message_count,
10723 x_message_list => x_message_list,
10724 x_return_status => x_return_status,
10725 p_batch_header_rec => l_in_batch_header_rec,
10726 p_org_code => NULL,
10727 p_ignore_exception => 'F',
10728 p_validate_flexfields => 'F',
10729 x_batch_header_rec => l_batch_header_rec,
10730 x_exception_material_tbl => l_exception_material_tbl
10731 );
10732 ELSIF (p_action = 5) THEN
10733 gme_api_pub.complete_batch
10734 (p_api_version => 2.0,
10735 p_validation_level => 100,
10736 p_init_msg_list => 'T',
10737 p_commit => 'T',
10738 x_message_count => x_message_count,
10739 x_message_list => x_message_list,
10740 x_return_status => x_return_status,
10741 p_batch_header_rec => l_in_batch_header_rec,
10742 p_org_code => NULL,
10743 p_ignore_exception => 'F',
10744 p_validate_flexfields => 'F',
10745 x_batch_header_rec => l_batch_header_rec,
10746 x_exception_material_tbl => l_exception_material_tbl
10747 );
10748 ELSIF (p_action = 6) THEN
10749 gme_api_pub.close_batch
10750 (p_api_version => 2.0,
10751 p_validation_level => 100,
10752 p_init_msg_list => 'T',
10753 p_commit => 'T',
10754 x_message_count => x_message_count,
10755 x_message_list => x_message_list,
10756 x_return_status => x_return_status,
10757 p_batch_header_rec => l_in_batch_header_rec,
10758 x_batch_header_rec => l_batch_header_rec,
10759 p_org_code => NULL
10760 );
10761 ELSIF (p_action = 7) THEN
10762 gme_api_pub.reopen_batch
10763 (p_api_version => 2.0,
10764 p_validation_level => 100,
10765 p_init_msg_list => 'T',
10766 p_commit => 'T',
10767 x_message_count => x_message_count,
10768 x_message_list => x_message_list,
10769 x_return_status => x_return_status,
10770 p_org_code => NULL,
10771 p_batch_header_rec => l_in_batch_header_rec,
10772 p_reopen_steps => NULL,
10773 x_batch_header_rec => l_batch_header_rec
10774 );
10775 ELSIF (p_action = 8) THEN
10776 gme_api_pub.revert_batch
10777 (p_api_version => 2.0,
10778 p_validation_level => 100,
10779 p_init_msg_list => 'T',
10780 p_commit => 'T',
10781 x_message_count => x_message_count,
10782 x_message_list => x_message_list,
10783 x_return_status => x_return_status,
10784 p_org_code => NULL,
10785 p_batch_header_rec => l_in_batch_header_rec,
10786 x_batch_header_rec => l_batch_header_rec
10787 );
10788 ELSIF (p_action = 9) THEN
10789 gme_api_pub.unrelease_batch
10790 (p_api_version => 2.0,
10791 p_validation_level => 100,
10792 p_init_msg_list => 'T',
10793 p_commit => 'T',
10794 x_message_count => x_message_count,
10795 x_message_list => x_message_list,
10796 x_return_status => x_return_status,
10797 p_batch_header_rec => l_in_batch_header_rec,
10798 p_org_code => NULL,
10799 p_create_resv_pend_lots => NULL,
10800 x_batch_header_rec => l_batch_header_rec
10801 );
10802 ELSIF (p_action = 10) THEN
10803 gme_api_pub.cancel_batch
10804 (p_api_version => 2.0,
10805 p_validation_level => 100,
10806 p_init_msg_list => 'T',
10807 p_commit => 'T',
10808 x_message_count => x_message_count,
10809 x_message_list => x_message_list,
10810 x_return_status => x_return_status,
10811 p_batch_header_rec => l_in_batch_header_rec,
10812 x_batch_header_rec => l_batch_header_rec,
10813 p_org_code => NULL
10814 );
10815
10816 ELSIF (p_action = 11) THEN
10817 gme_api_pub.terminate_batch
10818 (p_api_version => 2.0,
10819 p_validation_level => 100,
10820 p_init_msg_list => 'T',
10821 p_commit => 'T',
10822 x_message_count => x_message_count,
10823 x_message_list => x_message_list,
10824 x_return_status => x_return_status,
10825 p_org_code => NULL,
10826 p_reason_name => NULL,
10827 p_batch_header_rec => l_in_batch_header_rec,
10828 x_batch_header_rec => l_batch_header_rec
10829 );
10830 END IF;
10831
10832 -- DBMS_OUTPUT.put_line ('return status is = ' || x_return_status);
10833 IF x_return_status <> fnd_api.g_ret_sts_success THEN
10834 failed_count := failed_count + 1;
10835 gme_common_pvt.count_and_get (x_count => x_message_count
10836 ,p_encoded => fnd_api.g_false
10837 ,x_data => x_message_list);
10838 -- DBMS_OUTPUT.put_line('Error ' || x_message_list);
10839 IF (p_on_error_flag = 'STOP') THEN
10840 RAISE error_process_group;
10841 END IF;
10842 ELSE
10843 success_count := success_count + 1;
10844 END IF;
10845
10846 EXCEPTION
10847 WHEN OTHERS THEN
10848 failed_count := failed_count + 1;
10849 gme_common_pvt.count_and_get (x_count => x_message_count
10850 ,p_encoded => fnd_api.g_false
10851 ,x_data => x_message_list);
10852 -- DBMS_OUTPUT.put_line('Error ' || x_message_list);
10853 IF (p_on_error_flag = 'STOP') THEN
10854 RAISE error_process_group;
10855 END IF;
10856 END;
10857 END LOOP;
10858
10859 IF i=0 THEN
10860 gme_common_pvt.log_message ('GME_NO_GROUP_ASSOC');
10861 RAISE fnd_api.g_exc_error;
10862 ELSE
10863 -- DBMS_OUTPUT.put_line('Total ' || i);
10864 -- DBMS_OUTPUT.put_line('Success ' || success_count);
10865 -- DBMS_OUTPUT.put_line('Failed ' || failed_count);
10866 gme_common_pvt.log_message
10867 ( p_message_code => 'GME_GROUP_ASSOC_TOTAL'
10868 ,p_product_code => 'GME'
10869 ,p_token1_name => 'TOTAL_COUNT'
10870 ,p_token1_value => i
10871 );
10872 gme_common_pvt.log_message
10873 ( p_message_code => 'GME_GROUP_ASSOC_SUCCESS'
10874 ,p_product_code => 'GME'
10875 ,p_token1_name => 'SUCCESS_COUNT'
10876 ,p_token1_value => success_count
10877 );
10878
10879 gme_common_pvt.log_message
10880 ( p_message_code => 'GME_GROUP_ASSOC_FAIL'
10881 ,p_product_code => 'GME'
10882 ,p_token1_name => 'FAILED_COUNT'
10883 ,p_token1_value => failed_count
10884 );
10885 END IF;
10886
10887 EXCEPTION
10888
10889 WHEN error_process_group THEN
10890 gme_common_pvt.count_and_get (x_count => x_message_count
10891 ,p_encoded => fnd_api.g_false
10892 ,x_data => x_message_list);
10893 WHEN fnd_api.g_exc_error THEN
10894 x_return_status := fnd_api.g_ret_sts_error;
10895 gme_common_pvt.count_and_get (x_count => x_message_count
10896 ,p_encoded => fnd_api.g_false
10897 ,x_data => x_message_list);
10898 WHEN OTHERS THEN
10899 gme_when_others ( p_api_name => l_api_name
10900 ,x_message_count => x_message_count
10901 ,x_message_list => x_message_list
10902 ,x_return_status => x_return_status );
10903 END process_group;
10904
10905
10906 END gme_api_pub;