[Home] [Help]
PACKAGE BODY: APPS.GMD_OUTBOUND_APIS_PUB
Source
1 PACKAGE BODY GMD_OUTBOUND_APIS_PUB AS
2 /* $Header: GMDOAPIB.pls 120.17 2011/05/05 17:57:40 rnalla ship $ */
3 --****************************************************************************************
4 --* FILE: GMDOAPIB.pls *
5 --* *
6 --* CONTENTS: Public level outbound GMD Quality API package *
7 --* *
8 --* AUTHOR: Paul Schofield, OPM Development EMEA *
9 --* *
10 --* DATE: May 20th 2003 *
11 --* *
12 --* VERSION CHANGED BY CHANGE *
13 --* ======= ========== ====== *
14 --* 20May03 P.J.Schofield New file *
15 --* 17Jun03 K.Y.Hunt Merged in 3 new APIs *
16 --* 03Jul03 P.J.Schofield Added sampling groups API *
17 --* 04Jul03 P.J.Schofield Added user_name parameters for logging *
18 --* 28Aug03 Chetan Nagar Added mini-pack K specific features. *
19 --* 18Dec03 Brenda Stone Bug 3124627 Fetch Sample Groups; Changed *
20 --* EVENT_ID to SAMPLING_EVENT_ID in where clause *
21 --* 18Dec03 Brenda Stone Bug 3124643 Fetch Sample Groups; Changed *
22 --* r.recipe_no to r.recipe_vers *
23 --* 26Dec03 Brenda Stone Bug 3133163; Default test method was not retrieved, *
24 --* Added wildcard (+) since the default test methods's *
25 --* user_id is not in FND_USERS table. *
26 --* 29Dec03 Brenda Stone Bug 3124620; Fetch_Sample_Groups, Changed where clause *
27 --* to validate the orgn_code * *
28 --* 29Dec03 Brenda Stone Bug 3124643; Fetch_Sample_Groups, Changed r.recipe_no*
29 --* to r.recipe_version *
30 --* 31Dec03 Brenda Stone Bug 3124653; Fetch_Sample_Groups. Added code to *
31 --* retrieve Sample Groups by customer_ship_to_location & *
32 --* customer_ship_to_location_id *
33 --* 15Jan04 Brenda Stone Added mini-pack L specific features *
34 --* 24Feb04 Brenda Stone Bug 3394055; Added L columns to results and *
35 --* composite results *
36 --* 05May04 SaiKiran Bug 3704049; Added 'delayed_lot_entry' to the column *
37 --* lists in 'FETCH_SPEC_VRS' procedure for WIP, Supplier *
38 --* and Inventory VRs *
39 --* 20Sep04 Brenda Stone Bug 3704049; Added auto_sample_ind field for WIP, *
40 --* Supplier and Inventory VRs *
41 --* 02May05 Saikiran Vankadari Convergence changes done for fetch_spec_vrs() procedure.*
42 --* Changed all references of OPM Inventory tables to Discrete inventory tables*
43 --* 20Jun05 S Feinstein Convergence changes done for fetch samples and fetch *
44 --* sample groups.
45 --* 26Aug05 Saikiran Vankadari Convergence changes done for fetch test methods procedure*
46 --* 10Oct05 RLNAGARA Bug # 4548546 - Added code to fetch records using revision*
47 --* 10Nov05 RLNAGARA Bug # 4616835 - Changed all the references of TYPE *
48 --* objects to SYSTEM schema. *
49 --* 12Jun06 PLOWE Bug # 5346713 *
50 --* 22Jun06 PLOWE Bug # 5284242 - add 'system.' for xdf tab_types *
51 --* 26Jun06 PLOWE Bug # 5335829 rework *
52 --* 03Jul06 PLOWE Bug # 5346713 rework *
53 --* 03Jul06 PLOWE Bug # 5346480 rework *
54 --* 05May08 PLOWE Bug # 7027149 support for LPN
55 --****************************************************************************************
56 --* *
57 --* COPYRIGHT (c) Oracle Corporation 2003 *
58 --* *
59 --****************************************************************************************
60
61
62
63
64 -- Small setup routine for the rest of the package called internally.
65
66 FUNCTION initialized_ok
67 ( p_user_name IN VARCHAR2)
68 RETURN BOOLEAN
69 IS
70 l_user_id NUMBER;
71 BEGIN
72
73 SELECT user_id INTO l_user_id
74 FROM fnd_user
75 WHERE user_name = UPPER(p_user_name)
76 AND SYSDATE BETWEEN start_date AND NVL(end_date,sysdate+1);
77
78 FND_GLOBAL.apps_initialize(l_user_id, NULL, NULL, 0);
79 --gme_debug.log_initialize('PAL_GMD_OUTBOUND_API');
80
81 RETURN TRUE;
82
83 EXCEPTION
84 WHEN NO_DATA_FOUND
85 THEN
86 gmd_api_pub.log_message('GMD_INVALID_USER_NAME', 'p_user_name', p_user_name);
87 RETURN FALSE;
88 WHEN OTHERS
89 THEN
90 gmd_api_pub.log_message('GMD_API_ERROR','Initialization failed', substr(SQLERRM,1,100));
91 RETURN FALSE;
92 END initialized_ok;
93
94 PROCEDURE fetch_test_methods
95 ( p_api_version IN NUMBER
96 , p_init_msg_list IN VARCHAR2 DEFAULT FND_API.G_FALSE
97 , p_user_name IN VARCHAR2
98 , p_from_test_method_code IN VARCHAR2 DEFAULT NULL
99 , p_to_test_method_code IN VARCHAR2 DEFAULT NULL
100 , p_test_method_id IN NUMBER DEFAULT NULL
101 , p_test_kit_organization_id IN NUMBER DEFAULT NULL --INVCONV
102 --, p_test_kit_item_no IN VARCHAR2 DEFAULT NULL --INVCONV
103 --, p_test_kit_item_id IN NUMBER DEFAULT NULL --INVCONV
104 , p_test_kit_inv_item_id IN NUMBER DEFAULT NULL --INVCONV
105 , p_resource IN VARCHAR2 DEFAULT NULL
106 , p_delete_mark IN NUMBER DEFAULT NULL
107 , p_from_last_update_date IN DATE DEFAULT NULL
108 , p_to_last_update_date IN DATE DEFAULT NULL
109 , x_test_methods_table OUT NOCOPY system.gmd_test_methods_tab_type -- 5284242
110 , x_return_status OUT NOCOPY VARCHAR2
111 , x_msg_count OUT NOCOPY NUMBER
112 , x_msg_data OUT NOCOPY VARCHAR2
113 )
114 IS
115 sql_statement VARCHAR2(2000);
116 column_list VARCHAR2(2000);
117 table_list VARCHAR2(2000);
118 where_clause VARCHAR2(2000);
119 into_clause VARCHAR2(2000);
120 using_clause VARCHAR2(2000);
121 execution_string VARCHAR2(5000);
122 row_count NUMBER;
123 i NUMBER;
124 l_api_name VARCHAR2(100) := 'fetch_test_methods';
125 BEGIN
126
127
128 IF NOT FND_API.Compatible_API_CALL
129 (gmd_outbound_apis_pub.api_version, p_api_version, l_api_name,'GMD_OUTBOUND_APIS_PUB')
130 OR NOT initialized_ok(p_user_name)
131 THEN
132 Raise FND_API.G_EXC_UNEXPECTED_ERROR;
133 ELSE
134 gme_debug.put_line('Starting FETCH_TESTS');
135
136 /* Initialize message list if p_int_msg_list is set TRUE. */
137
138 IF FND_API.to_boolean(p_init_msg_list)
139 THEN
140 FND_MSG_PUB.Initialize;
141 END IF;
142
143 -- Start construction the select.
144
145 gme_debug.put_line('Constructing select statement');
146
147 sql_statement := 'SELECT ';
148
149 column_list := 'system.gmd_test_method_rec_type( gtm.test_method_id, gtm.test_method_code, ' -- 5284242
150 ||'gtm.test_method_desc, gtm.test_qty, gtm.test_qty_uom, gtm.delete_mark, '
151 ||'gtm.display_precision, gtm.test_duration, gtm.days, gtm.hours, '
152 ||'gtm.minutes, gtm.seconds, gtm.test_replicate, gtm.resources, '
153 ||'gtm.test_kit_organization_id, NULL, ' --INVCONV
154 ||'gtm.test_kit_inv_item_id, NULL, gtm.text_code, gtm.attribute1, '
155 ||'gtm.attribute2, gtm.attribute3, gtm.attribute4, gtm.attribute5, '
156 ||'gtm.attribute6, gtm.attribute7, gtm.attribute8, gtm.attribute9, '
157 ||'gtm.attribute10, gtm.attribute11, gtm.attribute12, gtm.attribute13, '
158 ||'gtm.attribute14, gtm.attribute15, gtm.attribute16, gtm.attribute17, '
159 ||'gtm.attribute18, gtm.attribute19, gtm.attribute20, gtm.attribute21, '
160 ||'gtm.attribute22, gtm.attribute23, gtm.attribute24, gtm.attribute25, '
161 ||'gtm.attribute26, gtm.attribute27, gtm.attribute28, gtm.attribute29, '
162 ||'gtm.attribute30, gtm.attribute_category, gtm.creation_date, '
163 ||'gtm.created_by, fu1.user_name, gtm.last_updated_by, fu2.user_name, '
164 ||'gtm.last_update_date, gtm.last_update_login) ';
165
166 table_list :='FROM gmd_test_methods gtm, fnd_user fu1, fnd_user fu2 ';
167
168
169 -- We now have the first three strings built. Here comes the good bit: building the where and using
170 -- clauses and inserting the bind variables and values.
171
172
173 -- Bug 3133163; Default test method was not retrieved, Added wildcard (+)
174 -- since the default test methods's user_id is not in FND_USERS
175 -- table.
176 where_clause := 'WHERE fu1.user_id (+) = gtm.created_by '||
177 ' AND fu2.user_id (+) = gtm.last_updated_by '||
178 'AND 1=:dummy ';
179 using_clause := 'USING 1 ';
180
181 -- Work down the parameter list and append conditions, bind variables and bind values.
182
183 IF p_from_test_method_code IS NOT NULL
184 THEN
185 gmd_outbound_apis_pub.g_from_test_method_code := p_from_test_method_code;
186 where_clause := where_clause||'AND gtm.test_method_code >= :from_test_method_code ';
187 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_test_method_code ';
188 END IF;
189
190 IF p_to_test_method_code IS NOT NULL
191 THEN
192 gmd_outbound_apis_pub.g_to_test_method_code := p_to_test_method_code;
193 where_clause := where_clause||'AND gtm.test_method_code <= :to_test_method_code ';
194 using_clause := using_clause||', gmd_outbound_apis_pub.g_to_test_method_code ';
195 END IF;
196
197 IF p_test_method_id IS NOT NULL
198 THEN
199 gmd_outbound_apis_pub.g_test_method_id := p_test_method_id;
200 where_clause := where_clause||'AND gtm.test_method_id = :test_method_id ';
201 using_clause := using_clause||', gmd_outbound_apis_pub.g_test_method_id ';
202 END IF;
203
204 IF p_test_kit_organization_id IS NOT NULL --INVCONV
205 THEN
206 gmd_outbound_apis_pub.g_test_kit_organization_id := p_test_kit_organization_id;
207 where_clause := where_clause||'AND gtm.test_kit_organization_id = :test_kit_organization_id ';
208 using_clause := using_clause||', gmd_outbound_apis_pub.g_test_kit_organization_id ';
209 END IF;
210
211 IF p_test_kit_inv_item_id IS NOT NULL --INVCONV
212 THEN
213 gmd_outbound_apis_pub.g_test_kit_inv_item_id := p_test_kit_inv_item_id;
214 where_clause := where_clause||'AND gtm.test_kit_item_id = :test_kit_inv_item_id ';
215 using_clause := using_clause||', gmd_outbound_apis_pub.g_test_kit_inv_item_id ';
216 END IF;
217
218 IF p_resource IS NOT NULL
219 THEN
220 gmd_outbound_apis_pub.g_resource := p_resource;
221 where_clause := where_clause||'AND gtm.resources = :resources ';
222 using_clause := using_clause||', gmd_outbound_apis_pub.g_resource ';
223 END IF;
224
225 IF p_delete_mark IS NOT NULL
226 THEN
227 gmd_outbound_apis_pub.g_delete_mark := p_delete_mark;
228 where_clause := where_clause||'AND gtm.delete_mark = :delete_mark ';
229 using_clause := using_clause||', gmd_outbound_apis_pub.g_delete_mark';
230 END IF;
231
232 IF p_from_last_update_date IS NOT NULL
233 THEN
234 gmd_outbound_apis_pub.g_from_last_update_date := p_from_last_update_date;
235 where_clause := where_clause||'AND gtm.last_update_date >= :from_last_update_date ';
236 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_last_update_date ';
237 END IF;
238
239 IF p_to_last_update_date IS NOT NULL
240 THEN
241 gmd_outbound_apis_pub.g_to_last_update_date := p_to_last_update_date;
242 where_clause := where_clause||'AND gtm.last_update_date <= :to_last_update_date';
243 using_clause := using_clause||', gmd_outbound_apis_pub.g_to_last_update_date';
244 END IF;
245
246 -- That's more or less the job done. We just need to tell the system where to store the data
247
248 into_clause := ' BULK COLLECT INTO gmd_outbound_apis_pub.g_test_methods_table ';
249
250 execution_string := 'BEGIN EXECUTE IMMEDIATE '
251 ||''''
252 ||sql_statement||column_list||table_list||where_clause
253 ||''''
254 ||into_clause
255 ||using_clause
256 ||'; END;';
257
258 /*gme_debug.put_line('The sql statement is:');
259 i:= 1;
260 LOOP
261 gme_debug.put_line(substr(execution_string, i, 100));
262 EXIT WHEN i> LENGTH(execution_string);
263 i := i+100;
264 END LOOP;
265 gme_debug.put_line('Executing string'); */
266
267 EXECUTE IMMEDIATE execution_string;
268
269 -- Main retrieval done, now just fill in any blanks
270
271 IF g_test_methods_table.count > 0
272 THEN
273 FOR i in 1.. g_test_methods_table.count
274 LOOP
275
276 IF g_test_methods_table(i).test_kit_organization_id IS NOT NULL THEN --INVCONV
277 gme_debug.put_line('Retrieving test kit organization for test kit organization id:'
278 ||to_char(g_test_methods_table(i).test_kit_organization_id));
279 SELECT organization_code INTO g_test_methods_table(i).test_kit_organization_code
280 FROM mtl_parameters
281 WHERE organization_id = g_test_methods_table(i).test_kit_organization_id;
282 END IF;
283
284 IF g_test_methods_table(i).test_kit_inv_item_id IS NOT NULL THEN --INVCONV
285 gme_debug.put_line('Retrieving test kit item for test kit inv item id:'
286 ||to_char(g_test_methods_table(i).test_kit_inv_item_id));
287 SELECT concatenated_segments INTO g_test_methods_table(i).test_kit_item_number
288 FROM mtl_system_items_b_kfv
289 WHERE organization_id = g_test_methods_table(i).test_kit_organization_id
290 AND inventory_item_id = g_test_methods_table(i).test_kit_inv_item_id;
291 END IF;
292
293 END LOOP;
294 END IF;
295
296 --gme_debug.put_line('Returning table to caller');
297 x_test_methods_table := gmd_outbound_apis_pub.g_test_methods_table;
298 x_return_status := FND_API.G_RET_STS_SUCCESS;
299
300 END IF;
301
302 FND_MSG_PUB.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
303 gme_debug.put_line('Finished');
304 EXCEPTION
305 WHEN OTHERS
306 THEN
307 gme_debug.put_line('EXCEPTION : '||substr(SQLERRM,1,100));
308 gmd_api_pub.log_message('GMD_API_ERROR','Fetch_Test_Methods', 'Exception',substr(SQLERRM,1,100));
309 FND_MSG_PUB.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
310 x_return_status := FND_API.G_RET_STS_ERROR;
311
312 END fetch_test_methods;
313
314
315 PROCEDURE fetch_tests
316 ( p_api_version IN NUMBER
317 , p_init_msg_list IN VARCHAR2 DEFAULT FND_API.G_FALSE
318 , p_user_name IN VARCHAR2
319 , p_from_test_code IN VARCHAR2 DEFAULT NULL
320 , p_to_test_code IN VARCHAR2 DEFAULT NULL
321 , p_from_test_method_code IN VARCHAR2 DEFAULT NULL
322 , p_to_test_method_code IN VARCHAR2 DEFAULT NULL
323 , p_test_id IN NUMBER DEFAULT NULL
324 , p_test_method_id IN NUMBER DEFAULT NULL
325 , p_test_class IN VARCHAR2 DEFAULT NULL
326 , p_test_type IN VARCHAR2 DEFAULT NULL
327 , p_priority IN VARCHAR2 DEFAULT NULL
328 , p_delete_mark IN NUMBER DEFAULT NULL
329 , p_from_last_update_date IN DATE DEFAULT NULL
330 , p_to_last_update_date IN DATE DEFAULT NULL
331 , x_tests_table OUT NOCOPY system.gmd_qc_tests_tab_type
332 , x_return_status OUT NOCOPY VARCHAR2
333 , x_msg_count OUT NOCOPY NUMBER
334 , x_msg_data OUT NOCOPY VARCHAR2
335 )
336 IS
337 CURSOR test_values_cursor (p_test_id NUMBER) IS
338 SELECT system.gmd_qc_test_value_rec_type
339 ( gtv.test_value_id, gtv.min_num, gtv.max_num, gtv.display_label_numeric_range, gtv.test_value_desc
340 , gtv.value_char, gtv.text_range_seq, gtv.expression_ref_test_id, gtv.text_code, gtv.attribute_category
341 , gtv.attribute1, gtv.attribute2, gtv.attribute3, gtv.attribute4, gtv.attribute5, gtv.attribute6, gtv.attribute7
342 , gtv.attribute8, gtv.attribute9, gtv.attribute10, gtv.attribute11, gtv.attribute12, gtv.attribute13, gtv.attribute14
343 , gtv.attribute15, gtv.attribute16, gtv.attribute17, gtv.attribute18, gtv.attribute19, gtv.attribute20
344 , gtv.attribute21, gtv.attribute22, gtv.attribute23, gtv.attribute24, gtv.attribute25, gtv.attribute26
345 , gtv.attribute27, gtv.attribute28, gtv.attribute29, gtv.attribute30, gtv.creation_date, gtv.created_by
346 , fu1.user_name, gtv.last_update_date, gtv.last_updated_by, fu2.user_name
347 , gtv.last_update_login
348 )
349 FROM gmd_qc_test_values gtv, fnd_user fu1, fnd_user fu2
350 WHERE gtv.test_id = p_test_id
351 AND fu1.user_id = gtv.created_by
352 AND fu2.user_id = gtv.last_updated_by;
353
354 CURSOR customers_cursor (p_test_id NUMBER) IS
355 SELECT system.gmd_customer_test_rec_type
356 ( gct.cust_id, ocm.cust_no, gct.report_precision, gct.cust_test_display, gct.text_code
357 , gct.creation_date, gct.created_by, fu1.user_name, gct.last_update_date
358 , gct.last_updated_by, fu2.user_name, gct.last_update_login
359 )
360 FROM gmd_customer_tests gct, op_cust_mst ocm, fnd_user fu1, fnd_user fu2
361 WHERE gct.test_id = p_test_id
362 AND gct.cust_id = ocm.cust_id
363 AND gct.created_by = fu1.user_id
364 AND gct.last_updated_by = fu2.user_id;
365
366 sql_statement VARCHAR2(4000);
367 column_list VARCHAR2(4000);
368 table_list VARCHAR2(4000);
369 where_clause VARCHAR2(4000);
370 into_clause VARCHAR2(4000);
371 using_clause VARCHAR2(4000);
372 execution_string VARCHAR2(9000);
373 row_count NUMBER;
374 i NUMBER;
375 l_api_name VARCHAR2(100) := 'fetch_tests';
376 BEGIN
377
378 IF NOT FND_API.Compatible_API_CALL
379 (gmd_outbound_apis_pub.api_version, p_api_version, l_api_name,'GMD_OUTBOUND_APIS_PUB')
380 OR NOT initialized_ok(p_user_name)
381 THEN
382 Raise FND_API.G_EXC_UNEXPECTED_ERROR;
383 ELSE
384 /* Initialize message list if p_int_msg_list is set TRUE. */
385 IF FND_API.to_boolean(p_init_msg_list)
386 THEN
387 FND_MSG_PUB.Initialize;
388 END IF;
389
390 sql_statement := 'SELECT ';
391
392 column_list := 'system.gmd_qc_test_rec_type('
393 ||' gqt.test_id, gqt.test_code, gqt.test_desc, gqt.test_method_id, gtm.test_method_code'
394 ||', gqt.test_oprn_line_id, gqt.test_provider_code, gqt.test_class, gqt.test_type'
395 ||', gqt.test_unit, gqt.min_value_num, gqt.max_value_num, gqt.exp_error_type, gqt.below_spec_min'
396 ||', gqt.above_spec_min, gqt.below_spec_max, gqt.above_spec_max, gqt.below_min_action_code'
397 ||', gqt.above_min_action_code, gqt.below_max_action_code, gqt.above_max_action_code'
398 ||', gqt.expression, gqt.display_precision, gqt.report_precision, gqt.priority, gqt.test_oprn_id'
399 ||', gqt.delete_mark, gqt.text_code, gqt.attribute_category, gqt.attribute1, gqt.attribute2'
400 ||', gqt.attribute3, gqt.attribute4, gqt.attribute5, gqt.attribute6, gqt.attribute7, gqt.attribute8'
401 ||', gqt.attribute9, gqt.attribute10, gqt.attribute11, gqt.attribute12, gqt.attribute13, gqt.attribute14'
402 ||', gqt.attribute15, gqt.attribute16, gqt.attribute17, gqt.attribute18, gqt.attribute19, gqt.attribute20'
403 ||', gqt.attribute21, gqt.attribute22, gqt.attribute23, gqt.attribute24, gqt.attribute25, gqt.attribute26'
404 ||', gqt.attribute27, gqt.attribute28, gqt.attribute29, gqt.attribute30, gqt.creation_date'
405 ||', gqt.created_by, fu1.user_name, gqt.last_update_date, gqt.last_updated_by'
406 ||', fu2.user_name, gqt.last_update_login'
407 ||', system.gmd_qc_test_values_tab_type (NULL), system.gmd_customer_tests_tab_type(NULL)' -- 5284242
408 ||')';
409
410 table_list := ' FROM gmd_qc_tests gqt, gmd_test_methods gtm, fnd_user fu1, fnd_user fu2';
411
412 where_clause := ' WHERE gqt.test_method_id = gtm.test_method_id'
413 ||' AND fu1.user_id=gqt.created_by'
414 ||' AND fu2.user_id=gqt.last_updated_by'
415 ||' AND 1=:dummy ';
416
417 using_clause := ' USING 1';
418
419 IF p_from_test_method_code IS NOT NULL
420 THEN
421 gmd_outbound_apis_pub.g_from_test_method_code := p_from_test_method_code;
422 where_clause := where_clause ||' AND gtm.test_method_code >= :from_test_method_code';
423 using_clause := using_clause ||', gmd_outbound_apis_pub.g_from_test_method_code';
424 END IF;
425
426 IF p_to_test_method_code IS NOT NULL
427 THEN
428 gmd_outbound_apis_pub.g_to_test_method_code := p_to_test_method_code;
429 where_clause := where_clause ||' AND gtm.test_method_code <= :to_test_method_code';
430 using_clause := using_clause ||', gmd_outbound_apis_pub.g_to_test_method_code';
431 END IF;
432
433 IF p_from_test_code IS NOT NULL
434 THEN
435 gmd_outbound_apis_pub.g_from_test_code := p_from_test_code;
436 where_clause := where_clause||' AND gqt.test_code >= :from_test_code';
437 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_test_code';
438 END IF;
439
440 IF p_to_test_code IS NOT NULL
441 THEN
442 gmd_outbound_apis_pub.g_to_test_code := p_to_test_code;
443 where_clause := where_clause||' AND gqt.test_code <= :to_test_code';
444 using_clause := using_clause||', gmd_outbound_apis_pub.g_to_test_code';
445 END IF;
446
447
448 IF p_test_method_id IS NOT NULL
449 THEN
450 gmd_outbound_apis_pub.g_test_method_id := p_test_method_id;
451 where_clause := where_clause||' AND gqt.test_method_id = :test_method_id';
452 using_clause := using_clause||', gmd_outbound_apis_pub.g_test_method_id';
453 END IF;
454
455
456 IF p_test_id IS NOT NULL
457 THEN
458 gmd_outbound_apis_pub.g_test_id := p_test_id;
459 where_clause := where_clause||' AND gqt.test_id = :test_id';
460 using_clause := using_clause||', gmd_outbound_apis_pub.g_test_id';
461 END IF;
462
463
464 IF p_test_class IS NOT NULL
465 THEN
466 gmd_outbound_apis_pub.g_test_class := p_test_class;
467 where_clause := where_clause||' AND gqt.test_class = :test_class';
468 using_clause := using_clause||', gmd_outbound_apis_pub.g_test_class';
469 END IF;
470
471
472 IF p_test_type IS NOT NULL
473 THEN
474 gmd_outbound_apis_pub.g_test_type := p_test_type;
475 where_clause := where_clause||' AND gqt.test_type = :test_type';
476 using_clause := using_clause||', gmd_outbound_apis_pub.g_test_type';
477 END IF;
478
479
480 IF p_priority IS NOT NULL
481 THEN
482 gmd_outbound_apis_pub.g_priority := p_priority;
483 where_clause := where_clause||' AND gqt.test_type = :priority';
484 using_clause := using_clause||', gmd_outbound_apis_pub.g_priority';
485 END IF;
486
487
488 IF p_delete_mark IS NOT NULL
489 THEN
490 gmd_outbound_apis_pub.g_delete_mark := p_delete_mark;
491 where_clause := where_clause||' AND gqt.delete_mark = :delete_mark';
492 using_clause := using_clause||', gmd_outbound_apis_pub.g_delete_mark';
493 END IF;
494
495
496 IF p_from_last_update_date IS NOT NULL
497 THEN
498 gmd_outbound_apis_pub.g_from_last_update_date := p_from_last_update_date;
499 where_clause := where_clause||' AND gqt.last_update_date >= :from_last_update_date';
500 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_last_update_date';
501 END IF;
502
503 IF p_to_last_update_date IS NOT NULL
504 THEN
505 gmd_outbound_apis_pub.g_to_last_update_date := p_to_last_update_date;
506 where_clause := where_clause||' AND gqt.last_update_date <= :to_last_update_date';
507 using_clause := using_clause||', gmd_outbound_apis_pub.g_to_last_update_date';
508 END IF;
509
510 -- That's more or less the job done. We just need to tell the system where to store the data
511
512 into_clause := ' BULK COLLECT INTO gmd_outbound_apis_pub.g_tests_table ';
513
514 execution_string := 'BEGIN EXECUTE IMMEDIATE '
515 ||''''
516 ||sql_statement||column_list||table_list||where_clause
517 ||''''
518 ||into_clause
519 ||using_clause
520 ||'; END;';
521
522 EXECUTE IMMEDIATE execution_string;
523
524 IF g_tests_table.count <> 0
525 THEN
526 FOR i IN 1..g_tests_table.count
527 LOOP
528 OPEN test_values_cursor(g_tests_table(i).test_id);
529 FETCH test_values_cursor BULK COLLECT INTO g_tests_table(i).test_values;
530 CLOSE test_values_cursor;
531
532 OPEN customers_cursor(g_tests_table(i).test_id);
533 FETCH customers_cursor BULK COLLECT INTO g_tests_table(i).customer_tests;
534 CLOSE customers_cursor;
535 END LOOP;
536 END IF;
537
538 x_tests_table := gmd_outbound_apis_pub.g_tests_table;
539 x_return_status := FND_API.G_RET_STS_SUCCESS;
540 END IF;
541
542 FND_MSG_PUB.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
543
544 EXCEPTION
545 WHEN OTHERS
546 THEN
547 FND_MESSAGE.SET_NAME('GMD',SQLCODE);
548 FND_MSG_PUB.Add;
549 FND_MSG_PUB.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
550 x_return_status := FND_API.G_RET_STS_ERROR;
551
552 END fetch_tests;
553
554
555 PROCEDURE FETCH_SPEC_VRS
556 ( p_api_version IN NUMBER
557 , p_init_msg_list IN VARCHAR2 DEFAULT FND_API.G_FALSE
558 , p_user_name IN VARCHAR2
559
560 -- Parameters relating to specifications
561
562 , p_from_spec_name IN VARCHAR2 DEFAULT NULL
563 , p_to_spec_name IN VARCHAR2 DEFAULT NULL
564 , p_spec_id IN NUMBER DEFAULT NULL
565 , p_spec_version IN NUMBER DEFAULT NULL
566 , p_from_grade_code IN VARCHAR2 DEFAULT NULL
567 , p_to_grade_code IN VARCHAR2 DEFAULT NULL
568 , p_from_item_number IN VARCHAR2 DEFAULT NULL
569 , p_to_item_number IN VARCHAR2 DEFAULT NULL
570 , p_inventory_item_id IN NUMBER DEFAULT NULL
571 , p_from_revision IN VARCHAR2 DEFAULT NULL -- RLNAGARA Bug # 4548546
572 , p_to_revision IN VARCHAR2 DEFAULT NULL -- RLNAGARA Bug # 4548546
573 , p_from_spec_last_update IN DATE DEFAULT NULL
574 , p_to_spec_last_update IN DATE DEFAULT NULL
575 , p_spec_status IN NUMBER DEFAULT NULL
576 , p_owner_organization_code IN VARCHAR2 DEFAULT NULL
577 , p_spec_delete_mark IN NUMBER DEFAULT NULL
578
579 -- START B3124291 Incorporated Mini-Pack K Features to Outboud APIs
580 , p_overlay_ind IN VARCHAR2 DEFAULT NULL
581 , p_spec_type IN VARCHAR2 DEFAULT NULL
582 , p_base_spec_id IN NUMBER DEFAULT NULL
583 , p_base_spec_name IN VARCHAR2 DEFAULT NULL
584 , p_base_spec_version IN NUMBER DEFAULT NULL
585 -- END B3124291 Incorporated Mini-Pack K Features to Outboud APIs
586
587 -- Parameters relating to spec tests
588
589 , p_test_code IN VARCHAR2 DEFAULT NULL
590 , p_test_id IN NUMBER DEFAULT NULL
591 , p_test_method_code IN VARCHAR2 DEFAULT NULL
592 , p_test_method_id IN NUMBER DEFAULT NULL
593 , p_test_qty_uom IN VARCHAR2 DEFAULT NULL
594 , p_test_priority IN VARCHAR2 DEFAULT NULL
595 , p_from_test_last_update IN DATE DEFAULT NULL
596 , p_to_test_last_update IN DATE DEFAULT NULL
597 , p_test_delete_mark IN NUMBER DEFAULT NULL
598 -- START B3124291 Incorporated Mini-Pack K Features to Outboud APIs
599 , p_from_base_ind IN VARCHAR2 DEFAULT NULL
600 , p_exclude_ind IN VARCHAR2 DEFAULT NULL
601 , p_modified_ind IN VARCHAR2 DEFAULT NULL
602 , p_calc_uom_conv_ind IN VARCHAR2 DEFAULT NULL
603 , p_to_qty_uom IN VARCHAR2 DEFAULT NULL
604 -- END B3124291 Incorporated Mini-Pack K Features to Outboud APIs
605
606 -- Parameters relating to wip spec validity rules
607
608 , p_wip_vr_status IN NUMBER DEFAULT NULL
609 , p_wip_vr_organization_code IN VARCHAR2 DEFAULT NULL
610 , p_wip_vr_batch_orgn_code IN VARCHAR2 DEFAULT NULL
611 , p_wip_vr_batch_no IN VARCHAR2 DEFAULT NULL
612 , p_wip_vr_batch_id IN NUMBER DEFAULT NULL
613 , p_wip_vr_recipe_no IN VARCHAR2 DEFAULT NULL
614 , p_wip_vr_recipe_version IN NUMBER DEFAULT NULL
615 , p_wip_vr_recipe_id IN NUMBER DEFAULT NULL
616 , p_wip_vr_formula_no IN VARCHAR2 DEFAULT NULL
617 , p_wip_vr_formula_version IN NUMBER DEFAULT NULL
618 , p_wip_vr_formula_id IN NUMBER DEFAULT NULL
619 , p_wip_vr_formulaline_no IN NUMBER DEFAULT NULL
620 , p_wip_vr_formulaline_id IN NUMBER DEFAULT NULL
621 , p_wip_vr_line_type IN NUMBER DEFAULT NULL
622 , p_wip_vr_routing_no IN VARCHAR2 DEFAULT NULL
623 , p_wip_vr_routing_version IN NUMBER DEFAULT NULL
624 , p_wip_vr_routing_id IN NUMBER DEFAULT NULL
625 , p_wip_vr_step_no IN NUMBER DEFAULT NULL
626 , p_wip_vr_step_id IN NUMBER DEFAULT NULL
627 , p_wip_vr_operation_no IN VARCHAR2 DEFAULT NULL
628 , p_wip_vr_operation_version IN NUMBER DEFAULT NULL
629 , p_wip_vr_operation_id IN NUMBER DEFAULT NULL
630 , p_wip_vr_start_date IN DATE DEFAULT NULL
631 , p_wip_vr_end_date IN DATE DEFAULT NULL
632 , p_wip_vr_coa_type IN VARCHAR2 DEFAULT NULL
633 , p_wip_vr_sampling_plan IN VARCHAR2 DEFAULT NULL
634 , p_wip_vr_sampling_plan_id IN NUMBER DEFAULT NULL
635 , p_wip_vr_delete_mark IN NUMBER DEFAULT NULL
636 , p_wip_vr_from_last_update IN DATE DEFAULT NULL
637 , p_wip_vr_to_last_update IN DATE DEFAULT NULL
638
639 -- Parameters relating to customer spec validity rules
640 , p_cust_vr_start_date IN DATE DEFAULT NULL
641 , p_cust_vr_end_date IN DATE DEFAULT NULL
642 , p_cust_vr_status IN NUMBER DEFAULT NULL
643 , p_cust_vr_organization_code IN VARCHAR2 DEFAULT NULL
644 , p_cust_vr_org_id IN NUMBER DEFAULT NULL
645 , p_cust_vr_coa_type IN VARCHAR2 DEFAULT NULL
646 , p_cust_vr_customer IN VARCHAR2 DEFAULT NULL
647 , p_cust_vr_customer_id IN NUMBER DEFAULT NULL
648 , p_cust_vr_order_number IN NUMBER DEFAULT NULL
649 , p_cust_vr_order_id IN NUMBER DEFAULT NULL
650 , p_cust_vr_order_type IN NUMBER DEFAULT NULL
651 , p_cust_vr_order_line_no IN NUMBER DEFAULT NULL
652 , p_cust_vr_order_line_id IN NUMBER DEFAULT NULL
653 , p_cust_vr_ship_to_location IN VARCHAR2 DEFAULT NULL
654 , p_cust_vr_ship_to_site_id IN NUMBER DEFAULT NULL
655 , p_cust_vr_operating_unit IN VARCHAR
656 , p_cust_vr_delete_mark IN NUMBER DEFAULT NULL
657 , p_cust_vr_from_last_update IN DATE DEFAULT NULL
658 , p_cust_vr_to_last_update IN DATE DEFAULT NULL
659
660 -- Parameters relating to supplier spec validity rules
661 , p_supl_vr_start_date IN DATE DEFAULT NULL
662 , p_supl_vr_end_date IN DATE DEFAULT NULL
663 , p_supl_vr_status IN NUMBER DEFAULT NULL
664 , p_supl_vr_organization_code IN VARCHAR2 DEFAULT NULL
665 , p_supl_vr_org_id IN NUMBER DEFAULT NULL
666 , p_supl_vr_coa_type IN VARCHAR2 DEFAULT NULL
667 , p_supl_vr_supplier IN VARCHAR2 DEFAULT NULL
668 , p_supl_vr_supplier_id IN NUMBER DEFAULT NULL
669 , p_supl_vr_po_number IN NUMBER DEFAULT NULL
670 , p_supl_vr_po_id IN NUMBER DEFAULT NULL
671 , p_supl_vr_po_line_no IN NUMBER DEFAULT NULL
672 , p_supl_vr_po_line_id IN NUMBER DEFAULT NULL
673 , p_supl_vr_supplier_site IN VARCHAR2 DEFAULT NULL
674 , p_supl_vr_supplier_site_id IN NUMBER DEFAULT NULL
675 , p_supl_vr_operating_unit IN VARCHAR2 DEFAULT NULL
676 , p_supl_vr_delete_mark IN NUMBER DEFAULT NULL
677 , p_supl_vr_from_last_update IN DATE DEFAULT NULL
678 , p_supl_vr_to_last_update IN DATE DEFAULT NULL
679
680 -- Parameters relating to inventory spec validity rules
681 , p_inv_vr_start_date IN DATE DEFAULT NULL
682 , p_inv_vr_end_date IN DATE DEFAULT NULL
683 , p_inv_vr_status IN NUMBER DEFAULT NULL
684 , p_inv_vr_organization_code IN VARCHAR2 DEFAULT NULL
685 , p_inv_vr_coa_type IN VARCHAR2 DEFAULT NULL
686 , p_inv_vr_item_number IN VARCHAR2 DEFAULT NULL
687 , p_inv_vr_inventory_item_id IN NUMBER DEFAULT NULL
688 , p_inv_vr_parent_lot_number IN VARCHAR2 DEFAULT NULL
689 , p_inv_vr_lot_number IN VARCHAR2 DEFAULT NULL
690 , p_inv_vr_subinventory IN VARCHAR2 DEFAULT NULL
691 , p_inv_vr_locator IN VARCHAR2 DEFAULT NULL
692 , p_inv_vr_locator_id IN NUMBER DEFAULT NULL
693 , p_inv_vr_sampling_plan IN VARCHAR2 DEFAULT NULL
694 , p_inv_vr_sampling_plan_id IN NUMBER DEFAULT NULL
695 , p_inv_vr_delete_mark IN NUMBER DEFAULT NULL
696 , p_inv_vr_from_last_update IN DATE DEFAULT NULL
697 , p_inv_vr_to_last_update IN DATE DEFAULT NULL
698
699 -- START B3124291 Incorporated Mini-Pack K Features to Outboud APIs
700 -- Parameters relating to monitor spec
701 , p_mon_vr_status IN NUMBER DEFAULT NULL
702 , p_mon_vr_rule_type IN VARCHAR2 DEFAULT NULL
703 , p_mon_vr_lct_organization_code IN VARCHAR2 DEFAULT NULL
704 , p_mon_vr_subinventory IN VARCHAR2 DEFAULT NULL
705 , p_mon_vr_locator_id IN NUMBER DEFAULT NULL
706 , p_mon_vr_locator IN VARCHAR2 DEFAULT NULL
707 , p_mon_vr_rsr_organization_code IN VARCHAR2 DEFAULT NULL
708 , p_mon_vr_resources IN VARCHAR2 DEFAULT NULL
709 , p_mon_vr_resource_instance_id IN NUMBER DEFAULT NULL
710 , p_mon_vr_sampling_plan IN VARCHAR2 DEFAULT NULL
711 , p_mon_vr_sampling_plan_id IN NUMBER DEFAULT NULL
712 , p_mon_vr_start_date IN DATE DEFAULT NULL
713 , p_mon_vr_end_date IN DATE DEFAULT NULL
714 , p_mon_vr_from_last_update_date IN DATE DEFAULT NULL
715 , p_mon_vr_to_last_update_date IN DATE DEFAULT NULL
716 , p_mon_vr_delete_mark IN NUMBER DEFAULT NULL
717 -- END B3124291 Incorporated Mini-Pack K Features to Outboud APIs
718
719 -- Return parameters
720
721 , x_specifications_tbl OUT NOCOPY system.gmd_specifications_tab_type
722 , x_return_status OUT NOCOPY VARCHAR2
723 , x_msg_count OUT NOCOPY NUMBER
724 , x_msg_data OUT NOCOPY VARCHAR2
725 )
726 IS
727 sql_statement VARCHAR2(32000);
728
729 main_column_list VARCHAR2(10000);
730 spec_test_column_list VARCHAR2(10000);
731 cust_vr_column_list VARCHAR2(10000);
732 inv_vr_column_list VARCHAR2(10000);
733 supl_vr_column_list VARCHAR2(10000);
734 wip_vr_column_list VARCHAR2(10000);
735 mon_vr_column_list VARCHAR2(10000);
736
737 main_table_list VARCHAR2(10000);
738 spec_test_table_list VARCHAR2(10000);
739 cust_vr_table_list VARCHAR2(10000);
740 inv_vr_table_list VARCHAR2(10000);
741 supl_vr_table_list VARCHAR2(10000);
742 wip_vr_table_list VARCHAR2(10000);
743 mon_vr_table_list VARCHAR2(10000);
744
745 main_where_clause VARCHAR2(20000);
746 spec_test_where_clause VARCHAR2(10000);
747 cust_vr_where_clause VARCHAR2(10000);
748 inv_vr_where_clause VARCHAR2(10000);
749 supl_vr_where_clause VARCHAR2(10000);
750 wip_vr_where_clause VARCHAR2(10000);
751 mon_vr_where_clause VARCHAR2(10000);
752
753 main_using_clause VARCHAR2(10000);
754 spec_test_using_clause VARCHAR2(10000);
755 wip_vr_using_clause VARCHAR2(10000);
756 inv_vr_using_clause VARCHAR2(10000);
757 supl_vr_using_clause VARCHAR2(10000);
758 cust_vr_using_clause VARCHAR2(10000);
759 mon_vr_using_clause VARCHAR2(10000);
760
761 main_into_clause VARCHAR2(10000);
762 main_execution_string VARCHAR2(30000);
763
764 row_count NUMBER;
765 i NUMBER;
766 j NUMBER;
767 l_api_name VARCHAR2(100) := 'fetch_spec_vrs';
768
769 BEGIN
770
771
772 IF NOT FND_API.Compatible_API_CALL
773 (gmd_outbound_apis_pub.api_version, p_api_version, l_api_name,'GMD_OUTBOUND_APIS_PUB')
774 OR NOT initialized_ok(p_user_name)
775 THEN
776
777 Raise FND_API.G_EXC_UNEXPECTED_ERROR;
778 ELSE
779
780 /* Initialize message list if p_int_msg_list is set TRUE. */
781 IF FND_API.to_boolean(p_init_msg_list)
782 THEN
783 FND_MSG_PUB.Initialize;
784 END IF;
785
786 -- Build the query to retrieve all base rows from gmd_specifications together with
787 -- linked nested rowsets from all of the other tables..
788 --
789 -- The code looks worse than it is. All the next few sections do is build SQL
790 -- clauses that are then glued together and executed dynamically with binds,
791 -- depending on what has been specified in the parameters.
792 --
793 -- By doing one large BULK COLLECT using the constructed statement, almost everything
794 -- is retrieved in a single hit, including all of the nested data. All that we need to
795 -- do afterwards is fill in the gaps where a direct retrieval is not possible due to
796 -- nullable columns where we cannot make outer joins.
797 --
798 -- The end result will resemble:
799
800 /* SELECT gmd_specifications_rec_type
801 ( <gmd_specification table columns>
802 , CAST
803 ( MULTISET
804 ( gmd_spec_test_rec_type
805 ( SELECT <gmd_spec_tests table columns>
806 FROM <gmd_spec_tests table set>
807 WHERE <gmd_spec_tests conditions with bind variables> ***
808 AS system.gmd_spec_tests_tab_type
809 )
810 , CAST
811 ( MULTISET
812 ( gmd_cust_spec_vrs_rec_type
813 ( SELECT <gmd_cust_spec_vrs table columns>
814 FROM <gmd_cust_spec_crs table set>
815 WHERE <gmd_cust_spec_vrs conditions with bind variables> ***
816 AS system.gmd_cust_spec_vrs_tab_type
817 )
818 , CAST
819 ( MULTISET
820 ( gmd_wip_spec_vrs_rec_type
821 ( SELECT <gmd_wip_spec_vrs table columns>
822 FROM <gmd_wip_spec_crs table set>
823 WHERE <gmd_wip_spec_vrs conditions with bind variables> ***
824 AS system.gmd_wip_spec_vrs_tab_type
825 )
826 , CAST
827 ( MULTISET
828 ( gmd_supl_spec_vrs_rec_type
829 ( SELECT <gmd_supl_spec_vrs table columns>
830 FROM <gmd_supl_spec_crs table set>
831 WHERE <gmd_supl_spec_vrs conditions with bind variables> ***
832 AS system.gmd_supl_spec_vrs_tab_type
833 )
834 , CAST
835 ( MULTISET
836 ( gmd_inv_spec_vrs_rec_type
837 ( SELECT <gmd_inv_spec_vrs table columns>
838 FROM <gmd_inv_spec_crs table set>
839 WHERE <gmd_inv_spec_vrs conditions with bind variables> ***
840 AS system.gmd_inv_spec_vrs_tab_type
841 )
842 )
843 FROM
844 <main table list>
845 WHERE
846 <specification constraining conditions with binds> ****
847 */
848
849 -- The lines marked *** are the slightly complicated ones to construct as the conditions
850 -- have to have the appropriate bind variables embedded.
851
852 -- The whole statement is then put into an EXECUTE IMMEDIATE statement to pass it
853 -- to the database. Here goes......
854
855
856 -- GMD_SPECIFICATIONS basic clauses
857
858 main_column_list := ' gs.spec_id, gs.spec_name, gs.spec_vers, gs.spec_desc'
859 ||', gs.inventory_item_id, NULL, gs.grade_code, gs.revision, gs.spec_status, gstat.description'
860 ||', gs.owner_organization_id, gs.owner_id, fu3.user_name'
861 ||', gs.sample_inv_trans_ind'
862 -- START B3124291 Incorporated Mini-Pack K Features to Outboud APIs
863 ||', gs.overlay_ind, gs.spec_type, gs.base_spec_id'
864 -- END B3124291 Incorporated Mini-Pack K Features to Outboud APIs
865 ||', gs.delete_mark, gs.text_code'
866 ||', gs.attribute_category, gs.attribute1, gs.attribute2, gs.attribute3'
867 ||', gs.attribute4, gs.attribute5, gs.attribute6, gs.attribute7'
868 ||', gs.attribute8, gs.attribute9, gs.attribute10, gs.attribute11'
869 ||', gs.attribute12, gs.attribute13, gs.attribute14, gs.attribute15'
870 ||', gs.attribute16, gs.attribute17, gs.attribute18, gs.attribute19'
871 ||', gs.attribute20, gs.attribute21, gs.attribute22, gs.attribute23'
872 ||', gs.attribute24, gs.attribute25, gs.attribute26, gs.attribute27'
873 ||', gs.attribute28, gs.attribute29, gs.attribute30, gs.creation_date'
874 ||', gs.created_by, fu1.user_name, gs.last_update_date'
875 ||', gs.last_updated_by, fu2.user_name, gs.last_update_login';
876
877 main_table_list := ' gmd_specifications gs, fnd_user fu1, fnd_user fu2, fnd_user fu3, gmd_status gstat';
878
879 main_where_clause := ' gs.created_by = fu1.user_id'
880 ||' AND gs.last_updated_by = fu2.user_id'
881 ||' AND gs.owner_id = fu3.user_id'
882 ||' AND to_char(gs.spec_status) = gstat.status_code'
883 ||' AND 1=:dummy1 ';
884
885 main_using_clause := '1';
886
887 -- GMD_SPEC_TESTS basic clauses
888
889 spec_test_column_list := ' system.gmd_spec_test_rec_type' -- 5284247
890 ||'( gst.test_id, gqt.test_code, gst.test_method_id, gtm.test_method_code'
891 ||', gst.seq'
892 ||', gst.test_qty, gst.test_qty_uom, gst.min_value_num, gst.target_value_num'
893 ||', gst.max_value_num, gst.min_value_char, gst.target_value_char'
894 ||', gst.max_value_char, gst.test_replicate, gst.check_result_interval'
895 ||', gst.print_on_coa_ind, gst.use_to_control_step, gst.out_of_spec_action'
896 ||', gst.exp_error_type, gst.below_spec_min, gst.above_spec_min, gst.below_spec_max'
897 ||', gst.above_spec_max, gst.below_min_action_code, gst.above_min_action_code'
898 ||', gst.optional_ind, gst.display_precision, gst.report_precision'
899 ||', gst.test_priority, gst.retest_lot_expiry_ind, gst.print_spec_ind'
900 ||', gst.print_result_ind, gst.below_max_action_code, gst.above_max_action_code'
901 ||', gst.test_display'
902 -- START B3124291 Incorporated Mini-Pack K Features to Outboud APIs
903 ||', gst.days, gst.hours, gst.minutes, gst.seconds, gst.from_base_ind'
904 ||', gst.exclude_ind, gst.modified_ind, gst.calc_uom_conv_ind, gst.to_qty_uom'
905 -- END B3124291 Incorporated Mini-Pack K Features to Outboud APIs
906 ||', gst.text_code'
907 ||', gst.attribute_category, gst.attribute1, gst.attribute2, gst.attribute3'
908 ||', gst.attribute4, gst.attribute5, gst.attribute6, gst.attribute7'
909 ||', gst.attribute8, gst.attribute9, gst.attribute10, gst.attribute11'
910 ||', gst.attribute12, gst.attribute13, gst.attribute14, gst.attribute15'
911 ||', gst.attribute16, gst.attribute17, gst.attribute18, gst.attribute19'
912 ||', gst.attribute20, gst.attribute21, gst.attribute22, gst.attribute23'
913 ||', gst.attribute24, gst.attribute25, gst.attribute26, gst.attribute27'
914 ||', gst.attribute28, gst.attribute29, gst.attribute30, gst.creation_date'
915 ||', gst.created_by, fu4.user_name, gst.last_update_date'
916 ||', gst.last_updated_by, fu5.user_name, gst.last_update_login'
917 ||')';
918
919 spec_test_table_list := ' gmd_spec_tests gst, fnd_user fu4, fnd_user fu5, gmd_test_methods gtm, gmd_qc_tests gqt';
920
921 spec_test_where_clause := ' gst.created_by = fu4.user_id AND gst.last_updated_by=fu5.user_id '
922 ||' AND gst.test_id = gqt.test_id AND gst.test_method_id=gtm.test_method_id'
923 ||' AND gst.spec_id = gs.spec_id AND 1=:dummy2 ';
924
925 spec_test_using_clause := '1';
926
927 -- GMD_CUSTOMER_SPEC_VRS basic clauses
928
929 cust_vr_column_list := ' system.gmd_cust_spec_vr_rec_type' -- 5284247
930 ||'( cvr.spec_vr_id, cvr.organization_id, cvr.cust_id, NULL, cvr.order_id, NULL'
931 ||', cvr.order_line, cvr.order_line_id, cvr.ship_to_site_id, NULL, cvr.org_id'
932 ||', NULL, cvr.spec_vr_status, NULL, cvr.start_date, cvr.end_date, cvr.sampling_plan_id'
933 ||', NULL, cvr.sample_inv_trans_ind, cvr.lot_optional_on_sample, cvr.coa_type'
934 ||', cvr.coa_at_ship_ind, cvr.coa_at_invoice_ind, cvr.coa_req_from_supl_ind'
935 ||', cvr.delete_mark, cvr.text_code, cvr.attribute_category'
936 ||', cvr.attribute1, cvr.attribute2, cvr.attribute3, cvr.attribute4, cvr.attribute5'
937 ||', cvr.attribute6, cvr.attribute7, cvr.attribute8, cvr.attribute9, cvr.attribute10'
938 ||', cvr.attribute11, cvr.attribute12, cvr.attribute13, cvr.attribute14, cvr.attribute15'
939 ||', cvr.attribute16, cvr.attribute17, cvr.attribute18, cvr.attribute19, cvr.attribute20'
940 ||', cvr.attribute21, cvr.attribute22, cvr.attribute23, cvr.attribute24, cvr.attribute25'
941 ||', cvr.attribute26, cvr.attribute27, cvr.attribute28, cvr.attribute29, cvr.attribute30'
942 ||', cvr.creation_date, cvr.created_by, fu6.user_name, cvr.last_update_date'
943 ||', cvr.last_updated_by, fu7.user_name, cvr.last_update_login'
944 ||')';
945 cust_vr_table_list := ' gmd_customer_spec_vrs cvr, fnd_user fu6, fnd_user fu7, oe_order_headers_all oeh';
946
947 cust_vr_where_clause := ' cvr.created_by = fu6.user_id AND cvr.last_updated_by = fu7.user_id'
948 ||' AND cvr.spec_id = gs.spec_id AND cvr.order_id = oeh.header_id(+) AND 1=:dummy3';
949
950 cust_vr_using_clause := '1';
951
952 -- GMD_WIP_SPEC_VRS basic clauses
953 -- Bug 3704090; Added fields delayed_lot_entry and auto_sample_ind
954
955 wip_vr_column_list := ' system.gmd_wip_spec_vr_rec_type' --5284247
956 ||'( wvr.spec_vr_id, wvr.organization_id, wvr.batch_id, gbh.batch_no, wvr.recipe_id, wvr.recipe_no'
957 ||', wvr.recipe_version, wvr.formula_id, wvr.formula_no, wvr.formula_vers, wvr.routing_id'
958 ||', wvr.routing_no, wvr.routing_vers, wvr.step_id, wvr.step_no, wvr.oprn_id, wvr.oprn_no'
959 ||', wvr.oprn_vers, wvr.charge, wvr.spec_vr_status, NULL, wvr.start_date, wvr.end_date'
960 ||', wvr.sampling_plan_id, NULL, wvr.sample_inv_trans_ind, wvr.lot_optional_on_sample'
961 ||', wvr.delayed_lot_entry, wvr.auto_sample_ind'
962 ||', wvr.control_lot_attrib_ind, wvr.out_of_spec_lot_status_id, wvr.in_spec_lot_status_id'
963 ||', wvr.coa_type, wvr.control_batch_step_ind, wvr.coa_at_ship_ind, wvr.coa_at_invoice_ind'
964 ||', wvr.coa_req_from_supl_ind, wvr.delete_mark, wvr.text_code, wvr.attribute_category'
965 ||', wvr.attribute1, wvr.attribute2, wvr.attribute3, wvr.attribute4, wvr.attribute5'
966 ||', wvr.attribute6, wvr.attribute7, wvr.attribute8, wvr.attribute9, wvr.attribute10'
967 ||', wvr.attribute11, wvr.attribute12, wvr.attribute13, wvr.attribute14, wvr.attribute15'
968 ||', wvr.attribute16, wvr.attribute17, wvr.attribute18, wvr.attribute19, wvr.attribute20'
969 ||', wvr.attribute21, wvr.attribute22, wvr.attribute23, wvr.attribute24, wvr.attribute25'
970 ||', wvr.attribute26, wvr.attribute27, wvr.attribute28, wvr.attribute29, wvr.attribute30'
971 ||', wvr.creation_date, wvr.created_by, fu8.user_name, wvr.last_update_date'
972 ||', wvr.last_updated_by, fu9.user_name, wvr.last_update_login'
973 ||')';
974
975 wip_vr_table_list := ' gmd_wip_spec_vrs wvr, fnd_user fu8, fnd_user fu9, gme_batch_header gbh';
976
977 wip_vr_where_clause := ' wvr.created_by = fu8.user_id AND wvr.last_updated_by = fu9.user_id'
978 ||' AND wvr.batch_id= gbh.batch_id(+) and gbh.batch_type(+) = 0'
979 ||' AND wvr.spec_id = gs.spec_id and 1=:dummy4';
980
981 wip_vr_using_clause := '1';
982
983 -- GMD_SUPPLIER_SPEC_VRS basic clauses
984 -- Bug 3704090; Added fields delayed_lot_entry and auto_sample_ind
985
986 supl_vr_column_list := ' system.gmd_supl_spec_vr_rec_type' -- 5284247
987 ||'( svr.po_header_id, NULL, svr.spec_vr_id, svr.organization_id, svr.supplier_id'
988 ||', v.segment1, svr.supplier_site_id, NULL, svr.org_id, svr.po_line_id'
989 ||', NULL, svr.spec_vr_status, NULL, svr.start_date, svr.end_date'
990 ||', svr.sampling_plan_id, NULL, svr.sample_inv_trans_ind, svr.lot_optional_on_sample'
991 ||', svr.delayed_lot_entry, svr.auto_sample_ind'
992 ||', svr.coa_type, svr.coa_at_ship_ind, svr.coa_at_invoice_ind, svr.coa_req_from_supl_ind'
993 ||', svr.out_of_spec_lot_status_id, svr.in_spec_lot_status_id'
994 ||', svr.delete_mark, svr.text_code, svr.attribute_category, svr.attribute1'
995 ||', svr.attribute2, svr.attribute3, svr.attribute4, svr.attribute5, svr.attribute6'
996 ||', svr.attribute7, svr.attribute8, svr.attribute9, svr.attribute10, svr.attribute11'
997 ||', svr.attribute12, svr.attribute13, svr.attribute14, svr.attribute15, svr.attribute16'
998 ||', svr.attribute17, svr.attribute18, svr.attribute19, svr.attribute20, svr.attribute21'
999 ||', svr.attribute22, svr.attribute23, svr.attribute24, svr.attribute25, svr.attribute26'
1000 ||', svr.attribute27, svr.attribute28, svr.attribute29, svr.attribute30, svr.creation_date'
1001 ||', svr.created_by, fu10.user_name, svr.last_update_date, svr.last_updated_by'
1002 ||', fu11.user_name, svr.last_update_login'
1003 ||')';
1004
1005 supl_vr_table_list := ' gmd_supplier_spec_vrs svr, fnd_user fu10, fnd_user fu11, po_vendors v';
1006
1007 supl_vr_where_clause := ' svr.created_by = fu10.user_id AND svr.last_updated_by = fu11.user_id'
1008 ||' AND svr.spec_id = gs.spec_id AND v.vendor_id = svr.supplier_id AND 1=:dummy5';
1009 supl_vr_using_clause := '1';
1010
1011 -- GMD_INVENTORY_SPEC_VRS basic clauses
1012 -- Bug 3704090; Added fields delayed_lot_entry and auto_sample_ind
1013
1014 inv_vr_column_list := ' system.gmd_inv_spec_vr_rec_type' -- 5284247
1015 ||'( ivr.spec_vr_id, ivr.organization_id, ivr.parent_lot_number, ivr.lot_number'
1016 ||', ivr.subinventory, ivr.locator_id, ivr.spec_vr_status, NULL, ivr.start_date'
1017 ||', ivr.end_date, ivr.sampling_plan_id, NULL, ivr.sample_inv_trans_ind'
1018 ||', ivr.control_lot_attrib_ind, ivr.lot_optional_on_sample'
1019 ||', ivr.delayed_lot_entry, ivr.auto_sample_ind'
1020 ||', ivr.in_spec_lot_status_id'
1021 ||', ivr.out_of_spec_lot_status_id, ivr.control_batch_step_ind, ivr.coa_type'
1022 ||', ivr.coa_at_ship_ind, ivr.coa_at_invoice_ind, ivr.coa_req_from_supl_ind'
1023 ||', ivr.delete_mark, ivr.text_code, ivr.attribute_category, ivr.attribute1'
1024 ||', ivr.attribute2, ivr.attribute3, ivr.attribute4, ivr.attribute5, ivr.attribute6'
1025 ||', ivr.attribute7, ivr.attribute8, ivr.attribute9, ivr.attribute10, ivr.attribute11'
1026 ||', ivr.attribute12, ivr.attribute13, ivr.attribute14, ivr.attribute15'
1027 ||', ivr.attribute16, ivr.attribute17, ivr.attribute18, ivr.attribute19'
1028 ||', ivr.attribute20, ivr.attribute21, ivr.attribute22, ivr.attribute23'
1029 ||', ivr.attribute24, ivr.attribute25, ivr.attribute26, ivr.attribute27'
1030 ||', ivr.attribute28, ivr.attribute29, ivr.attribute30, ivr.creation_date'
1031 ||', ivr.created_by, fu12.user_name, ivr.last_update_date, ivr.last_updated_by'
1032 ||', fu13.user_name, ivr.last_update_login'
1033 ||')';
1034 inv_vr_table_list := ' gmd_inventory_spec_vrs ivr, fnd_user fu12, fnd_user fu13';
1035
1036 inv_vr_where_clause := ' ivr.created_by = fu12.user_id AND ivr.last_updated_by = fu13.user_id'
1037 ||' AND ivr.spec_id = gs.spec_id AND 1=:dummy6';
1038 inv_vr_using_clause := '1';
1039
1040 -- START B3124291 Incorporated Mini-Pack K Features to Outboud APIs
1041 -- GMD_MONITORING_SPEC_VRS basic clauses
1042
1043 mon_vr_column_list := ' system.gmd_mon_spec_vr_rec_type' -- 5284247
1044 ||'( mvr.spec_vr_id, mvr.spec_id, mvr.rule_type, mvr.locator_organization_id, mvr.subinventory'
1045 ||', mvr.locator_id, mvr.resources, mvr.resource_organization_id, mvr.resource_instance_id'
1046 ||', mvr.spec_vr_status, NULL, mvr.start_date, mvr.end_date'
1047 ||', mvr.sampling_plan_id, NULL, mvr.delete_mark, mvr.text_code'
1048 ||', mvr.attribute_category, mvr.attribute1, mvr.attribute2, mvr.attribute3'
1049 ||', mvr.attribute4, mvr.attribute5, mvr.attribute6, mvr.attribute7, mvr.attribute8'
1050 ||', mvr.attribute9, mvr.attribute10, mvr.attribute11, mvr.attribute12, mvr.attribute13'
1051 ||', mvr.attribute14, mvr.attribute15, mvr.attribute16, mvr.attribute17, mvr.attribute18'
1052 ||', mvr.attribute19, mvr.attribute20, mvr.attribute21, mvr.attribute22, mvr.attribute23'
1053 ||', mvr.attribute24, mvr.attribute25, mvr.attribute26, mvr.attribute27, mvr.attribute28'
1054 ||', mvr.attribute29, mvr.attribute30, mvr.creation_date, mvr.created_by'
1055 ||', mvr.last_updated_by, mvr.last_update_date, mvr.last_update_login'
1056 ||')';
1057 mon_vr_table_list := ' gmd_monitoring_spec_vrs mvr, fnd_user fu14, fnd_user fu15';
1058
1059 mon_vr_where_clause := ' mvr.created_by = fu14.user_id AND mvr.last_updated_by = fu15.user_id'
1060 ||' AND mvr.spec_id = gs.spec_id AND 1=:dummy7';
1061 mon_vr_using_clause := '1';
1062 -- END B3124291 Incorporated Mini-Pack K Features to Outboud APIs
1063
1064
1065 -- Now comes the fun. We need to add conditions that restrict which rows are retrieved
1066 -- from each table by inspecting the parameters that are passed in and build a list of
1067 -- bind variable values as we go along.
1068
1069 -- We start with the base table itself, GMD_SPECIFICATIONS
1070
1071 IF p_from_spec_name IS NOT NULL
1072 THEN
1073 g_from_spec_name := p_from_spec_name;
1074 main_where_clause := main_where_clause||' AND gs.spec_name >= :from_spec_name';
1075 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_from_spec_name';
1076 END IF;
1077
1078 IF p_to_spec_name IS NOT NULL
1079 THEN
1080 g_to_spec_name := p_to_spec_name;
1081 main_where_clause := main_where_clause||' AND gs.spec_name <= :to_spec_name';
1082 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_to_spec_name';
1083 END IF;
1084
1085 IF p_spec_id IS NOT NULL
1086 THEN
1087 gmd_outbound_apis_pub.g_spec_id := p_spec_id;
1088 main_where_clause := main_where_clause||' AND gs.spec_id = :spec_id';
1089 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_spec_id';
1090 END IF;
1091
1092 IF p_spec_version IS NOT NULL
1093 THEN
1094 g_spec_version := p_spec_version;
1095 main_where_clause := main_where_clause||' AND gs.spec_vers = :spec_version';
1096 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_spec_version';
1097 END IF;
1098
1099 IF p_from_grade_code IS NOT NULL
1100 THEN
1101 g_from_grade_code := p_from_grade_code;
1102 main_where_clause := main_where_clause||' AND gs.grade_code >= :from_grade_code';
1103 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_from_grade_code';
1104 END IF;
1105
1106 IF p_to_grade_code IS NOT NULL
1107 THEN
1108 g_to_grade_code := p_to_grade_code;
1109 main_where_clause := main_where_clause||' AND gs.grade <= :to_grade_code';
1110 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_to_grade_code';
1111 END IF;
1112
1113 IF p_inventory_item_id IS NOT NULL
1114 THEN
1115 g_inventory_item_id := p_inventory_item_id;
1116 main_where_clause := main_where_clause|| ' AND gs.inventory_item_id = :inventory_item_id';
1117 main_using_clause := main_using_clause|| ', gmd_outbound_apis_pub.g_inventory_item_id';
1118 END if;
1119
1120 -- Start RLNAGARA Bug # 4548546
1121 IF p_from_revision IS NOT NULL
1122 THEN
1123 g_from_revision := p_from_revision;
1124 main_where_clause := main_where_clause||' AND gs.revision >= :from_revision';
1125 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_from_revision';
1126 END IF;
1127
1128 IF p_to_revision IS NOT NULL
1129 THEN
1130 g_to_revision := p_to_revision;
1131 main_where_clause := main_where_clause||' AND gs.revision <= :to_revision';
1132 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_to_revision';
1133 END IF;
1134 -- End RLNAGARA Bug # 4548546
1135
1136 IF p_from_item_number IS NOT NULL and p_to_item_number IS NOT NULL
1137 THEN
1138 g_from_item_number := p_from_item_number;
1139 g_to_item_number := p_to_item_number;
1140 main_where_clause := main_where_clause
1141 ||' AND gs.inventory_item_id IN (SELECT inventory_item_id FROM mtl_system_items_b_kfv'
1142 ||' WHERE concatenated_segments BETWEEN :from_item_number AND :to_item_number'
1143 ||' AND organization_id = gs.owner_organization_id)';
1144 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_from_item_number, gmd_outbound_apis_pub.g_to_item_number';
1145 ELSIF p_from_item_number IS NOT NULL
1146 THEN
1147 g_from_item_number := p_from_item_number;
1148 main_where_clause := main_where_clause
1149 ||' AND gs.inventory_item_id IN (SELECT inventory_item_id FROM mtl_system_items_b_kfv'
1150 ||' WHERE concatenated_segments >= :from_item_number'
1151 ||' AND organization_id = gs.owner_organization_id)';
1152 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_from_item_number';
1153 ELSIF p_to_item_number IS NOT NULL
1154 THEN
1155 g_to_item_number := p_to_item_number;
1156 main_where_clause := main_where_clause
1157 ||' AND gs.inventory_item_id IN (SELECT inventory_item_id FROM mtl_system_items_b_kfv'
1158 ||' WHERE concatenated_segments <= :to_item_number'
1159 ||' AND organization_id = gs.owner_organization_id)';
1160 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_to_item_number';
1161 END IF;
1162
1163 IF p_owner_organization_code IS NOT NULL
1164 THEN
1165 g_owner_organization_code := p_owner_organization_code;
1166 main_where_clause := main_where_clause|| ' AND gs.owner_organization_id = (SELECT organization_id'
1167 || ' FROM mtl_organizations WHERE organization_code = :owner_organization_code)';
1168 main_using_clause := main_using_clause|| ', gmd_outbound_apis_pub.g_owner_organization_code';
1169 END IF;
1170
1171 IF p_spec_status IS NOT NULL
1172 THEN
1173 g_spec_status := p_spec_status;
1174 main_where_clause := main_where_clause|| ' AND gs.spec_status = :spec_status';
1175 main_using_clause := main_using_clause|| ', gmd_outbound_apis_pub.g_spec_status';
1176 END IF;
1177
1178 IF p_spec_delete_mark IS NOT NULL
1179 THEN
1180 g_spec_delete_mark := p_spec_delete_mark;
1181 main_where_clause := main_where_clause|| ' AND gs.delete_mark = :delete_mark';
1182 main_using_clause := main_using_clause|| ', gmd_outbound_apis_pub.g_spec_delete_mark';
1183 END IF;
1184
1185 IF p_from_spec_last_update IS NOT NULL
1186 THEN
1187 gmd_outbound_apis_pub.g_from_spec_last_update := p_from_spec_last_update;
1188 main_where_clause := main_where_clause||' AND gs.last_update_date >= :from_spec_last_update';
1189 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_from_spec_last_update';
1190 END IF;
1191
1192 IF p_to_spec_last_update IS NOT NULL
1193 THEN
1194 gmd_outbound_apis_pub.g_to_spec_last_update := p_to_spec_last_update;
1195 main_where_clause := main_where_clause||' AND gs.last_update_date <= :to_spec_last_update';
1196 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_to_spec_last_update';
1197 END IF;
1198
1199 -- START B3124291 Incorporated Mini-Pack K Features to Outboud APIs
1200 IF p_overlay_ind IS NOT NULL
1201 THEN
1202 gmd_outbound_apis_pub.g_overlay_ind := p_overlay_ind;
1203 main_where_clause := main_where_clause||' AND gs.overlay_ind = :overlay_ind';
1204 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_overlay_ind';
1205 END IF;
1206
1207 IF p_spec_type IS NOT NULL
1208 THEN
1209 gmd_outbound_apis_pub.g_spec_type := p_spec_type;
1210 main_where_clause := main_where_clause||' AND gs.spec_type = :spec_type';
1211 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_spec_type';
1212 END IF;
1213
1214 IF p_base_spec_id IS NOT NULL
1215 THEN
1216 gmd_outbound_apis_pub.g_base_spec_id := p_base_spec_id;
1217 main_where_clause := main_where_clause||' AND gs.base_spec_id = :base_spec_id';
1218 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_base_spec_id';
1219 END IF;
1220
1221 IF p_base_spec_name IS NOT NULL OR p_base_spec_version IS NOT NULL
1222 THEN
1223 main_table_list := main_table_list || ', gmd_specifications_b gsp';
1224 main_where_clause := main_where_clause || ' AND gsp.spec_id = gs.base_spec_id';
1225
1226 IF p_base_spec_name IS NOT NULL
1227 THEN
1228 gmd_outbound_apis_pub.g_base_spec_name := p_base_spec_name;
1229 main_where_clause := main_where_clause||' AND gsp.spec_name = :base_spec_name';
1230 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_base_spec_name';
1231 END IF;
1232
1233 IF p_base_spec_version IS NOT NULL
1234 THEN
1235 gmd_outbound_apis_pub.g_base_spec_name := p_base_spec_name;
1236 main_where_clause := main_where_clause||' AND gsp.spec_vers = :base_spec_version';
1237 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_base_spec_version';
1238 END IF;
1239
1240 END IF;
1241 -- END B3124291 Incorporated Mini-Pack K Features to Outboud APIs
1242
1243 -- Now sort out retrieval from GMD_SPEC_TESTS
1244
1245 IF p_test_code IS NOT NULL OR p_test_id IS NOT NULL OR p_test_method_code IS NOT NULL
1246 OR p_test_method_id IS NOT NULL OR p_test_qty_uom IS NOT NULL OR p_test_priority IS NOT NULL
1247 OR p_from_test_last_update IS NOT NULL OR p_to_test_last_update IS NOT NULL
1248 OR p_test_delete_mark IS NOT NULL
1249 -- START B3124291 Incorporated Mini-Pack K Features to Outboud APIs
1250 OR p_from_base_ind IS NOT NULL OR p_exclude_ind IS NOT NULL OR p_modified_ind IS NOT NULL
1251 OR p_calc_uom_conv_ind IS NOT NULL OR p_to_qty_uom IS NOT NULL
1252 -- END B3124291 Incorporated Mini-Pack K Features to Outboud APIs
1253 THEN
1254
1255 -- Add the tables to the main list and join to it.
1256
1257 main_where_clause := main_where_clause
1258 ||' AND gs.spec_id IN '
1259 ||' (SELECT mgst.spec_id FROM gmd_spec_tests mgst '
1260 ||' WHERE 1=1';
1261
1262 -- Now work down the parameters that apply against this table and add to the
1263 -- main where clause and the spec_test where clause.
1264
1265 IF p_test_code IS NOT NULL
1266 THEN
1267 gmd_outbound_apis_pub.g_test_code := p_test_code;
1268 main_table_list := main_table_list||', gmd_qc_tests_b gqtb';
1269 main_where_clause := main_where_clause||' AND gqtb.test_code = :p_test_code';
1270 main_where_clause := main_where_clause||' AND mgst.test_id = gqtb.test_id';
1271 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_test_code';
1272
1273 spec_test_where_clause := spec_test_where_clause||' AND gst.test_id=gqtb.test_id';
1274 END IF;
1275
1276 IF p_test_id IS NOT NULL
1277 THEN
1278 gmd_outbound_apis_pub.g_test_id := p_test_id;
1279 main_where_clause := main_where_clause||' AND mgst.test_id = :p_test_id';
1280 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_test_id';
1281
1282 spec_test_where_clause := spec_test_where_clause||' AND gst.test_id = :p_test_id';
1283 spec_test_using_clause := spec_test_using_clause||', gmd_outbound_apis_pub.g_test_id';
1284 END IF;
1285
1286 IF p_test_method_id IS NOT NULL
1287 THEN
1288 gmd_outbound_apis_pub.g_test_method_id := p_test_method_id;
1289 main_where_clause := main_where_clause||' AND gtm.test_method_id = :p_test_method_id';
1290 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_test_method_id';
1291
1292 spec_test_where_clause := spec_test_where_clause||' AND gtm.test_method_id = :p_test_method_id';
1293 spec_test_using_clause := spec_test_using_clause||', gmd_outbound_apis_pub.g_test_method_id';
1294 END IF;
1295
1296 IF p_test_method_code IS NOT NULL
1297 THEN
1298 -- Need to link in the test methods table if the test method code parameter is passed
1299
1300 main_table_list := main_table_list||', gmd_test_methods mgtm';
1301
1302 gmd_outbound_apis_pub.g_test_method_code := p_test_method_code;
1303 main_where_clause := main_where_clause||' AND mgtm.test_method_code = :p_test_method_code'
1304 ||' AND mgtm.test_method_id = mgst.test_method_id';
1305 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_test_method_code';
1306
1307 spec_test_where_clause := spec_test_where_clause||' AND gtm.test_method_code = :p_test_method_code';
1308 spec_test_using_clause := spec_test_using_clause||', gmd_outbound_apis_pub.g_test_method_code';
1309
1310 END IF;
1311
1312 IF p_test_qty_uom IS NOT NULL
1313 THEN
1314 gmd_outbound_apis_pub.g_test_qty_uom := p_test_qty_uom;
1315 main_where_clause := main_where_clause||' AND mgst.test_qty_uom = :p_test_qty_uom';
1316 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_test_qty_uom';
1317
1318 spec_test_where_clause := spec_test_where_clause||' AND gst.test_qty_uom = :p_test_qty_uom';
1319 spec_test_using_clause := spec_test_using_clause||', gmd_outbound_apis_pub.g_test_qty_uom';
1320 END IF;
1321
1322 IF p_test_priority IS NOT NULL
1323 THEN
1324 gmd_outbound_apis_pub.g_test_priority := p_test_priority;
1325 main_where_clause := main_where_clause||' AND mgst.test_priority = :p_test_priority';
1326 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_test_priority';
1327
1328 spec_test_where_clause := spec_test_where_clause||' AND gst.test_priority = :p_test_priority';
1329 spec_test_using_clause := spec_test_using_clause||', gmd_outbound_apis_pub.g_test_priority';
1330 END IF;
1331
1332 IF p_from_test_last_update IS NOT NULL
1333 THEN
1334 gmd_outbound_apis_pub.g_from_test_last_update := p_from_test_last_update;
1335 main_where_clause := main_where_clause||' AND mgst.last_update_date >= :p_from_test_last_update';
1336 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_from_test_last_update';
1337
1338 spec_test_where_clause := spec_test_where_clause||' AND gst.last_update_date >= :p_from_test_last_update';
1339 spec_test_using_clause := spec_test_using_clause||', gmd_outbound_apis_pub.g_from_test_last_update';
1340 END IF;
1341
1342 IF p_to_test_last_update IS NOT NULL
1343 THEN
1344 gmd_outbound_apis_pub.g_to_test_last_update := p_to_test_last_update;
1345 main_where_clause := main_where_clause||' AND mgst.to_update_date <= :p_to_test_last_update';
1346 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_to_test_last_update';
1347
1348 spec_test_where_clause := spec_test_where_clause||' AND gst.to_update_date <= :p_to_test_last_update';
1349 spec_test_using_clause := spec_test_using_clause||', gmd_outbound_apis_pub.g_to_test_last_update';
1350 END IF;
1351
1352 IF p_test_delete_mark IS NOT NULL
1353 THEN
1354 gmd_outbound_apis_pub.g_test_delete_mark := p_test_delete_mark;
1355 main_where_clause := main_where_clause||' AND mgst.delete_mark = :p_test_delete_mark';
1356 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_test_delete_mark';
1357
1358 spec_test_where_clause := spec_test_where_clause||' AND gst.delete_mark = :p_test_delete_mark';
1359 spec_test_using_clause := spec_test_using_clause||', gmd_outbound_apis_pub.g_test_delete_mark';
1360 END IF;
1361
1362 -- START B3124291 Incorporated Mini-Pack K Features to Outboud APIs
1363 IF p_from_base_ind IS NOT NULL
1364 THEN
1365 gmd_outbound_apis_pub.g_from_base_ind := p_from_base_ind;
1366 main_where_clause := main_where_clause||' AND mgst.from_base_ind = :p_from_base_ind';
1367 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_from_base_ind';
1368
1369 spec_test_where_clause := spec_test_where_clause||' AND gst.from_base_ind = :p_from_base_ind';
1370 spec_test_using_clause := spec_test_using_clause||', gmd_outbound_apis_pub.g_from_base_ind';
1371 END IF;
1372
1373 IF p_exclude_ind IS NOT NULL
1374 THEN
1375 gmd_outbound_apis_pub.g_exclude_ind := p_exclude_ind;
1376 main_where_clause := main_where_clause||' AND mgst.exclude_ind = :p_exclude_ind';
1377 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_exclude_ind';
1378
1379 spec_test_where_clause := spec_test_where_clause||' AND gst.exclude_ind = :p_exclude_ind';
1380 spec_test_using_clause := spec_test_using_clause||', gmd_outbound_apis_pub.g_exclude_ind';
1381 END IF;
1382
1383 IF p_modified_ind IS NOT NULL
1384 THEN
1385 gmd_outbound_apis_pub.g_modified_ind := p_modified_ind;
1386 main_where_clause := main_where_clause||' AND mgst.modified_ind = :p_modified_ind';
1387 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_modified_ind';
1388
1389 spec_test_where_clause := spec_test_where_clause||' AND gst.modified_ind = :p_modified_ind';
1390 spec_test_using_clause := spec_test_using_clause||', gmd_outbound_apis_pub.g_modified_ind';
1391 END IF;
1392
1393 IF p_calc_uom_conv_ind IS NOT NULL
1394 THEN
1395 gmd_outbound_apis_pub.g_calc_uom_conv_ind := p_calc_uom_conv_ind;
1396 main_where_clause := main_where_clause||' AND mgst.calc_uom_conv_ind = :p_calc_uom_conv_ind';
1397 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_calc_uom_conv_ind';
1398
1399 spec_test_where_clause := spec_test_where_clause||' AND gst.calc_uom_conv_ind = :p_calc_uom_conv_ind';
1400 spec_test_using_clause := spec_test_using_clause||', gmd_outbound_apis_pub.g_calc_uom_conv_ind';
1401 END IF;
1402
1403 IF p_to_qty_uom IS NOT NULL
1404 THEN
1405 gmd_outbound_apis_pub.g_to_qty_uom := p_to_qty_uom;
1406 main_where_clause := main_where_clause||' AND mgst.to_qty_uom = :p_to_qty_uom';
1407 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_to_qty_uom';
1408
1409 spec_test_where_clause := spec_test_where_clause||' AND gst.to_qty_uom = :p_to_qty_uom';
1410 spec_test_using_clause := spec_test_using_clause||', gmd_outbound_apis_pub.g_to_qty_uom';
1411 END IF;
1412
1413 -- END B3124291 Incorporated Mini-Pack K Features to Outboud APIs
1414
1415 main_where_clause := main_where_clause||' ) ';
1416
1417 END IF;
1418
1419 -- Now sort out the retrieval from GMD_WIP_SPEC_VRS
1420
1421
1422 IF p_wip_vr_status IS NOT NULL OR p_wip_vr_organization_code IS NOT NULL OR p_wip_vr_batch_orgn_code IS NOT NULL
1423 OR p_wip_vr_batch_no IS NOT NULL OR p_wip_vr_batch_id IS NOT NULL OR p_wip_vr_recipe_no IS NOT NULL
1424 OR p_wip_vr_recipe_version IS NOT NULL OR p_wip_vr_recipe_id IS NOT NULL OR p_wip_vr_formula_no IS NOT NULL
1425 OR p_wip_vr_formula_version IS NOT NULL OR p_wip_vr_formula_id IS NOT NULL OR p_wip_vr_formulaline_no IS NOT NULL
1426 OR p_wip_vr_formulaline_id IS NOT NULL OR p_wip_vr_line_type IS NOT NULL OR p_wip_vr_routing_no IS NOT NULL
1427 OR p_wip_vr_routing_version IS NOT NULL OR p_wip_vr_routing_id IS NOT NULL OR p_wip_vr_step_no IS NOT NULL
1428 OR p_wip_vr_step_id IS NOT NULL OR p_wip_vr_operation_no IS NOT NULL OR p_wip_vr_operation_version IS NOT NULL
1429 OR p_wip_vr_operation_id IS NOT NULL OR p_wip_vr_start_date IS NOT NULL OR p_wip_vr_end_date IS NOT NULL
1430 OR p_wip_vr_coa_type IS NOT NULL OR p_wip_vr_sampling_plan IS NOT NULL OR p_wip_vr_sampling_plan_id IS NOT NULL
1431 OR p_wip_vr_delete_mark IS NOT NULL OR p_wip_vr_from_last_update IS NOT NULL OR p_wip_vr_to_last_update IS NOT NULL
1432 THEN
1433 -- Add the table to the main list and join to it.
1434
1435 main_where_clause := main_where_clause
1436 ||' AND gs.spec_id IN'
1437 ||' (SELECT mwvr.spec_id'
1438 ||' FROM gmd_wip_spec_vrs mwvr'
1439 ||' WHERE 1=1';
1440
1441 IF p_wip_vr_status IS NOT NULL
1442 THEN
1443 gmd_outbound_apis_pub.g_wip_vr_status := p_wip_vr_status;
1444 main_where_clause := main_where_clause||' AND mwvr.spec_vr_status = :wip_spec_vr_status';
1445 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_status';
1446
1447 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.spec_vr_status = :wip_spec_vr_status';
1448 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_status';
1449
1450 END IF;
1451
1452 IF p_wip_vr_organization_code IS NOT NULL
1453 THEN
1454 gmd_outbound_apis_pub.g_wip_vr_organization_code := p_wip_vr_organization_code;
1455 main_where_clause := main_where_clause||' AND mwvr.organization_id = (SELECT organization_id '
1456 ||'FROM mtl_organizations WHERE organization_code = :wip_vr_organization_code)';
1457 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_organization_code';
1458
1459 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.organization_id = (SELECT organization_id '
1460 ||'FROM mtl_organizations WHERE organization_code = :wip_vr_organization_code)';
1461 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_organization_code';
1462
1463 END IF;
1464
1465 IF p_wip_vr_batch_orgn_code IS NOT NULL
1466 THEN
1467 gmd_outbound_apis_pub.g_wip_vr_batch_orgn_code := p_wip_vr_batch_orgn_code;
1468 main_where_clause := main_where_clause||' AND mwvr.batch_id IN'
1469 ||' (SELECT batch_id FROM gme_batch_header '
1470 ||' WHERE organization_id = (SELECT organization_id FROM'
1471 ||' mtl_parameters WHERE organization_code = :wip_vr_batch_orgn_code) )';
1472 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_batch_orgn_code';
1473
1474 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.batch_id IN'
1475 ||' (SELECT batch_id FROM gme_batch_header '
1476 ||' WHERE organization_id = (SELECT organization_id FROM'
1477 ||' mtl_parameters WHERE organization_code = :wip_vr_batch_orgn_code) )';
1478 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_batch_orgn_code';
1479 END IF;
1480
1481 IF p_wip_vr_batch_no IS NOT NULL
1482 THEN
1483 gmd_outbound_apis_pub.g_wip_vr_batch_no := p_wip_vr_batch_no;
1484 main_where_clause := main_where_clause||' AND mwvr.batch_id IN'
1485 ||' (SELECT batch_id FROM gme_batch_header '
1486 ||' WHERE batch_no = :wip_vr_batch_no '
1487 ||' AND batch_type = 0)';
1488 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_batch_no';
1489
1490 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.batch_id IN'
1491 ||' (SELECT batch_id FROM gme_batch_header '
1492 ||' WHERE batch_no = :wip_vr_batch_no '
1493 ||' AND batch_type = 0)';
1494 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_batch_no';
1495 END IF;
1496
1497 IF p_wip_vr_batch_id IS NOT NULL
1498 THEN
1499 gmd_outbound_apis_pub.g_wip_vr_batch_id := p_wip_vr_batch_id;
1500 main_where_clause := main_where_clause||' AND mwvr.batch_id = :wip_vr_batch_id';
1501 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_batch_id';
1502
1503 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.batch_id = :wip_vr_batch_id';
1504 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_batch_id';
1505 END IF;
1506
1507 IF p_wip_vr_recipe_no IS NOT NULL
1508 THEN
1509 gmd_outbound_apis_pub.g_wip_vr_recipe_no := p_wip_vr_recipe_no;
1510 main_where_clause := main_where_clause||' AND mwvr.recipe_no = :wip_vr_recipe_no';
1511 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_recipe_no';
1512
1513 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.recipe_no = :wip_vr_recipe_no';
1514 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_recipe_no';
1515 END IF;
1516
1517 IF p_wip_vr_recipe_version IS NOT NULL
1518 THEN
1519 gmd_outbound_apis_pub.g_wip_vr_recipe_version := p_wip_vr_recipe_version;
1520 main_where_clause := main_where_clause||' AND mwvr.recipe_version = :wip_vr_recipe_version';
1521 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_recipe_version';
1522
1523 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.recipe_version = :wip_vr_recipe_version';
1524 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_recipe_version';
1525 END IF;
1526
1527 IF p_wip_vr_recipe_id IS NOT NULL
1528 THEN
1529 gmd_outbound_apis_pub.g_wip_vr_recipe_id := p_wip_vr_recipe_id;
1530 main_where_clause := main_where_clause||' AND mwvr.recipe_id = :wip_vr_recipe_id';
1531 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_recipe_id';
1532
1533 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.recipe_id = :wip_vr_recipe_id';
1534 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_recipe_id';
1535 END IF;
1536
1537 IF p_wip_vr_formula_no IS NOT NULL
1538 THEN
1539 gmd_outbound_apis_pub.g_wip_vr_formula_no := p_wip_vr_formula_no;
1540 main_where_clause := main_where_clause||' AND mwvr.formula_no = :wip_vr_formula_no';
1541 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_formula_no';
1542
1543 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.formula_no = :wip_vr_formula_no';
1544 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_formula_no';
1545 END IF;
1546
1547 IF p_wip_vr_formula_version IS NOT NULL
1548 THEN
1549 gmd_outbound_apis_pub.g_wip_vr_formula_version := p_wip_vr_formula_version;
1550 main_where_clause := main_where_clause||' AND mwvr.formula_vers = :wip_vr_formula_version';
1551 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_formula_version';
1552
1553 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.formula_vers = :wip_vr_formula_version';
1554 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_formula_version';
1555 END IF;
1556
1557 IF p_wip_vr_formula_id IS NOT NULL
1558 THEN
1559 gmd_outbound_apis_pub.g_wip_vr_formula_id := p_wip_vr_formula_id;
1560 main_where_clause := main_where_clause||' AND mwvr.formula_id = :wip_vr_formula_id';
1561 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_formula_id';
1562
1563 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.formula_id = :wip_vr_formula_id';
1564 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_formula_id';
1565 END IF;
1566
1567 IF p_wip_vr_formulaline_no IS NOT NULL
1568 THEN
1569 gmd_outbound_apis_pub.g_wip_vr_formulaline_no := p_wip_vr_formulaline_no;
1570 main_where_clause := main_where_clause||' AND mwvr.formulaline_no = :wip_vr_formulaline_no';
1571 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_formulaline_no';
1572
1573 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.formulaline_no = :wip_vr_formulaline_no';
1574 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_formulaline_no';
1575 END IF;
1576
1577 IF p_wip_vr_formulaline_id IS NOT NULL
1578 THEN
1579 gmd_outbound_apis_pub.g_wip_vr_formulaline_id := p_wip_vr_formulaline_id;
1580 main_where_clause := main_where_clause||' AND mwvr.formulaline_id = :wip_vr_formulaline_id';
1581 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_formulaline_id';
1582
1583 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.formulaline_id = :wip_vr_formulaline_id';
1584 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_formulaline_id';
1585 END IF;
1586
1587 IF p_wip_vr_routing_no IS NOT NULL
1588 THEN
1589 gmd_outbound_apis_pub.g_wip_vr_formula_no := p_wip_vr_routing_no;
1590 main_where_clause := main_where_clause||' AND mwvr.routing_no = :wip_vr_routing_no';
1591 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_routing_no';
1592
1593 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.routing_no = :wip_vr_routing_no';
1594 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_routing_no';
1595 END IF;
1596
1597 IF p_wip_vr_routing_version IS NOT NULL
1598 THEN
1599 gmd_outbound_apis_pub.g_wip_vr_routing_version := p_wip_vr_routing_version;
1600 main_where_clause := main_where_clause||' AND mwvr.routing_vers = :wip_vr_routing_version';
1601 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_routing_version';
1602
1603 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.routing_vers = :wip_vr_routing_version';
1604 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_routing_version';
1605 END IF;
1606
1607 IF p_wip_vr_routing_id IS NOT NULL
1608 THEN
1609 gmd_outbound_apis_pub.g_wip_vr_routing_id := p_wip_vr_routing_id;
1610 main_where_clause := main_where_clause||' AND mwvr.routing_id = :wip_vr_routing_id';
1611 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_routing_id';
1612
1613 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.routing_id = :wip_vr_routing_id';
1614 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_routing_id';
1615 END IF;
1616
1617 IF p_wip_vr_step_no IS NOT NULL
1618 THEN
1619 gmd_outbound_apis_pub.g_wip_vr_step_no := p_wip_vr_step_no;
1620 main_where_clause := main_where_clause||' AND mwvr.step_no = :wip_vr_step_no';
1621 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_step_no';
1622
1623 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.step_no = :wip_vr_step_no';
1624 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_step_no';
1625 END IF;
1626
1627 IF p_wip_vr_step_id IS NOT NULL
1628 THEN
1629 gmd_outbound_apis_pub.g_wip_vr_step_id := p_wip_vr_step_id;
1630 main_where_clause := main_where_clause||' AND mwvr.step_id = :wip_vr_step_id';
1631 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_step_id';
1632
1633 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.step_id = :wip_vr_step_id';
1634 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_step_id';
1635 END IF;
1636
1637 IF p_wip_vr_operation_no IS NOT NULL
1638 THEN
1639 gmd_outbound_apis_pub.g_wip_vr_operation_no := p_wip_vr_operation_no;
1640 main_where_clause := main_where_clause||' AND mwvr.oprn_no = :wip_vr_operation_no';
1641 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_operation_no';
1642
1643 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.oprn_no = :wip_vr_operation_no';
1644 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_operation_no';
1645 END IF;
1646
1647 IF p_wip_vr_operation_version IS NOT NULL
1648 THEN
1649 gmd_outbound_apis_pub.g_wip_vr_operation_version := p_wip_vr_operation_version;
1650 main_where_clause := main_where_clause||' AND mwvr.oprn_vers = :wip_vr_operation_version';
1651 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_operation_version';
1652
1653 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.oprn_vers = :wip_vr_operation_version';
1654 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_operation_version';
1655 END IF;
1656
1657 IF p_wip_vr_operation_id IS NOT NULL
1658 THEN
1659 gmd_outbound_apis_pub.g_wip_vr_operation_id := p_wip_vr_operation_id;
1660 main_where_clause := main_where_clause||' AND mwvr.oprn_id = :wip_vr_operation_id';
1661 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_operation_id';
1662
1663 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.oprn_id = :wip_vr_operation_id';
1664 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_operation_id';
1665 END IF;
1666
1667 IF p_wip_vr_start_date IS NOT NULL
1668 THEN
1669 gmd_outbound_apis_pub.g_wip_vr_start_date := p_wip_vr_start_date;
1670 main_where_clause := main_where_clause||' AND mwvr.start_date >= :wip_vr_start_date';
1671 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_start_date';
1672
1673 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.start_date >= :wip_vr_start_date';
1674 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_start_date';
1675 END IF;
1676
1677 IF p_wip_vr_end_date IS NOT NULL
1678 THEN
1679 gmd_outbound_apis_pub.g_wip_vr_end_date := p_wip_vr_end_date;
1680 main_where_clause := main_where_clause||' AND mwvr.end_date <= :wip_vr_end_date';
1681 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_end_date';
1682
1683 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.end_date <= :wip_vr_end_date';
1684 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_end_date';
1685 END IF;
1686
1687 IF p_wip_vr_coa_type IS NOT NULL
1688 THEN
1689 gmd_outbound_apis_pub.g_wip_vr_coa_type := p_wip_vr_coa_type;
1690 main_where_clause := main_where_clause||' AND mwvr.coa_type = :wip_vr_coa_type';
1691 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_coa_type';
1692
1693 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.coa_type = :wip_vr_coa_type';
1694 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_coa_type';
1695 END IF;
1696
1697 IF p_wip_vr_sampling_plan_id IS NOT NULL
1698 THEN
1699 gmd_outbound_apis_pub.g_wip_vr_sampling_plan_id := p_wip_vr_sampling_plan_id;
1700 main_where_clause := main_where_clause||' AND mwvr.sampling_plan_id = :wip_vr_sampling_plan_id';
1701 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_sampling_plan_id';
1702
1703 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.sampling_plan_id = :wip_vr_sampling_plan_id';
1704 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_sampling_plan_id';
1705 END IF;
1706
1707 IF p_wip_vr_delete_mark IS NOT NULL
1708 THEN
1709 gmd_outbound_apis_pub.g_wip_vr_delete_mark := p_wip_vr_delete_mark;
1710 main_where_clause := main_where_clause||' AND mwvr.delete_mark >= :wip_vr_delete_mark';
1711 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_delete_mark';
1712
1713 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.delete_mark >= :wip_vr_delete_mark';
1714 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_delete_mark';
1715 END IF;
1716
1717 IF p_wip_vr_from_last_update IS NOT NULL
1718 THEN
1719 gmd_outbound_apis_pub.g_wip_vr_from_last_update := p_wip_vr_from_last_update;
1720 main_where_clause := main_where_clause||' AND mwvr.last_update_date >= :wip_vr_from_last_update';
1721 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_from_last_update';
1722
1723 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.last_update_date >= :wip_vr_from_last_update';
1724 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_from_last_update';
1725 END IF;
1726
1727 IF p_wip_vr_to_last_update IS NOT NULL
1728 THEN
1729 gmd_outbound_apis_pub.g_wip_vr_to_last_update := p_wip_vr_to_last_update;
1730 main_where_clause := main_where_clause||' AND mwvr.last_update_date <= :wip_vr_to_last_update';
1731 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_vr_to_last_update';
1732
1733 wip_vr_where_clause := wip_vr_where_clause||' AND wvr.last_update_date <= :wip_vr_to_last_update';
1734 wip_vr_using_clause := wip_vr_using_clause||', gmd_outbound_apis_pub.g_wip_vr_to_last_update';
1735 END IF;
1736
1737 main_where_clause := main_where_clause||' ) ';
1738
1739 END IF;
1740
1741 -- Now sort out the retrieval from GMD_CUSTOMER_SPEC_VRS
1742
1743 IF p_cust_vr_start_date IS NOT NULL OR p_cust_vr_end_date IS NOT NULL OR p_cust_vr_status IS NOT NULL
1744 OR p_cust_vr_organization_code IS NOT NULL OR p_cust_vr_org_id IS NOT NULL OR p_cust_vr_coa_type IS NOT NULL
1745 OR p_cust_vr_customer IS NOT NULL OR p_cust_vr_customer_id IS NOT NULL OR p_cust_vr_order_number IS NOT NULL
1746 OR p_cust_vr_order_id IS NOT NULL OR p_cust_vr_order_type IS NOT NULL OR p_cust_vr_order_line_no IS NOT NULL
1747 OR p_cust_vr_order_line_id IS NOT NULL OR p_cust_vr_ship_to_location IS NOT NULL
1748 OR p_cust_vr_ship_to_site_id IS NOT NULL OR p_cust_vr_operating_unit IS NOT NULL
1749 OR p_cust_vr_delete_mark IS NOT NULL OR p_cust_vr_from_last_update IS NOT NULL
1750 OR p_cust_vr_to_last_update IS NOT NULL
1751 THEN
1752 -- Add the table to the list and join to it.
1753
1754
1755 main_where_clause := main_where_clause
1756 ||' AND gs.spec_id IN'
1757 ||' (SELECT mcvr.spec_id FROM gmd_customer_spec_vrs mcvr'
1758 ||' WHERE 1=1';
1759
1760 IF p_cust_vr_start_date IS NOT NULL
1761 THEN
1762 g_cust_vr_start_date := p_cust_vr_start_date;
1763 main_where_clause := main_where_clause||' AND mcvr.start_date >= :cust_vr_start_date';
1764 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_cust_vr_start_date';
1765
1766 cust_vr_where_clause := cust_vr_where_clause||' AND cvr.start_date >= :cust_vr_start_date';
1767 cust_vr_using_clause := cust_vr_using_clause||', gmd_outbound_apis_pub.g_cust_vr_start_date';
1768 END IF;
1769
1770 IF p_cust_vr_end_date IS NOT NULL
1771 THEN
1772 g_cust_vr_end_date := p_cust_vr_end_date;
1773 main_where_clause := main_where_clause||' AND mcvr.end_date <= :cust_vr_end_date';
1774 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_cust_vr_end_date';
1775
1776 cust_vr_where_clause := cust_vr_where_clause||' AND cvr.end_date <= :cust_vr_end_date';
1777 cust_vr_using_clause := cust_vr_using_clause||', gmd_outbound_apis_pub.g_cust_vr_end_date';
1778 END IF;
1779
1780 IF p_cust_vr_status IS NOT NULL
1781 THEN
1782 g_cust_vr_status := p_cust_vr_status;
1783 main_where_clause := main_where_clause||' AND mcvr.spec_vr_status = :cust_vr_status';
1784 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_cust_vr_status';
1785
1786 cust_vr_where_clause := cust_vr_where_clause||' AND cvr.spec_vr_status = :cust_vr_status';
1787 cust_vr_using_clause := cust_vr_using_clause||', gmd_outbound_apis_pub.g_cust_vr_status';
1788 END IF;
1789
1790 IF p_cust_vr_organization_code IS NOT NULL
1791 THEN
1792 g_cust_vr_organization_code := p_cust_vr_organization_code;
1793 main_where_clause := main_where_clause||' AND mcvr.organization_id = (SELECT organization_id '
1794 ||'FROM mtl_organizations WHERE organization_code = :cust_vr_organization_code)';
1795 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_cust_vr_organization_code';
1796
1797 cust_vr_where_clause := cust_vr_where_clause||' AND cvr.organization_id = (SELECT organization_id '
1798 ||'FROM mtl_organizations WHERE organization_code = :cust_vr_organization_code)';
1799 cust_vr_using_clause := cust_vr_using_clause||', gmd_outbound_apis_pub.g_cust_vr_organization_code';
1800 END IF;
1801
1802 IF p_cust_vr_org_id IS NOT NULL
1803 THEN
1804 g_cust_vr_org_id := p_cust_vr_org_id;
1805 main_where_clause := main_where_clause||' AND mcvr.org_id = :cust_vr_org_id';
1806 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_cust_vr_org_id';
1807
1808 cust_vr_where_clause := cust_vr_where_clause||' AND cvr.org_id = :cust_vr_org_id';
1809 cust_vr_using_clause := cust_vr_using_clause||', gmd_outbound_apis_pub.g_cust_vr_org_id';
1810 END IF;
1811
1812 IF p_cust_vr_coa_type IS NOT NULL
1813 THEN
1814 g_cust_vr_coa_type := p_cust_vr_coa_type;
1815 main_where_clause := main_where_clause||' AND mcvr.coa_type = :cust_vr_coa_type';
1816 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_cust_vr_coa_type';
1817
1818 cust_vr_where_clause := cust_vr_where_clause||' AND cvr.coa_type = :cust_vr_coa_type';
1819 cust_vr_using_clause := cust_vr_using_clause||', gmd_outbound_apis_pub.g_cust_vr_coa_type';
1820 END IF;
1821
1822 IF p_cust_vr_customer_id IS NOT NULL
1823 THEN
1824 g_cust_vr_customer_id := p_cust_vr_customer_id;
1825 main_where_clause := main_where_clause||' AND mcvr.cust_id = :cust_vr_customer_id';
1826 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_cust_vr_customer_id';
1827
1828 cust_vr_where_clause := cust_vr_where_clause||' AND cvr.cust_id = :cust_vr_customer_id';
1829 cust_vr_using_clause := cust_vr_using_clause||', gmd_outbound_apis_pub.g_cust_vr_customer_id';
1830 END IF;
1831
1832 IF p_cust_vr_customer IS NOT NULL
1833 THEN
1834 g_cust_vr_customer := p_cust_vr_customer;
1835 main_where_clause := main_where_clause||' AND mcvr.cust_id IN'
1836 ||' (SELECT hzca.cust_account_id'
1837 ||' FROM hz_parties hzp, hz_cust_accounts_all hzca'
1838 ||' WHERE hzp.party_id = hzca.party_id AND'
1839 ||' UPPER(hzp.party_name)'
1840 ||' LIKE UPPER(:cust_vr_customer)'
1841 ||' )';
1842 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_cust_vr_customer';
1843
1844 cust_vr_where_clause := cust_vr_where_clause||' AND cvr.cust_id IN'
1845 ||' (SELECT hzca.cust_account_id'
1846 ||' FROM hz_parties hzp, hz_cust_accounts_all hzca'
1847 ||' WHERE hzp.party_id = hzca.party_id AND'
1848 ||' UPPER(hzp.party_name)'
1849 ||' LIKE UPPER(:cust_vr_customer)'
1850 ||' )';
1851 cust_vr_using_clause := cust_vr_using_clause||', gmd_outbound_apis_pub.g_cust_vr_customer';
1852 END IF;
1853
1854 IF p_cust_vr_order_id IS NOT NULL
1855 THEN
1856 g_cust_vr_order_id := p_cust_vr_order_id;
1857 main_where_clause := main_where_clause||' AND mcvr.order_id = :cust_vr_order_id';
1858 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_cust_vr_order_id';
1859
1860 cust_vr_where_clause := cust_vr_where_clause||' AND cvr.order_id = :cust_vr_order_id';
1861 cust_vr_using_clause := cust_vr_using_clause||', gmd_outbound_apis_pub.g_cust_vr_order_id';
1862 END IF;
1863
1864 IF p_cust_vr_order_number IS NOT NULL
1865 THEN
1866 g_cust_vr_order_number := p_cust_vr_order_number;
1867 main_where_clause := main_where_clause||' AND mcvr.order_id = (select header_id '
1868 ||' from oe_order_headers_all'
1869 ||' where order_number = :cust_vr_order_number)';
1870 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_cust_vr_order_number';
1871
1872 cust_vr_where_clause := cust_vr_where_clause||' AND oeh.order_number = :cust_vr_order_number';
1873 cust_vr_using_clause := cust_vr_using_clause||', gmd_outbound_apis_pub.g_cust_vr_order_number';
1874 END IF;
1875
1876
1877 IF p_cust_vr_delete_mark IS NOT NULL
1878 THEN
1879 g_cust_vr_delete_mark := p_cust_vr_delete_mark;
1880 main_where_clause := main_where_clause||' AND mcvr.delete_mark = :cust_vr_delete_mark';
1881 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_cust_vr_delete_mark';
1882
1883 cust_vr_where_clause := cust_vr_where_clause||' AND cvr.delete_mark = :cust_vr_delete_mark';
1884 cust_vr_using_clause := cust_vr_using_clause||', gmd_outbound_apis_pub.g_cust_vr_delete_mark';
1885 END IF;
1886
1887 IF p_cust_vr_from_last_update IS NOT NULL
1888 THEN
1889 g_cust_vr_from_last_update := p_cust_vr_from_last_update;
1890 main_where_clause := main_where_clause||' AND mcvr.last_update_date >= :cust_vr_from_last_update';
1891 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_cust_vr_from_last_update';
1892
1893 cust_vr_where_clause := cust_vr_where_clause||' AND cvr.last_update_date >= :cust_vr_from_last_update';
1894 cust_vr_using_clause := cust_vr_using_clause||', gmd_outbound_apis_pub.g_cust_vr_from_last_update';
1895 END IF;
1896
1897 IF p_cust_vr_to_last_update IS NOT NULL
1898 THEN
1899 g_cust_vr_to_last_update := p_cust_vr_to_last_update;
1900 main_where_clause := main_where_clause||' AND mcvr.last_update_date <= :cust_vr_to_last_update';
1901 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_cust_vr_to_last_update';
1902
1903 cust_vr_where_clause := cust_vr_where_clause||' AND cvr.last_update_date <= :cust_vr_to_last_update';
1904 cust_vr_using_clause := cust_vr_using_clause||', gmd_outbound_apis_pub.g_cust_vr_to_last_update';
1905 END IF;
1906
1907 IF p_cust_vr_order_line_id IS NOT NULL
1908 THEN
1909 g_cust_vr_order_line_id := p_cust_vr_order_line_id;
1910 main_where_clause := main_where_clause||' AND mcvr.order_line_id = :cust_vr_order_line_id';
1911 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_cust_vr_order_line_id';
1912
1913 cust_vr_where_clause := cust_vr_where_clause||' AND cvr.order_line_id = :cust_vr_order_line_id';
1914 cust_vr_using_clause := cust_vr_using_clause||', gmd_outbound_apis_pub.g_cust_vr_order_line_id';
1915 END IF;
1916
1917 IF p_cust_vr_order_line_no IS NOT NULL
1918 THEN
1919 g_cust_vr_order_line_no := p_cust_vr_order_line_no;
1920 main_where_clause := main_where_clause||' AND mcvr.order_line = :cust_vr_order_line_no';
1921 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_cust_vr_order_line_no';
1922
1923 cust_vr_where_clause := cust_vr_where_clause||' AND cvr.order_line = :cust_vr_order_line_no';
1924 cust_vr_using_clause := cust_vr_using_clause||', gmd_outbound_apis_pub.g_cust_vr_order_line_no';
1925 END IF;
1926
1927 IF p_cust_vr_order_type IS NOT NULL
1928 THEN
1929 g_cust_vr_order_type := p_cust_vr_order_type;
1930 main_where_clause := main_where_clause||' AND mcvr.order_id IN (select header_id '
1931 ||' FROM oe_order_headers_all h, oe_transaction_types_all t'
1932 ||' WHERE h.order_type_id = t.transaction_type_id'
1933 ||' AND t.transaction_type_code = :cust_vr_order_type)';
1934 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_cust_vr_order_type';
1935
1936 cust_vr_table_list := cust_vr_table_list||', oe_transaction_types_all tta';
1937 cust_vr_where_clause := cust_vr_where_clause||' AND oeh.order_type_id = tta.transaction_type_id'
1938 ||' AND tta.transaction_type_code = :cust_vr_order_type';
1939 cust_vr_using_clause := cust_vr_using_clause||', gmd_outbound_apis_pub.g_cust_vr_order_type';
1940 END IF;
1941
1942 IF p_cust_vr_ship_to_site_id IS NOT NULL
1943 THEN
1944 g_cust_vr_ship_to_site_id := p_cust_vr_ship_to_site_id;
1945 main_where_clause := main_where_clause||' AND mcvr.ship_to_site_id = :cust_vr_ship_to_site_id';
1946 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_cust_vr_ship_to_site_id';
1947
1948 cust_vr_where_clause := cust_vr_where_clause||' AND cvr.ship_to_site_id = :cust_vr_ship_to_site_id';
1949 cust_vr_using_clause := cust_vr_using_clause||', gmd_outbound_apis_pub.g_cust_vr_ship_to_site_id';
1950 END IF;
1951
1952 IF p_cust_vr_ship_to_location IS NOT NULL
1953 THEN
1954 g_cust_vr_ship_to_location := p_cust_vr_ship_to_location;
1955 main_where_clause := main_where_clause||' AND mcvr.ship_to_site_use_id = '
1956 ||' (SELECT site_use_id'
1957 ||' FROM hz_cust_site_uses_all'
1958 ||' WHERE location = :cust_vr_ship_to_location)';
1959 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_cust_vr_ship_to_location';
1960
1961 cust_vr_where_clause := cust_vr_where_clause||' AND cvr.ship_to_site_use_id = '
1962 ||' (SELECT site_use_id'
1963 ||' FROM hz_cust_site_uses_all'
1964 ||' WHERE location = :cust_vr_ship_to_location)';
1965 cust_vr_using_clause := cust_vr_using_clause||', gmd_outbound_apis_pub.g_cust_vr_ship_to_location';
1966 END IF;
1967
1968 IF p_cust_vr_operating_unit IS NOT NULL
1969 THEN
1970 g_cust_vr_operating_unit := p_cust_vr_operating_unit;
1971 main_where_clause := main_where_clause||' AND mcvr.org_id = '
1972 ||' (SELECT organization_id'
1973 ||' FROM hr_operating_units'
1974 ||' WHERE name = :cust_vr_operating_unit)';
1975 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_cust_vr_operating_unit';
1976
1977 cust_vr_where_clause := cust_vr_where_clause||' AND cvr.org_id = '
1978 ||' (SELECT organization_id'
1979 ||' FROM hr_operating_units'
1980 ||' WHERE name = :cust_vr_operating_unit)';
1981 cust_vr_using_clause := cust_vr_using_clause||', gmd_outbound_apis_pub.g_cust_vr_operating_unit';
1982
1983 END IF;
1984
1985 main_where_clause := main_where_clause||' ) ';
1986
1987 END IF;
1988
1989 -- Sort out the GMD_SUPPLIER_SPEC_VRS parameters
1990
1991 IF p_supl_vr_start_date IS NOT NULL OR p_supl_vr_end_date IS NOT NULL OR p_supl_vr_status IS NOT NULL
1992 OR p_supl_vr_organization_code IS NOT NULL OR p_supl_vr_org_id IS NOT NULL OR p_supl_vr_coa_type IS NOT NULL
1993 OR p_supl_vr_supplier IS NOT NULL OR p_supl_vr_supplier_id IS NOT NULL OR p_supl_vr_po_number IS NOT NULL
1994 OR p_supl_vr_po_id IS NOT NULL OR p_supl_vr_po_line_no IS NOT NULL OR p_supl_vr_po_line_id IS NOT NULL
1995 OR p_supl_vr_supplier_site IS NOT NULL OR p_supl_vr_supplier_site_id IS NOT NULL
1996 OR p_supl_vr_operating_unit IS NOT NULL OR p_supl_vr_delete_mark IS NOT NULL
1997 OR p_supl_vr_from_last_update IS NOT NULL OR p_supl_vr_to_last_update IS NOT NULL
1998 THEN
1999
2000 -- Include the table in the list, and join to it.
2001
2002
2003 main_where_clause := main_where_clause
2004 ||' AND gs.spec_id IN'
2005 ||' ( SELECT spec_id fROM gmd_supplier_spec_vrs msvr, po_vendors mpv'
2006 ||' WHERE msvr.supplier_id = mpv.vendor_id';
2007
2008 IF p_supl_vr_start_date IS NOT NULL
2009 THEN
2010 g_supl_vr_start_date := p_supl_vr_start_date;
2011 main_where_clause := main_where_clause||' AND msvr.start_date >= :supl_vr_start_date';
2012 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supl_vr_start_date';
2013
2014 supl_vr_where_clause := supl_vr_where_clause||' AND svr.start_date >= :supl_vr_start_date';
2015 supl_vr_using_clause := supl_vr_using_clause||', gmd_outbound_apis_pub.g_supl_vr_start_date';
2016 END IF;
2017
2018 IF p_supl_vr_end_date IS NOT NULL
2019 THEN
2020 g_supl_vr_end_date := p_supl_vr_end_date;
2021 main_where_clause := main_where_clause||' AND msvr.end_date <= :supl_vr_end_date';
2022 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supl_vr_end_date';
2023
2024 supl_vr_where_clause := supl_vr_where_clause||' AND svr.end_date >= :supl_vr_end_date';
2025 supl_vr_using_clause := supl_vr_using_clause||', gmd_outbound_apis_pub.g_supl_vr_end_date';
2026 END IF;
2027
2028 IF p_supl_vr_status IS NOT NULL
2029 THEN
2030 g_supl_vr_status := p_supl_vr_status;
2031 main_where_clause := main_where_clause||' AND msvr.spec_vr_status = :supl_vr_status';
2032 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supl_vr_status';
2033
2034 supl_vr_where_clause := supl_vr_where_clause||' AND svr.status = :supl_vr_status';
2035 supl_vr_using_clause := supl_vr_using_clause||', gmd_outbound_apis_pub.g_supl_vr_status';
2036 END IF;
2037
2038 IF p_supl_vr_organization_code IS NOT NULL
2039 THEN
2040 g_supl_vr_organization_code := p_supl_vr_organization_code;
2041 main_where_clause := main_where_clause||' AND msvr.organization_id = (SELECT organization_id '
2042 ||'FROM mtl_organizations WHERE organization_code = :supl_vr_organization_code)';
2043 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supl_vr_organization_code';
2044
2045 supl_vr_where_clause := supl_vr_where_clause||' AND svr.organization_id = (SELECT organization_id '
2046 ||'FROM mtl_organizations WHERE organization_code = :supl_vr_organization_code)';
2047 supl_vr_using_clause := supl_vr_using_clause||', gmd_outbound_apis_pub.g_supl_vr_organization_code';
2048 END IF;
2049
2050 IF p_supl_vr_org_id IS NOT NULL
2051 THEN
2052 g_supl_vr_org_id := p_supl_vr_org_id;
2053 main_where_clause := main_where_clause||' AND msvr.org_id = :supl_vr_org_id';
2054 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supl_vr_org_id';
2055
2056 supl_vr_where_clause := supl_vr_where_clause||' AND svr.org_id = :supl_vr_org_id';
2057 supl_vr_using_clause := supl_vr_using_clause||', gmd_outbound_apis_pub.g_supl_vr_org_id';
2058 END IF;
2059
2060 IF p_supl_vr_coa_type IS NOT NULL
2061 THEN
2062 g_supl_vr_coa_type := p_supl_vr_coa_type;
2063 main_where_clause := main_where_clause||' AND msvr.coa_type = :supl_vr_coa_type';
2064 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supl_vr_coa_type';
2065
2066 supl_vr_where_clause := supl_vr_where_clause||' AND svr.coa_type = :supl_vr_coa_type';
2067 supl_vr_using_clause := supl_vr_using_clause||', gmd_outbound_apis_pub.g_supl_vr_coa_type';
2068 END IF;
2069
2070 IF p_supl_vr_coa_type IS NOT NULL
2071 THEN
2072 g_supl_vr_coa_type := p_supl_vr_coa_type;
2073 main_where_clause := main_where_clause||' AND msvr.coa_type = :supl_vr_coa_type';
2074 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supl_vr_coa_type';
2075
2076 supl_vr_where_clause := supl_vr_where_clause||' AND svr.coa_type = :supl_vr_coa_type';
2077 supl_vr_using_clause := supl_vr_using_clause||', gmd_outbound_apis_pub.g_supl_vr_coa_type';
2078 END IF;
2079
2080 IF p_supl_vr_supplier_id IS NOT NULL
2081 THEN
2082 g_supl_vr_supplier_id := p_supl_vr_supplier_id;
2083 main_where_clause := main_where_clause||' AND msvr.supplier_id = :supl_vr_supplier_id';
2084 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supl_vr_supplier_id';
2085
2086 supl_vr_where_clause := supl_vr_where_clause||' AND svr.supplier_id = :supl_vr_supplier_id';
2087 supl_vr_using_clause := supl_vr_using_clause||', gmd_outbound_apis_pub.g_supl_vr_supplier_id';
2088 END IF;
2089
2090 IF p_supl_vr_supplier IS NOT NULL
2091 THEN
2092 g_supl_vr_supplier := p_supl_vr_supplier;
2093 main_where_clause := main_where_clause||' AND mpv.segment1 = :supl_vr_supplier';
2094 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supl_vr_supplier';
2095
2096 supl_vr_where_clause := supl_vr_where_clause||' AND v.segment1 = :supl_vr_supplier';
2097 supl_vr_using_clause := supl_vr_using_clause||', gmd_outbound_apis_pub.g_supl_vr_supplier';
2098 END IF;
2099
2100 IF p_supl_vr_po_number IS NOT NULL
2101 THEN
2102 g_supl_vr_po_number := p_supl_vr_po_number;
2103 main_where_clause := main_where_clause||' AND msvr.po_line_id IN'
2104 ||' (SELECT pla.po_line_id FROM po_headers_all pha, po_lines_all pla'
2105 ||' WHERE pha.segment1 = :supl_vr_po_number'
2106 ||' AND pha.po_header_id = pla.po_header_id)';
2107 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supl_vr_po_number';
2108
2109 supl_vr_where_clause := supl_vr_where_clause||' AND svr.po_line_id IN'
2110 ||' (SELECT pla.po_line_id FROM po_headers_all pha, po_lines_all pla'
2111 ||' WHERE pha.segment1 = :supl_vr_po_number'
2112 ||' AND pha.po_header_id = pla.po_header_id)';
2113 supl_vr_using_clause := supl_vr_using_clause||', gmd_outbound_apis_pub.g_supl_vr_po_number';
2114 END IF;
2115
2116 IF p_supl_vr_po_id IS NOT NULL
2117 THEN
2118 g_supl_vr_po_id := p_supl_vr_po_id;
2119 main_where_clause := main_where_clause||' AND msvr.po_line_id IN'
2120 ||' (SELECT po_line_id FROM po_lines_all'
2121 ||' WHERE po_header_id = :supl_vr_po_id)';
2122 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supl_vr_po_id';
2123
2124 supl_vr_where_clause := supl_vr_where_clause||' AND svr.po_line_id IN'
2125 ||' (SELECT po_line_id FROM po_lines_all'
2126 ||' WHERE po_header_id = :supl_vr_po_id)';
2127 supl_vr_using_clause := supl_vr_using_clause||', gmd_outbound_apis_pub.g_supl_vr_po_id';
2128 END IF;
2129
2130 IF p_supl_vr_po_line_no IS NOT NULL
2131 THEN
2132 g_supl_vr_po_line_no := p_supl_vr_po_line_no;
2133 main_where_clause := main_where_clause||' AND msvr.po_line_id IN'
2134 ||' (SELECT po_line_id FROM po_lines_all'
2135 ||' WHERE line_num = :supl_vr_po_line_no)';
2136 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supl_vr_po_line_no';
2137
2138 supl_vr_where_clause := supl_vr_where_clause||' AND svr.po_line_id IN'
2139 ||' (SELECT po_line_id FROM po_lines_all'
2140 ||' WHERE line_num = :supl_vr_po_line_no)';
2141 supl_vr_using_clause := supl_vr_using_clause||', gmd_outbound_apis_pub.g_supl_vr_po_line_no';
2142 END IF;
2143
2144 IF p_supl_vr_po_line_id IS NOT NULL
2145 THEN
2146 g_supl_vr_po_line_id := p_supl_vr_po_line_id;
2147 main_where_clause := main_where_clause||' AND msvr.po_line_id =:supl_vr_po_line_id';
2148 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supl_vr_po_line_id';
2149
2150 supl_vr_where_clause := supl_vr_where_clause||' AND svr.po_line_id = :supl_vr_po_line_id';
2151 supl_vr_using_clause := supl_vr_using_clause||', gmd_outbound_apis_pub.g_supl_vr_po_line_id';
2152 END IF;
2153
2154 IF p_supl_vr_supplier_site_id IS NOT NULL
2155 THEN
2156 g_supl_vr_supplier_site_id := p_supl_vr_supplier_site_id;
2157 main_where_clause := main_where_clause||' AND msvr.supplier_site_id =:supl_vr_supplier_site_id';
2158 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supl_vr_supplier_site_id';
2159
2160 supl_vr_where_clause := supl_vr_where_clause||' AND svr.supplier_site_id = :supl_vr_supplier_site_id';
2161 supl_vr_using_clause := supl_vr_using_clause||', gmd_outbound_apis_pub.g_supl_vr_supplier_site_id';
2162 END IF;
2163
2164 IF p_supl_vr_supplier_site IS NOT NULL
2165 THEN
2166 g_supl_vr_supplier_site := p_supl_vr_supplier_site;
2167 main_where_clause := main_where_clause||' AND msvr.supplier_site_id = '
2168 ||' (SELECT vendor_site_id FROM po_vendor_sites_all'
2169 ||' WHERE vendor_site_code = :supl_vr_supplier_site';
2170 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supl_vr_supplier_site';
2171
2172 supl_vr_where_clause := supl_vr_where_clause||' AND svr.supplier_site_id = '
2173 ||' (SELECT vendor_site_id FROM po_vendor_sites_all'
2174 ||' WHERE vendor_site_code = :supl_vr_supplier_site';
2175 supl_vr_using_clause := supl_vr_using_clause||', gmd_outbound_apis_pub.g_supl_vr_supplier_site';
2176 END IF;
2177
2178 IF p_supl_vr_operating_unit IS NOT NULL
2179 THEN
2180 g_supl_vr_operating_unit := p_supl_vr_operating_unit;
2181 main_where_clause := main_where_clause||' AND msvr.org_id = '
2182 ||' (SELECT organization_id'
2183 ||' FROM hr_operating_units'
2184 ||' WHERE name = :supl_vr_operating_unit)';
2185 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supl_vr_operating_unit';
2186
2187 supl_vr_where_clause := supl_vr_where_clause||' AND svr.org_id = '
2188 ||' (SELECT organization_id'
2189 ||' FROM hr_operating_units'
2190 ||' WHERE name = :supl_vr_operating_unit)';
2191 supl_vr_using_clause := supl_vr_using_clause||', gmd_outbound_apis_pub.g_supl_vr_operating_unit';
2192
2193 END IF;
2194
2195 IF p_supl_vr_from_last_update IS NOT NULL
2196 THEN
2197 g_supl_vr_from_last_update := p_supl_vr_from_last_update;
2198 main_where_clause := main_where_clause||' AND msvr.last_update_date >= :supl_vr_from_last_update';
2199 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supl_vr_from_last_update';
2200
2201 supl_vr_where_clause := supl_vr_where_clause||' AND svr.last_update_date >= :supl_vr_from_last_update';
2202 supl_vr_using_clause := supl_vr_using_clause||', gmd_outbound_apis_pub.g_supl_vr_from_last_update';
2203 END IF;
2204
2205 IF p_supl_vr_to_last_update IS NOT NULL
2206 THEN
2207 g_supl_vr_to_last_update := p_supl_vr_to_last_update;
2208 main_where_clause := main_where_clause||' AND msvr.last_update_date <= :supl_vr_to_last_update';
2209 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supl_vr_to_last_update';
2210
2211 supl_vr_where_clause := supl_vr_where_clause||' AND svr.last_update_date <= :supl_vr_to_last_update';
2212 supl_vr_using_clause := supl_vr_using_clause||', gmd_outbound_apis_pub.g_supl_vr_to_last_update';
2213 END IF;
2214
2215 IF p_supl_vr_delete_mark IS NOT NULL
2216 THEN
2217 g_supl_vr_delete_mark := p_supl_vr_delete_mark;
2218 main_where_clause := main_where_clause||' AND msvr.delete_mark =:supl_vr_delete_mark';
2219 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supl_vr_delete_mark';
2220
2221 supl_vr_where_clause := supl_vr_where_clause||' AND svr.delete_mark = :supl_vr_delete_mark';
2222 supl_vr_using_clause := supl_vr_using_clause||', gmd_outbound_apis_pub.g_supl_vr_delete_mark';
2223 END IF;
2224
2225 main_where_clause := main_where_clause||' ) ';
2226
2227 END IF;
2228
2229 -- Sort out the GMD_INVENTORY_SPEC_VRS table's needs
2230
2231 IF p_inv_vr_start_date IS NOT NULL OR p_inv_vr_end_date IS NOT NULL OR p_inv_vr_status IS NOT NULL
2232 OR p_inv_vr_organization_code IS NOT NULL OR p_inv_vr_coa_type IS NOT NULL
2233 OR p_inv_vr_item_number IS NOT NULL OR p_inv_vr_inventory_item_id IS NOT NULL OR p_inv_vr_parent_lot_number IS NOT NULL
2234 OR p_inv_vr_lot_number IS NOT NULL OR p_inv_vr_subinventory IS NOT NULL OR p_inv_vr_locator IS NOT NULL
2235 OR p_inv_vr_locator_id IS NOT NULL OR p_inv_vr_sampling_plan IS NOT NULL OR p_inv_vr_sampling_plan_id IS NOT NULL
2236 OR p_inv_vr_delete_mark IS NOT NULL OR p_inv_vr_from_last_update IS NOT NULL OR p_inv_vr_to_last_update IS NOT NULL
2237 THEN
2238 -- Include the table in the list, and join to it.
2239
2240 main_where_clause := main_where_clause
2241 ||' AND gs.spec_id IN'
2242 ||' (SELECT mivr.spec_id FROM gmd_inventory_spec_vrs mivr'
2243 ||' WHERE 1=1';
2244
2245
2246 IF p_inv_vr_start_date IS NOT NULL
2247 THEN
2248 g_inv_vr_start_date := p_inv_vr_start_date;
2249 main_where_clause := main_where_clause||' AND mivr.start_date >= :inv_vr_start_date';
2250 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_inv_vr_start_date';
2251
2252 inv_vr_where_clause := inv_vr_where_clause||' AND ivr.start_date >= :inv_vr_start_date';
2253 inv_vr_using_clause := inv_vr_using_clause||', gmd_outbound_apis_pub.g_inv_vr_start_date';
2254 END IF;
2255
2256 IF p_inv_vr_end_date IS NOT NULL
2257 THEN
2258 g_inv_vr_end_date := p_inv_vr_end_date;
2259 main_where_clause := main_where_clause||' AND mivr.end_date <= :inv_vr_end_date';
2260 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_inv_vr_end_date';
2261
2262 inv_vr_where_clause := inv_vr_where_clause||' AND ivr.end_date <= :inv_vr_end_date';
2263 inv_vr_using_clause := inv_vr_using_clause||', gmd_outbound_apis_pub.g_inv_vr_end_date';
2264 END IF;
2265
2266 IF p_inv_vr_status IS NOT NULL
2267 THEN
2268 g_inv_vr_status := p_inv_vr_status;
2269 main_where_clause := main_where_clause||' AND mivr.spec_vr_status = :inv_vr_status';
2270 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_inv_vr_status';
2271
2272 inv_vr_where_clause := inv_vr_where_clause||' AND ivr.status = :inv_vr_status';
2273 inv_vr_using_clause := inv_vr_using_clause||', gmd_outbound_apis_pub.g_inv_vr_status';
2274 END IF;
2275
2276 IF p_inv_vr_organization_code IS NOT NULL
2277 THEN
2278 g_inv_vr_organization_code := p_inv_vr_organization_code;
2279 main_where_clause := main_where_clause||' AND mivr.organization_id = (SELECT organization_id '
2280 ||'FROM mtl_organizations WHERE organization_code = :inv_vr_organization_code)';
2281 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_inv_vr_organization_code';
2282
2283 inv_vr_where_clause := inv_vr_where_clause||' AND ivr.organization_id = (SELECT organization_id '
2284 ||'FROM mtl_organizations WHERE organization_code = :inv_vr_organization_code)';
2285 inv_vr_using_clause := inv_vr_using_clause||', gmd_outbound_apis_pub.g_inv_vr_organization_code';
2286 END IF;
2287
2288 IF p_inv_vr_inventory_item_id IS NOT NULL
2289 THEN
2290 g_inv_vr_inventory_item_id := p_inv_vr_inventory_item_id;
2291 main_where_clause := main_where_clause||' AND mivr.lot_number IN'
2292 ||' (SELECT lot_number FROM mtl_lot_numbers'
2293 ||' WHERE inventory_item_id = :inv_vr_inventory_item_id)';
2294 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_inv_vr_inventory_item_id';
2295
2296 inv_vr_where_clause := inv_vr_where_clause||' AND ivr.lot_number IN'
2297 ||' (SELECT lot_number FROM mtl_lot_numbers'
2298 ||' WHERE inventory_item_id = :inv_vr_inventory_item_id)';
2299 inv_vr_using_clause := inv_vr_using_clause||', gmd_outbound_apis_pub.g_inv_vr_inventory_item_id';
2300 END IF;
2301
2302 IF p_inv_vr_item_number IS NOT NULL
2303 THEN
2304 g_inv_vr_item_number := p_inv_vr_item_number;
2305 main_where_clause := main_where_clause||' AND mivr.lot_number IN'
2306 ||' (SELECT l.lot_number FROM mtl_lot_numbers l'
2307 ||' WHERE l.organization_id IN (SELECT organization_id FROM'
2308 ||' mtl_system_items_b_kfv WHERE concatenated_segments = :inv_vr_item_number'
2309 ||' AND inventory_item_id = l.inventory_item_id))';
2310
2311 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_inv_vr_item_number';
2312
2313 inv_vr_where_clause := inv_vr_where_clause||' AND ivr.lot_number IN'
2314 ||' (SELECT l.lot_number FROM mtl_lot_numbers l'
2315 ||' WHERE l.organization_id IN (SELECT organization_id FROM'
2316 ||' mtl_system_items_b_kfv WHERE concatenated_segments = :inv_vr_item_number'
2317 ||' AND inventory_item_id = l.inventory_item_id))';
2318 inv_vr_using_clause := inv_vr_using_clause||', gmd_outbound_apis_pub.g_inv_vr_item_number';
2319 END IF;
2320
2321 IF p_inv_vr_parent_lot_number IS NOT NULL
2322 THEN
2323 g_inv_vr_parent_lot_number := p_inv_vr_parent_lot_number;
2324 main_where_clause := main_where_clause||' AND mivr.parent_lot_number = :inv_vr_parent_lot_number';
2325 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_inv_vr_parent_lot_number';
2326
2327 inv_vr_where_clause := inv_vr_where_clause||' AND ivr.parent_lot_number = :inv_vr_parent_lot_number';
2328 inv_vr_using_clause := inv_vr_using_clause||', gmd_outbound_apis_pub.g_inv_vr_parent_lot_number';
2329 END IF;
2330
2331 IF p_inv_vr_lot_number IS NOT NULL
2332 THEN
2333 g_inv_vr_lot_number := p_inv_vr_lot_number;
2334 main_where_clause := main_where_clause||' AND mivr.lot_number = :inv_vr_lot_number';
2335 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_inv_vr_lot_number';
2336
2337 inv_vr_where_clause := inv_vr_where_clause||' AND ivr.lot_number = :inv_vr_lot_number';
2338 inv_vr_using_clause := inv_vr_using_clause||', gmd_outbound_apis_pub.g_inv_vr_lot_number';
2339 END IF;
2340
2341 IF p_inv_vr_subinventory IS NOT NULL
2342 THEN
2343 g_inv_vr_subinventory := p_inv_vr_subinventory;
2344 main_where_clause := main_where_clause||' AND mivr.subinventory = :inv_vr_subinventory';
2345 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_inv_vr_subinventory';
2346
2347 inv_vr_where_clause := inv_vr_where_clause||' AND ivr.subinventory = :inv_vr_subinventory';
2348 inv_vr_using_clause := inv_vr_using_clause||', gmd_outbound_apis_pub.g_inv_vr_subinventory';
2349 END IF;
2350
2351 IF p_inv_vr_locator IS NOT NULL
2352 THEN
2353 g_inv_vr_locator := p_inv_vr_locator;
2354 main_where_clause := main_where_clause||' AND mivr.locator_id = (SELECT inventory_location_id '
2355 ||'FROM mtl_item_locations_kfv WHERE concatenated_segments = :inv_vr_locator '
2356 ||'AND organization_id = mivr.organization_id)';
2357 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_inv_vr_locator';
2358
2359 inv_vr_where_clause := inv_vr_where_clause||' AND ivr.locator_id = (SELECT inventory_location_id '
2360 ||'FROM mtl_item_locations_kfv WHERE concatenated_segments = :inv_vr_locator '
2361 ||'AND organization_id = ivr.organization_id)';
2362 inv_vr_using_clause := inv_vr_using_clause||', gmd_outbound_apis_pub.g_inv_vr_locator';
2363 END IF;
2364
2365 IF p_inv_vr_locator_id IS NOT NULL
2366 THEN
2367 g_inv_vr_locator_id := p_inv_vr_locator_id;
2368 main_where_clause := main_where_clause||' AND mivr.locator_id = :inv_vr_locator_id';
2369 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_inv_vr_locator_id';
2370
2371 inv_vr_where_clause := inv_vr_where_clause||' AND ivr.locator_id = :inv_vr_locator_id';
2372 inv_vr_using_clause := inv_vr_using_clause||', gmd_outbound_apis_pub.g_inv_vr_locator_id';
2373 END IF;
2374
2375 IF p_inv_vr_sampling_plan_id IS NOT NULL
2376 THEN
2377 g_inv_vr_sampling_plan_id := p_inv_vr_sampling_plan_id;
2378 main_where_clause := main_where_clause||' AND mivr.sampling_plan_id = :inv_vr_sampling_plan_id';
2379 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_inv_vr_sampling_plan_id';
2380
2381 inv_vr_where_clause := inv_vr_where_clause||' AND ivr.sampling_plan_id = :inv_vr_sampling_plan_id';
2382 inv_vr_using_clause := inv_vr_using_clause||', gmd_outbound_apis_pub.g_inv_vr_sampling_plan_id';
2383 END IF;
2384
2385 IF p_inv_vr_from_last_update IS NOT NULL
2386 THEN
2387 g_inv_vr_from_last_update := p_inv_vr_from_last_update;
2388 main_where_clause := main_where_clause||' AND mivr.last_update_date >= :inv_vr_from_last_update';
2389 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_inv_vr_from_last_update';
2390
2391 inv_vr_where_clause := inv_vr_where_clause||' AND ivr.last_update_date >= :inv_vr_from_last_update';
2392 inv_vr_using_clause := inv_vr_using_clause||', gmd_outbound_apis_pub.g_inv_vr_from_last_update';
2393 END IF;
2394
2395 IF p_inv_vr_to_last_update IS NOT NULL
2396 THEN
2397 g_inv_vr_to_last_update := p_inv_vr_to_last_update;
2398 main_where_clause := main_where_clause||' AND mivr.last_update_date <= :inv_vr_to_last_update';
2399 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_inv_vr_to_last_update';
2400
2401 inv_vr_where_clause := inv_vr_where_clause||' AND ivr.last_update_date <= :inv_vr_to_last_update';
2402 inv_vr_using_clause := inv_vr_using_clause||', gmd_outbound_apis_pub.g_inv_vr_to_last_update';
2403 END IF;
2404
2405 IF p_inv_vr_delete_mark IS NOT NULL
2406 THEN
2407 g_inv_vr_delete_mark := p_inv_vr_delete_mark;
2408 main_where_clause := main_where_clause||' AND mivr.delete_mark =:inv_vr_delete_mark';
2409 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_inv_vr_delete_mark';
2410
2411 inv_vr_where_clause := inv_vr_where_clause||' AND ivr.delete_mark = :inv_vr_delete_mark';
2412 inv_vr_using_clause := inv_vr_using_clause||', gmd_outbound_apis_pub.g_inv_vr_delete_mark';
2413 END IF;
2414
2415 main_where_clause := main_where_clause||' ) ';
2416
2417 END IF;
2418
2419 -- START B3124291 Incorporated Mini-Pack K Features to Outboud APIs
2420
2421 -- Sort out the GMD_MONITORING_SPEC_VRS table's needs
2422
2423 IF p_mon_vr_status IS NOT NULL OR
2424 p_mon_vr_rule_type IS NOT NULL OR
2425 p_mon_vr_lct_organization_code IS NOT NULL OR
2426 p_mon_vr_subinventory IS NOT NULL OR
2427 p_mon_vr_locator IS NOT NULL OR
2428 p_mon_vr_locator_id IS NOT NULL OR
2429 p_mon_vr_rsr_organization_code IS NOT NULL OR
2430 p_mon_vr_resources IS NOT NULL OR
2431 p_mon_vr_resource_instance_id IS NOT NULL OR
2432 p_mon_vr_sampling_plan_id IS NOT NULL OR
2433 p_mon_vr_start_date IS NOT NULL OR
2434 p_mon_vr_end_date IS NOT NULL OR
2435 p_mon_vr_from_last_update_date IS NOT NULL OR
2436 p_mon_vr_to_last_update_date IS NOT NULL OR
2437 p_mon_vr_delete_mark IS NOT NULL
2438 THEN
2439 -- Include the table in the list, and join to it.
2440
2441 main_where_clause := main_where_clause
2442 ||' AND gs.spec_id IN'
2443 ||' (SELECT mmvr.spec_id FROM gmd_monitoring_spec_vrs mmvr'
2444 ||' WHERE 1=1';
2445
2446
2447 IF p_mon_vr_start_date IS NOT NULL
2448 THEN
2449 g_mon_vr_start_date := p_mon_vr_start_date;
2450 main_where_clause := main_where_clause||' AND mmvr.start_date >= :mon_vr_start_date';
2451 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_mon_vr_start_date';
2452
2453 mon_vr_where_clause := mon_vr_where_clause||' AND mvr.start_date >= :mon_vr_start_date';
2454 mon_vr_using_clause := mon_vr_using_clause||', gmd_outbound_apis_pub.g_mon_vr_start_date';
2455 END IF;
2456
2457 IF p_mon_vr_end_date IS NOT NULL
2458 THEN
2459 g_mon_vr_end_date := p_mon_vr_end_date;
2460 main_where_clause := main_where_clause||' AND mmvr.end_date <= :mon_vr_end_date';
2461 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_mon_vr_end_date';
2462
2463 mon_vr_where_clause := mon_vr_where_clause||' AND mvr.end_date <= :mon_vr_end_date';
2464 mon_vr_using_clause := mon_vr_using_clause||', gmd_outbound_apis_pub.g_mon_vr_end_date';
2465 END IF;
2466
2467 IF p_mon_vr_status IS NOT NULL
2468 THEN
2469 g_mon_vr_status := p_mon_vr_status;
2470 main_where_clause := main_where_clause||' AND mmvr.spec_vr_status = :mon_vr_status';
2471 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_mon_vr_status';
2472
2473 mon_vr_where_clause := mon_vr_where_clause||' AND mvr.spec_vr_status = :mon_vr_status';
2474 mon_vr_using_clause := mon_vr_using_clause||', gmd_outbound_apis_pub.g_mon_vr_status';
2475 END IF;
2476
2477 IF p_mon_vr_rule_type IS NOT NULL
2478 THEN
2479 g_mon_vr_rule_type := p_mon_vr_rule_type;
2480 main_where_clause := main_where_clause||' AND mmvr.rule_type = :mon_vr_rule_type';
2481 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_mon_vr_rule_type';
2482
2483 mon_vr_where_clause := mon_vr_where_clause||' AND mvr.rule_type = :mon_vr_rule_type';
2484 mon_vr_using_clause := mon_vr_using_clause||', gmd_outbound_apis_pub.g_mon_vr_rule_type';
2485 END IF;
2486
2487 IF p_mon_vr_lct_organization_code IS NOT NULL
2488 THEN
2489 g_mon_vr_lct_organization_code := p_mon_vr_lct_organization_code;
2490 main_where_clause := main_where_clause||' AND mmvr.locator_organization_id = (SELECT organization_id'
2491 ||' FROM mtl_organizations WHERE organization_code = :mon_vr_lct_organization_code)';
2492 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_mon_vr_lct_organization_code';
2493
2494 mon_vr_where_clause := mon_vr_where_clause||' AND mvr.locator_organization_id = (SELECT organization_id'
2495 ||' FROM mtl_organizations WHERE organization_code = :mon_vr_lct_organization_code)';
2496 mon_vr_using_clause := mon_vr_using_clause||', gmd_outbound_apis_pub.g_mon_vr_lct_organization_code';
2497 END IF;
2498
2499 IF p_mon_vr_subinventory IS NOT NULL
2500 THEN
2501 g_mon_vr_subinventory := p_mon_vr_subinventory;
2502 main_where_clause := main_where_clause||' AND mmvr.subinventory = :mon_vr_subinventory';
2503 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_mon_vr_subinventory';
2504
2505 mon_vr_where_clause := mon_vr_where_clause||' AND mvr.whse_code = :mon_vr_subinventory';
2506 mon_vr_using_clause := mon_vr_using_clause||', gmd_outbound_apis_pub.g_mon_vr_subinventory';
2507 END IF;
2508
2509 IF p_mon_vr_locator_id IS NOT NULL
2510 THEN
2511 g_mon_vr_locator_id := p_mon_vr_locator_id;
2512 main_where_clause := main_where_clause||' AND mmvr.locator_id = :mon_vr_locator_id';
2513 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_mon_vr_locator_id';
2514
2515 mon_vr_where_clause := mon_vr_where_clause||' AND mvr.locator_id = :mon_vr_locator_id';
2516 mon_vr_using_clause := mon_vr_using_clause||', gmd_outbound_apis_pub.g_mon_vr_locator_id';
2517 END IF;
2518
2519 IF p_mon_vr_locator IS NOT NULL
2520 THEN
2521 g_mon_vr_locator := p_mon_vr_locator;
2522 main_where_clause := main_where_clause||' AND mmvr.locator_id = (SELECT inventory_location_id'
2523 ||' FROM mtl_item_locations_kfv WHERE'
2524 ||' concatenated_segments = :mon_vr_locator'
2525 ||' AND organization_id = mmvr.locator_organization_id)';
2526 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_mon_vr_locator';
2527
2528 mon_vr_where_clause := mon_vr_where_clause||' AND mvr.locator_id = (SELECT inventory_location_id'
2529 ||' FROM mtl_item_locations_kfv WHERE'
2530 ||' concatenated_segments = :mon_vr_locator'
2531 ||' AND organization_id = mvr.locator_organization_id)';
2532 mon_vr_using_clause := mon_vr_using_clause||', gmd_outbound_apis_pub.g_mon_vr_locator';
2533 END IF;
2534
2535 IF p_mon_vr_rsr_organization_code IS NOT NULL
2536 THEN
2537 g_mon_vr_rsr_organization_code := p_mon_vr_rsr_organization_code;
2538 main_where_clause := main_where_clause||' AND mmvr.resource_organization_id = (SELECT organization_id'
2539 ||' FROM mtl_organizations WHERE organization_code = :mon_vr_rsr_organization_code)';
2540 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_mon_vr_rsr_organization_code';
2541
2542 mon_vr_where_clause := mon_vr_where_clause||' AND mvr.resource_organization_id = (SELECT organization_id'
2543 ||' FROM mtl_organizations WHERE organization_code = :mon_vr_rsr_organization_code)';
2544 mon_vr_using_clause := mon_vr_using_clause||', gmd_outbound_apis_pub.g_mon_vr_rsr_organization_code';
2545 END IF;
2546
2547 IF p_mon_vr_resources IS NOT NULL
2548 THEN
2549 g_mon_vr_resources := p_mon_vr_resources;
2550 main_where_clause := main_where_clause||' AND mmvr.resources = :mon_vr_resources';
2551 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_mon_vr_resources';
2552
2553 mon_vr_where_clause := mon_vr_where_clause||' AND mvr.resources = :mon_vr_resources';
2554 mon_vr_using_clause := mon_vr_using_clause||', gmd_outbound_apis_pub.g_mon_vr_resources';
2555 END IF;
2556
2557 IF p_mon_vr_resource_instance_id IS NOT NULL
2558 THEN
2559 g_mon_vr_resource_instance_id := p_mon_vr_resource_instance_id;
2560 main_where_clause := main_where_clause||' AND mmvr.resource_instance_id = :mon_vr_resource_instance_id';
2561 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_mon_vr_resource_instance_id';
2562
2563 mon_vr_where_clause := mon_vr_where_clause||' AND mvr.resource_instance_id = :mon_vr_resource_instance_id';
2564 mon_vr_using_clause := mon_vr_using_clause||', gmd_outbound_apis_pub.g_mon_vr_resource_instance_id';
2565 END IF;
2566
2567 IF p_mon_vr_sampling_plan_id IS NOT NULL
2568 THEN
2569 g_mon_vr_sampling_plan_id := p_mon_vr_sampling_plan_id;
2570 main_where_clause := main_where_clause||' AND mmvr.sampling_plan_id = :mon_vr_sampling_plan_id';
2571 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_mon_vr_sampling_plan_id';
2572
2573 mon_vr_where_clause := mon_vr_where_clause||' AND mvr.sampling_plan_id = :mon_vr_sampling_plan_id';
2574 mon_vr_using_clause := mon_vr_using_clause||', gmd_outbound_apis_pub.g_mon_vr_sampling_plan_id';
2575 END IF;
2576
2577 IF p_mon_vr_from_last_update_date IS NOT NULL
2578 THEN
2579 g_mon_vr_from_last_update_date := p_mon_vr_from_last_update_date;
2580 main_where_clause := main_where_clause||' AND mmvr.last_update_date >= :mon_vr_from_last_update_date';
2581 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_mon_vr_from_last_update_date';
2582
2583 mon_vr_where_clause := mon_vr_where_clause||' AND mvr.last_update_date >= :mon_vr_from_last_update_date';
2584 mon_vr_using_clause := mon_vr_using_clause||', gmd_outbound_apis_pub.g_mon_vr_from_last_update_date';
2585 END IF;
2586
2587 IF p_mon_vr_to_last_update_date IS NOT NULL
2588 THEN
2589 g_mon_vr_to_last_update_date := p_mon_vr_to_last_update_date;
2590 main_where_clause := main_where_clause||' AND mmvr.last_update_date <= :mon_vr_to_last_update_date';
2591 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_mon_vr_to_last_update_date';
2592
2593 mon_vr_where_clause := mon_vr_where_clause||' AND mvr.last_update_date <= :mon_vr_to_last_update_date';
2594 mon_vr_using_clause := mon_vr_using_clause||', gmd_outbound_apis_pub.g_mon_vr_to_last_update_date';
2595 END IF;
2596
2597 IF p_mon_vr_delete_mark IS NOT NULL
2598 THEN
2599 g_mon_vr_delete_mark := p_mon_vr_delete_mark;
2600 main_where_clause := main_where_clause||' AND mmvr.delete_mark =:mon_vr_delete_mark';
2601 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_mon_vr_delete_mark';
2602
2603 mon_vr_where_clause := mon_vr_where_clause||' AND mvr.delete_mark = :mon_vr_delete_mark';
2604 mon_vr_using_clause := mon_vr_using_clause||', gmd_outbound_apis_pub.g_mon_vr_delete_mark';
2605 END IF;
2606
2607 main_where_clause := main_where_clause||' ) ';
2608
2609 END IF;
2610 -- END B3124291 Incorporated Mini-Pack K Features to Outboud APIs
2611
2612
2613 sql_statement := 'SELECT system.gmd_specification_rec_type' -- 5284247
2614 ||'('||main_column_list
2615 ||', CAST'
2616 ||' ( MULTISET'
2617 ||' ( SELECT ' ||spec_test_column_list
2618 ||' FROM '||spec_test_table_list
2619 ||' WHERE '||spec_test_where_clause
2620 ||' ) AS system.gmd_spec_tests_tab_type' -- 5284242
2621 ||' )'
2622 ||', CAST'
2623 ||' ( MULTISET'
2624 ||' ( SELECT ' ||cust_vr_column_list
2625 ||' FROM '||cust_vr_table_list
2626 ||' WHERE '||cust_vr_where_clause
2627 ||' ) AS system.gmd_cust_spec_vrs_tab_type' -- 5284242
2628 ||' )'
2629 ||', CAST'
2630 ||' ( MULTISET'
2631 ||' ( SELECT ' ||wip_vr_column_list
2632 ||' FROM '||wip_vr_table_list
2633 ||' WHERE '||wip_vr_where_clause
2634 ||' ) AS system.gmd_wip_spec_vrs_tab_type' -- 5284242
2635 ||' )'
2636 ||', CAST'
2637 ||' ( MULTISET'
2638 ||' ( SELECT ' ||supl_vr_column_list
2639 ||' FROM '||supl_vr_table_list
2640 ||' WHERE '||supl_vr_where_clause
2641 ||' ) AS system.gmd_supl_spec_vrs_tab_type' -- 5284242
2642 ||' )'
2643 ||', CAST'
2644 ||' ( MULTISET'
2645 ||' ( SELECT ' ||inv_vr_column_list
2646 ||' FROM '||inv_vr_table_list
2647 ||' WHERE '||inv_vr_where_clause
2648 ||' ) AS system.gmd_inv_spec_vrs_tab_type' -- 5284242
2649 ||' )'
2650 -- START B3124291 Incorporated Mini-Pack K Features to Outboud APIs
2651 ||', CAST'
2652 ||' ( MULTISET'
2653 ||' ( SELECT ' ||mon_vr_column_list
2654 ||' FROM '||mon_vr_table_list
2655 ||' WHERE '||mon_vr_where_clause
2656 ||' ) AS system.gmd_mon_spec_vrs_tab_type' -- 5284242
2657 ||' )'
2658 -- END B3124291 Incorporated Mini-Pack K Features to Outboud APIs
2659 ||')'
2660 ||' FROM ' ||main_table_list
2661 ||' WHERE '||main_where_clause;
2662
2663 -- That's more or less the job done. We just need to tell the system where to store the data
2664 -- and assemble the USING clause. Note thatthe main_using_clause is last in the list as it
2665 -- appears last in the query.
2666
2667 main_into_clause := ' BULK COLLECT INTO gmd_outbound_apis_pub.g_specifications_table ';
2668
2669 main_using_clause := ' USING '||spec_test_using_clause
2670 ||','||cust_vr_using_clause
2671 ||','||wip_vr_using_clause
2672 ||','||supl_vr_using_clause
2673 ||','||inv_vr_using_clause
2674 -- START B3124291 Incorporated Mini-Pack K Features to Outboud APIs
2675 ||','||mon_vr_using_clause
2676 -- END B3124291 Incorporated Mini-Pack K Features to Outboud APIs
2677 ||','||main_using_clause;
2678
2679
2680 main_execution_string := 'BEGIN EXECUTE IMMEDIATE '
2681 ||''''
2682 ||sql_statement
2683 ||''''
2684 ||main_into_clause
2685 ||main_using_clause
2686 ||'; END;';
2687
2688
2689 gme_debug.put_line('The sql statement is:');
2690 i:= 1;
2691 LOOP
2692 gme_debug.put_line(substr(main_execution_string, i, 100));
2693 EXIT WHEN i> LENGTH(main_execution_string);
2694 i := i+100;
2695 END LOOP;
2696 gme_debug.put_line('Executing string');
2697
2698 -- problem here
2699 -- check the s=rec type on d/b with the list here
2700
2701 EXECUTE IMMEDIATE main_execution_string;
2702 gme_debug.put_line('SQL string execution comleted');
2703 -- Main retrieval done, now just fill in any blanks
2704
2705 IF g_specifications_table.count > 0
2706 THEN
2707 FOR i in 1.. g_specifications_table.count
2708 LOOP
2709 IF g_specifications_table(i).owner_organization_id IS NOT NULL
2710 AND g_specifications_table(i).inventory_item_id IS NOT NULL THEN
2711 SELECT concatenated_segments INTO g_specifications_table(i).item_number
2712 FROM mtl_system_items_b_kfv
2713 WHERE organization_id = g_specifications_table(i).owner_organization_id
2714 AND inventory_item_id = g_specifications_table(i).inventory_item_id;
2715 END IF;
2716 END LOOP;
2717 END IF;
2718
2719 x_specifications_tbl := gmd_outbound_apis_pub.g_specifications_table;
2720 x_return_status := FND_API.G_RET_STS_SUCCESS;
2721
2722 END IF;
2723 FND_MSG_PUB.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
2724
2725 EXCEPTION
2726 WHEN OTHERS
2727 THEN
2728
2729 FND_MESSAGE.SET_NAME('GMD',SQLCODE);
2730 FND_MSG_PUB.Add;
2731 FND_MSG_PUB.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
2732 x_return_status := FND_API.G_RET_STS_ERROR;
2733 END fetch_spec_vrs;
2734
2735
2736 PROCEDURE fetch_results
2737 ( p_api_version IN NUMBER
2738 , p_init_msg_list IN VARCHAR2 DEFAULT FND_API.G_FALSE
2739 , p_user_name IN VARCHAR2
2740 , p_orgn_code IN VARCHAR2 DEFAULT NULL
2741 , p_from_sample_no IN VARCHAR2 DEFAULT NULL
2742 , p_to_sample_no IN VARCHAR2 DEFAULT NULL
2743 , p_sample_id IN NUMBER DEFAULT NULL
2744 , p_from_result_date IN DATE DEFAULT NULL
2745 , p_to_result_date IN DATE DEFAULT NULL
2746 , p_sample_disposition IN VARCHAR2 DEFAULT NULL
2747 , p_in_spec_ind IN VARCHAR2 DEFAULT NULL
2748 , p_qc_lab_orgn_code IN VARCHAR2 DEFAULT NULL
2749 , p_evaluation_ind IN VARCHAR2 DEFAULT NULL
2750 , p_tester IN VARCHAR2 DEFAULT NULL
2751 , p_tester_id IN NUMBER DEFAULT NULL
2752 , p_test_provider_id IN NUMBER DEFAULT NULL
2753 , p_delete_mark IN NUMBER DEFAULT NULL
2754 , p_from_last_update_date IN DATE DEFAULT NULL
2755 , p_to_last_update_date IN DATE DEFAULT NULL
2756 , p_planned_resource IN VARCHAR2 DEFAULT NULL
2757 , p_planned_resource_instance IN NUMBER DEFAULT NULL
2758 , p_actual_resource IN VARCHAR2 DEFAULT NULL
2759 , p_actual_resource_instance IN NUMBER DEFAULT NULL
2760 , p_from_planned_result_date IN DATE DEFAULT NULL
2761 , p_to_planned_result_date IN DATE DEFAULT NULL
2762 , p_from_test_by_date IN DATE DEFAULT NULL
2763 , p_to_test_by_date IN DATE DEFAULT NULL
2764 , p_reserve_sample_id IN NUMBER DEFAULT NULL
2765 , x_results_table OUT NOCOPY system.gmd_results_tab_type
2766 , x_return_status OUT NOCOPY VARCHAR2
2767 , x_msg_count OUT NOCOPY NUMBER
2768 , x_msg_data OUT NOCOPY VARCHAR2
2769 )
2770 IS
2771
2772 sql_statement VARCHAR2(2000);
2773 column_list VARCHAR2(2000);
2774 table_list VARCHAR2(2000);
2775 where_clause VARCHAR2(2000);
2776 into_clause VARCHAR2(2000);
2777 using_clause VARCHAR2(2000);
2778 execution_string VARCHAR2(10000);
2779 row_count NUMBER;
2780 i NUMBER;
2781
2782
2783 CURSOR item_cursor (cp_inventory_item_id NUMBER) IS
2784 SELECT concatenated_segments FROM mtl_system_items_kfv
2785 WHERE inventory_item_id = cp_inventory_item_id;
2786
2787 l_api_name VARCHAR2(100) := 'fetch_results';
2788
2789 BEGIN
2790
2791 gme_debug.put_line('Enter GMD_OUTBOUND_APIS_PUB.FETCH_RESULTS API');
2792
2793 IF NOT FND_API.Compatible_API_CALL
2794 (gmd_outbound_apis_pub.api_version, p_api_version, l_api_name,'GMD_OUTBOUND_APIS_PUB')
2795 OR NOT initialized_ok(p_user_name)
2796 THEN
2797 Raise FND_API.G_EXC_UNEXPECTED_ERROR;
2798 ELSE
2799 gme_debug.put_line('Starting FETCH_RESULTS processing');
2800 /* Initialize message list if p_int_msg_list is set TRUE. */
2801 IF FND_API.to_boolean(p_init_msg_list)
2802 THEN
2803 FND_MSG_PUB.Initialize;
2804 END IF;
2805
2806 -- Start construction the select.
2807
2808 gme_debug.put_line('Begin constructing SELECT statement');
2809 sql_statement := 'SELECT ';
2810
2811
2812 column_list := 'system.gmd_results_rec_type( r.update_instance_id, r.result_id, ' -- 5346480 add system.
2813 ||'r.sample_id, gs.sample_no, r.test_id, gt.test_code, '
2814 ||'r.test_replicate_cnt, r.lab_organization_id, r.result_value_num, '
2815 ||'r.result_date, r.test_kit_inv_item_id, NULL, '
2816 ||'r.test_kit_lot_number , r.tester, r.tester_id, '
2817 ||'r.test_provider_id, r.ad_hoc_print_on_coa_ind, r.seq, '
2818 ||'r.result_value_char, r.test_provider_code, r.assay_retest, '
2819 ||'gsr.in_spec_ind, gesd.disposition, gsr.evaluation_ind, '
2820 ||'r.planned_resource, r.planned_resource_instance, '
2821 ||'r.actual_resource, r.actual_resource_instance, '
2822 ||'r.planned_result_date, r.test_by_date, '
2823 ||'r.delete_mark, r.text_code, r.attribute_category, r.attribute1, '
2824 ||'r.attribute2, r.attribute3, r.attribute4, r.attribute5, '
2825 ||'r.attribute6, r.attribute7, r.attribute8, r.attribute9, '
2826 ||'r.attribute10, r.attribute11, r.attribute12, r.attribute13, '
2827 ||'r.attribute14, r.attribute15, r.attribute16, r.attribute17, '
2828 ||'r.attribute18, r.attribute19, r.attribute20, r.attribute21, '
2829 ||'r.attribute22, r.attribute23, r.attribute24, r.attribute25, '
2830 ||'r.attribute26, r.attribute27, r.attribute28, r.attribute29, '
2831 ||'r.attribute30, r.creation_date, '
2832 ||'r.created_by, fu1.user_name, r.last_updated_by, fu2.user_name, '
2833 ||'r.last_update_date, r.last_update_login, '
2834 ||'r.test_qty, r.test_qty_uom, '
2835 ||'r.reserve_sample_id, r.consumed_qty, '
2836 ||'r.parent_result_id, r.test_method_id )';
2837
2838
2839 table_list := 'FROM gmd_results r, gmd_samples gs, gmd_qc_tests_b gt,'
2840 ||'gmd_spec_results gsr, gmd_event_spec_disp gesd,'
2841 ||'fnd_user fu1, fnd_user fu2 ';
2842
2843
2844 -- We now have the first three strings built. Here comes the good bit: building the where and us
2845 -- clauses and inserting the bind variables and values.
2846
2847 -- We will not make any attempt to guess what the user had in mind, so if (for example) they spe
2848 -- an item_id and an item_no and these two don't stack up, so be it. The query will simply fail
2849 -- return anything.
2850
2851 where_clause := 'WHERE r.sample_id = gs.sample_id and r.test_id = gt.test_id '
2852 ||'AND r.result_id = gsr.result_id '
2853 ||'AND gsr.event_spec_disp_id = gesd.event_spec_disp_id '
2854 ||'AND gesd.spec_used_for_lot_attrib_ind = ''''Y'''' '
2855 ||'AND fu1.user_id = r.created_by AND fu2.user_id = r.last_updated_by and 1=:dummy ';
2856
2857 using_clause := ' USING 1 ';
2858
2859 -- Work down the parameter list and append conditions, bind variables and bind values.
2860
2861 IF p_orgn_code IS NOT NULL /*NSRIVAST, INVCONV*/
2862 THEN
2863 gmd_outbound_apis_pub.g_orgn_code := p_orgn_code;
2864 where_clause := where_clause||'AND gs.organization_id = (SELECT organization_id'
2865 || ' FROM mtl_organizations WHERE organization_code = :orgn_code)';
2866 using_clause := using_clause||', gmd_outbound_apis_pub.g_orgn_code ';
2867 END IF;
2868
2869 IF p_from_sample_no IS NOT NULL
2870 THEN
2871 gmd_outbound_apis_pub.g_from_sample_no := p_from_sample_no;
2872 where_clause := where_clause||'AND gs.sample_no >= :sample_no ';
2873 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_sample_no ';
2874 END IF;
2875
2876 IF p_to_sample_no IS NOT NULL
2877 THEN
2878 gmd_outbound_apis_pub.g_to_sample_no := p_to_sample_no;
2879 where_clause := where_clause||'AND gs.sample_no <= :sample_no ';
2880 using_clause := using_clause||', gmd_outbound_apis_pub.g_to_sample_no ';
2881 END IF;
2882
2883 IF p_sample_id IS NOT NULL
2884 THEN
2885 gmd_outbound_apis_pub.g_sample_id := p_sample_id;
2886 where_clause := where_clause||'AND gs.sample_id = :sample_id ';
2887 using_clause := using_clause||', gmd_outbound_apis_pub.g_sample_id ';
2888 END IF;
2889
2890 IF p_from_result_date IS NOT NULL
2891 THEN
2892 gmd_outbound_apis_pub.g_from_result_date := p_from_result_date ;
2893 where_clause := where_clause||'AND r.result_date >= :from_result_date ';
2894 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_result_date ';
2895 END IF;
2896
2897 IF p_to_result_date IS NOT NULL
2898 THEN
2899 gmd_outbound_apis_pub.g_to_result_date := p_to_result_date ;
2900 where_clause := where_clause||'AND r.result_date <= :to_result_date ';
2901 using_clause := using_clause||', gmd_outbound_apis_pub.g_to_result_date ';
2902 END IF;
2903
2904 IF p_sample_disposition IS NOT NULL
2905 THEN
2906 gmd_outbound_apis_pub.g_sample_disposition := p_sample_disposition ;
2907 where_clause := where_clause||'AND gesd.disposition = :disposition ';
2908 using_clause := using_clause||', gmd_outbound_apis_pub.g_sample_disposition ';
2909 END IF;
2910
2911 IF p_in_spec_ind IS NOT NULL
2912 THEN
2913 gmd_outbound_apis_pub.g_in_spec_ind := p_in_spec_ind;
2914 where_clause := where_clause||'AND gsr.in_spec_ind = :in_spec_ind ';
2915 using_clause := using_clause||', gmd_outbound_apis_pub.g_in_spec_ind ';
2916 END IF;
2917
2918 IF p_qc_lab_orgn_code IS NOT NULL /*NSRIVAST, INVCONV*/
2919 THEN
2920 gmd_outbound_apis_pub.g_qc_lab_orgn_code := p_qc_lab_orgn_code ;
2921 where_clause := where_clause||'AND r.lab_organization_id = (SELECT organization_id'
2922 || ' FROM mtl_organizations WHERE organization_code = :lab_orgn_code)';
2923 using_clause := using_clause||', gmd_outbound_apis_pub.g_qc_lab_orgn_code ';
2924 END IF;
2925
2926 IF p_evaluation_ind IS NOT NULL
2927 THEN
2928 gmd_outbound_apis_pub.g_evaluation_ind := p_evaluation_ind ;
2929 where_clause := where_clause||'AND gsr.evaluation_ind = :evaluation_ind ';
2930 using_clause := using_clause||', gmd_outbound_apis_pub.g_evaluation_ind ';
2931 END IF;
2932
2933 -- BUG 3078568 target fnd_user for tester
2934 IF p_tester IS NOT NULL
2935 THEN
2936 table_list := table_list ||', fnd_user fu3 ';
2937 where_clause := where_clause ||'AND r.tester_id = fu3.user_id ';
2938
2939 gmd_outbound_apis_pub.g_tester := p_tester;
2940 where_clause := where_clause||'AND fu3.user_name = :tester ';
2941 using_clause := using_clause||', gmd_outbound_apis_pub.g_tester ';
2942 END IF;
2943
2944 IF p_tester_id IS NOT NULL
2945 THEN
2946 gmd_outbound_apis_pub.g_tester_id := p_tester_id ;
2947 where_clause := where_clause||'AND r.tester_id = :tester_id ';
2948 using_clause := using_clause||', gmd_outbound_apis_pub.g_tester_id ';
2949 END IF;
2950
2951 IF p_test_provider_id IS NOT NULL
2952 THEN
2953 gmd_outbound_apis_pub.g_test_provider_id := p_test_provider_id ;
2954 where_clause := where_clause||'AND r.test_provider_id = :test_provider_id ';
2955 using_clause := using_clause||', gmd_outbound_apis_pub.g_test_provider_id ';
2956 END IF;
2957
2958 IF p_delete_mark IS NOT NULL
2959 THEN
2960 gmd_outbound_apis_pub.g_delete_mark := p_delete_mark ;
2961 where_clause := where_clause||'AND r.delete_mark = :delete_mark ';
2962 using_clause := using_clause||', gmd_outbound_apis_pub.g_delete_mark ';
2963 END IF;
2964
2965 IF p_from_last_update_date IS NOT NULL
2966 THEN
2967 gmd_outbound_apis_pub.g_from_last_update_date := p_from_last_update_date;
2968 where_clause := where_clause||'AND r.last_update_date >= :from_last_update_date ';
2969 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_last_update_date ';
2970 END IF;
2971
2972 IF p_to_last_update_date IS NOT NULL
2973 THEN
2974 gmd_outbound_apis_pub.g_to_last_update_date := p_to_last_update_date;
2975 where_clause := where_clause||'AND r.last_update_date <= :to_last_update_date ';
2976 using_clause := using_clause||', gmd_outbound_apis_pub.g_to_last_update_date ';
2977 END IF;
2978
2979 IF p_planned_resource IS NOT NULL
2980 THEN
2981 gmd_outbound_apis_pub.g_planned_resource := p_planned_resource;
2982 where_clause := where_clause||'AND gsr.planned_resource = :planned_resource ';
2983 using_clause := using_clause||', gmd_outbound_apis_pub.g_planned_resource ';
2984 END IF;
2985
2986 IF p_planned_resource_instance IS NOT NULL
2987 THEN
2988 gmd_outbound_apis_pub.g_planned_resource_instance := p_planned_resource_instance;
2989 where_clause := where_clause||'AND gsr.planned_resource_instance = :planned_resource_instance ';
2990 using_clause := using_clause||', gmd_outbound_apis_pub.g_planned_resource_instance ';
2991 END IF;
2992
2993 IF p_actual_resource IS NOT NULL
2994 THEN
2995 gmd_outbound_apis_pub.g_actual_resource := p_actual_resource;
2996 where_clause := where_clause||'AND gsr.actual_resource = :actual_resource ';
2997 using_clause := using_clause||', gmd_outbound_apis_pub.g_actual_resource ';
2998 END IF;
2999
3000 IF p_actual_resource_instance IS NOT NULL
3001 THEN
3002 gmd_outbound_apis_pub.g_actual_resource_instance := p_actual_resource_instance;
3003 where_clause := where_clause||'AND gsr.actual_resource_instance = :actual_resource_instance ';
3004 using_clause := using_clause||', gmd_outbound_apis_pub.g_actual_resource_instance ';
3005 END IF;
3006
3007 IF p_from_planned_result_date IS NOT NULL
3008 THEN
3009 gmd_outbound_apis_pub.g_from_planned_result_date := p_from_planned_result_date;
3010 where_clause := where_clause||'AND gsr.planned_result_date >= :from_planned_result_date ';
3011 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_planned_result_date ';
3012 END IF;
3013
3014 IF p_to_planned_result_date IS NOT NULL
3015 THEN
3016 gmd_outbound_apis_pub.g_to_planned_result_date := p_to_planned_result_date;
3017 where_clause := where_clause||'AND gsr.planned_result_date <= :to_planned_result_date ';
3018 using_clause := using_clause||', gmd_outbound_apis_pub.g_to_planned_result_date ';
3019 END IF;
3020
3021 IF p_from_test_by_date IS NOT NULL
3022 THEN
3023 gmd_outbound_apis_pub.g_from_test_by_date := p_from_test_by_date;
3024 where_clause := where_clause||'AND gsr.test_by_date >= :from_test_by_date ';
3025 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_test_by_date ';
3026 END IF;
3027
3028 IF p_to_test_by_date IS NOT NULL
3029 THEN
3030 gmd_outbound_apis_pub.g_to_test_by_date := p_to_test_by_date;
3031 where_clause := where_clause||'AND gsr.test_by_date <= :to_test_by_date ';
3032 using_clause := using_clause||', gmd_outbound_apis_pub.g_to_test_by_date ';
3033 END IF;
3034
3035 IF p_reserve_sample_id IS NOT NULL
3036 THEN
3037 gmd_outbound_apis_pub.g_reserve_sample_id := p_reserve_sample_id;
3038 where_clause := where_clause||'AND r.reserve_sample_id = :reserve_sample_id ';
3039 using_clause := using_clause||', gmd_outbound_apis_pub.g_reserve_sample_id ';
3040 END IF;
3041
3042 -- That's more or less the job done. We just need to tell the system where to store the data
3043
3044 into_clause := ' BULK COLLECT INTO gmd_outbound_apis_pub.g_results_table ';
3045
3046
3047 execution_string := 'BEGIN EXECUTE IMMEDIATE '
3048 ||''''
3049 ||sql_statement||column_list||table_list||where_clause
3050 ||''''
3051 ||into_clause
3052 ||using_clause
3053 ||'; END;';
3054
3055 gme_debug.put_line('The sql statement is:');
3056 i:= 1;
3057 LOOP
3058 gme_debug.put_line(substr(execution_string, i, 100));
3059 EXIT WHEN i> LENGTH(execution_string);
3060 i := i+100;
3061 END LOOP;
3062 gme_debug.put_line('Executing string');
3063
3064 EXECUTE IMMEDIATE execution_string;
3065
3066 FOR i IN 1..g_results_table.COUNT
3067 LOOP
3068
3069 IF g_results_table(i).test_kit_inv_item_id IS NOT NULL
3070 THEN
3071 gme_debug.put_line('select from mtl_system_items_kfv using inventory_item_id of '|| g_results_table(i).test_kit_inv_item_id);
3072 SELECT concatenated_segments
3073 INTO g_results_table(i).test_kit_inv_item_number
3074 FROM mtl_system_items_kfv
3075 WHERE inventory_item_id = g_results_table(i).test_kit_inv_item_id
3076 and rownum = 1; -- 5346480 rework
3077 END IF;
3078
3079 -- BUG 3078568 - populate tester from tester_id
3080 IF g_results_table(i).tester_id IS NOT NULL
3081 THEN
3082 gme_debug.put_line('select from fnd_user using user_id of '
3083 || g_results_table(i).tester_id);
3084 SELECT user_name
3085 INTO g_results_table(i).tester
3086 FROM fnd_user
3087 WHERE user_id = g_results_table(i).tester_id;
3088 END IF;
3089
3090 END LOOP;
3091
3092
3093 gme_debug.put_line('Returning table to caller');
3094 x_results_table := gmd_outbound_apis_pub.g_results_table;
3095 x_return_status := FND_API.G_RET_STS_SUCCESS;
3096
3097 END IF;
3098
3099 FND_MSG_PUB.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
3100 gme_debug.put_line('Finished FETCH_RESULTS');
3101
3102 EXCEPTION
3103 WHEN OTHERS
3104 THEN
3105 FND_MESSAGE.SET_NAME('GMD',SQLCODE);
3106 FND_MSG_PUB.Add;
3107 FND_MSG_PUB.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
3108 x_return_status := FND_API.G_RET_STS_ERROR;
3109
3110 END fetch_results;
3111
3112
3113 PROCEDURE fetch_composite_results
3114 ( p_api_version IN NUMBER
3115 , p_init_msg_list IN VARCHAR2 DEFAULT FND_API.G_FALSE
3116 , p_user_name IN VARCHAR2
3117 , p_sampling_event_id IN NUMBER DEFAULT NULL
3118 , p_composite_result_disposition IN VARCHAR2 DEFAULT NULL
3119 , p_from_item_number IN VARCHAR2 DEFAULT NULL /*NSRIVAST, INVCONV*/
3120 , p_to_item_number IN VARCHAR2 DEFAULT NULL /*NSRIVAST, INVCONV*/
3121 , p_inventory_item_id IN NUMBER DEFAULT NULL /*NSRIVAST, INVCONV*/
3122 , p_from_lot_number IN VARCHAR2 DEFAULT NULL /*NSRIVAST, INVCONV*/
3123 , p_to_lot_number IN VARCHAR2 DEFAULT NULL /*NSRIVAST, INVCONV*/
3124 , p_lot_number IN VARCHAR2 DEFAULT NULL /*NSRIVAST, INVCONV*/
3125 , p_from_last_update_date IN DATE DEFAULT NULL
3126 , p_to_last_update_date IN DATE DEFAULT NULL
3127 , p_delete_mark IN NUMBER DEFAULT NULL
3128 , x_composite_results_table OUT NOCOPY system.gmd_composite_results_tab_type
3129 , x_return_status OUT NOCOPY VARCHAR2
3130 , x_msg_count OUT NOCOPY NUMBER
3131 , x_msg_data OUT NOCOPY VARCHAR2
3132 )
3133 IS
3134
3135 sql_statement VARCHAR2(2000);
3136 column_list VARCHAR2(2000);
3137 table_list VARCHAR2(2000);
3138 where_clause VARCHAR2(2000);
3139 into_clause VARCHAR2(2000);
3140 using_clause VARCHAR2(2000);
3141 execution_string VARCHAR2(10000);
3142 row_count NUMBER;
3143 i NUMBER;
3144 l_api_name VARCHAR2(100) := 'fetch_composite_results';
3145
3146 BEGIN
3147
3148 gme_debug.put_line('Enter GMD_OUTBOUND_APIS_PUB.FETCH_COMPOSITE_RESULTS API');
3149
3150 IF NOT FND_API.Compatible_API_CALL
3151 (gmd_outbound_apis_pub.api_version, p_api_version, l_api_name,'GMD_OUTBOUND_APIS_PUB')
3152 OR NOT initialized_ok(p_user_name)
3153 THEN
3154 Raise FND_API.G_EXC_UNEXPECTED_ERROR;
3155 ELSE
3156
3157 gme_debug.put_line('Starting FETCH_COMPOSITE_RESULTS processing');
3158 /* Initialize message list if p_int_msg_list is set TRUE. */
3159 IF FND_API.to_boolean(p_init_msg_list)
3160 THEN
3161 FND_MSG_PUB.Initialize;
3162 END IF;
3163
3164 -- Start construction the select.
3165
3166 gme_debug.put_line('Begin constructing SELECT statement');
3167 sql_statement := 'SELECT ';
3168
3169 IF (p_from_item_number IS NOT NULL OR p_to_item_number IS NOT NULL or p_inventory_item_id is NOT NULL) AND
3170 (p_lot_number is NOT NULL)
3171 THEN
3172 column_list := 'system.gmd_composite_results_rec_type( gcr.composite_result_id, gcr.test_id, '
3173 ||'gcr.mean, gcr.mode_num, gcr.mode_char, gcr.low_num, gcr.high_num , '
3174 ||'gcr.range, gcr.standard_deviation, gcr.sample_total, '
3175 ||'gcr.sample_cnt_used, gcr.non_validated_result, '
3176 ||'gcr.high_char, gcr.low_char, gcr.median_char, gcr.median_num, '
3177 ||'gcr.composite_spec_disp_id, gcr.in_spec_ind, gcr.wf_response, '
3178 ||'gcr.value_in_report_precision, gcsd.disposition, '
3179 ||'gse.inventory_item_id, msi.concatenated_segments, gse.lot_number, '
3180 ||'gcr.delete_mark, gcr.text_code, gcr.attribute_category, gcr.attribute1, '
3181 ||'gcr.attribute2, gcr.attribute3, gcr.attribute4, gcr.attribute5, '
3182 ||'gcr.attribute6, gcr.attribute7, gcr.attribute8, gcr.attribute9, '
3183 ||'gcr.attribute10, gcr.attribute11, gcr.attribute12, gcr.attribute13, '
3184 ||'gcr.attribute14, gcr.attribute15, gcr.attribute16, gcr.attribute17, '
3185 ||'gcr.attribute18, gcr.attribute19, gcr.attribute20, gcr.attribute21, '
3186 ||'gcr.attribute22, gcr.attribute23, gcr.attribute24, gcr.attribute25, '
3187 ||'gcr.attribute26, gcr.attribute27, gcr.attribute28, gcr.attribute29, '
3188 ||'gcr.attribute30, gcr.creation_date, gcr.created_by, fu1.user_name, '
3189 ||'gcr.last_update_date, gcr.last_updated_by, fu2.user_name, '
3190 ||'gcr.last_update_login, gcr.PARENT_COMPOSITE_RESULT_ID) '; -- 5346713
3191
3192 table_list := 'FROM gmd_composite_results gcr, gmd_sampling_events gse, gmd_event_spec_disp gesd, '
3193 ||'gmd_composite_spec_disp gcsd, mtl_system_items_kfv msi, '
3194 ||'fnd_user fu1, fnd_user fu2 ';
3195
3196
3197 where_clause := 'WHERE gse.sampling_event_id = gesd.sampling_event_id '
3198 ||'AND gesd.event_spec_disp_id = gcsd.event_spec_disp_id '
3199 ||'AND gcsd.composite_spec_disp_id = gcr.composite_spec_disp_id '
3200 ||'AND gse.inventory_item_id = msi.inventory_item_id '
3201 ||'AND fu1.user_id = gcr.created_by AND fu2.user_id = gcr.last_updated_by and 1=:dummy ';
3202
3203 ELSIF (p_from_item_number IS NOT NULL OR p_to_item_number IS NOT NULL or p_inventory_item_id is NOT NULL)
3204 THEN
3205 column_list := 'system.gmd_composite_results_rec_type( gcr.composite_result_id, gcr.test_id, ' -- 5284247
3206 ||'gcr.mean, gcr.mode_num, gcr.mode_char, gcr.low_num, gcr.high_num , '
3207 ||'gcr.range, gcr.standard_deviation, gcr.sample_total, '
3208 ||'gcr.sample_cnt_used, gcr.non_validated_result, '
3209 ||'gcr.high_char, gcr.low_char, gcr.median_char, gcr.median_num, '
3210 ||'gcr.composite_spec_disp_id, gcr.in_spec_ind, gcr.wf_response, '
3211 ||'gcr.value_in_report_precision, gcsd.disposition, '
3212 ||'gse.inventory_item_id, msi.concatenated_segments, gse.lot_number, '
3213 ||'gcr.delete_mark, gcr.text_code, gcr.attribute_category, gcr.attribute1, '
3214 ||'gcr.attribute2, gcr.attribute3, gcr.attribute4, gcr.attribute5, '
3215 ||'gcr.attribute6, gcr.attribute7, gcr.attribute8, gcr.attribute9, '
3216 ||'gcr.attribute10, gcr.attribute11, gcr.attribute12, gcr.attribute13, '
3217 ||'gcr.attribute14, gcr.attribute15, gcr.attribute16, gcr.attribute17, '
3218 ||'gcr.attribute18, gcr.attribute19, gcr.attribute20, gcr.attribute21, '
3219 ||'gcr.attribute22, gcr.attribute23, gcr.attribute24, gcr.attribute25, '
3220 ||'gcr.attribute26, gcr.attribute27, gcr.attribute28, gcr.attribute29, '
3221 ||'gcr.attribute30, gcr.creation_date, gcr.created_by, fu1.user_name, '
3222 ||'gcr.last_update_date, gcr.last_updated_by, fu2.user_name, '
3223 ||'gcr.last_update_login, gcr.PARENT_COMPOSITE_RESULT_ID) '; -- 5346713
3224
3225 table_list := 'FROM gmd_composite_results gcr, gmd_sampling_events gse, gmd_event_spec_disp gesd, '
3226 ||'gmd_composite_spec_disp gcsd, mtl_system_items_kfv msi, '
3227 ||'fnd_user fu1, fnd_user fu2 ';
3228
3229
3230 where_clause := 'WHERE gse.sampling_event_id = gesd.sampling_event_id '
3231 ||'AND gesd.event_spec_disp_id = gcsd.event_spec_disp_id '
3232 ||'AND gcsd.composite_spec_disp_id = gcr.composite_spec_disp_id '
3233 ||'AND gse.inventory_item_id = msi.inventory_item_id '
3234 ||'AND fu1.user_id = gcr.created_by AND fu2.user_id = gcr.last_updated_by and 1=:dummy ';
3235
3236 ELSIF (p_lot_number is NOT NULL)
3237 THEN
3238 column_list := 'system.gmd_composite_results_rec_type( gcr.composite_result_id, gcr.test_id, ' -- 5284247
3239 ||'gcr.mean, gcr.mode_num, gcr.mode_char, gcr.low_num, gcr.high_num , '
3240 ||'gcr.range, gcr.standard_deviation, gcr.sample_total, '
3241 ||'gcr.sample_cnt_used, gcr.non_validated_result, '
3242 ||'gcr.high_char, gcr.low_char, gcr.median_char, gcr.median_num, '
3243 ||'gcr.composite_spec_disp_id, gcr.in_spec_ind, gcr.wf_response, '
3244 ||'gcr.value_in_report_precision, gcsd.disposition, '
3245 ||'gse.inventory_item_id, NULL, gse.lot_number, '
3246 ||'gcr.delete_mark, gcr.text_code, gcr.attribute_category, gcr.attribute1, '
3247 ||'gcr.attribute2, gcr.attribute3, gcr.attribute4, gcr.attribute5, '
3248 ||'gcr.attribute6, gcr.attribute7, gcr.attribute8, gcr.attribute9, '
3249 ||'gcr.attribute10, gcr.attribute11, gcr.attribute12, gcr.attribute13, '
3250 ||'gcr.attribute14, gcr.attribute15, gcr.attribute16, gcr.attribute17, '
3251 ||'gcr.attribute18, gcr.attribute19, gcr.attribute20, gcr.attribute21, '
3252 ||'gcr.attribute22, gcr.attribute23, gcr.attribute24, gcr.attribute25, '
3253 ||'gcr.attribute26, gcr.attribute27, gcr.attribute28, gcr.attribute29, '
3254 ||'gcr.attribute30, gcr.creation_date, gcr.created_by, fu1.user_name, '
3255 ||'gcr.last_update_date, gcr.last_updated_by, fu2.user_name, '
3256 ||'gcr.last_update_login, gcr.PARENT_COMPOSITE_RESULT_ID) '; -- 5347613
3257
3258 table_list := 'FROM gmd_composite_results gcr, gmd_sampling_events gse, gmd_event_spec_disp gesd,'
3259 ||'gmd_composite_spec_disp gcsd, mtl_system_items_kfv msi, '
3260 ||'fnd_user fu1, fnd_user fu2 ';
3261
3262
3263 where_clause := 'WHERE gse.sampling_event_id = gesd.sampling_event_id '
3264 ||'AND gesd.event_spec_disp_id = gcsd.event_spec_disp_id '
3265 ||'AND gcsd.composite_spec_disp_id = gcr.composite_spec_disp_id '
3266 ||'AND gse.inventory_item_id = msi.inventory_item_id ' -- 5346713 rework - space missing from end of statement
3267 ||'AND fu1.user_id = gcr.created_by AND fu2.user_id = gcr.last_updated_by and 1=:dummy ';
3268
3269
3270 ELSE
3271 column_list := 'system.gmd_composite_results_rec_type( gcr.composite_result_id, gcr.test_id, ' -- 5284247
3272 ||'gcr.mean, gcr.mode_num, gcr.mode_char, gcr.low_num, gcr.high_num , '
3273 ||'gcr.range, gcr.standard_deviation, gcr.sample_total, '
3274 ||'gcr.sample_cnt_used, gcr.non_validated_result, '
3275 ||'gcr.high_char, gcr.low_char, gcr.median_char, gcr.median_num, '
3276 ||'gcr.composite_spec_disp_id, gcr.in_spec_ind, gcr.wf_response, '
3277 ||'gcr.value_in_report_precision, gcsd.disposition, '
3278 ||'gse.inventory_item_id, NULL, gse.lot_number, '
3279 ||'gcr.delete_mark, gcr.text_code, gcr.attribute_category, gcr.attribute1, '
3280 ||'gcr.attribute2, gcr.attribute3, gcr.attribute4, gcr.attribute5, '
3281 ||'gcr.attribute6, gcr.attribute7, gcr.attribute8, gcr.attribute9, '
3282 ||'gcr.attribute10, gcr.attribute11, gcr.attribute12, gcr.attribute13, '
3283 ||'gcr.attribute14, gcr.attribute15, gcr.attribute16, gcr.attribute17, '
3284 ||'gcr.attribute18, gcr.attribute19, gcr.attribute20, gcr.attribute21, '
3285 ||'gcr.attribute22, gcr.attribute23, gcr.attribute24, gcr.attribute25, '
3286 ||'gcr.attribute26, gcr.attribute27, gcr.attribute28, gcr.attribute29, '
3287 ||'gcr.attribute30, gcr.creation_date, gcr.created_by, fu1.user_name, '
3288 ||'gcr.last_update_date, gcr.last_updated_by, fu2.user_name, '
3289 ||'gcr.last_update_login, gcr.PARENT_COMPOSITE_RESULT_ID) '; -- 5346713
3290
3291
3292 table_list := 'FROM gmd_composite_results gcr, gmd_sampling_events gse, gmd_event_spec_disp gesd, '
3293 ||'gmd_composite_spec_disp gcsd, '
3294 ||'fnd_user fu1, fnd_user fu2 ';
3295
3296
3297 where_clause := 'WHERE gse.sampling_event_id = gesd.sampling_event_id '
3298 ||'AND gesd.event_spec_disp_id = gcsd.event_spec_disp_id '
3299 ||'AND gcsd.composite_spec_disp_id = gcr.composite_spec_disp_id '
3300 ||'AND fu1.user_id = gcr.created_by AND fu2.user_id = gcr.last_updated_by and 1=:dummy ';
3301
3302
3303 END IF;
3304 using_clause := ' USING 1 ';
3305
3306 -- Work down the parameter list and append conditions, bind variables and bind values.
3307
3308 IF p_sampling_event_id IS NOT NULL
3309 THEN
3310 gmd_outbound_apis_pub.g_sampling_event_id := p_sampling_event_id;
3311 where_clause := where_clause||'AND gse.sampling_event_id = :sampling_event_id ';
3312 using_clause := using_clause||', gmd_outbound_apis_pub.g_sampling_event_id ';
3313 END IF;
3314
3315 IF p_composite_result_disposition IS NOT NULL
3316 THEN
3317 gmd_outbound_apis_pub.g_disposition := p_composite_result_disposition;
3318 where_clause := where_clause||'AND gcsd.disposition = :disposition ';
3319 using_clause := using_clause||', gmd_outbound_apis_pub.g_disposition ';
3320 END IF;
3321 -- pal
3322 -- BUG 3078607 correct using variable
3323 IF p_from_item_number IS NOT NULL /*NSRIVAST, INVCONV*/
3324 THEN
3325 gmd_outbound_apis_pub.g_from_item_no := p_from_item_number;
3326 where_clause := where_clause||'AND msi.inventory_item_id IN ( SELECT distinct inventory_item_id FROM mtl_system_items_kfv'
3327 ||' WHERE concatenated_segments >= :from_item_number'
3328 ||' AND organization_id = gse.organization_id)'; -- 5346713 rework added org id
3329
3330 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_item_no ';
3331 END IF;
3332
3333 IF p_to_item_number IS NOT NULL /*NSRIVAST, INVCONV*/
3334 THEN
3335 gmd_outbound_apis_pub.g_to_item_no := p_to_item_number;
3336 where_clause := where_clause||'AND msi.inventory_item_id IN ( SELECT distinct inventory_item_id FROM mtl_system_items_kfv'
3337 ||' WHERE concatenated_segments <= :to_item_number'
3338 ||' AND organization_id = gse.organization_id)'; -- 5346713 rework added org id
3339 using_clause := using_clause||', gmd_outbound_apis_pub.g_to_item_no ';
3340 END IF;
3341
3342 IF p_inventory_item_id IS NOT NULL /*NSRIVAST, INVCONV*/
3343 THEN
3344 gmd_outbound_apis_pub.g_inventory_item_id := p_inventory_item_id;
3345 where_clause := where_clause||'AND msi.inventory_item_id = :inventory_item_id '
3346 ||' AND msi.organization_id = gse.organization_id'; -- 5346713 rework added org id
3347 using_clause := using_clause||', gmd_outbound_apis_pub.g_inventory_item_id ';
3348 END IF;
3349
3350 IF p_from_lot_number IS NOT NULL /*NSRIVAST, INVCONV*/
3351 THEN
3352 gmd_outbound_apis_pub.g_from_lot_number := p_from_lot_number;
3353 where_clause := where_clause||'AND gse.lot_number >= :from_lot_number ';
3354 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_lot_number ';
3355 END IF;
3356
3357 IF p_to_lot_number IS NOT NULL /*NSRIVAST, INVCONV*/
3358 THEN
3359 gmd_outbound_apis_pub.g_to_lot_number := p_to_lot_number;
3360 where_clause := where_clause||'AND gse.lot_number <= :to_lot_number ';
3361 using_clause := using_clause||', gmd_outbound_apis_pub.g_to_lot_number ';
3362 END IF;
3363
3364 -- BUG 3078607 lot_id from gse not ilm
3365 IF p_lot_number IS NOT NULL /*NSRIVAST, INVCONV*/
3366 THEN
3367 gmd_outbound_apis_pub.g_lot_number := p_lot_number;
3368 where_clause := where_clause||'AND gse.lot_number = :lot_number ';
3369 using_clause := using_clause||', gmd_outbound_apis_pub.g_lot_number ';
3370 END IF;
3371
3372 IF p_from_last_update_date IS NOT NULL
3373 THEN
3374 gmd_outbound_apis_pub.g_from_last_update_date := p_from_last_update_date;
3375 where_clause := where_clause||'AND gcr.last_update_date >= :from_last_update_date ';
3376 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_last_update_date ';
3377 END IF;
3378
3379 IF p_to_last_update_date IS NOT NULL
3380 THEN
3381 gmd_outbound_apis_pub.g_to_last_update_date := p_to_last_update_date;
3382 where_clause := where_clause||'AND gcr.last_update_date <= :to_last_update_date '; -- BUG 3078683
3383 using_clause := using_clause||', gmd_outbound_apis_pub.g_to_last_update_date ';
3384 END IF;
3385
3386 IF p_delete_mark IS NOT NULL
3387 THEN
3388 gmd_outbound_apis_pub.g_delete_mark := p_delete_mark ;
3389 where_clause := where_clause||'AND gcr.delete_mark = :delete_mark ';
3390 using_clause := using_clause||', gmd_outbound_apis_pub.g_delete_mark ';
3391 END IF;
3392
3393 -- That's more or less the job done. We just need to tell the system where to store the data
3394
3395 into_clause := ' BULK COLLECT INTO gmd_outbound_apis_pub.g_composite_results_table ';
3396
3397 execution_string := 'BEGIN EXECUTE IMMEDIATE '
3398 ||''''
3399 ||sql_statement||column_list||table_list||where_clause
3400 ||''''
3401 ||into_clause
3402 ||using_clause
3403 ||'; END;';
3404
3405 gme_debug.put_line('The sql statement is:');
3406 i:= 1;
3407 LOOP
3408 gme_debug.put_line(substr(execution_string, i, 100));
3409 EXIT WHEN i> LENGTH(execution_string);
3410 i := i+100;
3411 END LOOP;
3412 gme_debug.put_line('Executing string');
3413
3414 EXECUTE IMMEDIATE execution_string;
3415 -- gme_debug.put_line('here 1 ');
3416 FOR i IN 1..g_composite_results_table.count
3417 LOOP
3418 --gme_debug.put_line('inside internal loop i = ' || i);
3419 IF g_composite_results_table(i).inventory_item_id IS NOT NULL AND g_composite_results_table(i).item_number IS NULL
3420 THEN
3421 gme_debug.put_line('select from mtl_system_items_kfv using '|| g_composite_results_table(i).inventory_item_id);
3422 SELECT concatenated_segments INTO g_composite_results_table(i).item_number
3423 FROM mtl_system_items_kfv msi
3424 WHERE inventory_item_id = g_composite_results_table(i).inventory_item_id
3425 and rownum = 1 ; -- 5346713 rework
3426 END IF;
3427
3428 /*IF g_composite_results_table(i).lot_number IS NOT NULL
3429 THEN
3430 gme_debug.put_line('select from mtl_lot_numbers using '|| g_composite_results_table(i).lot_number);
3431 SELECT lot_number INTO g_composite_results_table(i).lot_number
3432 FROM mtl_lot_numbers
3433 WHERE lot_number = g_composite_results_table(i).lot_number;
3434 END IF;*/
3435
3436
3437 END LOOP;
3438
3439
3440 gme_debug.put_line('Returning table to caller');
3441 x_composite_results_table := gmd_outbound_apis_pub.g_composite_results_table;
3442 x_return_status := FND_API.G_RET_STS_SUCCESS;
3443
3444 END IF;
3445
3446
3447 FND_MSG_PUB.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
3448 gme_debug.put_line('Finished FETCH_COMPOSITE_RESULTS');
3449
3450 EXCEPTION
3451 WHEN OTHERS
3452 THEN
3453 FND_MESSAGE.SET_NAME('GMD',SQLCODE);
3454 FND_MSG_PUB.Add;
3455 FND_MSG_PUB.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
3456 x_return_status := FND_API.G_RET_STS_ERROR;
3457
3458 END fetch_composite_results;
3459
3460
3461 PROCEDURE fetch_samples
3462 ( p_api_version IN NUMBER
3463 , p_init_msg_list IN VARCHAR2 DEFAULT FND_API.G_FALSE
3464 , p_user_name IN VARCHAR2
3465 , p_organization_id IN NUMBER DEFAULT NULL
3466 , p_from_sample_no IN VARCHAR2 DEFAULT NULL
3467 , p_to_sample_no IN VARCHAR2 DEFAULT NULL
3468 , p_sample_id IN NUMBER DEFAULT NULL
3469 , p_sampling_event_id IN NUMBER DEFAULT NULL
3470 , p_from_item_number IN VARCHAR2 DEFAULT NULL /*bug 4165704, INVCONV*/
3471 , p_to_item_number IN VARCHAR2 DEFAULT NULL /*bug 4165704, INVCONV*/
3472 , p_inventory_item_id IN NUMBER DEFAULT NULL /*bug 4165704, INVCONV*/
3473 , p_revision IN VARCHAR2 DEFAULT NULL /*bug 4165704, INVCONV*/
3474 , p_from_lot_number IN VARCHAR2 DEFAULT NULL /*bug 4165704, INVCONV*/
3475 , p_to_lot_number IN VARCHAR2 DEFAULT NULL /*bug 4165704, INVCONV*/
3476 , p_parent_lot_number IN VARCHAR2 DEFAULT NULL /*bug 4165704, INVCONV*/
3477 --, p_lot_number IN VARCHAR2 DEFAULT NULL /*bug 4165704, INVCONV*/
3478 , p_priority IN VARCHAR2 DEFAULT NULL
3479 , p_spec_name IN VARCHAR2 DEFAULT NULL
3480 , p_spec_vers IN VARCHAR2 DEFAULT NULL
3481 , p_spec_id IN NUMBER DEFAULT NULL
3482 , p_source IN VARCHAR2 DEFAULT NULL
3483 , p_from_date_drawn IN DATE DEFAULT NULL
3484 , p_to_date_drawn IN DATE DEFAULT NULL
3485 , p_from_expiration_date IN DATE DEFAULT NULL
3486 , p_to_expiration_date IN DATE DEFAULT NULL
3487 , p_from_date_received IN DATE DEFAULT NULL
3488 , p_to_date_received IN DATE DEFAULT NULL
3489 , p_from_date_required IN DATE DEFAULT NULL
3490 , p_to_date_required IN DATE DEFAULT NULL
3491 , p_resources IN VARCHAR2 DEFAULT NULL
3492 , p_instance_id IN NUMBER DEFAULT NULL
3493 , p_from_retrieval_date IN DATE DEFAULT NULL
3494 , p_to_retrieval_date IN DATE DEFAULT NULL
3495 , p_sample_type IN VARCHAR2 DEFAULT NULL
3496 , p_ss_id IN NUMBER DEFAULT NULL
3497 , p_ss_organization_id IN VARCHAR2 DEFAULT NULL
3498 , p_ss_no IN VARCHAR2 DEFAULT NULL
3499 , p_variant_id IN NUMBER DEFAULT NULL
3500 , p_variant_no IN NUMBER DEFAULT NULL
3501 , p_time_point_id IN NUMBER DEFAULT NULL
3502 , p_source_subinventory IN VARCHAR2 DEFAULT NULL
3503 , p_source_locator_id IN NUMBER DEFAULT NULL
3504 , p_grade_code IN VARCHAR2 DEFAULT NULL
3505 , p_sample_disposition IN VARCHAR2 DEFAULT NULL
3506 , p_storage_subinventory IN VARCHAR2 DEFAULT NULL
3507 , p_storage_locator_id IN NUMBER DEFAULT NULL
3508 , p_lab_organization_id IN VARCHAR2 DEFAULT NULL
3509 , p_external_id IN VARCHAR2 DEFAULT NULL
3510 , p_sampler IN VARCHAR2 DEFAULT NULL
3511 , p_lot_retest_ind IN VARCHAR2 DEFAULT NULL
3512 , p_subinventory IN VARCHAR2 DEFAULT NULL
3513 , p_locator_id IN NUMBER DEFAULT NULL
3514 , p_wip_plant_code IN VARCHAR2 DEFAULT NULL
3515 , p_wip_batch_no IN VARCHAR2 DEFAULT NULL
3516 , p_wip_batch_id IN NUMBER DEFAULT NULL
3517 , p_wip_recipe_no IN VARCHAR2 DEFAULT NULL
3518 , p_wip_recipe_version IN NUMBER DEFAULT NULL
3519 , p_wip_recipe_id IN NUMBER DEFAULT NULL
3520 , p_wip_formula_no IN VARCHAR2 DEFAULT NULL
3521 , p_wip_formula_version IN NUMBER DEFAULT NULL
3522 , p_wip_formula_id IN NUMBER DEFAULT NULL
3523 , p_wip_formulaline IN NUMBER DEFAULT NULL
3524 , p_wip_formulaline_id IN NUMBER DEFAULT NULL
3525 , p_wip_line_type IN NUMBER DEFAULT NULL
3526 , p_wip_routing_no IN VARCHAR2 DEFAULT NULL
3527 , p_wip_routing_vers IN NUMBER DEFAULT NULL
3528 , p_wip_routing_id IN NUMBER DEFAULT NULL
3529 , p_wip_batchstep_no IN NUMBER DEFAULT NULL
3530 , p_wip_batchstep_id IN NUMBER DEFAULT NULL
3531 , p_wip_oprn_no IN VARCHAR2 DEFAULT NULL
3532 , p_wip_oprn_vers IN NUMBER DEFAULT NULL
3533 , p_wip_oprn_id IN NUMBER DEFAULT NULL
3534 , p_cust_name IN VARCHAR2 DEFAULT NULL
3535 , p_cust_id IN NUMBER DEFAULT NULL
3536 , p_org_id IN NUMBER DEFAULT NULL
3537 , p_cust_ship_to_site_id IN NUMBER DEFAULT NULL
3538 , p_cust_order IN VARCHAR2 DEFAULT NULL
3539 , p_cust_order_id IN NUMBER DEFAULT NULL
3540 , p_cust_order_type IN VARCHAR2 DEFAULT NULL
3541 , p_cust_order_line IN NUMBER DEFAULT NULL
3542 , p_cust_order_line_id IN NUMBER DEFAULT NULL
3543 , p_supplier IN VARCHAR2 DEFAULT NULL
3544 , p_supplier_id IN NUMBER DEFAULT NULL
3545 , p_supplier_site_id IN NUMBER DEFAULT NULL
3546 , p_supplier_po IN VARCHAR2 DEFAULT NULL
3547 , p_supplier_po_id IN NUMBER DEFAULT NULL
3548 , p_supplier_po_line IN NUMBER DEFAULT NULL
3549 , p_supplier_po_line_id IN NUMBER DEFAULT NULL
3550 , p_from_last_update_date IN DATE DEFAULT NULL
3551 , p_to_last_update_date IN DATE DEFAULT NULL
3552 , p_retain_as IN VARCHAR2 DEFAULT NULL
3553 , p_delete_mark IN NUMBER DEFAULT NULL
3554 , p_lpn IN VARCHAR2 DEFAULT NULL -- 7027149
3555 , p_lpn_id IN NUMBER DEFAULT NULL-- 7027149
3556 , x_samples_table OUT NOCOPY system.gmd_samples_tab_type -- 5335829
3557 , x_return_status OUT NOCOPY VARCHAR2
3558 , x_msg_count OUT NOCOPY NUMBER
3559 , x_msg_data OUT NOCOPY VARCHAR2
3560
3561 )
3562 IS
3563 -- BUG 3078013 increase size of variables
3564 sql_statement VARCHAR2(2000);
3565 column_list VARCHAR2(4000);
3566 table_list VARCHAR2(2000);
3567 where_clause VARCHAR2(4000);
3568 into_clause VARCHAR2(4000);
3569 using_clause VARCHAR2(4000);
3570 execution_string VARCHAR2(12000);
3571 row_count NUMBER;
3572 i NUMBER;
3573
3574 l_api_name VARCHAR2(100) := 'fetch_samples';
3575
3576 l_ss_table_included VARCHAR2(10);
3577
3578 G_PKG_NAME CONSTANT VARCHAR2(30):='GMD_OUTBOUND_APIS_PUB';
3579
3580 BEGIN
3581 gme_debug.put_line('Starting FETCH_SAMPLES');
3582 -- dbms_output.put_line('Enter GMD_OUTBOUND_APIS_PUB.FETCH_SAMPLES API');
3583 -- (gmd_outbound_apis_pub.api_version, p_api_version, l_api_name,'GMD_OUTBOUND_APIS_PUB')
3584 IF NOT FND_API.Compatible_API_CALL
3585 (gmd_outbound_apis_pub.api_version, p_api_version , l_api_name , G_PKG_NAME)
3586 THEN
3587
3588 -- dbms_output.put_line('api version error');
3589 Raise FND_API.G_EXC_UNEXPECTED_ERROR;
3590
3591 ELSIF NOT initialized_ok(p_user_name)
3592
3593 THEN
3594
3595 -- dbms_output.put_line('user name error');
3596 Raise FND_API.G_EXC_UNEXPECTED_ERROR;
3597 ELSE
3598
3599 -- dbms_output.put_line('Starting FETCH_SAMPLES processing');
3600 gme_debug.put_line('Starting FETCH_SAMPLES processing');
3601 /* Initialize message list if p_int_msg_list is set TRUE. */
3602 IF FND_API.to_boolean(p_init_msg_list)
3603 THEN
3604 FND_MSG_PUB.Initialize;
3605 END IF;
3606
3607 -- Start construction for the select.
3608
3609 -- dbms_output.put_line('Begin constructing SELECT statement');
3610 gme_debug.put_line('Begin constructing SELECT statement');
3611 sql_statement := 'SELECT ';
3612
3613 -- BUG 3077905 Retrieve sample_disposition from gmd_sample_spec_disp not gmd_samples
3614
3615 column_list := 'system.gmd_samples_rec_type( gs.sampling_event_id, gs.step_no, gs.step_id, ' -- 5335829
3616 ||'gs.sample_id, gs.sample_no, gs.sample_desc, '
3617 ||'gesd.spec_id, null, null , '
3618 ||'gs.lab_organization_id, gs.inventory_item_id, gs.revision, null, '
3619 ||'gs.locator_id, gs.expiration_date, '
3620 ||'gs.lot_number, gs.parent_lot_number, '
3621 ||'gs.batch_id, null, null, '
3622 ||'gs.recipe_id, null, null, '
3623 ||'gs.formula_id, null, null, gs.formulaline_id, null, null, '
3624 ||'gs.routing_id, null, null, gs.oprn_id, null, null, null,null, gs.charge, '
3625 ||'gs.cust_id, null, gs.order_id, null, null, gs.order_line_id, null, gs.org_id, null, '
3626 ||'gs.supplier_id, null, gs.sample_qty, gs.sample_qty_uom, gs.source, '
3627 ||'gs.sampler_id, null, gs.date_drawn, gs.source_comment, '
3628 ||'gs.storage_subinventory, gs.storage_locator_id, gs.external_id, '
3629 ||'gs.sample_approver_id, gs.inv_approver_id, '
3630 ||'gs.priority, gs.sample_inv_trans_ind, '
3631 ||'gs.supplier_site_id, null, gs.subinventory, gs.organization_id, '
3632 ||'gs.po_header_id, null, gs.po_line_id, null, '
3633 ||'gs.receipt_id, null, gs.receipt_line_id, null, '
3634 ||'gssd.disposition, gs.ship_to_site_id, null, '
3635 ||'gs.supplier_lot_no, gs.lot_retest_ind, gs.sample_instance, '
3636 ||'gs.source_subinventory, gs.source_locator_id, '
3637 ||'gs.date_received, gs.date_required, gs.resources, gs.instance_id, '
3638 ||'gs.retrieval_date, gs.sample_type, gs.time_point_id, gs.variant_id, '
3639 ||'gs.delete_mark, gs.text_code, gs.attribute_category, gs.attribute1, '
3640 ||'gs.attribute2, gs.attribute3, gs.attribute4, gs.attribute5, '
3641 ||'gs.attribute6, gs.attribute7, gs.attribute8, gs.attribute9, '
3642 ||'gs.attribute10, gs.attribute11, gs.attribute12, gs.attribute13, '
3643 ||'gs.attribute14, gs.attribute15, gs.attribute16, gs.attribute17, '
3644 ||'gs.attribute18, gs.attribute19, gs.attribute20, gs.attribute21, '
3645 ||'gs.attribute22, gs.attribute23, gs.attribute24, gs.attribute25, '
3646 ||'gs.attribute26, gs.attribute27, gs.attribute28, gs.attribute29, '
3647 ||'gs.attribute30, gs.creation_date, gs.created_by, fu1.user_name, '
3648 ||'gs.last_update_date, gs.last_updated_by, fu2.user_name, '
3649 ||'gs.last_update_login, gs.retain_as, gs.remaining_qty, gs.lpn_id, null) '; -- 7027149
3650
3651 table_list := 'FROM gmd_samples gs, gmd_event_spec_disp gesd,gmd_sample_spec_disp gssd, '
3652 ||'fnd_user fu1, fnd_user fu2 ';
3653
3654
3655 -- BUG 3077905 Retrieve sample_disposition from gmd_sample_spec_disp not gmd_samples
3656 where_clause := 'WHERE gs.sampling_event_id = gesd.sampling_event_id and '
3657 ||' gesd.event_spec_disp_id = gssd.event_spec_disp_id and '
3658 ||' gs.sample_id = gssd.sample_id and '
3659 ||' gesd.spec_used_for_lot_attrib_ind = ''''Y'''' and '
3660 ||' fu1.user_id = gs.created_by AND fu2.user_id = gs.last_updated_by and 1=:dummy ';
3661
3662 using_clause := ' USING 1 ';
3663 -- dbms_output.put_line('Before test for organization id not null');
3664
3665 -- Work down the parameter list and append conditions, bind variables and bind values.
3666 -- ===================================================================================
3667
3668 IF p_organization_id IS NOT NULL
3669 THEN
3670 gmd_outbound_apis_pub.g_orgn_id := p_organization_id;
3671 where_clause := where_clause||'AND gs.organization_id = :organization_id ';
3672 using_clause := using_clause||', gmd_outbound_apis_pub.g_orgn_id ';
3673 END IF;
3674 -- dbms_output.put_line('after organization id test for null');
3675
3676 IF p_from_sample_no IS NOT NULL
3677 THEN
3678 gmd_outbound_apis_pub.g_from_sample_no := p_from_sample_no;
3679 where_clause := where_clause||'AND gs.sample_no >= :from_sample_no ';
3680 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_sample_no ';
3681 END IF;
3682
3683 IF p_to_sample_no IS NOT NULL
3684 THEN
3685 gmd_outbound_apis_pub.g_to_sample_no := p_to_sample_no;
3686 where_clause := where_clause||'AND gs.sample_no <= :to_sample_no ';
3687 using_clause := using_clause||', gmd_outbound_apis_pub.g_to_sample_no ';
3688 END IF;
3689
3690 IF p_sample_id IS NOT NULL
3691 THEN
3692 gmd_outbound_apis_pub.g_sample_id := p_sample_id;
3693 where_clause := where_clause||'AND gs.sample_id = :sample_id ';
3694 using_clause := using_clause||', gmd_outbound_apis_pub.g_sample_id ';
3695 END IF;
3696
3697 IF p_sampling_event_id IS NOT NULL
3698 THEN
3699 gmd_outbound_apis_pub.g_sampling_event_id := p_sampling_event_id;
3700 where_clause := where_clause||'AND gs.sampling_event_id = :sampling_event_id ';
3701 using_clause := using_clause||', gmd_outbound_apis_pub.g_sampling_event_id ';
3702 END IF;
3703
3704 -- 5335829 rework
3705
3706 IF p_from_item_number IS NOT NULL and p_to_item_number IS NOT NULL
3707 THEN
3708 g_from_item_number := p_from_item_number;
3709 g_to_item_number := p_to_item_number;
3710 where_clause := where_clause
3711 ||' AND gs.inventory_item_id IN (SELECT inventory_item_id FROM mtl_system_items_b_kfv'
3712 ||' WHERE concatenated_segments BETWEEN :from_item_number AND :to_item_number'
3713 ||' AND organization_id = gs.organization_id)'; -- 5335829 rework - owner_organization_id is not a valid column name
3714 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_item_number, gmd_outbound_apis_pub.g_to_item_number';
3715 ELSIF p_from_item_number IS NOT NULL
3716 THEN
3717 g_from_item_number := p_from_item_number;
3718 where_clause := where_clause
3719 ||' AND gs.inventory_item_id IN (SELECT inventory_item_id FROM mtl_system_items_b_kfv'
3720 ||' WHERE concatenated_segments >= :from_item_number'
3721 ||' AND organization_id = gs.organization_id)'; -- 5335829 rework - owner_organization_id is not a valid column name
3722 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_item_number';
3723 ELSIF p_to_item_number IS NOT NULL
3724 THEN
3725 g_to_item_number := p_to_item_number;
3726 where_clause := where_clause
3727 ||' AND gs.inventory_item_id IN (SELECT inventory_item_id FROM mtl_system_items_b_kfv'
3728 ||' WHERE concatenated_segments <= :to_item_number'
3729 ||' AND organization_id = gs.organization_id)'; -- 5335829 rework - owner_organization_id is not a valid column name
3730 using_clause := using_clause||', gmd_outbound_apis_pub.g_to_item_number';
3731 END IF; -- IF p_from_item_number IS NOT NULL and p_to_item_number IS NOT NULL
3732 -- 5335829 end of rework
3733 -- Bug 4165704 invconv: this code should not be needed anymore
3734 --table_list := table_list ||', ic_item_mst iim ';
3735 --IF p_from_item_number IS NOT NULL THEN
3736 --where_clause := where_clause||'AND iim.item_number >= :from_item_number ';
3737 --END IF;
3738 --IF p_to_item_number IS NOT NULL THEN
3739 --where_clause := where_clause||'AND iim.item_number <= :to_item_number ';
3740 --END IF;
3741 -- dbms_output.put_line('after item_number');
3742
3743 IF p_inventory_item_id IS NOT NULL
3744 THEN
3745 gmd_outbound_apis_pub.g_inventory_item_id := p_inventory_item_id;
3746 where_clause := where_clause||'AND gs.inventory_item_id = :inventory_item_id ';
3747 using_clause := using_clause||', gmd_outbound_apis_pub.g_inventory_item_id ';
3748 END IF;
3749
3750 IF p_from_lot_number IS NOT NULL
3751 THEN
3752 gmd_outbound_apis_pub.g_from_lot_number := p_from_lot_number;
3753 where_clause := where_clause||'AND gs.lot_number >= :from_lot_number ';
3754 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_lot_number ';
3755 END IF;
3756
3757 IF p_to_lot_number IS NOT NULL
3758 THEN
3759 gmd_outbound_apis_pub.g_to_lot_number := p_to_lot_number;
3760 where_clause := where_clause||'AND gs.lot_number <= :to_lot_number ';
3761 using_clause := using_clause||', gmd_outbound_apis_pub.g_to_lot_number ';
3762 END IF;
3763
3764 IF p_parent_lot_number IS NOT NULL
3765 THEN
3766 gmd_outbound_apis_pub.g_parent_lot_number := p_parent_lot_number;
3767 where_clause := where_clause||'AND gs.parent_lot_number = :parent_lot_number ';
3768 using_clause := using_clause||', gmd_outbound_apis_pub.g_parent_lot_number ';
3769 END IF;
3770
3771 /* taken out for Bug 4165704
3772 IF p_lot_id IS NOT NULL
3773 THEN
3774 gmd_outbound_apis_pub.g_lot_id := p_lot_id;
3775 where_clause := where_clause||'AND gs.lot_id = :lot_id ';
3776 using_clause := using_clause||', gmd_outbound_apis_pub.g_lot_id ';
3777 END IF;
3778 */
3779
3780 IF p_priority IS NOT NULL
3781 THEN
3782 gmd_outbound_apis_pub.g_priority := p_priority;
3783 where_clause := where_clause||'AND gs.priority = :priority ';
3784 using_clause := using_clause||', gmd_outbound_apis_pub.g_priority ';
3785 END IF;
3786 -- dbms_output.put_line('after priority');
3787
3788 IF (p_spec_name IS NOT NULL OR p_spec_vers IS NOT NULL or p_spec_id is NOT NULL or p_grade_code is NOT NULL)
3789 THEN
3790 table_list := table_list ||', gmd_specifications gspec ';
3791 where_clause := where_clause ||'AND gesd.spec_id = gspec.spec_id ';
3792
3793 IF p_spec_name IS NOT NULL
3794 THEN
3795 gmd_outbound_apis_pub.g_spec_name := p_spec_name;
3796 where_clause := where_clause||'AND gspec.spec_name = :spec_name ';
3797 using_clause := using_clause||', gmd_outbound_apis_pub.g_spec_name ';
3798 END IF;
3799
3800 IF p_spec_vers IS NOT NULL
3801 THEN
3802 gmd_outbound_apis_pub.g_spec_vers := p_spec_vers;
3803 where_clause := where_clause||'AND gspec.spec_vers = :spec_vers ';
3804 using_clause := using_clause||', gmd_outbound_apis_pub.g_spec_vers ';
3805 END IF;
3806
3807 IF p_spec_id IS NOT NULL
3808 THEN
3809 gmd_outbound_apis_pub.g_spec_id := p_spec_id;
3810 where_clause := where_clause||'AND gspec.spec_id = :spec_id ';
3811 using_clause := using_clause||', gmd_outbound_apis_pub.g_spec_id ';
3812 END IF;
3813
3814 IF p_grade_code IS NOT NULL
3815 THEN
3816 gmd_outbound_apis_pub.g_grade := p_grade_code;
3817 where_clause := where_clause||'AND gspec.grade = :grade ';
3818 using_clause := using_clause||', gmd_outbound_apis_pub.g_grade ';
3819 END IF;
3820 END IF;
3821
3822 IF p_source IS NOT NULL
3823 THEN
3824 gmd_outbound_apis_pub.g_source := p_source;
3825 where_clause := where_clause||'AND gs.source = :source ';
3826 using_clause := using_clause||', gmd_outbound_apis_pub.g_source ';
3827 END IF;
3828
3829 IF p_from_date_drawn IS NOT NULL
3830 THEN
3831 gmd_outbound_apis_pub.g_from_date_drawn := p_from_date_drawn;
3832 where_clause := where_clause||'AND gs.date_drawn >= :from_date_drawn ';
3833 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_date_drawn ';
3834 END IF;
3835
3836 IF p_to_date_drawn IS NOT NULL
3837 THEN
3838 gmd_outbound_apis_pub.g_to_date_drawn := p_to_date_drawn;
3839 where_clause := where_clause||'AND gs.date_drawn <= :to_date_drawn ';
3840 using_clause := using_clause||', gmd_outbound_apis_pub.g_to_date_drawn ';
3841 END IF;
3842
3843 IF p_from_expiration_date IS NOT NULL
3844 THEN
3845 gmd_outbound_apis_pub.g_from_expiration_date := p_from_expiration_date;
3846 where_clause := where_clause||'AND gs.expiration_date >= :from_expiration_date ';
3847 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_expiration_date ';
3848 END IF;
3849
3850 IF p_to_expiration_date IS NOT NULL
3851 THEN
3852 gmd_outbound_apis_pub.g_to_expiration_date := p_to_expiration_date;
3853 where_clause := where_clause||'AND gs.expiration_date <= :to_expiration_date ';
3854 using_clause := using_clause||', gmd_outbound_apis_pub.g_to_expiration_date ';
3855 END IF;
3856
3857 IF p_source_subinventory IS NOT NULL
3858 THEN
3859 gmd_outbound_apis_pub.g_source_subinventory := p_source_subinventory;
3860 where_clause := where_clause||'AND gs.source_subinventory = :source_subinventory ';
3861 using_clause := using_clause||', gmd_outbound_apis_pub.g_source_subinventory ';
3862 END IF;
3863
3864 IF p_source_locator_id IS NOT NULL
3865 THEN
3866 gmd_outbound_apis_pub.g_source_locator_id := p_source_locator_id;
3867 where_clause := where_clause||'AND gs.source_locator_id = :source_locator_id ';
3868 using_clause := using_clause||', gmd_outbound_apis_pub.g_source_locator_id ';
3869 END IF;
3870
3871 IF p_sample_disposition IS NOT NULL
3872 THEN
3873 gmd_outbound_apis_pub.g_sample_disposition := p_sample_disposition;
3874 where_clause := where_clause||'AND gssd.disposition = :sample_disposition ';
3875 using_clause := using_clause||', gmd_outbound_apis_pub.g_sample_disposition ';
3876 END IF;
3877 -- dbms_output.put_line('after sample_disp');
3878
3879 IF p_storage_subinventory IS NOT NULL
3880 THEN
3881 gmd_outbound_apis_pub.g_storage_subinventory := p_storage_subinventory;
3882 where_clause := where_clause||'AND gs.storage_subinventory = :storage_subinventory ';
3883 using_clause := using_clause||', gmd_outbound_apis_pub.g_storage_subinventory ';
3884 END IF;
3885
3886 IF p_storage_locator_id IS NOT NULL
3887 THEN
3888 gmd_outbound_apis_pub.g_storage_locator_id := p_storage_locator_id;
3889 where_clause := where_clause||'AND gs.storage_locator_id = :storage_locator_id ';
3890 using_clause := using_clause||', gmd_outbound_apis_pub.g_storage_locator_id ';
3891 END IF;
3892
3893 IF p_lab_organization_id IS NOT NULL
3894 THEN
3895 gmd_outbound_apis_pub.g_lab_organization_id := p_lab_organization_id;
3896 where_clause := where_clause||'AND gs.lab_organization_id = :lab_organization_id ';
3897 using_clause := using_clause||', gmd_outbound_apis_pub.g_lab_organization_id ';
3898 END IF;
3899
3900 IF p_external_id IS NOT NULL
3901 THEN
3902 gmd_outbound_apis_pub.g_external_id := p_external_id;
3903 where_clause := where_clause||'AND gs.external_id = :external_id ';
3904 using_clause := using_clause||', gmd_outbound_apis_pub.g_external_id ';
3905 END IF;
3906
3907 IF p_sampler IS NOT NULL
3908 THEN
3909 table_list := table_list ||', fnd_user fu3 ';
3910 where_clause := where_clause ||'AND gs.sampler_id = fu3.user_id ';
3911
3912 gmd_outbound_apis_pub.g_sampler := p_sampler;
3913 where_clause := where_clause||'AND fu3.user_name = :sampler ';
3914 using_clause := using_clause||', gmd_outbound_apis_pub.g_sampler ';
3915 END IF;
3916
3917 IF p_lot_retest_ind IS NOT NULL
3918 THEN
3919 gmd_outbound_apis_pub.g_lot_retest_ind := p_lot_retest_ind;
3920 where_clause := where_clause||'AND gs.lot_retest_ind = :lot_retest_ind ';
3921 using_clause := using_clause||', gmd_outbound_apis_pub.g_lot_retest_ind ';
3922 END IF;
3923
3924 IF p_subinventory IS NOT NULL
3925 THEN
3926 gmd_outbound_apis_pub.g_subinventory := p_subinventory;
3927 where_clause := where_clause||'AND gs.subinventory = :subinventory ';
3928 using_clause := using_clause||', gmd_outbound_apis_pub.g_subinventory ';
3929 END IF;
3930
3931 IF p_locator_id IS NOT NULL
3932 THEN
3933 gmd_outbound_apis_pub.g_locator_id := p_locator_id;
3934 where_clause := where_clause||'AND gs.locator_id = :locator_id ';
3935 using_clause := using_clause||', gmd_outbound_apis_pub.g_locator_id ';
3936 END IF;
3937
3938 /* Bug 4165704: taken out for inventory convergence
3939 IF p_location_id IS NOT NULL
3940 THEN
3941 table_list := table_list ||', ic_loct_mst ilm ';
3942 where_clause := where_clause ||'AND gs.location = ilm.location ';
3943
3944 gmd_outbound_apis_pub.g_location_id := p_location_id;
3945 where_clause := where_clause||'AND ilm.inventory_location_id = :location_id ';
3946 using_clause := using_clause||', gmd_outbound_apis_pub.g_location_id ';
3947 END IF;
3948 */
3949
3950 IF (p_wip_plant_code IS NOT NULL or p_wip_batch_no IS NOT NULL)
3951 THEN
3952 table_list := table_list ||', gme_batch_header gbh ';
3953 where_clause := where_clause ||'AND gs.batch_id = gbh.batch_id ';
3954 IF p_wip_plant_code IS NOT NULL
3955 THEN
3956 gmd_outbound_apis_pub.g_wip_plant_code := p_wip_plant_code;
3957 where_clause := where_clause||'AND gbh.plant_code = :wip_plant_code ';
3958 using_clause := using_clause||', gmd_outbound_apis_pub.g_wip_plant_code ';
3959 END IF;
3960
3961 IF p_wip_batch_no IS NOT NULL
3962 THEN
3963 gmd_outbound_apis_pub.g_wip_batch_no := p_wip_batch_no;
3964 where_clause := where_clause||'AND gbh.batch_no = :wip_batch_no ';
3965 using_clause := using_clause||', gmd_outbound_apis_pub.g_wip_batch_no ';
3966 END IF;
3967 END IF;
3968
3969 IF p_wip_batch_id IS NOT NULL
3970 THEN
3971 gmd_outbound_apis_pub.g_wip_batch_id := p_wip_batch_id;
3972 where_clause := where_clause||'AND gs.batch_id = :wip_batch_id ';
3973 using_clause := using_clause||', gmd_outbound_apis_pub.g_wip_batch_id ';
3974 END IF;
3975
3976 IF (p_wip_recipe_no IS NOT NULL or p_wip_recipe_version IS NOT NULL)
3977 THEN
3978 table_list := table_list ||', gmd_recipes_b r ';
3979 where_clause := where_clause ||'AND gs.recipe_id = r.recipe_id ';
3980
3981 IF p_wip_recipe_no IS NOT NULL
3982 THEN
3983 gmd_outbound_apis_pub.g_wip_recipe_no := p_wip_recipe_no;
3984 where_clause := where_clause||'AND r.recipe_no = :wip_recipe_no ';
3985 using_clause := using_clause||', gmd_outbound_apis_pub.g_wip_recipe_no ';
3986 END IF;
3987
3988 IF p_wip_recipe_version IS NOT NULL
3989 THEN
3990 gmd_outbound_apis_pub.g_wip_recipe_version := p_wip_recipe_version;
3991 where_clause := where_clause||'AND r.recipe_version = :wip_recipe_version ';
3992 using_clause := using_clause||', gmd_outbound_apis_pub.g_wip_recipe_version ';
3993 END IF;
3994 END IF;
3995
3996 IF p_wip_recipe_id IS NOT NULL
3997 THEN
3998 gmd_outbound_apis_pub.g_wip_recipe_id := p_wip_recipe_id;
3999 where_clause := where_clause||'AND r.recipe_id = :wip_recipe_id ';
4000 using_clause := using_clause||', gmd_outbound_apis_pub.g_wip_recipe_id ';
4001 END IF;
4002
4003 -- BUG 3082684 - incorporate formula_vers
4004 IF p_wip_formula_no IS NOT NULL or p_wip_formula_version IS NOT NULL
4005 THEN
4006 table_list := table_list ||', fm_form_mst ffm ';
4007 where_clause := where_clause ||'AND gs.formula_id = ffm.formula_id ';
4008
4009 IF p_wip_formula_no IS NOT NULL
4010 THEN
4011 gmd_outbound_apis_pub.g_wip_formula_no := p_wip_formula_no;
4012 where_clause := where_clause||'AND ffm.formula_no = :wip_formula_no ';
4013 using_clause := using_clause||', gmd_outbound_apis_pub.g_wip_formula_no ';
4014 END IF;
4015
4016 IF p_wip_formula_version IS NOT NULL
4017 THEN
4018 gmd_outbound_apis_pub.g_wip_formula_vers := p_wip_formula_version;
4019 where_clause := where_clause||'AND ffm.formula_vers = :wip_formula_vers ';
4020 using_clause := using_clause||', gmd_outbound_apis_pub.g_wip_formula_vers ';
4021 END IF;
4022 END IF;
4023
4024 IF p_wip_formula_id IS NOT NULL
4025 THEN
4026 gmd_outbound_apis_pub.g_wip_formula_id := p_wip_formula_id;
4027 where_clause := where_clause||'AND gs.formula_id = :wip_formula_id ';
4028 using_clause := using_clause||', gmd_outbound_apis_pub.g_wip_formula_id ';
4029 END IF;
4030
4031 IF (p_wip_formulaline IS NOT NULL or p_wip_line_type IS NOT NULL)
4032 THEN
4033 table_list := table_list ||', fm_matl_dtl fmd ';
4034 where_clause := where_clause ||'AND gs.formulaline_id = fmd.formulaline_id ';
4035
4036 IF p_wip_formulaline IS NOT NULL
4037 THEN
4038 gmd_outbound_apis_pub.g_wip_formulaline := p_wip_formulaline;
4039 where_clause := where_clause||'AND fmd.line_no = :wip_formulaline ';
4040 using_clause := using_clause||', gmd_outbound_apis_pub.g_wip_formulaline ';
4041 END IF;
4042
4043 IF p_wip_line_type IS NOT NULL
4044 THEN
4045 gmd_outbound_apis_pub.g_wip_line_type := p_wip_line_type;
4046 where_clause := where_clause||'AND fmd.line_type = :wip_line_type ';
4047 using_clause := using_clause||', gmd_outbound_apis_pub.g_wip_line_type ';
4048 END IF;
4049 END IF;
4050
4051 IF p_wip_formulaline_id IS NOT NULL
4052 THEN
4053 gmd_outbound_apis_pub.g_wip_formulaline_id := p_wip_formulaline_id;
4054 where_clause := where_clause||'AND gs.formulaline_id = :wip_formulaline_id ';
4055 using_clause := using_clause||', gmd_outbound_apis_pub.g_wip_formulaline_id ';
4056 END IF;
4057
4058 IF (p_wip_routing_no IS NOT NULL or p_wip_routing_vers IS NOT NULL)
4059 THEN
4060 table_list := table_list ||', gmd_routings_b grout ';
4061 where_clause := where_clause ||'AND gs.routing_id = grout.routing_id ';
4062
4063 IF p_wip_routing_no IS NOT NULL
4064 THEN
4065 gmd_outbound_apis_pub.g_wip_routing_no := p_wip_routing_no;
4066 where_clause := where_clause||'AND grout.routing_no = :wip_routing_no ';
4067 using_clause := using_clause||', gmd_outbound_apis_pub.g_wip_routing_no ';
4068 END IF;
4069
4070 IF p_wip_routing_vers IS NOT NULL
4071 THEN
4072 gmd_outbound_apis_pub.g_wip_routing_vers := p_wip_routing_vers;
4073 where_clause := where_clause||'AND grout.routing_vers = :wip_routing_vers ';
4074 using_clause := using_clause||', gmd_outbound_apis_pub.g_wip_routing_vers ';
4075 END IF;
4076 END IF;
4077
4078 IF p_wip_routing_id IS NOT NULL
4079 THEN
4080 gmd_outbound_apis_pub.g_wip_routing_id := p_wip_routing_id;
4081 where_clause := where_clause||'AND gs.routing_id = :wip_routing_id ';
4082 using_clause := using_clause||', gmd_outbound_apis_pub.g_wip_routing_id ';
4083 END IF;
4084
4085
4086 IF p_wip_batchstep_no IS NOT NULL
4087 THEN
4088 gmd_outbound_apis_pub.g_wip_batchstep_no := p_wip_batchstep_no;
4089 where_clause := where_clause||'AND gs.step_no = :wip_batchstep_no ';
4090 using_clause := using_clause||', gmd_outbound_apis_pub.g_wip_batchstep_no ';
4091 END IF;
4092
4093 IF p_wip_batchstep_id IS NOT NULL
4094 THEN
4095 gmd_outbound_apis_pub.g_wip_batchstep_id := p_wip_batchstep_id;
4096 where_clause := where_clause||'AND gs.step_id = :wip_batchstep_id ';
4097 using_clause := using_clause||', gmd_outbound_apis_pub.g_wip_batchstep_id ';
4098 END IF;
4099
4100 IF (p_wip_oprn_no IS NOT NULL or p_wip_oprn_vers IS NOT NULL )
4101 THEN
4102 table_list := table_list ||', gmd_operations go ';
4103 where_clause := where_clause ||'AND gs.oprn_id = go.oprn_id ';
4104
4105 IF p_wip_oprn_no IS NOT NULL
4106 THEN
4107 gmd_outbound_apis_pub.g_wip_oprn_no := p_wip_oprn_no;
4108 where_clause := where_clause||'AND go.oprn_no = :wip_oprn_no ';
4109 using_clause := using_clause||', gmd_outbound_apis_pub.g_wip_oprn_no ';
4110 END IF;
4111
4112 IF p_wip_oprn_vers IS NOT NULL
4113 THEN
4114 gmd_outbound_apis_pub.g_wip_oprn_vers := p_wip_oprn_vers;
4115 where_clause := where_clause||'AND go.oprn_vers = :wip_oprn_vers ';
4116 using_clause := using_clause||', gmd_outbound_apis_pub.g_wip_oprn_vers ';
4117 END IF;
4118 END IF;
4119
4120 IF p_wip_oprn_id IS NOT NULL
4121 THEN
4122 gmd_outbound_apis_pub.g_wip_oprn_id := p_wip_oprn_id;
4123 where_clause := where_clause||'AND gs.oprn_id = :wip_oprn_id ';
4124 using_clause := using_clause||', gmd_outbound_apis_pub.g_wip_oprn_id ';
4125 END IF;
4126
4127 IF p_cust_name IS NOT NULL
4128 THEN
4129 table_list := table_list ||', hz_cust_accounts_all hca, hz_parties hp ';
4130 where_clause := where_clause ||'AND gs.cust_id = hca.cust_account_id and hca.party_id = hp.party_id ';
4131
4132 gmd_outbound_apis_pub.g_cust_name := p_cust_name;
4133 where_clause := where_clause||'AND hp.party_name = :cust_name ';
4134 using_clause := using_clause||', gmd_outbound_apis_pub.g_cust_name ';
4135 END IF;
4136
4137 IF p_cust_id IS NOT NULL
4138 THEN
4139 gmd_outbound_apis_pub.g_cust_id := p_cust_id;
4140 where_clause := where_clause||'AND gs.cust_id = :cust_id ';
4141 using_clause := using_clause||', gmd_outbound_apis_pub.g_cust_id ';
4142 END IF;
4143
4144 IF p_org_id IS NOT NULL
4145 THEN
4146 gmd_outbound_apis_pub.g_org_id := p_org_id;
4147 where_clause := where_clause||'AND gs.org_id = :org_id ';
4148 using_clause := using_clause||', gmd_outbound_apis_pub.g_org_id ';
4149 END IF;
4150
4151 IF p_cust_ship_to_site_id IS NOT NULL
4152 THEN
4153 gmd_outbound_apis_pub.g_cust_ship_to_site_id := p_cust_ship_to_site_id;
4154 where_clause := where_clause||'AND gs.ship_to_site_id = :cust_ship_to_site_id ';
4155 using_clause := using_clause||', gmd_outbound_apis_pub.g_cust_ship_to_site_id ';
4156 END IF;
4157 -- dbms_output.put_line('after shipto site id');
4158
4159 IF p_cust_order is NOT NULL or p_cust_order_type is NOT NULL
4160 THEN
4161 table_list := table_list ||', oe_order_headers_all ooh ';
4162 where_clause := where_clause ||'AND gs.order_id = ooh.header_id ';
4163
4164 IF p_cust_order IS NOT NULL
4165 THEN
4166 gmd_outbound_apis_pub.g_cust_order := p_cust_order;
4167 where_clause := where_clause||'AND ooh.order_number = :cust_order ';
4168 using_clause := using_clause||', gmd_outbound_apis_pub.g_cust_order ';
4169 END IF;
4170
4171 IF p_cust_order_type IS NOT NULL
4172 THEN
4173 table_list := table_list ||', oe_transaction_types_all ott ';
4174 where_clause := where_clause ||'AND ooh.order_type_id = ott.transaction_type_id ';
4175
4176 gmd_outbound_apis_pub.g_cust_order_type := p_cust_order_type;
4177 where_clause := where_clause||'AND ott.transaction_type_code = :cust_order_type ';
4178 using_clause := using_clause||', gmd_outbound_apis_pub.g_cust_order_type ';
4179 END IF;
4180 END IF;
4181
4182 IF p_cust_order_id IS NOT NULL
4183 THEN
4184 gmd_outbound_apis_pub.g_cust_order_id := p_cust_order_id;
4185 where_clause := where_clause||'AND gs.order_id = :cust_order_id ';
4186 using_clause := using_clause||', gmd_outbound_apis_pub.g_cust_order_id ';
4187 END IF;
4188
4189 IF p_cust_order_line IS NOT NULL
4190 THEN
4191 table_list := table_list ||', oe_order_lines_all ool ';
4192 where_clause := where_clause ||'AND gs.order_line_id = ool.line_id ';
4193
4194 gmd_outbound_apis_pub.g_cust_order_line := p_cust_order_line;
4195 where_clause := where_clause||'AND ool.line_number = :cust_order_line ';
4196 using_clause := using_clause||', gmd_outbound_apis_pub.g_cust_order_line ';
4197 END IF;
4198
4199 IF p_cust_order_line_id IS NOT NULL
4200 THEN
4201 gmd_outbound_apis_pub.g_cust_order_line_id := p_cust_order_line_id;
4202 where_clause := where_clause||'AND gs.order_line_id = :cust_order_line_id ';
4203 using_clause := using_clause||', gmd_outbound_apis_pub.g_cust_order_line_id ';
4204 END IF;
4205
4206 IF p_supplier IS NOT NULL
4207 THEN
4208 table_list := table_list ||', po_vendors v ';
4209 where_clause := where_clause ||'AND gs.supplier_id = v.vendor_id ';
4210
4211 gmd_outbound_apis_pub.g_supplier := p_supplier;
4212 where_clause := where_clause||'AND v.vendor_name = :supplier '; -- 5335829 rework - changed from segment1
4213 using_clause := using_clause||', gmd_outbound_apis_pub.g_supplier ';
4214 END IF;
4215
4216 IF p_supplier_id IS NOT NULL
4217 THEN
4218 gmd_outbound_apis_pub.g_supplier_id := p_supplier_id;
4219 where_clause := where_clause||'AND gs.supplier_id = :supplier_id ';
4220 using_clause := using_clause||', gmd_outbound_apis_pub.g_supplier_id ';
4221 END IF;
4222
4223 IF p_supplier_site_id IS NOT NULL
4224 THEN
4225 gmd_outbound_apis_pub.g_supplier_site_id := p_supplier_site_id;
4226 where_clause := where_clause||'AND gs.supplier_site_id = :supplier_site_id ';
4227 using_clause := using_clause||', gmd_outbound_apis_pub.g_supplier_site_id ';
4228 END IF;
4229
4230 IF p_supplier_po IS NOT NULL
4231 THEN
4232 table_list := table_list ||', po_headers_all ph ';
4233 where_clause := where_clause ||'AND gs.po_header_id = ph.po_header_id ';
4234
4235 gmd_outbound_apis_pub.g_supplier_po := p_supplier_po;
4236 where_clause := where_clause||'AND ph.segment1 = :supplier_po ';
4237 using_clause := using_clause||', gmd_outbound_apis_pub.g_supplier_po ';
4238 END IF;
4239
4240 IF p_supplier_po_id IS NOT NULL
4241 THEN
4242 gmd_outbound_apis_pub.g_supplier_po_id := p_supplier_po_id;
4243 where_clause := where_clause||'AND gs.po_header_id = :supplier_po_id ';
4244 using_clause := using_clause||', gmd_outbound_apis_pub.g_supplier_po_id ';
4245 END IF;
4246
4247 IF p_supplier_po_line IS NOT NULL
4248 THEN
4249 table_list := table_list ||', po_lines_all pl ';
4250 where_clause := where_clause ||'AND gs.po_line_id = pl.po_line_id ';
4251
4252 gmd_outbound_apis_pub.g_supplier_po_line := p_supplier_po_line;
4253 where_clause := where_clause||'AND pl.line_num = :supplier_po_line ';
4254 using_clause := using_clause||', gmd_outbound_apis_pub.g_supplier_po_line ';
4255 END IF;
4256
4257 IF p_supplier_po_line_id IS NOT NULL
4258 THEN
4259 gmd_outbound_apis_pub.g_supplier_po_line_id := p_supplier_po_line_id;
4260 where_clause := where_clause||'AND gs.po_line_id = :supplier_po_line_id ';
4261 using_clause := using_clause||', gmd_outbound_apis_pub.g_supplier_po_line_id ';
4262 END IF;
4263
4264 IF p_from_last_update_date IS NOT NULL
4265 THEN
4266 gmd_outbound_apis_pub.g_from_last_update_date := p_from_last_update_date;
4267 where_clause := where_clause||'AND gs.last_update_date >= :from_last_update_date ';
4268 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_last_update_date ';
4269 END IF;
4270
4271 IF p_to_last_update_date IS NOT NULL
4272 THEN
4273 gmd_outbound_apis_pub.g_to_last_update_date := p_to_last_update_date;
4274 where_clause := where_clause||'AND gs.last_update_date <= :to_last_update_date ';
4275 using_clause := using_clause||', gmd_outbound_apis_pub.g_to_last_update_date ';
4276 END IF;
4277
4278 IF p_delete_mark IS NOT NULL
4279 THEN
4280 gmd_outbound_apis_pub.g_delete_mark := p_delete_mark ;
4281 where_clause := where_clause||'AND gs.delete_mark = :delete_mark ';
4282 using_clause := using_clause||', gmd_outbound_apis_pub.g_delete_mark ';
4283 END IF;
4284
4285 -- START B3124291 Incorporated Mini-Pack K Features to Outboud APIs
4286 IF p_from_date_received IS NOT NULL
4287 THEN
4288 gmd_outbound_apis_pub.g_from_date_received := p_from_date_received;
4289 where_clause := where_clause||'AND gs.date_received >= :from_date_received ';
4290 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_date_received ';
4291 END IF;
4292
4293 IF p_to_date_received IS NOT NULL
4294 THEN
4295 gmd_outbound_apis_pub.g_to_date_received := p_to_date_received;
4296 where_clause := where_clause||'AND gs.date_received <= :to_date_received ';
4297 using_clause := using_clause||', gmd_outbound_apis_pub.g_to_date_received ';
4298 END IF;
4299
4300 IF p_from_date_required IS NOT NULL
4301 THEN
4302 gmd_outbound_apis_pub.g_from_date_required := p_from_date_required;
4303 where_clause := where_clause||'AND gs.date_required >= :from_date_required ';
4304 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_date_required ';
4305 END IF;
4306
4307 IF p_to_date_required IS NOT NULL
4308 THEN
4309 gmd_outbound_apis_pub.g_to_date_required := p_to_date_required;
4310 where_clause := where_clause||'AND gs.date_required <= :to_date_required ';
4311 using_clause := using_clause||', gmd_outbound_apis_pub.g_to_date_required ';
4312 END IF;
4313
4314 IF p_resources IS NOT NULL
4315 THEN
4316 gmd_outbound_apis_pub.g_resources := p_resources;
4317 where_clause := where_clause||'AND gs.resources = :resources ';
4318 using_clause := using_clause||', gmd_outbound_apis_pub.g_resources ';
4319 END IF;
4320
4321 -- dbms_output.put_line('after resources');
4322 IF p_instance_id IS NOT NULL
4323 THEN
4324 gmd_outbound_apis_pub.g_instance_id := p_instance_id;
4325 where_clause := where_clause||'AND gs.instance_id = :instance_id ';
4326 using_clause := using_clause||', gmd_outbound_apis_pub.g_instance_id ';
4327 END IF;
4328
4329 IF p_from_retrieval_date IS NOT NULL
4330 THEN
4331 gmd_outbound_apis_pub.g_from_retrieval_date := p_from_retrieval_date;
4332 where_clause := where_clause||'AND gs.retrieval_date >= :from_retrieval_date ';
4333 using_clause := using_clause||', gmd_outbound_apis_pub.g_from_retrieval_date ';
4334 END IF;
4335
4336 IF p_to_retrieval_date IS NOT NULL
4337 THEN
4338 gmd_outbound_apis_pub.g_to_retrieval_date := p_to_retrieval_date;
4339 where_clause := where_clause||'AND gs.retrieval_date <= :to_retrieval_date ';
4340 using_clause := using_clause||', gmd_outbound_apis_pub.g_to_retrieval_date ';
4341 END IF;
4342
4343 IF p_sample_type IS NOT NULL
4344 THEN
4345 gmd_outbound_apis_pub.g_sample_type := p_sample_type;
4346 where_clause := where_clause||'AND gs.sample_type = :sample_type ';
4347 using_clause := using_clause||', gmd_outbound_apis_pub.g_sample_type ';
4348 END IF;
4349
4350 l_ss_table_included := 'FALSE';
4351 IF (p_ss_organization_id IS NOT NULL OR p_ss_no IS NOT NULL OR p_ss_id IS NOT NULL) THEN
4352 table_list := table_list ||', gmd_stability_studies_b ss, gmd_ss_variants ssv ';
4353 where_clause := where_clause ||'AND ss.ss_id = ssv.ss_id AND ssv.variant_id = gs.variant_id ';
4354 l_ss_table_included := 'TRUE';
4355
4356 IF p_ss_id IS NOT NULL
4357 THEN
4358 gmd_outbound_apis_pub.g_ss_id := p_ss_id;
4359 where_clause := where_clause||'AND ss.ss_id = :ss_id ';
4360 using_clause := using_clause||', gmd_outbound_apis_pub.g_ss_id ';
4361 END IF;
4362
4363 IF p_ss_organization_id IS NOT NULL
4364 THEN
4365 gmd_outbound_apis_pub.g_ss_organization_id := p_ss_organization_id;
4366 where_clause := where_clause||'AND ss.organization_id = :ss_organization_id ';
4367 using_clause := using_clause||', gmd_outbound_apis_pub.g_ss_organization_id ';
4368 END IF;
4369
4370 IF p_ss_no IS NOT NULL
4371 THEN
4372 gmd_outbound_apis_pub.g_ss_no := p_ss_no;
4373 where_clause := where_clause||'AND ss.ss_no = :ss_no ';
4374 using_clause := using_clause||', gmd_outbound_apis_pub.g_ss_no ';
4375 END IF;
4376
4377 END IF;
4378
4379 IF p_variant_no IS NOT NULL
4380 THEN
4381 IF (l_ss_table_included = 'FALSE') THEN
4382 table_list := table_list ||', gmd_ss_variants ssv ';
4383 where_clause := where_clause ||'AND ssv.variant_id = gs.variant_id ';
4384 END IF;
4385
4386 gmd_outbound_apis_pub.g_variant_no := p_variant_no;
4387 where_clause := where_clause||'AND ssv.variant_no = :variant_no ';
4388 using_clause := using_clause||', gmd_outbound_apis_pub.g_variant_no ';
4389 END IF;
4390
4391 IF p_variant_id IS NOT NULL
4392 THEN
4393 gmd_outbound_apis_pub.g_variant_id := p_variant_id;
4394 where_clause := where_clause||'AND gs.variant_id = :variant_id ';
4395 using_clause := using_clause||', gmd_outbound_apis_pub.g_variant_id ';
4396 END IF;
4397 -- dbms_output.put_line('after variant_id');
4398
4399 IF p_time_point_id IS NOT NULL
4400 THEN
4401 gmd_outbound_apis_pub.g_time_point_id := p_time_point_id;
4402 where_clause := where_clause||'AND gs.time_point_id = :time_point_id ';
4403 using_clause := using_clause||', gmd_outbound_apis_pub.g_time_point_id ';
4404 END IF;
4405
4406 -- END B3124291 Incorporated Mini-Pack K Features to Outboud APIs
4407
4408 -- START Incorporated Mini-Pack L Features to Outboud APIs
4409 IF p_retain_as IS NOT NULL
4410 THEN
4411 gmd_outbound_apis_pub.g_retain_as := p_retain_as;
4412 where_clause := where_clause||'AND gs.retain_as = :retain_as ';
4413 using_clause := using_clause||', gmd_outbound_apis_pub.g_retain_as ';
4414 END IF;
4415
4416 -- END Incorporated Mini-Pack L Features to Outboud APIs
4417
4418 -- 7027149
4419
4420 IF p_lpn_id IS NOT NULL
4421 THEN
4422 gmd_outbound_apis_pub.g_lpn_id := p_lpn_id;
4423 where_clause := where_clause||'AND gs.lpn_id = :lpn_id ';
4424 using_clause := using_clause||', gmd_outbound_apis_pub.g_lpn_id ';
4425 END IF;
4426
4427 IF p_lpn IS NOT NULL
4428 THEN
4429 table_list := table_list ||', wms_license_plate_numbers lpn ';
4430 where_clause := where_clause ||'AND gs.lpn_id = lpn.lpn_id ';
4431
4432 gmd_outbound_apis_pub.g_lpn := p_lpn;
4433 where_clause := where_clause||'AND lpn.license_plate_number = :lpn ';
4434 using_clause := using_clause||', gmd_outbound_apis_pub.g_lpn ';
4435 gme_debug.put_line('in IF p_lpn IS NOT NULL ');
4436
4437
4438 END IF;
4439
4440
4441
4442 -- That's more or less the job done. We just need to tell the system where to store the data
4443
4444 into_clause := ' BULK COLLECT INTO gmd_outbound_apis_pub.g_samples_table ';
4445
4446 execution_string := 'BEGIN EXECUTE IMMEDIATE '
4447 ||''''
4448 ||sql_statement||column_list||table_list||where_clause
4449 ||''''
4450 ||into_clause
4451 ||using_clause
4452 ||'; END;';
4453
4454 gme_debug.put_line('The sql statement is:');
4455
4456
4457 -- dbms_output.put_line('The sql statement is:');
4458 i:= 1;
4459 LOOP
4460 -- dbms_output.put_line(substr(execution_string, i, 100));
4461 gme_debug.put_line(substr(execution_string, i, 100));
4462 EXIT WHEN i> LENGTH(execution_string);
4463 i := i+100;
4464 END LOOP;
4465
4466 -- dbms_output.put_line('Executing stringxxx');
4467 gme_debug.put_line('Executing string');
4468 EXECUTE IMMEDIATE execution_string;
4469 gme_debug.put_line('out of executing string ');
4470 -- Now fill in any missing data
4471
4472 -- dbms_output.put_line('filling in missing data');
4473 FOR i IN 1..g_samples_table.count
4474 LOOP
4475 gme_debug.put_line('sample no=' || g_samples_table(i).sample_no);
4476 IF g_samples_table(i).spec_id is not NULL
4477 THEN
4478 gme_debug.put_line('select from gmd_specifications_b using spec_id of '
4479 || g_samples_table(i).spec_id);
4480 select spec_name, spec_vers into g_samples_table(i).spec_name,g_samples_table(i).spec_vers
4481 from gmd_specifications_b
4482 where spec_id = g_samples_table(i).spec_id;
4483 END IF;
4484
4485 IF g_samples_table(i).inventory_item_id is not NULL
4486 THEN
4487 -- dbms_output.put_line('select from mtl_system_items using inventory_item_id of '|| g_samples_table(i).inventory_item_id);
4488 -- dbms_output.put_line('filling in missing data');
4489 select concatenated_segments into g_samples_table(i).item_number
4490 from mtl_system_items_b_kfv
4491 where inventory_item_id = g_samples_table(i).inventory_item_id
4492 and organization_id = g_samples_table(i).organization_id;
4493 END IF;
4494
4495 IF g_samples_table(i).batch_id is not NULL
4496 THEN
4497 -- dbms_output.put_line('select from gme_batch_header with batch_id of '|| g_samples_table(i).batch_id);
4498 select plant_code, batch_no into g_samples_table(i).plant_code,g_samples_table(i).batch_no
4499 from gme_batch_header
4500 where batch_id = g_samples_table(i).batch_id;
4501 END IF;
4502
4503 IF g_samples_table(i).recipe_id is not NULL
4504 THEN
4505 -- dbms_output.put_line('select from gmd_recipes_b with recipe_id of '|| g_samples_table(i).recipe_id);
4506 select recipe_no, recipe_version into g_samples_table(i).recipe_no,
4507 g_samples_table(i).recipe_version
4508 from gmd_recipes_b
4509 where recipe_id = g_samples_table(i).recipe_id;
4510 END IF;
4511
4512 IF g_samples_table(i).formula_id is not NULL
4513 THEN
4514 -- dbms_output.put_line('select from fm_form_mst with formula_id of '|| g_samples_table(i).formula_id);
4515 select formula_no, formula_vers into g_samples_table(i).formula_no,
4516 g_samples_table(i).formula_vers
4517 from fm_form_mst
4518 where formula_id = g_samples_table(i).formula_id;
4519 END IF;
4520
4521 IF g_samples_table(i).formulaline_id is not NULL
4522 THEN
4523 --dbms_output.put_line('select from fm_matl_dtl with formulaline_id of '
4524 -- || g_samples_table(i).formulaline_id);
4525 select line_no, line_type into g_samples_table(i).formulaline_no,
4526 g_samples_table(i).line_type
4527 from fm_matl_dtl
4528 where formulaline_id = g_samples_table(i).formulaline_id;
4529 END IF;
4530
4531 IF g_samples_table(i).routing_id is not NULL
4532 THEN
4533 --dbms_output.put_line('select from gmd_routings_b with routing_id of '
4534 -- || g_samples_table(i).routing_id);
4535 select routing_no, routing_vers into g_samples_table(i).routing_no,g_samples_table(i).routing_vers
4536 from gmd_routings_b
4537 where routing_id = g_samples_table(i).routing_id;
4538 END IF;
4539
4540 IF g_samples_table(i).oprn_id is not NULL
4541 THEN
4542 --dbms_output.put_line('select from gmd_operations with oprn_id of '|| g_samples_table(i).oprn_id);
4543 select oprn_no, oprn_vers into g_samples_table(i).oprn_no,g_samples_table(i).oprn_vers
4544 from gmd_operations
4545 where oprn_id = g_samples_table(i).oprn_id;
4546 END IF;
4547
4548 IF g_samples_table(i).cust_id is not NULL
4549 THEN
4550 --dbms_output.put_line('select from hz_cust_accounts_all with cust_id of '
4551 -- || g_samples_table(i).cust_id);
4552 select hp.party_name into g_samples_table(i).cust_name
4553 from hz_cust_accounts_all hca,hz_parties hp
4554 where hca.cust_account_id = g_samples_table(i).cust_id
4555 and hca.party_id = hp.party_id;
4556 END IF;
4557
4558 IF g_samples_table(i).order_id is not NULL
4559 THEN
4560 --dbms_output.put_line('select from oe_order_headers_all with header_id of '
4561 -- || g_samples_table(i).order_id);
4562 select ooh.order_number, ott.transaction_type_code into
4563 g_samples_table(i).order_number, g_samples_table(i).order_type
4564 from oe_order_headers_all ooh, oe_transaction_types_all ott
4565 where ooh.header_id = g_samples_table(i).order_id and
4566 ooh.order_type_id = ott.transaction_type_id ;
4567 END IF;
4568
4569 IF g_samples_table(i).order_line_id is not NULL
4570 THEN
4571 --dbms_output.put_line('select from oe_order_lines_all with line_id of '
4572 -- || g_samples_table(i).order_line_id);
4573 select line_number into g_samples_table(i).order_line_number
4574 from oe_order_lines_all
4575 where line_id = g_samples_table(i).order_line_id;
4576 END IF;
4577
4578 IF g_samples_table(i).org_id is not NULL
4579 THEN
4580 --dbms_output.put_line('select from hr_operating_units using org_id of '|| g_samples_table(i).org_id);
4581 select name into g_samples_table(i).org_name
4582 from hr_operating_units
4583 where organization_id = g_samples_table(i).org_id;
4584 END IF;
4585
4586 IF g_samples_table(i).supplier_id is not NULL
4587 THEN
4588 --dbms_output.put_line('select from po_vendors using vendor_id of '|| g_samples_table(i).supplier_id);
4589 select segment1 into g_samples_table(i).supplier_no
4590 from po_vendors
4591 where vendor_id = g_samples_table(i).supplier_id;
4592 END IF;
4593
4594 IF g_samples_table(i).sampler_id is not NULL
4595 THEN
4596 --dbms_output.put_line('select from fnd_user using user_id of '|| g_samples_table(i).sampler_id);
4597 select user_name into g_samples_table(i).sampler
4598 from fnd_user
4599 where user_id = g_samples_table(i).sampler_id;
4600 END IF;
4601
4602 IF g_samples_table(i).po_header_id is not NULL
4603 THEN
4604 --dbms_output.put_line('select from po_headers_all with po_header_id of '
4605 -- || g_samples_table(i).po_header_id);
4606 select segment1 into g_samples_table(i).po_number
4607 from po_headers_all
4608 where po_header_id = g_samples_table(i).po_header_id;
4609 END IF;
4610
4611 IF g_samples_table(i).supplier_site_id is not NULL
4612 THEN
4613 --dbms_output.put_line('select from po_vendor_sites_all with supplier_site_id of '
4614 -- || g_samples_table(i).supplier_site_id);
4615 select vendor_site_code into g_samples_table(i).supplier_site
4616 from po_vendor_sites_all
4617 where vendor_site_id = g_samples_table(i).supplier_site_id;
4618 END IF;
4619
4620 IF g_samples_table(i).po_line_id is not NULL
4621 THEN
4622 --dbms_output.put_line('select from po_lines_all with po_line_id of '
4623 -- || g_samples_table(i).po_line_id);
4624 select line_num into g_samples_table(i).po_line_number
4625 from po_lines_all
4626 where po_line_id = g_samples_table(i).po_line_id;
4627 END IF;
4628
4629 IF g_samples_table(i).receipt_id is not NULL
4630 THEN
4631 --dbms_output.put_line('select from rcv_shipment_headers with shipment_header_id of '
4632 -- || g_samples_table(i).receipt_id);
4633 select receipt_num into g_samples_table(i).receipt_no
4634 from rcv_shipment_headers
4635 where shipment_header_id = g_samples_table(i).receipt_id;
4636 END IF;
4637
4638 IF g_samples_table(i).receipt_line_id is not NULL
4639 THEN
4640 -- Bug 3970893: receipt line id is changed from transaction if to shipment line id
4641 --dbms_output.put_line('select from rcv_shipment_lines with shipment_line_id of '
4642 -- || g_samples_table(i).receipt_line_id);
4643 select rsl.line_num into g_samples_table(i).receipt_line
4644 from rcv_shipment_lines rsl
4645 where rsl.shipment_line_id = g_samples_table(i).receipt_line_id;
4646 END IF;
4647
4648 IF g_samples_table(i).ship_to_site_id is not NULL
4649 THEN
4650 --dbms_output.put_line('select from hz_cust_site_uses_all with site_use_id of '
4651 -- || g_samples_table(i).ship_to_site_id);
4652 SELECT location into g_samples_table(i).ship_to_location
4653 FROM hz_cust_site_uses_all
4654 WHERE site_use_id = g_samples_table(i).ship_to_site_id;
4655 END IF;
4656
4657 --7027149 Added sql to get LPN from id
4658 IF g_samples_table(i).lpn_id is not NULL
4659 THEN
4660 SELECT license_plate_number into g_samples_table(i).lpn
4661 FROM wms_license_plate_numbers
4662 WHERE lpn_id = g_samples_table(i).lpn_id;
4663 END IF;
4664
4665
4666
4667
4668
4669 END LOOP;
4670
4671 x_samples_table := gmd_outbound_apis_pub.g_samples_table;
4672 x_return_status := FND_API.G_RET_STS_SUCCESS;
4673 -- dbms_output.put_line('Returning table to caller');
4674
4675 gme_debug.put_line('Returning table to caller');
4676
4677
4678
4679
4680
4681
4682 END IF;
4683
4684 FND_MSG_PUB.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4685 -- dbms_output.put_line('Finished FETCH_SAMPLES');
4686
4687 EXCEPTION
4688 WHEN OTHERS
4689 THEN
4690
4691 FND_MESSAGE.SET_NAME('GMD',SQLCODE);
4692 FND_MSG_PUB.Add;
4693 FND_MSG_PUB.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4694 gme_debug.put_line('exception sqlcode = '
4695 || SQLCODE );
4696 x_return_status := FND_API.G_RET_STS_ERROR;
4697
4698
4699 END fetch_samples;
4700
4701
4702 PROCEDURE fetch_sample_groups
4703 ( p_api_version IN NUMBER
4704 , p_init_msg_list IN VARCHAR2 DEFAULT FND_API.G_FALSE
4705 , p_user_name IN VARCHAR2
4706 , p_organization_id IN VARCHAR2 DEFAULT NULL
4707 , p_from_sample_no IN VARCHAR2 DEFAULT NULL
4708 , p_to_sample_no IN VARCHAR2 DEFAULT NULL
4709 , p_sample_event_id IN NUMBER DEFAULT NULL
4710 , p_from_item_number IN VARCHAR2 DEFAULT NULL
4711 , p_to_item_number IN VARCHAR2 DEFAULT NULL
4712 , p_inventory_item_id IN NUMBER DEFAULT NULL
4713 , p_revision IN NUMBER DEFAULT NULL
4714 , p_from_lot_number IN VARCHAR2 DEFAULT NULL
4715 , p_to_lot_number IN VARCHAR2 DEFAULT NULL
4716 , p_from_parent_lot_number IN VARCHAR2 DEFAULT NULL
4717 , p_to_parent_lot_number IN VARCHAR2 DEFAULT NULL
4718 , p_disposition IN VARCHAR2 DEFAULT NULL
4719 , p_subinventory IN VARCHAR2 DEFAULT NULL
4720 , p_locator_id IN VARCHAR2 DEFAULT NULL
4721 , p_wip_organization_id IN VARCHAR2 DEFAULT NULL
4722 , p_wip_batch_no IN VARCHAR2 DEFAULT NULL
4723 , p_wip_batch_id IN NUMBER DEFAULT NULL
4724 , p_wip_recipe_no IN VARCHAR2 DEFAULT NULL
4725 , p_wip_recipe_vers IN NUMBER DEFAULT NULL
4726 , p_wip_recipe_id IN NUMBER DEFAULT NULL
4727 , p_wip_formula_no IN VARCHAR2 DEFAULT NULL
4728 , p_wip_formula_vers IN NUMBER DEFAULT NULL
4729 , p_wip_formula_id IN NUMBER DEFAULT NULL
4730 , p_wip_formulaline_no IN NUMBER DEFAULT NULL
4731 , p_wip_formulaline_id IN NUMBER DEFAULT NULL
4732 , p_wip_formulaline_type IN NUMBER DEFAULT NULL
4733 , p_wip_routing_no IN VARCHAR2 DEFAULT NULL
4734 , p_wip_routing_vers IN NUMBER DEFAULT NULL
4735 , p_wip_routing_id IN NUMBER DEFAULT NULL
4736 , p_wip_step_no IN NUMBER DEFAULT NULL
4737 , p_wip_step_id IN NUMBER DEFAULT NULL
4738 , p_wip_oprn_no IN VARCHAR2 DEFAULT NULL
4739 , p_wip_oprn_vers IN NUMBER DEFAULT NULL
4740 , p_wip_oprn_id IN NUMBER DEFAULT NULL
4741 , p_customer IN NUMBER DEFAULT NULL
4742 , p_customer_id IN VARCHAR2 DEFAULT NULL
4743 , p_customer_org_id IN NUMBER DEFAULT NULL
4744 , p_customer_ship_to_location IN VARCHAR2 DEFAULT NULL
4745 , p_customer_ship_to_location_id IN NUMBER DEFAULT NULL
4746 , p_customer_order_number IN NUMBER DEFAULT NULL
4747 , p_customer_order_id IN NUMBER DEFAULT NULL
4748 , p_customer_order_type IN NUMBER DEFAULT NULL
4749 , p_customer_order_line IN NUMBER DEFAULT NULL
4750 , p_customer_order_line_id IN NUMBER DEFAULT NULL
4751 , p_supplier IN NUMBER DEFAULT NULL
4752 , p_supplier_id IN NUMBER DEFAULT NULL
4753 , p_supplier_site IN VARCHAR2 DEFAULT NULL
4754 , p_supplier_po_number IN VARCHAR2 DEFAULT NULL
4755 , p_supplier_po_id IN NUMBER DEFAULT NULL
4756 , p_supplier_po_line IN NUMBER DEFAULT NULL
4757 , p_supplier_po_line_id IN NUMBER DEFAULT NULL
4758 , p_delete_mark IN NUMBER DEFAULT NULL
4759 , p_from_last_update_date IN DATE DEFAULT NULL
4760 , p_to_last_update_date IN DATE DEFAULT NULL
4761 -- START B3124291 Incorporated Mini-Pack K Features to Outboud APIs
4762 , p_sg_organization_id IN VARCHAR2 DEFAULT NULL
4763 , p_resources IN VARCHAR2 DEFAULT NULL
4764 , p_instance_id IN NUMBER DEFAULT NULL
4765 , p_ss_id IN NUMBER DEFAULT NULL
4766 , p_ss_organization_id IN VARCHAR2 DEFAULT NULL
4767 , p_ss_no IN VARCHAR2 DEFAULT NULL
4768 , p_variant_id IN NUMBER DEFAULT NULL
4769 , p_variant_no IN NUMBER DEFAULT NULL
4770 , p_time_point_id IN NUMBER DEFAULT NULL
4771 -- END B3124291 Incorporated Mini-Pack K Features to Outboud APIs
4772 , x_sample_groups_table OUT NOCOPY system.gmd_sampling_events_tab_type
4773 , x_return_status OUT NOCOPY VARCHAR2
4774 , x_msg_count OUT NOCOPY NUMBER
4775 , x_msg_data OUT NOCOPY VARCHAR2
4776 )
4777 IS
4778 sql_statement VARCHAR2(32000);
4779
4780 main_column_list VARCHAR2(10000);
4781 disp_column_list VARCHAR2(10000);
4782
4783 main_table_list VARCHAR2(10000);
4784 disp_table_list VARCHAR2(10000);
4785
4786 main_where_clause VARCHAR2(10000);
4787 disp_where_clause VARCHAR2(10000);
4788
4789 main_using_clause VARCHAR2(10000);
4790 disp_using_clause VARCHAR2(10000);
4791
4792 main_into_clause VARCHAR2(10000);
4793 main_execution_string VARCHAR2(10000);
4794
4795 row_count NUMBER;
4796 l_api_name VARCHAR2(240) := 'fetch_sample_groups';
4797
4798 string_length NUMBER;
4799 i NUMBER;
4800
4801 l_ss_table_included VARCHAR2(10);
4802
4803 BEGIN
4804
4805 IF NOT FND_API.Compatible_API_CALL
4806 (gmd_outbound_apis_pub.api_version, p_api_version, l_api_name,'GMD_OUTBOUND_APIS_PUB')
4807 OR NOT initialized_ok(p_user_name)
4808 THEN
4809 Raise FND_API.G_EXC_UNEXPECTED_ERROR;
4810 ELSE
4811 --dbms_output.put_line('Starting Fetch_Sample_Groups');
4812
4813 /* Initialize message list if p_int_msg_list is set TRUE. */
4814 IF FND_API.to_boolean(p_init_msg_list)
4815 THEN
4816 FND_MSG_PUB.Initialize;
4817 END IF;
4818
4819 -- Start construction for the select.
4820 --dbms_output.put_line('Starting statement construction');
4821
4822 sql_statement := 'SELECT ';
4823
4824 -- Build the query to retrieve all base rows from gmd_sampling events together with
4825 -- linked nested rowsets from gmd_event_spec_disp
4826 --
4827 -- The code looks worse than it is. All the next few sections do is build SQL
4828 -- clauses that are then glued together and executed dynamically with binds,
4829 -- depending on what has been specified in the parameters.
4830 --
4831 -- By doing one large BULK COLLECT using the constructed statement, almost everything
4832 -- is retrieved in a single hit, including all of the nested data. All that we need to
4833 -- do afterwards is fill in the gaps where a direct retrieval is not possible due to
4834 -- nullable columns where we cannot make outer joins.
4835 --
4836 -- The end result will resemble:
4837
4838 /* SELECT gmd_sampling_event_rec_type
4839 ( <gmd_sampling_events table columns>
4840 , CAST
4841 ( MULTISET
4842 ( gmd_event_spec_disp_rec_type
4843 ( SELECT <gmd_event_spec_disp table columns>
4844 FROM <gmd_event_spec_disp table set>
4845 where <GMD_EVENT_SPEC_DISP CONDITIONS WITH BIND VARIABLES> ***
4846 )
4847 AS gmd_event_spec_disps_tab_type
4848 )
4849 )
4850 )
4851 FROM
4852 <main table list>
4853 WHERE
4854 <sampling events constraining conditions with binds> ****
4855 */
4856
4857 -- Here goes.....
4858
4859 main_column_list :=' se.RECEIPT_ID, rh.RECEIPT_NUM, se.PO_HEADER_ID , ph.SEGMENT1'
4860 ||', se.SAMPLING_EVENT_ID, se.ORIGINAL_SPEC_VR_ID, se.DISPOSITION'
4861 ||', se.SAMPLE_REQ_CNT, se.SAMPLE_TAKEN_CNT, se.SAMPLING_PLAN_ID'
4862 ||', se.EVENT_TYPE_CODE, se.SAMPLING_EVENT_ID, se.inventory_item_id, im.concatenated_segments'
4863 ||', se.lot_number, se.parent_lot_number, se.subinventory, se.locator_id'
4864 ||', se.BATCH_ID, bh.BATCH_NO, se.RECIPE_ID, r.RECIPE_NO'
4865 ||', r.RECIPE_VERSION, se.FORMULA_ID, fh.FORMULA_NO, fh.FORMULA_VERS'
4866 ||', se.FORMULALINE_ID, fd.LINE_NO, se.ROUTING_ID, se.OPRN_ID'
4867 ||', se.CHARGE, se.CUST_ID, NULL, se.ORDER_ID, oh.ORDER_NUMBER'
4868 ||', se.ORDER_LINE_ID, ol.line_number, se.ORG_ID, mp.organization_code, se.SUPPLIER_ID'
4869 ||', NULL, se.PO_LINE_ID, pl.LINE_NUM, se.RECEIPT_LINE_ID'
4870 ||', NULL, se.SUPPLIER_LOT_NO, se.COMPLETE_IND'
4871 ||', se.SAMPLE_ID_TO_EVALUATE, se.COMPOSITE_ID_TO_EVALUATE, se.TEXT_CODE'
4872 ||', se.CREATION_DATE, se.CREATED_BY, fu1.USER_NAME, se.LAST_UPDATED_BY'
4873 ||', fu2.USER_NAME, se.LAST_UPDATE_DATE, se.LAST_UPDATE_LOGIN'
4874 ||', se.SUPPLIER_SITE_ID, NULL, se.SHIP_TO_SITE_ID, NULL'
4875 ||', se.STEP_ID, se.STEP_NO, se.LOT_RETEST_IND, se.RECOMPOSITE_IND'
4876 ||', se.SAMPLE_ACTIVE_CNT '
4877 ||', se.organization_id, se.resources, se.instance_id, se.time_point_id '
4878 ||', se.variant_id, se.archived_taken, se.reserved_taken ';
4879
4880 main_table_list :=' gmd_sampling_events se, rcv_shipment_headers rh, po_headers_all ph'
4881 ||',gme_batch_header bh, fnd_user fu1, fnd_user fu2, gmd_recipes_b r'
4882 ||',fm_form_mst_b fh, oe_order_headers_all oh, mtl_system_items_b im'
4883 ||',po_lines_all pl, oe_order_lines_all ol, fm_matl_dtl fd'
4884 ||',mtl_parameters mp';
4885
4886 main_where_clause:=' 1=:dummy AND se.receipt_id = rh.shipment_header_id(+)'
4887 ||' AND se.po_header_id = ph.po_header_id(+)'
4888 ||' AND se.inventory_item_id = im.inventory_item_id(+)'
4889 ||' AND se.batch_id = bh.batch_id(+)'
4890 ||' AND se.recipe_id = r.recipe_id(+)'
4891 ||' AND se.formula_id = fh.formula_id(+)'
4892 ||' AND se.order_id = oh.header_id(+)'
4893 ||' AND se.po_line_id = pl.po_line_id(+)'
4894 ||' AND se.order_line_id = ol.line_id(+)'
4895 ||' AND se.formulaline_id = fd.formulaline_id(+)'
4896 ||' AND se.org_id = mp.organization_id(+)'
4897 ||' AND se.created_by = fu1.user_id'
4898 ||' AND se.last_updated_by = fu2.user_id';
4899
4900 main_using_clause:='1';
4901
4902 disp_column_list :=' sd.EVENT_SPEC_DISP_ID, sd.SPEC_ID, gs.SPEC_NAME, gs.SPEC_VERS'
4903 ||',sd.SPEC_VR_ID, sd.DISPOSITION, sd.SPEC_USED_FOR_LOT_ATTRIB_IND'
4904 ||',sd.DELETE_MARK, sd.CREATION_DATE, sd.CREATED_BY, fu3.USER_NAME'
4905 ||',sd.LAST_UPDATE_DATE, sd.LAST_UPDATED_BY, fu4.USER_NAME, sd.LAST_UPDATE_LOGIN';
4906
4907 disp_table_list :=' gmd_event_spec_disp sd, gmd_specifications_b gs, fnd_user fu3, fnd_user fu4';
4908
4909 disp_where_clause:=' sd.spec_id = gs.spec_id(+) AND sd.created_by = fu3.user_id'
4910 ||' AND sd.last_updated_by = fu4.user_id'
4911 ||' AND sd.sampling_event_id = se.sampling_event_id'
4912 ||' AND 1=:dummy ';
4913 disp_using_clause:='1';
4914
4915 -- Bug 3124620; Changed where clause to validate the orgn_code
4916 IF p_organization_id IS NOT NULL
4917 THEN
4918 g_orgn_id := p_organization_id;
4919 main_where_clause := main_where_clause
4920 ||' AND se.organization_id = :organization_id';
4921 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_orgn_id';
4922 END IF;
4923
4924 IF p_from_sample_no IS NOT NULL OR p_to_sample_no IS NOT NULL
4925 THEN
4926 main_table_list := main_table_list||', gmd_samples gsa';
4927 main_where_clause := main_where_clause||' AND se.sampling_event_id = gsa.sampling_event_id';
4928
4929 IF p_from_sample_no IS NOT NULL
4930 THEN
4931 g_from_sample_no := p_from_sample_no;
4932 main_where_clause := main_where_clause||' AND gsa.sample_no >= :from_sample';
4933 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_from_sample_no';
4934 END IF;
4935
4936 IF p_to_sample_no IS NOT NULL
4937 THEN
4938 g_to_sample_no := p_to_sample_no;
4939 main_where_clause := main_where_clause||' AND gsa.sample_no <= :to_sample';
4940 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_to_sample_no';
4941 END IF;
4942 END IF;
4943
4944 /* Bug 3124627 - changed event_id to sampling_event_id */
4945 IF p_sample_event_id IS NOT NULL
4946 THEN
4947 g_sample_event_id := p_sample_event_id;
4948 main_where_clause := main_where_clause||
4949 ' AND se.sampling_event_id = :sampling_event_id';
4950 main_using_clause := main_using_clause||
4951 ', gmd_outbound_apis_pub.g_sample_event_id';
4952 END IF;
4953
4954 IF (p_from_item_number IS NOT NULL OR p_to_item_number IS NOT NULL ) THEN
4955 g_from_item_number := p_from_item_number;
4956 g_to_item_number := p_to_item_number;
4957 main_where_clause := main_where_clause
4958 ||' AND gs.inventory_item_id IN (SELECT inventory_item_id FROM mtl_system_items_b_kfv'
4959 ||' WHERE concatenated_segments BETWEEN :from_item_number AND :to_item_number'
4960 ||' AND organization_id = gs.owner_organization_id)';
4961 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_from_item_number, gmd_outbound_apis_pub.g_to_item_number';
4962 END IF; -- (p_from_item_number IS NOT NULL OR p_to_item_number IS NOT NULL )
4963
4964 -- Bug 4165704 invconv: code replaced by above
4965 --IF p_from_item_number IS NOT NULL THEN
4966 --g_from_item_number := p_from_item_number;
4967 --main_where_clause := main_where_clause||' AND im.item_number >= :from_item';
4968 --main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_from_item_number';
4969 --END IF;
4970 --IF p_to_item_number IS NOT NULL THEN
4971 --g_to_item_number := p_to_item_number;
4972 --main_where_clause := main_where_clause||' AND im.item_number <= :to_item';
4973 --main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_to_item_number';
4974 --END IF;
4975
4976 IF p_inventory_item_id IS NOT NULL
4977 THEN
4978 g_inventory_item_id := p_inventory_item_id;
4979 main_where_clause := main_where_clause||' AND se.inventory_item_id = :inventory_item_id';
4980 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_inventory_item_id';
4981 END IF;
4982
4983 IF p_from_lot_number IS NOT NULL
4984 THEN
4985 g_from_lot_number := p_from_lot_number;
4986 main_where_clause := main_where_clause||' AND se.lot_number >= :from_lot_number';
4987 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_from_lot_number';
4988 END IF;
4989
4990 IF p_to_lot_number IS NOT NULL
4991 THEN
4992 g_to_lot_number := p_to_lot_number;
4993 main_where_clause := main_where_clause||' AND se.lot_number <= :to_lot_number';
4994 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_to_lot_number';
4995 END IF;
4996
4997 IF p_from_parent_lot_number IS NOT NULL
4998 THEN
4999 g_from_parent_lot_number := p_from_parent_lot_number;
5000 main_where_clause := main_where_clause||' AND se.parent_lot_number >= :from_parent_lot_number';
5001 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_from_parent_lot_number';
5002 END IF;
5003
5004 IF p_to_parent_lot_number IS NOT NULL
5005 THEN
5006 g_to_parent_lot_number := p_to_parent_lot_number;
5007 main_where_clause := main_where_clause||' AND se.parent_lot_number <= :to_parent_lot_number';
5008 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_to_parent_lot_number';
5009 END IF;
5010
5011 /* taken out for bug 4165704
5012 IF p_lot_id IS NOT NULL
5013 THEN
5014 g_lot_id := p_lot_id;
5015 main_where_clause := main_where_clause||' AND se.lot_id = :lot_id';
5016 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_lot_id';
5017 END IF;
5018 */
5019
5020 IF p_subinventory IS NOT NULL
5021 THEN
5022 g_subinventory := p_subinventory;
5023 main_where_clause := main_where_clause||' AND se.subinventory = :subinventory';
5024 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_subinventory';
5025 END IF;
5026
5027 IF p_locator_id IS NOT NULL
5028 THEN
5029 g_locator_id := p_locator_id;
5030 main_where_clause := main_where_clause||' AND se.locator_id = :locator_id';
5031 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_locator_id';
5032 END IF;
5033
5034 /* taken out for invconv bug 4165704
5035 IF p_location_id IS NOT NULL
5036 THEN
5037 g_location_id := p_location_id;
5038 main_table_list := main_table_list||', ic_loct_mst lm';
5039 main_where_clause := main_where_clause||' AND se.location = il.location'
5040 ||' AND il.inventory_location_id = :location_id';
5041 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_location_id';
5042 END IF;
5043 */
5044
5045 IF p_wip_organization_id IS NOT NULL
5046 THEN
5047 g_wip_orgn_id := p_wip_organization_id;
5048 main_where_clause := main_where_clause||' AND bh.plant_code = :wip_organization_id';
5049 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_orgn_id';
5050 END IF;
5051
5052 IF p_wip_batch_no IS NOT NULL
5053 THEN
5054 g_wip_batch_no := p_wip_batch_no;
5055 main_where_clause := main_where_clause||' AND bh.batch_no = :wip_batch_no';
5056 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_batch_no';
5057 END IF;
5058
5059 IF p_wip_batch_id IS NOT NULL
5060 THEN
5061 g_wip_batch_id := p_wip_batch_id;
5062 main_where_clause := main_where_clause||' AND se.batch_id = :wip_batch_id';
5063 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_batch_id';
5064 END IF;
5065
5066 IF p_wip_formula_no IS NOT NULL
5067 THEN
5068 g_wip_formula_no := p_wip_formula_no;
5069 main_where_clause := main_where_clause||' AND fh.formula_no = :wip_formula_no';
5070 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_formula_no';
5071 END IF;
5072
5073 IF p_wip_formula_vers IS NOT NULL
5074 THEN
5075 g_wip_formula_vers := p_wip_formula_vers;
5076 main_where_clause := main_where_clause||' AND fh.formula_no = :wip_formula_vers';
5077 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_formula_vers';
5078 END IF;
5079
5080 IF p_wip_formula_id IS NOT NULL
5081 THEN
5082 g_wip_formula_id := p_wip_formula_id;
5083 main_where_clause := main_where_clause||' AND se.formula_id = :wip_formula_id';
5084 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_formula_id';
5085 END IF;
5086
5087 IF p_wip_recipe_no IS NOT NULL
5088 THEN
5089 g_wip_recipe_no := p_wip_recipe_no;
5090 main_where_clause := main_where_clause||' AND r.recipe_no = :wip_recipe_no';
5091 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_recipe_no';
5092 END IF;
5093
5094 /* Bug 3124643; Changed r.recipe_no to r.recipe_version */
5095 IF p_wip_recipe_vers IS NOT NULL
5096 THEN
5097 g_wip_recipe_vers := p_wip_recipe_vers;
5098 main_where_clause := main_where_clause||' AND r.recipe_version = :wip_recipe_vers';
5099 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_recipe_vers';
5100 END IF;
5101
5102 IF p_wip_recipe_id IS NOT NULL
5103 THEN
5104 g_wip_recipe_id := p_wip_recipe_id;
5105 main_where_clause := main_where_clause||' AND se.recipe_id = :wip_recipe_id';
5106 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_formula_id';
5107 END IF;
5108
5109 IF p_wip_formulaline_id IS NOT NULL
5110 THEN
5111 g_wip_formulaline_id := p_wip_formulaline_id;
5112 main_where_clause := main_where_clause||' AND se.formulaline_id = :wip_formulaline_id';
5113 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_formulaline_id';
5114 END IF;
5115
5116 IF p_wip_formulaline_no IS NOT NULL OR p_wip_formulaline_type IS NOT NULL
5117 THEN
5118
5119 IF p_wip_formulaline_no IS NOT NULL
5120 THEN
5121 g_wip_formulaline_no := p_wip_formulaline_no;
5122 main_where_clause := main_where_clause||' AND fd.line_no = :wip_formulaline_no';
5123 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_formulaline_no';
5124 END IF;
5125
5126 IF p_wip_formulaline_type IS NOT NULL
5127 THEN
5128 g_wip_formulaline_type := p_wip_formulaline_type;
5129 main_where_clause := main_where_clause||' AND fd.formulaline_type = :wip_formulaline_type';
5130 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_formulaline_type';
5131 END IF;
5132 END IF;
5133
5134 IF p_wip_step_id IS NOT NULL
5135 THEN
5136 g_wip_step_id := p_wip_step_id;
5137 main_where_clause := main_where_clause||' AND se.step_id = :wip_step_id';
5138 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_step_id';
5139 END IF;
5140
5141 IF p_wip_step_no IS NOT NULL
5142 THEN
5143 g_wip_step_no := p_wip_step_no;
5144 main_where_clause := main_where_clause||' AND se.step_no = :wip_step_no';
5145 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_step_no';
5146 END IF;
5147
5148 IF p_wip_oprn_id IS NOT NULL
5149 THEN
5150 g_wip_oprn_id := p_wip_oprn_id;
5151 main_where_clause := main_where_clause||' AND se.oprn_id = :wip_oprn_id';
5152 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_oprn_id';
5153 END IF;
5154
5155 IF p_wip_oprn_no IS NOT NULL OR p_wip_oprn_vers IS NOT NULL
5156 THEN
5157 main_table_list := main_table_list||', gmd_operations_b go';
5158 main_where_clause := main_where_clause||' AND se.oprn_id = go.oprn_id';
5159
5160 IF p_wip_oprn_no IS NOT NULL
5161 THEN
5162 g_wip_oprn_no := p_wip_oprn_no;
5163 main_where_clause := main_where_clause||' AND go.oprn_no = :wip_oprn_no';
5164 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_oprn_no';
5165 END IF;
5166
5167 IF p_wip_oprn_id IS NOT NULL
5168 THEN
5169 g_wip_oprn_id := p_wip_oprn_id;
5170 main_where_clause := main_where_clause||' AND go.oprn_vers = :wip_oprn_vers';
5171 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_wip_oprn_vers';
5172 END IF;
5173 END IF;
5174
5175 IF p_customer_order_id IS NOT NULL
5176 THEN
5177 g_customer_order_id := p_customer_order_id;
5178 main_where_clause := main_where_clause||' AND se.order_id = :customer_order_id';
5179 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_customer_order_id';
5180 END IF;
5181
5182 IF p_customer_order_number IS NOT NULL
5183 THEN
5184 g_customer_order_number := p_customer_order_number;
5185 main_where_clause := main_where_clause||' AND oh.order_number = :customer_order_number';
5186 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_customer_order_number';
5187 END IF;
5188
5189 IF p_customer IS NOT NULL
5190 THEN
5191 g_cust_name := p_customer;
5192 main_table_list := main_table_list ||', hz_cust_accounts_all hca, hz_parties hp ';
5193 main_where_clause := main_where_clause ||' AND se.cust_id = hca.cust_account_id'
5194 ||' AND hca.party_id = hp.party_id'
5195 ||' AND hp.party_name = :cust_name';
5196 main_using_clause := main_using_clause ||', gmd_outbound_apis_pub.g_cust_name ';
5197 END IF;
5198
5199 IF p_customer_id IS NOT NULL
5200 THEN
5201 g_customer_id := p_customer_id;
5202 main_where_clause := main_where_clause||' AND se.cust_id = :customer_id';
5203 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_customer_id';
5204 END IF;
5205
5206 /* Bug 3124653 Added code to retrieve sample groups by customer_ship_to_location &
5207 customer_ship_to_location_id */
5208 IF p_customer_ship_to_location IS NOT NULL
5209 THEN
5210 g_customer_ship_to_location := p_customer_ship_to_location;
5211 main_where_clause := main_where_clause||
5212 ' AND se.ship_to_site_id IN '||
5213 ' ( select site_use_id '||
5214 ' from hz_cust_site_uses_all '||
5215 ' where location = :customer_ship_to_location)';
5216 main_using_clause := main_using_clause||
5217 ', gmd_outbound_apis_pub.g_customer_ship_to_location';
5218 END IF;
5219
5220 IF p_customer_ship_to_location_id IS NOT NULL
5221 THEN
5222 g_customer_ship_to_location_id := p_customer_ship_to_location_id;
5223 main_where_clause := main_where_clause||
5224 ' AND se.ship_to_site_id = :customer_ship_to_location_id';
5225 main_using_clause := main_using_clause||
5226 ', gmd_outbound_apis_pub.g_customer_ship_to_location_id';
5227 END IF;
5228
5229 IF p_customer_order_type IS NOT NULL
5230 THEN
5231 g_customer_order_type := p_customer_order_type;
5232 main_table_list := main_table_list||', oe_transaction_types_all tt';
5233 main_where_clause := main_where_clause||' AND oh.order_type_id = tt.transaction_type_id'
5234 ||' AND tt.transaction_type_code = :customer_order_type';
5235 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_customer_order_type';
5236 END IF;
5237
5238 IF p_customer_order_line IS NOT NULL OR p_customer_order_line_id IS NOT NULL
5239 THEN
5240 main_where_clause := main_where_clause||' AND oh.header_id = ol.header_id';
5241
5242 IF p_customer_order_line IS NOT NULL
5243 THEN
5244 g_customer_order_line := p_customer_order_line;
5245 main_where_clause := main_where_clause||' AND ol.line_number = :customer_order_line';
5246 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_customer_order_line';
5247 END IF;
5248
5249 IF p_customer_order_line_id IS NOT NULL
5250 THEN
5251 g_customer_order_line_id := g_customer_order_line_id;
5252 main_where_clause := main_where_clause||' AND ol.line_id = :customer_order_line_id';
5253 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_customer_order_line_id';
5254 END IF;
5255 END IF;
5256
5257 IF p_supplier_id IS NOT NULL
5258 THEN
5259 g_supplier_id := p_supplier_id;
5260 main_where_clause := main_where_clause||' AND se.supplier_id = :supplier_id';
5261 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supplier_id';
5262 END IF;
5263
5264 IF p_supplier IS NOT NULL
5265 THEN
5266 g_supplier := p_supplier;
5267 main_table_list := main_table_list||', po_vendors v';
5268 main_where_clause := main_where_clause||' AND se.supplier_id = v.vendor_id'
5269 ||' AND v.segment1 = :supplier';
5270 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supplier';
5271 END IF;
5272
5273 IF p_supplier_site IS NOT NULL
5274 THEN
5275 g_supplier_site := p_supplier_site;
5276 main_table_list := main_table_list||', po_vendor_sites_all vsa';
5277 main_where_clause := main_where_clause||' AND se.supplier_site_id = vsa.vendor_site_id'
5278 ||' AND vsa.vendor_site_code = :supplier_site';
5279 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supplier_site';
5280 END IF;
5281
5282 IF p_supplier_po_number IS NOT NULL
5283 THEN
5284 g_supplier_po_number := p_supplier_po_number;
5285 main_table_list := main_table_list||', po_headers_all pha';
5286 main_where_clause := main_where_clause||' AND se.po_header_id = pha.po_header_id'
5287 ||' AND pha.segment1 = :supplier_po_number';
5288 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supplier_po_number';
5289 END IF;
5290
5291 IF p_supplier_po_id IS NOT NULL
5292 THEN
5293 g_supplier_po_id := p_supplier_po_id;
5294 main_where_clause := main_where_clause||' AND se.po_header_id = :supplier_po_id';
5295 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supplier_po_id';
5296 END IF;
5297
5298 IF p_supplier_po_line IS NOT NULL
5299 THEN
5300 g_supplier_po_line := g_supplier_po_line;
5301 main_where_clause := main_where_clause||' AND pl.line_num = :supplier_po_line)';
5302 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supplier_po_line';
5303 END IF;
5304
5305 IF p_supplier_po_line_id IS NOT NULL
5306 THEN
5307 g_supplier_po_line_id := p_supplier_po_line_id;
5308 main_where_clause := main_where_clause||' AND se.po_line_id = :supplier_po_line_id';
5309 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_supplier_po_line_id';
5310 END IF;
5311
5312 IF p_disposition IS NOT NULL
5313 THEN
5314 g_disposition := p_disposition;
5315 main_where_clause := main_where_clause||' AND se.disposition = :disposition';
5316 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_disposition';
5317
5318 disp_where_clause := disp_where_clause||' AND sd.disposition = :disposition';
5319 disp_using_clause := disp_using_clause||', gmd_outbound_apis_pub.g_disposition';
5320 END IF;
5321
5322 IF p_delete_mark IS NOT NULL
5323 THEN
5324 g_delete_mark := p_delete_mark;
5325 disp_where_clause := disp_where_clause||' AND sd.delete_mark = :delete_mark';
5326 disp_using_clause := disp_using_clause||', gmd_outbound_apis_pub.g_delete_mark';
5327 END IF;
5328
5329
5330 IF p_from_last_update_date IS NOT NULL
5331 THEN
5332 gmd_outbound_apis_pub.g_from_last_update_date := p_from_last_update_date;
5333 main_where_clause := main_where_clause||'AND se.last_update_date >= :from_last_update_date ';
5334 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_from_last_update_date ';
5335
5336 disp_where_clause := disp_where_clause||'AND sd.last_update_date >= :from_last_update_date ';
5337 disp_using_clause := disp_using_clause||', gmd_outbound_apis_pub.g_from_last_update_date ';
5338 END IF;
5339
5340 IF p_to_last_update_date IS NOT NULL
5341 THEN
5342 gmd_outbound_apis_pub.g_to_last_update_date := p_to_last_update_date;
5343 main_where_clause := main_where_clause||'AND se.last_update_date <= :to_last_update_date ';
5344 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_to_last_update_date ';
5345
5346 disp_where_clause := disp_where_clause||'AND sd.last_update_date <= :to_last_update_date ';
5347 disp_using_clause := disp_using_clause||', gmd_outbound_apis_pub.g_to_last_update_date ';
5348 END IF;
5349
5350 -- START B3124291 Incorporated Mini-Pack K Features to Outboud APIs
5351 IF p_sg_organization_id IS NOT NULL
5352 THEN
5353 gmd_outbound_apis_pub.g_sg_organization_id := p_sg_organization_id;
5354 main_where_clause := main_where_clause||'AND se.organization_id = :sg_organization_id ';
5355 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_sg_organization_id ';
5356 END IF;
5357
5358 IF p_resources IS NOT NULL
5359 THEN
5360 gmd_outbound_apis_pub.g_resources := p_resources;
5361 main_where_clause := main_where_clause||'AND se.resources = :resources ';
5362 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_resources ';
5363 END IF;
5364
5365 IF p_instance_id IS NOT NULL
5366 THEN
5367 gmd_outbound_apis_pub.g_instance_id := p_instance_id;
5368 main_where_clause := main_where_clause||'AND se.instance_id = :instance_id ';
5369 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_instance_id ';
5370 END IF;
5371
5372 l_ss_table_included := 'FALSE';
5373 IF (p_ss_organization_id IS NOT NULL OR p_ss_no IS NOT NULL OR p_ss_id IS NOT NULL) THEN
5374 main_table_list := main_table_list ||', gmd_stability_studies_b ss, gmd_ss_variants ssv ';
5375 main_where_clause := main_where_clause ||'AND ss.ss_id = ssv.ss_id AND ssv.variant_id = se.variant_id ';
5376 l_ss_table_included := 'TRUE';
5377
5378 IF p_ss_id IS NOT NULL
5379 THEN
5380 gmd_outbound_apis_pub.g_ss_id := p_ss_id;
5381 main_where_clause := main_where_clause||'AND ss.ss_id = :ss_id ';
5382 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_ss_id ';
5383 END IF;
5384
5385 IF p_ss_organization_id IS NOT NULL
5386 THEN
5387 gmd_outbound_apis_pub.g_ss_organization_id := p_ss_organization_id;
5388 main_where_clause := main_where_clause||'AND ss.organization_id = :ss_organization_id ';
5389 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_ss_organization_id ';
5390 END IF;
5391
5392 IF p_ss_no IS NOT NULL
5393 THEN
5394 gmd_outbound_apis_pub.g_ss_no := p_ss_no;
5395 main_where_clause := main_where_clause||'AND ss.ss_no = :ss_no ';
5396 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_ss_no ';
5397 END IF;
5398
5399 END IF;
5400
5401 IF p_variant_no IS NOT NULL
5402 THEN
5403 IF (l_ss_table_included = 'FALSE') THEN
5404 main_table_list := main_table_list ||', gmd_ss_variants ssv ';
5405 main_where_clause := main_where_clause ||'AND ssv.variant_id = se.variant_id ';
5406 END IF;
5407
5408 gmd_outbound_apis_pub.g_variant_no := p_variant_no;
5409 main_where_clause := main_where_clause||'AND ssv.variant_no = :variant_no ';
5410 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_variant_no ';
5411 END IF;
5412
5413 IF p_variant_id IS NOT NULL
5414 THEN
5415 gmd_outbound_apis_pub.g_variant_id := p_variant_id;
5416 main_where_clause := main_where_clause||'AND se.variant_id = :variant_id ';
5417 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_variant_id ';
5418 END IF;
5419
5420 IF p_time_point_id IS NOT NULL
5421 THEN
5422 gmd_outbound_apis_pub.g_time_point_id := p_time_point_id;
5423 main_where_clause := main_where_clause||'AND se.time_point_id = :time_point_id ';
5424 main_using_clause := main_using_clause||', gmd_outbound_apis_pub.g_time_point_id ';
5425 END IF;
5426
5427 -- END B3124291 Incorporated Mini-Pack K Features to Outboud APIs
5428
5429
5430
5431 sql_statement := 'SELECT system.gmd_sampling_event_rec_type' -- 5284247
5432 ||'('||main_column_list
5433 ||', CAST'
5434 ||' ( MULTISET'
5435 ||' ( SELECT ' ||disp_column_list
5436 ||' FROM '||disp_table_list
5437 ||' WHERE '||disp_where_clause
5438 ||' ) AS system.gmd_event_spec_disps_tab_type' -- 5284242
5439 ||' )'
5440 ||')'
5441 ||' FROM ' ||main_table_list
5442 ||' WHERE '||main_where_clause;
5443
5444 -- That's more or less the job done. We just need to tell the system where to store the data
5445 -- and assemble the USING clause. Note thatthe main_using_clause is last in the list as it
5446 -- appears last in the query.
5447
5448 main_into_clause := ' BULK COLLECT INTO gmd_outbound_apis_pub.g_sample_groups_table ';
5449 main_using_clause := ' USING '||disp_using_clause
5450 ||','||main_using_clause;
5451
5452 main_execution_string := 'BEGIN EXECUTE IMMEDIATE '
5453 ||''''
5454 ||sql_statement
5455 ||''''
5456 ||main_into_clause
5457 ||main_using_clause
5458 ||'; END;';
5459
5460 string_length := LENGTH(main_execution_string);
5461
5462
5463 EXECUTE IMMEDIATE main_execution_string;
5464
5465 IF g_sample_groups_table.count > 0
5466 THEN
5467 FOR i in 1 .. g_sample_groups_table.count
5468 LOOP
5469 IF g_sample_groups_table(i).receipt_line_id IS NOT NULL
5470 THEN
5471 -- Bug 3970893: receipt line id is changed from transaction if to shipment line id
5472 -- select rsl.line_num into g_sample_groups_table(i).receipt_line_number
5473 -- from rcv_shipment_lines rsl, rcv_transactions rt
5474 -- where rt.transaction_id = g_sample_groups_table(i).receipt_line_id
5475 select rsl.line_num into g_sample_groups_table(i).receipt_line_number
5476 from rcv_shipment_lines rsl
5477 where rsl.shipment_line_id = g_sample_groups_table(i).receipt_line_id;
5478 END IF;
5479
5480 IF g_sample_groups_table(i).supplier_id IS NOT NULL
5481 THEN
5482 select segment1 into g_sample_groups_table(i).supplier_name
5483 from po_vendors
5484 where vendor_id=g_sample_groups_table(i).supplier_id;
5485 END IF;
5486
5487 IF g_sample_groups_table(i).ship_to_site_id IS NOT NULL
5488 THEN
5489 select location into g_sample_groups_table(i).ship_to_site_name
5490 from hz_cust_site_uses_all
5491 where site_use_id = g_sample_groups_table(i).ship_to_site_id;
5492 END IF;
5493
5494 IF g_sample_groups_table(i).supplier_site_id IS NOT NULL
5495 THEN
5496 select vendor_site_code into g_sample_groups_table(i).supplier_site_name
5497 from po_vendor_sites_all
5498 where vendor_site_id = g_sample_groups_table(i).supplier_site_id;
5499 END IF;
5500 END LOOP;
5501 END IF;
5502
5503 END IF;
5504
5505 x_sample_groups_table := g_sample_groups_table;
5506 x_return_status := FND_API.G_RET_STS_SUCCESS;
5507
5508 FND_MSG_PUB.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5509
5510 EXCEPTION
5511 WHEN OTHERS THEN
5512
5513 FND_MESSAGE.SET_NAME('GMD',SQLCODE);
5514 FND_MSG_PUB.Add;
5515 FND_MSG_PUB.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5516 x_return_status := FND_API.G_RET_STS_ERROR;
5517 END fetch_sample_groups;
5518
5519 end gmd_outbound_apis_pub;