[Home] [Help]
PACKAGE BODY: APPS.GME_INSERT_STEP_PVT
Source
1 PACKAGE BODY gme_insert_step_pvt AS
2 /* $Header: GMEVINSB.pls 120.6.12010000.1 2008/07/25 10:31:06 appldev ship $ */
3 g_debug VARCHAR2 (5) := fnd_profile.VALUE ('AFLOG_LEVEL');
4 g_pkg_name CONSTANT VARCHAR2 (30) := 'GME_API_INSERT_STEP';
5
6 PROCEDURE insert_batch_step (
7 p_gme_batch_header IN gme_batch_header%ROWTYPE
8 ,p_gme_batch_step IN gme_batch_steps%ROWTYPE
9 ,x_gme_batch_step OUT NOCOPY gme_batch_steps%ROWTYPE
10 ,x_return_status OUT NOCOPY VARCHAR2)
11 IS
12 CURSOR get_steps_count (v_batchstep_no NUMBER, v_batch_id NUMBER)
13 IS
14 SELECT COUNT (*)
15 FROM gme_batch_steps
16 WHERE batch_id = v_batch_id
17 AND batchstep_no = v_batchstep_no
18 AND delete_mark = 0;
19
20 /* Punit Kumar */
21 /* Susruth D. Bug#4917184 Start */
22 CURSOR get_orgn_code (p_org_id NUMBER)
23 IS
24 SELECT organization_code
25 FROM mtl_parameters
26 WHERE organization_id = p_org_id ;
27
28 /* Bug#5231180 */
29 CURSOR cur_get_std_factor (v_um_code VARCHAR2)
30 IS
31 SELECT conversion_rate, uom_class
32 FROM mtl_uom_conversions
33 WHERE uom_code = v_um_code
34 AND inventory_item_id = 0;
35
36 --nsinghi bug#5202811.
37 CURSOR cur_text_code (v_text_code NUMBER) IS
38 SELECT 1
39 FROM sys.DUAL
40 WHERE EXISTS ( SELECT 1
41 FROM gme_text_header
42 WHERE text_code = v_text_code);
43
44 /* Bug#4917184 End */
45 l_recipe_rout_step gmd_recipe_fetch_pub.recipe_step_tbl;
46 -- gme_batch_steps
47 l_recipe_rout_act gmd_recipe_fetch_pub.oprn_act_tbl;
48 -- gme_batch_step_activities
49 l_recipe_rout_resc gmd_recipe_fetch_pub.oprn_resc_tbl;
50 -- gme_batch_step_resources
51 /* Pawan kumar bug 2509572 added code for process parameters */
52 l_resc_parameters gmd_recipe_fetch_pub.recp_resc_proc_param_tbl;
53 -- gme_process_parameters
54 l_recipe_rout_matl gmd_recipe_fetch_pub.recipe_rout_matl_tbl;
55 -- gme_batch_step_items
56 l_routing_depd gmd_recipe_fetch_pub.routing_depd_tbl;
57 -- gme_batch_step_dependencies
58 l_message_count NUMBER;
59 l_message_data VARCHAR2 (2048);
60 l_return_code NUMBER;
61 l_return_status VARCHAR2 (1);
62 l_count NUMBER;
63 l_batch_id NUMBER;
64 l_batch_step_row gme_batch_steps%ROWTYPE;
65 l_exists NUMBER; --nsinghi bug#5202811
66 --Bug#5231180
67 l_um_type mtl_units_of_measure.uom_class%TYPE;
68 l_std_factor NUMBER;
69 /* Punit Kumar */
70 l_orgn_code VARCHAR2 (3);
71 error_inv_status_ins_step EXCEPTION;
72 error_no_oprn_defined EXCEPTION;
73 error_gmd_fetch_oprn EXCEPTION;
74 error_step_qty_lthan_zero EXCEPTION;
75 error_create_batch_step EXCEPTION;
76 error_calc_max_capacity EXCEPTION;
77 batch_step_fetch_error EXCEPTION;
78 /* Punit Kumar
79 */
80 error_no_organization_id EXCEPTION;
81 validation_failure EXCEPTION;
82 batch_step_update_error EXCEPTION;
83 expected_error EXCEPTION;
84 invalid_text_code EXCEPTION; --nsinghi bug#5202811
85 invalid_oprn_effectivity EXCEPTION;
86 BEGIN
87 IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
88 gme_debug.put_line ('Begin Insert_Batch_Step');
89 END IF;
90
91 x_return_status := fnd_api.g_ret_sts_success;
92 /* Bug 2397077 Use only one batch_id when batch IDs passed in both parameters. */
93 l_batch_id :=
94 NVL (p_gme_batch_step.batch_id, p_gme_batch_header.batch_id);
95
96 /* End Bug 2397077 */
97 IF p_gme_batch_step.batchstep_no IS NULL THEN
98 gme_common_pvt.log_message ('GME_STEP_REQD'
99 ,'FIELDREQ'
100 ,'Batchstep Number');
101 RAISE expected_error;
102 END IF;
103
104 OPEN get_steps_count (p_gme_batch_step.batchstep_no, l_batch_id);
105
106 FETCH get_steps_count
107 INTO l_count;
108
109 CLOSE get_steps_count;
110
111 IF l_count > 0 THEN
112 /* Bug 2397077 Corrected message from PC_DUPLICATESTEP_NO to PC_DUPLICATESTEPNO*/
113 gme_common_pvt.log_message ('PC_DUPLICATESTEPNO');
114 RAISE expected_error;
115 END IF;
116
117 /* Bug 2397077 Validate step_release_type passed to program. */
118 IF (p_gme_batch_step.steprelease_type NOT IN (1, 2) ) THEN
119 gme_common_pvt.log_message ('GME_INVALID_STEPRELEASE');
120 RAISE expected_error;
121 END IF;
122
123 /* End Bug 2397077 */
124 IF (p_gme_batch_header.batch_status = 4)
125 OR (p_gme_batch_header.batch_status = -1) THEN
126 -- Closed or cancelled batch not valid for step insert...
127 RAISE error_inv_status_ins_step;
128 END IF;
129
130 IF p_gme_batch_step.oprn_id IS NULL THEN
131 RAISE error_no_oprn_defined;
132 END IF;
133
134 /* Punit Kumar */
135 IF p_gme_batch_header.organization_id IS NULL THEN
136 RAISE error_no_organization_id;
137 END IF;
138
139 /* Punit Kumar */
140 OPEN get_orgn_code (p_gme_batch_header.organization_id);
141
142 FETCH get_orgn_code
143 INTO l_orgn_code;
144
145 CLOSE get_orgn_code;
146
147 /* Pawan kumar bug 2509572 added code for process parameters */
148
149 /* Punit Kumar */
150 gmd_fetch_oprn.fetch_oprn
151 (p_api_version => 1.0
152 ,p_init_msg_list => fnd_api.g_false
153 ,p_oprn_id => p_gme_batch_step.oprn_id
154 ,p_orgn_code => l_orgn_code
155 , /* p_gme_batch_header.plant_code, */
156 x_return_status => l_return_status
157 ,x_msg_count => l_message_count
158 ,x_msg_data => l_message_data
159 ,x_return_code => l_return_code
160 ,x_oprn_act_out => l_recipe_rout_act
161 ,x_oprn_resc_rec => l_recipe_rout_resc
162 ,x_oprn_resc_proc_param_tbl => l_resc_parameters);
163
164 IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
165 gme_debug.put_line ( 'Inser_Batch_step:fetch_oprn returned:'
166 || l_return_status
167 || ' Return Code:'||l_return_code
168 || ' Error Msg: '
169 || l_message_data
170 || ' ERROR:'
171 || SQLERRM);
172 gme_debug.put_line
173 ( 'Insert_Batch_Step... GMD_FETCH_OPRN.FETCH_OPRN returned '
174 || l_recipe_rout_act.COUNT
175 || ' ACTIVITIES');
176 gme_debug.put_line
177 ( 'Insert_Batch_Step... GMD_FETCH_OPRN.FETCH_OPRN returned '
178 || l_recipe_rout_resc.COUNT
179 || ' RESOURCES');
180
181 FOR i IN 1 .. l_recipe_rout_act.COUNT LOOP
182 gme_debug.put_line
183 ( 'Insert_Batch_Step... GMD_FETCH_OPRN.FETCH_OPRN returned '
184 || l_recipe_rout_act (i).oprn_id
185 || ' operation_id');
186 gme_debug.put_line
187 ( 'Insert_Batch_Step... GMD_FETCH_OPRN.FETCH_OPRN returned '
188 || l_recipe_rout_act (i).minimum_transfer_qty
189 || ' minimum_transfer_qty at Activity '||l_recipe_rout_act (i).activity);
190 END LOOP;
191 END IF;
192
193 IF l_return_status <> x_return_status THEN
194 RAISE error_gmd_fetch_oprn;
195 END IF;
196
197 IF l_recipe_rout_act.COUNT < 1 THEN
198 IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
199 gme_debug.put_line
200 ('Insert_Batch Step - GMD_FETCH_OPRN.FETCH_OPRN returned no activities');
201 END IF;
202 gme_common_pvt.log_message('GME_AT_LEAST_ONE_ACTIVITY');
203 RAISE error_gmd_fetch_oprn;
204 END IF;
205
206 IF l_recipe_rout_resc.COUNT < 1 THEN
207 IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
208 gme_debug.put_line
209 ('Insert_Batch Step - GMD_FETCH_OPRN.FETCH_OPRN returned no resources');
210 END IF;
211 gme_common_pvt.log_message('GME_AT_LEAST_ONE_RESOURCE');
212 RAISE error_gmd_fetch_oprn;
213 END IF;
214
215 -- Fill in the recipe_rout_step structure from what was filled in on p_gme_batch_step
216 -- subscript is hard-coded to 1 since this is only inserting 1 batch step....
217 l_recipe_rout_step (1).routingstep_no := p_gme_batch_step.batchstep_no;
218 l_recipe_rout_step (1).oprn_id := p_gme_batch_step.oprn_id;
219 l_recipe_rout_step (1).steprelease_type :=
220 p_gme_batch_step.steprelease_type;
221
222 --Bharati Satpute bug2848936 added to fetch minimum_transfer_qty
223 -- Bug 4773956: Corrected field name to process_qty_uom instead of um
224 -- Also combined both the select statements into one.
225 SELECT minimum_transfer_qty, process_qty_uom
226 INTO l_recipe_rout_step (1).minimum_transfer_qty,
227 l_recipe_rout_step (1).process_qty_uom
228 FROM gmd_operations_b
229 WHERE oprn_id = p_gme_batch_step.oprn_id;
230 --Bug#5231180
231 l_recipe_rout_step (1).capacity_uom := l_recipe_rout_step (1).process_qty_uom;
232
233 --bharati satpute bug2848936 Added
234 -- l_recipe_rout_step (1). minimum_transfer_qty := p_gme_batch_step.minimum_transfer_qty;
235 IF (p_gme_batch_header.automatic_step_calculation = 1) THEN
236 l_recipe_rout_step (1).step_qty := 0;
237 --NULL;
238 ELSE
239 IF p_gme_batch_step.plan_step_qty < 0 THEN
240 RAISE error_step_qty_lthan_zero;
241 END IF;
242 l_recipe_rout_step (1).step_qty := p_gme_batch_step.plan_step_qty;
243 END IF;
244
245
246
247 /* SELECT process_qty_um
248 INTO l_recipe_rout_step (1).process_qty_uom
249 FROM gmd_operations
250 WHERE oprn_id = p_gme_batch_step.oprn_id;*/
251
252 calc_max_capacity (p_recipe_rout_resc => l_recipe_rout_resc
253 ,p_max_capacity => l_recipe_rout_step (1).max_capacity
254 ,p_capacity_uom => l_recipe_rout_step (1).capacity_uom
255 ,x_resource => l_recipe_rout_step (1).resources
256 ,x_return_status => l_return_status
257 ,p_step_qty_uom => l_recipe_rout_step (1).process_qty_uom);
258
259 IF l_return_status <> x_return_status THEN
260 RAISE error_calc_max_capacity;
261 END IF;
262
263 /* Pawan kumar bug 2509572 added code for process parameters */
264
265 /* Punit Kumar */
266 gme_create_step_pvt.create_batch_steps
267 (p_recipe_rout_step_tbl => l_recipe_rout_step
268 ,p_recipe_rout_act_tbl => l_recipe_rout_act
269 ,p_recipe_rout_resc_tbl => l_recipe_rout_resc
270 ,p_resc_parameters_tbl => l_resc_parameters
271 ,p_recipe_rout_matl_tbl => l_recipe_rout_matl
272 ,p_routing_depd_tbl => l_routing_depd
273 ,p_gme_batch_header_rec => p_gme_batch_header
274 ,p_use_workday_cal => fnd_api.g_true
275 ,p_contiguity_override => fnd_api.g_true
276 ,x_return_status => l_return_status
277 ,p_ignore_qty_below_cap => fnd_api.g_true
278 ,p_step_start_date => p_gme_batch_step.plan_start_date
279 ,p_step_cmplt_date => p_gme_batch_step.plan_cmplt_date
280 ,p_step_due_date => p_gme_batch_step.due_date);
281
282 IF l_return_status <> x_return_status THEN
283 RAISE error_create_batch_step;
284 END IF;
285
286 x_gme_batch_step.batchstep_no := p_gme_batch_step.batchstep_no;
287 x_gme_batch_step.batch_id := l_batch_id;
288
289 IF NOT (gme_batch_steps_dbl.fetch_row (x_gme_batch_step
290 ,x_gme_batch_step) ) THEN
291 RAISE batch_step_fetch_error;
292 END IF;
293
294 /* Bug#6408612 calculated step plan start and end dates are validated
295 against the operation effectivity start and end dates */
296 IF NOT gme_common_pvt.check_oprn_effectivity_dates(x_gme_batch_step.oprn_id,
297 x_gme_batch_step.plan_start_date,
298 x_gme_batch_step.plan_cmplt_date) THEN
299 x_return_status := FND_API.G_RET_STS_ERROR;
300 RAISE invalid_oprn_effectivity;
301 END IF;
302
303 IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
304 gme_debug.put_line (' Before Validate Flex ');
305 END IF;
306
307 -- Added following code in order to set the flexfields and the ID fields
308 -- Before calling the validate_flex_fields
309 l_batch_step_row := x_gme_batch_step;
310 l_batch_step_row.attribute_category :=
311 p_gme_batch_step.attribute_category;
312 l_batch_step_row.attribute1 := p_gme_batch_step.attribute1;
313 l_batch_step_row.attribute2 := p_gme_batch_step.attribute2;
314 l_batch_step_row.attribute3 := p_gme_batch_step.attribute3;
315 l_batch_step_row.attribute4 := p_gme_batch_step.attribute4;
316 l_batch_step_row.attribute5 := p_gme_batch_step.attribute5;
317 l_batch_step_row.attribute6 := p_gme_batch_step.attribute6;
318 l_batch_step_row.attribute7 := p_gme_batch_step.attribute7;
319 l_batch_step_row.attribute8 := p_gme_batch_step.attribute8;
320 l_batch_step_row.attribute9 := p_gme_batch_step.attribute9;
321 l_batch_step_row.attribute10 := p_gme_batch_step.attribute10;
322 l_batch_step_row.attribute11 := p_gme_batch_step.attribute11;
323 l_batch_step_row.attribute12 := p_gme_batch_step.attribute12;
324 l_batch_step_row.attribute13 := p_gme_batch_step.attribute13;
325 l_batch_step_row.attribute14 := p_gme_batch_step.attribute14;
326 l_batch_step_row.attribute15 := p_gme_batch_step.attribute15;
327 l_batch_step_row.attribute16 := p_gme_batch_step.attribute16;
328 l_batch_step_row.attribute17 := p_gme_batch_step.attribute17;
329 l_batch_step_row.attribute18 := p_gme_batch_step.attribute18;
330 l_batch_step_row.attribute19 := p_gme_batch_step.attribute19;
331 l_batch_step_row.attribute20 := p_gme_batch_step.attribute20;
332 l_batch_step_row.attribute21 := p_gme_batch_step.attribute21;
333 l_batch_step_row.attribute22 := p_gme_batch_step.attribute22;
334 l_batch_step_row.attribute23 := p_gme_batch_step.attribute23;
335 l_batch_step_row.attribute24 := p_gme_batch_step.attribute24;
336 l_batch_step_row.attribute25 := p_gme_batch_step.attribute25;
337 l_batch_step_row.attribute26 := p_gme_batch_step.attribute26;
338 l_batch_step_row.attribute27 := p_gme_batch_step.attribute27;
339 l_batch_step_row.attribute28 := p_gme_batch_step.attribute28;
340 l_batch_step_row.attribute29 := p_gme_batch_step.attribute29;
341 l_batch_step_row.attribute30 := p_gme_batch_step.attribute30;
342 --3556979
343 gme_validate_flex_fld_pvt.validate_flex_batch_step
344 (p_batch_step => l_batch_step_row
345 ,x_batch_step => x_gme_batch_step
346 ,x_return_status => x_return_status);
347
348 IF x_return_status <> fnd_api.g_ret_sts_success THEN
349 RAISE validation_failure;
350 END IF;
351
352 --nsinghi bug#5202811 added the code to process edit text.
353 IF p_gme_batch_step.text_code IS NOT NULL THEN
354 OPEN cur_text_code (p_gme_batch_step.text_code);
355 FETCH cur_text_code INTO l_exists;
356 IF cur_text_code%NOTFOUND THEN
357 CLOSE cur_text_code;
358 RAISE invalid_text_code;
359 END IF;
360
361 CLOSE cur_text_code;
362 END IF;
363 x_gme_batch_step.text_code := p_gme_batch_step.text_code;
364
365 IF NOT (gme_batch_steps_dbl.update_row (p_batch_step => x_gme_batch_step) ) THEN
366 RAISE batch_step_update_error;
367 END IF;
368
369 /* Bug 2397077 Added message to indicate success of program. */
370 gme_common_pvt.log_message ('GME_INSERT_BATCH_STEP_SUCCESS');
371
372 /* End Bug 2397077 */
373 IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
374 gme_debug.put_line ('End Insert_Batch_Step');
375 END IF;
376 EXCEPTION
377 WHEN error_inv_status_ins_step THEN
378 IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
379 gme_debug.put_line ('insert_step --> invalid batch status');
380 END IF;
381
382 x_return_status := fnd_api.g_ret_sts_error;
383 gme_common_pvt.log_message ('GME_INV_STATUS_INSERT_STEP');
384 WHEN error_no_oprn_defined THEN
385 IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
386 gme_debug.put_line ('insert_step --> no oprn passed');
387 END IF;
388
389 x_return_status := fnd_api.g_ret_sts_error;
390 gme_common_pvt.log_message ('GME_NO_OPRN_DEFINED');
391 WHEN error_gmd_fetch_oprn THEN
392 x_return_status := l_return_status;
393 WHEN error_step_qty_lthan_zero THEN
394 IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
395 gme_debug.put_line ('insert_step --> step qty < zero');
396 END IF;
397
398 x_return_status := fnd_api.g_ret_sts_error;
399 gme_common_pvt.log_message ('GME_STEP_QTY_LTHAN_ZERO');
400 /* Punit Kumar */
401 WHEN error_no_organization_id THEN
402 IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
403 gme_debug.put_line ('insert_step --> no ORGANIZATION_ID supplied');
404 END IF;
405
406 x_return_status := fnd_api.g_ret_sts_error;
407 WHEN error_create_batch_step THEN
408 IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
409 gme_debug.put_line
410 (fnd_msg_pub.get (p_encoded => fnd_api.g_false) );
411 END IF;
412
413 x_return_status := l_return_status;
414 WHEN error_calc_max_capacity THEN
415 x_return_status := l_return_status;
416 WHEN invalid_text_code THEN -- nsinghi bug#5202911
417 x_return_status := fnd_api.g_ret_sts_error;
418 gme_common_pvt.log_message ('GME_INVALID_TEXT_CODE');
419 WHEN batch_step_fetch_error OR batch_step_update_error THEN
420 IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
421 gme_debug.put_line
422 (fnd_msg_pub.get (p_encoded => fnd_api.g_false) );
423 END IF;
424
425 x_return_status := fnd_api.g_ret_sts_error;
426 WHEN validation_failure THEN
427 NULL;
428 WHEN expected_error OR invalid_oprn_effectivity THEN --Bug#6408612
429 x_return_status := fnd_api.g_ret_sts_error;
430 WHEN OTHERS THEN
431 IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
432 gme_debug.put_line ( 'GME insert_step API -- when others '
433 || SQLERRM);
434 END IF;
435
436 x_return_status := fnd_api.g_ret_sts_unexp_error;
437 fnd_msg_pub.add_exc_msg ('GME_API_INSERT_STEP', 'INSERT_BATCH_STEP');
438 END insert_batch_step;
439
440 PROCEDURE calc_max_capacity (
441 p_recipe_rout_resc IN gmd_recipe_fetch_pub.oprn_resc_tbl
442 -- resources that we want the max_capacity of
443 ,p_max_capacity OUT NOCOPY gme_batch_steps.max_step_capacity%TYPE
444 ,p_capacity_uom OUT NOCOPY gme_batch_steps.max_step_capacity_um%TYPE
445 ,x_resource OUT NOCOPY gme_batch_step_resources.resources%TYPE
446 ,x_return_status OUT NOCOPY VARCHAR2
447 ,p_step_qty_uom IN VARCHAR2 DEFAULT NULL) --Bug#5231180
448 IS
449 l_max_cap cr_rsrc_mst.max_capacity%TYPE;
450 l_std_cap cr_rsrc_mst.max_capacity%TYPE;
451 l_std_min_of_max_cap cr_rsrc_mst.max_capacity%TYPE;
452 l_min_of_max_cap cr_rsrc_mst.max_capacity%TYPE;
453 l_min_of_max_cap_uom cr_rsrc_mst.capacity_uom%TYPE;
454 l_cap_uom cr_rsrc_mst.capacity_uom%TYPE;
455
456 --Bug#5231180 changed to mtl_units_of_measure
457 l_min_of_max_um_type mtl_units_of_measure.uom_class%TYPE; --sy_uoms_mst.um_type%TYPE;
458 l_std_factor NUMBER;
459 l_um_type mtl_units_of_measure.uom_class%TYPE; --sy_uoms_mst.um_type%TYPE;
460
461 l_first BOOLEAN;
462 l_assign BOOLEAN;
463 l_api_name CONSTANT VARCHAR2 (30) := 'CALC_MAX_CAPACITY';
464
465 CURSOR cur_get_rsrc (p_rsrc cr_rsrc_mst.resources%TYPE)
466 IS
467 SELECT max_capacity, capacity_um --Bug#5231180 changed to capacity um
468 FROM cr_rsrc_mst
469 WHERE resources = p_rsrc
470 AND delete_mark = 0
471 AND capacity_constraint = 1;
472
473 --Bug#5231180 rewritten the folloiwing cursor to use mtl_uom_conversions table
474 /*CURSOR cur_get_std_factor (v_um_code VARCHAR2)
475 IS
476 SELECT std_factor, um_type
477 FROM sy_uoms_mst
478 WHERE um_code = v_um_code; */
479 CURSOR cur_get_std_factor (v_um_code VARCHAR2)
480 IS
481 SELECT conversion_rate, uom_class
482 FROM mtl_uom_conversions
483 WHERE uom_code = v_um_code
484 AND inventory_item_id = 0;
485
486 error_rsrc_diff_um_type EXCEPTION;
487 error_calc_charge_conv EXCEPTION; --Bug#5231180
488 l_temp_qty NUMBER; --Bug#5231180
489 BEGIN
490 IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
491 gme_debug.put_line ('Insert_batch_step... BEGIN calc max cap');
492 END IF;
493
494 x_return_status := fnd_api.g_ret_sts_success;
495 l_first := TRUE;
496 l_assign := FALSE;
497 -- Initialize in case we don't find any rsrcs that are capacity constraining...
498 l_min_of_max_cap := NULL;
499 l_min_of_max_cap_uom := NULL;
500 -- Initialize in case there is an error...
501 p_max_capacity := NULL;
502 p_capacity_uom := NULL;
503
504 IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
505 gme_debug.put_line ('Resource Count: '||p_recipe_rout_resc.COUNT);
506 END IF;
507
508 FOR i IN 1 .. p_recipe_rout_resc.COUNT LOOP
509 l_max_cap := NULL;
510 l_cap_uom := NULL;
511
512 OPEN cur_get_rsrc (p_recipe_rout_resc (i).resources);
513 FETCH cur_get_rsrc INTO l_max_cap, l_cap_uom;
514 CLOSE cur_get_rsrc;
515
516 IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
517 gme_debug.put_line ('Max Capacity: '||l_max_cap);
518 gme_debug.put_line ('Resource Capacity UOM: '||l_cap_uom);
519 END IF;
520
521 -- Did we find something? not deleted and capacity constraining...
522 IF (l_max_cap IS NOT NULL AND l_cap_uom IS NOT NULL) THEN
523
524 OPEN cur_get_std_factor (l_cap_uom);
525 FETCH cur_get_std_factor INTO l_std_factor, l_um_type;
526 CLOSE cur_get_std_factor;
527
528 -- calculate the capacity in the std UOM for it's UOM type...
529 l_std_cap := l_max_cap * l_std_factor;
530
531 -- If this is the first to be found, then take it.
532 IF (l_first) THEN
533 l_assign := TRUE;
534 l_first := FALSE;
535 ELSE
536 -- If this is not the first to come through, then the capacity must be less then
537 -- that which we have already stored... we are ensuring that both qty's are in the
538 -- same um type and then comparing the capacity in the STD UOM.
539 IF (l_min_of_max_um_type = l_um_type) THEN
540 IF l_std_cap < l_std_min_of_max_cap THEN
541 l_assign := TRUE;
542 END IF;
543 ELSE
544 -- can't compare the capacity... this will cause the max cap and cap_UOM to
545 -- be returned as NULL.
546 IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
547 gme_debug.put_line('GME insert_step API calc_max_cap --> resources in diff UOM types...');
548 END IF;
549 --Bug#5231180 used gme_common_pvt to log the message
550 gme_common_pvt.log_message('GME_RSRC_DIFF_UM_TYPE');
551 RAISE error_rsrc_diff_um_type;
552 END IF;
553 END IF;
554
555 IF (l_assign) THEN
556 l_std_min_of_max_cap := l_std_cap;
557 l_min_of_max_cap := l_max_cap;
558 l_min_of_max_cap_uom := l_cap_uom;
559 l_min_of_max_um_type := l_um_type;
560 x_resource := p_recipe_rout_resc(i).resources;
561 l_assign := FALSE;
562 END IF;
563 END IF;
564 END LOOP;
565
566 /*Bug#5231180 Begin calculate the max step capacity in step qty uom*/
567 IF NVL(l_min_of_max_cap,0) > 0 THEN
568 l_temp_qty := inv_convert.inv_um_convert
569 (item_id => 0
570 ,PRECISION => gme_common_pvt.g_precision
571 ,from_quantity => l_min_of_max_cap
572 ,from_unit => l_min_of_max_cap_uom
573 ,to_unit => p_step_qty_uom
574 ,from_name => NULL
575 ,to_name => NULL);
576 IF (l_temp_qty < 0) THEN
577 RAISE error_calc_charge_conv;
578 ELSE
579 p_max_capacity := l_temp_qty;
580 END IF;
581 END IF;
582
583 p_capacity_uom := p_step_qty_uom;
584 --Bug#5231180 End
585
586 IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
587 gme_debug.put_line('Max Capcity calculated: '||p_max_capacity);
588 gme_debug.put_line('Capcity UOM : '||p_capacity_uom);
589 gme_debug.put_line ('Insert_batch_step... END calc max cap');
590 END IF;
591 EXCEPTION
592 WHEN error_rsrc_diff_um_type OR error_calc_charge_conv THEN
593 x_return_status := fnd_api.g_ret_sts_error;
594 WHEN OTHERS THEN
595 IF (NVL (g_debug, -1) = gme_debug.g_log_statement) THEN
596 gme_debug.put_line
597 ( 'GME insert_step API calc_max_cap --> when others '
598 || SQLERRM);
599 END IF;
600
601 x_return_status := fnd_api.g_ret_sts_unexp_error;
602 --Bug2804440
603 fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
604 END calc_max_capacity;
605
606
607
608 END gme_insert_step_pvt;