[Home] [Help]
PACKAGE BODY: APPS.INV_LOT_API_PUB
Source
1 PACKAGE BODY inv_lot_api_pub AS
2 /* $Header: INVPLOTB.pls 120.51.12020000.6 2013/01/31 08:19:42 alxue ship $ */
3
4 -- Global constant holding the package name
5 g_pkg_name CONSTANT VARCHAR2 ( 30 ) := 'INV_LOT_API_PUB';
6
7
8 /*****************************************************************************
9 Bug - 2181558 Additions Starts
10 1. Added a new 'type' called 'non_wms_lot_att_rec_type' to store the values
11 of Non WMS Attributes
12 2. Added a new 'procedure' called get_lot_att_from_source() to get the
13 WMS and Non WMS Lot Attributes from the Source Lot if the transaction
14 is an Intransit Transaction
15 *****************************************************************************/
16 TYPE non_wms_lot_att_rec_type IS RECORD
17 (
18 attribute_category mtl_lot_numbers.attribute_category%TYPE,
19 attribute1 mtl_lot_numbers.attribute1%TYPE,
20 attribute2 mtl_lot_numbers.attribute2%TYPE,
21 attribute3 mtl_lot_numbers.attribute3%TYPE,
22 attribute4 mtl_lot_numbers.attribute4%TYPE,
23 attribute5 mtl_lot_numbers.attribute5%TYPE,
24 attribute6 mtl_lot_numbers.attribute6%TYPE,
25 attribute7 mtl_lot_numbers.attribute7%TYPE,
26 attribute8 mtl_lot_numbers.attribute8%TYPE,
27 attribute9 mtl_lot_numbers.attribute9%TYPE,
28 attribute10 mtl_lot_numbers.attribute10%TYPE,
29 attribute11 mtl_lot_numbers.attribute11%TYPE,
30 attribute12 mtl_lot_numbers.attribute12%TYPE,
31 attribute13 mtl_lot_numbers.attribute13%TYPE,
32 attribute14 mtl_lot_numbers.attribute14%TYPE,
33 attribute15 mtl_lot_numbers.attribute15%TYPE
34 );
35
36 PROCEDURE get_lot_att_from_source (
37 x_return_status OUT NOCOPY VARCHAR2,
38 x_count OUT NOCOPY NUMBER,
39 x_source_wms_lot_att_tbl OUT NOCOPY inv_lot_sel_attr.lot_sel_attributes_tbl_type,
40 x_source_non_wms_lot_att_rec OUT NOCOPY non_wms_lot_att_rec_type,
41 p_from_organization_id IN NUMBER,
42 p_inventory_item_id IN NUMBER,
43 p_lot_number IN VARCHAR2,
44 p_count IN NUMBER,
45 p_source_wms_lot_att_tbl IN inv_lot_sel_attr.lot_sel_attributes_tbl_type
46 );
47
48 /********************** Bug - 2181558 Additions Ends ************************/
49
50
51 PROCEDURE print_debug ( p_err_msg VARCHAR2, p_level NUMBER DEFAULT 1)
52 IS
53 --l_debug number := 1;--NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
54 BEGIN
55 IF (g_debug = 1) THEN
56 inv_mobile_helper_functions.tracelog (
57 p_err_msg => p_err_msg,
58 p_module => 'INV_LOT_API_PUB',
59 p_level => p_level
60 );
61 --DBMS_OUTPUT.PUT_LINE(p_err_msg);
62 END IF;
63 --DBMS_OUTPUT.PUT_LINE(p_err_msg);
64 END print_debug;
65
66 PROCEDURE set_firstscan ( p_firstscan BOOLEAN )
67 IS
68 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
69 BEGIN
70 g_firstscan := p_firstscan;
71 END;
72
73 /* Bug 8198497 - Added this procedure to validate and update lot status correctly */
74 PROCEDURE validate_lot_status(
75 p_api_version IN NUMBER
76 , p_init_msg_list IN VARCHAR2
77 , p_organization_id IN NUMBER
78 , p_inventory_item_id IN NUMBER
79 , p_lot_number IN VARCHAR2
80 , p_status_id IN NUMBER
81 , x_return_status OUT NOCOPY VARCHAR2
82 , x_msg_count OUT NOCOPY NUMBER
83 , x_msg_data OUT NOCOPY VARCHAR
84 )
85 IS
86 l_old_status_id NUMBER;
87 l_ret_status BOOLEAN;
88 l_lot_status_enabled mtl_system_items.lot_status_enabled%TYPE; /* Bug8647949 */
89 BEGIN
90
91 print_debug('Entered validate_lot_status ', 9);
92 print_debug('validate_lot_status: Organization Id: '||p_organization_id, 9);
93 print_debug('validate_lot_status: Inventory Item Id: ' || p_inventory_item_id, 9);
94 print_debug('validate_lot_status: Lot Number: ' || p_lot_number, 9);
95 print_debug('validate_lot_status: Status Id ' || p_status_id, 9);
96
97 /* Bug8647949 - Fetching lot_status_enabled code of Item and Calling validate_lot_status
98 only when lot_status_enabled is 'Y' */
99 Select nvl(lot_status_enabled,'N')
100 into l_lot_status_enabled
101 from mtl_system_items
102 where organization_id= p_organization_id
103 and inventory_item_id= p_inventory_item_id;
104
105 IF(l_lot_status_enabled= 'Y' and (p_status_id <> g_miss_num or p_status_id is not null)) then
106 -- Get old status id
107 select status_id
108 into l_old_status_id
109 from mtl_lot_numbers
110 where organization_id = p_organization_id
111 and inventory_item_id = p_inventory_item_id
112 and lot_number = p_lot_number;
113
114 print_debug('validate_lot_status: Old Status Id ' || l_old_status_id, 9);
115
116 -- if no data found then no update
117
118 -- if lot exists then call validate_mtstatus
119 l_ret_status := INV_MATERIAL_STATUS_PKG.validate_mtstatus(
120 p_old_status_id => l_old_status_id
121 ,p_new_status_id => p_status_id
122 ,p_subinventory_code => NULL
123 ,p_locator_id => NULL
124 ,p_organization_id => p_organization_id
125 ,p_inventory_item_id => p_inventory_item_id
126 ,P_lot_number => p_lot_number) ;
127
128
129 if (l_ret_status) then
130 print_debug('validate_lot_status: Returned true from validate_mtstatus ', 9);
131 else
132 print_debug('validate_lot_status: Returned false from validate_mtstatus ', 9);
133 x_return_status := fnd_api.g_ret_sts_error;
134 x_msg_data := fnd_message.GET_STRING('INV', 'INV_STATUS_UPD_RESV_FAIL');
135 x_msg_count := 1;
136 return;
137 end if;
138
139 -- if returned true then call inv_material_status_grp.update_status
140 IF (l_ret_status) then
141
142 print_debug('validate_lot_status: Before calling inv_material_status_grp.update_status', 9);
143
144 INV_MATERIAL_STATUS_GRP.update_status
145 ( p_api_version
146 , p_init_msg_list
147 , x_return_status
148 , x_msg_count
149 , x_msg_data
150 , 2
151 , p_status_id
152 , p_organization_id
153 , p_inventory_item_id
154 , NULL
155 , NULL
156 , p_lot_number
157 , NULL
158 , NULL
159 , 'O'
160 , NULL
161 ) ;
162
163 print_debug('validate_lot_status: Return status from inv_material_status_grp.update_status: '||x_return_status, 9);
164 END IF;
165 ELSIF (l_lot_status_enabled = 'N' ) then
166 x_return_status := fnd_api.g_ret_sts_success;
167 x_msg_data := fnd_message.GET_STRING('INV', 'INV_NOT_VALID');
168 x_msg_count := 1;
169 END IF;
170 /* End of Fix for Bug8647949 */
171
172 EXCEPTION
173 WHEN OTHERS THEN
174 x_return_status := g_ret_sts_unexp_error;
175 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
176 if( x_msg_count > 1 ) then
177 x_msg_data := fnd_msg_pub.get(x_msg_count, FND_API.G_FALSE);
178 end if;
179 print_debug('validate_lot_status: In others ' || SQLERRM, 9);
180 END validate_lot_status;
181
182 PROCEDURE populateattributescolumn
183 IS
184 l_column_idx BINARY_INTEGER;
185 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
186 BEGIN
187 g_lot_attributes_tbl ( 1 ).column_name := 'VENDOR_ID';
188 g_lot_attributes_tbl ( 1 ).column_type := 'NUMBER';
189 g_lot_attributes_tbl ( 2 ).column_name := 'GRADE_CODE';
190 g_lot_attributes_tbl ( 2 ).column_type := 'VARCHAR2';
191 g_lot_attributes_tbl ( 3 ).column_name := 'ORIGINATION_DATE';
192 g_lot_attributes_tbl ( 3 ).column_type := 'DATE';
193 g_lot_attributes_tbl ( 4 ).column_name := 'DATE_CODE';
194 g_lot_attributes_tbl ( 4 ).column_type := 'VARCHAR2';
195 g_lot_attributes_tbl ( 5 ).column_name := 'STATUS_ID';
196 g_lot_attributes_tbl ( 5 ).column_type := 'NUMBER';
197 g_lot_attributes_tbl ( 6 ).column_name := 'CHANGE_DATE';
198 g_lot_attributes_tbl ( 6 ).column_type := 'DATE';
199 g_lot_attributes_tbl ( 7 ).column_name := 'AGE';
200 g_lot_attributes_tbl ( 7 ).column_type := 'NUMBER';
201 g_lot_attributes_tbl ( 8 ).column_name := 'RETEST_DATE';
202 g_lot_attributes_tbl ( 8 ).column_type := 'DATE';
203 g_lot_attributes_tbl ( 9 ).column_name := 'MATURITY_DATE';
204 g_lot_attributes_tbl ( 9 ).column_type := 'DATE';
205 g_lot_attributes_tbl ( 10 ).column_name := 'LOT_ATTRIBUTE_CATEGORY';
206 g_lot_attributes_tbl ( 10 ).column_type := 'VARCHAR2';
207 g_lot_attributes_tbl ( 11 ).column_name := 'ITEM_SIZE';
208 g_lot_attributes_tbl ( 11 ).column_type := 'NUMBER';
209 g_lot_attributes_tbl ( 12 ).column_name := 'COLOR';
210 g_lot_attributes_tbl ( 12 ).column_type := 'VARCHAR2';
211 g_lot_attributes_tbl ( 13 ).column_name := 'VOLUME';
212 g_lot_attributes_tbl ( 13 ).column_type := 'NUMBER';
213 g_lot_attributes_tbl ( 14 ).column_name := 'VOLUME_UOM';
214 g_lot_attributes_tbl ( 14 ).column_type := 'VARCHAR2';
215 g_lot_attributes_tbl ( 15 ).column_name := 'PLACE_OF_ORIGIN';
216 g_lot_attributes_tbl ( 15 ).column_type := 'VARCHAR2';
217 g_lot_attributes_tbl ( 16 ).column_name := 'BEST_BY_DATE';
218 g_lot_attributes_tbl ( 16 ).column_type := 'DATE';
219 g_lot_attributes_tbl ( 17 ).column_name := 'LENGTH';
220 g_lot_attributes_tbl ( 17 ).column_type := 'NUMBER';
221 g_lot_attributes_tbl ( 18 ).column_name := 'LENGTH_UOM';
222 g_lot_attributes_tbl ( 18 ).column_type := 'VARCHAR2';
223 g_lot_attributes_tbl ( 19 ).column_name := 'RECYCLED_CONTENT';
224 g_lot_attributes_tbl ( 19 ).column_type := 'NUMBER';
225 g_lot_attributes_tbl ( 20 ).column_name := 'THICKNESS';
226 g_lot_attributes_tbl ( 20 ).column_type := 'NUMBER';
227 g_lot_attributes_tbl ( 21 ).column_name := 'THICKNESS_UOM';
228 g_lot_attributes_tbl ( 21 ).column_type := 'VARCHAR2';
229 g_lot_attributes_tbl ( 22 ).column_name := 'WIDTH';
230 g_lot_attributes_tbl ( 22 ).column_type := 'NUMBER';
231 g_lot_attributes_tbl ( 23 ).column_name := 'WIDTH_UOM';
232 g_lot_attributes_tbl ( 23 ).column_type := 'VARCHAR2';
233 g_lot_attributes_tbl ( 24 ).column_name := 'CURL_WRINKLE_FOLD';
234 g_lot_attributes_tbl ( 24 ).column_type := 'VARCHAR2';
235 g_lot_attributes_tbl ( 25 ).column_name := 'C_ATTRIBUTE1';
236 g_lot_attributes_tbl ( 25 ).column_type := 'VARCHAR2';
237 g_lot_attributes_tbl ( 26 ).column_name := 'C_ATTRIBUTE2';
238 g_lot_attributes_tbl ( 26 ).column_type := 'VARCHAR2';
239 g_lot_attributes_tbl ( 27 ).column_name := 'C_ATTRIBUTE3';
240 g_lot_attributes_tbl ( 27 ).column_type := 'VARCHAR2';
241 g_lot_attributes_tbl ( 28 ).column_name := 'C_ATTRIBUTE4';
242 g_lot_attributes_tbl ( 28 ).column_type := 'VARCHAR2';
243 g_lot_attributes_tbl ( 29 ).column_name := 'C_ATTRIBUTE5';
244 g_lot_attributes_tbl ( 29 ).column_type := 'VARCHAR2';
245 g_lot_attributes_tbl ( 30 ).column_name := 'C_ATTRIBUTE6';
246 g_lot_attributes_tbl ( 30 ).column_type := 'VARCHAR2';
247 g_lot_attributes_tbl ( 31 ).column_name := 'C_ATTRIBUTE7';
248 g_lot_attributes_tbl ( 31 ).column_type := 'VARCHAR2';
249 g_lot_attributes_tbl ( 32 ).column_name := 'C_ATTRIBUTE8';
250 g_lot_attributes_tbl ( 32 ).column_type := 'VARCHAR2';
251 g_lot_attributes_tbl ( 33 ).column_name := 'C_ATTRIBUTE9';
252 g_lot_attributes_tbl ( 33 ).column_type := 'VARCHAR2';
253 g_lot_attributes_tbl ( 34 ).column_name := 'C_ATTRIBUTE10';
254 g_lot_attributes_tbl ( 34 ).column_type := 'VARCHAR2';
255 g_lot_attributes_tbl ( 35 ).column_name := 'C_ATTRIBUTE11';
256 g_lot_attributes_tbl ( 35 ).column_type := 'VARCHAR2';
257 g_lot_attributes_tbl ( 36 ).column_name := 'C_ATTRIBUTE12';
258 g_lot_attributes_tbl ( 36 ).column_type := 'VARCHAR2';
259 g_lot_attributes_tbl ( 37 ).column_name := 'C_ATTRIBUTE13';
260 g_lot_attributes_tbl ( 37 ).column_type := 'VARCHAR2';
261 g_lot_attributes_tbl ( 38 ).column_name := 'C_ATTRIBUTE14';
262 g_lot_attributes_tbl ( 38 ).column_type := 'VARCHAR2';
263 g_lot_attributes_tbl ( 39 ).column_name := 'C_ATTRIBUTE15';
264 g_lot_attributes_tbl ( 39 ).column_type := 'VARCHAR2';
265 g_lot_attributes_tbl ( 40 ).column_name := 'C_ATTRIBUTE16';
266 g_lot_attributes_tbl ( 40 ).column_type := 'VARCHAR2';
267 g_lot_attributes_tbl ( 41 ).column_name := 'C_ATTRIBUTE17';
268 g_lot_attributes_tbl ( 41 ).column_type := 'VARCHAR2';
269 g_lot_attributes_tbl ( 42 ).column_name := 'C_ATTRIBUTE18';
270 g_lot_attributes_tbl ( 42 ).column_type := 'VARCHAR2';
271 g_lot_attributes_tbl ( 43 ).column_name := 'C_ATTRIBUTE19';
272 g_lot_attributes_tbl ( 43 ).column_type := 'VARCHAR2';
273 g_lot_attributes_tbl ( 44 ).column_name := 'C_ATTRIBUTE20';
274 g_lot_attributes_tbl ( 44 ).column_type := 'VARCHAR2';
275 g_lot_attributes_tbl ( 45 ).column_name := 'D_ATTRIBUTE1';
276 g_lot_attributes_tbl ( 45 ).column_type := 'DATE';
277 g_lot_attributes_tbl ( 46 ).column_name := 'D_ATTRIBUTE2';
278 g_lot_attributes_tbl ( 46 ).column_type := 'DATE';
279 g_lot_attributes_tbl ( 47 ).column_name := 'D_ATTRIBUTE3';
280 g_lot_attributes_tbl ( 47 ).column_type := 'DATE';
281 g_lot_attributes_tbl ( 48 ).column_name := 'D_ATTRIBUTE4';
282 g_lot_attributes_tbl ( 48 ).column_type := 'DATE';
283 g_lot_attributes_tbl ( 49 ).column_name := 'D_ATTRIBUTE5';
284 g_lot_attributes_tbl ( 49 ).column_type := 'DATE';
285 g_lot_attributes_tbl ( 50 ).column_name := 'D_ATTRIBUTE6';
286 g_lot_attributes_tbl ( 50 ).column_type := 'DATE';
287 g_lot_attributes_tbl ( 51 ).column_name := 'D_ATTRIBUTE7';
288 g_lot_attributes_tbl ( 51 ).column_type := 'DATE';
289 g_lot_attributes_tbl ( 52 ).column_name := 'D_ATTRIBUTE8';
290 g_lot_attributes_tbl ( 52 ).column_type := 'DATE';
291 g_lot_attributes_tbl ( 53 ).column_name := 'D_ATTRIBUTE9';
292 g_lot_attributes_tbl ( 53 ).column_type := 'DATE';
293 g_lot_attributes_tbl ( 54 ).column_name := 'D_ATTRIBUTE10';
294 g_lot_attributes_tbl ( 54 ).column_type := 'DATE';
295 g_lot_attributes_tbl ( 55 ).column_name := 'N_ATTRIBUTE1';
296 g_lot_attributes_tbl ( 55 ).column_type := 'NUMBER';
297 g_lot_attributes_tbl ( 56 ).column_name := 'N_ATTRIBUTE2';
298 g_lot_attributes_tbl ( 56 ).column_type := 'NUMBER';
299 g_lot_attributes_tbl ( 57 ).column_name := 'N_ATTRIBUTE3';
300 g_lot_attributes_tbl ( 57 ).column_type := 'NUMBER';
301 g_lot_attributes_tbl ( 58 ).column_name := 'N_ATTRIBUTE4';
302 g_lot_attributes_tbl ( 58 ).column_type := 'NUMBER';
303 g_lot_attributes_tbl ( 59 ).column_name := 'N_ATTRIBUTE5';
304 g_lot_attributes_tbl ( 59 ).column_type := 'NUMBER';
305 g_lot_attributes_tbl ( 60 ).column_name := 'N_ATTRIBUTE6';
306 g_lot_attributes_tbl ( 60 ).column_type := 'NUMBER';
307 g_lot_attributes_tbl ( 61 ).column_name := 'N_ATTRIBUTE7';
308 g_lot_attributes_tbl ( 61 ).column_type := 'NUMBER';
309 g_lot_attributes_tbl ( 62 ).column_name := 'N_ATTRIBUTE8';
310 g_lot_attributes_tbl ( 62 ).column_type := 'NUMBER';
311 g_lot_attributes_tbl ( 63 ).column_name := 'N_ATTRIBUTE10';
312 g_lot_attributes_tbl ( 63 ).column_type := 'NUMBER';
313 g_lot_attributes_tbl ( 64 ).column_name := 'SUPPLIER_LOT_NUMBER';
314 g_lot_attributes_tbl ( 64 ).column_type := 'VARCHAR2';
315 g_lot_attributes_tbl ( 65 ).column_name := 'N_ATTRIBUTE9';
316 g_lot_attributes_tbl ( 65 ).column_type := 'NUMBER';
317 g_lot_attributes_tbl ( 66 ).column_name := 'TERRITORY_CODE';
318 g_lot_attributes_tbl ( 66 ).column_type := 'VARCHAR2';
319 -- Added 05/16/2001
320 g_lot_attributes_tbl ( 67 ).column_name := 'VENDOR_NAME';
321 g_lot_attributes_tbl ( 67 ).column_type := 'VARCHAR2';
322 g_lot_attributes_tbl ( 68 ).column_name := 'DESCRIPTION';
323 g_lot_attributes_tbl ( 68 ).column_type := 'VARCHAR2';
324 END;
325
326 PROCEDURE insertlot (
327 p_api_version IN NUMBER,
328 p_init_msg_list IN VARCHAR2 := fnd_api.g_false,
329 p_commit IN VARCHAR2 := fnd_api.g_false,
330 p_validation_level IN NUMBER
331 := fnd_api.g_valid_level_full,
332 p_inventory_item_id IN NUMBER,
333 p_organization_id IN NUMBER,
334 p_lot_number IN VARCHAR2,
335 p_expiration_date IN OUT NOCOPY DATE,
336 p_transaction_temp_id IN NUMBER DEFAULT NULL,
337 p_transaction_action_id IN NUMBER DEFAULT NULL,
338 p_transfer_organization_id IN NUMBER DEFAULT NULL,
339 x_object_id OUT NOCOPY NUMBER,
340 x_return_status OUT NOCOPY VARCHAR2,
341 x_msg_count OUT NOCOPY NUMBER,
342 x_msg_data OUT NOCOPY VARCHAR2,
343 p_parent_lot_number IN VARCHAR2 DEFAULT NULL, --bug 10176719 - inserting parent lot number
344 p_origination_type IN NUMBER DEFAULT NULL --bug 15896641 - inserting origination type
345 )
346 IS
347 l_api_version CONSTANT NUMBER := 1.0;
348 l_api_name CONSTANT VARCHAR2 ( 30 ) := 'insertLot';
349 l_lot_control_code NUMBER;
350 l_lotunique NUMBER;
351 l_lotcount NUMBER;
352 l_userid NUMBER;
353 l_loginid NUMBER;
354 l_shelf_life_code NUMBER;
355 l_shelf_life_days NUMBER;
356 l_attributes_default inv_lot_sel_attr.lot_sel_attributes_tbl_type;
357 l_attributes_default_count NUMBER;
358 l_attributes_in inv_lot_sel_attr.lot_sel_attributes_tbl_type;
359 l_column_idx BINARY_INTEGER;
360 l_return_status VARCHAR2 ( 1 );
361 l_msg_data VARCHAR2 ( 2000 );
362 l_msg_count NUMBER;
363 l_input_idx BINARY_INTEGER;
364
365 -- Bug# 1520495
366 l_lot_status_enabled VARCHAR2 ( 1 );
367 l_default_lot_status_id NUMBER := NULL;
368 l_serial_status_enabled VARCHAR2 ( 1 );
369 l_default_serial_status_id NUMBER;
370 l_status_rec inv_material_status_pub.mtl_status_update_rec_type;
371
372 -- Bug 2181558 Variable Declaration Starts
373 l_att_after_source_copy inv_lot_sel_attr.lot_sel_attributes_tbl_type;
374 l_source_non_wms_lot_att_rec non_wms_lot_att_rec_type;
375 l_num_wms_lot_att_copied NUMBER;
376 -- Bug 2181558 Variable Declaration Ends
377 l_dest_status_enabled VARCHAR2(1); --Added bug4066234
378
379 CURSOR lot_temp_csr ( p_lot_number VARCHAR2, p_trx_temp_id NUMBER )
380 IS
381 SELECT TO_CHAR ( vendor_id ),
382 grade_code,
383 fnd_date.date_to_canonical ( origination_date ),
384 date_code,
385 TO_CHAR ( status_id ),
386 fnd_date.date_to_canonical ( change_date ),
387 TO_NUMBER ( age ),
388 fnd_date.date_to_canonical ( retest_date ),
389 fnd_date.date_to_canonical ( maturity_date ),
390 lot_attribute_category,
391 TO_CHAR ( item_size ),
392 color,
393 TO_CHAR ( volume ),
394 volume_uom,
395 place_of_origin,
396 fnd_date.date_to_canonical ( best_by_date ),
397 TO_CHAR ( LENGTH ),
398 length_uom,
399 TO_CHAR ( recycled_content ),
400 TO_CHAR ( thickness ),
401 thickness_uom,
402 TO_CHAR ( width ),
403 width_uom,
404 curl_wrinkle_fold,
405 c_attribute1,
406 c_attribute2,
407 c_attribute3,
408 c_attribute4,
409 c_attribute5,
410 c_attribute6,
411 c_attribute7,
412 c_attribute8,
413 c_attribute9,
414 c_attribute10,
415 c_attribute11,
416 c_attribute12,
417 c_attribute13,
418 c_attribute14,
419 c_attribute15,
420 c_attribute16,
421 c_attribute17,
422 c_attribute18,
423 c_attribute19,
424 c_attribute20,
425 fnd_date.date_to_canonical ( d_attribute1 ),
426 fnd_date.date_to_canonical ( d_attribute2 ),
427 fnd_date.date_to_canonical ( d_attribute3 ),
428 fnd_date.date_to_canonical ( d_attribute4 ),
429 fnd_date.date_to_canonical ( d_attribute5 ),
430 fnd_date.date_to_canonical ( d_attribute6 ),
431 fnd_date.date_to_canonical ( d_attribute7 ),
432 fnd_date.date_to_canonical ( d_attribute8 ),
433 fnd_date.date_to_canonical ( d_attribute9 ),
434 fnd_date.date_to_canonical ( d_attribute10 ),
435 TO_CHAR ( n_attribute1 ),
436 TO_CHAR ( n_attribute2 ),
437 TO_CHAR ( n_attribute3 ),
438 TO_CHAR ( n_attribute4 ),
439 TO_CHAR ( n_attribute5 ),
440 TO_CHAR ( n_attribute6 ),
441 TO_CHAR ( n_attribute7 ),
442 TO_CHAR ( n_attribute8 ),
443 TO_CHAR ( n_attribute10 ),
444 supplier_lot_number,
445 TO_CHAR ( n_attribute9 ),
446 territory_code,
447 vendor_name,
448 description
449 FROM mtl_transaction_lots_temp
450 WHERE lot_number = p_lot_number
451 AND transaction_temp_id = p_trx_temp_id;
452 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
453 BEGIN
454 IF (l_debug = 1) THEN
455 inv_pick_wave_pick_confirm_pub.tracelog ( 'Inside InsertLot API' , 'INV_LOT_API_PUB');
456 END IF;
457 -- Standard Start of API savepoint
458 SAVEPOINT apiinsertlot_apipub;
459
460 -- Standard call to check for call compatibility.
461 IF NOT fnd_api.compatible_api_call ( l_api_version, p_api_version, l_api_name, g_pkg_name) THEN
462 RAISE fnd_api.g_exc_unexpected_error;
463 END IF;
464
465 -- Initialize message list if p_init_msg_list is set to TRUE.
466 IF fnd_api.to_boolean ( p_init_msg_list ) THEN
467 fnd_msg_pub.initialize;
468 END IF;
469
470 -- Initialize API return status to success
471 x_return_status := fnd_api.g_ret_sts_success;
472
473 -- API body
474 IF ( g_firstscan = TRUE AND p_transaction_action_id = 3) THEN
475 x_return_status := fnd_api.g_ret_sts_success;
476 ELSE
477 BEGIN
478 SELECT lot_control_code
479 INTO l_lot_control_code
480 FROM mtl_system_items
481 WHERE inventory_item_id = p_inventory_item_id
482 AND organization_id = p_organization_id;
483
484 IF ( l_lot_control_code = 1 )
485 THEN
486 fnd_message.set_name ('INV' , 'INV_NO_LOT_CONTROL' );
487 fnd_msg_pub.ADD;
488 x_return_status := fnd_api.g_ret_sts_error;
489 RAISE fnd_api.g_exc_unexpected_error;
490 END IF;
491 EXCEPTION
492 WHEN NO_DATA_FOUND
493 THEN
494 IF (l_debug = 1) THEN
495 inv_pick_wave_pick_confirm_pub.tracelog ( 'Exception in LOT_CONTROL_CODE' , 'INV_LOT_API_PUB');
496 END IF;
497 fnd_message.set_name ('INV' , 'INV_INVALID_ITEM' );
498 fnd_msg_pub.ADD;
499 x_return_status := fnd_api.g_ret_sts_error;
500 RAISE fnd_api.g_exc_unexpected_error;
501 END;
502
503 SELECT lot_number_uniqueness
504 INTO l_lotunique
505 FROM mtl_parameters
506 WHERE organization_id = p_organization_id;
507
508 SELECT lot_status_enabled --Added select for bug4066234
509 INTO l_dest_status_enabled
510 FROM mtl_system_items
511 WHERE
512 inventory_item_id=p_inventory_item_id and
513 organization_id=p_organization_id;
514
515 IF ( l_lotunique = 1 ) THEN
516 SELECT COUNT ( 1 )
517 INTO l_lotcount
518 FROM mtl_lot_numbers
519 WHERE inventory_item_id <> p_inventory_item_id
520 AND lot_number = p_lot_number
521 AND NOT EXISTS ( SELECT NULL
522 FROM mtl_lot_numbers lot
523 WHERE lot.lot_number = p_lot_number
524 AND lot.organization_id = p_organization_id
525 AND lot.inventory_item_id = p_inventory_item_id );
526
527 IF ( l_lotcount > 0 ) THEN
528 fnd_message.set_name ('INV' , 'INV_INT_LOTUNIQEXP' );
529 fnd_msg_pub.ADD;
530 x_return_status := fnd_api.g_ret_sts_error;
531 RAISE fnd_api.g_exc_unexpected_error;
532 IF (l_debug = 1) THEN
533 inv_pick_wave_pick_confirm_pub.tracelog ( 'Exception in MTL_LOT_NUMBER' , 'INV_LOT_API_PUB');
534 END IF;
535 END IF;
536 END IF;
537
538 l_lotcount := 0;
539
540 SELECT COUNT ( 1 )
541 INTO l_lotcount
542 FROM mtl_lot_numbers
543 WHERE inventory_item_id = p_inventory_item_id
544 AND organization_id = p_organization_id
545 AND lot_number = p_lot_number;
546
547 IF ( l_lotcount = 0 ) THEN
548 l_userid := fnd_global.user_id;
549 l_loginid := fnd_global.login_id;
550
551 IF ( p_expiration_date IS NULL ) THEN
552 SELECT shelf_life_code,
553 shelf_life_days
554 INTO l_shelf_life_code,
555 l_shelf_life_days
556 FROM mtl_system_items
557 WHERE inventory_item_id = p_inventory_item_id
558 AND organization_id = p_organization_id;
559
560 IF ( l_shelf_life_code = 2 ) THEN
561 SELECT SYSDATE + l_shelf_life_days
562 INTO p_expiration_date
563 FROM DUAL;
564 ELSIF ( l_shelf_life_code = 4 ) THEN
565 fnd_message.set_name ('INV' , 'INV_LOT_EXPREQD' );
566 fnd_msg_pub.ADD;
567 x_return_status := fnd_api.g_ret_sts_error;
568 RAISE fnd_api.g_exc_unexpected_error;
569 END IF;
570 END IF;
571
572 IF (l_debug = 1) THEN
573 inv_pick_wave_pick_confirm_pub.tracelog ( 'Before calling populateattributesColumn' , 'INV_LOT_API_PUB');
574 END IF;
575
576 SELECT mtl_gen_object_id_s.NEXTVAL
577 INTO x_object_id
578 FROM DUAL;
579
580 populateattributescolumn ( );
581 IF (l_debug = 1) THEN
582 inv_pick_wave_pick_confirm_pub.tracelog ( 'After calling populateattributesColumn' , 'INV_LOT_API_PUB');
583 END IF;
584
585 IF ( p_transaction_temp_id IS NOT NULL ) THEN
586 IF (l_debug = 1) THEN
587 inv_pick_wave_pick_confirm_pub.tracelog ( 'p_transaction_temp_id' || p_transaction_temp_id, 'INV_LOT_API_PUB');
588 END IF;
589 OPEN lot_temp_csr ( p_lot_number, p_transaction_temp_id );
590
591 LOOP
592 FETCH lot_temp_csr INTO g_lot_attributes_tbl ( 1 ).column_value,
593 g_lot_attributes_tbl ( 2 ).column_value,
594 g_lot_attributes_tbl ( 3 ).column_value,
595 g_lot_attributes_tbl ( 4 ).column_value,
596 g_lot_attributes_tbl ( 5 ).column_value,
597 g_lot_attributes_tbl ( 6 ).column_value,
598 g_lot_attributes_tbl ( 7 ).column_value,
599 g_lot_attributes_tbl ( 8 ).column_value,
600 g_lot_attributes_tbl ( 9 ).column_value,
601 g_lot_attributes_tbl ( 10 ).column_value,
602 g_lot_attributes_tbl ( 11 ).column_value,
603 g_lot_attributes_tbl ( 12 ).column_value,
604 g_lot_attributes_tbl ( 13 ).column_value,
605 g_lot_attributes_tbl ( 14 ).column_value,
606 g_lot_attributes_tbl ( 15 ).column_value,
607 g_lot_attributes_tbl ( 16 ).column_value,
608 g_lot_attributes_tbl ( 17 ).column_value,
609 g_lot_attributes_tbl ( 18 ).column_value,
610 g_lot_attributes_tbl ( 19 ).column_value,
611 g_lot_attributes_tbl ( 20 ).column_value,
612 g_lot_attributes_tbl ( 21 ).column_value,
613 g_lot_attributes_tbl ( 22 ).column_value,
614 g_lot_attributes_tbl ( 23 ).column_value,
615 g_lot_attributes_tbl ( 24 ).column_value,
616 g_lot_attributes_tbl ( 25 ).column_value,
617 g_lot_attributes_tbl ( 26 ).column_value,
618 g_lot_attributes_tbl ( 27 ).column_value,
619 g_lot_attributes_tbl ( 28 ).column_value,
620 g_lot_attributes_tbl ( 29 ).column_value,
621 g_lot_attributes_tbl ( 30 ).column_value,
622 g_lot_attributes_tbl ( 31 ).column_value,
623 g_lot_attributes_tbl ( 32 ).column_value,
624 g_lot_attributes_tbl ( 33 ).column_value,
625 g_lot_attributes_tbl ( 34 ).column_value,
626 g_lot_attributes_tbl ( 35 ).column_value,
627 g_lot_attributes_tbl ( 36 ).column_value,
628 g_lot_attributes_tbl ( 37 ).column_value,
629 g_lot_attributes_tbl ( 38 ).column_value,
630 g_lot_attributes_tbl ( 39 ).column_value,
631 g_lot_attributes_tbl ( 40 ).column_value,
632 g_lot_attributes_tbl ( 41 ).column_value,
633 g_lot_attributes_tbl ( 42 ).column_value,
634 g_lot_attributes_tbl ( 43 ).column_value,
635 g_lot_attributes_tbl ( 44 ).column_value,
636 g_lot_attributes_tbl ( 45 ).column_value,
637 g_lot_attributes_tbl ( 46 ).column_value,
638 g_lot_attributes_tbl ( 47 ).column_value,
639 g_lot_attributes_tbl ( 48 ).column_value,
640 g_lot_attributes_tbl ( 49 ).column_value,
641 g_lot_attributes_tbl ( 50 ).column_value,
642 g_lot_attributes_tbl ( 51 ).column_value,
643 g_lot_attributes_tbl ( 52 ).column_value,
644 g_lot_attributes_tbl ( 53 ).column_value,
645 g_lot_attributes_tbl ( 54 ).column_value,
646 g_lot_attributes_tbl ( 55 ).column_value,
647 g_lot_attributes_tbl ( 56 ).column_value,
648 g_lot_attributes_tbl ( 57 ).column_value,
649 g_lot_attributes_tbl ( 58 ).column_value,
650 g_lot_attributes_tbl ( 59 ).column_value,
651 g_lot_attributes_tbl ( 60 ).column_value,
652 g_lot_attributes_tbl ( 61 ).column_value,
653 g_lot_attributes_tbl ( 62 ).column_value,
654 g_lot_attributes_tbl ( 63 ).column_value,
655 g_lot_attributes_tbl ( 64 ).column_value,
656 g_lot_attributes_tbl ( 65 ).column_value,
657 g_lot_attributes_tbl ( 66 ).column_value,
658 g_lot_attributes_tbl ( 67 ).column_value,
659 g_lot_attributes_tbl ( 68 ).column_value;
660 EXIT WHEN lot_temp_csr%NOTFOUND;
661 END LOOP;
662
663 CLOSE lot_temp_csr;
664 l_input_idx := 0;
665
666 FOR x IN 1 .. 68
667 LOOP
668 IF ( g_lot_attributes_tbl ( x ).column_value IS NOT NULL ) THEN
669 l_input_idx := l_input_idx + 1;
670 l_attributes_in ( l_input_idx ).column_name := g_lot_attributes_tbl ( x ).column_name;
671 l_attributes_in ( l_input_idx ).column_value := g_lot_attributes_tbl ( x ).column_value;
672 l_attributes_in ( l_input_idx ).column_type := g_lot_attributes_tbl ( x ).column_type;
673 END IF;
674 END LOOP;
675 END IF;
676
677 IF (( p_transaction_action_id IS NOT NULL AND p_transaction_action_id = 3 AND g_firstscan = FALSE)
678 OR ( p_transaction_action_id is not null AND p_transaction_action_id = 12 )) THEN
679 IF (l_debug = 1) THEN
680 inv_pick_wave_pick_confirm_pub.tracelog ( 'Before Insert action_id=3' , 'INV_LOT_API_PUB');
681 END IF;
682 BEGIN
683 select count(*)
684 into l_lotcount
685 From mtl_lot_numbers
686 where organization_id = p_transfer_organization_id
687 and inventory_item_id = p_inventory_item_id
688 and lot_number = p_lot_number;
689
690 if( l_lotcount > 0 ) then
691 INSERT INTO mtl_lot_numbers
692 (
693 inventory_item_id,
694 organization_id,
695 lot_number,
696 last_update_date,
697 last_updated_by,
698 creation_date,
699 created_by,
700 last_update_login,
701 expiration_date,
702 disable_flag,
703 attribute_category,
704 attribute1,
705 attribute2,
706 attribute3,
707 attribute4,
708 attribute5,
709 attribute6,
710 attribute7,
711 attribute8,
712 attribute9,
713 attribute10,
714 attribute11,
715 attribute12,
716 attribute13,
717 attribute14,
718 attribute15,
719 request_id,
720 program_application_id,
721 program_id,
722 program_update_date,
723 gen_object_id,
724 description,
725 vendor_id,
726 grade_code,
727 origination_date,
728 date_code,
729 status_id,
730 change_date,
731 age,
732 retest_date,
733 maturity_date,
734 lot_attribute_category,
735 item_size,
736 color,
737 volume,
738 volume_uom,
739 place_of_origin,
740 best_by_date,
741 LENGTH,
742 length_uom,
743 recycled_content,
744 thickness,
745 thickness_uom,
746 width,
747 width_uom,
748 curl_wrinkle_fold,
749 c_attribute1,
750 c_attribute2,
751 c_attribute3,
752 c_attribute4,
753 c_attribute5,
754 c_attribute6,
755 c_attribute7,
756 c_attribute8,
757 c_attribute9,
758 c_attribute10,
759 c_attribute11,
760 c_attribute12,
761 c_attribute13,
762 c_attribute14,
763 c_attribute15,
764 c_attribute16,
765 c_attribute17,
766 c_attribute18,
767 c_attribute19,
768 c_attribute20,
769 d_attribute1,
770 d_attribute2,
771 d_attribute3,
772 d_attribute4,
773 d_attribute5,
774 d_attribute6,
775 d_attribute7,
776 d_attribute8,
777 d_attribute9,
778 d_attribute10,
779 n_attribute1,
780 n_attribute2,
781 n_attribute3,
782 n_attribute4,
783 n_attribute5,
784 n_attribute6,
785 n_attribute7,
786 n_attribute8,
787 n_attribute9,
788 supplier_lot_number,
789 n_attribute10,
790 territory_code,
791 vendor_name,
792 parent_lot_number -- bug 10176719 - inserting parent lot number
793 )
794 SELECT inventory_item_id,
795 p_organization_id,
796 p_lot_number,
797 SYSDATE,
798 l_userid,
799 creation_date,
800 created_by,
801 last_update_login,
802 expiration_date,
803 disable_flag,
804 attribute_category,
805 attribute1,
806 attribute2,
807 attribute3,
808 attribute4,
809 attribute5,
810 attribute6,
811 attribute7,
812 attribute8,
813 attribute9,
814 attribute10,
815 attribute11,
816 attribute12,
817 attribute13,
818 attribute14,
819 attribute15,
820 request_id,
821 program_application_id,
822 program_id,
823 program_update_date,
824 x_object_id,
825 description,
826 vendor_id,
827 grade_code,
828 origination_date,
829 date_code,
830 decode(l_dest_status_enabled,'Y',status_id,1), --Added bug4066234,
831 change_date,
832 age,
833 retest_date,
834 maturity_date,
835 lot_attribute_category,
836 item_size,
837 color,
838 volume,
839 volume_uom,
840 place_of_origin,
841 best_by_date,
842 LENGTH,
843 length_uom,
844 recycled_content,
845 thickness,
846 thickness_uom,
847 width,
848 width_uom,
849 curl_wrinkle_fold,
850 c_attribute1,
851 c_attribute2,
852 c_attribute3,
853 c_attribute4,
854 c_attribute5,
855 c_attribute6,
856 c_attribute7,
857 c_attribute8,
858 c_attribute9,
859 c_attribute10,
860 c_attribute11,
861 c_attribute12,
862 c_attribute13,
863 c_attribute14,
864 c_attribute15,
865 c_attribute16,
866 c_attribute17,
867 c_attribute18,
868 c_attribute19,
869 c_attribute20,
870 d_attribute1,
871 d_attribute2,
872 d_attribute3,
873 d_attribute4,
874 d_attribute5,
875 d_attribute6,
876 d_attribute7,
877 d_attribute8,
878 d_attribute9,
879 d_attribute10,
880 n_attribute1,
881 n_attribute2,
882 n_attribute3,
883 n_attribute4,
884 n_attribute5,
885 n_attribute6,
886 n_attribute7,
887 n_attribute8,
888 n_attribute9,
889 supplier_lot_number,
890 n_attribute10,
891 territory_code,
892 vendor_name,
893 p_parent_lot_number -- bug 10176719 - inserting parent lot number
894 FROM mtl_lot_numbers
895 WHERE organization_id = p_transfer_organization_id
896 AND inventory_item_id = p_inventory_item_id
897 AND lot_number = p_lot_number
898 AND NOT EXISTS ( SELECT NULL
899 FROM mtl_lot_numbers lot
900 WHERE lot.lot_number = p_lot_number
901 AND lot.organization_id = p_organization_id
902 AND lot.inventory_item_id = p_inventory_item_id );
903 else
904 INSERT INTO mtl_lot_numbers
905 (
906 inventory_item_id,
907 organization_id,
908 lot_number,
909 last_update_date,
910 last_updated_by,
911 creation_date,
912 created_by,
913 last_update_login,
914 expiration_date,
915 request_id,
916 program_application_id,
917 program_id,
918 program_update_date,
919 gen_object_id,
920 description,
921 vendor_id,
922 grade_code,
923 origination_date,
924 date_code,
925 status_id,
926 change_date,
927 age,
928 retest_date,
929 maturity_date,
930 lot_attribute_category,
931 item_size,
932 color,
933 volume,
934 volume_uom,
935 place_of_origin,
936 best_by_date,
937 LENGTH,
938 length_uom,
939 recycled_content,
940 thickness,
941 thickness_uom,
942 width,
943 width_uom,
944 curl_wrinkle_fold,
945 c_attribute1,
946 c_attribute2,
947 c_attribute3,
948 c_attribute4,
949 c_attribute5,
950 c_attribute6,
951 c_attribute7,
952 c_attribute8,
953 c_attribute9,
954 c_attribute10,
955 c_attribute11,
956 c_attribute12,
957 c_attribute13,
958 c_attribute14,
959 c_attribute15,
960 c_attribute16,
961 c_attribute17,
962 c_attribute18,
963 c_attribute19,
964 c_attribute20,
965 d_attribute1,
966 d_attribute2,
967 d_attribute3,
968 d_attribute4,
969 d_attribute5,
970 d_attribute6,
971 d_attribute7,
972 d_attribute8,
973 d_attribute9,
974 d_attribute10,
975 n_attribute1,
976 n_attribute2,
977 n_attribute3,
978 n_attribute4,
979 n_attribute5,
980 n_attribute6,
981 n_attribute7,
982 n_attribute8,
983 n_attribute9,
984 supplier_lot_number,
985 n_attribute10,
986 territory_code,
987 vendor_name,
988 parent_lot_number -- bug 10176719 - inserting parent lot number
989 )
990 SELECT mmtt.inventory_item_id,
991 p_organization_id,
992 p_lot_number,
993 SYSDATE,
994 l_userid,
995 mtlt.creation_date,
996 mtlt.created_by,
997 mtlt.last_update_login,
998 mtlt.lot_expiration_date,
999 mtlt.request_id,
1000 mtlt.program_application_id,
1001 mtlt.program_id,
1002 mtlt.program_update_date,
1003 x_object_id,
1004 mtlt.description,
1005 mtlt.vendor_id,
1006 mtlt.grade_code,
1007 mtlt.origination_date,
1008 mtlt.date_code,
1009 decode(l_dest_status_enabled,'Y',mtlt.status_id,1), --Added bug4066234,
1010 mtlt.change_date,
1011 mtlt.age,
1012 mtlt.retest_date,
1013 mtlt.maturity_date,
1014 mtlt.lot_attribute_category,
1015 mtlt.item_size,
1016 mtlt.color,
1017 mtlt.volume,
1018 mtlt.volume_uom,
1019 mtlt.place_of_origin,
1020 mtlt.best_by_date,
1021 mtlt.LENGTH,
1022 mtlt.length_uom,
1023 mtlt.recycled_content,
1024 mtlt.thickness,
1025 mtlt.thickness_uom,
1026 mtlt.width,
1027 mtlt.width_uom,
1028 mtlt.curl_wrinkle_fold,
1029 mtlt.c_attribute1,
1030 mtlt.c_attribute2,
1031 mtlt.c_attribute3,
1032 mtlt.c_attribute4,
1033 mtlt.c_attribute5,
1034 mtlt.c_attribute6,
1035 mtlt.c_attribute7,
1036 mtlt.c_attribute8,
1037 mtlt.c_attribute9,
1038 mtlt.c_attribute10,
1039 mtlt.c_attribute11,
1040 mtlt.c_attribute12,
1041 mtlt.c_attribute13,
1042 mtlt.c_attribute14,
1043 mtlt.c_attribute15,
1044 mtlt.c_attribute16,
1045 mtlt.c_attribute17,
1046 mtlt.c_attribute18,
1047 mtlt.c_attribute19,
1048 mtlt.c_attribute20,
1049 mtlt.d_attribute1,
1050 mtlt.d_attribute2,
1051 mtlt.d_attribute3,
1052 mtlt.d_attribute4,
1053 mtlt.d_attribute5,
1054 mtlt.d_attribute6,
1055 mtlt.d_attribute7,
1056 mtlt.d_attribute8,
1057 mtlt.d_attribute9,
1058 mtlt.d_attribute10,
1059 mtlt.n_attribute1,
1060 mtlt.n_attribute2,
1061 mtlt.n_attribute3,
1062 mtlt.n_attribute4,
1063 mtlt.n_attribute5,
1064 mtlt.n_attribute6,
1065 mtlt.n_attribute7,
1066 mtlt.n_attribute8,
1067 mtlt.n_attribute9,
1068 mtlt.supplier_lot_number,
1069 mtlt.n_attribute10,
1070 mtlt.territory_code,
1071 mtlt.vendor_name,
1072 p_parent_lot_number -- bug 10176719 - inserting parent_lot_number
1073 FROM mtl_transaction_lots_temp mtlt, mtl_material_transactions_temp mmtt
1074 WHERE mtlt.transaction_temp_id = p_transaction_temp_id
1075 AND mtlt.lot_number = p_lot_number
1076 AND mtlt.transaction_temp_id = mmtt.transaction_temp_id
1077 AND NOT EXISTS ( SELECT NULL
1078 FROM mtl_lot_numbers lot
1079 WHERE lot.lot_number = p_lot_number
1080 AND lot.organization_id = p_organization_id
1081 AND lot.inventory_item_id = p_inventory_item_id );
1082
1083 end if;
1084 EXCEPTION
1085 when no_data_found THEN
1086 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1087 IF (l_debug = 1) THEN
1088 inv_log_util.trace('SQL : ' || substr(sqlerrm, 1, 200), 'INV_LOT_API_PUB','9');
1089 inv_log_util.trace('Error in insertLot : ', 'INV_LOT_API_PUB','9');
1090 END IF;
1091 raise FND_API.G_EXC_UNEXPECTED_ERROR;
1092 when others then
1093 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1094 IF (l_debug = 1) THEN
1095 inv_log_util.trace('SQL : ' || substr(sqlerrm, 1, 200), 'INV_LOT_API_PUB','9');
1096 inv_log_util.trace('Error in insertLot : ', 'INV_LOT_API_PUB','9');
1097 END IF;
1098 raise FND_API.G_EXC_UNEXPECTED_ERROR;
1099
1100 end;
1101
1102 -- to prepare to insert the status to status history table for the initial status
1103 -- bug 1870120
1104 SELECT status_id
1105 INTO l_default_lot_status_id
1106 FROM mtl_lot_numbers
1107 WHERE lot_number = p_lot_number
1108 AND organization_id = p_organization_id
1109 AND inventory_item_id = p_inventory_item_id;
1110
1111 IF (l_debug = 1) THEN
1112 inv_pick_wave_pick_confirm_pub.tracelog ( 'After Insert action_id=3' , 'INV_LOT_API_PUB');
1113 END IF;
1114 ELSE -- if transaction_action_id is not 3
1115 /* ---------------------------------------------------------
1116 * call inv_lot_sel_attr.get_default to get the default value
1117 * of the lot attributes
1118 * ---------------------------------------------------------*/
1119 IF ( inv_install.adv_inv_installed ( NULL ) = TRUE ) THEN
1120
1121 IF (l_debug = 1) THEN
1122 inv_pick_wave_pick_confirm_pub.tracelog ( 'Before calling get_default' , 'INV_LOT_API_PUB');
1123 END IF;
1124 inv_lot_sel_attr.get_default (
1125 x_attributes_default => l_attributes_default,
1126 x_attributes_default_count => l_attributes_default_count,
1127 x_return_status => l_return_status,
1128 x_msg_count => l_msg_count,
1129 x_msg_data => l_msg_data,
1130 p_table_name => 'MTL_LOT_NUMBERS',
1131 p_attributes_name => 'Lot Attributes',
1132 p_inventory_item_id => p_inventory_item_id,
1133 p_organization_id => p_organization_id,
1134 p_lot_serial_number => p_lot_number,
1135 p_attributes => l_attributes_in
1136 );
1137 IF (l_debug = 1) THEN
1138 inv_pick_wave_pick_confirm_pub.tracelog ( 'After get_default' , 'INV_LOT_API_PUB');
1139 END IF;
1140
1141 IF ( l_return_status <> fnd_api.g_ret_sts_success ) THEN
1142 IF (l_debug = 1) THEN
1143 inv_pick_wave_pick_confirm_pub.tracelog ( 'exception of get_default' , 'INV_LOT_API_PUB');
1144 END IF;
1145 x_return_status := l_return_status;
1146 RAISE fnd_api.g_exc_unexpected_error;
1147 END IF;
1148
1149 /********************************************************************
1150 Bug 2181558 - Code Starts
1151 To Copy the Lot Attributes from the Start Lot to this Lot
1152 if this is a intransit transfer transaction
1153 Check for Transfer Organization ID being not null will
1154 suffice the fact that it is called only for Intrasit Receipt.
1155 ********************************************************************/
1156 l_source_non_wms_lot_att_rec.attribute_category := NULL;
1157 l_source_non_wms_lot_att_rec.attribute1 := NULL;
1158 l_source_non_wms_lot_att_rec.attribute2 := NULL;
1159 l_source_non_wms_lot_att_rec.attribute3 := NULL;
1160 l_source_non_wms_lot_att_rec.attribute4 := NULL;
1161 l_source_non_wms_lot_att_rec.attribute5 := NULL;
1162 l_source_non_wms_lot_att_rec.attribute6 := NULL;
1163 l_source_non_wms_lot_att_rec.attribute7 := NULL;
1164 l_source_non_wms_lot_att_rec.attribute8 := NULL;
1165 l_source_non_wms_lot_att_rec.attribute9 := NULL;
1166 l_source_non_wms_lot_att_rec.attribute10 := NULL;
1167 l_source_non_wms_lot_att_rec.attribute11 := NULL;
1168 l_source_non_wms_lot_att_rec.attribute12 := NULL;
1169 l_source_non_wms_lot_att_rec.attribute13 := NULL;
1170 l_source_non_wms_lot_att_rec.attribute14 := NULL;
1171 l_source_non_wms_lot_att_rec.attribute15 := NULL;
1172
1173 IF p_transfer_organization_id IS NOT NULL THEN
1174 IF (l_debug = 1) THEN
1175 inv_pick_wave_pick_confirm_pub.tracelog ( 'Before calling get_lot_att_from_source' , 'INV_LOT_API_PUB');
1176 END IF;
1177
1178 get_lot_att_from_source
1179 (
1180 x_return_status => l_return_status,
1181 x_count => l_num_wms_lot_att_copied,
1182 x_source_wms_lot_att_tbl => l_att_after_source_copy,
1183 x_source_non_wms_lot_att_rec => l_source_non_wms_lot_att_rec,
1184 p_from_organization_id => p_transfer_organization_id,
1185 p_inventory_item_id => p_inventory_item_id,
1186 p_lot_number => p_lot_number,
1187 p_count => l_attributes_default_count,
1188 p_source_wms_lot_att_tbl => l_attributes_default
1189 );
1190
1191 IF ( l_return_status <> fnd_api.g_ret_sts_success ) THEN
1192 x_return_status := l_return_status;
1193 RAISE fnd_api.g_exc_unexpected_error;
1194 END IF;
1195
1196 l_attributes_default := l_att_after_source_copy;
1197 l_attributes_default_count := l_num_wms_lot_att_copied;
1198
1199 IF (l_debug = 1) THEN
1200 inv_pick_wave_pick_confirm_pub.tracelog ( 'After calling get_lot_att_from_source' , 'INV_LOT_API_PUB');
1201 END IF;
1202 END IF;
1203
1204 /* Bug 2181558 - Code Ends */
1205
1206 IF ( l_attributes_default_count > 0 )
1207 THEN
1208 FOR i IN 1 .. l_attributes_default_count LOOP
1209 FOR j IN 1 .. g_lot_attributes_tbl.COUNT LOOP
1210 IF (UPPER(l_attributes_default(i).column_name) = UPPER(g_lot_attributes_tbl(j).column_name)) THEN
1211 g_lot_attributes_tbl ( j ).column_value := l_attributes_default ( i ).column_value;
1212 END IF;
1213
1214 EXIT WHEN (UPPER(l_attributes_default(i).column_name) =
1215 UPPER(g_lot_attributes_tbl(j).column_name));
1216 END LOOP;
1217 END LOOP;
1218 END IF;
1219 END IF;
1220
1221
1222 /***********************************************************************
1223 * Comments related to Bug 1520495 fix:
1224 * g_lot_attributes_tbl(5) points to 'STATUS_ID' information. But ,
1225 * 'STATUS_ID' is not part of descriptive flex field columns yet
1226 * for DFF 'Lot Attributes'. So the above code can never find default
1227 * value for 'STATUS_ID' in DFF segment definition. Like 'VENDOR_ID',
1228 * 'STATUS_ID' could be added to DFF columns in future.
1229 * Nevertheless, to fix the bug 1520495, we need to have an application
1230 * logic to get the default value for 'STATUS_ID'. This can be got
1231 * by using API INV_MATERIAL_STATUS_GRP.get_lot_serial_status_control()
1232 * and assigning OUT parameter 'default_lot_status_id' to
1233 * g_lot_attributes_tbl(5).COLUMN_VALUE if OUT parameter
1234 * 'lot_status_enabled' is 'Y'.
1235 ***********************************************************************/
1236 IF (l_debug = 1) THEN
1237 inv_pick_wave_pick_confirm_pub.tracelog ( 'before calling get_lot_Serial_status_control' , 'INV_LOT_API_PUB');
1238 END IF;
1239 inv_material_status_grp.get_lot_serial_status_control (
1240 p_organization_id => p_organization_id,
1241 p_inventory_item_id => p_inventory_item_id,
1242 x_return_status => l_return_status,
1243 x_msg_count => l_msg_count,
1244 x_msg_data => l_msg_data,
1245 x_lot_status_enabled => l_lot_status_enabled,
1246 x_default_lot_status_id => l_default_lot_status_id,
1247 x_serial_status_enabled => l_serial_status_enabled,
1248 x_default_serial_status_id => l_default_serial_status_id
1249 );
1250 IF (l_debug = 1) THEN
1251 inv_pick_wave_pick_confirm_pub.tracelog ( 'After get_lot_Serial_status_control' , 'INV_LOT_API_PUB');
1252 END IF;
1253
1254 IF ( l_return_status <> fnd_api.g_ret_sts_success ) THEN
1255 x_return_status := l_return_status;
1256 RAISE fnd_api.g_exc_unexpected_error;
1257 END IF;
1258
1259 IF ( NVL ( l_lot_status_enabled, 'Y' ) = 'Y' ) THEN
1260 -- For consistency, fill after converting to 'char'
1261 g_lot_attributes_tbl ( 5 ).column_value := TO_CHAR ( l_default_lot_status_id );
1262 END IF;
1263
1264 --print_debug('before get_context_code 20', 4);
1265
1266 /** Populate Lot Attribute Category info. **/
1267 inv_lot_sel_attr.get_context_code
1268 (
1269 g_lot_attributes_tbl ( 10 ).column_value,
1270 p_organization_id,
1271 p_inventory_item_id,
1272 'Lot Attributes'
1273 );
1274 IF (l_debug = 1) THEN
1275 inv_pick_wave_pick_confirm_pub.tracelog ( 'before inserting into mtl_lot_numbers' , 'INV_LOT_API_PUB');
1276 END IF;
1277
1278 --print_debug('after get_context_code 30', 4);
1279
1280 INSERT INTO mtl_lot_numbers
1281 (
1282 inventory_item_id,
1283 organization_id,
1284 lot_number,
1285 last_update_date,
1286 last_updated_by,
1287 creation_date,
1288 created_by,
1289 last_update_login,
1290 expiration_date,
1291 disable_flag,
1292 attribute_category,
1293 attribute1,
1294 attribute2,
1295 attribute3,
1296 attribute4,
1297 attribute5,
1298 attribute6,
1299 attribute7,
1300 attribute8,
1301 attribute9,
1302 attribute10,
1303 attribute11,
1304 attribute12,
1305 attribute13,
1306 attribute14,
1307 attribute15,
1308 request_id,
1309 program_application_id,
1310 program_id,
1311 program_update_date,
1312 gen_object_id,
1313 description,
1314 vendor_id,
1315 grade_code,
1316 origination_date,
1317 date_code,
1318 status_id,
1319 change_date,
1320 age,
1321 retest_date,
1322 maturity_date,
1323 lot_attribute_category,
1324 item_size,
1325 color,
1326 volume,
1327 volume_uom,
1328 place_of_origin,
1329 best_by_date,
1330 LENGTH,
1331 length_uom,
1332 recycled_content,
1333 thickness,
1334 thickness_uom,
1335 width,
1336 width_uom,
1337 curl_wrinkle_fold,
1338 c_attribute1,
1339 c_attribute2,
1340 c_attribute3,
1341 c_attribute4,
1342 c_attribute5,
1343 c_attribute6,
1344 c_attribute7,
1345 c_attribute8,
1346 c_attribute9,
1347 c_attribute10,
1348 c_attribute11,
1349 c_attribute12,
1350 c_attribute13,
1351 c_attribute14,
1352 c_attribute15,
1353 c_attribute16,
1354 c_attribute17,
1355 c_attribute18,
1356 c_attribute19,
1357 c_attribute20,
1358 d_attribute1,
1359 d_attribute2,
1360 d_attribute3,
1361 d_attribute4,
1362 d_attribute5,
1363 d_attribute6,
1364 d_attribute7,
1365 d_attribute8,
1366 d_attribute9,
1367 d_attribute10,
1368 n_attribute1,
1369 n_attribute2,
1370 n_attribute3,
1371 n_attribute4,
1372 n_attribute5,
1373 n_attribute6,
1374 n_attribute7,
1375 n_attribute8,
1376 n_attribute10,
1377 supplier_lot_number,
1378 n_attribute9,
1379 territory_code,
1380 vendor_name,
1381 parent_lot_number, -- bug 10176719 - inserting parent lot number
1382 origination_type -- bug 15896641 - inserting origination type
1383 )
1384 VALUES (
1385 p_inventory_item_id,
1386 p_organization_id,
1387 p_lot_number,
1388 SYSDATE,
1389 l_userid,
1390 SYSDATE,
1391 l_userid,
1392 l_loginid,
1393 p_expiration_date,
1394 NULL,
1395 l_source_non_wms_lot_att_rec.attribute_category,
1396 l_source_non_wms_lot_att_rec.attribute1,
1397 l_source_non_wms_lot_att_rec.attribute2,
1398 l_source_non_wms_lot_att_rec.attribute3,
1399 l_source_non_wms_lot_att_rec.attribute4,
1400 l_source_non_wms_lot_att_rec.attribute5,
1401 l_source_non_wms_lot_att_rec.attribute6,
1402 l_source_non_wms_lot_att_rec.attribute7,
1403 l_source_non_wms_lot_att_rec.attribute8,
1404 l_source_non_wms_lot_att_rec.attribute9,
1405 l_source_non_wms_lot_att_rec.attribute10,
1406 l_source_non_wms_lot_att_rec.attribute11,
1407 l_source_non_wms_lot_att_rec.attribute12,
1408 l_source_non_wms_lot_att_rec.attribute13,
1409 l_source_non_wms_lot_att_rec.attribute14,
1410 l_source_non_wms_lot_att_rec.attribute15,
1411 NULL,
1412 NULL,
1413 NULL,
1414 NULL,
1415 x_object_id,
1416 g_lot_attributes_tbl(68).column_value,
1417 TO_NUMBER(g_lot_attributes_tbl(1).column_value),
1418 g_lot_attributes_tbl(2).column_value,
1419 fnd_date.canonical_to_date(g_lot_attributes_tbl(3).column_value),
1420 g_lot_attributes_tbl(4).column_value,
1421 decode(l_dest_status_enabled,'Y',TO_NUMBER(g_lot_attributes_tbl(5).column_value),1), --Added bug 4066234
1422 fnd_date.canonical_to_date (g_lot_attributes_tbl(6).column_value),
1423 TO_NUMBER(g_lot_attributes_tbl(7).column_value),
1424 fnd_date.canonical_to_date(g_lot_attributes_tbl(8).column_value),
1425 fnd_date.canonical_to_date(g_lot_attributes_tbl(9).column_value),
1426 g_lot_attributes_tbl(10).column_value,
1427 TO_NUMBER(g_lot_attributes_tbl(11).column_value),
1428 g_lot_attributes_tbl(12).column_value,
1429 TO_NUMBER(g_lot_attributes_tbl(13).column_value),
1430 g_lot_attributes_tbl(14).column_value,
1431 g_lot_attributes_tbl(15).column_value,
1432 fnd_date.canonical_to_date(g_lot_attributes_tbl(16).column_value),
1433 TO_NUMBER(g_lot_attributes_tbl(17).column_value),
1434 g_lot_attributes_tbl(18).column_value,
1435 TO_NUMBER(g_lot_attributes_tbl(19).column_value),
1436 TO_NUMBER(g_lot_attributes_tbl(20).column_value),
1437 g_lot_attributes_tbl(21).column_value,
1438 TO_NUMBER(g_lot_attributes_tbl(22).column_value),
1439 g_lot_attributes_tbl(23).column_value,
1440 g_lot_attributes_tbl(24).column_value,
1441 g_lot_attributes_tbl(25).column_value,
1442 g_lot_attributes_tbl(26).column_value,
1443 g_lot_attributes_tbl(27).column_value,
1444 g_lot_attributes_tbl(28).column_value,
1445 g_lot_attributes_tbl(29).column_value,
1446 g_lot_attributes_tbl(30).column_value,
1447 g_lot_attributes_tbl(31).column_value,
1448 g_lot_attributes_tbl(32).column_value,
1449 g_lot_attributes_tbl(33).column_value,
1450 g_lot_attributes_tbl(34).column_value,
1451 g_lot_attributes_tbl(35).column_value,
1452 g_lot_attributes_tbl(36).column_value,
1453 g_lot_attributes_tbl(37).column_value,
1454 g_lot_attributes_tbl(38).column_value,
1455 g_lot_attributes_tbl(39).column_value,
1456 g_lot_attributes_tbl(40).column_value,
1457 g_lot_attributes_tbl(41).column_value,
1458 g_lot_attributes_tbl(42).column_value,
1459 g_lot_attributes_tbl(43).column_value,
1460 g_lot_attributes_tbl(44).column_value,
1461 fnd_date.canonical_to_date(g_lot_attributes_tbl(45).column_value),
1462 fnd_date.canonical_to_date(g_lot_attributes_tbl(46).column_value),
1463 fnd_date.canonical_to_date(g_lot_attributes_tbl(47).column_value),
1464 fnd_date.canonical_to_date(g_lot_attributes_tbl(48).column_value),
1465 fnd_date.canonical_to_date(g_lot_attributes_tbl(49).column_value),
1466 fnd_date.canonical_to_date(g_lot_attributes_tbl(50).column_value),
1467 fnd_date.canonical_to_date(g_lot_attributes_tbl(51).column_value),
1468 fnd_date.canonical_to_date(g_lot_attributes_tbl(52).column_value),
1469 fnd_date.canonical_to_date(g_lot_attributes_tbl(53).column_value),
1470 fnd_date.canonical_to_date(g_lot_attributes_tbl(54).column_value),
1471 TO_NUMBER(g_lot_attributes_tbl(55).column_value),
1472 TO_NUMBER(g_lot_attributes_tbl(56).column_value),
1473 TO_NUMBER(g_lot_attributes_tbl(57).column_value),
1474 TO_NUMBER(g_lot_attributes_tbl(58).column_value),
1475 TO_NUMBER(g_lot_attributes_tbl(59).column_value),
1476 TO_NUMBER(g_lot_attributes_tbl(60).column_value),
1477 TO_NUMBER(g_lot_attributes_tbl(61).column_value),
1478 TO_NUMBER(g_lot_attributes_tbl(62).column_value),
1479 TO_NUMBER(g_lot_attributes_tbl(63).column_value),
1480 g_lot_attributes_tbl(64).column_value,
1481 TO_NUMBER(g_lot_attributes_tbl(65).column_value),
1482 g_lot_attributes_tbl(66).column_value,
1483 g_lot_attributes_tbl(67).column_value,
1484 p_parent_lot_number, -- bug 10176719 - inserting parent lot number
1485 p_origination_type -- bug 15896641 - inserting origination type
1486 );
1487
1488 IF (l_debug = 1) THEN
1489 inv_pick_wave_pick_confirm_pub.tracelog ( 'After inserting the lot' , 'INV_LOT_API_PUB');
1490 END IF;
1491
1492 END IF;
1493
1494 -- insert into status update history table, bug 1870120
1495 IF ( l_default_lot_status_id IS NOT NULL AND l_dest_status_enabled = 'Y' ) THEN -- bug #4201246
1496 l_status_rec.update_method := inv_material_status_pub.g_update_method_auto;
1497 l_status_rec.organization_id := p_organization_id;
1498 l_status_rec.inventory_item_id := p_inventory_item_id;
1499 l_status_rec.lot_number := p_lot_number;
1500 l_status_rec.status_id := l_default_lot_status_id;
1501 l_status_rec.initial_status_flag := 'Y';
1502 inv_material_status_pkg.insert_status_history ( l_status_rec);
1503 IF (l_debug = 1) THEN
1504 inv_pick_wave_pick_confirm_pub.tracelog ( 'after calling insert_status_history' , 'INV_LOT_API_PUB');
1505 END IF;
1506 END IF;
1507
1508 x_return_status := fnd_api.g_ret_sts_success;
1509 ELSE
1510 IF (l_debug = 1) THEN
1511 inv_pick_wave_pick_confirm_pub.tracelog ( 'INV_LOT_EXISTS' , 'INV_LOT_API_PUB');
1512 END IF;
1513 fnd_message.set_name ('INV' , 'INV_LOT_EXISTS' );
1514 fnd_msg_pub.ADD;
1515 --l_return_status := FND_API.G_RET_STS_SUCCESS;
1516 x_return_status := fnd_api.g_ret_sts_success;
1517 END IF;
1518
1519 IF (l_lotcount > 0 AND p_expiration_date IS NOT NULL) THEN
1520
1521 l_userid := fnd_global.user_id;
1522
1523 --Lot exists, but now the user has entered the lot expiration date
1524 IF (l_debug = 1) THEN
1525 inv_pick_wave_pick_confirm_pub.tracelog ('Update the expiration date', 'INV_LOT_API_PUB');
1526 END IF;
1527
1528 UPDATE mtl_lot_numbers
1529 SET expiration_date = p_expiration_date,
1530 last_update_date = SYSDATE,
1531 last_updated_by = l_userid
1532 WHERE inventory_item_id = p_inventory_item_id
1533 AND organization_id = p_organization_id
1534 AND lot_number = p_lot_number
1535 AND expiration_date IS NULL ;
1536
1537 END IF;
1538 END IF;
1539
1540 -- End of API body.
1541 -- Standard check of p_commit.
1542 IF (l_debug = 1) THEN
1543 inv_pick_wave_pick_confirm_pub.tracelog ( 'Inserted the Lot ' || p_lot_number, 'INV_LOT_API_PUB');
1544 END IF;
1545
1546 IF fnd_api.to_boolean ( p_commit ) THEN
1547 COMMIT WORK;
1548 END IF;
1549
1550 -- Standard call to get message count and if count is 1, get message info.
1551 fnd_msg_pub.count_and_get ( p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
1552 --x_return_status := l_return_status;
1553
1554 --print_debug('end insertlot', 4);
1555
1556 EXCEPTION
1557 WHEN OTHERS THEN
1558 IF (l_debug = 1) THEN
1559 inv_pick_wave_pick_confirm_pub.tracelog ( 'Inside the exception ' || p_lot_number, 'INV_LOT_API_PUB');
1560 END IF;
1561 --print_debug('insertlot other exception', 4);
1562
1563 ROLLBACK TO apiinsertlot_apipub;
1564
1565 IF fnd_msg_pub.check_msg_level ( fnd_msg_pub.g_msg_lvl_unexp_error) THEN
1566 fnd_msg_pub.add_exc_msg ('INV_LOT_API_PUB' , 'insertLot' );
1567 END IF;
1568
1569 x_return_status := fnd_api.g_ret_sts_unexp_error;
1570 END insertlot;
1571
1572 PROCEDURE inserttrxlot (
1573 p_api_version IN NUMBER,
1574 p_init_msg_list IN VARCHAR2 := fnd_api.g_false,
1575 p_commit IN VARCHAR2 := fnd_api.g_false,
1576 p_validation_level IN NUMBER
1577 := fnd_api.g_valid_level_full,
1578 p_primary_quantity IN NUMBER DEFAULT NULL,
1579 p_transaction_id IN NUMBER,
1580 p_inventory_item_id IN NUMBER,
1581 p_organization_id IN NUMBER,
1582 p_transaction_date IN DATE,
1583 p_transaction_source_id IN NUMBER,
1584 p_transaction_source_name IN VARCHAR2,
1585 p_transaction_source_type_id IN NUMBER,
1586 p_transaction_temp_id IN NUMBER,
1587 p_transaction_action_id IN NUMBER,
1588 p_serial_transaction_id IN NUMBER,
1589 p_lot_number IN VARCHAR2,
1590 x_return_status OUT NOCOPY VARCHAR2,
1591 x_msg_count OUT NOCOPY NUMBER,
1592 x_msg_data OUT NOCOPY VARCHAR2
1593 )
1594 IS
1595 l_attributes_default inv_lot_sel_attr.lot_sel_attributes_tbl_type;
1596 l_attributes_default_count NUMBER;
1597 l_attributes_in inv_lot_sel_attr.lot_sel_attributes_tbl_type;
1598 l_column_idx BINARY_INTEGER;
1599 l_return_status VARCHAR2 ( 1 );
1600 l_msg_data VARCHAR2 ( 2000 );
1601 l_msg_count NUMBER;
1602 l_input_idx BINARY_INTEGER;
1603 l_userid NUMBER;
1604 l_loginid NUMBER;
1605 l_api_version CONSTANT NUMBER := 1.0;
1606 l_api_name CONSTANT VARCHAR2 ( 30 ) := 'insertTrxLot';
1607 l_mmtt_pri_quantity NUMBER := 0;
1608 l_transaction_quantity NUMBER;
1609 l_primary_quantity NUMBER;
1610
1611 CURSOR lot_temp_csr ( p_lot_number VARCHAR2, p_trx_temp_id NUMBER )
1612 IS
1613 SELECT TO_CHAR ( vendor_id ),
1614 grade_code,
1615 fnd_date.date_to_canonical ( origination_date ),
1616 date_code,
1617 TO_CHAR ( status_id ),
1618 fnd_date.date_to_canonical ( change_date ),
1619 TO_NUMBER ( age ),
1620 fnd_date.date_to_canonical ( retest_date ),
1621 fnd_date.date_to_canonical ( maturity_date ),
1622 lot_attribute_category,
1623 TO_CHAR ( item_size ),
1624 color,
1625 TO_CHAR ( volume ),
1626 volume_uom,
1627 place_of_origin,
1628 fnd_date.date_to_canonical ( best_by_date ),
1629 TO_CHAR ( LENGTH ),
1630 length_uom,
1631 TO_CHAR ( recycled_content ),
1632 TO_CHAR ( thickness ),
1633 thickness_uom,
1634 TO_CHAR ( width ),
1635 width_uom,
1636 curl_wrinkle_fold,
1637 c_attribute1,
1638 c_attribute2,
1639 c_attribute3,
1640 c_attribute4,
1641 c_attribute5,
1642 c_attribute6,
1643 c_attribute7,
1644 c_attribute8,
1645 c_attribute9,
1646 c_attribute10,
1647 c_attribute11,
1648 c_attribute12,
1649 c_attribute13,
1650 c_attribute14,
1651 c_attribute15,
1652 c_attribute16,
1653 c_attribute17,
1654 c_attribute18,
1655 c_attribute19,
1656 c_attribute20,
1657 fnd_date.date_to_canonical ( d_attribute1 ),
1658 fnd_date.date_to_canonical ( d_attribute2 ),
1659 fnd_date.date_to_canonical ( d_attribute3 ),
1660 fnd_date.date_to_canonical ( d_attribute4 ),
1661 fnd_date.date_to_canonical ( d_attribute5 ),
1662 fnd_date.date_to_canonical ( d_attribute6 ),
1663 fnd_date.date_to_canonical ( d_attribute7 ),
1664 fnd_date.date_to_canonical ( d_attribute8 ),
1665 fnd_date.date_to_canonical ( d_attribute9 ),
1666 fnd_date.date_to_canonical ( d_attribute10 ),
1667 TO_CHAR ( n_attribute1 ),
1668 TO_CHAR ( n_attribute2 ),
1669 TO_CHAR ( n_attribute3 ),
1670 TO_CHAR ( n_attribute4 ),
1671 TO_CHAR ( n_attribute5 ),
1672 TO_CHAR ( n_attribute6 ),
1673 TO_CHAR ( n_attribute7 ),
1674 TO_CHAR ( n_attribute8 ),
1675 TO_CHAR ( n_attribute10 ),
1676 supplier_lot_number,
1677 TO_CHAR ( n_attribute9 ),
1678 territory_code,
1679 vendor_name
1680 FROM mtl_transaction_lots_temp
1681 WHERE lot_number = p_lot_number
1682 AND transaction_temp_id = p_trx_temp_id;
1683 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1684 BEGIN
1685 -- Standard Start of API savepoint
1686 SAVEPOINT apiinsertlot_apipub;
1687
1688 -- Standard call to check for call compatibility.
1689 IF NOT fnd_api.compatible_api_call (
1690 l_api_version,
1691 p_api_version,
1692 l_api_name,
1693 g_pkg_name
1694 )
1695 THEN
1696 RAISE fnd_api.g_exc_unexpected_error;
1697 END IF;
1698
1699 -- Initialize message list if p_init_msg_list is set to TRUE.
1700 IF fnd_api.to_boolean ( p_init_msg_list )
1701 THEN
1702 fnd_msg_pub.initialize;
1703 END IF;
1704
1705 -- Initialize API return status to success
1706 x_return_status := fnd_api.g_ret_sts_success;
1707 -- API body
1708
1709 if( l_debug = 1 ) then
1710 print_debug('Calling populateattributescolumn()', 10);
1711 print_debug('p_transaction_temp_id is ' || p_transaction_temp_id, 10);
1712 print_debug('p_transaction_action_id is ' || p_transaction_action_id, 10);
1713 if( g_firstScan = false ) then
1714 print_debug('g_firstscan is false', 10);
1715 else
1716 print_debug('g_firstscan is true', 10);
1717 end if;
1718 end if;
1719
1720 populateattributescolumn ( );
1721 l_userid := fnd_global.user_id;
1722 l_loginid := fnd_global.login_id;
1723 l_mmtt_pri_quantity := 0;
1724
1725 IF ( p_primary_quantity IS NOT NULL )
1726 THEN
1727 IF p_primary_quantity < 0
1728 THEN
1729 l_mmtt_pri_quantity := 1;
1730 ELSE
1731 l_mmtt_pri_quantity := 0;
1732 END IF;
1733 ELSE
1734 l_mmtt_pri_quantity := 0;
1735 END IF;
1736
1737 IF ( p_transaction_temp_id IS NOT NULL )
1738 THEN
1739 OPEN lot_temp_csr ( p_lot_number, p_transaction_temp_id );
1740
1741 LOOP
1742 FETCH lot_temp_csr INTO g_lot_attributes_tbl ( 1 ).column_value,
1743 g_lot_attributes_tbl ( 2 ).column_value,
1744 g_lot_attributes_tbl ( 3 ).column_value,
1745 g_lot_attributes_tbl ( 4 ).column_value,
1746 g_lot_attributes_tbl ( 5 ).column_value,
1747 g_lot_attributes_tbl ( 6 ).column_value,
1748 g_lot_attributes_tbl ( 7 ).column_value,
1749 g_lot_attributes_tbl ( 8 ).column_value,
1750 g_lot_attributes_tbl ( 9 ).column_value,
1751 g_lot_attributes_tbl ( 10 ).column_value,
1752 g_lot_attributes_tbl ( 11 ).column_value,
1753 g_lot_attributes_tbl ( 12 ).column_value,
1754 g_lot_attributes_tbl ( 13 ).column_value,
1755 g_lot_attributes_tbl ( 14 ).column_value,
1756 g_lot_attributes_tbl ( 15 ).column_value,
1757 g_lot_attributes_tbl ( 16 ).column_value,
1758 g_lot_attributes_tbl ( 17 ).column_value,
1759 g_lot_attributes_tbl ( 18 ).column_value,
1760 g_lot_attributes_tbl ( 19 ).column_value,
1761 g_lot_attributes_tbl ( 20 ).column_value,
1762 g_lot_attributes_tbl ( 21 ).column_value,
1763 g_lot_attributes_tbl ( 22 ).column_value,
1764 g_lot_attributes_tbl ( 23 ).column_value,
1765 g_lot_attributes_tbl ( 24 ).column_value,
1766 g_lot_attributes_tbl ( 25 ).column_value,
1767 g_lot_attributes_tbl ( 26 ).column_value,
1768 g_lot_attributes_tbl ( 27 ).column_value,
1769 g_lot_attributes_tbl ( 28 ).column_value,
1770 g_lot_attributes_tbl ( 29 ).column_value,
1771 g_lot_attributes_tbl ( 30 ).column_value,
1772 g_lot_attributes_tbl ( 31 ).column_value,
1773 g_lot_attributes_tbl ( 32 ).column_value,
1774 g_lot_attributes_tbl ( 33 ).column_value,
1775 g_lot_attributes_tbl ( 34 ).column_value,
1776 g_lot_attributes_tbl ( 35 ).column_value,
1777 g_lot_attributes_tbl ( 36 ).column_value,
1778 g_lot_attributes_tbl ( 37 ).column_value,
1779 g_lot_attributes_tbl ( 38 ).column_value,
1780 g_lot_attributes_tbl ( 39 ).column_value,
1781 g_lot_attributes_tbl ( 40 ).column_value,
1782 g_lot_attributes_tbl ( 41 ).column_value,
1783 g_lot_attributes_tbl ( 42 ).column_value,
1784 g_lot_attributes_tbl ( 43 ).column_value,
1785 g_lot_attributes_tbl ( 44 ).column_value,
1786 g_lot_attributes_tbl ( 45 ).column_value,
1787 g_lot_attributes_tbl ( 46 ).column_value,
1788 g_lot_attributes_tbl ( 47 ).column_value,
1789 g_lot_attributes_tbl ( 48 ).column_value,
1790 g_lot_attributes_tbl ( 49 ).column_value,
1791 g_lot_attributes_tbl ( 50 ).column_value,
1792 g_lot_attributes_tbl ( 51 ).column_value,
1793 g_lot_attributes_tbl ( 52 ).column_value,
1794 g_lot_attributes_tbl ( 53 ).column_value,
1795 g_lot_attributes_tbl ( 54 ).column_value,
1796 g_lot_attributes_tbl ( 55 ).column_value,
1797 g_lot_attributes_tbl ( 56 ).column_value,
1798 g_lot_attributes_tbl ( 57 ).column_value,
1799 g_lot_attributes_tbl ( 58 ).column_value,
1800 g_lot_attributes_tbl ( 59 ).column_value,
1801 g_lot_attributes_tbl ( 60 ).column_value,
1802 g_lot_attributes_tbl ( 61 ).column_value,
1803 g_lot_attributes_tbl ( 62 ).column_value,
1804 g_lot_attributes_tbl ( 63 ).column_value,
1805 g_lot_attributes_tbl ( 64 ).column_value,
1806 g_lot_attributes_tbl ( 65 ).column_value,
1807 g_lot_attributes_tbl ( 66 ).column_value,
1808 g_lot_attributes_tbl ( 67 ).column_value;
1809 EXIT WHEN lot_temp_csr%NOTFOUND;
1810 END LOOP;
1811
1812 CLOSE lot_temp_csr;
1813 l_input_idx := 0;
1814
1815 FOR x IN 1 .. 67
1816 LOOP
1817 IF ( g_lot_attributes_tbl ( x ).column_value IS NOT NULL )
1818 THEN
1819 l_input_idx := l_input_idx + 1;
1820 l_attributes_in ( l_input_idx ).column_name :=
1821 g_lot_attributes_tbl ( x ).column_name;
1822 l_attributes_in ( l_input_idx ).column_value :=
1823 g_lot_attributes_tbl ( x ).column_value;
1824 l_attributes_in ( l_input_idx ).column_type :=
1825 g_lot_attributes_tbl ( x ).column_type;
1826 END IF;
1827 END LOOP;
1828 END IF;
1829
1830 IF ( p_transaction_action_id IS NOT NULL AND p_transaction_action_id = 3 ) THEN
1831
1832 -- Changes for bug 2221892 for same lot being provided as
1833 -- multiple lots with different quantities for inter-org
1834 -- transfer transactions
1835 /* SELECT transaction_quantity,
1836 primary_quantity
1837 INTO l_transaction_quantity,
1838 l_primary_quantity
1839 FROM mtl_transaction_lots_temp
1840 WHERE transaction_temp_id = p_transaction_temp_id
1841 AND lot_number = p_lot_number;
1842 */
1843
1844 INSERT INTO mtl_transaction_lot_numbers
1845 (
1846 transaction_id,
1847 last_update_date,
1848 last_updated_by,
1849 creation_date,
1850 created_by,
1851 last_update_login,
1852 inventory_item_id,
1853 organization_id,
1854 transaction_date,
1855 transaction_source_id,
1856 transaction_source_type_id,
1857 transaction_source_name,
1858 transaction_quantity,
1859 primary_quantity,
1860 lot_number,
1861 serial_transaction_id,
1862 description,
1863 supplier_lot_number,
1864 origination_date,
1865 date_code,
1866 grade_code,
1867 change_date,
1868 maturity_date,
1869 status_id,
1870 retest_date,
1871 age,
1872 item_size,
1873 color,
1874 volume,
1875 volume_uom,
1876 place_of_origin,
1877 best_by_date,
1878 LENGTH,
1879 length_uom,
1880 width,
1881 width_uom,
1882 recycled_content,
1883 thickness,
1884 thickness_uom,
1885 curl_wrinkle_fold,
1886 lot_attribute_category,
1887 c_attribute1,
1888 c_attribute2,
1889 c_attribute3,
1890 c_attribute4,
1891 c_attribute5,
1892 c_attribute6,
1893 c_attribute7,
1894 c_attribute8,
1895 c_attribute9,
1896 c_attribute10,
1897 c_attribute11,
1898 c_attribute12,
1899 c_attribute13,
1900 c_attribute14,
1901 c_attribute15,
1902 c_attribute16,
1903 c_attribute17,
1904 c_attribute18,
1905 c_attribute19,
1906 c_attribute20,
1907 d_attribute1,
1908 d_attribute2,
1909 d_attribute3,
1910 d_attribute4,
1911 d_attribute5,
1912 d_attribute6,
1913 d_attribute7,
1914 d_attribute8,
1915 d_attribute9,
1916 d_attribute10,
1917 n_attribute1,
1918 n_attribute2,
1919 n_attribute3,
1920 n_attribute4,
1921 n_attribute5,
1922 n_attribute6,
1923 n_attribute7,
1924 n_attribute8,
1925 n_attribute9,
1926 n_attribute10,
1927 vendor_id,
1928 territory_code,
1929 vendor_name,
1930 product_code,
1931 product_transaction_id
1932 )
1933 SELECT p_transaction_id,
1934 SYSDATE,
1935 l_userid,
1936 MLN.creation_date,
1937 MLN.created_by,
1938 MLN.last_update_login,
1939 p_inventory_item_id,
1940 p_organization_id,
1941 p_transaction_date,
1942 p_transaction_source_id,
1943 p_transaction_source_type_id,
1944 p_transaction_source_name,
1945 ROUND ( ABS ( MTLT.transaction_quantity ), 5 ),
1946 ROUND ( ABS ( MTLT.primary_quantity ), 5 ),
1947 MLN.lot_number,
1948 p_serial_transaction_id,
1949 MLN.description,
1950 MLN.supplier_lot_number,
1951 MLN.origination_date,
1952 MLN.date_code,
1953 MLN.grade_code,
1954 MLN.change_date,
1955 MLN.maturity_date,
1956 MLN.status_id,
1957 MLN.retest_date,
1958 MLN.age,
1959 MLN.item_size,
1960 MLN.color,
1961 MLN.volume,
1962 MLN.volume_uom,
1963 MLN.place_of_origin,
1964 MLN.best_by_date,
1965 MLN.LENGTH,
1966 MLN.length_uom,
1967 MLN.width,
1968 MLN.width_uom,
1969 MLN.recycled_content,
1970 MLN.thickness,
1971 MLN.thickness_uom,
1972 MLN.curl_wrinkle_fold,
1973 MLN.lot_attribute_category,
1974 MLN.c_attribute1,
1975 MLN.c_attribute2,
1976 MLN.c_attribute3,
1977 MLN.c_attribute4,
1978 MLN.c_attribute5,
1979 MLN.c_attribute6,
1980 MLN.c_attribute7,
1981 MLN.c_attribute8,
1982 MLN.c_attribute9,
1983 MLN.c_attribute10,
1984 MLN.c_attribute11,
1985 MLN.c_attribute12,
1986 MLN.c_attribute13,
1987 MLN.c_attribute14,
1988 MLN.c_attribute15,
1989 MLN.c_attribute16,
1990 MLN.c_attribute17,
1991 MLN.c_attribute18,
1992 MLN.c_attribute19,
1993 MLN.c_attribute20,
1994 MLN.d_attribute1,
1995 MLN.d_attribute2,
1996 MLN.d_attribute3,
1997 MLN.d_attribute4,
1998 MLN.d_attribute5,
1999 MLN.d_attribute6,
2000 MLN.d_attribute7,
2001 MLN.d_attribute8,
2002 MLN.d_attribute9,
2003 MLN.d_attribute10,
2004 MLN.n_attribute1,
2005 MLN.n_attribute2,
2006 MLN.n_attribute3,
2007 MLN.n_attribute4,
2008 MLN.n_attribute5,
2009 MLN.n_attribute6,
2010 MLN.n_attribute7,
2011 MLN.n_attribute8,
2012 MLN.n_attribute9,
2013 MLN.n_attribute10,
2014 MLN.vendor_id,
2015 MLN.territory_code,
2016 MLN.vendor_name,
2017 mtlt.product_code,
2018 mtlt.product_transaction_id
2019 FROM mtl_lot_numbers MLN,
2020 mtl_transaction_lots_temp MTLT
2021 WHERE MLN.organization_id = p_organization_id
2022 AND MLN.inventory_item_id = p_inventory_item_id
2023 AND MLN.lot_number = p_lot_number
2024 AND MTLT.lot_number = MLN.lot_number
2025 AND MTLT.transaction_temp_id = p_transaction_temp_id
2026 -- AND MTLT.LOT_NUMBER = p_lot_number
2027 and not exists (
2028 select null
2029 from mtl_transaction_lot_numbers mtln
2030 where mtln.lot_number = p_lot_number
2031 and mtln.primary_quantity = round(abs(MTLT.PRIMARY_QUANTITY),5)
2032 and mtln.inventory_item_id = p_inventory_item_id
2033 and mtln.organization_id = p_organization_id
2034 and mtln.transaction_date = p_transaction_date
2035 and nvl(mtln.transaction_source_id,-1) = nvl(p_transaction_source_id,-1)
2036 and nvl(mtln.transaction_source_type_id,-1) = nvl(p_transaction_source_type_id,-1)
2037 and nvl(mtln.transaction_source_name,'$$$') = nvl(p_transaction_source_name,'$$$')
2038 and mtln.transaction_id = p_transaction_id
2039 );
2040
2041 -- AND ROWNUM < 2;
2042
2043 /*
2044 and not exists
2045 (select NULL
2046 from MTL_LOT_NUMBERS LOT
2047 where LOT.lot_number = p_lot_number
2048 and LOT.organization_id = p_organization_id
2049 and LOT.inventory_item_id = p_inventory_item_id);
2050 */
2051 ELSE
2052 /* ---------------------------------------------------------
2053 * call inv_lot_sel_attr.get_default to get the default value
2054 * of the lot attributes
2055 * ---------------------------------------------------------*/
2056 IF ( inv_install.adv_inv_installed ( NULL ) = TRUE )
2057 THEN
2058 inv_lot_sel_attr.get_default (
2059 x_attributes_default => l_attributes_default,
2060 x_attributes_default_count => l_attributes_default_count,
2061 x_return_status => l_return_status,
2062 x_msg_count => l_msg_count,
2063 x_msg_data => l_msg_data,
2064 p_table_name => 'MTL_LOT_NUMBERS',
2065 p_attributes_name => 'Lot Attributes',
2066 p_inventory_item_id => p_inventory_item_id,
2067 p_organization_id => p_organization_id,
2068 p_lot_serial_number => p_lot_number,
2069 p_attributes => l_attributes_in
2070 );
2071
2072 IF ( l_return_status <> fnd_api.g_ret_sts_success )
2073 THEN
2074 x_return_status := l_return_status;
2075 RAISE fnd_api.g_exc_unexpected_error;
2076 END IF;
2077
2078 IF ( l_attributes_default_count > 0 )
2079 THEN
2080 FOR i IN 1 .. l_attributes_default_count
2081 LOOP
2082 FOR j IN 1 .. g_lot_attributes_tbl.COUNT
2083 LOOP
2084 IF ( UPPER (
2085 l_attributes_default ( i ).column_name
2086 ) = UPPER (
2087 g_lot_attributes_tbl ( j ).column_name
2088 )
2089 )
2090 THEN
2091 g_lot_attributes_tbl ( j ).column_value :=
2092 l_attributes_default ( i ).column_value;
2093 END IF;
2094
2095 EXIT WHEN ( UPPER (
2096 l_attributes_default ( i ).column_name
2097 ) =
2098 UPPER (
2099 g_lot_attributes_tbl ( j ).column_name
2100 )
2101 );
2102 END LOOP;
2103 END LOOP;
2104 END IF;
2105 END IF;
2106
2107 /** Populate Lot Attribute Category info. **/
2108 inv_lot_sel_attr.get_context_code (
2109 g_lot_attributes_tbl ( 10 ).column_value,
2110 p_organization_id,
2111 p_inventory_item_id,
2112 'Lot Attributes'
2113 );
2114
2115 INSERT INTO mtl_transaction_lot_numbers
2116 (
2117 transaction_id,
2118 last_update_date,
2119 last_updated_by,
2120 creation_date,
2121 created_by,
2122 last_update_login,
2123 inventory_item_id,
2124 organization_id,
2125 transaction_date,
2126 transaction_source_id,
2127 transaction_source_type_id,
2128 transaction_source_name,
2129 transaction_quantity,
2130 primary_quantity,
2131 lot_number,
2132 serial_transaction_id,
2133 description,
2134 vendor_id,
2135 grade_code,
2136 origination_date,
2137 date_code,
2138 status_id,
2139 change_date,
2140 age,
2141 retest_date,
2142 maturity_date,
2143 lot_attribute_category,
2144 item_size,
2145 color,
2146 volume,
2147 volume_uom,
2148 place_of_origin,
2149 best_by_date,
2150 LENGTH,
2151 length_uom,
2152 recycled_content,
2153 thickness,
2154 thickness_uom,
2155 width,
2156 width_uom,
2157 curl_wrinkle_fold,
2158 c_attribute1,
2159 c_attribute2,
2160 c_attribute3,
2161 c_attribute4,
2162 c_attribute5,
2163 c_attribute6,
2164 c_attribute7,
2165 c_attribute8,
2166 c_attribute9,
2167 c_attribute10,
2168 c_attribute11,
2169 c_attribute12,
2170 c_attribute13,
2171 c_attribute14,
2172 c_attribute15,
2173 c_attribute16,
2174 c_attribute17,
2175 c_attribute18,
2176 c_attribute19,
2177 c_attribute20,
2178 d_attribute1,
2179 d_attribute2,
2180 d_attribute3,
2181 d_attribute4,
2182 d_attribute5,
2183 d_attribute6,
2184 d_attribute7,
2185 d_attribute8,
2186 d_attribute9,
2187 d_attribute10,
2188 n_attribute1,
2189 n_attribute2,
2190 n_attribute3,
2191 n_attribute4,
2192 n_attribute5,
2193 n_attribute6,
2194 n_attribute7,
2195 n_attribute8,
2196 n_attribute10,
2197 supplier_lot_number,
2198 n_attribute9,
2199 territory_code,
2200 vendor_name,
2201 product_code,
2202 product_transaction_id
2203 )
2204 SELECT p_transaction_id,
2205 SYSDATE,
2206 l_userid,
2207 SYSDATE,
2208 l_userid,
2209 l_loginid,
2210 p_inventory_item_id,
2211 p_organization_id,
2212 p_transaction_date,
2213 p_transaction_source_id,
2214 p_transaction_source_type_id,
2215 p_transaction_source_name,
2216 DECODE (
2217 l_mmtt_pri_quantity,
2218 1, ROUND (
2219 ( ABS ( transaction_quantity ) * -1 ),
2220 5
2221 ),
2222 ROUND ( ABS ( transaction_quantity ), 5 )
2223 ),
2224 DECODE (
2225 l_mmtt_pri_quantity,
2226 1, ROUND ( ( ABS ( primary_quantity ) * -1 ), 5 ),
2227 ROUND ( ABS ( primary_quantity ), 5 )
2228 ),
2229 p_lot_number,
2230 p_serial_transaction_id,
2231 description,
2232 TO_NUMBER ( g_lot_attributes_tbl ( 1 ).column_value ),
2233 g_lot_attributes_tbl ( 2 ).column_value,
2234 fnd_date.canonical_to_date (
2235 g_lot_attributes_tbl ( 3 ).column_value
2236 ),
2237 g_lot_attributes_tbl ( 4 ).column_value,
2238 TO_NUMBER ( g_lot_attributes_tbl ( 5 ).column_value ),
2239 fnd_date.canonical_to_date (
2240 g_lot_attributes_tbl ( 6 ).column_value
2241 ),
2242 TO_NUMBER ( g_lot_attributes_tbl ( 7 ).column_value ),
2243 fnd_date.canonical_to_date (
2244 g_lot_attributes_tbl ( 8 ).column_value
2245 ),
2246 fnd_date.canonical_to_date (
2247 g_lot_attributes_tbl ( 9 ).column_value
2248 ),
2249 g_lot_attributes_tbl ( 10 ).column_value,
2250 TO_NUMBER ( g_lot_attributes_tbl ( 11 ).column_value ),
2251 g_lot_attributes_tbl ( 12 ).column_value,
2252 TO_NUMBER ( g_lot_attributes_tbl ( 13 ).column_value ),
2253 g_lot_attributes_tbl ( 14 ).column_value,
2254 g_lot_attributes_tbl ( 15 ).column_value,
2255 fnd_date.canonical_to_date (
2256 g_lot_attributes_tbl ( 16 ).column_value
2257 ),
2258 TO_NUMBER ( g_lot_attributes_tbl ( 17 ).column_value ),
2259 g_lot_attributes_tbl ( 18 ).column_value,
2260 TO_NUMBER ( g_lot_attributes_tbl ( 19 ).column_value ),
2261 TO_NUMBER ( g_lot_attributes_tbl ( 20 ).column_value ),
2262 g_lot_attributes_tbl ( 21 ).column_value,
2263 TO_NUMBER ( g_lot_attributes_tbl ( 22 ).column_value ),
2264 g_lot_attributes_tbl ( 23 ).column_value,
2265 g_lot_attributes_tbl ( 24 ).column_value,
2266 g_lot_attributes_tbl ( 25 ).column_value,
2267 g_lot_attributes_tbl ( 26 ).column_value,
2268 g_lot_attributes_tbl ( 27 ).column_value,
2269 g_lot_attributes_tbl ( 28 ).column_value,
2270 g_lot_attributes_tbl ( 29 ).column_value,
2271 g_lot_attributes_tbl ( 30 ).column_value,
2272 g_lot_attributes_tbl ( 31 ).column_value,
2273 g_lot_attributes_tbl ( 32 ).column_value,
2274 g_lot_attributes_tbl ( 33 ).column_value,
2275 g_lot_attributes_tbl ( 34 ).column_value,
2276 g_lot_attributes_tbl ( 35 ).column_value,
2277 g_lot_attributes_tbl ( 36 ).column_value,
2278 g_lot_attributes_tbl ( 37 ).column_value,
2279 g_lot_attributes_tbl ( 38 ).column_value,
2280 g_lot_attributes_tbl ( 39 ).column_value,
2281 g_lot_attributes_tbl ( 40 ).column_value,
2282 g_lot_attributes_tbl ( 41 ).column_value,
2283 g_lot_attributes_tbl ( 42 ).column_value,
2284 g_lot_attributes_tbl ( 43 ).column_value,
2285 g_lot_attributes_tbl ( 44 ).column_value,
2286 fnd_date.canonical_to_date (
2287 g_lot_attributes_tbl ( 45 ).column_value
2288 ),
2289 fnd_date.canonical_to_date (
2290 g_lot_attributes_tbl ( 46 ).column_value
2291 ),
2292 fnd_date.canonical_to_date (
2293 g_lot_attributes_tbl ( 47 ).column_value
2294 ),
2295 fnd_date.canonical_to_date (
2296 g_lot_attributes_tbl ( 48 ).column_value
2297 ),
2298 fnd_date.canonical_to_date (
2299 g_lot_attributes_tbl ( 49 ).column_value
2300 ),
2301 fnd_date.canonical_to_date (
2302 g_lot_attributes_tbl ( 50 ).column_value
2303 ),
2304 fnd_date.canonical_to_date (
2305 g_lot_attributes_tbl ( 51 ).column_value
2306 ),
2307 fnd_date.canonical_to_date (
2308 g_lot_attributes_tbl ( 52 ).column_value
2309 ),
2310 fnd_date.canonical_to_date (
2311 g_lot_attributes_tbl ( 53 ).column_value
2312 ),
2313 fnd_date.canonical_to_date (
2314 g_lot_attributes_tbl ( 54 ).column_value
2315 ),
2316 TO_NUMBER ( g_lot_attributes_tbl ( 55 ).column_value ),
2317 TO_NUMBER ( g_lot_attributes_tbl ( 56 ).column_value ),
2318 TO_NUMBER ( g_lot_attributes_tbl ( 57 ).column_value ),
2319 TO_NUMBER ( g_lot_attributes_tbl ( 58 ).column_value ),
2320 TO_NUMBER ( g_lot_attributes_tbl ( 59 ).column_value ),
2321 TO_NUMBER ( g_lot_attributes_tbl ( 60 ).column_value ),
2322 TO_NUMBER ( g_lot_attributes_tbl ( 61 ).column_value ),
2323 TO_NUMBER ( g_lot_attributes_tbl ( 62 ).column_value ),
2324 TO_NUMBER ( g_lot_attributes_tbl ( 63 ).column_value ),
2325 g_lot_attributes_tbl ( 64 ).column_value,
2326 TO_NUMBER ( g_lot_attributes_tbl ( 65 ).column_value ),
2327 g_lot_attributes_tbl ( 66 ).column_value,
2328 g_lot_attributes_tbl ( 67 ).column_value,
2329 mtlt.product_code,
2330 mtlt.product_transaction_id
2331 FROM mtl_transaction_lots_temp mtlt
2332 WHERE transaction_temp_id = p_transaction_temp_id
2333 AND lot_number = p_lot_number
2334 -- Hack for bug 2130268
2335 -- What if any transaction has the same lot 'p_lot_number' twice !!
2336 -- The insert statement then inserts two records instead of one,
2337 -- hence the following 'not exists' clause
2338 AND NOT EXISTS (
2339 SELECT NULL
2340 FROM mtl_transaction_lot_numbers mtln
2341 WHERE mtln.lot_number = p_lot_number
2342 AND mtln.primary_quantity =
2343 DECODE (
2344 l_mmtt_pri_quantity,
2345 1, ROUND (
2346 ( ABS (
2347 mtlt.primary_quantity
2348 )
2349 * -1
2350 ),
2351 5
2352 ),
2353 ROUND (
2354 ABS (
2355 mtlt.primary_quantity
2356 ),
2357 5
2358 )
2359 )
2360 AND mtln.inventory_item_id =
2361 p_inventory_item_id
2362 AND mtln.organization_id = p_organization_id
2363 AND mtln.transaction_date =
2364 p_transaction_date
2365 AND NVL ( mtln.transaction_source_id, -1 ) =
2366 NVL ( p_transaction_source_id, -1 )
2367 AND NVL (
2368 mtln.transaction_source_type_id,
2369 -1
2370 ) = NVL (
2371 p_transaction_source_type_id,
2372 -1
2373 )
2374 AND NVL (
2375 mtln.transaction_source_name,
2376 '$$$'
2377 ) = NVL (
2378 p_transaction_source_name,
2379 '$$$'
2380 )
2381 AND mtln.transaction_id = p_transaction_id );
2382
2383 -- Hack for bug 2130268
2384 x_return_status := fnd_api.g_ret_sts_success;
2385 END IF;
2386
2387 IF ( fnd_api.to_boolean ( p_commit ) )
2388 THEN
2389 COMMIT;
2390 END IF;
2391
2392 -- Standard call to get message count and if count is 1, get message info.
2393 fnd_msg_pub.count_and_get (
2394 p_encoded => fnd_api.g_false,
2395 p_count => x_msg_count,
2396 p_data => x_msg_data
2397 );
2398 EXCEPTION
2399 WHEN OTHERS
2400 THEN
2401 ROLLBACK TO apiinsertlot_apipub;
2402
2403 IF fnd_msg_pub.check_msg_level (
2404 fnd_msg_pub.g_msg_lvl_unexp_error
2405 )
2406 THEN
2407 fnd_msg_pub.add_exc_msg ('INV_LOT_API_PUB' , 'insertLot' );
2408 END IF;
2409
2410 x_return_status := fnd_api.g_ret_sts_unexp_error;
2411 END inserttrxlot;
2412
2413 FUNCTION validate_unique_lot (
2414 p_org_id IN NUMBER,
2415 p_inventory_item_id IN NUMBER,
2416 p_lot_uniqueness IN NUMBER,
2417 p_auto_lot_number IN VARCHAR2
2418 )
2419 RETURN BOOLEAN
2420 IS
2421 l_lot_number NUMBER := 0;
2422 l_lot_uniqueness NUMBER := p_lot_uniqueness;
2423 l_count NUMBER := 0;
2424 l_api_name CONSTANT VARCHAR2 ( 50 )
2425 := 'INV_LOT_API_PUB.validate_unique_lot';
2426
2427 CURSOR mln_cur_2
2428 IS
2429 SELECT lot_number
2430 FROM mtl_lot_numbers
2431 WHERE lot_number = p_auto_lot_number
2432 AND inventory_item_id <> p_inventory_item_id;
2433
2434 CURSOR mtln_cur_2
2435 IS
2436 SELECT lot_number
2437 FROM mtl_transaction_lot_numbers
2438 WHERE lot_number = p_auto_lot_number
2439 AND inventory_item_id <> p_inventory_item_id;
2440
2441 CURSOR mtlt_cur_2
2442 IS
2443 SELECT lot.lot_number
2444 FROM mtl_transaction_lots_temp lot,
2445 mtl_material_transactions_temp mmtt
2446 WHERE lot.transaction_temp_id = mmtt.transaction_temp_id
2447 AND lot.lot_number = p_auto_lot_number
2448 AND mmtt.inventory_item_id <> p_inventory_item_id;
2449
2450 CURSOR mmtt_cur_2
2451 IS
2452 SELECT lot_number
2453 FROM mtl_material_transactions_temp lot
2454 WHERE lot_number = p_auto_lot_number
2455 AND inventory_item_id <> p_inventory_item_id;
2456 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
2457 BEGIN
2458 IF l_lot_uniqueness IS NULL
2459 THEN
2460 BEGIN
2461 SELECT lot_number_uniqueness
2462 INTO l_lot_uniqueness
2463 FROM mtl_parameters
2464 WHERE organization_id = p_org_id;
2465 EXCEPTION
2466 WHEN NO_DATA_FOUND
2467 THEN
2468 RAISE fnd_api.g_exc_error;
2469 END;
2470 END IF;
2471
2472 IF ( l_lot_uniqueness = 1 ) -- Item level control
2473 THEN
2474 BEGIN
2475 FOR mln_rec IN mln_cur_2
2476 LOOP
2477 l_count := 1;
2478 EXIT;
2479 END LOOP;
2480
2481 IF ( l_count > 0 )
2482 THEN
2483 RETURN FALSE;
2484 ELSE
2485 l_count := 0;
2486 END IF;
2487
2488 FOR mtln_rec IN mtln_cur_2
2489 LOOP
2490 l_count := 1;
2491 EXIT;
2492 END LOOP;
2493
2494 IF ( l_count > 0 )
2495 THEN
2496 RETURN FALSE;
2497 ELSE
2498 l_count := 0;
2499 END IF;
2500
2501 FOR mtlt_rec IN mtlt_cur_2
2502 LOOP
2503 l_count := 1;
2504 EXIT;
2505 END LOOP;
2506
2507 IF ( l_count > 0 )
2508 THEN
2509 RETURN FALSE;
2510 ELSE
2511 l_count := 0;
2512 END IF;
2513
2514 FOR mtlt_rec IN mtlt_cur_2
2515 LOOP
2516 l_count := 1;
2517 EXIT;
2518 END LOOP;
2519
2520 IF ( l_count > 0 )
2521 THEN
2522 RETURN FALSE;
2523 END IF;
2524 END;
2525 END IF;
2526
2527 RETURN TRUE;
2528 EXCEPTION
2529 WHEN OTHERS
2530 THEN
2531 IF fnd_msg_pub.check_msg_level (
2532 fnd_msg_pub.g_msg_lvl_unexp_error
2533 )
2534 THEN
2535 fnd_msg_pub.add_exc_msg ( g_pkg_name, l_api_name );
2536 END IF;
2537
2538 RETURN FALSE;
2539 END validate_unique_lot;
2540
2541 PROCEDURE update_msi (
2542 p_org_id IN NUMBER,
2543 p_inventory_item_id IN NUMBER,
2544 p_new_suffix IN VARCHAR2,
2545 p_lot_uniqueness IN NUMBER DEFAULT NULL,
2546 p_lot_generation IN NUMBER DEFAULT NULL,
2547 x_return_status OUT NOCOPY VARCHAR2,
2548 p_lot_prefix IN VARCHAR2 -- Bug# 7298723
2549 )
2550 IS
2551 PRAGMA AUTONOMOUS_TRANSACTION;
2552 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
2553 l_update_count number := 0; -- Bug# 7298723
2554
2555 /* Added for bug 8428348 */
2556 l_return_status VARCHAR2(1) := NULL;
2557 l_got_lock BOOLEAN := FALSE;
2558 /* End of changes for bug 8428348 */
2559
2560 BEGIN
2561 x_return_status := fnd_api.g_ret_sts_success;
2562 IF (l_debug =1 ) THEN
2563 print_debug('before updating msi '||p_lot_prefix,9);
2564 END IF;
2565
2566 /* Added for bug 8428348 */
2567 l_got_lock:= inv_lot_sel_attr.lock_lot_records(p_org_id
2568 , p_inventory_item_id
2569 , p_lot_uniqueness
2570 , p_lot_generation
2571 , p_lot_prefix
2572 , l_return_status);
2573
2574 IF NOT (l_got_lock) THEN
2575 IF l_return_status <> 'S' THEN
2576 x_return_status := fnd_api.g_ret_sts_error;
2577 END IF;
2578 ROLLBACK;
2579 ELSE /* not (l_got_lock) */
2580 print_debug('Got lock on lot items ', 9);
2581 /* end of changes for bug 8428348 */
2582 if( p_lot_generation = 2 AND p_lot_uniqueness = 1 ) THEN
2583 UPDATE mtl_system_items_b
2584 SET start_auto_lot_number = p_new_suffix
2585 -- Bug# 7298723
2586 -- WHERE organization_id = p_org_id
2587 WHERE auto_lot_alpha_prefix = p_lot_prefix
2588 AND lot_control_code = 2;
2589 -- End of Bug# 7298723
2590 --AND inventory_item_id = p_inventory_item_id;
2591 l_update_count := SQL%ROWCOUNT; -- Bug# 7298723
2592
2593 elsif( p_lot_generation = 2 and p_lot_uniqueness <> 1 ) THEN
2594 UPDATE mtl_system_items
2595 SET start_auto_lot_number = p_new_suffix
2596 WHERE organization_id = p_org_id
2597 AND inventory_item_id = p_inventory_item_id;
2598
2599 l_update_count := SQL%ROWCOUNT; -- Bug# 7298723
2600
2601 end if;
2602 -- Bug 2700722.. commit the transaction after confirming that records exist
2603 -- else, return an error status
2604 -- COMMIT;
2605
2606 IF l_update_count > 0 THEN -- Bug# 7298723
2607 IF (l_debug =1 ) THEN
2608 print_debug('commiting',9);
2609 END IF;
2610
2611 COMMIT;
2612
2613 ELSE
2614 ROLLBACK;
2615 IF (l_debug =1 ) THEN
2616 print_debug('not found',9);
2617 END IF;
2618 fnd_message.set_name ('INV' , 'INV_LOT_AUTOGEN_FAILED' ); -- Bug# 7298723
2619 -- fnd_message.set_token ('ENTITY1' , 'Item with last lot number' ); -- Bug# 7298723
2620 fnd_msg_pub.ADD;
2621 x_return_status := fnd_api.g_ret_sts_error;
2622 --AND inventory_item_id = p_inventory_item_id;
2623 END IF;
2624 END IF; /* if not (l_got_lock) */
2625 END;
2626
2627 /*=============================================================
2628 Autonomous function to insert to mtl_child_lot_numbers.
2629 Added by Joe DiIorio for OPM Convergence. 05/18/2004
2630 =============================================================*/
2631
2632
2633 FUNCTION ins_mtl_child_lot_num (
2634 p_org_id IN NUMBER,
2635 p_inventory_item_id IN NUMBER,
2636 p_parent_lot_number IN VARCHAR2,
2637 p_last_child_lot_seq IN NUMBER
2638 )
2639 RETURN NUMBER
2640 IS
2641 PRAGMA AUTONOMOUS_TRANSACTION;
2642
2643 l_userid FND_USER.USER_ID%TYPE;
2644 l_loginid NUMBER;
2645
2646 BEGIN
2647
2648 l_userid := fnd_global.user_id;
2649 l_loginid := fnd_global.login_id;
2650
2651 INSERT into mtl_child_lot_numbers
2652 (organization_id, inventory_item_id,
2653 parent_lot_number, last_child_lot_number_seq,
2654 creation_date, created_by, last_update_date,
2655 last_updated_by, last_update_login)
2656 VALUES (p_org_id, p_inventory_item_id, p_parent_lot_number,
2657 p_last_child_lot_seq, SYSDATE, l_userid,
2658 SYSDATE, l_userid, l_loginid);
2659
2660 COMMIT;
2661 RETURN SQLCODE;
2662
2663 END ins_mtl_child_lot_num;
2664
2665
2666 /*=============================================================
2667 Autonomous function to update to mtl_child_lot_numbers.
2668 Added by Joe DiIorio for OPM Convergence. 05/18/2004
2669 =============================================================*/
2670
2671 FUNCTION upd_mtl_child_lot_num (
2672 p_org_id IN NUMBER,
2673 p_inventory_item_id IN NUMBER,
2674 p_parent_lot_number IN VARCHAR2,
2675 p_last_child_lot_seq IN NUMBER
2676 )
2677 RETURN NUMBER
2678 IS
2679 PRAGMA AUTONOMOUS_TRANSACTION;
2680
2681 l_userid FND_USER.USER_ID%TYPE;
2682 l_loginid NUMBER;
2683
2684 BEGIN
2685
2686 l_userid := fnd_global.user_id;
2687 l_loginid := fnd_global.login_id;
2688 UPDATE mtl_child_lot_numbers
2689 SET last_child_lot_number_seq = p_last_child_lot_seq,
2690 last_updated_by = l_userid,
2691 last_update_date = SYSDATE,
2692 last_update_login = l_loginid
2693 WHERE organization_id = p_org_id
2694 AND inventory_item_id = p_inventory_item_id
2695 AND parent_lot_number = p_parent_lot_number;
2696
2697 COMMIT;
2698 RETURN SQLCODE;
2699
2700 END upd_mtl_child_lot_num;
2701
2702
2703
2704 --
2705 -- Fix for Bug#12925054
2706 -- Added new parameters p_transaction_source_id and p_transaction_source_line_id
2707
2708 FUNCTION auto_gen_lot (
2709 p_org_id IN NUMBER,
2710 p_inventory_item_id IN NUMBER,
2711 p_lot_generation IN NUMBER := NULL,
2712 p_lot_uniqueness IN NUMBER := NULL,
2713 p_lot_prefix IN VARCHAR2 := NULL,
2714 p_zero_pad IN NUMBER := NULL,
2715 p_lot_length IN NUMBER := NULL,
2716 p_transaction_date IN DATE := NULL,
2717 p_revision IN VARCHAR2 := NULL,
2718 p_subinventory_code IN VARCHAR2 := NULL,
2719 p_locator_id IN NUMBER := NULL,
2720 p_transaction_type_id IN NUMBER := NULL,
2721 p_transaction_action_id IN NUMBER := NULL,
2722 p_transaction_source_type_id IN NUMBER := NULL,
2723 p_lot_number IN VARCHAR2 := NULL,
2724 p_api_version IN NUMBER,
2725 p_init_msg_list IN VARCHAR2 := fnd_api.g_false,
2726 p_commit IN VARCHAR2 := fnd_api.g_false,
2727 p_validation_level IN NUMBER
2728 := fnd_api.g_valid_level_full,
2729 p_parent_lot_number IN VARCHAR2,
2730 x_return_status OUT NOCOPY VARCHAR2,
2731 x_msg_count OUT NOCOPY NUMBER,
2732 x_msg_data OUT NOCOPY VARCHAR2,
2733 p_transaction_source_id IN NUMBER := NULL, /* 13368816 */
2734 p_transaction_source_line_id IN NUMBER := NULL /* 13368816 */
2735 )
2736 RETURN VARCHAR2
2737 IS
2738 /* Mrana : - New version of auto lot gen that calls the user_defined lot_number
2739 generation routine */
2740 lot_generation NUMBER := p_lot_generation;
2741 lot_uniqueness NUMBER := p_lot_uniqueness;
2742 lot_prefix VARCHAR2 ( 80 ) := p_lot_prefix;
2743 zero_pad NUMBER := p_zero_pad;
2744 lot_length NUMBER := p_lot_length;
2745 l_lot_prefix VARCHAR2 ( 80 );
2746 l_lot_prefix_length NUMBER;
2747 l_new_suffix VARCHAR2 ( 80 );
2748 l_lot_suffix VARCHAR2 ( 80 );
2749 l_lot_suffix_length NUMBER;
2750 l_found BOOLEAN;
2751 l_lot_control_code NUMBER;
2752 auto_lot_number VARCHAR2 ( 80 ) := NULL;
2753 l_unique_lot BOOLEAN := FALSE;
2754 l_lotcount NUMBER;
2755 l_api_version CONSTANT NUMBER := 1.0;
2756 l_api_name CONSTANT VARCHAR2 ( 50 ) := 'INV_LOT_API_PUB.auto_gen_lot';
2757 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
2758 -- The following 2 variables are added as a part of bug fix for: Bug #3330855
2759 v_org_code VARCHAR2 ( 3 );
2760 v_item_name VARCHAR2 ( 80 );
2761
2762 /*======================================
2763 OPM Convergence
2764 Added cursors to check for existence
2765 of parent lot in temp or permanent
2766 table.
2767 Removed check for existing parent lot.
2768 CURSOR mtlt_cur_1 IS
2769 SELECT lot.lot_number
2770 FROM mtl_transaction_lots_temp lot,
2771 mtl_material_transactions_temp mmtt
2772 WHERE lot.transaction_temp_id = mmtt.transaction_temp_id
2773 AND lot.lot_number = p_parent_lot_number
2774 AND inventory_item_id = p_inventory_item_id;
2775
2776
2777 CURSOR get_mtl_lot IS
2778 SELECT lot_number
2779 FROM mtl_lot_numbers
2780 WHERE lot_number = p_parent_lot_number
2781 AND organization_id = p_org_id
2782 AND inventory_item_id = p_inventory_item_id;
2783
2784 x_lot_number MTL_LOT_NUMBERS.LOT_NUMBER%TYPE := NULL;
2785 ===========================================*/
2786
2787 /*=============================================
2788 Following variable controls looping until a
2789 valid child lot is found.
2790 =============================================*/
2791 l_unique_child_lot BOOLEAN := FALSE;
2792
2793 /*====================================
2794 OPM Convergence
2795 Added cursor to get Item Master setup.
2796 Variables following this cursor are
2797 used to receive the values from the
2798 cursor.
2799 ======================================*/
2800 CURSOR get_item_data IS
2801 SELECT child_lot_flag, parent_child_generation_flag,
2802 child_lot_prefix, child_lot_starting_number
2803 FROM mtl_system_items_b -- NSRIVAST, Changed the name to MTL_SYSTEM_ITEMS_B as per review comments by Shelly
2804 WHERE organization_id = p_org_id
2805 AND inventory_item_id = p_inventory_item_id;
2806
2807 x_child_lot_flag MTL_SYSTEM_ITEMS.CHILD_LOT_FLAG%TYPE;
2808 x_item_parent_child_gen_flag MTL_SYSTEM_ITEMS.PARENT_CHILD_GENERATION_FLAG%TYPE;
2809 x_item_child_lot_prefix MTL_SYSTEM_ITEMS.CHILD_LOT_PREFIX%TYPE;
2810 x_child_lot_starting_number MTL_SYSTEM_ITEMS.CHILD_LOT_STARTING_NUMBER%TYPE;
2811
2812
2813 /*====================================
2814 OPM Convergence
2815 Added cursor to get child mtl parms.
2816 Variables that follow the cursor are
2817 used to accept the data returned
2818 from the cursor.
2819 ====================================*/
2820 CURSOR get_child_parms IS
2821 SELECT lot_number_generation,
2822 parent_child_generation_flag,
2823 child_lot_zero_padding_flag,
2824 child_lot_alpha_prefix, NVL(child_lot_number_length,80)
2825 FROM mtl_parameters
2826 WHERE organization_id = p_org_id;
2827
2828 x_parent_child_generation_flag MTL_PARAMETERS.PARENT_CHILD_GENERATION_FLAG%TYPE;
2829 x_child_lot_zero_padding_flag MTL_PARAMETERS.CHILD_LOT_ZERO_PADDING_FLAG%TYPE;
2830 x_child_lot_alpha_prefix MTL_PARAMETERS.CHILD_LOT_ALPHA_PREFIX%TYPE;
2831 x_child_lot_number_length MTL_PARAMETERS.CHILD_LOT_NUMBER_LENGTH%TYPE;
2832 x_lot_number_generation MTL_PARAMETERS.LOT_NUMBER_GENERATION%TYPE;
2833
2834 /*======================================
2835 x_pad_value is the number of
2836 characters to be padded in the child
2837 lot suffix.
2838 ====================================*/
2839
2840 x_pad_value NUMBER;
2841
2842 /*======================================
2843 x_parent_lot_number is a placeholder to
2844 pass null in this value when recalling
2845 the generation routine.
2846 x_parent_call is the lot returned from
2847 the recall.
2848 ====================================*/
2849
2850 x_parent_lot_number MTL_LOT_NUMBERS.LOT_NUMBER%TYPE;
2851 x_parent_call MTL_LOT_NUMBERS.LOT_NUMBER%TYPE;
2852
2853 /*========================================
2854 interim_child_lot_number is the generated
2855 child lot that is a candidate to be
2856 passed back. Becomes passed back if
2857 it does not exist already.
2858 interim prefix is child lot prefix
2859 concatenated with parent lot.
2860 ======================================*/
2861
2862
2863 /*=======================================
2864 BUG#4145437 - increased interim size.
2865 =======================================*/
2866 interim_child_lot_number VARCHAR2(300);
2867 x_interim_child_prefix VARCHAR2(200);
2868
2869 /*========================================
2870 Cursor to check if candidate child lot
2871 exists already. Variable l_sublotcount
2872 is used with this cursor.
2873 ======================================*/
2874
2875 CURSOR check_lot_exists IS
2876 SELECT count( 1 )
2877 FROM mtl_lot_numbers
2878 WHERE inventory_item_id = p_inventory_item_id
2879 AND organization_id = p_org_id
2880 AND lot_number = interim_child_lot_number;
2881
2882 l_sublotcount NUMBER;
2883
2884 /*====================================
2885 l_ret is used in calls to functions
2886 to insert/update child lot table.
2887 ====================================*/
2888 l_ret NUMBER;
2889
2890 /*====================================
2891 Cursor to get next child number.
2892 x_last_child_seq is used with this
2893 cursor.
2894 ====================================*/
2895
2896 CURSOR get_next_child IS
2897 SELECT last_child_lot_number_seq
2898 FROM mtl_child_lot_numbers
2899 WHERE inventory_item_id = p_inventory_item_id
2900 AND organization_id = p_org_id
2901 AND parent_lot_number = p_parent_lot_number;
2902
2903 x_last_child_seq NUMBER;
2904
2905 /*====================================
2906 x_last_child_seq_pad holds the
2907 padded format of x_last_child_seq.
2908 ====================================*/
2909
2910 x_last_child_seq_pad VARCHAR2(80);
2911
2912
2913
2914 BEGIN
2915 -- Standard Start of API savepoint
2916 SAVEPOINT apiauto_gen_lot_apipub;
2917 IF (l_debug = 1) THEN
2918 print_debug('in auto_gen_lot',9);
2919 END IF;
2920 -- Standard call to check for call compatibility.
2921
2922 IF NOT fnd_api.compatible_api_call (
2923 l_api_version,
2924 p_api_version,
2925 l_api_name,
2926 g_pkg_name
2927 )
2928 THEN
2929 RAISE fnd_api.g_exc_unexpected_error;
2930 END IF;
2931
2932 -- Initialize message list if p_init_msg_list is set to TRUE.
2933 IF fnd_api.to_boolean ( p_init_msg_list )
2934 THEN
2935 fnd_msg_pub.initialize;
2936 END IF;
2937
2938 -- Initialize API return status to success
2939 x_return_status := fnd_api.g_ret_sts_success;
2940
2941 -- API body
2942
2943 /*================================================
2944 Joe DiIorio 05/17/2004 OPM Convergence.
2945 Added logic upfront to deal with parent_lot.
2946 Standard lot generation will bypass this
2947 and proceed as usual. Entry of parent lot
2948 means you want to generate a child lot.
2949 ==============================================*/
2950 IF (p_parent_lot_number IS NOT NULL) THEN
2951 /*===========================================
2952 Check if child_lot_split is allowed and
2953 retrieve all item master parms.
2954 ===========================================*/
2955 OPEN get_item_data;
2956 FETCH get_item_data INTO
2957 x_child_lot_flag, x_item_parent_child_gen_flag,
2958 x_item_child_lot_prefix, x_child_lot_starting_number;
2959 IF (get_item_data%NOTFOUND) THEN
2960 CLOSE get_item_data;
2961 fnd_message.set_name ('INV' , 'INV_CL_GET_ITEM_ERR' );
2962 fnd_msg_pub.ADD;
2963 RAISE fnd_api.g_exc_error;
2964 END IF;
2965 CLOSE get_item_data;
2966 /*===========================================
2967 Is child_lot split allowed?
2968 ===========================================*/
2969 IF (nvl(x_child_lot_flag,'N') = 'N') THEN
2970 fnd_message.set_name ('INV' , 'INV_CL_CHILD_LOT_DISABLED');
2971 fnd_msg_pub.ADD;
2972 RAISE fnd_api.g_exc_error;
2973 END IF;
2974 /*===========================================
2975 Get the Child lot generation parameters.
2976 ===========================================*/
2977 OPEN get_child_parms;
2978 FETCH get_child_parms INTO
2979 x_lot_number_generation,
2980 x_parent_child_generation_flag,
2981 x_child_lot_zero_padding_flag,
2982 x_child_lot_alpha_prefix, x_child_lot_number_length;
2983 IF (get_child_parms%NOTFOUND) THEN
2984 CLOSE get_child_parms;
2985 fnd_message.set_name ('INV' , 'INV_CL_GET_PARM_ERR');
2986 fnd_msg_pub.ADD;
2987 RAISE fnd_api.g_exc_error;
2988 END IF;
2989 CLOSE get_child_parms;
2990
2991
2992 /*===========================================
2993 Loop until we have a valid unique lot.
2994 ===========================================*/
2995 WHILE NOT ( l_unique_child_lot = TRUE )
2996 LOOP
2997 /*===========================================
2998 Parent Lot Logic First Check User Defined.
2999 Added parent lot number to call parameters.
3000 ===========================================*/
3001 IF (x_lot_number_generation = 3) THEN
3002 interim_child_lot_number :=
3003 user_pkg_lot.generate_lot_number (
3004 p_org_id,
3005 p_inventory_item_id,
3006 p_transaction_date,
3007 p_revision,
3008 p_subinventory_code,
3009 p_locator_id,
3010 p_transaction_type_id,
3011 p_transaction_action_id,
3012 p_transaction_source_type_id,
3013 p_transaction_source_id, /* 12925054 */
3014 p_transaction_source_line_id, /* 12925054 */
3015 p_lot_number,
3016 p_parent_lot_number,
3017 x_return_status
3018 );
3019
3020 IF ( x_return_status = fnd_api.g_ret_sts_error )
3021 THEN
3022 RAISE fnd_api.g_exc_error;
3023 END IF;
3024
3025 IF ( x_return_status = fnd_api.g_ret_sts_unexp_error )
3026 THEN
3027 RAISE fnd_api.g_exc_unexpected_error;
3028 END IF;
3029 /*===========================================
3030 If child lot generated by user routine then
3031 return it, Otherwise if null then return
3032 ===========================================*/
3033 IF (interim_child_lot_number IS NULL) THEN
3034 fnd_message.set_name ('INV' , 'INV_CL_USER_PGM_ERR');
3035 fnd_msg_pub.ADD;
3036 RAISE fnd_api.g_exc_error;
3037 END IF;
3038 /*=================================
3039 BUG#4145437
3040 =================================*/
3041 IF (lengthb(interim_child_lot_number) > 80) THEN
3042 fnd_message.set_name ('INV' , 'INV_CL_MAX_FLD_LENGTH' );
3043 fnd_msg_pub.ADD;
3044 RAISE fnd_api.g_exc_error;
3045 END IF;
3046
3047 ELSIF (x_lot_number_generation = 1) THEN
3048 /*====================================
3049 Organization Level Generation
3050 ===================================*/
3051 IF (x_parent_child_generation_flag = 'C') THEN
3052 OPEN get_next_child;
3053 FETCH get_next_child INTO x_last_child_seq;
3054 IF get_next_child%NOTFOUND THEN
3055 CLOSE get_next_child;
3056 x_last_child_seq := 1;
3057 /*=======================================
3058 Insert mtl_child_lot_numbers record.
3059 =======================================*/
3060 l_ret := ins_mtl_child_lot_num(p_org_id,
3061 p_inventory_item_id,
3062 p_parent_lot_number,
3063 x_last_child_seq);
3064 IF (l_ret <> 0 ) THEN
3065 fnd_message.set_name ('INV','INV_CL_INS_CHILD_ERR');
3066 fnd_msg_pub.ADD;
3067 RAISE fnd_api.g_exc_error;
3068 END IF;
3069 ELSE
3070 CLOSE get_next_child;
3071 x_last_child_seq := x_last_child_seq + 1;
3072 /*=======================================
3073 Update mtl_child_lot_numbers record.
3074 =======================================*/
3075 l_ret := upd_mtl_child_lot_num(p_org_id,
3076 p_inventory_item_id,
3077 p_parent_lot_number,
3078 x_last_child_seq);
3079 IF (l_ret <> 0 ) THEN
3080 fnd_message.set_name ('INV','INV_CL_UPD_CHILD_ERR');
3081 fnd_msg_pub.ADD;
3082 RAISE fnd_api.g_exc_error;
3083 END IF;
3084 END IF;
3085 /*===============================
3086 Append Parent to alpha prefix.
3087 ===============================*/
3088 x_interim_child_prefix :=
3089 p_parent_lot_number||x_child_lot_alpha_prefix;
3090
3091
3092 IF ( (lengthb(x_interim_child_prefix)
3093 + lengthb(x_last_child_seq)) > 80 ) THEN
3094 fnd_message.set_name ('INV' , 'INV_CL_MAX_FLD_LENGTH' );
3095 fnd_msg_pub.ADD;
3096 RAISE fnd_api.g_exc_error;
3097 END IF;
3098 IF ( (lengthb(x_interim_child_prefix)
3099 + lengthb(x_last_child_seq)) >
3100 x_child_lot_number_length ) THEN
3101 fnd_message.set_name ('INV' , 'INV_CL_MAX_CHLD_ERR' );
3102 fnd_msg_pub.ADD;
3103 RAISE fnd_api.g_exc_error;
3104 END IF;
3105
3106 IF (x_child_lot_zero_padding_flag = 'Y') THEN
3107 x_pad_value :=
3108 x_child_lot_number_length -
3109 length(x_interim_child_prefix);
3110 x_last_child_seq_pad :=
3111 LPAD (x_last_child_seq,x_pad_value,'0');
3112 interim_child_lot_number :=
3113 x_interim_child_prefix||x_last_child_seq_pad;
3114 ELSE
3115 interim_child_lot_number :=
3116 x_interim_child_prefix||x_last_child_seq;
3117 END IF;
3118 ELSE
3119 /*=========================================
3120 Recall this api with parent lot = NULL;
3121 *=========================================*/
3122 x_parent_lot_number := NULL;
3123 x_parent_call := inv_lot_api_pub.auto_gen_lot (
3124 p_org_id,
3125 p_inventory_item_id,
3126 p_lot_generation,
3127 p_lot_uniqueness,
3128 p_lot_prefix,
3129 p_zero_pad,
3130 p_lot_length,
3131 p_transaction_date,
3132 p_revision,
3133 p_subinventory_code,
3134 p_locator_id,
3135 p_transaction_type_id ,
3136 p_transaction_action_id,
3137 p_transaction_source_type_id,
3138 p_lot_number,
3139 p_api_version,
3140 p_init_msg_list,
3141 p_commit,
3142 p_validation_level,
3143 x_parent_lot_number,
3144 x_return_status,
3145 x_msg_count,
3146 x_msg_data,
3147 p_transaction_source_id, /* 13368816 */
3148 p_transaction_source_line_id /* 13368816 */
3149 );
3150 RETURN (x_parent_call);
3151 END IF;
3152
3153
3154 ELSE
3155 /*====================================
3156 Item Level Generation
3157 ===================================*/
3158 IF (x_item_parent_child_gen_flag = 'C') THEN
3159 OPEN get_next_child;
3160 FETCH get_next_child INTO x_last_child_seq;
3161 IF get_next_child%NOTFOUND THEN
3162 CLOSE get_next_child;
3163 x_last_child_seq := x_child_lot_starting_number;
3164 /*=======================================
3165 Insert mtl_child_lot_numbers record.
3166 =======================================*/
3167 l_ret := ins_mtl_child_lot_num(p_org_id,
3168 p_inventory_item_id,
3169 p_parent_lot_number,
3170 x_last_child_seq);
3171 IF (l_ret <> 0 ) THEN
3172 fnd_message.set_name ('INV','INV_CL_INS_CHILD_ERR');
3173 fnd_msg_pub.ADD;
3174 RAISE fnd_api.g_exc_error;
3175 END IF;
3176 ELSE
3177 CLOSE get_next_child;
3178 x_last_child_seq := x_last_child_seq + 1;
3179 /*=======================================
3180 Update mtl_child_lot_numbers record.
3181 =======================================*/
3182 l_ret := upd_mtl_child_lot_num(p_org_id,
3183 p_inventory_item_id,
3184 p_parent_lot_number,
3185 x_last_child_seq);
3186 IF (l_ret <> 0 ) THEN
3187 fnd_message.set_name ('INV','INV_CL_UPD_CHILD_ERR');
3188 fnd_msg_pub.ADD;
3189 RAISE fnd_api.g_exc_error;
3190 END IF;
3191 END IF;
3192 /*===============================
3193 Append Parent to alpha prefix.
3194 ===============================*/
3195 x_interim_child_prefix :=
3196 p_parent_lot_number||x_item_child_lot_prefix;
3197 IF ( (lengthb(x_interim_child_prefix)
3198 + lengthb(x_last_child_seq)) > 80 ) THEN
3199 fnd_message.set_name ('INV' , 'INV_CL_MAX_FLD_ERR' );
3200 fnd_msg_pub.ADD;
3201 RAISE fnd_api.g_exc_error;
3202 END IF;
3203 --temp joe what is length for item child?
3204 interim_child_lot_number :=
3205 x_interim_child_prefix||x_last_child_seq;
3206 ELSE
3207 /*=========================================
3208 Recall this api with parent lot = NULL;
3209 *=========================================*/
3210 x_parent_lot_number := NULL;
3211 x_parent_call := inv_lot_api_pub.auto_gen_lot (
3212 p_org_id,
3213 p_inventory_item_id,
3214 p_lot_generation,
3215 p_lot_uniqueness,
3216 p_lot_prefix,
3217 p_zero_pad,
3218 p_lot_length,
3219 p_transaction_date,
3220 p_revision,
3221 p_subinventory_code,
3222 p_locator_id,
3223 p_transaction_type_id,
3224 p_transaction_action_id,
3225 p_transaction_source_type_id,
3226 p_lot_number,
3227 p_api_version,
3228 p_init_msg_list,
3229 p_commit,
3230 p_validation_level,
3231 x_parent_lot_number,
3232 x_return_status,
3233 x_msg_count,
3234 x_msg_data,
3235 p_transaction_source_id, /* 13368816 */
3236 p_transaction_source_line_id /* 13368816 */
3237 );
3238 RETURN x_parent_call;
3239 END IF;
3240 END IF; -- end of generation checks.
3241 /*======================================
3242 Check if generated child lot exists.
3243 IF unique, then stop.
3244 ======================================*/
3245 OPEN check_lot_exists;
3246 FETCH check_lot_exists INTO l_sublotcount;
3247 CLOSE check_lot_exists;
3248
3249 IF ( l_sublotcount = 0 )
3250 THEN
3251 l_unique_child_lot := TRUE;
3252 ELSE
3253 l_unique_child_lot := FALSE;
3254 END IF;
3255 END LOOP;
3256 RETURN (interim_child_lot_number);
3257
3258 END IF; -- parent_lot_number is null.
3259
3260
3261 /* call the procedure (USER_GENERATE_LOT_NUMBER) to allow the users to
3262 have custom defined lot numbers instead of using the lot numbers
3263 generated by Inventory) . If this procedure is not coded by the users
3264 then it will return a NULL lot number, x_return_status =
3265 FND_API.G_RET_STS_SUCCESS */
3266 /* Fixed bug 2075044 -- added the while loop to generate the lot number.
3267 Check if the generated lot is existed in the mtl_lot_number, then generate
3268 a new lot again. */
3269
3270 WHILE NOT ( l_unique_lot = TRUE ) LOOP
3271
3272 /* Added for bug 7669676 , auto_lot_number is nulled out to generate the next valid lo */
3273 auto_lot_number := NULL ;
3274 /* End of changes for 7669676 */
3275 /*=======================================
3276 OPM Convergence Added parent lot no.
3277 =====================================*/
3278 /*===========================
3279 BUG#4089972
3280 ===========================*/
3281 /*===========================================
3282 Get the Child lot generation parameters.
3283 ===========================================*/
3284 OPEN get_child_parms;
3285 FETCH get_child_parms INTO
3286 x_lot_number_generation,
3287 x_parent_child_generation_flag,
3288 x_child_lot_zero_padding_flag,
3289 x_child_lot_alpha_prefix, x_child_lot_number_length;
3290 IF (get_child_parms%NOTFOUND) THEN
3291 CLOSE get_child_parms;
3292 fnd_message.set_name ('INV' , 'INV_CL_GET_PARM_ERR');
3293 fnd_msg_pub.ADD;
3294 RAISE fnd_api.g_exc_error;
3295 END IF;
3296 CLOSE get_child_parms;
3297 IF (x_lot_number_generation = 3) THEN
3298 auto_lot_number :=
3299 user_pkg_lot.generate_lot_number (
3300 p_org_id,
3301 p_inventory_item_id,
3302 p_transaction_date,
3303 p_revision,
3304 p_subinventory_code,
3305 p_locator_id,
3306 p_transaction_type_id,
3307 p_transaction_action_id,
3308 p_transaction_source_type_id,
3309 p_transaction_source_id, /* 12925054 */
3310 p_transaction_source_line_id, /* 12925054 */
3311 p_lot_number,
3312 p_parent_lot_number,
3313 x_return_status
3314 );
3315
3316 IF ( x_return_status = fnd_api.g_ret_sts_error ) THEN
3317 RAISE fnd_api.g_exc_error;
3318 END IF;
3319
3320 IF ( x_return_status = fnd_api.g_ret_sts_unexp_error ) THEN
3321 RAISE fnd_api.g_exc_unexpected_error;
3322 END IF;
3323
3324 END IF; -- gen is 3
3325 /* If i/p parameter p_lot_generation or p_lot_uniqueness are null that means we do
3326 not know at what level the lot number control is therefore Retrieve the following
3327 information for the input organization_id */
3328
3329 IF ( lot_generation IS NULL OR lot_uniqueness IS NULL) THEN
3330 BEGIN
3331 /*=================================
3332 OPM Default 80 in length not 30.
3333 =================================*/
3334 SELECT lot_number_generation,
3335 lot_number_uniqueness,
3336 NVL ( lot_number_zero_padding, 2 ),
3337 NVL ( lot_number_length, 80 ),
3338 auto_lot_alpha_prefix
3339 INTO lot_generation,
3340 lot_uniqueness,
3341 zero_pad,
3342 lot_length,
3343 lot_prefix
3344 FROM mtl_parameters
3345 WHERE organization_id = p_org_id;
3346 EXCEPTION
3347 WHEN NO_DATA_FOUND THEN
3348 fnd_message.set_name ('INV' , 'INV_FIELD_INVALID' );
3349 fnd_message.set_token ('ENTITY1' , 'p_org_id' );
3350 fnd_msg_pub.ADD;
3351 RAISE fnd_api.g_exc_error;
3352 END;
3353 END IF;
3354
3355 /* If the lot number (auto_lot_number) returned by user_defined_procedure is null
3356 then we should proceed with the generation of lot number as defined in Oracle
3357 inventory */
3358
3359 IF ( auto_lot_number IS NULL ) THEN
3360 IF ( lot_generation = 2 ) THEN -- item-level
3361 BEGIN
3362 IF (l_debug = 1) THEN
3363 print_debug('lot generation is at item level', 9);
3364 END IF;
3365
3366 SELECT lot_control_code
3367 INTO l_lot_control_code
3368 FROM mtl_system_items
3369 WHERE organization_id = p_org_id
3370 AND inventory_item_id = p_inventory_item_id;
3371
3372 IF ( l_lot_control_code = 1 ) THEN
3373 fnd_message.set_name ( 'INV' , 'INV_NO_LOT_CONTROL');
3374 fnd_msg_pub.ADD;
3375 RAISE fnd_api.g_exc_error;
3376 END IF;
3377 EXCEPTION
3378 WHEN NO_DATA_FOUND THEN
3379 fnd_message.set_name ('INV' , 'INV_INVALID_ITEM' );
3380 fnd_msg_pub.ADD;
3381 RAISE fnd_api.g_exc_error;
3382 END;
3383
3384 BEGIN
3385 -- get prefix and default lot number
3386 SELECT auto_lot_alpha_prefix,
3387 start_auto_lot_number
3388 INTO l_lot_prefix,
3389 l_lot_suffix
3390 FROM mtl_system_items
3391 WHERE organization_id = p_org_id
3392 AND inventory_item_id = p_inventory_item_id;
3393 IF (l_debug = 1) THEN
3394 print_debug('lot prefix and start number is ' || l_lot_prefix || ' & ' ||l_lot_suffix,9);
3395 END IF;
3396 IF ( l_lot_suffix IS NOT NULL ) THEN
3397 IF (l_debug = 1) THEN
3398 print_debug('lot suffix is not null',9);
3399 END IF;
3400 -- find lengths
3401 l_lot_prefix_length := NVL ( LENGTHB ( l_lot_prefix ), 0 );
3402 l_lot_suffix_length := NVL ( LENGTHB ( l_lot_suffix ), 0 );
3403 IF (l_debug = 1) THEN
3404 print_debug('lot prefixlength and suffix length is ' || l_lot_prefix_length || ' & ' ||l_lot_suffix_length,9);
3405 print_debug('lot length is ' || nvl(lot_length,80),9); -- INVCONV
3406 END IF;
3407 -- generate only if total length lot less than or equal to lot_length
3408 IF ( l_lot_prefix_length + l_lot_suffix_length <= nvl(lot_length,80)) THEN -- INVCONV
3409 IF (l_debug = 1) THEN
3410 print_debug('l_lot_prefix_length + l_lot_suffix_length <= nvl(lot_length,80)',9); -- INVCONV
3411 END IF;
3412 -- create lot number
3413 auto_lot_number := l_lot_prefix || l_lot_suffix;
3414
3415 -- left pad with zero if lot number begins with zero
3416 IF ( SUBSTR ( l_lot_suffix, 1, 1 ) = '0' ) THEN
3417 -- increment and left pad with zeros
3418 l_new_suffix := LPAD ( TO_CHAR ( TO_NUMBER ( l_lot_suffix ) + 1), l_lot_suffix_length, '0');
3419 ELSE
3420 -- increment lot number
3421 l_new_suffix := TO_CHAR ( TO_NUMBER ( l_lot_suffix ) + 1);
3422 END IF;
3423
3424 -- set new lot number
3425 -- OPM changed to 80.
3426 IF ( LENGTHB ( l_new_suffix ) <= 80 ) THEN
3427 IF (l_debug = 1) THEN
3428 print_debug('setting new lot number..calling update_msi with params' ||
3429 p_org_id || ' ' || p_inventory_item_id || ' ' || l_new_suffix,9);
3430 END IF;
3431
3432 update_msi (
3433 p_org_id,
3434 p_inventory_item_id,
3435 l_new_suffix,
3436 lot_uniqueness,
3437 lot_generation,
3438 x_return_status,
3439 l_lot_prefix -- Bug# 7298723
3440 );
3441 IF x_return_status = fnd_api.g_ret_sts_error THEN
3442 IF (l_debug = 1) THEN
3443 print_debug('it is an error ',9);
3444 END IF;
3445 RAISE fnd_api.g_exc_error;
3446 END IF;
3447 END IF;
3448 ELSE -- lot length exceeds 80
3449 fnd_message.set_name ( 'INV' , 'INV_SERIAL_LOT_TOO_LONG');
3450 fnd_message.set_token( 'LENGTH', nvl(lot_length, 80)); -- INVCONV
3451 fnd_msg_pub.ADD;
3452 RAISE fnd_api.g_exc_error;
3453 END IF;
3454 ELSE -- l_lot_suffix is NULL
3455 fnd_message.set_name ( 'INV' , 'INV_FIELD_INVALID');
3456
3457 -- Following query added as a part of the bug fix for Bug # 3330855
3458 SELECT ORGANIZATION_CODE, CONCATENATED_SEGMENTS
3459 INTO v_org_code, v_item_name
3460 FROM MTL_PARAMETERS ORG, MTL_SYSTEM_ITEMS_KFV ITEM
3461 WHERE ORG.ORGANIZATION_ID = p_org_id
3462 AND INVENTORY_ITEM_ID = p_inventory_item_id
3463 AND ITEM.ORGANIZATION_ID = p_org_id;
3464
3465 fnd_message.set_token ( 'ENTITY1' , 'Lot Suffix for Org: ' || v_org_code || ' and Item: ' || v_item_name);
3466 fnd_msg_pub.ADD;
3467 RAISE fnd_api.g_exc_error;
3468 END IF;
3469 EXCEPTION
3470 WHEN NO_DATA_FOUND THEN
3471 IF (l_debug=1) THEN
3472 print_debug('no data found',9);
3473 END IF;
3474 fnd_message.set_name ('INV' , 'INV_INVALID_ITEM' );
3475 fnd_message.set_token ( 'ENTITY1' , 'p_org_id, p_inventory_item_id');
3476 fnd_msg_pub.ADD;
3477 RAISE fnd_api.g_exc_error;
3478 END;
3479 ELSIF ( lot_generation = 1 ) THEN -- org-level
3480 BEGIN
3481 IF (l_debug =1 ) THEN
3482 print_debug('lot generation is at org level ',9);
3483 END IF;
3484 -- set lot prefix
3485 l_lot_prefix := lot_prefix;
3486
3487 -- get next org level lot number
3488 SELECT TO_CHAR ( mtl_lot_numeric_suffix_s.NEXTVAL )
3489 INTO l_lot_suffix
3490 FROM sys.DUAL;
3491 IF (l_debug =1 ) THEN
3492 print_debug('lot prefix is ' || l_lot_prefix || 'suffix is ' || l_lot_suffix,9);
3493 END IF;
3494 -- find lengths
3495 l_lot_prefix_length := NVL ( LENGTHB ( l_lot_prefix ), 0 );
3496 l_lot_suffix_length := NVL ( LENGTHB ( l_lot_suffix ), 0 );
3497 IF (l_debug =1 ) THEN
3498 print_debug('lot prefix length is ' || l_lot_prefix_length || ' suffix length is ' || l_lot_suffix_length,9);
3499 END IF;
3500 -- generate only if total lot length less than or equal to lot_length
3501 IF ( l_lot_prefix_length + l_lot_suffix_length <= lot_length) THEN
3502 IF (l_debug =1 ) THEN
3503 print_debug('sum < lot length',9);
3504 END IF;
3505 IF ( zero_pad = 1 ) THEN -- YES = 1 AND 2 = NO
3506 auto_lot_number := lot_prefix || LPAD ( l_lot_suffix, lot_length - l_lot_prefix_length, '0');
3507 ELSE
3508 auto_lot_number := l_lot_prefix || l_lot_suffix;
3509 END IF;
3510 ELSE -- lot length exceeds 80
3511 fnd_message.set_name ( 'INV' , 'INV_SERIAL_LOT_TOO_LONG');
3512 fnd_message.set_token( 'LENGTH', nvl(lot_length, 80)); -- INVCONV
3513 fnd_msg_pub.ADD;
3514 RAISE fnd_api.g_exc_error;
3515 END IF;
3516 END;
3517 END IF;
3518 END IF;
3519
3520
3521 --RETURN (auto_lot_number);
3522 /*
3523 IF inv_lot_api_pub.validate_unique_lot
3524 ( p_org_id,
3525 p_inventory_item_id,
3526 lot_uniqueness,
3527 auto_lot_number)
3528 THEN
3529 RETURN (auto_lot_number);
3530 ELSE
3531 fnd_message.set_name('INV', 'INV_LOT_NUMBER_EXISTS');
3532 fnd_msg_pub.add;
3533 RAISE fnd_api.g_exc_error ;
3534 END IF;
3535 */
3536
3537 /* Check if the generated lot is already existed in the mtl_lot_number,
3538 set the l_unique_lot = FALSE and go back to the while loop to generate
3539 a new lot, otherwise l_unique_lot = TRUE and return the lot number */
3540 --Bug 3750324 Validating the uniqueness of lot through existing api for checking validation so that the unique lot is
3541 -- generated at first go on the form
3542 /* SELECT COUNT ( 1 )
3543 INTO l_lotcount
3544 FROM mtl_lot_numbers
3545 WHERE
3546 inventory_item_id = p_inventory_item_id AND
3547 organization_id = p_org_id AND
3548 lot_number = auto_lot_number;
3549
3550 IF ( l_lotcount = 0 )
3551 THEN
3552 l_unique_lot := TRUE;
3553 ELSE
3554 l_unique_lot := FALSE;
3555 END IF; */
3556 l_unique_lot :=
3557 inv_lot_api_pub.validate_unique_lot(
3558 p_org_id
3559 , p_inventory_item_id
3560 , p_lot_uniqueness
3561 , auto_lot_number
3562 );
3563 --Bug 3750324 Ends
3564 END LOOP;
3565 IF (l_debug =1 ) THEN
3566 print_debug('returning lot number ' || auto_lot_number,9);
3567 END IF;
3568 RETURN ( auto_lot_number );
3569 EXCEPTION
3570 WHEN fnd_api.g_exc_error THEN
3571 ROLLBACK TO apiauto_gen_lot_apipub;
3572 x_return_status := fnd_api.g_ret_sts_error;
3573 fnd_msg_pub.count_and_get (
3574 p_encoded => fnd_api.g_false,
3575 p_count => x_msg_count,
3576 p_data => x_msg_data
3577 );
3578 --Bugfix 3940851 {
3579 if( x_msg_count > 1 ) then
3580 x_msg_data := fnd_msg_pub.get(x_msg_count, FND_API.G_FALSE);
3581 end if;
3582 --Bugfix 3940851 }
3583 RETURN ( NULL );
3584 WHEN fnd_api.g_exc_unexpected_error THEN
3585 ROLLBACK TO apiauto_gen_lot_apipub;
3586 x_return_status := fnd_api.g_ret_sts_unexp_error;
3587 fnd_msg_pub.count_and_get (
3588 p_encoded => fnd_api.g_false,
3589 p_count => x_msg_count,
3590 p_data => x_msg_data
3591 );
3592 --Bugfix 3940851 {
3593 if( x_msg_count > 1 ) then
3594 x_msg_data := fnd_msg_pub.get(x_msg_count, FND_API.G_FALSE);
3595 end if;
3596 --Bugfix 3940851 }
3597 RETURN ( NULL );
3598 WHEN OTHERS THEN
3599 ROLLBACK TO apiauto_gen_lot_apipub;
3600 x_return_status := fnd_api.g_ret_sts_unexp_error;
3601
3602 IF fnd_msg_pub.check_msg_level ( fnd_msg_pub.g_msg_lvl_unexp_error) THEN
3603 fnd_msg_pub.add_exc_msg ( g_pkg_name, l_api_name );
3604 END IF;
3605
3606 fnd_msg_pub.count_and_get (
3607 p_encoded => fnd_api.g_false,
3608 p_count => x_msg_count,
3609 p_data => x_msg_data
3610 );
3611 --Bugfix 3940851 {
3612 if( x_msg_count > 1 ) then
3613 x_msg_data := fnd_msg_pub.get(x_msg_count, FND_API.G_FALSE);
3614 end if;
3615 --Bugfix 3940851 }
3616 RETURN ( NULL );
3617 END auto_gen_lot;
3618
3619
3620 /* Created a wrapper around validate_unique_lot to be able to call it thru Mobile apps */
3621 PROCEDURE validate_unique_lot (
3622 p_org_id IN NUMBER,
3623 p_inventory_item_id IN NUMBER,
3624 p_lot_uniqueness IN NUMBER,
3625 p_auto_lot_number IN VARCHAR2,
3626 p_check_same_item IN VARCHAR2,
3627 x_is_unique OUT NOCOPY VARCHAR2
3628 )
3629 IS
3630 l_lot_number NUMBER := 0;
3631 l_lot_uniqueness NUMBER := p_lot_uniqueness;
3632 l_count NUMBER := 0;
3633 l_api_name CONSTANT VARCHAR2 ( 50 )
3634 := 'INV_LOT_API_PUB.validate_unique_lot';
3635
3636 CURSOR mln_cur_1
3637 IS
3638 SELECT lot_number
3639 FROM mtl_lot_numbers
3640 WHERE lot_number = p_auto_lot_number
3641 AND inventory_item_id = p_inventory_item_id;
3642
3643 CURSOR mtln_cur_1
3644 IS
3645 SELECT lot_number
3646 FROM mtl_transaction_lot_numbers
3647 WHERE lot_number = p_auto_lot_number
3648 AND inventory_item_id = p_inventory_item_id;
3649
3650 CURSOR mtlt_cur_1
3651 IS
3652 SELECT lot.lot_number
3653 FROM mtl_transaction_lots_temp lot,
3654 mtl_material_transactions_temp mmtt
3655 WHERE lot.transaction_temp_id = mmtt.transaction_temp_id
3656 AND lot.lot_number = p_auto_lot_number
3657 AND mmtt.inventory_item_id = p_inventory_item_id;
3658
3659 CURSOR mmtt_cur_1
3660 IS
3661 SELECT lot_number
3662 FROM mtl_material_transactions_temp lot
3663 WHERE lot_number = p_auto_lot_number
3664 AND inventory_item_id = p_inventory_item_id;
3665 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3666 BEGIN
3667 IF l_lot_uniqueness IS NULL
3668 THEN
3669 BEGIN
3670 SELECT lot_number_uniqueness
3671 INTO l_lot_uniqueness
3672 FROM mtl_parameters
3673 WHERE organization_id = p_org_id;
3674 EXCEPTION
3675 WHEN NO_DATA_FOUND
3676 THEN
3677 RAISE fnd_api.g_exc_error;
3678 END;
3679 END IF;
3680
3681 IF ( l_lot_uniqueness = 1 ) -- Item level control
3682 THEN
3683 IF ( validate_unique_lot (
3684 p_org_id,
3685 p_inventory_item_id,
3686 l_lot_uniqueness,
3687 p_auto_lot_number
3688 )
3689 )
3690 AND p_check_same_item = 'Y'
3691 THEN
3692 BEGIN
3693 x_is_unique := 'true';
3694
3695 FOR mln_rec IN mln_cur_1
3696 LOOP
3697 l_count := 1;
3698 EXIT;
3699 END LOOP;
3700
3701 IF ( l_count > 0 )
3702 THEN
3703 x_is_unique := 'false';
3704 ELSE
3705 l_count := 0;
3706 END IF;
3707
3708 FOR mtln_rec IN mtln_cur_1
3709 LOOP
3710 l_count := 1;
3711 EXIT;
3712 END LOOP;
3713
3714 IF ( l_count > 0 )
3715 THEN
3716 x_is_unique := 'false';
3717 ELSE
3718 l_count := 0;
3719 END IF;
3720
3721 FOR mtlt_rec IN mtlt_cur_1
3722 LOOP
3723 l_count := 1;
3724 EXIT;
3725 END LOOP;
3726
3727 IF ( l_count > 0 )
3728 THEN
3729 x_is_unique := 'false';
3730 ELSE
3731 l_count := 0;
3732 END IF;
3733
3734 FOR mtlt_rec IN mtlt_cur_1
3735 LOOP
3736 l_count := 1;
3737 EXIT;
3738 END LOOP;
3739
3740 IF ( l_count > 0 )
3741 THEN
3742 x_is_unique := 'false';
3743 END IF;
3744 END;
3745 ELSE
3746 x_is_unique := 'false';
3747 END IF;
3748 ELSE
3749 x_is_unique := 'true';
3750 END IF;
3751 EXCEPTION
3752 WHEN OTHERS
3753 THEN
3754 IF fnd_msg_pub.check_msg_level (
3755 fnd_msg_pub.g_msg_lvl_unexp_error
3756 )
3757 THEN
3758 fnd_msg_pub.add_exc_msg ( g_pkg_name, l_api_name );
3759 END IF;
3760
3761 x_is_unique := 'false';
3762 END validate_unique_lot;
3763
3764
3765 /***************************************************************************************
3766 Bug - 2181558
3767 Procedure to copy the WMS and Non WMS Lot Attributes from the Source Lot to this Lot
3768 ***************************************************************************************/
3769 PROCEDURE get_lot_att_from_source (
3770 x_return_status OUT NOCOPY VARCHAR2,
3771 x_count OUT NOCOPY NUMBER,
3772 x_source_wms_lot_att_tbl OUT NOCOPY inv_lot_sel_attr.lot_sel_attributes_tbl_type,
3773 x_source_non_wms_lot_att_rec OUT NOCOPY non_wms_lot_att_rec_type,
3774 p_from_organization_id IN NUMBER,
3775 p_inventory_item_id IN NUMBER,
3776 p_lot_number IN VARCHAR2,
3777 p_count IN NUMBER,
3778 p_source_wms_lot_att_tbl IN inv_lot_sel_attr.lot_sel_attributes_tbl_type
3779 )
3780 IS
3781 temp_tbl inv_lot_sel_attr.lot_sel_attributes_tbl_type;
3782 v_found BOOLEAN := FALSE;
3783 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3784 BEGIN
3785 IF (l_debug = 1) THEN
3786 print_debug ('Getting the WMS and NON WMS LOT Attributes From the Source LOT',4);
3787 END IF;
3788
3789 SELECT TO_CHAR ( vendor_id ),
3790 grade_code,
3791 fnd_date.date_to_canonical ( origination_date ),
3792 date_code,
3793 TO_CHAR ( status_id ),
3794 fnd_date.date_to_canonical ( change_date ),
3795 TO_NUMBER ( age ),
3796 fnd_date.date_to_canonical ( retest_date ),
3797 fnd_date.date_to_canonical ( maturity_date ),
3798 lot_attribute_category,
3799 TO_CHAR ( item_size ),
3800 color,
3801 TO_CHAR ( volume ),
3802 volume_uom,
3803 place_of_origin,
3804 fnd_date.date_to_canonical ( best_by_date ),
3805 TO_CHAR ( LENGTH ),
3806 length_uom,
3807 TO_CHAR ( recycled_content ),
3808 TO_CHAR ( thickness ),
3809 thickness_uom,
3810 TO_CHAR ( width ),
3811 width_uom,
3812 curl_wrinkle_fold,
3813 c_attribute1,
3814 c_attribute2,
3815 c_attribute3,
3816 c_attribute4,
3817 c_attribute5,
3818 c_attribute6,
3819 c_attribute7,
3820 c_attribute8,
3821 c_attribute9,
3822 c_attribute10,
3823 c_attribute11,
3824 c_attribute12,
3825 c_attribute13,
3826 c_attribute14,
3827 c_attribute15,
3828 c_attribute16,
3829 c_attribute17,
3830 c_attribute18,
3831 c_attribute19,
3832 c_attribute20,
3833 fnd_date.date_to_canonical ( d_attribute1 ),
3834 fnd_date.date_to_canonical ( d_attribute2 ),
3835 fnd_date.date_to_canonical ( d_attribute3 ),
3836 fnd_date.date_to_canonical ( d_attribute4 ),
3837 fnd_date.date_to_canonical ( d_attribute5 ),
3838 fnd_date.date_to_canonical ( d_attribute6 ),
3839 fnd_date.date_to_canonical ( d_attribute7 ),
3840 fnd_date.date_to_canonical ( d_attribute8 ),
3841 fnd_date.date_to_canonical ( d_attribute9 ),
3842 fnd_date.date_to_canonical ( d_attribute10 ),
3843 TO_CHAR ( n_attribute1 ),
3844 TO_CHAR ( n_attribute2 ),
3845 TO_CHAR ( n_attribute3 ),
3846 TO_CHAR ( n_attribute4 ),
3847 TO_CHAR ( n_attribute5 ),
3848 TO_CHAR ( n_attribute6 ),
3849 TO_CHAR ( n_attribute7 ),
3850 TO_CHAR ( n_attribute8 ),
3851 TO_CHAR ( n_attribute10 ),
3852 supplier_lot_number,
3853 TO_CHAR ( n_attribute9 ),
3854 territory_code,
3855 vendor_name,
3856 description,
3857 attribute_category,
3858 attribute1,
3859 attribute2,
3860 attribute3,
3861 attribute4,
3862 attribute5,
3863 attribute6,
3864 attribute7,
3865 attribute8,
3866 attribute9,
3867 attribute10,
3868 attribute11,
3869 attribute12,
3870 attribute13,
3871 attribute14,
3872 attribute15
3873 INTO temp_tbl ( 1 ).column_value,
3874 temp_tbl ( 2 ).column_value,
3875 temp_tbl ( 3 ).column_value,
3876 temp_tbl ( 4 ).column_value,
3877 temp_tbl ( 5 ).column_value,
3878 temp_tbl ( 6 ).column_value,
3879 temp_tbl ( 7 ).column_value,
3880 temp_tbl ( 8 ).column_value,
3881 temp_tbl ( 9 ).column_value,
3882 temp_tbl ( 10 ).column_value,
3883 temp_tbl ( 11 ).column_value,
3884 temp_tbl ( 12 ).column_value,
3885 temp_tbl ( 13 ).column_value,
3886 temp_tbl ( 14 ).column_value,
3887 temp_tbl ( 15 ).column_value,
3888 temp_tbl ( 16 ).column_value,
3889 temp_tbl ( 17 ).column_value,
3890 temp_tbl ( 18 ).column_value,
3891 temp_tbl ( 19 ).column_value,
3892 temp_tbl ( 20 ).column_value,
3893 temp_tbl ( 21 ).column_value,
3894 temp_tbl ( 22 ).column_value,
3895 temp_tbl ( 23 ).column_value,
3896 temp_tbl ( 24 ).column_value,
3897 temp_tbl ( 25 ).column_value,
3898 temp_tbl ( 26 ).column_value,
3899 temp_tbl ( 27 ).column_value,
3900 temp_tbl ( 28 ).column_value,
3901 temp_tbl ( 29 ).column_value,
3902 temp_tbl ( 30 ).column_value,
3903 temp_tbl ( 31 ).column_value,
3904 temp_tbl ( 32 ).column_value,
3905 temp_tbl ( 33 ).column_value,
3906 temp_tbl ( 34 ).column_value,
3907 temp_tbl ( 35 ).column_value,
3908 temp_tbl ( 36 ).column_value,
3909 temp_tbl ( 37 ).column_value,
3910 temp_tbl ( 38 ).column_value,
3911 temp_tbl ( 39 ).column_value,
3912 temp_tbl ( 40 ).column_value,
3913 temp_tbl ( 41 ).column_value,
3914 temp_tbl ( 42 ).column_value,
3915 temp_tbl ( 43 ).column_value,
3916 temp_tbl ( 44 ).column_value,
3917 temp_tbl ( 45 ).column_value,
3918 temp_tbl ( 46 ).column_value,
3919 temp_tbl ( 47 ).column_value,
3920 temp_tbl ( 48 ).column_value,
3921 temp_tbl ( 49 ).column_value,
3922 temp_tbl ( 50 ).column_value,
3923 temp_tbl ( 51 ).column_value,
3924 temp_tbl ( 52 ).column_value,
3925 temp_tbl ( 53 ).column_value,
3926 temp_tbl ( 54 ).column_value,
3927 temp_tbl ( 55 ).column_value,
3928 temp_tbl ( 56 ).column_value,
3929 temp_tbl ( 57 ).column_value,
3930 temp_tbl ( 58 ).column_value,
3931 temp_tbl ( 59 ).column_value,
3932 temp_tbl ( 60 ).column_value,
3933 temp_tbl ( 61 ).column_value,
3934 temp_tbl ( 62 ).column_value,
3935 temp_tbl ( 63 ).column_value,
3936 temp_tbl ( 64 ).column_value,
3937 temp_tbl ( 65 ).column_value,
3938 temp_tbl ( 66 ).column_value,
3939 temp_tbl ( 67 ).column_value,
3940 temp_tbl ( 68 ).column_value,
3941 x_source_non_wms_lot_att_rec.attribute_category,
3942 x_source_non_wms_lot_att_rec.attribute1,
3943 x_source_non_wms_lot_att_rec.attribute2,
3944 x_source_non_wms_lot_att_rec.attribute3,
3945 x_source_non_wms_lot_att_rec.attribute4,
3946 x_source_non_wms_lot_att_rec.attribute5,
3947 x_source_non_wms_lot_att_rec.attribute6,
3948 x_source_non_wms_lot_att_rec.attribute7,
3949 x_source_non_wms_lot_att_rec.attribute8,
3950 x_source_non_wms_lot_att_rec.attribute9,
3951 x_source_non_wms_lot_att_rec.attribute10,
3952 x_source_non_wms_lot_att_rec.attribute11,
3953 x_source_non_wms_lot_att_rec.attribute12,
3954 x_source_non_wms_lot_att_rec.attribute13,
3955 x_source_non_wms_lot_att_rec.attribute14,
3956 x_source_non_wms_lot_att_rec.attribute15
3957 FROM mtl_lot_numbers
3958 WHERE organization_id = p_from_organization_id
3959 AND inventory_item_id = p_inventory_item_id
3960 AND lot_number = p_lot_number;
3961
3962 x_count := p_count;
3963 x_source_wms_lot_att_tbl := p_source_wms_lot_att_tbl;
3964
3965 FOR x IN 1..68 LOOP
3966 v_found := FALSE;
3967 FOR y IN 1..p_count LOOP
3968 IF ( upper(temp_tbl(y).column_name) = upper(p_source_wms_lot_att_tbl(y).column_name)) THEN
3969 v_found := TRUE;
3970 END IF;
3971 END LOOP;
3972
3973 IF(v_found = FALSE) THEN
3974 IF temp_tbl(x).column_value IS NOT NULL THEN
3975 x_count := x_count + 1;
3976 x_source_wms_lot_att_tbl(x_count).column_name := g_lot_attributes_tbl(x).column_name;
3977 x_source_wms_lot_att_tbl(x_count).column_type := g_lot_attributes_tbl(x).column_type;
3978 x_source_wms_lot_att_tbl(x_count).column_value := temp_tbl(x).column_value;
3979 END IF;
3980 END IF;
3981 END LOOP;
3982 EXCEPTION
3983 WHEN no_data_found THEN
3984 IF (l_debug = 1) THEN
3985 print_debug('The selected lot_number, organization, item combination doesnt exist in MLN',4);
3986 END IF;
3987 x_count := p_count;
3988 x_source_wms_lot_att_tbl := p_source_wms_lot_att_tbl;
3989 WHEN OTHERS
3990 THEN
3991 x_return_status := fnd_api.g_ret_sts_unexp_error;
3992 IF (l_debug = 1) THEN
3993 print_debug ('Exitting populatelotattributes - other exception:' || TO_CHAR ( SYSDATE, 'YYYY-MM-DD HH:DD:SS' ),1);
3994 END IF;
3995 IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error) THEN
3996 fnd_msg_pub.add_exc_msg (g_pkg_name,'get_lot_att_from_source');
3997 END IF;
3998 END get_lot_att_from_source;
3999
4000
4001 -----------------------------------------------------------J Develop--------------------------------
4002
4003 PROCEDURE validate_lot_attr_info(
4004 x_return_status OUT NOCOPY VARCHAR2
4005 , x_msg_count OUT NOCOPY NUMBER
4006 , x_msg_data OUT NOCOPY VARCHAR2
4007 , p_wms_is_installed IN VARCHAR2
4008 , p_attribute_category IN VARCHAR2
4009 , p_lot_attribute_category IN VARCHAR2
4010 , p_inventory_item_id IN NUMBER
4011 , p_organization_id IN NUMBER
4012 , p_attributes_tbl IN inv_lot_api_pub.char_tbl
4013 , p_c_attributes_tbl IN inv_lot_api_pub.char_tbl
4014 , p_n_attributes_tbl IN inv_lot_api_pub.number_tbl
4015 , p_d_attributes_tbl IN inv_lot_api_pub.date_tbl
4016 , p_disable_flag IN NUMBER
4017 , p_grade_code IN VARCHAR2
4018 , p_origination_date IN DATE
4019 , p_date_code IN VARCHAR2
4020 , p_change_date IN DATE
4021 , p_age IN NUMBER
4022 , p_retest_date IN DATE
4023 , p_maturity_date IN DATE
4024 , p_item_size IN NUMBER
4025 , p_color IN VARCHAR2
4026 , p_volume IN NUMBER
4027 , p_volume_uom IN VARCHAR2
4028 , p_place_of_origin IN VARCHAR2
4029 , p_best_by_date IN DATE
4030 , p_length IN NUMBER
4031 , p_length_uom IN VARCHAR2
4032 , p_recycled_content IN NUMBER
4033 , p_thickness IN NUMBER
4034 , p_thickness_uom IN VARCHAR2
4035 , p_width IN NUMBER
4036 , p_width_uom IN VARCHAR2
4037 , p_territory_code IN VARCHAR2
4038 , p_supplier_lot_number IN VARCHAR2
4039 , p_vendor_name IN VARCHAR2
4040 ) IS
4041 TYPE seg_name IS TABLE OF VARCHAR2(1000)
4042 INDEX BY BINARY_INTEGER;
4043
4044 l_context VARCHAR2(1000);
4045 l_context_r fnd_dflex.context_r;
4046 l_contexts_dr fnd_dflex.contexts_dr;
4047 l_dflex_r fnd_dflex.dflex_r;
4048 l_segments_dr fnd_dflex.segments_dr;
4049 l_enabled_seg_name seg_name;
4050 l_wms_all_segs_tbl seg_name;
4051 l_nsegments BINARY_INTEGER;
4052 l_global_context BINARY_INTEGER;
4053 v_index NUMBER := 1;
4054 v_index1 NUMBER := 1;
4055 l_chk_flag NUMBER := 0;
4056 l_char_count NUMBER;
4057 l_num_count NUMBER;
4058 l_date_count NUMBER;
4059 l_wms_attr_chk NUMBER := 1;
4060 l_return_status VARCHAR2(1);
4061 l_msg_count NUMBER;
4062 l_msg_data VARCHAR2(1000);
4063 /*Return status definition
4064 G_RET_STS_SUCCESS CONSTANT VARCHAR2(1) :='S';
4065 G_RET_STS_ERROR CONSTANT VARCHAR2(1) :='E';
4066 G_RET_STS_UNEXP_ERROR CONSTANT VARCHAR2(1) :='U'; */
4067
4068
4069 /*Exception definitions
4070 G_EXC_ERROR EXCEPTION;
4071 G_EXC_UNEXPECTED_ERROR EXCEPTION;*/
4072
4073 /* Variables used for Validate_desccols procedure */
4074 error_segment VARCHAR2(30);
4075 errors_received EXCEPTION;
4076 error_msg VARCHAR2(5000);
4077 s NUMBER;
4078 e NUMBER;
4079 --g_debug NUMBER := 1 ;--NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'),0);
4080 l_null_char_val VARCHAR2(1000);
4081 l_null_num_val NUMBER;
4082 l_null_date_val DATE;
4083 l_global_nsegments NUMBER := 0;
4084 BEGIN
4085 x_return_status := g_ret_sts_success;
4086 SAVEPOINT get_lot_attr_information;
4087
4088 /* Populate the flex field record */
4089 --IF p_attribute_category IS NOT NULL THEN
4090 --AND p_attributes_tbl.COUNT > 0 THEN
4091 l_dflex_r.application_id := 401;
4092 l_dflex_r.flexfield_name := 'MTL_LOT_NUMBERS';
4093 /* Get all contexts */
4094 fnd_dflex.get_contexts(flexfield => l_dflex_r, contexts => l_contexts_dr);
4095
4096 IF g_debug = 1 THEN
4097 print_debug('Found contexts for the Flexfield MTL_LOT_NUMBERS', 9);
4098 END IF;
4099
4100 /* From the l_contexts_dr, get the position of the global context */
4101 l_global_context := l_contexts_dr.global_context;
4102
4103 IF g_debug = 1 THEN
4104 print_debug('Found the position of the global context ', 9);
4105 END IF;
4106
4107 /* Using the position get the segments in the global context which are enabled */
4108 l_context := l_contexts_dr.context_code(l_global_context);
4109
4110 /* Prepare the context_r type for getting the segments associated with the global context */
4111 l_context_r.flexfield := l_dflex_r;
4112 l_context_r.context_code := l_context;
4113 fnd_dflex.get_segments(CONTEXT => l_context_r, segments => l_segments_dr, enabled_only => TRUE);
4114
4115 IF g_debug = 1 THEN
4116 print_debug('After successfully getting all the enabled segmenst for the Global Context ', 9);
4117 END IF;
4118
4119 /* read through the segments */
4120 l_nsegments := l_segments_dr.nsegments;
4121 l_global_nsegments := l_segments_dr.nsegments;
4122 IF g_debug = 1 THEN
4123 print_debug('The number of enabled segments for the Global Context are ' || l_nsegments, 9);
4124 END IF;
4125
4126 FOR i IN 1 .. l_nsegments LOOP
4127 print_debug('v_index is ' || v_index, 9);
4128 print_debug('application_column_name is ' || l_segments_dr.application_column_name(i), 9);
4129
4130 l_enabled_seg_name(v_index) := l_segments_dr.application_column_name(i);
4131
4132 IF g_debug = 1 THEN
4133 print_debug('The segment is ' || l_segments_dr.segment_name(i), 9);
4134 END IF;
4135
4136 print_debug(p_attributes_tbl.count, 9);
4137
4138 IF l_segments_dr.is_required(i) THEN
4139 IF NOT p_attributes_tbl.EXISTS(SUBSTR(l_segments_dr.application_column_name(i)
4140 , INSTR(l_segments_dr.application_column_name(i), 'ATTRIBUTE') + 9)) THEN
4141 fnd_message.set_name('INV', 'INV_REQ_SEG_MISS');
4142 fnd_message.set_token('SEGMENT', l_segments_dr.segment_name(i));
4143 fnd_msg_pub.ADD;
4144
4145 IF g_debug = 1 THEN
4146 print_debug('Req segment is not populated', 9);
4147 END IF;
4148
4149 RAISE g_exc_error;
4150 END IF;
4151 ELSE
4152 IF g_debug = 1 THEN
4153 print_debug('This segment is not required', 9);
4154 END IF;
4155 END IF;
4156
4157 IF p_attributes_tbl.EXISTS(SUBSTR(l_segments_dr.application_column_name(i)
4158 , INSTR(l_segments_dr.application_column_name(i), 'ATTRIBUTE') + 9)) THEN
4159 fnd_flex_descval.set_column_value(
4160 l_segments_dr.application_column_name(i)
4161 , p_attributes_tbl(SUBSTR(l_segments_dr.application_column_name(i)
4162 , INSTR(l_segments_dr.application_column_name(i), 'ATTRIBUTE') + 9))
4163 );
4164 ELSE
4165 fnd_flex_descval.set_column_value(l_segments_dr.application_column_name(i), l_null_char_val);
4166 END IF;
4167
4168 --fnd_flex_descval.set_column_value(l_segments_dr.application_column_name(i),p_attributes_tbl(SUBSTR(l_segments_dr.application_column_name(i),INSTR(l_segments_dr.application_column_name(i),'ATTRIBUTE')+9)));
4169 v_index := v_index + 1;
4170 END LOOP;
4171
4172 IF l_enabled_seg_name.COUNT > 0 THEN
4173 FOR i IN l_enabled_seg_name.FIRST .. l_enabled_seg_name.LAST LOOP
4174 IF g_debug = 1 THEN
4175 print_debug('The enabled segment : ' || l_enabled_seg_name(i), 9);
4176 END IF;
4177 END LOOP;
4178 END IF;
4179
4180 /* Initialise the l_context_value to null */
4181 l_context := NULL;
4182 l_nsegments := 0;
4183
4184 /*Get the context for the item passed */
4185 IF p_attribute_category IS NOT NULL THEN
4186 l_context := p_attribute_category;
4187 /* Set flex context for validation of the value set */
4188 fnd_flex_descval.set_context_value(l_context);
4189
4190 IF g_debug = 1 THEN
4191 print_debug('The value of INV context is ' || l_context, 9);
4192 END IF;
4193
4194 /* Prepare the context_r type */
4195 l_context_r.flexfield := l_dflex_r;
4196 l_context_r.context_code := l_context;
4197 fnd_dflex.get_segments(CONTEXT => l_context_r, segments => l_segments_dr, enabled_only => TRUE);
4198 /* read through the segments */
4199 l_nsegments := l_segments_dr.nsegments;
4200 IF g_debug = 1 THEN
4201 print_debug('No of segments enabled for context ' || l_context || ' are ' || l_nsegments, 9);
4202 END IF;
4203
4204 print_Debug('v_index is ' || v_index, 9);
4205 FOR i IN 1 .. l_nsegments LOOP
4206 l_enabled_seg_name(v_index) := l_segments_dr.application_column_name(i);
4207
4208 print_debug('The segment is ' || l_segments_dr.segment_name(i), 9);
4209
4210 IF l_segments_dr.is_required(i) THEN
4211 IF NOT p_attributes_tbl.EXISTS(SUBSTR(l_segments_dr.application_column_name(i)
4212 , INSTR(l_segments_dr.application_column_name(i), 'ATTRIBUTE') + 9)) THEN
4213 fnd_message.set_name('INV', 'INV_REQ_SEG_MISS');
4214 fnd_message.set_token('SEGMENT', l_segments_dr.segment_name(i));
4215 fnd_msg_pub.ADD;
4216 RAISE g_exc_error;
4217
4218 IF g_debug = 1 THEN
4219 print_debug('Req segment is not populated', 9);
4220 END IF;
4221 END IF;
4222 END IF;
4223
4224 IF p_attributes_tbl.EXISTS(SUBSTR(l_segments_dr.application_column_name(i)
4225 , INSTR(l_segments_dr.application_column_name(i), 'ATTRIBUTE') + 9)) THEN
4226 fnd_flex_descval.set_column_value(
4227 l_segments_dr.application_column_name(i)
4228 , p_attributes_tbl(SUBSTR(l_segments_dr.application_column_name(i)
4229 , INSTR(l_segments_dr.application_column_name(i), 'ATTRIBUTE') + 9))
4230 );
4231 ELSE
4232 fnd_flex_descval.set_column_value(l_segments_dr.application_column_name(i), l_null_char_val);
4233 END IF;
4234
4235 v_index := v_index + 1;
4236 END LOOP;
4237
4238 --IF l_enabled_seg_name.count = P_ATTRIBUTES_TBL.count THEN
4239 /*v_index1 := p_attributes_tbl.FIRST;
4240
4241 print_debug('l_enabled_seg_name.count is ' || l_enabled_seg_name.COUNT, 9);
4242 WHILE v_index1 <= p_attributes_tbl.LAST LOOP
4243 IF g_debug = 1 THEN
4244 print_debug('The value of segment is ' || v_index1, 9);
4245 END IF;
4246
4247 FOR i IN 1 .. l_enabled_seg_name.COUNT LOOP
4248 IF l_enabled_seg_name(i) = 'ATTRIBUTE' || v_index1 THEN
4249 print_debug('The value of segmentS have matched '||l_enabled_seg_name(i), 9);
4250 l_chk_flag := 1;
4251 EXIT;
4252 END IF;
4253 END LOOP;
4254
4255 IF l_chk_flag = 0 AND p_attributes_tbl(v_index1) IS NOT NULL THEN
4256 fnd_message.set_name('INV', 'INV_WRONG_SEG_POPULATE');
4257 fnd_message.set_token('SEGMENT', 'ATTRIBUTE' || v_index1);
4258 fnd_message.set_token('CONTEXT', l_context);
4259 fnd_msg_pub.ADD;
4260 --dbms_output.put_line('Error out. Correct segmenst are not populated ');
4261 RAISE g_exc_error;
4262 END IF;
4263
4264 v_index1 := p_attributes_tbl.NEXT(v_index1);
4265 l_chk_flag := 0;
4266 END LOOP;*/
4267 END IF;
4268 /*Make a call to FND_FLEX_DESCVAL.validate_desccols */
4269 IF (l_global_nsegments > 0 AND p_attribute_Category IS NULL ) THEN
4270 l_context := l_contexts_dr.context_code(l_global_context);
4271 fnd_flex_descval.set_context_value(l_context);
4272 end if;
4273 IF( l_global_nsegments > 0 OR p_attribute_category IS NOT NULL ) then
4274 IF fnd_flex_descval.validate_desccols(appl_short_name => 'INV', desc_flex_name => 'MTL_LOT_NUMBERS', values_or_ids => 'I'
4275 , validation_date => SYSDATE) THEN
4276 IF g_debug = 1 THEN
4277 print_debug('Value set validation successful', 9);
4278 END IF;
4279 ELSE
4280 IF g_debug = 1 THEN
4281 error_segment := fnd_flex_descval.error_segment;
4282 print_debug('Value set validation failed for segment ' || error_segment, 9);
4283 RAISE errors_received;
4284 END IF;
4285 END IF;
4286 END IF; /*If P attribute category is not null */
4287 --END IF; /* p_attribute_category IS NOT NULL */
4288
4289 /*Check If WMS is installed */
4290 IF p_wms_is_installed = 'TRUE' THEN
4291 wms_lot_attr_validate(
4292 x_return_status => l_return_status
4293 , x_msg_count => l_msg_count
4294 , x_msg_data => l_msg_data
4295 , p_inventory_item_id => p_inventory_item_id
4296 , p_organization_id => p_organization_id
4297 , p_disable_flag => p_disable_flag
4298 , p_lot_attribute_category => p_lot_attribute_category
4299 , p_c_attributes_tbl => p_c_attributes_tbl
4300 , p_n_attributes_tbl => p_n_attributes_tbl
4301 , p_d_attributes_tbl => p_d_attributes_tbl
4302 , p_grade_code => p_grade_code
4303 , p_origination_date => p_origination_date
4304 , p_date_code => p_date_code
4305 , p_change_date => p_change_date
4306 , p_age => p_age
4307 , p_retest_date => p_retest_date
4308 , p_maturity_date => p_maturity_date
4309 , p_item_size => p_item_size
4310 , p_color => p_color
4311 , p_volume => p_volume
4312 , p_volume_uom => p_volume_uom
4313 , p_place_of_origin => p_place_of_origin
4314 , p_best_by_date => p_best_by_date
4315 , p_length => p_length
4316 , p_length_uom => p_length_uom
4317 , p_recycled_content => p_recycled_content
4318 , p_thickness => p_thickness
4319 , p_thickness_uom => p_thickness_uom
4320 , p_width => p_width
4321 , p_width_uom => p_width_uom
4322 , p_territory_code => p_territory_code
4323 , p_supplier_lot_number => p_supplier_lot_number
4324 , p_vendor_name => p_vendor_name
4325 );
4326
4327 IF l_return_status = g_ret_sts_error THEN
4328 IF g_debug = 1 THEN
4329 print_debug('Program WMS_LOT_ATTR_VALIDATE has failed with a user defined exception', 9);
4330 print_debug('l_msg_data is ' || l_msg_data, 9);
4331 END IF;
4332 RAISE g_exc_error;
4333 ELSIF l_return_status = g_ret_sts_unexp_error THEN
4334 IF g_debug = 1 THEN
4335 print_debug('Program WMS_LOT_ATTR_VALIDATE has failed with a Unexpected exception', 9);
4336 END IF;
4337 FND_MESSAGE.SET_NAME('INV','INV_PROGRAM_ERROR');
4338 FND_MESSAGE.SET_TOKEN('PROG_NAME','WMS_LOT_ATTR_VALIDATE');
4339 fnd_msg_pub.ADD;
4340 RAISE g_exc_unexpected_error;
4341 END IF;
4342 END IF; /* If wms_is installed */
4343 EXCEPTION
4344 WHEN errors_received THEN
4345 x_return_status := g_ret_sts_error;
4346 error_msg := fnd_flex_descval.error_message;
4347 s := 1;
4348 e := 200;
4349
4350 --print_debug('Here are the error messages: ',9);
4351 WHILE e < 5001
4352 AND SUBSTR(error_msg, s, e) IS NOT NULL LOOP
4353 fnd_message.set_name('INV', 'INV_FND_GENERIC_MSG');
4354 fnd_message.set_token('MSG', SUBSTR(error_msg, s, e));
4355 fnd_msg_pub.ADD;
4356 print_debug(SUBSTR(error_msg, s, e), 9);
4357 s := s + 200;
4358 e := e + 200;
4359 END LOOP;
4360
4361 ROLLBACK TO get_lot_attr_information;
4362 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
4363 WHEN g_exc_error THEN
4364 x_return_status := g_ret_sts_error;
4365 ROLLBACK TO get_lot_attr_information;
4366 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
4367 WHEN g_exc_unexpected_error THEN
4368 x_return_status := g_ret_sts_unexp_error;
4369 ROLLBACK TO get_lot_attr_information;
4370 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
4371 WHEN OTHERS THEN
4372 x_return_status := g_ret_sts_unexp_error;
4373 ROLLBACK TO get_lot_attr_information;
4374 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
4375 print_debug('Error ' || SQLERRM, 9);
4376 END validate_lot_attr_info;
4377
4378
4379 PROCEDURE validate_lot_attr_in_param(
4380 x_return_status OUT NOCOPY VARCHAR2
4381 , x_msg_count OUT NOCOPY NUMBER
4382 , x_msg_data OUT NOCOPY VARCHAR2
4383 , p_inventory_item_id IN NUMBER
4384 , p_organization_id IN NUMBER
4385 , p_lot_number IN VARCHAR2
4386 , p_attribute_category IN VARCHAR2
4387 , p_lot_attribute_category IN VARCHAR2
4388 , p_attributes_tbl IN inv_lot_api_pub.char_tbl
4389 , p_c_attributes_tbl IN inv_lot_api_pub.char_tbl
4390 , p_n_attributes_tbl IN inv_lot_api_pub.number_tbl
4391 , p_d_attributes_tbl IN inv_lot_api_pub.date_tbl
4392 , p_wms_is_installed IN VARCHAR2
4393 , p_source IN NUMBER
4394 , p_disable_flag IN NUMBER
4395 , p_grade_code IN VARCHAR2
4396 , p_origination_date IN DATE
4397 , p_date_code IN VARCHAR2
4398 , p_change_date IN DATE
4399 , p_age IN NUMBER
4400 , p_retest_date IN DATE
4401 , p_maturity_date IN DATE
4402 , p_item_size IN NUMBER
4403 , p_color IN VARCHAR2
4404 , p_volume IN NUMBER
4405 , p_volume_uom IN VARCHAR2
4406 , p_place_of_origin IN VARCHAR2
4407 , p_best_by_date IN DATE
4408 , p_length IN NUMBER
4409 , p_length_uom IN VARCHAR2
4410 , p_recycled_content IN NUMBER
4411 , p_thickness IN NUMBER
4412 , p_thickness_uom IN VARCHAR2
4413 , p_width IN NUMBER
4414 , p_width_uom IN VARCHAR2
4415 , p_territory_code IN VARCHAR2
4416 , p_supplier_lot_number IN VARCHAR2
4417 , p_vendor_name IN VARCHAR2
4418 ) IS
4419 /*Program variables declaration */
4420 l_lot_control_code mtl_system_items_b.lot_control_code%TYPE;
4421 l_chk_lot_uniqueness BOOLEAN;
4422 l_wms_installed VARCHAR2(5);
4423 l_lot_number_uniqueness NUMBER;
4424 l_return_status VARCHAR2(1);
4425 l_msg_count NUMBER;
4426 l_msg_data VARCHAR2(3000);
4427 l_status NUMBER;
4428 BEGIN
4429 x_return_status := g_ret_sts_success;
4430 SAVEPOINT val_lot_attr;
4431
4432 BEGIN
4433 SELECT lot_control_code
4434 INTO l_lot_control_code
4435 FROM mtl_system_items
4436 WHERE inventory_item_id = p_inventory_item_id
4437 AND organization_id = p_organization_id;
4438
4439 /* If not lot controlled , then error out */
4440 IF (l_lot_control_code = 1) THEN
4441 IF g_debug = 1 THEN
4442 print_debug('Item is not lot controlled ', 9);
4443 END IF;
4444
4445 fnd_message.set_name('INV', 'INV_NO_LOT_CONTROL');
4446 fnd_msg_pub.ADD;
4447 x_return_status := fnd_api.g_ret_sts_error;
4448 RAISE g_exc_error;
4449 END IF;
4450 EXCEPTION
4451 WHEN NO_DATA_FOUND THEN
4452 IF (g_debug = 1) THEN
4453 print_debug('Exception in LOT_CONTROL_CODE', 9);
4454 END IF;
4455
4456 fnd_message.set_name('INV', 'INV_INVALID_ITEM');
4457 fnd_msg_pub.ADD;
4458 RAISE g_exc_error;
4459 END;
4460
4461 IF g_debug = 1 THEN
4462 print_debug('Item is lot controlled ', 9);
4463 END IF;
4464
4465 /* Get the Lot number uniqueness from mtl_parameters for the passed org_id
4466 oNE MESSAGE TO BE ADDED
4467 */
4468 BEGIN
4469 SELECT lot_number_uniqueness
4470 INTO l_lot_number_uniqueness
4471 FROM mtl_parameters
4472 WHERE organization_id = p_organization_id;
4473 EXCEPTION
4474 WHEN NO_DATA_FOUND THEN
4475 IF (g_debug = 1) THEN
4476 print_debug('Lot Number Uniqueness is not defined ', 9);
4477 END IF;
4478
4479 fnd_message.set_name('INV', 'INV_NO_UNIQUENESS_DEFN');
4480 /* Lot Number Uniqueness is not defined*/
4481 fnd_msg_pub.ADD;
4482 RAISE NO_DATA_FOUND;
4483 END;
4484
4485 /* Call the function to check the Lot Uniqueness */
4486 l_chk_lot_uniqueness :=
4487 inv_lot_api_pub.validate_unique_lot(
4488 p_org_id => p_organization_id
4489 , p_inventory_item_id => p_inventory_item_id
4490 , p_lot_uniqueness => l_lot_number_uniqueness
4491 , p_auto_lot_number => p_lot_number
4492 );
4493
4494 IF NOT l_chk_lot_uniqueness THEN
4495 fnd_message.set_name('INV', 'INV_LOT_UNIQUENESS');
4496 fnd_msg_pub.ADD;
4497
4498 IF g_debug = 1 THEN
4499 print_debug('Lot Number Uniqueness check failed ', 9);
4500 END IF;
4501
4502 RAISE g_exc_error;
4503 END IF;
4504
4505 IF g_debug = 1 THEN
4506 print_debug('Lot Number Uniqueness check passed successfully ', 9);
4507 END IF;
4508
4509 l_wms_installed := p_wms_is_installed;
4510
4511 /*If WMS is installed then accept both the inventory attributes and
4512 WMS attributes. If WMS is not installed then accept only Inventory
4513 attributes
4514 */
4515 --IF l_wms_installed = 'TRUE' THEN
4516 IF g_debug = 1 THEN
4517 print_debug('WMS installed is ' || l_wms_installed, 9);
4518 print_debug('p_attributes_tbl.count = ' || p_attributes_tbl.count, 9);
4519 END IF;
4520
4521 /* Check if the Attribute_Category has been populated */
4522
4523 /*IF p_attribute_category IS NULL THEN
4524 for i in 1..p_attributes_tbl.count LOOP
4525 if p_attributes_tbl(i) IS NOT NULL THEN
4526 fnd_message.set_name('INV', 'INV_NO_ATTRIBUTE_CATEGORY');
4527 fnd_msg_pub.ADD;
4528
4529 IF g_debug = 1 THEN
4530 print_debug('Attribute Category value is null', 9);
4531 END IF;
4532
4533 RAISE g_exc_error;
4534 end if;
4535 end loop;
4536 END IF;*/
4537
4538 /* Find out if the Inventory attributes are populated*/
4539 IF p_attributes_tbl.COUNT > 0 THEN
4540 IF g_debug = 1 THEN
4541 print_debug('The Inventory attributes are populated ', 9);
4542 END IF;
4543 END IF;
4544
4545 IF p_source NOT IN(osfm_form_no_validate) THEN
4546 validate_lot_attr_info(
4547 x_return_status => l_return_status
4548 , x_msg_count => l_msg_count
4549 , x_msg_data => l_msg_data
4550 , p_wms_is_installed => l_wms_installed
4551 , p_attribute_category => p_attribute_category
4552 , p_lot_attribute_category => p_lot_attribute_category
4553 , p_inventory_item_id => p_inventory_item_id
4554 , p_organization_id => p_organization_id
4555 , p_attributes_tbl => p_attributes_tbl
4556 , p_c_attributes_tbl => p_c_attributes_tbl
4557 , p_n_attributes_tbl => p_n_attributes_tbl
4558 , p_d_attributes_tbl => p_d_attributes_tbl
4559 , p_disable_flag => p_disable_flag
4560 , p_grade_code => p_grade_code
4561 , p_origination_date => p_origination_date
4562 , p_date_code => p_date_code
4563 , p_change_date => p_change_date
4564 , p_age => p_age
4565 , p_retest_date => p_retest_date
4566 , p_maturity_date => p_maturity_date
4567 , p_item_size => p_item_size
4568 , p_color => p_color
4569 , p_volume => p_volume
4570 , p_volume_uom => p_volume_uom
4571 , p_place_of_origin => p_place_of_origin
4572 , p_best_by_date => p_best_by_date
4573 , p_length => p_length
4574 , p_length_uom => p_length_uom
4575 , p_recycled_content => p_recycled_content
4576 , p_thickness => p_thickness
4577 , p_thickness_uom => p_thickness_uom
4578 , p_width => p_width
4579 , p_width_uom => p_width_uom
4580 , p_territory_code => p_territory_code
4581 , p_supplier_lot_number => p_supplier_lot_number
4582 , p_vendor_name => p_vendor_name
4583 );
4584
4585 IF l_return_status = g_ret_sts_error THEN
4586 IF g_debug = 1 THEN
4587 print_debug('Program get_lot_attr_info has failed with a user defined exception', 9);
4588 END IF;
4589 RAISE g_exc_error;
4590 ELSIF l_return_status = g_ret_sts_unexp_error THEN
4591 IF g_debug = 1 THEN
4592 print_debug('Program get_lot_attr_info has failed with a Unexpected exception', 9);
4593 END IF;
4594 FND_MESSAGE.SET_NAME('INV','INV_PROGRAM_ERROR');
4595 FND_MESSAGE.SET_TOKEN('PROG_NAME','get_lot_attr_info');
4596 fnd_msg_pub.ADD;
4597 RAISE g_exc_unexpected_error;
4598 END IF;
4599 END IF;
4600 EXCEPTION
4601 WHEN NO_DATA_FOUND THEN
4602 x_return_status := g_ret_sts_error;
4603 ROLLBACK TO val_lot_attr;
4604 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
4605 print_debug('In No data found -val_lot_attr ' || SQLERRM, 9);
4606 WHEN g_exc_error THEN
4607 x_return_status := g_ret_sts_error;
4608 ROLLBACK TO val_lot_attr;
4609 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
4610 print_debug('In g_exc_error -val_lot_attr' || SQLERRM, 9);
4611 WHEN g_exc_unexpected_error THEN
4612 x_return_status := g_ret_sts_unexp_error;
4613 ROLLBACK TO val_lot_attr;
4614 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
4615 print_debug('In g_exc_unexpected_error val_lot_attr' || SQLERRM, 9);
4616 WHEN OTHERS THEN
4617 x_return_status := g_ret_sts_unexp_error;
4618 ROLLBACK TO val_lot_attr;
4619 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
4620 print_debug('In others val_lot_attr' || SQLERRM, 9);
4621 END validate_lot_attr_in_param;
4622
4623 -- nsinghi 5209065 START. Created new overloaded procedure.
4624 PROCEDURE update_inv_lot(
4625 x_return_status OUT NOCOPY VARCHAR2
4626 , x_msg_count OUT NOCOPY NUMBER
4627 , x_msg_data OUT NOCOPY VARCHAR2
4628 , x_lot_rec OUT NOCOPY MTL_LOT_NUMBERS%ROWTYPE
4629 , p_lot_rec IN MTL_LOT_NUMBERS%ROWTYPE
4630 , p_source IN NUMBER
4631 , p_api_version IN NUMBER
4632 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
4633 , p_commit IN VARCHAR2 := fnd_api.g_false
4634 )
4635 IS
4636 CURSOR inv_attributes_cur IS
4637 SELECT attribute1
4638 , attribute2
4639 , attribute3
4640 , attribute4
4641 , attribute5
4642 , attribute6
4643 , attribute7
4644 , attribute8
4645 , attribute9
4646 , attribute10
4647 , attribute11
4648 , attribute12
4649 , attribute13
4650 , attribute14
4651 , attribute15
4652 FROM mtl_lot_numbers
4653 WHERE inventory_item_id = p_lot_rec.inventory_item_id
4654 AND organization_id = p_lot_rec.organization_id
4655 AND lot_number = p_lot_rec.lot_number;
4656
4657 CURSOR c_attributes_cur IS
4658 SELECT c_attribute1
4659 , c_attribute2
4660 , c_attribute3
4661 , c_attribute4
4662 , c_attribute5
4663 , c_attribute6
4664 , c_attribute7
4665 , c_attribute8
4666 , c_attribute9
4667 , c_attribute10
4668 , c_attribute11
4669 , c_attribute12
4670 , c_attribute13
4671 , c_attribute14
4672 , c_attribute15
4673 , c_attribute16
4674 , c_attribute17
4675 , c_attribute18
4676 , c_attribute19
4677 , c_attribute20
4678 FROM mtl_lot_numbers
4679 WHERE inventory_item_id = p_lot_rec.inventory_item_id
4680 AND organization_id = p_lot_rec.organization_id
4681 AND lot_number = p_lot_rec.lot_number;
4682
4683 CURSOR n_attributes_cur IS
4684 SELECT n_attribute1
4685 , n_attribute2
4686 , n_attribute3
4687 , n_attribute4
4688 , n_attribute5
4689 , n_attribute6
4690 , n_attribute7
4691 , n_attribute8
4692 , n_attribute9
4693 , n_attribute10
4694 FROM mtl_lot_numbers
4695 WHERE inventory_item_id = p_lot_rec.inventory_item_id
4696 AND organization_id = p_lot_rec.organization_id
4697 AND lot_number = p_lot_rec.lot_number;
4698
4699 CURSOR d_attributes_cur IS
4700 SELECT d_attribute1
4701 , d_attribute2
4702 , d_attribute3
4703 , d_attribute4
4704 , d_attribute5
4705 , d_attribute6
4706 , d_attribute7
4707 , d_attribute8
4708 , d_attribute9
4709 , d_attribute10
4710 FROM mtl_lot_numbers
4711 WHERE inventory_item_id = p_lot_rec.inventory_item_id
4712 AND organization_id = p_lot_rec.organization_id
4713 AND lot_number = p_lot_rec.lot_number;
4714
4715 CURSOR attr_category_cur IS
4716 SELECT attribute_category
4717 , lot_attribute_category
4718 FROM mtl_lot_numbers
4719 WHERE inventory_item_id = p_lot_rec.inventory_item_id
4720 AND organization_id = p_lot_rec.organization_id
4721 AND lot_number = p_lot_rec.lot_number;
4722
4723 CURSOR wms_named_attr IS
4724 SELECT grade_code
4725 , DISABLE_FLAG
4726 , origination_date
4727 , date_code
4728 , change_date
4729 , age
4730 , retest_date
4731 , maturity_date
4732 , item_size
4733 , color
4734 , volume
4735 , volume_uom
4736 , place_of_origin
4737 , best_by_date
4738 , length
4739 , length_uom
4740 , recycled_content
4741 , thickness
4742 , thickness_uom
4743 , width
4744 , width_uom
4745 , territory_code
4746 , supplier_lot_number
4747 , VENDOR_NAME
4748 FROM MTL_LOT_NUMBERS
4749 WHERE inventory_item_id = p_lot_rec.inventory_item_id
4750 AND organization_id = p_lot_rec.organization_id
4751 AND lot_number = p_lot_rec.lot_number;
4752
4753 l_wms_named_attributes INV_LOT_API_PUB.wms_named_attributes;
4754 l_wms_named_attr wms_named_attr%ROWTYPE;
4755 l_attr_category_cur attr_category_cur%ROWTYPE;
4756 l_c_attributes_cur c_attributes_cur%ROWTYPE;
4757 l_n_attributes_cur n_attributes_cur%ROWTYPE;
4758 l_d_attributes_cur d_attributes_cur%ROWTYPE;
4759 l_inv_attributes_cur inv_attributes_cur%ROWTYPE;
4760 l_inv_attributes_tbl inv_lot_api_pub.char_tbl;
4761 l_c_attributes_tbl inv_lot_api_pub.char_tbl;
4762 l_n_attributes_tbl inv_lot_api_pub.number_tbl;
4763 l_d_attributes_tbl inv_lot_api_pub.date_tbl;
4764 /* Index variables for looping through the input tables*/
4765 l_attr_index NUMBER;
4766 l_c_attr_index NUMBER;
4767 l_n_attr_index NUMBER;
4768 l_d_attr_index NUMBER;
4769 l_return_status VARCHAR2(1);
4770 l_msg_data VARCHAR2(2000);
4771 l_msg_count NUMBER;
4772 l_wms_installed VARCHAR2(5);
4773 l_chk NUMBER;
4774 l_context VARCHAR2(1000);
4775 l_global_context BINARY_INTEGER;
4776 l_context_r fnd_dflex.context_r;
4777 l_contexts_dr fnd_dflex.contexts_dr;
4778 l_dflex_r fnd_dflex.dflex_r;
4779 l_segments_dr fnd_dflex.segments_dr;
4780 inv_global_index NUMBER;
4781 inv_context_index NUMBER;
4782 wms_global_index NUMBER;
4783 wms_context_index NUMBER;
4784 l_res_inv_attributes_tbl inv_lot_api_pub.char_tbl;
4785 l_res_c_attributes_tbl inv_lot_api_pub.char_tbl;
4786 l_res_n_attributes_tbl inv_lot_api_pub.number_tbl;
4787 l_res_d_attributes_tbl inv_lot_api_pub.date_tbl;
4788 /* Shelf life code constants */
4789 no_shelf_life_control CONSTANT NUMBER := 1;
4790 item_shelf_life_days CONSTANT NUMBER := 2;
4791 user_defined_exp_date CONSTANT NUMBER := 4;
4792 l_shelf_life_days mtl_system_items.shelf_life_days%TYPE;
4793 l_shelf_life_code mtl_system_items.shelf_life_code%TYPE;
4794 l_expiration_date mtl_lot_numbers.expiration_date%TYPE;
4795 l_global_nsegments NUMBER := 0;
4796 l_lot_grade VARCHAR2(150); /*bug 13780398 Bug 13987577 changed the data type to incoporate more than 2 bytes*/
4797 l_grade_enabled VARCHAR2(1); --bug 13780398
4798
4799 BEGIN
4800 x_return_status := g_ret_sts_success;
4801 SAVEPOINT upd_lot_attr;
4802
4803 IF g_debug = 1 THEN
4804 print_debug(p_err_msg => 'Update Lot Attr: The value of the input parametsrs are :', p_level => 9);
4805 print_debug(p_err_msg => 'Update Lot Attr: The value of the INVENTORY_ITEM_ID : ' || p_lot_rec.inventory_item_id, p_level => 9);
4806 print_debug(p_err_msg => 'Update Lot Attr: The value of ORGANIZATION_ID :' || p_lot_rec.organization_id, p_level => 9);
4807 print_debug(p_err_msg => 'Update Lot Attr: The value of LOT_NUMBER :' || p_lot_rec.lot_number, p_level => 9);
4808 print_debug(p_err_msg => 'Update Lot Attr: The value of PARENT LOT_NUMBER :' || p_lot_rec.parent_lot_number, p_level => 9);
4809
4810 print_debug(p_err_msg => 'Update Lot Attr: The value of the EXPIRATION_DATE :' || p_lot_rec.expiration_date, p_level => 9);
4811 print_debug(p_err_msg => 'Update Lot Attr: The value of the DISABLE_FLAG :' || p_lot_rec.disable_flag, p_level => 9);
4812 print_debug(p_err_msg => 'Update Lot Attr: The value of the ATTRIBUTE_CATEGORY :' || p_lot_rec.attribute_category, p_level => 9);
4813 print_debug(p_err_msg => 'Update Lot Attr: The value of the LOT_ATTRIBUTE_CATEGORY :' || p_lot_rec.lot_attribute_category, p_level => 9);
4814 print_debug(p_err_msg => 'Update Lot Attr: The value of the GRADE_CODE :' || p_lot_rec.grade_code, p_level => 9);
4815 print_debug(p_err_msg => 'Update Lot Attr: The value of the ORIGINATION_DATE :' || p_lot_rec.origination_date, p_level => 9);
4816 print_debug(p_err_msg => 'Update Lot Attr: The value of the DATE_CODE :' || p_lot_rec.date_code, p_level => 9);
4817 print_debug(p_err_msg => 'Update Lot Attr: The value of the STATUS_ID :' || p_lot_rec.status_id, p_level => 9);
4818 print_debug(p_err_msg => 'Update Lot Attr: The value of the CHANGE_DATE :' || p_lot_rec.change_date, p_level => 9);
4819 print_debug(p_err_msg => 'Update Lot Attr: The value of the AGE :' || p_lot_rec.age, p_level => 9);
4820 print_debug(p_err_msg => 'Update Lot Attr: The value of the RETEST_DATE :' || p_lot_rec.retest_date, p_level => 9);
4821 print_debug(p_err_msg => 'Update Lot Attr: The value of the MATURITY_DATE :' || p_lot_rec.maturity_date, p_level => 9);
4822 print_debug(p_err_msg => 'Update Lot Attr: The value of the ITEM_SIZE :' || p_lot_rec.item_size, p_level => 9);
4823 print_debug(p_err_msg => 'Update Lot Attr: The value of COLOR :' || p_lot_rec.color, p_level => 9);
4824 print_debug(p_err_msg => 'Update Lot Attr: The value of VOLUME :' || p_lot_rec.volume, p_level => 9);
4825 print_debug(p_err_msg => 'Update Lot Attr: The value of VOLUME_UOM :' || p_lot_rec.volume_uom, p_level => 9);
4826 print_debug(p_err_msg => 'Update Lot Attr: The value of PLACE_OF_ORIGIN :' || p_lot_rec.place_of_origin, p_level => 9);
4827 print_debug(p_err_msg => 'Update Lot Attr: The value of BEST_BY_DATE :' || p_lot_rec.best_by_date, p_level => 9);
4828 print_debug(p_err_msg => 'Update Lot Attr: The value of LENGTH :' || p_lot_rec.length, p_level => 9);
4829 print_debug(p_err_msg => 'Update Lot Attr: The value of LENGTH_UOM:' || p_lot_rec.length_uom, p_level => 9);
4830 print_debug(p_err_msg => 'Update Lot Attr: The value of RECYCLED_CONTENT :' || p_lot_rec.recycled_content, p_level => 9);
4831 print_debug(p_err_msg => 'Update Lot Attr: The value of THICKNESS :' || p_lot_rec.thickness, p_level => 9);
4832 print_debug(p_err_msg => 'Update Lot Attr: The value of THICKNESS_UOM :' || p_lot_rec.thickness_uom, p_level => 9);
4833 print_debug(p_err_msg => 'Update Lot Attr: The value of WIDTH :' || p_lot_rec.width, p_level => 9);
4834 print_debug(p_err_msg => 'Update Lot Attr: The value of WIDTH_UOM :' || p_lot_rec.width_uom, p_level => 9);
4835 print_debug(p_err_msg => 'Update Lot Attr: The value of Territory Code :' || p_lot_rec.territory_code, p_level => 9);
4836 print_debug(p_err_msg => 'Update Lot Attr: The value of VENDOR_NAME :' || p_lot_rec.vendor_name, p_level => 9);
4837 print_debug(p_err_msg => 'Update Lot Attr: The value of SUPPLIER_LOT_NUMBER :' || p_lot_rec.supplier_lot_number, p_level => 9);
4838 print_debug(p_err_msg => 'Update Lot Attr: The value of SUPPLIER_LOT_NUMBER :' || p_lot_rec.supplier_lot_number, p_level => 9);
4839 print_debug(p_err_msg => 'Update Lot Attr: The value of P_SOURCE :' || p_source, p_level => 9);
4840 END IF;
4841
4842 /* Check if this combination is valid */
4843 BEGIN
4844 SELECT 1
4845 INTO l_chk
4846 FROM mtl_lot_numbers
4847 WHERE inventory_item_id = p_lot_rec.inventory_item_id
4848 AND organization_id = p_lot_rec.organization_id
4849 AND lot_number = p_lot_rec.lot_number;
4850 EXCEPTION
4851 WHEN NO_DATA_FOUND THEN
4852 IF g_debug = 1 THEN
4853 print_debug('Upd Lot Attr : Conmbination of Lot number,Item and Org does not exists', 9);
4854 END IF;
4855
4856 fnd_message.set_name('INV', 'INV_LOT_NOT_EXISTS');
4857 fnd_msg_pub.add;
4858 --fnd_message.set_token('LOT',p_lot_rec.lot_number);
4859 RAISE g_exc_error;
4860 END;
4861
4862 BEGIN
4863 SELECT shelf_life_days
4864 , shelf_life_code
4865 INTO l_shelf_life_days
4866 , l_shelf_life_code
4867 FROM mtl_system_items
4868 WHERE inventory_item_id = p_lot_rec.inventory_item_id
4869 AND organization_id = p_lot_rec.organization_id;
4870 EXCEPTION
4871 WHEN NO_DATA_FOUND THEN
4872 NULL;
4873 END;
4874
4875 /*Start of changes for bug 4888300 */
4876 IF ( l_shelf_life_code IN (item_shelf_life_days ,user_defined_exp_date)
4877 AND p_lot_rec.expiration_date IS NOT NULL ) THEN
4878 IF g_debug = 1 THEN
4879 print_debug('Shelf_life code is of type USER_DEFINED_EXP_DATE OR ITEM_SHELF_LIFE_DAYS', 9);
4880 END IF;
4881
4882 IF p_lot_rec.expiration_date <> g_miss_date THEN
4883 l_expiration_date := p_lot_rec.expiration_date;
4884 ELSE
4885 l_expiration_date := NULL;
4886 END IF;
4887 /*End of changes for bug 4888300 */
4888
4889 ELSE
4890 l_expiration_date := NULL; --4888300
4891 IF g_debug = 1 THEN
4892 print_debug('Shelf_life code is of type NO_SHELF_LIFE_CONTROL', 9);
4893 END IF;
4894 END IF;
4895
4896 --END IF; /* IF NOT in (OSFM_FORM.OSFM_OPEN_INTERFACE)*/ --4888300
4897
4898 OPEN attr_category_cur;
4899 FETCH attr_category_cur INTO l_attr_category_cur;
4900 CLOSE attr_category_cur;
4901
4902 IF g_debug = 1 THEN
4903 print_debug('Upd Lot Attr: After gteting the attribte category', 9);
4904 END IF;
4905
4906 OPEN inv_attributes_cur;
4907 FETCH inv_attributes_cur INTO l_inv_attributes_cur;
4908 CLOSE inv_attributes_cur;
4909 l_inv_attributes_tbl(1) := l_inv_attributes_cur.attribute1;
4910 l_inv_attributes_tbl(2) := l_inv_attributes_cur.attribute2;
4911 l_inv_attributes_tbl(3) := l_inv_attributes_cur.attribute3;
4912 l_inv_attributes_tbl(4) := l_inv_attributes_cur.attribute4;
4913 l_inv_attributes_tbl(5) := l_inv_attributes_cur.attribute5;
4914 l_inv_attributes_tbl(6) := l_inv_attributes_cur.attribute6;
4915 l_inv_attributes_tbl(7) := l_inv_attributes_cur.attribute7;
4916 l_inv_attributes_tbl(8) := l_inv_attributes_cur.attribute8;
4917 l_inv_attributes_tbl(9) := l_inv_attributes_cur.attribute9;
4918 l_inv_attributes_tbl(10) := l_inv_attributes_cur.attribute10;
4919 l_inv_attributes_tbl(11) := l_inv_attributes_cur.attribute11;
4920 l_inv_attributes_tbl(12) := l_inv_attributes_cur.attribute12;
4921 l_inv_attributes_tbl(13) := l_inv_attributes_cur.attribute13;
4922 l_inv_attributes_tbl(14) := l_inv_attributes_cur.attribute14;
4923 l_inv_attributes_tbl(15) := l_inv_attributes_cur.attribute15;
4924
4925 /* **************************New additions ************************************ */
4926 /*Get the Contexts for the flex definition and check if any of the columns are required.
4927 If it is required, populate the value in a new table l_res_inv_attributes_tbl with
4928 the l_inv_attributes_tbl. This is done INV attributes and wms attributes
4929 Following will be pseudo code
4930 1. Get the Global context from INV attributes
4931 2. Check if any of the segment is required(mandatory)
4932 3. If required populate the value in l_res_inv_attributes_tbl
4933 which is obtained from l_inv_attributes_tbl table
4934 4. Set the context to INV context and fetch the segments for this context
4935 5. Loop through the segments and find out if any of the segments are
4936 required (mandatory)
4937 6. If so populate the value at the corresponding index with the value obtained
4938 from l_inv_attributes_tbl table
4939 7. Now at this point of time we have l_res_inv_attributes_tbl has only those
4940 segments whose value are required(mandatory)
4941 8. Loop through the input table p_attributes_tbl and populate the
4942 corresponding values in the l_res_inv_attributes_tbl
4943 9. Set the flex field defn to Lot Attributes
4944 10. Get the global context for WMS attributes
4945 11. check if the applicaton column name is C_attribute,D_attribute or N_Attribute
4946 12. Check if the corresponding column is required or not. If req, populate the new
4947 table l_res_c_attributes_tbl, or l_res_d_attributes_tbl or l_res_n_attributes_tbl
4948 13. Set the context to Lot Attribute Category
4949 14. Fetch all the segments for the context
4950 15. Check if the corresponding column is required or not. If req, populate the new
4951 table l_res_c_attributes_tbl, or l_res_d_attributes_tbl or l_res_n_attributes_tbl
4952 16. Loop through the input tables p_c_attributes,p_d_attributes and p_n_attributes
4953 and populate the corresponding value in l_res_c_attributes_tbl,
4954 l_res_d_attributes_tbl,l_res_n_attributes_tbl
4955 */
4956 IF p_source NOT IN(osfm_form_no_validate) THEN
4957 IF g_debug = 1 THEN
4958 print_debug(p_err_msg => 'Source is Not From OSFM_FORM So validating the Inventory Attributes ..... ' , p_level => 9);
4959 END IF;
4960 --IF l_attr_category_cur.attribute_category IS NOT NULL THEN
4961 -- AND p_attributes_tbl.COUNT > 0 THEN
4962 /* Populate the flex field record */
4963 l_dflex_r.application_id := 401;
4964 l_dflex_r.flexfield_name := 'MTL_LOT_NUMBERS';
4965 /* Get all contexts */
4966 fnd_dflex.get_contexts(flexfield => l_dflex_r, contexts => l_contexts_dr);
4967 /* From the l_contexts_dr, get the position of the global context */
4968 l_global_context := l_contexts_dr.global_context;
4969 l_context := l_contexts_dr.context_code(l_global_context);
4970 /* Prepare the context_r type for getting the segments associated with the global context */
4971 l_context_r.flexfield := l_dflex_r;
4972 l_context_r.context_code := l_context;
4973 /*Get the segments for the context */
4974 fnd_dflex.get_segments(CONTEXT => l_context_r, segments => l_segments_dr, enabled_only => TRUE);
4975
4976 /*Loop through the Segments table to see if any segments are required */
4977 --inv_global_index :=l_segments_dr.first;
4978 l_global_nsegments := l_segments_dr.nsegments;
4979
4980 FOR inv_global_index IN 1 .. l_segments_dr.nsegments LOOP
4981 IF l_segments_dr.is_required(inv_global_index) THEN
4982 l_res_inv_attributes_tbl(
4983 SUBSTR(
4984 l_segments_dr.application_column_name(inv_global_index)
4985 , INSTR(l_segments_dr.application_column_name(inv_global_index), 'ATTRIBUTE') + 9
4986 )
4987 ) :=
4988 l_inv_attributes_tbl(
4989 SUBSTR(
4990 l_segments_dr.application_column_name(inv_global_index)
4991 , INSTR(l_segments_dr.application_column_name(inv_global_index), 'ATTRIBUTE') + 9
4992 )
4993 );
4994 END IF;
4995 --inv_global_index :=l_segments_dr.next(inv_global_index);
4996 END LOOP;
4997 IF g_debug = 1 THEN
4998 print_debug(p_err_msg => 'Successfully validated INV global segments ..... ' , p_level => 9);
4999 END IF;
5000
5001
5002 /* Prepare the context_r type for getting the segments associated with the
5003 attribute_category */
5004 if( nvl(p_lot_rec.attribute_category, l_attr_category_cur.attribute_Category) IS NOT NULL ) THEN
5005
5006 l_context_r.flexfield := l_dflex_r;
5007 l_context_r.context_code := nvl(p_lot_rec.attribute_category, l_attr_category_cur.attribute_category);
5008 /*Get the segments for the context */
5009 fnd_dflex.get_segments(CONTEXT => l_context_r, segments => l_segments_dr, enabled_only => TRUE);
5010 /*Loop through the Segments table to see if any segments are required */
5011 inv_context_index := NULL;
5012
5013 --inv_context_index :=l_segments_dr.first;
5014 FOR inv_context_index IN 1 .. l_segments_dr.nsegments LOOP
5015 IF l_segments_dr.is_required(inv_context_index) THEN
5016 l_res_inv_attributes_tbl(
5017 SUBSTR(
5018 l_segments_dr.application_column_name(inv_context_index)
5019 , INSTR(l_segments_dr.application_column_name(inv_context_index), 'ATTRIBUTE') + 9
5020 )
5021 ) :=
5022 l_inv_attributes_tbl(
5023 SUBSTR(
5024 l_segments_dr.application_column_name(inv_context_index)
5025 , INSTR(l_segments_dr.application_column_name(inv_context_index), 'ATTRIBUTE') + 9
5026 )
5027 );
5028 END IF;
5029 END LOOP;
5030 IF g_debug = 1 THEN
5031 print_debug(p_err_msg => 'Successfully validated INV input Context segments ..... ' , p_level => 9);
5032 END IF;
5033 END IF; /*IF l_attr_category_cur.attribute_category IS NOT NULL */
5034
5035 END IF; /*P_SOURCE NOT IN (OSFM_FORM)*/
5036
5037 IF (p_lot_rec.attribute1 = g_miss_char) THEN
5038 l_res_inv_attributes_tbl(1) := NULL;
5039 l_inv_attributes_tbl(1) := g_miss_char;
5040 ELSE
5041 l_res_inv_attributes_tbl(1) := p_lot_rec.attribute1;
5042 l_inv_attributes_tbl(1) := p_lot_rec.attribute1;
5043 END IF;
5044 IF (p_lot_rec.attribute2 = g_miss_char) THEN
5045 l_res_inv_attributes_tbl(2) := NULL;
5046 l_inv_attributes_tbl(2) := g_miss_char;
5047 ELSE
5048 l_res_inv_attributes_tbl(2) := p_lot_rec.attribute2;
5049 l_inv_attributes_tbl(2) := p_lot_rec.attribute2;
5050 END IF;
5051 IF (p_lot_rec.attribute3 = g_miss_char) THEN
5052 l_res_inv_attributes_tbl(3) := NULL;
5053 l_inv_attributes_tbl(3) := g_miss_char;
5054 ELSE
5055 l_res_inv_attributes_tbl(3) := p_lot_rec.attribute3;
5056 l_inv_attributes_tbl(3) := p_lot_rec.attribute3;
5057 END IF;
5058 IF (p_lot_rec.attribute4 = g_miss_char) THEN
5059 l_res_inv_attributes_tbl(4) := NULL;
5060 l_inv_attributes_tbl(4) := g_miss_char;
5061 ELSE
5062 l_res_inv_attributes_tbl(4) := p_lot_rec.attribute4;
5063 l_inv_attributes_tbl(4) := p_lot_rec.attribute4;
5064 END IF;
5065 IF (p_lot_rec.attribute5 = g_miss_char) THEN
5066 l_res_inv_attributes_tbl(5) := NULL;
5067 l_inv_attributes_tbl(5) := g_miss_char;
5068 ELSE
5069 l_res_inv_attributes_tbl(5) := p_lot_rec.attribute5;
5070 l_inv_attributes_tbl(5) := p_lot_rec.attribute5;
5071 END IF;
5072 IF (p_lot_rec.attribute6 = g_miss_char) THEN
5073 l_res_inv_attributes_tbl(6) := NULL;
5074 l_inv_attributes_tbl(6) := g_miss_char;
5075 ELSE
5076 l_res_inv_attributes_tbl(6) := p_lot_rec.attribute6;
5077 l_inv_attributes_tbl(6) := p_lot_rec.attribute6;
5078 END IF;
5079 IF (p_lot_rec.attribute7 = g_miss_char) THEN
5080 l_res_inv_attributes_tbl(7) := NULL;
5081 l_inv_attributes_tbl(7) := g_miss_char;
5082 ELSE
5083 l_res_inv_attributes_tbl(7) := p_lot_rec.attribute7;
5084 l_inv_attributes_tbl(7) := p_lot_rec.attribute7;
5085 END IF;
5086 IF (p_lot_rec.attribute8 = g_miss_char) THEN
5087 l_res_inv_attributes_tbl(8) := NULL;
5088 l_inv_attributes_tbl(8) := g_miss_char;
5089 ELSE
5090 l_res_inv_attributes_tbl(8) := p_lot_rec.attribute8;
5091 l_inv_attributes_tbl(8) := p_lot_rec.attribute8;
5092 END IF;
5093 IF (p_lot_rec.attribute9 = g_miss_char) THEN
5094 l_res_inv_attributes_tbl(9) := NULL;
5095 l_inv_attributes_tbl(9) := g_miss_char;
5096 ELSE
5097 l_res_inv_attributes_tbl(9) := p_lot_rec.attribute9;
5098 l_inv_attributes_tbl(9) := p_lot_rec.attribute9;
5099 END IF;
5100 IF (p_lot_rec.attribute10 = g_miss_char) THEN
5101 l_res_inv_attributes_tbl(10) := NULL;
5102 l_inv_attributes_tbl(10) := g_miss_char;
5103 ELSE
5104 l_res_inv_attributes_tbl(10) := p_lot_rec.attribute10;
5105 l_inv_attributes_tbl(10) := p_lot_rec.attribute10;
5106 END IF;
5107 IF (p_lot_rec.attribute11 = g_miss_char) THEN
5108 l_res_inv_attributes_tbl(11) := NULL;
5109 l_inv_attributes_tbl(11) := g_miss_char;
5110 ELSE
5111 l_res_inv_attributes_tbl(11) := p_lot_rec.attribute11;
5112 l_inv_attributes_tbl(11) := p_lot_rec.attribute11;
5113 END IF;
5114 IF (p_lot_rec.attribute12 = g_miss_char) THEN
5115 l_res_inv_attributes_tbl(12) := NULL;
5116 l_inv_attributes_tbl(12) := g_miss_char;
5117 ELSE
5118 l_res_inv_attributes_tbl(12) := p_lot_rec.attribute12;
5119 l_inv_attributes_tbl(12) := p_lot_rec.attribute12;
5120 END IF;
5121 IF (p_lot_rec.attribute13 = g_miss_char) THEN
5122 l_res_inv_attributes_tbl(13) := NULL;
5123 l_inv_attributes_tbl(13) := g_miss_char;
5124 ELSE
5125 l_res_inv_attributes_tbl(13) := p_lot_rec.attribute13;
5126 l_inv_attributes_tbl(13) := p_lot_rec.attribute13;
5127 END IF;
5128 IF (p_lot_rec.attribute14 = g_miss_char) THEN
5129 l_res_inv_attributes_tbl(14) := NULL;
5130 l_inv_attributes_tbl(14) := g_miss_char;
5131 ELSE
5132 l_res_inv_attributes_tbl(14) := p_lot_rec.attribute14;
5133 l_inv_attributes_tbl(14) := p_lot_rec.attribute14;
5134 END IF;
5135 IF (p_lot_rec.attribute15 = g_miss_char) THEN
5136 l_res_inv_attributes_tbl(15) := NULL;
5137 l_inv_attributes_tbl(15) := g_miss_char;
5138 ELSE
5139 l_res_inv_attributes_tbl(15) := p_lot_rec.attribute15;
5140 l_inv_attributes_tbl(15) := p_lot_rec.attribute15;
5141 END IF;
5142
5143
5144 IF g_debug = 1 THEN
5145 print_debug('Upd Lot Attr: After preparing the table INV_Attributes', 9);
5146 END IF;
5147
5148 IF G_WMS_INSTALLED is NULL then
5149 IF (inv_install.adv_inv_installed(NULL) = TRUE) THEN
5150 G_WMS_INSTALLED := 'TRUE';
5151 ELSE
5152 G_WMS_INSTALLED := 'FALSE';
5153 end if;
5154 end if;
5155 l_wms_installed := G_WMS_INSTALLED;
5156
5157 if g_debug = 1 then
5158 print_debug('Upd Lot Attr: l_wms_installed is ' || l_wms_installed, 9);
5159 print_debug('Upd Lot Attr: lot_attribute_category ' || p_lot_rec.lot_attribute_category, 9);
5160 end if;
5161
5162 IF l_wms_installed = 'TRUE' then
5163 IF g_debug = 1 THEN
5164 print_debug('Upd Lot Attr: WMS is installed ', 9);
5165 END IF;
5166
5167 IF p_lot_rec.lot_attribute_category IS NULL THEN
5168 inv_lot_sel_attr.get_context_code(l_context, p_lot_rec.organization_id, p_lot_rec.inventory_item_id, 'Lot Attributes');
5169 ELSE
5170 l_context := p_lot_rec.lot_attribute_category;
5171 END IF;
5172
5173 OPEN c_attributes_cur;
5174 FETCH c_attributes_cur INTO l_c_attributes_cur;
5175 CLOSE c_attributes_cur;
5176 OPEN n_attributes_cur;
5177 FETCH n_attributes_cur INTO l_n_attributes_cur;
5178 CLOSE n_attributes_cur;
5179 OPEN d_attributes_cur;
5180 FETCH d_attributes_cur INTO l_d_attributes_cur;
5181 CLOSE d_attributes_cur;
5182 OPEN wms_named_attr;
5183 FETCH wms_named_attr INTO l_wms_named_attr;
5184 CLOSE wms_named_attr;
5185 /*Populate the PL/SQL tables with the values obtained from the cursor*/
5186 l_c_attributes_tbl(1) := l_c_attributes_cur.c_attribute1;
5187 l_c_attributes_tbl(2) := l_c_attributes_cur.c_attribute2;
5188 l_c_attributes_tbl(3) := l_c_attributes_cur.c_attribute3;
5189 l_c_attributes_tbl(4) := l_c_attributes_cur.c_attribute4;
5190 l_c_attributes_tbl(5) := l_c_attributes_cur.c_attribute5;
5191 l_c_attributes_tbl(6) := l_c_attributes_cur.c_attribute6;
5192 l_c_attributes_tbl(7) := l_c_attributes_cur.c_attribute7;
5193 l_c_attributes_tbl(8) := l_c_attributes_cur.c_attribute8;
5194 l_c_attributes_tbl(9) := l_c_attributes_cur.c_attribute9;
5195 l_c_attributes_tbl(10) := l_c_attributes_cur.c_attribute10;
5196 l_c_attributes_tbl(11) := l_c_attributes_cur.c_attribute11;
5197 l_c_attributes_tbl(12) := l_c_attributes_cur.c_attribute12;
5198 l_c_attributes_tbl(13) := l_c_attributes_cur.c_attribute13;
5199 l_c_attributes_tbl(14) := l_c_attributes_cur.c_attribute14;
5200 l_c_attributes_tbl(15) := l_c_attributes_cur.c_attribute15;
5201 l_c_attributes_tbl(16) := l_c_attributes_cur.c_attribute16;
5202 l_c_attributes_tbl(17) := l_c_attributes_cur.c_attribute17;
5203 l_c_attributes_tbl(18) := l_c_attributes_cur.c_attribute18;
5204 l_c_attributes_tbl(19) := l_c_attributes_cur.c_attribute19;
5205 l_c_attributes_tbl(20) := l_c_attributes_cur.c_attribute20;
5206 l_n_attributes_tbl(1) := l_n_attributes_cur.n_attribute1;
5207 l_n_attributes_tbl(2) := l_n_attributes_cur.n_attribute2;
5208 l_n_attributes_tbl(3) := l_n_attributes_cur.n_attribute3;
5209 l_n_attributes_tbl(4) := l_n_attributes_cur.n_attribute4;
5210 l_n_attributes_tbl(5) := l_n_attributes_cur.n_attribute5;
5211 l_n_attributes_tbl(6) := l_n_attributes_cur.n_attribute6;
5212 l_n_attributes_tbl(7) := l_n_attributes_cur.n_attribute7;
5213 l_n_attributes_tbl(8) := l_n_attributes_cur.n_attribute8;
5214 l_n_attributes_tbl(9) := l_n_attributes_cur.n_attribute9;
5215 l_n_attributes_tbl(10) := l_n_attributes_cur.n_attribute10;
5216 l_d_attributes_tbl(1) := l_d_attributes_cur.d_attribute1;
5217 l_d_attributes_tbl(2) := l_d_attributes_cur.d_attribute2;
5218 l_d_attributes_tbl(3) := l_d_attributes_cur.d_attribute3;
5219 l_d_attributes_tbl(4) := l_d_attributes_cur.d_attribute4;
5220 l_d_attributes_tbl(5) := l_d_attributes_cur.d_attribute5;
5221 l_d_attributes_tbl(6) := l_d_attributes_cur.d_attribute6;
5222 l_d_attributes_tbl(7) := l_d_attributes_cur.d_attribute7;
5223 l_d_attributes_tbl(8) := l_d_attributes_cur.d_attribute8;
5224 l_d_attributes_tbl(9) := l_d_attributes_cur.d_attribute9;
5225 l_d_attributes_tbl(10) := l_d_attributes_cur.d_attribute10;
5226
5227 l_wms_named_attributes.grade_code := p_lot_rec.grade_code;
5228 l_wms_named_attributes.DISABLE_FLAG := p_lot_rec.disable_flag;
5229 l_wms_named_attributes.origination_date := p_lot_rec.origination_date;
5230 l_wms_named_attributes.date_code := p_lot_rec.date_code;
5231 l_wms_named_attributes.change_date := p_lot_rec.change_date;
5232 l_wms_named_attributes.age := p_lot_rec.age;
5233 l_wms_named_attributes.retest_date := p_lot_rec.retest_date;
5234 l_wms_named_attributes.maturity_date := p_lot_rec.maturity_date;
5235 l_wms_named_attributes.item_size := p_lot_rec.item_size;
5236 l_wms_named_attributes.color := p_lot_rec.color;
5237 l_wms_named_attributes.volume := p_lot_rec.volume;
5238 l_wms_named_attributes.volume_uom := p_lot_rec.volume_uom;
5239 l_wms_named_attributes.place_of_origin := p_lot_rec.place_of_origin;
5240 l_wms_named_attributes.best_by_date := p_lot_rec.best_by_date;
5241 l_wms_named_attributes.length := p_lot_rec.length;
5242 l_wms_named_attributes.length_uom := p_lot_rec.length_uom;
5243 l_wms_named_attributes.recycled_content := p_lot_rec.recycled_content;
5244 l_wms_named_attributes.thickness := p_lot_rec.thickness;
5245 l_wms_named_attributes.thickness_uom := p_lot_rec.thickness_uom;
5246 l_wms_named_attributes.width := p_lot_rec.width;
5247 l_wms_named_attributes.width_uom := p_lot_rec.width_uom;
5248 l_wms_named_attributes.territory_code := p_lot_rec.territory_code;
5249 l_wms_named_attributes.supplier_lot_number := p_lot_rec.supplier_lot_number;
5250 l_wms_named_attributes.VENDOR_NAME := p_lot_rec.vendor_name;
5251
5252 IF g_debug = 1 THEN
5253 print_debug('Upd Lot Attr: After getting attributes from the table MLN ' , 9);
5254 END IF;
5255
5256 IF p_source NOT IN(osfm_form_no_validate) THEN
5257 IF g_debug = 1 THEN
5258 print_debug('Validating the Global Segments for WMS context ....' , 9);
5259 END IF;
5260 IF l_context IS NOT NULL THEN
5261 /* Populate the flex field record */
5262
5263 l_dflex_r.application_id := 401;
5264 l_dflex_r.flexfield_name := 'Lot Attributes';
5265
5266 /* Get all contexts */
5267
5268 fnd_dflex.get_contexts(flexfield => l_dflex_r, contexts => l_contexts_dr);
5269 l_context := NULL;
5270 l_global_context := NULL;
5271
5272 /* From the l_contexts_dr, get the position of the global context */
5273
5274 l_global_context := l_contexts_dr.global_context;
5275 l_context := l_contexts_dr.context_code(l_global_context);
5276
5277 /* Prepare the context_r type for getting the segments associated with the global context */
5278
5279 l_context_r.flexfield := l_dflex_r;
5280 l_context_r.context_code := l_context;
5281
5282 /*Get the segments for the context */
5283
5284 fnd_dflex.get_segments(CONTEXT => l_context_r, segments => l_segments_dr, enabled_only => TRUE);
5285
5286 /*Loop through the Segments table to see if any segments are required */
5287
5288 --wms_global_index :=l_segments_dr.first;
5289 FOR wms_global_index IN 1 .. l_segments_dr.nsegments LOOP
5290 IF l_segments_dr.is_required(wms_global_index) THEN
5291 --print_debug('Segment '|| l_segments_dr.application_column_name(wms_global_index)||'is required',9);
5292 IF SUBSTR(l_segments_dr.application_column_name(wms_global_index), INSTR(l_segments_dr.application_column_name(wms_global_index),'ATTRIBUTE')-2, 2) = 'C_' THEN
5293 l_res_c_attributes_tbl(
5294 SUBSTR(
5295 l_segments_dr.application_column_name(wms_global_index)
5296 , INSTR(l_segments_dr.application_column_name(wms_global_index), 'ATTRIBUTE') + 9
5297 )
5298 ) :=
5299 l_c_attributes_tbl(
5300 SUBSTR(
5301 l_segments_dr.application_column_name(wms_global_index)
5302 , INSTR(l_segments_dr.application_column_name(wms_global_index), 'ATTRIBUTE') + 9
5303 )
5304 );
5305 --print_debug('upd Lot Attr tHE VALUE ENTERED IS '|| l_c_attributes_tbl(SUBSTR(l_segments_dr.application_column_name(wms_global_index), INSTR(l_segments_dr.application_column_name(wms_global_index), 'ATTRIBUTE') + 9)), 9);
5306 ELSIF SUBSTR(l_segments_dr.application_column_name(wms_global_index), INSTR(l_segments_dr.application_column_name(wms_global_index),'ATTRIBUTE')-2, 2) = 'N_' THEN
5307 l_res_n_attributes_tbl(
5308 SUBSTR(
5309 l_segments_dr.application_column_name(wms_global_index)
5310 , INSTR(l_segments_dr.application_column_name(wms_global_index), 'ATTRIBUTE') + 9
5311 )
5312 ) :=
5313 l_n_attributes_tbl(
5314 SUBSTR(
5315 l_segments_dr.application_column_name(wms_global_index)
5316 , INSTR(l_segments_dr.application_column_name(wms_global_index), 'ATTRIBUTE') + 9
5317 )
5318 );
5319 ELSIF SUBSTR(l_segments_dr.application_column_name(wms_global_index), INSTR(l_segments_dr.application_column_name(wms_global_index),'ATTRIBUTE')-2, 2) = 'D_' THEN
5320 l_res_d_attributes_tbl(
5321 SUBSTR(
5322 l_segments_dr.application_column_name(wms_global_index)
5323 , INSTR(l_segments_dr.application_column_name(wms_global_index), 'ATTRIBUTE') + 9
5324 )
5325 ) :=
5326 l_d_attributes_tbl(
5327 SUBSTR(
5328 l_segments_dr.application_column_name(wms_global_index)
5329 , INSTR(l_segments_dr.application_column_name(wms_global_index), 'ATTRIBUTE') + 9
5330 )
5331 );
5332 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'GRADE_CODE' THEN
5333 l_wms_named_attributes.grade_code := NVL(l_wms_named_attributes.grade_code,l_wms_named_attr.GRADE_CODE);
5334 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'DISABLE_FLAG' THEN
5335 l_wms_named_attributes.DISABLE_FLAG := NVL(l_wms_named_attributes.DISABLE_FLAG,l_wms_named_attr.DISABLE_FLAG);
5336 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'ORIGINATION_DATE' THEN
5337 l_wms_named_attributes.origination_date := NVL(l_wms_named_attributes.origination_date,L_WMS_NAMED_ATTR.origination_date);
5338 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'DATE_CODE' THEN
5339 l_wms_named_attributes.date_code := NVL(l_wms_named_attributes.date_code,l_wms_named_attr.DATE_CODE);
5340 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'CHANGE_DATE' THEN
5341 l_wms_named_attributes.change_date := NVL(l_wms_named_attributes.change_date,l_wms_named_attr.CHANGE_DATE);
5342 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'AGE' THEN
5343 l_wms_named_attributes.age := NVL(l_wms_named_attributes.age,l_wms_named_attr.AGE);
5344 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'RETEST_DATE' THEN
5345 l_wms_named_attributes.retest_date :=NVL(l_wms_named_attributes.retest_date ,l_wms_named_attr.retest_date);
5346 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'MATURITY_DATE' THEN
5347 l_wms_named_attributes.maturity_date := NVL(l_wms_named_attributes.maturity_date,l_wms_named_attr.MATURITY_DATE) ;
5348 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'ITEM_SIZE' THEN
5349 l_wms_named_attributes.item_size := NVL(l_wms_named_attributes.item_size,l_wms_named_attr.ITEM_SIZE);
5350 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'COLOR' THEN
5351 l_wms_named_attributes.color := nvl(l_wms_named_attributes.color,l_wms_named_attr.COLOR);
5352 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'VOLUME' THEN
5353 l_wms_named_attributes.volume := NVL(l_wms_named_attributes.volume,l_wms_named_attr.VOLUME);
5354 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'VOLUME_UOM' THEN
5355 l_wms_named_attributes.volume_uom := NVL(l_wms_named_attributes.volume_uom,l_wms_named_attr.VOLUME_UOM);
5356 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'PLACE_OF_ORIGIN' THEN
5357 l_wms_named_attributes.place_of_origin := nvl(l_wms_named_attributes.place_of_origin,l_wms_named_attr.PLACE_OF_ORIGIN);
5358 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'BEST_BY_DATE' THEN
5359 l_wms_named_attributes.best_by_date := NVL(l_wms_named_attributes.best_by_date,l_wms_named_attr.BEST_BY_DATE);
5360 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'LENGTH' THEN
5361 l_wms_named_attributes.length := nvl(l_wms_named_attributes.length,l_wms_named_attr.LENGTH);
5362 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'RECYCLED_CONTENT' THEN
5363 l_wms_named_attributes.recycled_content := NVL(l_wms_named_attributes.recycled_content,l_wms_named_attr.RECYCLED_CONTENT);
5364 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'THICKNESS' THEN
5365 l_wms_named_attributes.thickness := NVL(l_wms_named_attributes.thickness,l_wms_named_attr.THICKNESS);
5366 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'THICKNESS_UOM' THEN
5367 l_wms_named_attributes.thickness_uom := NVL(l_wms_named_attributes.thickness_uom,l_wms_named_attr.THICKNESS_UOM);
5368 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'WIDTH' THEN
5369 l_wms_named_attributes.width := NVL(l_wms_named_attributes.width,l_wms_named_attr.WIDTH);
5370 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'WIDTH_UOM' THEN
5371 l_wms_named_attributes.width_uom := NVL(l_wms_named_attributes.width_uom,l_wms_named_attr.WIDTH_UOM);
5372 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'TERRITORY_CODE' THEN
5373 l_wms_named_attributes.territory_code := NVL(l_wms_named_attributes.territory_code,l_wms_named_attr.TERRITORY_CODE);
5374 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'SUPPLIER_LOT_NUMBER' THEN
5375 l_wms_named_attributes.supplier_lot_number := NVL(l_wms_named_attributes.supplier_lot_number,l_wms_named_attr.SUPPLIER_LOT_NUMBER);
5376 ELSIF l_segments_dr.application_column_name(wms_global_index) = 'VENDOR_NAME' THEN
5377 l_wms_named_attributes.VENDOR_NAME := NVL(l_wms_named_attributes.VENDOR_NAME,l_wms_named_attr.VENDOR_NAME);
5378 END IF; /*SUBSTR(l_segments_dr.application_column_name(wms_global_index), 1, 1) = 'C' */
5379 END IF; /*l_segments_dr.is_required(wms_global_index) */
5380 --wms_global_index :=l_segments_dr.next(wms_global_index);
5381 END LOOP;
5382 IF g_debug = 1 THEN
5383 print_debug('Successfully Validated the Global Segments for WMS DFF ....' , 9);
5384 END IF;
5385
5386 l_context := NULL;
5387
5388 IF p_lot_rec.lot_attribute_category IS NULL THEN
5389 inv_lot_sel_attr.get_context_code(l_context, p_lot_rec.organization_id, p_lot_rec.inventory_item_id, 'Lot Attributes');
5390 ELSE
5391 l_context := p_lot_rec.lot_attribute_category;
5392 END IF;
5393
5394 /* Prepare the context_r type for getting the segments associated with the global context */
5395 l_context_r.flexfield := l_dflex_r;
5396 l_context_r.context_code := l_context;
5397 /*Get the segments for the context */
5398 fnd_dflex.get_segments(CONTEXT => l_context_r, segments => l_segments_dr, enabled_only => TRUE);
5399 /*Loop through the Segments table to see if any segments are required */
5400 --wms_context_index :=l_segments_dr.first;
5401 print_debug('Before looping for wms context', 9);
5402
5403 FOR wms_context_index IN 1 .. l_segments_dr.nsegments LOOP
5404 IF l_segments_dr.is_required(wms_context_index) THEN
5405 print_debug('Segment ' || l_segments_dr.application_column_name(wms_context_index) || ' is required', 9);
5406
5407 IF SUBSTR(l_segments_dr.application_column_name(wms_context_index), INSTR(l_segments_dr.application_column_name(wms_context_index),'ATTRIBUTE')-2, 2) = 'C_' THEN
5408 l_res_c_attributes_tbl(
5409 SUBSTR(
5410 l_segments_dr.application_column_name(wms_context_index)
5411 , INSTR(l_segments_dr.application_column_name(wms_context_index), 'ATTRIBUTE') + 9
5412 )
5413 ) :=
5414 l_c_attributes_tbl(
5415 SUBSTR(
5416 l_segments_dr.application_column_name(wms_context_index)
5417 , INSTR(l_segments_dr.application_column_name(wms_context_index), 'ATTRIBUTE') + 9
5418 )
5419 );
5420 ELSIF SUBSTR(l_segments_dr.application_column_name(wms_context_index), INSTR(l_segments_dr.application_column_name(wms_context_index),'ATTRIBUTE')-2, 2) = 'N_' THEN
5421 l_res_n_attributes_tbl(
5422 SUBSTR(
5423 l_segments_dr.application_column_name(wms_context_index)
5424 , INSTR(l_segments_dr.application_column_name(wms_context_index), 'ATTRIBUTE') + 9
5425 )
5426 ) :=
5427 l_n_attributes_tbl(
5428 SUBSTR(
5429 l_segments_dr.application_column_name(wms_context_index)
5430 , INSTR(l_segments_dr.application_column_name(wms_context_index), 'ATTRIBUTE') + 9
5431 )
5432 );
5433 ELSIF SUBSTR(l_segments_dr.application_column_name(wms_context_index), INSTR(l_segments_dr.application_column_name(wms_context_index),'ATTRIBUTE')-2, 2) = 'D_' THEN
5434 l_res_d_attributes_tbl(
5435 SUBSTR(
5436 l_segments_dr.application_column_name(wms_context_index)
5437 , INSTR(l_segments_dr.application_column_name(wms_context_index), 'ATTRIBUTE') + 9
5438 )
5439 ) :=
5440 l_d_attributes_tbl(
5441 SUBSTR(
5442 l_segments_dr.application_column_name(wms_context_index)
5443 , INSTR(l_segments_dr.application_column_name(wms_context_index), 'ATTRIBUTE') + 9
5444 )
5445 );
5446 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'GRADE_CODE' THEN
5447 l_wms_named_attributes.grade_code := NVL(l_wms_named_attributes.grade_code,l_wms_named_attr.GRADE_CODE);
5448 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'DISABLE_FLAG' THEN
5449 l_wms_named_attributes.DISABLE_FLAG := NVL(l_wms_named_attributes.DISABLE_FLAG,l_wms_named_attr.DISABLE_FLAG);
5450 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'ORIGINATION_DATE' THEN
5451 l_wms_named_attributes.origination_date := NVL(l_wms_named_attributes.origination_date,L_WMS_NAMED_ATTR.origination_date);
5452 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'DATE_CODE' THEN
5453 l_wms_named_attributes.date_code := NVL(l_wms_named_attributes.date_code,l_wms_named_attr.DATE_CODE);
5454 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'CHANGE_DATE' THEN
5455 l_wms_named_attributes.change_date := NVL(l_wms_named_attributes.change_date,l_wms_named_attr.CHANGE_DATE);
5456 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'AGE' THEN
5457 l_wms_named_attributes.age := NVL(l_wms_named_attributes.age,l_wms_named_attr.AGE);
5458 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'RETEST_DATE' THEN
5459 l_wms_named_attributes.retest_date :=NVL(l_wms_named_attributes.retest_date ,l_wms_named_attr.retest_date);
5460 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'MATURITY_DATE' THEN
5461 l_wms_named_attributes.maturity_date := NVL(l_wms_named_attributes.maturity_date,l_wms_named_attr.MATURITY_DATE);
5462 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'ITEM_SIZE' THEN
5463 l_wms_named_attributes.item_size := NVL(l_wms_named_attributes.item_size,l_wms_named_attr.ITEM_SIZE);
5464 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'COLOR' THEN
5465 l_wms_named_attributes.color := nvl(l_wms_named_attributes.color,l_wms_named_attr.COLOR);
5466 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'VOLUME' THEN
5467 l_wms_named_attributes.volume := NVL(l_wms_named_attributes.volume,l_wms_named_attr.VOLUME);
5468 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'VOLUME_UOM' THEN
5469 l_wms_named_attributes.volume_uom := NVL(l_wms_named_attributes.volume_uom,l_wms_named_attr.VOLUME_UOM);
5470 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'PLACE_OF_ORIGIN' THEN
5471 l_wms_named_attributes.place_of_origin := nvl(l_wms_named_attributes.place_of_origin,l_wms_named_attr.PLACE_OF_ORIGIN);
5472 IF G_DEBUG =1 THEN
5473 PRINT_DEBUG('After assigninig Place of origin',9);
5474 END IF;
5475 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'BEST_BY_DATE' THEN
5476 l_wms_named_attributes.best_by_date := NVL(l_wms_named_attributes.best_by_date,l_wms_named_attr.BEST_BY_DATE);
5477 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'LENGTH' THEN
5478 l_wms_named_attributes.length := nvl(l_wms_named_attributes.length,l_wms_named_attr.LENGTH);
5479 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'RECYCLED_CONTENT' THEN
5480 l_wms_named_attributes.recycled_content := NVL(l_wms_named_attributes.recycled_content,l_wms_named_attr.RECYCLED_CONTENT);
5481 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'THICKNESS' THEN
5482 l_wms_named_attributes.thickness := NVL(l_wms_named_attributes.thickness,l_wms_named_attr.THICKNESS);
5483 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'THICKNESS_UOM' THEN
5484 l_wms_named_attributes.thickness_uom := NVL(l_wms_named_attributes.thickness_uom,l_wms_named_attr.THICKNESS_UOM);
5485 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'WIDTH' THEN
5486 l_wms_named_attributes.width := NVL(l_wms_named_attributes.width,l_wms_named_attr.WIDTH);
5487 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'WIDTH_UOM' THEN
5488 l_wms_named_attributes.width_uom := NVL(l_wms_named_attributes.width_uom,l_wms_named_attr.WIDTH_UOM);
5489 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'TERRITORY_CODE' THEN
5490 IF G_DEBUG =1 THEN
5491 PRINT_DEBUG('After Territory code '||l_wms_named_attributes.territory_code,9);
5492 PRINT_DEBUG('l_wms_named_attr Territory code '||l_wms_named_attr.TERRITORY_CODE,9);
5493 END IF;
5494 l_wms_named_attributes.territory_code := NVL(l_wms_named_attributes.territory_code,l_wms_named_attr.TERRITORY_CODE);
5495 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'SUPPLIER_LOT_NUMBER' THEN
5496 l_wms_named_attributes.supplier_lot_number := NVL(l_wms_named_attributes.supplier_lot_number,l_wms_named_attr.SUPPLIER_LOT_NUMBER);
5497 ELSIF l_segments_dr.application_column_name(wms_context_index) = 'VENDOR_NAME' THEN
5498 l_wms_named_attributes.VENDOR_NAME := NVL(l_wms_named_attributes.VENDOR_NAME,l_wms_named_attr.VENDOR_NAME);
5499 END IF; /*SUBSTR(l_segments_dr.application_column_name(wms_context_index), 1, 1) = 'C' */
5500 END IF;
5501 --wms_context_index :=l_segments_dr.next(wms_context_index);
5502 END LOOP;
5503 END IF; /*l_context IS NOT NULL */
5504 IF g_debug = 1 THEN
5505 print_debug('Successfully Validated the Segments for passed WMS context ....' , 9);
5506 END IF;
5507 END IF; /* P_SOURCE NOT IN (OSFM_FORM) */
5508
5509 IF g_debug = 1 THEN
5510 print_debug('Preparing input Table for validation ....' , 9);
5511 END IF;
5512
5513 IF (p_lot_rec.c_attribute1 = g_miss_char) THEN
5514 l_res_c_attributes_tbl(1) := NULL;
5515 l_c_attributes_tbl(1) := g_miss_char;
5516 ELSE
5517 l_res_c_attributes_tbl(1) := p_lot_rec.c_attribute1;
5518 l_c_attributes_tbl(1) := p_lot_rec.c_attribute1;
5519 END IF;
5520 IF (p_lot_rec.c_attribute2 = g_miss_char) THEN
5521 l_res_c_attributes_tbl(2) := NULL;
5522 l_c_attributes_tbl(2) := g_miss_char;
5523 ELSE
5524 l_res_c_attributes_tbl(2) := p_lot_rec.c_attribute2;
5525 l_c_attributes_tbl(2) := p_lot_rec.c_attribute2;
5526 END IF;
5527 IF (p_lot_rec.c_attribute3 = g_miss_char) THEN
5528 l_res_c_attributes_tbl(3) := NULL;
5529 l_c_attributes_tbl(3) := g_miss_char;
5530 ELSE
5531 l_res_c_attributes_tbl(3) := p_lot_rec.c_attribute3;
5532 l_c_attributes_tbl(3) := p_lot_rec.c_attribute3;
5533 END IF;
5534 IF (p_lot_rec.c_attribute4 = g_miss_char) THEN
5535 l_res_c_attributes_tbl(4) := NULL;
5536 l_c_attributes_tbl(4) := g_miss_char;
5537 ELSE
5538 l_res_c_attributes_tbl(4) := p_lot_rec.c_attribute4;
5539 l_c_attributes_tbl(4) := p_lot_rec.c_attribute4;
5540 END IF;
5541 IF (p_lot_rec.c_attribute5 = g_miss_char) THEN
5542 l_res_c_attributes_tbl(5) := NULL;
5543 l_c_attributes_tbl(5) := g_miss_char;
5544 ELSE
5545 l_res_c_attributes_tbl(5) := p_lot_rec.c_attribute5;
5546 l_c_attributes_tbl(5) := p_lot_rec.c_attribute5;
5547 END IF;
5548 IF (p_lot_rec.c_attribute6 = g_miss_char) THEN
5549 l_res_c_attributes_tbl(6) := NULL;
5550 l_c_attributes_tbl(6) := g_miss_char;
5551 ELSE
5552 l_res_c_attributes_tbl(6) := p_lot_rec.c_attribute6;
5553 l_c_attributes_tbl(6) := p_lot_rec.c_attribute6;
5554 END IF;
5555 IF (p_lot_rec.c_attribute7 = g_miss_char) THEN
5556 l_res_c_attributes_tbl(7) := NULL;
5557 l_c_attributes_tbl(7) := g_miss_char;
5558 ELSE
5559 l_res_c_attributes_tbl(7) := p_lot_rec.c_attribute7;
5560 l_c_attributes_tbl(7) := p_lot_rec.c_attribute7;
5561 END IF;
5562 IF (p_lot_rec.c_attribute8 = g_miss_char) THEN
5563 l_res_c_attributes_tbl(8) := NULL;
5564 l_c_attributes_tbl(8) := g_miss_char;
5565 ELSE
5566 l_res_c_attributes_tbl(8) := p_lot_rec.c_attribute8;
5567 l_c_attributes_tbl(8) := p_lot_rec.c_attribute8;
5568 END IF;
5569 IF (p_lot_rec.c_attribute9 = g_miss_char) THEN
5570 l_res_c_attributes_tbl(9) := NULL;
5571 l_c_attributes_tbl(9) := g_miss_char;
5572 ELSE
5573 l_res_c_attributes_tbl(9) := p_lot_rec.c_attribute9;
5574 l_c_attributes_tbl(9) := p_lot_rec.c_attribute9;
5575 END IF;
5576 IF (p_lot_rec.c_attribute10 = g_miss_char) THEN
5577 l_res_c_attributes_tbl(10) := NULL;
5578 l_c_attributes_tbl(10) := g_miss_char;
5579 ELSE
5580 l_res_c_attributes_tbl(10) := p_lot_rec.c_attribute10;
5581 l_c_attributes_tbl(10) := p_lot_rec.c_attribute10;
5582 END IF;
5583 IF (p_lot_rec.c_attribute11 = g_miss_char) THEN
5584 l_res_c_attributes_tbl(11) := NULL;
5585 l_c_attributes_tbl(11) := g_miss_char;
5586 ELSE
5587 l_res_c_attributes_tbl(11) := p_lot_rec.c_attribute11;
5588 l_c_attributes_tbl(11) := p_lot_rec.c_attribute11;
5589 END IF;
5590 IF (p_lot_rec.c_attribute12 = g_miss_char) THEN
5591 l_res_c_attributes_tbl(12) := NULL;
5592 l_c_attributes_tbl(12) := g_miss_char;
5593 ELSE
5594 l_res_c_attributes_tbl(12) := p_lot_rec.c_attribute12;
5595 l_c_attributes_tbl(12) := p_lot_rec.c_attribute12;
5596 END IF;
5597 IF (p_lot_rec.c_attribute13 = g_miss_char) THEN
5598 l_res_c_attributes_tbl(13) := NULL;
5599 l_c_attributes_tbl(13) := g_miss_char;
5600 ELSE
5601 l_res_c_attributes_tbl(13) := p_lot_rec.c_attribute13;
5602 l_c_attributes_tbl(13) := p_lot_rec.c_attribute13;
5603 END IF;
5604 IF (p_lot_rec.c_attribute14 = g_miss_char) THEN
5605 l_res_c_attributes_tbl(14) := NULL;
5606 l_c_attributes_tbl(14) := g_miss_char;
5607 ELSE
5608 l_res_c_attributes_tbl(14) := p_lot_rec.c_attribute14;
5609 l_c_attributes_tbl(14) := p_lot_rec.c_attribute14;
5610 END IF;
5611 IF (p_lot_rec.c_attribute15 = g_miss_char) THEN
5612 l_res_c_attributes_tbl(15) := NULL;
5613 l_c_attributes_tbl(15) := g_miss_char;
5614 ELSE
5615 l_res_c_attributes_tbl(15) := p_lot_rec.c_attribute15;
5616 l_c_attributes_tbl(15) := p_lot_rec.c_attribute15;
5617 END IF;
5618 IF (p_lot_rec.c_attribute16 = g_miss_char) THEN
5619 l_res_c_attributes_tbl(16) := NULL;
5620 l_c_attributes_tbl(16) := g_miss_char;
5621 ELSE
5622 l_res_c_attributes_tbl(16) := p_lot_rec.c_attribute16;
5623 l_c_attributes_tbl(16) := p_lot_rec.c_attribute16;
5624 END IF;
5625 IF (p_lot_rec.c_attribute17 = g_miss_char) THEN
5626 l_res_c_attributes_tbl(17) := NULL;
5627 l_c_attributes_tbl(17) := g_miss_char;
5628 ELSE
5629 l_res_c_attributes_tbl(17) := p_lot_rec.c_attribute17;
5630 l_c_attributes_tbl(17) := p_lot_rec.c_attribute17;
5631 END IF;
5632 IF (p_lot_rec.c_attribute18 = g_miss_char) THEN
5633 l_res_c_attributes_tbl(18) := NULL;
5634 l_c_attributes_tbl(18) := g_miss_char;
5635 ELSE
5636 l_res_c_attributes_tbl(18) := p_lot_rec.c_attribute18;
5637 l_c_attributes_tbl(18) := p_lot_rec.c_attribute18;
5638 END IF;
5639 IF (p_lot_rec.c_attribute19 = g_miss_char) THEN
5640 l_res_c_attributes_tbl(19) := NULL;
5641 l_c_attributes_tbl(19) := g_miss_char;
5642 ELSE
5643 l_res_c_attributes_tbl(19) := p_lot_rec.c_attribute19;
5644 l_c_attributes_tbl(19) := p_lot_rec.c_attribute19;
5645 END IF;
5646 IF (p_lot_rec.c_attribute20 = g_miss_char) THEN
5647 l_res_c_attributes_tbl(20) := NULL;
5648 l_c_attributes_tbl(20) := g_miss_char;
5649 ELSE
5650 l_res_c_attributes_tbl(20) := p_lot_rec.c_attribute20;
5651 l_c_attributes_tbl(20) := p_lot_rec.c_attribute20;
5652 END IF;
5653
5654 IF g_debug = 1 THEN
5655 print_debug('Upd Lot Attr: After preparing the C_ATTRIBUTES table ', 9);
5656 END IF;
5657
5658 IF (p_lot_rec.n_attribute1 = g_miss_num) THEN
5659 l_res_n_attributes_tbl(1) := NULL;
5660 l_n_attributes_tbl(1) := g_miss_num;
5661 ELSE
5662 l_res_n_attributes_tbl(1) := p_lot_rec.n_attribute1;
5663 l_n_attributes_tbl(1) := p_lot_rec.n_attribute1;
5664 END IF;
5665 IF (p_lot_rec.n_attribute2 = g_miss_num) THEN
5666 l_res_n_attributes_tbl(2) := NULL;
5667 l_n_attributes_tbl(2) := g_miss_num;
5668 ELSE
5669 l_res_n_attributes_tbl(2) := p_lot_rec.n_attribute2;
5670 l_n_attributes_tbl(2) := p_lot_rec.n_attribute2;
5671 END IF;
5672 IF (p_lot_rec.n_attribute3 = g_miss_num) THEN
5673 l_res_n_attributes_tbl(3) := NULL;
5674 l_n_attributes_tbl(3) := g_miss_num;
5675 ELSE
5676 l_res_n_attributes_tbl(3) := p_lot_rec.n_attribute3;
5677 l_n_attributes_tbl(3) := p_lot_rec.n_attribute3;
5678 END IF;
5679 IF (p_lot_rec.n_attribute4 = g_miss_num) THEN
5680 l_res_n_attributes_tbl(4) := NULL;
5681 l_n_attributes_tbl(4) := g_miss_num;
5682 ELSE
5683 l_res_n_attributes_tbl(4) := p_lot_rec.n_attribute4;
5684 l_n_attributes_tbl(4) := p_lot_rec.n_attribute4;
5685 END IF;
5686 IF (p_lot_rec.n_attribute5 = g_miss_num) THEN
5687 l_res_n_attributes_tbl(5) := NULL;
5688 l_n_attributes_tbl(5) := g_miss_num;
5689 ELSE
5690 l_res_n_attributes_tbl(5) := p_lot_rec.n_attribute5;
5691 l_n_attributes_tbl(5) := p_lot_rec.n_attribute5;
5692 END IF;
5693 IF (p_lot_rec.n_attribute6 = g_miss_num) THEN
5694 l_res_n_attributes_tbl(6) := NULL;
5695 l_n_attributes_tbl(6) := g_miss_num;
5696 ELSE
5697 l_res_n_attributes_tbl(6) := p_lot_rec.n_attribute6;
5698 l_n_attributes_tbl(6) := p_lot_rec.n_attribute6;
5699 END IF;
5700 IF (p_lot_rec.n_attribute7 = g_miss_num) THEN
5701 l_res_n_attributes_tbl(7) := NULL;
5702 l_n_attributes_tbl(7) := g_miss_num;
5703 ELSE
5704 l_res_n_attributes_tbl(7) := p_lot_rec.n_attribute7;
5705 l_n_attributes_tbl(7) := p_lot_rec.n_attribute7;
5706 END IF;
5707 IF (p_lot_rec.n_attribute8 = g_miss_num) THEN
5708 l_res_n_attributes_tbl(8) := NULL;
5709 l_n_attributes_tbl(8) := g_miss_num;
5710 ELSE
5711 l_res_n_attributes_tbl(8) := p_lot_rec.n_attribute8;
5712 l_n_attributes_tbl(8) := p_lot_rec.n_attribute8;
5713 END IF;
5714 IF (p_lot_rec.n_attribute9 = g_miss_num) THEN
5715 l_res_n_attributes_tbl(9) := NULL;
5716 l_n_attributes_tbl(9) := g_miss_num;
5717 ELSE
5718 l_res_n_attributes_tbl(9) := p_lot_rec.n_attribute9;
5719 l_n_attributes_tbl(9) := p_lot_rec.n_attribute9;
5720 END IF;
5721 IF (p_lot_rec.n_attribute10 = g_miss_num) THEN
5722 l_res_n_attributes_tbl(10) := NULL;
5723 l_n_attributes_tbl(10) := g_miss_num;
5724 ELSE
5725 l_res_n_attributes_tbl(10) := p_lot_rec.n_attribute10;
5726 l_n_attributes_tbl(10) := p_lot_rec.n_attribute10;
5727 END IF;
5728
5729 IF g_debug = 1 THEN
5730 print_debug('Upd Lot Attr: After preparing the N_ATTRIBUTES table ', 9);
5731 END IF;
5732
5733 IF (p_lot_rec.d_attribute1 = g_miss_date) THEN
5734 l_res_d_attributes_tbl(1) := NULL;
5735 l_d_attributes_tbl(1) := g_miss_date;
5736 ELSE
5737 l_res_d_attributes_tbl(1) := p_lot_rec.d_attribute1;
5738 l_d_attributes_tbl(1) := p_lot_rec.d_attribute1;
5739 END IF;
5740 IF (p_lot_rec.d_attribute2 = g_miss_date) THEN
5741 l_res_d_attributes_tbl(2) := NULL;
5742 l_d_attributes_tbl(2) := g_miss_date;
5743 ELSE
5744 l_res_d_attributes_tbl(2) := p_lot_rec.d_attribute2;
5745 l_d_attributes_tbl(2) := p_lot_rec.d_attribute2;
5746 END IF;
5747 IF (p_lot_rec.d_attribute3 = g_miss_date) THEN
5748 l_res_d_attributes_tbl(3) := NULL;
5749 l_d_attributes_tbl(3) := g_miss_date;
5750 ELSE
5751 l_res_d_attributes_tbl(3) := p_lot_rec.d_attribute3;
5752 l_d_attributes_tbl(3) := p_lot_rec.d_attribute3;
5753 END IF;
5754 IF (p_lot_rec.d_attribute4 = g_miss_date) THEN
5755 l_res_d_attributes_tbl(4) := NULL;
5756 l_d_attributes_tbl(4) := g_miss_date;
5757 ELSE
5758 l_res_d_attributes_tbl(4) := p_lot_rec.d_attribute4;
5759 l_d_attributes_tbl(4) := p_lot_rec.d_attribute4;
5760 END IF;
5761 IF (p_lot_rec.d_attribute5 = g_miss_date) THEN
5762 l_res_d_attributes_tbl(5) := NULL;
5763 l_d_attributes_tbl(5) := g_miss_date;
5764 ELSE
5765 l_res_d_attributes_tbl(5) := p_lot_rec.d_attribute5;
5766 l_d_attributes_tbl(5) := p_lot_rec.d_attribute5;
5767 END IF;
5768 IF (p_lot_rec.d_attribute6 = g_miss_date) THEN
5769 l_res_d_attributes_tbl(6) := NULL;
5770 l_d_attributes_tbl(6) := g_miss_date;
5771 ELSE
5772 l_res_d_attributes_tbl(6) := p_lot_rec.d_attribute6;
5773 l_d_attributes_tbl(6) := p_lot_rec.d_attribute6;
5774 END IF;
5775 IF (p_lot_rec.d_attribute7 = g_miss_date) THEN
5776 l_res_d_attributes_tbl(7) := NULL;
5777 l_d_attributes_tbl(7) := g_miss_date;
5778 ELSE
5779 l_res_d_attributes_tbl(7) := p_lot_rec.d_attribute7;
5780 l_d_attributes_tbl(7) := p_lot_rec.d_attribute7;
5781 END IF;
5782 IF (p_lot_rec.d_attribute8 = g_miss_date) THEN
5783 l_res_d_attributes_tbl(8) := NULL;
5784 l_d_attributes_tbl(8) := g_miss_date;
5785 ELSE
5786 l_res_d_attributes_tbl(8) := p_lot_rec.d_attribute8;
5787 l_d_attributes_tbl(8) := p_lot_rec.d_attribute8;
5788 END IF;
5789 IF (p_lot_rec.d_attribute9 = g_miss_date) THEN
5790 l_res_d_attributes_tbl(9) := NULL;
5791 l_d_attributes_tbl(9) := g_miss_date;
5792 ELSE
5793 l_res_d_attributes_tbl(9) := p_lot_rec.d_attribute9;
5794 l_d_attributes_tbl(9) := p_lot_rec.d_attribute9;
5795 END IF;
5796 IF (p_lot_rec.d_attribute10 = g_miss_date) THEN
5797 l_res_d_attributes_tbl(10) := NULL;
5798 l_d_attributes_tbl(10) := g_miss_date;
5799 ELSE
5800 l_res_d_attributes_tbl(10) := p_lot_rec.d_attribute10;
5801 l_d_attributes_tbl(10) := p_lot_rec.d_attribute10;
5802 END IF;
5803
5804 IF g_debug = 1 THEN
5805 print_debug('Upd Lot Attr: After preparing the D_ATTRIBUTES table ', 9);
5806 END IF;
5807 END IF; /* end if for Wms is installed */
5808
5809 IF g_debug = 1 THEN
5810 print_debug(' Before the call to The procedure validate_lot_attr_in_param ....' , 9);
5811 END IF;
5812
5813 validate_lot_attr_in_param(
5814 x_return_status => l_return_status
5815 , x_msg_count => l_msg_count
5816 , x_msg_data => l_msg_data
5817 , p_inventory_item_id => p_lot_rec.inventory_item_id
5818 , p_organization_id => p_lot_rec.organization_id
5819 , p_lot_number => p_lot_rec.lot_number
5820 , p_attribute_category => p_lot_rec.attribute_category
5821 , p_lot_attribute_category => p_lot_rec.lot_attribute_category
5822 , p_attributes_tbl => l_res_inv_attributes_tbl
5823 , p_c_attributes_tbl => l_res_c_attributes_tbl
5824 , p_n_attributes_tbl => l_res_n_attributes_tbl
5825 , p_d_attributes_tbl => l_res_d_attributes_tbl
5826 , p_wms_is_installed => l_wms_installed
5827 , p_source => p_source
5828 , p_disable_flag => l_wms_named_attributes.disable_flag
5829 , p_grade_code => l_wms_named_attributes.grade_code
5830 , p_origination_date => l_wms_named_attributes.origination_date
5831 , p_date_code => l_wms_named_attributes.date_code
5832 , p_change_date => l_wms_named_attributes.change_date
5833 , p_age => l_wms_named_attributes.age
5834 , p_retest_date => l_wms_named_attributes.retest_date
5835 , p_maturity_date => l_wms_named_attributes.maturity_date
5836 , p_item_size => l_wms_named_attributes.item_size
5837 , p_color => l_wms_named_attributes.color
5838 , p_volume => l_wms_named_attributes.volume
5839 , p_volume_uom => l_wms_named_attributes.volume_uom
5840 , p_place_of_origin => l_wms_named_attributes.place_of_origin
5841 , p_best_by_date => l_wms_named_attributes.best_by_date
5842 , p_length => l_wms_named_attributes.length
5843 , p_length_uom => l_wms_named_attributes.length_uom
5844 , p_recycled_content => l_wms_named_attributes.recycled_content
5845 , p_thickness => l_wms_named_attributes.thickness
5846 , p_thickness_uom => l_wms_named_attributes.thickness_uom
5847 , p_width => l_wms_named_attributes.width
5848 , p_width_uom => l_wms_named_attributes.width_uom
5849 , p_territory_code => l_wms_named_attributes.territory_code
5850 , p_supplier_lot_number => l_wms_named_attributes.supplier_lot_number
5851 , p_vendor_name => l_wms_named_attributes.vendor_name
5852 );
5853
5854 IF l_return_status = g_ret_sts_error THEN
5855 IF g_debug = 1 THEN
5856 print_debug('Update Lot Attr: Program validate_lot_attr_in_param has failed with a user defined exception', 9);
5857 END IF;
5858
5859 RAISE g_exc_error;
5860 ELSIF l_return_status = g_ret_sts_unexp_error THEN
5861 IF g_debug = 1 THEN
5862 print_debug('Update Lot Attr: Program validate_lot_attr_in_param has failed with a Unexpected exception', 9);
5863 END IF;
5864
5865 RAISE g_exc_unexpected_error;
5866 END IF;
5867
5868 IF g_debug = 1 THEN
5869 print_debug('Upd Lot Attr: Call to validate_lot_attr_in_param is success ', 9);
5870 END IF;
5871 IF g_debug = 1 THEN
5872 print_debug('Updating MTL_LOT_NUMBERS table ....' , 9);
5873 END IF;
5874 inv_log_util.trace('l_expiration_date is:'||l_expiration_date, 'INV_LOT_API_PUB','9'); --For bug 4888300
5875
5876 --Fixed for bug#7529468
5877 --added two column in update statement
5878 --LAST_UPDATE_DATE and LAST_UPDATED_BY
5879 --Fix for bug#7930079
5880 --In decode function for date columns - NULL is changed as to_date(NULL)
5881 IF l_wms_installed = 'TRUE' THEN
5882 UPDATE mtl_lot_numbers
5883 SET expiration_date =
5884 DECODE(l_expiration_date, NULL, expiration_date, l_expiration_date )
5885 , disable_flag =
5886 DECODE(
5887 p_source
5888 , 2, DECODE(p_lot_rec.disable_flag, g_miss_num, NULL, NULL, disable_flag, p_lot_rec.disable_flag) /*Bug 14835444 changed g_miss_char to g_miss_num */
5889 , DECODE(p_lot_rec.disable_flag, g_miss_num, disable_flag, NULL, NULL, p_lot_rec.disable_flag)
5890 )
5891 , attribute_category =
5892 DECODE(
5893 p_source
5894 , 2, DECODE(p_lot_rec.attribute_category, g_miss_char, NULL, NULL, attribute_category, p_lot_rec.attribute_category)
5895 , DECODE(p_lot_rec.attribute_category, g_miss_char, attribute_category, NULL, NULL, p_lot_rec.attribute_category)
5896 )
5897 , lot_attribute_category =
5898 DECODE(
5899 p_source
5900 , 2, DECODE(p_lot_rec.lot_attribute_category, g_miss_char, NULL, NULL, lot_attribute_category, p_lot_rec.lot_attribute_category)
5901 , DECODE(p_lot_rec.lot_attribute_category, g_miss_char, lot_attribute_category, NULL, NULL, p_lot_rec.lot_attribute_category)
5902 )
5903 /*, grade_code =
5904 DECODE(
5905 p_source
5906 , 2, DECODE(p_lot_rec.grade_code, g_miss_char, NULL, NULL, grade_code, p_lot_rec.grade_code)
5907 , DECODE(p_lot_rec.grade_code, g_miss_char, grade_code, NULL, NULL, p_lot_rec.grade_code)
5908 )*/ -- Commented for bug 13780398
5909 , origination_date =
5910 DECODE(
5911 p_source
5912 , 2, DECODE(p_lot_rec.origination_date, g_miss_date,To_Date(NULL), NULL, origination_date, p_lot_rec.origination_date)
5913 , DECODE(p_lot_rec.origination_date, g_miss_date, origination_date, NULL, To_Date(NULL), p_lot_rec.origination_date)
5914 )
5915 , date_code =
5916 DECODE(
5917 p_source
5918 , 2, DECODE(p_lot_rec.date_code, g_miss_char, NULL, NULL, date_code, p_lot_rec.date_code)
5919 , DECODE(p_lot_rec.date_code, g_miss_char, date_code, NULL, NULL, p_lot_rec.date_code)
5920 )
5921 /* Bug 8198497- Removed the code as we are updating the status by calling validate_lot_status */
5922 , change_date =
5923 DECODE(
5924 p_source
5925 , 2, DECODE(p_lot_rec.change_date, g_miss_date, To_Date(NULL), NULL, change_date, p_lot_rec.change_date)
5926 , DECODE(p_lot_rec.change_date, g_miss_date, change_date, NULL, To_Date(NULL), p_lot_rec.change_date)
5927 )
5928 , age = DECODE(
5929 p_source
5930 , 2, DECODE(p_lot_rec.age, g_miss_num, NULL, NULL, age, p_lot_rec.age)
5931 , DECODE(p_lot_rec.age, g_miss_num, age, NULL, NULL, p_lot_rec.age)
5932 )
5933 , retest_date =
5934 DECODE(
5935 p_source
5936 , 2, DECODE(p_lot_rec.retest_date, g_miss_date, To_Date(NULL), NULL, retest_date, p_lot_rec.retest_date)
5937 , DECODE(p_lot_rec.retest_date, g_miss_date, retest_date, NULL, To_Date(NULL), p_lot_rec.retest_date)
5938 )
5939 , maturity_date =
5940 DECODE(
5941 p_source
5942 , 2, DECODE(p_lot_rec.maturity_date, g_miss_date, To_Date(NULL), NULL, maturity_date, p_lot_rec.maturity_date)
5943 , DECODE(p_lot_rec.maturity_date, g_miss_date, maturity_date, NULL, To_Date(NULL), p_lot_rec.maturity_date)
5944 )
5945 , item_size =
5946 DECODE(
5947 p_source
5948 , 2, DECODE(p_lot_rec.item_size, g_miss_num, NULL, NULL, item_size, p_lot_rec.item_size)
5949 , DECODE(p_lot_rec.item_size, g_miss_num, item_size, NULL, NULL, p_lot_rec.item_size)
5950 )
5951 , color =
5952 DECODE(
5953 p_source
5954 , 2, DECODE(p_lot_rec.color, g_miss_char, NULL, NULL, color, p_lot_rec.color)
5955 , DECODE(p_lot_rec.color, g_miss_char, color, NULL, NULL, p_lot_rec.color)
5956 )
5957 , volume =
5958 DECODE(
5959 p_source
5960 , 2, DECODE(p_lot_rec.volume, g_miss_num, NULL, NULL, volume, p_lot_rec.volume)
5961 , DECODE(p_lot_rec.volume, g_miss_num, volume, NULL, NULL, p_lot_rec.volume)
5962 )
5963 , volume_uom =
5964 DECODE(
5965 p_source
5966 , 2, DECODE(p_lot_rec.volume_uom, g_miss_char, NULL, NULL, volume_uom, p_lot_rec.volume_uom)
5967 , DECODE(p_lot_rec.volume_uom, g_miss_char, volume_uom, NULL, NULL, p_lot_rec.volume_uom)
5968 )
5969 , place_of_origin =
5970 DECODE(
5971 p_source
5972 , 2, DECODE(p_lot_rec.place_of_origin, g_miss_char, NULL, NULL, place_of_origin, p_lot_rec.place_of_origin)
5973 , DECODE(p_lot_rec.place_of_origin, g_miss_char, place_of_origin, NULL, place_of_origin, p_lot_rec.place_of_origin)
5974 )
5975 , best_by_date =
5976 DECODE(
5977 p_source
5978 , 2, DECODE(p_lot_rec.best_by_date, g_miss_date, To_Date(NULL), NULL, best_by_date, p_lot_rec.best_by_date)
5979 , DECODE(p_lot_rec.best_by_date, g_miss_date, best_by_date, NULL, To_Date(NULL), p_lot_rec.best_by_date)
5980 )
5981 , LENGTH =
5982 DECODE(
5983 p_source
5984 , 2, DECODE(p_lot_rec.length, g_miss_num, NULL, NULL, LENGTH, p_lot_rec.length)
5985 , DECODE(p_lot_rec.length, g_miss_num, LENGTH, NULL, NULL, p_lot_rec.length)
5986 )
5987 , length_uom =
5988 DECODE(
5989 p_source
5990 , 2, DECODE(p_lot_rec.length_uom, g_miss_char, NULL, NULL, length_uom, p_lot_rec.length_uom)
5991 , DECODE(p_lot_rec.length_uom, g_miss_char, length_uom, NULL, NULL, p_lot_rec.length_uom)
5992 )
5993 , recycled_content =
5994 DECODE(
5995 p_source
5996 , 2, DECODE(p_lot_rec.recycled_content, g_miss_num, NULL, NULL, recycled_content, p_lot_rec.recycled_content)
5997 , DECODE(p_lot_rec.recycled_content, g_miss_num, recycled_content, NULL, NULL, p_lot_rec.recycled_content)
5998 )
5999 , thickness =
6000 DECODE(
6001 p_source
6002 , 2, DECODE(p_lot_rec.thickness, g_miss_num, NULL, NULL, thickness, p_lot_rec.thickness)
6003 , DECODE(p_lot_rec.thickness, g_miss_num, thickness, NULL, NULL, p_lot_rec.thickness)
6004 )
6005 , thickness_uom =
6006 DECODE(
6007 p_source
6008 , 2, DECODE(p_lot_rec.thickness_uom, g_miss_char, NULL, NULL, thickness_uom, p_lot_rec.thickness_uom)
6009 , DECODE(p_lot_rec.thickness_uom, g_miss_char, thickness_uom, NULL, NULL, p_lot_rec.thickness_uom)
6010 )
6011 , width =
6012 DECODE(
6013 p_source
6014 , 2, DECODE(p_lot_rec.width, g_miss_num, NULL, NULL, width, p_lot_rec.width)
6015 , DECODE(p_lot_rec.width, g_miss_num, width, NULL, NULL, p_lot_rec.width)
6016 )
6017 , width_uom =
6018 DECODE(
6019 p_source
6020 , 2, DECODE(p_lot_rec.width_uom, g_miss_char, NULL, NULL, width_uom, p_lot_rec.width_uom)
6021 , DECODE(p_lot_rec.width_uom, g_miss_char, width_uom, NULL, NULL, p_lot_rec.width_uom)
6022 )
6023 , territory_code =
6024 DECODE(
6025 p_source
6026 , 2, DECODE(p_lot_rec.territory_code, g_miss_char, NULL, NULL, territory_code, p_lot_rec.territory_code)
6027 , DECODE(p_lot_rec.territory_code, g_miss_char, territory_code, NULL, NULL, p_lot_rec.territory_code)
6028 )
6029 , supplier_lot_number =
6030 DECODE(
6031 p_source
6032 , 2, DECODE(p_lot_rec.supplier_lot_number, g_miss_char, NULL, NULL, supplier_lot_number, p_lot_rec.supplier_lot_number)
6033 , DECODE(p_lot_rec.supplier_lot_number, g_miss_char, supplier_lot_number, NULL, NULL, p_lot_rec.supplier_lot_number)
6034 )
6035 , vendor_name =
6036 DECODE(
6037 p_source
6038 , 2, DECODE(p_lot_rec.vendor_name, g_miss_char, NULL, NULL, vendor_name, p_lot_rec.vendor_name)
6039 , DECODE(p_lot_rec.vendor_name, g_miss_char, vendor_name, NULL, NULL, p_lot_rec.vendor_name)
6040 )
6041 -- Bug 6983527 - Parent lot number should never be updated.
6042 /*Bug 8311729 Uncommenting the below code as we should be able to
6043 update the mistakenly entered parent lot information */
6044 -- nsinghi bug#5209065. Update new lot attributes
6045 , parent_lot_number =
6046 DECODE(
6047 p_source
6048 , 2, DECODE(p_lot_rec.parent_lot_number, g_miss_char, NULL, NULL, parent_lot_number, p_lot_rec.parent_lot_number)
6049 , DECODE(p_lot_rec.parent_lot_number, g_miss_char, parent_lot_number, NULL, NULL, p_lot_rec.parent_lot_number)
6050 )
6051
6052 -- Bug 13553990 keeping the value of columns without getting updated to NULL which are not passed.
6053 , origination_type =
6054 DECODE(
6055 p_source
6056 , 2, DECODE(p_lot_rec.origination_type, g_miss_num, NULL, NULL, origination_type, p_lot_rec.origination_type)
6057 , DECODE(p_lot_rec.origination_type, -99, origination_type, g_miss_num, origination_type, NULL, NULL, p_lot_rec.origination_type)
6058 )
6059 , availability_type =
6060 DECODE(
6061 p_source
6062 , 2, DECODE(p_lot_rec.availability_type, g_miss_num, NULL, NULL, availability_type, p_lot_rec.availability_type)
6063 , DECODE(p_lot_rec.availability_type, g_miss_num, availability_type, NULL, NULL, p_lot_rec.availability_type)
6064 )
6065 , expiration_action_code =
6066 DECODE(
6067 p_source
6068 , 2, DECODE(p_lot_rec.expiration_action_code, g_miss_char, NULL, NULL, expiration_action_code, p_lot_rec.expiration_action_code)
6069 , DECODE(p_lot_rec.expiration_action_code, g_miss_char, expiration_action_code, NULL, NULL, p_lot_rec.expiration_action_code)
6070 )
6071 , expiration_action_date =
6072 DECODE(
6073 p_source
6074 , 2, DECODE(p_lot_rec.expiration_action_date, g_miss_date, To_Date(NULL), NULL, expiration_action_date, p_lot_rec.expiration_action_date)
6075 , DECODE(p_lot_rec.expiration_action_date, g_miss_date, expiration_action_date, NULL, To_Date(NULL), p_lot_rec.expiration_action_date)
6076 )
6077 , hold_date =
6078 DECODE(
6079 p_source
6080 , 2, DECODE(p_lot_rec.hold_date, g_miss_date, To_Date(NULL), NULL, hold_date, p_lot_rec.hold_date)
6081 , DECODE(p_lot_rec.hold_date, g_miss_date, hold_date, NULL, To_Date(NULL), p_lot_rec.hold_date)
6082 )
6083 , inventory_atp_code =
6084 DECODE(
6085 p_source
6086 , 2, DECODE(p_lot_rec.inventory_atp_code, g_miss_num, NULL, NULL, inventory_atp_code, p_lot_rec.inventory_atp_code)
6087 , DECODE(p_lot_rec.inventory_atp_code, g_miss_num, inventory_atp_code, NULL, NULL, p_lot_rec.inventory_atp_code)
6088 )
6089 , reservable_type =
6090 DECODE(
6091 p_source
6092 , 2, DECODE(p_lot_rec.reservable_type, g_miss_num, NULL, NULL, reservable_type, p_lot_rec.reservable_type)
6093 , DECODE(p_lot_rec.reservable_type, g_miss_num, reservable_type, NULL, NULL, p_lot_rec.reservable_type)
6094 )
6095 , sampling_event_id =
6096 DECODE(
6097 p_source
6098 , 2, DECODE(p_lot_rec.sampling_event_id, g_miss_num, NULL, NULL, sampling_event_id, p_lot_rec.sampling_event_id)
6099 , DECODE(p_lot_rec.sampling_event_id, g_miss_num, sampling_event_id, NULL, NULL, p_lot_rec.sampling_event_id)
6100 )
6101 -- nsinghi bug#5209065. End.
6102 , attribute1 =
6103 DECODE(
6104 p_source
6105 , 2, DECODE(l_inv_attributes_tbl(1), g_miss_char, NULL, NULL, attribute1, l_inv_attributes_tbl(1))
6106 , DECODE(l_inv_attributes_tbl(1), g_miss_char, attribute1, NULL, NULL, l_inv_attributes_tbl(1))
6107 )
6108 , attribute2 =
6109 DECODE(
6110 p_source
6111 , 2, DECODE(l_inv_attributes_tbl(2), g_miss_char, NULL, NULL, attribute2, l_inv_attributes_tbl(2))
6112 , DECODE(l_inv_attributes_tbl(2), g_miss_char, attribute2, NULL, NULL, l_inv_attributes_tbl(2))
6113 )
6114 , attribute3 =
6115 DECODE(
6116 p_source
6117 , 2, DECODE(l_inv_attributes_tbl(3), g_miss_char, NULL, NULL, attribute3, l_inv_attributes_tbl(3))
6118 , DECODE(l_inv_attributes_tbl(3), g_miss_char, attribute3, NULL, NULL, l_inv_attributes_tbl(3))
6119 )
6120 , attribute4 =
6121 DECODE(
6122 p_source
6123 , 2, DECODE(l_inv_attributes_tbl(4), g_miss_char, NULL, NULL, attribute4, l_inv_attributes_tbl(4))
6124 , DECODE(l_inv_attributes_tbl(4), g_miss_char, attribute4, NULL, NULL, l_inv_attributes_tbl(4))
6125 )
6126 , attribute5 =
6127 DECODE(
6128 p_source
6129 , 2, DECODE(l_inv_attributes_tbl(5), g_miss_char, NULL, NULL, attribute5, l_inv_attributes_tbl(5))
6130 , DECODE(l_inv_attributes_tbl(5), g_miss_char, attribute5, NULL, NULL, l_inv_attributes_tbl(5))
6131 )
6132 , attribute6 =
6133 DECODE(
6134 p_source
6135 , 2, DECODE(l_inv_attributes_tbl(6), g_miss_char, NULL, NULL, attribute6, l_inv_attributes_tbl(6))
6136 , DECODE(l_inv_attributes_tbl(6), g_miss_char, attribute6, NULL, NULL, l_inv_attributes_tbl(6))
6137 )
6138 , attribute7 =
6139 DECODE(
6140 p_source
6141 , 2, DECODE(l_inv_attributes_tbl(7), g_miss_char, NULL, NULL, attribute7, l_inv_attributes_tbl(7))
6142 , DECODE(l_inv_attributes_tbl(7), g_miss_char, attribute7, NULL, NULL, l_inv_attributes_tbl(7))
6143 )
6144 , attribute8 =
6145 DECODE(
6146 p_source
6147 , 2, DECODE(l_inv_attributes_tbl(8), g_miss_char, NULL, NULL, attribute8, l_inv_attributes_tbl(8))
6148 , DECODE(l_inv_attributes_tbl(8), g_miss_char, attribute8, NULL, NULL, l_inv_attributes_tbl(8))
6149 )
6150 , attribute9 =
6151 DECODE(
6152 p_source
6153 , 2, DECODE(l_inv_attributes_tbl(9), g_miss_char, NULL, NULL, attribute9, l_inv_attributes_tbl(9))
6154 , DECODE(l_inv_attributes_tbl(9), g_miss_char, attribute9, NULL, NULL, l_inv_attributes_tbl(9))
6155 )
6156 , attribute10 =
6157 DECODE(
6158 p_source
6159 , 2, DECODE(l_inv_attributes_tbl(10), g_miss_char, NULL, NULL, attribute10, l_inv_attributes_tbl(10))
6160 , DECODE(l_inv_attributes_tbl(10), g_miss_char, attribute10, NULL, NULL, l_inv_attributes_tbl(10))
6161 )
6162 , attribute11 =
6163 DECODE(
6164 p_source
6165 , 2, DECODE(l_inv_attributes_tbl(11), g_miss_char, NULL, NULL, attribute11, l_inv_attributes_tbl(11))
6166 , DECODE(l_inv_attributes_tbl(11), g_miss_char, attribute11, NULL, NULL, l_inv_attributes_tbl(11))
6167 )
6168 , attribute12 =
6169 DECODE(
6170 p_source
6171 , 2, DECODE(l_inv_attributes_tbl(12), g_miss_char, NULL, NULL, attribute12, l_inv_attributes_tbl(12))
6172 , DECODE(l_inv_attributes_tbl(12), g_miss_char, attribute12, NULL, NULL, l_inv_attributes_tbl(12))
6173 )
6174 , attribute13 =
6175 DECODE(
6176 p_source
6177 , 2, DECODE(l_inv_attributes_tbl(13), g_miss_char, NULL, NULL, attribute13, l_inv_attributes_tbl(13))
6178 , DECODE(l_inv_attributes_tbl(13), g_miss_char, attribute13, NULL, NULL, l_inv_attributes_tbl(13))
6179 )
6180 , attribute14 =
6181 DECODE(
6182 p_source
6183 , 2, DECODE(l_inv_attributes_tbl(14), g_miss_char, NULL, NULL, attribute14, l_inv_attributes_tbl(14))
6184 , DECODE(l_inv_attributes_tbl(14), g_miss_char, attribute14, NULL, NULL, l_inv_attributes_tbl(14))
6185 )
6186 , attribute15 =
6187 DECODE(
6188 p_source
6189 , 2, DECODE(l_inv_attributes_tbl(15), g_miss_char, NULL, NULL, attribute15, l_inv_attributes_tbl(15))
6190 , DECODE(l_inv_attributes_tbl(15), g_miss_char, attribute15, NULL, NULL, l_inv_attributes_tbl(15))
6191 )
6192 , c_attribute1 =
6193 DECODE(
6194 p_source
6195 , 2, DECODE(l_c_attributes_tbl(1), g_miss_char, NULL, NULL, c_attribute1, l_c_attributes_tbl(1))
6196 , DECODE(l_c_attributes_tbl(1), g_miss_char, c_attribute1, NULL, NULL, l_c_attributes_tbl(1))
6197 )
6198 , c_attribute2 =
6199 DECODE(
6200 p_source
6201 , 2, DECODE(l_c_attributes_tbl(2), g_miss_char, NULL, NULL, c_attribute2, l_c_attributes_tbl(2))
6202 , DECODE(l_c_attributes_tbl(2), g_miss_char, c_attribute2, NULL, NULL, l_c_attributes_tbl(2))
6203 )
6204 , c_attribute3 =
6205 DECODE(
6206 p_source
6207 , 2, DECODE(l_c_attributes_tbl(3), g_miss_char, NULL, NULL, c_attribute3, l_c_attributes_tbl(3))
6208 , DECODE(l_c_attributes_tbl(3), g_miss_char, c_attribute3, NULL, NULL, l_c_attributes_tbl(3))
6209 )
6210 , c_attribute4 =
6211 DECODE(
6212 p_source
6213 , 2, DECODE(l_c_attributes_tbl(4), g_miss_char, NULL, NULL, c_attribute4, l_c_attributes_tbl(4))
6214 , DECODE(l_c_attributes_tbl(4), g_miss_char, c_attribute4, NULL, NULL, l_c_attributes_tbl(4))
6215 )
6216 , c_attribute5 =
6217 DECODE(
6218 p_source
6219 , 2, DECODE(l_c_attributes_tbl(5), g_miss_char, NULL, NULL, c_attribute5, l_c_attributes_tbl(5))
6220 , DECODE(l_c_attributes_tbl(5), g_miss_char, c_attribute5, NULL, NULL, l_c_attributes_tbl(5))
6221 )
6222 , c_attribute6 =
6223 DECODE(
6224 p_source
6225 , 2, DECODE(l_c_attributes_tbl(6), g_miss_char, NULL, NULL, c_attribute6, l_c_attributes_tbl(6))
6226 , DECODE(l_c_attributes_tbl(6), g_miss_char, c_attribute6, NULL, NULL, l_c_attributes_tbl(6))
6227 )
6228 , c_attribute7 =
6229 DECODE(
6230 p_source
6231 , 2, DECODE(l_c_attributes_tbl(7), g_miss_char, NULL, NULL, c_attribute7, l_c_attributes_tbl(7))
6232 , DECODE(l_c_attributes_tbl(7), g_miss_char, c_attribute7, NULL, NULL, l_c_attributes_tbl(7))
6233 )
6234 , c_attribute8 =
6235 DECODE(
6236 p_source
6237 , 2, DECODE(l_c_attributes_tbl(8), g_miss_char, NULL, NULL, c_attribute8, l_c_attributes_tbl(8))
6238 , DECODE(l_c_attributes_tbl(8), g_miss_char, c_attribute8, NULL, NULL, l_c_attributes_tbl(8))
6239 )
6240 , c_attribute9 =
6241 DECODE(
6242 p_source
6243 , 2, DECODE(l_c_attributes_tbl(9), g_miss_char, NULL, NULL, c_attribute9, l_c_attributes_tbl(9))
6244 , DECODE(l_c_attributes_tbl(9), g_miss_char, c_attribute9, NULL, NULL, l_c_attributes_tbl(9))
6245 )
6246 , c_attribute10 =
6247 DECODE(
6248 p_source
6249 , 2, DECODE(l_c_attributes_tbl(10), g_miss_char, NULL, NULL, c_attribute10, l_c_attributes_tbl(10))
6250 , DECODE(l_c_attributes_tbl(10), g_miss_char, c_attribute10, NULL, NULL, l_c_attributes_tbl(10))
6251 )
6252 , c_attribute11 =
6253 DECODE(
6254 p_source
6255 , 2, DECODE(l_c_attributes_tbl(11), g_miss_char, NULL, NULL, c_attribute11, l_c_attributes_tbl(11))
6256 , DECODE(l_c_attributes_tbl(11), g_miss_char, c_attribute11, NULL, NULL, l_c_attributes_tbl(11))
6257 )
6258 , c_attribute12 =
6259 DECODE(
6260 p_source
6261 , 2, DECODE(l_c_attributes_tbl(12), g_miss_char, NULL, NULL, c_attribute12, l_c_attributes_tbl(12))
6262 , DECODE(l_c_attributes_tbl(12), g_miss_char, c_attribute12, NULL, NULL, l_c_attributes_tbl(12))
6263 )
6264 , c_attribute13 =
6265 DECODE(
6266 p_source
6267 , 2, DECODE(l_c_attributes_tbl(13), g_miss_char, NULL, NULL, c_attribute13, l_c_attributes_tbl(13))
6268 , DECODE(l_c_attributes_tbl(13), g_miss_char, c_attribute13, NULL, NULL, l_c_attributes_tbl(13))
6269 )
6270 , c_attribute14 =
6271 DECODE(
6272 p_source
6273 , 2, DECODE(l_c_attributes_tbl(14), g_miss_char, NULL, NULL, c_attribute14, l_c_attributes_tbl(14))
6274 , DECODE(l_c_attributes_tbl(14), g_miss_char, c_attribute14, NULL, NULL, l_c_attributes_tbl(14))
6275 )
6276 , c_attribute15 =
6277 DECODE(
6278 p_source
6279 , 2, DECODE(l_c_attributes_tbl(15), g_miss_char, NULL, NULL, c_attribute15, l_c_attributes_tbl(15))
6280 , DECODE(l_c_attributes_tbl(15), g_miss_char, c_attribute15, NULL, NULL, l_c_attributes_tbl(15))
6281 )
6282 , c_attribute16 =
6283 DECODE(
6284 p_source
6285 , 2, DECODE(l_c_attributes_tbl(16), g_miss_char, NULL, NULL, c_attribute16, l_c_attributes_tbl(16))
6286 , DECODE(l_c_attributes_tbl(16), g_miss_char, c_attribute16, NULL, NULL, l_c_attributes_tbl(16))
6287 )
6288 , c_attribute17 =
6289 DECODE(
6290 p_source
6291 , 2, DECODE(l_c_attributes_tbl(17), g_miss_char, NULL, NULL, c_attribute17, l_c_attributes_tbl(17))
6292 , DECODE(l_c_attributes_tbl(17), g_miss_char, c_attribute17, NULL, NULL, l_c_attributes_tbl(17))
6293 )
6294 , c_attribute18 =
6295 DECODE(
6296 p_source
6297 , 2, DECODE(l_c_attributes_tbl(18), g_miss_char, NULL, NULL, c_attribute18, l_c_attributes_tbl(18))
6298 , DECODE(l_c_attributes_tbl(18), g_miss_char, c_attribute18, NULL, NULL, l_c_attributes_tbl(18))
6299 )
6300 , c_attribute19 =
6301 DECODE(
6302 p_source
6303 , 2, DECODE(l_c_attributes_tbl(19), g_miss_char, NULL, NULL, c_attribute19, l_c_attributes_tbl(19))
6304 , DECODE(l_c_attributes_tbl(19), g_miss_char, c_attribute19, NULL, NULL, l_c_attributes_tbl(19))
6305 )
6306 , c_attribute20 =
6307 DECODE(
6308 p_source
6309 , 2, DECODE(l_c_attributes_tbl(20), g_miss_char, NULL, NULL, c_attribute20, l_c_attributes_tbl(20))
6310 , DECODE(l_c_attributes_tbl(20), g_miss_char, c_attribute20, NULL, NULL, l_c_attributes_tbl(20))
6311 )
6312 , n_attribute1 =
6313 DECODE(
6314 p_source
6315 , 2, DECODE(l_n_attributes_tbl(1), g_miss_num, NULL, NULL, n_attribute1, l_n_attributes_tbl(1))
6316 , DECODE(l_n_attributes_tbl(1), g_miss_num, n_attribute1, NULL, NULL, l_n_attributes_tbl(1))
6317 )
6318 , n_attribute2 =
6319 DECODE(
6320 p_source
6321 , 2, DECODE(l_n_attributes_tbl(2), g_miss_num, NULL, NULL, n_attribute2, l_n_attributes_tbl(2))
6322 , DECODE(l_n_attributes_tbl(2), g_miss_num, n_attribute2, NULL, NULL, l_n_attributes_tbl(2))
6323 )
6324 , n_attribute3 =
6325 DECODE(
6326 p_source
6327 , 2, DECODE(l_n_attributes_tbl(3), g_miss_num, NULL, NULL, n_attribute3, l_n_attributes_tbl(3))
6328 , DECODE(l_n_attributes_tbl(3), g_miss_num, n_attribute3, NULL, NULL, l_n_attributes_tbl(3))
6329 )
6330 , n_attribute4 =
6331 DECODE(
6332 p_source
6333 , 2, DECODE(l_n_attributes_tbl(4), g_miss_num, NULL, NULL, n_attribute4, l_n_attributes_tbl(4))
6334 , DECODE(l_n_attributes_tbl(4), g_miss_num, n_attribute4, NULL, NULL, l_n_attributes_tbl(4))
6335 )
6336 , n_attribute5 =
6337 DECODE(
6338 p_source
6339 , 2, DECODE(l_n_attributes_tbl(5), g_miss_num, NULL, NULL, n_attribute5, l_n_attributes_tbl(5))
6340 , DECODE(l_n_attributes_tbl(5), g_miss_num, n_attribute5, NULL, NULL, l_n_attributes_tbl(5))
6341 )
6342 , n_attribute6 =
6343 DECODE(
6344 p_source
6345 , 2, DECODE(l_n_attributes_tbl(6), g_miss_num, NULL, NULL, n_attribute6, l_n_attributes_tbl(6))
6346 , DECODE(l_n_attributes_tbl(6), g_miss_num, n_attribute6, NULL, NULL, l_n_attributes_tbl(6))
6347 )
6348 , n_attribute7 =
6349 DECODE(
6350 p_source
6351 , 2, DECODE(l_n_attributes_tbl(7), g_miss_num, NULL, NULL, n_attribute7, l_n_attributes_tbl(7))
6352 , DECODE(l_n_attributes_tbl(7), g_miss_num, n_attribute7, NULL, NULL, l_n_attributes_tbl(7))
6353 )
6354 , n_attribute8 =
6355 DECODE(
6356 p_source
6357 , 2, DECODE(l_n_attributes_tbl(8), g_miss_num, NULL, NULL, n_attribute8, l_n_attributes_tbl(8))
6358 , DECODE(l_n_attributes_tbl(8), g_miss_num, n_attribute8, NULL, NULL, l_n_attributes_tbl(8))
6359 )
6360 , n_attribute9 =
6361 DECODE(
6362 p_source
6363 , 2, DECODE(l_n_attributes_tbl(9), g_miss_num, NULL, NULL, n_attribute9, l_n_attributes_tbl(9))
6364 , DECODE(l_n_attributes_tbl(9), g_miss_num, n_attribute9, NULL, NULL, l_n_attributes_tbl(9))
6365 )
6366 , n_attribute10 =
6367 DECODE(
6368 p_source
6369 , 2, DECODE(l_n_attributes_tbl(10), g_miss_num, NULL, NULL, n_attribute10, l_n_attributes_tbl(10))
6370 , DECODE(l_n_attributes_tbl(10), g_miss_num, n_attribute10, NULL, NULL, l_n_attributes_tbl(10))
6371 )
6372 , d_attribute1 =
6373 DECODE(
6374 p_source
6375 , 2, DECODE(l_d_attributes_tbl(1), g_miss_date, NULL, NULL, d_attribute1, l_d_attributes_tbl(1))
6376 , DECODE(l_d_attributes_tbl(1), g_miss_date, d_attribute1, NULL, NULL, l_d_attributes_tbl(1))
6377 )
6378 , d_attribute2 =
6379 DECODE(
6380 p_source
6381 , 2, DECODE(l_d_attributes_tbl(2), g_miss_date, NULL, NULL, d_attribute2, l_d_attributes_tbl(2))
6382 , DECODE(l_d_attributes_tbl(2), g_miss_date, d_attribute2, NULL, NULL, l_d_attributes_tbl(2))
6383 )
6384 , d_attribute3 =
6385 DECODE(
6386 p_source
6387 , 2, DECODE(l_d_attributes_tbl(3), g_miss_date, NULL, NULL, d_attribute3, l_d_attributes_tbl(3))
6388 , DECODE(l_d_attributes_tbl(3), g_miss_date, d_attribute3, NULL, NULL, l_d_attributes_tbl(3))
6389 )
6390 , d_attribute4 =
6391 DECODE(
6392 p_source
6393 , 2, DECODE(l_d_attributes_tbl(4), g_miss_date, NULL, NULL, d_attribute4, l_d_attributes_tbl(4))
6394 , DECODE(l_d_attributes_tbl(4), g_miss_date, d_attribute4, NULL, NULL, l_d_attributes_tbl(4))
6395 )
6396 , d_attribute5 =
6397 DECODE(
6398 p_source
6399 , 2, DECODE(l_d_attributes_tbl(5), g_miss_date, NULL, NULL, d_attribute5, l_d_attributes_tbl(5))
6400 , DECODE(l_d_attributes_tbl(5), g_miss_date, d_attribute5, NULL, NULL, l_d_attributes_tbl(5))
6401 )
6402 , d_attribute6 =
6403 DECODE(
6404 p_source
6405 , 2, DECODE(l_d_attributes_tbl(6), g_miss_date, NULL, NULL, d_attribute6, l_d_attributes_tbl(6))
6406 , DECODE(l_d_attributes_tbl(6), g_miss_date, d_attribute6, NULL, NULL, l_d_attributes_tbl(6))
6407 )
6408 , d_attribute7 =
6409 DECODE(
6410 p_source
6411 , 2, DECODE(l_d_attributes_tbl(7), g_miss_date, NULL, NULL, d_attribute7, l_d_attributes_tbl(7))
6412 , DECODE(l_d_attributes_tbl(7), g_miss_date, d_attribute7, NULL, NULL, l_d_attributes_tbl(7))
6413 )
6414 , d_attribute8 =
6415 DECODE(
6416 p_source
6417 , 2, DECODE(l_d_attributes_tbl(8), g_miss_date, NULL, NULL, d_attribute8, l_d_attributes_tbl(8))
6418 , DECODE(l_d_attributes_tbl(8), g_miss_date, d_attribute8, NULL, NULL, l_d_attributes_tbl(8))
6419 )
6420 , d_attribute9 =
6421 DECODE(
6422 p_source
6423 , 2, DECODE(l_d_attributes_tbl(9), g_miss_date, NULL, NULL, d_attribute9, l_d_attributes_tbl(9))
6424 , DECODE(l_d_attributes_tbl(9), g_miss_date, d_attribute9, NULL, NULL, l_d_attributes_tbl(9))
6425 )
6426 , d_attribute10 =
6427 DECODE(
6428 p_source
6429 , 2, DECODE(l_d_attributes_tbl(10), g_miss_date, NULL, NULL, d_attribute10, l_d_attributes_tbl(10))
6430 , DECODE(l_d_attributes_tbl(10), g_miss_date, d_attribute10, NULL, NULL, l_d_attributes_tbl(10))
6431 )
6432 ,LAST_UPDATE_DATE = sysdate
6433 ,LAST_UPDATED_BY = fnd_global.user_id
6434 WHERE inventory_item_id = p_lot_rec.inventory_item_id
6435 AND organization_id = p_lot_rec.organization_id
6436 AND lot_number = p_lot_rec.lot_number;
6437 ELSE
6438 UPDATE mtl_lot_numbers
6439 SET expiration_date =
6440 DECODE(l_expiration_date, NULL, expiration_date, l_expiration_date )
6441 , disable_flag =
6442 DECODE(
6443 p_source
6444 , 2, DECODE(p_lot_rec.disable_flag, g_miss_num, NULL, NULL, disable_flag, p_lot_rec.disable_flag) /*Bug 14835444 changed g_miss_char to g_miss_num */
6445 , DECODE(p_lot_rec.disable_flag, g_miss_num, disable_flag, NULL, NULL, p_lot_rec.disable_flag)
6446 )
6447 , attribute_category =
6448 DECODE(
6449 p_source
6450 , 2, DECODE(p_lot_rec.attribute_category, g_miss_char, NULL, NULL, attribute_category, p_lot_rec.attribute_category)
6451 , DECODE(p_lot_rec.attribute_category, g_miss_char, attribute_category, NULL, NULL, p_lot_rec.attribute_category)
6452 )
6453 , lot_attribute_category =
6454 DECODE(
6455 p_source
6456 , 2, DECODE(p_lot_rec.lot_attribute_category, g_miss_char, NULL, NULL, lot_attribute_category, p_lot_rec.lot_attribute_category)
6457 , DECODE(p_lot_rec.lot_attribute_category, g_miss_char, lot_attribute_category, NULL, NULL, p_lot_rec.lot_attribute_category)
6458 )
6459 /*, grade_code =
6460 DECODE(
6461 p_source
6462 , 2, DECODE(p_lot_rec.grade_code, g_miss_char, NULL, NULL, grade_code, p_lot_rec.grade_code)
6463 , DECODE(p_lot_rec.grade_code, g_miss_char, grade_code, NULL, NULL, p_lot_rec.grade_code)
6464 )*/ -- Commented for bug 13780398
6465 , origination_date =
6466 DECODE(
6467 p_source
6468 , 2, DECODE(p_lot_rec.origination_date, g_miss_date, To_Date(NULL), NULL, origination_date, p_lot_rec.origination_date)
6469 , DECODE(p_lot_rec.origination_date, g_miss_date, origination_date, NULL, To_Date(NULL), p_lot_rec.origination_date)
6470 )
6471 , date_code =
6472 DECODE(
6473 p_source
6474 , 2, DECODE(p_lot_rec.date_code, g_miss_char, NULL, NULL, date_code, p_lot_rec.date_code)
6475 , DECODE(p_lot_rec.date_code, g_miss_char, date_code, NULL, NULL, p_lot_rec.date_code)
6476 )
6477 /* Bug 8198497 - Removed the code as we are updating the status by calling validate_lot_status */
6478 , change_date =
6479 DECODE(
6480 p_source
6481 , 2, DECODE(p_lot_rec.change_date, g_miss_date, To_Date(NULL), NULL, change_date, p_lot_rec.change_date)
6482 , DECODE(p_lot_rec.change_date, g_miss_date, change_date, NULL, To_Date(NULL), p_lot_rec.change_date)
6483 )
6484 , age = DECODE(
6485 p_source
6486 , 2, DECODE(p_lot_rec.age, g_miss_num, NULL, NULL, age, p_lot_rec.age)
6487 , DECODE(p_lot_rec.age, g_miss_num, age, NULL, NULL, p_lot_rec.age)
6488 )
6489 , retest_date =
6490 DECODE(
6491 p_source
6492 , 2, DECODE(p_lot_rec.retest_date, g_miss_date, To_Date(NULL), NULL, retest_date, p_lot_rec.retest_date)
6493 , DECODE(p_lot_rec.retest_date, g_miss_date, retest_date, NULL, To_Date(NULL), p_lot_rec.retest_date)
6494 )
6495 , maturity_date =
6496 DECODE(
6497 p_source
6498 , 2, DECODE(p_lot_rec.maturity_date, g_miss_date, To_Date(NULL), NULL, maturity_date, p_lot_rec.maturity_date)
6499 , DECODE(p_lot_rec.maturity_date, g_miss_date, maturity_date, NULL, To_Date(NULL), p_lot_rec.maturity_date)
6500 )
6501 , item_size =
6502 DECODE(
6503 p_source
6504 , 2, DECODE(p_lot_rec.item_size, g_miss_num, NULL, NULL, item_size, p_lot_rec.item_size)
6505 , DECODE(p_lot_rec.item_size, g_miss_num, item_size, NULL, NULL, p_lot_rec.item_size)
6506 )
6507 , color =
6508 DECODE(
6509 p_source
6510 , 2, DECODE(p_lot_rec.color, g_miss_char, NULL, NULL, color, p_lot_rec.color)
6511 , DECODE(p_lot_rec.color, g_miss_char, color, NULL, NULL, p_lot_rec.color)
6512 )
6513 , volume =
6514 DECODE(
6515 p_source
6516 , 2, DECODE(p_lot_rec.volume, g_miss_num, NULL, NULL, volume, p_lot_rec.volume)
6517 , DECODE(p_lot_rec.volume, g_miss_num, volume, NULL, NULL, p_lot_rec.volume)
6518 )
6519 , volume_uom =
6520 DECODE(
6521 p_source
6522 , 2, DECODE(p_lot_rec.volume_uom, g_miss_char, NULL, NULL, volume_uom, p_lot_rec.volume_uom)
6523 , DECODE(p_lot_rec.volume_uom, g_miss_char, volume_uom, NULL, NULL, p_lot_rec.volume_uom)
6524 )
6525 , place_of_origin =
6526 DECODE(
6527 p_source
6528 , 2, DECODE(p_lot_rec.place_of_origin, g_miss_char, NULL, NULL, place_of_origin, p_lot_rec.place_of_origin)
6529 , DECODE(p_lot_rec.place_of_origin, g_miss_char, place_of_origin, NULL, place_of_origin, p_lot_rec.place_of_origin)
6530 )
6531 , best_by_date =
6532 DECODE(
6533 p_source
6534 , 2, DECODE(p_lot_rec.best_by_date, g_miss_date, To_Date(NULL), NULL, best_by_date, p_lot_rec.best_by_date)
6535 , DECODE(p_lot_rec.best_by_date, g_miss_date, best_by_date, NULL, To_Date(NULL), p_lot_rec.best_by_date)
6536 )
6537 , LENGTH =
6538 DECODE(
6539 p_source
6540 , 2, DECODE(p_lot_rec.length, g_miss_num, NULL, NULL, LENGTH, p_lot_rec.length)
6541 , DECODE(p_lot_rec.length, g_miss_num, LENGTH, NULL, NULL, p_lot_rec.length)
6542 )
6543 , length_uom =
6544 DECODE(
6545 p_source
6546 , 2, DECODE(p_lot_rec.length_uom, g_miss_char, NULL, NULL, length_uom, p_lot_rec.length_uom)
6547 , DECODE(p_lot_rec.length_uom, g_miss_char, length_uom, NULL, NULL, p_lot_rec.length_uom)
6548 )
6549 , recycled_content =
6550 DECODE(
6551 p_source
6552 , 2, DECODE(p_lot_rec.recycled_content, g_miss_num, NULL, NULL, recycled_content, p_lot_rec.recycled_content)
6553 , DECODE(p_lot_rec.recycled_content, g_miss_num, recycled_content, NULL, NULL, p_lot_rec.recycled_content)
6554 )
6555 , thickness =
6556 DECODE(
6557 p_source
6558 , 2, DECODE(p_lot_rec.thickness, g_miss_num, NULL, NULL, thickness, p_lot_rec.thickness)
6559 , DECODE(p_lot_rec.thickness, g_miss_num, thickness, NULL, NULL, p_lot_rec.thickness)
6560 )
6561 , thickness_uom =
6562 DECODE(
6563 p_source
6564 , 2, DECODE(p_lot_rec.thickness_uom, g_miss_char, NULL, NULL, thickness_uom, p_lot_rec.thickness_uom)
6565 , DECODE(p_lot_rec.thickness_uom, g_miss_char, thickness_uom, NULL, NULL, p_lot_rec.thickness_uom)
6566 )
6567 , width =
6568 DECODE(
6569 p_source
6570 , 2, DECODE(p_lot_rec.width, g_miss_num, NULL, NULL, width, p_lot_rec.width)
6571 , DECODE(p_lot_rec.width, g_miss_num, width, NULL, NULL, p_lot_rec.width)
6572 )
6573 , width_uom =
6574 DECODE(
6575 p_source
6576 , 2, DECODE(p_lot_rec.width_uom, g_miss_char, NULL, NULL, width_uom, p_lot_rec.width_uom)
6577 , DECODE(p_lot_rec.width_uom, g_miss_char, width_uom, NULL, NULL, p_lot_rec.width_uom)
6578 )
6579 , territory_code =
6580 DECODE(
6581 p_source
6582 , 2, DECODE(p_lot_rec.territory_code, g_miss_char, NULL, NULL, territory_code, p_lot_rec.territory_code)
6583 , DECODE(p_lot_rec.territory_code, g_miss_char, territory_code, NULL, NULL, p_lot_rec.territory_code)
6584 )
6585 , supplier_lot_number =
6586 DECODE(
6587 p_source
6588 , 2, DECODE(p_lot_rec.supplier_lot_number, g_miss_char, NULL, NULL, supplier_lot_number, p_lot_rec.supplier_lot_number)
6589 , DECODE(p_lot_rec.supplier_lot_number, g_miss_char, supplier_lot_number, NULL, NULL, p_lot_rec.supplier_lot_number)
6590 )
6591 -- Bug 6983527 - Parent lot number should never be updated.
6592 /*Bug 8311729 Uncommenting the below code as we should be able to
6593 update the mistakenly entered parent lot information */
6594 -- nsinghi bug#5209065. Update new lot attributes
6595 , parent_lot_number =
6596 DECODE(
6597 p_source
6598 , 2, DECODE(p_lot_rec.parent_lot_number, g_miss_char, NULL, NULL, parent_lot_number, p_lot_rec.parent_lot_number)
6599 , DECODE(p_lot_rec.parent_lot_number, g_miss_char, parent_lot_number, NULL, NULL, p_lot_rec.parent_lot_number)
6600 )
6601
6602 -- Bug 13553990 keeping the value of columns without getting updated to NULL which are not passed.
6603 , origination_type =
6604 DECODE(
6605 p_source
6606 , 2, DECODE(p_lot_rec.origination_type, g_miss_num, NULL, NULL, origination_type, p_lot_rec.origination_type)
6607 , DECODE(p_lot_rec.origination_type, -99, origination_type, g_miss_num, origination_type, NULL, NULL, p_lot_rec.origination_type)
6608 )
6609 , availability_type =
6610 DECODE(
6611 p_source
6612 , 2, DECODE(p_lot_rec.availability_type, g_miss_num, NULL, NULL, availability_type, p_lot_rec.availability_type)
6613 , DECODE(p_lot_rec.availability_type, g_miss_num, availability_type, NULL, NULL, p_lot_rec.availability_type)
6614 )
6615 , expiration_action_code =
6616 DECODE(
6617 p_source
6618 , 2, DECODE(p_lot_rec.expiration_action_code, g_miss_char, NULL, NULL, expiration_action_code, p_lot_rec.expiration_action_code)
6619 , DECODE(p_lot_rec.expiration_action_code, g_miss_char, expiration_action_code, NULL, NULL, p_lot_rec.expiration_action_code)
6620 )
6621 , expiration_action_date =
6622 DECODE(
6623 p_source
6624 , 2, DECODE(p_lot_rec.expiration_action_date, g_miss_date, To_Date(NULL), NULL, expiration_action_date, p_lot_rec.expiration_action_date)
6625 , DECODE(p_lot_rec.expiration_action_date, g_miss_date, expiration_action_date, NULL, To_Date(NULL), p_lot_rec.expiration_action_date)
6626 )
6627 , hold_date =
6628 DECODE(
6629 p_source
6630 , 2, DECODE(p_lot_rec.hold_date, g_miss_date, To_Date(NULL), NULL, hold_date, p_lot_rec.hold_date)
6631 , DECODE(p_lot_rec.hold_date, g_miss_date, hold_date, NULL, To_Date(NULL), p_lot_rec.hold_date)
6632 )
6633 , inventory_atp_code =
6634 DECODE(
6635 p_source
6636 , 2, DECODE(p_lot_rec.inventory_atp_code, g_miss_num, NULL, NULL, inventory_atp_code, p_lot_rec.inventory_atp_code)
6637 , DECODE(p_lot_rec.inventory_atp_code, g_miss_num, inventory_atp_code, NULL, NULL, p_lot_rec.inventory_atp_code)
6638 )
6639 , reservable_type =
6640 DECODE(
6641 p_source
6642 , 2, DECODE(p_lot_rec.reservable_type, g_miss_num, NULL, NULL, reservable_type, p_lot_rec.reservable_type)
6643 , DECODE(p_lot_rec.reservable_type, g_miss_num, reservable_type, NULL, NULL, p_lot_rec.reservable_type)
6644 )
6645 , sampling_event_id =
6646 DECODE(
6647 p_source
6648 , 2, DECODE(p_lot_rec.sampling_event_id, g_miss_num, NULL, NULL, sampling_event_id, p_lot_rec.sampling_event_id)
6649 , DECODE(p_lot_rec.sampling_event_id, g_miss_num, sampling_event_id, NULL, NULL, p_lot_rec.sampling_event_id)
6650 )
6651 -- nsinghi bug#5209065. End.
6652 , vendor_name =
6653 DECODE(
6654 p_source
6655 , 2, DECODE(p_lot_rec.vendor_name, g_miss_char, NULL, NULL, vendor_name, p_lot_rec.vendor_name)
6656 , DECODE(p_lot_rec.vendor_name, g_miss_char, vendor_name, NULL, NULL, p_lot_rec.vendor_name)
6657 )
6658 , attribute1 =
6659 DECODE(
6660 p_source
6661 , 2, DECODE(l_inv_attributes_tbl(1), g_miss_char, NULL, NULL, attribute1, l_inv_attributes_tbl(1))
6662 , DECODE(l_inv_attributes_tbl(1), g_miss_char, attribute1, NULL, NULL, l_inv_attributes_tbl(1))
6663 )
6664 , attribute2 =
6665 DECODE(
6666 p_source
6667 , 2, DECODE(l_inv_attributes_tbl(2), g_miss_char, NULL, NULL, attribute2, l_inv_attributes_tbl(2))
6668 , DECODE(l_inv_attributes_tbl(2), g_miss_char, attribute2, NULL, NULL, l_inv_attributes_tbl(2))
6669 )
6670 , attribute3 =
6671 DECODE(
6672 p_source
6673 , 2, DECODE(l_inv_attributes_tbl(3), g_miss_char, NULL, NULL, attribute3, l_inv_attributes_tbl(3))
6674 , DECODE(l_inv_attributes_tbl(3), g_miss_char, attribute3, NULL, NULL, l_inv_attributes_tbl(3))
6675 )
6676 , attribute4 =
6677 DECODE(
6678 p_source
6679 , 2, DECODE(l_inv_attributes_tbl(4), g_miss_char, NULL, NULL, attribute4, l_inv_attributes_tbl(4))
6680 , DECODE(l_inv_attributes_tbl(4), g_miss_char, attribute4, NULL, NULL, l_inv_attributes_tbl(4))
6681 )
6682 , attribute5 =
6683 DECODE(
6684 p_source
6685 , 2, DECODE(l_inv_attributes_tbl(5), g_miss_char, NULL, NULL, attribute5, l_inv_attributes_tbl(5))
6686 , DECODE(l_inv_attributes_tbl(5), g_miss_char, attribute5, NULL, NULL, l_inv_attributes_tbl(5))
6687 )
6688 , attribute6 =
6689 DECODE(
6690 p_source
6691 , 2, DECODE(l_inv_attributes_tbl(6), g_miss_char, NULL, NULL, attribute6, l_inv_attributes_tbl(6))
6692 , DECODE(l_inv_attributes_tbl(6), g_miss_char, attribute6, NULL, NULL, l_inv_attributes_tbl(6))
6693 )
6694 , attribute7 =
6695 DECODE(
6696 p_source
6697 , 2, DECODE(l_inv_attributes_tbl(7), g_miss_char, NULL, NULL, attribute7, l_inv_attributes_tbl(7))
6698 , DECODE(l_inv_attributes_tbl(7), g_miss_char, attribute7, NULL, NULL, l_inv_attributes_tbl(7))
6699 )
6700 , attribute8 =
6701 DECODE(
6702 p_source
6703 , 2, DECODE(l_inv_attributes_tbl(8), g_miss_char, NULL, NULL, attribute8, l_inv_attributes_tbl(8))
6704 , DECODE(l_inv_attributes_tbl(8), g_miss_char, attribute8, NULL, NULL, l_inv_attributes_tbl(8))
6705 )
6706 , attribute9 =
6707 DECODE(
6708 p_source
6709 , 2, DECODE(l_inv_attributes_tbl(9), g_miss_char, NULL, NULL, attribute9, l_inv_attributes_tbl(9))
6710 , DECODE(l_inv_attributes_tbl(9), g_miss_char, attribute9, NULL, NULL, l_inv_attributes_tbl(9))
6711 )
6712 , attribute10 =
6713 DECODE(
6714 p_source
6715 , 2, DECODE(l_inv_attributes_tbl(10), g_miss_char, NULL, NULL, attribute10, l_inv_attributes_tbl(10))
6716 , DECODE(l_inv_attributes_tbl(10), g_miss_char, attribute10, NULL, NULL, l_inv_attributes_tbl(10))
6717 )
6718 , attribute11 =
6719 DECODE(
6720 p_source
6721 , 2, DECODE(l_inv_attributes_tbl(11), g_miss_char, NULL, NULL, attribute11, l_inv_attributes_tbl(11))
6722 , DECODE(l_inv_attributes_tbl(11), g_miss_char, attribute11, NULL, NULL, l_inv_attributes_tbl(11))
6723 )
6724 , attribute12 =
6725 DECODE(
6726 p_source
6727 , 2, DECODE(l_inv_attributes_tbl(12), g_miss_char, NULL, NULL, attribute12, l_inv_attributes_tbl(12))
6728 , DECODE(l_inv_attributes_tbl(12), g_miss_char, attribute12, NULL, NULL, l_inv_attributes_tbl(12))
6729 )
6730 , attribute13 =
6731 DECODE(
6732 p_source
6733 , 2, DECODE(l_inv_attributes_tbl(13), g_miss_char, NULL, NULL, attribute13, l_inv_attributes_tbl(13))
6734 , DECODE(l_inv_attributes_tbl(13), g_miss_char, attribute13, NULL, NULL, l_inv_attributes_tbl(13))
6735 )
6736 , attribute14 =
6737 DECODE(
6738 p_source
6739 , 2, DECODE(l_inv_attributes_tbl(14), g_miss_char, NULL, NULL, attribute14, l_inv_attributes_tbl(14))
6740 , DECODE(l_inv_attributes_tbl(14), g_miss_char, attribute14, NULL, NULL, l_inv_attributes_tbl(14))
6741 )
6742 , attribute15 =
6743 DECODE(
6744 p_source
6745 , 2, DECODE(l_inv_attributes_tbl(15), g_miss_char, NULL, NULL, attribute15, l_inv_attributes_tbl(15))
6746 , DECODE(l_inv_attributes_tbl(15), g_miss_char, attribute15, NULL, NULL, l_inv_attributes_tbl(15))
6747 )
6748 /*, c_attribute1 = decode(p_source, 2,
6749 DECODE(l_c_attributes_tbl(1), g_miss_char, NULL, NULL, c_attribute1, l_c_attributes_tbl(1))
6750 ,DECODE(l_c_attributes_tbl(1), g_miss_char, c_attribute1, NULL, null, l_c_attributes_tbl(1)))
6751 , c_attribute2 = decode(p_source, 2,
6752 DECODE(l_c_attributes_tbl(2), g_miss_char, NULL, NULL, c_attribute2, l_c_attributes_tbl(2))
6753 ,DECODE(l_c_attributes_tbl(2), g_miss_char, c_attribute2, NULL, null, l_c_attributes_tbl(2)))
6754 , c_attribute3 = decode(p_source, 2,
6755 DECODE(l_c_attributes_tbl(3), g_miss_char, NULL, NULL, c_attribute3, l_c_attributes_tbl(3))
6756 ,DECODE(l_c_attributes_tbl(3), g_miss_char, c_attribute3, NULL, null, l_c_attributes_tbl(3)))
6757 , c_attribute4 = decode(p_source, 2,
6758 DECODE(l_c_attributes_tbl(4), g_miss_char, NULL, NULL, c_attribute4, l_c_attributes_tbl(4))
6759 ,DECODE(l_c_attributes_tbl(4), g_miss_char, c_attribute4, NULL, null, l_c_attributes_tbl(4)))
6760 , c_attribute5 = decode(p_source, 2,
6761 DECODE(l_c_attributes_tbl(5), g_miss_char, NULL, NULL, c_attribute5, l_c_attributes_tbl(5))
6762 ,DECODE(l_c_attributes_tbl(5), g_miss_char, c_attribute5, NULL, null, l_c_attributes_tbl(5)))
6763 , c_attribute6 = decode(p_source, 2,
6764 DECODE(l_c_attributes_tbl(6), g_miss_char, NULL, NULL, c_attribute6, l_c_attributes_tbl(6))
6765 ,DECODE(l_c_attributes_tbl(6), g_miss_char, c_attribute6, NULL, null, l_c_attributes_tbl(6)))
6766 , c_attribute7 = decode(p_source, 2,
6767 DECODE(l_c_attributes_tbl(7), g_miss_char, NULL, NULL, c_attribute7, l_c_attributes_tbl(7))
6768 ,DECODE(l_c_attributes_tbl(7), g_miss_char, c_attribute7, NULL, null, l_c_attributes_tbl(7)))
6769 , c_attribute8 = decode(p_source, 2,
6770 DECODE(l_c_attributes_tbl(8), g_miss_char, NULL, NULL, c_attribute8, l_c_attributes_tbl(8))
6771 ,DECODE(l_c_attributes_tbl(8), g_miss_char, c_attribute8, NULL, null, l_c_attributes_tbl(8)))
6772 , c_attribute9 = decode(p_source, 2,
6773 DECODE(l_c_attributes_tbl(9), g_miss_char, NULL, NULL, c_attribute9, l_c_attributes_tbl(9))
6774 ,DECODE(l_c_attributes_tbl(9), g_miss_char, c_attribute9, NULL, null, l_c_attributes_tbl(9)))
6775 , c_attribute10 = decode(p_source, 2,
6776 DECODE(l_c_attributes_tbl(10), g_miss_char, NULL, NULL, c_attribute10, l_c_attributes_tbl(10))
6777 ,DECODE(l_c_attributes_tbl(10), g_miss_char, c_attribute10, NULL, null, l_c_attributes_tbl(10)))
6778 , c_attribute11 = decode(p_source, 2,
6779 DECODE(l_c_attributes_tbl(11), g_miss_char, NULL, NULL, c_attribute11, l_c_attributes_tbl(11))
6780 ,DECODE(l_c_attributes_tbl(11), g_miss_char, c_attribute11, NULL, null, l_c_attributes_tbl(11)))
6781 , c_attribute12 = decode(p_source, 2,
6782 DECODE(l_c_attributes_tbl(12), g_miss_char, NULL, NULL, c_attribute12, l_c_attributes_tbl(12))
6783 ,DECODE(l_c_attributes_tbl(12), g_miss_char, c_attribute12, NULL, null, l_c_attributes_tbl(12)))
6784 , c_attribute13 = decode(p_source, 2,
6785 DECODE(l_c_attributes_tbl(13), g_miss_char, NULL, NULL, c_attribute13, l_c_attributes_tbl(13))
6786 ,DECODE(l_c_attributes_tbl(13), g_miss_char, c_attribute13, NULL, null, l_c_attributes_tbl(13)))
6787 , c_attribute14 = decode(p_source, 2,
6788 DECODE(l_c_attributes_tbl(14), g_miss_char, NULL, NULL, c_attribute14, l_c_attributes_tbl(14))
6789 ,DECODE(l_c_attributes_tbl(14), g_miss_char, c_attribute14, NULL, null, l_c_attributes_tbl(14)))
6790 , c_attribute15 = decode(p_source, 2,
6791 DECODE(l_c_attributes_tbl(15), g_miss_char, NULL, NULL, c_attribute15, l_c_attributes_tbl(15))
6792 ,DECODE(l_c_attributes_tbl(15), g_miss_char, c_attribute15, NULL, null, l_c_attributes_tbl(15)))
6793 , c_attribute16 = decode(p_source, 2,
6794 DECODE(l_c_attributes_tbl(16), g_miss_char, NULL, NULL, c_attribute16, l_c_attributes_tbl(16))
6795 ,DECODE(l_c_attributes_tbl(16), g_miss_char, c_attribute16, NULL, null, l_c_attributes_tbl(16)))
6796 , c_attribute17 = decode(p_source, 2,
6797 DECODE(l_c_attributes_tbl(17), g_miss_char, NULL, NULL, c_attribute17, l_c_attributes_tbl(17))
6798 ,DECODE(l_c_attributes_tbl(17), g_miss_char, c_attribute17, NULL, null, l_c_attributes_tbl(17)))
6799 , c_attribute18 = decode(p_source, 2,
6800 DECODE(l_c_attributes_tbl(18), g_miss_char, NULL, NULL, c_attribute18, l_c_attributes_tbl(18))
6801 ,DECODE(l_c_attributes_tbl(18), g_miss_char, c_attribute18, NULL, null, l_c_attributes_tbl(18)))
6802 , c_attribute19 = decode(p_source, 2,
6803 DECODE(l_c_attributes_tbl(19), g_miss_char, NULL, NULL, c_attribute19, l_c_attributes_tbl(19))
6804 ,DECODE(l_c_attributes_tbl(19), g_miss_char, c_attribute19, NULL, null, l_c_attributes_tbl(19)))
6805 , c_attribute20 = decode(p_source, 2,
6806 DECODE(l_c_attributes_tbl(20), g_miss_char, NULL, NULL, c_attribute20, l_c_attributes_tbl(20))
6807 ,DECODE(l_c_attributes_tbl(20), g_miss_char, c_attribute20, NULL, null, l_c_attributes_tbl(20)))
6808 , n_attribute1 = decode(p_source, 2,
6809 DECODE(l_n_attributes_tbl(1), g_miss_num, NULL, NULL, n_attribute1, l_n_attributes_tbl(1))
6810 , DECODE(l_n_attributes_tbl(1), g_miss_num, N_attribute1, NULL, null, l_n_attributes_tbl(1)))
6811 , n_attribute2 = decode(p_source, 2,
6812 DECODE(l_n_attributes_tbl(2), g_miss_num, NULL, NULL, n_attribute2, l_n_attributes_tbl(2))
6813 , DECODE(l_n_attributes_tbl(2), g_miss_num, N_attribute2, NULL, null, l_n_attributes_tbl(2)))
6814 , n_attribute3 = decode(p_source, 2,
6815 DECODE(l_n_attributes_tbl(3), g_miss_num, NULL, NULL, n_attribute3, l_n_attributes_tbl(3))
6816 , DECODE(l_n_attributes_tbl(3), g_miss_num, N_attribute3, NULL, null, l_n_attributes_tbl(3)))
6817 , n_attribute4 = decode(p_source, 2,
6818 DECODE(l_n_attributes_tbl(4), g_miss_num, NULL, NULL, n_attribute4, l_n_attributes_tbl(4))
6819 , DECODE(l_n_attributes_tbl(4), g_miss_num, N_attribute4, NULL, null, l_n_attributes_tbl(4)))
6820 , n_attribute5 = decode(p_source, 2,
6821 DECODE(l_n_attributes_tbl(5), g_miss_num, NULL, NULL, n_attribute5, l_n_attributes_tbl(5))
6822 , DECODE(l_n_attributes_tbl(5), g_miss_num, N_attribute5, NULL, null, l_n_attributes_tbl(5)))
6823 , n_attribute6 = decode(p_source, 2,
6824 DECODE(l_n_attributes_tbl(6), g_miss_num, NULL, NULL, n_attribute6, l_n_attributes_tbl(6))
6825 , DECODE(l_n_attributes_tbl(6), g_miss_num, N_attribute6, NULL, null, l_n_attributes_tbl(6)))
6826 , n_attribute7 = decode(p_source, 2,
6827 DECODE(l_n_attributes_tbl(7), g_miss_num, NULL, NULL, n_attribute7, l_n_attributes_tbl(7))
6828 , DECODE(l_n_attributes_tbl(7), g_miss_num, N_attribute7, NULL, null, l_n_attributes_tbl(7)))
6829 , n_attribute8 = decode(p_source, 2,
6830 DECODE(l_n_attributes_tbl(8), g_miss_num, NULL, NULL, n_attribute8, l_n_attributes_tbl(8))
6831 , DECODE(l_n_attributes_tbl(8), g_miss_num, N_attribute8, NULL, null, l_n_attributes_tbl(8)))
6832 , n_attribute9 = decode(p_source, 2,
6833 DECODE(l_n_attributes_tbl(9), g_miss_num, NULL, NULL, n_attribute9, l_n_attributes_tbl(9))
6834 ,DECODE(l_n_attributes_tbl(9), g_miss_num, N_attribute9, NULL, null, l_n_attributes_tbl(9)))
6835 , n_attribute10 = decode(p_source, 2,
6836 DECODE(l_n_attributes_tbl(10), g_miss_num, NULL, NULL, n_attribute10, l_n_attributes_tbl(10))
6837 ,DECODE(l_n_attributes_tbl(10), g_miss_num, n_attribute10, NULL, null, l_n_attributes_tbl(10)))
6838 , d_attribute1 = decode(p_source, 2,
6839 DECODE(l_d_attributes_tbl(1), g_miss_date, NULL, NULL, d_attribute1, l_d_attributes_tbl(1))
6840 , DECODE(l_d_attributes_tbl(1), g_miss_date, d_attribute1, NULL, null, l_d_attributes_tbl(1)))
6841 , d_attribute2 = decode(p_source, 2,
6842 DECODE(l_d_attributes_tbl(2), g_miss_date, NULL, NULL, d_attribute2, l_d_attributes_tbl(2))
6843 , DECODE(l_d_attributes_tbl(2), g_miss_date, d_attribute2, NULL, null, l_d_attributes_tbl(2)))
6844 , d_attribute3 = decode(p_source, 2,
6845 DECODE(l_d_attributes_tbl(3), g_miss_date, NULL, NULL, d_attribute3, l_d_attributes_tbl(3))
6846 , DECODE(l_d_attributes_tbl(3), g_miss_date, d_attribute3, NULL, null, l_d_attributes_tbl(3)))
6847 , d_attribute4 = decode(p_source, 2,
6848 DECODE(l_d_attributes_tbl(4), g_miss_date, NULL, NULL, d_attribute4, l_d_attributes_tbl(4))
6849 , DECODE(l_d_attributes_tbl(4), g_miss_date, d_attribute4, NULL, null, l_d_attributes_tbl(4)))
6850 , d_attribute5 = decode(p_source, 2,
6851 DECODE(l_d_attributes_tbl(5), g_miss_date, NULL, NULL, d_attribute5, l_d_attributes_tbl(5))
6852 , DECODE(l_d_attributes_tbl(5), g_miss_date, d_attribute5, NULL, null, l_d_attributes_tbl(5)))
6853 , d_attribute6 = decode(p_source, 2,
6854 DECODE(l_d_attributes_tbl(6), g_miss_date, NULL, NULL, d_attribute6, l_d_attributes_tbl(6))
6855 ,DECODE(l_d_attributes_tbl(6), g_miss_date, d_attribute6, NULL, null, l_d_attributes_tbl(6)))
6856 , d_attribute7 = decode(p_source, 2,
6857 DECODE(l_d_attributes_tbl(7), g_miss_date, NULL, NULL, d_attribute7, l_d_attributes_tbl(7))
6858 , DECODE(l_d_attributes_tbl(7), g_miss_date, d_attribute7, NULL, null, l_d_attributes_tbl(7)))
6859 , d_attribute8 = decode(p_source, 2,
6860 DECODE(l_d_attributes_tbl(8), g_miss_date, NULL, NULL, d_attribute8, l_d_attributes_tbl(8))
6861 , DECODE(l_d_attributes_tbl(8), g_miss_date, d_attribute8, NULL, null, l_d_attributes_tbl(8)))
6862 , d_attribute9 = decode(p_source, 2,
6863 DECODE(l_d_attributes_tbl(9), g_miss_date, NULL, NULL, d_attribute9, l_d_attributes_tbl(9))
6864 , DECODE(l_d_attributes_tbl(9), g_miss_date, d_attribute9, NULL, null, l_d_attributes_tbl(9)))
6865 , d_attribute10 = decode(p_source, 2,
6866 DECODE(l_d_attributes_tbl(10), g_miss_date, NULL, NULL, d_attribute10, l_d_attributes_tbl(10))
6867 ,DECODE(l_d_attributes_tbl(10), g_miss_date, d_attribute10, NULL, null, l_d_attributes_tbl(10)))*/
6868 ,LAST_UPDATE_DATE = sysdate
6869 ,LAST_UPDATED_BY = fnd_global.user_id
6870 WHERE inventory_item_id = p_lot_rec.inventory_item_id
6871 AND organization_id = p_lot_rec.organization_id
6872 AND lot_number = p_lot_rec.lot_number;
6873 END IF;
6874
6875
6876 IF SQL%FOUND THEN
6877 IF g_debug = 1 THEN
6878 print_debug('Upd Lot Attr:Update successfully completed', 9);
6879 END IF;
6880 END IF;
6881
6882 /* Bug 8198497: Calling the API to validate status of the lot and update it */
6883 validate_lot_status(
6884 p_api_version
6885 , p_init_msg_list
6886 , p_lot_rec.organization_id
6887 , p_lot_rec.inventory_item_id
6888 , p_lot_rec.lot_number
6889 , p_lot_rec.status_id
6890 , x_return_status
6891 , x_msg_count
6892 , x_msg_data
6893 );
6894
6895 -- bug 13780398
6896 select grade_code
6897 into l_lot_grade
6898 from mtl_lot_numbers
6899 where organization_id=p_lot_rec.organization_id
6900 and inventory_item_id=p_lot_rec.inventory_item_id
6901 and lot_number=p_lot_rec.lot_number;
6902
6903 Select nvl(GRADE_CONTROL_FLAG,'N')
6904 into l_grade_enabled
6905 from mtl_system_items
6906 where organization_id= p_lot_rec.organization_id
6907 and inventory_item_id= p_lot_rec.inventory_item_id;
6908
6909
6910 If (l_grade_enabled = 'Y' and p_lot_rec.grade_code <> l_lot_grade and (p_lot_rec.grade_code is not null or p_lot_rec.grade_code <> g_miss_char)) then
6911
6912 INV_GRADE_PKG.UPDATE_GRADE(
6913 p_organization_id => p_lot_rec.organization_id
6914 , p_update_method => 2
6915 , p_inventory_item_id => p_lot_rec.inventory_item_id
6916 , p_from_grade_code => l_lot_grade
6917 , p_to_grade_code => p_lot_rec.grade_code
6918 , p_reason_id => NULL
6919 , p_lot_number => p_lot_rec.lot_number
6920 , x_Status => x_return_status
6921 , x_Message => x_msg_data
6922 , p_update_from_mobile => 'N'
6923 , p_primary_quantity => NULL
6924 , p_secondary_quantity => NULL);
6925
6926 end if;
6927 -- end bug 13780398
6928
6929 EXCEPTION
6930 WHEN NO_DATA_FOUND THEN
6931 x_return_status := g_ret_sts_error;
6932 ROLLBACK TO upd_lot_attr;
6933 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
6934 if( x_msg_count > 1 ) then
6935 x_msg_data := fnd_msg_pub.get(x_msg_count, FND_API.G_FALSE);
6936 end if;
6937 print_debug('Upd Lort Attr: In No data found ' || SQLERRM, 9);
6938 WHEN g_exc_error THEN
6939 x_return_status := g_ret_sts_error;
6940 ROLLBACK TO upd_lot_attr;
6941 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
6942 if( x_msg_count > 1 ) then
6943 x_msg_data := fnd_msg_pub.get(x_msg_count, FND_API.G_FALSE);
6944 end if;
6945 print_debug('Upd Lot Attr: In g_exc_error ' || SQLERRM, 9);
6946 WHEN g_exc_unexpected_error THEN
6947 x_return_status := g_ret_sts_unexp_error;
6948 ROLLBACK TO upd_lot_attr;
6949 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
6950 if ( x_msg_count > 1 ) then
6951 x_msg_data := fnd_msg_pub.get(x_msg_count, FND_API.G_FALSE);
6952 end if;
6953 print_debug('In g_exc_unexpected_error ' || SQLERRM, 9);
6954 WHEN OTHERS THEN
6955 x_return_status := g_ret_sts_unexp_error;
6956 ROLLBACK TO upd_lot_attr;
6957 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
6958 if( x_msg_count > 1 ) then
6959 x_msg_data := fnd_msg_pub.get(x_msg_count, FND_API.G_FALSE);
6960 end if;
6961 print_debug('Upd Lot Attr: In others ' || SQLERRM, 9);
6962 END update_inv_lot;
6963
6964 -- nsinghi bug#5209065. Created Overloaded procedure, which takes in lot rec as input parameter. This will help updating the new lot attributes added in R12.
6965 PROCEDURE update_inv_lot(
6966 x_return_status OUT NOCOPY VARCHAR2
6967 , x_msg_count OUT NOCOPY NUMBER
6968 , x_msg_data OUT NOCOPY VARCHAR2
6969 , p_inventory_item_id IN NUMBER
6970 , p_organization_id IN NUMBER
6971 , p_lot_number IN VARCHAR2
6972 , p_expiration_date IN DATE
6973 , p_disable_flag IN NUMBER
6974 , p_attribute_category IN VARCHAR2
6975 , p_lot_attribute_category IN VARCHAR2
6976 , p_attributes_tbl IN inv_lot_api_pub.char_tbl
6977 , p_c_attributes_tbl IN inv_lot_api_pub.char_tbl
6978 , p_n_attributes_tbl IN inv_lot_api_pub.number_tbl
6979 , p_d_attributes_tbl IN inv_lot_api_pub.date_tbl
6980 , p_grade_code IN VARCHAR2
6981 , p_origination_date IN DATE
6982 , p_date_code IN VARCHAR2
6983 , p_status_id IN NUMBER
6984 , p_change_date IN DATE
6985 , p_age IN NUMBER
6986 , p_retest_date IN DATE
6987 , p_maturity_date IN DATE
6988 , p_item_size IN NUMBER
6989 , p_color IN VARCHAR2
6990 , p_volume IN NUMBER
6991 , p_volume_uom IN VARCHAR2
6992 , p_place_of_origin IN VARCHAR2
6993 , p_best_by_date IN DATE
6994 , p_length IN NUMBER
6995 , p_length_uom IN VARCHAR2
6996 , p_recycled_content IN NUMBER
6997 , p_thickness IN NUMBER
6998 , p_thickness_uom IN VARCHAR2
6999 , p_width IN NUMBER
7000 , p_width_uom IN VARCHAR2
7001 , p_territory_code IN VARCHAR2
7002 , p_supplier_lot_number IN VARCHAR2
7003 , p_vendor_name IN VARCHAR2
7004 , p_source IN NUMBER
7005 ) IS
7006 l_in_lot_rec MTL_LOT_NUMBERS%ROWTYPE;
7007 x_lot_rec MTL_LOT_NUMBERS%ROWTYPE;
7008 l_api_version NUMBER;
7009 l_init_msg_list VARCHAR2(100);
7010 l_commit VARCHAR2(100);
7011 l_origin_txn_id NUMBER;
7012 l_return_status VARCHAR2(1) ;
7013 l_msg_data VARCHAR2(3000) ;
7014 l_msg_count NUMBER ;
7015
7016 BEGIN
7017 SAVEPOINT upd_lot_attr;
7018 x_return_status := fnd_api.g_ret_sts_success;
7019
7020 /* Populating the variables and calling the new overloaded API */
7021
7022 l_in_lot_rec.inventory_item_id := p_inventory_item_id;
7023 l_in_lot_rec.organization_id := p_organization_id;
7024 l_in_lot_rec.lot_number := p_lot_number;
7025
7026 -- bug 13987577 Commented the line below and added new line
7027 --l_in_lot_rec.parent_lot_number := NULL;
7028 --l_in_lot_rec.parent_lot_number := g_miss_char;
7029
7030 l_in_lot_rec.expiration_date := p_expiration_date;
7031 l_in_lot_rec.disable_flag := p_disable_flag;
7032 l_in_lot_rec.attribute_category := p_attribute_category;
7033 l_in_lot_rec.lot_attribute_category := p_lot_attribute_category;
7034 l_in_lot_rec.grade_code := p_grade_code;
7035 l_in_lot_rec.origination_date := p_origination_date;
7036 l_in_lot_rec.date_code := p_date_code;
7037 l_in_lot_rec.status_id := p_status_id;
7038 l_in_lot_rec.change_date := p_change_date;
7039 l_in_lot_rec.age := p_age;
7040 l_in_lot_rec.retest_date := p_retest_date;
7041 l_in_lot_rec.maturity_date := p_maturity_date;
7042 l_in_lot_rec.item_size := p_item_size;
7043 l_in_lot_rec.color := p_color;
7044 l_in_lot_rec.volume := p_volume;
7045 l_in_lot_rec.volume_uom := p_volume_uom;
7046 l_in_lot_rec.place_of_origin := p_place_of_origin;
7047 l_in_lot_rec.best_by_date := p_best_by_date;
7048 l_in_lot_rec.length := p_length;
7049 l_in_lot_rec.length_uom := p_length_uom;
7050 l_in_lot_rec.recycled_content := p_recycled_content;
7051 l_in_lot_rec.thickness := p_thickness;
7052 l_in_lot_rec.thickness_uom := p_thickness_uom;
7053 l_in_lot_rec.width := p_width;
7054 l_in_lot_rec.width_uom := p_width_uom;
7055 l_in_lot_rec.territory_code := p_territory_code;
7056 l_in_lot_rec.supplier_lot_number := p_supplier_lot_number;
7057 l_in_lot_rec.vendor_name := p_vendor_name;
7058 l_in_lot_rec.last_update_date := SYSDATE ;
7059 l_in_lot_rec.last_updated_by := FND_GLOBAL.USER_ID;
7060 l_in_lot_rec.last_update_login := FND_GLOBAL.LOGIN_ID;
7061 --BUG 4748451: if the p%tbl are not initialized, then a no_date_found
7062 --exception would be thrown if accessed. So add clause to check for this
7063
7064 /*bug 14546399 added else for passing g_miss_char for all attributes values*/
7065 IF (p_attributes_tbl.exists(1)) THEN
7066 l_in_lot_rec.attribute1 := p_attributes_tbl(1);
7067 ELSE
7068 l_in_lot_rec.attribute1 := g_miss_char;
7069 END IF;
7070 IF (p_attributes_tbl.exists(2)) THEN
7071 l_in_lot_rec.attribute2 := p_attributes_tbl(2);
7072 ELSE
7073 l_in_lot_rec.attribute2 := g_miss_char;
7074 END IF;
7075 IF (p_attributes_tbl.exists(3)) THEN
7076 l_in_lot_rec.attribute3 := p_attributes_tbl(3);
7077 ELSE
7078 l_in_lot_rec.attribute3 := g_miss_char;
7079 END IF;
7080 IF (p_attributes_tbl.exists(4)) THEN
7081 l_in_lot_rec.attribute4 := p_attributes_tbl(4);
7082 ELSE
7083 l_in_lot_rec.attribute4 := g_miss_char;
7084 END IF;
7085 IF (p_attributes_tbl.exists(5)) THEN
7086 l_in_lot_rec.attribute5 := p_attributes_tbl(5);
7087 ELSE
7088 l_in_lot_rec.attribute5 := g_miss_char;
7089 END IF;
7090 IF (p_attributes_tbl.exists(6)) THEN
7091 l_in_lot_rec.attribute6 := p_attributes_tbl(6);
7092 ELSE
7093 l_in_lot_rec.attribute6 := g_miss_char;
7094 END IF;
7095 IF (p_attributes_tbl.exists(7)) THEN
7096 l_in_lot_rec.attribute7 := p_attributes_tbl(7);
7097 ELSE
7098 l_in_lot_rec.attribute7 := g_miss_char;
7099 END IF;
7100 IF (p_attributes_tbl.exists(8)) THEN
7101 l_in_lot_rec.attribute8 := p_attributes_tbl(8);
7102 ELSE
7103 l_in_lot_rec.attribute8 := g_miss_char;
7104 END IF;
7105 IF (p_attributes_tbl.exists(9)) THEN
7106 l_in_lot_rec.attribute9 := p_attributes_tbl(9);
7107 ELSE
7108 l_in_lot_rec.attribute9 := g_miss_char;
7109 END IF;
7110 IF (p_attributes_tbl.exists(10)) THEN
7111 l_in_lot_rec.attribute10 := p_attributes_tbl(10);
7112 ELSE
7113 l_in_lot_rec.attribute10 := g_miss_char;
7114 END IF;
7115 IF (p_attributes_tbl.exists(11)) THEN
7116 l_in_lot_rec.attribute11 := p_attributes_tbl(11);
7117 ELSE
7118 l_in_lot_rec.attribute11 := g_miss_char;
7119 END IF;
7120 IF (p_attributes_tbl.exists(12)) THEN
7121 l_in_lot_rec.attribute12 := p_attributes_tbl(12);
7122 ELSE
7123 l_in_lot_rec.attribute12 := g_miss_char;
7124 END IF;
7125 IF (p_attributes_tbl.exists(13)) THEN
7126 l_in_lot_rec.attribute13 := p_attributes_tbl(13);
7127 ELSE
7128 l_in_lot_rec.attribute13 := g_miss_char;
7129 END IF;
7130 IF (p_attributes_tbl.exists(14)) THEN
7131 l_in_lot_rec.attribute14 := p_attributes_tbl(14);
7132 ELSE
7133 l_in_lot_rec.attribute14 := g_miss_char;
7134 END IF;
7135 IF (p_attributes_tbl.exists(15)) THEN
7136 l_in_lot_rec.attribute15 := p_attributes_tbl(15);
7137 ELSE
7138 l_in_lot_rec.attribute15 := g_miss_char;
7139 END IF;
7140 IF (p_c_attributes_tbl.exists(1)) THEN
7141 l_in_lot_rec.c_attribute1 := p_c_attributes_tbl(1);
7142 ELSE
7143 l_in_lot_rec.c_attribute1 := g_miss_char;
7144 END IF;
7145 IF (p_c_attributes_tbl.exists(2)) THEN
7146 l_in_lot_rec.c_attribute2 := p_c_attributes_tbl(2);
7147 ELSE
7148 l_in_lot_rec.c_attribute2 := g_miss_char;
7149 END IF;
7150 IF (p_c_attributes_tbl.exists(3)) THEN
7151 l_in_lot_rec.c_attribute3 := p_c_attributes_tbl(3);
7152 ELSE
7153 l_in_lot_rec.c_attribute3 := g_miss_char;
7154 END IF;
7155 IF (p_c_attributes_tbl.exists(4)) THEN
7156 l_in_lot_rec.c_attribute4 := p_c_attributes_tbl(4);
7157 ELSE
7158 l_in_lot_rec.c_attribute4 := g_miss_char;
7159 END IF;
7160 IF (p_c_attributes_tbl.exists(5)) THEN
7161 l_in_lot_rec.c_attribute5 := p_c_attributes_tbl(5);
7162 ELSE
7163 l_in_lot_rec.c_attribute5 := g_miss_char;
7164 END IF;
7165 IF (p_c_attributes_tbl.exists(6)) THEN
7166 l_in_lot_rec.c_attribute6 := p_c_attributes_tbl(6);
7167 ELSE
7168 l_in_lot_rec.c_attribute6 := g_miss_char;
7169 END IF;
7170 IF (p_c_attributes_tbl.exists(7)) THEN
7171 l_in_lot_rec.c_attribute7 := p_c_attributes_tbl(7);
7172 ELSE
7173 l_in_lot_rec.c_attribute7 := g_miss_char;
7174 END IF;
7175 IF (p_c_attributes_tbl.exists(8)) THEN
7176 l_in_lot_rec.c_attribute8 := p_c_attributes_tbl(8);
7177 ELSE
7178 l_in_lot_rec.c_attribute8 := g_miss_char;
7179 END IF;
7180 IF (p_c_attributes_tbl.exists(9)) THEN
7181 l_in_lot_rec.c_attribute9 := p_c_attributes_tbl(9);
7182 ELSE
7183 l_in_lot_rec.c_attribute9 := g_miss_char;
7184 END IF;
7185 IF (p_c_attributes_tbl.exists(10)) THEN
7186 l_in_lot_rec.c_attribute10 := p_c_attributes_tbl(10);
7187 ELSE
7188 l_in_lot_rec.c_attribute10 := g_miss_char;
7189 END IF;
7190 IF (p_c_attributes_tbl.exists(11)) THEN
7191 l_in_lot_rec.c_attribute11 := p_c_attributes_tbl(11);
7192 ELSE
7193 l_in_lot_rec.c_attribute11 := g_miss_char;
7194 END IF;
7195 IF (p_c_attributes_tbl.exists(12)) THEN
7196 l_in_lot_rec.c_attribute12 := p_c_attributes_tbl(12);
7197 ELSE
7198 l_in_lot_rec.c_attribute12 := g_miss_char;
7199 END IF;
7200 IF (p_c_attributes_tbl.exists(13)) THEN
7201 l_in_lot_rec.c_attribute13 := p_c_attributes_tbl(13);
7202 ELSE
7203 l_in_lot_rec.c_attribute13 := g_miss_char;
7204 END IF;
7205 IF (p_c_attributes_tbl.exists(14)) THEN
7206 l_in_lot_rec.c_attribute14 := p_c_attributes_tbl(14);
7207 ELSE
7208 l_in_lot_rec.c_attribute14 := g_miss_char;
7209 END IF;
7210 IF (p_c_attributes_tbl.exists(15)) THEN
7211 l_in_lot_rec.c_attribute15 := p_c_attributes_tbl(15);
7212 ELSE
7213 l_in_lot_rec.c_attribute15 := g_miss_char;
7214 END IF;
7215 IF (p_c_attributes_tbl.exists(16)) THEN
7216 l_in_lot_rec.c_attribute16 := p_c_attributes_tbl(16);
7217 ELSE
7218 l_in_lot_rec.c_attribute16 := g_miss_char;
7219 END IF;
7220 IF (p_c_attributes_tbl.exists(17)) THEN
7221 l_in_lot_rec.c_attribute17 := p_c_attributes_tbl(17);
7222 ELSE
7223 l_in_lot_rec.c_attribute17 := g_miss_char;
7224 END IF;
7225 IF (p_c_attributes_tbl.exists(18)) THEN
7226 l_in_lot_rec.c_attribute18 := p_c_attributes_tbl(18);
7227 ELSE
7228 l_in_lot_rec.c_attribute18 := g_miss_char;
7229 END IF;
7230 IF (p_c_attributes_tbl.exists(19)) THEN
7231 l_in_lot_rec.c_attribute19 := p_c_attributes_tbl(19);
7232 ELSE
7233 l_in_lot_rec.c_attribute19 := g_miss_char;
7234 END IF;
7235 IF (p_c_attributes_tbl.exists(20)) THEN
7236 l_in_lot_rec.c_attribute20 := p_c_attributes_tbl(20);
7237 ELSE
7238 l_in_lot_rec.c_attribute20 := g_miss_char;
7239 END IF;
7240 IF (p_n_attributes_tbl.exists(1)) THEN
7241 l_in_lot_rec.n_attribute1 := p_n_attributes_tbl(1);
7242 ELSE
7243 l_in_lot_rec.n_attribute1 := g_miss_num;
7244 END IF;
7245 IF (p_n_attributes_tbl.exists(2)) THEN
7246 l_in_lot_rec.n_attribute2 := p_n_attributes_tbl(2);
7247 ELSE
7248 l_in_lot_rec.n_attribute2 := g_miss_num;
7249 END IF;
7250 IF (p_n_attributes_tbl.exists(3)) THEN
7251 l_in_lot_rec.n_attribute3 := p_n_attributes_tbl(3);
7252 ELSE
7253 l_in_lot_rec.n_attribute3 := g_miss_num;
7254 END IF;
7255 IF (p_n_attributes_tbl.exists(4)) THEN
7256 l_in_lot_rec.n_attribute4 := p_n_attributes_tbl(4);
7257 ELSE
7258 l_in_lot_rec.n_attribute4 := g_miss_num;
7259 END IF;
7260 IF (p_n_attributes_tbl.exists(5)) THEN
7261 l_in_lot_rec.n_attribute5 := p_n_attributes_tbl(5);
7262 ELSE
7263 l_in_lot_rec.n_attribute5 := g_miss_num;
7264 END IF;
7265 IF (p_n_attributes_tbl.exists(6)) THEN
7266 l_in_lot_rec.n_attribute6 := p_n_attributes_tbl(6);
7267 ELSE
7268 l_in_lot_rec.n_attribute6 := g_miss_num;
7269 END IF;
7270 IF (p_n_attributes_tbl.exists(7)) THEN
7271 l_in_lot_rec.n_attribute7 := p_n_attributes_tbl(7);
7272 ELSE
7273 l_in_lot_rec.n_attribute7 := g_miss_num;
7274 END IF;
7275 IF (p_n_attributes_tbl.exists(8)) THEN
7276 l_in_lot_rec.n_attribute8 := p_n_attributes_tbl(8);
7277 ELSE
7278 l_in_lot_rec.n_attribute8 := g_miss_num;
7279 END IF;
7280 IF (p_n_attributes_tbl.exists(9)) THEN
7281 l_in_lot_rec.n_attribute9 := p_n_attributes_tbl(9);
7282 ELSE
7283 l_in_lot_rec.n_attribute9 := g_miss_num;
7284 END IF;
7285 IF (p_n_attributes_tbl.exists(10)) THEN
7286 l_in_lot_rec.n_attribute10 := p_n_attributes_tbl(10);
7287 ELSE
7288 l_in_lot_rec.n_attribute10 := g_miss_num;
7289 END IF;
7290 IF (p_d_attributes_tbl.exists(1)) THEN
7291 l_in_lot_rec.d_attribute1 := p_d_attributes_tbl(1);
7292 ELSE
7293 l_in_lot_rec.d_attribute1 := g_miss_date;
7294 END IF;
7295 IF (p_d_attributes_tbl.exists(2)) THEN
7296 l_in_lot_rec.d_attribute2 := p_d_attributes_tbl(2);
7297 ELSE
7298 l_in_lot_rec.d_attribute2 := g_miss_date;
7299 END IF;
7300 IF (p_d_attributes_tbl.exists(3)) THEN
7301 l_in_lot_rec.d_attribute3 := p_d_attributes_tbl(3);
7302 ELSE
7303 l_in_lot_rec.d_attribute3 := g_miss_date;
7304 END IF;
7305 IF (p_d_attributes_tbl.exists(4)) THEN
7306 l_in_lot_rec.d_attribute4 := p_d_attributes_tbl(4);
7307 ELSE
7308 l_in_lot_rec.d_attribute4 := g_miss_date;
7309 END IF;
7310 IF (p_d_attributes_tbl.exists(5)) THEN
7311 l_in_lot_rec.d_attribute5 := p_d_attributes_tbl(5);
7312 ELSE
7313 l_in_lot_rec.d_attribute5 := g_miss_date;
7314 END IF;
7315 IF (p_d_attributes_tbl.exists(6)) THEN
7316 l_in_lot_rec.d_attribute6 := p_d_attributes_tbl(6);
7317 ELSE
7318 l_in_lot_rec.d_attribute6 := g_miss_date;
7319 END IF;
7320 IF (p_d_attributes_tbl.exists(7)) THEN
7321 l_in_lot_rec.d_attribute7 := p_d_attributes_tbl(7);
7322 ELSE
7323 l_in_lot_rec.d_attribute7 := g_miss_date;
7324 END IF;
7325 IF (p_d_attributes_tbl.exists(8)) THEN
7326 l_in_lot_rec.d_attribute8 := p_d_attributes_tbl(8);
7327 ELSE
7328 l_in_lot_rec.d_attribute8 := g_miss_date;
7329 END IF;
7330 IF (p_d_attributes_tbl.exists(9)) THEN
7331 l_in_lot_rec.d_attribute9 := p_d_attributes_tbl(9);
7332 ELSE
7333 l_in_lot_rec.d_attribute9 := g_miss_date;
7334 END IF;
7335 IF (p_d_attributes_tbl.exists(10)) THEN
7336 l_in_lot_rec.d_attribute10 := p_d_attributes_tbl(10);
7337 ELSE
7338 l_in_lot_rec.d_attribute10 := g_miss_date;
7339 END IF;
7340 --END BUG 4748451
7341 l_api_version := 1.0;
7342 l_init_msg_list := fnd_api.g_false;
7343 l_commit := fnd_api.g_false;
7344 l_origin_txn_id := NULL;
7345
7346 --Bug 13553990 keeping the value of columns without getting updated to NULL which are not passed.
7347 if (p_source <> 2) then
7348 l_in_lot_rec.origination_type := -99;
7349 l_in_lot_rec.inventory_atp_code := g_miss_num;
7350 l_in_lot_rec.reservable_type := g_miss_num;
7351 l_in_lot_rec.availability_type := g_miss_num;
7352 l_in_lot_rec.sampling_event_id := g_miss_num;
7353 l_in_lot_rec.expiration_action_code := g_miss_char;
7354 l_in_lot_rec.expiration_action_date := g_miss_date;
7355 l_in_lot_rec.hold_date := g_miss_date;
7356 end if;
7357
7358 -- bug 13987577
7359 if (p_source = 2) then
7360 l_in_lot_rec.parent_lot_number := NULL;
7361 else
7362 l_in_lot_rec.parent_lot_number := g_miss_char;
7363 end if;
7364
7365
7366 /* Calling the overloaded procedure */
7367 Update_Inv_lot(
7368 x_return_status => l_return_status
7369 , x_msg_count => l_msg_count
7370 , x_msg_data => l_msg_data
7371 , x_lot_rec => x_lot_rec
7372 , p_lot_rec => l_in_lot_rec
7373 , p_source => p_source
7374 , p_api_version => l_api_version
7375 , p_init_msg_list => l_init_msg_list
7376 , p_commit => l_commit
7377 );
7378
7379 IF g_debug = 1 THEN
7380 print_debug('Program Update_Inv_lot return ' || l_return_status, 9);
7381 END IF;
7382 IF l_return_status = fnd_api.g_ret_sts_error THEN
7383 IF g_debug = 1 THEN
7384 print_debug('Program Update_Inv_lot has failed with a user defined exception', 9);
7385 END IF;
7386 RAISE g_exc_error;
7387 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
7388 IF g_debug = 1 THEN
7389 print_debug('Program Update_Inv_lot has failed with a Unexpected exception', 9);
7390 END IF;
7391 FND_MESSAGE.SET_NAME('INV','INV_PROGRAM_ERROR');
7392 FND_MESSAGE.SET_TOKEN('PROG_NAME','Update_Inv_lot');
7393 fnd_msg_pub.ADD;
7394 RAISE g_exc_unexpected_error;
7395 END IF;
7396
7397 print_debug('End of the program Update_Inv_lot. Program has completed successfully ', 9);
7398 EXCEPTION
7399 WHEN NO_DATA_FOUND THEN
7400 x_return_status := g_ret_sts_error;
7401 ROLLBACK TO upd_lot_attr;
7402 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
7403 if( x_msg_count > 1 ) then
7404 x_msg_data := fnd_msg_pub.get(x_msg_count, FND_API.G_FALSE);
7405 end if;
7406 print_debug('Upd Lot Attr: In No data found ' || SQLERRM, 9);
7407 WHEN g_exc_error THEN
7408 x_return_status := g_ret_sts_error;
7409 ROLLBACK TO upd_lot_attr;
7410 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
7411 if( x_msg_count > 1 ) then
7412 x_msg_data := fnd_msg_pub.get(x_msg_count, FND_API.G_FALSE);
7413 end if;
7414 print_debug('Upd Lot Attr: In g_exc_error ' || SQLERRM, 9);
7415 WHEN g_exc_unexpected_error THEN
7416 x_return_status := g_ret_sts_unexp_error;
7417 ROLLBACK TO upd_lot_attr;
7418 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
7419 if ( x_msg_count > 1 ) then
7420 x_msg_data := fnd_msg_pub.get(x_msg_count, FND_API.G_FALSE);
7421 end if;
7422 print_debug('In g_exc_unexpected_error ' || SQLERRM, 9);
7423 WHEN OTHERS THEN
7424 x_return_status := g_ret_sts_unexp_error;
7425 ROLLBACK TO upd_lot_attr;
7426 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
7427 if( x_msg_count > 1 ) then
7428 x_msg_data := fnd_msg_pub.get(x_msg_count, FND_API.G_FALSE);
7429 end if;
7430 print_debug('Upd Lot Attr: In others ' || SQLERRM, 9);
7431
7432 END update_inv_lot;
7433 -- nsinghi END. Created new overloaded procedure.
7434
7435 PROCEDURE wms_lot_attr_validate(
7436 x_return_status OUT NOCOPY VARCHAR2
7437 , x_msg_count OUT NOCOPY NUMBER
7438 , x_msg_data OUT NOCOPY VARCHAR2
7439 , p_inventory_item_id IN NUMBER
7440 , p_organization_id IN NUMBER
7441 , p_disable_flag IN NUMBER
7442 , p_lot_attribute_category IN VARCHAR2
7443 , p_c_attributes_tbl IN inv_lot_api_pub.char_tbl
7444 , p_n_attributes_tbl IN inv_lot_api_pub.number_tbl
7445 , p_d_attributes_tbl IN inv_lot_api_pub.date_tbl
7446 , p_grade_code IN VARCHAR2
7447 , p_origination_date IN DATE
7448 , p_date_code IN VARCHAR2
7449 , p_change_date IN DATE
7450 , p_age IN NUMBER
7451 , p_retest_date IN DATE
7452 , p_maturity_date IN DATE
7453 , p_item_size IN NUMBER
7454 , p_color IN VARCHAR2
7455 , p_volume IN NUMBER
7456 , p_volume_uom IN VARCHAR2
7457 , p_place_of_origin IN VARCHAR2
7458 , p_best_by_date IN DATE
7459 , p_length IN NUMBER
7460 , p_length_uom IN VARCHAR2
7461 , p_recycled_content IN NUMBER
7462 , p_thickness IN NUMBER
7463 , p_thickness_uom IN VARCHAR2
7464 , p_width IN NUMBER
7465 , p_width_uom IN VARCHAR2
7466 , p_territory_code IN VARCHAR2
7467 , p_supplier_lot_number IN VARCHAR2
7468 , p_vendor_name IN VARCHAR2
7469 ) IS
7470 TYPE seg_name IS TABLE OF VARCHAR2(1000)
7471 INDEX BY BINARY_INTEGER;
7472
7473 lot_dff inv_lot_sel_attr.lot_sel_attributes_tbl_type;
7474 l_attributes_default inv_lot_sel_attr.lot_sel_attributes_tbl_type;
7475 l_attributes_default_count NUMBER;
7476 l_c_attr_index NUMBER;
7477 l_n_attr_index NUMBER;
7478 l_d_attr_index NUMBER;
7479 l_context VARCHAR2(1000);
7480 l_context_r fnd_dflex.context_r;
7481 l_contexts_dr fnd_dflex.contexts_dr;
7482 l_dflex_r fnd_dflex.dflex_r;
7483 l_segments_dr fnd_dflex.segments_dr;
7484 l_enabled_seg_name seg_name;
7485 l_wms_all_segs_tbl seg_name;
7486 l_nsegments BINARY_INTEGER;
7487 l_global_context BINARY_INTEGER;
7488 l_global_nsegments BINARY_INTEGER;
7489 l_value_not_null_flag NUMBER := NULL;
7490 v_index NUMBER := 1;
7491 l_seg_exists NUMBER;
7492 error_segment VARCHAR2(30);
7493 errors_received EXCEPTION;
7494 error_msg VARCHAR2(5000);
7495 s NUMBER;
7496 e NUMBER;
7497 l_required_flag boolean;
7498 l_return_status VARCHAR2(1);
7499 l_msg_count NUMBER;
7500 l_msg_data VARCHAR2(2000);
7501 l_enabled_attributes NUMBER;
7502 l_context_enabled BOOLEAN := false;
7503 BEGIN
7504 x_return_status := inv_lot_api_pub.g_ret_sts_success;
7505 SAVEPOINT wms_lot_dff_validate;
7506
7507 IF g_debug = 1 THEN
7508 print_debug('In the beginning of the program lot_dff_validate', 9);
7509 END IF;
7510
7511 lot_dff(1).column_name := 'DISABLE_FLAG';
7512 lot_dff(1).column_type := 'NUMBER';
7513 IF p_disable_flag =G_MISS_NUM THEN
7514 lot_dff(1).column_value := NULL;
7515 ELSE
7516 lot_dff(1).column_value := p_disable_flag;
7517 END IF;
7518
7519 lot_dff(2).column_name := 'GRADE_CODE';
7520 lot_dff(2).column_type := 'VARCHAR2';
7521 IF P_GRADE_CODE =G_MISS_CHAR THEN
7522 lot_dff(2).column_value := NULL;
7523 ELSE
7524 lot_dff(2).column_value := p_grade_code;
7525 END IF;
7526
7527 lot_dff(3).column_name := 'ORIGINATION_DATE';
7528 lot_dff(3).column_type := 'DATE';
7529 IF P_ORIGINATION_DATE =G_MISS_DATE THEN
7530 lot_dff(3).column_value := NULL;
7531 ELSE
7532 lot_dff(3).column_value := fnd_date.date_to_canonical(p_origination_date);
7533 END IF;
7534
7535 lot_dff(4).column_name := 'DATE_CODE';
7536 lot_dff(4).column_type := 'VARCHAR2';
7537 IF p_date_code = G_MISS_CHAR THEN
7538 lot_dff(4).column_value := NULL;
7539 ELSE
7540 lot_dff(4).column_value := p_date_code;
7541 END IF;
7542
7543 lot_dff(5).column_name := 'CHANGE_DATE';
7544 lot_dff(5).column_type := 'DATE';
7545 IF p_change_date= G_MISS_DATE THEN
7546 lot_dff(5).column_value := NULL;
7547 ELSE
7548 lot_dff(5).column_value := fnd_date.date_to_canonical(p_change_date);
7549 END IF;
7550
7551 lot_dff(6).column_name := 'ORIGINATION_DATE';
7552 lot_dff(6).column_type := 'DATE';
7553 IF p_origination_date=G_MISS_DATE THEN
7554 lot_dff(6).column_value := NULL;
7555 ELSE
7556 lot_dff(6).column_value := fnd_date.date_to_canonical(p_origination_date);
7557 END IF;
7558
7559 lot_dff(6).column_name := 'AGE';
7560 lot_dff(6).column_type := 'NUMBER';
7561 IF p_age =G_MISS_NUM THEN
7562 lot_dff(6).column_value := NULL;
7563 ELSE
7564 lot_dff(6).column_value := p_age;
7565 END IF;
7566
7567 lot_dff(7).column_name := 'RETEST_DATE';
7568 lot_dff(7).column_type := 'DATE';
7569 IF p_retest_date=G_MISS_DATE THEN
7570 lot_dff(7).column_value := NULL;
7571 ELSE
7572 lot_dff(7).column_value := fnd_date.date_to_canonical(p_retest_date);
7573 END IF;
7574
7575 lot_dff(8).column_name := 'MATURITY_DATE';
7576 lot_dff(8).column_type := 'DATE';
7577 IF p_maturity_date= G_MISS_DATE THEN
7578 lot_dff(8).column_value := NULL;
7579 ELSE
7580 lot_dff(8).column_value := fnd_date.date_to_canonical(p_maturity_date);
7581 END IF;
7582
7583 lot_dff(9).column_name := 'ITEM_SIZE';
7584 lot_dff(9).column_type := 'NUMBER';
7585 IF p_item_size=G_MISS_NUM THEN
7586 lot_dff(9).column_value := NULL;
7587 ELSE
7588 lot_dff(9).column_value := p_item_size;
7589 END IF;
7590
7591 lot_dff(10).column_name := 'COLOR';
7592 lot_dff(10).column_type := 'VARCHAR2';
7593 IF p_color=G_MISS_CHAR THEN
7594 lot_dff(10).column_value := NULL;
7595 ELSE
7596 lot_dff(10).column_value := p_color;
7597 END IF;
7598
7599 lot_dff(11).column_name := 'VOLUME';
7600 lot_dff(11).column_type := 'NUMBER';
7601 IF p_volume = G_MISS_NUM THEN
7602 lot_dff(11).column_value := NULL;
7603 ELSE
7604 lot_dff(11).column_value := p_volume;
7605 END IF;
7606
7607 lot_dff(12).column_name := 'VOLUME_UOM';
7608 lot_dff(12).column_type := 'VARCHAR2';
7609 IF p_volume_uom = G_MISS_CHAR THEN
7610 lot_dff(12).column_value := NULL;
7611 ELSE
7612 lot_dff(12).column_value := p_volume_uom;
7613 END IF;
7614
7615 lot_dff(13).column_name := 'PLACE_OF_ORIGIN';
7616 lot_dff(13).column_type := 'VARCHAR2';
7617 IF p_place_of_origin=G_MISS_CHAR THEN
7618 lot_dff(13).column_value := NULL;
7619 ELSE
7620 lot_dff(13).column_value := p_place_of_origin;
7621 END IF;
7622
7623 lot_dff(14).column_name := 'BEST_BY_DATE';
7624 lot_dff(14).column_type := 'DATE';
7625 IF p_best_by_date= G_MISS_DATE THEN
7626 lot_dff(14).column_value := NULL;
7627 ELSE
7628 --BUG 3784406: Call date_to_canonical, instead of canonical_to_date
7629 lot_dff(14).column_value := fnd_date.date_to_canonical(p_best_by_date);
7630 END IF;
7631
7632 lot_dff(15).column_name := 'LENGTH';
7633 lot_dff(15).column_type := 'NUMBER';
7634 IF p_length=G_MISS_NUM THEN
7635 lot_dff(15).column_value := NULL;
7636 ELSE
7637 lot_dff(15).column_value := p_length;
7638 END IF;
7639
7640 lot_dff(16).column_name := 'LENGTH_UOM';
7641 lot_dff(16).column_type := 'VARCHAR2';
7642 IF p_length_uom=G_MISS_CHAR THEN
7643 lot_dff(16).column_value := NULL;
7644 ELSE
7645 lot_dff(16).column_value := p_length_uom;
7646 END IF;
7647
7648 lot_dff(17).column_name := 'RECYCLED_CONTENT';
7649 lot_dff(17).column_type := 'NUMBER';
7650 IF p_recycled_content=G_MISS_NUM THEN
7651 lot_dff(17).column_value := NULL;
7652 ELSE
7653 lot_dff(17).column_value := p_recycled_content;
7654 END IF;
7655
7656 lot_dff(18).column_name := 'THICKNESS';
7657 lot_dff(18).column_type := 'NUMBER';
7658 IF p_thickness= G_MISS_NUM THEN
7659 lot_dff(18).column_value := NULL;
7660 ELSE
7661 lot_dff(18).column_value := p_thickness;
7662 END IF;
7663
7664 lot_dff(19).column_name := 'THICKNESS_UOM';
7665 lot_dff(19).column_type := 'VARCHAR2';
7666 IF p_thickness_uom=G_MISS_CHAR THEN
7667 lot_dff(19).column_value := NULL;
7668 ELSE
7669 lot_dff(19).column_value := p_thickness_uom;
7670 END IF;
7671
7672 lot_dff(20).column_name := 'WIDTH';
7673 lot_dff(20).column_type := 'NUMBER';
7674 IF p_width =g_miss_num THEN
7675 lot_dff(20).column_value := NULL;
7676 ELSE
7677 lot_dff(20).column_value := p_width;
7678 END IF;
7679
7680 lot_dff(21).column_name := 'WIDTH_UOM';
7681 lot_dff(21).column_type := 'NUMBER';
7682 IF p_width_uom=g_miss_char THEN
7683 lot_dff(21).column_value := NULL;
7684 ELSE
7685 lot_dff(21).column_value := p_width_uom;
7686 END IF;
7687
7688 lot_dff(22).column_name := 'TERRITORY_CODE';
7689 lot_dff(22).column_type := 'VARCHAR2';
7690 IF p_territory_code= g_miss_char THEN
7691 lot_dff(22).column_value := NULL;
7692 ELSE
7693 lot_dff(22).column_value := p_territory_code;
7694 END IF;
7695
7696 lot_dff(23).column_name := 'SUPPLIER_LOT_NUMBER';
7697 lot_dff(23).column_type := 'VARCHAR2';
7698 IF p_supplier_lot_number = g_miss_char THEN
7699 lot_dff(23).column_value := NULL;
7700 ELSE
7701 lot_dff(23).column_value := p_supplier_lot_number;
7702 END IF;
7703
7704 lot_dff(24).column_name := 'C_ATTRIBUTE1';
7705 lot_dff(24).column_type := 'VARCHAR2';
7706 lot_dff(24).column_value := NULL;
7707 lot_dff(25).column_name := 'C_ATTRIBUTE2';
7708 lot_dff(25).column_type := 'VARCHAR2';
7709 lot_dff(25).column_value := NULL;
7710 lot_dff(26).column_name := 'C_ATTRIBUTE3';
7711 lot_dff(26).column_type := 'VARCHAR2';
7712 lot_dff(26).column_value := NULL;
7713 lot_dff(27).column_name := 'C_ATTRIBUTE4';
7714 lot_dff(27).column_type := 'VARCHAR2';
7715 lot_dff(27).column_value := NULL;
7716 lot_dff(28).column_name := 'C_ATTRIBUTE5';
7717 lot_dff(28).column_type := 'VARCHAR2';
7718 lot_dff(28).column_value := NULL;
7719 lot_dff(29).column_name := 'C_ATTRIBUTE6';
7720 lot_dff(29).column_type := 'VARCHAR2';
7721 lot_dff(29).column_value := NULL;
7722 lot_dff(30).column_name := 'C_ATTRIBUTE7';
7723 lot_dff(30).column_type := 'VARCHAR2';
7724 lot_dff(30).column_value := NULL;
7725 lot_dff(31).column_name := 'C_ATTRIBUTE8';
7726 lot_dff(31).column_type := 'VARCHAR2';
7727 lot_dff(31).column_value := NULL;
7728 lot_dff(32).column_name := 'C_ATTRIBUTE9';
7729 lot_dff(32).column_type := 'VARCHAR2';
7730 lot_dff(32).column_value := NULL;
7731 lot_dff(33).column_name := 'C_ATTRIBUTE10';
7732 lot_dff(33).column_type := 'VARCHAR2';
7733 lot_dff(33).column_value := NULL;
7734 lot_dff(34).column_name := 'C_ATTRIBUTE11';
7735 lot_dff(34).column_type := 'VARCHAR2';
7736 lot_dff(34).column_value := NULL;
7737 lot_dff(35).column_name := 'C_ATTRIBUTE12';
7738 lot_dff(35).column_type := 'VARCHAR2';
7739 lot_dff(35).column_value := NULL;
7740 lot_dff(36).column_name := 'C_ATTRIBUTE13';
7741 lot_dff(36).column_type := 'VARCHAR2';
7742 lot_dff(36).column_value := NULL;
7743 lot_dff(37).column_name := 'C_ATTRIBUTE14';
7744 lot_dff(37).column_type := 'VARCHAR2';
7745 lot_dff(37).column_value := NULL;
7746 lot_dff(38).column_name := 'C_ATTRIBUTE15';
7747 lot_dff(38).column_type := 'VARCHAR2';
7748 lot_dff(38).column_value := NULL;
7749 lot_dff(39).column_name := 'C_ATTRIBUTE16';
7750 lot_dff(39).column_type := 'VARCHAR2';
7751 lot_dff(39).column_value := NULL;
7752 lot_dff(40).column_name := 'C_ATTRIBUTE17';
7753 lot_dff(40).column_type := 'VARCHAR2';
7754 lot_dff(40).column_value := NULL;
7755 lot_dff(41).column_name := 'C_ATTRIBUTE18';
7756 lot_dff(41).column_type := 'VARCHAR2';
7757 lot_dff(41).column_value := NULL;
7758 lot_dff(42).column_name := 'C_ATTRIBUTE19';
7759 lot_dff(42).column_type := 'VARCHAR2';
7760 lot_dff(42).column_value := NULL;
7761 lot_dff(43).column_name := 'C_ATTRIBUTE20';
7762 lot_dff(43).column_type := 'VARCHAR2';
7763 lot_dff(43).column_value := NULL;
7764 lot_dff(44).column_name := 'N_ATTRIBUTE1';
7765 lot_dff(44).column_type := 'NUMBER';
7766 lot_dff(44).column_value := NULL;
7767 lot_dff(45).column_name := 'N_ATTRIBUTE2';
7768 lot_dff(45).column_type := 'NUMBER';
7769 lot_dff(45).column_value := NULL;
7770 lot_dff(46).column_name := 'N_ATTRIBUTE3';
7771 lot_dff(46).column_type := 'NUMBER';
7772 lot_dff(46).column_value := NULL;
7773 lot_dff(47).column_name := 'N_ATTRIBUTE4';
7774 lot_dff(47).column_type := 'NUMBER';
7775 lot_dff(47).column_value := NULL;
7776 lot_dff(48).column_name := 'N_ATTRIBUTE5';
7777 lot_dff(48).column_type := 'NUMBER';
7778 lot_dff(48).column_value := NULL;
7779 lot_dff(49).column_name := 'N_ATTRIBUTE6';
7780 lot_dff(49).column_type := 'NUMBER';
7781 lot_dff(49).column_value := NULL;
7782 lot_dff(50).column_name := 'N_ATTRIBUTE7';
7783 lot_dff(50).column_type := 'NUMBER';
7784 lot_dff(50).column_value := NULL;
7785 lot_dff(51).column_name := 'N_ATTRIBUTE8';
7786 lot_dff(51).column_type := 'NUMBER';
7787 lot_dff(51).column_value := NULL;
7788 lot_dff(52).column_name := 'N_ATTRIBUTE9';
7789 lot_dff(52).column_type := 'NUMBER';
7790 lot_dff(52).column_value := NULL;
7791 lot_dff(53).column_name := 'N_ATTRIBUTE10';
7792 lot_dff(53).column_type := 'NUMBER';
7793 lot_dff(53).column_value := NULL;
7794 lot_dff(54).column_name := 'D_ATTRIBUTE1';
7795 lot_dff(54).column_type := 'DATE';
7796 lot_dff(54).column_value := NULL;
7797 lot_dff(55).column_name := 'D_ATTRIBUTE2';
7798 lot_dff(55).column_type := 'DATE';
7799 lot_dff(55).column_value := NULL;
7800 lot_dff(56).column_name := 'D_ATTRIBUTE3';
7801 lot_dff(56).column_type := 'DATE';
7802 lot_dff(56).column_value := NULL;
7803 lot_dff(57).column_name := 'D_ATTRIBUTE4';
7804 lot_dff(57).column_type := 'DATE';
7805 lot_dff(57).column_value := NULL;
7806 lot_dff(58).column_name := 'D_ATTRIBUTE5';
7807 lot_dff(58).column_type := 'DATE';
7808 lot_dff(58).column_value := NULL;
7809 lot_dff(59).column_name := 'D_ATTRIBUTE6';
7810 lot_dff(59).column_type := 'DATE';
7811 lot_dff(59).column_value := NULL;
7812 lot_dff(60).column_name := 'D_ATTRIBUTE7';
7813 lot_dff(60).column_type := 'DATE';
7814 lot_dff(60).column_value := NULL;
7815 lot_dff(61).column_name := 'D_ATTRIBUTE8';
7816 lot_dff(61).column_type := 'DATE';
7817 lot_dff(61).column_value := NULL;
7818 lot_dff(62).column_name := 'D_ATTRIBUTE9';
7819 lot_dff(62).column_type := 'DATE';
7820 lot_dff(62).column_value := NULL;
7821 lot_dff(63).column_name := 'D_ATTRIBUTE10';
7822 lot_dff(63).column_type := 'DATE';
7823 lot_dff(63).column_value := NULL;
7824 /* Loop through the C_ATTRIBUTES_TBL and populate the values. This starts
7825 from index 24 till 43. Find the index in the input table where data is
7826 populated. Add the index value to the starting index of the table
7827 lot_dff to get the column for which data is populated
7828 */
7829 l_c_attr_index := p_c_attributes_tbl.FIRST;
7830
7831 WHILE l_c_attr_index <= p_c_attributes_tbl.LAST LOOP
7832 lot_dff(23 + l_c_attr_index).column_value := p_c_attributes_tbl(l_c_attr_index);
7833 l_c_attr_index := p_c_attributes_tbl.NEXT(l_c_attr_index);
7834 END LOOP;
7835
7836 IF g_debug = 1 THEN
7837 print_debug('After populating the lot_dff table with C_ATTRIBUTES', 9);
7838 END IF;
7839
7840 /* Loop through the N_ATTRIBUTES_TBL and populate the values. This starts
7841 from index 44 till 53. Find the index in the input table where data is
7842 populated. Add the index value to the starting index of the table
7843 lot_dff to get the column for which data is populated
7844 */
7845 l_n_attr_index := p_n_attributes_tbl.FIRST;
7846
7847 WHILE l_n_attr_index <= p_n_attributes_tbl.LAST LOOP
7848 lot_dff(43 + l_n_attr_index).column_value := p_n_attributes_tbl(l_n_attr_index);
7849 l_n_attr_index := p_n_attributes_tbl.NEXT(l_n_attr_index);
7850 END LOOP;
7851
7852 IF g_debug = 1 THEN
7853 print_debug('After populating the lot_dff table with N_ATTRIBUTES', 9);
7854 END IF;
7855
7856 /* Loop through the D_ATTRIBUTES_TBL and populate the values. This starts
7857 from index 54 till 63. Find the index in the input table where data is
7858 populated. Add the index value to the starting index of the table
7859 lot_dff to get the column for which data is populated
7860 */
7861 l_d_attr_index := p_d_attributes_tbl.FIRST;
7862
7863 WHILE l_d_attr_index <= p_d_attributes_tbl.LAST LOOP
7864 IF p_d_attributes_tbl(l_d_attr_index) IS NOT NULL THEN
7865 -- BUG 3784406: Call fnd_date.date_to_canonical
7866 IF g_debug = 1 THEN
7867 print_debug('Date before casting into DD:MM:YYYY format'||To_char(p_d_attributes_tbl(l_d_attr_index),'DD:MM:YYYY'), 9);
7868 END IF;
7869 lot_dff(53 + l_d_attr_index).column_value := fnd_date.date_to_canonical(p_d_attributes_tbl(l_d_attr_index));
7870 IF g_debug = 1 THEN
7871 print_debug('Date after casting in canonical format ' || lot_dff(53 + l_d_attr_index).column_value,9);
7872 END IF;
7873 ELSE
7874 lot_dff(53 + l_d_attr_index).column_value := NULL;
7875 END IF;
7876
7877 l_d_attr_index := p_d_attributes_tbl.NEXT(l_d_attr_index);
7878 END LOOP;
7879
7880 IF g_debug = 1 THEN
7881 print_debug('After populating the lot_dff table with D_ATTRIBUTES', 9);
7882 END IF;
7883
7884 l_enabled_attributes := INV_LOT_SEL_ATTR.is_enabled(
7885 p_flex_name => 'Lot Attributes'
7886 , p_organization_id => p_organization_id
7887 , p_inventory_item_id => p_inventory_item_id);
7888
7889 IF g_debug = 1 THEN
7890 print_Debug('l_enabled_attributes = ' || l_enabled_attributes, 9);
7891 end if;
7892 /*
7893 * Get the default lot attribute values if any
7894 */
7895 inv_lot_sel_attr.get_default (
7896 x_attributes_default => l_attributes_default,
7897 x_attributes_default_count => l_attributes_default_count,
7898 x_return_status => l_return_status,
7899 x_msg_count => l_msg_count,
7900 x_msg_data => l_msg_data,
7901 p_table_name => 'MTL_LOT_NUMBERS',
7902 p_attributes_name => 'Lot Attributes',
7903 p_inventory_item_id => p_inventory_item_id,
7904 p_organization_id => p_organization_id,
7905 p_lot_serial_number => null,
7906 p_attributes => lot_dff
7907 );
7908
7909 IF ( l_return_status <> fnd_api.g_ret_sts_success ) THEN
7910 x_return_status := l_return_status;
7911 RAISE fnd_api.g_exc_unexpected_error;
7912 END IF;
7913
7914 IF ( l_attributes_default_count > 0 ) THEN
7915 FOR i IN 1 .. l_attributes_default_count LOOP
7916 FOR j IN 1 .. lot_dff.COUNT LOOP
7917 IF (UPPER(l_attributes_default(i).column_name) = UPPER(lot_dff(j).column_name)) THEN
7918 lot_dff(j).column_value := l_attributes_default(i).column_value;
7919 END IF;
7920
7921 EXIT WHEN (UPPER(l_attributes_default(i).column_name) =
7922 UPPER(lot_dff(j).column_name));
7923 END LOOP;
7924 END LOOP;
7925 END IF;
7926
7927 l_dflex_r.application_id := 401;
7928 l_dflex_r.flexfield_name := 'Lot Attributes';
7929
7930 IF g_debug = 1 THEN
7931 print_debug('WMS is installed ', 9);
7932 END IF;
7933
7934
7935
7936 /* Get all contexts */
7937 fnd_dflex.get_contexts(flexfield => l_dflex_r, contexts => l_contexts_dr);
7938
7939 /* From the l_contexts_dr, get the position of the global context */
7940 IF g_debug = 1 THEN
7941 print_debug('Found contexts for the Flexfield Lot Attributes ', 9);
7942 END IF;
7943
7944 l_global_context := l_contexts_dr.global_context;
7945 /* Using the position get the segments in the global context which are enabled */
7946 l_context := l_contexts_dr.context_code(l_global_context);
7947
7948 IF g_debug = 1 THEN
7949 print_debug('In WMS -Global COntext is ' || l_context, 9);
7950 END IF;
7951
7952 /* Prepare the context_r type for getting the segments associated with the global context */
7953 l_context_r.flexfield := l_dflex_r;
7954 l_context_r.context_code := l_context;
7955 fnd_dflex.get_segments(CONTEXT => l_context_r, segments => l_segments_dr, enabled_only => TRUE);
7956 /* read through the segments */
7957 l_global_nsegments := l_segments_dr.nsegments;
7958
7959 IF g_debug = 1 THEN
7960 print_debug('WMs Installed .The number of segments enabled for Global context are ' || l_nsegments, 9);
7961 END IF;
7962
7963 FOR i IN 1 .. l_global_nsegments LOOP
7964 l_enabled_seg_name(v_index) := l_segments_dr.application_column_name(i);
7965 l_value_not_null_flag := NULL;
7966
7967 FOR j IN 1 .. lot_dff.COUNT LOOP
7968 IF UPPER(lot_dff(j).column_name) = UPPER(l_segments_dr.application_column_name(i)) THEN
7969 IF g_debug = 1 THEN
7970 print_debug('The segment is ' || UPPER(l_segments_dr.application_column_name(i)), 9);
7971 print_debug('The column name is ' || lot_dff(j).column_name, 9);
7972 print_debug('The column value is ' || NVL(lot_dff(j).column_value, NULL), 9);
7973 print_debug('The column type is ' || NVL(lot_dff(j).column_type, NULL), 9);
7974 END IF;
7975
7976 IF lot_dff(j).column_type = 'VARCHAR2' THEN
7977 fnd_flex_descval.set_column_value(lot_dff(j).column_name, lot_dff(j).column_value);
7978 ELSIF lot_dff(j).column_type = 'NUMBER' THEN
7979 fnd_flex_descval.set_column_value(lot_dff(j).column_name, TO_NUMBER(lot_dff(j).column_value));
7980 ELSIF lot_dff(j).column_type = 'DATE' THEN
7981 fnd_flex_descval.set_column_value(lot_dff(j).column_name, fnd_date.canonical_to_date(lot_dff(j).column_value));
7982 END IF;
7983
7984 IF lot_dff(j).column_value IS NOT NULL THEN
7985 l_value_not_null_flag := 1;
7986
7987 IF g_debug = 1 THEN
7988 print_debug('Value is not null ', 9);
7989 END IF;
7990 ELSE
7991 l_value_not_null_flag := 0;
7992
7993 IF g_debug = 1 THEN
7994 print_debug('Value is null ', 9);
7995 END IF;
7996 END IF;
7997
7998 EXIT;
7999 END IF;
8000 END LOOP;
8001
8002 IF l_segments_dr.is_required(i)
8003 AND NVL(l_value_not_null_flag, 0) = 0 THEN
8004 l_required_flag := true;
8005 IF g_debug = 1 THEN
8006 print_debug('The value is required and value is null ' || l_segments_dr.application_column_name(i), 9);
8007 END IF;
8008
8009 fnd_message.set_name('INV', 'INV_REQ_SEG_MISS');
8010 fnd_message.set_token('SEGMENT', l_segments_dr.segment_name(i));
8011 fnd_msg_pub.ADD;
8012 RAISE g_exc_error;
8013 END IF;
8014
8015 v_index := v_index + 1;
8016 END LOOP;
8017
8018 /* Initialise the l_context_value to null */
8019 l_context := NULL;
8020
8021 /*Check if the Lot Attribute Category is passed or not. If not passed
8022 Get the context for the item passed
8023 */
8024 if g_debug = 1 then
8025 print_debug('p_lot_attribute_category = ' || p_lot_attribute_category, 9);
8026 end if;
8027 IF p_lot_attribute_category IS NOT NULL THEN
8028 print_debug('setting l_context = ' || p_lot_attribute_category, 9);
8029 l_context := p_lot_attribute_category;
8030 ELSE
8031 /*Get the context for the item passed */
8032 inv_lot_sel_attr.get_context_code(l_context, p_organization_id, p_inventory_item_id, 'Lot Attributes');
8033 END IF;
8034
8035 IF l_context IS NULL AND l_required_flag = TRUE THEN
8036 fnd_message.set_name('WMS', 'WMS_NO_CONTEXT');
8037 fnd_msg_pub.ADD;
8038 RAISE g_exc_error;
8039 END IF;
8040
8041 IF g_debug = 1 THEN
8042 print_debug('Context is ' || l_context, 9);
8043 END IF;
8044
8045 FOR i in 1..l_contexts_dr.ncontexts LOOP
8046 if( l_contexts_dr.is_enabled(i) AND l_context IS NOT NULL AND
8047 UPPER(l_contexts_dr.context_code(i)) = UPPER(l_context)) THEN
8048 l_context_enabled := TRUE;
8049 /* Set flex context for validation of the value set */
8050 fnd_flex_descval.set_context_value(l_context);
8051 /* Prepare the context_r type */
8052 l_context_r.flexfield := l_dflex_r;
8053 l_context_r.context_code := l_context;
8054 fnd_dflex.get_segments(CONTEXT => l_context_r, segments => l_segments_dr, enabled_only => TRUE);
8055 /* read through the segments */
8056 l_nsegments := 0;
8057 l_nsegments := l_segments_dr.nsegments;
8058 FOR i IN 1 .. l_nsegments LOOP
8059 l_enabled_seg_name(v_index) := l_segments_dr.application_column_name(i);
8060 l_value_not_null_flag := NULL;
8061
8062 FOR j IN 1 .. lot_dff.COUNT LOOP
8063 IF UPPER(lot_dff(j).column_name) = UPPER(l_segments_dr.application_column_name(i)) THEN
8064 IF g_debug = 1 THEN
8065 print_debug('The segment is ' || UPPER(l_segments_dr.application_column_name(i)), 9);
8066 END IF;
8067
8068 IF lot_dff(j).column_type = 'VARCHAR2' THEN
8069 fnd_flex_descval.set_column_value(lot_dff(j).column_name, lot_dff(j).column_value);
8070 ELSIF lot_dff(j).column_type = 'NUMBER' THEN
8071 fnd_flex_descval.set_column_value(lot_dff(j).column_name, TO_NUMBER(lot_dff(j).column_value));
8072 ELSIF lot_dff(j).column_type = 'DATE' THEN
8073 fnd_flex_descval.set_column_value(lot_dff(j).column_name,
8074 fnd_date.canonical_to_date(lot_dff(j).column_value));
8075 END IF;
8076
8077 IF lot_dff(j).column_value IS NOT NULL THEN
8078 l_value_not_null_flag := 1;
8079 print_debug('Value is not null', 9);
8080 ELSE
8081 l_value_not_null_flag := 0;
8082 print_debug('Value is null', 9);
8083 END IF;
8084 EXIT;
8085 END IF;
8086 END LOOP;
8087
8088 IF l_segments_dr.is_required(i) AND NVL(l_value_not_null_flag, 0) = 0 THEN
8089 IF g_debug = 1 THEN
8090 print_debug('Segment is required and value is null', 9);
8091 END IF;
8092
8093 fnd_message.set_name('INV', 'INV_REQ_SEG_MISS');
8094 fnd_message.set_token('SEGMENT', l_segments_dr.segment_name(i));
8095 fnd_msg_pub.ADD;
8096 RAISE g_exc_error;
8097 END IF;
8098 v_index := v_index + 1;
8099 END LOOP;
8100 END IF;
8101 END LOOP;
8102 IF l_context IS NOT NULL AND l_context_enabled = TRUE AND l_global_nsegments > 0 then
8103 IF fnd_flex_descval.validate_desccols(appl_short_name => 'INV', desc_flex_name => 'Lot Attributes', values_or_ids => 'I'
8104 , validation_date => SYSDATE) THEN
8105 IF g_debug = 1 THEN
8106 print_debug('Value set validation successful', 9);
8107 print_debug('Program LOT_DFF_VALIDATE has completed succcessfuly', 9);
8108 END IF;
8109 ELSE
8110 IF g_debug = 1 THEN
8111 error_segment := fnd_flex_descval.error_segment;
8112 print_debug('Value set validation failed for segment ' || error_segment, 9);
8113 RAISE errors_received;
8114 END IF;
8115 END IF;
8116 end if;
8117 EXCEPTION
8118 WHEN g_exc_error THEN
8119 print_debug('Validation error', 9);
8120 x_return_status := inv_lot_api_pub.g_ret_sts_error;
8121 ROLLBACK TO wms_lot_dff_validate;
8122
8123 IF g_debug = 1 THEN
8124 print_debug('Program LOT_DFF_VALIDATE has completed with validation errors', 9);
8125 END IF;
8126
8127 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
8128 WHEN errors_received THEN
8129 x_return_status := inv_lot_api_pub.g_ret_sts_error;
8130
8131 IF g_debug = 1 THEN
8132 print_debug('Program LOT_DFF_VALIDATE has completed with errors_received', 9);
8133 END IF;
8134
8135 error_msg := fnd_flex_descval.error_message;
8136 s := 1;
8137 e := 200;
8138
8139 --print_debug('Here are the error messages: ',9);
8140 WHILE e < 5001
8141 AND SUBSTR(error_msg, s, e) IS NOT NULL LOOP
8142 fnd_message.set_name('INV', 'INV_FND_GENERIC_MSG');
8143 fnd_message.set_token('MSG', SUBSTR(error_msg, s, e));
8144 fnd_msg_pub.ADD;
8145 print_debug(SUBSTR(error_msg, s, e), 9);
8146 s := s + 200;
8147 e := e + 200;
8148 END LOOP;
8149
8150 ROLLBACK TO wms_lot_dff_validate;
8151 WHEN OTHERS THEN
8152 x_return_status := inv_lot_api_pub.g_ret_sts_unexp_error;
8153 ROLLBACK TO wms_lot_dff_validate;
8154 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
8155
8156 IF g_debug = 1 THEN
8157 print_debug('Program LOT_DFF_VALIDATE has completed with errors. In when others ', 9);
8158 print_debug('Error ' || SQLERRM, 9);
8159 END IF;
8160 END wms_lot_attr_validate;
8161
8162
8163 ---------------------------------------------------------End Of J Develop--------------------------------
8164 PROCEDURE set_wms_installed_flag (
8165 p_wms_installed_flag IN VARCHAR2)
8166 IS
8167 BEGIN
8168 G_WMS_INSTALLED := p_wms_installed_flag;
8169 END set_wms_installed_flag;
8170
8171
8172
8173 /* +==========================================================================+
8174 | PROCEDURE NAME |
8175 | validate_child_lot |
8176 | |
8177 | RETURNS |
8178 | Via x_ OUT parameters |
8179 | |
8180 | HISTORY |
8181 | Created Joe DiIorio 05/20/2004 |
8182 | |
8183 +==========================================================================+ */
8184
8185
8186 PROCEDURE validate_child_lot
8187 ( p_api_version IN NUMBER
8188 , p_init_msg_list IN VARCHAR2 DEFAULT FND_API.G_FALSE
8189 , p_commit IN VARCHAR2 DEFAULT FND_API.G_FALSE
8190 , p_validation_level IN NUMBER DEFAULT FND_API.G_VALID_LEVEL_FULL
8191 , p_organization_id IN NUMBER
8192 , p_inventory_item_id IN NUMBER
8193 , p_parent_lot_number IN VARCHAR2
8194 , p_child_lot_number IN VARCHAR2
8195 , x_return_status OUT NOCOPY VARCHAR2
8196 , x_msg_count OUT NOCOPY NUMBER
8197 , x_msg_data OUT NOCOPY VARCHAR2
8198 )
8199 IS
8200
8201
8202 l_api_name CONSTANT VARCHAR2(30) := 'validate_child_lot';
8203 l_api_version CONSTANT NUMBER := 1.0;
8204 G_PKG_NAME CONSTANT VARCHAR2(30) := 'INV_CHILD_LOT_GRP';
8205
8206 /*====================================
8207 Cursor to get Item Master setup.
8208 ======================================*/
8209
8210 CURSOR get_item_data IS
8211 SELECT child_lot_flag, parent_child_generation_flag,
8212 child_lot_prefix, child_lot_validation_flag,
8213 child_lot_starting_number
8214 FROM mtl_system_items_b -- NSRIVAST, Changed the name to MTL_SYSTEM_ITEMS_B as per review comments by Shelly
8215 WHERE organization_id = p_organization_id
8216 AND inventory_item_id = p_inventory_item_id;
8217
8218 l_item_child_lot_flag MTL_SYSTEM_ITEMS.CHILD_LOT_FLAG%TYPE;
8219 l_item_parent_child_gen_flag MTL_SYSTEM_ITEMS.PARENT_CHILD_GENERATION_FLAG%TYPE;
8220 l_item_child_lot_prefix MTL_SYSTEM_ITEMS.CHILD_LOT_PREFIX%TYPE;
8221 l_item_child_lot_validation MTL_SYSTEM_ITEMS.CHILD_LOT_VALIDATION_FLAG%TYPE;
8222 l_item_child_lot_startno MTL_SYSTEM_ITEMS.CHILD_LOT_STARTING_NUMBER%TYPE;
8223 L_ITEM_LOT_LENGTH CONSTANT NUMBER := 80;
8224
8225
8226 /*====================================
8227 Cursor to get child mtl parms.
8228 ====================================*/
8229
8230 CURSOR get_child_parms IS
8231 SELECT lot_number_generation,
8232 parent_child_generation_flag,
8233 child_lot_alpha_prefix, child_lot_number_length,
8234 child_lot_validation_flag, child_lot_zero_padding_flag
8235 FROM mtl_parameters
8236 WHERE organization_id = p_organization_id;
8237
8238 l_prm_lot_number_generation MTL_PARAMETERS.lot_number_generation%TYPE;
8239 l_prm_parent_child_gen_flag MTL_PARAMETERS.parent_child_generation_flag%TYPE;
8240 l_prm_child_lot_alpha_prefix MTL_PARAMETERS.child_lot_alpha_prefix%TYPE;
8241 l_prm_child_lot_number_length MTL_PARAMETERS.child_lot_number_length%TYPE;
8242 l_prm_child_lot_val_flag MTL_PARAMETERS.child_lot_validation_flag%TYPE;
8243 l_prm_zero_padding_flag MTL_PARAMETERS.child_lot_zero_padding_flag%TYPE;
8244
8245 l_common_child_gen_flag MTL_PARAMETERS.parent_child_generation_flag%TYPE;
8246 l_parent_length NUMBER;
8247 l_child_prefix_length NUMBER;
8248 l_child_prefix VARCHAR2(30);
8249 l_final_start NUMBER;
8250 l_final_length NUMBER;
8251 l_final_suffix VARCHAR2(80);
8252 l_final_suffix_numeric NUMBER;
8253 l_child_lot_length NUMBER;
8254 /*=========================================================
8255 For overall length if Item controlled lot generation
8256 it is = 80. For Org control it is what is specified.
8257 If not specified, the value is 80.
8258 =========================================================*/
8259 l_overall_length NUMBER;
8260
8261 l_num_error EXCEPTION;
8262 PRAGMA EXCEPTION_INIT(l_num_error,-06502);
8263
8264
8265
8266
8267 BEGIN
8268 IF FND_API.to_boolean(p_init_msg_list) THEN
8269 FND_MSG_PUB.Initialize;
8270 END IF;
8271
8272 -- Standard call to check for call compatibility.
8273 IF NOT FND_API.Compatible_API_Call ( l_api_version ,
8274 p_api_version ,
8275 l_api_name ,
8276 G_PKG_NAME ) THEN
8277 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8278 END IF;
8279 x_return_status := FND_API.G_RET_STS_SUCCESS;
8280
8281
8282 /*==========================================
8283 Get Item Information
8284 ========================================*/
8285 OPEN get_item_data;
8286 FETCH get_item_data INTO
8287 l_item_child_lot_flag, l_item_parent_child_gen_flag,
8288 l_item_child_lot_prefix, l_item_child_lot_validation,
8289 l_item_child_lot_startno;
8290 IF (get_item_data%NOTFOUND) THEN
8291 CLOSE get_item_data;
8292 fnd_message.set_name ('INV' , 'INV_CL_ITEM_ERR');
8293 fnd_msg_pub.ADD;
8294 RAISE fnd_api.g_exc_error;
8295 END IF;
8296 CLOSE get_item_data;
8297
8298 /*==========================================
8299 If Item not autosplit enabled stop.
8300 ========================================*/
8301 IF (nvl(l_item_child_lot_flag,'N') = 'N') THEN
8302 fnd_message.set_name ('INV' , 'INV_CL_CHILD_LOT_DISABLED');
8303 fnd_msg_pub.ADD;
8304 RAISE fnd_api.g_exc_error;
8305 END IF;
8306
8307 /*==========================================
8308 Get mtl_parameters information.
8309 ========================================*/
8310
8311 OPEN get_child_parms;
8312 FETCH get_child_parms INTO
8313 l_prm_lot_number_generation, l_prm_parent_child_gen_flag,
8314 l_prm_child_lot_alpha_prefix,
8315 l_prm_child_lot_number_length, l_prm_child_lot_val_flag,
8316 l_prm_zero_padding_flag;
8317 IF (get_child_parms%NOTFOUND) THEN
8318 CLOSE get_child_parms;
8319 fnd_message.set_name ('INV' , 'INV_CL_GET_PARM_ERR');
8320 fnd_msg_pub.ADD;
8321 RAISE fnd_api.g_exc_error;
8322 END IF;
8323 CLOSE get_child_parms;
8324
8325 /*==========================================
8326 If User Level Generation no check is
8327 required. Just return.
8328 ========================================*/
8329
8330 IF (l_prm_lot_number_generation = 3) THEN
8331 x_return_status := FND_API.G_RET_STS_SUCCESS;
8332 RETURN;
8333 END IF;
8334
8335 /*==========================================
8336 If Validation is off, just return.
8337 Values for prm_lot_number_generation.
8338 1 = org, 2 = item, 3 = user.
8339 ========================================*/
8340
8341 IF (l_prm_lot_number_generation = 1) THEN
8342 l_common_child_gen_flag := l_prm_parent_child_gen_flag;
8343 IF (nvl(l_prm_child_lot_val_flag,'N') = 'N') THEN
8344 RETURN;
8345 END IF;
8346 ELSE -- must be Item control
8347 l_common_child_gen_flag := l_item_parent_child_gen_flag;
8348 IF (nvl(l_item_child_lot_validation,'N') = 'N') THEN
8349 RETURN;
8350 END IF;
8351 END IF;
8352
8353
8354 /*==========================================
8355 Validate the Child Lot.
8356 Get the setup data for validation.
8357 ========================================*/
8358
8359 l_parent_length := NVL(LENGTHB(p_parent_lot_number),0);
8360
8361 IF (l_prm_lot_number_generation = 1) THEN --org
8362 l_child_prefix_length := NVL(LENGTHB(l_prm_child_lot_alpha_prefix),0);
8363 l_child_prefix := l_prm_child_lot_alpha_prefix;
8364 l_overall_length := NVL(l_prm_child_lot_number_length,80);
8365 ELSE --item
8366 l_child_prefix_length := NVL(LENGTHB(l_item_child_lot_prefix),0);
8367 l_child_prefix := l_item_child_lot_prefix;
8368 l_overall_length := L_ITEM_LOT_LENGTH;
8369 END IF;
8370
8371
8372 /*==========================================
8373 Check if Parent Lot is prefix to
8374 Child Lot when Lot+Child generation
8375 is in effect.
8376 ========================================*/
8377
8378 IF (l_common_child_gen_flag = 'C') THEN
8379 /*===================================================
8380 Prefix of child lot must match parent lot number.
8381 ===================================================*/
8382 IF (p_parent_lot_number = SUBSTRB(p_child_lot_number,1,l_parent_length)) THEN
8383 /*===================================================
8384 After the prefix the next characters must match
8385 the child lot prefix.
8386 ===================================================*/
8387 IF (NVL(l_child_prefix,'ZZZZ') = NVL(SUBSTRB(p_child_lot_number, l_parent_length + 1, l_child_prefix_length),'ZZZZ')) THEN
8388 NULL;
8389 ELSE
8390 fnd_message.set_name ('INV' , 'INV_CL_SUFFIX_MISMATCH');
8391 fnd_msg_pub.ADD;
8392 RAISE fnd_api.g_exc_error;
8393 END IF;
8394 ELSE
8395 fnd_message.set_name ('INV' , 'INV_CL_PREFIX_MISMATCH');
8396 fnd_msg_pub.ADD;
8397 RAISE fnd_api.g_exc_error;
8398 END IF;
8399 ELSE
8400 /*=======================================
8401 For Lot/Lot validation just return.
8402 =======================================*/
8403 RETURN;
8404 END IF;
8405
8406 /*============================================
8407 Now check if remaining suffix is numeric.
8408 ============================================*/
8409
8410
8411 l_final_start := l_parent_length + NVL(l_child_prefix_length,0) + 1;
8412 l_final_length := 80 - l_final_start - 1;
8413
8414 l_final_suffix :=
8415 SUBSTRB(p_child_lot_number, l_final_start);
8416
8417 IF (l_final_suffix IS NULL) THEN
8418 fnd_message.set_name ('INV' , 'INV_CL_SUFFIX_NONUMERIC');
8419 fnd_msg_pub.ADD;
8420 RAISE fnd_api.g_exc_error;
8421 END IF;
8422
8423 /*============================================
8424 Exception will trap the following command
8425 if suffix is not numeric.
8426 ============================================*/
8427
8428 l_final_suffix_numeric := TO_NUMBER(l_final_suffix);
8429
8430 /*===============================================
8431 Check if padded correctly. If padding is
8432 on must verify that total length of suffix
8433 is correct. Only done at org level control.
8434 If Item level check if starting number is
8435 above suffix number,
8436 ===============================================*/
8437
8438 l_child_lot_length := NVL(LENGTHB(p_child_lot_number),0);
8439
8440 IF (l_prm_lot_number_generation = 1) THEN --org
8441 IF (l_prm_zero_padding_flag = 'Y') THEN
8442 IF (l_overall_length <> l_child_lot_length) THEN
8443 fnd_message.set_name ('INV' , 'INV_CL_PAD_ERROR');
8444 fnd_msg_pub.ADD;
8445 RAISE fnd_api.g_exc_error;
8446 END IF;
8447 END IF;
8448 ELSE -- Item
8449 IF (NVL(l_item_child_lot_startno,0) > l_final_suffix_numeric) THEN
8450 fnd_message.set_name ('INV' , 'INV_CL_STARTING_SUFFIX_ERR');
8451 fnd_msg_pub.ADD;
8452 RAISE fnd_api.g_exc_error;
8453 END IF;
8454 END IF;
8455
8456 /*============================================
8457 Check if total length is correct.
8458 Item generation child lots can be up to 80
8459 in length. For org generated lots the
8460 length indicated is used. Otherwise use 80.
8461 ============================================*/
8462
8463 IF (l_child_lot_length > l_overall_length ) THEN
8464 fnd_message.set_name ('INV' , 'INV_CL_OVERALL_LENGTH');
8465 fnd_msg_pub.ADD;
8466 RAISE fnd_api.g_exc_error;
8467 END IF;
8468 RETURN;
8469
8470 EXCEPTION
8471
8472 WHEN l_num_error THEN
8473 fnd_message.set_name ('INV' , 'INV_CL_SUFFIX_NONUMERIC');
8474 fnd_msg_pub.ADD;
8475 x_return_status := FND_API.G_RET_STS_ERROR;
8476 FND_MSG_PUB.Count_AND_GET
8477 (p_count => x_msg_count, p_data => x_msg_data);
8478 WHEN FND_API.G_EXC_ERROR THEN
8479 x_return_status := FND_API.G_RET_STS_ERROR;
8480 FND_MSG_PUB.Count_AND_GET
8481 (p_count => x_msg_count, p_data => x_msg_data);
8482
8483 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8484 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8485 FND_MSG_PUB.Count_AND_GET
8486 (p_count => x_msg_count, p_data => x_msg_data);
8487
8488 WHEN OTHERS THEN
8489 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8490 FND_MSG_PUB.Count_AND_GET
8491 (p_count => x_msg_count, p_data => x_msg_data);
8492
8493 END validate_child_lot;
8494
8495
8496 FUNCTION validate_lot_indivisible
8497 ( p_api_version IN NUMBER
8498 , p_init_msg_list IN VARCHAR2 DEFAULT FND_API.G_FALSE
8499 , p_commit IN VARCHAR2 DEFAULT FND_API.G_FALSE
8500 , p_validation_level IN NUMBER DEFAULT FND_API.G_VALID_LEVEL_FULL
8501 , p_transaction_type_id IN NUMBER
8502 , p_organization_id IN NUMBER
8503 , p_inventory_item_id IN NUMBER
8504 , p_revision IN VARCHAR2
8505 , p_subinventory_code IN VARCHAR2
8506 , p_locator_id IN NUMBER
8507 , p_lot_number IN VARCHAR2
8508 , p_primary_quantity IN NUMBER
8509 , p_qoh IN NUMBER DEFAULT NULL
8510 , p_atr IN NUMBER DEFAULT NULL
8511 , x_return_status OUT NOCOPY VARCHAR2
8512 , x_msg_count OUT NOCOPY NUMBER
8513 , x_msg_data OUT NOCOPY VARCHAR2
8514 ) RETURN BOOLEAN
8515 IS
8516 l_primary_quantity number;
8517 l_secondary_quantity number; /* Bug#11729772 */
8518 l_return boolean;
8519 CREATE_TREE_ERROR EXCEPTION;
8520 QUERY_TREE_ERROR EXCEPTION;
8521 BEGIN
8522 /* Fix for Bug#11729772. Added p_secondary_quantity and x_secondary_quantity
8523 parameters in following call
8524 */
8525 l_return := validate_lot_indivisible
8526 ( p_api_version => p_api_version
8527 , p_init_msg_list => p_init_msg_list
8528 , p_commit => p_commit
8529 , p_validation_level => p_validation_level
8530 , p_transaction_type_id => p_transaction_type_id
8531 , p_organization_id => p_organization_id
8532 , p_inventory_item_id => p_inventory_item_id
8533 , p_revision => p_revision
8534 , p_subinventory_code => p_subinventory_code
8535 , p_locator_id => p_locator_id
8536 , p_lot_number => p_lot_number
8537 , p_primary_quantity => p_primary_quantity
8538 , p_secondary_quantity => l_secondary_quantity
8539 , p_qoh => p_qoh
8540 , p_atr => p_atr
8541 , x_primary_quantity => l_primary_quantity
8542 , x_secondary_quantity => l_secondary_quantity
8543 , x_return_status => x_return_status
8544 , x_msg_count => x_msg_count
8545 , x_msg_data => x_msg_data
8546 );
8547 RETURN l_return;
8548
8549 EXCEPTION
8550
8551 WHEN CREATE_TREE_ERROR THEN
8552 print_debug(' CREATE_TREE error...');
8553 x_return_status := FND_API.G_RET_STS_ERROR;
8554 FND_MSG_PUB.Count_AND_GET
8555 (p_count => x_msg_count, p_data => x_msg_data);
8556 RETURN FALSE;
8557
8558 WHEN QUERY_TREE_ERROR THEN
8559 print_debug(' QUERY_TREE error...');
8560 x_return_status := FND_API.G_RET_STS_ERROR;
8561 FND_MSG_PUB.Count_AND_GET
8562 (p_count => x_msg_count, p_data => x_msg_data);
8563 RETURN FALSE;
8564
8565 WHEN FND_API.G_EXC_ERROR THEN
8566 print_debug(' EXCP error...');
8567 x_return_status := FND_API.G_RET_STS_ERROR;
8568 FND_MSG_PUB.Count_AND_GET
8569 (p_count => x_msg_count, p_data => x_msg_data);
8570 RETURN FALSE;
8571
8572 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8573 print_debug(' UNEXCP error...');
8574 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8575 FND_MSG_PUB.Count_AND_GET
8576 (p_count => x_msg_count, p_data => x_msg_data);
8577 RETURN FALSE;
8578
8579 WHEN OTHERS THEN
8580 print_debug(' OTHERS error...'||SQLERRM);
8581 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8582 FND_MSG_PUB.Count_AND_GET
8583 (p_count => x_msg_count, p_data => x_msg_data);
8584 RETURN FALSE;
8585
8586 END validate_lot_indivisible;
8587
8588
8589 /*+==========================================================================+
8590 | PROCEDURE NAME |
8591 | validate_lot_indivisible |
8592 | This function validates, from the IN parameters, |
8593 | whether a lot transaction can be added into the inventory |
8594 | regarding the lot definition. |
8595 | |
8596 | IN PARAMETERS |
8597 | - the transaction details (trx_type, item, org, lot, rev) |
8598 | - the primary quantity of the transaction |
8599 | - IF qoh and atr are passed, THEN quantity tree is bypassed. |
8600 | - IF qoh and atr are NULL, THEN quantity tree is called (recommanded) |
8601 | |
8602 | RETURNS |
8603 | TRUE if the lot transaction is valid |
8604 | FALSE if the lot transaction is NOT valid because of lot indivisible |
8605 | Via x_ OUT parameters |
8606 | |
8607 | HISTORY |
8608 | Created Olivier Daboval 17-Jun-2004 |
8609 | Bug 4122106 : using p_primary_quantity as an ABS value in the tests |
8610 | |
8611 +==========================================================================+ */
8612 FUNCTION validate_lot_indivisible
8613 ( p_api_version IN NUMBER
8614 , p_init_msg_list IN VARCHAR2 DEFAULT FND_API.G_FALSE
8615 , p_commit IN VARCHAR2 DEFAULT FND_API.G_FALSE
8616 , p_validation_level IN NUMBER DEFAULT FND_API.G_VALID_LEVEL_FULL
8617 , p_transaction_type_id IN NUMBER
8618 , p_organization_id IN NUMBER
8619 , p_inventory_item_id IN NUMBER
8620 , p_revision IN VARCHAR2
8621 , p_subinventory_code IN VARCHAR2
8622 , p_locator_id IN NUMBER
8623 , p_lot_number IN VARCHAR2
8624 , p_lpn_id IN NUMBER DEFAULT NULL /*Bug#10113239*/
8625 , p_primary_quantity IN NUMBER
8626 , p_secondary_quantity IN NUMBER DEFAULT NULL /* Fix for Bug#11729772 */
8627 , p_qoh IN NUMBER DEFAULT NULL
8628 , p_atr IN NUMBER DEFAULT NULL
8629 , x_primary_quantity OUT NOCOPY NUMBER
8630 , x_secondary_quantity OUT NOCOPY NUMBER /* Fix for Bug#11729772 */
8631 , x_return_status OUT NOCOPY VARCHAR2
8632 , x_msg_count OUT NOCOPY NUMBER
8633 , x_msg_data OUT NOCOPY VARCHAR2
8634 ) RETURN BOOLEAN
8635 IS
8636
8637
8638 l_api_name CONSTANT VARCHAR2(30) := 'validate_lot_indivisible';
8639 l_api_version CONSTANT NUMBER := 1.0;
8640 G_PKG_NAME CONSTANT VARCHAR2(30) := 'INV_LOT_API_PUB';
8641
8642 l_return BOOLEAN;
8643 l_lot_divisible VARCHAR2(1);
8644 l_lot_control_code pls_integer;
8645 l_transaction_action_id NUMBER;
8646 l_transaction_source_type_id NUMBER;
8647
8648 l_return_status VARCHAR2(2);
8649 l_msg_count NUMBER;
8650 l_msg_data VARCHAR2(2000);
8651 l_tree_mode NUMBER;
8652 l_is_revision_control BOOLEAN;
8653 l_is_lot_control BOOLEAN;
8654 l_is_serial_control BOOLEAN;
8655 l_grade_code VARCHAR2(150) := NULL;
8656 l_check_qties BOOLEAN;
8657 l_lot_no VARCHAR2(150) := NULL;
8658
8659 CREATE_TREE_ERROR EXCEPTION;
8660 QUERY_TREE_ERROR EXCEPTION;
8661 l_tree_id INTEGER;
8662 l_qoh NUMBER;
8663 l_rqoh NUMBER;
8664 l_qr NUMBER;
8665 l_qs NUMBER;
8666 l_att NUMBER;
8667 l_atr NUMBER;
8668 l_atr_plus NUMBER;
8669 l_sqoh NUMBER;
8670 l_srqoh NUMBER;
8671 l_sqr NUMBER;
8672 l_sqs NUMBER;
8673 l_satt NUMBER;
8674 l_satr NUMBER;
8675 ll_qoh NUMBER;
8676 ll_rqoh NUMBER;
8677 ll_qr NUMBER;
8678 ll_qs NUMBER;
8679 ll_att NUMBER;
8680 ll_atr NUMBER;
8681 ll_atr_plus NUMBER;
8682 ll_sqoh NUMBER;
8683 ll_srqoh NUMBER;
8684 ll_sqr NUMBER;
8685 ll_sqs NUMBER;
8686 ll_satt NUMBER;
8687 ll_satr NUMBER;
8688 l_revision_qty_control_code NUMBER ; --Bug 12716806
8689 l_revision mtl_material_transactions.revision%type; --Bug 12716806
8690
8691 /*====================================
8692 Get item details:
8693 - lot_divisible_flag = Y(divisible), N(indivisible), NULL(divisible)
8694 - lot_control_code = 1(notLotControlled), 2(lotControlled)
8695 - revision_qty_control_code = 1(notRevControlled), 2(revControlled)
8696 ======================================*/
8697 /* Fix for Bug#11729772. Added tracking quantity_ind in following cursor */
8698 CURSOR get_item_details( org_id IN NUMBER
8699 , item_id IN NUMBER) IS
8700 SELECT NVL( lot_divisible_flag, 'Y')
8701 ,lot_control_code
8702 ,tracking_quantity_ind
8703 FROM mtl_system_items_b -- NSRIVAST, Changed the name to MTL_SYSTEM_ITEMS_B as per review comments by Shelly
8704 WHERE organization_id = org_id
8705 AND inventory_item_id = item_id;
8706
8707 l_tracking_quantity_ind VARCHAR2(5);
8708 /*====================================
8709 Get transaction action from transaction type:
8710 ======================================*/
8711 CURSOR get_transaction_details( trx_type_id IN NUMBER) IS
8712 SELECT transaction_action_id
8713 , transaction_source_type_id
8714 FROM mtl_transaction_types
8715 WHERE transaction_type_id = trx_type_id;
8716
8717 /*====================================
8718 Get new lot information:
8719 ======================================*/
8720 /* Jalaj Srivastava Bug 4634410
8721 This cursor is no longer used */
8722 /*
8723 CURSOR get_new_lot_details( org_id IN NUMBER
8724 , item_id IN NUMBER
8725 , lot_no IN VARCHAR2) IS
8726 SELECT lot_number
8727 FROM mtl_lot_numbers
8728 WHERE lot_number = lot_no
8729 AND inventory_item_id = item_id
8730 AND organization_id = org_id; */
8731
8732 /*Bug#9717803 any issue transaction other than the misc issue */
8733 CURSOR cur_any_consumptions IS
8734 SELECT 1
8735 FROM mtl_transaction_lot_numbers mtln, mtl_material_transactions mmt
8736 WHERE mtln.organization_id = p_organization_id
8737 AND mtln.inventory_item_id = p_inventory_item_id
8738 AND mtln.lot_number = p_lot_number
8739 AND mtln.transaction_id = mmt.transaction_id
8740 AND (mmt.transaction_action_id = 1 and mmt.transaction_type_id not in (1,32));
8741 l_exists NUMBER;
8742 BEGIN
8743
8744 print_debug('Entering validate_lot_indivisible. transaction_type_id='||p_transaction_type_id||', prim_qty='||p_primary_quantity||'.');
8745 print_debug(' ... org='||p_organization_id||', item='||p_inventory_item_id||', rev='||p_revision||', sub='||p_subinventory_code||', loct='||p_locator_id);
8746 print_debug(' ... lot='||p_lot_number||', p_qoh='||p_qoh||', p_atr='||p_atr);
8747
8748 IF FND_API.to_boolean(p_init_msg_list) THEN
8749 FND_MSG_PUB.Initialize;
8750 END IF;
8751
8752 -- Standard call to check for call compatibility.
8753 IF NOT FND_API.Compatible_API_Call( l_api_version
8754 , p_api_version
8755 , l_api_name
8756 , G_PKG_NAME)
8757 THEN
8758 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8759 END IF;
8760 x_return_status := FND_API.G_RET_STS_SUCCESS;
8761
8762 /*==========================================
8763 Get item details:
8764 ========================================*/
8765 OPEN get_item_details( p_organization_id, p_inventory_item_id);
8766 FETCH get_item_details
8767 INTO l_lot_divisible,l_lot_control_code,l_tracking_quantity_ind ; /* Fix for Bug#11729772 */
8768 IF (get_item_details%NOTFOUND)
8769 THEN
8770 CLOSE get_item_details;
8771 FND_MESSAGE.SET_NAME('INV','ITEM_NOT_FOUND');
8772 FND_MESSAGE.SET_TOKEN('ORGANIZATION_ID', p_organization_id);
8773 FND_MESSAGE.SET_TOKEN('INVENTORY_ITEM_ID', p_inventory_item_id);
8774 FND_MSG_PUB.ADD;
8775 RAISE FND_API.G_EXC_ERROR;
8776 END IF;
8777 CLOSE get_item_details;
8778
8779 /* Jalaj Srivastava Bug 4634410
8780 We should always validate
8781 because same indivisible lot could be created
8782 in 2 lines in diff sub/loc.
8783 commented new lot logic below*/
8784 /*==========================================
8785 Get new lot details:
8786 ========================================*/
8787 /*
8788 OPEN get_new_lot_details(p_organization_id, p_inventory_item_id, p_lot_number);
8789 FETCH get_new_lot_details
8790 INTO l_lot_no;
8791
8792 IF (get_new_lot_details%NOTFOUND)
8793 THEN
8794 -- The lot is a NEW lot.... The trx is always valid.
8795 print_debug(' the lot is NEW. trx valid always.');
8796 l_new_lot := TRUE;
8797 ELSE
8798 print_debug(' the lot is NOT NEW. More check to follow.');
8799 l_new_lot := FALSE;
8800 END IF;
8801 CLOSE get_new_lot_details;
8802 */
8803
8804 IF (l_lot_control_code = 2 AND l_lot_divisible = 'N' AND p_lot_number IS NOT NULL)
8805 THEN
8806 print_debug(' the lot is NOT divisible... Return can be false.');
8807 /*==========================================
8808 Get transaction details:
8809 ========================================*/
8810 OPEN get_transaction_details(p_transaction_type_id);
8811 FETCH get_transaction_details
8812 INTO l_transaction_action_id
8813 , l_transaction_source_type_id;
8814 IF (get_transaction_details%NOTFOUND)
8815 THEN
8816 CLOSE get_transaction_details;
8817 FND_MESSAGE.SET_NAME('INV','TRX_TYPE_NOT_FOUND');
8818 FND_MESSAGE.SET_TOKEN('TRANSACTION_TYPE_ID', p_transaction_type_id);
8819 FND_MSG_PUB.ADD;
8820 RAISE FND_API.G_EXC_ERROR;
8821 END IF;
8822 CLOSE get_transaction_details;
8823
8824 print_debug('... transaction_type_id='||p_transaction_type_id||', trx_action='||l_transaction_action_id||', trx_source_type='||l_transaction_source_type_id);
8825
8826 /*==========================================
8827 If check quantities is needed, then calls Quantity Tree:
8828 ========================================*/
8829 IF (p_qoh IS NULL or p_atr IS NULL)
8830 THEN
8831 l_check_qties := TRUE;
8832 END IF;
8833
8834 IF (l_check_qties = TRUE)
8835 THEN
8836 print_debug('Checking the quantities');
8837 /*==========================================
8838 Set local variables from given parameters
8839 ========================================*/
8840 -- I think that p_transaction_type_id is NEVER NULL !!!!.
8841 IF (p_transaction_type_id IS NOT NULL)
8842 THEN
8843 -- Transaction mode
8844 l_tree_mode := 2;
8845 ELSE
8846 --Reservation mode
8847 l_tree_mode := 1;
8848 END IF;
8849
8850 IF (p_revision IS NOT NULL)
8851 THEN
8852 l_is_revision_control := TRUE;
8853 ELSE
8854 l_is_revision_control := FALSE;
8855 END IF;
8856
8857 IF (p_lot_number IS NOT NULL)
8858 THEN
8859 l_is_lot_control := TRUE;
8860 ELSE
8861 l_is_lot_control := FALSE;
8862 END IF;
8863
8864 l_is_serial_control := FALSE;
8865
8866 /**Begin Bug 12716806 */
8867 l_revision := p_revision;
8868 IF (p_transaction_type_id = 36 AND p_revision IS NOT NULL) THEN
8869
8870 SELECT Nvl(revision_qty_control_code,1)
8871 INTO l_revision_qty_control_code
8872 FROM mtl_system_items
8873 WHERE inventory_item_id = p_inventory_item_id
8874 AND organization_id = p_organization_id;
8875
8876 print_debug('In going into RTV get item revision revision_qty_control_code: '
8877 || l_revision_qty_control_code
8878 || ', p_revision : ' || p_revision);
8879
8880 IF l_revision_qty_control_code = 1 THEN
8881 l_is_revision_control := FALSE;
8882 l_revision := NULL;
8883 END IF ;
8884
8885 END IF;
8886
8887 /**End Bug 12716806 */
8888
8889 /*==========================================
8890 Call Quantity Tree for checking whether
8891 it is possible to generate a transation for this lot.
8892 ========================================*/
8893 /* Jalaj Srivastava Bug 4634410
8894 commenting code below.
8895 we will call INV_QUANTITY_TREE_PUB to query quantities */
8896 /*
8897 print_debug('Calling INV_QUANTITY_TREE_GRP.CREATE_TREE api');
8898 INV_QUANTITY_TREE_GRP.CREATE_TREE
8899 ( p_api_version_number => p_api_version
8900 , p_init_msg_lst => p_init_msg_list
8901 , x_return_status => l_return_status
8902 , x_msg_count => l_msg_count
8903 , x_msg_data => l_msg_data
8904 , p_organization_id => p_organization_id
8905 , p_inventory_item_id => p_inventory_item_id
8906 , p_tree_mode => l_tree_mode
8907 , p_is_revision_control => l_is_revision_control
8908 , p_is_lot_control => l_is_lot_control
8909 , p_is_serial_control => l_is_serial_control
8910 , p_grade_code => l_grade_code
8911 , p_demand_source_type_id => 13
8912 , p_demand_source_header_id => -1
8913 , p_demand_source_line_id => -1
8914 , p_demand_source_name => -1
8915 , p_lot_expiration_date => sysdate
8916 , p_onhand_source => 3
8917 , x_tree_id => l_tree_id);
8918
8919 print_debug('return status INV_QUANTITY_TREE_GRP.CREATE_TREE api'||l_return_status);
8920 -- NSRIVAST, using <> as per GSCC compliance
8921 IF (l_return_status <> FND_API.G_RET_STS_SUCCESS)
8922 THEN
8923 print_debug('Returning error from INV_QUANTITY_TREE_GRP.CREATE_TREE');
8924 RAISE CREATE_TREE_ERROR;
8925 END IF;
8926 */
8927 print_debug('Calling INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES api');
8928 INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES
8929 ( p_api_version_number => p_api_version
8930 , p_init_msg_lst => p_init_msg_list
8931 , x_return_status => l_return_status
8932 , x_msg_count => l_msg_count
8933 , x_msg_data => l_msg_data
8934 , p_tree_mode => l_tree_mode
8935 , p_organization_id => p_organization_id
8936 , p_inventory_item_id => p_inventory_item_id
8937 , p_is_revision_control => l_is_revision_control
8938 , p_is_lot_control => l_is_lot_control
8939 , p_is_serial_control => l_is_serial_control
8940 , p_grade_code => l_grade_code
8941 , p_revision => l_revision --p_revision Bug 12716806
8942 , p_lot_number => p_lot_number
8943 , p_subinventory_code => NULL -- p_subinventory_code Bug# 4233182 pass null instead of p_subinventory_code
8944 , p_locator_id => NULL -- p_locator_id Bug# 4233182 pass null instead of p_locator_id
8945 , x_qoh => l_qoh
8946 , x_rqoh => l_rqoh
8947 , x_qr => l_qr
8948 , x_qs => l_qs
8949 , x_att => l_att
8950 , x_atr => l_atr
8951 , x_sqoh => l_sqoh
8952 , x_srqoh => l_srqoh
8953 , x_sqr => l_sqr
8954 , x_sqs => l_sqs
8955 , x_satt => l_satt
8956 , x_satr => l_satr
8957 );
8958
8959 print_debug('Return Status INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES api'||l_return_status);
8960 print_debug(' onhand='||l_qoh||' l_atr --> '||l_atr);
8961 --Returning quantity to calling procedure
8962 x_primary_quantity := l_qoh;
8963 /* Start fix for Bug 11729772 */
8964 --
8965 x_secondary_quantity := NULL;
8966 IF (l_tracking_quantity_ind = 'PS') THEN
8967 x_secondary_quantity := l_sqoh;
8968 END IF;
8969
8970 -- NSRIVAST, using <> as per GSCC compliance
8971 IF (l_return_status <> FND_API.G_RET_STS_SUCCESS)
8972 THEN
8973 print_debug('Returning error from INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
8974 RAISE QUERY_TREE_ERROR;
8975 END IF;
8976
8977 ELSE
8978 -- the quantities are passed as parameters
8979 l_qoh := p_qoh;
8980 l_atr := p_atr;
8981 END IF; -- l_check_qties
8982
8983 print_debug(' l_qoh -->'||l_qoh||' l_atr --> '||l_atr);
8984 /*==========================================
8985 Compare values of transaction_source and transaction_action
8986 and then decide whether the new transaction is allowed
8987
8988 ========================================*/
8989 -- action 1 = issue
8990 -- action 2 = subinv transfer
8991 -- action 3 = direct org transfer
8992 -- action 28 = staging transfer
8993 -- action 32 = assembly return
8994 -- action 34 = negative component return
8995 -- transaction_type_id = 32 (Misc Issue), always return VALID TRX if enough onhand.
8996 -- l_transaction_action_id 50,51,52 PACK,UNPACK,SPLIT. --Bug 4218736
8997 IF ( l_transaction_action_id IN ( 2, 3, 32, 34, 28)
8998 OR (l_transaction_action_id = 1 AND p_transaction_type_id NOT IN ( 1, 32) ) )
8999 OR (l_transaction_action_id IN ( 50,51,52) )
9000 OR (p_transaction_type_id=21 AND l_transaction_action_id=21 AND l_transaction_source_type_id=13 ) --Bug#10205679
9001 THEN
9002 print_debug('within case 1 : Must issue the full onhand qty');
9003 -- bug 4122106 : added ABS in the test.
9004 IF (ABS(p_primary_quantity) <> l_qoh
9005 OR (p_secondary_quantity IS NOT NULL AND ABS(p_secondary_quantity) <> l_sqoh)) /* Fix for Bug#11729772 */
9006 THEN
9007 -- print_debug('INV_LOT_INDIV_QTY_ISSUE_CASE_1');
9008 print_debug('INV_LOT_INDIVISIBLE_VIOLATION');
9009 --l_error_exp := FND_MESSAGE.GET;
9010 FND_MESSAGE.SET_NAME('INV','INV_LOT_INDIVISIBLE_VIOLATION'); -- bug 4121709
9011 -- FND_MESSAGE.SET_TOKEN('QOH',l_qoh);
9012 FND_MSG_PUB.ADD;
9013 --l_error_code := FND_MESSAGE.GET;
9014 /* Update MTI table with error code/explanation */
9015 --errupdate(p_rowid);
9016 RAISE FND_API.G_EXC_ERROR;
9017 END IF;
9018 END IF;
9019
9020 -- IF ( p_transaction_type_id = 32 )
9021 -- THEN
9022 -- print_debug('within case 1.1 : Misc Issue. Can issue less than onhand qty');
9023 -- IF (p_primary_quantity > l_qoh )
9024 -- THEN
9025 -- print_debug('INV_LOT_INDIV_QTY_ISSUE_CASE_1.1');
9026 -- --l_error_exp := FND_MESSAGE.GET;
9027 -- FND_MESSAGE.SET_NAME('INV','INV_LOT_INDIV_QTY_ISSUE_CASE_1.1');
9028 -- FND_MSG_PUB.ADD;
9029 -- --l_error_code := FND_MESSAGE.GET;
9030 -- /* Update MTI table with error code/explanation */
9031 -- --errupdate(p_rowid);
9032 -- RAISE FND_API.G_EXC_ERROR;
9033 -- END IF;
9034 -- END IF;
9035
9036 -- action 27 = Receipt into store
9037 /*Bug#5465377 added transaction action id 41 for lot merge so that
9038 it checks for lot indivisibility for lot merge also. */
9039 --bug 4648937 kbanddyo...included id 31 in the if condition below to restrict user from doing a WIP completion for lot indivisible item into diff subinv/loc
9040 IF (l_transaction_action_id IN (27,41,31) )
9041 THEN
9042 /* Bug 9903477 Following IF condition added so that fix for bug 9717803 is restricted only to WIP txns */
9043 IF l_transaction_action_id = 31 THEN
9044 /* Bug#9717803 Check if there are any consumption transactions before yielding */
9045 OPEN cur_any_consumptions;
9046 FETCH cur_any_consumptions INTO l_exists;
9047 CLOSE cur_any_consumptions;
9048
9049 IF l_exists = 1 THEN
9050 FND_MESSAGE.SET_NAME('INV','INV_LOT_INDIVISIBLE_VIOLATION');
9051 FND_MSG_PUB.ADD;
9052 RAISE FND_API.G_EXC_ERROR;
9053 END IF;
9054 END IF;
9055
9056 -- test if some inventory exist at lowest level
9057 -- if some inventory ALREADY exists for that sub/loct/lot, then that's fine. trx accepted
9058 -- IF ( l_atr = 0 )
9059 -- BUG 4146697 -- Changed the check to compare Onhand > 0.
9060 IF ( l_qoh > 0 )
9061 THEN
9062 -- No inventory for sub/loct/lot, then, need to search somewhere-else :
9063 -- Going to see whether, for that lot the qty is the same at node=lot
9064 print_debug('within case 2 prim_qty='||p_primary_quantity||', atr='||l_atr);
9065
9066 INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES
9067 ( p_api_version_number => p_api_version
9068 , p_init_msg_lst => p_init_msg_list
9069 , x_return_status => l_return_status
9070 , x_msg_count => l_msg_count
9071 , x_msg_data => l_msg_data
9072 , p_tree_mode => l_tree_mode
9073 , p_organization_id => p_organization_id
9074 , p_inventory_item_id => p_inventory_item_id
9075 , p_is_revision_control => l_is_revision_control
9076 , p_is_lot_control => l_is_lot_control
9077 , p_is_serial_control => l_is_serial_control
9078 , p_grade_code => l_grade_code
9079 , p_revision => p_revision
9080 , p_lot_number => p_lot_number
9081 , p_subinventory_code => p_subinventory_code -- NULL Bug# 4233182 removed null and passed p_subinventory_code
9082 , p_locator_id => p_locator_id -- NULL Bug# 4233182 removed null and passed p_locator_id
9083 , p_lpn_id => p_lpn_id /*Bug#10113239*/
9084 , x_qoh => ll_qoh
9085 , x_rqoh => ll_rqoh
9086 , x_qr => ll_qr
9087 , x_qs => ll_qs
9088 , x_att => ll_att
9089 , x_atr => ll_atr_plus
9090 , x_sqoh => ll_sqoh
9091 , x_srqoh => ll_srqoh
9092 , x_sqr => ll_sqr
9093 , x_sqs => ll_sqs
9094 , x_satt => ll_satt
9095 , x_satr => ll_satr
9096 );
9097
9098 -- returning primary quantity to calling procedure
9099 x_primary_quantity := l_qoh;
9100
9101 -- NSRIVAST, using <> as per GSCC compliance
9102 IF (l_return_status <> FND_API.G_RET_STS_SUCCESS)
9103 THEN
9104 print_debug('Returning error from INV_QUANTITY_TREE_GRP.QUERY_TREE');
9105 RAISE QUERY_TREE_ERROR;
9106 END IF;
9107
9108 print_debug('within case A prim_qty='||p_primary_quantity||', atr='||l_atr||', ll_atr_Plus='||ll_atr_plus);
9109
9110 -- Check Qties at Lot level
9111 -- IF ( ll_atr_plus > 0 )
9112 -- Bug 4146697 - Modified Condition.
9113 --IF ( ll_atr_plus <> l_atr ) -- This means that Inventory was found in a
9114 -- a different location.
9115 IF ( ll_qoh <> l_qoh ) --Bug#5469430
9116 THEN
9117 print_debug('INV_LOT_INDIV_QTY_RCPT_CASE_2');
9118 --l_error_exp := FND_MESSAGE.GET;
9119 FND_MESSAGE.SET_NAME('INV','INV_LOT_INDIV_QTY_RCPT_CASE_2');
9120 FND_MSG_PUB.ADD;
9121 --l_error_expp := FND_MESSAGE.GET;
9122 /* Update MTI table with error code/explanation */
9123 --errupdate(p_rowid);
9124 RAISE FND_API.G_EXC_ERROR;
9125 END IF; -- ( ll_atr = 0 )
9126 -- bug 4042255 : added forgotten ELSE clause :
9127 -- Bug 4146697 - Removed ELSE condition below.
9128 -- ELSE
9129 -- print_debug('within case 3 Some Qty already available to reserve. prim_qty='||p_primary_quantity||', atr='||l_atr);
9130 -- FND_MESSAGE.SET_NAME('INV','INV_LOT_INDIV_QTY_RCPT_CASE_3');
9131 -- FND_MSG_PUB.ADD;
9132
9133 -- RAISE FND_API.G_EXC_ERROR;
9134 END IF; -- ( l_atr = 0 )
9135
9136 IF ( l_qr > 0 )
9137 THEN
9138 print_debug('within case 3 Some Qty already reserved. prim_qty='||p_primary_quantity||', qr='||l_qr);
9139
9140 print_debug('INV_LOT_INDIV_QTY_RCPT_CASE_3');
9141 --l_error_exp := FND_MESSAGE.GET;
9142 FND_MESSAGE.SET_NAME('INV','INV_LOT_INDIV_QTY_RCPT_CASE_3');
9143 FND_MSG_PUB.ADD;
9144 --l_error_expp := FND_MESSAGE.GET;
9145 /* Update MTI table with error code/explanation */
9146 --errupdate(p_rowid);
9147 RAISE FND_API.G_EXC_ERROR;
9148 END IF; -- ( l_qr > 0 )
9149 END IF; -- l_transaction_action_id IN (27)
9150 l_return := TRUE;
9151
9152 -- action 12 = Intransit Receipt
9153 -- action 30 = WIP Scrap Transaction
9154 -- action 31 = Assembly Completion
9155 -- Before IF (l_transaction_action_id IN ( 12, 27, 30, 31) )
9156 IF (l_transaction_action_id IN ( 12, 30, 31) )
9157 THEN
9158 -- print_debug('within case 4 prim_qty='||p_primary_quantity||', atr='||l_atr);
9159 print_debug('within case 4 prim_qty= '||p_primary_quantity||', l_qr= ' || l_qr);
9160 -- bug 4122106 : added ABS in the test.
9161 -- IF (ABS(p_primary_quantity) <> l_atr )
9162 -- fabdi bug 4486488 changes
9163 IF ( l_qr > 0 )
9164 THEN
9165 -- print_debug('INV_LOT_INDIV_QTY_RCPT_CASE_4');
9166 print_debug('INV_LOT_INDIV_QTY_RCPT_CASE_3');
9167 --l_error_exp := FND_MESSAGE.GET;
9168 -- FND_MESSAGE.SET_NAME('INV','INV_LOT_INDIV_QTY_RCPT_CASE_4');
9169 ---FND_MESSAGE.SET_TOKEN('ATR',l_atr);
9170 -- FND_MSG_PUB.ADD;
9171 FND_MESSAGE.SET_NAME('INV','INV_LOT_INDIV_QTY_RCPT_CASE_3');
9172 FND_MSG_PUB.ADD;
9173 --l_error_expp := FND_MESSAGE.GET;
9174 /* Update MTI table with error code/explanation */
9175 --errupdate(p_rowid);
9176 RAISE FND_API.G_EXC_ERROR;
9177 END IF;
9178 END IF;
9179 l_return := TRUE;
9180 ELSE
9181 print_debug(' the lot is either divisible or new... Return TRUE.');
9182 l_return := TRUE;
9183 END IF; -- lot_divisible
9184
9185 RETURN l_return;
9186
9187 EXCEPTION
9188
9189 WHEN CREATE_TREE_ERROR THEN
9190 print_debug(' CREATE_TREE error...');
9191 x_return_status := FND_API.G_RET_STS_ERROR;
9192 FND_MSG_PUB.Count_AND_GET
9193 (p_count => x_msg_count, p_data => x_msg_data);
9194 RETURN FALSE;
9195
9196 WHEN QUERY_TREE_ERROR THEN
9197 print_debug(' QUERY_TREE error...');
9198 x_return_status := FND_API.G_RET_STS_ERROR;
9199 FND_MSG_PUB.Count_AND_GET
9200 (p_count => x_msg_count, p_data => x_msg_data);
9201 RETURN FALSE;
9202
9203 WHEN FND_API.G_EXC_ERROR THEN
9204 print_debug(' EXCP error...');
9205 x_return_status := FND_API.G_RET_STS_ERROR;
9206 FND_MSG_PUB.Count_AND_GET
9207 (p_count => x_msg_count, p_data => x_msg_data);
9208 RETURN FALSE;
9209
9210 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
9211 print_debug(' UNEXCP error...');
9212 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9213 FND_MSG_PUB.Count_AND_GET
9214 (p_count => x_msg_count, p_data => x_msg_data);
9215 RETURN FALSE;
9216
9217 WHEN OTHERS THEN
9218 print_debug(' OTHERS error...'||SQLERRM);
9219 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9220 FND_MSG_PUB.Count_AND_GET
9221 (p_count => x_msg_count, p_data => x_msg_data);
9222 RETURN FALSE;
9223
9224 END validate_lot_indivisible;
9225
9226
9227
9228 PROCEDURE create_inv_lot(
9229 x_return_status OUT NOCOPY VARCHAR2
9230 , x_msg_count OUT NOCOPY NUMBER
9231 , x_msg_data OUT NOCOPY VARCHAR2
9232 , p_inventory_item_id IN NUMBER
9233 , p_organization_id IN NUMBER
9234 , p_lot_number IN VARCHAR2
9235 , p_expiration_date IN DATE
9236 , p_disable_flag IN NUMBER
9237 , p_attribute_category IN VARCHAR2
9238 , p_lot_attribute_category IN VARCHAR2
9239 , p_attributes_tbl IN inv_lot_api_pub.char_tbl
9240 , p_c_attributes_tbl IN inv_lot_api_pub.char_tbl
9241 , p_n_attributes_tbl IN inv_lot_api_pub.number_tbl
9242 , p_d_attributes_tbl IN inv_lot_api_pub.date_tbl
9243 , p_grade_code IN VARCHAR2
9244 , p_origination_date IN DATE
9245 , p_date_code IN VARCHAR2
9246 , p_status_id IN NUMBER
9247 , p_change_date IN DATE
9248 , p_age IN NUMBER
9249 , p_retest_date IN DATE
9250 , p_maturity_date IN DATE
9251 , p_item_size IN NUMBER
9252 , p_color IN VARCHAR2
9253 , p_volume IN NUMBER
9254 , p_volume_uom IN VARCHAR2
9255 , p_place_of_origin IN VARCHAR2
9256 , p_best_by_date IN DATE
9257 , p_length IN NUMBER
9258 , p_length_uom IN VARCHAR2
9259 , p_recycled_content IN NUMBER
9260 , p_thickness IN NUMBER
9261 , p_thickness_uom IN VARCHAR2
9262 , p_width IN NUMBER
9263 , p_width_uom IN VARCHAR2
9264 , p_territory_code IN VARCHAR2
9265 , p_supplier_lot_number IN VARCHAR2
9266 , p_vendor_name IN VARCHAR2
9267 , p_source IN NUMBER
9268 , p_init_msg_list IN VARCHAR2 DEFAULT fnd_api.g_false --bug 7513308
9269 ) IS
9270
9271
9272 /* Defined new variables for overloaded API call */
9273
9274 l_in_lot_rec MTL_LOT_NUMBERS%ROWTYPE;
9275 l_out_lot_rec MTL_LOT_NUMBERS%ROWTYPE;
9276 x_lot_rec MTL_LOT_NUMBERS%ROWTYPE;
9277 l_api_version NUMBER;
9278 l_init_msg_list VARCHAR2(100);
9279 l_commit VARCHAR2(100);
9280 l_validation_level NUMBER;
9281 l_origin_txn_id NUMBER;
9282 l_source NUMBER;
9283 l_return_status VARCHAR2(1) ;
9284 l_msg_data VARCHAR2(3000) ;
9285 l_msg_count NUMBER ;
9286 l_row_id ROWID ;
9287 BEGIN
9288 SAVEPOINT inv_lot;
9289 x_return_status := fnd_api.g_ret_sts_success;
9290
9291 /* Populating the variables and calling the new overloaded API */
9292
9293 l_in_lot_rec.inventory_item_id := p_inventory_item_id;
9294 l_in_lot_rec.organization_id := p_organization_id;
9295 l_in_lot_rec.lot_number := p_lot_number;
9296 l_in_lot_rec.parent_lot_number := NULL;
9297 l_in_lot_rec.expiration_date := p_expiration_date;
9298 l_in_lot_rec.disable_flag := p_disable_flag;
9299 l_in_lot_rec.attribute_category := p_attribute_category;
9300 l_in_lot_rec.lot_attribute_category := p_lot_attribute_category;
9301 l_in_lot_rec.grade_code := p_grade_code;
9302 l_in_lot_rec.origination_date := p_origination_date;
9303 l_in_lot_rec.date_code := p_date_code;
9304 l_in_lot_rec.status_id := p_status_id;
9305 l_in_lot_rec.change_date := p_change_date;
9306 l_in_lot_rec.age := p_age;
9307 l_in_lot_rec.retest_date := p_retest_date;
9308 l_in_lot_rec.maturity_date := p_maturity_date;
9309 l_in_lot_rec.item_size := p_item_size;
9310 l_in_lot_rec.color := p_color;
9311 l_in_lot_rec.volume := p_volume;
9312 l_in_lot_rec.volume_uom := p_volume_uom;
9313 l_in_lot_rec.place_of_origin := p_place_of_origin;
9314 l_in_lot_rec.best_by_date := p_best_by_date;
9315 l_in_lot_rec.length := p_length;
9316 l_in_lot_rec.length_uom := p_length_uom;
9317 l_in_lot_rec.recycled_content := p_recycled_content;
9318 l_in_lot_rec.thickness := p_thickness;
9319 l_in_lot_rec.thickness_uom := p_thickness_uom;
9320 l_in_lot_rec.width := p_width;
9321 l_in_lot_rec.width_uom := p_width_uom;
9322 l_in_lot_rec.territory_code := p_territory_code;
9323 l_in_lot_rec.supplier_lot_number := p_supplier_lot_number;
9324 l_in_lot_rec.vendor_name := p_vendor_name;
9325 l_in_lot_rec.creation_date := SYSDATE;
9326 l_in_lot_rec.last_update_date := SYSDATE ;
9327 l_in_lot_rec.created_by := FND_GLOBAL.USER_ID;
9328 l_in_lot_rec.last_updated_by := FND_GLOBAL.USER_ID;
9329 l_in_lot_rec.last_update_login := FND_GLOBAL.LOGIN_ID;
9330 --BUG 4748451: if the p%tbl are not initialized, then a no_date_found
9331 --exception would be thrown if accessed. So add clause to check for this
9332 IF (p_attributes_tbl.exists(1)) THEN
9333 l_in_lot_rec.attribute1 := p_attributes_tbl(1);
9334 END IF;
9335 IF (p_attributes_tbl.exists(2)) THEN
9336 l_in_lot_rec.attribute2 := p_attributes_tbl(2);
9337 END IF;
9338 IF (p_attributes_tbl.exists(3)) THEN
9339 l_in_lot_rec.attribute3 := p_attributes_tbl(3);
9340 END IF;
9341 IF (p_attributes_tbl.exists(4)) THEN
9342 l_in_lot_rec.attribute4 := p_attributes_tbl(4);
9343 END IF;
9344 IF (p_attributes_tbl.exists(5)) THEN
9345 l_in_lot_rec.attribute5 := p_attributes_tbl(5);
9346 END IF;
9347 IF (p_attributes_tbl.exists(6)) THEN
9348 l_in_lot_rec.attribute6 := p_attributes_tbl(6);
9349 END IF;
9350 IF (p_attributes_tbl.exists(7)) THEN
9351 l_in_lot_rec.attribute7 := p_attributes_tbl(7);
9352 END IF;
9353 IF (p_attributes_tbl.exists(8)) THEN
9354 l_in_lot_rec.attribute8 := p_attributes_tbl(8);
9355 END IF;
9356 IF (p_attributes_tbl.exists(9)) THEN
9357 l_in_lot_rec.attribute9 := p_attributes_tbl(9);
9358 END IF;
9359 IF (p_attributes_tbl.exists(10)) THEN
9360 l_in_lot_rec.attribute10 := p_attributes_tbl(10);
9361 END IF;
9362 IF (p_attributes_tbl.exists(11)) THEN
9363 l_in_lot_rec.attribute11 := p_attributes_tbl(11);
9364 END IF;
9365 IF (p_attributes_tbl.exists(12)) THEN
9366 l_in_lot_rec.attribute12 := p_attributes_tbl(12);
9367 END IF;
9368 IF (p_attributes_tbl.exists(13)) THEN
9369 l_in_lot_rec.attribute13 := p_attributes_tbl(13);
9370 END IF;
9371 IF (p_attributes_tbl.exists(14)) THEN
9372 l_in_lot_rec.attribute14 := p_attributes_tbl(14);
9373 END IF;
9374 IF (p_attributes_tbl.exists(15)) THEN
9375 l_in_lot_rec.attribute15 := p_attributes_tbl(15);
9376 END IF;
9377 IF (p_c_attributes_tbl.exists(1)) THEN
9378 l_in_lot_rec.c_attribute1 := p_c_attributes_tbl(1);
9379 END IF;
9380 IF (p_c_attributes_tbl.exists(2)) THEN
9381 l_in_lot_rec.c_attribute2 := p_c_attributes_tbl(2);
9382 END IF;
9383 IF (p_c_attributes_tbl.exists(3)) THEN
9384 l_in_lot_rec.c_attribute3 := p_c_attributes_tbl(3);
9385 END IF;
9386 IF (p_c_attributes_tbl.exists(4)) THEN
9387 l_in_lot_rec.c_attribute4 := p_c_attributes_tbl(4);
9388 END IF;
9389 IF (p_c_attributes_tbl.exists(5)) THEN
9390 l_in_lot_rec.c_attribute5 := p_c_attributes_tbl(5);
9391 END IF;
9392 IF (p_c_attributes_tbl.exists(6)) THEN
9393 l_in_lot_rec.c_attribute6 := p_c_attributes_tbl(6);
9394 END IF;
9395 IF (p_c_attributes_tbl.exists(7)) THEN
9396 l_in_lot_rec.c_attribute7 := p_c_attributes_tbl(7);
9397 END IF;
9398 IF (p_c_attributes_tbl.exists(8)) THEN
9399 l_in_lot_rec.c_attribute8 := p_c_attributes_tbl(8);
9400 END IF;
9401 IF (p_c_attributes_tbl.exists(9)) THEN
9402 l_in_lot_rec.c_attribute9 := p_c_attributes_tbl(9);
9403 END IF;
9404 IF (p_c_attributes_tbl.exists(10)) THEN
9405 l_in_lot_rec.c_attribute10 := p_c_attributes_tbl(10);
9406 END IF;
9407 IF (p_c_attributes_tbl.exists(11)) THEN
9408 l_in_lot_rec.c_attribute11 := p_c_attributes_tbl(11);
9409 END IF;
9410 IF (p_c_attributes_tbl.exists(12)) THEN
9411 l_in_lot_rec.c_attribute12 := p_c_attributes_tbl(12);
9412 END IF;
9413 IF (p_c_attributes_tbl.exists(13)) THEN
9414 l_in_lot_rec.c_attribute13 := p_c_attributes_tbl(13);
9415 END IF;
9416 IF (p_c_attributes_tbl.exists(14)) THEN
9417 l_in_lot_rec.c_attribute14 := p_c_attributes_tbl(14);
9418 END IF;
9419 IF (p_c_attributes_tbl.exists(15)) THEN
9420 l_in_lot_rec.c_attribute15 := p_c_attributes_tbl(15);
9421 END IF;
9422 IF (p_c_attributes_tbl.exists(16)) THEN
9423 l_in_lot_rec.c_attribute16 := p_c_attributes_tbl(16);
9424 END IF;
9425 IF (p_c_attributes_tbl.exists(17)) THEN
9426 l_in_lot_rec.c_attribute17 := p_c_attributes_tbl(17);
9427 END IF;
9428 IF (p_c_attributes_tbl.exists(18)) THEN
9429 l_in_lot_rec.c_attribute18 := p_c_attributes_tbl(18);
9430 END IF;
9431 IF (p_c_attributes_tbl.exists(19)) THEN
9432 l_in_lot_rec.c_attribute19 := p_c_attributes_tbl(19);
9433 END IF;
9434 IF (p_c_attributes_tbl.exists(20)) THEN
9435 l_in_lot_rec.c_attribute20 := p_c_attributes_tbl(20);
9436 END IF;
9437 IF (p_n_attributes_tbl.exists(1)) THEN
9438 l_in_lot_rec.n_attribute1 := p_n_attributes_tbl(1);
9439 END IF;
9440 IF (p_n_attributes_tbl.exists(2)) THEN
9441 l_in_lot_rec.n_attribute2 := p_n_attributes_tbl(2);
9442 END IF;
9443 IF (p_n_attributes_tbl.exists(3)) THEN
9444 l_in_lot_rec.n_attribute3 := p_n_attributes_tbl(3);
9445 END IF;
9446 IF (p_n_attributes_tbl.exists(4)) THEN
9447 l_in_lot_rec.n_attribute4 := p_n_attributes_tbl(4);
9448 END IF;
9449 IF (p_n_attributes_tbl.exists(5)) THEN
9450 l_in_lot_rec.n_attribute5 := p_n_attributes_tbl(5);
9451 END IF;
9452 IF (p_n_attributes_tbl.exists(6)) THEN
9453 l_in_lot_rec.n_attribute6 := p_n_attributes_tbl(6);
9454 END IF;
9455 IF (p_n_attributes_tbl.exists(7)) THEN
9456 l_in_lot_rec.n_attribute7 := p_n_attributes_tbl(7);
9457 END IF;
9458 IF (p_n_attributes_tbl.exists(8)) THEN
9459 l_in_lot_rec.n_attribute8 := p_n_attributes_tbl(8);
9460 END IF;
9461 IF (p_n_attributes_tbl.exists(9)) THEN
9462 l_in_lot_rec.n_attribute9 := p_n_attributes_tbl(9);
9463 END IF;
9464 IF (p_n_attributes_tbl.exists(10)) THEN
9465 l_in_lot_rec.n_attribute10 := p_n_attributes_tbl(10);
9466 END IF;
9467 IF (p_d_attributes_tbl.exists(1)) THEN
9468 l_in_lot_rec.d_attribute1 := p_d_attributes_tbl(1);
9469 END IF;
9470 IF (p_d_attributes_tbl.exists(2)) THEN
9471 l_in_lot_rec.d_attribute2 := p_d_attributes_tbl(2);
9472 END IF;
9473 IF (p_d_attributes_tbl.exists(3)) THEN
9474 l_in_lot_rec.d_attribute3 := p_d_attributes_tbl(3);
9475 END IF;
9476 IF (p_d_attributes_tbl.exists(4)) THEN
9477 l_in_lot_rec.d_attribute4 := p_d_attributes_tbl(4);
9478 END IF;
9479 IF (p_d_attributes_tbl.exists(5)) THEN
9480 l_in_lot_rec.d_attribute5 := p_d_attributes_tbl(5);
9481 END IF;
9482 IF (p_d_attributes_tbl.exists(6)) THEN
9483 l_in_lot_rec.d_attribute6 := p_d_attributes_tbl(6);
9484 END IF;
9485 IF (p_d_attributes_tbl.exists(7)) THEN
9486 l_in_lot_rec.d_attribute7 := p_d_attributes_tbl(7);
9487 END IF;
9488 IF (p_d_attributes_tbl.exists(8)) THEN
9489 l_in_lot_rec.d_attribute8 := p_d_attributes_tbl(8);
9490 END IF;
9491 IF (p_d_attributes_tbl.exists(9)) THEN
9492 l_in_lot_rec.d_attribute9 := p_d_attributes_tbl(9);
9493 END IF;
9494 IF (p_d_attributes_tbl.exists(10)) THEN
9495 l_in_lot_rec.d_attribute10 := p_d_attributes_tbl(10);
9496 END IF;
9497 --END BUG 4748451
9498
9499 -- Bug 7513308
9500 -- Initialize message list if p_init_msg_list is set to TRUE.
9501 IF fnd_api.to_boolean(p_init_msg_list) THEN
9502 fnd_msg_pub.initialize;
9503 END IF;
9504
9505 l_source := p_source;
9506 l_api_version := 1.0;
9507 l_init_msg_list := p_init_msg_list; --fnd_api.g_false; bug 7513308
9508 l_commit := fnd_api.g_false;
9509 l_validation_level := fnd_api.g_valid_level_full;
9510 l_origin_txn_id := NULL;
9511
9512
9513
9514 /* Calling the overloaded procedure */
9515 Create_Inv_lot(
9516 x_return_status => l_return_status
9517 , x_msg_count => l_msg_count
9518 , x_msg_data => l_msg_data
9519 , x_row_id => l_row_id
9520 , x_lot_rec => x_lot_rec
9521 , p_lot_rec => l_in_lot_rec
9522 , p_source => p_source
9523 , p_api_version => l_api_version
9524 , p_init_msg_list => l_init_msg_list
9525 , p_commit => l_commit
9526 , p_validation_level => l_validation_level
9527 , p_origin_txn_id => l_origin_txn_id
9528 );
9529
9530 IF g_debug = 1 THEN
9531 print_debug('Program Create_Inv_lot return ' || l_return_status, 9);
9532 END IF;
9533 IF l_return_status = fnd_api.g_ret_sts_error THEN
9534 IF g_debug = 1 THEN
9535 print_debug('Program Create_Inv_lot has failed with a user defined exception', 9);
9536 END IF;
9537 RAISE g_exc_error;
9538 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
9539 IF g_debug = 1 THEN
9540 print_debug('Program Create_Inv_lot has failed with a Unexpected exception', 9);
9541 END IF;
9542 FND_MESSAGE.SET_NAME('INV','INV_PROGRAM_ERROR');
9543 FND_MESSAGE.SET_TOKEN('PROG_NAME','Create_Inv_lot');
9544 fnd_msg_pub.ADD;
9545 RAISE g_exc_unexpected_error;
9546 END IF;
9547
9548 print_debug('End of the program create_inv_lot. Program has completed successfully ', 9);
9549 EXCEPTION
9550 WHEN NO_DATA_FOUND THEN
9551 x_return_status := fnd_api.g_ret_sts_error;
9552 ROLLBACK TO inv_lot;
9553 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
9554 if( x_msg_count > 1 ) then
9555 x_msg_data := fnd_msg_pub.get(x_msg_count, FND_API.G_FALSE);
9556 end if;
9557 print_debug('In No data found ' || SQLERRM, 9);
9558 WHEN g_exc_error THEN
9559 x_return_status := fnd_api.g_ret_sts_error;
9560 ROLLBACK TO inv_lot;
9561 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
9562 if( x_msg_count > 1 ) then
9563 x_msg_data := fnd_msg_pub.get(x_msg_count, FND_API.G_FALSE);
9564 end if;
9565 print_debug('In g_exc_error ' || SQLERRM, 9);
9566 WHEN g_exc_unexpected_error THEN
9567 x_return_status := fnd_api.g_ret_sts_unexp_error;
9568 ROLLBACK TO inv_lot;
9569 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
9570 if( x_msg_count > 1 ) then
9571 x_msg_data := fnd_msg_pub.get(x_msg_count, FND_API.G_FALSE);
9572 end if;
9573 print_debug('In g_exc_unexpected_error ' || SQLERRM, 9);
9574 WHEN OTHERS THEN
9575 x_return_status := fnd_api.g_ret_sts_unexp_error;
9576 ROLLBACK TO inv_lot;
9577 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
9578 if( x_msg_count > 1 ) then
9579 x_msg_data := fnd_msg_pub.get(x_msg_count, FND_API.G_FALSE);
9580 end if;
9581 print_debug('In others ' || SQLERRM, 9);
9582 END create_inv_lot;
9583
9584 /* Overloaded Create_Inv_lot procedure */
9585 --14192172
9586 PROCEDURE Create_Inv_lot(
9587 x_return_status OUT NOCOPY VARCHAR2
9588 , x_msg_count OUT NOCOPY NUMBER
9589 , x_msg_data OUT NOCOPY VARCHAR2
9590 , x_row_id OUT NOCOPY ROWID
9591 , x_lot_rec OUT NOCOPY MTL_LOT_NUMBERS%ROWTYPE
9592 , p_lot_rec IN MTL_LOT_NUMBERS%ROWTYPE
9593 , p_source IN NUMBER
9594 , p_api_version IN NUMBER
9595 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
9596 , p_commit IN VARCHAR2 := fnd_api.g_false
9597 , p_validation_level IN NUMBER := fnd_api.g_valid_level_full
9598 , p_origin_txn_id IN NUMBER
9599 )
9600 IS
9601 BEGIN
9602
9603 --call over load functin by pass p_caculate_flag
9604 Create_Inv_lot(
9605 x_return_status => x_return_status
9606 , x_msg_count => x_msg_count
9607 , x_msg_data => x_msg_data
9608 , x_row_id => x_row_id
9609 , x_lot_rec => x_lot_rec
9610 , p_lot_rec => p_lot_rec
9611 , p_source => p_source
9612 , p_api_version => p_api_version
9613 , p_init_msg_list => p_init_msg_list
9614 , p_commit => p_commit
9615 , p_validation_level => p_validation_level
9616 , p_origin_txn_id => p_origin_txn_id
9617 , p_caculate_flag => null
9618 );
9619
9620
9621 END Create_Inv_lot;
9622
9623 /* Overloaded Create_Inv_lot procedure */
9624 PROCEDURE Create_Inv_lot(
9625 x_return_status OUT NOCOPY VARCHAR2
9626 , x_msg_count OUT NOCOPY NUMBER
9627 , x_msg_data OUT NOCOPY VARCHAR2
9628 , x_row_id OUT NOCOPY ROWID
9629 , x_lot_rec OUT NOCOPY MTL_LOT_NUMBERS%ROWTYPE
9630 , p_lot_rec IN MTL_LOT_NUMBERS%ROWTYPE
9631 , p_source IN NUMBER
9632 , p_api_version IN NUMBER
9633 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
9634 , p_commit IN VARCHAR2 := fnd_api.g_false
9635 , p_validation_level IN NUMBER := fnd_api.g_valid_level_full
9636 , p_origin_txn_id IN NUMBER
9637 , p_caculate_flag IN VARCHAR2 --14192172
9638 )
9639 IS
9640
9641 /* Cursor definition to check whether item is a valid item and it's lot controlled */
9642 CURSOR c_chk_msi_attr(cp_inventory_item_id NUMBER, cp_organization_id NUMBER) IS
9643 SELECT lot_control_code,
9644 child_lot_flag,
9645 copy_lot_attribute_flag,
9646 shelf_life_code,
9647 grade_control_flag
9648 FROM mtl_system_items_b -- NSRIVAST, Changed the name to MTL_SYSTEM_ITEMS_B as per review comments by Shelly
9649 WHERE inventory_item_id = cp_inventory_item_id
9650 AND organization_id = cp_organization_id;
9651
9652 l_chk_msi_attr_rec c_chk_msi_attr%ROWTYPE;
9653
9654 /* Cursor definition to check lot existence in Mtl_Lot_Numbers Table */
9655 CURSOR c_chk_lot_exists(cp_lot_number MTL_LOT_NUMBERS.lot_number%TYPE,cp_inventory_item_id NUMBER, cp_organization_id NUMBER) IS
9656 SELECT lot_number
9657 FROM mtl_lot_numbers
9658 WHERE lot_number = cp_lot_number AND
9659 inventory_item_id = cp_inventory_item_id AND
9660 organization_id = cp_organization_id;
9661
9662 l_chk_lot_rec c_chk_lot_exists%ROWTYPE;
9663
9664 /* Cursor definition to check if Lot UOM Conversion is needed */
9665 CURSOR c_lot_uom_conv(cp_organization_id NUMBER) IS
9666 SELECT copy_lot_attribute_flag,
9667 lot_number_generation
9668 FROM mtl_parameters
9669 WHERE organization_id = cp_organization_id;
9670
9671 l_lot_uom_conv c_lot_uom_conv%ROWTYPE ;
9672
9673 /* Cursor definition to get gen_object_id for a lot */
9674 CURSOR c_get_obj_id(cp_lot_number MTL_LOT_NUMBERS.lot_number%TYPE,cp_inventory_item_id NUMBER, cp_organization_id NUMBER) IS
9675 SELECT gen_object_id, ROWID
9676 FROM mtl_lot_numbers
9677 WHERE lot_number = cp_lot_number AND
9678 inventory_item_id = cp_inventory_item_id AND
9679 organization_id = cp_organization_id;
9680
9681 l_get_obj_id_rec c_get_obj_id%ROWTYPE;
9682
9683
9684 l_parent_lot_rec MTL_LOT_NUMBERS%ROWTYPE ;
9685 l_child_lot_rec MTL_LOT_NUMBERS%ROWTYPE ;
9686 x_parent_lot_rec MTL_LOT_NUMBERS%ROWTYPE ;
9687 x_child_lot_rec MTL_LOT_NUMBERS%ROWTYPE ;
9688
9689 l_chd_gen_obj_id NUMBER;
9690 l_prt_gen_obj_id NUMBER;
9691
9692 l_parent_exists_flag VARCHAR2(1) ; -- NSRIVAST
9693 l_copy_lot_attribute_flag VARCHAR2(1) ;
9694 l_return_status VARCHAR2(1) ;
9695 l_msg_data VARCHAR2(3000) ;
9696 l_msg_count NUMBER ;
9697 l_api_version NUMBER;
9698 l_init_msg_list VARCHAR2(100);
9699 l_commit VARCHAR2(100);
9700 l_source NUMBER;
9701 l_row_id ROWID ;
9702 BEGIN
9703
9704 SAVEPOINT inv_lot_1;
9705
9706 -- Bug 7686319
9707 -- Initialize message list if p_init_msg_list is set to TRUE.
9708 IF fnd_api.to_boolean(p_init_msg_list) THEN
9709 fnd_msg_pub.initialize;
9710 END IF;
9711
9712 x_return_status := g_ret_sts_success;
9713
9714 /* BASIC CHECKS , start */
9715 IF p_lot_rec.organization_id IS NULL THEN
9716 IF g_debug = 1 THEN
9717 print_debug('Value for mandatory field organization id cannot be null.', 9);
9718 END IF;
9719 fnd_message.set_name('INV', 'INV_NULL_ORG_EXP') ;
9720 fnd_msg_pub.ADD;
9721 RAISE fnd_api.g_exc_error;
9722 END IF ;
9723
9724
9725 /* Check item existence in Mtl_system_items Table */
9726 OPEN c_chk_msi_attr(p_lot_rec.inventory_item_id,p_lot_rec.organization_id);
9727 FETCH c_chk_msi_attr INTO l_chk_msi_attr_rec;
9728
9729 IF c_chk_msi_attr%NOTFOUND THEN
9730 CLOSE c_chk_msi_attr;
9731 IF (g_debug = 1) THEN
9732 print_debug('Item not found. Invalid item. Please re-enter.', 9);
9733 END IF;
9734
9735 fnd_message.set_name('INV', 'INV_INVALID_ITEM');
9736 fnd_msg_pub.ADD;
9737 RAISE g_exc_error;
9738 ELSE
9739 CLOSE c_chk_msi_attr;
9740
9741 l_copy_lot_attribute_flag := l_chk_msi_attr_rec.copy_lot_attribute_flag ;
9742
9743 /* If not lot controlled then error out */
9744 IF (l_chk_msi_attr_rec.lot_control_code = 1) THEN
9745 IF g_debug = 1 THEN
9746 print_debug('Item is not lot controlled ', 9);
9747 END IF;
9748
9749 fnd_message.set_name('INV', 'INV_NO_LOT_CONTROL');
9750 fnd_msg_pub.ADD;
9751 x_return_status := fnd_api.g_ret_sts_error;
9752 RAISE g_exc_error;
9753 END IF; /* l_chk_msi_attr_rec.lot_control_code = 1 */
9754
9755 /* If not child lot enabled and p_lot_rec.parent_lot_number IS NOT NULL then error out */
9756 IF (l_chk_msi_attr_rec.child_lot_flag = 'N' AND p_lot_rec.parent_lot_number IS NOT NULL) THEN
9757 IF g_debug = 1 THEN
9758 print_debug('Item is not child lot enabled ', 9);
9759 END IF;
9760
9761 fnd_message.set_name('INV', 'INV_ITEM_CLOT_DISABLE_EXP');
9762 fnd_msg_pub.ADD;
9763 x_return_status := fnd_api.g_ret_sts_error;
9764 RAISE g_exc_error;
9765 END IF; /* l_chk_msi_attr_rec.child_lot_flag = 'N' */
9766
9767 /* Check for User-defined expiration date */
9768 IF p_lot_rec.expiration_date IS NULL AND
9769 l_chk_msi_attr_rec.shelf_life_code = 4 THEN -- User-defined expiration date
9770 IF g_debug = 1 THEN
9771 print_debug('User defined expiration date cannot be null', 9);
9772 END IF;
9773
9774 fnd_message.set_name('INV', 'INV_NULL_EXPIRATION_DATE_EXP') ;
9775 fnd_msg_pub.ADD;
9776 RAISE fnd_api.g_exc_error;
9777 END IF;
9778
9779 /* Check whether item is grade controlled */
9780 IF p_lot_rec.grade_code IS NOT NULL AND
9781 l_chk_msi_attr_rec.grade_control_flag = 'N' THEN
9782 IF g_debug = 1 THEN
9783 print_debug('Item is not grade controlled.', 9);
9784 END IF;
9785
9786 fnd_message.set_name('INV', 'INV_ITEM_NOT_GRADE_CTRL_EXP');
9787 fnd_msg_pub.ADD;
9788 RAISE fnd_api.g_exc_error;
9789 END IF;
9790
9791 END IF; /* c_chk_msi_attr*/
9792
9793 /* Check for existence of Lot in Mtl_Lot_Numbers Table */
9794 IF p_lot_rec.lot_number IS NULL THEN
9795 IF g_debug = 1 THEN
9796 print_debug('Value for mandatory field Lot Number cannot be null', 9);
9797 END IF;
9798
9799 fnd_message.set_name('INV', 'INV_NULL_CLOT_EXP');
9800 fnd_msg_pub.ADD;
9801 RAISE fnd_api.g_exc_error;
9802 ELSE
9803 /* Check child lot existence in Mtl_Lot_Numbers Table */
9804 OPEN c_chk_lot_exists(p_lot_rec.lot_number,p_lot_rec.inventory_item_id,p_lot_rec.organization_id);
9805 FETCH c_chk_lot_exists INTO l_chk_lot_rec;
9806
9807 IF c_chk_lot_exists%FOUND THEN
9808 /* Child lot exists in Mtl_Lot_Numbers Table. */
9809 IF g_debug = 1 THEN
9810 print_debug('Child lot already exists in the system.', 9);
9811 END IF;
9812
9813 -- Child lot already exists in the system: LOT_NUMBER
9814 fnd_message.set_name('INV', 'INV_CLOT_EXISTS_EXP');
9815 fnd_message.set_token('LOT_NUMBER', to_char(p_lot_rec.lot_number));
9816 fnd_msg_pub.ADD;
9817 RAISE fnd_api.g_exc_error;
9818 END IF;
9819 /* Child lot DOES NOT exist in Mtl_Lot_Numbers Table. */
9820 CLOSE c_chk_lot_exists;
9821 END IF;
9822
9823 /* Check for same parent and child lot names */
9824 IF p_lot_rec.lot_number IS NOT NULL AND p_lot_rec.parent_lot_number IS NOT NULL THEN
9825 IF p_lot_rec.lot_number = p_lot_rec.parent_lot_number THEN
9826 /*Both the parent and child lots have same name*/
9827 IF g_debug = 1 THEN
9828 print_debug('Parent lot number and child lot number can not be same.', 9);
9829 END IF;
9830 fnd_message.set_name('INV', 'INV_SAME_LOT_NAMES_EXP');
9831 fnd_msg_pub.ADD;
9832 RAISE fnd_api.g_exc_error;
9833 END IF ;
9834 END IF ;
9835
9836 /* Check for existence of Parent Lot in Mtl_Lot_Numbers Table */
9837 l_parent_exists_flag := NULL;
9838
9839 OPEN c_chk_lot_exists(p_lot_rec.parent_lot_number,p_lot_rec.inventory_item_id,p_lot_rec.organization_id);
9840 FETCH c_chk_lot_exists INTO l_chk_lot_rec;
9841
9842 IF c_chk_lot_exists%FOUND THEN
9843 /* Parent lot exists in Mtl_Lot_Numbers Table. */
9844 l_parent_exists_flag := 'Y';
9845
9846 ELSIF c_chk_lot_exists%NOTFOUND AND p_lot_rec.parent_lot_number IS NOT NULL THEN
9847 /* Parent lot DOES NOT exist in Mtl_Lot_Numbers Table. */
9848 l_parent_exists_flag := 'N';
9849 END IF;
9850 CLOSE c_chk_lot_exists;
9851
9852 /* BASIC CHECKS , End */
9853
9854 IF p_validation_level = FND_API.G_VALID_LEVEL_FULL THEN
9855
9856 -- Call Populate_Lot_Records API.
9857 -- Populate_Lot_Records API returns following OUT parameters:
9858 -- x_parent_lot_rec,
9859 -- x_lot_rec
9860 l_source := p_source ;
9861 l_api_version := 1.0;
9862 l_init_msg_list := p_init_msg_list; --fnd_api.g_false; Bug# 7686319
9863 l_commit := fnd_api.g_false;
9864
9865 Inv_Lot_Api_Pkg.Populate_Lot_Records (
9866 p_lot_rec => p_lot_rec
9867 , p_copy_lot_attribute_flag => l_copy_lot_attribute_flag
9868 , p_source => l_source
9869 , p_api_version => l_api_version
9870 , p_init_msg_list => l_init_msg_list
9871 , p_commit => l_commit
9872 , x_child_lot_rec => x_child_lot_rec
9873 , x_return_status => l_return_status
9874 , x_msg_count => l_msg_count
9875 , x_msg_data => l_msg_data
9876 , p_caculate_flag => p_caculate_flag --14192172
9877 );
9878
9879 IF g_debug = 1 THEN
9880 print_debug('Program INV_LOT_API_PKG.POPULATE_LOT_RECORDS return ' || x_return_status, 9);
9881 END IF;
9882 IF l_return_status = g_ret_sts_error THEN
9883 IF g_debug = 1 THEN
9884 print_debug('Program INV_LOT_API_PKG.POPULATE_LOT_RECORDS has failed with a user defined exception', 9);
9885 END IF;
9886 RAISE g_exc_error;
9887 ELSIF l_return_status = g_ret_sts_unexp_error THEN
9888 IF g_debug = 1 THEN
9889 print_debug('Program INV_LOT_API_PKG.POPULATE_LOT_RECORDS has failed with a Unexpected exception', 9);
9890 END IF;
9891 FND_MESSAGE.SET_NAME('INV','INV_PROGRAM_ERROR');
9892 FND_MESSAGE.SET_TOKEN('PROG_NAME','INV_LOT_API_PKG.POPULATE_LOT_RECORDS');
9893 FND_MSG_PUB.ADD;
9894 RAISE g_exc_unexpected_error;
9895 END IF;
9896
9897 -- Populate local variable l_child_lot_rec with the values from x_child_lot_rec.
9898 l_child_lot_rec := x_child_lot_rec;
9899
9900 END IF; /* p_validation_level = G_VALID_LEVEL_FULL */
9901
9902
9903 IF p_validation_level = FND_API.G_VALID_LEVEL_NONE THEN
9904 -- Populate local variable l_child_lot_rec with proper attribute's values that are passed as input parameter to this API.
9905 l_child_lot_rec := p_lot_rec ;
9906
9907 END IF; /* p_validation_level = G_VALID_LEVEL_NONE */
9908
9909
9910 -- Call mtl_lot_numbers_pkg.insert_row API passing the attribute's
9911 -- values populated in local variable l_child_lot_rec.
9912
9913 -- OPM Inventory Convergence - added column sampling_event_id to mtl_lot_number
9914 -- Bug #4115021
9915 /*Bug#5523811 passing values from l_child_lot_rec instead of NULL for fields
9916 curl_wrnkl_fold, description and vendor_id */
9917 Mtl_Lot_Numbers_Pkg.Insert_Row(
9918 x_inventory_item_id => l_child_lot_rec.inventory_item_id
9919 , x_organization_id => l_child_lot_rec.organization_id
9920 , x_lot_number => l_child_lot_rec.lot_number
9921 , x_parent_lot_number => l_child_lot_rec.parent_lot_number
9922 , x_supplier_lot_number => l_child_lot_rec.supplier_lot_number
9923 , x_grade_code => l_child_lot_rec.grade_code
9924 , x_origination_date => l_child_lot_rec.origination_date
9925 , x_date_code => l_child_lot_rec.date_code
9926 , x_status_id => l_child_lot_rec.status_id
9927 , x_change_date => l_child_lot_rec.change_date
9928 , x_age => l_child_lot_rec.age
9929 , x_retest_date => l_child_lot_rec.retest_date
9930 , x_maturity_date => l_child_lot_rec.maturity_date
9931 , x_lot_attribute_category => l_child_lot_rec.lot_attribute_category
9932 , x_item_size => l_child_lot_rec.item_size
9933 , x_color => l_child_lot_rec.color
9934 , x_volume => l_child_lot_rec.volume
9935 , x_volume_uom => l_child_lot_rec.volume_uom
9936 , x_place_of_origin => l_child_lot_rec.place_of_origin
9937 , x_best_by_date => l_child_lot_rec.best_by_date
9938 , x_length => l_child_lot_rec.length
9939 , x_length_uom => l_child_lot_rec.length_uom
9940 , x_recycled_content => l_child_lot_rec.recycled_content
9941 , x_thickness => l_child_lot_rec.thickness
9942 , x_thickness_uom => l_child_lot_rec.thickness_uom
9943 , x_width => l_child_lot_rec.width
9944 , x_width_uom => l_child_lot_rec.width_uom
9945 , x_territory_code => l_child_lot_rec.territory_code
9946 , x_expiration_date => l_child_lot_rec.expiration_date
9947 , x_disable_flag => l_child_lot_rec.disable_flag
9948 , x_attribute_category => l_child_lot_rec.attribute_category
9949 , x_origination_type => l_child_lot_rec.origination_type
9950 , x_expiration_action_date => l_child_lot_rec.expiration_action_date
9951 , x_expiration_action_code => l_child_lot_rec.expiration_action_code
9952 , x_hold_date => l_child_lot_rec.hold_date
9953 , x_last_update_date => SYSDATE
9954 , x_last_updated_by => FND_GLOBAL.USER_ID
9955 , x_creation_date => SYSDATE
9956 , x_created_by => FND_GLOBAL.USER_ID
9957 , x_last_update_login => FND_GLOBAL.LOGIN_ID
9958 , x_attribute1 => l_child_lot_rec.attribute1
9959 , x_attribute2 => l_child_lot_rec.attribute2
9960 , x_attribute3 => l_child_lot_rec.attribute3
9961 , x_attribute4 => l_child_lot_rec.attribute4
9962 , x_attribute5 => l_child_lot_rec.attribute5
9963 , x_attribute6 => l_child_lot_rec.attribute6
9964 , x_attribute7 => l_child_lot_rec.attribute7
9965 , x_attribute8 => l_child_lot_rec.attribute8
9966 , x_attribute9 => l_child_lot_rec.attribute9
9967 , x_attribute10 => l_child_lot_rec.attribute10
9968 , x_attribute11 => l_child_lot_rec.attribute11
9969 , x_attribute12 => l_child_lot_rec.attribute12
9970 , x_attribute13 => l_child_lot_rec.attribute13
9971 , x_attribute14 => l_child_lot_rec.attribute14
9972 , x_attribute15 => l_child_lot_rec.attribute15
9973 , x_c_attribute1 => l_child_lot_rec.c_attribute1
9974 , x_c_attribute2 => l_child_lot_rec.c_attribute2
9975 , x_c_attribute3 => l_child_lot_rec.c_attribute3
9976 , x_c_attribute4 => l_child_lot_rec.c_attribute4
9977 , x_c_attribute5 => l_child_lot_rec.c_attribute5
9978 , x_c_attribute6 => l_child_lot_rec.c_attribute6
9979 , x_c_attribute7 => l_child_lot_rec.c_attribute7
9980 , x_c_attribute8 => l_child_lot_rec.c_attribute8
9981 , x_c_attribute9 => l_child_lot_rec.c_attribute9
9982 , x_c_attribute10 => l_child_lot_rec.c_attribute10
9983 , x_c_attribute11 => l_child_lot_rec.c_attribute11
9984 , x_c_attribute12 => l_child_lot_rec.c_attribute12
9985 , x_c_attribute13 => l_child_lot_rec.c_attribute13
9986 , x_c_attribute14 => l_child_lot_rec.c_attribute14
9987 , x_c_attribute15 => l_child_lot_rec.c_attribute15
9988 , x_c_attribute16 => l_child_lot_rec.c_attribute16
9989 , x_c_attribute17 => l_child_lot_rec.c_attribute17
9990 , x_c_attribute18 => l_child_lot_rec.c_attribute18
9991 , x_c_attribute19 => l_child_lot_rec.c_attribute19
9992 , x_c_attribute20 => l_child_lot_rec.c_attribute20
9993 , x_d_attribute1 => l_child_lot_rec.d_attribute1
9994 , x_d_attribute2 => l_child_lot_rec.d_attribute2
9995 , x_d_attribute3 => l_child_lot_rec.d_attribute3
9996 , x_d_attribute4 => l_child_lot_rec.d_attribute4
9997 , x_d_attribute5 => l_child_lot_rec.d_attribute5
9998 , x_d_attribute6 => l_child_lot_rec.d_attribute6
9999 , x_d_attribute7 => l_child_lot_rec.d_attribute7
10000 , x_d_attribute8 => l_child_lot_rec.d_attribute8
10001 , x_d_attribute9 => l_child_lot_rec.d_attribute9
10002 , x_d_attribute10 => l_child_lot_rec.d_attribute10
10003 , x_n_attribute1 => l_child_lot_rec.n_attribute1
10004 , x_n_attribute2 => l_child_lot_rec.n_attribute2
10005 , x_n_attribute3 => l_child_lot_rec.n_attribute3
10006 , x_n_attribute4 => l_child_lot_rec.n_attribute4
10007 , x_n_attribute5 => l_child_lot_rec.n_attribute5
10008 , x_n_attribute6 => l_child_lot_rec.n_attribute6
10009 , x_n_attribute7 => l_child_lot_rec.n_attribute7
10010 , x_n_attribute8 => l_child_lot_rec.n_attribute8
10011 , x_n_attribute9 => l_child_lot_rec.n_attribute9
10012 , x_n_attribute10 => l_child_lot_rec.n_attribute10
10013 , x_request_id => NULL
10014 , x_program_application_id => NULL
10015 , x_program_id => NULL
10016 , x_program_update_date => NULL
10017 , x_curl_wrinkle_fold => l_child_lot_rec.curl_wrinkle_fold
10018 , x_description => l_child_lot_rec.description
10019 , x_vendor_id => l_child_lot_rec.vendor_id
10020 , x_sampling_event_id => l_child_lot_rec.sampling_event_id
10021 );
10022
10023 /*.Check needed for Lot UOM conversion */
10024 OPEN c_lot_uom_conv (p_lot_rec.organization_id) ;
10025 FETCH c_lot_uom_conv INTO l_lot_uom_conv ;
10026
10027 IF c_lot_uom_conv%FOUND THEN
10028 CLOSE c_lot_uom_conv ;
10029
10030 -- Possible values for mtl_parameters.lot_number_generation are:
10031 -- 1 At organization level
10032 -- 3 User defined
10033 -- 2 At item level
10034
10035 IF l_lot_uom_conv.lot_number_generation = 1 THEN
10036 l_copy_lot_attribute_flag := NVL(l_lot_uom_conv.copy_lot_attribute_flag,'N') ;
10037 ELSIF l_lot_uom_conv.lot_number_generation IN (2,3) THEN
10038 l_copy_lot_attribute_flag := NVL(l_chk_msi_attr_rec.copy_lot_attribute_flag,'N') ;
10039 END IF;
10040
10041 ELSE
10042 CLOSE c_lot_uom_conv ;
10043 END IF ;
10044
10045
10046 /* Check to see if Copy Lot UOM Conversions is required.
10047 Call MTL_LOT_UOM_CONV_PVT.COPY_LOT_UOM_CONVERSIONS */
10048
10049 IF l_copy_lot_attribute_flag = 'Y' AND l_parent_exists_flag = 'Y' THEN
10050 Mtl_Lot_Uom_Conv_Pvt.Copy_Lot_Uom_Conversions (
10051 p_from_organization_id => p_lot_rec.organization_id
10052 , p_to_organization_id => p_lot_rec.organization_id
10053 , p_inventory_item_id => p_lot_rec.inventory_item_id
10054 , p_from_lot_number => p_lot_rec.parent_lot_number
10055 , p_to_lot_number => p_lot_rec.lot_number
10056 , p_user_id => fnd_global.user_id
10057 , p_creation_date => SYSDATE
10058 , p_commit => p_commit
10059 , x_return_status => l_return_status
10060 , x_msg_count => l_msg_count
10061 , x_msg_data => l_msg_data
10062 ) ;
10063
10064 IF g_debug = 1 THEN
10065 print_debug('Program MTL_LOT_UOM_CONV_PVT.COPY_LOT_UOM return ' || l_return_status, 9);
10066 END IF;
10067 IF l_return_status = g_ret_sts_error THEN
10068 IF g_debug = 1 THEN
10069 print_debug('Program MTL_LOT_UOM_CONV_PVT.COPY_LOT_UOM has failed with a user defined exception', 9);
10070 END IF;
10071 RAISE g_exc_error;
10072 ELSIF l_return_status = g_ret_sts_unexp_error THEN
10073 IF g_debug = 1 THEN
10074 print_debug('Program MTL_LOT_UOM_CONV_PVT.COPY_LOT_UOM has failed with a Unexpected exception', 9);
10075 END IF;
10076 FND_MESSAGE.SET_NAME('INV','INV_PROGRAM_ERROR');
10077 FND_MESSAGE.SET_TOKEN('PROG_NAME','MTL_LOT_UOM_CONV_PVT.COPY_LOT_UOM');
10078 FND_MSG_PUB.ADD;
10079 RAISE g_exc_unexpected_error;
10080 END IF;
10081
10082 END IF; /* Call MTL_LOT_UOM_CONV_PVT.COPY_LOT_UOM_CONVERSIONS */
10083
10084
10085 OPEN c_get_obj_id (p_lot_rec.lot_number,p_lot_rec.inventory_item_id,p_lot_rec.organization_id);
10086 FETCH c_get_obj_id INTO l_get_obj_id_rec;
10087 IF c_get_obj_id%NOTFOUND THEN
10088 CLOSE c_get_obj_id;
10089 RAISE NO_DATA_FOUND ;
10090 END IF;
10091 CLOSE c_get_obj_id;
10092
10093 l_row_id := l_get_obj_id_rec.ROWID ;
10094 x_row_id := l_row_id ;
10095
10096 /* Populate the Our parameter, x_lot_rec */
10097 x_lot_rec := l_child_lot_rec ;
10098 x_lot_rec.gen_object_id := l_get_obj_id_rec.gen_object_id ;
10099
10100 print_debug('End of the program create_inv_lot. Program has completed successfully ', 9);
10101 EXCEPTION
10102 WHEN NO_DATA_FOUND THEN
10103 x_return_status := g_ret_sts_error;
10104 ROLLBACK TO inv_lot_1;
10105 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
10106 if( x_msg_count > 1 ) then
10107 x_msg_data := fnd_msg_pub.get(x_msg_count, FND_API.G_FALSE);
10108 end if;
10109 print_debug('In No data found Create_Inv_Lot ' || SQLERRM, 9);
10110 WHEN g_exc_error THEN
10111 x_return_status := g_ret_sts_error;
10112 ROLLBACK TO inv_lot_1;
10113 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
10114 if( x_msg_count > 1 ) then
10115 x_msg_data := fnd_msg_pub.get(x_msg_count, FND_API.G_FALSE);
10116 end if;
10117 print_debug('In g_exc_error Create_Inv_Lot ' || SQLERRM, 9);
10118 WHEN g_exc_unexpected_error THEN
10119 x_return_status := g_ret_sts_unexp_error;
10120 ROLLBACK TO inv_lot_1;
10121 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
10122 if( x_msg_count > 1 ) then
10123 x_msg_data := fnd_msg_pub.get(x_msg_count, FND_API.G_FALSE);
10124 end if;
10125 print_debug('In g_exc_unexpected_error Create_Inv_Lot ' || SQLERRM, 9);
10126 WHEN OTHERS THEN
10127 x_return_status := g_ret_sts_unexp_error;
10128 ROLLBACK TO inv_lot_1;
10129 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
10130 if( x_msg_count > 1 ) then
10131 x_msg_data := fnd_msg_pub.get(x_msg_count, FND_API.G_FALSE);
10132 end if;
10133 print_debug('In others Create_Inv_Lot ' || SQLERRM, 9);
10134
10135 END Create_Inv_lot;
10136
10137 /* HVERDDIN ADDED OLD routine back, this will call new version, Start */
10138
10139 -- Fix for Bug#12925054
10140 -- Added new parameters p_transaction_source_id and p_transaction_source_line_id
10141
10142 FUNCTION auto_gen_lot (
10143 p_org_id IN NUMBER,
10144 p_inventory_item_id IN NUMBER,
10145 p_lot_generation IN NUMBER := NULL,
10146 p_lot_uniqueness IN NUMBER := NULL,
10147 p_lot_prefix IN VARCHAR2 := NULL,
10148 p_zero_pad IN NUMBER := NULL,
10149 p_lot_length IN NUMBER := NULL,
10150 p_transaction_date IN DATE := NULL,
10151 p_revision IN VARCHAR2 := NULL,
10152 p_subinventory_code IN VARCHAR2 := NULL,
10153 p_locator_id IN NUMBER := NULL,
10154 p_transaction_type_id IN NUMBER := NULL,
10155 p_transaction_action_id IN NUMBER := NULL,
10156 p_transaction_source_type_id IN NUMBER := NULL,
10157 p_lot_number IN VARCHAR2 := NULL,
10158 p_api_version IN NUMBER,
10159 p_init_msg_list IN VARCHAR2 := fnd_api.g_false,
10160 p_commit IN VARCHAR2 := fnd_api.g_false,
10161 p_validation_level IN NUMBER
10162 := fnd_api.g_valid_level_full,
10163 x_return_status OUT NOCOPY VARCHAR2,
10164 x_msg_count OUT NOCOPY NUMBER,
10165 x_msg_data OUT NOCOPY VARCHAR2,
10166 p_transaction_source_id IN NUMBER := NULL,
10167 p_transaction_source_line_id IN NUMBER := NULL
10168 )
10169 RETURN VARCHAR2
10170 IS
10171 l_unique_lot BOOLEAN := FALSE;
10172 l_lotcount NUMBER;
10173 l_api_version CONSTANT NUMBER := 1.0;
10174 l_api_name CONSTANT VARCHAR2 ( 50 ) := 'INV_LOT_API_PUB.auto_gen_lot';
10175 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
10176 v_org_code VARCHAR2 ( 3 );
10177 v_item_name VARCHAR2 ( 40 );
10178 x_parent_lot_number MTL_LOT_NUMBERS.LOT_NUMBER%TYPE := NULL;
10179 x_parent_call MTL_LOT_NUMBERS.LOT_NUMBER%TYPE;
10180
10181 BEGIN
10182 x_parent_call := inv_lot_api_pub.auto_gen_lot (
10183 p_org_id,
10184 p_inventory_item_id,
10185 p_lot_generation,
10186 p_lot_uniqueness,
10187 p_lot_prefix,
10188 p_zero_pad,
10189 p_lot_length,
10190 p_transaction_date,
10191 p_revision,
10192 p_subinventory_code,
10193 p_locator_id,
10194 p_transaction_type_id,
10195 p_transaction_action_id,
10196 p_transaction_source_type_id,
10197 p_lot_number,
10198 p_api_version,
10199 p_init_msg_list,
10200 p_commit,
10201 p_validation_level,
10202 x_parent_lot_number,
10203 x_return_status,
10204 x_msg_count,
10205 x_msg_data,
10206 p_transaction_source_id, /* 13368816 */
10207 p_transaction_source_line_id /* 13368816 */
10208 );
10209 RETURN x_parent_call;
10210
10211
10212 EXCEPTION
10213 WHEN fnd_api.g_exc_error THEN
10214 ROLLBACK TO apiauto_gen_lot_apipub;
10215 x_return_status := fnd_api.g_ret_sts_error;
10216 fnd_msg_pub.count_and_get (
10217 p_encoded => fnd_api.g_false,
10218 p_count => x_msg_count,
10219 p_data => x_msg_data
10220 );
10221 RETURN ( NULL );
10222 WHEN fnd_api.g_exc_unexpected_error THEN
10223 ROLLBACK TO apiauto_gen_lot_apipub;
10224 x_return_status := fnd_api.g_ret_sts_unexp_error;
10225 fnd_msg_pub.count_and_get (
10226 p_encoded => fnd_api.g_false,
10227 p_count => x_msg_count,
10228 p_data => x_msg_data
10229 );
10230 RETURN ( NULL );
10231 WHEN OTHERS THEN
10232 ROLLBACK TO apiauto_gen_lot_apipub;
10233 x_return_status := fnd_api.g_ret_sts_unexp_error;
10234
10235 IF fnd_msg_pub.check_msg_level ( fnd_msg_pub.g_msg_lvl_unexp_error) THEN
10236 fnd_msg_pub.add_exc_msg ( g_pkg_name, l_api_name );
10237 END IF;
10238
10239 fnd_msg_pub.count_and_get (
10240 p_encoded => fnd_api.g_false,
10241 p_count => x_msg_count,
10242 p_data => x_msg_data
10243 );
10244 RETURN ( NULL );
10245 END auto_gen_lot;
10246
10247 /* INVCONV , HVERDDIN ADDED AUTO_GEN_LOT Wrapper for MSCA , End*/
10248
10249
10250
10251
10252 /*INVCONV , Punit Kumar */
10253
10254 /*####################################################################################
10255 #
10256 # PROCEDURE : CHECK_LOT_INDIVISIBILITY
10257 #
10258 #
10259 # DESCRIPTION : This is a wrapper procedure to call lot indivisible api
10260 # and shall be called by INV TM.
10261 # it also encorporates an enhancement to handle multiple deliveries
10262 # to INV for a lot indiv item.
10263 #
10264 #
10265 # MODIFICATION HISTORY
10266 # 07-FEB-2005 Punit Kumar Created
10267 #
10268 ######################################################################################*/
10269
10270 PROCEDURE CHECK_LOT_INDIVISIBILITY ( p_api_version IN NUMBER DEFAULT 1.0
10271 ,p_init_msg_list IN VARCHAR2 DEFAULT FND_API.G_FALSE
10272 ,p_commit IN VARCHAR2 DEFAULT FND_API.G_FALSE
10273 ,p_validation_level IN NUMBER DEFAULT FND_API.G_VALID_LEVEL_FULL
10274 ,p_rti_id IN NUMBER
10275 ,p_transaction_type_id IN NUMBER
10276 ,p_lot_number IN VARCHAR2
10277 ,p_lot_quantity IN NUMBER
10278 ,p_revision IN VARCHAR2
10279 ,p_qoh IN NUMBER DEFAULT NULL
10280 ,p_atr IN NUMBER DEFAULT NULL
10281 ,x_return_status OUT NOCOPY VARCHAR2
10282 ,x_msg_count OUT NOCOPY NUMBER
10283 ,x_msg_data OUT NOCOPY VARCHAR2
10284 )
10285 IS
10286
10287 l_api_name VARCHAR2(30) := 'CHECK_LOT_INDIVISIBILITY' ;
10288 l_api_version CONSTANT NUMBER := 1.0 ;
10289 l_return_status VARCHAR2(1) ;
10290 l_msg_data VARCHAR2(3000) ;
10291 l_msg_count NUMBER ;
10292 l_progress VARCHAR2(3) := '000' ;
10293
10294 l_parent_trx_id NUMBER ;
10295 l_pmy_rcv_qty NUMBER ;
10296 l_lot_qty NUMBER ;
10297 l_pmy_unit_of_meas VARCHAR2(100) ;
10298 l_to_organization_id NUMBER ;
10299 l_subinventory_code VARCHAR2(100) ;
10300 l_locator_id NUMBER ;
10301 l_item_id NUMBER ;
10302 l_trx_unit_of_measure VARCHAR2(100) ;
10303
10304
10305
10306 CURSOR Cr_rti_values(l_rti_id NUMBER) IS
10307 SELECT TO_ORGANIZATION_ID
10308 ,SUBINVENTORY
10309 ,locator_id
10310 ,item_id
10311 ,PARENT_TRANSACTION_ID
10312 ,UNIT_OF_MEASURE
10313 FROM RCV_TRANSACTIONS_INTERFACE
10314 WHERE INTERFACE_TRANSACTION_ID = l_rti_id;
10315
10316
10317 CURSOR Cr_rt_values(l_rt_id NUMBER) IS
10318 SELECT primary_quantity , primary_unit_of_measure
10319 FROM rcv_transactions
10320 WHERE transaction_id = l_rt_id ;
10321
10322
10323
10324 BEGIN
10325
10326 -- Standard call to check for call compatibility.
10327 IF NOT fnd_api.compatible_api_call(
10328 l_api_version,
10329 p_api_version,
10330 l_api_name,
10331 'inv_lot_api_pub'
10332 ) THEN
10333 IF (g_debug = 1) THEN
10334 print_debug('FND_API not compatible INV_LOT_API_PUB.CHECK_LOT_INDIVISIBILITY: '||l_progress, 1);
10335 END IF;
10336 RAISE fnd_api.g_exc_unexpected_error;
10337 END IF;
10338
10339 l_progress := '001';
10340
10341 -- Initialize message list if p_init_msg_list is set to TRUE.
10342 IF fnd_api.to_boolean(p_init_msg_list) THEN
10343 fnd_msg_pub.initialize;
10344 END IF;
10345
10346 --Initialize the return status
10347 x_return_status := FND_API.G_RET_STS_SUCCESS;
10348
10349 l_progress := '002';
10350
10351 /*Calling the lot indivisible function only for the following
10352 1) Deliver to Inventory (PO Receipt) --- for PO or RMA or Internal Req
10353 2) Return to Vendor (from INV)
10354 3) Return to Receiving (from INV)
10355 4) Return to Customer (from INV)---RMA
10356
10357 Since the current procedure is executed only for INV related trx ,
10358 as its being called from INV TM, so we need not code for restricting
10359 RCV location related trx.
10360 Hence restrict for the above 4 types of trx only */
10361
10362 IF p_transaction_type_id IN (18,15,61,36,37) THEN
10363
10364 ----fetching values from RTI
10365 OPEN Cr_rti_values(p_rti_id);
10366 FETCH Cr_rti_values
10367 INTO l_to_organization_id
10368 ,l_subinventory_code
10369 ,l_locator_id
10370 ,l_item_id
10371 ,l_parent_trx_id
10372 ,l_trx_unit_of_measure;
10373 CLOSE Cr_rti_values;
10374
10375 l_progress := '003';
10376
10377 IF g_debug = 1 THEN
10378 print_debug('l_to_organization_id '|| l_to_organization_id , 1);
10379 print_debug('l_subinventory_code '||l_subinventory_code , 1);
10380 print_debug('l_locator_id '|| l_locator_id, 1);
10381 print_debug('l_item_id '|| l_item_id , 1);
10382 print_debug('l_parent_trx_id '|| l_parent_trx_id, 1);
10383 print_debug('l_trx_unit_of_measure '|| l_trx_unit_of_measure, 1);
10384 print_debug('Before calling INV_LOT_API_PUB.validate_lot_indivisible ',1);
10385 END IF;
10386
10387 l_progress := '004';
10388
10389 ---call the indiv function
10390 IF NOT (INV_LOT_API_PUB.validate_lot_indivisible(
10391 p_api_version =>1.0
10392 ,p_init_msg_list =>FND_API.G_FALSE
10393 ,p_commit =>FND_API.G_FALSE
10394 ,p_validation_level =>FND_API.G_VALID_LEVEL_FULL
10395 ,p_transaction_type_id =>p_transaction_type_id
10396 ,p_organization_id =>l_to_organization_id
10397 ,p_inventory_item_id =>l_item_id
10398 ,p_revision =>p_revision
10399 ,p_subinventory_code =>l_subinventory_code
10400 ,p_locator_id =>l_locator_id
10401 ,p_lot_number =>p_lot_number
10402 ,p_primary_quantity =>p_lot_quantity------------the primary quantity of the transaction
10403 ,p_qoh =>p_qoh
10404 ,p_atr =>p_atr
10405 ,x_return_status =>l_return_status
10406 ,x_msg_count =>l_msg_count
10407 ,x_msg_data =>l_msg_data
10408 ))THEN
10409
10410 IF g_debug = 1 THEN
10411 print_debug('Program INV_LOT_API_PUB.validate_lot_indivisible return FALSE ' || l_return_status || 'and '|| l_progress, 9);
10412 END IF;
10413
10414 l_progress := '005';
10415
10416 ---If lot indiv fails fro a Return trx...
10417 IF ((l_return_status <> FND_API.G_RET_STS_SUCCESS) AND p_transaction_type_id IN (36,37)) THEN
10418
10419 /*---logic to explain the values of p_transaction_type_id
10420 IF (transaction_type IN ('RETURN TO RECEIVING','RETURN TO VENDOR','RETURN TO CUSTOMER')) THEN
10421 IF (source_document_code = 'PO') THEN
10422 p_transaction_type_id := 36;
10423 ELSIF (source_document_code = 'RMA') THEN
10424 p_transaction_type_id := 37;
10425 END IF;
10426 END IF;
10427 */
10428
10429 l_progress := '006';
10430
10431 IF l_parent_trx_id IS NULL THEN
10432 IF g_debug = 1 THEN
10433 print_debug('parent txn id cannot be null for a Return trx:'|| l_progress, 1);
10434 END IF;
10435 RAISE g_exc_unexpected_error;
10436 END IF;
10437
10438 ------------------Get previously received primary quantity for the Lot.
10439 OPEN Cr_rt_values(l_parent_trx_id) ;
10440 FETCH Cr_rt_values
10441 INTO l_pmy_rcv_qty,l_pmy_unit_of_meas;
10442 CLOSE Cr_rt_values;
10443
10444 l_progress := '007';
10445
10446 --getting lot trx qty in local var.
10447 l_lot_qty :=p_lot_quantity ;
10448
10449 ---If trx uom and previously received uom are diff
10450 IF l_pmy_unit_of_meas <> l_trx_unit_of_measure THEN
10451
10452 l_progress := '008';
10453
10454 /* Convert transaction qty in p_transaction_unit_of_measure to l_pmy_unit_of_meas */
10455
10456 l_lot_qty := INV_CONVERT.inv_um_convert(
10457 item_id => l_item_id ,
10458 lot_number => p_lot_number ,
10459 organization_id => l_to_organization_id ,
10460 precision => 5 ,
10461 from_quantity => l_lot_qty ,
10462 from_unit => NULL ,
10463 to_unit => NULL ,
10464 from_name => l_trx_unit_of_measure ,
10465 to_name => l_pmy_unit_of_meas
10466 );
10467 l_progress := '009';
10468
10469 IF l_lot_qty = -99999 THEN
10470 IF g_debug = 1 THEN
10471 print_debug('INV_CONVERT.inv_um_convert has failed '|| l_progress, 1);
10472 END IF;
10473
10474 FND_MESSAGE.SET_NAME('INV','INV_NO_CONVERSION_ERR');
10475 FND_MESSAGE.SET_TOKEN('PGM_NAME','INV_CONVERT.inv_um_convert');
10476 fnd_msg_pub.ADD;
10477 RAISE g_exc_unexpected_error;
10478 END IF;
10479
10480 END IF; -----------IF l_pmy_unit_of_meas <> p_transaction_unit_of_measure
10481
10482 /* If the trx quantity = total received quantity for that parent deliver trx
10483 then even though lot indivisibily fails , we shall allow the "Return" trx
10484 */
10485
10486 ---if the return qty is equal to full delivered qty in parent trx
10487 IF l_lot_qty = l_pmy_rcv_qty THEN
10488
10489 l_progress := '010';
10490
10491 --overriding the false return status of lot indiv api
10492 l_return_status := FND_API.G_RET_STS_SUCCESS ;
10493
10494 IF g_debug = 1 THEN
10495 print_debug('l_return_status'|| l_return_status, 9);
10496 print_debug('set return status of validate_lot_indivisible to true'|| l_progress, 9);
10497 END IF;
10498 END IF; ----------IF (l_lot_qty = l_pmy_rcv_qty
10499
10500 END IF; -------- IF ((l_return_status <>...... AND p_transaction_type_id IN.......
10501
10502 l_progress := '011';
10503
10504 IF l_return_status = fnd_api.g_ret_sts_error THEN
10505 IF g_debug = 1 THEN
10506 print_debug('Program INV_LOT_API_PUB.validate_lot_indivisible has failed with a user defined exception '|| l_progress, 9);
10507 END IF;
10508
10509 FND_MESSAGE.SET_NAME('INV','INV_PROGRAM_ERROR');
10510 FND_MESSAGE.SET_TOKEN('PGM_NAME','INV_LOT_API_PUB.validate_lot_indivisible');
10511 fnd_msg_pub.ADD;
10512 RAISE g_exc_error;
10513
10514 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
10515 l_progress := '012' ;
10516
10517 IF g_debug = 1 THEN
10518 print_debug('Program INV_LOT_API_PUB.validate_lot_indivisible has failed with a Unexpected exception' || l_progress, 9);
10519 END IF;
10520
10521 FND_MESSAGE.SET_NAME('INV','INV_PROGRAM_ERROR');
10522 FND_MESSAGE.SET_TOKEN('PGM_NAME','INV_LOT_API_PUB.validate_lot_indivisible');
10523 fnd_msg_pub.ADD;
10524 RAISE g_exc_unexpected_error;
10525 END IF;------------IF l_return_status = fnd_api.g_ret_sts_error THEN
10526
10527
10528 END IF;--------IF NOT (INV_LOT_API_PUB.validate_lot_indivisible(
10529
10530 l_progress := '013';
10531
10532 IF g_debug = 1 THEN
10533 print_debug('Program INV_LOT_API_PUB.validate_lot_indivisible return TRUE: ' || l_return_status || 'and '|| l_progress, 9);
10534 print_debug('Exitting inv_lot_api_pub.check_lot_indivisibility :'|| l_progress, 9);
10535 END IF;
10536
10537 ELSE ----------IF p_transaction_type_id IN
10538
10539 IF g_debug = 1 THEN
10540 print_debug('p_transaction_type_id:'|| p_transaction_type_id, 9);
10541 print_debug('lot indivisiblitity is not being checked for this trx type:'|| l_progress, 9);
10542 END IF;
10543
10544 END IF; ----------IF p_transaction_type_id IN
10545
10546
10547
10548 EXCEPTION
10549
10550 WHEN NO_DATA_FOUND THEN
10551 x_return_status := fnd_api.g_ret_sts_error;
10552
10553 fnd_msg_pub.count_and_get(
10554 p_encoded => fnd_api.g_false ,
10555 p_count => x_msg_count ,
10556 p_data => x_msg_data
10557 );
10558 IF( x_msg_count > 1 ) THEN
10559 x_msg_data := fnd_msg_pub.get(
10560 x_msg_count ,
10561 FND_API.G_FALSE
10562 );
10563 END IF ;
10564
10565
10566 IF g_debug = 1 THEN
10567 print_debug('Exitting CHECK_LOT_INDIVISIBILITY - No data found error:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
10568 -----print_stacked_messages;
10569 END IF;
10570
10571 WHEN g_exc_error THEN
10572
10573 x_return_status := fnd_api.g_ret_sts_error;
10574
10575 fnd_msg_pub.count_and_get(
10576 p_encoded => fnd_api.g_false ,
10577 p_count => x_msg_count ,
10578 p_data => x_msg_data
10579 );
10580
10581 IF( x_msg_count > 1 ) THEN
10582 x_msg_data := fnd_msg_pub.get(
10583 x_msg_count ,
10584 FND_API.G_FALSE
10585 );
10586 END IF;
10587
10588 IF g_debug = 1 THEN
10589 print_debug('Exitting CHECK_LOT_INDIVISIBILITY - g_exc_error error:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
10590 -----print_stacked_messages;
10591 END IF;
10592
10593
10594 WHEN g_exc_unexpected_error THEN
10595 x_return_status := fnd_api.g_ret_sts_unexp_error;
10596
10597 fnd_msg_pub.count_and_get(
10598 p_encoded => fnd_api.g_false ,
10599 p_count => x_msg_count ,
10600 p_data => x_msg_data
10601 );
10602 IF( x_msg_count > 1 ) THEN
10603 x_msg_data := fnd_msg_pub.get(
10604 x_msg_count ,
10605 FND_API.G_FALSE
10606 );
10607 END IF ;
10608
10609 IF g_debug = 1 THEN
10610 print_debug('Exitting CHECK_LOT_INDIVISIBILITY - g_exc_unexpected_error error:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
10611 --------print_stacked_messages;
10612 END IF;
10613
10614 WHEN OTHERS THEN
10615 x_return_status := fnd_api.g_ret_sts_unexp_error;
10616 fnd_msg_pub.count_and_get(
10617 p_encoded => fnd_api.g_false ,
10618 p_count => x_msg_count ,
10619 p_data => x_msg_data
10620 );
10621 IF( x_msg_count > 1 ) THEN
10622 x_msg_data := fnd_msg_pub.get(
10623 x_msg_count ,
10624 FND_API.G_FALSE);
10625 END IF;
10626
10627 IF g_debug = 1 THEN
10628 print_debug('Exitting CHECK_LOT_INDIVISIBILITY - In others error:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
10629 --------print_stacked_messages;
10630 END IF;
10631
10632
10633
10634 END CHECK_LOT_INDIVISIBILITY;
10635
10636
10637
10638 /*end , INVCONV , Punit Kumar*/
10639 -----------------------------------------------------------------------
10640 -- Name : validate_quantities
10641 -- Desc : This procedure is used to validate transaction quantity2
10642 -- if primary quantity/uom is not passed then they will be
10643 -- calculated and returned'
10644 -- if primary quantity is passed in, it will not be validated
10645 -- I/P Params :
10646 -- All the relevant transaction details :
10647 -- - organization id
10648 -- - item_id
10649 -- - lot, revision, subinventory
10650 -- - transaction quantities
10651 -- O/P Params :
10652 -- x_rerturn_status.
10653 -- RETURN VALUE :
10654 -- TRUE : IF the transaction is valid regarding Quantity2 and lot indivisible
10655 -- FALSE : IF the transaction is NOT valid regarding Quantity2 and lot indivisible
10656 --
10657 -----------------------------------------------------------------------
10658 FUNCTION validate_quantities(
10659 p_api_version IN NUMBER
10660 , p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE
10661 , p_transaction_type_id IN NUMBER
10662 , p_organization_id IN NUMBER
10663 , p_inventory_item_id IN NUMBER
10664 , p_revision IN VARCHAR2
10665 , p_subinventory_code IN VARCHAR2
10666 , p_locator_id IN NUMBER
10667 , p_lot_number IN VARCHAR2
10668 , p_transaction_quantity IN OUT NOCOPY NUMBER
10669 , p_transaction_uom_code IN VARCHAR2
10670 , p_primary_quantity IN OUT NOCOPY NUMBER
10671 , p_primary_uom_code OUT NOCOPY VARCHAR2
10672 , p_secondary_quantity IN OUT NOCOPY NUMBER
10673 , p_secondary_uom_code IN OUT NOCOPY VARCHAR2
10674 , x_return_status OUT NOCOPY VARCHAR2
10675 , x_msg_count OUT NOCOPY NUMBER
10676 , x_msg_data OUT NOCOPY VARCHAR2)
10677 RETURN BOOLEAN
10678 IS
10679 l_api_name CONSTANT VARCHAR2(30) := 'validate_quantities';
10680 l_api_version CONSTANT NUMBER := 1.0;
10681 l_lot_divisible_flag VARCHAR2(1);
10682 l_tracking_quantity_ind VARCHAR2(30);
10683 l_secondary_default_ind VARCHAR2(30);
10684 l_secondary_uom_code VARCHAR2(3);
10685 l_secondary_qty NUMBER;
10686 l_transaction_quantity NUMBER;
10687 l_primary_quantity NUMBER;
10688 l_are_qties_valid NUMBER;
10689 l_error_message VARCHAR2(500);
10690 l_lot_indiv_trx_valid BOOLEAN;
10691 l_msg VARCHAR2(2000);
10692 l_msg_index_out NUMBER;
10693 l_debug NUMBER;
10694
10695 CURSOR get_item_details( org_id IN NUMBER
10696 , item_id IN NUMBER) IS
10697 SELECT lot_divisible_flag
10698 , tracking_quantity_ind
10699 , secondary_default_ind
10700 , secondary_uom_code
10701 , primary_uom_code
10702 FROM mtl_system_items
10703 WHERE organization_id = org_id
10704 AND inventory_item_id = item_id;
10705
10706 BEGIN
10707
10708 IF (l_debug is null) THEN
10709 l_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
10710 END IF;
10711
10712 IF (l_debug = 1) THEN
10713 inv_log_util.trace('validate_quantities: Start ', g_pkg_name, 9);
10714 END IF;
10715
10716 IF FND_API.TO_BOOLEAN(p_init_msg_list) THEN
10717 FND_MSG_PUB.Initialize;
10718 END IF;
10719
10720 -- Standard call to check for call compatibility.
10721 IF NOT FND_API.COMPATIBLE_API_CALL( l_api_version
10722 , p_api_version
10723 , l_api_name
10724 , G_PKG_NAME)
10725 THEN
10726 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10727 END IF;
10728
10729 /* =======================================================================
10730 Init variables
10731 ======================================================================= */
10732 x_return_status := FND_API.G_RET_STS_SUCCESS;
10733
10734 OPEN get_item_details( p_organization_id
10735 , p_inventory_item_id);
10736 FETCH get_item_details
10737 INTO l_lot_divisible_flag
10738 , l_tracking_quantity_ind
10739 , l_secondary_default_ind
10740 , l_secondary_uom_code
10741 , p_primary_uom_code;
10742
10743 IF (get_item_details%NOTFOUND)
10744 THEN
10745 CLOSE get_item_details;
10746 FND_MESSAGE.SET_NAME('INV','ITEM_NOT_FOUND');
10747 FND_MESSAGE.SET_TOKEN('ORGANIZATION_ID', p_organization_id);
10748 FND_MESSAGE.SET_TOKEN('INVENTORY_ITEM_ID', p_inventory_item_id);
10749 FND_MSG_PUB.ADD;
10750 RAISE FND_API.G_EXC_ERROR;
10751 END IF;
10752 CLOSE get_item_details;
10753
10754 --{
10755 IF (l_tracking_quantity_ind = 'P') THEN
10756 IF (p_secondary_quantity IS NOT NULL) THEN
10757 FND_MESSAGE.SET_NAME('INV','INV_SECONDARY_QTY_NOT_REQUIRED');
10758 FND_MSG_PUB.ADD;
10759 RAISE FND_API.G_EXC_ERROR;
10760 END IF;
10761
10762 IF (p_secondary_uom_code IS NOT NULL) THEN
10763 FND_MESSAGE.SET_NAME('INV','INV_SECONDARY_UOM_NOT_REQUIRED');
10764 FND_MSG_PUB.ADD;
10765 RAISE FND_API.G_EXC_ERROR;
10766 END IF;
10767
10768 ELSIF (l_tracking_quantity_ind = 'PS') THEN
10769 -- the item is DUOM controlled
10770 /** UOM Validation **/
10771 /** UOM Validation **/
10772 IF (p_secondary_uom_code <> l_secondary_uom_code) THEN
10773 FND_MESSAGE.SET_NAME('INV','INV_INCORRECT_SECONDARY_UOM');
10774 FND_MSG_PUB.ADD;
10775 RAISE FND_API.G_EXC_ERROR;
10776 END IF;
10777
10778 -- Set the default UOM2 if missing or incorrect:
10779 IF (p_secondary_uom_code IS NULL) THEN
10780 p_secondary_uom_code := l_secondary_uom_code;
10781 END IF;
10782
10783 /** Quantity Validation **/
10784 IF ((p_transaction_quantity IS NULL AND p_secondary_quantity IS NULL) OR
10785 (l_secondary_default_ind = 'N' AND (p_transaction_quantity IS NULL
10786 OR p_secondary_quantity IS NULL))) THEN
10787 IF (l_debug = 1) THEN
10788 inv_log_util.trace('validate_quantities: Missing both quantities or one qty for no default item ..', g_pkg_name, 9);
10789 END IF;
10790 FND_MESSAGE.SET_NAME('INV','INV_INT_QTYCODE');
10791 FND_MSG_PUB.ADD;
10792 RAISE FND_API.G_EXC_ERROR;
10793 END IF;
10794 --{
10795 IF (p_secondary_quantity IS NULL) THEN
10796 -- Set the Qty2 from Qty1 if missing:
10797 l_secondary_qty := INV_CONVERT.INV_UM_CONVERT
10798 ( item_id => p_inventory_item_id
10799 , lot_number => p_lot_number
10800 , organization_id => p_organization_id
10801 , precision => 5
10802 , from_quantity => p_transaction_quantity
10803 , from_unit => p_transaction_uom_code
10804 , to_unit => p_secondary_uom_code
10805 , from_name => NULL
10806 , to_name => NULL);
10807
10808 IF (l_secondary_qty = -99999) THEN
10809 IF (l_debug = 1) THEN
10810 inv_log_util.trace('validate_quantities: INV_CONVERT.INV_UM_CONVERT error ', g_pkg_name, 9);
10811 END IF;
10812 FND_MESSAGE.SET_NAME('INV','INV_NO_CONVERSION_ERR');
10813 FND_MSG_PUB.ADD;
10814 RAISE FND_API.G_EXC_ERROR;
10815 END IF;
10816 p_secondary_quantity := l_secondary_qty;
10817 IF (l_debug = 1) THEN
10818 inv_log_util.trace('validate_quantities: new secondary qty is: '|| l_secondary_qty , g_pkg_name, 9);
10819 END IF;
10820 ELSIF (p_transaction_quantity IS NULL) THEN
10821 -- Set the Qty1 from Qty2 if missing:
10822 l_transaction_quantity := INV_CONVERT.INV_UM_CONVERT
10823 ( item_id => p_inventory_item_id
10824 , lot_number => p_lot_number
10825 , organization_id => p_organization_id
10826 , precision => 5
10827 , from_quantity => p_secondary_quantity
10828 , from_unit => p_secondary_uom_code
10829 , to_unit => p_transaction_uom_code
10830 , from_name => NULL
10831 , to_name => NULL);
10832
10833 IF (l_transaction_quantity = -99999) THEN
10834 IF (l_debug = 1) THEN
10835 inv_log_util.trace('validate_quantities: INV_CONVERT.INV_UM_CONVERT ERROR ', g_pkg_name, 9);
10836 END IF;
10837 FND_MESSAGE.SET_NAME('INV','INV_NO_CONVERSION_ERR');
10838 FND_MSG_PUB.ADD;
10839 RAISE FND_API.G_EXC_ERROR;
10840 END IF;
10841 p_transaction_quantity := l_transaction_quantity;
10842 IF (l_debug = 1) THEN
10843 inv_log_util.trace('validate_quantities: new transaction qty is: '|| l_transaction_quantity , g_pkg_name, 9);
10844 END IF;
10845 ELSIF (p_transaction_quantity IS NOT NULL AND p_secondary_quantity IS NOT NULL) THEN
10846 IF (l_debug = 1) THEN
10847 inv_log_util.trace('validate_quantities: calling INV_CONVERT.WITHIN_DEVIATION', g_pkg_name, 9);
10848 END IF;
10849 -- Validate the quantitioes within deviation :
10850 l_are_qties_valid := INV_CONVERT.within_deviation(
10851 p_organization_id => p_organization_id
10852 , p_inventory_item_id => p_inventory_item_id
10853 , p_lot_number => p_lot_number
10854 , p_precision => 5
10855 , p_quantity => ABS(p_transaction_quantity)
10856 , p_uom_code1 => p_transaction_uom_code
10857 , p_quantity2 => ABS(p_secondary_quantity)
10858 , p_uom_code2 => p_secondary_uom_code);
10859
10860 IF (l_are_qties_valid = 0) THEN
10861 IF (l_debug = 1) THEN
10862 inv_log_util.trace('validate_quantities: INV_CONVERT.within_deviation (ERROR)' , g_pkg_name, 9);
10863 inv_log_util.trace('p_transaction_quantity: ' || p_transaction_quantity ||
10864 ' p_transaction_uom_code: ' || p_transaction_uom_code, g_pkg_name, 9);
10865 inv_log_util.trace(' p_secondary_quantity: ' || p_secondary_quantity ||
10866 ' p_secondary_uom_code: ' || p_secondary_uom_code, g_pkg_name, 9);
10867 inv_log_util.trace(' p_lot_number: ' || p_lot_number || ' p_inventory_item_id: '||
10868 p_inventory_item_id || ' p_organization_id: ' || p_organization_id, g_pkg_name, 9);
10869 END IF;
10870 RAISE FND_API.G_EXC_ERROR;
10871 END IF;
10872 IF (l_debug = 1) THEN
10873 inv_log_util.trace('validate_quantities: INV_CONVERT.within_deviation (PASS)' , g_pkg_name, 9);
10874 END IF;
10875 END IF;--}
10876 END IF;--} -- l_tracking_quantity_ind != 'P'
10877 -- Set the prim Qty from transaction Qty if missing:
10878 --{
10879 IF (p_primary_quantity IS NULL) THEN
10880 l_primary_quantity := INV_CONVERT.INV_UM_CONVERT
10881 ( item_id => p_inventory_item_id
10882 , lot_number => p_lot_number
10883 , organization_id => p_organization_id
10884 , precision => 5
10885 , from_quantity => p_transaction_quantity
10886 , from_unit => p_transaction_uom_code
10887 , to_unit => p_primary_uom_code
10888 , from_name => NULL
10889 , to_name => NULL);
10890
10891 IF (l_primary_quantity = -99999) THEN
10892 IF (l_debug = 1) THEN
10893 inv_log_util.trace('validate_quantities: INV_CONVERT.INV_UM_CONVERT error ', g_pkg_name, 9);
10894 END IF;
10895 FND_MESSAGE.SET_NAME('INV','INV_NO_CONVERSION_ERR');
10896 FND_MSG_PUB.ADD;
10897 RAISE FND_API.G_EXC_ERROR;
10898 END IF;
10899 p_primary_quantity := l_primary_quantity;
10900 IF (l_debug = 1) THEN
10901 inv_log_util.trace('validate_quantities: new primary qty is: '|| l_primary_quantity , g_pkg_name, 9);
10902 END IF;
10903 END IF;--} -- primary_quantity check
10904
10905 -- Lot Indivisible Validation:
10906 --{
10907 IF (l_lot_divisible_flag = 'N') THEN
10908 l_lot_indiv_trx_valid := INV_LOT_API_PUB.VALIDATE_LOT_INDIVISIBLE
10909 ( p_api_version => p_api_version
10910 , p_init_msg_list => p_init_msg_list
10911 , p_transaction_type_id => p_transaction_type_id
10912 , p_organization_id => p_organization_id
10913 , p_inventory_item_id => p_inventory_item_id
10914 , p_revision => p_revision
10915 , p_subinventory_code => p_subinventory_code
10916 , p_locator_id => p_locator_id
10917 , p_lot_number => p_lot_number
10918 , p_primary_quantity => p_primary_quantity
10919 , p_qoh => NULL
10920 , p_atr => NULL
10921 , x_return_status => x_return_status
10922 , x_msg_count => x_msg_count
10923 , x_msg_data => x_msg_data);
10924
10925
10926 IF (NOT l_lot_indiv_trx_valid) THEN
10927 -- the transaction is not valid regarding lot indivisible:
10928 IF (l_debug = 1) THEN
10929 inv_log_util.trace('validate_quantities: INV_LOT_API_PUB.VALIDATE_LOT_INDIVISIBLE (ERROR)', g_pkg_name, 9);
10930 END IF;
10931 RAISE FND_API.G_EXC_ERROR;
10932 END IF;
10933 IF (l_debug = 1) THEN
10934 inv_log_util.trace('validate_quantities: INV_LOT_API_PUB.VALIDATE_LOT_INDIVISIBLE (PASS) ', g_pkg_name, 9);
10935 END IF;
10936
10937 END IF;--} -- l_lot_divisible_flag = 'N'
10938
10939 IF (l_debug = 1) THEN
10940 inv_log_util.trace('validate_quantities: End .... ', g_pkg_name, 9);
10941 END IF;
10942
10943 RETURN TRUE;
10944
10945 EXCEPTION
10946 WHEN FND_API.G_EXC_ERROR THEN
10947 x_return_status := FND_API.G_RET_STS_ERROR;
10948 IF (l_debug = 1) THEN
10949 inv_log_util.trace('validate_quantities: FND_API.G_EXC_ERROR ', g_pkg_name, 9);
10950 END IF;
10951 FND_MSG_PUB.Count_AND_GET (p_count => x_msg_count, p_data => x_msg_data);
10952 RETURN FALSE;
10953
10954 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
10955 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
10956 IF (l_debug = 1) THEN
10957 inv_log_util.trace('validate_quantities:when unexp sqlcode= '||sqlcode||' sqlerrm= '||substr(sqlerrm,1,240), g_pkg_name, 9);
10958 END IF;
10959 FND_MSG_PUB.Count_AND_GET (p_count => x_msg_count, p_data => x_msg_data);
10960 RETURN FALSE;
10961
10962 WHEN OTHERS THEN
10963 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
10964 IF (l_debug = 1) THEN
10965 inv_log_util.trace('validate_quantities:when others sqlcode= '||sqlcode||' sqlerrm= '||substr(sqlerrm,1,240), g_pkg_name, 9);
10966 END IF;
10967 FND_MSG_PUB.Count_AND_GET (p_count => x_msg_count, p_data => x_msg_data);
10968 RETURN FALSE;
10969
10970 END validate_quantities;
10971
10972 --This procedure checks whether lot specific conversion exist in source org or not
10973 --If lot specific conversion exist then it will create the lot specific conversion
10974 -- in desitnation org
10975 --BUG#10202198
10976
10977 PROCEDURE lot_UOM_conv_OrgTxf (
10978 p_organization_id IN NUMBER
10979 , p_inventory_item_id IN NUMBER
10980 , p_xfr_organization_id IN NUMBER
10981 , p_lot_number IN VARCHAR2
10982 , p_transaction_temp_id IN NUMBER
10983 , p_to_UOM_code IN VARCHAR2
10984 , p_from_UOM_code IN VARCHAR2
10985 , x_return_status OUT NOCOPY VARCHAR2
10986 , x_msg_count OUT NOCOPY NUMBER
10987 , x_msg_data OUT NOCOPY VARCHAR2) IS
10988
10989 l_object_id NUMBER;
10990 l_transaction_action_id NUMBER;
10991 l_create_lot_uom_conversion NUMBER;
10992 l_value NUMBER;
10993 l_debug NUMBER ;
10994 l_expiration_date DATE;
10995 l_to_UOM_code VARCHAR2(50);
10996 l_from_UOM_code VARCHAR2(50);
10997
10998 CURSOR c_check_exists(p_org_id NUMBER,p_to_UOM VARCHAR2 ,p_from_UOM VARCHAR2) IS
10999 SELECT 1
11000 FROM mtl_lot_uom_class_conversions
11001 WHERE organization_id = p_org_id
11002 AND lot_number = p_lot_number
11003 AND inventory_item_id = p_inventory_item_id
11004 AND TO_UOM_CODE=p_to_UOM
11005 AND FROM_UOM_CODE=p_from_UOM;
11006
11007 CURSOR check_lot_exists (p_org_id NUMBER )IS
11008 SELECT LOT_NUMBER, EXPIRATION_DATE FROM MTL_LOT_NUMBERS
11009 WHERE ORGANIZATION_ID =p_org_id
11010 AND INVENTORY_ITEM_ID = p_inventory_item_id
11011 AND LOT_NUMBER =p_lot_number;
11012
11013 l_lot_rec check_lot_exists%rowtype;
11014
11015 BEGIN
11016 IF (l_debug = 1) THEN
11017 inv_log_util.trace('lot_UOM_conv_OrgTxf: inside proc ', g_pkg_name,9);
11018 inv_log_util.trace('lot_UOM_conv_OrgTxf: p_organization_id '||p_organization_id, g_pkg_name,9);
11019 inv_log_util.trace('lot_UOM_conv_OrgTxf: p_inventory_item_id '||p_inventory_item_id, g_pkg_name,9) ;
11020 inv_log_util.trace('lot_UOM_conv_OrgTxf: p_xfr_organization_id '||p_xfr_organization_id, g_pkg_name,9) ;
11021 inv_log_util.trace('lot_UOM_conv_OrgTxf: p_lot_number '||p_lot_number, g_pkg_name,9) ;
11022 inv_log_util.trace('lot_UOM_conv_OrgTxf: p_transaction_temp_id '||p_transaction_temp_id, g_pkg_name,9) ;
11023 inv_log_util.trace('lot_UOM_conv_OrgTxf: p_to_UOM_code '||p_to_UOM_code, g_pkg_name,9) ;
11024 inv_log_util.trace('lot_UOM_conv_OrgTxf: p_from_UOM_code '||p_from_UOM_code, g_pkg_name,9) ;
11025 END IF ;
11026
11027
11028 begin
11029 select transaction_action_id INTO l_transaction_action_id
11030 FROM MTL_MATERIAL_TRANSACTIONS_TEMP
11031 WHERE transaction_temp_id=p_transaction_temp_id;
11032 EXCEPTION
11033 WHEN No_Data_Found THEN
11034 l_transaction_action_id:=NULL;
11035 END ;
11036
11037 begin
11038 SELECT create_lot_uom_conversion INTO l_create_lot_uom_conversion
11039 FROM mtl_parameters
11040 WHERE organization_id =p_organization_id ;
11041 EXCEPTION
11042 WHEN No_Data_Found THEN
11043 l_create_lot_uom_conversion:=NULL;
11044 END;
11045 IF (l_debug = 1) THEN
11046 inv_log_util.trace('lot_UOM_conv_OrgTxf: create_lot_uom_conversion '||l_create_lot_uom_conversion, g_pkg_name,9);
11047 END IF ;
11048
11049 BEGIN
11050 SELECT uom_code INTO l_to_UOM_code
11051 FROM mtl_units_of_measure
11052 WHERE uom_class IN (SELECT uom_class
11053 FROM mtl_units_of_measure
11054 WHERE uom_code = p_to_UOM_code)
11055 AND base_uom_flag = 'Y';
11056 EXCEPTION
11057 WHEN No_Data_Found THEN
11058 l_to_UOM_code:=p_to_UOM_code;
11059 END;
11060
11061 BEGIN
11062 SELECT uom_code INTO l_from_UOM_code
11063 FROM mtl_units_of_measure
11064 WHERE uom_class IN (SELECT uom_class
11065 FROM mtl_units_of_measure
11066 WHERE uom_code = p_from_UOM_code)
11067 AND base_uom_flag = 'Y';
11068 EXCEPTION
11069 WHEN No_Data_Found THEN
11070 l_to_UOM_code:=p_from_UOM_code;
11071 END;
11072 IF (l_debug = 1) THEN
11073 inv_log_util.trace('lot_UOM_conv_OrgTxf: l_to_UOM_code '||l_to_UOM_code, g_pkg_name,9);
11074 inv_log_util.trace('lot_UOM_conv_OrgTxf: l_from_UOM_code '||l_from_UOM_code, g_pkg_name,9);
11075
11076 END IF ;
11077
11078
11079 IF (l_create_lot_uom_conversion =1 OR l_create_lot_uom_conversion=3) THEN
11080 IF (l_debug = 1) THEN
11081 inv_log_util.trace('lot_UOM_conv_OrgTxf: first IF', g_pkg_name,9);
11082 END IF ;
11083 OPEN c_check_exists(p_xfr_organization_id,l_to_UOM_code,l_from_UOM_code);
11084 FETCH c_check_exists into l_value;
11085 inv_log_util.trace('lot_UOM_conv_OrgTxf: l_value'||l_value, g_pkg_name,9);
11086 IF c_check_exists%FOUND THEN
11087
11088 IF (l_debug = 1) THEN
11089 inv_log_util.trace('lot_UOM_conv_OrgTxf: cursor c_check_exists found', g_pkg_name,9);
11090 END IF ;
11091
11092 OPEN check_lot_exists(p_organization_id);
11093 FETCH check_lot_exists INTO l_lot_rec;
11094
11095 IF (l_debug = 1) THEN
11096 inv_log_util.trace('lot_UOM_conv_OrgTxf: checking check_lot_exists ', g_pkg_name,9);
11097 END IF ;
11098
11099 IF check_lot_exists%FOUND THEN
11100 CLOSE c_check_exists;
11101
11102 IF (l_debug = 1) THEN
11103 inv_log_util.trace('lot_UOM_conv_OrgTxf: cursor check_lot_exists found', g_pkg_name,9);
11104 END IF;
11105
11106 OPEN c_check_exists(p_organization_id,l_to_UOM_code,l_from_UOM_code);
11107 FETCH c_check_exists into l_value;
11108 IF c_check_exists%NOTFOUND THEN
11109
11110 IF (l_debug = 1) THEN
11111 inv_log_util.trace('lot_UOM_conv_OrgTxf: 1', g_pkg_name,9);
11112 END IF;
11113
11114 create_lot_UOM_conv_orgtxf(
11115 p_organization_id => p_organization_id
11116 , p_inventory_item_id => p_inventory_item_id
11117 , p_xfr_organization_id => p_xfr_organization_id
11118 , p_lot_number => p_lot_number
11119 , p_to_UOM_code => l_to_UOM_code
11120 , p_from_UOM_code => l_from_UOM_code
11121 , x_return_status => x_return_status
11122 , x_msg_count => x_msg_count
11123 , x_msg_data => x_msg_data);
11124
11125 END IF;
11126 CLOSE check_lot_exists;
11127 ELSIF check_lot_exists%NOTFOUND THEN
11128
11129 IF (l_debug = 1) THEN
11130 inv_log_util.trace('lot_UOM_conv_OrgTxf: in else', g_pkg_name,9);
11131 END IF;
11132
11133 begin
11134 SELECT EXPIRATION_DATE INTO l_expiration_date FROM MTL_LOT_NUMBERS
11135 WHERE ORGANIZATION_ID =p_xfr_organization_id
11136 AND INVENTORY_ITEM_ID = p_inventory_item_id
11137 AND LOT_NUMBER =p_lot_number;
11138 EXCEPTION
11139 WHEN No_Data_Found THEN
11140 l_expiration_date:=NULL;
11141 END;
11142 IF (l_debug = 1) THEN
11143 inv_log_util.trace('lot_UOM_conv_OrgTxf: 2' ||l_expiration_date, g_pkg_name,9);
11144 END IF;
11145 inv_lot_api_pub.insertlot(
11146 p_api_version => 1.0
11147 , p_init_msg_list => fnd_api.g_false
11148 , p_commit => fnd_api.g_false
11149 , p_validation_level => fnd_api.g_valid_level_full
11150 , p_inventory_item_id => p_inventory_item_id
11151 , p_organization_id => p_organization_id
11152 , p_lot_number => p_lot_number
11153 , p_expiration_date => l_expiration_date
11154 , p_transaction_temp_id => p_transaction_temp_id
11155 , p_transaction_action_id => l_transaction_action_id
11156 , p_transfer_organization_id => p_xfr_organization_id
11157 , x_object_id => l_transaction_action_id
11158 , x_return_status => x_return_status
11159 , x_msg_count => x_msg_count
11160 , x_msg_data => x_msg_data
11161 );
11162 IF x_return_status <> FND_API.g_ret_sts_success THEN
11163 IF (l_debug = 1) THEN
11164 inv_log_util.trace('Lot insertion failed. ',g_pkg_name,9);
11165 END IF;
11166 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
11167 END IF;
11168 IF (l_debug = 1) THEN
11169 inv_log_util.trace('lot_UOM_conv_OrgTxf: 3', g_pkg_name,9);
11170 END IF;
11171 create_lot_UOM_conv_orgtxf(
11172 p_organization_id => p_organization_id
11173 , p_inventory_item_id => p_inventory_item_id
11174 , p_xfr_organization_id => p_xfr_organization_id
11175 , p_lot_number => p_lot_number
11176 , p_to_UOM_code => l_to_UOM_code
11177 , p_from_UOM_code => l_from_UOM_code
11178 , x_return_status => x_return_status
11179 , x_msg_count => x_msg_count
11180 , x_msg_data => x_msg_data);
11181 CLOSE check_lot_exists;
11182 END IF;
11183 END IF;
11184 END IF;
11185 IF (l_debug = 1) THEN
11186 inv_log_util.trace('lot_UOM_conv_OrgTxf: end', g_pkg_name,9);
11187 END IF;
11188
11189 x_return_status := FND_API.G_RET_STS_SUCCESS;
11190
11191 EXCEPTION
11192 WHEN FND_API.G_EXC_ERROR THEN
11193 x_return_status := FND_API.G_RET_STS_ERROR;
11194 IF (l_debug = 1) THEN
11195 inv_log_util.trace('lot_UOM_conv_OrgTxf: FND_API.G_EXC_ERROR ', g_pkg_name,9);
11196 END IF;
11197 FND_MSG_PUB.Count_AND_GET (p_count => x_msg_count, p_data => x_msg_data);
11198
11199 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
11200 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
11201 IF (l_debug = 1) THEN
11202 inv_log_util.trace('lot_UOM_conv_OrgTxf:when unexp sqlcode= '||sqlcode||' sqlerrm= '||substr(sqlerrm,1,240), g_pkg_name,9);
11203 END IF;
11204 FND_MSG_PUB.Count_AND_GET (p_count => x_msg_count, p_data => x_msg_data);
11205
11206 WHEN OTHERS THEN
11207 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
11208 IF (l_debug = 1) THEN
11209 inv_log_util.trace('lot_UOM_conv_OrgTxf:when others sqlcode= '||sqlcode||' sqlerrm= '||substr(sqlerrm,1,240), g_pkg_name,9);
11210 END IF;
11211 FND_MSG_PUB.Count_AND_GET (p_count => x_msg_count, p_data => x_msg_data);
11212 END lot_UOM_conv_OrgTxf;
11213
11214 --this procedure inserts data in MTL_LOT_UOM_CLASS_CONVERSIONS table
11215 --Bug#10202198
11216
11217 PROCEDURE create_lot_UOM_conv_orgtxf (
11218 p_organization_id IN NUMBER
11219 , p_inventory_item_id IN NUMBER
11220 , p_xfr_organization_id IN NUMBER
11221 , p_lot_number IN VARCHAR2
11222 , p_to_UOM_code IN VARCHAR2
11223 , p_from_UOM_code IN VARCHAR2
11224 , x_return_status OUT NOCOPY VARCHAR2
11225 , x_msg_count OUT NOCOPY NUMBER
11226 , x_msg_data OUT NOCOPY VARCHAR2) IS
11227
11228 l_conv_seq NUMBER;
11229 l_debug NUMBER;
11230
11231 CURSOR GET_CONV_SEQ
11232 IS
11233 SELECT MTL_CONVERSION_ID_S.NEXTVAL
11234 FROM FND_DUAL;
11235
11236 BEGIN
11237 --IF (l_debug = 1) THEN
11238 inv_log_util.trace('create_lot_UOM_conv_orgtxf: start ', g_pkg_name, 9);
11239 --END IF;
11240 OPEN GET_CONV_SEQ;
11241 FETCH GET_CONV_SEQ INTO l_conv_seq;
11242 CLOSE GET_CONV_SEQ;
11243
11244 INSERT INTO MTL_LOT_UOM_CLASS_CONVERSIONS(
11245 CONVERSION_ID,
11246 LOT_NUMBER,
11247 ORGANIZATION_ID,
11248 INVENTORY_ITEM_ID,
11249 FROM_UNIT_OF_MEASURE,
11250 FROM_UOM_CODE,
11251 FROM_UOM_CLASS,
11252 TO_UNIT_OF_MEASURE,
11253 TO_UOM_CODE,
11254 TO_UOM_CLASS,
11255 CONVERSION_RATE,
11256 DISABLE_DATE,
11257 EVENT_SPEC_DISP_ID,
11258 CREATED_BY,
11259 CREATION_DATE,
11260 LAST_UPDATED_BY,
11261 LAST_UPDATE_DATE,
11262 LAST_UPDATE_LOGIN,
11263 REQUEST_ID,
11264 PROGRAM_APPLICATION_ID,
11265 PROGRAM_ID,
11266 PROGRAM_UPDATE_DATE
11267 )
11268 SELECT
11269 l_conv_seq
11270 , LOT_NUMBER
11271 , p_organization_id
11272 , INVENTORY_ITEM_ID
11273 , FROM_UNIT_OF_MEASURE
11274 , FROM_UOM_CODE
11275 , FROM_UOM_CLASS
11276 , TO_UNIT_OF_MEASURE
11277 , TO_UOM_CODE
11278 , TO_UOM_CLASS
11279 , CONVERSION_RATE
11280 , DISABLE_DATE
11281 , EVENT_SPEC_DISP_ID
11282 , CREATED_BY
11283 , CREATION_DATE
11284 , LAST_UPDATED_BY
11285 , LAST_UPDATE_DATE
11286 , LAST_UPDATE_LOGIN
11287 , REQUEST_ID
11288 , PROGRAM_APPLICATION_ID
11289 , PROGRAM_ID
11290 , PROGRAM_UPDATE_DATE
11291 FROM MTL_LOT_UOM_CLASS_CONVERSIONS
11292 where LOT_NUMBER=p_lot_number
11293 and ORGANIZATION_ID=p_xfr_organization_id
11294 and INVENTORY_ITEM_ID=p_inventory_item_id
11295 AND TO_UOM_CODE=p_to_UOM_code
11296 AND FROM_UOM_CODE=p_from_UOM_code ;
11297
11298 x_return_status := FND_API.G_RET_STS_SUCCESS;
11299 --IF (l_debug = 1) THEN
11300 inv_log_util.trace('create_lot_UOM_conv_orgtxf: end ', g_pkg_name, 9);
11301 --END IF;
11302 EXCEPTION
11303 WHEN FND_API.G_EXC_ERROR THEN
11304 x_return_status := FND_API.G_RET_STS_ERROR;
11305 IF (l_debug = 1) THEN
11306 inv_log_util.trace('create_lot_UOM_conv_orgtxf: FND_API.G_EXC_ERROR ', g_pkg_name,9);
11307 END IF;
11308 FND_MSG_PUB.Count_AND_GET (p_count => x_msg_count, p_data => x_msg_data);
11309
11310 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
11311 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
11312 IF (l_debug = 1) THEN
11313 inv_log_util.trace('create_lot_UOM_conv_orgtxf:when unexp sqlcode= '||sqlcode||' sqlerrm= '||substr(sqlerrm,1,240), g_pkg_name,9);
11314 END IF;
11315 FND_MSG_PUB.Count_AND_GET (p_count => x_msg_count, p_data => x_msg_data);
11316
11317 WHEN OTHERS THEN
11318 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
11319 IF (l_debug = 1) THEN
11320 inv_log_util.trace('create_lot_UOM_conv_orgtxf:when others sqlcode= '||sqlcode||' sqlerrm= '||substr(sqlerrm,1,240), g_pkg_name,9);
11321 END IF;
11322 FND_MSG_PUB.Count_AND_GET (p_count => x_msg_count, p_data => x_msg_data);
11323
11324
11325 END create_lot_UOM_conv_orgtxf;
11326
11327 END inv_lot_api_pub;
11328
11329