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