[Home] [Help]
PACKAGE BODY: APPS.MSC_CL_PRE_PROCESS
Source
1 PACKAGE BODY MSC_CL_PRE_PROCESS AS -- body
2 /* $Header: MSCCLPPB.pls 120.67.12020000.3 2012/11/27 05:47:31 neelredd ship $ */
3
4 -- ========= Global Parameters ===========
5
6 --Instance --
7
8 v_apps_ver NUMBER;
9 v_supply_id_c NUMBER ;
10 v_supply_id_n NUMBER ;
11 v_supply_id NUMBER ;
12 v_source_organization_id NUMBER ;
13 v_source_sr_instance_id NUMBER ;
14 v_discrete_flag NUMBER:= SYS_NO;
15 v_process_flag NUMBER:= SYS_NO;
16 --v_debug BOOLEAN := FALSE;
17 v_req_data varchar2(10);
18 v_cal_build boolean := False;
19 v_MSC_CONFIGURATION VARCHAR2(10) := nvl(fnd_profile.value('MSC_X_CONFIGURATION'), 1);
20 v_my_company VARCHAR2(1000) := MSC_ST_UTIL.GET_MY_COMPANY;
21
22
23 -- User Environment --
24 -- v_current_date DATE := sysdate;
25 -- v_current_user NUMBER;
26 v_applsys_schema VARCHAR2(32);
27 prec MSC_UTIL.CollParamREC;
28
29 -- Pre Process Program --
30 --v_batch_size NUMBER := 1000;
31 v_last_collection_id NUMBER;
32 v_is_complete_refresh BOOLEAN;
33 v_is_incremental_refresh BOOLEAN;
34 v_is_so_complete_refresh BOOLEAN;
35 v_is_so_incremental_refresh BOOLEAN;
36 v_cp_enabled NUMBER;
37 v_recalc_nra NUMBER;
38 v_recalc_sh NUMBER;
39 v_exchange_mode NUMBER:= SYS_NO; -- default to SYS_NO
40 v_so_exchange_mode NUMBER:= SYS_NO; -- default to SYS_NO
41 v_monitor_request_id NUMBER;
42 v_error_no_begin PLS_INTEGER;
43 v_error_no_end PLS_INTEGER;
44 v_sce_installed BOOLEAN;
45
46 v_res_dmd_enabled NUMBER;
47 v_mat_dmd_enabled NUMBER;
48 v_reserve_enabled NUMBER;
49 v_mat_sup_enabled NUMBER;
50 v_rtg_enabled NUMBER;
51 v_bom_enabled NUMBER;
52 v_resources_enabled NUMBER;
53 v_sourcing_enabled NUMBER;
54 v_ctg_enabled NUMBER;
55 v_sup_cap_enabled NUMBER;
56 v_safety_stk_enabled NUMBER;
57 v_item_enabled NUMBER;
58 v_tp_enabled NUMBER;
59 v_dmd_class_enabled NUMBER;
60 v_uom_enabled NUMBER;
61 v_desig_enabled NUMBER;
62 v_project_enabled NUMBER;
63 v_cal_enabled NUMBER;
64 v_item_cat_enabled NUMBER;
65 v_uom_class_enabled NUMBER;
66 v_ship_mthd_enabled NUMBER;
67 v_item_cst_enabled NUMBER;
68 v_parent_request_id PLS_INTEGER;
69 v_request_id PLS_INTEGER; -- added to identify the set of records loaded at a time.
70 v_second_pass BOOLEAN := FALSE;
71 v_fiscal_cal_enabled NUMBER;
72 v_comp_cal_enabled NUMBER;
73 v_setup_enabled NUMBER;
74 v_item_rollup NUMBER;
75 v_level_value_enabled NUMBER;
76 v_level_assoc_enabled NUMBER;
77 v_booking_enabled NUMBER;
78 v_shipment_enabled NUMBER;
79 v_mfg_fct_enabled NUMBER;
80 v_list_price_enabled NUMBER;
81 v_cs_data_enabled NUMBER;
82 v_cs_refresh NUMBER;
83 v_curr_conv_enabled NUMBER;
84 v_uom_conv_enabled NUMBER;
85 v_comp_users_enabled NUMBER;
86 v_item_substitute_enabled NUMBER;
87 v_planners_enabled NUMBER;
88 v_profile_enabled NUMBER;
89 v_cal_assignment_enabled NUMBER;
90 v_iro_enabled NUMBER;
91 v_ero_enabled NUMBER;
92 v_sales_channel_enabled NUMBER;
93 v_fiscal_calendar_enabled NUMBER;
94 v_CMRO_enabled NUMBER; --- CMRO Proj bug 9135694
95 /* v_cs_batches_launched NUMBER := 0; S_OP*/
96
97 -- status --
98 v_warning_flag NUMBER:= SYS_NO;
99
100 -- Task Control --
101 v_pipe_task_que VARCHAR2(32);
102 v_pipe_wm VARCHAR2(32);
103 v_pipe_mw VARCHAR2(32);
104 v_pipe_status VARCHAR2(32);
105
106 -- Misc --
107
108 PBS NUMBER; -- purge batch size
109 v_sourcing NUMBER; -- sourcing rule flag
110 v_cal_worker NumTblTyp:= NumTblTyp(0);-- Calendar Build
111 v_total_worker_num Number;
112
113 -- ODP(Oracle Demand Planning) Changes-----------
114 v_install_msd BOOLEAN;
115 v_install_msc BOOLEAN;
116 -----------------------------
117 -- ========== Declare Local Procedures ==============
118
119 PROCEDURE LOAD_SUPPLIER_CAPACITY;
120 PROCEDURE LOAD_SAFETY_STOCK;
121 PROCEDURE LOAD_ITEM (p_batch_id NUMBER);
122 PROCEDURE LOAD_ITEM_SUBSTITUTES; -- Product item substitute
123 PROCEDURE LOAD_CATEGORIES_SOURCING;
124 PROCEDURE LOAD_DEPT_RESOURCES;
125 PROCEDURE LOAD_RESOURCE_SETUPS;
126 PROCEDURE LOAD_SETUP_TRANSITIONS;
127 PROCEDURE LOAD_MATERIAL_SUPPLY(p_batch_id NUMBER);
128 PROCEDURE LOAD_MATERIAL_DEMAND(p_batch_id NUMBER);
129 PROCEDURE LOAD_SO_DEMAND(p_batch_id NUMBER);
130 PROCEDURE LOAD_RESERVATION;
131 PROCEDURE LOAD_BOM_ROUTING;
132 PROCEDURE LOAD_RESOURCE_DEMAND;
133 PROCEDURE LOAD_ITEM_CST;
134 -- Added for the bug fix 2191021
135 PROCEDURE LOAD_ITEM_ABC_CLASSES;
136 PROCEDURE LOAD_COMPANY_USER;
137 PROCEDURE LOAD_ITEM_SUBSTITUTE;
138 PROCEDURE LOAD_CAL_ASSIGNMENTS;
139 PROCEDURE LOAD_SALES_CHNL;
140 PROCEDURE LOAD_FISCAL;
141 PROCEDURE LOAD_CMRO; --- CMRO Proj bug 9135694
142
143 -- ========= Declare DP local Procedure ===============
144 PROCEDURE LOAD_LEVEL_VALUE (p_batch_id NUMBER );
145 PROCEDURE LOAD_LEVEL_ASSOCIATION (p_batch_id NUMBER );
146 PROCEDURE LOAD_BOOKING_DATA (p_batch_id NUMBER );
147 PROCEDURE LOAD_SHIPMENT_DATA (p_batch_id NUMBER );
148 PROCEDURE LOAD_MFG_FORECAST (p_batch_id NUMBER );
149 PROCEDURE LOAD_PRICE_LIST(p_batch_id NUMBER );
150 -- PROCEDURE LOAD_ITEM_LIST_PRICE(p_batch_id NUMBER );
151 PROCEDURE LOAD_CS_DATA (p_batch_id NUMBER);
152 PROCEDURE LOAD_CURR_CONV (p_batch_id NUMBER );
153 PROCEDURE LOAD_UOM_CONV (p_batch_id NUMBER );
154 PROCEDURE LOAD_SETUP_PARAMETER;
155 PROCEDURE LOAD_FISCAL_TIME;
156 PROCEDURE LOAD_COMPOSITE_TIME;
157 PROCEDURE LOAD_IRO_SUPPLY_DEMAND;
158 PROCEDURE LOAD_ERO_SUPPLY_DEMAND;
159
160
161 --==Send Error/ Warning Email for XML Transactions having Errors/ Warnings ==
162
163 /*
164 PROCEDURE SEND_ERROR
165 IS
166 TYPE MailCurTyp IS REF CURSOR;
167 c_email MailCurTyp;
168 lv_errbuf varchar2(4000):='';
169 lv_protocol_type varchar2(30) := 'SMTP';
170 lv_protocol_address varchar2(4000);
171 lv_clob CLOB;
172 lv_message system.ecxevtmsg;
173 lv_messageproperties dbms_aq.message_properties_t;
174 lv_msgid raw(16);
175 lv_enqueueoptions dbms_aq.enqueue_options_t;
176 lv_amount pls_integer;
177 lv_pointer pls_integer;
178 lv_party_id pls_integer;
179
180 cursor c_err is select
181 ed.document_number,
182 ed.transaction_type,
183 ed.transaction_subtype,
184 ed.party_site_id,
185 err.error_id,
186 err.error_text,
187 err.severity,
188 err.table_name,
189 err.rrow
190 from msc_errors err,
191 ecx_doclogs ed
192 where err.message_id = ed.internal_control_number
193 and err.instance_code = v_instance_code
194 and nvl(err.message_sent,SYS_NO) <> SYS_YES;
195
196 BEGIN
197 FOR c in c_err loop
198
199 lv_errbuf:= '';
200
201 lv_pointer:= 1;
202 OPEN c_email FOR
203 'select hdr.company_admin_email, hdr.tp_header_id '
204 ||' from ecx_tp_headers hdr, ecx_tp_details det'
205 ||' where hdr.tp_header_id = det.tp_header_id'
206 ||' and hdr.company_admin_email IS NOT NULL'
207 ||' and det.source_tp_location_code = :loc' USING c.party_site_id;
208 -- party_site_id actually contains the loc code
209 FETCH c_email into lv_protocol_address, lv_party_id;
210 CLOSE c_email;
211
212 lv_pointer:= 2;
213 IF lv_protocol_address IS NULL THEN
214 fnd_message.set_name ('ECX', 'ECX_TP_ADMIN_EMAIL_NOT_FOUND');
215 fnd_message.set_token ('TP_ID', c.party_site_id);
216 lv_errbuf := fnd_message.get;
217 LOG_MESSAGE( lv_errbuf);
218 fnd_profile.get('ECX_SYS_ADMIN_EMAIL',lv_protocol_address);
219 END IF;
220
221 lv_pointer:= 3;
222 IF lv_protocol_address IS NULL THEN
223 fnd_message.set_name ('ECX', 'ECX_SYS_ADMIN_EMAIL_NOT_FOUND');
224 LOG_MESSAGE(fnd_message.get);
225 ELSE
226 IF v_debug THEN
227 LOG_MESSAGE('lv_protocol_address: '||lv_protocol_address);
228 END IF;
229 IF c.severity = 1 THEN
230 fnd_message.set_name ('MSC', 'MSC_PP_ERROR_EMAIL');
231 ELSE
232 fnd_message.set_name ('MSC', 'MSC_PP_WARN_EMAIL');
233 END IF;
234
235 lv_pointer:= 4;
236 fnd_message.set_token ('TRANSACTION_TYPE', c.transaction_type);
237 fnd_message.set_token ('TRANSACTION_SUB_TYPE', c.transaction_subtype);
238 fnd_message.set_token ('DOCUMENT_NUMBER', c.document_number);
239 lv_errbuf := lv_errbuf ||fnd_message.get;
240 lv_errbuf := lv_errbuf ||c.error_text;
241
242 IF v_debug THEN
243 LOG_MESSAGE('lv_errbuf : '||lv_errbuf );
244 END IF;
245
246 lv_pointer:= 5;
247 lv_amount := length(lv_errbuf);
248 dbms_lob.createtemporary(lv_clob,TRUE,DBMS_LOB.SESSION);
249 dbms_lob.write(lv_clob,lv_amount,1,lv_errbuf);
250
251 lv_pointer:= 6;
252 lv_message := system.ecxevtmsg( c.document_number,
253 lv_party_id,
254 c.transaction_type,
255 lv_clob,
256 'USER',
257 'ERROR',
258 lv_protocol_address,
259 null,
260 null,
261 null);
262
263 lv_pointer:= 7;
264 -- Enqueue
265 dbms_aq.enqueue
266 (
267 queue_name=>'ECXEVENTQ',
268 enqueue_options=>lv_enqueueoptions,
269 message_properties=>lv_messageproperties,
270 payload=>lv_message,
271 msgid=>lv_msgid
272 );
273
274 lv_pointer:= 8;
275 -- Start the Workflow process
276 wf_xmlnotify.startprocess(lv_msgid);
277
278 lv_pointer:= 9;
279 update msc_errors set message_sent = SYS_YES
280 where error_id = c.error_id;
281
282 END IF;
283 END LOOP;
284
285 EXCEPTION
286 when others then
287 LOG_MESSAGE('MSC_CL_PRE_PROCESS.SEND_ERROR ('||lv_pointer||'): '||SQLERRM);
288 END;
289 */
290
291 -- WRITE_ERROR_SUMM_LOG ===========
292 PROCEDURE WRITE_ERROR_SUMM_LOG (p_parent_req_id number DEFAULT -1 ) IS
293 CURSOR c_error IS
294 SELECT table_name, error_text, count(*) occur
295 FROM msc_errors
296 WHERE instance_code = v_instance_code
297 AND error_id between (v_error_no_begin + 1) and v_error_no_end
298 AND severity = 1
299 GROUP BY table_name, error_text;
300
301 CURSOR c_error_by_req(p_request_id number) IS
302 SELECT table_name, error_text, count(*) occur
303 FROM msc_errors
304 WHERE instance_code = v_instance_code
305 AND request_id = p_request_id
306 AND severity = 1
307 GROUP BY table_name, error_text;
308
309 CURSOR c_warning IS
310 SELECT table_name, error_text, count(*) occur
311 FROM msc_errors
312 WHERE instance_code = v_instance_code
313 AND error_id between (v_error_no_begin +1) and v_error_no_end
314 AND severity = 2
315 GROUP BY table_name, error_text;
316
317 CURSOR c_warning_by_req(p_request_id number) IS
318 SELECT table_name, error_text, count(*) occur
319 FROM msc_errors
320 WHERE instance_code = v_instance_code
321 AND request_id = p_request_id
322 AND severity = 2
323 GROUP BY table_name, error_text;
324
325 lv_count PLS_INTEGER := 0;
326
327 BEGIN
328
329 IF nvl(p_parent_req_id,-1) < 1 THEN
330 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'*************** DATA ERRORS DURING PRE-PROCESSING ****************');
331
332 FOR cur in c_error LOOP
333
334 lv_count:= lv_count + 1;
335
336 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_count||'. Table Name: '||cur.table_name||', Number of Occurences: '|| cur.occur||', Error: '|| cur.error_text);
337
338 END LOOP;
339
340 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,' **********************');
341 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,' ');
342
343 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'*************** WARNINGS DURING PRE-PROCESSING ****************');
344
345 lv_count := 0;
346
347 FOR cur in c_warning LOOP
348
349 lv_count:= lv_count + 1;
350
351 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_count||'. Table Name: '||cur.table_name||', Number of Occurences: '|| cur.occur||', Warning: '|| cur.error_text);
352
353 END LOOP;
354
355 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,' **********************');
356 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,' ');
357
358 ELSE
359 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'*************** DATA ERRORS DURING PRE-PROCESSING ****************');
360
361 FOR cur in c_error_by_req(p_parent_req_id) LOOP
362
363 lv_count:= lv_count + 1;
364
365 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_count||'. Table Name: '||cur.table_name||', Number of Occurences: '|| cur.occur||', Error: '|| cur.error_text);
366
367 END LOOP;
368
369 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,' **********************');
370 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,' ');
371
372 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'*************** WARNINGS DURING PRE-PROCESSING ****************');
373
374 lv_count := 0;
375
376 FOR cur in c_warning_by_req(p_parent_req_id) LOOP
377
378 lv_count:= lv_count + 1;
379
380 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_count||'. Table Name: '||cur.table_name||', Number of Occurences: '|| cur.occur||', Warning: '|| cur.error_text);
381
382 END LOOP;
383
384 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,' **********************');
385 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,' ');
386
387 END IF;
388
389 EXCEPTION
390 when others then
391 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error in WRITE_ERROR_SUMM_LOG: '||dbms_utility.format_error_stack );
392
393 END;
394
395 --
396
397 --Launch DP Pull -------------
398 --Launch DP Pull -------------
399 PROCEDURE LAUNCH_DP_PULL (ERRBUF OUT NOCOPY VARCHAR2,
400 RETCODE OUT NOCOPY NUMBER)
401 IS
402 lv_direct_load_profile BOOLEAN ;
403 lv_launch_lvalue NUMBER := SYS_NO;
404 lv_launch_time NUMBER := SYS_NO;
405 lv_sql_stmt VARCHAR2(4000);
406 lv_error_text VARCHAR2(250);
407
408 BEGIN
409
410 IF (v_install_msd) THEN
411
412 lv_direct_load_profile := (fnd_profile.value('MSD_ONE_STEP_COLLECTION')='Y');
413
414 --IF ((v_level_assoc_enabled = SYS_YES) OR (v_item_rollup = SYS_YES) ) THEN
415 IF ((v_level_assoc_enabled = SYS_YES) OR (v_level_value_enabled = SYS_YES) OR (v_item_rollup = SYS_YES) ) THEN
416 lv_launch_lvalue := SYS_YES;
417 END IF;
418
419
420 IF ((v_cal_enabled = SYS_YES) OR (v_fiscal_cal_enabled = SYS_YES) OR (v_comp_cal_enabled=SYS_YES)) THEN
421 lv_launch_time := SYS_YES ;
422 END IF ;
423
424 IF(lv_direct_load_profile) THEN
425 lv_sql_stmt := ' DECLARE errbuf varchar2(250);'
426 ||' retcode number ;'
427 ||' BEGIN '
428 ||' MSD_CL_PRE_PROCESS.LAUNCH_PULL_PROGRAM'
429 ||' (ERRBUF => errbuf ,'
430 ||' RETCODE => retcode ,'
431 ||' p_instance_id => :v_instance_id,'
432 ||' p_request_id => :v_request_id,'
433 ||' p_launch_lvalue => :lv_launch_lvalue,'
434 ||' p_launch_booking => :v_booking_enabled,'
435 ||' p_launch_shipment => :v_shipment_enabled,'
436 ||' p_launch_forecast => :v_mfg_fct_enabled,'
437 ||' p_launch_time => :lv_launch_time,'
438 ||' p_launch_pricing => :v_list_price_enabled,'
439 ||' p_launch_curr_conv => :v_curr_conv_enabled ,'
440 ||' p_launch_uom_conv => :v_uom_conv_enabled,'
441 ||' p_launch_cs_data => :v_cs_data_enabled,'
442 ||' p_cs_refresh => :v_cs_refresh);'
443 ||' END ;';
444
445 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,lv_sql_stmt);
446
447 EXECUTE IMMEDIATE lv_sql_stmt
448 USING v_instance_id,
449 v_request_id,
450 lv_launch_lvalue,
451 v_booking_enabled,
452 v_shipment_enabled,
453 v_mfg_fct_enabled,
454 lv_launch_time,
455 v_list_price_enabled,
456 v_curr_conv_enabled ,
457 v_uom_conv_enabled,
458 v_cs_data_enabled,
459 v_cs_refresh ;
460
461 END IF; -- One step collection
462 END IF ;-- v_install_msd
463
464 EXCEPTION
465
466 WHEN OTHERS THEN
467 lv_error_text := substr('MSC_CL_PRE_PROCESS.LAUNCH_DP_PULL'||SQLERRM,1,240);
468 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
469 RETCODE := G_WARNING;
470 ERRBUF := lv_error_text;
471
472 END LAUNCH_DP_PULL ;
473
474 PROCEDURE LAUNCH_DELETE_DUPLICATES (ERRBUF OUT NOCOPY VARCHAR2,
475 RETCODE OUT NOCOPY NUMBER)
476 IS
477
478 lv_sql_stmt VARCHAR2(4000);
479 lv_error_text VARCHAR2(250);
480
481 BEGIN
482
483 IF (v_install_msd) THEN
484
485 lv_sql_stmt := ' DECLARE errbuf varchar2(250);'
486 ||' retcode number ;'
487 ||' BEGIN '
488 ||' MSD_CL_PRE_PROCESS.LAUNCH_DELETE_DUPLICATES'
489 ||' (ERRBUF => errbuf ,'
490 ||' RETCODE => retcode ,'
491 ||' p_instance_id => :v_instance_id);'
492 ||' END ;';
493
494 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,lv_sql_stmt);
495
496 EXECUTE IMMEDIATE lv_sql_stmt
497 USING v_instance_id;
498
499
500 END IF ;-- v_install_msd
501
502 EXCEPTION
503
504 WHEN OTHERS THEN
505 lv_error_text := substr('MSC_CL_PRE_PROCESS.LAUNCH_DELETE_DUPLICATES'||SQLERRM,1,240);
506 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
507 RETCODE := G_WARNING;
508 ERRBUF := lv_error_text;
509
510 END LAUNCH_DELETE_DUPLICATES ;
511
512 -- =====Local Procedures =========
513 FUNCTION GET_MY_COMPANY return VARCHAR2 IS
514 p_my_company msc_companies.company_name%TYPE;
515 BEGIN
516
517 /* Get the name of the own Company */
518 /* This name is seeded with company_is = 1 in msc_companies */
519 BEGIN
520 select company_name into p_my_company
521 from msc_companies
522 where company_id = 1;
523 EXCEPTION
524 WHEN OTHERS THEN
525 return 'My Company';
526 END;
527
528 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'The name in GET_MY_COMPANY :'||p_my_company);
529 return p_my_company;
530
531 END GET_MY_COMPANY;
532
533 -- ===== CREATE_INDEXES ==========
534 PROCEDURE CREATE_INDEXES (p_batch_index VARCHAR2 DEFAULT NULL) IS
535 BEGIN
536
537 IF p_batch_index IS NULL THEN
538
539 IF v_item_enabled = SYS_YES THEN
540
541 BEGIN
542
543 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
544 application_short_name => 'MSC',
545 statement_type => AD_DDL.CREATE_INDEX,
546 statement =>
547 'create index MSC_ST_SYSTEM_ITEMS_N1_'||v_instance_code
548 ||' on MSC_ST_SYSTEM_ITEMS '
549 ||'(item_name, sr_instance_code, organization_code, company_name) '
550 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
551 object_name =>'MSC_ST_SYSTEM_ITEMS_N1_'||v_instance_code);
552
553 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Created Index MSC_ST_SYSTEM_ITEMS_N1_'||v_instance_code);
554
555
556 EXCEPTION
557 WHEN OTHERS THEN
558 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_SYSTEM_ITEMS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
559 END;
560
561 msc_analyse_tables_pk.analyse_table( 'MSC_ST_SYSTEM_ITEMS', v_instance_id, -1);
562
563 END IF;
564
565 IF v_mat_sup_enabled = SYS_YES THEN
566
567 BEGIN
568 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
569 application_short_name => 'MSC',
570 statement_type => AD_DDL.CREATE_INDEX,
571 statement =>
572 'create index MSC_ST_SUPPLIES_N1_'||v_instance_code
573 ||' on MSC_ST_SUPPLIES '
574 ||'(SR_INSTANCE_CODE, ORDER_NUMBER, PURCH_LINE_NUM, ORDER_TYPE, COMPANY_NAME) '
575 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
576 object_name =>'MSC_ST_SUPPLIES_N1_'||v_instance_code);
577 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Created Index MSC_ST_SUPPLIES_N1_'||v_instance_code);
578
579 EXCEPTION
580 WHEN OTHERS THEN
581 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Error creating Index MSC_ST_SUPPLIES_N1_'||v_instance_code ||'. Error:'||substr(SQLERRM,1,240));
582 END;
583
584 BEGIN
585 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
586 application_short_name => 'MSC',
587 statement_type => AD_DDL.CREATE_INDEX,
588 statement =>
589 'create index MSC_ST_SUPPLIES_N2_'||v_instance_code
590 ||' on MSC_ST_SUPPLIES '
591 ||'(sr_instance_code, schedule_line_num, schedule_designator, organization_code, order_type, company_name) '
592 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
593 object_name =>'MSC_ST_SUPPLIES_N2_'||v_instance_code);
594 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Created Index MSC_ST_SUPPLIES_N2_'||v_instance_code);
595
596 EXCEPTION
597 WHEN OTHERS THEN
598 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Error creating Index MSC_ST_SUPPLIES_N2_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
599 END;
600
601 BEGIN
602 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
603 application_short_name => 'MSC',
604 statement_type => AD_DDL.CREATE_INDEX,
605 statement =>
606 'create index MSC_ST_SUPPLIES_N3_'||v_instance_code
607 ||' on MSC_ST_SUPPLIES '
608 ||'(sr_instance_code, item_name, organization_code, order_type, company_name) '
609 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
610 object_name =>'MSC_ST_SUPPLIES_N3_'||v_instance_code);
611
612 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_SUPPLIES_N3_'||v_instance_code);
613
614
615 EXCEPTION
616 WHEN OTHERS THEN
617 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_SUPPLIES_N3_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
618 END;
619
620 BEGIN
621 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
622 application_short_name => 'MSC',
623 statement_type => AD_DDL.CREATE_INDEX,
624 statement =>
625 'create index MSC_ST_SUPPLIES_N4_'||v_instance_code
626 ||' on MSC_ST_SUPPLIES '
627 ||'(sr_instance_code,wip_entity_name, organization_code,order_type, company_name) '
628 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
629 object_name =>'MSC_ST_SUPPLIES_N4_'||v_instance_code);
630 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_SUPPLIES_N4_'||v_instance_code);
631
632
633 EXCEPTION
634 WHEN OTHERS THEN
635 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_SUPPLIES_N4_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
636 END;
637
638 msc_analyse_tables_pk.analyse_table( 'MSC_ST_SUPPLIES', v_instance_id, -1);
639
640 END IF;
641
642 IF v_mat_dmd_enabled = SYS_YES THEN
643
644 BEGIN
645 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
646 application_short_name => 'MSC',
647 statement_type => AD_DDL.CREATE_INDEX,
648 statement =>
649 'create index MSC_ST_DEMANDS_N1_'||v_instance_code
650 ||' on MSC_ST_DEMANDS '
651 ||'(sr_instance_code, schedule_date, item_name, organization_code, forecast_designator, company_name) '
652 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
653 object_name =>'MSC_ST_DEMANDS_N1_'||v_instance_code);
654 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_DEMANDS_N1_'||v_instance_code);
655
656
657 EXCEPTION
658 WHEN OTHERS THEN
659 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_DEMANDS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
660 END;
661
662 BEGIN
663 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
664 application_short_name => 'MSC',
665 statement_type => AD_DDL.CREATE_INDEX,
666 statement =>
667 'create index MSC_ST_DEMANDS_N2_'||v_instance_code
668 ||' on MSC_ST_DEMANDS '
669 ||'(SR_INSTANCE_CODE, ITEM_NAME,WIP_ENTITY_NAME, ORGANIZATION_CODE, ORIGINATION_TYPE, OPERATION_SEQ_CODE, COMPANY_NAME) '
670 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
671 object_name =>'MSC_ST_DEMANDS_N2_'||v_instance_code);
672
673 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_DEMANDS_N2_'||v_instance_code);
674
675 EXCEPTION
676 WHEN OTHERS THEN
677 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_DEMANDS_N2_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
678 END;
679
680 BEGIN
681 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
682 application_short_name => 'MSC',
683 statement_type => AD_DDL.CREATE_INDEX,
684 statement =>
685 'create index MSC_ST_SO_N1_'||v_instance_code
686 ||' on MSC_ST_SALES_ORDERS '
687 ||'(sr_instance_code, sales_order_number, line_num, organization_code, company_name) '
688 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
689 object_name =>'MSC_ST_SO_N1_'||v_instance_code);
690
691 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_SO_N1_'||v_instance_code);
692
693 EXCEPTION
694 WHEN OTHERS THEN
695 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_SO_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
696 END;
697
698 msc_analyse_tables_pk.analyse_table( 'MSC_ST_DEMANDS', v_instance_id, -1);
699 msc_analyse_tables_pk.analyse_table( 'MSC_ST_SALES_ORDERS', v_instance_id, -1);
700
701 END IF;
702
703 IF v_reserve_enabled = SYS_YES THEN
704
705 BEGIN
706 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
707 application_short_name => 'MSC',
708 statement_type => AD_DDL.CREATE_INDEX,
709 statement =>
710 'create index MSC_ST_RESERVE_N1_'||v_instance_code
711 ||' on MSC_ST_RESERVATIONS '
712 ||'(sr_instance_code,sales_order_number, line_num,organization_code,company_name ) '
713 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
714 object_name =>'MSC_ST_RESERVE_N1_'||v_instance_code);
715
716
717 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_RESERVE_N1_'||v_instance_code);
718
719 EXCEPTION
720 WHEN OTHERS THEN
721 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_RESERVE_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
722 END;
723
724 msc_analyse_tables_pk.analyse_table( 'MSC_ST_RESERVATIONS', v_instance_id, -1);
725
726 END IF;
727
728
729 IF v_bom_enabled = SYS_YES THEN
730
731 BEGIN
732 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
733 application_short_name => 'MSC',
734 statement_type => AD_DDL.CREATE_INDEX,
735 statement =>
736 'create index MSC_ST_BOMS_N1_'||v_instance_code
737 ||' on MSC_ST_BOMS '
738 ||'(sr_instance_code, assembly_name, organization_code, company_name, bom_name, alternate_bom_designator) '
739 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
740 object_name =>'MSC_ST_BOMS_N1_'||v_instance_code);
741 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_BOMS_N1_'||v_instance_code);
742
743 EXCEPTION
744 WHEN OTHERS THEN
745 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_BOMS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
746 END;
747
748 BEGIN
749 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
750 application_short_name => 'MSC',
751 statement_type => AD_DDL.CREATE_INDEX,
752 statement =>
753 'create index MSC_ST_BOM_COMP_N1_'||v_instance_code
754 ||' on MSC_ST_BOM_COMPONENTS '
755 ||'(sr_instance_code, assembly_name, component_name, effectivity_date, operation_seq_code, organization_code, company_name, bom_name, alternate_bom_designator) '
756 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
757 object_name =>'MSC_ST_BOM_COMP_N1_'||v_instance_code);
758 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_BOM_COMP_N1_'||v_instance_code);
759
760 EXCEPTION
761 WHEN OTHERS THEN
762 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_BOM_COMP_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
763 END;
764
765 BEGIN
766 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
767 application_short_name => 'MSC',
768 statement_type => AD_DDL.CREATE_INDEX,
769 statement =>
770 'create index MSC_ST_COMP_SUB_N1_'||v_instance_code
771 ||' on MSC_ST_COMPONENT_SUBSTITUTES '
772 ||'(sr_instance_code, assembly_name, component_name, sub_item_name, effectivity_date, operation_seq_code, organization_code,company_name, bom_name, alternate_bom_designator) '
773 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
774 object_name =>'MSC_ST_COMP_SUB_N1_'||v_instance_code);
775
776 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_COMP_SUB_N1_'||v_instance_code);
777
778 EXCEPTION
779 WHEN OTHERS THEN
780 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_COMP_SUB_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
781 END;
782
783 -- Added for Co Products (OSFM Integration) --
784 BEGIN
785 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
786 application_short_name => 'MSC',
787 statement_type => AD_DDL.CREATE_INDEX,
788 statement =>
789 'create index MSC_ST_CO_PRODUCTS_N1_'||v_instance_code
790 ||' on MSC_ST_CO_PRODUCTS '
791 ||'(co_product_name,component_name,sr_instance_code,company_name ) '
792 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
793 object_name =>'MSC_ST_CO_PRODUCTS_N1_'||v_instance_code);
794 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_CO_PRODUCTS_N1_'||v_instance_code);
795
796 EXCEPTION
797 WHEN OTHERS THEN
798 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_CO_PRODUCTS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
799 END;
800
801 msc_analyse_tables_pk.analyse_table( 'MSC_ST_BOMS', v_instance_id, -1);
802 msc_analyse_tables_pk.analyse_table( 'MSC_ST_BOM_COMPONENTS', v_instance_id, -1);
803 msc_analyse_tables_pk.analyse_table( 'MSC_ST_COMPONENT_SUBSTITUTES', v_instance_id, -1);
804 msc_analyse_tables_pk.analyse_table( 'MSC_ST_CO_PRODUCTS', v_instance_id, -1);
805
806
807 END IF;
808
809 IF v_rtg_enabled = SYS_YES THEN
810
811 BEGIN
812 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
813 application_short_name => 'MSC',
814 statement_type => AD_DDL.CREATE_INDEX,
815 statement =>
816 'create index MSC_ST_ROUTINGS_N1_'||v_instance_code
817 ||' on MSC_ST_ROUTINGS '
818 ||'(sr_instance_code, assembly_name, organization_code, company_name, routing_name, alternate_routing_designator) '
819 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
820 object_name =>'MSC_ST_ROUTINGS_N1_'||v_instance_code);
821
822 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_ROUTINGS_N1_'||v_instance_code);
823
824 EXCEPTION
825 WHEN OTHERS THEN
826 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_ROUTINGS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
827 END;
828
829 BEGIN
830 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
831 application_short_name => 'MSC',
832 statement_type => AD_DDL.CREATE_INDEX,
833 statement =>
834 'create index MSC_ST_ROUTING_OPER_N1_'||v_instance_code
835 ||' on MSC_ST_ROUTING_OPERATIONS '
836 ||'( sr_instance_code, assembly_name, operation_seq_code, organization_code, company_name, routing_name, alternate_routing_designator) '
837 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
838 object_name =>'MSC_ST_ROUTING_OPER_N1_'||v_instance_code);
839
840 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_ROUTING_OPER_N1_'||v_instance_code);
841
842
843 EXCEPTION
844 WHEN OTHERS THEN
845 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_ROUTING_OPER_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
846 END;
847
848 BEGIN
849 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
850 application_short_name => 'MSC',
851 statement_type => AD_DDL.CREATE_INDEX,
852 statement =>
853 'create index MSC_ST_OPER_RES_N1_'||v_instance_code
854 ||' on MSC_ST_OPERATION_RESOURCES '
855 ||'(sr_instance_code, assembly_name, resource_code, organization_code, company_name, alternate_number, operation_seq_code, resource_seq_code, routing_name, alternate_routing_designator) '
856 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
857 object_name =>'MSC_ST_OPER_RES_N1_'||v_instance_code);
858
859 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_OPER_RES_N1_'||v_instance_code);
860
861 EXCEPTION
862 WHEN OTHERS THEN
863 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_OPER_RES_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
864 END;
865
866 -- Added for Operation Networks (OSFM Integration )
867 BEGIN
868 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
869 application_short_name => 'MSC',
870 statement_type => AD_DDL.CREATE_INDEX,
871 statement =>
872 'create index MSC_ST_OPER_NTWK_N1_'||v_instance_code
873 ||' on MSC_ST_OPERATION_NETWORKS '
874 ||'(assembly_name, organization_code,FROM_OPERATION_SEQ_CODE, TO_OPERATION_SEQ_CODE,sr_instance_code, company_name) '
875 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
876 object_name =>'MSC_ST_OPER_NTWK_N1_'||v_instance_code);
877
878 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_OPER_NTWK_N1_'||v_instance_code);
879
880 EXCEPTION
881 WHEN OTHERS THEN
882 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_OPER_NTWK_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
883 END;
884
885 msc_analyse_tables_pk.analyse_table( 'MSC_ST_ROUTINGS', v_instance_id, -1);
886 msc_analyse_tables_pk.analyse_table( 'MSC_ST_OPERATION_RESOURCES', v_instance_id, -1);
887 msc_analyse_tables_pk.analyse_table( 'MSC_ST_ROUTING_OPERATIONS', v_instance_id, -1);
888 msc_analyse_tables_pk.analyse_table( 'MSC_ST_OPERATION_NETWORKS', v_instance_id, -1);
889
890
891 END IF;
892
893 IF v_item_cat_enabled = SYS_YES THEN
894
895 BEGIN
896 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
897 application_short_name => 'MSC',
898 statement_type => AD_DDL.CREATE_INDEX,
899 statement =>
900 'create index MSC_ST_ITEM_CAT_N1_'||v_instance_code
901 ||' on MSC_ST_ITEM_CATEGORIES '
902 ||'(sr_instance_code,item_name, category_name, category_set_name, organization_code, company_name) '
903 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
904 object_name =>'MSC_ST_ITEM_CAT_N1_'||v_instance_code);
905
906 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_ITEM_CAT_N1_'||v_instance_code);
907
908 EXCEPTION
909 WHEN OTHERS THEN
910 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_ITEM_CAT_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
911 END;
912
913 BEGIN
914 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
915 application_short_name => 'MSC',
916 statement_type => AD_DDL.CREATE_INDEX,
917 statement =>
918 'create index MSC_ST_ITEM_CAT_N2_'||v_instance_code
919 ||' on MSC_ST_ITEM_CATEGORIES '
920 ||'(sr_instance_code,batch_id) '
921 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
922 object_name =>'MSC_ST_ITEM_CAT_N2_'||v_instance_code);
923
924 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_ITEM_CAT_N2_'||v_instance_code);
925
926 EXCEPTION
927 WHEN OTHERS THEN
928 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_ITEM_CAT_N2_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
929 END;
930
931 msc_analyse_tables_pk.analyse_table( 'MSC_ST_ITEM_CATEGORIES', v_instance_id, -1);
932
933 END IF;
934
935 IF v_resources_enabled = SYS_YES THEN
936 BEGIN
937
938 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
939 application_short_name => 'MSC',
940 statement_type => AD_DDL.CREATE_INDEX,
941 statement =>
942 'create index MSC_ST_RESOURCE_GROUPS_N1_'||v_instance_code
943 ||' on MSC_ST_RESOURCE_GROUPS '
944 ||'(sr_instance_code, group_code, company_name) '
945 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
946 object_name =>'MSC_ST_RESOURCE_GROUPS_N1_'||v_instance_code);
947
948 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_RESOURCE_GROUPS_N1_'||v_instance_code);
949
950 EXCEPTION
951 WHEN OTHERS THEN
952 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_RESOURCE_GROUPS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
953 END;
954
955 BEGIN
956 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
957 application_short_name => 'MSC',
958 statement_type => AD_DDL.CREATE_INDEX,
959 statement =>
960 'create index MSC_ST_DEPT_RES_N1_'||v_instance_code
961 ||' on MSC_ST_DEPARTMENT_RESOURCES '
962 ||'(sr_instance_code, resource_code, department_code, organization_code, company_name) '
963 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
964 object_name =>'MSC_ST_DEPT_RES_N1_'||v_instance_code);
965
966 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_DEPT_RES_N1_'||v_instance_code);
967
968 EXCEPTION
969 WHEN OTHERS THEN
970 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_DEPT_RES_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
971 END;
972
973 BEGIN
974 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
975 application_short_name => 'MSC',
976 statement_type => AD_DDL.CREATE_INDEX,
977 statement =>
978 'create index MSC_ST_RES_SHIFTS_N1_'||v_instance_code
979 ||' on MSC_ST_RESOURCE_SHIFTS '
980 ||'(sr_instance_code, resource_code, department_code, shift_name, organization_code, company_name) '
981 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
982 object_name =>'MSC_ST_RES_SHIFTS_N1_'||v_instance_code);
983
984 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_RES_SHIFTS_N1_'||v_instance_code);
985
986 EXCEPTION
987 WHEN OTHERS THEN
988 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_RES_SHIFTS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
989 END;
990
991 BEGIN
992 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
993 application_short_name => 'MSC',
994 statement_type => AD_DDL.CREATE_INDEX,
995 statement =>
996 'create index MSC_ST_RES_CHANGES_N1_'||v_instance_code
997 ||' on MSC_ST_RESOURCE_CHANGES '
998 ||'(sr_instance_code, simulation_set, resource_code, department_code, from_date, shift_name, organization_code, company_name) '
999 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1000 object_name =>'MSC_ST_RES_CHANGES_N1_'||v_instance_code);
1001
1002 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_RES_CHANGES_N1_'||v_instance_code);
1003
1004 EXCEPTION
1005 WHEN OTHERS THEN
1006 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_RES_CHANGES_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1007 END;
1008
1009 msc_analyse_tables_pk.analyse_table( 'MSC_ST_RESOURCE_GROUPS', v_instance_id, -1);
1010 msc_analyse_tables_pk.analyse_table( 'MSC_ST_DEPARTMENT_RESOURCES', v_instance_id, -1);
1011 msc_analyse_tables_pk.analyse_table( 'MSC_ST_RESOURCE_SHIFTS', v_instance_id, -1);
1012 msc_analyse_tables_pk.analyse_table( 'MSC_ST_RESOURCE_CHANGES', v_instance_id, -1);
1013
1014 END IF;
1015
1016 IF v_project_enabled = SYS_YES THEN
1017
1018 BEGIN
1019 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1020 application_short_name => 'MSC',
1021 statement_type => AD_DDL.CREATE_INDEX,
1022 statement =>
1023 'create index MSC_ST_PROJECT_TASKS_N1_'||v_instance_code
1024 ||' on MSC_ST_PROJECT_TASKS '
1025 ||'(sr_instance_code, project_number, task_number, organization_code, company_name) '
1026 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1027 object_name =>'MSC_ST_PROJECT_TASKS_N1_'||v_instance_code);
1028
1029 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_PROJECT_TASKS_N1_'||v_instance_code);
1030
1031 EXCEPTION
1032 WHEN OTHERS THEN
1033 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_PROJECT_TASKS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1034 END;
1035
1036 msc_analyse_tables_pk.analyse_table( 'MSC_ST_PROJECT_TASKS', v_instance_id, -1);
1037
1038 END IF;
1039
1040 IF v_dmd_class_enabled = SYS_YES THEN
1041
1042 BEGIN
1043 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1044 application_short_name => 'MSC',
1045 statement_type => AD_DDL.CREATE_INDEX,
1046 statement =>
1047 'create index MSC_ST_DMD_CLASS_N1_'||v_instance_code
1048 ||' on MSC_ST_DEMAND_CLASSES '
1049 ||'(sr_instance_code,demand_class,company_name) '
1050 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1051 object_name =>'MSC_ST_DMD_CLASS_N1_'||v_instance_code);
1052
1053 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_DMD_CLASS_N1_'||v_instance_code);
1054
1055 EXCEPTION
1056 WHEN OTHERS THEN
1057 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_DMD_CLASS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1058 END;
1059
1060 msc_analyse_tables_pk.analyse_table( 'MSC_ST_DEMAND_CLASSES', v_instance_id, -1);
1061
1062 END IF;
1063
1064 IF v_tp_enabled = SYS_YES THEN
1065
1066 BEGIN
1067 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1068 application_short_name => 'MSC',
1069 statement_type => AD_DDL.CREATE_INDEX,
1070 statement =>
1071 'create index MSC_ST_TRADING_PART_N1_'||v_instance_code
1072 ||' on MSC_ST_TRADING_PARTNERS '
1073 ||'(sr_instance_code, partner_name, partner_type, company_name) '
1074 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1075 object_name =>'MSC_ST_TRADING_PART_N1_'||v_instance_code);
1076
1077 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_TRADING_PART_N1_'||v_instance_code);
1078
1079 EXCEPTION
1080 WHEN OTHERS THEN
1081 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_TRADING_PART_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1082 END;
1083
1084 BEGIN
1085 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1086 application_short_name => 'MSC',
1087 statement_type => AD_DDL.CREATE_INDEX,
1088 statement =>
1089 'create index MSC_ST_TRADING_PART_N2_'||v_instance_code
1090 ||' on MSC_ST_TRADING_PARTNERS '
1091 ||'(sr_instance_code, organization_code, partner_type, company_name) '
1092 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1093 object_name =>'MSC_ST_TRADING_PART_N2_'||v_instance_code);
1094
1095 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_TRADING_PART_N2_'||v_instance_code);
1096
1097 EXCEPTION
1098 WHEN OTHERS THEN
1099 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_TRADING_PART_N2_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1100 END;
1101
1102 BEGIN
1103 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1104 application_short_name => 'MSC',
1105 statement_type => AD_DDL.CREATE_INDEX,
1106 statement =>
1107 'create index MSC_ST_TRD_PART_SITES_N1_'||v_instance_code
1108 ||' on MSC_ST_TRADING_PARTNER_SITES '
1109 ||'(sr_instance_code ,tp_site_code, partner_name, partner_type) '
1110 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1111 object_name =>'MSC_ST_TRD_PART_SITES_N1_'||v_instance_code);
1112
1113 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_TRD_PART_SITES_N1_'||v_instance_code);
1114
1115 EXCEPTION
1116 WHEN OTHERS THEN
1117 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_TRD_PART_SITES_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1118 END;
1119
1120 BEGIN
1121 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1122 application_short_name => 'MSC',
1123 statement_type => AD_DDL.CREATE_INDEX,
1124 statement =>
1125 'create index MSC_ST_SUB_INV_N1_'||v_instance_code
1126 ||' on MSC_ST_SUB_INVENTORIES '
1127 ||'( sr_instance_code, sub_inventory_code, organization_code ) '
1128 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1129 object_name =>'MSC_ST_SUB_INV_N1_'||v_instance_code);
1130
1131 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_SUB_INV_N1_'||v_instance_code);
1132
1133 EXCEPTION
1134 WHEN OTHERS THEN
1135 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_SUB_INV_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1136 END;
1137
1138 BEGIN
1139 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1140 application_short_name => 'MSC',
1141 statement_type => AD_DDL.CREATE_INDEX,
1142 statement =>
1143 'create index MSC_ST_LOC_ASC_N1_'||v_instance_code
1144 ||' on MSC_ST_LOCATION_ASSOCIATIONS '
1145 ||'(sr_instance_code, location_code, tp_site_code, partner_name, partner_type, company_name) '
1146 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1147 object_name =>'MSC_ST_LOC_ASC_N1_'||v_instance_code);
1148
1149 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_LOC_ASC_N1_'||v_instance_code);
1150
1151 EXCEPTION
1152 WHEN OTHERS THEN
1153 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_LOC_ASC_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1154 END;
1155
1156 BEGIN
1157 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1158 application_short_name => 'MSC',
1159 statement_type => AD_DDL.CREATE_INDEX,
1160 statement =>
1161 'create index MSC_ST_PART_CONT_N1_'||v_instance_code
1162 ||' on MSC_ST_PARTNER_CONTACTS '
1163 ||'(sr_instance_code,tp_site_code, partner_name, partner_type, company_name) '
1164 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1165 object_name =>'MSC_ST_PART_CONT_N1_'||v_instance_code);
1166
1167 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_PART_CONT_N1_'||v_instance_code);
1168
1169 EXCEPTION
1170 WHEN OTHERS THEN
1171 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_PART_CONT_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1172 END;
1173
1174 --For Aeroexchange
1175 --Added for MSC_ST_GROUPS
1176 BEGIN
1177 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1178 application_short_name => 'MSC',
1179 statement_type => AD_DDL.CREATE_INDEX,
1180 statement =>
1181 'create index MSC_ST_GROUPS_N1_'||v_instance_code
1182 ||' on MSC_ST_GROUPS '
1183 ||'(GROUP_NAME) '
1184 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1185 object_name =>'MSC_ST_GROUPS_N1_'||v_instance_code);
1186
1187 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_GROUPS_N1_'||v_instance_code);
1188
1189 msc_analyse_tables_pk.analyse_table( 'MSC_ST_GROUPS', v_instance_id, -1);
1190
1191 EXCEPTION
1192 WHEN OTHERS THEN
1193 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_GROUPS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1194 END;
1195
1196 BEGIN
1197 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1198 application_short_name => 'MSC',
1199 statement_type => AD_DDL.CREATE_INDEX,
1200 statement =>
1201 'create index MSC_ST_GROUP_COMPANIES_N1_'||v_instance_code
1202 ||' on MSC_ST_GROUP_COMPANIES '
1203 ||'(group_name,company_name) '
1204 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1205 object_name =>'MSC_ST_GROUP_COMPANIES_N1_'||v_instance_code);
1206
1207 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_GROUP_COMPANIES_N1_'||v_instance_code);
1208
1209 EXCEPTION
1210 WHEN OTHERS THEN
1211 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_GROUP_COMPANIES_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1212 END;
1213
1214
1215
1216 msc_analyse_tables_pk.analyse_table( 'MSC_ST_TRADING_PARTNERS', v_instance_id, -1);
1217 msc_analyse_tables_pk.analyse_table( 'MSC_ST_TRADING_PARTNER_SITES', v_instance_id, -1);
1218 msc_analyse_tables_pk.analyse_table( 'MSC_ST_SUB_INVENTORIES', v_instance_id, -1);
1219 msc_analyse_tables_pk.analyse_table( 'MSC_ST_LOCATION_ASSOCIATIONS', v_instance_id, -1);
1220 msc_analyse_tables_pk.analyse_table( 'MSC_ST_PARTNER_CONTACTS', v_instance_id, -1);
1221
1222 END IF;
1223
1224 IF v_item_cst_enabled = SYS_YES THEN
1225
1226 BEGIN
1227
1228 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1229 application_short_name => 'MSC',
1230 statement_type => AD_DDL.CREATE_INDEX,
1231 statement =>
1232 'create index MSC_ST_ITEM_CUSTOMERS_N1_'||v_instance_code
1233 ||' on MSC_ST_ITEM_CUSTOMERS '
1234 ||'(ITEM_NAME, CUSTOMER_NAME, SR_INSTANCE_CODE, COMPANY_NAME, CUSTOMER_SITE_NAME) '
1235 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1236 object_name =>'MSC_ST_ITEM_CUSTOMERS_N1_'||v_instance_code);
1237
1238 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_ITEM_CUSTOMERS_N1_'||v_instance_code);
1239
1240 EXCEPTION
1241 WHEN OTHERS THEN
1242 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_ITEM_CUSTOMERS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1243 END;
1244
1245 BEGIN
1246
1247 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1248 application_short_name => 'MSC',
1249 statement_type => AD_DDL.CREATE_INDEX,
1250 statement =>
1251 'create index MSC_ST_ITEM_CUSTOMERS_N2_'||v_instance_code
1252 ||' on MSC_ST_ITEM_CUSTOMERS '
1253 ||'(CUSTOMER_ITEM_NAME, CUSTOMER_NAME, SR_INSTANCE_CODE, COMPANY_NAME, CUSTOMER_SITE_NAME) '
1254 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1255 object_name =>'MSC_ST_ITEM_CUSTOMERS_N2_'||v_instance_code);
1256
1257 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_ITEM_CUSTOMERS_N2_'||v_instance_code);
1258
1259 EXCEPTION
1260 WHEN OTHERS THEN
1261 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_ITEM_CUSTOMERS_N2_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1262 END;
1263
1264 msc_analyse_tables_pk.analyse_table( 'MSC_ST_ITEM_CUSTOMERS', v_instance_id, -1);
1265
1266 END IF;
1267
1268 IF v_ship_mthd_enabled = SYS_YES THEN
1269
1270 BEGIN
1271 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1272 application_short_name => 'MSC',
1273 statement_type => AD_DDL.CREATE_INDEX,
1274 statement =>
1275 'create index MSC_ST_INTERORG_SHIP_N1_'||v_instance_code
1276 ||' on MSC_ST_INTERORG_SHIP_METHODS '
1277 ||'(sr_instance_code,from_organization_code,to_organization_code,ship_method,company_name) '
1278 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1279 object_name =>'MSC_ST_INTERORG_SHIP_N1_'||v_instance_code);
1280
1281 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_INTERORG_SHIP_N1_'||v_instance_code);
1282
1283 EXCEPTION
1284 WHEN OTHERS THEN
1285 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_INTERORG_SHIP_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1286 END;
1287
1288 msc_analyse_tables_pk.analyse_table( 'MSC_ST_INTERORG_SHIP_METHODS', v_instance_id, -1);
1289
1290 END IF;
1291
1292 IF v_sourcing_enabled = SYS_YES THEN
1293
1294 BEGIN
1295
1296 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1297 application_short_name => 'MSC',
1298 statement_type => AD_DDL.CREATE_INDEX,
1299 statement =>
1300 'create index MSC_ST_ITEM_SRC_N1_'||v_instance_code
1301 ||' on MSC_ST_ITEM_SOURCING '
1302 ||'(sr_instance_code, sourcing_rule_name, assignment_set_name, organization_code, company_name, receipt_organization_code, source_organization_code) '
1303 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1304 object_name =>'MSC_ST_ITEM_SRC_N1_'||v_instance_code);
1305
1306 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_ITEM_SRC_N1_'||v_instance_code);
1307
1308 EXCEPTION
1309 WHEN OTHERS THEN
1310 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_ITEM_SRC_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1311 END;
1312
1313 BEGIN
1314
1315 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1316 application_short_name => 'MSC',
1317 statement_type => AD_DDL.CREATE_INDEX,
1318 statement =>
1319 'create index MSC_ST_REGIONS_N1_'||v_instance_code
1320 ||' on MSC_ST_REGIONS '
1321 ||'(sr_instance_code, country, state, city, postal_code_from, postal_code_to, zone ) '
1322 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1323 object_name =>'MSC_ST_REGIONS_N1_'||v_instance_code);
1324
1325 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_REGIONS_N1_'||v_instance_code);
1326
1327 EXCEPTION
1328 WHEN OTHERS THEN
1329 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_REGIONS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1330 END;
1331
1332 BEGIN
1333
1334 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1335 application_short_name => 'MSC',
1336 statement_type => AD_DDL.CREATE_INDEX,
1337 statement =>
1338 'create index MSC_ST_ZONE_REGIONS_N1_'||v_instance_code
1339 ||' on MSC_ST_ZONE_REGIONS '
1340 ||'(sr_instance_code, country, state, city, postal_code_from, postal_code_to, zone ) '
1341 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1342 object_name =>'MSC_ST_ZONE_REGIONS_N1_'||v_instance_code);
1343
1344 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_ZONE_REGIONS_N1_'||v_instance_code);
1345
1346 EXCEPTION
1347 WHEN OTHERS THEN
1348 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_ZONE_REGIONS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1349 END;
1350
1351 BEGIN
1352 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1353 application_short_name => 'MSC',
1354 statement_type => AD_DDL.CREATE_INDEX,
1355 statement =>
1356 'create index MSC_ST_REGION_LOC_N1_'||v_instance_code
1357 ||' on MSC_ST_REGION_LOCATIONS '
1358 ||'(sr_instance_code, country, state, city, postal_code_from, postal_code_to, location_code ) '
1359 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1360 object_name =>'MSC_ST_REGION_LOC_N1_'||v_instance_code);
1361
1362 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_REGION_LOC_N1_'||v_instance_code);
1363
1364 EXCEPTION
1365 WHEN OTHERS THEN
1366 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_REGION_LOC_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1367 END;
1368
1369 BEGIN
1370 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1371 application_short_name => 'MSC',
1372 statement_type => AD_DDL.CREATE_INDEX,
1373 statement =>
1374 'create index MSC_ST_REGION_SITE_N1_'||v_instance_code
1375 ||' on MSC_ST_REGION_SITES '
1376 ||'(sr_instance_code, country, state, city, postal_code_from, postal_code_to, vendor_name, vendor_site_code ) '
1377 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1378 object_name =>'MSC_ST_REGION_SITE_N1_'||v_instance_code);
1379
1380 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_REGION_SITE_N1_'||v_instance_code);
1381
1382 EXCEPTION
1383 WHEN OTHERS THEN
1384 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_REGION_SITE_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1385 END;
1386
1387 msc_analyse_tables_pk.analyse_table( 'MSC_ST_ITEM_SOURCING', v_instance_id, -1);
1388 msc_analyse_tables_pk.analyse_table( 'MSC_ST_REGIONS', v_instance_id, -1);
1389 msc_analyse_tables_pk.analyse_table( 'MSC_ST_ZONE_REGIONS', v_instance_id, -1);
1390 msc_analyse_tables_pk.analyse_table( 'MSC_ST_REGION_LOCATIONS', v_instance_id, -1);
1391 msc_analyse_tables_pk.analyse_table( 'MSC_ST_REGION_SITES', v_instance_id, -1);
1392
1393 END IF;
1394
1395 IF v_res_dmd_enabled = SYS_YES THEN
1396
1397 BEGIN
1398
1399 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1400 application_short_name => 'MSC',
1401 statement_type => AD_DDL.CREATE_INDEX,
1402 statement =>
1403 'create index MSC_ST_RES_REQ_N1_'||v_instance_code
1404 ||' on MSC_ST_RESOURCE_REQUIREMENTS '
1405 ||'(sr_instance_code, resource_code, wip_entity_name, operation_seq_code, organization_code, company_name, resource_seq_code) '
1406 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1407 object_name =>'MSC_ST_RES_REQ_N1_'||v_instance_code);
1408
1409 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_RES_REQ_N1_'||v_instance_code);
1410
1411 EXCEPTION
1412 WHEN OTHERS THEN
1413 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_RES_REQ_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1414 END;
1415
1416 msc_analyse_tables_pk.analyse_table( 'MSC_ST_RESOURCE_REQUIREMENTS', v_instance_id, -1);
1417
1418 END IF;
1419
1420 IF v_uom_class_enabled = SYS_YES THEN
1421
1422 BEGIN
1423
1424 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1425 application_short_name => 'MSC',
1426 statement_type => AD_DDL.CREATE_INDEX,
1427 statement =>
1428 'create index MSC_ST_UOM_CLS_CONV_N1_'||v_instance_code
1429 ||' on MSC_ST_UOM_CLASS_CONVERSIONS '
1430 ||'( from_uom_code, to_uom_code, item_name, company_name) '
1431 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1432 object_name =>'MSC_ST_UOM_CLS_CONV_N1_'||v_instance_code);
1433
1434 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_UOM_CLS_CONV_N1_'||v_instance_code);
1435
1436 EXCEPTION
1437 WHEN OTHERS THEN
1438 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_UOM_CLS_CONV_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1439 END;
1440
1441 msc_analyse_tables_pk.analyse_table( 'MSC_ST_UOM_CLASS_CONVERSIONS', v_instance_id, -1);
1442
1443 END IF;
1444
1445 IF v_sup_cap_enabled = SYS_YES THEN
1446
1447 BEGIN
1448 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1449 application_short_name => 'MSC',
1450 statement_type => AD_DDL.CREATE_INDEX,
1451 statement =>
1452 'create index MSC_ST_ITEM_SUP_N1_'||v_instance_code
1453 ||' on MSC_ST_ITEM_SUPPLIERS '
1454 ||'(sr_instance_code, item_name, vendor_name, organization_code, company_name, vendor_site_code) '
1455 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1456 object_name =>'MSC_ST_ITEM_SUP_N1_'||v_instance_code);
1457
1458
1459 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_ITEM_SUP_N1_'||v_instance_code);
1460
1461 EXCEPTION
1462 WHEN OTHERS THEN
1463 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_ITEM_SUP_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1464 END;
1465
1466 BEGIN
1467 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1468 application_short_name => 'MSC',
1469 statement_type => AD_DDL.CREATE_INDEX,
1470 statement =>
1471 'create index MSC_ST_SUP_CAP_N1_'||v_instance_code
1472 ||' on MSC_ST_SUPPLIER_CAPACITIES '
1473 ||'(sr_instance_code, item_name, vendor_name, from_date,organization_code,company_name,vendor_site_code) '
1474 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1475 object_name =>'MSC_ST_SUP_CAP_N1_'||v_instance_code);
1476
1477 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_SUP_CAP_N1_'||v_instance_code);
1478
1479 EXCEPTION
1480 WHEN OTHERS THEN
1481 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_SUP_CAP_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1482 END;
1483
1484 BEGIN
1485 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1486 application_short_name => 'MSC',
1487 statement_type => AD_DDL.CREATE_INDEX,
1488 statement =>
1489 'create index MSC_ST_SUP_FENCES_N1_'||v_instance_code
1490 ||' on MSC_ST_SUPPLIER_FLEX_FENCES '
1491 ||'(sr_instance_code, item_name,vendor_name,fence_days,organization_code,company_name,vendor_site_code) '
1492 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1493 object_name =>'MSC_ST_SUP_FENCES_N1_'||v_instance_code);
1494
1495 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_SUP_FENCES_N1_'||v_instance_code);
1496
1497 EXCEPTION
1498 WHEN OTHERS THEN
1499 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_SUP_FENCES_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1500 END;
1501
1502 msc_analyse_tables_pk.analyse_table( 'MSC_ST_ITEM_SUPPLIERS', v_instance_id, -1);
1503 msc_analyse_tables_pk.analyse_table( 'MSC_ST_SUPPLIER_CAPACITIES', v_instance_id, -1);
1504 msc_analyse_tables_pk.analyse_table( 'MSC_ST_SUPPLIER_FLEX_FENCES', v_instance_id, -1);
1505
1506 END IF;
1507
1508 IF v_safety_stk_enabled = SYS_YES THEN
1509
1510 BEGIN
1511
1512 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1513 application_short_name => 'MSC',
1514 statement_type => AD_DDL.CREATE_INDEX,
1515 statement =>
1516 'create index MSC_ST_SAFETY_STOCKS_N1_'||v_instance_code
1517 ||' on MSC_ST_SAFETY_STOCKS '
1518 ||'(sr_instance_code,organization_code,item_name,period_start_date,company_name) '
1519 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1520 object_name =>'MSC_ST_SAFETY_STOCKS_N1_'||v_instance_code);
1521
1522 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_SAFETY_STOCKS_N1_'||v_instance_code);
1523
1524 EXCEPTION
1525 WHEN OTHERS THEN
1526 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_SAFETY_STOCKS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1527 END;
1528 END IF;
1529
1530 IF v_item_substitute_enabled = SYS_YES THEN
1531
1532 BEGIN
1533
1534 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1535 application_short_name => 'MSC',
1536 statement_type => AD_DDL.CREATE_INDEX,
1537 statement =>
1538 'create index MSC_ST_ITEM_SUBSTITUTES_N1_'||v_instance_code
1539 ||' on MSC_ST_ITEM_SUBSTITUTES '
1540 ||' (sr_instance_code,item_name,substitute_item_name,customer_name,'
1541 ||' customer_site_code,substitution_set,company_name) '
1542 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1543 object_name =>'MSC_ST_SAFETY_STOCKS_N1_'||v_instance_code);
1544
1545 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_ITEM_SUBSTITUTES_N1_'||v_instance_code);
1546
1547 EXCEPTION
1548 WHEN OTHERS THEN
1549 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_ITEM_SUBSTITUTES_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1550 END;
1551
1552 msc_analyse_tables_pk.analyse_table( 'MSC_ST_SAFETY_STOCKS', v_instance_id, -1);
1553 msc_analyse_tables_pk.analyse_table( 'MSC_ST_ITEM_SUBSTITUTES', v_instance_id, -1);
1554
1555 END IF;
1556
1557 IF v_planners_enabled = SYS_YES THEN
1558
1559 BEGIN
1560
1561 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1562 application_short_name => 'MSC',
1563 statement_type => AD_DDL.CREATE_INDEX,
1564 statement =>
1565 'create index MSC_ST_PLANNERS_N1_'||v_instance_code
1566 ||' on MSC_ST_PLANNERS '
1567 ||'(sr_instance_code,organization_code,planner_code,company_name) '
1568 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1569 object_name =>'MSC_ST_PLANNERS_N1_'||v_instance_code);
1570
1571 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_PLANNERS_N1_'||v_instance_code);
1572
1573 EXCEPTION
1574 WHEN OTHERS THEN
1575 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_PLANNERS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1576 END;
1577
1578 msc_analyse_tables_pk.analyse_table( 'MSC_ST_PLANNERS', v_instance_id, -1);
1579
1580 END IF;
1581
1582 IF v_mat_sup_enabled = SYS_YES THEN
1583
1584 BEGIN
1585 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1586 application_short_name => 'MSC',
1587 statement_type => AD_DDL.CREATE_INDEX,
1588 statement =>
1589 'create index MSC_ST_JOB_OP_NETWORKS_N1_'||v_instance_code
1590 ||' on MSC_ST_JOB_OPERATION_NETWORKS '
1591 ||'(SR_INSTANCE_CODE, WIP_ENTITY_NAME, FROM_OPERATION_SEQ_CODE, TO_OPERATION_SEQ_CODE) '
1592 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1593 object_name =>'MSC_ST_JOB_OP_NETWORKS_N1_'||v_instance_code);
1594 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_JOB_OP_NETWORKS_N1_'||v_instance_code);
1595
1596 EXCEPTION
1597 WHEN OTHERS THEN
1598 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_JOB_OP_NETWORKS_N1_'||v_instance_code ||'. Error:'||substr(SQLERRM,1,240));
1599 END;
1600
1601 BEGIN
1602 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1603 application_short_name => 'MSC',
1604 statement_type => AD_DDL.CREATE_INDEX,
1605 statement =>
1606 'create index MSC_ST_JOB_OPERATIONS_N1_'||v_instance_code
1607 ||' on MSC_ST_JOB_OPERATIONS '
1608 ||'(SR_INSTANCE_CODE, ORGANIZATION_CODE, WIP_ENTITY_NAME, OPERATION_SEQ_CODE ) '
1609 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1610 object_name =>'MSC_ST_JOB_OPERATIONS_N1_'||v_instance_code);
1611 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_JOB_OPERATIONS_N1_'||v_instance_code);
1612
1613 EXCEPTION
1614 WHEN OTHERS THEN
1615 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_JOB_OPERATIONS_N1_'||v_instance_code ||'. Error:'||substr(SQLERRM,1,240));
1616 END;
1617
1618 BEGIN
1619 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1620 application_short_name => 'MSC',
1621 statement_type => AD_DDL.CREATE_INDEX,
1622 statement =>
1623 'create index MSC_ST_JOB_REQ_OPS_N1_'||v_instance_code
1624 ||' on MSC_ST_JOB_REQUIREMENT_OPS '
1625 ||'(SR_INSTANCE_CODE, ORGANIZATION_CODE, WIP_ENTITY_NAME, OPERATION_SEQ_CODE, COMPONENT_NAME, PRIMARY_COMPONENT_NAME ) '
1626 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1627 object_name =>'MSC_ST_JOB_REQ_OPS_N1_'||v_instance_code);
1628 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_JOB_REQ_OPS_N1_'||v_instance_code);
1629
1630 EXCEPTION
1631 WHEN OTHERS THEN
1632 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_JOB_REQ_OPS_N1_'||v_instance_code ||'. Error:'||substr(SQLERRM,1,240));
1633 END;
1634
1635 BEGIN
1636 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1637 application_short_name => 'MSC',
1638 statement_type => AD_DDL.CREATE_INDEX,
1639 statement =>
1640 'create index MSC_ST_JOB_OP_RESOURCES_N1_'||v_instance_code
1641 ||' on MSC_ST_JOB_OP_RESOURCES '
1642 ||'(SR_INSTANCE_CODE, ORGANIZATION_CODE, WIP_ENTITY_NAME, OPERATION_SEQ_CODE, RESOURCE_SEQ_CODE, ALTERNATE_NUM, RESOURCE_CODE ) '
1643 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1644 object_name =>'MSC_ST_JOB_OP_RESOURCES_N1_'||v_instance_code);
1645 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_JOB_OP_RESOURCES_N1_'||v_instance_code);
1646
1647 EXCEPTION
1648 WHEN OTHERS THEN
1649 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_JOB_OP_RESOURCES_N1_'||v_instance_code ||'. Error:'||substr(SQLERRM,1,240));
1650 END;
1651
1652 END IF;
1653
1654 IF v_cal_assignment_enabled = SYS_YES THEN
1655
1656 BEGIN
1657
1658 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1659 application_short_name => 'MSC',
1660 statement_type => AD_DDL.CREATE_INDEX,
1661 statement =>
1662 'create index MSC_ST_CAL_ASSIGNMENTS_N1_'||v_instance_code
1663 ||' on MSC_ST_CALENDAR_ASSIGNMENTS '
1664 ||'(sr_instance_code,association_type, calendar_code, calendar_type, partner_name, partner_site_code, organization_code, ship_method_code) '
1665 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1666 object_name =>'MSC_ST_CAL_ASSIGNMENTS_N1_'||v_instance_code);
1667
1668 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_CAL_ASSIGNMENTS_N1_'||v_instance_code);
1669
1670 EXCEPTION
1671 WHEN OTHERS THEN
1672 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_CAL_ASSIGNMENTS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1673 END;
1674
1675 msc_analyse_tables_pk.analyse_table( 'MSC_ST_CALENDAR_ASSIGNMENTS', v_instance_id, -1);
1676
1677 END IF;
1678
1679
1680 ELSIF p_batch_index = 'ITEM' THEN
1681
1682 BEGIN
1683
1684 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1685 application_short_name => 'MSC',
1686 statement_type => AD_DDL.CREATE_INDEX,
1687 statement =>
1688 'create index MSC_ST_SYSTEM_ITEMS_N2_'||v_instance_code
1689 ||' on MSC_ST_SYSTEM_ITEMS '
1690 ||' (sr_instance_code,batch_id,sr_inventory_item_id, deleted_flag) '
1691 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1692 object_name => 'MSC_ST_SYSTEM_ITEMS_N2_'||v_instance_code);
1693
1694
1695 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_SYSTEM_ITEMS_N2_'||v_instance_code);
1696
1697 EXCEPTION
1698 WHEN OTHERS THEN
1699 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_SYSTEM_ITEMS_N2_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1700 END;
1701
1702 msc_analyse_tables_pk.analyse_table( 'MSC_ST_SYSTEM_ITEMS', v_instance_id, -1);
1703
1704 ELSIF p_batch_index = 'SUPPLY' THEN
1705
1706 BEGIN
1707
1708 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1709 application_short_name => 'MSC',
1710 statement_type => AD_DDL.CREATE_INDEX,
1711 statement =>
1712 'create index MSC_ST_SUPPLIES_N5_'||v_instance_code
1713 ||' on MSC_ST_SUPPLIES '
1714 ||' (batch_id, order_type, sr_instance_code, deleted_flag) '
1715 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1716 object_name => 'MSC_ST_SUPPLIES_N5_'||v_instance_code);
1717
1718 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_SUPPLIES_N5_'||v_instance_code);
1719
1720 EXCEPTION
1721 WHEN OTHERS THEN
1722 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_SUPPLIES_N5_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1723 END;
1724
1725 msc_analyse_tables_pk.analyse_table( 'MSC_ST_SUPPLIES', v_instance_id, -1);
1726
1727 ELSIF p_batch_index = 'DEMAND' THEN
1728
1729 BEGIN
1730
1731 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1732 application_short_name => 'MSC',
1733 statement_type => AD_DDL.CREATE_INDEX,
1734 statement =>
1735 'create index MSC_ST_DEMANDS_N3_'||v_instance_code
1736 ||' on MSC_ST_DEMANDS '
1737 ||' (batch_id, origination_type, sr_instance_code, deleted_flag) '
1738 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1739 object_name => 'MSC_ST_DEMANDS_N3_'||v_instance_code);
1740
1741 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_DEMANDS_N3_'||v_instance_code);
1742
1743 EXCEPTION
1744 WHEN OTHERS THEN
1745 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_DEMANDS_N3_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1746 END;
1747
1748 msc_analyse_tables_pk.analyse_table( 'MSC_ST_DEMANDS', v_instance_id, -1);
1749
1750 ELSIF p_batch_index = 'SO' THEN
1751
1752 BEGIN
1753 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1754 application_short_name => 'MSC',
1755 statement_type => AD_DDL.CREATE_INDEX,
1756 statement =>
1757 'create index MSC_ST_SO_N2_'||v_instance_code
1758 ||' on MSC_ST_SALES_ORDERS '
1759 ||' (sales_order_number, batch_id ,sr_instance_code, deleted_flag) '
1760 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1761 object_name => 'MSC_ST_SO_N2_'||v_instance_code);
1762
1763 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_SO_N2_'||v_instance_code);
1764
1765 EXCEPTION
1766 WHEN OTHERS THEN
1767 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_SO_N2_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1768 END;
1769
1770 BEGIN
1771 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1772 application_short_name => 'MSC',
1773 statement_type => AD_DDL.CREATE_INDEX,
1774 statement =>
1775 'create index MSC_ST_SO_N3_'||v_instance_code
1776 ||' on MSC_ST_SALES_ORDERS '
1777 ||' (sr_instance_code, batch_id , deleted_flag) '
1778 ||' STORAGE (INITIAL 100K NEXT 1M PCTINCREASE 0) ',
1779 object_name => 'MSC_ST_SO_N3_'||v_instance_code);
1780
1781 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Created Index MSC_ST_SO_N3_'||v_instance_code);
1782
1783 EXCEPTION
1784 WHEN OTHERS THEN
1785 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error creating Index MSC_ST_SO_N3_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1786 END;
1787
1788 msc_analyse_tables_pk.analyse_table( 'MSC_ST_SALES_ORDERS', v_instance_id, -1);
1789
1790 END IF;
1791
1792 EXCEPTION
1793 when others then
1794 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'CREATE_INDEXES: '||dbms_utility.format_error_stack );
1795 END CREATE_INDEXES;
1796
1797 -- ===== DROP_INDEXES================
1798 PROCEDURE DROP_INDEXES IS
1799 BEGIN
1800
1801 IF v_item_enabled = SYS_YES THEN
1802
1803 BEGIN
1804 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1805 application_short_name => 'MSC',
1806 statement_type => AD_DDL.DROP_INDEX,
1807 statement =>
1808 'drop index MSC_ST_SYSTEM_ITEMS_N1_'||v_instance_code,
1809 object_name => 'MSC_ST_SYSTEM_ITEMS_N1_'||v_instance_code);
1810
1811 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_SYSTEM_ITEMS_N1_'||v_instance_code);
1812
1813 EXCEPTION
1814 WHEN OTHERS THEN
1815 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_SYSTEM_ITEMS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1816 END;
1817
1818 BEGIN
1819 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1820 application_short_name => 'MSC',
1821 statement_type => AD_DDL.DROP_INDEX,
1822 statement =>
1823 'drop index MSC_ST_SYSTEM_ITEMS_N2_'||v_instance_code,
1824 object_name => 'MSC_ST_SYSTEM_ITEMS_N2_'||v_instance_code);
1825
1826 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_SYSTEM_ITEMS_N2_'||v_instance_code);
1827
1828 EXCEPTION
1829 WHEN OTHERS THEN
1830 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_SYSTEM_ITEMS_N2_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1831 END;
1832
1833 msc_analyse_tables_pk.analyse_table( 'MSC_LOCAL_ID_ITEM', v_instance_id, -1);
1834
1835 END IF;
1836
1837 IF v_mat_sup_enabled = SYS_YES THEN
1838
1839 BEGIN
1840 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1841 application_short_name => 'MSC',
1842 statement_type => AD_DDL.DROP_INDEX,
1843 statement =>
1844 'drop index MSC_ST_SUPPLIES_N1_'||v_instance_code,
1845 object_name => 'MSC_ST_SUPPLIES_N1_'||v_instance_code);
1846
1847 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_SUPPLIES_N1_'||v_instance_code);
1848
1849 EXCEPTION
1850 WHEN OTHERS THEN
1851 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_SUPPLIES_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1852 END;
1853
1854 BEGIN
1855 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1856 application_short_name => 'MSC',
1857 statement_type => AD_DDL.DROP_INDEX,
1858 statement =>
1859 'drop index MSC_ST_SUPPLIES_N2_'||v_instance_code,
1860 object_name => 'MSC_ST_SUPPLIES_N2_'||v_instance_code);
1861
1862 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_SUPPLIES_N2_'||v_instance_code);
1863 EXCEPTION
1864 WHEN OTHERS THEN
1865 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_SUPPLIES_N2_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1866 END;
1867
1868 BEGIN
1869 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1870 application_short_name => 'MSC',
1871 statement_type => AD_DDL.DROP_INDEX,
1872 statement =>
1873 'drop index MSC_ST_SUPPLIES_N3_'||v_instance_code,
1874 object_name => 'MSC_ST_SUPPLIES_N3_'||v_instance_code);
1875
1876 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_SUPPLIES_N3_'||v_instance_code);
1877 EXCEPTION
1878 WHEN OTHERS THEN
1879 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_SUPPLIES_N3_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1880 END;
1881
1882 BEGIN
1883 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1884 application_short_name => 'MSC',
1885 statement_type => AD_DDL.DROP_INDEX,
1886 statement =>
1887 'drop index MSC_ST_SUPPLIES_N4_'||v_instance_code,
1888 object_name => 'MSC_ST_SUPPLIES_N4_'||v_instance_code);
1889
1890 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_SUPPLIES_N4_'||v_instance_code);
1891 EXCEPTION
1892 WHEN OTHERS THEN
1893 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_SUPPLIES_N4_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1894 END;
1895
1896 BEGIN
1897 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1898 application_short_name => 'MSC',
1899 statement_type => AD_DDL.DROP_INDEX,
1900 statement =>
1901 'drop index MSC_ST_SUPPLIES_N5_'||v_instance_code,
1902 object_name => 'MSC_ST_SUPPLIES_N5_'||v_instance_code);
1903
1904 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_SUPPLIES_N5_'||v_instance_code);
1905
1906 EXCEPTION
1907 WHEN OTHERS THEN
1908 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_SUPPLIES_N5_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1909 END;
1910
1911 msc_analyse_tables_pk.analyse_table( 'MSC_LOCAL_ID_SUPPLY', v_instance_id, -1);
1912
1913 END IF;
1914
1915 IF v_mat_dmd_enabled = SYS_YES THEN
1916
1917 BEGIN
1918 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1919 application_short_name => 'MSC',
1920 statement_type => AD_DDL.DROP_INDEX,
1921 statement =>
1922 'drop index MSC_ST_DEMANDS_N1_'||v_instance_code,
1923 object_name => 'MSC_ST_DEMANDS_N1_'||v_instance_code);
1924
1925 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_DEMANDS_N1_'||v_instance_code);
1926 EXCEPTION
1927 WHEN OTHERS THEN
1928 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_DEMANDS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1929 END;
1930
1931 BEGIN
1932 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1933 application_short_name => 'MSC',
1934 statement_type => AD_DDL.DROP_INDEX,
1935 statement =>
1936 'drop index MSC_ST_DEMANDS_N2_'||v_instance_code,
1937 object_name => 'MSC_ST_DEMANDS_N2_'||v_instance_code);
1938
1939 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_DEMANDS_N2_'||v_instance_code);
1940 EXCEPTION
1941 WHEN OTHERS THEN
1942 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_DEMANDS_N2_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1943 END;
1944
1945 BEGIN
1946 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1947 application_short_name => 'MSC',
1948 statement_type => AD_DDL.DROP_INDEX,
1949 statement =>
1950 'drop index MSC_ST_DEMANDS_N3_'||v_instance_code,
1951 object_name => 'MSC_ST_DEMANDS_N3_'||v_instance_code);
1952
1953 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_DEMANDS_N3_'||v_instance_code);
1954
1955 EXCEPTION
1956 WHEN OTHERS THEN
1957 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_DEMANDS_N3_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1958 END;
1959
1960 BEGIN
1961 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1962 application_short_name => 'MSC',
1963 statement_type => AD_DDL.DROP_INDEX,
1964 statement =>
1965 'drop index MSC_ST_SO_N1_'||v_instance_code,
1966 object_name => 'MSC_ST_SO_N1_'||v_instance_code);
1967
1968 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_SO_N1_'||v_instance_code);
1969 EXCEPTION
1970 WHEN OTHERS THEN
1971 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_SO_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1972 END;
1973
1974 BEGIN
1975 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1976 application_short_name => 'MSC',
1977 statement_type => AD_DDL.DROP_INDEX,
1978 statement =>
1979 'drop index MSC_ST_SO_N2_'||v_instance_code,
1980 object_name => 'MSC_ST_SO_N2_'||v_instance_code);
1981
1982 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_SO_N2_'||v_instance_code);
1983 EXCEPTION
1984 WHEN OTHERS THEN
1985 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_SO_N2_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
1986 END;
1987
1988 BEGIN
1989 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
1990 application_short_name => 'MSC',
1991 statement_type => AD_DDL.DROP_INDEX,
1992 statement =>
1993 'drop index MSC_ST_SO_N3_'||v_instance_code,
1994 object_name => 'MSC_ST_SO_N3_'||v_instance_code);
1995
1996 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_SO_N3_'||v_instance_code);
1997
1998 EXCEPTION
1999 WHEN OTHERS THEN
2000 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_SO_N3_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2001 END;
2002
2003 msc_analyse_tables_pk.analyse_table( 'MSC_LOCAL_ID_DEMAND', v_instance_id, -1);
2004
2005 END IF;
2006
2007 IF v_reserve_enabled = SYS_YES THEN
2008 BEGIN
2009 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2010 application_short_name => 'MSC',
2011 statement_type => AD_DDL.DROP_INDEX,
2012 statement =>
2013 'drop index MSC_ST_RESERVE_N1_'||v_instance_code,
2014 object_name => 'MSC_ST_RESERVE_N1_'||v_instance_code);
2015
2016 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_RESERVE_N1_'||v_instance_code);
2017 EXCEPTION
2018 WHEN OTHERS THEN
2019 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_RESERVE_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2020 END;
2021 END IF;
2022
2023 IF v_bom_enabled = SYS_YES THEN
2024
2025 BEGIN
2026 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2027 application_short_name => 'MSC',
2028 statement_type => AD_DDL.DROP_INDEX,
2029 statement =>
2030 'drop index MSC_ST_BOMS_N1_'||v_instance_code,
2031 object_name => 'MSC_ST_BOMS_N1_'||v_instance_code);
2032
2033 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_BOMS_N1_'||v_instance_code);
2034 EXCEPTION
2035 WHEN OTHERS THEN
2036 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_BOMS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2037 END;
2038
2039 BEGIN
2040 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2041 application_short_name => 'MSC',
2042 statement_type => AD_DDL.DROP_INDEX,
2043 statement =>
2044 'drop index MSC_ST_BOM_COMP_N1_'||v_instance_code,
2045 object_name => 'MSC_ST_BOM_COMP_N1_'||v_instance_code);
2046
2047 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_BOM_COMP_N1_'||v_instance_code);
2048 EXCEPTION
2049 WHEN OTHERS THEN
2050 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_BOM_COMP_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2051 END;
2052
2053 BEGIN
2054 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2055 application_short_name => 'MSC',
2056 statement_type => AD_DDL.DROP_INDEX,
2057 statement =>
2058 'drop index MSC_ST_COMP_SUB_N1_'||v_instance_code,
2059 object_name => 'MSC_ST_COMP_SUB_N1_'||v_instance_code);
2060
2061 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_COMP_SUB_N1_'||v_instance_code);
2062
2063 EXCEPTION
2064 WHEN OTHERS THEN
2065 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_COMP_SUB_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2066 END;
2067
2068 -- Added for Co Products (OSFM Integration --
2069 BEGIN
2070 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2071 application_short_name => 'MSC',
2072 statement_type => AD_DDL.DROP_INDEX,
2073 statement =>
2074 'drop index MSC_ST_CO_PRODUCTS_N1_'||v_instance_code,
2075 object_name => 'MSC_ST_CO_PRODUCTS_N1_'||v_instance_code);
2076
2077 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_CO_PRODUCTS_N1_'||v_instance_code);
2078 EXCEPTION
2079 WHEN OTHERS THEN
2080 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_CO_PRODUCTS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2081 END;
2082
2083 END IF;
2084
2085 IF v_rtg_enabled = SYS_YES THEN
2086
2087 BEGIN
2088 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2089 application_short_name => 'MSC',
2090 statement_type => AD_DDL.DROP_INDEX,
2091 statement =>
2092 'drop index MSC_ST_ROUTINGS_N1_'||v_instance_code,
2093 object_name => 'MSC_ST_ROUTINGS_N1_'||v_instance_code);
2094
2095 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_ROUTINGS_N1_'||v_instance_code);
2096 EXCEPTION
2097 WHEN OTHERS THEN
2098 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_ROUTINGS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2099 END;
2100
2101 BEGIN
2102 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2103 application_short_name => 'MSC',
2104 statement_type => AD_DDL.DROP_INDEX,
2105 statement =>
2106 'drop index MSC_ST_ROUTING_OPER_N1_'||v_instance_code,
2107 object_name => 'MSC_ST_ROUTING_OPER_N1_'||v_instance_code);
2108
2109 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_ROUTING_OPER_N1_'||v_instance_code);
2110
2111 EXCEPTION
2112 WHEN OTHERS THEN
2113 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_ROUTING_OPER_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2114 END;
2115
2116 BEGIN
2117 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2118 application_short_name => 'MSC',
2119 statement_type => AD_DDL.DROP_INDEX,
2120 statement =>
2121 'drop index MSC_ST_OPER_RES_N1_'||v_instance_code,
2122 object_name => 'MSC_ST_OPER_RES_N1_'||v_instance_code);
2123
2124 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_OPER_RES_N1_'||v_instance_code);
2125
2126 EXCEPTION
2127 WHEN OTHERS THEN
2128 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_OPER_RES_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2129 END;
2130
2131 -- Added for Operation Networks (OSFM Integration)--
2132 BEGIN
2133 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2134 application_short_name => 'MSC',
2135 statement_type => AD_DDL.DROP_INDEX,
2136 statement =>
2137 'drop index MSC_ST_OPER_NTWK_N1_'||v_instance_code,
2138 object_name => 'MSC_ST_OPER_NTWK_N1_'||v_instance_code);
2139
2140
2141 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_OPER_NTWK_N1_'||v_instance_code);
2142
2143 EXCEPTION
2144 WHEN OTHERS THEN
2145 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_OPER_NTWK_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2146 END;
2147
2148 END IF;
2149
2150 IF v_item_cat_enabled = SYS_YES THEN
2151
2152 BEGIN
2153 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2154 application_short_name => 'MSC',
2155 statement_type => AD_DDL.DROP_INDEX,
2156 statement =>
2157 'drop index MSC_ST_ITEM_CAT_N1_'||v_instance_code,
2158 object_name => 'MSC_ST_ITEM_CAT_N1_'||v_instance_code);
2159
2160 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_ITEM_CAT_N1_'||v_instance_code);
2161
2162 EXCEPTION
2163 WHEN OTHERS THEN
2164 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_ITEM_CAT_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2165 END;
2166
2167 BEGIN
2168 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2169 application_short_name => 'MSC',
2170 statement_type => AD_DDL.DROP_INDEX,
2171 statement =>
2172 'drop index MSC_ST_ITEM_CAT_N2_'||v_instance_code,
2173 object_name => 'MSC_ST_ITEM_CAT_N2_'||v_instance_code);
2174
2175 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_ITEM_CAT_N2_'||v_instance_code);
2176
2177 EXCEPTION
2178 WHEN OTHERS THEN
2179 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_ITEM_CAT_N2_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2180 END;
2181 END IF;
2182
2183
2184 IF v_resources_enabled = SYS_YES THEN
2185
2186 BEGIN
2187 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2188 application_short_name => 'MSC',
2189 statement_type => AD_DDL.DROP_INDEX,
2190 statement =>
2191 'drop index MSC_ST_RESOURCE_GROUPS_N1_'||v_instance_code,
2192 object_name => 'MSC_ST_RESOURCE_GROUPS_N1_'||v_instance_code);
2193
2194 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_RESOURCE_GROUPS_N1_'||v_instance_code);
2195
2196 EXCEPTION
2197 WHEN OTHERS THEN
2198 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_RESOURCE_GROUPS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2199 END;
2200
2201 BEGIN
2202 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2203 application_short_name => 'MSC',
2204 statement_type => AD_DDL.DROP_INDEX,
2205 statement =>
2206 'drop index MSC_ST_DEPT_RES_N1_'||v_instance_code,
2207 object_name => 'MSC_ST_DEPT_RES_N1_'||v_instance_code);
2208
2209 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_DEPT_RES_N1_'||v_instance_code);
2210
2211 EXCEPTION
2212 WHEN OTHERS THEN
2213 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_DEPT_RES_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2214 END;
2215
2216 BEGIN
2217 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2218 application_short_name => 'MSC',
2219 statement_type => AD_DDL.DROP_INDEX,
2220 statement =>
2221 'drop index MSC_ST_RES_SHIFTS_N1_'||v_instance_code,
2222 object_name => 'MSC_ST_RES_SHIFTS_N1_'||v_instance_code);
2223
2224 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_RES_SHIFTS_N1_'||v_instance_code);
2225
2226 EXCEPTION
2227 WHEN OTHERS THEN
2228 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_RES_SHIFTS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2229 END;
2230
2231 BEGIN
2232 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2233 application_short_name => 'MSC',
2234 statement_type => AD_DDL.DROP_INDEX,
2235 statement =>
2236 'drop index MSC_ST_RES_CHANGES_N1_'||v_instance_code,
2237 object_name => 'MSC_ST_RES_CHANGES_N1_'||v_instance_code);
2238
2239 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_RES_CHANGES_N1_'||v_instance_code);
2240
2241
2242 EXCEPTION
2243 WHEN OTHERS THEN
2244 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_RES_CHANGES_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2245 END;
2246
2247 END IF;
2248
2249
2250 IF v_project_enabled = SYS_YES THEN
2251
2252 BEGIN
2253
2254 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2255 application_short_name => 'MSC',
2256 statement_type => AD_DDL.DROP_INDEX,
2257 statement =>
2258 'drop index MSC_ST_PROJECT_TASKS_N1_'||v_instance_code,
2259 object_name => 'MSC_ST_PROJECT_TASKS_N1_'||v_instance_code);
2260
2261 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_PROJECT_TASKS_N1_'||v_instance_code);
2262
2263
2264 EXCEPTION
2265 WHEN OTHERS THEN
2266 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_PROJECT_TASKS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2267 END;
2268
2269 END IF;
2270
2271 IF v_dmd_class_enabled = SYS_YES THEN
2272
2273 BEGIN
2274 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2275 application_short_name => 'MSC',
2276 statement_type => AD_DDL.DROP_INDEX,
2277 statement =>
2278 'drop index MSC_ST_DMD_CLASS_N1_'||v_instance_code,
2279 object_name => 'MSC_ST_DMD_CLASS_N1_'||v_instance_code);
2280
2281 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_DMD_CLASS_N1_'||v_instance_code);
2282
2283 EXCEPTION
2284 WHEN OTHERS THEN
2285 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_DMD_CLASS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2286 END;
2287 END IF;
2288
2289 IF v_tp_enabled = SYS_YES THEN
2290
2291 BEGIN
2292 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2293 application_short_name => 'MSC',
2294 statement_type => AD_DDL.DROP_INDEX,
2295 statement =>
2296 'drop index MSC_ST_TRADING_PART_N1_'||v_instance_code,
2297 object_name => 'MSC_ST_TRADING_PART_N1_'||v_instance_code);
2298
2299 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_TRADING_PART_N1_'||v_instance_code);
2300
2301 EXCEPTION
2302 WHEN OTHERS THEN
2303 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_TRADING_PART_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2304 END;
2305
2306 BEGIN
2307 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2308 application_short_name => 'MSC',
2309 statement_type => AD_DDL.DROP_INDEX,
2310 statement =>
2311 'drop index MSC_ST_TRADING_PART_N2_'||v_instance_code,
2312 object_name => 'MSC_ST_TRADING_PART_N2_'||v_instance_code);
2313
2314 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_TRADING_PART_N2_'||v_instance_code);
2315
2316 EXCEPTION
2317 WHEN OTHERS THEN
2318 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_TRADING_PART_N2_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2319 END;
2320
2321 BEGIN
2322 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2323 application_short_name => 'MSC',
2324 statement_type => AD_DDL.DROP_INDEX,
2325 statement =>
2326 'drop index MSC_ST_TRD_PART_SITES_N1_'||v_instance_code,
2327 object_name => 'MSC_ST_TRD_PART_SITES_N1_'||v_instance_code);
2328
2329 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_TRD_PART_SITES_N1_'||v_instance_code);
2330
2331 EXCEPTION
2332 WHEN OTHERS THEN
2333 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_TRD_PART_SITES_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2334 END;
2335
2336 BEGIN
2337 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2338 application_short_name => 'MSC',
2339 statement_type => AD_DDL.DROP_INDEX,
2340 statement =>
2341 'drop index MSC_ST_SUB_INV_N1_'||v_instance_code,
2342 object_name => 'MSC_ST_SUB_INV_N1_'||v_instance_code);
2343
2344 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_SUB_INV_N1_'||v_instance_code);
2345
2346 EXCEPTION
2347 WHEN OTHERS THEN
2348 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_SUB_INV_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2349 END;
2350
2351 BEGIN
2352 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2353 application_short_name => 'MSC',
2354 statement_type => AD_DDL.DROP_INDEX,
2355 statement =>
2356 'drop index MSC_ST_LOC_ASC_N1_'||v_instance_code,
2357 object_name => 'MSC_ST_LOC_ASC_N1_'||v_instance_code);
2358
2359 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_LOC_ASC_N1_'||v_instance_code);
2360
2361 EXCEPTION
2362 WHEN OTHERS THEN
2363 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_LOC_ASC_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2364 END;
2365
2366 BEGIN
2367 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2368 application_short_name => 'MSC',
2369 statement_type => AD_DDL.DROP_INDEX,
2370 statement =>
2371 'drop index MSC_ST_PART_CONT_N1_'||v_instance_code,
2372 object_name => 'MSC_ST_PART_CONT_N1_'||v_instance_code);
2373
2374 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_PART_CONT_N1_'||v_instance_code);
2375 EXCEPTION
2376 WHEN OTHERS THEN
2377 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_PART_CONT_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2378 END;
2379
2380 -- For Aeroexchange
2381 -- Drop index of MSC_ST_GROUP_COMPANIES
2382
2383 BEGIN
2384 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2385 application_short_name => 'MSC',
2386 statement_type => AD_DDL.DROP_INDEX,
2387 statement =>
2388 'drop index MSC_ST_GROUP_COMPANIES_N1_'||v_instance_code,
2389 object_name => 'MSC_ST_GROUP_COMPANIES_N1_'||v_instance_code);
2390
2391 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_GROUP_COMPANIES_N1_'||v_instance_code);
2392
2393 EXCEPTION
2394 WHEN OTHERS THEN
2395 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_GROUP_COMPANIES_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2396 END;
2397
2398
2399 ---- Drop index of MSC_ST_GROUPS
2400 BEGIN
2401 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2402 application_short_name => 'MSC',
2403 statement_type => AD_DDL.DROP_INDEX,
2404 statement =>
2405 'drop index MSC_ST_GROUPS_N1_'||v_instance_code,
2406 object_name => 'MSC_ST_GROUPS_N1_'||v_instance_code);
2407
2408 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_GROUPS_N1_'||v_instance_code);
2409
2410 EXCEPTION
2411 WHEN OTHERS THEN
2412 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_GROUPS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2413 END;
2414
2415
2416 END IF;
2417
2418 -- For bug fix 2379391, dropping the indexes for MSC_ST_ITEM_CUSTOMERS
2419 IF v_item_cst_enabled = SYS_YES THEN
2420
2421 BEGIN
2422 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2423 application_short_name => 'MSC',
2424 statement_type => AD_DDL.DROP_INDEX,
2425 statement =>
2426 'drop index MSC_ST_ITEM_CUSTOMERS_N1_'||v_instance_code,
2427 object_name => 'MSC_ST_ITEM_CUSTOMERS_N1_'||v_instance_code);
2428
2429 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_ITEM_CUSTOMERS_N1_'||v_instance_code);
2430
2431 EXCEPTION
2432 WHEN OTHERS THEN
2433 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_ITEM_CUSTOMERS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2434 END;
2435
2436 BEGIN
2437 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2438 application_short_name => 'MSC',
2439 statement_type => AD_DDL.DROP_INDEX,
2440 statement =>
2441 'drop index MSC_ST_ITEM_CUSTOMERS_N2_'||v_instance_code,
2442 object_name => 'MSC_ST_ITEM_CUSTOMERS_N2_'||v_instance_code);
2443
2444 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_ITEM_CUSTOMERS_N2_'||v_instance_code);
2445
2446 EXCEPTION
2447 WHEN OTHERS THEN
2448 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_ITEM_CUSTOMERS_N2_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2449 END;
2450
2451 msc_analyse_tables_pk.analyse_table( 'MSC_ST_ITEM_CUSTOMERS', v_instance_id, -1);
2452
2453 END IF;
2454
2455 IF v_ship_mthd_enabled = SYS_YES THEN
2456
2457 BEGIN
2458 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2459 application_short_name => 'MSC',
2460 statement_type => AD_DDL.DROP_INDEX,
2461 statement =>
2462 'drop index MSC_ST_INTERORG_SHIP_N1_'||v_instance_code,
2463 object_name => 'MSC_ST_INTERORG_SHIP_N1_'||v_instance_code);
2464
2465 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_INTERORG_SHIP_N1_'||v_instance_code);
2466
2467 EXCEPTION
2468 WHEN OTHERS THEN
2469 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_INTERORG_SHIP_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2470 END;
2471 END IF;
2472
2473 IF v_sourcing_enabled = SYS_YES THEN
2474
2475 BEGIN
2476 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2477 application_short_name => 'MSC',
2478 statement_type => AD_DDL.DROP_INDEX,
2479 statement =>
2480 'drop index MSC_ST_ITEM_SRC_N1_'||v_instance_code,
2481 object_name => 'MSC_ST_ITEM_SRC_N1_'||v_instance_code);
2482
2483 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_ITEM_SRC_N1_'||v_instance_code);
2484
2485 EXCEPTION
2486 WHEN OTHERS THEN
2487 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_ITEM_SRC_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2488 END;
2489
2490 BEGIN
2491 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2492 application_short_name => 'MSC',
2493 statement_type => AD_DDL.DROP_INDEX,
2494 statement =>
2495 'drop index MSC_ST_REGIONS_N1_'||v_instance_code,
2496 object_name => 'MSC_ST_REGIONS_N1_'||v_instance_code);
2497
2498 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_REGIONS_N1_'||v_instance_code);
2499
2500 EXCEPTION
2501 WHEN OTHERS THEN
2502 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_REGIONS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2503 END;
2504
2505 BEGIN
2506 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2507 application_short_name => 'MSC',
2508 statement_type => AD_DDL.DROP_INDEX,
2509 statement =>
2510 'drop index MSC_ST_ZONE_REGIONS_N1_'||v_instance_code,
2511 object_name => 'MSC_ST_ZONE_REGIONS_N1_'||v_instance_code);
2512
2513 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_ZONE_REGIONS_N1_'||v_instance_code);
2514
2515 EXCEPTION
2516 WHEN OTHERS THEN
2517 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_ZONE_REGIONS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2518 END;
2519
2520 BEGIN
2521 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2522 application_short_name => 'MSC',
2523 statement_type => AD_DDL.DROP_INDEX,
2524 statement =>
2525 'drop index MSC_ST_REGION_LOC_N1_'||v_instance_code,
2526 object_name => 'MSC_ST_REGION_LOC_N1_'||v_instance_code);
2527
2528 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_REGION_LOC_N1_'||v_instance_code);
2529
2530 EXCEPTION
2531 WHEN OTHERS THEN
2532 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_REGION_LOC_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2533 END;
2534
2535 BEGIN
2536 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2537 application_short_name => 'MSC',
2538 statement_type => AD_DDL.DROP_INDEX,
2539 statement =>
2540 'drop index MSC_ST_REGION_SITE_N1_'||v_instance_code,
2541 object_name => 'MSC_ST_REGION_SITE_N1_'||v_instance_code);
2542
2543 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_REGION_SITE_N1_'||v_instance_code);
2544
2545 EXCEPTION
2546 WHEN OTHERS THEN
2547 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_REGION_SITE_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2548 END;
2549
2550 END IF;
2551
2552 IF v_res_dmd_enabled = SYS_YES THEN
2553
2554 BEGIN
2555 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2556 application_short_name => 'MSC',
2557 statement_type => AD_DDL.DROP_INDEX,
2558 statement =>
2559 'drop index MSC_ST_RES_REQ_N1_'||v_instance_code,
2560 object_name => 'MSC_ST_RES_REQ_N1_'||v_instance_code);
2561
2562 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_RES_REQ_N1_'||v_instance_code);
2563
2564 EXCEPTION
2565 WHEN OTHERS THEN
2566 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_RES_REQ_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2567 END;
2568 END IF;
2569
2570 IF v_sup_cap_enabled = SYS_YES THEN
2571
2572 BEGIN
2573 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2574 application_short_name => 'MSC',
2575 statement_type => AD_DDL.DROP_INDEX,
2576 statement =>
2577 'drop index MSC_ST_ITEM_SUP_N1_'||v_instance_code,
2578 object_name => 'MSC_ST_ITEM_SUP_N1_'||v_instance_code);
2579
2580 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_ITEM_SUP_N1_'||v_instance_code);
2581
2582 EXCEPTION
2583 WHEN OTHERS THEN
2584 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_ITEM_SUP_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2585 END;
2586
2587 BEGIN
2588 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2589 application_short_name => 'MSC',
2590 statement_type => AD_DDL.DROP_INDEX,
2591 statement =>
2592 'drop index MSC_ST_SUP_CAP_N1_'||v_instance_code,
2593 object_name => 'MSC_ST_SUP_CAP_N1_'||v_instance_code);
2594
2595 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_SUP_CAP_N1_'||v_instance_code);
2596
2597 EXCEPTION
2598 WHEN OTHERS THEN
2599 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_SUP_CAP_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2600 END;
2601
2602 BEGIN
2603 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2604 application_short_name => 'MSC',
2605 statement_type => AD_DDL.DROP_INDEX,
2606 statement =>
2607 'drop index MSC_ST_SUP_FENCES_N1_'||v_instance_code,
2608 object_name => 'MSC_ST_SUP_FENCES_N1_'||v_instance_code);
2609
2610
2611 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_SUP_FENCES_N1_'||v_instance_code);
2612
2613 EXCEPTION
2614 WHEN OTHERS THEN
2615 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_SUP_FENCES_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2616 END;
2617
2618 END IF;
2619
2620 IF v_safety_stk_enabled = SYS_YES THEN
2621
2622 BEGIN
2623 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2624 application_short_name => 'MSC',
2625 statement_type => AD_DDL.DROP_INDEX,
2626 statement =>
2627 'drop index MSC_ST_SAFETY_STOCKS_N1_'||v_instance_code,
2628 object_name => 'MSC_ST_SAFETY_STOCKS_N1_'||v_instance_code);
2629
2630
2631 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_SAFETY_STOCKS_N1_'||v_instance_code);
2632
2633 EXCEPTION
2634 WHEN OTHERS THEN
2635 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_SAFETY_STOCKS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2636 END;
2637
2638 END IF;
2639
2640 IF v_item_substitute_enabled = SYS_YES THEN
2641
2642 BEGIN
2643 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2644 application_short_name => 'MSC',
2645 statement_type => AD_DDL.DROP_INDEX,
2646 statement =>
2647 'drop index MSC_ST_ITEM_SUBSTITUTES_N1_'||v_instance_code,
2648 object_name => 'MSC_ST_ITEM_SUBSTITUTES_N1_'||v_instance_code);
2649
2650 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_ITEM_SUBSTITUTES_N1_'||v_instance_code);
2651
2652 EXCEPTION
2653 WHEN OTHERS THEN
2654 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_ITEM_SUBSTITUTES_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2655 END;
2656
2657 END IF;
2658
2659 IF v_planners_enabled = SYS_YES THEN
2660
2661 BEGIN
2662 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2663 application_short_name => 'MSC',
2664 statement_type => AD_DDL.DROP_INDEX,
2665 statement =>
2666 'drop index MSC_ST_PLANNERS_N1_'||v_instance_code,
2667 object_name => 'MSC_ST_PLANNERS_N1_'||v_instance_code);
2668
2669 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_PLANNERS_N1_'||v_instance_code);
2670
2671 EXCEPTION
2672 WHEN OTHERS THEN
2673 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_PLANNERS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2674 END;
2675
2676 END IF;
2677
2678 IF v_uom_class_enabled = SYS_YES THEN
2679
2680 BEGIN
2681 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2682 application_short_name => 'MSC',
2683 statement_type => AD_DDL.DROP_INDEX,
2684 statement =>
2685 'drop index MSC_ST_UOM_CLS_CONV_N1_'||v_instance_code,
2686 object_name => 'MSC_ST_UOM_CLS_CONV_N1_'||v_instance_code);
2687
2688 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_UOM_CLS_CONV_N1_'||v_instance_code);
2689
2690 EXCEPTION
2691 WHEN OTHERS THEN
2692 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_UOM_CLS_CONV_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2693 END;
2694
2695 END IF;
2696
2697 IF v_mat_sup_enabled = SYS_YES THEN
2698
2699 BEGIN
2700 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2701 application_short_name => 'MSC',
2702 statement_type => AD_DDL.DROP_INDEX,
2703 statement =>
2704 'drop index MSC_ST_JOB_OP_NETWORKS_N1_'||v_instance_code,
2705 object_name => 'MSC_ST_JOB_OP_NETWORKS_N1_'||v_instance_code);
2706
2707 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_JOB_OP_NETWORKS_N1_'||v_instance_code);
2708
2709 EXCEPTION
2710 WHEN OTHERS THEN
2711 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_JOB_OP_NETWORKS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2712 END;
2713
2714 BEGIN
2715 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2716 application_short_name => 'MSC',
2717 statement_type => AD_DDL.DROP_INDEX,
2718 statement =>
2719 'drop index MSC_ST_JOB_OPERATIONS_N1_'||v_instance_code,
2720 object_name => 'MSC_ST_JOB_OPERATIONS_N1_'||v_instance_code);
2721
2722 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_JOB_OPERATIONS_N1_'||v_instance_code);
2723
2724 EXCEPTION
2725 WHEN OTHERS THEN
2726 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_JOB_OPERATIONS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2727 END;
2728
2729 BEGIN
2730 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2731 application_short_name => 'MSC',
2732 statement_type => AD_DDL.DROP_INDEX,
2733 statement =>
2734 'drop index MSC_ST_JOB_REQ_OPS_N1_'||v_instance_code,
2735 object_name => 'MSC_ST_JOB_REQ_OPS_N1_'||v_instance_code);
2736
2737 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_JOB_REQ_OPS_N1_'||v_instance_code);
2738
2739 EXCEPTION
2740 WHEN OTHERS THEN
2741 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_JOB_REQ_OPS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2742 END;
2743
2744 BEGIN
2745 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2746 application_short_name => 'MSC',
2747 statement_type => AD_DDL.DROP_INDEX,
2748 statement =>
2749 'drop index MSC_ST_JOB_OP_RESOURCES_N1_'||v_instance_code,
2750 object_name => 'MSC_ST_JOB_OP_RESOURCES_N1_'||v_instance_code);
2751
2752 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_JOB_OP_RESOURCES_N1_'||v_instance_code);
2753
2754 EXCEPTION
2755 WHEN OTHERS THEN
2756 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_JOB_OP_RESOURCES_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2757 END;
2758
2759 END IF;
2760
2761 IF v_cal_assignment_enabled = SYS_YES THEN
2762
2763 BEGIN
2764 ad_ddl.do_ddl( applsys_schema => v_applsys_schema,
2765 application_short_name => 'MSC',
2766 statement_type => AD_DDL.DROP_INDEX,
2767 statement =>
2768 'drop index MSC_ST_CAL_ASSIGNMENTS_N1_'||v_instance_code,
2769 object_name => 'MSC_ST_CAL_ASSIGNMENTS_N1_'||v_instance_code);
2770
2771 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Dropped Index MSC_ST_CAL_ASSIGNMENTS_N1_'||v_instance_code);
2772
2773 EXCEPTION
2774 WHEN OTHERS THEN
2775 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error dropping Index MSC_ST_CAL_ASSIGNMENTS_N1_'||v_instance_code||'. Error:'||substr(SQLERRM,1,240));
2776 END;
2777
2778 END IF;
2779
2780 msc_analyse_tables_pk.analyse_table( 'MSC_LOCAL_ID_SETUP', v_instance_id, -1);
2781 msc_analyse_tables_pk.analyse_table( 'MSC_LOCAL_ID_MISC', v_instance_id, -1);
2782
2783
2784 EXCEPTION
2785 when others then
2786 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'DROP_INDEXES: '||sqlerrm);
2787 END DROP_INDEXES;
2788
2789
2790 --========= Get Task Number =================
2791 FUNCTION GET_TASK_NUM(p_message VARCHAR2) RETURN NUMBER
2792 IS
2793 lv_comma_pos number:= 0;
2794 lv_length number:= 0;
2795 lv_task_num number:= 0;
2796 BEGIN
2797 -- The message in the pipe could be of the form 'task_num,batch_id'
2798 -- or just 'task_num'. The comma should be in 2nd place or higher if present.
2799 -- to get the task num we find the length till the comma and then
2800 -- extract the task number
2801
2802 lv_comma_pos:= INSTR(p_message,',');
2803 IF lv_comma_pos > 1 THEN
2804 lv_length := lv_comma_pos - 1;
2805 lv_task_num := to_number(substr(p_message,1,lv_length));
2806 ELSE
2807 lv_task_num := to_number(p_message);
2808 END IF;
2809
2810 RETURN lv_task_num;
2811
2812 exception
2813 when others then
2814 RETURN -1;
2815 end;
2816
2817
2818 FUNCTION GET_BATCH_ID(p_message VARCHAR2) RETURN NUMBER
2819 IS
2820 lv_comma_pos number := 0;
2821 lv_start_pos number := 0;
2822 lv_batch_id number := 0;
2823 BEGIN
2824 -- The message in the pipe would be of the form 'task_num,batch_id'
2825 -- or just 'task_num'. The comma should be in 2nd place or higher if present.
2826 -- to get the batch id we find the postion of the comma and then
2827 -- extract the batch id
2828
2829 lv_comma_pos:= INSTR(p_message,',');
2830 IF lv_comma_pos > 1 THEN
2831 lv_start_pos:= lv_comma_pos + 1;
2832 lv_batch_id := to_number(substr(p_message,lv_start_pos));
2833 ELSE
2834 lv_batch_id := -1;
2835 END IF;
2836
2837 RETURN lv_batch_id;
2838
2839 exception
2840 when others then
2841 RETURN -1;
2842 end;
2843
2844 PROCEDURE INITIALIZE( p_instance_id NUMBER)
2845 IS
2846 lv_last_refresh_type VARCHAR2(1) := '';
2847 lv_so_last_refresh_type VARCHAR2(1) := '';
2848 lv_retval BOOLEAN;
2849 lv_dummy1 VARCHAR2(32) := '';
2850 lv_dummy2 VARCHAR2(32) := '';
2851 lv_msc_config NUMBER := 1;
2852 BEGIN
2853
2854 SELECT LRTYPE,
2855 SO_LRTYPE,
2856 APPS_VER,
2857 SYSDATE,
2858 SYSDATE,
2859 LRID, -- gets current refresh id
2860 FND_GLOBAL.USER_ID,
2861 SYSDATE,
2862 FND_GLOBAL.USER_ID,
2863 INSTANCE_CODE,
2864 INSTANCE_TYPE -- OPM
2865 INTO lv_last_refresh_type,
2866 lv_so_last_refresh_type,
2867 v_apps_ver,
2868 START_TIME,
2869 v_current_date,
2870 v_refresh_id,
2871 v_current_user,
2872 v_current_date,
2873 v_current_user,
2874 v_instance_code,
2875 v_instance_type -- OPM
2876 FROM MSC_APPS_INSTANCES
2877 WHERE INSTANCE_ID= p_instance_id;
2878
2879
2880 -- check whether SCE is installed
2881 BEGIN
2882 lv_msc_config := FND_PROFILE.VALUE('MSC_X_CONFIGURATION');
2883
2884 EXCEPTION
2885 when others then
2886 lv_msc_config := 1;
2887 END;
2888
2889 IF lv_msc_config IN (2,3) THEN
2890 v_sce_installed := true;
2891 ELSIF lv_msc_config = 1 THEN
2892 v_sce_installed := false;
2893 END IF;
2894
2895 /*
2896 IF lv_last_refresh_type= 'C' THEN
2897 v_is_complete_refresh := TRUE;
2898 v_is_incremental_refresh := FALSE;
2899 ELSE
2900 v_is_complete_refresh := FALSE;
2901 v_is_incremental_refresh := TRUE;
2902 END IF;
2903
2904 IF lv_so_last_refresh_type= 'C' THEN
2905 v_is_so_complete_refresh := TRUE;
2906 v_is_so_incremental_refresh := FALSE;
2907 ELSE
2908 v_is_so_complete_refresh := FALSE;
2909 v_is_so_incremental_refresh := TRUE;
2910 END IF;
2911 */
2912
2913 v_pipe_task_que := 'MSC_CL_PRE_TQ'||TO_CHAR(p_instance_id);
2914 v_pipe_wm := 'MSC_CL_PRE_WM'||TO_CHAR(p_instance_id);
2915 v_pipe_mw := 'MSC_CL_PRE_MW'||TO_CHAR(p_instance_id);
2916 v_pipe_status := 'MSC_CL_PRE_ST'||TO_CHAR(p_instance_id);
2917 v_instance_id := p_instance_id;
2918
2919 MSC_ST_UTIL.v_instance_type := v_instance_type;
2920 MSC_ST_UTIL.v_instance_id := v_instance_id;
2921
2922 -------------- Get current ERROR_ID from MSC_ERRORS ---
2923 -- SELECT max(ERROR_ID) INTO v_error_no_begin FROM MSC_ERRORS;
2924
2925 ---------------- Set Flags -----------------------------
2926 -- set the flags as to whether discrete and/or process
2927 -- manufacturing are being used in the same instance
2928
2929 v_discrete_flag := SYS_NO;
2930 v_process_flag := SYS_NO;
2931
2932 IF v_instance_type = G_INS_DISCRETE OR
2933 v_instance_type = G_INS_MIXED THEN
2934 v_discrete_flag := SYS_YES;
2935 END IF;
2936
2937 IF v_instance_type = G_INS_PROCESS OR
2938 v_instance_type = G_INS_MIXED THEN
2939 v_process_flag := SYS_YES;
2940 END IF;
2941
2942 --------- Get the Application Information ---------------------
2943 -- Get the aplication info, whether MSD(ODP) is installed or not
2944
2945 lv_retval := FND_INSTALLATION.GET_APP_INFO(
2946 'MSD', lv_dummy1,lv_dummy2, v_applsys_schema);
2947
2948 IF (lv_dummy1 = 'I' OR lv_dummy1 = 'S')THEN
2949 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Oracle Demand Planning Installed');
2950 v_install_msd := TRUE ;
2951 END IF;
2952
2953 -- Get the aplication info, whether MSC(ASCP) is installed or not
2954 lv_retval := FND_INSTALLATION.GET_APP_INFO(
2955 'MSC', lv_dummy1,lv_dummy2, v_applsys_schema);
2956
2957 IF (lv_dummy1 = 'I' OR lv_dummy1 = 'S')THEN
2958 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Oracle ASCP Installed');
2959 v_install_msc := TRUE ;
2960 END IF;
2961
2962 -- set thr v_applsys_schema properly
2963
2964 lv_retval := FND_INSTALLATION.GET_APP_INFO(
2965 'FND', lv_dummy1,lv_dummy2, v_applsys_schema);
2966
2967 EXCEPTION
2968 WHEN NO_DATA_FOUND THEN
2969 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_INVALID_INSTANCE_ID');
2970 FND_MESSAGE.SET_TOKEN('INSTANCE_ID', v_pipe_wm);
2971 raise_application_error(-20101,FND_MESSAGE.GET);
2972 END INITIALIZE;
2973
2974
2975 PROCEDURE FINAL
2976 IS
2977 lv_param_rec_count PLS_INTEGER; -- for L flow
2978 BEGIN
2979
2980 UPDATE MSC_APPS_INSTANCES mai
2981 SET LAST_UPDATE_DATE = v_current_date,
2982 LAST_UPDATED_BY = v_current_user,
2983 LRID= v_refresh_id,
2984 LRTYPE= 'L',
2985 SO_LRTYPE= 'I',
2986 CLEANSED_FLAG= SYS_NO,
2987 REQUEST_ID = FND_GLOBAL.CONC_REQUEST_ID
2988 WHERE mai.INSTANCE_ID = v_instance_id;
2989
2990 -- Legacy Net Change Perf L flow changes
2991
2992 SELECT count(*)
2993 INTO lv_param_rec_count
2994 FROM msc_coll_parameters
2995 WHERE instance_id = v_instance_id;
2996
2997 IF lv_param_rec_count > 0 THEN
2998 DELETE FROM msc_coll_parameters
2999 WHERE instance_id = v_instance_id;
3000 END IF;
3001
3002 INSERT INTO msc_coll_parameters
3003 (INSTANCE_ID, delete_ods_data, supplier_capacity, atp_rules,
3004 bom, bor, calendar_check, demand_class, forecast, item,
3005 kpi_targets_bis, mds, mps, oh, parameter, planners,
3006 item_substitutes, projects, po, reservations, nra, safety_stock,
3007 sales_order, sourcing_history, sourcing, sub_inventories,
3008 customer, supplier, unit_numbers, uom, user_supply_demand, wip, user_comp_association,
3009 INTERNAL_REPAIR,EXTERNAL_REPAIR,sales_channel,fiscal_calendar,CMRO,ret_fcst,LAST_UPDATE_DATE, LAST_UPDATED_BY, CREATION_DATE, CREATED_BY)
3010 VALUES (v_instance_id, prec.purge_ods_flag,prec.app_supp_cap_flag,--13839374 added ret_fcst
3011 prec.atp_rules_flag, prec.bom_flag,
3012 prec.bor_flag, prec.calendar_flag,
3013 prec.demand_class_flag, prec.forecast_flag,
3014 prec.item_flag, prec.kpi_bis_flag,
3015 prec.mds_flag, prec.mps_flag,
3016 prec.oh_flag, prec.parameter_flag,
3017 prec.planner_flag,prec.item_subst_flag, prec.project_flag,
3018 prec.po_flag, prec.reserves_flag,
3019 prec.resource_nra_flag, prec.saf_stock_flag,
3020 prec.sales_order_flag, prec.source_hist_flag,
3021 prec.sourcing_rule_flag, prec.sub_inventory_flag,
3022 prec.tp_customer_flag, prec.tp_vendor_flag,
3023 prec.unit_number_flag, prec.uom_flag,
3024 prec.user_supply_demand_flag, prec.wip_flag, prec.user_company_flag,
3025 prec.internal_repair_flag,prec.external_repair_flag,prec.sales_channel_flag,prec.fiscal_calendar_flag,prec.CMRO_flag,prec.ret_fcst_flag,sysdate, v_current_user, sysdate, v_current_user);
3026 -- End L Flow changes
3027
3028 END FINAL;
3029
3030 FUNCTION is_monitor_status_running RETURN NUMBER
3031 IS
3032 l_call_status boolean;
3033 l_phase varchar2(80);
3034 l_status varchar2(80);
3035 l_dev_phase varchar2(80);
3036 l_dev_status varchar2(80);
3037 l_message varchar2(2048);
3038
3039 BEGIN
3040
3041 IF v_cp_enabled= SYS_NO THEN
3042 RETURN SYS_YES;
3043 END IF;
3044
3045 l_call_status:= FND_CONCURRENT.GET_REQUEST_STATUS
3046 ( v_monitor_request_id,
3047 NULL,
3048 NULL,
3049 l_phase,
3050 l_status,
3051 l_dev_phase,
3052 l_dev_status,
3053 l_message);
3054
3055 IF l_call_status=FALSE THEN
3056 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS, l_message);
3057 RETURN SYS_NO;
3058 END IF;
3059
3060 IF l_dev_phase='RUNNING' THEN
3061 RETURN SYS_YES;
3062 ELSE
3063 RETURN SYS_NO;
3064 END IF;
3065
3066 END is_monitor_status_running;
3067
3068 FUNCTION is_request_status_running RETURN NUMBER
3069 IS
3070 l_call_status boolean;
3071 l_phase varchar2(80);
3072 l_status varchar2(80);
3073 l_dev_phase varchar2(80);
3074 l_dev_status varchar2(80);
3075 l_message varchar2(2048);
3076
3077 l_request_id NUMBER;
3078
3079 BEGIN
3080
3081 IF v_cp_enabled= SYS_NO THEN
3082 RETURN SYS_YES;
3083 END IF;
3084
3085 l_request_id := FND_GLOBAL.CONC_REQUEST_ID;
3086
3087 l_call_status:= FND_CONCURRENT.GET_REQUEST_STATUS
3088 ( l_request_id,
3089 NULL,
3090 NULL,
3091 l_phase,
3092 l_status,
3093 l_dev_phase,
3094 l_dev_status,
3095 l_message);
3096
3097 IF l_call_status=FALSE THEN
3098 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS, l_message);
3099 RETURN SYS_NO;
3100 END IF;
3101
3102 IF l_dev_phase='RUNNING' THEN
3103 RETURN SYS_YES;
3104 ELSE
3105 RETURN SYS_NO;
3106 END IF;
3107
3108 END is_request_status_running;
3109
3110 FUNCTION is_worker_status_valid( ps_request_id IN NumTblTyp)
3111 RETURN NUMBER
3112 IS
3113 l_call_status boolean;
3114 l_phase varchar2(80);
3115 l_status varchar2(80);
3116 l_dev_phase varchar2(80);
3117 l_dev_status varchar2(80);
3118 l_message varchar2(2048);
3119
3120 l_request_id NUMBER;
3121 BEGIN
3122
3123 IF v_cp_enabled= SYS_NO THEN
3124 RETURN SYS_YES;
3125 END IF;
3126
3127 FOR lc_i IN 1..(ps_request_id.COUNT-1) LOOP
3128
3129 l_request_id := ps_request_id(lc_i);
3130
3131 l_call_status:= FND_CONCURRENT.GET_REQUEST_STATUS
3132 ( l_request_id,
3133 NULL,
3134 NULL,
3135 l_phase,
3136 l_status,
3137 l_dev_phase,
3138 l_dev_status,
3139 l_message);
3140
3141 IF l_call_status=FALSE THEN
3142 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS, l_message);
3143 RETURN SYS_NO;
3144 END IF;
3145
3146 IF l_dev_phase NOT IN ( 'PENDING','RUNNING') THEN
3147 RETURN SYS_NO;
3148 END IF;
3149
3150 END LOOP;
3151
3152 RETURN SYS_YES;
3153
3154 END is_worker_status_valid;
3155
3156
3157 -- Fix for 2788719.
3158 -- Returns 1 if bis periods has to be updated else 2.
3159 FUNCTION is_bis_periods_load_reqd RETURN NUMBER
3160 IS
3161 lv_rec_count_cal NUMBER:=0;
3162 lv_rec_count_mtp NUMBER:=0;
3163 BEGIN
3164
3165 BEGIN
3166 SELECT 1
3167 INTO lv_rec_count_cal
3168 FROM dual
3169 WHERE EXISTS(SELECT 1
3170 FROM msc_st_calendars
3171 WHERE sr_instance_id = v_instance_id
3172 AND process_flag = G_VALID);
3173
3174 EXCEPTION
3175 WHEN NO_DATA_FOUND THEN
3176 lv_rec_count_cal := 0;
3177 END;
3178
3179 BEGIN
3180 SELECT 1
3181 INTO lv_rec_count_mtp
3182 FROM dual
3183 WHERE EXISTS(SELECT 1
3184 FROM msc_st_trading_partners
3185 WHERE sr_instance_id = v_instance_id
3186 AND process_flag = G_VALID);
3187
3188 EXCEPTION
3189 WHEN NO_DATA_FOUND THEN
3190 lv_rec_count_mtp := 0;
3191 END;
3192 IF (lv_rec_count_cal > 0 OR lv_rec_count_mtp > 0) THEN
3193 RETURN SYS_YES;
3194 ELSE
3195 RETURN SYS_NO;
3196
3197 END IF;
3198
3199 END is_bis_periods_load_reqd;
3200
3201 ----- ============== BO VALIDATIONS START HERE ========
3202
3203 --+===========================================================================+
3204 --| DESCRIPTION : This Procedure derives the modeled partner id and |
3205 --| site id for those partners and partner sites which is |
3206 --| modeled as inventory organization. |
3207 --+===========================================================================+
3208
3209 PROCEDURE MODEL_ORG_SUPPLIER_CUSTOMER IS
3210 lv_error_text VARCHAR2(250);
3211 lv_return NUMBER;
3212 lv_message_text msc_errors.error_text%TYPE;
3213 ex_logging_err EXCEPTION;
3214
3215 BEGIN
3216
3217 v_sql_stmt := 1;
3218 UPDATE msc_st_trading_partners
3219 SET modeled_customer_id =
3220 (SELECT local_id
3221 FROM msc_local_id_setup
3222 WHERE char1 = sr_instance_code
3223 AND NVL(char2,NULL_CHAR) = NVL(company_name,NULL_CHAR)
3224 AND char3 = modeled_customer_name
3225 AND number1 = G_CUSTOMER
3226 AND entity_name = 'SR_TP_ID' )
3227 WHERE sr_instance_code = v_instance_code
3228 AND modeled_customer_name IS NOT NULL
3229 AND process_flag = G_VALID
3230 AND partner_type = G_ORGANIZATION;
3231
3232 v_sql_stmt := 2;
3233 UPDATE msc_st_trading_partners
3234 SET modeled_supplier_id =
3235 (SELECT local_id
3236 FROM msc_local_id_setup
3237 WHERE char1 = sr_instance_code
3238 AND NVL(char2,NULL_CHAR) = NVL(company_name,NULL_CHAR)
3239 AND char3 = modeled_supplier_name
3240 AND number1 = G_VENDOR
3241 AND entity_name = 'SR_TP_ID' )
3242 WHERE sr_instance_code = v_instance_code
3243 AND modeled_supplier_name IS NOT NULL
3244 AND process_flag = G_VALID
3245 AND partner_type = G_ORGANIZATION;
3246
3247 v_sql_stmt := 3;
3248 UPDATE msc_st_trading_partners
3249 SET modeled_customer_site_id =
3250 (SELECT local_id
3251 FROM msc_local_id_setup
3252 WHERE char1 = sr_instance_code
3253 AND NVL(char2,NULL_CHAR) = NVL(company_name,NULL_CHAR)
3254 AND char3 = modeled_customer_name
3255 AND char4 = modeled_customer_site_code
3256 AND number1 = G_CUSTOMER
3257 AND entity_name = 'SR_TP_SITE_ID')
3258 WHERE sr_instance_code = v_instance_code
3259 AND modeled_customer_site_code IS NOT NULL
3260 AND process_flag = G_VALID
3261 AND partner_type = G_ORGANIZATION;
3262
3263 v_sql_stmt := 4;
3264 UPDATE msc_st_trading_partners
3265 SET modeled_supplier_site_id =
3266 (SELECT local_id
3267 FROM msc_local_id_setup
3268 WHERE char1 = sr_instance_code
3269 AND NVL(char2,NULL_CHAR) = NVL(company_name,NULL_CHAR)
3270 AND char3 = modeled_supplier_name
3271 AND char4 = modeled_supplier_site_code
3272 AND number1 = G_VENDOR
3273 AND entity_name = 'SR_TP_SITE_ID')
3274 WHERE sr_instance_code = v_instance_code
3275 AND modeled_supplier_site_code IS NOT NULL
3276 AND process_flag = G_VALID
3277 AND partner_type = G_ORGANIZATION;
3278
3279 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
3280 (p_app_short_name => 'MSC',
3281 p_error_code => 'MSC_PP_INVALID_VALUE',
3282 p_message_text => lv_message_text,
3283 p_error_text => lv_error_text,
3284 p_token1 => 'COLUMN_NAME',
3285 p_token_value1 => 'MODELED_CUSTOMER_NAME OR MODELED_SUPPLIER_NAME OR '
3286 ||'MODELED_CUSTOMER_SITE_CODE OR MODELED_SUPPLIER_SITE_CODE');
3287
3288 IF lv_return <> 0 THEN
3289 RAISE ex_logging_err;
3290 END IF;
3291
3292 v_sql_stmt := 5;
3293 UPDATE msc_st_trading_partners
3294 SET error_text = lv_message_text
3295 WHERE sr_instance_code = v_instance_code
3296 AND partner_type = G_ORGANIZATION
3297 AND process_flag = G_VALID
3298 AND ((modeled_customer_id IS NULL
3299 AND modeled_customer_name IS NOT NULL)
3300 OR (modeled_supplier_id IS NULL
3301 AND modeled_supplier_name IS NOT NULL)
3302 OR (modeled_customer_site_id IS NULL
3303 AND modeled_customer_site_code IS NOT NULL)
3304 OR (modeled_supplier_site_id IS NULL
3305 AND modeled_supplier_site_code IS NOT NULL));
3306
3307 v_sql_stmt := 6;
3308 -- bug 2774016 (validation for master organization code)
3309
3310 UPDATE msc_st_trading_partners
3311 SET master_organization =
3312 (SELECT local_id
3313 FROM msc_local_id_setup
3314 WHERE char1 = sr_instance_code
3315 AND NVL(char2,NULL_CHAR) = NVL(company_name,NULL_CHAR)
3316 AND char3 = master_organization_code
3317 AND number1 = G_ORGANIZATION
3318 AND entity_name = 'SR_TP_ID' )
3319 WHERE sr_instance_code = v_instance_code
3320 AND master_organization_code IS NOT NULL
3321 AND process_flag = G_VALID
3322 AND partner_type = G_ORGANIZATION;
3323
3324 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
3325 (p_app_short_name => 'MSC',
3326 p_error_code => 'MSC_PP_INVALID_VALUE',
3327 p_message_text => lv_message_text,
3328 p_error_text => lv_error_text,
3329 p_token1 => 'COLUMN_NAME',
3330 p_token_value1 => 'MASTER_ORGANIZATION_CODE');
3331
3332 IF lv_return <> 0 THEN
3333 RAISE ex_logging_err;
3334 END IF;
3335
3336
3337 INSERT INTO msc_errors
3338 ( error_id,
3339 transaction_id,
3340 message_id,
3341 instance_code,
3342 table_name,
3343 propagated,
3344 source,
3345 rrow,
3346 severity,
3347 message_sent,
3348 last_update_date,
3349 last_updated_by,
3350 creation_date,
3351 created_by,
3352 last_update_login,
3353 request_id,
3354 program_application_id,
3355 program_id,
3356 program_update_date,
3357 error_text)
3358 SELECT
3359 msc_errors_s.NEXTVAL,
3360 st_transaction_id,
3361 message_id,
3362 sr_instance_code,
3363 'MSC_ST_TRADING_PARTNERS',
3364 'N',
3365 data_source_type,
3366 'MASTER_ORGANIZATION_CODE',
3367 G_SEV_WARNING,
3368 SYS_NO,
3369 last_update_date,
3370 last_updated_by,
3371 creation_date,
3372 created_by,
3373 last_update_login,
3374 request_id,
3375 program_application_id,
3376 program_id,
3377 program_update_date,
3378 lv_message_text
3379 FROM
3380 MSC_ST_TRADING_PARTNERS
3381 WHERE sr_instance_code = v_instance_code
3382 AND partner_type = G_ORGANIZATION
3383 AND process_flag = G_VALID
3384 AND (master_organization IS NULL
3385 AND master_organization_code IS NOT NULL);
3386
3387
3388 commit;
3389
3390 EXCEPTION
3391 WHEN OTHERS THEN
3392 lv_error_text := substr('MSC_CL_PRE_PROCESS.MODEL_ORG_SUPPLIER_CUSTOMER'||'('
3393 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
3394 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
3395 ROLLBACK;
3396
3397 END MODEL_ORG_SUPPLIER_CUSTOMER;
3398
3399
3400 /*==========================================================================+
3401 | DESCRIPTION : This function errors out the record for which the |
3402 | validation failed and inserts a record into the error |
3403 | table. And then this error is propagated to the remaining |
3404 | calendar summary tables(with the process_flag = 4) |
3405 +==========================================================================*/
3406 FUNCTION PROPAGATE_CAL_ERROR
3407 (p_table_name VARCHAR2,
3408 p_transaction_id NUMBER,
3409 p_calendar_code VARCHAR2,
3410 p_message_text VARCHAR2,
3411 p_column_names VARCHAR2,
3412 p_error_text OUT NOCOPY VARCHAR2)
3413 RETURN NUMBER IS
3414 lv_sql_stmt VARCHAR2(5000);
3415 lv_status NUMBER := 0;
3416 lv_column_names VARCHAR2(5000); --stores concatenated column names
3417 lv_error_type NUMBER;
3418
3419 BEGIN
3420
3421 IF p_table_name = 'MSC_ST_CALENDARS' THEN
3422 v_sql_stmt := 1;
3423 lv_sql_stmt :=
3424 'UPDATE msc_st_calendars'
3425 ||' set process_flag = '||G_ERROR_FLG||','
3426 ||' error_text = :p_message_text'
3427 ||' WHERE st_transaction_id = :p_transaction_id'
3428 ||' AND sr_instance_code = :instance_code'
3429 ||' AND process_flag = '||G_IN_PROCESS
3430 ||' AND calendar_code = :calendar_code';
3431
3432 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
3433
3434 EXECUTE IMMEDIATE lv_sql_stmt
3435 USING p_message_text,
3436 p_transaction_id,
3437 v_instance_code,
3438 p_calendar_code;
3439
3440 ELSIF p_table_name = 'MSC_ST_WORKDAY_PATTERNS' THEN
3441
3442 v_sql_stmt := 2;
3443 lv_sql_stmt :=
3444 'UPDATE msc_st_workday_patterns'
3445 ||' set process_flag = '||G_ERROR_FLG||','
3446 ||' error_text = :p_message_text'
3447 ||' WHERE st_transaction_id = :p_transaction_id'
3448 ||' AND sr_instance_code = :instance_code'
3449 ||' AND process_flag = '||G_IN_PROCESS
3450 ||' AND calendar_code = :calendar_code';
3451
3452 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
3453
3454 EXECUTE IMMEDIATE lv_sql_stmt
3455 USING p_message_text,
3456 p_transaction_id,
3457 v_instance_code,
3458 p_calendar_code;
3459
3460 ELSIF p_table_name = 'MSC_ST_SHIFT_TIMES' THEN
3461
3462 v_sql_stmt := 3;
3463 lv_sql_stmt :=
3464 'UPDATE msc_st_shift_times'
3465 ||' set process_flag = '||G_ERROR_FLG||','
3466 ||' error_text = :p_message_text'
3467 ||' WHERE st_transaction_id = :p_transaction_id'
3468 ||' AND sr_instance_code = :instance_code'
3469 ||' AND process_flag = '||G_IN_PROCESS
3470 ||' AND calendar_code = :calendar_code';
3471
3472 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
3473
3474 EXECUTE IMMEDIATE lv_sql_stmt
3475 USING p_message_text,
3476 p_transaction_id,
3477 v_instance_code,
3478 p_calendar_code;
3479
3480
3481 ELSIF p_table_name = 'MSC_ST_CALENDAR_EXCEPTIONS' THEN
3482
3483 v_sql_stmt := 4;
3484 lv_sql_stmt :=
3485 'UPDATE msc_st_calendar_exceptions'
3486 ||' set process_flag = '||G_ERROR_FLG||','
3487 ||' error_text = :p_message_text'
3488 ||' WHERE st_transaction_id = :p_transaction_id'
3489 ||' AND sr_instance_code = :instance_code'
3490 ||' AND process_flag = '||G_IN_PROCESS
3491 ||' AND calendar_code = :calendar_code';
3492
3493 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
3494
3495 EXECUTE IMMEDIATE lv_sql_stmt
3496 USING p_message_text,
3497 p_transaction_id,
3498 v_instance_code,
3499 p_calendar_code;
3500
3501 ELSIF p_table_name = 'MSC_ST_SHIFT_EXCEPTIONS' THEN
3502
3503 v_sql_stmt := 5;
3504 lv_sql_stmt :=
3505 'UPDATE msc_st_shift_exceptions'
3506 ||' set process_flag = '||G_ERROR_FLG||','
3507 ||' error_text = :p_message_text'
3508 ||' WHERE st_transaction_id = :p_transaction_id'
3509 ||' AND sr_instance_code = :instance_code'
3510 ||' AND process_flag = '||G_IN_PROCESS
3511 ||' AND calendar_code = :calendar_code';
3512
3513 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
3514
3515 EXECUTE IMMEDIATE lv_sql_stmt
3516 USING p_message_text,
3517 p_transaction_id,
3518 v_instance_code,
3519 p_calendar_code;
3520
3521 END IF;
3522
3523 IF p_table_name <> 'MSC_ST_CALENDARS' THEN
3524 v_sql_stmt := 6;
3525 lv_sql_stmt :=
3526 'UPDATE msc_st_calendars'
3527 ||' set process_flag = '||G_PROPAGATION
3528 ||' WHERE sr_instance_code = :instance_code'
3529 ||' AND process_flag = '||G_IN_PROCESS
3530 ||' AND calendar_code = :calendar_code';
3531
3532 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
3533
3534 EXECUTE IMMEDIATE lv_sql_stmt
3535 USING v_instance_code,
3536 p_calendar_code;
3537
3538 END IF;
3539
3540 v_sql_stmt := 7;
3541 lv_sql_stmt :=
3542 'UPDATE msc_st_workday_patterns'
3543 ||' set process_flag = '||G_PROPAGATION
3544 ||' WHERE sr_instance_code = :instance_code'
3545 ||' AND process_flag = '||G_IN_PROCESS
3546 ||' AND calendar_code = :calendar_code';
3547
3548 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
3549
3550 EXECUTE IMMEDIATE lv_sql_stmt
3551 USING v_instance_code,
3552 p_calendar_code;
3553
3554 v_sql_stmt := 8;
3555 lv_sql_stmt :=
3556 'UPDATE msc_st_calendar_shifts'
3557 ||' set process_flag = '||G_PROPAGATION
3558 ||' WHERE sr_instance_code = :instance_code'
3559 ||' AND process_flag = '||G_IN_PROCESS
3560 ||' AND calendar_code = :calendar_code';
3561
3562 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
3563
3564 EXECUTE IMMEDIATE lv_sql_stmt
3565 USING v_instance_code,
3566 p_calendar_code;
3567
3568 v_sql_stmt := 9;
3569 lv_sql_stmt :=
3570 'UPDATE msc_st_shift_times'
3571 ||' set process_flag = '||G_PROPAGATION
3572 ||' WHERE sr_instance_code = :instance_code'
3573 ||' AND process_flag = '||G_IN_PROCESS
3574 ||' AND calendar_code = :calendar_code';
3575
3576 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
3577
3578 EXECUTE IMMEDIATE lv_sql_stmt
3579 USING v_instance_code,
3580 p_calendar_code;
3581
3582
3583 v_sql_stmt := 10;
3584 lv_sql_stmt :=
3585 'UPDATE msc_st_calendar_exceptions'
3586 ||' set process_flag = '||G_PROPAGATION
3587 ||' WHERE sr_instance_code = :instance_code'
3588 ||' AND process_flag = '||G_IN_PROCESS
3589 ||' AND calendar_code = :calendar_code';
3590
3591 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
3592
3593 EXECUTE IMMEDIATE lv_sql_stmt
3594 USING v_instance_code,
3595 p_calendar_code;
3596
3597 v_sql_stmt := 11;
3598 lv_sql_stmt :=
3599 'UPDATE msc_st_shift_exceptions'
3600 ||' set process_flag = '||G_PROPAGATION
3601 ||' WHERE sr_instance_code = :instance_code'
3602 ||' AND process_flag = '||G_IN_PROCESS
3603 ||' AND calendar_code = :calendar_code';
3604
3605 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
3606
3607 EXECUTE IMMEDIATE lv_sql_stmt
3608 USING v_instance_code,
3609 p_calendar_code;
3610
3611
3612 lv_status := MSC_ST_UTIL.LOG_ERROR
3613 (p_table_name => p_table_name,
3614 p_instance_code => v_instance_code,
3615 p_row => p_column_names,
3616 p_severity => G_SEV_ERROR,
3617 p_message_text => NULL,
3618 p_error_text => p_error_text,
3619 p_debug => v_debug,
3620 p_propagated => 'Y');
3621
3622 RETURN(lv_status);
3623 EXCEPTION
3624 WHEN OTHERS THEN
3625 p_error_text := substr('MSC_CL_PRE_PROCESS.PROPAGATE_CAL_ERROR'
3626 ||'('||v_sql_stmt||')'|| SQLERRM, 1, 240);
3627 return(SQLCODE);
3628
3629 END PROPAGATE_CAL_ERROR;
3630
3631 /*==========================================================================+
3632 | DESCRIPTION : This function inserts a record into the LID table for the |
3633 | new shifts, derives the shift information from the |
3634 | workday pattern table and updates the shift_num in the |
3635 | tables msc_st_shift_exceptions and msc_st_shift_times |
3636 +==========================================================================*/
3637 FUNCTION derive_shift_details
3638 (p_transaction_id NUMBER,
3639 p_company_name VARCHAR2,
3640 p_calendar_code VARCHAR2,
3641 p_shift_name VARCHAR2,
3642 p_error_text OUT NOCOPY VARCHAR2,
3643 P_shift_num NUMBER DEFAULT NULL_VALUE,
3644 p_shift_exist NUMBER DEFAULT NULL_VALUE)
3645 RETURN NUMBER IS
3646 lv_sql_stmt VARCHAR2(5000);
3647 lv_shift_num msc_st_calendar_shifts.shift_num%TYPE;
3648
3649 BEGIN
3650 lv_shift_num := p_shift_num;
3651
3652 IF p_shift_exist = SYS_NO THEN
3653 v_sql_stmt := 2;
3654 lv_sql_stmt :=
3655 'INSERT INTO msc_local_id_setup'
3656 ||' (local_id, '
3657 ||' st_transaction_id,'
3658 ||' instance_id,'
3659 ||' entity_name,'
3660 ||' char1,'
3661 ||' char2,'
3662 ||' char3,'
3663 ||' char4,'
3664 ||' last_update_date,'
3665 ||' last_updated_by,'
3666 ||' creation_date,'
3667 ||' created_by)'
3668 ||' VALUES'
3669 ||' (:lv_shift_num,'
3670 ||' :p_transaction_id,'
3671 ||' :v_instance_id,'
3672 ||' ''SHIFT_NUM'','
3673 ||' :v_instance_code,'
3674 ||' :company_name,'
3675 ||' :p_calendar_code,'
3676 ||' :p_shift_name,'
3677 ||' :v_current_date,'
3678 ||' :v_current_user,'
3679 ||' :v_current_date,'
3680 ||' :v_current_user)';
3681
3682 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
3683 EXECUTE IMMEDIATE lv_sql_stmt
3684 USING lv_shift_num,
3685 p_transaction_id,
3686 v_instance_id,
3687 v_instance_code,
3688 p_company_name,
3689 p_calendar_code,
3690 p_shift_name,
3691 v_current_date,
3692 v_current_user,
3693 v_current_date,
3694 v_current_user;
3695 END IF;
3696
3697 v_sql_stmt := 3;
3698 lv_sql_stmt :=
3699 'UPDATE msc_st_workday_patterns'
3700 ||' SET shift_num = :lv_shift_num'
3701 ||' WHERE st_transaction_id = :p_transaction_id'
3702 ||' AND process_flag = '||G_IN_PROCESS
3703 ||' AND sr_instance_code = :v_instance_code';
3704
3705 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
3706 EXECUTE IMMEDIATE lv_sql_stmt
3707 USING lv_shift_num,
3708 p_transaction_id,
3709 v_instance_code;
3710
3711 v_sql_stmt := 4;
3712 lv_sql_stmt :=
3713 'UPDATE msc_st_shift_times '
3714 ||' SET shift_num = :lv_shift_num'
3715 ||' WHERE calendar_code = :p_calendar_code'
3716 ||' AND shift_name = :p_shift_name'
3717 ||' AND process_flag = '||G_IN_PROCESS
3718 ||' AND sr_instance_code = :v_instance_code';
3719
3720 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
3721 EXECUTE IMMEDIATE lv_sql_stmt
3722 USING lv_shift_num,
3723 p_calendar_code,
3724 p_shift_name,
3725 v_instance_code;
3726
3727 v_sql_stmt := 5;
3728 lv_sql_stmt :=
3729 'UPDATE msc_st_shift_exceptions '
3730 ||' SET shift_num = :lv_shift_num'
3731 ||' WHERE calendar_code = :p_calendar_code'
3732 ||' AND shift_name = :p_shift_name'
3733 ||' AND process_flag = '||G_IN_PROCESS
3734 ||' AND sr_instance_code = :v_instance_code';
3735
3736 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
3737 EXECUTE IMMEDIATE lv_sql_stmt
3738 USING lv_shift_num,
3739 p_calendar_code,
3740 p_shift_name,
3741 v_instance_code;
3742
3743 v_sql_stmt := 6;
3744 lv_sql_stmt :=
3745 'INSERT INTO msc_st_calendar_shifts '
3746 ||' (calendar_code,'
3747 ||' shift_name,'
3748 ||' shift_num,'
3749 ||' sr_instance_code,'
3750 ||' company_name,'
3751 ||' sr_instance_id,'
3752 ||' last_update_date,'
3753 ||' last_updated_by,'
3754 ||' creation_date,'
3755 ||' created_by,'
3756 ||' message_id,'
3757 ||' process_flag,'
3758 ||' data_source_type)'
3759 ||' SELECT'
3760 ||' calendar_code,'
3761 ||' shift_name,'
3762 ||' shift_num,'
3763 ||' :v_instance_code,'
3764 ||' company_name,'
3765 || 0||','
3766 ||' last_update_date,'
3767 ||' last_updated_by,'
3768 ||' creation_date,'
3769 ||' created_by,'
3770 ||' message_id,'
3771 ||' process_flag,'
3772 ||' data_source_type'
3773 ||' FROM msc_st_workday_patterns mwp'
3774 ||' WHERE st_transaction_id = :p_transaction_id'
3775 ||' AND process_flag = '||G_IN_PROCESS
3776 ||' AND sr_instance_code = :instance_code'
3777 ||' AND NOT EXISTS( SELECT 1 '
3778 ||' FROM MSC_ST_CALENDAR_SHIFTS mcs'
3779 ||' where mcs.calendar_code = mwp.calendar_code'
3780 ||' AND mcs.shift_name = mwp.shift_name'
3781 ||' AND mcs.shift_num = mwp.shift_num'
3782 ||' AND mcs.sr_instance_code = :v_instance_code'
3783 ||' AND NVL(mwp.company_name, '||''''||NULL_CHAR||''''||') = '
3784 ||' NVL(mcs.company_name, '||''''||NULL_CHAR||''''||'))';
3785
3786
3787
3788 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
3789 EXECUTE IMMEDIATE lv_sql_stmt
3790 USING v_instance_code,
3791 p_transaction_id,
3792 v_instance_code,
3793 v_instance_code;
3794 RETURN(0);
3795 EXCEPTION
3796 WHEN OTHERS THEN
3797 p_error_text := substr('MSC_CL_PRE_PROCESS.DERIVE_SHIFT_DETAILS'
3798 ||'('||v_sql_stmt||')'|| SQLERRM, 1, 240);
3799 return(SQLCODE);
3800
3801 END derive_shift_details;
3802
3803 /*==========================================================================+
3804 | DESCRIPTION : This procedure validates the summary information from the |
3805 | legacy systems, inserts/updates the validated information |
3806 | into the ODS tables and spawns the calendar build program |
3807 | which populates the calendar details into the ODS tables. |
3808 +==========================================================================*/
3809 PROCEDURE LOAD_CALENDAR IS
3810 lv_rec_no NUMBER;
3811 lv_return NUMBER;
3812 lv_request_id Number;
3813 lv_shift_num_gen NUMBER;
3814 lv_shift_dup NUMBER;
3815 lv_error_text VARCHAR2(250);
3816 lv_sql_stmt VARCHAR2(5000);
3817 lv_where_str VARCHAR2(5000);
3818 lv_table_name VARCHAR2(32);
3819 lv_column_names VARCHAR2(5000); --stores concatenated column names
3820
3821 lv_calendar_code msc_st_calendars.calendar_code%TYPE;
3822 lv_transaction_id msc_st_calendars.st_transaction_id%TYPE;
3823 lv_calendar_start_date msc_st_calendars.calendar_start_date%TYPE;
3824 lv_calendar_end_date msc_st_calendars.calendar_end_date%TYPE;
3825 lv_seq_num msc_st_workday_patterns.seq_num%TYPE := 0;
3826 lv_message_text msc_errors.error_text%TYPE;
3827 lv_shift_num msc_st_calendar_shifts.shift_num%TYPE;
3828
3829 ex_logging_err EXCEPTION;
3830 ex_critical_err EXCEPTION;
3831
3832 CURSOR c1 IS
3833 SELECT rowid,
3834 calendar_code,
3835 calendar_start_date,
3836 calendar_end_date,
3837 quarterly_calendar_type,
3838 week_start_day,
3839 overwrite_flag,
3840 deleted_flag
3841 FROM msc_st_calendars
3842 WHERE sr_instance_code = v_instance_code
3843 AND process_flag = G_IN_PROCESS;
3844
3845 CURSOR c2(p_calendar_code VARCHAR2) IS
3846 SELECT rowid,
3847 company_name,
3848 shift_name,
3849 seq_num,
3850 days_on,
3851 days_off,
3852 deleted_flag
3853 FROM msc_st_workday_patterns
3854 WHERE sr_instance_code = v_instance_code
3855 AND calendar_code = p_calendar_code
3856 AND process_flag = G_IN_PROCESS;
3857
3858 CURSOR c3(p_calendar_code VARCHAR2) IS
3859 SELECT rowid,
3860 shift_name,
3861 shift_num,
3862 from_time,
3863 to_time,
3864 deleted_flag
3865 FROM msc_st_shift_times
3866 WHERE sr_instance_code = v_instance_code
3867 AND calendar_code = p_calendar_code
3868 AND process_flag = G_IN_PROCESS;
3869
3870 CURSOR c4(p_calendar_code VARCHAR2) IS
3871 SELECT rowid,
3872 exception_date,
3873 exception_type,
3874 deleted_flag
3875 FROM msc_st_calendar_exceptions
3876 WHERE sr_instance_code = v_instance_code
3877 AND calendar_code = p_calendar_code
3878 AND process_flag = G_IN_PROCESS;
3879
3880 CURSOR c5(p_calendar_code VARCHAR2) IS
3881 SELECT rowid,
3882 shift_name,
3883 exception_date,
3884 exception_type,
3885 deleted_flag
3886 FROM msc_st_shift_exceptions
3887 WHERE sr_instance_code = v_instance_code
3888 AND calendar_code = p_calendar_code
3889 AND process_flag = G_IN_PROCESS;
3890
3891 BEGIN
3892 --Calendar summary information is processed calendar by calendar.
3893 v_cal_build := False;
3894
3895 --Added to fix the bug#2748859
3896 --Getting the error message text
3897 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
3898 (p_app_short_name => 'MSC',
3899 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
3900 p_message_text => lv_message_text,
3901 p_error_text => lv_error_text);
3902
3903 IF lv_return <> 0 THEN
3904 RAISE ex_logging_err;
3905 END IF;
3906
3907 --Duplicate records check for the records whose source is XML
3908
3909 UPDATE msc_st_calendars mc1
3910 SET process_flag = G_ERROR_FLG,
3911 error_text = lv_message_text
3912 WHERE message_id < (SELECT MAX(message_id)
3913 FROM msc_st_calendars mc2
3914 WHERE mc2.sr_instance_code = mc1.sr_instance_code
3915 AND mc2.calendar_code = mc1.calendar_code
3916 AND mc2.process_flag = G_IN_PROCESS
3917 AND NVL(mc2.message_id,NULL_VALUE) <>NULL_VALUE)
3918 AND mc1.process_flag = G_IN_PROCESS
3919 AND mc1.sr_instance_code = v_instance_code
3920 AND NVL(mc1.message_id,NULL_VALUE) <> NULL_VALUE;
3921
3922
3923 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
3924 (p_app_short_name => 'MSC',
3925 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
3926 p_message_text => lv_message_text,
3927 p_error_text => lv_error_text);
3928
3929 IF lv_return <> 0 THEN
3930 RAISE ex_logging_err;
3931 END IF;
3932
3933 --Duplicate records check for the records whose source is other than XML
3934 --Different SQL is used because in XML we can identify the latest records
3935 --whereas in batch load we cannot.
3936
3937 UPDATE msc_st_calendars mc1
3938 SET process_flag = G_ERROR_FLG,
3939 error_text = lv_message_text
3940 WHERE EXISTS( SELECT 1
3941 FROM msc_st_calendars mc2
3942 WHERE mc2.sr_instance_code = mc1.sr_instance_code
3943 AND mc2.calendar_code = mc1.calendar_code
3944 AND mc2.process_flag = G_IN_PROCESS
3945 AND NVL(mc2.message_id,NULL_VALUE) = NULL_VALUE
3946 GROUP BY sr_instance_code,company_name,calendar_code
3947 HAVING COUNT(*) > 1)
3948 AND mc1.process_flag = G_IN_PROCESS
3949 AND mc1.sr_instance_code = v_instance_code
3950 AND NVL(mc1.message_id,NULL_VALUE) = NULL_VALUE;
3951 --Added to fix the bug#2748859
3952
3953 FOR rec1 IN c1
3954 LOOP
3955 BEGIN
3956
3957 lv_calendar_code := rec1.calendar_code;--used for error propagation
3958 lv_table_name := 'MSC_ST_CALENDARS';--used for error propagation
3959
3960 lv_column_names :=
3961 'CALENDAR_CODE ||''~''||'
3962 ||'CALENDAR_START_DATE ||''~''||'
3963 ||'CALENDAR_END_DATE ||''~''||'
3964 ||'QUARTERLY_CALENDAR_TYPE||''~''||'
3965 ||'SR_INSTANCE_CODE ||''~''||'
3966 ||'DESCRIPTION ||''~''||'
3967 ||'WEEK_START_DAY ||''~''||'
3968 ||'OVERWRITE_FLAG ||''~''||'
3969 ||'COMPANY_NAME ||''~''||'
3970 ||'DAYS_ON ||''~''||'
3971 ||'DAYS_OFF ||''~''||'
3972 ||'DELETED_FLAG';
3973
3974 v_sql_stmt := 1;
3975 SELECT msc_st_calendars_s.NEXTVAL
3976 INTO lv_transaction_id
3977 FROM dual;
3978
3979 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,'Refresh ID: '||v_refresh_id);
3980
3981 --Update the transaction_id and the who columns
3982 v_sql_stmt := 2;
3983 lv_sql_stmt :=
3984 'UPDATE msc_st_calendars '
3985 ||' SET st_transaction_id = :lv_transaction_id,'
3986 ||' refresh_id = '||v_refresh_id ||','
3987 ||' last_update_date = :v_current_date,'
3988 ||' last_updated_by = :v_current_user,'
3989 ||' creation_date = :v_current_date,'
3990 ||' created_by = :v_current_user'
3991 ||' WHERE nvl(calendar_code, '||''''||NULL_CHAR||''''||') ='
3992 ||' nvl(:calendar_code,'||''''||NULL_CHAR||''''||') '
3993 ||' AND sr_instance_code = :v_instance_code';
3994
3995 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
3996
3997 EXECUTE IMMEDIATE lv_sql_stmt
3998 USING lv_transaction_id,
3999 v_current_date,
4000 v_current_user,
4001 v_current_date,
4002 v_current_user,
4003 rec1.calendar_code,
4004 v_instance_code;
4005
4006 IF (rec1.calendar_code IS NULL OR
4007 rec1.calendar_start_date IS NULL OR
4008 rec1.calendar_end_date IS NULL) THEN
4009
4010 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4011 (p_app_short_name => 'MSC',
4012 p_error_code => 'MSC_PP_COL_VAL_NULL',
4013 p_message_text => lv_message_text,
4014 p_error_text => lv_error_text,
4015 p_token1 => 'COLUMN_NAME',
4016 p_token_value1 => 'CALENDAR_CODE OR '
4017 ||'CALENDAR_START_DATE OR '
4018 ||'CALENDAR_END_DATE ');
4019
4020 IF lv_return <> 0 THEN
4021 RAISE ex_logging_err;
4022 END IF;
4023
4024 RAISE ex_critical_err;
4025
4026 ELSIF rec1.deleted_flag = SYS_YES THEN
4027
4028 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4029 (p_app_short_name => 'MSC',
4030 p_error_code => 'MSC_PP_NO_DELETION',
4031 p_message_text => lv_message_text,
4032 p_error_text => lv_error_text,
4033 p_token1 => 'TABLE_NAME',
4034 p_token_value1 => 'MSC_ST_CALENDARS');
4035
4036 IF lv_return <> 0 THEN
4037 RAISE ex_logging_err;
4038 END IF;
4039 RAISE ex_critical_err;
4040
4041 ELSIF (rec1.week_start_day NOT IN(1,2) OR
4042 rec1.quarterly_calendar_type NOT IN(1,2,3,4) OR
4043 NVL(rec1.overwrite_flag,'N') NOT IN('Y','N')) THEN
4044
4045 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4046 (p_app_short_name => 'MSC',
4047 p_error_code => 'MSC_PP_INVALID_VALUE',
4048 p_message_text => lv_message_text,
4049 p_error_text => lv_error_text,
4050 p_token1 => 'COLUMN_NAME',
4051 p_token_value1 => 'WEEK_START_DAY OR'
4052 ||' QUARTERLY_CALENDAR_TYPE OR'
4053 ||' OVERWRITE_FLAG');
4054
4055 IF lv_return <> 0 THEN
4056 RAISE ex_logging_err;
4057 END IF;
4058 RAISE ex_critical_err;
4059
4060 ELSIF rec1.calendar_end_date <= rec1.calendar_start_date THEN
4061
4062 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4063 (p_app_short_name => 'MSC',
4064 p_error_code => 'MSC_PP_END_GT_ST_DATE',
4065 p_message_text => lv_message_text,
4066 p_error_text => lv_error_text);
4067
4068 IF lv_return <> 0 THEN
4069 RAISE ex_logging_err;
4070 END IF;
4071 RAISE ex_critical_err;
4072
4073 END IF;
4074
4075 --Calendar is a global entity. Hence checking for the similar calendar
4076 --existence in other instances. Check is done in msc_calendar_dates
4077 --because 'ERP collections' does'nt collect the calendar header informations
4078 --like msc_Calendars, msc_workday_patterns etc.,
4079 v_sql_stmt := 2; /*Bug 2424200*/
4080 lv_sql_stmt :=
4081 'SELECT count(*)'
4082 ||' FROM msc_calendar_dates'
4083 ||' WHERE calendar_code = :calendar_code'
4084 ||' AND sr_instance_id <> :instance_id';
4085
4086
4087 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
4088 EXECUTE IMMEDIATE lv_sql_stmt
4089 INTO lv_rec_no
4090 USING rec1.calendar_code,
4091 v_instance_id;
4092
4093 IF lv_rec_no > 0 THEN
4094
4095 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4096 (p_app_short_name => 'MSC',
4097 p_error_code => 'MSC_PP_CAL_ALREADY_EXISTS',
4098 p_message_text => lv_message_text,
4099 p_error_text => lv_error_text);
4100
4101 IF lv_return <> 0 THEN
4102 RAISE ex_logging_err;
4103 END IF;
4104 RAISE ex_critical_err;
4105 END IF;
4106
4107 --If the overwrite_flag is 'N' and the calendar is already existing
4108 --in the ODS table then the calendar will be errored out and also if
4109 --if the overwrite_flag is 'Y' and if the calendar does'nt exist
4110 --in the ODS table then the calendar will be errored out. And also, if
4111 --all the existing shifts(in ODS) is not provided, then the calendar
4112 --will be errored out.
4113 BEGIN
4114 v_sql_stmt := 3; /*Bug 2172537*/
4115 lv_sql_stmt :=
4116 'SELECT calendar_start_date,'
4117 ||' calendar_end_date'
4118 ||' FROM msc_calendars'
4119 ||' WHERE calendar_code = :calendar_code'
4120 ||' AND sr_instance_id = :instance_id'
4121 ||' FOR UPDATE NOWAIT';
4122
4123 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
4124 EXECUTE IMMEDIATE lv_sql_stmt
4125 INTO lv_calendar_start_date,
4126 lv_calendar_end_date
4127 USING rec1.calendar_code,
4128 v_instance_id;
4129
4130 IF NVL(rec1.overwrite_flag,'N') = 'N' THEN
4131
4132 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4133 (p_app_short_name => 'MSC',
4134 p_error_code => 'MSC_PP_CAL_ALREADY_EXISTS',
4135 p_message_text => lv_message_text,
4136 p_error_text => lv_error_text);
4137
4138 IF lv_return <> 0 THEN
4139 RAISE ex_logging_err;
4140 END IF;
4141 RAISE ex_critical_err;
4142
4143 ELSIF NVL(rec1.overwrite_flag,'N') = 'Y' AND
4144 (rec1.calendar_start_date > lv_calendar_start_date OR
4145 rec1.calendar_end_date < lv_calendar_end_date) THEN
4146
4147 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4148 (p_app_short_name => 'MSC',
4149 p_error_code => 'MSC_PP_CAL_PERIOD_INVALID',
4150 p_message_text => lv_message_text,
4151 p_error_text => lv_error_text);
4152
4153 IF lv_return <> 0 THEN
4154 RAISE ex_logging_err;
4155 END IF;
4156 RAISE ex_critical_err;
4157
4158 END IF;
4159
4160 EXCEPTION
4161 WHEN no_data_found THEN
4162 IF NVL(rec1.overwrite_flag,'N') = 'Y' THEN
4163
4164 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4165 (p_app_short_name => 'MSC',
4166 p_error_code => 'MSC_PP_CAL_UPDATE_NOT_ALLOWED',
4167 p_message_text => lv_message_text,
4168 p_error_text => lv_error_text);
4169
4170 IF lv_return <> 0 THEN
4171 RAISE ex_logging_err;
4172 END IF;
4173 RAISE ex_critical_err;
4174 END IF;
4175 END;
4176
4177 IF NVL(rec1.overwrite_flag,'N') = 'Y' THEN
4178 BEGIN
4179 v_sql_stmt := 4; /*Bug 2172537*/
4180 lv_sql_stmt :=
4181 'SELECT 1'
4182 ||' FROM msc_calendar_shifts mcs, msc_apps_instances mai '
4183 ||' WHERE NOT EXISTS(SELECT 1 '
4184 ||' FROM msc_st_workday_patterns mwp '
4185 ||' WHERE mwp.shift_name = mcs.shift_name'
4186 ||' AND mcs.calendar_code = mwp.calendar_code'
4187 ||' AND mwp.sr_instance_code = mai.instance_code'
4188 ||' AND mwp.process_flag = '||G_IN_PROCESS||')'
4189 ||' AND calendar_code = :calendar_code'
4190 ||' AND mai.instance_code = :instance_code'
4191 ||' AND mcs.sr_instance_id = mai.instance_id'
4192 ||' FOR UPDATE NOWAIT';
4193
4194 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
4195 EXECUTE IMMEDIATE lv_sql_stmt
4196 INTO lv_rec_no
4197 USING rec1.calendar_code,
4198 v_instance_code;
4199
4200 IF lv_rec_no =1 THEN
4201
4202 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4203 (p_app_short_name => 'MSC',
4204 p_error_code => 'MSC_PP_SHIFT_NOT_EXIST',
4205 p_message_text => lv_message_text,
4206 p_error_text => lv_error_text);
4207
4208 IF lv_return <> 0 THEN
4209 RAISE ex_logging_err;
4210 END IF;
4211 RAISE ex_critical_err;
4212 END IF;
4213 EXCEPTION
4214 WHEN no_data_found THEN
4215 NULL;
4216
4217 WHEN too_many_rows THEN
4218 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4219 (p_app_short_name => 'MSC',
4220 p_error_code => 'MSC_PP_SHIFT_NOT_EXIST',
4221 p_message_text => lv_message_text,
4222 p_error_text => lv_error_text);
4223
4224 IF lv_return <> 0 THEN
4225 RAISE ex_logging_err;
4226 END IF;
4227 RAISE ex_critical_err;
4228 END;
4229 END IF;
4230
4231 v_sql_stmt := 7;
4232 lv_sql_stmt :=
4233 'SELECT nvl(SUM(nvl(days_on,0) + nvl(days_off,0)),0)'
4234 ||' FROM msc_st_workday_patterns'
4235 ||' WHERE calendar_code = :calendar_code'
4236 ||' AND NVL(shift_name,'||''''||NULL_CHAR||''''||')'
4237 ||' = '||''''||NULL_CHAR||''''
4238 ||' AND deleted_flag <> '||SYS_YES
4239 ||' AND process_flag = '||G_IN_PROCESS
4240 ||' AND sr_instance_code = :instance_code';
4241
4242 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
4243 EXECUTE IMMEDIATE lv_sql_stmt
4244 INTO lv_rec_no
4245 USING rec1.calendar_code,
4246 v_instance_code;
4247
4248 IF lv_rec_no <= 0 THEN
4249 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4250 (p_app_short_name => 'MSC',
4251 p_error_code => 'MSC_PP_WORKDAY_PAT_INVALID',
4252 p_message_text => lv_message_text,
4253 p_error_text => lv_error_text);
4254
4255 IF lv_return <> 0 THEN
4256 RAISE ex_logging_err;
4257 END IF;
4258
4259 RAISE ex_critical_err;
4260 END IF;
4261
4262 --Call to customised validation.
4263 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
4264 (ERRBUF => lv_error_text,
4265 RETCODE => lv_return,
4266 pBatchID => null,
4267 pInstanceCode => v_instance_code,
4268 pEntityName => 'MSC_ST_CALENDARS',
4269 pInstanceID => v_instance_id);
4270
4271 IF lv_return <> 0 THEN
4272 RAISE ex_logging_err;
4273 END IF;
4274
4275 IF rec1.deleted_flag NOT IN(1,2) THEN
4276 lv_where_str := ' AND calendar_code = '||''''||rec1.calendar_code||''''
4277 ||' AND sr_instance_code = '||''''||v_instance_code ||'''';
4278
4279 --Logging a warning for those records where the deleted_flag value
4280 --is other than Yes/No.
4281 lv_return := MSC_ST_UTIL.LOG_ERROR
4282 (p_table_name => 'MSC_ST_CALENDARS',
4283 p_instance_code => v_instance_code,
4284 p_row => lv_column_names,
4285 p_severity => G_SEV_WARNING,
4286 p_message_text => lv_message_text,
4287 p_error_text => lv_error_text,
4288 p_where_str => lv_where_str,
4289 p_col_name => 'DELETED_FLAG',
4290 p_debug => v_debug,
4291 p_default_value => SYS_NO);
4292
4293 IF lv_return <> 0 THEN
4294 RAISE ex_logging_err;
4295 END IF;
4296 END IF;
4297
4298 SELECT MIN(to_number(decode(length(rtrim(shift_name,'0123456789')),
4299 NULL,shift_name,'0')))
4300 INTO lv_shift_num_gen
4301 FROM msc_st_workday_patterns
4302 WHERE sr_instance_code = v_instance_code
4303 AND calendar_code = rec1.calendar_code
4304 AND process_flag = G_IN_PROCESS
4305 AND shift_name IS NOT NULL;
4306
4307 --Workday Pattern is validated for a calendar.
4308 FOR rec2 IN c2(rec1.calendar_code)
4309 LOOP
4310 lv_table_name := 'MSC_ST_WORKDAY_PATTERNS';
4311 lv_seq_num := lv_seq_num + 1;
4312
4313 lv_column_names :=
4314 'CALENDAR_CODE ||''~''||'
4315 ||'DAYS_ON ||''~''||'
4316 ||'DAYS_OFF ||''~''||'
4317 ||'SR_INSTANCE_CODE ||''~''||'
4318 ||'SHIFT_NUM ||''~''||'
4319 ||'SHIFT_NAME ||''~''||'
4320 ||'DESCRIPTION ||''~''||'
4321 ||'COMPANY_NAME ||''~''||'
4322 ||'DELETED_FLAG';
4323
4324 v_sql_stmt := 8;
4325 SELECT msc_st_workday_patterns_s.NEXTVAL
4326 INTO lv_transaction_id
4327 FROM dual;
4328
4329 v_sql_stmt := 9;
4330 UPDATE msc_st_workday_patterns
4331 SET st_transaction_id = lv_transaction_id,
4332 refresh_id = v_refresh_id,
4333 seq_num = lv_seq_num,
4334 last_update_date = v_current_date,
4335 last_updated_by = v_current_user,
4336 creation_date = v_current_date,
4337 created_by = v_current_user
4338 WHERE rowid = rec2.rowid;
4339
4340 IF rec2.deleted_flag = SYS_YES THEN
4341
4342 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4343 (p_app_short_name => 'MSC',
4344 p_error_code => 'MSC_PP_NO_DELETION',
4345 p_message_text => lv_message_text,
4346 p_error_text => lv_error_text,
4347 p_token1 => 'TABLE_NAME',
4348 p_token_value1 => 'MSC_ST_WORKDAY_PATTERNS');
4349
4350 IF lv_return <> 0 THEN
4351 RAISE ex_logging_err;
4352 END IF;
4353 RAISE ex_critical_err;
4354
4355 ELSIF (rec2.days_on < 0 OR
4356 rec2.days_off < 0) THEN
4357
4358 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4359 (p_app_short_name => 'MSC',
4360 p_error_code => 'MSC_PP_CONV_RT_NEG',
4361 p_message_text => lv_message_text,
4362 p_error_text => lv_error_text,
4363 p_token1 => 'COLUMN_NAME',
4364 p_token_value1 => 'DAYS_ON AND DAYS_OFF');
4365
4366 IF lv_return <> 0 THEN
4367 RAISE ex_logging_err;
4368 END IF;
4369 RAISE ex_critical_err;
4370
4371 END IF;
4372
4373 IF rec2.deleted_flag NOT IN(1,2) THEN
4374
4375 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4376 (p_app_short_name => 'MSC',
4377 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
4378 p_message_text => lv_message_text,
4379 p_error_text => lv_error_text,
4380 p_token1 => 'COLUMN_NAME',
4381 p_token_value1 => 'DELETED_FLAG',
4382 p_token2 => 'DEFAULT_VALUE',
4383 p_token_value2 => SYS_NO);
4384
4385 lv_where_str := ' AND st_transaction_id = '||lv_transaction_id;
4386
4387 --Logging a warning for those records where the deleted_flag value
4388 --is other than Yes/No.
4389 lv_return := MSC_ST_UTIL.LOG_ERROR
4390 (p_table_name => 'MSC_ST_WORKDAY_PATTERNS',
4391 p_instance_code => v_instance_code,
4392 p_row => lv_column_names,
4393 p_severity => G_SEV_WARNING,
4394 p_message_text => lv_message_text,
4395 p_error_text => lv_error_text,
4396 p_where_str => lv_where_str,
4397 p_col_name => 'DELETED_FLAG',
4398 p_debug => v_debug,
4399 p_default_value => SYS_NO);
4400
4401 IF lv_return <> 0 THEN
4402 RAISE ex_logging_err;
4403 END IF;
4404 END IF;
4405
4406 --Call to customised validation.
4407 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
4408 (ERRBUF => lv_error_text,
4409 RETCODE => lv_return,
4410 pBatchID => null,
4411 pInstanceCode => v_instance_code,
4412 pEntityName => 'MSC_ST_WORKDAY_PATTERNS',
4413 pInstanceID => v_instance_id);
4414
4415 IF lv_return <> 0 THEN
4416 RAISE ex_logging_err;
4417 END IF;
4418
4419 --If the workday pattern definition is for the shifts, then the
4420 --shift details are derived here.
4421 IF rec2.shift_name IS NOT NULL THEN
4422
4423 BEGIN
4424 v_sql_stmt := 12;
4425 lv_sql_stmt :=
4426 'SELECT local_id '
4427 ||' FROM msc_local_id_setup'
4428 ||' WHERE char1 = :v_instance_code'
4429 ||' AND NVL(char2, '||''''||NULL_CHAR||''''||') = '
4430 ||' NVL(:company_name,'||''''||NULL_CHAR||''''||') '
4431 ||' AND char3 = :calendar_code'
4432 ||' AND char4 = :shift_name'
4433 ||' AND entity_name = ''SHIFT_NUM'' ';
4434
4435 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
4436 EXECUTE IMMEDIATE lv_sql_stmt
4437 INTO lv_shift_num
4438 USING v_instance_code,
4439 rec2.company_name,
4440 rec1.calendar_code,
4441 rec2.shift_name;
4442
4443 lv_return := derive_shift_details
4444 (p_transaction_id => lv_transaction_id,
4445 p_company_name => rec2.company_name,
4446 p_calendar_code => rec1.calendar_code,
4447 p_shift_name => rec2.shift_name,
4448 p_error_text => lv_error_text,
4449 p_shift_num => lv_shift_num,
4450 p_shift_exist => SYS_YES);
4451
4452 IF lv_return <> 0 THEN
4453 RAISE ex_logging_err;
4454 END IF;
4455
4456 EXCEPTION
4457 WHEN no_data_found THEN
4458
4459 IF lv_shift_num_gen > 0 THEN
4460 lv_shift_num := rec2.shift_name;
4461 ELSE
4462 SELECT msc_st_shift_num_s.NEXTVAL
4463 INTO lv_shift_num
4464 FROM dual;
4465 END IF;
4466
4467 lv_return := derive_shift_details
4468 (p_transaction_id => lv_transaction_id,
4469 p_company_name => rec2.company_name,
4470 p_calendar_code => rec1.calendar_code,
4471 p_shift_name => rec2.shift_name,
4472 p_error_text => lv_error_text,
4473 p_shift_num => lv_shift_num,
4474 p_shift_exist => SYS_NO);
4475
4476 IF lv_return <> 0 THEN
4477 RAISE ex_logging_err;
4478 END IF;
4479 END;
4480 END IF;
4481
4482 END LOOP;
4483
4484 --Validation for shift times table.
4485 FOR rec3 IN c3(rec1.calendar_code)
4486 LOOP
4487 lv_table_name := 'MSC_ST_SHIFT_TIMES';
4488 lv_column_names :=
4489 'CALENDAR_CODE ||''~''||'
4490 ||'SHIFT_NAME ||''~''||'
4491 ||'SHIFT_NUM ||''~''||'
4492 ||'SR_INSTANCE_CODE ||''~''||'
4493 ||'FROM_TIME ||''~''||'
4494 ||'TO_TIME ||''~''||'
4495 ||'COMPANY_NAME ||''~''||'
4496 ||'DELETED_FLAG';
4497
4498 v_sql_stmt := 13;
4499 SELECT msc_st_shift_times_s.NEXTVAL
4500 INTO lv_transaction_id
4501 FROM dual;
4502
4503 v_sql_stmt := 14;
4504 UPDATE msc_st_shift_times
4505 SET st_transaction_id = lv_transaction_id,
4506 refresh_id = v_refresh_id,
4507 last_update_date = v_current_date,
4508 last_updated_by = v_current_user,
4509 creation_date = v_current_date,
4510 created_by = v_current_user
4511 WHERE rowid = rec3.rowid;
4512
4513 IF (rec3.shift_name IS NULL OR
4514 rec3.shift_num IS NULL) THEN
4515
4516 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4517 (p_app_short_name => 'MSC',
4518 p_error_code => 'MSC_PP_COL_VAL_NULL',
4519 p_message_text => lv_message_text,
4520 p_error_text => lv_error_text,
4521 p_token1 => 'COLUMN_NAME',
4522 p_token_value1 => 'SHIFT_NAME OR SHIFT_NUM ');
4523 RAISE ex_critical_err;
4524
4525 ELSIF rec3.deleted_flag = SYS_YES THEN
4526
4527 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4528 (p_app_short_name => 'MSC',
4529 p_error_code => 'MSC_PP_NO_DELETION',
4530 p_message_text => lv_message_text,
4531 p_error_text => lv_error_text,
4532 p_token1 => 'TABLE_NAME',
4533 p_token_value1 => lv_table_name);
4534
4535 IF lv_return <> 0 THEN
4536 RAISE ex_logging_err;
4537 END IF;
4538 RAISE ex_critical_err;
4539
4540 END IF;
4541
4542 IF rec3.deleted_flag NOT IN(1,2) THEN
4543 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4544 (p_app_short_name => 'MSC',
4545 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
4546 p_message_text => lv_message_text,
4547 p_error_text => lv_error_text,
4548 p_token1 => 'COLUMN_NAME',
4549 p_token_value1 => 'DELETED_FLAG',
4550 p_token2 => 'DEFAULT_VALUE',
4551 p_token_value2 => SYS_NO);
4552
4553 lv_where_str := ' AND st_transaction_id = '||lv_transaction_id;
4554
4555 --Logging a warning for those records where the deleted_flag value
4556 --is other than Yes/No.
4557 lv_return := MSC_ST_UTIL.LOG_ERROR
4558 (p_table_name => 'MSC_ST_SHIFT_TIMES',
4559 p_instance_code => v_instance_code,
4560 p_row => lv_column_names,
4561 p_severity => G_SEV_WARNING,
4562 p_message_text => lv_message_text,
4563 p_error_text => lv_error_text,
4564 p_where_str => lv_where_str,
4565 p_col_name => 'DELETED_FLAG',
4566 p_debug => v_debug,
4567 p_default_value => SYS_NO);
4568
4569 IF lv_return <> 0 THEN
4570 RAISE ex_logging_err;
4571 END IF;
4572 END IF;
4573
4574 BEGIN
4575 v_sql_stmt := 17; /*Bug 2172537-Modified the satement*/
4576 lv_sql_stmt :=
4577 'SELECT 1'
4578 ||' FROM DUAL'
4579 ||' WHERE NOT EXISTS(SELECT 1'
4580 ||' FROM msc_st_shift_times'
4581 ||' WHERE sr_instance_code = :sr_instance_code'
4582 ||' AND process_flag = '||G_IN_PROCESS
4583 ||' AND deleted_flag = '||SYS_NO
4584 ||' AND calendar_code = :calendar_code'
4585 ||' AND shift_name = :shift_name'
4586 ||' AND from_time = :from_time'
4587 ||' AND to_time = :to_time'
4588 ||' AND st_transaction_id <> :lv_transaction_id'
4589 ||' UNION'
4590 ||' SELECT 1'
4591 ||' FROM msc_st_shift_times'
4592 ||' WHERE sr_instance_code = :sr_instance_code'
4593 ||' AND process_flag = '||G_IN_PROCESS
4594 ||' AND deleted_flag = '||SYS_NO
4595 ||' AND calendar_code = :calendar_code'
4596 ||' AND shift_name = :shift_name'
4597 ||' AND from_time > :from_time'
4598 ||' AND from_time < :to_time'
4599 ||' AND st_transaction_id <> :lv_transaction_id'
4600 ||' UNION'
4601 ||' SELECT 1'
4602 ||' FROM msc_st_shift_times'
4603 ||' WHERE sr_instance_code = :sr_instance_code'
4604 ||' AND process_flag = '||G_IN_PROCESS
4605 ||' AND deleted_flag = '||SYS_NO
4606 ||' AND calendar_code = :calendar_code'
4607 ||' AND shift_name = :shift_name'
4608 ||' AND to_time > :from_time'
4609 ||' AND to_time < :to_time'
4610 ||' AND st_transaction_id <> :lv_transaction_id)';
4611
4612 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
4613 EXECUTE IMMEDIATE lv_sql_stmt
4614 INTO lv_rec_no
4615 USING v_instance_code,
4616 rec1.calendar_code,
4617 rec3.shift_name,
4618 rec3.from_time,
4619 rec3.to_time,
4620 lv_transaction_id,
4621 v_instance_code,
4622 rec1.calendar_code,
4623 rec3.shift_name,
4624 rec3.from_time,
4625 rec3.to_time,
4626 lv_transaction_id,
4627 v_instance_code,
4628 rec1.calendar_code,
4629 rec3.shift_name,
4630 rec3.from_time,
4631 rec3.to_time,
4632 lv_transaction_id;
4633
4634 EXCEPTION
4635 WHEN NO_DATA_FOUND THEN
4636 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4637 (p_app_short_name => 'MSC',
4638 p_error_code => 'MSC_PP_SHIFT_TIME_OVERLAP',
4639 p_message_text => lv_message_text,
4640 p_error_text => lv_error_text);
4641
4642 IF lv_return <> 0 THEN
4643 RAISE ex_logging_err;
4644 END IF;
4645 RAISE ex_critical_err;
4646 END;
4647
4648 --Call to customised validation.
4649 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
4650 (ERRBUF => lv_error_text,
4651 RETCODE => lv_return,
4652 pBatchID => null,
4653 pInstanceCode => v_instance_code,
4654 pEntityName => 'MSC_ST_SHIFT_TIMES',
4655 pInstanceID => v_instance_id);
4656
4657 IF lv_return <> 0 THEN
4658 RAISE ex_logging_err;
4659 END IF;
4660
4661 END LOOP;
4662
4663 --validation for the table msc_st_Calendar_exceptions.
4664 --Added to fix the bug#2748859
4665
4666 --Getting the error message text
4667 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4668 (p_app_short_name => 'MSC',
4669 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
4670 p_message_text => lv_message_text,
4671 p_error_text => lv_error_text);
4672
4673 IF lv_return <> 0 THEN
4674 RAISE ex_logging_err;
4675 END IF;
4676
4677 --Duplicate records check for the records whose source is XML
4678
4679 UPDATE msc_st_calendar_exceptions mc1
4680 SET process_flag = G_ERROR_FLG,
4681 error_text = lv_message_text
4682 WHERE message_id < (SELECT MAX(message_id)
4683 FROM msc_st_calendar_exceptions mc2
4684 WHERE mc2.sr_instance_code = mc1.sr_instance_code
4685 AND mc2.calendar_code = mc1.calendar_code
4686 AND mc2.exception_date = mc1.exception_date
4687 AND mc2.process_flag = G_IN_PROCESS
4688 AND NVL(mc2.message_id,NULL_VALUE) <>NULL_VALUE)
4689 AND mc1.calendar_code = rec1.calendar_code
4690 AND mc1.process_flag = G_IN_PROCESS
4691 AND mc1.sr_instance_code = v_instance_code
4692 AND NVL(mc1.message_id,NULL_VALUE) <> NULL_VALUE;
4693
4694
4695 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4696 (p_app_short_name => 'MSC',
4697 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
4698 p_message_text => lv_message_text,
4699 p_error_text => lv_error_text);
4700
4701 IF lv_return <> 0 THEN
4702 RAISE ex_logging_err;
4703 END IF;
4704
4705 --Duplicate records check for the records whose source is other than XML
4706 --Different SQL is used because in XML we can identify the latest records
4707 --whereas in batch load we cannot.
4708
4709 UPDATE msc_st_calendar_exceptions mc1
4710 SET process_flag = G_ERROR_FLG,
4711 error_text = lv_message_text
4712 WHERE EXISTS( SELECT 1
4713 FROM msc_st_calendar_exceptions mc2
4714 WHERE mc2.sr_instance_code = mc1.sr_instance_code
4715 AND mc2.calendar_code = mc1.calendar_code
4716 AND mc2.exception_date = mc1.exception_date
4717 AND mc2.process_flag = G_IN_PROCESS
4718 AND NVL(mc2.message_id,NULL_VALUE) = NULL_VALUE
4719 GROUP BY sr_instance_code,company_name,calendar_code,exception_date
4720 HAVING COUNT(*) > 1)
4721 AND mc1.calendar_code = rec1.calendar_code
4722 AND mc1.process_flag = G_IN_PROCESS
4723 AND mc1.sr_instance_code = v_instance_code
4724 AND NVL(mc1.message_id,NULL_VALUE) = NULL_VALUE;
4725
4726 --Added to fix the bug#2748859
4727
4728 FOR rec4 IN c4(rec1.calendar_code)
4729 LOOP
4730 lv_table_name := 'MSC_ST_CALENDAR_EXCEPTIONS';
4731 lv_column_names :=
4732 'CALENDAR_CODE ||''~''||'
4733 ||'EXCEPTION_DATE ||''~''||'
4734 ||'EXCEPTION_TYPE ||''~''||'
4735 ||'SR_INSTANCE_CODE ||''~''||'
4736 ||'COMPANY_NAME ||''~''||'
4737 ||'EXCEPTION_SET_ID ||''~''||'
4738 ||'DELETED_FLAG';
4739
4740 v_sql_stmt := 18;
4741 SELECT msc_st_calendar_exceptions_s.NEXTVAL
4742 INTO lv_transaction_id
4743 FROM dual;
4744
4745 v_sql_stmt := 19;
4746 UPDATE msc_st_calendar_exceptions
4747 SET st_transaction_id = lv_transaction_id,
4748 refresh_id = v_refresh_id,
4749 exception_set_id = -1,
4750 last_update_date = v_current_date,
4751 last_updated_by = v_current_user,
4752 creation_date = v_current_date,
4753 created_by = v_current_user
4754 WHERE rowid = rec4.rowid;
4755
4756 IF rec4.deleted_flag = SYS_YES THEN
4757 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4758 (p_app_short_name => 'MSC',
4759 p_error_code => 'MSC_PP_NO_DELETION',
4760 p_message_text => lv_message_text,
4761 p_error_text => lv_error_text,
4762 p_token1 => 'TABLE_NAME',
4763 p_token_value1 => lv_table_name);
4764
4765 IF lv_return <> 0 THEN
4766 RAISE ex_logging_err;
4767 END IF;
4768 RAISE ex_critical_err;
4769
4770 ELSIF rec4.exception_date IS NULL THEN
4771
4772 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4773 (p_app_short_name => 'MSC',
4774 p_error_code => 'MSC_PP_COL_VAL_NULL',
4775 p_message_text => lv_message_text,
4776 p_error_text => lv_error_text,
4777 p_token1 => 'COLUMN_NAME',
4778 p_token_value1 => 'EXCEPTION_DATE ');
4779
4780 IF lv_return <> 0 THEN
4781 RAISE ex_logging_err;
4782 END IF;
4783 RAISE ex_critical_err;
4784
4785 ELSIF (rec4.exception_date < rec1.calendar_start_date OR
4786 rec4.exception_date > rec1.calendar_end_date) THEN
4787 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4788 (p_app_short_name => 'MSC',
4789 p_error_code => 'MSC_PP_EXCEP_DATE_INVALID',
4790 p_message_text => lv_message_text,
4791 p_error_text => lv_error_text);
4792
4793 IF lv_return <> 0 THEN
4794 RAISE ex_logging_err;
4795 END IF;
4796 RAISE ex_critical_err;
4797
4798 ELSIF rec4.exception_type NOT IN(1,2) THEN
4799 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4800 (p_app_short_name => 'MSC',
4801 p_error_code => 'MSC_PP_INVALID_VALUE',
4802 p_message_text => lv_message_text,
4803 p_error_text => lv_error_text,
4804 p_token1 => 'COLUMN_NAME',
4805 p_token_value1 => 'EXCEPTION_TYPE');
4806
4807 IF lv_return <> 0 THEN
4808 RAISE ex_logging_err;
4809 END IF;
4810 RAISE ex_critical_err;
4811 END IF;
4812
4813 IF v_instance_type = G_SCE then
4814 v_sql_stmt := 20;
4815 lv_sql_stmt :=
4816 ' UPDATE msc_st_calendar_exceptions mc'
4817 ||' SET company_id = (SELECT party_id '
4818 ||' FROM hz_parties hp'
4819 ||' WHERE hp.party_name = mc.company_name)'
4820 ||' WHERE st_transaction_id = :lv_transaction_id';
4821
4822 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
4823 EXECUTE IMMEDIATE lv_sql_stmt
4824 USING lv_transaction_id;
4825
4826 IF SQL%NOTFOUND THEN
4827 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4828 (p_app_short_name => 'MSC',
4829 p_error_code => 'MSC_PP_INVALID_VALUE',
4830 p_message_text => lv_message_text,
4831 p_error_text => lv_error_text,
4832 p_token1 => 'COLUMN_NAME',
4833 p_token_value1 => 'COMPANY_NAME');
4834
4835 IF lv_return <> 0 THEN
4836 RAISE ex_logging_err;
4837 END IF;
4838 RAISE ex_critical_err;
4839 END IF;
4840 ELSE
4841 v_sql_stmt := 21;
4842 lv_sql_stmt :=
4843 ' UPDATE msc_st_calendar_exceptions '
4844 ||' SET company_id = '||G_COMPANY_ID
4845 ||' WHERE st_transaction_id = :lv_transaction_id';
4846
4847 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
4848 EXECUTE IMMEDIATE lv_sql_stmt
4849 USING lv_transaction_id;
4850
4851 END IF;
4852
4853 IF rec4.deleted_flag NOT IN(1,2) THEN
4854 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4855 (p_app_short_name => 'MSC',
4856 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
4857 p_message_text => lv_message_text,
4858 p_error_text => lv_error_text,
4859 p_token1 => 'COLUMN_NAME',
4860 p_token_value1 => 'DELETED_FLAG',
4861 p_token2 => 'DEFAULT_VALUE',
4862 p_token_value2 => SYS_NO);
4863
4864 lv_where_str := ' AND st_transaction_id = '||lv_transaction_id;
4865
4866 --Logging a warning for those records where the deleted_flag value
4867 --is other than Yes/No.
4868 lv_return := MSC_ST_UTIL.LOG_ERROR
4869 (p_table_name => 'MSC_ST_CALENDAR_EXCEPTIONS',
4870 p_instance_code => v_instance_code,
4871 p_row => lv_column_names,
4872 p_severity => G_SEV_WARNING,
4873 p_message_text => lv_message_text,
4874 p_error_text => lv_error_text,
4875 p_where_str => lv_where_str,
4876 p_col_name => 'DELETED_FLAG',
4877 p_debug => v_debug,
4878 p_default_value => SYS_NO);
4879
4880 IF lv_return <> 0 THEN
4881 RAISE ex_logging_err;
4882 END IF;
4883 END IF;
4884
4885 --Call to customised validation.
4886 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
4887 (ERRBUF => lv_error_text,
4888 RETCODE => lv_return,
4889 pBatchID => null,
4890 pInstanceCode => v_instance_code,
4891 pEntityName => 'MSC_ST_CALENDAR_EXCEPTIONS',
4892 pInstanceID => v_instance_id);
4893
4894 IF lv_return <> 0 THEN
4895 RAISE ex_logging_err;
4896 END IF;
4897
4898 END LOOP;
4899
4900 --validation for the table msc_st_shift_exceptions.
4901 --Added to fix the bug#2748859
4902
4903 --Getting the error message text
4904 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4905 (p_app_short_name => 'MSC',
4906 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
4907 p_message_text => lv_message_text,
4908 p_error_text => lv_error_text);
4909
4910 IF lv_return <> 0 THEN
4911 RAISE ex_logging_err;
4912 END IF;
4913
4914 --Duplicate records check for the records whose source is XML
4915
4916 UPDATE msc_st_shift_exceptions mc1
4917 SET process_flag = G_ERROR_FLG,
4918 error_text = lv_message_text
4919 WHERE message_id < (SELECT MAX(message_id)
4920 FROM msc_st_shift_exceptions mc2
4921 WHERE mc2.sr_instance_code = mc1.sr_instance_code
4922 AND mc2.calendar_code = mc1.calendar_code
4923 AND mc2.exception_date = mc1.exception_date
4924 AND nvl(mc2.shift_name,NULL_CHAR) = nvl(mc1.shift_name,NULL_CHAR)
4925 AND nvl(mc2.shift_num,NULL_VALUE) = nvl(mc1.shift_num,NULL_VALUE)
4926 AND mc2.process_flag = G_IN_PROCESS
4927 AND NVL(mc2.message_id,NULL_VALUE) <>NULL_VALUE)
4928 AND mc1.calendar_code = rec1.calendar_code
4929 AND mc1.process_flag = G_IN_PROCESS
4930 AND mc1.sr_instance_code = v_instance_code
4931 AND NVL(mc1.message_id,NULL_VALUE) <> NULL_VALUE;
4932
4933
4934 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
4935 (p_app_short_name => 'MSC',
4936 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
4937 p_message_text => lv_message_text,
4938 p_error_text => lv_error_text);
4939
4940 IF lv_return <> 0 THEN
4941 RAISE ex_logging_err;
4942 END IF;
4943
4944 --Duplicate records check for the records whose source is other than XML
4945 --Different SQL is used because in XML we can identify the latest records
4946 --whereas in batch load we cannot.
4947
4948 UPDATE msc_st_shift_exceptions mc1
4949 SET process_flag = G_ERROR_FLG,
4950 error_text = lv_message_text
4951 WHERE EXISTS( SELECT 1
4952 FROM msc_st_shift_exceptions mc2
4953 WHERE mc2.sr_instance_code = mc1.sr_instance_code
4954 AND mc2.calendar_code = mc1.calendar_code
4955 AND mc2.exception_date = mc1.exception_date
4956 AND nvl(mc2.shift_name,NULL_CHAR) = nvl(mc1.shift_name,NULL_CHAR)
4957 AND nvl(mc2.shift_num,NULL_VALUE) = nvl(mc1.shift_num,NULL_VALUE)
4958 AND mc2.process_flag = G_IN_PROCESS
4959 AND NVL(mc2.message_id,NULL_VALUE) = NULL_VALUE
4960 GROUP BY sr_instance_code,company_name,calendar_code,exception_date
4961 HAVING COUNT(*) > 1)
4962 AND mc1.calendar_code = rec1.calendar_code
4963 AND mc1.process_flag = G_IN_PROCESS
4964 AND mc1.sr_instance_code = v_instance_code
4965 AND NVL(mc1.message_id,NULL_VALUE) = NULL_VALUE;
4966 --Added to fix the bug#2748859
4967
4968 FOR rec5 IN c5(rec1.calendar_code)
4969 LOOP
4970 lv_table_name := 'MSC_ST_SHIFT_EXCEPTIONS';
4971 lv_column_names :=
4972 'CALENDAR_CODE ||''~''||'
4973 ||'EXCEPTION_DATE ||''~''||'
4974 ||'EXCEPTION_TYPE ||''~''||'
4975 ||'SR_INSTANCE_CODE||''~''||'
4976 ||'SHIFT_NUM ||''~''||'
4977 ||'SHIFT_NAME ||''~''||'
4978 ||'COMPANY_NAME ||''~''||'
4979 ||'EXCEPTION_SET_ID||''~''||'
4980 ||'DELETED_FLAG';
4981
4982 v_sql_stmt := 22;
4983 SELECT msc_st_shift_exceptions_s.NEXTVAL
4984 INTO lv_transaction_id
4985 FROM dual;
4986
4987 v_sql_stmt := 23;
4988 UPDATE msc_st_shift_exceptions
4989 SET st_transaction_id = lv_transaction_id,
4990 refresh_id = v_refresh_id,
4991 exception_set_id = -1,
4992 last_update_date = v_current_date,
4993 last_updated_by = v_current_user,
4994 creation_date = v_current_date,
4995 created_by = v_current_user
4996 WHERE rowid = rec5.rowid;
4997
4998 IF rec5.deleted_flag = SYS_YES THEN
4999 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
5000 (p_app_short_name => 'MSC',
5001 p_error_code => 'MSC_PP_NO_DELETION',
5002 p_message_text => lv_message_text,
5003 p_error_text => lv_error_text,
5004 p_token1 => 'TABLE_NAME',
5005 p_token_value1 => 'MSC_ST_SHIFT_EXCEPTIONS');
5006
5007 IF lv_return <> 0 THEN
5008 RAISE ex_logging_err;
5009 END IF;
5010 RAISE ex_critical_err;
5011
5012 ELSIF rec5.exception_date IS NULL THEN
5013 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
5014 (p_app_short_name => 'MSC',
5015 p_error_code => 'MSC_PP_COL_VAL_NULL',
5016 p_message_text => lv_message_text,
5017 p_error_text => lv_error_text,
5018 p_token1 => 'COLUMN_NAME',
5019 p_token_value1 => 'EXCEPTION_DATE ');
5020
5021 IF lv_return <> 0 THEN
5022 RAISE ex_logging_err;
5023 END IF;
5024 RAISE ex_critical_err;
5025
5026 ELSIF (rec5.exception_date < rec1.calendar_start_date OR
5027 rec5.exception_date > rec1.calendar_end_date) THEN
5028 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
5029 (p_app_short_name => 'MSC',
5030 p_error_code => 'MSC_PP_EXCEP_DATE_INVALID',
5031 p_message_text => lv_message_text,
5032 p_error_text => lv_error_text);
5033
5034 IF lv_return <> 0 THEN
5035 RAISE ex_logging_err;
5036 END IF;
5037 RAISE ex_critical_err;
5038
5039 ELSIF rec5.exception_type NOT IN(1,2) THEN
5040 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
5041 (p_app_short_name => 'MSC',
5042 p_error_code => 'MSC_PP_INVALID_VALUE',
5043 p_message_text => lv_message_text,
5044 p_error_text => lv_error_text,
5045 p_token1 => 'COLUMN_NAME',
5046 p_token_value1 => 'EXCEPTION_TYPE');
5047
5048 IF lv_return <> 0 THEN
5049 RAISE ex_logging_err;
5050 END IF;
5051 RAISE ex_critical_err;
5052
5053 ELSIF rec5.shift_name IS NULL THEN
5054 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
5055 (p_app_short_name => 'MSC',
5056 p_error_code => 'MSC_PP_COL_VAL_NULL',
5057 p_message_text => lv_message_text,
5058 p_error_text => lv_error_text,
5059 p_token1 => 'COLUMN_NAME',
5060 p_token_value1 => 'SHIFT_NAME');
5061
5062 IF lv_return <> 0 THEN
5063 RAISE ex_logging_err;
5064 END IF;
5065 RAISE ex_critical_err;
5066
5067 END IF;
5068
5069 IF v_instance_type = G_SCE then
5070 v_sql_stmt := 24;
5071 lv_sql_stmt :=
5072 ' UPDATE msc_st_shift_exceptions mc'
5073 ||' SET company_id = (SELECT party_id '
5074 ||' FROM hz_parties hp'
5075 ||' WHERE hp.party_name = mc.company_name)'
5076 ||' WHERE st_transaction_id = :lv_transaction_id ';
5077
5078 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5079 EXECUTE IMMEDIATE lv_sql_stmt
5080 USING lv_transaction_id;
5081
5082 IF SQL%NOTFOUND THEN
5083 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
5084 (p_app_short_name => 'MSC',
5085 p_error_code => 'MSC_PP_INVALID_VALUE',
5086 p_message_text => lv_message_text,
5087 p_error_text => lv_error_text,
5088 p_token1 => 'COLUMN_NAME',
5089 p_token_value1 => 'COMPANY_NAME');
5090
5091 IF lv_return <> 0 THEN
5092 RAISE ex_logging_err;
5093 END IF;
5094 RAISE ex_critical_err;
5095 END IF;
5096 ELSE
5097 v_sql_stmt := 25;
5098 lv_sql_stmt :=
5099 ' UPDATE msc_st_shift_exceptions'
5100 ||' SET company_id = '||G_COMPANY_ID
5101 ||' WHERE st_transaction_id = :lv_transaction_id ';
5102
5103 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5104 EXECUTE IMMEDIATE lv_sql_stmt
5105 USING lv_transaction_id;
5106
5107 END IF;
5108
5109 IF rec5.deleted_flag NOT IN(1,2) THEN
5110 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
5111 (p_app_short_name => 'MSC',
5112 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
5113 p_message_text => lv_message_text,
5114 p_error_text => lv_error_text,
5115 p_token1 => 'COLUMN_NAME',
5116 p_token_value1 => 'DELETED_FLAG',
5117 p_token2 => 'DEFAULT_VALUE',
5118 p_token_value2 => SYS_NO);
5119
5120 lv_where_str := ' AND st_transaction_id = '||lv_transaction_id;
5121
5122 --Logging a warning for those records where the deleted_flag value
5123 --is other than Yes/No.
5124 lv_return := MSC_ST_UTIL.LOG_ERROR
5125 (p_table_name => 'MSC_ST_SHIFT_EXCEPTIONS',
5126 p_instance_code => v_instance_code,
5127 p_row => lv_column_names,
5128 p_severity => G_SEV_WARNING,
5129 p_message_text => lv_message_text,
5130 p_error_text => lv_error_text,
5131 p_where_str => lv_where_str,
5132 p_col_name => 'DELETED_FLAG',
5133 p_debug => v_debug,
5134 p_default_value => SYS_NO);
5135
5136 IF lv_return <> 0 THEN
5137 RAISE ex_logging_err;
5138 END IF;
5139 END IF;
5140
5141 --Call to customised validation.
5142 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
5143 (ERRBUF => lv_error_text,
5144 RETCODE => lv_return,
5145 pBatchID => null,
5146 pInstanceCode => v_instance_code,
5147 pEntityName => 'MSC_ST_SHIFT_EXCEPTIONS',
5148 pInstanceID => v_instance_id);
5149
5150 IF lv_return <> 0 THEN
5151 RAISE ex_logging_err;
5152 END IF;
5153
5154 END LOOP;
5155
5156 lv_where_str :=
5157 ' AND calendar_code = '||''''||rec1.calendar_code||'''';
5158 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
5159 (p_table_name => 'MSC_ST_CALENDARS',
5160 p_instance_id => v_instance_id,
5161 p_instance_code => v_instance_code,
5162 p_process_flag => G_VALID,
5163 p_where_str => lv_where_str,
5164 p_debug => v_debug,
5165 p_error_text => lv_error_text);
5166
5167 IF lv_return <> 0 THEN
5168 RAISE ex_logging_err;
5169 END IF;
5170
5171 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
5172 (p_table_name => 'MSC_ST_WORKDAY_PATTERNS',
5173 p_instance_id => v_instance_id,
5174 p_instance_code => v_instance_code,
5175 p_process_flag => G_VALID,
5176 p_where_str => lv_where_str,
5177 p_debug => v_debug,
5178 p_error_text => lv_error_text);
5179
5180 IF lv_return <> 0 THEN
5181 RAISE ex_logging_err;
5182 END IF;
5183
5184
5185 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
5186 (p_table_name => 'MSC_ST_CALENDAR_SHIFTS',
5187 p_instance_id => v_instance_id,
5188 p_instance_code => v_instance_code,
5189 p_process_flag => G_VALID,
5190 p_where_str => lv_where_str,
5191 p_debug => v_debug,
5192 p_error_text => lv_error_text);
5193
5194 IF lv_return <> 0 THEN
5195 RAISE ex_logging_err;
5196 END IF;
5197
5198 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
5199 (p_table_name => 'MSC_ST_SHIFT_TIMES',
5200 p_instance_id => v_instance_id,
5201 p_instance_code => v_instance_code,
5202 p_process_flag => G_VALID,
5203 p_where_str => lv_where_str,
5204 p_debug => v_debug,
5205 p_error_text => lv_error_text);
5206
5207 IF lv_return <> 0 THEN
5208 RAISE ex_logging_err;
5209 END IF;
5210
5211 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
5212 (p_table_name => 'MSC_ST_CALENDAR_EXCEPTIONS',
5213 p_instance_id => v_instance_id,
5214 p_instance_code => v_instance_code,
5215 p_process_flag => G_VALID,
5216 p_where_str => lv_where_str,
5217 p_debug => v_debug,
5218 p_error_text => lv_error_text);
5219
5220 IF lv_return <> 0 THEN
5221 RAISE ex_logging_err;
5222 END IF;
5223
5224 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
5225 (p_table_name => 'MSC_ST_SHIFT_EXCEPTIONS',
5226 p_instance_id => v_instance_id,
5227 p_instance_code => v_instance_code,
5228 p_process_flag => G_VALID,
5229 p_where_str => lv_where_str,
5230 p_debug => v_debug,
5231 p_error_text => lv_error_text);
5232
5233 IF lv_return <> 0 THEN
5234 RAISE ex_logging_err;
5235 END IF;
5236
5237 IF rec1.overwrite_flag = 'Y' THEN
5238 v_sql_stmt := 26; /*Bug 2172537*/
5239 lv_sql_stmt :=
5240 'UPDATE msc_calendars '
5241 ||' SET calendar_start_date = :calendar_start_date,'
5242 ||' calendar_end_date = :calendar_end_date,'
5243 ||' quarterly_calendar_type = :quarterly_calendar_type,'
5244 ||' week_start_day = :week_start_day,'
5245 ||' creation_date = :v_current_date,'
5246 ||' created_by = :v_current_user,'
5247 ||' last_update_date = :v_current_date,'
5248 ||' last_updated_by = :v_current_user'
5249 ||' WHERE calendar_code = :calendar_code'
5250 ||' AND sr_instance_id = :instance_id';
5251
5252 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5253 EXECUTE IMMEDIATE lv_sql_stmt
5254 USING rec1.calendar_start_date,
5255 rec1.calendar_end_date,
5256 rec1.quarterly_calendar_type,
5257 rec1.week_start_day,
5258 v_current_date,
5259 v_current_user,
5260 v_current_date,
5261 v_current_user,
5262 rec1.calendar_code,
5263 v_instance_id;
5264
5265 ELSE
5266 v_sql_stmt := 27;
5267 lv_sql_stmt :=
5268 'DELETE FROM msc_calendars '
5269 ||' WHERE calendar_code = :calendar_code';
5270
5271 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5272 EXECUTE IMMEDIATE lv_sql_stmt
5273 USING rec1.calendar_code;
5274
5275 v_sql_stmt := 28; /*Bug 2172537*/
5276 lv_sql_stmt :=
5277 'INSERT INTO msc_calendars '
5278 ||' (calendar_code,'
5279 ||' description,'
5280 ||' days_on,'
5281 ||' days_off,'
5282 ||' calendar_start_date,'
5283 ||' calendar_end_date,'
5284 ||' quarterly_calendar_type,'
5285 ||' sr_instance_id,'
5286 ||' last_update_date,'
5287 ||' last_updated_by,'
5288 ||' creation_date,'
5289 ||' created_by,'
5290 ||' last_update_login,'
5291 ||' request_id,'
5292 ||' program_application_id,'
5293 ||' program_id,'
5294 ||' program_update_date,'
5295 ||' refresh_id,'
5296 ||' overwrite_flag,'
5297 ||' week_start_day)'
5298 ||' SELECT '
5299 ||' calendar_code,'
5300 ||' description,'
5301 ||' days_on,'
5302 ||' days_off,'
5303 ||' calendar_start_date,'
5304 ||' calendar_end_date,'
5305 ||' quarterly_calendar_type,'
5306 ||' sr_instance_id,'
5307 ||' last_update_date,'
5308 ||' last_updated_by,'
5309 ||' creation_date,'
5310 ||' created_by,'
5311 ||' last_update_login,'
5312 ||' request_id,'
5313 ||' program_application_id,'
5314 ||' program_id,'
5315 ||' program_update_date,'
5316 ||' refresh_id,'
5317 ||' overwrite_flag,'
5318 ||' week_start_day'
5319 ||' FROM msc_st_calendars'
5320 ||' WHERE calendar_code = :calendar_code'
5321 ||' AND sr_instance_code = :sr_instance_code'
5322 ||' AND process_flag = '||G_VALID;
5323
5324
5325 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5326 EXECUTE IMMEDIATE lv_sql_stmt
5327 USING rec1.calendar_code,
5328 v_instance_code;
5329 END IF;
5330
5331 v_sql_stmt := 29; /*Bug 2172537*/
5332 lv_sql_stmt :=
5333 'DELETE FROM msc_workday_patterns '
5334 ||' WHERE calendar_code = :calendar_code';
5335
5336 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5337 EXECUTE IMMEDIATE lv_sql_stmt
5338 USING rec1.calendar_code;
5339
5340 v_sql_stmt := 30; /*Bug 2172537*/
5341 lv_sql_stmt :=
5342 'INSERT INTO msc_workday_patterns '
5343 ||' (calendar_code,'
5344 ||' description,'
5345 ||' sr_instance_id,'
5346 ||' shift_num,'
5347 ||' seq_num,'
5348 ||' last_update_date,'
5349 ||' last_updated_by,'
5350 ||' creation_date,'
5351 ||' created_by,'
5352 ||' last_update_login,'
5353 ||' days_on,'
5354 ||' days_off,'
5355 ||' request_id,'
5356 ||' program_application_id,'
5357 ||' program_id,'
5358 ||' program_update_date,'
5359 ||' refresh_id)'
5360 ||' SELECT '
5361 ||' calendar_code,'
5362 ||' description,'
5363 ||' sr_instance_id,'
5364 ||' shift_num,'
5365 ||' seq_num,'
5366 ||' last_update_date,'
5367 ||' last_updated_by,'
5368 ||' creation_date,'
5369 ||' created_by,'
5370 ||' last_update_login,'
5371 ||' days_on,'
5372 ||' days_off,'
5373 ||' request_id,'
5374 ||' program_application_id,'
5375 ||' program_id,'
5376 ||' program_update_date,'
5377 ||' refresh_id'
5378 ||' FROM msc_st_workday_patterns'
5379 ||' WHERE calendar_code = :calendar_code'
5380 ||' AND sr_instance_code = :sr_instance_code'
5381 ||' AND process_flag = '||G_VALID;
5382
5383 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5384 EXECUTE IMMEDIATE lv_sql_stmt
5385 USING rec1.calendar_code,
5386 v_instance_code;
5387
5388 v_sql_stmt := 31; /*Bug 2172537*/
5389 lv_sql_stmt :=
5390 'DELETE FROM msc_calendar_exceptions '
5391 ||' WHERE calendar_code = :calendar_code';
5392
5393 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5394 EXECUTE IMMEDIATE lv_sql_stmt
5395 USING rec1.calendar_code;
5396
5397
5398 v_sql_stmt := 32; /*Bug 2172537*/
5399 lv_sql_stmt :=
5400 'INSERT INTO msc_calendar_exceptions'
5401 ||' (calendar_code,'
5402 ||' exception_date,'
5403 ||' exception_type,'
5404 ||' sr_instance_id,'
5405 ||' last_update_date,'
5406 ||' last_updated_by,'
5407 ||' creation_date,'
5408 ||' created_by,'
5409 ||' last_update_login,'
5410 ||' request_id,'
5411 ||' program_application_id,'
5412 ||' program_id,'
5413 ||' program_update_date,'
5414 ||' refresh_id,'
5415 ||' exception_set_id)'
5416 ||' SELECT '
5417 ||' calendar_code,'
5418 ||' exception_date,'
5419 ||' exception_type,'
5420 ||' sr_instance_id,'
5421 ||' last_update_date,'
5422 ||' last_updated_by,'
5423 ||' creation_date,'
5424 ||' created_by,'
5425 ||' last_update_login,'
5426 ||' request_id,'
5427 ||' program_application_id,'
5428 ||' program_id,'
5429 ||' program_update_date,'
5430 ||' refresh_id,'
5431 ||' exception_set_id'
5432 ||' FROM msc_st_calendar_exceptions'
5433 ||' WHERE calendar_code = :calendar_code'
5434 ||' AND sr_instance_code = :sr_instance_code'
5435 ||' AND process_flag = '||G_VALID ;
5436
5437 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5438 EXECUTE IMMEDIATE lv_sql_stmt
5439 USING rec1.calendar_code,
5440 v_instance_code;
5441
5442 v_sql_stmt := 33; /*Bug 2172537*/
5443 lv_sql_stmt :=
5444 'DELETE FROM msc_calendar_shifts '
5445 ||' WHERE calendar_code = :calendar_code';
5446
5447
5448 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5449 EXECUTE IMMEDIATE lv_sql_stmt
5450 USING rec1.calendar_code;
5451
5452 v_sql_stmt := 34; /*Bug 2172537*/
5453 lv_sql_stmt :=
5454 'INSERT INTO msc_calendar_shifts '
5455 ||' (calendar_code,'
5456 ||' sr_instance_id,'
5457 ||' shift_name,'
5458 ||' shift_num,'
5459 ||' days_on,'
5460 ||' days_off,'
5461 ||' description,'
5462 ||' refresh_number,'
5463 ||' last_update_date,'
5464 ||' last_updated_by,'
5465 ||' last_update_login,'
5466 ||' creation_date,'
5467 ||' created_by,'
5468 ||' request_id,'
5469 ||' program_application_id,'
5470 ||' program_id,'
5471 ||' program_update_date)'
5472 ||' SELECT '
5473 ||' calendar_code,'
5474 ||' sr_instance_id,'
5475 ||' shift_name,'
5476 ||' shift_num, '
5477 ||' days_on,'
5478 ||' days_off,'
5479 ||' description,'
5480 ||' refresh_id,'
5481 ||' last_update_date,'
5482 ||' last_updated_by,'
5483 ||' last_update_login,'
5484 ||' creation_date,'
5485 ||' created_by,'
5486 ||' request_id,'
5487 ||' program_application_id,'
5488 ||' program_id,'
5489 ||' program_update_date'
5490 ||' FROM msc_st_calendar_shifts '
5491 ||' WHERE calendar_code = :calendar_code'
5492 ||' AND sr_instance_code = :sr_instance_code'
5493 ||' AND process_flag = '||G_VALID;
5494
5495 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5496 EXECUTE IMMEDIATE lv_sql_stmt
5497 USING rec1.calendar_code,
5498 v_instance_code;
5499
5500 v_sql_stmt := 35;/*Bug 2172537*/
5501 lv_sql_stmt :=
5502 'DELETE FROM msc_shift_times '
5503 ||' WHERE calendar_code = :calendar_code';
5504
5505 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5506 EXECUTE IMMEDIATE lv_sql_stmt
5507 USING rec1.calendar_code;
5508
5509
5510 v_sql_stmt := 36; /*Bug 2172537*/
5511 lv_sql_stmt :=
5512 'INSERT INTO msc_shift_times '
5513 ||' (calendar_code,'
5514 ||' sr_instance_id,'
5515 ||' shift_num,'
5516 ||' from_time,'
5517 ||' to_time,'
5518 ||' refresh_number,'
5519 ||' last_update_date,'
5520 ||' last_updated_by,'
5521 ||' last_update_login,'
5522 ||' creation_date,'
5523 ||' created_by,'
5524 ||' request_id,'
5525 ||' program_application_id,'
5526 ||' program_id,'
5527 ||' program_update_date)'
5528 ||' SELECT '
5529 ||' calendar_code,'
5530 ||' sr_instance_id,'
5531 ||' shift_num,'
5532 ||' from_time,'
5533 ||' to_time,'
5534 ||' refresh_id,'
5535 ||' last_update_date,'
5536 ||' last_updated_by,'
5537 ||' last_update_login,'
5538 ||' creation_date,'
5539 ||' created_by,'
5540 ||' request_id,'
5541 ||' program_application_id,'
5542 ||' program_id,'
5543 ||' program_update_date'
5544 ||' FROM msc_st_shift_times '
5545 ||' WHERE calendar_code = :calendar_code'
5546 ||' AND sr_instance_code = :sr_instance_code'
5547 ||' AND process_flag = '||G_VALID;
5548
5549 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5550 EXECUTE IMMEDIATE lv_sql_stmt
5551 USING rec1.calendar_code,
5552 v_instance_code;
5553
5554 v_sql_stmt := 37;/*Bug 2172537*/
5555 lv_sql_stmt :=
5556 'DELETE FROM msc_shift_exceptions '
5557 ||' WHERE calendar_code = :calendar_code';
5558
5559 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5560 EXECUTE IMMEDIATE lv_sql_stmt
5561 USING rec1.calendar_code;
5562
5563
5564 v_sql_stmt := 38; /*Bug 2172537*/
5565 lv_sql_stmt :=
5566 'INSERT INTO msc_shift_exceptions'
5567 ||' (calendar_code,'
5568 ||' shift_num,'
5569 ||' exception_date,'
5570 ||' exception_type,'
5571 ||' sr_instance_id,'
5572 ||' last_update_date,'
5573 ||' last_updated_by,'
5574 ||' creation_date,'
5575 ||' created_by,'
5576 ||' last_update_login,'
5577 ||' request_id,'
5578 ||' program_application_id,'
5579 ||' program_id,'
5580 ||' program_update_date,'
5581 ||' refresh_number,'
5582 ||' exception_set_id)'
5583 ||' SELECT '
5584 ||' calendar_code,'
5585 ||' shift_num,'
5586 ||' exception_date,'
5587 ||' exception_type,'
5588 ||' sr_instance_id,'
5589 ||' last_update_date,'
5590 ||' last_updated_by,'
5591 ||' creation_date,'
5592 ||' created_by,'
5593 ||' last_update_login,'
5594 ||' request_id,'
5595 ||' program_application_id,'
5596 ||' program_id,'
5597 ||' program_update_date,'
5598 ||' refresh_id,'
5599 ||' exception_set_id'
5600 ||' FROM msc_st_shift_exceptions'
5601 ||' WHERE calendar_code = :calendar_code'
5602 ||' AND sr_instance_code = :sr_instance_code'
5603 ||' AND process_flag = '||G_VALID;
5604
5605 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5606 EXECUTE IMMEDIATE lv_sql_stmt
5607 USING rec1.calendar_code,
5608 v_instance_code;
5609
5610 -- Delete those tables that is collected by collections
5611 v_sql_stmt := 39;
5612
5613 lv_sql_stmt :=
5614 ' DELETE FROM msc_st_calendar_shifts '
5615 ||' WHERE calendar_code = :calendar_code'
5616 ||' AND sr_instance_code = :sr_instance_code'
5617 ||' AND process_flag = '||G_VALID;
5618
5619
5620 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5621
5622 EXECUTE IMMEDIATE lv_sql_stmt
5623 USING rec1.calendar_code,
5624 v_instance_code;
5625
5626 v_sql_stmt := 40;
5627
5628 lv_sql_stmt :=
5629 ' DELETE FROM msc_st_shift_times '
5630 ||' WHERE calendar_code = :calendar_code'
5631 ||' AND sr_instance_code = :sr_instance_code'
5632 ||' AND process_flag = '||G_VALID;
5633
5634
5635 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5636
5637 EXECUTE IMMEDIATE lv_sql_stmt
5638 USING rec1.calendar_code,
5639 v_instance_code;
5640
5641 v_sql_stmt := 41;
5642
5643 lv_sql_stmt :=
5644 ' DELETE FROM msc_st_shift_exceptions '
5645 ||' WHERE calendar_code = :calendar_code'
5646 ||' AND sr_instance_code = :sr_instance_code'
5647 ||' AND process_flag = '||G_VALID;
5648
5649
5650 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5651
5652 EXECUTE IMMEDIATE lv_sql_stmt
5653 USING rec1.calendar_code,
5654 v_instance_code;
5655
5656
5657
5658 COMMIT;
5659 lv_request_id := fnd_request.submit_request('MSC','MSCPCL',
5660 '','',TRUE,
5661 rec1.calendar_code,
5662 v_instance_id);
5663 v_cal_build := true;
5664 IF lv_request_id <> 0 THEN
5665 fnd_conc_global.set_req_globals(conc_status => 'PAUSED',
5666 request_data => to_char(G_CAL_REQ_DATA)) ;
5667 FND_MESSAGE.SET_NAME('MSC', 'MSC_PP_WORKER_REQUEST_ID');
5668 FND_MESSAGE.SET_TOKEN('REQUEST_ID', lv_request_id);
5669 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
5670 END IF;
5671
5672 EXCEPTION
5673 WHEN too_many_rows THEN
5674 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_CALENDAR'||'('
5675 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
5676 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
5677 ROLLBACK;
5678
5679 WHEN ex_logging_err THEN
5680 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
5681 ROLLBACK;
5682
5683 WHEN ex_critical_err THEN
5684 lv_return := PROPAGATE_CAL_ERROR
5685 (p_table_name => lv_table_name,
5686 p_transaction_id => lv_transaction_id,
5687 p_calendar_code => lv_calendar_code,
5688 p_message_text => lv_message_text,
5689 p_column_names => lv_column_names,
5690 p_error_text => lv_error_text);
5691
5692 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
5693 IF lv_return <> 0 THEN
5694 ROLLBACK;
5695 ELSE
5696 COMMIT;
5697 END IF;
5698
5699 WHEN OTHERS THEN
5700 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_CALENDAR'||'('
5701 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
5702 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
5703
5704 ROLLBACK;
5705 END;
5706
5707 END LOOP;
5708 EXCEPTION
5709 WHEN OTHERS THEN
5710 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_CALENDAR'||'('
5711 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
5712 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
5713
5714 ROLLBACK;
5715
5716 END LOAD_CALENDAR;
5717 /*==========================================================================+
5718 | DESCRIPTION : This function performs the validation and loads the data |
5719 | for business object demand class |
5720 +==========================================================================*/
5721 PROCEDURE LOAD_DEMAND_CLASS IS
5722 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
5723 lb_rowid RowidTab; --bulk collects rowid
5724 lv_return NUMBER;
5725 lv_batch_id NUMBER;
5726 lv_error_text VARCHAR2(250);
5727 lv_where_str VARCHAR2(5000);
5728 lv_sql_stmt VARCHAR2(5000);
5729 lv_column_names VARCHAR2(5000); --stores concatenated column names
5730 lv_message_text msc_errors.error_text%TYPE;
5731
5732 ex_logging_err EXCEPTION;
5733
5734 CURSOR c1(p_batch_id NUMBER) IS
5735 SELECT rowid
5736 FROM msc_st_demand_classes
5737 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
5738 AND sr_instance_code = v_instance_code
5739 AND batch_id = p_batch_id;
5740
5741 BEGIN
5742
5743 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
5744 (p_app_short_name => 'MSC',
5745 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
5746 p_message_text => lv_message_text,
5747 p_error_text => lv_error_text);
5748
5749 IF lv_return <> 0 THEN
5750 RAISE ex_logging_err;
5751 END IF;
5752
5753 --Validation check for the table MSC_ST_DEMAND_CLASSES
5754
5755 --Duplicate records check for the records whose source is other than XML
5756 --Different SQL is used because in XML we can identify the latest records
5757 --whereas in batch load we cannot.
5758
5759 v_sql_stmt := 01;
5760 lv_sql_stmt :=
5761 'UPDATE msc_st_demand_classes msd1 '
5762 ||' SET process_flag = '||G_ERROR_FLG||','
5763 ||' error_text = '||''''||lv_message_text||''''
5764 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_demand_classes msd2 '
5765 ||' WHERE msd2.sr_instance_code = msd1.sr_instance_code'
5766 ||' AND msd2.demand_class = msd1.demand_class'
5767 ||' AND NVL(msd2.company_name, '||''''||NULL_CHAR||''''||') = '
5768 ||' NVL(msd1.company_name, '||''''||NULL_CHAR||''''||')'
5769 ||' AND msd2.process_flag = msd1.process_flag'
5770 ||' AND NVL(msd2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
5771 ||' GROUP BY sr_instance_code,demand_class,company_name '
5772 ||' HAVING COUNT(*) >1 )'
5773 ||' AND msd1.process_flag = '||G_IN_PROCESS
5774 ||' AND msd1.sr_instance_code = :v_instance_code'
5775 ||' AND NVL(msd1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
5776
5777
5778 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5779
5780
5781 EXECUTE IMMEDIATE lv_sql_stmt
5782 USING v_instance_code;
5783
5784
5785 --Duplicate records check for the records whose source is XML
5786 v_sql_stmt := 02;
5787 lv_sql_stmt :=
5788 'UPDATE msc_st_demand_classes msd1 '
5789 ||' SET process_flag = '||G_ERROR_FLG||','
5790 ||' error_text = '||''''||lv_message_text||''''
5791 ||' WHERE message_id < ( SELECT max(message_id) '
5792 ||' FROM msc_st_demand_classes msd2'
5793 ||' WHERE msd2.sr_instance_code = msd1.sr_instance_code'
5794 ||' AND msd2.demand_class = msd1.demand_class'
5795 ||' AND NVL(msd2.company_name, '||''''||NULL_CHAR||''''||') = '
5796 ||' NVL(msd1.company_name, '||''''||NULL_CHAR||''''||')'
5797 ||' AND msd2.process_flag = msd1.process_flag'
5798 ||' AND NVL(msd2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
5799 ||' AND msd1.process_flag = '||G_IN_PROCESS
5800 ||' AND msd1.sr_instance_code = :v_instance_code '
5801 ||' AND NVL(msd1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
5802
5803
5804 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5805
5806
5807 EXECUTE IMMEDIATE lv_sql_stmt
5808 USING v_instance_code;
5809
5810
5811 lv_column_names :=
5812 ' DEMAND_CLASS ||''~''||'
5813 ||' MEANING ||''~''||'
5814 ||' DESCRIPTION ||''~''||'
5815 ||' FROM_DATE ||''~''||'
5816 ||' TO_DATE ||''~''||'
5817 ||' ENABLED_FLAG ||''~''||'
5818 ||' SR_INSTANCE_CODE ||''~''||'
5819 ||' COMPANY_NAME ||''~''||'
5820 ||' DELETED_FLAG ';
5821
5822
5823 -- Dividing records in batches based on batchsize
5824 LOOP
5825 v_sql_stmt := 03;
5826 SELECT msc_st_batch_id_s.NEXTVAL
5827 INTO lv_batch_id
5828 FROM DUAL;
5829
5830 v_sql_stmt := 04;
5831 lv_sql_stmt :=
5832 'UPDATE msc_st_demand_classes '
5833 ||' SET batch_id = :lv_batch_id '
5834 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
5835 ||' AND sr_instance_code = :v_instance_code'
5836 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
5837 ||' AND rownum <= '||v_batch_size;
5838
5839
5840 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5841
5842
5843 EXECUTE IMMEDIATE lv_sql_stmt
5844 USING lv_batch_id,
5845 v_instance_code;
5846
5847 EXIT WHEN SQL%NOTFOUND ;
5848
5849 OPEN c1(lv_batch_id);
5850 FETCH c1 BULK COLLECT INTO lb_rowid;
5851 CLOSE c1;
5852
5853 v_sql_stmt := 05;
5854 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
5855 UPDATE msc_st_demand_classes
5856 SET st_transaction_id = msc_st_demand_classes_s.NEXTVAL,
5857 refresh_id = v_refresh_id,
5858 last_update_date = v_current_date,
5859 last_updated_by = v_current_user,
5860 creation_date = v_current_date,
5861 created_by = v_current_user
5862 WHERE rowid = lb_rowid(j);
5863
5864
5865 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
5866 (p_app_short_name => 'MSC',
5867 p_error_code => 'MSC_PP_NO_DELETION',
5868 p_message_text => lv_message_text,
5869 p_error_text => lv_error_text,
5870 p_token1 => 'TABLE_NAME',
5871 p_token_value1 => 'MSC_ST_DEMAND_CLASSES');
5872
5873 -- Deletion is not allowed for this table
5874 v_sql_stmt := 06;
5875 lv_sql_stmt :=
5876 'UPDATE msc_st_demand_classes '
5877 ||' SET process_flag = '||G_ERROR_FLG||','
5878 ||' error_text = '||''''||lv_message_text||''''
5879 ||' WHERE deleted_flag = '||SYS_YES
5880 ||' AND process_flag = '||G_IN_PROCESS
5881 ||' AND batch_id = :lv_batch_id'
5882 ||' AND sr_instance_code = :v_instance_code';
5883
5884
5885 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5886
5887
5888 EXECUTE IMMEDIATE lv_sql_stmt
5889 USING lv_batch_id,
5890 v_instance_code;
5891
5892
5893 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
5894 (p_app_short_name => 'MSC',
5895 p_error_code => 'MSC_PP_COL_VAL_NULL',
5896 p_message_text => lv_message_text,
5897 p_error_text => lv_error_text,
5898 p_token1 => 'COLUMN_NAME',
5899 p_token_value1 => 'DEMAND_CLASS OR MEANING');
5900
5901 IF lv_return <> 0 THEN
5902 RAISE ex_logging_err;
5903 END IF;
5904
5905 -- Error out records where demand_class or meaning is NULL
5906
5907 v_sql_stmt := 07;
5908 lv_sql_stmt :=
5909 'UPDATE msc_st_demand_classes'
5910 ||' SET process_flag = '||G_ERROR_FLG||','
5911 ||' error_text = '||''''||lv_message_text||''''
5912 ||' WHERE (NVL(demand_class, '||''''||NULL_CHAR||''''||') '
5913 ||' = '||''''||NULL_CHAR||''''
5914 ||' OR NVL(meaning, '||''''||NULL_CHAR||''''||') '
5915 ||' = '||''''||NULL_CHAR||''''||') '
5916 ||' AND batch_id = :lv_batch_id'
5917 ||' AND process_flag = '||G_IN_PROCESS
5918 ||' AND sr_instance_code = :v_instance_code';
5919
5920
5921 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
5922
5923 EXECUTE IMMEDIATE lv_sql_stmt
5924 USING lv_batch_id,
5925 v_instance_code;
5926
5927
5928 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
5929 (p_app_short_name => 'MSC',
5930 p_error_code => 'MSC_PP_NO_UPDATION',
5931 p_message_text => lv_message_text,
5932 p_error_text => lv_error_text,
5933 p_token1 => 'TABLE_NAME',
5934 p_token_value1 => 'MSC_ST_DEMAND_CLASSES');
5935
5936
5937 -- Error out the record if same demand class already exists in ODS
5938 -- As we do not allow demand_class incremental update
5939 -- It has to be purged before laoded again
5940
5941 -- bug# 3807591
5942 /* v_sql_stmt := 08;
5943 lv_sql_stmt :=
5944 'UPDATE msc_st_demand_classes mstd'
5945 ||' SET mstd.process_flag = '||G_ERROR_FLG||','
5946 ||' mstd.error_text = '||''''||lv_message_text||''''
5947 ||' WHERE mstd.batch_id = :lv_batch_id'
5948 ||' AND mstd.sr_instance_code = :v_instance_code'
5949 ||' AND EXISTS ( SELECT 1'
5950 ||' FROM msc_demand_classes msd'
5951 ||' WHERE mstd.demand_class = msd.demand_class'
5952 ||' AND msd.sr_instance_id = :v_instance_id)';
5953 IF V_DEBUG THEN
5954 msc_st_util.log_message(lv_sql_stmt);
5955 END IF;
5956
5957 EXECUTE IMMEDIATE lv_sql_stmt
5958 USING lv_batch_id,
5959 v_instance_code,
5960 v_instance_id; */
5961
5962
5963 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
5964 (p_app_short_name => 'MSC',
5965 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
5966 p_message_text => lv_message_text,
5967 p_error_text => lv_error_text,
5968 p_token1 => 'COLUMN_NAME',
5969 p_token_value1 => 'DELETED_FLAG',
5970 p_token2 => 'DEFAULT_VALUE',
5971 p_token_value2 => SYS_NO);
5972
5973 IF lv_return <> 0 THEN
5974 RAISE ex_logging_err;
5975 END IF;
5976
5977 -- Check DELETE_FLAG column has valid value or not and if not set it to SYS_NO
5978 -- Log error procedure inserts warning and also defaults the delete flag
5979
5980 lv_where_str := ' AND NVL(deleted_flag,'||NULL_VALUE||') '
5981 ||' NOT IN(1,2)';
5982
5983 lv_return := MSC_ST_UTIL.LOG_ERROR
5984 (p_table_name => 'MSC_ST_DEMAND_CLASSES',
5985 p_instance_code => v_instance_code,
5986 p_row => lv_column_names,
5987 p_severity => G_SEV_WARNING,
5988 p_message_text => lv_message_text,
5989 p_error_text => lv_error_text,
5990 p_batch_id => lv_batch_id,
5991 p_where_str => lv_where_str,
5992 p_col_name => 'DELETED_FLAG',
5993 p_debug => v_debug,
5994 p_default_value => SYS_NO);
5995
5996 IF lv_return <> 0 THEN
5997 RAISE ex_logging_err;
5998 END IF;
5999
6000 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
6001 (p_app_short_name => 'MSC',
6002 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
6003 p_message_text => lv_message_text,
6004 p_error_text => lv_error_text,
6005 p_token1 => 'COLUMN_NAME',
6006 p_token_value1 => 'ENABLED_FLAG',
6007 p_token2 => 'DEFAULT_VALUE',
6008 p_token_value2 => SYS_NO);
6009
6010 IF lv_return <> 0 THEN
6011 RAISE ex_logging_err;
6012 END IF;
6013
6014 -- Check ENABLED_FLAG column has valid value or not and if not set it to SYS_NO
6015 -- Log error procedure inserts warning and also defaults the delete flag
6016
6017 lv_where_str := ' AND NVL(enabled_flag,'||NULL_VALUE||') '
6018 ||' NOT IN(1,2)';
6019
6020 lv_return := MSC_ST_UTIL.LOG_ERROR
6021 (p_table_name => 'MSC_ST_DEMAND_CLASSES',
6022 p_instance_code => v_instance_code,
6023 p_row => lv_column_names,
6024 p_severity => G_SEV_WARNING,
6025 p_message_text => lv_message_text,
6026 p_error_text => lv_error_text,
6027 p_batch_id => lv_batch_id,
6028 p_where_str => lv_where_str,
6029 p_col_name => 'ENABLED_FLAG',
6030 p_debug => v_debug,
6031 p_default_value => SYS_YES);
6032
6033 IF lv_return <> 0 THEN
6034 RAISE ex_logging_err;
6035 END IF;
6036
6037 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
6038 (p_app_short_name => 'MSC',
6039 p_error_code => 'MSC_PP_INVALID_VALUE',
6040 p_message_text => lv_message_text,
6041 p_error_text => lv_error_text,
6042 p_token1 => 'COLUMN_NAME',
6043 p_token_value1 => 'FROM_DATE OR'
6044 ||' TO_DATE');
6045
6046 IF lv_return <> 0 THEN
6047 RAISE ex_logging_err;
6048 END IF;
6049
6050
6051 -- Validate that from_date is greater than to_date
6052
6053 v_sql_stmt := 08;
6054
6055 lv_sql_stmt :=
6056 'UPDATE msc_st_demand_classes'
6057 ||' SET process_flag = '||G_ERROR_FLG||','
6058 ||' error_text = '||''''||lv_message_text||''''
6059 ||' WHERE NVL(from_date,SYSDATE-365000 ) '
6060 ||' > NVL(to_date, SYSDATE+365000) '
6061 ||' AND batch_id = :lv_batch_id'
6062 ||' AND process_flag = '||G_IN_PROCESS
6063 ||' AND sr_instance_code = :v_instance_code';
6064
6065
6066 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
6067
6068 EXECUTE IMMEDIATE lv_sql_stmt
6069 USING lv_batch_id,
6070 v_instance_code;
6071
6072
6073 --Call to customised validation.
6074 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
6075 (ERRBUF => lv_error_text,
6076 RETCODE => lv_return,
6077 pBatchID => lv_batch_id,
6078 pInstanceCode => v_instance_code,
6079 pEntityName => 'MSC_ST_TRADING_PARTNERS',
6080 pInstanceID => v_instance_id);
6081
6082 IF NVL(lv_return,0) <> 0 THEN
6083 RAISE ex_logging_err;
6084 END IF;
6085
6086
6087 -- Set the process flag as Valid and populate instance_id
6088 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
6089 (p_table_name => 'MSC_ST_DEMAND_CLASSES',
6090 p_instance_id => v_instance_id,
6091 p_instance_code => v_instance_code,
6092 p_process_flag => G_VALID,
6093 p_error_text => lv_error_text,
6094 p_debug => v_debug,
6095 p_batch_id => lv_batch_id);
6096
6097 IF lv_return <> 0 THEN
6098 RAISE ex_logging_err;
6099 END IF;
6100
6101 -- At the end calling the LOG_ERROR for logging all
6102 -- errored out records.
6103
6104 lv_return := MSC_ST_UTIL.LOG_ERROR
6105 (p_table_name => 'MSC_ST_DEMAND_CLASSES',
6106 p_instance_code => v_instance_code,
6107 p_row => lv_column_names,
6108 p_severity => G_SEV_ERROR,
6109 p_message_text => NULL,
6110 p_error_text => lv_error_text,
6111 p_debug => v_debug,
6112 p_batch_id => lv_batch_id );
6113
6114 IF lv_return <> 0 THEN
6115 RAISE ex_logging_err;
6116 END IF;
6117
6118 v_sql_stmt := 09;
6119
6120 -- bug# 3807591 (code is moved to MSCCLBAB.pls)
6121 /* lv_sql_stmt :=
6122 ' INSERT INTO MSC_DEMAND_CLASSES '
6123 ||' ( DEMAND_CLASS, '
6124 ||' MEANING, '
6125 ||' DESCRIPTION, '
6126 ||' FROM_DATE, '
6127 ||' TO_DATE, '
6128 ||' ENABLED_FLAG, '
6129 ||' SR_INSTANCE_ID, '
6130 ||' LAST_UPDATE_DATE, '
6131 ||' LAST_UPDATED_BY, '
6132 ||' CREATION_DATE, '
6133 ||' CREATED_BY) '
6134 ||' SELECT distinct '
6135 ||' mstd.demand_class,'
6136 ||' mstd.meaning,'
6137 ||' mstd.description,'
6138 ||' mstd.from_date,'
6139 ||' mstd.to_date,'
6140 ||' mstd.enabled_flag,'
6141 || v_instance_id ||','
6142 ||' mstd.last_update_date,'
6143 ||' mstd.last_updated_by,'
6144 ||' mstd.creation_date,'
6145 ||' mstd.created_by '
6146 ||' FROM MSC_ST_DEMAND_CLASSES mstd'
6147 ||' WHERE mstd.batch_id = :lv_batch_id'
6148 ||' AND mstd.sr_instance_code = :v_instance_code'
6149 ||' AND mstd.process_flag = '||G_VALID ;
6150
6151 IF V_DEBUG THEN
6152 msc_st_util.log_message(lv_sql_stmt);
6153 END IF;
6154
6155 EXECUTE IMMEDIATE lv_sql_stmt
6156 USING lv_batch_id,
6157 v_instance_code; */
6158
6159 COMMIT;
6160
6161 -- ODP change
6162 -- Call the procedure to insert categories into msd_st_level_values
6163 IF(v_install_msd) THEN
6164
6165 lv_sql_stmt := ' DECLARE errbuf varchar2(250);'
6166 ||' retcode number ;'
6167 || ' BEGIN '
6168 ||' MSD_CL_PRE_PROCESS.LOAD_DEMAND_CLASS'
6169 ||' (ERRBUF => errbuf ,'
6170 ||' RETCODE => retcode ,'
6171 ||' p_instance_code => :v_instance_code, '
6172 ||' p_instance_id => :v_instance_id,'
6173 ||' p_batch_id => :lv_batch_id);'
6174 ||' IF ( retcode = '||G_WARNING||') THEN'
6175 ||' MSC_CL_PRE_PROCESS.v_flag := '||SYS_YES||';'
6176 ||' END IF;'
6177 ||' END ;';
6178
6179
6180 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
6181
6182
6183 EXECUTE IMMEDIATE lv_sql_stmt
6184 USING v_instance_code,
6185 v_instance_id,
6186 lv_batch_id;
6187
6188 END IF ;
6189
6190 COMMIT;
6191
6192 END LOOP;
6193
6194 EXCEPTION
6195
6196 WHEN ex_logging_err THEN
6197 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
6198
6199 ROLLBACK;
6200
6201 WHEN OTHERS THEN
6202 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_DEMAND_CLASS '||'('
6203 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
6204 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
6205
6206 ROLLBACK;
6207
6208 END LOAD_DEMAND_CLASS ;
6209
6210
6211 /*==========================================================================+
6212 | DESCRIPTION : This function performs the validation and loads the data |
6213 | for business object trading partners |
6214 +==========================================================================*/
6215 PROCEDURE LOAD_TRADING_PARTNERS IS
6216 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
6217 lb_rowid RowidTab; --bulk collects rowid
6218 lv_return NUMBER;
6219 lv_batch_id NUMBER;
6220 lv_error_text VARCHAR2(250);
6221 lv_where_str VARCHAR2(5000);
6222 lv_sql_stmt VARCHAR2(5000);
6223 lv_column_names VARCHAR2(5000); --stores concatenated column names
6224 lv_message_text msc_errors.error_text%TYPE;
6225 lv_my_company msc_companies.company_name%TYPE;
6226 lv_user_id NUMBER;
6227
6228 TYPE CharTblTyp IS TABLE OF VARCHAR2(240);
6229 TYPE NumTblTyp IS TABLE OF NUMBER;
6230 TYPE DateTblTyp IS TABLE OF DATE;
6231 lb_GROUP_ID NumTblTyp;
6232 lb_GROUP_NAME CharTblTyp;
6233 lb_DESCRIPTION CharTblTyp;
6234 lb_GROUP_TYPE NumTblTyp;
6235 lb_GROUP_OWNER_ID NumTblTyp;
6236 lb_CONTACT_USER_NAME CharTblTyp;
6237 lb_CONTACT_USER_ID NumTblTyp;
6238 lb_CONTRACT_DOC_URL CharTblTyp;
6239 lb_EFFECTIVE_DATE DateTblTyp;
6240 lb_DISABLE_DATE DateTblTyp;
6241 lb_CONTEXT CharTblTyp;
6242 lb_ATTRIBUTE1 CharTblTyp;
6243 lb_ATTRIBUTE2 CharTblTyp;
6244 lb_ATTRIBUTE3 CharTblTyp;
6245 lb_ATTRIBUTE4 CharTblTyp;
6246 lb_ATTRIBUTE5 CharTblTyp;
6247 lb_ATTRIBUTE6 CharTblTyp;
6248 lb_ATTRIBUTE7 CharTblTyp;
6249 lb_ATTRIBUTE8 CharTblTyp;
6250 lb_ATTRIBUTE9 CharTblTyp;
6251 lb_ATTRIBUTE10 CharTblTyp;
6252 lb_ATTRIBUTE11 CharTblTyp;
6253 lb_ATTRIBUTE12 CharTblTyp;
6254 lb_ATTRIBUTE13 CharTblTyp;
6255 lb_ATTRIBUTE14 CharTblTyp;
6256 lb_ATTRIBUTE15 CharTblTyp;
6257 lb_OWNER_CONTACT CharTblTyp;
6258 lb_LAST_UPDATE_DATE DateTblTyp;
6259 lb_LAST_UPDATED_BY CharTblTyp;
6260 lb_LAST_UPDATE_LOGIN CharTblTyp;
6261 lb_COMPANY_ID NumTblTyp;
6262
6263
6264 ex_logging_err EXCEPTION;
6265
6266 CURSOR c1(p_batch_id NUMBER) IS
6267 SELECT rowid
6268 FROM msc_st_trading_partners
6269 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
6270 AND sr_instance_code = v_instance_code
6271 AND batch_id = p_batch_id;
6272
6273 CURSOR c2(p_batch_id NUMBER) IS
6274 SELECT rowid
6275 FROM msc_st_trading_partners
6276 WHERE process_flag = G_IN_PROCESS
6277 AND sr_instance_code = v_instance_code
6278 AND batch_id = p_batch_id
6279 AND NVL(sr_tp_id,NULL_VALUE) = NULL_VALUE
6280 AND deleted_flag = SYS_NO;
6281
6282 CURSOR c3(p_batch_id NUMBER) IS
6283 SELECT rowid
6284 FROM msc_st_trading_partner_sites
6285 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
6286 AND sr_instance_code = v_instance_code
6287 AND batch_id = p_batch_id;
6288
6289 CURSOR c4(p_batch_id NUMBER) IS
6290 SELECT rowid
6291 FROM msc_st_trading_partner_sites
6292 WHERE process_flag = G_IN_PROCESS
6293 AND sr_instance_code = v_instance_code
6294 AND batch_id = p_batch_id
6295 AND NVL(sr_tp_site_id,NULL_VALUE) = NULL_VALUE
6296 AND partner_type IN (1,2)
6297 AND deleted_flag = SYS_NO;
6298
6299 CURSOR c5(p_batch_id NUMBER) IS
6300 SELECT rowid
6301 FROM msc_st_sub_inventories
6302 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
6303 AND sr_instance_code = v_instance_code
6304 AND batch_id = p_batch_id;
6305
6306 CURSOR c6(p_batch_id NUMBER) IS
6307 SELECT rowid
6308 FROM msc_st_location_associations
6309 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
6310 AND sr_instance_code = v_instance_code
6311 AND batch_id = p_batch_id;
6312
6313 CURSOR c7(p_batch_id NUMBER) IS
6314 SELECT max(rowid)
6315 FROM msc_st_trading_partner_sites
6316 WHERE process_flag = G_IN_PROCESS
6317 AND deleted_flag = SYS_NO
6318 AND NVL(sr_tp_site_id,NULL_VALUE) = NULL_VALUE
6319 AND partner_type = 3
6320 AND sr_instance_code = v_instance_code
6321 AND batch_id = p_batch_id
6322 GROUP BY location;
6323
6324 CURSOR c8(p_batch_id NUMBER) IS
6325 SELECT rowid
6326 FROM msc_st_partner_contacts
6327 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
6328 AND sr_instance_code = v_instance_code
6329 AND batch_id = p_batch_id;
6330
6331 CURSOR c9(p_batch_id NUMBER) IS
6332 SELECT rowid
6333 FROM MSC_ST_GROUPS
6334 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
6335 AND batch_id = p_batch_id
6336 AND sr_instance_code = v_instance_code;
6337
6338 CURSOR c10(p_batch_id NUMBER) IS
6339 SELECT rowid
6340 FROM MSC_ST_GROUPS
6341 WHERE process_flag = G_IN_PROCESS
6342 AND sr_instance_code = v_instance_code
6343 AND batch_id = p_batch_id
6344 AND NVL(group_id,NULL_VALUE) = NULL_VALUE;
6345
6346 CURSOR c11(p_batch_id NUMBER) IS
6347 SELECT
6348 msg.GROUP_ID,
6349 msg.GROUP_NAME,
6350 msg.DESCRIPTION,
6351 msg.GROUP_TYPE,
6352 msg.GROUP_OWNER_ID,
6353 msg.CONTACT_USER_ID,
6354 msg.CONTRACT_DOC_URL,
6355 msg.EFFECTIVE_DATE,
6356 msg.DISABLE_DATE,
6357 msg.LAST_UPDATE_DATE,
6358 msg.LAST_UPDATED_BY,
6359 msg.LAST_UPDATE_LOGIN,
6360 msg.CONTEXT,
6361 msg.ATTRIBUTE1,
6362 msg.ATTRIBUTE2,
6363 msg.ATTRIBUTE3,
6364 msg.ATTRIBUTE4,
6365 msg.ATTRIBUTE5,
6366 msg.ATTRIBUTE6,
6367 msg.ATTRIBUTE7,
6368 msg.ATTRIBUTE8,
6369 msg.ATTRIBUTE9,
6370 msg.ATTRIBUTE10,
6371 msg.ATTRIBUTE11,
6372 msg.ATTRIBUTE12,
6373 msg.ATTRIBUTE13,
6374 msg.ATTRIBUTE14,
6375 msg.ATTRIBUTE15
6376 FROM msc_st_groups msg,msc_groups mg
6377 WHERE msg.process_flag = G_VALID
6378 AND msg.sr_instance_code = v_instance_code
6379 AND msg.batch_id = p_batch_id
6380 AND msg.group_id = mg.group_id;
6381
6382 --------
6383 CURSOR c12(p_batch_id NUMBER) IS
6384 SELECT rowid
6385 FROM msc_st_group_companies
6386 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
6387 AND sr_instance_code = v_instance_code
6388 AND batch_id = p_batch_id;
6389
6390 CURSOR c13(p_batch_id NUMBER) IS
6391 SELECT msg.group_id,
6392 msg.company_id,
6393 msg.CONTACT_USER_ID,
6394 msg.EFFECTIVE_DATE,
6395 msg.DISABLE_DATE,
6396 msg.CONTEXT,
6397 msg.ATTRIBUTE1,
6398 msg.ATTRIBUTE2,
6399 msg.ATTRIBUTE3,
6400 msg.ATTRIBUTE4,
6401 msg.ATTRIBUTE5,
6402 msg.ATTRIBUTE6,
6403 msg.ATTRIBUTE7,
6404 msg.ATTRIBUTE8,
6405 msg.ATTRIBUTE9,
6406 msg.ATTRIBUTE10,
6407 msg.ATTRIBUTE11,
6408 msg.ATTRIBUTE12,
6409 msg.ATTRIBUTE13,
6410 msg.ATTRIBUTE14,
6411 msg.ATTRIBUTE15
6412 FROM msc_st_group_companies msg,msc_group_companies mg
6413 WHERE msg.process_flag = G_VALID
6414 AND msg.sr_instance_code = v_instance_code
6415 AND msg.batch_id = p_batch_id
6416 AND msg.group_id = mg.group_id
6417 AND msg.company_id = mg.company_id;
6418
6419 ----
6420
6421 CURSOR c14(p_batch_id NUMBER) IS
6422 SELECT max(rowid)
6423 FROM msc_st_location_associations
6424 WHERE process_flag = G_IN_PROCESS
6425 AND deleted_flag = SYS_NO
6426 AND NVL(location_id,NULL_VALUE) = NULL_VALUE
6427 AND sr_instance_code = v_instance_code
6428 AND batch_id = p_batch_id
6429 GROUP BY location_code;
6430
6431 CURSOR c15(p_batch_id NUMBER) IS
6432 SELECT max(rowid)
6433 FROM msc_st_trading_partner_sites
6434 WHERE process_flag = G_IN_PROCESS
6435 AND deleted_flag = SYS_NO
6436 AND NVL(location_id,NULL_VALUE) = NULL_VALUE
6437 AND partner_type = 2
6438 AND sr_instance_code = v_instance_code
6439 AND batch_id = p_batch_id
6440 GROUP BY location;
6441
6442 BEGIN
6443
6444 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
6445 (p_app_short_name => 'MSC',
6446 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
6447 p_message_text => lv_message_text,
6448 p_error_text => lv_error_text);
6449
6450 IF lv_return <> 0 THEN
6451 RAISE ex_logging_err;
6452 END IF;
6453
6454 --Validation check for the table MSC_ST_TRADING_PARTNERS
6455
6456 --Duplicate records check for the records whose source is other than XML
6457 --Different SQL is used because in XML we can identify the latest records
6458 --whereas in batch load we cannot.
6459
6460 v_sql_stmt := 01;
6461 lv_sql_stmt :=
6462 'UPDATE msc_st_trading_partners mstp1 '
6463 ||' SET process_flag = '||G_ERROR_FLG||','
6464 ||' error_text = '||''''||lv_message_text||''''
6465 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_trading_partners mstp2 '
6466 ||' WHERE mstp2.sr_instance_code = mstp1.sr_instance_code'
6467 ||' AND NVL(mstp2.company_name, '||''''||NULL_CHAR||''''||') = '
6468 ||' NVL(mstp1.company_name, '||''''||NULL_CHAR||''''||')'
6469 ||' AND mstp2.partner_name = mstp1.partner_name'
6470 ||' AND mstp2.partner_type = mstp1.partner_type'
6471 ||' AND mstp2.cust_account_number = mstp1.cust_account_number'
6472 ||' AND mstp2.process_flag = mstp1.process_flag'
6473 ||' AND NVL(mstp2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
6474 ||' GROUP BY sr_instance_code,company_name,partner_name,partner_type,cust_account_number '
6475 ||' HAVING COUNT(*) >1 )'
6476 ||' AND mstp1.process_flag = '||G_IN_PROCESS
6477 -- ssurendr - bug 2647423: partner name should be unique for orgs as well.
6478 --||' AND mstp1.partner_type <>'||G_ORGANIZATION
6479 ||' AND mstp1.sr_instance_code = :v_instance_code'
6480 ||' AND NVL(mstp1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
6481
6482
6483 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
6484
6485
6486 EXECUTE IMMEDIATE lv_sql_stmt
6487 USING v_instance_code;
6488
6489
6490 IF v_MSC_CONFIGURATION = 3 THEN -- For SCE Standalone add company in udk
6491 v_sql_stmt := 02;
6492 lv_sql_stmt :=
6493 'UPDATE msc_st_trading_partners mstp1 '
6494 ||' SET process_flag = '||G_ERROR_FLG||','
6495 ||' error_text = '||''''||lv_message_text||''''
6496 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_trading_partners mstp2 '
6497 ||' WHERE mstp2.sr_instance_code = mstp1.sr_instance_code'
6498 ||' AND NVL(mstp2.company_name, '||''''||NULL_CHAR||''''||') = '
6499 ||' NVL(mstp1.company_name, '||''''||NULL_CHAR||''''||')'
6500 ||' AND mstp2.organization_code = mstp1.organization_code'
6501 ||' AND mstp2.partner_type = mstp1.partner_type'
6502 ||' AND mstp2.process_flag = mstp1.process_flag'
6503 ||' AND NVL(mstp2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
6504 ||' GROUP BY sr_instance_code,company_name,organization_code,partner_type '
6505 -- ||' GROUP BY sr_instance_code,organization_code,partner_type '
6506 ||' HAVING COUNT(*) >1 )'
6507 ||' AND mstp1.process_flag = '||G_IN_PROCESS
6508 ||' AND mstp1.partner_type = '||G_ORGANIZATION
6509 ||' AND mstp1.sr_instance_code = :v_instance_code'
6510 ||' AND NVL(mstp1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
6511
6512 ELSE
6513 v_sql_stmt := 02;
6514 lv_sql_stmt :=
6515 'UPDATE msc_st_trading_partners mstp1 '
6516 ||' SET process_flag = '||G_ERROR_FLG||','
6517 ||' error_text = '||''''||lv_message_text||''''
6518 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_trading_partners mstp2 '
6519 ||' WHERE mstp2.sr_instance_code = mstp1.sr_instance_code'
6520 -- ||' AND NVL(mstp2.company_name, '||''''||NULL_CHAR||''''||') = '
6521 -- ||' NVL(mstp1.company_name, '||''''||NULL_CHAR||''''||')'
6522 ||' AND mstp2.organization_code = mstp1.organization_code'
6523 ||' AND mstp2.partner_type = mstp1.partner_type'
6524 ||' AND mstp2.process_flag = mstp1.process_flag'
6525 ||' AND NVL(mstp2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
6526 -- ||' GROUP BY sr_instance_code,company_name,organization_code,partner_type '
6527 ||' GROUP BY sr_instance_code,organization_code,partner_type '
6528 ||' HAVING COUNT(*) >1 )'
6529 ||' AND mstp1.process_flag = '||G_IN_PROCESS
6530 ||' AND mstp1.partner_type = '||G_ORGANIZATION
6531 ||' AND mstp1.sr_instance_code = :v_instance_code'
6532 ||' AND NVL(mstp1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
6533 END IF;
6534
6535
6536 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
6537
6538
6539 EXECUTE IMMEDIATE lv_sql_stmt
6540 USING v_instance_code;
6541
6542
6543
6544 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
6545 (p_app_short_name => 'MSC',
6546 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
6547 p_message_text => lv_message_text,
6548 p_error_text => lv_error_text);
6549
6550 IF lv_return <> 0 THEN
6551 RAISE ex_logging_err;
6552 END IF;
6553
6554 --Duplicate records check for the records whose source is XML
6555 v_sql_stmt := 03;
6556 lv_sql_stmt :=
6557 'UPDATE msc_st_trading_partners mstp1 '
6558 ||' SET process_flag = '||G_ERROR_FLG||','
6559 ||' error_text = '||''''||lv_message_text||''''
6560 ||' WHERE message_id < ( SELECT max(message_id) '
6561 ||' FROM msc_st_trading_partners mstp2'
6562 ||' WHERE mstp2.sr_instance_code = mstp1.sr_instance_code'
6563 ||' AND NVL(mstp2.company_name, '||''''||NULL_CHAR||''''||') = '
6564 ||' NVL(mstp1.company_name, '||''''||NULL_CHAR||''''||')'
6565 ||' AND mstp2.partner_name = mstp1.partner_name'
6566 ||' AND mstp2.partner_type = mstp1.partner_type'
6567 ||' AND mstp2.cust_account_number = mstp1.cust_account_number'
6568 ||' AND mstp2.process_flag = mstp1.process_flag'
6569 ||' AND mstp2.process_flag = '||G_IN_PROCESS
6570 ||' AND NVL(mstp2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
6571 ||' AND mstp1.process_flag = '||G_IN_PROCESS
6572 -- ssurendr - bug 2647423: partner name should be unique for orgs as well.
6573 --||' AND mstp1.partner_type <> '||G_ORGANIZATION
6574 ||' AND mstp1.sr_instance_code = :v_instance_code '
6575 ||' AND NVL(mstp1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
6576
6577
6578 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
6579
6580
6581 EXECUTE IMMEDIATE lv_sql_stmt
6582 USING v_instance_code;
6583
6584 v_sql_stmt := 04;
6585 lv_sql_stmt :=
6586 'UPDATE msc_st_trading_partners mstp1 '
6587 ||' SET process_flag = '||G_ERROR_FLG||','
6588 ||' error_text = '||''''||lv_message_text||''''
6589 ||' WHERE message_id < ( SELECT max(message_id) '
6590 ||' FROM msc_st_trading_partners mstp2'
6591 ||' WHERE mstp2.sr_instance_code = mstp1.sr_instance_code'
6592 -- ||' AND NVL(mstp2.company_name, '||''''||NULL_CHAR||''''||') = '
6593 -- ||' NVL(mstp1.company_name, '||''''||NULL_CHAR||''''||')'
6594 ||' AND mstp2.organization_code = mstp1.organization_code'
6595 ||' AND mstp2.partner_type = mstp1.partner_type'
6596 ||' AND mstp2.process_flag = mstp1.process_flag'
6597 ||' AND mstp2.process_flag = '||G_IN_PROCESS
6598 ||' AND NVL(mstp2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
6599 ||' AND mstp1.process_flag = '||G_IN_PROCESS
6600 ||' AND mstp1.partner_type = '||G_ORGANIZATION
6601 ||' AND mstp1.sr_instance_code = :v_instance_code '
6602 ||' AND NVL(mstp1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
6603
6604
6605 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
6606
6607
6608 EXECUTE IMMEDIATE lv_sql_stmt
6609 USING v_instance_code;
6610
6611 lv_column_names :=
6612 'PARTNER_TYPE ||''~''||'
6613 ||'PARTNER_NAME ||''~''||'
6614 ||'SR_INSTANCE_CODE ||''~''||'
6615 ||'ORGANIZATION_CODE ||''~''||'
6616 ||'DISABLE_DATE ||''~''||'
6617 ||'STATUS ||''~''||'
6618 ||'MASTER_ORGANIZATION ||''~''||'
6619 ||'PARTNER_NUMBER ||''~''||'
6620 ||'CALENDAR_CODE ||''~''||'
6621 ||'MAXIMUM_WEIGHT ||''~''||'
6622 ||'MAXIMUM_VOLUME ||''~''||'
6623 ||'WEIGHT_UOM ||''~''||'
6624 ||'VOLUME_UOM ||''~''||'
6625 ||'PROJECT_REFERENCE_ENABLED ||''~''||'
6626 ||'PROJECT_CONTROL_LEVEL ||''~''||'
6627 ||'DEMAND_LATENESS_COST ||''~''||'
6628 ||'SUPPLIER_CAP_OVERUTIL_COST ||''~''||'
6629 ||'RESOURCE_CAP_OVERUTIL_COST ||''~''||'
6630 ||'TRANSPORT_CAP_OVER_UTIL_COST||''~''||'
6631 ||'USE_PHANTOM_ROUTINGS ||''~''||'
6632 ||'INHERIT_PHANTOM_OP_SEQ ||''~''||'
6633 ||'DEFAULT_ATP_RULE_NAME ||''~''||'
6634 ||'DEFAULT_DEMAND_CLASS ||''~''||'
6635 ||'MATERIAL_ACCOUNT ||''~''||'
6636 ||'EXPENSE_ACCOUNT ||''~''||'
6637 ||'ORGANIZATION_TYPE ||''~''||'
6638 ||'SERVICE_LEVEL ||''~''||'
6639 ||'COMPANY_NAME ||''~''||'
6640 ||'CALENDAR_EXCEPTION_SET_ID ||''~''||'
6641 ||'DELETED_FLAG';
6642
6643 -- Dividing records in batches based on batchsize
6644 LOOP
6645 v_sql_stmt := 05;
6646 SELECT msc_st_batch_id_s.NEXTVAL
6647 INTO lv_batch_id
6648 FROM DUAL;
6649
6650 v_sql_stmt := 06;
6651 lv_sql_stmt :=
6652 'UPDATE msc_st_trading_partners '
6653 ||' SET batch_id = :lv_batch_id '
6654 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
6655 ||' AND sr_instance_code = :v_instance_code'
6656 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
6657 ||' AND rownum <= '||v_batch_size;
6658
6659
6660 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
6661
6662
6663 EXECUTE IMMEDIATE lv_sql_stmt
6664 USING lv_batch_id,
6665 v_instance_code;
6666
6667 EXIT WHEN SQL%NOTFOUND ;
6668
6669 OPEN c1(lv_batch_id);
6670 FETCH c1 BULK COLLECT INTO lb_rowid;
6671 CLOSE c1;
6672
6673 v_sql_stmt := 07;
6674 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
6675 UPDATE msc_st_trading_partners
6676 SET st_transaction_id = msc_st_trading_partners_s.NEXTVAL,
6677 refresh_id = v_refresh_id,
6678 last_update_date = v_current_date,
6679 last_updated_by = v_current_user,
6680 creation_date = v_current_date,
6681 created_by = v_current_user
6682 WHERE rowid = lb_rowid(j);
6683
6684 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
6685 (p_app_short_name => 'MSC',
6686 p_error_code => 'MSC_PP_NO_DELETION',
6687 p_message_text => lv_message_text,
6688 p_error_text => lv_error_text,
6689 p_token1 => 'TABLE_NAME',
6690 p_token_value1 => 'MSC_ST_TRADING_PARTNERS');
6691
6692 -- Deletion is not allowed for this table
6693 v_sql_stmt := 08;
6694 lv_sql_stmt :=
6695 'UPDATE msc_st_trading_partners '
6696 ||' SET process_flag = '||G_ERROR_FLG||','
6697 ||' error_text = '||''''||lv_message_text||''''
6698 ||' WHERE deleted_flag = '||SYS_YES
6699 ||' AND process_flag = '||G_IN_PROCESS
6700 ||' AND batch_id = :lv_batch_id'
6701 ||' AND sr_instance_code = :v_instance_code';
6702
6703
6704 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
6705
6706
6707 EXECUTE IMMEDIATE lv_sql_stmt
6708 USING lv_batch_id,
6709 v_instance_code;
6710
6711 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
6712 (p_app_short_name => 'MSC',
6713 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
6714 p_message_text => lv_message_text,
6715 p_error_text => lv_error_text,
6716 p_token1 => 'COLUMN_NAME',
6717 p_token_value1 => 'DELETED_FLAG',
6718 p_token2 => 'DEFAULT_VALUE',
6719 p_token_value2 => SYS_NO);
6720
6721 IF lv_return <> 0 THEN
6722 RAISE ex_logging_err;
6723 END IF;
6724
6725 -- Check DELETE_FLAG column has valid value or not and if not set it to SYS_NO
6726 -- Log error procedure inserts warning and also defaults the delete flag
6727
6728 lv_where_str := ' AND NVL(deleted_flag,'||NULL_VALUE||') '
6729 ||' NOT IN(1,2)';
6730
6731 lv_return := MSC_ST_UTIL.LOG_ERROR
6732 (p_table_name => 'MSC_ST_TRADING_PARTNERS',
6733 p_instance_code => v_instance_code,
6734 p_row => lv_column_names,
6735 p_severity => G_SEV_WARNING,
6736 p_message_text => lv_message_text,
6737 p_error_text => lv_error_text,
6738 p_batch_id => lv_batch_id,
6739 p_where_str => lv_where_str,
6740 p_col_name => 'DELETED_FLAG',
6741 p_debug => v_debug,
6742 p_default_value => SYS_NO);
6743
6744 IF lv_return <> 0 THEN
6745 RAISE ex_logging_err;
6746 END IF;
6747
6748 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
6749 (p_app_short_name => 'MSC',
6750 p_error_code => 'MSC_PP_COL_VAL_NULL',
6751 p_message_text => lv_message_text,
6752 p_error_text => lv_error_text,
6753 p_token1 => 'COLUMN_NAME',
6754 p_token_value1 => 'PARTNER_NAME');
6755
6756 IF lv_return <> 0 THEN
6757 RAISE ex_logging_err;
6758 END IF;
6759
6760 -- Error out records where partner_name is NULL
6761 v_sql_stmt := 09;
6762 lv_sql_stmt :=
6763 'UPDATE msc_st_trading_partners'
6764 ||' SET process_flag = '||G_ERROR_FLG||','
6765 ||' error_text = '||''''||lv_message_text||''''
6766 ||' WHERE NVL(partner_name, '||''''||NULL_CHAR||''''||') '
6767 ||' = '||''''||NULL_CHAR||''''
6768 ||' AND batch_id = :lv_batch_id'
6769 ||' AND process_flag = '||G_IN_PROCESS
6770 ||' AND sr_instance_code = :v_instance_code';
6771
6772
6773 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
6774
6775 EXECUTE IMMEDIATE lv_sql_stmt
6776 USING lv_batch_id,
6777 v_instance_code;
6778
6779
6780 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
6781 (p_app_short_name => 'MSC',
6782 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
6783 p_message_text => lv_message_text,
6784 p_error_text => lv_error_text,
6785 p_token1 => 'COLUMN_NAME',
6786 p_token_value1 => 'PARTNER_TYPE');
6787
6788 IF lv_return <> 0 THEN
6789 RAISE ex_logging_err;
6790 END IF;
6791
6792 -- Error out records where partner_type NOT in (1,2,3,4)
6793 v_sql_stmt := 10;
6794 lv_sql_stmt :=
6795 'UPDATE msc_st_trading_partners'
6796 ||' SET process_flag = '||G_ERROR_FLG||','
6797 ||' error_text = '||''''||lv_message_text||''''
6798 ||' WHERE sr_instance_code = :v_instance_code'
6799 ||' AND batch_id = :lv_batch_id'
6800 ||' AND process_flag = '||G_IN_PROCESS
6801 ||' AND partner_type NOT IN (1,2,3,4)' ;
6802
6803
6804 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
6805
6806 EXECUTE IMMEDIATE lv_sql_stmt
6807 USING v_instance_code,
6808 lv_batch_id;
6809
6810
6811 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
6812 (p_app_short_name => 'MSC',
6813 p_error_code => 'MSC_PP_COL_VAL_NULL',
6814 p_message_text => lv_message_text,
6815 p_error_text => lv_error_text,
6816 p_token1 => 'COLUMN_NAME',
6817 p_token_value1 => 'ORGANIZATION_CODE');
6818
6819 IF lv_return <> 0 THEN
6820 RAISE ex_logging_err;
6821 END IF;
6822
6823 -- Error out records where organization_code is NULL for partner_type = 3
6824 v_sql_stmt := 11;
6825 lv_sql_stmt :=
6826 'UPDATE msc_st_trading_partners '
6827 ||' SET process_flag = '||G_ERROR_FLG||','
6828 ||' error_text = '||''''||lv_message_text||''''
6829 ||' WHERE sr_instance_code = :v_instance_code'
6830 ||' AND batch_id = :lv_batch_id'
6831 ||' AND process_flag = '||G_IN_PROCESS
6832 ||' AND NVL(organization_code, '||''''||NULL_CHAR||''''||')'
6833 ||' = '||''''||NULL_CHAR||''''
6834 ||' AND partner_type ='||G_ORGANIZATION;
6835
6836
6837 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
6838
6839 EXECUTE IMMEDIATE lv_sql_stmt
6840 USING v_instance_code,
6841 lv_batch_id;
6842
6843 --- changes for SRP
6844
6845 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
6846 (p_app_short_name => 'MSC',
6847 p_error_code => 'MSC_PP_INVALID_VALUE',
6848 p_message_text => lv_message_text,
6849 p_error_text => lv_error_text,
6850 p_token1 => 'COLUMN_NAME',
6851 p_token_value1 => 'RESOURCE_TYPE');
6852
6853 -- Resource type validation
6854 v_sql_stmt := 11.1;
6855 lv_sql_stmt :=
6856 'UPDATE msc_st_trading_partners '
6857 ||' SET process_flag = '||G_ERROR_FLG||','
6858 ||' error_text = '||''''||lv_message_text||''''
6859 ||' WHERE process_flag = '||G_IN_PROCESS
6860 ||' AND batch_id = :lv_batch_id'
6861 ||' AND sr_instance_code = :v_instance_code'
6862 ||' AND partner_type = 2'
6863 ||' AND (resource_type IS NOT NULL AND resource_type <>1)';
6864
6865
6866 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
6867
6868
6869 EXECUTE IMMEDIATE lv_sql_stmt
6870 USING lv_batch_id,
6871 v_instance_code;
6872
6873 v_sql_stmt := 11.2;
6874 lv_sql_stmt :=
6875 'UPDATE msc_st_trading_partners '
6876 ||' SET RESOURCE_TYPE ='''''
6877 ||' WHERE process_flag = '||G_IN_PROCESS
6878 ||' AND batch_id = :lv_batch_id'
6879 ||' AND sr_instance_code = :v_instance_code'
6880 ||' AND PARTNER_TYPE in (1,3,4) '
6881 ||' AND (resource_type is not null and resource_type <>1)';
6882
6883
6884 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
6885
6886
6887 EXECUTE IMMEDIATE lv_sql_stmt
6888 USING lv_batch_id,
6889 v_instance_code;
6890
6891 -- bug# 2385805: dont allow dup orgs to go through
6892 -- unless these belong to this company - to allow updation
6893 -- Bypass this check if it is SCE Standalone
6894
6895 IF v_MSC_CONFIGURATION <> 3 THEN
6896 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
6897 (p_app_short_name => 'MSC',
6898 p_error_code => 'MSC_PP_INVALID_VALUE',
6899 p_message_text => lv_message_text,
6900 p_error_text => lv_error_text,
6901 p_token1 => 'COLUMN_NAME',
6902 p_token_value1 => 'ORGANIZATION_CODE');
6903
6904 IF lv_return <> 0 THEN
6905 RAISE ex_logging_err;
6906 END IF;
6907
6908 UPDATE msc_st_trading_partners mstp
6909 SET process_flag = G_ERROR_FLG,
6910 error_text = lv_message_text
6911 WHERE mstp.process_flag = G_IN_PROCESS
6912 AND mstp.sr_instance_code = v_instance_code
6913 AND mstp.batch_id = lv_batch_id
6914 AND mstp.partner_type = G_ORGANIZATION
6915 AND EXISTS -- check against those orgs which do not belong to this company
6916 (SELECT mtp.organization_code from msc_trading_partners mtp
6917 WHERE mstp.organization_code = mtp.organization_code
6918 AND mtp.sr_instance_id = v_instance_id
6919 AND mtp.partner_type = G_ORGANIZATION
6920 MINUS
6921 SELECT mlis.char3 from msc_local_id_setup mlis
6922 WHERE mlis.entity_name = 'SR_TP_ID'
6923 AND mlis.char1 = mstp.sr_instance_code
6924 AND mlis.number1 = mstp.partner_type
6925 AND nvl(mlis.char2, NULL_CHAR) = nvl(mstp.company_name,NULL_CHAR));
6926 END IF;
6927
6928
6929 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
6930 (p_app_short_name => 'MSC',
6931 p_error_code => 'MSC_PP_COL_VAL_NULL',
6932 p_message_text => lv_message_text,
6933 p_error_text => lv_error_text,
6934 p_token1 => 'COLUMN_NAME',
6935 p_token_value1 => 'CALENDAR_CODE');
6936
6937 IF lv_return <> 0 THEN
6938 RAISE ex_logging_err;
6939 END IF;
6940
6941 -- Error out records where calendar_code is NULL for partner_type = 3
6942 -- This validation is not required if MSC not installed(ODP standalone)
6943
6944 IF (v_install_msc) THEN
6945 v_sql_stmt := 11;
6946 lv_sql_stmt :=
6947 'UPDATE msc_st_trading_partners '
6948 ||' SET process_flag = '||G_ERROR_FLG||','
6949 ||' error_text = '||''''||lv_message_text||''''
6950 ||' WHERE sr_instance_code = :v_instance_code'
6951 ||' AND batch_id = :lv_batch_id'
6952 ||' AND process_flag = '||G_IN_PROCESS
6953 ||' AND NVL(calendar_code, '||''''||NULL_CHAR||''''||')'
6954 ||' = '||''''||NULL_CHAR||''''
6955 ||' AND partner_type ='||G_ORGANIZATION;
6956
6957
6958 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
6959
6960 EXECUTE IMMEDIATE lv_sql_stmt
6961 USING v_instance_code,
6962 lv_batch_id;
6963
6964
6965 /* Bug 2172537 - Do not prefix the instance code
6966 -- Update all partner_name and calendar_code as instance_code concatenated with name
6967 -- Where partner_type = 3 (organization)
6968 v_sql_stmt := 12;
6969 lv_sql_stmt :=
6970 'UPDATE msc_st_trading_partners '
6971 ||' SET partner_name = sr_instance_code'||'||'':''||'||'partner_name,'
6972 ||' calendar_code = sr_instance_code'||'||'':''||'||'calendar_code'
6973 ||' WHERE partner_type = '||G_ORGANIZATION
6974 ||' AND sr_instance_code = :v_instance_code'
6975 ||' AND batch_id = :lv_batch_id'
6976 ||' AND process_flag = '||G_IN_PROCESS;
6977
6978 IF V_DEBUG THEN
6979 msc_st_util.log_message(lv_sql_stmt);
6980 END IF;
6981 EXECUTE IMMEDIATE lv_sql_stmt
6982 USING v_instance_code,
6983 lv_batch_id; */
6984
6985 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
6986 (p_app_short_name => 'MSC',
6987 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
6988 p_message_text => lv_message_text,
6989 p_error_text => lv_error_text,
6990 p_token1 => 'COLUMN_NAMES',
6991 p_token_value1 => 'SR_INSTANCE_ID AND CALENDAR_CODE',
6992 p_token2 => 'MASTER_TABLE',
6993 p_token_value2 => 'MSC_CALENDARS',
6994 p_token3 => 'CHILD_TABLE',
6995 p_token_value3 => 'MSC_ST_TRADING_PARTNERS');
6996 IF lv_return <> 0 THEN
6997 RAISE ex_logging_err;
6998 END IF;
6999
7000 -- Validate the calendar code for org
7001 v_sql_stmt := 14;
7002 lv_sql_stmt :=
7003 'UPDATE msc_st_trading_partners mstp'
7004 ||' SET process_flag = '||G_ERROR_FLG||','
7005 ||' error_text = '||''''||lv_message_text||''''
7006 ||' WHERE NOT EXISTS ( SELECT 1 '
7007 ||' FROM msc_calendars mc '
7008 ||' WHERE mc.calendar_code = mstp.calendar_code '
7009 ||' AND mc.sr_instance_id = :v_instance_id )'
7010 ||' AND partner_type = '||G_ORGANIZATION
7011 ||' AND sr_instance_code = :v_instance_code'
7012 ||' AND batch_id = :lv_batch_id'
7013 ||' AND process_flag = '||G_IN_PROCESS;
7014
7015
7016
7017 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
7018
7019 EXECUTE IMMEDIATE lv_sql_stmt
7020 USING v_instance_id,
7021 v_instance_code,
7022 lv_batch_id;
7023
7024 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
7025 (p_app_short_name => 'MSC',
7026 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
7027 p_message_text => lv_message_text,
7028 p_error_text => lv_error_text,
7029 p_token1 => 'COLUMN_NAME',
7030 p_token_value1 => 'CALENDAR_EXCEPTION_SET_ID');
7031
7032 IF lv_return <> 0 THEN
7033 RAISE ex_logging_err;
7034 END IF;
7035
7036 -- Default calendar exception set id as -1 always for legacy
7037 lv_where_str :=
7038 ' AND calendar_exception_set_id <> -1 '
7039 ||' AND partner_type = '||G_ORGANIZATION ;
7040
7041 lv_return := MSC_ST_UTIL.LOG_ERROR
7042 (p_table_name => 'MSC_ST_TRADING_PARTNERS',
7043 p_instance_code => v_instance_code,
7044 p_row => lv_column_names,
7045 p_severity => G_SEV_WARNING,
7046 p_message_text => lv_message_text,
7047 p_error_text => lv_error_text,
7048 p_batch_id => lv_batch_id,
7049 p_where_str => lv_where_str,
7050 p_col_name => 'CALENDAR_EXCEPTION_SET_ID',
7051 p_debug => v_debug,
7052 p_default_value => G_CAL_EXCEP_SET_ID);
7053
7054 IF lv_return <> 0 THEN
7055 RAISE ex_logging_err;
7056 END IF;
7057
7058
7059 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
7060 (p_app_short_name => 'MSC',
7061 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
7062 p_message_text => lv_message_text,
7063 p_error_text => lv_error_text,
7064 p_token1 => 'COLUMN_NAMES',
7065 p_token_value1 => 'SR_INSTANCE_CODE OR WEIGHT_UOM',
7066 p_token2 => 'MASTER_TABLE',
7067 p_token_value2 => 'MSC_ST_UNITS_OF_MEASURE',
7068 p_token3 => 'CHILD_TABLE',
7069 p_token_value3 => 'MSC_ST_TRADING_PARTNERS');
7070 IF lv_return <> 0 THEN
7071 RAISE ex_logging_err;
7072 END IF;
7073
7074 -- Validate all UOM code both Weight/Volume
7075 v_sql_stmt := 15;
7076 lv_sql_stmt :=
7077 'UPDATE msc_st_trading_partners mstp'
7078 ||' SET process_flag = '||G_ERROR_FLG||','
7079 ||' error_text = '||''''||lv_message_text||''''
7080 ||' WHERE NOT EXISTS(SELECT 1 '
7081 ||' FROM msc_units_of_measure muom '
7082 ||' WHERE NVL(muom.uom_code, '||''''||NULL_CHAR||''''||') = '
7083 ||' NVL(mstp.weight_uom,'||''''||NULL_CHAR||''''||')'
7084 ||' UNION '
7085 ||' SELECT 1 FROM msc_st_units_of_measure msuom'
7086 ||' WHERE NVL(msuom.uom_code, '||''''||NULL_CHAR||''''||') = '
7087 ||' NVL(mstp.weight_uom,'||''''||NULL_CHAR||''''||')'
7088 ||' AND msuom.sr_instance_id = :v_instance_id'
7089 ||' AND msuom.process_flag = '||G_VALID||' ) '
7090 ||' AND NVL(mstp.weight_uom,'||''''||NULL_CHAR||''''||') '
7091 ||' <> '||''''||NULL_CHAR||''''
7092 ||' AND partner_type = '||G_ORGANIZATION
7093 ||' AND mstp.sr_instance_code = :v_instance_code'
7094 ||' AND mstp.batch_id = :lv_batch_id'
7095 ||' AND mstp.process_flag = '||G_IN_PROCESS ;
7096
7097
7098
7099 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
7100
7101
7102 EXECUTE IMMEDIATE lv_sql_stmt
7103 USING v_instance_id,
7104 v_instance_code,
7105 lv_batch_id;
7106
7107 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
7108 (p_app_short_name => 'MSC',
7109 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
7110 p_message_text => lv_message_text,
7111 p_error_text => lv_error_text,
7112 p_token1 => 'COLUMN_NAMES',
7113 p_token_value1 => 'SR_INSTANCE_CODE OR VOLUME_UOM',
7114 p_token2 => 'MASTER_TABLE',
7115 p_token_value2 => 'MSC_ST_UNITS_OF_MEASURE',
7116 p_token3 => 'CHILD_TABLE',
7117 p_token_value3 => 'MSC_ST_TRADING_PARTNERS');
7118 IF lv_return <> 0 THEN
7119 RAISE ex_logging_err;
7120 END IF;
7121
7122 v_sql_stmt := 16;
7123 lv_sql_stmt :=
7124 'UPDATE msc_st_trading_partners mstp'
7125 ||' SET process_flag = '||G_ERROR_FLG||','
7126 ||' error_text = '||''''||lv_message_text||''''
7127 ||' WHERE NOT EXISTS(SELECT 1 '
7128 ||' FROM msc_units_of_measure muom'
7129 ||' WHERE NVL(muom.uom_code, '||''''||NULL_CHAR||''''||') = '
7130 ||' NVL(mstp.volume_uom,'||''''||NULL_CHAR||''''||')'
7131 ||' UNION '
7132 ||' SELECT 1 FROM msc_st_units_of_measure msuom'
7133 ||' WHERE NVL(msuom.uom_code,' ||''''||NULL_CHAR||''''||') = '
7134 ||' NVL(mstp.volume_uom,'||''''||NULL_CHAR||''''||')'
7135 ||' AND msuom.sr_instance_id = :v_instance_id'
7136 ||' AND msuom.process_flag = '||G_VALID||' )'
7137 ||' AND NVL(mstp.volume_uom,'||''''||NULL_CHAR||''''||')'
7138 ||' <> '||''''||NULL_CHAR||''''
7139 ||' AND mstp.partner_type ='||G_ORGANIZATION
7140 ||' AND mstp.sr_instance_code = :v_instance_code'
7141 ||' AND mstp.batch_id = :lv_batch_id'
7142 ||' AND mstp.process_flag = '||G_IN_PROCESS ;
7143
7144
7145 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
7146
7147
7148 EXECUTE IMMEDIATE lv_sql_stmt
7149 USING v_instance_id,
7150 v_instance_code,
7151 lv_batch_id;
7152
7153
7154 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
7155 (p_app_short_name => 'MSC',
7156 p_error_code => 'MSC_PP_INVALID_VALUE',
7157 p_message_text => lv_message_text,
7158 p_error_text => lv_error_text,
7159 p_token1 => 'COLUMN_NAME',
7160 p_token_value1 => 'COMPANY_NAME');
7161
7162 IF lv_return <> 0 THEN
7163 RAISE ex_logging_err;
7164 END IF;
7165
7166 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
7167 (p_app_short_name => 'MSC',
7168 p_error_code => 'MSC_PP_INVALID_VALUE',
7169 p_message_text => lv_message_text,
7170 p_error_text => lv_error_text,
7171 p_token1 => 'COLUMN_NAME',
7172 p_token_value1 => 'DEFAULT_DEMAND_CLASS');
7173
7174 IF lv_return <> 0 THEN
7175 RAISE ex_logging_err;
7176 END IF;
7177
7178
7179 -- Validate Demand Class, if value provided it should exists
7180 -- in ODS or staging table
7181
7182 lv_return :=
7183 MSC_ST_UTIL.VALIDATE_DMD_CLASS(p_table_name => 'MSC_ST_TRADING_PARTNERS',
7184 p_dmd_class_column => 'DEFAULT_DEMAND_CLASS',
7185 p_instance_id => v_instance_id,
7186 p_instance_code => v_instance_code,
7187 p_severity => G_SEV3_ERROR,
7188 p_message_text => lv_message_text,
7189 p_batch_id => lv_batch_id,
7190 p_debug => v_debug,
7191 p_error_text => lv_error_text);
7192
7193 if(lv_return <> 0) then
7194 RAISE ex_logging_err;
7195 end if;
7196
7197
7198 IF v_sce_installed THEN
7199 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
7200 (p_app_short_name => 'MSC',
7201 p_error_code => 'MSC_PP_INVALID_VALUE',
7202 p_message_text => lv_message_text,
7203 p_error_text => lv_error_text,
7204 p_token1 => 'COLUMN_NAME',
7205 p_token_value1 => 'COMPANY_NAME');
7206
7207 IF lv_return <> 0 THEN
7208 RAISE ex_logging_err;
7209 END IF;
7210
7211 --Derive company_id
7212 lv_return := MSC_ST_UTIL.DERIVE_COMPANY_ID
7213 (p_table_name => 'MSC_ST_TRADING_PARTNERS',
7214 p_company_name => 'COMPANY_NAME',
7215 p_company_id => 'COMPANY_ID',
7216 p_instance_code => v_instance_code,
7217 p_error_text => lv_error_text,
7218 p_batch_id => lv_batch_id,
7219 p_message_text => lv_message_text,
7220 p_debug => v_debug);
7221
7222
7223 IF lv_return <> 0 THEN
7224 RAISE ex_logging_err;
7225 END IF;
7226
7227 END IF;
7228
7229 /* Moved the code to MSCSUTLB.pls
7230
7231 --Modified to fix the bug#2336975
7232
7233 IF v_sce_installed THEN
7234 lv_my_company := GET_MY_COMPANY;
7235 -- if record is for OEM's partners, company name will be null or 'My Company'
7236
7237 UPDATE msc_st_trading_partners mscu
7238 SET company_id = -1
7239 WHERE exists( SELECT 1
7240 FROM msc_companies mc
7241 WHERE mc.company_name = nvl(mscu.company_name,lv_my_company)
7242 AND mc.company_id = 1
7243 AND NVL(mc.disable_date,sysdate+1) > sysdate)
7244 AND mscu.process_flag = G_IN_PROCESS
7245 AND mscu.sr_instance_code = v_instance_code
7246 AND mscu.batch_id = lv_batch_id;
7247
7248 -- if not 'My Company' then get the first occurence of sr_tp_id for this company_name
7249
7250 UPDATE msc_st_trading_partners mscu
7251 SET company_id = (SELECT local_id from MSC_LOCAL_ID_SETUP
7252 WHERE char1 = mscu.sr_instance_code
7253 and NVL(char3,NULL_CHAR) = NVL(mscu.company_name,NULL_CHAR)
7254 and entity_name = 'SR_TP_ID'
7255 and rownum = 1) -- we need the first occurence of sr_tp_id
7256 WHERE mscu.company_id IS NULL
7257 AND mscu.process_flag = G_IN_PROCESS
7258 AND mscu.sr_instance_code = v_instance_code
7259 AND mscu.batch_id = lv_batch_id;
7260
7261 -- Set the message
7262
7263 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
7264 (p_app_short_name => 'MSC',
7265 p_error_code => 'MSC_PP_INVALID_VALUE',
7266 p_message_text => lv_message_text,
7267 p_error_text => lv_error_text,
7268 p_token1 => 'COLUMN_NAME',
7269 p_token_value1 => 'COMPANY_NAME');
7270
7271 IF lv_return <> 0 THEN
7272 RAISE ex_logging_err;
7273 END IF;
7274
7275 UPDATE msc_st_trading_partners mscu
7276 SET process_flag = G_ERROR_FLG,
7277 error_text = lv_message_text
7278 WHERE mscu.company_id IS NULL
7279 AND mscu.process_flag = G_IN_PROCESS
7280 AND mscu.sr_instance_code = v_instance_code
7281 AND mscu.batch_id = lv_batch_id;
7282
7283 END IF;
7284 */
7285
7286 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
7287 (p_app_short_name => 'MSC',
7288 p_error_code => 'MSC_PP_INVALID_VALUE',
7289 p_message_text => lv_message_text,
7290 p_error_text => lv_error_text,
7291 p_token1 => 'COLUMN_NAME',
7292 p_token_value1 => 'SOURCE_ORG_CODE');
7293
7294 IF lv_return <> 0 THEN
7295 RAISE ex_logging_err;
7296 END IF;
7297
7298 -- Derive source_org_id
7299 lv_return :=msc_st_util.derive_partner_org_id
7300 (p_table_name => 'MSC_ST_TRADING_PARTNERS',
7301 p_org_partner_name => 'SOURCE_ORG_CODE',
7302 p_org_partner_id => 'SOURCE_ORG_ID',
7303 p_instance_code => v_instance_code,
7304 p_partner_type => G_ORGANIZATION,
7305 p_error_text => lv_error_text,
7306 p_batch_id => lv_batch_id,
7307 p_severity => G_SEV3_ERROR,
7308 p_debug => v_debug,
7309 p_message_text => lv_message_text);
7310
7311 IF lv_return <> 0 THEN
7312 RAISE ex_logging_err;
7313 END IF;
7314 END IF; --v_msc_installed
7315
7316 -- ssurendr - bug 2647423: check for partner name - org code mismatch with respect to ODS - begin.
7317 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
7318 (p_app_short_name => 'MSC',
7319 p_error_code => 'MSC_PP_INVALID_VALUE',
7320 p_message_text => lv_message_text,
7321 p_error_text => lv_error_text,
7322 p_token1 => 'COLUMN_NAME',
7323 p_token_value1 => 'PARTNER_NAME');
7324
7325 IF lv_return <> 0 THEN
7326 RAISE ex_logging_err;
7327 END IF;
7328
7329 v_sql_stmt := 16.1;
7330 lv_sql_stmt :=
7331 'UPDATE msc_st_trading_partners mstp'
7332 ||' SET process_flag = '||G_ERROR_FLG||','
7333 ||' error_text = '||''''||lv_message_text||''''
7334 ||' WHERE EXISTS(SELECT 1 '
7335 ||' FROM msc_trading_partners mtp,'
7336 ||' msc_company_id_lid mcil'
7337 ||' WHERE mtp.partner_name = mstp.partner_name'
7338 ||' AND mtp.partner_type = mstp.partner_type'
7339 ||' AND mtp.organization_code <> mstp.organization_code'
7340 ||' AND mcil.sr_company_id = mstp.company_id'
7341 ||' AND mcil.partner_type = mstp.partner_type'
7342 ||' AND mcil.company_id = mtp.company_id'
7343 ||' AND mcil.sr_instance_id = :v_instance_id)'
7344 ||' AND mstp.partner_type ='||G_ORGANIZATION
7345 ||' AND nvl(mstp.company_id,-1) <> -1'
7346 ||' AND mstp.sr_instance_code = :v_instance_code'
7347 ||' AND mstp.batch_id = :lv_batch_id'
7348 ||' AND mstp.process_flag = '||G_IN_PROCESS ;
7349
7350
7351 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
7352
7353
7354 EXECUTE IMMEDIATE lv_sql_stmt
7355 USING v_instance_id,
7356 v_instance_code,
7357 lv_batch_id;
7358
7359 v_sql_stmt := 16.2;
7360 lv_sql_stmt :=
7361 'UPDATE msc_st_trading_partners mstp'
7362 ||' SET process_flag = '||G_ERROR_FLG||','
7363 ||' error_text = '||''''||lv_message_text||''''
7364 ||' WHERE EXISTS(SELECT 1 '
7365 ||' FROM msc_trading_partners mtp'
7366 ||' WHERE mtp.partner_name = mstp.partner_name'
7367 ||' AND mtp.partner_type = mstp.partner_type'
7368 ||' AND mtp.organization_code <> mstp.organization_code'
7369 ||' AND nvl(mtp.company_id,1) = 1)'
7370 ||' AND mstp.partner_type ='||G_ORGANIZATION
7371 ||' AND nvl(mstp.company_id,-1) = -1'
7372 ||' AND mstp.sr_instance_code = :v_instance_code'
7373 ||' AND mstp.batch_id = :lv_batch_id'
7374 ||' AND mstp.process_flag = '||G_IN_PROCESS ;
7375
7376
7377 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
7378
7379
7380 EXECUTE IMMEDIATE lv_sql_stmt
7381 USING v_instance_code,
7382 lv_batch_id;
7383 -- ssurendr - bug 2647423: check for partner name - org code mismatch with respect to ODS - end.
7384
7385 -- Derive sr_tp_id(Organization)
7386 lv_return :=msc_st_util.derive_partner_org_id
7387 (p_table_name => 'MSC_ST_TRADING_PARTNERS',
7388 p_org_partner_name => 'ORGANIZATION_CODE',
7389 p_org_partner_id => 'SR_TP_ID',
7390 p_instance_code => v_instance_code,
7391 p_partner_type => G_ORGANIZATION,
7392 p_error_text => lv_error_text,
7393 p_debug => v_debug,
7394 p_batch_id => lv_batch_id);
7395
7396 IF lv_return <> 0 THEN
7397 RAISE ex_logging_err;
7398 END IF;
7399
7400 -- Derive sr_tp_id(Customer)
7401 lv_return :=msc_st_util.derive_partner_org_id
7402 (p_table_name => 'MSC_ST_TRADING_PARTNERS',
7403 p_org_partner_name => 'PARTNER_NAME',
7404 p_cust_account_number=>'CUST_ACCOUNT_NUMBER',
7405 p_org_partner_id => 'SR_TP_ID',
7406 p_instance_code => v_instance_code,
7407 p_partner_type => G_CUSTOMER,
7408 p_error_text => lv_error_text,
7409 p_debug => v_debug,
7410 p_batch_id => lv_batch_id);
7411
7412 IF lv_return <> 0 THEN
7413 RAISE ex_logging_err;
7414 END IF;
7415
7416 -- Derive sr_tp_id(Supplier).
7417 lv_return :=msc_st_util.derive_partner_org_id
7418 (p_table_name => 'MSC_ST_TRADING_PARTNERS',
7419 p_org_partner_name => 'PARTNER_NAME',
7420 p_org_partner_id => 'SR_TP_ID',
7421 p_instance_code => v_instance_code,
7422 p_partner_type => G_VENDOR,
7423 p_error_text => lv_error_text,
7424 p_debug => v_debug,
7425 p_batch_id => lv_batch_id);
7426
7427 IF lv_return <> 0 THEN
7428 RAISE ex_logging_err;
7429 END IF;
7430
7431 -- Derive sr_tp_id(Carrier).
7432 lv_return :=msc_st_util.derive_partner_org_id
7433 (p_table_name => 'MSC_ST_TRADING_PARTNERS',
7434 p_org_partner_name => 'PARTNER_NAME',
7435 p_org_partner_id => 'SR_TP_ID',
7436 p_instance_code => v_instance_code,
7437 p_partner_type => G_CARRIER,
7438 p_error_text => lv_error_text,
7439 p_debug => v_debug,
7440 p_batch_id => lv_batch_id);
7441
7442 IF lv_return <> 0 THEN
7443 RAISE ex_logging_err;
7444 END IF;
7445
7446
7447 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
7448 (p_app_short_name => 'MSC',
7449 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
7450 p_message_text => lv_message_text,
7451 p_error_text => lv_error_text,
7452 p_token1 => 'COLUMN_NAME',
7453 p_token_value1 => 'INHERIT_OC_OP_SEQ_NUM',
7454 p_token2 => 'DEFAULT_VALUE',
7455 p_token_value2 => 2);
7456
7457 IF lv_return <> 0 THEN
7458 RAISE ex_logging_err;
7459 END IF;
7460
7461 -- Check INHERIT_OC_OP_SEQ_NUM column has valid value or not and if not set it to 2
7462 -- Log error procedure inserts warning and also defaults the INHERIT_OC_OP_SEQ_NUM
7463
7464 lv_where_str := ' AND NVL(INHERIT_OC_OP_SEQ_NUM,'||NULL_VALUE||') '
7465 ||' NOT IN(1,2)'
7466 ||' AND partner_type = '||G_ORGANIZATION ;
7467
7468 lv_return := MSC_ST_UTIL.LOG_ERROR
7469 (p_table_name => 'MSC_ST_TRADING_PARTNERS',
7470 p_instance_code => v_instance_code,
7471 p_row => lv_column_names,
7472 p_severity => G_SEV_WARNING,
7473 p_message_text => lv_message_text,
7474 p_error_text => lv_error_text,
7475 p_batch_id => lv_batch_id,
7476 p_where_str => lv_where_str,
7477 p_col_name => 'INHERIT_OC_OP_SEQ_NUM',
7478 p_debug => v_debug,
7479 p_default_value => 2);
7480
7481 IF lv_return <> 0 THEN
7482 RAISE ex_logging_err;
7483 END IF;
7484
7485 --Call to customised validation.
7486 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
7487 (ERRBUF => lv_error_text,
7488 RETCODE => lv_return,
7489 pBatchID => lv_batch_id,
7490 pInstanceCode => v_instance_code,
7491 pEntityName => 'MSC_ST_TRADING_PARTNERS',
7492 pInstanceID => v_instance_id);
7493
7494 IF NVL(lv_return,0) <> 0 THEN
7495 RAISE ex_logging_err;
7496 END IF;
7497
7498
7499 OPEN c2(lv_batch_id);
7500 FETCH c2 BULK COLLECT INTO lb_rowid ;
7501
7502 IF c2%ROWCOUNT > 0 THEN
7503 v_sql_stmt := 17;
7504 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
7505 UPDATE msc_st_trading_partners
7506 SET sr_tp_id = msc_st_sr_tp_id_s.NEXTVAL
7507 WHERE rowid = lb_rowid(j);
7508
7509 -- Insert into the LID table this new partner with the
7510 -- user defined key
7511
7512 v_sql_stmt := 18;
7513 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
7514 INSERT INTO msc_local_id_setup
7515 (local_id,
7516 st_transaction_id,
7517 instance_id,
7518 entity_name,
7519 data_source_type,
7520 char1,
7521 char2,
7522 char3,
7523 number1,
7524 char4,
7525 SOURCE_SOURCE_ORG_ID,
7526 SOURCE_SR_TP_ID,
7527 last_update_date,
7528 last_updated_by,
7529 creation_date,
7530 created_by )
7531 SELECT
7532 sr_tp_id,
7533 st_transaction_id,
7534 v_instance_id,
7535 'SR_TP_ID',
7536 data_source_type,
7537 v_instance_code,
7538 company_name,
7539 DECODE(partner_type,G_ORGANIZATION,organization_code,partner_name),
7540 partner_type,
7541 CUST_ACCOUNT_NUMBER,
7542 SOURCE_SOURCE_ORG_ID,
7543 SOURCE_SR_TP_ID,
7544 v_current_date,
7545 v_current_user,
7546 v_current_date,
7547 v_current_user
7548 FROM msc_st_trading_partners
7549 WHERE rowid = lb_rowid(j);
7550
7551 END IF;
7552 CLOSE c2 ;
7553 /* Removed this prefixing of instance to org code bug 2172537
7554 -- Update all organization_code as instance_code concatenated with org_code
7555 -- Where partner_type = 3 (organization)
7556 v_sql_stmt := 19;
7557 lv_sql_stmt :=
7558 'UPDATE msc_st_trading_partners '
7559 ||' SET organization_code = sr_instance_code'||'||'':''||'||'organization_code,'
7560 ||' master_organization = sr_tp_id'
7561 ||' WHERE partner_type = '||G_ORGANIZATION
7562 ||' AND sr_instance_code = :v_instance_code'
7563 ||' AND batch_id = :lv_batch_id'
7564 ||' AND process_flag = '||G_IN_PROCESS;
7565
7566 IF V_DEBUG THEN
7567 msc_st_util.log_message(lv_sql_stmt);
7568 END IF;
7569 EXECUTE IMMEDIATE lv_sql_stmt
7570 USING v_instance_code,
7571 lv_batch_id; */
7572
7573 -- Set the process flag as Valid and populate instance_id
7574 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
7575 (p_table_name => 'MSC_ST_TRADING_PARTNERS',
7576 p_instance_id => v_instance_id,
7577 p_instance_code => v_instance_code,
7578 p_process_flag => G_VALID,
7579 p_error_text => lv_error_text,
7580 p_debug => v_debug,
7581 p_batch_id => lv_batch_id);
7582
7583 IF lv_return <> 0 THEN
7584 RAISE ex_logging_err;
7585 END IF;
7586
7587 -- At the end calling the LOG_ERROR for logging all
7588 -- errored out records.
7589
7590 lv_return := MSC_ST_UTIL.LOG_ERROR
7591 (p_table_name => 'MSC_ST_TRADING_PARTNERS',
7592 p_instance_code => v_instance_code,
7593 p_row => lv_column_names,
7594 p_severity => G_SEV_ERROR,
7595 p_message_text => NULL,
7596 p_error_text => lv_error_text,
7597 p_debug => v_debug,
7598 p_batch_id => lv_batch_id );
7599
7600 IF lv_return <> 0 THEN
7601 RAISE ex_logging_err;
7602 END IF;
7603 COMMIT;
7604
7605 -- ODP change
7606 -- Call the procedure to insert all org/customer into the msd_st_level_values
7607 IF(v_install_msd) THEN
7608 lv_sql_stmt := 'DECLARE errbuf varchar2(250);'
7609 ||' retcode number;'
7610 ||' BEGIN '
7611 ||' MSD_CL_PRE_PROCESS.LOAD_ORG_CUST'
7612 ||' (ERRBUF => errbuf,'
7613 ||' RETCODE => retcode,'
7614 ||' p_instance_id => :v_instance_id,'
7615 ||' p_batch_id => :lv_batch_id);'
7616 ||' IF ( retcode = '||G_WARNING||') THEN '
7617 ||' update msc_apps_instances'
7618 ||' set dbs_ver = '||SYS_YES
7619 ||' where instance_id='||v_instance_id||';'
7620 ||' END IF;'
7621 ||' END ;';
7622
7623 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
7624
7625 EXECUTE IMMEDIATE lv_sql_stmt
7626 USING v_instance_id,
7627 lv_batch_id ;
7628 END IF ;
7629 COMMIT;
7630 END LOOP;
7631
7632 --Validation for MSC_ST_TRADING_PARTNER_SITES
7633
7634 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
7635 (p_app_short_name => 'MSC',
7636 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
7637 p_message_text => lv_message_text,
7638 p_error_text => lv_error_text);
7639
7640 IF lv_return <> 0 THEN
7641 RAISE ex_logging_err;
7642 END IF;
7643 /*
7644 -- UDK validations
7645 v_sql_stmt := 19;
7646 lv_sql_stmt :=
7647 ' UPDATE msc_st_trading_partner_sites mstp1'
7648 ||' SET process_flag = '||G_ERROR_FLG||', '
7649 ||' error_text = '||''''||lv_message_text||''''
7650 ||' WHERE EXISTS ( SELECT 1 '
7651 ||' FROM msc_st_trading_partner_sites mstp2 '
7652 ||' WHERE mstp2.sr_instance_code = mstp1.sr_instance_code '
7653 ||' AND NVL(mstp2.company_name, '||''''||NULL_CHAR||''''||') = '
7654 ||' NVL(mstp1.company_name, '||''''||NULL_CHAR||''''||')'
7655 ||' AND mstp2.partner_name = mstp1.partner_name '
7656 ||' AND NVL(mstp2.tp_site_code,mstp2.location) = NVL(mstp1.tp_site_code,mstp1.location) '
7657 ||' AND mstp2.partner_type = mstp1.partner_type '
7658 ||' AND mstp2.process_flag = mstp1.process_flag '
7659 ||' AND NVL(mstp2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
7660 ||' GROUP BY sr_instance_code,partner_name,tp_site_code,'
7661 ||' partner_type '
7662 ||' HAVING COUNT(*) >1 )'
7663 ||' AND mstp1.process_flag = '||G_IN_PROCESS
7664 ||' AND mstp1.sr_instance_code = :v_instance_code '
7665 ||' AND NVL(mstp1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
7666
7667 IF V_DEBUG THEN
7668 msc_st_util.log_message(lv_sql_stmt);
7669 END IF;
7670
7671 EXECUTE IMMEDIATE lv_sql_stmt
7672 USING v_instance_code;
7673 */
7674
7675 -- UDK validations for locations
7676 v_sql_stmt := 19;
7677 lv_sql_stmt :=
7678 ' UPDATE msc_st_trading_partner_sites mstp1'
7679 ||' SET process_flag = '||G_ERROR_FLG||', '
7680 ||' error_text = '||''''||lv_message_text||''''
7681 ||' WHERE EXISTS ( SELECT 1 '
7682 ||' FROM msc_st_trading_partner_sites mstp2 '
7683 ||' WHERE mstp2.sr_instance_code = mstp1.sr_instance_code '
7684 ||' AND NVL(mstp2.company_name, '||''''||NULL_CHAR||''''||') = '
7685 ||' NVL(mstp1.company_name, '||''''||NULL_CHAR||''''||')'
7686 ||' AND mstp2.partner_name = mstp1.partner_name '
7687 ||' AND mstp2.partner_type = mstp1.partner_type '
7688 ||' AND mstp2.process_flag = mstp1.process_flag '
7689 ||' AND NVL(mstp2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
7690 ||' GROUP BY sr_instance_code,partner_name,company_name,'
7691 ||' partner_type '
7692 ||' HAVING COUNT(*) >1 )'
7693 ||' AND mstp1.process_flag = '||G_IN_PROCESS
7694 ||' AND mstp1.sr_instance_code = :v_instance_code '
7695 ||' AND mstp1.partner_type = 3'
7696 ||' AND NVL(mstp1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
7697
7698
7699 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
7700
7701
7702 EXECUTE IMMEDIATE lv_sql_stmt
7703 USING v_instance_code;
7704
7705
7706 -- UDK validations for tp sites
7707 v_sql_stmt := 19;
7708 lv_sql_stmt :=
7709 ' UPDATE msc_st_trading_partner_sites mstp1'
7710 ||' SET process_flag = '||G_ERROR_FLG||', '
7711 ||' error_text = '||''''||lv_message_text||''''
7712 ||' WHERE EXISTS ( SELECT 1 '
7713 ||' FROM msc_st_trading_partner_sites mstp2 '
7714 ||' WHERE mstp2.sr_instance_code = mstp1.sr_instance_code '
7715 ||' AND NVL(mstp2.company_name, '||''''||NULL_CHAR||''''||') = '
7716 ||' NVL(mstp1.company_name, '||''''||NULL_CHAR||''''||')'
7717 ||' AND mstp2.partner_name = mstp1.partner_name '
7718 ||' AND mstp2.tp_site_code = mstp1.tp_site_code '
7719 ||' AND mstp2.partner_type = mstp1.partner_type '
7720 ||' AND mstp2.CUST_ACCOUNT_NUMBER = mstp1.CUST_ACCOUNT_NUMBER '
7721 ||' AND mstp2.process_flag = mstp1.process_flag '
7722 ||' AND NVL(mstp2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
7723 ||' GROUP BY sr_instance_code,partner_name,tp_site_code,'
7724 ||' partner_type,CUST_ACCOUNT_NUMBER'
7725 ||' HAVING COUNT(*) >1 )'
7726 ||' AND mstp1.process_flag = '||G_IN_PROCESS
7727 ||' AND mstp1.sr_instance_code = :v_instance_code '
7728 ||' AND mstp1.partner_type IN (1,2) '
7729 ||' AND NVL(mstp1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
7730
7731
7732 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
7733
7734
7735 EXECUTE IMMEDIATE lv_sql_stmt
7736 USING v_instance_code;
7737 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
7738 (p_app_short_name => 'MSC',
7739 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
7740 p_message_text => lv_message_text,
7741 p_error_text => lv_error_text);
7742
7743 IF lv_return <> 0 THEN
7744 RAISE ex_logging_err;
7745 END IF;
7746
7747 -- Duplicate UDK validation for XML message
7748 v_sql_stmt := 20;
7749 lv_sql_stmt :=
7750 ' UPDATE msc_st_trading_partner_sites mstp1'
7751 ||' SET process_flag = '||G_ERROR_FLG||', '
7752 ||' error_text = '||''''||lv_message_text||''''
7753 ||' WHERE message_id < ( SELECT max(message_id) '
7754 ||' FROM msc_st_trading_partner_sites mstp2 '
7755 ||' WHERE mstp2.sr_instance_code = mstp1.sr_instance_code '
7756 ||' AND NVL(mstp2.company_name, '||''''||NULL_CHAR||''''||') = '
7757 ||' NVL(mstp1.company_name, '||''''||NULL_CHAR||''''||')'
7758 ||' AND mstp2.partner_name = mstp1.partner_name '
7759 ||' AND mstp2.partner_type = mstp1.partner_type '
7760 ||' AND mstp2.process_flag = mstp1.process_flag '
7761 ||' AND mstp2.process_flag = '||G_IN_PROCESS
7762 ||' AND NVL(mstp2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
7763 ||' AND mstp1.process_flag = '||G_IN_PROCESS
7764 ||' AND mstp1.sr_instance_code = :v_instance_code '
7765 ||' AND mstp1.partner_type = 3'
7766 ||' AND NVL(mstp1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
7767
7768
7769 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
7770
7771
7772 EXECUTE IMMEDIATE lv_sql_stmt
7773 USING v_instance_code;
7774
7775 lv_column_names :=
7776 'PARTNER_NAME ||''~''||'
7777 ||'TP_SITE_CODE ||''~''||'
7778 ||'PARTNER_TYPE ||''~''||'
7779 ||'PARTNER_ADDRESS ||''~''||'
7780 ||'LOCATION ||''~''||'
7781 ||'LONGITUDE ||''~''||'
7782 ||'LATITUDE ||''~''||'
7783 ||'SR_INSTANCE_CODE ||''~''||'
7784 ||'COMPANY_NAME ||''~''||'
7785 ||'DELETED_FLAG';
7786
7787 -- Dividing records in batches based on batchsize
7788
7789 LOOP
7790 v_sql_stmt := 21;
7791 SELECT msc_st_batch_id_s.NEXTVAL
7792 INTO lv_batch_id
7793 FROM DUAL;
7794
7795 v_sql_stmt := 22;
7796 lv_sql_stmt :=
7797 'UPDATE msc_st_trading_partner_sites '
7798 ||' SET batch_id = :lv_batch_id'
7799 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
7800 ||' AND sr_instance_code = :v_instance_code'
7801 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
7802 ||' AND rownum <= '||v_batch_size;
7803
7804
7805 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
7806
7807
7808 EXECUTE IMMEDIATE lv_sql_stmt
7809 USING lv_batch_id,
7810 v_instance_code;
7811
7812 EXIT WHEN SQL%NOTFOUND ;
7813
7814 OPEN c3(lv_batch_id);
7815 FETCH c3 BULK COLLECT INTO lb_rowid;
7816 CLOSE c3;
7817
7818 -- Populate the st_transaction_id and WHO columns
7819 v_sql_stmt := 23;
7820 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
7821 UPDATE msc_st_trading_partner_sites
7822 SET st_transaction_id = msc_st_trading_partner_sites_s.NEXTVAL ,
7823 refresh_id = v_refresh_id,
7824 last_update_date = v_current_date,
7825 last_updated_by = v_current_user,
7826 creation_date = v_current_date,
7827 created_by = v_current_user
7828 WHERE rowid = lb_rowid(j);
7829
7830 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
7831 (p_app_short_name => 'MSC',
7832 p_error_code => 'MSC_PP_NO_DELETION',
7833 p_message_text => lv_message_text,
7834 p_error_text => lv_error_text,
7835 p_token1 => 'TABLE_NAME',
7836 p_token_value1 => 'MSC_ST_TRADING_PARTNER_SITES');
7837
7838 IF lv_return <> 0 THEN
7839 RAISE ex_logging_err;
7840 END IF;
7841
7842 -- Deletion is not allowed for this table
7843 v_sql_stmt := 24;
7844 lv_sql_stmt :=
7845 'UPDATE msc_st_trading_partner_sites '
7846 ||' SET process_flag = '||G_ERROR_FLG||','
7847 ||' error_text = '||''''||lv_message_text||''''
7848 ||' WHERE deleted_flag = '||SYS_YES
7849 ||' AND process_flag = '||G_IN_PROCESS
7850 ||' AND batch_id = :lv_batch_id'
7851 ||' AND sr_instance_code = :v_instance_code';
7852
7853
7854 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
7855
7856
7857 EXECUTE IMMEDIATE lv_sql_stmt
7858 USING lv_batch_id,
7859 v_instance_code;
7860
7861
7862 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
7863 (p_app_short_name => 'MSC',
7864 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
7865 p_message_text => lv_message_text,
7866 p_error_text => lv_error_text,
7867 p_token1 => 'COLUMN_NAME',
7868 p_token_value1 => 'DELETED_FLAG',
7869 p_token2 => 'DEFAULT_VALUE',
7870 p_token_value2 => SYS_NO);
7871
7872 IF lv_return <> 0 THEN
7873 RAISE ex_logging_err;
7874 END IF;
7875
7876 -- Check DELETE_FLAG column has valid value or not and if not set it to SYS_NO
7877 -- Log error procedure inserts warning and also defaults the delete flag
7878
7879 lv_where_str := ' AND NVL(deleted_flag,'||NULL_VALUE||') '
7880 ||' NOT IN(1,2)';
7881
7882 lv_return := MSC_ST_UTIL.LOG_ERROR
7883 (p_table_name => 'MSC_ST_TRADING_PARTNER_SITES',
7884 p_instance_code => v_instance_code,
7885 p_row => lv_column_names,
7886 p_severity => G_SEV_WARNING,
7887 p_message_text => lv_message_text,
7888 p_error_text => lv_error_text,
7889 p_batch_id => lv_batch_id,
7890 p_where_str => lv_where_str,
7891 p_col_name => 'DELETED_FLAG',
7892 p_debug => v_debug,
7893 p_default_value => SYS_NO);
7894
7895
7896 IF lv_return <> 0 THEN
7897 RAISE ex_logging_err;
7898 END IF;
7899
7900 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
7901 (p_app_short_name => 'MSC',
7902 p_error_code => 'MSC_PP_INVALID_VALUE',
7903 p_message_text => lv_message_text,
7904 p_error_text => lv_error_text,
7905 p_token1 => 'COLUMN_NAME',
7906 p_token_value1 => 'PARTNER_TYPE');
7907
7908 IF lv_return <> 0 THEN
7909 RAISE ex_logging_err;
7910 END IF;
7911
7912 -- Error out records where partner_type NOT in (1,2,3)
7913 v_sql_stmt := 25;
7914 lv_sql_stmt :=
7915 'UPDATE msc_st_trading_partner_sites '
7916 ||' SET process_flag = '||G_ERROR_FLG||', '
7917 ||' error_text = '||''''||lv_message_text||''''
7918 ||' WHERE sr_instance_code = :v_instance_code'
7919 ||' AND batch_id = :lv_batch_id'
7920 ||' AND process_flag = '||G_IN_PROCESS
7921 ||' AND NVL(partner_type,'||NULL_VALUE||') NOT IN (1,2,3)';
7922
7923
7924 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
7925
7926
7927 EXECUTE IMMEDIATE lv_sql_stmt
7928 USING v_instance_code,
7929 lv_batch_id;
7930
7931 -- ODP changes , error out the record if only DP is installed
7932 -- then only partner_type = 2 (customer ) should come in
7933
7934 IF (NOT v_install_msc) THEN
7935 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
7936 (p_app_short_name => 'MSC',
7937 p_error_code => 'MSC_PP_INVALID_VALUE',
7938 p_message_text => lv_message_text,
7939 p_error_text => lv_error_text,
7940 p_token1 => 'COLUMN_NAME',
7941 p_token_value1 => 'PARTNER_TYPE');
7942
7943 IF lv_return <> 0 THEN
7944 RAISE ex_logging_err;
7945 END IF;
7946
7947 -- Error out records where partner_type NOT in (2)
7948 v_sql_stmt := 25;
7949 lv_sql_stmt :=
7950 'UPDATE msc_st_trading_partner_sites '
7951 ||' SET process_flag = '||G_ERROR_FLG||', '
7952 ||' error_text = '||''''||lv_message_text||''''
7953 ||' WHERE sr_instance_code = :v_instance_code'
7954 ||' AND batch_id = :lv_batch_id'
7955 ||' AND process_flag = '||G_IN_PROCESS
7956 ||' AND NVL(partner_type,'||NULL_VALUE||') <> 2';
7957
7958
7959 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
7960
7961
7962 EXECUTE IMMEDIATE lv_sql_stmt
7963 USING v_instance_code,
7964 lv_batch_id;
7965 END IF ; --v_msc_install
7966
7967
7968
7969 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
7970 (p_app_short_name => 'MSC',
7971 p_error_code => 'MSC_PP_COL_VAL_NULL',
7972 p_message_text => lv_message_text,
7973 p_error_text => lv_error_text,
7974 p_token1 => 'COLUMN_NAME',
7975 p_token_value1 => 'PARTNER_NAME OR TP_SITE_CODE');
7976
7977 IF lv_return <> 0 THEN
7978 RAISE ex_logging_err;
7979 END IF;
7980
7981 -- Error out records where partner_name/tp_site_code is NULL
7982 -- For partner type 1 and 2
7983 v_sql_stmt := 26;
7984 lv_sql_stmt :=
7985 'UPDATE msc_st_trading_partner_sites '
7986 ||' SET process_flag = '||G_ERROR_FLG||','
7987 ||' error_text = '||''''||lv_message_text||''''
7988 ||' WHERE sr_instance_code = :v_instance_code'
7989 ||' AND batch_id = :lv_batch_id'
7990 ||' AND process_flag = '||G_IN_PROCESS
7991 ||' AND partner_type IN (1,2)'
7992 ||' AND (NVL(partner_name,'||''''||NULL_CHAR||''''||')'
7993 ||' = '||''''||NULL_CHAR||''''
7994 ||' OR NVL(tp_site_code,'||''''||NULL_CHAR||''''||') '
7995 ||' = '||''''||NULL_CHAR||''''||')';
7996
7997
7998 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
7999
8000
8001 EXECUTE IMMEDIATE lv_sql_stmt
8002 USING v_instance_code,
8003 lv_batch_id;
8004
8005 IF (v_install_msc) THEN
8006 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
8007 (p_app_short_name => 'MSC',
8008 p_error_code => 'MSC_PP_COL_VAL_NULL',
8009 p_message_text => lv_message_text,
8010 p_error_text => lv_error_text,
8011 p_token1 => 'COLUMN_NAME',
8012 p_token_value1 => 'PARTNER_NAME OR LOCATION');
8013
8014 IF lv_return <> 0 THEN
8015 RAISE ex_logging_err;
8016 END IF;
8017
8018 -- Error out records where partner_name/location is NULL
8019 -- For partner type 3
8020 v_sql_stmt := 27;
8021 lv_sql_stmt :=
8022 'UPDATE msc_st_trading_partner_sites '
8023 ||' SET process_flag = '||G_ERROR_FLG||','
8024 ||' error_text = '||''''||lv_message_text||''''
8025 ||' WHERE sr_instance_code = :v_instance_code'
8026 ||' AND batch_id = :lv_batch_id'
8027 ||' AND process_flag = '||G_IN_PROCESS
8028 ||' AND partner_type = 3'
8029 ||' AND (NVL(partner_name,'||''''||NULL_CHAR||''''||')'
8030 ||' = '||''''||NULL_CHAR||''''
8031 ||' OR NVL(location,'||''''||NULL_CHAR||''''||') '
8032 ||' = '||''''||NULL_CHAR||''''||')';
8033
8034
8035 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
8036
8037
8038 EXECUTE IMMEDIATE lv_sql_stmt
8039 USING v_instance_code,
8040 lv_batch_id;
8041
8042 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
8043 (p_app_short_name => 'MSC',
8044 p_error_code => 'MSC_PP_INVALID_VALUE',
8045 p_message_text => lv_message_text,
8046 p_error_text => lv_error_text,
8047 p_token1 => 'COLUMN_NAME',
8048 p_token_value1 => 'PARTNER_NAME');
8049
8050 IF lv_return <> 0 THEN
8051 RAISE ex_logging_err;
8052 END IF;
8053
8054 -- Update sr_tp_id(customer)
8055 lv_return :=msc_st_util.derive_partner_org_id
8056 (p_table_name =>'MSC_ST_TRADING_PARTNER_SITES',
8057 p_org_partner_name =>'PARTNER_NAME',
8058 p_cust_account_number=>'CUST_ACCOUNT_NUMBER',
8059 p_org_partner_id =>'SR_TP_ID',
8060 p_instance_code => v_instance_code,
8061 p_partner_type => G_CUSTOMER,
8062 p_batch_id =>lv_batch_id,
8063 p_debug => v_debug,
8064 p_error_text =>lv_error_text);
8065
8066 IF lv_return <> 0 THEN
8067 RAISE ex_logging_err;
8068 END IF;
8069
8070 -- Update sr_tp_id(Organization)
8071 lv_return :=msc_st_util.derive_partner_org_id
8072 (p_table_name => 'MSC_ST_TRADING_PARTNER_SITES',
8073 p_org_partner_name => 'PARTNER_NAME',
8074 p_org_partner_id => 'SR_TP_ID',
8075 p_instance_code => v_instance_code,
8076 p_partner_type => G_ORGANIZATION,
8077 p_error_text => lv_error_text,
8078 p_debug => v_debug,
8079 p_batch_id => lv_batch_id);
8080
8081 IF lv_return <> 0 THEN
8082 RAISE ex_logging_err;
8083 END IF;
8084 END IF ; --v_install_msc
8085
8086 -- Update sr_tp_id(supplier)
8087 lv_return :=msc_st_util.derive_partner_org_id
8088 (p_table_name =>'MSC_ST_TRADING_PARTNER_SITES',
8089 p_org_partner_name =>'PARTNER_NAME',
8090 p_org_partner_id =>'SR_TP_ID',
8091 p_instance_code => v_instance_code,
8092 p_partner_type => G_VENDOR,
8093 p_message_text => lv_message_text,
8094 p_batch_id =>lv_batch_id,
8095 p_debug => v_debug,
8096 p_error_text =>lv_error_text);
8097
8098 IF lv_return <> 0 THEN
8099 RAISE ex_logging_err;
8100 END IF;
8101
8102
8103 -- Error out the record if sr_tp_id is NULL
8104 v_sql_stmt := 28;
8105 lv_sql_stmt :=
8106 'UPDATE msc_st_trading_partner_sites'
8107 ||' SET process_flag = '||G_ERROR_FLG||','
8108 ||' error_text = '||''''||lv_message_text||''''
8109 ||' WHERE NVL(sr_tp_id,'||NULL_VALUE||')= '||NULL_VALUE
8110 ||' AND batch_id = :lv_batch_id'
8111 ||' AND process_flag = '||G_IN_PROCESS
8112 ||' AND sr_instance_code = :v_instance_code';
8113
8114
8115 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
8116
8117 EXECUTE IMMEDIATE lv_sql_stmt
8118 USING lv_batch_id,
8119 v_instance_code;
8120
8121 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
8122 (p_app_short_name => 'MSC',
8123 p_error_code => 'MSC_PP_INVALID_VALUE',
8124 p_message_text => lv_message_text,
8125 p_error_text => lv_error_text,
8126 p_token1 => 'COLUMN_NAME',
8127 p_token_value1 => 'TP_SITE_CODE');
8128
8129 IF lv_return <> 0 THEN
8130 RAISE ex_logging_err;
8131 END IF;
8132
8133 -- Update sr_tp_site_id(Vendor)
8134 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
8135 (p_table_name => 'MSC_ST_TRADING_PARTNER_SITES',
8136 p_partner_name => 'PARTNER_NAME',
8137 p_partner_site_code => 'TP_SITE_CODE',
8138 p_partner_site_id => 'SR_TP_SITE_ID',
8139 p_instance_code => v_instance_code,
8140 p_partner_type => G_VENDOR,
8141 p_error_text => lv_error_text,
8142 p_batch_id => lv_batch_id,
8143 p_debug => v_debug,
8144 p_row => lv_column_names);
8145
8146 IF lv_return <> 0 THEN
8147 RAISE ex_logging_err;
8148 END IF;
8149
8150 IF(v_install_msc) THEN
8151 -- Update sr_tp_site_id(Customer)
8152 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
8153 (p_table_name => 'MSC_ST_TRADING_PARTNER_SITES',
8154 p_partner_name => 'PARTNER_NAME',
8155 p_partner_site_code => 'TP_SITE_CODE',
8156 p_CUST_ACCOUNT_NUMBER =>'CUST_ACCOUNT_NUMBER',
8157 p_partner_site_id => 'SR_TP_SITE_ID',
8158 p_instance_code => v_instance_code,
8159 p_partner_type => G_CUSTOMER,
8160 p_error_text => lv_error_text,
8161 p_batch_id => lv_batch_id,
8162 p_debug => v_debug,
8163 p_row => lv_column_names);
8164
8165 IF lv_return <> 0 THEN
8166 RAISE ex_logging_err;
8167 END IF;
8168
8169 -- Update sr_tp_site_id(Organization)
8170 -- location_id goes into sr_tp_site_id
8171 v_sql_stmt := 28;
8172 lv_sql_stmt :=
8173 'UPDATE msc_st_trading_partner_sites mts'
8174 ||' SET sr_tp_site_id = (SELECT local_id'
8175 ||' FROM msc_local_id_setup mls'
8176 ||' WHERE mls.char1 = mts.sr_instance_code'
8177 ||' AND mls.char3 = mts.location'
8178 ||' AND mls.entity_name = ''LOCATION_ID'' )'
8179 ||' WHERE process_flag = '||G_IN_PROCESS
8180 ||' AND partner_type = 3'
8181 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
8182 ||' AND sr_instance_code = :v_instance_code';
8183
8184
8185 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
8186
8187
8188 EXECUTE IMMEDIATE lv_sql_stmt
8189 USING lv_batch_id,
8190 v_instance_code;
8191
8192
8193
8194 /* not required anymore for bug fix 2748525. locations are not specific to orgs
8195
8196 -- If we get a location code for the same org
8197 -- We will update the location_code in LID and won't generate a new location_id
8198 -- This will ensure that we will have just one location for the organization
8199
8200 v_sql_stmt := 29;
8201 v_sql_stmt := 29;
8202 lv_sql_stmt :=
8203 'UPDATE msc_local_id_setup mls'
8204 ||' SET mls.char4 = NVL( (select mts.location '
8205 ||' FROM msc_st_trading_partner_sites mts'
8206 ||' WHERE mls.char1 = mts.sr_instance_code'
8207 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
8208 ||' NVL(mts.company_name,'||''''||NULL_CHAR||''''||') '
8209 ||' AND mls.char3 = mts.partner_name'
8210 ||' AND mts.process_flag = '||G_IN_PROCESS
8211 ||' AND mts.partner_type = '||G_ORGANIZATION
8212 ||' AND NVL(mts.batch_id,'||NULL_VALUE||') = :p_batch_id'
8213 ||' AND mts.sr_instance_code = :v_instance_code),mls.char4)'
8214 ||' WHERE mls.entity_name = ''LOCATION_ID'' '
8215 ||' AND mls.instance_id = :v_instance_id' ;
8216
8217 IF V_DEBUG THEN
8218 msc_st_util.log_message(lv_sql_stmt);
8219 END IF;
8220
8221 EXECUTE IMMEDIATE lv_sql_stmt
8222 USING lv_batch_id,
8223 v_instance_code,v_instance_id;
8224 */
8225
8226 END IF ; -- v_install_msc
8227
8228 --Call to customised validation.
8229 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
8230 (ERRBUF => lv_error_text,
8231 RETCODE => lv_return,
8232 pBatchID => lv_batch_id,
8233 pInstanceCode => v_instance_code,
8234 pEntityName => 'MSC_ST_TRADING_PARTNER_SITES',
8235 pInstanceID => v_instance_id);
8236
8237 IF NVL(lv_return,0) <> 0 THEN
8238 RAISE ex_logging_err;
8239 END IF;
8240
8241 OPEN c4(lv_batch_id);
8242 FETCH c4 BULK COLLECT INTO lb_rowid ;
8243
8244 IF c4%ROWCOUNT > 0 THEN
8245 v_sql_stmt := 29;
8246 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
8247 UPDATE msc_st_trading_partner_sites
8248 SET sr_tp_site_id = msc_st_sr_tp_site_id_s.NEXTVAL
8249 WHERE rowid = lb_rowid(j);
8250
8251 -- Insert record in LID
8252 v_sql_stmt := 30;
8253 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
8254 INSERT INTO msc_local_id_setup
8255 (local_id,
8256 st_transaction_id,
8257 instance_id,
8258 entity_name,
8259 data_source_type,
8260 char1,
8261 char2,
8262 char3,
8263 char4,
8264 number1,
8265 SOURCE_SR_TP_ID,
8266 SOURCE_SR_TP_SITE_ID,
8267 char5,
8268 last_update_date,
8269 last_updated_by,
8270 creation_date,
8271 created_by)
8272 SELECT
8273 sr_tp_site_id,
8274 st_transaction_id,
8275 v_instance_id,
8276 'SR_TP_SITE_ID',
8277 data_source_type,
8278 v_instance_code,
8279 company_name,
8280 partner_name,
8281 tp_site_code,
8282 partner_type,
8283 SOURCE_SR_TP_ID,
8284 SOURCE_SR_TP_SITE_ID,
8285 CUST_ACCOUNT_NUMBER,
8286 v_current_date,
8287 v_current_user,
8288 v_current_date,
8289 v_current_user
8290 FROM msc_st_trading_partner_sites
8291 WHERE rowid = lb_rowid(j);
8292 END IF;
8293 CLOSE C4;
8294
8295 IF (v_install_msc) THEN -- IF MSC installed then only do this
8296 OPEN c7(lv_batch_id);
8297 FETCH c7 BULK COLLECT INTO lb_rowid ;
8298
8299 IF c7%ROWCOUNT > 0 THEN
8300 v_sql_stmt := 31;
8301 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
8302 UPDATE msc_st_trading_partner_sites
8303 SET sr_tp_site_id = msc_st_location_id_s.NEXTVAL
8304 WHERE rowid = lb_rowid(j);
8305
8306 -- Insert record in LID
8307 v_sql_stmt := 32;
8308 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
8309 INSERT INTO msc_local_id_setup
8310 (local_id,
8311 st_transaction_id,
8312 instance_id,
8313 entity_name,
8314 data_source_type,
8315 char1,
8316 char3,
8317 SOURCE_SR_TP_ID,
8318 SOURCE_SR_TP_SITE_ID,
8319 last_update_date,
8320 last_updated_by,
8321 creation_date,
8322 created_by)
8323 SELECT
8324 sr_tp_site_id,
8325 st_transaction_id,
8326 v_instance_id,
8327 'LOCATION_ID',
8328 data_source_type,
8329 v_instance_code,
8330 location,
8331 SOURCE_SR_TP_ID,
8332 SOURCE_SR_TP_SITE_ID,
8333 v_current_date,
8334 v_current_user,
8335 v_current_date,
8336 v_current_user
8337 FROM msc_st_trading_partner_sites
8338 WHERE rowid = lb_rowid(j);
8339 END IF;
8340 CLOSE C7;
8341
8342 --Deriving location_id
8343 v_sql_stmt := 32.1;
8344 lv_sql_stmt :=
8345 'UPDATE msc_st_trading_partner_sites mts'
8346 ||' SET sr_tp_site_id = (SELECT local_id'
8347 ||' FROM msc_local_id_setup mls'
8348 ||' WHERE mls.char1 = mts.sr_instance_code'
8349 ||' AND mls.char3 = mts.location'
8350 ||' AND mls.entity_name = ''LOCATION_ID'' )'
8351 ||' WHERE process_flag = '||G_IN_PROCESS
8352 ||' AND partner_type = 3'
8353 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
8354 ||' AND sr_instance_code = :v_instance_code';
8355
8356
8357 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
8358
8359
8360 EXECUTE IMMEDIATE lv_sql_stmt
8361 USING lv_batch_id,
8362 v_instance_code;
8363
8364 END IF ; -- v_install_msc
8365
8366 -- fix for 2409667
8367 -- Populating TP_SITE_CODE into LOCATION for Customer sites because in case
8368 -- of Customer Sites SCE would pick LOCATION as the COMPANY_SITE_NAME for MSC_COMPANY_SITES.
8369
8370 v_sql_stmt := 33;
8371 lv_sql_stmt :=
8372 'UPDATE msc_st_trading_partner_sites '
8373 ||' SET LOCATION = TP_SITE_CODE '
8374 ||' WHERE process_flag = '|| G_IN_PROCESS
8375 ||' AND partner_type = '|| G_CUSTOMER
8376 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
8377 ||' AND sr_instance_code = :v_instance_code';
8378
8379
8380 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
8381
8382
8383 EXECUTE IMMEDIATE lv_sql_stmt
8384 USING lv_batch_id,
8385 v_instance_code;
8386
8387
8388
8389 --Deriving location_id for G_CUSTOMERS --- for E1 integration 8651763 .
8390 v_sql_stmt := 32.2;
8391 lv_sql_stmt :=
8392 'UPDATE msc_st_trading_partner_sites mts'
8393 ||' SET location_id = (SELECT local_id'
8394 ||' FROM msc_local_id_setup mls'
8395 ||' WHERE mls.char1 = mts.sr_instance_code'
8396 ||' AND mls.char3 = mts.location'
8397 ||' AND mls.entity_name = ''LOCATION_ID'' )'
8398 ||' WHERE process_flag = '||G_IN_PROCESS
8399 ||' AND partner_type = 2'
8400 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
8401 ||' AND sr_instance_code = :v_instance_code';
8402
8403
8404 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
8405
8406
8407 EXECUTE IMMEDIATE lv_sql_stmt
8408 USING lv_batch_id,
8409 v_instance_code;
8410
8411
8412
8413 ----------------For E1 integ-- populating the location_id in case of customer-- bug # 8651763
8414
8415 OPEN c15(lv_batch_id);
8416 FETCH c15 BULK COLLECT INTO lb_rowid ;
8417
8418 IF c15%ROWCOUNT > 0 THEN
8419 v_sql_stmt := 32.3;
8420 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
8421 UPDATE msc_st_trading_partner_sites
8422 SET location_id = msc_st_location_id_s.NEXTVAL
8423 WHERE rowid = lb_rowid(j);
8424
8425 -- Insert record in LID
8426 v_sql_stmt := 32.4;
8427 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
8428 INSERT INTO msc_local_id_setup
8429 (local_id,
8430 st_transaction_id,
8431 instance_id,
8432 entity_name,
8433 data_source_type,
8434 char1,
8435 char3,
8436 SOURCE_SR_TP_ID,
8437 SOURCE_SR_TP_SITE_ID,
8438 last_update_date,
8439 last_updated_by,
8440 creation_date,
8441 created_by)
8442 SELECT
8443 location_id,
8444 st_transaction_id,
8445 v_instance_id,
8446 'LOCATION_ID',
8447 data_source_type,
8448 v_instance_code,
8449 location,
8450 SOURCE_SR_TP_ID,
8451 SOURCE_SR_TP_SITE_ID,
8452 v_current_date,
8453 v_current_user,
8454 v_current_date,
8455 v_current_user
8456 FROM msc_st_trading_partner_sites
8457 WHERE rowid = lb_rowid(j);
8458 END IF;
8459 CLOSE C15;
8460
8461 --Deriving location_id
8462 v_sql_stmt := 32.5;
8463 lv_sql_stmt :=
8464 'UPDATE msc_st_trading_partner_sites mts'
8465 ||' SET location_id = (SELECT local_id'
8466 ||' FROM msc_local_id_setup mls'
8467 ||' WHERE mls.char1 = mts.sr_instance_code'
8468 ||' AND mls.char3 = mts.location'
8469 ||' AND mls.entity_name = ''LOCATION_ID'' )'
8470 ||' WHERE process_flag = '||G_IN_PROCESS
8471 ||' AND partner_type = 2'
8472 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
8473 ||' AND sr_instance_code = :v_instance_code';
8474
8475
8476 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
8477
8478
8479 EXECUTE IMMEDIATE lv_sql_stmt
8480 USING lv_batch_id,
8481 v_instance_code;
8482 ----------------For E1 integ-- populating the location_id in case of customer-- bug # 8651763
8483
8484
8485
8486 -- Set the process flag as Valid and poulate instance_id
8487 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
8488 (p_table_name => 'MSC_ST_TRADING_PARTNER_SITES',
8489 p_instance_id => v_instance_id,
8490 p_instance_code => v_instance_code,
8491 p_process_flag => G_VALID,
8492 p_error_text => lv_error_text,
8493 p_debug => v_debug,
8494 p_batch_id => lv_batch_id);
8495
8496 IF lv_return < 0 THEN
8497 RAISE ex_logging_err;
8498 END IF;
8499
8500 -- At the end calling the LOG_ERROR for logging all errored out records
8501
8502 lv_return := MSC_ST_UTIL.LOG_ERROR
8503 (p_table_name => 'MSC_ST_TRADING_PARTNER_SITES',
8504 p_instance_code => v_instance_code,
8505 p_row => lv_column_names,
8506 p_severity => G_SEV_ERROR,
8507 p_message_text => NULL,
8508 p_error_text => lv_error_text,
8509 p_debug => v_debug,
8510 p_batch_id => lv_batch_id );
8511
8512 IF lv_return < 0 THEN
8513 RAISE ex_logging_err;
8514 END IF;
8515 COMMIT;
8516
8517
8518 -- ODP change
8519 -- Call the procedure to insert site into the msd_st_level_values
8520 IF(v_install_msd) THEN
8521 lv_sql_stmt := ' DECLARE errbuf varchar2(250);'
8522 ||' retcode number ;'
8523 ||' BEGIN '
8524 ||' MSD_CL_PRE_PROCESS.LOAD_SITE'
8525 ||' (ERRBUF => errbuf ,'
8526 ||' RETCODE => retcode ,'
8527 ||' p_instance_id => :v_instance_id,'
8528 ||' p_batch_id => :lv_batch_id);'
8529 ||' IF ( retcode = '||G_WARNING||') THEN '
8530 ||' update msc_apps_instances'
8531 ||' set dbs_ver = '||SYS_YES
8532 ||' where instance_id='||v_instance_id||';'
8533 ||' END IF;'
8534 ||' END ;';
8535
8536 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
8537
8538 EXECUTE IMMEDIATE lv_sql_stmt
8539 USING v_instance_id,
8540 lv_batch_id ;
8541 END IF ; -- v_install_msd
8542 COMMIT;
8543 END LOOP;
8544
8545 --Validation for MSC_ST_SUB_INVENTORIES
8546
8547
8548 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
8549 (p_app_short_name => 'MSC',
8550 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
8551 p_message_text => lv_message_text,
8552 p_error_text => lv_error_text);
8553
8554 IF lv_return <> 0 THEN
8555 RAISE ex_logging_err;
8556 END IF;
8557
8558 -- UDK validations
8559 v_sql_stmt := 29;
8560 lv_sql_stmt :=
8561 'UPDATE msc_st_sub_inventories mssi1 '
8562 ||' SET process_flag = '||G_ERROR_FLG||','
8563 ||' error_text = '||''''||lv_message_text||''''
8564 ||' WHERE EXISTS( SELECT 1 '
8565 ||' FROM msc_st_sub_inventories mssi2 '
8566 ||' WHERE mssi2.sr_instance_code = mssi1.sr_instance_code'
8567 ||' AND NVL(mssi2.company_name, '||''''||NULL_CHAR||''''||') = '
8568 ||' NVL(mssi1.company_name, '||''''||NULL_CHAR||''''||')'
8569 ||' AND mssi2.organization_code = mssi1.organization_code'
8570 ||' AND mssi2.sub_inventory_code = mssi1.sub_inventory_code'
8571 ||' AND NVL(mssi2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
8572 ||' GROUP BY sr_instance_code,organization_code,sub_inventory_code'
8573 ||' HAVING COUNT(*) >1 )'
8574 ||' AND mssi1.process_flag = '||G_IN_PROCESS
8575 ||' AND mssi1.sr_instance_code = :v_instance_code'
8576 ||' AND NVL(mssi1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
8577
8578
8579 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
8580
8581 EXECUTE IMMEDIATE lv_sql_stmt
8582 USING v_instance_code;
8583
8584
8585 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
8586 (p_app_short_name => 'MSC',
8587 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
8588 p_message_text => lv_message_text,
8589 p_error_text => lv_error_text);
8590
8591 IF lv_return <> 0 THEN
8592 RAISE ex_logging_err;
8593 END IF;
8594
8595 -- Duplicate UDK validation for XML message
8596 v_sql_stmt := 28;
8597 lv_sql_stmt :=
8598 'UPDATE msc_st_sub_inventories mssi1 '
8599 ||' SET process_flag = '||G_ERROR_FLG||','
8600 ||' error_text = '||''''||lv_message_text||''''
8601 ||' WHERE message_id < (SELECT MAX(message_id)'
8602 ||' FROM msc_st_sub_inventories mssi2'
8603 ||' WHERE mssi2.sr_instance_code = mssi1.sr_instance_code '
8604 ||' AND NVL(mssi2.company_name, '||''''||NULL_CHAR||''''||') = '
8605 ||' NVL(mssi1.company_name, '||''''||NULL_CHAR||''''||')'
8606 ||' AND mssi2.organization_code = mssi1.organization_code'
8607 ||' AND mssi2.sub_inventory_code = mssi1.sub_inventory_code'
8608 ||' AND mssi2.process_flag = '||G_IN_PROCESS
8609 ||' AND NVL(mssi2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
8610 ||' AND mssi1.process_flag = '||G_IN_PROCESS
8611 ||' AND mssi1.sr_instance_code = :v_instance_code'
8612 ||' AND NVL(mssi1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
8613
8614
8615 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
8616
8617 EXECUTE IMMEDIATE lv_sql_stmt
8618 USING v_instance_code;
8619
8620
8621 lv_column_names :=
8622 'ORGANIZATION_CODE ||''~''||'
8623 ||'SUB_INVENTORY_CODE||''~''||'
8624 ||'SR_INSTANCE_CODE ||''~''||'
8625 ||'DESCRIPTION ||''~''||'
8626 ||'DISABLE_DATE ||''~''||'
8627 ||'NETTING_TYPE ||''~''||'
8628 ||'DEMAND_CLASS ||''~''||'
8629 ||'PROJECT_NUMBER ||''~''||'
8630 ||'TASK_NUMBER ||''~''||'
8631 ||'INVENTORY_ATP_CODE||''~''||'
8632 ||'COMPANY_NAME ||''~''||'
8633 ||'DELETED_FLAG';
8634
8635
8636 -- Dividing records in batches based on batchsize
8637
8638 LOOP
8639 v_sql_stmt := 29;
8640 SELECT msc_st_batch_id_s.NEXTVAL
8641 INTO lv_batch_id
8642 FROM DUAL;
8643
8644 v_sql_stmt := 30;
8645 lv_sql_stmt :=
8646 'UPDATE msc_st_sub_inventories '
8647 ||' SET batch_id = :lv_batch_id'
8648 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
8649 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
8650 ||' AND sr_instance_code = :v_instance_code'
8651 ||' AND rownum <= '||v_batch_size;
8652
8653
8654 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
8655
8656 EXECUTE IMMEDIATE lv_sql_stmt
8657 USING lv_batch_id,
8658 v_instance_code;
8659
8660 EXIT WHEN SQL%NOTFOUND;
8661
8662 OPEN c5(lv_batch_id);
8663 FETCH c5 BULK COLLECT INTO lb_rowid;
8664 CLOSE c5;
8665
8666 v_sql_stmt := 31;
8667 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
8668 UPDATE msc_st_sub_inventories
8669 SET st_transaction_id = msc_st_sub_inventories_s.NEXTVAL ,
8670 refresh_id = v_refresh_id,
8671 last_update_date = v_current_date,
8672 last_updated_by = v_current_user,
8673 creation_date = v_current_date,
8674 created_by = v_current_user
8675 WHERE rowid = lb_rowid(j);
8676
8677
8678 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
8679 (p_app_short_name => 'MSC',
8680 p_error_code => 'MSC_PP_NO_DELETION',
8681 p_message_text => lv_message_text,
8682 p_error_text => lv_error_text,
8683 p_token1 => 'TABLE_NAME',
8684 p_token_value1 => 'MSC_ST_SUB_INVENTORIES');
8685
8686 IF lv_return <> 0 THEN
8687 RAISE ex_logging_err;
8688 END IF;
8689
8690 -- Deletion is not allowed for this table
8691 v_sql_stmt := 32;
8692 lv_sql_stmt :=
8693 'UPDATE msc_st_sub_inventories '
8694 ||' SET process_flag = '||G_ERROR_FLG||','
8695 ||' error_text = '||''''||lv_message_text||''''
8696 ||' WHERE deleted_flag = '||SYS_YES
8697 ||' AND process_flag = '||G_IN_PROCESS
8698 ||' AND batch_id = :lv_batch_id'
8699 ||' AND sr_instance_code = :v_instance_code';
8700
8701
8702
8703 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
8704
8705 EXECUTE IMMEDIATE lv_sql_stmt
8706 USING lv_batch_id,
8707 v_instance_code;
8708
8709 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
8710 (p_app_short_name => 'MSC',
8711 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
8712 p_message_text => lv_message_text,
8713 p_error_text => lv_error_text,
8714 p_token1 => 'COLUMN_NAME',
8715 p_token_value1 => 'DELETED_FLAG',
8716 p_token2 => 'DEFAULT_VALUE',
8717 p_token_value2 => SYS_NO);
8718
8719 IF lv_return <> 0 THEN
8720 RAISE ex_logging_err;
8721 END IF;
8722
8723 -- Check DELETE_FLAG column has valid value or not and if not set it to SYS_NO
8724 -- Log error procedure inserts warning and also defaults the delete flag
8725
8726 lv_where_str := ' AND NVL(deleted_flag,'||NULL_VALUE||') '
8727 ||' NOT IN(1,2)';
8728
8729 lv_return := MSC_ST_UTIL.LOG_ERROR
8730 (p_table_name => 'MSC_ST_SUB_INVENTORIES',
8731 p_instance_code => v_instance_code,
8732 p_row => lv_column_names,
8733 p_severity => G_SEV_WARNING,
8734 p_message_text => lv_message_text,
8735 p_error_text => lv_error_text,
8736 p_batch_id => lv_batch_id,
8737 p_where_str => lv_where_str,
8738 p_col_name => 'DELETED_FLAG',
8739 p_debug => v_debug,
8740 p_default_value => SYS_NO);
8741
8742 IF lv_return <> 0 THEN
8743 RAISE ex_logging_err;
8744 END IF;
8745
8746 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
8747 (p_app_short_name => 'MSC',
8748 p_error_code => 'MSC_PP_COL_VAL_NULL',
8749 p_message_text => lv_message_text,
8750 p_error_text => lv_error_text,
8751 p_token1 => 'COLUMN_NAME',
8752 p_token_value1 => 'SUB_INVENTORY_CODE');
8753
8754 IF lv_return <> 0 THEN
8755 RAISE ex_logging_err;
8756 END IF;
8757
8758 -- Error out records where subinventory_code is NULL
8759 v_sql_stmt := 33;
8760 lv_sql_stmt :=
8761 'UPDATE msc_st_sub_inventories '
8762 ||' SET process_flag = '||G_ERROR_FLG||','
8763 ||' error_text = '||''''||lv_message_text||''''
8764 ||' WHERE sr_instance_code = :v_instance_code'
8765 ||' AND batch_id = :lv_batch_id'
8766 ||' AND process_flag = '||G_IN_PROCESS
8767 ||' AND NVL(sub_inventory_code,'||''''||NULL_CHAR||''''||')'
8768 ||' = '||''''||NULL_CHAR||'''';
8769
8770
8771
8772 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
8773 EXECUTE IMMEDIATE lv_sql_stmt
8774 USING v_instance_code,
8775 lv_batch_id;
8776
8777 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
8778 (p_app_short_name => 'MSC',
8779 p_error_code => 'MSC_PP_INVALID_VALUE',
8780 p_message_text => lv_message_text,
8781 p_error_text => lv_error_text,
8782 p_token1 => 'COLUMN_NAME',
8783 p_token_value1 => 'ORGANIZATION_CODE');
8784
8785 IF lv_return <> 0 THEN
8786 RAISE ex_logging_err;
8787 END IF;
8788
8789 -- Update organization_id
8790 lv_return := msc_st_util.derive_partner_org_id
8791 (p_table_name => 'MSC_ST_SUB_INVENTORIES',
8792 p_org_partner_name => 'ORGANIZATION_CODE',
8793 p_org_partner_id => 'ORGANIZATION_ID',
8794 p_instance_code => v_instance_code,
8795 p_partner_type => G_ORGANIZATION,
8796 p_error_text => lv_error_text,
8797 p_batch_id => lv_batch_id,
8798 p_severity => G_SEV_ERROR,
8799 p_message_text => lv_message_text,
8800 p_debug => v_debug,
8801 p_row => lv_column_names);
8802
8803 if(lv_return <> 0) then
8804 RAISE ex_logging_err;
8805 end if;
8806
8807 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
8808 (p_app_short_name => 'MSC',
8809 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
8810 p_message_text => lv_message_text,
8811 p_error_text => lv_error_text,
8812 p_token1 => 'COLUMN_NAME',
8813 p_token_value1 => 'NETTING_TYPE',
8814 p_token2 => 'DEFAULT_VALUE',
8815 p_token_value2 => 1);
8816
8817 IF lv_return <> 0 THEN
8818 RAISE ex_logging_err;
8819 END IF;
8820
8821 -- Default netting_type as 2 if NOT IN (1,2)
8822 lv_where_str := ' AND nvl(netting_type,'||NULL_VALUE||') NOT IN (1,2)';
8823 lv_return := MSC_ST_UTIL.LOG_ERROR
8824 (p_table_name => 'MSC_ST_SUB_INVENTORIES',
8825 p_instance_code => v_instance_code,
8826 p_row => lv_column_names,
8827 p_severity => G_SEV_WARNING,
8828 p_message_text => lv_message_text,
8829 p_error_text => lv_error_text,
8830 p_batch_id => lv_batch_id,
8831 p_where_str => lv_where_str,
8832 p_col_name => 'NETTING_TYPE',
8833 p_debug => v_debug,
8834 p_default_value => 1);
8835
8836 IF lv_return <> 0 THEN
8837 RAISE ex_logging_err;
8838 END IF;
8839
8840 --Call to customised validation.
8841 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
8842 (ERRBUF => lv_error_text,
8843 RETCODE => lv_return,
8844 pBatchID => lv_batch_id,
8845 pInstanceCode => v_instance_code,
8846 pEntityName => 'MSC_ST_SUB_INVENTORIES',
8847 pInstanceID => v_instance_id);
8848
8849 IF NVL(lv_return,0) <> 0 THEN
8850 RAISE ex_logging_err;
8851 END IF;
8852
8853 -- Set the processf flag as Valid and poulate instance_id
8854 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
8855 (p_table_name => 'MSC_ST_SUB_INVENTORIES',
8856 p_instance_id => v_instance_id,
8857 p_instance_code => v_instance_code,
8858 p_process_flag => G_VALID,
8859 p_error_text => lv_error_text,
8860 p_debug => v_debug,
8861 p_batch_id => lv_batch_id);
8862
8863 IF lv_return < 0 THEN
8864 RAISE ex_logging_err;
8865 END IF;
8866
8867 -- At the end calling the LOG_ERROR for logging all errored out records
8868
8869 lv_return := MSC_ST_UTIL.LOG_ERROR
8870 (p_table_name =>'MSC_ST_SUB_INVENTORIES',
8871 p_instance_code =>v_instance_code,
8872 p_row =>lv_column_names,
8873 p_severity =>G_SEV_ERROR,
8874 p_message_text => NULL,
8875 p_error_text =>lv_error_text,
8876 p_debug => v_debug,
8877 p_batch_id => lv_batch_id );
8878
8879 IF(lv_return <> 0) then
8880 RAISE ex_logging_err;
8881 END IF;
8882 COMMIT;
8883 END LOOP;
8884
8885
8886 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
8887 (p_app_short_name => 'MSC',
8888 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
8889 p_message_text => lv_message_text,
8890 p_error_text => lv_error_text);
8891
8892 IF lv_return <> 0 THEN
8893 RAISE ex_logging_err;
8894 END IF;
8895
8896 --Validation check for the table MSC_ST_LOCATION_ASSOCIATIONS
8897
8898 --Duplicate records check for the records whose source is other than XML
8899 --Different SQL is used because in XML we can identify the latest records
8900 --whereas in batch load we cannot.
8901
8902 v_sql_stmt := 34;
8903 lv_sql_stmt :=
8904 'UPDATE msc_st_location_associations mla1 '
8905 ||' SET process_flag = '||G_ERROR_FLG||','
8906 ||' error_text = '||''''||lv_message_text||''''
8907 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_location_associations mla2 '
8908 ||' WHERE mla2.sr_instance_code = mla1.sr_instance_code'
8909 ||' AND NVL(mla2.company_name, '||''''||NULL_CHAR||''''||') = '
8910 ||' NVL(mla1.company_name, '||''''||NULL_CHAR||''''||')'
8911 ||' AND mla2.partner_name = mla1.partner_name '
8912 ||' AND mla2.partner_type = mla1.partner_type '
8913 ||' AND mla2.tp_site_code = mla1.tp_site_code '
8914 ||' AND mla2.location_code = mla1.location_code'
8915 ||' AND mla2.organization_code = mla1.organization_code'
8916 ||' AND mla2.process_flag = mla1.process_flag '
8917 ||' AND NVL(mla2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
8918 ||' GROUP BY sr_instance_code,company_name,partner_name,'
8919 ||' tp_site_code,location_code,partner_type,organization_code '
8920 ||' HAVING COUNT(*) >1 )'
8921 ||' AND mla1.process_flag = '||G_IN_PROCESS
8922 ||' AND mla1.sr_instance_code = :v_instance_code'
8923 ||' AND NVL(mla1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
8924
8925
8926 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
8927
8928 EXECUTE IMMEDIATE lv_sql_stmt
8929 USING v_instance_code;
8930
8931
8932 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
8933 (p_app_short_name => 'MSC',
8934 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
8935 p_message_text => lv_message_text,
8936 p_error_text => lv_error_text);
8937
8938 IF lv_return <> 0 THEN
8939 RAISE ex_logging_err;
8940 END IF;
8941
8942 --Duplicate records check for the records whose source is XML
8943 v_sql_stmt := 35;
8944 lv_sql_stmt :=
8945 'UPDATE msc_st_location_associations mla1 '
8946 ||' SET process_flag = '||G_ERROR_FLG||','
8947 ||' error_text = '||''''||lv_message_text||''''
8948 ||' WHERE message_id < ( SELECT max(message_id) '
8949 ||' FROM msc_st_location_associations mla2 '
8950 ||' WHERE mla2.sr_instance_code = mla1.sr_instance_code'
8951 ||' AND NVL(mla2.company_name, '||''''||NULL_CHAR||''''||') = '
8952 ||' NVL(mla1.company_name, '||''''||NULL_CHAR||''''||')'
8953 ||' AND mla2.partner_name = mla1.partner_name '
8954 ||' AND mla2.partner_type = mla1.partner_type '
8955 ||' AND mla2.tp_site_code = mla1.tp_site_code '
8956 ||' AND mla2.location_code = mla1.location_code'
8957 ||' AND mla2.organization_code = mla1.organization_code'
8958 ||' AND mla2.process_flag = mla1.process_flag '
8959 ||' AND NVL(mla2.message_id,'||NULL_VALUE||') <> '||NULL_VALUE||')'
8960 ||' AND mla1.process_flag = '||G_IN_PROCESS
8961 ||' AND mla1.sr_instance_code = :v_instance_code '
8962 ||' AND NVL(mla1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
8963
8964
8965 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
8966
8967 EXECUTE IMMEDIATE lv_sql_stmt
8968 USING v_instance_code;
8969
8970 lv_column_names :=
8971 'LOCATION_CODE ||''~''||'
8972 ||'PARTNER_NAME ||''~''||'
8973 ||'TP_SITE_CODE ||''~''||'
8974 ||'PARTNER_TYPE ||''~''||'
8975 ||'SR_INSTANCE_CODE ||''~''||'
8976 ||'ORGANIZATION_CODE ||''~''||'
8977 ||'DELETED_FLAG ||''~''||'
8978 ||'COMPANY_NAME ';
8979
8980
8981 -- Dividing records in batches based on batchsize
8982 LOOP
8983 v_sql_stmt := 36;
8984 SELECT msc_st_batch_id_s.NEXTVAL
8985 INTO lv_batch_id
8986 FROM DUAL;
8987
8988 v_sql_stmt := 37;
8989 lv_sql_stmt :=
8990 'UPDATE msc_st_location_associations '
8991 ||' SET batch_id = :lv_batch_id '
8992 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
8993 ||' AND sr_instance_code = :v_instance_code'
8994 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
8995 ||' AND rownum <= '||v_batch_size;
8996
8997
8998 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
8999
9000 EXECUTE IMMEDIATE lv_sql_stmt
9001 USING lv_batch_id,
9002 v_instance_code;
9003
9004 EXIT WHEN SQL%NOTFOUND ;
9005
9006 OPEN c6(lv_batch_id);
9007 FETCH c6 BULK COLLECT INTO lb_rowid;
9008 CLOSE c6;
9009
9010 v_sql_stmt := 38;
9011 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
9012 UPDATE msc_st_location_associations
9013 SET st_transaction_id = msc_st_location_associations_s.NEXTVAL,
9014 refresh_id = v_refresh_id,
9015 last_update_date = v_current_date,
9016 last_updated_by = v_current_user,
9017 creation_date = v_current_date,
9018 created_by = v_current_user
9019 WHERE rowid = lb_rowid(j);
9020
9021 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
9022 (p_app_short_name => 'MSC',
9023 p_error_code => 'MSC_PP_NO_DELETION',
9024 p_message_text => lv_message_text,
9025 p_error_text => lv_error_text,
9026 p_token1 => 'TABLE_NAME',
9027 p_token_value1 => 'MSC_ST_LOCATION_ASSOCIATIONS');
9028
9029 -- Deletion is not allowed for this table
9030 v_sql_stmt := 39;
9031 lv_sql_stmt :=
9032 'UPDATE msc_st_location_associations '
9033 ||' SET process_flag = '||G_ERROR_FLG||','
9034 ||' error_text = '||''''||lv_message_text||''''
9035 ||' WHERE deleted_flag = '||SYS_YES
9036 ||' AND process_flag = '||G_IN_PROCESS
9037 ||' AND batch_id = :lv_batch_id'
9038 ||' AND sr_instance_code = :v_instance_code';
9039
9040
9041 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
9042
9043 EXECUTE IMMEDIATE lv_sql_stmt
9044 USING lv_batch_id,
9045 v_instance_code;
9046
9047
9048 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
9049 (p_app_short_name => 'MSC',
9050 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
9051 p_message_text => lv_message_text,
9052 p_error_text => lv_error_text,
9053 p_token1 => 'COLUMN_NAME',
9054 p_token_value1 => 'DELETED_FLAG',
9055 p_token2 => 'DEFAULT_VALUE',
9056 p_token_value2 => SYS_NO);
9057
9058 IF lv_return <> 0 THEN
9059 RAISE ex_logging_err;
9060 END IF;
9061
9062 -- Check DELETE_FLAG column has valid value or not and if not set it to SYS_NO
9063 -- Log error procedure inserts warning and also defaults the delete flag
9064
9065 lv_where_str := ' AND NVL(deleted_flag,'||NULL_VALUE||') '
9066 ||' NOT IN(1,2)';
9067
9068 lv_return := MSC_ST_UTIL.LOG_ERROR
9069 (p_table_name => 'MSC_ST_LOCATION_ASSOCIATIONS',
9070 p_instance_code => v_instance_code,
9071 p_row => lv_column_names,
9072 p_severity => G_SEV_WARNING,
9073 p_message_text => lv_message_text,
9074 p_error_text => lv_error_text,
9075 p_batch_id => lv_batch_id,
9076 p_where_str => lv_where_str,
9077 p_col_name => 'DELETED_FLAG',
9078 p_debug => v_debug,
9079 p_default_value => SYS_NO);
9080
9081 IF lv_return <> 0 THEN
9082 RAISE ex_logging_err;
9083 END IF;
9084
9085 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
9086 (p_app_short_name => 'MSC',
9087 p_error_code => 'MSC_PP_COL_VAL_NULL',
9088 p_message_text => lv_message_text,
9089 p_error_text => lv_error_text,
9090 p_token1 => 'COLUMN_NAME',
9091 p_token_value1 => 'PARTNER_NAME OR TP_SITE_CODE OR LOCATION_CODE');
9092
9093 IF lv_return <> 0 THEN
9094 RAISE ex_logging_err;
9095 END IF;
9096
9097 -- Error out records where partner_name/tp_site_code/location_code is NULL
9098 v_sql_stmt := 40;
9099 lv_sql_stmt :=
9100 'UPDATE msc_st_location_associations'
9101 ||' SET process_flag = '||G_ERROR_FLG||','
9102 ||' error_text = '||''''||lv_message_text||''''
9103 ||' WHERE (NVL(partner_name,'||''''||NULL_CHAR||''''||') '
9104 ||' = '||''''||NULL_CHAR||''''
9105 ||' OR (partner_type <> 3 AND NVL(tp_site_code, '||''''||NULL_CHAR||''''||') '
9106 ||' = '||''''||NULL_CHAR||''''||' ) '
9107 ||' OR NVL(location_code, '||''''||NULL_CHAR||''''||') '
9108 ||' = '||''''||NULL_CHAR||''''||' ) '
9109 ||' AND batch_id = :lv_batch_id'
9110 ||' AND process_flag = '||G_IN_PROCESS
9111 ||' AND deleted_flag = '||SYS_NO
9112 ||' AND sr_instance_code = :v_instance_code';
9113
9114
9115 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
9116 EXECUTE IMMEDIATE lv_sql_stmt
9117 USING lv_batch_id,
9118 v_instance_code;
9119
9120
9121 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
9122 (p_app_short_name => 'MSC',
9123 p_error_code => 'MSC_PP_INVALID_VALUE',
9124 p_message_text => lv_message_text,
9125 p_error_text => lv_error_text,
9126 p_token1 => 'COLUMN_NAME',
9127 p_token_value1 => 'PARTNER_TYPE');
9128
9129 IF lv_return <> 0 THEN
9130 RAISE ex_logging_err;
9131 END IF;
9132
9133 -- Error out records where partner_type NOT in (1,2,3)
9134 v_sql_stmt := 41;
9135 lv_sql_stmt :=
9136 'UPDATE msc_st_location_associations'
9137 ||' SET process_flag = '||G_ERROR_FLG||','
9138 ||' error_text = '||''''||lv_message_text||''''
9139 ||' WHERE sr_instance_code = :v_instance_code'
9140 ||' AND batch_id = :lv_batch_id'
9141 ||' AND process_flag = '||G_IN_PROCESS
9142 ||' AND partner_type NOT IN (1,2,3)' ;
9143
9144
9145 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
9146 EXECUTE IMMEDIATE lv_sql_stmt
9147 USING v_instance_code,
9148 lv_batch_id;
9149
9150 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
9151 (p_app_short_name => 'MSC',
9152 p_error_code => 'MSC_PP_INVALID_VALUE',
9153 p_message_text => lv_message_text,
9154 p_error_text => lv_error_text,
9155 p_token1 => 'COLUMN_NAME',
9156 p_token_value1 => 'ORGANIZATION_CODE');
9157
9158 IF lv_return <> 0 THEN
9159 RAISE ex_logging_err;
9160 END IF;
9161
9162 -- Update organization_id
9163 lv_return :=msc_st_util.derive_partner_org_id
9164 (p_table_name =>'MSC_ST_LOCATION_ASSOCIATIONS',
9165 p_org_partner_name =>'ORGANIZATION_CODE',
9166 p_org_partner_id =>'ORGANIZATION_ID',
9167 p_instance_code => v_instance_code,
9168 p_partner_type => G_ORGANIZATION,
9169 p_severity => G_SEV_ERROR,
9170 p_message_text => lv_message_text,
9171 p_batch_id =>lv_batch_id,
9172 p_debug => v_debug,
9173 p_error_text =>lv_error_text);
9174
9175 IF lv_return <> 0 THEN
9176 RAISE ex_logging_err;
9177 END IF;
9178
9179 --Update sr_tp_id (organizations)
9180 v_sql_stmt := 41.1;
9181 lv_sql_stmt :=
9182 'UPDATE msc_st_location_associations mla'
9183 ||' SET SR_TP_ID = ORGANIZATION_ID'
9184 ||' WHERE process_flag = '||G_IN_PROCESS
9185 ||' AND partner_type = '||G_ORGANIZATION
9186 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
9187 ||' AND sr_instance_code = :v_instance_code';
9188
9189
9190 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
9191
9192 EXECUTE IMMEDIATE lv_sql_stmt
9193 USING lv_batch_id,
9194 v_instance_code;
9195
9196
9197
9198
9199
9200 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
9201 (p_app_short_name => 'MSC',
9202 p_error_code => 'MSC_PP_INVALID_VALUE',
9203 p_message_text => lv_message_text,
9204 p_error_text => lv_error_text,
9205 p_token1 => 'COLUMN_NAME',
9206 p_token_value1 => 'PARTNER_NAME');
9207
9208 IF lv_return <> 0 THEN
9209 RAISE ex_logging_err;
9210 END IF;
9211
9212 -- Update sr_tp_id(customer)
9213 lv_return :=msc_st_util.derive_partner_org_id
9214 (p_table_name =>'MSC_ST_LOCATION_ASSOCIATIONS',
9215 p_org_partner_name =>'PARTNER_NAME',
9216 p_org_partner_id =>'SR_TP_ID',
9217 p_instance_code => v_instance_code,
9218 p_partner_type => G_CUSTOMER,
9219 p_batch_id =>lv_batch_id,
9220 p_debug => v_debug,
9221 p_error_text =>lv_error_text);
9222
9223 IF lv_return <> 0 THEN
9224 RAISE ex_logging_err;
9225 END IF;
9226
9227 -- Update sr_tp_id(supplier)
9228 lv_return :=msc_st_util.derive_partner_org_id
9229 (p_table_name =>'MSC_ST_LOCATION_ASSOCIATIONS',
9230 p_org_partner_name =>'PARTNER_NAME',
9231 p_org_partner_id =>'SR_TP_ID',
9232 p_instance_code => v_instance_code,
9233 p_partner_type => G_VENDOR,
9234 p_severity => G_SEV_ERROR,
9235 p_message_text => lv_message_text,
9236 p_batch_id => lv_batch_id,
9237 p_debug => v_debug,
9238 p_error_text => lv_error_text);
9239
9240 IF lv_return <> 0 THEN
9241 RAISE ex_logging_err;
9242 END IF;
9243
9244
9245 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
9246 (p_app_short_name => 'MSC',
9247 p_error_code => 'MSC_PP_INVALID_VALUE',
9248 p_message_text => lv_message_text,
9249 p_error_text => lv_error_text,
9250 p_token1 => 'COLUMN_NAME',
9251 p_token_value1 => 'TP_SITE_CODE');
9252
9253 IF lv_return <> 0 THEN
9254 RAISE ex_logging_err;
9255 END IF;
9256
9257 -- Derive sr_tp_site_id(Customer)
9258 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
9259 (p_table_name => 'MSC_ST_LOCATION_ASSOCIATIONS',
9260 p_partner_name => 'PARTNER_NAME',
9261 p_partner_site_code => 'TP_SITE_CODE',
9262 p_partner_site_id => 'SR_TP_SITE_ID',
9263 p_instance_code => v_instance_code,
9264 p_partner_type => G_CUSTOMER,
9265 p_severity => G_SEV_ERROR,
9266 p_message_text => lv_message_text,
9267 p_error_text => lv_error_text,
9268 p_batch_id => lv_batch_id,
9269 p_debug => v_debug,
9270 p_row => lv_column_names);
9271
9272 IF lv_return <> 0 THEN
9273 RAISE ex_logging_err;
9274 END IF;
9275
9276 -- Derive sr_tp_site_id(Supplier)
9277 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
9278 (p_table_name => 'MSC_ST_LOCATION_ASSOCIATIONS',
9279 p_partner_name => 'PARTNER_NAME',
9280 p_partner_site_code => 'TP_SITE_CODE',
9281 p_partner_site_id => 'SR_TP_SITE_ID',
9282 p_instance_code => v_instance_code,
9283 p_partner_type => G_VENDOR,
9284 p_severity => G_SEV_ERROR,
9285 p_message_text => lv_message_text,
9286 p_error_text => lv_error_text,
9287 p_batch_id => lv_batch_id,
9288 p_debug => v_debug,
9289 p_row => lv_column_names);
9290
9291 IF lv_return <> 0 THEN
9292 RAISE ex_logging_err;
9293 END IF;
9294
9295
9296 --Deriving location_id
9297 v_sql_stmt := 42;
9298 lv_sql_stmt :=
9299 'UPDATE msc_st_location_associations mla'
9300 ||' SET location_id = (SELECT local_id'
9301 ||' FROM msc_local_id_setup mls'
9302 ||' WHERE mls.char1 = mla.sr_instance_code'
9303 ||' AND mls.char3 = mla.location_code'
9304 ||' AND mls.entity_name = ''LOCATION_ID'' )'
9305 ||' WHERE process_flag = '||G_IN_PROCESS
9306 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
9307 ||' AND sr_instance_code = :v_instance_code';
9308
9309
9310 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
9311
9312 EXECUTE IMMEDIATE lv_sql_stmt
9313 USING lv_batch_id,
9314 v_instance_code;
9315
9316 /*
9317 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
9318 (p_app_short_name => 'MSC',
9319 p_error_code => 'MSC_PP_INVALID_VALUE',
9320 p_message_text => lv_message_text,
9321 p_error_text => lv_error_text,
9322 p_token1 => 'COLUMN_NAME',
9323 p_token_value1 => 'ORGANIZATION_CODE AND LOCATION_CODE');
9324
9325 IF lv_return <> 0 THEN
9326 RAISE ex_logging_err;
9327 END IF;
9328
9329 -- Error out the record if location_id is NULL
9330 v_sql_stmt := 43;
9331 lv_sql_stmt :=
9332 'UPDATE msc_st_location_associations'
9333 ||' SET process_flag = '||G_ERROR_FLG||','
9334 ||' error_text = '||''''||lv_message_text||''''
9335 ||' WHERE NVL(location_id,'||NULL_VALUE||')= '||NULL_VALUE
9336 ||' AND batch_id = :lv_batch_id'
9337 ||' AND process_flag = '||G_IN_PROCESS
9338 ||' AND sr_instance_code = :v_instance_code';
9339
9340 IF V_DEBUG THEN
9341 msc_st_util.log_message(lv_sql_stmt);
9342 END IF;
9343 EXECUTE IMMEDIATE lv_sql_stmt
9344 USING lv_batch_id,
9345 v_instance_code;
9346
9347 */
9348
9349
9350
9351
9352
9353 --Call to customised validation.
9354 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
9355 (ERRBUF => lv_error_text,
9356 RETCODE => lv_return,
9357 pBatchID => lv_batch_id,
9358 pInstanceCode => v_instance_code,
9359 pEntityName => 'MSC_ST_LOCATION_ASSOCIATIONS',
9360 pInstanceID => v_instance_id);
9361
9362 IF NVL(lv_return,0) <> 0 THEN
9363 RAISE ex_logging_err;
9364 END IF;
9365
9366 -- generation location id's for new locations
9367
9368 IF (v_install_msc) THEN -- IF MSC installed then only do this
9369 OPEN c14(lv_batch_id);
9370 FETCH c14 BULK COLLECT INTO lb_rowid ;
9371
9372 IF c14%ROWCOUNT > 0 THEN
9373 v_sql_stmt := 43.1;
9374 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
9375 UPDATE msc_st_location_associations
9376 SET location_id = msc_st_location_id_s.NEXTVAL
9377 WHERE rowid = lb_rowid(j);
9378
9379 -- Insert record in LID
9380 v_sql_stmt := 43.2;
9381 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
9382 INSERT INTO msc_local_id_setup
9383 (local_id,
9384 st_transaction_id,
9385 instance_id,
9386 entity_name,
9387 data_source_type,
9388 char1,
9389 char3,
9390 SOURCE_SR_TP_ID,
9391 SOURCE_SR_TP_SITE_ID,
9392 last_update_date,
9393 last_updated_by,
9394 creation_date,
9395 created_by)
9396 SELECT
9397 location_id,
9398 st_transaction_id,
9399 v_instance_id,
9400 'LOCATION_ID',
9401 data_source_type,
9402 v_instance_code,
9403 location_code,
9404 SOURCE_SR_TP_ID,
9405 SOURCE_SR_TP_SITE_ID,
9406 v_current_date,
9407 v_current_user,
9408 v_current_date,
9409 v_current_user
9410 FROM msc_st_location_associations
9411 WHERE rowid = lb_rowid(j);
9412 END IF;
9413 CLOSE C14;
9414
9415 --Deriving location_id
9416 v_sql_stmt := 43.3;
9417 lv_sql_stmt :=
9418 'UPDATE msc_st_location_associations mla'
9419 ||' SET location_id = (SELECT local_id'
9420 ||' FROM msc_local_id_setup mls'
9421 ||' WHERE mls.char1 = mla.sr_instance_code'
9422 ||' AND mls.char3 = mla.location_code'
9423 ||' AND mls.entity_name = ''LOCATION_ID'' )'
9424 ||' WHERE process_flag = '||G_IN_PROCESS
9425 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
9426 ||' AND sr_instance_code = :v_instance_code';
9427
9428
9429 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
9430
9431 EXECUTE IMMEDIATE lv_sql_stmt
9432 USING lv_batch_id,
9433 v_instance_code;
9434
9435 END IF ; -- v_install_msc
9436
9437
9438 -- Update partner_site_id with location id for orgs
9439 v_sql_stmt := 43.4;
9440 lv_sql_stmt :=
9441 'UPDATE msc_st_location_associations'
9442 ||' SET partner_site_id = location_id'
9443 ||' WHERE NVL(partner_site_id,'||NULL_VALUE||')= '||NULL_VALUE
9444 ||' AND batch_id = :lv_batch_id'
9445 ||' AND partner_type = '||G_ORGANIZATION
9446 ||' AND process_flag = '||G_IN_PROCESS
9447 ||' AND sr_instance_code = :v_instance_code';
9448
9449
9450 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
9451 EXECUTE IMMEDIATE lv_sql_stmt
9452 USING lv_batch_id,
9453 v_instance_code;
9454
9455
9456 -- Set the process flag as Valid and populate instance_id
9457 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
9458 (p_table_name => 'MSC_ST_LOCATION_ASSOCIATIONS',
9459 p_instance_id => v_instance_id,
9460 p_instance_code => v_instance_code,
9461 p_process_flag => G_VALID,
9462 p_error_text => lv_error_text,
9463 p_debug => v_debug,
9464 p_batch_id => lv_batch_id);
9465
9466 IF lv_return <> 0 THEN
9467 RAISE ex_logging_err;
9468 END IF;
9469
9470 -- At the end calling the LOG_ERROR for logging all
9471 -- errored out records.
9472 lv_return := MSC_ST_UTIL.LOG_ERROR
9473 (p_table_name => 'MSC_ST_LOCATION_ASSOCIATIONS',
9474 p_instance_code => v_instance_code,
9475 p_row => lv_column_names,
9476 p_severity => G_SEV_ERROR,
9477 p_message_text => NULL,
9478 p_error_text => lv_error_text,
9479 p_debug => v_debug,
9480 p_batch_id => lv_batch_id );
9481
9482 IF lv_return <> 0 THEN
9483 RAISE ex_logging_err;
9484 END IF;
9485
9486 COMMIT;
9487 END LOOP;
9488
9489
9490 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
9491 (p_app_short_name => 'MSC',
9492 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
9493 p_message_text => lv_message_text,
9494 p_error_text => lv_error_text);
9495
9496 IF lv_return <> 0 THEN
9497 RAISE ex_logging_err;
9498 END IF;
9499
9500 --Validation check for the table MSC_ST_PARTNER_CONTACTS
9501
9502 --Duplicate records check for the records whose source is other than XML
9503 --Different SQL is used because in XML we can identify the latest records
9504 --whereas in batch load we cannot.
9505
9506 v_sql_stmt := 45;
9507 lv_sql_stmt :=
9508 'UPDATE msc_st_partner_contacts mpc1 '
9509 ||' SET process_flag = '||G_ERROR_FLG||','
9510 ||' error_text = '||''''||lv_message_text||''''
9511 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_partner_contacts mpc2 '
9512 ||' WHERE mpc2.sr_instance_code = mpc1.sr_instance_code'
9513 ||' AND NVL(mpc2.company_name, '||''''||NULL_CHAR||''''||') = '
9514 ||' NVL(mpc1.company_name, '||''''||NULL_CHAR||''''||')'
9515 ||' AND mpc2.partner_name = mpc1.partner_name '
9516 ||' AND mpc2.partner_type = mpc1.partner_type '
9517 ||' AND mpc2.tp_site_code = mpc1.tp_site_code '
9518 ||' AND mpc2.process_flag = mpc1.process_flag '
9519 ||' AND NVL(mpc2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
9520 ||' GROUP BY sr_instance_code,company_name,partner_name,'
9521 ||' tp_site_code,partner_type '
9522 ||' HAVING COUNT(*) >1 )'
9523 ||' AND mpc1.process_flag = '||G_IN_PROCESS
9524 ||' AND mpc1.sr_instance_code = :v_instance_code'
9525 ||' AND NVL(mpc1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
9526
9527
9528 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
9529
9530 EXECUTE IMMEDIATE lv_sql_stmt
9531 USING v_instance_code;
9532
9533
9534 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
9535 (p_app_short_name => 'MSC',
9536 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
9537 p_message_text => lv_message_text,
9538 p_error_text => lv_error_text);
9539
9540 IF lv_return <> 0 THEN
9541 RAISE ex_logging_err;
9542 END IF;
9543
9544 --Duplicate records check for the records whose source is XML
9545 v_sql_stmt := 46;
9546 lv_sql_stmt :=
9547 'UPDATE msc_st_partner_contacts mpc1 '
9548 ||' SET process_flag = '||G_ERROR_FLG||','
9549 ||' error_text = '||''''||lv_message_text||''''
9550 ||' WHERE message_id < ( SELECT max(message_id) '
9551 ||' FROM msc_st_partner_contacts mpc2 '
9552 ||' WHERE mpc2.sr_instance_code = mpc1.sr_instance_code'
9553 ||' AND NVL(mpc2.company_name, '||''''||NULL_CHAR||''''||') = '
9554 ||' NVL(mpc1.company_name, '||''''||NULL_CHAR||''''||')'
9555 ||' AND mpc2.partner_name = mpc1.partner_name '
9556 ||' AND mpc2.partner_type = mpc1.partner_type '
9557 ||' AND mpc2.tp_site_code = mpc1.tp_site_code '
9558 ||' AND mpc2.process_flag = mpc1.process_flag '
9559 ||' AND NVL(mpc2.message_id,'||NULL_VALUE||') <> '||NULL_VALUE||')'
9560 ||' AND mpc1.process_flag = '||G_IN_PROCESS
9561 ||' AND mpc1.sr_instance_code = :v_instance_code '
9562 ||' AND NVL(mpc1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
9563
9564
9565 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
9566
9567 EXECUTE IMMEDIATE lv_sql_stmt
9568 USING v_instance_code;
9569
9570 lv_column_names :=
9571 'PARTNER_NAME ||''~''||'
9572 ||'TP_SITE_CODE ||''~''||'
9573 ||'PARTNER_TYPE ||''~''||'
9574 ||'NAME ||''~''||'
9575 ||'SR_INSTANCE_CODE ||''~''||'
9576 ||'DISPLAY_NAME ||''~''||'
9577 ||'EMAIL ||''~''||'
9578 ||'FAX ||''~''||'
9579 ||'DELETED_FLAG ||''~''||'
9580 ||'COMPANY_NAME ||''~''||'
9581 ||'ENABLED_FLAG ';
9582
9583
9584 -- Dividing records in batches based on batchsize
9585 LOOP
9586 v_sql_stmt := 47;
9587 SELECT msc_st_batch_id_s.NEXTVAL
9588 INTO lv_batch_id
9589 FROM DUAL;
9590
9591 v_sql_stmt := 48;
9592 lv_sql_stmt :=
9593 'UPDATE msc_st_partner_contacts '
9594 ||' SET batch_id = :lv_batch_id '
9595 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
9596 ||' AND sr_instance_code = :v_instance_code'
9597 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
9598 ||' AND rownum <= '||v_batch_size;
9599
9600
9601 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
9602
9603 EXECUTE IMMEDIATE lv_sql_stmt
9604 USING lv_batch_id,
9605 v_instance_code;
9606
9607 EXIT WHEN SQL%NOTFOUND ;
9608
9609 OPEN c8(lv_batch_id);
9610 FETCH c8 BULK COLLECT INTO lb_rowid;
9611 CLOSE c8;
9612
9613 v_sql_stmt := 49;
9614 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
9615 UPDATE msc_st_partner_contacts
9616 SET st_transaction_id = msc_st_partner_contacts_s.NEXTVAL,
9617 refresh_id = v_refresh_id,
9618 last_update_date = v_current_date,
9619 last_updated_by = v_current_user,
9620 creation_date = v_current_date,
9621 created_by = v_current_user
9622 WHERE rowid = lb_rowid(j);
9623
9624 /*
9625 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
9626 (p_app_short_name => 'MSC',
9627 p_error_code => 'MSC_PP_NO_DELETION',
9628 p_message_text => lv_message_text,
9629 p_error_text => lv_error_text,
9630 p_token1 => 'TABLE_NAME',
9631 p_token_value1 => 'MSC_ST_PARTNER_CONTACTS');
9632
9633 -- Deletion is not allowed for this table
9634 v_sql_stmt := 50;
9635 lv_sql_stmt :=
9636 'UPDATE msc_st_partner_contacts '
9637 ||' SET process_flag = '||G_ERROR_FLG||','
9638 ||' error_text = '||''''||lv_message_text||''''
9639 ||' WHERE deleted_flag = '||SYS_YES
9640 ||' AND process_flag = '||G_IN_PROCESS
9641 ||' AND batch_id = :lv_batch_id'
9642 ||' AND sr_instance_code = :v_instance_code';
9643
9644 IF V_DEBUG THEN
9645 msc_st_util.log_message(lv_sql_stmt);
9646 END IF;
9647
9648 EXECUTE IMMEDIATE lv_sql_stmt
9649 USING lv_batch_id,
9650 v_instance_code;
9651
9652 */
9653
9654
9655 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
9656 (p_app_short_name => 'MSC',
9657 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
9658 p_message_text => lv_message_text,
9659 p_error_text => lv_error_text,
9660 p_token1 => 'COLUMN_NAME',
9661 p_token_value1 => 'DELETED_FLAG',
9662 p_token2 => 'DEFAULT_VALUE',
9663 p_token_value2 => SYS_NO);
9664
9665 IF lv_return <> 0 THEN
9666 RAISE ex_logging_err;
9667 END IF;
9668
9669 -- Check DELETE_FLAG column has valid value or not and if not set it to SYS_NO
9670 -- Log error procedure inserts warning and also defaults the delete flag
9671
9672 lv_where_str := ' AND NVL(deleted_flag,'||NULL_VALUE||') '
9673 ||' NOT IN(1,2)';
9674
9675 lv_return := MSC_ST_UTIL.LOG_ERROR
9676 (p_table_name => 'MSC_ST_PARTNER_CONTACTS',
9677 p_instance_code => v_instance_code,
9678 p_row => lv_column_names,
9679 p_severity => G_SEV_WARNING,
9680 p_message_text => lv_message_text,
9681 p_error_text => lv_error_text,
9682 p_batch_id => lv_batch_id,
9683 p_where_str => lv_where_str,
9684 p_col_name => 'DELETED_FLAG',
9685 p_debug => v_debug,
9686 p_default_value => SYS_NO);
9687
9688 IF lv_return <> 0 THEN
9689 RAISE ex_logging_err;
9690 END IF;
9691
9692 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
9693 (p_app_short_name => 'MSC',
9694 p_error_code => 'MSC_PP_COL_VAL_NULL',
9695 p_message_text => lv_message_text,
9696 p_error_text => lv_error_text,
9697 p_token1 => 'COLUMN_NAME',
9698 p_token_value1 => 'PARTNER_NAME OR '
9699 ||'TP_SITE_CODE OR '
9700 ||'NAME ');
9701
9702 IF lv_return <> 0 THEN
9703 RAISE ex_logging_err;
9704 END IF;
9705
9706 -- Error out records where partner_name/tp_site_code/name is NULL
9707 v_sql_stmt := 51;
9708 lv_sql_stmt :=
9709 'UPDATE msc_st_partner_contacts'
9710 ||' SET process_flag = '||G_ERROR_FLG||','
9711 ||' error_text = '||''''||lv_message_text||''''
9712 ||' WHERE (NVL(partner_name,'||''''||NULL_CHAR||''''||') '
9713 ||' = '||''''||NULL_CHAR||''''
9714 ||' OR NVL(tp_site_code, '||''''||NULL_CHAR||''''||') '
9715 ||' = '||''''||NULL_CHAR||''''
9716 ||' OR NVL(name, '||''''||NULL_CHAR||''''||') '
9717 ||' = '||''''||NULL_CHAR||''''||') '
9718 ||' AND batch_id = :lv_batch_id'
9719 ||' AND process_flag = '||G_IN_PROCESS
9720 ||' AND deleted_flag = '||SYS_NO
9721 ||' AND sr_instance_code = :v_instance_code';
9722
9723
9724 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
9725 EXECUTE IMMEDIATE lv_sql_stmt
9726 USING lv_batch_id,
9727 v_instance_code;
9728
9729
9730 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
9731 (p_app_short_name => 'MSC',
9732 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
9733 p_message_text => lv_message_text,
9734 p_error_text => lv_error_text,
9735 p_token1 => 'COLUMN_NAME',
9736 p_token_value1 => 'PARTNER_TYPE');
9737
9738 IF lv_return <> 0 THEN
9739 RAISE ex_logging_err;
9740 END IF;
9741
9742 -- Error out records where partner_type NOT in (1,2)
9743 v_sql_stmt := 52;
9744 lv_sql_stmt :=
9745 'UPDATE msc_st_partner_contacts'
9746 ||' SET process_flag = '||G_ERROR_FLG||','
9747 ||' error_text = '||''''||lv_message_text||''''
9748 ||' WHERE sr_instance_code = :v_instance_code'
9749 ||' AND batch_id = :lv_batch_id'
9750 ||' AND process_flag = '||G_IN_PROCESS
9751 ||' AND partner_type NOT IN (1,2)' ;
9752
9753
9754 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
9755 EXECUTE IMMEDIATE lv_sql_stmt
9756 USING v_instance_code,
9757 lv_batch_id;
9758
9759 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
9760 (p_app_short_name => 'MSC',
9761 p_error_code => 'MSC_PP_INVALID_VALUE',
9762 p_message_text => lv_message_text,
9763 p_error_text => lv_error_text,
9764 p_token1 => 'COLUMN_NAME',
9765 p_token_value1 => 'PARTNER_NAME');
9766
9767 IF lv_return <> 0 THEN
9768 RAISE ex_logging_err;
9769 END IF;
9770
9771 -- Update sr_tp_id(customer)
9772 lv_return :=msc_st_util.derive_partner_org_id
9773 (p_table_name =>'MSC_ST_PARTNER_CONTACTS',
9774 p_org_partner_name =>'PARTNER_NAME',
9775 p_org_partner_id =>'PARTNER_ID',
9776 p_instance_code => v_instance_code,
9777 p_partner_type => G_CUSTOMER,
9778 p_batch_id =>lv_batch_id,
9779 p_debug => v_debug,
9780 p_error_text =>lv_error_text);
9781
9782 IF lv_return <> 0 THEN
9783 RAISE ex_logging_err;
9784 END IF;
9785
9786 -- Update sr_tp_id(supplier)
9787 lv_return :=msc_st_util.derive_partner_org_id
9788 (p_table_name =>'MSC_ST_PARTNER_CONTACTS',
9789 p_org_partner_name =>'PARTNER_NAME',
9790 p_org_partner_id =>'PARTNER_ID',
9791 p_instance_code => v_instance_code,
9792 p_partner_type => G_VENDOR,
9793 p_severity => G_SEV_ERROR,
9794 p_message_text => lv_message_text,
9795 p_batch_id => lv_batch_id,
9796 p_debug => v_debug,
9797 p_error_text => lv_error_text);
9798
9799 IF lv_return <> 0 THEN
9800 RAISE ex_logging_err;
9801 END IF;
9802
9803 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
9804 (p_app_short_name => 'MSC',
9805 p_error_code => 'MSC_PP_INVALID_VALUE',
9806 p_message_text => lv_message_text,
9807 p_error_text => lv_error_text,
9808 p_token1 => 'COLUMN_NAME',
9809 p_token_value1 => 'TP_SITE_CODE');
9810
9811 IF lv_return <> 0 THEN
9812 RAISE ex_logging_err;
9813 END IF;
9814
9815 -- Derive sr_tp_site_id(Customer)
9816 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
9817 (p_table_name => 'MSC_ST_PARTNER_CONTACTS',
9818 p_partner_name => 'PARTNER_NAME',
9819 p_partner_site_code => 'TP_SITE_CODE',
9820 p_partner_site_id => 'PARTNER_SITE_ID',
9821 p_instance_code => v_instance_code,
9822 p_partner_type => G_CUSTOMER,
9823 p_error_text => lv_error_text,
9824 p_batch_id => lv_batch_id,
9825 p_debug => v_debug,
9826 p_row => lv_column_names);
9827
9828 IF lv_return <> 0 THEN
9829 RAISE ex_logging_err;
9830 END IF;
9831
9832 -- Derive sr_tp_site_id(Supplier)
9833 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
9834 (p_table_name => 'MSC_ST_PARTNER_CONTACTS',
9835 p_partner_name => 'PARTNER_NAME',
9836 p_partner_site_code => 'TP_SITE_CODE',
9837 p_partner_site_id => 'PARTNER_SITE_ID',
9838 p_instance_code => v_instance_code,
9839 p_partner_type => G_VENDOR,
9840 p_severity => G_SEV_ERROR,
9841 p_message_text => lv_message_text,
9842 p_error_text => lv_error_text,
9843 p_batch_id => lv_batch_id,
9844 p_debug => v_debug,
9845 p_row => lv_column_names);
9846
9847 IF lv_return <> 0 THEN
9848 RAISE ex_logging_err;
9849 END IF;
9850
9851 --Call to customised validation.
9852 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
9853 (ERRBUF => lv_error_text,
9854 RETCODE => lv_return,
9855 pBatchID => lv_batch_id,
9856 pInstanceCode => v_instance_code,
9857 pEntityName => 'MSC_ST_PARTNER_CONTACTS',
9858 pInstanceID => v_instance_id);
9859
9860 IF NVL(lv_return,0) <> 0 THEN
9861 RAISE ex_logging_err;
9862 END IF;
9863
9864 -- Set the process flag as Valid and populate instance_id
9865 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
9866 (p_table_name => 'MSC_ST_PARTNER_CONTACTS',
9867 p_instance_id => v_instance_id,
9868 p_instance_code => v_instance_code,
9869 p_process_flag => G_VALID,
9870 p_error_text => lv_error_text,
9871 p_debug => v_debug,
9872 p_batch_id => lv_batch_id);
9873
9874 IF lv_return <> 0 THEN
9875 RAISE ex_logging_err;
9876 END IF;
9877
9878 -- At the end calling the LOG_ERROR for logging all
9879 -- errored out records.
9880 lv_return := MSC_ST_UTIL.LOG_ERROR
9881 (p_table_name => 'MSC_ST_PARTNER_CONTACTS',
9882 p_instance_code => v_instance_code,
9883 p_row => lv_column_names,
9884 p_severity => G_SEV_ERROR,
9885 p_message_text => NULL,
9886 p_error_text => lv_error_text,
9887 p_debug => v_debug,
9888 p_batch_id => lv_batch_id );
9889
9890 IF lv_return <> 0 THEN
9891 RAISE ex_logging_err;
9892 END IF;
9893
9894 COMMIT;
9895 END LOOP;
9896
9897
9898 --Validation for GROUPS IS
9899
9900 lv_return := MSC_ST_util.GET_ERROR_MESSAGE
9901 (p_app_short_name => 'MSC',
9902 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
9903 p_message_text => lv_message_text,
9904 p_error_text => lv_error_text);
9905
9906 IF lv_return <> 0 THEN
9907 RAISE ex_logging_err;
9908 END IF;
9909
9910 --Duplicate records check for the records whose source is XML
9911 v_sql_stmt := 52;
9912 lv_sql_stmt :=
9913 ' UPDATE MSC_ST_GROUPS msu1'
9914 ||' SET process_flag = '||G_ERROR_FLG||','
9915 ||' error_text = '||''''||lv_message_text||''''
9916 ||' WHERE message_id < (SELECT MAX(message_id)'
9917 ||' FROM MSC_ST_GROUPS msu2'
9918 ||' where msu2.group_name = msu1.group_name '
9919 ||' AND msu2.process_flag <> '||G_ERROR_FLG
9920 ||' AND NVL(msu2.message_id,'||NULL_VALUE||')<>'||NULL_VALUE||')'
9921 ||' AND msu1.process_flag = '||G_IN_PROCESS
9922 ||' AND msu1.sr_instance_code = :v_instance_code'
9923 ||' AND NVL(msu1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
9924
9925
9926 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
9927
9928 EXECUTE IMMEDIATE lv_sql_stmt
9929 USING v_instance_code;
9930
9931 lv_return := MSC_ST_util.GET_ERROR_MESSAGE
9932 (p_app_short_name => 'MSC',
9933 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
9934 p_message_text => lv_message_text,
9935 p_error_text => lv_error_text);
9936
9937 IF lv_return <> 0 THEN
9938 RAISE ex_logging_err;
9939 END IF;
9940
9941 --Duplicate records check for the records whose source is other than XML
9942 --Different SQL is used because in XML we can identify the latest records
9943 --whereas in batch load we cannot.
9944
9945 v_sql_stmt := 53;
9946 lv_sql_stmt :=
9947 ' UPDATE MSC_ST_GROUPS msu1'
9948 ||' SET process_flag = '||G_ERROR_FLG||','
9949 ||' error_text = '||''''||lv_message_text||''''
9950 ||' WHERE EXISTS( SELECT 1 '
9951 ||' FROM MSC_ST_GROUPS msu2'
9952 ||' WHERE msu2.group_name = msu1.group_name'
9953 ||' AND msu2.process_flag <> '||G_ERROR_FLG
9954 ||' AND NVL(msu2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
9955 ||' AND msu2.rowid <> msu1.rowid)'
9956 ||' AND msu1.process_flag = '||G_IN_PROCESS
9957 ||' AND msu1.sr_instance_code = :v_instance_code '
9958 ||' AND NVL(msu1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
9959
9960
9961 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
9962
9963 EXECUTE IMMEDIATE lv_sql_stmt
9964 USING v_instance_code;
9965
9966 lv_column_names :=
9967 'GROUP_NAME ||''~''||'
9968 ||' DESCRIPTION ||''~''||'
9969 ||' GROUP_TYPE ||''~''||'
9970 ||' CONTACT_USER_NAME ||''~''||'
9971 ||' CONTRACT_DOC_URL ||''~''||'
9972 ||' EFFECTIVE_DATE ||''~''||'
9973 ||' DISABLE_DATE ||''~''||'
9974 ||' CONTEXT ||''~''||'
9975 ||' ATTRIBUTE1 ||''~''||'
9976 ||' ATTRIBUTE2 ||''~''||'
9977 ||' ATTRIBUTE3 ||''~''||'
9978 ||' ATTRIBUTE4 ||''~''||'
9979 ||' ATTRIBUTE5 ||''~''||'
9980 ||' ATTRIBUTE6 ||''~''||'
9981 ||' ATTRIBUTE7 ||''~''||'
9982 ||' ATTRIBUTE8 ||''~''||'
9983 ||' ATTRIBUTE9 ||''~''||'
9984 ||' ATTRIBUTE10 ||''~''||'
9985 ||' ATTRIBUTE11 ||''~''||'
9986 ||' ATTRIBUTE12 ||''~''||'
9987 ||' ATTRIBUTE13 ||''~''||'
9988 ||' ATTRIBUTE14 ||''~''||'
9989 ||' ATTRIBUTE15 ||''~''||'
9990 ||' SR_INSTANCE_CODE ||''~''||'
9991 ||' DELETED_FLAG ' ;
9992
9993
9994 -- Dividing records in batches based on batchsize
9995 LOOP
9996 v_sql_stmt := 54;
9997 SELECT msc_st_batch_id_s.NEXTVAL
9998 INTO lv_batch_id
9999 FROM dual;
10000
10001 v_sql_stmt := 55;
10002 lv_sql_stmt :=
10003 ' UPDATE MSC_ST_GROUPS '
10004 ||' SET batch_id = :lv_batch_id'
10005 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
10006 ||' AND sr_instance_code = :v_instance_code'
10007 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
10008 ||' AND rownum <= '||v_batch_size;
10009
10010
10011 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
10012
10013 EXECUTE IMMEDIATE lv_sql_stmt
10014 USING lv_batch_id,
10015 v_instance_code;
10016
10017 EXIT WHEN SQL%NOTFOUND;
10018
10019 -- updation of WHO columns
10020
10021 OPEN c9(lv_batch_id);
10022 FETCH c9 BULK COLLECT INTO lb_rowid;
10023 CLOSE c9;
10024
10025 v_sql_stmt := 56;
10026 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
10027 UPDATE MSC_ST_GROUPS
10028 SET st_transaction_id = msc_st_groups_s.NEXTVAL,
10029 last_update_date = v_current_date,
10030 last_updated_by = v_current_user,
10031 creation_date = v_current_date,
10032 created_by = v_current_user
10033 WHERE rowid = lb_rowid(j);
10034
10035 -- Set the message
10036 lv_return := MSC_ST_util.GET_ERROR_MESSAGE
10037 (p_app_short_name => 'MSC',
10038 p_error_code => 'MSC_PP_NO_DELETION',
10039 p_message_text => lv_message_text,
10040 p_error_text => lv_error_text,
10041 p_token1 => 'TABLE_NAME',
10042 p_token_value1 => 'MSC_ST_GROUPS');
10043
10044 IF lv_return <> 0 THEN
10045 RAISE ex_logging_err;
10046 END IF;
10047
10048 --Deletion is not allowed on this table.
10049 v_sql_stmt := 57;
10050 lv_sql_stmt :=
10051 ' UPDATE msc_st_groups '
10052 ||' SET process_flag ='||G_ERROR_FLG||','
10053 ||' error_text = '||''''||lv_message_text||''''
10054 ||' WHERE deleted_flag = '||SYS_YES
10055 ||' AND process_flag = '||G_IN_PROCESS
10056 ||' AND batch_id = :lv_batch_id'
10057 ||' AND sr_instance_code = :v_instance_code';
10058
10059
10060 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
10061
10062 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
10063
10064 -- Set the message for deleted flag
10065
10066 lv_return := MSC_ST_util.GET_ERROR_MESSAGE
10067 (p_app_short_name => 'MSC',
10068 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
10069 p_message_text => lv_message_text,
10070 p_error_text => lv_error_text,
10071 p_token1 => 'COLUMN_NAME',
10072 p_token_value1 => 'DELETED_FLAG',
10073 p_token2 => 'DEFAULT_VALUE',
10074 p_token_value2 => SYS_NO);
10075
10076 IF lv_return <> 0 THEN
10077 RAISE ex_logging_err;
10078 END IF;
10079
10080 -- Check DELETED_FLAG column has valid value or not and
10081 -- if not set it to SYS_NO
10082
10083 lv_where_str :=
10084 ' AND NVL(deleted_flag,'||NULL_VALUE||') NOT IN(1,2)';
10085
10086 lv_return := MSC_ST_util.LOG_ERROR
10087 (p_table_name => 'MSC_ST_GROUPS',
10088 p_instance_code => v_instance_code,
10089 p_row => lv_column_names,
10090 p_severity => G_SEV_WARNING,
10091 p_message_text => lv_message_text,
10092 p_error_text => lv_error_text,
10093 p_batch_id => lv_batch_id,
10094 p_where_str => lv_where_str,
10095 p_col_name => 'DELETED_FLAG',
10096 p_debug => v_debug,
10097 p_default_value => SYS_NO);
10098
10099 IF lv_return <> 0 THEN
10100 RAISE ex_logging_err;
10101 END IF;
10102
10103 -- Set the error message for invalid group type
10104
10105 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
10106 (p_app_short_name => 'MSC',
10107 p_error_code => 'MSC_PP_INVALID_VALUE',
10108 p_message_text => lv_message_text,
10109 p_error_text => lv_error_text,
10110 p_token1 => 'COLUMN_NAME',
10111 p_token_value1 => 'GROUP_TYPE');
10112
10113 IF lv_return <> 0 THEN
10114 RAISE ex_logging_err;
10115 END IF;
10116
10117
10118 -- error out record with GROUP_TYPE NOT IN (1,2)
10119
10120 v_sql_stmt := 58;
10121
10122 lv_sql_Stmt:=
10123 'UPDATE msc_st_groups '
10124 ||' SET process_flag ='||G_ERROR_FLG||','
10125 ||' error_text = '||''''||lv_message_text||''''
10126 ||' WHERE NVL(group_type,'||NULL_VALUE||') NOT IN (1,2) '
10127 ||' AND sr_instance_code = :v_instance_code'
10128 ||' AND process_flag ='|| G_IN_PROCESS
10129 ||' AND batch_id = :lv_batch_id';
10130
10131
10132 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
10133
10134 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
10135
10136
10137 -- The following values are mandatory in MSC_GROUPS
10138 -- 1.Group name
10139 -- 2.Effective Date
10140 -- 3.Contact Doc URL
10141 -- 4.Group Owner Id.
10142
10143 lv_return :=
10144 MSC_ST_util.GET_ERROR_MESSAGE (p_app_short_name => 'MSC',
10145 p_error_code => 'MSC_PP_COL_VAL_NULL',
10146 p_message_text => lv_message_text,
10147 p_error_text => lv_error_text,
10148 p_token1 => 'COLUMN_NAME',
10149 p_token_value1 => 'GROUP_NAME OR '
10150 ||' EFFECTIVE_DATE OR '
10151 ||' CONTRACT_DOC_URL OR '
10152 ||' GROUP_OWNER_ID ');
10153
10154 IF lv_return <> 0 THEN
10155 RAISE ex_logging_err;
10156 END IF;
10157
10158
10159 v_sql_stmt := 59;
10160
10161 lv_sql_stmt :=
10162 ' UPDATE MSC_ST_GROUPS '
10163 ||' SET process_flag = '||G_ERROR_FLG||','
10164 ||' error_text = '||''''||lv_message_text||''''
10165 ||' WHERE (effective_date IS NULL '
10166 ||' OR group_name IS NULL '
10167 ||' OR contract_doc_url IS NULL '
10168 ||' OR group_owner_id IS NULL) '
10169 ||' AND batch_id = :lv_batch_id'
10170 ||' AND process_flag = '||G_IN_PROCESS
10171 ||' AND sr_instance_code = :v_instance_code';
10172
10173
10174 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
10175
10176 EXECUTE IMMEDIATE lv_sql_stmt
10177 USING lv_batch_id,
10178 v_instance_code;
10179
10180 -- Set the error message for DISABLE_DATE should be greater than EFFECTIVE_DATE
10181
10182 lv_return := MSC_ST_util.GET_ERROR_MESSAGE
10183 (p_app_short_name => 'MSC',
10184 p_error_code => 'MSC_PP_END_GT_ST_DATE',
10185 p_message_text => lv_message_text,
10186 p_error_text => lv_error_text);
10187
10188 IF lv_return <> 0 THEN
10189 RAISE ex_logging_err;
10190 END IF;
10191
10192 v_sql_stmt := 60;
10193
10194 lv_sql_stmt :=
10195 ' UPDATE MSC_ST_GROUPS '
10196 ||' SET process_flag = '||G_ERROR_FLG||','
10197 ||' error_text = '||''''||lv_message_text||''''
10198 ||' WHERE effective_date > disable_date'
10199 ||' AND disable_date IS NOT NULL'
10200 ||' AND batch_id = :lv_batch_id'
10201 ||' AND process_flag = '||G_IN_PROCESS
10202 ||' AND sr_instance_code = :v_instance_code';
10203
10204
10205 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
10206
10207 EXECUTE IMMEDIATE lv_sql_stmt
10208 USING lv_batch_id,
10209 v_instance_code;
10210
10211
10212
10213 --Derive contact_user_id
10214
10215 v_sql_stmt := 61;
10216 lv_sql_stmt :=
10217 'UPDATE msc_st_groups msg'
10218 ||' SET contact_user_id = (select user_id '
10219 ||' from fnd_user fu'
10220 ||' where UPPER(fu.user_name) = UPPER(msg.contact_user_name)) '
10221 ||' WHERE contact_user_name IS NOT NULL'
10222 ||' AND batch_id = :lv_batch_id'
10223 ||' AND sr_instance_code = :v_instance_code'
10224 ||' AND process_flag = '||G_IN_PROCESS;
10225
10226
10227 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
10228
10229 EXECUTE IMMEDIATE lv_sql_stmt
10230 USING lv_batch_id,
10231 v_instance_code;
10232
10233
10234 -- Error out the invalid Contact User Name
10235
10236 lv_return := MSC_ST_util.GET_ERROR_MESSAGE
10237 (p_app_short_name => 'MSC',
10238 p_error_code => 'MSC_PP_INVALID_VALUE',
10239 p_message_text => lv_message_text,
10240 p_error_text => lv_error_text,
10241 p_token1 => 'COLUMN_NAME',
10242 p_token_value1 => 'CONTACT_USER_NAME');
10243
10244 IF lv_return <> 0 THEN
10245 RAISE ex_logging_err;
10246 END IF;
10247
10248 -- Update the record as errored out record
10249
10250 v_sql_stmt := 62;
10251 lv_sql_stmt :=
10252 'UPDATE MSC_ST_GROUPS '
10253 ||' SET process_flag = '||G_ERROR_FLG||','
10254 ||' error_text = '||''''||lv_message_text||''''
10255 ||' WHERE contact_user_name IS NOT NULL '
10256 ||' AND contact_user_id IS NULL '
10257 ||' AND batch_id = :lv_batch_id'
10258 ||' AND sr_instance_code = :v_instance_code'
10259 ||' AND process_flag = '||G_IN_PROCESS;
10260
10261
10262 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
10263
10264 EXECUTE IMMEDIATE lv_sql_stmt
10265 USING lv_batch_id,
10266 v_instance_code;
10267
10268 --DERIVE GROUP_ID
10269
10270 lv_return := MSC_ST_util.DERIVE_GROUP_ID
10271 (p_table_name =>'MSC_ST_GROUPS',
10272 p_grp_col_name => 'GROUP_NAME',
10273 p_grp_col_id => 'GROUP_ID',
10274 p_instance_code => v_instance_code,
10275 p_instance_id => v_instance_id,
10276 p_batch_id => lv_batch_id,
10277 p_debug => v_debug,
10278 p_severity => G_SEV_ERROR,
10279 p_error_text => lv_error_text,
10280 p_row => lv_column_names);
10281
10282 IF lv_return <> 0 THEN
10283 RAISE ex_logging_err;
10284 END IF;
10285
10286 select fnd_global.user_id into lv_user_id from dual;
10287
10288 IF NOT MSC_ST_util.IS_OPERATOR(lv_user_id) THEN
10289 lv_return := MSC_ST_util.GET_ERROR_MESSAGE
10290 (p_app_short_name => 'MSC',
10291 p_error_code => 'MSC_PP_INVALID_VALUE',
10292 p_message_text => lv_message_text,
10293 p_error_text => lv_error_text,
10294 p_token1 => 'COLUMN_NAME',
10295 p_token_value1 => 'GROUP_OWNER_ID');
10296
10297 IF lv_return <> 0 THEN
10298 RAISE ex_logging_err;
10299 END IF;
10300
10301 v_sql_stmt := 63;
10302 lv_sql_stmt :=
10303 'UPDATE MSC_ST_GROUPS msg'
10304 ||' SET process_flag = '||G_ERROR_FLG||','
10305 ||' error_text = '||''''||lv_message_text||''''
10306 ||' WHERE EXISTS(SELECT 1 '
10307 ||' FROM MSC_GROUPS mg'
10308 ||' where mg.GROUP_OWNER_ID <> msg.GROUP_OWNER_ID '
10309 ||' AND mg.group_id = msg.group_id )'
10310 ||' AND group_id IS NOT NULL'
10311 ||' AND batch_id = :lv_batch_id'
10312 ||' AND sr_instance_code = :v_instance_code'
10313 ||' AND process_flag = '||G_IN_PROCESS;
10314
10315
10316 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
10317
10318
10319 EXECUTE IMMEDIATE lv_sql_stmt
10320 USING lv_batch_id,
10321 v_instance_code;
10322 END IF;
10323
10324 --Call to customised validation.
10325
10326 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
10327 (ERRBUF => lv_error_text,
10328 RETCODE => lv_return,
10329 pBatchID => lv_batch_id,
10330 pInstanceCode => v_instance_code,
10331 pEntityName => 'MSC_ST_GROUPS',
10332 pInstanceID => v_instance_id);
10333
10334 IF NVL(lv_return,0) <> 0 THEN
10335 RAISE ex_logging_err;
10336 END IF;
10337
10338 -- Generate group_id for the first time
10339
10340 OPEN c10(lv_batch_id);
10341 FETCH c10 BULK COLLECT INTO lb_rowid ;
10342
10343 IF c10%ROWCOUNT > 0 THEN
10344 v_sql_stmt := 64;
10345 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
10346 UPDATE MSC_ST_GROUPS
10347 SET group_id = msc_st_group_id_s.NEXTVAL
10348 WHERE rowid = lb_rowid(j);
10349
10350 v_sql_stmt := 65;
10351 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
10352 INSERT INTO msc_local_id_setup
10353 (local_id,
10354 st_transaction_id,
10355 instance_id,
10356 entity_name,
10357 data_source_type,
10358 char1,
10359 last_update_date,
10360 last_updated_by,
10361 creation_date,
10362 created_by)
10363 SELECT
10364 group_id,
10365 st_transaction_id,
10366 v_instance_id,
10367 'GROUP_ID',
10368 data_source_type,
10369 group_name,
10370 v_current_date,
10371 v_current_user,
10372 v_current_date,
10373 v_current_user
10374 FROM MSC_ST_GROUPS
10375 WHERE rowid = lb_rowid(j);
10376
10377 END IF;
10378 CLOSE c10 ;
10379
10380
10381 -- Set the process flag as Valid and derive sr_instance_id
10382
10383 lv_return := MSC_ST_util.SET_PROCESS_FLAG
10384 (p_table_name => 'MSC_ST_GROUPS',
10385 p_instance_id => v_instance_id,
10386 p_instance_code => v_instance_code,
10387 p_process_flag => G_VALID,
10388 p_error_text => lv_error_text,
10389 p_debug => v_debug,
10390 p_batch_id => lv_batch_id);
10391
10392 IF lv_return <> 0 THEN
10393 RAISE ex_logging_err;
10394 END IF;
10395
10396 -- Inserting all the errored out records into MSC_ERRORS
10397
10398 lv_return := MSC_ST_util.LOG_ERROR
10399 (p_table_name => 'MSC_ST_GROUPS',
10400 p_instance_code => v_instance_code,
10401 p_row => lv_column_names,
10402 p_severity => G_SEV_ERROR,
10403 p_error_text => lv_error_text,
10404 p_message_text => NULL,
10405 p_batch_id => lv_batch_id);
10406
10407
10408 IF lv_return <> 0 THEN
10409 RAISE ex_logging_err;
10410 END IF;
10411
10412 OPEN c11(lv_batch_id);
10413 FETCH c11 BULK COLLECT INTO
10414 lb_GROUP_ID,
10415 lb_GROUP_NAME,
10416 lb_DESCRIPTION,
10417 lb_GROUP_TYPE,
10418 lb_GROUP_OWNER_ID,
10419 lb_CONTACT_USER_ID,
10420 lb_CONTRACT_DOC_URL,
10421 lb_EFFECTIVE_DATE,
10422 lb_DISABLE_DATE,
10423 lb_LAST_UPDATE_DATE,
10424 lb_LAST_UPDATED_BY,
10425 lb_LAST_UPDATE_LOGIN,
10426 lb_CONTEXT,
10427 lb_ATTRIBUTE1,
10428 lb_ATTRIBUTE2,
10429 lb_ATTRIBUTE3,
10430 lb_ATTRIBUTE4,
10431 lb_ATTRIBUTE5,
10432 lb_ATTRIBUTE6,
10433 lb_ATTRIBUTE7,
10434 lb_ATTRIBUTE8,
10435 lb_ATTRIBUTE9,
10436 lb_ATTRIBUTE10,
10437 lb_ATTRIBUTE11,
10438 lb_ATTRIBUTE12,
10439 lb_ATTRIBUTE13,
10440 lb_ATTRIBUTE14,
10441 lb_ATTRIBUTE15;
10442
10443
10444
10445 IF c11%ROWCOUNT > 0 THEN
10446 v_sql_stmt := 66;
10447
10448 FORALL j IN lb_GROUP_ID.FIRST..lb_GROUP_ID.LAST
10449 UPDATE msc_groups
10450 SET description = lb_description(j),
10451 group_type = lb_group_type(j),
10452 owner_contact = lb_contact_user_id(j),
10453 contract_doc_url = lb_contract_doc_url(j),
10454 effective_date = lb_effective_date(j),
10455 disable_date = lb_disable_date(j),
10456 last_update_date = v_current_date,
10457 last_updated_by = v_current_user,
10458 context = lb_context(j),
10459 attribute1 = lb_attribute1(j),
10460 attribute2 = lb_attribute2(j),
10461 attribute3 = lb_attribute3(j),
10462 attribute4 = lb_attribute4(j),
10463 attribute5 = lb_attribute5(j),
10464 attribute6 = lb_attribute6(j),
10465 attribute7 = lb_attribute7(j),
10466 attribute8 = lb_attribute8(j),
10467 attribute9 = lb_attribute9(j),
10468 attribute10 = lb_attribute10(j),
10469 attribute11 = lb_attribute11(j),
10470 attribute12 = lb_attribute12(j),
10471 attribute13 = lb_attribute13(j),
10472 attribute14 = lb_attribute14(j),
10473 attribute15 = lb_attribute15(j)
10474 WHERE group_id = lb_group_id(j);
10475 end if;
10476 CLOSE c11;
10477
10478 --Inserts the valid records into the ODS table, Since the collection program
10479 --doesn't collect this entity incrementally and whereras post-processor always
10480 --runs in the incremental mode.
10481
10482 v_sql_stmt := 67;
10483 lv_sql_stmt :=
10484 'INSERT INTO MSC_GROUPS'
10485 ||'( GROUP_ID ,'
10486 ||' GROUP_NAME ,'
10487 ||' DESCRIPTION ,'
10488 ||' GROUP_TYPE ,'
10489 ||' GROUP_OWNER_ID ,'
10490 ||' OWNER_CONTACT ,'
10491 ||' CONTRACT_DOC_URL,'
10492 ||' EFFECTIVE_DATE ,'
10493 ||' DISABLE_DATE ,'
10494 ||' CREATION_DATE ,'
10495 ||' CREATED_BY ,'
10496 ||' LAST_UPDATE_DATE,'
10497 ||' LAST_UPDATED_BY ,'
10498 ||' LAST_UPDATE_LOGIN,'
10499 ||' CONTEXT ,'
10500 ||' ATTRIBUTE1 ,'
10501 ||' ATTRIBUTE2 ,'
10502 ||' ATTRIBUTE3 ,'
10503 ||' ATTRIBUTE4 ,'
10504 ||' ATTRIBUTE5 ,'
10505 ||' ATTRIBUTE6 ,'
10506 ||' ATTRIBUTE7 ,'
10507 ||' ATTRIBUTE8 ,'
10508 ||' ATTRIBUTE9 ,'
10509 ||' ATTRIBUTE10 ,'
10510 ||' ATTRIBUTE11 ,'
10511 ||' ATTRIBUTE12 ,'
10512 ||' ATTRIBUTE13 ,'
10513 ||' ATTRIBUTE14 ,'
10514 ||' ATTRIBUTE15 )'
10515 ||' SELECT'
10516 ||' GROUP_ID ,'
10517 ||' GROUP_NAME ,'
10518 ||' DESCRIPTION ,'
10519 ||' GROUP_TYPE ,'
10520 ||' GROUP_OWNER_ID ,'
10521 --||' CONTACT_USER_NAME,'
10522 ||' CONTACT_USER_ID ,'
10523 ||' CONTRACT_DOC_URL,'
10524 ||' EFFECTIVE_DATE ,'
10525 ||' DISABLE_DATE ,'
10526 ||' CREATION_DATE ,'
10527 ||' CREATED_BY ,'
10528 ||' LAST_UPDATE_DATE,'
10529 ||' LAST_UPDATED_BY ,'
10530 ||' LAST_UPDATE_LOGIN,'
10531 ||' CONTEXT ,'
10532 ||' ATTRIBUTE1 ,'
10533 ||' ATTRIBUTE2 ,'
10534 ||' ATTRIBUTE3 ,'
10535 ||' ATTRIBUTE4 ,'
10536 ||' ATTRIBUTE5 ,'
10537 ||' ATTRIBUTE6 ,'
10538 ||' ATTRIBUTE7 ,'
10539 ||' ATTRIBUTE8 ,'
10540 ||' ATTRIBUTE9 ,'
10541 ||' ATTRIBUTE10 ,'
10542 ||' ATTRIBUTE11 ,'
10543 ||' ATTRIBUTE12 ,'
10544 ||' ATTRIBUTE13 ,'
10545 ||' ATTRIBUTE14 ,'
10546 ||' ATTRIBUTE15 '
10547 ||' FROM MSC_ST_GROUPS msg'
10548 ||' WHERE sr_instance_code = :sr_instance_code'
10549 ||' AND batch_id = :lv_batch_id'
10550 ||' AND process_flag = '||G_VALID
10551 ||' AND NOT EXISTS( SELECT 1 '
10552 ||' FROM MSC_GROUPS mg'
10553 ||' WHERE mg.group_id = msg.group_id)';
10554
10555
10556 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
10557
10558 EXECUTE IMMEDIATE lv_sql_stmt
10559 USING v_instance_code,
10560 lv_batch_id;
10561 COMMIT;
10562 END LOOP;
10563
10564 --Validation for GROUP COMPANIES IS
10565
10566 lv_return := MSC_ST_util.GET_ERROR_MESSAGE
10567 (p_app_short_name => 'MSC',
10568 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
10569 p_message_text => lv_message_text,
10570 p_error_text => lv_error_text);
10571
10572 IF lv_return <> 0 THEN
10573 RAISE ex_logging_err;
10574 END IF;
10575
10576 --Duplicate records check for the records whose source is XML
10577 v_sql_stmt := 68;
10578 lv_sql_stmt :=
10579 ' UPDATE msc_st_group_companies mgc1'
10580 ||' SET process_flag = '||G_ERROR_FLG||','
10581 ||' error_text = '||''''||lv_message_text||''''
10582 ||' WHERE message_id < (SELECT MAX(message_id)'
10583 ||' FROM msc_st_group_companies mgc2'
10584 ||' WHERE mgc2.group_name = mgc1.group_name '
10585 ||' AND mgc2.company_name = mgc1.company_name '
10586 ||' AND mgc2.process_flag <> '||G_ERROR_FLG
10587 ||' AND NVL(mgc2.message_id,'||NULL_VALUE||')<>'||NULL_VALUE||')'
10588 ||' AND mgc1.process_flag = '||G_IN_PROCESS
10589 ||' AND mgc1.sr_instance_code = :v_instance_code'
10590 ||' AND NVL(mgc1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
10591
10592
10593 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
10594
10595 EXECUTE IMMEDIATE lv_sql_stmt
10596 USING v_instance_code;
10597
10598 lv_return := MSC_ST_util.GET_ERROR_MESSAGE
10599 (p_app_short_name => 'MSC',
10600 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
10601 p_message_text => lv_message_text,
10602 p_error_text => lv_error_text);
10603
10604 IF lv_return <> 0 THEN
10605 RAISE ex_logging_err;
10606 END IF;
10607
10608 --Duplicate records check for the records whose source is other than XML
10609 --Different SQL is used because in XML we can identify the latest records
10610 --whereas in batch load we cannot.
10611
10612 v_sql_stmt := 69;
10613
10614 lv_sql_stmt :=
10615 ' UPDATE msc_st_group_companies mgc1'
10616 ||' SET process_flag = '||G_ERROR_FLG||','
10617 ||' error_text = '||''''||lv_message_text||''''
10618 ||' WHERE EXISTS( SELECT 1 '
10619 ||' FROM msc_st_group_companies mgc2'
10620 ||' WHERE mgc2.group_name = mgc1.group_name '
10621 ||' AND mgc2.company_name = mgc1.company_name '
10622 ||' AND mgc2.process_flag <> '||G_ERROR_FLG
10623 ||' AND NVL(mgc2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
10624 ||' AND mgc2.rowid <> mgc1.rowid)'
10625 ||' AND mgc1.process_flag = '||G_IN_PROCESS
10626 ||' AND mgc1.sr_instance_code = :v_instance_code '
10627 ||' AND NVL(mgc1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
10628
10629
10630 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
10631
10632 EXECUTE IMMEDIATE lv_sql_stmt
10633 USING v_instance_code;
10634
10635 lv_column_names :=
10636 ' GROUP_NAME ||''~''||'
10637 ||' COMPANY_NAME ||''~''||'
10638 ||' EFFECTIVE_DATE ||''~''||'
10639 ||' DISABLE_DATE ||''~''||'
10640 ||' CONTACT_USER_NAME ||''~''||'
10641 ||' CONTEXT ||''~''||'
10642 ||' ATTRIBUTE1 ||''~''||'
10643 ||' ATTRIBUTE2 ||''~''||'
10644 ||' ATTRIBUTE3 ||''~''||'
10645 ||' ATTRIBUTE4 ||''~''||'
10646 ||' ATTRIBUTE5 ||''~''||'
10647 ||' ATTRIBUTE6 ||''~''||'
10648 ||' ATTRIBUTE7 ||''~''||'
10649 ||' ATTRIBUTE8 ||''~''||'
10650 ||' ATTRIBUTE9 ||''~''||'
10651 ||' ATTRIBUTE10 ||''~''||'
10652 ||' ATTRIBUTE11 ||''~''||'
10653 ||' ATTRIBUTE12 ||''~''||'
10654 ||' ATTRIBUTE13 ||''~''||'
10655 ||' ATTRIBUTE14 ||''~''||'
10656 ||' ATTRIBUTE15 ||''~''||'
10657 ||' SR_INSTANCE_CODE';
10658
10659 -- Dividing records in batches based on batchsize
10660
10661 LOOP
10662 v_sql_stmt := 70;
10663 SELECT msc_st_batch_id_s.NEXTVAL
10664 INTO lv_batch_id
10665 FROM DUAL;
10666
10667 v_sql_stmt := 71;
10668 lv_sql_stmt :=
10669 'UPDATE msc_st_group_companies '
10670 ||' SET batch_id = :lv_batch_id'
10671 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
10672 ||' AND sr_instance_code = :v_instance_code'
10673 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
10674 ||' AND rownum <= '||v_batch_size;
10675
10676
10677 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
10678
10679 EXECUTE IMMEDIATE lv_sql_stmt
10680 USING lv_batch_id,
10681 v_instance_code;
10682
10683 EXIT WHEN SQL%NOTFOUND ;
10684
10685 -- Updation of WHO columns
10686
10687 OPEN c12(lv_batch_id);
10688 FETCH c12 BULK COLLECT INTO lb_rowid;
10689 CLOSE c12;
10690
10691 v_sql_stmt := 72;
10692 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
10693 UPDATE msc_st_group_companies
10694 SET st_transaction_id = msc_st_group_companies_s.NEXTVAL,
10695 last_update_date = v_current_date,
10696 last_updated_by = v_current_user,
10697 creation_date = v_current_date,
10698 created_by = v_current_user
10699 WHERE rowid = lb_rowid(j);
10700
10701
10702 -- Set the message for no deletion is allowed.
10703
10704 lv_return := MSC_ST_util.GET_ERROR_MESSAGE
10705 (p_app_short_name => 'MSC',
10706 p_error_code => 'MSC_PP_NO_DELETION',
10707 p_message_text => lv_message_text,
10708 p_error_text => lv_error_text,
10709 p_token1 => 'TABLE_NAME',
10710 p_token_value1 => 'MSC_ST_GROUP_COMPANIES');
10711
10712 IF lv_return <> 0 THEN
10713 RAISE ex_logging_err;
10714 END IF;
10715
10716 --Deletion is not allowed on this table.
10717 v_sql_stmt := 73;
10718 lv_sql_stmt :=
10719 ' UPDATE msc_st_group_companies '
10720 ||' SET process_flag ='||G_ERROR_FLG||','
10721 ||' error_text = '||''''||lv_message_text||''''
10722 ||' WHERE deleted_flag = '||SYS_YES
10723 ||' AND process_flag = '||G_IN_PROCESS
10724 ||' AND batch_id = :lv_batch_id'
10725 ||' AND sr_instance_code = :v_instance_code';
10726
10727
10728 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
10729
10730 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
10731
10732 -- Set the message for deleted flag
10733
10734 lv_return := MSC_ST_util.GET_ERROR_MESSAGE
10735 (p_app_short_name => 'MSC',
10736 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
10737 p_message_text => lv_message_text,
10738 p_error_text => lv_error_text,
10739 p_token1 => 'COLUMN_NAME',
10740 p_token_value1 => 'DELETED_FLAG',
10741 p_token2 => 'DEFAULT_VALUE',
10742 p_token_value2 => SYS_NO);
10743
10744 IF lv_return <> 0 THEN
10745 RAISE ex_logging_err;
10746 END IF;
10747
10748 -- Check DELETED_FLAG column has valid value or not and
10749 -- if not set it to SYS_NO
10750
10751 lv_where_str :=
10752 ' AND NVL(deleted_flag,'||NULL_VALUE||') NOT IN(1,2)';
10753
10754 lv_return := MSC_ST_util.LOG_ERROR
10755 (p_table_name => 'MSC_ST_GROUP_COMPANIES',
10756 p_instance_code => v_instance_code,
10757 p_row => lv_column_names,
10758 p_severity => G_SEV_WARNING,
10759 p_message_text => lv_message_text,
10760 p_error_text => lv_error_text,
10761 p_batch_id => lv_batch_id,
10762 p_where_str => lv_where_str,
10763 p_col_name => 'DELETED_FLAG',
10764 p_debug => v_debug,
10765 p_default_value => SYS_NO);
10766
10767 IF lv_return <> 0 THEN
10768 RAISE ex_logging_err;
10769 END IF;
10770
10771 -- Effective Date is a mandatory column in MSC_GROUP_COMPANIES , set error message
10772 lv_return :=
10773 MSC_ST_util.GET_ERROR_MESSAGE (p_app_short_name => 'MSC',
10774 p_error_code => 'MSC_PP_COL_VAL_NULL',
10775 p_message_text => lv_message_text,
10776 p_error_text => lv_error_text,
10777 p_token1 => 'COLUMN_NAME',
10778 p_token_value1 => 'EFFECTIVE_DATE');
10779
10780 IF lv_return <> 0 THEN
10781 RAISE ex_logging_err;
10782 END IF;
10783
10784
10785 v_sql_stmt := 74;
10786
10787 lv_sql_stmt :=
10788 ' UPDATE msc_st_group_companies '
10789 ||' SET process_flag = '||G_ERROR_FLG||','
10790 ||' error_text = '||''''||lv_message_text||''''
10791 ||' WHERE effective_date IS NULL '
10792 ||' AND batch_id = :lv_batch_id'
10793 ||' AND process_flag = '||G_IN_PROCESS
10794 ||' AND sr_instance_code = :v_instance_code';
10795
10796
10797 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
10798
10799 EXECUTE IMMEDIATE lv_sql_stmt
10800 USING lv_batch_id,
10801 v_instance_code;
10802
10803 -- Set the error message for DISABLE_DATE should be greater than EFFECTIVE_DATE
10804
10805 lv_return := MSC_ST_util.GET_ERROR_MESSAGE
10806 (p_app_short_name => 'MSC',
10807 p_error_code => 'MSC_PP_END_GT_ST_DATE',
10808 p_message_text => lv_message_text,
10809 p_error_text => lv_error_text);
10810
10811 IF lv_return <> 0 THEN
10812 RAISE ex_logging_err;
10813 END IF;
10814
10815 v_sql_stmt := 75;
10816
10817 lv_sql_stmt :=
10818 ' UPDATE msc_st_group_companies '
10819 ||' SET process_flag = '||G_ERROR_FLG||','
10820 ||' error_text = '||''''||lv_message_text||''''
10821 ||' WHERE effective_date > disable_date'
10822 ||' AND disable_date IS NOT NULL'
10823 ||' AND batch_id = :lv_batch_id'
10824 ||' AND process_flag = '||G_IN_PROCESS
10825 ||' AND sr_instance_code = :v_instance_code';
10826
10827
10828 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
10829
10830
10831 EXECUTE IMMEDIATE lv_sql_stmt
10832 USING lv_batch_id,
10833 v_instance_code;
10834
10835 --DERIVE GROUP_ID
10836
10837 lv_return := MSC_ST_util.GET_ERROR_MESSAGE
10838 (p_app_short_name => 'MSC',
10839 p_error_code => 'MSC_PP_INVALID_VALUE',
10840 p_message_text => lv_message_text,
10841 p_error_text => lv_error_text,
10842 p_token1 => 'COLUMN_NAME',
10843 p_token_value1 => 'GROUP_NAME');
10844
10845
10846 lv_return := MSC_ST_util.DERIVE_GROUP_ID
10847 (p_table_name =>'MSC_ST_GROUP_COMPANIES',
10848 p_grp_col_name => 'GROUP_NAME',
10849 p_grp_col_id => 'GROUP_ID',
10850 p_instance_code => v_instance_code,
10851 p_instance_id => v_instance_id,
10852 p_batch_id => lv_batch_id,
10853 p_debug => v_debug,
10854 p_severity => G_SEV_ERROR,
10855 p_error_text => lv_error_text,
10856 p_row => lv_column_names);
10857
10858 IF lv_return <> 0 THEN
10859 RAISE ex_logging_err;
10860 END IF;
10861
10862
10863
10864 -- Only group owner or operator can update
10865
10866 select fnd_global.user_id into lv_user_id from dual;
10867
10868 lv_return := MSC_ST_util.GET_ERROR_MESSAGE
10869 (p_app_short_name => 'MSC',
10870 p_error_code => 'MSC_PP_INVALID_VALUE',
10871 p_message_text => lv_message_text,
10872 p_error_text => lv_error_text,
10873 p_token1 => 'COLUMN_NAME',
10874 p_token_value1 => 'Posting_party_id');
10875
10876 IF lv_return <> 0 THEN
10877 RAISE ex_logging_err;
10878 END IF;
10879
10880 -- changes
10881
10882 IF NOT MSC_ST_util.IS_OPERATOR(lv_user_id) THEN
10883
10884 v_sql_stmt := 76;
10885 lv_sql_stmt :=
10886 'UPDATE msc_st_group_companies msg'
10887 ||' SET process_flag = '||G_ERROR_FLG||','
10888 ||' error_text = '||''''||lv_message_text||''''
10889 ||' WHERE NOT EXISTS(SELECT 1 '
10890 ||' FROM msc_groups mg'
10891 ||' where mg.group_owner_id = msg.posting_party_id '
10892 ||' AND mg.group_id = msg.group_id '
10893 ||' UNION '
10894 ||' SELECT 1 '
10895 ||' FROM msc_st_groups ms'
10896 ||' where ms.group_owner_id = msg.posting_party_id '
10897 ||' AND ms.group_id = msg.group_id '
10898 ||' AND ms.process_flag = '||G_VALID ||')'
10899 ||' AND batch_id = :lv_batch_id'
10900 ||' AND sr_instance_code = :v_instance_code'
10901 ||' AND process_flag = '||G_IN_PROCESS;
10902
10903
10904 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
10905
10906 EXECUTE IMMEDIATE lv_sql_stmt
10907 USING lv_batch_id,
10908 v_instance_code;
10909 END IF;
10910 --Derive company_id
10911
10912 v_sql_stmt := 77;
10913 lv_sql_stmt :=
10914 'UPDATE msc_st_group_companies msg '
10915 ||' SET company_id = ( SELECT mc.company_id '
10916 ||' FROM msc_companies mc '
10917 ||' WHERE mc.company_name = msg.company_name '
10918 ||' AND NVL(mc.disable_date,sysdate+1) > sysdate) '
10919 ||' WHERE msg.sr_instance_code = :v_instance_code'
10920 ||' AND msg.batch_id = :lv_batch_id'
10921 ||' AND msg.process_flag = '||G_IN_PROCESS;
10922
10923
10924 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
10925
10926 EXECUTE IMMEDIATE lv_sql_stmt
10927 USING v_instance_code,
10928 lv_batch_id;
10929
10930 -- Error out the invalid company Name
10931
10932 lv_return := MSC_ST_util.GET_ERROR_MESSAGE
10933 (p_app_short_name => 'MSC',
10934 p_error_code => 'MSC_PP_INVALID_VALUE',
10935 p_message_text => lv_message_text,
10936 p_error_text => lv_error_text,
10937 p_token1 => 'COLUMN_NAME',
10938 p_token_value1 => 'COMPANY_NAME');
10939
10940 IF lv_return <> 0 THEN
10941 RAISE ex_logging_err;
10942 END IF;
10943
10944 --Derive contact_user_id
10945
10946 v_sql_stmt := 78;
10947 lv_sql_stmt :=
10948 'UPDATE msc_st_group_companies msg'
10949 ||' SET contact_user_id = (select user_id '
10950 ||' from fnd_user fu'
10951 ||' where UPPER(fu.user_name) =UPPER( msg.contact_user_name)) '
10952 ||' WHERE batch_id = :lv_batch_id'
10953 ||' AND sr_instance_code = :v_instance_code'
10954 ||' AND process_flag = '||G_IN_PROCESS;
10955
10956
10957 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
10958
10959 EXECUTE IMMEDIATE lv_sql_stmt
10960 USING lv_batch_id,
10961 v_instance_code;
10962
10963 -- Error out the invalid Contact User Name
10964
10965 lv_return := MSC_ST_util.GET_ERROR_MESSAGE
10966 (p_app_short_name => 'MSC',
10967 p_error_code => 'MSC_PP_INVALID_VALUE',
10968 p_message_text => lv_message_text,
10969 p_error_text => lv_error_text,
10970 p_token1 => 'COLUMN_NAME',
10971 p_token_value1 => 'CONTACT_USER_NAME');
10972
10973 IF lv_return <> 0 THEN
10974 RAISE ex_logging_err;
10975 END IF;
10976
10977 -- Update the record as errored out record
10978
10979 v_sql_stmt := 79;
10980 lv_sql_stmt :=
10981 'UPDATE msc_st_group_companies '
10982 ||' SET process_flag = '||G_ERROR_FLG||','
10983 ||' error_text = '||''''||lv_message_text||''''
10984 ||' WHERE contact_user_id IS NULL '
10985 ||' AND batch_id = :lv_batch_id'
10986 ||' AND sr_instance_code = :v_instance_code'
10987 ||' AND process_flag = '||G_IN_PROCESS;
10988
10989 lv_return := MSC_ST_util.GET_ERROR_MESSAGE
10990 (p_app_short_name => 'MSC',
10991 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
10992 p_message_text => lv_message_text,
10993 p_error_text => lv_error_text,
10994 p_token1 => 'COLUMN_NAMES',
10995 p_token_value1 => 'CONTACT_USER_NAME,COMPANY_NAME',
10996 p_token2 => 'MASTER_TABLE',
10997 p_token_value2 => 'MSC_COMPANY_USERS',
10998 p_token3 => 'CHILD_TABLE',
10999 p_token_value3 => 'MSC_ST_GROUP_COMPANIES');
11000
11001 IF lv_return <> 0 THEN
11002 RAISE ex_logging_err;
11003 END IF;
11004
11005 -- Populating valid Contact user id
11006
11007 v_sql_stmt := 80;
11008 lv_sql_stmt :=
11009 ' UPDATE msc_st_group_companies mgc'
11010 ||' SET process_flag = '||G_ERROR_FLG||','
11011 ||' error_text = '||''''||lv_message_text||''''
11012 ||' WHERE NOT EXISTS (SELECT 1 '
11013 ||' FROM msc_company_users mcu '
11014 ||' WHERE mcu.company_id = mgc.company_id'
11015 ||' AND mcu.user_id = mgc.contact_user_id)'
11016 ||' AND mgc.sr_instance_code = :v_instance_code'
11017 ||' AND mgc.batch_id = :lv_batch_id'
11018 ||' AND mgc.process_flag = '||G_IN_PROCESS ;
11019
11020
11021 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
11022
11023 EXECUTE IMMEDIATE lv_sql_stmt
11024 USING v_instance_code,
11025 lv_batch_id;
11026
11027 --Call to customised validation.
11028
11029 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
11030 (ERRBUF => lv_error_text,
11031 RETCODE => lv_return,
11032 pBatchID => lv_batch_id,
11033 pInstanceCode => v_instance_code,
11034 pEntityName => 'MSC_ST_GROUP_COMPANIES',
11035 pInstanceID => v_instance_id);
11036
11037 IF NVL(lv_return,0) <> 0 THEN
11038 RAISE ex_logging_err;
11039 END IF;
11040
11041 -- Set the process flag as Valid and derive sr_instance_id
11042
11043 lv_return := MSC_ST_util.SET_PROCESS_FLAG
11044 (p_table_name => 'MSC_ST_GROUP_COMPANIES',
11045 p_instance_id => v_instance_id,
11046 p_instance_code => v_instance_code,
11047 p_process_flag => G_VALID,
11048 p_error_text => lv_error_text,
11049 p_debug => v_debug,
11050 p_batch_id => lv_batch_id);
11051
11052 IF lv_return <> 0 THEN
11053 RAISE ex_logging_err;
11054 END IF;
11055
11056 -- Inserting all the errored out records into MSC_ERRORS
11057
11058 lv_return := MSC_ST_util.LOG_ERROR
11059 (p_table_name => 'MSC_ST_GROUP_COMPANIES',
11060 p_instance_code => v_instance_code,
11061 p_row => lv_column_names,
11062 p_severity => G_SEV_ERROR,
11063 p_error_text => lv_error_text,
11064 p_message_text => NULL,
11065 p_batch_id => lv_batch_id);
11066
11067
11068 IF lv_return <> 0 THEN
11069 RAISE ex_logging_err;
11070 END IF;
11071
11072 -- Updation of the record in msc_group_companies
11073 OPEN c13(lv_batch_id);
11074 FETCH c13 BULK COLLECT INTO
11075 lb_group_id,
11076 lb_company_id,
11077 lb_CONTACT_USER_ID,
11078 lb_EFFECTIVE_DATE,
11079 lb_DISABLE_DATE,
11080 lb_CONTEXT,
11081 lb_ATTRIBUTE1,
11082 lb_ATTRIBUTE2,
11083 lb_ATTRIBUTE3,
11084 lb_ATTRIBUTE4,
11085 lb_ATTRIBUTE5,
11086 lb_ATTRIBUTE6,
11087 lb_ATTRIBUTE7,
11088 lb_ATTRIBUTE8,
11089 lb_ATTRIBUTE9,
11090 lb_ATTRIBUTE10,
11091 lb_ATTRIBUTE11,
11092 lb_ATTRIBUTE12,
11093 lb_ATTRIBUTE13,
11094 lb_ATTRIBUTE14,
11095 lb_ATTRIBUTE15;
11096
11097 IF c13%ROWCOUNT > 0 THEN
11098 v_sql_stmt := 81;
11099 FORALL j IN lb_GROUP_ID.FIRST..lb_GROUP_ID.LAST
11100
11101 UPDATE msc_group_companies
11102 SET contact_user = lb_contact_user_id(j),
11103 effective_date = lb_effective_date(j),
11104 disable_date = lb_disable_date(j),
11105 last_update_date = v_current_date,
11106 last_updated_by = v_current_user,
11107 context = lb_context(j),
11108 attribute1 = lb_attribute1(j),
11109 attribute2 = lb_attribute2(j),
11110 attribute3 = lb_attribute3(j),
11111 attribute4 = lb_attribute4(j),
11112 attribute5 = lb_attribute5(j),
11113 attribute6 = lb_attribute6(j),
11114 attribute7 = lb_attribute7(j),
11115 attribute8 = lb_attribute8(j),
11116 attribute9 = lb_attribute9(j),
11117 attribute10 = lb_attribute10(j),
11118 attribute11 = lb_attribute11(j),
11119 attribute12 = lb_attribute12(j),
11120 attribute13 = lb_attribute13(j),
11121 attribute14 = lb_attribute14(j),
11122 attribute15 = lb_attribute15(j)
11123 WHERE group_id = lb_group_id(J)
11124 AND company_id = lb_company_id(J);
11125 end if;
11126 CLOSE c13;
11127
11128 --Inserts the valid records into the ODS table, Since the collection program
11129 --doesn't collect this entity incrementally and whereras post-processor always
11130 --runs in the incremental mode.
11131
11132 v_sql_stmt := 82;
11133 lv_sql_stmt :=
11134 'INSERT INTO MSC_GROUP_COMPANIES'
11135 ||'( GROUP_ID ,'
11136 ||' COMPANY_ID ,'
11137 ||' EFFECTIVE_DATE ,'
11138 ||' DISABLE_DATE ,'
11139 ||' CONTACT_USER ,'
11140 ||' CREATION_DATE ,'
11141 ||' CREATED_BY ,'
11142 ||' LAST_UPDATE_DATE,'
11143 ||' LAST_UPDATED_BY ,'
11144 ||' LAST_UPDATE_LOGIN,'
11145 ||' CONTEXT ,'
11146 ||' ATTRIBUTE1 ,'
11147 ||' ATTRIBUTE2 ,'
11148 ||' ATTRIBUTE3 ,'
11149 ||' ATTRIBUTE4 ,'
11150 ||' ATTRIBUTE5 ,'
11151 ||' ATTRIBUTE6 ,'
11152 ||' ATTRIBUTE7 ,'
11153 ||' ATTRIBUTE8 ,'
11154 ||' ATTRIBUTE9 ,'
11155 ||' ATTRIBUTE10 ,'
11156 ||' ATTRIBUTE11 ,'
11157 ||' ATTRIBUTE12 ,'
11158 ||' ATTRIBUTE13 ,'
11159 ||' ATTRIBUTE14 ,'
11160 ||' ATTRIBUTE15 )'
11161 ||' SELECT'
11162 ||' GROUP_ID ,'
11163 ||' COMPANY_ID ,'
11164 ||' EFFECTIVE_DATE ,'
11165 ||' DISABLE_DATE ,'
11166 ||' CONTACT_USER_id ,'
11167 ||' CREATION_DATE ,'
11168 ||' CREATED_BY ,'
11169 ||' LAST_UPDATE_DATE,'
11170 ||' LAST_UPDATED_BY ,'
11171 ||' LAST_UPDATE_LOGIN,'
11172 ||' CONTEXT ,'
11173 ||' ATTRIBUTE1 ,'
11174 ||' ATTRIBUTE2 ,'
11175 ||' ATTRIBUTE3 ,'
11176 ||' ATTRIBUTE4 ,'
11177 ||' ATTRIBUTE5 ,'
11178 ||' ATTRIBUTE6 ,'
11179 ||' ATTRIBUTE7 ,'
11180 ||' ATTRIBUTE8 ,'
11181 ||' ATTRIBUTE9 ,'
11182 ||' ATTRIBUTE10 ,'
11183 ||' ATTRIBUTE11 ,'
11184 ||' ATTRIBUTE12 ,'
11185 ||' ATTRIBUTE13 ,'
11186 ||' ATTRIBUTE14 ,'
11187 ||' ATTRIBUTE15 '
11188 ||' FROM msc_st_group_companies msg'
11189 ||' WHERE sr_instance_code = :sr_instance_code'
11190 ||' AND batch_id = :lv_batch_id'
11191 ||' AND process_flag = '||G_VALID
11192 ||' AND NOT EXISTS( SELECT 1 '
11193 ||' FROM msc_group_companies mgc'
11194 ||' WHERE mgc.group_id = msg.group_id '
11195 ||' AND mgc.company_id = msg.company_id)';
11196
11197
11198 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
11199
11200 EXECUTE IMMEDIATE lv_sql_stmt
11201 USING v_instance_code,
11202 lv_batch_id;
11203
11204 COMMIT;
11205 END LOOP;
11206
11207 MODEL_ORG_SUPPLIER_CUSTOMER;
11208
11209 EXCEPTION
11210 WHEN too_many_rows THEN
11211 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_TRADING_PARTNERS '||'('
11212 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
11213 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
11214
11215 ROLLBACK;
11216
11217 WHEN ex_logging_err THEN
11218 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
11219
11220 ROLLBACK;
11221
11222 WHEN OTHERS THEN
11223 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_TRADING_PARTNERS '||'('
11224 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
11225 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
11226
11227 ROLLBACK;
11228
11229 END LOAD_TRADING_PARTNERS ;
11230
11231 /*==========================================================================+
11232 | DESCRIPTION : This procedure performs validation and loads data into the |
11233 | table msc_st_calendar_assignments. |
11234 +==========================================================================*/
11235
11236
11237 PROCEDURE LOAD_CALENDAR_ASSIGNMENTS IS
11238 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
11239 lb_rowid RowidTab;
11240 lv_return NUMBER;
11241 lv_error_text VARCHAR2(250);
11242 lv_where_str VARCHAR2(5000);
11243 lv_sql_stmt VARCHAR2(5000);
11244 lv_column_names VARCHAR2(5000);
11245 lv_batch_id msc_st_calendar_assignments.batch_id%TYPE;
11246 lv_message_text msc_errors.error_text%TYPE;
11247
11248 ex_logging_err EXCEPTION;
11249
11250 CURSOR c1(p_batch_id NUMBER) IS
11251 SELECT rowid
11252 FROM msc_st_calendar_assignments
11253 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
11254 AND batch_id = p_batch_id
11255 AND sr_instance_code = v_instance_code;
11256
11257 BEGIN
11258
11259 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
11260 (p_app_short_name => 'MSC',
11261 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
11262 p_message_text => lv_message_text,
11263 p_error_text => lv_error_text);
11264
11265 IF lv_return <> 0 THEN
11266 RAISE ex_logging_err;
11267 END IF;
11268
11269
11270 --Duplicate records check for the records whose source is XML
11271 v_sql_stmt := 01;
11272 lv_sql_stmt :=
11273 ' UPDATE msc_st_calendar_assignments msp1'
11274 ||' SET process_flag = '||G_ERROR_FLG||','
11275 ||' error_text = '||''''||lv_message_text||''''
11276 ||' WHERE message_id < (SELECT MAX(message_id)'
11277 ||' FROM msc_st_calendar_assignments msp2'
11278 ||' WHERE msp2.sr_instance_code = msp1.sr_instance_code'
11279 ||' AND NVL(msp2.company_name, ' ||''''||NULL_CHAR||''''||') = '
11280 ||' NVL(msp1.company_name, ' ||''''||NULL_CHAR||''''||')'
11281 ||' AND NVL(msp2.organization_code, ' ||''''||NULL_CHAR||''''||') = '
11282 ||' NVL(msp1.organization_code, ' ||''''||NULL_CHAR||''''||')'
11283 ||' AND NVL(msp2.partner_name, ' ||''''||NULL_CHAR||''''||') = '
11284 ||' NVL(msp1.partner_name, ' ||''''||NULL_CHAR||''''||')'
11285 ||' AND NVL(msp2.partner_site_code, ' ||''''||NULL_CHAR||''''||') = '
11286 ||' NVL(msp1.partner_site_code, ' ||''''||NULL_CHAR||''''||')'
11287 ||' AND NVL(msp2.carrier_partner_code, ' ||''''||NULL_CHAR||''''||') = '
11288 ||' NVL(msp1.carrier_partner_code, ' ||''''||NULL_CHAR||''''||')'
11289 ||' AND NVL(msp2.ship_method_code, ' ||''''||NULL_CHAR||''''||') = '
11290 ||' NVL(msp1.ship_method_code, ' ||''''||NULL_CHAR||''''||')'
11291 ||' AND msp2.calendar_type = msp1.calendar_type'
11292 ||' AND msp2.calendar_code = msp1.calendar_code'
11293 ||' AND NVL(msp2.partner_type,'||NULL_VALUE||') = NVL(msp1.partner_type,'||NULL_VALUE||')'
11294 ||' AND msp2.association_type = msp1.association_type'
11295 ||' AND msp2.process_flag = '||G_IN_PROCESS
11296 ||' AND NVL(msp2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
11297 ||' AND msp1.process_flag = '||G_IN_PROCESS
11298 ||' AND msp1.sr_instance_code = :v_instance_code'
11299 ||' AND NVL(msp1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
11300
11301
11302
11303 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
11304
11305 EXECUTE IMMEDIATE lv_sql_stmt
11306 USING v_instance_code;
11307
11308 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
11309 (p_app_short_name => 'MSC',
11310 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
11311 p_message_text => lv_message_text,
11312 p_error_text => lv_error_text);
11313
11314 IF lv_return <> 0 THEN
11315 RAISE ex_logging_err;
11316 END IF;
11317
11318 --Duplicate records check for the records whose source is other than XML
11319 --Different SQL is used because in XML we can identify the latest records
11320 --whereas in batch load we cannot.
11321 v_sql_stmt := 02;
11322 lv_sql_stmt :=
11323 ' UPDATE msc_st_calendar_assignments msp1'
11324 ||' SET process_flag = '||G_ERROR_FLG||','
11325 ||' error_text = '||''''||lv_message_text||''''
11326 ||' WHERE EXISTS( SELECT 1 '
11327 ||' FROM msc_st_calendar_assignments msp2'
11328 ||' WHERE msp2.sr_instance_code = msp1.sr_instance_code'
11329 ||' AND NVL(msp2.company_name, ' ||''''||NULL_CHAR||''''||') = '
11330 ||' NVL(msp1.company_name, ' ||''''||NULL_CHAR||''''||')'
11331 ||' AND NVL(msp2.organization_code, ' ||''''||NULL_CHAR||''''||') = '
11332 ||' NVL(msp1.organization_code, ' ||''''||NULL_CHAR||''''||')'
11333 ||' AND NVL(msp2.partner_name, ' ||''''||NULL_CHAR||''''||') = '
11334 ||' NVL(msp1.partner_name, ' ||''''||NULL_CHAR||''''||')'
11335 ||' AND NVL(msp2.partner_site_code, ' ||''''||NULL_CHAR||''''||') = '
11336 ||' NVL(msp1.partner_site_code, ' ||''''||NULL_CHAR||''''||')'
11337 ||' AND NVL(msp2.carrier_partner_code, ' ||''''||NULL_CHAR||''''||') = '
11338 ||' NVL(msp1.carrier_partner_code, ' ||''''||NULL_CHAR||''''||')'
11339 ||' AND NVL(msp2.ship_method_code, ' ||''''||NULL_CHAR||''''||') = '
11340 ||' NVL(msp1.ship_method_code, ' ||''''||NULL_CHAR||''''||')'
11341 ||' AND msp2.calendar_type = msp1.calendar_type'
11342 ||' AND msp2.calendar_code = msp1.calendar_code'
11343 ||' AND NVL(msp2.partner_type,'||NULL_VALUE||') = NVL(msp1.partner_type,'||NULL_VALUE||')'
11344 ||' AND msp2.association_type = msp1.association_type'
11345 ||' AND msp2.process_flag = '||G_IN_PROCESS
11346 ||' AND NVL(msp2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
11347 ||' AND msp2.rowid <> msp1.rowid)'
11348 ||' AND msp1.process_flag = '||G_IN_PROCESS
11349 ||' AND msp1.sr_instance_code = :v_instance_code'
11350 ||' AND NVL(msp1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
11351
11352
11353
11354 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
11355
11356 EXECUTE IMMEDIATE lv_sql_stmt
11357 USING v_instance_code;
11358
11359 lv_column_names :=
11360 'CALENDAR_CODE ||''~''||'
11361 ||'ORGANIZATION_CODE ||''~''||'
11362 ||'ASSOCIATION_TYPE ||''~''||'
11363 ||'CALENDAR_TYPE ||''~''||'
11364 ||'PARTNER_NAME ||''~''||'
11365 ||'PARTNER_SITE_CODE ||''~''||'
11366 ||'CARRIER_PARTNER_CODE ||''~''||'
11367 ||'SR_INSTANCE_CODE ||''~''||'
11368 ||'COMPANY_NAME';
11369
11370 LOOP
11371 v_sql_stmt := 03;
11372 SELECT msc_st_batch_id_s.NEXTVAL
11373 INTO lv_batch_id
11374 FROM dual;
11375
11376 v_sql_stmt := 04;
11377 lv_sql_stmt :=
11378 'UPDATE msc_st_calendar_assignments '
11379 ||' SET batch_id = :lv_batch_id'
11380 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
11381 ||' AND sr_instance_code = :v_instance_code'
11382 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
11383 ||' AND rownum <= '||v_batch_size;
11384
11385
11386 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
11387
11388 EXECUTE IMMEDIATE lv_sql_stmt
11389 USING lv_batch_id,
11390 v_instance_code;
11391
11392 EXIT WHEN SQL%NOTFOUND;
11393
11394 OPEN c1(lv_batch_id);
11395 FETCH c1 BULK COLLECT INTO lb_rowid;
11396 CLOSE c1;
11397
11398 v_sql_stmt := 05;
11399 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
11400 UPDATE msc_st_calendar_assignments
11401 SET st_transaction_id = msc_st_calendar_assignments_s.NEXTVAL,
11402 refresh_id = v_refresh_id,
11403 last_update_date = v_current_date,
11404 last_updated_by = v_current_user,
11405 creation_date = v_current_date,
11406 created_by = v_current_user
11407 WHERE rowid = lb_rowid(j);
11408
11409 -- set the error message
11410
11411 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
11412 (p_app_short_name => 'MSC',
11413 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
11414 p_message_text => lv_message_text,
11415 p_error_text => lv_error_text,
11416 p_token1 => 'COLUMN_NAME',
11417 p_token_value1 => 'DELETED_FLAG',
11418 p_token2 => 'DEFAULT_VALUE',
11419 p_token_value2 => SYS_NO);
11420
11421 IF lv_return <> 0 THEN
11422 RAISE ex_logging_err;
11423 END IF;
11424
11425 lv_where_str :=
11426 ' AND NVL(deleted_flag,'||NULL_VALUE||') '
11427 ||' NOT IN(1,2)';
11428 --Log a warning for those records where the deleted_flag has a value other
11429 --than SYS_NO
11430 lv_return := MSC_ST_UTIL.LOG_ERROR
11431 (p_table_name => 'MSC_ST_CALENDAR_ASSIGNMENTS',
11432 p_instance_code => v_instance_code,
11433 p_row => lv_column_names,
11434 p_severity => G_SEV_WARNING,
11435 p_message_text => lv_message_text,
11436 p_error_text => lv_error_text,
11437 p_batch_id => lv_batch_id,
11438 p_where_str => lv_where_str,
11439 p_col_name => 'DELETED_FLAG',
11440 p_debug => v_debug,
11441 p_default_value => SYS_NO);
11442
11443 IF lv_return <> 0 THEN
11444 RAISE ex_logging_err;
11445 END IF;
11446
11447 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
11448 (p_app_short_name => 'MSC',
11449 p_error_code => 'MSC_PP_INVALID_VALUE',
11450 p_message_text => lv_message_text,
11451 p_error_text => lv_error_text,
11452 p_token1 => 'COLUMN_NAME',
11453 p_token_value1 => 'CALENDAR_TYPE');
11454
11455 IF lv_return <> 0 THEN
11456 RAISE ex_logging_err;
11457 END IF;
11458
11459 lv_sql_stmt :=
11460 'UPDATE msc_st_calendar_assignments '
11461 ||' SET process_flag = '||G_ERROR_FLG||','
11462 ||' error_text = '||''''||lv_message_text||''''
11463 ||' WHERE NVL(calendar_type,'||''''||NULL_CHAR||''''||') '
11464 ||' NOT IN(''RECEIVING'',''SHIPPING'', ''CARRIER'' )'
11465 ||' AND batch_id = :lv_batch_id'
11466 ||' AND sr_instance_code = :v_instance_code'
11467 ||' AND process_flag = '||G_IN_PROCESS;
11468
11469
11470 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
11471
11472 EXECUTE IMMEDIATE lv_sql_stmt
11473 USING lv_batch_id,
11474 v_instance_code;
11475
11476
11477 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
11478 (p_app_short_name => 'MSC',
11479 p_error_code => 'MSC_PP_INVALID_VALUE',
11480 p_message_text => lv_message_text,
11481 p_error_text => lv_error_text,
11482 p_token1 => 'COLUMN_NAME',
11483 p_token_value1 => 'ASSOCIATION_TYPE');
11484
11485 IF lv_return <> 0 THEN
11486 RAISE ex_logging_err;
11487 END IF;
11488
11489 -- error out the records where association_type is not correct
11490
11491 lv_sql_stmt :=
11492 'UPDATE msc_st_calendar_assignments '
11493 ||' SET process_flag = '||G_ERROR_FLG||','
11494 ||' error_text = '||''''||lv_message_text||''''
11495 ||' WHERE association_type '
11496 ||' NOT IN (SELECT lookup_code FROM mfg_lookups where lookup_type = ''MSC_UI_ASSIGNMENT_TYPE'')'
11497 ||' AND batch_id = :lv_batch_id'
11498 ||' AND sr_instance_code = :v_instance_code'
11499 ||' AND process_flag = '||G_IN_PROCESS;
11500
11501
11502 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
11503
11504 EXECUTE IMMEDIATE lv_sql_stmt
11505 USING lv_batch_id,
11506 v_instance_code;
11507
11508
11509 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
11510 (p_app_short_name => 'MSC',
11511 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
11512 p_message_text => lv_message_text,
11513 p_error_text => lv_error_text,
11514 p_token1 => 'COLUMN_NAME',
11515 p_token_value1 => 'PARTNER_TYPE');
11516
11517 IF lv_return <> 0 THEN
11518 RAISE ex_logging_err;
11519 END IF;
11520
11521 -- Error out records where partner_type NOT in (1,2,3,4)
11522 v_sql_stmt := 10;
11523 lv_sql_stmt :=
11524 'UPDATE msc_st_calendar_assignments'
11525 ||' SET process_flag = '||G_ERROR_FLG||','
11526 ||' error_text = '||''''||lv_message_text||''''
11527 ||' WHERE sr_instance_code = :v_instance_code'
11528 ||' AND batch_id = :lv_batch_id'
11529 ||' AND process_flag = '||G_IN_PROCESS
11530 ||' AND partner_type NOT IN (1,2,3,4)' ;
11531
11532
11533 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
11534 EXECUTE IMMEDIATE lv_sql_stmt
11535 USING v_instance_code,
11536 lv_batch_id;
11537
11538 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
11539 (p_app_short_name => 'MSC',
11540 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
11541 p_message_text => lv_message_text,
11542 p_error_text => lv_error_text,
11543 p_token1 => 'COLUMN_NAME',
11544 p_token_value1 => 'ASSOCIATION_LEVEL');
11545
11546 IF lv_return <> 0 THEN
11547 RAISE ex_logging_err;
11548 END IF;
11549
11550 -- Error out records where ASSOCIATION_LEVEL NOT in (1,2,3,4)
11551 v_sql_stmt := 11;
11552 lv_sql_stmt :=
11553 'UPDATE msc_st_calendar_assignments'
11554 ||' SET process_flag = '||G_ERROR_FLG||','
11555 ||' error_text = '||''''||lv_message_text||''''
11556 ||' WHERE sr_instance_code = :v_instance_code'
11557 ||' AND batch_id = :lv_batch_id'
11558 ||' AND process_flag = '||G_IN_PROCESS
11559 ||' AND association_level NOT IN (1,2,3,4)' ;
11560
11561
11562 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
11563 EXECUTE IMMEDIATE lv_sql_stmt
11564 USING v_instance_code,
11565 lv_batch_id;
11566
11567
11568 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
11569 (p_app_short_name => 'MSC',
11570 p_error_code => 'MSC_PP_COL_VAL_NULL',
11571 p_message_text => lv_message_text,
11572 p_error_text => lv_error_text,
11573 p_token1 => 'COLUMN_NAME',
11574 p_token_value1 => 'CALENDAR_CODE');
11575
11576 IF lv_return <> 0 THEN
11577 RAISE ex_logging_err;
11578 END IF;
11579
11580 -- Error out records where calendar_code is NULL
11581
11582 lv_sql_stmt :=
11583 'UPDATE msc_st_calendar_assignments '
11584 ||' SET process_flag = '||G_ERROR_FLG||','
11585 ||' error_text = '||''''||lv_message_text||''''
11586 ||' WHERE sr_instance_code = :v_instance_code'
11587 ||' AND batch_id = :lv_batch_id'
11588 ||' AND process_flag = '||G_IN_PROCESS
11589 ||' AND NVL(calendar_code, '||''''||NULL_CHAR||''''||')'
11590 ||' = '||''''||NULL_CHAR||'''' ;
11591
11592
11593 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
11594 EXECUTE IMMEDIATE lv_sql_stmt
11595 USING v_instance_code,
11596 lv_batch_id;
11597
11598
11599 -- We need to check correct association_type is attached to that particular record.
11600 -- For example if association_type is CARRIER_VENDOR_SITE, then for that particular record partner_name, partner_site_code and carrier_code should not be null
11601
11602
11603 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
11604 (p_app_short_name => 'MSC',
11605 p_error_code => 'MSC_PP_INVAL_ASSO_COMB',
11606 p_message_text => lv_message_text,
11607 p_error_text => lv_error_text,
11608 p_token1 => 'COLUMN_NAME',
11609 p_token_value1 => 'PARTNER_NAME OR PARTNER_SITE_CODE OR'
11610 ||'CARRIER_PARTNER_CODE');
11611
11612
11613 IF lv_return <> 0 THEN
11614 RAISE ex_logging_err;
11615 END IF;
11616
11617 lv_sql_stmt :=
11618 'UPDATE msc_st_calendar_assignments '
11619 ||' SET process_flag = '||G_ERROR_FLG||','
11620 ||' error_text = '||''''||lv_message_text||''''
11621 ||' WHERE sr_instance_code = :v_instance_code'
11622 ||' AND batch_id = :lv_batch_id'
11623 ||' AND process_flag = '||G_IN_PROCESS
11624 ||' AND association_type IN (10,11)'
11625 ||' AND (NVL(PARTNER_NAME, '||''''||NULL_CHAR||''''||') '
11626 ||' = '||''''||NULL_CHAR||''''
11627 ||' OR NVL(PARTNER_SITE_CODE, '||''''||NULL_CHAR||''''||') '
11628 ||' = '||''''||NULL_CHAR||''''
11629 ||' OR NVL(CARRIER_PARTNER_CODE, '||''''||NULL_CHAR||''''||') '
11630 ||' = '||''''||NULL_CHAR||''''||') ';
11631
11632
11633 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
11634
11635 EXECUTE IMMEDIATE lv_sql_stmt
11636 USING v_instance_code,
11637 lv_batch_id;
11638
11639
11640
11641 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
11642 (p_app_short_name => 'MSC',
11643 p_error_code => 'MSC_PP_INVAL_ASSO_COMB',
11644 p_message_text => lv_message_text,
11645 p_error_text => lv_error_text,
11646 p_token1 => 'COLUMN_NAME',
11647 p_token_value1 => 'PARTNER_NAME OR CARRIER_PARTNER_CODE');
11648
11649
11650
11651 IF lv_return <> 0 THEN
11652 RAISE ex_logging_err;
11653 END IF;
11654
11655 lv_sql_stmt :=
11656 'UPDATE msc_st_calendar_assignments '
11657 ||' SET process_flag = '||G_ERROR_FLG||','
11658 ||' error_text = '||''''||lv_message_text||''''
11659 ||' WHERE sr_instance_code = :v_instance_code'
11660 ||' AND batch_id = :lv_batch_id'
11661 ||' AND process_flag = '||G_IN_PROCESS
11662 ||' AND association_type IN (7,8)'
11663 ||' AND (NVL(PARTNER_NAME, '||''''||NULL_CHAR||''''||') '
11664 ||' = '||''''||NULL_CHAR||''''
11665 ||' OR NVL(CARRIER_PARTNER_CODE, '||''''||NULL_CHAR||''''||') '
11666 ||' = '||''''||NULL_CHAR||''''||') ';
11667
11668
11669 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
11670
11671 EXECUTE IMMEDIATE lv_sql_stmt
11672 USING v_instance_code,
11673 lv_batch_id;
11674
11675
11676 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
11677 (p_app_short_name => 'MSC',
11678 p_error_code => 'MSC_PP_INVAL_ASSO_COMB',
11679 p_message_text => lv_message_text,
11680 p_error_text => lv_error_text,
11681 p_token1 => 'COLUMN_NAME',
11682 p_token_value1 => 'ORGANIZATION_CODE OR CARRIER_PARTNER_CODE');
11683
11684
11685 IF lv_return <> 0 THEN
11686 RAISE ex_logging_err;
11687 END IF;
11688
11689 lv_sql_stmt :=
11690 'UPDATE msc_st_calendar_assignments '
11691 ||' SET process_flag = '||G_ERROR_FLG||','
11692 ||' error_text = '||''''||lv_message_text||''''
11693 ||' WHERE sr_instance_code = :v_instance_code'
11694 ||' AND batch_id = :lv_batch_id'
11695 ||' AND process_flag = '||G_IN_PROCESS
11696 ||' AND association_type = 9 '
11697 ||' AND (NVL(ORGANIZATION_CODE, '||''''||NULL_CHAR||''''||') '
11698 ||' = '||''''||NULL_CHAR||''''
11699 ||' OR NVL(CARRIER_PARTNER_CODE, '||''''||NULL_CHAR||''''||') '
11700 ||' = '||''''||NULL_CHAR||''''||') ';
11701
11702
11703 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
11704
11705 EXECUTE IMMEDIATE lv_sql_stmt
11706 USING v_instance_code,
11707 lv_batch_id;
11708
11709
11710 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
11711 (p_app_short_name => 'MSC',
11712 p_error_code => 'MSC_PP_INVAL_ASSO_COMB',
11713 p_message_text => lv_message_text,
11714 p_error_text => lv_error_text,
11715 p_token1 => 'COLUMN_NAME',
11716 p_token_value1 => 'PARTNER_NAME OR PARTNER_SITE_CODE');
11717
11718
11719 IF lv_return <> 0 THEN
11720 RAISE ex_logging_err;
11721 END IF;
11722
11723 lv_sql_stmt :=
11724 'UPDATE msc_st_calendar_assignments '
11725 ||' SET process_flag = '||G_ERROR_FLG||','
11726 ||' error_text = '||''''||lv_message_text||''''
11727 ||' WHERE sr_instance_code = :v_instance_code'
11728 ||' AND batch_id = :lv_batch_id'
11729 ||' AND process_flag = '||G_IN_PROCESS
11730 ||' AND association_type IN( 5,6 )'
11731 ||' AND (NVL(PARTNER_NAME, '||''''||NULL_CHAR||''''||') '
11732 ||' = '||''''||NULL_CHAR||''''
11733 ||' OR NVL(PARTNER_SITE_CODE, '||''''||NULL_CHAR||''''||') '
11734 ||' = '||''''||NULL_CHAR||''''||') ';
11735
11736
11737 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
11738
11739 EXECUTE IMMEDIATE lv_sql_stmt
11740 USING v_instance_code,
11741 lv_batch_id;
11742
11743
11744 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
11745 (p_app_short_name => 'MSC',
11746 p_error_code => 'MSC_PP_INVAL_ASSO_COMB',
11747 p_message_text => lv_message_text,
11748 p_error_text => lv_error_text,
11749 p_token1 => 'COLUMN_NAME',
11750 p_token_value1 => 'PARTNER_NAME OR ORGANIZATION_CODE OR CARRIER_PARTNER_CODE');
11751
11752
11753 IF lv_return <> 0 THEN
11754 RAISE ex_logging_err;
11755 END IF;
11756
11757 lv_sql_stmt :=
11758 'UPDATE msc_st_calendar_assignments '
11759 ||' SET process_flag = '||G_ERROR_FLG||','
11760 ||' error_text = '||''''||lv_message_text||''''
11761 ||' WHERE sr_instance_code = :v_instance_code'
11762 ||' AND batch_id = :lv_batch_id'
11763 ||' AND process_flag = '||G_IN_PROCESS
11764 ||' AND ((association_type IN( 1,2 )'
11765 ||' AND NVL(PARTNER_NAME, '||''''||NULL_CHAR||''''||') '
11766 ||' = '||''''||NULL_CHAR||''''||') '
11767 ||' OR (association_type =3 '
11768 ||' AND NVL(ORGANIZATION_CODE, '||''''||NULL_CHAR||''''||') '
11769 ||' = '||''''||NULL_CHAR||''''||') '
11770 ||' OR (association_type =4 '
11771 ||' AND NVL(CARRIER_PARTNER_CODE, '||''''||NULL_CHAR||''''||') '
11772 ||' = '||''''||NULL_CHAR||''''||')) ' ;
11773
11774
11775 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
11776
11777 EXECUTE IMMEDIATE lv_sql_stmt
11778 USING v_instance_code,
11779 lv_batch_id;
11780
11781
11782
11783 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
11784 (p_app_short_name => 'MSC',
11785 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
11786 p_message_text => lv_message_text,
11787 p_error_text => lv_error_text,
11788 p_token1 => 'COLUMN_NAMES',
11789 p_token_value1 => 'CALENDAR_CODE',
11790 p_token2 => 'MASTER_TABLE',
11791 p_token_value2 => 'MSC_CALENDARS',
11792 p_token3 => 'CHILD_TABLE',
11793 p_token_value3 => 'MSC_ST_CALENDAR_ASSIGNMENTS');
11794 IF lv_return <> 0 THEN
11795 RAISE ex_logging_err;
11796 END IF;
11797
11798 lv_sql_stmt :=
11799 'UPDATE msc_st_calendar_assignments msca'
11800 ||' SET process_flag = '||G_ERROR_FLG||','
11801 ||' error_text = '||''''||lv_message_text||''''
11802 ||' WHERE NOT EXISTS ( SELECT 1 '
11803 ||' FROM msc_calendars mc '
11804 ||' WHERE mc.calendar_code = msca.calendar_code '
11805 ||' AND mc.sr_instance_id = :v_instance_id )'
11806 ||' AND sr_instance_code = :v_instance_code'
11807 ||' AND batch_id = :lv_batch_id'
11808 ||' AND process_flag = '||G_IN_PROCESS;
11809
11810
11811
11812 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
11813 EXECUTE IMMEDIATE lv_sql_stmt
11814 USING v_instance_id,
11815 v_instance_code,
11816 lv_batch_id;
11817
11818
11819 -- Derive partner_id (supplier)
11820
11821 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
11822 (p_app_short_name => 'MSC',
11823 p_error_code => 'MSC_PP_INVALID_VALUE',
11824 p_message_text => lv_message_text,
11825 p_error_text => lv_error_text,
11826 p_token1 => 'COLUMN_NAME',
11827 p_token_value1 => 'PARTNER_NAME');
11828
11829 IF lv_return <> 0 THEN
11830 RAISE ex_logging_err;
11831 END IF;
11832
11833 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
11834 (p_table_name => 'MSC_ST_CALENDAR_ASSIGNMENTS',
11835 p_org_partner_name => 'PARTNER_NAME',
11836 p_org_partner_id => 'PARTNER_ID',
11837 p_instance_code => v_instance_code,
11838 p_partner_type => G_VENDOR,
11839 p_error_text => lv_error_text,
11840 p_batch_id => lv_batch_id,
11841 p_severity => G_SEV_ERROR,
11842 p_message_text => lv_message_text,
11843 p_debug => v_debug,
11844 p_row => lv_column_names);
11845
11846 IF lv_return <> 0 THEN
11847 RAISE ex_logging_err;
11848 END IF;
11849
11850 -- Derive partner_id (Customer)
11851
11852 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
11853 (p_app_short_name => 'MSC',
11854 p_error_code => 'MSC_PP_INVALID_VALUE',
11855 p_message_text => lv_message_text,
11856 p_error_text => lv_error_text,
11857 p_token1 => 'COLUMN_NAME',
11858 p_token_value1 => 'PARTNER_NAME');
11859
11860 IF lv_return <> 0 THEN
11861 RAISE ex_logging_err;
11862 END IF;
11863
11864 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
11865 (p_table_name => 'MSC_ST_CALENDAR_ASSIGNMENTS',
11866 p_org_partner_name => 'PARTNER_NAME',
11867 p_org_partner_id => 'PARTNER_ID',
11868 p_instance_code => v_instance_code,
11869 p_partner_type => G_CUSTOMER,
11870 p_error_text => lv_error_text,
11871 p_batch_id => lv_batch_id,
11872 p_severity => G_SEV_ERROR,
11873 p_message_text => lv_message_text,
11874 p_debug => v_debug,
11875 p_row => lv_column_names);
11876
11877 IF lv_return <> 0 THEN
11878 RAISE ex_logging_err;
11879 END IF;
11880
11881 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
11882 (p_app_short_name => 'MSC',
11883 p_error_code => 'MSC_PP_INVALID_VALUE',
11884 p_message_text => lv_message_text,
11885 p_error_text => lv_error_text,
11886 p_token1 => 'COLUMN_NAME',
11887 p_token_value1 => 'ORGANIZATION_CODE');
11888
11889 IF lv_return <> 0 THEN
11890 RAISE ex_logging_err;
11891 END IF;
11892
11893 --Derive Organization_id
11894 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
11895 (p_table_name => 'MSC_ST_CALENDAR_ASSIGNMENTS',
11896 p_org_partner_name => 'ORGANIZATION_CODE',
11897 p_org_partner_id => 'ORGANIZATION_ID',
11898 p_instance_code => v_instance_code,
11899 p_partner_type => G_ORGANIZATION,
11900 p_error_text => lv_error_text,
11901 p_batch_id => lv_batch_id,
11902 p_severity => G_SEV3_ERROR,
11903 p_message_text => lv_message_text,
11904 p_debug => v_debug,
11905 p_row => lv_column_names);
11906
11907 IF lv_return <> 0 THEN
11908 RAISE ex_logging_err;
11909 END IF;
11910
11911 -- Derive carrier_partner_id (Carrier)
11912
11913 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
11914 (p_app_short_name => 'MSC',
11915 p_error_code => 'MSC_PP_INVALID_VALUE',
11916 p_message_text => lv_message_text,
11917 p_error_text => lv_error_text,
11918 p_token1 => 'COLUMN_NAME',
11919 p_token_value1 => 'CARRIER_PARTNER_CODE');
11920
11921 IF lv_return <> 0 THEN
11922 RAISE ex_logging_err;
11923 END IF;
11924
11925 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
11926 (p_table_name => 'MSC_ST_CALENDAR_ASSIGNMENTS',
11927 p_org_partner_name => 'CARRIER_PARTNER_CODE',
11928 p_org_partner_id => 'CARRIER_PARTNER_ID',
11929 p_instance_code => v_instance_code,
11930 p_partner_type => G_CARRIER,
11931 p_error_text => lv_error_text,
11932 p_batch_id => lv_batch_id,
11933 p_severity => G_SEV3_ERROR,
11934 p_message_text => lv_message_text,
11935 p_debug => v_debug,
11936 p_row => lv_column_names);
11937
11938 IF lv_return <> 0 THEN
11939 RAISE ex_logging_err;
11940 END IF;
11941
11942 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
11943 (p_app_short_name => 'MSC',
11944 p_error_code => 'MSC_PP_INVALID_VALUE',
11945 p_message_text => lv_message_text,
11946 p_error_text => lv_error_text,
11947 p_token1 => 'COLUMN_NAME',
11948 p_token_value1 => 'PARTNER_SITE_CODE');
11949
11950 IF lv_return <> 0 THEN
11951 RAISE ex_logging_err;
11952 END IF;
11953
11954 --Derive partner_site_id (Supplier)
11955 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
11956 (p_table_name => 'MSC_ST_CALENDAR_ASSIGNMENTS',
11957 p_partner_name => 'PARTNER_NAME',
11958 p_partner_site_code => 'PARTNER_SITE_CODE',
11959 p_partner_site_id => 'PARTNER_SITE_ID',
11960 p_instance_code => v_instance_code,
11961 p_partner_type => G_VENDOR,
11962 p_error_text => lv_error_text,
11963 p_batch_id => lv_batch_id,
11964 p_severity => G_SEV3_ERROR,
11965 p_message_text => lv_message_text,
11966 p_debug => v_debug,
11967 p_row => lv_column_names);
11968
11969 IF lv_return <> 0 THEN
11970 RAISE ex_logging_err;
11971 END IF;
11972
11973 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
11974 (p_app_short_name => 'MSC',
11975 p_error_code => 'MSC_PP_INVALID_VALUE',
11976 p_message_text => lv_message_text,
11977 p_error_text => lv_error_text,
11978 p_token1 => 'COLUMN_NAME',
11979 p_token_value1 => 'PARTNER_SITE_CODE');
11980
11981 IF lv_return <> 0 THEN
11982 RAISE ex_logging_err;
11983 END IF;
11984
11985 --Derive partner_site_id (Customer)
11986 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
11987 (p_table_name => 'MSC_ST_CALENDAR_ASSIGNMENTS',
11988 p_partner_name => 'PARTNER_NAME',
11989 p_partner_site_code => 'PARTNER_SITE_CODE',
11990 p_partner_site_id => 'PARTNER_SITE_ID',
11991 p_instance_code => v_instance_code,
11992 p_partner_type => G_CUSTOMER,
11993 p_error_text => lv_error_text,
11994 p_batch_id => lv_batch_id,
11995 p_severity => G_SEV3_ERROR,
11996 p_message_text => lv_message_text,
11997 p_debug => v_debug,
11998 p_row => lv_column_names);
11999
12000 IF lv_return <> 0 THEN
12001 RAISE ex_logging_err;
12002 END IF;
12003
12004 --Call to customised validation.
12005 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
12006 (ERRBUF => lv_error_text,
12007 RETCODE => lv_return,
12008 pBatchID => lv_batch_id,
12009 pInstanceCode => v_instance_code,
12010 pEntityName => 'MSC_ST_CALENDAR_ASSIGNMENTS',
12011 pInstanceID => v_instance_id);
12012
12013 IF NVL(lv_return,0) <> 0 THEN
12014 RAISE ex_logging_err;
12015 END IF;
12016
12017 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
12018 (p_table_name => 'MSC_ST_CALENDAR_ASSIGNMENTS',
12019 p_instance_id => v_instance_id,
12020 p_instance_code => v_instance_code,
12021 p_process_flag => G_VALID,
12022 p_error_text => lv_error_text,
12023 p_debug => v_debug,
12024 p_batch_id => lv_batch_id);
12025
12026 IF lv_return <> 0 THEN
12027 RAISE ex_logging_err;
12028 END IF;
12029
12030 lv_return := MSC_ST_UTIL.LOG_ERROR
12031 (p_table_name => 'MSC_ST_CALENDAR_ASSIGNMENTS',
12032 p_instance_code => v_instance_code,
12033 p_row => lv_column_names,
12034 p_severity => G_SEV_ERROR,
12035 p_message_text => NULL,
12036 p_error_text => lv_error_text,
12037 p_debug => v_debug,
12038 p_batch_id => lv_batch_id);
12039
12040 IF lv_return <> 0 THEN
12041 RAISE ex_logging_err;
12042 END IF;
12043 COMMIT;
12044 END LOOP;
12045
12046 EXCEPTION
12047
12048 WHEN too_many_rows THEN
12049 lv_error_text := substr('MSC_CL_PRE_PROCESS.MSC_ST_CALENDAR_ASSIGNMENTS'||'('
12050 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
12051 ROLLBACK ;
12052
12053 WHEN ex_logging_err THEN
12054 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
12055 ROLLBACK;
12056
12057 WHEN OTHERS THEN
12058 lv_error_text := substr('MSC_CL_PRE_PROCESS.MSC_ST_CALENDAR_ASSIGNMENTS '||'('
12059 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
12060 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
12061 ROLLBACK;
12062
12063 END LOAD_CALENDAR_ASSIGNMENTS;
12064
12065
12066 ------------------7704614-----------------------------------------------------
12067 PROCEDURE LOAD_SALES_CHANNEL IS
12068 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
12069 lb_rowid RowidTab; --bulk collects rowid
12070 lv_return NUMBER;
12071 lv_error_text VARCHAR2(250);
12072 lv_where_str VARCHAR2(5000);
12073 lv_sql_stmt VARCHAR2(5000);
12074 lv_column_names VARCHAR2(5000); --stores concatenated column names
12075 lv_message_text msc_errors.error_text%TYPE;
12076
12077 ex_logging_err EXCEPTION;
12078
12079 CURSOR c1 IS
12080 SELECT rowid
12081 FROM msc_st_sr_lookups
12082 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
12083 AND sr_instance_code = v_instance_code;
12084
12085 BEGIN
12086
12087 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
12088 (p_app_short_name => 'MSC',
12089 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
12090 p_message_text => lv_message_text,
12091 p_error_text => lv_error_text);
12092
12093 IF lv_return <> 0 THEN
12094 RAISE ex_logging_err;
12095 END IF;
12096
12097 --Validation check for the table msc_st_sr_lookups
12098
12099 --Duplicate records check for the records whose source is other than XML
12100 --Different SQL is used because in XML we can identify the latest records
12101 --whereas in batch load we cannot.
12102
12103 v_sql_stmt := 01;
12104 lv_sql_stmt :=
12105 'UPDATE msc_st_sr_lookups mssc1 '
12106 ||' SET process_flag = '||G_ERROR_FLG||','
12107 ||' error_text = '||''''||lv_message_text||''''
12108 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_sr_lookups mssc2 '
12109 ||' WHERE mssc2.sr_instance_code = mssc1.sr_instance_code'
12110 ||' AND mssc2.lookup_code = mssc1.lookup_code'
12111 ||' AND NVL(mssc2.company_name, '||''''||NULL_CHAR||''''||') = '
12112 ||' NVL(mssc1.company_name, '||''''||NULL_CHAR||''''||')'
12113 ||' AND mssc2.process_flag = mssc1.process_flag'
12114 ||' AND NVL(mssc2.message_id,NULL) IS NULL'
12115 ||' GROUP BY sr_instance_code,lookup_code,company_name '
12116 ||' HAVING COUNT(*) >1 )'
12117 ||' AND mssc1.process_flag = '||G_IN_PROCESS
12118 ||' AND mssc1.sr_instance_code = :v_instance_code'
12119 ||' AND NVL(mssc1.message_id,NULL) IS NULL';
12120
12121 IF V_DEBUG THEN
12122 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
12123 END IF;
12124
12125
12126 EXECUTE IMMEDIATE lv_sql_stmt
12127 USING v_instance_code;
12128
12129
12130 --Duplicate records check for the records whose source is XML
12131 v_sql_stmt := 02;
12132 lv_sql_stmt :=
12133 'UPDATE msc_st_sr_lookups mssc1 '
12134 ||' SET process_flag = '||G_ERROR_FLG||','
12135 ||' error_text = '||''''||lv_message_text||''''
12136 ||' WHERE message_id < ( SELECT max(message_id) '
12137 ||' FROM msc_st_sr_lookups mssc2'
12138 ||' WHERE mssc2.sr_instance_code = mssc1.sr_instance_code'
12139 ||' AND mssc2.lookup_code = mssc1.lookup_code'
12140 ||' AND NVL(mssc2.company_name, '||''''||NULL_CHAR||''''||') = '
12141 ||' NVL(mssc1.company_name, '||''''||NULL_CHAR||''''||')'
12142 ||' AND mssc2.process_flag = mssc1.process_flag'
12143 ||' AND NVL(mssc2.message_id,NULL) IS NOT NULL) '
12144 ||' AND mssc1.process_flag = '||G_IN_PROCESS
12145 ||' AND mssc1.sr_instance_code = :v_instance_code '
12146 ||' AND NVL(mssc1.message_id,NULL) IS NOT NULL';
12147
12148 IF V_DEBUG THEN
12149 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
12150 END IF;
12151
12152 EXECUTE IMMEDIATE lv_sql_stmt
12153 USING v_instance_code;
12154
12155
12156 lv_column_names :=
12157 ' LOOKUP_CODE ||''~''||'
12158 ||' MEANING ||''~''||'
12159 ||' DESCRIPTION ||''~''||'
12160 ||' FROM_DATE ||''~''||'
12161 ||' TO_DATE ||''~''||'
12162 ||' ENABLED_FLAG ||''~''||'
12163 ||' SR_INSTANCE_CODE ||''~''||'
12164 ||' COMPANY_NAME ||''~''||'
12165 ||' DELETED_FLAG ';
12166
12167
12168 v_sql_stmt := 04;
12169
12170 OPEN c1;
12171 FETCH c1 BULK COLLECT INTO lb_rowid;
12172 CLOSE c1;
12173
12174 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
12175 UPDATE msc_st_sr_lookups
12176 SET st_transaction_id = MSC_ST_SALES_CHANNEL_S.nextval,
12177 refresh_id = v_refresh_id,
12178 last_update_date = v_current_date,
12179 last_updated_by = v_current_user,
12180 creation_date = v_current_date,
12181 created_by = v_current_user
12182 WHERE rowid = lb_rowid(j);
12183
12184
12185
12186 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
12187 (p_app_short_name => 'MSC',
12188 p_error_code => 'MSC_PP_NO_DELETION',
12189 p_message_text => lv_message_text,
12190 p_error_text => lv_error_text,
12191 p_token1 => 'TABLE_NAME',
12192 p_token_value1 => 'MSC_ST_SR_LOOKUPS');
12193
12194 -- Deletion is not allowed for this table
12195 v_sql_stmt := 05;
12196 lv_sql_stmt :=
12197 'UPDATE msc_st_sr_lookups '
12198 ||' SET process_flag = '||G_ERROR_FLG||','
12199 ||' error_text = '||''''||lv_message_text||''''
12200 ||' WHERE deleted_flag = '||SYS_YES
12201 ||' AND process_flag = '||G_IN_PROCESS
12202 ||' AND sr_instance_code = :v_instance_code';
12203
12204 IF V_DEBUG THEN
12205 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
12206 END IF;
12207
12208 EXECUTE IMMEDIATE lv_sql_stmt
12209 USING v_instance_code;
12210
12211 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
12212 (p_app_short_name => 'MSC',
12213 p_error_code => 'MSC_PP_COL_VAL_NULL',
12214 p_message_text => lv_message_text,
12215 p_error_text => lv_error_text,
12216 p_token1 => 'COLUMN_NAME',
12217 p_token_value1 => 'LOOKUP_CODE OR MEANING');
12218
12219 IF lv_return <> 0 THEN
12220 RAISE ex_logging_err;
12221 END IF;
12222
12223 -- Error out records where sales_channel or meaning is NULL
12224
12225 v_sql_stmt := 06;
12226 lv_sql_stmt :=
12227 'UPDATE msc_st_sr_lookups'
12228 ||' SET process_flag = '||G_ERROR_FLG||','
12229 ||' error_text = '||''''||lv_message_text||''''
12230 ||' WHERE (NVL(lookup_code,NULL) IS NULL '
12231 ||' OR NVL(meaning,NULL) IS NULL) '
12232 ||' AND process_flag = '||G_IN_PROCESS
12233 ||' AND sr_instance_code = :v_instance_code';
12234
12235 IF V_DEBUG THEN
12236 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
12237 END IF;
12238 EXECUTE IMMEDIATE lv_sql_stmt
12239 USING v_instance_code;
12240
12241
12242 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
12243 (p_app_short_name => 'MSC',
12244 p_error_code => 'MSC_PP_NO_UPDATION',
12245 p_message_text => lv_message_text,
12246 p_error_text => lv_error_text,
12247 p_token1 => 'TABLE_NAME',
12248 p_token_value1 => 'MSC_ST_SR_LOOKUPS');
12249
12250
12251 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
12252 (p_app_short_name => 'MSC',
12253 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
12254 p_message_text => lv_message_text,
12255 p_error_text => lv_error_text,
12256 p_token1 => 'COLUMN_NAME',
12257 p_token_value1 => 'ENABLED_FLAG',
12258 p_token2 => 'DEFAULT_VALUE',
12259 p_token_value2 => SYS_NO);
12260
12261 IF lv_return <> 0 THEN
12262 RAISE ex_logging_err;
12263 END IF;
12264
12265 -- Check ENABLED_FLAG column has valid value or not and if not set it to SYS_NO
12266 -- Log error procedure inserts warning and also defaults the delete flag
12267
12268 lv_where_str := ' AND NVL(enabled_flag,'||NULL_VALUE||') '
12269 ||' NOT IN(1,2)';
12270
12271 lv_return := MSC_ST_UTIL.LOG_ERROR
12272 (p_table_name => 'MSC_ST_SR_LOOKUPS',
12273 p_instance_code => v_instance_code,
12274 p_row => lv_column_names,
12275 p_severity => G_SEV_WARNING,
12276 p_message_text => lv_message_text,
12277 p_error_text => lv_error_text,
12278 p_where_str => lv_where_str,
12279 p_col_name => 'ENABLED_FLAG',
12280 p_debug => v_debug,
12281 p_default_value => SYS_YES);
12282
12283 IF lv_return <> 0 THEN
12284 RAISE ex_logging_err;
12285 END IF;
12286
12287 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
12288 (p_app_short_name => 'MSC',
12289 p_error_code => 'MSC_PP_INVALID_VALUE',
12290 p_message_text => lv_message_text,
12291 p_error_text => lv_error_text,
12292 p_token1 => 'COLUMN_NAME',
12293 p_token_value1 => 'FROM_DATE OR'
12294 ||' TO_DATE');
12295
12296 IF lv_return <> 0 THEN
12297 RAISE ex_logging_err;
12298 END IF;
12299
12300
12301 -- Validate that from_date is greater than to_date
12302
12303 v_sql_stmt := 07;
12304 lv_sql_stmt :=
12305 'UPDATE msc_st_sr_lookups'
12306 ||' SET process_flag = '||G_ERROR_FLG||','
12307 ||' error_text = '||''''||lv_message_text||''''
12308 ||' WHERE NVL(from_date,SYSDATE-365000 ) '
12309 ||' > NVL(to_date, SYSDATE+365000) '
12310 ||' AND process_flag = '||G_IN_PROCESS
12311 ||' AND sr_instance_code = :v_instance_code';
12312
12313 IF V_DEBUG THEN
12314 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
12315 END IF;
12316 EXECUTE IMMEDIATE lv_sql_stmt
12317 USING v_instance_code;
12318
12319 --Call to customised validation.
12320 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
12321 (ERRBUF => lv_error_text,
12322 RETCODE => lv_return,
12323 pBatchID => NULL,
12324 pInstanceCode => v_instance_code,
12325 pEntityName => 'MSC_ST_SR_LOOKUPS',
12326 pInstanceID => v_instance_id);
12327
12328 IF NVL(lv_return,0) <> 0 THEN
12329 RAISE ex_logging_err;
12330 END IF;
12331 -- Set the process flag as Valid and populate instance_id
12332 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
12333 (p_table_name => 'MSC_ST_SR_LOOKUPS',
12334 p_instance_id => v_instance_id,
12335 p_instance_code => v_instance_code,
12336 p_process_flag => G_VALID,
12337 p_error_text => lv_error_text,
12338 p_debug => v_debug);
12339
12340 IF lv_return <> 0 THEN
12341 RAISE ex_logging_err;
12342 END IF;
12343
12344 -- At the end calling the LOG_ERROR for logging all
12345 -- errored out records.
12346
12347 lv_return := MSC_ST_UTIL.LOG_ERROR
12348 (p_table_name => 'MSC_ST_SR_LOOKUPS',
12349 p_instance_code => v_instance_code,
12350 p_row => lv_column_names,
12351 p_severity => G_SEV_ERROR,
12352 p_message_text => NULL,
12353 p_error_text => lv_error_text,
12354 p_debug => v_debug );
12355
12356 IF lv_return <> 0 THEN
12357 RAISE ex_logging_err;
12358 END IF;
12359
12360
12361 COMMIT;
12362 EXCEPTION
12363
12364 WHEN ex_logging_err THEN
12365 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_error_text);
12366 -- G_WARNING_FLAG := 1;
12367 ROLLBACK;
12368
12369 WHEN OTHERS THEN
12370 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_SALES_CHANNEL '||'('
12371 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
12372 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_error_text);
12373 -- G_WARNING_FLAG := 1;
12374 ROLLBACK;
12375
12376 END LOAD_SALES_CHANNEL;
12377
12378 PROCEDURE LOAD_FISCAL_CALENDAR
12379 IS
12380 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
12381
12382 lb_rowid RowidTab;
12383 lv_sql_stmt VARCHAR2(4000);
12384 lv_message_text msc_errors.error_text%TYPE;
12385 lv_error_text VARCHAR2(250);
12386 lv_debug BOOLEAN := msc_cl_pre_process.v_debug;
12387 lv_current_user NUMBER := msc_cl_pre_process.v_current_user;
12388 lv_current_date DATE := msc_cl_pre_process.v_current_date;
12389 lv_return NUMBER := 0;
12390 lv_instance_code VARCHAR2(3);
12391
12392 ex_logging_err EXCEPTION;
12393 lv_column_names VARCHAR2(5000);
12394
12395 CURSOR c1 IS
12396 SELECT rowid
12397 FROM msc_st_calendar_months
12398 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
12399 AND sr_instance_code = v_instance_code;
12400
12401
12402 BEGIN
12403
12404 lv_column_names :=
12405 ' SR_INSTANCE_CODE ||''~''||'
12406 ||' CALENDAR_CODE ||''~''||'
12407 ||' YEAR ||''~''||'
12408 ||' YEAR_DESCRIPTION ||''~''||'
12409 ||' YEAR_START_DATE ||''~''||'
12410 ||' YEAR_END_DATE ||''~''||'
12411 ||' QUARTER ||''~''||'
12412 ||' QUARTER_DESCRIPTION ||''~''||'
12413 ||' QUARTER_START_DATE ||''~''||'
12414 ||' QUARTER_END_DATE ||''~''||'
12415 ||' MONTH ||''~''||'
12416 ||' MONTH_DESCRIPTION ||''~''||'
12417 ||' MONTH_START_DATE ||''~''||'
12418 ||' MONTH_END_DATE ';
12419
12420
12421 OPEN c1;
12422 FETCH c1 BULK COLLECT INTO lb_rowid;
12423 CLOSE c1;
12424
12425 v_sql_stmt := 01;
12426 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
12427 UPDATE msc_st_calendar_months
12428 SET st_transaction_id = msc_st_calendar_months_s.NEXTVAL,
12429 last_update_date = lv_current_date,
12430 last_updated_by = lv_current_user,
12431 creation_date = lv_current_date,
12432 created_by = lv_current_user
12433 WHERE rowid = lb_rowid(j);
12434
12435
12436
12437 -- set the message
12438
12439 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
12440 (p_app_short_name => 'MSC',
12441 p_error_code => 'MSC_PP_COL_VAL_NULL',
12442 p_message_text => lv_message_text,
12443 p_error_text => lv_error_text,
12444 p_token1 => 'COLUMN_NAME',
12445 p_token_value1 => 'YEAR OR '
12446 ||'YEAR_DESCRIPTION OR '
12447 ||'YEAR_START_DATE OR '
12448 ||'YEAR_END_DATE OR '
12449 ||'QUARTER OR '
12450 ||'QUARTER_DESCRIPTION OR '
12451 ||'QUARTER_START_DATE OR '
12452 ||'QUARTER_END_DATE OR '
12453 ||'MONTH OR '
12454 ||'MONTH_DESCRIPTION OR '
12455 ||'MONTH_ START DATE OR '
12456 ||'MONTH END DATE ');
12457
12458
12459 IF lv_return <> 0 THEN
12460 RAISE ex_logging_err;
12461 END IF;
12462
12463 -- Error out the records if any of the details regarding Month, Year or
12464 -- Date is not provided.
12465
12466 v_sql_stmt := 02;
12467 lv_sql_stmt :=
12468 'UPDATE msc_st_calendar_months'
12469 ||' SET process_flag = '||G_ERROR_FLG||','
12470 ||' error_text = '||''''||lv_message_text||''''
12471 ||' WHERE ( year IS NULL'
12472 ||' OR year_description IS NULL'
12473 ||' OR year_start_date IS NULL'
12474 ||' OR year_end_date IS NULL'
12475 ||' OR quarter IS NULL'
12476 ||' OR quarter_description IS NULL'
12477 ||' OR quarter_start_date IS NULL'
12478 ||' OR quarter_end_date IS NULL'
12479 ||' OR month IS NULL'
12480 ||' OR month_description IS NULL'
12481 ||' OR month_start_date IS NULL'
12482 ||' OR month_end_date IS NULL)'
12483 ||' AND process_flag = '||G_IN_PROCESS
12484 ||' AND sr_instance_code = :v_instance_code';
12485
12486 IF lv_debug THEN
12487 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
12488 END IF;
12489 EXECUTE IMMEDIATE lv_sql_stmt
12490 USING v_instance_code;
12491
12492 -- set the message
12493
12494 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
12495 (p_app_short_name => 'MSC',
12496 p_error_code => 'MSC_PP_END_GT_ST_DATE',
12497 p_message_text => lv_message_text,
12498 p_error_text => lv_error_text );
12499
12500
12501 IF lv_return <> 0 THEN
12502 RAISE ex_logging_err;
12503 END IF;
12504
12505 -- All the start date should be less than end date
12506
12507 v_sql_stmt := 03;
12508 lv_sql_stmt :=
12509 'UPDATE msc_st_calendar_months'
12510 ||' SET process_flag = '||G_ERROR_FLG||','
12511 ||' error_text = '||''''||lv_message_text||''''
12512 ||' WHERE (year_start_date >= year_end_date'
12513 ||' OR quarter_start_date >= quarter_end_date'
12514 ||' OR month_start_date >= month_end_date)'
12515 ||' AND process_flag = '||G_IN_PROCESS
12516 ||' AND sr_instance_code = :v_instance_code';
12517
12518 IF lv_debug THEN
12519 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
12520 END IF;
12521 EXECUTE IMMEDIATE lv_sql_stmt
12522 USING v_instance_code;
12523
12524 --Call to customised validation.
12525 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
12526 (ERRBUF => lv_error_text,
12527 RETCODE => lv_return,
12528 pBatchID => NULL,
12529 pInstanceCode => v_instance_code,
12530 pEntityName => 'MSC_ST_CALENDAR_MONTHS',
12531 pInstanceID => v_instance_id);
12532
12533 IF NVL(lv_return,0) <> 0 THEN
12534 RAISE ex_logging_err;
12535 END IF;
12536 -- Set the process flag as Valid and populate instance_id
12537 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
12538 (p_table_name => 'MSC_ST_CALENDAR_MONTHS',
12539 p_instance_id => v_instance_id,
12540 p_instance_code => v_instance_code,
12541 p_process_flag => G_VALID,
12542 p_error_text => lv_error_text,
12543 p_debug => v_debug);
12544
12545 IF lv_return <> 0 THEN
12546 RAISE ex_logging_err;
12547 END IF;
12548
12549 -- Inserting all the errored out records into MSC_ERRORS:
12550
12551 lv_return := MSC_ST_UTIL.LOG_ERROR
12552 (p_table_name => 'MSC_ST_CALENDAR_MONTHS',
12553 p_instance_code => v_instance_code,
12554 p_row => lv_column_names,
12555 p_severity => G_SEV_ERROR,
12556 p_error_text => lv_error_text,
12557 p_message_text => NULL);
12558
12559 IF(lv_return <> 0) THEN
12560 RAISE ex_logging_err;
12561 END IF;
12562
12563 COMMIT;
12564 EXCEPTION
12565 WHEN ex_logging_err THEN
12566 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_error_text);
12567 -- G_WARNING_FLAG := 1;
12568 ROLLBACK;
12569
12570 WHEN OTHERS THEN
12571 ROLLBACK;
12572
12573 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_FISCAL_CALENDAR '||'('
12574 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
12575 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_error_text);
12576 -- G_WARNING_FLAG := 1;
12577 ROLLBACK;
12578
12579 END LOAD_FISCAL_CALENDAR;
12580 ------------------7704614-----------------------------------------------------
12581 --- CMRO Proj bug 9135694
12582 PROCEDURE LOAD_VISITS IS
12583 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
12584 lb_rowid RowidTab; --bulk collects rowid
12585 lv_return NUMBER;
12586 lv_error_text VARCHAR2(250);
12587 lv_where_str VARCHAR2(5000);
12588 lv_sql_stmt VARCHAR2(5000);
12589 lv_column_names VARCHAR2(5000); --stores concatenated column names
12590 lv_batch_id msc_st_visits.batch_id%TYPE;
12591 lv_message_text msc_errors.error_text%TYPE;
12592
12593 ex_logging_err EXCEPTION;
12594
12595 CURSOR c1(p_batch_id NUMBER) IS
12596 SELECT rowid
12597 FROM msc_st_visits
12598 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
12599 AND batch_id = p_batch_id
12600 AND sr_instance_code = v_instance_code;
12601
12602 CURSOR C2(p_batch_id NUMBER) IS
12603 SELECT max(rowid)
12604 FROM msc_st_visits
12605 WHERE process_flag = G_IN_PROCESS
12606 AND sr_instance_code = v_instance_code
12607 AND batch_id = p_batch_id
12608 AND NVL(visit_id,NULL_VALUE) = NULL_VALUE
12609 GROUP BY sr_instance_code,visit_name;
12610
12611 BEGIN
12612 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'IN LOAD VISIT ');
12613 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
12614 (p_app_short_name => 'MSC',
12615 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
12616 p_message_text => lv_message_text,
12617 p_error_text => lv_error_text);
12618
12619 IF lv_return <> 0 THEN
12620 RAISE ex_logging_err;
12621 END IF;
12622
12623 --Validation check for the table msc_st_visits
12624
12625 --Duplicate records check for the records whose source is other than XML
12626 --Different SQL is used because in XML we can identify the latest records
12627 --whereas in batch load we cannot.
12628
12629 v_sql_stmt := 01;
12630 lv_sql_stmt :=
12631 'UPDATE msc_st_visits mssc1 '
12632 ||' SET process_flag = '||G_ERROR_FLG||','
12633 ||' error_text = '||''''||lv_message_text||''''
12634 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_visits mssc2 '
12635 ||' WHERE mssc2.sr_instance_code = mssc1.sr_instance_code'
12636 ||' AND mssc2.visit_name = mssc1.visit_name'
12637 ||' AND mssc2.process_flag = mssc1.process_flag'
12638 ||' AND NVL(mssc2.message_id,NULL) IS NULL'
12639 ||' GROUP BY sr_instance_code,visit_name'
12640 ||' HAVING COUNT(*) >1 )'
12641 ||' AND mssc1.process_flag = '||G_IN_PROCESS
12642 ||' AND mssc1.sr_instance_code = :v_instance_code'
12643 ||' AND NVL(mssc1.message_id,NULL) IS NULL';
12644
12645 IF V_DEBUG THEN
12646 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
12647 END IF;
12648
12649
12650 EXECUTE IMMEDIATE lv_sql_stmt
12651 USING v_instance_code;
12652
12653
12654 --Duplicate records check for the records whose source is XML
12655 v_sql_stmt := 02;
12656 lv_sql_stmt :=
12657 'UPDATE msc_st_visits mssc1 '
12658 ||' SET process_flag = '||G_ERROR_FLG||','
12659 ||' error_text = '||''''||lv_message_text||''''
12660 ||' WHERE message_id < ( SELECT max(message_id) '
12661 ||' FROM msc_st_visits mssc2'
12662 ||' WHERE mssc2.sr_instance_code = mssc1.sr_instance_code'
12663 ||' AND mssc2.visit_name = mssc1.visit_name'
12664 ||' AND mssc2.process_flag = mssc1.process_flag'
12665 ||' AND NVL(mssc2.message_id,NULL) IS NOT NULL) '
12666 ||' AND mssc1.process_flag = '||G_IN_PROCESS
12667 ||' AND mssc1.sr_instance_code = :v_instance_code '
12668 ||' AND NVL(mssc1.message_id,NULL) IS NOT NULL';
12669
12670 IF V_DEBUG THEN
12671 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
12672 END IF;
12673
12674 EXECUTE IMMEDIATE lv_sql_stmt
12675 USING v_instance_code;
12676
12677
12678 lv_column_names :=
12679 ' VISIT_NAME ||''~''||'
12680 ||' VISIT_DESC ||''~''||'
12681 ||' VISIT_START_DATE ||''~''||'
12682 ||' VISIT_END_DATE ||''~''||'
12683 ||' SR_INSTANCE_CODE ||''~''||'
12684 ||' DELETED_FLAG ';
12685
12686
12687 LOOP
12688 v_sql_stmt := 03;
12689 SELECT msc_st_batch_id_s.NEXTVAL
12690 INTO lv_batch_id
12691 FROM dual;
12692
12693 v_sql_stmt := 04;
12694 lv_sql_stmt :=
12695 'UPDATE msc_st_visits '
12696 ||' SET batch_id = :lv_batch_id'
12697 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
12698 ||' AND sr_instance_code = :v_instance_code'
12699 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
12700 ||' AND rownum <= '||v_batch_size;
12701
12702
12703 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
12704
12705 EXECUTE IMMEDIATE lv_sql_stmt
12706 USING lv_batch_id,
12707 v_instance_code;
12708
12709 EXIT WHEN SQL%NOTFOUND;
12710
12711 OPEN c1(lv_batch_id);
12712 FETCH c1 BULK COLLECT INTO lb_rowid;
12713 CLOSE c1;
12714
12715 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
12716 UPDATE msc_st_visits
12717 SET st_transaction_id = msc_st_visits_s.nextval,
12718 refresh_id = v_refresh_id,
12719 last_update_date = v_current_date,
12720 last_updated_by = v_current_user,
12721 creation_date = v_current_date,
12722 created_by = v_current_user
12723 WHERE rowid = lb_rowid(j);
12724
12725 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
12726 (p_app_short_name => 'MSC',
12727 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
12728 p_message_text => lv_message_text,
12729 p_error_text => lv_error_text,
12730 p_token1 => 'COLUMN_NAME',
12731 p_token_value1 => 'DELETED_FLAG',
12732 p_token2 => 'DEFAULT_VALUE',
12733 p_token_value2 => SYS_NO);
12734
12735 IF lv_return <> 0 THEN
12736 RAISE ex_logging_err;
12737 END IF;
12738
12739 lv_where_str :=
12740 ' AND NVL(deleted_flag,'||NULL_VALUE||') '
12741 ||' NOT IN(1,2)';
12742 --Log a warning for those records where the deleted_flag has a value other
12743 --than SYS_NO
12744 lv_return := MSC_ST_UTIL.LOG_ERROR
12745 (p_table_name => 'MSC_ST_VISITS',
12746 p_instance_code => v_instance_code,
12747 p_row => lv_column_names,
12748 p_severity => G_SEV_WARNING,
12749 p_message_text => lv_message_text,
12750 p_error_text => lv_error_text,
12751 p_batch_id => lv_batch_id,
12752 p_where_str => lv_where_str,
12753 p_col_name => 'DELETED_FLAG',
12754 p_debug => v_debug,
12755 p_default_value => SYS_NO);
12756
12757 IF lv_return <> 0 THEN
12758 RAISE ex_logging_err;
12759 END IF;
12760
12761 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
12762 (p_app_short_name => 'MSC',
12763 p_error_code => 'MSC_PP_COL_VAL_NULL',
12764 p_message_text => lv_message_text,
12765 p_error_text => lv_error_text,
12766 p_token1 => 'COLUMN_NAME',
12767 p_token_value1 => 'VISIT_NAME OR '
12768 ||'VISIT_START_DATE OR '
12769 ||'VISIT_END_DATE');
12770
12771 IF lv_return <> 0 THEN
12772 RAISE ex_logging_err;
12773 END IF;
12774
12775 -- Error out records where visit_name, visit start/end date is NULL
12776
12777 v_sql_stmt := 06;
12778 lv_sql_stmt :=
12779 'UPDATE msc_st_visits'
12780 ||' SET process_flag = '||G_ERROR_FLG||','
12781 ||' error_text = '||''''||lv_message_text||''''
12782 ||' WHERE ( VISIT_NAME IS NULL'
12783 ||' OR VISIT_START_DATE IS NULL'
12784 ||' OR VISIT_END_DATE IS NULL)'
12785 ||' AND process_flag = '||G_IN_PROCESS
12786 ||' AND batch_id = :lv_batch_id'
12787 ||' AND sr_instance_code = :v_instance_code';
12788
12789 IF V_DEBUG THEN
12790 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
12791 END IF;
12792 EXECUTE IMMEDIATE lv_sql_stmt
12793 USING lv_batch_id,v_instance_code;
12794
12795
12796
12797 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
12798 (p_app_short_name => 'MSC',
12799 p_error_code => 'MSC_PP_END_GT_ST_DATE',
12800 p_message_text => lv_message_text,
12801 p_error_text => lv_error_text );
12802
12803 IF lv_return <> 0 THEN
12804 RAISE ex_logging_err;
12805 END IF;
12806
12807 -- Validate that start_date is greater than end_date
12808
12809 v_sql_stmt := 07;
12810 lv_sql_stmt :=
12811 'UPDATE msc_st_visits'
12812 ||' SET process_flag = '||G_ERROR_FLG||','
12813 ||' error_text = '||''''||lv_message_text||''''
12814 ||' WHERE (VISIT_START_DATE >= VISIT_END_DATE)'
12815 ||' AND process_flag = '||G_IN_PROCESS
12816 ||' AND batch_id = :lv_batch_id'
12817 ||' AND sr_instance_code = :v_instance_code';
12818
12819 IF V_DEBUG THEN
12820 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
12821 END IF;
12822 EXECUTE IMMEDIATE lv_sql_stmt
12823 USING lv_batch_id,v_instance_code;
12824
12825 -- Set the message
12826
12827 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
12828 (p_app_short_name => 'MSC',
12829 p_error_code => 'MSC_PP_INVALID_VALUE',
12830 p_message_text => lv_message_text,
12831 p_error_text => lv_error_text,
12832 p_token1 => 'COLUMN_NAME',
12833 p_token_value1 => 'ORGANIZATION_CODE');
12834
12835 IF lv_return <> 0 THEN
12836 RAISE ex_logging_err;
12837 END IF;
12838
12839 -- Populate organization id
12840
12841 lv_return :=
12842 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name => 'MSC_ST_VISITS',
12843 p_org_partner_name => 'ORGANIZATION_CODE',
12844 p_org_partner_id => 'ORGANIZATION_ID',
12845 p_instance_code => v_instance_code,
12846 p_partner_type => G_ORGANIZATION,
12847 p_severity => G_SEV_ERROR,
12848 p_message_text => lv_message_text,
12849 p_batch_id => lv_batch_id,
12850 p_debug => v_debug,
12851 p_error_text => lv_error_text,
12852 p_company_name_col => FALSE);
12853
12854 if(lv_return <> 0) then
12855 RAISE ex_logging_err;
12856 end if;
12857
12858 --Deriving visit_id
12859 v_sql_stmt := 08;
12860 lv_sql_stmt :=
12861 'UPDATE msc_st_visits msv'
12862 ||' SET visit_id = (SELECT local_id'
12863 ||' FROM msc_local_id_setup mls'
12864 ||' WHERE mls.char1 = msv.sr_instance_code'
12865 ||' AND mls.char4 = msv.visit_name'
12866 ||' AND mls.entity_name = ''VISIT'' )'
12867 ||' WHERE process_flag = '||G_IN_PROCESS
12868 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
12869 ||' AND sr_instance_code = :v_instance_code';
12870
12871
12872 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
12873
12874
12875 EXECUTE IMMEDIATE lv_sql_stmt
12876 USING lv_batch_id,
12877 v_instance_code;
12878
12879
12880 -- Genearte visit_id
12881 v_sql_stmt := 09;
12882
12883 OPEN c2(lv_batch_id);
12884 FETCH c2 BULK COLLECT INTO lb_rowid ;
12885
12886 IF c2%ROWCOUNT > 0 THEN
12887 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
12888
12889 UPDATE msc_st_visits
12890 SET visit_id = msc_st_visit_id_s.NEXTVAL
12891 WHERE rowid = lb_rowid(j);
12892
12893 v_sql_stmt := 10;
12894
12895 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
12896
12897 -- Insert into the LID table
12898
12899 INSERT INTO msc_local_id_setup
12900 (local_id,
12901 st_transaction_id,
12902 instance_id,
12903 entity_name,
12904 data_source_type,
12905 char1,
12906 char4,
12907 last_update_date,
12908 last_updated_by,
12909 creation_date,
12910 created_by )
12911 SELECT
12912 visit_id,
12913 st_transaction_id,
12914 v_instance_id,
12915 'VISIT',
12916 data_source_type,
12917 v_instance_code,
12918 visit_name,
12919 v_current_date,
12920 v_current_user,
12921 v_current_date,
12922 v_current_user
12923 FROM msc_st_visits
12924 WHERE rowid = lb_rowid(j);
12925
12926 END IF;
12927 CLOSE c2;
12928 -- Udpate visit_id
12929 v_sql_stmt := 11;
12930
12931 lv_sql_stmt:=
12932 'UPDATE MSC_ST_VISITS msv'
12933 ||' SET visit_id = (SELECT local_id '
12934 ||' FROM msc_local_id_setup mlis'
12935 ||' WHERE mlis.entity_name= ''VISIT'' '
12936 ||' AND mlis.char1 = msv.sr_instance_code'
12937 ||' AND mlis.char4 = msv.visit_name)'
12938 ||' WHERE sr_instance_code = :v_instance_code'
12939 ||' AND NVL(visit_id,'||NULL_VALUE||') = '||NULL_VALUE
12940 ||' AND process_flag = '||G_IN_PROCESS
12941 ||' AND batch_id = :lv_batch_id';
12942
12943
12944 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
12945
12946 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
12947
12948
12949 --Call to customised validation.
12950 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
12951 (ERRBUF => lv_error_text,
12952 RETCODE => lv_return,
12953 pBatchID => NULL,
12954 pInstanceCode => v_instance_code,
12955 pEntityName => 'MSC_ST_VISITS',
12956 pInstanceID => v_instance_id);
12957
12958 IF NVL(lv_return,0) <> 0 THEN
12959 RAISE ex_logging_err;
12960 END IF;
12961 -- Set the process flag as Valid and populate instance_id
12962 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
12963 (p_table_name => 'MSC_ST_VISITS',
12964 p_instance_id => v_instance_id,
12965 p_instance_code => v_instance_code,
12966 p_process_flag => G_VALID,
12967 p_error_text => lv_error_text,
12968 p_debug => v_debug);
12969
12970 IF lv_return <> 0 THEN
12971 RAISE ex_logging_err;
12972 END IF;
12973
12974 -- At the end calling the LOG_ERROR for logging all
12975 -- errored out records.
12976
12977 lv_return := MSC_ST_UTIL.LOG_ERROR
12978 (p_table_name => 'MSC_ST_VISITS',
12979 p_instance_code => v_instance_code,
12980 p_row => lv_column_names,
12981 p_severity => G_SEV_ERROR,
12982 p_message_text => NULL,
12983 p_error_text => lv_error_text,
12984 p_debug => v_debug );
12985
12986 IF lv_return <> 0 THEN
12987 RAISE ex_logging_err;
12988 END IF;
12989 COMMIT;
12990 END LOOP;
12991
12992 EXCEPTION WHEN ex_logging_err THEN
12993 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_error_text);
12994 -- G_WARNING_FLAG := 1;
12995 ROLLBACK;
12996
12997 WHEN OTHERS THEN
12998 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_VISITS '||'('
12999 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
13000 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_error_text);
13001 -- G_WARNING_FLAG := 1;
13002 ROLLBACK;
13003
13004 END LOAD_VISITS;
13005
13006
13007 PROCEDURE LOAD_MILESTONES IS
13008 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
13009 lb_rowid RowidTab; --bulk collects rowid
13010 lv_return NUMBER;
13011 lv_error_text VARCHAR2(250);
13012 lv_where_str VARCHAR2(5000);
13013 lv_sql_stmt VARCHAR2(5000);
13014 lv_column_names VARCHAR2(5000); --stores concatenated column names
13015 lv_batch_id msc_st_wo_milestones.batch_id%TYPE;
13016 lv_message_text msc_errors.error_text%TYPE;
13017
13018 ex_logging_err EXCEPTION;
13019
13020 CURSOR c1(p_batch_id NUMBER) IS
13021 SELECT rowid
13022 FROM msc_st_wo_milestones
13023 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
13024 AND batch_id = p_batch_id
13025 AND sr_instance_code = v_instance_code;
13026
13027 BEGIN
13028 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'IN LOAD MILESTONES ');
13029
13030 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
13031 (p_app_short_name => 'MSC',
13032 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
13033 p_message_text => lv_message_text,
13034 p_error_text => lv_error_text);
13035
13036 IF lv_return <> 0 THEN
13037 RAISE ex_logging_err;
13038 END IF;
13039
13040 --Validation check for the table msc_st_wo_milestones
13041
13042 --Duplicate records check for the records whose source is other than XML
13043 --Different SQL is used because in XML we can identify the latest records
13044 --whereas in batch load we cannot.
13045
13046 v_sql_stmt := 01;
13047 lv_sql_stmt :=
13048 'UPDATE msc_st_wo_milestones mswm1 '
13049 ||' SET process_flag = '||G_ERROR_FLG||','
13050 ||' error_text = '||''''||lv_message_text||''''
13051 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_wo_milestones mswm2 '
13052 ||' WHERE mswm2.sr_instance_code = mswm1.sr_instance_code'
13053 ||' AND mswm2.visit_name = mswm1.visit_name'
13054 ||' AND mswm2.milestone = mswm1.milestone'
13055 ||' AND mswm2.process_flag = mswm1.process_flag'
13056 ||' AND NVL(mswm2.message_id,NULL) IS NULL'
13057 ||' GROUP BY sr_instance_code,visit_name'
13058 ||' HAVING COUNT(*) >1 )'
13059 ||' AND mswm1.process_flag = '||G_IN_PROCESS
13060 ||' AND mswm1.sr_instance_code = :v_instance_code'
13061 ||' AND NVL(mswm1.message_id,NULL) IS NULL';
13062
13063 IF V_DEBUG THEN
13064 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
13065 END IF;
13066
13067
13068 EXECUTE IMMEDIATE lv_sql_stmt
13069 USING v_instance_code;
13070
13071
13072 --Duplicate records check for the records whose source is XML
13073 v_sql_stmt := 02;
13074 lv_sql_stmt :=
13075 'UPDATE msc_st_wo_milestones mswm1 '
13076 ||' SET process_flag = '||G_ERROR_FLG||','
13077 ||' error_text = '||''''||lv_message_text||''''
13078 ||' WHERE message_id < ( SELECT max(message_id) '
13079 ||' FROM msc_st_wo_milestones mswm2'
13080 ||' WHERE mswm2.sr_instance_code = mswm1.sr_instance_code'
13081 ||' AND mswm2.visit_name = mswm1.visit_name'
13082 ||' AND mswm2.milestone = mswm1.milestone'
13083 ||' AND mswm2.process_flag = mswm1.process_flag'
13084 ||' AND NVL(mswm2.message_id,NULL) IS NOT NULL) '
13085 ||' AND mswm1.process_flag = '||G_IN_PROCESS
13086 ||' AND mswm1.sr_instance_code = :v_instance_code '
13087 ||' AND NVL(mswm1.message_id,NULL) IS NOT NULL';
13088
13089 IF V_DEBUG THEN
13090 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
13091 END IF;
13092
13093 EXECUTE IMMEDIATE lv_sql_stmt
13094 USING v_instance_code;
13095
13096
13097 lv_column_names :=
13098 ' MILESTONE ||''~''||'
13099 ||' MILESTONE_DESC ||''~''||'
13100 ||' VISIT_NAME ||''~''||'
13101 ||' ORGANIZATION_CODE ||''~''||'
13102 ||' SR_INSTANCE_CODE ||''~''||'
13103 ||' DELETED_FLAG ';
13104
13105
13106 LOOP
13107 v_sql_stmt := 03;
13108 SELECT msc_st_batch_id_s.NEXTVAL
13109 INTO lv_batch_id
13110 FROM dual;
13111
13112 v_sql_stmt := 04;
13113 lv_sql_stmt :=
13114 'UPDATE msc_st_wo_milestones '
13115 ||' SET batch_id = :lv_batch_id'
13116 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
13117 ||' AND sr_instance_code = :v_instance_code'
13118 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
13119 ||' AND rownum <= '||v_batch_size;
13120
13121
13122 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
13123
13124 EXECUTE IMMEDIATE lv_sql_stmt
13125 USING lv_batch_id,
13126 v_instance_code;
13127 EXIT WHEN SQL%NOTFOUND;
13128
13129 OPEN c1(lv_batch_id);
13130 FETCH c1 BULK COLLECT INTO lb_rowid;
13131 CLOSE c1;
13132
13133 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
13134 UPDATE msc_st_wo_milestones
13135 SET st_transaction_id = msc_st_wo_milestone_s.nextval,
13136 refresh_id = v_refresh_id,
13137 last_update_date = v_current_date,
13138 last_updated_by = v_current_user,
13139 creation_date = v_current_date,
13140 created_by = v_current_user
13141 WHERE rowid = lb_rowid(j);
13142
13143
13144 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
13145 (p_app_short_name => 'MSC',
13146 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
13147 p_message_text => lv_message_text,
13148 p_error_text => lv_error_text,
13149 p_token1 => 'COLUMN_NAME',
13150 p_token_value1 => 'DELETED_FLAG',
13151 p_token2 => 'DEFAULT_VALUE',
13152 p_token_value2 => SYS_NO);
13153
13154 IF lv_return <> 0 THEN
13155 RAISE ex_logging_err;
13156 END IF;
13157
13158 lv_where_str :=
13159 ' AND NVL(deleted_flag,'||NULL_VALUE||') '
13160 ||' NOT IN(1,2)';
13161 --Log a warning for those records where the deleted_flag has a value other
13162 --than SYS_NO
13163 lv_return := MSC_ST_UTIL.LOG_ERROR
13164 (p_table_name => 'MSC_ST_WO_MILESTONES',
13165 p_instance_code => v_instance_code,
13166 p_row => lv_column_names,
13167 p_severity => G_SEV_WARNING,
13168 p_message_text => lv_message_text,
13169 p_error_text => lv_error_text,
13170 p_batch_id => lv_batch_id,
13171 p_where_str => lv_where_str,
13172 p_col_name => 'DELETED_FLAG',
13173 p_debug => v_debug,
13174 p_default_value => SYS_NO);
13175
13176 IF lv_return <> 0 THEN
13177 RAISE ex_logging_err;
13178 END IF;
13179
13180 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
13181 (p_app_short_name => 'MSC',
13182 p_error_code => 'MSC_PP_COL_VAL_NULL',
13183 p_message_text => lv_message_text,
13184 p_error_text => lv_error_text,
13185 p_token1 => 'COLUMN_NAME',
13186 p_token_value1 => 'MILESTONE OR '
13187 ||'VISIT_NAME ');
13188
13189 IF lv_return <> 0 THEN
13190 RAISE ex_logging_err;
13191 END IF;
13192
13193 -- Error out records where milestone or visit_name is NULL
13194 v_sql_stmt := 06;
13195 lv_sql_stmt :=
13196 'UPDATE msc_st_wo_milestones'
13197 ||' SET process_flag = '||G_ERROR_FLG||','
13198 ||' error_text = '||''''||lv_message_text||''''
13199 ||' WHERE ( VISIT_NAME IS NULL'
13200 ||' OR MILESTONE IS NULL)'
13201 ||' AND process_flag = '||G_IN_PROCESS
13202 ||' AND batch_id = :lv_batch_id'
13203 ||' AND sr_instance_code = :v_instance_code';
13204
13205 IF V_DEBUG THEN
13206 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
13207 END IF;
13208 EXECUTE IMMEDIATE lv_sql_stmt
13209 USING lv_batch_id,v_instance_code;
13210
13211
13212 -- Set the message
13213
13214 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
13215 (p_app_short_name => 'MSC',
13216 p_error_code => 'MSC_PP_INVALID_VALUE',
13217 p_message_text => lv_message_text,
13218 p_error_text => lv_error_text,
13219 p_token1 => 'COLUMN_NAME',
13220 p_token_value1 => 'ORGANIZATION_CODE');
13221
13222 IF lv_return <> 0 THEN
13223 RAISE ex_logging_err;
13224 END IF;
13225
13226 -- Populate organization id
13227
13228 lv_return :=
13229 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name => 'MSC_ST_WO_MILESTONES',
13230 p_org_partner_name => 'ORGANIZATION_CODE',
13231 p_org_partner_id => 'ORGANIZATION_ID',
13232 p_instance_code => v_instance_code,
13233 p_partner_type => G_ORGANIZATION,
13234 p_severity => G_SEV_ERROR,
13235 p_message_text => lv_message_text,
13236 p_batch_id => lv_batch_id,
13237 p_debug => v_debug,
13238 p_error_text => lv_error_text,
13239 p_company_name_col => FALSE);
13240
13241 if(lv_return <> 0) then
13242 RAISE ex_logging_err;
13243 end if;
13244
13245 --Deriving visit_id
13246 v_sql_stmt := 07;
13247 lv_sql_stmt :=
13248 'UPDATE msc_st_wo_milestones msv'
13249 ||' SET visit_id = (SELECT local_id'
13250 ||' FROM msc_local_id_setup mls'
13251 ||' WHERE mls.char1 = msv.sr_instance_code'
13252 ||' AND mls.char4 = msv.visit_name'
13253 ||' AND mls.entity_name = ''VISIT'' )'
13254 ||' WHERE process_flag = '||G_IN_PROCESS
13255 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
13256 ||' AND sr_instance_code = :v_instance_code';
13257
13258
13259 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
13260
13261
13262 EXECUTE IMMEDIATE lv_sql_stmt
13263 USING lv_batch_id,
13264 v_instance_code;
13265
13266 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
13267 (p_app_short_name => 'MSC',
13268 p_error_code => 'MSC_PP_INVALID_VALUE',
13269 p_message_text => lv_message_text,
13270 p_error_text => lv_error_text,
13271 p_token1 => 'COLUMN_NAME',
13272 p_token_value1 => 'VISIT_NAME');
13273
13274 -- Validate the visit name with data in msc_local_id_setup
13275 v_sql_stmt := 08;
13276 lv_sql_stmt :=
13277 'UPDATE msc_st_wo_milestones '
13278 ||' SET process_flag = '||G_ERROR_FLG||','
13279 ||' error_text = '||''''||lv_message_text||''''
13280 ||' WHERE VISIT_ID IS NULL'
13281 ||' AND process_flag = '||G_IN_PROCESS
13282 ||' AND batch_id = :lv_batch_id'
13283 ||' AND sr_instance_code = :v_instance_code';
13284
13285 IF V_DEBUG THEN
13286 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
13287 END IF;
13288
13289 EXECUTE IMMEDIATE lv_sql_stmt
13290 USING lv_batch_id,v_instance_code;
13291
13292
13293 --Call to customised validation.
13294 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
13295 (ERRBUF => lv_error_text,
13296 RETCODE => lv_return,
13297 pBatchID => NULL,
13298 pInstanceCode => v_instance_code,
13299 pEntityName => 'MSC_ST_WO_MILESTONES',
13300 pInstanceID => v_instance_id);
13301
13302 IF NVL(lv_return,0) <> 0 THEN
13303 RAISE ex_logging_err;
13304 END IF;
13305 -- Set the process flag as Valid and populate instance_id
13306 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
13307 (p_table_name => 'MSC_ST_WO_MILESTONES',
13308 p_instance_id => v_instance_id,
13309 p_instance_code => v_instance_code,
13310 p_process_flag => G_VALID,
13311 p_error_text => lv_error_text,
13312 p_debug => v_debug);
13313
13314 IF lv_return <> 0 THEN
13315 RAISE ex_logging_err;
13316 END IF;
13317
13318 -- At the end calling the LOG_ERROR for logging all
13319 -- errored out records.
13320
13321 lv_return := MSC_ST_UTIL.LOG_ERROR
13322 (p_table_name => 'MSC_ST_WO_MILESTONES',
13323 p_instance_code => v_instance_code,
13324 p_row => lv_column_names,
13325 p_severity => G_SEV_ERROR,
13326 p_message_text => NULL,
13327 p_error_text => lv_error_text,
13328 p_debug => v_debug );
13329
13330 IF lv_return <> 0 THEN
13331 RAISE ex_logging_err;
13332 END IF;
13333 COMMIT;
13334 END LOOP;
13335
13336 EXCEPTION WHEN ex_logging_err THEN
13337 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_error_text);
13338 -- G_WARNING_FLAG := 1;
13339 ROLLBACK;
13340
13341 WHEN OTHERS THEN
13342 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_MILESTONES '||'('
13343 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
13344 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_error_text);
13345 -- G_WARNING_FLAG := 1;
13346 ROLLBACK;
13347
13348 END LOAD_MILESTONES;
13349
13350 PROCEDURE LOAD_WBS IS
13351 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
13352 lb_rowid RowidTab; --bulk collects rowid
13353 lv_return NUMBER;
13354 lv_error_text VARCHAR2(250);
13355 lv_where_str VARCHAR2(5000);
13356 lv_sql_stmt VARCHAR2(5000);
13357 lv_column_names VARCHAR2(5000); --stores concatenated column names
13358 lv_message_text msc_errors.error_text%TYPE;
13359
13360 ex_logging_err EXCEPTION;
13361
13362 CURSOR c1 IS
13363 SELECT rowid
13364 FROM msc_st_work_breakdown_struct
13365 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
13366 AND sr_instance_code = v_instance_code;
13367
13368 BEGIN
13369 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'IN LOAD WBS ');
13370
13371 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
13372 (p_app_short_name => 'MSC',
13373 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
13374 p_message_text => lv_message_text,
13375 p_error_text => lv_error_text);
13376
13377 IF lv_return <> 0 THEN
13378 RAISE ex_logging_err;
13379 END IF;
13380
13381 --Validation check for the table msc_st_work_breakdown_struct
13382
13383 --Duplicate records check for the records whose source is other than XML
13384 --Different SQL is used because in XML we can identify the latest records
13385 --whereas in batch load we cannot.
13386
13387 v_sql_stmt := 01;
13388 lv_sql_stmt :=
13389 'UPDATE msc_st_work_breakdown_struct mswbs1 '
13390 ||' SET process_flag = '||G_ERROR_FLG||','
13391 ||' error_text = '||''''||lv_message_text||''''
13392 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_work_breakdown_struct mswbs2 '
13393 ||' WHERE mswbs2.parameter_name = mswbs1.parameter_name'
13394 ||' AND mswbs2.organization_code = mswbs1.organization_code'
13395 ||' AND mswbs2.display_name = mswbs1.display_name'
13396 ||' AND mswbs2.sr_instance_code = mswbs1.sr_instance_code'
13397 ||' AND mswbs2.process_flag = mswbs1.process_flag'
13398 ||' AND NVL(mswbs2.message_id,NULL) IS NULL'
13399 ||' GROUP BY sr_instance_code'
13400 ||' HAVING COUNT(*) >1 )'
13401 ||' AND mswbs1.process_flag = '||G_IN_PROCESS
13402 ||' AND mswbs1.sr_instance_code = :v_instance_code'
13403 ||' AND NVL(mswbs1.message_id,NULL) IS NULL';
13404
13405 IF V_DEBUG THEN
13406 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
13407 END IF;
13408
13409
13410 EXECUTE IMMEDIATE lv_sql_stmt
13411 USING v_instance_code;
13412
13413
13414 --Duplicate records check for the records whose source is XML
13415 v_sql_stmt := 02;
13416 lv_sql_stmt :=
13417 'UPDATE msc_st_work_breakdown_struct mswbs1 '
13418 ||' SET process_flag = '||G_ERROR_FLG||','
13419 ||' error_text = '||''''||lv_message_text||''''
13420 ||' WHERE message_id < ( SELECT max(message_id) '
13421 ||' FROM msc_st_work_breakdown_struct mswbs2'
13422 ||' WHERE mswbs2.parameter_name = mswbs1.parameter_name'
13423 ||' AND mswbs2.display_name = mswbs1.display_name'
13424 ||' AND mswbs2.sr_instance_code = mswbs1.sr_instance_code'
13425 ||' AND mswbs2.process_flag = mswbs1.process_flag'
13426 ||' AND NVL(mswbs2.message_id,NULL) IS NOT NULL) '
13427 ||' AND mswbs1.process_flag = '||G_IN_PROCESS
13428 ||' AND mswbs1.sr_instance_code = :v_instance_code '
13429 ||' AND NVL(mswbs1.message_id,NULL) IS NOT NULL';
13430
13431 IF V_DEBUG THEN
13432 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
13433 END IF;
13434
13435 EXECUTE IMMEDIATE lv_sql_stmt
13436 USING v_instance_code;
13437
13438
13439 lv_column_names :=
13440 ' PARAMETER_NAME ||''~''||'
13441 ||' DISPLAY_NAME ||''~''||'
13442 ||' ORGANIZATION_CODE ||''~''||'
13443 ||' SR_INSTANCE_CODE ||''~''||'
13444 ||' DELETED_FLAG ';
13445
13446
13447 v_sql_stmt := 03;
13448
13449 OPEN c1;
13450 FETCH c1 BULK COLLECT INTO lb_rowid;
13451 CLOSE c1;
13452
13453 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
13454 UPDATE msc_st_work_breakdown_struct
13455 SET st_transaction_id = msc_st_work_breakdown_struct_s.nextval,
13456 refresh_id = v_refresh_id,
13457 last_update_date = v_current_date,
13458 last_updated_by = v_current_user,
13459 creation_date = v_current_date,
13460 created_by = v_current_user
13461 WHERE rowid = lb_rowid(j);
13462
13463
13464 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
13465 (p_app_short_name => 'MSC',
13466 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
13467 p_message_text => lv_message_text,
13468 p_error_text => lv_error_text,
13469 p_token1 => 'COLUMN_NAME',
13470 p_token_value1 => 'DELETED_FLAG',
13471 p_token2 => 'DEFAULT_VALUE',
13472 p_token_value2 => SYS_NO);
13473
13474 IF lv_return <> 0 THEN
13475 RAISE ex_logging_err;
13476 END IF;
13477
13478 lv_where_str :=
13479 ' AND NVL(deleted_flag,'||NULL_VALUE||') '
13480 ||' NOT IN(1,2)';
13481 --Log a warning for those records where the deleted_flag has a value other
13482 --than SYS_NO
13483 lv_return := MSC_ST_UTIL.LOG_ERROR
13484 (p_table_name => 'MSC_ST_WORK_BREAKDOWN_STRUCT',
13485 p_instance_code => v_instance_code,
13486 p_row => lv_column_names,
13487 p_severity => G_SEV_WARNING,
13488 p_message_text => lv_message_text,
13489 p_error_text => lv_error_text,
13490 p_where_str => lv_where_str,
13491 p_col_name => 'DELETED_FLAG',
13492 p_debug => v_debug,
13493 p_default_value => SYS_NO);
13494
13495 IF lv_return <> 0 THEN
13496 RAISE ex_logging_err;
13497 END IF;
13498 -- Set the message
13499
13500 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
13501 (p_app_short_name => 'MSC',
13502 p_error_code => 'MSC_PP_INVALID_VALUE',
13503 p_message_text => lv_message_text,
13504 p_error_text => lv_error_text,
13505 p_token1 => 'COLUMN_NAME',
13506 p_token_value1 => 'ORGANIZATION_CODE');
13507
13508 IF lv_return <> 0 THEN
13509 RAISE ex_logging_err;
13510 END IF;
13511
13512 -- Populate organization id
13513
13514 lv_return :=
13515 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name => 'MSC_ST_WORK_BREAKDOWN_STRUCT',
13516 p_org_partner_name => 'ORGANIZATION_CODE',
13517 p_org_partner_id => 'ORGANIZATION_ID',
13518 p_instance_code => v_instance_code,
13519 p_partner_type => G_ORGANIZATION,
13520 p_severity => G_SEV_ERROR,
13521 p_message_text => lv_message_text,
13522 p_debug => v_debug,
13523 p_error_text => lv_error_text,
13524 p_company_name_col => FALSE);
13525
13526 if(lv_return <> 0) then
13527 RAISE ex_logging_err;
13528 end if;
13529
13530 --Call to customised validation.
13531 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
13532 (ERRBUF => lv_error_text,
13533 RETCODE => lv_return,
13534 pBatchID => NULL,
13535 pInstanceCode => v_instance_code,
13536 pEntityName => 'MSC_ST_WORK_BREAKDOWN_STRUCT',
13537 pInstanceID => v_instance_id);
13538
13539 IF NVL(lv_return,0) <> 0 THEN
13540 RAISE ex_logging_err;
13541 END IF;
13542 -- Set the process flag as Valid and populate instance_id
13543 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
13544 (p_table_name => 'MSC_ST_WORK_BREAKDOWN_STRUCT',
13545 p_instance_id => v_instance_id,
13546 p_instance_code => v_instance_code,
13547 p_process_flag => G_VALID,
13548 p_error_text => lv_error_text,
13549 p_debug => v_debug);
13550
13551 IF lv_return <> 0 THEN
13552 RAISE ex_logging_err;
13553 END IF;
13554
13555 -- At the end calling the LOG_ERROR for logging all
13556 -- errored out records.
13557
13558 lv_return := MSC_ST_UTIL.LOG_ERROR
13559 (p_table_name => 'MSC_ST_WORK_BREAKDOWN_STRUCT',
13560 p_instance_code => v_instance_code,
13561 p_row => lv_column_names,
13562 p_severity => G_SEV_ERROR,
13563 p_message_text => NULL,
13564 p_error_text => lv_error_text,
13565 p_debug => v_debug );
13566
13567 IF lv_return <> 0 THEN
13568 RAISE ex_logging_err;
13569 END IF;
13570 COMMIT;
13571
13572
13573 EXCEPTION WHEN ex_logging_err THEN
13574 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_error_text);
13575 -- G_WARNING_FLAG := 1;
13576 ROLLBACK;
13577
13578 WHEN OTHERS THEN
13579 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_WBS '||'('
13580 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
13581 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_error_text);
13582 -- G_WARNING_FLAG := 1;
13583 ROLLBACK;
13584
13585 END LOAD_WBS;
13586
13587 PROCEDURE LOAD_WOATTRIBUTES IS
13588 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
13589 lb_rowid RowidTab; --bulk collects rowid
13590 lv_return NUMBER;
13591 lv_error_text VARCHAR2(250);
13592 lv_where_str VARCHAR2(5000);
13593 lv_sql_stmt VARCHAR2(5000);
13594 lv_column_names VARCHAR2(5000); --stores concatenated column names
13595 lv_batch_id msc_st_wo_attributes.batch_id%TYPE;
13596 lv_message_text msc_errors.error_text%TYPE;
13597
13598 ex_logging_err EXCEPTION;
13599
13600 CURSOR c1(p_batch_id NUMBER) IS
13601 SELECT rowid
13602 FROM msc_st_wo_attributes
13603 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
13604 AND batch_id = p_batch_id
13605 AND sr_instance_code = v_instance_code;
13606
13607 BEGIN
13608 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'IN LOAD WO Attributes ');
13609
13610 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
13611 (p_app_short_name => 'MSC',
13612 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
13613 p_message_text => lv_message_text,
13614 p_error_text => lv_error_text);
13615
13616 IF lv_return <> 0 THEN
13617 RAISE ex_logging_err;
13618 END IF;
13619
13620 --Validation check for the table msc_st_wo_attributes
13621
13622 --Duplicate records check for the records whose source is other than XML
13623 --Different SQL is used because in XML we can identify the latest records
13624 --whereas in batch load we cannot.
13625
13626 v_sql_stmt := 01;
13627 lv_sql_stmt :=
13628 'UPDATE msc_st_wo_attributes mswoa1 '
13629 ||' SET process_flag = '||G_ERROR_FLG||','
13630 ||' error_text = '||''''||lv_message_text||''''
13631 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_wo_attributes mswoa2 '
13632 ||' WHERE mswoa2.sr_instance_code = mswoa1.sr_instance_code'
13633 ||' AND mswoa2.wip_entity_code = mswoa1.wip_entity_code'
13634 ||' AND mswoa2.organization_code = mswoa1.organization_code'
13635 ||' AND mswoa2.visit_name = mswoa1.visit_name'
13636 ||' AND mswoa2.prev_milestone = mswoa1.prev_milestone'
13637 ||' AND mswoa2.next_milestone = mswoa1.next_milestone'
13638 ||' AND mswoa2.process_flag = mswoa1.process_flag'
13639 ||' AND NVL(mswoa2.message_id,NULL) IS NULL'
13640 ||' GROUP BY sr_instance_code,visit_name'
13641 ||' HAVING COUNT(*) >1 )'
13642 ||' AND mswoa1.process_flag = '||G_IN_PROCESS
13643 ||' AND mswoa1.sr_instance_code = :v_instance_code'
13644 ||' AND NVL(mswoa1.message_id,NULL) IS NULL';
13645
13646 IF V_DEBUG THEN
13647 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
13648 END IF;
13649
13650
13651 EXECUTE IMMEDIATE lv_sql_stmt
13652 USING v_instance_code;
13653
13654
13655 --Duplicate records check for the records whose source is XML
13656 v_sql_stmt := 02;
13657 lv_sql_stmt :=
13658 'UPDATE msc_st_wo_attributes mswoa1 '
13659 ||' SET process_flag = '||G_ERROR_FLG||','
13660 ||' error_text = '||''''||lv_message_text||''''
13661 ||' WHERE message_id < ( SELECT max(message_id) '
13662 ||' FROM msc_st_wo_attributes mswoa2'
13663 ||' WHERE mswoa2.sr_instance_code = mswoa1.sr_instance_code'
13664 ||' AND mswoa2.wip_entity_code = mswoa1.wip_entity_code'
13665 ||' AND mswoa2.organization_code = mswoa1.organization_code'
13666 ||' AND mswoa2.visit_name = mswoa1.visit_name'
13667 ||' AND mswoa2.prev_milestone = mswoa1.prev_milestone'
13668 ||' AND mswoa2.next_milestone = mswoa1.next_milestone'
13669 ||' AND mswoa2.process_flag = mswoa1.process_flag'
13670 ||' AND NVL(mswoa2.message_id,NULL) IS NOT NULL) '
13671 ||' AND mswoa1.process_flag = '||G_IN_PROCESS
13672 ||' AND mswoa1.sr_instance_code = :v_instance_code '
13673 ||' AND NVL(mswoa1.message_id,NULL) IS NOT NULL';
13674
13675 IF V_DEBUG THEN
13676 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
13677 END IF;
13678
13679 EXECUTE IMMEDIATE lv_sql_stmt
13680 USING v_instance_code;
13681
13682
13683 lv_column_names :=
13684 ' WIP_ENTITY_CODE ||''~''||'
13685 ||' PRODUCES_TO_STOCK ||''~''||'
13686 ||' SERIAL_NUM ||''~''||'
13687 ||' VISIT_NAME ||''~''||'
13688 ||' ORGANIZATION_CODE ||''~''||'
13689 ||' PARAMETER1 ||''~''||'
13690 ||' PARAMETER2 ||''~''||'
13691 ||' PARAMETER3 ||''~''||'
13692 ||' PARAMETER4 ||''~''||'
13693 ||' PARAMETER5 ||''~''||'
13694 ||' PARAMETER6 ||''~''||'
13695 ||' PARAMETER7 ||''~''||'
13696 ||' PARAMETER8 ||''~''||'
13697 ||' PARAMETER9 ||''~''||'
13698 ||' MASTER_WO ||''~''||'
13699 ||' PREV_MILESTONE ||''~''||'
13700 ||' NEXT_MILESTONE ||''~''||'
13701 ||' SR_INSTANCE_CODE ||''~''||'
13702 ||' DELETED_FLAG ';
13703
13704
13705 LOOP
13706 v_sql_stmt := 03;
13707 SELECT msc_st_batch_id_s.NEXTVAL
13708 INTO lv_batch_id
13709 FROM dual;
13710
13711 v_sql_stmt := 04;
13712 lv_sql_stmt :=
13713 'UPDATE msc_st_wo_attributes '
13714 ||' SET batch_id = :lv_batch_id'
13715 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
13716 ||' AND sr_instance_code = :v_instance_code'
13717 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
13718 ||' AND rownum <= '||v_batch_size;
13719
13720
13721 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
13722
13723 EXECUTE IMMEDIATE lv_sql_stmt
13724 USING lv_batch_id,
13725 v_instance_code;
13726 EXIT WHEN SQL%NOTFOUND;
13727
13728 OPEN c1(lv_batch_id);
13729 FETCH c1 BULK COLLECT INTO lb_rowid;
13730 CLOSE c1;
13731
13732 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
13733 UPDATE msc_st_wo_attributes
13734 SET st_transaction_id = msc_st_wo_attributes_s.nextval,
13735 refresh_id = v_refresh_id,
13736 last_update_date = v_current_date,
13737 last_updated_by = v_current_user,
13738 creation_date = v_current_date,
13739 created_by = v_current_user
13740 WHERE rowid = lb_rowid(j);
13741
13742
13743 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
13744 (p_app_short_name => 'MSC',
13745 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
13746 p_message_text => lv_message_text,
13747 p_error_text => lv_error_text,
13748 p_token1 => 'COLUMN_NAME',
13749 p_token_value1 => 'DELETED_FLAG',
13750 p_token2 => 'DEFAULT_VALUE',
13751 p_token_value2 => SYS_NO);
13752
13753 IF lv_return <> 0 THEN
13754 RAISE ex_logging_err;
13755 END IF;
13756
13757 lv_where_str :=
13758 ' AND NVL(deleted_flag,'||NULL_VALUE||') '
13759 ||' NOT IN(1,2)';
13760 --Log a warning for those records where the deleted_flag has a value other
13761 --than SYS_NO
13762 lv_return := MSC_ST_UTIL.LOG_ERROR
13763 (p_table_name => 'MSC_ST_WO_ATTRIBUTES',
13764 p_instance_code => v_instance_code,
13765 p_row => lv_column_names,
13766 p_severity => G_SEV_WARNING,
13767 p_message_text => lv_message_text,
13768 p_error_text => lv_error_text,
13769 p_batch_id => lv_batch_id,
13770 p_where_str => lv_where_str,
13771 p_col_name => 'DELETED_FLAG',
13772 p_debug => v_debug,
13773 p_default_value => SYS_NO);
13774
13775 IF lv_return <> 0 THEN
13776 RAISE ex_logging_err;
13777 END IF;
13778
13779 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
13780 (p_app_short_name => 'MSC',
13781 p_error_code => 'MSC_PP_COL_VAL_NULL',
13782 p_message_text => lv_message_text,
13783 p_error_text => lv_error_text,
13784 p_token1 => 'COLUMN_NAME',
13785 p_token_value1 => 'WIP_ENTITY_CODE OR '
13786 ||'VISIT_NAME');
13787
13788 IF lv_return <> 0 THEN
13789 RAISE ex_logging_err;
13790 END IF;
13791
13792 -- Error out records where milestone or visit_name is NULL
13793 v_sql_stmt := 06;
13794 lv_sql_stmt :=
13795 'UPDATE msc_st_wo_attributes'
13796 ||' SET process_flag = '||G_ERROR_FLG||','
13797 ||' error_text = '||''''||lv_message_text||''''
13798 ||' WHERE ( VISIT_NAME IS NULL'
13799 ||' OR WIP_ENTITY_CODE IS NULL )'
13800 ||' AND process_flag = '||G_IN_PROCESS
13801 ||' AND batch_id = :lv_batch_id'
13802 ||' AND sr_instance_code = :v_instance_code';
13803
13804 IF V_DEBUG THEN
13805 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
13806 END IF;
13807 EXECUTE IMMEDIATE lv_sql_stmt
13808 USING lv_batch_id,v_instance_code;
13809
13810
13811 -- Set the message
13812
13813 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
13814 (p_app_short_name => 'MSC',
13815 p_error_code => 'MSC_PP_INVALID_VALUE',
13816 p_message_text => lv_message_text,
13817 p_error_text => lv_error_text,
13818 p_token1 => 'COLUMN_NAME',
13819 p_token_value1 => 'ORGANIZATION_CODE');
13820
13821 IF lv_return <> 0 THEN
13822 RAISE ex_logging_err;
13823 END IF;
13824
13825 -- Populate organization id
13826
13827 lv_return :=
13828 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name => 'MSC_ST_WO_ATTRIBUTES',
13829 p_org_partner_name => 'ORGANIZATION_CODE',
13830 p_org_partner_id => 'ORGANIZATION_ID',
13831 p_instance_code => v_instance_code,
13832 p_partner_type => G_ORGANIZATION,
13833 p_severity => G_SEV_ERROR,
13834 p_message_text => lv_message_text,
13835 p_batch_id => lv_batch_id,
13836 p_debug => v_debug,
13837 p_error_text => lv_error_text,
13838 p_company_name_col => FALSE);
13839
13840 if(lv_return <> 0) then
13841 RAISE ex_logging_err;
13842 end if;
13843
13844 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
13845 (p_app_short_name => 'MSC',
13846 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
13847 p_message_text => lv_message_text,
13848 p_error_text => lv_error_text,
13849 p_token1 => 'COLUMN_NAME',
13850 p_token_value1 => 'PRODUCES_TO_STOCK',
13851 p_token2 => 'DEFAULT_VALUE',
13852 p_token_value2 => SYS_NO);
13853
13854 IF lv_return <> 0 THEN
13855 RAISE ex_logging_err;
13856 END IF;
13857
13858 -- Check PRODUCES_TO_STOCK column has valid value or not and if not set it to SYS_NO
13859 -- Log error procedure inserts warning and also defaults the value
13860
13861 lv_where_str := ' AND NVL(PRODUCES_TO_STOCK,'||NULL_VALUE||') '
13862 ||' NOT IN(1,2)';
13863
13864 lv_return := MSC_ST_UTIL.LOG_ERROR
13865 (p_table_name => 'MSC_ST_WO_ATTRIBUTES',
13866 p_instance_code => v_instance_code,
13867 p_row => lv_column_names,
13868 p_severity => G_SEV_WARNING,
13869 p_message_text => lv_message_text,
13870 p_error_text => lv_error_text,
13871 p_batch_id => lv_batch_id,
13872 p_where_str => lv_where_str,
13873 p_col_name => 'PRODUCES_TO_STOCK',
13874 p_debug => v_debug,
13875 p_default_value => SYS_NO);
13876
13877 IF lv_return <> 0 THEN
13878 RAISE ex_logging_err;
13879 END IF;
13880
13881 -- Set the error message
13882 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
13883 (p_app_short_name => 'MSC',
13884 p_error_code => 'MSC_PP_INVALID_VALUE',
13885 p_message_text => lv_message_text,
13886 p_error_text => lv_error_text,
13887 p_token1 => 'COLUMN_NAME',
13888 p_token_value1 => 'MASTER_WO');
13889
13890 IF lv_return <> 0 THEN
13891 RAISE ex_logging_err;
13892 END IF;
13893
13894
13895 -- Valid value for MASTER_WO is 1,2
13896
13897 v_sql_stmt := 07;
13898 lv_sql_stmt :=
13899
13900 ' UPDATE msc_st_wo_attributes '
13901 ||' SET process_flag = '||G_ERROR_FLG||','
13902 ||' error_text = '||''''||lv_message_text||''''
13903 ||' WHERE nvl(MASTER_WO,'||NULL_VALUE||') not in(1,2)'
13904 ||' AND process_flag = '||G_IN_PROCESS
13905 ||' AND batch_id = :lv_batch_id'
13906 ||' AND sr_instance_code = :v_instance_code';
13907
13908
13909 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
13910
13911 EXECUTE IMMEDIATE lv_sql_stmt
13912 USING lv_batch_id,
13913 v_instance_code;
13914
13915 --Deriving visit_id
13916 v_sql_stmt := 08;
13917 lv_sql_stmt :=
13918 'UPDATE msc_st_wo_attributes mswa'
13919 ||' SET visit_id = (SELECT local_id'
13920 ||' FROM msc_local_id_setup mls'
13921 ||' WHERE mls.char1 = mswa.sr_instance_code'
13922 ||' AND mls.char4 = mswa.visit_name'
13923 ||' AND mls.entity_name = ''VISIT'' )'
13924 ||' WHERE process_flag = '||G_IN_PROCESS
13925 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
13926 ||' AND sr_instance_code = :v_instance_code';
13927
13928
13929 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
13930
13931
13932 EXECUTE IMMEDIATE lv_sql_stmt
13933 USING lv_batch_id,
13934 v_instance_code;
13935
13936 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
13937 (p_app_short_name => 'MSC',
13938 p_error_code => 'MSC_PP_INVALID_VALUE',
13939 p_message_text => lv_message_text,
13940 p_error_text => lv_error_text,
13941 p_token1 => 'COLUMN_NAME',
13942 p_token_value1 => 'VISIT_NAME');
13943
13944 -- Validate the visit name with data in msc_local_id_setup
13945 v_sql_stmt := 09;
13946 lv_sql_stmt :=
13947 'UPDATE msc_st_wo_attributes '
13948 ||' SET process_flag = '||G_ERROR_FLG||','
13949 ||' error_text = '||''''||lv_message_text||''''
13950 ||' WHERE VISIT_ID IS NULL'
13951 ||' AND process_flag = '||G_IN_PROCESS
13952 ||' AND batch_id = :lv_batch_id'
13953 ||' AND sr_instance_code = :v_instance_code';
13954
13955 IF V_DEBUG THEN
13956 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
13957 END IF;
13958
13959 EXECUTE IMMEDIATE lv_sql_stmt
13960 USING lv_batch_id,v_instance_code;
13961
13962 -- Set the error message
13963 -- Value for PREVIOUS_MILESTONE is validated from msc_wo_milestones table.
13964
13965 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
13966 (p_app_short_name => 'MSC',
13967 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
13968 p_message_text => lv_message_text,
13969 p_error_text => lv_error_text,
13970 p_token1 => 'COLUMN_NAME',
13971 p_token_value1 => 'PREV_MILESTONE');
13972
13973 IF lv_return <> 0 THEN
13974 RAISE ex_logging_err;
13975 END IF;
13976
13977 -- Validate
13978 v_sql_stmt := 10;
13979 lv_sql_stmt :=
13980 'UPDATE msc_st_wo_attributes mswa'
13981 ||' SET process_flag = '||G_ERROR_FLG||','
13982 ||' error_text = '||''''||lv_message_text||''''
13983 ||' WHERE NOT EXISTS(SELECT 1 '
13984 ||' FROM msc_wo_milestones mwm '
13985 ||' WHERE NVL(mwm.milestone, '||''''||NULL_CHAR||''''||') = '
13986 ||' NVL(mswa.prev_milestone,'||''''||NULL_CHAR||''''||')'
13987 ||' AND mwm.organization_id = mswa.organization_id'
13988 ||' AND mwm.visit_id = mswa.visit_id'
13989 ||' UNION '
13990 ||' SELECT 1 FROM msc_st_wo_milestones mswm'
13991 ||' WHERE NVL(mswm.milestone, '||''''||NULL_CHAR||''''||') = '
13992 ||' NVL(mswa.prev_milestone,'||''''||NULL_CHAR||''''||')'
13993 ||' AND mswm.organization_id = mswa.organization_id'
13994 ||' AND mswm.visit_id = mswa.visit_id'
13995 ||' AND mswm.sr_instance_id = :v_instance_id'
13996 ||' AND mswm.process_flag = '||G_VALID||' ) '
13997 ||' AND NVL(mswa.prev_milestone,'||''''||NULL_CHAR||''''||') '
13998 ||' <> '||''''||NULL_CHAR||''''
13999 ||' AND mswa.sr_instance_code = :v_instance_code'
14000 ||' AND mswa.batch_id = :lv_batch_id'
14001 ||' AND mswa.process_flag = '||G_IN_PROCESS ;
14002
14003
14004
14005 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14006
14007
14008 EXECUTE IMMEDIATE lv_sql_stmt
14009 USING v_instance_id,
14010 v_instance_code,
14011 lv_batch_id;
14012 -- next milestone
14013
14014 -- Set the error message
14015 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
14016 (p_app_short_name => 'MSC',
14017 p_error_code => 'MSC_PP_INVALID_VALUE',
14018 p_message_text => lv_message_text,
14019 p_error_text => lv_error_text,
14020 p_token1 => 'COLUMN_NAME',
14021 p_token_value1 => 'NEXT_MILESTONE');
14022
14023 IF lv_return <> 0 THEN
14024 RAISE ex_logging_err;
14025 END IF;
14026
14027
14028 -- Value for NEXT_MILESTONE is validated from msc_wo_milestones table.
14029
14030 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
14031 (p_app_short_name => 'MSC',
14032 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
14033 p_message_text => lv_message_text,
14034 p_error_text => lv_error_text,
14035 p_token1 => 'COLUMN_NAMES',
14036 p_token_value1 => 'NEXT_MILESTONE');
14037
14038 IF lv_return <> 0 THEN
14039 RAISE ex_logging_err;
14040 END IF;
14041
14042 -- Validate
14043 v_sql_stmt := 11;
14044 lv_sql_stmt :=
14045 'UPDATE msc_st_wo_attributes mswa'
14046 ||' SET process_flag = '||G_ERROR_FLG||','
14047 ||' error_text = '||''''||lv_message_text||''''
14048 ||' WHERE NOT EXISTS(SELECT 1 '
14049 ||' FROM msc_wo_milestones mwm '
14050 ||' WHERE NVL(mwm.milestone, '||''''||NULL_CHAR||''''||') = '
14051 ||' NVL(mswa.next_milestone,'||''''||NULL_CHAR||''''||')'
14052 ||' AND mwm.organization_id = mswa.organization_id'
14053 ||' AND mwm.visit_id = mswa.visit_id'
14054 ||' UNION '
14055 ||' SELECT 1 FROM msc_st_wo_milestones mswm'
14056 ||' WHERE NVL(mswm.milestone, '||''''||NULL_CHAR||''''||') = '
14057 ||' NVL(mswa.next_milestone,'||''''||NULL_CHAR||''''||')'
14058 ||' AND mswm.organization_id = mswa.organization_id'
14059 ||' AND mswm.visit_id = mswa.visit_id'
14060 ||' AND mswm.sr_instance_id = :v_instance_id'
14061 ||' AND mswm.process_flag = '||G_VALID||' ) '
14062 ||' AND NVL(mswa.next_milestone,'||''''||NULL_CHAR||''''||') '
14063 ||' <> '||''''||NULL_CHAR||''''
14064 ||' AND mswa.sr_instance_code = :v_instance_code'
14065 ||' AND mswa.batch_id = :lv_batch_id'
14066 ||' AND mswa.process_flag = '||G_IN_PROCESS ;
14067
14068
14069
14070 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14071
14072
14073 EXECUTE IMMEDIATE lv_sql_stmt
14074 USING v_instance_id,
14075 v_instance_code,
14076 lv_batch_id;
14077 v_sql_stmt := 12;
14078 lv_sql_stmt :=
14079
14080 ' UPDATE msc_st_wo_attributes '
14081 ||' SET process_flag = '||G_ERROR_FLG||','
14082 ||' error_text = '||''''||lv_message_text||''''
14083 ||' WHERE nvl(MASTER_WO,'||NULL_VALUE||') not in(1,2)'
14084 ||' AND process_flag = '||G_IN_PROCESS
14085 ||' AND batch_id = :lv_batch_id'
14086 ||' AND sr_instance_code = :v_instance_code';
14087
14088
14089 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14090
14091 EXECUTE IMMEDIATE lv_sql_stmt
14092 USING lv_batch_id,
14093 v_instance_code;
14094
14095 --Deriving supply_id
14096 v_sql_stmt := 13;
14097 lv_sql_stmt :=
14098 'UPDATE msc_st_wo_attributes mswa'
14099 ||' SET supply_id = (SELECT transaction_id'
14100 ||' FROM msc_supplies ms'
14101 ||' WHERE ms.sr_instance_id = :v_instance_id'
14102 ||' AND ms.order_number = mswa.wip_entity_code'
14103 ||' AND ms.organization_id = mswa.organization_id '
14104 ||' AND ms.order_type = 70 )'
14105 ||' WHERE process_flag = '||G_IN_PROCESS
14106 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
14107 ||' AND sr_instance_code = :v_instance_code';
14108
14109
14110 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14111
14112
14113 EXECUTE IMMEDIATE lv_sql_stmt
14114 USING v_instance_id,lv_batch_id,
14115 v_instance_code;
14116
14117 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
14118 (p_app_short_name => 'MSC',
14119 p_error_code => 'MSC_PP_INVALID_VALUE',
14120 p_message_text => lv_message_text,
14121 p_error_text => lv_error_text,
14122 p_token1 => 'COLUMN_NAME',
14123 p_token_value1 => 'WIP_ENTITY_CODE');
14124
14125 v_sql_stmt := 14;
14126 lv_sql_stmt :=
14127 'UPDATE msc_st_wo_attributes '
14128 ||' SET process_flag = '||G_ERROR_FLG||','
14129 ||' error_text = '||''''||lv_message_text||''''
14130 ||' WHERE SUPPLY_ID IS NULL'
14131 ||' AND process_flag = '||G_IN_PROCESS
14132 ||' AND batch_id = :lv_batch_id'
14133 ||' AND sr_instance_code = :v_instance_code';
14134
14135 IF V_DEBUG THEN
14136 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14137 END IF;
14138
14139 EXECUTE IMMEDIATE lv_sql_stmt
14140 USING lv_batch_id,v_instance_code;
14141
14142
14143
14144 --Call to customised validation.
14145 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
14146 (ERRBUF => lv_error_text,
14147 RETCODE => lv_return,
14148 pBatchID => NULL,
14149 pInstanceCode => v_instance_code,
14150 pEntityName => 'MSC_ST_WO_ATTRIBUTES',
14151 pInstanceID => v_instance_id);
14152
14153 IF NVL(lv_return,0) <> 0 THEN
14154 RAISE ex_logging_err;
14155 END IF;
14156 -- Set the process flag as Valid and populate instance_id
14157 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
14158 (p_table_name => 'MSC_ST_WO_ATTRIBUTES',
14159 p_instance_id => v_instance_id,
14160 p_instance_code => v_instance_code,
14161 p_process_flag => G_VALID,
14162 p_error_text => lv_error_text,
14163 p_debug => v_debug);
14164
14165 IF lv_return <> 0 THEN
14166 RAISE ex_logging_err;
14167 END IF;
14168
14169 -- At the end calling the LOG_ERROR for logging all
14170 -- errored out records.
14171
14172 lv_return := MSC_ST_UTIL.LOG_ERROR
14173 (p_table_name => 'MSC_ST_WO_ATTRIBUTES',
14174 p_instance_code => v_instance_code,
14175 p_row => lv_column_names,
14176 p_severity => G_SEV_ERROR,
14177 p_message_text => NULL,
14178 p_error_text => lv_error_text,
14179 p_debug => v_debug );
14180
14181 IF lv_return <> 0 THEN
14182 RAISE ex_logging_err;
14183 END IF;
14184 COMMIT;
14185 END LOOP;
14186
14187 EXCEPTION WHEN ex_logging_err THEN
14188 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_error_text);
14189 -- G_WARNING_FLAG := 1;
14190 ROLLBACK;
14191
14192 WHEN OTHERS THEN
14193 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_WOATTRIBUTES '||'('
14194 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
14195 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_error_text);
14196 -- G_WARNING_FLAG := 1;
14197 ROLLBACK;
14198
14199 END LOAD_WOATTRIBUTES;
14200
14201 PROCEDURE LOAD_WO_TASK_HIERARCHY IS
14202 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
14203 lb_rowid RowidTab; --bulk collects rowid
14204 lv_return NUMBER;
14205 lv_error_text VARCHAR2(250);
14206 lv_where_str VARCHAR2(5000);
14207 lv_sql_stmt VARCHAR2(5000);
14208 lv_column_names VARCHAR2(5000); --stores concatenated column names
14209 lv_batch_id msc_st_wo_task_hierarchy.batch_id%TYPE;
14210 lv_message_text msc_errors.error_text%TYPE;
14211
14212 ex_logging_err EXCEPTION;
14213
14214 CURSOR c1(p_batch_id NUMBER) IS
14215 SELECT rowid
14216 FROM msc_st_wo_task_hierarchy
14217 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
14218 AND batch_id = p_batch_id
14219 AND sr_instance_code = v_instance_code;
14220
14221 BEGIN
14222 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'IN LOAD WO TASK hierarchy ');
14223
14224 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
14225 (p_app_short_name => 'MSC',
14226 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
14227 p_message_text => lv_message_text,
14228 p_error_text => lv_error_text);
14229
14230 IF lv_return <> 0 THEN
14231 RAISE ex_logging_err;
14232 END IF;
14233
14234 --Validation check for the table msc_st_wo_task_hierarchy
14235
14236 --Duplicate records check for the records whose source is other than XML
14237 --Different SQL is used because in XML we can identify the latest records
14238 --whereas in batch load we cannot.
14239
14240 v_sql_stmt := 01;
14241 lv_sql_stmt :=
14242 'UPDATE msc_st_wo_task_hierarchy mswth1 '
14243 ||' SET process_flag = '||G_ERROR_FLG||','
14244 ||' error_text = '||''''||lv_message_text||''''
14245 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_wo_task_hierarchy mswth2 '
14246 ||' WHERE mswth2.sr_instance_code = mswth1.sr_instance_code'
14247 ||' AND mswth2.organization_code = mswth1.organization_code'
14248 ||' AND mswth2.curr_wip_entity_code = mswth1.curr_wip_entity_code'
14249 ||' AND mswth2.next_wip_entity_code = mswth1.next_wip_entity_code'
14250 ||' AND mswth2.process_flag = mswth1.process_flag'
14251 ||' AND NVL(mswth2.message_id,NULL) IS NULL'
14252 ||' GROUP BY sr_instance_code'
14253 ||' HAVING COUNT(*) >1 )'
14254 ||' AND mswth1.process_flag = '||G_IN_PROCESS
14255 ||' AND mswth1.sr_instance_code = :v_instance_code'
14256 ||' AND NVL(mswth1.message_id,NULL) IS NULL';
14257
14258 IF V_DEBUG THEN
14259 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14260 END IF;
14261
14262
14263 EXECUTE IMMEDIATE lv_sql_stmt
14264 USING v_instance_code;
14265
14266
14267 --Duplicate records check for the records whose source is XML
14268 v_sql_stmt := 02;
14269 lv_sql_stmt :=
14270 'UPDATE msc_st_wo_task_hierarchy mswth1 '
14271 ||' SET process_flag = '||G_ERROR_FLG||','
14272 ||' error_text = '||''''||lv_message_text||''''
14273 ||' WHERE message_id < ( SELECT max(message_id) '
14274 ||' FROM msc_st_wo_task_hierarchy mswth2'
14275 ||' WHERE mswth2.sr_instance_code = mswth1.sr_instance_code'
14276 ||' AND mswth2.curr_wip_entity_code = mswth1.curr_wip_entity_code'
14277 ||' AND mswth2.next_wip_entity_code = mswth1.next_wip_entity_code'
14278 ||' AND mswth2.process_flag = mswth1.process_flag'
14279 ||' AND NVL(mswth2.message_id,NULL) IS NOT NULL) '
14280 ||' AND mswth1.process_flag = '||G_IN_PROCESS
14281 ||' AND mswth1.sr_instance_code = :v_instance_code '
14282 ||' AND NVL(mswth1.message_id,NULL) IS NOT NULL';
14283
14284 IF V_DEBUG THEN
14285 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14286 END IF;
14287
14288 EXECUTE IMMEDIATE lv_sql_stmt
14289 USING v_instance_code;
14290
14291
14292 lv_column_names :=
14293 ' CURR_WIP_ENTITY_CODE ||''~''||'
14294 ||' NEXT_WIP_ENTITY_CODE ||''~''||'
14295 ||' PRECEDENCE_CONSTRAINT ||''~''||'
14296 ||' MIN_SEPARATION ||''~''||'
14297 ||' MIN_SEP_TIME_UNIT ||''~''||'
14298 ||' MAX_SEPARATION ||''~''||'
14299 ||' MAX_SEP_TIME_UNIT ||''~''||'
14300 ||' ORGANIZATION_CODE ||''~''||'
14301 ||' SR_INSTANCE_CODE ||''~''||'
14302 ||' DELETED_FLAG ';
14303
14304
14305 LOOP
14306 v_sql_stmt := 03;
14307 SELECT msc_st_batch_id_s.NEXTVAL
14308 INTO lv_batch_id
14309 FROM dual;
14310
14311 v_sql_stmt := 04;
14312 lv_sql_stmt :=
14313 'UPDATE msc_st_wo_task_hierarchy '
14314 ||' SET batch_id = :lv_batch_id'
14315 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
14316 ||' AND sr_instance_code = :v_instance_code'
14317 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
14318 ||' AND rownum <= '||v_batch_size;
14319
14320
14321 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14322
14323 EXECUTE IMMEDIATE lv_sql_stmt
14324 USING lv_batch_id,
14325 v_instance_code;
14326 EXIT WHEN SQL%NOTFOUND;
14327
14328 OPEN c1(lv_batch_id);
14329 FETCH c1 BULK COLLECT INTO lb_rowid;
14330 CLOSE c1;
14331
14332 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
14333 UPDATE msc_st_wo_task_hierarchy
14334 SET st_transaction_id = msc_st_wo_task_hierarchy_s.nextval,
14335 refresh_id = v_refresh_id,
14336 last_update_date = v_current_date,
14337 last_updated_by = v_current_user,
14338 creation_date = v_current_date,
14339 created_by = v_current_user
14340 WHERE rowid = lb_rowid(j);
14341
14342
14343 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
14344 (p_app_short_name => 'MSC',
14345 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
14346 p_message_text => lv_message_text,
14347 p_error_text => lv_error_text,
14348 p_token1 => 'COLUMN_NAME',
14349 p_token_value1 => 'DELETED_FLAG',
14350 p_token2 => 'DEFAULT_VALUE',
14351 p_token_value2 => SYS_NO);
14352
14353 IF lv_return <> 0 THEN
14354 RAISE ex_logging_err;
14355 END IF;
14356
14357 lv_where_str :=
14358 ' AND NVL(deleted_flag,'||NULL_VALUE||') '
14359 ||' NOT IN(1,2)';
14360 --Log a warning for those records where the deleted_flag has a value other
14361 --than SYS_NO
14362 lv_return := MSC_ST_UTIL.LOG_ERROR
14363 (p_table_name => 'MSC_ST_WO_TASK_HIERARCHY',
14364 p_instance_code => v_instance_code,
14365 p_row => lv_column_names,
14366 p_severity => G_SEV_WARNING,
14367 p_message_text => lv_message_text,
14368 p_error_text => lv_error_text,
14369 p_batch_id => lv_batch_id,
14370 p_where_str => lv_where_str,
14371 p_col_name => 'DELETED_FLAG',
14372 p_debug => v_debug,
14373 p_default_value => SYS_NO);
14374
14375 IF lv_return <> 0 THEN
14376 RAISE ex_logging_err;
14377 END IF;
14378
14379 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
14380 (p_app_short_name => 'MSC',
14381 p_error_code => 'MSC_PP_COL_VAL_NULL',
14382 p_message_text => lv_message_text,
14383 p_error_text => lv_error_text,
14384 p_token1 => 'COLUMN_NAME',
14385 p_token_value1 => 'CURR_WIP_ENTITY_CODE OR '
14386 ||'NEXT_WIP_ENTITY_CODE');
14387
14388 IF lv_return <> 0 THEN
14389 RAISE ex_logging_err;
14390 END IF;
14391
14392 -- Error out records where NEXT_WIP_ENTITY_CODE or CURR_WIP_ENTITY_CODE is NULL
14393 v_sql_stmt := 06;
14394 lv_sql_stmt :=
14395 'UPDATE msc_st_wo_task_hierarchy'
14396 ||' SET process_flag = '||G_ERROR_FLG||','
14397 ||' error_text = '||''''||lv_message_text||''''
14398 ||' WHERE ( CURR_WIP_ENTITY_CODE IS NULL'
14399 ||' OR NEXT_WIP_ENTITY_CODE IS NULL )'
14400 ||' AND process_flag = '||G_IN_PROCESS
14401 ||' AND batch_id = :lv_batch_id'
14402 ||' AND sr_instance_code = :v_instance_code';
14403
14404 IF V_DEBUG THEN
14405 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14406 END IF;
14407
14408
14409 EXECUTE IMMEDIATE lv_sql_stmt
14410 USING lv_batch_id,v_instance_code;
14411
14412
14413 -- Set the message
14414
14415 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
14416 (p_app_short_name => 'MSC',
14417 p_error_code => 'MSC_PP_INVALID_VALUE',
14418 p_message_text => lv_message_text,
14419 p_error_text => lv_error_text,
14420 p_token1 => 'COLUMN_NAME',
14421 p_token_value1 => 'MIN_SEP_TIME_UNIT');
14422
14423 IF lv_return <> 0 THEN
14424 RAISE ex_logging_err;
14425 END IF;
14426
14427 -- validate time unit
14428
14429 v_sql_stmt := 07;
14430 lv_sql_stmt :=
14431 'UPDATE msc_st_wo_task_hierarchy'
14432 ||' SET process_flag = '||G_ERROR_FLG||','
14433 ||' error_text = '||''''||lv_message_text||''''
14434 ||' WHERE upper(MIN_SEP_TIME_UNIT) NOT IN (''S'',''M'',''H'',''D'',''W'') '
14435 ||' AND process_flag = '||G_IN_PROCESS
14436 ||' AND batch_id = :lv_batch_id'
14437 ||' AND sr_instance_code = :v_instance_code';
14438
14439 IF V_DEBUG THEN
14440 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14441 END IF;
14442
14443 EXECUTE IMMEDIATE lv_sql_stmt
14444 USING lv_batch_id,v_instance_code;
14445
14446 v_sql_stmt := 8;
14447 lv_sql_stmt :=
14448 'UPDATE msc_st_wo_task_hierarchy'
14449 ||' SET MIN_SEP_TIME_UNIT = (select meaning from fnd_lookup_values lv'
14450 ||' WHERE LV.LANGUAGE = userenv(''lang'') '
14451 ||' AND LV.ENABLED_FLAG = ''Y'''
14452 ||' and lookup_type = ''MSC_TIME_UNIT'''
14453 ||' and lookup_code = upper(min_sep_time_unit))'
14454 ||' WHERE NVL(upper(MIN_SEP_TIME_UNIT),-1) IN (''S'',''M'',''H'',''D'',''W'')'
14455 ||' AND process_flag = '||G_IN_PROCESS
14456 ||' AND batch_id = :lv_batch_id'
14457 ||' AND sr_instance_code = :v_instance_code';
14458
14459 IF V_DEBUG THEN
14460 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14461 END IF;
14462
14463 EXECUTE IMMEDIATE lv_sql_stmt
14464 USING lv_batch_id,v_instance_code;
14465
14466 -- Set the message
14467
14468 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
14469 (p_app_short_name => 'MSC',
14470 p_error_code => 'MSC_PP_INVALID_VALUE',
14471 p_message_text => lv_message_text,
14472 p_error_text => lv_error_text,
14473 p_token1 => 'COLUMN_NAME',
14474 p_token_value1 => 'MAX_SEP_TIME_UNIT');
14475
14476 IF lv_return <> 0 THEN
14477 RAISE ex_logging_err;
14478 END IF;
14479
14480
14481 v_sql_stmt := 09;
14482 lv_sql_stmt :=
14483 'UPDATE msc_st_wo_task_hierarchy'
14484 ||' SET process_flag = '||G_ERROR_FLG||','
14485 ||' error_text = '||''''||lv_message_text||''''
14486 ||' WHERE upper(MAX_SEP_TIME_UNIT) NOT IN (''S'',''M'',''H'',''D'',''W'') '
14487 ||' AND process_flag = '||G_IN_PROCESS
14488 ||' AND batch_id = :lv_batch_id'
14489 ||' AND sr_instance_code = :v_instance_code';
14490
14491 IF V_DEBUG THEN
14492 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14493 END IF;
14494
14495
14496 EXECUTE IMMEDIATE lv_sql_stmt
14497 USING lv_batch_id,v_instance_code;
14498
14499 v_sql_stmt := 10;
14500 lv_sql_stmt :=
14501 'UPDATE msc_st_wo_task_hierarchy'
14502 ||' SET MAX_SEP_TIME_UNIT = (select meaning from fnd_lookup_values lv'
14503 ||' WHERE LV.LANGUAGE = userenv(''lang'') '
14504 ||' AND LV.ENABLED_FLAG = ''Y'''
14505 ||' and lookup_type = ''MSC_TIME_UNIT'''
14506 ||' and lookup_code = upper(max_sep_time_unit))'
14507 ||' WHERE NVL(upper(MAX_SEP_TIME_UNIT),-1) IN (''S'',''M'',''H'',''D'',''W'')'
14508 ||' AND process_flag = '||G_IN_PROCESS
14509 ||' AND batch_id = :lv_batch_id'
14510 ||' AND sr_instance_code = :v_instance_code';
14511
14512 IF V_DEBUG THEN
14513 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14514 END IF;
14515
14516 EXECUTE IMMEDIATE lv_sql_stmt
14517 USING lv_batch_id,v_instance_code;
14518
14519 -- Set the message
14520
14521 /* lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
14522 (p_app_short_name => 'MSC',
14523 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
14524 p_message_text => lv_message_text,
14525 p_error_text => lv_error_text,
14526 p_token1 => 'COLUMN_NAME',
14527 p_token_value1 => 'PRECEDENCE_CONSTRAINT',
14528 p_token2 => 'DEFAULT_VALUE',
14529 p_token_value2 => SYS_NO);
14530
14531 IF lv_return <> 0 THEN
14532 RAISE ex_logging_err;
14533 END IF; */
14534
14535 -- Check PRECEDENCE_CONSTRAINT column has valid value or not and if not set it to 1- Starts after end
14536 -- Log error procedure inserts warning and also defaults the value
14537
14538 lv_where_str := ' AND NVL(PRECEDENCE_CONSTRAINT,'||NULL_VALUE||') '
14539 ||' NOT IN(1,2,3)';
14540
14541 lv_return := MSC_ST_UTIL.LOG_ERROR
14542 (p_table_name => 'MSC_ST_WO_TASK_HIERARCHY',
14543 p_instance_code => v_instance_code,
14544 p_row => lv_column_names,
14545 p_severity => G_SEV_WARNING,
14546 p_message_text => lv_message_text,
14547 p_error_text => lv_error_text,
14548 p_batch_id => lv_batch_id,
14549 p_where_str => lv_where_str,
14550 p_col_name => 'PRECEDENCE_CONSTRAINT',
14551 p_debug => v_debug,
14552 p_default_value => 1);
14553
14554 IF lv_return <> 0 THEN
14555 RAISE ex_logging_err;
14556 END IF;
14557
14558 v_sql_stmt := 11;
14559 lv_sql_stmt :=
14560 'UPDATE msc_st_wo_task_hierarchy'
14561 ||' SET PRECEDENCE_CONSTRAINT = (select meaning from fnd_lookup_values lv'
14562 ||' WHERE LV.LANGUAGE = userenv(''lang'') '
14563 ||' AND LV.ENABLED_FLAG = ''Y'''
14564 ||' and lookup_type = ''MSC_PRECEDENCE_CONSTRAINT'''
14565 ||' and lookup_code = precedence_constraint)'
14566 ||' WHERE NVL(PRECEDENCE_CONSTRAINT,-1) IN (1,2,3)'
14567 ||' AND process_flag = '||G_IN_PROCESS
14568 ||' AND batch_id = :lv_batch_id'
14569 ||' AND sr_instance_code = :v_instance_code';
14570
14571 IF V_DEBUG THEN
14572 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14573 END IF;
14574 EXECUTE IMMEDIATE lv_sql_stmt
14575 USING lv_batch_id,v_instance_code;
14576
14577
14578 --Deriving supply_id
14579 v_sql_stmt := 12;
14580 lv_sql_stmt :=
14581 'UPDATE msc_st_wo_task_hierarchy mswth'
14582 ||' SET curr_supply_id = (SELECT transaction_id'
14583 ||' FROM msc_supplies ms'
14584 ||' WHERE ms.sr_instance_id = :v_instance_id'
14585 ||' AND ms.order_number = mswth.curr_wip_entity_code'
14586 ||' AND ms.order_type = 70 )'
14587 ||' WHERE process_flag = '||G_IN_PROCESS
14588 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
14589 ||' AND sr_instance_code = :v_instance_code';
14590
14591
14592 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14593
14594
14595 EXECUTE IMMEDIATE lv_sql_stmt
14596 USING v_instance_id,lv_batch_id,
14597 v_instance_code;
14598
14599 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
14600 (p_app_short_name => 'MSC',
14601 p_error_code => 'MSC_PP_INVALID_VALUE',
14602 p_message_text => lv_message_text,
14603 p_error_text => lv_error_text,
14604 p_token1 => 'COLUMN_NAME',
14605 p_token_value1 => 'CURR_WIP_ENTITY_CODE');
14606
14607 v_sql_stmt := 13;
14608 lv_sql_stmt :=
14609 'UPDATE msc_st_wo_task_hierarchy '
14610 ||' SET process_flag = '||G_ERROR_FLG||','
14611 ||' error_text = '||''''||lv_message_text||''''
14612 ||' WHERE CURR_SUPPLY_ID IS NULL'
14613 ||' AND process_flag = '||G_IN_PROCESS
14614 ||' AND batch_id = :lv_batch_id'
14615 ||' AND sr_instance_code = :v_instance_code';
14616
14617 IF V_DEBUG THEN
14618 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14619 END IF;
14620
14621 EXECUTE IMMEDIATE lv_sql_stmt
14622 USING lv_batch_id,v_instance_code;
14623
14624 -- next_supply_id
14625
14626 --Deriving supply_id
14627 v_sql_stmt := 14;
14628 lv_sql_stmt :=
14629 'UPDATE msc_st_wo_task_hierarchy mswth'
14630 ||' SET next_supply_id = (SELECT transaction_id'
14631 ||' FROM msc_supplies ms'
14632 ||' WHERE ms.sr_instance_id = :v_instance_id'
14633 ||' AND ms.order_number = mswth.next_wip_entity_code'
14634 ||' AND ms.order_type = 70 )'
14635 ||' WHERE process_flag = '||G_IN_PROCESS
14636 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
14637 ||' AND sr_instance_code = :v_instance_code';
14638
14639
14640 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14641
14642
14643 EXECUTE IMMEDIATE lv_sql_stmt
14644 USING v_instance_id,lv_batch_id,
14645 v_instance_code;
14646
14647 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
14648 (p_app_short_name => 'MSC',
14649 p_error_code => 'MSC_PP_INVALID_VALUE',
14650 p_message_text => lv_message_text,
14651 p_error_text => lv_error_text,
14652 p_token1 => 'COLUMN_NAME',
14653 p_token_value1 => 'NEXT_WIP_ENTITY_CODE');
14654
14655 v_sql_stmt := 15;
14656 lv_sql_stmt :=
14657 'UPDATE msc_st_wo_task_hierarchy '
14658 ||' SET process_flag = '||G_ERROR_FLG||','
14659 ||' error_text = '||''''||lv_message_text||''''
14660 ||' WHERE NEXT_SUPPLY_ID IS NULL'
14661 ||' AND process_flag = '||G_IN_PROCESS
14662 ||' AND batch_id = :lv_batch_id'
14663 ||' AND sr_instance_code = :v_instance_code';
14664
14665 IF V_DEBUG THEN
14666 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14667 END IF;
14668
14669 EXECUTE IMMEDIATE lv_sql_stmt
14670 USING lv_batch_id,v_instance_code;
14671
14672 -- Set the message
14673
14674 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
14675 (p_app_short_name => 'MSC',
14676 p_error_code => 'MSC_PP_INVALID_VALUE',
14677 p_message_text => lv_message_text,
14678 p_error_text => lv_error_text,
14679 p_token1 => 'COLUMN_NAME',
14680 p_token_value1 => 'ORGANIZATION_CODE');
14681
14682 IF lv_return <> 0 THEN
14683 RAISE ex_logging_err;
14684 END IF;
14685
14686 -- Populate organization id
14687
14688 lv_return :=
14689 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name => 'MSC_ST_WO_TASK_HIERARCHY',
14690 p_org_partner_name => 'ORGANIZATION_CODE',
14691 p_org_partner_id => 'ORGANIZATION_ID',
14692 p_instance_code => v_instance_code,
14693 p_partner_type => G_ORGANIZATION,
14694 p_severity => G_SEV_ERROR,
14695 p_message_text => lv_message_text,
14696 p_batch_id => lv_batch_id,
14697 p_debug => v_debug,
14698 p_error_text => lv_error_text,
14699 p_company_name_col => FALSE);
14700
14701 if(lv_return <> 0) then
14702 RAISE ex_logging_err;
14703 end if;
14704
14705 --Call to customised validation.
14706 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
14707 (ERRBUF => lv_error_text,
14708 RETCODE => lv_return,
14709 pBatchID => NULL,
14710 pInstanceCode => v_instance_code,
14711 pEntityName => 'MSC_ST_WO_TASK_HIERARCHY',
14712 pInstanceID => v_instance_id);
14713
14714 IF NVL(lv_return,0) <> 0 THEN
14715 RAISE ex_logging_err;
14716 END IF;
14717 -- Set the process flag as Valid and populate instance_id
14718 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
14719 (p_table_name => 'MSC_ST_WO_TASK_HIERARCHY',
14720 p_instance_id => v_instance_id,
14721 p_instance_code => v_instance_code,
14722 p_process_flag => G_VALID,
14723 p_error_text => lv_error_text,
14724 p_debug => v_debug);
14725
14726 IF lv_return <> 0 THEN
14727 RAISE ex_logging_err;
14728 END IF;
14729
14730 -- At the end calling the LOG_ERROR for logging all
14731 -- errored out records.
14732
14733 lv_return := MSC_ST_UTIL.LOG_ERROR
14734 (p_table_name => 'MSC_ST_WO_TASK_HIERARCHY',
14735 p_instance_code => v_instance_code,
14736 p_row => lv_column_names,
14737 p_severity => G_SEV_ERROR,
14738 p_message_text => NULL,
14739 p_error_text => lv_error_text,
14740 p_debug => v_debug );
14741
14742 IF lv_return <> 0 THEN
14743 RAISE ex_logging_err;
14744 END IF;
14745 COMMIT;
14746 END LOOP;
14747
14748 EXCEPTION WHEN ex_logging_err THEN
14749 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_error_text);
14750 -- G_WARNING_FLAG := 1;
14751 ROLLBACK;
14752
14753 WHEN OTHERS THEN
14754 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_WO_TASK_HIERARCHY '||'('
14755 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
14756 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_error_text);
14757 -- G_WARNING_FLAG := 1;
14758 ROLLBACK;
14759
14760 END LOAD_WO_TASK_HIERARCHY;
14761
14762 PROCEDURE LOAD_WO_OPERATION_REL IS
14763 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
14764 lb_rowid RowidTab; --bulk collects rowid
14765 lv_return NUMBER;
14766 lv_error_text VARCHAR2(250);
14767 lv_where_str VARCHAR2(5000);
14768 lv_sql_stmt VARCHAR2(5000);
14769 lv_column_names VARCHAR2(5000); --stores concatenated column names
14770 lv_batch_id msc_st_wo_operation_rel.batch_id%TYPE;
14771 lv_message_text msc_errors.error_text%TYPE;
14772
14773 ex_logging_err EXCEPTION;
14774
14775 CURSOR c1(p_batch_id NUMBER) IS
14776 SELECT rowid
14777 FROM msc_st_wo_operation_rel
14778 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
14779 AND batch_id = p_batch_id
14780 AND sr_instance_code = v_instance_code;
14781
14782 BEGIN
14783 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'IN LOAD WO OPERATION REL -');
14784
14785 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
14786 (p_app_short_name => 'MSC',
14787 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
14788 p_message_text => lv_message_text,
14789 p_error_text => lv_error_text);
14790
14791 IF lv_return <> 0 THEN
14792 RAISE ex_logging_err;
14793 END IF;
14794
14795 --Validation check for the table msc_st_wo_operation_rel
14796
14797 --Duplicate records check for the records whose source is other than XML
14798 --Different SQL is used because in XML we can identify the latest records
14799 --whereas in batch load we cannot.
14800
14801 v_sql_stmt := 01;
14802 lv_sql_stmt :=
14803 'UPDATE msc_st_wo_operation_rel mswor1 '
14804 ||' SET process_flag = '||G_ERROR_FLG||','
14805 ||' error_text = '||''''||lv_message_text||''''
14806 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_wo_operation_rel mswor2 '
14807 ||' WHERE mswor2.sr_instance_code = mswor1.sr_instance_code'
14808 ||' AND mswor2.organization_code = mswor1.organization_code'
14809 ||' AND mswor2.wip_entity_code = mswor1.wip_entity_code'
14810 ||' AND mswor2.from_op_seq_num = mswor1.from_op_seq_num'
14811 ||' AND mswor2.from_op_res_seq_num = mswor1.from_op_res_seq_num'
14812 ||' AND mswor2.to_op_seq_num = mswor1.to_op_seq_num'
14813 ||' AND mswor2.to_op_res_seq_num = mswor1.to_op_res_seq_num'
14814 ||' AND mswor2.process_flag = mswor1.process_flag'
14815 ||' AND NVL(mswor2.message_id,NULL) IS NULL'
14816 ||' GROUP BY sr_instance_code'
14817 ||' HAVING COUNT(*) >1 )'
14818 ||' AND mswor1.process_flag = '||G_IN_PROCESS
14819 ||' AND mswor1.sr_instance_code = :v_instance_code'
14820 ||' AND NVL(mswor1.message_id,NULL) IS NULL';
14821
14822 IF V_DEBUG THEN
14823 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14824 END IF;
14825
14826
14827 EXECUTE IMMEDIATE lv_sql_stmt
14828 USING v_instance_code;
14829
14830
14831 --Duplicate records check for the records whose source is XML
14832 v_sql_stmt := 02;
14833 lv_sql_stmt :=
14834 'UPDATE msc_st_wo_operation_rel mswor1 '
14835 ||' SET process_flag = '||G_ERROR_FLG||','
14836 ||' error_text = '||''''||lv_message_text||''''
14837 ||' WHERE message_id < ( SELECT max(message_id) '
14838 ||' FROM msc_st_wo_operation_rel mswor2'
14839 ||' WHERE mswor2.sr_instance_code = mswor1.sr_instance_code'
14840 ||' AND mswor2.wip_entity_code = mswor1.wip_entity_code'
14841 ||' AND mswor2.from_op_seq_num = mswor1.from_op_seq_num'
14842 ||' AND mswor2.from_op_res_seq_num = mswor1.from_op_res_seq_num'
14843 ||' AND mswor2.to_op_seq_num = mswor1.to_op_seq_num'
14844 ||' AND mswor2.to_op_res_seq_num = mswor1.to_op_res_seq_num'
14845 ||' AND mswor2.process_flag = mswor1.process_flag'
14846 ||' AND NVL(mswor2.message_id,NULL) IS NOT NULL) '
14847 ||' AND mswor1.process_flag = '||G_IN_PROCESS
14848 ||' AND mswor1.sr_instance_code = :v_instance_code '
14849 ||' AND NVL(mswor1.message_id,NULL) IS NOT NULL';
14850
14851 IF V_DEBUG THEN
14852 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14853 END IF;
14854
14855 EXECUTE IMMEDIATE lv_sql_stmt
14856 USING v_instance_code;
14857
14858
14859 lv_column_names :=
14860 ' WIP_ENTITY_CODE ||''~''||'
14861 ||' FROM_OP_SEQ_NUM ||''~''||'
14862 ||' FROM_OP_RES_SEQ_NUM ||''~''||'
14863 ||' FROM_OP_DESC ||''~''||'
14864 ||' TO_OP_SEQ_NUM ||''~''||'
14865 ||' TO_OP_RES_SEQ_NUM ||''~''||'
14866 ||' TO_OP_DESC ||''~''||'
14867 ||' PRECEDENCE_CONSTRAINT ||''~''||'
14868 ||' MIN_SEPARATION ||''~''||'
14869 ||' MIN_SEP_TIME_UNIT ||''~''||'
14870 ||' MAX_SEPARATION ||''~''||'
14871 ||' MAX_SEP_TIME_UNIT ||''~''||'
14872 ||' ORGANIZATION_CODE ||''~''||'
14873 ||' SR_INSTANCE_CODE ||''~''||'
14874 ||' DELETED_FLAG ';
14875
14876
14877 LOOP
14878 v_sql_stmt := 03;
14879 SELECT msc_st_batch_id_s.NEXTVAL
14880 INTO lv_batch_id
14881 FROM dual;
14882
14883 v_sql_stmt := 04;
14884 lv_sql_stmt :=
14885 'UPDATE msc_st_wo_operation_rel '
14886 ||' SET batch_id = :lv_batch_id'
14887 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
14888 ||' AND sr_instance_code = :v_instance_code'
14889 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
14890 ||' AND rownum <= '||v_batch_size;
14891
14892
14893 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14894
14895 EXECUTE IMMEDIATE lv_sql_stmt
14896 USING lv_batch_id,
14897 v_instance_code;
14898 EXIT WHEN SQL%NOTFOUND;
14899
14900 OPEN c1(lv_batch_id);
14901 FETCH c1 BULK COLLECT INTO lb_rowid;
14902 CLOSE c1;
14903
14904 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
14905 UPDATE msc_st_wo_operation_rel
14906 SET st_transaction_id = msc_st_wo_operation_rel_s.nextval,
14907 refresh_id = v_refresh_id,
14908 last_update_date = v_current_date,
14909 last_updated_by = v_current_user,
14910 creation_date = v_current_date,
14911 created_by = v_current_user
14912 WHERE rowid = lb_rowid(j);
14913
14914
14915 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
14916 (p_app_short_name => 'MSC',
14917 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
14918 p_message_text => lv_message_text,
14919 p_error_text => lv_error_text,
14920 p_token1 => 'COLUMN_NAME',
14921 p_token_value1 => 'DELETED_FLAG',
14922 p_token2 => 'DEFAULT_VALUE',
14923 p_token_value2 => SYS_NO);
14924
14925 IF lv_return <> 0 THEN
14926 RAISE ex_logging_err;
14927 END IF;
14928
14929 lv_where_str :=
14930 ' AND NVL(deleted_flag,'||NULL_VALUE||') '
14931 ||' NOT IN(1,2)';
14932 --Log a warning for those records where the deleted_flag has a value other
14933 --than SYS_NO
14934 lv_return := MSC_ST_UTIL.LOG_ERROR
14935 (p_table_name => 'MSC_ST_WO_OPERATION_REL',
14936 p_instance_code => v_instance_code,
14937 p_row => lv_column_names,
14938 p_severity => G_SEV_WARNING,
14939 p_message_text => lv_message_text,
14940 p_error_text => lv_error_text,
14941 p_batch_id => lv_batch_id,
14942 p_where_str => lv_where_str,
14943 p_col_name => 'DELETED_FLAG',
14944 p_debug => v_debug,
14945 p_default_value => SYS_NO);
14946
14947 IF lv_return <> 0 THEN
14948 RAISE ex_logging_err;
14949 END IF;
14950
14951 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
14952 (p_app_short_name => 'MSC',
14953 p_error_code => 'MSC_PP_COL_VAL_NULL',
14954 p_message_text => lv_message_text,
14955 p_error_text => lv_error_text,
14956 p_token1 => 'COLUMN_NAME',
14957 p_token_value1 => 'WIP_ENTITY_CODE');
14958
14959 IF lv_return <> 0 THEN
14960 RAISE ex_logging_err;
14961 END IF;
14962
14963 -- Error out records where wip_entity_code is NULL
14964 v_sql_stmt := 06;
14965 lv_sql_stmt :=
14966 'UPDATE msc_st_wo_operation_rel'
14967 ||' SET process_flag = '||G_ERROR_FLG||','
14968 ||' error_text = '||''''||lv_message_text||''''
14969 ||' WHERE ( WIP_ENTITY_CODE IS NULL )'
14970 ||' AND process_flag = '||G_IN_PROCESS
14971 ||' AND batch_id = :lv_batch_id'
14972 ||' AND sr_instance_code = :v_instance_code';
14973
14974 IF V_DEBUG THEN
14975 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
14976 END IF;
14977 EXECUTE IMMEDIATE lv_sql_stmt
14978 USING lv_batch_id,v_instance_code;
14979
14980
14981 -- Set the message
14982
14983 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
14984 (p_app_short_name => 'MSC',
14985 p_error_code => 'MSC_PP_INVALID_VALUE',
14986 p_message_text => lv_message_text,
14987 p_error_text => lv_error_text,
14988 p_token1 => 'COLUMN_NAME',
14989 p_token_value1 => 'MIN_SEP_TIME_UNIT');
14990
14991 IF lv_return <> 0 THEN
14992 RAISE ex_logging_err;
14993 END IF;
14994
14995 -- validate time unit
14996
14997 v_sql_stmt := 07;
14998 lv_sql_stmt :=
14999 'UPDATE msc_st_wo_operation_rel'
15000 ||' SET process_flag = '||G_ERROR_FLG||','
15001 ||' error_text = '||''''||lv_message_text||''''
15002 ||' WHERE upper(MIN_SEP_TIME_UNIT) NOT IN (''S'',''M'',''H'',''D'',''W'') '
15003 ||' AND process_flag = '||G_IN_PROCESS
15004 ||' AND batch_id = :lv_batch_id'
15005 ||' AND sr_instance_code = :v_instance_code';
15006
15007 IF V_DEBUG THEN
15008 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
15009 END IF;
15010 EXECUTE IMMEDIATE lv_sql_stmt
15011 USING lv_batch_id,v_instance_code;
15012
15013 v_sql_stmt := 08;
15014 lv_sql_stmt :=
15015 'UPDATE msc_st_wo_operation_rel'
15016 ||' SET MIN_SEP_TIME_UNIT = (select meaning from fnd_lookup_values lv'
15017 ||' WHERE LV.LANGUAGE = userenv(''lang'') '
15018 ||' AND LV.ENABLED_FLAG = ''Y'''
15019 ||' and lookup_type = ''MSC_TIME_UNIT'''
15020 ||' and lookup_code = upper(min_sep_time_unit))'
15021 ||' WHERE NVL(upper(MIN_SEP_TIME_UNIT),-1) IN (''S'',''M'',''H'',''D'',''W'')'
15022 ||' AND process_flag = '||G_IN_PROCESS
15023 ||' AND batch_id = :lv_batch_id'
15024 ||' AND sr_instance_code = :v_instance_code';
15025
15026 IF V_DEBUG THEN
15027 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
15028 END IF;
15029 EXECUTE IMMEDIATE lv_sql_stmt
15030 USING lv_batch_id,v_instance_code;
15031
15032 -- Set the message
15033
15034 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
15035 (p_app_short_name => 'MSC',
15036 p_error_code => 'MSC_PP_INVALID_VALUE',
15037 p_message_text => lv_message_text,
15038 p_error_text => lv_error_text,
15039 p_token1 => 'COLUMN_NAME',
15040 p_token_value1 => 'MAX_SEP_TIME_UNIT');
15041
15042 IF lv_return <> 0 THEN
15043 RAISE ex_logging_err;
15044 END IF;
15045
15046
15047 v_sql_stmt := 09;
15048 lv_sql_stmt :=
15049 'UPDATE msc_st_wo_operation_rel'
15050 ||' SET process_flag = '||G_ERROR_FLG||','
15051 ||' error_text = '||''''||lv_message_text||''''
15052 ||' WHERE upper(MAX_SEP_TIME_UNIT) NOT IN (''S'',''M'',''H'',''D'',''W'') '
15053 ||' AND process_flag = '||G_IN_PROCESS
15054 ||' AND batch_id = :lv_batch_id'
15055 ||' AND sr_instance_code = :v_instance_code';
15056
15057 IF V_DEBUG THEN
15058 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
15059 END IF;
15060 EXECUTE IMMEDIATE lv_sql_stmt
15061 USING lv_batch_id,v_instance_code;
15062 v_sql_stmt := 10;
15063 lv_sql_stmt :=
15064 'UPDATE msc_st_wo_operation_rel'
15065 ||' SET MAX_SEP_TIME_UNIT = (select meaning from fnd_lookup_values lv'
15066 ||' WHERE LV.LANGUAGE = userenv(''lang'') '
15067 ||' AND LV.ENABLED_FLAG = ''Y'''
15068 ||' and lookup_type = ''MSC_TIME_UNIT'''
15069 ||' and lookup_code = upper(max_sep_time_unit))'
15070 ||' WHERE NVL(upper(MAX_SEP_TIME_UNIT),-1) IN (''S'',''M'',''H'',''D'',''W'')'
15071 ||' AND process_flag = '||G_IN_PROCESS
15072 ||' AND batch_id = :lv_batch_id'
15073 ||' AND sr_instance_code = :v_instance_code';
15074
15075 IF V_DEBUG THEN
15076 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
15077 END IF;
15078 EXECUTE IMMEDIATE lv_sql_stmt
15079 USING lv_batch_id,v_instance_code;
15080
15081 /* -- Set the message
15082 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
15083 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
15084 (p_app_short_name => 'MSC',
15085 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
15086 p_message_text => lv_message_text,
15087 p_error_text => lv_error_text,
15088 p_token1 => 'COLUMN_NAME',
15089 p_token_value1 => 'PRECEDENCE_CONSTRAINT',
15090 p_token2 => 'DEFAULT_VALUE',
15091 p_token_value2 => SYS_NO);
15092
15093 IF lv_return <> 0 THEN
15094 RAISE ex_logging_err;
15095 END IF; */
15096
15097 -- Check PRECEDENCE_CONSTRAINT column has valid value or not and if not set it to 1- Starts after end
15098 -- Log error procedure inserts warning and also defaults the value
15099
15100 lv_where_str := ' AND NVL(PRECEDENCE_CONSTRAINT,'||NULL_VALUE||') '
15101 ||' NOT IN(1,2,3)';
15102
15103 lv_return := MSC_ST_UTIL.LOG_ERROR
15104 (p_table_name => 'MSC_ST_WO_OPERATION_REL',
15105 p_instance_code => v_instance_code,
15106 p_row => lv_column_names,
15107 p_severity => G_SEV_WARNING,
15108 p_message_text => lv_message_text,
15109 p_error_text => lv_error_text,
15110 p_batch_id => lv_batch_id,
15111 p_where_str => lv_where_str,
15112 p_col_name => 'PRECEDENCE_CONSTRAINT',
15113 p_debug => v_debug,
15114 p_default_value => 1);
15115
15116 IF lv_return <> 0 THEN
15117 RAISE ex_logging_err;
15118 END IF;
15119
15120 v_sql_stmt := 11;
15121 lv_sql_stmt :=
15122 'UPDATE msc_st_wo_operation_rel'
15123 ||' SET PRECEDENCE_CONSTRAINT = (select meaning from fnd_lookup_values lv'
15124 ||' WHERE LV.LANGUAGE = userenv(''lang'') '
15125 ||' AND LV.ENABLED_FLAG = ''Y'''
15126 ||' and lookup_type = ''MSC_PRECEDENCE_CONSTRAINT'''
15127 ||' and lookup_code = precedence_constraint)'
15128 ||' WHERE NVL(PRECEDENCE_CONSTRAINT,-1) IN (1,2,3)'
15129 ||' AND process_flag = '||G_IN_PROCESS
15130 ||' AND batch_id = :lv_batch_id'
15131 ||' AND sr_instance_code = :v_instance_code';
15132
15133 IF V_DEBUG THEN
15134 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
15135 END IF;
15136 EXECUTE IMMEDIATE lv_sql_stmt
15137 USING lv_batch_id,v_instance_code;
15138 -- Set the message
15139
15140 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
15141 (p_app_short_name => 'MSC',
15142 p_error_code => 'MSC_PP_INVALID_VALUE',
15143 p_message_text => lv_message_text,
15144 p_error_text => lv_error_text,
15145 p_token1 => 'COLUMN_NAME',
15146 p_token_value1 => 'ORGANIZATION_CODE');
15147
15148 IF lv_return <> 0 THEN
15149 RAISE ex_logging_err;
15150 END IF;
15151
15152 -- Populate organization id
15153
15154 lv_return :=
15155 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name => 'MSC_ST_WO_OPERATION_REL',
15156 p_org_partner_name => 'ORGANIZATION_CODE',
15157 p_org_partner_id => 'ORGANIZATION_ID',
15158 p_instance_code => v_instance_code,
15159 p_partner_type => G_ORGANIZATION,
15160 p_severity => G_SEV_ERROR,
15161 p_message_text => lv_message_text,
15162 p_batch_id => lv_batch_id,
15163 p_debug => v_debug,
15164 p_error_text => lv_error_text,
15165 p_company_name_col => FALSE);
15166
15167 if(lv_return <> 0) then
15168 RAISE ex_logging_err;
15169 end if;
15170
15171 --Deriving supply_id
15172 v_sql_stmt := 12;
15173 lv_sql_stmt :=
15174 'UPDATE msc_st_wo_operation_rel mswth'
15175 ||' SET supply_id = (SELECT transaction_id'
15176 ||' FROM msc_supplies ms'
15177 ||' WHERE ms.sr_instance_id = :v_instance_id'
15178 ||' AND ms.organization_id = mswth.organization_id'
15179 ||' AND ms.order_number = mswth.wip_entity_code'
15180 ||' AND ms.order_type = 70 )'
15181 ||' WHERE process_flag = '||G_IN_PROCESS
15182 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
15183 ||' AND sr_instance_code = :v_instance_code';
15184
15185
15186 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
15187
15188
15189 EXECUTE IMMEDIATE lv_sql_stmt
15190 USING v_instance_id,lv_batch_id,
15191 v_instance_code;
15192
15193 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
15194 (p_app_short_name => 'MSC',
15195 p_error_code => 'MSC_PP_INVALID_VALUE',
15196 p_message_text => lv_message_text,
15197 p_error_text => lv_error_text,
15198 p_token1 => 'COLUMN_NAME',
15199 p_token_value1 => 'WIP_ENTITY_CODE');
15200
15201 v_sql_stmt := 13;
15202 lv_sql_stmt :=
15203 'UPDATE msc_st_wo_operation_rel '
15204 ||' SET process_flag = '||G_ERROR_FLG||','
15205 ||' error_text = '||''''||lv_message_text||''''
15206 ||' WHERE SUPPLY_ID IS NULL'
15207 ||' AND process_flag = '||G_IN_PROCESS
15208 ||' AND batch_id = :lv_batch_id'
15209 ||' AND sr_instance_code = :v_instance_code';
15210
15211 IF V_DEBUG THEN
15212 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
15213 END IF;
15214
15215 EXECUTE IMMEDIATE lv_sql_stmt
15216 USING lv_batch_id,v_instance_code;
15217
15218 --OP code validations
15219
15220 -- Set the message
15221
15222 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
15223 (p_app_short_name => 'MSC',
15224 p_error_code => 'MSC_PP_INVALID_VALUE',
15225 p_message_text => lv_message_text,
15226 p_error_text => lv_error_text,
15227 p_token1 => 'COLUMN_NAME',
15228 p_token_value1 => 'FROM_OP_SEQ_NUM');
15229
15230 IF lv_return <> 0 THEN
15231 RAISE ex_logging_err;
15232 END IF;
15233
15234 -- validate from_op_seq_num
15235
15236 v_sql_stmt := 14;
15237 lv_sql_stmt :=
15238 'UPDATE msc_st_wo_operation_rel mswth'
15239 ||' SET process_flag = '||G_ERROR_FLG||','
15240 ||' error_text = '||''''||lv_message_text||''''
15241 ||' WHERE NOT EXISTS ( SELECT 1 '
15242 ||' FROM msc_resource_requirements mrr'
15243 ||' WHERE mrr.sr_instance_id = :v_instance_id'
15244 ||' AND mrr.organization_id = mswth.organization_id'
15245 ||' AND mrr.supply_id = mswth.supply_id'
15246 ||' AND mrr.operation_seq_num = mswth.from_op_seq_num ) '
15247 ||' AND process_flag = '||G_IN_PROCESS
15248 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
15249 ||' AND sr_instance_code = :v_instance_code';
15250
15251 IF V_DEBUG THEN
15252 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
15253 END IF;
15254 EXECUTE IMMEDIATE lv_sql_stmt
15255 USING v_instance_id,lv_batch_id,v_instance_code;
15256
15257 -- Set the message
15258
15259 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
15260 (p_app_short_name => 'MSC',
15261 p_error_code => 'MSC_PP_INVALID_VALUE',
15262 p_message_text => lv_message_text,
15263 p_error_text => lv_error_text,
15264 p_token1 => 'COLUMN_NAME',
15265 p_token_value1 => 'FROM_OP_RES_SEQ_NUM');
15266
15267 IF lv_return <> 0 THEN
15268 RAISE ex_logging_err;
15269 END IF;
15270
15271 -- validate from_op_res_seq_num
15272
15273 v_sql_stmt := 15;
15274 lv_sql_stmt :=
15275 'UPDATE msc_st_wo_operation_rel mswth'
15276 ||' SET process_flag = '||G_ERROR_FLG||','
15277 ||' error_text = '||''''||lv_message_text||''''
15278 ||' WHERE NOT EXISTS ( SELECT 1 '
15279 ||' FROM msc_resource_requirements mrr'
15280 ||' WHERE mrr.sr_instance_id = :v_instance_id'
15281 ||' AND mrr.organization_id = mswth.organization_id'
15282 ||' AND mrr.supply_id = mswth.supply_id'
15283 ||' AND mrr.resource_seq_num = mswth.from_op_res_seq_num ) '
15284 ||' AND process_flag = '||G_IN_PROCESS
15285 ||' AND NVL(from_op_res_seq_num,'||NULL_VALUE||') <> '||NULL_VALUE
15286 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
15287 ||' AND sr_instance_code = :v_instance_code';
15288
15289 IF V_DEBUG THEN
15290 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
15291 END IF;
15292 EXECUTE IMMEDIATE lv_sql_stmt
15293 USING v_instance_id,lv_batch_id,v_instance_code;
15294
15295 -- Set the message
15296
15297 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
15298 (p_app_short_name => 'MSC',
15299 p_error_code => 'MSC_PP_INVALID_VALUE',
15300 p_message_text => lv_message_text,
15301 p_error_text => lv_error_text,
15302 p_token1 => 'COLUMN_NAME',
15303 p_token_value1 => 'TO_OP_SEQ_NUM');
15304
15305 IF lv_return <> 0 THEN
15306 RAISE ex_logging_err;
15307 END IF;
15308
15309 -- validate to_op_seq_num
15310
15311 v_sql_stmt := 16;
15312 lv_sql_stmt :=
15313 'UPDATE msc_st_wo_operation_rel mswth'
15314 ||' SET process_flag = '||G_ERROR_FLG||','
15315 ||' error_text = '||''''||lv_message_text||''''
15316 ||' WHERE NOT EXISTS ( SELECT 1 '
15317 ||' FROM msc_resource_requirements mrr'
15318 ||' WHERE mrr.sr_instance_id = :v_instance_id'
15319 ||' AND mrr.organization_id = mswth.organization_id'
15320 ||' AND mrr.supply_id = mswth.supply_id'
15321 ||' AND mrr.operation_seq_num = mswth.to_op_seq_num ) '
15322 ||' AND process_flag = '||G_IN_PROCESS
15323 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
15324 ||' AND sr_instance_code = :v_instance_code';
15325
15326 IF V_DEBUG THEN
15327 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
15328 END IF;
15329 EXECUTE IMMEDIATE lv_sql_stmt
15330 USING v_instance_id,lv_batch_id,v_instance_code;
15331
15332 -- Set the message
15333
15334 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
15335 (p_app_short_name => 'MSC',
15336 p_error_code => 'MSC_PP_INVALID_VALUE',
15337 p_message_text => lv_message_text,
15338 p_error_text => lv_error_text,
15339 p_token1 => 'COLUMN_NAME',
15340 p_token_value1 => 'TO_OP_RES_SEQ_NUM');
15341
15342 IF lv_return <> 0 THEN
15343 RAISE ex_logging_err;
15344 END IF;
15345
15346 -- validate to_op_res_seq_num
15347
15348 v_sql_stmt := 17;
15349 lv_sql_stmt :=
15350 'UPDATE msc_st_wo_operation_rel mswth'
15351 ||' SET process_flag = '||G_ERROR_FLG||','
15352 ||' error_text = '||''''||lv_message_text||''''
15353 ||' WHERE NOT EXISTS ( SELECT 1 '
15354 ||' FROM msc_resource_requirements mrr'
15355 ||' WHERE mrr.sr_instance_id = :v_instance_id'
15356 ||' AND mrr.organization_id = mswth.organization_id'
15357 ||' AND mrr.supply_id = mswth.supply_id'
15358 ||' AND mrr.resource_seq_num = mswth.to_op_res_seq_num ) '
15359 ||' AND process_flag = '||G_IN_PROCESS
15360 ||' AND NVL(to_op_res_seq_num,'||NULL_VALUE||') <> '||NULL_VALUE
15361 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
15362 ||' AND sr_instance_code = :v_instance_code';
15363
15364 IF V_DEBUG THEN
15365 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
15366 END IF;
15367 EXECUTE IMMEDIATE lv_sql_stmt
15368 USING v_instance_id,lv_batch_id,v_instance_code;
15369
15370 --Call to customised validation.
15371 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
15372 (ERRBUF => lv_error_text,
15373 RETCODE => lv_return,
15374 pBatchID => NULL,
15375 pInstanceCode => v_instance_code,
15376 pEntityName => 'MSC_ST_WO_OPERATION_REL',
15377 pInstanceID => v_instance_id);
15378
15379 IF NVL(lv_return,0) <> 0 THEN
15380 RAISE ex_logging_err;
15381 END IF;
15382 -- Set the process flag as Valid and populate instance_id
15383 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
15384 (p_table_name => 'MSC_ST_WO_OPERATION_REL',
15385 p_instance_id => v_instance_id,
15386 p_instance_code => v_instance_code,
15387 p_process_flag => G_VALID,
15388 p_error_text => lv_error_text,
15389 p_debug => v_debug);
15390
15391 IF lv_return <> 0 THEN
15392 RAISE ex_logging_err;
15393 END IF;
15394
15395 -- At the end calling the LOG_ERROR for logging all
15396 -- errored out records.
15397
15398 lv_return := MSC_ST_UTIL.LOG_ERROR
15399 (p_table_name => 'MSC_ST_WO_OPERATION_REL',
15400 p_instance_code => v_instance_code,
15401 p_row => lv_column_names,
15402 p_severity => G_SEV_ERROR,
15403 p_message_text => NULL,
15404 p_error_text => lv_error_text,
15405 p_debug => v_debug );
15406
15407 IF lv_return <> 0 THEN
15408 RAISE ex_logging_err;
15409 END IF;
15410 COMMIT;
15411 END LOOP;
15412
15413 EXCEPTION WHEN ex_logging_err THEN
15414 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_error_text);
15415 -- G_WARNING_FLAG := 1;
15416 ROLLBACK;
15417
15418 WHEN OTHERS THEN
15419 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_WO_OPERATION_REL '||'('
15420 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
15421 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_error_text);
15422 -- G_WARNING_FLAG := 1;
15423 ROLLBACK;
15424
15425 END LOAD_WO_OPERATION_REL;
15426
15427 /*==========================================================================+
15428 | DESCRIPTION : This procedure performs validation and loads data into the |
15429 | table msc_st_planners. |
15430 +==========================================================================*/
15431 PROCEDURE LOAD_planners IS
15432 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
15433 lb_rowid RowidTab;
15434 lv_return NUMBER;
15435 lv_error_text VARCHAR2(250);
15436 lv_where_str VARCHAR2(5000);
15437 lv_sql_stmt VARCHAR2(5000);
15438 lv_column_names VARCHAR2(5000);
15439 lv_batch_id msc_st_planners.batch_id%TYPE;
15440 lv_message_text msc_errors.error_text%TYPE;
15441
15442 ex_logging_err EXCEPTION;
15443
15444 CURSOR c1(p_batch_id NUMBER) IS
15445 SELECT rowid
15446 FROM msc_st_planners
15447 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
15448 AND batch_id = p_batch_id
15449 AND sr_instance_code = v_instance_code;
15450
15451 CURSOR c2(p_batch_id NUMBER)IS
15452 SELECT
15453 x.PLANNER_CODE,
15454 x.ORGANIZATION_ID,
15455 x.DESCRIPTION,
15456 x.DISABLE_DATE,
15457 x.ELECTRONIC_MAIL_ADDRESS,
15458 x.EMPLOYEE_ID,
15459 x.CURRENT_EMPLOYEE_FLAG,
15460 x.USER_NAME,
15461 x.sr_instance_id,
15462 x.LAST_UPDATE_DATE,
15463 x.LAST_UPDATED_BY,
15464 x.CREATION_DATE,
15465 x.CREATED_BY,
15466 x.deleted_flag
15467 FROM MSC_ST_PLANNERS x
15468 WHERE x.sr_instance_code = v_instance_code
15469 and x.batch_id =p_batch_id
15470 and x.process_flag = G_VALID;
15471
15472 BEGIN
15473
15474 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
15475 (p_app_short_name => 'MSC',
15476 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
15477 p_message_text => lv_message_text,
15478 p_error_text => lv_error_text);
15479
15480 IF lv_return <> 0 THEN
15481 RAISE ex_logging_err;
15482 END IF;
15483
15484 --Duplicate records check for the records whose source is XML
15485 v_sql_stmt := 01;
15486 lv_sql_stmt :=
15487 ' UPDATE msc_st_planners msp1'
15488 ||' SET process_flag = '||G_ERROR_FLG||','
15489 ||' error_text = '||''''||lv_message_text||''''
15490 ||' WHERE message_id < (SELECT MAX(message_id)'
15491 ||' FROM msc_st_planners msp2'
15492 ||' WHERE msp2.sr_instance_code = msp1.sr_instance_code'
15493 ||' AND NVL(msp2.company_name, ' ||''''||NULL_CHAR||''''||') = '
15494 ||' NVL(msp1.company_name, ' ||''''||NULL_CHAR||''''||')'
15495 ||' AND msp2.organization_code = msp1.organization_code'
15496 ||' AND msp2.planner_code = msp1.planner_code'
15497 ||' AND msp2.process_flag = '||G_IN_PROCESS
15498 ||' AND NVL(msp2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
15499 ||' AND msp1.process_flag = '||G_IN_PROCESS
15500 ||' AND msp1.sr_instance_code = :v_instance_code'
15501 ||' AND NVL(msp1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
15502
15503
15504
15505 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
15506
15507 EXECUTE IMMEDIATE lv_sql_stmt
15508 USING v_instance_code;
15509
15510 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
15511 (p_app_short_name => 'MSC',
15512 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
15513 p_message_text => lv_message_text,
15514 p_error_text => lv_error_text);
15515
15516 IF lv_return <> 0 THEN
15517 RAISE ex_logging_err;
15518 END IF;
15519
15520 --Duplicate records check for the records whose source is other than XML
15521 --Different SQL is used because in XML we can identify the latest records
15522 --whereas in batch load we cannot.
15523 v_sql_stmt := 02;
15524 lv_sql_stmt :=
15525 ' UPDATE msc_st_planners msp1'
15526 ||' SET process_flag = '||G_ERROR_FLG||','
15527 ||' error_text = '||''''||lv_message_text||''''
15528 ||' WHERE EXISTS( SELECT 1 '
15529 ||' FROM msc_st_planners msp2'
15530 ||' WHERE msp2.sr_instance_code = msp1.sr_instance_code'
15531 ||' AND NVL(msp2.company_name, ' ||''''||NULL_CHAR||''''||') = '
15532 ||' NVL(msp1.company_name, ' ||''''||NULL_CHAR||''''||')'
15533 ||' AND msp2.organization_code = msp1.organization_code'
15534 ||' AND msp2.planner_code = msp1.planner_code'
15535 ||' AND msp2.process_flag = '||G_IN_PROCESS
15536 ||' AND NVL(msp2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
15537 ||' AND msp2.rowid <> msp1.rowid)'
15538 ||' AND msp1.process_flag = '||G_IN_PROCESS
15539 ||' AND msp1.sr_instance_code = :v_instance_code'
15540 ||' AND NVL(msp1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
15541
15542
15543
15544 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
15545
15546 EXECUTE IMMEDIATE lv_sql_stmt
15547 USING v_instance_code;
15548
15549 lv_column_names :=
15550 'PLANNER_CODE ||''~''||'
15551 ||'ORGANIZATION_CODE ||''~''||'
15552 ||'DESCRIPTION ||''~''||'
15553 ||'DISABLE_DATE ||''~''||'
15554 ||'ELECTRONIC_MAIL_ADDRESS ||''~''||'
15555 ||'CURRENT_EMPLOYEE_FLAG ||''~''||'
15556 ||'USER_NAME ||''~''||'
15557 ||'SR_INSTANCE_CODE ||''~''||'
15558 ||'COMPANY_NAME';
15559
15560
15561 LOOP
15562 v_sql_stmt := 03;
15563 SELECT msc_st_batch_id_s.NEXTVAL
15564 INTO lv_batch_id
15565 FROM dual;
15566
15567 v_sql_stmt := 04;
15568 lv_sql_stmt :=
15569 'UPDATE msc_st_planners '
15570 ||' SET batch_id = :lv_batch_id'
15571 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
15572 ||' AND sr_instance_code = :v_instance_code'
15573 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
15574 ||' AND rownum <= '||v_batch_size;
15575
15576
15577 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
15578
15579 EXECUTE IMMEDIATE lv_sql_stmt
15580 USING lv_batch_id,
15581 v_instance_code;
15582
15583 EXIT WHEN SQL%NOTFOUND;
15584
15585 OPEN c1(lv_batch_id);
15586 FETCH c1 BULK COLLECT INTO lb_rowid;
15587 CLOSE c1;
15588
15589 v_sql_stmt := 05;
15590 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
15591 UPDATE msc_st_planners
15592 SET st_transaction_id = msc_st_planners_s.NEXTVAL,
15593 refresh_id = v_refresh_id,
15594 last_update_date = v_current_date,
15595 last_updated_by = v_current_user,
15596 creation_date = v_current_date,
15597 created_by = v_current_user
15598 WHERE rowid = lb_rowid(j);
15599
15600 /* --Deletion is not allowed on this table.
15601 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
15602 (p_app_short_name => 'MSC',
15603 p_error_code => 'MSC_PP_NO_DELETION',
15604 p_message_text => lv_message_text,
15605 p_error_text => lv_error_text,
15606 p_token1 => 'TABLE_NAME',
15607 p_token_value1 => 'MSC_ST_PLANNERS');
15608
15609 IF lv_return <> 0 THEN
15610 RAISE ex_logging_err;
15611 END IF;
15612
15613 v_sql_stmt := 06;
15614 lv_sql_stmt :=
15615 'UPDATE msc_st_planners '
15616 ||' SET process_flag = '||G_ERROR_FLG||','
15617 ||' error_text = '||''''||lv_message_text||''''
15618 ||' WHERE deleted_flag = '||SYS_YES
15619 ||' AND process_flag = '||G_IN_PROCESS
15620 ||' AND batch_id = :lv_batch_id'
15621 ||' AND sr_instance_code = :v_instance_code';
15622
15623
15624 msc_st_util.log_message(lv_sql_stmt);
15625 END IF;
15626
15627 EXECUTE IMMEDIATE lv_sql_stmt
15628 USING lv_batch_id,
15629 v_instance_code;
15630 */
15631
15632 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
15633 (p_app_short_name => 'MSC',
15634 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
15635 p_message_text => lv_message_text,
15636 p_error_text => lv_error_text,
15637 p_token1 => 'COLUMN_NAME',
15638 p_token_value1 => 'DELETED_FLAG',
15639 p_token2 => 'DEFAULT_VALUE',
15640 p_token_value2 => SYS_NO);
15641
15642 IF lv_return <> 0 THEN
15643 RAISE ex_logging_err;
15644 END IF;
15645
15646 lv_where_str :=
15647 ' AND NVL(deleted_flag,'||NULL_VALUE||') '
15648 ||' NOT IN(1,2)';
15649 --Log a warning for those records where the deleted_flag has a value other
15650 --than SYS_NO
15651 lv_return := MSC_ST_UTIL.LOG_ERROR
15652 (p_table_name => 'MSC_ST_PLANNERS',
15653 p_instance_code => v_instance_code,
15654 p_row => lv_column_names,
15655 p_severity => G_SEV_WARNING,
15656 p_message_text => lv_message_text,
15657 p_error_text => lv_error_text,
15658 p_batch_id => lv_batch_id,
15659 p_where_str => lv_where_str,
15660 p_col_name => 'DELETED_FLAG',
15661 p_debug => v_debug,
15662 p_default_value => SYS_NO);
15663
15664 IF lv_return <> 0 THEN
15665 RAISE ex_logging_err;
15666 END IF;
15667
15668 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
15669 (p_app_short_name => 'MSC',
15670 p_error_code => 'MSC_PP_COL_VAL_NULL',
15671 p_message_text => lv_message_text,
15672 p_error_text => lv_error_text,
15673 p_token1 => 'COLUMN_NAME',
15674 p_token_value1 => 'PLANNER_CODE');
15675
15676 IF lv_return <> 0 THEN
15677 RAISE ex_logging_err;
15678 END IF;
15679
15680 v_sql_stmt := 07;
15681 lv_sql_stmt :=
15682 'UPDATE msc_st_planners '
15683 ||' SET process_flag = '||G_ERROR_FLG||','
15684 ||' error_text = '||''''||lv_message_text||''''
15685 ||' WHERE NVL(planner_code, '||''''||NULL_CHAR||''''||') '
15686 ||' = '||''''||NULL_CHAR||''''
15687 ||' AND batch_id = :lv_batch_id'
15688 ||' AND sr_instance_code = :v_instance_code'
15689 ||' AND process_flag = '||G_IN_PROCESS;
15690
15691
15692 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
15693
15694 EXECUTE IMMEDIATE lv_sql_stmt
15695 USING lv_batch_id,
15696 v_instance_code;
15697
15698 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
15699 (p_app_short_name => 'MSC',
15700 p_error_code => 'MSC_PP_INVALID_VALUE',
15701 p_message_text => lv_message_text,
15702 p_error_text => lv_error_text,
15703 p_token1 => 'COLUMN_NAME',
15704 p_token_value1 => 'CURRENT_EMPLOYEE_FLAG');
15705
15706 IF lv_return <> 0 THEN
15707 RAISE ex_logging_err;
15708 END IF;
15709
15710 v_sql_stmt := 07;
15711 lv_sql_stmt :=
15712 'UPDATE msc_st_planners '
15713 ||' SET process_flag = '||G_ERROR_FLG||','
15714 ||' error_text = '||''''||lv_message_text||''''
15715 ||' WHERE NVL(current_employee_flag,'||NULL_VALUE||') NOT IN(1,2) '
15716 ||' AND batch_id = :lv_batch_id'
15717 ||' AND sr_instance_code = :v_instance_code'
15718 ||' AND process_flag = '||G_IN_PROCESS;
15719
15720
15721 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
15722
15723 EXECUTE IMMEDIATE lv_sql_stmt
15724 USING lv_batch_id,
15725 v_instance_code;
15726
15727
15728 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
15729 (p_app_short_name => 'MSC',
15730 p_error_code => 'MSC_PP_INVALID_VALUE',
15731 p_message_text => lv_message_text,
15732 p_error_text => lv_error_text,
15733 p_token1 => 'COLUMN_NAME',
15734 p_token_value1 => 'USER_NAME');
15735
15736 IF lv_return <> 0 THEN
15737 RAISE ex_logging_err;
15738 END IF;
15739
15740 v_sql_stmt := 07;
15741 lv_sql_stmt :=
15742 'UPDATE msc_st_planners msp'
15743 ||' SET process_flag = '||G_ERROR_FLG||','
15744 ||' error_text = '||''''||lv_message_text||''''
15745 ||' WHERE NOT EXISTS(SELECT 1 '
15746 ||' FROM fnd_user fu'
15747 ||' where fu.user_name =UPPER(msp.user_name))'
15748 ||' AND batch_id = :lv_batch_id'
15749 ||' AND sr_instance_code = :v_instance_code'
15750 ||' AND process_flag = '||G_IN_PROCESS;
15751
15752
15753 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
15754
15755
15756 EXECUTE IMMEDIATE lv_sql_stmt
15757 USING lv_batch_id,
15758 v_instance_code;
15759
15760 -- Set the message
15761
15762 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
15763 (p_app_short_name => 'MSC',
15764 p_error_code => 'MSC_PP_INVALID_VALUE',
15765 p_message_text => lv_message_text,
15766 p_error_text => lv_error_text,
15767 p_token1 => 'COLUMN_NAME',
15768 p_token_value1 => 'ORGANIZATION_CODE');
15769
15770 IF lv_return <> 0 THEN
15771 RAISE ex_logging_err;
15772 END IF;
15773
15774 -- Derive organization_id
15775
15776 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
15777 (p_table_name => 'MSC_ST_PLANNERS',
15778 p_org_partner_name => 'ORGANIZATION_CODE',
15779 p_org_partner_id => 'ORGANIZATION_ID',
15780 p_instance_code => v_instance_code,
15781 p_partner_type => G_ORGANIZATION,
15782 p_severity => G_SEV_ERROR,
15783 p_error_text => lv_error_text,
15784 p_batch_id => lv_batch_id,
15785 p_debug => v_debug,
15786 p_message_text => lv_message_text);
15787
15788 IF lv_return <> 0 THEN
15789 RAISE ex_logging_err;
15790 END IF;
15791 /*
15792 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
15793 (p_app_short_name => 'MSC',
15794 p_error_code => 'MSC_PP_NO_UPDATION',
15795 p_message_text => lv_message_text,
15796 p_error_text => lv_error_text,
15797 p_token1 => 'TABLE_NAME',
15798 p_token_value1 => 'MSC_ST_PLANNERS');
15799
15800 IF lv_return <> 0 THEN
15801 RAISE ex_logging_err;
15802 END IF;
15803
15804 --Updation is not allowed on this entity(this is done to make the
15805 --Post-Processor in sync with the collection program).
15806 v_sql_stmt := 09;
15807 lv_sql_stmt :=
15808 ' UPDATE msc_st_planners msp1'
15809 ||' SET process_flag = '||G_ERROR_FLG||','
15810 ||' error_text = '||''''||lv_message_text||''''
15811 ||' WHERE process_flag = '||G_IN_PROCESS
15812 ||' AND batch_id = :lv_batch_id'
15813 ||' AND sr_instance_code = :v_instance_code'
15814 ||' AND EXISTS'
15815 ||' (SELECT 1 FROM msc_planners msp2'
15816 ||' WHERE msp2.organization_id = msp1.organization_id'
15817 ||' AND msp2.planner_code = msp1.planner_code'
15818 ||' AND msp2.sr_instance_id = ' ||v_instance_id ||')';
15819
15820
15821 msc_st_util.log_message(lv_sql_stmt);
15822 END IF;
15823
15824 EXECUTE IMMEDIATE lv_sql_stmt
15825 USING lv_batch_id,
15826 v_instance_code;
15827
15828 */
15829 --Derive employee_id
15830
15831 v_sql_stmt := 07;
15832 lv_sql_stmt :=
15833 'UPDATE msc_st_planners msp'
15834 ||' SET employee_id = (select employee_id '
15835 ||' from fnd_user fu'
15836 ||' where fu.user_name = UPPER(msp.user_name)) '
15837 ||' WHERE batch_id = :lv_batch_id'
15838 ||' AND sr_instance_code = :v_instance_code'
15839 ||' AND process_flag = '||G_IN_PROCESS;
15840
15841
15842 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
15843
15844 EXECUTE IMMEDIATE lv_sql_stmt
15845 USING lv_batch_id,
15846 v_instance_code;
15847
15848 --Call to customised validation.
15849 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
15850 (ERRBUF => lv_error_text,
15851 RETCODE => lv_return,
15852 pBatchID => lv_batch_id,
15853 pInstanceCode => v_instance_code,
15854 pEntityName => 'MSC_ST_PLANNERS',
15855 pInstanceID => v_instance_id);
15856
15857 IF NVL(lv_return,0) <> 0 THEN
15858 RAISE ex_logging_err;
15859 END IF;
15860
15861 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
15862 (p_table_name => 'MSC_ST_PLANNERS',
15863 p_instance_id => v_instance_id,
15864 p_instance_code => v_instance_code,
15865 p_process_flag => G_VALID,
15866 p_error_text => lv_error_text,
15867 p_debug => v_debug,
15868 p_batch_id => lv_batch_id);
15869
15870 IF lv_return <> 0 THEN
15871 RAISE ex_logging_err;
15872 END IF;
15873
15874 lv_return := MSC_ST_UTIL.LOG_ERROR
15875 (p_table_name => 'MSC_ST_PLANNERS',
15876 p_instance_code => v_instance_code,
15877 p_row => lv_column_names,
15878 p_severity => G_SEV_ERROR,
15879 p_message_text => NULL,
15880 p_error_text => lv_error_text,
15881 p_debug => v_debug,
15882 p_batch_id => lv_batch_id);
15883
15884 IF lv_return <> 0 THEN
15885 RAISE ex_logging_err;
15886 END IF;
15887
15888 --Inserts the valid records into the ODS table, Since the collection program
15889 --doesn't collect this entity incrementally and whereras post-processor always
15890 --runs in the incremental mode.
15891
15892 v_sql_stmt := 10;
15893 FOR c_rec IN c2(lv_batch_id) LOOP
15894
15895 BEGIN
15896
15897 if (c_rec.deleted_flag= SYS_YES) then
15898 DELETE from MSC_PLANNERS x where
15899 x.PLANNER_CODE = c_rec.PLANNER_CODE
15900 AND x.ORGANIZATION_ID = c_rec.ORGANIZATION_ID
15901 AND x.SR_INSTANCE_ID = v_instance_id
15902 AND c_rec.deleted_flag= SYS_YES;
15903
15904
15905 else
15906
15907 UPDATE MSC_PLANNERS x set
15908 DESCRIPTION =c_rec.DESCRIPTION,
15909 DISABLE_DATE =c_rec.DISABLE_DATE,
15910 ELECTRONIC_MAIL_ADDRESS =c_rec.ELECTRONIC_MAIL_ADDRESS,
15911 EMPLOYEE_ID =c_rec.EMPLOYEE_ID,
15912 CURRENT_EMPLOYEE_FLAG =c_rec.CURRENT_EMPLOYEE_FLAG,
15913 USER_NAME =c_rec.USER_NAME,
15914 LAST_UPDATE_DATE = c_rec.LAST_UPDATE_DATE,
15915 LAST_UPDATED_BY = c_rec.LAST_UPDATED_BY,
15916 CREATION_DATE = c_rec.CREATION_DATE,
15917 CREATED_BY = c_rec.CREATED_BY
15918 where x.PLANNER_CODE = c_rec.PLANNER_CODE
15919 and x.ORGANIZATION_ID = c_rec.ORGANIZATION_ID
15920 and x.SR_INSTANCE_ID = v_instance_id;
15921
15922
15923 IF SQL%NOTFOUND THEN
15924
15925 INSERT INTO MSC_PLANNERS
15926 ( PLANNER_CODE,
15927 ORGANIZATION_ID,
15928 DESCRIPTION,
15929 DISABLE_DATE,
15930 ELECTRONIC_MAIL_ADDRESS,
15931 EMPLOYEE_ID,
15932 CURRENT_EMPLOYEE_FLAG,
15933 USER_NAME,
15934 SR_INSTANCE_ID,
15935 LAST_UPDATE_DATE,
15936 LAST_UPDATED_BY,
15937 CREATION_DATE,
15938 CREATED_BY)
15939 VALUES
15940 (
15941 c_rec.PLANNER_CODE,
15942 c_rec.ORGANIZATION_ID,
15943 c_rec.DESCRIPTION,
15944 c_rec.DISABLE_DATE,
15945 c_rec.ELECTRONIC_MAIL_ADDRESS,
15946 c_rec.EMPLOYEE_ID,
15947 c_rec.CURRENT_EMPLOYEE_FLAG,
15948 c_rec.USER_NAME,
15949 v_instance_id,
15950 c_rec.LAST_UPDATE_DATE,
15951 c_rec.LAST_UPDATED_BY,
15952 c_rec.CREATION_DATE,
15953 c_rec.CREATED_BY
15954 );
15955 END IF;
15956 end if;
15957
15958 EXCEPTION
15959 WHEN OTHERS THEN
15960 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_PLANNERS'||
15961 'Error in Inserting or Updating into MSC_PLANNERS'|| SQLERRM, 1, 240);
15962 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
15963 ROLLBACK;
15964 END;
15965 END LOOP;
15966
15967 UPDATE FND_USER y
15968 SET EMAIL_ADDRESS = (select ELECTRONIC_MAIL_ADDRESS
15969 from msc_st_planners z
15970 WHERE UPPER(z.USER_NAME) = y.USER_NAME
15971 AND z.process_flag = G_VALID
15972 AND z.CURRENT_EMPLOYEE_FLAG = 1
15973 AND z.EMPLOYEE_ID IS NOT NULL
15974 AND z.ELECTRONIC_MAIL_ADDRESS IS NOT NULL
15975 AND z.SR_INSTANCE_ID = v_instance_id
15976 AND rownum=1)
15977 WHERE exists (SELECT 1
15978 from msc_st_planners x
15979 WHERE x.USER_NAME = y.USER_NAME
15980 AND x.CURRENT_EMPLOYEE_FLAG = 1
15981 AND x.EMPLOYEE_ID IS NOT NULL
15982 AND x.ELECTRONIC_MAIL_ADDRESS IS NOT NULL
15983 AND x.SR_INSTANCE_ID = v_instance_id
15984 AND x.batch_id = lv_batch_id);
15985
15986
15987 COMMIT;
15988 END LOOP;
15989
15990 EXCEPTION
15991 WHEN ex_logging_err THEN
15992 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
15993 ROLLBACK;
15994
15995 WHEN OTHERS THEN
15996 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_PLANNERS'||'('
15997 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
15998 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
15999 ROLLBACK;
16000
16001 END LOAD_PLANNERS;
16002
16003
16004 /*==========================================================================+
16005 | DESCRIPTION : This procedure validates the data for inter org shipping |
16006 | methods for table MSC_ST_INTERORG_SHIP_METHODS |
16007 +==========================================================================*/
16008 PROCEDURE LOAD_SHIP_METHODS IS
16009
16010 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
16011 lb_rowid RowidTab; --bulk collects rowid
16012 lv_return NUMBER;
16013 lv_batch_id NUMBER;
16014 lv_error_text VARCHAR2(250);
16015 lv_where_str VARCHAR2(5000);
16016 lv_sql_stmt VARCHAR2(5000);
16017 lv_column_names VARCHAR2(5000); --stores concatenated column names
16018 lv_message_text msc_errors.error_text%TYPE;
16019
16020 ex_logging_err EXCEPTION;
16021
16022 CURSOR c1(p_batch_id NUMBER) IS
16023 SELECT rowid
16024 FROM msc_st_interorg_ship_methods
16025 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
16026 AND sr_instance_code = v_instance_code
16027 AND batch_id = p_batch_id;
16028
16029 BEGIN
16030
16031 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
16032 (p_app_short_name => 'MSC',
16033 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
16034 p_message_text => lv_message_text,
16035 p_error_text => lv_error_text);
16036
16037 IF lv_return <> 0 THEN
16038 RAISE ex_logging_err;
16039 END IF;
16040
16041
16042 -- duplicate key validation changed for the bug fix 2748525.
16043 --Duplicate records check for the records whose source is other than XML
16044 --Different SQL is used because in XML we can identify the latest records
16045 --whereas in batch load we cannot.
16046
16047 v_sql_stmt := 01;
16048 lv_sql_stmt :=
16049 'UPDATE msc_st_interorg_ship_methods msis1 '
16050 ||' SET process_flag = '||G_ERROR_FLG||','
16051 ||' error_text = '||''''||lv_message_text||''''
16052 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_interorg_ship_methods msis2 '
16053 ||' WHERE msis2.sr_instance_code = msis1.sr_instance_code'
16054 ||' AND NVL(msis2.company_name, '||''''||NULL_CHAR||''''||') = '
16055 ||' NVL(msis1.company_name, '||''''||NULL_CHAR||''''||')'
16056 ||' AND NVL(msis2.from_organization_code, '||''''||NULL_CHAR||''''||') = '
16057 ||' NVL(msis1.from_organization_code, '||''''||NULL_CHAR||''''||')'
16058 ||' AND NVL(msis2.to_organization_code, '||''''||NULL_CHAR||''''||') = '
16059 ||' NVL(msis1.to_organization_code, '||''''||NULL_CHAR||''''||')'
16060 ||' AND NVL(msis2.from_location_code, '||''''||NULL_CHAR||''''||') = '
16061 ||' NVL(msis1.from_location_code, '||''''||NULL_CHAR||''''||')'
16062 ||' AND NVL(msis2.to_location_code, '||''''||NULL_CHAR||''''||') = '
16063 ||' NVL(msis1.to_location_code, '||''''||NULL_CHAR||''''||')'
16064 ||' AND msis2.ship_method = msis1.ship_method'
16065 ||' AND msis2.process_flag = msis1.process_flag'
16066 ||' AND NVL(msis2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
16067 ||' AND NVL(msis2.to_region_type, '||NULL_VALUE||')= NVL(msis1.to_region_type, '||NULL_VALUE||')'
16068 ||' AND NVL(msis2.to_country, '||''''||NULL_CHAR||''''||') = '
16069 ||' NVL(msis1.to_country, '||''''||NULL_CHAR||''''||')'
16070 ||' AND NVL(msis2.to_country_code, '||''''||NULL_CHAR||''''||') = '
16071 ||' NVL(msis1.to_country_code, '||''''||NULL_CHAR||''''||')'
16072 ||' AND NVL(msis2.to_state, '||''''||NULL_CHAR||''''||') = '
16073 ||' NVL(msis1.to_state, '||''''||NULL_CHAR||''''||')'
16074 ||' AND NVL(msis2.to_state_code, '||''''||NULL_CHAR||''''||') = '
16075 ||' NVL(msis1.to_state_code, '||''''||NULL_CHAR||''''||')'
16076 ||' AND NVL(msis2.to_city, '||''''||NULL_CHAR||''''||') = '
16077 ||' NVL(msis1.to_city, '||''''||NULL_CHAR||''''||')'
16078 ||' AND NVL(msis2.to_city_code, '||''''||NULL_CHAR||''''||') = '
16079 ||' NVL(msis1.to_city_code, '||''''||NULL_CHAR||''''||')'
16080 ||' AND NVL(msis2.to_postal_code_from, '||''''||NULL_CHAR||''''||') = '
16081 ||' NVL(msis1.to_postal_code_from, '||''''||NULL_CHAR||''''||')'
16082 ||' AND NVL(msis2.to_postal_code_to, '||''''||NULL_CHAR||''''||') = '
16083 ||' NVL(msis1.to_postal_code_to, '||''''||NULL_CHAR||''''||')'
16084 ||' AND NVL(msis2.to_zone, '||''''||NULL_CHAR||''''||') = '
16085 ||' NVL(msis1.to_zone, '||''''||NULL_CHAR||''''||')'
16086 ||' AND NVL(msis2.from_region_type, '||NULL_VALUE||')= NVL(msis1.from_region_type, '||NULL_VALUE||')'
16087 ||' AND NVL(msis2.from_country, '||''''||NULL_CHAR||''''||') = '
16088 ||' NVL(msis1.from_country, '||''''||NULL_CHAR||''''||')'
16089 ||' AND NVL(msis2.from_country_code, '||''''||NULL_CHAR||''''||') = '
16090 ||' NVL(msis1.from_country_code, '||''''||NULL_CHAR||''''||')'
16091 ||' AND NVL(msis2.from_state, '||''''||NULL_CHAR||''''||') = '
16092 ||' NVL(msis1.from_state, '||''''||NULL_CHAR||''''||')'
16093 ||' AND NVL(msis2.from_state_code, '||''''||NULL_CHAR||''''||') = '
16094 ||' NVL(msis1.from_state_code, '||''''||NULL_CHAR||''''||')'
16095 ||' AND NVL(msis2.from_city, '||''''||NULL_CHAR||''''||') = '
16096 ||' NVL(msis1.from_city, '||''''||NULL_CHAR||''''||')'
16097 ||' AND NVL(msis2.from_city_code, '||''''||NULL_CHAR||''''||') = '
16098 ||' NVL(msis1.from_city_code, '||''''||NULL_CHAR||''''||')'
16099 ||' AND NVL(msis2.from_postal_code_from, '||''''||NULL_CHAR||''''||') = '
16100 ||' NVL(msis1.from_postal_code_from, '||''''||NULL_CHAR||''''||')'
16101 ||' AND NVL(msis2.from_postal_code_to, '||''''||NULL_CHAR||''''||') = '
16102 ||' NVL(msis1.from_postal_code_to, '||''''||NULL_CHAR||''''||')'
16103 ||' AND NVL(msis2.from_zone, '||''''||NULL_CHAR||''''||') = '
16104 ||' NVL(msis1.from_zone, '||''''||NULL_CHAR||''''||')'
16105 ||' AND msis2.rowid <> msis1.rowid)'
16106 ||' AND msis1.process_flag = '||G_IN_PROCESS
16107 ||' AND msis1.sr_instance_code = :v_instance_code'
16108 ||' AND NVL(msis1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
16109
16110
16111 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
16112
16113 EXECUTE IMMEDIATE lv_sql_stmt
16114 USING v_instance_code;
16115
16116 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
16117 (p_app_short_name => 'MSC',
16118 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
16119 p_message_text => lv_message_text,
16120 p_error_text => lv_error_text);
16121
16122 IF lv_return <> 0 THEN
16123 RAISE ex_logging_err;
16124 END IF;
16125
16126 --Duplicate records check for the records whose source is XML
16127 v_sql_stmt := 02;
16128 lv_sql_stmt :=
16129 'UPDATE msc_st_interorg_ship_methods msis1 '
16130 ||' SET process_flag = '||G_ERROR_FLG||','
16131 ||' error_text = '||''''||lv_message_text||''''
16132 ||' WHERE message_id < ( SELECT max(message_id) '
16133 ||' FROM msc_st_interorg_ship_methods msis2 '
16134 ||' WHERE msis2.sr_instance_code = msis1.sr_instance_code'
16135 ||' AND NVL(msis2.company_name, '||''''||NULL_CHAR||''''||') = '
16136 ||' NVL(msis1.company_name, '||''''||NULL_CHAR||''''||')'
16137 ||' AND NVL(msis2.from_organization_code, '||''''||NULL_CHAR||''''||') = '
16138 ||' NVL(msis1.from_organization_code, '||''''||NULL_CHAR||''''||')'
16139 ||' AND NVL(msis2.to_organization_code, '||''''||NULL_CHAR||''''||') = '
16140 ||' NVL(msis1.to_organization_code, '||''''||NULL_CHAR||''''||')'
16141 ||' AND NVL(msis2.from_location_code, '||''''||NULL_CHAR||''''||') = '
16142 ||' NVL(msis1.from_location_code, '||''''||NULL_CHAR||''''||')'
16143 ||' AND NVL(msis2.to_location_code, '||''''||NULL_CHAR||''''||') = '
16144 ||' NVL(msis1.to_location_code, '||''''||NULL_CHAR||''''||')'
16145 ||' AND msis2.ship_method = msis1.ship_method'
16146 ||' AND NVL(msis2.to_region_type, '||NULL_VALUE||')= NVL(msis1.to_region_type, '||NULL_VALUE||')'
16147 ||' AND NVL(msis2.to_country, '||''''||NULL_CHAR||''''||') = '
16148 ||' NVL(msis1.to_country, '||''''||NULL_CHAR||''''||')'
16149 ||' AND NVL(msis2.to_country_code, '||''''||NULL_CHAR||''''||') = '
16150 ||' NVL(msis1.to_country_code, '||''''||NULL_CHAR||''''||')'
16151 ||' AND NVL(msis2.to_state, '||''''||NULL_CHAR||''''||') = '
16152 ||' NVL(msis1.to_state, '||''''||NULL_CHAR||''''||')'
16153 ||' AND NVL(msis2.to_state_code, '||''''||NULL_CHAR||''''||') = '
16154 ||' NVL(msis1.to_state_code, '||''''||NULL_CHAR||''''||')'
16155 ||' AND NVL(msis2.to_city, '||''''||NULL_CHAR||''''||') = '
16156 ||' NVL(msis1.to_city, '||''''||NULL_CHAR||''''||')'
16157 ||' AND NVL(msis2.to_city_code, '||''''||NULL_CHAR||''''||') = '
16158 ||' NVL(msis1.to_city_code, '||''''||NULL_CHAR||''''||')'
16159 ||' AND NVL(msis2.to_postal_code_from, '||''''||NULL_CHAR||''''||') = '
16160 ||' NVL(msis1.to_postal_code_from, '||''''||NULL_CHAR||''''||')'
16161 ||' AND NVL(msis2.to_postal_code_to, '||''''||NULL_CHAR||''''||') = '
16162 ||' NVL(msis1.to_postal_code_to, '||''''||NULL_CHAR||''''||')'
16163 ||' AND NVL(msis2.to_zone, '||''''||NULL_CHAR||''''||') = '
16164 ||' NVL(msis1.to_zone, '||''''||NULL_CHAR||''''||')'
16165 ||' AND NVL(msis2.from_region_type, '||NULL_VALUE||')= NVL(msis1.from_region_type, '||NULL_VALUE||')'
16166 ||' AND NVL(msis2.from_country, '||''''||NULL_CHAR||''''||') = '
16167 ||' NVL(msis1.from_country, '||''''||NULL_CHAR||''''||')'
16168 ||' AND NVL(msis2.from_country_code, '||''''||NULL_CHAR||''''||') = '
16169 ||' NVL(msis1.from_country_code, '||''''||NULL_CHAR||''''||')'
16170 ||' AND NVL(msis2.from_state, '||''''||NULL_CHAR||''''||') = '
16171 ||' NVL(msis1.from_state, '||''''||NULL_CHAR||''''||')'
16172 ||' AND NVL(msis2.from_state_code, '||''''||NULL_CHAR||''''||') = '
16173 ||' NVL(msis1.from_state_code, '||''''||NULL_CHAR||''''||')'
16174 ||' AND NVL(msis2.from_city, '||''''||NULL_CHAR||''''||') = '
16175 ||' NVL(msis1.from_city, '||''''||NULL_CHAR||''''||')'
16176 ||' AND NVL(msis2.from_city_code, '||''''||NULL_CHAR||''''||') = '
16177 ||' NVL(msis1.from_city_code, '||''''||NULL_CHAR||''''||')'
16178 ||' AND NVL(msis2.from_postal_code_from, '||''''||NULL_CHAR||''''||') = '
16179 ||' NVL(msis1.from_postal_code_from, '||''''||NULL_CHAR||''''||')'
16180 ||' AND NVL(msis2.from_postal_code_to, '||''''||NULL_CHAR||''''||') = '
16181 ||' NVL(msis1.from_postal_code_to, '||''''||NULL_CHAR||''''||')'
16182 ||' AND NVL(msis2.from_zone, '||''''||NULL_CHAR||''''||') = '
16183 ||' NVL(msis1.from_zone, '||''''||NULL_CHAR||''''||')'
16184 ||' AND msis2.process_flag = msis1.process_flag'
16185 ||' AND NVL(msis2.message_id,'||NULL_VALUE||') <> '||NULL_VALUE||')'
16186 ||' AND msis1.process_flag = '||G_IN_PROCESS
16187 ||' AND msis1.sr_instance_code = :v_instance_code'
16188 ||' AND NVL(msis1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
16189
16190
16191 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
16192
16193 EXECUTE IMMEDIATE lv_sql_stmt
16194 USING v_instance_code;
16195
16196 lv_column_names :=
16197 'FROM_ORGANIZATION_CODE ||''~''||'
16198 ||'TO_ORGANIZATION_CODE ||''~''||'
16199 ||'SR_INSTANCE_CODE ||''~''||'
16200 ||'SHIP_METHOD ||''~''||'
16201 ||'DEFAULT_FLAG ||''~''||'
16202 ||'INTRANSIT_TIME ||''~''||'
16203 ||'TIME_UOM_CODE ||''~''||'
16204 ||'WEIGHT_CAPACITY ||''~''||'
16205 ||'WEIGHT_UOM ||''~''||'
16206 ||'VOLUME_CAPACITY ||''~''||'
16207 ||'VOLUME_UOM ||''~''||'
16208 ||'COST_PER_WEIGHT_UNIT ||''~''||'
16209 ||'COST_PER_VOLUME_UNIT ||''~''||'
16210 ||'TRANSPORT_CAP_OVER_UTIL_COST ||''~''||'
16211 ||'COMPANY_NAME ||''~''||'
16212 ||'FROM_LOCATION_CODE ||''~''||'
16213 ||'TO_LOCATION_CODE ||''~''||'
16214 ||'DELETED_FLAG' ;
16215
16216 -- Dividing records in batches based on batchsize
16217 LOOP
16218 v_sql_stmt := 03;
16219 SELECT msc_st_batch_id_s.NEXTVAL
16220 INTO lv_batch_id
16221 FROM DUAL;
16222
16223 v_sql_stmt := 04;
16224 lv_sql_stmt :=
16225 'UPDATE msc_st_interorg_ship_methods '
16226 ||' SET batch_id = :lv_batch_id '
16227 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
16228 ||' AND sr_instance_code = :v_instance_code'
16229 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
16230 ||' AND rownum <= '||v_batch_size;
16231
16232
16233 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
16234
16235 EXECUTE IMMEDIATE lv_sql_stmt
16236 USING lv_batch_id,
16237 v_instance_code;
16238
16239 EXIT WHEN SQL%NOTFOUND ;
16240
16241 OPEN c1(lv_batch_id);
16242 FETCH c1 BULK COLLECT INTO lb_rowid;
16243 CLOSE c1;
16244
16245 v_sql_stmt := 05;
16246 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
16247 UPDATE msc_st_interorg_ship_methods
16248 SET st_transaction_id = msc_st_interorg_ship_methods_s.NEXTVAL,
16249 refresh_id = v_refresh_id,
16250 last_update_date = v_current_date,
16251 last_updated_by = v_current_user,
16252 creation_date = v_current_date,
16253 created_by = v_current_user
16254 WHERE rowid = lb_rowid(j);
16255
16256 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
16257 (p_app_short_name => 'MSC',
16258 p_error_code => 'MSC_PP_NO_DELETION',
16259 p_message_text => lv_message_text,
16260 p_error_text => lv_error_text,
16261 p_token1 => 'TABLE_NAME',
16262 p_token_value1 => 'MSC_ST_INTERORG_SHIP_METHODS');
16263
16264
16265 -- Deletion is not allowed for this table
16266 v_sql_stmt := 06;
16267 lv_sql_stmt :=
16268 'UPDATE msc_st_interorg_ship_methods '
16269 ||' SET process_flag = '||G_ERROR_FLG||','
16270 ||' error_text = '||''''||lv_message_text||''''
16271 ||' WHERE deleted_flag = '||SYS_YES
16272 ||' AND process_flag = '||G_IN_PROCESS
16273 ||' AND batch_id = :lv_batch_id'
16274 ||' AND sr_instance_code = :v_instance_code';
16275
16276
16277 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
16278
16279 EXECUTE IMMEDIATE lv_sql_stmt
16280 USING lv_batch_id,
16281 v_instance_code;
16282
16283 -- set the message
16284
16285 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
16286 (p_app_short_name => 'MSC',
16287 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
16288 p_message_text => lv_message_text,
16289 p_error_text => lv_error_text,
16290 p_token1 => 'COLUMN_NAME',
16291 p_token_value1 => 'DELETED_FLAG',
16292 p_token2 => 'DEFAULT_VALUE',
16293 p_token_value2 => SYS_NO);
16294
16295 IF lv_return <> 0 THEN
16296 RAISE ex_logging_err;
16297 END IF;
16298
16299 -- Check DELETE_FLAG column has valid value or not and if not set it to SYS_NO
16300 -- Log error procedure inserts warning and also defaults the delete flag
16301
16302 lv_where_str := ' AND NVL(deleted_flag,'||NULL_VALUE||') '
16303 ||' NOT IN(1,2)';
16304
16305 lv_return := MSC_ST_UTIL.LOG_ERROR
16306 (p_table_name => 'MSC_ST_INTERORG_SHIP_METHODS',
16307 p_instance_code => v_instance_code,
16308 p_row => lv_column_names,
16309 p_severity => G_SEV_WARNING,
16310 p_message_text => lv_message_text,
16311 p_error_text => lv_error_text,
16312 p_batch_id => lv_batch_id,
16313 p_where_str => lv_where_str,
16314 p_col_name => 'DELETED_FLAG',
16315 p_debug => v_debug,
16316 p_default_value => SYS_NO);
16317
16318 IF lv_return <> 0 THEN
16319 RAISE ex_logging_err;
16320 END IF;
16321
16322 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
16323 (p_app_short_name => 'MSC',
16324 p_error_code => 'MSC_PP_COL_VAL_NULL',
16325 p_message_text => lv_message_text,
16326 p_error_text => lv_error_text,
16327 p_token1 => 'COLUMN_NAME',
16328 p_token_value1 => 'SHIP_METHOD');
16329
16330 IF lv_return <> 0 THEN
16331 RAISE ex_logging_err;
16332 END IF;
16333
16334 -- Error out records where ship_method is NULL
16335 v_sql_stmt := 07;
16336 lv_sql_stmt :=
16337 'UPDATE msc_st_interorg_ship_methods'
16338 ||' SET process_flag = '||G_ERROR_FLG||','
16339 ||' error_text = '||''''||lv_message_text||''''
16340 ||' WHERE NVL(ship_method, '||''''||NULL_CHAR||''''||') '
16341 ||' = '||''''||NULL_CHAR||''''
16342 ||' AND batch_id = :lv_batch_id'
16343 ||' AND process_flag = '||G_IN_PROCESS
16344 ||' AND sr_instance_code = :v_instance_code';
16345
16346
16347 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
16348 EXECUTE IMMEDIATE lv_sql_stmt
16349 USING lv_batch_id,
16350 v_instance_code;
16351
16352 -- Set the message
16353
16354 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
16355 (p_app_short_name => 'MSC',
16356 p_error_code => 'MSC_PP_INVALID_VALUE',
16357 p_message_text => lv_message_text,
16358 p_error_text => lv_error_text,
16359 p_token1 => 'COLUMN_NAME',
16360 p_token_value1 => 'FROM_ORGANIZATION_CODE');
16361
16362 IF lv_return <> 0 THEN
16363 RAISE ex_logging_err;
16364 END IF;
16365
16366 -- Derive from_organization_id
16367
16368 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
16369 (p_table_name => 'MSC_ST_INTERORG_SHIP_METHODS',
16370 p_org_partner_name => 'FROM_ORGANIZATION_CODE',
16371 p_org_partner_id => 'FROM_ORGANIZATION_ID',
16372 p_instance_code => v_instance_code,
16373 p_partner_type => G_ORGANIZATION,
16374 p_severity => G_SEV3_ERROR,
16375 p_error_text => lv_error_text,
16376 p_batch_id => lv_batch_id,
16377 p_debug => v_debug,
16378 p_message_text => lv_message_text);
16379
16380 IF lv_return <> 0 THEN
16381 RAISE ex_logging_err;
16382 END IF;
16383
16384 lv_sql_stmt :=
16385 'UPDATE msc_st_interorg_ship_methods '
16386 ||' SET FROM_ORGANIZATION_ID = -1 '
16387 ||' WHERE NVL(FROM_ORGANIZATION_ID,'||NULL_VALUE||') = '||NULL_VALUE
16388 ||' AND NVL(FROM_ORGANIZATION_CODE,'||''''||NULL_CHAR||''''||')'
16389 ||' = '||''''||NULL_CHAR||''''
16390 ||' AND process_flag = '||G_IN_PROCESS
16391 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
16392 ||' AND sr_instance_code = :v_instance_code';
16393
16394
16395 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
16396
16397
16398 EXECUTE IMMEDIATE lv_sql_stmt
16399 USING lv_batch_id,
16400 v_instance_code;
16401
16402 -- Set the message
16403
16404 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
16405 (p_app_short_name => 'MSC',
16406 p_error_code => 'MSC_PP_INVALID_VALUE',
16407 p_message_text => lv_message_text,
16408 p_error_text => lv_error_text,
16409 p_token1 => 'COLUMN_NAME',
16410 p_token_value1 => 'TO_ORGANIZATION_CODE');
16411
16412 IF lv_return <> 0 THEN
16413 RAISE ex_logging_err;
16414 END IF;
16415
16416 -- Derive to_organization_id
16417
16418 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
16419 (p_table_name => 'MSC_ST_INTERORG_SHIP_METHODS',
16420 p_org_partner_name => 'TO_ORGANIZATION_CODE',
16421 p_org_partner_id => 'TO_ORGANIZATION_ID',
16422 p_instance_code => v_instance_code,
16423 p_partner_type => G_ORGANIZATION,
16424 p_severity => G_SEV3_ERROR,
16425 p_error_text => lv_error_text,
16426 p_batch_id => lv_batch_id,
16427 p_debug => v_debug,
16428 p_message_text => lv_message_text);
16429
16430 IF lv_return <> 0 THEN
16431 RAISE ex_logging_err;
16432 END IF;
16433
16434 lv_sql_stmt :=
16435 'UPDATE msc_st_interorg_ship_methods '
16436 ||' SET TO_ORGANIZATION_ID = -1 '
16437 ||' WHERE NVL(TO_ORGANIZATION_ID,'||NULL_VALUE||') = '||NULL_VALUE
16438 ||' AND NVL(TO_ORGANIZATION_CODE,'||''''||NULL_CHAR||''''||')'
16439 ||' = '||''''||NULL_CHAR||''''
16440 ||' AND process_flag = '||G_IN_PROCESS
16441 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
16442 ||' AND sr_instance_code = :v_instance_code';
16443
16444
16445 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
16446
16447
16448 EXECUTE IMMEDIATE lv_sql_stmt
16449 USING lv_batch_id,
16450 v_instance_code;
16451
16452 -- Update FROM_LOCATION_ID
16453 v_sql_stmt := 08;
16454 lv_sql_stmt :=
16455 'UPDATE msc_st_interorg_ship_methods msis'
16456 ||' SET from_location_id = (SELECT local_id'
16457 ||' FROM msc_local_id_setup mls'
16458 ||' WHERE mls.char1 = msis.sr_instance_code'
16459 ||' AND mls.char3 = msis.from_location_code'
16460 ||' AND mls.entity_name = ''LOCATION_ID'' )'
16461 ||' WHERE process_flag = '||G_IN_PROCESS
16462 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
16463 ||' AND sr_instance_code = :v_instance_code';
16464
16465
16466 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
16467
16468 EXECUTE IMMEDIATE lv_sql_stmt
16469 USING lv_batch_id,
16470 v_instance_code;
16471
16472
16473 -- Update TO_LOCATION_ID
16474
16475 v_sql_stmt := 09;
16476 lv_sql_stmt :=
16477 'UPDATE msc_st_interorg_ship_methods msis'
16478 ||' SET to_location_id = (SELECT local_id'
16479 ||' FROM msc_local_id_setup mls'
16480 ||' WHERE mls.char1 = msis.sr_instance_code'
16481 ||' AND mls.char3 = msis.to_location_code'
16482 ||' AND mls.entity_name = ''LOCATION_ID'' )'
16483 ||' WHERE process_flag = '||G_IN_PROCESS
16484 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
16485 ||' AND sr_instance_code = :v_instance_code';
16486
16487
16488
16489 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
16490
16491 EXECUTE IMMEDIATE lv_sql_stmt
16492 USING lv_batch_id,
16493 v_instance_code;
16494
16495
16496 -- if from or to location code was provided, error out if doesn't exists in local id.
16497
16498 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
16499 (p_app_short_name => 'MSC',
16500 p_error_code => 'MSC_PP_INVALID_VALUE',
16501 p_message_text => lv_message_text,
16502 p_error_text => lv_error_text,
16503 p_token1 => 'COLUMN_NAME',
16504 p_token_value1 => 'TO_LOCATION_CODE');
16505
16506 IF lv_return <> 0 THEN
16507 RAISE ex_logging_err;
16508 END IF;
16509
16510 v_sql_stmt := 9.1;
16511 lv_sql_stmt :=
16512 'UPDATE msc_st_interorg_ship_methods '
16513 ||' SET error_text = '||''''||lv_error_text||''''||','
16514 ||' process_flag = '||G_ERROR
16515 ||' WHERE NVL(to_location_id,'||NULL_VALUE||') = '||NULL_VALUE
16516 ||' AND NVL(to_location_code,'||''''||NULL_CHAR||''''||')'
16517 ||' <> '||''''||NULL_CHAR||''''
16518 ||' AND process_flag = '||G_IN_PROCESS
16519 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
16520 ||' AND sr_instance_code = :v_instance_code';
16521
16522
16523 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
16524
16525
16526 EXECUTE IMMEDIATE lv_sql_stmt
16527 USING lv_batch_id,
16528 v_instance_code;
16529
16530
16531 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
16532 (p_app_short_name => 'MSC',
16533 p_error_code => 'MSC_PP_INVALID_VALUE',
16534 p_message_text => lv_message_text,
16535 p_error_text => lv_error_text,
16536 p_token1 => 'COLUMN_NAME',
16537 p_token_value1 => 'FROM_LOCATION_CODE');
16538
16539 IF lv_return <> 0 THEN
16540 RAISE ex_logging_err;
16541 END IF;
16542
16543 v_sql_stmt := 9.2;
16544 lv_sql_stmt :=
16545 'UPDATE msc_st_interorg_ship_methods '
16546 ||' SET error_text = '||''''||lv_error_text||''''||','
16547 ||' process_flag = '||G_ERROR
16548 ||' WHERE NVL(from_location_id,'||NULL_VALUE||') = '||NULL_VALUE
16549 ||' AND NVL(from_location_code,'||''''||NULL_CHAR||''''||')'
16550 ||' <> '||''''||NULL_CHAR||''''
16551 ||' AND process_flag = '||G_IN_PROCESS
16552 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
16553 ||' AND sr_instance_code = :v_instance_code';
16554
16555
16556 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
16557
16558
16559 EXECUTE IMMEDIATE lv_sql_stmt
16560 USING lv_batch_id,
16561 v_instance_code;
16562
16563 lv_sql_stmt :=
16564 'UPDATE msc_st_interorg_ship_methods '
16565 ||' SET from_location_id = -1'
16566 ||' WHERE NVL(from_location_id,'||NULL_VALUE||') = '||NULL_VALUE
16567 ||' AND NVL(from_location_code,'||''''||NULL_CHAR||''''||')'
16568 ||' = '||''''||NULL_CHAR||''''
16569 ||' AND process_flag = '||G_IN_PROCESS
16570 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
16571 ||' AND sr_instance_code = :v_instance_code';
16572
16573
16574 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
16575
16576
16577 EXECUTE IMMEDIATE lv_sql_stmt
16578 USING lv_batch_id,
16579 v_instance_code;
16580
16581 lv_sql_stmt :=
16582 'UPDATE msc_st_interorg_ship_methods '
16583 ||' SET to_location_id = -1'
16584 ||' WHERE NVL(to_location_id,'||NULL_VALUE||') = '||NULL_VALUE
16585 ||' AND NVL(to_location_code,'||''''||NULL_CHAR||''''||')'
16586 ||' = '||''''||NULL_CHAR||''''
16587 ||' AND process_flag = '||G_IN_PROCESS
16588 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
16589 ||' AND sr_instance_code = :v_instance_code';
16590
16591
16592 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
16593
16594
16595 EXECUTE IMMEDIATE lv_sql_stmt
16596 USING lv_batch_id,
16597 v_instance_code;
16598
16599 -- Derive from_region_id
16600
16601 lv_sql_stmt :=
16602 'UPDATE msc_st_interorg_ship_methods msr'
16603 ||' SET from_region_id = (SELECT local_id'
16604 ||' FROM msc_local_id_setup mls'
16605 ||' WHERE mls.char1 = msr.sr_instance_code'
16606 ||' AND mls.number1 = nvl(msr.from_region_type,'||NULL_VALUE||')'
16607 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
16608 ||' NVL(msr.from_country, '||''''||NULL_CHAR||''''||') '
16609 ||' AND NVL(mls.char3, '||''''||NULL_CHAR||''''||') = '
16610 ||' NVL(msr.from_country_code, '||''''||NULL_CHAR||''''||') '
16611 ||' AND NVL(mls.char4, '||''''||NULL_CHAR||''''||') = '
16612 ||' NVL(msr.from_state, '||''''||NULL_CHAR||''''||') '
16613 ||' AND NVL(mls.char5, '||''''||NULL_CHAR||''''||') = '
16614 ||' NVL(msr.from_state_code, '||''''||NULL_CHAR||''''||') '
16615 ||' AND NVL(mls.char6, '||''''||NULL_CHAR||''''||') = '
16616 ||' NVL(msr.from_city, '||''''||NULL_CHAR||''''||') '
16617 ||' AND NVL(mls.char7, '||''''||NULL_CHAR||''''||') = '
16618 ||' NVL(msr.from_city_code, '||''''||NULL_CHAR||''''||') '
16619 ||' AND NVL(mls.char8, '||''''||NULL_CHAR||''''||') = '
16620 ||' NVL(msr.from_postal_code_from, '||''''||NULL_CHAR||''''||') '
16621 ||' AND NVL(mls.char9, '||''''||NULL_CHAR||''''||') = '
16622 ||' NVL(msr.from_postal_code_to, '||''''||NULL_CHAR||''''||') '
16623 ||' AND NVL(mls.char10, '||''''||NULL_CHAR||''''||') = '
16624 ||' NVL(msr.from_zone, '||''''||NULL_CHAR||''''||') '
16625 ||' AND mls.entity_name = ''REGION_ID'' )'
16626 ||' WHERE process_flag = '||G_IN_PROCESS
16627 ||' AND NVL(batch_id,'||NULL_VALUE||') = :lv_batch_id'
16628 ||' AND sr_instance_code = :v_instance_code';
16629
16630
16631 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
16632
16633
16634 EXECUTE IMMEDIATE lv_sql_stmt
16635 USING lv_batch_id,
16636 v_instance_code;
16637
16638 -- Derive to_region_id
16639
16640 lv_sql_stmt :=
16641 'UPDATE msc_st_interorg_ship_methods msr'
16642 ||' SET to_region_id = (SELECT local_id'
16643 ||' FROM msc_local_id_setup mls'
16644 ||' WHERE mls.char1 = msr.sr_instance_code'
16645 ||' AND mls.number1 = nvl(msr.to_region_type,'||NULL_VALUE||')'
16646 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
16647 ||' NVL(msr.to_country, '||''''||NULL_CHAR||''''||') '
16648 ||' AND NVL(mls.char3, '||''''||NULL_CHAR||''''||') = '
16649 ||' NVL(msr.to_country_code, '||''''||NULL_CHAR||''''||') '
16650 ||' AND NVL(mls.char4, '||''''||NULL_CHAR||''''||') = '
16651 ||' NVL(msr.to_state, '||''''||NULL_CHAR||''''||') '
16652 ||' AND NVL(mls.char5, '||''''||NULL_CHAR||''''||') = '
16653 ||' NVL(msr.to_state_code, '||''''||NULL_CHAR||''''||') '
16654 ||' AND NVL(mls.char6, '||''''||NULL_CHAR||''''||') = '
16655 ||' NVL(msr.to_city, '||''''||NULL_CHAR||''''||') '
16656 ||' AND NVL(mls.char7, '||''''||NULL_CHAR||''''||') = '
16657 ||' NVL(msr.to_city_code, '||''''||NULL_CHAR||''''||') '
16658 ||' AND NVL(mls.char8, '||''''||NULL_CHAR||''''||') = '
16659 ||' NVL(msr.to_postal_code_from, '||''''||NULL_CHAR||''''||') '
16660 ||' AND NVL(mls.char9, '||''''||NULL_CHAR||''''||') = '
16661 ||' NVL(msr.to_postal_code_to, '||''''||NULL_CHAR||''''||') '
16662 ||' AND NVL(mls.char10, '||''''||NULL_CHAR||''''||') = '
16663 ||' NVL(msr.to_zone, '||''''||NULL_CHAR||''''||') '
16664 ||' AND mls.entity_name = ''REGION_ID'' )'
16665 ||' WHERE process_flag = '||G_IN_PROCESS
16666 ||' AND NVL(batch_id,'||NULL_VALUE||') = :lv_batch_id'
16667 ||' AND sr_instance_code = :v_instance_code';
16668
16669
16670 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
16671
16672
16673 EXECUTE IMMEDIATE lv_sql_stmt
16674 USING lv_batch_id,
16675 v_instance_code;
16676
16677
16678 -- records should either have organization id's populated or location id's populated or both.
16679
16680 -- Set the message
16681
16682 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
16683 (p_app_short_name => 'MSC',
16684 p_error_code => 'MSC_PP_INVALID_VALUE',
16685 p_message_text => lv_message_text,
16686 p_error_text => lv_error_text,
16687 p_token1 => 'COLUMN_NAME',
16688 p_token_value1 => 'TO_ORGANIZATION_CODE OR '
16689 ||'FROM_ORGANIZATION_CODE OR '
16690 ||'TO_LOCATION_CODE OR '
16691 ||'FROM_LOCATION_CODE OR '
16692 ||'TO_REGION_CODE OR '
16693 ||'FROM_REGION_CODE ');
16694
16695 IF lv_return <> 0 THEN
16696 RAISE ex_logging_err;
16697 END IF;
16698
16699
16700 v_sql_stmt := 9.1;
16701 lv_sql_stmt :=
16702 'UPDATE msc_st_interorg_ship_methods msis1'
16703 ||' SET process_flag = '||G_ERROR_FLG||','
16704 ||' error_text = '||''''||lv_message_text||''''
16705 ||' WHERE (msis1.to_location_id is NULL OR msis1.from_location_id is NULL) '
16706 ||' AND (msis1.to_organization_id is NULL OR msis1.from_organization_id is NULL) '
16707 ||' AND (msis1.to_region_id is NULL OR msis1.from_region_id is NULL) '
16708 ||' AND msis1.batch_id = :lv_batch_id'
16709 ||' AND msis1.process_flag = '||G_IN_PROCESS
16710 ||' AND msis1.sr_instance_code = :v_instance_code' ;
16711
16712
16713 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
16714
16715
16716 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,
16717 v_instance_code;
16718
16719
16720 -- Set the message
16721 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
16722 (p_app_short_name => 'MSC',
16723 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
16724 p_message_text => lv_message_text,
16725 p_error_text => lv_error_text,
16726 p_token1 => 'COLUMN_NAME',
16727 p_token_value1 => 'DEFAULT_FLAG',
16728 p_token2 => 'DEFAULT_VALUE',
16729 p_token_value2 => SYS_NO);
16730 -- Check DEFAULT_FLAG column has valid value or not and if not set it to SYS_NO
16731
16732 lv_where_str := ' AND NVL(default_flag,'||NULL_VALUE||') '
16733 ||' NOT IN(1,2)';
16734
16735 lv_return := MSC_ST_UTIL.LOG_ERROR
16736 (p_table_name => 'MSC_ST_INTERORG_SHIP_METHODS',
16737 p_instance_code => v_instance_code,
16738 p_row => lv_column_names,
16739 p_severity => G_SEV_WARNING,
16740 p_message_text => lv_message_text,
16741 p_error_text => lv_error_text,
16742 p_batch_id => lv_batch_id,
16743 p_where_str => lv_where_str,
16744 p_col_name => 'DEFAULT_FLAG',
16745 p_debug => v_debug,
16746 p_default_value => SYS_NO);
16747
16748 IF lv_return <> 0 THEN
16749 RAISE ex_logging_err;
16750 END IF;
16751
16752
16753 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
16754 (p_app_short_name => 'MSC',
16755 p_error_code => 'MSC_PP_DEFAULT_SHIP_METHOD',
16756 p_message_text => lv_message_text,
16757 p_error_text => lv_error_text,
16758 p_token1 => 'FROM_ORGANIZATION',
16759 p_token_value1 => 'FROM_ORGANIZATION_CODE, FROM_LOCATION_CODE, FROM_REGION_CODE',
16760 p_token2 => 'TO_ORGANIZATION',
16761 p_token_value2 => 'TO_ORGANIZATION, TO_LOCATION_CODE, TO_REGION_CODE');
16762
16763 IF lv_return <> 0 THEN
16764 RAISE ex_logging_err;
16765 END IF;
16766
16767 -- Check that only one ship method has default flag set as yes
16768 -- in ODS as well as staging
16769 -- forward ported 2767559
16770
16771 v_sql_stmt := 12;
16772 lv_sql_stmt :=
16773 'UPDATE msc_st_interorg_ship_methods msis1'
16774 ||' SET process_flag = '||G_ERROR_FLG||','
16775 ||' error_text = '||''''||lv_message_text||''''
16776 ||' WHERE EXISTS( SELECT 1 '
16777 ||' FROM msc_st_interorg_ship_methods msis2'
16778 ||' WHERE msis2.sr_instance_code = msis1.sr_instance_code'
16779 ||' AND nvl(msis2.from_organization_code, '||''''||NULL_CHAR||''''||') = '
16780 ||' nvl(msis1.from_organization_code, '||''''||NULL_CHAR||''''||')'
16781 ||' AND nvl(msis2.to_organization_code, '||''''||NULL_CHAR||''''||') = '
16782 ||' nvl(msis1.to_organization_code, '||''''||NULL_CHAR||''''||')'
16783 ||' AND nvl(msis2.from_location_code, '||''''||NULL_CHAR||''''||') = '
16784 ||' nvl(msis1.from_location_code, '||''''||NULL_CHAR||''''||')'
16785 ||' AND nvl(msis2.to_location_code, '||''''||NULL_CHAR||''''||') = '
16786 ||' nvl(msis1.to_location_code, '||''''||NULL_CHAR||''''||')'
16787 ||' AND nvl(msis2.from_region_id, '||NULL_VALUE||') = '
16788 ||' nvl(msis1.from_region_id, '||NULL_VALUE||')'
16789 ||' AND nvl(msis2.to_region_id, '||NULL_VALUE||') = '
16790 ||' nvl(msis1.to_region_id, '||NULL_VALUE||')'
16791 ||' AND msis2.process_flag IN (2,5)'
16792 ||' AND msis2.default_flag = '||SYS_YES
16793 ||' AND msis2.rowid <> msis1.rowid'
16794 ||' UNION'
16795 ||' SELECT 1 '
16796 ||' FROM msc_interorg_ship_methods msis3 '
16797 ||' WHERE msis3.sr_instance_id = :v_instance_id'
16798 ||' AND nvl(msis3.from_organization_id, '||''''||NULL_CHAR||''''||') = '
16799 ||' nvl(msis1.from_organization_id, '||''''||NULL_CHAR||''''||')'
16800 ||' AND nvl(msis3.to_organization_id, '||''''||NULL_CHAR||''''||') = '
16801 ||' nvl(msis1.to_organization_id, '||''''||NULL_CHAR||''''||')'
16802 ||' AND nvl(msis3.from_location_id, '||''''||NULL_CHAR||''''||') = '
16803 ||' nvl(msis1.from_location_id, '||''''||NULL_CHAR||''''||')'
16804 ||' AND nvl(msis3.to_location_id, '||''''||NULL_CHAR||''''||') = '
16805 ||' nvl(msis1.to_location_id, '||''''||NULL_CHAR||''''||')'
16806 ||' AND nvl(msis3.from_region_id, '||''''||NULL_CHAR||''''||') = '
16807 ||' nvl(msis1.from_region_id, '||''''||NULL_CHAR||''''||')'
16808 ||' AND nvl(msis3.to_region_id, '||''''||NULL_CHAR||''''||') = '
16809 ||' nvl(msis1.to_region_id, '||''''||NULL_CHAR||''''||')'
16810 ||' AND msis3.plan_id = -1 '
16811 ||' AND msis3.default_flag = '||SYS_YES||')'
16812 ||' AND msis1.default_flag = '||SYS_YES
16813 ||' AND msis1.batch_id = :lv_batch_id'
16814 ||' AND msis1.process_flag = '||G_IN_PROCESS
16815 ||' AND msis1.sr_instance_code = :v_instance_code' ;
16816
16817
16818 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
16819
16820
16821 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_id,
16822 lv_batch_id,
16823 v_instance_code;
16824
16825 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
16826 (p_app_short_name => 'MSC',
16827 p_error_code => 'MSC_PP_INVALID_VALUE',
16828 p_message_text => lv_message_text,
16829 p_error_text => lv_error_text,
16830 p_token1 => 'COLUMN_NAME',
16831 p_token_value1 => 'VOLUME_UOM');
16832
16833 IF lv_return <> 0 THEN
16834 RAISE ex_logging_err;
16835 END IF;
16836
16837 -- Validate Volume UOM
16838
16839 lv_return :=
16840 MSC_ST_UTIL.VALIDATE_UOM (p_table_name => 'MSC_ST_INTERORG_SHIP_METHODS',
16841 p_uom_col_name => 'VOLUME_UOM',
16842 p_instance_id => v_instance_id,
16843 p_instance_code => v_instance_code,
16844 p_severity => G_SEV3_ERROR,
16845 p_message_text => lv_message_text,
16846 p_batch_id => lv_batch_id,
16847 p_debug => v_debug,
16848 p_error_text => lv_error_text);
16849
16850 if(lv_return <> 0) then
16851 RAISE ex_logging_err;
16852 end if;
16853
16854 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
16855 (p_app_short_name => 'MSC',
16856 p_error_code => 'MSC_PP_INVALID_VALUE',
16857 p_message_text => lv_message_text,
16858 p_error_text => lv_error_text,
16859 p_token1 => 'COLUMN_NAME',
16860 p_token_value1 => 'WEIGHT_UOM');
16861
16862 IF lv_return <> 0 THEN
16863 RAISE ex_logging_err;
16864 END IF;
16865
16866 -- Validate Weight UOM
16867
16868 lv_return :=
16869 MSC_ST_UTIL.VALIDATE_UOM (p_table_name => 'MSC_ST_INTERORG_SHIP_METHODS',
16870 p_uom_col_name => 'WEIGHT_UOM',
16871 p_instance_id => v_instance_id,
16872 p_instance_code => v_instance_code,
16873 p_severity => G_SEV3_ERROR,
16874 p_message_text => lv_message_text,
16875 p_batch_id => lv_batch_id,
16876 p_debug => v_debug,
16877 p_error_text => lv_error_text);
16878
16879 if(lv_return <> 0) then
16880 RAISE ex_logging_err;
16881 end if;
16882
16883
16884 --Call to customised validation.
16885 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
16886 (ERRBUF => lv_error_text,
16887 RETCODE => lv_return,
16888 pBatchID => lv_batch_id,
16889 pInstanceCode => v_instance_code,
16890 pEntityName => 'MSC_ST_INTERORG_SHIP_METHODS',
16891 pInstanceID => v_instance_id);
16892
16893 IF NVL(lv_return,0) <> 0 THEN
16894 RAISE ex_logging_err;
16895 END IF;
16896
16897
16898 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
16899 (p_table_name => 'MSC_ST_INTERORG_SHIP_METHODS',
16900 p_instance_id => v_instance_id,
16901 p_instance_code => v_instance_code,
16902 p_process_flag => G_VALID,
16903 p_error_text => lv_error_text,
16904 p_debug => v_debug,
16905 p_batch_id => lv_batch_id);
16906
16907 IF lv_return <> 0 THEN
16908 RAISE ex_logging_err;
16909 END IF;
16910
16911 v_sql_stmt := 13;
16912 lv_sql_stmt :=
16913 'UPDATE msc_st_interorg_ship_methods'
16914 ||' SET sr_instance_id2 = '||v_instance_id
16915 ||' WHERE sr_instance_code = :v_instance_code'
16916 ||' AND process_flag ='|| G_VALID
16917 ||' AND batch_id = :lv_batch_id' ;
16918
16919
16920 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
16921
16922
16923 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
16924
16925 lv_return := MSC_ST_UTIL.LOG_ERROR
16926 (p_table_name => 'MSC_ST_INTERORG_SHIP_METHODS',
16927 p_instance_code => v_instance_code,
16928 p_row => lv_column_names,
16929 p_severity => G_SEV_ERROR,
16930 p_message_text => NULL,
16931 p_error_text => lv_error_text,
16932 p_debug => v_debug,
16933 p_batch_id => lv_batch_id);
16934 IF lv_return <> 0 THEN
16935 RAISE ex_logging_err;
16936 END IF;
16937 COMMIT;
16938 END LOOP;
16939
16940 EXCEPTION
16941 WHEN too_many_rows THEN
16942 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_SHIP_METHODS'||'('
16943 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
16944 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
16945 ROLLBACK;
16946
16947 WHEN ex_logging_err THEN
16948 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
16949 ROLLBACK;
16950
16951 WHEN OTHERS THEN
16952 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_SHIP_METHODS'||'('
16953 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
16954 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
16955 ROLLBACK;
16956
16957 END LOAD_SHIP_METHODS ;
16958
16959
16960 /*=============================================================================+
16961 | DESCRIPTION : This procedure validates the data for REGIONS, ZONES, Region |
16962 | locations and region sites |
16963 +==============================================================================*/
16964
16965 PROCEDURE LOAD_REGIONS IS
16966 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
16967 TYPE CurTyp IS REF CURSOR;
16968 c1 CurTyp;
16969 lb_rowid RowidTab; --bulk collects rowid
16970 lv_return NUMBER;
16971 lv_error_text VARCHAR2(250);
16972 lv_where_str VARCHAR2(5000);
16973 lv_sql_stmt VARCHAR2(5000);
16974 lv_column_names VARCHAR2(5000); --stores concatenated column names
16975 lv_batch_id msc_st_regions.batch_id%TYPE;
16976 lv_message_text msc_errors.error_text%TYPE;
16977 lv_cursor_stmt VARCHAR2(5000);
16978
16979 ex_logging_err EXCEPTION;
16980
16981 CURSOR c2(p_batch_id NUMBER) IS
16982 SELECT rowid
16983 FROM msc_st_regions
16984 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
16985 AND sr_instance_code = v_instance_code
16986 AND batch_id = p_batch_id;
16987
16988
16989 CURSOR c3(p_batch_id NUMBER) IS
16990 SELECT rowid
16991 FROM msc_st_regions
16992 WHERE NVL(region_id,NULL_VALUE) = NULL_VALUE
16993 AND process_flag = G_IN_PROCESS
16994 AND NVL(batch_id,NULL_VALUE) =p_batch_id
16995 AND sr_instance_code = v_instance_code;
16996
16997 CURSOR c4(p_batch_id NUMBER) IS
16998 SELECT rowid
16999 FROM msc_st_zone_regions
17000 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
17001 AND sr_instance_code = v_instance_code
17002 AND batch_id = p_batch_id;
17003
17004 CURSOR c5(p_batch_id NUMBER) IS
17005 SELECT rowid
17006 FROM msc_st_zone_regions
17007 WHERE NVL(zone_region_id,NULL_VALUE) = NULL_VALUE
17008 AND process_flag = G_IN_PROCESS
17009 AND NVL(batch_id,NULL_VALUE) =p_batch_id
17010 AND sr_instance_code = v_instance_code;
17011
17012 CURSOR c6(p_batch_id NUMBER) IS
17013 SELECT rowid
17014 FROM msc_st_region_locations
17015 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
17016 AND sr_instance_code = v_instance_code
17017 AND batch_id = p_batch_id;
17018
17019 CURSOR c7(p_batch_id NUMBER) IS
17020 SELECT max(rowid)
17021 FROM msc_st_region_locations
17022 WHERE process_flag = G_IN_PROCESS
17023 AND deleted_flag = SYS_NO
17024 AND NVL(location_id,NULL_VALUE) = NULL_VALUE
17025 AND sr_instance_code = v_instance_code
17026 AND batch_id = p_batch_id
17027 GROUP BY location_code;
17028
17029 CURSOR c8(p_batch_id NUMBER) IS
17030 SELECT rowid
17031 FROM msc_st_region_sites
17032 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
17033 AND sr_instance_code = v_instance_code
17034 AND batch_id = p_batch_id;
17035
17036 BEGIN
17037
17038 --Getting the error message text
17039 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
17040 (p_app_short_name => 'MSC',
17041 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
17042 p_message_text => lv_message_text,
17043 p_error_text => lv_error_text);
17044
17045 IF lv_return <> 0 THEN
17046 RAISE ex_logging_err;
17047 END IF;
17048
17049 --Duplicate records check for the records whose source is XML
17050 v_sql_stmt := 01;
17051 lv_sql_stmt :=
17052 'UPDATE msc_st_regions msr1 '
17053 ||' SET process_flag = '||G_ERROR_FLG||','
17054 ||' error_text = '||''''||lv_message_text||''''
17055 ||' WHERE message_id < (SELECT MAX(message_id)'
17056 ||' FROM msc_st_regions msr2'
17057 ||' WHERE msr2.sr_instance_code = msr1.sr_instance_code'
17058 ||' AND msr2.region_type = msr1.region_type'
17059 ||' AND NVL(msr2.company_name, '||''''||NULL_CHAR||''''||') = '
17060 ||' NVL(msr1.company_name, '||''''||NULL_CHAR||''''||')'
17061 ||' AND NVL(msr2.country, '||''''||NULL_CHAR||''''||') = '
17062 ||' NVL(msr1.country, '||''''||NULL_CHAR||''''||')'
17063 ||' AND NVL(msr2.country_code, '||''''||NULL_CHAR||''''||') = '
17064 ||' NVL(msr1.country_code, '||''''||NULL_CHAR||''''||')'
17065 ||' AND NVL(msr2.state, '||''''||NULL_CHAR||''''||') = '
17066 ||' NVL(msr1.state, '||''''||NULL_CHAR||''''||')'
17067 ||' AND NVL(msr2.state_code, '||''''||NULL_CHAR||''''||') = '
17068 ||' NVL(msr1.state_code, '||''''||NULL_CHAR||''''||')'
17069 ||' AND NVL(msr2.city, '||''''||NULL_CHAR||''''||') = '
17070 ||' NVL(msr1.city, '||''''||NULL_CHAR||''''||')'
17071 ||' AND NVL(msr2.city_code, '||''''||NULL_CHAR||''''||') = '
17072 ||' NVL(msr1.city_code, '||''''||NULL_CHAR||''''||')'
17073 ||' AND NVL(msr2.postal_code_from, '||''''||NULL_CHAR||''''||') = '
17074 ||' NVL(msr1.postal_code_from, '||''''||NULL_CHAR||''''||')'
17075 ||' AND NVL(msr2.postal_code_to, '||''''||NULL_CHAR||''''||') = '
17076 ||' NVL(msr1.postal_code_to, '||''''||NULL_CHAR||''''||')'
17077 ||' AND NVL(msr2.zone, '||''''||NULL_CHAR||''''||') = '
17078 ||' NVL(msr1.zone, '||''''||NULL_CHAR||''''||')'
17079 ||' AND msr2.process_flag ='|| G_IN_PROCESS
17080 ||' AND NVL(msr2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
17081 ||' AND msr1.process_flag = '||G_IN_PROCESS
17082 ||' AND msr1.sr_instance_code = :v_instance_code'
17083 ||' AND NVL(msr1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
17084
17085
17086 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
17087
17088
17089 EXECUTE IMMEDIATE lv_sql_stmt
17090 USING v_instance_code;
17091
17092
17093 /* v_sql_stmt := 1.1;
17094 lv_sql_stmt :=
17095 'UPDATE msc_st_regions msr1 '
17096 ||' SET process_flag = '||G_ERROR_FLG||','
17097 ||' error_text = '||''''||lv_message_text||''''
17098 ||' WHERE message_id < (SELECT MAX(message_id)'
17099 ||' FROM msc_st_regions msr2'
17100 ||' WHERE msr2.sr_instance_code = msr1.sr_instance_code'
17101 ||' AND msr2.region_type = msr1.region_type'
17102 ||' AND NVL(msr2.company_name, '||''''||NULL_CHAR||''''||') = '
17103 ||' NVL(msr1.company_name, '||''''||NULL_CHAR||''''||')'
17104 ||' AND NVL(msr2.zone, '||''''||NULL_CHAR||''''||') = '
17105 ||' NVL(msr1.zone, '||''''||NULL_CHAR||''''||')'
17106 ||' AND msr2.process_flag ='|| G_IN_PROCESS
17107 ||' AND msr2.region_type in (10,11) '
17108 ||' AND NVL(msr2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
17109 ||' AND msr1.process_flag = '||G_IN_PROCESS
17110 ||' AND msr1.sr_instance_code = :v_instance_code'
17111 ||' AND msr1.region_type in (10,11) '
17112 ||' AND NVL(msr1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
17113
17114 IF V_DEBUG THEN
17115 msc_st_util.log_message(lv_sql_stmt);
17116 END IF;
17117
17118 EXECUTE IMMEDIATE lv_sql_stmt
17119 USING v_instance_code; */
17120
17121
17122 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
17123 (p_app_short_name => 'MSC',
17124 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
17125 p_message_text => lv_message_text,
17126 p_error_text => lv_error_text);
17127
17128 IF lv_return <> 0 THEN
17129 RAISE ex_logging_err;
17130 END IF;
17131
17132 --Duplicate records check for the records whose source is other than XML
17133 --Different SQL is used because in XML we can identify the latest records
17134 --whereas in batch load we cannot.
17135 v_sql_stmt := 02;
17136 lv_sql_stmt :=
17137 'UPDATE msc_st_regions msr1'
17138 ||' SET process_flag = '||G_ERROR_FLG||','
17139 ||' error_text = '||''''||lv_message_text||''''
17140 ||' WHERE EXISTS( SELECT 1 '
17141 ||' FROM msc_st_regions msr2'
17142 ||' WHERE msr2.sr_instance_code = msr1.sr_instance_code'
17143 ||' AND msr2.region_type = msr1.region_type'
17144 ||' AND NVL(msr2.company_name, '||''''||NULL_CHAR||''''||') = '
17145 ||' NVL(msr1.company_name, '||''''||NULL_CHAR||''''||')'
17146 ||' AND NVL(msr2.country, '||''''||NULL_CHAR||''''||') = '
17147 ||' NVL(msr1.country, '||''''||NULL_CHAR||''''||')'
17148 ||' AND NVL(msr2.country_code, '||''''||NULL_CHAR||''''||') = '
17149 ||' NVL(msr1.country_code, '||''''||NULL_CHAR||''''||')'
17150 ||' AND NVL(msr2.state, '||''''||NULL_CHAR||''''||') = '
17151 ||' NVL(msr1.state, '||''''||NULL_CHAR||''''||')'
17152 ||' AND NVL(msr2.state_code, '||''''||NULL_CHAR||''''||') = '
17153 ||' NVL(msr1.state_code, '||''''||NULL_CHAR||''''||')'
17154 ||' AND NVL(msr2.city, '||''''||NULL_CHAR||''''||') = '
17155 ||' NVL(msr1.city, '||''''||NULL_CHAR||''''||')'
17156 ||' AND NVL(msr2.city_code, '||''''||NULL_CHAR||''''||') = '
17157 ||' NVL(msr1.city_code, '||''''||NULL_CHAR||''''||')'
17158 ||' AND NVL(msr2.postal_code_from, '||''''||NULL_CHAR||''''||') = '
17159 ||' NVL(msr1.postal_code_from, '||''''||NULL_CHAR||''''||')'
17160 ||' AND NVL(msr2.postal_code_to, '||''''||NULL_CHAR||''''||') = '
17161 ||' NVL(msr1.postal_code_to, '||''''||NULL_CHAR||''''||')'
17162 ||' AND NVL(msr2.zone, '||''''||NULL_CHAR||''''||') = '
17163 ||' NVL(msr1.zone, '||''''||NULL_CHAR||''''||')'
17164 ||' AND msr2.process_flag = '||G_IN_PROCESS
17165 ||' GROUP BY sr_instance_code, region_type, company_name,country,country_code, state, state_code, city, city_code, postal_code_from, postal_code_to, zone'
17166 ||' HAVING COUNT(*) > 1)'
17167 ||' AND msr1.process_flag = '||G_IN_PROCESS
17168 ||' AND msr1.sr_instance_code = :v_instance_code'
17169 ||' AND NVL(msr1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
17170
17171
17172 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
17173
17174
17175 EXECUTE IMMEDIATE lv_sql_stmt
17176 USING v_instance_code;
17177
17178
17179
17180 lv_column_names :=
17181 'REGION_TYPE ||''~''||'
17182 ||' COUNTRY ||''~''||'
17183 ||' COUNTRY_CODE ||''~''||'
17184 ||' STATE_CODE ||''~''||'
17185 ||' SR_INSTANCE_CODE ||''~''||'
17186 ||' STATE ||''~''||'
17187 ||' CITY ||''~''||'
17188 ||' CITY_CODE ||''~''||'
17189 ||' POSTAL_CODE_FROM ||''~''||'
17190 ||' POSTAL_CODE_TO ||''~''||'
17191 ||' ZONE ||''~''||'
17192 ||' DELETED_FLAG ||''~''||'
17193 ||' COMPANY_NAME ' ;
17194
17195 -- Now processing by batch
17196 LOOP
17197 v_sql_stmt := 03;
17198 lv_cursor_stmt :=
17199 ' SELECT msc_st_batch_id_s.NEXTVAL '
17200 ||' FROM dual';
17201
17202 OPEN c1 FOR lv_cursor_stmt;
17203 FETCH c1 INTO lv_batch_id;
17204 CLOSE c1;
17205
17206 v_sql_stmt := 04;
17207 lv_sql_stmt :=
17208 ' UPDATE msc_st_regions '
17209 ||' SET batch_id = :lv_batch_id'
17210 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
17211 ||' AND sr_instance_code = :v_instance_code'
17212 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
17213 ||' AND rownum <= '||v_batch_size;
17214
17215
17216 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
17217
17218
17219 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
17220
17221 EXIT WHEN SQL%NOTFOUND;
17222
17223 OPEN c2(lv_batch_id);
17224 FETCH c2 BULK COLLECT INTO lb_rowid;
17225 CLOSE c2;
17226
17227 v_sql_stmt := 05;
17228 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
17229 UPDATE msc_st_regions
17230 SET st_transaction_id = msc_st_regions_s.NEXTVAL,
17231 refresh_number = v_refresh_id,
17232 last_update_date = v_current_date,
17233 last_updated_by = v_current_user,
17234 creation_date = v_current_date,
17235 created_by = v_current_user
17236 WHERE rowid = lb_rowid(j);
17237
17238 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
17239 (p_app_short_name => 'MSC',
17240 p_error_code => 'MSC_PP_NO_DELETION',
17241 p_message_text => lv_message_text,
17242 p_error_text => lv_error_text,
17243 p_token1 => 'TABLE_NAME',
17244 p_token_value1 => 'MSC_ST_REGIONS');
17245
17246
17247 -- Deletion is not allowed for this table
17248 v_sql_stmt := 06;
17249 lv_sql_stmt :=
17250 'UPDATE msc_st_regions '
17251 ||' SET process_flag = '||G_ERROR_FLG||','
17252 ||' error_text = '||''''||lv_message_text||''''
17253 ||' WHERE deleted_flag = '||SYS_YES
17254 ||' AND process_flag = '||G_IN_PROCESS
17255 ||' AND batch_id = :lv_batch_id'
17256 ||' AND sr_instance_code = :v_instance_code';
17257
17258
17259 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
17260
17261
17262 EXECUTE IMMEDIATE lv_sql_stmt
17263 USING lv_batch_id,
17264 v_instance_code;
17265
17266 -- set the message
17267
17268 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
17269 (p_app_short_name => 'MSC',
17270 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
17271 p_message_text => lv_message_text,
17272 p_error_text => lv_error_text,
17273 p_token1 => 'COLUMN_NAME',
17274 p_token_value1 => 'DELETED_FLAG',
17275 p_token2 => 'DEFAULT_VALUE',
17276 p_token_value2 => SYS_NO);
17277
17278 IF lv_return <> 0 THEN
17279 RAISE ex_logging_err;
17280 END IF;
17281
17282 -- Check DELETED_FLAG column has valid value or not and if not set it to SYS_NO
17283 -- Log error procedure inserts warning and also defaults the deleted flag
17284
17285 lv_where_str := ' AND NVL(deleted_flag,'||NULL_VALUE||') '
17286 ||' NOT IN(1,2)';
17287
17288 lv_return := MSC_ST_UTIL.LOG_ERROR
17289 (p_table_name => 'MSC_ST_REGIONS',
17290 p_instance_code => v_instance_code,
17291 p_row => lv_column_names,
17292 p_severity => G_SEV_WARNING,
17293 p_message_text => lv_message_text,
17294 p_error_text => lv_error_text,
17295 p_batch_id => lv_batch_id,
17296 p_where_str => lv_where_str,
17297 p_col_name => 'DELETED_FLAG',
17298 p_debug => v_debug,
17299 p_default_value => SYS_NO);
17300
17301 IF lv_return <> 0 THEN
17302 RAISE ex_logging_err;
17303 END IF;
17304
17305
17306 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
17307 (p_app_short_name => 'MSC',
17308 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
17309 p_message_text => lv_message_text,
17310 p_error_text => lv_error_text,
17311 p_token1 => 'COLUMN_NAME',
17312 p_token_value1 => 'REGION_TYPE');
17313
17314 IF lv_return <> 0 THEN
17315 RAISE ex_logging_err;
17316 END IF;
17317
17318 lv_sql_stmt :=
17319 'UPDATE msc_st_regions'
17320 ||' SET process_flag ='||G_ERROR_FLG||','
17321 ||' error_text = '||''''||lv_message_text||''''
17322 ||' WHERE region_type NOT IN (0,1,2,3,10) '
17323 ||' AND sr_instance_code = :v_instance_code'
17324 ||' AND process_flag = '||G_IN_PROCESS
17325 ||' AND batch_id = :lv_batch_id';
17326
17327
17328 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
17329
17330 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
17331
17332
17333 lv_sql_stmt :=
17334 ' UPDATE msc_st_regions '
17335 ||' SET parent_region_id = -1'
17336 ||' WHERE process_flag = '||G_IN_PROCESS
17337 ||' AND sr_instance_code = :v_instance_code'
17338 ||' AND region_type in (0,10) '
17339 ||' AND batch_id = :lv_batch_id';
17340
17341
17342 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
17343
17344
17345 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code, lv_batch_id;
17346
17347
17348 -- write message text here
17349
17350 /* lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
17351 (p_app_short_name => 'MSC',
17352 p_error_code => 'MSC_PP_POSTAL_CODE_OVERLAP',
17353 p_message_text => lv_message_text,
17354 p_error_text => lv_error_text);
17355
17356 IF lv_return <> 0 THEN
17357 RAISE ex_logging_err;
17358 END IF;
17359
17360 lv_sql_stmt :=
17361 'UPDATE msc_st_regions msr1'
17362 ||' SET process_flag = '||G_ERROR_FLG||','
17363 ||' error_text = '||''''||lv_message_text||''''
17364 ||' WHERE EXISTS( SELECT 1 '
17365 ||' FROM msc_st_regions msr2'
17366 ||' WHERE msr2.sr_instance_code = msr1.sr_instance_code'
17367 ||' AND msr2.region_type = msr1.region_type'
17368 ||' AND NVL(msr2.country, '||''''||NULL_CHAR||''''||') = '
17369 ||' NVL(msr1.country, '||''''||NULL_CHAR||''''||')'
17370 ||' AND NVL(msr2.country_code, '||''''||NULL_CHAR||''''||') = '
17371 ||' NVL(msr1.country_code, '||''''||NULL_CHAR||''''||')'
17372 ||' AND ((NVL(msr2.postal_code_from, '||''''||NULL_CHAR||''''||') = '
17373 ||' NVL(msr1.postal_code_from, '||''''||NULL_CHAR||''''||')'
17374 ||' AND NVL(msr2.postal_code_to, '||''''||NULL_CHAR||''''||') = '
17375 ||' NVL(msr1.postal_code_to, '||''''||NULL_CHAR||''''||'))'
17376 ||' OR (NVL(msr2.postal_code_from, '||''''||NULL_CHAR||''''||') > '
17377 ||' NVL(msr1.postal_code_from, '||''''||NULL_CHAR||''''||')'
17378 ||' AND NVL(msr2.postal_code_from, '||''''||NULL_CHAR||''''||') < '
17379 ||' NVL(msr1.postal_code_to, '||''''||NULL_CHAR||''''||'))'
17380 ||' OR (NVL(msr2.postal_code_to, '||''''||NULL_CHAR||''''||') > '
17381 ||' NVL(msr1.postal_code_from, '||''''||NULL_CHAR||''''||')'
17382 ||' AND NVL(msr2.postal_code_to, '||''''||NULL_CHAR||''''||') < '
17383 ||' NVL(msr1.postal_code_to, '||''''||NULL_CHAR||''''||')))'
17384 ||' AND msr2.process_flag = '||G_IN_PROCESS
17385 ||' AND NVL(msr2.postal_code_from, '||''''||NULL_CHAR||''''||')'
17386 ||' <> '||''''||NULL_CHAR||''''
17387 ||' AND NVL(msr1.postal_code_from, '||''''||NULL_CHAR||''''||')'
17388 ||' <> '||''''||NULL_CHAR||''''
17389 ||' AND msr2.region_type in (0,1,2,3) '
17390 ||' AND msr1.rowid <> msr2.rowid)'
17391 ||' AND msr1.process_flag = '||G_IN_PROCESS
17392 ||' AND msr1.sr_instance_code = :v_instance_code'
17393 ||' AND msr1.region_type in (0,1,2,3) ';
17394
17395
17396
17397 msc_st_util.log_message(lv_sql_stmt);
17398
17399
17400 EXECUTE IMMEDIATE lv_sql_stmt
17401 USING v_instance_code;
17402
17403 */
17404
17405 --Deriving region_id
17406
17407 lv_sql_stmt :=
17408 'UPDATE msc_st_regions msr'
17409 ||' SET region_id = nvl((SELECT local_id'
17410 ||' FROM msc_local_id_setup mls'
17411 ||' WHERE mls.char1 = msr.sr_instance_code'
17412 ||' AND mls.number1 = msr.region_type'
17413 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
17414 ||' NVL(msr.country, '||''''||NULL_CHAR||''''||') '
17415 ||' AND NVL(mls.char3, '||''''||NULL_CHAR||''''||') = '
17416 ||' NVL(msr.country_code, '||''''||NULL_CHAR||''''||') '
17417 ||' AND NVL(mls.char4, '||''''||NULL_CHAR||''''||') = '
17418 ||' NVL(msr.state, '||''''||NULL_CHAR||''''||') '
17419 ||' AND NVL(mls.char5, '||''''||NULL_CHAR||''''||') = '
17420 ||' NVL(msr.state_code, '||''''||NULL_CHAR||''''||') '
17421 ||' AND NVL(mls.char6, '||''''||NULL_CHAR||''''||') = '
17422 ||' NVL(msr.city, '||''''||NULL_CHAR||''''||') '
17423 ||' AND NVL(mls.char7, '||''''||NULL_CHAR||''''||') = '
17424 ||' NVL(msr.city_code, '||''''||NULL_CHAR||''''||') '
17425 ||' AND NVL(mls.char8, '||''''||NULL_CHAR||''''||') = '
17426 ||' NVL(msr.postal_code_from, '||''''||NULL_CHAR||''''||') '
17427 ||' AND NVL(mls.char9, '||''''||NULL_CHAR||''''||') = '
17428 ||' NVL(msr.postal_code_to, '||''''||NULL_CHAR||''''||') '
17429 ||' AND NVL(mls.char10, '||''''||NULL_CHAR||''''||') = '
17430 ||' NVL(msr.zone, '||''''||NULL_CHAR||''''||') '
17431 ||' AND mls.entity_name = ''REGION_ID'' ), ' ||NULL_VALUE|| ')'
17432 ||' WHERE process_flag = '||G_IN_PROCESS
17433 ||' AND NVL(batch_id,'||NULL_VALUE||') = :lv_batch_id'
17434 ||' AND sr_instance_code = :v_instance_code';
17435
17436
17437 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
17438
17439
17440 EXECUTE IMMEDIATE lv_sql_stmt
17441 USING lv_batch_id,
17442 v_instance_code;
17443
17444
17445 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
17446 (p_app_short_name => 'MSC',
17447 p_error_code => 'MSC_PP_NO_UPDATION',
17448 p_message_text => lv_message_text,
17449 p_error_text => lv_error_text,
17450 p_token1 => 'TABLE_NAME',
17451 p_token_value1 => 'MSC_ST_REGIONS');
17452
17453
17454 -- Error out the record if same region already exists in ODS
17455 -- As we do not allow regions incremental update
17456 -- It has to be purged before loaded again
17457
17458 lv_sql_stmt :=
17459 'UPDATE msc_st_regions msr'
17460 ||' SET msr.process_flag = '||G_ERROR_FLG||','
17461 ||' msr.error_text = '||''''||lv_message_text||''''
17462 ||' WHERE msr.batch_id = :lv_batch_id'
17463 ||' AND msr.sr_instance_code = :v_instance_code'
17464 ||' AND EXISTS ( SELECT 1'
17465 ||' FROM msc_regions mr'
17466 ||' WHERE nvl(msr.region_id,'||NULL_VALUE||') = mr.region_id'
17467 ||' AND mr.sr_instance_id = :v_instance_id)';
17468
17469 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
17470
17471
17472 EXECUTE IMMEDIATE lv_sql_stmt
17473 USING lv_batch_id,
17474 v_instance_code,
17475 v_instance_id;
17476
17477
17478 --Call to customised validation.
17479 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
17480 (ERRBUF => lv_error_text,
17481 RETCODE => lv_return,
17482 pBatchID => lv_batch_id,
17483 pInstanceCode => v_instance_code,
17484 pEntityName => 'MSC_ST_REGIONS',
17485 pInstanceID => v_instance_id);
17486
17487 IF NVL(lv_return,0) <> 0 THEN
17488 RAISE ex_logging_err;
17489 END IF;
17490
17491 --Generation of region_id
17492 OPEN c3(lv_batch_id);
17493 FETCH c3 BULK COLLECT INTO lb_rowid ;
17494
17495 IF c3%ROWCOUNT > 0 THEN
17496 v_sql_stmt := 12;
17497 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
17498 UPDATE msc_st_regions
17499 SET region_id = msc_st_region_id_s.NEXTVAL
17500 WHERE rowid = lb_rowid(j);
17501
17502 v_sql_stmt := 13;
17503 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
17504 INSERT INTO msc_local_id_setup
17505 (local_id,
17506 st_transaction_id,
17507 instance_id,
17508 entity_name,
17509 data_source_type,
17510 char1,
17511 char2,
17512 char3,
17513 char4,
17514 char5,
17515 char6,
17516 char7,
17517 char8,
17518 char9,
17519 char10,
17520 number1,
17521 last_update_date,
17522 last_updated_by,
17523 creation_date,
17524 created_by)
17525 SELECT
17526 region_id,
17527 st_transaction_id,
17528 v_instance_id,
17529 'REGION_ID',
17530 data_source_type,
17531 v_instance_code,
17532 country,
17533 country_code,
17534 state,
17535 state_code,
17536 city,
17537 city_code,
17538 postal_code_from,
17539 postal_code_to,
17540 zone,
17541 region_type,
17542 v_current_date,
17543 v_current_user,
17544 v_current_date,
17545 v_current_user
17546 FROM msc_st_regions
17547 WHERE rowid = lb_rowid(j);
17548
17549 END IF;
17550 CLOSE c3 ;
17551
17552 lv_sql_stmt :=
17553 ' UPDATE msc_st_regions msr1 '
17554 ||' SET parent_region_id = (SELECT msr2.region_id'
17555 ||' FROM msc_st_regions msr2'
17556 ||' WHERE msr2.sr_instance_code = msr1.sr_instance_code '
17557 ||' AND msr2.region_type = msr1.region_type - 1 '
17558 ||' AND NVL(msr2.country, NVL(msr1.country, '||''''||NULL_CHAR||''''||')) = '
17559 ||' NVL(msr1.country, '||''''||NULL_CHAR||''''||') '
17560 ||' AND NVL(msr2.country_code, NVL(msr1.country_code, '||''''||NULL_CHAR||''''||')) = '
17561 ||' NVL(msr1.country_code, '||''''||NULL_CHAR||''''||') '
17562 ||' AND NVL(msr2.state, NVL(msr1.state, '||''''||NULL_CHAR||''''||')) = '
17563 ||' NVL(msr1.state, '||''''||NULL_CHAR||''''||') '
17564 ||' AND NVL(msr2.state_code, NVL(msr1.state_code, '||''''||NULL_CHAR||''''||')) = '
17565 ||' NVL(msr1.state_code, '||''''||NULL_CHAR||''''||') '
17566 ||' AND NVL(msr2.city, NVL(msr1.city, '||''''||NULL_CHAR||''''||')) = '
17567 ||' NVL(msr1.city, '||''''||NULL_CHAR||''''||') '
17568 ||' AND NVL(msr2.city_code, NVL(msr1.city_code, '||''''||NULL_CHAR||''''||')) = '
17569 ||' NVL(msr1.city_code, '||''''||NULL_CHAR||''''||') '
17570 ||' AND msr2.process_flag = '||G_IN_PROCESS
17571 ||' AND msr2.region_type in (0,1,2)) '
17572 ||' WHERE msr1.process_flag = '||G_IN_PROCESS
17573 ||' AND sr_instance_code = :v_instance_code'
17574 ||' AND region_type in (1,2,3) '
17575 ||' AND NVL(parent_region_id, '||NULL_VALUE||')= '|| NULL_VALUE
17576 ||' AND batch_id = :lv_batch_id';
17577
17578
17579 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
17580
17581
17582 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code, lv_batch_id;
17583
17584 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
17585 (p_table_name => 'MSC_ST_REGIONS',
17586 p_instance_id => v_instance_id,
17587 p_instance_code => v_instance_code,
17588 p_process_flag => G_VALID,
17589 p_error_text => lv_error_text,
17590 p_debug => v_debug,
17591 p_batch_id => lv_batch_id);
17592 IF lv_return <> 0 THEN
17593 RAISE ex_logging_err;
17594 END IF;
17595
17596 lv_return := MSC_ST_UTIL.LOG_ERROR
17597 (p_table_name => 'MSC_ST_REGIONS',
17598 p_instance_code => v_instance_code,
17599 p_row => lv_column_names,
17600 p_severity => G_SEV_ERROR,
17601 p_message_text => NULL,
17602 p_error_text => lv_error_text,
17603 p_debug => v_debug,
17604 p_batch_id => lv_batch_id);
17605
17606 IF lv_return <> 0 THEN
17607 RAISE ex_logging_err;
17608 END IF;
17609
17610 lv_sql_stmt :=
17611 ' INSERT INTO MSC_REGIONS '
17612 ||' (REGION_ID,'
17613 ||' REGION_TYPE,'
17614 ||' PARENT_REGION_ID,'
17615 ||' COUNTRY_CODE,'
17616 ||' COUNTRY_REGION_CODE,'
17617 ||' STATE_CODE,'
17618 ||' CITY_CODE,'
17619 ||' PORT_FLAG,'
17620 ||' AIRPORT_FLAG,'
17621 ||' ROAD_TERMINAL_FLAG,'
17622 ||' RAIL_TERMINAL_FLAG,'
17623 ||' LONGITUDE,'
17624 ||' LATITUDE,'
17625 ||' TIMEZONE,'
17626 ||' CONTINENT,'
17627 ||' COUNTRY,'
17628 ||' COUNTRY_REGION,'
17629 ||' STATE,'
17630 ||' CITY,'
17631 ||' ZONE,'
17632 ||' ZONE_LEVEL,'
17633 ||' POSTAL_CODE_FROM,'
17634 ||' POSTAL_CODE_TO,'
17635 ||' ALTERNATE_NAME,'
17636 ||' COUNTY,'
17637 ||' SR_INSTANCE_ID,'
17638 ||' ZONE_USAGE,'
17639 ||' CREATED_BY,'
17640 ||' CREATION_DATE,'
17641 ||' LAST_UPDATED_BY,'
17642 ||' LAST_UPDATE_DATE)'
17643 ||' SELECT distinct '
17644 ||' msr.REGION_ID,'
17645 ||' msr.REGION_TYPE,'
17646 ||' msr.PARENT_REGION_ID,'
17647 ||' msr.COUNTRY_CODE,'
17648 ||' msr.COUNTRY_REGION_CODE,'
17649 ||' msr.STATE_CODE,'
17650 ||' msr.CITY_CODE,'
17651 ||' msr.PORT_FLAG,'
17652 ||' msr.AIRPORT_FLAG,'
17653 ||' msr.ROAD_TERMINAL_FLAG,'
17654 ||' msr.RAIL_TERMINAL_FLAG,'
17655 ||' msr.LONGITUDE,'
17656 ||' msr.LATITUDE,'
17657 ||' msr.TIMEZONE,'
17658 ||' msr.CONTINENT,'
17659 ||' msr.COUNTRY,'
17660 ||' msr.COUNTRY_REGION,'
17661 ||' msr.STATE,'
17662 ||' msr.CITY,'
17663 ||' msr.ZONE,'
17664 ||' msr.ZONE_LEVEL,'
17665 ||' msr.POSTAL_CODE_FROM,'
17666 ||' msr.POSTAL_CODE_TO,'
17667 ||' msr.ALTERNATE_NAME,'
17668 ||' msr.COUNTY,'
17669 ||' msr.SR_INSTANCE_ID,'
17670 ||' msr.ZONE_USAGE,'
17671 ||' msr.CREATED_BY,'
17672 ||' msr.CREATION_DATE,'
17673 ||' msr.LAST_UPDATED_BY,'
17674 ||' msr.LAST_UPDATE_DATE'
17675 ||' FROM MSC_ST_REGIONS msr'
17676 ||' WHERE msr.batch_id = :lv_batch_id'
17677 ||' AND msr.sr_instance_code = :v_instance_code'
17678 ||' AND msr.process_flag = '||G_VALID ;
17679
17680
17681 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
17682
17683
17684 EXECUTE IMMEDIATE lv_sql_stmt
17685 USING lv_batch_id,
17686 v_instance_code;
17687
17688
17689 COMMIT;
17690 END LOOP;
17691
17692 -- Validation for Zone Regions
17693
17694 --Getting the error message text
17695 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
17696 (p_app_short_name => 'MSC',
17697 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
17698 p_message_text => lv_message_text,
17699 p_error_text => lv_error_text);
17700
17701 IF lv_return <> 0 THEN
17702 RAISE ex_logging_err;
17703 END IF;
17704
17705 --Duplicate records check for the records whose source is XML
17706 v_sql_stmt := 01;
17707 lv_sql_stmt :=
17708 'UPDATE msc_st_zone_regions mszr1 '
17709 ||' SET process_flag = '||G_ERROR_FLG||','
17710 ||' error_text = '||''''||lv_message_text||''''
17711 ||' WHERE message_id < (SELECT MAX(message_id)'
17712 ||' FROM msc_st_zone_regions mszr2'
17713 ||' WHERE mszr2.sr_instance_code = mszr1.sr_instance_code'
17714 ||' AND mszr2.zone = mszr1.zone'
17715 ||' AND NVL(mszr2.country, NVL(mszr1.country, '||''''||NULL_CHAR||''''||')) = '
17716 ||' NVL(mszr1.country, NVL(mszr2.country, '||''''||NULL_CHAR||''''||'))'
17717 ||' AND NVL(mszr2.country_code, NVL(mszr1.country_code, '||''''||NULL_CHAR||''''||')) = '
17718 ||' NVL(mszr1.country_code, NVL(mszr2.country_code, '||''''||NULL_CHAR||''''||'))'
17719 ||' AND NVL(mszr2.state, NVL(mszr1.state, '||''''||NULL_CHAR||''''||')) = '
17720 ||' NVL(mszr1.state, NVL(mszr2.state, '||''''||NULL_CHAR||''''||'))'
17721 ||' AND NVL(mszr2.state_code, NVL(mszr1.state_code, '||''''||NULL_CHAR||''''||')) = '
17722 ||' NVL(mszr1.state_code, NVL(mszr2.state_code, '||''''||NULL_CHAR||''''||'))'
17723 ||' AND NVL(mszr2.city, NVL(mszr1.city, '||''''||NULL_CHAR||''''||')) = '
17724 ||' NVL(mszr1.city, NVL(mszr2.city, '||''''||NULL_CHAR||''''||'))'
17725 ||' AND NVL(mszr2.city_code, NVL(mszr1.city_code, '||''''||NULL_CHAR||''''||')) = '
17726 ||' NVL(mszr1.city_code, NVL(mszr2.city_code, '||''''||NULL_CHAR||''''||'))'
17727 ||' AND NVL(mszr2.postal_code_from, NVL(mszr1.postal_code_from, '||''''||NULL_CHAR||''''||')) = '
17728 ||' NVL(mszr1.postal_code_from, NVL(mszr2.postal_code_from, '||''''||NULL_CHAR||''''||'))'
17729 ||' AND NVL(mszr2.postal_code_to, NVL(mszr1.postal_code_to, '||''''||NULL_CHAR||''''||')) = '
17730 ||' NVL(mszr1.postal_code_to, NVL(mszr2.postal_code_to, '||''''||NULL_CHAR||''''||'))'
17731 ||' AND mszr2.process_flag ='|| G_IN_PROCESS
17732 ||' AND NVL(mszr2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
17733 ||' AND mszr1.process_flag = '||G_IN_PROCESS
17734 ||' AND mszr1.sr_instance_code = :v_instance_code'
17735 ||' AND NVL(mszr1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
17736
17737
17738 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
17739
17740 EXECUTE IMMEDIATE lv_sql_stmt
17741 USING v_instance_code;
17742
17743 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
17744 (p_app_short_name => 'MSC',
17745 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
17746 p_message_text => lv_message_text,
17747 p_error_text => lv_error_text);
17748
17749 IF lv_return <> 0 THEN
17750 RAISE ex_logging_err;
17751 END IF;
17752
17753 --Duplicate records check for the records whose source is other than XML
17754 --Different SQL is used because in XML we can identify the latest records
17755 --whereas in batch load we cannot.
17756 v_sql_stmt := 02;
17757 lv_sql_stmt :=
17758 'UPDATE msc_st_zone_regions mszr1'
17759 ||' SET process_flag = '||G_ERROR_FLG||','
17760 ||' error_text = '||''''||lv_message_text||''''
17761 ||' WHERE EXISTS( SELECT 1 '
17762 ||' FROM msc_st_zone_regions mszr2'
17763 ||' WHERE mszr2.sr_instance_code = mszr1.sr_instance_code'
17764 ||' AND mszr2.zone = mszr1.zone'
17765 ||' AND NVL(mszr2.country, NVL(mszr1.country, '||''''||NULL_CHAR||''''||')) = '
17766 ||' NVL(mszr1.country, NVL(mszr2.country, '||''''||NULL_CHAR||''''||'))'
17767 ||' AND NVL(mszr2.country_code, NVL(mszr1.country_code, '||''''||NULL_CHAR||''''||')) = '
17768 ||' NVL(mszr1.country_code, NVL(mszr2.country_code, '||''''||NULL_CHAR||''''||'))'
17769 ||' AND NVL(mszr2.state, NVL(mszr1.state, '||''''||NULL_CHAR||''''||')) = '
17770 ||' NVL(mszr1.state, NVL(mszr2.state, '||''''||NULL_CHAR||''''||'))'
17771 ||' AND NVL(mszr2.state_code, NVL(mszr1.state_code, '||''''||NULL_CHAR||''''||')) = '
17772 ||' NVL(mszr1.state_code, NVL(mszr2.state_code, '||''''||NULL_CHAR||''''||'))'
17773 ||' AND NVL(mszr2.city, NVL(mszr1.city, '||''''||NULL_CHAR||''''||')) = '
17774 ||' NVL(mszr1.city, NVL(mszr2.city, '||''''||NULL_CHAR||''''||'))'
17775 ||' AND NVL(mszr2.city_code, NVL(mszr1.city_code, '||''''||NULL_CHAR||''''||')) = '
17776 ||' NVL(mszr1.city_code, NVL(mszr2.city_code, '||''''||NULL_CHAR||''''||'))'
17777 ||' AND NVL(mszr2.postal_code_from, NVL(mszr1.postal_code_from, '||''''||NULL_CHAR||''''||')) = '
17778 ||' NVL(mszr1.postal_code_from, NVL(mszr2.postal_code_from, '||''''||NULL_CHAR||''''||'))'
17779 ||' AND NVL(mszr2.postal_code_to, NVL(mszr1.postal_code_to, '||''''||NULL_CHAR||''''||')) = '
17780 ||' NVL(mszr1.postal_code_to, NVL(mszr2.postal_code_to, '||''''||NULL_CHAR||''''||'))'
17781 ||' AND mszr2.process_flag = '||G_IN_PROCESS
17782 ||' GROUP BY sr_instance_code, zone, country,country_code, state, state_code, city, city_code, postal_code_from, postal_code_to'
17783 ||' HAVING COUNT(*) > 1)'
17784 ||' AND mszr1.process_flag = '||G_IN_PROCESS
17785 ||' AND mszr1.sr_instance_code = :v_instance_code'
17786 ||' AND NVL(mszr1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
17787
17788
17789 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
17790
17791 EXECUTE IMMEDIATE lv_sql_stmt
17792 USING v_instance_code;
17793
17794 lv_column_names :=
17795 'ZONE ||''~''||'
17796 ||' COUNTRY ||''~''||'
17797 ||' COUNTRY_CODE ||''~''||'
17798 ||' STATE_CODE ||''~''||'
17799 ||' SR_INSTANCE_CODE ||''~''||'
17800 ||' STATE ||''~''||'
17801 ||' CITY ||''~''||'
17802 ||' CITY_CODE ||''~''||'
17803 ||' POSTAL_CODE_FROM ||''~''||'
17804 ||' POSTAL_CODE_TO ||''~''||'
17805 ||'DELETED_FLAG';
17806
17807 LOOP
17808
17809 SELECT msc_st_batch_id_s.NEXTVAL
17810 INTO lv_batch_id
17811 FROM DUAL;
17812
17813 lv_sql_stmt :=
17814 'UPDATE msc_st_zone_regions '
17815 ||' SET batch_id = :lv_batch_id'
17816 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
17817 ||' AND sr_instance_code = :v_instance_code'
17818 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
17819 ||' AND rownum <= '||v_batch_size;
17820
17821
17822 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
17823
17824 EXECUTE IMMEDIATE lv_sql_stmt
17825 USING lv_batch_id,
17826 v_instance_code;
17827
17828 EXIT WHEN SQL%NOTFOUND ;
17829
17830
17831 OPEN c4(lv_batch_id);
17832 FETCH c4 BULK COLLECT INTO lb_rowid;
17833 CLOSE c4;
17834
17835 v_sql_stmt := 05;
17836 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
17837 UPDATE msc_st_zone_regions
17838 SET st_transaction_id = msc_st_zone_regions_s.NEXTVAL,
17839 refresh_number = v_refresh_id,
17840 last_update_date = v_current_date,
17841 last_updated_by = v_current_user,
17842 creation_date = v_current_date,
17843 created_by = v_current_user
17844 WHERE rowid = lb_rowid(j);
17845
17846 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
17847 (p_app_short_name => 'MSC',
17848 p_error_code => 'MSC_PP_NO_DELETION',
17849 p_message_text => lv_message_text,
17850 p_error_text => lv_error_text,
17851 p_token1 => 'TABLE_NAME',
17852 p_token_value1 => 'MSC_ST_ZONE_REGIONS');
17853
17854
17855 -- Deletion is not allowed for this table
17856 v_sql_stmt := 06;
17857 lv_sql_stmt :=
17858 'UPDATE msc_st_zone_regions '
17859 ||' SET process_flag = '||G_ERROR_FLG||','
17860 ||' error_text = '||''''||lv_message_text||''''
17861 ||' WHERE deleted_flag = '||SYS_YES
17862 ||' AND process_flag = '||G_IN_PROCESS
17863 ||' AND batch_id = :lv_batch_id'
17864 ||' AND sr_instance_code = :v_instance_code';
17865
17866
17867 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
17868
17869 EXECUTE IMMEDIATE lv_sql_stmt
17870 USING lv_batch_id,
17871 v_instance_code;
17872
17873 -- set the message
17874
17875 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
17876 (p_app_short_name => 'MSC',
17877 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
17878 p_message_text => lv_message_text,
17879 p_error_text => lv_error_text,
17880 p_token1 => 'COLUMN_NAME',
17881 p_token_value1 => 'DELETED_FLAG',
17882 p_token2 => 'DEFAULT_VALUE',
17883 p_token_value2 => SYS_NO);
17884
17885 IF lv_return <> 0 THEN
17886 RAISE ex_logging_err;
17887 END IF;
17888
17889 -- Check DELETED_FLAG column has valid value or not and if not set it to SYS_NO
17890 -- Log error procedure inserts warning and also defaults the deleted flag
17891
17892 lv_where_str := ' AND NVL(deleted_flag,'||NULL_VALUE||') '
17893 ||' NOT IN(1,2)';
17894
17895 lv_return := MSC_ST_UTIL.LOG_ERROR
17896 (p_table_name => 'MSC_ST_ZONE_REGIONS',
17897 p_instance_code => v_instance_code,
17898 p_row => lv_column_names,
17899 p_severity => G_SEV_WARNING,
17900 p_message_text => lv_message_text,
17901 p_error_text => lv_error_text,
17902 p_batch_id => lv_batch_id,
17903 p_where_str => lv_where_str,
17904 p_col_name => 'DELETED_FLAG',
17905 p_debug => v_debug,
17906 p_default_value => SYS_NO);
17907
17908 IF lv_return <> 0 THEN
17909 RAISE ex_logging_err;
17910 END IF;
17911
17912 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
17913 (p_app_short_name => 'MSC',
17914 p_error_code => 'MSC_PP_COL_VAL_NULL',
17915 p_message_text => lv_message_text,
17916 p_error_text => lv_error_text,
17917 p_token1 => 'COLUMN_NAME',
17918 p_token_value1 => 'ZONE OR COUNTRY OR COUNTRY_CODE');
17919
17920 IF lv_return <> 0 THEN
17921 RAISE ex_logging_err;
17922 END IF;
17923
17924 -- Error out records where zone/country/country_code is NULL
17925
17926 lv_sql_stmt :=
17927 'UPDATE msc_st_zone_regions '
17928 ||' SET process_flag = '||G_ERROR_FLG||','
17929 ||' error_text = '||''''||lv_message_text||''''
17930 ||' WHERE sr_instance_code = :v_instance_code'
17931 ||' AND batch_id = :lv_batch_id'
17932 ||' AND process_flag = '||G_IN_PROCESS
17933 ||' AND (NVL(zone,'||''''||NULL_CHAR||''''||')'
17934 ||' = '||''''||NULL_CHAR||''''
17935 ||' OR NVL(country,'||''''||NULL_CHAR||''''||') '
17936 ||' = '||''''||NULL_CHAR||''''
17937 ||' OR NVL(country_code,'||''''||NULL_CHAR||''''||') '
17938 ||' = '||''''||NULL_CHAR||''''||')';
17939
17940
17941 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
17942
17943 EXECUTE IMMEDIATE lv_sql_stmt
17944 USING v_instance_code,
17945 lv_batch_id;
17946
17947
17948
17949 lv_sql_stmt :=
17950 'UPDATE msc_st_zone_regions mszr'
17951 ||' SET region_id = nvl((SELECT local_id'
17952 ||' FROM msc_local_id_setup mls'
17953 ||' WHERE mls.char1 = mszr.sr_instance_code'
17954 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
17955 ||' NVL(mszr.country, '||''''||NULL_CHAR||''''||') '
17956 ||' AND NVL(mls.char3, '||''''||NULL_CHAR||''''||') = '
17957 ||' NVL(mszr.country_code, '||''''||NULL_CHAR||''''||') '
17958 ||' AND NVL(mls.char4, '||''''||NULL_CHAR||''''||') = '
17959 ||' NVL(mszr.state, '||''''||NULL_CHAR||''''||') '
17960 ||' AND NVL(mls.char5, '||''''||NULL_CHAR||''''||') = '
17961 ||' NVL(mszr.state_code, '||''''||NULL_CHAR||''''||') '
17962 ||' AND NVL(mls.char6, '||''''||NULL_CHAR||''''||') = '
17963 ||' NVL(mszr.city, '||''''||NULL_CHAR||''''||') '
17964 ||' AND NVL(mls.char7, '||''''||NULL_CHAR||''''||') = '
17965 ||' NVL(mszr.city_code, '||''''||NULL_CHAR||''''||') '
17966 ||' AND NVL(mls.char8, '||''''||NULL_CHAR||''''||') = '
17967 ||' NVL(mszr.postal_code_from, '||''''||NULL_CHAR||''''||') '
17968 ||' AND NVL(mls.char9, '||''''||NULL_CHAR||''''||') = '
17969 ||' NVL(mszr.postal_code_to, '||''''||NULL_CHAR||''''||') '
17970 ||' AND mls.number1 in (0,1,2,3) '
17971 ||' AND mls.entity_name = ''REGION_ID'' ), ' ||NULL_VALUE|| ')'
17972 ||' WHERE process_flag = '||G_IN_PROCESS
17973 ||' AND NVL(region_id,'||NULL_VALUE||')= '||NULL_VALUE
17974 ||' AND NVL(batch_id,'||NULL_VALUE||') = :lv_batch_id'
17975 ||' AND sr_instance_code = :v_instance_code';
17976
17977
17978 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
17979
17980 EXECUTE IMMEDIATE lv_sql_stmt
17981 USING lv_batch_id,
17982 v_instance_code;
17983
17984 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
17985 (p_app_short_name => 'MSC',
17986 p_error_code => 'MSC_PP_COL_VAL_NULL',
17987 p_message_text => lv_message_text,
17988 p_error_text => lv_error_text,
17989 p_token1 => 'COLUMN_NAME',
17990 p_token_value1 => 'REGION_ID');
17991
17992 IF lv_return <> 0 THEN
17993 RAISE ex_logging_err;
17994 END IF;
17995
17996 -- Error out records where region_id is null
17997
17998 lv_sql_stmt :=
17999 'UPDATE msc_st_zone_regions '
18000 ||' SET process_flag = '||G_ERROR_FLG||','
18001 ||' error_text = '||''''||lv_message_text||''''
18002 ||' WHERE sr_instance_code = :v_instance_code'
18003 ||' AND batch_id = :lv_batch_id'
18004 ||' AND process_flag = '||G_IN_PROCESS
18005 ||' AND NVL(region_id,'||NULL_VALUE||')= '||NULL_VALUE ;
18006
18007
18008 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
18009
18010 EXECUTE IMMEDIATE lv_sql_stmt
18011 USING v_instance_code,
18012 lv_batch_id;
18013
18014 lv_sql_stmt :=
18015 'UPDATE msc_st_zone_regions mszr'
18016 ||' SET parent_region_id = nvl((SELECT local_id'
18017 ||' FROM msc_local_id_setup mls'
18018 ||' WHERE mls.char1 = mszr.sr_instance_code'
18019 ||' AND NVL(mls.char10, '||''''||NULL_CHAR||''''||') = '
18020 ||' NVL(mszr.zone, '||''''||NULL_CHAR||''''||') '
18021 ||' AND mls.number1 = 10 '
18022 ||' AND mls.entity_name = ''REGION_ID'' ), ' ||NULL_VALUE|| ')'
18023 ||' WHERE process_flag = '||G_IN_PROCESS
18024 ||' AND NVL(batch_id,'||NULL_VALUE||') = :lv_batch_id'
18025 ||' AND NVL(parent_region_id,'||NULL_VALUE||')= '||NULL_VALUE
18026 ||' AND sr_instance_code = :v_instance_code';
18027
18028
18029 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
18030
18031 EXECUTE IMMEDIATE lv_sql_stmt
18032 USING lv_batch_id,
18033 v_instance_code;
18034
18035 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
18036 (p_app_short_name => 'MSC',
18037 p_error_code => 'MSC_PP_COL_VAL_NULL',
18038 p_message_text => lv_message_text,
18039 p_error_text => lv_error_text,
18040 p_token1 => 'COLUMN_NAME',
18041 p_token_value1 => 'PARENT_REGION_ID');
18042
18043 IF lv_return <> 0 THEN
18044 RAISE ex_logging_err;
18045 END IF;
18046
18047 -- Error out records where parent_region_id is null
18048
18049 lv_sql_stmt :=
18050 'UPDATE msc_st_zone_regions '
18051 ||' SET process_flag = '||G_ERROR_FLG||','
18052 ||' error_text = '||''''||lv_message_text||''''
18053 ||' WHERE sr_instance_code = :v_instance_code'
18054 ||' AND batch_id = :lv_batch_id'
18055 ||' AND process_flag = '||G_IN_PROCESS
18056 ||' AND NVL(parent_region_id,'||NULL_VALUE||')= '||NULL_VALUE ;
18057
18058
18059 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
18060
18061 EXECUTE IMMEDIATE lv_sql_stmt
18062 USING v_instance_code,
18063 lv_batch_id;
18064
18065 -- set the default value of party_id to -1
18066
18067 lv_sql_stmt :=
18068 'UPDATE msc_st_zone_regions '
18069 ||' SET party_id = -1 '
18070 ||' WHERE sr_instance_code = :v_instance_code'
18071 ||' AND batch_id = :lv_batch_id'
18072 ||' AND process_flag = '||G_IN_PROCESS
18073 ||' AND NVL(party_id,'||NULL_VALUE||')= '||NULL_VALUE ;
18074
18075
18076 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
18077
18078 EXECUTE IMMEDIATE lv_sql_stmt
18079 USING v_instance_code,
18080 lv_batch_id;
18081
18082
18083 -- Deriving zone_region_id
18084
18085 lv_sql_stmt :=
18086 'UPDATE msc_st_zone_regions mszr'
18087 ||' SET zone_region_id = nvl((SELECT local_id'
18088 ||' FROM msc_local_id_setup mls'
18089 ||' WHERE mls.char1 = mszr.sr_instance_code'
18090 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
18091 ||' NVL(mszr.country, '||''''||NULL_CHAR||''''||') '
18092 ||' AND NVL(mls.char3, '||''''||NULL_CHAR||''''||') = '
18093 ||' NVL(mszr.country_code, '||''''||NULL_CHAR||''''||') '
18094 ||' AND NVL(mls.char4, '||''''||NULL_CHAR||''''||') = '
18095 ||' NVL(mszr.state, '||''''||NULL_CHAR||''''||') '
18096 ||' AND NVL(mls.char5, '||''''||NULL_CHAR||''''||') = '
18097 ||' NVL(mszr.state_code, '||''''||NULL_CHAR||''''||') '
18098 ||' AND NVL(mls.char6, '||''''||NULL_CHAR||''''||') = '
18099 ||' NVL(mszr.city, '||''''||NULL_CHAR||''''||') '
18100 ||' AND NVL(mls.char7, '||''''||NULL_CHAR||''''||') = '
18101 ||' NVL(mszr.city_code, '||''''||NULL_CHAR||''''||') '
18102 ||' AND NVL(mls.char8, '||''''||NULL_CHAR||''''||') = '
18103 ||' NVL(mszr.postal_code_from, '||''''||NULL_CHAR||''''||') '
18104 ||' AND NVL(mls.char9, '||''''||NULL_CHAR||''''||') = '
18105 ||' NVL(mszr.postal_code_to, '||''''||NULL_CHAR||''''||') '
18106 ||' AND NVL(mls.char10, '||''''||NULL_CHAR||''''||') = '
18107 ||' NVL(mszr.zone, '||''''||NULL_CHAR||''''||') '
18108 ||' AND mls.entity_name = ''ZONE_REGION_ID'' ), ' ||NULL_VALUE|| ')'
18109 ||' WHERE process_flag = '||G_IN_PROCESS
18110 ||' AND NVL(batch_id,'||NULL_VALUE||') = :lv_batch_id'
18111 ||' AND sr_instance_code = :v_instance_code';
18112
18113
18114 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
18115
18116 EXECUTE IMMEDIATE lv_sql_stmt
18117 USING lv_batch_id,
18118 v_instance_code;
18119
18120
18121 --Call to customised validation.
18122 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
18123 (ERRBUF => lv_error_text,
18124 RETCODE => lv_return,
18125 pBatchID => lv_batch_id,
18126 pInstanceCode => v_instance_code,
18127 pEntityName => 'MSC_ST_ZONE_REGIONS',
18128 pInstanceID => v_instance_id);
18129
18130 IF NVL(lv_return,0) <> 0 THEN
18131 RAISE ex_logging_err;
18132 END IF;
18133
18134 --Generation of zone_region_id
18135 OPEN c5(lv_batch_id);
18136 FETCH c5 BULK COLLECT INTO lb_rowid ;
18137
18138 IF c5%ROWCOUNT > 0 THEN
18139 v_sql_stmt := 12;
18140 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
18141 UPDATE msc_st_zone_regions
18142 SET zone_region_id = msc_st_zone_region_id_s.NEXTVAL
18143 WHERE rowid = lb_rowid(j);
18144
18145 v_sql_stmt := 13;
18146 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
18147 INSERT INTO msc_local_id_setup
18148 (local_id,
18149 st_transaction_id,
18150 instance_id,
18151 entity_name,
18152 data_source_type,
18153 char1,
18154 char2,
18155 char3,
18156 char4,
18157 char5,
18158 char6,
18159 char7,
18160 char8,
18161 char9,
18162 char10,
18163 last_update_date,
18164 last_updated_by,
18165 creation_date,
18166 created_by)
18167 SELECT
18168 zone_region_id,
18169 st_transaction_id,
18170 v_instance_id,
18171 'ZONE_REGION_ID',
18172 data_source_type,
18173 v_instance_code,
18174 country,
18175 country_code,
18176 state,
18177 state_code,
18178 city,
18179 city_code,
18180 postal_code_from,
18181 postal_code_to,
18182 zone,
18183 v_current_date,
18184 v_current_user,
18185 v_current_date,
18186 v_current_user
18187 FROM msc_st_zone_regions
18188 WHERE rowid = lb_rowid(j);
18189
18190 END IF;
18191 CLOSE c5 ;
18192
18193 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
18194 (p_table_name => 'MSC_ST_ZONE_REGIONS',
18195 p_instance_id => v_instance_id,
18196 p_instance_code => v_instance_code,
18197 p_process_flag => G_VALID,
18198 p_error_text => lv_error_text,
18199 p_debug => v_debug,
18200 p_batch_id => lv_batch_id);
18201 IF lv_return <> 0 THEN
18202 RAISE ex_logging_err;
18203 END IF;
18204
18205 lv_return := MSC_ST_UTIL.LOG_ERROR
18206 (p_table_name => 'MSC_ST_ZONE_REGIONS',
18207 p_instance_code => v_instance_code,
18208 p_row => lv_column_names,
18209 p_severity => G_SEV_ERROR,
18210 p_message_text => NULL,
18211 p_error_text => lv_error_text,
18212 p_debug => v_debug,
18213 p_batch_id => lv_batch_id);
18214
18215 IF lv_return <> 0 THEN
18216 RAISE ex_logging_err;
18217 END IF;
18218
18219 lv_sql_stmt :=
18220 ' INSERT INTO MSC_ZONE_REGIONS '
18221 ||' (ZONE_REGION_ID,'
18222 ||' REGION_ID,'
18223 ||' PARENT_REGION_ID,'
18224 ||' PARTY_ID,'
18225 ||' SR_INSTANCE_ID,'
18226 ||' CREATED_BY,'
18227 ||' CREATION_DATE,'
18228 ||' LAST_UPDATED_BY,'
18229 ||' LAST_UPDATE_DATE)'
18230 ||' SELECT distinct '
18231 ||' msr.ZONE_REGION_ID,'
18232 ||' msr.REGION_ID,'
18233 ||' msr.PARENT_REGION_ID,'
18234 ||' msr.PARTY_ID, '
18235 ||' msr.SR_INSTANCE_ID,'
18236 ||' msr.CREATED_BY,'
18237 ||' msr.CREATION_DATE,'
18238 ||' msr.LAST_UPDATED_BY,'
18239 ||' msr.LAST_UPDATE_DATE'
18240 ||' FROM MSC_ST_ZONE_REGIONS msr'
18241 ||' WHERE msr.batch_id = :lv_batch_id'
18242 ||' AND msr.sr_instance_code = :v_instance_code'
18243 ||' AND msr.process_flag = '||G_VALID
18244 ||' AND NOT EXISTS'
18245 ||' ( SELECT 1 FROM MSC_ZONE_REGIONS mzr'
18246 ||' WHERE mzr.zone_region_id = msr.zone_region_id'
18247 ||' AND mzr.sr_instance_id = ' ||v_instance_id ||')';
18248
18249
18250 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
18251
18252
18253 EXECUTE IMMEDIATE lv_sql_stmt
18254 USING lv_batch_id,
18255 v_instance_code;
18256
18257 COMMIT;
18258 END LOOP;
18259
18260 -- validation for Region Locations
18261
18262 --Getting the error message text
18263 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
18264 (p_app_short_name => 'MSC',
18265 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
18266 p_message_text => lv_message_text,
18267 p_error_text => lv_error_text);
18268
18269 IF lv_return <> 0 THEN
18270 RAISE ex_logging_err;
18271 END IF;
18272
18273 --Duplicate records check for the records whose source is XML
18274 v_sql_stmt := 01;
18275 lv_sql_stmt :=
18276 'UPDATE msc_st_region_locations msr1 '
18277 ||' SET process_flag = '||G_ERROR_FLG||','
18278 ||' error_text = '||''''||lv_message_text||''''
18279 ||' WHERE message_id < (SELECT MAX(message_id)'
18280 ||' FROM msc_st_region_locations msr2'
18281 ||' WHERE msr2.sr_instance_code = msr1.sr_instance_code'
18282 ||' AND NVL(msr2.region_type, '||NULL_VALUE||') = NVL(msr1.region_type, '||NULL_VALUE||')'
18283 ||' AND NVL(msr2.company_name, '||''''||NULL_CHAR||''''||') = '
18284 ||' NVL(msr1.company_name, '||''''||NULL_CHAR||''''||')'
18285 ||' AND NVL(msr2.country, '||''''||NULL_CHAR||''''||') = '
18286 ||' NVL(msr1.country, '||''''||NULL_CHAR||''''||')'
18287 ||' AND NVL(msr2.country_code, '||''''||NULL_CHAR||''''||') = '
18288 ||' NVL(msr1.country_code, '||''''||NULL_CHAR||''''||')'
18289 ||' AND NVL(msr2.state, '||''''||NULL_CHAR||''''||') = '
18290 ||' NVL(msr1.state, '||''''||NULL_CHAR||''''||')'
18291 ||' AND NVL(msr2.state_code, '||''''||NULL_CHAR||''''||') = '
18292 ||' NVL(msr1.state_code, '||''''||NULL_CHAR||''''||')'
18293 ||' AND NVL(msr2.city, '||''''||NULL_CHAR||''''||') = '
18294 ||' NVL(msr1.city, '||''''||NULL_CHAR||''''||')'
18295 ||' AND NVL(msr2.city_code, '||''''||NULL_CHAR||''''||') = '
18296 ||' NVL(msr1.city_code, '||''''||NULL_CHAR||''''||')'
18297 ||' AND NVL(msr2.postal_code_from, '||''''||NULL_CHAR||''''||') = '
18298 ||' NVL(msr1.postal_code_from, '||''''||NULL_CHAR||''''||')'
18299 ||' AND NVL(msr2.postal_code_to, '||''''||NULL_CHAR||''''||') = '
18300 ||' NVL(msr1.postal_code_to, '||''''||NULL_CHAR||''''||')'
18301 ||' AND NVL(msr2.location_code, '||''''||NULL_CHAR||''''||') = '
18302 ||' NVL(msr1.location_code, '||''''||NULL_CHAR||''''||')'
18303 ||' AND msr2.process_flag ='|| G_IN_PROCESS
18304 ||' AND NVL(msr2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
18305 ||' AND msr1.process_flag = '||G_IN_PROCESS
18306 ||' AND msr1.sr_instance_code = :v_instance_code'
18307 ||' AND NVL(msr1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
18308
18309
18310 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
18311
18312 EXECUTE IMMEDIATE lv_sql_stmt
18313 USING v_instance_code;
18314
18315
18316 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
18317 (p_app_short_name => 'MSC',
18318 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
18319 p_message_text => lv_message_text,
18320 p_error_text => lv_error_text);
18321
18322 IF lv_return <> 0 THEN
18323 RAISE ex_logging_err;
18324 END IF;
18325
18326 --Duplicate records check for the records whose source is other than XML
18327 --Different SQL is used because in XML we can identify the latest records
18328 --whereas in batch load we cannot.
18329 v_sql_stmt := 02;
18330 lv_sql_stmt :=
18331 'UPDATE msc_st_region_locations msr1'
18332 ||' SET process_flag = '||G_ERROR_FLG||','
18333 ||' error_text = '||''''||lv_message_text||''''
18334 ||' WHERE EXISTS( SELECT 1 '
18335 ||' FROM msc_st_region_locations msr2'
18336 ||' WHERE msr2.sr_instance_code = msr1.sr_instance_code'
18337 ||' AND NVL(msr2.region_type, '||NULL_VALUE||') = NVL(msr1.region_type,'||NULL_VALUE||')'
18338 ||' AND NVL(msr2.company_name, '||''''||NULL_CHAR||''''||') = '
18339 ||' NVL(msr1.company_name, '||''''||NULL_CHAR||''''||')'
18340 ||' AND NVL(msr2.country, '||''''||NULL_CHAR||''''||') = '
18341 ||' NVL(msr1.country, '||''''||NULL_CHAR||''''||')'
18342 ||' AND NVL(msr2.country_code, '||''''||NULL_CHAR||''''||') = '
18343 ||' NVL(msr1.country_code, '||''''||NULL_CHAR||''''||')'
18344 ||' AND NVL(msr2.state, '||''''||NULL_CHAR||''''||') = '
18345 ||' NVL(msr1.state, '||''''||NULL_CHAR||''''||')'
18346 ||' AND NVL(msr2.state_code, '||''''||NULL_CHAR||''''||') = '
18347 ||' NVL(msr1.state_code, '||''''||NULL_CHAR||''''||')'
18348 ||' AND NVL(msr2.city, '||''''||NULL_CHAR||''''||') = '
18349 ||' NVL(msr1.city, '||''''||NULL_CHAR||''''||')'
18350 ||' AND NVL(msr2.city_code, '||''''||NULL_CHAR||''''||') = '
18351 ||' NVL(msr1.city_code, '||''''||NULL_CHAR||''''||')'
18352 ||' AND NVL(msr2.postal_code_from, '||''''||NULL_CHAR||''''||') = '
18353 ||' NVL(msr1.postal_code_from, '||''''||NULL_CHAR||''''||')'
18354 ||' AND NVL(msr2.postal_code_to, '||''''||NULL_CHAR||''''||') = '
18355 ||' NVL(msr1.postal_code_to, '||''''||NULL_CHAR||''''||')'
18356 ||' AND NVL(msr2.location_code, '||''''||NULL_CHAR||''''||') = '
18357 ||' NVL(msr1.location_code, '||''''||NULL_CHAR||''''||')'
18358 ||' AND msr2.process_flag = '||G_IN_PROCESS
18359 ||' GROUP BY sr_instance_code, region_type, company_name,country,country_code, state, state_code, city, city_code, postal_code_from, postal_code_to, location_code'
18360 ||' HAVING COUNT(*) > 1)'
18361 ||' AND msr1.process_flag = '||G_IN_PROCESS
18362 ||' AND msr1.sr_instance_code = :v_instance_code'
18363 ||' AND NVL(msr1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
18364
18365
18366 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
18367
18368 EXECUTE IMMEDIATE lv_sql_stmt
18369 USING v_instance_code;
18370
18371
18372
18373 lv_column_names :=
18374 'REGION_TYPE ||''~''||'
18375 ||' COUNTRY ||''~''||'
18376 ||' COUNTRY_CODE ||''~''||'
18377 ||' STATE_CODE ||''~''||'
18378 ||' SR_INSTANCE_CODE ||''~''||'
18379 ||' STATE ||''~''||'
18380 ||' CITY ||''~''||'
18381 ||' CITY_CODE ||''~''||'
18382 ||' POSTAL_CODE_FROM ||''~''||'
18383 ||' POSTAL_CODE_TO ||''~''||'
18384 ||' LOCATION_CODE ||''~''||'
18385 ||' DELETED_FLAG ||''~''||'
18386 ||' COMPANY_NAME ' ;
18387
18388 -- Now processing by batch
18389 LOOP
18390 v_sql_stmt := 03;
18391 lv_cursor_stmt :=
18392 ' SELECT msc_st_batch_id_s.NEXTVAL '
18393 ||' FROM dual';
18394
18395 OPEN c1 FOR lv_cursor_stmt;
18396 FETCH c1 INTO lv_batch_id;
18397 CLOSE c1;
18398
18399 lv_sql_stmt :=
18400 ' UPDATE msc_st_region_locations '
18401 ||' SET batch_id = :lv_batch_id'
18402 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
18403 ||' AND sr_instance_code = :v_instance_code'
18404 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
18405 ||' AND rownum <= '||v_batch_size;
18406
18407
18408 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
18409
18410 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
18411
18412 EXIT WHEN SQL%NOTFOUND;
18413
18414 OPEN c6(lv_batch_id);
18415 FETCH c6 BULK COLLECT INTO lb_rowid;
18416 CLOSE c6;
18417
18418
18419 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
18420 UPDATE msc_st_region_locations
18421 SET st_transaction_id = msc_st_region_locations_s.NEXTVAL,
18422 refresh_number = v_refresh_id,
18423 last_update_date = v_current_date,
18424 last_updated_by = v_current_user,
18425 creation_date = v_current_date,
18426 created_by = v_current_user
18427 WHERE rowid = lb_rowid(j);
18428
18429 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
18430 (p_app_short_name => 'MSC',
18431 p_error_code => 'MSC_PP_NO_DELETION',
18432 p_message_text => lv_message_text,
18433 p_error_text => lv_error_text,
18434 p_token1 => 'TABLE_NAME',
18435 p_token_value1 => 'MSC_ST_REGION_LOCATIONS');
18436
18437
18438 -- Deletion is not allowed for this table
18439 v_sql_stmt := 06;
18440 lv_sql_stmt :=
18441 'UPDATE msc_st_region_locations '
18442 ||' SET process_flag = '||G_ERROR_FLG||','
18443 ||' error_text = '||''''||lv_message_text||''''
18444 ||' WHERE deleted_flag = '||SYS_YES
18445 ||' AND process_flag = '||G_IN_PROCESS
18446 ||' AND batch_id = :lv_batch_id'
18447 ||' AND sr_instance_code = :v_instance_code';
18448
18449
18450 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
18451
18452 EXECUTE IMMEDIATE lv_sql_stmt
18453 USING lv_batch_id,
18454 v_instance_code;
18455
18456 -- set the message
18457
18458 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
18459 (p_app_short_name => 'MSC',
18460 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
18461 p_message_text => lv_message_text,
18462 p_error_text => lv_error_text,
18463 p_token1 => 'COLUMN_NAME',
18464 p_token_value1 => 'DELETED_FLAG',
18465 p_token2 => 'DEFAULT_VALUE',
18466 p_token_value2 => SYS_NO);
18467
18468 IF lv_return <> 0 THEN
18469 RAISE ex_logging_err;
18470 END IF;
18471
18472 -- Check DELETED_FLAG column has valid value or not and if not set it to SYS_NO
18473 -- Log error procedure inserts warning and also defaults the deleted flag
18474
18475 lv_where_str := ' AND NVL(deleted_flag,'||NULL_VALUE||') '
18476 ||' NOT IN(1,2)';
18477
18478 lv_return := MSC_ST_UTIL.LOG_ERROR
18479 (p_table_name => 'MSC_ST_REGION_LOCATIONS',
18480 p_instance_code => v_instance_code,
18481 p_row => lv_column_names,
18482 p_severity => G_SEV_WARNING,
18483 p_message_text => lv_message_text,
18484 p_error_text => lv_error_text,
18485 p_batch_id => lv_batch_id,
18486 p_where_str => lv_where_str,
18487 p_col_name => 'DELETED_FLAG',
18488 p_debug => v_debug,
18489 p_default_value => SYS_NO);
18490
18491 IF lv_return <> 0 THEN
18492 RAISE ex_logging_err;
18493 END IF;
18494
18495 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
18496 (p_app_short_name => 'MSC',
18497 p_error_code => 'MSC_PP_COL_VAL_NULL',
18498 p_message_text => lv_message_text,
18499 p_error_text => lv_error_text,
18500 p_token1 => 'COLUMN_NAME',
18501 p_token_value1 => 'LOCATION_CODE');
18502
18503 IF lv_return <> 0 THEN
18504 RAISE ex_logging_err;
18505 END IF;
18506
18507 -- Error out records where location_code is NULL
18508
18509 lv_sql_stmt :=
18510 'UPDATE msc_st_region_locations '
18511 ||' SET process_flag = '||G_ERROR_FLG||','
18512 ||' error_text = '||''''||lv_message_text||''''
18513 ||' WHERE sr_instance_code = :v_instance_code'
18514 ||' AND batch_id = :lv_batch_id'
18515 ||' AND process_flag = '||G_IN_PROCESS
18516 ||' AND NVL(location_code,'||''''||NULL_CHAR||''''||') '
18517 ||' = '||''''||NULL_CHAR||'''';
18518
18519
18520 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
18521
18522 EXECUTE IMMEDIATE lv_sql_stmt
18523 USING v_instance_code,
18524 lv_batch_id;
18525
18526
18527 -- Derive region_id
18528
18529 lv_sql_stmt :=
18530 'UPDATE msc_st_region_locations msr'
18531 ||' SET region_id = (SELECT local_id'
18532 ||' FROM msc_local_id_setup mls'
18533 ||' WHERE mls.char1 = msr.sr_instance_code'
18534 ||' AND NVL(mls.number1, '||NULL_VALUE||') = NVL(msr.region_type,'||NULL_VALUE||')'
18535 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
18536 ||' NVL(msr.country, '||''''||NULL_CHAR||''''||') '
18537 ||' AND NVL(mls.char3, '||''''||NULL_CHAR||''''||') = '
18538 ||' NVL(msr.country_code, '||''''||NULL_CHAR||''''||') '
18539 ||' AND NVL(mls.char4, '||''''||NULL_CHAR||''''||') = '
18540 ||' NVL(msr.state, '||''''||NULL_CHAR||''''||') '
18541 ||' AND NVL(mls.char5, '||''''||NULL_CHAR||''''||') = '
18542 ||' NVL(msr.state_code, '||''''||NULL_CHAR||''''||') '
18543 ||' AND NVL(mls.char6, '||''''||NULL_CHAR||''''||') = '
18544 ||' NVL(msr.city, '||''''||NULL_CHAR||''''||') '
18545 ||' AND NVL(mls.char7, '||''''||NULL_CHAR||''''||') = '
18546 ||' NVL(msr.city_code, '||''''||NULL_CHAR||''''||') '
18547 ||' AND NVL(mls.char8, '||''''||NULL_CHAR||''''||') = '
18548 ||' NVL(msr.postal_code_from, '||''''||NULL_CHAR||''''||') '
18549 ||' AND NVL(mls.char9, '||''''||NULL_CHAR||''''||') = '
18550 ||' NVL(msr.postal_code_to, '||''''||NULL_CHAR||''''||') '
18551 ||' AND mls.number1 in (0,1,2,3) '
18552 ||' AND mls.entity_name = ''REGION_ID'' )'
18553 ||' WHERE process_flag = '||G_IN_PROCESS
18554 ||' AND NVL(batch_id,'||NULL_VALUE||') = :lv_batch_id'
18555 ||' AND msr.region_type in (0,1,2,3) '
18556 ||' AND sr_instance_code = :v_instance_code';
18557
18558
18559 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
18560
18561 EXECUTE IMMEDIATE lv_sql_stmt
18562 USING lv_batch_id,
18563 v_instance_code;
18564
18565 --Deriving location_id
18566 lv_sql_stmt :=
18567 'UPDATE msc_st_region_locations msr'
18568 ||' SET location_id = nvl((SELECT local_id'
18569 ||' FROM msc_local_id_setup mls'
18570 ||' WHERE mls.char1 = msr.sr_instance_code'
18571 ||' AND mls.char3 = msr.location_code'
18572 ||' AND mls.entity_name = ''LOCATION_ID'' ), ' ||NULL_VALUE|| ')'
18573 ||' WHERE process_flag = '||G_IN_PROCESS
18574 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
18575 ||' AND sr_instance_code = :v_instance_code';
18576
18577
18578 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
18579
18580 EXECUTE IMMEDIATE lv_sql_stmt
18581 USING lv_batch_id,
18582 v_instance_code;
18583
18584
18585 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
18586 (p_app_short_name => 'MSC',
18587 p_error_code => 'MSC_PP_NO_UPDATION',
18588 p_message_text => lv_message_text,
18589 p_error_text => lv_error_text,
18590 p_token1 => 'TABLE_NAME',
18591 p_token_value1 => 'MSC_ST_REGION_LOCATIONS');
18592
18593
18594 -- Error out the record if same region locations already exists in ODS
18595 -- As we do not allow region locations incremental update
18596 -- It has to be purged before laoded again
18597
18598 lv_sql_stmt :=
18599 'UPDATE msc_st_region_locations msrl'
18600 ||' SET msrl.process_flag = '||G_ERROR_FLG||','
18601 ||' msrl.error_text = '||''''||lv_message_text||''''
18602 ||' WHERE msrl.batch_id = :lv_batch_id'
18603 ||' AND msrl.sr_instance_code = :v_instance_code'
18604 ||' AND EXISTS ( SELECT 1'
18605 ||' FROM msc_region_locations mrl'
18606 ||' WHERE mrl.location_id = nvl(msrl.location_id ,'||NULL_VALUE||') '
18607 ||' AND nvl(mrl.region_id, '||NULL_VALUE||') = nvl(msrl.region_id, '||NULL_VALUE||')'
18608 ||' AND mrl.sr_instance_id = :v_instance_id)';
18609
18610 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
18611
18612 EXECUTE IMMEDIATE lv_sql_stmt
18613 USING lv_batch_id,
18614 v_instance_code,
18615 v_instance_id;
18616
18617 --Call to customised validation.
18618 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
18619 (ERRBUF => lv_error_text,
18620 RETCODE => lv_return,
18621 pBatchID => lv_batch_id,
18622 pInstanceCode => v_instance_code,
18623 pEntityName => 'MSC_ST_REGION_LOCATIONS',
18624 pInstanceID => v_instance_id);
18625
18626 IF NVL(lv_return,0) <> 0 THEN
18627 RAISE ex_logging_err;
18628 END IF;
18629
18630 OPEN c7(lv_batch_id);
18631 FETCH c7 BULK COLLECT INTO lb_rowid ;
18632
18633 IF c7%ROWCOUNT > 0 THEN
18634 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
18635 UPDATE msc_st_region_locations
18636 SET location_id = msc_st_location_id_s.NEXTVAL
18637 WHERE rowid = lb_rowid(j);
18638
18639 -- Insert record in LID
18640 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
18641 INSERT INTO msc_local_id_setup
18642 (local_id,
18643 st_transaction_id,
18644 instance_id,
18645 entity_name,
18646 data_source_type,
18647 char1,
18648 char3,
18649 last_update_date,
18650 last_updated_by,
18651 creation_date,
18652 created_by)
18653 SELECT
18654 location_id,
18655 st_transaction_id,
18656 v_instance_id,
18657 'LOCATION_ID',
18658 data_source_type,
18659 v_instance_code,
18660 location_code,
18661 v_current_date,
18662 v_current_user,
18663 v_current_date,
18664 v_current_user
18665 FROM msc_st_region_locations
18666 WHERE rowid = lb_rowid(j);
18667 END IF;
18668 CLOSE c7;
18669
18670 --Deriving location_id
18671
18672 lv_sql_stmt :=
18673 'UPDATE msc_st_region_locations msr'
18674 ||' SET location_id = nvl((SELECT local_id'
18675 ||' FROM msc_local_id_setup mls'
18676 ||' WHERE mls.char1 = msr.sr_instance_code'
18677 ||' AND mls.char3 = msr.location_code'
18678 ||' AND mls.entity_name = ''LOCATION_ID'' ), ' ||NULL_VALUE|| ')'
18679 ||' WHERE process_flag = '||G_IN_PROCESS
18680 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
18681 ||' AND sr_instance_code = :v_instance_code';
18682
18683
18684 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
18685
18686 EXECUTE IMMEDIATE lv_sql_stmt
18687 USING lv_batch_id,
18688 v_instance_code;
18689
18690 -- Set the process flag as Valid and populate instance_id
18691 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
18692 (p_table_name => 'MSC_ST_REGION_LOCATIONS',
18693 p_instance_id => v_instance_id,
18694 p_instance_code => v_instance_code,
18695 p_process_flag => G_VALID,
18696 p_error_text => lv_error_text,
18697 p_debug => v_debug,
18698 p_batch_id => lv_batch_id);
18699
18700 IF lv_return <> 0 THEN
18701 RAISE ex_logging_err;
18702 END IF;
18703
18704 -- At the end calling the LOG_ERROR for logging all
18705 -- errored out records.
18706 lv_return := MSC_ST_UTIL.LOG_ERROR
18707 (p_table_name => 'MSC_ST_REGION_LOCATIONS',
18708 p_instance_code => v_instance_code,
18709 p_row => lv_column_names,
18710 p_severity => G_SEV_ERROR,
18711 p_message_text => NULL,
18712 p_error_text => lv_error_text,
18713 p_debug => v_debug,
18714 p_batch_id => lv_batch_id );
18715
18716 IF lv_return <> 0 THEN
18717 RAISE ex_logging_err;
18718 END IF;
18719
18720 lv_sql_stmt :=
18721 ' INSERT INTO MSC_REGION_LOCATIONS '
18722 ||' (REGION_ID,'
18723 ||' LOCATION_ID,'
18724 ||' REGION_TYPE,'
18725 ||' PARENT_REGION_FLAG,'
18726 ||' LOCATION_SOURCE,'
18727 ||' EXCEPTION_TYPE,'
18728 ||' SR_INSTANCE_ID,'
18729 ||' CREATED_BY,'
18730 ||' CREATION_DATE,'
18731 ||' LAST_UPDATED_BY,'
18732 ||' LAST_UPDATE_DATE,'
18733 ||' LAST_UPDATE_LOGIN)'
18734 ||' SELECT distinct '
18735 ||' REGION_ID,'
18736 ||' LOCATION_ID,'
18737 ||' REGION_TYPE,'
18738 ||' PARENT_REGION_FLAG,'
18739 ||' LOCATION_SOURCE,'
18740 ||' EXCEPTION_TYPE,'
18741 ||' SR_INSTANCE_ID,'
18742 ||' CREATED_BY,'
18743 ||' CREATION_DATE,'
18744 ||' LAST_UPDATED_BY,'
18745 ||' LAST_UPDATE_DATE,'
18746 ||' LAST_UPDATE_LOGIN'
18747 ||' FROM MSC_ST_REGION_LOCATIONS msrl'
18748 ||' WHERE msrl.batch_id = :lv_batch_id'
18749 ||' AND msrl.sr_instance_code = :v_instance_code'
18750 ||' AND msrl.process_flag = '||G_VALID ;
18751
18752
18753 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
18754
18755 EXECUTE IMMEDIATE lv_sql_stmt
18756 USING lv_batch_id,
18757 v_instance_code;
18758
18759
18760 COMMIT;
18761 END LOOP;
18762
18763 -- validation for region sites
18764
18765 --Getting the error message text
18766 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
18767 (p_app_short_name => 'MSC',
18768 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
18769 p_message_text => lv_message_text,
18770 p_error_text => lv_error_text);
18771
18772 IF lv_return <> 0 THEN
18773 RAISE ex_logging_err;
18774 END IF;
18775
18776 --Duplicate records check for the records whose source is XML
18777
18778 lv_sql_stmt :=
18779 'UPDATE msc_st_region_sites msr1 '
18780 ||' SET process_flag = '||G_ERROR_FLG||','
18781 ||' error_text = '||''''||lv_message_text||''''
18782 ||' WHERE message_id < (SELECT MAX(message_id)'
18783 ||' FROM msc_st_region_sites msr2'
18784 ||' WHERE msr2.sr_instance_code = msr1.sr_instance_code'
18785 ||' AND NVL(msr2.country, '||''''||NULL_CHAR||''''||') = '
18786 ||' NVL(msr1.country, '||''''||NULL_CHAR||''''||')'
18787 ||' AND NVL(msr2.country_code, '||''''||NULL_CHAR||''''||') = '
18788 ||' NVL(msr1.country_code, '||''''||NULL_CHAR||''''||')'
18789 ||' AND NVL(msr2.state, '||''''||NULL_CHAR||''''||') = '
18790 ||' NVL(msr1.state, '||''''||NULL_CHAR||''''||')'
18791 ||' AND NVL(msr2.state_code, '||''''||NULL_CHAR||''''||') = '
18792 ||' NVL(msr1.state_code, '||''''||NULL_CHAR||''''||')'
18793 ||' AND NVL(msr2.city, '||''''||NULL_CHAR||''''||') = '
18794 ||' NVL(msr1.city, '||''''||NULL_CHAR||''''||')'
18795 ||' AND NVL(msr2.city_code, '||''''||NULL_CHAR||''''||') = '
18796 ||' NVL(msr1.city_code, '||''''||NULL_CHAR||''''||')'
18797 ||' AND NVL(msr2.postal_code_from, '||''''||NULL_CHAR||''''||') = '
18798 ||' NVL(msr1.postal_code_from, '||''''||NULL_CHAR||''''||')'
18799 ||' AND NVL(msr2.postal_code_to, '||''''||NULL_CHAR||''''||') = '
18800 ||' NVL(msr1.postal_code_to, '||''''||NULL_CHAR||''''||')'
18801 ||' AND NVL(msr2.zone, '||''''||NULL_CHAR||''''||') = '
18802 ||' NVL(msr1.zone, '||''''||NULL_CHAR||''''||')'
18803 ||' AND NVL(msr2.vendor_name, '||''''||NULL_CHAR||''''||') = '
18804 ||' NVL(msr1.vendor_name, '||''''||NULL_CHAR||''''||')'
18805 ||' AND NVL(msr2.vendor_site_code, '||''''||NULL_CHAR||''''||') = '
18806 ||' NVL(msr1.vendor_site_code, '||''''||NULL_CHAR||''''||')'
18807 ||' AND msr2.process_flag ='|| G_IN_PROCESS
18808 ||' AND NVL(msr2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
18809 ||' AND msr1.process_flag = '||G_IN_PROCESS
18810 ||' AND msr1.sr_instance_code = :v_instance_code'
18811 ||' AND NVL(msr1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
18812
18813
18814 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
18815
18816 EXECUTE IMMEDIATE lv_sql_stmt
18817 USING v_instance_code;
18818
18819 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
18820 (p_app_short_name => 'MSC',
18821 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
18822 p_message_text => lv_message_text,
18823 p_error_text => lv_error_text);
18824
18825 IF lv_return <> 0 THEN
18826 RAISE ex_logging_err;
18827 END IF;
18828
18829 --Duplicate records check for the records whose source is other than XML
18830 --Different SQL is used because in XML we can identify the latest records
18831 --whereas in batch load we cannot.
18832
18833 lv_sql_stmt :=
18834 'UPDATE msc_st_region_sites msr1'
18835 ||' SET process_flag = '||G_ERROR_FLG||','
18836 ||' error_text = '||''''||lv_message_text||''''
18837 ||' WHERE EXISTS( SELECT 1 '
18838 ||' FROM msc_st_region_sites msr2'
18839 ||' WHERE msr2.sr_instance_code = msr1.sr_instance_code'
18840 ||' AND NVL(msr2.country, '||''''||NULL_CHAR||''''||') = '
18841 ||' NVL(msr1.country, '||''''||NULL_CHAR||''''||')'
18842 ||' AND NVL(msr2.country_code, '||''''||NULL_CHAR||''''||') = '
18843 ||' NVL(msr1.country_code, '||''''||NULL_CHAR||''''||')'
18844 ||' AND NVL(msr2.state, '||''''||NULL_CHAR||''''||') = '
18845 ||' NVL(msr1.state, '||''''||NULL_CHAR||''''||')'
18846 ||' AND NVL(msr2.state_code, '||''''||NULL_CHAR||''''||') = '
18847 ||' NVL(msr1.state_code, '||''''||NULL_CHAR||''''||')'
18848 ||' AND NVL(msr2.city, '||''''||NULL_CHAR||''''||') = '
18849 ||' NVL(msr1.city, '||''''||NULL_CHAR||''''||')'
18850 ||' AND NVL(msr2.city_code, '||''''||NULL_CHAR||''''||') = '
18851 ||' NVL(msr1.city_code, '||''''||NULL_CHAR||''''||')'
18852 ||' AND NVL(msr2.postal_code_from, '||''''||NULL_CHAR||''''||') = '
18853 ||' NVL(msr1.postal_code_from, '||''''||NULL_CHAR||''''||')'
18854 ||' AND NVL(msr2.postal_code_to, '||''''||NULL_CHAR||''''||') = '
18855 ||' NVL(msr1.postal_code_to, '||''''||NULL_CHAR||''''||')'
18856 ||' AND NVL(msr2.zone, '||''''||NULL_CHAR||''''||') = '
18857 ||' NVL(msr1.zone, '||''''||NULL_CHAR||''''||')'
18858 ||' AND NVL(msr2.vendor_name, '||''''||NULL_CHAR||''''||') = '
18859 ||' NVL(msr1.vendor_name, '||''''||NULL_CHAR||''''||')'
18860 ||' AND NVL(msr2.vendor_site_code, '||''''||NULL_CHAR||''''||') = '
18861 ||' NVL(msr1.vendor_site_code, '||''''||NULL_CHAR||''''||')'
18862 ||' AND msr2.process_flag = '||G_IN_PROCESS
18863 ||' GROUP BY sr_instance_code,country,country_code, state, state_code, city, city_code, postal_code_from, postal_code_to, zone, vendor_name, vendor_site_code'
18864 ||' HAVING COUNT(*) > 1)'
18865 ||' AND msr1.process_flag = '||G_IN_PROCESS
18866 ||' AND msr1.sr_instance_code = :v_instance_code'
18867 ||' AND NVL(msr1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
18868
18869
18870 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
18871
18872 EXECUTE IMMEDIATE lv_sql_stmt
18873 USING v_instance_code;
18874
18875
18876
18877 lv_column_names :=
18878 'REGION_TYPE ||''~''||'
18879 ||' COUNTRY ||''~''||'
18880 ||' COUNTRY_CODE ||''~''||'
18881 ||' STATE_CODE ||''~''||'
18882 ||' SR_INSTANCE_CODE ||''~''||'
18883 ||' STATE ||''~''||'
18884 ||' CITY ||''~''||'
18885 ||' CITY_CODE ||''~''||'
18886 ||' POSTAL_CODE_FROM ||''~''||'
18887 ||' POSTAL_CODE_TO ||''~''||'
18888 ||' ZONE ||''~''||'
18889 ||' DELETED_FLAG ||''~''||'
18890 ||' VENDOR_NAME ' ;
18891
18892 -- Now processing by batch
18893 LOOP
18894
18895 lv_cursor_stmt :=
18896 ' SELECT msc_st_batch_id_s.NEXTVAL '
18897 ||' FROM dual';
18898
18899 OPEN c1 FOR lv_cursor_stmt;
18900 FETCH c1 INTO lv_batch_id;
18901 CLOSE c1;
18902
18903 lv_sql_stmt :=
18904 ' UPDATE msc_st_region_sites '
18905 ||' SET batch_id = :lv_batch_id'
18906 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
18907 ||' AND sr_instance_code = :v_instance_code'
18908 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
18909 ||' AND rownum <= '||v_batch_size;
18910
18911
18912 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
18913
18914 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
18915
18916 EXIT WHEN SQL%NOTFOUND;
18917
18918 OPEN c8(lv_batch_id);
18919 FETCH c8 BULK COLLECT INTO lb_rowid;
18920 CLOSE c8;
18921
18922 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
18923 UPDATE msc_st_region_sites
18924 SET st_transaction_id = msc_st_region_sites_s.NEXTVAL,
18925 refresh_id = v_refresh_id,
18926 last_update_date = v_current_date,
18927 last_updated_by = v_current_user,
18928 creation_date = v_current_date,
18929 created_by = v_current_user
18930 WHERE rowid = lb_rowid(j);
18931
18932 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
18933 (p_app_short_name => 'MSC',
18934 p_error_code => 'MSC_PP_NO_DELETION',
18935 p_message_text => lv_message_text,
18936 p_error_text => lv_error_text,
18937 p_token1 => 'TABLE_NAME',
18938 p_token_value1 => 'MSC_ST_REGION_SITES');
18939
18940
18941 -- Deletion is not allowed for this table
18942 v_sql_stmt := 06;
18943 lv_sql_stmt :=
18944 'UPDATE msc_st_region_sites '
18945 ||' SET process_flag = '||G_ERROR_FLG||','
18946 ||' error_text = '||''''||lv_message_text||''''
18947 ||' WHERE deleted_flag = '||SYS_YES
18948 ||' AND process_flag = '||G_IN_PROCESS
18949 ||' AND batch_id = :lv_batch_id'
18950 ||' AND sr_instance_code = :v_instance_code';
18951
18952
18953 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
18954
18955 EXECUTE IMMEDIATE lv_sql_stmt
18956 USING lv_batch_id,
18957 v_instance_code;
18958
18959 -- set the message
18960
18961 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
18962 (p_app_short_name => 'MSC',
18963 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
18964 p_message_text => lv_message_text,
18965 p_error_text => lv_error_text,
18966 p_token1 => 'COLUMN_NAME',
18967 p_token_value1 => 'DELETED_FLAG',
18968 p_token2 => 'DEFAULT_VALUE',
18969 p_token_value2 => SYS_NO);
18970
18971 IF lv_return <> 0 THEN
18972 RAISE ex_logging_err;
18973 END IF;
18974
18975 -- Check DELETED_FLAG column has valid value or not and if not set it to SYS_NO
18976 -- Log error procedure inserts warning and also defaults the deleted flag
18977
18978 lv_where_str := ' AND NVL(deleted_flag,'||NULL_VALUE||') '
18979 ||' NOT IN(1,2)';
18980
18981 lv_return := MSC_ST_UTIL.LOG_ERROR
18982 (p_table_name => 'MSC_ST_REGION_SITES',
18983 p_instance_code => v_instance_code,
18984 p_row => lv_column_names,
18985 p_severity => G_SEV_WARNING,
18986 p_message_text => lv_message_text,
18987 p_error_text => lv_error_text,
18988 p_batch_id => lv_batch_id,
18989 p_where_str => lv_where_str,
18990 p_col_name => 'DELETED_FLAG',
18991 p_debug => v_debug,
18992 p_default_value => SYS_NO);
18993
18994 IF lv_return <> 0 THEN
18995 RAISE ex_logging_err;
18996 END IF;
18997
18998 --Deriving region_id
18999
19000 lv_sql_stmt :=
19001 'UPDATE msc_st_region_sites msr'
19002 ||' SET region_id = (SELECT local_id'
19003 ||' FROM msc_local_id_setup mls'
19004 ||' WHERE mls.char1 = msr.sr_instance_code'
19005 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
19006 ||' NVL(msr.country, '||''''||NULL_CHAR||''''||') '
19007 ||' AND NVL(mls.char3, '||''''||NULL_CHAR||''''||') = '
19008 ||' NVL(msr.country_code, '||''''||NULL_CHAR||''''||') '
19009 ||' AND NVL(mls.char4, '||''''||NULL_CHAR||''''||') = '
19010 ||' NVL(msr.state, '||''''||NULL_CHAR||''''||') '
19011 ||' AND NVL(mls.char5, '||''''||NULL_CHAR||''''||') = '
19012 ||' NVL(msr.state_code, '||''''||NULL_CHAR||''''||') '
19013 ||' AND NVL(mls.char6, '||''''||NULL_CHAR||''''||') = '
19014 ||' NVL(msr.city, '||''''||NULL_CHAR||''''||') '
19015 ||' AND NVL(mls.char7, '||''''||NULL_CHAR||''''||') = '
19016 ||' NVL(msr.city_code, '||''''||NULL_CHAR||''''||') '
19017 ||' AND NVL(mls.char8, '||''''||NULL_CHAR||''''||') = '
19018 ||' NVL(msr.postal_code_from, '||''''||NULL_CHAR||''''||') '
19019 ||' AND NVL(mls.char9, '||''''||NULL_CHAR||''''||') = '
19020 ||' NVL(msr.postal_code_to, '||''''||NULL_CHAR||''''||') '
19021 ||' AND NVL(mls.char10, '||''''||NULL_CHAR||''''||') = '
19022 ||' NVL(msr.zone, '||''''||NULL_CHAR||''''||') '
19023 ||' AND mls.entity_name = ''REGION_ID'' )'
19024 ||' WHERE process_flag = '||G_IN_PROCESS
19025 ||' AND NVL(batch_id,'||NULL_VALUE||') = :lv_batch_id'
19026 ||' AND sr_instance_code = :v_instance_code';
19027
19028
19029 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
19030
19031 EXECUTE IMMEDIATE lv_sql_stmt
19032 USING lv_batch_id,
19033 v_instance_code;
19034
19035 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
19036 (p_app_short_name => 'MSC',
19037 p_error_code => 'MSC_PP_INVALID_VALUE',
19038 p_message_text => lv_message_text,
19039 p_error_text => lv_error_text,
19040 p_token1 => 'COLUMN_NAME',
19041 p_token_value1 => 'VENDOR_SITE_CODE');
19042
19043 IF lv_return <> 0 THEN
19044 RAISE ex_logging_err;
19045 END IF;
19046
19047 --Derive vendor_site_id
19048 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
19049 (p_table_name => 'MSC_ST_REGION_SITES',
19050 p_partner_name => 'VENDOR_NAME',
19051 p_partner_site_code => 'VENDOR_SITE_CODE',
19052 p_partner_site_id => 'VENDOR_SITE_ID',
19053 p_instance_code => v_instance_code,
19054 p_partner_type => G_VENDOR,
19055 p_error_text => lv_error_text,
19056 p_batch_id => lv_batch_id,
19057 p_severity => G_SEV3_ERROR,
19058 p_message_text => lv_message_text,
19059 p_debug => v_debug,
19060 p_row => lv_column_names);
19061
19062 IF lv_return <> 0 THEN
19063 RAISE ex_logging_err;
19064 END IF;
19065
19066 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
19067 (p_app_short_name => 'MSC',
19068 p_error_code => 'MSC_PP_NO_UPDATION',
19069 p_message_text => lv_message_text,
19070 p_error_text => lv_error_text,
19071 p_token1 => 'TABLE_NAME',
19072 p_token_value1 => 'MSC_ST_REGION_SITES');
19073
19074
19075 -- Error out the record if same region_site already exists in ODS
19076 -- As we do not allow region_site incremental update
19077 -- It has to be purged before loaded again
19078
19079 lv_sql_stmt :=
19080 'UPDATE msc_st_region_sites msrs'
19081 ||' SET msrs.process_flag = '||G_ERROR_FLG||','
19082 ||' msrs.error_text = '||''''||lv_message_text||''''
19083 ||' WHERE msrs.batch_id = :lv_batch_id'
19084 ||' AND msrs.sr_instance_code = :v_instance_code'
19085 ||' AND EXISTS ( SELECT 1'
19086 ||' FROM msc_region_sites mrs, MSC_TP_SITE_ID_LID mtsil'
19087 ||' WHERE msrs.vendor_site_id = mtsil.SR_TP_SITE_ID'
19088 ||' AND mtsil.sr_instance_id = :v_instance_id '
19089 ||' AND mtsil.Partner_Type = 1'
19090 ||' AND mtsil.TP_SITE_ID = mrs.vendor_site_id '
19091 ||' AND msrs.region_id = mrs.region_id'
19092 ||' AND mrs.sr_instance_id = :v_instance_id)';
19093
19094 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
19095
19096 EXECUTE IMMEDIATE lv_sql_stmt
19097 USING lv_batch_id,
19098 v_instance_code,
19099 v_instance_id,
19100 v_instance_id;
19101
19102 --Call to customised validation.
19103 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
19104 (ERRBUF => lv_error_text,
19105 RETCODE => lv_return,
19106 pBatchID => lv_batch_id,
19107 pInstanceCode => v_instance_code,
19108 pEntityName => 'MSC_ST_REGION_SITES',
19109 pInstanceID => v_instance_id);
19110
19111 IF NVL(lv_return,0) <> 0 THEN
19112 RAISE ex_logging_err;
19113 END IF;
19114
19115 -- Set the process flag as Valid and populate instance_id
19116 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
19117 (p_table_name => 'MSC_ST_REGION_SITES',
19118 p_instance_id => v_instance_id,
19119 p_instance_code => v_instance_code,
19120 p_process_flag => G_VALID,
19121 p_error_text => lv_error_text,
19122 p_debug => v_debug,
19123 p_batch_id => lv_batch_id);
19124
19125 IF lv_return <> 0 THEN
19126 RAISE ex_logging_err;
19127 END IF;
19128
19129 -- At the end calling the LOG_ERROR for logging all
19130 -- errored out records.
19131 lv_return := MSC_ST_UTIL.LOG_ERROR
19132 (p_table_name => 'MSC_ST_REGION_SITES',
19133 p_instance_code => v_instance_code,
19134 p_row => lv_column_names,
19135 p_severity => G_SEV_ERROR,
19136 p_message_text => NULL,
19137 p_error_text => lv_error_text,
19138 p_debug => v_debug,
19139 p_batch_id => lv_batch_id );
19140
19141 IF lv_return <> 0 THEN
19142 RAISE ex_logging_err;
19143 END IF;
19144
19145 lv_sql_stmt :=
19146 ' INSERT INTO MSC_REGION_SITES '
19147 ||' (REGION_ID, '
19148 ||' VENDOR_SITE_ID,'
19149 ||' REGION_TYPE,'
19150 ||' ZONE_LEVEL,'
19151 ||' SR_INSTANCE_ID,'
19152 ||' CREATED_BY,'
19153 ||' CREATION_DATE,'
19154 ||' LAST_UPDATED_BY,'
19155 ||' LAST_UPDATE_DATE,'
19156 ||' LAST_UPDATE_LOGIN)'
19157 ||' SELECT distinct '
19158 ||' msrs.REGION_ID,'
19159 ||' mtsil.TP_SITE_ID,'
19160 ||' msrs.REGION_TYPE,'
19161 ||' msrs.ZONE_LEVEL,'
19162 ||' msrs.SR_INSTANCE_ID,'
19163 ||' msrs.CREATED_BY,'
19164 ||' msrs.CREATION_DATE,'
19165 ||' msrs.LAST_UPDATED_BY,'
19166 ||' msrs.LAST_UPDATE_DATE,'
19167 ||' msrs.LAST_UPDATE_LOGIN'
19168 ||' FROM MSC_TP_SITE_ID_LID mtsil, MSC_ST_REGION_SITES msrs'
19169 ||' WHERE msrs.batch_id = :lv_batch_id'
19170 ||' AND mtsil.SR_TP_SITE_ID = msrs.VENDOR_SITE_ID'
19171 ||' AND mtsil.SR_Instance_ID = msrs.SR_INSTANCE_ID'
19172 ||' AND mtsil.Partner_Type = 1 '
19173 ||' AND msrs.sr_instance_code = :v_instance_code'
19174 ||' AND msrs.process_flag = '||G_VALID ;
19175
19176
19177 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
19178
19179 EXECUTE IMMEDIATE lv_sql_stmt
19180 USING lv_batch_id,
19181 v_instance_code;
19182
19183 COMMIT;
19184 END LOOP;
19185
19186 EXCEPTION
19187 WHEN too_many_rows THEN
19188 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_REGIONS'||'('
19189 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
19190 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
19191 ROLLBACK;
19192
19193 WHEN ex_logging_err THEN
19194 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
19195 ROLLBACK;
19196
19197 WHEN OTHERS THEN
19198 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_REGIONS'||'('
19199 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
19200 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
19201 ROLLBACK;
19202
19203
19204 END LOAD_REGIONS;
19205
19206
19207 /*==========================================================================+
19208 | DESCRIPTION : This procedure validates the data in MSC_ST_CATEGORY_SETS |
19209 | table. |
19210 +==========================================================================*/
19211 PROCEDURE LOAD_CATEGORY_SET IS
19212 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
19213 lb_rowid RowidTab; --bulk collects rowid
19214 lv_return NUMBER;
19215 lv_error_text VARCHAR2(250);
19216 lv_where_str VARCHAR2(5000);
19217 lv_sql_stmt VARCHAR2(5000);
19218 lv_column_names VARCHAR2(5000); --stores concatenated column names
19219 lv_batch_id msc_st_category_sets.batch_id%TYPE;
19220 lv_message_text msc_errors.error_text%TYPE;
19221 ex_logging_err EXCEPTION;
19222
19223 CURSOR c1(p_batch_id NUMBER) IS
19224 SELECT rowid
19225 FROM msc_st_category_sets
19226 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
19227 AND batch_id = p_batch_id
19228 AND sr_instance_code = v_instance_code;
19229
19230 CURSOR c2(p_batch_id NUMBER) IS
19231 SELECT rowid
19232 FROM msc_st_category_sets
19233 WHERE NVL(sr_category_set_id,NULL_VALUE) = NULL_VALUE
19234 AND process_flag = G_IN_PROCESS
19235 AND batch_id = p_batch_id
19236 AND sr_instance_code = v_instance_code;
19237
19238 BEGIN
19239
19240 --Getting the error message text
19241 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
19242 (p_app_short_name => 'MSC',
19243 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
19244 p_message_text => lv_message_text,
19245 p_error_text => lv_error_text);
19246
19247 IF lv_return <> 0 THEN
19248 RAISE ex_logging_err;
19249 END IF;
19250
19251 --Duplicate records check for the records whose source is XML
19252 v_sql_stmt := 01;
19253 lv_sql_stmt :=
19254 'UPDATE msc_st_category_sets mcs1 '
19255 ||' SET process_flag = '||G_ERROR_FLG||','
19256 ||' error_text = '||''''||lv_message_text||''''
19257 ||' WHERE message_id < (SELECT MAX(message_id)'
19258 ||' FROM msc_st_category_sets mcs2'
19259 ||' WHERE mcs2.sr_instance_code = mcs1.sr_instance_code'
19260 ||' AND NVL(mcs2.company_name, '||''''||NULL_CHAR||''''||') = '
19261 ||' NVL(mcs1.company_name, '||''''||NULL_CHAR||''''||')'
19262 ||' AND mcs2.category_set_name = mcs1.category_set_name'
19263 ||' AND mcs2.process_flag ='|| G_IN_PROCESS
19264 ||' AND NVL(mcs2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
19265 ||' AND mcs1.process_flag = '||G_IN_PROCESS
19266 ||' AND mcs1.sr_instance_code = :v_instance_code'
19267 ||' AND NVL(mcs1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
19268
19269
19270 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
19271
19272 EXECUTE IMMEDIATE lv_sql_stmt
19273 USING v_instance_code;
19274
19275
19276 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
19277 (p_app_short_name => 'MSC',
19278 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
19279 p_message_text => lv_message_text,
19280 p_error_text => lv_error_text);
19281
19282 IF lv_return <> 0 THEN
19283 RAISE ex_logging_err;
19284 END IF;
19285
19286 --Duplicate records check for the records whose source is other than XML
19287 --Different SQL is used because in XML we can identify the latest records
19288 --whereas in batch load we cannot.
19289 v_sql_stmt := 02;
19290 lv_sql_stmt :=
19291 'UPDATE msc_st_category_sets mcs1'
19292 ||' SET process_flag = '||G_ERROR_FLG||','
19293 ||' error_text = '||''''||lv_message_text||''''
19294 ||' WHERE EXISTS( SELECT 1 '
19295 ||' FROM msc_st_category_sets mcs2'
19296 ||' WHERE mcs2.sr_instance_code = mcs1.sr_instance_code'
19297 ||' AND NVL(mcs2.company_name, '||''''||NULL_CHAR||''''||') = '
19298 ||' NVL(mcs1.company_name, '||''''||NULL_CHAR||''''||')'
19299 ||' AND mcs2.category_set_name = mcs1.category_set_name'
19300 ||' AND mcs2.process_flag = '||G_IN_PROCESS
19301 ||' AND NVL(mcs2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
19302 ||' GROUP BY sr_instance_code,company_name,category_set_name'
19303 ||' HAVING COUNT(*) > 1)'
19304 ||' AND mcs1.process_flag = '||G_IN_PROCESS
19305 ||' AND mcs1.sr_instance_code = :v_instance_code'
19306 ||' AND NVL(mcs1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
19307
19308
19309 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
19310
19311 EXECUTE IMMEDIATE lv_sql_stmt
19312 USING v_instance_code;
19313
19314 lv_column_names :=
19315 'CATEGORY_SET_NAME ||''~''||'
19316 ||'CONTROL_LEVEL ||''~''||'
19317 ||'SR_INSTANCE_CODE||''~''||'
19318 ||'DESCRIPTION ||''~''||'
19319 ||'DEFAULT_FLAG ||''~''||'
19320 ||'COMPANY_NAME ||''~''||'
19321 ||'DELETED_FLAG ';
19322
19323 LOOP
19324 v_sql_stmt := 03;
19325 SELECT msc_st_batch_id_s.NEXTVAL
19326 INTO lv_batch_id
19327 FROM dual;
19328
19329 v_sql_stmt := 04;
19330 lv_sql_stmt :=
19331 ' UPDATE msc_st_category_sets '
19332 ||' SET batch_id = :lv_batch_id'
19333 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
19334 ||' AND sr_instance_code = :v_instance_code'
19335 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
19336 ||' AND rownum <= '||v_batch_size;
19337
19338
19339 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
19340
19341 EXECUTE IMMEDIATE lv_sql_stmt
19342 USING lv_batch_id,
19343 v_instance_code;
19344
19345 EXIT WHEN SQL%NOTFOUND;
19346
19347 OPEN c1(lv_batch_id);
19348 FETCH c1 BULK COLLECT INTO lb_rowid;
19349 CLOSE c1;
19350
19351 v_sql_stmt := 05;
19352 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
19353 UPDATE msc_st_category_sets
19354 SET st_transaction_id = msc_st_category_sets_s.NEXTVAL,
19355 refresh_id = v_refresh_id,
19356 last_update_date = v_current_date,
19357 last_updated_by = v_current_user,
19358 creation_date = v_current_date,
19359 created_by = v_current_user
19360 WHERE rowid = lb_rowid(j);
19361
19362 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
19363 (p_app_short_name => 'MSC',
19364 p_error_code => 'MSC_PP_NO_DELETION',
19365 p_message_text => lv_message_text,
19366 p_error_text => lv_error_text,
19367 p_token1 => 'TABLE_NAME',
19368 p_token_value1 => 'MSC_ST_CATEGORY_SETS');
19369
19370 IF lv_return <> 0 THEN
19371 RAISE ex_logging_err;
19372 END IF;
19373
19374 --Deletion is not allowed for this entity.
19375 v_sql_stmt := 06;
19376 lv_sql_stmt :=
19377 ' UPDATE msc_st_category_sets '
19378 ||' SET process_flag = '||G_ERROR_FLG||','
19379 ||' error_text = '||''''||lv_message_text||''''
19380 ||' WHERE deleted_flag = '||SYS_YES
19381 ||' AND process_flag = '||G_IN_PROCESS
19382 ||' AND batch_id = :lv_batch_id'
19383 ||' AND sr_instance_code = :v_instance_code';
19384
19385
19386 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
19387
19388 EXECUTE IMMEDIATE lv_sql_stmt
19389 USING lv_batch_id,
19390 v_instance_code;
19391
19392 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
19393 (p_app_short_name => 'MSC',
19394 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
19395 p_message_text => lv_message_text,
19396 p_error_text => lv_error_text,
19397 p_token1 => 'COLUMN_NAME',
19398 p_token_value1 => 'DELETED_FLAG',
19399 p_token2 => 'DEFAULT_VALUE',
19400 p_token_value2 => SYS_NO);
19401
19402 IF lv_return <> 0 THEN
19403 RAISE ex_logging_err;
19404 END IF;
19405
19406 lv_where_str :=
19407 ' AND NVL(deleted_flag,'||NULL_VALUE||') '
19408 ||' NOT IN(1,2)';
19409
19410 --Logging a warning for those records where the deleted_flag value
19411 --is other than Yes/No.
19412 lv_return := MSC_ST_UTIL.LOG_ERROR
19413 (p_table_name => 'MSC_ST_CATEGORY_SETS',
19414 p_instance_code => v_instance_code,
19415 p_row => lv_column_names,
19416 p_severity => G_SEV_WARNING,
19417 p_message_text => lv_message_text,
19418 p_error_text => lv_error_text,
19419 p_batch_id => lv_batch_id,
19420 p_where_str => lv_where_str,
19421 p_col_name => 'DELETED_FLAG',
19422 p_debug => v_debug,
19423 p_default_value => SYS_NO);
19424
19425 IF lv_return <> 0 THEN
19426 RAISE ex_logging_err;
19427 END IF;
19428
19429 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
19430 (p_app_short_name => 'MSC',
19431 p_error_code => 'MSC_PP_COL_VAL_NULL',
19432 p_message_text => lv_message_text,
19433 p_error_text => lv_error_text,
19434 p_token1 => 'COLUMN_NAME',
19435 p_token_value1 => 'CATEGORY_SET_NAME');
19436
19437 IF lv_return <> 0 THEN
19438 RAISE ex_logging_err;
19439 END IF;
19440
19441 v_sql_stmt := 07;
19442 lv_sql_stmt :=
19443 ' UPDATE msc_st_category_sets '
19444 ||' SET process_flag = '||G_ERROR_FLG||','
19445 ||' error_text = '||''''||lv_message_text||''''
19446 ||' WHERE NVL(category_set_name,'||''''||NULL_CHAR||''''||')'
19447 ||' = '||''''||NULL_CHAR||''''
19448 ||' AND batch_id = :lv_batch_id'
19449 ||' AND process_flag = '||G_IN_PROCESS
19450 ||' AND sr_instance_code = :v_instance_code';
19451
19452
19453 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
19454 EXECUTE IMMEDIATE lv_sql_stmt
19455 USING lv_batch_id,
19456 v_instance_code;
19457
19458
19459 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
19460 (p_app_short_name => 'MSC',
19461 p_error_code => 'MSC_PP_INVALID_VALUE',
19462 p_message_text => lv_message_text,
19463 p_error_text => lv_error_text,
19464 p_token1 => 'COLUMN_NAME',
19465 p_token_value1 => 'CONTROL_LEVEL OR DEFAULT_FLAG');
19466
19467 IF lv_return <> 0 THEN
19468 RAISE ex_logging_err;
19469 END IF;
19470
19471 v_sql_stmt := 08;
19472 lv_sql_stmt :=
19473 ' UPDATE msc_st_category_sets '
19474 ||' SET process_flag = '||G_ERROR_FLG||','
19475 ||' error_text = '||''''||lv_message_text||''''
19476 ||' WHERE (NVL(control_level,'||NULL_VALUE||') NOT IN(1,2)'
19477 ||' OR NVL(default_flag,' ||NULL_VALUE||') NOT IN(1,2))'
19478 ||' AND batch_id = :lv_batch_id'
19479 ||' AND process_flag = '||G_IN_PROCESS
19480 ||' AND sr_instance_code = :v_instance_code';
19481
19482
19483 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
19484 EXECUTE IMMEDIATE lv_sql_stmt
19485 USING lv_batch_id,
19486 v_instance_code;
19487
19488
19489 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
19490 (p_app_short_name => 'MSC',
19491 p_error_code => 'MSC_PP_DEFAULT_FLG_INVALID',
19492 p_message_text => lv_message_text,
19493 p_error_text => lv_error_text);
19494
19495 IF lv_return <> 0 THEN
19496 RAISE ex_logging_err;
19497 END IF;
19498
19499 --There can be only one record in the staging/ODS with the
19500 --default_flag = 'YES'
19501 v_sql_stmt := 09;
19502 lv_sql_stmt :=
19503 'UPDATE msc_st_category_sets mcs1'
19504 ||' SET process_flag = '||G_ERROR_FLG||','
19505 ||' error_text = '||''''||lv_message_text||''''
19506 ||' WHERE EXISTS( SELECT 1 '
19507 ||' FROM msc_st_category_sets mcs2'
19508 ||' WHERE mcs2.sr_instance_code = mcs1.sr_instance_code'
19509 ||' AND mcs2.process_flag IN(2,5)'
19510 ||' AND mcs2.default_flag = '||SYS_YES
19511 ||' GROUP BY sr_instance_code'
19512 ||' HAVING COUNT(*) > 1'
19513 ||' UNION'
19514 ||' SELECT 1 '
19515 ||' FROM msc_category_sets mcs3'
19516 ||' WHERE mcs3.sr_instance_id = :v_instance_id'
19517 ||' AND mcs3.category_set_name <> mcs1.category_set_name'
19518 ||' AND mcs3.default_flag = '||SYS_YES||')'
19519 ||' AND mcs1.default_flag = '||SYS_YES
19520 ||' AND mcs1.batch_id = :lv_batch_id'
19521 ||' AND mcs1.process_flag = '||G_IN_PROCESS
19522 ||' AND mcs1.sr_instance_code = :v_instance_code'
19523 ||' AND NVL(mcs1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
19524
19525
19526 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
19527
19528 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_id,
19529 lv_batch_id,
19530 v_instance_code;
19531
19532
19533 --Derive sr_category_set_id.
19534 v_sql_stmt := 10;
19535 lv_sql_stmt :=
19536 ' UPDATE msc_st_category_sets'
19537 ||' SET sr_category_set_id = (SELECT local_id'
19538 ||' FROM msc_local_id_misc'
19539 ||' WHERE char1 = sr_instance_code'
19540 ||' AND NVL(char2, '||''''||NULL_CHAR||''''||')='
19541 ||' NVL(company_name,'||''''||NULL_CHAR||''''||')'
19542 ||' AND char3 = category_set_name'
19543 ||' AND entity_name = ''SR_CATEGORY_SET_ID'' )'
19544 ||' WHERE batch_id = :lv_batch_id'
19545 ||' AND process_flag = '||G_IN_PROCESS
19546 ||' AND sr_instance_code = :v_instance_code';
19547
19548
19549 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
19550 EXECUTE IMMEDIATE lv_sql_stmt
19551 USING lv_batch_id,
19552 v_instance_code;
19553
19554 --Call to customised validation.
19555 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
19556 (ERRBUF => lv_error_text,
19557 RETCODE => lv_return,
19558 pBatchID => lv_batch_id,
19559 pInstanceCode => v_instance_code,
19560 pEntityName => 'MSC_ST_CATEGORY_SETS',
19561 pInstanceID => v_instance_id);
19562
19563 IF NVL(lv_return,0) <> 0 THEN
19564 RAISE ex_logging_err;
19565 END IF;
19566
19567 OPEN c2(lv_batch_id);
19568 FETCH c2 BULK COLLECT INTO lb_rowid ;
19569
19570 IF c2%ROWCOUNT > 0 THEN
19571 v_sql_stmt := 11;
19572 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
19573 UPDATE msc_st_category_sets
19574 SET sr_category_set_id = msc_st_sr_category_set_id_s.NEXTVAL
19575 WHERE rowid = lb_rowid(j);
19576
19577 v_sql_stmt := 12;
19578 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
19579 INSERT INTO msc_local_id_misc
19580 (local_id,
19581 st_transaction_id,
19582 instance_id,
19583 entity_name,
19584 data_source_type,
19585 char1,
19586 char2,
19587 char3,
19588 SOURCE_SR_CATEGORY_SET_ID,
19589 last_update_date,
19590 last_updated_by,
19591 creation_date,
19592 created_by)
19593 SELECT
19594 sr_category_set_id,
19595 st_transaction_id,
19596 v_instance_id,
19597 'SR_CATEGORY_SET_ID',
19598 data_source_type,
19599 v_instance_code,
19600 company_name,
19601 category_set_name,
19602 SOURCE_SR_CATEGORY_SET_ID,
19603 v_current_date,
19604 v_current_user,
19605 v_current_date,
19606 v_current_user
19607 FROM msc_st_category_sets
19608 WHERE rowid = lb_rowid(j);
19609
19610 END IF;
19611 CLOSE c2 ;
19612
19613 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
19614 (p_table_name => 'MSC_ST_CATEGORY_SETS',
19615 p_instance_id => v_instance_id,
19616 p_instance_code => v_instance_code,
19617 p_process_flag => G_VALID,
19618 p_error_text => lv_error_text,
19619 p_debug => v_debug,
19620 p_batch_id => lv_batch_id);
19621
19622 IF lv_return <> 0 THEN
19623 RAISE ex_logging_err;
19624 END IF;
19625
19626 lv_return := MSC_ST_UTIL.LOG_ERROR
19627 (p_table_name => 'MSC_ST_CATEGORY_SETS',
19628 p_instance_code => v_instance_code,
19629 p_row => lv_column_names,
19630 p_severity => G_SEV_ERROR,
19631 p_message_text => NULL,
19632 p_error_text => lv_error_text,
19633 p_debug => v_debug,
19634 p_batch_id => lv_batch_id);
19635 IF lv_return <> 0 THEN
19636 RAISE ex_logging_err;
19637 END IF;
19638 COMMIT;
19639 END LOOP;
19640
19641 EXCEPTION
19642 WHEN too_many_rows THEN
19643 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_CATEGORY_SET'||'('
19644 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
19645 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
19646 ROLLBACK;
19647
19648 WHEN ex_logging_err THEN
19649 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
19650 ROLLBACK;
19651
19652 WHEN OTHERS THEN
19653 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_CATEGORY_SET'||'('
19654 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
19655 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
19656 ROLLBACK;
19657
19658 END LOAD_CATEGORY_SET;
19659
19660 /*==========================================================================+
19661 | DESCRIPTION : This procedure performs validation and loads data into the |
19662 | table msc_st_units_of_measure. |
19663 +==========================================================================*/
19664 PROCEDURE LOAD_UOM IS
19665 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
19666 lb_rowid RowidTab;
19667 lv_return NUMBER;
19668 lv_error_text VARCHAR2(250);
19669 lv_where_str VARCHAR2(5000);
19670 lv_sql_stmt VARCHAR2(5000);
19671 lv_column_names VARCHAR2(5000);
19672 lv_batch_id msc_st_units_of_measure.batch_id%TYPE;
19673 lv_message_text msc_errors.error_text%TYPE;
19674
19675 ex_logging_err EXCEPTION;
19676
19677 CURSOR c1(p_batch_id NUMBER) IS
19678 SELECT rowid
19679 FROM msc_st_units_of_measure
19680 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
19681 AND batch_id = p_batch_id
19682 AND sr_instance_code = v_instance_code;
19683
19684 BEGIN
19685 --*********Validation for msc_st_units_of_measure***********
19686 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
19687 (p_app_short_name => 'MSC',
19688 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
19689 p_message_text => lv_message_text,
19690 p_error_text => lv_error_text);
19691
19692 IF lv_return <> 0 THEN
19693 RAISE ex_logging_err;
19694 END IF;
19695
19696 --Duplicate records check for the records whose source is XML
19697 v_sql_stmt := 01;
19698 lv_sql_stmt :=
19699 ' UPDATE msc_st_units_of_measure mum1'
19700 ||' SET process_flag = '||G_ERROR_FLG||','
19701 ||' error_text = '||''''||lv_message_text||''''
19702 ||' WHERE message_id < (SELECT MAX(message_id)'
19703 ||' FROM msc_st_units_of_measure mum2'
19704 ||' WHERE NVL(mum2.unit_of_measure,' ||''''||NULL_CHAR||''''||') ='
19705 ||' NVL(mum1.unit_of_measure,' ||''''||NULL_CHAR||''''||') '
19706 ||' AND NVL(mum2.company_name, ' ||''''||NULL_CHAR||''''||') = '
19707 ||' NVL(mum1.company_name, ' ||''''||NULL_CHAR||''''||')'
19708 ||' AND mum2.uom_code = mum1.uom_code'
19709 ||' AND mum2.process_flag = '||G_IN_PROCESS
19710 ||' AND NVL(mum2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
19711 ||' AND mum1.process_flag = '||G_IN_PROCESS
19712 ||' AND mum1.sr_instance_code = :v_instance_code'
19713 ||' AND NVL(mum1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
19714
19715
19716
19717 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
19718
19719 EXECUTE IMMEDIATE lv_sql_stmt
19720 USING v_instance_code;
19721
19722 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
19723 (p_app_short_name => 'MSC',
19724 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
19725 p_message_text => lv_message_text,
19726 p_error_text => lv_error_text);
19727
19728 IF lv_return <> 0 THEN
19729 RAISE ex_logging_err;
19730 END IF;
19731
19732 --Duplicate records check for the records whose source is other than XML
19733 --Different SQL is used because in XML we can identify the latest records
19734 --whereas in batch load we cannot.
19735 v_sql_stmt := 02;
19736 lv_sql_stmt :=
19737 ' UPDATE msc_st_units_of_measure mum1'
19738 ||' SET process_flag = '||G_ERROR_FLG||','
19739 ||' error_text = '||''''||lv_message_text||''''
19740 ||' WHERE EXISTS( SELECT 1 '
19741 ||' FROM msc_st_units_of_measure mum2'
19742 ||' WHERE NVL(mum2.unit_of_measure, '||''''||NULL_CHAR||''''||')'
19743 ||' = NVL(mum1.unit_of_measure,'||''''||NULL_CHAR||''''||')'
19744 ||' AND NVL(mum2.company_name, '||''''||NULL_CHAR||''''||') = '
19745 ||' NVL(mum1.company_name, '||''''||NULL_CHAR||''''||')'
19746 ||' AND mum2.uom_code = mum1.uom_code'
19747 ||' AND mum2.process_flag ='|| G_IN_PROCESS
19748 ||' AND NVL(mum2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
19749 ||' GROUP BY uom_code,company_name,unit_of_measure'
19750 ||' HAVING COUNT(*) > 1)'
19751 ||' AND mum1.process_flag = '||G_IN_PROCESS
19752 ||' AND mum1.sr_instance_code = :v_instance_code'
19753 ||' AND NVL(mum1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
19754
19755
19756
19757 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
19758
19759 EXECUTE IMMEDIATE lv_sql_stmt
19760 USING v_instance_code;
19761
19762 lv_column_names :=
19763 'UNIT_OF_MEASURE ||''~''||'
19764 ||'UOM_CODE ||''~''||'
19765 ||'UOM_CLASS ||''~''||'
19766 ||'BASE_UOM_FLAG ||''~''||'
19767 ||'SR_INSTANCE_CODE ||''~''||'
19768 ||'DISABLE_DATE ||''~''||'
19769 ||'DESCRIPTION ||''~''||'
19770 ||'COMPANY_NAME ||''~''||'
19771 ||'DELETED_FLAG';
19772
19773 LOOP
19774 v_sql_stmt := 03;
19775 SELECT msc_st_batch_id_s.NEXTVAL
19776 INTO lv_batch_id
19777 FROM dual;
19778
19779 v_sql_stmt := 04;
19780 lv_sql_stmt :=
19781 'UPDATE msc_st_units_of_measure '
19782 ||' SET batch_id = :lv_batch_id'
19783 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
19784 ||' AND sr_instance_code = :v_instance_code'
19785 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
19786 ||' AND rownum <= '||v_batch_size;
19787
19788
19789 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
19790
19791 EXECUTE IMMEDIATE lv_sql_stmt
19792 USING lv_batch_id,
19793 v_instance_code;
19794
19795 EXIT WHEN SQL%NOTFOUND;
19796
19797 OPEN c1(lv_batch_id);
19798 FETCH c1 BULK COLLECT INTO lb_rowid;
19799 CLOSE c1;
19800
19801 v_sql_stmt := 05;
19802 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
19803 UPDATE msc_st_units_of_measure
19804 SET st_transaction_id = msc_st_units_of_measure_s.NEXTVAL,
19805 refresh_id = v_refresh_id,
19806 last_update_date = v_current_date,
19807 last_updated_by = v_current_user,
19808 creation_date = v_current_date,
19809 created_by = v_current_user
19810 WHERE rowid = lb_rowid(j);
19811
19812 --Deletion is not allowed on this table.
19813 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
19814 (p_app_short_name => 'MSC',
19815 p_error_code => 'MSC_PP_NO_DELETION',
19816 p_message_text => lv_message_text,
19817 p_error_text => lv_error_text,
19818 p_token1 => 'TABLE_NAME',
19819 p_token_value1 => 'MSC_ST_UNITS_OF_MEASURE');
19820
19821 IF lv_return <> 0 THEN
19822 RAISE ex_logging_err;
19823 END IF;
19824
19825 v_sql_stmt := 06;
19826 lv_sql_stmt :=
19827 'UPDATE msc_st_units_of_measure '
19828 ||' SET process_flag = '||G_ERROR_FLG||','
19829 ||' error_text = '||''''||lv_message_text||''''
19830 ||' WHERE deleted_flag = '||SYS_YES
19831 ||' AND process_flag = '||G_IN_PROCESS
19832 ||' AND batch_id = :lv_batch_id'
19833 ||' AND sr_instance_code = :v_instance_code';
19834
19835
19836 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
19837
19838 EXECUTE IMMEDIATE lv_sql_stmt
19839 USING lv_batch_id,
19840 v_instance_code;
19841
19842 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
19843 (p_app_short_name => 'MSC',
19844 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
19845 p_message_text => lv_message_text,
19846 p_error_text => lv_error_text,
19847 p_token1 => 'COLUMN_NAME',
19848 p_token_value1 => 'DELETED_FLAG',
19849 p_token2 => 'DEFAULT_VALUE',
19850 p_token_value2 => SYS_NO);
19851
19852 IF lv_return <> 0 THEN
19853 RAISE ex_logging_err;
19854 END IF;
19855
19856 lv_where_str :=
19857 ' AND NVL(deleted_flag,'||NULL_VALUE||') '
19858 ||' NOT IN(1,2)';
19859 --Log a warning for those records where the deleted_flag has a value other
19860 --than SYS_NO
19861 lv_return := MSC_ST_UTIL.LOG_ERROR
19862 (p_table_name => 'MSC_ST_UNITS_OF_MEASURE',
19863 p_instance_code => v_instance_code,
19864 p_row => lv_column_names,
19865 p_severity => G_SEV_WARNING,
19866 p_message_text => lv_message_text,
19867 p_error_text => lv_error_text,
19868 p_batch_id => lv_batch_id,
19869 p_where_str => lv_where_str,
19870 p_col_name => 'DELETED_FLAG',
19871 p_debug => v_debug,
19872 p_default_value => SYS_NO);
19873
19874 IF lv_return <> 0 THEN
19875 RAISE ex_logging_err;
19876 END IF;
19877
19878 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
19879 (p_app_short_name => 'MSC',
19880 p_error_code => 'MSC_PP_COL_VAL_NULL',
19881 p_message_text => lv_message_text,
19882 p_error_text => lv_error_text,
19883 p_token1 => 'COLUMN_NAME',
19884 p_token_value1 => 'UOM_CODE OR UOM_CLASS');
19885
19886 IF lv_return <> 0 THEN
19887 RAISE ex_logging_err;
19888 END IF;
19889
19890 v_sql_stmt := 07;
19891 lv_sql_stmt :=
19892 'UPDATE msc_st_units_of_measure '
19893 ||' SET process_flag = '||G_ERROR_FLG||','
19894 ||' error_text = '||''''||lv_message_text||''''
19895 ||' WHERE (NVL(uom_code, '||''''||NULL_CHAR||''''||') '
19896 ||' = '||''''||NULL_CHAR||''''
19897 ||' OR NVL(uom_class, '||''''||NULL_CHAR||''''||')'
19898 ||' = '||''''||NULL_CHAR||''''
19899 ||' AND batch_id = :lv_batch_id'
19900 ||' AND sr_instance_code = :v_instance_code'
19901 ||' AND process_flag = '||G_IN_PROCESS||')';
19902
19903
19904 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
19905
19906 EXECUTE IMMEDIATE lv_sql_stmt
19907 USING lv_batch_id,
19908 v_instance_code;
19909
19910 v_sql_stmt := 08;
19911 lv_sql_stmt :=
19912 'UPDATE msc_st_units_of_measure '
19913 ||' SET unit_of_measure = uom_code'
19914 ||' WHERE NVL(unit_of_measure,'||''''||NULL_CHAR||''''||') '
19915 ||' = '||''''||NULL_CHAR||''''
19916 ||' AND batch_id = :lv_batch_id'
19917 ||' AND sr_instance_code = :v_instance_code'
19918 ||' AND process_flag = '||G_IN_PROCESS;
19919
19920
19921
19922 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
19923
19924 EXECUTE IMMEDIATE lv_sql_stmt
19925 USING lv_batch_id,
19926 v_instance_code;
19927
19928 --A UOM class can have one and only one base UOM.
19929
19930 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
19931 (p_app_short_name => 'MSC',
19932 p_error_code => 'MSC_PP_BASE_UOM_INVALID',
19933 p_message_text => lv_message_text,
19934 p_error_text => lv_error_text);
19935
19936 IF lv_return <> 0 THEN
19937 RAISE ex_logging_err;
19938 END IF;
19939
19940 v_sql_stmt := 09;
19941 lv_sql_stmt :=
19942 'UPDATE msc_st_units_of_measure mum1 '
19943 ||' SET process_flag = '||G_ERROR_FLG||','
19944 ||' error_text = '||''''||lv_message_text||''''
19945 ||' WHERE EXISTS(SELECT 1'
19946 ||' FROM msc_units_of_measure mum2'
19947 ||' WHERE mum2.unit_of_measure <> '
19948 ||' NVL(mum1.unit_of_measure,'||''''||NULL_CHAR||''''||' )'
19949 ||' AND mum2.uom_code <> '
19950 ||' NVL(mum1.uom_code, '||''''||NULL_CHAR||''''||' )'
19951 ||' AND mum2.uom_class = '
19952 ||' NVL(mum1.uom_class, '||''''||NULL_CHAR||''''||' )'
19953 ||' AND mum2.base_uom_flag = ''Y'' '
19954 ||' UNION'
19955 ||' SELECT 1'
19956 ||' FROM msc_st_units_of_measure mum3'
19957 ||' WHERE NVL(mum3.unit_of_measure,'||''''||NULL_CHAR||''''||') <> '
19958 ||' NVL(mum1.unit_of_measure,'||''''||NULL_CHAR||''''||')'
19959 ||' AND NVL(mum3.uom_code, '||''''||NULL_CHAR||''''||') <> '
19960 ||' NVL(mum1.uom_code, '||''''||NULL_CHAR||''''||')'
19961 ||' AND NVL(mum3.uom_class, '||''''||NULL_CHAR||''''||') = '
19962 ||' NVL(mum1.uom_class, '||''''||NULL_CHAR||''''||')'
19963 ||' AND mum3.base_uom_flag = ''Y'' '
19964 ||' AND mum3.process_flag IN(2,5))'
19965 ||' AND mum1.base_uom_flag = ''Y'' '
19966 ||' AND process_flag = '||G_IN_PROCESS
19967 ||' AND batch_id = :lv_batch_id'
19968 ||' AND sr_instance_code = :v_instance_code';
19969
19970
19971 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
19972
19973 EXECUTE IMMEDIATE lv_sql_stmt
19974 USING lv_batch_id,
19975 v_instance_code;
19976
19977 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
19978 (p_app_short_name => 'MSC',
19979 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
19980 p_message_text => lv_message_text,
19981 p_error_text => lv_error_text,
19982 p_token1 => 'COLUMN_NAME',
19983 p_token_value1 => 'BASE_UOM_FLAG');
19984
19985 IF lv_return <> 0 THEN
19986 RAISE ex_logging_err;
19987 END IF;
19988
19989 lv_where_str :=
19990 ' AND NVL(base_uom_flag,'||''''||NULL_CHAR||''''||') '
19991 ||' NOT IN(''Y'',''N'' )';
19992 --Log a warning for those records where the base_uom_flag has value
19993 --other than('Y','N')
19994
19995 lv_return := MSC_ST_UTIL.LOG_ERROR
19996 (p_table_name => 'MSC_ST_UNITS_OF_MEASURE',
19997 p_instance_code => v_instance_code,
19998 p_row => lv_column_names,
19999 p_severity => G_SEV_WARNING,
20000 p_message_text => lv_message_text,
20001 p_error_text => lv_error_text,
20002 p_batch_id => lv_batch_id,
20003 p_where_str => lv_where_str,
20004 p_col_name => 'BASE_UOM_FLAG',
20005 p_debug => v_debug,
20006 p_default_value => '''N''');
20007
20008 IF lv_return <> 0 THEN
20009 RAISE ex_logging_err;
20010 END IF;
20011
20012 --Call to customised validation.
20013 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
20014 (ERRBUF => lv_error_text,
20015 RETCODE => lv_return,
20016 pBatchID => lv_batch_id,
20017 pInstanceCode => v_instance_code,
20018 pEntityName => 'MSC_ST_UNTIS_OF_MEASURE',
20019 pInstanceID => v_instance_id);
20020
20021 IF NVL(lv_return,0) <> 0 THEN
20022 RAISE ex_logging_err;
20023 END IF;
20024
20025 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
20026 (p_table_name => 'MSC_ST_UNITS_OF_MEASURE',
20027 p_instance_id => v_instance_id,
20028 p_instance_code => v_instance_code,
20029 p_process_flag => G_VALID,
20030 p_error_text => lv_error_text,
20031 p_debug => v_debug,
20032 p_batch_id => lv_batch_id);
20033
20034 IF lv_return <> 0 THEN
20035 RAISE ex_logging_err;
20036 END IF;
20037
20038 lv_return := MSC_ST_UTIL.LOG_ERROR
20039 (p_table_name => 'MSC_ST_UNITS_OF_MEASURE',
20040 p_instance_code => v_instance_code,
20041 p_row => lv_column_names,
20042 p_severity => G_SEV_ERROR,
20043 p_message_text => NULL,
20044 p_error_text => lv_error_text,
20045 p_debug => v_debug,
20046 p_batch_id => lv_batch_id);
20047
20048 IF lv_return <> 0 THEN
20049 RAISE ex_logging_err;
20050 END IF;
20051 COMMIT;
20052 END LOOP;
20053
20054 EXCEPTION
20055 WHEN ex_logging_err THEN
20056 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
20057 ROLLBACK;
20058
20059 WHEN OTHERS THEN
20060 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_UOM'||'('
20061 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
20062 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
20063 ROLLBACK;
20064
20065 END LOAD_UOM;
20066
20067 /*==========================================================================+
20068 | DESCRIPTION : This procedure performs validation and loads data into the |
20069 | tables msc_st_uom_class_conversions and |
20070 | msc_st_uom_conversions. |
20071 +==========================================================================*/
20072 PROCEDURE LOAD_UOM_CLASS_CONV IS
20073 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
20074 TYPE CharTblTyp IS TABLE OF VARCHAR2(1000);
20075 lb_rowid RowidTab;
20076 lb_item CharTblTyp;
20077 lb_from_uom_code CharTblTyp;
20078 lb_to_uom_code CharTblTyp;
20079 lb_org CharTblTyp;
20080 lb_comp CharTblTyp;
20081 lv_return NUMBER;
20082 lv_error_text VARCHAR2(250);
20083 lv_where_str VARCHAR2(5000);
20084 lv_sql_stmt VARCHAR2(5000);
20085 lv_column_names VARCHAR2(5000);
20086 lv_batch_id msc_st_uom_class_conversions.batch_id%TYPE;
20087 lv_message_text msc_errors.error_text%TYPE;
20088
20089 ex_logging_err EXCEPTION;
20090
20091 CURSOR c_udk1 is
20092 SELECT from_uom_code, to_uom_code, item_name, company_name
20093 FROM msc_st_uom_class_conversions mcc2
20094 WHERE mcc2.process_flag = G_IN_PROCESS
20095 AND item_name is not null
20096 AND sr_instance_code = v_instance_code
20097 AND NVL(mcc2.message_id, NULL_VALUE) = NULL_VALUE
20098 GROUP BY from_uom_code, to_uom_code, item_name, company_name
20099 HAVING COUNT(*) > 1;
20100
20101 CURSOR c_udk2 is select from_uom_code, to_uom_code, item_name, company_name
20102 FROM msc_st_uom_class_conversions mcc2
20103 WHERE mcc2.process_flag = G_IN_PROCESS
20104 AND item_name is null
20105 AND sr_instance_code = v_instance_code
20106 AND NVL(mcc2.message_id, NULL_VALUE) = NULL_VALUE
20107 GROUP BY from_uom_code, to_uom_code, item_name, company_name
20108 HAVING COUNT(*) > 1;
20109
20110 CURSOR c2(p_batch_id NUMBER) IS
20111 SELECT rowid
20112 FROM msc_st_uom_class_conversions
20113 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
20114 AND batch_id = p_batch_id
20115 AND sr_instance_code = v_instance_code;
20116
20117 CURSOR c3(p_batch_id NUMBER) IS
20118 SELECT rowid
20119 FROM msc_st_uom_conversions
20120 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
20121 AND batch_id = p_batch_id
20122 AND sr_instance_code = v_instance_code;
20123
20124 BEGIN
20125 --*****Validation for the table msc_st_uom_class_conversions.*****
20126
20127 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
20128 (p_app_short_name => 'MSC',
20129 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
20130 p_message_text => lv_message_text,
20131 p_error_text => lv_error_text);
20132
20133 IF lv_return <> 0 THEN
20134 RAISE ex_logging_err;
20135 END IF;
20136
20137 /* --Remove organization code from records which have item name null
20138
20139 UPDATE msc_st_uom_class_conversions
20140 SET organization_code = ''
20141 WHERE sr_instance_code = v_instance_code
20142 AND process_flag = G_IN_PROCESS
20143 AND item_name is null;*/
20144
20145 --Duplicate records check for the records whose source is XML.
20146 v_sql_stmt := 10;
20147 lv_sql_stmt :=
20148 'UPDATE msc_st_uom_class_conversions mcc1 '
20149 ||' SET process_flag = '||G_ERROR_FLG||','
20150 ||' error_text = '||''''||lv_message_text||''''
20151 ||' WHERE message_id < (SELECT MAX(message_id)'
20152 ||' FROM msc_st_uom_class_conversions mcc2'
20153 ||' WHERE NVL(mcc2.item_name, '||''''||NULL_CHAR||''''||') = '
20154 ||' NVL(mcc1.item_name, '||''''||NULL_CHAR||''''||')'
20155 ||' AND NVL(mcc2.from_uom_code, '||''''||NULL_CHAR||''''||') = '
20156 ||' NVL(mcc1.from_uom_code, '||''''||NULL_CHAR||''''||')'
20157 ||' AND NVL(mcc2.to_uom_code, '||''''||NULL_CHAR||''''||') = '
20158 ||' NVL(mcc1.to_uom_code, '||''''||NULL_CHAR||''''||')'
20159 ||' AND NVL(mcc2.company_name, '||''''||NULL_CHAR||''''||') = '
20160 ||' NVL(mcc1.company_name, '||''''||NULL_CHAR||''''||')'
20161 ||' AND mcc2.process_flag = '||G_IN_PROCESS
20162 ||' AND NVL(mcc2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
20163 ||' AND mcc1.process_flag = '||G_IN_PROCESS
20164 ||' AND mcc1.sr_instance_code = :v_instance_code'
20165 ||' AND NVL(mcc1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
20166
20167
20168
20169 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
20170
20171 EXECUTE IMMEDIATE lv_sql_stmt
20172 USING v_instance_code;
20173
20174
20175 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
20176 (p_app_short_name => 'MSC',
20177 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
20178 p_message_text => lv_message_text,
20179 p_error_text => lv_error_text);
20180
20181 IF lv_return <> 0 THEN
20182 RAISE ex_logging_err;
20183 END IF;
20184
20185 --Duplicate records check for the records whose source is other than XML
20186 --Different SQL is used because in XML we can identify the latest records
20187 --whereas in batch load we cannot.
20188 v_sql_stmt := 11;
20189 /*
20190 lv_sql_stmt :=
20191 'UPDATE msc_st_uom_class_conversions mcc1 '
20192 ||' SET process_flag = '||G_ERROR_FLG||','
20193 ||' error_text = '||''''||lv_message_text||''''
20194 ||' WHERE EXISTS( SELECT 1 '
20195 ||' FROM msc_st_uom_class_conversions mcc2'
20196 ||' WHERE NVL(mcc2.item_name, '||''''||NULL_CHAR||''''||') = '
20197 ||' NVL(mcc1.item_name, '||''''||NULL_CHAR||''''||')'
20198 ||' AND NVL(mcc2.organization_code, '||''''||NULL_CHAR||''''||') = '
20199 ||' NVL(mcc1.organization_code, '||''''||NULL_CHAR||''''||')'
20200 ||' AND NVL(mcc2.from_uom_code, '||''''||NULL_CHAR||''''||') = '
20201 ||' NVL(mcc1.from_uom_code, '||''''||NULL_CHAR||''''||')'
20202 ||' AND NVL(mcc2.to_uom_code, '||''''||NULL_CHAR||''''||') = '
20203 ||' NVL(mcc1.to_uom_code, '||''''||NULL_CHAR||''''||')'
20204 ||' AND NVL(mcc2.company_name, '||''''||NULL_CHAR||''''||') = '
20205 ||' NVL(mcc1.company_name, '||''''||NULL_CHAR||''''||')'
20206 ||' AND mcc2.process_flag = '||G_IN_PROCESS
20207 ||' AND NVL(mcc2.message_id, '||NULL_VALUE||') = '||NULL_VALUE
20208 ||' GROUP BY item_name,organization_code,company_name,'
20209 ||' from_uom_code,to_uom_code'
20210 ||' HAVING COUNT(*) > 1)'
20211 ||' AND mcc1.process_flag = '||G_IN_PROCESS
20212 ||' AND mcc1.sr_instance_code = :v_instance_code'
20213 ||' AND NVL(mcc1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
20214
20215
20216 msc_st_util.log_message(lv_sql_stmt);
20217
20218 EXECUTE IMMEDIATE lv_sql_stmt
20219 USING v_instance_code;
20220 */
20221
20222 BEGIN
20223
20224 BEGIN
20225 OPEN c_udk1;
20226 FETCH c_udk1 BULK COLLECT INTO lb_from_uom_code,lb_to_uom_code, lb_item,lb_comp;
20227 CLOSE c_udk1;
20228
20229 FORALL j IN lb_item.FIRST..lb_item.LAST
20230 UPDATE msc_st_uom_class_conversions SET process_flag = G_ERROR_FLG, error_text =lv_message_text
20231 WHERE from_uom_code= lb_from_uom_code(j)
20232 AND to_uom_code = lb_to_uom_code(j)
20233 AND item_name= lb_item(j)
20234 AND NVL(company_name, NULL_CHAR) = NVL(lb_comp(j), NULL_CHAR)
20235 AND process_flag = G_IN_PROCESS
20236 AND sr_instance_code = v_instance_code
20237 AND NVL(message_id, NULL_VALUE) = NULL_VALUE ;
20238 EXCEPTION
20239 when others then
20240 null;
20241 END;
20242
20243 BEGIN
20244 lb_item.DELETE;
20245 lb_from_uom_code.DELETE;
20246 lb_to_uom_code.DELETE;
20247 lb_comp.DELETE;
20248 OPEN c_udk2;
20249 FETCH c_udk2 BULK COLLECT INTO lb_from_uom_code,lb_to_uom_code, lb_item,lb_comp;
20250 CLOSE c_udk2;
20251
20252 FORALL j IN lb_item.FIRST..lb_item.LAST
20253 UPDATE msc_st_uom_class_conversions SET process_flag = G_ERROR_FLG, error_text =lv_message_text
20254 WHERE from_uom_code= lb_from_uom_code(j)
20255 AND to_uom_code = lb_to_uom_code(j)
20256 AND NVL(company_name, NULL_CHAR) = NVL(lb_comp(j), NULL_CHAR)
20257 AND item_name is null
20258 AND process_flag = G_IN_PROCESS
20259 AND sr_instance_code = v_instance_code
20260 AND NVL(message_id, NULL_VALUE) = NULL_VALUE ;
20261 EXCEPTION
20262 when others then
20263 null;
20264 END;
20265
20266 END;
20267
20268 lv_column_names :=
20269 'FROM_UNIT_OF_MEASURE||''~''||'
20270 ||'FROM_UOM_CODE ||''~''||'
20271 ||'FROM_UOM_CLASS ||''~''||'
20272 ||'TO_UNIT_OF_MEASURE||''~''||'
20273 ||'TO_UOM_CODE ||''~''||'
20274 ||'TO_UOM_CLASS ||''~''||'
20275 ||'CONVERSION_RATE ||''~''||'
20276 ||'SR_INSTANCE_CODE ||''~''||'
20277 ||'DISABLE_DATE ||''~''||'
20278 ||'ITEM_NAME ||''~''||'
20279 ||'ORGANIZATION_CODE ||''~''||'
20280 ||'COMPANY_NAME ||''~''||'
20281 ||'DELETED_FLAG';
20282
20283 LOOP
20284 v_sql_stmt := 12;
20285 SELECT msc_st_batch_id_s.NEXTVAL
20286 INTO lv_batch_id
20287 FROM dual;
20288
20289 v_sql_stmt := 13;
20290 lv_sql_stmt :=
20291 'UPDATE msc_st_uom_class_conversions '
20292 ||' SET batch_id = :lv_batch_id'
20293 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
20294 ||' AND sr_instance_code = :v_instance_code'
20295 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
20296 ||' AND rownum <= '||v_batch_size;
20297
20298
20299 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
20300
20301 EXECUTE IMMEDIATE lv_sql_stmt
20302 USING lv_batch_id,
20303 v_instance_code;
20304
20305 EXIT WHEN SQL%NOTFOUND;
20306
20307 OPEN c2(lv_batch_id);
20308 FETCH c2 BULK COLLECT INTO lb_rowid;
20309 CLOSE c2;
20310
20311 v_sql_stmt := 14;
20312 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
20313 UPDATE msc_st_uom_class_conversions
20314 SET st_transaction_id = msc_st_uom_class_conversions_s.NEXTVAL,
20315 refresh_id = v_refresh_id,
20316 last_update_date = v_current_date,
20317 last_updated_by = v_current_user,
20318 creation_date = v_current_date,
20319 created_by = v_current_user
20320 WHERE rowid = lb_rowid(j);
20321
20322 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
20323 (p_app_short_name => 'MSC',
20324 p_error_code => 'MSC_PP_NO_DELETION',
20325 p_message_text => lv_message_text,
20326 p_error_text => lv_error_text,
20327 p_token1 => 'TABLE_NAME',
20328 p_token_value1 => 'MSC_ST_UOM_CLASS_CONVERSIONS');
20329
20330 IF lv_return <> 0 THEN
20331 RAISE ex_logging_err;
20332 END IF;
20333
20334 --Deletion is not allowed on this table.
20335 v_sql_stmt := 15;
20336 lv_sql_stmt :=
20337 'UPDATE msc_st_uom_class_conversions '
20338 ||' SET process_flag = '||G_ERROR_FLG||','
20339 ||' error_text = '||''''||lv_message_text||''''
20340 ||' WHERE deleted_flag = '||SYS_YES
20341 ||' AND process_flag = '||G_IN_PROCESS
20342 ||' AND batch_id = :lv_batch_id'
20343 ||' AND sr_instance_code = :v_instance_code';
20344
20345
20346 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
20347
20348 EXECUTE IMMEDIATE lv_sql_stmt
20349 USING lv_batch_id,
20350 v_instance_code;
20351
20352 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
20353 (p_app_short_name => 'MSC',
20354 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
20355 p_message_text => lv_message_text,
20356 p_error_text => lv_error_text,
20357 p_token1 => 'COLUMN_NAME',
20358 p_token_value1 => 'DELETED_FLAG',
20359 p_token2 => 'DEFAULT_VALUE',
20360 p_token_value2 => SYS_NO);
20361
20362 IF lv_return <> 0 THEN
20363 RAISE ex_logging_err;
20364 END IF;
20365
20366 lv_where_str := ' AND NVL(deleted_flag,'||NULL_VALUE||') '
20367 ||' NOT IN(1,2)';
20368
20369 --Log a warning for those records where the deleted_flag has a value other
20370 --than SYS_NO
20371 lv_return := MSC_ST_UTIL.LOG_ERROR
20372 (p_table_name => 'MSC_ST_UOM_CLASS_CONVERSIONS',
20373 p_instance_code => v_instance_code,
20374 p_row => lv_column_names,
20375 p_severity => G_SEV_WARNING,
20376 p_message_text => lv_message_text,
20377 p_error_text => lv_error_text,
20378 p_batch_id => lv_batch_id,
20379 p_where_str => lv_where_str,
20380 p_col_name => 'DELETED_FLAG',
20381 p_debug => v_debug,
20382 p_default_value => SYS_NO);
20383
20384 IF lv_return <> 0 THEN
20385 RAISE ex_logging_err;
20386 END IF;
20387
20388 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
20389 (p_app_short_name => 'MSC',
20390 p_error_code => 'MSC_PP_COL_VAL_NULL',
20391 p_message_text => lv_message_text,
20392 p_error_text => lv_error_text,
20393 p_token1 => 'COLUMN_NAME',
20394 p_token_value1 => 'FROM_UOM_CODE OR FROM_UOM_CLASS OR'
20395 ||' TO_UOM_CODE OR TO_UOM_CLASS');
20396
20397 IF lv_return <> 0 THEN
20398 RAISE ex_logging_err;
20399 END IF;
20400
20401 v_sql_stmt := 16;
20402 lv_sql_stmt :=
20403 'UPDATE msc_st_uom_class_conversions'
20404 ||' SET process_flag = '||G_ERROR_FLG||','
20405 ||' error_text = '||''''||lv_message_text||''''
20406 ||' WHERE (NVL(from_uom_code,'||''''||NULL_CHAR||''''||') '
20407 ||' = '||''''||NULL_CHAR||''''
20408 ||' OR NVL(from_uom_class,'||''''||NULL_CHAR||''''||') '
20409 ||' = '||''''||NULL_CHAR||''''
20410 ||' OR NVL(to_uom_code, '||''''||NULL_CHAR||''''||') '
20411 ||' = '||''''||NULL_CHAR||''''
20412 ||' OR NVL(to_uom_class, '||''''||NULL_CHAR||''''||') '
20413 ||' = '||''''||NULL_CHAR||''''||') '
20414 ||' AND process_flag = '||G_IN_PROCESS
20415 ||' AND batch_id = :lv_batch_id'
20416 ||' AND sr_instance_code = :v_instance_code';
20417
20418
20419
20420 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
20421
20422 EXECUTE IMMEDIATE lv_sql_stmt
20423 USING lv_batch_id,
20424 v_instance_code;
20425
20426 v_sql_stmt := 17;
20427 lv_sql_stmt :=
20428 'UPDATE msc_st_uom_class_conversions'
20429 ||' SET from_unit_of_measure = from_uom_code'
20430 ||' WHERE NVL(from_unit_of_measure,'||''''||NULL_CHAR||''''||')'
20431 ||' = '||''''||NULL_CHAR||''''
20432 ||' AND process_flag = '||G_IN_PROCESS
20433 ||' AND batch_id = :lv_batch_id'
20434 ||' AND sr_instance_code = :v_instance_code';
20435
20436
20437 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
20438
20439 EXECUTE IMMEDIATE lv_sql_stmt
20440 USING lv_batch_id,
20441 v_instance_code;
20442
20443 v_sql_stmt := 18;
20444 lv_sql_stmt :=
20445 'UPDATE msc_st_uom_class_conversions '
20446 ||' SET to_unit_of_measure = to_uom_code'
20447 ||' WHERE NVL(to_unit_of_measure,'||''''||NULL_CHAR||''''||')'
20448 ||' = '||''''||NULL_CHAR||''''
20449 ||' AND process_flag = '||G_IN_PROCESS
20450 ||' AND batch_id = :lv_batch_id'
20451 ||' AND sr_instance_code = :v_instance_code';
20452
20453
20454 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
20455
20456 EXECUTE IMMEDIATE lv_sql_stmt
20457 USING lv_batch_id,
20458 v_instance_code;
20459
20460 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
20461 (p_app_short_name => 'MSC',
20462 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
20463 p_message_text => lv_message_text,
20464 p_error_text => lv_error_text,
20465 p_token1 => 'COLUMN_NAMES',
20466 p_token_value1 => 'FROM_UOM_CODE, FROM_UOM_CLASS AND FROM_UNIT_OF_MEASURE',
20467 p_token2 => 'MASTER_TABLE',
20468 p_token_value2 => 'MSC_ST_UNITS_OF_MEASURE',
20469 p_token3 => 'MASTER_TABLE',
20470 p_token_value3 => 'MSC_ST_UNITS_OF_MEASURE',
20471 p_token4 => 'CHILD_TABLE',
20472 p_token_value4 => 'MSC_ST_UOM_CLASS_CONVERSIONS');
20473 IF lv_return <> 0 THEN
20474 RAISE ex_logging_err;
20475 END IF;
20476
20477 v_sql_stmt := 19;
20478 lv_sql_stmt :=
20479 'UPDATE msc_st_uom_class_conversions mcc '
20480 ||' SET process_flag = '||G_ERROR_FLG||','
20481 ||' error_text = '||''''||lv_message_text||''''
20482 ||' WHERE NOT EXISTS(SELECT 1'
20483 ||' FROM msc_units_of_measure mum'
20484 ||' WHERE mum.uom_code = mcc.from_uom_code'
20485 ||' AND mum.uom_class = mcc.from_uom_class'
20486 ||' AND mum.unit_of_measure = mcc.from_unit_of_measure'
20487 ||' AND mum.base_uom_flag = ''Y'' '
20488 ||' UNION'
20489 ||' SELECT 1'
20490 ||' FROM msc_st_units_of_measure mum'
20491 ||' WHERE mum.uom_code = mcc.from_uom_code'
20492 ||' AND mum.uom_class = mcc.from_uom_class'
20493 ||' AND mum.unit_of_measure = mcc.from_unit_of_measure'
20494 ||' AND mum.base_uom_flag = ''Y'' '
20495 ||' AND mum.process_flag = '||G_VALID||')'
20496 ||' AND mcc.batch_id = :lv_batch_id'
20497 ||' AND mcc.sr_instance_code = :v_instance_code'
20498 ||' AND mcc.process_flag = 2';
20499
20500
20501
20502 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
20503
20504 EXECUTE IMMEDIATE lv_sql_stmt
20505 USING lv_batch_id,
20506 v_instance_code;
20507
20508
20509 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
20510 (p_app_short_name => 'MSC',
20511 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
20512 p_message_text => lv_message_text,
20513 p_error_text => lv_error_text,
20514 p_token1 => 'COLUMN_NAMES',
20515 p_token_value1 => 'TO_UOM_CODE, TO_UOM_CLASS'
20516 ||' AND TO_UNIT_OF_MEASURE',
20517 p_token2 => 'MASTER_TABLE',
20518 p_token_value2 => 'MSC_ST_UNITS_OF_MEASURE',
20519 p_token3 => 'CHILD_TABLE',
20520 p_token_value3 => 'MSC_ST_UOM_CLASS_CONVERSIONS');
20521 IF lv_return <> 0 THEN
20522 RAISE ex_logging_err;
20523 END IF;
20524
20525 v_sql_stmt := 20;
20526 lv_sql_stmt :=
20527 'UPDATE msc_st_uom_class_conversions mcc '
20528 ||' SET process_flag = '||G_ERROR_FLG||','
20529 ||' error_text = '||''''||lv_message_text||''''
20530 ||' WHERE NOT EXISTS(SELECT 1'
20531 ||' FROM msc_units_of_measure mum '
20532 ||' WHERE mum.uom_code = mcc.to_uom_code'
20533 ||' AND mum.uom_class = mcc.to_uom_class'
20534 ||' AND mum.unit_of_measure = mcc.to_unit_of_measure'
20535 ||' AND mum.base_uom_flag = ''Y'' '
20536 ||' UNION'
20537 ||' SELECT 1'
20538 ||' FROM msc_st_units_of_measure mum'
20539 ||' WHERE mum.uom_code = mcc.to_uom_code'
20540 ||' AND mum.uom_class = mcc.to_uom_class'
20541 ||' AND mum.unit_of_measure = mcc.to_unit_of_measure'
20542 ||' AND mum.base_uom_flag = ''Y'' '
20543 ||' AND mum.process_flag = '||G_VALID||') '
20544 ||' AND mcc.batch_id = :lv_batch_id'
20545 ||' AND mcc.sr_instance_code = :v_instance_code'
20546 ||' AND mcc.process_flag = 2';
20547
20548
20549 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
20550
20551 EXECUTE IMMEDIATE lv_sql_stmt
20552 USING lv_batch_id,
20553 v_instance_code;
20554
20555
20556 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
20557 (p_app_short_name => 'MSC',
20558 p_error_code => 'MSC_PP_CONV_RT_NEG',
20559 p_message_text => lv_message_text,
20560 p_error_text => lv_error_text,
20561 p_token1 => 'COLUMN_NAME',
20562 p_token_value1 => 'CONVERSION_RATE');
20563
20564 IF lv_return <> 0 THEN
20565 RAISE ex_logging_err;
20566 END IF;
20567
20568 v_sql_stmt := 21;
20569 lv_sql_stmt :=
20570 ' UPDATE msc_st_uom_class_conversions'
20571 ||' SET process_flag = '||G_ERROR_FLG||', '
20572 ||' error_text = '||''''||lv_message_text||''''
20573 ||' WHERE NVL(conversion_rate,'||NULL_VALUE||') <= 0'
20574 ||' AND process_flag = '||G_IN_PROCESS
20575 ||' AND batch_id = :lv_batch_id'
20576 ||' AND sr_instance_code = :v_instance_code';
20577
20578
20579 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
20580
20581 EXECUTE IMMEDIATE lv_sql_stmt
20582 USING lv_batch_id,
20583 v_instance_code;
20584
20585
20586 /* lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
20587 (p_app_short_name => 'MSC',
20588 p_error_code => 'MSC_PP_COL_VAL_NULL',
20589 p_message_text => lv_message_text,
20590 p_error_text => lv_error_text,
20591 p_token1 => 'COLUMN_NAME',
20592 p_token_value1 => 'ORGANIZATION_CODE');
20593
20594 IF lv_return <> 0 THEN
20595 RAISE ex_logging_err;
20596 END IF;
20597
20598 --Org code is mandatory where item name is not null
20599 v_sql_stmt := 22;
20600 lv_sql_stmt :=
20601 ' UPDATE msc_st_uom_class_conversions'
20602 ||' SET process_flag = '||G_ERROR_FLG||', '
20603 ||' error_text = '||''''||lv_message_text||''''
20604 ||' WHERE NVL(item_name, '||''''||NULL_CHAR||''''||')'
20605 ||' = '||''''||NULL_CHAR||''''
20606 ||' AND NVL(ORGANIZATION_CODE,'||''''||NULL_CHAR||''''||') '
20607 ||' = '||''''||NULL_CHAR||''''
20608 ||' AND process_flag = '||G_IN_PROCESS
20609 ||' AND batch_id = :lv_batch_id'
20610 ||' AND sr_instance_code = :v_instance_code';
20611
20612
20613 msc_st_util.log_message(lv_sql_stmt);
20614
20615 EXECUTE IMMEDIATE lv_sql_stmt
20616 USING lv_batch_id,
20617 v_instance_code;
20618
20619 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
20620 (p_app_short_name => 'MSC',
20621 p_error_code => 'MSC_PP_INVALID_VALUE',
20622 p_message_text => lv_message_text,
20623 p_error_text => lv_error_text,
20624 p_token1 => 'COLUMN_NAME',
20625 p_token_value1 => 'ORGANIZATION_CODE');
20626
20627 IF lv_return <> 0 THEN
20628 RAISE ex_logging_err;
20629 END IF;
20630
20631 --Derive Organization_id
20632 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
20633 (p_table_name => 'MSC_ST_UOM_CLASS_CONVERSIONS',
20634 p_org_partner_name => 'ORGANIZATION_CODE',
20635 p_org_partner_id => 'ORGANIZATION_ID',
20636 p_instance_code => v_instance_code,
20637 p_partner_type => G_ORGANIZATION,
20638 p_error_text => lv_error_text,
20639 p_batch_id => lv_batch_id,
20640 p_severity => G_SEV3_ERROR,
20641 p_message_text => lv_message_text,
20642 p_debug => v_debug,
20643 p_row => lv_column_names);
20644
20645 IF lv_return <> 0 THEN
20646 RAISE ex_logging_err;
20647 END IF; */
20648 v_sql_stmt := 23;
20649 --Update inventory_item_id
20650 lv_sql_stmt :=
20651 'UPDATE msc_st_uom_class_conversions mcc '
20652 ||' SET inventory_item_id = (SELECT local_id'
20653 ||' FROM msc_local_id_item mli'
20654 ||' WHERE mli.char1 = mcc.sr_instance_code '
20655 ||' AND NVL(mli.char2, '||''''||NULL_CHAR||''''||')='
20656 ||' NVL(mcc.company_name,'||''''||NULL_CHAR||''''||')'
20657 ||' AND mli.char4 = mcc.item_name'
20658 ||' AND mli.entity_name = ''SR_INVENTORY_ITEM_ID'' '
20659 ||' AND mli.instance_id = :v_instance_id '
20660 ||' AND rownum < 2) '
20661 ||' WHERE item_name IS NOT NULL'
20662 ||' AND sr_instance_code = :v_instance_code'
20663 ||' AND batch_id = :lv_batch_id'
20664 ||' AND process_flag = '||G_IN_PROCESS;
20665
20666
20667 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
20668
20669 EXECUTE IMMEDIATE lv_sql_stmt
20670 USING v_instance_id,
20671 v_instance_code,
20672 lv_batch_id;
20673
20674
20675 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
20676 (p_app_short_name => 'MSC',
20677 p_error_code => 'MSC_PP_INVALID_VALUE',
20678 p_message_text => lv_message_text,
20679 p_error_text => lv_error_text,
20680 p_token1 => 'COLUMN_NAME',
20681 p_token_value1 => 'ITEM_NAME');
20682
20683 IF lv_return <> 0 THEN
20684 RAISE ex_logging_err;
20685 END IF;
20686 v_sql_stmt := 24;
20687 lv_sql_stmt :=
20688 'UPDATE msc_st_uom_class_conversions '
20689 ||' SET error_text = '||''''||lv_message_text||''''||','
20690 ||' process_flag = '||g_error
20691 ||' WHERE inventory_item_id IS NULL '
20692 ||' AND item_name IS NOT NULL '
20693 ||' AND sr_instance_code = :v_instance_code'
20694 ||' AND batch_id = :lv_batch_id'
20695 ||' AND process_flag = ' ||G_IN_PROCESS;
20696
20697
20698 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,lv_sql_stmt);
20699
20700 EXECUTE IMMEDIATE lv_sql_stmt
20701 USING v_instance_code,
20702 lv_batch_id;
20703
20704
20705 --Call to customised validation.
20706 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
20707 (ERRBUF => lv_error_text,
20708 RETCODE => lv_return,
20709 pBatchID => lv_batch_id,
20710 pInstanceCode => v_instance_code,
20711 pEntityName => 'MSC_ST_UOM_CLASS_CONVERSIONS',
20712 pInstanceID => v_instance_id);
20713
20714 IF NVL(lv_return,0) <> 0 THEN
20715 RAISE ex_logging_err;
20716 END IF;
20717
20718 v_sql_stmt := 25;
20719 --Fixed against the bug#2734588.
20720
20721 UPDATE msc_st_uom_class_conversions
20722 SET inventory_item_id = 0
20723 WHERE item_name IS NULL
20724 AND process_flag = G_IN_PROCESS
20725 AND batch_id = lv_batch_id
20726 AND sr_instance_code = v_instance_code;
20727
20728 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
20729 (p_table_name => 'MSC_ST_UOM_CLASS_CONVERSIONS',
20730 p_instance_id => v_instance_id,
20731 p_instance_code => v_instance_code,
20732 p_process_flag => G_VALID,
20733 p_error_text => lv_error_text,
20734 p_debug => v_debug,
20735 p_batch_id => lv_batch_id);
20736
20737 IF lv_return <> 0 THEN
20738 RAISE ex_logging_err;
20739 END IF;
20740
20741 lv_return := MSC_ST_UTIL.LOG_ERROR
20742 (p_table_name => 'MSC_ST_UOM_CLASS_CONVERSIONS',
20743 p_instance_code => v_instance_code,
20744 p_row => lv_column_names,
20745 p_severity => G_SEV_ERROR,
20746 p_message_text => NULL,
20747 p_error_text => lv_error_text,
20748 p_debug => v_debug,
20749 p_batch_id => lv_batch_id);
20750
20751 IF lv_return <> 0 THEN
20752 RAISE ex_logging_err;
20753 END IF;
20754
20755 COMMIT;
20756 END LOOP;
20757
20758 --Validation check for the table msc_st_uom_class_conversions.
20759
20760 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
20761 (p_app_short_name => 'MSC',
20762 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
20763 p_message_text => lv_message_text,
20764 p_error_text => lv_error_text);
20765
20766 IF lv_return <> 0 THEN
20767 RAISE ex_logging_err;
20768 END IF;
20769
20770 --Duplicate records check for the records whose source is XML.
20771 v_sql_stmt := 23;
20772 lv_sql_stmt :=
20773 'UPDATE msc_st_uom_conversions mcc1 '
20774 ||' SET process_flag = '||G_ERROR_FLG||','
20775 ||' error_text = '||''''||lv_message_text||''''
20776 ||' WHERE message_id < (SELECT MAX(message_id) '
20777 ||' FROM msc_st_uom_conversions mcc2 '
20778 ||' WHERE NVL(mcc2.item_name, '||''''||NULL_CHAR||''''||') = '
20779 ||' NVL(mcc1.item_name, '||''''||NULL_CHAR||''''||')'
20780 ||' AND NVL(mcc2.unit_of_measure, '||''''||NULL_CHAR||''''||') = '
20781 ||' NVL(mcc1.unit_of_measure, '||''''||NULL_CHAR||''''||')'
20782 ||' AND NVL(mcc2.company_name, '||''''||NULL_CHAR||''''||') = '
20783 ||' NVL(mcc1.company_name, '||''''||NULL_CHAR||''''||')'
20784 ||' AND mcc2.process_flag = '||G_IN_PROCESS
20785 ||' AND NVL(mcc2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
20786 ||' AND mcc1.process_flag = '||G_IN_PROCESS
20787 ||' AND mcc1.sr_instance_code = :v_instance_code'
20788 ||' AND NVL(mcc1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
20789
20790
20791
20792 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
20793
20794 EXECUTE IMMEDIATE lv_sql_stmt
20795 USING v_instance_code;
20796
20797
20798 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
20799 (p_app_short_name => 'MSC',
20800 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
20801 p_message_text => lv_message_text,
20802 p_error_text => lv_error_text);
20803
20804 IF lv_return <> 0 THEN
20805 RAISE ex_logging_err;
20806 END IF;
20807
20808 --Duplicate records check for the records whose source is other than XML
20809 --Different SQL is used because in XML we can identify the latest records
20810 --whereas in batch load we cannot.
20811 v_sql_stmt := 24;
20812 lv_sql_stmt :=
20813 'UPDATE msc_st_uom_conversions mcc1 '
20814 ||' SET process_flag = '||G_ERROR_FLG||','
20815 ||' error_text = '||''''||lv_message_text||''''
20816 ||' WHERE EXISTS( SELECT 1 '
20817 ||' FROM msc_st_uom_conversions mcc2'
20818 ||' WHERE NVL(mcc2.item_name, '||''''||NULL_CHAR||''''||') = '
20819 ||' NVL(mcc1.item_name, '||''''||NULL_CHAR||''''||')'
20820 ||' AND NVL(mcc2.unit_of_measure, '||''''||NULL_CHAR||''''||') = '
20821 ||' NVL(mcc1.unit_of_measure, '||''''||NULL_CHAR||''''||')'
20822 ||' AND NVL(mcc2.company_name, '||''''||NULL_CHAR||''''||') = '
20823 ||' NVL(mcc1.company_name, '||''''||NULL_CHAR||''''||')'
20824 ||' AND mcc2.process_flag = '||G_IN_PROCESS
20825 ||' AND NVL(mcc2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
20826 ||' GROUP BY item_name,company_name,'
20827 ||' unit_of_measure'
20828 ||' HAVING COUNT(*) > 1)'
20829 ||' AND mcc1.process_flag = '||G_IN_PROCESS
20830 ||' AND mcc1.sr_instance_code = :v_instance_code'
20831 ||' AND NVL(mcc1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
20832
20833
20834 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
20835
20836 EXECUTE IMMEDIATE lv_sql_stmt
20837 USING v_instance_code;
20838
20839 lv_column_names :=
20840 'UNIT_OF_MEASURE ||''~''||'
20841 ||'UOM_CODE ||''~''||'
20842 ||'UOM_CLASS ||''~''||'
20843 ||'INVENTORY_ITEM_ID ||''~''||'
20844 ||'CONVERSION_RATE ||''~''||'
20845 ||'DEFAULT_CONVERSION_FLAG ||''~''||'
20846 ||'SR_INSTANCE_CODE ||''~''||'
20847 ||'DISABLE_DATE ||''~''||'
20848 ||'ITEM_NAME ||''~''||'
20849 ||'ORGANIZATION_CODE ||''~''||'
20850 ||'COMPANY_NAME ||''~''||'
20851 ||'DELETED_FLAG';
20852
20853 LOOP
20854 v_sql_stmt := 25;
20855 SELECT msc_st_batch_id_s.NEXTVAL
20856 INTO lv_batch_id
20857 FROM dual;
20858
20859 v_sql_stmt := 26;
20860 lv_sql_stmt :=
20861 'UPDATE msc_st_uom_conversions '
20862 ||' SET batch_id = :lv_batch_id'
20863 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
20864 ||' AND sr_instance_code = :v_instance_code'
20865 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
20866 ||' AND rownum <= '||v_batch_size;
20867
20868
20869 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
20870
20871 EXECUTE IMMEDIATE lv_sql_stmt
20872 USING lv_batch_id,
20873 v_instance_code;
20874
20875 EXIT WHEN SQL%NOTFOUND;
20876
20877 OPEN c3(lv_batch_id);
20878 FETCH c3 BULK COLLECT INTO lb_rowid;
20879 CLOSE c3;
20880
20881 v_sql_stmt := 27;
20882 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
20883 UPDATE msc_st_uom_conversions
20884 SET st_transaction_id = msc_st_uom_conversions_s.NEXTVAL,
20885 refresh_id = v_refresh_id,
20886 last_update_date = v_current_date,
20887 last_updated_by = v_current_user,
20888 creation_date = v_current_date,
20889 created_by = v_current_user
20890 WHERE rowid = lb_rowid(j);
20891
20892 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
20893 (p_app_short_name => 'MSC',
20894 p_error_code => 'MSC_PP_NO_DELETION',
20895 p_message_text => lv_message_text,
20896 p_error_text => lv_error_text,
20897 p_token1 => 'TABLE_NAME',
20898 p_token_value1 => 'MSC_ST_UOM_CONVERSIONS');
20899
20900 IF lv_return <> 0 THEN
20901 RAISE ex_logging_err;
20902 END IF;
20903
20904 --Deletion is not allowed on this table.
20905 v_sql_stmt := 28;
20906 lv_sql_stmt :=
20907 'UPDATE msc_st_uom_conversions'
20908 ||' SET process_flag = '||G_ERROR_FLG||','
20909 ||' error_text = '||''''||lv_message_text||''''
20910 ||' WHERE deleted_flag = '||SYS_YES
20911 ||' AND process_flag = '||G_IN_PROCESS
20912 ||' AND batch_id = :lv_batch_id'
20913 ||' AND sr_instance_code = :v_instance_code';
20914
20915
20916 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
20917
20918 EXECUTE IMMEDIATE lv_sql_stmt
20919 USING lv_batch_id,
20920 v_instance_code;
20921
20922 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
20923 (p_app_short_name => 'MSC',
20924 p_error_code => 'MSC_PP_COL_VAL_NULL',
20925 p_message_text => lv_message_text,
20926 p_error_text => lv_error_text,
20927 p_token1 => 'COLUMN_NAME',
20928 p_token_value1 => 'ITEM_NAME');
20929
20930 IF lv_return <> 0 THEN
20931 RAISE ex_logging_err;
20932 END IF;
20933
20934 --Item Name is mandatory if the Default Conversion Flag is set to 'Y' (fix for 2747791)
20935 v_sql_stmt := 29;
20936 lv_sql_stmt :=
20937 'UPDATE msc_st_uom_conversions'
20938 ||' SET process_flag = '||G_ERROR_FLG||','
20939 ||' error_text = '||''''||lv_message_text||''''
20940 ||' WHERE item_name IS NULL '
20941 ||' AND default_conversion_flag = ''Y'' '
20942 ||' AND process_flag = '||G_IN_PROCESS
20943 ||' AND batch_id = :lv_batch_id'
20944 ||' AND sr_instance_code = :v_instance_code';
20945
20946
20947 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
20948
20949 EXECUTE IMMEDIATE lv_sql_stmt
20950 USING lv_batch_id,
20951 v_instance_code;
20952
20953
20954 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
20955 (p_app_short_name => 'MSC',
20956 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
20957 p_message_text => lv_message_text,
20958 p_error_text => lv_error_text,
20959 p_token1 => 'COLUMN_NAME',
20960 p_token_value1 => 'DELETED_FLAG',
20961 p_token2 => 'DEFAULT_VALUE',
20962 p_token_value2 => SYS_NO);
20963
20964 IF lv_return <> 0 THEN
20965 RAISE ex_logging_err;
20966 END IF;
20967
20968 lv_where_str :=
20969 ' AND NVL(deleted_flag,'||NULL_VALUE||') '
20970 ||' NOT IN(1,2)';
20971
20972 --Log a warning for those records where the deleted_flag has a value other
20973 --than SYS_NO
20974 lv_return := MSC_ST_UTIL.LOG_ERROR
20975 (p_table_name => 'MSC_ST_UOM_CONVERSIONS',
20976 p_instance_code => v_instance_code,
20977 p_row => lv_column_names,
20978 p_severity => G_SEV_WARNING,
20979 p_message_text => lv_message_text,
20980 p_error_text => lv_error_text,
20981 p_batch_id => lv_batch_id,
20982 p_where_str => lv_where_str,
20983 p_col_name => 'DELETED_FLAG',
20984 p_debug => v_debug,
20985 p_default_value => SYS_NO);
20986
20987 IF lv_return <> 0 THEN
20988 RAISE ex_logging_err;
20989 END IF;
20990
20991 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
20992 (p_app_short_name => 'MSC',
20993 p_error_code => 'MSC_PP_COL_VAL_NULL',
20994 p_message_text => lv_message_text,
20995 p_error_text => lv_error_text,
20996 p_token1 => 'COLUMN_NAME',
20997 p_token_value1 => 'UOM_CODE OR UOM_CLASS');
20998
20999 IF lv_return <> 0 THEN
21000 RAISE ex_logging_err;
21001 END IF;
21002
21003 v_sql_stmt := 30;
21004 lv_sql_stmt :=
21005 'UPDATE msc_st_uom_conversions'
21006 ||' SET process_flag = '||G_ERROR_FLG||','
21007 ||' error_text = '||''''||lv_message_text||''''
21008 ||' WHERE (NVL(uom_code, '||''''||NULL_CHAR||''''||') '
21009 ||' = '||''''||NULL_CHAR||''''
21010 ||' OR NVL(uom_class, '||''''||NULL_CHAR||''''||') '
21011 ||' = '||''''||NULL_CHAR||''''||') '
21012 ||' AND process_flag = '||G_IN_PROCESS
21013 ||' AND batch_id = :lv_batch_id'
21014 ||' AND sr_instance_code = :v_instance_code';
21015
21016
21017 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
21018 EXECUTE IMMEDIATE lv_sql_stmt
21019 USING lv_batch_id,
21020 v_instance_code;
21021
21022 v_sql_stmt := 30;
21023 lv_sql_stmt :=
21024 'UPDATE msc_st_uom_conversions'
21025 ||' SET unit_of_measure = uom_code'
21026 ||' WHERE NVL(unit_of_measure,'||''''||NULL_CHAR||''''||')'
21027 ||' = '||''''||NULL_CHAR||''''
21028 ||' AND process_flag = '||G_IN_PROCESS
21029 ||' AND batch_id = :lv_batch_id'
21030 ||' AND sr_instance_code = :v_instance_code';
21031
21032
21033 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
21034
21035 EXECUTE IMMEDIATE lv_sql_stmt
21036 USING lv_batch_id,
21037 v_instance_code;
21038
21039 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
21040 (p_app_short_name => 'MSC',
21041 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
21042 p_message_text => lv_message_text,
21043 p_error_text => lv_error_text,
21044 p_token1 => 'COLUMN_NAMES',
21045 p_token_value1 => 'UOM_CODE, UOM_CLASS AND UNIT_OF_MEASURE',
21046 p_token2 => 'MASTER_TABLE',
21047 p_token_value2 => 'MSC_ST_UNITS_OF_MEASURE',
21048 p_token3 => 'CHILD_TABLE',
21049 p_token_value3 => 'MSC_ST_UOM_CONVERSIONS');
21050 IF lv_return <> 0 THEN
21051 RAISE ex_logging_err;
21052 END IF;
21053
21054 v_sql_stmt := 31;
21055 lv_sql_stmt :=
21056 ' UPDATE msc_st_uom_conversions mcc'
21057 ||' SET process_flag = '||G_ERROR_FLG||','
21058 ||' error_text = '||''''||lv_message_text||''''
21059 ||' WHERE NOT EXISTS(SELECT 1'
21060 ||' FROM msc_units_of_measure mum'
21061 ||' WHERE mum.uom_code = mcc.uom_code'
21062 ||' AND mum.uom_class = mcc.uom_class'
21063 ||' AND mum.unit_of_measure = mcc.unit_of_measure'
21064 ||' UNION'
21065 ||' SELECT 1'
21066 ||' FROM msc_st_units_of_measure mum'
21067 ||' WHERE mum.uom_code = mcc.uom_code'
21068 ||' AND mum.uom_class = mcc.uom_class'
21069 ||' AND mum.unit_of_measure = mcc.unit_of_measure'
21070 ||' AND mum.process_flag = '||G_VALID||')'
21071 ||' AND batch_id = :lv_batch_id'
21072 ||' AND mcc.sr_instance_code = :v_instance_code'
21073 ||' AND mcc.process_flag = '||G_IN_PROCESS;
21074
21075
21076 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
21077
21078 EXECUTE IMMEDIATE lv_sql_stmt
21079 USING lv_batch_id,
21080 v_instance_code;
21081
21082
21083 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
21084 (p_app_short_name => 'MSC',
21085 p_error_code => 'MSC_PP_CONV_RT_NEG',
21086 p_message_text => lv_message_text,
21087 p_error_text => lv_error_text,
21088 p_token1 => 'COLUMN_NAME',
21089 p_token_value1 => 'CONVERSION_RATE');
21090
21091 IF lv_return <> 0 THEN
21092 RAISE ex_logging_err;
21093 END IF;
21094
21095 v_sql_stmt := 32;
21096 lv_sql_stmt :=
21097 'UPDATE msc_st_uom_conversions'
21098 ||' SET process_flag = '||G_ERROR_FLG||','
21099 ||' error_text = '||''''||lv_message_text||''''
21100 ||' WHERE NVL(conversion_rate,'||NULL_VALUE||') <= 0'
21101 ||' AND process_flag = '||G_IN_PROCESS
21102 ||' AND batch_id = :lv_batch_id'
21103 ||' AND sr_instance_code = :v_instance_code';
21104
21105
21106 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
21107
21108 EXECUTE IMMEDIATE lv_sql_stmt
21109 USING lv_batch_id,
21110 v_instance_code;
21111
21112 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
21113 (p_app_short_name => 'MSC',
21114 p_error_code => 'MSC_PP_COL_VAL_NULL',
21115 p_message_text => lv_message_text,
21116 p_error_text => lv_error_text,
21117 p_token1 => 'COLUMN_NAME',
21118 p_token_value1 => 'ORGANIZATION_CODE');
21119
21120 IF lv_return <> 0 THEN
21121 RAISE ex_logging_err;
21122 END IF;
21123
21124 /* --Org code is mandatory where item name is not null
21125 v_sql_stmt := 33;
21126 lv_sql_stmt :=
21127 'UPDATE msc_st_uom_conversions'
21128 ||' SET process_flag = '||G_ERROR_FLG||','
21129 ||' error_text = '||''''||lv_message_text||''''
21130 ||' WHERE NVL(item_name, '||''''||NULL_CHAR||''''||') '
21131 ||' <> '||''''||NULL_CHAR||''''
21132 ||' AND NVL(ORGANIZATION_CODE, '||''''||NULL_CHAR||''''||') '
21133 ||' = '||''''||NULL_CHAR||''''
21134 ||' AND process_flag = '||G_IN_PROCESS
21135 ||' AND batch_id = :lv_batch_id'
21136 ||' AND sr_instance_code = :v_instance_code';
21137
21138
21139 msc_st_util.log_message(lv_sql_stmt);
21140
21141 EXECUTE IMMEDIATE lv_sql_stmt
21142 USING lv_batch_id,
21143 v_instance_code;
21144
21145
21146 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
21147 (p_app_short_name => 'MSC',
21148 p_error_code => 'MSC_PP_INVALID_VALUE',
21149 p_message_text => lv_message_text,
21150 p_error_text => lv_error_text,
21151 p_token1 => 'COLUMN_NAME',
21152 p_token_value1 => 'ORGANIZATION_CODE');
21153
21154 IF lv_return <> 0 THEN
21155 RAISE ex_logging_err;
21156 END IF;
21157
21158 --Derive Organization_id
21159 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
21160 (p_table_name => 'MSC_ST_UOM_CONVERSIONS',
21161 p_org_partner_name => 'ORGANIZATION_CODE',
21162 p_org_partner_id => 'ORGANIZATION_ID',
21163 p_instance_code => v_instance_code,
21164 p_partner_type => G_ORGANIZATION,
21165 p_error_text => lv_error_text,
21166 p_batch_id => lv_batch_id,
21167 p_severity => G_SEV3_ERROR,
21168 p_message_text => lv_message_text,
21169 p_debug => v_debug,
21170 p_row => lv_column_names);
21171
21172 IF lv_return <> 0 THEN
21173 RAISE ex_logging_err;
21174 END IF; */
21175
21176 --Update inventory_item_id
21177 lv_sql_stmt :=
21178 'UPDATE msc_st_uom_conversions mcc '
21179 ||' SET inventory_item_id = (SELECT local_id'
21180 ||' FROM msc_local_id_item mli'
21181 ||' WHERE mli.char1 = mcc.sr_instance_code '
21182 ||' AND NVL(mli.char2, '||''''||NULL_CHAR||''''||')='
21183 ||' NVL(mcc.company_name,'||''''||NULL_CHAR||''''||')'
21184 ||' AND mli.char4 = mcc.item_name'
21185 ||' AND mli.entity_name = ''SR_INVENTORY_ITEM_ID'' '
21186 ||' AND mli.instance_id = :v_instance_id '
21187 ||' AND rownum < 2 )'
21188 ||' WHERE item_name IS NOT NULL'
21189 ||' AND sr_instance_code = :v_instance_code'
21190 ||' AND batch_id = :lv_batch_id'
21191 ||' AND process_flag = '||G_IN_PROCESS;
21192
21193
21194 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
21195
21196 EXECUTE IMMEDIATE lv_sql_stmt
21197 USING v_instance_id,
21198 v_instance_code,
21199 lv_batch_id;
21200
21201
21202 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
21203 (p_app_short_name => 'MSC',
21204 p_error_code => 'MSC_PP_INVALID_VALUE',
21205 p_message_text => lv_message_text,
21206 p_error_text => lv_error_text,
21207 p_token1 => 'COLUMN_NAME',
21208 p_token_value1 => 'ITEM_NAME');
21209
21210 IF lv_return <> 0 THEN
21211 RAISE ex_logging_err;
21212 END IF;
21213
21214 lv_sql_stmt :=
21215 'UPDATE msc_st_uom_class_conversions '
21216 ||' SET error_text = '||''''||lv_message_text||''''||','
21217 ||' process_flag = '||g_error
21218 ||' WHERE inventory_item_id IS NULL '
21219 ||' AND item_name IS NOT NULL '
21220 ||' AND sr_instance_code = :v_instance_code'
21221 ||' AND batch_id = :lv_batch_id'
21222 ||' AND process_flag = ' ||G_IN_PROCESS;
21223
21224
21225 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,lv_sql_stmt);
21226
21227 EXECUTE IMMEDIATE lv_sql_stmt
21228 USING v_instance_code,
21229 lv_batch_id;
21230
21231 --Item id is set to 0 if the inventory_item_id is NULL
21232 v_sql_stmt := 34;
21233 lv_sql_stmt :=
21234 'UPDATE msc_st_uom_conversions '
21235 ||' SET inventory_item_id = 0 '
21236 ||' WHERE process_flag = '||G_IN_PROCESS
21237 ||' AND batch_id = :lv_batch_id'
21238 ||' AND sr_instance_code = :v_instance_code'
21239 ||' AND inventory_item_id IS NULL ';
21240
21241
21242 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
21243
21244 EXECUTE IMMEDIATE lv_sql_stmt
21245 USING lv_batch_id,
21246 v_instance_code;
21247
21248 --Call to customised validation.
21249 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
21250 (ERRBUF => lv_error_text,
21251 RETCODE => lv_return,
21252 pBatchID => lv_batch_id,
21253 pInstanceCode => v_instance_code,
21254 pEntityName => 'MSC_ST_UOM_CONVERSIONS',
21255 pInstanceID => v_instance_id);
21256
21257 IF NVL(lv_return,0) <> 0 THEN
21258 RAISE ex_logging_err;
21259 END IF;
21260
21261 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
21262 (p_table_name => 'MSC_ST_UOM_CONVERSIONS',
21263 p_instance_id => v_instance_id,
21264 p_instance_code => v_instance_code,
21265 p_process_flag => G_VALID,
21266 p_error_text => lv_error_text,
21267 p_debug => v_debug,
21268 p_batch_id => lv_batch_id);
21269
21270 IF lv_return <> 0 THEN
21271 RAISE ex_logging_err;
21272 END IF;
21273
21274 lv_return := MSC_ST_UTIL.LOG_ERROR
21275 (p_table_name => 'MSC_ST_UOM_CONVERSIONS',
21276 p_instance_code => v_instance_code,
21277 p_row => lv_column_names,
21278 p_severity => G_SEV_ERROR,
21279 p_message_text => NULL,
21280 p_error_text => lv_error_text,
21281 p_debug => v_debug,
21282 p_batch_id => lv_batch_id);
21283
21284 IF lv_return <> 0 THEN
21285 RAISE ex_logging_err;
21286 END IF;
21287
21288 COMMIT;
21289 END LOOP;
21290
21291 EXCEPTION
21292 WHEN ex_logging_err THEN
21293 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
21294 ROLLBACK;
21295
21296 WHEN OTHERS THEN
21297 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_UOM_CLASS_CONV'||'('
21298 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
21299 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
21300 ROLLBACK;
21301
21302 END LOAD_UOM_CLASS_CONV;
21303
21304 /*==========================================================================+
21305 | DESCRIPTION : This procedure validates the records and updates the table |
21306 | msc_st_designators. |
21307 | |
21308 | Designator Types Type Code |
21309 | ---------------------------------------------------------- |
21310 | Manual MDS 1 |
21311 | Plan Orders 2 |
21312 | Forecast 6 |
21313 +==========================================================================*/
21314 PROCEDURE LOAD_DESIGNATOR IS
21315 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
21316 lb_rowid RowidTab;
21317 lv_error_text VARCHAR2(250);
21318 lv_column_names VARCHAR2(5000);--stores concatenated column names
21319 lv_where_str VARCHAR2(5000);
21320 lv_sql_stmt VARCHAR2(5000);
21321 lv_return NUMBER;
21322
21323 lv_batch_id msc_st_designators.batch_id%TYPE;
21324 lv_message_text msc_errors.error_text%TYPE;
21325 ex_logging_err EXCEPTION;
21326
21327 CURSOR c1(lv_batch_id NUMBER) IS
21328 SELECT rowid
21329 FROM msc_st_designators
21330 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
21331 AND sr_instance_code = v_instance_code
21332 AND batch_id = lv_batch_id;
21333
21334 BEGIN
21335
21336 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
21337 (p_app_short_name => 'MSC',
21338 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
21339 p_message_text => lv_message_text,
21340 p_error_text => lv_error_text);
21341
21342 IF lv_return <> 0 THEN
21343 RAISE ex_logging_err;
21344 END IF;
21345
21346 --Duplicate records check for the records whose source is XML
21347 --Based on bug#2736771 UDK has been changed.
21348 v_sql_stmt := 01;
21349 lv_sql_stmt :=
21350 'UPDATE msc_st_designators msd1 '
21351 ||' SET process_flag = '||G_ERROR_FLG||','
21352 ||' error_text = '||''''||lv_message_text||''''
21353 ||' WHERE message_id < (SELECT MAX(message_id)'
21354 ||' FROM msc_st_designators msd2'
21355 ||' WHERE msd2.sr_instance_code = msd1.sr_instance_code'
21356 ||' AND NVL(msd2.company_name, '||''''||NULL_CHAR||''''||') = '
21357 ||' NVL(msd1.company_name, '||''''||NULL_CHAR||''''||')'
21358 ||' AND msd2.organization_code = msd1.organization_code'
21359 ||' AND msd2.designator = msd1.designator'
21360 ||' AND msd2.process_flag = '||G_IN_PROCESS
21361 ||' AND msd2.sr_instance_code = msd1.sr_instance_code'
21362 ||' AND NVL(msd2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
21363 ||' AND msd1.process_flag = '||G_IN_PROCESS
21364 ||' AND msd1.sr_instance_code = :v_instance_code'
21365 ||' AND NVL(msd1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
21366
21367
21368 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
21369
21370 EXECUTE IMMEDIATE lv_sql_stmt
21371 USING v_instance_code;
21372
21373 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
21374 (p_app_short_name => 'MSC',
21375 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
21376 p_message_text => lv_message_text,
21377 p_error_text => lv_error_text);
21378
21379 IF lv_return <> 0 THEN
21380 RAISE ex_logging_err;
21381 END IF;
21382
21383 --Duplicate records check for the records whose source is other than XML
21384 --Different SQL is used because in XML we can identify the latest records
21385 --whereas in batch load we cannot.
21386 v_sql_stmt := 02;
21387 lv_sql_stmt :=
21388 'UPDATE msc_st_designators msd1'
21389 ||' SET process_flag = '||G_ERROR_FLG||','
21390 ||' error_text = '||''''||lv_message_text||''''
21391 ||' WHERE EXISTS( SELECT 1 '
21392 ||' FROM msc_st_designators msd2'
21393 ||' WHERE msd2.sr_instance_code = msd1.sr_instance_code'
21394 ||' AND NVL(msd2.company_name, '||''''||NULL_CHAR||''''||') = '
21395 ||' NVL(msd1.company_name, '||''''||NULL_CHAR||''''||')'
21396 ||' AND msd2.organization_code = msd1.organization_code'
21397 ||' AND msd2.designator = msd1.designator'
21398 ||' AND msd2.process_flag = '||G_IN_PROCESS
21399 ||' AND msd2.sr_instance_code = msd1.sr_instance_code'
21400 ||' AND NVL(msd2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
21401 ||' GROUP BY sr_instance_code,organization_code,company_name,'
21402 ||' designator'
21403 ||' HAVING COUNT(*) > 1)'
21404 ||' AND msd1.process_flag = '||G_IN_PROCESS
21405 ||' AND msd1.sr_instance_code = :v_instance_code'
21406 ||' AND NVL(msd1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
21407
21408
21409 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
21410
21411 EXECUTE IMMEDIATE lv_sql_stmt
21412 USING v_instance_code;
21413
21414 lv_column_names :=
21415 'DESIGNATOR ||''~''||'
21416 ||'ORGANIZATION_CODE ||''~''||'
21417 ||'MPS_RELIEF ||''~''||'
21418 ||'INVENTORY_ATP_FLAG ||''~''||'
21419 ||'DESCRIPTION ||''~''||'
21420 ||'DISABLE_DATE ||''~''||'
21421 ||'DEMAND_CLASS ||''~''||'
21422 ||'ORGANIZATION_SELECTION ||''~''||'
21423 ||'PRODUCTION ||''~''||'
21424 ||'SR_INSTANCE_CODE ||''~''||'
21425 ||'DELETED_FLAG ||''~''||'
21426 ||'BUCKET_TYPE ||''~''||'
21427 ||'RECOMMENDATION_RELEASE ||''~''||'
21428 ||'CONSUME_FORECAST ||''~''||'
21429 ||'UPDATE_TYPE ||''~''||'
21430 ||'FORWARD_UPDATE_TIME_FENCE ||''~''||'
21431 ||'BACKWARD_UPDATE_TIME_FENCE ||''~''||'
21432 ||'OUTLIER_UPDATE_PERCENTAGE ||''~''||'
21433 ||'CUSTOMER_NAME ||''~''||'
21434 ||'SHIP_TO_SITE_CODE ||''~''||'
21435 ||'BILL_TO_SITE_CODE ||''~''||'
21436 ||'FORECAST_SET ||''~''||'
21437 ||'COMPANY_NAME ||''~''||'
21438 ||'DESIGNATOR_TYPE ||''~''||'
21439 ||'PROBABILITY';
21440
21441 LOOP
21442 v_sql_stmt := 03;
21443
21444 SELECT msc_st_batch_id_s.NEXTVAL
21445 INTO lv_batch_id
21446 FROM dual;
21447
21448 v_sql_stmt := 04;
21449 lv_sql_stmt :=
21450 'UPDATE msc_st_designators '
21451 ||' SET batch_id = :lv_batch_id'
21452 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
21453 ||' AND sr_instance_code = :v_instance_code'
21454 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
21455 ||' AND rownum <= '||v_batch_size;
21456
21457
21458 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
21459
21460 EXECUTE IMMEDIATE lv_sql_stmt
21461 USING lv_batch_id,
21462 v_instance_code;
21463
21464 EXIT WHEN SQL%NOTFOUND;
21465
21466 OPEN c1(lv_batch_id);
21467 FETCH c1 BULK COLLECT INTO lb_rowid;
21468 CLOSE c1;
21469
21470 v_sql_stmt := 05;
21471 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
21472 UPDATE msc_st_designators
21473 SET st_transaction_id = msc_st_designators_s.NEXTVAL,
21474 refresh_id = v_refresh_id,
21475 last_update_date = v_current_date,
21476 last_updated_by = v_current_user,
21477 creation_date = v_current_date,
21478 created_by = v_current_user
21479 WHERE rowid = lb_rowid(j);
21480
21481 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
21482 (p_app_short_name => 'MSC',
21483 p_error_code => 'MSC_PP_INVALID_VALUE',
21484 p_message_text => lv_message_text,
21485 p_error_text => lv_error_text,
21486 p_token1 => 'COLUMN_NAME',
21487 p_token_value1 => 'DESIGNATOR_TYPE');
21488
21489 IF lv_return <> 0 THEN
21490 RAISE ex_logging_err;
21491 END IF;
21492
21493 v_sql_stmt := 06;
21494 lv_sql_stmt :=
21495 'UPDATE msc_st_designators '
21496 ||' SET error_text = '||''''||lv_message_text||''''||','
21497 ||' process_flag = '||G_ERROR_FLG
21498 ||' WHERE nvl(designator_type,'||NULL_VALUE||') NOT IN(1,2,6)'
21499 ||' AND deleted_flag = '||SYS_NO
21500 ||' AND process_flag = '||G_IN_PROCESS
21501 ||' AND batch_id = :lv_batch_id'
21502 ||' AND sr_instance_code = :v_instance_code';
21503
21504
21505 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
21506
21507 EXECUTE IMMEDIATE lv_sql_stmt
21508 USING lv_batch_id,
21509 v_instance_code;
21510
21511 -- Set message
21512
21513 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
21514 (p_app_short_name => 'MSC',
21515 p_error_code => 'MSC_PP_NO_DELETION',
21516 p_message_text => lv_message_text,
21517 p_error_text => lv_error_text,
21518 p_token1 => 'TABLE_NAME',
21519 p_token_value1 => 'MSC_ST_DESIGNATORS');
21520
21521 IF lv_return <> 0 THEN
21522 RAISE ex_logging_err;
21523 END IF;
21524
21525 -- Deletion is not allowed for this table
21526 v_sql_stmt := 07;
21527 lv_sql_stmt :=
21528 'UPDATE msc_st_designators '
21529 ||' SET process_flag = '||G_ERROR_FLG||','
21530 ||' error_text = '||''''||lv_message_text||''''
21531 ||' WHERE deleted_flag = '||SYS_YES
21532 ||' AND process_flag = '||G_IN_PROCESS
21533 ||' AND batch_id = :lv_batch_id'
21534 ||' AND sr_instance_code = :v_instance_code';
21535
21536
21537
21538 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
21539 EXECUTE IMMEDIATE lv_sql_stmt
21540 USING lv_batch_id,
21541 v_instance_code;
21542
21543
21544
21545 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
21546 (p_app_short_name => 'MSC',
21547 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
21548 p_message_text => lv_message_text,
21549 p_error_text => lv_error_text,
21550 p_token1 => 'COLUMN_NAME',
21551 p_token_value1 => 'DELETED_FLAG',
21552 p_token2 => 'DEFAULT_VALUE',
21553 p_token_value2 => SYS_NO);
21554
21555 IF lv_return <> 0 THEN
21556 RAISE ex_logging_err;
21557 END IF;
21558
21559 lv_where_str :=
21560 ' AND NVL(deleted_flag,'||NULL_VALUE||') NOT IN(1,2)';
21561
21562 --Log a warning for those records where the deleted_flag has a value other
21563 --SYS_NO
21564 lv_return := MSC_ST_UTIL.LOG_ERROR
21565 (p_table_name => 'MSC_ST_DESIGNATORS',
21566 p_instance_code => v_instance_code,
21567 p_row => lv_column_names,
21568 p_severity => G_SEV_WARNING,
21569 p_message_text => lv_message_text,
21570 p_error_text => lv_error_text,
21571 p_batch_id => lv_batch_id,
21572 p_where_str => lv_where_str,
21573 p_col_name => 'DELETED_FLAG',
21574 p_debug => v_debug,
21575 p_default_value => SYS_NO);
21576
21577 IF lv_return <> 0 THEN
21578 RAISE ex_logging_err;
21579 END IF;
21580
21581 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
21582 (p_app_short_name => 'MSC',
21583 p_error_code => 'MSC_PP_INVALID_VALUE',
21584 p_message_text => lv_message_text,
21585 p_error_text => lv_error_text,
21586 p_token1 => 'COLUMN_NAME',
21587 p_token_value1 => 'ORGANIZATION_CODE');
21588
21589 IF lv_return <> 0 THEN
21590 RAISE ex_logging_err;
21591 END IF;
21592
21593 --Derive Organization_id
21594 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
21595 (p_table_name => 'MSC_ST_DESIGNATORS',
21596 p_org_partner_name => 'ORGANIZATION_CODE',
21597 p_org_partner_id => 'ORGANIZATION_ID',
21598 p_instance_code => v_instance_code,
21599 p_partner_type => G_ORGANIZATION,
21600 p_error_text => lv_error_text,
21601 p_batch_id => lv_batch_id,
21602 p_severity => G_SEV_ERROR,
21603 p_message_text => lv_message_text,
21604 p_debug => v_debug,
21605 p_row => lv_column_names);
21606
21607 IF lv_return <> 0 THEN
21608 RAISE ex_logging_err;
21609 END IF;
21610
21611 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
21612 (p_app_short_name => 'MSC',
21613 p_error_code => 'MSC_PP_COL_VAL_NULL',
21614 p_message_text => lv_message_text,
21615 p_error_text => lv_error_text,
21616 p_token1 => 'COLUMN_NAME',
21617 p_token_value1 => 'DESIGNATOR');
21618
21619 IF lv_return <> 0 THEN
21620 RAISE ex_logging_err;
21621 END IF;
21622
21623 v_sql_stmt := 08;
21624 lv_sql_stmt :=
21625 'UPDATE msc_st_designators '
21626 ||' SET error_text = '||''''||lv_message_text||''''||','
21627 ||' process_flag = '||G_ERROR_FLG
21628 ||' WHERE NVL(designator,'||''''||NULL_CHAR||''''||')'
21629 ||' = '||''''||NULL_CHAR||''''
21630 ||' AND deleted_flag = '||SYS_NO
21631 ||' AND process_flag = '||G_IN_PROCESS
21632 ||' AND batch_id = :lv_batch_id'
21633 ||' AND sr_instance_code = :v_instance_code';
21634
21635
21636 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
21637
21638 EXECUTE IMMEDIATE lv_sql_stmt
21639 USING lv_batch_id,
21640 v_instance_code;
21641
21642 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
21643 (p_app_short_name => 'MSC',
21644 p_error_code => 'MSC_PP_INVALID_VALUE',
21645 p_message_text => lv_message_text,
21646 p_error_text => lv_error_text,
21647 p_token1 => 'COLUMN_NAME',
21648 p_token_value1 => 'DEMAND_CLASS');
21649
21650 IF lv_return <> 0 THEN
21651 RAISE ex_logging_err;
21652 END IF;
21653
21654 -- Validate Demand Class, if value provided it should exists
21655 -- in ODS or staging table
21656 lv_return :=
21657 MSC_ST_UTIL.VALIDATE_DMD_CLASS(p_table_name => 'MSC_ST_DESIGNATORS',
21658 p_dmd_class_column => 'DEMAND_CLASS',
21659 p_instance_id => v_instance_id,
21660 p_instance_code => v_instance_code,
21661 p_severity => G_SEV3_ERROR,
21662 p_message_text => lv_message_text,
21663 p_batch_id => lv_batch_id,
21664 p_debug => v_debug,
21665 p_error_text => lv_error_text);
21666
21667 if(lv_return <> 0) then
21668 RAISE ex_logging_err;
21669 end if;
21670
21671
21672 v_sql_stmt := 10;
21673 lv_sql_stmt :=
21674 'UPDATE msc_st_designators '
21675 ||' SET inventory_atp_flag = '||G_FOR_INV_ATP_FLAG
21676 --||' mps_relief = '||G_FOR_MPS_RELIEF ||','
21677 --||' consume_forecast = '||G_CONSUME_FORECAST ||','
21678 --||' update_type = '||G_UPDATE_TYPE
21679 ||' WHERE nvl(inventory_atp_flag,'||NULL_VALUE||') NOT IN(1,2)'
21680 ||' AND designator_type ='||G_FORECAST_DESIGNATOR
21681 ||' AND process_flag = '||G_IN_PROCESS
21682 ||' AND batch_id = :lv_batch_id'
21683 ||' AND sr_instance_code = :v_instance_code';
21684
21685
21686 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
21687
21688 EXECUTE IMMEDIATE lv_sql_stmt
21689 USING lv_batch_id,
21690 v_instance_code;
21691
21692 v_sql_stmt := 11;
21693 lv_sql_stmt :=
21694 'UPDATE msc_st_designators '
21695 ||' SET inventory_atp_flag = '||G_INV_ATP_FLAG
21696 ||' WHERE NVL(inventory_atp_flag,'||NULL_VALUE||') NOT IN(1,2)'
21697 ||' AND NVL(designator_type,'||NULL_VALUE||') IN(1,2)'
21698 ||' AND process_flag = '||G_IN_PROCESS
21699 ||' AND batch_id = :lv_batch_id'
21700 ||' AND sr_instance_code = :v_instance_code';
21701
21702
21703 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
21704
21705 EXECUTE IMMEDIATE lv_sql_stmt
21706 USING lv_batch_id,
21707 v_instance_code;
21708
21709 v_sql_stmt := 12;
21710 lv_sql_stmt :=
21711 'UPDATE msc_st_designators '
21712 ||' SET mps_relief = '||G_MPS_RELIEF
21713 ||' WHERE designator_type IN(1,2)'
21714 ||' AND process_flag ='|| G_IN_PROCESS
21715 ||' AND batch_id = :lv_batch_id'
21716 ||' AND sr_instance_code = :v_instance_code';
21717
21718
21719 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
21720
21721 EXECUTE IMMEDIATE lv_sql_stmt
21722 USING lv_batch_id,
21723 v_instance_code;
21724
21725 v_sql_stmt := 13;
21726 lv_sql_stmt :=
21727 ' UPDATE msc_st_designators '
21728 ||' SET bucket_type = '||G_BUCKET_TYPE
21729 ||' WHERE NVL(bucket_type,'||NULL_VALUE||') NOT IN(1,2,3,'||NULL_VALUE||')'
21730 ||' AND designator_type = 6'
21731 ||' AND process_flag = '||G_IN_PROCESS
21732 ||' AND batch_id = :lv_batch_id'
21733 ||' AND sr_instance_code = :v_instance_code';
21734
21735
21736 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
21737
21738 EXECUTE IMMEDIATE lv_sql_stmt
21739 USING lv_batch_id,
21740 v_instance_code;
21741
21742
21743 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
21744 (p_app_short_name => 'MSC',
21745 p_error_code => 'MSC_PP_INVALID_VALUE',
21746 p_message_text => lv_message_text,
21747 p_error_text => lv_error_text,
21748 p_token1 => 'COLUMN_NAME',
21749 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME and CUSTOMER_NAME');
21750
21751 IF lv_return <> 0 THEN
21752 RAISE ex_logging_err;
21753 END IF;
21754
21755 --Derive Customer_id
21756 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
21757 (p_table_name => 'MSC_ST_DESIGNATORS',
21758 p_org_partner_name => 'CUSTOMER_NAME',
21759 p_org_partner_id => 'CUSTOMER_ID',
21760 p_instance_code => v_instance_code,
21761 p_partner_type => G_CUSTOMER,
21762 p_error_text => lv_error_text,
21763 p_batch_id => lv_batch_id,
21764 p_severity => G_SEV_WARNING,
21765 p_message_text => lv_message_text,
21766 p_debug => v_debug,
21767 p_row => lv_column_names);
21768
21769 IF lv_return <> 0 THEN
21770 RAISE ex_logging_err;
21771 END IF;
21772
21773 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
21774 (p_app_short_name => 'MSC',
21775 p_error_code => 'MSC_PP_INVALID_VALUE',
21776 p_message_text => lv_message_text,
21777 p_error_text => lv_error_text,
21778 p_token1 => 'COLUMN_NAME',
21779 p_token_value1 => 'SR_INSTANCE_CODE, COMPANY_NAME, CUSTOMER_NAME and BILL_TO_SITE_CODE');
21780
21781 IF lv_return <> 0 THEN
21782 RAISE ex_logging_err;
21783 END IF;
21784
21785 --Derive Bill_id
21786 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
21787 (p_table_name => 'MSC_ST_DESIGNATORS',
21788 p_partner_name => 'CUSTOMER_NAME',
21789 p_partner_site_code => 'BILL_TO_SITE_CODE',
21790 p_partner_site_id => 'BILL_ID',
21791 p_instance_code => v_instance_code,
21792 p_partner_type => G_CUSTOMER,
21793 p_error_text => lv_error_text,
21794 p_batch_id => lv_batch_id,
21795 p_severity => G_SEV_WARNING,
21796 p_message_text => lv_message_text,
21797 p_debug => v_debug,
21798 p_row => lv_column_names);
21799
21800 IF lv_return <> 0 THEN
21801 RAISE ex_logging_err;
21802 END IF;
21803
21804 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
21805 (p_app_short_name => 'MSC',
21806 p_error_code => 'MSC_PP_INVALID_VALUE',
21807 p_message_text => lv_message_text,
21808 p_error_text => lv_error_text,
21809 p_token1 => 'COLUMN_NAME',
21810 p_token_value1 => 'SR_INSTANCE_CODE, COMPANY_NAME, CUSTOMER_NAME and SHIP_TO_SITE_CODE');
21811
21812 IF lv_return <> 0 THEN
21813 RAISE ex_logging_err;
21814 END IF;
21815
21816 --Derive Ship_id
21817 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
21818 (p_table_name => 'MSC_ST_DESIGNATORS',
21819 p_partner_name => 'CUSTOMER_NAME',
21820 p_partner_site_code => 'SHIP_TO_SITE_CODE',
21821 p_partner_site_id => 'SHIP_ID',
21822 p_instance_code => v_instance_code,
21823 p_partner_type => G_CUSTOMER,
21824 p_error_text => lv_error_text,
21825 p_batch_id => lv_batch_id,
21826 p_severity => G_SEV_WARNING,
21827 p_message_text => lv_message_text,
21828 p_debug => v_debug,
21829 p_row => lv_column_names);
21830
21831 IF lv_return <> 0 THEN
21832 RAISE ex_logging_err;
21833 END IF;
21834
21835 --Call to customised validation.
21836 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
21837 (ERRBUF => lv_error_text,
21838 RETCODE => lv_return,
21839 pBatchID => lv_batch_id,
21840 pInstanceCode => v_instance_code,
21841 pEntityName => 'MSC_ST_DESIGNATORS',
21842 pInstanceID => v_instance_id);
21843
21844 IF NVL(lv_return,0) <> 0 THEN
21845 RAISE ex_logging_err;
21846 END IF;
21847
21848
21849 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
21850 (p_app_short_name => 'MSC',
21851 p_error_code => 'MSC_PP_COL_VAL_EXISTS',
21852 p_message_text => lv_message_text,
21853 p_error_text => lv_error_text,
21854 p_token1 => 'COLUMN_NAME1',
21855 p_token_value1 => 'DESIGNATOR',
21856 p_token2 => 'COLUMN_NAME2',
21857 p_token_value2 => 'DESIGNATOR_TYPE',
21858 p_token3 => 'ODS_TABLE_NAME',
21859 p_token_value3 => 'MSC_DESIGNATORS');
21860
21861 IF lv_return <> 0 THEN
21862 RAISE ex_logging_err;
21863 END IF;
21864
21865
21866 lv_sql_stmt :=
21867 'UPDATE msc_st_designators msd'
21868 ||' SET error_text = '||''''||lv_message_text||''''||','
21869 ||' process_flag = '||G_ERROR_FLG
21870 ||' WHERE EXISTS (SELECT 1 '
21871 ||' FROM msc_designators md'
21872 ||' WHERE md.designator = msd.designator'
21873 ||' AND md.sr_instance_id = :v_instance_id'
21874 ||' AND md.organization_id= msd.organization_id'
21875 ||' AND md.designator_type <> msd.designator_type)'
21876 ||' AND msd.deleted_flag = '||SYS_NO
21877 ||' AND msd.process_flag = '||G_IN_PROCESS
21878 ||' AND msd.batch_id = :lv_batch_id'
21879 ||' AND msd.sr_instance_code = :v_instance_code';
21880
21881
21882 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
21883
21884 EXECUTE IMMEDIATE lv_sql_stmt
21885 USING v_instance_id,
21886 lv_batch_id,
21887 v_instance_code;
21888
21889
21890
21891 -- For forecast set we check in ODS if it does not exist then
21892 -- Insert record in staging for forecast set
21893
21894 v_sql_stmt := 14;
21895 lv_sql_stmt :=
21896 'insert into MSC_ST_DESIGNATORS'
21897 ||' ( DESIGNATOR,'
21898 ||' FORECAST_SET,'
21899 ||' COMPANY_ID,'
21900 ||' ORGANIZATION_ID,'
21901 ||' MPS_RELIEF,'
21902 ||' INVENTORY_ATP_FLAG,'
21903 ||' DESCRIPTION,'
21904 ||' DISABLE_DATE,'
21905 ||' DEMAND_CLASS,'
21906 ||' CONSUME_FORECAST,'
21907 ||' UPDATE_TYPE,'
21908 ||' FORWARD_UPDATE_TIME_FENCE,'
21909 ||' BACKWARD_UPDATE_TIME_FENCE,'
21910 ||' OUTLIER_UPDATE_PERCENTAGE,'
21911 ||' CUSTOMER_ID,'
21912 ||' SHIP_ID,'
21913 ||' BILL_ID,'
21914 ||' BUCKET_TYPE,'
21915 ||' DESIGNATOR_TYPE,'
21916 ||' DELETED_FLAG,'
21917 ||' REFRESH_ID,'
21918 ||' ST_TRANSACTION_ID,'
21919 ||' BATCH_ID,'
21920 ||' MESSAGE_ID,'
21921 ||' DATA_SOURCE_TYPE,'
21922 ||' PROCESS_FLAG,'
21923 ||' SR_INSTANCE_CODE)'
21924 ||' select'
21925 ||' FORECAST_SET,'
21926 ||' NULL,'
21927 ||' COMPANY_ID,'
21928 ||' ORGANIZATION_ID,'
21929 ||' MPS_RELIEF,'
21930 ||' INVENTORY_ATP_FLAG,'
21931 ||' DESCRIPTION,'
21932 ||' DISABLE_DATE,'
21933 ||' DEMAND_CLASS,'
21934 ||' CONSUME_FORECAST,'
21935 ||' UPDATE_TYPE,'
21936 ||' FORWARD_UPDATE_TIME_FENCE,'
21937 ||' BACKWARD_UPDATE_TIME_FENCE,'
21938 ||' OUTLIER_UPDATE_PERCENTAGE,'
21939 ||' CUSTOMER_ID,'
21940 ||' SHIP_ID,'
21941 ||' BILL_ID,'
21942 ||' BUCKET_TYPE,'
21943 ||' DESIGNATOR_TYPE,'
21944 ||' DELETED_FLAG,'
21945 || v_refresh_id ||' , '
21946 ||' ST_TRANSACTION_ID,'
21947 ||' BATCH_ID,'
21948 ||' MESSAGE_ID,'
21949 ||' DATA_SOURCE_TYPE,'
21950 || G_IN_PROCESS||','
21951 ||' SR_INSTANCE_CODE'
21952 ||' from MSC_ST_DESIGNATORS msd'
21953 ||' WHERE NOT EXISTS ('
21954 /* Bug 13114192
21955 ||' SELECT 1 FROM MSC_DESIGNATORS md'
21956 ||' WHERE md.designator = msd.forecast_set'
21957 ||' AND NVL(md.forecast_set_id,'||NULL_VALUE||') = '||NULL_VALUE
21958 ||' AND md.organization_id = msd.organization_id'
21959 ||' AND md.sr_instance_id = :v_instance_id'
21960 ||' UNION'
21961 */
21962 ||' SELECT 1'
21963 ||' FROM msc_st_designators msd1'
21964 ||' WHERE msd.forecast_set = msd1.designator'
21965 ||' AND msd.organization_code = msd1.organization_code'
21966 ||' AND msd1.sr_instance_code = :v_instance_code'
21967 ||' AND msd1.designator_type = 6'
21968 ||' AND NVL(msd1.forecast_set,'||''''||NULL_CHAR||''''||')'
21969 ||' = '||''''||NULL_CHAR||''''
21970 ||' AND msd1.process_flag IN ('||G_IN_PROCESS||','||G_VALID||')'
21971 ||' AND msd.rowid <> msd1.rowid)'
21972 ||' AND NVL(msd.forecast_set,'||''''||NULL_CHAR||''''||')'
21973 ||' <> '||''''||NULL_CHAR||''''
21974 ||' AND msd.designator_type = 6'
21975 ||' AND msd.batch_id = :lv_batch_id'
21976 ||' AND msd.process_flag ='||G_IN_PROCESS
21977 ||' AND msd.sr_instance_code = :v_instance_code' ;
21978
21979
21980
21981 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
21982
21983 EXECUTE IMMEDIATE lv_sql_stmt
21984 USING -- Bug 13114192: v_instance_id,
21985 v_instance_code,
21986 lv_batch_id,
21987 v_instance_code;
21988
21989
21990
21991 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
21992 (p_table_name => 'MSC_ST_DESIGNATORS',
21993 p_instance_id => v_instance_id,
21994 p_instance_code => v_instance_code,
21995 p_process_flag => G_VALID,
21996 p_error_text => lv_error_text,
21997 p_debug => v_debug,
21998 p_batch_id => lv_batch_id);
21999
22000 IF lv_return <> 0 THEN
22001 RAISE ex_logging_err;
22002 END IF;
22003
22004 lv_return := MSC_ST_UTIL.LOG_ERROR
22005 (p_table_name => 'MSC_ST_DESIGNATORS',
22006 p_instance_code => v_instance_code,
22007 p_row => lv_column_names,
22008 p_severity => G_SEV_ERROR,
22009 p_message_text => NULL,
22010 p_error_text => lv_error_text,
22011 p_debug => v_debug,
22012 p_batch_id => lv_batch_id);
22013 IF lv_return <> 0 THEN
22014 RAISE ex_logging_err;
22015 END IF;
22016 COMMIT;
22017 END LOOP;
22018
22019 EXCEPTION
22020 WHEN ex_logging_err THEN
22021 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
22022 ROLLBACK;
22023
22024 WHEN OTHERS THEN
22025 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_DESIGNATOR'||'('
22026 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
22027 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
22028 ROLLBACK;
22029
22030 END LOAD_DESIGNATOR;
22031
22032 /*==========================================================================+
22033 | DESCRIPTION : This function performs the validation and loads the data |
22034 | for business object item |
22035 +==========================================================================*/
22036 PROCEDURE LOAD_ITEMS(p_batch_id NUMBER) IS
22037
22038 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
22039 lb_rowid RowidTab;
22040 lb_rowid_abc RowidTab;
22041
22042 lv_column_names VARCHAR2(5000); -- Stores cocatenated column names
22043 lv_return NUMBER;
22044 lv_error_text VARCHAR2(250);
22045 lv_where_str VARCHAR2(5000);
22046 lv_sql_stmt VARCHAR2(5000);
22047 lv_batch_id msc_st_system_items.batch_id%TYPE;
22048 lv_message_text msc_errors.error_text%TYPE;
22049
22050 ex_logging_err EXCEPTION;
22051 busy EXCEPTION;
22052 PRAGMA EXCEPTION_INIT(busy, -54);
22053
22054 CURSOR c1(p_batch_id NUMBER) IS
22055 SELECT rowid
22056 FROM msc_st_system_items
22057 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
22058 AND sr_instance_code = v_instance_code
22059 AND batch_id = p_batch_id;
22060
22061 CURSOR c2(p_batch_id NUMBER) IS
22062 SELECT max(ROWID)
22063 FROM msc_st_system_items
22064 WHERE NVL(sr_inventory_item_id,NULL_VALUE) = NULL_VALUE
22065 AND process_flag = G_IN_PROCESS
22066 AND sr_instance_code = v_instance_code
22067 AND batch_id = p_batch_id
22068 GROUP BY item_name, sr_instance_code,company_name;
22069
22070 /**** Don't need this cursor anymore -- bug fix 2191021
22071 CURSOR c3(p_batch_id NUMBER) IS
22072 SELECT max(ROWID)
22073 FROM msc_st_system_items
22074 WHERE ABC_CLASS_ID IS NULL
22075 AND ABC_CLASS_NAME IS NOT NULL
22076 AND process_flag = G_IN_PROCESS
22077 AND sr_instance_code = v_instance_code
22078 AND batch_id = p_batch_id
22079 GROUP BY ABC_CLASS_NAME, organization_code, sr_instance_code, company_name;
22080 ******/
22081
22082 CURSOR c_lock(p_batch_id NUMBER) IS
22083 SELECT 'X'
22084 FROM msc_st_system_items msi1,
22085 msc_st_system_items msi2
22086 WHERE msi1.batch_id = p_batch_id
22087 AND msi1.batch_id <> nvl(msi2.batch_id,NULL_VALUE)
22088 AND msi1.sr_inventory_item_id IS NULL
22089 AND msi2.sr_inventory_item_id IS NULL
22090 AND msi1.sr_instance_code = msi2.sr_instance_code
22091 AND msi1.item_name = msi2.item_name
22092 AND NVL(msi1.company_name,NULL_CHAR)= NVL(msi2.company_name,NULL_CHAR)
22093 FOR UPDATE NOWAIT ;
22094
22095 /**** Don't need this lock anymore -- bug fix 2191021
22096 CURSOR c_lock_abc(p_batch_id NUMBER) IS
22097 SELECT 'X'
22098 FROM msc_st_system_items msi1 ,
22099 msc_st_system_items msi2
22100 WHERE msi1.batch_id = p_batch_id
22101 AND msi1.batch_id <> nvl(msi2.batch_id,NULL_VALUE)
22102 AND msi1.abc_class_id IS NULL
22103 AND msi2.abc_class_id IS NULL
22104 AND msi1.sr_instance_code = msi2.sr_instance_code
22105 AND msi1.abc_class_name = msi2.abc_class_name
22106 AND msi1.organization_code = msi2.organization_code
22107 AND NVL(msi1.company_name,NULL_CHAR) = NVL(msi2.company_name,NULL_CHAR)
22108 FOR UPDATE NOWAIT ;
22109 *******/
22110
22111
22112 BEGIN
22113
22114 -- Validation of table msc_st_system_items
22115
22116 lv_column_names :=
22117 'ORGANIZATION_CODE ||''~''||'
22118 ||'ITEM_NAME ||''~''||'
22119 ||'LOT_CONTROL_CODE ||''~''||'
22120 ||'ROUNDING_CONTROL_TYPE ||''~''||'
22121 ||'IN_SOURCE_PLAN ||''~''||'
22122 ||'MRP_PLANNING_CODE ||''~''||'
22123 ||'FULL_LEAD_TIME ||''~''||'
22124 ||'UOM_CODE ||''~''||'
22125 ||'MRP_CALCULATE_ATP_FLAG ||''~''||'
22126 ||'ATP_COMPONENTS_FLAG ||''~''||'
22127 ||'BUILT_IN_WIP_FLAG ||''~''||'
22128 ||'PURCHASING_ENABLED_FLAG ||''~''||'
22129 ||'PLANNING_MAKE_BUY_CODE ||''~''||'
22130 ||'REPETITIVE_TYPE ||''~''||'
22131 ||'ENGINEERING_ITEM_FLAG ||''~''||'
22132 ||'MRP_SAFETY_STOCK_CODE ||''~''||'
22133 ||'EFFECTIVITY_CONTROL ||''~''||'
22134 ||'INVENTORY_PLANNING_CODE ||''~''||'
22135 ||'ATP_FLAG ||''~''||'
22136 ||'SR_INSTANCE_CODE ||''~''||'
22137 ||'DESCRIPTION ||''~''||'
22138 ||'LOTS_EXPIRATION ||''~''||'
22139 ||'SHRINKAGE_RATE ||''~''||'
22140 ||'FIXED_DAYS_SUPPLY ||''~''||'
22141 ||'FIXED_ORDER_QUANTITY ||''~''||'
22142 ||'FIXED_LOT_MULTIPLIER ||''~''||'
22143 ||'MINIMUM_ORDER_QUANTITY ||''~''||'
22144 ||'MAXIMUM_ORDER_QUANTITY ||''~''||'
22145 ||'PLANNING_TIME_FENCE_DAYS ||''~''||'
22146 ||'DEMAND_TIME_FENCE_DAYS ||''~''||'
22147 ||'RELEASE_TIME_FENCE_CODE ||''~''||'
22148 ||'RELEASE_TIME_FENCE_DAYS ||''~''||'
22149 ||'REVISION ||''~''||'
22150 ||'CATEGORY_NAME ||''~''||'
22151 ||'ABC_CLASS_NAME ||''~''||'
22152 ||'FIXED_LEAD_TIME ||''~''||'
22153 ||'VARIABLE_LEAD_TIME ||''~''||'
22154 ||'PREPROCESSING_LEAD_TIME ||''~''||'
22155 ||'POSTPROCESSING_LEAD_TIME ||''~''||'
22156 ||'CUMULATIVE_TOTAL_LEAD_TIME ||''~''||'
22157 ||'CUM_MANUFACTURING_LEAD_TIME ||''~''||'
22158 ||'UNIT_WEIGHT ||''~''||'
22159 ||'UNIT_VOLUME ||''~''||'
22160 ||'WEIGHT_UOM ||''~''||'
22161 ||'VOLUME_UOM ||''~''||'
22162 ||'PRODUCT_FAMILY_ID ||''~''||'
22163 ||'ATP_RULE_CODE ||''~''||'
22164 ||'STANDARD_COST ||''~''||'
22165 ||'CARRYING_COST ||''~''||'
22166 ||'ORDER_COST ||''~''||'
22167 ||'DMD_LATENESS_COST ||''~''||'
22168 ||'SS_PENALTY_COST ||''~''||'
22169 ||'SUPPLIER_CAP_OVERUTIL_COST ||''~''||'
22170 ||'LIST_PRICE ||''~''||'
22171 ||'AVERAGE_DISCOUNT ||''~''||'
22172 ||'END_ASSEMBLY_PEGGING_FLAG ||''~''||'
22173 ||'END_ASSEMBLY_PEGGING ||''~''||'
22174 ||'FULL_PEGGING ||''~''||'
22175 ||'WIP_SUPPLY_TYPE ||''~''||'
22176 ||'MRP_SAFETY_STOCK_PERCENT ||''~''||'
22177 ||'SAFETY_STOCK_BUCKET_DAYS ||''~''||'
22178 ||'INVENTORY_USE_UP_DATE ||''~''||'
22179 ||'BUYER_NAME ||''~''||'
22180 ||'PLANNER_CODE ||''~''||'
22181 ||'PLANNING_EXCEPTION_SET ||''~''||'
22182 ||'EXCESS_QUANTITY ||''~''||'
22183 ||'EXCEPTION_SHORTAGE_DAYS ||''~''||'
22184 ||'EXCEPTION_EXCESS_DAYS ||''~''||'
22185 ||'EXCEPTION_OVERPROMISED_DAYS ||''~''||'
22186 ||'REPETITIVE_VARIANCE_DAYS ||''~''||'
22187 ||'BASE_ITEM_NAME ||''~''||'
22188 ||'BOM_ITEM_TYPE ||''~''||'
22189 ||'ATO_FORECAST_CONTROL ||''~''||'
22190 ||'ACCEPTABLE_EARLY_DELIVERY ||''~''||'
22191 ||'ACCEPTABLE_RATE_INCREASE ||''~''||'
22192 ||'ACCEPTABLE_RATE_DECREASE ||''~''||'
22193 ||'PRIMARY_SUPPLIER_NAME ||''~''||'
22194 ||'INVENTORY_ITEM_FLAG ||''~''||'
22195 ||'REVISION_QTY_CONTROL_CODE ||''~''||'
22196 ||'EXPENSE_ACCOUNT ||''~''||'
22197 ||'INVENTORY_ASSET_FLAG ||''~''||'
22198 ||'MATERIAL_COST ||''~''||'
22199 ||'RESOURCE_COST ||''~''||'
22200 ||'SOURCE_ORG_CODE ||''~''||'
22201 ||'PICK_COMPONENTS_FLAG ||''~''||'
22202 ||'ALLOWED_UNITS_LOOKUP_CODE ||''~''||'
22203 ||'SERVICE_LEVEL ||''~''||'
22204 ||'REPLENISH_TO_ORDER_FLAG ||''~''||'
22205 ||'COMPANY_NAME ||''~''||'
22206 ||'SERIAL_NUMBER_CONTROL_CODE ||''~''||'
22207 ||'REPAIR_LEAD_TIME ||''~''||'
22208 ||'PREPOSITION_POINT ||''~''||'
22209 ||'REPAIR_YIELD ||''~''||'
22210 ||'REPAIR_PROGRAM ||''~''||'
22211 ||'DELETED_FLAG';
22212
22213
22214
22215
22216 lv_batch_id := p_batch_id;
22217
22218 LOOP
22219 BEGIN
22220 v_sql_stmt := 01;
22221 OPEN c_lock(p_batch_id) ;
22222 EXIT;
22223 EXCEPTION
22224 WHEN busy THEN
22225 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_ITEM'||'(' ||v_sql_stmt||')'|| SQLERRM, 1, 240);
22226 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
22227 dbms_lock.sleep(5);
22228 WHEN OTHERS THEN
22229 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_ITEM'||'(' ||v_sql_stmt||')'|| SQLERRM, 1, 240);
22230 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
22231
22232 v_sql_stmt := 02;
22233 lv_sql_stmt :=
22234 'UPDATE msc_st_system_items '
22235 ||' SET process_flag = 1, '
22236 ||' batch_id = NULL'
22237 ||' WHERE batch_id = :p_batch_id'
22238 ||' AND process_flag = '||G_IN_PROCESS
22239 ||' AND sr_instance_code = :v_instance_code';
22240
22241
22242 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
22243
22244 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
22245 COMMIT;
22246 RETURN;
22247 END ;
22248 END LOOP ;
22249
22250 /************ No need to acquire this lock anymore -- bug fix for 2191021
22251 LOOP
22252 BEGIN
22253 v_sql_stmt := 01;
22254 OPEN c_lock_abc(p_batch_id) ;
22255 EXIT;
22256 EXCEPTION
22257 WHEN busy THEN
22258 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_ITEM'||'(' ||v_sql_stmt||')'|| SQLERRM, 1, 240);
22259 msc_st_util.log_message(lv_error_text);
22260 dbms_lock.sleep(5);
22261 WHEN OTHERS THEN
22262 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_ITEM'||'(' ||v_sql_stmt||')'|| SQLERRM, 1, 240);
22263 msc_st_util.log_message(lv_error_text);
22264
22265 v_sql_stmt := 03;
22266 lv_sql_stmt :=
22267 'UPDATE msc_st_system_items '
22268 ||' SET process_flag = 1, '
22269 ||' batch_id = NULL'
22270 ||' WHERE batch_id = :p_batch_id'
22271 ||' AND process_flag = '||G_IN_PROCESS
22272 ||' AND sr_instance_code = :v_instance_code';
22273
22274
22275 msc_st_util.log_message(lv_sql_stmt);
22276
22277 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
22278 COMMIT;
22279 RETURN;
22280 END ;
22281 END LOOP ;
22282 ******/
22283
22284 -- Update transaction id and WHO columns
22285
22286 OPEN c1(lv_batch_id);
22287
22288 v_sql_stmt := 01;
22289
22290 FETCH c1 BULK COLLECT INTO lb_rowid;
22291
22292 v_sql_stmt := 04;
22293
22294 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
22295 UPDATE msc_st_system_items
22296 SET st_transaction_id = msc_st_system_items_s.NEXTVAL,
22297 refresh_id = v_refresh_id,
22298 last_update_date = v_current_date,
22299 last_updated_by = v_current_user,
22300 creation_date = v_current_date,
22301 created_by = v_current_user
22302 WHERE rowid = lb_rowid(j);
22303
22304
22305 -- Set the error message
22306
22307 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
22308 (p_app_short_name => 'MSC',
22309 p_error_code => 'MSC_PP_COL_VAL_NULL',
22310 p_message_text => lv_message_text,
22311 p_error_text => lv_error_text,
22312 p_token1 => 'COLUMN_NAME',
22313 p_token_value1 => 'ITEM_NAME');
22314
22315 IF lv_return <> 0 THEN
22316 RAISE ex_logging_err;
22317 END IF;
22318
22319 -- Error out records where item_name is NULL
22320
22321 v_sql_stmt := 06;
22322
22323 lv_sql_stmt :=
22324 ' UPDATE msc_st_system_items '
22325 ||' SET process_flag = '||G_ERROR_FLG||','
22326 ||' error_text = '||''''||lv_message_text||''''
22327 ||' WHERE NVL(item_name,'||''''||NULL_CHAR||''''||')'
22328 ||' = '||''''||NULL_CHAR||''''
22329 ||' AND batch_id = :lv_batch_id'
22330 ||' AND process_flag = '||G_IN_PROCESS
22331 ||' AND sr_instance_code = :v_instance_code';
22332
22333
22334 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
22335
22336
22337 EXECUTE IMMEDIATE lv_sql_stmt
22338 USING lv_batch_id,
22339 v_instance_code;
22340
22341 -- Set the error message
22342
22343 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
22344 (p_app_short_name => 'MSC',
22345 p_error_code => 'MSC_PP_NO_DELETION',
22346 p_message_text => lv_message_text,
22347 p_error_text => lv_error_text,
22348 p_token1 => 'TABLE_NAME',
22349 p_token_value1 => 'MSC_ST_SYSTEM_ITEMS');
22350
22351 IF lv_return <> 0 THEN
22352 RAISE ex_logging_err;
22353 END IF;
22354
22355 --Deletion is not allowed on this table.
22356
22357 v_sql_stmt := 07;
22358 lv_sql_stmt :=
22359 ' UPDATE msc_st_system_items '
22360 ||' SET process_flag = '||G_ERROR_FLG||','
22361 ||' error_text = '||''''||lv_message_text||''''
22362 ||' WHERE deleted_flag = '||SYS_YES
22363 ||' AND process_flag = '||G_IN_PROCESS
22364 ||' AND batch_id = :lv_batch_id'
22365 ||' AND sr_instance_code = :v_instance_code';
22366
22367
22368 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
22369
22370 EXECUTE IMMEDIATE lv_sql_stmt
22371 USING lv_batch_id,
22372 v_instance_code;
22373
22374 -- Set the error message , PIP FIX
22375
22376 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
22377 (p_app_short_name => 'MSC',
22378 p_error_code => 'MSC_PP_INVALID_VALUE',
22379 p_message_text => lv_message_text,
22380 p_error_text => lv_error_text,
22381 p_token1 => 'COLUMN_NAME',
22382 p_token_value1 => 'PIP_FLAG');
22383
22384 IF lv_return <> 0 THEN
22385 RAISE ex_logging_err;
22386 END IF;
22387
22388 --Valid values for PIP_flag are 1 and 2.
22389
22390 v_sql_stmt := 07;
22391 lv_sql_stmt :=
22392 ' UPDATE msc_st_system_items '
22393 ||' SET process_flag = '||G_ERROR_FLG||','
22394 ||' error_text = '||''''||lv_message_text||''''
22395 ||' WHERE nvl(pip_flag,1) not in(1,2)'
22396 ||' AND process_flag = '||G_IN_PROCESS
22397 ||' AND batch_id = :lv_batch_id'
22398 ||' AND sr_instance_code = :v_instance_code';
22399
22400
22401 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
22402
22403 EXECUTE IMMEDIATE lv_sql_stmt
22404 USING lv_batch_id,
22405 v_instance_code;
22406
22407 -- create supply flag validation
22408 -- Set the error message
22409
22410 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
22411 (p_app_short_name => 'MSC',
22412 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
22413 p_message_text => lv_message_text,
22414 p_error_text => lv_error_text,
22415 p_token1 => 'COLUMN_NAME',
22416 p_token_value1 => 'CREATE_SUPPLY_FLAG');
22417
22418 IF lv_return <> 0 THEN
22419 RAISE ex_logging_err;
22420 END IF;
22421
22422 -- Valid value for CREATE_SUPPLY_FLAG are (1,2)
22423
22424 v_sql_stmt := 97;
22425 lv_sql_stmt :=
22426 ' UPDATE MSC_ST_SYSTEM_ITEMS '
22427 ||' SET process_flag = '||G_ERROR_FLG||','
22428 ||' error_text = '||''''||lv_message_text||''''
22429 ||' WHERE nvl(CREATE_SUPPLY_FLAG,1) not in(1,2)'
22430 ||' AND process_flag = '||G_IN_PROCESS
22431 ||' AND batch_id = :lv_batch_id'
22432 ||' AND sr_instance_code = :v_instance_code';
22433
22434
22435 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
22436
22437 EXECUTE IMMEDIATE lv_sql_stmt
22438 USING lv_batch_id,
22439 v_instance_code;
22440
22441 -- Set the message
22442
22443 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
22444 (p_app_short_name => 'MSC',
22445 p_error_code => 'MSC_PP_INVALID_VALUE',
22446 p_message_text => lv_message_text,
22447 p_error_text => lv_error_text,
22448 p_token1 => 'COLUMN_NAME',
22449 p_token_value1 => 'ORGANIZATION_CODE');
22450
22451 IF lv_return <> 0 THEN
22452 RAISE ex_logging_err;
22453 END IF;
22454
22455
22456 -- Derive organization id
22457 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
22458 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
22459 p_org_partner_name => 'ORGANIZATION_CODE',
22460 p_org_partner_id => 'ORGANIZATION_ID',
22461 p_instance_code => v_instance_code,
22462 p_partner_type => G_ORGANIZATION,
22463 p_severity => G_SEV_ERROR,
22464 p_error_text => lv_error_text,
22465 p_batch_id => lv_batch_id,
22466 p_debug => v_debug,
22467 p_message_text => lv_message_text);
22468
22469 IF lv_return <> 0 THEN
22470 RAISE ex_logging_err;
22471 END IF;
22472
22473 --Update sr_inventory_item_id if already exists
22474 v_sql_stmt := 08;
22475 lv_sql_stmt :=
22476 'UPDATE msc_st_system_items msi'
22477 ||' SET sr_inventory_item_id = (SELECT local_id'
22478 ||' FROM msc_local_id_item mli'
22479 ||' WHERE mli.char1 = msi.sr_instance_code '
22480 ||' AND NVL(mli.char2, '||''''||NULL_CHAR||''''||')='
22481 ||' NVL(msi.company_name,'||''''||NULL_CHAR||''''||')'
22482 ||' AND mli.char4 = msi.item_name'
22483 ||' AND mli.entity_name = ''SR_INVENTORY_ITEM_ID'' '
22484 ||' AND mli.instance_id = :v_instance_id'
22485 ||' AND rownum < 2)'
22486 ||' WHERE sr_instance_code = :v_instance_code'
22487 ||' AND batch_id = :lv_batch_id'
22488 ||' AND process_flag = '||G_IN_PROCESS;
22489
22490
22491 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
22492
22493 EXECUTE IMMEDIATE lv_sql_stmt
22494 USING v_instance_id,
22495 v_instance_code,
22496 lv_batch_id;
22497
22498 ---- Changes for SRP legacy collections -----
22499
22500 -- Set the error message
22501 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
22502 (p_app_short_name => 'MSC',
22503 p_error_code => 'MSC_PP_INVALID_VALUE',
22504 p_message_text => lv_message_text,
22505 p_error_text => lv_error_text,
22506 p_token1 => 'COLUMN_NAME',
22507 p_token_value1 => 'PREPOSITION_POINT');
22508
22509
22510 IF lv_return <> 0 THEN
22511 RAISE ex_logging_err;
22512 END IF;
22513
22514 --Valid values for Preposition_point are Y and N
22515
22516 v_sql_stmt := 101;
22517 lv_sql_stmt :=
22518 ' UPDATE msc_st_system_items '
22519 ||' SET process_flag = '||G_ERROR_FLG||','
22520 ||' error_text = '||''''||lv_message_text||''''
22521 ||' WHERE preposition_point not in(''Y'',''N'')'
22522 ||' AND process_flag = '||G_IN_PROCESS
22523 ||' AND batch_id = :lv_batch_id'
22524 ||' AND sr_instance_code = :v_instance_code';
22525
22526
22527 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
22528
22529
22530 EXECUTE IMMEDIATE lv_sql_stmt
22531 USING lv_batch_id,
22532 v_instance_code;
22533
22534 -- Set the error message
22535 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
22536 (p_app_short_name => 'MSC',
22537 p_error_code => 'MSC_PP_INVALID_VALUE',
22538 p_message_text => lv_message_text,
22539 p_error_text => lv_error_text,
22540 p_token1 => 'COLUMN_NAME',
22541 p_token_value1 => 'REPAIR_PROGRAM');
22542
22543
22544
22545 IF lv_return <> 0 THEN
22546 RAISE ex_logging_err;
22547 END IF;
22548
22549 --Valid values for repair_program are (1,2,3))
22550
22551 v_sql_stmt := 102;
22552 lv_sql_stmt :=
22553 ' UPDATE MSC_ST_SYSTEM_ITEMS '
22554 ||' SET process_flag = '||G_ERROR_FLG||','
22555 ||' error_text = '||''''||lv_message_text||''''
22556 ||' WHERE REPAIR_PROGRAM not in(1,2,3)'
22557 ||' AND process_flag = '||G_IN_PROCESS
22558 ||' AND batch_id = :lv_batch_id'
22559 ||' AND sr_instance_code = :v_instance_code';
22560
22561
22562
22563 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
22564
22565 EXECUTE IMMEDIATE lv_sql_stmt
22566 USING lv_batch_id,
22567 v_instance_code;
22568
22569
22570 IF (v_install_msc) THEN
22571
22572 -- Now check for UOM code if it is Invalid error out
22573 -- Set the error message
22574
22575 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
22576 (p_app_short_name => 'MSC',
22577 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
22578 p_message_text => lv_message_text,
22579 p_error_text => lv_error_text,
22580 p_token1 => 'COLUMN_NAMES',
22581 p_token_value1 => 'SR_INSTANCE_CODE ,UOM_CODE',
22582 p_token2 => 'MASTER_TABLE',
22583 p_token_value2 => 'MSC_ST_UNITS_OF_MEASURE',
22584 p_token3 => 'CHILD_TABLE',
22585 p_token_value3 => 'MSC_ST_SYSTEM_ITEMS');
22586 IF lv_return <> 0 THEN
22587 RAISE ex_logging_err;
22588 END IF;
22589
22590 v_sql_stmt := 09;
22591
22592 lv_sql_stmt :=
22593 ' UPDATE msc_st_system_items mssi'
22594 ||' SET process_flag = '||G_ERROR_FLG||','
22595 ||' error_text = '||''''||lv_message_text||''''
22596 ||' WHERE NOT EXISTS (SELECT 1 '
22597 ||' FROM msc_units_of_measure muom'
22598 ||' WHERE muom.uom_code = mssi.uom_code'
22599 ||' UNION'
22600 ||' SELECT 1 FROM msc_st_units_of_measure msuom'
22601 ||' WHERE msuom.uom_code = mssi.uom_code'
22602 ||' AND msuom.sr_instance_id = :v_instance_id'
22603 ||' AND msuom.process_flag = '||G_VALID||')'
22604 ||' AND mssi.sr_instance_code = :v_instance_code'
22605 ||' AND mssi.batch_id = :lv_batch_id'
22606 ||' AND mssi.process_flag = '||G_IN_PROCESS ;
22607
22608
22609 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
22610
22611 EXECUTE IMMEDIATE lv_sql_stmt
22612 USING v_instance_id,
22613 v_instance_code,
22614 lv_batch_id;
22615
22616 -- Set the message
22617
22618 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
22619 (p_app_short_name => 'MSC',
22620 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
22621 p_message_text => lv_message_text,
22622 p_error_text => lv_error_text,
22623 p_token1 => 'COLUMN_NAMES',
22624 p_token_value1 => 'SR_INSTANCE_CODE OR VOLUME_UOM',
22625 p_token2 => 'MASTER_TABLE',
22626 p_token_value2 => 'MSC_ST_UNITS_OF_MEASURE',
22627 p_token3 => 'CHILD_TABLE',
22628 p_token_value3 => 'MSC_ST_SYSTEM_ITEMS');
22629 IF lv_return <> 0 THEN
22630 RAISE ex_logging_err;
22631 END IF;
22632
22633 -- Validate volume uom if provided
22634 v_sql_stmt := 10;
22635
22636 lv_sql_stmt :=
22637 ' UPDATE msc_st_system_items mssi'
22638 ||' SET process_flag = '||G_ERROR_FLG||','
22639 ||' error_text = '||''''||lv_message_text||''''
22640 ||' WHERE NOT EXISTS( SELECT 1 '
22641 ||' FROM msc_units_of_measure muom'
22642 ||' WHERE muom.uom_code = mssi.volume_uom'
22643 ||' UNION'
22644 ||' SELECT 1 '
22645 ||' FROM msc_st_units_of_measure msuom'
22646 ||' WHERE msuom.uom_code = mssi.volume_uom'
22647 ||' AND msuom.sr_instance_id = :v_instance_id'
22648 ||' AND msuom.process_flag = '||G_VALID||')'
22649 ||' AND NVL(mssi.volume_uom,'||''''||NULL_CHAR||''''||') '
22650 ||' <> '||''''||NULL_CHAR||''''
22651 ||' AND mssi.sr_instance_code = :v_instance_code'
22652 ||' AND mssi.batch_id = :lv_batch_id'
22653 ||' AND mssi.process_flag = '||G_IN_PROCESS ;
22654
22655
22656 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
22657
22658
22659 EXECUTE IMMEDIATE lv_sql_stmt
22660 USING v_instance_id,
22661 v_instance_code,
22662 lv_batch_id;
22663
22664 -- Set the message
22665
22666 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
22667 (p_app_short_name => 'MSC',
22668 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
22669 p_message_text => lv_message_text,
22670 p_error_text => lv_error_text,
22671 p_token1 => 'COLUMN_NAMES',
22672 p_token_value1 => 'SR_INSTANCE_CODE OR WEIGHT_UOM',
22673 p_token2 => 'MASTER_TABLE',
22674 p_token_value2 => 'MSC_ST_UNITS_OF_MEASURE',
22675 p_token3 => 'CHILD_TABLE',
22676 p_token_value3 => 'MSC_ST_SYSTEM_ITEMS');
22677 IF lv_return <> 0 THEN
22678 RAISE ex_logging_err;
22679 END IF;
22680
22681 -- Validate weight uom if provided
22682
22683 v_sql_stmt := 12;
22684
22685 lv_sql_stmt :=
22686 ' UPDATE msc_st_system_items mssi'
22687 ||' SET process_flag = '||G_ERROR_FLG||','
22688 ||' error_text = '||''''||lv_message_text||''''
22689 ||' WHERE NOT EXISTS( SELECT 1 '
22690 ||' FROM msc_units_of_measure muom'
22691 ||' WHERE muom.uom_code = mssi.weight_uom'
22692 ||' UNION'
22693 ||' SELECT 1 FROM msc_st_units_of_measure msuom'
22694 ||' WHERE msuom.uom_code = mssi.weight_uom'
22695 ||' AND msuom.sr_instance_id = :v_instance_id'
22696 ||' AND msuom.process_flag = '||G_VALID||')'
22697 ||' AND NVL(mssi.weight_uom,'||''''||NULL_CHAR||''''||') '
22698 ||' <> '||''''||NULL_CHAR||''''
22699 ||' AND mssi.sr_instance_code = :v_instance_code'
22700 ||' AND mssi.batch_id = :lv_batch_id'
22701 ||' AND mssi.process_flag = '||G_IN_PROCESS ;
22702
22703
22704 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
22705
22706 EXECUTE IMMEDIATE lv_sql_stmt
22707 USING v_instance_id,
22708 v_instance_code,
22709 lv_batch_id;
22710
22711 -- Set the error message
22712 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
22713 (p_app_short_name => 'MSC',
22714 p_error_code => 'MSC_PP_INVALID_VALUE',
22715 p_message_text => lv_message_text,
22716 p_error_text => lv_error_text,
22717 p_token1 => 'COLUMN_NAME',
22718 p_token_value1 => 'SOURCE_ORG_CODE');
22719
22720
22721 IF lv_return <> 0 THEN
22722 RAISE ex_logging_err;
22723 END IF;
22724
22725 -- Update Source org id
22726
22727 lv_return :=
22728 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name => 'MSC_ST_SYSTEM_ITEMS',
22729 p_org_partner_name =>'SOURCE_ORG_CODE',
22730 p_org_partner_id =>'SOURCE_ORG_ID',
22731 p_instance_code => v_instance_code,
22732 p_partner_type => G_ORGANIZATION,
22733 p_severity => G_SEV3_ERROR,
22734 p_message_text => lv_message_text,
22735 p_batch_id =>lv_batch_id,
22736 p_debug => v_debug,
22737 p_error_text =>lv_error_text);
22738 IF lv_return <> 0 THEN
22739 RAISE ex_logging_err;
22740 END IF;
22741
22742
22743 -- Set the error message
22744 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
22745 (p_app_short_name => 'MSC',
22746 p_error_code => 'MSC_PP_INVALID_VALUE',
22747 p_message_text => lv_message_text,
22748 p_error_text => lv_error_text,
22749 p_token1 => 'COLUMN_NAME',
22750 p_token_value1 => 'PRIMARY_SUPPLIER_NAME');
22751
22752
22753 IF lv_return <> 0 THEN
22754 RAISE ex_logging_err;
22755 END IF;
22756
22757 -- Update primary_supplier_name
22758
22759 lv_return :=
22760 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name => 'MSC_ST_SYSTEM_ITEMS',
22761 p_org_partner_name =>'PRIMARY_SUPPLIER_NAME',
22762 p_org_partner_id =>'PRIMARY_SUPPLIER_ID',
22763 p_instance_code => v_instance_code,
22764 p_partner_type => G_VENDOR,
22765 p_severity => G_SEV3_ERROR,
22766 p_message_text => lv_message_text,
22767 p_batch_id =>lv_batch_id,
22768 p_debug => v_debug,
22769 p_error_text =>lv_error_text);
22770 IF lv_return <> 0 THEN
22771 RAISE ex_logging_err;
22772 END IF;
22773
22774 -- Set the message
22775
22776 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
22777 (p_app_short_name => 'MSC',
22778 p_error_code => 'MSC_PP_INVALID_VALUE',
22779 p_message_text => lv_message_text,
22780 p_error_text => lv_error_text,
22781 p_token1 => 'COLUMN_NAME',
22782 p_token_value1 => 'ATP_FLAG and MRP_PLANNING_CODE'
22783 ||' and ATP_COMPONENTS_FLAG');
22784
22785 IF lv_return <> 0 THEN
22786 RAISE ex_logging_err;
22787 END IF;
22788
22789 -- ERP collection does not handle
22790 -- Error out the record where atp_flag or atp_components_flag is N and
22791 -- MRP_PLANNING_CODE is 6 (not planned)
22792
22793 v_sql_stmt := 13;
22794
22795 lv_sql_stmt :=
22796 ' UPDATE msc_st_system_items '
22797 ||' SET process_flag = '||G_ERROR_FLG||','
22798 ||' error_text = '||''''||lv_message_text||''''
22799 ||' WHERE mrp_planning_code = 6 '
22800 ||' AND atp_flag = ''N'' '
22801 ||' AND atp_components_flag = ''N'' '
22802 ||' AND pick_components_flag <> ''Y'' '
22803 ||' AND bom_item_type <> 3 '
22804 ||' AND batch_id = :lv_batch_id'
22805 ||' AND process_flag = '||G_IN_PROCESS
22806 ||' AND sr_instance_code = :v_instance_code';
22807
22808
22809 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
22810
22811 EXECUTE IMMEDIATE lv_sql_stmt
22812 USING lv_batch_id,
22813 v_instance_code;
22814
22815
22816 END IF ; --v_install_msc
22817
22818 --Call to customised validation.
22819
22820 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
22821 (ERRBUF => lv_error_text,
22822 RETCODE => lv_return,
22823 pBatchID => lv_batch_id,
22824 pInstanceCode => v_instance_code,
22825 pEntityName => 'MSC_ST_SYSTEM_ITEMS',
22826 pInstanceID => v_instance_id);
22827
22828 IF NVL(lv_return,0) <> 0 THEN
22829 RAISE ex_logging_err;
22830 END IF;
22831 /**** Transfering this piece of code to the Monitor -- bug fix 2191021
22832 IF(v_install_msc) THEN
22833 -- update ABC_CLASS_ID where it exists in the planning system
22834 v_sql_stmt := 14;
22835 lv_sql_stmt :=
22836 ' UPDATE msc_st_system_items msi'
22837 ||' SET abc_class_id = (SELECT local_id from MSC_LOCAL_ID_MISC mac '
22838 ||' WHERE mac.char1 = msi.sr_instance_code'
22839 ||' AND mac.char3 = msi.organization_code '
22840 ||' AND mac.char4 = msi.abc_class_name '
22841 ||' AND mac.ENTITY_NAME = ''ABC_CLASS_ID'''
22842 ||' AND NVL(mac.char2,'||''''||NULL_CHAR||''''||') '
22843 ||' = NVL(msi.company_name,'||''''||NULL_CHAR||''''||')) '
22844 ||' WHERE batch_id = :lv_batch_id'
22845 ||' AND process_flag = '||G_IN_PROCESS
22846 ||' AND sr_instance_code = :v_instance_code'
22847 ||' AND abc_class_name is not null ';
22848
22849
22850 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
22851
22852 EXECUTE IMMEDIATE lv_sql_stmt
22853 USING lv_batch_id,
22854 v_instance_code;
22855
22856 OPEN c3(lv_batch_id);
22857 FETCH c3 BULK COLLECT INTO lb_rowid_abc ;
22858
22859 IF c3%ROWCOUNT > 0 THEN
22860
22861 FORALL j IN lb_rowid_abc.FIRST..lb_rowid_abc.LAST
22862 UPDATE msc_st_system_items msi
22863 SET abc_class_id = MSC_ST_ABC_CLASS_ID_S.nextval
22864 WHERE rowid = lb_rowid_abc(j);
22865
22866
22867 FORALL j IN lb_rowid_abc.FIRST..lb_rowid_abc.LAST
22868 INSERT INTO msc_local_id_misc
22869 (local_id,
22870 st_transaction_id,
22871 instance_id,
22872 entity_name,
22873 data_source_type,
22874 char1,
22875 char2,
22876 char3,
22877 char4,
22878 last_update_date,
22879 last_updated_by,
22880 creation_date,
22881 created_by )
22882 SELECT
22883 abc_class_id,
22884 st_transaction_id,
22885 v_instance_id,
22886 'ABC_CLASS_ID',
22887 data_source_type,
22888 sr_instance_code,
22889 company_name,
22890 organization_code,
22891 ABC_CLASS_NAME,
22892 v_current_date,
22893 v_current_user,
22894 v_current_date,
22895 v_current_user
22896 FROM msc_st_system_items
22897 WHERE rowid = lb_rowid_abc(j);
22898
22899 END IF;
22900 CLOSE c3;
22901
22902 -- update ABC_CLASS_ID for ABC_CLASS_NAME for which we have just populated the local id
22903 v_sql_stmt := 15;
22904 lv_sql_stmt :=
22905 ' UPDATE msc_st_system_items msi'
22906 ||' SET abc_class_id = (SELECT local_id from MSC_LOCAL_ID_MISC mac '
22907 ||' WHERE mac.char1 = msi.sr_instance_code'
22908 ||' AND mac.char3 = msi.organization_code '
22909 ||' AND mac.char4 = msi.abc_class_name '
22910 ||' AND mac.ENTITY_NAME = ''ABC_CLASS_ID'''
22911 ||' AND NVL(mac.char2,'||''''||NULL_CHAR||''''||') '
22912 ||' = NVL(msi.company_name,'||''''||NULL_CHAR||''''||')) '
22913 ||' WHERE batch_id = :lv_batch_id'
22914 ||' AND process_flag = '||G_IN_PROCESS
22915 ||' AND sr_instance_code = :v_instance_code'
22916 ||' AND abc_class_id IS NULL'
22917 ||' AND abc_class_name is not null ';
22918
22919
22920 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
22921
22922 EXECUTE IMMEDIATE lv_sql_stmt
22923 USING lv_batch_id,
22924 v_instance_code;
22925
22926 v_sql_stmt := 16;
22927 lv_sql_stmt :=
22928 ' INSERT INTO MSC_ABC_CLASSES '
22929 ||' ( ABC_CLASS_ID, '
22930 ||' ABC_CLASS_NAME, '
22931 ||' ORGANIZATION_ID, '
22932 ||' SR_INSTANCE_ID, '
22933 ||' LAST_UPDATE_DATE, '
22934 ||' LAST_UPDATED_BY, '
22935 ||' CREATION_DATE, '
22936 ||' CREATED_BY) '
22937 ||' SELECT distinct '
22938 ||' msi.abc_class_id,'
22939 ||' msi.abc_class_name,'
22940 ||' msi.organization_id,'
22941 || v_instance_id ||','
22942 ||' last_update_date,'
22943 ||' last_updated_by,'
22944 ||' creation_date,'
22945 ||' created_by '
22946 ||' FROM MSC_ST_SYSTEM_ITEMS msi'
22947 ||' WHERE batch_id = :lv_batch_id'
22948 ||' AND sr_instance_code = :v_instance_code'
22949 ||' AND process_flag = '||G_IN_PROCESS
22950 ||' AND msi.abc_class_id is not null'
22951 ||' AND msi.abc_class_name is not null'
22952 ||' AND NOT EXISTS'
22953 ||' ( SELECT 1 FROM MSC_ABC_CLASSES abc'
22954 ||' WHERE abc.abc_class_id = msi.abc_class_id'
22955 ||' AND abc.abc_class_name = msi.abc_class_name'
22956 ||' AND abc.organization_id = msi.organization_id'
22957 ||' AND abc.sr_instance_id = ' ||v_instance_id ||')';
22958
22959 IF V_DEBUG THEN
22960 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
22961 END IF;
22962
22963 EXECUTE IMMEDIATE lv_sql_stmt
22964 USING lv_batch_id,
22965 v_instance_code;
22966 END IF; --v_install_msc
22967
22968 *******************/
22969 OPEN c2(lv_batch_id);
22970 FETCH c2 BULK COLLECT INTO lb_rowid ;
22971
22972 IF c2%ROWCOUNT > 0 THEN
22973
22974 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
22975
22976 UPDATE msc_st_system_items
22977 SET sr_inventory_item_id = msc_st_sr_inventory_item_id_s.NEXTVAL
22978 WHERE rowid = lb_rowid(j);
22979
22980 v_sql_stmt := 10;
22981
22982 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
22983 INSERT INTO msc_local_id_item
22984 (local_id,
22985 st_transaction_id,
22986 instance_id,
22987 entity_name,
22988 data_source_type,
22989 char1,
22990 char2,
22991 char3,
22992 char4,
22993 SOURCE_SR_INVENTORY_ITEM_ID,
22994 SOURCE_SOURCE_ORG_ID,
22995 SOURCE_PRIMARY_SUPPLIER_ID,
22996 SOURCE_BASE_ITEM_ID,
22997 last_update_date,
22998 last_updated_by,
22999 creation_date,
23000 created_by )
23001 SELECT
23002 sr_inventory_item_id,
23003 st_transaction_id,
23004 v_instance_id,
23005 'SR_INVENTORY_ITEM_ID',
23006 data_source_type,
23007 sr_instance_code,
23008 company_name,
23009 organization_code,
23010 item_name,
23011 SOURCE_SR_INVENTORY_ITEM_ID,
23012 SOURCE_SOURCE_ORG_ID,
23013 SOURCE_PRIMARY_SUPPLIER_ID,
23014 SOURCE_BASE_ITEM_ID,
23015 v_current_date,
23016 v_current_user,
23017 v_current_date,
23018 v_current_user
23019 FROM msc_st_system_items
23020 WHERE rowid = lb_rowid(j);
23021
23022 END IF;
23023 CLOSE c2;
23024
23025 v_sql_stmt := 17;
23026 lv_sql_stmt :=
23027 'UPDATE msc_st_system_items msi'
23028 ||' SET sr_inventory_item_id = (SELECT local_id'
23029 ||' FROM msc_local_id_item mli'
23030 ||' WHERE mli.char1 = msi.sr_instance_code '
23031 ||' AND NVL(mli.char2, '||''''||NULL_CHAR||''''||')='
23032 ||' NVL(msi.company_name,'||''''||NULL_CHAR||''''||')'
23033 ||' AND mli.char4 = msi.item_name'
23034 ||' AND mli.entity_name = ''SR_INVENTORY_ITEM_ID'' '
23035 ||' AND mli.instance_id = :v_instance_id'
23036 ||' AND rownum < 2 )'
23037 ||' WHERE sr_inventory_item_id IS NULL'
23038 ||' AND sr_instance_code = :v_instance_code'
23039 ||' AND batch_id = :lv_batch_id'
23040 ||' AND process_flag = '||G_IN_PROCESS;
23041
23042
23043 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
23044
23045 EXECUTE IMMEDIATE lv_sql_stmt
23046 USING v_instance_id,
23047 v_instance_code,
23048 lv_batch_id;
23049
23050 v_sql_stmt := 18;
23051 lv_sql_stmt :=
23052 'INSERT INTO msc_local_id_item '
23053 ||' (local_id,'
23054 ||' st_transaction_id,'
23055 ||' instance_id,'
23056 ||' entity_name,'
23057 ||' data_source_type,'
23058 ||' char1,'
23059 ||' char2,'
23060 ||' char3,'
23061 ||' char4,'
23062 ||' SOURCE_SR_INVENTORY_ITEM_ID,'
23063 ||' SOURCE_SOURCE_ORG_ID,'
23064 ||' SOURCE_PRIMARY_SUPPLIER_ID,'
23065 ||' SOURCE_BASE_ITEM_ID,'
23066 ||' last_update_date,'
23067 ||' last_updated_by,'
23068 ||' creation_date,'
23069 ||' created_by )'
23070 ||' SELECT '
23071 ||' sr_inventory_item_id,'
23072 ||' st_transaction_id,'
23073 || v_instance_id||','
23074 ||' ''SR_INVENTORY_ITEM_ID'','
23075 ||' data_source_type,'
23076 ||' sr_instance_code,'
23077 ||' company_name,'
23078 ||' organization_code,'
23079 ||' item_name,'
23080 ||' SOURCE_SR_INVENTORY_ITEM_ID,'
23081 ||' SOURCE_SOURCE_ORG_ID,'
23082 ||' SOURCE_PRIMARY_SUPPLIER_ID,'
23083 ||' SOURCE_BASE_ITEM_ID,'
23084 ||' last_update_date,'
23085 ||' last_updated_by,'
23086 ||' creation_date,'
23087 ||' created_by '
23088 ||' FROM msc_st_system_items'
23089 ||' WHERE NOT EXISTS( SELECT 1'
23090 ||' FROM msc_local_id_item'
23091 ||' WHERE char1 = sr_instance_code '
23092 ||' AND NVL(char2, '||''''||NULL_CHAR||''''||')='
23093 ||' NVL(company_name,'||''''||NULL_CHAR||''''||')'
23094 ||' AND char3 = organization_code'
23095 ||' AND char4 = item_name'
23096 ||' AND entity_name = ''SR_INVENTORY_ITEM_ID'' )'
23097 ||' AND sr_instance_code = :v_instance_code'
23098 ||' AND batch_id = :lv_batch_id'
23099 ||' AND process_flag = '||G_IN_PROCESS;
23100
23101
23102 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
23103
23104 EXECUTE IMMEDIATE lv_sql_stmt
23105 USING v_instance_code,
23106 lv_batch_id;
23107
23108 IF(v_install_msc) THEN
23109 -- Set the message
23110
23111 /* lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23112 (p_app_short_name => 'MSC',
23113 p_error_code => 'MSC_PP_INVALID_VALUE',
23114 p_message_text => lv_message_text,
23115 p_error_text => lv_error_text,
23116 p_token1 => 'COLUMN_NAME',
23117 p_token_value1 => 'BASE_ITEM_NAME');
23118
23119 IF lv_return <> 0 THEN
23120 RAISE ex_logging_err;
23121 END IF;
23122
23123 -- Poplulate base item id
23124 lv_return :=
23125 MSC_ST_UTIL.DERIVE_ITEM_ID(p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23126 p_item_col_name => 'BASE_ITEM_NAME',
23127 p_item_col_id =>'BASE_ITEM_ID',
23128 p_instance_code => v_instance_code,
23129 p_instance_id => v_instance_id,
23130 p_severity => G_SEV3_ERROR,
23131 p_message_text => lv_message_text,
23132 p_batch_id =>lv_batch_id,
23133 p_debug => v_debug,
23134 p_error_text =>lv_error_text);
23135
23136
23137 if(lv_return <> 0) then
23138 RAISE ex_logging_err;
23139 end if; */
23140
23141 COMMIT;
23142
23143 -- Set the message
23144
23145 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23146 (p_app_short_name => 'MSC',
23147 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23148 p_message_text => lv_message_text,
23149 p_error_text => lv_error_text,
23150 p_token1 => 'COLUMN_NAME',
23151 p_token_value1 => 'DELETED_FLAG',
23152 p_token2 => 'DEFAULT_VALUE',
23153 p_token_value2 => SYS_NO);
23154
23155 IF lv_return <> 0 THEN
23156 RAISE ex_logging_err;
23157 END IF;
23158
23159 -- Check DELETE_FLAG column has valid value or not and
23160 -- if not set it to SYS_NO
23161
23162 lv_where_str :=
23163 ' AND NVL(deleted_flag,'||NULL_VALUE||') <>'||SYS_NO;
23164
23165 lv_return := MSC_ST_UTIL.LOG_ERROR
23166 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23167 p_instance_code => v_instance_code,
23168 p_row => lv_column_names,
23169 p_severity => G_SEV_WARNING,
23170 p_message_text => lv_message_text,
23171 p_error_text => lv_error_text,
23172 p_batch_id => lv_batch_id,
23173 p_where_str => lv_where_str,
23174 p_col_name => 'DELETED_FLAG',
23175 p_debug => v_debug,
23176 p_default_value => SYS_NO);
23177
23178 IF lv_return <> 0 THEN
23179 RAISE ex_logging_err;
23180 END IF;
23181
23182
23183
23184 -- Set the error message
23185 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23186 (p_app_short_name => 'MSC',
23187 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23188 p_message_text => lv_message_text,
23189 p_error_text => lv_error_text,
23190 p_token1 => 'COLUMN_NAME',
23191 p_token_value1 => 'LOT_CONTROL_CODE',
23192 p_token2 => 'DEFAULT_VALUE',
23193 p_token_value2 => G_LOT_CONTROL_CODE );
23194
23195 IF lv_return <> 0 THEN
23196 RAISE ex_logging_err;
23197 END IF;
23198
23199 -- Valid value for Lot control code is 1,2 default it to 2
23200
23201 lv_where_str :=
23202 ' AND NVL(lot_control_code,'||NULL_VALUE||')'
23203 ||' NOT IN (1,2)';
23204
23205 lv_return := MSC_ST_UTIL.LOG_ERROR
23206 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23207 p_instance_code => v_instance_code,
23208 p_row => lv_column_names,
23209 p_severity => G_SEV_WARNING,
23210 p_message_text => lv_message_text,
23211 p_error_text => lv_error_text,
23212 p_batch_id => lv_batch_id,
23213 p_where_str => lv_where_str,
23214 p_col_name => 'LOT_CONTROL_CODE',
23215 p_debug => v_debug,
23216 p_default_value => G_LOT_CONTROL_CODE);
23217
23218 IF lv_return <> 0 THEN
23219 RAISE ex_logging_err;
23220 END IF;
23221
23222 -- Set the error message
23223 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23224 (p_app_short_name => 'MSC',
23225 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23226 p_message_text => lv_message_text,
23227 p_error_text => lv_error_text,
23228 p_token1 => 'COLUMN_NAME',
23229 p_token_value1 => 'ROUNDING_CONTROL_TYPE',
23230 p_token2 => 'DEFAULT_VALUE',
23231 p_token_value2 => G_ROUNDING_CONTROL_TYPE );
23232
23233 IF lv_return <> 0 THEN
23234 RAISE ex_logging_err;
23235 END IF;
23236
23237 -- Valid value for rounding_control_type is 1,2 default it to 2
23238
23239 lv_where_str :=
23240 ' AND NVL(rounding_control_type,'||NULL_VALUE||')'
23241 ||' NOT IN (1,2)';
23242
23243 lv_return := MSC_ST_UTIL.LOG_ERROR
23244 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23245 p_instance_code => v_instance_code,
23246 p_row => lv_column_names,
23247 p_severity => G_SEV_WARNING,
23248 p_message_text => lv_message_text,
23249 p_error_text => lv_error_text,
23250 p_batch_id => lv_batch_id,
23251 p_where_str => lv_where_str,
23252 p_col_name => 'ROUNDING_CONTROL_TYPE',
23253 p_debug => v_debug,
23254 p_default_value => G_ROUNDING_CONTROL_TYPE);
23255
23256 IF lv_return <> 0 THEN
23257 RAISE ex_logging_err;
23258 END IF;
23259
23260 -- Set the error message
23261 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23262 (p_app_short_name => 'MSC',
23263 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23264 p_message_text => lv_message_text,
23265 p_error_text => lv_error_text,
23266 p_token1 => 'COLUMN_NAME',
23267 p_token_value1 => 'IN_SOURCE_PLAN',
23268 p_token2 => 'DEFAULT_VALUE',
23269 p_token_value2 => G_IN_SOURCE_PLAN );
23270
23271 IF lv_return <> 0 THEN
23272 RAISE ex_logging_err;
23273 END IF;
23274
23275 -- Valid value for in_source_plan is 1,2 default it to 2
23276
23277 lv_where_str :=
23278 ' AND NVL(in_source_plan,'||NULL_VALUE||')'
23279 ||' NOT IN (1,2)';
23280
23281 lv_return := MSC_ST_UTIL.LOG_ERROR
23282 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23283 p_instance_code => v_instance_code,
23284 p_row => lv_column_names,
23285 p_severity => G_SEV_WARNING,
23286 p_message_text => lv_message_text,
23287 p_error_text => lv_error_text,
23288 p_batch_id => lv_batch_id,
23289 p_where_str => lv_where_str,
23290 p_col_name => 'IN_SOURCE_PLAN',
23291 p_debug => v_debug,
23292 p_default_value => G_IN_SOURCE_PLAN);
23293
23294 IF lv_return <> 0 THEN
23295 RAISE ex_logging_err;
23296 END IF;
23297
23298 -- Set the error message
23299 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23300 (p_app_short_name => 'MSC',
23301 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23302 p_message_text => lv_message_text,
23303 p_error_text => lv_error_text,
23304 p_token1 => 'COLUMN_NAME',
23305 p_token_value1 => 'MRP_PLANNING_CODE',
23306 p_token2 => 'DEFAULT_VALUE',
23307 p_token_value2 => G_MRP_PLANNING_CODE );
23308
23309 IF lv_return <> 0 THEN
23310 RAISE ex_logging_err;
23311 END IF;
23312
23313 -- Valid value for mrp_planning_code are (3,4,6,7,8,9),default it to 7
23314
23315 lv_where_str :=
23316 ' AND NVL(mrp_planning_code,'||NULL_VALUE||')'
23317 ||' NOT IN (3,4,6,7,8,9)';
23318
23319
23320 lv_return := MSC_ST_UTIL.LOG_ERROR
23321 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23322 p_instance_code => v_instance_code,
23323 p_row => lv_column_names,
23324 p_severity => G_SEV_WARNING,
23325 p_message_text => lv_message_text,
23326 p_error_text => lv_error_text,
23327 p_batch_id => lv_batch_id,
23328 p_where_str => lv_where_str,
23329 p_col_name => 'mrp_planning_code',
23330 p_debug => v_debug,
23331 p_default_value => G_MRP_PLANNING_CODE);
23332
23333 IF lv_return <> 0 THEN
23334 RAISE ex_logging_err;
23335 END IF;
23336
23337 -- Set the error message
23338 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23339 (p_app_short_name => 'MSC',
23340 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23341 p_message_text => lv_message_text,
23342 p_error_text => lv_error_text,
23343 p_token1 => 'COLUMN_NAME',
23344 p_token_value1 => 'MRP_CALCULATE_ATP_FLAG',
23345 p_token2 => 'DEFAULT_VALUE',
23346 p_token_value2 => G_MRP_CALCULATE_ATP_FLAG );
23347
23348 IF lv_return <> 0 THEN
23349 RAISE ex_logging_err;
23350 END IF;
23351
23352 -- Valid value for mrp_calculate_atp_flag are (1,2),default it to 2
23353
23354 lv_where_str :=
23355 ' AND NVL(mrp_calculate_atp_flag,'||NULL_VALUE||')'
23356 ||' NOT IN (1,2)';
23357
23358 lv_return := MSC_ST_UTIL.LOG_ERROR
23359 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23360 p_instance_code => v_instance_code,
23361 p_row => lv_column_names,
23362 p_severity => G_SEV_WARNING,
23363 p_message_text => lv_message_text,
23364 p_error_text => lv_error_text,
23365 p_batch_id => lv_batch_id,
23366 p_where_str => lv_where_str,
23367 p_col_name => 'MRP_CALCULATE_ATP_FLAG',
23368 p_debug => v_debug,
23369 p_default_value => G_MRP_CALCULATE_ATP_FLAG);
23370
23371 IF lv_return <> 0 THEN
23372 RAISE ex_logging_err;
23373 END IF;
23374
23375 -- Set the error message
23376 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23377 (p_app_short_name => 'MSC',
23378 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23379 p_message_text => lv_message_text,
23380 p_error_text => lv_error_text,
23381 p_token1 => 'COLUMN_NAME',
23382 p_token_value1 => 'ATP_COMPONENTS_FLAG',
23383 p_token2 => 'DEFAULT_VALUE',
23384 p_token_value2 => G_ATP_COMPONENTS_FLAG );
23385
23386 IF lv_return <> 0 THEN
23387 RAISE ex_logging_err;
23388 END IF;
23389
23390 -- Valid value for atp_components_flag are (Y,N),default it to 2
23391
23392 lv_where_str :=
23393 ' AND NVL(atp_components_flag ,'||''''||NULL_CHAR||''''||')'
23394 ||' NOT IN (''Y'', ''N'', ''C'', ''R'')'; -- Added C and R as part of bug 12781762
23395
23396 lv_return := MSC_ST_UTIL.LOG_ERROR
23397 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23398 p_instance_code => v_instance_code,
23399 p_row => lv_column_names,
23400 p_severity => G_SEV_WARNING,
23401 p_message_text => lv_message_text,
23402 p_error_text => lv_error_text,
23403 p_batch_id => lv_batch_id,
23404 p_where_str => lv_where_str,
23405 p_col_name => 'ATP_COMPONENTS_FLAG',
23406 p_debug => v_debug,
23407 p_default_value => '''N''');
23408
23409 IF lv_return <> 0 THEN
23410 RAISE ex_logging_err;
23411 END IF;
23412
23413 -- Set the error message
23414 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23415 (p_app_short_name => 'MSC',
23416 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23417 p_message_text => lv_message_text,
23418 p_error_text => lv_error_text,
23419 p_token1 => 'COLUMN_NAME',
23420 p_token_value1 => 'BUILT_IN_WIP_FLAG',
23421 p_token2 => 'DEFAULT_VALUE',
23422 p_token_value2 => G_BUILT_IN_WIP_FLAG );
23423
23424 IF lv_return <> 0 THEN
23425 RAISE ex_logging_err;
23426 END IF;
23427
23428 -- Valid value for built_in_wip_flag are (1,2),default it to 1
23429
23430 lv_where_str :=
23431 ' AND NVL(built_in_wip_flag ,'||NULL_VALUE||') NOT IN (1,2)';
23432
23433 lv_return := MSC_ST_UTIL.LOG_ERROR
23434 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23435 p_instance_code => v_instance_code,
23436 p_row => lv_column_names,
23437 p_severity => G_SEV_WARNING,
23438 p_message_text => lv_message_text,
23439 p_error_text => lv_error_text,
23440 p_batch_id => lv_batch_id,
23441 p_where_str => lv_where_str,
23442 p_col_name => 'BUILT_IN_WIP_FLAG',
23443 p_debug => v_debug,
23444 p_default_value => G_BUILT_IN_WIP_FLAG);
23445
23446 IF lv_return <> 0 THEN
23447 RAISE ex_logging_err;
23448 END IF;
23449
23450 -- Set the error message
23451 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23452 (p_app_short_name => 'MSC',
23453 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23454 p_message_text => lv_message_text,
23455 p_error_text => lv_error_text,
23456 p_token1 => 'COLUMN_NAME',
23457 p_token_value1 => 'PURCHASING_ENABLED_FLAG',
23458 p_token2 => 'DEFAULT_VALUE',
23459 p_token_value2 => G_PURCHASING_ENABLED_FLAG );
23460
23461 IF lv_return <> 0 THEN
23462 RAISE ex_logging_err;
23463 END IF;
23464
23465 -- Valid value for purchasing_enabled_flag are (1,2),default it to 2
23466
23467 lv_where_str :=
23468 ' AND NVL(purchasing_enabled_flag,'||NULL_VALUE||') NOT IN (1,2) ';
23469
23470 lv_return := MSC_ST_UTIL.LOG_ERROR
23471 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23472 p_instance_code => v_instance_code,
23473 p_row => lv_column_names,
23474 p_severity => G_SEV_WARNING,
23475 p_message_text => lv_message_text,
23476 p_error_text => lv_error_text,
23477 p_batch_id => lv_batch_id,
23478 p_where_str => lv_where_str,
23479 p_col_name => 'PURCHASING_ENABLED_FLAG',
23480 p_debug => v_debug,
23481 p_default_value => G_PURCHASING_ENABLED_FLAG);
23482
23483 IF lv_return <> 0 THEN
23484 RAISE ex_logging_err;
23485 END IF;
23486
23487 -- Set the error message
23488 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23489 (p_app_short_name => 'MSC',
23490 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23491 p_message_text => lv_message_text,
23492 p_error_text => lv_error_text,
23493 p_token1 => 'COLUMN_NAME',
23494 p_token_value1 => 'PLANNING_MAKE_BUY_CODE',
23495 p_token2 => 'DEFAULT_VALUE',
23496 p_token_value2 => G_PLANNING_MAKE_BUY_CODE );
23497
23498 IF lv_return <> 0 THEN
23499 RAISE ex_logging_err;
23500 END IF;
23501
23502
23503 -- Valid value for planning_make_buy_code are (1,2),default it to 2
23504
23505 lv_where_str :=
23506 ' AND NVL(planning_make_buy_code,'||NULL_VALUE||') NOT IN (1,2)';
23507
23508 lv_return := MSC_ST_UTIL.LOG_ERROR
23509 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23510 p_instance_code => v_instance_code,
23511 p_row => lv_column_names,
23512 p_severity => G_SEV_WARNING,
23513 p_message_text => lv_message_text,
23514 p_error_text => lv_error_text,
23515 p_batch_id => lv_batch_id,
23516 p_where_str => lv_where_str,
23517 p_col_name => 'PLANNING_MAKE_BUY_CODE',
23518 p_debug => v_debug,
23519 p_default_value => G_PLANNING_MAKE_BUY_CODE );
23520
23521 IF lv_return <> 0 THEN
23522 RAISE ex_logging_err;
23523 END IF;
23524
23525 -- Set the error message
23526 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23527 (p_app_short_name => 'MSC',
23528 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23529 p_message_text => lv_message_text,
23530 p_error_text => lv_error_text,
23531 p_token1 => 'COLUMN_NAME',
23532 p_token_value1 => 'INVENTORY_PLANNING_CODE',
23533 p_token2 => 'DEFAULT_VALUE',
23534 p_token_value2 => G_INVENTORY_PLANNING_CODE );
23535
23536 IF lv_return <> 0 THEN
23537 RAISE ex_logging_err;
23538 END IF;
23539
23540 -- Valid value for inventory_planning_code are (1,2,6),default it to 6
23541
23542 lv_where_str :=
23543 ' AND NVL(inventory_planning_code,'||NULL_VALUE||') NOT IN (1,2,6)';
23544
23545 lv_return := MSC_ST_UTIL.LOG_ERROR
23546 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23547 p_instance_code => v_instance_code,
23548 p_row => lv_column_names,
23549 p_severity => G_SEV_WARNING,
23550 p_message_text => lv_message_text,
23551 p_error_text => lv_error_text,
23552 p_batch_id => lv_batch_id,
23553 p_where_str => lv_where_str,
23554 p_col_name => 'INVENTORY_PLANNING_CODE',
23555 p_debug => v_debug,
23556 p_default_value => G_INVENTORY_PLANNING_CODE);
23557
23558 IF lv_return <> 0 THEN
23559 RAISE ex_logging_err;
23560 END IF;
23561
23562 -- Set the error message
23563 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23564 (p_app_short_name => 'MSC',
23565 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23566 p_message_text => lv_message_text,
23567 p_error_text => lv_error_text,
23568 p_token1 => 'COLUMN_NAME',
23569 p_token_value1 => 'REPETITIVE_TYPE',
23570 p_token2 => 'DEFAULT_VALUE',
23571 p_token_value2 => G_REPETITIVE_TYPE);
23572
23573 IF lv_return <> 0 THEN
23574 RAISE ex_logging_err;
23575 END IF;
23576
23577 -- Repetiitve type always default to 1
23578
23579 lv_where_str :=
23580 ' AND NVL(repetitive_type,'||NULL_VALUE||') NOT IN (1,2)';
23581
23582 lv_return := MSC_ST_UTIL.LOG_ERROR
23583 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23584 p_instance_code => v_instance_code,
23585 p_row => lv_column_names,
23586 p_severity => G_SEV_WARNING,
23587 p_message_text => lv_message_text,
23588 p_error_text => lv_error_text,
23589 p_batch_id => lv_batch_id,
23590 p_where_str => lv_where_str,
23591 p_col_name => 'repetitive_type',
23592 p_debug => v_debug,
23593 p_default_value => G_REPETITIVE_TYPE);
23594
23595 IF lv_return <> 0 THEN
23596 RAISE ex_logging_err;
23597 END IF;
23598
23599 -- Set the error message
23600 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23601 (p_app_short_name => 'MSC',
23602 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23603 p_message_text => lv_message_text,
23604 p_error_text => lv_error_text,
23605 p_token1 => 'COLUMN_NAME',
23606 p_token_value1 => 'ENGINEERING_ITEM_FLAG',
23607 p_token2 => 'DEFAULT_VALUE',
23608 p_token_value2 => G_ENGINEERING_ITEM_FLAG);
23609
23610 IF lv_return <> 0 THEN
23611 RAISE ex_logging_err;
23612 END IF;
23613
23614 -- Valid value for engineering_item_flag are (1,2),default it to 2
23615 lv_where_str :=
23616 ' AND NVL(engineering_item_flag ,'||NULL_VALUE||') NOT IN (1,2)';
23617
23618 lv_return := MSC_ST_UTIL.LOG_ERROR
23619 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23620 p_instance_code => v_instance_code,
23621 p_row => lv_column_names,
23622 p_severity => G_SEV_WARNING,
23623 p_message_text => lv_message_text,
23624 p_error_text => lv_error_text,
23625 p_batch_id => lv_batch_id,
23626 p_where_str => lv_where_str,
23627 p_col_name => 'ENGINEERING_ITEM_FLAG' ,
23628 p_debug => v_debug,
23629 p_default_value => G_ENGINEERING_ITEM_FLAG);
23630
23631 IF lv_return <> 0 THEN
23632 RAISE ex_logging_err;
23633 END IF;
23634
23635 -- Set the error message
23636 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23637 (p_app_short_name => 'MSC',
23638 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23639 p_message_text => lv_message_text,
23640 p_error_text => lv_error_text,
23641 p_token1 => 'COLUMN_NAME',
23642 p_token_value1 => 'MRP_SAFETY_STOCK_CODE',
23643 p_token2 => 'DEFAULT_VALUE',
23644 p_token_value2 => 1);
23645
23646 IF lv_return <> 0 THEN
23647 RAISE ex_logging_err;
23648 END IF;
23649
23650 -- Valid value for mrp_safety_stock_code are (1,2),default it based on
23651 -- whether mrp_safety_stock_percent is NULL or Not
23652
23653 lv_where_str :=
23654 ' AND NVL(mrp_safety_stock_code,'||NULL_VALUE||') <>'||' 1 AND'
23655 ||' NVL(mrp_safety_stock_percent,'||NULL_VALUE||')='||NULL_VALUE;
23656
23657 lv_return := MSC_ST_UTIL.LOG_ERROR
23658 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23659 p_instance_code => v_instance_code,
23660 p_row => lv_column_names,
23661 p_severity => G_SEV_WARNING,
23662 p_message_text => lv_message_text,
23663 p_error_text => lv_error_text,
23664 p_batch_id => lv_batch_id,
23665 p_where_str => lv_where_str,
23666 p_col_name => 'mrp_safety_stock_code' ,
23667 p_debug => v_debug,
23668 p_default_value => 1);
23669
23670 IF lv_return <> 0 THEN
23671 RAISE ex_logging_err;
23672 END IF;
23673
23674 -- Set the error message
23675 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23676 (p_app_short_name => 'MSC',
23677 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23678 p_message_text => lv_message_text,
23679 p_error_text => lv_error_text,
23680 p_token1 => 'COLUMN_NAME',
23681 p_token_value1 => 'MRP_SAFETY_STOCK_CODE',
23682 p_token2 => 'DEFAULT_VALUE',
23683 p_token_value2 => 2);
23684
23685 IF lv_return <> 0 THEN
23686 RAISE ex_logging_err;
23687 END IF;
23688
23689 -- Valid value for mrp_safety_stock_code are (1,2),default it based on
23690 -- whether mrp_safety_stock_percent is NULL or Not
23691
23692 lv_where_str :=
23693 ' AND NVL(mrp_safety_stock_code,'||NULL_VALUE||') <>'||' 2 AND'
23694 ||' NVL(mrp_safety_stock_percent,'||NULL_VALUE||')<>'||NULL_VALUE;
23695
23696 lv_return := MSC_ST_UTIL.LOG_ERROR
23697 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23698 p_instance_code => v_instance_code,
23699 p_row => lv_column_names,
23700 p_severity => G_SEV_WARNING,
23701 p_message_text => lv_message_text,
23702 p_error_text => lv_error_text,
23703 p_batch_id => lv_batch_id,
23704 p_where_str => lv_where_str,
23705 p_col_name => 'mrp_safety_stock_code' ,
23706 p_debug => v_debug,
23707 p_default_value => 1);
23708
23709 IF lv_return <> 0 THEN
23710 RAISE ex_logging_err;
23711 END IF;
23712
23713 -- Set the error message
23714 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23715 (p_app_short_name => 'MSC',
23716 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23717 p_message_text => lv_message_text,
23718 p_error_text => lv_error_text,
23719 p_token1 => 'COLUMN_NAME',
23720 p_token_value1 => 'ATP_FLAG',
23721 p_token2 => 'DEFAULT_VALUE',
23722 p_token_value2 => G_ATP_FLAG);
23723
23724 IF lv_return <> 0 THEN
23725 RAISE ex_logging_err;
23726 END IF;
23727
23728 -- Valid value for atp_flag are (Y,N,C),default it to N
23729
23730 lv_where_str :=
23731 ' AND NVL(atp_flag ,'||''''||NULL_CHAR||''''||')'
23732 ||' NOT IN (''Y'', ''N'', ''C'')';
23733
23734 lv_return := MSC_ST_UTIL.LOG_ERROR
23735 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23736 p_instance_code => v_instance_code,
23737 p_row => lv_column_names,
23738 p_severity => G_SEV_WARNING,
23739 p_message_text => lv_message_text,
23740 p_error_text => lv_error_text,
23741 p_batch_id => lv_batch_id,
23742 p_where_str => lv_where_str,
23743 p_col_name => 'ATP_FLAG' ,
23744 p_debug => v_debug,
23745 p_default_value => '''N''');
23746
23747 IF lv_return <> 0 THEN
23748 RAISE ex_logging_err;
23749 END IF;
23750
23751 -- Set the error message
23752 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23753 (p_app_short_name => 'MSC',
23754 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23755 p_message_text => lv_message_text,
23756 p_error_text => lv_error_text,
23757 p_token1 => 'COLUMN_NAME',
23758 p_token_value1 => 'INVENTORY_ASSET_FLAG',
23759 p_token2 => 'DEFAULT_VALUE',
23760 p_token_value2 => G_INVENTORY_ASSET_FLAG);
23761
23762 IF lv_return <> 0 THEN
23763 RAISE ex_logging_err;
23764 END IF;
23765
23766 -- Valid value for inventory_asset_flag are (Y,N),default it to N
23767
23768 lv_where_str :=
23769 ' AND NVL(inventory_asset_flag,'||''''||NULL_CHAR||''''||')'
23770 ||' NOT IN (''Y'', ''N'')';
23771
23772 lv_return := MSC_ST_UTIL.LOG_ERROR
23773 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23774 p_instance_code => v_instance_code,
23775 p_row => lv_column_names,
23776 p_severity => G_SEV_WARNING,
23777 p_message_text => lv_message_text,
23778 p_error_text => lv_error_text,
23779 p_batch_id => lv_batch_id,
23780 p_where_str => lv_where_str,
23781 p_col_name => 'INVENTORY_ASSET_FLAG' ,
23782 p_debug => v_debug,
23783 p_default_value => '''Y''');
23784
23785 IF lv_return <> 0 THEN
23786 RAISE ex_logging_err;
23787 END IF;
23788
23789 -- Set the error message
23790 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23791 (p_app_short_name => 'MSC',
23792 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23793 p_message_text => lv_message_text,
23794 p_error_text => lv_error_text,
23795 p_token1 => 'COLUMN_NAME',
23796 p_token_value1 => 'END_ASSEMBLY_PEGGING_FLAG',
23797 p_token2 => 'DEFAULT_VALUE',
23798 p_token_value2 => G_END_ASSEMBLY_PEGGING_FLAG);
23799
23800 IF lv_return <> 0 THEN
23801 RAISE ex_logging_err;
23802 END IF;
23803
23804
23805 -- Valid value for end_assembly_pegging_flag are
23806 -- ('A','B','I','N','X','Y'),default it to N
23807
23808 lv_where_str :=
23809 ' AND end_assembly_pegging_flag NOT IN (''A'',''B'',''X'',''I'',''N'',''Y'')';
23810 lv_return := MSC_ST_UTIL.LOG_ERROR
23811 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23812 p_instance_code => v_instance_code,
23813 p_row => lv_column_names,
23814 p_severity => G_SEV_WARNING,
23815 p_message_text => lv_message_text,
23816 p_error_text => lv_error_text,
23817 p_batch_id => lv_batch_id,
23818 p_where_str => lv_where_str,
23819 p_col_name => 'END_ASSEMBLY_PEGGING_FLAG' ,
23820 p_debug => v_debug,
23821 p_default_value => '''N''');
23822
23823 IF lv_return <> 0 THEN
23824 RAISE ex_logging_err;
23825 END IF;
23826
23827 -- Set the error message
23828 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23829 (p_app_short_name => 'MSC',
23830 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23831 p_message_text => lv_message_text,
23832 p_error_text => lv_error_text,
23833 p_token1 => 'COLUMN_NAME',
23834 p_token_value1 => 'WIP_SUPPLY_TYPE',
23835 p_token2 => 'DEFAULT_VALUE',
23836 p_token_value2 => G_WIP_SUPPLY_TYPE);
23837
23838 IF lv_return <> 0 THEN
23839 RAISE ex_logging_err;
23840 END IF;
23841
23842
23843 -- Valid value for wip_supply_type are (1,2,3,4,5,6,7),default it to 1
23844
23845 lv_where_str := ' AND NVL(wip_supply_type,'||NULL_VALUE||') NOT IN (1,2,3,4,5,6,7) ';
23846
23847 lv_return := MSC_ST_UTIL.LOG_ERROR
23848 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23849 p_instance_code => v_instance_code,
23850 p_row => lv_column_names,
23851 p_severity => G_SEV_WARNING,
23852 p_message_text => lv_message_text,
23853 p_error_text => lv_error_text,
23854 p_batch_id => lv_batch_id,
23855 p_where_str => lv_where_str,
23856 p_col_name => 'WIP_SUPPLY_TYPE' ,
23857 p_debug => v_debug,
23858 p_default_value => G_WIP_SUPPLY_TYPE);
23859
23860 IF lv_return <> 0 THEN
23861 RAISE ex_logging_err;
23862 END IF;
23863
23864
23865 -- Set the error message
23866 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23867 (p_app_short_name => 'MSC',
23868 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23869 p_message_text => lv_message_text,
23870 p_error_text => lv_error_text,
23871 p_token1 => 'COLUMN_NAME',
23872 p_token_value1 => 'ATO_FORECAST_CONTROL',
23873 p_token2 => 'DEFAULT_VALUE',
23874 p_token_value2 => G_ATO_FORECAST_CONTROL);
23875
23876 IF lv_return <> 0 THEN
23877 RAISE ex_logging_err;
23878 END IF;
23879
23880 -- Default ato_forecast_control to 3 if NOT IN (1,2,3)
23881
23882 lv_where_str := ' AND ato_forecast_control NOT IN (1,2,3) ';
23883
23884 lv_return := MSC_ST_UTIL.LOG_ERROR
23885 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23886 p_instance_code => v_instance_code,
23887 p_row => lv_column_names,
23888 p_severity => G_SEV_WARNING,
23889 p_message_text => lv_message_text,
23890 p_error_text => lv_error_text,
23891 p_batch_id => lv_batch_id,
23892 p_where_str => lv_where_str,
23893 p_col_name => 'ATO_FORECAST_CONTROL' ,
23894 p_debug => v_debug,
23895 p_default_value => G_ATO_FORECAST_CONTROL);
23896
23897 IF lv_return <> 0 THEN
23898 RAISE ex_logging_err;
23899 END IF;
23900
23901 -- Set the error message
23902 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23903 (p_app_short_name => 'MSC',
23904 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23905 p_message_text => lv_message_text,
23906 p_error_text => lv_error_text,
23907 p_token1 => 'COLUMN_NAME',
23908 p_token_value1 => 'INVENTORY_ITEM_FLAG',
23909 p_token2 => 'DEFAULT_VALUE',
23910 p_token_value2 => G_INVENTORY_ITEM_FLAG);
23911
23912 IF lv_return <> 0 THEN
23913 RAISE ex_logging_err;
23914 END IF;
23915
23916 -- Default inventory_item_flag to 1 if NOT IN (1,2)
23917
23918 lv_where_str := ' AND inventory_item_flag NOT IN (1,2) ';
23919
23920 lv_return := MSC_ST_UTIL.LOG_ERROR
23921 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23922 p_instance_code => v_instance_code,
23923 p_row => lv_column_names,
23924 p_severity => G_SEV_WARNING,
23925 p_message_text => lv_message_text,
23926 p_error_text => lv_error_text,
23927 p_batch_id => lv_batch_id,
23928 p_where_str => lv_where_str,
23929 p_col_name => 'INVENTORY_ITEM_FLAG' ,
23930 p_debug => v_debug,
23931 p_default_value => G_INVENTORY_ITEM_FLAG);
23932
23933 IF lv_return <> 0 THEN
23934 RAISE ex_logging_err;
23935 END IF;
23936
23937 -- Set the error message
23938 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23939 (p_app_short_name => 'MSC',
23940 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23941 p_message_text => lv_message_text,
23942 p_error_text => lv_error_text,
23943 p_token1 => 'COLUMN_NAME',
23944 p_token_value1 => 'INVENTORY_TYPE',
23945 p_token2 => 'DEFAULT_VALUE',
23946 p_token_value2 => G_INVENTORY_TYPE);
23947
23948 IF lv_return <> 0 THEN
23949 RAISE ex_logging_err;
23950 END IF;
23951
23952 -- Default inventory_item_flag to 1 if NOT IN (1,2)
23953
23954 lv_where_str := ' AND inventory_type NOT IN (1,2,3,4,5,6,7,8) ';
23955
23956 lv_return := MSC_ST_UTIL.LOG_ERROR
23957 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23958 p_instance_code => v_instance_code,
23959 p_row => lv_column_names,
23960 p_severity => G_SEV_WARNING,
23961 p_message_text => lv_message_text,
23962 p_error_text => lv_error_text,
23963 p_batch_id => lv_batch_id,
23964 p_where_str => lv_where_str,
23965 p_col_name => 'INVENTORY_TYPE' ,
23966 p_debug => v_debug,
23967 p_default_value => G_INVENTORY_TYPE);
23968
23969 IF lv_return <> 0 THEN
23970 RAISE ex_logging_err;
23971 END IF;
23972 END IF ; --v_install_msc
23973 -- Set the error message
23974 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
23975 (p_app_short_name => 'MSC',
23976 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
23977 p_message_text => lv_message_text,
23978 p_error_text => lv_error_text,
23979 p_token1 => 'COLUMN_NAME',
23980 p_token_value1 => 'BOM_ITEM_TYPE',
23981 p_token2 => 'DEFAULT_VALUE',
23982 p_token_value2 => G_BOM_ITEM_TYPE);
23983
23984 IF lv_return <> 0 THEN
23985 RAISE ex_logging_err;
23986 END IF;
23987
23988 -- Default BOM Item Type to 4 if NOT IN (1,2,3,4,5)
23989
23990 lv_where_str := ' AND bom_item_type NOT IN (1,2,3,4,5) ';
23991
23992 lv_return := MSC_ST_UTIL.LOG_ERROR
23993 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
23994 p_instance_code => v_instance_code,
23995 p_row => lv_column_names,
23996 p_severity => G_SEV_WARNING,
23997 p_message_text => lv_message_text,
23998 p_error_text => lv_error_text,
23999 p_batch_id => lv_batch_id,
24000 p_where_str => lv_where_str,
24001 p_col_name => 'bom_item_type' ,
24002 p_debug => v_debug,
24003 p_default_value => G_BOM_ITEM_TYPE);
24004
24005 IF lv_return <> 0 THEN
24006 RAISE ex_logging_err;
24007 END IF;
24008
24009
24010 -- Set the error message for DRP_PLANNED flag
24011 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
24012 (p_app_short_name => 'MSC',
24013 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
24014 p_message_text => lv_message_text,
24015 p_error_text => lv_error_text,
24016 p_token1 => 'COLUMN_NAME',
24017 p_token_value1 => 'DRP_PLANNED',
24018 p_token2 => 'DEFAULT_VALUE',
24019 p_token_value2 => G_DRP_PLANNED);
24020
24021 IF lv_return <> 0 THEN
24022 RAISE ex_logging_err;
24023 END IF;
24024
24025 -- Valid value for drp_planned is 1,2 default it to 2
24026
24027 lv_where_str :=
24028 ' AND NVL(drp_planned,'||NULL_VALUE||')'
24029 ||' NOT IN (1,2)';
24030
24031 lv_return := MSC_ST_UTIL.LOG_ERROR
24032 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
24033 p_instance_code => v_instance_code,
24034 p_row => lv_column_names,
24035 p_severity => G_SEV_WARNING,
24036 p_message_text => lv_message_text,
24037 p_error_text => lv_error_text,
24038 p_batch_id => lv_batch_id,
24039 p_where_str => lv_where_str,
24040 p_col_name => 'DRP_PLANNED',
24041 p_debug => v_debug,
24042 p_default_value => G_DRP_PLANNED);
24043
24044 IF lv_return <> 0 THEN
24045 RAISE ex_logging_err;
24046 END IF;
24047
24048
24049 -- Set the error message for SERIAL_NUMBER_CONTROL_CODE
24050
24051 lv_return := MSC_ST_util.GET_ERROR_MESSAGE
24052 (p_app_short_name => 'MSC',
24053 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
24054 p_message_text => lv_message_text,
24055 p_error_text => lv_error_text,
24056 p_token1 => 'COLUMN_NAME',
24057 p_token_value1 => 'SERIAL_NUMBER_CONTROL_CODE',
24058 p_token2 => 'DEFAULT_VALUE',
24059 p_token_value2 => G_SERIAL_NUMBER_CONTROL_CODE );
24060
24061 IF lv_return <> 0 THEN
24062 RAISE ex_logging_err;
24063 END IF;
24064
24065 -- Valid values for SERIAL_NUMBER_CONTROL_CODE are 1,2 default it to 2
24066
24067 lv_where_str :=
24068 ' AND NVL(SERIAL_NUMBER_CONTROL_CODE,2)'
24069 ||' NOT IN (1,2)';
24070
24071 lv_return := MSC_ST_util.LOG_ERROR
24072 (p_table_name => 'MSC_ST_SYSTEM_ITEMS',
24073 p_instance_code => v_instance_code,
24074 p_row => lv_column_names,
24075 p_severity => G_SEV_WARNING,
24076 p_message_text => lv_message_text,
24077 p_error_text => lv_error_text,
24078 p_batch_id => lv_batch_id,
24079 p_where_str => lv_where_str,
24080 p_col_name => 'SERIAL_NUMBER_CONTROL_CODE',
24081 p_debug => v_debug,
24082 p_default_value => G_SERIAL_NUMBER_CONTROL_CODE);
24083
24084 IF lv_return <> 0 THEN
24085 RAISE ex_logging_err;
24086 END IF;
24087
24088 -- If the Serial Number Validation is enabled.
24089 IF NVL(FND_PROFILE.VALUE('MSC_DEFAULT_SERIAL_CONTROL'),'Y') ='Y' THEN
24090
24091 -- Assumes the org_id,inventory_item_id and sr_instance_id is derrived by now.
24092 -- Set the error message
24093
24094 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
24095 (p_app_short_name => 'MSC',
24096 p_error_code => 'MSC_PP_SERIAL_FLAG_NOT_CHANGED',
24097 p_message_text => lv_message_text,
24098 p_error_text => lv_error_text);
24099
24100 IF lv_return <> 0 THEN
24101 RAISE ex_logging_err;
24102 END IF;
24103
24104 -- Error out record if supply/demand daa exists and serial_number_control_code flag is being set to no(2)
24105
24106 v_sql_stmt := 100;
24107
24108 lv_sql_stmt :=
24109 ' UPDATE msc_st_system_items mssi '
24110 ||' SET process_flag = '||G_ERROR_FLG||','
24111 ||' error_text = '||''''||lv_message_text||''''
24112 ||' WHERE nvl(serial_number_control_code,2) = 2 '
24113 ||' AND EXISTS (SELECT serial_number_control_code
24114 FROM msc_system_items msi,
24115 msc_item_id_lid miil,
24116 msc_apps_instances mai
24117 WHERE msi.plan_id = -1
24118 AND msi.organization_id = mssi.organization_id
24119 AND msi.sr_instance_id = mai.instance_id
24120 AND msi.inventory_item_id = miil.inventory_item_id
24121 AND miil.sr_instance_id = mai.instance_id
24122 AND mai.instance_code = mssi.sr_instance_code
24123 AND miil.sr_inventory_item_id = mssi.sr_inventory_item_id
24124 AND msi.serial_number_control_code = 1
24125 )'
24126 ||' AND EXISTS (SELECT msn.serial_txn_id
24127 FROM msc_serial_numbers msn,
24128 msc_sup_dem_entries msde,
24129 msc_trading_partner_maps mtpm,
24130 msc_trading_partners mtp,
24131 msc_item_id_lid miil,
24132 msc_apps_instances mai
24133 WHERE msde.inventory_item_id = miil.inventory_item_id
24134 AND miil.sr_inventory_item_id = mssi.sr_inventory_item_id
24135 AND miil.sr_instance_id = mai.instance_id
24136 AND mai.instance_code = mssi.sr_instance_code
24137 AND msde.plan_id = -1
24138 AND msde.publisher_site_id = mtpm.company_key
24139 AND mtpm.map_type = 2
24140 AND mtpm.tp_key = mtp.partner_id
24141 AND mtp.partner_type = 3
24142 AND mtp.sr_tp_id = mssi.organization_id
24143 AND mtp.sr_instance_id = mai.instance_id
24144 AND msde.transaction_id = msn.serial_txn_id
24145 AND NVL(msn.disable_date,sysdate+1)>sysdate
24146 )'
24147 ||' AND batch_id = :lv_batch_id'
24148 ||' AND process_flag = '||G_IN_PROCESS
24149 ||' AND sr_instance_code = :v_instance_code';
24150
24151
24152 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
24153
24154 EXECUTE IMMEDIATE lv_sql_stmt
24155 USING lv_batch_id,
24156 v_instance_code;
24157 END IF;
24158
24159
24160
24161 /* Bug 2172537 , do not prefix instance code before org code
24162 --Concatenating organization_code with instance_code
24163 v_sql_stmt := 19;
24164 lv_sql_stmt:=
24165 'UPDATE msc_st_system_items '
24166 ||' SET organization_code= sr_instance_code'||'||'':''||'||'organization_code'
24167 ||' WHERE process_flag = '||G_IN_PROCESS
24168 ||' AND batch_id = :lv_batch_id'
24169 ||' AND sr_instance_code = :v_instance_code';
24170
24171
24172 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
24173
24174 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code; */
24175
24176 /*** Setting the process_flag to valid in LOAD_ITEM_ABC_CLASSES -- fix for the bug 2191021
24177 -- Set the process flag as Valid and populate instance_id */
24178
24179 lv_return :=
24180 MSC_ST_UTIL.SET_PROCESS_FLAG(p_table_name => 'MSC_ST_SYSTEM_ITEMS',
24181 p_instance_id => v_instance_id,
24182 p_instance_code => v_instance_code,
24183 p_process_flag => G_VALID,
24184 p_error_text => lv_error_text,
24185 p_debug => v_debug,
24186 p_batch_id => lv_batch_id);
24187
24188 IF lv_return <> 0 THEN
24189 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
24190 END IF;
24191
24192
24193 -- At the end calling the LOG_ERROR for logging all errored out records
24194
24195 lv_return :=
24196 MSC_ST_UTIL.LOG_ERROR(p_table_name =>'MSC_ST_SYSTEM_ITEMS',
24197 p_instance_code =>v_instance_code,
24198 p_row =>lv_column_names,
24199 p_severity =>G_SEV_ERROR,
24200 p_message_text =>NULL,
24201 p_error_text =>lv_error_text,
24202 p_debug => v_debug,
24203 p_batch_id => lv_batch_id );
24204
24205 IF(lv_return <> 0) THEN
24206 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
24207 END IF;
24208 COMMIT;
24209
24210
24211 IF c_lock%ISOPEN THEN
24212 CLOSE c_lock;
24213 END IF;
24214
24215 -- ODP change
24216 -- Call the procedure to insert all items into the msd_st_level_values
24217 IF(v_install_msd) THEN
24218 lv_sql_stmt := ' DECLARE errbuf varchar2(250);'
24219 ||' retcode number ;'
24220 ||' BEGIN '
24221 ||' MSD_CL_PRE_PROCESS.LOAD_ITEMS'
24222 ||' (ERRBUF => errbuf ,'
24223 ||' RETCODE => retcode ,'
24224 ||' p_instance_id => :v_instance_id,'
24225 ||' p_batch_id => :lv_batch_id);'
24226 ||' IF ( retcode = '||G_WARNING||') THEN'
24227 ||' MSC_CL_PRE_PROCESS.v_flag := '||SYS_YES||';'
24228 ||' END IF;'
24229 ||' END ;';
24230
24231 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
24232 EXECUTE IMMEDIATE lv_sql_stmt
24233 USING v_instance_id,
24234 lv_batch_id ;
24235 END IF ;
24236 COMMIT;
24237
24238
24239 EXCEPTION
24240 WHEN too_many_rows THEN
24241 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_ITEMS'||'('
24242 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
24243 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
24244 ROLLBACK;
24245 IF c_lock%ISOPEN THEN
24246 CLOSE c_lock;
24247 END IF;
24248 WHEN ex_logging_err THEN
24249 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
24250 ROLLBACK;
24251 IF c_lock%ISOPEN THEN
24252 CLOSE c_lock;
24253 END IF;
24254 WHEN OTHERS THEN
24255 lv_error_text :=substr('MSC_CL_PRE_PROCESS.LOAD_ITEMS'||'('
24256 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
24257 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
24258 ROLLBACK;
24259 IF c_lock%ISOPEN THEN
24260 CLOSE c_lock;
24261 END IF;
24262 END LOAD_ITEMS;
24263
24264
24265 /*===========================================================================+
24266 | DESCRIPTION : This procedure validates the data in MSC_ST_ITEM_SUBSTITUTES|
24267 | table and derives the id's from the local id's table. |
24268 +===========================================================================*/
24269 PROCEDURE LOAD_ITEM_SUBSTITUTES IS
24270
24271 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
24272 lb_rowid RowidTab;
24273 lv_return NUMBER;
24274 lv_error_text VARCHAR2(250);
24275 lv_where_str VARCHAR2(5000);
24276 lv_sql_stmt VARCHAR2(5000);
24277 lv_column_names VARCHAR2(5000); --stores concatenated column names
24278 lv_batch_id msc_st_item_substitutes.batch_id%TYPE;
24279 lv_message_text msc_errors.error_text%TYPE;
24280
24281 ex_logging_err EXCEPTION;
24282
24283 CURSOR c1(p_batch_id NUMBER) IS
24284 SELECT rowid
24285 FROM msc_st_item_substitutes
24286 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
24287 AND batch_id = p_batch_id
24288 AND sr_instance_code = v_instance_code;
24289
24290 BEGIN
24291
24292 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
24293 (p_app_short_name => 'MSC',
24294 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
24295 p_message_text => lv_message_text,
24296 p_error_text => lv_error_text);
24297
24298 IF lv_return <> 0 THEN
24299 RAISE ex_logging_err;
24300 END IF;
24301
24302 --Duplicate records check for the records whose source is XML
24303 v_sql_stmt := 01;
24304 lv_sql_stmt :=
24305 ' UPDATE msc_st_item_substitutes msu1'
24306 ||' SET process_flag = '||G_ERROR_FLG||','
24307 ||' error_text = '||''''||lv_message_text||''''
24308 ||' WHERE message_id < (SELECT MAX(message_id)'
24309 ||' FROM msc_st_item_substitutes msu2'
24310 ||' WHERE msu2.sr_instance_code = msu1.sr_instance_code'
24311 ||' AND NVL(msu2.RELATIONSHIP_TYPE, '||''''||NULL_CHAR||''''||') = '
24312 ||' NVL(msu1.RELATIONSHIP_TYPE, '||''''||NULL_CHAR||''''||')'
24313 ||' AND msu2.ITEM_NAME = msu1.ITEM_NAME'
24314 ||' AND msu2.SUBSTITUTE_ITEM_NAME = msu1.SUBSTITUTE_ITEM_NAME'
24315 ||' AND NVL(msu2.CUSTOMER_NAME, '||''''||NULL_CHAR||''''||') = '
24316 ||' NVL(msu1.CUSTOMER_NAME, '||''''||NULL_CHAR||''''||')'
24317 ||' AND NVL(msu2.CUSTOMER_SITE_CODE, '||''''||NULL_CHAR||''''||') = '
24318 ||' NVL(msu1.CUSTOMER_SITE_CODE, '||''''||NULL_CHAR||''''||')'
24319 ||' AND NVL(msu2.SUBSTITUTION_SET, '||''''||NULL_CHAR||''''||') = '
24320 ||' NVL(msu1.SUBSTITUTION_SET, '||''''||NULL_CHAR||''''||')'
24321 ||' AND NVL(msu2.EFFECTIVE_DATE,sysdate) = NVL(msu1.EFFECTIVE_DATE,sysdate) '
24322 ||' AND NVL(msu2.DISABLE_DATE,sysdate) = NVL(msu1.DISABLE_DATE,sysdate) '
24323 ||' AND NVL(msu2.company_name, '||''''||NULL_CHAR||''''||') = '
24324 ||' NVL(msu1.company_name, '||''''||NULL_CHAR||''''||')'
24325 ||' AND msu2.process_flag = msu1.process_flag'
24326 ||' AND NVL(msu2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
24327 ||' AND msu1.process_flag = '||G_IN_PROCESS
24328 ||' AND msu1.sr_instance_code = :v_instance_code'
24329 ||' AND NVL(msu1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
24330
24331
24332 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
24333
24334 EXECUTE IMMEDIATE lv_sql_stmt
24335 USING v_instance_code;
24336
24337 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
24338 (p_app_short_name => 'MSC',
24339 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
24340 p_message_text => lv_message_text,
24341 p_error_text => lv_error_text);
24342
24343 IF lv_return <> 0 THEN
24344 RAISE ex_logging_err;
24345 END IF;
24346
24347 --Duplicate records check for the records whose source is other than XML
24348 --Different SQL is used because in XML we can identify the latest records
24349 --whereas in batch load we cannot.
24350
24351 v_sql_stmt := 02;
24352 lv_sql_stmt :=
24353 ' UPDATE msc_st_item_substitutes msu1'
24354 ||' SET process_flag = '||G_ERROR_FLG||','
24355 ||' error_text = '||''''||lv_message_text||''''
24356 ||' WHERE EXISTS( SELECT 1 '
24357 ||' FROM msc_st_item_substitutes msu2'
24358 ||' WHERE msu2.sr_instance_code = msu1.sr_instance_code'
24359 ||' AND NVL(msu2.RELATIONSHIP_TYPE, '||''''||NULL_CHAR||''''||') = '
24360 ||' NVL(msu1.RELATIONSHIP_TYPE, '||''''||NULL_CHAR||''''||')'
24361 ||' AND msu2.ITEM_NAME = msu1.ITEM_NAME'
24362 ||' AND msu2.SUBSTITUTE_ITEM_NAME = msu1.SUBSTITUTE_ITEM_NAME'
24363 ||' AND NVL(msu2.CUSTOMER_NAME, '||''''||NULL_CHAR||''''||') = '
24364 ||' NVL(msu1.CUSTOMER_NAME, '||''''||NULL_CHAR||''''||')'
24365 ||' AND NVL(msu2.CUSTOMER_SITE_CODE, '||''''||NULL_CHAR||''''||') = '
24366 ||' NVL(msu1.CUSTOMER_SITE_CODE, '||''''||NULL_CHAR||''''||')'
24367 ||' AND NVL(msu2.SUBSTITUTION_SET, '||''''||NULL_CHAR||''''||') = '
24368 ||' NVL(msu1.SUBSTITUTION_SET, '||''''||NULL_CHAR||''''||')'
24369 ||' AND NVL(msu2.EFFECTIVE_DATE,sysdate) = NVL(msu1.EFFECTIVE_DATE,sysdate) '
24370 ||' AND NVL(msu2.DISABLE_DATE,sysdate) = NVL(msu1.DISABLE_DATE,sysdate) '
24371 ||' AND NVL(msu2.company_name, '||''''||NULL_CHAR||''''||') = '
24372 ||' NVL(msu1.company_name, '||''''||NULL_CHAR||''''||')'
24373 ||' AND msu2.process_flag = msu1.process_flag'
24374 ||' AND NVL(msu2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
24375 ||' AND msu2.rowid <> msu1.rowid)'
24376 ||' AND msu1.process_flag = '||G_IN_PROCESS
24377 ||' AND msu1.sr_instance_code = :v_instance_code '
24378 ||' AND NVL(msu1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
24379
24380
24381 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
24382
24383 EXECUTE IMMEDIATE lv_sql_stmt
24384 USING v_instance_code;
24385
24386 lv_column_names :=
24387 'LOWER_ITEM_ID ||''~''||'
24388 ||'HIGHER_ITEM_ID ||''~''||'
24389 ||'HIGHEST_ITEM_ID ||''~''||'
24390 ||'EFFECTIVE_DATE ||''~''||'
24391 ||'DISABLE_DATE ||''~''||'
24392 ||'RELATIONSHIP_TYPE ||''~''||'
24393 ||'RECIPROCAL_FLAG ||''~''||'
24394 ||'SUBSTITUTION_SET ||''~''||'
24395 ||'PARTIAL_FULFILLMENT_FLAG ||''~''||'
24396 ||'SUBSTITUTE_ITEM_NAME ||''~''||'
24397 ||'ITEM_NAME ||''~''||'
24398 ||'CUSTOMER_NAME ||''~''||'
24399 ||'CUSTOMER_SITE_CODE ||''~''||'
24400 ||'DELETED_FLAG ';
24401
24402 LOOP
24403 v_sql_stmt := 03;
24404 SELECT msc_st_batch_id_s.NEXTVAL
24405 INTO lv_batch_id
24406 FROM dual;
24407
24408 v_sql_stmt := 04;
24409 lv_sql_stmt :=
24410 ' UPDATE msc_st_item_substitutes '
24411 ||' SET batch_id = :lv_batch_id'
24412 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
24413 ||' AND sr_instance_code = :v_instance_code'
24414 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
24415 ||' AND rownum <= '||v_batch_size;
24416
24417
24418 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
24419
24420 EXECUTE IMMEDIATE lv_sql_stmt
24421 USING lv_batch_id,
24422 v_instance_code;
24423
24424 EXIT WHEN SQL%NOTFOUND;
24425
24426 OPEN c1(lv_batch_id);
24427 FETCH c1 BULK COLLECT INTO lb_rowid;
24428 CLOSE c1;
24429
24430 v_sql_stmt := 05;
24431 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
24432 UPDATE msc_st_item_substitutes
24433 SET st_transaction_id = msc_st_item_substitute_s.NEXTVAL,
24434 last_update_date = v_current_date,
24435 last_updated_by = v_current_user,
24436 creation_date = v_current_date,
24437 created_by = v_current_user
24438 WHERE rowid = lb_rowid(j);
24439
24440 /* lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
24441 (p_app_short_name => 'MSC',
24442 p_error_code => 'MSC_PP_NO_DELETION',
24443 p_message_text => lv_message_text,
24444 p_error_text => lv_error_text,
24445 p_token1 => 'TABLE_NAME',
24446 p_token_value1 => 'MSC_ST_ITEM_SUBSTITUTES');
24447
24448 IF lv_return <> 0 THEN
24449 RAISE ex_logging_err;
24450 END IF;
24451
24452 --Deletion is not allowed for this entity.
24453 v_sql_stmt := 06;
24454 lv_sql_stmt :=
24455 ' UPDATE msc_st_item_substitutes '
24456 ||' SET process_flag = '||G_ERROR_FLG||','
24457 ||' error_text = '||''''||lv_message_text||''''
24458 ||' WHERE deleted_flag = '||SYS_YES
24459 ||' AND process_flag = '||G_IN_PROCESS
24460 ||' AND batch_id = :lv_batch_id'
24461 ||' AND sr_instance_code = :v_instance_code';
24462
24463
24464 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
24465
24466 EXECUTE IMMEDIATE lv_sql_stmt
24467 USING lv_batch_id,
24468 v_instance_code;
24469
24470 */
24471
24472 -- RELATIONSHIP_TYPE default to 2
24473
24474 lv_where_str := ' AND RELATIONSHIP_TYPE IS NULL';
24475 lv_return := MSC_ST_UTIL.LOG_ERROR
24476 (p_table_name => 'msc_st_item_substitutes',
24477 p_instance_code => v_instance_code,
24478 p_row => lv_column_names,
24479 p_severity => G_SEV_WARNING,
24480 p_message_text => lv_message_text,
24481 p_error_text => lv_error_text,
24482 p_batch_id => lv_batch_id,
24483 p_where_str => lv_where_str,
24484 p_col_name => 'RELATIONSHIP_TYPE',
24485 p_debug => v_debug,
24486 p_default_value => G_RELATIONSHIP_TYPE);
24487
24488 IF lv_return <> 0 THEN
24489 RAISE ex_logging_err;
24490 END IF;
24491
24492 -- Set the error message
24493 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
24494 (p_app_short_name => 'MSC',
24495 p_error_code => 'MSC_PP_INVALID_VALUE',
24496 p_message_text => lv_message_text,
24497 p_error_text => lv_error_text,
24498 p_token1 => 'COLUMN_NAME',
24499 p_token_value1 => 'RECIPROCAL_FLAG');
24500
24501 IF lv_return <> 0 THEN
24502 RAISE ex_logging_err;
24503 END IF;
24504
24505
24506 -- Valid value for RECIPROCAL_FLAG is 1 and 2
24507
24508 v_sql_stmt := 99;
24509 lv_sql_stmt :=
24510
24511 ' UPDATE msc_st_item_substitutes '
24512 ||' SET process_flag = '||G_ERROR_FLG||','
24513 ||' error_text = '||''''||lv_message_text||''''
24514 ||' WHERE nvl(RECIPROCAL_FLAG,'||NULL_VALUE||') not in(1,2)'
24515 ||' AND process_flag = '||G_IN_PROCESS
24516 ||' AND batch_id = :lv_batch_id'
24517 ||' AND sr_instance_code = :v_instance_code';
24518
24519
24520 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
24521
24522 EXECUTE IMMEDIATE lv_sql_stmt
24523 USING lv_batch_id,
24524 v_instance_code;
24525
24526 -- Set the error message
24527 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
24528 (p_app_short_name => 'MSC',
24529 p_error_code => 'MSC_PP_INVALID_VALUE',
24530 p_message_text => lv_message_text,
24531 p_error_text => lv_error_text,
24532 p_token1 => 'COLUMN_NAME',
24533 p_token_value1 => 'PARTIAL_FULFILLMENT_FLAG');
24534
24535 IF lv_return <> 0 THEN
24536 RAISE ex_logging_err;
24537 END IF;
24538
24539
24540 -- Valid value for PARTIAL_FULFILLMENT_FLAG is 1,2
24541
24542 v_sql_stmt := 98;
24543 lv_sql_stmt :=
24544
24545 ' UPDATE msc_st_item_substitutes '
24546 ||' SET process_flag = '||G_ERROR_FLG||','
24547 ||' error_text = '||''''||lv_message_text||''''
24548 ||' WHERE nvl(PARTIAL_FULFILLMENT_FLAG,'||NULL_VALUE||') not in(1,2)'
24549 ||' AND relationship_type = 2 '
24550 ||' AND process_flag = '||G_IN_PROCESS
24551 ||' AND batch_id = :lv_batch_id'
24552 ||' AND sr_instance_code = :v_instance_code';
24553
24554
24555 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
24556
24557 EXECUTE IMMEDIATE lv_sql_stmt
24558 USING lv_batch_id,
24559 v_instance_code;
24560
24561 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
24562 (p_app_short_name => 'MSC',
24563 p_error_code => 'MSC_PP_INVALID_VALUE',
24564 p_message_text => lv_message_text,
24565 p_error_text => lv_error_text,
24566 p_token1 => 'COLUMN_NAME',
24567 p_token_value1 => 'ORGANIZATION_CODE');
24568
24569 IF lv_return <> 0 THEN
24570 RAISE ex_logging_err;
24571 END IF;
24572
24573 -- Derive organization_id
24574 lv_return :=msc_st_util.derive_partner_org_id
24575 (p_table_name => 'MSC_ST_ITEM_SUBSTITUTES',
24576 p_org_partner_name => 'ORGANIZATION_CODE',
24577 p_org_partner_id => 'ORGANIZATION_ID',
24578 p_instance_code => v_instance_code,
24579 p_partner_type => G_ORGANIZATION,
24580 p_error_text => lv_error_text,
24581 p_debug => v_debug,
24582 p_batch_id => lv_batch_id);
24583
24584 IF lv_return <> 0 THEN
24585 RAISE ex_logging_err;
24586 END IF;
24587
24588 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
24589 (p_app_short_name => 'MSC',
24590 p_error_code => 'MSC_PP_INVALID_VALUE',
24591 p_message_text => lv_message_text,
24592 p_error_text => lv_error_text,
24593 p_token1 => 'COLUMN_NAME',
24594 p_token_value1 => 'CUSTOMER_NAME');
24595
24596 IF lv_return <> 0 THEN
24597 RAISE ex_logging_err;
24598 END IF;
24599
24600 lv_where_str := ' AND RELATIONSHIP_TYPE = 2';
24601
24602 -- Derive sr_tp_id(Customer)
24603 lv_return :=msc_st_util.derive_partner_org_id
24604 (p_table_name => 'MSC_ST_ITEM_SUBSTITUTES',
24605 p_org_partner_name => 'CUSTOMER_NAME',
24606 p_org_partner_id => 'CUSTOMER_ID',
24607 p_instance_code => v_instance_code,
24608 p_partner_type => G_CUSTOMER,
24609 p_error_text => lv_error_text,
24610 p_debug => v_debug,
24611 p_severity => G_SEV3_ERROR,
24612 p_message_text => lv_message_text,
24613 p_row => lv_column_names,
24614 p_batch_id => lv_batch_id,
24615 p_where_str => lv_where_str);
24616
24617 IF lv_return <> 0 THEN
24618 RAISE ex_logging_err;
24619 END IF;
24620
24621
24622 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
24623 (p_app_short_name => 'MSC',
24624 p_error_code => 'MSC_PP_INVALID_VALUE',
24625 p_message_text => lv_message_text,
24626 p_error_text => lv_error_text,
24627 p_token1 => 'COLUMN_NAME',
24628 p_token_value1 => 'CUSTOMER_SITE_CODE');
24629
24630 lv_where_str := ' AND RELATIONSHIP_TYPE = 2';
24631 -- Derive sr_tp_site_id(Customer)
24632 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
24633 (p_table_name => 'MSC_ST_ITEM_SUBSTITUTES',
24634 p_partner_name => 'CUSTOMER_NAME',
24635 p_partner_site_code => 'CUSTOMER_SITE_CODE',
24636 p_partner_site_id => 'CUSTOMER_SITE_ID',
24637 p_instance_code => v_instance_code,
24638 p_partner_type => G_CUSTOMER,
24639 p_error_text => lv_error_text,
24640 p_batch_id => lv_batch_id,
24641 p_severity => G_SEV3_ERROR,
24642 p_debug => v_debug,
24643 p_row => lv_column_names,
24644 p_where_str => lv_where_str);
24645
24646 IF lv_return <> 0 THEN
24647 RAISE ex_logging_err;
24648 END IF;
24649
24650 --DERIVE LOWER_ITEM_ID
24651
24652 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
24653 (p_app_short_name => 'MSC',
24654 p_error_code => 'MSC_PP_INVALID_VALUE',
24655 p_message_text => lv_message_text,
24656 p_error_text => lv_error_text,
24657 p_token1 => 'COLUMN_NAME',
24658 p_token_value1 => 'ITEM_NAME');
24659
24660
24661 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
24662 (p_table_name =>'MSC_ST_ITEM_SUBSTITUTES',
24663 p_item_col_name =>'ITEM_NAME',
24664 p_item_col_id =>'LOWER_ITEM_ID',
24665 p_instance_code => v_instance_code,
24666 p_instance_id => v_instance_id,
24667 p_batch_id =>lv_batch_id,
24668 p_debug => v_debug,
24669 p_severity => G_SEV_ERROR,
24670 p_message_text =>lv_message_text,
24671 p_error_text =>lv_error_text,
24672 p_row => lv_column_names,
24673 p_check_org => FALSE);
24674
24675 IF lv_return <> 0 THEN
24676 RAISE ex_logging_err;
24677 END IF;
24678
24679
24680 --DERIVE HIGHER_ITEM_ID
24681
24682 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
24683 (p_app_short_name => 'MSC',
24684 p_error_code => 'MSC_PP_INVALID_VALUE',
24685 p_message_text => lv_message_text,
24686 p_error_text => lv_error_text,
24687 p_token1 => 'COLUMN_NAME',
24688 p_token_value1 => 'SUBSTITUTE_ITEM_NAME');
24689
24690
24691 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
24692 (p_table_name =>'msc_st_item_substitutes',
24693 p_item_col_name =>'SUBSTITUTE_ITEM_NAME',
24694 p_item_col_id =>'HIGHER_ITEM_ID',
24695 p_instance_code => v_instance_code,
24696 p_instance_id => v_instance_id,
24697 p_batch_id =>lv_batch_id,
24698 p_debug => v_debug,
24699 p_severity => G_SEV_ERROR,
24700 p_message_text =>lv_message_text,
24701 p_error_text =>lv_error_text,
24702 p_row => lv_column_names,
24703 p_check_org => FALSE);
24704
24705 IF lv_return <> 0 THEN
24706 RAISE ex_logging_err;
24707 END IF;
24708
24709 -- SUBSTITUTION_SET always default to 'DEFAULT'
24710
24711 lv_where_str :=
24712 ' AND NVL(SUBSTITUTION_SET,'||''''||NULL_CHAR||''''||') = '||''''||NULL_CHAR||'''';
24713 lv_return := MSC_ST_UTIL.LOG_ERROR
24714 (p_table_name => 'msc_st_item_substitutes',
24715 p_instance_code => v_instance_code,
24716 p_row => lv_column_names,
24717 p_severity => G_SEV_WARNING,
24718 p_message_text => lv_message_text,
24719 p_error_text => lv_error_text,
24720 p_batch_id => lv_batch_id,
24721 p_where_str => lv_where_str,
24722 p_col_name => 'SUBSTITUTION_SET',
24723 p_default_value => '''DEFAULT''',
24724 p_debug => v_debug);
24725
24726 IF lv_return <> 0 THEN
24727 RAISE ex_logging_err;
24728 END IF;
24729
24730 /* removed for SRP
24731 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
24732 (p_app_short_name => 'MSC',
24733 p_error_code => 'MSC_PP_NO_UPDATION',
24734 p_message_text => lv_message_text,
24735 p_error_text => lv_error_text,
24736 p_token1 => 'TABLE_NAME',
24737 p_token_value1 => 'MSC_ST_ITEM_SUBSTITUTES');
24738
24739 IF lv_return <> 0 THEN
24740 RAISE ex_logging_err;
24741 END IF;
24742
24743 --Updation is not allowed on this entity(this is done to make the
24744 --Post-Processor in sync with the collection program).
24745
24746 v_sql_stmt := 09;
24747 lv_sql_stmt :=
24748 ' UPDATE msc_st_item_substitutes mis1'
24749 ||' SET process_flag = '||G_ERROR_FLG||','
24750 ||' error_text = '||''''||lv_message_text||''''
24751 ||' WHERE process_flag = '||G_IN_PROCESS
24752 ||' AND batch_id = :lv_batch_id'
24753 ||' AND sr_instance_code = :v_instance_code'
24754 ||' AND EXISTS'
24755 ||' (SELECT 1 FROM msc_item_substitutes mis2'
24756 ||' WHERE mis2.higher_item_id = mis1.higher_item_id'
24757 ||' AND mis2.lower_item_id = mis1.lower_item_id'
24758 ||' AND nvl(mis2.customer_id, '||NULL_VALUE||') = nvl(mis1.customer_id,'||NULL_VALUE||')'
24759 ||' AND nvl(mis2.customer_site_id, '||NULL_VALUE||') = nvl(mis1.customer_site_id,'||NULL_VALUE||')'
24760 ||' AND mis2.substitution_set = mis1.substitution_set'
24761 ||' AND trunc(nvl(mis2.EFFECTIVE_DATE,SYSDATE+36500)) = trunc(nvl(mis1.EFFECTIVE_DATE, SYSDATE+36500))'
24762 ||' AND trunc(nvl(mis2.DISABLE_DATE, SYSDATE+36500)) = trunc(nvl(mis1.DISABLE_DATE, SYSDATE+36500))'
24763 ||' AND mis2.sr_instance_id = ' ||v_instance_id ||')';
24764
24765
24766 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
24767
24768 EXECUTE IMMEDIATE lv_sql_stmt
24769 USING lv_batch_id,
24770 v_instance_code;
24771 */
24772 ------ Changes for SRP legacy collections
24773
24774 ---set message
24775 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
24776 (p_app_short_name => 'MSC',
24777 p_error_code => 'MSC_PP_INVALID_VALUE',
24778 p_message_text => lv_message_text,
24779 p_error_text => lv_error_text,
24780 p_token1 => 'COLUMN_NAME',
24781 p_token_value1 => 'RELATIONSHIP_TYPE');
24782
24783 IF lv_return <> 0 THEN
24784 RAISE ex_logging_err;
24785 END IF;
24786
24787 -- check if relationship_type not in 2,5,8,18
24788
24789 v_sql_stmt := 12;
24790 lv_sql_stmt :=
24791 ' UPDATE msc_st_item_substitutes '
24792 ||' SET process_flag = '||G_ERROR_FLG||','
24793 ||' error_text = '||''''||lv_message_text||''''
24794 ||' WHERE RELATIONSHIP_TYPE not in(2,5,8,18)'
24795 ||' AND process_flag = '||G_IN_PROCESS
24796 ||' AND batch_id = :lv_batch_id'
24797 ||' AND sr_instance_code = :v_instance_code';
24798
24799
24800
24801 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
24802
24803 EXECUTE IMMEDIATE lv_sql_stmt
24804 USING lv_batch_id,
24805 v_instance_code;
24806
24807
24808 --Call to customised validation.
24809 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
24810 (ERRBUF => lv_error_text,
24811 RETCODE => lv_return,
24812 pBatchID => lv_batch_id,
24813 pInstanceCode => v_instance_code,
24814 pEntityName => 'MSC_ST_ITEM_SUBSTITUTES',
24815 pInstanceID => v_instance_id);
24816
24817 IF NVL(lv_return,0) <> 0 THEN
24818 RAISE ex_logging_err;
24819 END IF;
24820
24821 -- Set the process flag as Valid and derive sr_instance_id
24822
24823 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
24824 (p_table_name => 'MSC_ST_ITEM_SUBSTITUTES',
24825 p_instance_id => v_instance_id,
24826 p_instance_code => v_instance_code,
24827 p_process_flag => G_VALID,
24828 p_error_text => lv_error_text,
24829 p_debug => v_debug,
24830 p_batch_id => lv_batch_id);
24831
24832 IF lv_return <> 0 THEN
24833 RAISE ex_logging_err;
24834 END IF;
24835
24836 -- Inserting all the errored out records into MSC_ERRORS
24837
24838 lv_return := MSC_ST_UTIL.LOG_ERROR
24839 (p_table_name => 'MSC_ST_ITEM_SUBSTITUTES',
24840 p_instance_code => v_instance_code,
24841 p_row => lv_column_names,
24842 p_severity => G_SEV_ERROR,
24843 p_error_text => lv_error_text,
24844 p_message_text => NULL,
24845 p_batch_id => lv_batch_id);
24846
24847
24848 IF lv_return <> 0 THEN
24849 RAISE ex_logging_err;
24850 END IF;
24851
24852
24853 /*
24854 --MSCCLBAB is modified to handle the legacy collection of item substitutes
24855 --Bug#2489334
24856
24857 --Inserts the valid records into the ODS table, Since the collection program
24858 --doesn't collect this entity incrementally and whereras post-processor always
24859 --runs in the incremental mode.
24860
24861 v_sql_stmt := 10;
24862 lv_sql_stmt :=
24863 'INSERT INTO msc_item_substitutes'
24864 ||'( PLAN_ID,'
24865 ||' HIGHER_ITEM_ID,'
24866 ||' LOWER_ITEM_ID,'
24867 ||' RECIPROCAL_FLAG,'
24868 ||' SUBSTITUTION_SET,'
24869 ||' CUSTOMER_ID,'
24870 ||' CUSTOMER_SITE_ID,'
24871 ||' EFFECTIVE_DATE,'
24872 ||' DISABLE_DATE,'
24873 ||' RELATIONSHIP_TYPE,'
24874 ||' PARTIAL_FULFILLMENT_FLAG,'
24875 ||' SR_INSTANCE_ID,'
24876 ||' LAST_UPDATE_DATE,'
24877 ||' LAST_UPDATED_BY,'
24878 ||' LAST_UPDATE_LOGIN,'
24879 ||' CREATION_DATE,'
24880 ||' CREATED_BY)'
24881 ||' SELECT'
24882 ||' -1,'
24883 ||' HIGHER_ITEM_ID,'
24884 ||' LOWER_ITEM_ID,'
24885 ||' RECIPROCAL_FLAG,'
24886 ||' SUBSTITUTION_SET,'
24887 ||' CUSTOMER_ID,'
24888 ||' CUSTOMER_SITE_ID,'
24889 ||' EFFECTIVE_DATE,'
24890 ||' DISABLE_DATE,'
24891 ||' RELATIONSHIP_TYPE,'
24892 ||' PARTIAL_FULFILLMENT_FLAG,'
24893 ||' SR_INSTANCE_ID,'
24894 ||' LAST_UPDATE_DATE,'
24895 ||' LAST_UPDATED_BY,'
24896 ||' LAST_UPDATE_LOGIN,'
24897 ||' CREATION_DATE,'
24898 ||' CREATED_BY '
24899 ||' FROM msc_st_item_substitutes'
24900 ||' WHERE sr_instance_code = :sr_instance_code'
24901 ||' AND batch_id = :lv_batch_id'
24902 ||' AND process_flag = '||G_VALID;
24903
24904
24905 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
24906
24907 EXECUTE IMMEDIATE lv_sql_stmt
24908 USING v_instance_code,
24909 lv_batch_id;
24910
24911 */
24912
24913 COMMIT;
24914 END LOOP;
24915
24916 EXCEPTION
24917
24918 WHEN too_many_rows THEN
24919 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_ITEM_SUBSTITUTES'||'('
24920 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
24921 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
24922 ROLLBACK;
24923
24924 WHEN ex_logging_err THEN
24925 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
24926 ROLLBACK;
24927
24928 WHEN OTHERS THEN
24929 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_ITEM_SUBSTITUTES'||'('
24930 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
24931 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
24932 ROLLBACK;
24933
24934 END LOAD_ITEM_SUBSTITUTES;
24935
24936
24937 /*==========================================================================+
24938 | DESCRIPTION : This procedure validates the data in MSC_ST_ITEM_SUPPLIERS,|
24939 | MSC_ST_SUPPLIER_CAPACITIES and MSC_ST_SUPPLIER_FLEX_FENCES |
24940 | table. |
24941 +==========================================================================*/
24942 PROCEDURE LOAD_SUPP_CAPACITY IS
24943 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
24944 lb_rowid RowidTab;
24945 lv_error_text VARCHAR2(250);
24946 lv_column_names VARCHAR2(5000);--stores concatenated column names
24947 lv_where_str VARCHAR2(5000);
24948 lv_sql_stmt VARCHAR2(5000);
24949 lv_return NUMBER;
24950 lv_batch_id msc_st_item_suppliers.batch_id%TYPE;
24951 lv_message_text msc_errors.error_text%TYPE;
24952
24953 ex_logging_err EXCEPTION;
24954
24955
24956 CURSOR c1(p_batch_id NUMBER) IS
24957 SELECT rowid
24958 FROM msc_st_item_suppliers
24959 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
24960 AND sr_instance_code = v_instance_code
24961 AND batch_id = p_batch_id;
24962
24963 CURSOR c2(p_batch_id NUMBER) IS
24964 SELECT rowid
24965 FROM msc_st_supplier_capacities
24966 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
24967 AND sr_instance_code = v_instance_code
24968 AND batch_id = p_batch_id;
24969
24970 CURSOR c3(p_batch_id NUMBER) IS
24971 SELECT rowid
24972 FROM msc_st_supplier_flex_fences
24973 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
24974 AND sr_instance_code = v_instance_code
24975 AND batch_id = p_batch_id;
24976
24977 BEGIN
24978
24979 --For local ASL's the organization code and the using organization code
24980 --will be one and the same
24981
24982 v_sql_stmt := 00;
24983
24984 lv_sql_stmt :=
24985 'UPDATE msc_st_item_suppliers '
24986 ||' SET using_organization_code = organization_code'
24987 ||' WHERE asl_level = 2'
24988 ||' AND process_flag = '||G_IN_PROCESS
24989 ||' AND sr_instance_code = :v_instance_code';
24990
24991
24992 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
24993
24994 EXECUTE IMMEDIATE lv_sql_stmt
24995 USING v_instance_code;
24996
24997
24998 --Validation check fot the table MSC_ST_ITEM_SUPPLIERS.
24999 --Duplicate records check for the records whose source is XML
25000
25001 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
25002 (p_app_short_name => 'MSC',
25003 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
25004 p_message_text => lv_message_text,
25005 p_error_text => lv_error_text);
25006
25007 IF lv_return <> 0 THEN
25008 RAISE ex_logging_err;
25009 END IF;
25010
25011 v_sql_stmt := 01;
25012 lv_sql_stmt :=
25013 'UPDATE msc_st_item_suppliers mis1 '
25014 ||' SET process_flag = '||G_ERROR_FLG||','
25015 ||' error_text = '||''''||lv_message_text||''''
25016 ||' WHERE message_id < (SELECT MAX(message_id) '
25017 ||' FROM msc_st_item_suppliers mis2 '
25018 ||' WHERE mis2.sr_instance_code = mis1.sr_instance_code'
25019 ||' AND mis2.vendor_name = mis1.vendor_name'
25020 ||' AND mis2.organization_code = mis1.organization_code'
25021 ||' AND mis2.vendor_site_code = mis1.vendor_site_code'
25022 ||' AND mis2.item_name = mis1.item_name'
25023 ||' AND NVL(mis2.company_name, '||''''||NULL_CHAR||''''||') = '
25024 ||' NVL(mis1.company_name, '||''''||NULL_CHAR||''''||')'
25025 ||' AND NVL(mis2.using_organization_code, '||''''||NULL_CHAR||''''||') = '
25026 ||' NVL(mis1.using_organization_code, '||''''||NULL_CHAR||''''||')'
25027 ||' AND mis2.process_flag = '||G_IN_PROCESS
25028 ||' AND mis2.sr_instance_code = mis1.sr_instance_code'
25029 ||' AND NVL(mis2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
25030 ||' AND mis1.process_flag ='||G_IN_PROCESS
25031 ||' AND mis1.sr_instance_code = :v_instance_code'
25032 ||' AND NVL(mis1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
25033
25034
25035 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
25036
25037 EXECUTE IMMEDIATE lv_sql_stmt
25038 USING v_instance_code;
25039
25040 --Duplicate records check for the records whose source is other than XML
25041 --Different SQL is used because in XML we can identify the latest records
25042 --whereas in batch load we cannot.
25043
25044 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
25045 (p_app_short_name => 'MSC',
25046 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
25047 p_message_text => lv_message_text,
25048 p_error_text => lv_error_text);
25049
25050 IF lv_return <> 0 THEN
25051 RAISE ex_logging_err;
25052 END IF;
25053
25054 v_sql_stmt := 02;
25055 lv_sql_stmt :=
25056 'UPDATE msc_st_item_suppliers mis1 '
25057 ||' SET process_flag = '||G_ERROR_FLG||','
25058 ||' error_text = '||''''||lv_message_text||''''
25059 ||' WHERE EXISTS( SELECT 1 '
25060 ||' FROM msc_st_item_suppliers mis2'
25061 ||' WHERE mis2.sr_instance_code = mis1.sr_instance_code'
25062 ||' AND mis2.vendor_name = mis1.vendor_name'
25063 ||' AND mis2.organization_code = mis1.organization_code'
25064 ||' AND mis2.vendor_site_code = mis1.vendor_site_code'
25065 ||' AND mis2.item_name = mis1.item_name'
25066 ||' AND NVL(mis2.company_name, '||''''||NULL_CHAR||''''||') = '
25067 ||' NVL(mis1.company_name, '||''''||NULL_CHAR||''''||')'
25068 ||' AND NVL(mis2.using_organization_code, '||''''||NULL_CHAR||''''||') = '
25069 ||' NVL(mis1.using_organization_code, '||''''||NULL_CHAR||''''||')'
25070 ||' AND mis2.process_flag = '||G_IN_PROCESS
25071 ||' AND mis2.sr_instance_code = mis1.sr_instance_code'
25072 ||' AND NVL(mis2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
25073 ||' GROUP BY sr_instance_code,organization_code,company_name,'
25074 ||' item_name,vendor_name,vendor_site_code,using_organization_code'
25075 ||' HAVING COUNT(*) > 1)'
25076 ||' AND mis1.process_flag = '||G_IN_PROCESS
25077 ||' AND mis1.sr_instance_code = :v_instance_code'
25078 ||' AND NVL(mis1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
25079
25080
25081
25082 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
25083
25084 EXECUTE IMMEDIATE lv_sql_stmt
25085 USING v_instance_code;
25086
25087 lv_column_names :=
25088 'ITEM_NAME ||''~''||'
25089 ||'ORGANIZATION_CODE ||''~''||'
25090 ||'VENDOR_NAME ||''~''||'
25091 ||'SR_INSTANCE_CODE ||''~''||'
25092 ||'PROCESSING_LEAD_TIME ||''~''||'
25093 ||'MINIMUM_ORDER_QUANTITY ||''~''||'
25094 ||'FIXED_LOT_MULTIPLE ||''~''||'
25095 ||'DELIVERY_CALENDAR_CODE ||''~''||'
25096 ||'VENDOR_SITE_CODE ||''~''||'
25097 ||'SUPPLIER_CAP_OVER_UTIL_COST ||''~''||'
25098 ||'COMPANY_NAME ||''~''||'
25099 ||'PURCHASING_UNIT_OF_MEASURE ||''~''||'
25100 ||'USING_ORGANIZATION_ID ||''~''||'
25101 ||'DELETED_FLAG';
25102
25103 LOOP
25104 v_sql_stmt := 03;
25105 SELECT msc_st_batch_id_s.NEXTVAL
25106 INTO lv_batch_id
25107 FROM dual;
25108
25109 v_sql_stmt := 04;
25110 lv_sql_stmt :=
25111 'UPDATE msc_st_item_suppliers '
25112 ||' SET batch_id = :lv_batch_id'
25113 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
25114 ||' AND sr_instance_code = :v_instance_code'
25115 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
25116 ||' AND rownum <= '||v_batch_size;
25117
25118
25119 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
25120
25121 EXECUTE IMMEDIATE lv_sql_stmt
25122 USING lv_batch_id,
25123 v_instance_code;
25124
25125 EXIT WHEN SQL%NOTFOUND;
25126
25127 OPEN c1(lv_batch_id);
25128 FETCH c1 BULK COLLECT INTO lb_rowid;
25129 CLOSE c1;
25130
25131 v_sql_stmt := 05;
25132 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
25133 UPDATE msc_st_item_suppliers
25134 SET st_transaction_id = msc_st_item_suppliers_s.NEXTVAL,
25135 last_update_date = v_current_date,
25136 last_updated_by = v_current_user,
25137 creation_date = v_current_date,
25138 created_by = v_current_user
25139 WHERE rowid = lb_rowid(j);
25140
25141 --Deletion is not allowed on this table.
25142
25143 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
25144 (p_app_short_name => 'MSC',
25145 p_error_code => 'MSC_PP_NO_DELETION',
25146 p_message_text => lv_message_text,
25147 p_error_text => lv_error_text,
25148 p_token1 => 'TABLE_NAME',
25149 p_token_value1 => 'MSC_ST_ITEM_SUPPLIERS');
25150
25151 IF lv_return <> 0 THEN
25152 RAISE ex_logging_err;
25153 END IF;
25154
25155 v_sql_stmt := 06;
25156 lv_sql_stmt :=
25157 'UPDATE msc_st_item_suppliers '
25158 ||' SET process_flag = '||G_ERROR_FLG||','
25159 ||' error_text = '||''''||lv_message_text||''''
25160 ||' WHERE deleted_flag = '||SYS_YES
25161 ||' AND process_flag = '||G_IN_PROCESS
25162 ||' AND batch_id = :lv_batch_id'
25163 ||' AND sr_instance_code = :v_instance_code';
25164
25165
25166 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
25167
25168 EXECUTE IMMEDIATE lv_sql_stmt
25169 USING lv_batch_id,
25170 v_instance_code;
25171
25172 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
25173 (p_app_short_name => 'MSC',
25174 p_error_code => 'MSC_PP_INVALID_VALUE',
25175 p_message_text => lv_message_text,
25176 p_error_text => lv_error_text,
25177 p_token1 => 'COLUMN_NAME',
25178 p_token_value1 => 'ASL_LEVEL');
25179
25180 IF lv_return <> 0 THEN
25181 RAISE ex_logging_err;
25182 END IF;
25183
25184 v_sql_stmt := 06;
25185
25186 lv_sql_stmt :=
25187 'UPDATE msc_st_item_suppliers '
25188 ||' SET process_flag = '||G_ERROR_FLG||','
25189 ||' error_text = '||''''||lv_message_text||''''
25190 ||' WHERE asl_level not in(1,2)'
25191 ||' AND process_flag = '||G_IN_PROCESS
25192 ||' AND batch_id = :lv_batch_id'
25193 ||' AND sr_instance_code = :v_instance_code';
25194
25195
25196 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
25197
25198 EXECUTE IMMEDIATE lv_sql_stmt
25199 USING lv_batch_id,
25200 v_instance_code;
25201
25202
25203 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
25204 (p_app_short_name => 'MSC',
25205 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
25206 p_message_text => lv_message_text,
25207 p_error_text => lv_error_text,
25208 p_token1 => 'COLUMN_NAMES',
25209 p_token_value1 => 'SR_INSTANCE_CODE OR'
25210 ||' PURCHASING_UNIT_OF_MEASURE',
25211 p_token2 => 'MASTER_TABLE',
25212 p_token_value2 => 'MSC_ST_UNITS_OF_MEASURE',
25213 p_token3 => 'CHILD_TABLE',
25214 p_token_value3 => 'MSC_ST_ITEM_SUPPLIERS');
25215
25216 IF lv_return <> 0 THEN
25217 RAISE ex_logging_err;
25218 END IF;
25219
25220 -- Validate all UOM code.
25221 v_sql_stmt := 07;
25222 lv_sql_stmt :=
25223 'UPDATE msc_st_item_suppliers mstp'
25224 ||' SET process_flag = '||G_ERROR_FLG||','
25225 ||' error_text = '||''''||lv_message_text||''''
25226 ||' WHERE NOT EXISTS(SELECT 1 '
25227 ||' FROM msc_units_of_measure muom '
25228 ||' WHERE NVL(muom.unit_of_measure, '||''''||NULL_CHAR||''''||') = '
25229 ||' NVL(mstp.purchasing_unit_of_measure,'||''''||NULL_CHAR||''''||')'
25230 ||' UNION '
25231 ||' SELECT 1 FROM msc_st_units_of_measure msuom'
25232 ||' WHERE NVL(msuom.unit_of_measure, '||''''||NULL_CHAR||''''||') = '
25233 ||' NVL(mstp.purchasing_unit_of_measure,'||''''||NULL_CHAR||''''||')'
25234 ||' AND msuom.sr_instance_id = :v_instance_id'
25235 ||' AND msuom.process_flag = '||G_VALID||' ) '
25236 ||' AND NVL(mstp.purchasing_unit_of_measure, '||''''||NULL_CHAR||''''||')'
25237 ||' <> '||''''||NULL_CHAR||''''
25238 ||' AND mstp.sr_instance_code = :v_instance_code'
25239 ||' AND mstp.batch_id = :lv_batch_id'
25240 ||' AND mstp.process_flag = '||G_IN_PROCESS ;
25241
25242
25243
25244 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
25245
25246 EXECUTE IMMEDIATE lv_sql_stmt
25247 USING v_instance_id,
25248 v_instance_code,
25249 lv_batch_id;
25250
25251 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
25252 (p_app_short_name => 'MSC',
25253 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
25254 p_message_text => lv_message_text,
25255 p_error_text => lv_error_text,
25256 p_token1 => 'COLUMN_NAME',
25257 p_token_value1 => 'DELETED_FLAG',
25258 p_token2 => 'DEFAULT_VALUE',
25259 p_token_value2 => SYS_NO);
25260
25261 IF lv_return <> 0 THEN
25262 RAISE ex_logging_err;
25263 END IF;
25264
25265 lv_where_str :=
25266 ' AND NVL(deleted_flag,'||NULL_VALUE||') '
25267 ||' NOT IN(1,2)';
25268 --Log a warning for those records where the deleted_flag has a value other
25269 --than SYS_NO
25270
25271 lv_return := MSC_ST_UTIL.LOG_ERROR
25272 (p_table_name => 'MSC_ST_ITEM_SUPPLIERS',
25273 p_instance_code => v_instance_code,
25274 p_row => lv_column_names,
25275 p_severity => G_SEV_WARNING,
25276 p_message_text => lv_message_text,
25277 p_error_text => lv_error_text,
25278 p_batch_id => lv_batch_id,
25279 p_where_str => lv_where_str,
25280 p_col_name => 'DELETED_FLAG',
25281 p_debug => v_debug,
25282 p_default_value => SYS_NO);
25283
25284 IF lv_return <> 0 THEN
25285 RAISE ex_logging_err;
25286 END IF;
25287
25288 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
25289 (p_app_short_name => 'MSC',
25290 p_error_code => 'MSC_PP_INVALID_VALUE',
25291 p_message_text => lv_message_text,
25292 p_error_text => lv_error_text,
25293 p_token1 => 'COLUMN_NAME',
25294 p_token_value1 => 'ORGANIZATION_CODE');
25295
25296 IF lv_return <> 0 THEN
25297 RAISE ex_logging_err;
25298 END IF;
25299
25300 --Derive Organization_id
25301 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
25302 (p_table_name => 'MSC_ST_ITEM_SUPPLIERS',
25303 p_org_partner_name => 'ORGANIZATION_CODE',
25304 p_org_partner_id => 'ORGANIZATION_ID',
25305 p_instance_code => v_instance_code,
25306 p_partner_type => G_ORGANIZATION,
25307 p_error_text => lv_error_text,
25308 p_batch_id => lv_batch_id,
25309 p_severity => G_SEV_ERROR,
25310 p_message_text => lv_message_text,
25311 p_debug => v_debug,
25312 p_row => lv_column_names);
25313
25314 IF lv_return <> 0 THEN
25315 RAISE ex_logging_err;
25316 END IF;
25317
25318 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
25319 (p_app_short_name => 'MSC',
25320 p_error_code => 'MSC_PP_INVALID_VALUE',
25321 p_message_text => lv_message_text,
25322 p_error_text => lv_error_text,
25323 p_token1 => 'COLUMN_NAME',
25324 p_token_value1 => 'ITEM_NAME');
25325
25326 --Derive Inventory_item_id
25327 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
25328 (p_table_name => 'MSC_ST_ITEM_SUPPLIERS',
25329 p_item_col_name => 'ITEM_NAME',
25330 p_item_col_id => 'INVENTORY_ITEM_ID',
25331 p_instance_id => v_instance_id,
25332 p_instance_code => v_instance_code,
25333 p_error_text => lv_error_text,
25334 p_batch_id => lv_batch_id,
25335 p_severity => G_SEV_ERROR,
25336 p_message_text => lv_message_text,
25337 p_debug => v_debug,
25338 p_row => lv_column_names);
25339
25340 IF lv_return <> 0 THEN
25341 RAISE ex_logging_err;
25342 END IF;
25343
25344 --Derive Supplier_id
25345 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
25346 (p_app_short_name => 'MSC',
25347 p_error_code => 'MSC_PP_INVALID_VALUE',
25348 p_message_text => lv_message_text,
25349 p_error_text => lv_error_text,
25350 p_token1 => 'COLUMN_NAME',
25351 p_token_value1 => 'VENDOR_NAME');
25352
25353 IF lv_return <> 0 THEN
25354 RAISE ex_logging_err;
25355 END IF;
25356
25357 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
25358 (p_table_name => 'MSC_ST_ITEM_SUPPLIERS',
25359 p_org_partner_name => 'VENDOR_NAME',
25360 p_org_partner_id => 'SUPPLIER_ID',
25361 p_instance_code => v_instance_code,
25362 p_partner_type => G_VENDOR,
25363 p_error_text => lv_error_text,
25364 p_batch_id => lv_batch_id,
25365 p_severity => G_SEV_ERROR,
25366 p_message_text => lv_message_text,
25367 p_debug => v_debug,
25368 p_row => lv_column_names);
25369
25370 IF lv_return <> 0 THEN
25371 RAISE ex_logging_err;
25372 END IF;
25373
25374 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
25375 (p_app_short_name => 'MSC',
25376 p_error_code => 'MSC_PP_INVALID_VALUE',
25377 p_message_text => lv_message_text,
25378 p_error_text => lv_error_text,
25379 p_token1 => 'COLUMN_NAME',
25380 p_token_value1 => 'VENDOR_SITE_CODE');
25381
25382 IF lv_return <> 0 THEN
25383 RAISE ex_logging_err;
25384 END IF;
25385
25386 --Derive Supplier_site_id
25387 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
25388 (p_table_name => 'MSC_ST_ITEM_SUPPLIERS',
25389 p_partner_name => 'VENDOR_NAME',
25390 p_partner_site_code => 'VENDOR_SITE_CODE',
25391 p_partner_site_id => 'SUPPLIER_SITE_ID',
25392 p_instance_code => v_instance_code,
25393 p_partner_type => G_VENDOR,
25394 p_error_text => lv_error_text,
25395 p_batch_id => lv_batch_id,
25396 p_severity => G_SEV3_ERROR,
25397 p_message_text => lv_message_text,
25398 p_debug => v_debug,
25399 p_row => lv_column_names);
25400
25401 IF lv_return <> 0 THEN
25402 RAISE ex_logging_err;
25403 END IF;
25404 /* Bug 2172537
25405 -- Update all calendar_code as instance_code concatenated with name
25406 v_sql_stmt := 12;
25407 lv_sql_stmt :=
25408 'UPDATE msc_st_item_suppliers '
25409 ||' SET delivery_calendar_code = sr_instance_code'||'||'':''||'||'delivery_calendar_code'
25410 ||' WHERE delivery_calendar_code IS NOT NULL'
25411 ||' AND sr_instance_code = :v_instance_code'
25412 ||' AND batch_id = :lv_batch_id'
25413 ||' AND process_flag = '||G_IN_PROCESS;
25414
25415
25416 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
25417 EXECUTE IMMEDIATE lv_sql_stmt
25418 USING v_instance_code,
25419 lv_batch_id; */
25420
25421
25422 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
25423 (p_app_short_name => 'MSC',
25424 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
25425 p_message_text => lv_message_text,
25426 p_error_text => lv_error_text,
25427 p_token1 => 'COLUMN_NAMES',
25428 p_token_value1 => 'SR_INSTANCE_ID AND CALENDAR_CODE',
25429 p_token2 => 'MASTER_TABLE',
25430 p_token_value2 => 'MSC_CALENDARS',
25431 p_token3 => 'CHILD_TABLE',
25432 p_token_value3 => 'MSC_ST_ITEM_SUPPLIERS');
25433 IF lv_return <> 0 THEN
25434 RAISE ex_logging_err;
25435 END IF;
25436
25437 -- Validate the calendar code for org
25438 v_sql_stmt := 14;
25439 lv_sql_stmt :=
25440 'UPDATE msc_st_item_suppliers mis'
25441 ||' SET process_flag = '||G_ERROR_FLG||','
25442 ||' error_text = '||''''||lv_message_text||''''
25443 ||' WHERE NOT EXISTS ( SELECT 1 '
25444 ||' FROM msc_calendars mc '
25445 ||' WHERE mc.calendar_code = mis.delivery_calendar_code '
25446 ||' AND mc.sr_instance_id = :v_instance_id )'
25447 ||' AND delivery_calendar_code IS NOT NULL '
25448 ||' AND sr_instance_code = :v_instance_code'
25449 ||' AND batch_id = :lv_batch_id'
25450 ||' AND process_flag = '||G_IN_PROCESS;
25451
25452
25453 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
25454
25455 EXECUTE IMMEDIATE lv_sql_stmt
25456 USING v_instance_id,
25457 v_instance_code,
25458 lv_batch_id;
25459
25460 --Setting using_organization_id to the default value -1 which is for the
25461 --globally valid supplier rules and to organization_id for the local ASL's.
25462 --Value of sr_instance_id2 should be same as sr_instance_id, Since, we are
25463 --always considering using_organization_id =-1.
25464
25465
25466 v_sql_stmt := 08;
25467
25468 lv_sql_stmt :=
25469 'UPDATE msc_st_item_suppliers mis '
25470 ||' SET using_organization_id = decode(asl_level,1,'||G_USING_ORG_ID||',organization_id),'
25471 ||' sr_instance_id2 = :v_instance_id'
25472 ||' WHERE sr_instance_code = :v_instance_code'
25473 ||' AND batch_id = :lv_batch_id'
25474 ||' AND process_flag = '||G_IN_PROCESS;
25475
25476
25477 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
25478
25479 EXECUTE IMMEDIATE lv_sql_stmt
25480 USING v_instance_id,
25481 v_instance_code,
25482 lv_batch_id;
25483
25484 -- validation for REPLENISHMENT_METHOD
25485 -- Set the error message
25486 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
25487 (p_app_short_name => 'MSC',
25488 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
25489 p_message_text => lv_message_text,
25490 p_error_text => lv_error_text,
25491 p_token1 => 'COLUMN_NAME',
25492 p_token_value1 => 'REPLENISHMENT_METHOD',
25493 p_token2 => 'DEFAULT_VALUE',
25494 p_token_value2 => 1 );
25495
25496 IF lv_return <> 0 THEN
25497 RAISE ex_logging_err;
25498 END IF;
25499
25500 -- Check whether REPLENISHMENT_METHOD value is in (1,2,3,4),if not default to 1 - MIN-MAX - QUANTITIES
25501
25502 lv_where_str :=
25503 ' AND NVL(REPLENISHMENT_METHOD,'||NULL_VALUE||') NOT IN(1,2,3,4)';
25504
25505 lv_return := MSC_ST_UTIL.LOG_ERROR
25506 (p_table_name => 'MSC_ST_ITEM_SUPPLIERS',
25507 p_instance_code => v_instance_code,
25508 p_row => lv_column_names,
25509 p_severity => G_SEV_WARNING,
25510 p_message_text => lv_message_text,
25511 p_error_text => lv_error_text,
25512 p_batch_id => lv_batch_id,
25513 p_where_str => lv_where_str,
25514 p_col_name => 'REPLENISHMENT_METHOD',
25515 p_debug => v_debug,
25516 p_default_value => 1);
25517
25518 IF lv_return <> 0 THEN
25519 RAISE ex_logging_err;
25520 END IF;
25521
25522
25523
25524 --Call to customised validation.
25525 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
25526 (ERRBUF => lv_error_text,
25527 RETCODE => lv_return,
25528 pBatchID => lv_batch_id,
25529 pInstanceCode => v_instance_code,
25530 pEntityName => 'MSC_ST_ITEM_SUPPLIERS',
25531 pInstanceID => v_instance_id);
25532
25533 IF NVL(lv_return,0) <> 0 THEN
25534 RAISE ex_logging_err;
25535 END IF;
25536
25537 -- SCE Changes Starts here
25538
25539 IF v_sce_installed THEN
25540
25541 -- company_id derivation
25542 -- derive the company_id . if not found then error out record
25543
25544 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
25545 (p_app_short_name => 'MSC',
25546 p_error_code => 'MSC_PP_INVALID_VALUE',
25547 p_message_text => lv_message_text,
25548 p_error_text => lv_error_text,
25549 p_token1 => 'COLUMN_NAME',
25550 p_token_value1 => 'COMPANY_NAME');
25551
25552 IF lv_return <> 0 THEN
25553 RAISE ex_logging_err;
25554 END IF;
25555
25556 lv_return := MSC_ST_UTIL.DERIVE_COMPANY_ID
25557 (p_table_name => 'MSC_ST_ITEM_SUPPLIERS',
25558 p_company_name => 'COMPANY_NAME',
25559 p_company_id => 'COMPANY_ID',
25560 p_instance_code => v_instance_code,
25561 p_error_text => lv_error_text,
25562 p_batch_id => lv_batch_id,
25563 p_message_text => lv_message_text,
25564 p_debug => v_debug);
25565
25566 IF lv_return <> 0 THEN
25567 RAISE ex_logging_err;
25568 END IF;
25569
25570 /*
25571 lv_sql_stmt :=
25572 ' UPDATE MSC_ST_ITEM_SUPPLIERS mic '
25573 ||' SET company_id = '
25574 ||' (select company_id from msc_companies mc'
25575 ||' where mic.company_name = mc.company_name) '
25576 ||' WHERE NVL(COMPANY_NAME,''-1'') <> ''-1'''
25577 ||' AND batch_id = :lv_batch_id'
25578 ||' AND process_flag = '||G_IN_PROCESS
25579 ||' AND sr_instance_code = :v_instance_code';
25580
25581
25582 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
25583
25584 EXECUTE IMMEDIATE lv_sql_stmt
25585 USING lv_batch_id,
25586 v_instance_code;
25587
25588 lv_sql_stmt :=
25589 ' UPDATE MSC_ST_ITEM_SUPPLIERS '
25590 ||' SET process_flag = '||G_ERROR_FLG||','
25591 ||' error_text = '||''''||lv_message_text||''''
25592 ||' WHERE NVL(COMPANY_NAME,''-1'') <> ''-1'''
25593 ||' AND COMPANY_ID IS NULL '
25594 ||' AND batch_id = :lv_batch_id'
25595 ||' AND process_flag = '||G_IN_PROCESS
25596 ||' AND sr_instance_code = :v_instance_code';
25597
25598
25599 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
25600
25601 EXECUTE IMMEDIATE lv_sql_stmt
25602 USING lv_batch_id,
25603 v_instance_code;
25604 */
25605
25606 END IF; -- SCE installed
25607
25608 -- SCE Changes end here
25609
25610 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
25611 (p_table_name => 'MSC_ST_ITEM_SUPPLIERS',
25612 p_instance_id => v_instance_id,
25613 p_instance_code => v_instance_code,
25614 p_process_flag => G_VALID,
25615 p_error_text => lv_error_text,
25616 p_debug => v_debug,
25617 p_batch_id => lv_batch_id);
25618
25619 IF lv_return <> 0 THEN
25620 RAISE ex_logging_err;
25621 END IF;
25622
25623 lv_return := MSC_ST_UTIL.LOG_ERROR
25624 (p_table_name => 'MSC_ST_ITEM_SUPPLIERS',
25625 p_instance_code => v_instance_code,
25626 p_row => lv_column_names,
25627 p_severity => G_SEV_ERROR,
25628 p_message_text => NULL,
25629 p_error_text => lv_error_text,
25630 p_debug => v_debug,
25631 p_batch_id => lv_batch_id);
25632
25633 IF lv_return <> 0 THEN
25634 RAISE ex_logging_err;
25635 END IF;
25636
25637 COMMIT;
25638 END LOOP;
25639
25640 --******Validation for MSC_ST_SUPPLIER_CAPACITIES***********
25641
25642 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
25643 (p_app_short_name => 'MSC',
25644 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
25645 p_message_text => lv_message_text,
25646 p_error_text => lv_error_text);
25647
25648 IF lv_return <> 0 THEN
25649 RAISE ex_logging_err;
25650 END IF;
25651 --Duplicate records check for the records whose source is XML
25652 v_sql_stmt := 09;
25653 lv_sql_stmt :=
25654 'UPDATE msc_st_supplier_capacities msc1 '
25655 ||' SET process_flag = '||G_ERROR_FLG||','
25656 ||' error_text = '||''''||lv_message_text||''''
25657 ||' WHERE message_id < (SELECT MAX(message_id)'
25658 ||' FROM msc_st_supplier_capacities msc2'
25659 ||' WHERE msc2.sr_instance_code = msc1.sr_instance_code'
25660 ||' AND msc2.organization_code = msc1.organization_code'
25661 ||' AND msc2.vendor_name = msc1.vendor_name'
25662 ||' AND msc2.vendor_site_code = msc1.vendor_site_code'
25663 ||' AND msc2.item_name = msc1.item_name'
25664 ||' AND msc2.from_date = msc1.from_date'
25665 ||' AND NVL(msc2.company_name, '||''''||NULL_CHAR||''''||') = '
25666 ||' NVL(msc1.company_name, '||''''||NULL_CHAR||''''||')'
25667 ||' AND msc2.process_flag = '||G_IN_PROCESS
25668 ||' AND msc2.sr_instance_code = msc1.sr_instance_code'
25669 ||' AND NVL(msc2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
25670 ||' AND msc1.process_flag = '||G_IN_PROCESS
25671 ||' AND msc1.sr_instance_code = :v_instance_code'
25672 ||' AND NVL(msc1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
25673
25674
25675
25676 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
25677
25678 EXECUTE IMMEDIATE lv_sql_stmt
25679 USING v_instance_code;
25680
25681 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
25682 (p_app_short_name => 'MSC',
25683 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
25684 p_message_text => lv_message_text,
25685 p_error_text => lv_error_text);
25686
25687 IF lv_return <> 0 THEN
25688 RAISE ex_logging_err;
25689 END IF;
25690
25691 --Duplicate records check for the records whose source is other than XML
25692 --Different SQL is used because in XML we can identify the latest records
25693 --whereas in batch load we cannot.
25694
25695 v_sql_stmt := 10;
25696 lv_sql_stmt :=
25697 ' UPDATE msc_st_supplier_capacities msc1'
25698 ||' SET process_flag = '||G_ERROR_FLG||','
25699 ||' error_text = '||''''||lv_message_text||''''
25700 ||' WHERE EXISTS( SELECT 1 '
25701 ||' FROM msc_st_supplier_capacities msc2'
25702 ||' WHERE msc2.sr_instance_code = msc1.sr_instance_code'
25703 ||' AND msc2.organization_code = msc1.organization_code'
25704 ||' AND msc2.vendor_name = msc1.vendor_name'
25705 ||' AND msc2.vendor_site_code = msc1.vendor_site_code'
25706 ||' AND msc2.item_name = msc1.item_name'
25707 ||' AND msc2.from_date = msc1.from_date'
25708 ||' AND NVL(msc2.company_name, '||''''||NULL_CHAR||''''||') = '
25709 ||' NVL(msc1.company_name, '||''''||NULL_CHAR||''''||')'
25710 ||' AND msc2.process_flag = '||G_IN_PROCESS
25711 ||' AND NVL(msc2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
25712 ||' GROUP BY sr_instance_code,organization_code,company_name,'
25713 ||' item_name,vendor_name,vendor_site_code,from_date'
25714 ||' HAVING COUNT(*) > 1)'
25715 ||' AND msc1.process_flag = '||G_IN_PROCESS
25716 ||' AND msc1.sr_instance_code = :v_instance_code'
25717 ||' AND NVL(msc1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
25718
25719
25720 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
25721
25722 EXECUTE IMMEDIATE lv_sql_stmt
25723 USING v_instance_code;
25724
25725 lv_column_names :=
25726 'ORGANIZATION_CODE ||''~''||'
25727 ||'ITEM_NAME ||''~''||'
25728 ||'VENDOR_NAME ||''~''||'
25729 ||'FROM_DATE ||''~''||'
25730 ||'CAPACITY ||''~''||'
25731 ||'SR_INSTANCE_CODE ||''~''||'
25732 ||'VENDOR_SITE_CODE ||''~''||'
25733 ||'TO_DATE ||''~''||'
25734 ||'DELETED_FLAG ||''~''||'
25735 ||'COMPANY_NAME ||''~''||'
25736 ||'USING_ORGANIZATION_ID';
25737
25738 LOOP
25739 v_sql_stmt := 11;
25740 SELECT msc_st_batch_id_s.NEXTVAL
25741 INTO lv_batch_id
25742 FROM dual;
25743
25744 v_sql_stmt := 12;
25745 lv_sql_stmt :=
25746 'UPDATE msc_st_supplier_capacities '
25747 ||' SET batch_id = :lv_batch_id'
25748 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
25749 ||' AND sr_instance_code = :v_instance_code'
25750 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
25751 ||' AND rownum <= '||v_batch_size;
25752
25753
25754 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
25755
25756 EXECUTE IMMEDIATE lv_sql_stmt
25757 USING lv_batch_id,
25758 v_instance_code;
25759
25760 EXIT WHEN SQL%NOTFOUND;
25761
25762 OPEN c2(lv_batch_id);
25763 FETCH c2 BULK COLLECT INTO lb_rowid;
25764 CLOSE c2;
25765
25766 v_sql_stmt := 13;
25767 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
25768 UPDATE msc_st_supplier_capacities
25769 SET st_transaction_id = msc_st_supplier_capacities_s.NEXTVAL,
25770 refresh_id = v_refresh_id,
25771 last_update_date = v_current_date,
25772 last_updated_by = v_current_user,
25773 creation_date = v_current_date,
25774 created_by = v_current_user
25775 WHERE rowid = lb_rowid(j);
25776
25777
25778 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
25779 (p_app_short_name => 'MSC',
25780 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
25781 p_message_text => lv_message_text,
25782 p_error_text => lv_error_text,
25783 p_token1 => 'COLUMN_NAME',
25784 p_token_value1 => 'DELETED_FLAG',
25785 p_token2 => 'DEFAULT_VALUE',
25786 p_token_value2 => SYS_NO);
25787
25788 IF lv_return <> 0 THEN
25789 RAISE ex_logging_err;
25790 END IF;
25791
25792 lv_where_str :=
25793 ' AND NVL(deleted_flag,'||NULL_VALUE||') '
25794 ||' NOT IN(1,2)';
25795 --Log a warning for those records where the deleted_flag has a value other
25796 --than SYS_NO
25797 lv_return := MSC_ST_UTIL.LOG_ERROR
25798 (p_table_name => 'MSC_ST_SUPPLIER_CAPACITIES',
25799 p_instance_code => v_instance_code,
25800 p_row => lv_column_names,
25801 p_severity => G_SEV_WARNING,
25802 p_message_text => lv_message_text,
25803 p_error_text => lv_error_text,
25804 p_batch_id => lv_batch_id,
25805 p_where_str => lv_where_str,
25806 p_col_name => 'DELETED_FLAG',
25807 p_debug => v_debug,
25808 p_default_value => SYS_NO);
25809
25810 IF lv_return <> 0 THEN
25811 RAISE ex_logging_err;
25812 END IF;
25813
25814 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
25815 (p_app_short_name => 'MSC',
25816 p_error_code => 'MSC_PP_INVALID_VALUE',
25817 p_message_text => lv_message_text,
25818 p_error_text => lv_error_text,
25819 p_token1 => 'COLUMN_NAME',
25820 p_token_value1 => 'ORGANIZATION_CODE');
25821
25822 --Derive Organization_id
25823 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
25824 (p_table_name => 'MSC_ST_SUPPLIER_CAPACITIES',
25825 p_org_partner_name => 'ORGANIZATION_CODE',
25826 p_org_partner_id => 'ORGANIZATION_ID',
25827 p_instance_code => v_instance_code,
25828 p_partner_type => G_ORGANIZATION,
25829 p_error_text => lv_error_text,
25830 p_batch_id => lv_batch_id,
25831 p_severity => G_SEV_ERROR,
25832 p_message_text => lv_message_text,
25833 p_debug => v_debug,
25834 p_row => lv_column_names);
25835
25836 IF lv_return <> 0 THEN
25837 RAISE ex_logging_err;
25838 END IF;
25839
25840 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
25841 (p_app_short_name => 'MSC',
25842 p_error_code => 'MSC_PP_INVALID_VALUE',
25843 p_message_text => lv_message_text,
25844 p_error_text => lv_error_text,
25845 p_token1 => 'COLUMN_NAME',
25846 p_token_value1 => 'ITEM_NAME');
25847
25848 IF lv_return <> 0 THEN
25849 RAISE ex_logging_err;
25850 END IF;
25851
25852 --Derive Inventory_item_id
25853 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
25854 (p_table_name => 'MSC_ST_SUPPLIER_CAPACITIES',
25855 p_item_col_name => 'ITEM_NAME',
25856 p_item_col_id => 'INVENTORY_ITEM_ID',
25857 p_instance_id => v_instance_id,
25858 p_instance_code => v_instance_code,
25859 p_error_text => lv_error_text,
25860 p_batch_id => lv_batch_id,
25861 p_severity => G_SEV_ERROR,
25862 p_message_text => lv_message_text,
25863 p_debug => v_debug,
25864 p_row => lv_column_names);
25865
25866 IF lv_return <> 0 THEN
25867 RAISE ex_logging_err;
25868 END IF;
25869
25870 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
25871 (p_app_short_name => 'MSC',
25872 p_error_code => 'MSC_PP_INVALID_VALUE',
25873 p_message_text => lv_message_text,
25874 p_error_text => lv_error_text,
25875 p_token1 => 'COLUMN_NAME',
25876 p_token_value1 => 'VENDOR_NAME');
25877
25878 IF lv_return <> 0 THEN
25879 RAISE ex_logging_err;
25880 END IF;
25881
25882 --Derive Supplier_id
25883 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
25884 (p_table_name => 'MSC_ST_SUPPLIER_CAPACITIES',
25885 p_org_partner_name => 'VENDOR_NAME',
25886 p_org_partner_id => 'SUPPLIER_ID',
25887 p_instance_code => v_instance_code,
25888 p_partner_type => G_VENDOR,
25889 p_error_text => lv_error_text,
25890 p_batch_id => lv_batch_id,
25891 p_severity => G_SEV_ERROR,
25892 p_message_text => lv_message_text,
25893 p_debug => v_debug,
25894 p_row => lv_column_names);
25895
25896 IF lv_return <> 0 THEN
25897 RAISE ex_logging_err;
25898 END IF;
25899
25900 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
25901 (p_app_short_name => 'MSC',
25902 p_error_code => 'MSC_PP_INVALID_VALUE',
25903 p_message_text => lv_message_text,
25904 p_error_text => lv_error_text,
25905 p_token1 => 'COLUMN_NAME',
25906 p_token_value1 => 'VENDOR_SITE_CODE');
25907
25908 IF lv_return <> 0 THEN
25909 RAISE ex_logging_err;
25910 END IF;
25911
25912 --Derive Supplier_site_id
25913 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
25914 (p_table_name => 'MSC_ST_SUPPLIER_CAPACITIES',
25915 p_partner_name => 'VENDOR_NAME',
25916 p_partner_site_code => 'VENDOR_SITE_CODE',
25917 p_partner_site_id => 'SUPPLIER_SITE_ID',
25918 p_instance_code => v_instance_code,
25919 p_partner_type => G_VENDOR,
25920 p_error_text => lv_error_text,
25921 p_batch_id => lv_batch_id,
25922 p_severity => G_SEV_ERROR,
25923 p_message_text => lv_message_text,
25924 p_debug => v_debug,
25925 p_row => lv_column_names);
25926
25927 IF lv_return <> 0 THEN
25928 RAISE ex_logging_err;
25929 END IF;
25930
25931
25932 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
25933 (p_app_short_name => 'MSC',
25934 p_error_code => 'MSC_PP_SUPP_NOT_EXIST',
25935 p_message_text => lv_message_text,
25936 p_error_text => lv_error_text,
25937 p_token1 => 'COLUMN_NAMES',
25938 p_token_value1 => 'SR_INSTANCE_CODE, COMPANY_NAME, ORGANIZATION_CODE,'
25939 ||' ITEM_NAME, VENDOR_NAME AND VENDOR_SITE_CODE',
25940 p_token2 => 'MASTER_TABLE',
25941 p_token_value2 => 'MSC_ST_ITEM_SUPPLIERS',
25942 p_token3 => 'CHILD_TABLE',
25943 p_token_value3 => 'MSC_ST_SUPPLIER_CAPACITIES',
25944 p_token4 => 'VALUE',
25945 p_token_value4 => 'ASL_LEVEL = 1');
25946 IF lv_return <> 0 THEN
25947 RAISE ex_logging_err;
25948 END IF;
25949
25950 --Checking for the referential integrity.
25951 v_sql_stmt := 14;
25952 lv_sql_stmt :=
25953 'UPDATE msc_st_supplier_capacities mis1 '
25954 ||' SET error_text = '||''''||lv_message_text||''''||','
25955 ||' process_flag = '||G_ERROR_FLG
25956 ||' WHERE NOT EXISTS(SELECT 1'
25957 ||' FROM msc_item_suppliers mis2, MSC_TP_ID_LID mtil, MSC_TP_SITE_ID_LID mtsil, MSC_ITEM_ID_LID mil'
25958 ||' WHERE mtil.SR_TP_ID = mis1.supplier_id'
25959 ||' AND mtil.TP_ID = mis2.supplier_id'
25960 ||' AND mtil.sr_instance_id = mis2.sr_instance_id'
25961 ||' AND mtil.PARTNER_TYPE = 1'
25962 ||' AND mtsil.SR_TP_SITE_ID = mis1.supplier_site_id'
25963 ||' AND mtsil.TP_SITE_ID = mis2.supplier_site_id'
25964 ||' AND mtsil.sr_instance_id = mis2.sr_instance_id'
25965 ||' AND mtsil.partner_type = 1'
25966 ||' AND mil.sr_inventory_item_id = mis1.inventory_item_id'
25967 ||' AND mil.inventory_item_id = mis2.inventory_item_id'
25968 ||' AND mil.sr_instance_id = mis2.sr_instance_id'
25969 ||' AND mis2.sr_instance_id = :v_instance_id'
25970 ||' AND mis2.organization_id = mis1.organization_id'
25971 ||' AND mis2.using_organization_id = -1'
25972 ||' AND mis2.plan_id = -1'
25973 ||' UNION'
25974 ||' SELECT 1'
25975 ||' FROM msc_st_item_suppliers mis3'
25976 ||' WHERE mis3.vendor_name = mis1.vendor_name'
25977 ||' AND mis3.vendor_site_code = mis1.vendor_site_code'
25978 ||' AND mis3.item_name = mis1.item_name'
25979 ||' AND mis3.sr_instance_code = mis1.sr_instance_code'
25980 ||' AND NVL(mis3.company_name,'||''''||NULL_CHAR||''''||') = '
25981 ||' NVL(mis1.company_name,'||''''||NULL_CHAR||''''||') '
25982 ||' AND mis3.organization_code = mis1.organization_code'
25983 ||' AND mis3.using_organization_id = -1'
25984 ||' AND mis3.process_flag = '||G_VALID||')'
25985 ||' AND sr_instance_code = :v_instance_code'
25986 ||' AND batch_id = :lv_batch_id'
25987 ||' AND process_flag = '||G_IN_PROCESS;
25988
25989
25990
25991 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
25992
25993 EXECUTE IMMEDIATE lv_sql_stmt
25994 USING v_instance_id,
25995 v_instance_code,
25996 lv_batch_id;
25997
25998 --Setting using_organization_id to the default value -1 which is for the
25999 --globally valid supplier rules.
26000 v_sql_stmt := 15;
26001
26002 lv_sql_stmt :=
26003 'UPDATE msc_st_supplier_capacities mis '
26004 ||' SET using_organization_id = '||G_USING_ORG_ID
26005 ||' WHERE sr_instance_code = :v_instance_code'
26006 ||' AND batch_id = :lv_batch_id'
26007 ||' AND process_flag = '||G_IN_PROCESS
26008 ||' AND deleted_flag = '||SYS_NO;
26009
26010
26011 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
26012
26013 EXECUTE IMMEDIATE lv_sql_stmt
26014 USING v_instance_code,
26015 lv_batch_id;
26016
26017 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
26018 (p_app_short_name => 'MSC',
26019 p_error_code => 'MSC_PP_COL_VAL_NULL',
26020 p_message_text => lv_message_text,
26021 p_error_text => lv_error_text,
26022 p_token1 => 'COLUMN_NAME',
26023 p_token_value1 => 'FROM_DATE');
26024
26025 IF lv_return <> 0 THEN
26026 RAISE ex_logging_err;
26027 END IF;
26028
26029 --From_date cannot be null.
26030 v_sql_stmt := 16;
26031
26032 lv_sql_stmt :=
26033 'UPDATE msc_st_supplier_capacities mis '
26034 ||' SET error_text = '||''''||lv_message_text||''''||','
26035 ||' process_flag = '||G_ERROR_FLG
26036 ||' WHERE NVL(from_date,(sysdate-36500)) = (sysdate-36500)'
26037 ||' AND deleted_flag = '||SYS_NO
26038 ||' AND process_flag = '||G_IN_PROCESS
26039 ||' AND batch_id = :lv_batch_id'
26040 ||' AND sr_instance_code = :v_instance_code';
26041
26042
26043 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
26044
26045 EXECUTE IMMEDIATE lv_sql_stmt
26046 USING lv_batch_id,
26047 v_instance_code;
26048
26049
26050 --Call to customised validation.
26051 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
26052 (ERRBUF => lv_error_text,
26053 RETCODE => lv_return,
26054 pBatchID => lv_batch_id,
26055 pInstanceCode => v_instance_code,
26056 pEntityName => 'MSC_ST_SUPPLIER_CAPACITIES',
26057 pInstanceID => v_instance_id);
26058
26059 IF NVL(lv_return,0) <> 0 THEN
26060 RAISE ex_logging_err;
26061 END IF;
26062
26063 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
26064 (p_table_name => 'MSC_ST_SUPPLIER_CAPACITIES',
26065 p_instance_id => v_instance_id,
26066 p_instance_code => v_instance_code,
26067 p_process_flag => G_VALID,
26068 p_error_text => lv_error_text,
26069 p_debug => v_debug,
26070 p_batch_id => lv_batch_id);
26071
26072 IF lv_return <> 0 THEN
26073 RAISE ex_logging_err;
26074 END IF;
26075
26076 lv_return := MSC_ST_UTIL.LOG_ERROR
26077 (p_table_name => 'MSC_ST_SUPPLIER_CAPACITIES',
26078 p_instance_code => v_instance_code,
26079 p_row => lv_column_names,
26080 p_severity => G_SEV_ERROR,
26081 p_message_text => NULL,
26082 p_error_text => lv_error_text,
26083 p_debug => v_debug,
26084 p_batch_id => lv_batch_id);
26085
26086 IF lv_return <> 0 THEN
26087 RAISE ex_logging_err;
26088 END IF;
26089 COMMIT;
26090 END LOOP;
26091
26092 --*********Validation for MSC_ST_SUPPLIER_FLEX_FENCES***********
26093
26094 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
26095 (p_app_short_name => 'MSC',
26096 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
26097 p_message_text => lv_message_text,
26098 p_error_text => lv_error_text);
26099
26100 IF lv_return <> 0 THEN
26101 RAISE ex_logging_err;
26102 END IF;
26103
26104 --Duplicate records check for the records whose source is XML
26105 v_sql_stmt := 17;
26106 lv_sql_stmt :=
26107 'UPDATE msc_st_supplier_flex_fences msf1 '
26108 ||' SET process_flag = '||G_ERROR_FLG||','
26109 ||' error_text = '||''''||lv_message_text||''''
26110 ||' WHERE message_id < (SELECT MAX(message_id)'
26111 ||' FROM msc_st_supplier_flex_fences msf2'
26112 ||' WHERE msf2.sr_instance_code = msf1.sr_instance_code'
26113 ||' AND msf2.organization_code = msf1.organization_code'
26114 ||' AND NVL(msf2.company_name, '||''''||NULL_CHAR||''''||') = '
26115 ||' NVL(msf1.company_name, '||''''||NULL_CHAR||''''||')'
26116 ||' AND msf2.vendor_name = msf1.vendor_name'
26117 ||' AND msf2.vendor_site_code = msf1.vendor_site_code'
26118 ||' AND msf2.item_name = msf1.item_name'
26119 ||' AND msf2.fence_days = msf1.fence_days'
26120 ||' AND msf2.process_flag = '||G_IN_PROCESS
26121 ||' AND NVL(msf2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
26122 ||' AND msf1.process_flag = '||G_IN_PROCESS
26123 ||' AND msf1.sr_instance_code = :v_instance_code'
26124 ||' AND NVL(msf1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
26125
26126
26127 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
26128
26129 EXECUTE IMMEDIATE lv_sql_stmt
26130 USING v_instance_code;
26131
26132 --Duplicate records check for the records whose source is other than XML
26133 --Different SQL is used because in XML we can identify the latest records
26134 --whereas in batch load we cannot.
26135
26136 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
26137 (p_app_short_name => 'MSC',
26138 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
26139 p_message_text => lv_message_text,
26140 p_error_text => lv_error_text);
26141
26142 IF lv_return <> 0 THEN
26143 RAISE ex_logging_err;
26144 END IF;
26145
26146 v_sql_stmt := 18;
26147 lv_sql_stmt :=
26148 'UPDATE msc_st_supplier_flex_fences msf1 '
26149 ||' SET process_flag = '||G_ERROR_FLG||','
26150 ||' error_text = '||''''||lv_message_text||''''
26151 ||' WHERE EXISTS( SELECT 1 '
26152 ||' FROM msc_st_supplier_flex_fences msf2'
26153 ||' WHERE msf2.sr_instance_code = msf1.sr_instance_code'
26154 ||' AND msf2.organization_code = msf1.organization_code'
26155 ||' AND NVL(msf2.company_name, '||''''||NULL_CHAR||''''||') = '
26156 ||' NVL(msf1.company_name, '||''''||NULL_CHAR||''''||')'
26157 ||' AND msf2.vendor_name = msf1.vendor_name'
26158 ||' AND msf2.vendor_site_code = msf1.vendor_site_code'
26159 ||' AND msf2.item_name = msf1.item_name'
26160 ||' AND msf2.fence_days = msf1.fence_days'
26161 ||' AND msf2.process_flag = '||G_IN_PROCESS
26162 ||' AND NVL(msf2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
26163 ||' GROUP BY sr_instance_code,organization_code,company_name,'
26164 ||' item_name,vendor_name,vendor_site_code,fence_days'
26165 ||' HAVING COUNT(*) > 1)'
26166 ||' AND msf1.process_flag ='|| G_IN_PROCESS
26167 ||' AND msf1.sr_instance_code = :v_instance_code'
26168 ||' AND NVL(msf1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
26169
26170
26171 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
26172
26173 EXECUTE IMMEDIATE lv_sql_stmt
26174 USING v_instance_code;
26175
26176 lv_column_names :=
26177 'ORGANIZATION_CODE ||''~''||'
26178 ||'VENDOR_NAME ||''~''||'
26179 ||'FENCE_DAYS ||''~''||'
26180 ||'SR_INSTANCE_CODE ||''~''||'
26181 ||'ITEM_NAME ||''~''||'
26182 ||'VENDOR_SITE_CODE ||''~''||'
26183 ||'TOLERANCE_PERCENTAGE ||''~''||'
26184 ||'DELETED_FLAG ||''~''||'
26185 ||'COMPANY_NAME ||''~''||'
26186 ||'USING_ORGANIZATION_ID';
26187
26188 LOOP
26189 v_sql_stmt := 19;
26190 SELECT msc_st_batch_id_s.NEXTVAL
26191 INTO lv_batch_id
26192 FROM dual;
26193
26194 v_sql_stmt := 20;
26195 lv_sql_stmt :=
26196 'UPDATE msc_st_supplier_flex_fences '
26197 ||' SET batch_id = :lv_batch_id'
26198 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
26199 ||' AND sr_instance_code = :v_instance_code'
26200 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
26201 ||' AND rownum <= '||v_batch_size;
26202
26203
26204 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
26205
26206 EXECUTE IMMEDIATE lv_sql_stmt
26207 USING lv_batch_id,
26208 v_instance_code;
26209
26210 EXIT WHEN SQL%NOTFOUND;
26211
26212 OPEN c3(lv_batch_id);
26213 FETCH c3 BULK COLLECT INTO lb_rowid;
26214 CLOSE c3;
26215
26216 v_sql_stmt := 21;
26217 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
26218 UPDATE msc_st_supplier_flex_fences
26219 SET st_transaction_id = msc_st_supplier_flex_fences_s.NEXTVAL,
26220 refresh_id = v_refresh_id,
26221 last_update_date = v_current_date,
26222 last_updated_by = v_current_user,
26223 creation_date = v_current_date,
26224 created_by = v_current_user
26225 WHERE rowid = lb_rowid(j);
26226
26227
26228 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
26229 (p_app_short_name => 'MSC',
26230 p_error_code => 'MSC_PP_NO_DELETION',
26231 p_message_text => lv_message_text,
26232 p_error_text => lv_error_text,
26233 p_token1 => 'TABLE_NAME',
26234 p_token_value1 => 'MSC_ST_SUPPLIER_FLEX_FENCES');
26235
26236 IF lv_return <> 0 THEN
26237 RAISE ex_logging_err;
26238 END IF;
26239
26240 --Deletion is not allowed on this table.
26241 v_sql_stmt := 22;
26242 lv_sql_stmt :=
26243 'UPDATE msc_st_supplier_flex_fences'
26244 ||' SET process_flag = '||G_ERROR_FLG||','
26245 ||' error_text = '||''''||lv_message_text||''''
26246 ||' WHERE deleted_flag = '||SYS_YES
26247 ||' AND process_flag = '||G_IN_PROCESS
26248 ||' AND batch_id = :lv_batch_id'
26249 ||' AND sr_instance_code = :v_instance_code';
26250
26251
26252 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
26253
26254 EXECUTE IMMEDIATE lv_sql_stmt
26255 USING lv_batch_id,
26256 v_instance_code;
26257
26258 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
26259 (p_app_short_name => 'MSC',
26260 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
26261 p_message_text => lv_message_text,
26262 p_error_text => lv_error_text,
26263 p_token1 => 'COLUMN_NAME',
26264 p_token_value1 => 'DELETED_FLAG',
26265 p_token2 => 'DEFAULT_VALUE',
26266 p_token_value2 => SYS_NO);
26267
26268 IF lv_return <> 0 THEN
26269 RAISE ex_logging_err;
26270 END IF;
26271
26272 lv_where_str := ' AND NVL(deleted_flag,'||NULL_VALUE||') '
26273 ||' NOT IN(1,2)';
26274
26275 --Log a warning for those records where the deleted_flag has a value other
26276 --than SYS_NO
26277 lv_return := MSC_ST_UTIL.LOG_ERROR
26278 (p_table_name => 'MSC_ST_SUPPLIER_FLEX_FENCES',
26279 p_instance_code => v_instance_code,
26280 p_row => lv_column_names,
26281 p_severity => G_SEV_WARNING,
26282 p_message_text => lv_message_text,
26283 p_error_text => lv_error_text,
26284 p_batch_id => lv_batch_id,
26285 p_where_str => lv_where_str,
26286 p_col_name => 'deleted_FLAG',
26287 p_debug => v_debug,
26288 p_default_value => SYS_NO);
26289
26290 IF lv_return <> 0 THEN
26291 RAISE ex_logging_err;
26292 END IF;
26293
26294 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
26295 (p_app_short_name => 'MSC',
26296 p_error_code => 'MSC_PP_INVALID_VALUE',
26297 p_message_text => lv_message_text,
26298 p_error_text => lv_error_text,
26299 p_token1 => 'COLUMN_NAME',
26300 p_token_value1 => 'ORGANIZATION_CODE');
26301
26302 IF lv_return <> 0 THEN
26303 RAISE ex_logging_err;
26304 END IF;
26305
26306 --Derive Organization_id
26307 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
26308 (p_table_name => 'MSC_ST_SUPPLIER_FLEX_FENCES',
26309 p_org_partner_name => 'ORGANIZATION_CODE',
26310 p_org_partner_id => 'ORGANIZATION_ID',
26311 p_instance_code => v_instance_code,
26312 p_partner_type => G_ORGANIZATION,
26313 p_error_text => lv_error_text,
26314 p_batch_id => lv_batch_id,
26315 p_severity => G_SEV_ERROR,
26316 p_message_text => lv_message_text,
26317 p_debug => v_debug,
26318 p_row => lv_column_names);
26319
26320 IF lv_return <> 0 THEN
26321 RAISE ex_logging_err;
26322 END IF;
26323
26324 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
26325 (p_app_short_name => 'MSC',
26326 p_error_code => 'MSC_PP_INVALID_VALUE',
26327 p_message_text => lv_message_text,
26328 p_error_text => lv_error_text,
26329 p_token1 => 'COLUMN_NAME',
26330 p_token_value1 => 'ITEM_NAME');
26331
26332 IF lv_return <> 0 THEN
26333 RAISE ex_logging_err;
26334 END IF;
26335
26336 --Derive Inventory_item_id
26337 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
26338 (p_table_name => 'MSC_ST_SUPPLIER_FLEX_FENCES',
26339 p_item_col_name => 'ITEM_NAME',
26340 p_item_col_id => 'INVENTORY_ITEM_ID',
26341 p_instance_id => v_instance_id,
26342 p_instance_code => v_instance_code,
26343 p_error_text => lv_error_text,
26344 p_batch_id => lv_batch_id,
26345 p_severity => G_SEV_ERROR,
26346 p_message_text => lv_message_text,
26347 p_debug => v_debug,
26348 p_row => lv_column_names);
26349
26350 IF lv_return <> 0 THEN
26351 RAISE ex_logging_err;
26352 END IF;
26353
26354 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
26355 (p_app_short_name => 'MSC',
26356 p_error_code => 'MSC_PP_INVALID_VALUE',
26357 p_message_text => lv_message_text,
26358 p_error_text => lv_error_text,
26359 p_token1 => 'COLUMN_NAME',
26360 p_token_value1 => 'VENDOR_NAME');
26361
26362 IF lv_return <> 0 THEN
26363 RAISE ex_logging_err;
26364 END IF;
26365
26366 --Derive Supplier_id
26367 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
26368 (p_table_name => 'MSC_ST_SUPPLIER_FLEX_FENCES',
26369 p_org_partner_name => 'VENDOR_NAME',
26370 p_org_partner_id => 'SUPPLIER_ID',
26371 p_instance_code => v_instance_code,
26372 p_partner_type => G_VENDOR,
26373 p_error_text => lv_error_text,
26374 p_batch_id => lv_batch_id,
26375 p_severity => G_SEV_ERROR,
26376 p_message_text => lv_message_text,
26377 p_debug => v_debug,
26378 p_row => lv_column_names);
26379
26380 IF lv_return <> 0 THEN
26381 RAISE ex_logging_err;
26382 END IF;
26383
26384 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
26385 (p_app_short_name => 'MSC',
26386 p_error_code => 'MSC_PP_INVALID_VALUE',
26387 p_message_text => lv_message_text,
26388 p_error_text => lv_error_text,
26389 p_token1 => 'COLUMN_NAME',
26390 p_token_value1 => 'VENDOR_SITE_CODE');
26391
26392 IF lv_return <> 0 THEN
26393 RAISE ex_logging_err;
26394 END IF;
26395
26396 --Derive Supplier_site_id
26397 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
26398 (p_table_name => 'MSC_ST_SUPPLIER_FLEX_FENCES',
26399 p_partner_name => 'VENDOR_NAME',
26400 p_partner_site_code=> 'VENDOR_SITE_CODE',
26401 p_partner_site_id => 'SUPPLIER_SITE_ID',
26402 p_instance_code => v_instance_code,
26403 p_partner_type => G_VENDOR,
26404 p_error_text => lv_error_text,
26405 p_batch_id => lv_batch_id,
26406 p_severity => G_SEV_ERROR,
26407 p_message_text => lv_message_text,
26408 p_debug => v_debug,
26409 p_row => lv_column_names);
26410
26411 IF lv_return <> 0 THEN
26412 RAISE ex_logging_err;
26413 END IF;
26414
26415 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
26416 (p_app_short_name => 'MSC',
26417 p_error_code => 'MSC_PP_SUPP_NOT_EXIST',
26418 p_message_text => lv_message_text,
26419 p_error_text => lv_error_text,
26420 p_token1 => 'COLUMN_NAMES',
26421 p_token_value1 => 'SR_INSTANCE_CODE, COMPANY_NAME, ORGANIZATION_CODE,'
26422 ||' ITEM_NAME, VENDOR_NAME AND VENDOR_SITE_CODE',
26423 p_token2 => 'MASTER_TABLE',
26424 p_token_value2 => 'MSC_ST_ITEM_SUPPLIERS',
26425 p_token3 => 'CHILD_TABLE',
26426 p_token_value3 => 'MSC_ST_SUPPLIER_FLEX_FENCES ',
26427 p_token4 => 'VALUE',
26428 p_token_value4 => 'ASL_LEVEL = 1');
26429 IF lv_return <> 0 THEN
26430 RAISE ex_logging_err;
26431 END IF;
26432
26433 --Checking for the referential integrity.
26434 v_sql_stmt := 23;
26435 lv_sql_stmt :=
26436 'UPDATE msc_st_supplier_flex_fences msf1'
26437 ||' SET error_text = '||''''||lv_message_text||''''||','
26438 ||' process_flag = '||G_ERROR_FLG
26439 ||' WHERE NOT EXISTS(SELECT 1'
26440 ||' FROM msc_item_suppliers msf2, MSC_TP_ID_LID mtil, MSC_TP_SITE_ID_LID mtsil, MSC_ITEM_ID_LID mil'
26441 ||' WHERE mtil.SR_TP_ID = msf1.supplier_id'
26442 ||' AND mtil.TP_ID = msf2.supplier_id'
26443 ||' AND mtil.sr_instance_id = msf2.sr_instance_id'
26444 ||' AND mtil.PARTNER_TYPE = 1'
26445 ||' AND mtsil.SR_TP_SITE_ID = msf1.supplier_site_id'
26446 ||' AND mtsil.TP_SITE_ID = msf2.supplier_site_id'
26447 ||' AND mtsil.sr_instance_id = msf2.sr_instance_id'
26448 ||' AND mtsil.partner_type = 1'
26449 ||' AND mil.sr_inventory_item_id = msf1.inventory_item_id'
26450 ||' AND mil.inventory_item_id = msf2.inventory_item_id'
26451 ||' AND mil.sr_instance_id = msf2.sr_instance_id'
26452 ||' AND msf2.sr_instance_id = :v_instance_id'
26453 ||' AND msf2.organization_id = msf1.organization_id'
26454 ||' AND msf2.using_organization_id = -1'
26455 ||' AND msf2.plan_id = -1'
26456 ||' UNION'
26457 ||' SELECT 1'
26458 ||' FROM msc_st_item_suppliers msf3'
26459 ||' WHERE msf3.vendor_name = msf1.vendor_name'
26460 ||' AND msf3.vendor_site_code = msf1.vendor_site_code'
26461 ||' AND msf3.item_name = msf1.item_name'
26462 ||' AND msf3.sr_instance_code = msf1.sr_instance_code'
26463 ||' AND NVL(msf3.company_name,'||G_COMPANY_ID||') = '
26464 ||' NVL(msf1.company_name,'||G_COMPANY_ID||')'
26465 ||' AND msf3.organization_code = msf1.organization_code'
26466 ||' AND msf3.using_organization_id = -1'
26467 ||' AND msf3.process_flag = '||G_VALID||')'
26468 ||' AND msf1.sr_instance_code = :v_instance_code'
26469 ||' AND msf1.batch_id = :lv_batch_id'
26470 ||' AND msf1.process_flag = '||G_IN_PROCESS;
26471
26472
26473 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
26474
26475 EXECUTE IMMEDIATE lv_sql_stmt
26476 USING v_instance_id,
26477 v_instance_code,
26478 lv_batch_id;
26479
26480 --Setting using_organization_id to the default value -1 which is for the
26481 --globally valid supplier rules.
26482 v_sql_stmt := 24;
26483 lv_sql_stmt :=
26484 'UPDATE msc_st_supplier_flex_fences mis '
26485 ||' SET using_organization_id = '||G_USING_ORG_ID
26486 ||' WHERE deleted_flag = '||SYS_NO
26487 ||' AND process_flag = '||G_IN_PROCESS
26488 ||' AND batch_id = :lv_batch_id'
26489 ||' AND sr_instance_code = :v_instance_code';
26490
26491
26492 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
26493
26494 EXECUTE IMMEDIATE lv_sql_stmt
26495 USING lv_batch_id,
26496 v_instance_code;
26497
26498 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
26499 (p_app_short_name => 'MSC',
26500 p_error_code => 'MSC_PP_COL_VAL_NULL',
26501 p_message_text => lv_message_text,
26502 p_error_text => lv_error_text,
26503 p_token1 => 'COLUMN_NAME',
26504 p_token_value1 => 'FENCE_DAYS');
26505
26506 IF lv_return <> 0 THEN
26507 RAISE ex_logging_err;
26508 END IF;
26509
26510 --Fence days should not be null.
26511 v_sql_stmt := 25;
26512 lv_sql_stmt :=
26513 'UPDATE msc_st_supplier_flex_fences '
26514 ||' SET error_text = '||''''||lv_message_text||''''||','
26515 ||' process_flag = '||G_ERROR_FLG
26516 ||' WHERE NVL(fence_days,'||NULL_VALUE||' )= '||NULL_VALUE
26517 ||' AND deleted_flag ='|| SYS_NO
26518 ||' AND process_flag ='|| G_IN_PROCESS
26519 ||' AND batch_id = :lv_batch_id'
26520 ||' AND sr_instance_code = :v_instance_code';
26521
26522
26523 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
26524
26525 EXECUTE IMMEDIATE lv_sql_stmt
26526 USING lv_batch_id,
26527 v_instance_code;
26528
26529 --Call to customised validation.
26530 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
26531 (ERRBUF => lv_error_text,
26532 RETCODE => lv_return,
26533 pBatchID => lv_batch_id,
26534 pInstanceCode => v_instance_code,
26535 pEntityName => 'MSC_ST_SUPPLIER_FLEX_FENCES',
26536 pInstanceID => v_instance_id);
26537
26538 IF NVL(lv_return,0) <> 0 THEN
26539 RAISE ex_logging_err;
26540 END IF;
26541
26542 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
26543 (p_table_name => 'MSC_ST_SUPPLIER_FLEX_FENCES',
26544 p_instance_id => v_instance_id,
26545 p_instance_code => v_instance_code,
26546 p_process_flag => G_VALID,
26547 p_error_text => lv_error_text,
26548 p_debug => v_debug,
26549 p_batch_id => lv_batch_id);
26550
26551 IF lv_return <> 0 THEN
26552 RAISE ex_logging_err;
26553 END IF;
26554
26555 lv_return := MSC_ST_UTIL.LOG_ERROR
26556 (p_table_name => 'MSC_ST_SUPPLIER_FLEX_FENCES',
26557 p_instance_code => v_instance_code,
26558 p_row => lv_column_names,
26559 p_severity => G_ERROR_FLG,
26560 p_message_text => NULL,
26561 p_error_text => lv_error_text,
26562 p_debug => v_debug,
26563 p_batch_id => lv_batch_id);
26564
26565 IF lv_return <> 0 THEN
26566 RAISE ex_logging_err;
26567 END IF;
26568 COMMIT;
26569 END LOOP;
26570 EXCEPTION
26571 WHEN ex_logging_err THEN
26572 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
26573 ROLLBACK;
26574
26575 WHEN OTHERS THEN
26576 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_SUPP_CAPACITY'||'('
26577 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
26578 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
26579 ROLLBACK;
26580
26581 END LOAD_SUPP_CAPACITY;
26582
26583 /*==========================================================================+
26584 | DESCRIPTION : This procedure validates the data in MSC_ST_SAFETY_STOCKS |
26585 | table and derives the id's from the local id's table. |
26586 +==========================================================================*/
26587 PROCEDURE LOAD_SAFETY_STOCKS IS
26588 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
26589 lb_rowid RowidTab;
26590 lv_return NUMBER;
26591 lv_error_text VARCHAR2(250);
26592 lv_where_str VARCHAR2(5000);
26593 lv_sql_stmt VARCHAR2(5000);
26594 lv_column_names VARCHAR2(5000); --stores concatenated column names
26595 lv_batch_id msc_st_safety_stocks.batch_id%TYPE;
26596 lv_message_text msc_errors.error_text%TYPE;
26597
26598 ex_logging_err EXCEPTION;
26599
26600 CURSOR c1(p_batch_id NUMBER) IS
26601 SELECT rowid
26602 FROM msc_st_safety_stocks
26603 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
26604 AND batch_id = p_batch_id
26605 AND sr_instance_code = v_instance_code;
26606
26607 BEGIN
26608
26609 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
26610 (p_app_short_name => 'MSC',
26611 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
26612 p_message_text => lv_message_text,
26613 p_error_text => lv_error_text);
26614
26615 IF lv_return <> 0 THEN
26616 RAISE ex_logging_err;
26617 END IF;
26618
26619 --Duplicate records check for the records whose source is XML
26620 v_sql_stmt := 01;
26621 lv_sql_stmt :=
26622 ' UPDATE msc_st_safety_stocks mss1'
26623 ||' SET process_flag = '||G_ERROR_FLG||','
26624 ||' error_text = '||''''||lv_message_text||''''
26625 ||' WHERE message_id < (SELECT MAX(message_id)'
26626 ||' FROM msc_st_safety_stocks mss2'
26627 ||' WHERE mss2.sr_instance_code = mss1.sr_instance_code'
26628 ||' AND mss2.organization_code = mss1.organization_code'
26629 ||' AND mss2.item_name = mss1.item_name'
26630 ||' AND mss2.period_start_date = mss1.period_start_date'
26631 ||' AND NVL(mss2.company_name, ' ||''''||NULL_CHAR||''''||') = '
26632 ||' NVL(mss1.company_name, ' ||''''||NULL_CHAR||''''||')'
26633 ||' AND mss2.process_flag = mss1.process_flag'
26634 ||' AND NVL(mss2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
26635 ||' AND mss1.process_flag = '||G_IN_PROCESS
26636 ||' AND mss1.sr_instance_code = :v_instance_code'
26637 ||' AND NVL(mss1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
26638
26639
26640 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
26641
26642 EXECUTE IMMEDIATE lv_sql_stmt
26643 USING v_instance_code;
26644
26645 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
26646 (p_app_short_name => 'MSC',
26647 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
26648 p_message_text => lv_message_text,
26649 p_error_text => lv_error_text);
26650
26651 IF lv_return <> 0 THEN
26652 RAISE ex_logging_err;
26653 END IF;
26654
26655 --Duplicate records check for the records whose source is other than XML
26656 --Different SQL is used because in XML we can identify the latest records
26657 --whereas in batch load we cannot.
26658 v_sql_stmt := 02;
26659 lv_sql_stmt :=
26660 ' UPDATE msc_st_safety_stocks mss1'
26661 ||' SET process_flag = '||G_ERROR_FLG||','
26662 ||' error_text = '||''''||lv_message_text||''''
26663 ||' WHERE EXISTS( SELECT 1 '
26664 ||' FROM msc_st_safety_stocks mss2'
26665 ||' WHERE mss2.sr_instance_code = mss1.sr_instance_code'
26666 ||' AND mss2.organization_code = mss1.organization_code'
26667 ||' AND mss2.item_name = mss1.item_name'
26668 ||' AND mss2.period_start_date = mss1.period_start_date'
26669 ||' AND NVL(mss2.company_name, ' ||''''||NULL_CHAR||''''||') = '
26670 ||' NVL(mss1.company_name, ' ||''''||NULL_CHAR||''''||')'
26671 ||' AND mss2.process_flag = mss1.process_flag'
26672 ||' AND NVL(mss2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
26673 ||' GROUP BY sr_instance_code,organization_code,item_name,'
26674 ||' period_start_date,company_name'
26675 ||' HAVING COUNT(*) > 1)'
26676 ||' AND mss1.process_flag = '||G_IN_PROCESS
26677 ||' AND mss1.sr_instance_code = :v_instance_code'
26678 ||' AND NVL(mss1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
26679
26680
26681 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
26682
26683 EXECUTE IMMEDIATE lv_sql_stmt
26684 USING v_instance_code;
26685
26686 lv_column_names :=
26687 'ORGANIZATION_CODE ||''~''||'
26688 ||'ITEM_NAME ||''~''||'
26689 ||'PERIOD_START_DATE ||''~''||'
26690 ||'SAFETY_STOCK_QUANTITY ||''~''||'
26691 ||'COMPANY_NAME ||''~''||'
26692 ||'SR_INSTANCE_CODE ||''~''||'
26693 ||'DELETED_FLAG ';
26694
26695 LOOP
26696 v_sql_stmt := 03;
26697 SELECT msc_st_batch_id_s.NEXTVAL
26698 INTO lv_batch_id
26699 FROM dual;
26700
26701 v_sql_stmt := 04;
26702 lv_sql_stmt :=
26703 ' UPDATE msc_st_safety_stocks '
26704 ||' SET batch_id = :lv_batch_id'
26705 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
26706 ||' AND sr_instance_code = :v_instance_code'
26707 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
26708 ||' AND rownum <= '||v_batch_size;
26709
26710
26711 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
26712
26713 EXECUTE IMMEDIATE lv_sql_stmt
26714 USING lv_batch_id,
26715 v_instance_code;
26716
26717 EXIT WHEN SQL%NOTFOUND;
26718
26719 OPEN c1(lv_batch_id);
26720 FETCH c1 BULK COLLECT INTO lb_rowid;
26721 CLOSE c1;
26722
26723 v_sql_stmt := 05;
26724 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
26725 UPDATE msc_st_safety_stocks
26726 SET st_transaction_id = msc_st_safety_stocks_s.NEXTVAL,
26727 refresh_id = v_refresh_id,
26728 last_update_date = v_current_date,
26729 last_updated_by = v_current_user,
26730 creation_date = v_current_date,
26731 created_by = v_current_user
26732 WHERE rowid = lb_rowid(j);
26733
26734 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
26735 (p_app_short_name => 'MSC',
26736 p_error_code => 'MSC_PP_NO_DELETION',
26737 p_message_text => lv_message_text,
26738 p_error_text => lv_error_text,
26739 p_token1 => 'TABLE_NAME',
26740 p_token_value1 => 'MSC_ST_SAFETY_STOCKS');
26741
26742 IF lv_return <> 0 THEN
26743 RAISE ex_logging_err;
26744 END IF;
26745
26746 --Deletion is not allowed for this entity.
26747 v_sql_stmt := 06;
26748 lv_sql_stmt :=
26749 ' UPDATE msc_st_safety_stocks '
26750 ||' SET process_flag = '||G_ERROR_FLG||','
26751 ||' error_text = '||''''||lv_message_text||''''
26752 ||' WHERE deleted_flag = '||SYS_YES
26753 ||' AND process_flag = '||G_IN_PROCESS
26754 ||' AND batch_id = :lv_batch_id'
26755 ||' AND sr_instance_code = :v_instance_code';
26756
26757
26758 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
26759
26760 EXECUTE IMMEDIATE lv_sql_stmt
26761 USING lv_batch_id,
26762 v_instance_code;
26763
26764 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
26765 (p_app_short_name => 'MSC',
26766 p_error_code => 'MSC_PP_COL_VAL_NULL',
26767 p_message_text => lv_message_text,
26768 p_error_text => lv_error_text,
26769 p_token1 => 'COLUMN_NAME',
26770 p_token_value1 => 'SAFETY_STOCK_QUANTITY OR PERIOD_START_DATE');
26771
26772 IF lv_return <> 0 THEN
26773 RAISE ex_logging_err;
26774 END IF;
26775
26776 v_sql_stmt := 07;
26777 lv_sql_stmt :=
26778 ' UPDATE msc_st_safety_stocks '
26779 ||' SET process_flag = '||G_ERROR_FLG||','
26780 ||' error_text = '||''''||lv_message_text||''''
26781 ||' WHERE (safety_stock_quantity IS NULL '
26782 ||' OR period_start_date IS NULL) '
26783 ||' AND batch_id = :lv_batch_id'
26784 ||' AND process_flag = '||G_IN_PROCESS
26785 ||' AND sr_instance_code = :v_instance_code';
26786
26787
26788 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
26789 EXECUTE IMMEDIATE lv_sql_stmt
26790 USING lv_batch_id,
26791 v_instance_code;
26792
26793 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
26794 (p_app_short_name => 'MSC',
26795 p_error_code => 'MSC_PP_INVALID_VALUE',
26796 p_message_text => lv_message_text,
26797 p_error_text => lv_error_text,
26798 p_token1 => 'COLUMN_NAME',
26799 p_token_value1 => 'ORGANIZATION_CODE');
26800
26801 IF lv_return <> 0 THEN
26802 RAISE ex_logging_err;
26803 END IF;
26804
26805 --Derive Organization_id
26806 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
26807 (p_table_name => 'MSC_ST_SAFETY_STOCKS',
26808 p_org_partner_name => 'ORGANIZATION_CODE',
26809 p_org_partner_id => 'ORGANIZATION_ID',
26810 p_instance_code => v_instance_code,
26811 p_partner_type => G_ORGANIZATION,
26812 p_error_text => lv_error_text,
26813 p_batch_id => lv_batch_id,
26814 p_severity => G_SEV_ERROR,
26815 p_message_text => lv_message_text,
26816 p_debug => v_debug,
26817 p_row => lv_column_names);
26818
26819 IF lv_return <> 0 THEN
26820 RAISE ex_logging_err;
26821 END IF;
26822
26823 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
26824 (p_app_short_name => 'MSC',
26825 p_error_code => 'MSC_PP_INVALID_VALUE',
26826 p_message_text => lv_message_text,
26827 p_error_text => lv_error_text,
26828 p_token1 => 'COLUMN_NAME',
26829 p_token_value1 => 'ITEM_NAME');
26830
26831 IF lv_return <> 0 THEN
26832 RAISE ex_logging_err;
26833 END IF;
26834
26835 --Derive Inventory_item_id
26836 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
26837 (p_table_name => 'MSC_ST_SAFETY_STOCKS',
26838 p_item_col_name => 'ITEM_NAME',
26839 p_item_col_id => 'INVENTORY_ITEM_ID',
26840 p_instance_id => v_instance_id,
26841 p_instance_code => v_instance_code,
26842 p_error_text => lv_error_text,
26843 p_batch_id => lv_batch_id,
26844 p_severity => G_SEV_ERROR,
26845 p_message_text => lv_message_text,
26846 p_debug => v_debug,
26847 p_row => lv_column_names);
26848
26849 IF lv_return <> 0 THEN
26850 RAISE ex_logging_err;
26851 END IF;
26852
26853 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
26854 (p_app_short_name => 'MSC',
26855 p_error_code => 'MSC_PP_SAFETY_STOCK_INVALID',
26856 p_message_text => lv_message_text,
26857 p_error_text => lv_error_text);
26858
26859 IF lv_return <> 0 THEN
26860 RAISE ex_logging_err;
26861 END IF;
26862
26863
26864 v_sql_stmt := 08;
26865 lv_sql_stmt :=
26866
26867 'UPDATE msc_st_safety_stocks mss'
26868 ||' SET process_flag = '||G_ERROR_FLG||','
26869 ||' error_text = '||''''||lv_message_text||''''
26870 ||' WHERE EXISTS (SELECT 1'
26871 ||' FROM msc_st_system_items msi'
26872 ||' WHERE msi.sr_instance_code = mss.sr_instance_code '
26873 ||' AND msi.organization_code = mss.organization_code'
26874 ||' AND msi.item_name = mss.item_name'
26875 ||' AND NVL(msi.company_name,'||''''||NULL_CHAR||''''||') '
26876 ||' = NVL(mss.company_name,'||''''||NULL_CHAR||''''||') '
26877 ||' AND msi.mrp_safety_stock_code <> 1'
26878 ||' AND msi.process_flag = '||G_VALID
26879 ||' UNION'
26880 ||' SELECT 1'
26881 ||' FROM msc_system_items itm'
26882 ||' WHERE itm.sr_instance_id = '||v_instance_id
26883 ||' AND itm.organization_id = mss.organization_id '
26884 ||' AND itm.item_name = mss.item_name'
26885 ||' AND itm.safety_stock_code <> 1'
26886 ||' AND itm.plan_id = -1 )'
26887 ||' AND deleted_flag = '||SYS_NO
26888 ||' AND process_flag = '||G_IN_PROCESS
26889 ||' AND batch_id = :lv_batch_id'
26890 ||' AND sr_instance_code = :v_instance_code';
26891
26892
26893 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
26894
26895 EXECUTE IMMEDIATE lv_sql_stmt
26896 USING lv_batch_id,
26897 v_instance_code;
26898
26899
26900 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
26901 (p_app_short_name => 'MSC',
26902 p_error_code => 'MSC_PP_FK_REF_NOT_EXIST',
26903 p_message_text => lv_message_text,
26904 p_error_text => lv_error_text,
26905 p_token1 => 'COLUMN_NAMES',
26906 p_token_value1 => ' SR_INSTANCE_CODE, COMPANY_NAME,'
26907 ||' ORGANIZATION_CODE AND PROJECT_NUMBER',
26908 p_token2 => 'MASTER_TABLE',
26909 p_token_value2 => 'MSC_ST_PROJECT_TASKS');
26910
26911 IF lv_return <> 0 THEN
26912 RAISE ex_logging_err;
26913 END IF;
26914
26915 --Derive Project Id.
26916 lv_return := MSC_ST_UTIL.DERIVE_PROJ_TASK_ID
26917 (p_table_name => 'MSC_ST_SAFETY_STOCKS',
26918 p_proj_col_name => 'PROJECT_NUMBER',
26919 p_proj_task_col_id => 'PROJECT_ID',
26920 p_instance_code => v_instance_code,
26921 p_entity_name => 'PROJECT_ID',
26922 p_error_text => lv_error_text,
26923 p_batch_id => lv_batch_id,
26924 p_severity => G_SEV_WARNING,
26925 p_message_text => lv_message_text,
26926 p_debug => v_debug,
26927 p_row => lv_column_names);
26928 IF lv_return <> 0 THEN
26929 RAISE ex_logging_err;
26930 END IF;
26931
26932 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
26933 (p_app_short_name => 'MSC',
26934 p_error_code => 'MSC_PP_FK_REF_NOT_EXIST',
26935 p_message_text => lv_message_text,
26936 p_error_text => lv_error_text,
26937 p_token1 => 'COLUMN_NAMES',
26938 p_token_value1 => ' SR_INSTANCE_CODE, COMPANY_NAME,'
26939 ||' ORGANIZATION_CODE, PROJECT_NUMBER,'
26940 ||' TASK_NUMBER',
26941 p_token2 => 'MASTER_TABLE',
26942 p_token_value2 => 'MSC_ST_PROJECT_TASKS');
26943
26944 IF lv_return <> 0 THEN
26945 RAISE ex_logging_err;
26946 END IF;
26947
26948 --Derive Task Id.
26949 lv_return := MSC_ST_UTIL.DERIVE_PROJ_TASK_ID
26950 (p_table_name => 'MSC_ST_SAFETY_STOCKS',
26951 p_proj_col_name => 'PROJECT_NUMBER',
26952 p_proj_task_col_id => 'TASK_ID',
26953 p_instance_code => v_instance_code,
26954 p_entity_name => 'TASK_ID',
26955 p_error_text => lv_error_text,
26956 p_task_col_name => 'TASK_NUMBER',
26957 p_batch_id => lv_batch_id,
26958 p_severity => G_SEV_WARNING,
26959 p_message_text => lv_message_text,
26960 p_debug => v_debug,
26961 p_row => lv_column_names);
26962
26963 IF lv_return <> 0 THEN
26964 RAISE ex_logging_err;
26965 END IF;
26966
26967 --Call to customised validation.
26968 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
26969 (ERRBUF => lv_error_text,
26970 RETCODE => lv_return,
26971 pBatchID => lv_batch_id,
26972 pInstanceCode => v_instance_code,
26973 pEntityName => 'MSC_ST_SAFETY_STOCKS',
26974 pInstanceID => v_instance_id);
26975
26976 IF NVL(lv_return,0) <> 0 THEN
26977 RAISE ex_logging_err;
26978 END IF;
26979
26980 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
26981 (p_table_name => 'MSC_ST_SAFETY_STOCKS',
26982 p_instance_id => v_instance_id,
26983 p_instance_code => v_instance_code,
26984 p_process_flag => G_VALID,
26985 p_error_text => lv_error_text,
26986 p_debug => v_debug,
26987 p_batch_id => lv_batch_id);
26988
26989 IF lv_return <> 0 THEN
26990 RAISE ex_logging_err;
26991 END IF;
26992
26993 lv_return := MSC_ST_UTIL.LOG_ERROR
26994 (p_table_name => 'MSC_ST_SAFETY_STOCKS',
26995 p_instance_code => v_instance_code,
26996 p_row => lv_column_names,
26997 p_severity => G_SEV_ERROR,
26998 p_message_text => NULL,
26999 p_error_text => lv_error_text,
27000 p_debug => v_debug,
27001 p_batch_id => lv_batch_id);
27002
27003 IF lv_return <> 0 THEN
27004 RAISE ex_logging_err;
27005 END IF;
27006
27007 COMMIT;
27008 END LOOP;
27009
27010 EXCEPTION
27011 WHEN too_many_rows THEN
27012 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_SAFETY_STOCKS'||'('
27013 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
27014 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
27015 ROLLBACK;
27016
27017 WHEN ex_logging_err THEN
27018 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
27019 ROLLBACK;
27020
27021 WHEN OTHERS THEN
27022 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_SAFETY_STOCKS'||'('
27023 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
27024 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
27025 ROLLBACK;
27026
27027 END LOAD_SAFETY_STOCKS;
27028
27029 /*==========================================================================+
27030 | DESCRIPTION : This procedure validates the data in MSC_ST_ITEM_CATEGORIES|
27031 | table. |
27032 +==========================================================================*/
27033 PROCEDURE LOAD_CATEGORY IS
27034 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
27035 lb_rowid RowidTab;
27036 lv_return NUMBER;
27037 lv_error_text VARCHAR2(250);
27038 lv_where_str VARCHAR2(5000);
27039 lv_sql_stmt VARCHAR2(5000);
27040 lv_column_names VARCHAR2(5000); --stores concatenated column names
27041 lv_batch_id msc_st_item_categories.batch_id%TYPE;
27042 lv_message_text msc_errors.error_text%TYPE;
27043
27044 ex_logging_err EXCEPTION;
27045
27046
27047 TYPE CharTblTyp IS TABLE OF VARCHAR2(1000);
27048 lb_item CharTblTyp;
27049 lb_cat CharTblTyp;
27050 lb_cat_set CharTblTyp;
27051 lb_org CharTblTyp;
27052 lb_comp CharTblTyp;
27053
27054 CURSOR c_udk is
27055 SELECT item_name, category_name, category_set_name, organization_code, company_name
27056 FROM msc_st_item_categories
27057 WHERE sr_instance_code = v_instance_code
27058 AND process_flag= G_IN_PROCESS
27059 AND NVL(message_id,NULL_VALUE) = NULL_VALUE
27060 GROUP BY sr_instance_code, item_name, category_name, category_set_name, organization_code, company_name
27061 HAVING COUNT(*) > 1;
27062
27063 CURSOR c1(p_batch_id NUMBER) IS
27064 SELECT rowid
27065 FROM msc_st_item_categories
27066 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
27067 AND batch_id = p_batch_id
27068 AND sr_instance_code = v_instance_code;
27069
27070 CURSOR c2(p_batch_id NUMBER) IS
27071 SELECT max(rowid)
27072 FROM msc_st_item_categories
27073 WHERE NVL(sr_category_id,NULL_VALUE) = NULL_VALUE
27074 AND process_flag = G_IN_PROCESS
27075 AND batch_id = p_batch_id
27076 AND sr_instance_code = v_instance_code
27077 GROUP BY sr_instance_code,company_name,category_name ;
27078
27079 BEGIN
27080
27081 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
27082 (p_app_short_name => 'MSC',
27083 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
27084 p_message_text => lv_message_text,
27085 p_error_text => lv_error_text);
27086
27087 IF lv_return <> 0 THEN
27088 RAISE ex_logging_err;
27089 END IF;
27090
27091 --Duplicate records check for the records whose source is XML
27092 v_sql_stmt := 01;
27093 lv_sql_stmt :=
27094 'UPDATE msc_st_item_categories mic1 '
27095 ||' SET process_flag = '||G_ERROR_FLG||','
27096 ||' error_text = '||''''||lv_message_text||''''
27097 ||' WHERE message_id < (SELECT MAX(message_id)'
27098 ||' FROM msc_st_item_categories mic2'
27099 ||' WHERE mic2.sr_instance_code = mic1.sr_instance_code'
27100 ||' AND mic2.organization_code = mic1.organization_code'
27101 ||' AND NVL(mic2.company_name, '||''''||NULL_CHAR||''''||') = '
27102 ||' NVL(mic1.company_name, '||''''||NULL_CHAR||''''||')'
27103 ||' AND mic2.category_set_name = mic1.category_set_name'
27104 ||' AND mic2.category_name = mic1.category_name'
27105 ||' AND mic2.item_name = mic1.item_name '
27106 ||' AND mic2.process_flag = '||G_IN_PROCESS
27107 ||' AND mic2.sr_instance_code = mic1.sr_instance_code'
27108 ||' AND NVL(mic2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
27109 ||' AND mic1.process_flag = '||G_IN_PROCESS
27110 ||' AND mic1.sr_instance_code = :v_instance_code'
27111 ||' AND NVL(mic1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
27112
27113
27114
27115 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
27116 EXECUTE IMMEDIATE lv_sql_stmt
27117 USING v_instance_code;
27118
27119 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
27120 (p_app_short_name => 'MSC',
27121 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
27122 p_message_text => lv_message_text,
27123 p_error_text => lv_error_text);
27124
27125 IF lv_return <> 0 THEN
27126 RAISE ex_logging_err;
27127 END IF;
27128
27129 --Duplicate records check for the records whose source is other than XML
27130 --Different SQL is used because in XML we can identify the latest records
27131 --whereas in batch load we cannot.
27132 /*
27133 v_sql_stmt := 02;
27134 lv_sql_stmt :=
27135 'UPDATE msc_st_item_categories mic1 '
27136 ||' SET process_flag = '||G_ERROR_FLG||','
27137 ||' error_text = '||''''||lv_message_text||''''
27138 ||' WHERE EXISTS( SELECT 1 '
27139 ||' FROM msc_st_item_categories mic2'
27140 ||' WHERE mic2.sr_instance_code = mic1.sr_instance_code'
27141 ||' AND mic2.organization_code = mic1.organization_code'
27142 ||' AND NVL(mic2.company_name, '||''''||NULL_CHAR||''''||') = '
27143 ||' NVL(mic1.company_name, '||''''||NULL_CHAR||''''||')'
27144 ||' AND mic2.category_set_name = mic1.category_set_name'
27145 ||' AND mic2.category_name = mic1.category_name'
27146 ||' AND nvl(mic2.item_name, '||''''||NULL_CHAR||''''||') = '
27147 ||' nvl(mic1.item_name, '||''''||NULL_CHAR||''''||') '
27148 ||' AND mic2.sr_instance_code = mic1.sr_instance_code'
27149 ||' AND NVL(mic2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
27150 ||' GROUP BY sr_instance_code,organization_code,category_set_name,'
27151 ||' company_name,category_name,item_name'
27152 ||' HAVING COUNT(*) > 1)'
27153 ||' AND mic1.process_flag = '||G_IN_PROCESS
27154 ||' AND mic1.sr_instance_code = :v_instance_code'
27155 ||' AND NVL(mic1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
27156
27157
27158 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
27159 EXECUTE IMMEDIATE lv_sql_stmt
27160 USING v_instance_code;
27161 */
27162
27163 BEGIN
27164 OPEN c_udk;
27165 FETCH c_udk BULK COLLECT INTO lb_item, lb_cat, lb_cat_set, lb_org, lb_comp;
27166 CLOSE c_udk;
27167
27168 FORALL j IN lb_item.FIRST..lb_item.LAST
27169 UPDATE msc_st_item_categories
27170 SET process_flag = G_ERROR_FLG, error_text = lv_message_text
27171 WHERE sr_instance_code = v_instance_code
27172 AND item_name = lb_item(j)
27173 AND category_name = lb_cat(j)
27174 AND category_set_name = lb_cat_set(j)
27175 AND organization_code = lb_org(j)
27176 AND NVL(company_name, NULL_CHAR) = NVL(lb_comp(j), NULL_CHAR)
27177 AND NVL(message_id,NULL_VALUE) = NULL_VALUE
27178 AND process_flag= G_IN_PROCESS;
27179
27180 EXCEPTION
27181 WHEN OTHERS THEN
27182 null;
27183 END;
27184
27185 lv_column_names :=
27186 'CATEGORY_NAME ||''~''||'
27187 ||'SR_INSTANCE_CODE ||''~''||'
27188 ||'DESCRIPTION ||''~''||'
27189 ||'DISABLE_DATE ||''~''||'
27190 ||'START_DATE_ACTIVE||''~''||'
27191 ||'END_DATE_ACTIVE ||''~''||'
27192 ||'ITEM_NAME ||''~''||'
27193 ||'ORGANIZATION_CODE||''~''||'
27194 ||'CATEGORY_SET_NAME||''~''||'
27195 ||'COMPANY_NAME ||''~''||'
27196 ||'SUMMARY_FLAG ||''~''||'
27197 ||'ENABLED_FLAG ||''~''||'
27198 ||'DELETED_FLAG';
27199
27200
27201 LOOP
27202 v_sql_stmt := 03;
27203 SELECT msc_st_batch_id_s.NEXTVAL
27204 INTO lv_batch_id
27205 FROM dual;
27206
27207 v_sql_stmt := 04;
27208 lv_sql_stmt :=
27209 'UPDATE msc_st_item_categories '
27210 ||' SET batch_id = :lv_batch_id'
27211 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
27212 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
27213 ||' AND sr_instance_code = :v_instance_code'
27214 ||' AND rownum <= '||v_batch_size;
27215
27216
27217 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
27218 EXECUTE IMMEDIATE lv_sql_stmt
27219 USING lv_batch_id,
27220 v_instance_code;
27221
27222 EXIT WHEN SQL%NOTFOUND;
27223
27224 OPEN c1(lv_batch_id);
27225 FETCH c1 BULK COLLECT INTO lb_rowid;
27226 CLOSE c1;
27227
27228 v_sql_stmt := 05;
27229 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
27230 UPDATE msc_st_item_categories
27231 SET st_transaction_id = msc_st_item_categories_s.NEXTVAL,
27232 refresh_id = v_refresh_id,
27233 last_update_date = v_current_date,
27234 last_updated_by = v_current_user,
27235 creation_date = v_current_date,
27236 created_by = v_current_user
27237 WHERE rowid = lb_rowid(j);
27238
27239 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
27240 (p_app_short_name => 'MSC',
27241 p_error_code => 'MSC_PP_NO_DELETION',
27242 p_message_text => lv_message_text,
27243 p_error_text => lv_error_text,
27244 p_token1 => 'TABLE_NAME',
27245 p_token_value1 => 'MSC_ST_ITEM_CATEGORIES');
27246
27247 IF lv_return <> 0 THEN
27248 RAISE ex_logging_err;
27249 END IF;
27250
27251 --Deletion is not allowed on this table.
27252 v_sql_stmt := 06;
27253 lv_sql_stmt :=
27254 'UPDATE msc_st_item_categories '
27255 ||' SET process_flag = '||G_ERROR_FLG||','
27256 ||' error_text = '||''''||lv_message_text||''''
27257 ||' WHERE deleted_flag = '||SYS_YES
27258 ||' AND process_flag = '||G_IN_PROCESS
27259 ||' AND batch_id = :lv_batch_id'
27260 ||' AND sr_instance_code = :v_instance_code';
27261
27262
27263
27264 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
27265 EXECUTE IMMEDIATE lv_sql_stmt
27266 USING lv_batch_id,
27267 v_instance_code;
27268
27269 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
27270 (p_app_short_name => 'MSC',
27271 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
27272 p_message_text => lv_message_text,
27273 p_error_text => lv_error_text,
27274 p_token1 => 'COLUMN_NAME',
27275 p_token_value1 => 'DELETED_FLAG',
27276 p_token2 => 'DEFAULT_VALUE',
27277 p_token_value2 => SYS_NO);
27278
27279 IF lv_return <> 0 THEN
27280 RAISE ex_logging_err;
27281 END IF;
27282
27283 lv_where_str :=
27284 ' AND NVL(deleted_flag,'||NULL_VALUE||') '
27285 ||' NOT IN(1,2)';
27286
27287 --Log a warning for those records where the deleted_flag has a value other
27288 --SYS_NO
27289 lv_return := MSC_ST_UTIL.LOG_ERROR
27290 (p_table_name => 'MSC_ST_ITEM_CATEGORIES',
27291 p_instance_code => v_instance_code,
27292 p_row => lv_column_names,
27293 p_severity => G_SEV_WARNING,
27294 p_message_text => lv_message_text,
27295 p_error_text => lv_error_text,
27296 p_batch_id => lv_batch_id,
27297 p_where_str => lv_where_str,
27298 p_col_name => 'DELETED_FLAG',
27299 p_debug => v_debug,
27300 p_default_value => SYS_NO);
27301
27302 IF lv_return <> 0 THEN
27303 RAISE ex_logging_err;
27304 END IF;
27305
27306 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
27307 (p_app_short_name => 'MSC',
27308 p_error_code => 'MSC_PP_INVALID_VALUE',
27309 p_message_text => lv_message_text,
27310 p_error_text => lv_error_text,
27311 p_token1 => 'COLUMN_NAME',
27312 p_token_value1 => 'ORGANIZATION_CODE');
27313
27314 IF lv_return <> 0 THEN
27315 RAISE ex_logging_err;
27316 END IF;
27317
27318 --Derive Organization_id
27319 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
27320 (p_table_name => 'MSC_ST_ITEM_CATEGORIES',
27321 p_org_partner_name => 'ORGANIZATION_CODE',
27322 p_org_partner_id => 'ORGANIZATION_ID',
27323 p_instance_code => v_instance_code,
27324 p_partner_type => G_ORGANIZATION,
27325 p_error_text => lv_error_text,
27326 p_batch_id => lv_batch_id,
27327 p_severity => G_SEV_ERROR,
27328 p_message_text => lv_message_text,
27329 p_debug => v_debug,
27330 p_row => lv_column_names);
27331
27332 IF lv_return <> 0 THEN
27333 RAISE ex_logging_err;
27334 END IF;
27335
27336 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
27337 (p_app_short_name => 'MSC',
27338 p_error_code => 'MSC_PP_INVALID_VALUE',
27339 p_message_text => lv_message_text,
27340 p_error_text => lv_error_text,
27341 p_token1 => 'COLUMN_NAME',
27342 p_token_value1 => 'ITEM_NAME');
27343
27344 IF lv_return <> 0 THEN
27345 RAISE ex_logging_err;
27346 END IF;
27347
27348 --Derive Inventory_item_id
27349 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
27350 (p_table_name => 'MSC_ST_ITEM_CATEGORIES',
27351 p_item_col_name => 'ITEM_NAME',
27352 p_item_col_id => 'INVENTORY_ITEM_ID',
27353 p_instance_id => v_instance_id,
27354 p_instance_code => v_instance_code,
27355 p_error_text => lv_error_text,
27356 p_batch_id => lv_batch_id,
27357 p_severity => G_SEV_ERROR,
27358 p_message_text => lv_message_text,
27359 p_debug => v_debug,
27360 p_row => lv_column_names);
27361
27362 IF lv_return <> 0 THEN
27363 RAISE ex_logging_err;
27364 END IF;
27365
27366
27367 --Derive sr_category_set_id
27368 v_sql_stmt := 07;
27369 lv_sql_stmt :=
27370 'UPDATE msc_st_item_categories '
27371 ||' SET sr_category_set_id = (SELECT local_id'
27372 ||' FROM msc_local_id_misc'
27373 ||' WHERE char1 = sr_instance_code'
27374 ||' AND NVL(char2, '||''''||NULL_CHAR||''''||') = '
27375 ||' NVL(company_name,'||''''||NULL_CHAR||''''||') '
27376 ||' AND char3 = category_set_name'
27377 ||' AND entity_name = ''SR_CATEGORY_SET_ID'' )'
27378 ||' WHERE sr_instance_code = :v_instance_code'
27379 ||' AND batch_id = :lv_batch_id'
27380 ||' AND process_flag = '||G_IN_PROCESS;
27381
27382
27383
27384 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
27385 EXECUTE IMMEDIATE lv_sql_stmt
27386 USING v_instance_code,
27387 lv_batch_id;
27388
27389 if(v_install_msc) THEN -- category set should exists
27390 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
27391 (p_app_short_name => 'MSC',
27392 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
27393 p_message_text => lv_message_text,
27394 p_error_text => lv_error_text,
27395 p_token1 => 'COLUMN_NAME',
27396 p_token_value1 => 'CATEGORY_SET_NAME');
27397
27398 IF lv_return <> 0 THEN
27399 RAISE ex_logging_err;
27400 END IF;
27401
27402 v_sql_stmt := 08;
27403 lv_sql_stmt :=
27404 'UPDATE msc_st_item_categories '
27405 ||' SET process_flag = '||G_ERROR_FLG||','
27406 ||' error_text = '||''''||lv_message_text||''''
27407 ||' WHERE NVL(sr_category_set_id,'||NULL_VALUE||') = '||NULL_VALUE
27408 ||' AND process_flag = '||G_IN_PROCESS
27409 ||' AND batch_id = :lv_batch_id'
27410 ||' AND sr_instance_code = :v_instance_code';
27411
27412
27413 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
27414 EXECUTE IMMEDIATE lv_sql_stmt
27415 USING lv_batch_id,
27416 v_instance_code;
27417 END IF ; -- v_install_msc
27418
27419 --Derive sr_category_id
27420 v_sql_stmt := 09;
27421 lv_sql_stmt :=
27422 'UPDATE msc_st_item_categories '
27423 ||' SET sr_category_id = (SELECT local_id '
27424 ||' FROM msc_local_id_misc'
27425 ||' WHERE char1 = sr_instance_code'
27426 ||' AND NVL(char2, '||''''||NULL_CHAR||''''||') = '
27427 ||' NVL(company_name,'||''''||NULL_CHAR||''''||') '
27428 ||' AND char3 = category_name'
27429 ||' AND entity_name = ''SR_CATEGORY_ID'' )'
27430 ||' WHERE sr_instance_code = :v_instance_code'
27431 ||' AND batch_id = :lv_batch_id'
27432 ||' AND process_flag = '||G_IN_PROCESS;
27433
27434
27435 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
27436 EXECUTE IMMEDIATE lv_sql_stmt
27437 USING v_instance_code,
27438 lv_batch_id;
27439
27440 --Call to customised validation.
27441 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
27442 (ERRBUF => lv_error_text,
27443 RETCODE => lv_return,
27444 pBatchID => lv_batch_id,
27445 pInstanceCode => v_instance_code,
27446 pEntityName => 'MSC_ST_ITEM_CATEGORIES',
27447 pInstanceID => v_instance_id);
27448
27449 IF NVL(lv_return,0) <> 0 THEN
27450 RAISE ex_logging_err;
27451 END IF;
27452
27453 OPEN c2(lv_batch_id);
27454 FETCH c2 BULK COLLECT INTO lb_rowid ;
27455
27456 IF c2%ROWCOUNT > 0 THEN
27457
27458 v_sql_stmt := 10;
27459 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
27460 UPDATE msc_st_item_categories
27461 SET sr_category_id = msc_st_sr_category_id_s.NEXTVAL
27462 WHERE rowid = lb_rowid(j);
27463
27464 v_sql_stmt := 11;
27465 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
27466 INSERT INTO msc_local_id_misc
27467 (local_id,
27468 st_transaction_id,
27469 instance_id,
27470 entity_name,
27471 data_source_type,
27472 char1,
27473 char2,
27474 char3,
27475 SOURCE_ORG_ID,
27476 SOURCE_INVENTORY_ITEM_ID,
27477 SOURCE_CATEGORY_SET_ID,
27478 SOURCE_CATEGORY_ID,
27479 last_update_date,
27480 last_updated_by,
27481 creation_date,
27482 created_by)
27483 SELECT
27484 sr_category_id,
27485 st_transaction_id,
27486 v_instance_id,
27487 'SR_CATEGORY_ID',
27488 data_source_type,
27489 v_instance_code,
27490 company_name,
27491 category_name,
27492 SOURCE_ORG_ID,
27493 SOURCE_INVENTORY_ITEM_ID,
27494 SOURCE_SR_CATEGORY_SET_ID,
27495 SOURCE_SR_CATEGORY_ID,
27496 v_current_date,
27497 v_current_user,
27498 v_current_date,
27499 v_current_user
27500 FROM msc_st_item_categories
27501 WHERE rowid = lb_rowid(j);
27502
27503 END IF;
27504 CLOSE c2 ;
27505
27506 --Derive sr_category_id
27507 v_sql_stmt := 09;
27508 lv_sql_stmt :=
27509 'UPDATE msc_st_item_categories '
27510 ||' SET sr_category_id = (SELECT local_id '
27511 ||' FROM msc_local_id_misc'
27512 ||' WHERE char1 = sr_instance_code'
27513 ||' AND NVL(char2, '||''''||NULL_CHAR||''''||') = '
27514 ||' NVL(company_name,'||''''||NULL_CHAR||''''||') '
27515 ||' AND char3 = category_name'
27516 ||' AND entity_name = ''SR_CATEGORY_ID'' )'
27517 ||' WHERE sr_instance_code = :v_instance_code'
27518 ||' AND NVL(sr_category_id,'||NULL_VALUE||') = '||NULL_VALUE
27519 ||' AND batch_id = :lv_batch_id'
27520 ||' AND process_flag = '||G_IN_PROCESS;
27521
27522
27523 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
27524 EXECUTE IMMEDIATE lv_sql_stmt
27525 USING v_instance_code,
27526 lv_batch_id;
27527
27528
27529 v_sql_stmt := 12;
27530 lv_sql_stmt :=
27531 'UPDATE msc_st_item_categories '
27532 ||' SET summary_flag = ''N'' '
27533 ||' WHERE process_flag = '||G_IN_PROCESS
27534 ||' AND batch_id = :lv_batch_id'
27535 ||' AND sr_instance_code = :v_instance_code';
27536
27537
27538 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
27539 EXECUTE IMMEDIATE lv_sql_stmt
27540 USING lv_batch_id,
27541 v_instance_code;
27542
27543 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
27544 (p_table_name => 'MSC_ST_ITEM_CATEGORIES',
27545 p_instance_id => v_instance_id,
27546 p_instance_code => v_instance_code,
27547 p_process_flag => G_VALID,
27548 p_error_text => lv_error_text,
27549 p_debug => v_debug,
27550 p_batch_id => lv_batch_id);
27551
27552 IF lv_return <> 0 THEN
27553 RAISE ex_logging_err;
27554 END IF;
27555
27556 lv_return := MSC_ST_UTIL.LOG_ERROR
27557 (p_table_name => 'MSC_ST_ITEM_CATEGORIES',
27558 p_instance_code => v_instance_code,
27559 p_row => lv_column_names,
27560 p_severity => G_SEV_ERROR,
27561 p_message_text => NULL,
27562 p_error_text => lv_error_text,
27563 p_debug => v_debug,
27564 p_batch_id => lv_batch_id);
27565
27566 IF lv_return <> 0 THEN
27567 RAISE ex_logging_err;
27568 END IF;
27569 COMMIT;
27570
27571 -- ODP change
27572 -- Call the procedure to insert categories into msd_st_level_values
27573 IF(v_install_msd) THEN
27574 lv_sql_stmt := ' DECLARE errbuf varchar2(250);'
27575 ||' retcode number ;'
27576 || ' BEGIN '
27577 ||' MSD_CL_PRE_PROCESS.LOAD_CATEGORY'
27578 ||' (ERRBUF => errbuf ,'
27579 ||' RETCODE => retcode ,'
27580 ||' p_instance_id => :v_instance_id,'
27581 ||' p_batch_id => :lv_batch_id ,'
27582 ||' p_link => :p_item_rollup);'
27583 ||' IF ( retcode = '||G_WARNING||') THEN'
27584 ||' MSC_CL_PRE_PROCESS.v_flag := '||SYS_YES||';'
27585 ||' END IF;'
27586 ||' END ;';
27587
27588 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
27589
27590 EXECUTE IMMEDIATE lv_sql_stmt
27591 USING v_instance_id,
27592 lv_batch_id,
27593 v_item_rollup;
27594 END IF ;
27595 COMMIT;
27596
27597
27598 END LOOP;
27599
27600 EXCEPTION
27601 WHEN too_many_rows THEN
27602 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_CATEGORY'||'('
27603 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
27604 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
27605 ROLLBACK;
27606
27607 WHEN ex_logging_err THEN
27608 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
27609 ROLLBACK;
27610
27611 WHEN OTHERS THEN
27612 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_CATEGORY'||'('
27613 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
27614 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
27615 ROLLBACK;
27616
27617 END LOAD_CATEGORY;
27618
27619
27620 /*==========================================================================+
27621 | DESCRIPTION : This function performs the validation and loads the data |
27622 | for business object Sourcing Rules. |
27623 +==========================================================================*/
27624 PROCEDURE LOAD_SOURCING_RULE IS
27625
27626 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
27627 TYPE CurTyp IS REF CURSOR;
27628 c1 CurTyp;
27629 lb_rowid RowidTab;
27630
27631 lv_column_names VARCHAR2(5000); -- Stores cocatenated column names
27632 lv_return NUMBER;
27633 lv_error_text VARCHAR2(250);
27634 lv_where_str VARCHAR2(5000);
27635 lv_sql_stmt VARCHAR2(5000);
27636 lv_cursor_stmt VARCHAR2(5000);
27637
27638 lv_default_sourcing_rule msc_st_item_sourcing.sourcing_rule_name%TYPE
27639 := v_instance_code||':'||'SRULE' ;
27640 lv_default_assignment_set msc_st_item_sourcing.sourcing_rule_name%TYPE
27641 := 'ASET' ;
27642 lv_default_category_set msc_st_category_sets.category_set_name%TYPE := NULL_CHAR ;
27643 lv_batch_id msc_st_item_sourcing.batch_id%TYPE;
27644 lv_message_text msc_errors.error_text%TYPE;
27645
27646 ex_logging_err EXCEPTION;
27647
27648
27649 CURSOR c2(p_batch_id NUMBER) IS
27650 SELECT rowid
27651 FROM msc_st_item_sourcing
27652 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
27653 AND sr_instance_code = v_instance_code
27654 AND batch_id = p_batch_id;
27655
27656 CURSOR c3(p_batch_id NUMBER) IS
27657 SELECT max(rowid)
27658 FROM msc_st_item_sourcing
27659 WHERE process_flag = G_IN_PROCESS
27660 AND sr_instance_code = v_instance_code
27661 AND batch_id = p_batch_id
27662 AND NVL(sourcing_rule_id,NULL_VALUE) = NULL_VALUE
27663 AND deleted_flag = SYS_NO
27664 GROUP BY sr_instance_code,company_name,
27665 organization_code,sourcing_rule_name;
27666
27667 CURSOR c4(p_batch_id NUMBER) IS
27668 SELECT max(rowid)
27669 FROM msc_st_item_sourcing
27670 WHERE process_flag = G_IN_PROCESS
27671 AND sr_instance_code = v_instance_code
27672 AND batch_id = p_batch_id
27673 AND NVL(assignment_set_id,NULL_VALUE) = NULL_VALUE
27674 AND deleted_flag = SYS_NO
27675 GROUP BY sr_instance_code,company_name,
27676 assignment_set_name;
27677
27678 CURSOR c5(p_batch_id NUMBER) IS
27679 SELECT max(rowid)
27680 FROM msc_st_item_sourcing
27681 WHERE process_flag = G_IN_PROCESS
27682 AND sr_instance_code = v_instance_code
27683 AND batch_id = p_batch_id
27684 AND NVL(sr_receipt_id,NULL_VALUE) = NULL_VALUE
27685 AND deleted_flag = SYS_NO
27686 GROUP BY sr_instance_code,company_name,
27687 organization_code, sourcing_rule_name,
27688 receipt_organization_code,receipt_org_instance_code,effective_date;
27689
27690 CURSOR c6(p_batch_id NUMBER) IS
27691 SELECT max(rowid)
27692 FROM msc_st_item_sourcing
27693 WHERE process_flag = G_IN_PROCESS
27694 AND sr_instance_code = v_instance_code
27695 AND batch_id = p_batch_id
27696 AND NVL(sr_source_id,NULL_VALUE) = NULL_VALUE
27697 AND deleted_flag = SYS_NO
27698 GROUP BY sr_instance_code,company_name,
27699 organization_code, sourcing_rule_name,
27700 source_organization_code, source_org_instance_code,
27701 source_partner_site_code,source_partner_name,
27702 receipt_organization_code,receipt_org_instance_code,
27703 effective_date;
27704
27705 CURSOR c7(p_batch_id NUMBER) IS
27706 SELECT max(rowid)
27707 FROM msc_st_item_sourcing
27708 WHERE process_flag = G_IN_PROCESS
27709 AND sr_instance_code = v_instance_code
27710 AND batch_id = p_batch_id
27711 AND NVL(assignment_id,NULL_VALUE) = NULL_VALUE
27712 AND deleted_flag = SYS_NO
27713 GROUP BY sr_instance_code,company_name,
27714 organization_code,assignment_set_name,
27715 item_name, category_name ;
27716
27717
27718 BEGIN
27719
27720 --Duplicate records check for the records whose source is XML
27721
27722 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
27723 (p_app_short_name => 'MSC',
27724 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
27725 p_message_text => lv_message_text,
27726 p_error_text => lv_error_text);
27727
27728 IF lv_return <> 0 THEN
27729 RAISE ex_logging_err;
27730 END IF;
27731
27732 v_sql_stmt := 01;
27733
27734 lv_sql_stmt :=
27735 'UPDATE msc_st_item_sourcing msis1'
27736 ||' SET process_flag ='||G_ERROR_FLG||','
27737 ||' error_text = '||''''||lv_message_text||''''
27738 ||' WHERE message_id < ( SELECT max(message_id) FROM msc_st_item_sourcing msis2'
27739 ||' WHERE msis2.sr_instance_code = msis1.sr_instance_code'
27740 ||' AND NVL(msis2.organization_code,'||''''||NULL_CHAR||''''||') '
27741 ||' = NVL(msis1.organization_code,'||''''||NULL_CHAR||''''||') '
27742 ||' AND NVL(msis2.sourcing_rule_name,'||''''||NULL_CHAR||''''||') '
27743 ||' = NVL(msis1.sourcing_rule_name,'||''''||NULL_CHAR||''''||') '
27744 ||' AND NVL(msis2.assignment_set_name,'||''''||NULL_CHAR||''''||') '
27745 ||' = NVL(msis1.assignment_set_name,'||''''||NULL_CHAR||''''||') '
27746 ||' AND NVL(msis2.item_name,'||''''||NULL_CHAR||''''||') '
27747 ||' = NVL(msis1.item_name,'||''''||NULL_CHAR||''''||') '
27748 ||' AND NVL(msis2.category_name,'||''''||NULL_CHAR||''''||') '
27749 ||' = NVL(msis1.category_name,'||''''||NULL_CHAR||''''||') '
27750 ||' AND NVL(msis2.receipt_organization_code,'||''''||NULL_CHAR||''''||') '
27751 ||' = NVL(msis1.receipt_organization_code,'||''''||NULL_CHAR||''''||') '
27752 ||' AND NVL(msis2.source_organization_code,'||''''||NULL_CHAR||''''||') '
27753 ||' = NVL(msis1.source_organization_code,'||''''||NULL_CHAR||''''||') '
27754 ||' AND NVL(msis2.source_partner_name,'||''''||NULL_CHAR||''''||') '
27755 ||' = NVL(msis1.source_partner_name,'||''''||NULL_CHAR||''''||') '
27756 ||' AND NVL(msis2.source_partner_site_code,'||''''||NULL_CHAR||''''||') '
27757 ||' = NVL(msis1.source_partner_site_code,'||''''||NULL_CHAR||''''||') '
27758 ||' AND msis2.effective_date = msis1.effective_date'
27759 ||' AND msis2.process_flag = '||G_IN_PROCESS
27760 ||' AND NVL(msis2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||')'
27761 ||' AND msis1.process_flag = '||G_IN_PROCESS
27762 ||' AND msis1.sr_instance_code = :v_instance_code'
27763 ||' AND NVL(msis1.message_id,'||NULL_VALUE||')<> '||NULL_VALUE;
27764
27765
27766 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
27767
27768 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
27769
27770 --Duplicate records check for the records whose source is batch load
27771
27772 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
27773 (p_app_short_name => 'MSC',
27774 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
27775 p_message_text => lv_message_text,
27776 p_error_text => lv_error_text);
27777
27778 IF lv_return <> 0 THEN
27779 RAISE ex_logging_err;
27780 END IF;
27781
27782 v_sql_stmt := 02;
27783
27784 lv_sql_stmt :=
27785 'UPDATE msc_st_item_sourcing msis1'
27786 ||' SET process_flag ='||G_ERROR_FLG||','
27787 ||' error_text = '||''''||lv_message_text||''''
27788 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_item_sourcing msis2'
27789 ||' WHERE msis2.sr_instance_code = msis1.sr_instance_code'
27790 ||' AND NVL(msis2.organization_code,'||''''||NULL_CHAR||''''||') '
27791 ||' = NVL(msis1.organization_code,'||''''||NULL_CHAR||''''||') '
27792 ||' AND NVL(msis2.sourcing_rule_name,'||''''||NULL_CHAR||''''||') '
27793 ||' = NVL(msis1.sourcing_rule_name,'||''''||NULL_CHAR||''''||') '
27794 ||' AND NVL(msis2.assignment_set_name,'||''''||NULL_CHAR||''''||') '
27795 ||' = NVL(msis1.assignment_set_name,'||''''||NULL_CHAR||''''||') '
27796 ||' AND NVL(msis2.item_name,'||''''||NULL_CHAR||''''||') '
27797 ||' = NVL(msis1.item_name,'||''''||NULL_CHAR||''''||') '
27798 ||' AND NVL(msis2.category_name,'||''''||NULL_CHAR||''''||') '
27799 ||' = NVL(msis1.category_name,'||''''||NULL_CHAR||''''||') '
27800 ||' AND NVL(msis2.receipt_organization_code,'||''''||NULL_CHAR||''''||') '
27801 ||' = NVL(msis1.receipt_organization_code,'||''''||NULL_CHAR||''''||') '
27802 ||' AND NVL(msis2.source_organization_code,'||''''||NULL_CHAR||''''||') '
27803 ||' = NVL(msis1.source_organization_code,'||''''||NULL_CHAR||''''||') '
27804 ||' AND NVL(msis2.source_partner_name,'||''''||NULL_CHAR||''''||') '
27805 ||' = NVL(msis1.source_partner_name,'||''''||NULL_CHAR||''''||') '
27806 ||' AND NVL(msis2.source_partner_site_code,'||''''||NULL_CHAR||''''||') '
27807 ||' = NVL(msis1.source_partner_site_code,'||''''||NULL_CHAR||''''||') '
27808 ||' AND msis2.effective_date = msis1.effective_date'
27809 ||' AND msis2.process_flag = '||G_IN_PROCESS
27810 ||' AND NVL(msis2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
27811 ||' GROUP BY sr_instance_code,company_name,organization_code,sourcing_rule_name,'
27812 ||' assignment_set_name,item_name, category_name,receipt_organization_code,'
27813 ||' source_organization_code, source_partner_name, source_partner_site_code,effective_date'
27814 ||' HAVING COUNT(*) >1 )'
27815 ||' AND msis1.process_flag ='||G_IN_PROCESS
27816 ||' AND msis1.sr_instance_code = :v_instance_code'
27817 ||' AND NVL(msis1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
27818
27819
27820 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
27821
27822 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
27823
27824
27825 lv_column_names :=
27826 'SOURCING_RULE_NAME ||''~''||'
27827 ||'EFFECTIVE_DATE ||''~''||'
27828 ||'ALLOCATION_PERCENT ||''~''||'
27829 ||'SOURCE_TYPE ||''~''||'
27830 ||'PLANNING_ACTIVE ||''~''||'
27831 ||'ASSIGNMENT_TYPE ||''~''||'
27832 ||'ORGANIZATION_CODE ||''~''||'
27833 ||'SR_INSTANCE_CODE ||''~''||'
27834 ||'DISABLE_DATE ||''~''||'
27835 ||'RANK ||''~''||'
27836 ||'DESCRIPTION ||''~''||'
27837 ||'SHIP_METHOD ||''~''||'
27838 ||'ITEM_NAME ||''~''||'
27839 ||'CATEGORY_NAME ||''~''||'
27840 ||'RECEIPT_ORGANIZATION_CODE ||''~''||'
27841 ||'RECEIPT_ORG_INSTANCE_CODE ||''~''||'
27842 ||'SOURCE_ORGANIZATION_CODE ||''~''||'
27843 ||'SOURCE_ORG_INSTANCE_CODE ||''~''||'
27844 ||'SOURCE_PARTNER_NAME ||''~''||'
27845 ||'SOURCE_PARTNER_SITE_CODE ||''~''||'
27846 ||'COMPANY_NAME ||''~''||'
27847 ||'ASSIGNMENT_SET_NAME ||''~''||'
27848 ||'DELETED_FLAG' ;
27849
27850 BEGIN
27851 -- Get the default category set
27852 lv_sql_stmt := 01;
27853 lv_sql_stmt :=
27854 'SELECT category_set_name'
27855 ||' FROM msc_category_sets '
27856 ||' WHERE sr_instance_id = :v_instance_id'
27857 ||' AND default_flag = 1' ;
27858
27859
27860 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
27861
27862 EXECUTE IMMEDIATE lv_sql_stmt
27863 INTO lv_default_category_set
27864 USING v_instance_id;
27865 EXCEPTION
27866 WHEN NO_DATA_FOUND THEN
27867 BEGIN
27868
27869 lv_sql_stmt := 13;
27870 lv_sql_stmt :=
27871 'SELECT category_set_name '
27872 ||' FROM msc_st_category_sets '
27873 ||' WHERE sr_instance_id = :v_instance_id'
27874 ||' AND default_flag = 1'
27875 ||' AND deleted_flag = '||SYS_NO
27876 ||' AND process_flag ='|| G_VALID ;
27877
27878
27879 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
27880
27881 EXECUTE IMMEDIATE lv_sql_stmt
27882 INTO lv_default_category_set
27883 USING v_instance_id;
27884 EXCEPTION
27885 WHEN NO_DATA_FOUND THEN
27886 -- Set the message
27887 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
27888 (p_app_short_name => 'MSC',
27889 p_error_code => 'MSC_PP_DEF_CAT_NOT_EXISTS',
27890 p_message_text => lv_message_text,
27891 p_error_text => lv_error_text);
27892
27893 IF lv_return <> 0 THEN
27894 RAISE ex_logging_err;
27895 END IF;
27896 WHEN OTHERS THEN
27897 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_SOURCING_RULE'||'('
27898 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
27899 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
27900
27901 END ;
27902 WHEN OTHERS THEN
27903 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_CATEGORY'||'('
27904 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
27905 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
27906
27907 END;
27908
27909
27910
27911 -- Now processing by batch
27912
27913 LOOP
27914 v_sql_stmt := 03;
27915 lv_cursor_stmt :=
27916 ' SELECT msc_st_batch_id_s.NEXTVAL '
27917 ||' FROM dual';
27918
27919 OPEN c1 FOR lv_cursor_stmt;
27920 FETCH c1 INTO lv_batch_id;
27921 CLOSE c1;
27922
27923 v_sql_stmt := 04;
27924 lv_sql_stmt :=
27925 ' UPDATE msc_st_item_sourcing '
27926 ||' SET batch_id = :lv_batch_id'
27927 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
27928 ||' AND sr_instance_code = :v_instance_code'
27929 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
27930 ||' AND rownum <= '||v_batch_size;
27931
27932
27933 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
27934
27935 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
27936
27937 EXIT WHEN SQL%NOTFOUND;
27938
27939 OPEN c2(lv_batch_id);
27940 FETCH c2 BULK COLLECT INTO lb_rowid;
27941 CLOSE c2;
27942
27943 v_sql_stmt := 05;
27944 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
27945 UPDATE msc_st_item_sourcing
27946 SET st_transaction_id = msc_st_item_sourcing_s.NEXTVAL,
27947 refresh_id = v_refresh_id,
27948 last_update_date = v_current_date,
27949 last_updated_by = v_current_user,
27950 creation_date = v_current_date,
27951 created_by = v_current_user
27952 WHERE rowid = lb_rowid(j);
27953
27954 -- Set the error message
27955
27956 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
27957 (p_app_short_name => 'MSC',
27958 p_error_code => 'MSC_PP_NO_DELETION',
27959 p_message_text => lv_message_text,
27960 p_error_text => lv_error_text,
27961 p_token1 => 'TABLE_NAME',
27962 p_token_value1 => 'MSC_ST_ITEM_SOURCING');
27963
27964 IF lv_return <> 0 THEN
27965 RAISE ex_logging_err;
27966 END IF;
27967
27968 --Deletion is not allowed on this table.
27969
27970 v_sql_stmt := 06;
27971 lv_sql_stmt :=
27972 ' UPDATE msc_st_item_sourcing '
27973 ||' SET process_flag = '||G_ERROR_FLG||','
27974 ||' error_text = '||''''||lv_message_text||''''
27975 ||' WHERE deleted_flag = '||SYS_YES
27976 ||' AND process_flag = '||G_IN_PROCESS
27977 ||' AND batch_id = :lv_batch_id'
27978 ||' AND sr_instance_code = :v_instance_code';
27979
27980
27981 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
27982
27983 EXECUTE IMMEDIATE lv_sql_stmt
27984 USING lv_batch_id,
27985 v_instance_code;
27986
27987 -- Set the error message
27988 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
27989 (p_app_short_name => 'MSC',
27990 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
27991 p_message_text => lv_message_text,
27992 p_error_text => lv_error_text,
27993 p_token1 => 'COLUMN_NAME',
27994 p_token_value1 => 'DELETED_FLAG',
27995 p_token2 => 'DEFAULT_VALUE',
27996 p_token_value2 => SYS_NO );
27997
27998 IF lv_return <> 0 THEN
27999 RAISE ex_logging_err;
28000 END IF;
28001
28002 -- Check whether delete flag value is in (SYS_YES,SYS_NO),if not default to SYS_NO
28003
28004 lv_where_str :=
28005 ' AND NVL(deleted_flag,'||NULL_VALUE||') NOT IN(1,2)';
28006
28007 lv_return := MSC_ST_UTIL.LOG_ERROR
28008 (p_table_name => 'MSC_ST_ITEM_SOURCING',
28009 p_instance_code => v_instance_code,
28010 p_row => lv_column_names,
28011 p_severity => G_SEV_WARNING,
28012 p_message_text => lv_message_text,
28013 p_error_text => lv_error_text,
28014 p_batch_id => lv_batch_id,
28015 p_where_str => lv_where_str,
28016 p_col_name => 'DELETED_FLAG',
28017 p_debug => v_debug,
28018 p_default_value => SYS_NO);
28019
28020
28021 IF lv_return <> 0 THEN
28022 RAISE ex_logging_err;
28023 END IF;
28024
28025 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
28026 (p_app_short_name => 'MSC',
28027 p_error_code => 'MSC_PP_INVALID_VALUE',
28028 p_message_text => lv_message_text,
28029 p_error_text => lv_error_text,
28030 p_token1 => 'COLUMN_NAME',
28031 p_token_value1 => 'ASSIGNMENT_TYPE');
28032
28033 IF lv_return <> 0 THEN
28034 RAISE ex_logging_err;
28035 END IF;
28036
28037 -- Error out record where assignment_type is NOT IN (1,2,3,4,5,6)
28038 v_sql_stmt := 07;
28039 lv_sql_stmt:=
28040 'UPDATE msc_st_item_sourcing'
28041 ||' SET process_flag = '||G_ERROR_FLG||','
28042 ||' error_text = '||''''||lv_message_text||''''
28043 ||' WHERE sr_instance_code = :v_instance_code'
28044 ||' AND batch_id = :lv_batch_id'
28045 ||' AND process_flag = '||G_IN_PROCESS
28046 ||' AND NVL(assignment_type,'||NULL_VALUE||') NOT IN (1,2,3,4,5,6)' ;
28047
28048
28049 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
28050
28051 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
28052
28053 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
28054 (p_app_short_name => 'MSC',
28055 p_error_code => 'MSC_PP_INVALID_VALUE',
28056 p_message_text => lv_message_text,
28057 p_error_text => lv_error_text,
28058 p_token1 => 'COLUMN_NAME',
28059 p_token_value1 => 'SOURCE_TYPE');
28060
28061 IF lv_return <> 0 THEN
28062 RAISE ex_logging_err;
28063 END IF;
28064
28065
28066 -- Error out record where source_type is NOT IN (1,2,3)
28067
28068 v_sql_stmt := 08;
28069 lv_sql_stmt:=
28070 'UPDATE msc_st_item_sourcing'
28071 ||' SET process_flag = '||G_ERROR_FLG||','
28072 ||' error_text = '||''''||lv_message_text||''''
28073 ||' WHERE sr_instance_code = :v_instance_code'
28074 ||' AND batch_id = :lv_batch_id'
28075 ||' AND process_flag = '||G_IN_PROCESS
28076 ||' AND NVL(source_type,'||NULL_VALUE||') NOT IN (1,2,3)' ;
28077
28078
28079 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
28080
28081 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
28082
28083
28084 -- Set the message
28085
28086 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
28087 (p_app_short_name => 'MSC',
28088 p_error_code => 'MSC_PP_INVALID_VALUE',
28089 p_message_text => lv_message_text,
28090 p_error_text => lv_error_text,
28091 p_token1 => 'COLUMN_NAME',
28092 p_token_value1 => 'ORGANIZATION_CODE');
28093
28094 IF lv_return <> 0 THEN
28095 RAISE ex_logging_err;
28096 END IF;
28097
28098 -- Udpate organization_id for all the records
28099
28100 lv_return :=
28101 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name => 'MSC_ST_ITEM_SOURCING',
28102 p_org_partner_name =>'ORGANIZATION_CODE',
28103 p_org_partner_id =>'ORGANIZATION_ID',
28104 p_instance_code => v_instance_code,
28105 p_partner_type => G_ORGANIZATION,
28106 p_severity => G_SEV3_ERROR,
28107 p_message_text => lv_message_text,
28108 p_batch_id =>lv_batch_id,
28109 p_debug => v_debug,
28110 p_error_text =>lv_error_text);
28111
28112 IF(lv_return <> 0) then
28113 RAISE ex_logging_err;
28114 END IF;
28115
28116 -- Default sourcing rule
28117
28118 v_sql_stmt := 09;
28119
28120 lv_sql_stmt:=
28121 'UPDATE msc_st_item_sourcing'
28122 ||' SET sourcing_rule_name = '||''''||lv_default_sourcing_rule||''''
28123 ||' WHERE sr_instance_code = :v_instance_code'
28124 ||' AND batch_id = :lv_batch_id'
28125 ||' AND process_flag ='||G_IN_PROCESS
28126 ||' AND NVL(sourcing_rule_name,'||''''||NULL_CHAR||''''||') '
28127 ||' = '||''''||NULL_CHAR||'''' ;
28128
28129
28130 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
28131
28132 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
28133
28134
28135 -- Default assignment set name
28136
28137 v_sql_stmt := 10;
28138
28139 lv_sql_stmt:=
28140 'UPDATE msc_st_item_sourcing'
28141 ||' SET assignment_set_name = '||''''||lv_default_assignment_set||''''
28142 ||' WHERE sr_instance_code = :v_instance_code'
28143 ||' AND batch_id = :lv_batch_id'
28144 ||' AND process_flag ='||G_IN_PROCESS
28145 ||' AND NVL(assignment_set_name,'||''''||NULL_CHAR||''''||')'
28146 ||' = '||''''||NULL_CHAR||'''' ;
28147
28148
28149 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
28150
28151 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
28152
28153
28154 -- Set the error message
28155 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
28156 (p_app_short_name => 'MSC',
28157 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
28158 p_message_text => lv_message_text,
28159 p_error_text => lv_error_text,
28160 p_token1 => 'COLUMN_NAME',
28161 p_token_value1 => 'PLANNING_ACTIVE',
28162 p_token2 => 'DEFAULT_VALUE',
28163 p_token_value2 => SYS_YES );
28164
28165 IF lv_return <> 0 THEN
28166 RAISE ex_logging_err;
28167 END IF;
28168
28169
28170 -- Default planning_active as 1
28171
28172 lv_where_str := ' AND NVL(planning_active,'||NULL_VALUE||') NOT IN (1,2)';
28173
28174 lv_return := MSC_ST_UTIL.LOG_ERROR
28175 (p_table_name => 'MSC_ST_ITEM_SOURCING',
28176 p_instance_code => v_instance_code,
28177 p_row => lv_column_names,
28178 p_severity => G_SEV_WARNING,
28179 p_message_text => lv_message_text,
28180 p_error_text => lv_error_text,
28181 p_batch_id => lv_batch_id,
28182 p_where_str => lv_where_str,
28183 p_col_name => 'PLANNING_ACTIVE',
28184 p_debug => v_debug,
28185 p_default_value => SYS_YES );
28186
28187
28188 IF(lv_return <> 0) then
28189 RAISE ex_logging_err;
28190 END IF;
28191
28192 -- Set the message
28193
28194 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
28195 (p_app_short_name => 'MSC',
28196 p_error_code => 'MSC_PP_INVALID_VALUE',
28197 p_message_text => lv_message_text,
28198 p_error_text => lv_error_text,
28199 p_token1 => 'COLUMN_NAME',
28200 p_token_value1 => 'RECEIPT_ORGANIZATION_CODE');
28201
28202 IF lv_return <> 0 THEN
28203 RAISE ex_logging_err;
28204 END IF;
28205
28206 -- Update receipt_organization_id
28207 -- As of now our assumption is that receipt_org_instance_code is same as
28208 -- v_instance_code ,
28209
28210 lv_return :=
28211 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name => 'MSC_ST_ITEM_SOURCING',
28212 p_org_partner_name =>'RECEIPT_ORGANIZATION_CODE',
28213 p_org_partner_id =>'RECEIPT_ORGANIZATION_ID',
28214 p_instance_code => v_instance_code,
28215 p_partner_type => G_ORGANIZATION,
28216 p_severity => G_SEV3_ERROR,
28217 p_message_text => lv_message_text,
28218 p_batch_id =>lv_batch_id,
28219 p_debug => v_debug,
28220 p_error_text =>lv_error_text);
28221
28222 IF(lv_return <> 0) then
28223 RAISE ex_logging_err;
28224 END IF;
28225
28226
28227 /* -- Update sr_receipt_org_instance_id
28228 v_sql_stmt := 09;
28229
28230 lv_sql_stmt:=
28231 'UPDATE msc_st_item_sourcing msis'
28232 ||' SET receipt_org_instance_id = ( SELECT instance_id FROM msc_apps_instances mai'
28233 ||' WHERE mai.instance_code = msis.sr_instance_code)'
28234 ||' WHERE sr_instance_code = :v_instance_code'
28235 ||' AND batch_id = :lv_batch_id'
28236 ||' AND process_flag ='||G_IN_PROCESS
28237 ||' AND NVL(receipt_org_instance_code,'||''''||NULL_CHAR||''''||')'
28238 ||' <> '||''''||NULL_CHAR||'''' ;
28239
28240
28241 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
28242
28243 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id; */
28244
28245 v_sql_stmt := 11;
28246
28247 lv_sql_stmt:=
28248 'UPDATE msc_st_item_sourcing msis'
28249 ||' SET receipt_org_instance_code = :v_instance_code ,'
28250 ||' source_org_instance_code = :v_instance_code'
28251 ||' WHERE sr_instance_code = :v_instance_code'
28252 ||' AND batch_id = :lv_batch_id'
28253 ||' AND process_flag ='||G_IN_PROCESS ;
28254
28255
28256 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
28257
28258 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,v_instance_code,
28259 v_instance_code,lv_batch_id;
28260
28261 -- Set the message
28262
28263 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
28264 (p_app_short_name => 'MSC',
28265 p_error_code => 'MSC_PP_INVALID_VALUE',
28266 p_message_text => lv_message_text,
28267 p_error_text => lv_error_text,
28268 p_token1 => 'COLUMN_NAME',
28269 p_token_value1 => 'ITEM_NAME');
28270
28271 IF lv_return <> 0 THEN
28272 RAISE ex_logging_err;
28273 END IF;
28274
28275
28276 -- Derive inventory_item_id
28277
28278 lv_return :=
28279 msc_st_util.derive_item_id(p_table_name => 'MSC_ST_ITEM_SOURCING',
28280 p_item_col_name => 'ITEM_NAME',
28281 p_item_col_id => 'INVENTORY_ITEM_ID',
28282 p_instance_code => v_instance_code,
28283 p_instance_id => v_instance_id,
28284 p_severity => G_SEV3_ERROR,
28285 p_message_text => lv_message_text,
28286 p_batch_id => lv_batch_id,
28287 p_debug => v_debug,
28288 p_error_text => lv_error_text,
28289 p_check_org => FALSE);
28290
28291 IF(lv_return <> 0) then
28292 RAISE ex_logging_err;
28293 END IF;
28294
28295
28296 -- If assignment_type = 3 or 6 ITEM_NAME should be valid
28297
28298 v_sql_stmt:= 12;
28299 lv_sql_stmt:=
28300 'UPDATE msc_st_item_sourcing'
28301 ||' SET process_flag = '||G_ERROR_FLG||','
28302 ||' error_text = '||''''||lv_message_text||''''
28303 ||' WHERE (assignment_type IN (3,6) '
28304 ||' AND NVL(inventory_item_id,'||NULL_VALUE||')'
28305 ||' = '||NULL_VALUE||')'
28306 ||' AND sr_instance_code = :v_instance_code'
28307 ||' AND process_flag = '||G_IN_PROCESS
28308 ||' AND batch_id = :lv_batch_id';
28309
28310
28311 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
28312
28313 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
28314
28315 -- Set the message
28316
28317 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
28318 (p_app_short_name => 'MSC',
28319 p_error_code => 'MSC_PP_COL_VAL_NULL',
28320 p_message_text => lv_message_text,
28321 p_error_text => lv_error_text,
28322 p_token1 => 'COLUMN_NAME',
28323 p_token_value1 => 'CATEGORY_NAME');
28324
28325 IF lv_return <> 0 THEN
28326 RAISE ex_logging_err;
28327 END IF;
28328
28329 -- If assignment_type = 2 and 5 then category_name should not be NULL
28330 v_sql_stmt := 13;
28331 lv_sql_stmt :=
28332 'UPDATE msc_st_item_sourcing '
28333 ||' SET process_flag = '||G_ERROR_FLG||','
28334 ||' error_text = '||''''||lv_message_text||''''
28335 ||' WHERE NVL(category_name,'||''''||NULL_CHAR||''''||') '
28336 ||' = '||''''||NULL_CHAR||''''
28337 ||' AND assignment_type IN (2,5) '
28338 ||' AND sr_instance_code = :v_instance_code '
28339 ||' AND process_flag ='||G_IN_PROCESS
28340 ||' AND batch_id = :lv_batch_id';
28341
28342
28343 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
28344
28345 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
28346
28347 -- Update categroy_set_id
28348
28349 v_sql_stmt :=14;
28350
28351 lv_sql_stmt :=
28352 'UPDATE MSC_ST_ITEM_SOURCING msis'
28353 ||' SET category_set_id = ( SELECT local_id FROM msc_local_id_misc mlim'
28354 ||' WHERE entity_name = ''SR_CATEGORY_SET_ID'' '
28355 ||' AND instance_id = '||v_instance_id
28356 ||' AND mlim.char1 = msis.sr_instance_code'
28357 ||' AND NVL(mlim.char2,'||''''||NULL_CHAR||''''||') '
28358 ||' = NVL(msis.company_name,'||''''||NULL_CHAR||''''||') '
28359 ||' AND mlim.char3 = '||''''||lv_default_category_set||''''||')'
28360 ||' WHERE msis.assignment_type IN (2,5)'
28361 ||' AND sr_instance_code = :v_instance_code'
28362 ||' AND process_flag = '||G_IN_PROCESS
28363 ||' AND batch_id = :lv_batch_id';
28364
28365
28366 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
28367
28368 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
28369
28370
28371 -- Now derive sr_category_id from LID table
28372
28373 v_sql_stmt :=15;
28374
28375 lv_sql_stmt :=
28376 'UPDATE MSC_ST_ITEM_SOURCING msis'
28377 ||' SET category_id = ( SELECT local_id FROM msc_local_id_misc mlim'
28378 ||' WHERE entity_name = ''SR_CATEGORY_ID'' '
28379 ||' AND instance_id = '||v_instance_id
28380 ||' AND mlim.char1 = msis.sr_instance_code'
28381 ||' AND NVL(mlim.char2,'||''''||NULL_CHAR||''''||') '
28382 ||' = NVL(msis.company_name,'||''''||NULL_CHAR||''''||') '
28383 ||' AND mlim.char3 = msis.category_name )'
28384 ||' WHERE msis.assignment_type IN (2,5)'
28385 ||' AND NVL(category_name,'||''''||NULL_CHAR||''''||') '
28386 ||' <> '||''''||NULL_CHAR||''''
28387 ||' AND sr_instance_code = :v_instance_code'
28388 ||' AND process_flag = '||G_IN_PROCESS
28389 ||' AND batch_id = :lv_batch_id';
28390
28391
28392 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
28393
28394 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
28395
28396 -- Set the message
28397
28398 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
28399 (p_app_short_name => 'MSC',
28400 p_error_code => 'MSC_PP_INVALID_VALUE',
28401 p_message_text => lv_message_text,
28402 p_error_text => lv_error_text,
28403 p_token1 => 'COLUMN_NAME',
28404 p_token_value1 => 'CATEGORY_NAME');
28405
28406 IF lv_return <> 0 THEN
28407 RAISE ex_logging_err;
28408 END IF;
28409
28410 -- Error our records if category_id/category_set_id is NULL
28411 lv_sql_stmt :=
28412 'UPDATE msc_st_item_sourcing '
28413 ||' SET process_flag = '||G_ERROR_FLG||','
28414 ||' error_text = '||''''||lv_message_text||''''
28415 ||' WHERE (NVL(category_id,'||NULL_VALUE||') = '||NULL_VALUE
28416 ||' OR NVL(category_set_id,'||NULL_VALUE||') = '||NULL_VALUE||')'
28417 ||' AND assignment_type IN (2,5) '
28418 ||' AND sr_instance_code = :v_instance_code '
28419 ||' AND process_flag ='||G_IN_PROCESS
28420 ||' AND batch_id = :lv_batch_id';
28421
28422
28423 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
28424
28425 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
28426
28427 -- Set the message
28428
28429 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
28430 (p_app_short_name => 'MSC',
28431 p_error_code => 'MSC_PP_INVALID_VALUE',
28432 p_message_text => lv_message_text,
28433 p_error_text => lv_error_text,
28434 p_token1 => 'COLUMN_NAME',
28435 p_token_value1 => 'SOURCE_ORGANIZATION_CODE');
28436
28437 IF lv_return <> 0 THEN
28438 RAISE ex_logging_err;
28439 END IF;
28440
28441
28442 -- If source_type = 2(make at) then source_partner_name should be NULL
28443 -- And source_organization_code should be same as organization_code
28444
28445 v_sql_stmt :=16;
28446
28447 lv_sql_stmt :=
28448 'UPDATE MSC_ST_ITEM_SOURCING msis'
28449 ||' SET process_flag ='||G_ERROR_FLG||','
28450 ||' error_text = '||''''||lv_message_text||''''
28451 ||' WHERE NVL(source_partner_name,'||''''||NULL_CHAR||''''||') '
28452 ||' <> '||''''||NULL_CHAR||''''
28453 ||' AND NVL(source_organization_code,'||''''||NULL_CHAR||''''||') '
28454 ||' <> NVL(organization_code,'||''''||NULL_CHAR||''''||') '
28455 ||' AND source_type = 2 '
28456 ||' AND sr_instance_code = :v_instance_code '
28457 ||' AND process_flag = '||G_IN_PROCESS
28458 ||' AND batch_id = :lv_batch_id';
28459
28460
28461 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
28462
28463 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
28464
28465 -- Set the message
28466
28467 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
28468 (p_app_short_name => 'MSC',
28469 p_error_code => 'MSC_PP_COL_VAL_NULL',
28470 p_message_text => lv_message_text,
28471 p_error_text => lv_error_text,
28472 p_token1 => 'COLUMN_NAME',
28473 p_token_value1 => 'SOURCE_PARTNER_NAME');
28474
28475 IF lv_return <> 0 THEN
28476 RAISE ex_logging_err;
28477 END IF;
28478
28479
28480 -- If source_type = 3 then , source_partner_name should not be NULL
28481
28482 v_sql_stmt :=17;
28483
28484 lv_sql_stmt :=
28485 'UPDATE MSC_ST_ITEM_SOURCING msis'
28486 ||' SET process_flag ='||G_ERROR_FLG||','
28487 ||' error_text = '||''''||lv_message_text||''''
28488 ||' WHERE NVL(source_partner_name,'||''''||NULL_CHAR||''''||') '
28489 ||' = '||''''||NULL_CHAR||''''
28490 ||' AND source_type = 3 '
28491 ||' AND sr_instance_code = :v_instance_code '
28492 ||' AND process_flag = '||G_IN_PROCESS
28493 ||' AND batch_id = :lv_batch_id';
28494
28495
28496 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
28497
28498 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
28499
28500 -- Set the message
28501
28502 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
28503 (p_app_short_name => 'MSC',
28504 p_error_code => 'MSC_PP_INVALID_VALUE',
28505 p_message_text => lv_message_text,
28506 p_error_text => lv_error_text,
28507 p_token1 => 'COLUMN_NAME',
28508 p_token_value1 => 'SOURCE_PARTNER_NAME');
28509
28510 IF lv_return <> 0 THEN
28511 RAISE ex_logging_err;
28512 END IF;
28513
28514
28515 -- Now derive the source_partner_id
28516 lv_return :=
28517 msc_st_util.derive_partner_org_id(p_table_name => 'MSC_ST_ITEM_SOURCING',
28518 p_org_partner_name =>'SOURCE_PARTNER_NAME',
28519 p_org_partner_id =>'SOURCE_PARTNER_ID',
28520 p_instance_code => v_instance_code,
28521 p_partner_type => G_VENDOR,
28522 p_severity => G_SEV3_ERROR,
28523 p_message_text => lv_message_text,
28524 p_batch_id => lv_batch_id,
28525 p_debug => v_debug,
28526 p_error_text => lv_error_text);
28527
28528 IF(lv_return <> 0) then
28529 RAISE ex_logging_err;
28530 END IF;
28531
28532 -- Set the message
28533
28534 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
28535 (p_app_short_name => 'MSC',
28536 p_error_code => 'MSC_PP_INVALID_VALUE',
28537 p_message_text => lv_message_text,
28538 p_error_text => lv_error_text,
28539 p_token1 => 'COLUMN_NAME',
28540 p_token_value1 => 'SOURCE_PARTNER_SITE_CODE');
28541
28542 IF lv_return <> 0 THEN
28543 RAISE ex_logging_err;
28544 END IF;
28545
28546
28547 -- Derive source_partner_site_id
28548
28549 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
28550 (p_table_name => 'MSC_ST_ITEM_SOURCING',
28551 p_partner_name => 'SOURCE_PARTNER_NAME',
28552 p_partner_site_code => 'SOURCE_PARTNER_SITE_CODE',
28553 p_partner_site_id => 'SOURCE_PARTNER_SITE_ID',
28554 p_instance_code => v_instance_code,
28555 p_partner_type => G_VENDOR,
28556 p_batch_id => lv_batch_id ,
28557 p_severity => G_SEV3_ERROR,
28558 p_message_text => lv_message_text,
28559 p_debug => v_debug,
28560 p_error_text => lv_error_text);
28561
28562
28563 IF(lv_return <> 0) then
28564 RAISE ex_logging_err;
28565 END IF;
28566
28567 -- Set the message
28568
28569 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
28570 (p_app_short_name => 'MSC',
28571 p_error_code => 'MSC_PP_COL_VAL_NULL',
28572 p_message_text => lv_message_text,
28573 p_error_text => lv_error_text,
28574 p_token1 => 'COLUMN_NAME',
28575 p_token_value1 => 'SOURCE_ORGANIZATION_CODE');
28576
28577 IF lv_return <> 0 THEN
28578 RAISE ex_logging_err;
28579 END IF;
28580
28581
28582 -- If source_type = 1 then , source_organization_code should not be NULL
28583
28584 v_sql_stmt :=17;
28585
28586 lv_sql_stmt :=
28587 'UPDATE MSC_ST_ITEM_SOURCING msis'
28588 ||' SET process_flag ='||G_ERROR_FLG||','
28589 ||' error_text = '||''''||lv_message_text||''''
28590 ||' WHERE NVL(source_organization_code,'||''''||NULL_CHAR||''''||') '
28591 ||' = '||''''||NULL_CHAR||''''
28592 ||' AND source_type = 1 '
28593 ||' AND sr_instance_code = :v_instance_code '
28594 ||' AND process_flag = '||G_IN_PROCESS
28595 ||' AND batch_id = :lv_batch_id';
28596
28597
28598 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
28599
28600 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
28601
28602
28603 -- Set the message
28604
28605 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
28606 (p_app_short_name => 'MSC',
28607 p_error_code => 'MSC_PP_INVALID_VALUE',
28608 p_message_text => lv_message_text,
28609 p_error_text => lv_error_text,
28610 p_token1 => 'COLUMN_NAME',
28611 p_token_value1 => 'SOURCE_ORGANIZATION_CODE');
28612
28613 IF lv_return <> 0 THEN
28614 RAISE ex_logging_err;
28615 END IF;
28616
28617 -- Derive source_organization_id
28618
28619 lv_return :=
28620 msc_st_util.derive_partner_org_id(p_table_name => 'MSC_ST_ITEM_SOURCING',
28621 p_org_partner_name =>'SOURCE_ORGANIZATION_CODE',
28622 p_org_partner_id =>'SOURCE_ORGANIZATION_ID',
28623 p_instance_code => v_instance_code,
28624 p_partner_type => G_ORGANIZATION,
28625 p_severity => G_SEV3_ERROR,
28626 p_message_text => lv_message_text,
28627 p_batch_id => lv_batch_id,
28628 p_debug => v_debug,
28629 p_error_text => lv_error_text);
28630
28631 IF(lv_return <> 0) then
28632 RAISE ex_logging_err;
28633 END IF;
28634
28635 -- Udpate SOURCING_RULE_ID
28636 v_sql_stmt := 18;
28637
28638 lv_sql_stmt:=
28639 'UPDATE MSC_ST_ITEM_SOURCING msis'
28640 ||' SET sourcing_rule_id = (SELECT local_id '
28641 ||' FROM msc_local_id_misc mlim'
28642 ||' WHERE mlim.entity_name= ''SOURCING_RULE_ID'' '
28643 ||' AND mlim.char1 = msis.sr_instance_code'
28644 ||' AND NVL(mlim.char2,'||''''||NULL_CHAR||''''||') '
28645 ||' = NVL(msis.company_name,'||''''||NULL_CHAR||''''||') '
28646 ||' AND NVL(mlim.char3,'||''''||NULL_CHAR||''''||') '
28647 ||' = NVL(msis.organization_code,'||''''||NULL_CHAR||''''||') '
28648 ||' AND mlim.char4 = msis.sourcing_rule_name)'
28649 ||' WHERE sr_instance_code = :v_instance_code'
28650 ||' AND process_flag = '||G_IN_PROCESS
28651 ||' AND batch_id = :lv_batch_id';
28652
28653
28654 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
28655
28656 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
28657
28658 -- Udpate ASSIGNMENT_SET_ID
28659 v_sql_stmt := 19;
28660 lv_sql_stmt:=
28661 'UPDATE MSC_ST_ITEM_SOURCING msis'
28662 ||' SET assignment_set_id = (SELECT local_id'
28663 ||' FROM msc_local_id_misc mlim'
28664 ||' WHERE mlim.entity_name= ''ASSIGNMENT_SET_ID'' '
28665 ||' AND mlim.char1 = msis.sr_instance_code'
28666 ||' AND NVL(mlim.char2,'||''''||NULL_CHAR||''''||') '
28667 ||' = NVL(msis.company_name,'||''''||NULL_CHAR||''''||') '
28668 ||' AND mlim.char3 = msis.assignment_set_name)'
28669 ||' WHERE sr_instance_code = :v_instance_code'
28670 ||' AND process_flag = '||G_IN_PROCESS
28671 ||' AND batch_id = :lv_batch_id';
28672
28673
28674 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
28675
28676 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
28677
28678 -- Udpate SR_RECEIPT_ID
28679
28680 v_sql_stmt := 20;
28681
28682 lv_sql_stmt:=
28683 'UPDATE MSC_ST_ITEM_SOURCING msis'
28684 ||' SET sr_receipt_id = (SELECT local_id'
28685 ||' FROM msc_local_id_misc mlim'
28686 ||' WHERE mlim.entity_name= ''SR_RECEIPT_ID'' '
28687 ||' AND mlim.char1 = msis.sr_instance_code'
28688 ||' AND NVL(mlim.char2,'||''''||NULL_CHAR||''''||') '
28689 ||' = NVL(msis.company_name,'||''''||NULL_CHAR||''''||') '
28690 ||' AND NVL(mlim.char3,'||''''||NULL_CHAR||''''||') '
28691 ||' = NVL(msis.organization_code,'||''''||NULL_CHAR||''''||') '
28692 ||' AND mlim.char4 = msis.sourcing_rule_name'
28693 ||' AND NVL(mlim.char5, '||''''||NULL_CHAR||''''||') '
28694 ||' = NVL(msis.receipt_organization_code,'||''''||NULL_CHAR||''''||') '
28695 ||' AND NVL(mlim.char6, '||''''||NULL_CHAR||''''||') '
28696 ||' = NVL(msis.receipt_org_instance_code,'||''''||NULL_CHAR||''''||') '
28697 ||' AND mlim.date1 = msis.effective_date)'
28698 ||' WHERE sr_instance_code = :v_instance_code'
28699 ||' AND process_flag = '||G_IN_PROCESS
28700 ||' AND batch_id = :lv_batch_id';
28701
28702
28703 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
28704
28705 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
28706
28707
28708
28709 -- Udpate SR_SOURCE_ID
28710 v_sql_stmt := 21;
28711
28712 lv_sql_stmt:=
28713 'UPDATE MSC_ST_ITEM_SOURCING msis'
28714 ||' SET sr_source_id = (SELECT local_id'
28715 ||' FROM msc_local_id_misc mlim'
28716 ||' WHERE mlim.entity_name= ''SR_SOURCE_ID'' '
28717 ||' AND mlim.char1 = msis.sr_instance_code'
28718 ||' AND NVL(mlim.char2,'||''''||NULL_CHAR||''''||') '
28719 ||' = NVL(msis.company_name,'||''''||NULL_CHAR||''''||') '
28720 ||' AND NVL(mlim.char3,'||''''||NULL_CHAR||''''||') '
28721 ||' = NVL(msis.organization_code,'||''''||NULL_CHAR||''''||') '
28722 ||' AND mlim.char4 = msis.sourcing_rule_name'
28723 ||' AND NVL(mlim.char5,'||''''||NULL_CHAR||''''||') '
28724 ||' = NVL(msis.source_organization_code,'||''''||NULL_CHAR||''''||') '
28725 ||' AND NVL(mlim.char6, '||''''||NULL_CHAR||''''||') '
28726 ||' = NVL(msis.source_org_instance_code,'||''''||NULL_CHAR||''''||') '
28727 ||' AND NVL(mlim.char7,'||''''||NULL_CHAR||''''||') '
28728 ||' = NVL(msis.source_partner_site_code,'||''''||NULL_CHAR||''''||') '
28729 ||' AND NVL(mlim.char8, '||''''||NULL_CHAR||''''||') '
28730 ||' = NVL(msis.source_partner_name,'||''''||NULL_CHAR||''''||') '
28731 ||' AND NVL(mlim.char9, '||''''||NULL_CHAR||''''||') '
28732 ||' = NVL(msis.receipt_organization_code,'||''''||NULL_CHAR||''''||') '
28733 ||' AND NVL(mlim.char10,'||''''||NULL_CHAR||''''||') '
28734 ||' = NVL(msis.receipt_org_instance_code,'||''''||NULL_CHAR||''''||') '
28735 ||' AND mlim.date1 = msis.effective_date)'
28736 ||' WHERE sr_instance_code = :v_instance_code'
28737 ||' AND process_flag ='||G_IN_PROCESS
28738 ||' AND batch_id = :lv_batch_id';
28739
28740
28741 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
28742
28743 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
28744
28745
28746 -- Udpate assignment_id
28747 v_sql_stmt := 22;
28748
28749 lv_sql_stmt:=
28750 'UPDATE MSC_ST_ITEM_SOURCING msis'
28751 ||' SET assignment_id = (SELECT local_id '
28752 ||' FROM msc_local_id_misc mlim'
28753 ||' WHERE mlim.entity_name= ''ASSIGNMENT_ID'' '
28754 ||' AND mlim.instance_id = '||v_instance_id
28755 ||' AND mlim.char1 = msis.sr_instance_code'
28756 ||' AND NVL(mlim.char2,'||''''||NULL_CHAR||''''||') '
28757 ||' = NVL(msis.company_name,'||''''||NULL_CHAR||''''||') '
28758 ||' AND NVL(mlim.char3,'||''''||NULL_CHAR||''''||') '
28759 ||' = NVL(msis.organization_code,'||''''||NULL_CHAR||''''||') '
28760 ||' AND mlim.char4 = msis.assignment_set_name'
28761 ||' AND NVL(mlim.char5,'||''''||NULL_CHAR||''''||') '
28762 ||' = NVL(msis.category_name,'||''''||NULL_CHAR||''''||') '
28763 ||' AND NVL(mlim.char6,'||''''||NULL_CHAR||''''||') '
28764 ||' = NVL(msis.item_name,'||''''||NULL_CHAR||''''||')) '
28765 ||' WHERE sr_instance_code = :v_instance_code'
28766 ||' AND process_flag ='||G_IN_PROCESS
28767 ||' AND batch_id = :lv_batch_id';
28768
28769
28770 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
28771
28772 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
28773
28774 -- Set the message
28775
28776 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
28777 (p_app_short_name => 'MSC',
28778 p_error_code => 'MSC_PP_DELETE_FAIL',
28779 p_message_text => lv_message_text,
28780 p_error_text => lv_error_text);
28781
28782 IF lv_return <> 0 THEN
28783 RAISE ex_logging_err;
28784 END IF;
28785
28786 -- Error out records if any id derivation fails and deleted_flag = 1
28787 v_sql_stmt := 23;
28788 lv_sql_stmt:=
28789 ' UPDATE MSC_ST_ITEM_SOURCING msis'
28790 ||' SET process_flag = '||G_ERROR_FLG||','
28791 ||' error_text = '||''''||lv_message_text||''''
28792 ||' WHERE ( NVL(sourcing_rule_id,'||NULL_VALUE||') ='||NULL_VALUE
28793 ||' OR NVL(sr_receipt_id,'||NULL_VALUE||') = '||NULL_VALUE
28794 ||' OR NVL(sr_receipt_id,'||NULL_VALUE||') = '||NULL_VALUE
28795 ||' OR NVL(sr_source_id,'||NULL_VALUE||') = '||NULL_VALUE
28796 ||' OR NVL(assignment_id,'||NULL_VALUE||') = '||NULL_VALUE||')'
28797 ||' AND sr_instance_code = :v_instance_code'
28798 ||' AND deleted_flag = '||SYS_YES
28799 ||' AND process_flag ='||G_IN_PROCESS
28800 ||' AND batch_id = :lv_batch_id';
28801
28802
28803 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
28804
28805 --Call to customised validation.
28806
28807 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
28808 (ERRBUF => lv_error_text,
28809 RETCODE => lv_return,
28810 pBatchID => lv_batch_id,
28811 pInstanceCode => v_instance_code,
28812 pEntityName => 'MSC_ST_ITEM_SOURCING',
28813 pInstanceID => v_instance_id);
28814
28815 IF NVL(lv_return,0) <> 0 THEN
28816 RAISE ex_logging_err;
28817 END IF;
28818
28819 -- Genearte sourcing rule id
28820 v_sql_stmt := 24;
28821
28822 OPEN c3(lv_batch_id);
28823 FETCH c3 BULK COLLECT INTO lb_rowid ;
28824
28825 IF c3%ROWCOUNT > 0 THEN
28826
28827 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
28828
28829 UPDATE msc_st_item_sourcing
28830 SET sourcing_rule_id = msc_st_sourcing_rule_id_s.NEXTVAL
28831 WHERE rowid = lb_rowid(j);
28832
28833 v_sql_stmt := 25;
28834
28835 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
28836
28837 -- Insert into the LID table
28838
28839 INSERT INTO msc_local_id_misc
28840 (local_id,
28841 st_transaction_id,
28842 instance_id,
28843 entity_name,
28844 data_source_type,
28845 char1,
28846 char2,
28847 char3,
28848 char4,
28849 SOURCE_ORG_ID,
28850 SOURCE_ASSIGNMENT_SET_ID,
28851 SOURCE_INVENTORY_ITEM_ID,
28852 SOURCE_CATEGORY_SET_ID,
28853 SOURCE_ASSIGNMENT_ID,
28854 SOURCE_CATEGORY_ID,
28855 SOURCE_SOURCING_RULE_ID,
28856 last_update_date,
28857 last_updated_by,
28858 creation_date,
28859 created_by )
28860 SELECT
28861 sourcing_rule_id,
28862 st_transaction_id,
28863 v_instance_id,
28864 'SOURCING_RULE_ID',
28865 data_source_type,
28866 sr_instance_code,
28867 company_name,
28868 organization_code,
28869 sourcing_rule_name,
28870 SOURCE_ORG_ID,
28871 SOURCE_ASSIGNMENT_SET_ID,
28872 SOURCE_INVENTORY_ITEM_ID,
28873 SOURCE_CATEGORY_SET_ID,
28874 SOURCE_ASSIGNMENT_ID,
28875 SOURCE_CATEGORY_ID,
28876 SOURCE_SOURCING_RULE_ID,
28877 v_current_date,
28878 v_current_user,
28879 v_current_date,
28880 v_current_user
28881 FROM msc_st_item_sourcing
28882 WHERE rowid = lb_rowid(j);
28883
28884 END IF;
28885 CLOSE c3;
28886
28887 -- Udpate SOURCING_RULE_ID
28888 v_sql_stmt := 26;
28889
28890 lv_sql_stmt:=
28891 'UPDATE MSC_ST_ITEM_SOURCING msis'
28892 ||' SET sourcing_rule_id = (SELECT local_id '
28893 ||' FROM msc_local_id_misc mlim'
28894 ||' WHERE mlim.entity_name= ''SOURCING_RULE_ID'' '
28895 ||' AND mlim.char1 = msis.sr_instance_code'
28896 ||' AND NVL(mlim.char2,'||''''||NULL_CHAR||''''||') '
28897 ||' = NVL(msis.company_name,'||''''||NULL_CHAR||''''||') '
28898 ||' AND NVL(mlim.char3,'||''''||NULL_CHAR||''''||') '
28899 ||' = NVL(msis.organization_code,'||''''||NULL_CHAR||''''||') '
28900 ||' AND mlim.char4 = msis.sourcing_rule_name)'
28901 ||' WHERE sr_instance_code = :v_instance_code'
28902 ||' AND NVL(sourcing_rule_id,'||NULL_VALUE||') = '||NULL_VALUE
28903 ||' AND process_flag = '||G_IN_PROCESS
28904 ||' AND batch_id = :lv_batch_id';
28905
28906
28907 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
28908
28909 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
28910
28911
28912 -- Genearte assignment_set_id
28913
28914 v_sql_stmt := 27;
28915
28916 OPEN c4(lv_batch_id);
28917 FETCH c4 BULK COLLECT INTO lb_rowid ;
28918
28919 IF c4%ROWCOUNT > 0 THEN
28920
28921 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
28922
28923 UPDATE msc_st_item_sourcing
28924 SET assignment_set_id = msc_st_assignment_set_id_s.NEXTVAL
28925 WHERE rowid = lb_rowid(j);
28926
28927 v_sql_stmt := 28;
28928
28929 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
28930
28931 -- Insert into the LID table
28932
28933 INSERT INTO msc_local_id_misc
28934 (local_id,
28935 st_transaction_id,
28936 instance_id,
28937 entity_name,
28938 data_source_type,
28939 char1,
28940 char2,
28941 char3,
28942 SOURCE_ASSIGNMENT_SET_ID,
28943 last_update_date,
28944 last_updated_by,
28945 creation_date,
28946 created_by )
28947 SELECT
28948 assignment_set_id,
28949 st_transaction_id,
28950 v_instance_id,
28951 'ASSIGNMENT_SET_ID',
28952 data_source_type,
28953 sr_instance_code,
28954 company_name,
28955 assignment_set_name,
28956 SOURCE_ASSIGNMENT_SET_ID,
28957 v_current_date,
28958 v_current_user,
28959 v_current_date,
28960 v_current_user
28961 FROM msc_st_item_sourcing
28962 WHERE rowid = lb_rowid(j);
28963
28964 END IF;
28965 CLOSE c4;
28966
28967 -- Udpate ASSIGNMENT_SET_ID
28968 v_sql_stmt := 29;
28969 lv_sql_stmt:=
28970 'UPDATE MSC_ST_ITEM_SOURCING msis'
28971 ||' SET assignment_set_id = (SELECT local_id'
28972 ||' FROM msc_local_id_misc mlim'
28973 ||' WHERE mlim.entity_name= ''ASSIGNMENT_SET_ID'' '
28974 ||' AND mlim.char1 = msis.sr_instance_code'
28975 ||' AND NVL(mlim.char2,'||''''||NULL_CHAR||''''||') '
28976 ||' = NVL(msis.company_name,'||''''||NULL_CHAR||''''||') '
28977 ||' AND mlim.char3 = msis.assignment_set_name)'
28978 ||' WHERE sr_instance_code = :v_instance_code'
28979 ||' AND NVL(assignment_set_id,'||NULL_VALUE||') = '||NULL_VALUE
28980 ||' AND process_flag = '||G_IN_PROCESS
28981 ||' AND batch_id = :lv_batch_id';
28982
28983
28984 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
28985
28986 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
28987
28988 -- Genearte sr_receipt_id
28989 v_sql_stmt := 30;
28990
28991 OPEN c5(lv_batch_id);
28992 FETCH c5 BULK COLLECT INTO lb_rowid ;
28993
28994 IF c5%ROWCOUNT > 0 THEN
28995
28996 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
28997
28998 UPDATE msc_st_item_sourcing
28999 SET sr_receipt_id = msc_st_sr_receipt_id_s.NEXTVAL
29000 WHERE rowid = lb_rowid(j);
29001
29002 v_sql_stmt := 31;
29003
29004 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
29005
29006 -- Insert into the LID table
29007
29008 INSERT INTO msc_local_id_misc
29009 (local_id,
29010 st_transaction_id,
29011 instance_id,
29012 entity_name,
29013 data_source_type,
29014 char1,
29015 char2,
29016 char3,
29017 char4,
29018 char5,
29019 char6,
29020 date1,
29021 SOURCE_ORG_ID,
29022 SOURCE_ASSIGNMENT_SET_ID,
29023 SOURCE_INVENTORY_ITEM_ID,
29024 SOURCE_CATEGORY_SET_ID,
29025 SOURCE_CATEGORY_ID,
29026 SOURCE_ASSIGNMENT_ID,
29027 SOURCE_SOURCING_RULE_ID,
29028 SOURCE_SR_RECEIPT_ID,
29029 SOURCE_RECEIPT_ORGANIZATION_ID,
29030 last_update_date,
29031 last_updated_by,
29032 creation_date,
29033 created_by )
29034 SELECT
29035 sr_receipt_id,
29036 st_transaction_id,
29037 v_instance_id,
29038 'SR_RECEIPT_ID',
29039 data_source_type,
29040 v_instance_code,
29041 company_name,
29042 organization_code,
29043 sourcing_rule_name,
29044 receipt_organization_code,
29045 receipt_org_instance_code,
29046 effective_date,
29047 SOURCE_ORG_ID,
29048 SOURCE_ASSIGNMENT_SET_ID,
29049 SOURCE_INVENTORY_ITEM_ID,
29050 SOURCE_CATEGORY_SET_ID,
29051 SOURCE_CATEGORY_ID,
29052 SOURCE_ASSIGNMENT_ID,
29053 SOURCE_SOURCING_RULE_ID,
29054 SOURCE_SR_RECEIPT_ID,
29055 SOURCE_RECEIPT_ORGANIZATION_ID,
29056 v_current_date,
29057 v_current_user,
29058 v_current_date,
29059 v_current_user
29060 FROM msc_st_item_sourcing
29061 WHERE rowid = lb_rowid(j);
29062
29063 END IF;
29064 CLOSE c5;
29065
29066 -- Udpate SR_RECEIPT_ID
29067
29068 v_sql_stmt := 32;
29069
29070 lv_sql_stmt:=
29071 'UPDATE MSC_ST_ITEM_SOURCING msis'
29072 ||' SET sr_receipt_id = (SELECT local_id'
29073 ||' FROM msc_local_id_misc mlim'
29074 ||' WHERE mlim.entity_name= ''SR_RECEIPT_ID'' '
29075 ||' AND mlim.char1 = msis.sr_instance_code'
29076 ||' AND NVL(mlim.char2,'||''''||NULL_CHAR||''''||') '
29077 ||' = NVL(msis.company_name,'||''''||NULL_CHAR||''''||') '
29078 ||' AND NVL(mlim.char3,'||''''||NULL_CHAR||''''||') '
29079 ||' = NVL(msis.organization_code,'||''''||NULL_CHAR||''''||') '
29080 ||' AND mlim.char4 = msis.sourcing_rule_name'
29081 ||' AND NVL(mlim.char5, '||''''||NULL_CHAR||''''||') '
29082 ||' = NVL(msis.receipt_organization_code,'||''''||NULL_CHAR||''''||') '
29083 ||' AND NVL(mlim.char6, '||''''||NULL_CHAR||''''||') '
29084 ||' = NVL(msis.receipt_org_instance_code,'||''''||NULL_CHAR||''''||') '
29085 ||' AND mlim.date1 = msis.effective_date)'
29086 ||' WHERE sr_instance_code = :v_instance_code'
29087 ||' AND NVL(sr_receipt_id,'||NULL_VALUE||') = '||NULL_VALUE
29088 ||' AND process_flag = '||G_IN_PROCESS
29089 ||' AND batch_id = :lv_batch_id';
29090
29091
29092 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
29093
29094 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
29095
29096
29097 -- Genearte sr_source_id
29098
29099 v_sql_stmt := 33;
29100
29101 OPEN c6(lv_batch_id);
29102 FETCH c6 BULK COLLECT INTO lb_rowid ;
29103
29104 IF c6%ROWCOUNT > 0 THEN
29105
29106 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
29107
29108 UPDATE msc_st_item_sourcing
29109 SET sr_source_id = msc_st_sr_source_id_s.NEXTVAL
29110 WHERE rowid = lb_rowid(j);
29111
29112 v_sql_stmt := 34;
29113
29114 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
29115
29116 -- Insert into the LID table
29117
29118 INSERT INTO msc_local_id_misc
29119 (local_id,
29120 st_transaction_id,
29121 instance_id,
29122 entity_name,
29123 data_source_type,
29124 char1,
29125 char2,
29126 char3,
29127 char4,
29128 char5,
29129 char6,
29130 char7,
29131 char8,
29132 char9,
29133 char10,
29134 date1,
29135 SOURCE_ORG_ID,
29136 SOURCE_ASSIGNMENT_SET_ID,
29137 SOURCE_INVENTORY_ITEM_ID,
29138 SOURCE_CATEGORY_SET_ID,
29139 SOURCE_CATEGORY_ID,
29140 SOURCE_ASSIGNMENT_ID,
29141 SOURCE_SOURCING_RULE_ID,
29142 SOURCE_SR_RECEIPT_ID,
29143 SOURCE_RECEIPT_ORGANIZATION_ID,
29144 SOURCE_SOURCE_PARTNER_ID,
29145 SOURCE_SOURCE_PARTNER_SITE_ID,
29146 SOURCE_SOURCE_ORGANIZATION_ID,
29147 SOURCE_SR_SOURCE_ID,
29148 last_update_date,
29149 last_updated_by,
29150 creation_date,
29151 created_by )
29152 SELECT
29153 sr_source_id,
29154 st_transaction_id,
29155 v_instance_id,
29156 'SR_SOURCE_ID',
29157 data_source_type,
29158 sr_instance_code,
29159 company_name,
29160 organization_code,
29161 sourcing_rule_name,
29162 source_organization_code,
29163 source_org_instance_code,
29164 source_partner_site_code,
29165 source_partner_name,
29166 receipt_organization_code,
29167 receipt_org_instance_code,
29168 effective_date,
29169 SOURCE_ORG_ID,
29170 SOURCE_ASSIGNMENT_SET_ID,
29171 SOURCE_INVENTORY_ITEM_ID,
29172 SOURCE_CATEGORY_SET_ID,
29173 SOURCE_CATEGORY_ID,
29174 SOURCE_ASSIGNMENT_ID,
29175 SOURCE_SOURCING_RULE_ID,
29176 SOURCE_SR_RECEIPT_ID,
29177 SOURCE_RECEIPT_ORGANIZATION_ID,
29178 SOURCE_SOURCE_PARTNER_ID,
29179 SOURCE_SOURCE_PARTNER_SITE_ID,
29180 SOURCE_SOURCE_ORGANIZATION_ID,
29181 SOURCE_SR_SOURCE_ID,
29182 v_current_date,
29183 v_current_user,
29184 v_current_date,
29185 v_current_user
29186 FROM msc_st_item_sourcing
29187 WHERE rowid = lb_rowid(j);
29188
29189 END IF;
29190 CLOSE c6;
29191
29192 -- Udpate SR_SOURCE_ID
29193 v_sql_stmt := 35;
29194
29195 lv_sql_stmt:=
29196 'UPDATE MSC_ST_ITEM_SOURCING msis'
29197 ||' SET sr_source_id = (SELECT local_id'
29198 ||' FROM msc_local_id_misc mlim'
29199 ||' WHERE mlim.entity_name= ''SR_SOURCE_ID'' '
29200 ||' AND mlim.char1 = msis.sr_instance_code'
29201 ||' AND NVL(mlim.char2,'||''''||NULL_CHAR||''''||') '
29202 ||' = NVL(msis.company_name,'||''''||NULL_CHAR||''''||') '
29203 ||' AND NVL(mlim.char3,'||''''||NULL_CHAR||''''||') '
29204 ||' = NVL(msis.organization_code,'||''''||NULL_CHAR||''''||') '
29205 ||' AND mlim.char4 = msis.sourcing_rule_name'
29206 ||' AND NVL(mlim.char5,'||''''||NULL_CHAR||''''||') '
29207 ||' = NVL(msis.source_organization_code,'||''''||NULL_CHAR||''''||') '
29208 ||' AND NVL(mlim.char6, '||''''||NULL_CHAR||''''||') '
29209 ||' = NVL(msis.source_org_instance_code,'||''''||NULL_CHAR||''''||') '
29210 ||' AND NVL(mlim.char7,'||''''||NULL_CHAR||''''||') '
29211 ||' = NVL(msis.source_partner_site_code,'||''''||NULL_CHAR||''''||') '
29212 ||' AND NVL(mlim.char8, '||''''||NULL_CHAR||''''||') '
29213 ||' = NVL(msis.source_partner_name,'||''''||NULL_CHAR||''''||') '
29214 ||' AND NVL(mlim.char9, '||''''||NULL_CHAR||''''||') '
29215 ||' = NVL(msis.receipt_organization_code,'||''''||NULL_CHAR||''''||') '
29216 ||' AND NVL(mlim.char10,'||''''||NULL_CHAR||''''||') '
29217 ||' = NVL(msis.receipt_org_instance_code,'||''''||NULL_CHAR||''''||') '
29218 ||' AND mlim.date1 = msis.effective_date)'
29219 ||' WHERE sr_instance_code = :v_instance_code'
29220 ||' AND NVL(sr_source_id,'||NULL_VALUE||') = '||NULL_VALUE
29221 ||' AND process_flag ='||G_IN_PROCESS
29222 ||' AND batch_id = :lv_batch_id';
29223
29224
29225 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
29226
29227 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
29228
29229
29230
29231 -- Genearte assignment id
29232
29233 v_sql_stmt := 36;
29234
29235 OPEN c7(lv_batch_id);
29236 FETCH c7 BULK COLLECT INTO lb_rowid ;
29237
29238 IF c7%ROWCOUNT > 0 THEN
29239
29240 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
29241
29242 UPDATE msc_st_item_sourcing
29243 SET assignment_id = msc_st_assignment_id_s.NEXTVAL
29244 WHERE rowid = lb_rowid(j);
29245
29246 v_sql_stmt := 37;
29247
29248 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
29249 -- Insert into the LID table
29250
29251 INSERT INTO msc_local_id_misc
29252 (local_id,
29253 st_transaction_id,
29254 instance_id,
29255 entity_name,
29256 data_source_type,
29257 char1,
29258 char2,
29259 char3,
29260 char4,
29261 char5,
29262 char6,
29263 SOURCE_ORG_ID,
29264 SOURCE_ASSIGNMENT_SET_ID,
29265 SOURCE_INVENTORY_ITEM_ID,
29266 SOURCE_CATEGORY_SET_ID,
29267 SOURCE_CATEGORY_ID,
29268 SOURCE_ASSIGNMENT_ID,
29269 SOURCE_SOURCING_RULE_ID,
29270 last_update_date,
29271 last_updated_by,
29272 creation_date,
29273 created_by )
29274 SELECT
29275 assignment_id,
29276 st_transaction_id,
29277 v_instance_id,
29278 'ASSIGNMENT_ID',
29279 data_source_type,
29280 sr_instance_code,
29281 company_name,
29282 organization_code,
29283 assignment_set_name,
29284 category_name,
29285 item_name,
29286 SOURCE_ORG_ID,
29287 SOURCE_ASSIGNMENT_SET_ID,
29288 SOURCE_INVENTORY_ITEM_ID,
29289 SOURCE_CATEGORY_SET_ID,
29290 SOURCE_CATEGORY_ID,
29291 SOURCE_ASSIGNMENT_ID,
29292 SOURCE_SOURCING_RULE_ID,
29293 v_current_date,
29294 v_current_user,
29295 v_current_date,
29296 v_current_user
29297 FROM msc_st_item_sourcing
29298 WHERE rowid = lb_rowid(j);
29299
29300 END IF;
29301 CLOSE c7;
29302
29303 -- Update assignment_id
29304 v_sql_stmt := 38;
29305
29306 lv_sql_stmt:=
29307 'UPDATE MSC_ST_ITEM_SOURCING msis'
29308 ||' SET assignment_id = (SELECT local_id '
29309 ||' FROM msc_local_id_misc mlim'
29310 ||' WHERE mlim.entity_name= ''ASSIGNMENT_ID'' '
29311 ||' AND mlim.instance_id = '||v_instance_id
29312 ||' AND mlim.char1 = msis.sr_instance_code'
29313 ||' AND NVL(mlim.char2,'||''''||NULL_CHAR||''''||') '
29314 ||' = NVL(msis.company_name,'||''''||NULL_CHAR||''''||') '
29315 ||' AND NVL(mlim.char3,'||''''||NULL_CHAR||''''||') '
29316 ||' = NVL(msis.organization_code,'||''''||NULL_CHAR||''''||') '
29317 ||' AND mlim.char4 = msis.assignment_set_name'
29318 ||' AND NVL(mlim.char5,'||''''||NULL_CHAR||''''||') '
29319 ||' = NVL(msis.category_name,'||''''||NULL_CHAR||''''||') '
29320 ||' AND NVL(mlim.char6,'||''''||NULL_CHAR||''''||') '
29321 ||' = NVL(msis.item_name,'||''''||NULL_CHAR||''''||')) '
29322 ||' WHERE sr_instance_code = :v_instance_code'
29323 ||' AND NVL(assignment_id,'||NULL_VALUE||') = '||NULL_VALUE
29324 ||' AND process_flag ='||G_IN_PROCESS
29325 ||' AND batch_id = :lv_batch_id';
29326
29327
29328 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
29329
29330 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
29331
29332
29333 v_sql_stmt := 39;
29334 lv_sql_stmt :=
29335 'INSERT INTO MSC_ST_SOURCING_RULES'
29336 ||' ( SR_SOURCING_RULE_ID,'
29337 ||' SOURCING_RULE_NAME,'
29338 ||' ORGANIZATION_ID,'
29339 ||' DESCRIPTION,'
29340 ||' STATUS,'
29341 ||' SOURCING_RULE_TYPE,'
29342 ||' PLANNING_ACTIVE,'
29343 ||' DELETED_FLAG,'
29344 ||' SR_INSTANCE_ID,'
29345 ||' REFRESH_ID,'
29346 ||' LAST_UPDATED_BY,'
29347 ||' LAST_UPDATE_DATE,'
29348 ||' CREATED_BY,'
29349 ||' CREATION_DATE)'
29350 ||' SELECT DISTINCT '
29351 ||' SOURCING_RULE_ID,'
29352 ||' SOURCING_RULE_NAME,'
29353 ||' ORGANIZATION_ID,'
29354 ||' DESCRIPTION,'
29355 ||' 1, '/* Hard coding as 1*/
29356 ||' 1, '/*Always as sourcing rule not Bill of Distribution*/
29357 ||' PLANNING_ACTIVE,'
29358 ||' DELETED_FLAG,'
29359 || v_instance_id||','
29360 ||' REFRESH_ID,'
29361 ||' LAST_UPDATED_BY,'
29362 ||' LAST_UPDATE_DATE,'
29363 ||' CREATED_BY,'
29364 ||' CREATION_DATE '
29365 ||' FROM MSC_ST_ITEM_SOURCING mis'
29366 ||' WHERE SR_INSTANCE_CODE = :v_instance_code'
29367 ||' AND process_flag = '||G_IN_PROCESS
29368 ||' AND batch_id = :lv_batch_id'
29369 ||' AND (SOURCING_RULE_ID)' /* Added for Bug 8485612*/
29370 ||' NOT IN ( SELECT MSR.SR_SOURCING_RULE_ID'
29371 ||' FROM MSC_ST_SOURCING_RULES msr'
29372 ||' WHERE msr.SR_INSTANCE_ID='||v_instance_id||')'
29373 ;
29374
29375
29376 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
29377
29378 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
29379
29380 v_sql_stmt := 40;
29381 lv_sql_stmt :=
29382 'INSERT INTO MSC_ST_SR_RECEIPT_ORG'
29383 ||' ( SR_RECEIPT_ID,'
29384 ||' SR_SR_RECEIPT_ORG,'
29385 ||' RECEIPT_ORG_INSTANCE_ID,'
29386 ||' SOURCING_RULE_ID,'
29387 ||' EFFECTIVE_DATE,'
29388 ||' DISABLE_DATE,'
29389 ||' DELETED_FLAG,'
29390 ||' SR_INSTANCE_ID,'
29391 ||' REFRESH_ID,'
29392 ||' LAST_UPDATED_BY,'
29393 ||' LAST_UPDATE_DATE,'
29394 ||' CREATED_BY,'
29395 ||' CREATION_DATE)'
29396 ||' SELECT DISTINCT'
29397 ||' SR_RECEIPT_ID,'
29398 ||' RECEIPT_ORGANIZATION_ID,'
29399 || v_instance_id||','
29400 ||' SOURCING_RULE_ID,'
29401 ||' EFFECTIVE_DATE,'
29402 ||' DISABLE_DATE,'
29403 ||' DELETED_FLAG,'
29404 || v_instance_id||','
29405 ||' REFRESH_ID,'
29406 ||' LAST_UPDATED_BY,'
29407 ||' LAST_UPDATE_DATE,'
29408 ||' CREATED_BY,'
29409 ||' CREATION_DATE '
29410 ||' FROM MSC_ST_ITEM_SOURCING mis'
29411 ||' WHERE SR_INSTANCE_CODE = :v_instance_code'
29412 ||' AND PROCESS_FLAG = '||G_IN_PROCESS
29413 ||' AND batch_id = :lv_batch_id'
29414 ||' AND (SR_RECEIPT_ID)'
29415 ||' NOT IN (SELECT MSR.SR_RECEIPT_ID ' /* Added for Bug 8485612*/
29416 ||' FROM MSC_ST_SR_RECEIPT_ORG msr'
29417 ||' WHERE msr.RECEIPT_ORG_INSTANCE_ID= '||v_instance_id||')'
29418 ;
29419
29420
29421 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
29422
29423 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
29424
29425 v_sql_stmt := 41;
29426
29427 lv_sql_stmt :=
29428 'INSERT INTO MSC_ST_SR_SOURCE_ORG'
29429 ||' ( SR_SR_SOURCE_ID,'
29430 ||' SR_RECEIPT_ID,'
29431 ||' SOURCE_ORGANIZATION_ID,'
29432 ||' SOURCE_ORG_INSTANCE_ID,'
29433 ||' ALLOCATION_PERCENT,'
29434 ||' SOURCE_TYPE,'
29435 ||' RANK,'
29436 ||' SOURCE_PARTNER_ID,'
29437 ||' SOURCE_PARTNER_SITE_ID,'
29438 ||' SHIP_METHOD,'
29439 ||' DELETED_FLAG,'
29440 ||' SR_INSTANCE_ID,'
29441 ||' REFRESH_ID,'
29442 ||' LAST_UPDATED_BY,'
29443 ||' LAST_UPDATE_DATE,'
29444 ||' CREATED_BY,'
29445 ||' CREATION_DATE)'
29446 ||' select distinct'
29447 ||' SR_SOURCE_ID,'
29448 ||' SR_RECEIPT_ID,'
29449 ||' SOURCE_ORGANIZATION_ID,'
29450 || v_instance_id||','
29451 ||' ALLOCATION_PERCENT,'
29452 ||' SOURCE_TYPE,'
29453 ||' RANK,'
29454 ||' SOURCE_PARTNER_ID,'
29455 ||' SOURCE_PARTNER_SITE_ID,'
29456 ||' SHIP_METHOD,'
29457 ||' DELETED_FLAG,'
29458 || v_instance_id||','
29459 ||' REFRESH_ID,'
29460 ||' LAST_UPDATED_BY,'
29461 ||' LAST_UPDATE_DATE,'
29462 ||' CREATED_BY,'
29463 ||' CREATION_DATE '
29464 ||' FROM MSC_ST_ITEM_SOURCING mis'
29465 ||' where SR_INSTANCE_CODE = :v_instance_code'
29466 ||' AND PROCESS_FLAG = '||G_IN_PROCESS
29467 ||' AND batch_id = :lv_batch_id'
29468 ||' AND (SR_SOURCE_ID)'
29469 ||' NOT IN ( SELECT MSR.SR_SR_SOURCE_ID ' /* Added for Bug 8485612*/
29470 ||' FROM MSC_ST_SR_SOURCE_ORG msr'
29471 ||' WHERE msr.SOURCE_ORG_INSTANCE_ID= '||v_instance_id||')'
29472 ;
29473
29474
29475 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
29476
29477 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
29478
29479
29480 v_sql_stmt := 42;
29481 lv_sql_stmt :=
29482 'insert into MSC_ST_ASSIGNMENT_SETS'
29483 ||'(SR_ASSIGNMENT_SET_ID,'
29484 ||' ASSIGNMENT_SET_NAME,'
29485 /*||' DESCRIPTION,'*/
29486 ||' DELETED_FLAG,'
29487 ||' SR_INSTANCE_ID,'
29488 ||' REFRESH_ID,'
29489 ||' LAST_UPDATED_BY,'
29490 ||' LAST_UPDATE_DATE,'
29491 ||' CREATED_BY,'
29492 ||' CREATION_DATE)'
29493 ||' SELECT DISTINCT'
29494 ||' ASSIGNMENT_SET_ID,'
29495 ||' SR_INSTANCE_CODE||'':''||ASSIGNMENT_SET_NAME,'
29496 /* ||' NULL,' */
29497 ||' DELETED_FLAG,'
29498 || v_instance_id||','
29499 ||' REFRESH_ID,'
29500 ||' LAST_UPDATED_BY,'
29501 ||' LAST_UPDATE_DATE,'
29502 ||' CREATED_BY,'
29503 ||' CREATION_DATE '
29504 ||' FROM MSC_ST_ITEM_SOURCING mis'
29505 ||' where SR_INSTANCE_CODE = :v_instance_code'
29506 ||' AND PROCESS_FLAG = '||G_IN_PROCESS
29507 ||' AND batch_id = :lv_batch_id'
29508 ||' AND (ASSIGNMENT_SET_ID)'
29509 ||' NOT IN( SELECT MSR.SR_ASSIGNMENT_SET_ID ' /* Added for Bug 8485612*/
29510 ||' FROM MSC_ST_ASSIGNMENT_SETS msr'
29511 ||' WHERE msr.SR_INSTANCE_ID='||v_instance_id||')'
29512 ;
29513
29514
29515 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
29516
29517 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
29518
29519 v_sql_stmt := 43;
29520 lv_sql_stmt :=
29521 'insert into MSC_ST_SR_ASSIGNMENTS'
29522 ||' ( SR_ASSIGNMENT_ID,'
29523 ||' ASSIGNMENT_TYPE,'
29524 ||' SOURCING_RULE_ID,'
29525 ||' SOURCING_RULE_TYPE,'
29526 ||' ASSIGNMENT_SET_ID,'
29527 ||' INVENTORY_ITEM_ID,'
29528 ||' CATEGORY_NAME,'
29529 ||' CATEGORY_SET_IDENTIFIER,'
29530 ||' SR_ASSIGNMENT_INSTANCE_ID,'
29531 ||' ORGANIZATION_ID,'
29532 ||' SR_INSTANCE_ID,'
29533 ||' DELETED_FLAG, '
29534 ||' REFRESH_ID,'
29535 ||' LAST_UPDATED_BY,'
29536 ||' LAST_UPDATE_DATE,'
29537 ||' CREATED_BY,'
29538 ||' CREATION_DATE )'
29539 ||'select distinct '
29540 ||' ASSIGNMENT_ID,'
29541 ||' ASSIGNMENT_TYPE,'
29542 ||' SOURCING_RULE_ID,'
29543 ||' 1,'
29544 ||' ASSIGNMENT_SET_ID,'
29545 ||' INVENTORY_ITEM_ID,'
29546 ||' CATEGORY_NAME,'
29547 ||' CATEGORY_SET_ID,'
29548 || v_instance_id||','
29549 ||' ORGANIZATION_ID,'
29550 || v_instance_id||','
29551 ||' DELETED_FLAG,'
29552 ||' REFRESH_ID,'
29553 ||' LAST_UPDATED_BY,'
29554 ||' LAST_UPDATE_DATE,'
29555 ||' CREATED_BY,'
29556 ||' CREATION_DATE '
29557 ||' from MSC_ST_ITEM_SOURCING mis'
29558 ||' where SR_INSTANCE_CODE = :v_instance_code'
29559 ||' AND PROCESS_FLAG = '||G_IN_PROCESS
29560 ||' AND batch_id = :lv_batch_id'
29561 ||' AND (ASSIGNMENT_ID)'
29562 ||' NOT IN( SELECT MSR.SR_ASSIGNMENT_ID ' /* Added for Bug 8485612*/
29563 ||' FROM MSC_ST_SR_ASSIGNMENTS msr'
29564 ||' WHERE msr.SR_ASSIGNMENT_INSTANCE_ID='||v_instance_id||' )'
29565 ;
29566
29567
29568 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
29569
29570
29571 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
29572
29573 -- Set the processf flag as Valid and poulate instance_id
29574 lv_return :=
29575 MSC_ST_UTIL.SET_PROCESS_FLAG(p_table_name => 'MSC_ST_ITEM_SOURCING',
29576 p_instance_id => v_instance_id,
29577 p_instance_code => v_instance_code,
29578 p_process_flag => G_VALID,
29579 p_error_text => lv_error_text,
29580 p_debug => v_debug,
29581 p_batch_id => lv_batch_id);
29582
29583 IF(lv_return <> 0) then
29584 RAISE ex_logging_err;
29585 END IF;
29586
29587 -- At the end calling the LOG_ERROR for logging all errored out records
29588
29589 lv_return :=
29590 msc_st_util.log_error(p_table_name => 'MSC_ST_ITEM_SOURCING',
29591 p_instance_code => v_instance_code,
29592 p_row => lv_column_names,
29593 p_severity => G_SEV_ERROR,
29594 p_error_text => lv_error_text,
29595 p_message_text => NULL,
29596 p_debug => v_debug,
29597 p_batch_id => lv_batch_id );
29598
29599 IF(lv_return <> 0) then
29600 RAISE ex_logging_err;
29601 END IF;
29602
29603 COMMIT;
29604 END LOOP;
29605
29606
29607 EXCEPTION
29608 WHEN too_many_rows THEN
29609 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_SOURCING_RULES'||'('
29610 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
29611 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
29612 ROLLBACK ;
29613
29614 WHEN ex_logging_err THEN
29615 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
29616 ROLLBACK;
29617
29618 WHEN OTHERS THEN
29619 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_SOURCING_RULE'||'('
29620 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
29621 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
29622 ROLLBACK;
29623
29624 END LOAD_SOURCING_RULE;
29625
29626
29627 /*==========================================================================+
29628 | DESCRIPTION : This function performs the validation and loads the data |
29629 | for business object Project and Task. |
29630 +==========================================================================*/
29631 PROCEDURE LOAD_PROJ_TASK IS
29632
29633 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
29634 TYPE CurTyp IS REF CURSOR;
29635 c1 CurTyp;
29636 lb_rowid RowidTab;
29637
29638 lv_local_id NUMBER;
29639 lv_column_names VARCHAR2(5000); -- Stores cocatenated column names
29640 lv_return NUMBER;
29641 lv_error_text VARCHAR2(250);
29642 lv_where_str VARCHAR2(5000);
29643 lv_sql_stmt VARCHAR2(5000);
29644 lv_cursor_stmt VARCHAR2(5000);
29645 lv_batch_id msc_st_project_tasks.batch_id%TYPE;
29646 lv_message_text msc_errors.error_text%TYPE;
29647
29648 ex_logging_err EXCEPTION;
29649
29650 CURSOR c2(p_batch_id NUMBER) IS
29651 SELECT rowid
29652 FROM msc_st_project_tasks
29653 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
29654 AND sr_instance_code = v_instance_code
29655 AND batch_id = p_batch_id;
29656
29657 CURSOR c3(p_batch_id NUMBER) IS
29658 SELECT max(rowid)
29659 FROM msc_st_project_tasks
29660 WHERE process_flag = G_IN_PROCESS
29661 AND sr_instance_code = v_instance_code
29662 AND batch_id = p_batch_id
29663 AND NVL(project_id,NULL_VALUE) = NULL_VALUE
29664 AND deleted_flag = SYS_NO
29665 GROUP BY sr_instance_code,company_name,
29666 project_number ;
29667
29668 CURSOR c4(p_batch_id NUMBER) IS
29669 SELECT MAX(rowid)
29670 FROM msc_st_project_tasks
29671 WHERE process_flag = G_IN_PROCESS
29672 AND sr_instance_code = v_instance_code
29673 AND batch_id = p_batch_id
29674 AND NVL(task_id,NULL_VALUE) = NULL_VALUE
29675 AND NVL(task_number,NULL_CHAR) <> NULL_CHAR
29676 AND deleted_flag = SYS_NO
29677 GROUP BY sr_instance_code,company_name,
29678 project_number,task_number ;
29679
29680
29681 CURSOR c5(p_batch_id NUMBER) IS
29682 SELECT max(rowid)
29683 FROM msc_st_project_tasks
29684 WHERE process_flag = G_IN_PROCESS
29685 AND sr_instance_code = v_instance_code
29686 AND batch_id = p_batch_id
29687 AND NVL(costing_group_id,NULL_VALUE) = NULL_VALUE
29688 AND NVL(costing_group_code,NULL_CHAR) <> NULL_CHAR
29689 AND deleted_flag = SYS_NO
29690 GROUP BY sr_instance_code,company_name,
29691 costing_group_code ;
29692
29693 BEGIN
29694
29695
29696 --Duplicate records check for the records whose source is XML
29697
29698 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
29699 (p_app_short_name => 'MSC',
29700 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
29701 p_message_text => lv_message_text,
29702 p_error_text => lv_error_text);
29703
29704 IF lv_return <> 0 THEN
29705 RAISE ex_logging_err;
29706 END IF;
29707
29708 v_sql_stmt := 01;
29709 lv_sql_stmt:=
29710 'UPDATE msc_st_project_tasks mspt1 '
29711 ||' SET process_flag ='||G_ERROR_FLG||','
29712 ||' error_text = '||''''||lv_message_text||''''
29713 ||' WHERE message_id < ( SELECT max(message_id) FROM msc_st_project_tasks mspt2'
29714 ||' WHERE mspt2.sr_instance_code = mspt1.sr_instance_code'
29715 ||' AND NVL(mspt2.company_name,'||''''||NULL_CHAR||''''||') '
29716 ||' = NVL(mspt1.company_name,'||''''||NULL_CHAR||''''||') '
29717 ||' AND mspt2.organization_code = mspt1.organization_code'
29718 ||' AND mspt2.project_number = mspt1.project_number'
29719 ||' AND NVL(mspt2.task_number, '||''''||NULL_CHAR||''''||') '
29720 ||' = NVL(mspt1.task_number, '||''''||NULL_CHAR||''''||') '
29721 ||' AND mspt2.process_flag ='||G_IN_PROCESS
29722 ||' AND NVL(mspt2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||')'
29723 ||' AND mspt1.process_flag ='|| G_IN_PROCESS
29724 ||' AND mspt1.sr_instance_code = :v_instance_code'
29725 ||' AND NVL(mspt1.message_id,'||NULL_VALUE||')<> '||NULL_VALUE;
29726
29727
29728 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
29729
29730 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
29731
29732 --Duplicate records check for the records whose source is batch load
29733
29734 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
29735 (p_app_short_name => 'MSC',
29736 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
29737 p_message_text => lv_message_text,
29738 p_error_text => lv_error_text);
29739
29740 IF lv_return <> 0 THEN
29741 RAISE ex_logging_err;
29742 END IF;
29743
29744 v_sql_stmt := 02;
29745
29746 lv_sql_stmt :=
29747 'UPDATE msc_st_project_tasks mspt1'
29748 ||' SET process_flag ='|| G_ERROR_FLG||','
29749 ||' error_text = '||''''||lv_message_text||''''
29750 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_project_tasks mspt2'
29751 ||' WHERE mspt2.sr_instance_code = mspt1.sr_instance_code'
29752 ||' AND NVL(mspt2.company_name,'||''''||NULL_CHAR||''''||') '
29753 ||' = NVL(mspt1.company_name,'||''''||NULL_CHAR||''''||') '
29754 ||' AND mspt2.organization_code = mspt1.organization_code'
29755 ||' AND mspt2.project_number = mspt1.project_number'
29756 ||' AND NVL(mspt2.task_number,'||''''||NULL_CHAR||''''||') '
29757 ||' = NVL(mspt1.task_number, '||''''||NULL_CHAR||''''||') '
29758 ||' AND mspt2.process_flag ='||G_IN_PROCESS
29759 ||' AND NVL(mspt2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
29760 ||' GROUP BY sr_instance_code,organization_code,company_name,'
29761 ||' project_number,task_number '
29762 ||' HAVING COUNT(*) >1 )'
29763 ||' AND mspt1.process_flag = '||G_IN_PROCESS
29764 ||' AND mspt1.sr_instance_code = :v_instance_code'
29765 ||' AND NVL(mspt1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
29766
29767
29768 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
29769
29770 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
29771
29772 lv_column_names :=
29773 'PROJECT_NUMBER ||''~''||'
29774 ||'SEIBAN_NUMBER_FLAG ||''~''||'
29775 ||'ORGANIZATION_CODE ||''~''||'
29776 ||'TASK_NUMBER ||''~''||'
29777 ||'SR_INSTANCE_CODE ||''~''||'
29778 ||'PROJECT_DESCRIPTION ||''~''||'
29779 ||'PLANNING_GROUP ||''~''||'
29780 ||'WIP_ACCT_CLASS_CODE ||''~''||'
29781 ||'COSTING_GROUP_CODE ||''~''||'
29782 ||'MATERIAL_ACCOUNT ||''~''||'
29783 ||'PROJECT_START_DATE ||''~''||'
29784 ||'PROJECT_COMPLETION_DATE ||''~''||'
29785 ||'DESCRIPTION ||''~''||'
29786 ||'MANAGER ||''~''||'
29787 ||'START_DATE ||''~''||'
29788 ||'END_DATE ||''~''||'
29789 ||'MANAGER_CONTACT ||''~''||'
29790 ||' COMPANY_NAME ||''~''||'
29791 ||' DELETED_FLAG ' ;
29792
29793
29794 LOOP
29795 v_sql_stmt := 03;
29796 lv_cursor_stmt :=
29797 ' SELECT msc_st_batch_id_s.NEXTVAL '
29798 ||' FROM dual';
29799
29800 OPEN c1 FOR lv_cursor_stmt;
29801 FETCH c1 INTO lv_batch_id;
29802 CLOSE c1;
29803
29804 v_sql_stmt := 04;
29805 lv_sql_stmt :=
29806 ' UPDATE msc_st_project_tasks '
29807 ||' SET batch_id = :lv_batch_id'
29808 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
29809 ||' AND sr_instance_code = :v_instance_code'
29810 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
29811 ||' AND rownum <= '||v_batch_size;
29812
29813
29814 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
29815
29816 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
29817
29818 EXIT WHEN SQL%NOTFOUND;
29819
29820 OPEN c2(lv_batch_id);
29821 FETCH c2 BULK COLLECT INTO lb_rowid;
29822 CLOSE c2;
29823
29824 v_sql_stmt := 05;
29825 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
29826 UPDATE msc_st_project_tasks
29827 SET st_transaction_id = msc_st_project_tasks_s.NEXTVAL,
29828 refresh_id = v_refresh_id,
29829 last_update_date = v_current_date,
29830 last_updated_by = v_current_user,
29831 creation_date = v_current_date,
29832 created_by = v_current_user
29833 WHERE rowid = lb_rowid(j);
29834
29835
29836 -- Set the message
29837 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
29838 (p_app_short_name => 'MSC',
29839 p_error_code => 'MSC_PP_NO_DELETION',
29840 p_message_text => lv_message_text,
29841 p_error_text => lv_error_text,
29842 p_token1 => 'TABLE_NAME',
29843 p_token_value1 => 'MSC_ST_PROJECT_TASKS');
29844
29845 IF lv_return <> 0 THEN
29846 RAISE ex_logging_err;
29847 END IF;
29848
29849 --Deletion is not allowed on this table.
29850 v_sql_stmt := 06;
29851 lv_sql_stmt :=
29852 ' UPDATE msc_st_project_tasks '
29853 ||' SET process_flag = '||G_ERROR_FLG||','
29854 ||' error_text = '||''''||lv_message_text||''''
29855 ||' WHERE deleted_flag = '||SYS_YES
29856 ||' AND process_flag = '||G_IN_PROCESS
29857 ||' AND batch_id = :lv_batch_id'
29858 ||' AND sr_instance_code = :v_instance_code';
29859
29860
29861 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
29862
29863 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
29864
29865 -- Set the error message
29866 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
29867 (p_app_short_name => 'MSC',
29868 p_error_code => 'MSC_PP_COL_VAL_NULL',
29869 p_message_text => lv_message_text,
29870 p_error_text => lv_error_text,
29871 p_token1 => 'COLUMN_NAME',
29872 p_token_value1 => 'PROJECT_NUMBER');
29873
29874 IF lv_return <> 0 THEN
29875 RAISE ex_logging_err;
29876 END IF;
29877
29878 -- Error out record if project_number is NULL
29879
29880 v_sql_stmt := 07;
29881 lv_sql_stmt :=
29882 ' UPDATE msc_st_project_tasks '
29883 ||' SET process_flag = '||G_ERROR_FLG||','
29884 ||' error_text = '||''''||lv_message_text||''''
29885 ||' WHERE NVL(project_number,'||''''||NULL_CHAR||''''||')'
29886 ||' = '||''''||NULL_CHAR||''''
29887 ||' AND batch_id = :lv_batch_id'
29888 ||' AND process_flag = '||G_IN_PROCESS
29889 ||' AND sr_instance_code = :v_instance_code';
29890
29891
29892 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
29893 EXECUTE IMMEDIATE lv_sql_stmt
29894 USING lv_batch_id,
29895 v_instance_code;
29896
29897
29898 -- Set the message
29899 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
29900 (p_app_short_name => 'MSC',
29901 p_error_code => 'MSC_PP_INVALID_VALUE',
29902 p_message_text => lv_message_text,
29903 p_error_text => lv_error_text,
29904 p_token1 => 'COLUMN_NAME',
29905 p_token_value1 => 'ORGANIZATION_CODE');
29906
29907 IF lv_return <> 0 THEN
29908 RAISE ex_logging_err;
29909 END IF;
29910
29911 -- Derive organization id
29912 lv_return :=
29913 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name =>'MSC_ST_PROJECT_TASKS',
29914 p_org_partner_name =>'ORGANIZATION_CODE',
29915 p_org_partner_id =>'ORGANIZATION_ID',
29916 p_instance_code => v_instance_code,
29917 p_partner_type => G_ORGANIZATION,
29918 p_severity => G_SEV_ERROR,
29919 p_message_text => lv_message_text,
29920 p_batch_id => lv_batch_id,
29921 p_debug => v_debug,
29922 p_error_text => lv_error_text);
29923
29924 IF(lv_return <> 0) then
29925 RAISE ex_logging_err;
29926 END IF;
29927
29928 -- Set the error message
29929 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
29930 (p_app_short_name => 'MSC',
29931 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
29932 p_message_text => lv_message_text,
29933 p_error_text => lv_error_text,
29934 p_token1 => 'COLUMN_NAME',
29935 p_token_value1 => 'DELETED_FLAG',
29936 p_token2 => 'DEFAULT_VALUE',
29937 p_token_value2 => SYS_NO );
29938
29939 IF lv_return <> 0 THEN
29940 RAISE ex_logging_err;
29941 END IF;
29942
29943 -- Check DELETE_FLAG column has valid value or not and if not set it to SYS_NO
29944 -- Log error procedure inserts warning and also defaults the delete flag
29945
29946 lv_where_str :=
29947 ' AND NVL(deleted_flag,'||NULL_VALUE||') <>'||SYS_NO;
29948
29949 lv_return := MSC_ST_UTIL.LOG_ERROR
29950 (p_table_name => 'MSC_ST_PROJECT_TASKS',
29951 p_instance_code => v_instance_code,
29952 p_row => lv_column_names,
29953 p_severity => G_SEV_WARNING,
29954 p_message_text => lv_message_text,
29955 p_error_text => lv_error_text,
29956 p_batch_id => lv_batch_id,
29957 p_where_str => lv_where_str,
29958 p_col_name => 'DELETED_FLAG',
29959 p_debug => v_debug,
29960 p_default_value => SYS_NO);
29961
29962
29963 IF lv_return <> 0 THEN
29964 RAISE ex_logging_err;
29965 END IF;
29966
29967
29968 -- Set the error message
29969 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
29970 (p_app_short_name => 'MSC',
29971 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
29972 p_message_text => lv_message_text,
29973 p_error_text => lv_error_text,
29974 p_token1 => 'COLUMN_NAME',
29975 p_token_value1 => 'SEIBAN_NUMBER_FLAG',
29976 p_token2 => 'DEFAULT_VALUE',
29977 p_token_value2 => G_SEIBAN_NUMBER_FLAG );
29978
29979 IF lv_return <> 0 THEN
29980 RAISE ex_logging_err;
29981 END IF;
29982
29983 -- Default SEIBAN NUMBER FLAG as 2 if not in (1,2)
29984
29985 lv_where_str := ' AND NVL(seiban_number_flag,'||NULL_VALUE||') NOT IN (1,2) ';
29986
29987 lv_return := MSC_ST_UTIL.LOG_ERROR
29988 (p_table_name => 'MSC_ST_PROJECT_TASKS',
29989 p_instance_code => v_instance_code,
29990 p_row => lv_column_names,
29991 p_severity => G_SEV_WARNING,
29992 p_message_text => lv_message_text,
29993 p_error_text => lv_error_text,
29994 p_batch_id => lv_batch_id,
29995 p_where_str => lv_where_str,
29996 p_col_name => 'SEIBAN_NUMBER_FLAG',
29997 p_debug => v_debug,
29998 p_default_value => G_SEIBAN_NUMBER_FLAG);
29999
30000 IF(lv_return <> 0) then
30001 RAISE ex_logging_err;
30002 END IF;
30003
30004 -- Derive Project id
30005 lv_return :=
30006 MSC_ST_UTIL.DERIVE_PROJ_TASK_ID(p_table_name => 'MSC_ST_PROJECT_TASKS',
30007 p_proj_col_name => 'PROJECT_NUMBER',
30008 p_proj_task_col_id => 'PROJECT_ID',
30009 p_instance_code => v_instance_code,
30010 p_entity_name => 'PROJECT_ID',
30011 p_batch_id => lv_batch_id,
30012 p_error_text => lv_error_text,
30013 p_debug => v_debug,
30014 p_row => lv_column_names);
30015
30016 IF(lv_return <> 0) then
30017 RAISE ex_logging_err;
30018 END IF;
30019
30020 -- Derive task id
30021 lv_return :=
30022 MSC_ST_UTIL.DERIVE_PROJ_TASK_ID(p_table_name =>'MSC_ST_PROJECT_TASKS',
30023 p_proj_col_name =>'PROJECT_NUMBER',
30024 p_proj_task_col_id =>'TASK_ID',
30025 p_task_col_name =>'TASK_NUMBER',
30026 p_instance_code => v_instance_code,
30027 p_entity_name => 'TASK_ID',
30028 p_batch_id =>lv_batch_id,
30029 p_error_text =>lv_error_text,
30030 p_debug => v_debug,
30031 p_row =>lv_column_names);
30032
30033 IF(lv_return <> 0) then
30034 RAISE ex_logging_err;
30035 END IF;
30036
30037 -- UPdate task_name with the task_number
30038
30039 v_sql_stmt := 07;
30040 lv_sql_stmt :=
30041 'UPDATE msc_st_project_tasks '
30042 ||' SET task_name = task_number'
30043 ||' WHERE sr_instance_code = :v_instance_code'
30044 ||' AND process_flag = '||G_IN_PROCESS
30045 ||' AND NVL(task_number,'||''''||NULL_CHAR||''''||') '
30046 ||' <> '||''''||NULL_CHAR||''''
30047 ||' AND batch_id = :lv_batch_id ';
30048
30049
30050 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
30051
30052 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
30053
30054
30055 -- derive costing_group_id
30056
30057 v_sql_stmt := 08;
30058
30059 lv_sql_stmt :=
30060 'UPDATE msc_st_project_tasks mstp'
30061 ||' SET costing_group_id = ( SELECT local_id '
30062 ||' FROM msc_local_id_misc mlim'
30063 ||' WHERE mlim.char1 = mstp.sr_instance_code'
30064 ||' AND NVL(mlim.char2,'||''''||NULL_CHAR||''''||') '
30065 ||' = NVL(mstp.company_name,'||''''||NULL_CHAR||''''||') '
30066 /* ||' AND mlim.char3 = mstp.organization_code'*/
30067 ||' AND mlim.char4 = mstp.costing_group_code'
30068 ||' AND mlim.entity_name = ''COSTING_GROUP_ID'')'
30069 ||' WHERE sr_instance_code = :v_instance_code'
30070 ||' AND NVL(costing_group_code, '||''''||NULL_CHAR||''''||') '
30071 ||' <> '||''''||NULL_CHAR||''''
30072 ||' AND process_flag = '||G_IN_PROCESS
30073 ||' AND batch_id = :lv_batch_id' ;
30074
30075
30076
30077 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
30078
30079 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
30080
30081 --Call to customised validation.
30082 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
30083 (ERRBUF => lv_error_text,
30084 RETCODE => lv_return,
30085 pBatchID => lv_batch_id,
30086 pInstanceCode => v_instance_code,
30087 pEntityName => 'MSC_ST_PROJECT_TASKS',
30088 pInstanceID => v_instance_id);
30089
30090 IF NVL(lv_return,0) <> 0 THEN
30091 RAISE ex_logging_err;
30092 END IF;
30093
30094 -- Generate costing_group_id where cost group code is Not null but id is Null
30095
30096 v_sql_stmt := 09;
30097
30098 OPEN c5(lv_batch_id);
30099 FETCH c5 BULK COLLECT INTO lb_rowid ;
30100
30101 IF c5%ROWCOUNT > 0 THEN
30102
30103 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
30104
30105 UPDATE msc_st_project_tasks
30106 SET costing_group_id = msc_st_costing_group_id_s.NEXTVAL
30107 WHERE rowid = lb_rowid(j);
30108
30109
30110 v_sql_stmt := 10;
30111
30112 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
30113 -- Insert into the LID table with the user defined key
30114
30115 INSERT INTO msc_local_id_misc
30116 (local_id,
30117 st_transaction_id,
30118 instance_id,
30119 entity_name,
30120 data_source_type,
30121 char1,
30122 char2,
30123 char3,
30124 char4,
30125 SOURCE_ORG_ID,
30126 SOURCE_COSTING_GROUP_ID,
30127 last_update_date,
30128 last_updated_by,
30129 creation_date,
30130 created_by )
30131 SELECT
30132 costing_group_id,
30133 st_transaction_id,
30134 v_instance_id,
30135 'COSTING_GROUP_ID',
30136 data_source_type,
30137 sr_instance_code,
30138 company_name,
30139 organization_code,
30140 costing_group_code,
30141 SOURCE_ORG_ID,
30142 SOURCE_COSTING_GROUP_ID,
30143 v_current_date,
30144 v_current_user,
30145 v_current_date,
30146 v_current_user
30147 FROM msc_st_project_tasks
30148 WHERE rowid = lb_rowid(j);
30149 END IF;
30150 CLOSE c5;
30151
30152 -- update costing_group_id
30153
30154 v_sql_stmt := 11;
30155
30156 lv_sql_stmt :=
30157 'UPDATE msc_st_project_tasks mstp'
30158 ||' SET costing_group_id = ( SELECT local_id '
30159 ||' FROM msc_local_id_misc mlim'
30160 ||' WHERE mlim.char1 = mstp.sr_instance_code'
30161 ||' AND NVL(mlim.char2,'||''''||NULL_CHAR||''''||') '
30162 ||' = NVL(mstp.company_name,'||''''||NULL_CHAR||''''||') '
30163 /* ||' AND mlim.char3 = mstp.organization_code'*/
30164 ||' AND mlim.char4 = mstp.costing_group_code'
30165 ||' AND mlim.entity_name = ''COSTING_GROUP_ID'')'
30166 ||' WHERE sr_instance_code = :v_instance_code'
30167 ||' AND NVL(costing_group_code, '||''''||NULL_CHAR||''''||') '
30168 ||' <> '||''''||NULL_CHAR||''''
30169 ||' AND NVL(costing_group_id,'||NULL_VALUE||') = '||NULL_VALUE
30170 ||' AND process_flag = '||G_IN_PROCESS
30171 ||' AND batch_id = :lv_batch_id' ;
30172
30173
30174
30175 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
30176
30177 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
30178
30179 -- Project id generation
30180
30181 v_sql_stmt := 12;
30182
30183 OPEN c3(lv_batch_id);
30184 FETCH c3 BULK COLLECT INTO lb_rowid ;
30185
30186 IF c3%ROWCOUNT > 0 THEN
30187
30188 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
30189
30190 UPDATE msc_st_project_tasks
30191 SET project_id = msc_st_project_id_s.NEXTVAL
30192 WHERE rowid = lb_rowid(j);
30193
30194
30195 v_sql_stmt := 13;
30196
30197 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
30198
30199 -- Insert into the LID table with the user defined key
30200 INSERT INTO msc_local_id_misc
30201 (local_id,
30202 st_transaction_id,
30203 instance_id,
30204 entity_name,
30205 data_source_type,
30206 char1,
30207 char2,
30208 char3,
30209 char4,
30210 SOURCE_ORG_ID,
30211 SOURCE_COSTING_GROUP_ID,
30212 SOURCE_PROJECT_ID,
30213 last_update_date,
30214 last_updated_by,
30215 creation_date,
30216 created_by )
30217 SELECT
30218 project_id,
30219 st_transaction_id,
30220 v_instance_id,
30221 'PROJECT_ID',
30222 data_source_type,
30223 sr_instance_code,
30224 company_name,
30225 organization_code,
30226 project_number,
30227 SOURCE_ORG_ID,
30228 SOURCE_COSTING_GROUP_ID,
30229 SOURCE_PROJECT_ID,
30230 v_current_date,
30231 v_current_user,
30232 v_current_date,
30233 v_current_user
30234 FROM msc_st_project_tasks
30235 WHERE rowid = lb_rowid(j);
30236 END IF;
30237
30238 CLOSE c3;
30239
30240 -- Derive Project id
30241 lv_return :=
30242 MSC_ST_UTIL.DERIVE_PROJ_TASK_ID(p_table_name => 'MSC_ST_PROJECT_TASKS',
30243 p_proj_col_name => 'PROJECT_NUMBER',
30244 p_proj_task_col_id => 'PROJECT_ID',
30245 p_instance_code => v_instance_code,
30246 p_entity_name => 'PROJECT_ID',
30247 p_batch_id => lv_batch_id,
30248 p_error_text => lv_error_text,
30249 p_debug => v_debug,
30250 p_row => lv_column_names);
30251
30252 IF(lv_return <> 0) then
30253 RAISE ex_logging_err;
30254 END IF;
30255
30256 -- Task Id generation
30257
30258 v_sql_stmt := 14;
30259
30260 OPEN c4(lv_batch_id);
30261 FETCH c4 BULK COLLECT INTO lb_rowid ;
30262
30263 IF c4%ROWCOUNT > 0 THEN
30264
30265 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
30266
30267 UPDATE msc_st_project_tasks
30268 SET task_id = msc_st_task_id_s.NEXTVAL
30269 WHERE rowid = lb_rowid(j);
30270
30271 v_sql_stmt := 15;
30272
30273 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
30274
30275 -- Insert into the LID table with the user defined key
30276 INSERT INTO msc_local_id_misc
30277 (local_id,
30278 st_transaction_id,
30279 instance_id,
30280 entity_name,
30281 data_source_type,
30282 char1,
30283 char2,
30284 char3,
30285 char4,
30286 char5,
30287 SOURCE_ORG_ID,
30288 SOURCE_COSTING_GROUP_ID,
30289 SOURCE_PROJECT_ID,
30290 SOURCE_TASK_ID,
30291 last_update_date,
30292 last_updated_by,
30293 creation_date,
30294 created_by )
30295 SELECT
30296 task_id,
30297 st_transaction_id,
30298 v_instance_id,
30299 'TASK_ID',
30300 data_source_type,
30301 sr_instance_code,
30302 company_name,
30303 organization_code,
30304 project_number,
30305 task_number,
30306 SOURCE_ORG_ID,
30307 SOURCE_COSTING_GROUP_ID,
30308 SOURCE_PROJECT_ID,
30309 SOURCE_TASK_ID,
30310 v_current_date,
30311 v_current_user,
30312 v_current_date,
30313 v_current_user
30314 FROM msc_st_project_tasks
30315 WHERE rowid = lb_rowid(j);
30316 END IF;
30317 CLOSE c4;
30318
30319 -- Derive task id
30320 lv_return :=
30321 MSC_ST_UTIL.DERIVE_PROJ_TASK_ID(p_table_name =>'MSC_ST_PROJECT_TASKS',
30322 p_proj_col_name =>'PROJECT_NUMBER',
30323 p_proj_task_col_id =>'TASK_ID',
30324 p_task_col_name =>'TASK_NUMBER',
30325 p_instance_code => v_instance_code,
30326 p_entity_name => 'TASK_ID',
30327 p_batch_id =>lv_batch_id,
30328 p_error_text =>lv_error_text,
30329 p_debug => v_debug,
30330 p_row =>lv_column_names);
30331
30332 IF(lv_return <> 0) then
30333 RAISE ex_logging_err;
30334 END IF;
30335 -- Insert records in MSC_ST_PROJECTS
30336 v_sql_stmt := 16;
30337
30338 lv_sql_stmt:=
30339 'INSERT INTO msc_st_projects'
30340 ||' (project_id,'
30341 ||' organization_id,'
30342 ||' planning_group,'
30343 ||' costing_group_id, '
30344 ||' wip_acct_class_code, '
30345 ||' seiban_number_flag, '
30346 ||' project_name,'
30347 ||' project_number, '
30348 ||' project_description, '
30349 ||' start_date, '
30350 ||' completion_date, '
30351 ||' material_account,'
30352 ||' manager_contact,'
30353 ||' sr_instance_id,'
30354 ||' refresh_id, '
30355 ||' last_update_date,'
30356 ||' last_updated_by, '
30357 ||' creation_date, '
30358 ||' created_by ) '
30359 ||' SELECT'
30360 ||' project_id, '
30361 ||' organization_id,'
30362 ||' planning_group,'
30363 ||' costing_group_id,'
30364 ||' wip_acct_class_code,'
30365 ||' seiban_number_flag,'
30366 ||' project_number,'
30367 ||' project_number,'
30368 ||' project_description,'
30369 ||' project_start_date,'
30370 ||' project_completion_date, '
30371 ||' material_account,'
30372 ||' manager_contact,'
30373 || v_instance_id||','
30374 ||' REFRESH_ID,'
30375 ||' last_update_date,'
30376 ||' last_updated_by,'
30377 ||' creation_date,'
30378 ||' created_by'
30379 ||' FROM msc_st_project_tasks'
30380 ||' WHERE sr_instance_code = :v_instance_code'
30381 ||' AND process_flag = '||G_IN_PROCESS
30382 ||' AND batch_id = :lv_batch_id' ;
30383
30384 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
30385
30386 -- Delete all the records from msc_st_projects_tasks where task number is NULL
30387 -- This is done as records with only task name is inserted in msc_st_projects_tasks
30388
30389 lv_sql_stmt :=
30390 ' DELETE FROM msc_st_project_tasks '
30391 ||' WHERE NVL(task_number, '||''''||NULL_CHAR||''''||') '
30392 ||' = '||''''||NULL_CHAR||''''
30393 ||' AND sr_instance_code = :v_instance_code'
30394 ||' AND process_flag = '||G_IN_PROCESS
30395 ||' AND batch_id = :lv_batch_id' ;
30396
30397 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
30398
30399 -- Set the process flag as Valid and poulate instance_id
30400 lv_return :=
30401 MSC_ST_UTIL.SET_PROCESS_FLAG(p_table_name => 'MSC_ST_PROJECT_TASKS',
30402 p_instance_id => v_instance_id,
30403 p_instance_code => v_instance_code,
30404 p_process_flag => G_VALID,
30405 p_error_text => lv_error_text,
30406 p_debug => v_debug,
30407 p_batch_id => lv_batch_id);
30408
30409 IF lv_return < 0 THEN
30410 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
30411 END IF;
30412
30413
30414 -- At the end calling the LOG_ERROR for logging all errored out records
30415
30416 lv_return :=
30417 MSC_ST_UTIL.LOG_ERROR(p_table_name => 'MSC_ST_PROJECT_TASKS',
30418 p_instance_code => v_instance_code,
30419 p_row => lv_column_names,
30420 p_severity => G_SEV_ERROR,
30421 p_message_text => NULL,
30422 p_error_text => lv_error_text,
30423 p_debug => v_debug,
30424 p_batch_id => lv_batch_id );
30425
30426 IF(lv_return <> 0) then
30427 RAISE ex_logging_err;
30428 END IF;
30429
30430 COMMIT;
30431 END LOOP;
30432
30433 EXCEPTION
30434 WHEN too_many_rows THEN
30435 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_PROJ_TASK'||'('
30436 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
30437 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
30438 ROLLBACK ;
30439
30440 WHEN ex_logging_err THEN
30441 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
30442 ROLLBACK;
30443
30444 WHEN OTHERS THEN
30445 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_PROJ_TASK'||'('
30446 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
30447 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
30448 ROLLBACK;
30449
30450 END LOAD_PROJ_TASK;
30451
30452
30453 /*==========================================================================+
30454 | DESCRIPTION : This function performs the validation and loads the data |
30455 | for business object Resource and Department. |
30456 +==========================================================================*/
30457 PROCEDURE LOAD_DEPT_RES IS
30458
30459 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
30460 TYPE CurTyp IS REF CURSOR;
30461 c1 CurTyp;
30462 lb_rowid RowidTab;
30463
30464 lv_column_names VARCHAR2(5000); -- Stores cocatenated column names
30465 lv_return NUMBER;
30466 lv_error_text VARCHAR2(250);
30467 lv_where_str VARCHAR2(5000);
30468 lv_sql_stmt VARCHAR2(5000);
30469 lv_cursor_stmt VARCHAR2(5000);
30470
30471 lv_simulation_set msc_st_resource_changes.simulation_set%type;
30472 lv_batch_id msc_st_department_resources.batch_id%TYPE;
30473 lv_message_text msc_errors.error_text%TYPE;
30474
30475
30476 ex_logging_err EXCEPTION;
30477
30478 CURSOR c2(p_batch_id NUMBER) IS
30479 SELECT rowid
30480 FROM msc_st_department_resources
30481 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
30482 AND sr_instance_code = v_instance_code
30483 AND batch_id = p_batch_id;
30484
30485 CURSOR c3(p_batch_id NUMBER) IS
30486 SELECT max(rowid)
30487 FROM msc_st_department_resources
30488 WHERE process_flag = G_IN_PROCESS
30489 AND sr_instance_code = v_instance_code
30490 AND batch_id = p_batch_id
30491 AND NVL(department_id,NULL_VALUE) = NULL_VALUE
30492 AND deleted_flag = SYS_NO
30493 AND line_flag = '2'
30494 GROUP BY sr_instance_code,company_name,
30495 organization_code,department_code ;
30496
30497 CURSOR c4(p_batch_id NUMBER) IS
30498 SELECT max(rowid)
30499 FROM msc_st_department_resources
30500 WHERE process_flag = G_IN_PROCESS
30501 AND sr_instance_code = v_instance_code
30502 AND batch_id = p_batch_id
30503 AND NVL(resource_id,NULL_VALUE) = NULL_VALUE
30504 AND deleted_flag = SYS_NO
30505 AND line_flag = '2'
30506 GROUP BY sr_instance_code,company_name,
30507 organization_code,resource_code ;
30508
30509 CURSOR c5 (p_batch_id NUMBER) IS
30510 SELECT rowid
30511 FROM msc_st_department_resources
30512 WHERE process_flag = G_IN_PROCESS
30513 AND sr_instance_code = v_instance_code
30514 AND batch_id = p_batch_id
30515 AND NVL(department_id,NULL_VALUE) = NULL_VALUE
30516 AND deleted_flag = SYS_NO
30517 AND line_flag = '1' ;
30518
30519
30520 CURSOR c6(p_batch_id NUMBER) IS
30521 SELECT rowid
30522 FROM msc_st_resource_shifts
30523 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
30524 AND sr_instance_code = v_instance_code
30525 AND batch_id = p_batch_id;
30526
30527 CURSOR c7(p_batch_id NUMBER) IS
30528 SELECT rowid
30529 FROM msc_st_resource_changes
30530 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
30531 AND sr_instance_code = v_instance_code
30532 AND batch_id = p_batch_id;
30533
30534 CURSOR c8(p_batch_id NUMBER) IS
30535 SELECT max(rowid)
30536 FROM msc_st_resource_changes msrc
30537 WHERE NOT EXISTS (SELECT 1 FROM msc_simulation_sets mss
30538 WHERE msrc.simulation_set = mss.simulation_set
30539 AND msrc.sr_instance_id = mss.sr_instance_id
30540 AND msrc.organization_id = mss.organization_id)
30541 AND msrc.process_flag = G_VALID
30542 AND msrc.sr_instance_code = v_instance_code
30543 AND msrc.deleted_flag = SYS_NO
30544 AND msrc.batch_id = p_batch_id
30545 GROUP BY simulation_set,sr_instance_code,
30546 company_name,organization_code ;
30547
30548 CURSOR c9(p_batch_id NUMBER) IS
30549 SELECT rowid
30550 FROM msc_st_resource_groups
30551 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
30552 AND sr_instance_code = v_instance_code
30553 AND batch_id = p_batch_id;
30554
30555 BEGIN
30556
30557 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
30558 (p_app_short_name => 'MSC',
30559 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
30560 p_message_text => lv_message_text,
30561 p_error_text => lv_error_text);
30562
30563 IF lv_return <> 0 THEN
30564 RAISE ex_logging_err;
30565 END IF;
30566
30567 --Duplicate records check for the records whose source is XML
30568 v_sql_stmt := 01;
30569 lv_sql_stmt :=
30570 ' UPDATE msc_st_resource_groups mrg1'
30571 ||' SET process_flag = '||G_ERROR_FLG||','
30572 ||' error_text = '||''''||lv_message_text||''''
30573 ||' WHERE message_id < (SELECT MAX(message_id)'
30574 ||' FROM msc_st_resource_groups mrg2'
30575 ||' WHERE mrg2.sr_instance_code = mrg1.sr_instance_code'
30576 ||' AND mrg2.group_code = mrg1.group_code'
30577 ||' AND NVL(mrg2.company_name, ' ||''''||NULL_CHAR||''''||') = '
30578 ||' NVL(mrg1.company_name, ' ||''''||NULL_CHAR||''''||')'
30579 ||' AND mrg2.process_flag = mrg1.process_flag'
30580 ||' AND NVL(mrg2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
30581 ||' AND mrg1.process_flag = '||G_IN_PROCESS
30582 ||' AND mrg1.sr_instance_code = :v_instance_code'
30583 ||' AND NVL(mrg1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
30584
30585
30586 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
30587
30588 EXECUTE IMMEDIATE lv_sql_stmt
30589 USING v_instance_code;
30590
30591 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
30592 (p_app_short_name => 'MSC',
30593 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
30594 p_message_text => lv_message_text,
30595 p_error_text => lv_error_text);
30596
30597 IF lv_return <> 0 THEN
30598 RAISE ex_logging_err;
30599 END IF;
30600
30601 --Duplicate records check for the records whose source is other than XML
30602 --Different SQL is used because in XML we can identify the latest records
30603 --whereas in batch load we cannot.
30604 v_sql_stmt := 02;
30605 lv_sql_stmt :=
30606 ' UPDATE msc_st_resource_groups mrg1'
30607 ||' SET process_flag = '||G_ERROR_FLG||','
30608 ||' error_text = '||''''||lv_message_text||''''
30609 ||' WHERE EXISTS( SELECT 1 '
30610 ||' FROM msc_st_resource_groups mrg2'
30611 ||' WHERE mrg2.sr_instance_code = mrg1.sr_instance_code'
30612 ||' AND mrg2.group_code = mrg1.group_code'
30613 ||' AND NVL(mrg2.company_name, ' ||''''||NULL_CHAR||''''||') = '
30614 ||' NVL(mrg1.company_name, ' ||''''||NULL_CHAR||''''||')'
30615 ||' AND mrg2.process_flag = mrg1.process_flag'
30616 ||' AND NVL(mrg2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
30617 ||' GROUP BY sr_instance_code,group_code,company_name '
30618 ||' HAVING COUNT(*) > 1)'
30619 ||' AND mrg1.process_flag = '||G_IN_PROCESS
30620 ||' AND mrg1.sr_instance_code = :v_instance_code'
30621 ||' AND NVL(mrg1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
30622
30623
30624 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
30625
30626 EXECUTE IMMEDIATE lv_sql_stmt
30627 USING v_instance_code;
30628
30629 lv_column_names :=
30630 'GROUP_CODE ||''~''||'
30631 ||'MEANING ||''~''||'
30632 ||'DESCRIPTION ||''~''||'
30633 ||'FROM_DATE ||''~''||'
30634 ||'TO_DATE ||''~''||'
30635 ||'ENABLED_FLAG ||''~''||'
30636 ||'SR_INSTANCE_CODE ||''~''||'
30637 ||'COMPANY_NAME ||''~''||'
30638 ||'DELETED_FLAG';
30639
30640 LOOP
30641 v_sql_stmt := 03;
30642 SELECT msc_st_batch_id_s.NEXTVAL
30643 INTO lv_batch_id
30644 FROM dual;
30645
30646 v_sql_stmt := 04;
30647 lv_sql_stmt :=
30648 ' UPDATE msc_st_resource_groups '
30649 ||' SET batch_id = :lv_batch_id'
30650 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
30651 ||' AND sr_instance_code = :v_instance_code'
30652 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
30653 ||' AND rownum <= '||v_batch_size;
30654
30655
30656 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
30657
30658 EXECUTE IMMEDIATE lv_sql_stmt
30659 USING lv_batch_id,
30660 v_instance_code;
30661
30662 EXIT WHEN SQL%NOTFOUND;
30663
30664 OPEN c9(lv_batch_id);
30665 FETCH c9 BULK COLLECT INTO lb_rowid;
30666 CLOSE c9;
30667
30668 v_sql_stmt := 05;
30669 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
30670 UPDATE msc_st_resource_groups
30671 SET st_transaction_id = msc_st_resource_groups_s.NEXTVAL,
30672 refresh_id = v_refresh_id,
30673 last_update_date = v_current_date,
30674 last_updated_by = v_current_user,
30675 creation_date = v_current_date,
30676 created_by = v_current_user
30677 WHERE rowid = lb_rowid(j);
30678
30679 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
30680 (p_app_short_name => 'MSC',
30681 p_error_code => 'MSC_PP_NO_DELETION',
30682 p_message_text => lv_message_text,
30683 p_error_text => lv_error_text,
30684 p_token1 => 'TABLE_NAME',
30685 p_token_value1 => 'MSC_ST_RESOURCE_GROUPS');
30686
30687 IF lv_return <> 0 THEN
30688 RAISE ex_logging_err;
30689 END IF;
30690
30691 --Deletion is not allowed for this entity.
30692 v_sql_stmt := 06;
30693 lv_sql_stmt :=
30694 ' UPDATE msc_st_resource_groups '
30695 ||' SET process_flag = '||G_ERROR_FLG||','
30696 ||' error_text = '||''''||lv_message_text||''''
30697 ||' WHERE deleted_flag = '||SYS_YES
30698 ||' AND process_flag = '||G_IN_PROCESS
30699 ||' AND batch_id = :lv_batch_id'
30700 ||' AND sr_instance_code = :v_instance_code';
30701
30702
30703 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
30704
30705 EXECUTE IMMEDIATE lv_sql_stmt
30706 USING lv_batch_id,
30707 v_instance_code;
30708
30709 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
30710 (p_app_short_name => 'MSC',
30711 p_error_code => 'MSC_PP_COL_VAL_NULL',
30712 p_message_text => lv_message_text,
30713 p_error_text => lv_error_text,
30714 p_token1 => 'COLUMN_NAME',
30715 p_token_value1 => 'GROUP_CODE OR MEANING');
30716
30717 IF lv_return <> 0 THEN
30718 RAISE ex_logging_err;
30719 END IF;
30720
30721 v_sql_stmt := 07;
30722 lv_sql_stmt :=
30723 ' UPDATE msc_st_resource_groups '
30724 ||' SET process_flag = '||G_ERROR_FLG||','
30725 ||' error_text = '||''''||lv_message_text||''''
30726 ||' WHERE (group_code IS NULL '
30727 ||' OR meaning IS NULL) '
30728 ||' AND batch_id = :lv_batch_id'
30729 ||' AND process_flag = '||G_IN_PROCESS
30730 ||' AND sr_instance_code = :v_instance_code';
30731
30732
30733 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
30734 EXECUTE IMMEDIATE lv_sql_stmt
30735 USING lv_batch_id,
30736 v_instance_code;
30737
30738
30739 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
30740 (p_app_short_name => 'MSC',
30741 p_error_code => 'MSC_PP_INVALID_VALUE',
30742 p_message_text => lv_message_text,
30743 p_error_text => lv_error_text,
30744 p_token1 => 'COLUMN_NAME',
30745 p_token_value1 => 'FROM_DATE AND TO_DATE');
30746
30747 IF lv_return <> 0 THEN
30748 RAISE ex_logging_err;
30749 END IF;
30750
30751 v_sql_stmt := 08;
30752 lv_sql_stmt :=
30753 ' UPDATE msc_st_resource_groups '
30754 ||' SET process_flag = '||G_ERROR_FLG||','
30755 ||' error_text = '||''''||lv_message_text||''''
30756 ||' WHERE from_date > to_date '
30757 ||' AND batch_id = :lv_batch_id'
30758 ||' AND process_flag = '||G_IN_PROCESS
30759 ||' AND sr_instance_code = :v_instance_code';
30760
30761
30762 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
30763 EXECUTE IMMEDIATE lv_sql_stmt
30764 USING lv_batch_id,
30765 v_instance_code;
30766
30767 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
30768 (p_app_short_name => 'MSC',
30769 p_error_code => 'MSC_PP_NO_UPDATION',
30770 p_message_text => lv_message_text,
30771 p_error_text => lv_error_text,
30772 p_token1 => 'TABLE_NAME',
30773 p_token_value1 => 'MSC_ST_RESOURCE_GROUPS');
30774
30775 IF lv_return <> 0 THEN
30776 RAISE ex_logging_err;
30777 END IF;
30778
30779 --Updation is not allowed on this entity(this is done to make the
30780 --Post-Processor in sync with the collection program).
30781 v_sql_stmt := 09;
30782 lv_sql_stmt :=
30783 ' UPDATE msc_st_resource_groups mrg1'
30784 ||' SET process_flag = '||G_ERROR_FLG||','
30785 ||' error_text = '||''''||lv_message_text||''''
30786 ||' WHERE process_flag = '||G_IN_PROCESS
30787 ||' AND batch_id = :lv_batch_id'
30788 ||' AND sr_instance_code = :v_instance_code'
30789 ||' AND EXISTS'
30790 ||' (SELECT 1 FROM msc_resource_groups mrg2'
30791 ||' WHERE mrg2.group_code = mrg1.group_code'
30792 ||' AND mrg2.sr_instance_id = ' ||v_instance_id ||')';
30793
30794
30795 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
30796
30797 EXECUTE IMMEDIATE lv_sql_stmt
30798 USING lv_batch_id,
30799 v_instance_code;
30800
30801 -- Set the error message
30802 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
30803 (p_app_short_name => 'MSC',
30804 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
30805 p_message_text => lv_message_text,
30806 p_error_text => lv_error_text,
30807 p_token1 => 'COLUMN_NAME',
30808 p_token_value1 => 'ENABLED_FLAG',
30809 p_token2 => 'DEFAULT_VALUE',
30810 p_token_value2 => SYS_YES );
30811
30812 IF lv_return <> 0 THEN
30813 RAISE ex_logging_err;
30814 END IF;
30815
30816 -- Valid values for enabled_flag is 1(ie.,'Y') and 2('N'). For any other
30817 -- value generates a warning and defaults the value to 'Y'.
30818
30819 lv_where_str :=
30820 ' AND NVL(enabled_flag,'||NULL_VALUE||') NOT IN (1,2) ';
30821
30822 lv_return := MSC_ST_UTIL.LOG_ERROR
30823 (p_table_name => 'MSC_ST_RESOURCE_GROUPS',
30824 p_instance_code => v_instance_code,
30825 p_row => lv_column_names,
30826 p_severity => G_SEV_WARNING,
30827 p_message_text => lv_message_text,
30828 p_error_text => lv_error_text,
30829 p_batch_id => lv_batch_id,
30830 p_where_str => lv_where_str,
30831 p_col_name => 'ENABLED_FLAG',
30832 p_debug => v_debug,
30833 p_default_value => SYS_YES);
30834
30835 IF(lv_return <> 0) then
30836 RAISE ex_logging_err;
30837 END IF;
30838
30839 --Call to customised validation.
30840 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
30841 (ERRBUF => lv_error_text,
30842 RETCODE => lv_return,
30843 pBatchID => lv_batch_id,
30844 pInstanceCode => v_instance_code,
30845 pEntityName => 'MSC_ST_RESOURCE_GROUPS',
30846 pInstanceID => v_instance_id);
30847
30848 IF NVL(lv_return,0) <> 0 THEN
30849 RAISE ex_logging_err;
30850 END IF;
30851
30852 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
30853 (p_table_name => 'MSC_ST_RESOURCE_GROUPS',
30854 p_instance_id => v_instance_id,
30855 p_instance_code => v_instance_code,
30856 p_process_flag => G_VALID,
30857 p_error_text => lv_error_text,
30858 p_debug => v_debug,
30859 p_batch_id => lv_batch_id);
30860
30861 IF lv_return <> 0 THEN
30862 RAISE ex_logging_err;
30863 END IF;
30864
30865 lv_return := MSC_ST_UTIL.LOG_ERROR
30866 (p_table_name => 'MSC_ST_RESOURCE_GROUPS',
30867 p_instance_code => v_instance_code,
30868 p_row => lv_column_names,
30869 p_severity => G_SEV_ERROR,
30870 p_message_text => NULL,
30871 p_error_text => lv_error_text,
30872 p_debug => v_debug,
30873 p_batch_id => lv_batch_id);
30874
30875 IF lv_return <> 0 THEN
30876 RAISE ex_logging_err;
30877 END IF;
30878
30879 --Inserts the valid records into the ODS table, Since the collection program
30880 --doesn't collect this entity incrementally and whereras post-processor always
30881 --runs in the incremental mode.
30882
30883 v_sql_stmt := 10;
30884 lv_sql_stmt :=
30885 ' INSERT INTO msc_resource_groups '
30886 ||' ( group_code,'
30887 ||' meaning,'
30888 ||' description,'
30889 ||' from_date,'
30890 ||' to_date,'
30891 ||' enabled_flag,'
30892 ||' sr_instance_id,'
30893 ||' last_update_date,'
30894 ||' last_updated_by,'
30895 ||' creation_date,'
30896 ||' created_by)'
30897 ||' SELECT'
30898 ||' group_code,'
30899 ||' meaning,'
30900 ||' description,'
30901 ||' from_date,'
30902 ||' to_date,'
30903 ||' enabled_flag,'
30904 ||' sr_instance_id,'
30905 ||' last_update_date,'
30906 ||' last_updated_by,'
30907 ||' creation_date,'
30908 ||' created_by '
30909 ||' FROM msc_st_resource_groups'
30910 ||' WHERE sr_instance_code = :sr_instance_code'
30911 ||' AND batch_id = :lv_batch_id'
30912 ||' AND process_flag = '||G_VALID;
30913
30914
30915 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
30916
30917 EXECUTE IMMEDIATE lv_sql_stmt
30918 USING v_instance_code,
30919 lv_batch_id;
30920
30921 COMMIT;
30922 END LOOP;
30923
30924 -- Before we start processing the record by group id( batch size ) we are going
30925 -- to check whether that there
30926 -- is any duplicates for user defined unique keys (UDKs,)
30927
30928
30929 --Duplicate records check for the records whose source is XML
30930
30931 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
30932 (p_app_short_name => 'MSC',
30933 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
30934 p_message_text => lv_message_text,
30935 p_error_text => lv_error_text);
30936
30937 IF lv_return <> 0 THEN
30938 RAISE ex_logging_err;
30939 END IF;
30940
30941 v_sql_stmt := 01;
30942 lv_sql_stmt :=
30943 'UPDATE msc_st_department_resources msdr1'
30944 ||' SET process_flag = '||G_ERROR_FLG||','
30945 ||' error_text = '||''''||lv_message_text||''''
30946 ||' WHERE message_id < ( SELECT max(message_id) FROM msc_st_department_resources msdr2'
30947 ||' WHERE msdr2.sr_instance_code = msdr1.sr_instance_code'
30948 ||' AND NVL(msdr2.company_name,'||''''||NULL_CHAR||''''||') '
30949 ||' = NVL(msdr1.company_name,'||''''||NULL_CHAR||''''||') '
30950 ||' AND msdr2.organization_code = msdr1.organization_code'
30951 ||' AND msdr2.department_code = msdr1.department_code'
30952 ||' AND msdr2.resource_code = msdr1.resource_code'
30953 ||' AND msdr2.process_flag = '||G_IN_PROCESS
30954 ||' AND NVL(msdr2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||')'
30955 ||' AND msdr1.process_flag = '|| G_IN_PROCESS
30956 ||' AND msdr1.sr_instance_code = :v_instance_code '
30957 ||' AND NVL(msdr1.message_id,'||NULL_VALUE||')<> '||NULL_VALUE;
30958
30959
30960 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
30961
30962 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
30963
30964
30965 --Duplicate records check for the records whose source is batch load
30966
30967 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
30968 (p_app_short_name => 'MSC',
30969 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
30970 p_message_text => lv_message_text,
30971 p_error_text => lv_error_text);
30972
30973 IF lv_return <> 0 THEN
30974 RAISE ex_logging_err;
30975 END IF;
30976 lv_sql_stmt :=
30977 'UPDATE msc_st_department_resources msdr1'
30978 ||' SET process_flag ='|| G_ERROR_FLG||','
30979 ||' error_text = '||''''||lv_message_text||''''
30980 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_department_resources msdr2'
30981 ||' WHERE msdr2.sr_instance_code = msdr1.sr_instance_code'
30982 ||' AND NVL(msdr2.company_name,'||''''||NULL_CHAR||''''||') '
30983 ||' = NVL(msdr1.company_name,'||''''||NULL_CHAR||''''||') '
30984 ||' AND msdr2.organization_code = msdr1.organization_code'
30985 ||' AND msdr2.department_code = msdr1.department_code'
30986 ||' AND msdr2.resource_code = msdr1.resource_code'
30987 ||' AND msdr2.process_flag = '||G_IN_PROCESS
30988 ||' AND NVL(msdr2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
30989 ||' GROUP BY sr_instance_code,company_name,organization_code,'
30990 ||' department_code,resource_code'
30991 ||' HAVING COUNT(*) >1 )'
30992 ||' AND msdr1.process_flag ='|| G_IN_PROCESS
30993 ||' AND msdr1.sr_instance_code = :v_instance_code'
30994 ||' AND NVL(msdr1.message_id,'||NULL_VALUE||')= '||NULL_VALUE;
30995
30996
30997 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
30998
30999 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
31000
31001 -- Duplicate UDK validation for XML message
31002
31003 v_sql_stmt := 02;
31004
31005 lv_column_names :=
31006 'ORGANIZATION_CODE ||''~''||'
31007 ||'LINE_FLAG ||''~''||'
31008 ||'AGGREGATED_RESOURCE_FLAG ||''~''||'
31009 ||'AVAILABLE_24_HOURS_FLAG ||''~''||'
31010 ||'SR_INSTANCE_CODE ||''~''||'
31011 ||'RESOURCE_CODE ||''~''||'
31012 ||'DEPARTMENT_CODE ||''~''||'
31013 ||'DEPARTMENT_CLASS ||''~''||'
31014 ||'OWNING_DEPARTMENT_CODE ||''~''||'
31015 ||'CAPACITY_UNITS ||''~''||'
31016 ||'MAX_RATE ||''~''||'
31017 ||'MIN_RATE ||''~''||'
31018 ||'RESOURCE_GROUP_NAME ||''~''||'
31019 ||'RESOURCE_GROUP_CODE ||''~''||'
31020 ||'RESOURCE_BALANCE_FLAG ||''~''||'
31021 ||'BOTTLENECK_FLAG ||''~''||'
31022 ||'START_TIME ||''~''||'
31023 ||'STOP_TIME ||''~''||'
31024 ||'DEPARTMENT_DESCRIPTION ||''~''||'
31025 ||'RESOURCE_DESCRIPTION ||''~''||'
31026 ||'OVER_UTILIZED_PERCENT ||''~''||'
31027 ||'UNDER_UTILIZED_PERCENT ||''~''||'
31028 ||'RESOURCE_SHORTAGE_TYPE ||''~''||'
31029 ||'RESOURCE_EXCESS_TYPE ||''~''||'
31030 ||'USER_TIME_FENCE ||''~''||'
31031 ||'UTILIZATION ||''~''||'
31032 ||'EFFICIENCY ||''~''||'
31033 ||'RESOURCE_INCLUDE_FLAG ||''~''||'
31034 ||'CRITICAL_RESOURCE_FLAG ||''~''||'
31035 ||'RESOURCE_TYPE ||''~''||'
31036 ||'DISABLE_DATE ||''~''||'
31037 ||'CTP_FLAG ||''~''||'
31038 ||'DEPT_OVERHEAD_COST ||''~''||'
31039 ||'RESOURCE_COST ||''~''||'
31040 ||'RESOURCE_OVER_UTIL_COST ||''~''||'
31041 ||'PLANNING_EXCEPTION_SET ||''~''||'
31042 ||'DELETED_FLAG ||''~''||'
31043 ||'COMPANY_NAME';
31044
31045 -- Now processing by batch
31046
31047 LOOP
31048 v_sql_stmt := 03;
31049 lv_cursor_stmt :=
31050 ' SELECT msc_st_batch_id_s.NEXTVAL '
31051 ||' FROM dual';
31052
31053 OPEN c1 FOR lv_cursor_stmt;
31054 FETCH c1 INTO lv_batch_id;
31055 CLOSE c1;
31056
31057 v_sql_stmt := 04;
31058 lv_sql_stmt :=
31059 ' UPDATE msc_st_department_resources '
31060 ||' SET batch_id = :lv_batch_id'
31061 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
31062 ||' AND sr_instance_code = :v_instance_code'
31063 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
31064 ||' AND rownum <= '||v_batch_size;
31065
31066
31067 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
31068
31069 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
31070
31071 EXIT WHEN SQL%NOTFOUND;
31072
31073 OPEN c2(lv_batch_id);
31074 FETCH c2 BULK COLLECT INTO lb_rowid;
31075 CLOSE c2;
31076
31077 v_sql_stmt := 05;
31078 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
31079 UPDATE msc_st_department_resources
31080 SET st_transaction_id = msc_st_department_resources_s.NEXTVAL,
31081 refresh_id = v_refresh_id,
31082 last_update_date = v_current_date,
31083 last_updated_by = v_current_user,
31084 creation_date = v_current_date,
31085 created_by = v_current_user
31086 WHERE rowid = lb_rowid(j);
31087
31088
31089 -- Set the message
31090 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
31091 (p_app_short_name => 'MSC',
31092 p_error_code => 'MSC_PP_NO_DELETION',
31093 p_message_text => lv_message_text,
31094 p_error_text => lv_error_text,
31095 p_token1 => 'TABLE_NAME',
31096 p_token_value1 => 'MSC_ST_DEPARTMENT_RESOURCES');
31097
31098 IF lv_return <> 0 THEN
31099 RAISE ex_logging_err;
31100 END IF;
31101 --Deletion is not allowed on this table.
31102 v_sql_stmt := 06;
31103 lv_sql_stmt :=
31104 ' UPDATE msc_st_department_resources '
31105 ||' SET process_flag ='||G_ERROR_FLG||','
31106 ||' error_text = '||''''||lv_message_text||''''
31107 ||' WHERE deleted_flag = '||SYS_YES
31108 ||' AND process_flag = '||G_IN_PROCESS
31109 ||' AND batch_id = :lv_batch_id'
31110 ||' AND sr_instance_code = :v_instance_code';
31111
31112
31113 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
31114
31115 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
31116
31117 -- bug 8310366 validate SCHEDULE_TO_INSTANCE(SDS Changes)
31118 -- Set the error message
31119 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
31120 (p_app_short_name => 'MSC',
31121 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
31122 p_message_text => lv_message_text,
31123 p_error_text => lv_error_text,
31124 p_token1 => 'COLUMN_NAME',
31125 p_token_value1 => 'SCHEDULE_TO_INSTANCE',
31126 p_token2 => 'DEFAULT_VALUE',
31127 p_token_value2 => SYS_NO );
31128
31129 IF lv_return <> 0 THEN
31130 RAISE ex_logging_err;
31131 END IF;
31132
31133 -- Default SCHEDULE_TO_INSTANCE as 2 if not in (1,2)
31134
31135 lv_where_str :=
31136 ' AND NVL(SCHEDULE_TO_INSTANCE,'||NULL_VALUE||') NOT IN (''1'',''2'')';
31137
31138 lv_return := MSC_ST_UTIL.LOG_ERROR
31139 (p_table_name => 'MSC_ST_DEPARTMENT_RESOURCES',
31140 p_instance_code => v_instance_code,
31141 p_row => lv_column_names,
31142 p_severity => G_SEV_WARNING,
31143 p_message_text => lv_message_text,
31144 p_error_text => lv_error_text,
31145 p_batch_id => lv_batch_id,
31146 p_where_str => lv_where_str,
31147 p_col_name => 'SCHEDULE_TO_INSTANCE',
31148 p_debug => v_debug,
31149 p_default_value => SYS_NO );
31150
31151 IF(lv_return <> 0) then
31152 RAISE ex_logging_err;
31153 END IF;
31154
31155
31156
31157
31158 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
31159 (p_app_short_name => 'MSC',
31160 p_error_code => 'MSC_PP_INVALID_VALUE',
31161 p_message_text => lv_message_text,
31162 p_error_text => lv_error_text,
31163 p_token1 => 'COLUMN_NAME',
31164 p_token_value1 => 'RESOURCE_GROUP_NAME');
31165
31166 IF lv_return <> 0 THEN
31167 RAISE ex_logging_err;
31168 END IF;
31169
31170 -- Resource group Name should refer to a valid group code
31171 -- in the msc_st_resource_groups entity.
31172 v_sql_stmt := 08;
31173
31174 lv_sql_stmt :=
31175 ' UPDATE msc_st_department_resources mdr'
31176 ||' SET process_flag = '||G_ERROR_FLG||','
31177 ||' error_text = '||''''||lv_message_text||''''
31178 ||' WHERE NOT EXISTS (SELECT 1'
31179 ||' FROM msc_resource_groups mrg'
31180 ||' WHERE mrg.group_code = mdr.resource_group_name '
31181 ||' AND (trunc(mrg.from_date) <= trunc(sysdate) '
31182 ||' OR trunc(mrg.to_date) >= trunc(sysdate)) '
31183 ||' AND mrg.enabled_flag = '||SYS_YES
31184 ||' AND mrg.sr_instance_id = :v_instance_id)'
31185 ||' AND mdr.resource_group_name IS NOT NULL'
31186 ||' AND mdr.sr_instance_code = :v_instance_code'
31187 ||' AND mdr.batch_id = :lv_batch_id'
31188 ||' AND mdr.process_flag = '||G_IN_PROCESS ;
31189
31190
31191 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
31192
31193 EXECUTE IMMEDIATE lv_sql_stmt
31194 USING v_instance_id,
31195 v_instance_code,
31196 lv_batch_id;
31197
31198 -- Set the error message
31199
31200 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
31201 (p_app_short_name => 'MSC',
31202 p_error_code => 'MSC_PP_COL_VAL_NULL',
31203 p_message_text => lv_message_text,
31204 p_error_text => lv_error_text,
31205 p_token1 => 'COLUMN_NAME',
31206 p_token_value1 => 'DEPARTMENT_CODE OR RESOURCE_CODE');
31207
31208 IF lv_return <> 0 THEN
31209 RAISE ex_logging_err;
31210 END IF;
31211
31212 -- Error out record if department_code is null/resource_code is NULL and line_flag=2
31213
31214 v_sql_stmt := 07;
31215 lv_sql_stmt :=
31216 ' UPDATE msc_st_department_resources '
31217 ||' SET process_flag = '||G_ERROR_FLG||','
31218 ||' error_text = '||''''||lv_message_text||''''
31219 ||' WHERE (NVL(department_code,'||''''||NULL_CHAR||''''||')'
31220 ||' = '||''''||NULL_CHAR||''''
31221 ||' OR (NVL(resource_code,'||''''||NULL_CHAR||''''||')'
31222 ||' = '||''''||NULL_CHAR||''''||') AND LINE_FLAG=2 )'
31223 ||' AND batch_id = :lv_batch_id'
31224 ||' AND process_flag = '||G_IN_PROCESS
31225 ||' AND sr_instance_code = :v_instance_code';
31226
31227
31228 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
31229 EXECUTE IMMEDIATE lv_sql_stmt
31230 USING lv_batch_id,
31231 v_instance_code;
31232
31233 -- Set the error message
31234 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
31235 (p_app_short_name => 'MSC',
31236 p_error_code => 'MSC_PP_COL_VAL_NULL',
31237 p_message_text => lv_message_text,
31238 p_error_text => lv_error_text,
31239 p_token1 => 'COLUMN_NAME',
31240 p_token_value1 => 'MAX_RATE OR MIN_RATE'
31241 ||'OR START_TIME OR STOP_TIME' );
31242
31243 IF lv_return <> 0 THEN
31244 RAISE ex_logging_err;
31245 END IF;
31246
31247 -- Error out records for lines when
31248 -- max_rate, min_rate, start_time and stop_time is NULL
31249
31250 v_sql_stmt:= 08;
31251
31252 lv_sql_stmt :=
31253 'UPDATE msc_st_department_resources '
31254 ||' SET process_flag ='|| G_ERROR_FLG||','
31255 ||' error_text ='||''''||lv_message_text||''''
31256 ||' WHERE (NVL(max_rate,'||NULL_VALUE||') ='||NULL_VALUE
31257 ||' OR NVL(min_rate,'||NULL_VALUE||') ='|| NULL_VALUE
31258 ||' OR NVL(start_time,'||NULL_VALUE||') ='|| NULL_VALUE
31259 ||' OR NVL(stop_time,'||NULL_VALUE||') ='|| NULL_VALUE||')'
31260 ||' AND sr_instance_code = :v_instance_code'
31261 ||' AND line_flag = ''1'' '
31262 ||' AND process_flag ='|| G_IN_PROCESS
31263 ||' AND batch_id = :lv_batch_id' ;
31264
31265
31266 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
31267
31268 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
31269
31270 -- Set the error message
31271 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
31272 (p_app_short_name => 'MSC',
31273 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
31274 p_message_text => lv_message_text,
31275 p_error_text => lv_error_text,
31276 p_token1 => 'COLUMN_NAME',
31277 p_token_value1 => 'DELETE_FLAG',
31278 p_token2 => 'DEFAULT_VALUE',
31279 p_token_value2 => SYS_NO );
31280
31281 IF lv_return <> 0 THEN
31282 RAISE ex_logging_err;
31283 END IF;
31284
31285 -- Check DELETE_FLAG column has valid value or not and if not set it to SYS_NO
31286 -- Log error procedure inserts warning and also defaults the delete flag
31287
31288 lv_where_str :=
31289 ' AND NVL(deleted_flag,'||NULL_VALUE||') <>'||SYS_NO;
31290
31291 lv_return := MSC_ST_UTIL.LOG_ERROR
31292 (p_table_name => 'MSC_ST_DEPARTMENT_RESOURCES',
31293 p_instance_code => v_instance_code,
31294 p_row => lv_column_names,
31295 p_severity => G_SEV_WARNING,
31296 p_message_text => lv_message_text,
31297 p_error_text => lv_error_text,
31298 p_batch_id => lv_batch_id,
31299 p_where_str => lv_where_str,
31300 p_col_name => 'DELETED_FLAG',
31301 p_debug => v_debug,
31302 p_default_value => SYS_NO);
31303
31304
31305 IF lv_return <> 0 THEN
31306 RAISE ex_logging_err;
31307 END IF;
31308
31309 -- Set the error message
31310
31311 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
31312 (p_app_short_name => 'MSC',
31313 p_error_code => 'MSC_PP_INVALID_VALUE',
31314 p_message_text => lv_message_text,
31315 p_error_text => lv_error_text,
31316 p_token1 => 'COLUMN_NAME',
31317 p_token_value1 => 'ORGANIZATION_CODE');
31318
31319 IF lv_return <> 0 THEN
31320 RAISE ex_logging_err;
31321 END IF;
31322
31323 -- Derive organization id
31324 lv_return :=
31325 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name => 'MSC_ST_DEPARTMENT_RESOURCES',
31326 p_org_partner_name => 'ORGANIZATION_CODE',
31327 p_org_partner_id => 'ORGANIZATION_ID',
31328 p_instance_code => v_instance_code,
31329 p_partner_type => G_ORGANIZATION,
31330 p_severity => G_SEV_ERROR,
31331 p_message_text => lv_message_text,
31332 p_batch_id => lv_batch_id,
31333 p_debug => v_debug,
31334 p_error_text => lv_error_text);
31335
31336 IF(lv_return <> 0) then
31337 RAISE ex_logging_err;
31338 END IF;
31339
31340 -- Set the error message
31341 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
31342 (p_app_short_name => 'MSC',
31343 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
31344 p_message_text => lv_message_text,
31345 p_error_text => lv_error_text,
31346 p_token1 => 'COLUMN_NAME',
31347 p_token_value1 => 'LINE_FLAG',
31348 p_token2 => 'DEFAULT_VALUE',
31349 p_token_value2 => G_LINE_FLAG );
31350
31351 IF lv_return <> 0 THEN
31352 RAISE ex_logging_err;
31353 END IF;
31354
31355 -- Default line_flag as 2 (Dept is Not a line) if not in (1,2)
31356
31357 lv_where_str :=
31358 ' AND NVL(line_flag,'||NULL_VALUE||') NOT IN (''1'',''2'')';
31359
31360 lv_return := MSC_ST_UTIL.LOG_ERROR
31361 (p_table_name => 'MSC_ST_DEPARTMENT_RESOURCES',
31362 p_instance_code => v_instance_code,
31363 p_row => lv_column_names,
31364 p_severity => G_SEV_WARNING,
31365 p_message_text => lv_message_text,
31366 p_error_text => lv_error_text,
31367 p_batch_id => lv_batch_id,
31368 p_where_str => lv_where_str,
31369 p_col_name => 'LINE_FLAG',
31370 p_debug => v_debug,
31371 p_default_value => G_LINE_FLAG );
31372
31373 IF(lv_return <> 0) then
31374 RAISE ex_logging_err;
31375 END IF;
31376
31377 -- Set the error message
31378 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
31379 (p_app_short_name => 'MSC',
31380 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
31381 p_message_text => lv_message_text,
31382 p_error_text => lv_error_text,
31383 p_token1 => 'COLUMN_NAME',
31384 p_token_value1 => 'AVAILABLE_24_HOURS_FLAG',
31385 p_token2 => 'DEFAULT_VALUE',
31386 p_token_value2 => G_AVAILABLE_24_HOURS_FLAG );
31387
31388 IF lv_return <> 0 THEN
31389 RAISE ex_logging_err;
31390 END IF;
31391
31392
31393 -- Default available 24 hr as Yes (1) for dept/line
31394
31395 lv_where_str :=
31396 ' AND NVL(available_24_hours_flag,'||NULL_VALUE||') NOT IN (1,2)';
31397
31398 lv_return := MSC_ST_UTIL.LOG_ERROR
31399 (p_table_name => 'MSC_ST_DEPARTMENT_RESOURCES',
31400 p_instance_code => v_instance_code,
31401 p_row => lv_column_names,
31402 p_severity => G_SEV_WARNING,
31403 p_message_text => lv_message_text,
31404 p_error_text => lv_error_text,
31405 p_batch_id => lv_batch_id,
31406 p_where_str => lv_where_str,
31407 p_col_name => 'AVAILABLE_24_HOURS_FLAG',
31408 p_debug => v_debug,
31409 p_default_value => G_AVAILABLE_24_HOURS_FLAG);
31410
31411
31412 IF(lv_return <> 0) then
31413 RAISE ex_logging_err;
31414 END IF;
31415
31416 -- Set the error message
31417 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
31418 (p_app_short_name => 'MSC',
31419 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
31420 p_message_text => lv_message_text,
31421 p_error_text => lv_error_text,
31422 p_token1 => 'COLUMN_NAME',
31423 p_token_value1 => 'CTP_FLAG ',
31424 p_token2 => 'DEFAULT_VALUE',
31425 p_token_value2 => G_CTP_FLAG );
31426
31427 IF lv_return <> 0 THEN
31428 RAISE ex_logging_err;
31429 END IF;
31430
31431 -- Default CTP flag as 2 if NOT IN (1,2) for dept only
31432
31433 lv_where_str :=
31434 ' AND NVL(ctp_flag,'||NULL_VALUE||') NOT IN (1,2) AND line_flag = ''2'' ';
31435
31436 lv_return := MSC_ST_UTIL.LOG_ERROR
31437 (p_table_name => 'MSC_ST_DEPARTMENT_RESOURCES',
31438 p_instance_code => v_instance_code,
31439 p_row => lv_column_names,
31440 p_severity => G_SEV_WARNING,
31441 p_message_text => lv_message_text,
31442 p_error_text => lv_error_text,
31443 p_batch_id => lv_batch_id,
31444 p_where_str => lv_where_str,
31445 p_col_name => 'CTP_FLAG',
31446 p_debug => v_debug,
31447 p_default_value => G_CTP_FLAG );
31448
31449 IF(lv_return <> 0) then
31450 RAISE ex_logging_err;
31451 END IF;
31452
31453 -- Set the error message
31454 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
31455 (p_app_short_name => 'MSC',
31456 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
31457 p_message_text => lv_message_text,
31458 p_error_text => lv_error_text,
31459 p_token1 => 'COLUMN_NAME',
31460 p_token_value1 => 'RESOURCE_TYPE ',
31461 p_token2 => 'DEFAULT_VALUE',
31462 p_token_value2 => G_RESOURCE_TYPE );
31463
31464 IF lv_return <> 0 THEN
31465 RAISE ex_logging_err;
31466 END IF;
31467
31468 -- Default resource_type as 1 (Machine) if not in (1,2,3,4,5)
31469
31470 lv_where_str :=
31471 ' AND NVL(resource_type,'||NULL_VALUE||')'
31472 ||' NOT IN (1,2,3,4,5) AND line_flag = ''2'' ';
31473
31474 lv_return := MSC_ST_UTIL.LOG_ERROR
31475 (p_table_name => 'MSC_ST_DEPARTMENT_RESOURCES',
31476 p_instance_code => v_instance_code,
31477 p_row => lv_column_names,
31478 p_severity => G_SEV_WARNING,
31479 p_message_text => lv_message_text,
31480 p_error_text => lv_error_text,
31481 p_batch_id => lv_batch_id,
31482 p_where_str => lv_where_str,
31483 p_col_name => 'RESOURCE_TYPE',
31484 p_debug => v_debug,
31485 p_default_value => G_RESOURCE_TYPE );
31486
31487
31488 IF(lv_return <> 0) then
31489 RAISE ex_logging_err;
31490 END IF;
31491
31492 /* commented for Bug 2970460
31493 -- Set the error message
31494 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
31495 (p_app_short_name => 'MSC',
31496 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
31497 p_message_text => lv_message_text,
31498 p_error_text => lv_error_text,
31499 p_token1 => 'COLUMN_NAME',
31500 p_token_value1 => 'RESOURCE_INCLUDE_FLAG',
31501 p_token2 => 'DEFAULT_VALUE',
31502 p_token_value2 => G_RESOURCE_INCLUDE_FLAG );
31503
31504 IF lv_return <> 0 THEN
31505 RAISE ex_logging_err;
31506 END IF;
31507
31508 -- Default resource_include_flag as 1 if not in (1,2)
31509
31510 lv_where_str :=
31511 ' AND NVL(resource_include_flag,'||NULL_VALUE||')'
31512 ||' NOT IN (1,2) AND line_flag = 2';
31513
31514 lv_return := MSC_ST_UTIL.LOG_ERROR
31515 (p_table_name => 'MSC_ST_DEPARTMENT_RESOURCES',
31516 p_instance_code => v_instance_code,
31517 p_row => lv_column_names,
31518 p_severity => G_SEV_WARNING,
31519 p_message_text => lv_message_text,
31520 p_error_text => lv_error_text,
31521 p_batch_id => lv_batch_id,
31522 p_where_str => lv_where_str,
31523 p_col_name => 'RESOURCE_INCLUDE_FLAG',
31524 p_debug => v_debug,
31525 p_default_value => G_RESOURCE_INCLUDE_FLAG);
31526
31527 IF(lv_return <> 0) then
31528 RAISE ex_logging_err;
31529 END IF;
31530 */
31531
31532 -- Set the error message
31533 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
31534 (p_app_short_name => 'MSC',
31535 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
31536 p_message_text => lv_message_text,
31537 p_error_text => lv_error_text,
31538 p_token1 => 'COLUMN_NAME',
31539 p_token_value1 => 'AGGREGATED_RESOURCE_FLAG',
31540 p_token2 => 'DEFAULT_VALUE',
31541 p_token_value2 => G_AGGREGATED_RESOURCE_FLAG);
31542
31543 IF lv_return <> 0 THEN
31544 RAISE ex_logging_err;
31545 END IF;
31546
31547 -- Default aggregated_resource_flag as
31548 -- 2(Resource is not aggregated one) if not in (1,2)
31549
31550 lv_where_str :=
31551 ' AND NVL(aggregated_resource_flag,'||NULL_VALUE||')'
31552 ||' NOT IN (1,2) AND LINE_FLAG = 2';
31553
31554 lv_return := MSC_ST_UTIL.LOG_ERROR
31555 (p_table_name => 'MSC_ST_DEPARTMENT_RESOURCES',
31556 p_instance_code => v_instance_code,
31557 p_row => lv_column_names,
31558 p_severity => G_SEV_WARNING,
31559 p_message_text => lv_message_text,
31560 p_error_text => lv_error_text,
31561 p_batch_id => lv_batch_id,
31562 p_where_str => lv_where_str,
31563 p_col_name => 'AGGREGATED_RESOURCE_FLAG',
31564 p_debug => v_debug,
31565 p_default_value => G_AGGREGATED_RESOURCE_FLAG );
31566
31567 IF(lv_return <> 0) then
31568 RAISE ex_logging_err;
31569 END IF;
31570
31571
31572
31573 -- Now derive department id
31574 v_sql_stmt:= 10;
31575
31576 lv_sql_stmt :=
31577 'UPDATE msc_st_department_resources msdr'
31578 ||' SET department_id= (SELECT local_id'
31579 ||' FROM msc_local_id_setup mlis'
31580 ||' WHERE mlis.char1 = msdr.sr_instance_code'
31581 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
31582 ||' = NVL(msdr.company_name,'||''''||NULL_CHAR||''''||') '
31583 ||' AND mlis.char3 = msdr.organization_code'
31584 ||' AND mlis.char4 = msdr.department_code'
31585 ||' AND mlis.entity_name = ''DEPARTMENT_ID'')'
31586 ||' WHERE msdr.sr_instance_code = :v_instance_code'
31587 ||' AND msdr.line_flag = ''2'' '
31588 ||' AND msdr.process_flag ='|| G_IN_PROCESS
31589 ||' AND msdr.batch_id = :lv_batch_id';
31590
31591
31592 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
31593
31594 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
31595
31596
31597 -- Now derive line id
31598 v_sql_stmt:= 10;
31599
31600 lv_sql_stmt :=
31601 'UPDATE msc_st_department_resources msdr'
31602 ||' SET department_id= (SELECT local_id '
31603 ||' FROM msc_local_id_setup mlis'
31604 ||' WHERE mlis.char1 = msdr.sr_instance_code'
31605 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
31606 ||' = NVL(msdr.company_name,'||''''||NULL_CHAR||''''||') '
31607 ||' AND mlis.char3 = msdr.organization_code'
31608 ||' AND mlis.char4 = msdr.department_code'
31609 ||' AND mlis.entity_name = ''LINE_ID'')'
31610 ||' WHERE msdr.sr_instance_code = :v_instance_code'
31611 ||' AND msdr.line_flag = ''1'' '
31612 ||' AND msdr.process_flag ='|| G_IN_PROCESS
31613 ||' AND msdr.batch_id = :lv_batch_id';
31614
31615
31616 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
31617
31618 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
31619
31620
31621 -- Derive resource id
31622
31623 v_sql_stmt:= 11;
31624
31625 lv_sql_stmt :=
31626 'UPDATE msc_st_department_resources msdr'
31627 ||' SET resource_id= (SELECT local_id'
31628 ||' FROM msc_local_id_setup mlis'
31629 ||' WHERE mlis.char1 = msdr.sr_instance_code'
31630 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
31631 ||' = NVL(msdr.company_name,'||''''||NULL_CHAR||''''||') '
31632 ||' AND mlis.char3 = msdr.organization_code'
31633 ||' AND mlis.char4 = msdr.resource_code'
31634 ||' AND mlis.entity_name = ''RESOURCE_ID'')'
31635 ||' WHERE msdr.sr_instance_code = :v_instance_code'
31636 ||' AND msdr.process_flag ='|| G_IN_PROCESS
31637 ||' AND msdr.batch_id = :lv_batch_id';
31638
31639
31640 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
31641
31642 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
31643
31644 -- Set resoure_id=-1 for line resources
31645
31646 lv_sql_stmt :=
31647 'UPDATE msc_st_department_resources msdr'
31648 ||' SET resource_id= -1 '
31649 ||' WHERE msdr.sr_instance_code = :v_instance_code'
31650 ||' AND msdr.process_flag ='|| G_IN_PROCESS
31651 ||' AND NVL(msdr.resource_code, '||''''||NULL_CHAR||''''||') '
31652 ||' = '||''''||NULL_CHAR||''''
31653 ||' AND line_flag = ''1'' '
31654 ||' AND msdr.batch_id = :lv_batch_id';
31655
31656
31657 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
31658
31659 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
31660
31661 --Call to customised validation.
31662
31663 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
31664 (ERRBUF => lv_error_text,
31665 RETCODE => lv_return,
31666 pBatchID => lv_batch_id,
31667 pInstanceCode => v_instance_code,
31668 pEntityName => 'MSC_ST_DEPARTMENT_RESOURCES',
31669 pInstanceID => v_instance_id);
31670
31671 IF NVL(lv_return,0) <> 0 THEN
31672 RAISE ex_logging_err;
31673 END IF;
31674
31675 -- Now generate the department_id
31676
31677 v_sql_stmt := 13;
31678
31679 OPEN c3(lv_batch_id);
31680 FETCH c3 BULK COLLECT INTO lb_rowid ;
31681
31682 IF c3%ROWCOUNT > 0 THEN
31683
31684 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
31685
31686 UPDATE msc_st_department_resources
31687 SET department_id = msc_st_sr_inventory_item_id_s.NEXTVAL
31688 WHERE rowid = lb_rowid(j);
31689
31690
31691 v_sql_stmt := 14;
31692
31693 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
31694
31695 -- Insert into the LID table this new department with the user defined key
31696
31697 INSERT INTO msc_local_id_setup
31698 (local_id,
31699 st_transaction_id,
31700 instance_id,
31701 entity_name,
31702 data_source_type,
31703 char1,
31704 char2,
31705 char3,
31706 char4,
31707 SOURCE_ORGANIZATION_ID,
31708 SOURCE_DEPARTMENT_ID,
31709 last_update_date,
31710 last_updated_by,
31711 creation_date,
31712 created_by )
31713 SELECT
31714 department_id,
31715 st_transaction_id,
31716 v_instance_id,
31717 'DEPARTMENT_ID',
31718 data_source_type,
31719 sr_instance_code,
31720 company_name,
31721 organization_code,
31722 department_code,
31723 SOURCE_ORGANIZATION_ID,
31724 SOURCE_DEPARTMENT_ID,
31725 v_current_date,
31726 v_current_user,
31727 v_current_date,
31728 v_current_user
31729 FROM msc_st_department_resources
31730 WHERE rowid = lb_rowid(j);
31731
31732 END IF;
31733 CLOSE c3;
31734
31735 -- Now derive department id
31736 v_sql_stmt:= 15;
31737
31738 lv_sql_stmt :=
31739 'UPDATE msc_st_department_resources msdr'
31740 ||' SET department_id= (SELECT local_id'
31741 ||' FROM msc_local_id_setup mlis'
31742 ||' WHERE mlis.char1 = msdr.sr_instance_code'
31743 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
31744 ||' = NVL(msdr.company_name,'||''''||NULL_CHAR||''''||') '
31745 ||' AND mlis.char3 = msdr.organization_code'
31746 ||' AND mlis.char4 = msdr.department_code'
31747 ||' AND mlis.entity_name = ''DEPARTMENT_ID'')'
31748 ||' WHERE msdr.sr_instance_code = :v_instance_code'
31749 ||' AND NVL(msdr.department_id,'||NULL_VALUE||') ='|| NULL_VALUE
31750 ||' AND msdr.line_flag = ''2'' '
31751 ||' AND msdr.process_flag ='|| G_IN_PROCESS
31752 ||' AND msdr.batch_id = :lv_batch_id';
31753
31754
31755 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
31756
31757 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
31758
31759 -- Update owning_department_code as department_code if that is NULL
31760 v_sql_stmt := 16;
31761 lv_sql_stmt :=
31762 'UPDATE msc_st_department_resources msdr'
31763 ||' SET owning_department_code = department_code'
31764 ||' WHERE NVL(owning_department_code,'||''''||NULL_CHAR||''''||') '
31765 ||' = '||''''||NULL_CHAR||''''
31766 ||' AND sr_instance_code = :v_instance_code'
31767 ||' AND line_flag = ''2'' '
31768 ||' AND process_flag ='|| G_IN_PROCESS
31769 ||' AND batch_id = :lv_batch_id';
31770
31771
31772 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
31773
31774 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
31775
31776 -- Now derive owning_department id
31777 v_sql_stmt := 17;
31778
31779 lv_sql_stmt :=
31780 'UPDATE msc_st_department_resources msdr'
31781 ||' SET owning_department_id= (SELECT local_id'
31782 ||' FROM msc_local_id_setup mlis'
31783 ||' WHERE mlis.char1 = msdr.sr_instance_code'
31784 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
31785 ||' = NVL(msdr.company_name,'||''''||NULL_CHAR||''''||') '
31786 ||' AND mlis.char3 = msdr.organization_code'
31787 ||' AND mlis.char4 = msdr.owning_department_code'
31788 ||' AND mlis.entity_name = ''DEPARTMENT_ID'')'
31789 ||' WHERE msdr.sr_instance_code = :v_instance_code'
31790 ||' AND NVL(msdr.owning_department_code,'||''''||NULL_CHAR||''''||') '
31791 ||' <> '||''''||NULL_CHAR||''''
31792 ||' AND msdr.line_flag = ''2'' '
31793 ||' AND msdr.process_flag ='|| G_IN_PROCESS
31794 ||' AND msdr.batch_id = :lv_batch_id';
31795
31796
31797 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
31798
31799 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
31800
31801 -- Error out if owning_department_id is NULL
31802 -- Set the error message
31803 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
31804 (p_app_short_name => 'MSC',
31805 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
31806 p_message_text => lv_message_text,
31807 p_error_text => lv_error_text,
31808 p_token1 => 'COLUMN_NAMES',
31809 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
31810 ||'ORGANIZATION_CODE,OWNING_DEPARTMENT_CODE',
31811 p_token2 => 'MASTER_TABLE',
31812 p_token_value2 => 'MSC_ST_DEPARTMENT_RESOURCES',
31813 p_token3 => 'CHILD_TABLE' ,
31814 p_token_value3 => 'MSC_ST_DEPARTMENT_RESOURCES' );
31815
31816 IF lv_return <> 0 THEN
31817 RAISE ex_logging_err;
31818 END IF;
31819 v_sql_stmt := 18;
31820
31821 lv_sql_stmt :=
31822 ' UPDATE msc_st_department_resources '
31823 ||' SET process_flag ='||G_ERROR_FLG||','
31824 ||' error_text = '||''''||lv_message_text||''''
31825 ||' WHERE NVL(owning_department_id,'||NULL_VALUE||') ='|| NULL_VALUE
31826 ||' AND deleted_flag = '||SYS_NO
31827 ||' AND line_flag = ''2'' '
31828 ||' AND process_flag = '||G_IN_PROCESS
31829 ||' AND sr_instance_code = :v_instance_code'
31830 ||' AND batch_id = :lv_batch_id';
31831
31832
31833
31834 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
31835
31836 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
31837
31838
31839 -- Now generate the resource_id
31840
31841 v_sql_stmt := 19;
31842
31843 OPEN c4(lv_batch_id);
31844 FETCH c4 BULK COLLECT INTO lb_rowid ;
31845
31846 IF c4%ROWCOUNT > 0 THEN
31847
31848 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
31849
31850 UPDATE msc_st_department_resources
31851 SET resource_id = msc_st_sr_inventory_item_id_s.NEXTVAL
31852 WHERE rowid = lb_rowid(j);
31853
31854
31855 v_sql_stmt := 20;
31856
31857 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
31858
31859 -- Insert into the LID table this new resource with the user defined key
31860
31861 INSERT INTO msc_local_id_setup
31862 (local_id,
31863 st_transaction_id,
31864 instance_id,
31865 entity_name,
31866 data_source_type,
31867 char1,
31868 char2,
31869 char3,
31870 char4,
31871 SOURCE_ORGANIZATION_ID,
31872 SOURCE_RESOURCE_ID,
31873 SOURCE_OWNING_DEPARTMENT_ID,
31874 last_update_date,
31875 last_updated_by,
31876 creation_date,
31877 created_by )
31878 SELECT
31879 resource_id,
31880 st_transaction_id,
31881 v_instance_id,
31882 'RESOURCE_ID',
31883 data_source_type,
31884 sr_instance_code,
31885 company_name,
31886 organization_code,
31887 resource_code,
31888 SOURCE_ORGANIZATION_ID,
31889 SOURCE_RESOURCE_ID,
31890 SOURCE_OWNING_DEPARTMENT_ID,
31891 v_current_date,
31892 v_current_user,
31893 v_current_date,
31894 v_current_user
31895 FROM msc_st_department_resources
31896 WHERE rowid = lb_rowid(j);
31897
31898 END IF;
31899 CLOSE c4;
31900
31901 -- Derive resource id
31902
31903 v_sql_stmt:= 21;
31904
31905 lv_sql_stmt :=
31906 'UPDATE msc_st_department_resources msdr'
31907 ||' SET resource_id= (SELECT local_id'
31908 ||' FROM msc_local_id_setup mlis'
31909 ||' WHERE mlis.char1 = msdr.sr_instance_code'
31910 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
31911 ||' = NVL(msdr.company_name,'||''''||NULL_CHAR||''''||') '
31912 ||' AND mlis.char3 = msdr.organization_code'
31913 ||' AND mlis.char4 = msdr.resource_code'
31914 ||' AND mlis.entity_name = ''RESOURCE_ID'')'
31915 ||' WHERE msdr.sr_instance_code = :v_instance_code'
31916 ||' AND NVL(msdr.resource_id,'||NULL_VALUE||') ='|| NULL_VALUE
31917 ||' AND msdr.process_flag ='|| G_IN_PROCESS
31918 ||' AND msdr.batch_id = :lv_batch_id';
31919
31920
31921 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
31922
31923 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
31924
31925
31926 v_sql_stmt := 22;
31927
31928 OPEN c5(lv_batch_id);
31929 FETCH c5 BULK COLLECT INTO lb_rowid ;
31930
31931 IF c5%ROWCOUNT > 0 THEN
31932
31933 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
31934
31935 UPDATE msc_st_department_resources
31936 SET department_id = msc_st_sr_inventory_item_id_s.NEXTVAL
31937 WHERE rowid = lb_rowid(j);
31938
31939
31940 v_sql_stmt := 23;
31941
31942 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
31943
31944 -- Insert into the LID table this new department with the user defined key
31945
31946 INSERT INTO msc_local_id_setup
31947 (local_id,
31948 st_transaction_id,
31949 instance_id,
31950 entity_name,
31951 data_source_type,
31952 char1,
31953 char2,
31954 char3,
31955 char4,
31956 SOURCE_ORGANIZATION_ID,
31957 SOURCE_DEPARTMENT_ID,
31958 last_update_date,
31959 last_updated_by,
31960 creation_date,
31961 created_by )
31962 SELECT
31963 department_id,
31964 st_transaction_id,
31965 v_instance_id,
31966 'LINE_ID',
31967 data_source_type,
31968 sr_instance_code,
31969 company_name,
31970 organization_code,
31971 department_code,
31972 SOURCE_ORGANIZATION_ID,
31973 SOURCE_DEPARTMENT_ID,
31974 v_current_date,
31975 v_current_user,
31976 v_current_date,
31977 v_current_user
31978 FROM msc_st_department_resources
31979 WHERE rowid = lb_rowid(j);
31980
31981 END IF;
31982 CLOSE c5;
31983
31984 -- Set the process flag as Valid and poulate instance_id
31985 lv_return :=
31986 MSC_ST_UTIL.SET_PROCESS_FLAG(p_table_name => 'MSC_ST_DEPARTMENT_RESOURCES',
31987 p_instance_id => v_instance_id,
31988 p_instance_code => v_instance_code,
31989 p_process_flag => G_VALID,
31990 p_error_text => lv_error_text,
31991 p_debug => v_debug,
31992 p_batch_id => lv_batch_id);
31993
31994 IF lv_return <> 0 THEN
31995 RAISE ex_logging_err;
31996 END IF;
31997
31998 -- At the end calling the LOG_ERROR for logging all errored out records
31999
32000 lv_return :=
32001 MSC_ST_UTIL.LOG_ERROR(p_table_name => 'MSC_ST_DEPARTMENT_RESOURCES',
32002 p_instance_code => v_instance_code,
32003 p_row => lv_column_names,
32004 p_severity => G_SEV_ERROR,
32005 p_message_text => NULL,
32006 p_error_text => lv_error_text,
32007 p_debug => v_debug,
32008 p_batch_id => lv_batch_id );
32009
32010 IF lv_return <> 0 THEN
32011 RAISE ex_logging_err;
32012 END IF;
32013
32014 COMMIT;
32015 END LOOP;
32016
32017
32018 -- Validation for table MSC_ST_RESOURCE_SHIFTS
32019
32020 --Duplicate records check for the records whose source is XML
32021
32022 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
32023 (p_app_short_name => 'MSC',
32024 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
32025 p_message_text => lv_message_text,
32026 p_error_text => lv_error_text);
32027
32028 IF lv_return <> 0 THEN
32029 RAISE ex_logging_err;
32030 END IF;
32031
32032 -- UDK validations
32033
32034 v_sql_stmt := 19;
32035
32036 lv_sql_stmt:=
32037 'UPDATE msc_st_resource_shifts msrs1'
32038 ||' SET process_flag = '||G_ERROR_FLG||','
32039 ||' error_text = '||''''||lv_message_text||''''
32040 ||' WHERE message_id < ( SELECT max(message_id)'
32041 ||' FROM msc_st_resource_shifts msrs2'
32042 ||' WHERE msrs2.sr_instance_code = msrs1.sr_instance_code'
32043 ||' AND NVL(msrs2.company_name,'||''''||NULL_CHAR||''''||') '
32044 ||' = NVL(msrs1.company_name,'||''''||NULL_CHAR||''''||') '
32045 ||' AND msrs2.organization_code = msrs1.organization_code'
32046 ||' AND msrs2.department_code = msrs1.department_code'
32047 ||' AND msrs2.resource_code = msrs1.resource_code'
32048 ||' AND msrs2.shift_name = msrs1.shift_name'
32049 ||' AND msrs2.process_flag = '||G_IN_PROCESS
32050 ||' AND NVL(msrs2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||')'
32051 ||' AND msrs1.process_flag ='|| G_IN_PROCESS
32052 ||' AND msrs1.sr_instance_code = :v_instance_code'
32053 ||' AND NVL(msrs1.message_id,'||NULL_VALUE||')<> '||NULL_VALUE;
32054
32055
32056 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32057
32058 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
32059
32060
32061 --Duplicate records check for the records whose source is batch load
32062
32063 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
32064 (p_app_short_name => 'MSC',
32065 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
32066 p_message_text => lv_message_text,
32067 p_error_text => lv_error_text);
32068
32069 IF lv_return <> 0 THEN
32070 RAISE ex_logging_err;
32071 END IF;
32072
32073 v_sql_stmt := 20;
32074
32075 lv_sql_stmt:=
32076 'UPDATE msc_st_resource_shifts msrs1'
32077 ||' SET process_flag ='||G_ERROR_FLG||','
32078 ||' error_text = '||''''||lv_message_text||''''
32079 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_resource_shifts msrs2'
32080 ||' WHERE msrs2.sr_instance_code = msrs1.sr_instance_code'
32081 ||' AND NVL(msrs2.company_name,'||''''||NULL_CHAR||''''||') '
32082 ||' = NVL(msrs1.company_name,'||''''||NULL_CHAR||''''||') '
32083 ||' AND msrs2.organization_code = msrs1.organization_code'
32084 ||' AND msrs2.department_code = msrs1.department_code'
32085 ||' AND msrs2.resource_code = msrs1.resource_code'
32086 ||' AND msrs2.shift_name = msrs1.shift_name'
32087 ||' AND msrs2.process_flag ='||G_IN_PROCESS
32088 ||' AND NVL(msrs2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
32089 ||' GROUP BY sr_instance_code,organization_code,company_name,'
32090 ||' department_code,resource_code,shift_name '
32091 ||' HAVING COUNT(*) >1 )'
32092 ||' AND msrs1.process_flag ='|| G_IN_PROCESS
32093 ||' AND msrs1.sr_instance_code = :v_instance_code'
32094 ||' AND NVL(msrs1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
32095
32096
32097 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32098
32099 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
32100
32101
32102 lv_column_names :=
32103 'DEPARTMENT_CODE ||''~''||'
32104 ||'RESOURCE_CODE ||''~''||'
32105 ||'SHIFT_NAME ||''~''||'
32106 ||'ORGANIZATION_CODE ||''~''||'
32107 ||'SR_INSTANCE_CODE ||''~''||'
32108 ||'DELETED_FLAG ||''~''||'
32109 ||'COMPANY_NAME ';
32110
32111 LOOP
32112 v_sql_stmt := 21;
32113 lv_cursor_stmt :=
32114 ' SELECT msc_st_batch_id_s.NEXTVAL '
32115 ||' FROM dual';
32116
32117 OPEN c1 FOR lv_cursor_stmt;
32118 FETCH c1 INTO lv_batch_id;
32119 CLOSE c1;
32120
32121 v_sql_stmt := 22;
32122 lv_sql_stmt :=
32123 ' UPDATE msc_st_resource_shifts '
32124 ||' SET batch_id = :lv_batch_id'
32125 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
32126 ||' AND sr_instance_code = :v_instance_code'
32127 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
32128 ||' AND rownum <= '||v_batch_size;
32129
32130
32131 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32132
32133 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
32134
32135 EXIT WHEN SQL%NOTFOUND;
32136
32137 OPEN c6(lv_batch_id);
32138 FETCH c6 BULK COLLECT INTO lb_rowid;
32139 CLOSE c6;
32140
32141 v_sql_stmt := 23;
32142 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
32143 UPDATE msc_st_resource_shifts
32144 SET st_transaction_id = msc_st_resource_shifts_s.NEXTVAL,
32145 refresh_id = v_refresh_id,
32146 last_update_date = v_current_date,
32147 last_updated_by = v_current_user,
32148 creation_date = v_current_date,
32149 created_by = v_current_user
32150 WHERE rowid = lb_rowid(j);
32151
32152
32153
32154 -- Set the error message
32155
32156 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
32157 (p_app_short_name => 'MSC',
32158 p_error_code => 'MSC_PP_INVALID_VALUE',
32159 p_message_text => lv_message_text,
32160 p_error_text => lv_error_text,
32161 p_token1 => 'COLUMN_NAME',
32162 p_token_value1 => 'COMPANY_NAME');
32163
32164 IF lv_return <> 0 THEN
32165 RAISE ex_logging_err;
32166 END IF;
32167
32168
32169 -- Deletion is not allowed for this table
32170
32171 v_sql_stmt := 24;
32172
32173 lv_sql_stmt :=
32174 ' UPDATE msc_st_resource_shifts '
32175 ||' SET process_flag ='||G_ERROR_FLG||','
32176 ||' error_text = '||''''||lv_message_text||''''
32177 ||' WHERE deleted_flag = '||SYS_YES
32178 ||' AND process_flag = '||G_IN_PROCESS
32179 ||' AND batch_id = :lv_batch_id'
32180 ||' AND sr_instance_code = :v_instance_code';
32181
32182
32183 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32184
32185 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
32186
32187
32188 -- Set the error message
32189 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
32190 (p_app_short_name => 'MSC',
32191 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
32192 p_message_text => lv_message_text,
32193 p_error_text => lv_error_text,
32194 p_token1 => 'COLUMN_NAME',
32195 p_token_value1 => 'DELETED_FLAG',
32196 p_token2 => 'DEFAULT_VALUE',
32197 p_token_value2 => SYS_NO );
32198
32199 IF lv_return <> 0 THEN
32200 RAISE ex_logging_err;
32201 END IF;
32202
32203 -- Check DELETE_FLAG column has valid value or not and if not set it to SYS_NO
32204 -- Log error procedure inserts warning and also defaults the delete flag
32205
32206 lv_where_str :=
32207 ' AND NVL(deleted_flag,'||NULL_VALUE||') <>'||SYS_NO;
32208
32209 lv_return := MSC_ST_UTIL.LOG_ERROR
32210 (p_table_name => 'MSC_ST_RESOURCE_SHIFTS',
32211 p_instance_code => v_instance_code,
32212 p_row => lv_column_names,
32213 p_severity => G_SEV_WARNING,
32214 p_message_text => lv_message_text,
32215 p_error_text => lv_error_text,
32216 p_batch_id => lv_batch_id,
32217 p_where_str => lv_where_str,
32218 p_col_name => 'DELETED_FLAG',
32219 p_debug => v_debug,
32220 p_default_value => SYS_NO);
32221
32222
32223 IF lv_return <> 0 THEN
32224 RAISE ex_logging_err;
32225 END IF;
32226
32227 -- Set the error message
32228
32229 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
32230 (p_app_short_name => 'MSC',
32231 p_error_code => 'MSC_PP_NO_DELETION',
32232 p_message_text => lv_message_text,
32233 p_error_text => lv_error_text,
32234 p_token1 => 'TABLE_NAME',
32235 p_token_value1 => 'MSC_ST_RESOURCE_SHIFTS');
32236
32237 IF lv_return <> 0 THEN
32238 RAISE ex_logging_err;
32239 END IF;
32240
32241 -- Popluate the Department id from LOCAL_ID table
32242
32243 v_sql_stmt := 25;
32244 lv_sql_stmt :=
32245 'UPDATE msc_st_resource_shifts msrs'
32246 ||' SET department_id = (SELECT local_id'
32247 ||' FROM msc_local_id_setup mlis'
32248 ||' WHERE mlis.char1 = msrs.sr_instance_code'
32249 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
32250 ||' = NVL(msrs.company_name,'||''''||NULL_CHAR||''''||') '
32251 ||' AND mlis.char3 = msrs.organization_code'
32252 ||' AND mlis.char4 = msrs.department_code'
32253 ||' AND mlis.entity_name = ''DEPARTMENT_ID'' '
32254 ||' AND mlis.instance_id = '||v_instance_id||')'
32255 ||' WHERE sr_instance_code = :v_instance_code'
32256 ||' AND process_flag = '|| G_IN_PROCESS
32257 ||' AND batch_id = :lv_batch_id';
32258
32259
32260 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32261
32262 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
32263
32264 -- Set the error message
32265 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
32266 (p_app_short_name => 'MSC',
32267 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
32268 p_message_text => lv_message_text,
32269 p_error_text => lv_error_text,
32270 p_token1 => 'COLUMN_NAMES',
32271 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME'
32272 ||' ORGANIZATION_CODE,DEPARTMENT_CODE',
32273 p_token2 => 'MASTER_TABLE',
32274 p_token_value2 => 'MSC_ST_DEPARTMENT_RESOURCES',
32275 p_token3 => 'CHILD_TABLE' ,
32276 p_token_value3 => 'MSC_ST_RESOURCE_SHIFTS' );
32277
32278 IF lv_return <> 0 THEN
32279 RAISE ex_logging_err;
32280 END IF;
32281
32282
32283 -- Error out the reords where department id is NULL
32284
32285 v_sql_stmt := 26;
32286 lv_sql_stmt:=
32287 'UPDATE msc_st_resource_shifts '
32288 ||' SET process_flag = '||G_ERROR_FLG||','
32289 ||' error_text = '||''''||lv_message_text||''''
32290 ||' WHERE NVL(department_id,'||NULL_VALUE||') = '||NULL_VALUE
32291 ||' AND sr_instance_code = :v_instance_code'
32292 ||' AND process_flag ='|| G_IN_PROCESS
32293 ||' AND batch_id = :lv_batch_id';
32294
32295
32296 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32297
32298 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
32299
32300 -- Popluate the resource id from LOCAL_ID table
32301 v_sql_stmt := 27;
32302 lv_sql_stmt:=
32303 'UPDATE msc_st_resource_shifts msrs'
32304 ||' SET resource_id = (SELECT local_id FROM msc_local_id_setup mlis'
32305 ||' WHERE mlis.char1 = msrs.sr_instance_code'
32306 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
32307 ||' = NVL(msrs.company_name,'||''''||NULL_CHAR||''''||') '
32308 ||' AND mlis.char3 = msrs.organization_code'
32309 ||' AND mlis.char4 = msrs.resource_code'
32310 ||' AND mlis.entity_name = ''RESOURCE_ID'' '
32311 ||' AND mlis.instance_id = '||v_instance_id||')'
32312 ||' WHERE sr_instance_code = :v_instance_code'
32313 ||' AND process_flag = '|| G_IN_PROCESS
32314 ||' AND batch_id = :lv_batch_id';
32315
32316
32317 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32318
32319 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
32320
32321 -- Set the error message
32322 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
32323 (p_app_short_name => 'MSC',
32324 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
32325 p_message_text => lv_message_text,
32326 p_error_text => lv_error_text,
32327 p_token1 => 'COLUMN_NAMES',
32328 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
32329 ||' ORGANIZATION_CODE,RESOURCE_CODE',
32330 p_token2 => 'MASTER_TABLE',
32331 p_token_value2 => 'MSC_ST_DEPARTMENT_RESOURCES',
32332 p_token3 => 'CHILD_TABLE' ,
32333 p_token_value3 => 'MSC_ST_RESOURCE_SHIFTS' );
32334
32335 IF lv_return <> 0 THEN
32336 RAISE ex_logging_err;
32337 END IF;
32338
32339 -- Error out the records where resource id is NULL
32340
32341 v_sql_stmt := 28;
32342 lv_sql_stmt:=
32343 'UPDATE msc_st_resource_shifts '
32344 ||' SET process_flag = '||G_ERROR_FLG||','
32345 ||' error_text = '||''''||lv_message_text||''''
32346 ||' WHERE NVL(resource_id,'||NULL_VALUE||') = '||NULL_VALUE
32347 ||' AND sr_instance_code = :v_instance_code'
32348 ||' AND process_flag ='|| G_IN_PROCESS
32349 ||' AND batch_id = :lv_batch_id';
32350
32351
32352 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32353
32354 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
32355
32356
32357 /* Bug 2172537 ,instance code not prefixed in calendar and org*/
32358 -- Derive the SHIFT_NUM
32359
32360 v_sql_stmt := 29;
32361 lv_sql_stmt :=
32362 'UPDATE msc_st_resource_shifts msrs'
32363 ||' SET shift_num =(SELECT mlis.local_id'
32364 ||' FROM msc_local_id_setup mlis, msc_st_trading_partners mtp '
32365 ||' WHERE mtp.sr_instance_id = '||v_instance_id
32366 ||' AND mlis.char1 = msrs.sr_instance_code'
32367 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
32368 ||' = NVL(msrs.company_name,'||''''||NULL_CHAR||''''||') '
32369 ||' AND mtp.calendar_code = mlis.char3'
32370 ||' AND mlis.char4 = msrs.shift_name'
32371 ||' AND mlis.entity_name = ''SHIFT_NUM'' '
32372 ||' AND mlis.instance_id = '||v_instance_id
32373 ||' AND mtp.organization_code = msrs.organization_code'
32374 ||' AND mtp.process_flag = '||G_VALID
32375 ||' AND mtp.partner_type = 3 )'
32376 ||' WHERE msrs.sr_instance_code = :v_instance_code'
32377 ||' AND msrs.process_flag ='|| G_IN_PROCESS
32378 ||' AND msrs.batch_id = :lv_batch_id';
32379
32380
32381 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32382
32383 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
32384
32385 /* Bug 2172537 ,instance code not prefixed in calendar and org*/
32386
32387 lv_sql_stmt :=
32388 'UPDATE msc_st_resource_shifts msrs'
32389 ||' SET shift_num =(SELECT mlis.local_id'
32390 ||' FROM msc_local_id_setup mlis, msc_trading_partners mtp '
32391 ||' WHERE mtp.sr_instance_id = '||v_instance_id
32392 ||' AND mlis.char1 = msrs.sr_instance_code'
32393 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
32394 ||' = NVL(msrs.company_name,'||''''||NULL_CHAR||''''||') '
32395 ||' AND mtp.calendar_code = mlis.char3'
32396 ||' AND mlis.char4 = msrs.shift_name'
32397 ||' AND mlis.entity_name = ''SHIFT_NUM'' '
32398 ||' AND mlis.instance_id = '||v_instance_id
32399 ||' AND mtp.organization_code = msrs.organization_code'
32400 ||' AND mtp.partner_type = 3 )'
32401 ||' WHERE msrs.sr_instance_code = :v_instance_code'
32402 ||' AND NVL(msrs.shift_num,'||NULL_VALUE||') = '||NULL_VALUE
32403 ||' AND msrs.process_flag ='|| G_IN_PROCESS
32404 ||' AND msrs.batch_id = :lv_batch_id';
32405
32406
32407 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32408
32409
32410 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
32411
32412
32413 -- Set the error message
32414 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
32415 (p_app_short_name => 'MSC',
32416 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
32417 p_message_text => lv_message_text,
32418 p_error_text => lv_error_text,
32419 p_token1 => 'COLUMN_NAMES',
32420 p_token_value1 => 'SR_INSTANCE_CODE,'
32421 ||' ORGANIZATION_CODE,SHIFT_NAME',
32422 p_token2 => 'MASTER_TABLE',
32423 p_token_value2 => 'MSC_ST_CALENDAR_SHIFTS',
32424 p_token3 => 'CHILD_TABLE' ,
32425 p_token_value3 => 'MSC_ST_RESOURCE_SHIFTS' );
32426
32427 IF lv_return <> 0 THEN
32428 RAISE ex_logging_err;
32429 END IF;
32430
32431
32432 -- Error out records where shift_num is NULL
32433
32434 v_sql_stmt := 30;
32435
32436 lv_sql_stmt:=
32437 'UPDATE msc_st_resource_shifts '
32438 ||' SET process_flag = '||G_ERROR_FLG||','
32439 ||' error_text = '||''''||lv_message_text||''''
32440 ||' WHERE NVL(shift_num,'||NULL_VALUE||') = '||NULL_VALUE
32441 ||' AND sr_instance_code = :v_instance_code'
32442 ||' AND process_flag ='|| G_IN_PROCESS
32443 ||' AND batch_id = :lv_batch_id';
32444
32445
32446 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32447
32448 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
32449
32450
32451 --Call to customised validation.
32452
32453 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
32454 (ERRBUF => lv_error_text,
32455 RETCODE => lv_return,
32456 pBatchID => lv_batch_id,
32457 pInstanceCode => v_instance_code,
32458 pEntityName => 'MSC_ST_RESOURCE_SHIFTS',
32459 pInstanceID => v_instance_id);
32460
32461 IF NVL(lv_return,0) <> 0 THEN
32462 RAISE ex_logging_err;
32463 END IF;
32464
32465
32466 -- Set the process flag as Valid and populate instance_id
32467 lv_return :=
32468 MSC_ST_UTIL.SET_PROCESS_FLAG(p_table_name => 'MSC_ST_RESOURCE_SHIFTS',
32469 p_instance_id => v_instance_id,
32470 p_instance_code => v_instance_code,
32471 p_process_flag => G_VALID,
32472 p_error_text => lv_error_text,
32473 p_debug => v_debug,
32474 p_batch_id => lv_batch_id);
32475
32476 IF lv_return <> 0 THEN
32477 RAISE ex_logging_err;
32478 END IF;
32479
32480 -- At the end calling the LOG_ERROR for logging all errored out records
32481
32482 lv_return :=
32483 MSC_ST_UTIL.LOG_ERROR(p_table_name =>'MSC_ST_RESOURCE_SHIFTS',
32484 p_instance_code =>v_instance_code,
32485 p_row =>lv_column_names,
32486 p_severity =>G_ERROR_FLG,
32487 p_message_text =>NULL,
32488 p_error_text =>lv_error_text,
32489 p_debug => v_debug,
32490 p_batch_id => lv_batch_id );
32491
32492 IF lv_return <> 0 THEN
32493 RAISE ex_logging_err;
32494 END IF;
32495
32496 COMMIT;
32497 END LOOP;
32498
32499
32500 -- Validation for table MSC_ST_RESOURCE_CHANGES
32501
32502 --Duplicate records check for the records whose source is XML
32503
32504 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
32505 (p_app_short_name => 'MSC',
32506 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
32507 p_message_text => lv_message_text,
32508 p_error_text => lv_error_text);
32509
32510 IF lv_return <> 0 THEN
32511 RAISE ex_logging_err;
32512 END IF;
32513
32514 -- Duplicate UDK validation for XML message
32515
32516 v_sql_stmt := 31;
32517 lv_sql_stmt :=
32518 'UPDATE msc_st_resource_changes msrc1'
32519 ||' SET process_flag = '||G_ERROR_FLG||','
32520 ||' error_text = '||''''||lv_message_text||''''
32521 ||' WHERE message_id < ( SELECT max(message_id)'
32522 ||' FROM msc_st_resource_changes msrc2'
32523 ||' WHERE msrc2.sr_instance_code '
32524 ||' = msrc1.sr_instance_code'
32525 ||' AND msrc2.organization_code '
32526 ||' = msrc1.organization_code'
32527 ||' AND NVL(msrc2.company_name,'||''''||NULL_CHAR||''''||') '
32528 ||' = NVL(msrc1.company_name,'||''''||NULL_CHAR||''''||') '
32529 ||' AND msrc2.department_code '
32530 ||' = msrc1.department_code'
32531 ||' AND msrc2.resource_code '
32532 ||' = msrc1.resource_code'
32533 ||' AND msrc2.shift_name '
32534 ||' = msrc1.shift_name '
32535 ||' AND NVL(msrc2.simulation_set,'||''''||NULL_CHAR||''''||') '
32536 ||' = NVL(msrc1.simulation_set,'||''''||NULL_CHAR||''''||') '
32537 ||' AND msrc2.from_date '
32538 ||' = msrc1.from_date'
32539 ||' AND NVL(msrc2.to_date,(sysdate-36500)) '
32540 ||' = NVL(msrc1.to_date,(sysdate-36500)) '
32541 ||' AND NVL(msrc2.from_time,'||NULL_VALUE||')'
32542 ||' = NVL(msrc1.from_time,'||NULL_VALUE||')'
32543 ||' AND NVL(msrc2.to_time,'||NULL_VALUE||')'
32544 ||' = NVL(msrc1.to_time,'||NULL_VALUE||')'
32545 ||' AND msrc2.action_type '
32546 ||' = msrc2.action_type'
32547 ||' AND msrc2.deleted_flag '
32548 ||' = msrc1.deleted_flag '
32549 ||' AND msrc2.process_flag ='||G_IN_PROCESS
32550 ||' AND NVL(msrc2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||')'
32551 ||' AND msrc1.process_flag ='|| G_IN_PROCESS
32552 ||' AND msrc1.sr_instance_code = :v_instance_code '
32553 ||' AND NVL(msrc1.message_id,'||NULL_VALUE||')<> '||NULL_VALUE;
32554
32555
32556 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32557
32558 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
32559
32560 --Duplicate records check for the records whose source is batch load
32561
32562 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
32563 (p_app_short_name => 'MSC',
32564 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
32565 p_message_text => lv_message_text,
32566 p_error_text => lv_error_text);
32567
32568 IF lv_return <> 0 THEN
32569 RAISE ex_logging_err;
32570 END IF;
32571
32572 LV_SQL_STMT :=
32573 'UPDATE MSC_ST_RESOURCE_CHANGES MSRC1'
32574 ||' SET PROCESS_FLAG = '||G_ERROR_FLG||','
32575 ||' ERROR_TEXT = '||''''||LV_MESSAGE_TEXT||''''
32576 ||' WHERE '
32577 ||' (SR_INSTANCE_CODE ,'
32578 ||' ORGANIZATION_CODE,'
32579 ||' COMPANY_NAME ,'
32580 ||' DEPARTMENT_CODE ,'
32581 ||' RESOURCE_CODE ,'
32582 ||' SHIFT_NAME ,'
32583 ||' SIMULATION_SET ,'
32584 ||' FROM_DATE ,'
32585 ||' TO_DATE ,'
32586 ||' FROM_TIME ,'
32587 ||' TO_TIME ,'
32588 ||' ACTION_TYPE ,'
32589 ||' DELETED_FLAG) IN'
32590 ||' (SELECT '
32591 ||' SR_INSTANCE_CODE ,'
32592 ||' ORGANIZATION_CODE,'
32593 ||' COMPANY_NAME ,'
32594 ||' DEPARTMENT_CODE ,'
32595 ||' RESOURCE_CODE ,'
32596 ||' SHIFT_NAME ,'
32597 ||' SIMULATION_SET ,'
32598 ||' FROM_DATE ,'
32599 ||' TO_DATE ,'
32600 ||' FROM_TIME ,'
32601 ||' TO_TIME ,'
32602 ||' ACTION_TYPE ,'
32603 ||' DELETED_FLAG '
32604 ||' FROM MSC_ST_RESOURCE_CHANGES MSRC2'
32605 ||' WHERE '
32606 ||' MSRC2.PROCESS_FLAG ='||G_IN_PROCESS
32607 ||' AND NVL(MSRC2.MESSAGE_ID,'||NULL_VALUE||') = '||NULL_VALUE
32608 ||' GROUP BY SR_INSTANCE_CODE,ORGANIZATION_CODE,COMPANY_NAME,DEPARTMENT_CODE,'
32609 ||' RESOURCE_CODE,SHIFT_NAME,SIMULATION_SET,FROM_DATE,'
32610 ||' TO_DATE,FROM_TIME,TO_TIME,ACTION_TYPE,DELETED_FLAG'
32611 ||' HAVING COUNT(*) >1 )'
32612 ||' AND MSRC1.PROCESS_FLAG ='|| G_IN_PROCESS
32613 ||' AND MSRC1.SR_INSTANCE_CODE = :V_INSTANCE_CODE'
32614 ||' AND NVL(MSRC1.MESSAGE_ID,'||NULL_VALUE||') = '||NULL_VALUE ;
32615
32616
32617
32618 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32619
32620 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
32621
32622
32623 lv_column_names :=
32624 'DEPARTMENT_CODE ||''~''||'
32625 ||'RESOURCE_CODE ||''~''||'
32626 ||'SHIFT_NAME ||''~''||'
32627 ||'FROM_DATE ||''~''||'
32628 ||'SIMULATION_SET ||''~''||'
32629 ||'ACTION_TYPE ||''~''||'
32630 ||'ORGANIZATION_CODE ||''~''||'
32631 ||'SR_INSTANCE_CODE ||''~''||'
32632 ||'TO_DATE ||''~''||'
32633 ||'FROM_TIME ||''~''||'
32634 ||'TO_TIME ||''~''||'
32635 ||'CAPACITY_CHANGE ||''~''||'
32636 ||'DELETED_FLAG ||''~''||'
32637 ||'COMPANY_NAME' ;
32638
32639
32640
32641 LOOP
32642 v_sql_stmt := 33;
32643 lv_cursor_stmt :=
32644 ' SELECT msc_st_batch_id_s.NEXTVAL '
32645 ||' FROM dual';
32646
32647 OPEN c1 FOR lv_cursor_stmt;
32648 FETCH c1 INTO lv_batch_id;
32649 CLOSE c1;
32650
32651 v_sql_stmt := 34;
32652 lv_sql_stmt :=
32653 ' UPDATE msc_st_resource_changes '
32654 ||' SET batch_id = :lv_batch_id'
32655 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
32656 ||' AND sr_instance_code = :v_instance_code'
32657 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
32658 ||' AND rownum <= '||v_batch_size;
32659
32660
32661 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32662
32663 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
32664
32665 EXIT WHEN SQL%NOTFOUND;
32666
32667 OPEN c7(lv_batch_id);
32668 FETCH c7 BULK COLLECT INTO lb_rowid;
32669 CLOSE c7;
32670
32671 v_sql_stmt := 35;
32672 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
32673 UPDATE msc_st_resource_changes
32674 SET st_transaction_id = msc_st_resource_changes_s.NEXTVAL,
32675 refresh_id = v_refresh_id,
32676 last_update_date = v_current_date,
32677 last_updated_by = v_current_user,
32678 creation_date = v_current_date,
32679 created_by = v_current_user
32680 WHERE rowid = lb_rowid(j);
32681
32682
32683
32684 -- Set the error message
32685
32686 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
32687 (p_app_short_name => 'MSC',
32688 p_error_code => 'MSC_PP_COL_VAL_NULL',
32689 p_message_text => lv_message_text,
32690 p_error_text => lv_error_text,
32691 p_token1 => 'COLUMN_NAME',
32692 p_token_value1 => 'FROM_DATE');
32693
32694 IF lv_return <> 0 THEN
32695 RAISE ex_logging_err;
32696 END IF;
32697
32698 -- Error out records where from_date is NULL
32699
32700 v_sql_stmt := 37;
32701 lv_sql_Stmt:=
32702 'UPDATE msc_st_resource_changes '
32703 ||' SET process_flag ='||G_ERROR_FLG||','
32704 ||' error_text = '||''''||lv_message_text||''''
32705 ||' WHERE NVL(from_date,(sysdate-36500)) = (sysdate-36500)'
32706 ||' AND sr_instance_code = :v_instance_code'
32707 ||' AND process_flag ='|| G_IN_PROCESS
32708 ||' AND batch_id = :lv_batch_id';
32709
32710
32711 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32712
32713 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
32714
32715 -- Set the message
32716
32717 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
32718 (p_app_short_name => 'MSC',
32719 p_error_code => 'MSC_PP_INVALID_VALUE',
32720 p_message_text => lv_message_text,
32721 p_error_text => lv_error_text,
32722 p_token1 => 'COLUMN_NAME',
32723 p_token_value1 => 'ACTION_TYPE');
32724
32725 IF lv_return <> 0 THEN
32726 RAISE ex_logging_err;
32727 END IF;
32728
32729
32730 -- error out record with ACTION_TYPE NOT IN (1,2,3)
32731
32732 v_sql_stmt := 38;
32733
32734 lv_sql_Stmt:=
32735 'UPDATE msc_st_resource_changes '
32736 ||' SET process_flag ='||G_ERROR_FLG||','
32737 ||' error_text = '||''''||lv_message_text||''''
32738 ||' WHERE NVL(action_type,'||NULL_VALUE||') NOT IN (1,2,3) '
32739 ||' AND sr_instance_code = :v_instance_code'
32740 ||' AND process_flag ='|| G_IN_PROCESS
32741 ||' AND batch_id = :lv_batch_id';
32742
32743
32744 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32745
32746 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
32747
32748
32749 -- Set the error message
32750 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
32751 (p_app_short_name => 'MSC',
32752 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
32753 p_message_text => lv_message_text,
32754 p_error_text => lv_error_text,
32755 p_token1 => 'COLUMN_NAME',
32756 p_token_value1 => 'DELETED_FLAG',
32757 p_token2 => 'DEFAULT_VALUE',
32758 p_token_value2 => SYS_NO );
32759
32760 IF lv_return <> 0 THEN
32761 RAISE ex_logging_err;
32762 END IF;
32763
32764 -- Check whether delete flag value is in (1,2),if not default to SYS_NO
32765
32766 lv_where_str := ' AND NVL(deleted_flag,'||NULL_VALUE||')NOT IN (1,2)';
32767
32768 lv_return := MSC_ST_UTIL.LOG_ERROR
32769 (p_table_name => 'MSC_ST_RESOURCE_CHANGES',
32770 p_instance_code => v_instance_code,
32771 p_row => lv_column_names,
32772 p_severity => G_SEV_WARNING,
32773 p_message_text => lv_message_text,
32774 p_error_text => lv_error_text,
32775 p_batch_id => lv_batch_id,
32776 p_where_str => lv_where_str,
32777 p_col_name => 'DELETED_FLAG',
32778 p_debug => v_debug,
32779 p_default_value => SYS_NO);
32780
32781
32782 IF lv_return <> 0 THEN
32783 RAISE ex_logging_err;
32784 END IF;
32785
32786 --Set the message
32787 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
32788 (p_app_short_name => 'MSC',
32789 p_error_code => 'MSC_PP_INVALID_VALUE',
32790 p_message_text => lv_message_text,
32791 p_error_text => lv_error_text,
32792 p_token1 => 'COLUMN_NAME',
32793 p_token_value1 => 'ORGANIZATION_CODE');
32794
32795 IF lv_return <> 0 THEN
32796 RAISE ex_logging_err;
32797 END IF;
32798
32799 -- Derive organization id
32800 lv_return :=
32801 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name => 'MSC_ST_RESOURCE_CHANGES',
32802 p_org_partner_name => 'ORGANIZATION_CODE',
32803 p_org_partner_id => 'ORGANIZATION_ID',
32804 p_instance_code => v_instance_code,
32805 p_partner_type => G_ORGANIZATION,
32806 p_severity => G_SEV_ERROR,
32807 p_message_text => lv_message_text,
32808 p_batch_id => lv_batch_id,
32809 p_debug => v_debug,
32810 p_error_text => lv_error_text);
32811
32812 IF(lv_return <> 0) then
32813 RAISE ex_logging_err;
32814 END IF;
32815
32816
32817 -- Popluate the Department id from LOCAL_ID table
32818
32819 v_sql_stmt := 39;
32820 lv_sql_stmt :=
32821 'UPDATE msc_st_resource_changes msrc'
32822 ||' SET department_id = (SELECT local_id'
32823 ||' FROM msc_local_id_setup mlis'
32824 ||' WHERE mlis.char1 = msrc.sr_instance_code'
32825 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
32826 ||' = NVL(msrc.company_name,'||''''||NULL_CHAR||''''||') '
32827 ||' AND mlis.char3 = msrc.organization_code'
32828 ||' AND mlis.char4 = msrc.department_code'
32829 ||' AND mlis.entity_name = ''DEPARTMENT_ID'' '
32830 ||' AND mlis.instance_id = '||v_instance_id||')'
32831 ||' WHERE sr_instance_code = :v_instance_code'
32832 ||' AND process_flag = '|| G_IN_PROCESS
32833 ||' AND batch_id = :lv_batch_id';
32834
32835
32836 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32837
32838 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code, lv_batch_id;
32839
32840 -- Set the error message
32841 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
32842 (p_app_short_name => 'MSC',
32843 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
32844 p_message_text => lv_message_text,
32845 p_error_text => lv_error_text,
32846 p_token1 => 'COLUMN_NAMES',
32847 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
32848 ||' ORGANIZATION_CODE,DEPARTMENT_CODE',
32849 p_token2 => 'MASTER_TABLE',
32850 p_token_value2 => 'MSC_ST_DEPARTMENT_RESOURCES',
32851 p_token3 => 'CHILD_TABLE' ,
32852 p_token_value3 => 'MSC_ST_RESOURCE_CHANGES' );
32853
32854 IF lv_return <> 0 THEN
32855 RAISE ex_logging_err;
32856 END IF;
32857
32858 -- Error out the records where department id is NULL
32859
32860 v_sql_stmt := 40;
32861 lv_sql_stmt:=
32862 'UPDATE msc_st_resource_changes '
32863 ||' SET process_flag = '||G_ERROR_FLG||','
32864 ||' error_text = '||''''||lv_message_text||''''
32865 ||' WHERE NVL(department_id,'||NULL_VALUE||') = '||NULL_VALUE
32866 ||' AND sr_instance_code = :v_instance_code'
32867 ||' AND process_flag ='|| G_IN_PROCESS
32868 ||' AND batch_id = :lv_batch_id';
32869
32870
32871 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32872
32873 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id ;
32874
32875
32876 -- Popluate the resource id from LOCAL_ID table
32877 v_sql_stmt := 41;
32878 lv_sql_stmt:=
32879 'UPDATE msc_st_resource_changes msrc'
32880 ||' SET resource_id = (SELECT local_id'
32881 ||' FROM msc_local_id_setup mlis'
32882 ||' WHERE mlis.char1 = msrc.sr_instance_code'
32883 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
32884 ||' = NVL(msrc.company_name,'||''''||NULL_CHAR||''''||') '
32885 ||' AND mlis.char3 = msrc.organization_code'
32886 ||' AND mlis.char4 = msrc.resource_code'
32887 ||' AND mlis.entity_name = ''RESOURCE_ID'' '
32888 ||' AND mlis.instance_id = '||v_instance_id||')'
32889 ||' WHERE sr_instance_code = :v_instance_code'
32890 ||' AND process_flag = '|| G_IN_PROCESS
32891 ||' AND batch_id = :lv_batch_id';
32892
32893
32894 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32895
32896 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
32897
32898
32899 -- Set the error message
32900 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
32901 (p_app_short_name => 'MSC',
32902 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
32903 p_message_text => lv_message_text,
32904 p_error_text => lv_error_text,
32905 p_token1 => 'COLUMN_NAMES',
32906 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
32907 ||' ORGANIZATION_CODE,RESOURCE_CODE',
32908 p_token2 => 'MASTER_TABLE',
32909 p_token_value2 => 'MSC_ST_DEPARTMENT_RESOURCES',
32910 p_token3 => 'CHILD_TABLE' ,
32911 p_token_value3 => 'MSC_ST_RESOURCE_CHANGES' );
32912
32913 IF lv_return <> 0 THEN
32914 RAISE ex_logging_err;
32915 END IF;
32916
32917 -- Error out the records where resource id is NULL
32918
32919 v_sql_stmt := 42;
32920 lv_sql_stmt:=
32921 'UPDATE msc_st_resource_changes '
32922 ||' SET process_flag = '||G_ERROR_FLG||','
32923 ||' error_text = '||''''||lv_message_text||''''
32924 ||' WHERE NVL(resource_id,'||NULL_VALUE||') = '||NULL_VALUE
32925 ||' AND sr_instance_code = :v_instance_code'
32926 ||' AND process_flag ='|| G_IN_PROCESS
32927 ||' AND batch_id = :lv_batch_id';
32928
32929
32930 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32931
32932 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
32933
32934
32935 /* Bug 2172537 ,instance code not prefixed in calendar and org*/
32936 -- Populate the SHIFT_NUM
32937 v_sql_stmt := 43;
32938
32939 lv_sql_stmt :=
32940 'UPDATE msc_st_resource_changes msrc'
32941 ||' SET shift_num =(SELECT mlis.local_id'
32942 ||' FROM msc_local_id_setup mlis, msc_st_trading_partners mtp '
32943 ||' WHERE mtp.sr_instance_id = '||v_instance_id
32944 ||' AND mlis.char1 = msrc.sr_instance_code'
32945 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
32946 ||' = NVL(msrc.company_name,'||''''||NULL_CHAR||''''||') '
32947 ||' AND mtp.calendar_code = mlis.char3'
32948 ||' AND mlis.char4 = msrc.shift_name'
32949 ||' AND mlis.entity_name = ''SHIFT_NUM'' '
32950 ||' AND mlis.instance_id = '||v_instance_id
32951 ||' AND mtp.organization_code = msrc.organization_code'
32952 ||' AND mtp.process_flag = '||G_VALID
32953 ||' AND mtp.partner_type = 3 )'
32954 ||' WHERE msrc.sr_instance_code = :v_instance_code'
32955 ||' AND msrc.process_flag ='|| G_IN_PROCESS
32956 ||' AND msrc.batch_id = :lv_batch_id';
32957
32958
32959 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32960
32961
32962 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
32963
32964
32965 lv_sql_stmt :=
32966 'UPDATE msc_st_resource_changes msrc'
32967 ||' SET shift_num =(SELECT mlis.local_id'
32968 ||' FROM msc_local_id_setup mlis, msc_trading_partners mtp '
32969 ||' WHERE mtp.sr_instance_id = '||v_instance_id
32970 ||' AND mlis.char1 = msrc.sr_instance_code'
32971 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
32972 ||' = NVL(msrc.company_name,'||''''||NULL_CHAR||''''||') '
32973 ||' AND mtp.calendar_code = mlis.char3'
32974 ||' AND mlis.char4 = msrc.shift_name'
32975 ||' AND mlis.entity_name = ''SHIFT_NUM'' '
32976 ||' AND mlis.instance_id = '||v_instance_id
32977 ||' AND mtp.organization_code = msrc.organization_code'
32978 ||' AND mtp.partner_type = 3 )'
32979 ||' WHERE msrc.sr_instance_code = :v_instance_code'
32980 ||' AND NVL(msrc.shift_num,'||NULL_VALUE||') = '||NULL_VALUE
32981 ||' AND msrc.process_flag ='|| G_IN_PROCESS
32982 ||' AND msrc.batch_id = :lv_batch_id';
32983
32984
32985 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
32986
32987
32988 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
32989
32990
32991 -- Set the error message
32992 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
32993 (p_app_short_name => 'MSC',
32994 p_error_code => 'MSC_PP_INVALID_VALUE',
32995 p_message_text => lv_message_text,
32996 p_error_text => lv_error_text,
32997 p_token1 => 'COLUMN_NAME',
32998 p_token_value1 => 'SHIFT_NAME');
32999 IF lv_return <> 0 THEN
33000 RAISE ex_logging_err;
33001 END IF;
33002
33003
33004 -- Error out records where shift_num is NULL
33005
33006 v_sql_stmt := 30;
33007
33008 lv_sql_stmt:=
33009 'UPDATE msc_st_resource_changes '
33010 ||' SET process_flag = '||G_ERROR_FLG||','
33011 ||' error_text = '||''''||lv_message_text||''''
33012 ||' WHERE NVL(shift_num,'||NULL_VALUE||') = '||NULL_VALUE
33013 ||' AND sr_instance_code = :v_instance_code'
33014 ||' AND process_flag ='|| G_IN_PROCESS
33015 ||' AND batch_id = :lv_batch_id';
33016
33017
33018 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
33019
33020 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
33021
33022 lv_simulation_set := v_instance_code||':'||'SIMSET' ;
33023
33024 v_sql_stmt := 31;
33025
33026 lv_sql_stmt:=
33027 'UPDATE msc_st_resource_changes '
33028 ||' SET simulation_set = '||''''||lv_simulation_set||''''
33029 ||' WHERE NVL(simulation_set,'||''''||NULL_CHAR||''''||') '
33030 ||' = '||''''||NULL_CHAR||''''
33031 ||' AND sr_instance_code = :v_instance_code'
33032 ||' AND process_flag ='|| G_IN_PROCESS
33033 ||' AND batch_id = :lv_batch_id';
33034
33035
33036 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
33037
33038 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
33039
33040
33041 --Call to customised validation.
33042
33043 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
33044 (ERRBUF => lv_error_text,
33045 RETCODE => lv_return,
33046 pBatchID => lv_batch_id,
33047 pInstanceCode => v_instance_code,
33048 pEntityName => 'MSC_ST_RESOURCE_CHANGES',
33049 pInstanceID => v_instance_id);
33050
33051 IF NVL(lv_return,0) <> 0 THEN
33052 RAISE ex_logging_err;
33053 END IF;
33054
33055
33056 -- Set the process flag as Valid and populate instance_id
33057 lv_return :=
33058 MSC_ST_UTIL.SET_PROCESS_FLAG(p_table_name => 'MSC_ST_RESOURCE_CHANGES',
33059 p_instance_id => v_instance_id,
33060 p_instance_code => v_instance_code,
33061 p_process_flag => G_VALID,
33062 p_error_text => lv_error_text,
33063 p_debug => v_debug,
33064 p_batch_id => lv_batch_id);
33065
33066 IF lv_return <> 0 THEN
33067 RAISE ex_logging_err;
33068 END IF;
33069
33070 -- Also insert the simulation set
33071 OPEN c8(lv_batch_id);
33072 FETCH c8 BULK COLLECT INTO lb_rowid ;
33073
33074 IF c8%ROWCOUNT > 0 THEN
33075
33076 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
33077
33078 INSERT INTO msc_st_simulation_sets
33079 ( ORGANIZATION_ID,
33080 SIMULATION_SET,
33081 DESCRIPTION,
33082 USE_IN_WIP_FLAG,
33083 DELETED_FLAG,
33084 REFRESH_ID,
33085 SR_INSTANCE_ID)
33086 SELECT
33087 ORGANIZATION_ID,
33088 SIMULATION_SET,
33089 NULL,
33090 NULL,
33091 DELETED_FLAG,
33092 v_refresh_id,
33093 SR_INSTANCE_ID
33094 FROM msc_st_resource_changes
33095 where rowid = lb_rowid(j) ;
33096
33097 END IF;
33098 CLOSE c8;
33099
33100
33101 -- At the end calling the LOG_ERROR for logging all errored out records
33102
33103 lv_return :=
33104 MSC_ST_UTIL.LOG_ERROR(p_table_name => 'MSC_ST_RESOURCE_CHANGES',
33105 p_instance_code => v_instance_code,
33106 p_row => lv_column_names,
33107 p_severity => G_SEV_ERROR,
33108 p_message_text => NULL,
33109 p_error_text => lv_error_text,
33110 p_debug => v_debug,
33111 p_batch_id => lv_batch_id );
33112
33113 IF lv_return <> 0 THEN
33114 RAISE ex_logging_err;
33115 END IF;
33116 COMMIT;
33117 END LOOP;
33118
33119
33120
33121 EXCEPTION
33122 WHEN too_many_rows THEN
33123 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_DEPT_RES'||'('
33124 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
33125 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
33126 ROLLBACK ;
33127
33128 WHEN ex_logging_err THEN
33129 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
33130 ROLLBACK;
33131
33132 WHEN OTHERS THEN
33133 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_DEPT_RES'||'('
33134 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
33135 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
33136 ROLLBACK;
33137
33138 END LOAD_DEPT_RES;
33139
33140 --bug 8310366 Validation of all columns for the RESOURCE_SETUP entity (SDS Changes)
33141
33142 PROCEDURE LOAD_RESOURCE_SETUPS IS
33143 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
33144 TYPE SetupCode IS TABLE OF MSC_ST_RESOURCE_SETUPS.SETUP_CODE%TYPE INDEX BY BINARY_INTEGER;
33145 TYPE OrganizationCode is TABLE OF MSC_ST_RESOURCE_SETUPS.ORGANIZATION_CODE%TYPE INDEX BY BINARY_INTEGER;
33146 TYPE CompanyName is TABLE OF MSC_ST_RESOURCE_SETUPS.COMPANY_NAME%TYPE INDEX BY BINARY_INTEGER;
33147 TYPE CurTyp IS REF CURSOR;
33148 c1 CurTyp;
33149 lb_rowid RowidTab; --bulk collects rowid
33150 stpCode SetupCode; --bulk collects setupcode
33151 orgCode OrganizationCode; -- bulk collects organization code
33152 compName CompanyName; -- bulk collects company name
33153 lv_return NUMBER;
33154 lv_error_text VARCHAR2(250);
33155 lv_cursor_stmt VARCHAR2(5000);
33156 lv_batch_id msc_st_resource_setups.batch_id%TYPE;
33157 lv_sql_stmt VARCHAR2(5000);
33158 lv_message_text msc_errors.error_text%TYPE;
33159 lv_column_names VARCHAR2(5000); --stores concatenated column names
33160 CURSOR c2(p_batch_id NUMBER) IS
33161 SELECT rowid
33162 FROM msc_st_resource_setups
33163 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG) --Check the where clause conditions. Look for any additions or deletions
33164 AND sr_instance_code = v_instance_code
33165 AND batch_id = p_batch_id;
33166
33167 CURSOR c3(p_batch_id NUMBER) IS
33168 SELECT max(rowid),setup_code,organization_code,company_name
33169 FROM msc_st_resource_setups
33170 WHERE process_flag = G_IN_PROCESS
33171 AND sr_instance_code = v_instance_code
33172 AND batch_id = p_batch_id
33173 AND NVL(setup_id,NULL_VALUE) = NULL_VALUE
33174 AND deleted_flag = SYS_NO
33175 group by sr_instance_code,organization_code,company_name,setup_code;
33176
33177 ex_logging_err EXCEPTION;
33178
33179 --query--
33180 BEGIN
33181 LOOP
33182
33183 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
33184 (p_app_short_name => 'MSC',
33185 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
33186 p_message_text => lv_message_text,
33187 p_error_text => lv_error_text);
33188
33189 IF lv_return <> 0 THEN
33190 RAISE ex_logging_err;
33191 END IF;
33192
33193 lv_sql_stmt :=
33194 'UPDATE msc_st_resource_setups msrs1 '
33195 ||'SET process_flag ='|| G_ERROR_FLG||','
33196 ||' error_text = '||''''||lv_message_text||''''
33197 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_resource_setups msrs2'
33198 ||' WHERE msrs2.sr_instance_code = msrs1.sr_instance_code'
33199 ||' AND NVL(msrs2.company_name,'||''''||NULL_CHAR||''''||') '
33200 ||' = NVL(msrs1.company_name,'||''''||NULL_CHAR||''''||') '
33201 ||' AND msrs2.organization_code = msrs1.organization_code'
33202 ||' AND msrs2.resource_code = msrs1.resource_code'
33203 ||' AND msrs2.setup_code = msrs1.setup_code'
33204 ||' AND msrs2.process_flag = '||G_IN_PROCESS
33205 ||' AND NVL(msrs2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
33206 ||' GROUP BY sr_instance_code,company_name,organization_code,'
33207 ||' resource_code,setup_code'
33208 ||' HAVING COUNT(*) >1 )'
33209 ||' AND msrs1.process_flag ='|| G_IN_PROCESS
33210 ||' AND msrs1.sr_instance_code = :v_instance_code'
33211 ||' AND NVL(msrs1.message_id,'||NULL_VALUE||')= '||NULL_VALUE;
33212
33213
33214 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
33215
33216 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
33217
33218 v_sql_stmt := 01;
33219 lv_cursor_stmt :=
33220 ' SELECT msc_st_batch_id_s.NEXTVAL '
33221 ||' FROM dual';
33222
33223 OPEN c1 FOR lv_cursor_stmt;
33224 FETCH c1 INTO lv_batch_id;
33225 CLOSE c1;
33226
33227 v_sql_stmt := 02;
33228 lv_sql_stmt :=
33229 ' UPDATE msc_st_resource_setups '
33230 ||' SET batch_id = :lv_batch_id'
33231 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
33232 ||' AND sr_instance_code = :v_instance_code'
33233 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
33234 ||' AND rownum <= '||v_batch_size;
33235
33236
33237 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
33238
33239 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
33240
33241 EXIT WHEN SQL%NOTFOUND;
33242
33243
33244 lv_column_names :=
33245 'SR_INSTANCE_CODE ||''~''||'
33246 ||'RESOURCE_CODE';
33247
33248
33249 OPEN c2(lv_batch_id);
33250 FETCH c2 BULK COLLECT INTO lb_rowid;
33251 CLOSE c2;
33252 v_sql_stmt := 03;
33253 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
33254 UPDATE msc_st_resource_setups
33255 SET st_transaction_id = msc_st_regions_s.NEXTVAL,
33256 refresh_id = v_refresh_id,
33257 last_update_date = v_current_date,
33258 last_updated_by = v_current_user,
33259 creation_date = v_current_date,
33260 created_by = v_current_user
33261 WHERE rowid = lb_rowid(j);
33262
33263
33264 -- Populate the setup_id
33265
33266 v_sql_stmt:= 04;
33267
33268 lv_sql_stmt :=
33269 'UPDATE msc_st_resource_setups msrs'
33270 ||' SET setup_id= (SELECT local_id'
33271 ||' FROM msc_local_id_setup mlis'
33272 ||' WHERE mlis.char1 = msrs.sr_instance_code'
33273 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||')'
33274 || '=NVL(msrs.company_name,'||''''||NULL_CHAR||''''||') '
33275 ||' AND mlis.char3 = msrs.organization_code'
33276 ||' AND mlis.char4 = msrs.setup_code'
33277 ||' AND mlis.entity_name = ''SETUP_ID'')'
33278 ||' WHERE msrs.sr_instance_code = :v_instance_code'
33279 ||' AND msrs.process_flag ='|| G_IN_PROCESS
33280 ||' AND msrs.batch_id = :lv_batch_id';
33281
33282 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
33283
33284 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
33285
33286 -- Set the message for invalid Organization_code
33287
33288 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
33289 (p_app_short_name => 'MSC',
33290 p_error_code => 'MSC_PP_INVALID_VALUE',
33291 p_message_text => lv_message_text,
33292 p_error_text => lv_error_text,
33293 p_token1 => 'COLUMN_NAME',
33294 p_token_value1 => 'ORGANIZATION_CODE');
33295
33296 IF lv_return <> 0 THEN
33297 RAISE ex_logging_err;
33298 END IF;
33299
33300 -- Populate organization id
33301
33302 v_sql_stmt:= 05;
33303
33304 lv_return :=
33305 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name =>'MSC_ST_RESOURCE_SETUPS',
33306 p_org_partner_name =>'ORGANIZATION_CODE',
33307 p_org_partner_id =>'ORGANIZATION_ID',
33308 p_instance_code => v_instance_code,
33309 p_partner_type => G_ORGANIZATION,
33310 p_severity => G_SEV_ERROR,
33311 p_message_text => lv_message_text,
33312 p_batch_id =>lv_batch_id,
33313 p_debug => v_debug,
33314 p_error_text =>lv_error_text);
33315
33316 if(lv_return <> 0) then
33317 RAISE ex_logging_err;
33318 end if;
33319
33320 -- Derive resource id
33321
33322 v_sql_stmt:= 06;
33323
33324 lv_sql_stmt :=
33325 'UPDATE msc_st_resource_setups msrs'
33326 ||' SET resource_id= (SELECT local_id'
33327 ||' FROM msc_local_id_setup mlis'
33328 ||' WHERE mlis.char1 = msrs.sr_instance_code'
33329 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||')'
33330 || '=NVL(msrs.company_name,'||''''||NULL_CHAR||''''||') '
33331 ||' AND mlis.char3 = msrs.organization_code'
33332 ||' AND mlis.char4 = msrs.resource_code'
33333 ||' AND mlis.entity_name = ''RESOURCE_ID'')'
33334 ||' WHERE msrs.sr_instance_code = :v_instance_code'
33335 ||' AND msrs.process_flag ='|| G_IN_PROCESS
33336 ||' AND msrs.batch_id = :lv_batch_id';
33337
33338
33339 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
33340
33341 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
33342
33343 -- Set the message for invalid resource_code
33344
33345 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
33346 (p_app_short_name => 'MSC',
33347 p_error_code => 'MSC_PP_INVALID_VALUE',
33348 p_message_text => lv_message_text,
33349 p_error_text => lv_error_text,
33350 p_token1 => 'COLUMN_NAME',
33351 p_token_value1 => 'RESOURCE_CODE');
33352
33353 IF lv_return <> 0 THEN
33354 RAISE ex_logging_err;
33355 END IF;
33356
33357
33358 lv_sql_stmt :=
33359 ' UPDATE msc_st_resource_setups '
33360 ||' SET process_flag ='||G_ERROR_FLG||','
33361 ||' error_text = '||''''||lv_message_text||''''
33362 ||' WHERE NVL(resource_id,'||NULL_VALUE||') ='|| NULL_VALUE
33363 ||' AND deleted_flag = '||SYS_NO
33364 ||' AND process_flag = '||G_IN_PROCESS
33365 ||' AND sr_instance_code = :v_instance_code'
33366 ||' AND batch_id = :lv_batch_id';
33367
33368
33369
33370 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
33371
33372 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
33373
33374
33375 v_sql_stmt := 07;
33376
33377 OPEN c3(lv_batch_id);
33378 FETCH c3 BULK COLLECT INTO lb_rowid,stpCode,orgCode,compName ;
33379
33380 IF c3%ROWCOUNT > 0 THEN
33381
33382 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
33383 UPDATE msc_st_resource_setups
33384 SET setup_id = msc_st_resource_setups_s.NEXTVAL
33385 WHERE rowid = lb_rowid(j);
33386
33387 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
33388 UPDATE msc_st_resource_setups
33389 SET setup_id =(select setup_id from msc_st_resource_setups where rowid = lb_rowid(j))
33390 WHERE setup_code=stpCode(j)
33391 AND organization_code = orgCode(j)
33392 AND company_name = compName(j)
33393 AND process_flag = G_IN_PROCESS
33394 AND sr_instance_code = v_instance_code;
33395
33396 v_sql_stmt := 08;
33397
33398 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
33399 INSERT INTO msc_local_id_setup
33400 (local_id,
33401 st_transaction_id,
33402 instance_id,
33403 entity_name,
33404 data_source_type,
33405 char1,
33406 char2,
33407 char3,
33408 char4,
33409 char5,
33410 -- char6, --Setup_id remains unique across all the resource in an instance_org
33411 last_update_date,
33412 last_updated_by,
33413 creation_date,
33414 created_by )
33415 SELECT
33416 setup_id,
33417 st_transaction_id,
33418 v_instance_id,
33419 'SETUP_ID',
33420 data_source_type,
33421 sr_instance_code,
33422 company_name,
33423 organization_code,
33424 setup_code,
33425 setup_description,
33426 -- resource_code,
33427 v_current_date,
33428 v_current_user,
33429 v_current_date,
33430 v_current_user
33431 FROM msc_st_resource_setups
33432 WHERE rowid= lb_rowid(j) ;
33433
33434 END IF;
33435 CLOSE c3;
33436
33437 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
33438 (p_table_name => 'MSC_ST_RESOURCE_SETUPS',
33439 p_instance_id => v_instance_id,
33440 p_instance_code => v_instance_code,
33441 p_process_flag => G_VALID,
33442 p_error_text => lv_error_text,
33443 p_debug => v_debug,
33444 p_batch_id => lv_batch_id);
33445
33446 IF lv_return <> 0 THEN
33447 RAISE ex_logging_err;
33448 END IF;
33449
33450 -- Inserting all the errored out records into MSC_ERRORS
33451
33452 lv_return := MSC_ST_UTIL.LOG_ERROR
33453 (p_table_name => 'MSC_ST_RESOURCE_SETUPS',
33454 p_instance_code => v_instance_code,
33455 p_row => lv_column_names,
33456 p_severity => G_SEV_ERROR,
33457 p_error_text => lv_error_text,
33458 p_message_text => NULL,
33459 p_batch_id => lv_batch_id);
33460
33461
33462 IF lv_return <> 0 THEN
33463 RAISE ex_logging_err;
33464 END IF;
33465
33466 COMMIT;
33467 END LOOP;
33468 EXCEPTION
33469 WHEN too_many_rows THEN
33470 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_RESOURCE_SETUPS'||'('
33471 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
33472 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
33473 ROLLBACK ;
33474
33475 WHEN ex_logging_err THEN
33476 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
33477 ROLLBACK;
33478
33479 WHEN OTHERS THEN
33480 lv_error_text :=substr('MSC_CL_PRE_PROCESS.LOAD_RESOURCE_SETUPS'||'('
33481 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
33482 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
33483 ROLLBACK;
33484
33485 END LOAD_RESOURCE_SETUPS;
33486
33487
33488 PROCEDURE LOAD_SETUP_TRANSITIONS IS
33489 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
33490 TYPE CurTyp IS REF CURSOR;
33491 c1 CurTyp;
33492 lv_return NUMBER;
33493 lv_message_text msc_errors.error_text%TYPE;
33494 lv_error_text VARCHAR2(250);
33495 lv_sql_stmt VARCHAR2(5000);
33496 lv_cursor_stmt VARCHAR2(5000);
33497 lv_batch_id msc_st_setup_transitions.batch_id%TYPE;
33498 lv_column_names VARCHAR2(5000); --stores concatenated column names
33499 CURSOR c2(p_batch_id NUMBER) IS
33500 SELECT rowid
33501 FROM msc_st_setup_transitions
33502 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
33503 AND sr_instance_code = v_instance_code
33504 AND batch_id = p_batch_id;
33505
33506 ex_logging_err EXCEPTION;
33507
33508 --query--
33509 BEGIN
33510 LOOP
33511 v_sql_stmt := 01;
33512 lv_cursor_stmt :=
33513 ' SELECT msc_st_batch_id_s.NEXTVAL '
33514 ||' FROM dual';
33515
33516 OPEN c1 FOR lv_cursor_stmt;
33517 FETCH c1 INTO lv_batch_id;
33518 CLOSE c1;
33519
33520 v_sql_stmt := 02;
33521 lv_sql_stmt :=
33522 ' UPDATE msc_st_setup_transitions '
33523 ||' SET batch_id = :lv_batch_id'
33524 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
33525 ||' AND sr_instance_code = :v_instance_code'
33526 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
33527 ||' AND rownum <= '||v_batch_size;
33528
33529
33530 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
33531
33532 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
33533
33534 EXIT WHEN SQL%NOTFOUND;
33535
33536
33537 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
33538 (p_app_short_name => 'MSC',
33539 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
33540 p_message_text => lv_message_text,
33541 p_error_text => lv_error_text);
33542
33543 IF lv_return <> 0 THEN
33544 RAISE ex_logging_err;
33545 END IF;
33546 lv_sql_stmt :=
33547 'UPDATE msc_st_setup_transitions msst1 '
33548 ||'SET process_flag ='|| G_ERROR_FLG||','
33549 ||' error_text = '||''''||lv_message_text||''''
33550 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_setup_transitions msst2'
33551 ||' WHERE msst2.sr_instance_code = msst1.sr_instance_code'
33552 ||' AND NVL(msst2.company_name,'||''''||NULL_CHAR||''''||') '
33553 ||' = NVL(msst1.company_name,'||''''||NULL_CHAR||''''||') '
33554 ||' AND msst2.organization_code = msst1.organization_code'
33555 ||' AND msst2.resource_code = msst1.resource_code'
33556 ||' AND msst2.from_setup_code = msst1.from_setup_code'
33557 ||' AND msst2.to_setup_code = msst1.to_setup_code'
33558 ||' AND msst2.process_flag = '||G_IN_PROCESS
33559 ||' AND NVL(msst2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
33560 ||' GROUP BY sr_instance_code,company_name,organization_code,'
33561 ||' resource_code,from_setup_code,to_setup_code'
33562 ||' HAVING COUNT(*) >1 )'
33563 ||' AND msst1.process_flag ='|| G_IN_PROCESS
33564 ||' AND msst1.sr_instance_code = :v_instance_code'
33565 ||' AND NVL(msst1.message_id,'||NULL_VALUE||')= '||NULL_VALUE;
33566
33567
33568 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
33569
33570 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
33571
33572 -- Set the message for invalid Organization_code
33573
33574 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
33575 (p_app_short_name => 'MSC',
33576 p_error_code => 'MSC_PP_INVALID_VALUE',
33577 p_message_text => lv_message_text,
33578 p_error_text => lv_error_text,
33579 p_token1 => 'COLUMN_NAME',
33580 p_token_value1 => 'ORGANIZATION_CODE');
33581
33582 IF lv_return <> 0 THEN
33583 RAISE ex_logging_err;
33584 END IF;
33585
33586 -- Populate organization id
33587 lv_return :=
33588 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name =>'MSC_ST_SETUP_TRANSITIONS',
33589 p_org_partner_name =>'ORGANIZATION_CODE',
33590 p_org_partner_id =>'ORGANIZATION_ID',
33591 p_instance_code => v_instance_code,
33592 p_partner_type => G_ORGANIZATION,
33593 p_severity => G_SEV_ERROR,
33594 p_message_text => lv_message_text,
33595 p_batch_id =>lv_batch_id,
33596 p_debug => v_debug,
33597 p_error_text =>lv_error_text);
33598
33599 if(lv_return <> 0) then
33600 RAISE ex_logging_err;
33601 end if;
33602
33603
33604
33605 lv_column_names :=
33606 'SR_INSTANCE_CODE ||''~''||'
33607 ||'FROM_SETUP_CODE ||''~''||'
33608 ||'TO_SETUP_CODE';
33609
33610 -- Deriving the from_setup_id...
33611 v_sql_stmt := 03;
33612
33613 lv_sql_stmt :=
33614 'UPDATE msc_st_setup_transitions msst'
33615 ||' SET from_setup_id= (SELECT local_id'
33616 ||' FROM msc_local_id_setup mlis'
33617 ||' WHERE mlis.char1 = msst.sr_instance_code'
33618 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||')'
33619 ||' =NVL(msst.company_name,'||''''||NULL_CHAR||''''||') '
33620 ||' AND mlis.char3 = msst.organization_code'
33621 ||' AND mlis.char4 = msst.from_setup_code'
33622 ||' AND mlis.entity_name = ''SETUP_ID'')'
33623 ||' WHERE msst.sr_instance_code = :v_instance_code'
33624 ||' AND NVL(msst.from_setup_code,'||''''||NULL_CHAR||''''||')'
33625 ||' <> '||''''||NULL_CHAR||''''
33626 ||' AND msst.process_flag ='|| G_IN_PROCESS
33627 ||' AND msst.batch_id = :lv_batch_id';
33628
33629 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
33630
33631 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
33632
33633 -- Set the error message
33634 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
33635 (p_app_short_name => 'MSC',
33636 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
33637 p_message_text => lv_message_text,
33638 p_error_text => lv_error_text,
33639 p_token1 => 'COLUMN_NAMES',
33640 p_token_value1 => 'FROM_SETUP_CODE',
33641 p_token2 => 'MASTER_TABLE',
33642 p_token_value2 => 'MSC_ST_RESOURCE_SETUPS',
33643 p_token3 => 'CHILD_TABLE' ,
33644 p_token_value3 => 'MSC_ST_RESOURCE_SETUPS' );
33645
33646 IF lv_return <> 0 THEN
33647 RAISE ex_logging_err;
33648 END IF;
33649 v_sql_stmt := 04;
33650
33651 lv_sql_stmt :=
33652 ' UPDATE msc_st_setup_transitions '
33653 ||' SET process_flag ='||G_ERROR_FLG||','
33654 ||' error_text = '||''''||lv_message_text||''''
33655 ||' WHERE NVL(from_setup_id,'||NULL_VALUE||') ='|| NULL_VALUE
33656 ||' AND deleted_flag = '||SYS_NO
33657 ||' AND process_flag = '||G_IN_PROCESS
33658 ||' AND sr_instance_code = :v_instance_code'
33659 ||' AND batch_id = :lv_batch_id';
33660
33661
33662
33663 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
33664
33665 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
33666
33667
33668 -- Deriving the to_setup_id...
33669 v_sql_stmt := 05;
33670 lv_sql_stmt :=
33671 'UPDATE msc_st_setup_transitions msst'
33672 ||' SET to_setup_id= (SELECT local_id'
33673 ||' FROM msc_local_id_setup mlis'
33674 ||' WHERE mlis.char1 = msst.sr_instance_code'
33675 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||')'
33676 ||' =NVL(msst.company_name,'||''''||NULL_CHAR||''''||') '
33677 ||' AND mlis.char3 = msst.organization_code'
33678 ||' AND mlis.char4 = msst.to_setup_code'
33679 ||' AND mlis.entity_name = ''SETUP_ID'')'
33680 ||' WHERE msst.sr_instance_code = :v_instance_code'
33681 ||' AND NVL(msst.to_setup_code,'||''''||NULL_CHAR||''''||')'
33682 ||' <> '||''''||NULL_CHAR||''''
33683 ||' AND msst.process_flag ='|| G_IN_PROCESS
33684 ||' AND msst.batch_id = :lv_batch_id';
33685
33686
33687 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
33688
33689 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
33690
33691 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
33692 (p_app_short_name => 'MSC',
33693 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
33694 p_message_text => lv_message_text,
33695 p_error_text => lv_error_text,
33696 p_token1 => 'COLUMN_NAMES',
33697 p_token_value1 => 'TO_SETUP_CODE',
33698 p_token2 => 'MASTER_TABLE',
33699 p_token_value2 => 'MSC_ST_RESOURCE_SETUPS',
33700 p_token3 => 'CHILD_TABLE' ,
33701 p_token_value3 => 'MSC_ST_RESOURCE_SETUPS' );
33702
33703
33704 IF lv_return <> 0 THEN
33705 RAISE ex_logging_err;
33706 END IF;
33707 v_sql_stmt := 06;
33708
33709 lv_sql_stmt :=
33710 ' UPDATE msc_st_setup_transitions '
33711 ||' SET process_flag ='||G_ERROR_FLG||','
33712 ||' error_text = '||''''||lv_message_text||''''
33713 ||' WHERE NVL(to_setup_id,'||NULL_VALUE||') ='|| NULL_VALUE
33714 ||' AND deleted_flag = '||SYS_NO
33715 ||' AND process_flag = '||G_IN_PROCESS
33716 ||' AND sr_instance_code = :v_instance_code'
33717 ||' AND batch_id = :lv_batch_id';
33718
33719
33720 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
33721 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
33722
33723 -- Populating standard_operation_id
33724
33725 v_sql_stmt:= 07;
33726
33727 lv_sql_stmt :=
33728 'UPDATE msc_st_setup_transitions msst'
33729 ||' SET standard_operation_id= (SELECT local_id'
33730 ||' FROM msc_local_id_setup mlis'
33731 ||' WHERE mlis.char1 = msst.sr_instance_code'
33732 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||')'
33733 || '=NVL(msst.company_name,'||''''||NULL_CHAR||''''||') '
33734 ||' AND mlis.char3 = msst.organization_code'
33735 ||' AND mlis.char4 = msst.standard_operation_code'
33736 ||' AND mlis.entity_name = ''STANDARD_OPERATION_ID'')'
33737 ||' WHERE msst.sr_instance_code = :v_instance_code'
33738 ||' AND msst.process_flag ='|| G_IN_PROCESS
33739 ||' AND msst.batch_id = :lv_batch_id';
33740
33741 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
33742
33743 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
33744
33745 --- Deriving DeptID...
33746 /*
33747 v_sql_stmt := 08;
33748 lv_sql_stmt :=
33749 'UPDATE MSC_ST_SETUP_TRANSITIONS msrc'
33750 ||' SET department_id = (SELECT local_id'
33751 ||' FROM msc_local_id_setup mlis'
33752 ||' WHERE mlis.char1 = msrc.sr_instance_code'
33753 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
33754 ||' = NVL(msrc.company_name,'||''''||NULL_CHAR||''''||') '
33755 ||' AND mlis.char3 = msrc.organization_code'
33756 ||' AND mlis.char4 = msrc.department_code'
33757 ||' AND mlis.entity_name = ''DEPARTMENT_ID'' '
33758 ||' AND mlis.instance_id = '||v_instance_id||')'
33759 ||' WHERE sr_instance_code = :v_instance_code'
33760 ||' AND process_flag = '|| G_IN_PROCESS
33761 ||' AND batch_id = :lv_batch_id';
33762
33763
33764 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
33765
33766 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code, lv_batch_id;
33767
33768 -- Set the error message
33769 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
33770
33771 (p_app_short_name => 'MSC',
33772 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
33773 p_message_text => lv_message_text,
33774 p_error_text => lv_error_text,
33775 p_token1 => 'COLUMN_NAMES',
33776 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
33777 ||'ORGANIZATION_CODE,DEPARTMENT_CODE',
33778 p_token2 => 'MASTER_TABLE',
33779 p_token_value2 => 'MSC_ST_DEPARTMENT_RESOURCES',
33780 p_token3 => 'CHILD_TABLE' ,
33781 p_token_value3 => 'MSC_ST_SETUP_TRANSITIONS' );
33782
33783 IF lv_return <> 0 THEN
33784 RAISE ex_logging_err;
33785 END IF;
33786
33787 -- Error out the records where department id is NULL
33788
33789 v_sql_stmt := 09;
33790 lv_sql_stmt:=
33791 'UPDATE MSC_ST_SETUP_TRANSITIONS '
33792 ||' SET process_flag = '||G_ERROR_FLG||','
33793 ||' error_text = '||''''||lv_message_text||''''
33794 ||' WHERE NVL(department_id,'||NULL_VALUE||') = '||NULL_VALUE
33795 ||' AND sr_instance_code = :v_instance_code'
33796 ||' AND process_flag ='|| G_IN_PROCESS
33797 ||' AND batch_id = :lv_batch_id';
33798
33799
33800 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
33801
33802 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id ;
33803 */
33804 -- Now derive the resource_id
33805 v_sql_stmt := 10;
33806 lv_sql_stmt :=
33807 'UPDATE msc_st_setup_transitions msst'
33808 ||' SET resource_id= (SELECT local_id'
33809 ||' FROM msc_local_id_setup mlis'
33810 ||' WHERE mlis.char1 = msst.sr_instance_code'
33811 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||')'
33812 ||' =NVL(msst.company_name,'||''''||NULL_CHAR||''''||') '
33813 ||' AND mlis.char3 = msst.organization_code'
33814 ||' AND mlis.char4 = msst.resource_code'
33815 ||' AND mlis.entity_name = ''RESOURCE_ID'')'
33816 ||' WHERE msst.sr_instance_code = :v_instance_code'
33817 ||' AND NVL(msst.resource_code,'||''''||NULL_CHAR||''''||')'
33818 ||' <> '||''''||NULL_CHAR||''''
33819 ||' AND msst.process_flag ='|| G_IN_PROCESS
33820 ||' AND msst.batch_id = :lv_batch_id';
33821
33822 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
33823
33824 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
33825
33826 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
33827 (p_app_short_name => 'MSC',
33828 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
33829 p_message_text => lv_message_text,
33830 p_error_text => lv_error_text,
33831 p_token1 => 'COLUMN_NAMES',
33832 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
33833 ||'ORGANIZATION_CODE,OWNING_DEPARTMENT_CODE',
33834 p_token2 => 'MASTER_TABLE',
33835 p_token_value2 => 'MSC_ST_DEPARTMENT_RESOURCES',
33836 p_token3 => 'CHILD_TABLE' ,
33837 p_token_value3 => 'MSC_ST_DEPARTMENT_RESOURCES' );
33838
33839 IF lv_return <> 0 THEN
33840 RAISE ex_logging_err;
33841 END IF;
33842 v_sql_stmt := 11;
33843
33844 lv_sql_stmt :=
33845 ' UPDATE msc_st_setup_transitions '
33846 ||' SET process_flag ='||G_ERROR_FLG||','
33847 ||' error_text = '||''''||lv_message_text||''''
33848 ||' WHERE NVL(resource_id,'||NULL_VALUE||') ='|| NULL_VALUE
33849 ||' AND deleted_flag = '||SYS_NO
33850 ||' AND process_flag = '||G_IN_PROCESS
33851 ||' AND sr_instance_code = :v_instance_code'
33852 ||' AND batch_id = :lv_batch_id';
33853
33854 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
33855
33856 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
33857
33858
33859
33860 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
33861 (p_table_name => 'MSC_ST_SETUP_TRANSITIONS',
33862 p_instance_id => v_instance_id,
33863 p_instance_code => v_instance_code,
33864 p_process_flag => G_VALID,
33865 p_error_text => lv_error_text,
33866 p_debug => v_debug,
33867 p_batch_id => lv_batch_id);
33868
33869 IF lv_return <> 0 THEN
33870 RAISE ex_logging_err;
33871 END IF;
33872
33873 -- Inserting all the errored out records into MSC_ERRORS
33874
33875 lv_return := MSC_ST_UTIL.LOG_ERROR
33876 (p_table_name => 'MSC_ST_SETUP_TRANSITIONS',
33877 p_instance_code => v_instance_code,
33878 p_row => lv_column_names,
33879 p_severity => G_SEV_ERROR,
33880 p_error_text => lv_error_text,
33881 p_message_text => NULL,
33882 p_batch_id => lv_batch_id);
33883
33884
33885 IF lv_return <> 0 THEN
33886 RAISE ex_logging_err;
33887 END IF;
33888
33889 COMMIT;
33890 END LOOP;
33891 EXCEPTION
33892 WHEN too_many_rows THEN
33893 lv_error_text :=
33894 substr('MSC_CL_PRE_PROCESS.LOAD_SETUP_TRANSITIONS'||'('
33895 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
33896 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
33897 ROLLBACK ;
33898
33899 WHEN ex_logging_err THEN
33900 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
33901 ROLLBACK;
33902
33903 WHEN OTHERS THEN
33904 lv_error_text :=substr('MSC_CL_PRE_PROCESS.LOAD_SETUP_TRANSITIONS'||'('
33905 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
33906 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
33907 ROLLBACK;
33908
33909 END LOAD_SETUP_TRANSITIONS;
33910
33911
33912
33913
33914
33915 /*==========================================================================+
33916 | DESCRIPTION : This procedure is called for validating supplies related |
33917 | records from the msc_st_supplies table. The following |
33918 | types are considered for the validation. |
33919 | Supply Source Order Type |
33920 | -------------------------------------------- |
33921 | Purchase Order 1 |
33922 | Requisition 2 |
33923 | Plan Orders 5 |
33924 | PO Receiving 8 |
33925 | Intransit Shipment 11 |
33926 | Intransit Receipt 12 |
33927 | On-Hand Quantities 18 |
33928 +==========================================================================*/
33929 PROCEDURE LOAD_SUPPLY(p_batch_id IN NUMBER DEFAULT NULL_VALUE) IS
33930 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
33931 lb_rowid RowidTab;
33932 lv_return NUMBER;
33933 lv_return2 NUMBER;
33934 lv_planning_tp_type Number;
33935 lv_owning_tp_type Number;
33936 lv_error_text VARCHAR2(250);
33937 lv_where_str VARCHAR2(5000);
33938 lv_sql_stmt VARCHAR2(5000);
33939 lv_column_names VARCHAR2(5000); --stores concatenated column names
33940 lv_message_text msc_errors.error_text%TYPE;
33941 ex_logging_err EXCEPTION;
33942 busy EXCEPTION;
33943 PRAGMA EXCEPTION_INIT(busy, -54);
33944
33945 CURSOR c1(p_batch_id NUMBER) IS
33946 SELECT rowid
33947 FROM msc_st_supplies
33948 WHERE order_type IN(1,2,5,8,11,12,18,73,74,87,81)
33949 AND process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
33950 AND NVL(batch_id,NULL_VALUE)=p_batch_id
33951 AND sr_instance_code = v_instance_code;
33952
33953 CURSOR c2(p_batch_id NUMBER) IS
33954 SELECT rowid
33955 FROM msc_st_supplies
33956 WHERE NVL(sr_mtl_supply_id,NULL_VALUE) = NULL_VALUE
33957 AND order_type IN(1,2,8,11,12,73,74,87)
33958 AND process_flag = G_IN_PROCESS
33959 AND NVL(batch_id,NULL_VALUE) =p_batch_id
33960 AND sr_instance_code = v_instance_code;
33961
33962 CURSOR c3(p_batch_id NUMBER) IS
33963 SELECT max(rowid)
33964 FROM msc_st_supplies
33965 WHERE NVL(disposition_id,NULL_VALUE) = NULL_VALUE
33966 AND order_type IN(1,2,8,11,12,73,74,87)
33967 AND deleted_flag = SYS_NO
33968 AND process_flag = G_IN_PROCESS
33969 AND NVL(batch_id,NULL_VALUE) =p_batch_id
33970 AND sr_instance_code = v_instance_code
33971 GROUP BY sr_instance_code,company_name,order_number,order_type;
33972
33973 CURSOR c4(p_batch_id NUMBER) IS
33974 SELECT rowid
33975 FROM msc_st_supplies
33976 WHERE NVL(po_line_id,NULL_VALUE) = NULL_VALUE
33977 AND deleted_flag = SYS_NO
33978 AND order_type IN(1,2,8,11,12,73,74,87)
33979 AND process_flag = G_IN_PROCESS
33980 AND NVL(batch_id,NULL_VALUE) =p_batch_id
33981 AND sr_instance_code = v_instance_code;
33982
33983 CURSOR c5(p_batch_id NUMBER) IS
33984 SELECT rowid
33985 FROM msc_st_supplies
33986 WHERE NVL(disposition_id,NULL_VALUE) = NULL_VALUE
33987 AND order_type IN (5,81)
33988 AND process_flag = G_IN_PROCESS
33989 AND NVL(batch_id,NULL_VALUE) =p_batch_id
33990 AND sr_instance_code = v_instance_code;
33991
33992 CURSOR c6(p_batch_id NUMBER) IS
33993 SELECT rowid
33994 FROM msc_st_supplies
33995 WHERE order_type = 18
33996 AND process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
33997 AND NVL(batch_id,NULL_VALUE)=p_batch_id
33998 AND sr_instance_code = v_instance_code;
33999
34000 CURSOR c_lock(p_batch_id NUMBER) IS
34001 SELECT 'X'
34002 FROM msc_st_supplies ms1 ,
34003 msc_st_supplies ms2
34004 WHERE ms1.batch_id = p_batch_id
34005 AND ms1.batch_id <> nvl(ms2.batch_id,NULL_VALUE)
34006 AND ms1.disposition_id IS NULL
34007 AND ms2.disposition_id IS NULL
34008 AND ms1.sr_instance_code = ms2.sr_instance_code
34009 AND NVL(ms1.company_name,NULL_CHAR)= NVL(ms2.company_name,NULL_CHAR)
34010 AND ms1.order_number = ms2.order_number
34011 AND ms1.order_type = ms2.order_type
34012 AND ms1.order_type IN(1,2,8,11,12,73,74,87)
34013 FOR UPDATE NOWAIT ;
34014
34015
34016
34017 BEGIN
34018
34019 lv_column_names :=
34020 'ITEM_NAME ||''~''||'
34021 ||'ORGANIZATION_CODE ||''~''||'
34022 ||'NEW_SCHEDULE_DATE ||''~''||'
34023 ||'NEW_ORDER_QUANTITY ||''~''||'
34024 ||'FIRM_PLANNED_TYPE ||''~''||'
34025 ||'SUPPLIER_NAME ||''~''||'
34026 ||'PURCH_LINE_NUM ||''~''||'
34027 ||'ORDER_NUMBER ||''~''||'
34028 ||'SUPPLIER_SITE_CODE ||''~''||'
34029 ||'SR_INSTANCE_CODE ||''~''||'
34030 ||'REVISION ||''~''||'
34031 ||'UNIT_NUMBER ||''~''||'
34032 ||'NEW_DOCK_DATE ||''~''||'
34033 ||'PROJECT_NUMBER ||''~''||'
34034 ||'TASK_NUMBER ||''~''||'
34035 ||'PLANNING_GROUP ||''~''||'
34036 ||'DELIVERY_PRICE ||''~''||'
34037 ||'QTY_SCRAPPED ||''~''||'
34038 ||'FROM_ORGANIZATION_CODE ||''~''||'
34039 ||'DELETED_FLAG ||''~''||'
34040 ||'ORDER_TYPE ||''~''||'
34041 ||'SUBINVENTORY_CODE ||''~''||'
34042 ||'LOT_NUMBER ||''~''||'
34043 ||'EXPIRATION_DATE ||''~''||'
34044 ||'SCHEDULE_LINE_NUM ||''~''||'
34045 ||'LAST_UNIT_START_DATE ||''~''||'
34046 ||'SCHEDULE_DESIGNATOR ||''~''||'
34047 ||'COMPANY_NAME ||''~''||'
34048 ||'DAILY_RATE';
34049
34050 LOOP
34051 BEGIN
34052 v_sql_stmt := 01;
34053 OPEN c_lock(p_batch_id) ;
34054 EXIT;
34055 EXCEPTION
34056 WHEN busy THEN
34057 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_SUPPLY'||'(' ||v_sql_stmt||')'|| SQLERRM, 1, 240);
34058 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
34059 dbms_lock.sleep(5);
34060 WHEN OTHERS THEN
34061 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_SUPPLY'||'(' ||v_sql_stmt||')'|| SQLERRM, 1, 240);
34062 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
34063 v_sql_stmt := 2.0;
34064 lv_sql_stmt :=
34065 'UPDATE msc_st_supplies '
34066 ||' SET process_flag = 1, '
34067 ||' batch_id = NULL'
34068 ||' WHERE batch_id = :p_batch_id'
34069 ||' AND order_type IN(1,2,8,11,12,73,74,87)'
34070 ||' AND process_flag = '||G_IN_PROCESS
34071 ||' AND sr_instance_code =:v_instance_code';
34072
34073
34074 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
34075
34076 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
34077 COMMIT;
34078 RETURN;
34079 END ;
34080 END LOOP ;
34081
34082 v_sql_stmt := 2.1;
34083 lv_sql_stmt :=
34084 'UPDATE msc_st_supplies mss '
34085 ||' SET disposition_id = (SELECT local_id'
34086 ||' FROM msc_local_id_supply mls'
34087 ||' WHERE mls.char3 = mss.order_number'
34088 ||' AND mls.number1 = mss.order_type'
34089 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
34090 ||' NVL(mss.company_name,'||''''||NULL_CHAR||''''||') '
34091 ||' AND mls.char1 = mss.sr_instance_code'
34092 ||' AND mls.entity_name = ''DISPOSITION_ID'' ) '
34093 ||' WHERE order_type IN(1,2,8,11,12,73,74,87)'
34094 ||' AND NVL(disposition_id,'||NULL_VALUE||') = '||NULL_VALUE
34095 ||' AND deleted_flag = '||SYS_NO
34096 ||' AND process_flag = '||G_IN_PROCESS
34097 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
34098 ||' AND sr_instance_code = :v_instance_code';
34099
34100
34101 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
34102
34103 EXECUTE IMMEDIATE lv_sql_stmt
34104 USING p_batch_id,
34105 v_instance_code;
34106
34107
34108 --Generation of disposition_id(PO, PO Req. and Intransit)
34109 OPEN c3(p_batch_id);
34110 FETCH c3 BULK COLLECT INTO lb_rowid ;
34111
34112 IF c3%ROWCOUNT > 0 THEN
34113 v_sql_stmt := 3.0;
34114
34115
34116 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
34117 UPDATE msc_st_supplies
34118 SET disposition_id = msc_st_disposition_id_s.NEXTVAL
34119 WHERE rowid = lb_rowid(j);
34120
34121 v_sql_stmt := 3.1;
34122 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
34123 INSERT INTO msc_local_id_supply
34124 (local_id,
34125 st_transaction_id,
34126 instance_id,
34127 entity_name,
34128 data_source_type,
34129 char1,
34130 char2,
34131 char3,
34132 number1,
34133 SOURCE_DISPOSITION_ID,
34134 last_update_date,
34135 last_updated_by,
34136 creation_date,
34137 created_by)
34138 SELECT
34139 disposition_id,
34140 st_transaction_id,
34141 v_instance_id,
34142 'DISPOSITION_ID',
34143 data_source_type,
34144 v_instance_code,
34145 company_name,
34146 order_number,
34147 order_type,
34148 SOURCE_DISPOSITION_ID,
34149 v_current_date,
34150 v_current_user,
34151 v_current_date,
34152 v_current_user
34153 FROM msc_st_supplies
34154 WHERE rowid = lb_rowid(j);
34155 END IF;
34156 CLOSE c3 ;
34157
34158 v_sql_stmt := 4.0;
34159 lv_sql_stmt :=
34160 'UPDATE msc_st_supplies mss '
34161 ||' SET disposition_id = (SELECT local_id'
34162 ||' FROM msc_local_id_supply mls'
34163 ||' WHERE mls.char3 = mss.order_number'
34164 ||' AND mls.number1 = mss.order_type'
34165 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
34166 ||' NVL(mss.company_name,'||''''||NULL_CHAR||''''||') '
34167 ||' AND mls.char1 = mss.sr_instance_code'
34168 ||' AND mls.entity_name = ''DISPOSITION_ID'' ) '
34169 ||' WHERE order_type IN(1,2,8,11,12,73,74,87)'
34170 ||' AND NVL(disposition_id,'||NULL_VALUE||') = '||NULL_VALUE
34171 ||' AND deleted_flag = '||SYS_NO
34172 ||' AND process_flag = '||G_IN_PROCESS
34173 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
34174 ||' AND sr_instance_code = :v_instance_code';
34175
34176
34177 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
34178
34179 EXECUTE IMMEDIATE lv_sql_stmt
34180 USING p_batch_id,
34181 v_instance_code;
34182
34183
34184 COMMIT ;
34185 IF c_lock%ISOPEN THEN
34186 CLOSE c_lock;
34187 END IF;
34188
34189
34190 OPEN c1(p_batch_id);
34191 FETCH c1 BULK COLLECT INTO lb_rowid;
34192 IF c1%ROWCOUNT > 0 THEN
34193
34194 v_sql_stmt := 5.0;
34195 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
34196 UPDATE msc_st_supplies
34197 SET st_transaction_id = msc_st_supplies_s.NEXTVAL,
34198 refresh_id = v_refresh_id,
34199 last_update_date = v_current_date,
34200 last_updated_by = v_current_user,
34201 creation_date = v_current_date,
34202 created_by = v_current_user
34203 WHERE rowid = lb_rowid(j);
34204
34205 END IF;
34206 CLOSE c1;
34207
34208 lv_where_str :=
34209 ' AND NVL(deleted_flag,'||NULL_VALUE||') '
34210 ||' NOT IN(1,2)';
34211
34212 --Log a warning for those records where the deleted_flag has a value other
34213 --SYS_NO
34214 lv_return := MSC_ST_UTIL.LOG_ERROR
34215 (p_table_name => 'MSC_ST_SUPPLIES',
34216 p_instance_code => v_instance_code,
34217 p_row => lv_column_names,
34218 p_severity => G_SEV_WARNING,
34219 p_message_text => lv_message_text,
34220 p_error_text => lv_error_text,
34221 p_batch_id => p_batch_id,
34222 p_where_str => lv_where_str,
34223 p_col_name => 'DELETED_FLAG',
34224 p_debug => v_debug,
34225 p_default_value => SYS_NO);
34226
34227 IF lv_return <> 0 THEN
34228 RAISE ex_logging_err;
34229 END IF;
34230
34231 --bug 2773881 (ssurendr) validation on need_by_date/promised_date -- changes begin
34232
34233 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
34234 (p_app_short_name => 'MSC',
34235 p_error_code => 'MSC_PP_COL_VAL_NULL',
34236 p_message_text => lv_message_text,
34237 p_error_text => lv_error_text,
34238 p_token1 => 'COLUMN_NAME',
34239 p_token_value1 => 'NEED_BY_DATE OR '
34240 ||' PROMISED_DATE');
34241
34242 IF lv_return <> 0 THEN
34243 RAISE ex_logging_err;
34244 END IF;
34245
34246 v_sql_stmt := 5.1;
34247 lv_sql_stmt :=
34248 'UPDATE msc_st_supplies '
34249 ||' SET error_text = ''' || lv_message_text || ''','
34250 ||' process_flag = '||G_ERROR_FLG
34251 ||' WHERE NEED_BY_DATE is null '
34252 ||' AND PROMISED_DATE is null '
34253 ||' AND order_type in (1,74) '
34254 ||' AND process_flag = '||G_IN_PROCESS
34255 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
34256 ||' AND sr_instance_code = :v_instance_code';
34257
34258
34259 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
34260
34261 EXECUTE IMMEDIATE lv_sql_stmt
34262 USING p_batch_id,
34263 v_instance_code;
34264
34265 --bug 2773881 (ssurendr) validation on need_by_date/promised_date -- changes end
34266
34267 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
34268 (p_app_short_name => 'MSC',
34269 p_error_code => 'MSC_PP_INVALID_VALUE',
34270 p_message_text => lv_message_text,
34271 p_error_text => lv_error_text,
34272 p_token1 => 'COLUMN_NAME',
34273 p_token_value1 => 'ORGANIZATION_CODE');
34274
34275 IF lv_return <> 0 THEN
34276 RAISE ex_logging_err;
34277 END IF;
34278
34279 --Derive Organization_id
34280 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
34281 (p_table_name => 'MSC_ST_SUPPLIES',
34282 p_org_partner_name => 'ORGANIZATION_CODE',
34283 p_org_partner_id => 'ORGANIZATION_ID',
34284 p_instance_code => v_instance_code,
34285 p_partner_type => G_ORGANIZATION,
34286 p_error_text => lv_error_text,
34287 p_batch_id => p_batch_id,
34288 p_severity => G_SEV_ERROR,
34289 p_message_text => lv_message_text,
34290 p_debug => v_debug,
34291 p_row => lv_column_names);
34292
34293 IF lv_return <> 0 THEN
34294 RAISE ex_logging_err;
34295 END IF;
34296
34297 -------- populate condition type
34298
34299
34300 OPEN c6(p_batch_id);
34301 FETCH c6 BULK COLLECT INTO lb_rowid;
34302 IF c6%ROWCOUNT > 0 THEN
34303
34304 v_sql_stmt := 2.2;
34305 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
34306 UPDATE msc_st_supplies mss
34307 SET mss.condition_type = (SELECT nvl(msi.condition_type,'G' )
34308 FROM msc_sub_inventories msi
34309 WHERE msi.organization_id = mss.organization_id
34310 AND msi.plan_id = -1
34311 AND msi.sub_inventory_code = mss.subinventory_code
34312 AND msi.sr_instance_id = v_instance_id
34313 AND mss.sr_instance_code = v_instance_code
34314 UNION
34315 SELECT nvl(mssi.condition_type ,'G' ) from msc_st_sub_inventories mssi
34316 WHERE mssi.organization_code = mss.organization_code
34317 AND mssi.sub_inventory_code = mss.subinventory_code
34318 AND mssi.sr_instance_code = mss.sr_instance_code)
34319 WHERE rowid = lb_rowid(j);
34320
34321 msc_util.initialize_common_globals (v_instance_id);
34322
34323 v_sql_stmt := 2.3;
34324 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
34325 UPDATE msc_st_supplies mss
34326 SET mss.ITEM_TYPE_ID = MSC_UTIL.G_PARTCONDN_ITEMTYPEID,
34327 mss.ITEM_TYPE_VALUE =DECODE(mss.condition_type,'G',MSC_UTIL.G_PARTCONDN_GOOD,'B',MSC_UTIL.G_PARTCONDN_BAD,MSC_UTIL.G_PARTCONDN_GOOD)
34328 WHERE rowid = lb_rowid(j);
34329
34330 END IF;
34331 CLOSE c6;
34332
34333 IF v_instance_type = G_INS_OTHER THEN
34334
34335 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
34336 (p_app_short_name => 'MSC',
34337 p_error_code => 'MSC_PP_INVALID_VALUE',
34338 p_message_text => lv_message_text,
34339 p_error_text => lv_error_text,
34340 p_token1 => 'COLUMN_NAME',
34341 p_token_value1 => 'PLANNING_PARTNER_SITE_CODE');
34342
34343 IF lv_return <> 0 THEN
34344 RAISE ex_logging_err;
34345 END IF;
34346
34347 UPDATE MSC_ST_SUPPLIES
34348 SET PLANNING_PARTNER_SITE_ID = (SELECT local_id
34349 FROM msc_local_id_setup
34350 WHERE char1 = sr_instance_code
34351 AND NVL(char2,NULL_CHAR) = NVL(company_name,NULL_CHAR)
34352 AND char4 = PLANNING_PARTNER_SITE_CODE
34353 AND number1 = G_VENDOR
34354 AND entity_name = 'SR_TP_SITE_ID' )
34355 WHERE sr_instance_code = v_instance_code
34356 AND NVL(PLANNING_PARTNER_SITE_ID,NULL_VALUE) = NULL_VALUE
34357 AND NVL(batch_id,NULL_VALUE)= p_batch_id
34358 AND process_flag = G_IN_PROCESS
34359 AND PLANNING_TP_TYPE = 1
34360 AND ORDER_TYPE = 18;
34361
34362
34363
34364 UPDATE MSC_ST_SUPPLIES
34365 SET PLANNING_PARTNER_SITE_ID = (SELECT local_id
34366 FROM msc_local_id_setup
34367 WHERE char1 = sr_instance_code
34368 AND char3 = PLANNING_PARTNER_SITE_CODE
34369 AND number1 = G_ORGANIZATION
34370 AND entity_name = 'SR_TP_ID' )
34371 WHERE sr_instance_code = v_instance_code
34372 AND NVL(PLANNING_PARTNER_SITE_ID,NULL_VALUE) = NULL_VALUE
34373 AND NVL(batch_id,NULL_VALUE)= p_batch_id
34374 AND process_flag = G_IN_PROCESS
34375 AND PLANNING_TP_TYPE = 2
34376 AND ORDER_TYPE =18;
34377
34378 UPDATE MSC_ST_SUPPLIES mss1
34379 SET process_flag = G_ERROR_FLG,
34380 error_text = lv_message_text
34381 WHERE EXISTS( SELECT 1
34382 FROM MSC_ST_SUPPLIES mss2
34383 WHERE mss2.sr_instance_code = mss1.sr_instance_code
34384 AND mss2.process_flag = G_IN_PROCESS
34385 AND NVL(mss2.planning_partner_site_id,NULL_VALUE) = NULL_VALUE
34386 GROUP BY sr_instance_code HAVING COUNT(*) > 0)
34387 AND mss1.process_flag = G_IN_PROCESS
34388 AND mss1.sr_instance_code = v_instance_code
34389 AND NVL(batch_id,NULL_VALUE) = p_batch_id -- bug 8547376
34390 AND NVL(mss1.planning_partner_site_id,NULL_VALUE) = NULL_VALUE
34391 AND ORDER_TYPE=18;
34392
34393 UPDATE MSC_ST_SUPPLIES
34394 SET OWNING_PARTNER_SITE_ID = (SELECT local_id
34395 FROM msc_local_id_setup
34396 WHERE char1 = sr_instance_code
34397 AND NVL(char2,NULL_CHAR) = NVL(company_name,NULL_CHAR)
34398 AND char4 = OWNING_PARTNER_SITE_CODE
34399 AND number1 = G_VENDOR
34400 AND entity_name = 'SR_TP_SITE_ID' )
34401 WHERE sr_instance_code = v_instance_code
34402 AND NVL(OWNING_PARTNER_SITE_ID,NULL_VALUE) = NULL_VALUE
34403 AND NVL(batch_id,NULL_VALUE)= p_batch_id
34404 AND process_flag = G_IN_PROCESS
34405 AND OWNING_TP_TYPE = 1
34406 AND ORDER_TYPE=18;
34407
34408 UPDATE MSC_ST_SUPPLIES
34409 SET OWNING_PARTNER_SITE_ID = (SELECT local_id
34410 FROM msc_local_id_setup
34411 WHERE char1 = sr_instance_code
34412 AND char3 = OWNING_PARTNER_SITE_CODE
34413 AND number1 = G_ORGANIZATION
34414 AND entity_name = 'SR_TP_ID')
34415 WHERE sr_instance_code = v_instance_code
34416 AND NVL(OWNING_PARTNER_SITE_ID,NULL_VALUE) = NULL_VALUE
34417 AND NVL(batch_id,NULL_VALUE)= p_batch_id
34418 AND process_flag = G_IN_PROCESS
34419 AND OWNING_TP_TYPE = 2
34420 AND ORDER_TYPE=18;
34421
34422 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
34423 (p_app_short_name => 'MSC',
34424 p_error_code => 'MSC_PP_INVALID_VALUE',
34425 p_message_text => lv_message_text,
34426 p_error_text => lv_error_text,
34427 p_token1 => 'COLUMN_NAME',
34428 p_token_value1 => 'OWNING_PARTNER_SITE_CODE');
34429
34430 IF lv_return <> 0 THEN
34431 RAISE ex_logging_err;
34432 END IF;
34433
34434 UPDATE MSC_ST_SUPPLIES mss1
34435 SET process_flag = G_ERROR_FLG,
34436 error_text = lv_message_text
34437 WHERE EXISTS( SELECT 1
34438 FROM MSC_ST_SUPPLIES mss2
34439 WHERE mss2.sr_instance_code = mss1.sr_instance_code
34440 AND mss2.process_flag = G_IN_PROCESS
34441 AND NVL(mss2.owning_partner_site_id,NULL_VALUE) = NULL_VALUE
34442 GROUP BY sr_instance_code HAVING COUNT(*) > 0)
34443 AND mss1.process_flag = G_IN_PROCESS
34444 AND mss1.sr_instance_code = v_instance_code
34445 AND NVL(batch_id,NULL_VALUE) = p_batch_id -- bug 8547376
34446 AND NVL(mss1.owning_partner_site_id,NULL_VALUE) = NULL_VALUE
34447 AND ORDER_TYPE =18 ;
34448
34449 -----------------start of changes for flatfile load into ERP instance-----------------------
34450
34451 ELSE
34452
34453 UPDATE MSC_ST_SUPPLIES t1
34454 SET PLANNING_PARTNER_SITE_ID =
34455 (SELECT mtps.sr_tp_site_id
34456 FROM msc_trading_partner_sites mtps
34457 WHERE mtps.partner_type = G_VENDOR
34458 AND mtps.sr_instance_id = v_instance_id
34459 AND mtps.tp_site_code = PLANNING_PARTNER_SITE_CODE
34460 AND rownum =1)
34461 WHERE sr_instance_code = v_instance_code
34462 AND NVL(PLANNING_PARTNER_SITE_ID,NULL_VALUE) = NULL_VALUE
34463 AND NVL(batch_id,NULL_VALUE)= p_batch_id
34464 AND process_flag = G_IN_PROCESS
34465 AND PLANNING_TP_TYPE = 1
34466 AND order_type=18;
34467
34468 UPDATE MSC_ST_SUPPLIES t1
34469 SET PLANNING_PARTNER_SITE_ID =
34470 (SELECT sr_tp_id
34471 FROM msc_trading_partners mtp
34472 WHERE mtp.partner_type = G_ORGANIZATION
34473 AND mtp.organization_code = v_instance_code||':'||t1.PLANNING_PARTNER_SITE_CODE
34474 AND mtp.sr_instance_id =v_instance_id)
34475 WHERE t1.sr_instance_code = v_instance_code
34476 AND NVL(t1.PLANNING_PARTNER_SITE_ID,NULL_VALUE) = NULL_VALUE
34477 AND NVL(t1.batch_id,NULL_VALUE)= p_batch_id
34478 AND t1.process_flag = G_IN_PROCESS
34479 AND t1.PLANNING_TP_TYPE = 2
34480 AND t1.order_type=18;
34481
34482
34483 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
34484 (p_app_short_name => 'MSC',
34485 p_error_code => 'MSC_PP_INVALID_VALUE',
34486 p_message_text => lv_message_text,
34487 p_error_text => lv_error_text,
34488 p_token1 => 'COLUMN_NAME',
34489 p_token_value1 => 'PLANNING_PARTNER_SITE_CODE');
34490
34491 IF lv_return <> 0 THEN
34492 RAISE ex_logging_err;
34493 END IF;
34494
34495 UPDATE MSC_ST_SUPPLIES mss1
34496 SET process_flag = G_ERROR_FLG,
34497 error_text = lv_message_text
34498 WHERE mss1.process_flag = G_IN_PROCESS
34499 AND mss1.sr_instance_code = v_instance_code
34500 AND NVL(batch_id,NULL_VALUE) = p_batch_id -- bug 8547376
34501 AND NVL(mss1.planning_partner_site_id,NULL_VALUE) = NULL_VALUE
34502 AND order_type=18 ;
34503
34504 UPDATE MSC_ST_SUPPLIES t1
34505 SET OWNING_PARTNER_SITE_ID =
34506 (SELECT mtps.sr_tp_site_id
34507 FROM msc_trading_partner_sites mtps
34508 WHERE mtps.partner_type = G_VENDOR
34509 AND mtps.sr_instance_id = v_instance_id
34510 AND mtps.tp_site_code = OWNING_PARTNER_SITE_CODE
34511 AND rownum =1)
34512 WHERE sr_instance_code = v_instance_code
34513 AND NVL(OWNING_PARTNER_SITE_ID,NULL_VALUE) = NULL_VALUE
34514 AND NVL(batch_id,NULL_VALUE)= p_batch_id
34515 AND process_flag = G_IN_PROCESS
34516 AND OWNING_TP_TYPE = 1
34517 AND order_type=18;
34518
34519 UPDATE MSC_ST_SUPPLIES t1
34520 SET OWNING_PARTNER_SITE_ID =
34521 (SELECT sr_tp_id
34522 FROM msc_trading_partners mtp
34523 WHERE mtp.partner_type = G_ORGANIZATION
34524 AND mtp.organization_code = v_instance_code||':'||t1.OWNING_PARTNER_SITE_CODE
34525 AND mtp.sr_instance_id =v_instance_id)
34526 WHERE t1.sr_instance_code = v_instance_code
34527 AND NVL(t1.OWNING_PARTNER_SITE_ID,NULL_VALUE) = NULL_VALUE
34528 AND NVL(t1.batch_id,NULL_VALUE)= p_batch_id
34529 AND t1.process_flag = G_IN_PROCESS
34530 AND t1.OWNING_TP_TYPE = 2
34531 AND t1.order_type=18;
34532
34533 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
34534 (p_app_short_name => 'MSC',
34535 p_error_code => 'MSC_PP_INVALID_VALUE',
34536 p_message_text => lv_message_text,
34537 p_error_text => lv_error_text,
34538 p_token1 => 'COLUMN_NAME',
34539 p_token_value1 => 'OWNING_PARTNER_SITE_CODE');
34540
34541 IF lv_return <> 0 THEN
34542 RAISE ex_logging_err;
34543 END IF;
34544
34545 UPDATE MSC_ST_SUPPLIES mss1
34546 SET process_flag = G_ERROR_FLG,
34547 error_text = lv_message_text
34548 WHERE mss1.process_flag = G_IN_PROCESS
34549 AND mss1.sr_instance_code = v_instance_code
34550 AND NVL(batch_id,NULL_VALUE) = p_batch_id -- bug 8547376
34551 AND NVL(mss1.owning_partner_site_id,NULL_VALUE) = NULL_VALUE
34552 AND order_type=18; --7704629
34553
34554 END IF;
34555
34556 -----------------end of changes for flatfile load into ERP instance-----------
34557
34558 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
34559 (p_app_short_name => 'MSC',
34560 p_error_code => 'MSC_PP_INVALID_VALUE',
34561 p_message_text => lv_message_text,
34562 p_error_text => lv_error_text,
34563 p_token1 => 'COLUMN_NAME',
34564 p_token_value1 => 'ITEM_NAME');
34565
34566 IF lv_return <> 0 THEN
34567 RAISE ex_logging_err;
34568 END IF;
34569
34570 --Derive Inventory_item_id
34571 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
34572 (p_table_name => 'MSC_ST_SUPPLIES',
34573 p_item_col_name => 'ITEM_NAME',
34574 p_item_col_id => 'INVENTORY_ITEM_ID',
34575 p_instance_id => v_instance_id,
34576 p_instance_code => v_instance_code,
34577 p_error_text => lv_error_text,
34578 p_batch_id => p_batch_id,
34579 p_severity => G_SEV_ERROR,
34580 p_message_text => lv_message_text,
34581 p_debug => v_debug,
34582 p_row => lv_column_names);
34583
34584 IF lv_return <> 0 THEN
34585 RAISE ex_logging_err;
34586 END IF;
34587
34588 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
34589 (p_app_short_name => 'MSC',
34590 p_error_code => 'MSC_PP_INVALID_VALUE',
34591 p_message_text => lv_message_text,
34592 p_error_text => lv_error_text,
34593 p_token1 => 'COLUMN_NAME',
34594 p_token_value1 => 'SUPPLIER_NAME');
34595
34596 IF lv_return <> 0 THEN
34597 RAISE ex_logging_err;
34598 END IF;
34599
34600 --Derive Supplier_id
34601 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
34602 (p_table_name => 'MSC_ST_SUPPLIES',
34603 p_org_partner_name => 'SUPPLIER_NAME',
34604 p_org_partner_id => 'SUPPLIER_ID',
34605 p_instance_code => v_instance_code,
34606 p_partner_type => G_VENDOR,
34607 p_error_text => lv_error_text,
34608 p_batch_id => p_batch_id,
34609 p_severity => G_SEV3_ERROR,
34610 p_message_text => lv_message_text,
34611 p_debug => v_debug,
34612 p_row => lv_column_names);
34613
34614 IF lv_return <> 0 THEN
34615 RAISE ex_logging_err;
34616 END IF;
34617
34618
34619 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
34620 (p_app_short_name => 'MSC',
34621 p_error_code => 'MSC_PP_INVALID_VALUE',
34622 p_message_text => lv_message_text,
34623 p_error_text => lv_error_text,
34624 p_token1 => 'COLUMN_NAME',
34625 p_token_value1 => 'SUPPLIER_SITE_CODE');
34626
34627 IF lv_return <> 0 THEN
34628 RAISE ex_logging_err;
34629 END IF;
34630
34631 --Derive Supplier_site_id
34632 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
34633 (p_table_name => 'MSC_ST_SUPPLIES',
34634 p_partner_name => 'SUPPLIER_NAME',
34635 p_partner_site_code => 'SUPPLIER_SITE_CODE',
34636 p_partner_site_id => 'SUPPLIER_SITE_ID',
34637 p_instance_code => v_instance_code,
34638 p_partner_type => G_VENDOR,
34639 p_error_text => lv_error_text,
34640 p_batch_id => p_batch_id,
34641 p_severity => G_SEV3_ERROR,
34642 p_message_text => lv_message_text,
34643 p_debug => v_debug,
34644 p_row => lv_column_names);
34645
34646 IF lv_return <> 0 THEN
34647 RAISE ex_logging_err;
34648 END IF;
34649
34650 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
34651 (p_app_short_name => 'MSC',
34652 p_error_code => 'MSC_PP_COL_VAL_NULL',
34653 p_message_text => lv_message_text,
34654 p_error_text => lv_error_text,
34655 p_token1 => 'COLUMN_NAME',
34656 p_token_value1 => 'ORDER_NUMBER OR '
34657 ||' PURCH_LINE_NUM OR '
34658 ||' SCHEDULE_DESIGNATOR OR '
34659 ||' SCHEDULE_LINE_NUM OR '
34660 ||' NEW_SCHEDULE_DATE OR '
34661 ||' NEW_ORDER_QUANTITY');
34662
34663 IF lv_return <> 0 THEN
34664 RAISE ex_logging_err;
34665 END IF;
34666
34667 v_sql_stmt := 10;
34668 lv_sql_stmt :=
34669 'UPDATE msc_st_supplies '
34670 ||' SET error_text = '||''''||lv_message_text||''''||','
34671 ||' process_flag = '||G_ERROR_FLG
34672 ||' WHERE (((NVL(order_number, '||''''||NULL_CHAR||''''||') '
34673 ||' = '||''''||NULL_CHAR||''''
34674 ||' OR NVL(purch_line_num, '||NULL_VALUE|| ') = '||NULL_VALUE||')'
34675 ||' AND order_type IN(1,2,8,11,12,73,74,87))'
34676 ||' OR ((NVL(schedule_designator, '||''''||NULL_CHAR||''''||') '
34677 ||' = '||''''||NULL_CHAR||''''
34678 ||' OR NVL(schedule_line_num , '||''''||NULL_CHAR||''''||') '
34679 ||' = '||''''||NULL_CHAR||''''||')'
34680 ||' AND ORDER_TYPE = 5)'
34681 --bug 2773881 (ssurendr) new_schedule_date will not be provided for PO,ONHAND (bug 2903052)
34682 ||' OR ((NVL(new_schedule_date,SYSDATE-36500 ) = SYSDATE-36500'
34683 ||' AND ORDER_TYPE NOT IN (1,18,74))'
34684 ||' OR NVL(new_order_quantity,'||NULL_VALUE||') = '||NULL_VALUE||')'
34685 ||' AND deleted_flag = '||SYS_NO||')'
34686 ||' AND process_flag = '||G_IN_PROCESS
34687 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
34688 ||' AND sr_instance_code = :v_instance_code';
34689
34690
34691 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
34692
34693 EXECUTE IMMEDIATE lv_sql_stmt
34694 USING p_batch_id,
34695 v_instance_code;
34696
34697
34698 -- bug 2903356
34699
34700 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
34701 (p_app_short_name => 'MSC',
34702 p_error_code => 'MSC_DOCK_INVALID_VAL',
34703 p_message_text => lv_message_text,
34704 p_error_text => lv_error_text,
34705 p_token1 => 'COLUMN_NAME1',
34706 p_token_value1 => 'NEW_SCHEDULE_DATE',
34707 p_token2 => 'COLUMN_NAME2',
34708 p_token_value2 => 'NEW_DOCK_DATE');
34709
34710 IF lv_return <> 0 THEN
34711 RAISE ex_logging_err;
34712 END IF;
34713
34714 --If NEW_DOCK_DATE is greater than NEW_SCHEDULE_DATE we will raise an error
34715 -- start
34716 lv_where_str :=
34717 ' AND NVL(new_dock_date,SYSDATE-36500) > NVL(new_schedule_date,SYSDATE-36500)'
34718 ||' AND deleted_flag ='||SYS_NO
34719 ||' AND order_type IN(2,11,12,73,87)'
34720 ||' AND process_flag = '||G_IN_PROCESS;
34721
34722 lv_return := MSC_ST_UTIL.LOG_ERROR
34723 (p_table_name => 'MSC_ST_SUPPLIES',
34724 p_instance_code => v_instance_code,
34725 p_row => lv_column_names,
34726 p_severity => G_SEV_WARNING,
34727 p_message_text => lv_message_text,
34728 p_error_text => lv_error_text,
34729 p_batch_id => p_batch_id,
34730 p_where_str => lv_where_str);
34731
34732 IF lv_return <> 0 THEN
34733 RAISE ex_logging_err;
34734 END IF;
34735
34736 -- end
34737
34738 /*
34739 lv_sql_stmt :=
34740 'UPDATE msc_st_supplies '
34741 ||' SET process_flag = '||G_ERROR_FLG||','
34742 ||' error_text = '||''''||lv_message_text||''''
34743 ||' WHERE NVL(new_dock_date,SYSDATE-36500) > NVL(new_schedule_date,SYSDATE-36500)'
34744 ||' AND deleted_flag ='||SYS_NO
34745 ||' AND order_type IN(2,11,12,73,87)'
34746 ||' AND process_flag = '||G_IN_PROCESS
34747 ||' AND NVL(batch_id,'||NULL_VALUE||')= :p_batch_id '
34748 ||' AND sr_instance_code =:v_instance_code';
34749
34750
34751 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
34752
34753 EXECUTE IMMEDIATE lv_sql_stmt
34754 USING p_batch_id,
34755 v_instance_code;
34756 */
34757
34758 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
34759 (p_app_short_name => 'MSC',
34760 p_error_code => 'MSC_PP_POS_NON_ZERO',
34761 p_message_text => lv_message_text,
34762 p_error_text => lv_error_text,
34763 p_token1 => 'COLUMN_NAME',
34764 p_token_value1 => 'NEW_ORDER_QUANTITY');
34765
34766 IF lv_return <> 0 THEN
34767 RAISE ex_logging_err;
34768 END IF;
34769
34770 --Negative quantities are allowed only for the order type On-Hand(18)
34771 v_sql_stmt := 11;
34772 lv_sql_stmt :=
34773 'UPDATE msc_st_supplies'
34774 ||' SET process_flag = '||G_ERROR_FLG||','
34775 ||' error_text = '||''''||lv_message_text||''''
34776 ||' WHERE new_order_quantity <= 0'
34777 ||' AND order_type <> 18'
34778 ||' AND process_flag = '||G_IN_PROCESS
34779 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
34780 ||' AND sr_instance_code = :v_instance_code';
34781
34782
34783 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
34784
34785 EXECUTE IMMEDIATE lv_sql_stmt
34786 USING p_batch_id,
34787 v_instance_code;
34788
34789
34790 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
34791 (p_app_short_name => 'MSC',
34792 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
34793 p_message_text => lv_message_text,
34794 p_error_text => lv_error_text,
34795 p_token1 => 'COLUMN_NAMES',
34796 p_token_value1 => 'SR_INSTANCE_CODE,'
34797 ||' COMPANY_NAME,'
34798 ||' ORGANIZATION_CODE,'
34799 ||' DESIGNATOR_TYPE AND'
34800 ||' DESIGNATOR',
34801 p_token2 => 'MASTER_TABLE',
34802 p_token_value2 => 'MSC_ST_DESIGNATORS',
34803 p_token3 => 'CHILD_TABLE',
34804 p_token_value3 => 'MSC_ST_SUPPLIES');
34805
34806 IF lv_return <> 0 THEN
34807 RAISE ex_logging_err;
34808 END IF;
34809
34810 v_sql_stmt := 12;
34811 lv_sql_stmt :=
34812 'UPDATE msc_st_supplies mss'
34813 ||' SET process_flag = '||G_ERROR_FLG||','
34814 ||' error_text = '||''''||lv_message_text||''''
34815 ||' WHERE NOT EXISTS(SELECT 1'
34816 ||' FROM msc_st_designators msd'
34817 ||' WHERE msd.designator = mss.schedule_designator'
34818 ||' AND msd.organization_code = mss.organization_code'
34819 ||' AND NVL(msd.company_name,'||''''||NULL_CHAR||''''||') = '
34820 ||' NVL(mss.company_name,'||''''||NULL_CHAR||''''||') '
34821 ||' AND msd.sr_instance_code = mss.sr_instance_code'
34822 ||' AND msd.process_flag = '||G_VALID
34823 ||' AND msd.designator_type = 2'
34824 ||' AND NVL(msd.disable_date, SYSDATE+1) > SYSDATE'
34825 ||' UNION'
34826 ||' SELECT 1'
34827 ||' FROM msc_designators md'
34828 ||' WHERE md.designator = mss.schedule_designator'
34829 ||' AND md.organization_id = mss.organization_id '
34830 ||' AND md.sr_instance_id = :v_instance_id '
34831 ||' AND md.designator_type = 2'
34832 ||' AND NVL(md.disable_date, SYSDATE+1) > SYSDATE)'
34833 ||' AND order_type = 5'
34834 ||' AND deleted_flag = '||SYS_NO
34835 ||' AND process_flag = '||G_IN_PROCESS
34836 ||' AND NVL(batch_id,'||NULL_VALUE||')= :p_batch_id'
34837 ||' AND sr_instance_code = :v_instance_code';
34838
34839
34840 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
34841
34842 EXECUTE IMMEDIATE lv_sql_stmt
34843 USING v_instance_id,
34844 p_batch_id,
34845 v_instance_code;
34846
34847 -- 13839374 validating designators for returns forecast
34848 v_sql_stmt := 14;
34849 lv_sql_stmt :=
34850 'UPDATE msc_st_supplies mss'
34851 ||' SET process_flag = '||G_ERROR_FLG||','
34852 ||' error_text = '||''''||lv_message_text||''''
34853 ||' WHERE NOT EXISTS(SELECT 1'
34854 ||' FROM msc_st_designators msd'
34855 ||' WHERE msd.designator = mss.schedule_designator'
34856 ||' AND msd.organization_code = mss.organization_code'
34857 ||' AND NVL(msd.company_name,'||''''||NULL_CHAR||''''||') = '
34858 ||' NVL(mss.company_name,'||''''||NULL_CHAR||''''||') '
34859 ||' AND msd.sr_instance_code = mss.sr_instance_code'
34860 ||' AND msd.process_flag = '||G_VALID
34861 ||' AND msd.designator_type = 6'
34862 ||' AND NVL(msd.disable_date, SYSDATE+1) > SYSDATE'
34863 ||' UNION'
34864 ||' SELECT 1'
34865 ||' FROM msc_designators md'
34866 ||' WHERE md.designator = mss.schedule_designator'
34867 ||' AND md.organization_id = mss.organization_id '
34868 ||' AND md.sr_instance_id = :v_instance_id '
34869 ||' AND md.designator_type = 6'
34870 ||' AND NVL(md.disable_date, SYSDATE+1) > SYSDATE)'
34871 ||' AND order_type = 81'
34872 ||' AND deleted_flag = '||SYS_NO
34873 ||' AND process_flag = '||G_IN_PROCESS
34874 ||' AND NVL(batch_id,'||NULL_VALUE||')= :p_batch_id'
34875 ||' AND sr_instance_code = :v_instance_code';
34876
34877
34878 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
34879
34880 EXECUTE IMMEDIATE lv_sql_stmt
34881 USING v_instance_id,
34882 p_batch_id,
34883 v_instance_code;
34884
34885
34886
34887 --Ship_to_party_name and ship_to_site_code validation is specific to
34888 --Supply chain exchange and the validation will be done only for PO's
34889
34890 IF v_instance_type = G_SCE THEN
34891
34892 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
34893 (p_app_short_name => 'MSC',
34894 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
34895 p_message_text => lv_message_text,
34896 p_error_text => lv_error_text,
34897 p_token1 => 'COLUMN_NAMES',
34898 p_token_value1 => 'SHIP_TO_PARTY_NAME',
34899 p_token2 => 'MASTER_TABLE',
34900 p_token_value2 => 'MSC_ST_DESIGNATORS',
34901 p_token3 => 'CHILD_TABLE',
34902 p_token_value3 => 'MSC_ST_SUPPLIES');
34903
34904 IF lv_return <> 0 THEN
34905 RAISE ex_logging_err;
34906 END IF;
34907
34908 v_sql_stmt := 13;
34909 lv_sql_stmt :=
34910 'UPDATE msc_st_supplies '
34911 ||' SET process_flag = '||G_ERROR_FLG||','
34912 ||' error_text = '||''''||lv_message_text||''''
34913 ||' WHERE NOT EXISTS (SELECT 1'
34914 ||' FROM hz_parties '
34915 ||' WHERE party_name = ship_to_party_name) '
34916 ||' AND order_type in (1,74)'
34917 ||' AND process_flag = '||G_IN_PROCESS
34918 ||' AND NVL(batch_id,'||NULL_VALUE||')= :p_batch_id'
34919 ||' AND sr_instance_code = :v_instance_code';
34920
34921
34922
34923 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
34924
34925 EXECUTE IMMEDIATE lv_sql_stmt
34926 USING p_batch_id,
34927 v_instance_code;
34928
34929
34930 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
34931 (p_app_short_name => 'MSC',
34932 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
34933 p_message_text => lv_message_text,
34934 p_error_text => lv_error_text,
34935 p_token1 => 'COLUMN_NAMES',
34936 p_token_value1 => 'SHIP_TO_PARTY_NAME AND'
34937 ||' SHIP_TO_SITE_CODE',
34938 p_token2 => 'MASTER_TABLE',
34939 p_token_value2 => 'MSC_ST_DESIGNATORS',
34940 p_token3 => 'CHILD_TABLE',
34941 p_token_value3 => 'MSC_ST_SUPPLIES');
34942
34943 IF lv_return <> 0 THEN
34944 RAISE ex_logging_err;
34945 END IF;
34946
34947 v_sql_stmt := 14;
34948 lv_sql_stmt :=
34949 'UPDATE msc_st_supplies ms'
34950 ||' SET process_flag = '||G_ERROR_FLG||','
34951 ||' error_text = '||''''||lv_message_text||''''
34952 ||' WHERE NOT EXISTS (SELECT 1'
34953 ||' FROM hz_parties hp,hz_party_sites hps'
34954 ||' WHERE hp.party_name = ms.ship_to_party_name '
34955 ||' AND hp.party_id = hps.party_id '
34956 ||' AND hps.party_site_name = ms.ship_to_site_code )'
34957 ||' AND order_type in (1,74)'
34958 ||' AND process_flag = '||G_IN_PROCESS
34959 ||' AND NVL(batch_id,'||NULL_VALUE||')= :p_batch_id'
34960 ||' AND sr_instance_code = :v_instance_code';
34961
34962
34963
34964 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
34965
34966 EXECUTE IMMEDIATE lv_sql_stmt
34967 USING p_batch_id,
34968 v_instance_code;
34969
34970 END IF;
34971
34972 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
34973 (p_app_short_name => 'MSC',
34974 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
34975 p_message_text => lv_message_text,
34976 p_error_text => lv_error_text,
34977 p_token1 => 'COLUMN_NAME',
34978 p_token_value1 => 'FIRM_PLANNED_TYPE',
34979 p_token2 => 'DEFAULT_VALUE',
34980 p_token_value2 => SYS_NO);
34981
34982 IF lv_return <> 0 THEN
34983 RAISE ex_logging_err;
34984 END IF;
34985
34986 lv_where_str := ' AND NVL(firm_planned_type, '||NULL_VALUE||') NOT IN(1,2)'
34987 ||' AND deleted_flag = '||SYS_NO;
34988
34989 --Log a warning for those records where the firm_planned_type has a value other
34990 --NOT IN (1,2)
34991 lv_return := MSC_ST_UTIL.LOG_ERROR
34992 (p_table_name => 'MSC_ST_SUPPLIES',
34993 p_instance_code => v_instance_code,
34994 p_row => lv_column_names,
34995 p_severity => G_SEV_WARNING,
34996 p_message_text => lv_message_text,
34997 p_error_text => lv_error_text,
34998 p_batch_id => p_batch_id,
34999 p_where_str => lv_where_str,
35000 p_col_name => 'FIRM_PLANNED_TYPE',
35001 p_debug => v_debug,
35002 p_default_value => SYS_NO);
35003
35004 IF lv_return <> 0 THEN
35005 RAISE ex_logging_err;
35006 END IF;
35007
35008 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
35009 (p_app_short_name => 'MSC',
35010 p_error_code => 'MSC_PP_FK_REF_NOT_EXIST',
35011 p_message_text => lv_message_text,
35012 p_error_text => lv_error_text,
35013 p_token1 => 'COLUMN_NAMES',
35014 p_token_value1 => ' SR_INSTANCE_CODE, COMPANY_NAME,'
35015 ||' ORGANIZATION_CODE AND PROJECT_NUMBER',
35016 p_token2 => 'MASTER_TABLE',
35017 p_token_value2 => 'MSC_ST_PROJECT_TASKS');
35018
35019 IF lv_return <> 0 THEN
35020 RAISE ex_logging_err;
35021 END IF;
35022
35023 --Derive Project Id.
35024 lv_return := MSC_ST_UTIL.DERIVE_PROJ_TASK_ID
35025 (p_table_name => 'MSC_ST_SUPPLIES',
35026 p_proj_col_name => 'PROJECT_NUMBER',
35027 p_proj_task_col_id => 'PROJECT_ID',
35028 p_instance_code => v_instance_code,
35029 p_entity_name => 'PROJECT_ID',
35030 p_error_text => lv_error_text,
35031 p_batch_id => p_batch_id,
35032 p_severity => G_SEV_WARNING,
35033 p_message_text => lv_message_text,
35034 p_debug => v_debug,
35035 p_row => lv_column_names);
35036 IF lv_return <> 0 THEN
35037 RAISE ex_logging_err;
35038 END IF;
35039
35040 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
35041 (p_app_short_name => 'MSC',
35042 p_error_code => 'MSC_PP_FK_REF_NOT_EXIST',
35043 p_message_text => lv_message_text,
35044 p_error_text => lv_error_text,
35045 p_token1 => 'COLUMN_NAMES',
35046 p_token_value1 => ' SR_INSTANCE_CODE, COMPANY_NAME,'
35047 ||' ORGANIZATION_CODE, PROJECT_NUMBER,'
35048 ||' TASK_NUMBER',
35049 p_token2 => 'MASTER_TABLE',
35050 p_token_value2 => 'MSC_ST_PROJECT_TASKS');
35051
35052 IF lv_return <> 0 THEN
35053 RAISE ex_logging_err;
35054 END IF;
35055
35056 --Derive Task Id.
35057 lv_return := MSC_ST_UTIL.DERIVE_PROJ_TASK_ID
35058 (p_table_name => 'MSC_ST_SUPPLIES',
35059 p_proj_col_name => 'PROJECT_NUMBER',
35060 p_proj_task_col_id => 'TASK_ID',
35061 p_instance_code => v_instance_code,
35062 p_entity_name => 'TASK_ID',
35063 p_error_text => lv_error_text,
35064 p_task_col_name => 'TASK_NUMBER',
35065 p_batch_id => p_batch_id,
35066 p_severity => G_SEV_WARNING,
35067 p_message_text => lv_message_text,
35068 p_debug => v_debug,
35069 p_row => lv_column_names);
35070
35071 IF lv_return <> 0 THEN
35072 RAISE ex_logging_err;
35073 END IF;
35074
35075 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
35076 (p_app_short_name => 'MSC',
35077 p_error_code => 'MSC_PP_INVALID_VALUE',
35078 p_message_text => lv_message_text,
35079 p_error_text => lv_error_text,
35080 p_token1 => 'COLUMN_NAME',
35081 p_token_value1 => 'FROM_ORGANIZATION_CODE');
35082
35083 IF lv_return <> 0 THEN
35084 RAISE ex_logging_err;
35085 END IF;
35086
35087 --Derive FROM_ORGANIZATION_ID
35088 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
35089 (p_table_name => 'MSC_ST_SUPPLIES',
35090 p_org_partner_name => 'FROM_ORGANIZATION_CODE',
35091 p_org_partner_id => 'FROM_ORGANIZATION_ID',
35092 p_instance_code => v_instance_code,
35093 p_partner_type => G_ORGANIZATION,
35094 p_error_text => lv_error_text,
35095 p_batch_id => p_batch_id,
35096 p_severity => G_SEV3_ERROR,
35097 p_message_text => lv_message_text,
35098 p_debug => v_debug,
35099 p_row => lv_column_names);
35100
35101 IF lv_return <> 0 THEN
35102 RAISE ex_logging_err;
35103 END IF;
35104
35105 --Derive source_Organization_id and source_sr_instance_id,
35106 v_sql_stmt := 15;
35107 lv_sql_stmt :=
35108 'UPDATE msc_st_supplies mss'
35109 ||' SET source_organization_id = from_organization_id,'
35110 ||' source_sr_instance_id = (select instance_id'
35111 ||' FROM msc_apps_instances mai'
35112 ||' WHERE mai.instance_code = mss.source_sr_instance_code)'
35113 ||' WHERE deleted_flag ='|| SYS_NO
35114 ||' AND process_flag ='|| G_IN_PROCESS
35115 ||' AND NVL(batch_id,'||NULL_VALUE||')= :p_batch_id'
35116 ||' AND sr_instance_code = :v_instance_code';
35117
35118
35119 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
35120
35121 EXECUTE IMMEDIATE lv_sql_stmt
35122 USING p_batch_id,
35123 v_instance_code;
35124
35125 --Deriving disposition_id and po_line_id for the supply type PO, Purchase
35126 --Req. and intransit supplies
35127 v_sql_stmt := 16;
35128 lv_sql_stmt :=
35129 'UPDATE msc_st_supplies mss '
35130 ||' SET disposition_id = (SELECT local_id'
35131 ||' FROM msc_local_id_supply mls'
35132 ||' WHERE mls.char3 = mss.order_number'
35133 ||' AND mls.number1 = mss.order_type'
35134 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
35135 ||' NVL(mss.company_name,'||''''||NULL_CHAR||''''||') '
35136 ||' AND mls.char1 = mss.sr_instance_code'
35137 ||' AND mls.entity_name = ''DISPOSITION_ID'' ),'
35138 ||' po_line_id = (SELECT local_id'
35139 ||' FROM msc_local_id_supply mls'
35140 ||' WHERE mls.number1 = mss.purch_line_num'
35141 ||' AND mls.number2 = mss.order_type'
35142 ||' AND mls.char3 = mss.order_number'
35143 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
35144 ||' NVL(mss.company_name,'||''''||NULL_CHAR||''''||') '
35145 ||' AND mls.char1 = mss.sr_instance_code'
35146 ||' AND mls.entity_name = ''PO_LINE_ID'')'
35147 ||' WHERE order_type IN(1,2,8,11,12,73,74,87)'
35148 ||' AND deleted_flag = '||SYS_NO
35149 ||' AND process_flag = '||G_IN_PROCESS
35150 ||' AND NVL(batch_id,'||NULL_VALUE||')= :p_batch_id'
35151 ||' AND sr_instance_code = :v_instance_code';
35152
35153
35154 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
35155
35156 EXECUTE IMMEDIATE lv_sql_stmt
35157 USING p_batch_id,
35158 v_instance_code;
35159
35160 v_sql_stmt := 17;
35161 lv_sql_stmt :=
35162 'UPDATE msc_st_supplies mss'
35163 ||' SET sr_mtl_supply_id = (SELECT local_id'
35164 ||' FROM msc_local_id_supply mls'
35165 ||' WHERE mls.char4 = mss.order_number'
35166 ||' AND mls.number1 = mss.purch_line_num'
35167 ||' AND mls.number2 = mss.order_type'
35168 ||' AND mls.char3 = mss.organization_code'
35169 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
35170 ||' NVL(mss.company_name,'||''''||NULL_CHAR||''''||') '
35171 ||' AND mls.char1 = mss.sr_instance_code'
35172 ||' AND mls.entity_name = ''SR_MTL_SUPPLY_ID'' )'
35173 ||' WHERE order_type IN(1,2,8,11,12,73,74,87)'
35174 ||' AND process_flag = '||G_IN_PROCESS
35175 ||' AND NVL(batch_id,'||NULL_VALUE||')= :p_batch_id'
35176 ||' AND sr_instance_code = :v_instance_code';
35177
35178
35179 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
35180
35181 EXECUTE IMMEDIATE lv_sql_stmt
35182 USING p_batch_id,
35183 v_instance_code;
35184
35185 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
35186 (p_app_short_name => 'MSC',
35187 p_error_code => 'MSC_PP_DELETE_FAIL',
35188 p_message_text => lv_message_text,
35189 p_error_text => lv_error_text);
35190
35191 IF lv_return <> 0 THEN
35192 RAISE ex_logging_err;
35193 END IF;
35194
35195 --If the deleted_flag is yes and the sr_mtl_supply_id(unique key)
35196 --derivation fails for the order_types po, req and intransit, then
35197 --the record will be errored out.
35198 v_sql_stmt := 18;
35199
35200 lv_sql_stmt :=
35201 'UPDATE msc_st_supplies '
35202 ||' SET process_flag = '||G_ERROR_FLG||','
35203 ||' error_text = '||''''||lv_message_text||''''
35204 ||' WHERE NVL(sr_mtl_supply_id,'||NULL_VALUE||') = '||NULL_VALUE
35205 ||' AND deleted_flag ='||SYS_YES
35206 ||' AND order_type IN(1,2,8,11,12,73,74,87)'
35207 ||' AND process_flag = '||G_IN_PROCESS
35208 ||' AND NVL(batch_id,'||NULL_VALUE||')= :p_batch_id '
35209 ||' AND sr_instance_code =:v_instance_code';
35210
35211
35212 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
35213
35214 EXECUTE IMMEDIATE lv_sql_stmt
35215 USING p_batch_id,
35216 v_instance_code;
35217
35218 --Deriving disposition_id for the Plan Orders.
35219 v_sql_stmt := 19;
35220 lv_sql_stmt :=
35221 'UPDATE msc_st_supplies mss'
35222 ||' SET disposition_id = (SELECT local_id'
35223 ||' FROM msc_local_id_supply mls'
35224 ||' WHERE mls.char4 = mss.schedule_designator'
35225 ||' AND mls.char5 = mss.schedule_line_num'
35226 ||' AND mls.number1 = mss.order_type'
35227 ||' AND mls.char1 = mss.sr_instance_code'
35228 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
35229 ||' NVL(mss.company_name,'||''''||NULL_CHAR||''''||') '
35230 ||' AND mls.char3 = mss.organization_code'
35231 ||' AND mls.entity_name = ''DISPOSITION_ID_MPS'')'
35232 ||' WHERE order_type IN (5,81)'
35233 ||' AND process_flag = '||G_IN_PROCESS
35234 ||' AND NVL(batch_id,'||NULL_VALUE||')= :p_batch_id'
35235 ||' AND sr_instance_code = :v_instance_code';
35236
35237
35238 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
35239
35240 EXECUTE IMMEDIATE lv_sql_stmt
35241 USING p_batch_id,
35242 v_instance_code;
35243
35244
35245 /*
35246
35247 --Deriving disposition_id for the Return Forecasts
35248 v_sql_stmt := 19;
35249 lv_sql_stmt :=
35250 'UPDATE msc_st_supplies mss'
35251 ||' SET disposition_id = (SELECT local_id'
35252 ||' FROM msc_local_id_supply mls'
35253 ||' WHERE mls.char4 = mss.schedule_designator'
35254 ||' AND mls.number1 = mss.order_type'
35255 ||' AND mls.char1 = mss.sr_instance_code'
35256 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
35257 ||' NVL(mss.company_name,'||''''||NULL_CHAR||''''||') '
35258 ||' AND mls.char3 = mss.organization_code'
35259 ||' AND mls.entity_name = ''DISPOSITION_ID_MPS'')'
35260 ||' WHERE order_type IN (81)'
35261 ||' AND process_flag = '||G_IN_PROCESS
35262 ||' AND NVL(batch_id,'||NULL_VALUE||')= :p_batch_id'
35263 ||' AND sr_instance_code = :v_instance_code';
35264
35265
35266
35267 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
35268
35269 EXECUTE IMMEDIATE lv_sql_stmt
35270 USING p_batch_id,
35271 v_instance_code;
35272 */
35273 --If the deleted_flag is yes and the disposition_id(unique key)
35274 --derivation fails for the plan orders then the record will be
35275 --errored out.
35276 v_sql_stmt := 20;
35277
35278 lv_sql_stmt :=
35279 'UPDATE msc_st_supplies '
35280 ||' SET process_flag = '||G_ERROR_FLG||','
35281 ||' error_text = '||''''||lv_message_text||''''
35282 ||' WHERE NVL(disposition_id,'||NULL_VALUE||') = '||NULL_VALUE
35283 ||' AND deleted_flag ='||SYS_YES
35284 ||' AND order_type IN (5,81)'
35285 ||' AND process_flag = '||G_IN_PROCESS
35286 ||' AND NVL(batch_id,'||NULL_VALUE||')= :p_batch_id '
35287 ||' AND sr_instance_code =:v_instance_code';
35288
35289
35290 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
35291
35292 EXECUTE IMMEDIATE lv_sql_stmt
35293 USING p_batch_id,
35294 v_instance_code;
35295
35296 --Call to customised validation.
35297 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
35298 (ERRBUF => lv_error_text,
35299 RETCODE => lv_return,
35300 pBatchID => p_batch_id,
35301 pInstanceCode => v_instance_code,
35302 pEntityName => 'MSC_ST_SUPPLIES',
35303 pInstanceID => v_instance_id);
35304
35305 IF NVL(lv_return,0) <> 0 THEN
35306 RAISE ex_logging_err;
35307 END IF;
35308
35309
35310 --Generation of sr_mtl_supply_id
35311 OPEN c2(p_batch_id);
35312 FETCH c2 BULK COLLECT INTO lb_rowid ;
35313
35314 IF c2%ROWCOUNT > 0 THEN
35315
35316 v_sql_stmt := 22;
35317 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
35318 UPDATE msc_st_supplies
35319 SET sr_mtl_supply_id = msc_st_sr_mtl_supply_id_s.NEXTVAL
35320 WHERE rowid = lb_rowid(j);
35321
35322 v_sql_stmt := 23;
35323 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
35324 INSERT INTO msc_local_id_supply
35325 (local_id,
35326 st_transaction_id,
35327 instance_id,
35328 entity_name,
35329 data_source_type,
35330 char1,
35331 char2,
35332 char3,
35333 char4,
35334 number1,
35335 number2,
35336 SOURCE_ORG_ID,
35337 SOURCE_INVENTORY_ITEM_ID,
35338 SOURCE_VENDOR_ID,
35339 SOURCE_VENDOR_SITE_ID,
35340 SOURCE_TASK_ID,
35341 SOURCE_FROM_ORGANIZATION_ID,
35342 SOURCE_SR_MTL_SUPPLY_ID,
35343 SOURCE_DISPOSITION_ID,
35344 SOURCE_PROJECT_ID,
35345 last_update_date,
35346 last_updated_by,
35347 creation_date,
35348 created_by)
35349 SELECT
35350 sr_mtl_supply_id,
35351 st_transaction_id,
35352 v_instance_id,
35353 'SR_MTL_SUPPLY_ID',
35354 data_source_type,
35355 v_instance_code,
35356 company_name,
35357 organization_code ,
35358 order_number,
35359 purch_line_num,
35360 order_type,
35361 SOURCE_ORG_ID,
35362 SOURCE_INVENTORY_ITEM_ID,
35363 SOURCE_VENDOR_ID,
35364 SOURCE_VENDOR_SITE_ID,
35365 SOURCE_TASK_ID,
35366 SOURCE_FROM_ORGANIZATION_ID,
35367 SOURCE_SR_MTL_SUPPLY_ID,
35368 SOURCE_DISPOSITION_ID,
35369 SOURCE_PROJECT_ID,
35370 v_current_date,
35371 v_current_user,
35372 v_current_date,
35373 v_current_user
35374 FROM msc_st_supplies
35375 WHERE rowid = lb_rowid(j);
35376 END IF;
35377 CLOSE c2 ;
35378
35379
35380 --Generation of po_line_id
35381 OPEN c4(p_batch_id);
35382 FETCH c4 BULK COLLECT INTO lb_rowid ;
35383
35384 IF c4%ROWCOUNT > 0 THEN
35385 v_sql_stmt := 26;
35386 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
35387 UPDATE msc_st_supplies
35388 SET po_line_id = msc_st_po_line_id_s.NEXTVAL
35389 WHERE rowid = lb_rowid(j);
35390
35391 v_sql_stmt := 27;
35392 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
35393 INSERT INTO msc_local_id_supply
35394 (local_id,
35395 st_transaction_id,
35396 instance_id,
35397 entity_name,
35398 data_source_type,
35399 char1,
35400 char2,
35401 char3,
35402 number1,
35403 number2,
35404 SOURCE_ORG_ID,
35405 SOURCE_INVENTORY_ITEM_ID,
35406 SOURCE_VENDOR_ID,
35407 SOURCE_VENDOR_SITE_ID,
35408 SOURCE_TASK_ID,
35409 SOURCE_FROM_ORGANIZATION_ID,
35410 SOURCE_SR_MTL_SUPPLY_ID,
35411 SOURCE_DISPOSITION_ID,
35412 SOURCE_PROJECT_ID,
35413 last_update_date,
35414 last_updated_by,
35415 creation_date,
35416 created_by)
35417 SELECT
35418 po_line_id,
35419 st_transaction_id,
35420 v_instance_id,
35421 'PO_LINE_ID',
35422 data_source_type,
35423 v_instance_code,
35424 company_name,
35425 order_number,
35426 purch_line_num,
35427 order_type,
35428 SOURCE_ORG_ID,
35429 SOURCE_INVENTORY_ITEM_ID,
35430 SOURCE_VENDOR_ID,
35431 SOURCE_VENDOR_SITE_ID,
35432 SOURCE_TASK_ID,
35433 SOURCE_FROM_ORGANIZATION_ID,
35434 SOURCE_SR_MTL_SUPPLY_ID,
35435 SOURCE_DISPOSITION_ID,
35436 SOURCE_PROJECT_ID,
35437 v_current_date,
35438 v_current_user,
35439 v_current_date,
35440 v_current_user
35441 FROM msc_st_supplies
35442 WHERE rowid = lb_rowid(j);
35443
35444 END IF;
35445 CLOSE c4 ;
35446
35447 --Generation of disposition_id(MPS)
35448 OPEN c5(p_batch_id);
35449 FETCH c5 BULK COLLECT INTO lb_rowid ;
35450
35451 IF c5%ROWCOUNT > 0 THEN
35452 v_sql_stmt := 28;
35453 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
35454 UPDATE msc_st_supplies
35455 SET disposition_id = msc_st_disposition_id_s.NEXTVAL
35456 WHERE rowid = lb_rowid(j);
35457
35458 v_sql_stmt := 29;
35459 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
35460 INSERT INTO msc_local_id_supply
35461 (local_id,
35462 st_transaction_id,
35463 instance_id,
35464 entity_name,
35465 data_source_type,
35466 char1,
35467 char2,
35468 char3,
35469 char4,
35470 char5,
35471 number1,
35472 SOURCE_ORG_ID,
35473 SOURCE_INVENTORY_ITEM_ID,
35474 SOURCE_VENDOR_ID,
35475 SOURCE_VENDOR_SITE_ID,
35476 SOURCE_TASK_ID,
35477 SOURCE_FROM_ORGANIZATION_ID,
35478 SOURCE_SR_MTL_SUPPLY_ID,
35479 SOURCE_DISPOSITION_ID,
35480 SOURCE_PROJECT_ID,
35481 last_update_date,
35482 last_updated_by,
35483 creation_date,
35484 created_by)
35485 SELECT
35486 disposition_id,
35487 st_transaction_id,
35488 v_instance_id,
35489 'DISPOSITION_ID_MPS',
35490 data_source_type,
35491 v_instance_code,
35492 company_name,
35493 organization_code,
35494 schedule_designator,
35495 schedule_line_num,
35496 order_type,
35497 SOURCE_ORG_ID,
35498 SOURCE_INVENTORY_ITEM_ID,
35499 SOURCE_VENDOR_ID,
35500 SOURCE_VENDOR_SITE_ID,
35501 SOURCE_TASK_ID,
35502 SOURCE_FROM_ORGANIZATION_ID,
35503 SOURCE_SR_MTL_SUPPLY_ID,
35504 SOURCE_DISPOSITION_ID,
35505 SOURCE_PROJECT_ID,
35506 v_current_date,
35507 v_current_user,
35508 v_current_date,
35509 v_current_user
35510 FROM msc_st_supplies
35511 WHERE rowid = lb_rowid(j);
35512
35513 END IF;
35514 CLOSE c5 ;
35515
35516 --Updating line_id using disposition_id for the Plan Orders.
35517 v_sql_stmt := 30;
35518 lv_sql_stmt :=
35519 'UPDATE msc_st_supplies mss'
35520 ||' SET line_id = disposition_id'
35521 ||' WHERE order_type = 5'
35522 ||' AND process_flag = '||G_IN_PROCESS
35523 ||' AND NVL(batch_id,'||NULL_VALUE||')= :p_batch_id'
35524 ||' AND sr_instance_code = :v_instance_code';
35525
35526
35527 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
35528
35529 EXECUTE IMMEDIATE lv_sql_stmt
35530 USING p_batch_id,
35531 v_instance_code;
35532
35533 v_sql_stmt := 31;
35534 lv_sql_stmt :=
35535 'UPDATE msc_st_supplies mss '
35536 ||' SET disposition_id = (SELECT local_id'
35537 ||' FROM msc_local_id_supply mls'
35538 ||' WHERE mls.char3 = mss.order_number'
35539 ||' AND mls.number1 = mss.order_type'
35540 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
35541 ||' NVL(mss.company_name,'||''''||NULL_CHAR||''''||') '
35542 ||' AND mls.char1 = mss.sr_instance_code'
35543 ||' AND mls.entity_name = ''DISPOSITION_ID'' ) '
35544 ||' WHERE order_type IN(1,2,8,11,12,73,74,87)'
35545 ||' AND NVL(disposition_id,'||NULL_VALUE||') = '||NULL_VALUE
35546 ||' AND deleted_flag = '||SYS_NO
35547 ||' AND process_flag = '||G_IN_PROCESS
35548 ||' AND NVL(batch_id,'||NULL_VALUE||') = :p_batch_id'
35549 ||' AND sr_instance_code = :v_instance_code';
35550
35551
35552 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
35553
35554 EXECUTE IMMEDIATE lv_sql_stmt
35555 USING p_batch_id,
35556 v_instance_code;
35557
35558
35559 -- Bug 2821525
35560 -- Updating vmi_flag with 1 for Purchase orders ,ASN (Intransit shipments) ,
35561 -- Shipment Receipts and Requisitions if Item has record of approved supplier list
35562 -- in msc_item_suppliers and that particular ASL is VMI enabled
35563
35564 v_sql_stmt := 32;
35565 lv_sql_stmt :=
35566 ' UPDATE msc_st_supplies mss '
35567 ||' SET vmi_flag = ''Y'''
35568 ||' WHERE exists (SELECT 1 FROM MSC_TP_ID_LID mtil,'
35569 ||' MSC_TP_SITE_ID_LID mtsil,'
35570 ||' MSC_ITEM_ID_LID t1,'
35571 ||' MSC_ITEM_SUPPLIERS mis'
35572 ||' WHERE mis.organization_id = mss.organization_id '
35573 ||' AND t1.SR_INVENTORY_ITEM_ID= mss.inventory_item_id'
35574 ||' AND t1.sr_instance_id= :v_instance_id'
35575 ||' AND t1.INVENTORY_ITEM_ID =mis.INVENTORY_ITEM_ID'
35576 ||' AND mtil.SR_TP_ID = mss.SUPPLIER_ID'
35577 ||' AND mtil.SR_INSTANCE_ID = :v_instance_id'
35578 ||' AND mtil.PARTNER_TYPE = 1'
35579 ||' AND nvl(mtil.sr_company_id, -1) = nvl(mss.company_id, -1)'
35580 ||' AND mtil.TP_ID = mis.SUPPLIER_ID'
35581 ||' AND mis.SR_INSTANCE_ID = :v_instance_id'
35582 ||' AND mis.plan_id = -1 '
35583 ||' AND mtsil.SR_TP_SITE_ID = mss.Supplier_Site_ID'
35584 ||' AND mtsil.SR_INSTANCE_ID= :v_instance_id'
35585 ||' AND mtsil.Partner_Type = 1'
35586 ||' AND nvl(mtsil.sr_company_id, -1) = nvl(mss.company_id, -1)'
35587 ||' AND mss.Supplier_Site_ID is NOT NULL '
35588 ||' AND mis.SUPPLIER_SITE_ID is NOT NULL'
35589 ||' AND mtsil.TP_SITE_ID = mis.SUPPLIER_SITE_ID'
35590 ||' AND mis.VMI_FLAG = 1'
35591 ||' UNION ALL '
35592 ||' SELECT 1 FROM MSC_TP_ID_LID mtil2,'
35593 ||' MSC_TP_SITE_ID_LID mtsil2,'
35594 ||' MSC_ITEM_ID_LID t2,'
35595 ||' MSC_ITEM_SUPPLIERS mis2'
35596 ||' WHERE mis2.organization_id = mss.organization_id '
35597 ||' AND t2.SR_INVENTORY_ITEM_ID= mss.inventory_item_id'
35598 ||' AND t2.sr_instance_id= :v_instance_id'
35599 ||' AND t2.INVENTORY_ITEM_ID =mis2.INVENTORY_ITEM_ID'
35600 ||' AND mtil2.SR_TP_ID = mss.SUPPLIER_ID'
35601 ||' AND mtil2.SR_INSTANCE_ID = :v_instance_id'
35602 ||' AND mtil2.PARTNER_TYPE = 1'
35603 ||' AND nvl(mtil2.sr_company_id, -1) = nvl(mss.company_id, -1)'
35604 ||' AND mtil2.TP_ID = mis2.SUPPLIER_ID'
35605 ||' AND mis2.SR_INSTANCE_ID = :v_instance_id'
35606 ||' AND mis2.plan_id = -1 '
35607 ||' AND mtsil2.SR_TP_SITE_ID = mss.Supplier_Site_ID'
35608 ||' AND mtsil2.SR_INSTANCE_ID= :v_instance_id'
35609 ||' AND mtsil2.Partner_Type = 1'
35610 ||' AND nvl(mtsil2.sr_company_id, -1) = nvl(mss.company_id, -1)'
35611 ||' AND mss.Supplier_Site_ID is NOT NULL '
35612 ||' AND mis2.SUPPLIER_SITE_ID is NULL'
35613 ||' AND mis2.VMI_FLAG = 1 '
35614 ||' AND not exists ( SELECT 1 from MSC_ITEM_SUPPLIERS mis3'
35615 ||' WHERE mtsil2.TP_SITE_ID = mis3.SUPPLIER_SITE_ID'
35616 ||' AND mis3.organization_id = mss.organization_id '
35617 ||' AND t2.SR_INVENTORY_ITEM_ID= mss.inventory_item_id'
35618 ||' AND t2.sr_instance_id= :v_instance_id'
35619 ||' AND t2.INVENTORY_ITEM_ID =mis3.INVENTORY_ITEM_ID'
35620 ||' AND mtil2.SR_TP_ID = mss.SUPPLIER_ID'
35621 ||' AND mtil2.SR_INSTANCE_ID = :v_instance_id'
35622 ||' AND mtil2.PARTNER_TYPE = 1'
35623 ||' AND nvl(mtil2.sr_company_id, -1) = nvl(mss.company_id, -1)'
35624 ||' AND mtil2.TP_ID = mis3.SUPPLIER_ID '
35625 ||' AND mis3.SR_INSTANCE_ID = :v_instance_id'
35626 ||' AND mis3.plan_id = -1)'
35627 ||' UNION ALL '
35628 ||' SELECT 1 FROM MSC_TP_ID_LID mtil4,'
35629 ||' MSC_TP_SITE_ID_LID mtsil4,'
35630 ||' MSC_ITEM_ID_LID t4,'
35631 ||' MSC_ITEM_SUPPLIERS mis4'
35632 ||' WHERE mis4.organization_id = mss.organization_id '
35633 ||' AND t4.SR_INVENTORY_ITEM_ID= mss.inventory_item_id'
35634 ||' AND t4.sr_instance_id= :v_instance_id'
35635 ||' AND t4.INVENTORY_ITEM_ID =mis4.INVENTORY_ITEM_ID'
35636 ||' AND mtil4.SR_TP_ID = mss.SUPPLIER_ID'
35637 ||' AND mtil4.SR_INSTANCE_ID = :v_instance_id'
35638 ||' AND mtil4.PARTNER_TYPE = 1'
35639 ||' AND nvl(mtil4.sr_company_id, -1) = nvl(mss.company_id, -1)'
35640 ||' AND mtil4.TP_ID = mis4.SUPPLIER_ID'
35641 ||' AND mis4.SR_INSTANCE_ID = :v_instance_id'
35642 ||' AND mis4.plan_id = -1 '
35643 ||' AND mss.Supplier_Site_ID is NULL '
35644 ||' AND mis4.SUPPLIER_SITE_ID is NULL'
35645 ||' AND mis4.VMI_FLAG = 1)'
35646 ||' AND order_type IN (1,2,8,11,12,73,74,87) '
35647 ||' AND process_flag = '||G_IN_PROCESS
35648 ||' AND NVL(batch_id,'||NULL_VALUE||')= :p_batch_id '
35649 ||' AND sr_instance_code =:v_instance_code';
35650
35651
35652
35653
35654 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
35655
35656 EXECUTE IMMEDIATE lv_sql_stmt
35657 USING v_instance_id, v_instance_id, v_instance_id, v_instance_id, v_instance_id,
35658 v_instance_id, v_instance_id,v_instance_id, v_instance_id, v_instance_id,
35659 v_instance_id, v_instance_id, v_instance_id, v_instance_id, p_batch_id,
35660 v_instance_code;
35661
35662
35663 -- bug 2903052 defaulting the new_schedule_date as sysdate for onhand supply
35664
35665 lv_sql_stmt :=
35666 'UPDATE msc_st_supplies mss'
35667 ||' SET new_schedule_date = SYSDATE'
35668 ||' WHERE deleted_flag ='|| SYS_NO
35669 ||' AND process_flag ='|| G_IN_PROCESS
35670 ||' AND order_type = 18'
35671 ||' AND NVL(batch_id,'||NULL_VALUE||')= :p_batch_id'
35672 ||' AND sr_instance_code = :v_instance_code';
35673
35674
35675 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
35676
35677 EXECUTE IMMEDIATE lv_sql_stmt
35678 USING p_batch_id,
35679 v_instance_code;
35680
35681
35682
35683
35684 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
35685 (p_table_name => 'MSC_ST_SUPPLIES',
35686 p_instance_id => v_instance_id,
35687 p_instance_code => v_instance_code,
35688 p_process_flag => G_VALID,
35689 p_error_text => lv_error_text,
35690 p_debug => v_debug,
35691 p_batch_id => p_batch_id);
35692
35693 IF lv_return <> 0 THEN
35694 RAISE ex_logging_err;
35695 END IF;
35696
35697 lv_return := MSC_ST_UTIL.LOG_ERROR
35698 (p_table_name => 'MSC_ST_SUPPLIES',
35699 p_instance_code => v_instance_code,
35700 p_row => lv_column_names,
35701 p_severity => G_SEV_ERROR,
35702 p_message_text => NULL,
35703 p_error_text => lv_error_text,
35704 p_debug => v_debug,
35705 p_batch_id => p_batch_id);
35706
35707 IF lv_return <> 0 THEN
35708 RAISE ex_logging_err;
35709 END IF;
35710
35711 COMMIT;
35712
35713 EXCEPTION
35714 WHEN too_many_rows THEN
35715 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_SUPPLY'||'('
35716 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
35717 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
35718 ROLLBACK;
35719 IF c_lock%ISOPEN THEN
35720 CLOSE c_lock;
35721 END IF;
35722
35723 WHEN ex_logging_err THEN
35724 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
35725 ROLLBACK;
35726 IF c_lock%ISOPEN THEN
35727 CLOSE c_lock;
35728 END IF;
35729
35730 WHEN OTHERS THEN
35731 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_SUPPLY'||'('
35732 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
35733 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
35734 ROLLBACK;
35735 IF c_lock%ISOPEN THEN
35736 CLOSE c_lock;
35737 END IF;
35738
35739 END LOAD_SUPPLY;
35740
35741 /*==========================================================================+
35742 | DESCRIPTION : This procedure is called for validating demand related |
35743 | records from the msc_st_sales_orders table. |
35744 +==========================================================================*/
35745 PROCEDURE LOAD_SALES_ORDER (p_batch_id IN NUMBER ) IS
35746 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
35747
35748 lb_rowid RowidTab;
35749
35750 lv_column_names VARCHAR2(5000); -- Stores cocatenated column names
35751 lv_return NUMBER;
35752 lv_error_text VARCHAR2(250);
35753 lv_where_str VARCHAR2(5000);
35754 lv_sql_stmt VARCHAR2(5000);
35755 lv_cursor_stmt VARCHAR2(5000);
35756 lv_message_text msc_errors.error_text%TYPE;
35757 lv_batch_id NUMBER;
35758
35759 lv_retain_src_header_line_id NUMBER; -- 12620427
35760 lv_apps_ver NUMBER;
35761 lv_allow_atp_flag NUMBER;
35762
35763 ex_logging_err EXCEPTION;
35764 busy EXCEPTION;
35765 PRAGMA EXCEPTION_INIT(busy, -54);
35766
35767 CURSOR c1(p_batch_id NUMBER) IS
35768 SELECT rowid
35769 FROM msc_st_sales_orders
35770 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
35771 AND batch_id = p_batch_id
35772 AND sr_instance_code = v_instance_code;
35773
35774 CURSOR c2(p_batch_id NUMBER) IS
35775 SELECT max(rowid)
35776 FROM msc_st_sales_orders
35777 WHERE process_flag = G_IN_PROCESS
35778 AND sr_instance_code = v_instance_code
35779 AND batch_id = p_batch_id
35780 AND NVL(demand_source_header_id,NULL_VALUE) = NULL_VALUE
35781 AND deleted_flag = SYS_NO
35782 GROUP BY SR_INSTANCE_CODE,COMPANY_NAME,
35783 ORGANIZATION_CODE,SALES_ORDER_NUMBER;
35784
35785 CURSOR c3(p_batch_id NUMBER) IS
35786 SELECT rowid
35787 FROM msc_st_sales_orders
35788 WHERE process_flag = G_IN_PROCESS
35789 AND sr_instance_code = v_instance_code
35790 AND batch_id = p_batch_id
35791 AND NVL(demand_id,NULL_VALUE) = NULL_VALUE
35792 AND deleted_flag = SYS_NO;
35793
35794 CURSOR c4(p_batch_id NUMBER) IS
35795 SELECT max(rowid)
35796 FROM msc_st_sales_orders
35797 WHERE process_flag = G_IN_PROCESS
35798 AND sr_instance_code = v_instance_code
35799 AND batch_id = p_batch_id
35800 AND NVL(ship_set_id,NULL_VALUE) = NULL_VALUE
35801 AND NVL(ship_set_name,NULL_CHAR) <> NULL_CHAR
35802 AND deleted_flag = SYS_NO
35803 GROUP BY SR_INSTANCE_CODE,COMPANY_NAME,
35804 ORGANIZATION_CODE,SALES_ORDER_NUMBER, SHIP_SET_NAME;
35805
35806 CURSOR c5(p_batch_id NUMBER) IS
35807 SELECT max(rowid)
35808 FROM msc_st_sales_orders
35809 WHERE process_flag = G_IN_PROCESS
35810 AND sr_instance_code = v_instance_code
35811 AND batch_id = p_batch_id
35812 AND NVL(arrival_set_id,NULL_VALUE) = NULL_VALUE
35813 AND NVL(arrival_set_name,NULL_CHAR) <> NULL_CHAR
35814 AND deleted_flag = SYS_NO
35815 GROUP BY SR_INSTANCE_CODE,COMPANY_NAME,
35816 ORGANIZATION_CODE,SALES_ORDER_NUMBER, ARRIVAL_SET_NAME;
35817
35818 CURSOR c_lock(p_batch_id NUMBER) IS
35819 SELECT 'X'
35820 FROM msc_st_sales_orders mso ,
35821 msc_st_sales_orders mcr
35822 WHERE mso.batch_id = p_batch_id
35823 AND mso.batch_id <> nvl(mcr.batch_id,NULL_VALUE)
35824 AND mso.demand_source_header_id IS NULL
35825 AND mcr.demand_source_header_id IS NULL
35826 AND NVL(mso.company_name,NULL_CHAR)= NVL(mcr.company_name,NULL_CHAR)
35827 AND mso.organization_code = mcr.organization_code
35828 AND mso.sales_order_number = mcr.sales_order_number
35829 AND mso.sr_instance_code = mcr.sr_instance_code
35830 AND mso.batch_id <> mcr.batch_id
35831 FOR UPDATE NOWAIT ;
35832
35833 BEGIN
35834
35835 lv_column_names :=
35836 'ITEM_NAME ||''~''||'
35837 ||' ORGANIZATION_CODE ||''~''||'
35838 ||' PRIMARY_UOM_QUANTITY ||''~''||'
35839 ||' COMPLETED_QUANTITY ||''~''||'
35840 ||' REQUIREMENT_DATE ||''~''||'
35841 ||' SALES_ORDER_NUMBER ||''~''||'
35842 ||' LINE_NUM ||''~''||'
35843 ||' SR_INSTANCE_CODE ||''~''||'
35844 ||' RESERVATION_TYPE ||''~''||'
35845 ||' RESERVATION_QUANTITY ||''~''||'
35846 ||' SUBINVENTORY ||''~''||'
35847 ||' DEMAND_CLASS ||''~''||'
35848 ||' SALESREP_CONTACT ||''~''||'
35849 ||' ORDERED_ITEM_NAME ||''~''||'
35850 ||' AVAILABLE_TO_MRP ||''~''||'
35851 ||' CUSTOMER_NAME ||''~''||'
35852 ||' SHIP_TO_SITE_CODE ||''~''||'
35853 ||' BILL_TO_SITE_CODE ||''~''||'
35854 ||' PLANNING_GROUP ||''~''||'
35855 ||' DEMAND_PRIORITY ||''~''||'
35856 ||' REQUEST_DATE ||''~''||'
35857 ||' SELLING_PRICE ||''~''||'
35858 ||' DEMAND_VISIBLE ||''~''||'
35859 ||' FORECAST_VISIBLE ||''~''||'
35860 ||' CTO_FLAG ||''~''||'
35861 ||' ORIGINAL_SYSTEM_REFERENCE ||''~''||'
35862 ||' ORIGINAL_SYSTEM_LINE_REFERENCE ||''~''||'
35863 ||' COMPANY_NAME ||''~''||'
35864 ||' DELETED_FLAG ||''~''||'
35865 ||' PROJECT_NUMBER ||''~''||'
35866 ||' TASK_NUMBER ||''~''||'
35867 ||' DEMAND_SOURCE_TYPE ||''~''||'
35868 ||' REVISED_DMD_DATE ||''~''||'
35869 ||' REVISED_DMD_PRIORITY';
35870
35871 -- 12620427
35872 -- Initialize variable lv_retain_src_header_line_id
35873
35874 BEGIN
35875 v_sql_stmt := 0.5;
35876
35877 SELECT
35878 allow_atp_flag
35879 , apps_ver
35880 INTO
35881 lv_allow_atp_flag
35882 , lv_apps_ver
35883 FROM msc_apps_instances
35884 WHERE
35885 instance_id = v_instance_id;
35886
35887 IF (lv_allow_atp_flag = 1) AND (lv_apps_ver = -1) THEN
35888 lv_retain_src_header_line_id := 1;
35889 ELSE
35890 lv_retain_src_header_line_id := 2;
35891 END IF;
35892 EXCEPTION
35893 WHEN no_data_found THEN
35894 lv_retain_src_header_line_id := 2;
35895 END;
35896
35897 -- Derive demand source header id
35898
35899 v_sql_stmt := 1.0;
35900
35901
35902 -- lock all the sales order lines in this batch that match the key .
35903 -- Vinay 15-NOV-2001.
35904
35905 LOOP
35906 BEGIN
35907 OPEN c_lock(p_batch_id) ;
35908 EXIT;
35909 EXCEPTION
35910 WHEN busy THEN
35911 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_SALES_ORDER'||'('||v_sql_stmt||')'||'p_batch_id :'||p_batch_id|| SQLERRM, 1, 240);
35912 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
35913 dbms_lock.sleep(5);
35914 WHEN OTHERS THEN
35915 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_SALES_ORDER'||'('||v_sql_stmt||')'||'p_batch_id :'||p_batch_id|| SQLERRM, 1, 240);
35916 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
35917
35918 v_sql_stmt := 1.1;
35919 lv_sql_stmt :=
35920 'UPDATE msc_st_sales_orders '
35921 ||' SET process_flag = 1,'
35922 ||' batch_id = NULL'
35923 ||' WHERE batch_id = :p_batch_id'
35924 ||' AND process_flag = '||G_IN_PROCESS
35925 ||' AND sr_instance_code =:v_instance_code';
35926
35927
35928 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
35929
35930 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
35931 COMMIT;
35932
35933 RETURN ;
35934 END;
35935 END LOOP;
35936
35937 -- 12620427
35938 IF (lv_retain_src_header_line_id = 1) THEN
35939 -- Set the message
35940
35941 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
35942 (p_app_short_name => 'MSC',
35943 p_error_code => 'MSC_PP_COL_VAL_NULL',
35944 p_message_text => lv_message_text,
35945 p_error_text => lv_error_text,
35946 p_token1 => 'COLUMN_NAME',
35947 p_token_value1 => 'SOURCE_DEMAND_SOURCE_HEADER_ID'
35948 ||'OR SOURCE_DEMAND_SOURCE_LINE');
35949
35950 IF lv_return <> 0 THEN
35951 RAISE ex_logging_err;
35952 END IF;
35953
35954
35955
35956 -- Error out records where NULL source_demand_source_header_id OR
35957 -- source_demand_source_line are present
35958
35959 v_sql_stmt := 1.5;
35960
35961 lv_sql_stmt :=
35962 'UPDATE msc_st_sales_orders '
35963 ||' SET process_flag = '||G_ERROR_FLG||','
35964 ||' error_text = '||''''||lv_message_text||''''
35965 ||' WHERE ( NVL(SOURCE_DEMAND_SOURCE_HEADER_ID,'
35966 ||NULL_VALUE||') = '||NULL_VALUE
35967 ||' OR NVL(SOURCE_DEMAND_SOURCE_LINE,'||''''||NULL_VALUE||''''||') '
35968 ||' = '||''''||NULL_VALUE||''''||')'
35969 ||' AND process_flag = '||G_IN_PROCESS
35970 ||' AND batch_id = :p_batch_id'
35971 ||' AND sr_instance_code = :v_instance_code';
35972
35973
35974
35975 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
35976
35977 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
35978
35979 END IF;
35980
35981 -- 12620427
35982 IF (lv_retain_src_header_line_id = 2) THEN
35983
35984 -- Generate demand_source_header_id
35985
35986 v_sql_stmt := 2.0;
35987 lv_sql_stmt :=
35988 'UPDATE msc_st_sales_orders mso '
35989 ||' SET demand_source_header_id = (SELECT local_id'
35990 ||' FROM msc_local_id_demand mlid'
35991 ||' WHERE mlid.char1 = mso.sr_instance_code'
35992 ||' AND NVL(mlid.char2,'||''''||NULL_CHAR||''''||') '
35993 ||' = NVL(mso.company_name,'||''''||NULL_CHAR||''''||') '
35994 ||' AND mlid.char3 = mso.organization_code'
35995 ||' AND mlid.char4 = mso.sales_order_number'
35996 ||' AND mlid.instance_id = '||v_instance_id
35997 ||' AND mlid.entity_name = ''SALES_ORDER_ID'' )'
35998 ||' WHERE process_flag = '||G_IN_PROCESS
35999 ||' AND NVL(demand_source_header_id,'||NULL_VALUE||') = '||NULL_VALUE
36000 ||' AND batch_id = :p_batch_id '
36001 ||' AND sr_instance_code =:v_instance_code';
36002
36003
36004 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
36005
36006 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
36007 OPEN c2(p_batch_id);
36008 FETCH c2 BULK COLLECT INTO lb_rowid ;
36009
36010 IF c2%ROWCOUNT > 0 THEN
36011 v_sql_stmt := 2.1;
36012 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
36013 UPDATE msc_st_sales_orders
36014 SET demand_source_header_id = msc_st_sales_order_id_s.NEXTVAL
36015 WHERE rowid = lb_rowid(j)
36016 AND demand_Source_header_id is null;
36017
36018 v_sql_stmt := 2.2;
36019 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
36020 INSERT INTO msc_local_id_demand
36021 (local_id,
36022 st_transaction_id,
36023 instance_id,
36024 entity_name,
36025 data_source_type,
36026 char1,
36027 char2,
36028 char3,
36029 char4,
36030 SOURCE_DEMAND_SOURCE_HEADER_ID,
36031 last_update_date,
36032 last_updated_by,
36033 creation_date,
36034 created_by)
36035 SELECT
36036 demand_source_header_id,
36037 st_transaction_id,
36038 v_instance_id,
36039 'SALES_ORDER_ID',
36040 data_source_type,
36041 sr_instance_code,
36042 company_name,
36043 organization_code,
36044 sales_order_number,
36045 SOURCE_DEMAND_SOURCE_HEADER_ID,
36046 v_current_date,
36047 v_current_user,
36048 v_current_date,
36049 v_current_user
36050 FROM msc_st_sales_orders
36051 WHERE rowid = lb_rowid(j);
36052
36053 END IF;
36054 CLOSE c2;
36055
36056 -- Update demand source header id
36057
36058 v_sql_stmt := 2.4;
36059 lv_sql_stmt :=
36060 'UPDATE msc_st_sales_orders mso '
36061 ||' SET demand_source_header_id = (SELECT local_id'
36062 ||' FROM msc_local_id_demand mlid'
36063 ||' WHERE mlid.char1 = mso.sr_instance_code'
36064 ||' AND NVL(mlid.char2,'||''''||NULL_CHAR||''''||') '
36065 ||' = NVL(mso.company_name,'||''''||NULL_CHAR||''''||') '
36066 ||' AND mlid.char3 = mso.organization_code'
36067 ||' AND mlid.char4 = mso.sales_order_number'
36068 ||' AND mlid.instance_id = '||v_instance_id
36069 ||' AND mlid.entity_name = ''SALES_ORDER_ID'' )'
36070 ||' WHERE process_flag = '||G_IN_PROCESS
36071 ||' AND NVL(demand_source_header_id,'||NULL_VALUE||') = '||NULL_VALUE
36072 ||' AND batch_id = :p_batch_id '
36073 ||' AND sr_instance_code =:v_instance_code';
36074
36075
36076 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
36077
36078 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
36079
36080
36081
36082 COMMIT;
36083 IF c_lock%ISOPEN THEN
36084 CLOSE c_lock;
36085 END IF;
36086 -- release locks
36087 ELSE
36088 -- 12620427
36089 -- Logic to retain the demand source header id present
36090 -- in the staging table.
36091
36092 -- Here, we will insert records into table msc_local_id_demand
36093 -- for entity_type = 'SALES_ORDER_ID'.
36094 -- for sales order number that do not already exist in this table.
36095
36096 v_sql_stmt := 2.5;
36097
36098 lv_sql_stmt :=
36099 'UPDATE msc_st_sales_orders mso '
36100 ||' SET demand_source_header_id = source_demand_source_header_id'
36101 ||' WHERE process_flag = '||G_IN_PROCESS
36102 ||' AND NVL(demand_source_header_id,'||NULL_VALUE||') = '||NULL_VALUE
36103 ||' AND batch_id = :p_batch_id '
36104 ||' AND sr_instance_code =:v_instance_code';
36105
36106 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
36107
36108 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
36109
36110
36111 END IF; --for lv_retain_src_header_line_id = 2
36112
36113
36114 OPEN c1(p_batch_id);
36115 FETCH c1 BULK COLLECT INTO lb_rowid;
36116 IF c1%ROWCOUNT > 0 THEN
36117 v_sql_stmt := 03;
36118 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
36119 UPDATE msc_st_sales_orders
36120 SET st_transaction_id = msc_st_sales_orders_s.NEXTVAL,
36121 refresh_id = v_refresh_id,
36122 last_update_date = v_current_date,
36123 last_updated_by = v_current_user,
36124 creation_date = v_current_date,
36125 created_by = v_current_user
36126 WHERE rowid = lb_rowid(j);
36127
36128 END IF;
36129 CLOSE c1;
36130
36131
36132 --Set the message
36133
36134 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36135 (p_app_short_name => 'MSC',
36136 p_error_code => 'MSC_PP_INVALID_VALUE',
36137 p_message_text => lv_message_text,
36138 p_error_text => lv_error_text,
36139 p_token1 => 'COLUMN_NAME',
36140 p_token_value1 => 'REVISED_DMD_PRIORITY' );
36141
36142 IF lv_return <> 0 THEN
36143 RAISE ex_logging_err;
36144 END IF;
36145
36146
36147 -- Error out records if REVISED_DMD_PRIORITY is not a positive number
36148
36149 v_sql_stmt := 03;
36150 lv_sql_stmt :=
36151 'UPDATE msc_st_sales_orders '
36152 ||' SET process_flag = '||G_ERROR_FLG||','
36153 ||' error_text = '||''''||lv_message_text||''''
36154 ||' WHERE NVL(REVISED_DMD_PRIORITY, 1) < 0'
36155 ||' AND process_flag = '||G_IN_PROCESS
36156 ||' AND batch_id = :p_batch_id'
36157 ||' AND sr_instance_code = :v_instance_code';
36158
36159
36160 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
36161
36162 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
36163
36164 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36165 (p_app_short_name => 'MSC',
36166 p_error_code => 'MSC_PP_REV_DT_GT_REQ_DATE',
36167 p_message_text => lv_message_text,
36168 p_error_text => lv_error_text);
36169
36170 IF lv_return <> 0 THEN
36171 RAISE ex_logging_err;
36172 END IF;
36173
36174
36175 lv_where_str :=
36176 ' AND TRUNC(NVL(REVISED_DMD_DATE,SYSDATE- 36500)) > TRUNC(NVL(REQUIREMENT_DATE,SYSDATE+36500))';
36177
36178 --Log a warning for those records where the revised_dmd_date is greater
36179 --than firm date(requirement_date)
36180 lv_return := MSC_ST_UTIL.LOG_ERROR
36181 (p_table_name => 'MSC_ST_SALES_ORDERS',
36182 p_instance_code => v_instance_code,
36183 p_row => lv_column_names,
36184 p_severity => G_SEV_WARNING,
36185 p_message_text => lv_message_text,
36186 p_error_text => lv_error_text,
36187 p_batch_id => p_batch_id,
36188 p_where_str => lv_where_str);
36189
36190
36191
36192
36193 IF lv_return <> 0 THEN
36194 RAISE ex_logging_err;
36195 END IF;
36196
36197
36198
36199 -- Set the message
36200
36201 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36202 (p_app_short_name => 'MSC',
36203 p_error_code => 'MSC_PP_COL_VAL_NULL',
36204 p_message_text => lv_message_text,
36205 p_error_text => lv_error_text,
36206 p_token1 => 'COLUMN_NAME',
36207 p_token_value1 => 'SALES_ORDER_NUMBER'
36208 ||'OR LINE_NUM' );
36209
36210 IF lv_return <> 0 THEN
36211 RAISE ex_logging_err;
36212 END IF;
36213
36214
36215
36216 -- Error out records where NOT NULL columns are not present
36217
36218 v_sql_stmt := 04;
36219
36220 lv_sql_stmt :=
36221 'UPDATE msc_st_sales_orders '
36222 ||' SET process_flag = '||G_ERROR_FLG||','
36223 ||' error_text = '||''''||lv_message_text||''''
36224 ||' WHERE ( NVL(line_num,'||NULL_VALUE||') = '||NULL_VALUE
36225 ||' OR NVL(sales_order_number,'||''''||NULL_CHAR||''''||') '
36226 ||' = '||''''||NULL_CHAR||''''||')'
36227 ||' AND process_flag = '||G_IN_PROCESS
36228 ||' AND batch_id = :p_batch_id'
36229 ||' AND sr_instance_code = :v_instance_code';
36230
36231
36232
36233 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
36234
36235 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
36236
36237
36238 -- Set the error message
36239 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36240 (p_app_short_name => 'MSC',
36241 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
36242 p_message_text => lv_message_text,
36243 p_error_text => lv_error_text,
36244 p_token1 => 'COLUMN_NAME',
36245 p_token_value1 => 'DELETED_FLAG',
36246 p_token2 => 'DEFAULT_VALUE',
36247 p_token_value2 => SYS_NO );
36248
36249 IF lv_return <> 0 THEN
36250 RAISE ex_logging_err;
36251 END IF;
36252
36253
36254 lv_where_str :=
36255 ' AND NVL(deleted_flag,'||NULL_VALUE||') NOT IN(1,2)';
36256
36257 --Log a warning for those records where the deleted_flag has a value other
36258 --SYS_NO or SYS_YES
36259 lv_return := MSC_ST_UTIL.LOG_ERROR
36260 (p_table_name => 'MSC_ST_SALES_ORDERS',
36261 p_instance_code => v_instance_code,
36262 p_row => lv_column_names,
36263 p_severity => G_SEV_WARNING,
36264 p_message_text => lv_message_text,
36265 p_error_text => lv_error_text,
36266 p_batch_id => p_batch_id,
36267 p_where_str => lv_where_str,
36268 p_col_name => 'DELETED_FLAG',
36269 p_debug => v_debug,
36270 p_default_value => SYS_NO);
36271
36272 IF lv_return <> 0 THEN
36273 RAISE ex_logging_err;
36274 END IF;
36275
36276 -- Set the message
36277
36278 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36279 (p_app_short_name => 'MSC',
36280 p_error_code => 'MSC_PP_INVALID_VALUE',
36281 p_message_text => lv_message_text,
36282 p_error_text => lv_error_text,
36283 p_token1 => 'COLUMN_NAME',
36284 p_token_value1 => 'ORGANIZATION_CODE');
36285
36286 IF lv_return <> 0 THEN
36287 RAISE ex_logging_err;
36288 END IF;
36289
36290 --Derive Organization_id
36291 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
36292 (p_table_name => 'MSC_ST_SALES_ORDERS',
36293 p_org_partner_name => 'ORGANIZATION_CODE',
36294 p_org_partner_id => 'ORGANIZATION_ID',
36295 p_instance_code => v_instance_code,
36296 p_partner_type => G_ORGANIZATION,
36297 p_error_text => lv_error_text,
36298 p_batch_id => p_batch_id,
36299 p_severity => G_SEV_ERROR,
36300 p_message_text => lv_message_text,
36301 p_debug => v_debug,
36302 p_row => lv_column_names);
36303
36304 IF lv_return <> 0 THEN
36305 RAISE ex_logging_err;
36306 END IF;
36307
36308 -- Set the message
36309
36310 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36311 (p_app_short_name => 'MSC',
36312 p_error_code => 'MSC_PP_INVALID_VALUE',
36313 p_message_text => lv_message_text,
36314 p_error_text => lv_error_text,
36315 p_token1 => 'COLUMN_NAME',
36316 p_token_value1 => 'ORIGINAL_ITEM_NAME');
36317
36318 IF lv_return <> 0 THEN
36319 RAISE ex_logging_err;
36320 END IF;
36321
36322 --DERIVE ORIGINAL_ITEM_ID
36323
36324 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
36325 (p_table_name =>'MSC_ST_SALES_ORDERS',
36326 p_item_col_name =>'ORIGINAL_ITEM_NAME',
36327 p_item_col_id =>'ORIGINAL_ITEM_ID',
36328 p_instance_code => v_instance_code,
36329 p_instance_id => v_instance_id,
36330 p_batch_id => p_batch_id,
36331 p_debug => v_debug,
36332 p_severity => G_SEV3_ERROR,
36333 p_message_text => lv_message_text,
36334 p_row => lv_column_names,
36335 p_error_text =>lv_error_text);
36336
36337 IF lv_return <> 0 THEN
36338 RAISE ex_logging_err;
36339 END IF;
36340
36341 -----------------------------------moved code from below to above demand_id generation E1----------------
36342 -- Set the error message
36343 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36344 (p_app_short_name => 'MSC',
36345 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
36346 p_message_text => lv_message_text,
36347 p_error_text => lv_error_text,
36348 p_token1 => 'COLUMN_NAME',
36349 p_token_value1 => 'RESERVATION_TYPE',
36350 p_token2 => 'DEFAULT_VALUE',
36351 p_token_value2 => G_RESERVATION_TYPE );
36352
36353 IF lv_return <> 0 THEN
36354 RAISE ex_logging_err;
36355 END IF;
36356
36357 -- Default reservation_type
36358 lv_where_str :=
36359 ' AND NVL(reservation_type,'||NULL_VALUE||') NOT IN (1,2,3)'
36360 ||' AND deleted_flag = '||SYS_NO;
36361
36362
36363 lv_return := MSC_ST_UTIL.LOG_ERROR
36364 (p_table_name => 'MSC_ST_SALES_ORDERS',
36365 p_instance_code => v_instance_code,
36366 p_row => lv_column_names,
36367 p_severity => G_SEV_WARNING,
36368 p_message_text => lv_message_text,
36369 p_error_text => lv_error_text,
36370 p_batch_id => p_batch_id,
36371 p_where_str => lv_where_str,
36372 p_col_name => 'RESERVATION_TYPE',
36373 p_debug => v_debug,
36374 p_default_value => G_RESERVATION_TYPE);
36375
36376 IF lv_return <> 0 THEN
36377 RAISE ex_logging_err;
36378 END IF;
36379 -----------------------------------moved code from below to above demand_id generation E1----------------
36380
36381 -- Derive Demand id
36382
36383 v_sql_stmt := 06;
36384 lv_sql_stmt :=
36385 'UPDATE msc_st_sales_orders mso '
36386 ||' SET demand_id = (SELECT local_id'
36387 ||' FROM msc_local_id_demand mlid'
36388 ||' WHERE mlid.char1 = mso.sr_instance_code'
36389 ||' AND NVL(mlid.char2,'||''''||NULL_CHAR||''''||') '
36390 ||' = NVL(mso.company_name,'||''''||NULL_CHAR||''''||') '
36391 ||' AND mlid.char3 = mso.organization_code'
36392 ||' AND mlid.char4 = mso.sales_order_number'
36393 ||' AND nvl(mlid.number2,'||NULL_VALUE||') = nvl(mso.reservation_type,'||NULL_VALUE||')'
36394 ||' AND NVL(mlid.char5,'||''''||NULL_CHAR||''''||') '
36395 ||' = NVL(mso.SUBINVENTORY,'||''''||NULL_CHAR||''''||') '
36396 ||' AND mlid.number1 = mso.line_num'
36397 ||' AND mlid.entity_name = ''DEMAND_ID'' )'
36398 ||' WHERE process_flag ='||G_IN_PROCESS
36399 ||' AND batch_id = :p_batch_id '
36400 ||' AND sr_instance_code =:v_instance_code';
36401
36402
36403
36404 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
36405
36406 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
36407
36408
36409 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36410 (p_app_short_name => 'MSC',
36411 p_error_code => 'MSC_PP_DELETE_FAIL',
36412 p_message_text => lv_message_text,
36413 p_error_text => lv_error_text);
36414
36415 IF lv_return <> 0 THEN
36416 RAISE ex_logging_err;
36417 END IF;
36418 -- Error out the records where deleted_flag = SYS_YES
36419 -- but NULL demand_id or demand_source_header_id
36420
36421 v_sql_stmt := 07;
36422
36423 lv_sql_stmt :=
36424 'UPDATE msc_st_sales_orders '
36425 ||' SET process_flag ='||G_ERROR_FLG||','
36426 ||' error_text = '||''''||lv_message_text||''''
36427 ||' WHERE (NVL(demand_id,'||NULL_VALUE||') = '||NULL_VALUE
36428 ||' OR NVL(demand_source_header_id,'||NULL_VALUE||') = '||NULL_VALUE||')'
36429 ||' AND deleted_flag ='||SYS_YES
36430 ||' AND batch_id = :p_batch_id '
36431 ||' AND sr_instance_code =:v_instance_code';
36432
36433
36434 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
36435
36436 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
36437
36438
36439 -- Set the message
36440
36441 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36442 (p_app_short_name => 'MSC',
36443 p_error_code => 'MSC_PP_COL_VAL_NULL',
36444 p_message_text => lv_message_text,
36445 p_error_text => lv_error_text,
36446 p_token1 => 'COLUMN_NAME',
36447 p_token_value1 => 'ITEM_NAME OR PRIMARY_UOM_QUANTITY'
36448 ||' OR REQUIREMENT_DATE' );
36449
36450 IF lv_return <> 0 THEN
36451 RAISE ex_logging_err;
36452 END IF;
36453
36454 -- Error out records where NOT NULL columns are not present
36455
36456 v_sql_stmt := 08;
36457
36458 lv_sql_stmt :=
36459 'UPDATE msc_st_sales_orders '
36460 ||' SET process_flag = '||G_ERROR_FLG||','
36461 ||' error_text = '||''''||lv_message_text||''''
36462 ||' WHERE ( NVL(primary_uom_quantity,'||NULL_VALUE||') = '||NULL_VALUE
36463 ||' OR NVL(requirement_date,SYSDATE-36500 ) = SYSDATE-36500 '
36464 ||' OR NVL(ITEM_NAME,'||''''||NULL_CHAR||''''||') '
36465 ||' = '||''''||NULL_CHAR||''''||')'
36466 ||' AND process_flag = '||G_IN_PROCESS
36467 ||' AND deleted_flag = '||SYS_NO
36468 ||' AND batch_id = :p_batch_id'
36469 ||' AND sr_instance_code = :v_instance_code';
36470
36471
36472
36473 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
36474
36475 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
36476
36477
36478 -- Set the message
36479
36480 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36481 (p_app_short_name => 'MSC',
36482 p_error_code => 'MSC_PP_INVALID_VALUE',
36483 p_message_text => lv_message_text,
36484 p_error_text => lv_error_text,
36485 p_token1 => 'COLUMN_NAME',
36486 p_token_value1 => 'ITEM_NAME');
36487
36488 IF lv_return <> 0 THEN
36489 RAISE ex_logging_err;
36490 END IF;
36491
36492 --Derive Inventory_item_id
36493 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
36494 (p_table_name => 'MSC_ST_SALES_ORDERS',
36495 p_item_col_name => 'ITEM_NAME',
36496 p_item_col_id => 'INVENTORY_ITEM_ID',
36497 p_instance_id => v_instance_id,
36498 p_instance_code => v_instance_code,
36499 p_error_text => lv_error_text,
36500 p_batch_id => p_batch_id,
36501 p_severity => G_SEV_ERROR,
36502 p_message_text => lv_message_text,
36503 p_debug => v_debug,
36504 p_row => lv_column_names);
36505
36506 IF lv_return <> 0 THEN
36507 RAISE ex_logging_err;
36508 END IF;
36509
36510 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36511 (p_app_short_name => 'MSC',
36512 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
36513 p_message_text => lv_message_text,
36514 p_error_text => lv_error_text,
36515 p_token1 => 'COLUMN_NAMES',
36516 p_token_value1 => 'ORIGINAL_ITEM,ITEM_NAME,'
36517 ||'RECIPROCAL_FLAG,SR_INSTANCE_CODE',
36518 p_token2 => 'MASTER_TABLE',
36519 p_token_value2 => 'MSC_ST_ITEM_SUBSTITUTES/MSC_ITEM_SUBSTITUTES',
36520 p_token3 => 'CHILD_TABLE' ,
36521 p_token_value3 => 'MSC_ST_SALES_ORDERS' );
36522
36523 IF lv_return <> 0 THEN
36524 RAISE ex_logging_err;
36525 END IF;
36526
36527 --Validates the product substitution effectivity and directionality rules.
36528
36529 UPDATE msc_st_sales_orders
36530 SET process_flag = G_ERROR_FLG,
36531 error_text = lv_message_text
36532 WHERE original_item_name is not null
36533 AND deleted_flag = SYS_NO
36534 AND NOT EXISTS(SELECT 1
36535 FROM msc_item_substitutes mis
36536 WHERE ((mis.reciprocal_flag = 1
36537 AND ((mis.lower_item_id = original_item_id
36538 AND mis.higher_item_id = inventory_item_id )
36539 OR (mis.higher_item_id = original_item_id
36540 AND mis.lower_item_id = inventory_item_id )))
36541 OR (mis.reciprocal_flag = 2
36542 AND mis.lower_item_id = original_item_id
36543 AND mis.higher_item_id = inventory_item_id ))
36544 AND nvl(mis.effective_date,sysdate) <=sysdate
36545 AND nvl(mis.disable_date,sysdate+1) > sysdate
36546 AND mis.sr_instance_id = v_instance_id
36547 AND mis.plan_id = -1
36548 UNION
36549 SELECT 1
36550 FROM msc_st_item_substitutes mss
36551 WHERE ((mss.reciprocal_flag = 1
36552 AND ((mss.lower_item_id = original_item_id
36553 AND mss.higher_item_id = inventory_item_id)
36554 OR (mss.higher_item_id = original_item_id
36555 AND mss.lower_item_id = inventory_item_id )))
36556 OR (mss.reciprocal_flag = 2
36557 AND mss.lower_item_id = original_item_id
36558 AND mss.higher_item_id = inventory_item_id ))
36559 AND nvl(effective_date,sysdate) <= sysdate
36560 AND nvl(disable_date,sysdate+1) > sysdate
36561 AND mss.sr_instance_id = v_instance_id
36562 AND mss.process_flag = G_VALID )
36563 AND process_flag = G_IN_PROCESS
36564 AND sr_instance_code = v_instance_code
36565 AND batch_id = p_batch_id;
36566
36567
36568 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36569 (p_app_short_name => 'MSC',
36570 p_error_code => 'MSC_PP_INVALID_VALUE',
36571 p_message_text => lv_message_text,
36572 p_error_text => lv_error_text,
36573 p_token1 => 'COLUMN_NAME',
36574 p_token_value1 => 'DEMAND_CLASS');
36575
36576 IF lv_return <> 0 THEN
36577 RAISE ex_logging_err;
36578 END IF;
36579
36580
36581 -- Validate Demand Class, if value provided it should exists
36582 -- in ODS or staging table
36583
36584 lv_return :=
36585 MSC_ST_UTIL.VALIDATE_DMD_CLASS(p_table_name => 'MSC_ST_SALES_ORDERS',
36586 p_dmd_class_column => 'DEMAND_CLASS',
36587 p_instance_id => v_instance_id,
36588 p_instance_code => v_instance_code,
36589 p_severity => G_SEV3_ERROR,
36590 p_message_text => lv_message_text,
36591 p_batch_id => p_batch_id,
36592 p_debug => v_debug,
36593 p_error_text => lv_error_text);
36594
36595 if(lv_return <> 0) then
36596 RAISE ex_logging_err;
36597 end if;
36598
36599 -- Set the error message
36600 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36601 (p_app_short_name => 'MSC',
36602 p_error_code => 'MSC_PP_COL_VAL_NULL_DEFAULT',
36603 p_message_text => lv_message_text,
36604 p_error_text => lv_error_text,
36605 p_token1 => 'COLUMN_NAME',
36606 p_token_value1 => 'COMPLETED_QUANTITY',
36607 p_token2 => 'DEFAULT_VALUE',
36608 p_token_value2 => G_COMPLETED_QUANTITY );
36609
36610 IF lv_return <> 0 THEN
36611 RAISE ex_logging_err;
36612 END IF;
36613
36614 -- Default completed_quantity
36615
36616 lv_where_str :=
36617 ' AND NVL(completed_quantity,'||NULL_VALUE||')'
36618 ||' = '||NULL_VALUE;
36619
36620 lv_return := MSC_ST_UTIL.LOG_ERROR
36621 (p_table_name => 'MSC_ST_SALES_ORDERS',
36622 p_instance_code => v_instance_code,
36623 p_row => lv_column_names,
36624 p_severity => G_SEV_WARNING,
36625 p_message_text => lv_message_text,
36626 p_error_text => lv_error_text,
36627 p_batch_id => p_batch_id,
36628 p_where_str => lv_where_str,
36629 p_col_name => 'COMPLETED_QUANTITY',
36630 p_debug => v_debug,
36631 p_default_value => G_COMPLETED_QUANTITY);
36632
36633 IF lv_return <> 0 THEN
36634 RAISE ex_logging_err;
36635 END IF;
36636
36637 -- Set the error message
36638 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36639 (p_app_short_name => 'MSC',
36640 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
36641 p_message_text => lv_message_text,
36642 p_error_text => lv_error_text,
36643 p_token1 => 'COLUMN_NAME',
36644 p_token_value1 => 'DEMAND_SOURCE_TYPE',
36645 p_token2 => 'DEFAULT_VALUE',
36646 p_token_value2 => G_SO_DEMAND_SOURCE_TYPE );
36647
36648 IF lv_return <> 0 THEN
36649 RAISE ex_logging_err;
36650 END IF;
36651
36652 -- Default demand_source_type
36653
36654 lv_where_str :=
36655 ' AND NVL(demand_source_type ,'||NULL_VALUE||') NOT IN (2,8) '
36656 ||' AND deleted_flag = '||SYS_NO;
36657
36658 lv_return := MSC_ST_UTIL.LOG_ERROR
36659 (p_table_name => 'MSC_ST_SALES_ORDERS',
36660 p_instance_code => v_instance_code,
36661 p_row => lv_column_names,
36662 p_severity => G_SEV_WARNING,
36663 p_message_text => lv_message_text,
36664 p_error_text => lv_error_text,
36665 p_batch_id => p_batch_id,
36666 p_where_str => lv_where_str,
36667 p_col_name => 'DEMAND_SOURCE_TYPE',
36668 p_debug => v_debug,
36669 p_default_value => G_SO_DEMAND_SOURCE_TYPE);
36670
36671 IF lv_return <> 0 THEN
36672 RAISE ex_logging_err;
36673 END IF;
36674
36675 -- Set the error message
36676 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36677 (p_app_short_name => 'MSC',
36678 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
36679 p_message_text => lv_message_text,
36680 p_error_text => lv_error_text,
36681 p_token1 => 'COLUMN_NAME',
36682 p_token_value1 => 'AVAILABLE_TO_MRP',
36683 p_token2 => 'DEFAULT_VALUE',
36684 p_token_value2 => G_AVAILABLE_TO_MRP);
36685
36686 IF lv_return <> 0 THEN
36687 RAISE ex_logging_err;
36688 END IF;
36689
36690 -- Default available_to_mrp
36691
36692 lv_where_str :=
36693 ' AND NVL(available_to_mrp ,'||''''||NULL_CHAR||''''||') '
36694 ||' NOT IN (''Y'', ''N'')'
36695 ||' AND deleted_flag = '||SYS_NO;
36696
36697
36698 lv_return := MSC_ST_UTIL.LOG_ERROR
36699 (p_table_name => 'MSC_ST_SALES_ORDERS',
36700 p_instance_code => v_instance_code,
36701 p_row => lv_column_names,
36702 p_severity => G_SEV_WARNING,
36703 p_message_text => lv_message_text,
36704 p_error_text => lv_error_text,
36705 p_batch_id => p_batch_id,
36706 p_where_str => lv_where_str,
36707 p_col_name => 'AVAILABLE_TO_MRP',
36708 p_debug => v_debug,
36709 p_default_value => '''Y''' );
36710
36711 IF lv_return <> 0 THEN
36712 RAISE ex_logging_err;
36713 END IF;
36714
36715 -- Set the error message
36716 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36717 (p_app_short_name => 'MSC',
36718 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
36719 p_message_text => lv_message_text,
36720 p_error_text => lv_error_text,
36721 p_token1 => 'COLUMN_NAME',
36722 p_token_value1 => 'CTO_FLAG',
36723 p_token2 => 'DEFAULT_VALUE',
36724 p_token_value2 => G_CTO_FLAG);
36725
36726 IF lv_return <> 0 THEN
36727 RAISE ex_logging_err;
36728 END IF;
36729
36730 -- Default cto_flag
36731
36732 lv_where_str :=
36733 ' AND NVL(cto_flag,'||NULL_VALUE||') NOT IN (1,2)' ;
36734
36735 lv_return := MSC_ST_UTIL.LOG_ERROR
36736 (p_table_name => 'MSC_ST_SALES_ORDERS',
36737 p_instance_code => v_instance_code,
36738 p_row => lv_column_names,
36739 p_severity => G_SEV_WARNING,
36740 p_message_text => lv_message_text,
36741 p_error_text => lv_error_text,
36742 p_batch_id => p_batch_id,
36743 p_where_str => lv_where_str,
36744 p_col_name => 'CTO_FLAG',
36745 p_debug => v_debug,
36746 p_default_value => G_CTO_FLAG);
36747
36748 IF lv_return <> 0 THEN
36749 RAISE ex_logging_err;
36750 END IF;
36751
36752 -- Set the error message
36753 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36754 (p_app_short_name => 'MSC',
36755 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
36756 p_message_text => lv_message_text,
36757 p_error_text => lv_error_text,
36758 p_token1 => 'COLUMN_NAME',
36759 p_token_value1 => 'FORECAST_VISIBLE',
36760 p_token2 => 'DEFAULT_VALUE',
36761 p_token_value2 => G_FORECAST_VISIBLE);
36762
36763 IF lv_return <> 0 THEN
36764 RAISE ex_logging_err;
36765 END IF;
36766
36767 -- Default forecast_visible
36768
36769 lv_where_str :=
36770 ' AND NVL(forecast_visible ,'||''''||NULL_CHAR||''''||')'
36771 ||' NOT IN (''Y'', ''N'') AND deleted_flag = '||SYS_NO ;
36772
36773 lv_return := MSC_ST_UTIL.LOG_ERROR
36774 (p_table_name => 'MSC_ST_SALES_ORDERS',
36775 p_instance_code => v_instance_code,
36776 p_row => lv_column_names,
36777 p_severity => G_SEV_WARNING,
36778 p_message_text => lv_message_text,
36779 p_error_text =>lv_error_text,
36780 p_batch_id => p_batch_id,
36781 p_where_str => lv_where_str,
36782 p_col_name => 'FORECAST_VISIBLE',
36783 p_debug => v_debug,
36784 p_default_value => '''Y''');
36785
36786 IF lv_return <> 0 THEN
36787 RAISE ex_logging_err;
36788 END IF;
36789
36790 -- Set the error message
36791 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36792 (p_app_short_name => 'MSC',
36793 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
36794 p_message_text => lv_message_text,
36795 p_error_text => lv_error_text,
36796 p_token1 => 'COLUMN_NAME',
36797 p_token_value1 => 'DEMAND_VISIBLE',
36798 p_token2 => 'DEFAULT_VALUE',
36799 p_token_value2 => G_DEMAND_VISIBLE);
36800
36801 IF lv_return <> 0 THEN
36802 RAISE ex_logging_err;
36803 END IF;
36804
36805 -- Default demand_visible
36806
36807 lv_where_str :=
36808 ' AND NVL(demand_visible,'||''''||NULL_CHAR||''''||')'
36809 ||' NOT IN (''Y'', ''N'') AND deleted_flag = '||SYS_NO ;
36810
36811 lv_return := MSC_ST_UTIL.LOG_ERROR
36812 (p_table_name => 'MSC_ST_SALES_ORDERS',
36813 p_instance_code => v_instance_code,
36814 p_row => lv_column_names,
36815 p_severity => G_SEV_WARNING,
36816 p_message_text => lv_message_text,
36817 p_error_text => lv_error_text,
36818 p_batch_id => p_batch_id,
36819 p_where_str => lv_where_str,
36820 p_col_name => 'DEMAND_VISIBLE',
36821 p_debug => v_debug,
36822 p_default_value => '''Y''');
36823
36824 IF lv_return <> 0 THEN
36825 RAISE ex_logging_err;
36826 END IF;
36827
36828
36829 -- Set the message
36830
36831 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36832 (p_app_short_name => 'MSC',
36833 p_error_code => 'MSC_PP_INVALID_VALUE',
36834 p_message_text => lv_message_text,
36835 p_error_text => lv_error_text,
36836 p_token1 => 'COLUMN_NAME',
36837 p_token_value1 => 'CUSTOMER_NAME');
36838
36839 IF lv_return <> 0 THEN
36840 RAISE ex_logging_err;
36841 END IF;
36842
36843 -- Derive customer_id
36844
36845 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
36846 (p_table_name => 'MSC_ST_SALES_ORDERS',
36847 p_org_partner_name => 'CUSTOMER_NAME',
36848 p_org_partner_id => 'CUSTOMER_ID',
36849 p_instance_code => v_instance_code,
36850 p_partner_type => G_CUSTOMER,
36851 p_error_text => lv_error_text,
36852 p_batch_id => p_batch_id,
36853 p_severity => G_SEV3_ERROR,
36854 p_message_text => lv_message_text,
36855 p_debug => v_debug,
36856 p_row => lv_column_names);
36857
36858 IF lv_return <> 0 THEN
36859 RAISE ex_logging_err;
36860 END IF;
36861
36862 -- Set the message
36863
36864 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36865 (p_app_short_name => 'MSC',
36866 p_error_code => 'MSC_PP_INVALID_VALUE',
36867 p_message_text => lv_message_text,
36868 p_error_text => lv_error_text,
36869 p_token1 => 'COLUMN_NAME',
36870 p_token_value1 => 'BILL_TO_SITE_CODE');
36871
36872 IF lv_return <> 0 THEN
36873 RAISE ex_logging_err;
36874 END IF;
36875
36876 -- Derive bill_to_site_id
36877 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
36878 (p_table_name => 'MSC_ST_SALES_ORDERS',
36879 p_partner_name => 'CUSTOMER_NAME',
36880 p_partner_site_code => 'BILL_TO_SITE_CODE',
36881 p_partner_site_id => 'BILL_TO_SITE_USE_ID',
36882 p_instance_code => v_instance_code,
36883 p_partner_type => G_CUSTOMER,
36884 p_error_text => lv_error_text,
36885 p_batch_id => p_batch_id,
36886 p_severity => G_SEV3_ERROR,
36887 p_message_text => lv_message_text,
36888 p_debug => v_debug,
36889 p_row => lv_column_names);
36890
36891 IF lv_return <> 0 THEN
36892 RAISE ex_logging_err;
36893 END IF;
36894
36895 -- Set the message
36896
36897 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36898 (p_app_short_name => 'MSC',
36899 p_error_code => 'MSC_PP_INVALID_VALUE',
36900 p_message_text => lv_message_text,
36901 p_error_text => lv_error_text,
36902 p_token1 => 'COLUMN_NAME',
36903 p_token_value1 => 'SHIP_TO_SITE_CODE');
36904
36905 IF lv_return <> 0 THEN
36906 RAISE ex_logging_err;
36907 END IF;
36908
36909 -- Derive ship_to_site_id
36910 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
36911 (p_table_name => 'MSC_ST_SALES_ORDERS',
36912 p_partner_name => 'CUSTOMER_NAME',
36913 p_partner_site_code => 'SHIP_TO_SITE_CODE',
36914 p_partner_site_id => 'SHIP_TO_SITE_USE_ID',
36915 p_instance_code => v_instance_code,
36916 p_partner_type => G_CUSTOMER,
36917 p_error_text => lv_error_text,
36918 p_batch_id => p_batch_id,
36919 p_severity => G_SEV3_ERROR,
36920 p_message_text => lv_message_text,
36921 p_debug => v_debug,
36922 p_row => lv_column_names);
36923
36924 IF lv_return <> 0 THEN
36925 RAISE ex_logging_err;
36926 END IF;
36927 -- Set the error message
36928 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36929 (p_app_short_name => 'MSC',
36930 p_error_code => 'MSC_PP_FK_REF_NOT_EXIST',
36931 p_message_text => lv_message_text,
36932 p_error_text => lv_error_text,
36933 p_token1 => 'COLUMN_NAMES',
36934 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
36935 ||'ORGANIZATION_CODE,PROJECT_NUMBER',
36936 p_token2 => 'MASTER_TABLE',
36937 p_token_value2 => 'MSC_ST_PROJECT_TASKS');
36938
36939 IF lv_return <> 0 THEN
36940 RAISE ex_logging_err;
36941 END IF;
36942
36943 --Derive Project Id.
36944 lv_return:= MSC_ST_UTIL.DERIVE_PROJ_TASK_ID
36945 (p_table_name => 'MSC_ST_SALES_ORDERS',
36946 p_proj_col_name => 'PROJECT_NUMBER',
36947 p_proj_task_col_id => 'PROJECT_ID',
36948 p_instance_code => v_instance_code,
36949 p_entity_name => 'PROJECT_ID',
36950 p_error_text => lv_error_text,
36951 p_batch_id => p_batch_id,
36952 p_severity => G_SEV_WARNING,
36953 p_message_text => lv_message_text,
36954 p_debug => v_debug,
36955 p_row => lv_column_names);
36956 IF lv_return<> 0 THEN
36957 RAISE ex_logging_err;
36958 END IF;
36959
36960 -- Set the error message
36961 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
36962 (p_app_short_name => 'MSC',
36963 p_error_code => 'MSC_PP_FK_REF_NOT_EXIST',
36964 p_message_text => lv_message_text,
36965 p_error_text => lv_error_text,
36966 p_token1 => 'COLUMN_NAMES',
36967 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
36968 ||'ORGANIZATION_CODE,PROJECT_NUMBER,'
36969 ||'TASK_NUMBER' ,
36970 p_token2 => 'MASTER_TABLE',
36971 p_token_value2 => 'MSC_ST_PROJECT_TASKS');
36972
36973 IF lv_return <> 0 THEN
36974 RAISE ex_logging_err;
36975 END IF;
36976
36977 --Derive Task Id.
36978 lv_return:= MSC_ST_UTIL.DERIVE_PROJ_TASK_ID
36979 (p_table_name => 'MSC_ST_SALES_ORDERS',
36980 p_proj_col_name => 'PROJECT_NUMBER',
36981 p_proj_task_col_id => 'TASK_ID',
36982 p_instance_code => v_instance_code,
36983 p_entity_name => 'TASK_ID',
36984 p_error_text => lv_error_text,
36985 p_task_col_name => 'TASK_NUMBER',
36986 p_batch_id => p_batch_id,
36987 p_severity => G_SEV_WARNING,
36988 p_message_text => lv_message_text,
36989 p_debug => v_debug,
36990 p_row => lv_column_names);
36991
36992 IF lv_return<> 0 THEN
36993 RAISE ex_logging_err;
36994 END IF;
36995 -- ordered_item_id is null in ERP collection
36996 /* v_sql_stmt := 09;
36997
36998 lv_sql_stmt :=
36999
37000 'UPDATE msc_st_sales_orders '
37001 ||' SET ordered_item_id = inventory_item_id'
37002 ||' WHERE sr_instance_code = :v_instance_code'
37003 ||' AND deleted_flag ='||SYS_NO
37004 ||' AND process_flag ='||G_IN_PROCESS
37005 ||' AND batch_id = :p_batch_id';
37006
37007
37008 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37009
37010 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,p_batch_id;
37011 */
37012 -- valid values for order_date_type_code are 'SHIP' and 'ARRIVE'
37013 -- Set the error message
37014
37015 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
37016 (p_app_short_name => 'MSC',
37017 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
37018 p_message_text => lv_message_text,
37019 p_error_text => lv_error_text,
37020 p_token1 => 'COLUMN_NAME',
37021 p_token_value1 => 'ORDER_DATE_TYPE_CODE',
37022 p_token2 => 'DEFAULT_VALUE',
37023 p_token_value2 => 1);
37024
37025 IF lv_return <> 0 THEN
37026 RAISE ex_logging_err;
37027 END IF;
37028
37029 lv_where_str :=
37030 ' AND NVL(order_date_type_code ,'||NULL_VALUE||') '
37031 ||' NOT IN (1,2)';
37032
37033 lv_return := MSC_ST_UTIL.LOG_ERROR
37034 (p_table_name => 'MSC_ST_SALES_ORDERS',
37035 p_instance_code => v_instance_code,
37036 p_row => lv_column_names,
37037 p_severity => G_SEV_WARNING,
37038 p_message_text => lv_message_text,
37039 p_error_text => lv_error_text,
37040 p_batch_id => p_batch_id,
37041 p_where_str => lv_where_str,
37042 p_col_name => 'ORDER_DATE_TYPE_CODE',
37043 p_debug => v_debug,
37044 p_default_value => 1);
37045
37046 IF lv_return <> 0 THEN
37047 RAISE ex_logging_err;
37048 END IF;
37049
37050 --Call to customised validation.
37051 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
37052 (ERRBUF => lv_error_text,
37053 RETCODE => lv_return,
37054 pBatchID => p_batch_id,
37055 pInstanceCode => v_instance_code,
37056 pEntityName => 'MSC_ST_SALES_ORDERS',
37057 pInstanceID => v_instance_id);
37058
37059 IF NVL(lv_return,0) <> 0 THEN
37060 RAISE ex_logging_err;
37061 END IF;
37062
37063 -- Generate demand_id
37064 -- 12620427
37065 IF (lv_retain_src_header_line_id = 2) THEN
37066
37067 OPEN c3(p_batch_id);
37068 FETCH c3 BULK COLLECT INTO lb_rowid ;
37069
37070 IF c3%ROWCOUNT > 0 THEN
37071 v_sql_stmt := 13;
37072 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
37073 UPDATE msc_st_sales_orders
37074 SET demand_id = msc_st_demand_id_s.NEXTVAL
37075 WHERE rowid = lb_rowid(j);
37076
37077 v_sql_stmt := 14;
37078 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
37079 INSERT INTO msc_local_id_demand
37080 (local_id,
37081 st_transaction_id,
37082 instance_id,
37083 entity_name,
37084 data_source_type,
37085 char1,
37086 char2,
37087 char3,
37088 char4,
37089 char5,
37090 number1,
37091 number2,
37092 SOURCE_DEMAND_SOURCE_HEADER_ID,
37093 SOURCE_ORG_ID,
37094 SOURCE_ORIGINAL_ITEM_ID,
37095 SOURCE_DEMAND_ID,
37096 SOURCE_INVENTORY_ITEM_ID,
37097 SOURCE_CUSTOMER_ID,
37098 SOURCE_BILL_TO_SITE_USE_ID,
37099 SOURCE_SHIP_TO_SITE_USE_ID,
37100 last_update_date,
37101 last_updated_by,
37102 creation_date,
37103 created_by)
37104 SELECT
37105 demand_id,
37106 st_transaction_id,
37107 v_instance_id,
37108 'DEMAND_ID',
37109 data_source_type,
37110 sr_instance_code,
37111 company_name,
37112 organization_code,
37113 sales_order_number,
37114 subinventory,
37115 line_num,
37116 decode(reservation_type,1,1,2,2,3,3,G_RESERVATION_TYPE),
37117 SOURCE_DEMAND_SOURCE_HEADER_ID,
37118 SOURCE_ORGANIZATION_ID,
37119 SOURCE_ORIGINAL_ITEM_ID,
37120 SOURCE_DEMAND_ID,
37121 SOURCE_INVENTORY_ITEM_ID,
37122 SOURCE_CUSTOMER_ID,
37123 SOURCE_BILL_TO_SITE_USE_ID,
37124 SOURCE_SHIP_TO_SITE_USE_ID,
37125 v_current_date,
37126 v_current_user,
37127 v_current_date,
37128 v_current_user
37129 FROM msc_st_sales_orders
37130 WHERE rowid = lb_rowid(j);
37131
37132 END IF;
37133 CLOSE c3 ;
37134
37135 lv_sql_stmt :=
37136
37137 'UPDATE msc_st_sales_orders '
37138 ||' SET demand_source_line = demand_id,'
37139 ||' atp_refresh_number = '||v_refresh_id
37140 ||' WHERE sr_instance_code = :v_instance_code'
37141 ||' AND deleted_flag ='||SYS_NO
37142 ||' AND process_flag ='||G_IN_PROCESS
37143 ||' AND batch_id = :p_batch_id';
37144
37145
37146 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37147
37148 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,p_batch_id;
37149
37150 ELSE
37151 -- 12620427
37152 -- Logic to retain the demand source line present
37153 -- in the staging table.
37154 -- Here, we will insert entity_type DEMAND_ID into
37155 -- msc_local_id_demand for sales order lines that are not present
37156 -- in the table already.
37157 -- Then, we will finally update msc_st_sales_orders.demand_id
37158 -- to be equal to demand_source_line
37159
37160 v_sql_stmt := 14.5;
37161
37162 lv_sql_stmt :=
37163
37164 'UPDATE msc_st_sales_orders '
37165 ||' SET demand_source_line = source_demand_source_line,'
37166 ||' demand_id = source_demand_source_line,'
37167 ||' atp_refresh_number = '||v_refresh_id
37168 ||' WHERE sr_instance_code = :v_instance_code'
37169 ||' AND deleted_flag ='||SYS_NO
37170 ||' AND process_flag ='||G_IN_PROCESS
37171 ||' AND batch_id = :p_batch_id';
37172
37173
37174 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37175
37176 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,p_batch_id;
37177
37178
37179 END IF; --for lv_retain_src_header_line_id = 2
37180
37181 -- Generate ship_set_id
37182
37183 v_sql_stmt := 15;
37184
37185 lv_sql_stmt :=
37186 'UPDATE msc_st_sales_orders mso '
37187 ||' SET ship_set_id = (SELECT local_id'
37188 ||' FROM msc_local_id_demand mlid'
37189 ||' WHERE mlid.char1 = mso.sr_instance_code'
37190 ||' AND NVL(mlid.char2,'||''''||NULL_CHAR||''''||') '
37191 ||' = NVL(mso.company_name,'||''''||NULL_CHAR||''''||') '
37192 ||' AND mlid.char3 = mso.organization_code'
37193 ||' AND mlid.char4 = mso.sales_order_number'
37194 ||' AND NVL(mlid.char5, '||''''||NULL_CHAR||''''||') '
37195 ||' = NVL(mso.ship_set_name,'||''''||NULL_CHAR||''''||') '
37196 ||' AND mlid.instance_id = '||v_instance_id
37197 ||' AND mlid.entity_name = ''SHIP_SET_ID'' )'
37198 ||' WHERE process_flag = '||G_IN_PROCESS
37199 ||' AND NVL(ship_set_id,'||NULL_VALUE||') = '||NULL_VALUE
37200 ||' AND batch_id = :p_batch_id '
37201 ||' AND sr_instance_code =:v_instance_code';
37202
37203
37204 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37205
37206 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
37207 OPEN c4(p_batch_id);
37208 FETCH c4 BULK COLLECT INTO lb_rowid ;
37209
37210 IF c4%ROWCOUNT > 0 THEN
37211 v_sql_stmt := 15.1;
37212 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
37213 UPDATE msc_st_sales_orders
37214 SET ship_set_id = msc_st_set_id_s.NEXTVAL
37215 WHERE rowid = lb_rowid(j)
37216 AND ship_set_id is null;
37217
37218 v_sql_stmt := 15.2;
37219 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
37220 INSERT INTO msc_local_id_demand
37221 (local_id,
37222 st_transaction_id,
37223 instance_id,
37224 entity_name,
37225 data_source_type,
37226 char1,
37227 char2,
37228 char3,
37229 char4,
37230 char5,
37231 last_update_date,
37232 last_updated_by,
37233 creation_date,
37234 created_by)
37235 SELECT
37236 ship_set_id,
37237 st_transaction_id,
37238 v_instance_id,
37239 'SHIP_SET_ID',
37240 data_source_type,
37241 sr_instance_code,
37242 company_name,
37243 organization_code,
37244 sales_order_number,
37245 ship_set_name,
37246 v_current_date,
37247 v_current_user,
37248 v_current_date,
37249 v_current_user
37250 FROM msc_st_sales_orders
37251 WHERE rowid = lb_rowid(j);
37252
37253 END IF;
37254 CLOSE c4;
37255
37256 -- Update ship_set_id
37257
37258 v_sql_stmt := 15.4;
37259 lv_sql_stmt :=
37260 'UPDATE msc_st_sales_orders mso '
37261 ||' SET ship_set_id = (SELECT local_id'
37262 ||' FROM msc_local_id_demand mlid'
37263 ||' WHERE mlid.char1 = mso.sr_instance_code'
37264 ||' AND NVL(mlid.char2,'||''''||NULL_CHAR||''''||') '
37265 ||' = NVL(mso.company_name,'||''''||NULL_CHAR||''''||') '
37266 ||' AND mlid.char3 = mso.organization_code'
37267 ||' AND mlid.char4 = mso.sales_order_number'
37268 ||' AND NVL(mlid.char5, '||''''||NULL_CHAR||''''||') '
37269 ||' = NVL(mso.ship_set_name,'||''''||NULL_CHAR||''''||') '
37270 ||' AND mlid.instance_id = '||v_instance_id
37271 ||' AND mlid.entity_name = ''SHIP_SET_ID'' )'
37272 ||' WHERE process_flag = '||G_IN_PROCESS
37273 ||' AND NVL(ship_set_id,'||NULL_VALUE||') = '||NULL_VALUE
37274 ||' AND batch_id = :p_batch_id '
37275 ||' AND sr_instance_code =:v_instance_code';
37276
37277
37278 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37279
37280 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
37281
37282
37283 -- Generate arrival_set_id
37284
37285 v_sql_stmt := 16;
37286
37287 lv_sql_stmt :=
37288 'UPDATE msc_st_sales_orders mso '
37289 ||' SET arrival_set_id = (SELECT local_id'
37290 ||' FROM msc_local_id_demand mlid'
37291 ||' WHERE mlid.char1 = mso.sr_instance_code'
37292 ||' AND NVL(mlid.char2,'||''''||NULL_CHAR||''''||') '
37293 ||' = NVL(mso.company_name,'||''''||NULL_CHAR||''''||') '
37294 ||' AND mlid.char3 = mso.organization_code'
37295 ||' AND mlid.char4 = mso.sales_order_number'
37296 ||' AND NVL(mlid.char5, '||''''||NULL_CHAR||''''||') '
37297 ||' = NVL(mso.arrival_set_name,'||''''||NULL_CHAR||''''||') '
37298 ||' AND mlid.instance_id = '||v_instance_id
37299 ||' AND mlid.entity_name = ''ARRIVAL_SET_ID'' )'
37300 ||' WHERE process_flag = '||G_IN_PROCESS
37301 ||' AND NVL(arrival_set_id,'||NULL_VALUE||') = '||NULL_VALUE
37302 ||' AND batch_id = :p_batch_id '
37303 ||' AND sr_instance_code =:v_instance_code';
37304
37305
37306 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37307
37308 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
37309 OPEN c5(p_batch_id);
37310 FETCH c5 BULK COLLECT INTO lb_rowid ;
37311
37312 IF c5%ROWCOUNT > 0 THEN
37313 v_sql_stmt := 16.1;
37314 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
37315 UPDATE msc_st_sales_orders
37316 SET arrival_set_id = msc_st_set_id_s.NEXTVAL
37317 WHERE rowid = lb_rowid(j)
37318 AND arrival_set_id is null;
37319
37320 v_sql_stmt := 16.2;
37321 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
37322 INSERT INTO msc_local_id_demand
37323 (local_id,
37324 st_transaction_id,
37325 instance_id,
37326 entity_name,
37327 data_source_type,
37328 char1,
37329 char2,
37330 char3,
37331 char4,
37332 char5,
37333 last_update_date,
37334 last_updated_by,
37335 creation_date,
37336 created_by)
37337 SELECT
37338 arrival_set_id,
37339 st_transaction_id,
37340 v_instance_id,
37341 'ARRIVAL_SET_ID',
37342 data_source_type,
37343 sr_instance_code,
37344 company_name,
37345 organization_code,
37346 sales_order_number,
37347 arrival_set_name,
37348 v_current_date,
37349 v_current_user,
37350 v_current_date,
37351 v_current_user
37352 FROM msc_st_sales_orders
37353 WHERE rowid = lb_rowid(j);
37354
37355 END IF;
37356 CLOSE c5;
37357
37358 -- Update arrival_set_id
37359
37360 v_sql_stmt := 16.4;
37361 lv_sql_stmt :=
37362 'UPDATE msc_st_sales_orders mso '
37363 ||' SET arrival_set_id = (SELECT local_id'
37364 ||' FROM msc_local_id_demand mlid'
37365 ||' WHERE mlid.char1 = mso.sr_instance_code'
37366 ||' AND NVL(mlid.char2,'||''''||NULL_CHAR||''''||') '
37367 ||' = NVL(mso.company_name,'||''''||NULL_CHAR||''''||') '
37368 ||' AND mlid.char3 = mso.organization_code'
37369 ||' AND mlid.char4 = mso.sales_order_number'
37370 ||' AND NVL(mlid.char5, '||''''||NULL_CHAR||''''||') '
37371 ||' = NVL(mso.arrival_set_name,'||''''||NULL_CHAR||''''||') '
37372 ||' AND mlid.instance_id = '||v_instance_id
37373 ||' AND mlid.entity_name = ''ARRIVAL_SET_ID'' )'
37374 ||' WHERE process_flag = '||G_IN_PROCESS
37375 ||' AND NVL(arrival_set_id,'||NULL_VALUE||') = '||NULL_VALUE
37376 ||' AND batch_id = :p_batch_id '
37377 ||' AND sr_instance_code =:v_instance_code';
37378
37379
37380 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37381
37382 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
37383
37384 -- populate row_type
37385
37386 v_sql_stmt := 17;
37387 lv_sql_stmt :=
37388 'UPDATE msc_st_sales_orders mso '
37389 ||' SET ROW_TYPE= decode(reservation_type,1,decode(AVAILABLE_TO_MRP,''N'',''3'',''1'')
37390 ,2,1
37391 ,3,1
37392 ,NULL)' -- resv tp already validated for 1,2,3 so this decode should never return NULL.
37393 ||' WHERE process_flag = '||G_IN_PROCESS
37394 ||' AND batch_id = :p_batch_id '
37395 ||' AND sr_instance_code =:v_instance_code';
37396
37397
37398 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37399
37400 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
37401
37402 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
37403 (p_table_name => 'MSC_ST_SALES_ORDERS',
37404 p_instance_id => v_instance_id,
37405 p_instance_code => v_instance_code,
37406 p_process_flag => G_VALID,
37407 p_error_text => lv_error_text,
37408 p_debug => v_debug,
37409 p_batch_id => p_batch_id);
37410
37411 IF lv_return <> 0 THEN
37412 RAISE ex_logging_err;
37413 END IF;
37414
37415 lv_return := MSC_ST_UTIL.LOG_ERROR
37416 (p_table_name => 'MSC_ST_SALES_ORDERS',
37417 p_instance_code => v_instance_code,
37418 p_row => lv_column_names,
37419 p_severity => G_SEV_ERROR,
37420 p_message_text => NULL,
37421 p_error_text => lv_error_text,
37422 p_debug => v_debug,
37423 p_batch_id => p_batch_id);
37424
37425 IF lv_return <> 0 THEN
37426 RAISE ex_logging_err;
37427 END IF;
37428
37429 COMMIT;
37430
37431 EXCEPTION
37432 WHEN too_many_rows THEN
37433 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_SALES_ORDER'||'('
37434 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
37435 ROLLBACK ;
37436 IF c_lock%ISOPEN THEN
37437 CLOSE c_lock;
37438 END IF;
37439
37440 WHEN ex_logging_err THEN
37441 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
37442
37443 ROLLBACK;
37444 IF c_lock%ISOPEN THEN
37445 CLOSE c_lock;
37446 END IF;
37447
37448 WHEN OTHERS THEN
37449 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_SALES_ORDER'||'('
37450 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
37451 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
37452
37453 ROLLBACK;
37454 IF c_lock%ISOPEN THEN
37455 CLOSE c_lock;
37456 END IF;
37457
37458 END LOAD_SALES_ORDER;
37459
37460 /*==========================================================================+
37461 | DESCRIPTION : This function performs the validation and loads the data |
37462 | for business object Hard Reservations |
37463 +==========================================================================*/
37464 PROCEDURE LOAD_RESERVATIONS IS
37465 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
37466 lb_rowid RowidTab; --bulk collects rowid
37467 lv_return NUMBER;
37468 lv_batch_id NUMBER;
37469 lv_error_text VARCHAR2(250);
37470 lv_where_str VARCHAR2(5000);
37471 lv_sql_stmt VARCHAR2(5000);
37472 lv_column_names VARCHAR2(5000); --stores concatenated column names
37473 lv_message_text msc_errors.error_text%TYPE;
37474
37475 ex_logging_err EXCEPTION;
37476
37477 CURSOR c1(p_batch_id NUMBER) IS
37478 SELECT rowid
37479 FROM msc_st_reservations
37480 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
37481 AND sr_instance_code = v_instance_code
37482 AND batch_id = p_batch_id;
37483
37484 BEGIN
37485
37486 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
37487 (p_app_short_name => 'MSC',
37488 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
37489 p_message_text => lv_message_text,
37490 p_error_text => lv_error_text);
37491
37492 IF lv_return <> 0 THEN
37493 RAISE ex_logging_err;
37494 END IF;
37495
37496 --Validation check for the table MSC_ST_RESERVATIONS
37497
37498 --Duplicate records check for the records whose source is other than XML
37499 --Different SQL is used because in XML we can identify the latest records
37500 --whereas in batch load we cannot.
37501
37502 v_sql_stmt := 01;
37503 lv_sql_stmt :=
37504 'UPDATE msc_st_reservations msr1 '
37505 ||' SET process_flag = '||G_ERROR_FLG||','
37506 ||' error_text = '||''''||lv_message_text||''''
37507 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_reservations msr2 '
37508 ||' WHERE msr2.sr_instance_code = msr1.sr_instance_code'
37509 ||' AND msr2.sales_order_number = msr1.sales_order_number'
37510 ||' AND msr2.line_num = msr1.line_num'
37511 ||' AND msr2.organization_code = msr1.organization_code'
37512 ||' AND NVL(msr2.company_name, '||''''||NULL_CHAR||''''||') = '
37513 ||' NVL(msr1.company_name, '||''''||NULL_CHAR||''''||')'
37514 ||' AND msr2.process_flag = msr1.process_flag'
37515 ||' AND NVL(msr2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
37516 ||' GROUP BY sr_instance_code, sales_order_number,line_num,'
37517 ||' organization_code,company_name '
37518 ||' HAVING COUNT(*) >1 )'
37519 ||' AND msr1.process_flag = '||G_IN_PROCESS
37520 ||' AND msr1.sr_instance_code = :v_instance_code'
37521 ||' AND msr1.reservation_type = 1'
37522 ||' AND NVL(msr1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
37523
37524
37525 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37526
37527 EXECUTE IMMEDIATE lv_sql_stmt
37528 USING v_instance_code;
37529
37530
37531 --Duplicate records check for the records whose source is XML
37532 v_sql_stmt := 02;
37533 lv_sql_stmt :=
37534 'UPDATE msc_st_reservations msr1 '
37535 ||' SET process_flag = '||G_ERROR_FLG||','
37536 ||' error_text = '||''''||lv_message_text||''''
37537 ||' WHERE message_id < ( SELECT max(message_id) '
37538 ||' FROM msc_st_reservations msr2'
37539 ||' WHERE msr2.sr_instance_code = msr1.sr_instance_code'
37540 ||' AND msr2.sales_order_number = msr1.sales_order_number'
37541 ||' AND msr2.line_num = msr1.line_num'
37542 ||' AND msr2.organization_code = msr1.organization_code'
37543 ||' AND NVL(msr2.company_name, '||''''||NULL_CHAR||''''||') = '
37544 ||' NVL(msr1.company_name, '||''''||NULL_CHAR||''''||')'
37545 ||' AND msr2.process_flag = msr1.process_flag'
37546 ||' AND msr2.reservation_type = msr1.reservation_type'
37547 ||' AND NVL(msr2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
37548 ||' AND msr1.process_flag = '||G_IN_PROCESS
37549 ||' AND msr1.sr_instance_code = :v_instance_code '
37550 ||' AND msr1.reservation_type = 1'
37551 ||' AND NVL(msr1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
37552
37553
37554 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37555
37556 EXECUTE IMMEDIATE lv_sql_stmt
37557 USING v_instance_code;
37558
37559
37560 /*duplicate records for reservation_type =3 */
37561 lv_sql_stmt :=
37562 'UPDATE msc_st_reservations msr1 '
37563 ||' SET process_flag = '||G_ERROR_FLG||','
37564 ||' error_text = '||''''||lv_message_text||''''
37565 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_reservations msr2 '
37566 ||' WHERE msr2.sr_instance_code = msr1.sr_instance_code'
37567 ||' AND msr2.supply_order_number = msr1.supply_order_number'
37568 ||' AND msr2.organization_code = msr1.organization_code'
37569 ||' AND msr2.process_flag = msr1.process_flag'
37570 ||' AND NVL(msr2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
37571 ||' AND msr2.reservation_type = msr1.reservation_type '
37572 ||' GROUP BY sr_instance_code, supply_order_number, '
37573 ||' organization_code '
37574 ||' HAVING COUNT(*) >1 )'
37575 ||' AND msr1.process_flag = '||G_IN_PROCESS
37576 ||' AND msr1.sr_instance_code = :v_instance_code'
37577 ||' AND msr1.reservation_type = 3'
37578 ||' AND NVL(msr1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
37579
37580
37581 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37582
37583 EXECUTE IMMEDIATE lv_sql_stmt
37584 USING v_instance_code;
37585
37586 /*duplicate records for reservation_type =4 */
37587 lv_sql_stmt :=
37588 'UPDATE msc_st_reservations msr1 '
37589 ||' SET process_flag = '||G_ERROR_FLG||','
37590 ||' error_text = '||''''||lv_message_text||''''
37591 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_reservations msr2 '
37592 ||' WHERE msr2.sr_instance_code = msr1.sr_instance_code'
37593 ||' AND msr2.supply_order_number = msr1.supply_order_number'
37594 ||' AND msr2.purch_line_num = msr1.purch_line_num'
37595 ||' AND msr2.organization_code = msr1.organization_code'
37596 ||' AND msr2.process_flag = msr1.process_flag'
37597 ||' AND NVL(msr2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
37598 ||' AND NVL(msr2.company_name, '||''''||NULL_CHAR||''''||') = '
37599 ||' NVL(msr1.company_name, '||''''||NULL_CHAR||''''||')'
37600 ||' AND msr2.reservation_type = msr1.reservation_type '
37601 ||' GROUP BY sr_instance_code, supply_order_number,purch_line_num,'
37602 ||' organization_code ,company_name'
37603 ||' HAVING COUNT(*) >1 )'
37604 ||' AND msr1.process_flag = '||G_IN_PROCESS
37605 ||' AND msr1.sr_instance_code = :v_instance_code'
37606 ||' AND msr1.reservation_type = 4'
37607 ||' AND NVL(msr1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
37608
37609
37610 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37611
37612 EXECUTE IMMEDIATE lv_sql_stmt
37613 USING v_instance_code;
37614
37615 /*duplicate records for reservation_type =5 */
37616 lv_sql_stmt :=
37617 'UPDATE msc_st_reservations msr1 '
37618 ||' SET process_flag = '||G_ERROR_FLG||','
37619 ||' error_text = '||''''||lv_message_text||''''
37620 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_reservations msr2 '
37621 ||' WHERE msr2.sr_instance_code = msr1.sr_instance_code'
37622 ||' AND msr2.supply_order_number = msr1.supply_order_number'
37623 ||' AND msr2.organization_code = msr1.organization_code'
37624 ||' AND msr2.supply_org_code = msr1.supply_org_code'
37625 ||' AND msr2.process_flag = msr1.process_flag'
37626 ||' AND NVL(msr2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
37627 ||' AND NVL(msr2.company_name, '||''''||NULL_CHAR||''''||') = '
37628 ||' NVL(msr1.company_name, '||''''||NULL_CHAR||''''||')'
37629 ||' AND msr2.reservation_type = msr1.reservation_type '
37630 ||' GROUP BY sr_instance_code, supply_order_number,'
37631 ||' organization_code ,supply_org_code,company_name'
37632 ||' HAVING COUNT(*) >1 )'
37633 ||' AND msr1.process_flag = '||G_IN_PROCESS
37634 ||' AND msr1.sr_instance_code = :v_instance_code'
37635 ||' AND msr1.reservation_type = 5'
37636 ||' AND NVL(msr1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
37637
37638
37639
37640
37641 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37642
37643 EXECUTE IMMEDIATE lv_sql_stmt
37644 USING v_instance_code;
37645
37646 /*duplicate records for reservation_type = 7 */
37647
37648 lv_sql_stmt :=
37649 'UPDATE msc_st_reservations msr1 '
37650 ||' SET process_flag = '||G_ERROR_FLG||','
37651 ||' error_text = '||''''||lv_message_text||''''
37652 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_reservations msr2 '
37653 ||' WHERE msr2.sr_instance_code = msr1.sr_instance_code'
37654 ||' AND msr2.supply_order_number = msr1.supply_order_number'
37655 ||' AND msr2.organization_code = msr1.organization_code'
37656 ||' AND msr2.process_flag = msr1.process_flag'
37657 ||' AND NVL(msr2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
37658 ||' AND NVL(msr2.company_name, '||''''||NULL_CHAR||''''||') = '
37659 ||' NVL(msr1.company_name, '||''''||NULL_CHAR||''''||')'
37660 ||' AND msr2.reservation_type = msr1.reservation_type '
37661 ||' GROUP BY sr_instance_code, supply_order_number,'
37662 ||' organization_code ,company_name'
37663 ||' HAVING COUNT(*) >1 )'
37664 ||' AND msr1.process_flag = '||G_IN_PROCESS
37665 ||' AND msr1.sr_instance_code = :v_instance_code'
37666 ||' AND msr1.reservation_type = 7'
37667 ||' AND NVL(msr1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
37668
37669
37670 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37671
37672 EXECUTE IMMEDIATE lv_sql_stmt
37673 USING v_instance_code;
37674
37675 lv_column_names :=
37676 ' ITEM_NAME ||''~''||'
37677 ||' ORGANIZATION_CODE ||''~''||'
37678 ||' SALES_ORDER_NUMBER ||''~''||'
37679 ||' LINE_NUM ||''~''||'
37680 ||' REQUIREMENT_DATE ||''~''||'
37681 ||' RESERVED_QUANTITY ||''~''||'
37682 ||' SUBINVENTORY ||''~''||'
37683 ||' DEMAND_CLASS ||''~''||'
37684 ||' PROJECT_NUMBER ||''~''||'
37685 ||' TASK_NUMBER ||''~''||'
37686 ||' PLANNING_GROUP ||''~''||'
37687 ||' COMPANY_NAME ||''~''||'
37688 ||' SR_INSTANCE_CODE ||''~''||'
37689 ||' DELETED_FLAG ';
37690
37691
37692 -- Dividing records in batches based on batchsize
37693 LOOP
37694 v_sql_stmt := 03;
37695 SELECT msc_st_batch_id_s.NEXTVAL
37696 INTO lv_batch_id
37697 FROM DUAL;
37698
37699 v_sql_stmt := 04;
37700 lv_sql_stmt :=
37701 'UPDATE msc_st_reservations '
37702 ||' SET batch_id = :lv_batch_id '
37703 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
37704 ||' AND sr_instance_code = :v_instance_code'
37705 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
37706 ||' AND rownum <= '||v_batch_size;
37707
37708
37709 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37710
37711 EXECUTE IMMEDIATE lv_sql_stmt
37712 USING lv_batch_id,
37713 v_instance_code;
37714
37715 EXIT WHEN SQL%NOTFOUND ;
37716
37717 OPEN c1(lv_batch_id);
37718 FETCH c1 BULK COLLECT INTO lb_rowid;
37719 CLOSE c1;
37720
37721 v_sql_stmt := 05;
37722 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
37723 UPDATE msc_st_reservations
37724 SET st_transaction_id = msc_st_demand_classes_s.NEXTVAL,
37725 refresh_id = v_refresh_id,
37726 last_update_date = v_current_date,
37727 last_updated_by = v_current_user,
37728 creation_date = v_current_date,
37729 created_by = v_current_user
37730 WHERE rowid = lb_rowid(j);
37731
37732
37733 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
37734 (p_app_short_name => 'MSC',
37735 p_error_code => 'MSC_PP_COL_VAL_NULL',
37736 p_message_text => lv_message_text,
37737 p_error_text => lv_error_text,
37738 p_token1 => 'COLUMN_NAME',
37739 p_token_value1 => 'SALE_ORDER_NUMBER OR LINE_NUM');
37740
37741 IF lv_return <> 0 THEN
37742 RAISE ex_logging_err;
37743 END IF;
37744
37745 v_sql_stmt := 04;
37746
37747 lv_sql_stmt :=
37748 'UPDATE msc_st_reservations '
37749 ||' SET process_flag = '||G_ERROR_FLG||','
37750 ||' error_text = '||''''||lv_message_text||''''
37751 ||' WHERE ( NVL(line_num,'||NULL_VALUE||') = '||NULL_VALUE
37752 ||' OR NVL(sales_order_number,'||''''||NULL_CHAR||''''||') '
37753 ||' = '||''''||NULL_CHAR||''''||')'
37754 ||' AND process_flag = '||G_IN_PROCESS
37755 ||' AND batch_id = :lv_batch_id'
37756 ||' AND reservation_type =1 '
37757 ||' AND sr_instance_code = :v_instance_code';
37758
37759
37760
37761 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37762
37763 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
37764
37765 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
37766 (p_app_short_name => 'MSC',
37767 p_error_code => 'MSC_PP_COL_VAL_NULL',
37768 p_message_text => lv_message_text,
37769 p_error_text => lv_error_text,
37770 p_token1 => 'COLUMN_NAME',
37771 p_token_value1 => 'SUPPLY_ORDER_NUMBER');
37772
37773 IF lv_return <> 0 THEN
37774 RAISE ex_logging_err;
37775 END IF;
37776
37777
37778 lv_sql_stmt :=
37779 'UPDATE msc_st_reservations '
37780 ||' SET process_flag = '||G_ERROR_FLG||','
37781 ||' error_text = '||''''||lv_message_text||''''
37782 ||' WHERE NVL(supply_order_number,'||''''||NULL_CHAR||''''||') = '||''''||NULL_CHAR||''''||''
37783 ||' AND process_flag = '||G_IN_PROCESS
37784 ||' AND batch_id = :lv_batch_id'
37785 ||' AND reservation_type in (3,4,5,7) '
37786 ||' AND sr_instance_code = :v_instance_code';
37787
37788
37789
37790 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37791
37792 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
37793
37794 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
37795 (p_app_short_name => 'MSC',
37796 p_error_code => 'MSC_PP_COL_VAL_NULL',
37797 p_message_text => lv_message_text,
37798 p_error_text => lv_error_text,
37799 p_token1 => 'COLUMN_NAME',
37800 p_token_value1 => 'PURCH_LINE_NUMBER');
37801
37802 IF lv_return <> 0 THEN
37803 RAISE ex_logging_err;
37804 END IF;
37805
37806
37807 lv_sql_stmt :=
37808 'UPDATE msc_st_reservations '
37809 ||' SET process_flag = '||G_ERROR_FLG||','
37810 ||' error_text = '||''''||lv_message_text||''''
37811 ||' WHERE NVL(purch_line_num,'||NULL_VALUE||') = '||NULL_VALUE
37812 ||' AND process_flag = '||G_IN_PROCESS
37813 ||' AND batch_id = :lv_batch_id'
37814 ||' AND reservation_type = 4 '
37815 ||' AND sr_instance_code = :v_instance_code';
37816
37817
37818
37819 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37820
37821 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
37822
37823 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
37824 (p_app_short_name => 'MSC',
37825 p_error_code => 'MSC_PP_COL_VAL_NULL',
37826 p_message_text => lv_message_text,
37827 p_error_text => lv_error_text,
37828 p_token1 => 'COLUMN_NAME',
37829 p_token_value1 => 'SUPPLY_ORG_CODE');
37830
37831 IF lv_return <> 0 THEN
37832 RAISE ex_logging_err;
37833 END IF;
37834
37835
37836 lv_sql_stmt :=
37837 'UPDATE msc_st_reservations '
37838 ||' SET process_flag = '||G_ERROR_FLG||','
37839 ||' error_text = '||''''||lv_message_text||''''
37840 ||' WHERE NVL(supply_org_code,'||''''||NULL_CHAR||''''||') = '||''''||NULL_CHAR||''''||''
37841 ||' AND process_flag = '||G_IN_PROCESS
37842 ||' AND batch_id = :lv_batch_id'
37843 ||' AND reservation_type = 5 '
37844 ||' AND sr_instance_code = :v_instance_code';
37845
37846
37847
37848 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37849
37850 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
37851
37852
37853 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
37854 (p_app_short_name => 'MSC',
37855 p_error_code => 'MSC_PP_INVALID_VALUE',
37856 p_message_text => lv_message_text,
37857 p_error_text => lv_error_text,
37858 p_token1 => 'COLUMN_NAME',
37859 p_token_value1 => 'DEMAND_CLASS');
37860
37861 IF lv_return <> 0 THEN
37862 RAISE ex_logging_err;
37863 END IF;
37864
37865
37866 -- Validate Demand Class, if value provided it should exists
37867 -- in ODS or staging table
37868
37869 lv_return :=
37870 MSC_ST_UTIL.VALIDATE_DMD_CLASS(p_table_name => 'MSC_ST_RESERVATIONS',
37871 p_dmd_class_column => 'DEMAND_CLASS',
37872 p_instance_id => v_instance_id,
37873 p_instance_code => v_instance_code,
37874 p_severity => G_SEV3_ERROR,
37875 p_message_text => lv_message_text,
37876 p_batch_id => lv_batch_id,
37877 p_debug => v_debug,
37878 p_error_text => lv_error_text);
37879
37880 if(lv_return <> 0) then
37881 RAISE ex_logging_err;
37882 end if;
37883
37884
37885
37886 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
37887 (p_app_short_name => 'MSC',
37888 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
37889 p_message_text => lv_message_text,
37890 p_error_text => lv_error_text,
37891 p_token1 => 'COLUMN_NAME',
37892 p_token_value1 => 'DELETED_FLAG',
37893 p_token2 => 'DEFAULT_VALUE',
37894 p_token_value2 => SYS_NO);
37895
37896 IF lv_return <> 0 THEN
37897 RAISE ex_logging_err;
37898 END IF;
37899
37900 -- Check DELETE_FLAG column has valid value or not and if not set it to SYS_NO
37901 -- Log error procedure inserts warning and also defaults the delete flag
37902
37903 lv_where_str := ' AND NVL(deleted_flag,'||NULL_VALUE||') '
37904 ||' NOT IN(1,2)';
37905
37906 lv_return := MSC_ST_UTIL.LOG_ERROR
37907 (p_table_name => 'MSC_ST_RESERVATIONS',
37908 p_instance_code => v_instance_code,
37909 p_row => lv_column_names,
37910 p_severity => G_SEV_WARNING,
37911 p_message_text => lv_message_text,
37912 p_error_text => lv_error_text,
37913 p_batch_id => lv_batch_id,
37914 p_where_str => lv_where_str,
37915 p_col_name => 'DELETED_FLAG',
37916 p_debug => v_debug,
37917 p_default_value => SYS_NO);
37918
37919 IF lv_return <> 0 THEN
37920 RAISE ex_logging_err;
37921 END IF;
37922
37923
37924
37925 lv_sql_stmt :=
37926 'UPDATE msc_st_reservations '
37927 ||' SET supply_source_type_id = 200,'
37928 ||' disposition_type =2 '
37929 ||' WHERE process_flag = '||G_IN_PROCESS
37930 ||' AND batch_id = :lv_batch_id'
37931 ||' AND reservation_type = 3 '
37932 ||' AND sr_instance_code = :v_instance_code';
37933
37934
37935
37936 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37937
37938 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
37939
37940 lv_sql_stmt :=
37941 'UPDATE msc_st_reservations '
37942 ||' SET supply_source_type_id = 7,'
37943 ||' disposition_type =200 '
37944 ||' WHERE process_flag = '||G_IN_PROCESS
37945 ||' AND batch_id = :lv_batch_id'
37946 ||' AND reservation_type = 4 '
37947 ||' AND sr_instance_code = :v_instance_code';
37948
37949
37950
37951 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37952
37953 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
37954
37955 lv_sql_stmt :=
37956 'UPDATE msc_st_reservations '
37957 ||' SET supply_source_type_id = 5,'
37958 ||' disposition_type =1 '
37959 ||' WHERE process_flag = '||G_IN_PROCESS
37960 ||' AND batch_id = :lv_batch_id'
37961 ||' AND reservation_type = 5 '
37962 ||' AND sr_instance_code = :v_instance_code';
37963
37964
37965
37966 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37967
37968 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
37969
37970 lv_sql_stmt :=
37971 'UPDATE msc_st_reservations '
37972 ||' SET supply_source_type_id = 1,'
37973 ||' disposition_type =2 '
37974 ||' WHERE process_flag = '||G_IN_PROCESS
37975 ||' AND batch_id = :lv_batch_id'
37976 ||' AND reservation_type = 7 '
37977 ||' AND sr_instance_code = :v_instance_code';
37978
37979
37980
37981 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
37982
37983 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
37984
37985 -- Check DISPOSITION_TYPE column has valid value or not and if not set it to 2
37986 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
37987 (p_app_short_name => 'MSC',
37988 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
37989 p_message_text => lv_message_text,
37990 p_error_text => lv_error_text,
37991 p_token1 => 'COLUMN_NAME',
37992 p_token_value1 => 'DISPOSITION_TYPE',
37993 p_token2 => 'DEFAULT_VALUE',
37994 p_token_value2 => G_DISPOSITION_TYPE);
37995
37996 IF lv_return <> 0 THEN
37997 RAISE ex_logging_err;
37998 END IF;
37999
38000 lv_where_str := ' AND NVL(disposition_type,'||NULL_VALUE||') '
38001 ||' <> 2 AND RESERVATION_TYPE =1';
38002
38003 lv_return := MSC_ST_UTIL.LOG_ERROR
38004 (p_table_name => 'MSC_ST_RESERVATIONS',
38005 p_instance_code => v_instance_code,
38006 p_row => lv_column_names,
38007 p_severity => G_SEV_WARNING,
38008 p_message_text => lv_message_text,
38009 p_error_text => lv_error_text,
38010 p_batch_id => lv_batch_id,
38011 p_where_str => lv_where_str,
38012 p_col_name => 'DISPOSITION_TYPE',
38013 p_debug => v_debug,
38014 p_default_value => G_DISPOSITION_TYPE);
38015
38016 IF lv_return <> 0 THEN
38017 RAISE ex_logging_err;
38018 END IF;
38019
38020 /* lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
38021 (p_app_short_name => 'MSC',
38022 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
38023 p_message_text => lv_message_text,
38024 p_error_text => lv_error_text,
38025 p_token1 => 'COLUMN_NAME',
38026 p_token_value1 => 'RESERVATION_TYPE',
38027 p_token2 => 'DEFAULT_VALUE',
38028 p_token_value2 => G_RESERVATION_TYPE);
38029
38030 IF lv_return <> 0 THEN
38031 RAISE ex_logging_err;
38032 END IF;
38033
38034 -- Check RESERVATION_TYPE column has valid value or not and if not set it to 2
38035
38036 lv_where_str := ' AND NVL(reservation_type,'||NULL_VALUE||') '
38037 ||' <> 1 ';
38038
38039 lv_return := MSC_ST_UTIL.LOG_ERROR
38040 (p_table_name => 'MSC_ST_RESERVATIONS',
38041 p_instance_code => v_instance_code,
38042 p_row => lv_column_names,
38043 p_severity => G_SEV_WARNING,
38044 p_message_text => lv_message_text,
38045 p_error_text => lv_error_text,
38046 p_batch_id => lv_batch_id,
38047 p_where_str => lv_where_str,
38048 p_col_name => 'RESERVATION_TYPE',
38049 p_debug => v_debug,
38050 p_default_value => G_RESERVATION_TYPE);
38051
38052 IF lv_return <> 0 THEN
38053 RAISE ex_logging_err;
38054 END IF;
38055 */
38056 -- Set the message
38057
38058 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
38059 (p_app_short_name => 'MSC',
38060 p_error_code => 'MSC_PP_INVALID_VALUE',
38061 p_message_text => lv_message_text,
38062 p_error_text => lv_error_text,
38063 p_token1 => 'COLUMN_NAME',
38064 p_token_value1 => 'ORGANIZATION_CODE');
38065
38066 IF lv_return <> 0 THEN
38067 RAISE ex_logging_err;
38068 END IF;
38069
38070 --Derive Organization_id
38071 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
38072 (p_table_name => 'MSC_ST_RESERVATIONS',
38073 p_org_partner_name => 'ORGANIZATION_CODE',
38074 p_org_partner_id => 'ORGANIZATION_ID',
38075 p_instance_code => v_instance_code,
38076 p_partner_type => G_ORGANIZATION,
38077 p_error_text => lv_error_text,
38078 p_batch_id => lv_batch_id,
38079 p_severity => G_SEV_ERROR,
38080 p_message_text => lv_message_text,
38081 p_debug => v_debug,
38082 p_row => lv_column_names);
38083
38084 IF lv_return <> 0 THEN
38085 RAISE ex_logging_err;
38086 END IF;
38087
38088
38089 -- Set the message
38090
38091 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
38092 (p_app_short_name => 'MSC',
38093 p_error_code => 'MSC_PP_INVALID_VALUE',
38094 p_message_text => lv_message_text,
38095 p_error_text => lv_error_text,
38096 p_token1 => 'COLUMN_NAME',
38097 p_token_value1 => 'ITEM_NAME');
38098
38099 IF lv_return <> 0 THEN
38100 RAISE ex_logging_err;
38101 END IF;
38102
38103 --Derive Inventory_item_id
38104 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
38105 (p_table_name => 'MSC_ST_RESERVATIONS',
38106 p_item_col_name => 'ITEM_NAME',
38107 p_item_col_id => 'INVENTORY_ITEM_ID',
38108 p_instance_id => v_instance_id,
38109 p_instance_code => v_instance_code,
38110 p_error_text => lv_error_text,
38111 p_batch_id => lv_batch_id,
38112 p_severity => G_SEV_ERROR,
38113 p_message_text => lv_message_text,
38114 p_debug => v_debug,
38115 p_row => lv_column_names);
38116
38117 IF lv_return <> 0 THEN
38118 RAISE ex_logging_err;
38119 END IF;
38120
38121 -- Derive dispostion id
38122
38123 v_sql_stmt := 5.0;
38124 lv_sql_stmt :=
38125 'UPDATE msc_st_reservations msr '
38126 ||' SET disposition_id = (SELECT local_id'
38127 ||' FROM msc_local_id_demand mlid'
38128 ||' WHERE mlid.char1 = msr.sr_instance_code'
38129 ||' AND NVL(mlid.char2,'||''''||NULL_CHAR||''''||') '
38130 ||' = NVL(msr.company_name,'||''''||NULL_CHAR||''''||') '
38131 ||' AND mlid.char3 = msr.organization_code'
38132 ||' AND mlid.char4 = msr.sales_order_number'
38133 ||' AND mlid.instance_id = '||v_instance_id
38134 ||' AND mlid.entity_name = ''SALES_ORDER_ID'' )'
38135 ||' WHERE process_flag = '||G_IN_PROCESS
38136 ||' AND NVL(disposition_id,'||NULL_VALUE||') = '||NULL_VALUE
38137 ||' AND (RESERVATION_TYPE in (1,2) or RESERVATION_TYPE is null) '
38138 ||' AND batch_id = :lv_batch_id '
38139 ||' AND sr_instance_code =:v_instance_code';
38140
38141
38142 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
38143
38144 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
38145
38146 /* derive disposition_id for reservation_type in (3,7) */
38147 v_sql_stmt := 5.1;
38148 lv_sql_stmt :=
38149 'UPDATE msc_st_reservations msr '
38150 ||' SET disposition_id = (SELECT local_id'
38151 ||' FROM msc_local_id_demand mlid'
38152 ||' WHERE mlid.char1 = msr.sr_instance_code'
38153 ||' AND NVL(mlid.char2,'||''''||NULL_CHAR||''''||') '
38154 ||' = NVL(msr.company_name,'||''''||NULL_CHAR||''''||') '
38155 ||' AND mlid.char3 = msr.organization_code'
38156 ||' AND mlid.char4 = msr.sales_order_number'
38157 ||' AND nvl(mlid.number2,'||NULL_VALUE||') = 1'
38158 ||' AND mlid.number1 = msr.line_num'
38159 ||' AND mlid.entity_name = ''DEMAND_ID'' )'
38160 ||' WHERE process_flag = '||G_IN_PROCESS
38161 ||' AND NVL(disposition_id,'||NULL_VALUE||') = '||NULL_VALUE
38162 ||' AND RESERVATION_TYPE in (3,7) '
38163 ||' AND batch_id = :lv_batch_id '
38164 ||' AND sr_instance_code =:v_instance_code';
38165
38166
38167 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
38168
38169 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
38170
38171 /* derive disposition_id for reservation_type =4 */
38172 v_sql_stmt := 5.2;
38173 lv_sql_stmt :=
38174 'UPDATE msc_st_reservations msr '
38175 ||' SET disposition_id =(SELECT local_id'
38176 ||' FROM msc_local_id_supply mls'
38177 ||' WHERE mls.char4 = msr.demand_order_number'
38178 ||' AND mls.char3 = msr.organization_code'
38179 ||' AND mls.char1 = msr.sr_instance_code'
38180 ||' AND mls.entity_name = ''REPAIR_NUMBER'' )'
38181 ||' WHERE process_flag = '||G_IN_PROCESS
38182 ||' AND NVL(disposition_id,'||NULL_VALUE||') = '||NULL_VALUE
38183 ||' AND RESERVATION_TYPE =4 '
38184 ||' AND batch_id = :lv_batch_id '
38185 ||' AND sr_instance_code =:v_instance_code';
38186
38187
38188 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
38189
38190 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
38191
38192 /* derive disposition_id for reservation_type =5 */
38193 v_sql_stmt := 5.3;
38194 lv_sql_stmt :=
38195 'UPDATE msc_st_reservations msr '
38196 ||' SET disposition_id =(SELECT local_id'
38197 ||' FROM msc_local_id_supply mls'
38198 ||' WHERE mls.char3 = msr.demand_order_number'
38199 ||' AND mls.number1 = 74' -- order_type
38200 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
38201 ||' NVL(msr.company_name,'||''''||NULL_CHAR||''''||') '
38202 ||' AND mls.char1 = msr.sr_instance_code'
38203 ||' AND mls.entity_name = ''DISPOSITION_ID'' ) '
38204 ||' WHERE process_flag = '||G_IN_PROCESS
38205 ||' AND NVL(disposition_id,'||NULL_VALUE||') = '||NULL_VALUE
38206 ||' AND RESERVATION_TYPE =5 '
38207 ||' AND batch_id = :lv_batch_id '
38208 ||' AND sr_instance_code =:v_instance_code';
38209
38210
38211 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
38212
38213 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
38214
38215
38216 /* derieve transaction_id for reservation_type =3 */
38217 v_sql_stmt := 5.5;
38218 lv_sql_stmt :=
38219 'UPDATE msc_st_reservations msr '
38220 ||' SET transaction_id =(SELECT local_id'
38221 ||' FROM msc_local_id_supply mls'
38222 ||' WHERE mls.char4 = msr.supply_order_number'
38223 ||' AND mls.char3 = msr.organization_code'
38224 ||' AND mls.char1 = msr.sr_instance_code'
38225 ||' AND mls.entity_name = ''REPAIR_NUMBER'' )'
38226 ||' WHERE process_flag = '||G_IN_PROCESS
38227 ||' AND NVL(transaction_id,'||NULL_VALUE||') = '||NULL_VALUE
38228 ||' AND RESERVATION_TYPE =3 '
38229 ||' AND batch_id = :lv_batch_id '
38230 ||' AND sr_instance_code =:v_instance_code';
38231
38232
38233 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
38234
38235 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
38236
38237 /* derieve transaction_id for reservation_type =4 */
38238 v_sql_stmt := 5.5;
38239 lv_sql_stmt :=
38240 'UPDATE msc_st_reservations msr '
38241 ||' SET transaction_id =(SELECT local_id'
38242 ||' FROM msc_local_id_supply mls'
38243 ||' WHERE mls.number1 = msr.purch_line_num'
38244 ||' AND mls.number2 =2' -- order_type
38245 ||' AND mls.char3 = msr.supply_order_number'
38246 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
38247 ||' NVL(msr.company_name,'||''''||NULL_CHAR||''''||') '
38248 ||' AND mls.char1 = msr.sr_instance_code'
38249 ||' AND mls.entity_name = ''PO_LINE_ID'')'
38250 ||' WHERE process_flag = '||G_IN_PROCESS
38251 ||' AND NVL(transaction_id,'||NULL_VALUE||') = '||NULL_VALUE
38252 ||' AND RESERVATION_TYPE =4 '
38253 ||' AND batch_id = :lv_batch_id '
38254 ||' AND sr_instance_code =:v_instance_code';
38255
38256
38257 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
38258
38259 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
38260
38261 /* derieve transaction_id for reservation_type =5 */
38262 v_sql_stmt := 5.6;
38263 lv_sql_stmt :=
38264 'UPDATE msc_st_reservations msr '
38265 ||' SET transaction_id =(SELECT local_id'
38266 ||' FROM msc_local_id_supply mls'
38267 ||' WHERE mls.char4 = msr.supply_order_number'
38268 ||' AND mls.char3 = msr.supply_org_code'
38269 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
38270 ||' NVL(msr.company_name,'||''''||NULL_CHAR||''''||') '
38271 ||' AND mls.char1 = msr.sr_instance_code'
38272 ||' AND mls.entity_name = ''WIP_ENTITY_ID'' )'
38273 ||' WHERE process_flag = '||G_IN_PROCESS
38274 ||' AND NVL(transaction_id,'||NULL_VALUE||') = '||NULL_VALUE
38275 ||' AND RESERVATION_TYPE =5 '
38276 ||' AND batch_id = :lv_batch_id '
38277 ||' AND sr_instance_code =:v_instance_code';
38278
38279
38280 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
38281
38282 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
38283
38284 /* derieve transaction_id for reservation_type =7*/
38285 v_sql_stmt := 5.6;
38286 lv_sql_stmt :=
38287 'UPDATE msc_st_reservations msr '
38288 ||' SET transaction_id =(SELECT local_id'
38289 ||' FROM msc_local_id_supply mls'
38290 ||' WHERE mls.char3 = msr.supply_order_number'
38291 ||' AND mls.number1 = 74' -- order_type
38292 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
38293 ||' NVL(msr.company_name,'||''''||NULL_CHAR||''''||') '
38294 ||' AND mls.char1 = msr.sr_instance_code'
38295 ||' AND mls.entity_name = ''DISPOSITION_ID'' ) '
38296 ||' WHERE process_flag = '||G_IN_PROCESS
38297 ||' AND NVL(transaction_id,'||NULL_VALUE||') = '||NULL_VALUE
38298 ||' AND RESERVATION_TYPE =7'
38299 ||' AND batch_id = :lv_batch_id '
38300 ||' AND sr_instance_code =:v_instance_code';
38301
38302
38303 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
38304
38305 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
38306
38307 -- Derive parent_demand_id
38308
38309 v_sql_stmt := 06;
38310 lv_sql_stmt :=
38311 'UPDATE msc_st_reservations msr '
38312 ||' SET parent_demand_id = (SELECT local_id'
38313 ||' FROM msc_local_id_demand mlid'
38314 ||' WHERE mlid.char1 = msr.sr_instance_code'
38315 ||' AND NVL(mlid.char2,'||''''||NULL_CHAR||''''||') '
38316 ||' = NVL(msr.company_name,'||''''||NULL_CHAR||''''||') '
38317 ||' AND mlid.char3 = msr.organization_code'
38318 ||' AND mlid.char4 = msr.sales_order_number'
38319 ||' AND nvl(mlid.number2,'||NULL_VALUE||') = nvl(msr.reservation_type,'||NULL_VALUE||')'
38320 ||' AND NVL(mlid.char5,'||''''||NULL_CHAR||''''||') '
38321 ||' = NVL(msr.SUBINVENTORY,'||''''||NULL_CHAR||''''||') '
38322 ||' AND mlid.number1 = msr.line_num'
38323 ||' AND mlid.entity_name = ''DEMAND_ID'' )'
38324 ||' WHERE process_flag ='||G_IN_PROCESS
38325 ||' AND batch_id = :lv_batch_id '
38326 ||' AND (RESERVATION_TYPE in (1,2) or RESERVATION_TYPE is null) '
38327 ||' AND sr_instance_code =:v_instance_code';
38328
38329
38330
38331 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
38332
38333 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
38334
38335 -- Error out the records if any parent_demand_id or dispostion id
38336 -- derivation fails
38337
38338 -- Set the error message
38339 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
38340 (p_app_short_name => 'MSC',
38341 p_error_code => 'MSC_PP_FK_REF_NOT_EXIST',
38342 p_message_text => lv_message_text,
38343 p_error_text => lv_error_text,
38344 p_token1 => 'COLUMN_NAMES',
38345 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
38346 ||'ORGANIZATION_CODE,SALES_ORDER_NUMBER'
38347 ||' LINE_NUM',
38348 p_token2 => 'MASTER_TABLE');
38349
38350 IF lv_return <> 0 THEN
38351 RAISE ex_logging_err;
38352 END IF;
38353
38354 v_sql_stmt := 07;
38355
38356 lv_sql_stmt :=
38357 'UPDATE msc_st_reservations '
38358 ||' SET process_flag ='||G_ERROR_FLG||','
38359 ||' error_text = '||''''||lv_message_text||''''
38360 ||' WHERE (NVL(disposition_id,'||NULL_VALUE||') = '||NULL_VALUE
38361 ||' OR NVL(parent_demand_id,'||NULL_VALUE||') = '||NULL_VALUE||')'
38362 ||' AND process_flag ='||G_IN_PROCESS
38363 ||' AND batch_id = :lv_batch_id '
38364 ||' AND (RESERVATION_TYPE in (1,2) or RESERVATION_TYPE is null) '
38365 ||' AND sr_instance_code =:v_instance_code';
38366
38367
38368 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
38369
38370 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
38371
38372 v_sql_stmt := 07.1;
38373 lv_sql_stmt :=
38374 'UPDATE msc_st_reservations '
38375 ||' SET process_flag ='||G_ERROR_FLG||','
38376 ||' error_text = '||''''||lv_message_text||''''
38377 ||' WHERE (NVL(disposition_id,'||NULL_VALUE||') = '||NULL_VALUE
38378 ||' OR NVL(transaction_id,'||NULL_VALUE||') = '||NULL_VALUE||')'
38379 ||' AND process_flag ='||G_IN_PROCESS
38380 ||' AND batch_id = :lv_batch_id '
38381 ||' AND RESERVATION_TYPE in (3,4,5,7) '
38382 ||' AND sr_instance_code =:v_instance_code';
38383
38384
38385 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
38386
38387 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
38388
38389 -- Update transaction_id by parent_demand_id
38390
38391 v_sql_stmt := 07;
38392
38393 lv_sql_stmt :=
38394 'UPDATE msc_st_reservations '
38395 ||' SET transaction_id = parent_demand_id'
38396 ||' WHERE NVL(parent_demand_id,'||NULL_VALUE||') <> '||NULL_VALUE
38397 ||' AND process_flag ='||G_IN_PROCESS
38398 ||' AND batch_id = :lv_batch_id '
38399 ||' AND (RESERVATION_TYPE in (1,2) or RESERVATION_TYPE is null) '
38400 ||' AND sr_instance_code =:v_instance_code';
38401
38402
38403 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
38404
38405 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
38406
38407
38408
38409 -- Set the error message
38410 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
38411 (p_app_short_name => 'MSC',
38412 p_error_code => 'MSC_PP_FK_REF_NOT_EXIST',
38413 p_message_text => lv_message_text,
38414 p_error_text => lv_error_text,
38415 p_token1 => 'COLUMN_NAMES',
38416 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
38417 ||'ORGANIZATION_CODE,PROJECT_NUMBER',
38418 p_token2 => 'MASTER_TABLE');
38419
38420 IF lv_return <> 0 THEN
38421 RAISE ex_logging_err;
38422 END IF;
38423
38424 --Derive Project Id.
38425 lv_return:= MSC_ST_UTIL.DERIVE_PROJ_TASK_ID
38426 (p_table_name => 'MSC_ST_RESERVATIONS',
38427 p_proj_col_name => 'PROJECT_NUMBER',
38428 p_proj_task_col_id => 'PROJECT_ID',
38429 p_instance_code => v_instance_code,
38430 p_entity_name => 'PROJECT_ID',
38431 p_error_text => lv_error_text,
38432 p_batch_id => lv_batch_id,
38433 p_severity => G_SEV_WARNING,
38434 p_message_text => lv_message_text,
38435 p_debug => v_debug,
38436 p_row => lv_column_names);
38437 IF lv_return<> 0 THEN
38438 RAISE ex_logging_err;
38439 END IF;
38440
38441 -- Set the error message
38442 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
38443 (p_app_short_name => 'MSC',
38444 p_error_code => 'MSC_PP_FK_REF_NOT_EXIST',
38445 p_message_text => lv_message_text,
38446 p_error_text => lv_error_text,
38447 p_token1 => 'COLUMN_NAMES',
38448 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
38449 ||'ORGANIZATION_CODE,PROJECT_NUMBER'
38450 ||'TASK_NUMBER' ,
38451 p_token2 => 'MASTER_TABLE',
38452 p_token_value2 => 'MSC_ST_PROJECT_TASKS');
38453
38454 IF lv_return <> 0 THEN
38455 RAISE ex_logging_err;
38456 END IF;
38457
38458 --Derive Task Id.
38459 lv_return:= MSC_ST_UTIL.DERIVE_PROJ_TASK_ID
38460 (p_table_name => 'MSC_ST_RESERVATIONS',
38461 p_proj_col_name => 'PROJECT_NUMBER',
38462 p_proj_task_col_id => 'TASK_ID',
38463 p_instance_code => v_instance_code,
38464 p_entity_name => 'TASK_ID',
38465 p_error_text => lv_error_text,
38466 p_task_col_name => 'TASK_NUMBER',
38467 p_batch_id => lv_batch_id,
38468 p_severity => G_SEV_WARNING,
38469 p_message_text => lv_message_text,
38470 p_debug => v_debug,
38471 p_row => lv_column_names);
38472
38473 IF lv_return<> 0 THEN
38474 RAISE ex_logging_err;
38475 END IF;
38476
38477
38478
38479 --Call to customised validation.
38480 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
38481 (ERRBUF => lv_error_text,
38482 RETCODE => lv_return,
38483 pBatchID => lv_batch_id,
38484 pInstanceCode => v_instance_code,
38485 pEntityName => 'MSC_ST_RESERVATIONS',
38486 pInstanceID => v_instance_id);
38487
38488 IF NVL(lv_return,0) <> 0 THEN
38489 RAISE ex_logging_err;
38490 END IF;
38491
38492
38493 -- Set the process flag as Valid and populate instance_id
38494 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
38495 (p_table_name => 'MSC_ST_RESERVATIONS',
38496 p_instance_id => v_instance_id,
38497 p_instance_code => v_instance_code,
38498 p_process_flag => G_VALID,
38499 p_error_text => lv_error_text,
38500 p_debug => v_debug,
38501 p_batch_id => lv_batch_id);
38502
38503 IF lv_return <> 0 THEN
38504 RAISE ex_logging_err;
38505 END IF;
38506
38507 -- At the end calling the LOG_ERROR for logging all
38508 -- errored out records.
38509
38510 lv_return := MSC_ST_UTIL.LOG_ERROR
38511 (p_table_name => 'MSC_ST_RESERVATIONS',
38512 p_instance_code => v_instance_code,
38513 p_row => lv_column_names,
38514 p_severity => G_SEV_ERROR,
38515 p_message_text => NULL,
38516 p_error_text => lv_error_text,
38517 p_debug => v_debug,
38518 p_batch_id => lv_batch_id );
38519
38520 IF lv_return <> 0 THEN
38521 RAISE ex_logging_err;
38522 END IF;
38523
38524 COMMIT;
38525
38526 END LOOP;
38527
38528 EXCEPTION
38529
38530 WHEN too_many_rows THEN
38531 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_RESRVATIONS'||'('
38532 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
38533 ROLLBACK ;
38534
38535 WHEN ex_logging_err THEN
38536 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
38537
38538 ROLLBACK;
38539
38540 WHEN OTHERS THEN
38541 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_RESERVATIONS '||'('
38542 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
38543 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
38544
38545 ROLLBACK;
38546
38547 END LOAD_RESERVATIONS ;
38548
38549 /*==========================================================================+
38550 | DESCRIPTION : This procedure is called for validating demand related |
38551 | records from the msc_st_demands table. The following |
38552 | types are considered for the validation. |
38553 | Demand origination Origination Type |
38554 | ------------------------------------------------- |
38555 | MDS Demand 8 |
38556 | Forecast Demand 29 |
38557 | Forecast MDS 7 |
38558 +==========================================================================*/
38559 PROCEDURE LOAD_MDS_FORECAST (p_batch_id IN NUMBER ) IS
38560 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
38561 lb_rowid RowidTab;
38562
38563 lv_column_names VARCHAR2(5000); -- Stores cocatenated column names
38564 lv_return NUMBER;
38565 lv_error_text VARCHAR2(250);
38566 lv_where_str VARCHAR2(5000);
38567 lv_sql_stmt VARCHAR2(5000);
38568 lv_cursor_stmt VARCHAR2(5000);
38569 lv_message_text msc_errors.error_text%TYPE;
38570
38571 ex_logging_err EXCEPTION;
38572
38573 CURSOR c1(p_batch_id NUMBER) IS
38574 SELECT rowid
38575 FROM msc_st_demands
38576 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
38577 AND origination_type IN (7,8,29)
38578 AND batch_id = p_batch_id
38579 AND sr_instance_code = v_instance_code ;
38580
38581 CURSOR c2(p_batch_id NUMBER) IS
38582 SELECT rowid
38583 FROM msc_st_demands
38584 WHERE process_flag = G_IN_PROCESS
38585 AND sr_instance_code = v_instance_code
38586 AND batch_id = p_batch_id
38587 AND NVL(disposition_id,NULL_VALUE) = NULL_VALUE
38588 AND origination_type in(7, 8)
38589 AND deleted_flag = SYS_NO;
38590
38591 CURSOR c3(p_batch_id NUMBER) IS
38592 SELECT rowid
38593 FROM msc_st_demands
38594 WHERE process_flag = G_IN_PROCESS
38595 AND sr_instance_code = v_instance_code
38596 AND batch_id = p_batch_id
38597 AND NVL(sales_order_line_id,NULL_VALUE) = NULL_VALUE
38598 AND origination_type = 29
38599 AND deleted_flag = SYS_NO;
38600
38601
38602 BEGIN
38603
38604 lv_column_names :=
38605 'ITEM_NAME ||''~''||'
38606 ||' ORGANIZATION_CODE ||''~''||'
38607 ||' USING_ASSEMBLY_ITEM_NAME ||''~''||'
38608 ||' USING_ASSEMBLY_DEMAND_DATE ||''~''||'
38609 ||' USING_REQUIREMENT_QUANTITY ||''~''||'
38610 ||' SCHEDULE_DATE ||''~''||'
38611 ||' DAILY_DEMAND_RATE ||''~''||'
38612 ||' DEMAND_TYPE ||''~''||'
38613 ||' SR_INSTANCE_CODE ||''~''||'
38614 ||' ASSEMBLY_DEMAND_COMP_DATE ||''~''||'
38615 ||' DEMAND_SCHEDULE_NAME ||''~''||'
38616 ||' SCHEDULE_LINE_NUM ||''~''||'
38617 ||' PROJECT_NUMBER ||''~''||'
38618 ||' TASK_NUMBER ||''~''||'
38619 ||' DEMAND_CLASS ||''~''||'
38620 ||' DMD_LATENESS_COST ||''~''||'
38621 ||' DMD_SATISFIED_DATE ||''~''||'
38622 ||' DMD_SPLIT_FLAG ||''~''||'
38623 ||' CONFIDENCE_PERCENTAGE ||''~''||'
38624 ||' BUCKET_TYPE ||''~''||'
38625 ||' BILL_CODE ||''~''||'
38626 ||' FORECAST_DESIGNATOR ||''~''||'
38627 ||' CUSTOMER_NAME ||''~''||'
38628 ||' FORECAST_MAD ||''~''||'
38629 ||' PROBABILITY ||''~''||'
38630 ||' ORIGINATION_TYPE ||''~''||'
38631 ||' END_ITEM_UNIT_NUMBER ||''~''||'
38632 ||' REQUEST_DATE ||''~''||'
38633 ||' DELETED_FLAG ||''~''||'
38634 ||' COMPANY_NAME ||''~''||'
38635 ||' REVISED_DMD_DATE ||''~''||'
38636 ||' REVISED_DMD_PRIORITY' ;
38637
38638 OPEN c1(p_batch_id);
38639 FETCH c1 BULK COLLECT INTO lb_rowid;
38640 CLOSE c1;
38641
38642 v_sql_stmt := 03;
38643 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
38644 UPDATE msc_st_demands
38645 SET st_transaction_id = msc_st_demands_s.NEXTVAL,
38646 refresh_id = v_refresh_id,
38647 last_update_date = v_current_date,
38648 last_updated_by = v_current_user,
38649 creation_date = v_current_date,
38650 created_by = v_current_user
38651 WHERE rowid = lb_rowid(j);
38652
38653
38654 -- Set the error message
38655 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
38656 (p_app_short_name => 'MSC',
38657 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
38658 p_message_text => lv_message_text,
38659 p_error_text => lv_error_text,
38660 p_token1 => 'COLUMN_NAME',
38661 p_token_value1 => 'DELETED_FLAG',
38662 p_token2 => 'DEFAULT_VALUE',
38663 p_token_value2 => SYS_NO );
38664
38665 IF lv_return <> 0 THEN
38666 RAISE ex_logging_err;
38667 END IF;
38668
38669 --Log a warning for those records where the deleted_flag has a value other
38670 --SYS_NO or SYS_YES
38671 lv_where_str :=
38672 ' AND NVL(deleted_flag,'||NULL_VALUE||') NOT IN(1,2)';
38673
38674 lv_return:= MSC_ST_UTIL.LOG_ERROR
38675 (p_table_name => 'MSC_ST_DEMANDS',
38676 p_instance_code => v_instance_code,
38677 p_row => lv_column_names,
38678 p_severity => G_SEV_WARNING,
38679 p_message_text => lv_message_text,
38680 p_error_text => lv_error_text,
38681 p_batch_id => p_batch_id,
38682 p_where_str => lv_where_str,
38683 p_col_name => 'DELETED_FLAG',
38684 p_debug => v_debug,
38685 p_default_value => SYS_NO);
38686
38687 IF lv_return<> 0 THEN
38688 RAISE ex_logging_err;
38689 END IF;
38690
38691
38692
38693 -- USING_ASSEMBLY_DEMAND_DATE check
38694 -- Set the message
38695
38696 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
38697 (p_app_short_name => 'MSC',
38698 p_error_code => 'MSC_PP_COL_VAL_NULL',
38699 p_message_text => lv_message_text,
38700 p_error_text => lv_error_text,
38701 p_token1 => 'COLUMN_NAME',
38702 p_token_value1 => 'USING_ASSEMBLY_DEMAND_DATE');
38703 IF lv_return <> 0 THEN
38704 RAISE ex_logging_err;
38705 END IF;
38706
38707 -- Error out records where USING_ASSEMBLY_DEMAND_DATE is NULL
38708
38709 v_sql_stmt := 04;
38710 lv_sql_stmt :=
38711 'UPDATE msc_st_demands '
38712 ||' SET process_flag = '||G_ERROR_FLG||','
38713 ||' error_text = '||''''||lv_message_text||''''
38714 ||' WHERE NVL(using_assembly_demand_date,SYSDATE-36500) = SYSDATE-36500'
38715 ||' AND process_flag = '||G_IN_PROCESS
38716 ||' AND origination_type IN (7,8,29)'
38717 ||' AND batch_id = :p_batch_id'
38718 ||' AND sr_instance_code = :v_instance_code';
38719
38720
38721 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
38722
38723 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
38724
38725 -- Set the message
38726
38727 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
38728 (p_app_short_name => 'MSC',
38729 p_error_code => 'MSC_PP_INVALID_VALUE',
38730 p_message_text => lv_message_text,
38731 p_error_text => lv_error_text,
38732 p_token1 => 'COLUMN_NAME',
38733 p_token_value1 => 'REVISED_DMD_PRIORITY' );
38734
38735 IF lv_return <> 0 THEN
38736 RAISE ex_logging_err;
38737 END IF;
38738
38739
38740 -- Error out records if REVISED_DMD_PRIORITY is not a positive number
38741
38742 v_sql_stmt := 04.5;
38743 lv_sql_stmt :=
38744 'UPDATE msc_st_demands '
38745 ||' SET process_flag = '||G_ERROR_FLG||','
38746 ||' error_text = '||''''||lv_message_text||''''
38747 ||' WHERE NVL(REVISED_DMD_PRIORITY, 1) < 0'
38748 ||' AND process_flag = '||G_IN_PROCESS
38749 ||' AND origination_type IN (29)'
38750 ||' AND batch_id = :p_batch_id'
38751 ||' AND sr_instance_code = :v_instance_code';
38752
38753
38754 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
38755
38756 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
38757
38758 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
38759 (p_app_short_name => 'MSC',
38760 p_error_code => 'MSC_PP_REV_DT_GT_DMD_DATE',
38761 p_message_text => lv_message_text,
38762 p_error_text => lv_error_text);
38763
38764 IF lv_return <> 0 THEN
38765 RAISE ex_logging_err;
38766 END IF;
38767
38768
38769
38770 lv_where_str :=
38771 ' AND TRUNC(NVL(REVISED_DMD_DATE,SYSDATE - 36500)) > ' ||
38772 ' TRUNC(NVL(USING_ASSEMBLY_DEMAND_DATE,SYSDATE+36500)) ' ||
38773 ' AND origination_type IN (29) ';
38774
38775 --Log a warning for those records where the revised_dmd_date is greater
38776 --than firm date(schedule_date)
38777
38778 lv_return := MSC_ST_UTIL.LOG_ERROR
38779 (p_table_name => 'MSC_ST_DEMANDS',
38780 p_instance_code => v_instance_code,
38781 p_row => lv_column_names,
38782 p_severity => G_SEV_WARNING,
38783 p_message_text => lv_message_text,
38784 p_error_text => lv_error_text,
38785 p_batch_id => p_batch_id,
38786 p_where_str => lv_where_str);
38787
38788 IF lv_return <> 0 THEN
38789 RAISE ex_logging_err;
38790 END IF;
38791
38792 -- Set the message
38793
38794 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
38795 (p_app_short_name => 'MSC',
38796 p_error_code => 'MSC_PP_COL_VAL_NULL',
38797 p_message_text => lv_message_text,
38798 p_error_text => lv_error_text,
38799 p_token1 => 'COLUMN_NAME',
38800 p_token_value1 => 'USING_REQUIREMENT_QUANTITY' );
38801
38802 IF lv_return <> 0 THEN
38803 RAISE ex_logging_err;
38804 END IF;
38805
38806
38807 -- Error out if USING_REQUIREMENT_QUNATITY is NULL
38808 -- and deleted_flag = SYS_NO
38809
38810 v_sql_stmt := 05;
38811 lv_sql_stmt :=
38812 'UPDATE msc_st_demands '
38813 ||' SET process_flag = '||G_ERROR_FLG||','
38814 ||' error_text = '||''''||lv_message_text||''''
38815 ||' WHERE NVL(using_requirement_quantity,'||NULL_VALUE||') ='||NULL_VALUE
38816 ||' AND process_flag = '||G_IN_PROCESS
38817 ||' AND origination_type IN (7,8,29)'
38818 ||' AND deleted_flag = '||SYS_NO
38819 ||' AND batch_id = :p_batch_id'
38820 ||' AND sr_instance_code = :v_instance_code';
38821
38822
38823 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
38824
38825 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
38826 -- Set the message
38827
38828 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
38829 (p_app_short_name => 'MSC',
38830 p_error_code => 'MSC_PP_INVALID_VALUE',
38831 p_message_text => lv_message_text,
38832 p_error_text => lv_error_text,
38833 p_token1 => 'COLUMN_NAME',
38834 p_token_value1 => 'ORGANIZATION_CODE');
38835
38836 IF lv_return <> 0 THEN
38837 RAISE ex_logging_err;
38838 END IF;
38839
38840 --Derive Organization_id
38841 lv_return:= MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
38842 (p_table_name => 'MSC_ST_DEMANDS',
38843 p_org_partner_name => 'ORGANIZATION_CODE',
38844 p_org_partner_id => 'ORGANIZATION_ID',
38845 p_instance_code => v_instance_code,
38846 p_partner_type => G_ORGANIZATION,
38847 p_error_text => lv_error_text,
38848 p_batch_id => p_batch_id,
38849 p_severity => G_SEV_ERROR,
38850 p_message_text => lv_message_text,
38851 p_debug => v_debug,
38852 p_row => lv_column_names);
38853
38854 IF lv_return<> 0 THEN
38855 RAISE ex_logging_err;
38856 END IF;
38857
38858 -- Set the message
38859
38860 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
38861 (p_app_short_name => 'MSC',
38862 p_error_code => 'MSC_PP_INVALID_VALUE',
38863 p_message_text => lv_message_text,
38864 p_error_text => lv_error_text,
38865 p_token1 => 'COLUMN_NAME',
38866 p_token_value1 => 'ITEM_NAME');
38867
38868 IF lv_return <> 0 THEN
38869 RAISE ex_logging_err;
38870 END IF;
38871
38872
38873 --Derive Inventory_item_id
38874 lv_return:= MSC_ST_UTIL.DERIVE_ITEM_ID
38875 (p_table_name => 'MSC_ST_DEMANDS',
38876 p_item_col_name => 'ITEM_NAME',
38877 p_item_col_id => 'INVENTORY_ITEM_ID',
38878 p_instance_id => v_instance_id,
38879 p_instance_code => v_instance_code,
38880 p_error_text => lv_error_text,
38881 p_batch_id => p_batch_id,
38882 p_severity => G_SEV_ERROR,
38883 p_message_text => lv_message_text,
38884 p_debug => v_debug,
38885 p_row => lv_column_names);
38886
38887 IF lv_return<> 0 THEN
38888 RAISE ex_logging_err;
38889 END IF;
38890
38891 -- Set the message
38892 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
38893 (p_app_short_name => 'MSC',
38894 p_error_code => 'MSC_PP_INVALID_VALUE',
38895 p_message_text => lv_message_text,
38896 p_error_text => lv_error_text,
38897 p_token1 => 'COLUMN_NAME',
38898 p_token_value1 => 'USING_ASSEMBLY_ITEM_NAME');
38899
38900 IF lv_return <> 0 THEN
38901 RAISE ex_logging_err;
38902 END IF;
38903
38904 --Derive Inventory_item_id
38905 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
38906 (p_table_name => 'MSC_ST_DEMANDS',
38907 p_item_col_name => 'USING_ASSEMBLY_ITEM_NAME',
38908 p_item_col_id => 'USING_ASSEMBLY_ITEM_ID',
38909 p_instance_id => v_instance_id,
38910 p_instance_code => v_instance_code,
38911 p_error_text => lv_error_text,
38912 p_batch_id => p_batch_id,
38913 p_severity => G_SEV3_ERROR,
38914 p_message_text => lv_message_text,
38915 p_debug => v_debug,
38916 p_row => lv_column_names);
38917
38918 IF lv_return <> 0 THEN
38919 RAISE ex_logging_err;
38920 END IF;
38921
38922 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
38923 (p_app_short_name => 'MSC',
38924 p_error_code => 'MSC_PP_INVALID_VALUE',
38925 p_message_text => lv_message_text,
38926 p_error_text => lv_error_text,
38927 p_token1 => 'COLUMN_NAME',
38928 p_token_value1 => 'DEMAND_CLASS');
38929
38930 IF lv_return <> 0 THEN
38931 RAISE ex_logging_err;
38932 END IF;
38933
38934
38935 -- Validate Demand Class, if value provided it should exists
38936 -- in ODS or staging table
38937
38938 lv_return :=
38939 MSC_ST_UTIL.VALIDATE_DMD_CLASS(p_table_name => 'MSC_ST_DEMANDS',
38940 p_dmd_class_column => 'DEMAND_CLASS',
38941 p_instance_id => v_instance_id,
38942 p_instance_code => v_instance_code,
38943 p_severity => G_SEV3_ERROR,
38944 p_message_text => lv_message_text,
38945 p_batch_id => p_batch_id,
38946 p_debug => v_debug,
38947 p_error_text => lv_error_text);
38948
38949 if(lv_return <> 0) then
38950 RAISE ex_logging_err;
38951 end if;
38952
38953
38954
38955 -- Update using_assembly_item_id = inventory_item_id
38956
38957 v_sql_stmt := 06;
38958 lv_sql_stmt :=
38959 ' UPDATE msc_st_demands'
38960 ||' SET using_assembly_item_id = inventory_item_id'
38961 ||' WHERE process_flag = '||G_IN_PROCESS
38962 ||' AND NVL(using_assembly_item_id,'||NULL_VALUE||') = '||NULL_VALUE
38963 ||' AND deleted_flag = '||SYS_NO
38964 ||' AND process_flag = '||G_IN_PROCESS
38965 ||' AND origination_type IN (7,8,29)'
38966 ||' AND deleted_flag = '||SYS_NO
38967 ||' AND batch_id = :p_batch_id'
38968 ||' AND sr_instance_code = :v_instance_code';
38969
38970
38971 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
38972
38973 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
38974
38975
38976 -- Update schedule_date = using_assembly_demand_date
38977
38978
38979 v_sql_stmt := 07;
38980 lv_sql_stmt :=
38981 ' UPDATE msc_st_demands'
38982 ||' SET schedule_date = using_assembly_demand_date '
38983 ||' WHERE process_flag = '||G_IN_PROCESS
38984 ||' AND deleted_flag = '||SYS_NO
38985 ||' AND origination_type IN (7,8,29)'
38986 ||' AND batch_id = :p_batch_id'
38987 ||' AND sr_instance_code = :v_instance_code';
38988
38989
38990 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
38991
38992 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
38993
38994 -- Derive disposition_id for MDS
38995
38996 v_sql_stmt := 08;
38997 lv_sql_stmt :=
38998 'UPDATE msc_st_demands msd '
38999 ||' SET disposition_id = (SELECT local_id'
39000 ||' FROM msc_local_id_demand mlid'
39001 ||' WHERE mlid.char1 = msd.sr_instance_code'
39002 ||' AND NVL(mlid.char2,'||''''||NULL_CHAR||''''||') '
39003 ||' = NVL(msd.company_name,'||''''||NULL_CHAR||''''||') '
39004 ||' AND mlid.char3 = msd.organization_code'
39005 ||' AND mlid.char4 = msd.demand_schedule_name'
39006 ||' AND mlid.char5 = msd.item_name'
39007 ||' AND NVL(mlid.char6,'||''''||NULL_CHAR||''''||') '
39008 ||' = NVL(msd.schedule_line_num,'||''''||NULL_CHAR||''''||') '
39009 ||' AND mlid.date1 = msd.schedule_date'
39010 ||' AND mlid.number1 = msd.origination_type'
39011 ||' AND mlid.entity_name = ''DISPOSITION_ID_MDS'' )'
39012 ||' WHERE origination_type in (7,8)'
39013 ||' AND process_flag ='||G_IN_PROCESS
39014 ||' AND batch_id = :p_batch_id'
39015 ||' AND sr_instance_code =:v_instance_code' ;
39016
39017
39018 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
39019
39020 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
39021
39022 -- Set the message
39023
39024 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
39025 (p_app_short_name => 'MSC',
39026 p_error_code => 'MSC_PP_DELETE_FAIL',
39027 p_message_text => lv_message_text,
39028 p_error_text => lv_error_text);
39029
39030 IF lv_return <> 0 THEN
39031 RAISE ex_logging_err;
39032 END IF;
39033 -- Error out records with deleted flag = SYS_YES and NULL disposition_id
39034
39035 v_sql_stmt := 09;
39036
39037 lv_sql_stmt :=
39038 'UPDATE msc_st_demands '
39039 ||' SET process_flag ='||G_ERROR_FLG||','
39040 ||' error_text = '||''''||lv_message_text||''''
39041 ||' WHERE NVL(disposition_id,'||NULL_VALUE||') = '||NULL_VALUE
39042 ||' AND deleted_flag ='||SYS_YES
39043 ||' AND origination_type in (7,8)'
39044 ||' AND batch_id = :p_batch_id'
39045 ||' AND sr_instance_code =:v_instance_code';
39046
39047
39048 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
39049
39050 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
39051
39052
39053 -- Derive sales_order_line_id for forecast
39054
39055 v_sql_stmt := 10;
39056 lv_sql_stmt :=
39057 'UPDATE msc_st_demands msd '
39058 ||' SET sales_order_line_id = (SELECT local_id'
39059 ||' FROM msc_local_id_demand mlid'
39060 ||' WHERE mlid.char1 = msd.sr_instance_code'
39061 ||' AND NVL(mlid.char2,'||''''||NULL_CHAR||''''||') '
39062 ||' = NVL(msd.company_name,'||''''||NULL_CHAR||''''||') '
39063 ||' AND mlid.char3 = msd.organization_code'
39064 ||' AND mlid.char4 = msd.forecast_designator'
39065 ||' AND mlid.char5 = msd.item_name'
39066 ||' AND NVL(mlid.char6,'||''''||NULL_CHAR||''''||') '
39067 ||' = NVL(msd.schedule_line_num,'||''''||NULL_CHAR||''''||') '
39068 ||' AND mlid.date1 = msd.schedule_date'
39069 ||' AND mlid.number1 = msd.origination_type'
39070 ||' AND mlid.entity_name = ''DISPOSITION_ID_FCT'' )'
39071 ||' WHERE origination_type = 29'
39072 ||' AND process_flag ='||G_IN_PROCESS
39073 ||' AND batch_id = :p_batch_id'
39074 ||' AND sr_instance_code =:v_instance_code';
39075
39076
39077 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
39078
39079 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
39080
39081 -- Set the message
39082
39083 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
39084 (p_app_short_name => 'MSC',
39085 p_error_code => 'MSC_PP_DELETE_FAIL',
39086 p_message_text => lv_message_text,
39087 p_error_text => lv_error_text);
39088
39089 IF lv_return <> 0 THEN
39090 RAISE ex_logging_err;
39091 END IF;
39092
39093 -- Error out records with deleted flag = SYS_YES and NULL disposition_id
39094
39095 v_sql_stmt := 11;
39096
39097 lv_sql_stmt :=
39098 'UPDATE msc_st_demands '
39099 ||' SET process_flag ='||G_ERROR_FLG||','
39100 ||' error_text = '||''''||lv_message_text||''''
39101 ||' WHERE NVL(sales_order_line_id,'||NULL_VALUE||') = '||NULL_VALUE
39102 ||' AND deleted_flag ='||SYS_YES
39103 ||' AND origination_type = 29'
39104 ||' AND batch_id = :p_batch_id'
39105 ||' AND sr_instance_code =:v_instance_code';
39106
39107
39108 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
39109
39110 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
39111
39112 -- Set the error message
39113 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
39114 (p_app_short_name => 'MSC',
39115 p_error_code => 'MSC_PP_FK_REF_NOT_EXIST',
39116 p_message_text => lv_message_text,
39117 p_error_text => lv_error_text,
39118 p_token1 => 'COLUMN_NAMES',
39119 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
39120 ||'ORGANIZATION_CODE,PROJECT_NUMBER',
39121 p_token2 => 'MASTER_TABLE');
39122
39123 IF lv_return <> 0 THEN
39124 RAISE ex_logging_err;
39125 END IF;
39126
39127 --Derive Project Id.
39128 lv_return:= MSC_ST_UTIL.DERIVE_PROJ_TASK_ID
39129 (p_table_name => 'MSC_ST_DEMANDS',
39130 p_proj_col_name => 'PROJECT_NUMBER',
39131 p_proj_task_col_id => 'PROJECT_ID',
39132 p_instance_code => v_instance_code,
39133 p_entity_name => 'PROJECT_ID',
39134 p_error_text => lv_error_text,
39135 p_batch_id => p_batch_id,
39136 p_severity => G_SEV_WARNING,
39137 p_message_text => lv_message_text,
39138 p_debug => v_debug,
39139 p_row => lv_column_names);
39140 IF lv_return<> 0 THEN
39141 RAISE ex_logging_err;
39142 END IF;
39143
39144 -- Set the error message
39145 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
39146 (p_app_short_name => 'MSC',
39147 p_error_code => 'MSC_PP_FK_REF_NOT_EXIST',
39148 p_message_text => lv_message_text,
39149 p_error_text => lv_error_text,
39150 p_token1 => 'COLUMN_NAMES',
39151 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
39152 ||'ORGANIZATION_CODE,PROJECT_NUMBER'
39153 ||'TASK_NUMBER' ,
39154 p_token2 => 'MASTER_TABLE',
39155 p_token_value2 => 'MSC_ST_PROJECT_TASKS');
39156
39157 IF lv_return <> 0 THEN
39158 RAISE ex_logging_err;
39159 END IF;
39160
39161 --Derive Task Id.
39162 lv_return:= MSC_ST_UTIL.DERIVE_PROJ_TASK_ID
39163 (p_table_name => 'MSC_ST_DEMANDS',
39164 p_proj_col_name => 'PROJECT_NUMBER',
39165 p_proj_task_col_id => 'TASK_ID',
39166 p_instance_code => v_instance_code,
39167 p_entity_name => 'TASK_ID',
39168 p_error_text => lv_error_text,
39169 p_task_col_name => 'TASK_NUMBER',
39170 p_batch_id => p_batch_id,
39171 p_severity => G_SEV_WARNING,
39172 p_message_text => lv_message_text,
39173 p_debug => v_debug,
39174 p_row => lv_column_names);
39175
39176 IF lv_return<> 0 THEN
39177 RAISE ex_logging_err;
39178 END IF;
39179
39180 -- Validations for MDS ( origination_type = 8)
39181
39182 -- Set the error message
39183 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
39184 (p_app_short_name => 'MSC',
39185 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
39186 p_message_text => lv_message_text,
39187 p_error_text => lv_error_text,
39188 p_token1 => 'COLUMN_NAMES',
39189 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
39190 ||' ORGANIZATION_CODE,'
39191 ||' DEMAND_SCHEDULE_NAME',
39192 p_token2 => 'MASTER_TABLE',
39193 p_token_value2 => 'MSC_ST_DESIGNATORS',
39194 p_token3 => 'CHILD_TABLE' ,
39195 p_token_value3 => 'MSC_ST_DEMANDS' );
39196
39197 IF lv_return <> 0 THEN
39198 RAISE ex_logging_err;
39199 END IF;
39200
39201 -- For MDS check whether designator exists
39202
39203 v_sql_stmt := 12;
39204 lv_sql_stmt :=
39205 'UPDATE msc_st_demands msdm'
39206 ||' SET process_flag = '||G_ERROR_FLG||','
39207 ||' error_text = '||''''||lv_message_text||''''
39208 ||' WHERE NOT EXISTS(SELECT 1'
39209 ||' FROM msc_st_designators msd'
39210 ||' WHERE msd.designator = msdm.demand_schedule_name'
39211 ||' AND NVL(msd.company_name,'||''''||NULL_CHAR||''''||') '
39212 ||' = NVL(msdm.company_name,'||''''||NULL_CHAR||''''||') '
39213 ||' AND msd.organization_code = msdm.organization_code'
39214 ||' AND msd.sr_instance_code = msdm.sr_instance_code'
39215 ||' AND msd.process_flag = '||G_VALID
39216 ||' AND msd.designator_type = 1'
39217 ||' AND NVL(msd.disable_date, SYSDATE+1) > SYSDATE'
39218 ||' UNION'
39219 ||' SELECT 1'
39220 ||' FROM msc_designators md'
39221 ||' WHERE md.designator = msdm.demand_schedule_name'
39222 ||' AND md.organization_id = msdm.organization_id '
39223 ||' AND md.sr_instance_id = :v_instance_id '
39224 ||' AND md.designator_type = 1'
39225 ||' AND NVL(md.disable_date, SYSDATE+1) > SYSDATE)'
39226 ||' AND origination_type in (7,8)'
39227 ||' AND deleted_flag = '||SYS_NO
39228 ||' AND process_flag = '||G_IN_PROCESS
39229 ||' AND batch_id = :p_batch_id'
39230 ||' AND sr_instance_code = :v_instance_code';
39231
39232
39233 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
39234
39235 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_id,
39236 p_batch_id,
39237 v_instance_code;
39238
39239
39240
39241 -- Repetitve planned items not supported
39242 -- So error out records with demand type = 2 ,or daily_demand_rate or
39243 -- assembly_demand_comp_date is NOT NULL for origination type = 8
39244
39245 -- Set the message
39246
39247 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
39248 (p_app_short_name => 'MSC',
39249 p_error_code => 'MSC_PP_INVALID_VALUE',
39250 p_message_text => lv_message_text,
39251 p_error_text => lv_error_text,
39252 p_token1 => 'COLUMN_NAME',
39253 p_token_value1 => 'DEMAND_TYPE OR DAILY_DEMAND_RATE ,'
39254 ||' ASSEMBLY_DEMAND_COMP_DATE' );
39255
39256 IF lv_return <> 0 THEN
39257 RAISE ex_logging_err;
39258 END IF;
39259
39260 v_sql_stmt := 13;
39261
39262 lv_sql_stmt :=
39263 'UPDATE msc_st_demands '
39264 ||' SET process_flag = '||G_ERROR_FLG||','
39265 ||' error_text = '||''''||lv_message_text||''''
39266 ||' WHERE (demand_type = 2'
39267 ||' OR assembly_demand_comp_date IS NOT NULL '
39268 ||' OR daily_demand_rate IS NOT NULL ) '
39269 ||' AND deleted_flag = '||SYS_NO
39270 ||' AND origination_type in (7,8)'
39271 ||' AND batch_id = :p_batch_id'
39272 ||' AND sr_instance_code = :v_instance_code';
39273
39274
39275 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
39276
39277 EXECUTE IMMEDIATE lv_sql_stmt USING p_batch_id,v_instance_code;
39278
39279 -- Validations for Forecast ( origination_type = 29)
39280
39281 -- Set the error message
39282 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
39283 (p_app_short_name => 'MSC',
39284 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
39285 p_message_text => lv_message_text,
39286 p_error_text => lv_error_text,
39287 p_token1 => 'COLUMN_NAMES',
39288 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
39289 ||'ORGANIZATION_CODE,FORECAST_DESIGNATOR',
39290 p_token2 => 'MASTER_TABLE',
39291 p_token_value2 => 'MSC_ST_DESIGNATORS',
39292 p_token3 => 'CHILD_TABLE' ,
39293 p_token_value3 => 'MSC_ST_DEMANDS' );
39294
39295 IF lv_return <> 0 THEN
39296 RAISE ex_logging_err;
39297 END IF;
39298
39299 -- For Forecast,check whether designator exists
39300
39301 v_sql_stmt := 14;
39302 lv_sql_stmt :=
39303 'UPDATE msc_st_demands msdm'
39304 ||' SET process_flag = '||G_ERROR_FLG||','
39305 ||' error_text = '||''''||lv_message_text||''''
39306 ||' WHERE NOT EXISTS(SELECT 1'
39307 ||' FROM msc_st_designators msd'
39308 ||' WHERE msd.designator = msdm.forecast_designator'
39309 ||' AND NVL(msd.company_name,'||''''||NULL_CHAR||''''||') '
39310 ||' = NVL(msd.company_name,'||''''||NULL_CHAR||''''||') '
39311 ||' AND msd.organization_code = msdm.organization_code'
39312 ||' AND msd.sr_instance_code = msdm.sr_instance_code'
39313 ||' AND msd.process_flag = '||G_VALID
39314 ||' AND msd.designator_type = 6'
39315 ||' AND NVL(msd.disable_date, SYSDATE+1) > SYSDATE'
39316 ||' UNION'
39317 ||' SELECT 1'
39318 ||' FROM msc_designators md'
39319 ||' WHERE md.designator = msdm.forecast_designator'
39320 ||' AND md.organization_id = msdm.organization_id '
39321 ||' AND md.sr_instance_id = :v_instance_id '
39322 ||' AND md.designator_type = 6'
39323 ||' AND NVL(md.disable_date, SYSDATE+1) > SYSDATE)'
39324 ||' AND origination_type = 29'
39325 ||' AND deleted_flag = '||SYS_NO
39326 ||' AND process_flag = '||G_IN_PROCESS
39327 ||' AND batch_id = :p_batch_id'
39328 ||' AND sr_instance_code = :v_instance_code';
39329
39330
39331 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
39332
39333 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_id,
39334 p_batch_id,
39335 v_instance_code;
39336
39337
39338 -- Set the error message
39339 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
39340 (p_app_short_name => 'MSC',
39341 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
39342 p_message_text => lv_message_text,
39343 p_error_text => lv_error_text,
39344 p_token1 => 'COLUMN_NAME',
39345 p_token_value1 => 'DEMAND_TYPE',
39346 p_token2 => 'DEFAULT_VALUE',
39347 p_token_value2 => 1 );
39348
39349 IF lv_return <> 0 THEN
39350 RAISE ex_logging_err;
39351 END IF;
39352
39353
39354 -- Default demand_type to 1 if assembly_demand_comp_date is NULL
39355
39356 lv_where_str := ' AND NVL(assembly_demand_comp_date,SYSDATE-36500 ) = SYSDATE-36500'
39357 ||' AND NVL(demand_type,'||NULL_VALUE||') <> 1'
39358 ||' AND origination_type = 29 AND deleted_flag ='||SYS_NO ;
39359
39360 lv_return:= MSC_ST_UTIL.LOG_ERROR
39361 (p_table_name => 'MSC_ST_DEMANDS',
39362 p_instance_code => v_instance_code,
39363 p_row => lv_column_names,
39364 p_severity => G_SEV_WARNING,
39365 p_message_text => lv_message_text,
39366 p_error_text => lv_error_text,
39367 p_batch_id => p_batch_id,
39368 p_where_str => lv_where_str,
39369 p_col_name => 'DEMAND_TYPE',
39370 p_debug => v_debug,
39371 p_default_value => 1);
39372
39373 IF lv_return<> 0 THEN
39374 RAISE ex_logging_err;
39375 END IF;
39376
39377 -- Set the error message
39378 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
39379 (p_app_short_name => 'MSC',
39380 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
39381 p_message_text => lv_message_text,
39382 p_error_text => lv_error_text,
39383 p_token1 => 'COLUMN_NAME',
39384 p_token_value1 => 'DEMAND_TYPE',
39385 p_token2 => 'DEFAULT_VALUE',
39386 p_token_value2 => 2 );
39387
39388 IF lv_return <> 0 THEN
39389 RAISE ex_logging_err;
39390 END IF;
39391
39392 -- Default demand_type as 2 if assembly_demand_comp_date is NOT NULL
39393
39394 lv_where_str := ' AND NVL(assembly_demand_comp_date,SYSDATE-36500 ) <> SYSDATE-36500 '
39395 ||' AND NVL(demand_type,'||NULL_VALUE||') <> 2'
39396 ||' AND origination_type = 29 AND deleted_flag ='||SYS_NO ;
39397
39398 lv_return:= MSC_ST_UTIL.LOG_ERROR
39399 (p_table_name => 'MSC_ST_DEMANDS',
39400 p_instance_code => v_instance_code,
39401 p_row => lv_column_names,
39402 p_severity => G_SEV_WARNING,
39403 p_message_text => lv_message_text,
39404 p_error_text => lv_error_text,
39405 p_batch_id => p_batch_id,
39406 p_where_str => lv_where_str,
39407 p_col_name => 'DEMAND_TYPE',
39408 p_debug => v_debug,
39409 p_default_value => 2);
39410
39411 IF lv_return<> 0 THEN
39412 RAISE ex_logging_err;
39413 END IF;
39414
39415 -- Set the error message
39416 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
39417 (p_app_short_name => 'MSC',
39418 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
39419 p_message_text => lv_message_text,
39420 p_error_text => lv_error_text,
39421 p_token1 => 'COLUMN_NAME',
39422 p_token_value1 => 'BUCKET_TYPE',
39423 p_token2 => 'DEFAULT_VALUE',
39424 p_token_value2 => G_BUCKET_TYPE );
39425
39426 IF lv_return <> 0 THEN
39427 RAISE ex_logging_err;
39428 END IF;
39429
39430 -- Default bucket type to 1, if NOT IN (1 -days,2 - Weeks,3 - Periods)
39431
39432 lv_where_str := ' AND NVL(bucket_type,'||NULL_VALUE||') NOT IN (1,2,3)'
39433 ||' AND origination_type = 29 AND deleted_flag ='||SYS_NO ;
39434
39435 lv_return:= MSC_ST_UTIL.LOG_ERROR
39436 (p_table_name => 'MSC_ST_DEMANDS',
39437 p_instance_code => v_instance_code,
39438 p_row => lv_column_names,
39439 p_severity => G_SEV_WARNING,
39440 p_message_text => lv_message_text,
39441 p_error_text => lv_error_text,
39442 p_batch_id => p_batch_id,
39443 p_where_str => lv_where_str,
39444 p_col_name => 'BUCKET_TYPE',
39445 p_debug => v_debug,
39446 p_default_value => G_BUCKET_TYPE);
39447
39448 IF lv_return<> 0 THEN
39449 RAISE ex_logging_err;
39450 END IF;
39451
39452 -- Set the message
39453
39454 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
39455 (p_app_short_name => 'MSC',
39456 p_error_code => 'MSC_PP_INVALID_VALUE',
39457 p_message_text => lv_message_text,
39458 p_error_text => lv_error_text,
39459 p_token1 => 'COLUMN_NAME',
39460 p_token_value1 => 'CUSTOMER_NAME');
39461
39462 IF lv_return <> 0 THEN
39463 RAISE ex_logging_err;
39464 END IF;
39465
39466 -- Derive customer_id
39467
39468 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
39469 (p_table_name => 'MSC_ST_DEMANDS',
39470 p_org_partner_name => 'CUSTOMER_NAME',
39471 p_org_partner_id => 'CUSTOMER_ID',
39472 p_instance_code => v_instance_code,
39473 p_partner_type => G_CUSTOMER,
39474 p_error_text => lv_error_text,
39475 p_batch_id => p_batch_id,
39476 p_severity => G_SEV3_ERROR,
39477 p_message_text => lv_message_text,
39478 p_debug => v_debug,
39479 p_row => lv_column_names);
39480
39481 IF lv_return <> 0 THEN
39482 RAISE ex_logging_err;
39483 END IF;
39484
39485 -- Set the message
39486 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
39487 (p_app_short_name => 'MSC',
39488 p_error_code => 'MSC_PP_INVALID_VALUE',
39489 p_message_text => lv_message_text,
39490 p_error_text => lv_error_text,
39491 p_token1 => 'COLUMN_NAME',
39492 p_token_value1 => 'CUSTOMER_SITE_CODE');
39493
39494 IF lv_return <> 0 THEN
39495 RAISE ex_logging_err;
39496 END IF;
39497
39498
39499 -- Derive customer_site_id
39500
39501 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
39502 (p_table_name => 'MSC_ST_DEMANDS',
39503 p_partner_name => 'CUSTOMER_NAME',
39504 p_partner_site_code => 'CUSTOMER_SITE_CODE',
39505 p_partner_site_id => 'CUSTOMER_SITE_ID',
39506 p_instance_code => v_instance_code,
39507 p_partner_type => G_CUSTOMER,
39508 p_error_text => lv_error_text,
39509 p_batch_id => p_batch_id,
39510 p_severity => G_SEV3_ERROR,
39511 p_message_text => lv_message_text,
39512 p_debug => v_debug,
39513 p_row => lv_column_names);
39514
39515 IF lv_return <> 0 THEN
39516 RAISE ex_logging_err;
39517 END IF;
39518
39519 -- Set the message
39520 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
39521 (p_app_short_name => 'MSC',
39522 p_error_code => 'MSC_PP_INVALID_VALUE',
39523 p_message_text => lv_message_text,
39524 p_error_text => lv_error_text,
39525 p_token1 => 'COLUMN_NAME',
39526 p_token_value1 => 'BILL_CODE');
39527
39528 IF lv_return <> 0 THEN
39529 RAISE ex_logging_err;
39530 END IF;
39531
39532
39533 -- Derive bill_to_site_id
39534 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
39535 (p_table_name => 'MSC_ST_DEMANDS',
39536 p_partner_name => 'CUSTOMER_NAME',
39537 p_partner_site_code => 'BILL_CODE',
39538 p_partner_site_id => 'BILL_ID',
39539 p_instance_code => v_instance_code,
39540 p_partner_type => G_CUSTOMER,
39541 p_error_text => lv_error_text,
39542 p_batch_id => p_batch_id,
39543 p_severity => G_SEV3_ERROR,
39544 p_message_text => lv_message_text,
39545 p_debug => v_debug,
39546 p_row => lv_column_names);
39547
39548 IF lv_return <> 0 THEN
39549 RAISE ex_logging_err;
39550 END IF;
39551
39552 -- valid values for order_date_type_code are 'SHIP' and 'ARRIVE'
39553 -- Set the error message
39554
39555 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
39556 (p_app_short_name => 'MSC',
39557 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
39558 p_message_text => lv_message_text,
39559 p_error_text => lv_error_text,
39560 p_token1 => 'COLUMN_NAME',
39561 p_token_value1 => 'ORDER_DATE_TYPE_CODE',
39562 p_token2 => 'DEFAULT_VALUE',
39563 p_token_value2 => 1);
39564
39565 IF lv_return <> 0 THEN
39566 RAISE ex_logging_err;
39567 END IF;
39568
39569 lv_where_str :=
39570 ' AND NVL(order_date_type_code ,'||NULL_VALUE||') '
39571 ||' NOT IN (1,2) AND origination_type in (7, 8)'
39572 ||' AND NVL(order_date_type_code,'||NULL_VALUE||')<> '||NULL_VALUE;
39573
39574 lv_return := MSC_ST_UTIL.LOG_ERROR
39575 (p_table_name => 'MSC_ST_DEMANDS',
39576 p_instance_code => v_instance_code,
39577 p_row => lv_column_names,
39578 p_severity => G_SEV_WARNING,
39579 p_message_text => lv_message_text,
39580 p_error_text => lv_error_text,
39581 p_batch_id => p_batch_id,
39582 p_where_str => lv_where_str,
39583 p_col_name => 'ORDER_DATE_TYPE_CODE',
39584 p_debug => v_debug,
39585 p_default_value => 1);
39586
39587 IF lv_return <> 0 THEN
39588 RAISE ex_logging_err;
39589 END IF;
39590
39591 --Call to customised validation.
39592 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
39593 (ERRBUF => lv_error_text,
39594 RETCODE => lv_return,
39595 pBatchID => p_batch_id,
39596 pInstanceCode => v_instance_code,
39597 pEntityName => 'MSC_ST_DEMANDS',
39598 pInstanceID => v_instance_id);
39599
39600 IF NVL(lv_return,0) <> 0 THEN
39601 RAISE ex_logging_err;
39602 END IF;
39603
39604 -- Generate disposition_id for MDS
39605
39606 OPEN c2(p_batch_id);
39607 FETCH c2 BULK COLLECT INTO lb_rowid ;
39608
39609 IF c2%ROWCOUNT > 0 THEN
39610 v_sql_stmt := 15;
39611 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
39612 UPDATE msc_st_demands
39613 SET disposition_id = msc_st_demand_disposition_id_s.NEXTVAL
39614 WHERE rowid = lb_rowid(j);
39615
39616 v_sql_stmt := 16;
39617 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
39618 INSERT INTO msc_local_id_demand
39619 (local_id,
39620 st_transaction_id,
39621 instance_id,
39622 entity_name,
39623 data_source_type,
39624 char1,
39625 char2,
39626 char3,
39627 char4,
39628 char5,
39629 char6,
39630 number1,
39631 date1,
39632 SOURCE_ORG_ID,
39633 SOURCE_INVENTORY_ITEM_ID,
39634 SOURCE_USING_ASSEMBLY_ITEM_ID ,
39635 SOURCE_PROJECT_ID ,
39636 SOURCE_TASK_ID,
39637 SOURCE_CUSTOMER_SITE_ID ,
39638 SOURCE_BILL_ID ,
39639 SOURCE_DISPOSITION_ID,
39640 SOURCE_CUSTOMER_ID,
39641 last_update_date,
39642 last_updated_by,
39643 creation_date,
39644 created_by)
39645 SELECT
39646 disposition_id,
39647 st_transaction_id,
39648 v_instance_id,
39649 'DISPOSITION_ID_MDS',
39650 data_source_type,
39651 sr_instance_code,
39652 company_name,
39653 organization_code,
39654 demand_schedule_name,
39655 item_name,
39656 schedule_line_num,
39657 origination_type,
39658 schedule_date,
39659 SOURCE_ORG_ID,
39660 SOURCE_INVENTORY_ITEM_ID,
39661 SOURCE_USING_ASSEMBLY_ITEM_ID ,
39662 SOURCE_PROJECT_ID ,
39663 SOURCE_TASK_ID,
39664 SOURCE_CUSTOMER_SITE_ID ,
39665 SOURCE_BILL_ID ,
39666 SOURCE_DISPOSITION_ID,
39667 SOURCE_CUSTOMER_ID,
39668 v_current_date,
39669 v_current_user,
39670 v_current_date,
39671 v_current_user
39672 FROM msc_st_demands
39673 WHERE rowid = lb_rowid(j);
39674
39675 END IF;
39676 CLOSE c2 ;
39677
39678
39679 -- Generate sales_order_line_id for Forecast
39680
39681 OPEN c3(p_batch_id);
39682 FETCH c3 BULK COLLECT INTO lb_rowid ;
39683
39684 IF c3%ROWCOUNT > 0 THEN
39685 v_sql_stmt := 17;
39686 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
39687 UPDATE msc_st_demands
39688 SET sales_order_line_id = msc_st_demand_disposition_id_s.NEXTVAL
39689 WHERE rowid = lb_rowid(j);
39690
39691 v_sql_stmt := 18;
39692 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
39693 INSERT INTO msc_local_id_demand
39694 (local_id,
39695 st_transaction_id,
39696 instance_id,
39697 entity_name,
39698 data_source_type,
39699 char1,
39700 char2,
39701 char3,
39702 char4,
39703 char5,
39704 char6,
39705 number1,
39706 date1,
39707 SOURCE_ORG_ID,
39708 SOURCE_INVENTORY_ITEM_ID,
39709 SOURCE_USING_ASSEMBLY_ITEM_ID ,
39710 SOURCE_SALES_ORDER_LINE_ID ,
39711 SOURCE_PROJECT_ID ,
39712 SOURCE_TASK_ID,
39713 SOURCE_CUSTOMER_SITE_ID ,
39714 SOURCE_BILL_ID ,
39715 SOURCE_CUSTOMER_ID,
39716 last_update_date,
39717 last_updated_by,
39718 creation_date,
39719 created_by)
39720 SELECT
39721 sales_order_line_id,
39722 st_transaction_id,
39723 v_instance_id,
39724 'DISPOSITION_ID_FCT',
39725 data_source_type,
39726 sr_instance_code,
39727 company_name,
39728 organization_code,
39729 forecast_designator,
39730 item_name,
39731 schedule_line_num,
39732 origination_type,
39733 schedule_date,
39734 SOURCE_ORG_ID,
39735 SOURCE_INVENTORY_ITEM_ID,
39736 SOURCE_USING_ASSEMBLY_ITEM_ID ,
39737 SOURCE_SALES_ORDER_LINE_ID ,
39738 SOURCE_PROJECT_ID ,
39739 SOURCE_TASK_ID,
39740 SOURCE_CUSTOMER_SITE_ID ,
39741 SOURCE_BILL_ID ,
39742 SOURCE_CUSTOMER_ID,
39743 v_current_date,
39744 v_current_user,
39745 v_current_date,
39746 v_current_user
39747 FROM msc_st_demands
39748 WHERE rowid = lb_rowid(j);
39749
39750 END IF;
39751 CLOSE c3 ;
39752
39753 lv_return:= MSC_ST_UTIL.SET_PROCESS_FLAG
39754 (p_table_name => 'MSC_ST_DEMANDS',
39755 p_instance_id => v_instance_id,
39756 p_instance_code => v_instance_code,
39757 p_process_flag => G_VALID,
39758 p_error_text => lv_error_text,
39759 p_debug => v_debug,
39760 p_batch_id => p_batch_id);
39761
39762 IF lv_return<> 0 THEN
39763 RAISE ex_logging_err;
39764 END IF;
39765
39766 lv_return:= MSC_ST_UTIL.LOG_ERROR
39767 (p_table_name => 'MSC_ST_DEMANDS',
39768 p_instance_code => v_instance_code,
39769 p_row => lv_column_names,
39770 p_severity => G_SEV_ERROR,
39771 p_message_text => NULL,
39772 p_error_text => lv_error_text,
39773 p_debug => v_debug,
39774 p_batch_id => p_batch_id);
39775
39776 IF lv_return<> 0 THEN
39777 RAISE ex_logging_err;
39778 END IF;
39779
39780 COMMIT;
39781
39782 EXCEPTION
39783
39784 WHEN too_many_rows THEN
39785 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_MDS_FORECAST'||'('
39786 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
39787 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
39788
39789 ROLLBACK ;
39790
39791 WHEN ex_logging_err THEN
39792 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
39793
39794 ROLLBACK;
39795
39796 WHEN OTHERS THEN
39797 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_MDS_FORECAST'||'('
39798 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
39799 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
39800
39801 ROLLBACK;
39802
39803 END LOAD_MDS_FORECAST ;
39804
39805 /*==========================================================================+
39806 | DESCRIPTION : This procedure derives the sr_company_id and the partner |
39807 | type for the business object Company users. |
39808 +==========================================================================*/
39809 PROCEDURE LOAD_COMPANY_USERS IS
39810
39811 ex_logging_err EXCEPTION;
39812 lv_return NUMBER;
39813 lv_error_text VARCHAR2(250);
39814 lv_sql_stmt VARCHAR2(5000);
39815 lv_batch_id msc_st_company_users.batch_id%TYPE;
39816 lv_message_text msc_errors.error_text%TYPE;
39817
39818 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
39819 lb_rowid RowidTab;
39820
39821 CURSOR c1(p_batch_id NUMBER) IS
39822 SELECT mscu.rowid
39823 FROM MSC_ST_COMPANY_USERS mscu
39824 WHERE mscu.process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
39825 AND mscu.sr_instance_code = v_instance_code
39826 AND batch_id = p_batch_id;
39827
39828 BEGIN
39829
39830 LOOP
39831 v_sql_stmt := 01;
39832
39833 SELECT msc_st_batch_id_s.NEXTVAL
39834 INTO lv_batch_id
39835 FROM DUAL;
39836
39837 v_sql_stmt := 02;
39838 lv_sql_stmt :=
39839 ' UPDATE MSC_ST_COMPANY_USERS '
39840 ||' SET batch_id = :lv_batch_id'
39841 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
39842 ||' AND sr_instance_code = :v_instance_code'
39843 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
39844 ||' AND rownum <= '||v_batch_size;
39845
39846
39847 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
39848
39849 EXECUTE IMMEDIATE lv_sql_stmt
39850 USING lv_batch_id,
39851 v_instance_code;
39852
39853 EXIT WHEN SQL%NOTFOUND;
39854
39855 OPEN c1(lv_batch_id);
39856 FETCH c1 BULK COLLECT INTO lb_rowid;
39857 CLOSE c1;
39858
39859 v_sql_stmt := 03;
39860
39861 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
39862 UPDATE MSC_ST_COMPANY_USERS
39863 SET st_transaction_id = msc_st_company_users_s.NEXTVAL,
39864 refresh_id = v_refresh_id,
39865 last_update_date = v_current_date,
39866 last_update_login = v_current_user,
39867 creation_date = v_current_date,
39868 created_by = v_current_user
39869 WHERE rowid = lb_rowid(j);
39870
39871 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
39872 (p_app_short_name => 'MSC',
39873 p_error_code => 'MSC_PP_INVALID_VALUE',
39874 p_message_text => lv_message_text,
39875 p_error_text => lv_error_text,
39876 p_token1 => 'COLUMN_NAME',
39877 p_token_value1 => 'COMPANY_NAME');
39878
39879 IF lv_return <> 0 THEN
39880 RAISE ex_logging_err;
39881 END IF;
39882
39883
39884 lv_return := MSC_ST_UTIL.DERIVE_COMPANY_ID
39885 (p_table_name => 'MSC_ST_COMPANY_USERS',
39886 p_company_name => 'COMPANY_NAME',
39887 p_company_id => 'SR_COMPANY_ID',
39888 p_instance_code => v_instance_code,
39889 p_error_text => lv_error_text,
39890 p_batch_id => lv_batch_id,
39891 p_message_text => lv_message_text,
39892 p_debug => v_debug);
39893
39894 IF lv_return <> 0 THEN
39895 RAISE ex_logging_err;
39896 END IF;
39897
39898 /* Calling derive_company_id
39899 v_sql_stmt := 04;
39900
39901 UPDATE MSC_ST_COMPANY_USERS mscu
39902 SET SR_COMPANY_ID = (SELECT local_id from MSC_LOCAL_ID_SETUP
39903 WHERE char1 = mscu.sr_instance_code
39904 and NVL(char3,NULL_CHAR) = NVL(mscu.company_name,NULL_CHAR)
39905 and entity_name = 'SR_TP_ID'
39906 and rownum = 1) -- we need the first occurence of sr_tp_id
39907 WHERE mscu.process_flag = G_IN_PROCESS
39908 AND mscu.sr_instance_code = v_instance_code
39909 AND mscu.batch_id = lv_batch_id;
39910
39911 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
39912 (p_app_short_name => 'MSC',
39913 p_error_code => 'MSC_PP_INVALID_VALUE',
39914 p_message_text => lv_message_text,
39915 p_error_text => lv_error_text,
39916 p_token1 => 'COLUMN_NAME',
39917 p_token_value1 => 'COMPANY_NAME');
39918
39919 IF lv_return <> 0 THEN
39920 RAISE ex_logging_err;
39921 END IF;
39922
39923 v_sql_stmt := 05;
39924
39925 UPDATE msc_st_company_users
39926 SET process_flag = G_ERROR_FLG,
39927 error_text = lv_message_text
39928 WHERE NVL(sr_company_id,NULL_VALUE) = NULL_VALUE
39929 AND NVL(company_name,'-1') <> '-1'
39930 AND process_flag = G_IN_PROCESS
39931 AND batch_id = lv_batch_id
39932 AND sr_instance_code = v_instance_code;
39933 */
39934 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
39935 (p_app_short_name => 'MSC',
39936 p_error_code => 'MSC_PP_INVALID_VALUE',
39937 p_message_text => lv_message_text,
39938 p_error_text => lv_error_text,
39939 p_token1 => 'COLUMN_NAME',
39940 p_token_value1 => 'USER_NAME');
39941
39942 IF lv_return <> 0 THEN
39943 RAISE ex_logging_err;
39944 END IF;
39945
39946 v_sql_stmt := 05.1;
39947
39948
39949 UPDATE msc_st_company_users mscu
39950 SET mscu.process_flag = G_ERROR_FLG,
39951 mscu.error_text = lv_message_text
39952 WHERE ( mscu.user_name IS NULL OR NOT EXISTS(select '1' from fnd_user fu where fu.user_name =UPPER(mscu.user_name)))
39953 AND mscu.process_flag = G_IN_PROCESS
39954 AND mscu.batch_id = lv_batch_id
39955 AND mscu.sr_instance_code = v_instance_code;
39956
39957 v_sql_stmt := 05;
39958
39959 UPDATE MSC_ST_COMPANY_USERS mscu
39960 SET PARTNER_TYPE = (SELECT number1 from MSC_LOCAL_ID_SETUP
39961 WHERE char1 = mscu.sr_instance_code
39962 and NVL(char3,NULL_CHAR) = NVL(mscu.company_name,NULL_CHAR)
39963 and entity_name = 'SR_TP_ID'
39964 and number1 in (1,2)
39965 and rownum = 1) -- we need the first occurence of sr_tp_id
39966 WHERE mscu.process_flag = G_IN_PROCESS
39967 AND mscu.sr_instance_code = v_instance_code
39968 AND mscu.batch_id = lv_batch_id;
39969
39970
39971 --Call to customised validation.
39972
39973 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
39974 (ERRBUF => lv_error_text,
39975 RETCODE => lv_return,
39976 pBatchID => lv_batch_id,
39977 pInstanceCode => v_instance_code,
39978 pEntityName => 'MSC_ST_COMPANY_USERS',
39979 pInstanceID => v_instance_id);
39980
39981 IF NVL(lv_return,0) <> 0 THEN
39982 RAISE ex_logging_err;
39983 END IF;
39984
39985 -- Set the process flag as Valid and poulate instance_id
39986 lv_return :=
39987 MSC_ST_UTIL.SET_PROCESS_FLAG(p_table_name => 'MSC_ST_COMPANY_USERS',
39988 p_instance_id => v_instance_id,
39989 p_instance_code => v_instance_code,
39990 p_process_flag => G_VALID,
39991 p_error_text => lv_error_text,
39992 p_debug => v_debug,
39993 p_batch_id => lv_batch_id);
39994
39995 IF lv_return < 0 THEN
39996 RAISE ex_logging_err;
39997 END IF;
39998 COMMIT;
39999
40000 END LOOP;
40001
40002 EXCEPTION
40003 WHEN too_many_rows THEN
40004 lv_error_text :=substr('MSC_CL_PRE_PROCESS.LOAD_COMPANY_USERS'||'('
40005 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
40006 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
40007
40008 ROLLBACK ;
40009
40010 WHEN ex_logging_err THEN
40011 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'MSC_CL_PRE_PROCESS.LOAD_COMPANY_USERS: '||lv_error_text);
40012 ROLLBACK;
40013
40014 WHEN OTHERS THEN
40015 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_COMPANY_USERS'||'('
40016 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
40017 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
40018 ROLLBACK;
40019
40020 END LOAD_COMPANY_USERS;
40021
40022 /*==========================================================================+
40023 | DESCRIPTION : This function performs insertion of co products records |
40024 | into msc_st_bom_componenets plus updates the records in |
40025 | msc_st_boms. Its called from LOAD_BOM after pre processing |
40026 | CO PRODUCTS. Included for OSFM Integration |
40027 +==========================================================================*/
40028
40029 PROCEDURE LOAD_CO_PRODUCT_BOMS IS
40030
40031 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
40032 lb_rowid RowidTab;
40033 lv_sql_stmt VARCHAR2(5000);
40034 v_query_str1 varchar2(6000);
40035 v_query_str2 varchar2(6000);
40036 v_query_str3 varchar2(6000);
40037 type cur_type is ref cursor;
40038 cur1 cur_type;
40039 cur2 cur_type;
40040 cur3 cur_type;
40041 l_co_product_id_cur1 Number;
40042 l_component_id_cur1 Number;
40043 l_split_cur1 Number;
40044 l_primary_flag_cur1 Number;
40045 l_bill_sequence_id_cur2 Number;
40046 l_rowid_cur2 rowid;
40047 l_co_product_id_cur3 Number;
40048 l_component_id_cur3 Number;
40049 l_split_cur3 Number;
40050 l_primary_flag_cur3 Number;
40051 lv_return NUMBER;
40052 lv_error_text VARCHAR2(250);
40053 lv_ODS_flag NUMBER; -- 1 if record from BOM ODS else 0.
40054 ex_logging_err EXCEPTION;
40055
40056 CURSOR c1 IS
40057 SELECT rowid
40058 FROM msc_st_bom_components
40059 WHERE process_flag = G_IN_PROCESS
40060 AND sr_instance_code = v_instance_code
40061 AND NVL(component_sequence_id,NULL_VALUE) = NULL_VALUE
40062 AND deleted_flag = SYS_NO;
40063
40064
40065
40066 BEGIN
40067
40068 -- selecting all the valid Co Products in the table --
40069 v_query_str1 := ' select mcp.co_product_id, '
40070 || ' mcp.component_id, '
40071 || ' mcp.split, '
40072 || ' mcp.primary_flag '
40073 || ' from msc_st_co_products mcp'
40074 || ' where process_flag = '|| G_VALID
40075 || ' and sr_instance_code = :v_instance_code ';
40076
40077
40078 -- selecting all the valid boms for the selected Co Product from staging table + ODS--
40079 v_query_str2 := ' select msb.bill_sequence_id,msb.rowid,0 '
40080 || ' from msc_st_boms msb '
40081 || ' where msb.assembly_item_id = :lv_assembly_item_id '
40082 || ' AND msb.process_flag = '|| G_VALID
40083 || ' and sr_instance_code = :v_instance_code '
40084 || ' UNION '
40085 || ' select mb.bill_sequence_id,mb.rowid,1 '
40086 || ' from msc_boms mb, MSC_ITEM_ID_LID lid '
40087 || ' where mb.assembly_item_id = lid.INVENTORY_ITEM_ID '
40088 || ' and mb.sr_instance_id= :v_instance_id '
40089 || ' and lid.SR_INVENTORY_ITEM_ID = :lv_assembly_item_id '
40090 || ' and lid.SR_INSTANCE_ID = :v_instance_id '
40091 || ' and mb.bill_sequence_id not in '
40092 || ' ( select msb1.bill_sequence_id '
40093 || ' from msc_st_boms msb1'
40094 || ' where msb1.assembly_item_id = :lv_assembly_item_id '
40095 || ' AND msb1.process_flag = '|| G_VALID
40096 || ' and sr_instance_code = :v_instance_code )';
40097
40098
40099
40100 -- selecting all the other valid Co products for the selected Co Product and Component--
40101 v_query_str3 := ' select mcp.co_product_id, '
40102 || ' mcp.component_id, '
40103 || ' mcp.split, '
40104 || ' mcp.primary_flag '
40105 || ' from msc_st_co_products mcp'
40106 || ' where process_flag = '|| G_VALID
40107 || ' and component_id = :lv_assembly_item_id '
40108 || ' and co_product_id <> :lv_co_product_id ';
40109
40110
40111
40112
40113
40114 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,v_query_str1);
40115
40116 v_sql_stmt := 01;
40117 OPEN cur1 FOR v_query_str1 USING v_instance_code;
40118 LOOP
40119
40120 FETCH cur1 INTO
40121 l_co_product_id_cur1,l_component_id_cur1,l_split_cur1,l_primary_flag_cur1;
40122
40123 EXIT WHEN cur1%NOTFOUND;
40124
40125
40126 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,v_query_str2);
40127
40128
40129 v_sql_stmt := 02;
40130 OPEN cur2 FOR v_query_str2 USING l_co_product_id_cur1,v_instance_code,
40131 v_instance_id,l_co_product_id_cur1,v_instance_id,l_co_product_id_cur1,v_instance_code;
40132
40133 LOOP
40134
40135 FETCH cur2 INTO l_bill_sequence_id_cur2,l_rowid_cur2,lv_ODS_flag ;
40136
40137 EXIT WHEN cur2%NOTFOUND;
40138
40139 -- set the primary_flag for the actual component to "not a primary" --
40140 -- this means whether a co product is primary or not would matter only --
40141 -- for the set of products not including the actual component --
40142 v_sql_stmt := 03;
40143 lv_sql_stmt :=
40144
40145 'update MSC_ST_BOM_COMPONENTS x'
40146 || ' set x.primary_flag = 2'
40147 || ' where x.bill_Sequence_id='||l_bill_sequence_id_cur2
40148 || ' and x.primary_flag is null '
40149 || ' and nvl(x.component_type,0) != 10 ' -- component_type is 10 for co products
40150 || ' and x.usage_quantity > 0 '
40151 || ' and x.inventory_item_id =' ||l_component_id_cur1;
40152
40153
40154 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
40155
40156 EXECUTE IMMEDIATE lv_sql_stmt;
40157 OPEN cur3 FOR v_query_str3 USING l_component_id_cur1, l_co_product_id_cur1;
40158
40159 LOOP
40160
40161
40162 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,v_query_str3);
40163
40164 v_sql_stmt := 04;
40165 FETCH cur3 INTO
40166 l_co_product_id_cur3,l_component_id_cur3,l_split_cur3,l_primary_flag_cur3;
40167
40168 EXIT WHEN cur3%NOTFOUND;
40169
40170 v_sql_stmt := 05;
40171 insert into MSC_ST_BOM_COMPONENTS
40172 ( INVENTORY_ITEM_ID,
40173 BILL_SEQUENCE_ID,
40174 COMPONENT_TYPE,
40175 USAGE_QUANTITY,
40176 COMPONENT_YIELD_FACTOR,
40177 EFFECTIVITY_DATE,
40178 DISABLE_DATE,
40179 OPERATION_OFFSET_PERCENT,
40180 OPTIONAL_COMPONENT,
40181 WIP_SUPPLY_TYPE,
40182 PLANNING_FACTOR,
40183 REVISED_ITEM_SEQUENCE_ID,
40184 ATP_FLAG,
40185 STATUS_TYPE,
40186 USE_UP_CODE,
40187 CHANGE_NOTICE,
40188 ORGANIZATION_ID,
40189 USING_ASSEMBLY_ID,
40190 FROM_UNIT_NUMBER,
40191 TO_UNIT_NUMBER,
40192 DRIVING_ITEM_ID,
40193 DELETED_FLAG,
40194 REFRESH_ID,
40195 SR_INSTANCE_CODE,
40196 PRIMARY_FLAG,
40197 ROUNDING_DIRECTION,
40198 process_flag)
40199 select
40200 l_co_product_id_cur3,
40201 l_bill_sequence_id_cur2,
40202 10,
40203 -(l_split_cur3/100),
40204 x.COMPONENT_YIELD_FACTOR,
40205 x.EFFECTIVITY_DATE,
40206 x.DISABLE_DATE,
40207 x.OPERATION_OFFSET_PERCENT,
40208 x.OPTIONAL_COMPONENT,
40209 x.WIP_SUPPLY_TYPE,
40210 x.PLANNING_FACTOR,
40211 x.REVISED_ITEM_SEQUENCE_ID,
40212 x.ATP_FLAG,
40213 x.STATUS_TYPE,
40214 x.USE_UP_CODE,
40215 x.CHANGE_NOTICE,
40216 x.ORGANIZATION_ID,
40217 l_co_product_id_cur1,
40218 x.FROM_UNIT_NUMBER,
40219 x.TO_UNIT_NUMBER,
40220 x.DRIVING_ITEM_ID,
40221 2,
40222 refresh_id,
40223 v_instance_code,
40224 l_primary_flag_cur3,
40225 3,
40226 2
40227 FROM MSC_ST_BOM_COMPONENTS x
40228 WHERE x.bill_Sequence_id = l_bill_sequence_id_cur2
40229 AND x.sr_instance_id = v_instance_id
40230 AND rownum = 1; -- so that in the next loop only 1 record is inserted
40231
40232 End loop;
40233
40234 IF lv_ODS_flag = 0 THEN -- if the BOM record is in the staging table
40235
40236 v_sql_stmt := 06;
40237 update msc_st_boms
40238 set assembly_quantity = (l_split_cur1/100)
40239 where rowid = l_rowid_cur2 ;
40240
40241 ELSE -- if the BOM record is in the ODS
40242
40243 v_sql_stmt := 07;
40244 insert into MSC_ST_BOMS
40245 ( BILL_SEQUENCE_ID,
40246 ORGANIZATION_ID,
40247 ASSEMBLY_ITEM_ID,
40248 ASSEMBLY_TYPE,
40249 ALTERNATE_BOM_DESIGNATOR,
40250 SPECIFIC_ASSEMBLY_COMMENT,
40251 SCALING_TYPE,
40252 PENDING_FROM_ECN,
40253 UOM,
40254 ASSEMBLY_QUANTITY,
40255 DELETED_FLAG,
40256 REFRESH_ID,
40257 SR_INSTANCE_ID)
40258 SELECT
40259 msb.BILL_SEQUENCE_ID,
40260 msb.ORGANIZATION_ID,
40261 lid.SR_INVENTORY_ITEM_ID,
40262 msb.ASSEMBLY_TYPE,
40263 msb.ALTERNATE_BOM_DESIGNATOR,
40264 msb.SPECIFIC_ASSEMBLY_COMMENT,
40265 msb.SCALING_TYPE,
40266 msb.PENDING_FROM_ECN,
40267 msb.UOM,
40268 (l_split_cur1/100),
40269 2,
40270 v_refresh_id,
40271 v_instance_id
40272 -- note the join on MSC_ITEM_ID_LID because MSC_BOMS stores ASSEMBLY_ITEM_ID
40273 -- and MSC_ST_BOMS stores SR_INVENTORY_ITEM_ID in ASSEMBLY_ITEM_ID
40274 FROM MSC_BOMS msb ,MSC_ITEM_ID_LID lid
40275 WHERE msb. BILL_SEQUENCE_ID = l_bill_sequence_id_cur2
40276 And lid.SR_INSTANCE_ID = msb.SR_INSTANCE_ID
40277 AND lid.INVENTORY_ITEM_ID = msb.ASSEMBLY_ITEM_ID ;
40278
40279 END IF;
40280
40281
40282 ENd loop;
40283
40284 v_sql_stmt := 08;
40285 -- Derive the component_sequence_id --
40286 lv_sql_stmt :=
40287 'UPDATE msc_st_bom_components mbc'
40288 ||' SET component_sequence_id= (SELECT local_id '
40289 ||' FROM msc_local_id_setup mlis'
40290 ||' WHERE mlis.char1 = mbc.sr_instance_code'
40291 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
40292 ||' = NVL(mbc.company_name,'||''''||NULL_CHAR||''''||') '
40293 ||' AND mlis.char3 = mbc.organization_code'
40294 ||' AND mlis.char4 = mbc.bom_name'
40295 ||' AND mlis.char5 = mbc.component_name'
40296 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
40297 ||' = NVL(mbc.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
40298 ||' AND mlis.char7 = mbc.operation_seq_code'
40299 ||' AND mlis.date1 = mbc.effectivity_date'
40300 ||' AND mlis.entity_name = ''COMPONENT_SEQUENCE_ID'')'
40301 ||' WHERE mbc.sr_instance_code = :v_instance_code'
40302 ||' AND mbc.process_flag ='|| G_IN_PROCESS ;
40303
40304
40305
40306
40307 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
40308
40309 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
40310
40311 -- Generate the component sequence id
40312 v_sql_stmt := 09;
40313 OPEN c1;
40314 FETCH c1 BULK COLLECT INTO lb_rowid ;
40315
40316 IF c1%ROWCOUNT > 0 THEN
40317 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
40318
40319 UPDATE msc_st_bom_components
40320 SET component_sequence_id = msc_st_component_sequence_id_s.NEXTVAL
40321 WHERE rowid = lb_rowid(j);
40322
40323
40324 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
40325
40326 -- Insert into the LID table
40327
40328 INSERT INTO msc_local_id_setup
40329 (local_id,
40330 st_transaction_id,
40331 instance_id,
40332 entity_name,
40333 data_source_type,
40334 char1,
40335 char2,
40336 char3,
40337 char4,
40338 char5,
40339 char6,
40340 char7,
40341 date1,
40342 date2,
40343 last_update_date,
40344 last_updated_by,
40345 creation_date,
40346 created_by )
40347 SELECT
40348 component_sequence_id,
40349 st_transaction_id,
40350 v_instance_id,
40351 'COMPONENT_SEQUENCE_ID',
40352 data_source_type,
40353 sr_instance_code,
40354 company_name,
40355 organization_code,
40356 bom_name,
40357 component_name,
40358 alternate_bom_designator,
40359 operation_seq_code,
40360 effectivity_date,
40361 disable_date,
40362 v_current_date,
40363 v_current_user,
40364 v_current_date,
40365 v_current_user
40366 FROM msc_st_bom_components
40367 WHERE rowid = lb_rowid(j) ;
40368
40369 END IF;
40370 CLOSE c1;
40371 COMMIT;
40372 End Loop;
40373
40374 -- Set the process flag as Valid and poulate instance_id
40375 lv_return :=
40376 MSC_ST_UTIL.SET_PROCESS_FLAG(p_table_name => 'MSC_ST_BOM_COMPONENTS',
40377 p_instance_id => v_instance_id,
40378 p_instance_code => v_instance_code,
40379 p_process_flag => G_VALID,
40380 p_error_text => lv_error_text,
40381 p_debug => v_debug);
40382
40383 IF lv_return <> 0 THEN
40384 RAISE ex_logging_err;
40385 END IF;
40386
40387 EXCEPTION
40388
40389 WHEN OTHERS THEN
40390 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_CO_PRODUCT_BOMS'||'('
40391 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
40392 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
40393 ROLLBACK;
40394
40395
40396 END LOAD_CO_PRODUCT_BOMS; /*osfm change */
40397
40398
40399 /*==========================================================================+
40400 | DESCRIPTION : This function performs the validation and loads the data |
40401 | for business object BOM. |
40402 +==========================================================================*/
40403 PROCEDURE LOAD_BOM IS
40404
40405 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
40406 TYPE CurTyp IS REF CURSOR;
40407 c1 CurTyp;
40408 lb_rowid RowidTab;
40409
40410 lv_column_names VARCHAR2(5000); -- Stores cocatenated column names
40411 lv_return NUMBER;
40412 lv_error_text VARCHAR2(250);
40413 lv_where_str VARCHAR2(5000);
40414 lv_sql_stmt VARCHAR2(5000);
40415 lv_cursor_stmt VARCHAR2(5000);
40416 lv_batch_id msc_st_boms.batch_id%TYPE;
40417 lv_message_text msc_errors.error_text%TYPE;
40418
40419 ex_logging_err EXCEPTION;
40420
40421 CURSOR c2(p_batch_id NUMBER) IS
40422 SELECT rowid
40423 FROM msc_st_boms
40424 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
40425 AND sr_instance_code = v_instance_code
40426 AND batch_id = p_batch_id;
40427
40428 CURSOR c3(p_batch_id NUMBER) IS
40429 SELECT rowid
40430 FROM msc_st_boms
40431 WHERE process_flag = G_IN_PROCESS
40432 AND sr_instance_code = v_instance_code
40433 AND batch_id = p_batch_id
40434 AND NVL(bill_sequence_id,NULL_VALUE) = NULL_VALUE
40435 AND deleted_flag = SYS_NO;
40436
40437 CURSOR c4(p_batch_id NUMBER) IS
40438 SELECT rowid
40439 FROM msc_st_bom_components
40440 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
40441 AND sr_instance_code = v_instance_code
40442 AND batch_id = p_batch_id;
40443
40444 CURSOR c5(p_batch_id NUMBER) IS
40445 SELECT rowid
40446 FROM msc_st_bom_components
40447 WHERE process_flag = G_IN_PROCESS
40448 AND sr_instance_code = v_instance_code
40449 AND batch_id = p_batch_id
40450 AND NVL(component_sequence_id,NULL_VALUE) = NULL_VALUE
40451 AND deleted_flag = SYS_NO;
40452
40453 CURSOR c6(p_batch_id NUMBER) IS
40454 SELECT rowid
40455 FROM msc_st_component_substitutes
40456 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
40457 AND sr_instance_code = v_instance_code
40458 AND batch_id = p_batch_id;
40459
40460 CURSOR c7(p_batch_id NUMBER) IS
40461 SELECT mlis.rowid
40462 FROM msc_st_bom_components mbc, msc_local_id_setup mlis
40463 WHERE mlis.char1 = mbc.sr_instance_code
40464 AND NVL(mlis.char2,'-23453') = NVL(mbc.company_name,'-23453')
40465 AND mlis.char3 = mbc.organization_code
40466 AND mlis.char4 = mbc.bom_name
40467 AND mlis.char5 = mbc.component_name
40468 AND NVL(mlis.char6,'-23453') = NVL(mbc.alternate_bom_designator,'-23453')
40469 AND mlis.char7 = mbc.operation_seq_code
40470 AND mlis.date1 = mbc.effectivity_date
40471 AND mbc.batch_id = p_batch_id
40472 AND mbc.deleted_flag = SYS_YES
40473 AND mbc.process_flag = G_IN_PROCESS
40474 AND mlis.entity_name = 'COMPONENT_SEQUENCE_ID'
40475 AND mlis.instance_id = v_instance_id ;
40476
40477 -- For Co Products --
40478 CURSOR c8(p_batch_id NUMBER) IS
40479 SELECT rowid
40480 FROM msc_st_co_products
40481 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
40482 AND sr_instance_code = v_instance_code
40483 AND batch_id = p_batch_id;
40484
40485 CURSOR c9 IS
40486 SELECT max(rowid)
40487 FROM msc_st_co_products
40488 WHERE process_flag = G_IN_PROCESS
40489 AND sr_instance_code = v_instance_code
40490 AND NVL(co_product_group_id,NULL_VALUE) = NULL_VALUE
40491 AND deleted_flag = SYS_NO
40492 GROUP BY component_name,sr_instance_code,company_name;
40493
40494
40495 BEGIN
40496
40497 -- Validation fo table msc_st_boms
40498
40499 -- Before we start processing the record by group id( batch size ) we are going
40500 -- to check whether that there
40501 -- is any duplicates for user defined unique keys (UDKs,)
40502
40503 --Duplicate records check for the records whose source is XML
40504
40505 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
40506 (p_app_short_name => 'MSC',
40507 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
40508 p_message_text => lv_message_text,
40509 p_error_text => lv_error_text);
40510
40511 IF lv_return <> 0 THEN
40512 RAISE ex_logging_err;
40513 END IF;
40514
40515 v_sql_stmt := 01;
40516 lv_sql_stmt :=
40517 'UPDATE msc_st_boms msb1'
40518 ||' SET process_flag = '||G_ERROR_FLG||','
40519 ||' error_text = '||''''||lv_message_text||''''
40520 ||' WHERE message_id < (SELECT MAX(message_id)'
40521 ||' FROM msc_st_boms msb2'
40522 ||' WHERE msb2.sr_instance_code = msb1.sr_instance_code'
40523 ||' AND msb2.organization_code = msb1.organization_code'
40524 ||' AND NVL(msb2.bom_name,'||''''||NULL_CHAR||''''||') '
40525 ||' = NVL(msb1.bom_name, '||''''||NULL_CHAR||''''||') '
40526 ||' AND NVL(msb2.company_name,'||''''||NULL_CHAR||''''||') '
40527 ||' = NVL(msb1.company_name, '||''''||NULL_CHAR||''''||') '
40528 ||' AND msb2.assembly_name = msb1.assembly_name'
40529 ||' AND NVL(msb2.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
40530 ||' = NVL(msb1.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
40531 ||' AND msb2.process_flag = '||G_IN_PROCESS
40532 ||' AND NVL(msb2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||') '
40533 ||' AND msb1.process_flag ='|| G_IN_PROCESS
40534 ||' AND msb1.sr_instance_code = :v_instance_code '
40535 ||' AND NVL(msb1.message_id,'||NULL_VALUE||')<> '||NULL_VALUE ;
40536
40537
40538 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
40539
40540 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
40541
40542 --Duplicate records check for the records whose source is batch load
40543
40544 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
40545 (p_app_short_name => 'MSC',
40546 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
40547 p_message_text => lv_message_text,
40548 p_error_text => lv_error_text);
40549
40550 IF lv_return <> 0 THEN
40551 RAISE ex_logging_err;
40552 END IF;
40553 v_sql_stmt := 02;
40554
40555 lv_sql_stmt :=
40556 'UPDATE msc_st_boms msb1'
40557 ||' SET process_flag = '||G_ERROR_FLG||','
40558 ||' error_text = '||''''||lv_message_text||''''
40559 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_boms msb2'
40560 ||' WHERE msb2.sr_instance_code = msb1.sr_instance_code'
40561 ||' AND msb2.organization_code = msb1.organization_code'
40562 ||' AND NVL(msb2.bom_name,'||''''||NULL_CHAR||''''||') '
40563 ||' = NVL(msb1.bom_name, '||''''||NULL_CHAR||''''||') '
40564 ||' AND NVL(msb2.company_name,'||''''||NULL_CHAR||''''||') '
40565 ||' = NVL(msb1.company_name, '||''''||NULL_CHAR||''''||') '
40566 ||' AND msb2.assembly_name = msb1.assembly_name'
40567 ||' AND NVL(msb2.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
40568 ||' = NVL(msb1.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
40569 ||' AND msb2.process_flag = '||G_IN_PROCESS
40570 ||' AND NVL(msb2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
40571 ||' AND msb2.rowid <> msb1.rowid)'
40572 ||' AND msb1.process_flag ='|| G_IN_PROCESS
40573 ||' AND msb1.sr_instance_code = :v_instance_code'
40574 ||' AND NVL(msb1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
40575
40576
40577 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
40578
40579 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
40580
40581
40582 lv_column_names :=
40583 'BOM_NAME ||''~''||'
40584 ||'ORGANIZATION_CODE ||''~''||'
40585 ||'ASSEMBLY_NAME ||''~''||'
40586 ||'ASSEMBLY_TYPE ||''~''||'
40587 ||'SR_INSTANCE_CODE ||''~''||'
40588 ||'ALTERNATE_BOM_DESIGNATOR ||''~''||'
40589 ||'SPECIFIC_ASSEMBLY_COMMENT ||''~''||'
40590 ||'PENDING_FROM_ECN ||''~''||'
40591 ||'BOM_SCALING_TYPE ||''~''||'
40592 ||'ASSEMBLY_QUANTITY ||''~''||'
40593 ||'UOM ||''~''||'
40594 ||'DELETED_FLAG ||''~''||'
40595 ||'COMPANY_NAME' ;
40596
40597 LOOP
40598 v_sql_stmt := 03;
40599 lv_cursor_stmt :=
40600 ' SELECT msc_st_batch_id_s.NEXTVAL '
40601 ||' FROM dual';
40602
40603 OPEN c1 FOR lv_cursor_stmt;
40604 FETCH c1 INTO lv_batch_id;
40605 CLOSE c1;
40606
40607 v_sql_stmt := 04;
40608 lv_sql_stmt :=
40609 ' UPDATE msc_st_boms '
40610 ||' SET batch_id = :lv_batch_id'
40611 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
40612 ||' AND sr_instance_code = :v_instance_code'
40613 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
40614 ||' AND rownum <= '||v_batch_size;
40615
40616
40617 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
40618
40619 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
40620
40621 EXIT WHEN SQL%NOTFOUND;
40622
40623 OPEN c2(lv_batch_id);
40624 FETCH c2 BULK COLLECT INTO lb_rowid;
40625 CLOSE c2;
40626
40627 v_sql_stmt := 05;
40628 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
40629 UPDATE msc_st_boms
40630 SET st_transaction_id = msc_st_boms_s.NEXTVAL,
40631 refresh_id = v_refresh_id,
40632 last_update_date = v_current_date,
40633 last_updated_by = v_current_user,
40634 creation_date = v_current_date,
40635 created_by = v_current_user
40636 WHERE rowid = lb_rowid(j);
40637
40638
40639 -- Set the error message
40640
40641 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
40642 (p_app_short_name => 'MSC',
40643 p_error_code => 'MSC_PP_NO_DELETION',
40644 p_message_text => lv_message_text,
40645 p_error_text => lv_error_text,
40646 p_token1 => 'TABLE_NAME',
40647 p_token_value1 => 'MSC_ST_BOMS');
40648
40649 IF lv_return <> 0 THEN
40650 RAISE ex_logging_err;
40651 END IF;
40652
40653 --Deletion is not allowed on this table.
40654 v_sql_stmt := 06;
40655 lv_sql_stmt :=
40656 ' UPDATE msc_st_boms '
40657 ||' SET process_flag = '||G_ERROR_FLG||','
40658 ||' error_text = '||''''||lv_message_text||''''
40659 ||' WHERE deleted_flag = '||SYS_YES
40660 ||' AND process_flag = '||G_IN_PROCESS
40661 ||' AND batch_id = :lv_batch_id'
40662 ||' AND sr_instance_code = :v_instance_code';
40663
40664
40665 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
40666
40667 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
40668
40669 -- Set the message
40670
40671 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
40672 (p_app_short_name => 'MSC',
40673 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
40674 p_message_text => lv_message_text,
40675 p_error_text => lv_error_text,
40676 p_token1 => 'COLUMN_NAME',
40677 p_token_value1 => 'DELETED_FLAG',
40678 p_token2 => 'DEFAULT_VALUE',
40679 p_token_value2 => SYS_NO);
40680
40681 IF lv_return <> 0 THEN
40682 RAISE ex_logging_err;
40683 END IF;
40684
40685
40686 -- Check DELETED_FLAG column has valid value or not and if not set it to SYS_NO
40687 -- Log error procedure inserts warning and also defaults the delete flag
40688
40689 lv_where_str := ' AND NVL(deleted_flag,'||NULL_VALUE||') <>'||SYS_NO;
40690
40691 lv_return := MSC_ST_UTIL.LOG_ERROR
40692 (p_table_name => 'MSC_ST_BOMS',
40693 p_instance_code => v_instance_code,
40694 p_row => lv_column_names,
40695 p_severity => G_SEV_WARNING,
40696 p_message_text => lv_message_text,
40697 p_error_text => lv_error_text,
40698 p_batch_id => lv_batch_id,
40699 p_where_str => lv_where_str,
40700 p_col_name => 'DELETED_FLAG',
40701 p_debug => v_debug,
40702 p_default_value => SYS_NO);
40703
40704
40705 IF lv_return <> 0 THEN
40706 RAISE ex_logging_err;
40707 END IF;
40708
40709 -- Set the message
40710
40711 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
40712 (p_app_short_name => 'MSC',
40713 p_error_code => 'MSC_PP_INVALID_VALUE',
40714 p_message_text => lv_message_text,
40715 p_error_text => lv_error_text,
40716 p_token1 => 'COLUMN_NAME',
40717 p_token_value1 => 'ORGANIZATION_CODE');
40718
40719 IF lv_return <> 0 THEN
40720 RAISE ex_logging_err;
40721 END IF;
40722
40723 -- Populate organization id
40724
40725 lv_return :=
40726 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name => 'MSC_ST_BOMS',
40727 p_org_partner_name => 'ORGANIZATION_CODE',
40728 p_org_partner_id => 'ORGANIZATION_ID',
40729 p_instance_code => v_instance_code,
40730 p_partner_type => G_ORGANIZATION,
40731 p_severity => G_SEV_ERROR,
40732 p_message_text => lv_message_text,
40733 p_batch_id => lv_batch_id,
40734 p_debug => v_debug,
40735 p_error_text => lv_error_text);
40736
40737 if(lv_return <> 0) then
40738 RAISE ex_logging_err;
40739 end if;
40740
40741 -- Set the message
40742
40743 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
40744 (p_app_short_name => 'MSC',
40745 p_error_code => 'MSC_PP_INVALID_VALUE',
40746 p_message_text => lv_message_text,
40747 p_error_text => lv_error_text,
40748 p_token1 => 'COLUMN_NAME',
40749 p_token_value1 => 'ASSEMBLY_NAME');
40750
40751 IF lv_return <> 0 THEN
40752 RAISE ex_logging_err;
40753 END IF;
40754
40755 -- Poplulate assembly item id
40756 lv_return :=
40757 MSC_ST_UTIL.DERIVE_ITEM_ID(p_table_name =>'MSC_ST_BOMS',
40758 p_item_col_name => 'ASSEMBLY_NAME',
40759 p_item_col_id =>'ASSEMBLY_ITEM_ID',
40760 p_instance_code => v_instance_code,
40761 p_instance_id => v_instance_id,
40762 p_severity => G_SEV_ERROR,
40763 p_message_text => lv_message_text,
40764 p_batch_id =>lv_batch_id,
40765 p_debug => v_debug,
40766 p_error_text =>lv_error_text);
40767
40768
40769 if(lv_return <> 0) then
40770 RAISE ex_logging_err;
40771 end if;
40772
40773
40774 -- Now we will check whether BOM Name is NULL , if it is NULL we will populate the
40775 -- ASSEMBLY NAME in BOM NAME column for all the records
40776
40777 v_sql_stmt := 07;
40778
40779 lv_sql_stmt :=
40780
40781 'UPDATE msc_st_boms msb'
40782 ||' SET msb.bom_name = msb.assembly_name'
40783 ||' WHERE sr_instance_code = :v_instance_code'
40784 ||' AND msb.process_flag ='||G_IN_PROCESS
40785 ||' AND NVL(msb.bom_name,'||''''||NULL_CHAR||''''||') '
40786 ||' = '||''''||NULL_CHAR||''''
40787 ||' AND msb.batch_id = :lv_batch_id';
40788
40789
40790 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
40791
40792 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
40793
40794
40795 -- Derive the BILL_SEQUENCE_ID for the BOM from LOCAL ID table
40796
40797 lv_return :=
40798 MSC_ST_UTIL.DERIVE_BILL_SEQUENCE_ID
40799 (p_table_name => 'MSC_ST_BOMS',
40800 p_bom_col_name => 'BOM_NAME',
40801 p_bom_col_id => 'BILL_SEQUENCE_ID',
40802 p_instance_code => v_instance_code,
40803 p_batch_id => lv_batch_id,
40804 p_debug => v_debug,
40805 p_error_text => lv_error_text);
40806
40807 IF (lv_return <> 0 ) THEN
40808 RAISE ex_logging_err;
40809 END IF;
40810
40811 -- Set the error message
40812 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
40813 (p_app_short_name => 'MSC',
40814 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
40815 p_message_text => lv_message_text,
40816 p_error_text => lv_error_text,
40817 p_token1 => 'COLUMN_NAME',
40818 p_token_value1 => 'ASSEMBLY_QUANTITY',
40819 p_token2 => 'DEFAULT_VALUE',
40820 p_token_value2 => G_ASSEMBLY_QUANTITY );
40821
40822 IF lv_return <> 0 THEN
40823 RAISE ex_logging_err;
40824 END IF;
40825
40826 -- To make ERP collection and Legacy in sync
40827 /* --ASSEMBLY_QUANTITY default to 1 if not provided
40828 --Log warning in error table
40829 lv_where_str :=
40830 ' AND NVL(assembly_quantity,'||NULL_VALUE||') ='|| NULL_VALUE;
40831
40832 lv_return := MSC_ST_UTIL.LOG_ERROR
40833 (p_table_name => 'MSC_ST_BOMS',
40834 p_instance_code => v_instance_code,
40835 p_row => lv_column_names,
40836 p_severity => G_SEV_WARNING,
40837 p_message_text => lv_message_text,
40838 p_error_text => lv_error_text,
40839 p_batch_id => lv_batch_id,
40840 p_where_str => lv_where_str,
40841 p_col_name => 'assembly_quantity',
40842 p_debug => v_debug,
40843 p_default_value => G_ASSEMBLY_QUANTITY);
40844
40845 IF lv_return <> 0 THEN
40846 RAISE ex_logging_err;
40847 END IF;
40848 */
40849 -- Now check for UOM code if it is Invalid error out
40850 -- Set the error message
40851
40852 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
40853 (p_app_short_name => 'MSC',
40854 p_error_code => 'MSC_PP_INVALID_VALUE',
40855 p_message_text => lv_message_text,
40856 p_error_text => lv_error_text,
40857 p_token1 => 'COLUMN_NAME',
40858 p_token_value1 => 'UOM_CODE');
40859
40860 IF lv_return <> 0 THEN
40861 RAISE ex_logging_err;
40862 END IF;
40863
40864 -- If UOM is provided validate the UOM_CODE
40865 -- For validation, use ODS table MSC_UNITS_OF_MEASURE table
40866 v_sql_stmt := 08;
40867
40868 lv_sql_stmt :=
40869 ' UPDATE msc_st_boms msb'
40870 ||' SET process_flag = '||G_ERROR_FLG||','
40871 ||' error_text = '||''''||lv_message_text||''''
40872 ||' WHERE NOT EXISTS (SELECT 1'
40873 ||' FROM msc_units_of_measure muom'
40874 ||' WHERE muom.uom_code = msb.uom'
40875 ||' UNION'
40876 ||' SELECT 1 FROM msc_st_units_of_measure msuom'
40877 ||' WHERE msuom.uom_code = msb.uom'
40878 ||' AND msuom.sr_instance_id = :v_instance_id'
40879 ||' AND msuom.process_flag = '||G_VALID||' )'
40880 ||' AND NVL(msb.uom,'||''''||NULL_CHAR||''''||') '
40881 ||' <> '||''''||NULL_CHAR||''''
40882 ||' AND msb.sr_instance_code = :v_instance_code'
40883 ||' AND msb.batch_id = :lv_batch_id'
40884 ||' AND msb.process_flag = '||G_IN_PROCESS ;
40885
40886
40887
40888 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
40889
40890 EXECUTE IMMEDIATE lv_sql_stmt
40891 USING v_instance_id,
40892 v_instance_code,
40893 lv_batch_id;
40894
40895 -- Set the error message
40896 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
40897 (p_app_short_name => 'MSC',
40898 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
40899 p_message_text => lv_message_text,
40900 p_error_text => lv_error_text,
40901 p_token1 => 'COLUMN_NAME',
40902 p_token_value1 => 'ASSEMBLY_TYPE',
40903 p_token2 => 'DEFAULT_VALUE',
40904 p_token_value2 => G_ASSEMBLY_TYPE );
40905
40906 IF lv_return <> 0 THEN
40907 RAISE ex_logging_err;
40908 END IF;
40909
40910 --ASSEMBLY_TYPE default to 1 if value NOT IN (1,2)
40911 --Log warning in error table
40912
40913 lv_where_str :=
40914 ' AND NVL(assembly_type,'||NULL_VALUE||') NOT IN (1,2)';
40915
40916 lv_return := MSC_ST_UTIL.LOG_ERROR
40917 (p_table_name => 'MSC_ST_BOMS',
40918 p_instance_code => v_instance_code,
40919 p_row => lv_column_names,
40920 p_severity => G_SEV_WARNING,
40921 p_message_text => lv_message_text,
40922 p_error_text => lv_error_text,
40923 p_batch_id => lv_batch_id,
40924 p_where_str => lv_where_str,
40925 p_col_name => 'ASSEMBLY_TYPE',
40926 p_debug => v_debug,
40927 p_default_value => G_ASSEMBLY_TYPE);
40928
40929
40930 IF lv_return <> 0 THEN
40931 RAISE ex_logging_err;
40932 END IF;
40933
40934 -- Set the error message
40935 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
40936 (p_app_short_name => 'MSC',
40937 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
40938 p_message_text => lv_message_text,
40939 p_error_text => lv_error_text,
40940 p_token1 => 'COLUMN_NAME',
40941 p_token_value1 => 'BOM_SCALING_TYPE',
40942 p_token2 => 'DEFAULT_VALUE',
40943 p_token_value2 => G_BOM_SCALING_TYPE );
40944
40945 IF lv_return <> 0 THEN
40946 RAISE ex_logging_err;
40947 END IF;
40948
40949 -- SCALING_TYPE NULL ( valid value NULL,0,1,2)
40950 -- Defaulting as NULL if invalid values
40951
40952 lv_where_str := ' AND bom_scaling_type NOT IN (0,1,2)';
40953
40954 lv_return := MSC_ST_UTIL.LOG_ERROR
40955 (p_table_name => 'MSC_ST_BOMS',
40956 p_instance_code => v_instance_code,
40957 p_row => lv_column_names,
40958 p_severity => G_SEV_WARNING,
40959 p_message_text => lv_message_text,
40960 p_error_text => lv_error_text,
40961 p_batch_id => lv_batch_id,
40962 p_where_str => lv_where_str,
40963 p_col_name => 'BOM_SCALING_TYPE',
40964 p_debug => v_debug,
40965 p_default_value => G_BOM_SCALING_TYPE);
40966
40967 IF lv_return <> 0 THEN
40968 RAISE ex_logging_err;
40969 END IF;
40970
40971 --Call to customised validation.
40972
40973 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
40974 (ERRBUF => lv_error_text,
40975 RETCODE => lv_return,
40976 pBatchID => lv_batch_id,
40977 pInstanceCode => v_instance_code,
40978 pEntityName => 'MSC_ST_BOMS',
40979 pInstanceID => v_instance_id);
40980
40981 IF NVL(lv_return,0) <> 0 THEN
40982 RAISE ex_logging_err;
40983 END IF;
40984
40985 -- Now generate bill_sequence_id for New BOM and populate the same in
40986 -- LID table and MSC_ST_BOMS , Sequence to be used MSC_ST_BILL_SEQUENCE_ID_S
40987
40988 v_sql_stmt := 09;
40989
40990 OPEN c3(lv_batch_id);
40991 FETCH c3 BULK COLLECT INTO lb_rowid ;
40992
40993 IF c3%ROWCOUNT > 0 THEN
40994
40995 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
40996
40997 UPDATE msc_st_boms
40998 SET bill_sequence_id = msc_st_bill_sequence_id_s.NEXTVAL
40999 WHERE rowid = lb_rowid(j);
41000
41001 v_sql_stmt := 10;
41002
41003 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
41004
41005 -- Insert into the LID table this new BOM with the user defined key
41006
41007 INSERT INTO msc_local_id_setup
41008 (local_id,
41009 st_transaction_id,
41010 instance_id,
41011 entity_name,
41012 data_source_type,
41013 char1,
41014 char2,
41015 char3,
41016 char4,
41017 char5,
41018 char6,
41019 SOURCE_ORGANIZATION_ID,
41020 SOURCE_BILL_SEQUENCE_ID,
41021 SOURCE_INVENTORY_ITEM_ID,
41022 last_update_date,
41023 last_updated_by,
41024 creation_date,
41025 created_by )
41026 SELECT
41027 bill_sequence_id,
41028 st_transaction_id,
41029 v_instance_id,
41030 'BILL_SEQUENCE_ID',
41031 data_source_type,
41032 sr_instance_code,
41033 company_name,
41034 organization_code,
41035 bom_name,
41036 assembly_name,
41037 alternate_bom_designator,
41038 SOURCE_ORGANIZATION_ID,
41039 SOURCE_BILL_SEQUENCE_ID,
41040 SOURCE_INVENTORY_ITEM_ID,
41041 v_current_date,
41042 v_current_user,
41043 v_current_date,
41044 v_current_user
41045 FROM msc_st_boms
41046 WHERE rowid = lb_rowid(j);
41047
41048 END IF;
41049 CLOSE c3;
41050
41051 -- Set the process flag as Valid and poulate instance_id
41052 lv_return :=
41053 MSC_ST_UTIL.SET_PROCESS_FLAG(p_table_name => 'MSC_ST_BOMS',
41054 p_instance_id => v_instance_id,
41055 p_instance_code => v_instance_code,
41056 p_process_flag => G_VALID,
41057 p_error_text => lv_error_text,
41058 p_debug => v_debug,
41059 p_batch_id => lv_batch_id);
41060
41061 IF lv_return <> 0 THEN
41062 RAISE ex_logging_err;
41063 END IF;
41064
41065 -- At the end calling the LOG_ERROR for logging all errored out records
41066
41067 lv_return :=
41068 MSC_ST_UTIL.LOG_ERROR(p_table_name =>'MSC_ST_BOMS',
41069 p_instance_code =>v_instance_code,
41070 p_row =>lv_column_names,
41071 p_severity =>G_SEV_ERROR,
41072 p_message_text =>NULL,
41073 p_error_text =>lv_error_text,
41074 p_debug => v_debug,
41075 p_batch_id => lv_batch_id );
41076
41077 IF(lv_return <> 0) then
41078 RAISE ex_logging_err;
41079 END IF;
41080 COMMIT;
41081 END LOOP;
41082
41083
41084 -- Now Validation for MSC_ST_BOM_COMPONENTS
41085
41086 --Duplicate records check for the records whose source is XML
41087
41088 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
41089 (p_app_short_name => 'MSC',
41090 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
41091 p_message_text => lv_message_text,
41092 p_error_text => lv_error_text);
41093
41094 IF lv_return <> 0 THEN
41095 RAISE ex_logging_err;
41096 END IF;
41097
41098 v_sql_stmt := 11;
41099
41100 lv_sql_stmt :=
41101 'UPDATE msc_st_bom_components mbc1'
41102 ||' SET process_flag = '||G_ERROR_FLG ||','
41103 ||' error_text = '||''''||lv_message_text||''''
41104 ||' WHERE message_id < ( SELECT max(message_id)'
41105 ||' FROM msc_st_bom_components mbc2'
41106 ||' WHERE mbc2.sr_instance_code = mbc1.sr_instance_code'
41107 ||' AND mbc2.organization_code = mbc1.organization_code'
41108 ||' AND NVL(mbc2.bom_name,'||''''||NULL_CHAR||''''||') '
41109 ||' = NVL(mbc1.bom_name, '||''''||NULL_CHAR||''''||') '
41110 ||' AND NVL(mbc2.company_name,'||''''||NULL_CHAR||''''||') '
41111 ||' = NVL(mbc1.company_name, '||''''||NULL_CHAR||''''||') '
41112 ||' AND mbc2.assembly_name = mbc1.assembly_name '
41113 ||' AND NVL(mbc2.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
41114 ||' = NVL(mbc1.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
41115 ||' AND mbc2.component_name = mbc1.component_name'
41116 ||' AND NVL(mbc2.effectivity_date,SYSDATE-36500 )'
41117 ||' = NVL(mbc1.effectivity_date,SYSDATE-36500)'
41118 ||' AND NVL(mbc2.operation_seq_code, '||''''||NULL_CHAR||''''||') '
41119 ||' = NVL(mbc1.operation_seq_code,'||''''||NULL_CHAR||''''||') '
41120 ||' AND mbc2.process_flag ='||G_IN_PROCESS
41121 ||' AND NVL(mbc2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||')'
41122 ||' AND mbc1.process_flag = '||G_IN_PROCESS
41123 ||' AND mbc1.sr_instance_code = :v_instance_code'
41124 ||' AND NVL(mbc1.message_id,'||NULL_VALUE||')<> '||NULL_VALUE;
41125
41126
41127 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
41128
41129 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
41130
41131 --Duplicate records check for the records whose source is batch load
41132
41133 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
41134 (p_app_short_name => 'MSC',
41135 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
41136 p_message_text => lv_message_text,
41137 p_error_text => lv_error_text);
41138
41139 IF lv_return <> 0 THEN
41140 RAISE ex_logging_err;
41141 END IF;
41142
41143 v_sql_stmt := 12;
41144 lv_sql_stmt:=
41145 'UPDATE msc_st_bom_components mbc1'
41146 ||' SET process_flag ='|| G_ERROR_FLG||','
41147 ||' error_text = '||''''||lv_message_text||''''
41148 ||' WHERE EXISTS ( SELECT 1'
41149 ||' FROM msc_st_bom_components mbc2'
41150 ||' WHERE mbc2.sr_instance_code = mbc1.sr_instance_code'
41151 ||' AND mbc2.organization_code = mbc1.organization_code'
41152 ||' AND NVL(mbc2.bom_name,'||''''||NULL_CHAR||''''||') '
41153 ||' = NVL(mbc1.bom_name, '||''''||NULL_CHAR||''''||') '
41154 ||' AND NVL(mbc2.company_name,'||''''||NULL_CHAR||''''||') '
41155 ||' = NVL(mbc1.company_name, '||''''||NULL_CHAR||''''||') '
41156 ||' AND mbc2.assembly_name = mbc1.assembly_name '
41157 ||' AND NVL(mbc2.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
41158 ||' = NVL(mbc1.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
41159 ||' AND mbc2.component_name = mbc1.component_name'
41160 ||' AND NVL(mbc2.effectivity_date,SYSDATE-36500 )'
41161 ||' = NVL(mbc1.effectivity_date,SYSDATE-36500 )'
41162 ||' AND NVL(mbc2.operation_seq_code,'||''''||NULL_CHAR||''''||') '
41163 ||' = NVL(mbc1.operation_seq_code,'||''''||NULL_CHAR||''''||') '
41164 ||' AND mbc2.process_flag ='||G_IN_PROCESS
41165 ||' AND NVL(mbc2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
41166 ||' AND mbc2.rowid <> mbc1.rowid)'
41167 ||' AND mbc1.process_flag ='|| G_IN_PROCESS
41168 ||' AND mbc1.sr_instance_code = :v_instance_code'
41169 ||' AND NVL(mbc1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
41170
41171
41172 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
41173
41174 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
41175
41176 lv_column_names :=
41177 'COMPONENT_NAME ||''~''||'
41178 ||'COMPONENT_TYPE ||''~''||'
41179 ||'BOM_NAME ||''~''||'
41180 ||'ORGANIZATION_CODE ||''~''||'
41181 ||'ASSEMBLY_NAME ||''~''||'
41182 ||'REVISION ||''~''||'
41183 ||'USAGE_QUANTITY ||''~''||'
41184 ||'COMPONENT_YIELD_FACTOR ||''~''||'
41185 ||'UOM_CODE ||''~''||'
41186 ||'SR_INSTANCE_CODE ||''~''||'
41187 ||'ALTERNATE_BOM_DESIGNATOR ||''~''||'
41188 ||'CHANGE_NOTICE ||''~''||'
41189 ||'SCALING_TYPE ||''~''||'
41190 ||'EFFECTIVITY_DATE ||''~''||'
41191 ||'DISABLE_DATE ||''~''||'
41192 ||'USE_UP_CODE ||''~''||'
41193 ||'OPERATION_OFFSET_PERCENT ||''~''||'
41194 ||'OPTIONAL_COMPONENT ||''~''||'
41195 ||'WIP_SUPPLY_TYPE ||''~''||'
41196 ||'PLANNING_FACTOR ||''~''||'
41197 ||'ATP_FLAG ||''~''||'
41198 ||'OPERATION_SEQ_CODE ||''~''||'
41199 ||'DELETED_FLAG ||''~''||'
41200 ||'DRIVING_ITEM_NAME ||''~''||'
41201 ||'COMPANY_NAME' ;
41202
41203
41204 -- Process msc_st_bom_components table
41205
41206 LOOP
41207 v_sql_stmt := 13;
41208 lv_cursor_stmt :=
41209 ' SELECT msc_st_batch_id_s.NEXTVAL '
41210 ||' FROM dual';
41211
41212 OPEN c1 FOR lv_cursor_stmt;
41213 FETCH c1 INTO lv_batch_id;
41214 CLOSE c1;
41215
41216 v_sql_stmt := 14;
41217 lv_sql_stmt :=
41218 ' UPDATE msc_st_bom_components '
41219 ||' SET batch_id = :lv_batch_id'
41220 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
41221 ||' AND sr_instance_code = :v_instance_code'
41222 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
41223 ||' AND rownum <= '||v_batch_size;
41224
41225
41226 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
41227
41228 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
41229
41230 EXIT WHEN SQL%NOTFOUND;
41231
41232 OPEN c4(lv_batch_id);
41233 FETCH c4 BULK COLLECT INTO lb_rowid;
41234 CLOSE c4;
41235
41236 v_sql_stmt := 1;
41237 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
41238 UPDATE msc_st_bom_components
41239 SET st_transaction_id = msc_st_bom_components_s.NEXTVAL,
41240 refresh_id = v_refresh_id,
41241 last_update_date = v_current_date,
41242 last_updated_by = v_current_user,
41243 creation_date = v_current_date,
41244 created_by = v_current_user
41245 WHERE rowid = lb_rowid(j);
41246
41247 -- Set the message
41248
41249 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
41250 (p_app_short_name => 'MSC',
41251 p_error_code => 'MSC_PP_INVALID_VALUE',
41252 p_message_text => lv_message_text,
41253 p_error_text => lv_error_text,
41254 p_token1 => 'COLUMN_NAME',
41255 p_token_value1 => 'COMPONENT_NAME');
41256
41257 IF lv_return <> 0 THEN
41258 RAISE ex_logging_err;
41259 END IF;
41260
41261 -- Populate Inventory Item id for component name
41262
41263 lv_return :=
41264 MSC_ST_UTIL.DERIVE_ITEM_ID(p_table_name => 'MSC_ST_BOM_COMPONENTS',
41265 p_item_col_name => 'COMPONENT_NAME',
41266 p_item_col_id => 'INVENTORY_ITEM_ID',
41267 p_instance_code => v_instance_code,
41268 p_instance_id => v_instance_id,
41269 p_severity => G_SEV_ERROR,
41270 p_message_text => lv_message_text,
41271 p_batch_id => lv_batch_id,
41272 p_debug => v_debug,
41273 p_error_text => lv_error_text);
41274
41275 if(lv_return <> 0) then
41276 RAISE ex_logging_err;
41277 end if;
41278
41279 -- Set the error message
41280 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
41281 (p_app_short_name => 'MSC',
41282 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
41283 p_message_text => lv_message_text,
41284 p_error_text => lv_error_text,
41285 p_token1 => 'COLUMN_NAME',
41286 p_token_value1 => 'DELETED_FLAG',
41287 p_token2 => 'DEFAULT_VALUE',
41288 p_token_value2 => SYS_NO );
41289
41290 IF lv_return <> 0 THEN
41291 RAISE ex_logging_err;
41292 END IF;
41293
41294 -- Check whether delete flag value is in (1,2),if not default to SYS_NO
41295
41296 lv_where_str := ' AND NVL(deleted_flag,'||NULL_VALUE||')NOT IN (1,2)';
41297
41298 lv_return := MSC_ST_UTIL.LOG_ERROR
41299 (p_table_name => 'MSC_ST_BOM_COMPONENTS',
41300 p_instance_code => v_instance_code,
41301 p_row => lv_column_names,
41302 p_severity => G_SEV_WARNING,
41303 p_message_text => lv_message_text,
41304 p_error_text => lv_error_text,
41305 p_batch_id => lv_batch_id,
41306 p_where_str => lv_where_str,
41307 p_col_name => 'DELETED_FLAG',
41308 p_debug => v_debug,
41309 p_default_value => SYS_NO);
41310
41311
41312 IF lv_return <> 0 THEN
41313 RAISE ex_logging_err;
41314 END IF;
41315
41316 -- Set the message
41317
41318 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
41319 (p_app_short_name => 'MSC',
41320 p_error_code => 'MSC_PP_INVALID_VALUE',
41321 p_message_text => lv_message_text,
41322 p_error_text => lv_error_text,
41323 p_token1 => 'COLUMN_NAME',
41324 p_token_value1 => 'ORGANIZATION_CODE');
41325
41326 IF lv_return <> 0 THEN
41327 RAISE ex_logging_err;
41328 END IF;
41329
41330 -- Populate organization id
41331
41332 lv_return :=
41333 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name => 'MSC_ST_BOM_COMPONENTS',
41334 p_org_partner_name =>'ORGANIZATION_CODE',
41335 p_org_partner_id =>'ORGANIZATION_ID',
41336 p_instance_code => v_instance_code,
41337 p_partner_type => G_ORGANIZATION,
41338 p_severity => G_SEV_ERROR,
41339 p_message_text => lv_message_text,
41340 p_batch_id =>lv_batch_id,
41341 p_debug => v_debug,
41342 p_error_text =>lv_error_text);
41343
41344 if(lv_return <> 0) then
41345 RAISE ex_logging_err;
41346 end if;
41347
41348 -- Now we will check whether BOM Name is NULL ,
41349 -- if it is NULL we will populate the
41350 -- ASSEMBLY NAME in BOM NAME column for all such records
41351
41352 v_sql_stmt := 17;
41353
41354 lv_sql_stmt :=
41355
41356 'UPDATE msc_st_bom_components '
41357 ||' SET bom_name = assembly_name'
41358 ||' WHERE sr_instance_code = :v_instance_code'
41359 ||' AND process_flag ='||G_IN_PROCESS
41360 ||' AND NVL(bom_name,'||''''||NULL_CHAR||''''||') '
41361 ||' = '||''''||NULL_CHAR||''''
41362 ||' AND NVL(assembly_name,'||''''||NULL_CHAR||''''||') '
41363 ||' <> '||''''||NULL_CHAR||''''
41364 ||' AND batch_id = :lv_batch_id';
41365
41366
41367
41368 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
41369
41370 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
41371
41372 -- Now derive assembly name for those records where assembly name is NULL
41373 -- If not able to get this error out those records
41374 -- In child table of BOM we will accept either BOM name/Assembly name or both
41375
41376 v_sql_stmt := 18;
41377
41378 lv_sql_stmt:=
41379 'UPDATE msc_st_bom_components mbc'
41380 ||' SET assembly_name = (SELECT char5'
41381 ||' FROM msc_local_id_setup mlis'
41382 ||' WHERE mlis.char1 = mbc.sr_instance_code'
41383 ||' AND mlis.char3 = mbc.organization_code'
41384 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
41385 ||' = NVL(mbc.company_name,'||''''||NULL_CHAR||''''||') '
41386 ||' AND mlis.char4 = mbc.bom_name'
41387 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
41388 ||' = NVL(mbc.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
41389 ||' AND mlis.entity_name =''BILL_SEQUENCE_ID'' '
41390 ||' AND mlis.instance_id = '||v_instance_id||' )'
41391 ||' WHERE sr_instance_code = :v_instance_code'
41392 ||' AND NVL(assembly_name,'||''''||NULL_CHAR||''''||') '
41393 ||' = '||''''||NULL_CHAR||''''
41394 ||' AND process_flag ='|| G_IN_PROCESS
41395 ||' AND batch_id = :lv_batch_id';
41396
41397
41398
41399 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
41400
41401 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
41402
41403 -- Set the message
41404
41405 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
41406 (p_app_short_name => 'MSC',
41407 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
41408 p_message_text => lv_message_text,
41409 p_error_text => lv_error_text,
41410 p_token1 => 'COLUMN_NAMES',
41411 p_token_value1 => 'BOM_NAME,INSTANCE_CODE,'
41412 ||' COMPANY_NAME,'
41413 ||'ALETERNATE_BOM_DESIGNATOR',
41414 p_token2 => 'MASTER_TABLE',
41415 p_token_value2 => 'MSC_ST_BOMS',
41416 p_token3 => 'CHILD_TABLE',
41417 p_token_value3 => 'MSC_ST_BOM_COMPONENTS');
41418
41419 IF lv_return <> 0 THEN
41420 RAISE ex_logging_err;
41421 END IF;
41422
41423 -- Error out records if assembly name is NULL
41424
41425 v_sql_stmt := 19;
41426
41427 lv_sql_stmt :=
41428 'UPDATE MSC_ST_BOM_COMPONENTS'
41429 ||' SET process_flag = '||G_ERROR_FLG||','
41430 ||' error_text = '||''''||lv_message_text||''''
41431 ||' WHERE NVL(assembly_name,'||''''||NULL_CHAR||''''||') '
41432 ||' = '||''''||NULL_CHAR||''''
41433 ||' AND process_flag = '||G_IN_PROCESS
41434 ||' AND sr_instance_code = :v_instance_code'
41435 ||' AND batch_id = :lv_batch_id';
41436
41437
41438 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
41439
41440 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
41441
41442 -- Set the message
41443
41444 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
41445 (p_app_short_name => 'MSC',
41446 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
41447 p_message_text => lv_message_text,
41448 p_error_text => lv_error_text,
41449 p_token1 => 'COLUMN_NAMES',
41450 p_token_value1 => 'BOM_NAME,INSTANCE_CODE,'
41451 ||' COMPANY_NAME,'
41452 ||'ALETERNATE_BOM_DESIGNATOR',
41453 p_token2 => 'MASTER_TABLE',
41454 p_token_value2 => 'MSC_ST_BOMS',
41455 p_token3 => 'CHILD_TABLE',
41456 p_token_value3 => 'MSC_ST_BOM_COMPONENTS');
41457
41458 IF lv_return <> 0 THEN
41459 RAISE ex_logging_err;
41460 END IF;
41461
41462
41463 -- Derive the Bill Sequence Id for the MSC_ST_BOM_COMPONENTS
41464 lv_return :=
41465 MSC_ST_UTIL.DERIVE_BILL_SEQUENCE_ID
41466 (p_table_name => 'MSC_ST_BOM_COMPONENTS',
41467 p_bom_col_name => 'BOM_NAME',
41468 p_bom_col_id => 'BILL_SEQUENCE_ID',
41469 p_instance_code => v_instance_code,
41470 p_severity => G_SEV_ERROR,
41471 p_message_text => lv_message_text,
41472 p_batch_id => lv_batch_id,
41473 p_debug => v_debug,
41474 p_error_text => lv_error_text);
41475
41476 IF (lv_return <> 0 )then
41477 RAISE ex_logging_err;
41478 END IF;
41479
41480 -- Set the error message
41481 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
41482 (p_app_short_name => 'MSC',
41483 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
41484 p_message_text => lv_message_text,
41485 p_error_text => lv_error_text,
41486 p_token1 => 'COLUMN_NAME',
41487 p_token_value1 => 'OPERATION_SEQ_CODE',
41488 p_token2 => 'DEFAULT_VALUE',
41489 p_token_value2 => G_OPERATION_SEQ_CODE );
41490
41491 IF lv_return <> 0 THEN
41492 RAISE ex_logging_err;
41493 END IF;
41494
41495 -- Default OPERATION_SEQ_CODE as 1 if it is NULL
41496 lv_where_str :=
41497 ' AND NVL(operation_seq_code,'||''''||NULL_CHAR||''''||') '
41498 ||' = '||''''||NULL_CHAR||'''' ;
41499
41500 lv_return := MSC_ST_UTIL.LOG_ERROR
41501 (p_table_name => 'MSC_ST_BOM_COMPONENTS',
41502 p_instance_code => v_instance_code,
41503 p_row => lv_column_names,
41504 p_severity => G_SEV_WARNING,
41505 p_message_text => lv_message_text,
41506 p_error_text => lv_error_text,
41507 p_batch_id => lv_batch_id,
41508 p_where_str => lv_where_str,
41509 p_col_name => 'OPERATION_SEQ_CODE',
41510 p_debug => v_debug,
41511 p_default_value => G_OPERATION_SEQ_CODE);
41512
41513
41514 IF lv_return <> 0 THEN
41515 RAISE ex_logging_err;
41516 END IF;
41517
41518 -- Set the error message
41519 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
41520 (p_app_short_name => 'MSC',
41521 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
41522 p_message_text => lv_message_text,
41523 p_error_text => lv_error_text,
41524 p_token1 => 'COLUMN_NAME',
41525 p_token_value1 => 'EFFECTIVITY_DATE',
41526 p_token2 => 'DEFAULT_VALUE',
41527 p_token_value2 => 'SYSDATE' );
41528
41529 IF lv_return <> 0 THEN
41530 RAISE ex_logging_err;
41531 END IF;
41532
41533
41534 -- Check the EFFECTIVITY_DATE , if it is NULL,default SYSDATE
41535
41536 lv_where_str :=
41537 ' AND NVL(effectivity_date,SYSDATE-36500 ) = SYSDATE-36500' ;
41538
41539 lv_return := MSC_ST_UTIL.LOG_ERROR
41540 (p_table_name => 'MSC_ST_BOM_COMPONENTS',
41541 p_instance_code => v_instance_code,
41542 p_row => lv_column_names,
41543 p_severity => G_SEV_WARNING,
41544 p_message_text => lv_message_text,
41545 p_error_text => lv_error_text,
41546 p_batch_id => lv_batch_id,
41547 p_where_str => lv_where_str,
41548 p_col_name => 'EFFECTIVITY_DATE',
41549 p_debug => v_debug,
41550 p_default_value => 'SYSDATE');
41551
41552 IF lv_return <> 0 THEN
41553 RAISE ex_logging_err;
41554 END IF;
41555
41556
41557 -- Derive the component_sequence_id
41558 v_sql_stmt := 20;
41559 lv_sql_stmt :=
41560 'UPDATE msc_st_bom_components mbc'
41561 ||' SET component_sequence_id= (SELECT local_id '
41562 ||' FROM msc_local_id_setup mlis'
41563 ||' WHERE mlis.char1 = mbc.sr_instance_code'
41564 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
41565 ||' = NVL(mbc.company_name,'||''''||NULL_CHAR||''''||') '
41566 ||' AND mlis.char3 = mbc.organization_code'
41567 ||' AND mlis.char4 = mbc.bom_name'
41568 ||' AND mlis.char5 = mbc.component_name'
41569 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
41570 ||' = NVL(mbc.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
41571 ||' AND mlis.char7 = mbc.operation_seq_code'
41572 ||' AND mlis.date1 = mbc.effectivity_date'
41573 ||' AND mlis.entity_name = ''COMPONENT_SEQUENCE_ID'')'
41574 ||' WHERE mbc.sr_instance_code = :v_instance_code'
41575 ||' AND mbc.process_flag ='|| G_IN_PROCESS
41576 ||' AND mbc.batch_id = :lv_batch_id';
41577
41578
41579 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
41580
41581 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
41582
41583 -- Set the message
41584
41585 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
41586 (p_app_short_name => 'MSC',
41587 p_error_code => 'MSC_PP_DELETE_FAIL',
41588 p_message_text => lv_message_text,
41589 p_error_text => lv_error_text);
41590
41591 IF lv_return <> 0 THEN
41592 RAISE ex_logging_err;
41593 END IF;
41594
41595
41596 -- At this point Error out those record with DELETE FLAG 1 and NULL
41597 -- Component sequence id
41598
41599 v_sql_stmt := 21;
41600
41601 lv_sql_stmt:=
41602 'UPDATE msc_st_bom_components '
41603 ||' SET process_flag ='|| G_ERROR_FLG||','
41604 ||' error_text = '||''''||lv_message_text||''''
41605 ||' WHERE NVL(component_sequence_id,'||NULL_VALUE||')='|| NULL_VALUE
41606 ||' AND deleted_flag ='|| SYS_YES
41607 ||' AND sr_instance_code = :v_instance_code'
41608 ||' AND process_flag = '||G_IN_PROCESS
41609 ||' AND batch_id = :lv_batch_id';
41610
41611
41612 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
41613
41614 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
41615
41616
41617 -- Set the message
41618
41619 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
41620 (p_app_short_name => 'MSC',
41621 p_error_code => 'MSC_PP_DATE_OVERLAP',
41622 p_message_text => lv_message_text,
41623 p_error_text => lv_error_text);
41624
41625 IF lv_return <> 0 THEN
41626 RAISE ex_logging_err;
41627 END IF;
41628
41629
41630 -- Now we are checking the overlapping of effectivity date of components
41631 v_sql_stmt := 22;
41632
41633 lv_sql_stmt:=
41634 'UPDATE msc_st_bom_components mbc'
41635 ||' SET process_flag = '||G_ERROR_FLG||','
41636 ||' error_text = '||''''||lv_message_text||''''
41637 ||' WHERE EXISTS (SELECT 1 FROM'
41638 ||' msc_local_id_setup mlis'
41639 ||' WHERE mlis.char1 = mbc.sr_instance_code'
41640 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
41641 ||' = NVL(mbc.company_name,'||''''||NULL_CHAR||''''||') '
41642 ||' AND mlis.char3 = mbc.organization_code'
41643 ||' AND mlis.char4 = mbc.bom_name'
41644 ||' AND mlis.char5 = mbc.component_name'
41645 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
41646 ||' = NVL(mbc.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
41647 ||' AND mlis.char7 = mbc.operation_seq_code'
41648 ||' AND ((mlis.date1 >= mbc.effectivity_date AND'
41649 ||' mlis.date1 <= NVL(mbc.disable_date,SYSDATE+36500))'
41650 ||' OR'
41651 ||' (NVL(mlis.date2,SYSDATE+36500) >= mbc.effectivity_date AND'
41652 ||' NVL(mlis.date2,SYSDATE+36500) <= NVL(mbc.disable_date,SYSDATE+36500))'
41653 ||' OR'
41654 ||' (mlis.date1 <= mbc.effectivity_date AND'
41655 ||' NVL(mlis.date2,SYSDATE+36500) >= NVL(mbc.disable_date,SYSDATE+36500))'
41656 ||' OR'
41657 ||' (mlis.date1 >= mbc.effectivity_date AND'
41658 ||' NVL(mlis.date2,SYSDATE+36500) <= NVL(mbc.disable_date,SYSDATE+36500)))'
41659 ||' AND mlis.entity_name = ''COMPONENT_SEQUENCE_ID'')'
41660 ||' AND NVL(mbc.component_sequence_id,'||NULL_VALUE||')='|| NULL_VALUE
41661 ||' AND mbc.sr_instance_code = :v_instance_code'
41662 ||' AND mbc.deleted_flag = '||SYS_NO
41663 ||' AND mbc.batch_id = :lv_batch_id'
41664 ||' AND mbc.process_flag = '||G_IN_PROCESS;
41665
41666
41667 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
41668
41669 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
41670
41671
41672 -- Set the message
41673
41674 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
41675 (p_app_short_name => 'MSC',
41676 p_error_code => 'MSC_PP_INVALID_VALUE',
41677 p_message_text => lv_message_text,
41678 p_error_text => lv_error_text,
41679 p_token1 => 'COLUMN_NAMES',
41680 p_token_value1 => 'ASSEMBLY_NAME',
41681 p_token2 => 'MASTER_TABLE',
41682 p_token_value2 => 'MSC_ST_BOMS'
41683 );
41684
41685 IF lv_return <> 0 THEN
41686 RAISE ex_logging_err;
41687 END IF;
41688
41689
41690 -- Populate the using_assembly_id from assembly name
41691
41692 lv_return :=
41693 MSC_ST_UTIL.DERIVE_ITEM_ID(p_table_name =>'MSC_ST_BOM_COMPONENTS',
41694 p_item_col_name => 'ASSEMBLY_NAME',
41695 p_item_col_id =>'USING_ASSEMBLY_ID',
41696 p_instance_code => v_instance_code,
41697 p_instance_id => v_instance_id,
41698 p_severity => G_SEV_ERROR,
41699 p_message_text => lv_message_text,
41700 p_batch_id =>lv_batch_id,
41701 p_debug => v_debug,
41702 p_error_text =>lv_error_text);
41703
41704 if(lv_return <> 0) then
41705 RAISE ex_logging_err;
41706 end if;
41707
41708
41709 -- Set the error message
41710 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
41711 (p_app_short_name => 'MSC',
41712 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
41713 p_message_text => lv_message_text,
41714 p_error_text => lv_error_text,
41715 p_token1 => 'COLUMN_NAME',
41716 p_token_value1 => 'USAGE_QUANTITY',
41717 p_token2 => 'DEFAULT_VALUE',
41718 p_token_value2 => G_USAGE_QUANTITY );
41719
41720 IF lv_return <> 0 THEN
41721 RAISE ex_logging_err;
41722 END IF;
41723
41724 -- default it to 1 if usage quantity is NULL
41725
41726 lv_where_str :=
41727 ' AND NVL(usage_quantity,'||NULL_VALUE||')='|| NULL_VALUE ;
41728
41729 lv_return := MSC_ST_UTIL.LOG_ERROR
41730 (p_table_name => 'MSC_ST_BOM_COMPONENTS',
41731 p_instance_code => v_instance_code,
41732 p_row => lv_column_names,
41733 p_severity => G_SEV_WARNING,
41734 p_message_text => lv_message_text,
41735 p_error_text => lv_error_text,
41736 p_batch_id => lv_batch_id,
41737 p_where_str => lv_where_str,
41738 p_col_name => 'USAGE_QUANTITY',
41739 p_debug => v_debug,
41740 p_default_value => G_USAGE_QUANTITY);
41741
41742 IF lv_return <> 0 THEN
41743 RAISE ex_logging_err;
41744 END IF;
41745
41746 -- Set the message
41747
41748 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
41749 (p_app_short_name => 'MSC',
41750 p_error_code => 'MSC_PP_INVALID_VALUE',
41751 p_message_text => lv_message_text,
41752 p_error_text => lv_error_text,
41753 p_token1 => 'COLUMN_NAME',
41754 p_token_value1 => 'UOM_CODE');
41755
41756 IF lv_return <> 0 THEN
41757 RAISE ex_logging_err;
41758 END IF;
41759
41760
41761
41762 -- If UOM is provided validate the UOM_CODE
41763 v_sql_stmt := 23;
41764
41765 lv_sql_stmt :=
41766 ' UPDATE msc_st_bom_components mbc'
41767 ||' SET process_flag = '||G_ERROR_FLG||','
41768 ||' error_text = '||''''||lv_message_text||''''
41769 ||' WHERE NOT EXISTS (SELECT 1'
41770 ||' FROM msc_units_of_measure muom'
41771 ||' WHERE muom.uom_code = mbc.uom_code'
41772 ||' UNION'
41773 ||' SELECT 1 FROM msc_st_units_of_measure msuom'
41774 ||' WHERE msuom.uom_code = mbc.uom_code'
41775 ||' AND msuom.sr_instance_id = :v_instance_id'
41776 ||' AND msuom.process_flag = '||G_VALID||' )'
41777 ||' AND NVL(mbc.uom_code,'||''''||NULL_CHAR||''''||') '
41778 ||' <> '||''''||NULL_CHAR||''''
41779 ||' AND mbc.sr_instance_code = :v_instance_code'
41780 ||' AND mbc.batch_id = :lv_batch_id'
41781 ||' AND mbc.process_flag = '||G_IN_PROCESS ;
41782
41783 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
41784
41785 EXECUTE IMMEDIATE lv_sql_stmt
41786 USING v_instance_id,
41787 v_instance_code,
41788 lv_batch_id;
41789
41790 -- Set the error message
41791 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
41792 (p_app_short_name => 'MSC',
41793 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
41794 p_message_text => lv_message_text,
41795 p_error_text => lv_error_text,
41796 p_token1 => 'COLUMN_NAME',
41797 p_token_value1 => 'COMPONENT_YEILD_FACTOR',
41798 p_token2 => 'DEFAULT_VALUE',
41799 p_token_value2 => G_COMPONENT_YEILD_FACTOR );
41800
41801 IF lv_return <> 0 THEN
41802 RAISE ex_logging_err;
41803 END IF;
41804
41805 -- Default the component_yield_factor to 1 if NULL
41806
41807 lv_where_str :=
41808 ' AND NVL(component_yield_factor,'||NULL_VALUE||')= '||NULL_VALUE ;
41809
41810 lv_return := MSC_ST_UTIL.LOG_ERROR
41811 (p_table_name => 'MSC_ST_BOM_COMPONENTS',
41812 p_instance_code => v_instance_code,
41813 p_row => lv_column_names,
41814 p_severity => G_SEV_WARNING,
41815 p_message_text => lv_message_text,
41816 p_error_text => lv_error_text,
41817 p_batch_id => lv_batch_id,
41818 p_where_str => lv_where_str,
41819 p_col_name => 'COMPONENT_YIELD_FACTOR',
41820 p_debug => v_debug,
41821 p_default_value => G_COMPONENT_YEILD_FACTOR );
41822
41823 if(lv_return <> 0) then
41824 RAISE ex_logging_err;
41825 end if;
41826
41827 -- Set the message
41828
41829 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
41830 (p_app_short_name => 'MSC',
41831 p_error_code => 'MSC_PP_INVALID_VALUE',
41832 p_message_text => lv_message_text,
41833 p_error_text => lv_error_text,
41834 p_token1 => 'COLUMN_NAME',
41835 p_token_value1 => 'DRIVING_ITEM_NAME');
41836
41837 IF lv_return <> 0 THEN
41838 RAISE ex_logging_err;
41839 END IF;
41840
41841 --Derive driving item id
41842
41843 lv_return :=
41844 MSC_ST_UTIL.DERIVE_ITEM_ID(p_table_name => 'MSC_ST_BOM_COMPONENTS',
41845 p_item_col_name => 'DRIVING_ITEM_NAME',
41846 p_item_col_id => 'DRIVING_ITEM_ID',
41847 p_instance_code => v_instance_code,
41848 p_instance_id => v_instance_id,
41849 p_severity => G_SEV3_ERROR,
41850 p_message_text => lv_message_text,
41851 p_batch_id => lv_batch_id,
41852 p_debug => v_debug,
41853 p_error_text => lv_error_text);
41854
41855 if(lv_return <> 0) then
41856 RAISE ex_logging_err;
41857 end if;
41858
41859 -- Set the error message
41860 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
41861 (p_app_short_name => 'MSC',
41862 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
41863 p_message_text => lv_message_text,
41864 p_error_text => lv_error_text,
41865 p_token1 => 'COLUMN_NAME',
41866 p_token_value1 => 'USE_UP_CODE',
41867 p_token2 => 'DEFAULT_VALUE',
41868 p_token_value2 => G_USE_UP_CODE );
41869
41870 IF lv_return <> 0 THEN
41871 RAISE ex_logging_err;
41872 END IF;
41873
41874 -- Default the use_up_code as NULL if not in 1,2
41875
41876 lv_where_str := ' AND use_up_code NOT IN (1,2)';
41877
41878 lv_return := MSC_ST_UTIL.LOG_ERROR
41879 (p_table_name => 'MSC_ST_BOM_COMPONENTS',
41880 p_instance_code => v_instance_code,
41881 p_row => lv_column_names,
41882 p_severity => G_SEV_WARNING,
41883 p_message_text => lv_message_text,
41884 p_error_text => lv_error_text,
41885 p_batch_id => lv_batch_id,
41886 p_where_str => lv_where_str,
41887 p_col_name => 'USE_UP_CODE',
41888 p_debug => v_debug,
41889 p_default_value => G_USE_UP_CODE);
41890
41891 if(lv_return <> 0) then
41892 RAISE ex_logging_err;
41893 end if;
41894
41895 -- Set the error message
41896 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
41897 (p_app_short_name => 'MSC',
41898 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
41899 p_message_text => lv_message_text,
41900 p_error_text => lv_error_text,
41901 p_token1 => 'COLUMN_NAME',
41902 p_token_value1 => 'OPTIONAL_COMPONENT',
41903 p_token2 => 'DEFAULT_VALUE',
41904 p_token_value2 => G_OPTIONAL_COMPONENT );
41905
41906 IF lv_return <> 0 THEN
41907 RAISE ex_logging_err;
41908 END IF;
41909
41910 -- Default the optional_component as NULL if not in 1,2
41911
41912 lv_where_str := ' AND optional_component NOT IN (1,2)';
41913
41914 lv_return := MSC_ST_UTIL.LOG_ERROR
41915 (p_table_name => 'MSC_ST_BOM_COMPONENTS',
41916 p_instance_code => v_instance_code,
41917 p_row => lv_column_names,
41918 p_severity => G_SEV_WARNING,
41919 p_message_text => lv_message_text,
41920 p_error_text => lv_error_text,
41921 p_batch_id => lv_batch_id,
41922 p_where_str => lv_where_str,
41923 p_col_name => 'OPTIONAL_COMPONENT',
41924 p_debug => v_debug,
41925 p_default_value => G_OPTIONAL_COMPONENT );
41926
41927 if(lv_return <> 0) then
41928 RAISE ex_logging_err;
41929 end if;
41930
41931 -- Set the error message
41932 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
41933 (p_app_short_name => 'MSC',
41934 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
41935 p_message_text => lv_message_text,
41936 p_error_text => lv_error_text,
41937 p_token1 => 'COLUMN_NAME',
41938 p_token_value1 => 'WIP_SUPPLY_TYPE',
41939 p_token2 => 'DEFAULT_VALUE',
41940 p_token_value2 => G_WIP_SUPPLY_TYPE );
41941
41942 IF lv_return <> 0 THEN
41943 RAISE ex_logging_err;
41944 END IF;
41945
41946 -- Default the wip_supply_type as 1(PUSH) if not in (1,2,3,4,5,6,7)
41947
41948 lv_where_str :=
41949 ' AND NVL(wip_supply_type,'||NULL_VALUE||') NOT IN (1,2,3,4,5,6,7)';
41950
41951 lv_return :=
41952 MSC_ST_UTIL.LOG_ERROR (p_table_name => 'MSC_ST_BOM_COMPONENTS',
41953 p_instance_code => v_instance_code,
41954 p_row => lv_column_names,
41955 p_severity => G_SEV_WARNING,
41956 p_message_text => lv_message_text,
41957 p_error_text => lv_error_text,
41958 p_batch_id => lv_batch_id,
41959 p_where_str => lv_where_str,
41960 p_col_name => 'WIP_SUPPLY_TYPE',
41961 p_debug => v_debug,
41962 p_default_value => G_WIP_SUPPLY_TYPE );
41963
41964 if(lv_return <> 0) then
41965 RAISE ex_logging_err;
41966 end if;
41967
41968 -- Set the error message
41969 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
41970 (p_app_short_name => 'MSC',
41971 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
41972 p_message_text => lv_message_text,
41973 p_error_text => lv_error_text,
41974 p_token1 => 'COLUMN_NAME',
41975 p_token_value1 => 'COMPONENT_TYPE',
41976 p_token2 => 'DEFAULT_VALUE',
41977 p_token_value2 => G_COMPONENT_TYPE );
41978
41979 IF lv_return <> 0 THEN
41980 RAISE ex_logging_err;
41981 END IF;
41982
41983 -- Comented out to match ERP behaviour
41984 /* -- Default the component_type 1 if not in (-1,1,2)
41985
41986
41987 lv_where_str :=
41988 ' AND NVL(component_type,'||NULL_VALUE||') NOT IN (-1,1,2)';
41989
41990 lv_return := MSC_ST_UTIL.LOG_ERROR
41991 (p_table_name => 'MSC_ST_BOM_COMPONENTS',
41992 p_instance_code => v_instance_code,
41993 p_row => lv_column_names,
41994 p_severity => G_SEV_WARNING,
41995 p_message_text => lv_message_text,
41996 p_error_text => lv_error_text,
41997 p_batch_id => lv_batch_id,
41998 p_where_str => lv_where_str,
41999 p_col_name => 'COMPONENT_TYPE',
42000 p_debug => v_debug,
42001 p_default_value => G_COMPONENT_TYPE );
42002
42003 if(lv_return <> 0) then
42004 RAISE ex_logging_err;
42005 end if;
42006 */
42007
42008 -- Set the error message
42009 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
42010 (p_app_short_name => 'MSC',
42011 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
42012 p_message_text => lv_message_text,
42013 p_error_text => lv_error_text,
42014 p_token1 => 'COLUMN_NAME',
42015 p_token_value1 => 'ATP_FLAG',
42016 p_token2 => 'DEFAULT_VALUE',
42017 p_token_value2 => G_ATP_FLAG_BOM );
42018
42019 IF lv_return <> 0 THEN
42020 RAISE ex_logging_err;
42021 END IF;
42022
42023 -- Default the atp_flag 2 if not in (1,2)
42024
42025 lv_where_str :=
42026 ' AND NVL(atp_flag,'||NULL_VALUE||')NOT IN (1,2)';
42027
42028 lv_return := MSC_ST_UTIL.LOG_ERROR
42029 (p_table_name => 'MSC_ST_BOM_COMPONENTS',
42030 p_instance_code => v_instance_code,
42031 p_row => lv_column_names,
42032 p_severity => G_SEV_WARNING,
42033 p_message_text => lv_message_text,
42034 p_error_text => lv_error_text,
42035 p_batch_id => lv_batch_id,
42036 p_where_str => lv_where_str,
42037 p_col_name => 'ATP_FLAG',
42038 p_debug => v_debug,
42039 p_default_value => G_ATP_FLAG_BOM );
42040
42041 if(lv_return <> 0) then
42042 RAISE ex_logging_err;
42043 end if;
42044
42045 --Call to customised validation.
42046
42047 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
42048 (ERRBUF => lv_error_text,
42049 RETCODE => lv_return,
42050 pBatchID => lv_batch_id,
42051 pInstanceCode => v_instance_code,
42052 pEntityName => 'MSC_ST_BOM_COMPONENTS',
42053 pInstanceID => v_instance_id);
42054
42055 IF NVL(lv_return,0) <> 0 THEN
42056 RAISE ex_logging_err;
42057 END IF;
42058
42059 v_sql_stmt := 23.1;
42060
42061 lv_sql_stmt :=
42062 'UPDATE MSC_ST_BOM_COMPONENTS'
42063 ||' SET usage_quantity = ( usage_quantity / decode(component_yield_factor,0,1,abs(component_yield_factor)) )* nvl(planning_factor,100)/100'
42064 ||' WHERE process_flag = '||G_IN_PROCESS
42065 ||' AND sr_instance_code = :v_instance_code'
42066 ||' AND batch_id = :lv_batch_id';
42067
42068
42069 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
42070
42071 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
42072
42073
42074 -- Now we will generate the component sequence id
42075
42076 v_sql_stmt := 24;
42077
42078 OPEN c5(lv_batch_id);
42079 FETCH c5 BULK COLLECT INTO lb_rowid ;
42080
42081 IF c5%ROWCOUNT > 0 THEN
42082
42083 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
42084
42085 UPDATE msc_st_bom_components
42086 SET component_sequence_id = msc_st_component_sequence_id_s.NEXTVAL
42087 WHERE rowid = lb_rowid(j);
42088
42089 v_sql_stmt := 23;
42090
42091 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
42092
42093 -- Insert into the LID table
42094
42095 INSERT INTO msc_local_id_setup
42096 (local_id,
42097 st_transaction_id,
42098 instance_id,
42099 entity_name,
42100 data_source_type,
42101 char1,
42102 char2,
42103 char3,
42104 char4,
42105 char5,
42106 char6,
42107 char7,
42108 date1,
42109 date2,
42110 SOURCE_ORGANIZATION_ID ,
42111 SOURCE_BILL_SEQUENCE_ID ,
42112 SOURCE_COMPONENT_SEQ_ID ,
42113 SOURCE_USING_ASSEMBLY_ID ,
42114 SOURCE_INVENTORY_ITEM_ID ,
42115 SOURCE_DRIVING_ITEM_ID ,
42116 last_update_date,
42117 last_updated_by,
42118 creation_date,
42119 created_by )
42120 SELECT
42121 component_sequence_id,
42122 st_transaction_id,
42123 v_instance_id,
42124 'COMPONENT_SEQUENCE_ID',
42125 data_source_type,
42126 sr_instance_code,
42127 company_name,
42128 organization_code,
42129 bom_name,
42130 component_name,
42131 alternate_bom_designator,
42132 operation_seq_code,
42133 effectivity_date,
42134 disable_date,
42135 SOURCE_ORGANIZATION_ID ,
42136 SOURCE_BILL_SEQUENCE_ID ,
42137 SOURCE_COMPONENT_SEQUENCE_ID ,
42138 SOURCE_USING_ASSEMBLY_ID ,
42139 SOURCE_INVENTORY_ITEM_ID ,
42140 SOURCE_DRIVING_ITEM_ID ,
42141 v_current_date,
42142 v_current_user,
42143 v_current_date,
42144 v_current_user
42145 FROM msc_st_bom_components
42146 WHERE rowid = lb_rowid(j) ;
42147
42148 END IF;
42149 CLOSE c5;
42150
42151
42152 -- Update the DISABLE_DATE to SYSDATE for the deleted component in LID table
42153 v_sql_stmt := 25;
42154 /*
42155 lv_sql_stmt :=
42156 'UPDATE msc_local_id_setup mlis'
42157 ||' SET date2 = SYSDATE'
42158 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_bom_components mbc'
42159 ||' WHERE mlis.char1 = mbc.sr_instance_code'
42160 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
42161 ||' = NVL(mbc.company_name,'||''''||NULL_CHAR||''''||') '
42162 ||' AND mlis.char3 = mbc.organization_code'
42163 ||' AND mlis.char4 = mbc.bom_name'
42164 ||' AND mlis.char5 = mbc.component_name'
42165 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
42166 ||' = NVL(mbc.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
42167 ||' AND mlis.char7 = mbc.operation_seq_code'
42168 ||' AND trunc(mlis.date1) = trunc(mbc.effectivity_date)'
42169 ||' AND mbc.batch_id= :lv_batch_id'
42170 ||' AND mbc.deleted_flag = '||SYS_YES
42171 ||' AND mbc.process_flag ='|| G_IN_PROCESS||')'
42172 ||' AND mlis.entity_name = ''COMPONENT_SEQUENCE_ID'' '
42173 ||' AND mlis.instance_id = :v_instance_id' ;
42174
42175
42176 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
42177
42178 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_id;
42179 */
42180 OPEN c7(lv_batch_id);
42181 FETCH c7 BULK COLLECT INTO lb_rowid ;
42182 IF c7%ROWCOUNT > 0 THEN
42183
42184 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
42185
42186 UPDATE msc_local_id_setup
42187 SET date2 = SYSDATE
42188 WHERE rowid = lb_rowid(j);
42189
42190 END IF;
42191 CLOSE c7;
42192
42193 -- Set the process flag as Valid and poulate instance_id
42194 lv_return :=
42195 MSC_ST_UTIL.SET_PROCESS_FLAG(p_table_name => 'MSC_ST_BOM_COMPONENTS',
42196 p_instance_id => v_instance_id,
42197 p_instance_code => v_instance_code,
42198 p_process_flag => G_VALID,
42199 p_error_text => lv_error_text,
42200 p_debug => v_debug,
42201 p_batch_id => lv_batch_id);
42202
42203 IF lv_return <> 0 THEN
42204 RAISE ex_logging_err;
42205 END IF;
42206
42207 -- At the end calling the LOG_ERROR for logging all errored out records
42208
42209 lv_return :=
42210 msc_st_util.log_error(p_table_name =>'MSC_ST_BOM_COMPONENTS',
42211 p_instance_code =>v_instance_code,
42212 p_row =>lv_column_names,
42213 p_severity =>G_SEV_ERROR,
42214 p_message_text => NULL,
42215 p_error_text =>lv_error_text,
42216 p_debug => v_debug,
42217 p_batch_id => lv_batch_id );
42218
42219 IF(lv_return <> 0) THEN
42220 RAISE ex_logging_err;
42221 END IF;
42222 COMMIT;
42223 END LOOP;
42224
42225
42226 -- Now validtion for MSC_ST_COMPONENT_SUBSTITUTES
42227
42228
42229 --Duplicate records check for the records whose source is XML
42230
42231 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
42232 (p_app_short_name => 'MSC',
42233 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
42234 p_message_text => lv_message_text,
42235 p_error_text => lv_error_text);
42236
42237 IF lv_return <> 0 THEN
42238 RAISE ex_logging_err;
42239 END IF;
42240
42241
42242 v_sql_stmt := 26;
42243 lv_sql_stmt :=
42244 'UPDATE msc_st_component_substitutes mcs1 '
42245 ||' SET process_flag ='|| G_ERROR_FLG||','
42246 ||' error_text = '||''''||lv_message_text||''''
42247 ||' WHERE message_id < ( SELECT max(message_id)'
42248 ||' FROM msc_st_component_substitutes mcs2'
42249 ||' WHERE mcs2.sr_instance_code = mcs1.sr_instance_code'
42250 ||' AND mcs2.organization_code = mcs1.organization_code'
42251 ||' AND NVL(mcs2.company_name,'||''''||NULL_CHAR||''''||') '
42252 ||' = NVL(mcs1.company_name, '||''''||NULL_CHAR||''''||') '
42253 ||' AND NVL(mcs2.bom_name,'||''''||NULL_CHAR||''''||') '
42254 ||' = NVL(mcs1.bom_name, '||''''||NULL_CHAR||''''||') '
42255 ||' AND mcs2.assembly_name = mcs1.assembly_name '
42256 ||' AND NVL(mcs2.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
42257 ||' = NVL(mcs1.alternate_bom_designator, '||''''||NULL_CHAR||''''||') '
42258 ||' AND mcs2.component_name = mcs1.component_name'
42259 ||' AND NVL(mcs2.effectivity_date,SYSDATE-36500 )'
42260 ||' = NVL(mcs1.effectivity_date,SYSDATE-36500 )'
42261 ||' AND NVL(mcs2.operation_seq_code ,'||''''||NULL_CHAR||''''||') '
42262 ||' = NVL(mcs1.operation_seq_code , '||''''||NULL_CHAR||''''||') '
42263 ||' AND mcs2.sub_item_name = mcs1.sub_item_name'
42264 ||' AND mcs2.process_flag = mcs1.process_flag'
42265 ||' AND NVL(mcs2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||')'
42266 ||' AND mcs1.process_flag ='|| G_IN_PROCESS
42267 ||' AND mcs1.sr_instance_code = :v_instance_code '
42268 ||' AND NVL(mcs1.message_id,'||NULL_VALUE||')<> '||NULL_VALUE;
42269
42270
42271 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
42272
42273 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
42274
42275
42276 --Duplicate records check for the records whose source is batch load
42277
42278 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
42279 (p_app_short_name => 'MSC',
42280 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
42281 p_message_text => lv_message_text,
42282 p_error_text => lv_error_text);
42283
42284 IF lv_return <> 0 THEN
42285 RAISE ex_logging_err;
42286 END IF;
42287
42288 v_sql_stmt := 27;
42289
42290 lv_sql_stmt :=
42291 'UPDATE msc_st_component_substitutes mcs1'
42292 ||' SET process_flag = '||G_ERROR_FLG||','
42293 ||' error_text = '||''''||lv_message_text||''''
42294 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_component_substitutes mcs2'
42295 ||' WHERE mcs2.sr_instance_code = mcs1.sr_instance_code'
42296 ||' AND mcs2.organization_code = mcs1.organization_code'
42297 ||' AND NVL(mcs2.company_name,'||''''||NULL_CHAR||''''||') '
42298 ||' = NVL(mcs1.company_name, '||''''||NULL_CHAR||''''||') '
42299 ||' AND NVL(mcs2.bom_name,'||''''||NULL_CHAR||''''||') '
42300 ||' = NVL(mcs1.bom_name, '||''''||NULL_CHAR||''''||') '
42301 ||' AND mcs2.assembly_name = mcs1.assembly_name '
42302 ||' AND NVL(mcs2.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
42303 ||' = NVL(mcs1.alternate_bom_designator, '||''''||NULL_CHAR||''''||') '
42304 ||' AND mcs2.component_name = mcs1.component_name'
42305 ||' AND NVL(mcs2.effectivity_date,SYSDATE-36500 )'
42306 ||' = NVL(mcs1.effectivity_date,SYSDATE-36500 )'
42307 ||' AND NVL(mcs2.operation_seq_code ,'||''''||NULL_CHAR||''''||') '
42308 ||' = NVL(mcs1.operation_seq_code , '||''''||NULL_CHAR||''''||') '
42309 ||' AND mcs2.sub_item_name = mcs1.sub_item_name'
42310 ||' AND mcs2.process_flag = mcs1.process_flag'
42311 ||' AND NVL(mcs2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
42312 ||' GROUP BY sr_instance_code,organization_code, bom_name,company_name,'
42313 ||' assembly_name,alternate_bom_designator,component_name,'
42314 ||' operation_seq_code,effectivity_date,sub_item_name'
42315 ||' HAVING count(*) > 1)'
42316 ||' AND mcs1.process_flag ='|| G_IN_PROCESS
42317 ||' AND mcs1.sr_instance_code = :v_instance_code'
42318 ||' AND NVL(mcs1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
42319
42320
42321 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
42322
42323 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
42324
42325
42326
42327 lv_column_names :=
42328 'ORGANIZATION_CODE ||''~''||'
42329 ||'BOM_NAME ||''~''||'
42330 ||'ASSEMBLY_NAME ||''~''||'
42331 ||'COMPONENT_NAME ||''~''||'
42332 ||'SUB_ITEM_NAME ||''~''||'
42333 ||'USAGE_QUANTITY ||''~''||'
42334 ||'PRIORITY ||''~''||'
42335 ||'SR_INSTANCE_CODE ||''~''||'
42336 ||'ALTERNATE_BOM_DESIGNATOR ||''~''||'
42337 ||'OPERATION_SEQ_CODE ||''~''||'
42338 ||'EFFECTIVITY_DATE ||''~''||'
42339 ||'COMPANY_NAME ||''~''||'
42340 ||'DELETED_FLAG ';
42341
42342
42343 -- Processing the MSC_ST_COMPONENT_SUBSTITUTES table
42344
42345 LOOP
42346 v_sql_stmt := 28;
42347 lv_cursor_stmt :=
42348 ' SELECT msc_st_batch_id_s.NEXTVAL '
42349 ||' FROM dual';
42350
42351 OPEN c1 FOR lv_cursor_stmt;
42352 FETCH c1 INTO lv_batch_id;
42353 CLOSE c1;
42354
42355 v_sql_stmt := 29;
42356 lv_sql_stmt :=
42357 ' UPDATE msc_st_component_substitutes '
42358 ||' SET batch_id = :lv_batch_id'
42359 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
42360 ||' AND sr_instance_code = :v_instance_code'
42361 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
42362 ||' AND rownum <= '||v_batch_size;
42363
42364
42365 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
42366
42367 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
42368
42369 EXIT WHEN SQL%NOTFOUND;
42370
42371 OPEN c6(lv_batch_id);
42372 FETCH c6 BULK COLLECT INTO lb_rowid;
42373 CLOSE c6;
42374
42375 v_sql_stmt := 29;
42376 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
42377 UPDATE msc_st_component_substitutes
42378 SET st_transaction_id = msc_st_component_substitutes_s.NEXTVAL,
42379 refresh_id = v_refresh_id,
42380 last_update_date = v_current_date,
42381 last_updated_by = v_current_user,
42382 creation_date = v_current_date,
42383 created_by = v_current_user
42384 WHERE rowid = lb_rowid(j);
42385
42386
42387 -- Set the error message
42388
42389 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
42390 (p_app_short_name => 'MSC',
42391 p_error_code => 'MSC_PP_NO_DELETION',
42392 p_message_text => lv_message_text,
42393 p_error_text => lv_error_text,
42394 p_token1 => 'TABLE_NAME',
42395 p_token_value1 => 'MSC_ST_COMPONENT_SUBSTITUTES');
42396
42397 IF lv_return <> 0 THEN
42398 RAISE ex_logging_err;
42399 END IF;
42400
42401 --Deletion is not allowed on this table.
42402 v_sql_stmt := 30;
42403 lv_sql_stmt :=
42404 ' UPDATE msc_st_component_substitutes'
42405 ||' SET process_flag = '||G_ERROR_FLG||','
42406 ||' error_text = '||''''||lv_message_text||''''
42407 ||' WHERE deleted_flag = '||SYS_YES
42408 ||' AND process_flag = '||G_IN_PROCESS
42409 ||' AND batch_id = :lv_batch_id'
42410 ||' AND sr_instance_code = :v_instance_code';
42411
42412
42413 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
42414
42415 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
42416
42417 -- Set the error message
42418 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
42419 (p_app_short_name => 'MSC',
42420 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
42421 p_message_text => lv_message_text,
42422 p_error_text => lv_error_text,
42423 p_token1 => 'COLUMN_NAME',
42424 p_token_value1 => 'DELETED_FLAG',
42425 p_token2 => 'DEFAULT_VALUE',
42426 p_token_value2 => SYS_NO );
42427
42428
42429
42430 -- Check whether delete flag value is in (SYS_YES,SYS_NO),if not default to SYS_NO
42431
42432 lv_where_str :=
42433 ' AND NVL(deleted_flag,'||NULL_VALUE||')NOT IN (1,2)';
42434
42435 lv_return := MSC_ST_UTIL.LOG_ERROR
42436 (p_table_name => 'MSC_ST_COMPONENT_SUBSTITUTES',
42437 p_instance_code => v_instance_code,
42438 p_row => lv_column_names,
42439 p_severity => G_SEV_WARNING,
42440 p_message_text => lv_message_text,
42441 p_error_text => lv_error_text,
42442 p_batch_id => lv_batch_id,
42443 p_where_str => lv_where_str,
42444 p_col_name => 'DELETED_FLAG',
42445 p_debug => v_debug,
42446 p_default_value => SYS_NO);
42447
42448
42449 IF lv_return <> 0 THEN
42450 RAISE ex_logging_err;
42451 END IF;
42452
42453 -- Set the message
42454
42455 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
42456 (p_app_short_name => 'MSC',
42457 p_error_code => 'MSC_PP_INVALID_VALUE',
42458 p_message_text => lv_message_text,
42459 p_error_text => lv_error_text,
42460 p_token1 => 'COLUMN_NAME',
42461 p_token_value1 => 'SUB_ITEM_NAME');
42462
42463 IF lv_return <> 0 THEN
42464 RAISE ex_logging_err;
42465 END IF;
42466
42467 --Derive SUBSTITUTE ITEM ID
42468 lv_return :=
42469 MSC_ST_UTIL.DERIVE_ITEM_ID(p_table_name => 'MSC_ST_COMPONENT_SUBSTITUTES',
42470 p_item_col_name => 'SUB_ITEM_NAME',
42471 p_item_col_id => 'SUBSTITUTE_ITEM_ID',
42472 p_instance_code => v_instance_code,
42473 p_instance_id => v_instance_id,
42474 p_severity => G_SEV_ERROR,
42475 p_message_text => lv_message_text,
42476 p_batch_id => lv_batch_id,
42477 p_debug => v_debug,
42478 p_error_text => lv_error_text);
42479
42480 IF lv_return <> 0 THEN
42481 RAISE ex_logging_err;
42482 END IF;
42483
42484 -- Set the message
42485
42486 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
42487 (p_app_short_name => 'MSC',
42488 p_error_code => 'MSC_PP_INVALID_VALUE',
42489 p_message_text => lv_message_text,
42490 p_error_text => lv_error_text,
42491 p_token1 => 'COLUMN_NAME',
42492 p_token_value1 => 'ORGANIZATION_CODE');
42493
42494 IF lv_return <> 0 THEN
42495 RAISE ex_logging_err;
42496 END IF;
42497
42498 -- Populate organization id ,
42499
42500 lv_return :=
42501 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name => 'MSC_ST_COMPONENT_SUBSTITUTES',
42502 p_org_partner_name => 'ORGANIZATION_CODE',
42503 p_org_partner_id => 'ORGANIZATION_ID',
42504 p_instance_code => v_instance_code,
42505 p_partner_type => G_ORGANIZATION,
42506 p_severity => G_SEV_ERROR,
42507 p_message_text => lv_message_text,
42508 p_batch_id => lv_batch_id,
42509 p_debug => v_debug,
42510 p_error_text => lv_error_text);
42511
42512 IF lv_return <> 0 THEN
42513 RAISE ex_logging_err;
42514 END IF;
42515
42516 -- Now we will check whether BOM Name is NULL , if it is NULL we will populate the
42517 -- ASSEMBLY NAME in BOM NAME column for all such records
42518
42519 v_sql_stmt := 31;
42520
42521 lv_sql_stmt :=
42522
42523 'UPDATE msc_st_component_substitutes '
42524 ||' SET bom_name = assembly_name'
42525 ||' WHERE sr_instance_code = :v_instance_code'
42526 ||' AND process_flag ='||G_IN_PROCESS
42527 ||' AND NVL(bom_name,'||''''||NULL_CHAR||''''||') '
42528 ||' = '||''''||NULL_CHAR||''''
42529 ||' AND NVL(assembly_name,'||''''||NULL_CHAR||''''||') '
42530 ||' <> '||''''||NULL_CHAR||''''
42531 ||' AND batch_id = :lv_batch_id';
42532
42533
42534 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
42535
42536 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
42537
42538
42539 -- Now derive assembly name for those records where assembly name is NULL
42540 -- If not able to get this error out those records
42541 -- In child table of BOM we will accept either BOM name/Assembly name or both
42542
42543 v_sql_stmt := 32;
42544
42545 lv_sql_stmt:=
42546 'UPDATE msc_st_component_substitutes mcs'
42547 ||' SET assembly_name = (SELECT char5'
42548 ||' FROM msc_local_id_setup mlis'
42549 ||' WHERE mlis.char1 = mcs.sr_instance_code'
42550 ||' AND mlis.char3 = mcs.organization_code'
42551 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
42552 ||' = NVL(mcs.company_name,'||''''||NULL_CHAR||''''||') '
42553 ||' AND mlis.char4 = mcs.bom_name'
42554 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
42555 ||' = NVL(mcs.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
42556 ||' AND mlis.entity_name =''BILL_SEQUENCE_ID'') '
42557 ||' WHERE sr_instance_code = :v_instance_code'
42558 ||' AND NVL(assembly_name,'||''''||NULL_CHAR||''''||') '
42559 ||' = '||''''||NULL_CHAR||''''
42560 ||' AND process_flag ='|| G_IN_PROCESS
42561 ||' AND batch_id = :lv_batch_id';
42562
42563
42564 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
42565
42566 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
42567
42568 -- Set the message
42569
42570 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
42571 (p_app_short_name => 'MSC',
42572 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
42573 p_message_text => lv_message_text,
42574 p_error_text => lv_error_text,
42575 p_token1 => 'COLUMN_NAMES',
42576 p_token_value1 => 'BOM_NAME,SR_INSTANCE_CODE,'
42577 ||' COMPANY_NAME,'
42578 ||' ALETERNATE_BOM_DESIGNATOR',
42579 p_token2 => 'MASTER_TABLE',
42580 p_token_value2 => 'MSC_ST_BOMS',
42581 p_token3 => 'CHILD_TABLE',
42582 p_token_value3 => 'MSC_ST_COMPONENT_SUBSTITUTES');
42583
42584 IF lv_return <> 0 THEN
42585 RAISE ex_logging_err;
42586 END IF;
42587
42588
42589 -- Error out those records where assembly name is still NULL,
42590
42591 v_sql_stmt := 33;
42592 lv_sql_stmt :=
42593 'UPDATE msc_st_component_substitutes '
42594 ||' SET process_flag = '||G_ERROR_FLG||','
42595 ||' error_text = '||''''||lv_message_text||''''
42596 ||' WHERE NVL(assembly_name,'||''''||NULL_CHAR||''''||') '
42597 ||' = '||''''||NULL_CHAR||''''
42598 ||' AND sr_instance_code = :v_instance_code'
42599 ||' AND process_flag = '||G_IN_PROCESS
42600 ||' AND batch_id = :lv_batch_id';
42601
42602
42603 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
42604
42605 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
42606
42607
42608 -- Derive bill sequence id
42609 lv_return :=
42610 MSC_ST_UTIL.DERIVE_BILL_SEQUENCE_ID
42611 (p_table_name => 'MSC_ST_COMPONENT_SUBSTITUTES',
42612 p_bom_col_name => 'BOM_NAME',
42613 p_bom_col_id => 'BILL_SEQUENCE_ID',
42614 p_instance_code => v_instance_code,
42615 p_severity => G_SEV_ERROR,
42616 p_message_text => lv_message_text,
42617 p_batch_id => lv_batch_id,
42618 p_debug => v_debug,
42619 p_error_text => lv_error_text);
42620
42621 IF (lv_return <> 0 )then
42622 RAISE ex_logging_err;
42623 END IF;
42624
42625 -- Set the error message
42626 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
42627 (p_app_short_name => 'MSC',
42628 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
42629 p_message_text => lv_message_text,
42630 p_error_text => lv_error_text,
42631 p_token1 => 'COLUMN_NAME',
42632 p_token_value1 => 'EFFECTIVITY_DATE',
42633 p_token2 => 'DEFAULT_VALUE',
42634 p_token_value2 => 'SYSDATE' );
42635
42636 IF lv_return <> 0 THEN
42637 RAISE ex_logging_err;
42638 END IF;
42639
42640
42641 -- Check the EFFECTIVITY_DATE , if it is NULL,default SYSDATE
42642
42643 lv_where_str :=
42644 ' AND NVL(effectivity_date,SYSDATE-36500 ) = SYSDATE-36500' ;
42645
42646 lv_return := MSC_ST_UTIL.LOG_ERROR
42647 (p_table_name => 'MSC_ST_COMPONENT_SUBSTITUTES',
42648 p_instance_code => v_instance_code,
42649 p_row => lv_column_names,
42650 p_severity => G_SEV_WARNING,
42651 p_message_text => lv_message_text,
42652 p_error_text => lv_error_text,
42653 p_batch_id => lv_batch_id,
42654 p_where_str => lv_where_str,
42655 p_col_name => 'EFFECTIVITY_DATE',
42656 p_debug => v_debug,
42657 p_default_value => 'SYSDATE');
42658
42659 IF lv_return <> 0 THEN
42660 RAISE ex_logging_err;
42661 END IF;
42662
42663 -- Now derive the component sequence id for the Unique key combination
42664 v_sql_stmt := 34;
42665
42666 lv_sql_stmt :=
42667 'UPDATE msc_st_component_substitutes mcs'
42668 ||' SET component_sequence_id= (SELECT local_id '
42669 ||' FROM msc_local_id_setup mlis'
42670 ||' WHERE mlis.char1 = mcs.sr_instance_code'
42671 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
42672 ||' = NVL(mcs.company_name,'||''''||NULL_CHAR||''''||') '
42673 ||' AND mlis.char3 = mcs.organization_code'
42674 ||' AND mlis.char4 = mcs.bom_name'
42675 ||' AND mlis.char5 = mcs.component_name'
42676 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
42677 ||' = NVL(mcs.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
42678 ||' AND mlis.char7 = mcs.operation_seq_code'
42679 ||' AND mlis.date1 = mcs.effectivity_date'
42680 ||' AND mlis.entity_name = ''COMPONENT_SEQUENCE_ID'' )'
42681 ||' WHERE sr_instance_code = :v_instance_code'
42682 ||' AND process_flag ='|| G_IN_PROCESS
42683 ||' AND batch_id = :lv_batch_id';
42684
42685
42686 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
42687
42688 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
42689
42690 -- Set the error message
42691
42692 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
42693 (p_app_short_name => 'MSC',
42694 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
42695 p_message_text => lv_message_text,
42696 p_error_text => lv_error_text,
42697 p_token1 => 'COLUMN_NAMES',
42698 p_token_value1 => 'BOM_NAME,SR_INSTANCE_CODE,EFFECTIVITY_DATE'
42699 ||' COMPANY_NAME,COMPONENT_NAME'
42700 ||' ALETERNATE_BOM_DESIGNATOR,OPERATION_SEQ_CODE',
42701 p_token2 => 'MASTER_TABLE',
42702 p_token_value2 => 'MSC_ST_BOM_COMPONENTS',
42703 p_token3 => 'CHILD_TABLE',
42704 p_token_value3 => 'MSC_ST_COMPONENT_SUBSTITUTES');
42705
42706
42707 IF lv_return <> 0 THEN
42708 RAISE ex_logging_err;
42709 END IF;
42710
42711 v_sql_stmt := 35;
42712 lv_sql_stmt:=
42713 'UPDATE msc_st_component_substitutes '
42714 ||' SET process_flag ='|| G_ERROR_FLG||','
42715 ||' error_text ='||''''||lv_message_text||''''
42716 ||' WHERE NVL(component_sequence_id,'||NULL_VALUE||')='|| NULL_VALUE
42717 ||' AND sr_instance_code = :v_instance_code'
42718 ||' AND process_flag = '||G_IN_PROCESS
42719 ||' AND batch_id = :lv_batch_id';
42720
42721
42722 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
42723
42724 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
42725
42726 -- Set the error message
42727 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
42728 (p_app_short_name => 'MSC',
42729 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
42730 p_message_text => lv_message_text,
42731 p_error_text => lv_error_text,
42732 p_token1 => 'COLUMN_NAME',
42733 p_token_value1 => 'USAGE_QUANTITY',
42734 p_token2 => 'DEFAULT_VALUE',
42735 p_token_value2 => G_USAGE_QUANTITY );
42736
42737 IF lv_return <> 0 THEN
42738 RAISE ex_logging_err;
42739 END IF;
42740
42741 -- Default 1 where usage quantity is NULL
42742
42743 lv_where_str := ' AND NVL(usage_quantity,'||NULL_VALUE||')='|| NULL_VALUE ;
42744
42745 lv_return := MSC_ST_UTIL.LOG_ERROR
42746 (p_table_name => 'MSC_ST_COMPONENT_SUBSTITUTES',
42747 p_instance_code => v_instance_code,
42748 p_row => lv_column_names,
42749 p_severity => G_SEV_WARNING,
42750 p_message_text => lv_message_text,
42751 p_error_text => lv_error_text,
42752 p_batch_id => lv_batch_id,
42753 p_where_str => lv_where_str,
42754 p_col_name => 'USAGE_QUANTITY',
42755 p_debug => v_debug,
42756 p_default_value => G_USAGE_QUANTITY );
42757
42758
42759 IF lv_return <> 0 THEN
42760 RAISE ex_logging_err;
42761 END IF;
42762
42763
42764 -- Set the error message
42765 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
42766 (p_app_short_name => 'MSC',
42767 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
42768 p_message_text => lv_message_text,
42769 p_error_text => lv_error_text,
42770 p_token1 => 'COLUMN_NAME',
42771 p_token_value1 => 'PRIORITY',
42772 p_token2 => 'DEFAULT_VALUE',
42773 p_token_value2 => G_PRIORITY );
42774
42775 IF lv_return <> 0 THEN
42776 RAISE ex_logging_err;
42777 END IF;
42778
42779 -- Default PRIORITY as 1 if NULL
42780
42781 lv_where_str := ' AND NVL(priority,'||NULL_VALUE||')='|| NULL_VALUE ;
42782
42783 lv_return := MSC_ST_UTIL.LOG_ERROR
42784 (p_table_name => 'MSC_ST_COMPONENT_SUBSTITUTES',
42785 p_instance_code => v_instance_code,
42786 p_row => lv_column_names,
42787 p_severity => G_SEV_WARNING,
42788 p_message_text => lv_message_text,
42789 p_error_text => lv_error_text,
42790 p_batch_id => lv_batch_id,
42791 p_where_str => lv_where_str,
42792 p_col_name => 'PRIORITY',
42793 p_debug => v_debug,
42794 p_default_value => G_PRIORITY );
42795
42796
42797 IF lv_return <> 0 THEN
42798 RAISE ex_logging_err;
42799 END IF;
42800
42801 --Call to customised validation.
42802
42803 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
42804 (ERRBUF => lv_error_text,
42805 RETCODE => lv_return,
42806 pBatchID => lv_batch_id,
42807 pInstanceCode => v_instance_code,
42808 pEntityName => 'MSC_ST_COMPONENT_SUBSTITUTES',
42809 pInstanceID => v_instance_id);
42810
42811 IF NVL(lv_return,0) <> 0 THEN
42812 RAISE ex_logging_err;
42813 END IF;
42814
42815 -- Set the process flag as Valid and poulate instance_id
42816 lv_return :=
42817 MSC_ST_UTIL.SET_PROCESS_FLAG(p_table_name => 'MSC_ST_COMPONENT_SUBSTITUTES',
42818 p_instance_id => v_instance_id,
42819 p_instance_code => v_instance_code,
42820 p_process_flag => G_VALID,
42821 p_error_text => lv_error_text,
42822 p_debug => v_debug,
42823 p_batch_id => lv_batch_id);
42824
42825 IF lv_return < 0 THEN
42826 RAISE ex_logging_err;
42827 END IF;
42828
42829 -- At the end calling the LOG_ERROR for logging all errored out records
42830
42831 lv_return :=
42832 msc_st_util.log_error(p_table_name => 'MSC_ST_COMPONENT_SUBSTITUTES',
42833 p_instance_code => v_instance_code,
42834 p_row => lv_column_names,
42835 p_severity => G_SEV_ERROR,
42836 p_error_text => lv_error_text,
42837 p_message_text => NULL,
42838 p_debug => v_debug,
42839 p_batch_id => lv_batch_id );
42840
42841 IF(lv_return <> 0) THEN
42842 RAISE ex_logging_err;
42843 END IF;
42844 COMMIT;
42845 END LOOP;
42846
42847 -- For OSFM Integration. Support for Co Products --
42848 -- Now validtion for MSC_ST_CO_PRODUCTS
42849
42850 --Duplicate records check for the records whose source is XML
42851
42852 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
42853 (p_app_short_name => 'MSC',
42854 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
42855 p_message_text => lv_message_text,
42856 p_error_text => lv_error_text);
42857
42858 IF lv_return <> 0 THEN
42859 RAISE ex_logging_err;
42860 END IF;
42861
42862
42863 v_sql_stmt := 36;
42864 lv_sql_stmt :=
42865 'UPDATE msc_st_co_products mcp1 '
42866 ||' SET process_flag ='|| G_ERROR_FLG||','
42867 ||' error_text = '||''''||lv_message_text||''''
42868 ||' WHERE message_id < ( SELECT max(message_id)'
42869 ||' FROM msc_st_co_products mcp2'
42870 ||' WHERE mcp2.co_product_name = mcp1.co_product_name'
42871 ||' AND mcp2.component_name = mcp1.component_name'
42872 ||' AND mcp2.sr_instance_code = mcp1.sr_instance_code'
42873 ||' AND NVL(mcp2.company_name,'||''''||NULL_CHAR||''''||') '
42874 ||' = NVL(mcp1.company_name, '||''''||NULL_CHAR||''''||') '
42875 ||' AND mcp2.process_flag = mcp1.process_flag'
42876 ||' AND NVL(mcp2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||')'
42877 ||' AND mcp1.process_flag ='|| G_IN_PROCESS
42878 ||' AND mcp1.sr_instance_code = :v_instance_code '
42879 ||' AND NVL(mcp1.message_id,'||NULL_VALUE||')<> '||NULL_VALUE;
42880
42881
42882 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
42883
42884 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
42885
42886
42887 --Duplicate records check for the records whose source is batch load
42888
42889 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
42890 (p_app_short_name => 'MSC',
42891 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
42892 p_message_text => lv_message_text,
42893 p_error_text => lv_error_text);
42894
42895 IF lv_return <> 0 THEN
42896 RAISE ex_logging_err;
42897 END IF;
42898
42899 v_sql_stmt := 37;
42900
42901 lv_sql_stmt :=
42902 'UPDATE msc_st_co_products mcp1 '
42903 ||' SET process_flag = '||G_ERROR_FLG||','
42904 ||' error_text = '||''''||lv_message_text||''''
42905 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_co_products mcp2 '
42906 ||' WHERE mcp2.co_product_name = mcp1.co_product_name'
42907 ||' AND mcp2.component_name = mcp1.component_name'
42908 ||' AND mcp2.sr_instance_code = mcp1.sr_instance_code'
42909 ||' AND NVL(mcp2.company_name,'||''''||NULL_CHAR||''''||') '
42910 ||' = NVL(mcp1.company_name, '||''''||NULL_CHAR||''''||') '
42911 ||' AND mcp2.process_flag = mcp1.process_flag'
42912 ||' AND NVL(mcp2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
42913 ||' AND mcp2.rowid <> mcp1.rowid )'
42914 ||' AND mcp1.process_flag ='|| G_IN_PROCESS
42915 ||' AND mcp1.sr_instance_code = :v_instance_code'
42916 ||' AND NVL(mcp1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
42917
42918
42919 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
42920
42921 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
42922
42923
42924 lv_column_names :=
42925 'CO_PRODUCT_NAME ||''~''||'
42926 ||'COMPONENT_NAME ||''~''||'
42927 ||'SPLIT ||''~''||'
42928 ||'PRIMARY_FLAG ||''~''||'
42929 ||'ORGANIZATION_CODE ||''~''||'
42930 ||'SR_INSTANCE_CODE ||''~''||'
42931 ||'COMPANY_NAME ||''~''||'
42932 ||'DELETED_FLAG ';
42933
42934
42935 -- Processing the MSC_ST_CO_PRODUCTS table in batch --
42936
42937 LOOP
42938 v_sql_stmt := 38;
42939 lv_cursor_stmt :=
42940 ' SELECT msc_st_batch_id_s.NEXTVAL '
42941 ||' FROM dual';
42942 OPEN c1 FOR lv_cursor_stmt;
42943 FETCH c1 INTO lv_batch_id;
42944 CLOSE c1;
42945
42946 v_sql_stmt := 39;
42947 lv_sql_stmt :=
42948 ' UPDATE msc_st_co_products '
42949 ||' SET batch_id = :lv_batch_id '
42950 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
42951 ||' AND sr_instance_code = :v_instance_code'
42952 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
42953 ||' AND rownum <= '||v_batch_size;
42954
42955
42956
42957
42958 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
42959
42960 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
42961
42962 EXIT WHEN SQL%NOTFOUND;
42963
42964
42965 OPEN c8(lv_batch_id);
42966 FETCH c8 BULK COLLECT INTO lb_rowid;
42967 CLOSE c8;
42968
42969 v_sql_stmt := 40;
42970 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
42971 UPDATE msc_st_co_products
42972 SET st_transaction_id = msc_st_co_products_s.NEXTVAL,
42973 refresh_id = v_refresh_id,
42974 last_update_date = v_current_date,
42975 last_updated_by = v_current_user,
42976 creation_date = v_current_date,
42977 created_by = v_current_user
42978 WHERE rowid = lb_rowid(j);
42979
42980
42981 -- Set the error message
42982
42983 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
42984 (p_app_short_name => 'MSC',
42985 p_error_code => 'MSC_PP_NO_DELETION',
42986 p_message_text => lv_message_text,
42987 p_error_text => lv_error_text,
42988 p_token1 => 'TABLE_NAME',
42989 p_token_value1 => 'MSC_ST_CO_PRODUCTS');
42990
42991 IF lv_return <> 0 THEN
42992 RAISE ex_logging_err;
42993 END IF;
42994
42995 --Deletion is not allowed on this table.
42996 v_sql_stmt := 41;
42997 lv_sql_stmt :=
42998 ' UPDATE msc_st_co_products'
42999 ||' SET process_flag = '||G_ERROR_FLG||','
43000 ||' error_text = '||''''||lv_message_text||''''
43001 ||' WHERE deleted_flag = '||SYS_YES
43002 ||' AND process_flag = '||G_IN_PROCESS
43003 ||' AND batch_id = :lv_batch_id'
43004 ||' AND sr_instance_code = :v_instance_code';
43005
43006
43007 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
43008
43009 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
43010
43011 -- Set the error message
43012 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
43013 (p_app_short_name => 'MSC',
43014 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
43015 p_message_text => lv_message_text,
43016 p_error_text => lv_error_text,
43017 p_token1 => 'COLUMN_NAME',
43018 p_token_value1 => 'DELETED_FLAG',
43019 p_token2 => 'DEFAULT_VALUE',
43020 p_token_value2 => SYS_NO );
43021
43022
43023
43024 -- Check whether delete flag value is in (SYS_YES,SYS_NO),if not default to SYS_NO
43025
43026 lv_where_str :=
43027 ' AND NVL(deleted_flag,'||NULL_VALUE||')NOT IN (1,2)';
43028
43029 lv_return := MSC_ST_UTIL.LOG_ERROR
43030 (p_table_name => 'MSC_ST_CO_PRODUCTS',
43031 p_instance_code => v_instance_code,
43032 p_row => lv_column_names,
43033 p_severity => G_SEV_WARNING,
43034 p_message_text => lv_message_text,
43035 p_error_text => lv_error_text,
43036 p_batch_id => lv_batch_id,
43037 p_where_str => lv_where_str,
43038 p_col_name => 'DELETED_FLAG',
43039 p_debug => v_debug,
43040 p_default_value => SYS_NO);
43041
43042
43043 IF lv_return <> 0 THEN
43044 RAISE ex_logging_err;
43045 END IF;
43046
43047
43048 -- Set the error message
43049
43050 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
43051 (p_app_short_name => 'MSC',
43052 p_error_code => 'MSC_PP_COL_VAL_NULL',
43053 p_message_text => lv_message_text,
43054 p_error_text => lv_error_text,
43055 p_token1 => 'COLUMN_NAME',
43056 p_token_value1 => 'SPLIT');
43057
43058 IF lv_return <> 0 THEN
43059 RAISE ex_logging_err;
43060 END IF;
43061
43062 -- Error out records where split is NULL
43063
43064 v_sql_stmt := 42;
43065
43066 lv_sql_stmt :=
43067 ' UPDATE msc_st_co_products '
43068 ||' SET process_flag = '||G_ERROR_FLG||','
43069 ||' error_text = '||''''||lv_message_text||''''
43070 ||' WHERE NVL(split,'||NULL_VALUE||') = '||NULL_VALUE
43071 ||' AND batch_id = :lv_batch_id'
43072 ||' AND process_flag = '||G_IN_PROCESS
43073 ||' AND sr_instance_code = :v_instance_code';
43074
43075
43076 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
43077
43078 EXECUTE IMMEDIATE lv_sql_stmt
43079 USING lv_batch_id,
43080 v_instance_code;
43081
43082
43083
43084 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
43085 (p_app_short_name => 'MSC',
43086 p_error_code => 'MSC_PP_INVALID_VALUE',
43087 p_message_text => lv_message_text,
43088 p_error_text => lv_error_text,
43089 p_token1 => 'COLUMN_NAME',
43090 p_token_value1 => 'COMPONENT_NAME');
43091
43092 IF lv_return <> 0 THEN
43093 RAISE ex_logging_err;
43094 END IF;
43095
43096 -- Derive Component_id
43097 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
43098 (p_table_name => 'MSC_ST_CO_PRODUCTS',
43099 p_item_col_name => 'COMPONENT_NAME',
43100 p_item_col_id => 'COMPONENT_ID',
43101 p_instance_id => v_instance_id,
43102 p_instance_code => v_instance_code,
43103 p_error_text => lv_error_text,
43104 p_batch_id => lv_batch_id,
43105 p_severity => G_SEV_ERROR,
43106 p_message_text => lv_message_text,
43107 p_debug => v_debug,
43108 p_row => lv_column_names);
43109
43110 IF lv_return <> 0 THEN
43111 RAISE ex_logging_err;
43112 END IF;
43113
43114
43115 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
43116 (p_app_short_name => 'MSC',
43117 p_error_code => 'MSC_PP_INVALID_VALUE',
43118 p_message_text => lv_message_text,
43119 p_error_text => lv_error_text,
43120 p_token1 => 'COLUMN_NAME',
43121 p_token_value1 => 'CO_PRODUCT_NAME');
43122
43123 IF lv_return <> 0 THEN
43124 RAISE ex_logging_err;
43125 END IF;
43126
43127 -- Derive Co_product_id
43128 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
43129 (p_table_name => 'MSC_ST_CO_PRODUCTS',
43130 p_item_col_name => 'CO_PRODUCT_NAME',
43131 p_item_col_id => 'CO_PRODUCT_ID',
43132 p_instance_id => v_instance_id,
43133 p_instance_code => v_instance_code,
43134 p_error_text => lv_error_text,
43135 p_batch_id => lv_batch_id,
43136 p_severity => G_SEV_ERROR,
43137 p_message_text => lv_message_text,
43138 p_debug => v_debug,
43139 p_row => lv_column_names);
43140
43141 IF lv_return <> 0 THEN
43142 RAISE ex_logging_err;
43143 END IF;
43144
43145
43146
43147 -- Derive the CO_PRODUCT_GROUP_ID from LOCAL ID table
43148 lv_sql_stmt :=
43149 'UPDATE MSC_ST_CO_PRODUCTS t1'
43150 ||' SET CO_PRODUCT_GROUP_ID '
43151 ||' = (SELECT local_id'
43152 ||' FROM msc_local_id_setup t2'
43153 ||' WHERE t2.char1 = t1.sr_instance_code'
43154 ||' AND NVL(t2.char2,'||''''||NULL_CHAR||''''||') '
43155 ||' = NVL(t1.company_name,'||''''||NULL_CHAR||''''||') '
43156 ||' AND t2.char4 = t1.COMPONENT_NAME '
43157 ||' AND t2.entity_name = ''CO_PRODUCT_GROUP_ID'')'
43158 ||' WHERE sr_instance_code = :v_instance_code '
43159 ||' AND batch_id = :lv_batch_id '
43160 ||' AND process_flag = '||G_IN_PROCESS;
43161
43162
43163 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
43164
43165 EXECUTE IMMEDIATE lv_sql_stmt
43166 USING v_instance_code,
43167 lv_batch_id;
43168
43169
43170 -- Error out all the records for which a CO_PRODUCT_GROUP_ID is derived.
43171 -- the idea is this record was already loaded earlier. Updation not allowed.
43172
43173 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
43174 (p_app_short_name => 'MSC',
43175 p_error_code => 'MSC_PP_NO_CO_PROD_UPDATE',
43176 p_message_text => lv_message_text,
43177 p_error_text => lv_error_text);
43178
43179 IF lv_return <> 0 THEN
43180 RAISE ex_logging_err;
43181 END IF;
43182
43183 v_sql_stmt := 43;
43184
43185 lv_sql_stmt :=
43186 ' UPDATE msc_st_co_products '
43187 ||' SET process_flag = '||G_ERROR_FLG||','
43188 ||' error_text = '||''''||lv_message_text||''''
43189 ||' WHERE NVL(co_product_group_id,'||NULL_VALUE||') <> '||NULL_VALUE
43190 ||' AND batch_id = :lv_batch_id'
43191 ||' AND process_flag = '||G_IN_PROCESS
43192 ||' AND sr_instance_code = :v_instance_code';
43193
43194
43195 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
43196
43197 EXECUTE IMMEDIATE lv_sql_stmt
43198 USING lv_batch_id,
43199 v_instance_code;
43200
43201
43202 -- Call to customised validation.
43203 -- Note this is called prior to next validation, so that records getting
43204 -- errored out in the customised validation later otherwise donot violate this.
43205
43206 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
43207 (ERRBUF => lv_error_text,
43208 RETCODE => lv_return,
43209 pBatchID => lv_batch_id,
43210 pInstanceCode => v_instance_code,
43211 pEntityName => 'MSC_ST_CO_PRODUCTS',
43212 pInstanceID => v_instance_id);
43213
43214 IF NVL(lv_return,0) <> 0 THEN
43215 RAISE ex_logging_err;
43216 END IF;
43217
43218 -- Set the error message
43219
43220 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
43221 (p_app_short_name => 'MSC',
43222 p_error_code => 'MSC_PP_INVALID_CO_PROD_SET',
43223 p_message_text => lv_message_text,
43224 p_error_text => lv_error_text);
43225
43226 IF lv_return <> 0 THEN
43227 RAISE ex_logging_err;
43228 END IF;
43229
43230 -- Error out all the co products records for that component
43231 -- if any of its co product record has errored out. The idea being
43232 -- the complete set of co-products for that component goes invalid
43233 -- Note using the request id, so that it doesn't consider the old records.
43234 v_sql_stmt := 44;
43235
43236 lv_sql_stmt :=
43237 'UPDATE msc_st_co_products mcp1 '
43238 ||' SET process_flag = '||G_PROPAGATION||','
43239 ||' error_text = '||''''||lv_message_text||''''
43240 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_co_products mcp2 '
43241 ||' WHERE mcp2.sr_instance_code = mcp1.sr_instance_code'
43242 ||' AND mcp2.component_id = mcp1.component_id'
43243 ||' AND mcp2.request_id = :v_request_id '
43244 ||' AND mcp2.process_flag = '||G_ERROR_FLG ||' )'
43245 ||' AND mcp1.process_flag ='|| G_IN_PROCESS
43246 ||' AND batch_id = :lv_batch_id'
43247 ||' AND mcp1.sr_instance_code = :v_instance_code';
43248
43249
43250 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
43251
43252 EXECUTE IMMEDIATE lv_sql_stmt
43253 USING v_request_id,
43254 lv_batch_id,
43255 v_instance_code;
43256
43257 COMMIT;
43258 END LOOP;
43259
43260 -- Next two validations donot need to propagate the error to the other in the set
43261 -- as the validation itself does it
43262
43263 -- split percentage for a component should add up to 100.
43264 -- Note: assumption is a component can have only one group of co products.
43265 -- Set the error message
43266 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
43267 (p_app_short_name => 'MSC',
43268 p_error_code => 'MSC_PP_CO_PROD_SPLIT_INVALID',
43269 p_message_text => lv_message_text,
43270 p_error_text => lv_error_text,
43271 p_token1 => 'COLUMN_NAME',
43272 p_token_value1 => 'SPLIT');
43273
43274 IF lv_return <> 0 THEN
43275 RAISE ex_logging_err;
43276 END IF;
43277
43278 v_sql_stmt := 45;
43279 lv_sql_stmt :=
43280 'UPDATE msc_st_co_products mcp1'
43281 ||' SET process_flag = '||G_ERROR_FLG||','
43282 ||' error_text = '||''''||lv_message_text||''''
43283 ||' WHERE 100 <> ( SELECT sum(split) '
43284 ||' FROM msc_st_co_products mcp2'
43285 ||' WHERE mcp2.component_name = mcp1.component_name'
43286 ||' AND mcp2.sr_instance_code = mcp1.sr_instance_code'
43287 ||' AND NVL(mcp2.company_name,'||''''||NULL_CHAR||''''||') '
43288 ||' = NVL(mcp1.company_name, '||''''||NULL_CHAR||''''||') '
43289 ||' AND mcp2.process_flag = mcp1.process_flag'
43290 ||' GROUP BY sr_instance_code,organization_code,company_name,'
43291 ||' component_name)'
43292 ||' AND mcp1.process_flag = '||G_IN_PROCESS
43293 ||' AND mcp1.sr_instance_code = :v_instance_code';
43294
43295
43296 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
43297
43298 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
43299
43300 -- one component should have one and only one primary co product.
43301 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
43302 (p_app_short_name => 'MSC',
43303 p_error_code => 'MSC_PP_MULTI_PRI_CO_PROD',
43304 p_message_text => lv_message_text,
43305 p_error_text => lv_error_text,
43306 p_token1 => 'COLUMN_NAME',
43307 p_token_value1 => 'PRIMARY_FLAG');
43308
43309 IF lv_return <> 0 THEN
43310 RAISE ex_logging_err;
43311 END IF;
43312
43313 v_sql_stmt := 46;
43314 lv_sql_stmt :=
43315 'UPDATE msc_st_co_products mcp1'
43316 ||' SET process_flag = '||G_ERROR_FLG||','
43317 ||' error_text = '||''''||lv_message_text||''''
43318 ||' WHERE 1 <> ( SELECT COUNT(*) '
43319 ||' FROM msc_st_co_products mcp2'
43320 ||' WHERE mcp2.component_name = mcp1.component_name'
43321 ||' AND mcp2.sr_instance_code = mcp1.sr_instance_code'
43322 ||' AND NVL(mcp2.company_name,'||''''||NULL_CHAR||''''||') '
43323 ||' = NVL(mcp1.company_name, '||''''||NULL_CHAR||''''||') '
43324 ||' AND mcp2.primary_flag = 1'
43325 ||' AND mcp2.process_flag = mcp1.process_flag'
43326 ||' GROUP BY sr_instance_code,organization_code,company_name,'
43327 ||' component_name )'
43328 ||' AND mcp1.process_flag = '||G_IN_PROCESS
43329 ||' AND mcp1.sr_instance_code = :v_instance_code';
43330
43331
43332 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
43333
43334 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
43335
43336 -- Generate co_product_group_id. This is only needed in the local_id table
43337 -- and not used any where else.
43338
43339 v_sql_stmt := 47;
43340
43341 OPEN c9 ;
43342 FETCH c9 BULK COLLECT INTO lb_rowid ;
43343
43344 IF c9%ROWCOUNT > 0 THEN
43345
43346 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
43347
43348 UPDATE msc_st_co_products
43349 SET co_product_group_id = msc_st_co_product_group_id_s.NEXTVAL
43350 WHERE rowid = lb_rowid(j);
43351
43352
43353 v_sql_stmt := 48;
43354 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
43355
43356 -- Insert into the LID table with the user defined key
43357
43358 INSERT INTO msc_local_id_setup
43359 (local_id,
43360 st_transaction_id,
43361 instance_id,
43362 entity_name,
43363 data_source_type,
43364 char1,
43365 char2,
43366 char4,
43367 SOURCE_COMPONENT_ID ,
43368 SOURCE_CO_PRODUCT_ID ,
43369 SOURCE_CO_PRODUCT_GROUP_ID ,
43370 last_update_date,
43371 last_updated_by,
43372 creation_date,
43373 created_by )
43374 SELECT
43375 co_product_group_id,
43376 st_transaction_id,
43377 v_instance_id,
43378 'CO_PRODUCT_GROUP_ID',
43379 data_source_type,
43380 v_instance_code,
43381 company_name,
43382 component_name,
43383 SOURCE_COMPONENT_ID ,
43384 SOURCE_CO_PRODUCT_ID ,
43385 SOURCE_CO_PRODUCT_GROUP_ID ,
43386 v_current_date,
43387 v_current_user,
43388 v_current_date,
43389 v_current_user
43390 FROM msc_st_co_products
43391 WHERE rowid = lb_rowid(j);
43392
43393 END IF;
43394 CLOSE c9;
43395
43396
43397
43398 -- Set the process flag as Valid and derive sr_instance_id
43399 lv_return :=
43400 MSC_ST_UTIL.SET_PROCESS_FLAG(p_table_name => 'MSC_ST_CO_PRODUCTS',
43401 p_instance_id => v_instance_id,
43402 p_instance_code => v_instance_code,
43403 p_process_flag => G_VALID,
43404 p_error_text => lv_error_text,
43405 p_debug => v_debug);
43406
43407 IF lv_return < 0 THEN
43408 RAISe ex_logging_err;
43409 END IF;
43410
43411
43412 -- At the end calling the LOG_ERROR for logging all errored out records
43413
43414 lv_return :=
43415 MSC_ST_UTIL.LOG_ERROR(p_table_name => 'MSC_ST_CO_PRODUCTS',
43416 p_instance_code => v_instance_code,
43417 p_row => lv_column_names,
43418 p_severity => G_SEV_ERROR,
43419 p_message_text => NULL,
43420 p_error_text => lv_error_text,
43421 p_debug => v_debug );
43422
43423 IF lv_return < 0 THEN
43424 RAISe ex_logging_err;
43425 END IF;
43426
43427 COMMIT;
43428 -- Now Updating the tables MSC_ST_BOMS and MSC_ST_BOM_COMPONENTS.
43429
43430 LOAD_CO_PRODUCT_BOMS;
43431
43432
43433 EXCEPTION
43434 WHEN too_many_rows THEN
43435 lv_error_text :=substr('MSC_CL_PRE_PROCESS.LOAD_BOM'||'('
43436 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
43437 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
43438 ROLLBACK ;
43439
43440 WHEN ex_logging_err THEN
43441 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
43442 ROLLBACK;
43443
43444 WHEN OTHERS THEN
43445 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_BOM'||'('
43446 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
43447 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
43448 ROLLBACK;
43449
43450 END LOAD_BOM;
43451
43452
43453
43454
43455 /*==========================================================================+
43456 | DESCRIPTION : This function performs the validation and loads the data |
43457 | for business object ROUTING. |
43458 +==========================================================================*/
43459
43460 PROCEDURE LOAD_ROUTING IS
43461
43462 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
43463 TYPE CurTyp IS REF CURSOR;
43464 c1 CurTyp;
43465 lb_rowid RowidTab;
43466
43467 lv_local_id NUMBER;
43468 lv_column_names VARCHAR2(5000); -- Stores concatenated column names
43469 lv_return NUMBER;
43470 lv_error_text VARCHAR2(250);
43471 lv_where_str VARCHAR2(5000);
43472 lv_sql_stmt VARCHAR2(5000);
43473 lv_cursor_stmt VARCHAR2(5000);
43474 lv_batch_id msc_st_routings.batch_id%TYPE;
43475 lv_message_text msc_errors.error_text%TYPE;
43476 ex_logging_err EXCEPTION;
43477
43478
43479 CURSOR c2(p_batch_id NUMBER) IS
43480 SELECT rowid
43481 FROM msc_st_routings
43482 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
43483 AND sr_instance_code = v_instance_code
43484 AND batch_id = p_batch_id;
43485
43486 CURSOR c3(p_batch_id NUMBER) IS
43487 SELECT rowid
43488 FROM msc_st_routings
43489 WHERE process_flag = G_IN_PROCESS
43490 AND sr_instance_code = v_instance_code
43491 AND batch_id = p_batch_id
43492 AND NVL(routing_sequence_id,NULL_VALUE) = NULL_VALUE
43493 AND deleted_flag = SYS_NO;
43494
43495 CURSOR c4(p_batch_id NUMBER) IS
43496 SELECT rowid
43497 FROM msc_st_routing_operations
43498 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
43499 AND sr_instance_code = v_instance_code
43500 AND batch_id = p_batch_id;
43501
43502 CURSOR c5(p_batch_id NUMBER) IS
43503 SELECT rowid
43504 FROM msc_st_routing_operations
43505 WHERE process_flag = G_IN_PROCESS
43506 AND sr_instance_code = v_instance_code
43507 AND batch_id = p_batch_id
43508 AND NVL(operation_sequence_id,NULL_VALUE) = NULL_VALUE
43509 AND deleted_flag = SYS_NO;
43510
43511 CURSOR c6(p_batch_id NUMBER) IS
43512 SELECT rowid
43513 FROM msc_st_operation_resources
43514 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
43515 AND sr_instance_code = v_instance_code
43516 AND batch_id = p_batch_id;
43517
43518 CURSOR c7(p_batch_id NUMBER) IS
43519 SELECT max(rowid)
43520 FROM msc_st_operation_resources
43521 WHERE process_flag = G_IN_PROCESS
43522 AND sr_instance_code = v_instance_code
43523 AND batch_id = p_batch_id
43524 AND NVL(resource_seq_num,NULL_VALUE) = NULL_VALUE
43525 AND deleted_flag = SYS_NO
43526 GROUP BY sr_instance_code,company_name,
43527 organization_code,routing_name,
43528 operation_seq_code,resource_seq_code,
43529 alternate_routing_designator,alternate_number;
43530
43531 CURSOR c8(p_batch_id NUMBER) IS
43532 SELECT max(rowid)
43533 FROM msc_st_operation_resources
43534 WHERE process_flag = G_IN_PROCESS
43535 AND sr_instance_code = v_instance_code
43536 AND batch_id = p_batch_id
43537 AND NVL(resource_seq_num,NULL_VALUE) <> NULL_VALUE
43538 AND NVL(operation_sequence_id,NULL_VALUE) <> NULL_VALUE
43539 AND NVL(routing_sequence_id,NULL_VALUE) <> NULL_VALUE
43540 GROUP BY sr_instance_code, operation_sequence_id,
43541 routing_sequence_id,resource_seq_num ;
43542
43543 -- For OSFM Integration
43544
43545 CURSOR c9(p_batch_id NUMBER) IS
43546 SELECT rowid
43547 FROM msc_st_operation_networks
43548 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
43549 AND sr_instance_code = v_instance_code
43550 AND batch_id = p_batch_id;
43551
43552
43553 -- For bug 3549086
43554
43555 CURSOR c10(p_batch_id NUMBER) IS
43556 SELECT max(rowid)
43557 FROM msc_st_routing_operations
43558 WHERE process_flag IN (G_IN_PROCESS)
43559 AND sr_instance_code = v_instance_code
43560 AND batch_id = p_batch_id
43561 AND NVL(department_id,NULL_VALUE) = NULL_VALUE
43562 GROUP BY sr_instance_code,company_name,
43563 organization_code,department_code ;
43564
43565 BEGIN
43566 --Duplicate records check for the records whose source is XML
43567
43568 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
43569 (p_app_short_name => 'MSC',
43570 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
43571 p_message_text => lv_message_text,
43572 p_error_text => lv_error_text);
43573
43574 IF lv_return <> 0 THEN
43575 RAISE ex_logging_err;
43576 END IF;
43577
43578 -- Duplicate UDK validation for XML message
43579
43580 v_sql_stmt := 01;
43581 lv_sql_stmt :=
43582 'UPDATE msc_st_routings msr1'
43583 ||' SET process_flag = '||G_ERROR_FLG||','
43584 ||' error_text = '||''''||lv_message_text||''''
43585 ||' WHERE message_id < (SELECT MAX(message_id)'
43586 ||' FROM msc_st_routings msr2'
43587 ||' WHERE msr2.sr_instance_code = msr1.sr_instance_code'
43588 ||' AND NVL(msr2.company_name,'||''''||NULL_CHAR||''''||') '
43589 ||' = NVL(msr1.company_name,'||''''||NULL_CHAR||''''||') '
43590 ||' AND msr2.organization_code = msr1.organization_code'
43591 ||' AND NVL(msr2.routing_name,'||''''||NULL_CHAR||''''||') '
43592 ||' = NVL(msr1.routing_name,'||''''||NULL_CHAR||''''||') '
43593 ||' AND msr2.assembly_name = msr1.assembly_name'
43594 ||' AND NVL(msr2.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
43595 ||' = NVL(msr1.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
43596 ||' AND msr2.process_flag ='||G_IN_PROCESS
43597 ||' AND NVL(msr2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||')'
43598 ||' AND msr1.process_flag = '||G_IN_PROCESS
43599 ||' AND msr1.sr_instance_code = :v_instance_code'
43600 ||' AND NVL(msr1.message_id,'||NULL_VALUE||')<> '||NULL_VALUE;
43601
43602
43603 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
43604
43605 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
43606
43607 --Duplicate records check for the records whose source is batch load
43608
43609 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
43610 (p_app_short_name => 'MSC',
43611 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
43612 p_message_text => lv_message_text,
43613 p_error_text => lv_error_text);
43614
43615 IF lv_return <> 0 THEN
43616 RAISE ex_logging_err;
43617 END IF;
43618
43619 v_sql_stmt := 02;
43620
43621 lv_sql_stmt :=
43622 'UPDATE msc_st_routings msr1 '
43623 ||' SET process_flag = '||G_ERROR_FLG||','
43624 ||' error_text = '||''''||lv_message_text||''''
43625 ||' WHERE EXISTS ( SELECT 1 FROM msc_st_routings msr2'
43626 ||' WHERE msr2.sr_instance_code = msr1.sr_instance_code'
43627 ||' AND NVL(msr2.company_name,'||''''||NULL_CHAR||''''||') '
43628 ||' = NVL(msr1.company_name,'||''''||NULL_CHAR||''''||') '
43629 ||' AND msr2.organization_code = msr1.organization_code'
43630 ||' AND NVL(msr2.routing_name,'||''''||NULL_CHAR||''''||') '
43631 ||' = NVL(msr1.routing_name,'||''''||NULL_CHAR||''''||') '
43632 ||' AND msr2.assembly_name = msr1.assembly_name'
43633 ||' AND NVL(msr2.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
43634 ||' = NVL(msr1.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
43635 ||' AND msr2.process_flag ='||G_IN_PROCESS
43636 ||' AND NVL(msr2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
43637 ||' GROUP BY sr_instance_code,organization_code,company_name,routing_name, '
43638 ||' assembly_name, alternate_routing_designator '
43639 ||' HAVING COUNT(*) >1 )'
43640 ||' AND msr1.process_flag = '||G_IN_PROCESS
43641 ||' AND msr1.sr_instance_code = :v_instance_code'
43642 ||' AND NVL(msr1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
43643
43644
43645 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
43646
43647 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
43648
43649 -- For OSFM integration
43650 -- Network routings should have FIRST_OP_SEQ_NUM and LAST_OP_SEQ_NUM
43651 -- corresponding to these should have FIRST_OPERATION_SEQ_CODE and LAST_OPERATION_SEQ_CODE
43652 -- in the control files.
43653 lv_column_names :=
43654 'ROUTING_NAME ||''~''||'
43655 ||' ASSEMBLY_NAME ||''~''||'
43656 ||' ROUTING_TYPE ||''~''||'
43657 ||' ORGANIZATION_CODE ||''~''||'
43658 ||' SR_INSTANCE_CODE ||''~''||'
43659 ||' ROUTING_COMMENT ||''~''||'
43660 ||' ALTERNATE_ROUTING_DESIGNATOR ||''~''||'
43661 ||' PROJECT_NUMBER ||''~''||'
43662 ||' TASK_NUMBER ||''~''||'
43663 ||' LINE_CODE ||''~''||'
43664 ||' UOM_CODE ||''~''||'
43665 ||' CFM_ROUTING_FLAG ||''~''||'
43666 ||' CTP_FLAG ||''~''||'
43667 ||' ROUTING_QUANTITY ||''~''||'
43668 ||' DELETED_FLAG ||''~''||'
43669 ||' BOM_NAME ||''~''||'
43670 ||' ALTERNATE_BOM_DESIGNATOR ||''~''||'
43671 ||' FIRST_OPERATION_SEQ_CODE ||''~''||'
43672 ||' LAST_OPERATION_SEQ_CODE ||''~''||'
43673 ||' COMPANY_NAME ' ;
43674
43675
43676 -- Now processing by batch
43677 LOOP
43678 v_sql_stmt := 03;
43679 lv_cursor_stmt :=
43680 ' SELECT msc_st_batch_id_s.NEXTVAL '
43681 ||' FROM dual';
43682
43683 OPEN c1 FOR lv_cursor_stmt;
43684 FETCH c1 INTO lv_batch_id;
43685 CLOSE c1;
43686
43687 v_sql_stmt := 04;
43688 lv_sql_stmt :=
43689 ' UPDATE msc_st_routings '
43690 ||' SET batch_id = :lv_batch_id'
43691 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
43692 ||' AND sr_instance_code = :v_instance_code'
43693 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
43694 ||' AND rownum <= '||v_batch_size;
43695
43696
43697 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
43698
43699 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
43700
43701 EXIT WHEN SQL%NOTFOUND;
43702
43703 OPEN c2(lv_batch_id);
43704 FETCH c2 BULK COLLECT INTO lb_rowid;
43705 CLOSE c2;
43706
43707 v_sql_stmt := 05;
43708 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
43709 UPDATE msc_st_routings
43710 SET st_transaction_id = msc_st_routings_s.NEXTVAL,
43711 refresh_id = v_refresh_id,
43712 last_update_date = v_current_date,
43713 last_updated_by = v_current_user,
43714 creation_date = v_current_date,
43715 created_by = v_current_user
43716 WHERE rowid = lb_rowid(j);
43717
43718
43719 -- Set the message
43720 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
43721 (p_app_short_name => 'MSC',
43722 p_error_code => 'MSC_PP_NO_DELETION',
43723 p_message_text => lv_message_text,
43724 p_error_text => lv_error_text,
43725 p_token1 => 'TABLE_NAME',
43726 p_token_value1 => 'MSC_ST_ROUTINGS');
43727
43728 IF lv_return <> 0 THEN
43729 RAISE ex_logging_err;
43730 END IF;
43731
43732 --Deletion is not allowed on this table.
43733 v_sql_stmt := 06;
43734 lv_sql_stmt :=
43735 ' UPDATE msc_st_routings '
43736 ||' SET process_flag ='||G_ERROR_FLG||','
43737 ||' error_text = '||''''||lv_message_text||''''
43738 ||' WHERE deleted_flag = '||SYS_YES
43739 ||' AND process_flag = '||G_IN_PROCESS
43740 ||' AND batch_id = :lv_batch_id'
43741 ||' AND sr_instance_code = :v_instance_code';
43742
43743
43744 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
43745
43746 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
43747
43748 -- Set the error message
43749 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
43750 (p_app_short_name => 'MSC',
43751 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
43752 p_message_text => lv_message_text,
43753 p_error_text => lv_error_text,
43754 p_token1 => 'COLUMN_NAME',
43755 p_token_value1 => 'DELETED_FLAG',
43756 p_token2 => 'DEFAULT_VALUE',
43757 p_token_value2 => SYS_NO );
43758
43759 IF lv_return <> 0 THEN
43760 RAISE ex_logging_err;
43761 END IF;
43762
43763 -- Check DELETE_FLAG column has valid value or not and if not set it to SYS_NO
43764 -- Log error procedure inserts warning and also defaults the delete flag
43765
43766 lv_where_str :=
43767 ' AND NVL(deleted_flag,'||NULL_VALUE||') <>'||SYS_NO;
43768
43769 lv_return := MSC_ST_UTIL.LOG_ERROR
43770 (p_table_name => 'MSC_ST_ROUTINGS',
43771 p_instance_code => v_instance_code,
43772 p_row => lv_column_names,
43773 p_severity => G_SEV_WARNING,
43774 p_message_text => lv_message_text,
43775 p_error_text => lv_error_text,
43776 p_batch_id => lv_batch_id,
43777 p_where_str => lv_where_str,
43778 p_col_name => 'DELETED_FLAG',
43779 p_debug => v_debug,
43780 p_default_value => SYS_NO);
43781
43782 IF lv_return <> 0 THEN
43783 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,lv_error_text);
43784 END IF;
43785
43786 -- Set the message
43787
43788 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
43789 (p_app_short_name => 'MSC',
43790 p_error_code => 'MSC_PP_INVALID_VALUE',
43791 p_message_text => lv_message_text,
43792 p_error_text => lv_error_text,
43793 p_token1 => 'COLUMN_NAME',
43794 p_token_value1 => 'ORGANIZATION_CODE');
43795
43796 IF lv_return <> 0 THEN
43797 RAISE ex_logging_err;
43798 END IF;
43799
43800 -- derive organization id , call utilty package- msc_st_util's procedure
43801
43802 lv_return :=
43803 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name => 'MSC_ST_ROUTINGS',
43804 p_org_partner_name => 'ORGANIZATION_CODE',
43805 p_org_partner_id => 'ORGANIZATION_ID',
43806 p_instance_code => v_instance_code,
43807 p_partner_type => G_ORGANIZATION,
43808 p_severity => G_SEV_ERROR,
43809 p_message_text => lv_message_text,
43810 p_batch_id => lv_batch_id,
43811 p_debug => v_debug,
43812 p_error_text => lv_error_text);
43813
43814 if(lv_return <> 0) then
43815 RAISE ex_logging_err;
43816 end if;
43817
43818 -- Set the message
43819
43820 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
43821 (p_app_short_name => 'MSC',
43822 p_error_code => 'MSC_PP_INVALID_VALUE',
43823 p_message_text => lv_message_text,
43824 p_error_text => lv_error_text,
43825 p_token1 => 'COLUMN_NAME',
43826 p_token_value1 => 'ASSEMBLY_NAME');
43827
43828 IF lv_return <> 0 THEN
43829 RAISE ex_logging_err;
43830 END IF;
43831
43832 -- Derive assembly item id
43833
43834 lv_return :=
43835 MSC_ST_UTIL.DERIVE_ITEM_ID(p_table_name => 'MSC_ST_ROUTINGS',
43836 p_item_col_name => 'ASSEMBLY_NAME',
43837 p_item_col_id => 'ASSEMBLY_ITEM_ID',
43838 p_instance_code => v_instance_code,
43839 p_instance_id => v_instance_id,
43840 p_severity => G_SEV_ERROR,
43841 p_message_text => lv_message_text,
43842 p_batch_id => lv_batch_id,
43843 p_debug => v_debug,
43844 p_error_text => lv_error_text);
43845
43846
43847 if(lv_return <> 0) then
43848 RAISE ex_logging_err;
43849 end if;
43850
43851
43852 -- Now check whether Routing Name is NULL , if it is NULL we will populate
43853 -- Assembly Name in Routing Name column for all such records
43854
43855 v_sql_stmt := 07;
43856
43857 lv_sql_stmt :=
43858 'UPDATE msc_st_routings '
43859 ||' SET routing_name = assembly_name'
43860 ||' WHERE sr_instance_code = :v_instance_code'
43861 ||' AND process_flag ='|| G_IN_PROCESS
43862 ||' AND NVL(routing_name,'||''''||NULL_CHAR||''''||') '
43863 ||' = '||''''||NULL_CHAR||''''
43864 ||' AND batch_id = :lv_batch_id ';
43865
43866
43867 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
43868
43869 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
43870
43871
43872 -- Derive the ROUTING_SEQUENCE_ID from LOCAL ID table
43873
43874 lv_return :=msc_st_util.derive_routing_sequence_id
43875 (p_table_name => 'MSC_ST_ROUTINGS',
43876 p_rtg_col_name => 'ROUTING_NAME',
43877 p_rtg_col_id =>'ROUTING_SEQUENCE_ID',
43878 p_instance_code => v_instance_code,
43879 p_batch_id => lv_batch_id,
43880 p_debug => v_debug,
43881 p_error_text => lv_error_text);
43882
43883 if (lv_return <> 0 )then
43884 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,lv_error_text);
43885 end if;
43886
43887 -- Set the error message
43888 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
43889 (p_app_short_name => 'MSC',
43890 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
43891 p_message_text => lv_message_text,
43892 p_error_text => lv_error_text,
43893 p_token1 => 'COLUMN_NAME',
43894 p_token_value1 => 'ROUTING_TYPE',
43895 p_token2 => 'DEFAULT_VALUE',
43896 p_token_value2 => G_ROUTING_TYPE);
43897
43898 IF lv_return <> 0 THEN
43899 RAISE ex_logging_err;
43900 END IF;
43901
43902 -- Defualt routing type
43903
43904 lv_where_str :=
43905 ' AND NVL(routing_type,'||NULL_VALUE||') NOT IN (1,2)';
43906
43907 lv_return := MSC_ST_UTIL.LOG_ERROR
43908 (p_table_name => 'MSC_ST_ROUTINGS',
43909 p_instance_code => v_instance_code,
43910 p_row => lv_column_names,
43911 p_severity => G_SEV_WARNING,
43912 p_message_text => lv_message_text,
43913 p_error_text => lv_error_text,
43914 p_batch_id => lv_batch_id,
43915 p_where_str => lv_where_str,
43916 p_col_name => 'ROUTING_TYPE',
43917 p_debug => v_debug,
43918 p_default_value => G_ROUTING_TYPE);
43919
43920
43921 IF lv_return <> 0 THEN
43922 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,lv_error_text);
43923 END IF;
43924
43925 -- Set the error message
43926 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
43927 (p_app_short_name => 'MSC',
43928 p_error_code => 'MSC_PP_FK_REF_NOT_EXIST',
43929 p_message_text => lv_message_text,
43930 p_error_text => lv_error_text,
43931 p_token1 => 'COLUMN_NAMES',
43932 p_token_value1 => ' SR_INSTANCE_CODE, COMPANY_NAME,'
43933 ||' ORGANIZATION_CODE AND PROJECT_NUMBER',
43934 p_token2 => 'MASTER_TABLE',
43935 p_token_value2 => 'MSC_ST_PROJECT_TASKS');
43936
43937 IF lv_return <> 0 THEN
43938 RAISE ex_logging_err;
43939 END IF;
43940
43941 --Derive Project Id.
43942 lv_return:= MSC_ST_UTIL.DERIVE_PROJ_TASK_ID
43943 (p_table_name => 'MSC_ST_ROUTINGS',
43944 p_proj_col_name => 'PROJECT_NUMBER',
43945 p_proj_task_col_id => 'PROJECT_ID',
43946 p_instance_code => v_instance_code,
43947 p_entity_name => 'PROJECT_ID',
43948 p_error_text => lv_error_text,
43949 p_batch_id => lv_batch_id,
43950 p_severity => G_SEV_WARNING,
43951 p_message_text => lv_message_text,
43952 p_debug => v_debug,
43953 p_row => lv_column_names);
43954 IF lv_return<> 0 THEN
43955 RAISE ex_logging_err;
43956 END IF;
43957
43958 -- Set the error message
43959 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
43960 (p_app_short_name => 'MSC',
43961 p_error_code => 'MSC_PP_FK_REF_NOT_EXIST',
43962 p_message_text => lv_message_text,
43963 p_error_text => lv_error_text,
43964 p_token1 => 'COLUMN_NAMES',
43965 p_token_value1 => ' SR_INSTANCE_CODE, COMPANY_NAME,'
43966 ||' ORGANIZATION_CODE, PROJECT_NUMBER,'
43967 ||' TASK_NUMBER',
43968 p_token2 => 'MASTER_TABLE',
43969 p_token_value2 => 'MSC_ST_PROJECT_TASKS');
43970
43971 IF lv_return <> 0 THEN
43972 RAISE ex_logging_err;
43973 END IF;
43974
43975 --Derive Task Id.
43976 lv_return:= MSC_ST_UTIL.DERIVE_PROJ_TASK_ID
43977 (p_table_name => 'MSC_ST_ROUTINGS',
43978 p_proj_col_name => 'PROJECT_NUMBER',
43979 p_proj_task_col_id => 'TASK_ID',
43980 p_instance_code => v_instance_code,
43981 p_entity_name => 'TASK_ID',
43982 p_error_text => lv_error_text,
43983 p_task_col_name => 'TASK_NUMBER',
43984 p_batch_id => lv_batch_id,
43985 p_severity => G_SEV_WARNING,
43986 p_message_text => lv_message_text,
43987 p_debug => v_debug,
43988 p_row => lv_column_names);
43989
43990 IF lv_return<> 0 THEN
43991 RAISE ex_logging_err;
43992 END IF;
43993
43994 -- Derive LINE_ID
43995 v_sql_stmt := 08;
43996
43997 lv_sql_stmt :=
43998 'UPDATE msc_st_routings msr'
43999 ||' SET line_id = ( SELECT local_id'
44000 ||' FROM msc_local_id_setup mlis'
44001 ||' WHERE mlis.char1 = msr.sr_instance_code'
44002 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
44003 ||' = NVL(msr.company_name,'||''''||NULL_CHAR||''''||') '
44004 ||' AND mlis.char3 = msr.organization_code'
44005 ||' AND mlis.char4 = msr.line_code'
44006 ||' AND mlis.entity_name = ''LINE_ID'')'
44007 ||' WHERE sr_instance_code = :v_instance_code'
44008 ||' AND process_flag = '||G_IN_PROCESS
44009 ||' AND batch_id = :lv_batch_id';
44010
44011
44012 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
44013
44014 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
44015
44016 -- Set the message
44017
44018 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
44019 (p_app_short_name => 'MSC',
44020 p_error_code => 'MSC_PP_INVALID_VALUE',
44021 p_message_text => lv_message_text,
44022 p_error_text => lv_error_text,
44023 p_token1 => 'COLUMN_NAME',
44024 p_token_value1 => 'UOM_CODE');
44025
44026 IF lv_return <> 0 THEN
44027 RAISE ex_logging_err;
44028 END IF;
44029
44030 -- Validate the UOM code
44031
44032 v_sql_stmt := 09;
44033 lv_sql_stmt :=
44034 'UPDATE msc_st_routings msr'
44035 ||' SET process_flag ='||G_ERROR_FLG||','
44036 ||' error_text = '||''''||lv_message_text||''''
44037 ||' WHERE NOT EXISTS (SELECT 1'
44038 ||' FROM msc_units_of_measure muom'
44039 ||' WHERE NVL(muom.uom_code, '||''''||NULL_CHAR||''''||') = '
44040 ||' NVL(msr.uom_code, '||''''||NULL_CHAR||''''||')'
44041 ||' UNION'
44042 ||' SELECT 1 FROM msc_st_units_of_measure msuom'
44043 ||' WHERE NVL(msuom.uom_code, '||''''||NULL_CHAR||''''||') = '
44044 ||' NVL(msr.uom_code,'||''''||NULL_CHAR||''''||')'
44045 ||' AND msuom.process_flag = '||G_VALID
44046 ||' AND msuom.sr_instance_id = :v_instance_id)'
44047 ||' AND NVL(msr.uom_code,'||''''||NULL_CHAR||''''||') '
44048 ||' <> '||''''||NULL_CHAR||''''
44049 ||' AND msr.sr_instance_code = :v_instance_code'
44050 ||' AND msr.batch_id = :lv_batch_id'
44051 ||' AND msr.process_flag = '||G_IN_PROCESS ;
44052
44053
44054 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
44055
44056 EXECUTE IMMEDIATE lv_sql_stmt
44057 USING v_instance_id,
44058 v_instance_code,
44059 lv_batch_id;
44060
44061 -- Set the error message
44062 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
44063 (p_app_short_name => 'MSC',
44064 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
44065 p_message_text => lv_message_text,
44066 p_error_text => lv_error_text,
44067 p_token1 => 'COLUMN_NAME',
44068 p_token_value1 => 'CTP_FLAG',
44069 p_token2 => 'DEFAULT_VALUE',
44070 p_token_value2 => G_CTP_FLAG );
44071
44072 IF lv_return <> 0 THEN
44073 RAISE ex_logging_err;
44074 END IF;
44075
44076 -- Defualt CTP FLAG as 2(No) if NOT IN (1,2)
44077
44078 lv_where_str := ' AND ctp_flag NOT IN (1,2)';
44079
44080 lv_return := MSC_ST_UTIL.LOG_ERROR
44081 (p_table_name => 'MSC_ST_ROUTINGS',
44082 p_instance_code => v_instance_code,
44083 p_row => lv_column_names,
44084 p_severity => G_SEV_WARNING,
44085 p_message_text => lv_message_text,
44086 p_error_text => lv_error_text,
44087 p_batch_id => lv_batch_id,
44088 p_where_str => lv_where_str,
44089 p_col_name => 'CTP_FLAG',
44090 p_debug => v_debug,
44091 p_default_value => G_CTP_FLAG);
44092
44093 IF lv_return<> 0 THEN
44094 RAISE ex_logging_err;
44095 END IF;
44096
44097 -- Set the error message
44098 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
44099 (p_app_short_name => 'MSC',
44100 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
44101 p_message_text => lv_message_text,
44102 p_error_text => lv_error_text,
44103 p_token1 => 'COLUMN_NAME',
44104 p_token_value1 => 'CFM_ROUTING_FLAG',
44105 p_token2 => 'DEFAULT_VALUE',
44106 p_token_value2 => G_CFM_ROUTING_FLAG );
44107
44108 IF lv_return <> 0 THEN
44109 RAISE ex_logging_err;
44110 END IF;
44111
44112 -- Defualt CFM flag as 2(No) if NOT IN (1,2,3)
44113 -- 3 added for Network Routing, now supported by OSFM integration.
44114
44115 lv_where_str := ' AND cfm_routing_flag NOT IN (1,2,3)';
44116
44117 lv_return := MSC_ST_UTIL.LOG_ERROR
44118 (p_table_name => 'MSC_ST_ROUTINGS',
44119 p_instance_code => v_instance_code,
44120 p_row => lv_column_names,
44121 p_severity => G_SEV_WARNING,
44122 p_message_text => lv_message_text,
44123 p_error_text => lv_error_text,
44124 p_batch_id => lv_batch_id,
44125 p_where_str => lv_where_str,
44126 p_col_name => 'CFM_ROUTING_FLAG',
44127 p_debug => v_debug,
44128 p_default_value => G_CFM_ROUTING_FLAG);
44129
44130 IF lv_return<> 0 THEN
44131 RAISE ex_logging_err;
44132 END IF;
44133
44134 -- Now we will check whether BOM Name is NULL , if it is NULL we will populate the
44135 -- ASSEMBLY NAME in BOM NAME column for all such records
44136
44137 v_sql_stmt := 10;
44138 lv_sql_stmt :=
44139 'UPDATE msc_st_routings '
44140 ||' SET bom_name = assembly_name'
44141 ||' WHERE sr_instance_code = :v_instance_code'
44142 ||' AND process_flag = '||G_IN_PROCESS
44143 ||' AND NVL(bom_name,'||''''||NULL_CHAR||''''||') '
44144 ||' = '||''''||NULL_CHAR||''''
44145 ||' AND batch_id = :lv_batch_id ';
44146
44147
44148 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
44149
44150 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
44151
44152
44153 -- Set the error message
44154 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
44155 (p_app_short_name => 'MSC',
44156 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
44157 p_message_text => lv_message_text,
44158 p_error_text => lv_error_text,
44159 p_token1 => 'COLUMN_NAMES',
44160 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
44161 ||'ORGANIZATION_CODE,BOM_NAME',
44162 p_token2 => 'MASTER_TABLE',
44163 p_token_value2 => 'MSC_ST_BOMS',
44164 p_token3 => 'CHILD_TABLE' ,
44165 p_token_value3 => 'MSC_ST_ROUTINGS' );
44166
44167 -- Derive the bill_sequence_id
44168
44169 lv_return :=
44170 MSC_ST_UTIL.DERIVE_BILL_SEQUENCE_ID
44171 (p_table_name => 'MSC_ST_ROUTINGS',
44172 p_row => lv_column_names,
44173 p_bom_col_name => 'BOM_NAME',
44174 p_bom_col_id => 'BILL_SEQUENCE_ID',
44175 p_instance_code => v_instance_code,
44176 p_severity => G_SEV_WARNING,
44177 p_message_text => lv_message_text,
44178 p_batch_id => lv_batch_id,
44179 p_debug => v_debug,
44180 p_error_text => lv_error_text);
44181
44182 IF lv_return<> 0 THEN
44183 RAISE ex_logging_err;
44184 END IF;
44185
44186 -- For OSFM Integration
44187 -- for Network Routings first_operation_seq_code or last_operation_seq_code cannot be null.
44188 -- Set the error message
44189 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
44190 (p_app_short_name => 'MSC',
44191 p_error_code => 'MSC_PP_COL_VAL_NULL',
44192 p_message_text => lv_message_text,
44193 p_error_text => lv_error_text,
44194 p_token1 => 'COLUMN_NAME',
44195 p_token_value1 => 'FIRST_OPERATION_SEQ_CODE OR '
44196 ||'LAST_OPERATION_SEQ_CODE' );
44197 IF lv_return <> 0 THEN
44198 RAISE ex_logging_err;
44199 END IF;
44200
44201 -- Error out the records whose first_operation_seq_code or last_operation_seq_code is NULL
44202
44203 v_sql_stmt := 11;
44204 lv_sql_stmt :=
44205 'UPDATE msc_st_routings'
44206 ||' SET process_flag ='||G_ERROR_FLG||','
44207 ||' error_text = '||''''||lv_message_text||''''
44208 ||' WHERE ( NVL(first_operation_seq_code,'||NULL_VALUE||') ='||NULL_VALUE
44209 ||' OR NVL(last_operation_seq_code,'||NULL_VALUE||') ='||NULL_VALUE ||')'
44210 ||' AND sr_instance_code = :v_instance_code'
44211 ||' AND process_flag = '||G_IN_PROCESS
44212 ||' AND cfm_routing_flag = 3'
44213 ||' AND batch_id = :lv_batch_id';
44214
44215
44216 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
44217
44218 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
44219
44220
44221 -- For Network routings populate the FIRST_OP_SEQ_NUM and LAST_OP_SEQ_NUM
44222 v_sql_stmt := 13;
44223 lv_sql_stmt :=
44224 'UPDATE msc_st_routings'
44225 ||' SET first_op_seq_num = to_number(decode(length(rtrim(first_operation_seq_code,''0123456789'')),'
44226 ||' NULL,first_operation_seq_code,''1'')),'
44227 ||' last_op_seq_num = to_number(decode(length(rtrim(last_operation_seq_code,''0123456789'')),'
44228 ||' NULL,last_operation_seq_code,''1''))'
44229 ||' WHERE sr_instance_code = :v_instance_code'
44230 ||' AND process_flag = '||G_IN_PROCESS
44231 ||' AND cfm_routing_flag = 3'
44232 ||' AND batch_id = :lv_batch_id';
44233
44234
44235 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
44236
44237 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
44238
44239 --Call to customised validation.
44240
44241 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
44242 (ERRBUF => lv_error_text,
44243 RETCODE => lv_return,
44244 pBatchID => lv_batch_id,
44245 pInstanceCode => v_instance_code,
44246 pEntityName => 'MSC_ST_ROUTINGS',
44247 pInstanceID => v_instance_id);
44248
44249 IF NVL(lv_return,0) <> 0 THEN
44250 RAISE ex_logging_err;
44251 END IF;
44252
44253 -- Now generate routing sequence id
44254
44255 v_sql_stmt := 15;
44256
44257 OPEN c3(lv_batch_id);
44258 FETCH c3 BULK COLLECT INTO lb_rowid ;
44259
44260 IF c3%ROWCOUNT > 0 THEN
44261
44262 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
44263
44264 UPDATE msc_st_routings
44265 SET routing_sequence_id = msc_st_routing_sequence_id_s.NEXTVAL
44266 WHERE rowid = lb_rowid(j);
44267
44268
44269 v_sql_stmt := 16;
44270 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
44271
44272 -- Insert into the LID table with the user defined key
44273
44274 INSERT INTO msc_local_id_setup
44275 (local_id,
44276 st_transaction_id,
44277 instance_id,
44278 entity_name,
44279 data_source_type,
44280 char1,
44281 char2,
44282 char3,
44283 char4,
44284 char5,
44285 char6,
44286 number1,
44287 SOURCE_ORGANIZATION_ID,
44288 SOURCE_ASSEMBLY_ITEM_ID ,
44289 SOURCE_ROUTING_SEQUENCE_ID ,
44290 SOURCE_TASK_ID ,
44291 SOURCE_PROJECT_ID ,
44292 SOURCE_BILL_SEQUENCE_ID ,
44293 SOURCE_COMMON_ROUTING_SEQ_ID ,
44294 SOURCE_LINE_ID ,
44295 last_update_date,
44296 last_updated_by,
44297 creation_date,
44298 created_by )
44299 SELECT
44300 routing_sequence_id,
44301 st_transaction_id,
44302 v_instance_id,
44303 'ROUTING_SEQUENCE_ID',
44304 data_source_type,
44305 v_instance_code,
44306 company_name,
44307 organization_code,
44308 routing_name,
44309 assembly_name,
44310 alternate_routing_designator,
44311 bill_sequence_id,
44312 SOURCE_ORGANIZATION_ID,
44313 SOURCE_ASSEMBLY_ITEM_ID ,
44314 SOURCE_ROUTING_SEQUENCE_ID ,
44315 SOURCE_TASK_ID ,
44316 SOURCE_PROJECT_ID ,
44317 SOURCE_BILL_SEQUENCE_ID ,
44318 SOURCE_COMMON_ROUTING_SEQ_ID ,
44319 SOURCE_LINE_ID ,
44320 v_current_date,
44321 v_current_user,
44322 v_current_date,
44323 v_current_user
44324 FROM msc_st_routings
44325 WHERE rowid = lb_rowid(j);
44326
44327 END IF;
44328 CLOSE c3;
44329
44330 -- set the message
44331
44332 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
44333 (p_app_short_name => 'MSC',
44334 p_error_code => 'MSC_PP_INVALID_VALUE',
44335 p_message_text => lv_message_text,
44336 p_error_text => lv_error_text,
44337 p_token1 => 'COLUMN_NAME',
44338 p_token_value1 => 'COMMON_ROUTING_NAME');
44339
44340 IF lv_return <> 0 THEN
44341 RAISE ex_logging_err;
44342 END IF;
44343
44344 -- Derive the COMMON_ROUTING_SEQUENCE_ID from LOCAL ID table
44345
44346 lv_where_str :=
44347 ' AND NVL(routing_name, '||''''||NULL_CHAR||''''||') <> '
44348 ||' NVL(common_routing_name, '||''''||NULL_CHAR||''''||')'
44349 ||' AND NVL(common_routing_name, '||''''||NULL_CHAR||''''||')'
44350 ||' <> '||''''||NULL_CHAR||'''' ;
44351
44352
44353
44354 lv_return := msc_st_util.derive_routing_sequence_id
44355 (p_table_name => 'MSC_ST_ROUTINGS',
44356 p_rtg_col_name => 'COMMON_ROUTING_NAME',
44357 p_rtg_col_id => 'COMMON_ROUTING_SEQUENCE_ID',
44358 p_instance_code => v_instance_code,
44359 p_batch_id => lv_batch_id,
44360 p_debug => v_debug,
44361 p_error_text => lv_error_text,
44362 p_where_str => lv_where_str);
44363
44364 if (lv_return <> 0 )then
44365 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,lv_error_text);
44366 end if;
44367
44368
44369 lv_sql_stmt :=
44370 'UPDATE msc_st_routings'
44371 ||' SET process_flag ='||G_ERROR_FLG||','
44372 ||' error_text = '||''''||lv_message_text||''''
44373 ||' WHERE NVL(COMMON_ROUTING_SEQUENCE_ID,'||NULL_VALUE||') ='||NULL_VALUE
44374 ||' AND NVL(routing_name, '||''''||NULL_CHAR||''''||') <> '
44375 ||' NVL(common_routing_name, '||''''||NULL_CHAR||''''||')'
44376 ||' AND NVL(common_routing_name, '||''''||NULL_CHAR||''''||')'
44377 ||' <> '||''''||NULL_CHAR||''''
44378 ||' AND sr_instance_code = :v_instance_code'
44379 ||' AND process_flag = '||G_IN_PROCESS
44380 ||' AND batch_id = :lv_batch_id';
44381
44382
44383 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
44384
44385 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
44386
44387
44388 -- Set the process flag as Valid and poulate instance_id
44389 lv_return :=
44390 MSC_ST_UTIL.SET_PROCESS_FLAG(p_table_name => 'MSC_ST_ROUTINGS',
44391 p_instance_id => v_instance_id,
44392 p_instance_code => v_instance_code,
44393 p_process_flag => G_VALID,
44394 p_error_text => lv_error_text,
44395 p_debug => v_debug,
44396 p_batch_id => lv_batch_id);
44397
44398 IF lv_return <> 0 THEN
44399 RAISE ex_logging_err;
44400 END IF;
44401
44402 -- At the end calling the LOG_ERROR for logging all errored out records
44403
44404 lv_return :=
44405 MSC_ST_UTIL.LOG_ERROR(p_table_name => 'MSC_ST_ROUTINGS',
44406 p_instance_code => v_instance_code,
44407 p_row => lv_column_names,
44408 p_severity => G_SEV_ERROR,
44409 p_message_text => NULL,
44410 p_error_text => lv_error_text,
44411 p_debug => v_debug,
44412 p_batch_id => lv_batch_id );
44413
44414 IF(lv_return <> 0) then
44415 RAISE ex_logging_err;
44416 END IF;
44417
44418 COMMIT;
44419 END LOOP;
44420
44421
44422
44423 -- Validation for MSC_ST_ROUTING_OPERATIONS
44424
44425
44426 --Duplicate records check for the records whose source is XML
44427
44428 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
44429 (p_app_short_name => 'MSC',
44430 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
44431 p_message_text => lv_message_text,
44432 p_error_text => lv_error_text);
44433
44434 IF lv_return <> 0 THEN
44435 RAISE ex_logging_err;
44436 END IF;
44437
44438 v_sql_stmt := 18;
44439
44440 lv_sql_stmt :=
44441 'UPDATE msc_st_routing_operations msro1 '
44442 ||' SET process_flag = '||G_ERROR_FLG||','
44443 ||' error_text = '||''''||lv_message_text||''''
44444 ||' WHERE message_id < ( SELECT max(message_id) '
44445 ||' FROM msc_st_routing_operations msro2'
44446 ||' WHERE msro2.sr_instance_code = msro1.sr_instance_code'
44447 ||' AND msro2.organization_code = msro1.organization_code'
44448 ||' AND msro2.effectivity_date = msro1.effectivity_date'
44449 ||' AND NVL(msro2.routing_name,'||''''||NULL_CHAR||''''||') '
44450 ||' = NVL(msro1.routing_name, '||''''||NULL_CHAR||''''||') '
44451 ||' AND msro2.assembly_name = msro1.assembly_name'
44452 ||' AND NVL(msro2.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
44453 ||' = NVL(msro1.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
44454 ||' AND NVL(msro2.operation_seq_code,'||''''||NULL_CHAR||''''||') '
44455 ||' = NVL(msro1.operation_seq_code,'||''''||NULL_CHAR||''''||') '
44456 ||' AND msro2.process_flag ='||G_IN_PROCESS
44457 ||' AND NVL(msro2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||')'
44458 ||' AND msro1.process_flag = '||G_IN_PROCESS
44459 ||' AND msro1.sr_instance_code = :v_instance_code'
44460 ||' AND NVL(msro1.message_id,'||NULL_VALUE||')<> '||NULL_VALUE;
44461
44462
44463 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
44464
44465 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
44466
44467
44468 --Duplicate records check for the records whose source is batch load
44469
44470 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
44471 (p_app_short_name => 'MSC',
44472 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
44473 p_message_text => lv_message_text,
44474 p_error_text => lv_error_text);
44475
44476 IF lv_return <> 0 THEN
44477 RAISE ex_logging_err;
44478 END IF;
44479
44480 v_sql_stmt := 19;
44481 lv_sql_stmt :=
44482 'UPDATE msc_st_routing_operations msro1'
44483 ||' SET process_flag = '||G_ERROR_FLG||','
44484 ||' error_text = '||''''||lv_message_text||''''
44485 ||' WHERE EXISTS ( SELECT 1 '
44486 ||' FROM msc_st_routing_operations msro2'
44487 ||' WHERE msro2.sr_instance_code = msro1.sr_instance_code'
44488 ||' AND msro2.organization_code = msro1.organization_code'
44489 ||' AND msro2.effectivity_date = msro1.effectivity_date'
44490 ||' AND NVL(msro2.routing_name,'||''''||NULL_CHAR||''''||') '
44491 ||' = NVL(msro1.routing_name, '||''''||NULL_CHAR||''''||') '
44492 ||' AND msro2.assembly_name = msro1.assembly_name'
44493 ||' AND NVL(msro2.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
44494 ||' = NVL(msro1.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
44495 ||' AND NVL(msro2.operation_seq_code,'||''''||NULL_CHAR||''''||') '
44496 ||' = NVL(msro1.operation_seq_code,'||''''||NULL_CHAR||''''||') '
44497 ||' AND msro2.process_flag ='||G_IN_PROCESS
44498 ||' AND NVL(msro2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
44499 ||' GROUP BY sr_instance_code,company_name,organization_code,routing_name,'
44500 ||' assembly_name, alternate_routing_designator,operation_seq_code,effectivity_date'
44501 ||' HAVING COUNT(*) >1 )'
44502 ||' AND msro1.process_flag = '||G_IN_PROCESS
44503 ||' AND msro1.sr_instance_code = :v_instance_code'
44504 ||' AND NVL(msro1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
44505
44506
44507 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
44508
44509 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
44510
44511
44512 lv_column_names :=
44513 'ROUTING_NAME ||''~''||'
44514 ||' ASSEMBLY_NAME ||''~''||'
44515 ||' ALTERNATE_ROUTING_DESIGNATOR ||''~''||'
44516 ||' OPERATION_SEQ_CODE ||''~''||'
44517 ||' EFFECTIVITY_DATE ||''~''||'
44518 ||' OPTION_DEPENDENT_FLAG ||''~''||'
44519 ||' DEPARTMENT_CODE ||''~''||'
44520 ||' ORGANIZATION_CODE ||''~''||'
44521 ||' SR_INSTANCE_CODE ||''~''||'
44522 ||' OPERATION_DESCRIPTION ||''~''||'
44523 ||' DISABLE_DATE ||''~''||'
44524 ||' FROM_UNIT_NUMBER ||''~''||'
44525 ||' TO_UNIT_NUMBER ||''~''||'
44526 ||' OPERATION_TYPE ||''~''||'
44527 ||' MINIMUM_TRANSFER_QUANTITY ||''~''||'
44528 ||' YIELD ||''~''||'
44529 ||' OPERATION_LEAD_TIME_PERCENT ||''~''||'
44530 ||' CUMULATIVE_YIELD ||''~''||'
44531 ||' REVERSE_CUMULATIVE_YIELD ||''~''||'
44532 ||' NET_PLANNING_PERCENT ||''~''||'
44533 ||' SETUP_DURATION ||''~''||'
44534 ||' TEAR_DOWN_DURATION ||''~''||'
44535 ||' UOM_CODE ||''~''||'
44536 ||' STANDARD_OPERATION_CODE ||''~''||'
44537 ||' DELETED_FLAG ||''~''||'
44538 ||' COMPANY_NAME ';
44539
44540
44541
44542 LOOP
44543
44544 v_sql_stmt := 20;
44545 lv_cursor_stmt :=
44546 ' SELECT msc_st_batch_id_s.NEXTVAL '
44547 ||' FROM dual';
44548
44549 OPEN c1 FOR lv_cursor_stmt;
44550 FETCH c1 INTO lv_batch_id;
44551 CLOSE c1;
44552
44553
44554 SELECT msc_st_batch_id_s.NEXTVAL
44555 INTO lv_batch_id
44556 FROM dual;
44557
44558 v_sql_stmt := 21;
44559 lv_sql_stmt :=
44560 ' UPDATE msc_st_routing_operations '
44561 ||' SET batch_id = :lv_batch_id'
44562 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
44563 ||' AND sr_instance_code = :v_instance_code'
44564 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
44565 ||' AND rownum <= '||v_batch_size;
44566
44567
44568 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
44569
44570 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
44571
44572 EXIT WHEN SQL%NOTFOUND;
44573
44574
44575 OPEN c4(lv_batch_id);
44576 FETCH c4 BULK COLLECT INTO lb_rowid;
44577 CLOSE c4;
44578
44579 v_sql_stmt := 22;
44580 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
44581 UPDATE msc_st_routing_operations
44582 SET st_transaction_id = msc_st_routing_operations_s.NEXTVAL,
44583 refresh_id = v_refresh_id,
44584 last_update_date = v_current_date,
44585 last_updated_by = v_current_user,
44586 creation_date = v_current_date,
44587 created_by = v_current_user
44588 WHERE rowid = lb_rowid(j);
44589
44590 -- Set the error message
44591 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
44592 (p_app_short_name => 'MSC',
44593 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
44594 p_message_text => lv_message_text,
44595 p_error_text => lv_error_text,
44596 p_token1 => 'COLUMN_NAME',
44597 p_token_value1 => 'DELETED_FLAG',
44598 p_token2 => 'DEFAULT_VALUE',
44599 p_token_value2 => SYS_NO );
44600
44601 IF lv_return <> 0 THEN
44602 RAISE ex_logging_err;
44603 END IF;
44604
44605
44606 -- Check whether delete flag value is in (1,2),if not default to SYS_NO
44607
44608 lv_where_str :=
44609 ' AND NVL(deleted_flag,'||NULL_VALUE||') <>'||SYS_NO;
44610
44611 lv_return := MSC_ST_UTIL.LOG_ERROR
44612 (p_table_name => 'MSC_ST_ROUTING_OPERATIONS',
44613 p_instance_code => v_instance_code,
44614 p_row => lv_column_names,
44615 p_severity => G_SEV_WARNING,
44616 p_message_text => lv_message_text,
44617 p_error_text => lv_error_text,
44618 p_batch_id => lv_batch_id,
44619 p_where_str => lv_where_str,
44620 p_col_name => 'DELETED_FLAG',
44621 p_debug => v_debug,
44622 p_default_value => SYS_NO);
44623
44624 IF lv_return <> 0 THEN
44625 RAISE ex_logging_err;
44626 END IF;
44627
44628 -- Set the message
44629
44630 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
44631 (p_app_short_name => 'MSC',
44632 p_error_code => 'MSC_PP_INVALID_VALUE',
44633 p_message_text => lv_message_text,
44634 p_error_text => lv_error_text,
44635 p_token1 => 'COLUMN_NAME',
44636 p_token_value1 => 'ORGANIZATION_CODE');
44637
44638 IF lv_return <> 0 THEN
44639 RAISE ex_logging_err;
44640 END IF;
44641
44642 -- derive organization id ,
44643 lv_return :=
44644 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name => 'MSC_ST_ROUTING_OPERATIONS',
44645 p_org_partner_name =>'ORGANIZATION_CODE',
44646 p_org_partner_id =>'ORGANIZATION_ID',
44647 p_instance_code => v_instance_code,
44648 p_partner_type => G_ORGANIZATION,
44649 p_severity => G_SEV_ERROR,
44650 p_message_text => lv_message_text,
44651 p_batch_id =>lv_batch_id,
44652 p_debug => v_debug,
44653 p_error_text =>lv_error_text);
44654
44655 if(lv_return <> 0) then
44656 RAISE ex_logging_err;
44657 end if;
44658
44659 -- Now we will check whether Routing Name is NULL , if it is NULL we will populate the
44660 -- ASSEMBLY NAME in ROUTING_NAME column for all such records
44661 v_sql_stmt := 23;
44662
44663 lv_sql_stmt :=
44664 'UPDATE msc_st_routing_operations '
44665 ||' SET routing_name = assembly_name'
44666 ||' WHERE sr_instance_code = :v_instance_code'
44667 ||' AND process_flag = '||G_IN_PROCESS
44668 ||' AND NVL(routing_name,'||''''||NULL_CHAR||''''||') '
44669 ||' = '||''''||NULL_CHAR||''''
44670 ||' AND batch_id = :lv_batch_id';
44671
44672
44673 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
44674
44675 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
44676
44677 -- Set the error message
44678 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
44679 (p_app_short_name => 'MSC',
44680 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
44681 p_message_text => lv_message_text,
44682 p_error_text => lv_error_text,
44683 p_token1 => 'COLUMN_NAMES',
44684 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
44685 ||'ORGANIZATION_CODE,ROUTING_NAME',
44686 p_token2 => 'MASTER_TABLE',
44687 p_token_value2 => 'MSC_ST_ROUTINGS',
44688 p_token3 => 'CHILD_TABLE' ,
44689 p_token_value3 => 'MSC_ST_ROUTING_OPERATIONS' );
44690
44691 IF lv_return <> 0 THEN
44692 RAISE ex_logging_err;
44693 END IF;
44694
44695 -- Derive the ROUTING_SEQUENCE_ID from LOCAL ID table
44696
44697 lv_return :=
44698 MSC_ST_UTIL.DERIVE_ROUTING_SEQUENCE_ID
44699 (p_table_name => 'MSC_ST_ROUTING_OPERATIONS',
44700 p_rtg_col_name => 'ROUTING_NAME',
44701 p_rtg_col_id => 'ROUTING_SEQUENCE_ID',
44702 p_instance_code => v_instance_code,
44703 p_severity => G_SEV_ERROR,
44704 p_message_text => lv_message_text,
44705 p_batch_id => lv_batch_id,
44706 p_debug => v_debug,
44707 p_error_text => lv_error_text);
44708
44709 if (lv_return <> 0 )then
44710 RAISE ex_logging_err;
44711 end if;
44712
44713 -- Set the error message
44714 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
44715 (p_app_short_name => 'MSC',
44716 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
44717 p_message_text => lv_message_text,
44718 p_error_text => lv_error_text,
44719 p_token1 => 'COLUMN_NAME',
44720 p_token_value1 => 'EFFECTIVITY_DATE',
44721 p_token2 => 'DEFAULT_VALUE',
44722 p_token_value2 => 'SYSDATE' );
44723
44724 IF lv_return <> 0 THEN
44725 RAISE ex_logging_err;
44726 END IF;
44727
44728 -- Default effectivity date as SYSDATE if NULL
44729
44730 lv_where_str :=
44731 ' AND NVL(effectivity_date,SYSDATE-36500 ) = SYSDATE-36500 ' ;
44732
44733 lv_return := MSC_ST_UTIL.LOG_ERROR
44734 (p_table_name => 'MSC_ST_ROUTING_OPERATIONS',
44735 p_instance_code => v_instance_code,
44736 p_row => lv_column_names,
44737 p_severity => G_SEV_WARNING,
44738 p_message_text => lv_message_text,
44739 p_error_text => lv_error_text,
44740 p_batch_id => lv_batch_id,
44741 p_where_str => lv_where_str,
44742 p_col_name => 'EFFECTIVITY_DATE',
44743 p_debug => v_debug,
44744 p_default_value => 'SYSDATE');
44745
44746 IF lv_return <> 0 THEN
44747 RAISE ex_logging_err;
44748 END IF;
44749
44750 -- Set the error message
44751 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
44752 (p_app_short_name => 'MSC',
44753 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
44754 p_message_text => lv_message_text,
44755 p_error_text => lv_error_text,
44756 p_token1 => 'COLUMN_NAME',
44757 p_token_value1 => 'OPERATION_SEQ_CODE',
44758 p_token2 => 'DEFAULT_VALUE',
44759 p_token_value2 => G_OPERATION_SEQ_CODE );
44760
44761 IF lv_return <> 0 THEN
44762 RAISE ex_logging_err;
44763 END IF;
44764
44765 -- Default operation_seq_code as 1 if NULL
44766 lv_where_str :=
44767 ' AND NVL(operation_seq_code,'||''''||NULL_CHAR||''''||') '
44768 ||' = '||''''||NULL_CHAR||'''' ;
44769
44770 lv_return := MSC_ST_UTIL.LOG_ERROR
44771 (p_table_name => 'MSC_ST_ROUTING_OPERATIONS',
44772 p_instance_code => v_instance_code,
44773 p_row => lv_column_names,
44774 p_severity => G_SEV_WARNING,
44775 p_message_text => lv_message_text,
44776 p_error_text => lv_error_text,
44777 p_batch_id => lv_batch_id,
44778 p_where_str => lv_where_str,
44779 p_col_name => 'OPERATION_SEQ_CODE',
44780 p_debug => v_debug,
44781 p_default_value => G_OPERATION_SEQ_CODE);
44782
44783 IF lv_return <> 0 THEN
44784 RAISE ex_logging_err;
44785 END IF;
44786
44787 -- Derive operation_sequence id, operation_seq_num
44788
44789 v_sql_stmt := 24;
44790 lv_sql_Stmt :=
44791 'UPDATE msc_st_routing_operations msro'
44792 ||' SET (operation_sequence_id,operation_seq_num)= (SELECT local_id,number1'
44793 ||' FROM msc_local_id_setup mlis'
44794 ||' WHERE mlis.char1 = msro.sr_instance_code'
44795 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
44796 ||' = NVL(msro.company_name,'||''''||NULL_CHAR||''''||') '
44797 ||' AND mlis.char3 = msro.organization_code'
44798 ||' AND mlis.char4 = msro.routing_name'
44799 ||' AND mlis.char5 = msro.operation_seq_code'
44800 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
44801 ||' = NVL(msro.alternate_routing_designator,'||''''||NULL_CHAR||''''||')'
44802 ||' AND mlis.date1 = msro.effectivity_date'
44803 ||' AND mlis.entity_name = ''OPERATION_SEQUENCE_ID'' '
44804 ||' AND mlis.instance_id = '||v_instance_id||')'
44805 ||' WHERE sr_instance_code = :v_instance_code'
44806 ||' AND process_flag ='||G_IN_PROCESS
44807 ||' AND batch_id = :lv_batch_id';
44808
44809
44810 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
44811
44812 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
44813
44814 -- derive the operation_seq_num column from LID
44815 -- where operation_sequence_id exist
44816 /*
44817 v_sql_stmt := 25;
44818
44819 lv_sql_stmt :=
44820 'UPDATE msc_st_routing_operations msro'
44821 ||' SET operation_seq_num = ( SELECT number1'
44822 ||' FROM msc_local_id_setup mlis'
44823 ||' WHERE local_id = msro.operation_sequence_id'
44824 ||' AND mlis.entity_name = ''OPERATION_SEQUENCE_ID'' '
44825 ||' AND mlis.instance_id = '||v_instance_id||')'
44826 ||' WHERE sr_instance_code = :v_instance_code'
44827 ||' AND NVL(operation_sequence_id,'||NULL_VALUE||') <>'||NULL_VALUE
44828 ||' AND process_flag = '||G_IN_PROCESS
44829 ||' AND batch_id = :lv_batch_id';
44830
44831
44832 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
44833
44834 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
44835 */
44836 -- Set the error message
44837 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
44838 (p_app_short_name => 'MSC',
44839 p_error_code => 'MSC_PP_DELETE_FAIL',
44840 p_message_text => lv_message_text,
44841 p_error_text => lv_error_text );
44842
44843 IF lv_return <> 0 THEN
44844 RAISE ex_logging_err;
44845 END IF;
44846
44847 -- Error out if DELETED_FLAG = SYS_YES but operation_sequence_id is NULL
44848
44849 v_sql_stmt := 26;
44850 lv_sql_stmt :=
44851 'UPDATE msc_st_routing_operations'
44852 ||' SET process_flag ='||G_ERROR_FLG||','
44853 ||' error_text = '||''''||lv_message_text||''''
44854 ||' WHERE NVL(operation_sequence_id,'||NULL_VALUE||') ='||NULL_VALUE
44855 ||' AND deleted_flag ='||SYS_YES
44856 ||' AND sr_instance_code = :v_instance_code'
44857 ||' AND process_flag = '||G_IN_PROCESS
44858 ||' AND batch_id = :lv_batch_id';
44859
44860
44861 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
44862
44863 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
44864
44865 -- Set the error message
44866
44867 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
44868 (p_app_short_name => 'MSC',
44869 p_error_code => 'MSC_PP_COL_VAL_NULL',
44870 p_message_text => lv_message_text,
44871 p_error_text => lv_error_text,
44872 p_token1 => 'COLUMN_NAME',
44873 p_token_value1 => 'DEPARTMENT_CODE');
44874
44875 IF lv_return <> 0 THEN
44876 RAISE ex_logging_err;
44877 END IF;
44878
44879 -- Error out record if department_code is null/resource_code is NULL and line_flag=2
44880
44881 v_sql_stmt := 26.1;
44882 lv_sql_stmt :=
44883 ' UPDATE msc_st_routing_operations '
44884 ||' SET process_flag = '||G_ERROR_FLG||','
44885 ||' error_text = '||''''||lv_message_text||''''
44886 ||' WHERE NVL(department_code,'||''''||NULL_CHAR||''''||')'
44887 ||' = '||''''||NULL_CHAR||''''
44888 ||' AND batch_id = :lv_batch_id'
44889 ||' AND process_flag = '||G_IN_PROCESS
44890 ||' AND sr_instance_code = :v_instance_code';
44891
44892
44893 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
44894 EXECUTE IMMEDIATE lv_sql_stmt
44895 USING lv_batch_id,
44896 v_instance_code;
44897
44898 -- Derive department id
44899 v_sql_stmt := 27;
44900 lv_sql_stmt :=
44901 'UPDATE msc_st_routing_operations msro'
44902 ||' SET department_id= (SELECT local_id'
44903 ||' FROM msc_local_id_setup mlis'
44904 ||' WHERE mlis.char1 = msro.sr_instance_code'
44905 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
44906 ||' = NVL(msro.company_name,'||''''||NULL_CHAR||''''||') '
44907 ||' AND mlis.char3 = msro.organization_code'
44908 ||' AND mlis.char4 = msro.department_code'
44909 ||' AND mlis.entity_name = ''DEPARTMENT_ID'')'
44910 ||' WHERE sr_instance_code = :v_instance_code'
44911 ||' AND deleted_flag = '||SYS_NO
44912 ||' AND process_flag = '||G_IN_PROCESS
44913 ||' AND batch_id = :lv_batch_id';
44914
44915
44916 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
44917
44918 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
44919
44920
44921
44922 -- Now generate the department_id
44923
44924 v_sql_stmt := 27.1;
44925
44926 OPEN c10(lv_batch_id);
44927 FETCH c10 BULK COLLECT INTO lb_rowid ;
44928
44929 IF c10%ROWCOUNT > 0 THEN
44930
44931 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
44932
44933 UPDATE msc_st_routing_operations
44934 SET department_id = msc_st_department_id_s.NEXTVAL
44935 WHERE rowid = lb_rowid(j);
44936
44937
44938 v_sql_stmt := 14;
44939
44940 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
44941
44942 -- Insert into the LID table this new department with the user defined key
44943
44944 INSERT INTO msc_local_id_setup
44945 (local_id,
44946 st_transaction_id,
44947 instance_id,
44948 entity_name,
44949 data_source_type,
44950 char1,
44951 char2,
44952 char3,
44953 char4,
44954 SOURCE_ORGANIZATION_ID,
44955 SOURCE_DEPARTMENT_ID,
44956 last_update_date,
44957 last_updated_by,
44958 creation_date,
44959 created_by )
44960 SELECT
44961 department_id,
44962 st_transaction_id,
44963 v_instance_id,
44964 'DEPARTMENT_ID',
44965 data_source_type,
44966 sr_instance_code,
44967 company_name,
44968 organization_code,
44969 department_code,
44970 SOURCE_ORGANIZATION_ID,
44971 SOURCE_DEPARTMENT_ID,
44972 v_current_date,
44973 v_current_user,
44974 v_current_date,
44975 v_current_user
44976 FROM msc_st_routing_operations
44977 WHERE rowid = lb_rowid(j);
44978
44979 END IF;
44980 CLOSE c10;
44981
44982 -- Now derive department id
44983 v_sql_stmt:= 15;
44984
44985 lv_sql_stmt :=
44986 'UPDATE msc_st_routing_operations msdr'
44987 ||' SET department_id= (SELECT local_id'
44988 ||' FROM msc_local_id_setup mlis'
44989 ||' WHERE mlis.char1 = msdr.sr_instance_code'
44990 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
44991 ||' = NVL(msdr.company_name,'||''''||NULL_CHAR||''''||') '
44992 ||' AND mlis.char3 = msdr.organization_code'
44993 ||' AND mlis.char4 = msdr.department_code'
44994 ||' AND mlis.entity_name = ''DEPARTMENT_ID'')'
44995 ||' WHERE msdr.sr_instance_code = :v_instance_code'
44996 ||' AND NVL(msdr.department_id,'||NULL_VALUE||') ='|| NULL_VALUE
44997 ||' AND msdr.process_flag ='|| G_IN_PROCESS
44998 ||' AND msdr.batch_id = :lv_batch_id';
44999
45000
45001 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
45002
45003 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
45004
45005
45006 /* Bug 3549086 -- we shouldn't be erroing out if department doen't exists.
45007 ERP allows such records. Hence we would genearet department it.
45008 -- Set the error message
45009 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
45010 (p_app_short_name => 'MSC',
45011 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
45012 p_message_text => lv_message_text,
45013 p_error_text => lv_error_text,
45014 p_token1 => 'COLUMN_NAMES',
45015 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
45016 ||'ORGANIZATION_CODE,DEPARTMENT_CODE',
45017 p_token2 => 'MASTER_TABLE',
45018 p_token_value2 => 'MSC_ST_DEPARTMENT_RESOURCES',
45019 p_token3 => 'CHILD_TABLE' ,
45020 p_token_value3 => 'MSC_ST_ROUTING_OPERATIONS' );
45021
45022 IF lv_return <> 0 THEN
45023 RAISE ex_logging_err;
45024 END IF;
45025
45026 -- Log an error if unable to derive department id
45027
45028 v_sql_stmt := 28;
45029 lv_sql_stmt :=
45030 'UPDATE msc_st_routing_operations '
45031 ||' SET process_flag ='||G_ERROR_FLG||','
45032 ||' error_text = '||''''||lv_message_text||''''
45033 ||' WHERE NVL(department_id,'||NULL_VALUE||') ='||NULL_VALUE
45034 ||' AND sr_instance_code = :v_instance_code'
45035 ||' AND deleted_flag ='||SYS_NO
45036 ||' AND process_flag ='|| G_IN_PROCESS
45037 ||' AND batch_id = :lv_batch_id' ;
45038
45039
45040 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
45041
45042 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
45043 */
45044
45045 -- Set the error message
45046 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
45047 (p_app_short_name => 'MSC',
45048 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
45049 p_message_text => lv_message_text,
45050 p_error_text => lv_error_text,
45051 p_token1 => 'COLUMN_NAME',
45052 p_token_value1 => 'OPTION_DEPENDENT_FLAG',
45053 p_token2 => 'DEFAULT_VALUE',
45054 p_token_value2 => G_OPTION_DEPENDENT_FLAG );
45055
45056 IF lv_return <> 0 THEN
45057 RAISE ex_logging_err;
45058 END IF;
45059
45060 -- Default option_dependent_flag
45061
45062 lv_where_str := ' AND NVL(option_dependent_flag,'||NULL_VALUE||')'
45063 ||' NOT IN (1,2) AND deleted_flag = '||SYS_NO ;
45064
45065 lv_return := MSC_ST_UTIL.LOG_ERROR
45066 (p_table_name => 'MSC_ST_ROUTING_OPERATIONS',
45067 p_instance_code => v_instance_code,
45068 p_row => lv_column_names,
45069 p_severity => G_SEV_WARNING,
45070 p_message_text => lv_message_text,
45071 p_error_text => lv_error_text,
45072 p_batch_id => lv_batch_id,
45073 p_where_str => lv_where_str,
45074 p_col_name => 'OPTION_DEPENDENT_FLAG',
45075 p_debug => v_debug,
45076 p_default_value => G_OPTION_DEPENDENT_FLAG);
45077
45078 IF lv_return <> 0 THEN
45079 RAISE ex_logging_err ;
45080 END IF;
45081
45082 --Call to customised validation.
45083
45084 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
45085 (ERRBUF => lv_error_text,
45086 RETCODE => lv_return,
45087 pBatchID => lv_batch_id,
45088 pInstanceCode => v_instance_code,
45089 pEntityName => 'MSC_ST_ROUTING_OPERATIONS',
45090 pInstanceID => v_instance_id);
45091
45092 IF NVL(lv_return,0) <> 0 THEN
45093 RAISE ex_logging_err;
45094 END IF;
45095
45096 -- Generate operation_sequence_id
45097 -- Also update operation_seq_num as operation_seq_code,
45098 -- here we assume that operation_seq_code is a number
45099 -- field,otherwise we will default it to 1
45100
45101 v_sql_stmt := 29;
45102
45103 OPEN c5(lv_batch_id);
45104 FETCH c5 BULK COLLECT INTO lb_rowid ;
45105
45106 IF c5%ROWCOUNT > 0 THEN
45107
45108 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
45109
45110 UPDATE msc_st_routing_operations
45111 SET operation_sequence_id = msc_st_operation_sequence_id_s.NEXTVAL ,
45112 operation_seq_num =
45113 to_number(decode(length(rtrim(operation_seq_code,'0123456789')),
45114 NULL,operation_seq_code,'1'))
45115 WHERE rowid = lb_rowid(j);
45116
45117 v_sql_stmt := 30;
45118
45119 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
45120 -- Insert into the LID table with the user defined key
45121
45122 INSERT INTO msc_local_id_setup
45123 (local_id,
45124 st_transaction_id,
45125 instance_id,
45126 entity_name,
45127 data_source_type,
45128 char1,
45129 char2,
45130 char3,
45131 char4,
45132 char5,
45133 char6,
45134 number1,
45135 date1,
45136 date2,
45137 SOURCE_ORGANIZATION_ID ,
45138 SOURCE_OPERATION_SEQUENCE_ID ,
45139 SOURCE_OPERATION_SEQ_NUM ,
45140 SOURCE_DEPARTMENT_ID ,
45141 last_update_date,
45142 last_updated_by,
45143 creation_date,
45144 created_by )
45145 SELECT
45146 operation_sequence_id,
45147 st_transaction_id,
45148 v_instance_id,
45149 'OPERATION_SEQUENCE_ID',
45150 data_source_type,
45151 v_instance_code,
45152 company_name,
45153 organization_code,
45154 routing_name,
45155 operation_seq_code,
45156 alternate_routing_designator,
45157 operation_seq_num,
45158 effectivity_date,
45159 disable_date,
45160 SOURCE_ORGANIZATION_ID ,
45161 SOURCE_OPERATION_SEQUENCE_ID ,
45162 SOURCE_OPERATION_SEQ_NUM ,
45163 SOURCE_DEPARTMENT_ID ,
45164 v_current_date,
45165 v_current_user,
45166 v_current_date,
45167 v_current_user
45168 FROM msc_st_routing_operations
45169 WHERE rowid = lb_rowid(j) ;
45170
45171 END IF;
45172 CLOSE c5;
45173
45174 -- Insert records in MSC_ST_OPERATION_COMPONENT
45175 v_sql_stmt := 31;
45176 lv_sql_stmt :=
45177 'INSERT INTO msc_st_operation_components '
45178 ||' (organization_id,'
45179 ||' operation_sequence_id,'
45180 ||' component_sequence_id,'
45181 ||' bill_sequence_id,'
45182 ||' routing_sequence_id,'
45183 ||' deleted_flag,'
45184 ||' sr_instance_id,'
45185 ||' last_update_date,'
45186 ||' last_updated_by, '
45187 ||' creation_date,'
45188 ||' created_by,'
45189 ||' refresh_id)'
45190 ||' SELECT'
45191 ||' msro.organization_id,'
45192 ||' msro.operation_sequence_id,'
45193 ||' msbc.component_sequence_id,'
45194 ||' msbc.bill_sequence_id,'
45195 ||' msro.routing_sequence_id,'
45196 ||' msro.deleted_flag,'
45197 || v_instance_id||','
45198 ||' msro.last_update_date,'
45199 ||' msro.last_updated_by,'
45200 ||' msro.creation_date,'
45201 ||' msro.created_by,'
45202 ||' msro.REFRESH_ID'
45203 ||' FROM msc_st_routing_operations msro,'
45204 ||' msc_st_bom_components msbc,'
45205 ||' msc_local_id_setup mlis'
45206 ||' WHERE msbc.bill_sequence_id = mlis.number1'
45207 ||' AND mlis.entity_name = ''ROUTING_SEQUENCE_ID'' '
45208 ||' AND mlis.local_id = msro.routing_sequence_id'
45209 ||' AND msbc.process_flag = '||G_VALID
45210 ||' AND mlis.instance_id = :v_instance_id'
45211 ||' AND msro.sr_instance_code = :v_instance_code'
45212 ||' AND msro.operation_seq_code = msbc.operation_seq_code'
45213 ||' AND msro.process_flag ='||G_IN_PROCESS
45214 ||' AND msro.batch_id = :lv_batch_id'
45215 ||' UNION'
45216 ||' SELECT'
45217 ||' msro.organization_id,'
45218 ||' msro.operation_sequence_id,'
45219 ||' mbc.component_sequence_id,'
45220 ||' mbc.bill_sequence_id,'
45221 ||' msro.routing_sequence_id,'
45222 ||' msro.deleted_flag,'
45223 || v_instance_id||','
45224 ||' msro.last_update_date,'
45225 ||' msro.last_updated_by,'
45226 ||' msro.creation_date,'
45227 ||' msro.created_by,'
45228 ||' msro.REFRESH_ID'
45229 ||' FROM msc_st_routing_operations msro,'
45230 ||' msc_bom_components mbc,'
45231 ||' msc_local_id_setup mlis,'
45232 ||' msc_local_id_setup mlis1'
45233 ||' WHERE mbc.component_sequence_id = mlis1.local_id '
45234 ||' AND mbc.bill_sequence_id = mlis.number1'
45235 ||' AND mbc.sr_instance_id = :v_instance_id'
45236 ||' AND mbc.plan_id = -1'
45237 ||' AND mlis.entity_name = ''ROUTING_SEQUENCE_ID'' '
45238 ||' AND mlis.local_id = msro.routing_sequence_id '
45239 ||' AND mlis.instance_id = :v_instance_id '
45240 ||' AND msro.sr_instance_code = :v_instance_code'
45241 ||' AND msro.organization_id = mbc.organization_id'
45242 ||' AND msro.operation_seq_code = mlis1.char7'
45243 ||' AND mlis1.instance_id = :v_instance_id'
45244 ||' AND mlis1.entity_name = ''COMPONENT_SEQUENCE_ID'' '
45245 ||' AND msro.process_flag ='||G_IN_PROCESS
45246 ||' AND msro.batch_id = :lv_batch_id';
45247
45248 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
45249
45250 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_id,v_instance_code,lv_batch_id,
45251 v_instance_id,v_instance_id,v_instance_code,v_instance_id,lv_batch_id;
45252
45253 -- Set the process flag as Valid and derive sr_instance_id
45254 lv_return :=
45255 MSC_ST_UTIL.SET_PROCESS_FLAG(p_table_name => 'MSC_ST_ROUTING_OPERATIONS',
45256 p_instance_id => v_instance_id,
45257 p_instance_code => v_instance_code,
45258 p_process_flag => G_VALID,
45259 p_error_text => lv_error_text,
45260 p_debug => v_debug,
45261 p_batch_id => lv_batch_id);
45262
45263 IF lv_return < 0 THEN
45264 RAISe ex_logging_err;
45265 END IF;
45266
45267
45268 -- At the end calling the LOG_ERROR for logging all errored out records
45269
45270 lv_return :=
45271 MSC_ST_UTIL.LOG_ERROR(p_table_name => 'MSC_ST_ROUTING_OPERATIONS',
45272 p_instance_code => v_instance_code,
45273 p_row => lv_column_names,
45274 p_severity => G_SEV_ERROR,
45275 p_message_text => NULL,
45276 p_error_text => lv_error_text,
45277 p_debug => v_debug,
45278 p_batch_id => lv_batch_id );
45279
45280 IF lv_return < 0 THEN
45281 RAISe ex_logging_err;
45282 END IF;
45283
45284 COMMIT;
45285 END LOOP;
45286
45287 -- Validation for the MSC_ST_OPERATION_RESOURCES
45288
45289 --Duplicate records check for the records whose source is XML
45290
45291 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
45292 (p_app_short_name => 'MSC',
45293 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
45294 p_message_text => lv_message_text,
45295 p_error_text => lv_error_text);
45296
45297 IF lv_return <> 0 THEN
45298 RAISE ex_logging_err;
45299 END IF;
45300
45301
45302 v_sql_stmt := 32;
45303
45304 lv_sql_stmt:=
45305 'UPDATE msc_st_operation_resources msor1 '
45306 ||' SET process_flag = '||G_ERROR_FLG||','
45307 ||' error_text = '||''''||lv_message_text||''''
45308 ||' WHERE message_id < ( SELECT max(message_id)'
45309 ||' FROM msc_st_operation_resources msor2'
45310 ||' WHERE msor2.sr_instance_code = msor1.sr_instance_code'
45311 ||' AND msor2.organization_code = msor1.organization_code'
45312 ||' AND NVL(msor2.company_name,'||''''||NULL_CHAR||''''||') '
45313 ||' = NVL(msor1.company_name,'||''''||NULL_CHAR||''''||') '
45314 ||' AND NVL(msor2.routing_name,'||''''||NULL_CHAR||''''||') '
45315 ||' = NVL(msor1.routing_name,'||''''||NULL_CHAR||''''||') '
45316 ||' AND msor2.assembly_name = msor1.assembly_name'
45317 ||' AND NVL(msor2.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
45318 ||' = NVL(msor1.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
45319 ||' AND NVL(msor2.operation_seq_code,'||''''||NULL_CHAR||''''||') '
45320 ||' = NVL(msor1.operation_seq_code,'||''''||NULL_CHAR||''''||') '
45321 ||' AND msor2.resource_code = msor1.resource_code'
45322 ||' AND NVL(msor2.resource_seq_code,'||''''||NULL_CHAR||''''||') '
45323 ||' = NVL(msor1.resource_seq_code,'||''''||NULL_CHAR||''''||') '
45324 ||' AND NVL(msor2.alternate_number,'||NULL_VALUE||')'
45325 ||' = NVL(msor1.alternate_number,'||NULL_VALUE||')'
45326 ||' AND msor2.process_flag ='||G_IN_PROCESS
45327 ||' AND NVL(msor2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||')'
45328 ||' AND msor1.process_flag = '||G_IN_PROCESS
45329 ||' AND msor1.sr_instance_code = :v_instance_code'
45330 ||' AND NVL(msor1.message_id,'||NULL_VALUE||')<> '||NULL_VALUE ;
45331
45332
45333 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
45334
45335 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
45336
45337
45338 --Duplicate records check for the records whose source is batch load
45339
45340 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
45341 (p_app_short_name => 'MSC',
45342 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
45343 p_message_text => lv_message_text,
45344 p_error_text => lv_error_text);
45345
45346 IF lv_return <> 0 THEN
45347 RAISE ex_logging_err;
45348 END IF;
45349
45350 v_sql_stmt := 33;
45351 lv_sql_stmt :=
45352 'UPDATE msc_st_operation_resources msor1'
45353 ||' SET process_flag = '||G_ERROR_FLG||','
45354 ||' error_text = '||''''||lv_message_text||''''
45355 ||' WHERE EXISTS ( SELECT 1 '
45356 ||' FROM msc_st_operation_resources msor2'
45357 ||' WHERE msor2.sr_instance_code = msor1.sr_instance_code'
45358 ||' AND msor2.organization_code = msor1.organization_code'
45359 ||' AND NVL(msor2.company_name,'||''''||NULL_CHAR||''''||') '
45360 ||' = NVL(msor1.company_name,'||''''||NULL_CHAR||''''||') '
45361 ||' AND NVL(msor2.routing_name,'||''''||NULL_CHAR||''''||') '
45362 ||' = NVL(msor1.routing_name,'||''''||NULL_CHAR||''''||') '
45363 ||' AND msor2.assembly_name = msor1.assembly_name'
45364 ||' AND NVL(msor2.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
45365 ||' = NVL(msor1.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
45366 ||' AND NVL(msor2.operation_seq_code,'||''''||NULL_CHAR||''''||') '
45367 ||' = NVL(msor1.operation_seq_code,'||''''||NULL_CHAR||''''||') '
45368 ||' AND msor2.resource_code = msor1.resource_code'
45369 ||' AND NVL(msor2.resource_seq_code,'||''''||NULL_CHAR||''''||') '
45370 ||' = NVL(msor1.resource_seq_code,'||''''||NULL_CHAR||''''||') '
45371 ||' AND NVL(msor2.alternate_number,'||NULL_VALUE||')'
45372 ||' = NVL(msor1.alternate_number,'||NULL_VALUE||')'
45373 ||' AND msor2.process_flag ='||G_IN_PROCESS
45374 ||' AND NVL(msor2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
45375 ||' GROUP BY sr_instance_code,organization_code,company_name,routing_name,'
45376 ||' assembly_name, alternate_routing_designator,operation_seq_code,'
45377 ||' resource_code,resource_seq_code,alternate_number '
45378 ||' HAVING COUNT(*) >1 )'
45379 ||' AND msor1.process_flag = '||G_IN_PROCESS
45380 ||' AND msor1.sr_instance_code = :v_instance_code'
45381 ||' AND NVL(msor1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
45382
45383 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
45384
45385
45386 --Duplicate records check for the records whose source is XML
45387
45388 lv_column_names :=
45389 'ROUTING_NAME ||''~''||'
45390 ||' ASSEMBLY_NAME ||''~''||'
45391 ||' OPERATION_SEQ_CODE ||''~''||'
45392 ||' RESOURCE_SEQ_CODE ||''~''||'
45393 ||' DEPARTMENT_CODE ||''~''||'
45394 ||' RESOURCE_CODE ||''~''||'
45395 ||' ALTERNATE_NUMBER ||''~''||'
45396 ||' PRINCIPAL_FLAG ||''~''||'
45397 ||' BASIS_TYPE ||''~''||'
45398 ||' RESOURCE_USAGE ||''~''||'
45399 ||' UOM_CODE ||''~''||'
45400 ||' SETUP_CODE ||''~''||'
45401 ||' ORGANIZATION_CODE ||''~''||'
45402 ||' SR_INSTANCE_CODE ||''~''||'
45403 ||' MAX_RESOURCE_UNITS ||''~''||'
45404 ||' RESOURCE_UNITS ||''~''||'
45405 ||' DELETED_FLAG ||''~''||'
45406 ||' RESOURCE_TYPE ||''~''||'
45407 ||' COMPANY_NAME';
45408
45409 LOOP
45410 lv_cursor_stmt :=
45411 ' SELECT msc_st_batch_id_s.NEXTVAL '
45412 ||' FROM dual';
45413
45414 OPEN c1 FOR lv_cursor_stmt;
45415 FETCH c1 INTO lv_batch_id;
45416 CLOSE c1;
45417
45418 v_sql_stmt := 34;
45419 lv_sql_stmt :=
45420 ' UPDATE msc_st_operation_resources '
45421 ||' SET batch_id = :lv_batch_id'
45422 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
45423 ||' AND sr_instance_code = :v_instance_code'
45424 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
45425 ||' AND rownum <= '||v_batch_size;
45426
45427
45428 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
45429
45430 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
45431
45432 EXIT WHEN SQL%NOTFOUND;
45433
45434 OPEN c6(lv_batch_id);
45435 FETCH c6 BULK COLLECT INTO lb_rowid;
45436 CLOSE c6;
45437
45438 v_sql_stmt := 35;
45439 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
45440 UPDATE msc_st_operation_resources
45441 SET st_transaction_id = msc_st_operation_resources_s.NEXTVAL,
45442 refresh_id = v_refresh_id,
45443 last_update_date = v_current_date,
45444 last_updated_by = v_current_user,
45445 creation_date = v_current_date,
45446 created_by = v_current_user
45447 WHERE rowid = lb_rowid(j);
45448
45449
45450 -- Set the error message
45451 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
45452 (p_app_short_name => 'MSC',
45453 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
45454 p_message_text => lv_message_text,
45455 p_error_text => lv_error_text,
45456 p_token1 => 'COLUMN_NAME',
45457 p_token_value1 => 'DELETED_FLAG',
45458 p_token2 => 'DEFAULT_VALUE',
45459 p_token_value2 => SYS_NO );
45460
45461 IF lv_return <> 0 THEN
45462 RAISE ex_logging_err;
45463 END IF;
45464
45465 -- Check whether delete flag value is in (SYS_YES,SYS_NO),
45466 -- if not default to SYS_NO
45467
45468 lv_where_str :=
45469 ' AND NVL(deleted_flag,'||NULL_VALUE||') NOT IN(1,2)';
45470
45471 lv_return := MSC_ST_UTIL.LOG_ERROR
45472 (p_table_name => 'MSC_ST_OPERATION_RESOURCES',
45473 p_instance_code => v_instance_code,
45474 p_row => lv_column_names,
45475 p_severity => G_SEV_WARNING,
45476 p_message_text => 'lv_message_text',
45477 p_error_text => lv_error_text,
45478 p_batch_id => lv_batch_id,
45479 p_where_str => lv_where_str,
45480 p_col_name => 'DELETED_FLAG',
45481 p_debug => v_debug,
45482 p_default_value => SYS_NO);
45483
45484
45485 IF lv_return <> 0 THEN
45486 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,lv_error_text);
45487 END IF;
45488
45489 -- Check whether routing_name is NULL
45490 -- then populate the ASSEMBLY_NAME in that
45491
45492 v_sql_stmt := 36;
45493 lv_sql_stmt :=
45494 'UPDATE msc_st_operation_resources '
45495 ||' SET routing_name = assembly_name'
45496 ||' WHERE sr_instance_code = :v_instance_code'
45497 ||' AND process_flag ='||G_IN_PROCESS
45498 ||' AND NVL(routing_name,'||''''||NULL_CHAR||''''||')'
45499 ||' = '||''''||NULL_CHAR||''''
45500 ||' AND batch_id = :lv_batch_id';
45501
45502
45503
45504
45505 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
45506
45507 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
45508
45509 -- Error out records where resource_usage is NULL
45510
45511 v_sql_stmt := 37;
45512 lv_sql_stmt :=
45513 'UPDATE msc_st_operation_resources '
45514 ||' SET process_flag ='||G_ERROR_FLG||','
45515 ||' error_text = '||''''||lv_message_text||''''
45516 ||' WHERE NVL(resource_usage,'||NULL_VALUE||') ='||NULL_VALUE
45517 ||' AND sr_instance_code = :v_instance_code'
45518 ||' AND deleted_flag = '||SYS_NO
45519 ||' AND process_flag = '||G_IN_PROCESS
45520 ||' AND batch_id = :lv_batch_id';
45521
45522
45523 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
45524
45525 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
45526
45527 -- Set the message
45528 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
45529 (p_app_short_name => 'MSC',
45530 p_error_code => 'MSC_PP_INVALID_VALUE',
45531 p_message_text => lv_message_text,
45532 p_error_text => lv_error_text,
45533 p_token1 => 'COLUMN_NAME',
45534 p_token_value1 => 'ROUTING_NAME');
45535
45536 IF lv_return <> 0 THEN
45537 RAISE ex_logging_err;
45538 END IF;
45539
45540 -- Derive the ROUTING_SEQUENCE_ID from LOCAL ID table
45541 lv_return :=
45542 MSC_ST_UTIL.DERIVE_ROUTING_SEQUENCE_ID
45543 (p_table_name => 'MSC_ST_OPERATION_RESOURCES',
45544 p_rtg_col_name => 'ROUTING_NAME',
45545 p_rtg_col_id =>'ROUTING_SEQUENCE_ID',
45546 p_instance_code => v_instance_code,
45547 p_severity => G_SEV_ERROR,
45548 p_message_text => lv_message_text,
45549 p_batch_id => lv_batch_id,
45550 p_debug => v_debug,
45551 p_error_text => lv_error_text);
45552
45553 if (lv_return <> 0 )then
45554 RAISE ex_logging_err;
45555 end if;
45556
45557
45558 -- Set the error message
45559
45560 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
45561 (p_app_short_name => 'MSC',
45562 p_error_code => 'MSC_PP_INVALID_VALUE',
45563 p_message_text => lv_message_text,
45564 p_error_text => lv_error_text,
45565 p_token1 => 'COLUMN_NAME',
45566 p_token_value1 => 'ORGANIZATION_CODE');
45567
45568 IF lv_return <> 0 THEN
45569 RAISE ex_logging_err;
45570 END IF;
45571
45572 --Derive Organization_id
45573 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
45574 (p_table_name => 'MSC_ST_OPERATION_RESOURCES',
45575 p_org_partner_name => 'ORGANIZATION_CODE',
45576 p_org_partner_id => 'ORGANIZATION_ID',
45577 p_instance_code => v_instance_code,
45578 p_partner_type => G_ORGANIZATION,
45579 p_error_text => lv_error_text,
45580 p_batch_id => lv_batch_id,
45581 p_severity => G_SEV_ERROR,
45582 p_message_text => lv_message_text,
45583 p_debug => v_debug,
45584 p_row => lv_column_names);
45585
45586 IF lv_return <> 0 THEN
45587 RAISE ex_logging_err;
45588 END IF;
45589
45590 -- Set the error message
45591 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
45592 (p_app_short_name => 'MSC',
45593 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
45594 p_message_text => lv_message_text,
45595 p_error_text => lv_error_text,
45596 p_token1 => 'COLUMN_NAME',
45597 p_token_value1 => 'OPERATION_SEQ_CODE',
45598 p_token2 => 'DEFAULT_VALUE',
45599 p_token_value2 => G_OPERATION_SEQ_CODE );
45600
45601 IF lv_return <> 0 THEN
45602 RAISE ex_logging_err;
45603 END IF;
45604
45605 -- Default operation_seq_code as 1 if NULL
45606
45607 lv_where_str := ' AND NVL(operation_seq_code,'||''''||NULL_CHAR||''''
45608 ||' ) ='||''''||NULL_CHAR||'''' ;
45609
45610 lv_return := MSC_ST_UTIL.LOG_ERROR
45611 (p_table_name => 'MSC_ST_OPERATION_RESOURCES',
45612 p_instance_code => v_instance_code,
45613 p_row => lv_column_names,
45614 p_severity => G_SEV_WARNING,
45615 p_message_text => lv_message_text,
45616 p_error_text => lv_error_text,
45617 p_batch_id => lv_batch_id,
45618 p_where_str => lv_where_str,
45619 p_col_name => 'OPERATION_SEQ_CODE',
45620 p_debug => v_debug,
45621 p_default_value => G_OPERATION_SEQ_CODE);
45622
45623 IF lv_return <> 0 THEN
45624 RAISE ex_logging_err;
45625 END IF;
45626
45627
45628 -- Set the error message
45629 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
45630 (p_app_short_name => 'MSC',
45631 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
45632 p_message_text => lv_message_text,
45633 p_error_text => lv_error_text,
45634 p_token1 => 'COLUMN_NAME',
45635 p_token_value1 => 'OPERATION_EFFECTIVITY_DATE',
45636 p_token2 => 'DEFAULT_VALUE',
45637 p_token_value2 => 'SYSDATE' );
45638
45639 IF lv_return <> 0 THEN
45640 RAISE ex_logging_err;
45641 END IF;
45642
45643 -- Default effectivity date as SYSDATE if NULL
45644
45645 lv_where_str :=
45646 ' AND NVL(operation_effectivity_date, SYSDATE-36500 ) = SYSDATE-36500 ' ;
45647
45648 lv_return := MSC_ST_UTIL.LOG_ERROR
45649 (p_table_name => 'MSC_ST_OPERATION_RESOURCES',
45650 p_instance_code => v_instance_code,
45651 p_row => lv_column_names,
45652 p_severity => G_SEV_WARNING,
45653 p_message_text => lv_message_text,
45654 p_error_text => lv_error_text,
45655 p_batch_id => lv_batch_id,
45656 p_where_str => lv_where_str,
45657 p_col_name => 'OPERATION_EFFECTIVITY_DATE',
45658 p_debug => v_debug,
45659 p_default_value => 'SYSDATE');
45660
45661 IF lv_return <> 0 THEN
45662 RAISE ex_logging_err;
45663 END IF;
45664
45665 -- Derive operation sequence id from local id table
45666
45667 v_sql_stmt := 38;
45668 lv_sql_stmt:=
45669 'UPDATE msc_st_operation_resources msor'
45670 ||' SET operation_sequence_id= (SELECT local_id'
45671 ||' FROM msc_local_id_setup mlis'
45672 ||' WHERE mlis.char1 = msor.sr_instance_code'
45673 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
45674 ||' = NVL(msor.company_name,'||''''||NULL_CHAR||''''||') '
45675 ||' AND mlis.char3 = msor.organization_code'
45676 ||' AND mlis.char4 = msor.routing_name'
45677 ||' AND mlis.char5 = msor.operation_seq_code'
45678 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
45679 ||' = NVL(msor.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
45680 ||' AND mlis.date1 = msor.operation_effectivity_date'
45681 ||' AND mlis.entity_name = ''OPERATION_SEQUENCE_ID'') '
45682 ||' WHERE sr_instance_code = :v_instance_code'
45683 ||' AND process_flag = '||G_IN_PROCESS
45684 ||' AND batch_id = :lv_batch_id';
45685
45686
45687
45688 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
45689
45690 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
45691
45692 -- Set the error message
45693 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
45694 (p_app_short_name => 'MSC',
45695 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
45696 p_message_text => lv_message_text,
45697 p_error_text => lv_error_text,
45698 p_token1 => 'COLUMN_NAMES',
45699 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
45700 ||'ORGANIZATION_CODE,ROUTING_NAME,'
45701 ||' OPERATION_SEQ_CODE,EFFECTIVITY_DATE,'
45702 ||' ALTERNATE_ROUTING_DESIGNATOR' ,
45703 p_token2 => 'MASTER_TABLE',
45704 p_token_value2 => 'MSC_ST_ROUTING_OPERATIONS',
45705 p_token3 => 'CHILD_TABLE' ,
45706 p_token_value3 => 'MSC_ST_OPERATION_RESOURCES' );
45707
45708 IF lv_return <> 0 THEN
45709 RAISE ex_logging_err;
45710 END IF;
45711
45712
45713 --Error out record where operation_sequence_id is NULL
45714
45715 v_sql_stmt := 39;
45716
45717 lv_sql_stmt :=
45718 'UPDATE msc_st_operation_resources'
45719 ||' SET process_flag = '||G_ERROR_FLG||','
45720 ||' error_text = '||''''||lv_message_text||''''
45721 ||' WHERE NVL(operation_sequence_id,'||NULL_VALUE||') = '||NULL_VALUE
45722 ||' AND sr_instance_code = :v_instance_code'
45723 ||' AND process_flag = '||G_IN_PROCESS
45724 ||' AND batch_id = :lv_batch_id';
45725
45726
45727
45728 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
45729
45730 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
45731
45732 -- Set the error message
45733 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
45734 (p_app_short_name => 'MSC',
45735 p_error_code => 'MSC_PP_COL_VAL_NULL_DEFAULT',
45736 p_message_text => lv_message_text,
45737 p_error_text => lv_error_text,
45738 p_token1 => 'COLUMN_NAME',
45739 p_token_value1 => 'RESOURCE_SEQ_CODE',
45740 p_token2 => 'DEFAULT_VALUE',
45741 p_token_value2 => G_RESOURCE_SEQ_CODE );
45742
45743 IF lv_return <> 0 THEN
45744 RAISE ex_logging_err;
45745 END IF;
45746
45747 -- Default resource_seq_code as 1 if NULL
45748
45749 lv_where_str := ' AND NVL(resource_seq_code,'||''''||NULL_CHAR||''''
45750 ||' ) ='||''''||NULL_CHAR||'''' ;
45751
45752 lv_return := MSC_ST_UTIL.LOG_ERROR
45753 (p_table_name => 'MSC_ST_OPERATION_RESOURCES',
45754 p_instance_code => v_instance_code,
45755 p_row => lv_column_names,
45756 p_severity => G_SEV_WARNING,
45757 p_message_text => lv_message_text,
45758 p_error_text => lv_error_text,
45759 p_batch_id => lv_batch_id,
45760 p_where_str => lv_where_str,
45761 p_col_name => 'RESOURCE_SEQ_CODE',
45762 p_debug => v_debug,
45763 p_default_value => G_RESOURCE_SEQ_CODE);
45764
45765 IF lv_return <> 0 THEN
45766 RAISE ex_logging_err;
45767 END IF;
45768
45769 -- Set the error message
45770 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
45771 (p_app_short_name => 'MSC',
45772 p_error_code => 'MSC_PP_COL_VAL_NULL_DEFAULT',
45773 p_message_text => lv_message_text,
45774 p_error_text => lv_error_text,
45775 p_token1 => 'COLUMN_NAME',
45776 p_token_value1 => 'ALTERNATE_NUMBER',
45777 p_token2 => 'DEFAULT_VALUE',
45778 p_token_value2 => G_ALTERNATE_NUMBER );
45779
45780 IF lv_return <> 0 THEN
45781 RAISE ex_logging_err;
45782 END IF;
45783
45784 -- Default alternate number as 0 if NULL
45785
45786 lv_where_str := ' AND NVL(alternate_number,'||NULL_VALUE||') ='||NULL_VALUE ;
45787
45788 lv_return := MSC_ST_UTIL.LOG_ERROR
45789 (p_table_name => 'MSC_ST_OPERATION_RESOURCES',
45790 p_instance_code => v_instance_code,
45791 p_row => lv_column_names,
45792 p_severity => G_SEV_WARNING,
45793 p_message_text => lv_message_text,
45794 p_error_text => lv_error_text,
45795 p_batch_id => lv_batch_id,
45796 p_where_str => lv_where_str,
45797 p_col_name => 'ALTERNATE_NUMBER',
45798 p_debug => v_debug,
45799 p_default_value => G_ALTERNATE_NUMBER);
45800
45801 IF lv_return <> 0 THEN
45802 RAISE ex_logging_err;
45803 END IF;
45804
45805 -- Derive resource seq num from the local id table
45806
45807 v_sql_stmt := 40;
45808 lv_sql_stmt :=
45809 'UPDATE msc_st_operation_resources msor'
45810 ||' SET resource_seq_num = (SELECT local_id '
45811 ||' FROM msc_local_id_setup mlis'
45812 ||' WHERE mlis.char1 = msor.sr_instance_code'
45813 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
45814 ||' = NVL(msor.company_name,'||''''||NULL_CHAR||''''||') '
45815 ||' AND mlis.char3 = msor.organization_code'
45816 ||' AND mlis.char4 = msor.routing_name'
45817 ||' AND mlis.char5 = msor.operation_seq_code'
45818 ||' AND mlis.char6 = msor.resource_seq_code'
45819 ||' AND NVL(mlis.char7,'||''''||NULL_CHAR||''''||') '
45820 ||' = NVL(msor.alternate_routing_designator,'||''''||NULL_CHAR||''''||')'
45821 ||' AND NVL(mlis.number1,'||NULL_VALUE||') = NVL(msor.alternate_number,'||NULL_VALUE||')'
45822 ||' AND rownum = 1' /*change made to solve res req issue*/
45823 ||' AND mlis.entity_name = ''RESOURCE_SEQ_NUM'')'
45824 ||' WHERE sr_instance_code = :v_instance_code'
45825 ||' AND process_flag = '||G_IN_PROCESS
45826 ||' AND batch_id = :lv_batch_id';
45827
45828
45829
45830 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
45831
45832 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
45833
45834
45835 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
45836 (p_app_short_name => 'MSC',
45837 p_error_code => 'MSC_PP_DELETE_FAIL',
45838 p_message_text => lv_message_text,
45839 p_error_text => lv_error_text);
45840
45841 IF lv_return <> 0 THEN
45842 RAISE ex_logging_err;
45843 END IF;
45844
45845 -- Error out the records where delete flag yes
45846 -- and resource_seq_num is NULL
45847
45848 v_sql_stmt := 41;
45849 lv_sql_stmt :=
45850 'UPDATE msc_st_operation_resources '
45851 ||' SET process_flag = '||G_ERROR_FLG||','
45852 ||' error_text = '||''''||lv_message_text||''''
45853 ||' WHERE NVL(resource_seq_num,'||NULL_VALUE||') ='||NULL_VALUE
45854 ||' AND deleted_flag = '||SYS_YES
45855 ||' AND sr_instance_code = :v_instance_code'
45856 ||' AND process_flag = '||G_IN_PROCESS
45857 ||' AND batch_id = :lv_batch_id';
45858
45859
45860
45861 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
45862
45863 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
45864
45865
45866 -- Derive resource id
45867 v_sql_stmt := 42;
45868
45869 lv_sql_stmt :=
45870 'UPDATE msc_st_operation_resources msor'
45871 ||' SET resource_id = (SELECT local_id'
45872 ||' FROM msc_local_id_setup mlis'
45873 ||' WHERE mlis.char1 = msor.sr_instance_code'
45874 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
45875 ||' = NVL(msor.company_name,'||''''||NULL_CHAR||''''||') '
45876 ||' AND mlis.char3 = msor.organization_code'
45877 ||' AND mlis.char4 = msor.resource_code'
45878 ||' AND mlis.entity_name = ''RESOURCE_ID'')'
45879 ||' WHERE sr_instance_code = :v_instance_code'
45880 ||' AND deleted_flag = '|| SYS_NO
45881 ||' AND process_flag = '||G_IN_PROCESS
45882 ||' AND batch_id = :lv_batch_id';
45883
45884
45885 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
45886
45887 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
45888
45889 -- Derive department id
45890 v_sql_stmt := 43;
45891
45892 lv_sql_stmt :=
45893 'UPDATE msc_st_operation_resources msor'
45894 ||' SET department_id = (SELECT local_id'
45895 ||' FROM msc_local_id_setup mlis'
45896 ||' WHERE mlis.char1 = msor.sr_instance_code'
45897 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
45898 ||' = NVL(msor.company_name,'||''''||NULL_CHAR||''''||') '
45899 ||' AND mlis.char3 = msor.organization_code'
45900 ||' AND mlis.char4 = msor.department_code'
45901 ||' AND mlis.entity_name = ''DEPARTMENT_ID'')'
45902 ||' WHERE sr_instance_code = :v_instance_code'
45903 ||' AND deleted_flag = '|| SYS_NO
45904 ||' AND process_flag = '||G_IN_PROCESS
45905 ||' AND batch_id = :lv_batch_id';
45906
45907
45908 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
45909
45910 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
45911
45912 -- Set the error message
45913 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
45914 (p_app_short_name => 'MSC',
45915 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
45916 p_message_text => lv_message_text,
45917 p_error_text => lv_error_text,
45918 p_token1 => 'COLUMN_NAMES',
45919 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
45920 ||' ORGANIZATION_CODE,DEPARTMENT_CODE'
45921 ||' OR RESOURCE_CODE' ,
45922 p_token2 => 'MASTER_TABLE',
45923 p_token_value2 => 'MSC_ST_DEPARTMENT_RESOURCES',
45924 p_token3 => 'CHILD_TABLE' ,
45925 p_token_value3 => 'MSC_ST_OPERATION_RESOURCES' );
45926
45927 IF lv_return <> 0 THEN
45928 RAISE ex_logging_err;
45929 END IF;
45930
45931 -- Error out records where resource_id or department_id is NULL
45932
45933 v_sql_stmt := 44;
45934 lv_sql_stmt :=
45935 'UPDATE msc_st_operation_resources'
45936 ||' SET process_flag ='||G_ERROR_FLG||','
45937 ||' error_text = '||''''||lv_message_text||''''
45938 ||' WHERE (NVL(resource_id,'||NULL_VALUE||') ='|| NULL_VALUE
45939 ||' OR NVL(department_id,'||NULL_VALUE||') ='|| NULL_VALUE||')'
45940 ||' AND sr_instance_code = :v_instance_code'
45941 ||' AND process_flag ='||G_IN_PROCESS
45942 ||' AND batch_id = :lv_batch_id';
45943
45944
45945 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
45946
45947 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
45948
45949
45950 lv_sql_stmt :=
45951 'UPDATE msc_st_operation_resources msor'
45952 ||' SET setup_id= (SELECT local_id'
45953 ||' FROM msc_local_id_setup mlis'
45954 ||' WHERE mlis.char1 = msor.sr_instance_code'
45955 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||')'
45956 ||' =NVL(msor.company_name,'||''''||NULL_CHAR||''''||') '
45957 ||' AND mlis.char3 = msor.organization_code'
45958 ||' AND mlis.char4 = msor.setup_code'
45959 ||' AND mlis.entity_name = ''SETUP_ID'')'
45960 ||' WHERE msor.sr_instance_code = :v_instance_code'
45961 ||' AND NVL(msor.setup_code,'||''''||NULL_CHAR||''''||')'
45962 ||' <> '||''''||NULL_CHAR||''''
45963 ||' AND msor.process_flag ='|| G_IN_PROCESS
45964 ||' AND msor.batch_id = :lv_batch_id';
45965
45966 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
45967
45968 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
45969
45970 -- Set the error message
45971 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
45972 (p_app_short_name => 'MSC',
45973 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
45974 p_message_text => lv_message_text,
45975 p_error_text => lv_error_text,
45976 p_token1 => 'COLUMN_NAMES',
45977 p_token_value1 => 'SETUP_CODE',
45978 p_token2 => 'MASTER_TABLE',
45979 p_token_value2 => 'MSC_ST_RESOURCE_SETUPS',
45980 p_token3 => 'CHILD_TABLE' ,
45981 p_token_value3 => 'MSC_ST_OPERATION_RESOURCES' );
45982
45983 IF lv_return <> 0 THEN
45984 RAISE ex_logging_err;
45985 END IF;
45986 v_sql_stmt := 06;
45987
45988 lv_sql_stmt :=
45989 ' UPDATE msc_st_operation_resources '
45990 ||' SET process_flag ='||G_ERROR_FLG||','
45991 ||' error_text = '||''''||lv_message_text||''''
45992 ||' WHERE NVL(setup_id,'||NULL_VALUE||') ='|| NULL_VALUE
45993 ||' AND setup_code is not NULL'
45994 ||' AND deleted_flag = '||SYS_NO
45995 ||' AND process_flag = '||G_IN_PROCESS
45996 ||' AND sr_instance_code = :v_instance_code'
45997 ||' AND batch_id = :lv_batch_id';
45998
45999
46000
46001 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
46002
46003 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
46004
46005
46006
46007 -- Set the error message
46008 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
46009 (p_app_short_name => 'MSC',
46010 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
46011 p_message_text => lv_message_text,
46012 p_error_text => lv_error_text,
46013 p_token1 => 'COLUMN_NAME',
46014 p_token_value1 => 'BASIS_TYPE',
46015 p_token2 => 'DEFAULT_VALUE',
46016 p_token_value2 => G_BASIS_TYPE );
46017
46018 IF lv_return <> 0 THEN
46019 RAISE ex_logging_err;
46020 END IF;
46021
46022 -- Default basis type as 1 if INVALID
46023
46024 lv_where_str :=
46025 ' AND NVL(basis_type,'||NULL_VALUE||')'
46026 ||' NOT IN (1,2,3,4,5) AND deleted_flag = 2' ;
46027
46028 lv_return := MSC_ST_UTIL.LOG_ERROR
46029 (p_table_name => 'MSC_ST_OPERATION_RESOURCES',
46030 p_instance_code => v_instance_code,
46031 p_row => lv_column_names,
46032 p_severity => G_SEV_WARNING,
46033 p_message_text => lv_message_text,
46034 p_error_text => lv_error_text,
46035 p_batch_id => lv_batch_id,
46036 p_where_str => lv_where_str,
46037 p_col_name => 'BASIS_TYPE',
46038 p_debug => v_debug,
46039 p_default_value => G_BASIS_TYPE);
46040 IF lv_return <> 0 THEN
46041 RAISE ex_logging_err;
46042 END IF;
46043
46044 -- Set the error message
46045 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
46046 (p_app_short_name => 'MSC',
46047 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
46048 p_message_text => lv_message_text,
46049 p_error_text => lv_error_text,
46050 p_token1 => 'COLUMN_NAME',
46051 p_token_value1 => 'PRINCIPAL_FLAG',
46052 p_token2 => 'DEFAULT_VALUE',
46053 p_token_value2 => G_PRINCIPAL_FLAG );
46054
46055 IF lv_return <> 0 THEN
46056 RAISE ex_logging_err;
46057 END IF;
46058
46059 -- Default principal_flag as 1 if NOT IN (1,2)
46060
46061 lv_where_str := ' AND NVL(principal_flag,'||NULL_VALUE||')'||' NOT IN (1,2)'
46062 ||'AND deleted_flag = 2';
46063
46064 lv_return := MSC_ST_UTIL.LOG_ERROR
46065 (p_table_name => 'MSC_ST_OPERATION_RESOURCES',
46066 p_instance_code => v_instance_code,
46067 p_row => lv_column_names,
46068 p_severity => G_SEV_WARNING,
46069 p_message_text => lv_message_text,
46070 p_error_text => lv_error_text,
46071 p_batch_id => lv_batch_id,
46072 p_where_str => lv_where_str,
46073 p_col_name => 'PRINCIPAL_FLAG',
46074 p_debug => v_debug,
46075 p_default_value => G_PRINCIPAL_FLAG);
46076
46077 IF lv_return <> 0 THEN
46078 RAISE ex_logging_err;
46079 END IF;
46080
46081 --Call to customised validation.
46082
46083 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
46084 (ERRBUF => lv_error_text,
46085 RETCODE => lv_return,
46086 pBatchID => lv_batch_id,
46087 pInstanceCode => v_instance_code,
46088 pEntityName => 'MSC_ST_OPERATION_RESOURCES',
46089 pInstanceID => v_instance_id);
46090
46091 IF NVL(lv_return,0) <> 0 THEN
46092 RAISE ex_logging_err;
46093 END IF;
46094
46095 -- Now generate resource_seq_num
46096 -- Its an update of resource_seq_num with the resource_seq_code
46097
46098 v_sql_stmt := 45;
46099
46100 OPEN c7(lv_batch_id);
46101 FETCH c7 BULK COLLECT INTO lb_rowid ;
46102
46103 IF c7%ROWCOUNT > 0 THEN
46104
46105 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
46106
46107 UPDATE msc_st_operation_resources
46108 SET resource_seq_num =
46109 to_number(decode(length(rtrim(resource_seq_code,'0123456789')),
46110 NULL,resource_seq_code,'1'))
46111 WHERE rowid = lb_rowid(j);
46112
46113 v_sql_stmt := 46;
46114
46115 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
46116 -- Insert into the LID table with the user defined key
46117
46118 INSERT INTO msc_local_id_setup
46119 (local_id,
46120 st_transaction_id,
46121 instance_id,
46122 entity_name,
46123 data_source_type,
46124 char1,
46125 char2,
46126 char3,
46127 char4,
46128 char5,
46129 char6,
46130 char7,
46131 number1,
46132 SOURCE_ORGANIZATION_ID,
46133 SOURCE_ROUTING_SEQUENCE_ID ,
46134 SOURCE_OPERATION_SEQUENCE_ID ,
46135 SOURCE_RESOURCE_SEQ_NUM ,
46136 SOURCE_RESOURCE_ID ,
46137 SOURCE_DEPARTMENT_ID ,
46138 last_update_date,
46139 last_updated_by,
46140 creation_date,
46141 created_by )
46142 SELECT
46143 resource_seq_num,
46144 st_transaction_id,
46145 v_instance_id,
46146 'RESOURCE_SEQ_NUM',
46147 data_source_type,
46148 v_instance_code,
46149 company_name,
46150 organization_code,
46151 routing_name,
46152 operation_seq_code,
46153 resource_seq_code,
46154 alternate_routing_designator,
46155 alternate_number,
46156 SOURCE_ORGANIZATION_ID,
46157 SOURCE_ROUTING_SEQUENCE_ID ,
46158 SOURCE_OPERATION_SEQUENCE_ID ,
46159 SOURCE_RESOURCE_SEQ_NUM ,
46160 SOURCE_RESOURCE_ID ,
46161 SOURCE_DEPARTMENT_ID ,
46162 v_current_date,
46163 v_current_user,
46164 v_current_date,
46165 v_current_user
46166 FROM msc_st_operation_resources
46167 WHERE rowid = lb_rowid(j) ;
46168
46169 END IF;
46170 CLOSE c7;
46171
46172 -- Update resource seq num from the local id table
46173
46174 v_sql_stmt := 47;
46175 lv_sql_stmt :=
46176 'UPDATE msc_st_operation_resources msor'
46177 ||' SET resource_seq_num = (SELECT local_id '
46178 ||' FROM msc_local_id_setup mlis'
46179 ||' WHERE mlis.char1 = msor.sr_instance_code'
46180 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
46181 ||' = NVL(msor.company_name,'||''''||NULL_CHAR||''''||') '
46182 ||' AND mlis.char3 = msor.organization_code'
46183 ||' AND mlis.char4 = msor.routing_name'
46184 ||' AND mlis.char5 = msor.operation_seq_code'
46185 ||' AND mlis.char6 = msor.resource_seq_code'
46186 ||' AND NVL(mlis.char7,'||''''||NULL_CHAR||''''||') '
46187 ||' = NVL(msor.alternate_routing_designator,'||''''||NULL_CHAR||''''||')'
46188 ||' AND NVL(mlis.number1,'||NULL_VALUE||') = NVL(msor.alternate_number,'||NULL_VALUE||')'
46189 ||' AND rownum = 1' /*change made to solve res req issue*/
46190 ||' AND mlis.entity_name = ''RESOURCE_SEQ_NUM'')'
46191 ||' WHERE sr_instance_code = :v_instance_code'
46192 ||' AND NVL(resource_seq_num,'||NULL_VALUE||') = '||NULL_VALUE
46193 ||' AND process_flag = '||G_IN_PROCESS
46194 ||' AND batch_id = :lv_batch_id';
46195
46196
46197
46198 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
46199
46200 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
46201
46202
46203 OPEN c8(lv_batch_id);
46204 FETCH c8 BULK COLLECT INTO lb_rowid ;
46205
46206 v_sql_stmt := 48;
46207
46208 IF c8%ROWCOUNT > 0 THEN
46209 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
46210
46211
46212 INSERT INTO msc_st_operation_resource_seqs
46213 ( routing_sequence_id,
46214 operation_sequence_id,
46215 resource_seq_num,
46216 schedule_flag,
46217 resource_offset_percent,
46218 department_id,
46219 deleted_flag,
46220 organization_id,
46221 sr_instance_id,
46222 activity_group_id,
46223 refresh_id,
46224 last_update_date,
46225 last_updated_by,
46226 creation_date,
46227 created_by )
46228 SELECT
46229 routing_sequence_id,
46230 operation_sequence_id,
46231 resource_seq_num,
46232 schedule_flag,
46233 resource_offset_percent,
46234 department_id,
46235 deleted_flag,
46236 organization_id,
46237 v_instance_id,
46238 activity_group_id,
46239 v_refresh_id,
46240 last_update_date,
46241 last_updated_by,
46242 creation_date,
46243 created_by
46244 FROM msc_st_operation_resources
46245 WHERE rowid = lb_rowid(j) ;
46246
46247 END IF ;
46248 CLOSE c8 ;
46249
46250 -- Set the process flag as Valid and derive sr_instance_id
46251 lv_return :=
46252 MSC_ST_UTIL.SET_PROCESS_FLAG(p_table_name => 'MSC_ST_OPERATION_RESOURCES',
46253 p_instance_id => v_instance_id,
46254 p_instance_code => v_instance_code,
46255 p_process_flag => G_VALID,
46256 p_error_text => lv_error_text,
46257 p_debug => v_debug,
46258 p_batch_id => lv_batch_id);
46259
46260 IF lv_return < 0 THEN
46261 RAISE ex_logging_err;
46262 END IF;
46263
46264
46265 -- At the end calling the LOG_ERROR for logging all errored out records
46266
46267 lv_return :=
46268 MSC_ST_UTIL.LOG_ERROR(p_table_name =>'MSC_ST_OPERATION_RESOURCES',
46269 p_instance_code =>v_instance_code,
46270 p_row =>lv_column_names,
46271 p_severity =>G_SEV_ERROR,
46272 p_message_text =>NULL,
46273 p_error_text =>lv_error_text,
46274 p_debug => v_debug,
46275 p_batch_id => lv_batch_id );
46276
46277 IF lv_return <> 0 THEN
46278 RAISE ex_logging_err;
46279 END IF;
46280
46281 COMMIT;
46282
46283 END LOOP;
46284
46285 -- From here added for OSFM Integration
46286 -- Pre processing for MSC_ST_OPERATION_NETWORKS
46287
46288 --Duplicate records check for the records whose source is XML
46289
46290 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
46291 (p_app_short_name => 'MSC',
46292 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
46293 p_message_text => lv_message_text,
46294 p_error_text => lv_error_text);
46295
46296 IF lv_return <> 0 THEN
46297 RAISE ex_logging_err;
46298 END IF;
46299
46300 v_sql_stmt := 51;
46301
46302 lv_sql_stmt :=
46303 'UPDATE msc_st_operation_networks mson1 '
46304 ||' SET process_flag = '||G_ERROR_FLG||','
46305 ||' error_text = '||''''||lv_message_text||''''
46306 ||' WHERE message_id < ( SELECT max(message_id) '
46307 ||' FROM msc_st_operation_networks mson2'
46308 ||' WHERE mson2.assembly_name = mson1.assembly_name'
46309 ||' AND mson2.organization_code = mson1.organization_code'
46310 ||' AND mson2.from_operation_seq_code = mson1.from_operation_seq_code'
46311 ||' AND mson2.to_operation_seq_code = mson1.to_operation_seq_code'
46312 ||' AND mson2.sr_instance_code = mson1.sr_instance_code'
46313 ||' AND NVL(mson2.company_name,'||''''||NULL_CHAR||''''||') '
46314 ||' = NVL(mson1.company_name,'||''''||NULL_CHAR||''''||') '
46315 ||' AND NVL(mson2.routing_name,'||''''||NULL_CHAR||''''||') '
46316 ||' = NVL(mson1.routing_name, '||''''||NULL_CHAR||''''||') '
46317 ||' AND NVL(mson2.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
46318 ||' = NVL(mson1.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
46319 ||' AND mson2.process_flag ='||G_IN_PROCESS
46320 ||' AND NVL(mson2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||')'
46321 ||' AND mson1.process_flag = '||G_IN_PROCESS
46322 ||' AND mson1.sr_instance_code = :v_instance_code'
46323 ||' AND NVL(mson1.message_id,'||NULL_VALUE||')<> '||NULL_VALUE;
46324
46325
46326 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
46327
46328 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
46329
46330
46331
46332 --Duplicate records check for the records whose source is batch load
46333
46334 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
46335 (p_app_short_name => 'MSC',
46336 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
46337 p_message_text => lv_message_text,
46338 p_error_text => lv_error_text);
46339
46340 IF lv_return <> 0 THEN
46341 RAISE ex_logging_err;
46342 END IF;
46343
46344 v_sql_stmt := 52;
46345
46346 lv_sql_stmt :=
46347 'UPDATE msc_st_operation_networks mson1'
46348 ||' SET process_flag = '||G_ERROR_FLG||','
46349 ||' error_text = '||''''||lv_message_text||''''
46350 ||' WHERE EXISTS ( SELECT 1 '
46351 ||' FROM msc_st_operation_networks mson2'
46352 ||' WHERE mson2.assembly_name = mson1.assembly_name'
46353 ||' AND mson2.organization_code = mson1.organization_code'
46354 ||' AND mson2.from_operation_seq_code = mson1.from_operation_seq_code'
46355 ||' AND mson2.to_operation_seq_code = mson1.to_operation_seq_code'
46356 ||' AND mson2.sr_instance_code = mson1.sr_instance_code'
46357 ||' AND NVL(mson2.company_name,'||''''||NULL_CHAR||''''||') '
46358 ||' = NVL(mson1.company_name,'||''''||NULL_CHAR||''''||') '
46359 ||' AND NVL(mson2.routing_name,'||''''||NULL_CHAR||''''||') '
46360 ||' = NVL(mson1.routing_name, '||''''||NULL_CHAR||''''||') '
46361 ||' AND NVL(mson2.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
46362 ||' = NVL(mson1.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
46363 ||' AND mson2.process_flag ='||G_IN_PROCESS
46364 ||' AND NVL(mson2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
46365 ||' AND mson2.rowid <> mson1.rowid )'
46366 ||' AND mson1.process_flag = '||G_IN_PROCESS
46367 ||' AND mson1.sr_instance_code = :v_instance_code'
46368 ||' AND NVL(mson1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
46369
46370
46371 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
46372
46373 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
46374
46375 COMMIT;
46376
46377 lv_column_names :=
46378 ' FROM_OPERATION_SEQ_CODE ||''~''||'
46379 ||' FROM_OP_EFFECTIVITY_DATE ||''~''||'
46380 ||' FROM_OP_DISABLE_DATE ||''~''||'
46381 ||' TO_OPERATION_SEQ_CODE ||''~''||'
46382 ||' TO_OP_EFFECTIVITY_DATE ||''~''||'
46383 ||' TO_OP_DISABLE_DATE ||''~''||'
46384 ||' ROUTING_NAME ||''~''||'
46385 ||' ASSEMBLY_NAME ||''~''||'
46386 ||' ALTERNATE_ROUTING_DESIGNATOR ||''~''||'
46387 ||' TRANSITION_TYPE ||''~''||'
46388 ||' PLANNING_PCT ||''~''||'
46389 ||' CUMMULATIVE_PCT ||''~''||'
46390 ||' DISABLE_DATE ||''~''||'
46391 ||' EFECTIVITY_DATE ||''~''||'
46392 ||' ORGANIZATION_CODE ||''~''||'
46393 ||' SR_INSTANCE_CODE ||''~''||'
46394 ||' DELETED_FLAG ||''~''||'
46395 ||' COMPANY_NAME ';
46396
46397
46398
46399 -- Now processing in batch
46400 LOOP
46401
46402 v_sql_stmt := 53;
46403
46404 lv_cursor_stmt :=
46405 ' SELECT msc_st_batch_id_s.NEXTVAL '
46406 ||' FROM dual';
46407
46408 OPEN c1 FOR lv_cursor_stmt;
46409 FETCH c1 INTO lv_batch_id;
46410 CLOSE c1;
46411
46412
46413 v_sql_stmt := 54;
46414
46415 lv_sql_stmt :=
46416 ' UPDATE msc_st_operation_networks '
46417 ||' SET batch_id = :lv_batch_id'
46418 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
46419 ||' AND sr_instance_code = :v_instance_code'
46420 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
46421 ||' AND rownum <= '||v_batch_size;
46422
46423
46424 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
46425
46426 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
46427
46428 EXIT WHEN SQL%NOTFOUND;
46429
46430 OPEN c9(lv_batch_id);
46431 FETCH c9 BULK COLLECT INTO lb_rowid;
46432 CLOSE c9;
46433
46434 v_sql_stmt := 55;
46435
46436 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
46437 UPDATE msc_st_operation_networks
46438 SET st_transaction_id = msc_st_operation_networks_s.NEXTVAL,
46439 refresh_id = v_refresh_id,
46440 last_update_date = v_current_date,
46441 last_updated_by = v_current_user,
46442 creation_date = v_current_date,
46443 created_by = v_current_user
46444 WHERE rowid = lb_rowid(j);
46445
46446
46447 -- Set the error message
46448 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
46449 (p_app_short_name => 'MSC',
46450 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
46451 p_message_text => lv_message_text,
46452 p_error_text => lv_error_text,
46453 p_token1 => 'COLUMN_NAME',
46454 p_token_value1 => 'DELETED_FLAG',
46455 p_token2 => 'DEFAULT_VALUE',
46456 p_token_value2 => SYS_NO );
46457
46458 IF lv_return <> 0 THEN
46459 RAISE ex_logging_err;
46460 END IF;
46461
46462 -- Check whether delete flag value is in (1,2),if not default to SYS_NO
46463
46464 lv_where_str :=
46465 ' AND NVL(deleted_flag,'||NULL_VALUE||') NOT IN(1,2)';
46466
46467 lv_return := MSC_ST_UTIL.LOG_ERROR
46468 (p_table_name => 'MSC_ST_OPERATION_NETWORKS',
46469 p_instance_code => v_instance_code,
46470 p_row => lv_column_names,
46471 p_severity => G_SEV_WARNING,
46472 p_message_text => lv_message_text,
46473 p_error_text => lv_error_text,
46474 p_batch_id => lv_batch_id,
46475 p_where_str => lv_where_str,
46476 p_col_name => 'DELETED_FLAG',
46477 p_debug => v_debug,
46478 p_default_value => SYS_NO);
46479
46480 IF lv_return <> 0 THEN
46481 RAISE ex_logging_err;
46482 END IF;
46483
46484
46485 -- Set the error message
46486 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
46487 (p_app_short_name => 'MSC',
46488 p_error_code => 'MSC_PP_COL_VAL_NULL',
46489 p_message_text => lv_message_text,
46490 p_error_text => lv_error_text,
46491 p_token1 => 'COLUMN_NAME',
46492 p_token_value1 => 'PLANNING_PCT');
46493
46494 IF lv_return <> 0 THEN
46495 RAISE ex_logging_err;
46496 END IF;
46497
46498 -- Error out the records whose PLANNING_PCT is NULL
46499
46500 v_sql_stmt := 56;
46501 lv_sql_stmt :=
46502 'UPDATE msc_st_operation_networks'
46503 ||' SET process_flag ='||G_ERROR_FLG||','
46504 ||' error_text = '||''''||lv_message_text||''''
46505 ||' WHERE NVL(PLANNING_PCT,'||NULL_VALUE||') = '||NULL_VALUE
46506 ||' AND sr_instance_code = :v_instance_code'
46507 ||' AND process_flag = '||G_IN_PROCESS
46508 ||' AND batch_id = :lv_batch_id';
46509
46510
46511 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
46512
46513 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
46514
46515 -- Set the error message
46516 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
46517 (p_app_short_name => 'MSC',
46518 p_error_code => 'MSC_PP_COL_VAL_NULL',
46519 p_message_text => lv_message_text,
46520 p_error_text => lv_error_text,
46521 p_token1 => 'COLUMN_NAME',
46522 p_token_value1 => 'ASSEMBLY_NAME');
46523
46524 IF lv_return <> 0 THEN
46525 RAISE ex_logging_err;
46526 END IF;
46527
46528 -- Error out the records whose Assembly Name is NULL
46529
46530 v_sql_stmt := 57;
46531 lv_sql_stmt :=
46532 'UPDATE msc_st_operation_networks'
46533 ||' SET process_flag ='||G_ERROR_FLG||','
46534 ||' error_text = '||''''||lv_message_text||''''
46535 ||' WHERE NVL(assembly_name,'||''''||NULL_CHAR||''''||') '
46536 ||' = '||''''||NULL_CHAR||''''
46537 ||' AND sr_instance_code = :v_instance_code'
46538 ||' AND process_flag = '||G_IN_PROCESS
46539 ||' AND batch_id = :lv_batch_id';
46540
46541
46542 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
46543
46544 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
46545
46546 -- Now we will check whether Routing Name is NULL , if it is NULL we will populate the
46547 -- ASSEMBLY NAME in ROUTING_NAME column for all such records
46548
46549 v_sql_stmt := 58;
46550
46551 lv_sql_stmt :=
46552 'UPDATE msc_st_operation_networks '
46553 ||' SET routing_name = assembly_name'
46554 ||' WHERE sr_instance_code = :v_instance_code'
46555 ||' AND process_flag = '||G_IN_PROCESS
46556 ||' AND NVL(routing_name,'||''''||NULL_CHAR||''''||') '
46557 ||' = '||''''||NULL_CHAR||''''
46558 ||' AND batch_id = :lv_batch_id';
46559
46560
46561 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
46562
46563 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
46564
46565
46566
46567 -- Set the error message
46568 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
46569 (p_app_short_name => 'MSC',
46570 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
46571 p_message_text => lv_message_text,
46572 p_error_text => lv_error_text,
46573 p_token1 => 'COLUMN_NAMES',
46574 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
46575 ||'ORGANIZATION_CODE,ROUTING_NAME',
46576 p_token2 => 'MASTER_TABLE',
46577 p_token_value2 => 'MSC_ST_ROUTINGS',
46578 p_token3 => 'CHILD_TABLE' ,
46579 p_token_value3 => 'MSC_ST_OPERATION_NETWORKS' );
46580
46581 IF lv_return <> 0 THEN
46582 RAISE ex_logging_err;
46583 END IF;
46584
46585 -- Derive the ROUTING_SEQUENCE_ID from LOCAL ID table
46586 v_sql_stmt := 59;
46587 lv_return :=
46588 MSC_ST_UTIL.DERIVE_ROUTING_SEQUENCE_ID
46589 (p_table_name => 'MSC_ST_OPERATION_NETWORKS',
46590 p_rtg_col_name => 'ROUTING_NAME',
46591 p_rtg_col_id => 'ROUTING_SEQUENCE_ID',
46592 p_instance_code => v_instance_code,
46593 p_severity => G_SEV_ERROR,
46594 p_message_text => lv_message_text,
46595 p_batch_id => lv_batch_id,
46596 p_debug => v_debug,
46597 p_error_text => lv_error_text);
46598
46599 if (lv_return <> 0 )then
46600 RAISE ex_logging_err;
46601 end if;
46602
46603
46604
46605 -- Set the error message
46606 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
46607 (p_app_short_name => 'MSC',
46608 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
46609 p_message_text => lv_message_text,
46610 p_error_text => lv_error_text,
46611 p_token1 => 'COLUMN_NAME',
46612 p_token_value1 => 'FROM_OP_EFFECTIVITY_DATE',
46613 p_token2 => 'DEFAULT_VALUE',
46614 p_token_value2 => 'SYSDATE' );
46615
46616 IF lv_return <> 0 THEN
46617 RAISE ex_logging_err;
46618 END IF;
46619
46620 -- The effectivity date does not get defaulted to sysdate in ERP collection
46621 /* -- Default from operation effectivity date as SYSDATE if NULL
46622
46623 v_sql_stmt := 60;
46624 lv_where_str :=
46625 ' AND NVL(from_op_effectivity_date,SYSDATE-36500 ) = SYSDATE-36500 ' ;
46626
46627 lv_return := MSC_ST_UTIL.LOG_ERROR
46628 (p_table_name => 'MSC_ST_OPERATION_NETWORKS',
46629 p_instance_code => v_instance_code,
46630 p_row => lv_column_names,
46631 p_severity => G_SEV_WARNING,
46632 p_message_text => lv_message_text,
46633 p_error_text => lv_error_text,
46634 p_batch_id => lv_batch_id,
46635 p_where_str => lv_where_str,
46636 p_col_name => 'FROM_OP_EFFECTIVITY_DATE',
46637 p_debug => v_debug,
46638 p_default_value => 'SYSDATE');
46639
46640 IF lv_return <> 0 THEN
46641 RAISE ex_logging_err;
46642 END IF;
46643 */
46644
46645 -- Set the error message
46646 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
46647 (p_app_short_name => 'MSC',
46648 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
46649 p_message_text => lv_message_text,
46650 p_error_text => lv_error_text,
46651 p_token1 => 'COLUMN_NAME',
46652 p_token_value1 => 'TO_OP_EFFECTIVITY_DATE',
46653 p_token2 => 'DEFAULT_VALUE',
46654 p_token_value2 => 'SYSDATE' );
46655
46656 IF lv_return <> 0 THEN
46657 RAISE ex_logging_err;
46658 END IF;
46659
46660 -- Default to operation effectivity date as SYSDATE if NULL
46661 v_sql_stmt := 61;
46662 lv_where_str :=
46663 ' AND NVL(to_op_effectivity_date,SYSDATE-36500 ) = SYSDATE-36500 ' ;
46664
46665 lv_return := MSC_ST_UTIL.LOG_ERROR
46666 (p_table_name => 'MSC_ST_OPERATION_NETWORKS',
46667 p_instance_code => v_instance_code,
46668 p_row => lv_column_names,
46669 p_severity => G_SEV_WARNING,
46670 p_message_text => lv_message_text,
46671 p_error_text => lv_error_text,
46672 p_batch_id => lv_batch_id,
46673 p_where_str => lv_where_str,
46674 p_col_name => 'TO_OP_EFFECTIVITY_DATE',
46675 p_debug => v_debug,
46676 p_default_value => 'SYSDATE');
46677
46678 IF lv_return <> 0 THEN
46679 RAISE ex_logging_err;
46680 END IF;
46681
46682 -- Set the error message
46683 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
46684 (p_app_short_name => 'MSC',
46685 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
46686 p_message_text => lv_message_text,
46687 p_error_text => lv_error_text,
46688 p_token1 => 'COLUMN_NAME',
46689 p_token_value1 => 'EFECTIVITY_DATE',
46690 p_token2 => 'DEFAULT_VALUE',
46691 p_token_value2 => 'SYSDATE' );
46692
46693 IF lv_return <> 0 THEN
46694 RAISE ex_logging_err;
46695 END IF;
46696
46697 -- Default effectivity date as SYSDATE if NULL
46698 v_sql_stmt := 62;
46699 lv_where_str :=
46700 ' AND NVL(efectivity_date,SYSDATE-36500 ) = SYSDATE-36500 ' ;
46701
46702 lv_return := MSC_ST_UTIL.LOG_ERROR
46703 (p_table_name => 'MSC_ST_OPERATION_NETWORKS',
46704 p_instance_code => v_instance_code,
46705 p_row => lv_column_names,
46706 p_severity => G_SEV_WARNING,
46707 p_message_text => lv_message_text,
46708 p_error_text => lv_error_text,
46709 p_batch_id => lv_batch_id,
46710 p_where_str => lv_where_str,
46711 p_col_name => 'EFECTIVITY_DATE',
46712 p_debug => v_debug,
46713 p_default_value => 'SYSDATE');
46714
46715 IF lv_return <> 0 THEN
46716 RAISE ex_logging_err;
46717 END IF;
46718
46719
46720
46721 -- from_operation_seq_code or to_operation_seq_code cannot be null.
46722 -- Set the error message
46723 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
46724 (p_app_short_name => 'MSC',
46725 p_error_code => 'MSC_PP_COL_VAL_NULL',
46726 p_message_text => lv_message_text,
46727 p_error_text => lv_error_text,
46728 p_token1 => 'COLUMN_NAME',
46729 p_token_value1 => 'FROM_OPERATION_SEQ_CODE OR '
46730 ||'TO_OPERATION_SEQ_CODE');
46731
46732 IF lv_return <> 0 THEN
46733 RAISE ex_logging_err;
46734 END IF;
46735
46736 -- Error out the records whose from_operation_seq_code or to_operation_seq_code is NULL
46737
46738 v_sql_stmt := 63;
46739 lv_sql_stmt :=
46740 'UPDATE msc_st_operation_networks'
46741 ||' SET process_flag ='||G_ERROR_FLG||','
46742 ||' error_text = '||''''||lv_message_text||''''
46743 ||' WHERE ( NVL(from_operation_seq_code,'||NULL_VALUE||') ='||NULL_VALUE
46744 ||' OR NVL(to_operation_seq_code,'||NULL_VALUE||') ='||NULL_VALUE ||')'
46745 ||' AND sr_instance_code = :v_instance_code'
46746 ||' AND process_flag = '||G_IN_PROCESS
46747 ||' AND batch_id = :lv_batch_id';
46748
46749
46750 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
46751
46752 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
46753
46754
46755
46756 -- from op_seq_code and to_op_seq_codes cannot be same
46757 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
46758 (p_app_short_name => 'MSC',
46759 p_error_code => 'MSC_PP_FROM_TO_SAME',
46760 p_message_text => lv_message_text,
46761 p_error_text => lv_error_text,
46762 p_token1 => 'COLUMN_NAME',
46763 p_token_value1 => 'TO_OPERATION_SEQ_CODE');
46764
46765 IF lv_return <> 0 THEN
46766 RAISE ex_logging_err;
46767 END IF;
46768
46769 -- Error out the records whose from_operation_seq_code is same as to_op_seq_code
46770
46771 v_sql_stmt := 64;
46772 lv_sql_stmt :=
46773 'UPDATE msc_st_operation_networks'
46774 ||' SET process_flag ='||G_ERROR_FLG||','
46775 ||' error_text = '||''''||lv_message_text||''''
46776 ||' WHERE NVL(to_operation_seq_code,'||NULL_VALUE||') = NVL(from_operation_seq_code,'||NULL_VALUE||')'
46777 ||' AND sr_instance_code = :v_instance_code'
46778 ||' AND process_flag = '||G_IN_PROCESS
46779 ||' AND batch_id = :lv_batch_id';
46780
46781
46782 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
46783
46784 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
46785
46786
46787 -- Derive from_operation_sequence id
46788
46789 v_sql_stmt := 65;
46790 lv_sql_Stmt :=
46791 'UPDATE msc_st_operation_networks mson'
46792 ||' SET from_op_seq_id= (SELECT local_id'
46793 ||' FROM msc_local_id_setup mlis'
46794 ||' WHERE mlis.char1 = mson.sr_instance_code'
46795 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
46796 ||' = NVL(mson.company_name,'||''''||NULL_CHAR||''''||') '
46797 ||' AND mlis.char3 = mson.organization_code'
46798 ||' AND mlis.char4 = mson.routing_name'
46799 ||' AND mlis.char5 = mson.from_operation_seq_code'
46800 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
46801 ||' = NVL(mson.alternate_routing_designator,'||''''||NULL_CHAR||''''||')'
46802 ||' AND mlis.date1 = mson.FROM_OP_EFFECTIVITY_DATE'
46803 ||' AND mlis.entity_name = ''OPERATION_SEQUENCE_ID'' '
46804 ||' AND mlis.instance_id = '||v_instance_id||')'
46805 ||' WHERE sr_instance_code = :v_instance_code'
46806 ||' AND process_flag ='||G_IN_PROCESS
46807 ||' AND batch_id = :lv_batch_id';
46808
46809
46810 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
46811
46812 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
46813
46814
46815 -- from_op_seq_id cannot be null. Error out the records with null value for them.
46816 -- Set the error message
46817 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
46818 (p_app_short_name => 'MSC',
46819 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
46820 p_message_text => lv_message_text,
46821 p_error_text => lv_error_text,
46822 p_token1 => 'COLUMN_NAMES',
46823 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
46824 ||'ORGANIZATION_CODE,ROUTING_NAME,'
46825 ||' FROM_OPERATION_SEQ_CODE,FROM_OP_EFFECTIVITY_DATE,'
46826 ||' ALTERNATE_ROUTING_DESIGNATOR' ,
46827 p_token2 => 'MASTER_TABLE',
46828 p_token_value2 => 'MSC_ST_ROUTING_OPERATIONS',
46829 p_token3 => 'CHILD_TABLE' ,
46830 p_token_value3 => 'MSC_ST_OPERATION_NETWORKS' );
46831
46832 -- Error out the records whose from_op_seq_id is NULL
46833
46834 v_sql_stmt := 66;
46835 lv_sql_stmt :=
46836 'UPDATE msc_st_operation_networks'
46837 ||' SET process_flag ='||G_ERROR_FLG||','
46838 ||' error_text = '||''''||lv_message_text||''''
46839 ||' WHERE NVL(from_op_seq_id,'||NULL_VALUE||') ='||NULL_VALUE
46840 ||' AND sr_instance_code = :v_instance_code'
46841 ||' AND process_flag = '||G_IN_PROCESS
46842 ||' AND batch_id = :lv_batch_id';
46843
46844
46845 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
46846
46847 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
46848
46849 -- Derive to_operation_sequence id
46850
46851 v_sql_stmt := 67;
46852 lv_sql_Stmt :=
46853 'UPDATE msc_st_operation_networks mson'
46854 ||' SET to_op_seq_id= (SELECT local_id'
46855 ||' FROM msc_local_id_setup mlis'
46856 ||' WHERE mlis.char1 = mson.sr_instance_code'
46857 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
46858 ||' = NVL(mson.company_name,'||''''||NULL_CHAR||''''||') '
46859 ||' AND mlis.char3 = mson.organization_code'
46860 ||' AND mlis.char4 = mson.routing_name'
46861 ||' AND mlis.char5 = mson.to_operation_seq_code'
46862 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
46863 ||' = NVL(mson.alternate_routing_designator,'||''''||NULL_CHAR||''''||')'
46864 ||' AND mlis.date1 = mson.TO_OP_EFFECTIVITY_DATE'
46865 ||' AND mlis.entity_name = ''OPERATION_SEQUENCE_ID'' '
46866 ||' AND mlis.instance_id = '||v_instance_id||')'
46867 ||' WHERE sr_instance_code = :v_instance_code'
46868 ||' AND process_flag ='||G_IN_PROCESS
46869 ||' AND batch_id = :lv_batch_id';
46870
46871
46872 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
46873
46874 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
46875
46876
46877 -- to_op_seq_id cannot be null. Error out the records with null value for them.
46878 -- Set the error message
46879 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
46880 (p_app_short_name => 'MSC',
46881 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
46882 p_message_text => lv_message_text,
46883 p_error_text => lv_error_text,
46884 p_token1 => 'COLUMN_NAMES',
46885 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
46886 ||'ORGANIZATION_CODE,ROUTING_NAME,'
46887 ||' TO_OPERATION_SEQ_CODE,TO_OP_EFFECTIVITY_DATE,'
46888 ||' ALTERNATE_ROUTING_DESIGNATOR' ,
46889 p_token2 => 'MASTER_TABLE',
46890 p_token_value2 => 'MSC_ST_ROUTING_OPERATIONS',
46891 p_token3 => 'CHILD_TABLE' ,
46892 p_token_value3 => 'MSC_ST_OPERATION_NETWORKS' );
46893
46894 IF lv_return <> 0 THEN
46895 RAISE ex_logging_err;
46896 END IF;
46897
46898 -- Error out the records whose to_op_seq_id is NULL
46899
46900 v_sql_stmt := 68;
46901 lv_sql_stmt :=
46902 'UPDATE msc_st_operation_networks'
46903 ||' SET process_flag ='||G_ERROR_FLG||','
46904 ||' error_text = '||''''||lv_message_text||''''
46905 ||' WHERE NVL(to_op_seq_id,'||NULL_VALUE||') ='||NULL_VALUE
46906 ||' AND sr_instance_code = :v_instance_code'
46907 ||' AND process_flag = '||G_IN_PROCESS
46908 ||' AND batch_id = :lv_batch_id';
46909
46910
46911 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
46912
46913 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
46914
46915
46916 -- populating from_op_seq_num and to_op_seq_num
46917 v_sql_stmt := 69;
46918 lv_sql_Stmt :=
46919 'UPDATE msc_st_operation_networks mson'
46920 ||' SET from_op_seq_num= to_number(decode(length(rtrim(from_operation_seq_code,''0123456789'')),'
46921 ||' NULL,from_operation_seq_code,''1'')),'
46922 ||' to_op_seq_num= to_number(decode(length(rtrim(to_operation_seq_code,''0123456789'')),'
46923 ||' NULL,to_operation_seq_code,''1''))'
46924 ||' WHERE sr_instance_code = :v_instance_code'
46925 ||' AND process_flag ='||G_IN_PROCESS
46926 ||' AND deleted_flag <> 1'
46927 ||' AND batch_id = :lv_batch_id';
46928
46929
46930 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
46931
46932 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
46933
46934
46935
46936 -- Set the error message
46937 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
46938 (p_app_short_name => 'MSC',
46939 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
46940 p_message_text => lv_message_text,
46941 p_error_text => lv_error_text,
46942 p_token1 => 'COLUMN_NAME',
46943 p_token_value1 => 'TRANSITION_TYPE',
46944 p_token2 => 'DEFAULT_VALUE',
46945 p_token_value2 => G_TRANSITION_TYPE);
46946
46947 IF lv_return <> 0 THEN
46948 RAISE ex_logging_err;
46949 END IF;
46950
46951 -- Defualt transition type to 2(i.e. alternate) if not in (1,2)
46952 v_sql_stmt := 70;
46953 lv_where_str :=
46954 ' AND NVL(transition_type,'||NULL_VALUE||') NOT IN (1,2)';
46955
46956 lv_return := MSC_ST_UTIL.LOG_ERROR
46957 (p_table_name => 'MSC_ST_OPERATION_NETWORKS',
46958 p_instance_code => v_instance_code,
46959 p_row => lv_column_names,
46960 p_severity => G_SEV_WARNING,
46961 p_message_text => lv_message_text,
46962 p_error_text => lv_error_text,
46963 p_batch_id => lv_batch_id,
46964 p_where_str => lv_where_str,
46965 p_col_name => 'TRANSITION_TYPE',
46966 p_debug => v_debug,
46967 p_default_value => G_TRANSITION_TYPE);
46968
46969
46970 IF lv_return <> 0 THEN
46971 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,lv_error_text);
46972 END IF;
46973
46974 -- Set the error message
46975 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
46976 (p_app_short_name => 'MSC',
46977 p_error_code => 'MSC_PP_END_GT_ST_DATE',
46978 p_message_text => lv_message_text,
46979 p_error_text => lv_error_text,
46980 p_token1 => 'COLUMN_NAME',
46981 p_token_value1 => 'EFFECTIVITY_DATE');
46982
46983 IF lv_return <> 0 THEN
46984 RAISE ex_logging_err;
46985 END IF;
46986
46987 -- Disable date should be greater than effectivity date if a value is there for disable date
46988
46989 v_sql_stmt := 71;
46990 lv_sql_stmt :=
46991 'UPDATE msc_st_operation_networks'
46992 ||' SET process_flag ='||G_ERROR_FLG||','
46993 ||' error_text = '||''''||lv_message_text||''''
46994 ||' WHERE NVL(DISABLE_DATE,SYSDATE-36500) <> SYSDATE-36500'
46995 ||' AND DISABLE_DATE <= EFECTIVITY_DATE '
46996 ||' AND sr_instance_code = :v_instance_code'
46997 ||' AND process_flag = '||G_IN_PROCESS
46998 ||' AND deleted_flag <> 1'
46999 ||' AND batch_id = :lv_batch_id';
47000
47001
47002 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
47003
47004 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
47005
47006
47007 --Call to customised validation.
47008
47009 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
47010 (ERRBUF => lv_error_text,
47011 RETCODE => lv_return,
47012 pBatchID => lv_batch_id,
47013 pInstanceCode => v_instance_code,
47014 pEntityName => 'MSC_ST_OPERATION_NETWORKS',
47015 pInstanceID => v_instance_id);
47016
47017 IF NVL(lv_return,0) <> 0 THEN
47018 RAISE ex_logging_err;
47019 END IF;
47020
47021 COMMIT;
47022 END LOOP;
47023
47024 -- There should be at the max only one primary path from a from_operation_seq_code
47025 -- Else error out all the records for that from_operation_seq_code
47026
47027 -- Set the error message
47028 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
47029 (p_app_short_name => 'MSC',
47030 p_error_code => 'MSC_PP_MULTI_PRI_PATH',
47031 p_message_text => lv_message_text,
47032 p_error_text => lv_error_text,
47033 p_token1 => 'COLUMN_NAME',
47034 p_token_value1 => 'TRANSITION_TYPE');
47035
47036 IF lv_return <> 0 THEN
47037 RAISE ex_logging_err;
47038 END IF;
47039
47040 v_sql_stmt := 72;
47041 lv_sql_stmt :=
47042 'UPDATE msc_st_operation_networks mson1'
47043 ||' SET process_flag = '||G_ERROR_FLG||','
47044 ||' error_text = '||''''||lv_message_text||''''
47045 ||' WHERE 1 < ( SELECT COUNT(*) '
47046 ||' FROM msc_st_operation_networks mson2'
47047 ||' WHERE mson2.assembly_name = mson1.assembly_name'
47048 ||' AND mson2.organization_code = mson1.organization_code'
47049 ||' AND mson2.from_operation_seq_code = mson1.from_operation_seq_code'
47050 ||' AND mson2.sr_instance_code = mson1.sr_instance_code'
47051 ||' AND NVL(mson2.company_name,'||''''||NULL_CHAR||''''||') '
47052 ||' = NVL(mson1.company_name,'||''''||NULL_CHAR||''''||') '
47053 ||' AND mson2.transition_type = 1 '
47054 ||' AND NVL(mson2.routing_name,'||''''||NULL_CHAR||''''||') '
47055 ||' = NVL(mson1.routing_name, '||''''||NULL_CHAR||''''||') '
47056 ||' AND NVL(mson2.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
47057 ||' = NVL(mson1.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
47058 ||' AND mson2.process_flag ='||G_IN_PROCESS
47059 ||' AND mson2.deleted_flag <>1 '
47060 ||' GROUP BY sr_instance_code,company_name,organization_code,from_operation_seq_code,'
47061 ||' routing_name,assembly_name, alternate_routing_designator )'
47062 ||' AND mson1.process_flag = '||G_IN_PROCESS
47063 ||' AND mson1.deleted_flag <>1 '
47064 ||' AND mson1.sr_instance_code = :v_instance_code';
47065
47066
47067
47068 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
47069
47070 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
47071
47072 -- The summation of the planning_pct's from a from_operation_sed_code should be exactly 100.
47073 -- Else error out all the records for that from_operation_seq_code
47074
47075 -- Set the error message
47076 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
47077 (p_app_short_name => 'MSC',
47078 p_error_code => 'MSC_INVALID_PLANNING_PCT',
47079 p_message_text => lv_message_text,
47080 p_error_text => lv_error_text,
47081 p_token1 => 'COLUMN_NAME',
47082 p_token_value1 => 'PLANNING_PCT');
47083
47084 IF lv_return <> 0 THEN
47085 RAISE ex_logging_err;
47086 END IF;
47087
47088 v_sql_stmt := 73;
47089 lv_sql_stmt :=
47090 'UPDATE msc_st_operation_networks mson1'
47091 ||' SET process_flag = '||G_ERROR_FLG||','
47092 ||' error_text = '||''''||lv_message_text||''''
47093 ||' WHERE 100 <> ( SELECT SUM(planning_pct) '
47094 ||' FROM msc_st_operation_networks mson2'
47095 ||' WHERE mson2.assembly_name = mson1.assembly_name'
47096 ||' AND mson2.organization_code = mson1.organization_code'
47097 ||' AND mson2.from_operation_seq_code = mson1.from_operation_seq_code'
47098 ||' AND mson2.sr_instance_code = mson1.sr_instance_code'
47099 ||' AND NVL(mson2.company_name,'||''''||NULL_CHAR||''''||') '
47100 ||' = NVL(mson1.company_name,'||''''||NULL_CHAR||''''||') '
47101 ||' AND NVL(mson2.routing_name,'||''''||NULL_CHAR||''''||') '
47102 ||' = NVL(mson1.routing_name, '||''''||NULL_CHAR||''''||') '
47103 ||' AND NVL(mson2.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
47104 ||' = NVL(mson1.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
47105 ||' AND mson2.process_flag ='||G_IN_PROCESS
47106 ||' AND mson2.deleted_flag <>1 '
47107 ||' GROUP BY sr_instance_code,company_name,organization_code,from_operation_seq_code,'
47108 ||' routing_name,assembly_name, alternate_routing_designator )'
47109 ||' AND mson1.process_flag = '||G_IN_PROCESS
47110 ||' AND mson1.deleted_flag <>1 '
47111 ||' AND mson1.sr_instance_code = :v_instance_code';
47112
47113
47114 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
47115
47116 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
47117
47118 -- Set the process flag as Valid and derive sr_instance_id
47119 lv_return :=
47120 MSC_ST_UTIL.SET_PROCESS_FLAG(p_table_name => 'MSC_ST_OPERATION_NETWORKS',
47121 p_instance_id => v_instance_id,
47122 p_instance_code => v_instance_code,
47123 p_process_flag => G_VALID,
47124 p_error_text => lv_error_text,
47125 p_debug => v_debug);
47126
47127 IF lv_return < 0 THEN
47128 RAISe ex_logging_err;
47129 END IF;
47130
47131
47132 -- At the end calling the LOG_ERROR for logging all errored out records
47133
47134 lv_return :=
47135 MSC_ST_UTIL.LOG_ERROR(p_table_name => 'MSC_ST_OPERATION_NETWORKS',
47136 p_instance_code => v_instance_code,
47137 p_row => lv_column_names,
47138 p_severity => G_SEV_ERROR,
47139 p_message_text => NULL,
47140 p_error_text => lv_error_text,
47141 p_debug => v_debug );
47142
47143 IF lv_return < 0 THEN
47144 RAISe ex_logging_err;
47145 END IF;
47146
47147 -- till here added for pre processing Opertion Networks (OSFM Integration)
47148
47149
47150 EXCEPTION
47151 WHEN too_many_rows THEN
47152 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_ROUTING'||'('
47153 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
47154 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
47155 ROLLBACK ;
47156
47157 WHEN ex_logging_err THEN
47158 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
47159 ROLLBACK;
47160
47161 WHEN OTHERS THEN
47162 lv_error_text :=substr('MSC_CL_PRE_PROCESS.LOAD_ROUTING'||'('
47163 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
47164 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
47165 ROLLBACK;
47166
47167 END LOAD_ROUTING ;
47168
47169
47170 /*==========================================================================+
47171 | DESCRIPTION : This function inserts records into process effectivity |
47172 +==========================================================================*/
47173
47174 PROCEDURE LOAD_PROCESS_EFFECTIVITY IS
47175
47176 lv_error_text VARCHAR2(250);
47177 lv_sql_stmt VARCHAR2(5000);
47178
47179
47180 BEGIN
47181 -- populating preference for the bugfix 2862276
47182 v_sql_stmt := 1;
47183 lv_sql_stmt :=
47184 'INSERT INTO msc_st_process_effectivity'
47185 ||'( item_id,'
47186 ||' organization_id,'
47187 ||' bill_sequence_id,'
47188 ||' routing_sequence_id,'
47189 ||' effectivity_date,'
47190 ||' line_id,'
47191 ||' preference,'
47192 ||' deleted_flag,'
47193 ||' sr_instance_id,'
47194 ||' refresh_id, '
47195 ||' ITEM_PROCESS_COST,'
47196 ||' last_update_date,'
47197 ||' last_updated_by, '
47198 ||' creation_date,'
47199 ||' created_by )'
47200 ||' SELECT '
47201 ||' assembly_item_id,'
47202 ||' organization_id,'
47203 ||' bill_sequence_id,'
47204 ||' routing_sequence_id,'
47205 ||' sysdate,'
47206 || NULL_VALUE||','
47207 ||' decode(alternate_bom_designator,NULL, DECODE( alternate_routing_designator,NULL, 1,2),2),'
47208 ||' deleted_flag,'
47209 || v_instance_id||','
47210 ||' REFRESH_ID,'
47211 ||' ITEM_PROCESS_COST ,'
47212 ||' last_update_date,'
47213 ||' last_updated_by, '
47214 ||' creation_date,'
47215 ||' created_by '
47216 ||' FROM msc_st_routings'
47217 ||' WHERE sr_instance_id = :v_instance_id';
47218
47219
47220
47221
47222 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
47223
47224 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_id;
47225
47226
47227
47228 v_sql_stmt := 2;
47229 lv_sql_stmt :=
47230 'INSERT INTO msc_st_process_effectivity'
47231 ||'( item_id,'
47232 ||' organization_id,'
47233 ||' bill_sequence_id,'
47234 ||' effectivity_date,'
47235 ||' line_id,'
47236 ||' preference,'
47237 ||' deleted_flag,'
47238 ||' sr_instance_id,'
47239 ||' refresh_id,'
47240 ||' ITEM_PROCESS_COST,'
47241 ||' last_update_date,'
47242 ||' last_updated_by, '
47243 ||' creation_date,'
47244 ||' created_by )'
47245 ||' SELECT '
47246 ||' assembly_item_id,'
47247 ||' organization_id,'
47248 ||' bill_sequence_id,'
47249 ||' sysdate,'
47250 || NULL_VALUE||','
47251 ||' decode(msb.alternate_bom_designator,NULL,1,2),'
47252 ||' deleted_flag,'
47253 || v_instance_id||','
47254 ||' REFRESH_ID,'
47255 ||' ITEM_PROCESS_COST ,'
47256 ||' last_update_date,'
47257 ||' last_updated_by, '
47258 ||' creation_date,'
47259 ||' created_by '
47260 ||' FROM msc_st_boms msb'
47261 ||' WHERE sr_instance_id = :v_instance_id'
47262 ||' AND NOT EXISTS ( SELECT 1 from msc_st_routings msr '
47263 ||' WHERE msr.bill_sequence_id = msb.bill_sequence_id '
47264 ||' AND msr.sr_instance_id = msb.sr_instance_id )';
47265
47266
47267 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
47268
47269 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_id;
47270
47271
47272 COMMIT;
47273
47274 EXCEPTION
47275 WHEN OTHERS THEN
47276 ROLLBACK;
47277 lv_error_text :=substr('MSC_CL_PRE_PROCESS.LOAD_PROCESS_EFFECTIVITY'||'('
47278 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
47279 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
47280
47281 END LOAD_PROCESS_EFFECTIVITY ;
47282
47283
47284 /*==========================================================================+
47285 | DESCRIPTION : This procedure validates Work Order supply related reocrds |
47286 | in the msc_st_supplies table. Order_types considered are |
47287 | Supply Source Order Type |
47288 | -------------------------------------------- |
47289 | Discrete Job 3 |
47290 | Non-Standard Job 7 |
47291 | Flow Schedule 27 |
47292 | Discrete job by-product 14 |
47293 | Nonstandard job by-product 15 |
47294 +==========================================================================*/
47295 PROCEDURE LOAD_WO_SUPPLY IS
47296 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
47297 lb_rowid RowidTab;
47298 lv_return NUMBER;
47299 lv_error_text VARCHAR2(250);
47300 lv_where_str VARCHAR2(5000);
47301 lv_sql_stmt VARCHAR2(5000);
47302 lv_column_names VARCHAR2(5000); --stores concatenated column names
47303 lv_message_text msc_errors.error_text%TYPE;
47304 lv_batch_id msc_st_supplies.batch_id%TYPE;
47305 ex_logging_err EXCEPTION;
47306
47307 CURSOR c1(p_batch_id NUMBER) IS
47308 SELECT rowid
47309 FROM msc_st_supplies
47310 WHERE order_type IN(3,7,27,14,15)
47311 AND process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
47312 AND NVL(batch_id,NULL_VALUE)=p_batch_id
47313 AND sr_instance_code = v_instance_code;
47314
47315 CURSOR c2(p_batch_id NUMBER) IS
47316 SELECT rowid
47317 FROM msc_st_supplies
47318 WHERE NVL(wip_entity_id,NULL_VALUE) = NULL_VALUE
47319 AND process_flag = G_IN_PROCESS
47320 AND NVL(batch_id,NULL_VALUE) =p_batch_id
47321 AND sr_instance_code = v_instance_code;
47322
47323 CURSOR c3(p_batch_id NUMBER) IS
47324 SELECT max(rowid)
47325 FROM msc_st_supplies
47326 WHERE NVL(schedule_group_id,NULL_VALUE) = NULL_VALUE
47327 AND deleted_flag = SYS_NO
47328 AND process_flag = G_IN_PROCESS
47329 AND NVL(batch_id,NULL_VALUE) = p_batch_id
47330 AND sr_instance_code = v_instance_code
47331 GROUP BY sr_instance_code,company_name,organization_code,schedule_group_name;
47332
47333 CURSOR c4(p_batch_id NUMBER) IS
47334 SELECT rowid
47335 FROM msc_st_supplies
47336 WHERE process_flag = G_IN_PROCESS
47337 AND sr_instance_code = v_instance_code
47338 AND batch_id = p_batch_id
47339 AND NVL(JOB_OP_SEQ_NUM, NULL_VALUE) = NULL_VALUE
47340 AND NVL(JOB_OP_SEQ_CODE, NULL_CHAR) <> NULL_CHAR
47341 AND order_type IN (3,7,14,15)
47342 AND deleted_flag = SYS_NO;
47343
47344 BEGIN
47345
47346 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
47347 (p_app_short_name => 'MSC',
47348 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
47349 p_message_text => lv_message_text,
47350 p_error_text => lv_error_text);
47351
47352 IF lv_return <> 0 THEN
47353 RAISE ex_logging_err;
47354 END IF;
47355
47356 --Duplicate records check for the records whose source is XML for
47357 --WO supplies
47358 v_sql_stmt := 01;
47359 lv_sql_stmt :=
47360 'UPDATE msc_st_supplies mss1'
47361 ||' SET process_flag = '||G_ERROR_FLG||','
47362 ||' error_text = '||''''||lv_message_text||''''
47363 ||' WHERE message_id < (SELECT MAX(message_id)'
47364 ||' FROM msc_st_supplies mss2'
47365 ||' WHERE mss2.sr_instance_code'
47366 ||' = mss1.sr_instance_code'
47367 ||' AND NVL(mss2.company_name,'||''''||NULL_CHAR||''''||') = '
47368 ||' NVL(mss1.company_name,'||''''||NULL_CHAR||''''||')'
47369 ||' AND mss2.wip_entity_name = mss1.wip_entity_name '
47370 ||' AND mss2.order_type = mss1.order_type'
47371 ||' AND mss2.process_flag = '||G_IN_PROCESS
47372 ||' AND mss2.organization_code = mss1.organization_code'
47373 ||' AND NVL(mss2.message_id,'||NULL_VALUE||')<>'||NULL_VALUE||')'
47374 ||' AND mss1.order_type IN(3,7,27,14,15)'
47375 ||' AND mss1.process_flag = '||G_IN_PROCESS
47376 ||' AND mss1.sr_instance_code = :v_instance_code'
47377 ||' AND NVL(mss1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
47378
47379
47380 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
47381
47382 EXECUTE IMMEDIATE lv_sql_stmt
47383 USING v_instance_code;
47384
47385
47386 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
47387 (p_app_short_name => 'MSC',
47388 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
47389 p_message_text => lv_message_text,
47390 p_error_text => lv_error_text);
47391
47392 IF lv_return <> 0 THEN
47393 RAISE ex_logging_err;
47394 END IF;
47395
47396 --Duplicate records check for the records whose source is other than XML
47397 --Different SQL is used because in XML we can identify the latest records
47398 --whereas in batch load we cannot.
47399 v_sql_stmt := 02;
47400 lv_sql_stmt :=
47401 'UPDATE msc_st_supplies mss1 '
47402 ||' SET process_flag = '||G_ERROR_FLG||','
47403 ||' error_text = '||''''||lv_message_text||''''
47404 ||' WHERE EXISTS( SELECT 1 '
47405 ||' FROM msc_st_supplies mss2'
47406 ||' WHERE mss2.sr_instance_code'
47407 ||' = mss1.sr_instance_code'
47408 ||' AND NVL(mss2.company_name, '||''''||NULL_CHAR||''''||')= '
47409 ||' NVL(mss1.company_name, '||''''||NULL_CHAR||''''||')'
47410 ||' AND mss2.wip_entity_name = mss1.wip_entity_name '
47411 ||' AND mss2.order_type = mss1.order_type'
47412 ||' AND mss2.process_flag = '||G_IN_PROCESS
47413 ||' AND mss2.organization_code = mss1.organization_code'
47414 ||' AND NVL(mss2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
47415 ||' GROUP BY sr_instance_code,wip_entity_name,organization_code,company_name,'
47416 ||' order_type'
47417 ||' HAVING COUNT(*) > 1)'
47418 ||' AND mss1.order_type IN (3,7,27,14,15)'
47419 ||' AND mss1.process_flag = '||G_IN_PROCESS
47420 ||' AND mss1.sr_instance_code = :v_instance_code'
47421 ||' AND NVL(mss1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
47422
47423
47424 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
47425
47426 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
47427
47428 lv_column_names :=
47429 'ITEM_NAME ||''~''||'
47430 ||'ORGANIZATION_CODE ||''~''||'
47431 ||'NEW_SCHEDULE_DATE ||''~''||'
47432 ||'FIRM_PLANNED_TYPE ||''~''||'
47433 ||'WIP_ENTITY_NAME ||''~''||'
47434 ||'SR_INSTANCE_CODE ||''~''||'
47435 ||'REVISION ||''~''||'
47436 ||'UNIT_NUMBER ||''~''||'
47437 ||'NEW_WIP_START_DATE ||''~''||'
47438 ||'NEW_ORDER_QUANTITY ||''~''||'
47439 ||'ALTERNATE_BOM_DESIGNATOR ||''~''||'
47440 ||'ALTERNATE_ROUTING_DESIGNATOR ||''~''||'
47441 ||'LINE_CODE ||''~''||'
47442 ||'PROJECT_NUMBER ||''~''||'
47443 ||'TASK_NUMBER ||''~''||'
47444 ||'PLANNING_GROUP ||''~''||'
47445 ||'SCHEDULE_GROUP_NAME ||''~''||'
47446 ||'BUILD_SEQUENCE ||''~''||'
47447 ||'WO_LATENESS_COST ||''~''||'
47448 ||'IMPLEMENT_PROCESSING_DAYS ||''~''||'
47449 ||'LATE_SUPPLY_DATE ||''~''||'
47450 ||'LATE_SUPPLY_QTY ||''~''||'
47451 ||'QTY_SCRAPPED ||''~''||'
47452 ||'QTY_COMPLETED ||''~''||'
47453 ||'WIP_STATUS_CODE ||''~''||'
47454 ||'BILL_NAME ||''~''||'
47455 ||'ROUTING_NAME ||''~''||'
47456 ||'DELETED_FLAG ||''~''||'
47457 ||'COMPANY_NAME ||''~''||'
47458 ||'ORDER_TYPE ||''~''||'
47459 ||'ORDER_NUMBER';
47460
47461 LOOP
47462 v_sql_stmt := 03;
47463 SELECT msc_st_batch_id_s.NEXTVAL
47464 INTO lv_batch_id
47465 FROM dual;
47466
47467 v_sql_stmt := 04;
47468 lv_sql_stmt :=
47469 ' UPDATE msc_st_supplies '
47470 ||' SET batch_id = :lv_batch_id'
47471 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
47472 ||' AND order_type IN(3,7,27,14,15)'
47473 ||' AND sr_instance_code = :v_instance_code'
47474 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
47475 ||' AND rownum <= '||v_batch_size;
47476
47477
47478 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
47479
47480 EXECUTE IMMEDIATE lv_sql_stmt
47481 USING lv_batch_id,
47482 v_instance_code;
47483
47484 EXIT WHEN SQL%NOTFOUND;
47485
47486 OPEN c1(lv_batch_id);
47487 FETCH c1 BULK COLLECT INTO lb_rowid;
47488 CLOSE c1;
47489
47490 v_sql_stmt := 03;
47491 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
47492 UPDATE msc_st_supplies
47493 SET st_transaction_id = msc_st_supplies_s.NEXTVAL,
47494 refresh_id = v_refresh_id,
47495 last_update_date = v_current_date,
47496 last_updated_by = v_current_user,
47497 creation_date = v_current_date,
47498 created_by = v_current_user
47499 WHERE rowid = lb_rowid(j);
47500
47501 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
47502 (p_app_short_name => 'MSC',
47503 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
47504 p_message_text => lv_message_text,
47505 p_error_text => lv_error_text,
47506 p_token1 => 'COLUMN_NAME',
47507 p_token_value1 => 'DELETED_FLAG',
47508 p_token2 => 'DEFAULT_VALUE',
47509 p_token_value2 => SYS_NO);
47510
47511 IF lv_return <> 0 THEN
47512 RAISE ex_logging_err;
47513 END IF;
47514
47515 lv_where_str :=
47516 ' AND NVL(deleted_flag,'||NULL_VALUE||') NOT IN(1,2)';
47517 --Log a warning for those records where the deleted_flag has a value other
47518 --SYS_NO
47519 lv_return := MSC_ST_UTIL.LOG_ERROR
47520 (p_table_name => 'MSC_ST_SUPPLIES',
47521 p_instance_code => v_instance_code,
47522 p_row => lv_column_names,
47523 p_severity => G_SEV_WARNING,
47524 p_message_text => lv_message_text,
47525 p_error_text => lv_error_text,
47526 p_batch_id => lv_batch_id,
47527 p_where_str => lv_where_str,
47528 p_col_name => 'DELETED_FLAG',
47529 p_debug => v_debug,
47530 p_default_value => SYS_NO);
47531
47532 IF lv_return <> 0 THEN
47533 RAISE ex_logging_err;
47534 END IF;
47535
47536 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
47537 (p_app_short_name => 'MSC',
47538 p_error_code => 'MSC_PP_INVALID_VALUE',
47539 p_message_text => lv_message_text,
47540 p_error_text => lv_error_text,
47541 p_token1 => 'COLUMN_NAME',
47542 p_token_value1 => 'ORGANIZATION_CODE');
47543
47544 IF lv_return <> 0 THEN
47545 RAISE ex_logging_err;
47546 END IF;
47547
47548 --Derive Organization_id
47549 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
47550 (p_table_name => 'MSC_ST_SUPPLIES',
47551 p_org_partner_name => 'ORGANIZATION_CODE',
47552 p_org_partner_id => 'ORGANIZATION_ID',
47553 p_instance_code => v_instance_code,
47554 p_partner_type => G_ORGANIZATION,
47555 p_error_text => lv_error_text,
47556 p_batch_id => lv_batch_id,
47557 p_severity => G_SEV_ERROR,
47558 p_message_text => lv_message_text,
47559 p_debug => v_debug,
47560 p_row => lv_column_names);
47561
47562 IF lv_return <> 0 THEN
47563 RAISE ex_logging_err;
47564 END IF;
47565
47566 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
47567 (p_app_short_name => 'MSC',
47568 p_error_code => 'MSC_PP_INVALID_VALUE',
47569 p_message_text => lv_message_text,
47570 p_error_text => lv_error_text,
47571 p_token1 => 'COLUMN_NAME',
47572 p_token_value1 => 'ITEM_NAME');
47573
47574 IF lv_return <> 0 THEN
47575 RAISE ex_logging_err;
47576 END IF;
47577
47578 --Derive Inventory_item_id
47579 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
47580 (p_table_name => 'MSC_ST_SUPPLIES',
47581 p_item_col_name => 'ITEM_NAME',
47582 p_item_col_id => 'INVENTORY_ITEM_ID',
47583 p_instance_id => v_instance_id,
47584 p_instance_code => v_instance_code,
47585 p_error_text => lv_error_text,
47586 p_batch_id => lv_batch_id,
47587 p_severity => G_SEV_ERROR,
47588 p_message_text => lv_message_text,
47589 p_debug => v_debug,
47590 p_row => lv_column_names);
47591
47592 IF lv_return <> 0 THEN
47593 RAISE ex_logging_err;
47594 END IF;
47595
47596 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
47597 (p_app_short_name => 'MSC',
47598 p_error_code => 'MSC_PP_COL_VAL_NULL',
47599 p_message_text => lv_message_text,
47600 p_error_text => lv_error_text,
47601 p_token1 => 'COLUMN_NAME',
47602 p_token_value1 => 'NEW_SCHEDULE_DATE OR NEW_ORDER_QUANTITY');
47603
47604 IF lv_return <> 0 THEN
47605 RAISE ex_logging_err;
47606 END IF;
47607
47608 v_sql_stmt := 04;
47609 lv_sql_stmt :=
47610 'UPDATE msc_st_supplies '
47611 ||' SET error_text = '||''''||lv_message_text||''''||','
47612 ||' process_flag = '||G_ERROR_FLG
47613 ||' WHERE (NVL(new_schedule_date,sysdate-36500) = sysdate-36500'
47614 ||' OR NVL(new_order_quantity,'||NULL_VALUE|| ')= '||NULL_VALUE||')'
47615 ||' AND deleted_flag = '||SYS_NO
47616 ||' AND process_flag = '||G_IN_PROCESS
47617 ||' AND NVL(batch_id,'||NULL_VALUE||') = :lv_batch_id'
47618 ||' AND sr_instance_code = :v_instance_code';
47619
47620
47621 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
47622
47623 EXECUTE IMMEDIATE lv_sql_stmt
47624 USING lv_batch_id,
47625 v_instance_code;
47626
47627 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
47628 (p_app_short_name => 'MSC',
47629 p_error_code => 'MSC_PP_COL_VAL_NULL',
47630 p_message_text => lv_message_text,
47631 p_error_text => lv_error_text,
47632 p_token1 => 'COLUMN_NAME',
47633 p_token_value1 => 'WIP_ENTITY_NAME');
47634
47635 IF lv_return <> 0 THEN
47636 RAISE ex_logging_err;
47637 END IF;
47638
47639 v_sql_stmt := 05;
47640 lv_sql_stmt :=
47641 'UPDATE msc_st_supplies '
47642 ||' SET error_text = '||''''||lv_message_text||''''||','
47643 ||' process_flag = '||G_ERROR_FLG
47644 ||' WHERE NVL(wip_entity_name,'||''''||NULL_CHAR||''''||') '
47645 ||' = '||''''||NULL_CHAR||''''
47646 ||' AND process_flag = '||G_IN_PROCESS
47647 ||' AND NVL(batch_id,'||NULL_VALUE||')= :lv_batch_id'
47648 ||' AND sr_instance_code = :v_instance_code';
47649
47650
47651 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
47652
47653 EXECUTE IMMEDIATE lv_sql_stmt
47654 USING lv_batch_id,
47655 v_instance_code;
47656
47657 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
47658 (p_app_short_name => 'MSC',
47659 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
47660 p_message_text => lv_message_text,
47661 p_error_text => lv_error_text,
47662 p_token1 => 'COLUMN_NAME',
47663 p_token_value1 => 'FIRM_PLANNED_TYPE',
47664 p_token2 => 'DEFAULT_VALUE',
47665 p_token_value2 => SYS_NO);
47666
47667 IF lv_return <> 0 THEN
47668 RAISE ex_logging_err;
47669 END IF;
47670
47671 lv_where_str :=
47672 ' AND NVL(firm_planned_type,'||NULL_VALUE||') NOT IN(1,2)'
47673 ||' AND deleted_flag = '||SYS_NO;
47674
47675 --Log a warning for those records where the firm_planned_type has a value
47676 --other than 1 and 2
47677
47678 lv_return := MSC_ST_UTIL.LOG_ERROR
47679 (p_table_name => 'MSC_ST_SUPPLIES',
47680 p_instance_code => v_instance_code,
47681 p_row => lv_column_names,
47682 p_severity => G_SEV_WARNING,
47683 p_message_text => lv_message_text,
47684 p_error_text => lv_error_text,
47685 p_batch_id => lv_batch_id,
47686 p_where_str => lv_where_str,
47687 p_col_name => 'FIRM_PLANNED_TYPE',
47688 p_debug => v_debug,
47689 p_default_value => SYS_NO);
47690
47691 IF lv_return <> 0 THEN
47692 RAISE ex_logging_err;
47693 END IF;
47694
47695 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
47696 (p_app_short_name => 'MSC',
47697 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
47698 p_message_text => lv_message_text,
47699 p_error_text => lv_error_text,
47700 p_token1 => 'COLUMN_NAME',
47701 p_token_value1 => 'WIP_STATUS_CODE',
47702 p_token2 => 'DEFAULT_VALUE',
47703 p_token_value2 => 1);
47704
47705 IF lv_return <> 0 THEN
47706 RAISE ex_logging_err;
47707 END IF;
47708
47709 lv_where_str := ' AND wip_status_code <= 1'
47710 ||' AND wip_status_code >= 15'
47711 ||' AND deleted_flag = '||SYS_NO;
47712
47713 --Log a warning for those records where the wip_status_code has a value other
47714 --than SYS_NO
47715
47716 lv_return := MSC_ST_UTIL.LOG_ERROR
47717 (p_table_name => 'MSC_ST_SUPPLIES',
47718 p_instance_code => v_instance_code,
47719 p_row => lv_column_names,
47720 p_severity => G_SEV_WARNING,
47721 p_message_text => lv_message_text,
47722 p_error_text => lv_error_text,
47723 p_batch_id => lv_batch_id,
47724 p_where_str => lv_where_str,
47725 p_col_name => 'WIP_STATUS_CODE',
47726 p_debug => v_debug,
47727 p_default_value => 1);
47728
47729 IF lv_return <> 0 THEN
47730 RAISE ex_logging_err;
47731 END IF;
47732
47733 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
47734 (p_app_short_name => 'MSC',
47735 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
47736 p_message_text => lv_message_text,
47737 p_error_text => lv_error_text,
47738 p_token1 => 'COLUMN_NAME',
47739 p_token_value1 => 'DISPOSITION_STATUS_TYPE',
47740 p_token2 => 'DEFAULT_VALUE',
47741 p_token_value2 => 1);
47742
47743 IF lv_return <> 0 THEN
47744 RAISE ex_logging_err;
47745 END IF;
47746
47747 lv_where_str :=
47748 ' AND NVL(disposition_status_type,'||NULL_VALUE||') NOT IN(1,2)'
47749 ||' AND deleted_flag = '||SYS_NO;
47750
47751 --Log a warning for those records where the firm_planned_type has a value other
47752 --than SYS_NO
47753
47754 lv_return := MSC_ST_UTIL.LOG_ERROR
47755 (p_table_name => 'MSC_ST_SUPPLIES',
47756 p_instance_code => v_instance_code,
47757 p_row => lv_column_names,
47758 p_severity => G_SEV_WARNING,
47759 p_message_text => lv_message_text,
47760 p_error_text => lv_error_text,
47761 p_batch_id => lv_batch_id,
47762 p_where_str => lv_where_str,
47763 p_col_name => 'DISPOSITION_STATUS_TYPE',
47764 p_debug => v_debug,
47765 p_default_value => 1);
47766
47767 IF lv_return <> 0 THEN
47768 RAISE ex_logging_err;
47769 END IF;
47770
47771 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
47772 (p_app_short_name => 'MSC',
47773 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
47774 p_message_text => lv_message_text,
47775 p_error_text => lv_error_text,
47776 p_token1 => 'COLUMN_NAME',
47777 p_token_value1 => 'WIP_SUPPLY_TYPE',
47778 p_token2 => 'DEFAULT_VALUE',
47779 p_token_value2 => 1);
47780
47781 IF lv_return <> 0 THEN
47782 RAISE ex_logging_err;
47783 END IF;
47784
47785 lv_where_str := ' AND wip_supply_type <= 1'
47786 ||' AND wip_supply_type >= 7'
47787 ||' AND deleted_flag = '||SYS_NO;
47788
47789 --Log a warning for those records where the wip_supply_type has a value other
47790 --than SYS_NO
47791
47792 lv_return := MSC_ST_UTIL.LOG_ERROR
47793 (p_table_name => 'MSC_ST_SUPPLIES',
47794 p_instance_code => v_instance_code,
47795 p_row => lv_column_names,
47796 p_severity => G_SEV_WARNING,
47797 p_message_text => lv_message_text,
47798 p_error_text => lv_error_text,
47799 p_batch_id => lv_batch_id,
47800 p_where_str => lv_where_str,
47801 p_col_name => 'WIP_SUPPLY_TYPE',
47802 p_debug => v_debug,
47803 p_default_value => 1);
47804
47805 IF lv_return <> 0 THEN
47806 RAISE ex_logging_err;
47807 END IF;
47808
47809 v_sql_stmt := 06;
47810 lv_sql_stmt :=
47811 'UPDATE msc_st_supplies'
47812 ||' SET order_number = wip_entity_name'
47813 ||' WHERE NVL(order_number,'||''''||NULL_CHAR||''''||')'
47814 ||' = '||''''||NULL_CHAR||''''
47815 ||' AND deleted_flag = '||SYS_NO
47816 ||' AND process_flag = '||G_IN_PROCESS
47817 ||' AND NVL(batch_id,'||NULL_VALUE||') = :lv_batch_id'
47818 ||' AND sr_instance_code = :v_instance_code';
47819
47820
47821 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
47822
47823 EXECUTE IMMEDIATE lv_sql_stmt
47824 USING lv_batch_id,
47825 v_instance_code;
47826
47827 -- Now we will check whether BOM Name is NULL , if it is NULL we will populate the
47828 -- ASSEMBLY NAME in BOM NAME column for all such records
47829
47830 v_sql_stmt := 07;
47831 lv_sql_stmt :=
47832 'UPDATE msc_st_supplies '
47833 ||' SET bill_name = item_name'
47834 ||' WHERE sr_instance_code = :v_instance_code'
47835 ||' AND order_type in (3, 14)'
47836 ||' AND process_flag ='||G_IN_PROCESS
47837 ||' AND NVL(bill_name,'||''''||NULL_CHAR||''''||') '
47838 ||' = '||''''||NULL_CHAR||''''
47839 ||' AND NVL(item_name,'||''''||NULL_CHAR||''''||') '
47840 ||' <> '||''''||NULL_CHAR||''''
47841 ||' AND batch_id = :lv_batch_id';
47842
47843
47844 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
47845
47846 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
47847
47848 -- Now check whether Routing Name is NULL , if it is NULL we will populate
47849 -- Assembly Name in Routing Name column for all such records
47850
47851 v_sql_stmt := 08;
47852
47853 lv_sql_stmt :=
47854 'UPDATE msc_st_supplies '
47855 ||' SET routing_name = item_name'
47856 ||' WHERE sr_instance_code = :v_instance_code'
47857 ||' AND order_type in (3, 14)'
47858 ||' AND process_flag ='|| G_IN_PROCESS
47859 ||' AND NVL(routing_name,'||''''||NULL_CHAR||''''||') '
47860 ||' = '||''''||NULL_CHAR||''''
47861 ||' AND NVL(item_name, '||''''||NULL_CHAR||''''||') '
47862 ||' <> '||''''||NULL_CHAR||''''
47863 ||' AND batch_id = :lv_batch_id ';
47864
47865
47866 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
47867
47868 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
47869
47870 lv_return := MSC_ST_UTIL.DERIVE_BILL_SEQUENCE_ID
47871 (p_table_name => 'MSC_ST_SUPPLIES',
47872 p_bom_col_name => 'BILL_NAME',
47873 p_bom_col_id => 'BILL_SEQUENCE_ID',
47874 p_instance_code => v_instance_code,
47875 p_batch_id => lv_batch_id,
47876 p_debug => v_debug,
47877 p_error_text => lv_error_text);
47878
47879
47880 IF (lv_return <> 0 ) THEN
47881 RAISE ex_logging_err;
47882 END IF;
47883
47884 lv_return := MSC_ST_UTIL.DERIVE_ROUTING_SEQUENCE_ID
47885 (p_table_name => 'MSC_ST_SUPPLIES',
47886 p_rtg_col_name => 'ROUTING_NAME',
47887 p_rtg_col_id => 'ROUTING_SEQUENCE_ID',
47888 p_instance_code => v_instance_code,
47889 p_batch_id => lv_batch_id,
47890 p_debug => v_debug,
47891 p_error_text => lv_error_text);
47892
47893 if (lv_return <> 0 )then
47894 RAISE ex_logging_err;
47895 end if;
47896
47897
47898
47899
47900 v_sql_stmt := 09;
47901 lv_sql_stmt :=
47902 'UPDATE msc_st_supplies mss'
47903 ||' SET schedule_group_id = (SELECT local_id'
47904 ||' FROM msc_local_id_supply mls'
47905 ||' WHERE mls.char4 = mss.schedule_group_name'
47906 ||' AND mls.char3 = mss.organization_code'
47907 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
47908 ||' NVL(mss.company_name,'||''''||NULL_CHAR||''''||') '
47909 ||' AND mls.char1 = mss.sr_instance_code'
47910 ||' AND mls.entity_name = ''SCHEDULE_GROUP_ID'' ),'
47911 ||' line_id = (SELECT local_id'
47912 ||' FROM msc_local_id_setup mls'
47913 ||' WHERE mls.char4 = mss.line_code'
47914 ||' AND mls.char3 = mss.organization_code'
47915 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
47916 ||' NVL(mss.company_name,'||''''||NULL_CHAR||''''||') '
47917 ||' AND mls.char1 = mss.sr_instance_code'
47918 ||' AND mls.entity_name = ''LINE_ID''),'
47919 ||' operation_seq_num = (SELECT number1'
47920 ||' FROM msc_local_id_setup mls'
47921 ||' WHERE mls.char5 = mss.operation_seq_code'
47922 ||' AND mls.char4 = mss.routing_name'
47923 ||' AND NVL(mls.char6, '||''''||NULL_CHAR||''''||') = '
47924 ||' NVL(mss.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
47925 ||' AND mls.char3 = mss.organization_code'
47926 ||' AND mls.date1 = mss.effectivity_date'
47927 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
47928 ||' NVL(mss.company_name,'||''''||NULL_CHAR||''''||') '
47929 ||' AND mls.char1 = mss.sr_instance_code'
47930 ||' AND mls.entity_name = ''OPERATION_SEQUENCE_ID'' )'
47931 ||' WHERE deleted_flag = '||SYS_NO
47932 ||' AND process_flag = '||G_IN_PROCESS
47933 ||' AND NVL(batch_id,'||NULL_VALUE||')= :lv_batch_id'
47934 ||' AND sr_instance_code = :v_instance_code';
47935
47936
47937 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
47938
47939 EXECUTE IMMEDIATE lv_sql_stmt
47940 USING lv_batch_id,
47941 v_instance_code;
47942
47943
47944 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
47945 (p_app_short_name => 'MSC',
47946 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
47947 p_message_text => lv_message_text,
47948 p_error_text => lv_error_text,
47949 p_token1 => 'COLUMN_NAME',
47950 p_token_value1 => 'BILL_SEQUENCE_ID OR ROUTING_SEQUENCE_ID',
47951 p_token2 => 'DEFAULT_VALUE',
47952 p_token_value2 => SYS_NO);
47953
47954 IF lv_return <> 0 THEN
47955 RAISE ex_logging_err;
47956 END IF;
47957
47958 lv_where_str :=
47959 ' AND (NVL(bill_sequence_id, '||NULL_VALUE||') = '||NULL_VALUE
47960 ||' OR NVL(routing_sequence_id,'||NULL_VALUE||') = '||NULL_VALUE||')'
47961 ||' AND deleted_flag = '||SYS_NO;
47962
47963 --Log a warning for those records where the bill_sequence_id or
47964 --routing_sequence_id has null values
47965
47966 lv_return := MSC_ST_UTIL.LOG_ERROR
47967 (p_table_name => 'MSC_ST_SUPPLIES',
47968 p_instance_code => v_instance_code,
47969 p_row => lv_column_names,
47970 p_severity => G_SEV_WARNING,
47971 p_message_text => lv_message_text,
47972 p_error_text => lv_error_text,
47973 p_batch_id => lv_batch_id,
47974 p_debug => v_debug,
47975 p_where_str => lv_where_str);
47976
47977 IF lv_return <> 0 THEN
47978 RAISE ex_logging_err;
47979 END IF;
47980
47981 --Deriving wip_entity_id
47982 v_sql_stmt := 10;
47983 lv_sql_stmt :=
47984 'UPDATE msc_st_supplies mss'
47985 ||' SET wip_entity_id = (SELECT local_id'
47986 ||' FROM msc_local_id_supply mls'
47987 ||' WHERE mls.char4 = mss.wip_entity_name'
47988 ||' AND mls.char3 = mss.organization_code'
47989 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
47990 ||' NVL(mss.company_name,'||''''||NULL_CHAR||''''||') '
47991 ||' AND mls.char1 = mss.sr_instance_code'
47992 ||' AND mls.entity_name = ''WIP_ENTITY_ID'' )'
47993 ||' WHERE process_flag = '||G_IN_PROCESS
47994 ||' AND NVL(batch_id,'||NULL_VALUE||') = :lv_batch_id'
47995 ||' AND sr_instance_code = :v_instance_code';
47996
47997
47998 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
47999
48000 EXECUTE IMMEDIATE lv_sql_stmt
48001 USING lv_batch_id,
48002 v_instance_code;
48003
48004
48005 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
48006 (p_app_short_name => 'MSC',
48007 p_error_code => 'MSC_PP_DELETE_FAIL',
48008 p_message_text => lv_message_text,
48009 p_error_text => lv_error_text);
48010
48011 IF lv_return <> 0 THEN
48012 RAISE ex_logging_err;
48013 END IF;
48014
48015 v_sql_stmt := 11;
48016
48017 lv_sql_stmt :=
48018 'UPDATE msc_st_supplies '
48019 ||' SET process_flag = '||G_ERROR_FLG||','
48020 ||' error_text = '||''''||lv_message_text||''''
48021 ||' WHERE NVL(wip_entity_id,'||NULL_VALUE||') = '||NULL_VALUE
48022 ||' AND deleted_flag ='||SYS_YES
48023 ||' AND process_flag = '||G_IN_PROCESS
48024 ||' AND NVL(batch_id,'||NULL_VALUE||')= :lv_batch_id '
48025 ||' AND sr_instance_code =:v_instance_code';
48026
48027
48028 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
48029
48030 EXECUTE IMMEDIATE lv_sql_stmt
48031 USING lv_batch_id,
48032 v_instance_code;
48033
48034
48035 -- update the jump_op_seq_num for lot based jobs for the operations jumped outside the network
48036
48037 lv_sql_stmt :=
48038 'UPDATE msc_st_supplies '
48039 ||' SET jump_op_seq_num = 50000'
48040 ||' WHERE NVL(jump_op_seq_code,'||''''||NULL_CHAR||''''||') '
48041 ||' = '||''''||50000||''''
48042 ||' AND process_flag = '||G_IN_PROCESS
48043 ||' AND NVL(batch_id,'||NULL_VALUE||')= :lv_batch_id '
48044 ||' AND order_type IN (3,7,14,15)'
48045 ||' AND sr_instance_code =:v_instance_code';
48046
48047
48048 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
48049
48050 EXECUTE IMMEDIATE lv_sql_stmt
48051 USING lv_batch_id,
48052 v_instance_code;
48053
48054
48055 lv_sql_stmt :=
48056 'UPDATE msc_st_supplies mss'
48057 ||' SET jump_op_seq_num = (SELECT number1'
48058 ||' FROM msc_local_id_setup mls'
48059 ||' WHERE NVL(mls.char5,'||''''||NULL_CHAR||''''||') = '
48060 ||' NVL(mss.jump_op_seq_code,'||''''||NULL_CHAR||''''||') '
48061 ||' AND mls.char4 = mss.routing_name'
48062 ||' AND NVL(mls.char6, '||''''||NULL_CHAR||''''||') = '
48063 ||' NVL(mss.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
48064 ||' AND mls.char3 = mss.organization_code'
48065 ||' AND mls.date1 = mss.jump_op_effectivity_date'
48066 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
48067 ||' NVL(mss.company_name,'||''''||NULL_CHAR||''''||') '
48068 ||' AND mls.char1 = mss.sr_instance_code'
48069 ||' AND mls.entity_name = ''OPERATION_SEQUENCE_ID'' )'
48070 ||' WHERE deleted_flag = '||SYS_NO
48071 ||' AND process_flag = '||G_IN_PROCESS
48072 ||' AND jump_op_seq_num <> 50000 '
48073 ||' AND NVL(batch_id,'||NULL_VALUE||')= :lv_batch_id'
48074 ||' AND sr_instance_code = :v_instance_code';
48075
48076
48077
48078 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
48079
48080 EXECUTE IMMEDIATE lv_sql_stmt
48081 USING lv_batch_id,
48082 v_instance_code;
48083
48084
48085 --Call to customised validation.
48086 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
48087 (ERRBUF => lv_error_text,
48088 RETCODE => lv_return,
48089 pBatchID => lv_batch_id,
48090 pInstanceCode => v_instance_code,
48091 pEntityName => 'MSC_ST_SUPPLIES_WO',
48092 pInstanceID => v_instance_id);
48093
48094 IF NVL(lv_return,0) <> 0 THEN
48095 RAISE ex_logging_err;
48096 END IF;
48097
48098 --Generation of wip_entity_id
48099 OPEN c2(lv_batch_id);
48100 FETCH c2 BULK COLLECT INTO lb_rowid ;
48101
48102 IF c2%ROWCOUNT > 0 THEN
48103 v_sql_stmt := 12;
48104 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
48105 UPDATE msc_st_supplies
48106 SET wip_entity_id = msc_st_wip_entity_id_s.NEXTVAL
48107 WHERE rowid = lb_rowid(j);
48108
48109 v_sql_stmt := 13;
48110 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
48111 INSERT INTO msc_local_id_supply
48112 (local_id,
48113 st_transaction_id,
48114 instance_id,
48115 entity_name,
48116 data_source_type,
48117 char1,
48118 char2,
48119 char3,
48120 char4,
48121 SOURCE_ORG_ID,
48122 SOURCE_INVENTORY_ITEM_ID,
48123 SOURCE_BILL_SEQUENCE_ID,
48124 SOURCE_ROUTING_SEQUENCE_ID,
48125 SOURCE_SCHEDULE_GROUP_ID,
48126 SOURCE_WIP_ENTITY_ID,
48127 last_update_date,
48128 last_updated_by,
48129 creation_date,
48130 created_by)
48131 SELECT
48132 wip_entity_id,
48133 st_transaction_id,
48134 v_instance_id,
48135 'WIP_ENTITY_ID',
48136 data_source_type,
48137 v_instance_code,
48138 company_name,
48139 organization_code ,
48140 wip_entity_name,
48141 SOURCE_ORG_ID,
48142 SOURCE_INVENTORY_ITEM_ID,
48143 SOURCE_BILL_SEQUENCE_ID,
48144 SOURCE_ROUTING_SEQUENCE_ID,
48145 SOURCE_SCHEDULE_GROUP_ID,
48146 SOURCE_WIP_ENTITY_ID,
48147 v_current_date,
48148 v_current_user,
48149 v_current_date,
48150 v_current_user
48151 FROM msc_st_supplies
48152 WHERE rowid = lb_rowid(j);
48153
48154 END IF;
48155 CLOSE c2 ;
48156
48157 --Generation of schedule_group_id
48158 OPEN c3(lv_batch_id);
48159 FETCH c3 BULK COLLECT INTO lb_rowid ;
48160
48161 IF c3%ROWCOUNT > 0 THEN
48162 v_sql_stmt := 14;
48163 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
48164 UPDATE msc_st_supplies
48165 SET schedule_group_id = msc_st_schedule_group_id_s.NEXTVAL
48166 WHERE rowid = lb_rowid(j);
48167
48168 v_sql_stmt := 15;
48169 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
48170 INSERT INTO msc_local_id_supply
48171 (local_id,
48172 st_transaction_id,
48173 instance_id,
48174 entity_name,
48175 data_source_type,
48176 char1,
48177 char2,
48178 char3,
48179 char4,
48180 SOURCE_ORG_ID,
48181 SOURCE_INVENTORY_ITEM_ID,
48182 SOURCE_BILL_SEQUENCE_ID,
48183 SOURCE_ROUTING_SEQUENCE_ID,
48184 SOURCE_SCHEDULE_GROUP_ID,
48185 SOURCE_WIP_ENTITY_ID,
48186 last_update_date,
48187 last_updated_by,
48188 creation_date,
48189 created_by)
48190 SELECT
48191 schedule_group_id,
48192 st_transaction_id,
48193 v_instance_id,
48194 'SCHEDULE_GROUP_ID',
48195 data_source_type,
48196 v_instance_code,
48197 company_name,
48198 organization_code ,
48199 schedule_group_name,
48200 SOURCE_ORG_ID,
48201 SOURCE_INVENTORY_ITEM_ID,
48202 SOURCE_BILL_SEQUENCE_ID,
48203 SOURCE_ROUTING_SEQUENCE_ID,
48204 SOURCE_SCHEDULE_GROUP_ID,
48205 SOURCE_WIP_ENTITY_ID,
48206 v_current_date,
48207 v_current_user,
48208 v_current_date,
48209 v_current_user
48210 FROM msc_st_supplies
48211 WHERE rowid = lb_rowid(j);
48212
48213 END IF;
48214 CLOSE c3;
48215
48216 --Update disposition_id with the wip_entity_id.
48217 v_sql_stmt := 16;
48218 UPDATE msc_st_supplies
48219 SET disposition_id = wip_entity_id
48220 WHERE process_flag = G_IN_PROCESS
48221 AND batch_id = lv_batch_id
48222 AND sr_instance_code = v_instance_code;
48223
48224 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
48225 (p_app_short_name => 'MSC',
48226 p_error_code => 'MSC_PP_FK_REF_NOT_EXIST',
48227 p_message_text => lv_message_text,
48228 p_error_text => lv_error_text,
48229 p_token1 => 'COLUMN_NAMES',
48230 p_token_value1 => ' SR_INSTANCE_CODE, COMPANY_NAME,'
48231 ||' ORGANIZATION_CODE AND PROJECT_NUMBER',
48232 p_token2 => 'MASTER_TABLE',
48233 p_token_value2 => 'MSC_ST_PROJECT_TASKS');
48234
48235 IF lv_return <> 0 THEN
48236 RAISE ex_logging_err;
48237 END IF;
48238
48239 --Derive Project Id.
48240 lv_return := MSC_ST_UTIL.DERIVE_PROJ_TASK_ID
48241 (p_table_name => 'MSC_ST_SUPPLIES',
48242 p_proj_col_name => 'PROJECT_NUMBER',
48243 p_proj_task_col_id => 'PROJECT_ID',
48244 p_instance_code => v_instance_code,
48245 p_entity_name => 'PROJECT_ID',
48246 p_error_text => lv_error_text,
48247 p_batch_id => lv_batch_id,
48248 p_severity => G_SEV_WARNING,
48249 p_message_text => lv_message_text,
48250 p_debug => v_debug,
48251 p_row => lv_column_names);
48252 IF lv_return <> 0 THEN
48253 RAISE ex_logging_err;
48254 END IF;
48255
48256 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
48257 (p_app_short_name => 'MSC',
48258 p_error_code => 'MSC_PP_FK_REF_NOT_EXIST',
48259 p_message_text => lv_message_text,
48260 p_error_text => lv_error_text,
48261 p_token1 => 'COLUMN_NAMES',
48262 p_token_value1 => ' SR_INSTANCE_CODE, COMPANY_NAME,'
48263 ||' ORGANIZATION_CODE, PROJECT_NUMBER,'
48264 ||' TASK_NUMBER',
48265 p_token2 => 'MASTER_TABLE',
48266 p_token_value2 => 'MSC_ST_PROJECT_TASKS');
48267
48268 IF lv_return <> 0 THEN
48269 RAISE ex_logging_err;
48270 END IF;
48271
48272 --Derive Task Id.
48273 lv_return := MSC_ST_UTIL.DERIVE_PROJ_TASK_ID
48274 (p_table_name => 'MSC_ST_SUPPLIES',
48275 p_proj_col_name => 'PROJECT_NUMBER',
48276 p_proj_task_col_id => 'TASK_ID',
48277 p_instance_code => v_instance_code,
48278 p_entity_name => 'TASK_ID',
48279 p_error_text => lv_error_text,
48280 p_task_col_name => 'TASK_NUMBER',
48281 p_batch_id => lv_batch_id,
48282 p_severity => G_SEV_WARNING,
48283 p_message_text => lv_message_text,
48284 p_debug => v_debug,
48285 p_row => lv_column_names);
48286
48287 IF lv_return <> 0 THEN
48288 RAISE ex_logging_err;
48289 END IF;
48290
48291
48292 v_sql_stmt := 17;
48293 lv_sql_stmt :=
48294 'UPDATE msc_st_supplies mss '
48295 ||' SET schedule_group_id = (SELECT local_id'
48296 ||' FROM msc_local_id_supply mls'
48297 ||' WHERE mls.char4 = mss.schedule_group_name'
48298 ||' AND mls.char3 = mss.organization_code'
48299 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
48300 ||' NVL(mss.company_name,'||''''||NULL_CHAR||''''||') '
48301 ||' AND mls.char1 = mss.sr_instance_code'
48302 ||' AND mls.entity_name = ''SCHEDULE_GROUP_ID'' )'
48303 ||' WHERE deleted_flag = '||SYS_NO
48304 ||' AND process_flag = '||G_IN_PROCESS
48305 ||' AND NVL(schedule_group_id,'||NULL_VALUE||') = '||NULL_VALUE
48306 ||' AND NVL(batch_id,'||NULL_VALUE||')= :lv_batch_id'
48307 ||' AND sr_instance_code = :v_instance_code';
48308
48309
48310 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
48311
48312 EXECUTE IMMEDIATE lv_sql_stmt
48313 USING lv_batch_id,
48314 v_instance_code;
48315
48316 OPEN c4(lv_batch_id);
48317 FETCH c4 BULK COLLECT INTO lb_rowid ;
48318
48319 IF c4%ROWCOUNT > 0 THEN
48320
48321 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
48322
48323 UPDATE msc_st_supplies
48324 SET job_op_seq_num =
48325 to_number(decode(length(rtrim(job_op_seq_code,'0123456789')),
48326 NULL,job_op_seq_code,'1'))
48327 WHERE rowid = lb_rowid(j);
48328 END IF;
48329 CLOSE c4;
48330
48331 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
48332 (p_table_name => 'MSC_ST_SUPPLIES',
48333 p_instance_id => v_instance_id,
48334 p_instance_code => v_instance_code,
48335 p_process_flag => G_VALID,
48336 p_error_text => lv_error_text,
48337 p_debug => v_debug,
48338 p_batch_id => lv_batch_id);
48339 IF lv_return <> 0 THEN
48340 RAISE ex_logging_err;
48341 END IF;
48342
48343 lv_return := MSC_ST_UTIL.LOG_ERROR
48344 (p_table_name => 'MSC_ST_SUPPLIES',
48345 p_instance_code => v_instance_code,
48346 p_row => lv_column_names,
48347 p_severity => G_SEV_ERROR,
48348 p_message_text => NULL,
48349 p_error_text => lv_error_text,
48350 p_debug => v_debug,
48351 p_batch_id => lv_batch_id);
48352
48353 IF lv_return <> 0 THEN
48354 RAISE ex_logging_err;
48355 END IF;
48356
48357 COMMIT;
48358 END LOOP;
48359 EXCEPTION
48360 WHEN too_many_rows THEN
48361 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_WO_SUPPLY'||'('
48362 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
48363 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
48364 ROLLBACK;
48365
48366 WHEN ex_logging_err THEN
48367 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
48368 ROLLBACK;
48369
48370 WHEN OTHERS THEN
48371 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_WO_SUPPLY'||'('
48372 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
48373 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
48374 ROLLBACK;
48375
48376 END LOAD_WO_SUPPLY;
48377
48378
48379 PROCEDURE LOAD_RES_DEMAND IS
48380
48381 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
48382 TYPE CurTyp IS REF CURSOR;
48383 c1 CurTyp;
48384 lb_rowid RowidTab;
48385
48386 lv_local_id NUMBER;
48387 lv_column_names VARCHAR2(5000); -- Stores cocatenated column names
48388 lv_return NUMBER;
48389 lv_error_text VARCHAR2(250);
48390 lv_where_str VARCHAR2(5000);
48391 lv_sql_stmt VARCHAR2(5000);
48392 lv_cursor_stmt VARCHAR2(5000);
48393 lv_batch_id msc_st_resource_requirements.batch_id%TYPE;
48394 lv_message_text msc_errors.error_text%TYPE;
48395
48396 ex_logging_err EXCEPTION;
48397
48398 CURSOR c2(p_batch_id NUMBER) IS
48399 SELECT rowid
48400 FROM msc_st_resource_requirements
48401 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
48402 AND sr_instance_code = v_instance_code
48403 AND batch_id = p_batch_id;
48404
48405 CURSOR c3(p_batch_id NUMBER) IS
48406 SELECT max(rowid)
48407 FROM msc_st_resource_requirements
48408 WHERE process_flag = G_IN_PROCESS
48409 AND sr_instance_code = v_instance_code
48410 AND batch_id = p_batch_id
48411 AND NVL(operation_sequence_id,NULL_VALUE) = NULL_VALUE
48412 AND deleted_flag = SYS_NO
48413 GROUP BY sr_instance_code,company_name,organization_code,routing_name,
48414 operation_seq_code,alternate_routing_designator,operation_effectivity_date;
48415
48416 CURSOR c4(p_batch_id NUMBER) IS
48417 SELECT max(rowid)
48418 FROM msc_st_resource_requirements
48419 WHERE process_flag = G_IN_PROCESS
48420 AND sr_instance_code = v_instance_code
48421 AND batch_id = p_batch_id
48422 AND NVL(resource_seq_num,NULL_VALUE) = NULL_VALUE
48423 AND NVL(resource_seq_code, NULL_CHAR) <> NULL_CHAR
48424 AND deleted_flag = SYS_NO
48425 GROUP BY sr_instance_code,company_name,organization_code,routing_name,
48426 operation_seq_code,resource_seq_code,alternate_routing_designator, alternate_number;
48427
48428 BEGIN
48429
48430 --Duplicate records check for the records whose source is XML
48431
48432 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
48433 (p_app_short_name => 'MSC',
48434 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
48435 p_message_text => lv_message_text,
48436 p_error_text => lv_error_text);
48437
48438 IF lv_return <> 0 THEN
48439 RAISE ex_logging_err;
48440 END IF;
48441
48442 v_sql_stmt := 01;
48443
48444 lv_sql_stmt:=
48445 'UPDATE msc_st_resource_requirements msrr1 '
48446 ||' SET process_flag ='||G_ERROR_FLG||','
48447 ||' error_text = '||''''||lv_message_text||''''
48448 ||' WHERE message_id < ( SELECT max(message_id) FROM msc_st_resource_requirements msrr2'
48449 ||' WHERE msrr2.sr_instance_code '
48450 ||' = msrr1.sr_instance_code'
48451 ||' AND NVL(msrr2.company_name,'||''''||NULL_CHAR||''''||') '
48452 ||' = NVL(msrr1.company_name,'||''''||NULL_CHAR||''''||') '
48453 ||' AND msrr2.wip_entity_name = msrr1.wip_entity_name'
48454 ||' AND msrr2.organization_code = msrr1.organization_code'
48455 ||' AND NVL(msrr2.operation_seq_code,'||''''||NULL_CHAR||''''||') '
48456 ||' = NVL(msrr1.operation_seq_code,'||''''||NULL_CHAR||''''||') '
48457 ||' AND NVL(msrr2.resource_seq_code,'||''''||NULL_CHAR||''''||') '
48458 ||' = NVL(msrr1.resource_seq_code,'||''''||NULL_CHAR||''''||') '
48459 ||' AND NVL(msrr2.resource_code, '||''''||NULL_CHAR||''''||') '
48460 ||' = NVL(msrr1.resource_code, '||''''||NULL_CHAR||''''||') '
48461 ||' AND msrr2.process_flag = '||G_IN_PROCESS
48462 ||' AND NVL(msrr2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||')'
48463 ||' AND msrr1.process_flag = '|| G_IN_PROCESS
48464 ||' AND msrr1.sr_instance_code = :v_instance_code '
48465 ||' AND NVL(msrr1.message_id,'||NULL_VALUE||')<> '||NULL_VALUE;
48466
48467
48468 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
48469
48470 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
48471
48472 --Duplicate records check for the records whose source is batch load
48473
48474 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
48475 (p_app_short_name => 'MSC',
48476 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
48477 p_message_text => lv_message_text,
48478 p_error_text => lv_error_text);
48479
48480 IF lv_return <> 0 THEN
48481 RAISE ex_logging_err;
48482 END IF;
48483 v_sql_stmt := 02;
48484
48485 lv_sql_stmt:=
48486 'UPDATE msc_st_resource_requirements msrr1'
48487 ||' SET process_flag = '||G_ERROR_FLG||','
48488 ||' error_text = '||''''||lv_message_text||''''
48489 ||' WHERE EXISTS ( SELECT 1 '
48490 ||' FROM msc_st_resource_requirements msrr2'
48491 ||' WHERE msrr2.sr_instance_code '
48492 ||' = msrr1.sr_instance_code'
48493 ||' AND NVL(msrr2.company_name,'||''''||NULL_CHAR||''''||') '
48494 ||' = NVL(msrr1.company_name,'||''''||NULL_CHAR||''''||') '
48495 ||' AND msrr2.wip_entity_name = msrr1.wip_entity_name'
48496 ||' AND msrr2.organization_code = msrr1.organization_code'
48497 ||' AND NVL(msrr2.operation_seq_code,'||''''||NULL_CHAR||''''||') '
48498 ||' = NVL(msrr1.operation_seq_code,'||''''||NULL_CHAR||''''||') '
48499 ||' AND NVL(msrr2.resource_seq_code,'||''''||NULL_CHAR||''''||') '
48500 ||' = NVL(msrr1.resource_seq_code,'||''''||NULL_CHAR||''''||') '
48501 ||' AND NVL(msrr2.resource_code, '||''''||NULL_CHAR||''''||') '
48502 ||' = NVL(msrr1.resource_code, '||''''||NULL_CHAR||''''||') '
48503 ||' AND msrr2.process_flag = '||G_IN_PROCESS
48504 ||' AND NVL(msrr2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
48505 ||' GROUP BY sr_instance_code,company_name,organization_code,wip_entity_name,'
48506 ||' operation_seq_code,resource_seq_code,resource_code '
48507 ||' HAVING COUNT(*) >1 )'
48508 ||' AND msrr1.process_flag = '||G_IN_PROCESS
48509 ||' AND msrr1.sr_instance_code = :v_instance_code'
48510 ||' AND NVL(msrr1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
48511
48512
48513 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
48514
48515 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
48516
48517 lv_column_names :=
48518 'DEPARTMENT_CODE ||''~''||'
48519 ||'RESOURCE_CODE ||''~''||'
48520 ||'ORGANIZATION_CODE ||''~''||'
48521 ||'RESOURCE_SEQ_CODE ||''~''||'
48522 ||'START_DATE ||''~''||'
48523 ||'OPERATION_HOURS_REQUIRED ||''~''||'
48524 ||'ASSIGNED_UNITS ||''~''||'
48525 ||'WIP_ENTITY_NAME ||''~''||'
48526 ||'SR_INSTANCE_CODE ||''~''||'
48527 ||'ITEM_NAME ||''~''||'
48528 ||'OPERATION_SEQ_CODE ||''~''||'
48529 ||'HOURS_EXPENDED ||''~''||'
48530 ||'DEMAND_CLASS ||''~''||'
48531 ||'BASIS_TYPE ||''~''||'
48532 ||'END_DATE ||''~''||'
48533 ||'WIP_JOB_TYPE ||''~''||'
48534 ||'SCHEDULED_COMPLETION_DATE ||''~''||'
48535 ||'SCHEDULED_QUANTITY ||''~''||'
48536 ||'QUANTITY_COMPLETED ||''~''||'
48537 ||'STD_OP_CODE ||''~''||'
48538 ||'SUPPLY_TYPE ||''~''||'
48539 ||'DELETED_FLAG ||''~''||'
48540 ||'COMPANY_NAME ' ;
48541
48542
48543 -- Now processing by batch
48544 LOOP
48545 v_sql_stmt := 03;
48546 lv_cursor_stmt :=
48547 ' SELECT msc_st_batch_id_s.NEXTVAL '
48548 ||' FROM dual';
48549
48550 OPEN c1 FOR lv_cursor_stmt;
48551 FETCH c1 INTO lv_batch_id;
48552 CLOSE c1;
48553
48554 v_sql_stmt := 04;
48555 lv_sql_stmt :=
48556 ' UPDATE msc_st_resource_requirements '
48557 ||' SET batch_id = :lv_batch_id'
48558 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
48559 ||' AND sr_instance_code = :v_instance_code'
48560 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
48561 ||' AND rownum <= '||v_batch_size;
48562
48563
48564 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
48565
48566
48567 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
48568
48569 EXIT WHEN SQL%NOTFOUND;
48570
48571 OPEN c2(lv_batch_id);
48572 FETCH c2 BULK COLLECT INTO lb_rowid;
48573 CLOSE c2;
48574
48575 v_sql_stmt := 05;
48576 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
48577 UPDATE msc_st_resource_requirements
48578 SET st_transaction_id = msc_st_resource_requirements_s.NEXTVAL,
48579 refresh_id = v_refresh_id,
48580 last_update_date = v_current_date,
48581 last_updated_by = v_current_user,
48582 creation_date = v_current_date,
48583 created_by = v_current_user
48584 WHERE rowid = lb_rowid(j);
48585
48586
48587 -- Set the error message
48588 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
48589 (p_app_short_name => 'MSC',
48590 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
48591 p_message_text => lv_message_text,
48592 p_error_text => lv_error_text,
48593 p_token1 => 'COLUMN_NAME',
48594 p_token_value1 => 'DELETED_FLAG',
48595 p_token2 => 'DEFAULT_VALUE',
48596 p_token_value2 => SYS_NO );
48597
48598 IF lv_return <> 0 THEN
48599 RAISE ex_logging_err;
48600 END IF;
48601
48602 -- Check whether delete flag value is in (SYS_YES,SYS_NO),if not default to SYS_NO
48603
48604 lv_where_str :=
48605 ' AND NVL(deleted_flag,'||NULL_VALUE||') NOT IN(1,2)';
48606
48607 lv_return := MSC_ST_UTIL.LOG_ERROR
48608 (p_table_name => 'MSC_ST_RESOURCE_REQUIREMENTS',
48609 p_instance_code => v_instance_code,
48610 p_row => lv_column_names,
48611 p_severity => G_SEV_WARNING,
48612 p_message_text => lv_message_text,
48613 p_error_text => lv_error_text,
48614 p_batch_id => lv_batch_id,
48615 p_where_str => lv_where_str,
48616 p_col_name => 'DELETED_FLAG',
48617 p_debug => v_debug,
48618 p_default_value => SYS_NO);
48619
48620
48621 IF lv_return <> 0 THEN
48622 RAISE ex_logging_err;
48623 END IF;
48624
48625 -- Set the message
48626 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
48627 (p_app_short_name => 'MSC',
48628 p_error_code => 'MSC_PP_INVALID_VALUE',
48629 p_message_text => lv_message_text,
48630 p_error_text => lv_error_text,
48631 p_token1 => 'COLUMN_NAME',
48632 p_token_value1 => 'ORGANIZATION_CODE');
48633
48634 IF lv_return <> 0 THEN
48635 RAISE ex_logging_err;
48636 END IF;
48637
48638
48639 -- Populate organization id , call utilty package- msc_st_util's procedure
48640
48641 lv_return :=
48642 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name => 'MSC_ST_RESOURCE_REQUIREMENTS',
48643 p_org_partner_name =>'ORGANIZATION_CODE',
48644 p_org_partner_id =>'ORGANIZATION_ID',
48645 p_instance_code => v_instance_code,
48646 p_partner_type => G_ORGANIZATION,
48647 p_severity => G_SEV_ERROR,
48648 p_message_text => lv_message_text,
48649 p_batch_id => lv_batch_id,
48650 p_debug => v_debug,
48651 p_error_text => lv_error_text);
48652
48653 IF(lv_return <> 0) then
48654 RAISE ex_logging_err;
48655 END IF;
48656
48657
48658 -- Derive WIP_ENTITY_ID
48659 v_sql_stmt := 06;
48660 lv_sql_stmt:=
48661 'UPDATE msc_st_resource_requirements msrr'
48662 ||' SET wip_entity_id = (SELECT local_id '
48663 ||' FROM msc_local_id_supply mlis'
48664 ||' WHERE mlis.char1 = msrr.sr_instance_code'
48665 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
48666 ||' = NVL(msrr.company_name,'||''''||NULL_CHAR||''''||') '
48667 ||' AND mlis.char3 = msrr.organization_code'
48668 ||' AND mlis.char4 = msrr.wip_entity_name'
48669 ||' AND mlis.entity_name = ''WIP_ENTITY_ID'' '
48670 ||' AND mlis.instance_id ='||v_instance_id||')'
48671 ||' WHERE sr_instance_code = :v_instance_code'
48672 ||' AND NVL(wip_entity_name,'||''''||NULL_CHAR||''''||') '
48673 ||' <> '||''''||NULL_CHAR||''''
48674 ||' AND process_flag ='||G_IN_PROCESS
48675 ||' AND batch_id = :lv_batch_id';
48676
48677
48678 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
48679
48680 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
48681
48682 -- Set the error message
48683
48684 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
48685 (p_app_short_name => 'MSC',
48686 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
48687 p_message_text => lv_message_text,
48688 p_error_text => lv_error_text,
48689 p_token1 => 'COLUMN_NAMES',
48690 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
48691 ||'ORGANIZATION_CODE,WIP_ENTITY_NAME',
48692 p_token2 => 'MASTER_TABLE',
48693 p_token_value2 => 'MSC_ST_SUPPLIES',
48694 p_token3 => 'CHILD_TABLE' ,
48695 p_token_value3 => 'MSC_ST_RESOURCE_REQUIREMENTS' );
48696
48697 IF lv_return <> 0 THEN
48698 RAISE ex_logging_err;
48699 END IF;
48700
48701
48702 -- Error out the records if WIP_ENTITY_ID NULL
48703
48704 v_sql_stmt := 07;
48705 lv_sql_stmt:=
48706 'UPDATE msc_st_resource_requirements msrr'
48707 ||' SET process_flag ='||G_ERROR_FLG||','
48708 ||' error_text = '||''''||lv_message_text||''''
48709 ||' WHERE NVL(wip_entity_id,'||NULL_VALUE||') = '||NULL_VALUE
48710 ||' AND sr_instance_code = :v_instance_code'
48711 ||' AND process_flag ='||G_IN_PROCESS
48712 ||' AND batch_id = :lv_batch_id';
48713
48714
48715 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
48716
48717 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
48718
48719
48720 -- Set supply_id = wip_entity_id
48721 v_sql_stmt := 09;
48722
48723 lv_sql_stmt:=
48724 'UPDATE msc_st_resource_requirements msrr'
48725 ||' SET supply_id = wip_entity_id '
48726 ||' WHERE sr_instance_code = :v_instance_code'
48727 ||' AND process_flag = '||G_IN_PROCESS
48728 ||' AND NVL(wip_entity_id,'||NULL_VALUE||')='||NULL_VALUE
48729 ||' AND batch_id = :lv_batch_id';
48730
48731
48732 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
48733
48734 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
48735
48736 /* bug 3768813 */
48737 -- Derive resource id
48738 /*
48739 v_sql_stmt := 10;
48740
48741 lv_sql_stmt :=
48742 'UPDATE msc_st_resource_requirements msrr'
48743 ||' SET resource_id= (SELECT local_id '
48744 ||' FROM msc_local_id_setup mlis'
48745 ||' WHERE mlis.char1 = msrr.sr_instance_code'
48746 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
48747 ||' = NVL(msrr.company_name,'||''''||NULL_CHAR||''''||') '
48748 ||' AND mlis.char3 = msrr.organization_code'
48749 ||' AND mlis.char4 = msrr.resource_code'
48750 ||' AND mlis.entity_name = ''RESOURCE_ID'''
48751 ||' AND mlis.instance_id ='||v_instance_id||' )'
48752 ||' WHERE msrr.sr_instance_code = :v_instance_code'
48753 ||' AND msrr.deleted_flag = '||SYS_NO
48754 ||' AND msrr.process_flag ='|| G_IN_PROCESS
48755 ||' AND msrr.schedule_flag <> 2'
48756 ||' AND msrr.batch_id = :lv_batch_id';
48757
48758
48759 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
48760
48761 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
48762
48763 */
48764 -- set the resource_id, department_id, resource_seq_num to -1 for those records where resource_code is null and resource is an unscheduled resource
48765
48766 lv_sql_stmt:=
48767 'UPDATE msc_st_resource_requirements msrr'
48768 ||' SET resource_id = -1, department_id = -1, resource_seq_num = -1 '
48769 ||' WHERE sr_instance_code = :v_instance_code'
48770 ||' AND deleted_flag = '||SYS_NO
48771 ||' AND process_flag = '|| G_IN_PROCESS
48772 ||' AND batch_id = :lv_batch_id'
48773 ||' AND NVL(resource_code,'||''''||NULL_CHAR||''''||') = '||''''||NULL_CHAR||''''
48774 ||' AND schedule_flag =2';
48775
48776 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
48777
48778 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
48779
48780 -- Set the error message
48781
48782 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
48783 (p_app_short_name => 'MSC',
48784 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
48785 p_message_text => lv_message_text,
48786 p_error_text => lv_error_text,
48787 p_token1 => 'COLUMN_NAMES',
48788 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
48789 ||'ORGANIZATION_CODE,RESOURCE_CODE',
48790 p_token2 => 'MASTER_TABLE',
48791 p_token_value2 => 'MSC_ST_DEPARTMENT_RESOURCES',
48792 p_token3 => 'CHILD_TABLE' ,
48793 p_token_value3 => 'MSC_ST_RESOURCE_REQUIREMENTS' );
48794
48795 IF lv_return <> 0 THEN
48796 RAISE ex_logging_err;
48797 END IF;
48798
48799 /* created the new function to derive resource_id for bug 3768813 */
48800 lv_where_str :=' AND schedule_flag <> 2';
48801 lv_return := MSC_ST_UTIL.DERIVE_RESOURCE_ID
48802 (p_table_name => 'MSC_ST_RESOURCE_REQUIREMENTS',
48803 p_resource_col_name => 'RESOURCE_CODE',
48804 p_department_col_name => 'DEPARTMENT_CODE',
48805 p_resource_col_id => 'RESOURCE_ID',
48806 p_instance_code => v_instance_code,
48807 p_error_text => lv_error_text,
48808 p_batch_id => lv_batch_id,
48809 p_severity => G_SEV_ERROR,
48810 p_message_text => lv_message_text,
48811 p_debug => v_debug,
48812 p_row => lv_column_names,
48813 p_where_str => lv_where_str);
48814
48815 IF lv_return <> 0 THEN
48816 RAISE ex_logging_err;
48817 END IF;
48818 /*
48819 -- Error out records where resource_id is NULL
48820
48821 v_sql_stmt := 11;
48822
48823 lv_sql_stmt:=
48824 'UPDATE msc_st_resource_requirements msrr'
48825 ||' SET process_flag ='||G_ERROR_FLG||','
48826 ||' error_text = '||''''||lv_message_text||''''
48827 ||' WHERE NVL(resource_id,'||NULL_VALUE||') = '||NULL_VALUE
48828 ||' AND sr_instance_code = :v_instance_code'
48829 ||' AND deleted_flag = '||SYS_NO
48830 ||' AND process_flag ='|| G_IN_PROCESS
48831 ||' AND batch_id = :lv_batch_id';
48832
48833 IF v_debug THEN
48834 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
48835 END IF;
48836
48837 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
48838
48839 */
48840 /* bug 3768813 */
48841 -- Derive Department id
48842 /*
48843 v_sql_stmt := 12;
48844
48845 lv_sql_stmt :=
48846 'UPDATE msc_st_resource_requirements msrr'
48847 ||' SET department_id = (SELECT local_id'
48848 ||' FROM msc_local_id_setup mlis'
48849 ||' WHERE mlis.char1 = msrr.sr_instance_code'
48850 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
48851 ||' = NVL(msrr.company_name,'||''''||NULL_CHAR||''''||') '
48852 ||' AND mlis.char3 = msrr.organization_code'
48853 ||' AND mlis.char4 = msrr.department_code'
48854 ||' AND mlis.entity_name = ''DEPARTMENT_ID'''
48855 ||' AND mlis.instance_id ='||v_instance_id||' )'
48856 ||' WHERE msrr.sr_instance_code = :v_instance_code'
48857 ||' AND msrr.process_flag ='||G_IN_PROCESS
48858 ||' AND NVL(msrr.department_id,'||NULL_VALUE||') <> -1'
48859 ||' AND msrr.batch_id = :lv_batch_id';
48860
48861
48862
48863 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
48864
48865
48866 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
48867 */
48868
48869 -- Set the error message
48870
48871 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
48872 (p_app_short_name => 'MSC',
48873 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
48874 p_message_text => lv_message_text,
48875 p_error_text => lv_error_text,
48876 p_token1 => 'COLUMN_NAMES',
48877 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
48878 ||'ORGANIZATION_CODE,DEPARTMENT_CODE',
48879 p_token2 => 'MASTER_TABLE',
48880 p_token_value2 => 'MSC_ST_DEPARTMENT_RESOURCES',
48881 p_token3 => 'CHILD_TABLE' ,
48882 p_token_value3 => 'MSC_ST_RESOURCE_REQUIREMENTS' );
48883
48884 IF lv_return <> 0 THEN
48885 RAISE ex_logging_err;
48886 END IF;
48887
48888 /* created the new function to derive department_id for bug 3768813 */
48889 lv_return := MSC_ST_UTIL.DERIVE_DEPARTMENT_ID
48890 (p_table_name => 'MSC_ST_RESOURCE_REQUIREMENTS',
48891 p_resource_col_name => 'RESOURCE_CODE',
48892 p_department_col_name => 'DEPARTMENT_CODE',
48893 p_department_col_id => 'DEPARTMENT_ID',
48894 p_instance_code => v_instance_code,
48895 p_error_text => lv_error_text,
48896 p_batch_id => lv_batch_id,
48897 p_severity => G_SEV_ERROR,
48898 p_message_text => lv_message_text,
48899 p_debug => v_debug,
48900 p_row => lv_column_names);
48901
48902 IF lv_return <> 0 THEN
48903 RAISE ex_logging_err;
48904 END IF;
48905
48906 /*
48907 -- Error out records where department_id is NULL
48908
48909 v_sql_stmt := 11;
48910
48911 lv_sql_stmt:=
48912 'UPDATE msc_st_resource_requirements msrr'
48913 ||' SET process_flag ='||G_ERROR_FLG||','
48914 ||' error_text = '||''''||lv_message_text||''''
48915 ||' WHERE NVL(department_id,'||NULL_VALUE||') = '||NULL_VALUE
48916 ||' AND sr_instance_code = :v_instance_code'
48917 ||' AND deleted_flag = '||SYS_NO
48918 ||' AND process_flag ='|| G_IN_PROCESS
48919 ||' AND batch_id = :lv_batch_id';
48920
48921
48922 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
48923
48924 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
48925
48926 */
48927
48928 -- Set the message
48929 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
48930 (p_app_short_name => 'MSC',
48931 p_error_code => 'MSC_PP_COL_VAL_NULL',
48932 p_message_text => lv_message_text,
48933 p_error_text => lv_error_text,
48934 p_token1 => 'COLUMN_NAME',
48935 p_token_value1 => 'ASSIGNED_UNITS');
48936
48937 IF lv_return <> 0 THEN
48938 RAISE ex_logging_err;
48939 END IF;
48940
48941 -- set the assigned units to 0 if resource_code is NULL
48942 lv_sql_stmt:=
48943 'UPDATE msc_st_resource_requirements msrr'
48944 ||' SET assigned_units = 0 '
48945 ||' WHERE NVL(assigned_units,'||NULL_VALUE||') = '||NULL_VALUE
48946 ||' AND resource_id = -1 '
48947 ||' AND sr_instance_code = :v_instance_code'
48948 ||' AND deleted_flag ='|| SYS_NO
48949 ||' AND process_flag ='|| G_IN_PROCESS
48950 ||' AND batch_id = :lv_batch_id';
48951
48952
48953 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
48954
48955 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
48956
48957 -- Error out records where assigned units NULL
48958 v_sql_stmt := 08;
48959
48960 lv_sql_stmt:=
48961 'UPDATE msc_st_resource_requirements msrr'
48962 ||' SET process_flag ='||G_ERROR_FLG||','
48963 ||' error_text = '||''''||lv_message_text||''''
48964 ||' WHERE NVL(assigned_units,'||NULL_VALUE||') = '||NULL_VALUE
48965 ||' AND sr_instance_code = :v_instance_code'
48966 ||' AND deleted_flag ='|| SYS_NO
48967 ||' AND process_flag ='|| G_IN_PROCESS
48968 ||' AND batch_id = :lv_batch_id';
48969
48970
48971 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
48972
48973 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
48974
48975
48976 -- Set the error message
48977 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
48978 (p_app_short_name => 'MSC',
48979 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
48980 p_message_text => lv_message_text,
48981 p_error_text => lv_error_text,
48982 p_token1 => 'COLUMN_NAME',
48983 p_token_value1 => 'OPERATION_SEQ_CODE',
48984 p_token2 => 'DEFAULT_VALUE',
48985 p_token_value2 => G_OPERATION_SEQ_CODE );
48986
48987 IF lv_return <> 0 THEN
48988 RAISE ex_logging_err;
48989 END IF;
48990
48991 -- Default operation_seq_code as 1 if NULL
48992 lv_where_str :=
48993 ' AND NVL(operation_seq_code,'||''''||NULL_CHAR||''''||') '
48994 ||' = '||''''||NULL_CHAR||'''' ;
48995
48996 lv_return := MSC_ST_UTIL.LOG_ERROR
48997 (p_table_name => 'MSC_ST_RESOURCE_REQUIREMENTS',
48998 p_instance_code => v_instance_code,
48999 p_row => lv_column_names,
49000 p_severity => G_SEV_WARNING,
49001 p_message_text => lv_message_text,
49002 p_error_text => lv_error_text,
49003 p_batch_id => lv_batch_id,
49004 p_where_str => lv_where_str,
49005 p_col_name => 'OPERATION_SEQ_CODE',
49006 p_debug => v_debug,
49007 p_default_value => G_OPERATION_SEQ_CODE);
49008
49009 IF lv_return <> 0 THEN
49010 RAISE ex_logging_err;
49011 END IF;
49012
49013 -- Set the error message
49014 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
49015 (p_app_short_name => 'MSC',
49016 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
49017 p_message_text => lv_message_text,
49018 p_error_text => lv_error_text,
49019 p_token1 => 'COLUMN_NAME',
49020 p_token_value1 => 'OPERATION_EFFECTIVITY_DATE',
49021 p_token2 => 'DEFAULT_VALUE',
49022 p_token_value2 => 'SYSDATE' );
49023
49024 IF lv_return <> 0 THEN
49025 RAISE ex_logging_err;
49026 END IF;
49027
49028 -- Default operation_effectivity date as SYSDATE if NULL
49029
49030 lv_where_str :=
49031 ' AND NVL(operation_effectivity_date,(sysdate-36500)) =(sysdate-36500)';
49032
49033 lv_return := MSC_ST_UTIL.LOG_ERROR
49034 (p_table_name => 'MSC_ST_RESOURCE_REQUIREMENTS',
49035 p_instance_code => v_instance_code,
49036 p_row => lv_column_names,
49037 p_severity => G_SEV_WARNING,
49038 p_message_text => lv_message_text,
49039 p_error_text => lv_error_text,
49040 p_batch_id => lv_batch_id,
49041 p_where_str => lv_where_str,
49042 p_col_name => 'OPERATION_EFFECTIVITY_DATE',
49043 p_debug => v_debug,
49044 p_default_value => 'SYSDATE');
49045
49046 IF lv_return <> 0 THEN
49047 RAISE ex_logging_err;
49048 END IF;
49049
49050 /* bug 3768813 */
49051 -- Set the message
49052 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
49053 (p_app_short_name => 'MSC',
49054 p_error_code => 'MSC_PP_INVALID_VALUE',
49055 p_message_text => lv_message_text,
49056 p_error_text => lv_error_text,
49057 p_token1 => 'COLUMN_NAME',
49058 p_token_value1 => 'ITEM_NAME');
49059
49060 IF lv_return <> 0 THEN
49061 RAISE ex_logging_err;
49062 END IF;
49063
49064 --Derive Inventory_item_id
49065 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
49066 (p_table_name => 'MSC_ST_RESOURCE_REQUIREMENTS',
49067 p_item_col_name => 'ITEM_NAME',
49068 p_item_col_id => 'INVENTORY_ITEM_ID',
49069 p_instance_id => v_instance_id,
49070 p_instance_code => v_instance_code,
49071 p_message_text => lv_message_text,
49072 p_error_text => lv_error_text,
49073 p_batch_id => lv_batch_id,
49074 p_severity => G_SEV_ERROR,
49075 p_debug => v_debug,
49076 p_row => lv_column_names);
49077
49078 IF lv_return <> 0 THEN
49079 RAISE ex_logging_err;
49080 END IF;
49081
49082 -- If routing_name is is NULL populate the item_name in routing name
49083
49084 v_sql_stmt := 13;
49085 lv_sql_stmt :=
49086 ' UPDATE msc_st_resource_requirements'
49087 ||' SET routing_name = item_name'
49088 ||' WHERE process_flag = '||G_IN_PROCESS
49089 ||' AND NVL(routing_name,'||''''||NULL_CHAR||''''||')'
49090 ||' = '||''''||NULL_CHAR||''''
49091 ||' AND batch_id = :lv_batch_id'
49092 ||' AND sr_instance_code = :v_instance_code';
49093
49094
49095 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
49096
49097 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
49098
49099 /* Bug 3768813 */
49100 -- Derive the ROUTING_SEQUENCE_ID from LOCAL ID table
49101
49102 lv_return :=msc_st_util.derive_routing_sequence_id
49103 (p_table_name => 'MSC_ST_RESOURCE_REQUIREMENTS',
49104 p_rtg_col_name => 'ROUTING_NAME',
49105 p_rtg_col_id =>'ROUTING_SEQUENCE_ID',
49106 p_instance_code => v_instance_code,
49107 p_batch_id => lv_batch_id,
49108 p_debug => v_debug,
49109 p_error_text => lv_error_text);
49110
49111 if (lv_return <> 0 )then
49112 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
49113 end if;
49114
49115 -- Derive operation seq num and operation_seq_id
49116
49117 v_sql_stmt := 14;
49118 lv_sql_stmt:=
49119 'UPDATE msc_st_resource_requirements msrr'
49120 ||' SET operation_seq_num = (SELECT number1'
49121 ||' FROM msc_local_id_setup mlis'
49122 ||' WHERE mlis.char1 = msrr.sr_instance_code'
49123 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
49124 ||' = NVL(msrr.company_name,'||''''||NULL_CHAR||''''||') '
49125 ||' AND mlis.char3 = msrr.organization_code'
49126 ||' AND mlis.char4 = msrr.routing_name'
49127 ||' AND mlis.char5 = msrr.operation_seq_code'
49128 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
49129 ||' = NVL(msrr.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
49130 ||' AND mlis.date1 = msrr.operation_effectivity_date'
49131 ||' AND mlis.entity_name = ''OPERATION_SEQUENCE_ID'' '
49132 ||' AND mlis.instance_id = '||v_instance_id ||')'
49133 ||' WHERE sr_instance_code = :v_instance_code'
49134 ||' AND process_flag = '||G_IN_PROCESS
49135 ||' AND batch_id = :lv_batch_id';
49136
49137
49138
49139 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
49140
49141 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
49142
49143 /* Bug 3768813 */
49144 -- Derive operation_sequence id
49145 /*
49146 v_sql_stmt := 15;
49147 lv_sql_Stmt :=
49148 'UPDATE msc_st_resource_requirements msrr'
49149 ||' SET operation_sequence_id= (SELECT local_id'
49150 ||' FROM msc_local_id_setup mlis'
49151 ||' WHERE mlis.char1 = msrr.sr_instance_code'
49152 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
49153 ||' = NVL(msrr.company_name,'||''''||NULL_CHAR||''''||') '
49154 ||' AND mlis.char3 = msrr.organization_code'
49155 ||' AND mlis.char4 = msrr.routing_name'
49156 ||' AND mlis.char5 = msrr.operation_seq_code'
49157 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
49158 ||' = NVL(msrr.alternate_routing_designator,'||''''||NULL_CHAR||''''||')'
49159 ||' AND mlis.date1 = msrr.operation_effectivity_date'
49160 ||' AND mlis.entity_name = ''OPERATION_SEQUENCE_ID'' '
49161 ||' AND mlis.instance_id = '||v_instance_id||')'
49162 ||' WHERE sr_instance_code = :v_instance_code'
49163 ||' AND process_flag ='||G_IN_PROCESS
49164 ||' AND batch_id = :lv_batch_id';
49165
49166
49167 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
49168
49169 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
49170
49171 */
49172
49173 /* created new function to derive operation sequence id for bug 3768813 */
49174 lv_return := MSC_ST_UTIL.DERIVE_OPERATION_SEQUENCE_ID
49175 (p_table_name => 'MSC_ST_RESOURCE_REQUIREMENTS',
49176 p_operation_seq_num => 'OPERATION_SEQ_NUM',
49177 p_routing_col_name => 'ROUTING_NAME',
49178 p_sequence_col_id => 'OPERATION_SEQUENCE_ID',
49179 p_op_effectivity_date => 'OPERATION_EFFECTIVITY_DATE',
49180 p_operation_seq_code => 'OPERATION_SEQ_CODE',
49181 p_routing_sequence_id => 'ROUTING_SEQUENCE_ID',
49182 p_instance_code => v_instance_code,
49183 p_error_text => lv_error_text,
49184 p_batch_id => lv_batch_id,
49185 p_message_text => lv_message_text,
49186 p_debug => v_debug,
49187 p_row => lv_column_names);
49188
49189 IF lv_return <> 0 THEN
49190 RAISE ex_logging_err;
49191 END IF;
49192
49193 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
49194 (p_app_short_name => 'MSC',
49195 p_error_code => 'MSC_PP_DELETE_FAIL',
49196 p_message_text => lv_message_text,
49197 p_error_text => lv_error_text);
49198
49199 IF lv_return <> 0 THEN
49200 RAISE ex_logging_err;
49201 END IF;
49202
49203 -- Error out the records where delete flag yes and operation_sequence_id is NULL
49204 v_sql_stmt := 16;
49205 lv_sql_stmt:=
49206 'UPDATE msc_st_resource_requirements '
49207 ||' SET process_flag ='||G_ERROR_FLG||','
49208 ||' error_text = '||''''||lv_message_text||''''
49209 ||' WHERE NVL(operation_sequence_id,'||NULL_VALUE||') ='|| NULL_VALUE
49210 ||' AND deleted_flag = '||SYS_YES
49211 ||' AND sr_instance_code = :v_instance_code'
49212 ||' AND process_flag = '||G_IN_PROCESS
49213 ||' AND batch_id = :lv_batch_id';
49214
49215
49216 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
49217
49218 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
49219
49220 -- Derive resource seq num from the local id table
49221
49222 lv_sql_stmt :=
49223 'UPDATE msc_st_resource_requirements msor'
49224 ||' SET resource_seq_num = (SELECT local_id '
49225 ||' FROM msc_local_id_setup mlis'
49226 ||' WHERE mlis.char1 = msor.sr_instance_code'
49227 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
49228 ||' = NVL(msor.company_name,'||''''||NULL_CHAR||''''||') '
49229 ||' AND mlis.char3 = msor.organization_code'
49230 ||' AND mlis.char4 = msor.routing_name'
49231 ||' AND mlis.char5 = msor.operation_seq_code'
49232 ||' AND mlis.char6 = msor.resource_seq_code'
49233 ||' AND NVL(mlis.char7,'||''''||NULL_CHAR||''''||') '
49234 ||' = NVL(msor.alternate_routing_designator,'||''''||NULL_CHAR||''''||')'
49235 ||' AND NVL(mlis.number1,'||NULL_VALUE||') = NVL(msor.alternate_number,'||NULL_VALUE||')'
49236 ||' AND rownum = 1' /*change made to solve res req issue*/
49237 ||' AND mlis.entity_name = ''RESOURCE_SEQ_NUM'')'
49238 ||' WHERE sr_instance_code = :v_instance_code'
49239 ||' AND process_flag = '||G_IN_PROCESS
49240 ||' AND NVL(msor.resource_seq_num,'||NULL_VALUE||') <> -1'
49241 ||' AND batch_id = :lv_batch_id';
49242
49243
49244
49245 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
49246
49247 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
49248
49249
49250 -- Default the operation yield to 1 where operation yield is less than 0 or greater than 1
49251
49252 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
49253 (p_app_short_name => 'MSC',
49254 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
49255 p_message_text => lv_message_text,
49256 p_error_text => lv_error_text,
49257 p_token1 => 'COLUMN_NAME',
49258 p_token_value1 => 'YIELD',
49259 p_token2 => 'DEFAULT_VALUE',
49260 p_token_value2 => 1 );
49261
49262 IF lv_return <> 0 THEN
49263 RAISE ex_logging_err;
49264 END IF;
49265
49266 lv_where_str :=
49267 ' AND (yield < 0 OR yield > 1 OR NVL(yield,'||NULL_VALUE||') ='|| NULL_VALUE||')';
49268
49269 lv_return := MSC_ST_UTIL.LOG_ERROR
49270 (p_table_name => 'MSC_ST_RESOURCE_REQUIREMENTS',
49271 p_instance_code => v_instance_code,
49272 p_row => lv_column_names,
49273 p_severity => G_SEV_WARNING,
49274 p_message_text => lv_message_text,
49275 p_error_text => lv_error_text,
49276 p_batch_id => lv_batch_id,
49277 p_where_str => lv_where_str,
49278 p_col_name => 'YIELD',
49279 p_debug => v_debug,
49280 p_default_value =>1);
49281
49282 IF lv_return <> 0 THEN
49283 RAISE ex_logging_err;
49284 END IF;
49285
49286 -- Set the error message
49287 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
49288 (p_app_short_name => 'MSC',
49289 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
49290 p_message_text => lv_message_text,
49291 p_error_text => lv_error_text,
49292 p_token1 => 'COLUMN_NAME',
49293 p_token_value1 => 'SCHEDULE_FLAG',
49294 p_token2 => 'DEFAULT_VALUE',
49295 p_token_value2 => 1 );
49296
49297 IF lv_return <> 0 THEN
49298 RAISE ex_logging_err;
49299 END IF;
49300
49301 -- Default schedule flag as 1 if values are other than 1,2,3,4
49302
49303 lv_where_str := ' AND NVL(schedule_flag,'||NULL_VALUE||') '
49304 ||' NOT IN(1,2,3,4)';
49305
49306 lv_return := MSC_ST_UTIL.LOG_ERROR
49307 (p_table_name => 'MSC_ST_RESOURCE_REQUIREMENTS',
49308 p_instance_code => v_instance_code,
49309 p_row => lv_column_names,
49310 p_severity => G_SEV_WARNING,
49311 p_message_text => lv_message_text,
49312 p_error_text => lv_error_text,
49313 p_batch_id => lv_batch_id,
49314 p_where_str => lv_where_str,
49315 p_col_name => 'SCHEDULE_FLAG',
49316 p_debug => v_debug,
49317 p_default_value => 1);
49318
49319 IF lv_return <> 0 THEN
49320 RAISE ex_logging_err;
49321 END IF;
49322
49323
49324 -- Error out the records where quantity_in_queue is negative OR quantity_running is negative
49325 -- OR quantity_waiting_to_move is negative OR quantity_completed is negative
49326
49327 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
49328 (p_app_short_name => 'MSC',
49329 p_error_code => 'MSC_PP_CONV_RT_NEG',
49330 p_message_text => lv_message_text,
49331 p_error_text => lv_error_text,
49332 p_token1 => 'COLUMN_NAME',
49333 p_token_value1 => 'QUANTITY_IN_QUEUE AND QUANTITY_RUNNING AND QUANTITY_WAITING_TO_MOVE AND QUANTITY_COMPLETED');
49334
49335 IF lv_return <> 0 THEN
49336 RAISE ex_logging_err;
49337 END IF;
49338
49339 UPDATE msc_st_resource_requirements
49340 SET process_flag = G_ERROR_FLG,
49341 error_text = lv_message_text
49342 WHERE deleted_flag = SYS_NO
49343 AND sr_instance_code = v_instance_code
49344 AND process_flag = G_IN_PROCESS
49345 AND batch_id = lv_batch_id
49346 AND (quantity_in_queue <0 OR quantity_running <0 OR quantity_waiting_to_move <0 OR quantity_completed <0);
49347
49348 -- Updating UNADJUSTED_RESOURCE_HOURS with the value in OPERATION_HOURS_REQUIRED
49349 -- for bug 7565280
49350
49351 UPDATE msc_st_resource_requirements msrr
49352 SET UNADJUSTED_RESOURCE_HOURS = OPERATION_HOURS_REQUIRED
49353 WHERE sr_instance_code = v_instance_code
49354 AND process_flag = G_IN_PROCESS
49355 AND batch_id = lv_batch_id;
49356
49357 --Call to customised validation.
49358
49359 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
49360 (ERRBUF => lv_error_text,
49361 RETCODE => lv_return,
49362 pBatchID => lv_batch_id,
49363 pInstanceCode => v_instance_code,
49364 pEntityName => 'MSC_ST_RESOURCE_REQUIREMENTS',
49365 pInstanceID => v_instance_id);
49366
49367 IF NVL(lv_return,0) <> 0 THEN
49368 RAISE ex_logging_err;
49369 END IF;
49370
49371 v_sql_stmt := 17 ;
49372
49373 OPEN c3(lv_batch_id);
49374 FETCH c3 BULK COLLECT INTO lb_rowid ;
49375
49376 IF c3%ROWCOUNT > 0 THEN
49377
49378 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
49379
49380 UPDATE msc_st_resource_requirements
49381 SET operation_sequence_id = msc_st_operation_sequence_id_s.NEXTVAL ,
49382 operation_seq_num =
49383 to_number(decode(length(rtrim(operation_seq_code,'0123456789')),
49384 NULL,operation_seq_code,'1'))
49385 WHERE rowid = lb_rowid(j);
49386
49387 v_sql_stmt := 18;
49388
49389 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
49390
49391 -- Insert into the LID table
49392 INSERT INTO msc_local_id_setup
49393 (local_id,
49394 st_transaction_id,
49395 instance_id,
49396 entity_name,
49397 data_source_type,
49398 char1,
49399 char2,
49400 char3,
49401 char4,
49402 char5,
49403 char6,
49404 number1,
49405 date1,
49406 SOURCE_ORGANIZATION_ID,
49407 SOURCE_DEPARTMENT_ID,
49408 SOURCE_RESOURCE_ID,
49409 SOURCE_RESOURCE_SEQ_NUM,
49410 SOURCE_OPERATION_SEQUENCE_ID,
49411 SOURCE_WIP_ENTITY_ID,
49412 SOURCE_OPERATION_SEQ_NUM,
49413 last_update_date,
49414 last_updated_by,
49415 creation_date,
49416 created_by )
49417 SELECT
49418 operation_sequence_id,
49419 st_transaction_id,
49420 v_instance_id,
49421 'OPERATION_SEQUENCE_ID',
49422 data_source_type,
49423 v_instance_code,
49424 company_name,
49425 organization_code,
49426 routing_name,
49427 operation_seq_code,
49428 alternate_routing_designator,
49429 operation_seq_num,
49430 operation_effectivity_date,
49431 SOURCE_ORGANIZATION_ID,
49432 SOURCE_DEPARTMENT_ID,
49433 SOURCE_RESOURCE_ID,
49434 SOURCE_RESOURCE_SEQ_NUM,
49435 SOURCE_OPERATION_SEQUENCE_ID,
49436 SOURCE_WIP_ENTITY_ID,
49437 SOURCE_OPERATION_SEQ_NUM,
49438 v_current_date,
49439 v_current_user,
49440 v_current_date,
49441 v_current_user
49442 FROM msc_st_resource_requirements
49443 WHERE rowid = lb_rowid(j);
49444
49445 END IF;
49446 close c3;
49447
49448 -- Update operation_sequence_id
49449
49450 v_sql_stmt := 19;
49451 lv_sql_Stmt :=
49452 'UPDATE msc_st_resource_requirements msrr'
49453 ||' SET (operation_sequence_id, operation_seq_num) = (SELECT local_id, number1'
49454 ||' FROM msc_local_id_setup mlis'
49455 ||' WHERE mlis.char1 = msrr.sr_instance_code'
49456 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
49457 ||' = NVL(msrr.company_name,'||''''||NULL_CHAR||''''||') '
49458 ||' AND mlis.char3 = msrr.organization_code'
49459 ||' AND mlis.char4 = msrr.routing_name'
49460 ||' AND mlis.char5 = TO_CHAR(msrr.operation_seq_code)'
49461 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
49462 ||' = NVL(msrr.alternate_routing_designator,'||''''||NULL_CHAR||''''||')'
49463 ||' AND mlis.date1 = msrr.operation_effectivity_date'
49464 ||' AND mlis.entity_name = ''OPERATION_SEQUENCE_ID'' '
49465 ||' AND mlis.instance_id = '||v_instance_id||')'
49466 ||' WHERE sr_instance_code = :v_instance_code'
49467 ||' AND NVL(operation_sequence_id,'||NULL_VALUE||') ='|| NULL_VALUE
49468 ||' AND process_flag ='||G_IN_PROCESS
49469 ||' AND batch_id = :lv_batch_id';
49470
49471
49472 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
49473
49474 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
49475
49476
49477 OPEN c4(lv_batch_id);
49478 FETCH c4 BULK COLLECT INTO lb_rowid ;
49479
49480 IF c4%ROWCOUNT > 0 THEN
49481
49482 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
49483
49484 UPDATE msc_st_resource_requirements
49485 SET resource_seq_num =
49486 to_number(decode(length(rtrim(resource_seq_code,'0123456789')),
49487 NULL,resource_seq_code,'1'))
49488 WHERE rowid = lb_rowid(j);
49489
49490
49491 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
49492 -- Insert into the LID table with the user defined key
49493
49494 INSERT INTO msc_local_id_setup
49495 (local_id,
49496 st_transaction_id,
49497 instance_id,
49498 entity_name,
49499 data_source_type,
49500 char1,
49501 char2,
49502 char3,
49503 char4,
49504 char5,
49505 char6,
49506 char7,
49507 number1,
49508 SOURCE_ORGANIZATION_ID,
49509 SOURCE_DEPARTMENT_ID,
49510 SOURCE_RESOURCE_ID,
49511 SOURCE_RESOURCE_SEQ_NUM,
49512 SOURCE_OPERATION_SEQUENCE_ID,
49513 SOURCE_WIP_ENTITY_ID,
49514 SOURCE_OPERATION_SEQ_NUM,
49515 last_update_date,
49516 last_updated_by,
49517 creation_date,
49518 created_by )
49519 SELECT
49520 resource_seq_num,
49521 st_transaction_id,
49522 v_instance_id,
49523 'RESOURCE_SEQ_NUM',
49524 data_source_type,
49525 v_instance_code,
49526 company_name,
49527 organization_code,
49528 routing_name,
49529 operation_seq_code,
49530 resource_seq_code,
49531 alternate_routing_designator,
49532 alternate_number,
49533 SOURCE_ORGANIZATION_ID,
49534 SOURCE_DEPARTMENT_ID,
49535 SOURCE_RESOURCE_ID,
49536 SOURCE_RESOURCE_SEQ_NUM,
49537 SOURCE_OPERATION_SEQUENCE_ID,
49538 SOURCE_WIP_ENTITY_ID,
49539 SOURCE_OPERATION_SEQ_NUM,
49540 v_current_date,
49541 v_current_user,
49542 v_current_date,
49543 v_current_user
49544 FROM msc_st_resource_requirements
49545 WHERE rowid = lb_rowid(j) ;
49546
49547 END IF;
49548 CLOSE c4;
49549
49550 -- Update resource seq num from the local id table
49551
49552 lv_sql_stmt :=
49553 'UPDATE msc_st_resource_requirements msor'
49554 ||' SET resource_seq_num = (SELECT local_id '
49555 ||' FROM msc_local_id_setup mlis'
49556 ||' WHERE mlis.char1 = msor.sr_instance_code'
49557 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
49558 ||' = NVL(msor.company_name,'||''''||NULL_CHAR||''''||') '
49559 ||' AND mlis.char3 = msor.organization_code'
49560 ||' AND mlis.char4 = msor.routing_name'
49561 ||' AND mlis.char5 = msor.operation_seq_code'
49562 ||' AND mlis.char6 = msor.resource_seq_code'
49563 ||' AND NVL(mlis.char7,'||''''||NULL_CHAR||''''||') '
49564 ||' = NVL(msor.alternate_routing_designator,'||''''||NULL_CHAR||''''||')'
49565 ||' AND NVL(mlis.number1,'||NULL_VALUE||') = NVL(msor.alternate_number,'||NULL_VALUE||')'
49566 ||' AND rownum = 1' /*change made to solve res req issue*/
49567 ||' AND mlis.entity_name = ''RESOURCE_SEQ_NUM'')'
49568 ||' WHERE sr_instance_code = :v_instance_code'
49569 ||' AND NVL(resource_seq_num,'||NULL_VALUE||') = '||NULL_VALUE
49570 ||' AND process_flag = '||G_IN_PROCESS
49571 ||' AND batch_id = :lv_batch_id';
49572
49573
49574
49575 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
49576
49577 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
49578
49579 -- Set the processf flag as Valid and populate sr_instance_id
49580 lv_return :=
49581 MSC_ST_UTIL.SET_PROCESS_FLAG(p_table_name => 'MSC_ST_RESOURCE_REQUIREMENTS',
49582 p_instance_id => v_instance_id,
49583 p_instance_code => v_instance_code,
49584 p_process_flag => G_VALID,
49585 p_error_text => lv_error_text,
49586 p_debug => v_debug,
49587 p_batch_id => lv_batch_id);
49588
49589 IF lv_return <> 0 THEN
49590 RAISE ex_logging_err;
49591 END IF;
49592
49593
49594 -- At the end calling the LOG_ERROR for logging all errored out records
49595
49596 lv_return :=
49597 MSC_ST_UTIL.LOG_ERROR(p_table_name => 'MSC_ST_RESOURCE_REQUIREMENTS',
49598 p_instance_code => v_instance_code,
49599 p_row => lv_column_names,
49600 p_severity => G_SEV_ERROR,
49601 p_message_text => NULL,
49602 p_error_text => lv_error_text,
49603 p_debug => v_debug,
49604 p_batch_id => lv_batch_id );
49605
49606 IF lv_return <> 0 THEN
49607 RAISE ex_logging_err;
49608 END IF;
49609
49610 COMMIT;
49611 END LOOP;
49612
49613
49614 EXCEPTION
49615
49616 WHEN too_many_rows THEN
49617 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_RES_DEMAND'||'('
49618 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
49619 ROLLBACK ;
49620
49621 WHEN ex_logging_err THEN
49622 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
49623 ROLLBACK;
49624
49625 WHEN OTHERS THEN
49626 lv_error_text :=substr('MSC_CL_PRE_PROCESS.LOAD_RES_DEMAND'||'('
49627 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
49628 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
49629 ROLLBACK;
49630
49631 END LOAD_RES_DEMAND;
49632
49633
49634 /*==========================================================================+
49635 | DESCRIPTION : This procedure is called for validating demand originating |
49636 | from WIP Supply and is for msc_st_demands table. Following |
49637 | types are considered for the validation. |
49638 | Demand origination Origination Type |
49639 | ------------------------------------------------- |
49640 | Std Job Demand 2 |
49641 | Non Std. Demand 3 |
49642 | Flow schedule 25 |
49643 +==========================================================================*/
49644
49645 PROCEDURE LOAD_WIP_DEMAND IS
49646
49647 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
49648
49649 lb_rowid RowidTab;
49650
49651 lv_local_id NUMBER;
49652 lv_sequence NUMBER;
49653 lv_column_names VARCHAR2(5000); -- Stores cocatenated column names
49654 lv_return NUMBER;
49655 lv_error_text VARCHAR2(250);
49656 lv_where_str VARCHAR2(5000);
49657 lv_sql_stmt VARCHAR2(5000);
49658 lv_cursor_stmt VARCHAR2(5000);
49659 lv_batch_id msc_st_demands.batch_id%TYPE;
49660 lv_message_text msc_errors.error_text%TYPE;
49661
49662 ex_logging_err EXCEPTION;
49663
49664 CURSOR c1(p_batch_id NUMBER) IS
49665 SELECT rowid
49666 FROM msc_st_demands
49667 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
49668 AND origination_type IN (2,3,25)
49669 AND batch_id = p_batch_id
49670 AND sr_instance_code = v_instance_code;
49671
49672 CURSOR c2(p_batch_id NUMBER) IS
49673 SELECT max(rowid)
49674 FROM msc_st_demands
49675 WHERE process_flag = G_IN_PROCESS
49676 AND sr_instance_code = v_instance_code
49677 AND batch_id = p_batch_id
49678 AND origination_type IN (2,3) -- Not for flow schedule
49679 AND NVL(operation_seq_num,NULL_VALUE) = NULL_VALUE
49680 AND deleted_flag = SYS_NO
49681 GROUP BY sr_instance_code,company_name,organization_code,routing_name,
49682 operation_seq_code,alternate_routing_designator,operation_effectivity_date;
49683
49684
49685 BEGIN
49686
49687 -- Before we start processing the record by group id( batch size ) we are going
49688 -- to check whether that there
49689 -- is any duplicates for user defined unique keys (UDKs,)
49690
49691 --For WIP component demand
49692
49693 --Duplicate records check for the records whose source is XML
49694 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
49695 (p_app_short_name => 'MSC',
49696 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
49697 p_message_text => lv_message_text,
49698 p_error_text => lv_error_text);
49699
49700 IF lv_return <> 0 THEN
49701 RAISE ex_logging_err;
49702 END IF;
49703
49704 v_sql_stmt := 01;
49705
49706 lv_sql_stmt :=
49707 'UPDATE msc_st_demands msd1'
49708 ||' SET process_flag = '||G_ERROR_FLG||','
49709 ||' error_text = '||''''||lv_message_text||''''
49710 ||' WHERE message_id < (SELECT MAX(message_id)'
49711 ||' FROM msc_st_demands msd2'
49712 ||' WHERE msd2.sr_instance_code '
49713 ||' = msd1.sr_instance_code '
49714 ||' AND msd2.organization_code '
49715 ||' = msd1.organization_code '
49716 ||' AND NVL(msd2.company_name,'||''''||NULL_CHAR||''''||') '
49717 ||' = NVL(msd1.company_name,'||''''||NULL_CHAR||''''||') '
49718 ||' AND msd2.wip_entity_name = msd1.wip_entity_name'
49719 ||' AND NVL(msd2.operation_seq_code,'||''''||NULL_CHAR||''''||') '
49720 ||' = NVL(msd1.operation_seq_code,'||''''||NULL_CHAR||''''||') '
49721 ||' AND msd2.item_name '
49722 ||' = msd1.item_name '
49723 ||' AND msd2.origination_type '
49724 ||' = msd1.origination_type'
49725 ||' AND msd2.process_flag = '||G_IN_PROCESS
49726 ||' AND NVL(msd2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||')'
49727 ||' AND msd1.process_flag ='|| G_IN_PROCESS
49728 ||' AND msd1.origination_type IN (2,3,25)'
49729 ||' AND msd1.sr_instance_code = :v_instance_code '
49730 ||' AND NVL(msd1.message_id,'||NULL_VALUE||')<> '||NULL_VALUE;
49731
49732
49733 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
49734
49735 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
49736
49737 --Duplicate records check for the records whose source is batch load
49738
49739 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
49740 (p_app_short_name => 'MSC',
49741 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
49742 p_message_text => lv_message_text,
49743 p_error_text => lv_error_text);
49744
49745 IF lv_return <> 0 THEN
49746 RAISE ex_logging_err;
49747 END IF;
49748
49749 v_sql_stmt := 02;
49750
49751 lv_sql_stmt :=
49752 'UPDATE msc_st_demands msd1'
49753 ||' SET process_flag = '||G_ERROR_FLG||','
49754 ||' error_text = '||''''||lv_message_text||''''
49755 ||' WHERE EXISTS( SELECT 1 '
49756 ||' FROM msc_st_demands msd2'
49757 ||' WHERE msd2.sr_instance_code '
49758 ||' = msd1.sr_instance_code '
49759 ||' AND msd2.organization_code '
49760 ||' = msd1.organization_code '
49761 ||' AND NVL(msd2.company_name,'||''''||NULL_CHAR||''''||') '
49762 ||' = NVL(msd1.company_name,'||''''||NULL_CHAR||''''||') '
49763 ||' AND msd2.wip_entity_name = msd1.wip_entity_name'
49764 ||' AND NVL(msd2.operation_seq_code,'||''''||NULL_CHAR||''''||') '
49765 ||' = NVL(msd1.operation_seq_code,'||''''||NULL_CHAR||''''||') '
49766 ||' AND msd2.item_name '
49767 ||' = msd1.item_name '
49768 ||' AND msd2.origination_type '
49769 ||' = msd1.origination_type'
49770 ||' AND msd2.process_flag = '||G_IN_PROCESS
49771 ||' AND NVL(msd2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
49772 ||' GROUP BY sr_instance_code,organization_code,wip_entity_name,'
49773 ||' company_name,operation_seq_code,item_name,origination_type'
49774 ||' HAVING COUNT(*) > 1)'
49775 ||' AND msd1.process_flag = '||G_IN_PROCESS
49776 ||' AND msd1.origination_type IN (2,3,25)'
49777 ||' AND msd1.sr_instance_code = :v_instance_code'
49778 ||' AND NVL(msd1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
49779
49780
49781 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
49782
49783 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
49784
49785 lv_column_names :=
49786 'ITEM_NAME ||''~''||'
49787 ||' ORGANIZATION_CODE ||''~''||'
49788 ||' USING_REQUIREMENT_QUANTITY ||''~''||'
49789 ||' WIP_ENTITY_NAME ||''~''||'
49790 ||' USING_ASSEMBLY_DEMAND_DATE ||''~''||'
49791 ||' SR_INSTANCE_CODE ||''~''||'
49792 ||' USING_ASSEMBLY_ITEM_NAME ||''~''||'
49793 ||' OPERATION_SEQ_CODE ||''~''||'
49794 ||' ORIGINATION_TYPE ||''~''||'
49795 ||' PROJECT_NUMBER ||''~''||'
49796 ||' TASK_NUMBER ||''~''||'
49797 ||' PLANNING_GROUP ||''~''||'
49798 ||' END_ITEM_UNIT_NUMBER ||''~''||'
49799 ||' DEMAND_CLASS ||''~''||'
49800 ||' WIP_STATUS_CODE ||''~''||'
49801 ||' WIP_SUPPLY_TYPE ||''~''||'
49802 ||' DELETED_FLAG ||''~''||'
49803 ||' COMPANY_NAME ||''~''||'
49804 ||' DEMAND_TYPE' ;
49805
49806
49807 LOOP
49808 v_sql_stmt := 03;
49809 SELECT msc_st_batch_id_s.NEXTVAL
49810 INTO lv_batch_id
49811 FROM DUAL;
49812
49813 v_sql_stmt := 04;
49814 lv_sql_stmt :=
49815 ' UPDATE msc_st_demands '
49816 ||' SET batch_id = :lv_batch_id'
49817 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
49818 ||' AND sr_instance_code = :v_instance_code'
49819 ||' AND origination_type IN (2,3,25)'
49820 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
49821 ||' AND rownum <= '||v_batch_size;
49822
49823
49824
49825 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
49826
49827 EXECUTE IMMEDIATE lv_sql_stmt
49828 USING lv_batch_id,
49829 v_instance_code;
49830
49831 EXIT WHEN SQL%NOTFOUND ;
49832
49833 OPEN c1(lv_batch_id);
49834 FETCH c1 BULK COLLECT INTO lb_rowid;
49835 CLOSE c1;
49836
49837 v_sql_stmt := 03;
49838 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
49839 UPDATE msc_st_demands
49840 SET st_transaction_id = msc_st_demands_s.NEXTVAL,
49841 refresh_id = v_refresh_id,
49842 last_update_date = v_current_date,
49843 last_updated_by = v_current_user,
49844 creation_date = v_current_date,
49845 created_by = v_current_user
49846 WHERE rowid = lb_rowid(j);
49847
49848 -- Set the error message
49849 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
49850 (p_app_short_name => 'MSC',
49851 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
49852 p_message_text => lv_message_text,
49853 p_error_text => lv_error_text,
49854 p_token1 => 'COLUMN_NAME',
49855 p_token_value1 => 'DELETED_FLAG',
49856 p_token2 => 'DEFAULT_VALUE',
49857 p_token_value2 => SYS_NO );
49858
49859 IF lv_return <> 0 THEN
49860 RAISE ex_logging_err;
49861 END IF;
49862 --Log a warning for those records where the deleted_flag has a value other
49863 --SYS_NO
49864
49865 lv_where_str :=
49866 ' AND NVL(deleted_flag,'||NULL_VALUE||') NOT IN(1,2)';
49867
49868 lv_return := MSC_ST_UTIL.LOG_ERROR
49869 (p_table_name => 'MSC_ST_DEMANDS',
49870 p_instance_code => v_instance_code,
49871 p_row => lv_column_names,
49872 p_severity => G_SEV_WARNING,
49873 p_message_text => lv_message_text,
49874 p_error_text => lv_error_text,
49875 p_batch_id => lv_batch_id,
49876 p_where_str => lv_where_str,
49877 p_col_name => 'DELETED_FLAG',
49878 p_debug => v_debug,
49879 p_default_value => SYS_NO);
49880
49881 IF lv_return <> 0 THEN
49882 RAISE ex_logging_err;
49883 END IF;
49884
49885 -- Set the message
49886 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
49887 (p_app_short_name => 'MSC',
49888 p_error_code => 'MSC_PP_INVALID_VALUE',
49889 p_message_text => lv_message_text,
49890 p_error_text => lv_error_text,
49891 p_token1 => 'COLUMN_NAME',
49892 p_token_value1 => 'ORGANIZATION_CODE');
49893
49894 IF lv_return <> 0 THEN
49895 RAISE ex_logging_err;
49896 END IF;
49897
49898 --Derive Organization_id
49899 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
49900 (p_table_name => 'MSC_ST_DEMANDS',
49901 p_org_partner_name => 'ORGANIZATION_CODE',
49902 p_org_partner_id => 'ORGANIZATION_ID',
49903 p_instance_code => v_instance_code,
49904 p_partner_type => G_ORGANIZATION,
49905 p_error_text => lv_error_text,
49906 p_batch_id => lv_batch_id,
49907 p_severity => G_SEV_ERROR,
49908 p_message_text => lv_message_text,
49909 p_debug => v_debug,
49910 p_row => lv_column_names);
49911
49912 IF lv_return <> 0 THEN
49913 RAISE ex_logging_err;
49914 END IF;
49915
49916 -- Set the message
49917 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
49918 (p_app_short_name => 'MSC',
49919 p_error_code => 'MSC_PP_INVALID_VALUE',
49920 p_message_text => lv_message_text,
49921 p_error_text => lv_error_text,
49922 p_token1 => 'COLUMN_NAME',
49923 p_token_value1 => 'ITEM_NAME');
49924
49925 IF lv_return <> 0 THEN
49926 RAISE ex_logging_err;
49927 END IF;
49928
49929 --Derive Inventory_item_id
49930 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
49931 (p_table_name => 'MSC_ST_DEMANDS',
49932 p_item_col_name => 'ITEM_NAME',
49933 p_item_col_id => 'INVENTORY_ITEM_ID',
49934 p_instance_id => v_instance_id,
49935 p_instance_code => v_instance_code,
49936 p_message_text => lv_message_text,
49937 p_error_text => lv_error_text,
49938 p_batch_id => lv_batch_id,
49939 p_severity => G_SEV_ERROR,
49940 p_debug => v_debug,
49941 p_row => lv_column_names);
49942
49943 IF lv_return <> 0 THEN
49944 RAISE ex_logging_err;
49945 END IF;
49946
49947 -- Set the message
49948 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
49949 (p_app_short_name => 'MSC',
49950 p_error_code => 'MSC_PP_INVALID_VALUE',
49951 p_message_text => lv_message_text,
49952 p_error_text => lv_error_text,
49953 p_token1 => 'COLUMN_NAME',
49954 p_token_value1 => 'USING_ASSEMBLY_ITEM_NAME');
49955
49956 IF lv_return <> 0 THEN
49957 RAISE ex_logging_err;
49958 END IF;
49959
49960 --Derive Using_assembly_item_id
49961 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
49962 (p_table_name => 'MSC_ST_DEMANDS',
49963 p_item_col_name => 'USING_ASSEMBLY_ITEM_NAME',
49964 p_item_col_id => 'USING_ASSEMBLY_ITEM_ID',
49965 p_instance_id => v_instance_id,
49966 p_instance_code => v_instance_code,
49967 p_message_text => lv_message_text,
49968 p_error_text => lv_error_text,
49969 p_batch_id => lv_batch_id,
49970 p_severity => G_SEV3_ERROR,
49971 p_debug => v_debug,
49972 p_row => lv_column_names);
49973
49974 IF lv_return <> 0 THEN
49975 RAISE ex_logging_err;
49976 END IF;
49977
49978 -- Derive WIP_ENTITY_ID
49979 v_sql_stmt := 04;
49980
49981 lv_sql_stmt :=
49982 'UPDATE msc_st_demands msd'
49983 ||' SET wip_entity_id = ( SELECT local_id '
49984 ||' FROM msc_local_id_supply mlid'
49985 ||' WHERE mlid.char1 = msd.sr_instance_code'
49986 ||' AND NVL(mlid.char2,'||''''||NULL_CHAR||''''||') '
49987 ||' = NVL(msd.company_name,'||''''||NULL_CHAR||''''||') '
49988 ||' AND mlid.char3 = msd.organization_code'
49989 ||' AND mlid.char4 = msd.wip_entity_name'
49990 ||' AND mlid.entity_name = ''WIP_ENTITY_ID'' )'
49991 ||' WHERE origination_type IN (2,3,25) '
49992 ||' AND process_flag ='||G_IN_PROCESS
49993 ||' AND batch_id = :lv_batch_id'
49994 ||' AND sr_instance_code =:v_instance_code';
49995
49996
49997 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
49998
49999 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
50000
50001 -- Set the error message
50002 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
50003 (p_app_short_name => 'MSC',
50004 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
50005 p_message_text => lv_message_text,
50006 p_error_text => lv_error_text,
50007 p_token1 => 'COLUMN_NAMES',
50008 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
50009 ||' ORGANIZATION_CODE,WIP_ENTITY_NAME',
50010 p_token2 => 'MASTER_TABLE',
50011 p_token_value2 => 'MSC_ST_SUPPLIES',
50012 p_token3 => 'CHILD_TABLE' ,
50013 p_token_value3 => 'MSC_ST_DEMANDS' );
50014
50015 IF lv_return <> 0 THEN
50016 RAISE ex_logging_err;
50017 END IF;
50018
50019 -- Error out records where WIP_ENTITY_ID is NULL;
50020
50021 v_sql_stmt := 05;
50022 lv_sql_stmt :=
50023 'UPDATE msc_st_demands '
50024 ||' SET process_flag = '||G_ERROR_FLG||','
50025 ||' error_text = '||''''||lv_message_text||''''
50026 ||' WHERE NVL(wip_entity_id,'||NULL_VALUE||') ='||NULL_VALUE
50027 ||' AND process_flag = '||G_IN_PROCESS
50028 ||' AND origination_type IN (2,3,25)'
50029 ||' AND batch_id = :lv_batch_id'
50030 ||' AND sr_instance_code = :v_instance_code';
50031
50032
50033 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
50034
50035 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
50036
50037
50038 -- Set the message
50039 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
50040 (p_app_short_name => 'MSC',
50041 p_error_code => 'MSC_PP_COL_VAL_NULL',
50042 p_message_text => lv_message_text,
50043 p_error_text => lv_error_text,
50044 p_token1 => 'COLUMN_NAME',
50045 p_token_value1 => 'USING_REQUIREMENT_QUANTITY'
50046 || ' OR USING_ASSEMBLY_DEMAND_DATE');
50047
50048 IF lv_return <> 0 THEN
50049 RAISE ex_logging_err;
50050 END IF;
50051
50052
50053 -- Error out records where USING_REQUIREMENT_QUANTITY is NULL;
50054 -- Error out records where using_assembly_demand_date is NULL
50055
50056 v_sql_stmt := 06;
50057 lv_sql_stmt :=
50058 'UPDATE msc_st_demands '
50059 ||' SET process_flag = '||G_ERROR_FLG||','
50060 ||' error_text = '||''''||lv_message_text||''''
50061 ||' WHERE (NVL(using_requirement_quantity,'||NULL_VALUE||')='||NULL_VALUE
50062 ||' OR NVL(using_assembly_demand_date,SYSDATE-36500) = SYSDATE-36500 )'
50063 ||' AND process_flag = '||G_IN_PROCESS
50064 ||' AND origination_type IN (2,3,25)'
50065 ||' AND deleted_flag = '||SYS_NO
50066 ||' AND batch_id = :lv_batch_id'
50067 ||' AND sr_instance_code = :v_instance_code';
50068
50069
50070 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
50071
50072 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
50073
50074
50075 -- Update using_assembly_item_id = inventory_item_id
50076
50077 v_sql_stmt := 07;
50078 lv_sql_stmt :=
50079 ' UPDATE msc_st_demands'
50080 ||' SET using_assembly_item_id = inventory_item_id'
50081 ||' WHERE process_flag = '||G_IN_PROCESS
50082 ||' AND NVL(using_assembly_item_id,'||NULL_VALUE||') = '||NULL_VALUE
50083 ||' AND deleted_flag = '||SYS_NO
50084 ||' AND process_flag = '||G_IN_PROCESS
50085 ||' AND origination_type IN (2,3,25)'
50086 ||' AND batch_id = :lv_batch_id'
50087 ||' AND deleted_flag = '||SYS_NO
50088 ||' AND sr_instance_code = :v_instance_code';
50089
50090
50091 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
50092
50093 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
50094
50095 -- Update order_number = wip_entity_name
50096
50097 v_sql_stmt := 08;
50098 lv_sql_stmt :=
50099 ' UPDATE msc_st_demands'
50100 ||' SET order_number = wip_entity_name'
50101 ||' WHERE process_flag = '||G_IN_PROCESS
50102 ||' AND deleted_flag = '||SYS_NO
50103 ||' AND process_flag = '||G_IN_PROCESS
50104 ||' AND origination_type IN (2,3,25)'
50105 ||' AND deleted_flag = '||SYS_NO
50106 ||' AND batch_id = :lv_batch_id'
50107 ||' AND sr_instance_code = :v_instance_code';
50108
50109
50110 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
50111
50112 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
50113
50114 -- Update disposition_id = wip_entity_id
50115
50116 v_sql_stmt := 09;
50117 lv_sql_stmt :=
50118 ' UPDATE msc_st_demands'
50119 ||' SET disposition_id = wip_entity_id'
50120 ||' WHERE process_flag = '||G_IN_PROCESS
50121 ||' AND NVL(wip_entity_id,'||NULL_VALUE||') = '||NULL_VALUE
50122 ||' AND deleted_flag = '||SYS_NO
50123 ||' AND process_flag = '||G_IN_PROCESS
50124 ||' AND origination_type IN (2,3,25)'
50125 ||' AND batch_id = :lv_batch_id'
50126 ||' AND sr_instance_code = :v_instance_code';
50127
50128
50129 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
50130
50131 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
50132
50133
50134
50135 -- UPdate MPS_DATE_REQUIRED as using_assembly_demand_date if NULL
50136 -- This is not reqd for flow schedule
50137
50138 v_sql_stmt := 10;
50139 lv_sql_stmt :=
50140 ' UPDATE msc_st_demands'
50141 ||' SET mps_date_required = using_assembly_demand_date'
50142 ||' WHERE process_flag = '||G_IN_PROCESS
50143 ||' AND NVL(mps_date_required,SYSDATE-36500) = SYSDATE-36500'
50144 ||' AND process_flag = '||G_IN_PROCESS
50145 ||' AND origination_type IN (2,3)'
50146 ||' AND deleted_flag = '||SYS_NO
50147 ||' AND batch_id = :lv_batch_id'
50148 ||' AND sr_instance_code = :v_instance_code';
50149
50150
50151 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
50152
50153 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
50154
50155
50156 -- Set the error message
50157 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
50158 (p_app_short_name => 'MSC',
50159 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
50160 p_message_text => lv_message_text,
50161 p_error_text => lv_error_text,
50162 p_token1 => 'COLUMN_NAME',
50163 p_token_value1 => 'OPERATION_SEQ_CODE',
50164 p_token2 => 'DEFAULT_VALUE',
50165 p_token_value2 => G_OPERATION_SEQ_CODE );
50166
50167 IF lv_return <> 0 THEN
50168 RAISE ex_logging_err;
50169 END IF;
50170
50171 -- Default operation_seq_code as 1 if NULL
50172 lv_where_str :=
50173 ' AND NVL(operation_seq_code,'||''''||NULL_CHAR||''''||') '
50174 ||' = '||''''||NULL_CHAR||''''
50175 ||' AND origination_type IN (2,3)';
50176
50177 lv_return := MSC_ST_UTIL.LOG_ERROR
50178 (p_table_name => 'MSC_ST_DEMANDS',
50179 p_instance_code => v_instance_code,
50180 p_row => lv_column_names,
50181 p_severity => G_SEV_WARNING,
50182 p_message_text => lv_message_text,
50183 p_error_text => lv_error_text,
50184 p_batch_id => lv_batch_id,
50185 p_where_str => lv_where_str,
50186 p_col_name => 'OPERATION_SEQ_CODE',
50187 p_debug => v_debug,
50188 p_default_value => G_OPERATION_SEQ_CODE);
50189
50190 IF lv_return <> 0 THEN
50191 RAISE ex_logging_err;
50192 END IF;
50193
50194 -- Set the error message
50195 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
50196 (p_app_short_name => 'MSC',
50197 p_error_code => 'MSC_PP_COL_VAL_NULL_DEFAULT',
50198 p_message_text => lv_message_text,
50199 p_error_text => lv_error_text,
50200 p_token1 => 'COLUMN_NAME',
50201 p_token_value1 => 'OPERATION_EFFECTIVITY_DATE',
50202 p_token2 => 'DEFAULT_VALUE',
50203 p_token_value2 => SYSDATE );
50204
50205 IF lv_return <> 0 THEN
50206 RAISE ex_logging_err;
50207 END IF;
50208
50209 -- Default operation_effectivity date as SYSDATE if NULL
50210
50211 lv_where_str :=
50212 ' AND NVL(operation_effectivity_date,SYSDATE-36500 ) = SYSDATE-36500 '
50213 ||' AND origination_type IN (2,3)' ;
50214
50215 lv_return := MSC_ST_UTIL.LOG_ERROR
50216 (p_table_name => 'MSC_ST_DEMANDS',
50217 p_instance_code => v_instance_code,
50218 p_row => lv_column_names,
50219 p_severity => G_SEV_WARNING,
50220 p_message_text => lv_message_text,
50221 p_error_text => lv_error_text,
50222 p_batch_id => lv_batch_id,
50223 p_where_str => lv_where_str,
50224 p_col_name => 'OPERATION_EFFECTIVITY_DATE',
50225 p_debug => v_debug,
50226 p_default_value => 'SYSDATE');
50227
50228 IF lv_return <> 0 THEN
50229 RAISE ex_logging_err;
50230 END IF;
50231
50232 -- If routing_name is is NULL populate the item_name in routing name
50233
50234 v_sql_stmt := 11;
50235 lv_sql_stmt :=
50236 ' UPDATE msc_st_demands'
50237 ||' SET routing_name = nvl(USING_ASSEMBLY_ITEM_NAME,item_name)' /* bug 3768813 */
50238 ||' WHERE process_flag = '||G_IN_PROCESS
50239 ||' AND NVL(routing_name,'||''''||NULL_CHAR||''''||')'
50240 ||' = '||''''||NULL_CHAR||''''
50241 ||' AND process_flag = '||G_IN_PROCESS
50242 ||' AND origination_type IN (2,3)'
50243 ||' AND batch_id = :lv_batch_id'
50244 ||' AND sr_instance_code = :v_instance_code';
50245
50246
50247 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
50248
50249 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
50250
50251 /* bug 3768813 */
50252 IF v_instance_type <> G_INS_OTHER THEN
50253
50254 -- Derive the ROUTING_SEQUENCE_ID from LOCAL ID table
50255
50256 lv_return :=msc_st_util.derive_routing_sequence_id
50257 (p_table_name => 'MSC_ST_DEMANDS',
50258 p_rtg_col_name => 'ROUTING_NAME',
50259 p_rtg_col_id =>'ROUTING_SEQUENCE_ID',
50260 p_instance_code => v_instance_code,
50261 p_batch_id => lv_batch_id,
50262 p_debug => v_debug,
50263 p_error_text => lv_error_text,
50264 p_item_id => 'using_assembly_item_id');
50265
50266 if (lv_return <> 0 )then
50267 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
50268 end if;
50269
50270 v_sql_stmt := 11;
50271 lv_sql_stmt:=
50272 'update msc_st_demands msd'
50273 ||' set operation_seq_num = '
50274 ||' (select operation_seq_num '
50275 ||' from msc_routing_operations mro '
50276 ||' where mro.routing_sequence_id = msd.routing_sequence_id and '
50277 ||' mro.effectivity_date = msd.operation_effectivity_date and '
50278 ||' mro.SR_INSTANCE_ID = '||v_instance_id||' and '
50279 ||' mro.operation_seq_num = to_number(decode(length(rtrim(msd.operation_seq_code,''0123456789'')),'
50280 ||' NULL,msd.operation_seq_code,''1'')) and'
50281 ||' mro.plan_id = -1 and '
50282 ||' mro.operation_type = 1)'
50283 ||' WHERE sr_instance_code = :v_instance_code'
50284 ||' AND process_flag = '|| G_IN_PROCESS
50285 ||' AND batch_id = :lv_batch_id ';
50286
50287
50288 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
50289
50290 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
50291 END IF;
50292
50293 -- Derive operation seq num from local id table
50294
50295 v_sql_stmt := 12;
50296 lv_sql_stmt:=
50297 'UPDATE msc_st_demands msd'
50298 ||' SET operation_seq_num= (SELECT number1'
50299 ||' FROM msc_local_id_setup mlis'
50300 ||' WHERE mlis.char1 = msd.sr_instance_code'
50301 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
50302 ||' = NVL(msd.company_name,'||''''||NULL_CHAR||''''||') '
50303 ||' AND mlis.char3 = msd.organization_code'
50304 ||' AND mlis.char4 = msd.routing_name'
50305 ||' AND mlis.char5 = msd.operation_seq_code'
50306 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
50307 ||' = NVL(msd.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
50308 ||' AND mlis.date1 = msd.operation_effectivity_date'
50309 ||' AND mlis.entity_name = ''OPERATION_SEQUENCE_ID'') '
50310 ||' WHERE sr_instance_code = :v_instance_code'
50311 ||' AND process_flag = '||G_IN_PROCESS
50312 ||' AND batch_id = :lv_batch_id'
50313 ||' AND operation_seq_num is null'; /* bug 3768813 */
50314
50315
50316
50317 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
50318
50319 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
50320
50321 -- Set the message
50322
50323 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
50324 (p_app_short_name => 'MSC',
50325 p_error_code => 'MSC_PP_DELETE_FAIL',
50326 p_message_text => lv_message_text,
50327 p_error_text => lv_error_text);
50328
50329 IF lv_return <> 0 THEN
50330 RAISE ex_logging_err;
50331 END IF;
50332
50333 -- Error out the records where operation_seq_num is NULL
50334 -- And deleted_flag = SYS_YES
50335
50336 v_sql_stmt := 13;
50337
50338 lv_sql_stmt :=
50339 'UPDATE msc_st_demands '
50340 ||' SET process_flag ='||G_ERROR_FLG||','
50341 ||' error_text = '||''''||lv_message_text||''''
50342 ||' WHERE NVL(operation_seq_num,'||NULL_VALUE||') = '||NULL_VALUE
50343 ||' AND deleted_flag ='||SYS_YES
50344 ||' AND origination_type IN (2,3)'
50345 ||' AND batch_id = :lv_batch_id'
50346 ||' AND sr_instance_code =:v_instance_code';
50347
50348
50349 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
50350
50351 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
50352
50353 -- Set the error message
50354 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
50355 (p_app_short_name => 'MSC',
50356 p_error_code => 'MSC_PP_FK_REF_NOT_EXIST',
50357 p_message_text => lv_message_text,
50358 p_error_text => lv_error_text,
50359 p_token1 => 'COLUMN_NAMES',
50360 p_token_value1 => ' SR_INSTANCE_CODE, COMPANY_NAME,'
50361 ||' ORGANIZATION_CODE AND PROJECT_NUMBER',
50362 p_token2 => 'MASTER_TABLE',
50363 p_token_value2 => 'MSC_ST_PROJECT_TASKS');
50364
50365 IF lv_return <> 0 THEN
50366 RAISE ex_logging_err;
50367 END IF;
50368
50369 --Derive Project Id.
50370 lv_return := MSC_ST_UTIL.DERIVE_PROJ_TASK_ID
50371 (p_table_name => 'MSC_ST_DEMANDS',
50372 p_proj_col_name => 'PROJECT_NUMBER',
50373 p_proj_task_col_id => 'PROJECT_ID',
50374 p_instance_code => v_instance_code,
50375 p_entity_name => 'PROJECT_ID',
50376 p_error_text => lv_error_text,
50377 p_batch_id => lv_batch_id,
50378 p_severity => G_SEV_WARNING,
50379 p_message_text => lv_message_text,
50380 p_debug => v_debug,
50381 p_row => lv_column_names);
50382 IF lv_return <> 0 THEN
50383 RAISE ex_logging_err;
50384 END IF;
50385
50386 -- Set the error message
50387 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
50388 (p_app_short_name => 'MSC',
50389 p_error_code => 'MSC_PP_FK_REF_NOT_EXIST',
50390 p_message_text => lv_message_text,
50391 p_error_text => lv_error_text,
50392 p_token1 => 'COLUMN_NAMES',
50393 p_token_value1 => ' SR_INSTANCE_CODE, COMPANY_NAME,'
50394 ||' ORGANIZATION_CODE, PROJECT_NUMBER,'
50395 ||' TASK_NUMBER',
50396 p_token2 => 'MASTER_TABLE',
50397 p_token_value2 => 'MSC_ST_PROJECT_TASKS');
50398
50399 IF lv_return <> 0 THEN
50400 RAISE ex_logging_err;
50401 END IF;
50402
50403 --Derive Task Id.
50404 lv_return := MSC_ST_UTIL.DERIVE_PROJ_TASK_ID
50405 (p_table_name => 'MSC_ST_DEMANDS',
50406 p_proj_col_name => 'PROJECT_NUMBER',
50407 p_proj_task_col_id => 'TASK_ID',
50408 p_instance_code => v_instance_code,
50409 p_entity_name => 'TASK_ID',
50410 p_error_text => lv_error_text,
50411 p_task_col_name => 'TASK_NUMBER',
50412 p_batch_id => lv_batch_id,
50413 p_severity => G_SEV_WARNING,
50414 p_message_text => lv_message_text,
50415 p_debug => v_debug,
50416 p_row => lv_column_names);
50417
50418 IF lv_return <> 0 THEN
50419 RAISE ex_logging_err;
50420 END IF;
50421
50422 -- Set the error message
50423 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
50424 (p_app_short_name => 'MSC',
50425 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
50426 p_message_text => lv_message_text,
50427 p_error_text => lv_error_text,
50428 p_token1 => 'COLUMN_NAME',
50429 p_token_value1 => 'DEMAND_TYPE',
50430 p_token2 => 'DEFAULT_VALUE',
50431 p_token_value2 => G_DEMAND_TYPE );
50432
50433 IF lv_return <> 0 THEN
50434 RAISE ex_logging_err;
50435 END IF;
50436
50437 -- Default demand_type to 1 always
50438
50439 lv_where_str := ' AND NVL(demand_type,'||NULL_VALUE||') <> '||G_DEMAND_TYPE
50440 ||' AND origination_type IN (2,3) AND deleted_flag ='||SYS_NO ;
50441
50442 lv_return := MSC_ST_UTIL.LOG_ERROR
50443 (p_table_name => 'MSC_ST_DEMANDS',
50444 p_instance_code => v_instance_code,
50445 p_row => lv_column_names,
50446 p_severity => G_SEV_WARNING,
50447 p_message_text => lv_message_text,
50448 p_error_text => lv_error_text,
50449 p_batch_id => lv_batch_id,
50450 p_where_str => lv_where_str,
50451 p_col_name => 'DEMAND_TYPE',
50452 p_debug => v_debug,
50453 p_default_value => G_DEMAND_TYPE);
50454
50455 IF lv_return <> 0 THEN
50456 RAISE ex_logging_err;
50457 END IF;
50458
50459
50460 -- Default demand_type to 2 always for flow schedule
50461
50462 lv_where_str := ' AND NVL(demand_type,'||NULL_VALUE||') <> 2'
50463 ||' AND origination_type = 25 AND deleted_flag ='||SYS_NO ;
50464
50465 lv_return := MSC_ST_UTIL.LOG_ERROR
50466 (p_table_name => 'MSC_ST_DEMANDS',
50467 p_instance_code => v_instance_code,
50468 p_row => lv_column_names,
50469 p_severity => G_SEV_WARNING,
50470 p_message_text => lv_message_text,
50471 p_error_text => lv_error_text,
50472 p_batch_id => lv_batch_id,
50473 p_where_str => lv_where_str,
50474 p_col_name => 'DEMAND_TYPE',
50475 p_debug => v_debug,
50476 p_default_value => 2);
50477
50478 IF lv_return <> 0 THEN
50479 RAISE ex_logging_err;
50480 END IF;
50481
50482
50483 -- Set the error message
50484 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
50485 (p_app_short_name => 'MSC',
50486 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
50487 p_message_text => lv_message_text,
50488 p_error_text => lv_error_text,
50489 p_token1 => 'COLUMN_NAME',
50490 p_token_value1 => 'WIP_SUPPLY_TYPE',
50491 p_token2 => 'DEFAULT_VALUE',
50492 p_token_value2 => G_WIP_SUPPLY_TYPE );
50493
50494 IF lv_return <> 0 THEN
50495 RAISE ex_logging_err;
50496 END IF;
50497
50498 -- Default wip_supply_type as 1
50499
50500 lv_where_str := ' AND NVL(wip_supply_type,'||NULL_VALUE||') NOT IN (1,2,3,4,5,6,7)'
50501 ||' AND origination_type IN (2,3) AND deleted_flag ='||SYS_NO ;
50502
50503 lv_return := MSC_ST_UTIL.LOG_ERROR
50504 (p_table_name => 'MSC_ST_DEMANDS',
50505 p_instance_code => v_instance_code,
50506 p_row => lv_column_names,
50507 p_severity => G_SEV_WARNING,
50508 p_message_text => lv_message_text,
50509 p_error_text => lv_error_text,
50510 p_batch_id => lv_batch_id,
50511 p_where_str => lv_where_str,
50512 p_col_name => 'WIP_SUPPLY_TYPE',
50513 p_debug => v_debug,
50514 p_default_value => G_WIP_SUPPLY_TYPE );
50515
50516 IF lv_return <> 0 THEN
50517 RAISE ex_logging_err;
50518 END IF;
50519
50520
50521 -- Set the error message
50522 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
50523 (p_app_short_name => 'MSC',
50524 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
50525 p_message_text => lv_message_text,
50526 p_error_text => lv_error_text,
50527 p_token1 => 'COLUMN_NAME',
50528 p_token_value1 => 'WIP_STATUS_CODE',
50529 p_token2 => 'DEFAULT_VALUE',
50530 p_token_value2 => G_WIP_STATUS_CODE );
50531
50532 IF lv_return <> 0 THEN
50533 RAISE ex_logging_err;
50534 END IF;
50535
50536 -- Default wip_status_code as 1(unrelased)
50537
50538 lv_where_str := ' AND NVL(wip_status_code,'||NULL_VALUE||') NOT IN (1,3,4,6,7,12)'
50539 ||' AND origination_type IN (2,3,25)AND deleted_flag ='||SYS_NO ;
50540
50541 lv_return := MSC_ST_UTIL.LOG_ERROR
50542 (p_table_name => 'MSC_ST_DEMANDS',
50543 p_instance_code => v_instance_code,
50544 p_row => lv_column_names,
50545 p_severity => G_SEV_WARNING,
50546 p_message_text => lv_message_text,
50547 p_error_text => lv_error_text,
50548 p_batch_id => lv_batch_id,
50549 p_where_str => lv_where_str,
50550 p_col_name => 'WIP_STATUS_CODE',
50551 p_debug => v_debug,
50552 p_default_value => G_WIP_STATUS_CODE);
50553
50554 IF lv_return <> 0 THEN
50555 RAISE ex_logging_err;
50556 END IF;
50557
50558 --Call to customised validation.
50559 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
50560 (ERRBUF => lv_error_text,
50561 RETCODE => lv_return,
50562 pBatchID => lv_batch_id,
50563 pInstanceCode => v_instance_code,
50564 pEntityName => 'MSC_ST_DEMANDS',
50565 pInstanceID => v_instance_id);
50566
50567 IF NVL(lv_return,0) <> 0 THEN
50568 RAISE ex_logging_err;
50569 END IF;
50570
50571 -- Generate the operation_seq_num and populate the LID table
50572
50573 OPEN c2(lv_batch_id);
50574 FETCH c2 BULK COLLECT INTO lb_rowid ;
50575
50576
50577 IF c2%ROWCOUNT > 0 THEN
50578 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
50579
50580 -- SELECT msc_st_operation_sequence_id_s.NEXTVAL
50581 -- INTO lv_local_id
50582 -- FROM DUAL;
50583
50584 UPDATE msc_st_demands
50585 SET operation_seq_num =
50586 to_number(decode(length(rtrim(operation_seq_code,'0123456789')),
50587 NULL,operation_seq_code,'1'))
50588 WHERE rowid = lb_rowid(j);
50589
50590 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
50591
50592 -- Insert into the LID table
50593
50594 INSERT INTO msc_local_id_setup
50595 (local_id,
50596 st_transaction_id,
50597 instance_id,
50598 entity_name,
50599 data_source_type,
50600 char1,
50601 char2,
50602 char3,
50603 char4,
50604 char5,
50605 char6,
50606 number1,
50607 date1,
50608 SOURCE_ORGANIZATION_ID,
50609 SOURCE_INVENTORY_ITEM_ID,
50610 SOURCE_PROJECT_ID,
50611 SOURCE_TASK_ID,
50612 SOURCE_WIP_ENTITY_ID,
50613 SOURCE_OPERATION_SEQ_NUM,
50614 SOURCE_USING_ASSEMBLY_ID,
50615 last_update_date,
50616 last_updated_by,
50617 creation_date,
50618 created_by )
50619 SELECT
50620 msc_st_operation_sequence_id_s.NEXTVAL,
50621 st_transaction_id,
50622 v_instance_id,
50623 'OPERATION_SEQUENCE_ID',
50624 data_source_type,
50625 v_instance_code,
50626 company_name,
50627 organization_code,
50628 routing_name,
50629 operation_seq_code,
50630 alternate_routing_designator,
50631 operation_seq_num,
50632 operation_effectivity_date,
50633 SOURCE_ORGANIZATION_ID,
50634 SOURCE_INVENTORY_ITEM_ID,
50635 SOURCE_PROJECT_ID,
50636 SOURCE_TASK_ID,
50637 SOURCE_WIP_ENTITY_ID,
50638 SOURCE_OPERATION_SEQ_NUM,
50639 SOURCE_USING_ASSEMBLY_ITEM_ID,
50640 v_current_date,
50641 v_current_user,
50642 v_current_date,
50643 v_current_user
50644 FROM msc_st_demands
50645 WHERE rowid = lb_rowid(j) ;
50646
50647 END IF;
50648 CLOSE c2;
50649
50650 -- Update operation seq num from local id table
50651
50652 v_sql_stmt := 12;
50653 lv_sql_stmt:=
50654 'UPDATE msc_st_demands msd'
50655 ||' SET operation_seq_num= (SELECT number1'
50656 ||' FROM msc_local_id_setup mlis'
50657 ||' WHERE mlis.char1 = msd.sr_instance_code'
50658 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
50659 ||' = NVL(msd.company_name,'||''''||NULL_CHAR||''''||') '
50660 ||' AND mlis.char3 = msd.organization_code'
50661 ||' AND mlis.char4 = msd.routing_name'
50662 ||' AND mlis.char5 = msd.operation_seq_code'
50663 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
50664 ||' = NVL(msd.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
50665 ||' AND mlis.date1 = msd.operation_effectivity_date'
50666 ||' AND mlis.entity_name = ''OPERATION_SEQUENCE_ID'') '
50667 ||' WHERE sr_instance_code = :v_instance_code'
50668 ||' AND NVL(operation_seq_num,'||NULL_VALUE||')= '||NULL_VALUE
50669 ||' AND process_flag = '||G_IN_PROCESS
50670 ||' AND batch_id = :lv_batch_id';
50671
50672
50673
50674 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
50675
50676 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
50677
50678
50679 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
50680 (p_table_name => 'MSC_ST_DEMANDS',
50681 p_instance_id => v_instance_id,
50682 p_instance_code => v_instance_code,
50683 p_process_flag => G_VALID,
50684 p_error_text => lv_error_text,
50685 p_debug => v_debug,
50686 p_batch_id => lv_batch_id);
50687
50688 IF lv_return <> 0 THEN
50689 RAISE ex_logging_err;
50690 END IF;
50691
50692 lv_return := MSC_ST_UTIL.LOG_ERROR
50693 (p_table_name => 'MSC_ST_DEMANDS',
50694 p_instance_code => v_instance_code,
50695 p_row => lv_column_names,
50696 p_severity => G_SEV_ERROR,
50697 p_message_text => NULL,
50698 p_error_text => lv_error_text,
50699 p_debug => v_debug,
50700 p_batch_id => lv_batch_id);
50701
50702 IF lv_return <> 0 THEN
50703 RAISE ex_logging_err;
50704 END IF;
50705
50706 COMMIT;
50707 END LOOP ;
50708
50709 EXCEPTION
50710 WHEN too_many_rows THEN
50711 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_WIP_DEMAND'||'('
50712 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
50713 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
50714 ROLLBACK ;
50715
50716 WHEN ex_logging_err THEN
50717 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
50718 ROLLBACK;
50719
50720 WHEN OTHERS THEN
50721 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_WIP_DEMAND'||'('
50722 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
50723 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
50724 ROLLBACK;
50725
50726 END LOAD_WIP_DEMAND;
50727
50728
50729
50730 /*==========================================================================+
50731 | DESCRIPTION : This procedure loads records into new tables for OFSM |
50732 | These tables contains the details for a lot based job |
50733 | |
50734 +==========================================================================*/
50735
50736 PROCEDURE LOAD_JOB_DETAILS IS
50737
50738 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
50739 TYPE CurTyp IS REF CURSOR;
50740 c1 CurTyp;
50741 lb_rowid RowidTab;
50742 lv_local_id NUMBER;
50743 lv_column_names VARCHAR2(5000); -- Stores concatenated column names
50744 lv_return NUMBER;
50745 lv_error_text VARCHAR2(250);
50746 lv_where_str VARCHAR2(5000);
50747 lv_sql_stmt VARCHAR2(5000);
50748 lv_cursor_stmt VARCHAR2(5000);
50749 lv_batch_id msc_st_routings.batch_id%TYPE;
50750 lv_message_text msc_errors.error_text%TYPE;
50751 ex_logging_err EXCEPTION;
50752
50753
50754 CURSOR c2(p_batch_id NUMBER) IS
50755 SELECT rowid
50756 FROM msc_st_job_operation_networks
50757 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
50758 AND sr_instance_code = v_instance_code
50759 AND batch_id = p_batch_id;
50760
50761 CURSOR c3(p_batch_id NUMBER) IS
50762 SELECT rowid
50763 FROM msc_st_job_operations
50764 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
50765 AND sr_instance_code = v_instance_code
50766 AND batch_id = p_batch_id;
50767
50768 CURSOR c4 (p_batch_id NUMBER) IS
50769 SELECT rowid
50770 FROM msc_st_job_requirement_ops
50771 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
50772 AND batch_id = p_batch_id
50773 AND sr_instance_code = v_instance_code;
50774
50775 CURSOR c5(p_batch_id NUMBER) IS
50776 SELECT rowid
50777 FROM msc_st_job_op_resources
50778 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
50779 AND sr_instance_code = v_instance_code
50780 AND batch_id = p_batch_id;
50781
50782 CURSOR c6(p_batch_id NUMBER) IS
50783 SELECT rowid
50784 FROM msc_st_job_op_resources
50785 WHERE process_flag = G_IN_PROCESS
50786 AND sr_instance_code = v_instance_code
50787 AND batch_id = p_batch_id
50788 AND NVL(resource_seq_num,NULL_VALUE) = NULL_VALUE
50789 AND NVL(RESOURCE_SEQ_CODE, NULL_CHAR) <> NULL_CHAR
50790 AND deleted_flag = SYS_NO;
50791
50792 BEGIN
50793
50794 -- -- Pre processing for MSC_ST_JOB_OPERATION_NETWORKS
50795 --Duplicate records check for the records whose source is XML
50796
50797 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
50798 (p_app_short_name => 'MSC',
50799 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
50800 p_message_text => lv_message_text,
50801 p_error_text => lv_error_text);
50802
50803 IF lv_return <> 0 THEN
50804 RAISE ex_logging_err;
50805 END IF;
50806
50807 v_sql_stmt := 1;
50808
50809 lv_sql_stmt :=
50810 'UPDATE msc_st_job_operation_networks mson1 '
50811 ||' SET process_flag = '||G_ERROR_FLG||','
50812 ||' error_text = '||''''||lv_message_text||''''
50813 ||' WHERE message_id < ( SELECT max(message_id) '
50814 ||' FROM msc_st_job_operation_networks mson2'
50815 ||' WHERE mson2.wip_entity_name = mson1.wip_entity_name'
50816 ||' AND mson2.organization_code = mson1.organization_code'
50817 ||' AND mson2.from_operation_seq_code = mson1.from_operation_seq_code'
50818 ||' AND mson2.to_operation_seq_code = mson1.to_operation_seq_code'
50819 ||' AND mson2.sr_instance_code = mson1.sr_instance_code'
50820 ||' AND NVL(mson2.routing_name,'||''''||NULL_CHAR||''''||') '
50821 ||' = NVL(mson1.routing_name, '||''''||NULL_CHAR||''''||') '
50822 ||' AND NVL(mson2.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
50823 ||' = NVL(mson1.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
50824 ||' AND NVL(mson2.company_name,'||''''||NULL_CHAR||''''||') '
50825 ||' = NVL(mson1.company_name,'||''''||NULL_CHAR||''''||') '
50826 ||' AND mson2.process_flag ='||G_IN_PROCESS
50827 ||' AND NVL(mson2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||')'
50828 ||' AND mson1.process_flag = '||G_IN_PROCESS
50829 ||' AND mson1.sr_instance_code = :v_instance_code'
50830 ||' AND NVL(mson1.message_id,'||NULL_VALUE||')<> '||NULL_VALUE;
50831
50832
50833 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
50834
50835 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
50836
50837 --Duplicate records check for the records whose source is batch load
50838
50839 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
50840 (p_app_short_name => 'MSC',
50841 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
50842 p_message_text => lv_message_text,
50843 p_error_text => lv_error_text);
50844
50845 IF lv_return <> 0 THEN
50846 RAISE ex_logging_err;
50847 END IF;
50848
50849 v_sql_stmt := 2;
50850
50851 lv_sql_stmt :=
50852 'UPDATE msc_st_job_operation_networks mson1'
50853 ||' SET process_flag = '||G_ERROR_FLG||','
50854 ||' error_text = '||''''||lv_message_text||''''
50855 ||' WHERE EXISTS ( SELECT 1 '
50856 ||' FROM msc_st_job_operation_networks mson2'
50857 ||' WHERE mson2.wip_entity_name = mson1.wip_entity_name'
50858 ||' AND mson2.organization_code = mson1.organization_code'
50859 ||' AND mson2.from_operation_seq_code = mson1.from_operation_seq_code'
50860 ||' AND mson2.to_operation_seq_code = mson1.to_operation_seq_code'
50861 ||' AND mson2.sr_instance_code = mson1.sr_instance_code'
50862 ||' AND NVL(mson2.routing_name,'||''''||NULL_CHAR||''''||') '
50863 ||' = NVL(mson1.routing_name, '||''''||NULL_CHAR||''''||') '
50864 ||' AND NVL(mson2.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
50865 ||' = NVL(mson1.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
50866 ||' AND NVL(mson2.company_name,'||''''||NULL_CHAR||''''||') '
50867 ||' = NVL(mson1.company_name,'||''''||NULL_CHAR||''''||') '
50868 ||' AND mson2.process_flag ='||G_IN_PROCESS
50869 ||' AND NVL(mson2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
50870 ||' AND mson2.rowid <> mson1.rowid )'
50871 ||' AND mson1.process_flag = '||G_IN_PROCESS
50872 ||' AND mson1.sr_instance_code = :v_instance_code'
50873 ||' AND NVL(mson1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
50874
50875
50876 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
50877
50878 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
50879
50880 COMMIT;
50881
50882 lv_column_names :=
50883 ' WIP_ENTITY_NAME ||''~''||'
50884 ||' FROM_OPERATION_SEQ_CODE ||''~''||'
50885 ||' FROM_OP_EFFECTIVITY_DATE ||''~''||'
50886 ||' TO_OPERATION_SEQ_CODE ||''~''||'
50887 ||' TO_OP_EFFECTIVITY_DATE ||''~''||'
50888 ||' ROUTING_NAME ||''~''||'
50889 ||' ASSEMBLY_NAME ||''~''||'
50890 ||' ALTERNATE_ROUTING_DESIGNATOR ||''~''||'
50891 ||' TRANSITION_TYPE ||''~''||'
50892 ||' PLANNING_PCT ||''~''||'
50893 ||' ORGANIZATION_CODE ||''~''||'
50894 ||' SR_INSTANCE_CODE ||''~''||'
50895 ||' DELETED_FLAG ||''~''||'
50896 ||' COMPANY_NAME ';
50897
50898 -- Now processing in batch
50899 LOOP
50900
50901 v_sql_stmt := 3;
50902
50903 lv_cursor_stmt :=
50904 ' SELECT msc_st_batch_id_s.NEXTVAL '
50905 ||' FROM dual';
50906
50907 OPEN c1 FOR lv_cursor_stmt;
50908 FETCH c1 INTO lv_batch_id;
50909 CLOSE c1;
50910
50911
50912 v_sql_stmt := 4;
50913
50914 lv_sql_stmt :=
50915 ' UPDATE msc_st_job_operation_networks '
50916 ||' SET batch_id = :lv_batch_id'
50917 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
50918 ||' AND sr_instance_code = :v_instance_code'
50919 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
50920 ||' AND rownum <= '||v_batch_size;
50921
50922
50923 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
50924
50925 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
50926
50927 EXIT WHEN SQL%NOTFOUND;
50928
50929 OPEN c2(lv_batch_id);
50930 FETCH c2 BULK COLLECT INTO lb_rowid;
50931 CLOSE c2;
50932
50933 v_sql_stmt := 5;
50934
50935 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
50936 UPDATE msc_st_job_operation_networks
50937 SET st_transaction_id = msc_st_job_op_networks_s.NEXTVAL,
50938 refresh_id = v_refresh_id,
50939 last_update_date = v_current_date,
50940 last_updated_by = v_current_user,
50941 creation_date = v_current_date,
50942 created_by = v_current_user
50943 WHERE rowid = lb_rowid(j);
50944
50945
50946 -- error out the records where wip_entity_name is null
50947
50948 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
50949 (p_app_short_name => 'MSC',
50950 p_error_code => 'MSC_PP_COL_VAL_NULL',
50951 p_message_text => lv_message_text,
50952 p_error_text => lv_error_text,
50953 p_token1 => 'COLUMN_NAME',
50954 p_token_value1 => 'WIP_ENTITY_NAME');
50955
50956 IF lv_return <> 0 THEN
50957 RAISE ex_logging_err;
50958 END IF;
50959
50960 v_sql_stmt := 6;
50961 lv_sql_stmt :=
50962 'UPDATE msc_st_job_operation_networks'
50963 ||' SET error_text = '||''''||lv_message_text||''''||','
50964 ||' process_flag = '||G_ERROR_FLG
50965 ||' WHERE NVL(wip_entity_name,'||''''||NULL_CHAR||''''||') '
50966 ||' = '||''''||NULL_CHAR||''''
50967 ||' AND process_flag = '||G_IN_PROCESS
50968 ||' AND NVL(batch_id,'||NULL_VALUE||')= :lv_batch_id'
50969 ||' AND sr_instance_code = :v_instance_code';
50970
50971
50972 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
50973
50974 EXECUTE IMMEDIATE lv_sql_stmt
50975 USING lv_batch_id,
50976 v_instance_code;
50977
50978
50979 -- Set the message
50980 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
50981 (p_app_short_name => 'MSC',
50982 p_error_code => 'MSC_PP_NO_DELETION',
50983 p_message_text => lv_message_text,
50984 p_error_text => lv_error_text,
50985 p_token1 => 'TABLE_NAME',
50986 p_token_value1 => 'MSC_ST_JOB_OPERATION_NETWORKS');
50987
50988 IF lv_return <> 0 THEN
50989 RAISE ex_logging_err;
50990 END IF;
50991
50992 --Deletion is not allowed on this table.
50993 v_sql_stmt := 06;
50994 lv_sql_stmt :=
50995 ' UPDATE msc_st_job_operation_networks '
50996 ||' SET process_flag ='||G_ERROR_FLG||','
50997 ||' error_text = '||''''||lv_message_text||''''
50998 ||' WHERE deleted_flag = '||SYS_YES
50999 ||' AND process_flag = '||G_IN_PROCESS
51000 ||' AND batch_id = :lv_batch_id'
51001 ||' AND sr_instance_code = :v_instance_code';
51002
51003
51004 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
51005
51006 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
51007
51008 -- Set the error message
51009 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51010 (p_app_short_name => 'MSC',
51011 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
51012 p_message_text => lv_message_text,
51013 p_error_text => lv_error_text,
51014 p_token1 => 'COLUMN_NAME',
51015 p_token_value1 => 'DELETED_FLAG',
51016 p_token2 => 'DEFAULT_VALUE',
51017 p_token_value2 => SYS_NO );
51018
51019 IF lv_return <> 0 THEN
51020 RAISE ex_logging_err;
51021 END IF;
51022
51023 -- Check whether delete flag value is in (1,2),if not default to SYS_NO
51024
51025 lv_where_str :=
51026 ' AND NVL(deleted_flag,'||NULL_VALUE||') NOT IN(1,2)';
51027
51028 lv_return := MSC_ST_UTIL.LOG_ERROR
51029 (p_table_name => 'MSC_ST_JOB_OPERATION_NETWORKS',
51030 p_instance_code => v_instance_code,
51031 p_row => lv_column_names,
51032 p_severity => G_SEV_WARNING,
51033 p_message_text => lv_message_text,
51034 p_error_text => lv_error_text,
51035 p_batch_id => lv_batch_id,
51036 p_where_str => lv_where_str,
51037 p_col_name => 'DELETED_FLAG',
51038 p_debug => v_debug,
51039 p_default_value => SYS_NO);
51040
51041 IF lv_return <> 0 THEN
51042 RAISE ex_logging_err;
51043 END IF;
51044
51045 -- Set the error message
51046 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51047 (p_app_short_name => 'MSC',
51048 p_error_code => 'MSC_PP_COL_VAL_NULL',
51049 p_message_text => lv_message_text,
51050 p_error_text => lv_error_text,
51051 p_token1 => 'COLUMN_NAME',
51052 p_token_value1 => 'PLANNING_PCT');
51053
51054 IF lv_return <> 0 THEN
51055 RAISE ex_logging_err;
51056 END IF;
51057
51058 -- Error out the records whose PLANNING_PCT is NULL
51059
51060 v_sql_stmt := 7;
51061 lv_sql_stmt :=
51062 'UPDATE msc_st_job_operation_networks'
51063 ||' SET process_flag ='||G_ERROR_FLG||','
51064 ||' error_text = '||''''||lv_message_text||''''
51065 ||' WHERE NVL(PLANNING_PCT,'||NULL_VALUE||') = '||NULL_VALUE
51066 ||' AND sr_instance_code = :v_instance_code'
51067 ||' AND process_flag = '||G_IN_PROCESS
51068 ||' AND batch_id = :lv_batch_id';
51069
51070
51071 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
51072
51073 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
51074
51075 -- Set the error message
51076 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51077 (p_app_short_name => 'MSC',
51078 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
51079 p_message_text => lv_message_text,
51080 p_error_text => lv_error_text,
51081 p_token1 => 'COLUMN_NAME',
51082 p_token_value1 => 'RECOMMENDED');
51083
51084 IF lv_return <> 0 THEN
51085 RAISE ex_logging_err;
51086 END IF;
51087
51088 -- Error out the records where RECOMMENDED is not 'Y' or 'N'
51089
51090 v_sql_stmt := 7;
51091 lv_sql_stmt :=
51092 'UPDATE msc_st_job_operation_networks'
51093 ||' SET process_flag ='||G_ERROR_FLG||','
51094 ||' error_text = '||''''||lv_message_text||''''
51095 ||' WHERE recommended NOT IN (''Y'', ''N'')'
51096 ||' AND sr_instance_code = :v_instance_code'
51097 ||' AND process_flag = '||G_IN_PROCESS
51098 ||' AND batch_id = :lv_batch_id';
51099
51100
51101 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
51102
51103 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
51104
51105 -- Set the error message
51106 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51107 (p_app_short_name => 'MSC',
51108 p_error_code => 'MSC_PP_COL_VAL_NULL',
51109 p_message_text => lv_message_text,
51110 p_error_text => lv_error_text,
51111 p_token1 => 'COLUMN_NAME',
51112 p_token_value1 => 'ASSEMBLY_NAME');
51113
51114 IF lv_return <> 0 THEN
51115 RAISE ex_logging_err;
51116 END IF;
51117
51118 -- Error out the records whose Assembly Name is NULL
51119
51120 v_sql_stmt := 8;
51121 lv_sql_stmt :=
51122 'UPDATE msc_st_job_operation_networks'
51123 ||' SET process_flag ='||G_ERROR_FLG||','
51124 ||' error_text = '||''''||lv_message_text||''''
51125 ||' WHERE NVL(assembly_name,'||''''||NULL_CHAR||''''||') '
51126 ||' = '||''''||NULL_CHAR||''''
51127 ||' AND sr_instance_code = :v_instance_code'
51128 ||' AND process_flag = '||G_IN_PROCESS
51129 ||' AND batch_id = :lv_batch_id';
51130
51131
51132 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
51133
51134 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
51135
51136 -- Now we will check whether Routing Name is NULL , if it is NULL we will populate the
51137 -- ASSEMBLY NAME in ROUTING_NAME column for all such records
51138
51139 v_sql_stmt := 9;
51140
51141 lv_sql_stmt :=
51142 'UPDATE msc_st_job_operation_networks '
51143 ||' SET routing_name = assembly_name'
51144 ||' WHERE sr_instance_code = :v_instance_code'
51145 ||' AND process_flag = '||G_IN_PROCESS
51146 ||' AND NVL(routing_name,'||''''||NULL_CHAR||''''||') '
51147 ||' = '||''''||NULL_CHAR||''''
51148 ||' AND batch_id = :lv_batch_id';
51149
51150
51151 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
51152
51153 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
51154
51155 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51156 (p_app_short_name => 'MSC',
51157 p_error_code => 'MSC_PP_INVALID_VALUE',
51158 p_message_text => lv_message_text,
51159 p_error_text => lv_error_text,
51160 p_token1 => 'COLUMN_NAME',
51161 p_token_value1 => 'ORGANIZATION_CODE');
51162
51163 IF lv_return <> 0 THEN
51164 RAISE ex_logging_err;
51165 END IF;
51166
51167 --Derive Organization_id
51168 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
51169 (p_table_name => 'MSC_ST_JOB_OPERATION_NETWORKS',
51170 p_org_partner_name => 'ORGANIZATION_CODE',
51171 p_org_partner_id => 'ORGANIZATION_ID',
51172 p_instance_code => v_instance_code,
51173 p_partner_type => G_ORGANIZATION,
51174 p_error_text => lv_error_text,
51175 p_batch_id => lv_batch_id,
51176 p_severity => G_SEV_ERROR,
51177 p_message_text => lv_message_text,
51178 p_debug => v_debug,
51179 p_row => lv_column_names);
51180
51181 IF lv_return <> 0 THEN
51182 RAISE ex_logging_err;
51183 END IF;
51184
51185 --Deriving wip_entity_id
51186 v_sql_stmt := 10;
51187 lv_sql_stmt :=
51188 'UPDATE msc_st_job_operation_networks mss'
51189 ||' SET wip_entity_id = (SELECT local_id'
51190 ||' FROM msc_local_id_supply mls'
51191 ||' WHERE mls.char4 = mss.wip_entity_name'
51192 ||' AND mls.char3 = mss.organization_code'
51193 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
51194 ||' NVL(mss.company_name,'||''''||NULL_CHAR||''''||') '
51195 ||' AND mls.char1 = mss.sr_instance_code'
51196 ||' AND mls.entity_name = ''WIP_ENTITY_ID'' )'
51197 ||' WHERE process_flag = '||G_IN_PROCESS
51198 ||' AND NVL(batch_id,'||NULL_VALUE||') = :lv_batch_id'
51199 ||' AND sr_instance_code = :v_instance_code';
51200
51201
51202 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
51203
51204 EXECUTE IMMEDIATE lv_sql_stmt
51205 USING lv_batch_id,
51206 v_instance_code;
51207
51208 -- Set the error message
51209
51210 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51211 (p_app_short_name => 'MSC',
51212 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
51213 p_message_text => lv_message_text,
51214 p_error_text => lv_error_text,
51215 p_token1 => 'COLUMN_NAMES',
51216 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
51217 ||'ORGANIZATION_CODE,WIP_ENTITY_NAME',
51218 p_token2 => 'MASTER_TABLE',
51219 p_token_value2 => 'MSC_ST_SUPPLIES',
51220 p_token3 => 'CHILD_TABLE' ,
51221 p_token_value3 => 'MSC_ST_JOB_OPERATION_NETWORKS' );
51222
51223 IF lv_return <> 0 THEN
51224 RAISE ex_logging_err;
51225 END IF;
51226
51227
51228 -- Error out the records if WIP_ENTITY_ID NULL
51229
51230 v_sql_stmt := 11;
51231 lv_sql_stmt:=
51232 'UPDATE msc_st_job_operation_networks msrr'
51233 ||' SET process_flag ='||G_ERROR_FLG||','
51234 ||' error_text = '||''''||lv_message_text||''''
51235 ||' WHERE NVL(wip_entity_id,'||NULL_VALUE||') = '||NULL_VALUE
51236 ||' AND sr_instance_code = :v_instance_code'
51237 ||' AND process_flag ='||G_IN_PROCESS
51238 ||' AND batch_id = :lv_batch_id';
51239
51240
51241 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
51242
51243 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
51244
51245 -- from_operation_seq_code or to_operation_seq_code cannot be null.
51246 -- Set the error message
51247 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51248 (p_app_short_name => 'MSC',
51249 p_error_code => 'MSC_PP_COL_VAL_NULL',
51250 p_message_text => lv_message_text,
51251 p_error_text => lv_error_text,
51252 p_token1 => 'COLUMN_NAME',
51253 p_token_value1 => 'FROM_OPERATION_SEQ_CODE OR '
51254 ||'TO_OPERATION_SEQ_CODE');
51255
51256 IF lv_return <> 0 THEN
51257 RAISE ex_logging_err;
51258 END IF;
51259
51260 -- Error out the records whose from_operation_seq_code or to_operation_seq_code is NULL
51261
51262 v_sql_stmt := 12;
51263 lv_sql_stmt :=
51264 'UPDATE msc_st_job_operation_networks'
51265 ||' SET process_flag ='||G_ERROR_FLG||','
51266 ||' error_text = '||''''||lv_message_text||''''
51267 ||' WHERE ( NVL(from_operation_seq_code,'||''''||NULL_CHAR||''''||') = '||''''||NULL_CHAR||''''
51268 ||' OR NVL(to_operation_seq_code,'||''''||NULL_CHAR||''''||') = '||''''||NULL_CHAR||''''||') '
51269 ||' AND sr_instance_code = :v_instance_code'
51270 ||' AND process_flag = '||G_IN_PROCESS
51271 ||' AND batch_id = :lv_batch_id';
51272
51273
51274 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
51275
51276 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
51277
51278 -- from op_seq_code and to_op_seq_codes cannot be same
51279 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51280 (p_app_short_name => 'MSC',
51281 p_error_code => 'MSC_PP_FROM_TO_SAME',
51282 p_message_text => lv_message_text,
51283 p_error_text => lv_error_text,
51284 p_token1 => 'COLUMN_NAME',
51285 p_token_value1 => 'TO_OPERATION_SEQ_CODE');
51286
51287 IF lv_return <> 0 THEN
51288 RAISE ex_logging_err;
51289 END IF;
51290
51291 -- Error out the records whose from_operation_seq_code is same as to_op_seq_code
51292
51293 v_sql_stmt := 13;
51294 lv_sql_stmt :=
51295 'UPDATE msc_st_job_operation_networks'
51296 ||' SET process_flag ='||G_ERROR_FLG||','
51297 ||' error_text = '||''''||lv_message_text||''''
51298 ||' WHERE NVL(to_operation_seq_code,'||''''||NULL_CHAR||''''||') = NVL(from_operation_seq_code,'||''''||NULL_CHAR||''''||')'
51299 ||' AND sr_instance_code = :v_instance_code'
51300 ||' AND process_flag = '||G_IN_PROCESS
51301 ||' AND batch_id = :lv_batch_id';
51302
51303
51304 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
51305
51306 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
51307
51308 -- Derive routing_sequence_id
51309
51310 -- Set the error message
51311 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51312 (p_app_short_name => 'MSC',
51313 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
51314 p_message_text => lv_message_text,
51315 p_error_text => lv_error_text,
51316 p_token1 => 'COLUMN_NAMES',
51317 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
51318 ||'ORGANIZATION_CODE,ROUTING_NAME',
51319 p_token2 => 'MASTER_TABLE',
51320 p_token_value2 => 'MSC_ST_ROUTINGS',
51321 p_token3 => 'CHILD_TABLE' ,
51322 p_token_value3 => 'MSC_ST_JOB_OPERATION_NETWORKS' );
51323
51324 IF lv_return <> 0 THEN
51325 RAISE ex_logging_err;
51326 END IF;
51327
51328 -- Derive the ROUTING_SEQUENCE_ID from LOCAL ID table
51329
51330 lv_return :=
51331 MSC_ST_UTIL.DERIVE_ROUTING_SEQUENCE_ID
51332 (p_table_name => 'MSC_ST_JOB_OPERATION_NETWORKS',
51333 p_rtg_col_name => 'ROUTING_NAME',
51334 p_rtg_col_id => 'ROUTING_SEQUENCE_ID',
51335 p_instance_code => v_instance_code,
51336 p_severity => G_SEV_ERROR,
51337 p_message_text => lv_message_text,
51338 p_batch_id => lv_batch_id,
51339 p_debug => v_debug,
51340 p_error_text => lv_error_text);
51341
51342 if (lv_return <> 0 )then
51343 RAISE ex_logging_err;
51344 end if;
51345
51346
51347 -- Set the error message
51348 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51349 (p_app_short_name => 'MSC',
51350 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
51351 p_message_text => lv_message_text,
51352 p_error_text => lv_error_text,
51353 p_token1 => 'COLUMN_NAME',
51354 p_token_value1 => 'FROM_OP_EFFECTIVITY_DATE',
51355 p_token2 => 'DEFAULT_VALUE',
51356 p_token_value2 => 'SYSDATE' );
51357
51358 IF lv_return <> 0 THEN
51359 RAISE ex_logging_err;
51360 END IF;
51361
51362 -- Default from operation effectivity date as SYSDATE if NULL
51363
51364 v_sql_stmt := 14;
51365 lv_where_str :=
51366 ' AND NVL(from_op_effectivity_date,SYSDATE-36500 ) = SYSDATE-36500 ' ;
51367
51368 lv_return := MSC_ST_UTIL.LOG_ERROR
51369 (p_table_name => 'MSC_ST_JOB_OPERATION_NETWORKS',
51370 p_instance_code => v_instance_code,
51371 p_row => lv_column_names,
51372 p_severity => G_SEV_WARNING,
51373 p_message_text => lv_message_text,
51374 p_error_text => lv_error_text,
51375 p_batch_id => lv_batch_id,
51376 p_where_str => lv_where_str,
51377 p_col_name => 'FROM_OP_EFFECTIVITY_DATE',
51378 p_debug => v_debug,
51379 p_default_value => 'SYSDATE');
51380
51381 IF lv_return <> 0 THEN
51382 RAISE ex_logging_err;
51383 END IF;
51384
51385
51386 -- Set the error message
51387 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51388 (p_app_short_name => 'MSC',
51389 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
51390 p_message_text => lv_message_text,
51391 p_error_text => lv_error_text,
51392 p_token1 => 'COLUMN_NAME',
51393 p_token_value1 => 'TO_OP_EFFECTIVITY_DATE',
51394 p_token2 => 'DEFAULT_VALUE',
51395 p_token_value2 => 'SYSDATE' );
51396
51397 IF lv_return <> 0 THEN
51398 RAISE ex_logging_err;
51399 END IF;
51400
51401 -- Default to operation effectivity date as SYSDATE if NULL
51402 v_sql_stmt := 15;
51403 lv_where_str :=
51404 ' AND NVL(to_op_effectivity_date,SYSDATE-36500 ) = SYSDATE-36500 ' ;
51405
51406 lv_return := MSC_ST_UTIL.LOG_ERROR
51407 (p_table_name => 'MSC_ST_JOB_OPERATION_NETWORKS',
51408 p_instance_code => v_instance_code,
51409 p_row => lv_column_names,
51410 p_severity => G_SEV_WARNING,
51411 p_message_text => lv_message_text,
51412 p_error_text => lv_error_text,
51413 p_batch_id => lv_batch_id,
51414 p_where_str => lv_where_str,
51415 p_col_name => 'TO_OP_EFFECTIVITY_DATE',
51416 p_debug => v_debug,
51417 p_default_value => 'SYSDATE');
51418
51419 IF lv_return <> 0 THEN
51420 RAISE ex_logging_err;
51421 END IF;
51422
51423 -- Derive from_op_seq_id, from_op_seq_num
51424
51425 v_sql_stmt := 16;
51426 lv_sql_Stmt :=
51427 'UPDATE msc_st_job_operation_networks mson'
51428 ||' SET (from_op_seq_id, from_op_seq_num) = (SELECT local_id, number1'
51429 ||' FROM msc_local_id_setup mlis'
51430 ||' WHERE mlis.char1 = mson.sr_instance_code'
51431 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
51432 ||' = NVL(mson.company_name,'||''''||NULL_CHAR||''''||') '
51433 ||' AND mlis.char3 = mson.organization_code'
51434 ||' AND mlis.char4 = mson.routing_name'
51435 ||' AND mlis.char5 = mson.from_operation_seq_code'
51436 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
51437 ||' = NVL(mson.alternate_routing_designator,'||''''||NULL_CHAR||''''||')'
51438 ||' AND mlis.date1 = mson.FROM_OP_EFFECTIVITY_DATE'
51439 ||' AND mlis.entity_name = ''OPERATION_SEQUENCE_ID'' '
51440 ||' AND mlis.instance_id = '||v_instance_id||')'
51441 ||' WHERE sr_instance_code = :v_instance_code'
51442 ||' AND process_flag ='||G_IN_PROCESS
51443 ||' AND batch_id = :lv_batch_id';
51444
51445
51446 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
51447
51448 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
51449
51450 -- from_op_seq_num cannot be null. Error out the records with null value for them.
51451 -- Set the error message
51452
51453 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51454 (p_app_short_name => 'MSC',
51455 p_error_code => 'MSC_PP_COL_VAL_NULL',
51456 p_message_text => lv_message_text,
51457 p_error_text => lv_error_text,
51458 p_token1 => 'COLUMN_NAME',
51459 p_token_value1 => 'FROM_OP_SEQ_ID OR '
51460 ||'FROM_OP_SEQ_NUM');
51461
51462 IF lv_return <> 0 THEN
51463 RAISE ex_logging_err;
51464 END IF;
51465
51466 -- Error out the records whose from_op_seq_id, from _op_seq_num is NULL
51467
51468 v_sql_stmt := 17;
51469 lv_sql_stmt :=
51470 'UPDATE msc_st_job_operation_networks'
51471 ||' SET process_flag ='||G_ERROR_FLG||','
51472 ||' error_text = '||''''||lv_message_text||''''
51473 ||' WHERE (NVL(from_op_seq_id,'||NULL_VALUE||') ='||NULL_VALUE
51474 ||' OR NVL(from_op_seq_num,'||NULL_VALUE||') ='||NULL_VALUE||')'
51475 ||' AND sr_instance_code = :v_instance_code'
51476 ||' AND process_flag = '||G_IN_PROCESS
51477 ||' AND batch_id = :lv_batch_id';
51478
51479
51480 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
51481
51482 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
51483
51484
51485 -- Derive to_op_seq_id, to_op_seq_num
51486
51487 v_sql_stmt := 18;
51488 lv_sql_Stmt :=
51489 'UPDATE msc_st_job_operation_networks mson'
51490 ||' SET (to_op_seq_id, to_op_seq_num) = (SELECT local_id, number1'
51491 ||' FROM msc_local_id_setup mlis'
51492 ||' WHERE mlis.char1 = mson.sr_instance_code'
51493 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
51494 ||' = NVL(mson.company_name,'||''''||NULL_CHAR||''''||') '
51495 ||' AND mlis.char3 = mson.organization_code'
51496 ||' AND mlis.char4 = mson.routing_name'
51497 ||' AND mlis.char5 = mson.to_operation_seq_code'
51498 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
51499 ||' = NVL(mson.alternate_routing_designator,'||''''||NULL_CHAR||''''||')'
51500 ||' AND mlis.date1 = mson.TO_OP_EFFECTIVITY_DATE'
51501 ||' AND mlis.entity_name = ''OPERATION_SEQUENCE_ID'' '
51502 ||' AND mlis.instance_id = '||v_instance_id||')'
51503 ||' WHERE sr_instance_code = :v_instance_code'
51504 ||' AND process_flag ='||G_IN_PROCESS
51505 ||' AND batch_id = :lv_batch_id';
51506
51507
51508 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
51509
51510 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
51511
51512 -- to_op_seq_num cannot be null. Error out the records with null value for them.
51513 -- Set the error message
51514
51515 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51516 (p_app_short_name => 'MSC',
51517 p_error_code => 'MSC_PP_COL_VAL_NULL',
51518 p_message_text => lv_message_text,
51519 p_error_text => lv_error_text,
51520 p_token1 => 'COLUMN_NAME',
51521 p_token_value1 => 'TO_OP_SEQ_ID OR '
51522 ||'TO_OP_SEQ_NUM');
51523
51524 IF lv_return <> 0 THEN
51525 RAISE ex_logging_err;
51526 END IF;
51527
51528 -- Error out the records whose to_op_seq_id, to_op_seq_num is NULL
51529
51530 v_sql_stmt := 19;
51531 lv_sql_stmt :=
51532 'UPDATE msc_st_job_operation_networks'
51533 ||' SET process_flag ='||G_ERROR_FLG||','
51534 ||' error_text = '||''''||lv_message_text||''''
51535 ||' WHERE (NVL(to_op_seq_id,'||NULL_VALUE||') ='||NULL_VALUE
51536 ||' OR NVL(to_op_seq_num,'||NULL_VALUE||') ='||NULL_VALUE||')'
51537 ||' AND sr_instance_code = :v_instance_code'
51538 ||' AND process_flag = '||G_IN_PROCESS
51539 ||' AND batch_id = :lv_batch_id';
51540
51541
51542 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
51543
51544 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
51545
51546 -- Set the error message
51547 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51548 (p_app_short_name => 'MSC',
51549 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
51550 p_message_text => lv_message_text,
51551 p_error_text => lv_error_text,
51552 p_token1 => 'COLUMN_NAME',
51553 p_token_value1 => 'TRANSITION_TYPE',
51554 p_token2 => 'DEFAULT_VALUE',
51555 p_token_value2 => G_TRANSITION_TYPE);
51556
51557 IF lv_return <> 0 THEN
51558 RAISE ex_logging_err;
51559 END IF;
51560
51561 -- Defualt transition type to 2(i.e. alternate) if not in (1,2)
51562 v_sql_stmt := 20;
51563 lv_where_str :=
51564 ' AND NVL(transition_type,'||NULL_VALUE||') NOT IN (1,2)';
51565
51566 lv_return := MSC_ST_UTIL.LOG_ERROR
51567 (p_table_name => 'MSC_ST_JOB_OPERATION_NETWORKS',
51568 p_instance_code => v_instance_code,
51569 p_row => lv_column_names,
51570 p_severity => G_SEV_WARNING,
51571 p_message_text => lv_message_text,
51572 p_error_text => lv_error_text,
51573 p_batch_id => lv_batch_id,
51574 p_where_str => lv_where_str,
51575 p_col_name => 'TRANSITION_TYPE',
51576 p_debug => v_debug,
51577 p_default_value => G_TRANSITION_TYPE);
51578
51579
51580 IF lv_return <> 0 THEN
51581 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
51582 END IF;
51583
51584 --Call to customised validation.
51585
51586 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
51587 (ERRBUF => lv_error_text,
51588 RETCODE => lv_return,
51589 pBatchID => lv_batch_id,
51590 pInstanceCode => v_instance_code,
51591 pEntityName => 'MSC_ST_JOB_OPERATION_NETWORKS',
51592 pInstanceID => v_instance_id);
51593
51594 IF NVL(lv_return,0) <> 0 THEN
51595 RAISE ex_logging_err;
51596 END IF;
51597
51598 COMMIT;
51599 END LOOP;
51600
51601 -- There should be at the max only one primary path from a from_operation_seq_code
51602 -- Else error out all the records for that from_operation_seq_code
51603
51604 -- Set the error message
51605 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51606 (p_app_short_name => 'MSC',
51607 p_error_code => 'MSC_PP_MULTI_PRI_PATH',
51608 p_message_text => lv_message_text,
51609 p_error_text => lv_error_text,
51610 p_token1 => 'COLUMN_NAME',
51611 p_token_value1 => 'TRANSITION_TYPE');
51612
51613 IF lv_return <> 0 THEN
51614 RAISE ex_logging_err;
51615 END IF;
51616
51617 v_sql_stmt := 21;
51618 lv_sql_stmt :=
51619 'UPDATE msc_st_job_operation_networks mson1'
51620 ||' SET process_flag = '||G_ERROR_FLG||','
51621 ||' error_text = '||''''||lv_message_text||''''
51622 ||' WHERE 1 < ( SELECT COUNT(*) '
51623 ||' FROM msc_st_job_operation_networks mson2'
51624 ||' WHERE mson2.wip_entity_name = mson1.wip_entity_name'
51625 ||' AND mson2.organization_code = mson1.organization_code'
51626 ||' AND mson2.from_operation_seq_code = mson1.from_operation_seq_code'
51627 ||' AND mson2.sr_instance_code = mson1.sr_instance_code'
51628 ||' AND NVL(mson2.company_name,'||''''||NULL_CHAR||''''||') '
51629 ||' = NVL(mson1.company_name,'||''''||NULL_CHAR||''''||') '
51630 ||' AND mson2.transition_type = 1 '
51631 ||' AND mson2.process_flag ='||G_IN_PROCESS
51632 ||' AND mson2.deleted_flag <>1 '
51633 ||' GROUP BY wip_entity_name, sr_instance_code,company_name,organization_code,from_operation_seq_code)'
51634 ||' AND mson1.process_flag = '||G_IN_PROCESS
51635 ||' AND mson1.deleted_flag <>1 '
51636 ||' AND mson1.sr_instance_code = :v_instance_code';
51637
51638
51639
51640 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
51641
51642 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
51643
51644 -- The summation of the planning_pct's from a from_operation_sed_code should be exactly 100.
51645 -- Else error out all the records for that from_operation_seq_code
51646
51647 -- Set the error message
51648 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51649 (p_app_short_name => 'MSC',
51650 p_error_code => 'MSC_INVALID_PLANNING_PCT',
51651 p_message_text => lv_message_text,
51652 p_error_text => lv_error_text,
51653 p_token1 => 'COLUMN_NAME',
51654 p_token_value1 => 'PLANNING_PCT');
51655
51656 IF lv_return <> 0 THEN
51657 RAISE ex_logging_err;
51658 END IF;
51659
51660 v_sql_stmt := 22;
51661 lv_sql_stmt :=
51662 'UPDATE msc_st_job_operation_networks mson1'
51663 ||' SET process_flag = '||G_ERROR_FLG||','
51664 ||' error_text = '||''''||lv_message_text||''''
51665 ||' WHERE 100 <> ( SELECT SUM(planning_pct) '
51666 ||' FROM msc_st_job_operation_networks mson2'
51667 ||' WHERE mson2.wip_entity_name = mson1.wip_entity_name'
51668 ||' AND mson2.organization_code = mson1.organization_code'
51669 ||' AND mson2.from_operation_seq_code = mson1.from_operation_seq_code'
51670 ||' AND mson2.sr_instance_code = mson1.sr_instance_code'
51671 ||' AND NVL(mson2.company_name,'||''''||NULL_CHAR||''''||') '
51672 ||' = NVL(mson1.company_name,'||''''||NULL_CHAR||''''||') '
51673 ||' AND mson2.process_flag ='||G_IN_PROCESS
51674 ||' AND mson2.deleted_flag <>1 '
51675 ||' GROUP BY wip_entity_name,sr_instance_code,company_name,organization_code,from_operation_seq_code)'
51676 ||' AND mson1.process_flag = '||G_IN_PROCESS
51677 ||' AND mson1.deleted_flag <>1 '
51678 ||' AND mson1.sr_instance_code = :v_instance_code';
51679
51680
51681 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
51682
51683 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
51684
51685 -- Set the process flag as Valid and derive sr_instance_id
51686 lv_return :=
51687 MSC_ST_UTIL.SET_PROCESS_FLAG(p_table_name => 'MSC_ST_JOB_OPERATION_NETWORKS',
51688 p_instance_id => v_instance_id,
51689 p_instance_code => v_instance_code,
51690 p_process_flag => G_VALID,
51691 p_error_text => lv_error_text,
51692 p_debug => v_debug);
51693
51694 IF lv_return < 0 THEN
51695 RAISe ex_logging_err;
51696 END IF;
51697
51698 -- At the end calling the LOG_ERROR for logging all errored out records
51699
51700 lv_return :=
51701 MSC_ST_UTIL.LOG_ERROR(p_table_name => 'MSC_ST_JOB_OPERATION_NETWORKS',
51702 p_instance_code => v_instance_code,
51703 p_row => lv_column_names,
51704 p_severity => G_SEV_ERROR,
51705 p_message_text => NULL,
51706 p_error_text => lv_error_text,
51707 p_debug => v_debug );
51708
51709 IF lv_return < 0 THEN
51710 Raise ex_logging_err;
51711 END IF;
51712
51713 -- Validation for MSC_ST_JOB_OPERATIONS
51714
51715 --Duplicate records check for the records whose source is XML
51716
51717 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51718 (p_app_short_name => 'MSC',
51719 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
51720 p_message_text => lv_message_text,
51721 p_error_text => lv_error_text);
51722
51723 IF lv_return <> 0 THEN
51724 RAISE ex_logging_err;
51725 END IF;
51726
51727 v_sql_stmt := 18;
51728
51729 lv_sql_stmt :=
51730 'UPDATE msc_st_job_operations msro1 '
51731 ||' SET process_flag = '||G_ERROR_FLG||','
51732 ||' error_text = '||''''||lv_message_text||''''
51733 ||' WHERE message_id < ( SELECT max(message_id) '
51734 ||' FROM msc_st_job_operations msro2'
51735 ||' WHERE msro2.sr_instance_code = msro1.sr_instance_code'
51736 ||' AND msro2.organization_code = msro1.organization_code'
51737 ||' AND msro2.wip_entity_name = msro1.wip_entity_name'
51738 ||' AND NVL(msro2.operation_seq_code,'||''''||NULL_CHAR||''''||') '
51739 ||' = NVL(msro1.operation_seq_code,'||''''||NULL_CHAR||''''||') '
51740 ||' AND NVL(msro2.routing_name,'||''''||NULL_CHAR||''''||') '
51741 ||' = NVL(msro1.routing_name, '||''''||NULL_CHAR||''''||') '
51742 ||' AND NVL(msro2.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
51743 ||' = NVL(msro1.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
51744 ||' AND msro2.process_flag ='||G_IN_PROCESS
51745 ||' AND NVL(msro2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||')'
51746 ||' AND msro1.process_flag = '||G_IN_PROCESS
51747 ||' AND msro1.sr_instance_code = :v_instance_code'
51748 ||' AND NVL(msro1.message_id,'||NULL_VALUE||')<> '||NULL_VALUE;
51749
51750
51751 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
51752
51753 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
51754
51755 --Duplicate records check for the records whose source is batch load
51756
51757 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51758 (p_app_short_name => 'MSC',
51759 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
51760 p_message_text => lv_message_text,
51761 p_error_text => lv_error_text);
51762
51763 IF lv_return <> 0 THEN
51764 RAISE ex_logging_err;
51765 END IF;
51766
51767 v_sql_stmt := 19;
51768 lv_sql_stmt :=
51769 'UPDATE msc_st_job_operations msro1'
51770 ||' SET process_flag = '||G_ERROR_FLG||','
51771 ||' error_text = '||''''||lv_message_text||''''
51772 ||' WHERE EXISTS ( SELECT 1 '
51773 ||' FROM msc_st_job_operations msro2'
51774 ||' WHERE msro2.sr_instance_code = msro1.sr_instance_code'
51775 ||' AND msro2.organization_code = msro1.organization_code'
51776 ||' AND msro2.wip_entity_name = msro1.wip_entity_name'
51777 ||' AND NVL(msro2.company_name,'||''''||NULL_CHAR||''''||') '
51778 ||' = NVL(msro1.company_name,'||''''||NULL_CHAR||''''||') '
51779 ||' AND NVL(msro2.operation_seq_code,'||''''||NULL_CHAR||''''||') '
51780 ||' = NVL(msro1.operation_seq_code,'||''''||NULL_CHAR||''''||') '
51781 ||' AND NVL(msro2.routing_name,'||''''||NULL_CHAR||''''||') '
51782 ||' = NVL(msro1.routing_name, '||''''||NULL_CHAR||''''||') '
51783 ||' AND NVL(msro2.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
51784 ||' = NVL(msro1.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
51785 ||' AND msro2.process_flag ='||G_IN_PROCESS
51786 ||' AND NVL(msro2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
51787 ||' GROUP BY sr_instance_code,company_name,organization_code,wip_entity_name,operation_seq_code'
51788 ||' HAVING COUNT(*) >1 )'
51789 ||' AND msro1.process_flag = '||G_IN_PROCESS
51790 ||' AND msro1.sr_instance_code = :v_instance_code'
51791 ||' AND NVL(msro1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
51792
51793
51794 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
51795
51796 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
51797
51798
51799 lv_column_names :=
51800 'ROUTING_NAME ||''~''||'
51801 ||' WIP_ENTITY_NAME ||''~''||'
51802 ||' ASSEMBLY_NAME ||''~''||'
51803 ||' ALTERNATE_ROUTING_DESIGNATOR ||''~''||'
51804 ||' OPERATION_SEQ_CODE ||''~''||'
51805 ||' EFFECTIVITY_DATE ||''~''||'
51806 ||' RECO_START_DATE ||''~''||'
51807 ||' DEPARTMENT_CODE ||''~''||'
51808 ||' ORGANIZATION_CODE ||''~''||'
51809 ||' SR_INSTANCE_CODE ||''~''||'
51810 ||' RECO_COMPLETION_DATE ||''~''||'
51811 ||' DISABLE_DATE ||''~''||'
51812 ||' NETWORK_START_END ||''~''||'
51813 ||' OPERATION_TYPE ||''~''||'
51814 ||' MINIMUM_TRANSFER_QUANTITY ||''~''||'
51815 ||' YIELD ||''~''||'
51816 ||' OPERATION_LEAD_TIME_PERCENT ||''~''||'
51817 ||' CUMULATIVE_YIELD ||''~''||'
51818 ||' REVERSE_CUMULATIVE_YIELD ||''~''||'
51819 ||' NET_PLANNING_PERCENT ||''~''||'
51820 ||' STANDARD_OPERATION_CODE ||''~''||'
51821 ||' DELETED_FLAG ||''~''||'
51822 ||' COMPANY_NAME ';
51823
51824 LOOP
51825
51826 lv_cursor_stmt :=
51827 ' SELECT msc_st_batch_id_s.NEXTVAL '
51828 ||' FROM dual';
51829
51830 OPEN c1 FOR lv_cursor_stmt;
51831 FETCH c1 INTO lv_batch_id;
51832 CLOSE c1;
51833
51834 v_sql_stmt := 21;
51835 lv_sql_stmt :=
51836 ' UPDATE msc_st_job_operations '
51837 ||' SET batch_id = :lv_batch_id'
51838 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
51839 ||' AND sr_instance_code = :v_instance_code'
51840 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
51841 ||' AND rownum <= '||v_batch_size;
51842
51843
51844 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
51845
51846 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
51847
51848 EXIT WHEN SQL%NOTFOUND;
51849
51850 OPEN c3(lv_batch_id);
51851 FETCH c3 BULK COLLECT INTO lb_rowid;
51852 CLOSE c3;
51853
51854 v_sql_stmt := 22;
51855 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
51856 UPDATE msc_st_job_operations
51857 SET st_transaction_id = msc_st_job_operations_s.NEXTVAL,
51858 refresh_id = v_refresh_id,
51859 last_update_date = v_current_date,
51860 last_updated_by = v_current_user,
51861 creation_date = v_current_date,
51862 created_by = v_current_user
51863 WHERE rowid = lb_rowid(j);
51864
51865
51866 -- Set the message
51867 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51868 (p_app_short_name => 'MSC',
51869 p_error_code => 'MSC_PP_NO_DELETION',
51870 p_message_text => lv_message_text,
51871 p_error_text => lv_error_text,
51872 p_token1 => 'TABLE_NAME',
51873 p_token_value1 => 'MSC_ST_JOB_OPERATIONS');
51874
51875 IF lv_return <> 0 THEN
51876 RAISE ex_logging_err;
51877 END IF;
51878
51879 --Deletion is not allowed on this table.
51880 v_sql_stmt := 06;
51881 lv_sql_stmt :=
51882 ' UPDATE msc_st_job_operations '
51883 ||' SET process_flag ='||G_ERROR_FLG||','
51884 ||' error_text = '||''''||lv_message_text||''''
51885 ||' WHERE deleted_flag = '||SYS_YES
51886 ||' AND process_flag = '||G_IN_PROCESS
51887 ||' AND batch_id = :lv_batch_id'
51888 ||' AND sr_instance_code = :v_instance_code';
51889
51890
51891 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
51892
51893 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
51894
51895 -- Set the error message
51896 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51897 (p_app_short_name => 'MSC',
51898 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
51899 p_message_text => lv_message_text,
51900 p_error_text => lv_error_text,
51901 p_token1 => 'COLUMN_NAME',
51902 p_token_value1 => 'DELETED_FLAG',
51903 p_token2 => 'DEFAULT_VALUE',
51904 p_token_value2 => SYS_NO );
51905
51906 IF lv_return <> 0 THEN
51907 RAISE ex_logging_err;
51908 END IF;
51909
51910
51911 -- Check whether delete flag value is in (1,2),if not default to SYS_NO
51912
51913 lv_where_str :=
51914 ' AND NVL(deleted_flag,'||NULL_VALUE||') <>'||SYS_NO;
51915
51916 lv_return := MSC_ST_UTIL.LOG_ERROR
51917 (p_table_name => 'MSC_ST_JOB_OPERATIONS',
51918 p_instance_code => v_instance_code,
51919 p_row => lv_column_names,
51920 p_severity => G_SEV_WARNING,
51921 p_message_text => lv_message_text,
51922 p_error_text => lv_error_text,
51923 p_batch_id => lv_batch_id,
51924 p_where_str => lv_where_str,
51925 p_col_name => 'DELETED_FLAG',
51926 p_debug => v_debug,
51927 p_default_value => SYS_NO);
51928
51929 IF lv_return <> 0 THEN
51930 RAISE ex_logging_err;
51931 END IF;
51932
51933 -- Set the message
51934
51935 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51936 (p_app_short_name => 'MSC',
51937 p_error_code => 'MSC_PP_INVALID_VALUE',
51938 p_message_text => lv_message_text,
51939 p_error_text => lv_error_text,
51940 p_token1 => 'COLUMN_NAME',
51941 p_token_value1 => 'ORGANIZATION_CODE');
51942
51943 IF lv_return <> 0 THEN
51944 RAISE ex_logging_err;
51945 END IF;
51946
51947 -- derive organization id ,
51948 lv_return :=
51949 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name => 'MSC_ST_JOB_OPERATIONS',
51950 p_org_partner_name =>'ORGANIZATION_CODE',
51951 p_org_partner_id =>'ORGANIZATION_ID',
51952 p_instance_code => v_instance_code,
51953 p_partner_type => G_ORGANIZATION,
51954 p_severity => G_SEV_ERROR,
51955 p_message_text => lv_message_text,
51956 p_batch_id =>lv_batch_id,
51957 p_debug => v_debug,
51958 p_error_text =>lv_error_text);
51959
51960 if(lv_return <> 0) then
51961 RAISE ex_logging_err;
51962 end if;
51963
51964 -- error out the records where wip_entity_name is null
51965
51966 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
51967 (p_app_short_name => 'MSC',
51968 p_error_code => 'MSC_PP_COL_VAL_NULL',
51969 p_message_text => lv_message_text,
51970 p_error_text => lv_error_text,
51971 p_token1 => 'COLUMN_NAME',
51972 p_token_value1 => 'WIP_ENTITY_NAME');
51973
51974 IF lv_return <> 0 THEN
51975 RAISE ex_logging_err;
51976 END IF;
51977
51978 v_sql_stmt := 6;
51979 lv_sql_stmt :=
51980 'UPDATE msc_st_job_operations'
51981 ||' SET error_text = '||''''||lv_message_text||''''||','
51982 ||' process_flag = '||G_ERROR_FLG
51983 ||' WHERE NVL(wip_entity_name,'||''''||NULL_CHAR||''''||') '
51984 ||' = '||''''||NULL_CHAR||''''
51985 ||' AND process_flag = '||G_IN_PROCESS
51986 ||' AND NVL(batch_id,'||NULL_VALUE||')= :lv_batch_id'
51987 ||' AND sr_instance_code = :v_instance_code';
51988
51989
51990 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
51991
51992 EXECUTE IMMEDIATE lv_sql_stmt
51993 USING lv_batch_id,
51994 v_instance_code;
51995
51996
51997 --Deriving wip_entity_id
51998 v_sql_stmt := 10;
51999 lv_sql_stmt :=
52000 'UPDATE msc_st_job_operations mss'
52001 ||' SET wip_entity_id = (SELECT local_id'
52002 ||' FROM msc_local_id_supply mls'
52003 ||' WHERE mls.char4 = mss.wip_entity_name'
52004 ||' AND mls.char3 = mss.organization_code'
52005 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
52006 ||' NVL(mss.company_name,'||''''||NULL_CHAR||''''||') '
52007 ||' AND mls.char1 = mss.sr_instance_code'
52008 ||' AND mls.entity_name = ''WIP_ENTITY_ID'' )'
52009 ||' WHERE process_flag = '||G_IN_PROCESS
52010 ||' AND NVL(batch_id,'||NULL_VALUE||') = :lv_batch_id'
52011 ||' AND sr_instance_code = :v_instance_code';
52012
52013
52014 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
52015
52016 EXECUTE IMMEDIATE lv_sql_stmt
52017 USING lv_batch_id,
52018 v_instance_code;
52019
52020 -- Set the error message
52021
52022 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
52023 (p_app_short_name => 'MSC',
52024 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
52025 p_message_text => lv_message_text,
52026 p_error_text => lv_error_text,
52027 p_token1 => 'COLUMN_NAMES',
52028 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
52029 ||'ORGANIZATION_CODE,WIP_ENTITY_NAME',
52030 p_token2 => 'MASTER_TABLE',
52031 p_token_value2 => 'MSC_ST_SUPPLIES',
52032 p_token3 => 'CHILD_TABLE' ,
52033 p_token_value3 => 'MSC_ST_JOB_OPERATION_NETWORKS' );
52034
52035 IF lv_return <> 0 THEN
52036 RAISE ex_logging_err;
52037 END IF;
52038
52039
52040 -- Error out the records if WIP_ENTITY_ID NULL
52041
52042 v_sql_stmt := 11;
52043 lv_sql_stmt:=
52044 'UPDATE msc_st_job_operations msrr'
52045 ||' SET process_flag ='||G_ERROR_FLG||','
52046 ||' error_text = '||''''||lv_message_text||''''
52047 ||' WHERE NVL(wip_entity_id,'||NULL_VALUE||') = '||NULL_VALUE
52048 ||' AND sr_instance_code = :v_instance_code'
52049 ||' AND process_flag ='||G_IN_PROCESS
52050 ||' AND batch_id = :lv_batch_id';
52051
52052
52053 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
52054
52055 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
52056
52057 -- Set the error message
52058 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
52059 (p_app_short_name => 'MSC',
52060 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
52061 p_message_text => lv_message_text,
52062 p_error_text => lv_error_text,
52063 p_token1 => 'COLUMN_NAME',
52064 p_token_value1 => 'RECOMMENDED');
52065
52066 IF lv_return <> 0 THEN
52067 RAISE ex_logging_err;
52068 END IF;
52069
52070 -- Error out the records where RECOMMENDED is not 'Y' or 'N'
52071
52072 v_sql_stmt := 7;
52073 lv_sql_stmt :=
52074 'UPDATE msc_st_job_operations'
52075 ||' SET process_flag ='||G_ERROR_FLG||','
52076 ||' error_text = '||''''||lv_message_text||''''
52077 ||' WHERE recommended NOT IN (''Y'', ''N'')'
52078 ||' AND sr_instance_code = :v_instance_code'
52079 ||' AND process_flag = '||G_IN_PROCESS
52080 ||' AND batch_id = :lv_batch_id';
52081
52082
52083 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
52084
52085 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
52086
52087 -- Now we will check whether Routing Name is NULL , if it is NULL we will populate the
52088 -- ASSEMBLY NAME in ROUTING_NAME column for all such records
52089
52090 lv_sql_stmt :=
52091 'UPDATE msc_st_job_operations '
52092 ||' SET routing_name = assembly_name'
52093 ||' WHERE sr_instance_code = :v_instance_code'
52094 ||' AND process_flag = '||G_IN_PROCESS
52095 ||' AND NVL(routing_name,'||''''||NULL_CHAR||''''||') '
52096 ||' = '||''''||NULL_CHAR||''''
52097 ||' AND batch_id = :lv_batch_id';
52098
52099
52100 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
52101
52102 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
52103
52104 -- Derive routing_sequence_id
52105
52106 -- Set the error message
52107 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
52108 (p_app_short_name => 'MSC',
52109 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
52110 p_message_text => lv_message_text,
52111 p_error_text => lv_error_text,
52112 p_token1 => 'COLUMN_NAMES',
52113 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
52114 ||'ORGANIZATION_CODE,ROUTING_NAME',
52115 p_token2 => 'MASTER_TABLE',
52116 p_token_value2 => 'MSC_ST_ROUTINGS',
52117 p_token3 => 'CHILD_TABLE' ,
52118 p_token_value3 => 'MSC_ST_JOB_OPERATIONS' );
52119
52120 IF lv_return <> 0 THEN
52121 RAISE ex_logging_err;
52122 END IF;
52123
52124 -- Derive the ROUTING_SEQUENCE_ID from LOCAL ID table
52125
52126 lv_return :=
52127 MSC_ST_UTIL.DERIVE_ROUTING_SEQUENCE_ID
52128 (p_table_name => 'MSC_ST_JOB_OPERATIONS',
52129 p_rtg_col_name => 'ROUTING_NAME',
52130 p_rtg_col_id => 'ROUTING_SEQUENCE_ID',
52131 p_instance_code => v_instance_code,
52132 p_severity => G_SEV_ERROR,
52133 p_message_text => lv_message_text,
52134 p_batch_id => lv_batch_id,
52135 p_debug => v_debug,
52136 p_error_text => lv_error_text);
52137
52138 if (lv_return <> 0 )then
52139 RAISE ex_logging_err;
52140 end if;
52141
52142
52143
52144 -- Set the error message
52145 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
52146 (p_app_short_name => 'MSC',
52147 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
52148 p_message_text => lv_message_text,
52149 p_error_text => lv_error_text,
52150 p_token1 => 'COLUMN_NAME',
52151 p_token_value1 => 'EFFECTIVITY_DATE',
52152 p_token2 => 'DEFAULT_VALUE',
52153 p_token_value2 => 'SYSDATE' );
52154
52155 IF lv_return <> 0 THEN
52156 RAISE ex_logging_err;
52157 END IF;
52158
52159 -- Default effectivity date as SYSDATE if NULL
52160
52161 lv_where_str :=
52162 ' AND NVL(effectivity_date,SYSDATE-36500 ) = SYSDATE-36500 ' ;
52163
52164 lv_return := MSC_ST_UTIL.LOG_ERROR
52165 (p_table_name => 'MSC_ST_JOB_OPERATIONS',
52166 p_instance_code => v_instance_code,
52167 p_row => lv_column_names,
52168 p_severity => G_SEV_WARNING,
52169 p_message_text => lv_message_text,
52170 p_error_text => lv_error_text,
52171 p_batch_id => lv_batch_id,
52172 p_where_str => lv_where_str,
52173 p_col_name => 'EFFECTIVITY_DATE',
52174 p_debug => v_debug,
52175 p_default_value => 'SYSDATE');
52176
52177 IF lv_return <> 0 THEN
52178 RAISE ex_logging_err;
52179 END IF;
52180
52181 -- Derive operation_seq_num, operation_sequence_id
52182
52183 v_sql_stmt := 18;
52184 lv_sql_Stmt :=
52185 'UPDATE msc_st_job_operations mson'
52186 ||' SET (operation_sequence_id, operation_seq_num) = (SELECT local_id, number1'
52187 ||' FROM msc_local_id_setup mlis'
52188 ||' WHERE mlis.char1 = mson.sr_instance_code'
52189 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
52190 ||' = NVL(mson.company_name,'||''''||NULL_CHAR||''''||') '
52191 ||' AND mlis.char3 = mson.organization_code'
52192 ||' AND mlis.char4 = mson.routing_name'
52193 ||' AND mlis.char5 = mson.operation_seq_code'
52194 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
52195 ||' = NVL(mson.alternate_routing_designator,'||''''||NULL_CHAR||''''||')'
52196 ||' AND mlis.date1 = mson.EFFECTIVITY_DATE'
52197 ||' AND mlis.entity_name = ''OPERATION_SEQUENCE_ID'' '
52198 ||' AND mlis.instance_id = '||v_instance_id||')'
52199 ||' WHERE sr_instance_code = :v_instance_code'
52200 ||' AND process_flag ='||G_IN_PROCESS
52201 ||' AND batch_id = :lv_batch_id';
52202
52203
52204 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
52205
52206 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
52207
52208 -- operation_seq_num cannot be null. Error out the records with null value for them.
52209 -- Set the error message
52210
52211 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
52212 (p_app_short_name => 'MSC',
52213 p_error_code => 'MSC_PP_COL_VAL_NULL',
52214 p_message_text => lv_message_text,
52215 p_error_text => lv_error_text,
52216 p_token1 => 'COLUMN_NAME',
52217 p_token_value1 => 'OPERATION_SEQUENCE_ID OR '
52218 ||'OPERATION_SEQ_NUM');
52219
52220 IF lv_return <> 0 THEN
52221 RAISE ex_logging_err;
52222 END IF;
52223
52224 -- Error out the records whose operation_sequence_id, operation_seq_num is NULL
52225
52226 v_sql_stmt := 19;
52227 lv_sql_stmt :=
52228 'UPDATE msc_st_job_operations'
52229 ||' SET process_flag ='||G_ERROR_FLG||','
52230 ||' error_text = '||''''||lv_message_text||''''
52231 ||' WHERE (NVL(operation_sequence_id,'||NULL_VALUE||') ='||NULL_VALUE
52232 ||' OR NVL(operation_seq_num,'||NULL_VALUE||') ='||NULL_VALUE||')'
52233 ||' AND sr_instance_code = :v_instance_code'
52234 ||' AND process_flag = '||G_IN_PROCESS
52235 ||' AND batch_id = :lv_batch_id';
52236
52237
52238 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
52239
52240 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
52241
52242 -- Derive department id
52243 v_sql_stmt := 27;
52244 lv_sql_stmt :=
52245 'UPDATE msc_st_job_operations msro'
52246 ||' SET department_id= (SELECT local_id'
52247 ||' FROM msc_local_id_setup mlis'
52248 ||' WHERE mlis.char1 = msro.sr_instance_code'
52249 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
52250 ||' = NVL(msro.company_name,'||''''||NULL_CHAR||''''||') '
52251 ||' AND mlis.char3 = msro.organization_code'
52252 ||' AND mlis.char4 = msro.department_code'
52253 ||' AND mlis.entity_name = ''DEPARTMENT_ID'')'
52254 ||' WHERE sr_instance_code = :v_instance_code'
52255 ||' AND deleted_flag = '||SYS_NO
52256 ||' AND process_flag = '||G_IN_PROCESS
52257 ||' AND batch_id = :lv_batch_id';
52258
52259
52260 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
52261
52262 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
52263
52264 -- Set the error message
52265 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
52266 (p_app_short_name => 'MSC',
52267 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
52268 p_message_text => lv_message_text,
52269 p_error_text => lv_error_text,
52270 p_token1 => 'COLUMN_NAMES',
52271 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
52272 ||'ORGANIZATION_CODE,DEPARTMENT_CODE',
52273 p_token2 => 'MASTER_TABLE',
52274 p_token_value2 => 'MSC_ST_DEPARTMENT_RESOURCES',
52275 p_token3 => 'CHILD_TABLE' ,
52276 p_token_value3 => 'MSC_ST_JOB_OPERATIONS' );
52277
52278 IF lv_return <> 0 THEN
52279 RAISE ex_logging_err;
52280 END IF;
52281
52282 -- Log an error if unable to derive department id
52283
52284 v_sql_stmt := 28;
52285 lv_sql_stmt :=
52286 'UPDATE msc_st_job_operations '
52287 ||' SET process_flag ='||G_ERROR_FLG||','
52288 ||' error_text = '||''''||lv_message_text||''''
52289 ||' WHERE NVL(department_id,'||NULL_VALUE||') ='||NULL_VALUE
52290 ||' AND sr_instance_code = :v_instance_code'
52291 ||' AND deleted_flag ='||SYS_NO
52292 ||' AND process_flag ='|| G_IN_PROCESS
52293 ||' AND batch_id = :lv_batch_id' ;
52294
52295
52296 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
52297
52298 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
52299
52300 --Call to customised validation.
52301
52302 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
52303 (ERRBUF => lv_error_text,
52304 RETCODE => lv_return,
52305 pBatchID => lv_batch_id,
52306 pInstanceCode => v_instance_code,
52307 pEntityName => 'MSC_ST_JOB_OPERATIONS',
52308 pInstanceID => v_instance_id);
52309
52310 IF NVL(lv_return,0) <> 0 THEN
52311 RAISE ex_logging_err;
52312 END IF;
52313
52314 -- Set the process flag as Valid and derive sr_instance_id
52315 lv_return :=
52316 MSC_ST_UTIL.SET_PROCESS_FLAG(p_table_name => 'MSC_ST_JOB_OPERATIONS',
52317 p_instance_id => v_instance_id,
52318 p_instance_code => v_instance_code,
52319 p_process_flag => G_VALID,
52320 p_error_text => lv_error_text,
52321 p_debug => v_debug,
52322 p_batch_id => lv_batch_id);
52323
52324 IF lv_return < 0 THEN
52325 RAISe ex_logging_err;
52326 END IF;
52327
52328
52329 -- At the end calling the LOG_ERROR for logging all errored out records
52330
52331 lv_return :=
52332 MSC_ST_UTIL.LOG_ERROR(p_table_name => 'MSC_ST_JOB_OPERATIONS',
52333 p_instance_code => v_instance_code,
52334 p_row => lv_column_names,
52335 p_severity => G_SEV_ERROR,
52336 p_message_text => NULL,
52337 p_error_text => lv_error_text,
52338 p_debug => v_debug,
52339 p_batch_id => lv_batch_id );
52340
52341 IF lv_return < 0 THEN
52342 RAISe ex_logging_err;
52343 END IF;
52344
52345 COMMIT;
52346 END LOOP;
52347
52348 -- Validation for MSC_ST_JOB_REQUIREMENT_OPS
52349
52350 --Duplicate records check for the records whose source is XML
52351
52352 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
52353 (p_app_short_name => 'MSC',
52354 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
52355 p_message_text => lv_message_text,
52356 p_error_text => lv_error_text);
52357
52358 IF lv_return <> 0 THEN
52359 RAISE ex_logging_err;
52360 END IF;
52361
52362 v_sql_stmt := 18;
52363
52364 lv_sql_stmt :=
52365 'UPDATE msc_st_job_requirement_ops msd1'
52366 ||' SET process_flag = '||G_ERROR_FLG||','
52367 ||' error_text = '||''''||lv_message_text||''''
52368 ||' WHERE message_id < (SELECT MAX(message_id)'
52369 ||' FROM msc_st_job_requirement_ops msd2'
52370 ||' WHERE msd2.sr_instance_code '
52371 ||' = msd1.sr_instance_code '
52372 ||' AND msd2.organization_code '
52373 ||' = msd1.organization_code '
52374 ||' AND NVL(msd2.company_name,'||''''||NULL_CHAR||''''||') '
52375 ||' = NVL(msd1.company_name,'||''''||NULL_CHAR||''''||') '
52376 ||' AND msd2.wip_entity_name = msd1.wip_entity_name'
52377 ||' AND NVL(msd2.operation_seq_code,'||''''||NULL_CHAR||''''||') '
52378 ||' = NVL(msd1.operation_seq_code,'||''''||NULL_CHAR||''''||') '
52379 ||' AND NVL(msd2.source_phantom_name,'||''''||NULL_CHAR||''''||') '
52380 ||' = NVL(msd1.source_phantom_name,'||''''||NULL_CHAR||''''||') '
52381 ||' AND NVL(msd2.assembly_item_name,'||''''||NULL_CHAR||''''||') '
52382 ||' = NVL(msd1.assembly_item_name,'||''''||NULL_CHAR||''''||') '
52383 ||' AND NVL(msd2.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
52384 ||' = NVL(msd1.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
52385 ||' AND NVL(msd2.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
52386 ||' = NVL(msd1.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
52387 ||' AND msd2.component_name '
52388 ||' = msd1.component_name '
52389 ||' AND msd2.primary_component_name '
52390 ||' = msd1.primary_component_name '
52391 ||' AND msd2.effectivity_date '
52392 ||' = msd1.effectivity_date '
52393 ||' AND msd2.process_flag = '||G_IN_PROCESS
52394 ||' AND NVL(msd2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||')'
52395 ||' AND msd1.process_flag ='|| G_IN_PROCESS
52396 ||' AND msd1.sr_instance_code = :v_instance_code '
52397 ||' AND NVL(msd1.message_id,'||NULL_VALUE||')<> '||NULL_VALUE;
52398
52399
52400 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
52401
52402 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
52403
52404 --Duplicate records check for the records whose source is batch load
52405
52406 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
52407 (p_app_short_name => 'MSC',
52408 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
52409 p_message_text => lv_message_text,
52410 p_error_text => lv_error_text);
52411
52412 IF lv_return <> 0 THEN
52413 RAISE ex_logging_err;
52414 END IF;
52415
52416 v_sql_stmt := 02;
52417
52418 lv_sql_stmt :=
52419 'UPDATE msc_st_job_requirement_ops msd1'
52420 ||' SET process_flag = '||G_ERROR_FLG||','
52421 ||' error_text = '||''''||lv_message_text||''''
52422 ||' WHERE EXISTS( SELECT 1 '
52423 ||' FROM msc_st_job_requirement_ops msd2'
52424 ||' WHERE msd2.sr_instance_code '
52425 ||' = msd1.sr_instance_code '
52426 ||' AND msd2.organization_code '
52427 ||' = msd1.organization_code '
52428 ||' AND NVL(msd2.company_name,'||''''||NULL_CHAR||''''||') '
52429 ||' = NVL(msd1.company_name,'||''''||NULL_CHAR||''''||') '
52430 ||' AND msd2.wip_entity_name = msd1.wip_entity_name'
52431 ||' AND NVL(msd2.operation_seq_code,'||''''||NULL_CHAR||''''||') '
52432 ||' = NVL(msd1.operation_seq_code,'||''''||NULL_CHAR||''''||') '
52433 ||' AND NVL(msd2.source_phantom_name,'||''''||NULL_CHAR||''''||') '
52434 ||' = NVL(msd1.source_phantom_name,'||''''||NULL_CHAR||''''||') '
52435 ||' AND NVL(msd2.assembly_item_name,'||''''||NULL_CHAR||''''||') '
52436 ||' = NVL(msd1.assembly_item_name,'||''''||NULL_CHAR||''''||') '
52437 ||' AND NVL(msd2.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
52438 ||' = NVL(msd1.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
52439 ||' AND NVL(msd2.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
52440 ||' = NVL(msd1.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
52441 ||' AND msd2.component_name '
52442 ||' = msd1.component_name '
52443 ||' AND msd2.primary_component_name '
52444 ||' = msd1.primary_component_name '
52445 ||' AND msd2.effectivity_date '
52446 ||' = msd1.effectivity_date '
52447 ||' AND msd2.process_flag = '||G_IN_PROCESS
52448 ||' AND NVL(msd2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
52449 ||' GROUP BY sr_instance_code,organization_code,wip_entity_name,'
52450 ||' company_name,operation_seq_code,component_name,primary_component_name,source_phantom_name,effectivity_date'
52451 ||' HAVING COUNT(*) > 1)'
52452 ||' AND msd1.process_flag = '||G_IN_PROCESS
52453 ||' AND msd1.sr_instance_code = :v_instance_code'
52454 ||' AND NVL(msd1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
52455
52456
52457 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
52458
52459 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
52460
52461 lv_column_names :=
52462 'COMPONENT_NAME ||''~''||'
52463 ||' ORGANIZATION_CODE ||''~''||'
52464 ||' WIP_ENTITY_NAME ||''~''||'
52465 ||' SR_INSTANCE_CODE ||''~''||'
52466 ||' ASSEMBLY_ITEM_NAME ||''~''||'
52467 ||' OPERATION_SEQ_CODE ||''~''||'
52468 ||' FROM_END_ITEM_UNIT_NUMBER ||''~''||'
52469 ||' TO_END_ITEM_UNIT_NUMBER ||''~''||'
52470 ||' WIP_SUPPLY_TYPE ||''~''||'
52471 ||' DELETED_FLAG ||''~''||'
52472 ||' COMPANY_NAME ||''~''||'
52473 ||' RECO_DATE_REQUIRED ||''~''||'
52474 ||' RECOMMENDED ||''~''||'
52475 ||' EFFECTIVITY_DATE ||''~''||'
52476 ||' DISABLE_DATE ||''~''||'
52477 ||' PRIMARY_COMPONENT_NAME' ;
52478
52479 LOOP
52480 v_sql_stmt := 03;
52481 SELECT msc_st_batch_id_s.NEXTVAL
52482 INTO lv_batch_id
52483 FROM DUAL;
52484
52485 v_sql_stmt := 04;
52486 lv_sql_stmt :=
52487 ' UPDATE msc_st_job_requirement_ops '
52488 ||' SET batch_id = :lv_batch_id'
52489 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
52490 ||' AND sr_instance_code = :v_instance_code'
52491 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
52492 ||' AND rownum <= '||v_batch_size;
52493
52494
52495
52496 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
52497
52498 EXECUTE IMMEDIATE lv_sql_stmt
52499 USING lv_batch_id,
52500 v_instance_code;
52501
52502 EXIT WHEN SQL%NOTFOUND ;
52503
52504 OPEN c4 (lv_batch_id);
52505 FETCH c4 BULK COLLECT INTO lb_rowid;
52506 CLOSE c4;
52507
52508 v_sql_stmt := 03;
52509 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
52510 UPDATE msc_st_job_requirement_ops
52511 SET st_transaction_id = msc_st_job_requirement_ops_s.NEXTVAL,
52512 refresh_id = v_refresh_id,
52513 last_update_date = v_current_date,
52514 last_updated_by = v_current_user,
52515 creation_date = v_current_date,
52516 created_by = v_current_user
52517 WHERE rowid = lb_rowid(j);
52518
52519 -- Set the error message
52520 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
52521 (p_app_short_name => 'MSC',
52522 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
52523 p_message_text => lv_message_text,
52524 p_error_text => lv_error_text,
52525 p_token1 => 'COLUMN_NAME',
52526 p_token_value1 => 'DELETED_FLAG',
52527 p_token2 => 'DEFAULT_VALUE',
52528 p_token_value2 => SYS_NO );
52529
52530 IF lv_return <> 0 THEN
52531 RAISE ex_logging_err;
52532 END IF;
52533 --Log a warning for those records where the deleted_flag has a value other
52534 --SYS_NO
52535
52536 lv_where_str :=
52537 ' AND NVL(deleted_flag,'||NULL_VALUE||') NOT IN(1,2)';
52538
52539 lv_return := MSC_ST_UTIL.LOG_ERROR
52540 (p_table_name => 'MSC_ST_JOB_REQUIREMENT_OPS',
52541 p_instance_code => v_instance_code,
52542 p_row => lv_column_names,
52543 p_severity => G_SEV_WARNING,
52544 p_message_text => lv_message_text,
52545 p_error_text => lv_error_text,
52546 p_batch_id => lv_batch_id,
52547 p_where_str => lv_where_str,
52548 p_col_name => 'DELETED_FLAG',
52549 p_debug => v_debug,
52550 p_default_value => SYS_NO);
52551
52552 IF lv_return <> 0 THEN
52553 RAISE ex_logging_err;
52554 END IF;
52555
52556 -- Set the message
52557 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
52558 (p_app_short_name => 'MSC',
52559 p_error_code => 'MSC_PP_INVALID_VALUE',
52560 p_message_text => lv_message_text,
52561 p_error_text => lv_error_text,
52562 p_token1 => 'COLUMN_NAME',
52563 p_token_value1 => 'ORGANIZATION_CODE');
52564
52565 IF lv_return <> 0 THEN
52566 RAISE ex_logging_err;
52567 END IF;
52568
52569 --Derive Organization_id
52570 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
52571 (p_table_name => 'MSC_ST_JOB_REQUIREMENT_OPS',
52572 p_org_partner_name => 'ORGANIZATION_CODE',
52573 p_org_partner_id => 'ORGANIZATION_ID',
52574 p_instance_code => v_instance_code,
52575 p_partner_type => G_ORGANIZATION,
52576 p_error_text => lv_error_text,
52577 p_batch_id => lv_batch_id,
52578 p_severity => G_SEV_ERROR,
52579 p_message_text => lv_message_text,
52580 p_debug => v_debug,
52581 p_row => lv_column_names);
52582
52583 IF lv_return <> 0 THEN
52584 RAISE ex_logging_err;
52585 END IF;
52586
52587 --Deriving wip_entity_id
52588 v_sql_stmt := 10;
52589 lv_sql_stmt :=
52590 'UPDATE msc_st_job_requirement_ops mss'
52591 ||' SET wip_entity_id = (SELECT local_id'
52592 ||' FROM msc_local_id_supply mls'
52593 ||' WHERE mls.char4 = mss.wip_entity_name'
52594 ||' AND mls.char3 = mss.organization_code'
52595 ||' AND NVL(mls.char2, '||''''||NULL_CHAR||''''||') = '
52596 ||' NVL(mss.company_name,'||''''||NULL_CHAR||''''||') '
52597 ||' AND mls.char1 = mss.sr_instance_code'
52598 ||' AND mls.entity_name = ''WIP_ENTITY_ID'' )'
52599 ||' WHERE process_flag = '||G_IN_PROCESS
52600 ||' AND NVL(batch_id,'||NULL_VALUE||') = :lv_batch_id'
52601 ||' AND sr_instance_code = :v_instance_code';
52602
52603
52604 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
52605
52606 EXECUTE IMMEDIATE lv_sql_stmt
52607 USING lv_batch_id,
52608 v_instance_code;
52609
52610 -- Set the error message
52611
52612 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
52613 (p_app_short_name => 'MSC',
52614 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
52615 p_message_text => lv_message_text,
52616 p_error_text => lv_error_text,
52617 p_token1 => 'COLUMN_NAMES',
52618 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
52619 ||'ORGANIZATION_CODE,WIP_ENTITY_NAME',
52620 p_token2 => 'MASTER_TABLE',
52621 p_token_value2 => 'MSC_ST_SUPPLIES',
52622 p_token3 => 'CHILD_TABLE' ,
52623 p_token_value3 => 'MSC_ST_JOB_REQUIREMENT_OPS' );
52624
52625 IF lv_return <> 0 THEN
52626 RAISE ex_logging_err;
52627 END IF;
52628
52629
52630 -- Error out the records if WIP_ENTITY_ID NULL
52631
52632 lv_sql_stmt:=
52633 'UPDATE msc_st_job_requirement_ops msrr'
52634 ||' SET process_flag ='||G_ERROR_FLG||','
52635 ||' error_text = '||''''||lv_message_text||''''
52636 ||' WHERE NVL(wip_entity_id,'||NULL_VALUE||') = '||NULL_VALUE
52637 ||' AND sr_instance_code = :v_instance_code'
52638 ||' AND process_flag ='||G_IN_PROCESS
52639 ||' AND batch_id = :lv_batch_id';
52640
52641
52642 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
52643
52644 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
52645
52646 -- Set the error message
52647 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
52648 (p_app_short_name => 'MSC',
52649 p_error_code => 'MSC_PP_INVALID_VALUE',
52650 p_message_text => lv_message_text,
52651 p_error_text => lv_error_text,
52652 p_token1 => 'COLUMN_NAME',
52653 p_token_value1 => 'RECOMMENDED');
52654
52655 IF lv_return <> 0 THEN
52656 RAISE ex_logging_err;
52657 END IF;
52658
52659 -- Error out the records where RECOMMENDED is not 'Y' or 'N'
52660
52661 v_sql_stmt := 7;
52662 lv_sql_stmt :=
52663 'UPDATE msc_st_job_requirement_ops'
52664 ||' SET process_flag ='||G_ERROR_FLG||','
52665 ||' error_text = '||''''||lv_message_text||''''
52666 ||' WHERE recommended NOT IN (''Y'', ''N'',''y'',''n'')'
52667 ||' AND sr_instance_code = :v_instance_code'
52668 ||' AND process_flag = '||G_IN_PROCESS
52669 ||' AND batch_id = :lv_batch_id';
52670
52671
52672 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
52673
52674 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
52675
52676 -- Set the message
52677 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
52678 (p_app_short_name => 'MSC',
52679 p_error_code => 'MSC_PP_INVALID_VALUE',
52680 p_message_text => lv_message_text,
52681 p_error_text => lv_error_text,
52682 p_token1 => 'COLUMN_NAME',
52683 p_token_value1 => 'COMPONENT_NAME');
52684
52685 IF lv_return <> 0 THEN
52686 RAISE ex_logging_err;
52687 END IF;
52688
52689 --Derive component_item_id
52690 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
52691 (p_table_name => 'MSC_ST_JOB_REQUIREMENT_OPS',
52692 p_item_col_name => 'COMPONENT_NAME',
52693 p_item_col_id => 'COMPONENT_ITEM_ID',
52694 p_instance_id => v_instance_id,
52695 p_instance_code => v_instance_code,
52696 p_message_text => lv_message_text,
52697 p_error_text => lv_error_text,
52698 p_batch_id => lv_batch_id,
52699 p_severity => G_SEV_ERROR,
52700 p_debug => v_debug,
52701 p_row => lv_column_names);
52702
52703 IF lv_return <> 0 THEN
52704 RAISE ex_logging_err;
52705 END IF;
52706
52707 -- Set the message
52708 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
52709 (p_app_short_name => 'MSC',
52710 p_error_code => 'MSC_PP_INVALID_VALUE',
52711 p_message_text => lv_message_text,
52712 p_error_text => lv_error_text,
52713 p_token1 => 'COLUMN_NAME',
52714 p_token_value1 => 'PRIMARY_COMPONENT_NAME');
52715
52716 IF lv_return <> 0 THEN
52717 RAISE ex_logging_err;
52718 END IF;
52719
52720 --Derive primary_component_id
52721 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
52722 (p_table_name => 'MSC_ST_JOB_REQUIREMENT_OPS',
52723 p_item_col_name => 'PRIMARY_COMPONENT_NAME',
52724 p_item_col_id => 'PRIMARY_COMPONENT_ID',
52725 p_instance_id => v_instance_id,
52726 p_instance_code => v_instance_code,
52727 p_message_text => lv_message_text,
52728 p_error_text => lv_error_text,
52729 p_batch_id => lv_batch_id,
52730 p_severity => G_SEV_ERROR,
52731 p_debug => v_debug,
52732 p_row => lv_column_names);
52733
52734 IF lv_return <> 0 THEN
52735 RAISE ex_logging_err;
52736 END IF;
52737
52738 -- Set the message
52739 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
52740 (p_app_short_name => 'MSC',
52741 p_error_code => 'MSC_PP_INVALID_VALUE',
52742 p_message_text => lv_message_text,
52743 p_error_text => lv_error_text,
52744 p_token1 => 'COLUMN_NAME',
52745 p_token_value1 => 'SOURCE_PHANTOM_NAME');
52746
52747 IF lv_return <> 0 THEN
52748 RAISE ex_logging_err;
52749 END IF;
52750
52751 --Derive primary_component_id
52752 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
52753 (p_table_name => 'MSC_ST_JOB_REQUIREMENT_OPS',
52754 p_item_col_name => 'SOURCE_PHANTOM_NAME',
52755 p_item_col_id => 'SOURCE_PHANTOM_ID',
52756 p_instance_id => v_instance_id,
52757 p_instance_code => v_instance_code,
52758 p_message_text => lv_message_text,
52759 p_error_text => lv_error_text,
52760 p_batch_id => lv_batch_id,
52761 p_severity => G_SEV3_ERROR,
52762 p_debug => v_debug,
52763 p_row => lv_column_names);
52764
52765 IF lv_return <> 0 THEN
52766 RAISE ex_logging_err;
52767 END IF;
52768
52769 -- Set the message
52770 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
52771 (p_app_short_name => 'MSC',
52772 p_error_code => 'MSC_PP_COL_VAL_NULL',
52773 p_message_text => lv_message_text,
52774 p_error_text => lv_error_text,
52775 p_token1 => 'COLUMN_NAME',
52776 p_token_value1 => 'QUANTITY_PER_ASSEMBLY');
52777
52778
52779 IF lv_return <> 0 THEN
52780 RAISE ex_logging_err;
52781 END IF;
52782
52783
52784 -- Error out records where QUANTITY_PER_ASSEMBLY is NULL;
52785
52786 v_sql_stmt := 06;
52787 lv_sql_stmt :=
52788 'UPDATE msc_st_job_requirement_ops '
52789 ||' SET process_flag = '||G_ERROR_FLG||','
52790 ||' error_text = '||''''||lv_message_text||''''
52791 ||' WHERE NVL(quantity_per_assembly,'||NULL_VALUE||')='||NULL_VALUE
52792 ||' AND process_flag = '||G_IN_PROCESS
52793 ||' AND deleted_flag = '||SYS_NO
52794 ||' AND batch_id = :lv_batch_id'
52795 ||' AND sr_instance_code = :v_instance_code';
52796
52797
52798 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
52799
52800 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
52801
52802 -- Set the error message
52803 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
52804 (p_app_short_name => 'MSC',
52805 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
52806 p_message_text => lv_message_text,
52807 p_error_text => lv_error_text,
52808 p_token1 => 'COLUMN_NAME',
52809 p_token_value1 => 'EFFECTIVITY_DATE',
52810 p_token2 => 'DEFAULT_VALUE',
52811 p_token_value2 => 'SYSDATE' );
52812
52813 IF lv_return <> 0 THEN
52814 RAISE ex_logging_err;
52815 END IF;
52816
52817 -- Default effectivity date as SYSDATE if NULL
52818
52819 lv_where_str :=
52820 ' AND NVL(effectivity_date,SYSDATE-36500 ) = SYSDATE-36500 ' ;
52821
52822 lv_return := MSC_ST_UTIL.LOG_ERROR
52823 (p_table_name => 'MSC_ST_JOB_REQUIREMENT_OPS',
52824 p_instance_code => v_instance_code,
52825 p_row => lv_column_names,
52826 p_severity => G_SEV_WARNING,
52827 p_message_text => lv_message_text,
52828 p_error_text => lv_error_text,
52829 p_batch_id => lv_batch_id,
52830 p_where_str => lv_where_str,
52831 p_col_name => 'EFFECTIVITY_DATE',
52832 p_debug => v_debug,
52833 p_default_value => 'SYSDATE');
52834
52835 IF lv_return <> 0 THEN
52836 RAISE ex_logging_err;
52837 END IF;
52838
52839 -- Set the error message
52840 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
52841 (p_app_short_name => 'MSC',
52842 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
52843 p_message_text => lv_message_text,
52844 p_error_text => lv_error_text,
52845 p_token1 => 'COLUMN_NAME',
52846 p_token_value1 => 'COMPONENT_YIELD_FACTOR',
52847 p_token2 => 'DEFAULT_VALUE',
52848 p_token_value2 => 1 );
52849
52850 IF lv_return <> 0 THEN
52851 RAISE ex_logging_err;
52852 END IF;
52853
52854 -- Default component_yield_factor if NULL
52855
52856 lv_where_str :=
52857 ' AND NVL(COMPONENT_YIELD_FACTOR,'||NULL_VALUE||') = '||NULL_VALUE ;
52858
52859 lv_return := MSC_ST_UTIL.LOG_ERROR
52860 (p_table_name => 'MSC_ST_JOB_REQUIREMENT_OPS',
52861 p_instance_code => v_instance_code,
52862 p_row => lv_column_names,
52863 p_severity => G_SEV_WARNING,
52864 p_message_text => lv_message_text,
52865 p_error_text => lv_error_text,
52866 p_batch_id => lv_batch_id,
52867 p_where_str => lv_where_str,
52868 p_col_name => 'COMPONENT_YIELD_FACTOR',
52869 p_debug => v_debug,
52870 p_default_value => 1);
52871
52872 IF lv_return <> 0 THEN
52873 RAISE ex_logging_err;
52874 END IF;
52875
52876 -- Set the error message
52877 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
52878 (p_app_short_name => 'MSC',
52879 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
52880 p_message_text => lv_message_text,
52881 p_error_text => lv_error_text,
52882 p_token1 => 'COLUMN_NAME',
52883 p_token_value1 => 'PLANNING_FACTOR',
52884 p_token2 => 'DEFAULT_VALUE',
52885 p_token_value2 => 100 );
52886
52887 IF lv_return <> 0 THEN
52888 RAISE ex_logging_err;
52889 END IF;
52890
52891 -- Default planning_factor if NULL
52892
52893 lv_where_str :=
52894 ' AND NVL(PLANNING_FACTOR,'||NULL_VALUE||') = '||NULL_VALUE ;
52895
52896 lv_return := MSC_ST_UTIL.LOG_ERROR
52897 (p_table_name => 'MSC_ST_JOB_REQUIREMENT_OPS',
52898 p_instance_code => v_instance_code,
52899 p_row => lv_column_names,
52900 p_severity => G_SEV_WARNING,
52901 p_message_text => lv_message_text,
52902 p_error_text => lv_error_text,
52903 p_batch_id => lv_batch_id,
52904 p_where_str => lv_where_str,
52905 p_col_name => 'PLANNING_FACTOR',
52906 p_debug => v_debug,
52907 p_default_value => 100);
52908
52909 IF lv_return <> 0 THEN
52910 RAISE ex_logging_err;
52911 END IF;
52912
52913 -- Set the error message
52914 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
52915 (p_app_short_name => 'MSC',
52916 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
52917 p_message_text => lv_message_text,
52918 p_error_text => lv_error_text,
52919 p_token1 => 'COLUMN_NAME',
52920 p_token_value1 => 'WIP_SUPPLY_TYPE',
52921 p_token2 => 'DEFAULT_VALUE',
52922 p_token_value2 => G_WIP_SUPPLY_TYPE );
52923
52924 IF lv_return <> 0 THEN
52925 RAISE ex_logging_err;
52926 END IF;
52927
52928 -- Default wip_supply_type as 1
52929
52930 lv_where_str := ' AND NVL(wip_supply_type,'||NULL_VALUE||') NOT IN (1,2,3,4,5,6,7)'
52931 ||' AND deleted_flag ='||SYS_NO ;
52932
52933 lv_return := MSC_ST_UTIL.LOG_ERROR
52934 (p_table_name => 'MSC_ST_JOB_REQUIREMENT_OPS',
52935 p_instance_code => v_instance_code,
52936 p_row => lv_column_names,
52937 p_severity => G_SEV_WARNING,
52938 p_message_text => lv_message_text,
52939 p_error_text => lv_error_text,
52940 p_batch_id => lv_batch_id,
52941 p_where_str => lv_where_str,
52942 p_col_name => 'WIP_SUPPLY_TYPE',
52943 p_debug => v_debug,
52944 p_default_value => G_WIP_SUPPLY_TYPE );
52945
52946 IF lv_return <> 0 THEN
52947 RAISE ex_logging_err;
52948 END IF;
52949
52950 -- If routing_name is is NULL populate the assembly_item_name in routing name
52951
52952 v_sql_stmt := 11;
52953 lv_sql_stmt :=
52954 ' UPDATE msc_st_job_requirement_ops'
52955 ||' SET routing_name = assembly_item_name'
52956 ||' WHERE process_flag = '||G_IN_PROCESS
52957 ||' AND NVL(routing_name,'||''''||NULL_CHAR||''''||')'
52958 ||' = '||''''||NULL_CHAR||''''
52959 ||' AND process_flag = '||G_IN_PROCESS
52960 ||' AND batch_id = :lv_batch_id'
52961 ||' AND sr_instance_code = :v_instance_code';
52962
52963
52964 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
52965
52966 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
52967
52968 -- Derive routing_sequence_id
52969
52970 -- Set the error message
52971 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
52972 (p_app_short_name => 'MSC',
52973 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
52974 p_message_text => lv_message_text,
52975 p_error_text => lv_error_text,
52976 p_token1 => 'COLUMN_NAMES',
52977 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
52978 ||'ORGANIZATION_CODE,ROUTING_NAME',
52979 p_token2 => 'MASTER_TABLE',
52980 p_token_value2 => 'MSC_ST_ROUTINGS',
52981 p_token3 => 'CHILD_TABLE' ,
52982 p_token_value3 => 'MSC_ST_JOB_REQUIREMENT_OPS' );
52983
52984 IF lv_return <> 0 THEN
52985 RAISE ex_logging_err;
52986 END IF;
52987
52988 -- Derive the ROUTING_SEQUENCE_ID from LOCAL ID table
52989
52990 lv_return :=
52991 MSC_ST_UTIL.DERIVE_ROUTING_SEQUENCE_ID
52992 (p_table_name => 'MSC_ST_JOB_REQUIREMENT_OPS',
52993 p_rtg_col_name => 'ROUTING_NAME',
52994 p_rtg_col_id => 'ROUTING_SEQUENCE_ID',
52995 p_instance_code => v_instance_code,
52996 p_severity => G_SEV_ERROR,
52997 p_message_text => lv_message_text,
52998 p_batch_id => lv_batch_id,
52999 p_debug => v_debug,
53000 p_error_text => lv_error_text);
53001
53002 if (lv_return <> 0 )then
53003 RAISE ex_logging_err;
53004 end if;
53005
53006
53007 -- Derive operation seq num from local id table
53008
53009 v_sql_stmt := 12;
53010 lv_sql_stmt:=
53011 'UPDATE msc_st_job_requirement_ops msd'
53012 ||' SET operation_seq_num= (SELECT number1'
53013 ||' FROM msc_local_id_setup mlis'
53014 ||' WHERE mlis.char1 = msd.sr_instance_code'
53015 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
53016 ||' = NVL(msd.company_name,'||''''||NULL_CHAR||''''||') '
53017 ||' AND mlis.char3 = msd.organization_code'
53018 ||' AND mlis.char4 = msd.routing_name'
53019 ||' AND mlis.char5 = msd.operation_seq_code'
53020 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
53021 ||' = NVL(msd.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
53022 ||' AND mlis.date1 = msd.op_effectivity_date'
53023 ||' AND mlis.entity_name = ''OPERATION_SEQUENCE_ID'') '
53024 ||' WHERE sr_instance_code = :v_instance_code'
53025 ||' AND process_flag = '||G_IN_PROCESS
53026 ||' AND batch_id = :lv_batch_id';
53027
53028
53029
53030 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
53031
53032 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
53033
53034 -- Set the error message
53035
53036 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
53037 (p_app_short_name => 'MSC',
53038 p_error_code => 'MSC_PP_COL_VAL_NULL',
53039 p_message_text => lv_message_text,
53040 p_error_text => lv_error_text,
53041 p_token1 => 'COLUMN_NAME',
53042 p_token_value1 => 'OPERATION_SEQ_NUM');
53043
53044
53045 IF lv_return <> 0 THEN
53046 RAISE ex_logging_err;
53047 END IF;
53048
53049 -- Error out the records whose operation_seq_num is NULL
53050
53051 v_sql_stmt := 19;
53052 lv_sql_stmt :=
53053 'UPDATE msc_st_job_requirement_ops'
53054 ||' SET process_flag ='||G_ERROR_FLG||','
53055 ||' error_text = '||''''||lv_message_text||''''
53056 ||' WHERE NVL(operation_seq_num,'||NULL_VALUE||') ='||NULL_VALUE
53057 ||' AND sr_instance_code = :v_instance_code'
53058 ||' AND process_flag = '||G_IN_PROCESS
53059 ||' AND batch_id = :lv_batch_id';
53060
53061
53062 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
53063
53064 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
53065
53066 -- Derive the component_sequence_id
53067
53068 lv_sql_stmt :=
53069 'UPDATE msc_st_job_requirement_ops mjro'
53070 ||' SET component_sequence_id= (SELECT local_id '
53071 ||' FROM msc_local_id_setup mlis'
53072 ||' WHERE mlis.char1 = mjro.sr_instance_code'
53073 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
53074 ||' = NVL(mjro.company_name,'||''''||NULL_CHAR||''''||') '
53075 ||' AND mlis.char3 = mjro.organization_code'
53076 ||' AND mlis.char4 = mjro.assembly_item_name'
53077 ||' AND mlis.char5 = mjro.component_name'
53078 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
53079 ||' = NVL(mjro.alternate_bom_designator,'||''''||NULL_CHAR||''''||') '
53080 ||' AND mlis.char7 = mjro.operation_seq_code'
53081 ||' AND mlis.date1 = mjro.effectivity_date'
53082 ||' AND mlis.entity_name = ''COMPONENT_SEQUENCE_ID'')'
53083 ||' WHERE mjro.sr_instance_code = :v_instance_code'
53084 ||' AND mjro.process_flag ='|| G_IN_PROCESS
53085 ||' AND mjro.batch_id = :lv_batch_id';
53086
53087
53088 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
53089
53090 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
53091
53092 -- Set the error message
53093
53094 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
53095 (p_app_short_name => 'MSC',
53096 p_error_code => 'MSC_PP_COL_VAL_NULL',
53097 p_message_text => lv_message_text,
53098 p_error_text => lv_error_text,
53099 p_token1 => 'COLUMN_NAME',
53100 p_token_value1 => 'COMPONENT_SEQUENCE_ID');
53101
53102
53103 IF lv_return <> 0 THEN
53104 RAISE ex_logging_err;
53105 END IF;
53106
53107 -- Error out the records where component_sequence_id is NULL
53108
53109
53110 lv_sql_stmt :=
53111 'UPDATE msc_st_job_requirement_ops'
53112 ||' SET process_flag ='||G_ERROR_FLG||','
53113 ||' error_text = '||''''||lv_message_text||''''
53114 ||' WHERE NVL(component_sequence_id,'||NULL_VALUE||') ='||NULL_VALUE
53115 ||' AND sr_instance_code = :v_instance_code'
53116 ||' AND process_flag = '||G_IN_PROCESS
53117 ||' AND batch_id = :lv_batch_id';
53118
53119 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
53120
53121 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
53122
53123 -- Derive department id
53124
53125 lv_sql_stmt :=
53126 'UPDATE msc_st_job_requirement_ops mjro'
53127 ||' SET department_id= (SELECT local_id'
53128 ||' FROM msc_local_id_setup mlis'
53129 ||' WHERE mlis.char1 = mjro.sr_instance_code'
53130 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
53131 ||' = NVL(mjro.company_name,'||''''||NULL_CHAR||''''||') '
53132 ||' AND mlis.char3 = mjro.organization_code'
53133 ||' AND mlis.char4 = mjro.department_code'
53134 ||' AND mlis.entity_name = ''DEPARTMENT_ID'')'
53135 ||' WHERE sr_instance_code = :v_instance_code'
53136 ||' AND deleted_flag = '||SYS_NO
53137 ||' AND process_flag = '||G_IN_PROCESS
53138 ||' AND batch_id = :lv_batch_id';
53139
53140
53141 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
53142
53143 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
53144
53145
53146
53147 --Call to customised validation.
53148 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
53149 (ERRBUF => lv_error_text,
53150 RETCODE => lv_return,
53151 pBatchID => lv_batch_id,
53152 pInstanceCode => v_instance_code,
53153 pEntityName => 'MSC_ST_JOB_REQUIREMENT_OPS',
53154 pInstanceID => v_instance_id);
53155
53156 IF NVL(lv_return,0) <> 0 THEN
53157 RAISE ex_logging_err;
53158 END IF;
53159
53160 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
53161 (p_table_name => 'MSC_ST_JOB_REQUIREMENT_OPS',
53162 p_instance_id => v_instance_id,
53163 p_instance_code => v_instance_code,
53164 p_process_flag => G_VALID,
53165 p_error_text => lv_error_text,
53166 p_debug => v_debug,
53167 p_batch_id => lv_batch_id);
53168
53169 IF lv_return <> 0 THEN
53170 RAISE ex_logging_err;
53171 END IF;
53172
53173 lv_return := MSC_ST_UTIL.LOG_ERROR
53174 (p_table_name => 'MSC_ST_JOB_REQUIREMENT_OPS',
53175 p_instance_code => v_instance_code,
53176 p_row => lv_column_names,
53177 p_severity => G_SEV_ERROR,
53178 p_message_text => NULL,
53179 p_error_text => lv_error_text,
53180 p_debug => v_debug,
53181 p_batch_id => lv_batch_id);
53182
53183 IF lv_return <> 0 THEN
53184 RAISE ex_logging_err;
53185 END IF;
53186
53187 COMMIT;
53188 END LOOP ;
53189
53190
53191 -- Validation for MSC_ST_JOB_OP_RESOURCES
53192
53193 --Duplicate records check for the records whose source is XML
53194
53195 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
53196 (p_app_short_name => 'MSC',
53197 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
53198 p_message_text => lv_message_text,
53199 p_error_text => lv_error_text);
53200
53201 IF lv_return <> 0 THEN
53202 RAISE ex_logging_err;
53203 END IF;
53204
53205 v_sql_stmt := 01;
53206
53207 lv_sql_stmt:=
53208 'UPDATE msc_st_job_op_resources msrr1 '
53209 ||' SET process_flag ='||G_ERROR_FLG||','
53210 ||' error_text = '||''''||lv_message_text||''''
53211 ||' WHERE message_id < ( SELECT max(message_id) FROM msc_st_job_op_resources msrr2'
53212 ||' WHERE msrr2.sr_instance_code '
53213 ||' = msrr1.sr_instance_code'
53214 ||' AND NVL(msrr2.company_name,'||''''||NULL_CHAR||''''||') '
53215 ||' = NVL(msrr1.company_name,'||''''||NULL_CHAR||''''||') '
53216 ||' AND msrr2.wip_entity_name = msrr1.wip_entity_name'
53217 ||' AND msrr2.organization_code = msrr1.organization_code'
53218 ||' AND NVL(msrr2.operation_seq_code,'||''''||NULL_CHAR||''''||') '
53219 ||' = NVL(msrr1.operation_seq_code,'||''''||NULL_CHAR||''''||') '
53220 ||' AND NVL(msrr2.resource_seq_code,'||''''||NULL_CHAR||''''||') '
53221 ||' = NVL(msrr1.resource_seq_code,'||''''||NULL_CHAR||''''||') '
53222 ||' AND NVL(msrr2.resource_code, '||''''||NULL_CHAR||''''||') '
53223 ||' = NVL(msrr1.resource_code, '||''''||NULL_CHAR||''''||') '
53224 ||' AND NVL(msrr2.routing_name,'||''''||NULL_CHAR||''''||') '
53225 ||' = NVL(msrr1.routing_name,'||''''||NULL_CHAR||''''||') '
53226 ||' AND NVL(msrr2.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
53227 ||' = NVL(msrr1.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
53228 ||' AND msrr2.process_flag = '||G_IN_PROCESS
53229 ||' AND NVL(msrr2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||')'
53230 ||' AND msrr1.process_flag = '|| G_IN_PROCESS
53231 ||' AND msrr1.sr_instance_code = :v_instance_code '
53232 ||' AND NVL(msrr1.message_id,'||NULL_VALUE||')<> '||NULL_VALUE;
53233
53234
53235 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
53236
53237 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
53238
53239 --Duplicate records check for the records whose source is batch load
53240
53241 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
53242 (p_app_short_name => 'MSC',
53243 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
53244 p_message_text => lv_message_text,
53245 p_error_text => lv_error_text);
53246
53247 IF lv_return <> 0 THEN
53248 RAISE ex_logging_err;
53249 END IF;
53250 v_sql_stmt := 02;
53251
53252 lv_sql_stmt:=
53253 'UPDATE msc_st_job_op_resources msrr1'
53254 ||' SET process_flag = '||G_ERROR_FLG||','
53255 ||' error_text = '||''''||lv_message_text||''''
53256 ||' WHERE EXISTS ( SELECT 1 '
53257 ||' FROM msc_st_job_op_resources msrr2'
53258 ||' WHERE msrr2.sr_instance_code '
53259 ||' = msrr1.sr_instance_code'
53260 ||' AND NVL(msrr2.company_name,'||''''||NULL_CHAR||''''||') '
53261 ||' = NVL(msrr1.company_name,'||''''||NULL_CHAR||''''||') '
53262 ||' AND msrr2.wip_entity_name = msrr1.wip_entity_name'
53263 ||' AND msrr2.organization_code = msrr1.organization_code'
53264 ||' AND NVL(msrr2.operation_seq_code,'||''''||NULL_CHAR||''''||') '
53265 ||' = NVL(msrr1.operation_seq_code,'||''''||NULL_CHAR||''''||') '
53266 ||' AND NVL(msrr2.resource_seq_code,'||''''||NULL_CHAR||''''||') '
53267 ||' = NVL(msrr1.resource_seq_code,'||''''||NULL_CHAR||''''||') '
53268 ||' AND NVL(msrr2.resource_code, '||''''||NULL_CHAR||''''||') '
53269 ||' = NVL(msrr1.resource_code, '||''''||NULL_CHAR||''''||') '
53270 ||' AND NVL(msrr2.routing_name,'||''''||NULL_CHAR||''''||') '
53271 ||' = NVL(msrr1.routing_name,'||''''||NULL_CHAR||''''||') '
53272 ||' AND NVL(msrr2.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
53273 ||' = NVL(msrr1.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
53274 ||' AND msrr2.process_flag = '||G_IN_PROCESS
53275 ||' AND NVL(msrr2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
53276 ||' GROUP BY sr_instance_code,company_name,organization_code,wip_entity_name,'
53277 ||' operation_seq_code,resource_seq_code,resource_code '
53278 ||' HAVING COUNT(*) >1 )'
53279 ||' AND msrr1.process_flag = '||G_IN_PROCESS
53280 ||' AND msrr1.sr_instance_code = :v_instance_code'
53281 ||' AND NVL(msrr1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
53282
53283
53284 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
53285
53286 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
53287
53288 lv_column_names :=
53289 'DEPARTMENT_CODE ||''~''||'
53290 ||'RESOURCE_CODE ||''~''||'
53291 ||'ORGANIZATION_CODE ||''~''||'
53292 ||'RESOURCE_SEQ_CODE ||''~''||'
53293 ||'RECO_START_DATE ||''~''||'
53294 ||'ASSIGNED_UNITS ||''~''||'
53295 ||'WIP_ENTITY_NAME ||''~''||'
53296 ||'SR_INSTANCE_CODE ||''~''||'
53297 ||'ITEM_NAME ||''~''||'
53298 ||'OPERATION_SEQ_CODE ||''~''||'
53299 ||'BASIS_TYPE ||''~''||'
53300 ||'RECO_COMPLETION_DATE ||''~''||'
53301 ||'DELETED_FLAG ||''~''||'
53302 ||'COMPANY_NAME ' ;
53303
53304 -- Now processing by batch
53305 LOOP
53306 v_sql_stmt := 03;
53307 lv_cursor_stmt :=
53308 ' SELECT msc_st_batch_id_s.NEXTVAL '
53309 ||' FROM dual';
53310
53311 OPEN c1 FOR lv_cursor_stmt;
53312 FETCH c1 INTO lv_batch_id;
53313 CLOSE c1;
53314
53315 v_sql_stmt := 04;
53316 lv_sql_stmt :=
53317 ' UPDATE msc_st_job_op_resources '
53318 ||' SET batch_id = :lv_batch_id'
53319 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
53320 ||' AND sr_instance_code = :v_instance_code'
53321 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
53322 ||' AND rownum <= '||v_batch_size;
53323
53324
53325 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
53326
53327 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
53328
53329 EXIT WHEN SQL%NOTFOUND;
53330
53331 OPEN c5(lv_batch_id);
53332 FETCH c5 BULK COLLECT INTO lb_rowid;
53333 CLOSE c5;
53334
53335 v_sql_stmt := 05;
53336 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
53337 UPDATE msc_st_job_op_resources
53338 SET st_transaction_id = msc_st_job_op_resources_s.NEXTVAL,
53339 refresh_id = v_refresh_id,
53340 last_update_date = v_current_date,
53341 last_updated_by = v_current_user,
53342 creation_date = v_current_date,
53343 created_by = v_current_user
53344 WHERE rowid = lb_rowid(j);
53345
53346 -- Set the error message
53347 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
53348 (p_app_short_name => 'MSC',
53349 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
53350 p_message_text => lv_message_text,
53351 p_error_text => lv_error_text,
53352 p_token1 => 'COLUMN_NAME',
53353 p_token_value1 => 'DELETED_FLAG',
53354 p_token2 => 'DEFAULT_VALUE',
53355 p_token_value2 => SYS_NO );
53356
53357 IF lv_return <> 0 THEN
53358 RAISE ex_logging_err;
53359 END IF;
53360
53361 -- Check whether delete flag value is in (SYS_YES,SYS_NO),if not default to SYS_NO
53362
53363 lv_where_str :=
53364 ' AND NVL(deleted_flag,'||NULL_VALUE||') NOT IN(1,2)';
53365
53366 lv_return := MSC_ST_UTIL.LOG_ERROR
53367 (p_table_name => 'MSC_ST_JOB_OP_RESOURCES',
53368 p_instance_code => v_instance_code,
53369 p_row => lv_column_names,
53370 p_severity => G_SEV_WARNING,
53371 p_message_text => lv_message_text,
53372 p_error_text => lv_error_text,
53373 p_batch_id => lv_batch_id,
53374 p_where_str => lv_where_str,
53375 p_col_name => 'DELETED_FLAG',
53376 p_debug => v_debug,
53377 p_default_value => SYS_NO);
53378
53379
53380 IF lv_return <> 0 THEN
53381 RAISE ex_logging_err;
53382 END IF;
53383
53384 -- Set the message
53385 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
53386 (p_app_short_name => 'MSC',
53387 p_error_code => 'MSC_PP_INVALID_VALUE',
53388 p_message_text => lv_message_text,
53389 p_error_text => lv_error_text,
53390 p_token1 => 'COLUMN_NAME',
53391 p_token_value1 => 'ORGANIZATION_CODE');
53392
53393 IF lv_return <> 0 THEN
53394 RAISE ex_logging_err;
53395 END IF;
53396
53397 -- Populate organization id
53398 lv_return :=
53399 MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID(p_table_name => 'MSC_ST_JOB_OP_RESOURCES',
53400 p_org_partner_name =>'ORGANIZATION_CODE',
53401 p_org_partner_id =>'ORGANIZATION_ID',
53402 p_instance_code => v_instance_code,
53403 p_partner_type => G_ORGANIZATION,
53404 p_severity => G_SEV_ERROR,
53405 p_message_text => lv_message_text,
53406 p_batch_id => lv_batch_id,
53407 p_debug => v_debug,
53408 p_error_text => lv_error_text);
53409
53410 IF(lv_return <> 0) then
53411 RAISE ex_logging_err;
53412 END IF;
53413
53414 -- Derive WIP_ENTITY_ID
53415 v_sql_stmt := 06;
53416 lv_sql_stmt:=
53417 'UPDATE msc_st_job_op_resources msrr'
53418 ||' SET wip_entity_id = (SELECT local_id '
53419 ||' FROM msc_local_id_supply mlis'
53420 ||' WHERE mlis.char1 = msrr.sr_instance_code'
53421 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
53422 ||' = NVL(msrr.company_name,'||''''||NULL_CHAR||''''||') '
53423 ||' AND mlis.char3 = msrr.organization_code'
53424 ||' AND mlis.char4 = msrr.wip_entity_name'
53425 ||' AND mlis.entity_name = ''WIP_ENTITY_ID'' '
53426 ||' AND mlis.instance_id ='||v_instance_id||')'
53427 ||' WHERE sr_instance_code = :v_instance_code'
53428 ||' AND NVL(wip_entity_name,'||''''||NULL_CHAR||''''||') '
53429 ||' <> '||''''||NULL_CHAR||''''
53430 ||' AND process_flag ='||G_IN_PROCESS
53431 ||' AND batch_id = :lv_batch_id';
53432
53433
53434 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
53435
53436 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
53437
53438 -- Set the error message
53439
53440 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
53441 (p_app_short_name => 'MSC',
53442 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
53443 p_message_text => lv_message_text,
53444 p_error_text => lv_error_text,
53445 p_token1 => 'COLUMN_NAMES',
53446 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
53447 ||'ORGANIZATION_CODE,WIP_ENTITY_NAME',
53448 p_token2 => 'MASTER_TABLE',
53449 p_token_value2 => 'MSC_ST_SUPPLIES',
53450 p_token3 => 'CHILD_TABLE' ,
53451 p_token_value3 => 'MSC_ST_JOB_OP_RESOURCES' );
53452
53453 IF lv_return <> 0 THEN
53454 RAISE ex_logging_err;
53455 END IF;
53456
53457
53458 -- Error out the records if WIP_ENTITY_ID NULL
53459
53460 v_sql_stmt := 07;
53461 lv_sql_stmt:=
53462 'UPDATE msc_st_job_op_resources msrr'
53463 ||' SET process_flag ='||G_ERROR_FLG||','
53464 ||' error_text = '||''''||lv_message_text||''''
53465 ||' WHERE NVL(wip_entity_id,'||NULL_VALUE||') = '||NULL_VALUE
53466 ||' AND sr_instance_code = :v_instance_code'
53467 ||' AND process_flag ='||G_IN_PROCESS
53468 ||' AND batch_id = :lv_batch_id';
53469
53470
53471 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
53472
53473 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
53474
53475 -- Derive resource id
53476 v_sql_stmt := 10;
53477
53478 lv_sql_stmt :=
53479 'UPDATE msc_st_job_op_resources msrr'
53480 ||' SET resource_id= (SELECT local_id '
53481 ||' FROM msc_local_id_setup mlis'
53482 ||' WHERE mlis.char1 = msrr.sr_instance_code'
53483 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
53484 ||' = NVL(msrr.company_name,'||''''||NULL_CHAR||''''||') '
53485 ||' AND mlis.char3 = msrr.organization_code'
53486 ||' AND mlis.char4 = msrr.resource_code'
53487 ||' AND mlis.entity_name = ''RESOURCE_ID'''
53488 ||' AND mlis.instance_id ='||v_instance_id||' )'
53489 ||' WHERE msrr.sr_instance_code = :v_instance_code'
53490 ||' AND msrr.deleted_flag = '||SYS_NO
53491 ||' AND msrr.process_flag ='|| G_IN_PROCESS
53492 ||' AND msrr.batch_id = :lv_batch_id';
53493
53494
53495 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
53496
53497 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
53498
53499 -- Set the error message
53500
53501 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
53502 (p_app_short_name => 'MSC',
53503 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
53504 p_message_text => lv_message_text,
53505 p_error_text => lv_error_text,
53506 p_token1 => 'COLUMN_NAMES',
53507 p_token_value1 => 'SR_INSTANCE_CODE,COMPANY_NAME,'
53508 ||'ORGANIZATION_CODE,RESOURCE_CODE',
53509 p_token2 => 'MASTER_TABLE',
53510 p_token_value2 => 'MSC_ST_DEPARTMENT_RESOURCES',
53511 p_token3 => 'CHILD_TABLE' ,
53512 p_token_value3 => 'MSC_ST_JOB_OP_RESOURCES' );
53513
53514 IF lv_return <> 0 THEN
53515 RAISE ex_logging_err;
53516 END IF;
53517
53518
53519 -- Error out records where resource_id is NULL
53520
53521 v_sql_stmt := 11;
53522
53523 lv_sql_stmt:=
53524 'UPDATE msc_st_job_op_resources msrr'
53525 ||' SET process_flag ='||G_ERROR_FLG||','
53526 ||' error_text = '||''''||lv_message_text||''''
53527 ||' WHERE NVL(resource_id,'||NULL_VALUE||') = '||NULL_VALUE
53528 ||' AND sr_instance_code = :v_instance_code'
53529 ||' AND deleted_flag = '||SYS_NO
53530 ||' AND process_flag ='|| G_IN_PROCESS
53531 ||' AND batch_id = :lv_batch_id';
53532
53533
53534 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
53535
53536 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
53537
53538 -- Popluate the Department id from LOCAL_ID table
53539
53540 v_sql_stmt := 25;
53541 lv_sql_stmt :=
53542 'UPDATE msc_st_job_op_resources msrs'
53543 ||' SET department_id = (SELECT local_id'
53544 ||' FROM msc_local_id_setup mlis'
53545 ||' WHERE mlis.char1 = msrs.sr_instance_code'
53546 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
53547 ||' = NVL(msrs.company_name,'||''''||NULL_CHAR||''''||') '
53548 ||' AND mlis.char3 = msrs.organization_code'
53549 ||' AND mlis.char4 = msrs.department_code'
53550 ||' AND mlis.entity_name = ''DEPARTMENT_ID'' '
53551 ||' AND mlis.instance_id = '||v_instance_id||')'
53552 ||' WHERE sr_instance_code = :v_instance_code'
53553 ||' AND process_flag = '|| G_IN_PROCESS
53554 ||' AND batch_id = :lv_batch_id';
53555
53556
53557 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
53558
53559 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
53560
53561
53562
53563 -- Set the message
53564 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
53565 (p_app_short_name => 'MSC',
53566 p_error_code => 'MSC_PP_COL_VAL_NULL',
53567 p_message_text => lv_message_text,
53568 p_error_text => lv_error_text,
53569 p_token1 => 'COLUMN_NAME',
53570 p_token_value1 => 'ASSIGNED_UNITS');
53571
53572 IF lv_return <> 0 THEN
53573 RAISE ex_logging_err;
53574 END IF;
53575
53576 -- Error out records where assigned units is NULL
53577 v_sql_stmt := 08;
53578
53579 lv_sql_stmt:=
53580 'UPDATE msc_st_job_op_resources msrr'
53581 ||' SET process_flag ='||G_ERROR_FLG||','
53582 ||' error_text = '||''''||lv_message_text||''''
53583 ||' WHERE NVL(assigned_units,'||NULL_VALUE||') = '||NULL_VALUE
53584 ||' AND sr_instance_code = :v_instance_code'
53585 ||' AND deleted_flag ='|| SYS_NO
53586 ||' AND process_flag ='|| G_IN_PROCESS
53587 ||' AND batch_id = :lv_batch_id';
53588
53589
53590 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
53591
53592 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
53593
53594 -- Set the message
53595 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
53596 (p_app_short_name => 'MSC',
53597 p_error_code => 'MSC_PP_COL_VAL_NULL',
53598 p_message_text => lv_message_text,
53599 p_error_text => lv_error_text,
53600 p_token1 => 'COLUMN_NAME',
53601 p_token_value1 => 'USAGE_RATE_OR_AMOUNT');
53602
53603 IF lv_return <> 0 THEN
53604 RAISE ex_logging_err;
53605 END IF;
53606
53607 -- Error out records where usage_rate_or_amount is NULL
53608 v_sql_stmt := 08;
53609
53610 lv_sql_stmt:=
53611 'UPDATE msc_st_job_op_resources msrr'
53612 ||' SET process_flag ='||G_ERROR_FLG||','
53613 ||' error_text = '||''''||lv_message_text||''''
53614 ||' WHERE NVL(usage_rate_or_amount,'||NULL_VALUE||') = '||NULL_VALUE
53615 ||' AND sr_instance_code = :v_instance_code'
53616 ||' AND deleted_flag ='|| SYS_NO
53617 ||' AND process_flag ='|| G_IN_PROCESS
53618 ||' AND batch_id = :lv_batch_id';
53619
53620
53621 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
53622
53623 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
53624
53625 -- Set the message
53626 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
53627 (p_app_short_name => 'MSC',
53628 p_error_code => 'MSC_PP_COL_VAL_NULL',
53629 p_message_text => lv_message_text,
53630 p_error_text => lv_error_text,
53631 p_token1 => 'COLUMN_NAME',
53632 p_token_value1 => 'RESOURCE_SEQ_CODE');
53633
53634 IF lv_return <> 0 THEN
53635 RAISE ex_logging_err;
53636 END IF;
53637
53638 -- Error out records where resource sequence code is NULL
53639
53640 lv_sql_stmt:=
53641 'UPDATE msc_st_job_op_resources msrr'
53642 ||' SET process_flag ='||G_ERROR_FLG||','
53643 ||' error_text = '||''''||lv_message_text||''''
53644 ||' WHERE NVL(resource_seq_code,'||''''||NULL_CHAR||''''||') '
53645 ||' = '||''''||NULL_CHAR||''''
53646 ||' AND sr_instance_code = :v_instance_code'
53647 ||' AND deleted_flag ='|| SYS_NO
53648 ||' AND process_flag ='|| G_IN_PROCESS
53649 ||' AND batch_id = :lv_batch_id';
53650
53651
53652 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
53653
53654 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
53655
53656 -- Set the error message
53657 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
53658 (p_app_short_name => 'MSC',
53659 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
53660 p_message_text => lv_message_text,
53661 p_error_text => lv_error_text,
53662 p_token1 => 'COLUMN_NAME',
53663 p_token_value1 => 'RECOMMENDED');
53664
53665 IF lv_return <> 0 THEN
53666 RAISE ex_logging_err;
53667 END IF;
53668
53669 -- Error out the records where RECOMMENDED is not 'Y' or 'N'
53670
53671 v_sql_stmt := 7;
53672 lv_sql_stmt :=
53673 'UPDATE msc_st_job_op_resources'
53674 ||' SET process_flag ='||G_ERROR_FLG||','
53675 ||' error_text = '||''''||lv_message_text||''''
53676 ||' WHERE recommended NOT IN (''Y'', ''N'')'
53677 ||' AND sr_instance_code = :v_instance_code'
53678 ||' AND process_flag = '||G_IN_PROCESS
53679 ||' AND batch_id = :lv_batch_id';
53680
53681
53682 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
53683
53684 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
53685
53686 -- If routing_name is is NULL populate the item_name in routing name
53687
53688 v_sql_stmt := 13;
53689 lv_sql_stmt :=
53690 ' UPDATE msc_st_job_op_resources'
53691 ||' SET routing_name = item_name'
53692 ||' WHERE process_flag = '||G_IN_PROCESS
53693 ||' AND NVL(routing_name,'||''''||NULL_CHAR||''''||')'
53694 ||' = '||''''||NULL_CHAR||''''
53695 ||' AND batch_id = :lv_batch_id'
53696 ||' AND sr_instance_code = :v_instance_code';
53697
53698
53699 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
53700
53701 EXECUTE IMMEDIATE lv_sql_stmt USING lv_batch_id,v_instance_code;
53702
53703 -- Set the message
53704 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
53705 (p_app_short_name => 'MSC',
53706 p_error_code => 'MSC_PP_INVALID_VALUE',
53707 p_message_text => lv_message_text,
53708 p_error_text => lv_error_text,
53709 p_token1 => 'COLUMN_NAME',
53710 p_token_value1 => 'ROUTING_NAME');
53711
53712 IF lv_return <> 0 THEN
53713 RAISE ex_logging_err;
53714 END IF;
53715
53716 -- Derive the ROUTING_SEQUENCE_ID from LOCAL ID table
53717 lv_return :=
53718 MSC_ST_UTIL.DERIVE_ROUTING_SEQUENCE_ID
53719 (p_table_name => 'MSC_ST_JOB_OP_RESOURCES',
53720 p_rtg_col_name => 'ROUTING_NAME',
53721 p_rtg_col_id =>'ROUTING_SEQUENCE_ID',
53722 p_instance_code => v_instance_code,
53723 p_severity => G_SEV_ERROR,
53724 p_message_text => lv_message_text,
53725 p_batch_id => lv_batch_id,
53726 p_debug => v_debug,
53727 p_error_text => lv_error_text);
53728
53729 if (lv_return <> 0 )then
53730 RAISE ex_logging_err;
53731 end if;
53732
53733
53734 -- Set the error message
53735 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
53736 (p_app_short_name => 'MSC',
53737 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
53738 p_message_text => lv_message_text,
53739 p_error_text => lv_error_text,
53740 p_token1 => 'COLUMN_NAME',
53741 p_token_value1 => 'OPERATION_EFFECTIVITY_DATE',
53742 p_token2 => 'DEFAULT_VALUE',
53743 p_token_value2 => 'SYSDATE' );
53744
53745 IF lv_return <> 0 THEN
53746 RAISE ex_logging_err;
53747 END IF;
53748
53749 -- Default operation_effectivity date as SYSDATE if NULL
53750
53751 lv_where_str :=
53752 ' AND NVL(operation_effectivity_date,(sysdate-36500)) =(sysdate-36500)';
53753
53754 lv_return := MSC_ST_UTIL.LOG_ERROR
53755 (p_table_name => 'MSC_ST_JOB_OP_RESOURCES',
53756 p_instance_code => v_instance_code,
53757 p_row => lv_column_names,
53758 p_severity => G_SEV_WARNING,
53759 p_message_text => lv_message_text,
53760 p_error_text => lv_error_text,
53761 p_batch_id => lv_batch_id,
53762 p_where_str => lv_where_str,
53763 p_col_name => 'OPERATION_EFFECTIVITY_DATE',
53764 p_debug => v_debug,
53765 p_default_value => 'SYSDATE');
53766
53767 IF lv_return <> 0 THEN
53768 RAISE ex_logging_err;
53769 END IF;
53770
53771 -- Derive operation seq num
53772
53773 v_sql_stmt := 14;
53774 lv_sql_stmt:=
53775 'UPDATE msc_st_job_op_resources msrr'
53776 ||' SET operation_seq_num = (SELECT number1'
53777 ||' FROM msc_local_id_setup mlis'
53778 ||' WHERE mlis.char1 = msrr.sr_instance_code'
53779 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
53780 ||' = NVL(msrr.company_name,'||''''||NULL_CHAR||''''||') '
53781 ||' AND mlis.char3 = msrr.organization_code'
53782 ||' AND mlis.char4 = msrr.routing_name'
53783 ||' AND mlis.char5 = msrr.operation_seq_code'
53784 ||' AND NVL(mlis.char6,'||''''||NULL_CHAR||''''||') '
53785 ||' = NVL(msrr.alternate_routing_designator,'||''''||NULL_CHAR||''''||') '
53786 ||' AND mlis.date1 = msrr.operation_effectivity_date'
53787 ||' AND mlis.entity_name = ''OPERATION_SEQUENCE_ID'' '
53788 ||' AND mlis.instance_id = '||v_instance_id ||')'
53789 ||' WHERE sr_instance_code = :v_instance_code'
53790 ||' AND process_flag = '||G_IN_PROCESS
53791 ||' AND batch_id = :lv_batch_id';
53792
53793
53794
53795 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
53796
53797 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
53798
53799 -- Set the error message
53800
53801 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
53802 (p_app_short_name => 'MSC',
53803 p_error_code => 'MSC_PP_COL_VAL_NULL',
53804 p_message_text => lv_message_text,
53805 p_error_text => lv_error_text,
53806 p_token1 => 'COLUMN_NAME',
53807 p_token_value1 => 'OPERATION_SEQ_NUM');
53808
53809
53810 IF lv_return <> 0 THEN
53811 RAISE ex_logging_err;
53812 END IF;
53813
53814 -- Error out the records whose operation_seq_num is NULL
53815
53816 v_sql_stmt := 19;
53817 lv_sql_stmt :=
53818 'UPDATE msc_st_job_op_resources'
53819 ||' SET process_flag ='||G_ERROR_FLG||','
53820 ||' error_text = '||''''||lv_message_text||''''
53821 ||' WHERE NVL(operation_seq_num,'||NULL_VALUE||') ='||NULL_VALUE
53822 ||' AND sr_instance_code = :v_instance_code'
53823 ||' AND process_flag = '||G_IN_PROCESS
53824 ||' AND batch_id = :lv_batch_id';
53825
53826
53827 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
53828
53829 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
53830
53831 -- Set the error message
53832 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
53833 (p_app_short_name => 'MSC',
53834 p_error_code => 'MSC_PP_COL_VAL_NULL_DEFAULT',
53835 p_message_text => lv_message_text,
53836 p_error_text => lv_error_text,
53837 p_token1 => 'COLUMN_NAME',
53838 p_token_value1 => 'ALTERNATE_NUM',
53839 p_token2 => 'DEFAULT_VALUE',
53840 p_token_value2 => G_ALTERNATE_NUMBER );
53841
53842 IF lv_return <> 0 THEN
53843 RAISE ex_logging_err;
53844 END IF;
53845
53846 -- Default alternate number as 0 if NULL
53847
53848 lv_where_str := ' AND NVL(ALTERNATE_NUM,'||NULL_VALUE||') ='||NULL_VALUE ;
53849
53850 lv_return := MSC_ST_UTIL.LOG_ERROR
53851 (p_table_name => 'MSC_ST_JOB_OP_RESOURCES',
53852 p_instance_code => v_instance_code,
53853 p_row => lv_column_names,
53854 p_severity => G_SEV_WARNING,
53855 p_message_text => lv_message_text,
53856 p_error_text => lv_error_text,
53857 p_batch_id => lv_batch_id,
53858 p_where_str => lv_where_str,
53859 p_col_name => 'ALTERNATE_NUM',
53860 p_debug => v_debug,
53861 p_default_value => G_ALTERNATE_NUMBER);
53862
53863 IF lv_return <> 0 THEN
53864 RAISE ex_logging_err;
53865 END IF;
53866
53867 -- Derive resource seq num from the local id table
53868
53869 lv_sql_stmt :=
53870 'UPDATE msc_st_job_op_resources msor'
53871 ||' SET resource_seq_num = (SELECT local_id '
53872 ||' FROM msc_local_id_setup mlis'
53873 ||' WHERE mlis.char1 = msor.sr_instance_code'
53874 ||' AND NVL(mlis.char2,'||''''||NULL_CHAR||''''||') '
53875 ||' = NVL(msor.company_name,'||''''||NULL_CHAR||''''||') '
53876 ||' AND mlis.char3 = msor.organization_code'
53877 ||' AND mlis.char4 = msor.routing_name'
53878 ||' AND mlis.char5 = msor.operation_seq_code'
53879 ||' AND mlis.char6 = msor.resource_seq_code'
53880 ||' AND NVL(mlis.char7,'||''''||NULL_CHAR||''''||') '
53881 ||' = NVL(msor.alternate_routing_designator,'||''''||NULL_CHAR||''''||')'
53882 ||' AND mlis.number1 = msor.ALTERNATE_NUM'
53883 ||' AND mlis.entity_name = ''RESOURCE_SEQ_NUM'')'
53884 ||' WHERE sr_instance_code = :v_instance_code'
53885 ||' AND process_flag = '||G_IN_PROCESS
53886 ||' AND batch_id = :lv_batch_id';
53887
53888
53889
53890 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
53891
53892 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code,lv_batch_id;
53893
53894 -- Set the error message
53895 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
53896 (p_app_short_name => 'MSC',
53897 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
53898 p_message_text => lv_message_text,
53899 p_error_text => lv_error_text,
53900 p_token1 => 'COLUMN_NAME',
53901 p_token_value1 => 'PRINCIPAL_FLAG',
53902 p_token2 => 'DEFAULT_VALUE',
53903 p_token_value2 => G_PRINCIPAL_FLAG );
53904
53905 IF lv_return <> 0 THEN
53906 RAISE ex_logging_err;
53907 END IF;
53908
53909 -- Default principal_flag as 1 if NOT IN (1,2)
53910
53911 lv_where_str := ' AND NVL(principal_flag,'||NULL_VALUE||')'||' NOT IN (1,2)'
53912 ||'AND deleted_flag = 2';
53913
53914 lv_return := MSC_ST_UTIL.LOG_ERROR
53915 (p_table_name => 'MSC_ST_JOB_OP_RESOURCES',
53916 p_instance_code => v_instance_code,
53917 p_row => lv_column_names,
53918 p_severity => G_SEV_WARNING,
53919 p_message_text => lv_message_text,
53920 p_error_text => lv_error_text,
53921 p_batch_id => lv_batch_id,
53922 p_where_str => lv_where_str,
53923 p_col_name => 'PRINCIPAL_FLAG',
53924 p_debug => v_debug,
53925 p_default_value => G_PRINCIPAL_FLAG);
53926
53927 IF lv_return <> 0 THEN
53928 RAISE ex_logging_err;
53929 END IF;
53930
53931 -- Set the error message
53932 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
53933 (p_app_short_name => 'MSC',
53934 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
53935 p_message_text => lv_message_text,
53936 p_error_text => lv_error_text,
53937 p_token1 => 'COLUMN_NAME',
53938 p_token_value1 => 'BASIS_TYPE',
53939 p_token2 => 'DEFAULT_VALUE',
53940 p_token_value2 => G_BASIS_TYPE );
53941
53942 IF lv_return <> 0 THEN
53943 RAISE ex_logging_err;
53944 END IF;
53945
53946 -- Default basis type as 1 if INVALID
53947
53948 lv_where_str :=
53949 ' AND NVL(basis_type,'||NULL_VALUE||')'
53950 ||' NOT IN (1,2,3,4,5) AND deleted_flag = 2' ;
53951
53952 lv_return := MSC_ST_UTIL.LOG_ERROR
53953 (p_table_name => 'MSC_ST_JOB_OP_RESOURCES',
53954 p_instance_code => v_instance_code,
53955 p_row => lv_column_names,
53956 p_severity => G_SEV_WARNING,
53957 p_message_text => lv_message_text,
53958 p_error_text => lv_error_text,
53959 p_batch_id => lv_batch_id,
53960 p_where_str => lv_where_str,
53961 p_col_name => 'BASIS_TYPE',
53962 p_debug => v_debug,
53963 p_default_value => G_BASIS_TYPE);
53964 IF lv_return <> 0 THEN
53965 RAISE ex_logging_err;
53966 END IF;
53967
53968 OPEN c6(lv_batch_id);
53969 FETCH c6 BULK COLLECT INTO lb_rowid ;
53970
53971 IF c6%ROWCOUNT > 0 THEN
53972
53973 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
53974
53975 UPDATE msc_st_job_op_resources
53976 SET resource_seq_num =
53977 to_number(decode(length(rtrim(resource_seq_code,'0123456789')),
53978 NULL,resource_seq_code,'1'))
53979 WHERE rowid = lb_rowid(j);
53980 END IF;
53981 CLOSE c6;
53982
53983
53984 --Call to customised validation.
53985
53986 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
53987 (ERRBUF => lv_error_text,
53988 RETCODE => lv_return,
53989 pBatchID => lv_batch_id,
53990 pInstanceCode => v_instance_code,
53991 pEntityName => 'MSC_ST_JOB_OP_RESOURCES',
53992 pInstanceID => v_instance_id);
53993
53994 IF NVL(lv_return,0) <> 0 THEN
53995 RAISE ex_logging_err;
53996 END IF;
53997
53998 -- Set the process flag as Valid and populate sr_instance_id
53999 lv_return :=
54000 MSC_ST_UTIL.SET_PROCESS_FLAG(p_table_name => 'MSC_ST_JOB_OP_RESOURCES',
54001 p_instance_id => v_instance_id,
54002 p_instance_code => v_instance_code,
54003 p_process_flag => G_VALID,
54004 p_error_text => lv_error_text,
54005 p_debug => v_debug,
54006 p_batch_id => lv_batch_id);
54007
54008 IF lv_return <> 0 THEN
54009 RAISE ex_logging_err;
54010 END IF;
54011
54012
54013 -- At the end calling the LOG_ERROR for logging all errored out records
54014
54015 lv_return :=
54016 MSC_ST_UTIL.LOG_ERROR(p_table_name => 'MSC_ST_JOB_OP_RESOURCES',
54017 p_instance_code => v_instance_code,
54018 p_row => lv_column_names,
54019 p_severity => G_SEV_ERROR,
54020 p_message_text => NULL,
54021 p_error_text => lv_error_text,
54022 p_debug => v_debug,
54023 p_batch_id => lv_batch_id );
54024
54025 IF lv_return <> 0 THEN
54026 RAISE ex_logging_err;
54027 END IF;
54028
54029 COMMIT;
54030 END LOOP;
54031
54032 EXCEPTION
54033
54034 WHEN too_many_rows THEN
54035 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_JOB_DETAILS'||'('
54036 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
54037 ROLLBACK ;
54038
54039 WHEN ex_logging_err THEN
54040 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
54041 ROLLBACK;
54042
54043 WHEN OTHERS THEN
54044 lv_error_text :=substr('MSC_CL_PRE_PROCESS.LOAD_JOB_DETAILS'||'('
54045 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
54046 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
54047 ROLLBACK;
54048
54049 END LOAD_JOB_DETAILS;
54050
54051
54052 /*==========================================================================+
54053 | DESCRIPTION : This procedure generates records in msc_st_bis_periods if |
54054 | records are coming into msc_st_trading_partners and/or |
54055 | records are coming in msc_st_calendars. |
54056 +==========================================================================*/
54057 PROCEDURE LOAD_BIS_PERIODS IS
54058 lv_error_text VARCHAR2(250);
54059
54060 BEGIN
54061
54062 IF is_bis_periods_load_reqd = SYS_YES THEN
54063
54064
54065 DELETE FROM msc_st_bis_periods where sr_instance_id = v_instance_id;
54066 INSERT INTO msc_st_bis_periods
54067 (organization_id,
54068 period_set_name,
54069 period_name,
54070 start_date,
54071 end_date,
54072 period_type,
54073 period_year,
54074 period_num,
54075 quarter_num,
54076 entered_period_name,
54077 adjustment_period_flag,
54078 description,
54079 context,
54080 year_start_date,
54081 quarter_start_date,
54082 refresh_id,
54083 sr_instance_id,
54084 last_update_date,
54085 last_updated_by,
54086 creation_date,
54087 created_by)
54088 (SELECT
54089 sr_tp_id,
54090 'LEGACY',
54091 TO_CHAR(period_start_date,'DD-MON-YYYY'),
54092 period_start_date,
54093 next_date-1,
54094 'Month',
54095 TO_NUMBER(TO_CHAR(period_start_date,'YYYY')),
54096 msc_st_shift_num_s.nextval,
54097 --decode(period_sequence_num,1,1,2,1,3,1,4,2,5,2,6,2,7,3,8,3,9,3,4),
54098 decode(to_char(period_start_date,'MM'),1,1,2,1,3,1,4,2,5,2,6,2,7,3,8,3,9,3,4), -- bug 8613033
54099 period_name,
54100 'N',
54101 'LEGACY',
54102 NULL,
54103 NULL,
54104 NULL,
54105 v_refresh_id,
54106 v_instance_id,
54107 v_current_date,
54108 v_current_user,
54109 v_current_date,
54110 v_current_user
54111 FROM msc_period_start_dates mpsd,msc_trading_partners mtp
54112 WHERE mpsd.calendar_code = mtp.calendar_code
54113 AND mpsd.sr_instance_id = mtp.sr_instance_id
54114 AND mtp.partner_type = G_ORGANIZATION
54115 AND mtp.sr_instance_id = v_instance_id
54116 AND mpsd.period_start_date <> mpsd.next_date); -- bug 8591107
54117
54118
54119 -- insert for those orgs which are coming in now
54120 -- and do not exist in the ODS
54121 INSERT INTO msc_st_bis_periods
54122 (organization_id,
54123 period_set_name,
54124 period_name,
54125 start_date,
54126 end_date,
54127 period_type,
54128 period_year,
54129 period_num,
54130 quarter_num,
54131 entered_period_name,
54132 adjustment_period_flag,
54133 description,
54134 context,
54135 year_start_date,
54136 quarter_start_date,
54137 refresh_id,
54138 sr_instance_id,
54139 last_update_date,
54140 last_updated_by,
54141 creation_date,
54142 created_by)
54143 (SELECT
54144 sr_tp_id,
54145 'LEGACY',
54146 TO_CHAR(period_start_date,'DD-MON-YYYY'),
54147 period_start_date,
54148 next_date-1,
54149 'Month',
54150 TO_NUMBER(TO_CHAR(period_start_date,'YYYY')),
54151 msc_st_shift_num_s.nextval,
54152 --decode(period_sequence_num,1,1,2,1,3,1,4,2,5,2,6,2,7,3,8,3,9,3,4),
54153 decode(to_char(period_start_date,'MM'),1,1,2,1,3,1,4,2,5,2,6,2,7,3,8,3,9,3,4), -- bug 8613033
54154 period_name,
54155 'N',
54156 'LEGACY',
54157 NULL,
54158 NULL,
54159 NULL,
54160 v_refresh_id,
54161 v_instance_id,
54162 v_current_date,
54163 v_current_user,
54164 v_current_date,
54165 v_current_user
54166 FROM msc_period_start_dates mpsd,msc_st_trading_partners mtp
54167 WHERE mpsd.calendar_code = mtp.calendar_code
54168 AND mpsd.sr_instance_id = mtp.sr_instance_id
54169 AND mpsd.period_start_date <> mpsd.next_date -- bug 8591107
54170 AND mtp.partner_type = G_ORGANIZATION
54171 AND mtp.process_flag = G_VALID
54172 AND mtp.sr_instance_id = v_instance_id
54173 AND NOT EXISTS(SELECT 1
54174 FROM msc_trading_partners mtpo
54175 WHERE mtpo.sr_instance_id = mtp.sr_instance_id
54176 AND mtpo.partner_type = mtp.partner_type
54177 AND mtpo.sr_tp_id = mtp.sr_tp_id)
54178 );
54179 END IF;
54180 COMMIT;
54181 --changes for bug 8613033
54182 update msc_st_bis_periods msbp
54183 set msbp.year_start_date=
54184 (
54185 select mcm.year_start_date from msc_calendar_months mcm
54186 where mcm.sr_instance_id = v_instance_id
54187 and mcm.calendar_type = 'FISCAL'
54188 and msbp.sr_instance_id = mcm.sr_instance_id
54189 and to_char(msbp.start_date,'MON-RR') = to_char(mcm.month_start_date,'MON-RR')
54190 ),
54191 msbp.quarter_start_date =
54192 (
54193 select mcm.quarter_start_date from msc_calendar_months mcm
54194 where mcm.sr_instance_id = v_instance_id
54195 and mcm.calendar_type = 'FISCAL'
54196 and msbp.sr_instance_id = mcm.sr_instance_id
54197 and to_char(msbp.start_date,'MON-RR') = to_char(mcm.month_start_date,'MON-RR')
54198 )
54199 where msbp.sr_instance_id = v_instance_id;
54200
54201 commit;
54202 MSC_UTIL.LOG_MSG(MSC_UTIL.G_D_DEBUG_1, 'msc_st_bis_periods : Rows updated - '||SQL%ROWCOUNT);
54203 --end of changes for bug 8613033
54204 EXCEPTION
54205 WHEN OTHERS THEN
54206 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_BIS_PERIODS'||'('
54207 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
54208 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
54209 ROLLBACK;
54210
54211 END LOAD_BIS_PERIODS;
54212
54213 ----- ============== CHECK_DUPLICATES ==================
54214
54215 Procedure CHECK_DUPLICATES ( ERRBUF OUT NOCOPY VARCHAR2, RETCODE OUT NOCOPY VARCHAR2)
54216 IS
54217 lv_return NUMBER;
54218 lv_error_text VARCHAR2(250);
54219 lv_sql_stmt VARCHAR2(5000);
54220 lv_message_text msc_errors.error_text%TYPE;
54221 ex_logging_err EXCEPTION;
54222 BEGIN
54223 -- items
54224 -- Validation for table msc_st_system_items
54225 -- Duplicate records check for the records whose source is XML
54226
54227 IF v_item_enabled = SYS_YES THEN
54228 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
54229 (p_app_short_name => 'MSC',
54230 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
54231 p_message_text => lv_message_text,
54232 p_error_text => lv_error_text);
54233
54234 IF lv_return <> 0 THEN
54235 RAISE ex_logging_err;
54236 END IF;
54237
54238 v_sql_stmt := 01;
54239 lv_sql_stmt :=
54240 'UPDATE msc_st_system_items mssi1'
54241 ||' SET process_flag = '||G_ERROR_FLG||','
54242 ||' error_text = '||''''||lv_message_text||''''
54243 ||' WHERE message_id < (SELECT MAX(message_id)'
54244 ||' FROM msc_st_system_items mssi2'
54245 ||' WHERE mssi2.sr_instance_code = mssi1.sr_instance_code'
54246 ||' AND mssi2.organization_code = mssi1.organization_code'
54247 ||' AND mssi2.item_name = mssi1.item_name'
54248 ||' AND NVL(mssi1.company_name, '||''''||NULL_CHAR||''''||') '
54249 ||' = NVL(mssi2.company_name,'||''''||NULL_CHAR||''''||') '
54250 ||' AND mssi2.process_flag ='|| G_IN_PROCESS
54251 ||' AND NVL(mssi2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||') '
54252 ||' AND mssi1.process_flag ='|| G_IN_PROCESS
54253 ||' AND mssi1.sr_instance_code = : v_instance_code'
54254 ||' AND NVL(mssi1.message_id,'||NULL_VALUE||')<> '||NULL_VALUE;
54255
54256
54257 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
54258
54259 EXECUTE IMMEDIATE lv_sql_stmt
54260 USING v_instance_code;
54261
54262 --Duplicate records check for the records whose source is batch load
54263 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
54264 (p_app_short_name => 'MSC',
54265 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
54266 p_message_text => lv_message_text,
54267 p_error_text => lv_error_text);
54268
54269 IF lv_return <> 0 THEN
54270 RAISE ex_logging_err;
54271 END IF;
54272
54273 v_sql_stmt := 02;
54274 lv_sql_stmt :=
54275 'UPDATE msc_st_system_items mssi1'
54276 ||' SET process_flag = '||G_ERROR_FLG||','
54277 ||' error_text = '||''''||lv_message_text||''''
54278 ||' WHERE EXISTS( SELECT 1 '
54279 ||' FROM msc_st_system_items mssi2'
54280 ||' WHERE mssi2.sr_instance_code = mssi1.sr_instance_code'
54281 ||' AND mssi2.organization_code = mssi1.organization_code'
54282 ||' AND NVL(mssi1.company_name,'||''''||NULL_CHAR||''''||') '
54283 ||' = NVL(mssi2.company_name,'||''''||NULL_CHAR||''''||') '
54284 ||' AND mssi2.item_name = mssi1.item_name'
54285 ||' AND mssi2.process_flag = '||G_IN_PROCESS
54286 ||' AND NVL(mssi2.message_id,'||NULL_VALUE||')= '||NULL_VALUE
54287 ||' GROUP BY sr_instance_code,organization_code,item_name,company_name'
54288 ||' HAVING COUNT(*) >1 )'
54289 ||' AND mssi1.process_flag ='|| G_IN_PROCESS
54290 ||' AND mssi1.sr_instance_code = :v_instance_code'
54291 ||' AND NVL(mssi1.message_id,'||NULL_VALUE||')= '||NULL_VALUE;
54292
54293
54294 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
54295
54296 EXECUTE IMMEDIATE lv_sql_stmt
54297 USING v_instance_code;
54298 END IF;
54299
54300 commit; -- for items
54301
54302 IF v_mat_sup_enabled = SYS_YES THEN
54303 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
54304 (p_app_short_name => 'MSC',
54305 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
54306 p_message_text => lv_message_text,
54307 p_error_text => lv_error_text);
54308
54309 IF lv_return <> 0 THEN
54310 RAISE ex_logging_err;
54311 END IF;
54312
54313 --Duplicate records check for the records whose source is XML for
54314 --PO, Purchase Req and Intransit supplies
54315 v_sql_stmt := 03;
54316 lv_sql_stmt :=
54317 'UPDATE msc_st_supplies mss1 '
54318 ||' SET process_flag = '||G_ERROR_FLG||','
54319 ||' error_text = '||''''||lv_message_text||''''
54320 ||' WHERE message_id < (SELECT MAX(message_id)'
54321 ||' FROM msc_st_supplies mss2'
54322 ||' WHERE mss2.sr_instance_code'
54323 ||' = mss1.sr_instance_code'
54324 ||' AND mss2.order_number = mss1.order_number'
54325 ||' AND mss2.purch_line_num = mss1.purch_line_num'
54326 ||' AND mss2.order_type = mss1.order_type'
54327 ||' AND mss2.process_flag = '||G_IN_PROCESS
54328 ||' AND NVL(mss2.company_name, '||''''||NULL_CHAR||''''||') = '
54329 ||' NVL(mss1.company_name, '||''''||NULL_CHAR||''''||')'
54330 ||' AND mss2.sr_instance_code = mss1.sr_instance_code'
54331 ||' AND NVL(mss2.message_id,'||NULL_VALUE||') <>'||NULL_VALUE||')'
54332 ||' AND mss1.order_type IN(1,8,2,11,12)'
54333 ||' AND mss1.process_flag = '||G_IN_PROCESS
54334 ||' AND mss1.sr_instance_code = :v_instance_code'
54335 ||' AND NVL(mss1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
54336
54337
54338 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
54339
54340 EXECUTE IMMEDIATE lv_sql_stmt
54341 USING v_instance_code;
54342
54343 --Duplicate records check for the records whose source is XML for
54344 --Plan Orders
54345 v_sql_stmt := 04;
54346 lv_sql_stmt :=
54347 'UPDATE msc_st_supplies mss1'
54348 ||' SET process_flag = '||G_ERROR_FLG||','
54349 ||' error_text = '||''''||lv_message_text||''''
54350 ||' WHERE message_id < (SELECT MAX(message_id)'
54351 ||' FROM msc_st_supplies mss2'
54352 ||' WHERE mss2.sr_instance_code '
54353 ||' = mss1.sr_instance_code'
54354 ||' AND NVL(mss2.company_name,'||''''||NULL_CHAR||''''||') = '
54355 ||' NVL(mss1.company_name,'||''''||NULL_CHAR||''''||')'
54356 ||' AND mss2.organization_code = mss1.organization_code '
54357 ||' AND mss2.schedule_designator = mss1.schedule_designator'
54358 ||' AND mss2.schedule_line_num = mss1.schedule_line_num '
54359 ||' AND mss2.order_type = mss1.order_type '
54360 ||' AND mss2.process_flag = '||G_IN_PROCESS
54361 ||' AND mss2.sr_instance_code = mss1.sr_instance_code'
54362 ||' AND NVL(mss2.message_id,'||NULL_VALUE||')<>'||NULL_VALUE||')'
54363 ||' AND mss1.order_type = 5'
54364 ||' AND mss1.process_flag = '||G_IN_PROCESS
54365 ||' AND mss1.sr_instance_code = :v_instance_code'
54366 ||' AND NVL(mss1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
54367
54368
54369 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
54370
54371 EXECUTE IMMEDIATE lv_sql_stmt
54372 USING v_instance_code;
54373
54374 --Duplicate records check for the records whose source is XML for
54375 --on hand supplies
54376 v_sql_stmt := 05;
54377 lv_sql_stmt :=
54378 'UPDATE msc_st_supplies mss1 '
54379 ||' SET process_flag = '||G_ERROR_FLG||','
54380 ||' error_text = '||''''||lv_message_text||''''
54381 ||' WHERE message_id < (SELECT MAX(message_id)'
54382 ||' FROM msc_st_supplies mss2'
54383 ||' WHERE mss2.sr_instance_code = mss1.sr_instance_code'
54384 ||' AND NVL(mss2.company_name,'||''''||NULL_CHAR||''''||') = '
54385 ||' NVL(mss1.company_name,'||''''||NULL_CHAR||''''||')'
54386 ||' AND mss2.organization_code = mss1.organization_code '
54387 ||' AND mss2.item_name = mss1.item_name '
54388 ||' AND NVL(mss2.subinventory_code,'||''''||NULL_CHAR||''''||') = '
54389 ||' NVL(mss1.subinventory_code,'||''''||NULL_CHAR||''''||')'
54390 ||' AND NVL(mss2.lot_number,'||''''||NULL_CHAR||''''||') = '
54391 ||' NVL(mss1.lot_number,'||''''||NULL_CHAR||''''||')'
54392 ||' AND NVL(mss2.project_number,'||''''||NULL_CHAR||''''||') = '
54393 ||' NVL(mss1.project_number,'||''''||NULL_CHAR||''''||')'
54394 ||' AND NVL(mss2.task_number,'||''''||NULL_CHAR||''''||') = '
54395 ||' NVL(mss1.task_number,'||''''||NULL_CHAR||''''||')'
54396 ||' AND NVL(mss2.unit_number,'||''''||NULL_CHAR||''''||') = '
54397 ||' NVL(mss1.unit_number,'||''''||NULL_CHAR||''''||')'
54398 ||' AND mss2.order_type = mss1.order_type '
54399 ||' AND mss2.process_flag = '||G_IN_PROCESS
54400 ||' AND mss2.sr_instance_code = mss1.sr_instance_code'
54401 ||' AND NVL(mss2.message_id,'||NULL_VALUE||')<>'||NULL_VALUE||')'
54402 ||' AND mss1.order_type = 18'
54403 ||' AND mss1.process_flag = '||G_IN_PROCESS
54404 ||' AND mss1.sr_instance_code = :v_instance_code'
54405 ||' AND NVL(mss1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
54406
54407
54408 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
54409
54410 EXECUTE IMMEDIATE lv_sql_stmt
54411 USING v_instance_code;
54412
54413
54414 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
54415 (p_app_short_name => 'MSC',
54416 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
54417 p_message_text => lv_message_text,
54418 p_error_text => lv_error_text);
54419
54420 IF lv_return <> 0 THEN
54421 RAISE ex_logging_err;
54422 END IF;
54423
54424 --Duplicate records check for the records whose source is other than XML
54425 --Different SQL is used because in XML we can identify the latest records
54426 --whereas in batch load we cannot.
54427 --Check for PO, purchase req. and intransit supplies.
54428 v_sql_stmt := 06;
54429 lv_sql_stmt :=
54430 'UPDATE msc_st_supplies mss1 '
54431 ||' SET process_flag = '||G_ERROR_FLG||','
54432 ||' error_text = '||''''||lv_message_text||''''
54433 ||' WHERE EXISTS( SELECT 1 '
54434 ||' FROM msc_st_supplies mss2'
54435 ||' WHERE mss2.sr_instance_code'
54436 ||' = mss1.sr_instance_code'
54437 ||' AND NVL(mss2.company_name, '||''''||NULL_CHAR||''''||') = '
54438 ||' NVL(mss1.company_name, '||''''||NULL_CHAR||''''||')'
54439 ||' AND mss2.order_number = mss1.order_number'
54440 ||' AND mss2.purch_line_num = mss1.purch_line_num'
54441 ||' AND mss2.order_type = mss1.order_type'
54442 ||' AND mss2.process_flag = '||G_IN_PROCESS
54443 ||' AND mss2.sr_instance_code = mss1.sr_instance_code'
54444 ||' AND NVL(mss2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
54445 ||' GROUP BY sr_instance_code,order_number,company_name,'
54446 ||' purch_line_num,order_type,organization_code'
54447 ||' HAVING COUNT(*) > 1)'
54448 ||' AND mss1.order_type IN(1,8,2,11,12)'
54449 ||' AND mss1.process_flag = '||G_IN_PROCESS
54450 ||' AND mss1.sr_instance_code = :v_instance_code'
54451 ||' AND NVL(mss1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
54452
54453
54454 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
54455
54456 EXECUTE IMMEDIATE lv_sql_stmt
54457 USING v_instance_code;
54458
54459 --Duplicate Check for plan orders and return forecasts(batch load).
54460 v_sql_stmt := 08;
54461 lv_sql_stmt :=
54462 'UPDATE msc_st_supplies mss1 '
54463 ||' SET process_flag = '||G_ERROR_FLG||','
54464 ||' error_text = '||''''||lv_message_text||''''
54465 ||' WHERE EXISTS( SELECT 1 '
54466 ||' FROM msc_st_supplies mss2'
54467 ||' WHERE mss2.sr_instance_code'
54468 ||' = mss1.sr_instance_code'
54469 ||' AND NVL(mss2.company_name,'||''''||NULL_CHAR||''''||') = '
54470 ||' NVL(mss1.company_name,'||''''||NULL_CHAR||''''||')'
54471 ||' AND mss2.organization_code = mss1.organization_code '
54472 ||' AND mss2.schedule_designator = mss1.schedule_designator'
54473 ||' AND mss2.schedule_line_num = mss1.schedule_line_num '
54474 ||' AND mss2.order_type = mss1.order_type '
54475 ||' AND mss2.process_flag = '||G_IN_PROCESS
54476 ||' AND mss2.sr_instance_code = mss1.sr_instance_code'
54477 ||' AND NVL(mss2.message_id,'||NULL_VALUE||') ='||NULL_VALUE
54478 ||' GROUP BY sr_instance_code,schedule_designator,company_name,'
54479 ||' schedule_line_num,order_type,organization_code'
54480 ||' HAVING COUNT(*) > 1)'
54481 ||' AND mss1.order_type IN (5,81)'
54482 ||' AND mss1.process_flag = '||G_IN_PROCESS
54483 ||' AND mss1.sr_instance_code = :v_instance_code'
54484 ||' AND NVL(mss1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
54485
54486
54487 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
54488
54489 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
54490
54491 --Duplicate Check for on hand supplies(batch load).
54492 v_sql_stmt := 09;
54493 lv_sql_stmt :=
54494 'UPDATE msc_st_supplies mss1'
54495 ||' SET process_flag = '||G_ERROR_FLG||','
54496 ||' error_text = '||''''||lv_message_text||''''
54497 ||' WHERE EXISTS( SELECT 1 '
54498 ||' FROM msc_st_supplies mss2'
54499 ||' WHERE mss2.sr_instance_code = mss1.sr_instance_code'
54500 ||' AND NVL(mss2.company_name,'||''''||NULL_CHAR||''''||') = '
54501 ||' NVL(mss1.company_name,'||''''||NULL_CHAR||''''||')'
54502 ||' AND mss2.organization_code = mss1.organization_code '
54503 ||' AND mss2.item_name = mss1.item_name '
54504 ||' AND NVL(mss2.subinventory_code,'||''''||NULL_CHAR||''''||') = '
54505 ||' NVL(mss1.subinventory_code,'||''''||NULL_CHAR||''''||')'
54506 ||' AND NVL(mss2.lot_number,'||''''||NULL_CHAR||''''||') = '
54507 ||' NVL(mss1.lot_number,'||''''||NULL_CHAR||''''||')'
54508 ||' AND NVL(mss2.project_number,'||''''||NULL_CHAR||''''||') = '
54509 ||' NVL(mss1.project_number,'||''''||NULL_CHAR||''''||')'
54510 ||' AND NVL(mss2.task_number,'||''''||NULL_CHAR||''''||') = '
54511 ||' NVL(mss1.task_number,'||''''||NULL_CHAR||''''||')'
54512 ||' AND NVL(mss2.unit_number,'||''''||NULL_CHAR||''''||') = '
54513 ||' NVL(mss1.unit_number,'||''''||NULL_CHAR||''''||')'
54514 ||' AND mss2.order_type = mss1.order_type '
54515 ||' AND mss2.process_flag = '||G_IN_PROCESS
54516 ||' AND mss2.sr_instance_code = mss1.sr_instance_code'
54517 ||' AND NVL(mss2.message_id,'||NULL_VALUE||') ='||NULL_VALUE
54518 ||' GROUP BY sr_instance_code,organization_code,'
54519 ||' item_name,subinventory_code,company_name,'
54520 ||' lot_number, project_number,'
54521 ||' task_number,unit_number,'
54522 ||' order_type'
54523 ||' HAVING COUNT(*) > 1)'
54524 ||' AND mss1.order_type = 18'
54525 ||' AND mss1.process_flag = '||G_IN_PROCESS
54526 ||' AND mss1.sr_instance_code = :v_instance_code'
54527 ||' AND NVL(mss1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
54528
54529
54530 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
54531
54532 EXECUTE IMMEDIATE lv_sql_stmt
54533 USING v_instance_code;
54534
54535 --Since all the validation is done based on the order type,
54536 --order_type validation is done here which is common to all
54537 --the supplies including WO supplies.
54538
54539 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
54540 (p_app_short_name => 'MSC',
54541 p_error_code => 'MSC_PP_INVALID_VALUE',
54542 p_message_text => lv_message_text,
54543 p_error_text => lv_error_text,
54544 p_token1 => 'COLUMN_NAME',
54545 p_token_value1 => 'ORDER_TYPE');
54546
54547 IF lv_return <> 0 THEN
54548 RAISE ex_logging_err;
54549 END IF;
54550
54551
54552 v_sql_stmt := 10;
54553 lv_sql_stmt :=
54554 'UPDATE msc_st_supplies '
54555 ||' SET process_flag = '||G_ERROR_FLG||','
54556 ||' error_text = '||''''||lv_message_text||''''
54557 ||' WHERE order_type NOT IN(1,2,3,5,7,8,11,12,14,15,16,18,27,75,73,74,87,86,81)'
54558 ||' AND process_flag = '||G_IN_PROCESS
54559 ||' AND sr_instance_code = :v_instance_code';
54560
54561
54562 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
54563
54564 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
54565 END IF;
54566
54567 commit; -- for supplies
54568
54569
54570 IF v_mat_dmd_enabled = SYS_YES THEN
54571
54572 --Duplicate records check for the records whose source is XML
54573
54574 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
54575 (p_app_short_name => 'MSC',
54576 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
54577 p_message_text => lv_message_text,
54578 p_error_text => lv_error_text);
54579
54580 IF lv_return <> 0 THEN
54581 RAISE ex_logging_err;
54582 END IF;
54583
54584 --For MDS and Forecast (origination_type 8 and 29)
54585
54586 -- MDS
54587 lv_sql_stmt :=
54588 'UPDATE msc_st_demands msd1'
54589 ||' SET process_flag = '||G_ERROR_FLG||','
54590 ||' error_text = '||''''||lv_message_text||''''
54591 ||' WHERE message_id < (SELECT MAX(message_id)'
54592 ||' FROM msc_st_demands msd2'
54593 ||' WHERE msd2.sr_instance_code = msd1.sr_instance_code '
54594 ||' AND nvl(msd2.using_assembly_demand_date,SYSDATE-365000 ) = nvl(msd1.using_assembly_demand_date,SYSDATE-365000 ) '
54595 ||' AND msd2.item_name = msd1.item_name'
54596 ||' AND msd2.organization_code = msd1.organization_code '
54597 ||' AND NVL(msd2.company_name,'||''''||NULL_CHAR||''''||') '
54598 ||' = NVL(msd1.company_name,'||''''||NULL_CHAR||''''||') '
54599 ||' AND msd2.demand_schedule_name = msd1.demand_schedule_name '
54600 ||' AND NVL(msd2.schedule_line_num,'||''''||NULL_CHAR||''''||') '
54601 ||' = NVL(msd1.schedule_line_num,'||''''||NULL_CHAR||''''||') '
54602 ||' AND msd2.origination_type = msd1.origination_type'
54603 ||' AND msd2.process_flag = '||G_IN_PROCESS
54604 ||' AND NVL(msd2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||')'
54605 ||' AND msd1.process_flag ='|| G_IN_PROCESS
54606 ||' AND msd1.origination_type = 8'
54607 ||' AND msd1.sr_instance_code = :v_instance_code '
54608 ||' AND NVL(msd1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
54609
54610
54611 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
54612
54613 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
54614
54615 -- Forecast
54616
54617 lv_sql_stmt :=
54618 'UPDATE msc_st_demands msd1'
54619 ||' SET process_flag = '||G_ERROR_FLG||','
54620 ||' error_text = '||''''||lv_message_text||''''
54621 ||' WHERE message_id < (SELECT MAX(message_id)'
54622 ||' FROM msc_st_demands msd2'
54623 ||' WHERE msd2.sr_instance_code = msd1.sr_instance_code '
54624 ||' AND msd2.schedule_date = msd1.schedule_date '
54625 ||' AND msd2.item_name = msd1.item_name'
54626 ||' AND msd2.forecast_designator = msd1.forecast_designator '
54627 ||' AND NVL(msd2.schedule_line_num,'||''''||NULL_CHAR||''''||') '
54628 ||' = NVL(msd1.schedule_line_num,'||''''||NULL_CHAR||''''||') '
54629 ||' AND msd2.organization_code = msd1.organization_code '
54630 ||' AND NVL(msd2.company_name,'||''''||NULL_CHAR||''''||') '
54631 ||' = NVL(msd1.company_name,'||''''||NULL_CHAR||''''||') '
54632 ||' AND msd2.origination_type = msd1.origination_type'
54633 ||' AND msd2.process_flag = '||G_IN_PROCESS
54634 ||' AND NVL(msd2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||')'
54635 ||' AND msd1.process_flag ='|| G_IN_PROCESS
54636 ||' AND msd1.origination_type = 29 '
54637 ||' AND msd1.sr_instance_code = :v_instance_code '
54638 ||' AND NVL(msd1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
54639
54640
54641 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
54642
54643 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
54644
54645 --Duplicate records check for the records whose source is batch load
54646
54647 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
54648 (p_app_short_name => 'MSC',
54649 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
54650 p_message_text => lv_message_text,
54651 p_error_text => lv_error_text);
54652
54653 IF lv_return <> 0 THEN
54654 RAISE ex_logging_err;
54655 END IF;
54656
54657 -- Forecast
54658 v_sql_stmt := 12;
54659
54660 lv_sql_stmt :=
54661 'UPDATE msc_st_demands msd1'
54662 ||' SET process_flag = '||G_ERROR_FLG||','
54663 ||' error_text = '||''''||lv_message_text||''''
54664 ||' WHERE EXISTS( SELECT 1 '
54665 ||' FROM msc_st_demands msd2'
54666 ||' WHERE msd2.sr_instance_code = msd1.sr_instance_code '
54667 ||' AND msd2.organization_code = msd1.organization_code '
54668 ||' AND NVL(msd2.company_name,'||''''||NULL_CHAR||''''||') '
54669 ||' = NVL(msd1.company_name,'||''''||NULL_CHAR||''''||') '
54670 ||' AND msd2.forecast_designator = msd1.forecast_designator '
54671 ||' AND msd2.item_name = msd1.item_name'
54672 ||' AND NVL(msd2.schedule_line_num,'||''''||NULL_CHAR||''''||') '
54673 ||' = NVL(msd1.schedule_line_num,'||''''||NULL_CHAR||''''||') '
54674 ||' AND msd2.schedule_date = msd1.schedule_date '
54675 ||' AND msd2.origination_type = msd1.origination_type'
54676 ||' AND msd2.process_flag = '||G_IN_PROCESS
54677 ||' AND NVL(msd2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
54678 ||' AND msd2.rowid <> msd1.rowid)'
54679 ||' AND msd1.process_flag = '||G_IN_PROCESS
54680 ||' AND msd1.origination_type = 29'
54681 ||' AND msd1.sr_instance_code = :v_instance_code'
54682 ||' AND NVL(msd1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
54683
54684
54685 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
54686
54687 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
54688
54689 -- MDS
54690 v_sql_stmt := 12;
54691
54692 lv_sql_stmt :=
54693 'UPDATE msc_st_demands msd1'
54694 ||' SET process_flag = '||G_ERROR_FLG||','
54695 ||' error_text = '||''''||lv_message_text||''''
54696 ||' WHERE EXISTS( SELECT 1 '
54697 ||' FROM msc_st_demands msd2'
54698 ||' WHERE msd2.sr_instance_code '
54699 ||' = msd1.sr_instance_code '
54700 ||' AND msd2.organization_code '
54701 ||' = msd1.organization_code '
54702 ||' AND NVL(msd2.company_name,'||''''||NULL_CHAR||''''||') '
54703 ||' = NVL(msd1.company_name,'||''''||NULL_CHAR||''''||') '
54704 ||' AND msd2.demand_schedule_name = msd1.demand_schedule_name '
54705 ||' AND msd2.item_name = msd1.item_name'
54706 ||' AND NVL(msd2.schedule_line_num,'||''''||NULL_CHAR||''''||') '
54707 ||' = NVL(msd1.schedule_line_num,'||''''||NULL_CHAR||''''||') '
54708 ||' AND nvl(msd2.using_assembly_demand_date,SYSDATE-365000 ) = nvl(msd1.using_assembly_demand_date,SYSDATE-365000 ) '
54709 ||' AND msd2.origination_type '
54710 ||' = msd1.origination_type'
54711 ||' AND msd2.process_flag = '||G_IN_PROCESS
54712 ||' AND NVL(msd2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
54713 ||' AND msd2.rowid <> msd1.rowid)'
54714 ||' AND msd1.process_flag = '||G_IN_PROCESS
54715 ||' AND msd1.origination_type = 8 '
54716 ||' AND msd1.sr_instance_code = :v_instance_code'
54717 ||' AND NVL(msd1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
54718
54719
54720 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
54721
54722 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
54723
54724
54725 --Duplicate SO records check for the records whose source is XML
54726
54727 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
54728 (p_app_short_name => 'MSC',
54729 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
54730 p_message_text => lv_message_text,
54731 p_error_text => lv_error_text);
54732
54733 IF lv_return <> 0 THEN
54734 RAISE ex_logging_err;
54735 END IF;
54736 --Duplicate records check for the records whose source is XML
54737
54738 v_sql_stmt := 13;
54739
54740 lv_sql_stmt :=
54741 'UPDATE msc_st_sales_orders mso1'
54742 ||' SET process_flag = '||G_ERROR_FLG||','
54743 ||' error_text = '||''''||lv_message_text||''''
54744 ||' WHERE message_id < (SELECT MAX(message_id)'
54745 ||' FROM msc_st_sales_orders mso2'
54746 ||' WHERE mso2.sr_instance_code '
54747 ||' = mso1.sr_instance_code '
54748 ||' AND mso2.sales_order_number '
54749 ||' = mso1.sales_order_number '
54750 ||' AND mso2.line_num'
54751 ||' = mso1.line_num'
54752 ||' AND mso2.organization_code '
54753 ||' = mso1.organization_code '
54754 ||' AND nvl(mso2.reservation_type,'||NULL_VALUE||') '
54755 ||' = nvl(mso1.reservation_type,'||NULL_VALUE||') '
54756 ||' AND nvl(mso2.SUBINVENTORY,'||''''||NULL_CHAR||''''||') '
54757 ||' = nvl(mso1.SUBINVENTORY,'||''''||NULL_CHAR||''''||') '
54758 ||' AND NVL(mso2.company_name,'||''''||NULL_CHAR||''''||') '
54759 ||' = NVL(mso1.company_name,'||''''||NULL_CHAR||''''||') '
54760 ||' AND mso2.process_flag = '||G_IN_PROCESS
54761 ||' AND NVL(mso2.message_id,'||NULL_VALUE||')<> '||NULL_VALUE||')'
54762 ||' AND mso1.process_flag ='|| G_IN_PROCESS
54763 ||' AND mso1.sr_instance_code = :v_instance_code '
54764 ||' AND NVL(mso1.message_id,'||NULL_VALUE||')<> '||NULL_VALUE;
54765
54766
54767 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
54768
54769 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
54770
54771
54772 --Duplicate records check for the records whose source is batch load
54773
54774 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
54775 (p_app_short_name => 'MSC',
54776 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
54777 p_message_text => lv_message_text,
54778 p_error_text => lv_error_text);
54779
54780 IF lv_return <> 0 THEN
54781 RAISE ex_logging_err;
54782 END IF;
54783
54784 v_sql_stmt := 14;
54785
54786 lv_sql_stmt :=
54787 'UPDATE msc_st_sales_orders mso1'
54788 ||' SET process_flag = '||G_ERROR_FLG||','
54789 ||' error_text = '||''''||lv_message_text||''''
54790 ||' WHERE EXISTS( SELECT 1 '
54791 ||' FROM msc_st_sales_orders mso2'
54792 ||' WHERE mso2.sr_instance_code '
54793 ||' = mso1.sr_instance_code '
54794 ||' AND mso2.sales_order_number '
54795 ||' = mso1.sales_order_number '
54796 ||' AND mso2.line_num'
54797 ||' = mso1.line_num'
54798 ||' AND mso2.organization_code '
54799 ||' = mso1.organization_code '
54800 ||' AND nvl(mso2.reservation_type,'||NULL_VALUE||') '
54801 ||' = nvl(mso1.reservation_type,'||NULL_VALUE||') '
54802 ||' AND nvl(mso2.SUBINVENTORY,'||''''||NULL_CHAR||''''||') '
54803 ||' = nvl(mso1.SUBINVENTORY,'||''''||NULL_CHAR||''''||') '
54804 ||' AND NVL(mso2.company_name,'||''''||NULL_CHAR||''''||') '
54805 ||' = NVL(mso1.company_name,'||''''||NULL_CHAR||''''||') '
54806 ||' AND mso2.process_flag = '||G_IN_PROCESS
54807 ||' AND NVL(mso2.message_id,'||NULL_VALUE||') = '||NULL_VALUE
54808 ||' AND mso2.rowid <> mso1.rowid )'
54809 ||' AND mso1.process_flag = '||G_IN_PROCESS
54810 ||' AND mso1.sr_instance_code = :v_instance_code'
54811 ||' AND NVL(mso1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
54812
54813
54814 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
54815
54816 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
54817 END IF;
54818
54819 commit; -- for demands
54820
54821 -- For LEVEL_VALUE
54822 IF v_level_value_enabled = SYS_YES THEN
54823 v_sql_stmt := 15;
54824 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
54825 (p_app_short_name => 'MSC',
54826 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
54827 p_message_text => lv_message_text,
54828 p_error_text => lv_error_text);
54829
54830 IF lv_return <> 0 THEN
54831 RAISE ex_logging_err;
54832 END IF;
54833
54834 v_sql_stmt := 01;
54835 lv_sql_stmt :=
54836 'UPDATE msd_st_level_values mlv1'
54837 ||' SET process_flag = '||G_ERROR_FLG||','
54838 ||' error_text = '||''''||lv_message_text||''''
54839 ||' WHERE EXISTS ( SELECT 1 FROM msd_st_level_values mlv2'
54840 ||' WHERE mlv1.level_name = mlv2.level_name'
54841 ||' AND mlv1.level_value = mlv2.level_value'
54842 ||' AND mlv1.process_flag = mlv2.process_flag'
54843 ||' AND mlv1.sr_instance_code = mlv2.sr_instance_code'
54844 ||' GROUP BY sr_instance_code,level_name, level_value'
54845 ||' HAVING COUNT(*)> 1 )'
54846 ||' AND mlv1.process_flag = '||G_IN_PROCESS
54847 ||' AND sr_instance_code = :v_instance_code';
54848
54849
54850 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
54851
54852 EXECUTE IMMEDIATE lv_sql_stmt
54853 USING v_instance_code;
54854
54855 commit;
54856 END IF; -- level_value
54857
54858 EXCEPTION
54859 WHEN ex_logging_err THEN
54860 ERRBUF := lv_error_text;
54861 RETCODE := G_ERROR;
54862 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,ERRBUF);
54863 ROLLBACK;
54864 WHEN others THEN
54865 ERRBUF := SQLERRM;
54866 RETCODE := G_ERROR;
54867 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,ERRBUF);
54868 ROLLBACK;
54869 END CHECK_DUPLICATES ;
54870
54871 -- Item Customer Records
54872 PROCEDURE LOAD_ITEM_CUSTOMERS IS
54873
54874 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
54875 lb_rowid RowidTab;
54876
54877 lv_column_names VARCHAR2(5000); -- Stores cocatenated column names
54878 lv_return NUMBER;
54879 lv_error_text VARCHAR2(250);
54880 lv_where_str VARCHAR2(5000);
54881 lv_sql_stmt VARCHAR2(5000);
54882 lv_batch_id msc_st_system_items.batch_id%TYPE;
54883 lv_message_text msc_errors.error_text%TYPE;
54884
54885 ex_logging_err EXCEPTION;
54886 busy EXCEPTION;
54887 PRAGMA EXCEPTION_INIT(busy, -54);
54888
54889 CURSOR c1(p_batch_id NUMBER) IS
54890 SELECT rowid
54891 FROM msc_st_item_customers
54892 WHERE process_flag IN (G_IN_PROCESS,G_ERROR_FLG)
54893 AND sr_instance_code = v_instance_code
54894 AND batch_id = p_batch_id;
54895
54896 BEGIN
54897 -- Validation of table msc_st_item_customers
54898
54899 lv_column_names :=
54900 'ITEM_NAME ||''~''||'
54901 ||'CUSTOMER_ITEM_NAME ||''~''||'
54902 ||'DESCRIPTION ||''~''||'
54903 ||'CUSTOMER_NAME ||''~''||'
54904 ||'CUSTOMER_SITE_NAME ||''~''||'
54905 ||'SR_INSTANCE_CODE ||''~''||'
54906 ||'LEAD_TIME ||''~''||'
54907 ||'UOM_CODE ||''~''||'
54908 ||'LIST_PRICE ||''~''||'
54909 ||'PLANNER_CODE ||''~''||'
54910 ||'COMPANY_NAME';
54911
54912
54913 -- For XML, duplicate UDK combinations would be allowed. We would pick up the record with the maximum MESSAGE_ID for the same user defined key combination for processing. For other records we would set process flag to 3 and log an error message.
54914 -- Duplicate records check for the records whose source is XML.
54915
54916 -- Error out records if same OEM item is mapped to multiple customer items
54917
54918 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
54919 (p_app_short_name => 'MSC',
54920 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
54921 p_message_text => lv_message_text,
54922 p_error_text => lv_error_text);
54923
54924 IF lv_return <> 0 THEN
54925 RAISE ex_logging_err;
54926 END IF;
54927
54928 v_sql_stmt := 01;
54929 lv_sql_stmt :=
54930 'UPDATE msc_st_item_customers mic1 '
54931 ||' SET process_flag = '||G_ERROR_FLG||','
54932 ||' error_text = '||''''||lv_message_text||''''
54933 ||' WHERE message_id < (SELECT MAX(message_id)'
54934 ||' FROM msc_st_item_customers mic2'
54935 ||' WHERE mic2.sr_instance_code = mic1.sr_instance_code'
54936 ||' AND NVL(mic2.company_name, '||''''||NULL_CHAR||''''||') = '
54937 ||' NVL(mic1.company_name, '||''''||NULL_CHAR||''''||')'
54938 ||' AND mic2.ITEM_NAME = mic1.ITEM_NAME'
54939 ||' AND mic2.CUSTOMER_NAME = mic1.CUSTOMER_NAME'
54940 ||' AND NVL(mic2.CUSTOMER_SITE_NAME, '||''''||NULL_CHAR||''''||') = '
54941 ||' NVL(mic1.CUSTOMER_SITE_NAME, '||''''||NULL_CHAR||''''||'))'
54942 ||' AND mic1.process_flag = '||G_IN_PROCESS
54943 ||' AND mic1.sr_instance_code = :v_instance_code'
54944 ||' AND NVL(mic1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
54945
54946
54947 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
54948
54949 EXECUTE IMMEDIATE lv_sql_stmt
54950 USING v_instance_code;
54951
54952 -- Error out records if multiple OEM items are mapped to same customer items
54953
54954 IF lv_return <> 0 THEN
54955 RAISE ex_logging_err;
54956 END IF;
54957
54958 v_sql_stmt := 02;
54959 lv_sql_stmt :=
54960 'UPDATE msc_st_item_customers mic1 '
54961 ||' SET process_flag = '||G_ERROR_FLG||','
54962 ||' error_text = '||''''||lv_message_text||''''
54963 ||' WHERE message_id < (SELECT MAX(message_id)'
54964 ||' FROM msc_st_item_customers mic2'
54965 ||' WHERE mic2.sr_instance_code = mic1.sr_instance_code'
54966 ||' AND NVL(mic2.company_name, '||''''||NULL_CHAR||''''||') = '
54967 ||' NVL(mic1.company_name, '||''''||NULL_CHAR||''''||')'
54968 ||' AND mic2.CUSTOMER_ITEM_NAME = mic1.CUSTOMER_ITEM_NAME'
54969 ||' AND mic2.CUSTOMER_NAME = mic1.CUSTOMER_NAME'
54970 ||' AND NVL(mic2.CUSTOMER_SITE_NAME, '||''''||NULL_CHAR||''''||') = '
54971 ||' NVL(mic1.CUSTOMER_SITE_NAME, '||''''||NULL_CHAR||''''||'))'
54972 ||' AND mic1.process_flag = '||G_IN_PROCESS
54973 ||' AND mic1.sr_instance_code = :v_instance_code'
54974 ||' AND NVL(mic1.message_id,'||NULL_VALUE||') <> '||NULL_VALUE;
54975
54976
54977 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
54978
54979 EXECUTE IMMEDIATE lv_sql_stmt
54980 USING v_instance_code;
54981
54982 -- For Batch loads (excel etc.) we error out all duplicate UDK records.
54983 -- No record would be processed in this case. To identify whether the record has come via batch/ XML we would use the MESSAGE_ID field.
54984 -- If MESSAGE_ID is not null then we would assume it to have come in via XML else via batch load.
54985
54986 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
54987 (p_app_short_name => 'MSC',
54988 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
54989 p_message_text => lv_message_text,
54990 p_error_text => lv_error_text);
54991
54992 IF lv_return <> 0 THEN
54993 RAISE ex_logging_err;
54994 END IF;
54995
54996 --Duplicate records check for the records whose source is other than XML
54997 --Different SQL is used because in XML we can identify the latest records
54998 --whereas in batch load we cannot.
54999
55000
55001 -- Error out records if same OEM item is mapped to multiple customer items. add index for this
55002
55003 v_sql_stmt := 03;
55004 lv_sql_stmt :=
55005 'UPDATE msc_st_item_customers mic1 '
55006 ||' SET process_flag = '||G_ERROR_FLG||','
55007 ||' error_text = '||''''||lv_message_text||''''
55008 ||' WHERE EXISTS( SELECT 1 '
55009 ||' FROM msc_st_item_customers mic2'
55010 ||' WHERE mic2.sr_instance_code = mic1.sr_instance_code'
55011 ||' AND NVL(mic2.company_name, '||''''||NULL_CHAR||''''||') = '
55012 ||' NVL(mic1.company_name, '||''''||NULL_CHAR||''''||')'
55013 ||' AND mic2.ITEM_NAME = mic1.ITEM_NAME'
55014 ||' AND mic2.CUSTOMER_NAME = mic1.CUSTOMER_NAME'
55015 ||' AND NVL(mic2.CUSTOMER_SITE_NAME, '||''''||NULL_CHAR||''''||') = '
55016 ||' NVL(mic1.CUSTOMER_SITE_NAME, '||''''||NULL_CHAR||''''||')'
55017 ||' AND mic1.rowid <> mic2.rowid)'
55018 ||' AND mic1.process_flag = '||G_IN_PROCESS
55019 ||' AND mic1.sr_instance_code = :v_instance_code'
55020 ||' AND NVL(mic1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
55021
55022
55023 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
55024
55025 EXECUTE IMMEDIATE lv_sql_stmt
55026 USING v_instance_code;
55027
55028 -- Error out records if multiple OEM items are mapped to same customer items. add index for this
55029
55030 v_sql_stmt := 04;
55031 lv_sql_stmt :=
55032 'UPDATE msc_st_item_customers mic1 '
55033 ||' SET process_flag = '||G_ERROR_FLG||','
55034 ||' error_text = '||''''||lv_message_text||''''
55035 ||' WHERE EXISTS( SELECT 1 '
55036 ||' FROM msc_st_item_customers mic2'
55037 ||' WHERE mic2.sr_instance_code = mic1.sr_instance_code'
55038 ||' AND NVL(mic2.company_name, '||''''||NULL_CHAR||''''||') = '
55039 ||' NVL(mic1.company_name, '||''''||NULL_CHAR||''''||')'
55040 ||' AND mic2.CUSTOMER_ITEM_NAME = mic1.CUSTOMER_ITEM_NAME'
55041 ||' AND mic2.CUSTOMER_NAME = mic1.CUSTOMER_NAME'
55042 ||' AND NVL(mic2.CUSTOMER_SITE_NAME, '||''''||NULL_CHAR||''''||') = '
55043 ||' NVL(mic1.CUSTOMER_SITE_NAME, '||''''||NULL_CHAR||''''||')'
55044 ||' AND mic1.rowid <> mic2.rowid)'
55045 ||' AND mic1.process_flag = '||G_IN_PROCESS
55046 ||' AND mic1.sr_instance_code = :v_instance_code'
55047 ||' AND NVL(mic1.message_id,'||NULL_VALUE||') = '||NULL_VALUE;
55048
55049
55050 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
55051
55052 EXECUTE IMMEDIATE lv_sql_stmt
55053 USING v_instance_code;
55054
55055
55056 -- Generate the batch_id and update the tables with the batch_id.
55057
55058 LOOP
55059 v_sql_stmt := 05;
55060
55061 SELECT msc_st_batch_id_s.NEXTVAL
55062 INTO lv_batch_id
55063 FROM dual;
55064
55065 v_sql_stmt := 06;
55066 lv_sql_stmt :=
55067 'UPDATE msc_st_item_customers '
55068 ||' SET batch_id = :lv_batch_id'
55069 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
55070 ||' AND sr_instance_code = :v_instance_code'
55071 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
55072 ||' AND rownum <= '||v_batch_size;
55073
55074
55075 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
55076
55077 EXECUTE IMMEDIATE lv_sql_stmt
55078 USING lv_batch_id,
55079 v_instance_code;
55080
55081 EXIT WHEN SQL%NOTFOUND;
55082
55083 OPEN c1(lv_batch_id);
55084 FETCH c1 BULK COLLECT INTO lb_rowid;
55085 CLOSE c1;
55086
55087
55088 -- Generate the st_transaction_id and update all the records with this st_transaction_id.
55089 -- Set the who columns also (where PROCESS_FLAG = 2 and SR_INSTANCE_CODE = v_instance_code).
55090 -- Sequence : MSC_ST_ITEM_CUSTOMERS_S.
55091
55092 v_sql_stmt := 07;
55093 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
55094 UPDATE msc_st_item_customers
55095 SET st_transaction_id = MSC_ST_ITEM_CUSTOMERS_S.NEXTVAL,
55096 refresh_id = v_refresh_id,
55097 last_update_date = v_current_date,
55098 last_updated_by = v_current_user,
55099 creation_date = v_current_date,
55100 created_by = v_current_user
55101 WHERE rowid = lb_rowid(j);
55102
55103
55104 -- Error out those records where the deleted_flag is set to 'Y' if the collection program doesn't support deletion for this BO.
55105 -- Insert the records into the error_table with the severity warning where deleted_flag has a null value.
55106 -- Update the MSC_ST_ITEM_SUPPLIERS table with the default value 2.
55107
55108 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
55109 (p_app_short_name => 'MSC',
55110 p_error_code => 'MSC_PP_NO_DELETION',
55111 p_message_text => lv_message_text,
55112 p_error_text => lv_error_text,
55113 p_token1 => 'TABLE_NAME',
55114 p_token_value1 => 'MSC_ST_ITEM_CUSTOMERS');
55115
55116 IF lv_return <> 0 THEN
55117 RAISE ex_logging_err;
55118 END IF;
55119
55120 -- Deletion is not allowed for this table
55121
55122 v_sql_stmt := 08;
55123 lv_sql_stmt :=
55124 'UPDATE MSC_ST_ITEM_CUSTOMERS '
55125 ||' SET process_flag = '||G_ERROR_FLG||','
55126 ||' error_text = '||''''||lv_message_text||''''
55127 ||' WHERE deleted_flag = '||SYS_YES
55128 ||' AND process_flag = '||G_IN_PROCESS
55129 ||' AND batch_id = :lv_batch_id'
55130 ||' AND sr_instance_code = :v_instance_code';
55131
55132
55133
55134 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
55135 EXECUTE IMMEDIATE lv_sql_stmt
55136 USING lv_batch_id,
55137 v_instance_code;
55138
55139 -- warning message if the DELETED_FLAG is other than 1, 2. default to SYS_NO (2)
55140
55141 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
55142 (p_app_short_name => 'MSC',
55143 p_error_code => 'MSC_PP_INVALID_COL_VALUE',
55144 p_message_text => lv_message_text,
55145 p_error_text => lv_error_text,
55146 p_token1 => 'COLUMN_NAME',
55147 p_token_value1 => 'DELETED_FLAG',
55148 p_token2 => 'DEFAULT_VALUE',
55149 p_token_value2 => SYS_NO);
55150
55151 IF lv_return <> 0 THEN
55152 RAISE ex_logging_err;
55153 END IF;
55154
55155 lv_where_str :=
55156 ' AND NVL(deleted_flag,'||NULL_VALUE||') NOT IN(1,2)';
55157
55158 --Log a warning for those records where the deleted_flag has a value other
55159 --SYS_NO
55160
55161 lv_return := MSC_ST_UTIL.LOG_ERROR
55162 (p_table_name => 'MSC_ST_ITEM_CUSTOMERS',
55163 p_instance_code => v_instance_code,
55164 p_row => lv_column_names,
55165 p_severity => G_SEV_WARNING,
55166 p_message_text => lv_message_text,
55167 p_error_text => lv_error_text,
55168 p_batch_id => lv_batch_id,
55169 p_where_str => lv_where_str,
55170 p_col_name => 'DELETED_FLAG',
55171 p_debug => v_debug,
55172 p_default_value => SYS_NO);
55173
55174 IF lv_return <> 0 THEN
55175 RAISE ex_logging_err;
55176 END IF;
55177
55178 -- derive the company_id if it is not null or -1. if not found then error out record
55179 IF v_sce_installed THEN
55180
55181 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
55182 (p_app_short_name => 'MSC',
55183 p_error_code => 'MSC_PP_INVALID_VALUE',
55184 p_message_text => lv_message_text,
55185 p_error_text => lv_error_text,
55186 p_token1 => 'COLUMN_NAME',
55187 p_token_value1 => 'COMPANY_NAME');
55188
55189 IF lv_return <> 0 THEN
55190 RAISE ex_logging_err;
55191 END IF;
55192
55193 lv_return := MSC_ST_UTIL.DERIVE_COMPANY_ID
55194 (p_table_name => 'MSC_ST_ITEM_CUSTOMERS',
55195 p_company_name => 'COMPANY_NAME',
55196 p_company_id => 'COMPANY_ID',
55197 p_instance_code => v_instance_code,
55198 p_error_text => lv_error_text,
55199 p_batch_id => lv_batch_id,
55200 p_message_text => lv_message_text,
55201 p_debug => v_debug);
55202
55203 IF lv_return <> 0 THEN
55204 RAISE ex_logging_err;
55205 END IF;
55206
55207 END IF;
55208
55209
55210 /* Calling derive_company_id
55211 lv_sql_stmt :=
55212 ' UPDATE MSC_ST_ITEM_CUSTOMERS mic '
55213 ||' SET company_id = '
55214 ||' (select company_id from msc_companies mc'
55215 ||' where mic.company_name = mc.company_name) '
55216 ||' WHERE NVL(COMPANY_NAME,''-1'') <> ''-1'''
55217 ||' AND batch_id = :lv_batch_id'
55218 ||' AND process_flag = '||G_IN_PROCESS
55219 ||' AND sr_instance_code = :v_instance_code';
55220
55221
55222 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
55223
55224 EXECUTE IMMEDIATE lv_sql_stmt
55225 USING lv_batch_id,
55226 v_instance_code;
55227
55228 lv_sql_stmt :=
55229 ' UPDATE MSC_ST_ITEM_CUSTOMERS '
55230 ||' SET process_flag = '||G_ERROR_FLG||','
55231 ||' error_text = '||''''||lv_message_text||''''
55232 ||' WHERE NVL(COMPANY_NAME,''-1'') <> ''-1'''
55233 ||' AND COMPANY_ID IS NULL '
55234 ||' AND batch_id = :lv_batch_id'
55235 ||' AND process_flag = '||G_IN_PROCESS
55236 ||' AND sr_instance_code = :v_instance_code';
55237
55238 IF V_DEBUG THEN
55239 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
55240 END IF;
55241
55242 EXECUTE IMMEDIATE lv_sql_stmt
55243 USING lv_batch_id,
55244 v_instance_code;
55245 */
55246
55247 -- error out records where CUSTOMER_ITEM_NAME is null
55248
55249 v_sql_stmt := 09;
55250
55251 -- Set the error message
55252
55253 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
55254 (p_app_short_name => 'MSC',
55255 p_error_code => 'MSC_PP_COL_VAL_NULL',
55256 p_message_text => lv_message_text,
55257 p_error_text => lv_error_text,
55258 p_token1 => 'COLUMN_NAME',
55259 p_token_value1 => 'CUSTOMER_ITEM_NAME');
55260
55261 IF lv_return <> 0 THEN
55262 RAISE ex_logging_err;
55263 END IF;
55264
55265 lv_sql_stmt :=
55266 ' UPDATE MSC_ST_ITEM_CUSTOMERS '
55267 ||' SET process_flag = '||G_ERROR_FLG||','
55268 ||' error_text = '||''''||lv_message_text||''''
55269 ||' WHERE NVL(customer_item_name,'||''''||NULL_CHAR||''''||')'
55270 ||' = '||''''||NULL_CHAR||''''
55271 ||' AND batch_id = :lv_batch_id'
55272 ||' AND process_flag = '||G_IN_PROCESS
55273 ||' AND sr_instance_code = :v_instance_code';
55274
55275
55276 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
55277
55278 EXECUTE IMMEDIATE lv_sql_stmt
55279 USING lv_batch_id,
55280 v_instance_code;
55281
55282 -- UOM_CODE should refer to a valid record in msc_units_of_measure/msc_st_units_of_measure .
55283 -- Now check for UOM code if it is Invalid error out
55284 -- Set the error message
55285
55286 v_sql_stmt := 10;
55287
55288 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
55289 (p_app_short_name => 'MSC',
55290 p_error_code => 'MSC_PP_COL_REF_NOT_EXIST',
55291 p_message_text => lv_message_text,
55292 p_error_text => lv_error_text,
55293 p_token1 => 'COLUMN_NAMES',
55294 p_token_value1 => 'SR_INSTANCE_CODE ,UOM_CODE',
55295 p_token2 => 'MASTER_TABLE',
55296 p_token_value2 => 'MSC_ST_UNITS_OF_MEASURE',
55297 p_token3 => 'CHILD_TABLE',
55298 p_token_value3 => 'MSC_ST_ITEM_CUSTOMERS');
55299 IF lv_return <> 0 THEN
55300 RAISE ex_logging_err;
55301 END IF;
55302
55303
55304 lv_sql_stmt :=
55305 ' UPDATE MSC_ST_ITEM_CUSTOMERS mic'
55306 ||' SET process_flag = '||G_ERROR_FLG||','
55307 ||' error_text = '||''''||lv_message_text||''''
55308 ||' WHERE NOT EXISTS (SELECT 1 '
55309 ||' FROM msc_units_of_measure muom'
55310 ||' WHERE muom.uom_code = mic.uom_code'
55311 ||' UNION'
55312 ||' SELECT 1 FROM msc_st_units_of_measure msuom'
55313 ||' WHERE msuom.uom_code = mic.uom_code'
55314 ||' AND msuom.sr_instance_id = :v_instance_id'
55315 ||' AND msuom.process_flag = '||G_VALID||')'
55316 ||' AND mic.sr_instance_code = :v_instance_code'
55317 ||' AND mic.batch_id = :lv_batch_id'
55318 ||' AND mic.process_flag = '||G_IN_PROCESS ;
55319
55320
55321 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
55322
55323 EXECUTE IMMEDIATE lv_sql_stmt
55324 USING v_instance_id,
55325 v_instance_code,
55326 lv_batch_id;
55327
55328
55329 -- Derive inventory_item_id based on the item_name and error_out all the records where the derivation has failed.
55330
55331 v_sql_stmt := 11;
55332
55333 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
55334 (p_app_short_name => 'MSC',
55335 p_error_code => 'MSC_PP_INVALID_VALUE',
55336 p_message_text => lv_message_text,
55337 p_error_text => lv_error_text,
55338 p_token1 => 'COLUMN_NAME',
55339 p_token_value1 => 'ITEM_NAME');
55340
55341 --Derive Inventory_item_id
55342
55343 lv_return := MSC_ST_UTIL.DERIVE_ITEM_ID
55344 (p_table_name => 'MSC_ST_ITEM_CUSTOMERS',
55345 p_item_col_name => 'ITEM_NAME',
55346 p_item_col_id => 'INVENTORY_ITEM_ID',
55347 p_instance_id => v_instance_id,
55348 p_instance_code => v_instance_code,
55349 p_error_text => lv_error_text,
55350 p_batch_id => lv_batch_id,
55351 p_severity => G_SEV_ERROR,
55352 p_message_text => lv_message_text,
55353 p_debug => v_debug,
55354 p_row => lv_column_names,
55355 p_check_org => FALSE);
55356
55357 IF lv_return <> 0 THEN
55358 RAISE ex_logging_err;
55359 END IF;
55360
55361 -- check customer exists in msc_trading_partners
55362 -- Set the message
55363
55364 v_sql_stmt := 12;
55365
55366 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
55367 (p_app_short_name => 'MSC',
55368 p_error_code => 'MSC_PP_INVALID_VALUE',
55369 p_message_text => lv_message_text,
55370 p_error_text => lv_error_text,
55371 p_token1 => 'COLUMN_NAME',
55372 p_token_value1 => 'CUSTOMER_NAME');
55373
55374 IF lv_return <> 0 THEN
55375 RAISE ex_logging_err;
55376 END IF;
55377
55378 -- Derive customer_id and error out records if customer is not valid
55379
55380 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_ORG_ID
55381 (p_table_name => 'MSC_ST_ITEM_CUSTOMERS',
55382 p_org_partner_name => 'CUSTOMER_NAME',
55383 p_org_partner_id => 'CUSTOMER_ID',
55384 p_instance_code => v_instance_code,
55385 p_partner_type => G_CUSTOMER,
55386 p_error_text => lv_error_text,
55387 p_batch_id => lv_batch_id,
55388 p_severity => G_SEV_ERROR,
55389 p_message_text => lv_message_text,
55390 p_debug => v_debug,
55391 p_row => lv_column_names);
55392
55393 IF lv_return <> 0 THEN
55394 RAISE ex_logging_err;
55395 END IF;
55396
55397
55398 -- Check for the valid CUSTOMER_SITE_NAME and derive the CUSTOMER_SITE_ID.
55399 -- Error out those records for which the CUSTOMER_SITE_ID derivation has failed.
55400
55401
55402 v_sql_stmt := 13;
55403
55404 -- Set the message
55405
55406 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
55407 (p_app_short_name => 'MSC',
55408 p_error_code => 'MSC_PP_INVALID_VALUE',
55409 p_message_text => lv_message_text,
55410 p_error_text => lv_error_text,
55411 p_token1 => 'COLUMN_NAME',
55412 p_token_value1 => 'CUSTOMER_SITE_NAME');
55413
55414 IF lv_return <> 0 THEN
55415 RAISE ex_logging_err;
55416 END IF;
55417
55418 lv_return := MSC_ST_UTIL.DERIVE_PARTNER_SITE_ID
55419 (p_table_name => 'MSC_ST_ITEM_CUSTOMERS',
55420 p_partner_name => 'CUSTOMER_NAME',
55421 p_partner_site_code => 'CUSTOMER_SITE_NAME',
55422 p_partner_site_id => 'CUSTOMER_SITE_ID',
55423 p_instance_code => v_instance_code,
55424 p_partner_type => G_CUSTOMER,
55425 p_error_text => lv_error_text,
55426 p_batch_id => lv_batch_id,
55427 p_severity => G_SEV3_ERROR,
55428 p_message_text => lv_message_text,
55429 p_debug => v_debug,
55430 p_row => lv_column_names);
55431
55432
55433 IF lv_return <> 0 THEN
55434 RAISE ex_logging_err;
55435 END IF;
55436
55437
55438 -- Call the HOOK to enable the customised validations if there is any.
55439 -- Call to customised validation.
55440 MSC_CL_PRE_PROCESS_HOOK.ENTITY_VALIDATION
55441 (ERRBUF => lv_error_text,
55442 RETCODE => lv_return,
55443 pBatchID => lv_batch_id,
55444 pInstanceCode => v_instance_code,
55445 pEntityName => 'MSC_ST_ITEM_CUSTOMERS',
55446 pInstanceID => v_instance_id);
55447
55448 IF NVL(lv_return,0) <> 0 THEN
55449 RAISE ex_logging_err;
55450 END IF;
55451
55452
55453 -- Update the process_flag to 5(valid) and sr_instance_id to v_instance_id.
55454 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
55455 (p_table_name => 'MSC_ST_ITEM_CUSTOMERS',
55456 p_instance_id => v_instance_id,
55457 p_instance_code => v_instance_code,
55458 p_process_flag => G_VALID,
55459 p_error_text => lv_error_text,
55460 p_debug => v_debug,
55461 p_batch_id => lv_batch_id);
55462
55463 IF lv_return <> 0 THEN
55464 RAISE ex_logging_err;
55465 END IF;
55466
55467 -- Insert all the errored out records into the error table.
55468 lv_return := MSC_ST_UTIL.LOG_ERROR
55469 (p_table_name => 'MSC_ST_ITEM_CUSTOMERS',
55470 p_instance_code => v_instance_code,
55471 p_row => lv_column_names,
55472 p_severity => G_SEV_ERROR,
55473 p_message_text => NULL,
55474 p_error_text => lv_error_text,
55475 p_debug => v_debug,
55476 p_batch_id => lv_batch_id);
55477 IF lv_return <> 0 THEN
55478 RAISE ex_logging_err;
55479 END IF;
55480
55481
55482 COMMIT;
55483
55484 END LOOP;
55485
55486 EXCEPTION
55487 WHEN ex_logging_err THEN
55488 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
55489 ROLLBACK;
55490
55491 WHEN OTHERS THEN
55492 lv_error_text := substr('MSC_CL_PRE_PROCESS.LOAD_DESIGNATOR'||'('
55493 ||v_sql_stmt||')'|| SQLERRM, 1, 240);
55494 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
55495 ROLLBACK;
55496
55497 END LOAD_ITEM_CUSTOMERS;
55498
55499
55500 ----- ============== SET_IN_PROCESS ====================
55501
55502 FUNCTION SET_IN_PROCESS (p_table_name VARCHAR2,
55503 p_instance_id_col VARCHAR2 DEFAULT 'SR_INSTANCE_ID',
55504 p_company_name_col BOOLEAN DEFAULT TRUE ,
55505 p_where_str VARCHAR2 DEFAULT NULL,
55506 p_erp_enabled VARCHAR2 DEFAULT 'N')
55507
55508 RETURN NUMBER
55509 IS
55510 lv_sql_stmt VARCHAR2(1000);
55511 lv_error_text VARCHAR2(1000);
55512 ln_count NUMBER := 0;
55513 lv_message_text msc_errors.error_text%TYPE;
55514 lv_return NUMBER;
55515 lv_column_names VARCHAR2(100);
55516 ex_logging_err EXCEPTION;
55517
55518 BEGIN
55519 IF (v_instance_type <> G_INS_OTHER AND p_erp_enabled = 'N') THEN
55520 lv_column_names := 'SR_INSTANCE_CODE';
55521 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
55522 (p_app_short_name => 'MSC',
55523 p_error_code => 'MSC_ERP_INVALID_ENTITY',
55524 p_message_text => lv_message_text,
55525 p_error_text => lv_error_text,
55526 p_token1 => 'TABLE_NAME',
55527 p_token_value1 => p_table_name);
55528
55529
55530 IF lv_return <> 0 THEN
55531 RAISE ex_logging_err;
55532 END IF;
55533
55534 lv_sql_stmt :=
55535 'UPDATE '||p_table_name
55536 ||' SET error_text ='||''''||lv_message_text||''''||','
55537 ||' process_flag = '||G_ERROR_FLG
55538 ||' WHERE sr_instance_code = ' ||''''||v_instance_code||''''
55539 ||' AND process_flag = ' ||G_NEW
55540 ||p_where_str;
55541
55542
55543 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
55544
55545 EXECUTE IMMEDIATE lv_sql_stmt;
55546
55547 lv_return := MSC_ST_UTIL.LOG_ERROR
55548 (p_table_name => p_table_name,
55549 p_instance_code => v_instance_code,
55550 p_row => lv_column_names,
55551 p_severity => G_SEV_ERROR,
55552 p_message_text => NULL,
55553 p_error_text => lv_error_text,
55554 p_debug => v_debug);
55555
55556
55557 IF lv_return <> 0 THEN
55558 RAISE ex_logging_err;
55559 END IF;
55560
55561 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,lv_message_text);
55562
55563 RETURN (0);
55564
55565 END IF;
55566
55567
55568 IF p_company_name_col THEN
55569
55570 lv_sql_stmt := 'UPDATE '||p_table_name
55571 ||' SET process_flag = ' ||G_IN_PROCESS ||','
55572 || p_instance_id_col||' = 0' ||','
55573 ||' company_name = NVL(company_name,:v_my_company) ,'
55574 ||' REQUEST_ID = :request_id ,'
55575 ||' LAST_UPDATE_DATE = :current_date ,'
55576 ||' LAST_UPDATED_BY = :current_user '
55577 ||' WHERE nvl(process_flag,'||G_NEW ||') = '||G_NEW
55578 ||' AND sr_instance_code = :instance_code '
55579 ||p_where_str;
55580
55581 -- OA Self Service load changes
55582 -- If request id is not -1 or null then pre-processor is called from OA
55583
55584 IF nvl(v_parent_request_id,-1) > 0 THEN
55585 lv_sql_stmt := lv_sql_stmt ||
55586 ' AND REQUEST_ID = :parent_request_id ';
55587 ELSIF nvl(v_parent_request_id,-1) = -1 THEN
55588 lv_sql_stmt := lv_sql_stmt ||
55589 ' AND nvl(REQUEST_ID,-1) = -1 ';
55590 END IF;
55591
55592
55593 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,lv_sql_stmt);
55594
55595 IF nvl(v_parent_request_id,-1) > 0 THEN
55596 EXECUTE IMMEDIATE lv_sql_stmt USING v_my_company,v_request_id,v_current_date, v_current_user, v_instance_code, v_parent_request_id;
55597 ELSE
55598 EXECUTE IMMEDIATE lv_sql_stmt USING v_my_company,v_request_id,v_current_date, v_current_user, v_instance_code;
55599 END IF;
55600
55601
55602 ELSE
55603
55604 lv_sql_stmt := 'UPDATE '||p_table_name
55605 ||' SET process_flag = ' ||G_IN_PROCESS ||','
55606 || p_instance_id_col||' = 0' ||','
55607 ||' REQUEST_ID = :request_id ,'
55608 ||' LAST_UPDATE_DATE = :current_date ,'
55609 ||' LAST_UPDATED_BY = :current_user '
55610 ||' WHERE nvl(process_flag,'||G_NEW ||') = '||G_NEW
55611 ||' AND sr_instance_code = :instance_code '
55612 ||p_where_str;
55613
55614 -- OA Self Service load changes
55615 -- If request id is not -1 or null then pre-processor is called from OA
55616
55617 IF nvl(v_parent_request_id,-1) > 0 THEN
55618 lv_sql_stmt := lv_sql_stmt ||
55619 ' AND REQUEST_ID = :parent_request_id ';
55620 ELSIF nvl(v_parent_request_id,-1) = -1 THEN
55621 lv_sql_stmt := lv_sql_stmt ||
55622 ' AND nvl(REQUEST_ID,-1) = -1 ';
55623 END IF;
55624
55625
55626 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,lv_sql_stmt);
55627
55628 IF nvl(v_parent_request_id,-1) > 0 THEN
55629 EXECUTE IMMEDIATE lv_sql_stmt USING v_request_id,v_current_date, v_current_user, v_instance_code, v_parent_request_id;
55630 ELSE
55631 EXECUTE IMMEDIATE lv_sql_stmt USING v_request_id,v_current_date, v_current_user, v_instance_code;
55632 END IF;
55633
55634 END IF;
55635
55636 ln_count := ln_count + SQL%ROWCOUNT;
55637
55638 COMMIT;
55639 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Table Name : '||p_table_name||' - No. of Records : '||ln_count);
55640
55641 RETURN nvl(ln_count,0);
55642
55643 EXCEPTION
55644
55645 WHEN ex_logging_err THEN
55646 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
55647 ROLLBACK;
55648 RETURN 0;
55649
55650 WHEN OTHERS THEN
55651 lv_error_text := substr('MSC_CL_PRE_PROCESS.SET_IN_PROCESS- '||p_table_name||': ('||v_sql_stmt||')'|| SQLERRM, 1, 240);
55652 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
55653 ROLLBACK;
55654 RETURN 0;
55655 END SET_IN_PROCESS ;
55656
55657 -----==============Divide DP entities in batches and send task to queue-----=================
55658
55659 PROCEDURE DIVIDE_BATCHES(p_table_name VARCHAR2,
55660 p_task_name NUMBER,
55661 p_task_not_completed OUT NOCOPY NUMBER,
55662 p_pipe_status OUT NOCOPY NUMBER )
55663 IS
55664
55665 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
55666 lb_rowid RowidTab;
55667 lv_batch_id PLS_INTEGER;
55668 lv_sql_stmt VARCHAR2(4000);
55669 lv_task_not_completed NUMBER := 0;
55670 lv_message VARCHAR2(240);
55671 EX_PIPE_SND EXCEPTION ;
55672
55673 BEGIN
55674 LOOP
55675 SELECT msc_st_batch_id_s.NEXTVAL
55676 INTO lv_batch_id
55677 FROM DUAL;
55678
55679 v_sql_stmt := 01;
55680 lv_sql_stmt :=
55681 'UPDATE '||p_table_name
55682 ||' SET batch_id = :lv_batch_id '
55683 ||' WHERE process_flag IN ('||G_IN_PROCESS||','||G_ERROR_FLG||')'
55684 ||' AND sr_instance_code = :v_instance_code'
55685 ||' AND NVL(batch_id,'||NULL_VALUE||') = '||NULL_VALUE
55686 ||' AND rownum <= '||v_batch_size;
55687
55688 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
55689
55690 EXECUTE IMMEDIATE lv_sql_stmt
55691 USING lv_batch_id,
55692 v_instance_code;
55693
55694
55695 EXIT WHEN SQL%NOTFOUND ;
55696 commit;
55697
55698 lv_message := to_char(p_task_name)||','||to_char(lv_batch_id);
55699 DBMS_PIPE.PACK_MESSAGE(lv_message);
55700 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
55701 RAISE EX_PIPE_SND;
55702 END IF;
55703 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'p_task_name: '||lv_message);
55704 lv_task_not_completed := lv_task_not_completed + 1;
55705
55706
55707 END LOOP;
55708 p_task_not_completed :=lv_task_not_completed ;
55709 EXCEPTION
55710 WHEN EX_PIPE_SND THEN
55711 p_pipe_status := 1;
55712 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error in Sending message in Pipe');
55713 WHEN OTHERS THEN
55714 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error in Batch ID generation: ' || SQLERRM);
55715 lv_message := to_char(p_task_name)||','||to_char(0);
55716 DBMS_PIPE.PACK_MESSAGE(lv_message );
55717 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
55718 RAISE EX_PIPE_SND ;
55719 END IF;
55720 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'p_task_name: '||lv_message);
55721 lv_task_not_completed := lv_task_not_completed + 1;
55722 p_task_not_completed :=lv_task_not_completed ;
55723
55724
55725 END DIVIDE_BATCHES;
55726
55727
55728
55729 -- ==============SNAPSHOT_TABLES ============
55730 -- Snapshot is done by setting the process flag
55731 -- of all the tables to G_IN_PROCESS
55732
55733 FUNCTION SNAPSHOT_TABLES RETURN BOOLEAN IS
55734 lv_error_text VARCHAR2(1000);
55735 lv_count PLS_INTEGER;
55736 BEGIN
55737 --- ===== Enter the ASCP tables to be set here ======
55738
55739 IF v_mat_dmd_enabled = SYS_YES OR v_iro_enabled = SYS_YES or v_ero_enabled = SYS_YES THEN
55740 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_DEMANDS', p_erp_enabled => 'Y');
55741 IF lv_count > 0 Then
55742 prec.mds_flag:= SYS_YES;
55743 prec.forecast_flag:= SYS_YES;
55744 prec.wip_flag:= SYS_YES;
55745 prec.internal_repair_flag:=SYS_YES;
55746 prec.external_repair_flag:=SYS_YES;
55747 End IF;
55748 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_SALES_ORDERS ',p_erp_enabled => 'Y');
55749 IF lv_count > 0 Then
55750 prec.sales_order_flag:= SYS_YES;
55751 End IF;
55752 END IF;
55753
55754 IF v_reserve_enabled = SYS_YES THEN
55755 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_RESERVATIONS');
55756 IF lv_count > 0 Then
55757 prec.reserves_flag:= SYS_YES;
55758 End IF;
55759 END IF;
55760
55761 IF v_mat_sup_enabled = SYS_YES OR v_iro_enabled = SYS_YES or v_ero_enabled = SYS_YES
55762 THEN
55763 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_SUPPLIES',p_erp_enabled => 'Y');
55764 IF lv_count > 0 Then
55765 prec.oh_flag:= SYS_YES;
55766 prec.po_flag:= SYS_YES;
55767 prec.mps_flag:= SYS_YES;
55768 prec.wip_flag:= SYS_YES;
55769 prec.internal_repair_flag:=SYS_YES;
55770 prec.external_repair_flag:=SYS_YES;
55771 prec.ret_fcst_flag:=SYS_YES;--13839374 returns forecast proj
55772 End IF;
55773
55774 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_JOB_OPERATION_NETWORKS');
55775 IF lv_count > 0 Then
55776 prec.wip_flag:= SYS_YES;
55777 End IF;
55778 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_JOB_OPERATIONS');
55779 IF lv_count > 0 Then
55780 prec.wip_flag:= SYS_YES;
55781 End IF;
55782 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_JOB_REQUIREMENT_OPS');
55783 IF lv_count > 0 Then
55784 prec.wip_flag:= SYS_YES;
55785 End IF;
55786 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_JOB_OP_RESOURCES');
55787 IF lv_count > 0 Then
55788 prec.wip_flag:= SYS_YES;
55789 End IF;
55790 END IF;
55791
55792 IF v_desig_enabled = SYS_YES THEN
55793 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_DESIGNATORS',p_erp_enabled => 'Y');
55794 IF lv_count > 0 Then
55795 prec.mds_flag:= SYS_YES;
55796 prec.forecast_flag:= SYS_YES;
55797 prec.mps_flag:= SYS_YES;
55798 End IF;
55799 END IF;
55800
55801 IF v_sourcing_enabled = SYS_YES THEN
55802 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_ITEM_SOURCING');
55803 IF lv_count > 0 Then
55804 prec.sourcing_rule_flag:= SYS_YES;
55805 End IF;
55806 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_REGIONS');
55807 IF lv_count > 0 Then
55808 prec.sourcing_rule_flag:= SYS_YES;
55809 End IF;
55810 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_ZONE_REGIONS');
55811 IF lv_count > 0 Then
55812 prec.sourcing_rule_flag:= SYS_YES;
55813 End IF;
55814 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_REGION_SITES');
55815 IF lv_count > 0 Then
55816 prec.sourcing_rule_flag:= SYS_YES;
55817 End IF;
55818 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_REGION_LOCATIONS');
55819 IF lv_count > 0 Then
55820 prec.sourcing_rule_flag:= SYS_YES;
55821 End IF;
55822 END IF;
55823
55824 IF v_ship_mthd_enabled = SYS_YES THEN
55825 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_INTERORG_SHIP_METHODS');
55826 IF lv_count > 0 Then
55827 prec.sourcing_rule_flag:= SYS_YES;
55828 End IF;
55829 END IF;
55830
55831 IF v_bom_enabled = SYS_YES THEN
55832 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_COMPONENT_SUBSTITUTES');
55833 IF lv_count > 0 Then
55834 prec.bom_flag:= SYS_YES;
55835 End IF;
55836 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_BOM_COMPONENTS');
55837 IF lv_count > 0 Then
55838 prec.bom_flag:= SYS_YES;
55839 End IF;
55840 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_BOMS');
55841 IF lv_count > 0 Then
55842 prec.bom_flag:= SYS_YES;
55843 End IF;
55844 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_CO_PRODUCTS');
55845 IF lv_count > 0 Then
55846 prec.bom_flag:= SYS_YES;
55847 End IF;
55848 END IF;
55849
55850 IF v_cal_enabled = SYS_YES THEN
55851 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_CALENDARS');
55852 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_WORKDAY_PATTERNS');
55853 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_CALENDAR_SHIFTS');
55854 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_SHIFT_TIMES');
55855 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_SHIFT_EXCEPTIONS');
55856 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_CALENDAR_EXCEPTIONS');
55857 END IF;
55858
55859 IF v_rtg_enabled = SYS_YES THEN
55860 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_OPERATION_RESOURCES');
55861 IF lv_count > 0 Then
55862 prec.bom_flag:= SYS_YES;
55863 End IF;
55864 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_ROUTING_OPERATIONS');
55865 IF lv_count > 0 Then
55866 prec.bom_flag:= SYS_YES;
55867 End IF;
55868 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_ROUTINGS');
55869 IF lv_count > 0 Then
55870 prec.bom_flag:= SYS_YES;
55871 End IF;
55872 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_OPERATION_NETWORKS');
55873 IF lv_count > 0 Then
55874 prec.bom_flag:= SYS_YES;
55875 End IF;
55876 END IF;
55877
55878 IF v_res_dmd_enabled = SYS_YES THEN
55879 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_RESOURCE_REQUIREMENTS',p_erp_enabled => 'Y'); /* bug 3768813 */
55880 IF lv_count > 0 Then
55881 prec.wip_flag:= SYS_YES;
55882 End IF;
55883 END IF;
55884
55885 IF v_resources_enabled = SYS_YES THEN
55886 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_RESOURCE_GROUPS');
55887 IF lv_count > 0 Then
55888 prec.bom_flag:= SYS_YES;
55889 End IF;
55890 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_DEPARTMENT_RESOURCES');
55891 IF lv_count > 0 Then
55892 prec.bom_flag:= SYS_YES;
55893 End IF;
55894 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_RESOURCE_SETUPS');
55895 IF lv_count > 0 Then
55896 prec.bom_flag:= SYS_YES;
55897 End IF;
55898 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_SETUP_TRANSITIONS');
55899 IF lv_count > 0 Then
55900 prec.bom_flag:= SYS_YES;
55901 End IF;
55902 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_RESOURCE_SHIFTS');
55903 IF lv_count > 0 Then
55904 prec.bom_flag:= SYS_YES;
55905 prec.calendar_flag:=SYS_YES;
55906 End IF;
55907 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_RESOURCE_CHANGES');
55908 IF lv_count > 0 Then
55909 prec.bom_flag:= SYS_YES;
55910 prec.calendar_flag:=SYS_YES;
55911 End IF;
55912 END IF;
55913
55914 IF v_tp_enabled = SYS_YES THEN
55915 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_LOCATION_ASSOCIATIONS');
55916 IF lv_count > 0 Then
55917 prec.tp_customer_flag:= SYS_YES;
55918 prec.tp_vendor_flag:= SYS_YES;
55919 End IF;
55920 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_TRADING_PARTNER_SITES');
55921 IF lv_count > 0 Then
55922 prec.tp_customer_flag:= SYS_YES;
55923 prec.tp_vendor_flag:= SYS_YES;
55924 End IF;
55925 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_PARTNER_CONTACTS');
55926 IF lv_count > 0 Then
55927 prec.tp_customer_flag:= SYS_YES;
55928 prec.tp_vendor_flag:= SYS_YES;
55929 End IF;
55930 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_TRADING_PARTNERS');
55931 IF lv_count > 0 Then
55932 prec.tp_customer_flag:= SYS_YES;
55933 prec.tp_vendor_flag:= SYS_YES;
55934 prec.sourcing_rule_flag:= SYS_YES;
55935 End IF;
55936 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_SUB_INVENTORIES');
55937 IF lv_count > 0 Then
55938 prec.sub_inventory_flag:= SYS_YES;
55939 End IF;
55940 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_GROUPS',p_company_name_col => FALSE);
55941 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_GROUP_COMPANIES');
55942 END IF;
55943
55944 IF v_dmd_class_enabled = SYS_YES THEN
55945 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_DEMAND_CLASSES');
55946 IF lv_count > 0 Then
55947 prec.demand_class_flag:= SYS_YES;
55948 End IF;
55949 END IF;
55950
55951 IF v_sup_cap_enabled = SYS_YES THEN
55952 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_ITEM_SUPPLIERS');
55953 IF lv_count > 0 Then
55954 prec.app_supp_cap_flag:= SYS_YES;
55955 End IF;
55956 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_SUPPLIER_CAPACITIES', p_erp_enabled => 'Y');
55957 IF lv_count > 0 Then
55958 prec.app_supp_cap_flag:= SYS_YES;
55959 End IF;
55960 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_SUPPLIER_FLEX_FENCES', p_erp_enabled => 'Y');
55961 IF lv_count > 0 Then
55962 prec.app_supp_cap_flag:= SYS_YES;
55963 End IF;
55964 END IF;
55965
55966 IF v_item_cst_enabled = SYS_YES THEN
55967 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_ITEM_CUSTOMERS');
55968 END IF;
55969
55970 IF v_safety_stk_enabled = SYS_YES THEN
55971 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_SAFETY_STOCKS');
55972 IF lv_count > 0 Then
55973 prec.saf_stock_flag:= SYS_YES;
55974 End IF;
55975 END IF;
55976
55977 IF v_project_enabled = SYS_YES THEN
55978 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_PROJECT_TASKS');
55979 IF lv_count > 0 Then
55980 prec.project_flag:= SYS_YES;
55981 End IF;
55982 END IF;
55983
55984 IF v_uom_enabled = SYS_YES THEN
55985 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_UNITS_OF_MEASURE');
55986 IF lv_count > 0 Then
55987 prec.uom_flag:= SYS_YES;
55988 End IF;
55989 END IF;
55990
55991 IF v_uom_class_enabled = SYS_YES THEN
55992 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_UOM_CLASS_CONVERSIONS');
55993 IF lv_count > 0 Then
55994 prec.uom_flag:= SYS_YES;
55995 End IF;
55996 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_UOM_CONVERSIONS');
55997 IF lv_count > 0 Then
55998 prec.uom_flag:= SYS_YES;
55999 End IF;
56000 END IF;
56001
56002 IF v_ctg_enabled = SYS_YES THEN
56003 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_CATEGORY_SETS');
56004 IF lv_count > 0 Then
56005 prec.item_flag:= SYS_YES;
56006 End IF;
56007 END IF;
56008
56009 IF v_item_cat_enabled = SYS_YES THEN
56010 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_ITEM_CATEGORIES');
56011 IF lv_count > 0 Then
56012 prec.item_flag:= SYS_YES;
56013 End IF;
56014 END IF;
56015
56016 IF v_item_enabled = SYS_YES THEN
56017 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_SYSTEM_ITEMS');
56018 IF lv_count > 0 Then
56019 prec.item_flag:= SYS_YES;
56020 End IF;
56021 END IF;
56022
56023 IF v_comp_users_enabled = SYS_YES THEN
56024 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_COMPANY_USERS');
56025 IF lv_count > 0 Then
56026 prec.user_company_flag:= G_COMP_USR_YES;
56027 End IF;
56028 END IF;
56029
56030 -- Product Item Substitute
56031
56032 IF v_item_substitute_enabled = SYS_YES THEN
56033 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_ITEM_SUBSTITUTES');
56034 IF lv_count > 0 Then
56035 prec.item_subst_flag:= SYS_YES;
56036 End IF;
56037 END IF;
56038
56039 IF v_planners_enabled = SYS_YES THEN
56040 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_PLANNERS');
56041 IF lv_count > 0 Then
56042 prec.planner_flag:= SYS_YES;
56043 End IF;
56044 END IF;
56045
56046 -- Profile Values
56047
56048 IF v_profile_enabled = SYS_YES THEN
56049 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_APPS_INSTANCES', p_company_name_col => FALSE);
56050 END IF;
56051
56052 IF v_cal_assignment_enabled = SYS_YES THEN
56053 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_CALENDAR_ASSIGNMENTS');
56054 IF lv_count > 0 Then
56055 prec.calendar_flag:=SYS_YES;
56056 End IF;
56057 END IF;
56058
56059 IF v_sales_channel_enabled = SYS_YES THEN
56060 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_SR_LOOKUPS');
56061 IF lv_count > 0 Then
56062 prec.sales_channel_flag:= SYS_YES;
56063 End IF;
56064 END IF;
56065
56066 IF v_fiscal_calendar_enabled = SYS_YES THEN
56067 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_CALENDAR_MONTHS', p_company_name_col => FALSE);
56068 IF lv_count > 0 Then
56069 prec.fiscal_calendar_flag:= SYS_YES;
56070 End IF;
56071 END IF;
56072
56073 IF v_CMRO_enabled = SYS_YES THEN
56074 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_VISITS', p_company_name_col => FALSE, p_erp_enabled => 'Y');
56075 IF lv_count > 0 Then
56076 prec.CMRO_flag:= SYS_YES;
56077 End IF;
56078
56079 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_WO_MILESTONES', p_company_name_col => FALSE, p_erp_enabled => 'Y');
56080 IF lv_count > 0 Then
56081 prec.CMRO_flag:= SYS_YES;
56082 End IF;
56083
56084 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_WO_ATTRIBUTES', p_company_name_col => FALSE, p_erp_enabled => 'Y');
56085 IF lv_count > 0 Then
56086 prec.CMRO_flag:= SYS_YES;
56087 End IF;
56088
56089 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_WORK_BREAKDOWN_STRUCT', p_company_name_col => FALSE, p_erp_enabled => 'Y');
56090 IF lv_count > 0 Then
56091 prec.CMRO_flag:= SYS_YES;
56092 End IF;
56093
56094 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_WO_OPERATION_REL', p_company_name_col => FALSE, p_erp_enabled => 'Y');
56095 IF lv_count > 0 Then
56096 prec.CMRO_flag:= SYS_YES;
56097 End IF;
56098
56099 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_WO_TASK_HIERARCHY', p_company_name_col => FALSE, p_erp_enabled => 'Y');
56100 IF lv_count > 0 Then
56101 prec.CMRO_flag:= SYS_YES;
56102 End IF;
56103
56104 END IF;
56105
56106
56107 --- ===== Enter the DP tables to be set here ======
56108
56109 IF v_fiscal_cal_enabled = SYS_YES THEN
56110 lv_count:= SET_IN_PROCESS (p_table_name => 'MSD_ST_TIME',p_instance_id_col => 'INSTANCE',p_company_name_col => FALSE, p_where_str => ' AND CALENDAR_TYPE <> '||G_COMPOSITE_CAL );
56111 IF lv_count = 0 Then
56112 v_fiscal_cal_enabled:= SYS_NO;
56113 End IF;
56114 END IF;
56115
56116
56117 IF v_comp_cal_enabled = SYS_YES THEN
56118 lv_count:= SET_IN_PROCESS (p_table_name => 'MSD_ST_TIME',p_instance_id_col => 'INSTANCE',p_company_name_col => FALSE,p_where_str => ' AND CALENDAR_TYPE <> '||G_FISCAL_CAL, p_erp_enabled => 'Y' );
56119 IF lv_count = 0 Then
56120 v_comp_cal_enabled:= SYS_NO;
56121 End IF;
56122 END IF;
56123
56124
56125
56126 IF v_setup_enabled = SYS_YES THEN
56127 lv_count:= SET_IN_PROCESS (p_table_name => 'MSD_ST_SETUP_PARAMETERS',p_instance_id_col => 'INSTANCE',p_company_name_col => FALSE,p_erp_enabled => 'Y');
56128 IF lv_count = 0 Then
56129 v_setup_enabled:= SYS_NO;
56130 End IF;
56131 END IF;
56132
56133 IF v_level_value_enabled = SYS_YES THEN
56134 lv_count:= SET_IN_PROCESS (p_table_name => 'MSD_ST_LEVEL_VALUES',p_instance_id_col => 'INSTANCE',p_company_name_col => FALSE, p_erp_enabled => 'Y');
56135 lv_count:= SET_IN_PROCESS (p_table_name => 'MSD_ST_LEVEL_ORG_ASSCNS',p_instance_id_col => 'INSTANCE',p_company_name_col => FALSE, p_erp_enabled => 'Y');
56136 lv_count:= SET_IN_PROCESS (p_table_name => 'MSD_ST_ITEM_RELATIONSHIPS',p_instance_id_col => 'INSTANCE_ID',p_company_name_col => FALSE, p_erp_enabled => 'Y');
56137 /*
56138 IF lv_count = 0 Then
56139 v_level_value_enabled:= SYS_NO;
56140 End IF;
56141 */
56142 END IF;
56143
56144 IF v_level_assoc_enabled = SYS_YES THEN
56145 lv_count:= SET_IN_PROCESS (p_table_name => 'MSD_ST_LEVEL_ASSOCIATIONS',p_instance_id_col => 'INSTANCE',p_company_name_col => FALSE, p_erp_enabled => 'Y');
56146 END IF;
56147
56148 IF v_booking_enabled = SYS_YES THEN
56149 lv_count:= SET_IN_PROCESS (p_table_name => 'MSD_ST_BOOKING_DATA',p_instance_id_col => 'INSTANCE',p_company_name_col => FALSE, p_erp_enabled => 'Y');
56150 IF lv_count = 0 Then
56151 v_booking_enabled:= SYS_NO;
56152 End IF;
56153 END IF;
56154
56155 IF v_shipment_enabled = SYS_YES THEN
56156 lv_count:= SET_IN_PROCESS (p_table_name => 'MSD_ST_SHIPMENT_DATA',p_instance_id_col => 'INSTANCE',p_company_name_col => FALSE, p_erp_enabled => 'Y');
56157 IF lv_count = 0 Then
56158 v_shipment_enabled:= SYS_NO;
56159 End IF;
56160 END IF;
56161
56162 IF v_mfg_fct_enabled = SYS_YES THEN
56163 lv_count:= SET_IN_PROCESS (p_table_name => 'MSD_ST_MFG_FORECAST',p_instance_id_col => 'INSTANCE',p_company_name_col => FALSE, p_erp_enabled => 'Y');
56164 IF lv_count = 0 Then
56165 v_mfg_fct_enabled:= SYS_NO;
56166 End IF;
56167 END IF;
56168
56169 IF v_list_price_enabled = SYS_YES THEN
56170 -- lv_count:= SET_IN_PROCESS (p_table_name => 'MSD_ST_ITEM_LIST_PRICE',p_instance_id_col => 'INSTANCE');
56171 lv_count:= SET_IN_PROCESS (p_table_name => 'MSD_ST_PRICE_LIST',p_instance_id_col => 'INSTANCE',p_company_name_col => FALSE, p_erp_enabled => 'Y');
56172 IF lv_count = 0 Then
56173 v_list_price_enabled:= SYS_NO;
56174 End IF;
56175 END IF;
56176
56177 IF v_cs_data_enabled = SYS_YES THEN
56178 lv_count:= SET_IN_PROCESS (p_table_name => 'MSD_ST_CS_DATA',p_instance_id_col => 'ATTRIBUTE_1',p_company_name_col => FALSE, p_erp_enabled => 'Y');
56179 IF lv_count = 0 Then
56180 v_cs_data_enabled:= SYS_NO;
56181 End IF;
56182 END IF;
56183
56184 IF v_curr_conv_enabled = SYS_YES THEN
56185 lv_count:= SET_IN_PROCESS (p_table_name => 'MSD_ST_CURRENCY_CONVERSIONS',p_instance_id_col => 'INSTANCE',p_company_name_col => FALSE);
56186 IF lv_count = 0 Then
56187 v_curr_conv_enabled:= SYS_NO;
56188 End IF;
56189 END IF;
56190
56191 IF v_uom_conv_enabled = SYS_YES THEN
56192 lv_count:= SET_IN_PROCESS (p_table_name => 'MSD_ST_UOM_CONVERSIONS',p_instance_id_col => 'INSTANCE',p_company_name_col => FALSE, p_erp_enabled => 'Y'); --Enabling DP UOM conversions for ERP Instances - Bug 3752937
56193 IF lv_count = 0 Then
56194 v_uom_conv_enabled:= SYS_NO;
56195 End IF;
56196 END IF;
56197
56198
56199
56200 --- ===== END entering the tables here =========
56201 COMMIT; -- close current transaction
56202 RETURN (TRUE);
56203
56204 EXCEPTION
56205 WHEN OTHERS THEN
56206 lv_error_text := substr('MSC_CL_PRE_PROCESS.SNAPSHOT_TABLES - '|| SQLERRM, 1, 240);
56207 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,lv_error_text);
56208 return(FALSE);
56209
56210 END SNAPSHOT_TABLES ;
56211
56212 -- ========= EXECUTE_TASK ==========
56213
56214 PROCEDURE EXECUTE_TASK( p_status OUT NOCOPY NUMBER,
56215 p_tasknum IN NUMBER,
56216 p_batch_id IN NUMBER DEFAULT -1 )
56217
56218 IS
56219
56220 lv_task_start_time DATE;
56221
56222 BEGIN
56223 lv_task_start_time:= SYSDATE;
56224
56225 SAVEPOINT ExecuteTask;
56226
56227 p_status := FAIL;
56228
56229 -- ============= Execute the task according to its task number ===========
56230
56231 IF p_tasknum= TASK_SUPPLIER_CAPACITY THEN
56232
56233 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56234 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_SUPPLIER_CAPACITY');
56235 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56236 LOAD_SUPPLIER_CAPACITY;
56237
56238 ELSIF p_tasknum= TASK_SAFETY_STOCK THEN
56239
56240 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56241 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_SAFETY_STOCKS');
56242 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56243 LOAD_SAFETY_STOCK;
56244
56245 ELSIF p_tasknum= TASK_BIS_PERIODS THEN
56246
56247 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56248 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_BIS_PERIODS');
56249 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56250 LOAD_BIS_PERIODS;
56251
56252 ELSIF p_tasknum= TASK_UOM_CONV THEN
56253
56254 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56255 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_UOM_CLASS_CONV');
56256 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56257 LOAD_UOM_CLASS_CONV;
56258
56259 ELSIF p_tasknum= TASK_ITEM THEN
56260
56261 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56262 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_ITEM');
56263 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56264 LOAD_ITEM(p_batch_id);
56265
56266 -- Product Item Substitute
56267
56268 ELSIF p_tasknum= TASK_ITEM_SUBSTITUTE THEN
56269 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56270 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_ITEM_SUBSTITUTE');
56271 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56272 LOAD_ITEM_SUBSTITUTE;
56273
56274
56275 ELSIF p_tasknum= TASK_CATEGORIES_SOURCING THEN
56276
56277 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56278 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_CATEGORIES_SOURCING');
56279 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56280 LOAD_CATEGORIES_SOURCING;
56281
56282 ELSIF p_tasknum= TASK_DEPT_RESOURCES THEN
56283
56284 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56285 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_DEPT_RESOURCES');
56286 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56287 LOAD_DEPT_RESOURCES;
56288 LOAD_RESOURCE_SETUPS;
56289 LOAD_SETUP_TRANSITIONS;
56290 ELSIF p_tasknum= TASK_MATERIAL_SUPPLY THEN
56291
56292 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56293 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_MATERIAL_SUPPLY');
56294 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56295 LOAD_MATERIAL_SUPPLY(p_batch_id);
56296
56297 ELSIF p_tasknum= TASK_MATERIAL_DEMAND THEN
56298
56299 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56300 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_MATERIAL_DEMAND');
56301 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56302 LOAD_MATERIAL_DEMAND(p_batch_id);
56303
56304 ELSIF p_tasknum= TASK_BOM_ROUTING THEN
56305
56306 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56307 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_BOM_ROUTING');
56308 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56309 LOAD_BOM_ROUTING;
56310
56311 ELSIF p_tasknum= TASK_RESOURCE_DEMAND THEN
56312
56313 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56314 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_RESOURCE_DEMAND');
56315 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56316 LOAD_RESOURCE_DEMAND;
56317
56318 ELSIF p_tasknum= TASK_SO_DEMAND THEN
56319
56320 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56321 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_SO_DEMAND');
56322 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56323 LOAD_SO_DEMAND(p_batch_id);
56324
56325
56326 ELSIF p_tasknum= TASK_RESERVATION THEN
56327
56328 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56329 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_RESERVATION');
56330 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56331 LOAD_RESERVATION;
56332
56333 ELSIF p_tasknum= TASK_ITEM_CST THEN
56334
56335 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56336 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_ITEM_CST');
56337 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56338 LOAD_ITEM_CST;
56339
56340 ELSIF p_tasknum= TASK_LEVEL_VALUE THEN
56341 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56342 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_LEVEL_VALUE');
56343 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56344 LOAD_LEVEL_VALUE(p_batch_id);
56345
56346 ELSIF p_tasknum= TASK_LEVEL_ASSOCIATION THEN
56347 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56348 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_LEVEL_ASSOCIATION');
56349 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56350 LOAD_LEVEL_ASSOCIATION(p_batch_id);
56351
56352 ELSIF p_tasknum= TASK_BOOKING_DATA THEN
56353 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56354 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_BOOKING_DATA');
56355 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56356 LOAD_BOOKING_DATA(p_batch_id);
56357
56358 ELSIF p_tasknum= TASK_SHIPMENT_DATA THEN
56359 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56360 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_SHIPMENT_DATA');
56361 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56362 LOAD_SHIPMENT_DATA(p_batch_id);
56363
56364 ELSIF p_tasknum= TASK_MFG_FORECAST THEN
56365 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56366 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_MFG_FORECAST');
56367 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56368 LOAD_MFG_FORECAST(p_batch_id);
56369
56370 ELSIF p_tasknum= TASK_PRICE_LIST THEN
56371 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56372 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_PRICE_LIST');
56373 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56374 LOAD_PRICE_LIST(p_batch_id);
56375 /*
56376 ELSIF p_tasknum= TASK_ITEM_LIST_PRICE THEN
56377 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56378 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_ITEM_LIST_PRICE');
56379 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56380 LOAD_ITEM_LIST_PRICE(p_batch_id);
56381 */
56382 ELSIF p_tasknum= TASK_CS_DATA THEN
56383 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56384 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_CS_DATA');
56385 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56386 LOAD_CS_DATA(p_batch_id);
56387
56388 ELSIF p_tasknum= TASK_CURR_CONV THEN
56389 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56390 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_CURR_CONV');
56391 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56392 LOAD_CURR_CONV(p_batch_id);
56393
56394 ELSIF p_tasknum= TASK_DP_UOM_CONV THEN
56395 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56396 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_UOM_CONV');
56397 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56398 LOAD_UOM_CONV(p_batch_id);
56399
56400 ELSIF p_tasknum= TASK_FISCAL_TIME THEN
56401 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56402 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_FISCAL_TIME');
56403 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56404 LOAD_FISCAL_TIME;
56405
56406 ELSIF p_tasknum= TASK_COMPOSITE_TIME THEN
56407 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56408 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_COMPOSITE_TIME');
56409 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56410 LOAD_COMPOSITE_TIME;
56411
56412
56413 ELSIF p_tasknum= TASK_COMPANY_USERS THEN
56414 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56415 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'TASK_COMPANY_USERS');
56416 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56417 LOAD_COMPANY_USER;
56418
56419 ELSIF p_tasknum= TASK_CAL_ASSIGNMENTS THEN
56420 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56421 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_CAL_ASSIGNMENTS');
56422 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56423 LOAD_CAL_ASSIGNMENTS;
56424
56425 ELSIF p_tasknum= TASK_IRO THEN
56426 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56427 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_IRO_SUPPLY_DEMAND');
56428 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56429 LOAD_IRO_SUPPLY_DEMAND;
56430
56431 ELSIF p_tasknum= TASK_ERO THEN
56432 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56433 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_ERO_SUPPLY_DEMAND');
56434 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56435 LOAD_ERO_SUPPLY_DEMAND;
56436
56437 ELSIF p_tasknum= TASK_SALES_CHANNEL THEN
56438 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56439 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_SALES_CHNL');
56440 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56441 LOAD_SALES_CHNL;
56442
56443 ELSIF p_tasknum= TASK_FISCAL_CALENDAR THEN
56444 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56445 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_FISCAL');
56446 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56447 LOAD_FISCAL;
56448
56449 ELSIF p_tasknum= TASK_CMRO THEN
56450 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_TASK_START');
56451 FND_MESSAGE.SET_TOKEN('PROCEDURE', 'LOAD_CMRO');
56452 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56453 LOAD_CMRO;
56454
56455 END IF;
56456
56457 -- ======== If no EXCEPTION occurs, then returns with status = OK =========
56458
56459 p_status := OK;
56460
56461 FND_MESSAGE.SET_NAME('MSC', 'MSC_ELAPSED_TIME');
56462 FND_MESSAGE.SET_TOKEN('ELAPSED_TIME',
56463 TO_CHAR(CEIL((SYSDATE- lv_task_start_time)*14400.0)/10));
56464 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
56465
56466 EXCEPTION
56467
56468 WHEN others THEN
56469
56470 -- ============= Raise the EXCEPTION ==============
56471
56472 ROLLBACK WORK TO SAVEPOINT ExecuteTask;
56473
56474 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,SQLERRM);
56475
56476 RAISE;
56477
56478 END EXECUTE_TASK;
56479
56480 -- ============ Load Procedures ==============================
56481
56482 PROCEDURE LOAD_ITEM(p_batch_id NUMBER)
56483 IS
56484 BEGIN
56485 -- items
56486 IF v_item_enabled = SYS_YES and p_batch_id <> 0 THEN
56487 LOAD_ITEMS(p_batch_id);
56488 END IF;
56489 END LOAD_ITEM;
56490
56491 -- Product item substitute
56492
56493 PROCEDURE LOAD_ITEM_SUBSTITUTE
56494 IS
56495 BEGIN
56496 -- items
56497 IF v_item_substitute_enabled = SYS_YES THEN
56498 LOAD_ITEM_SUBSTITUTES;
56499 END IF;
56500 END LOAD_ITEM_SUBSTITUTE;
56501
56502
56503 PROCEDURE LOAD_SUPPLIER_CAPACITY
56504 IS
56505 BEGIN
56506 -- supplier capacity
56507 IF v_sup_cap_enabled = SYS_YES THEN
56508 LOAD_SUPP_CAPACITY;
56509 END IF;
56510 END LOAD_SUPPLIER_CAPACITY;
56511
56512 PROCEDURE LOAD_SAFETY_STOCK
56513 IS
56514 BEGIN
56515 -- safety stocks
56516 IF v_safety_stk_enabled = SYS_YES THEN
56517 LOAD_SAFETY_STOCKS;
56518 END IF;
56519 END LOAD_SAFETY_STOCK;
56520
56521 PROCEDURE LOAD_CATEGORIES_SOURCING
56522 IS
56523 BEGIN
56524 -- categories
56525 IF v_item_cat_enabled = SYS_YES THEN
56526 LOAD_CATEGORY;
56527 END IF;
56528 -- Inter-org ship methods
56529 IF v_ship_mthd_enabled = SYS_YES THEN
56530 LOAD_SHIP_METHODS;
56531 END IF;
56532
56533 -- sourcing
56534 IF v_sourcing_enabled = SYS_YES THEN
56535 LOAD_SOURCING_RULE;
56536 LOAD_REGIONS;
56537 END IF;
56538 END LOAD_CATEGORIES_SOURCING;
56539
56540 PROCEDURE LOAD_DEPT_RESOURCES
56541 IS
56542 BEGIN
56543 -- dept and resources
56544 IF v_resources_enabled = SYS_YES THEN
56545 LOAD_DEPT_RES;
56546 END IF;
56547 END LOAD_DEPT_RESOURCES;
56548
56549 PROCEDURE LOAD_MATERIAL_SUPPLY(p_batch_id NUMBER)
56550 IS
56551 BEGIN
56552 -- Material Supply ( PO, Intransit, On Hand, MPS, Requisitions)
56553 IF v_mat_sup_enabled = SYS_YES THEN
56554 LOAD_SUPPLY(p_batch_id);
56555 END IF;
56556 END LOAD_MATERIAL_SUPPLY;
56557
56558 PROCEDURE LOAD_MATERIAL_DEMAND(p_batch_id NUMBER)
56559 IS
56560 BEGIN
56561 -- Material Demand (forecast amd MDS)
56562 IF v_mat_dmd_enabled = SYS_YES THEN
56563 LOAD_MDS_FORECAST (p_batch_id);
56564 END IF;
56565 END LOAD_MATERIAL_DEMAND;
56566
56567 PROCEDURE LOAD_SO_DEMAND(p_batch_id NUMBER)
56568 IS
56569 BEGIN
56570 -- Material Demand (sales orders)
56571 IF v_mat_dmd_enabled = SYS_YES THEN
56572 LOAD_SALES_ORDER ( p_batch_id);
56573 END IF;
56574 END LOAD_SO_DEMAND;
56575
56576 PROCEDURE LOAD_RESERVATION
56577 IS
56578 BEGIN
56579 -- Hard Reservations
56580 IF v_reserve_enabled = SYS_YES THEN
56581 LOAD_RESERVATIONS;
56582 END IF;
56583 END LOAD_RESERVATION ;
56584
56585 PROCEDURE LOAD_COMPANY_USER
56586 IS
56587 BEGIN
56588
56589 IF v_comp_users_enabled = SYS_YES THEN
56590 LOAD_COMPANY_USERS;
56591 END IF;
56592 END LOAD_COMPANY_USER;
56593
56594 PROCEDURE LOAD_BOM_ROUTING
56595 IS
56596 BEGIN
56597 -- bom
56598 IF v_bom_enabled = SYS_YES THEN
56599 LOAD_BOM;
56600 END IF;
56601 -- routing
56602 IF v_rtg_enabled = SYS_YES THEN
56603 LOAD_ROUTING;
56604 END IF;
56605 -- process effectivity
56606 IF v_rtg_enabled = SYS_YES OR v_bom_enabled = SYS_YES THEN
56607 LOAD_PROCESS_EFFECTIVITY;
56608 END IF;
56609 END LOAD_BOM_ROUTING;
56610
56611 PROCEDURE LOAD_RESOURCE_DEMAND
56612 IS
56613
56614 BEGIN
56615 -- material supply WO
56616 IF v_mat_sup_enabled = SYS_YES THEN
56617 LOAD_WO_SUPPLY;
56618 END IF;
56619 -- material demand WO
56620 IF v_mat_dmd_enabled = SYS_YES THEN
56621 LOAD_WIP_DEMAND;
56622 END IF;
56623 -- resource demand
56624 IF v_res_dmd_enabled = SYS_YES THEN
56625 LOAD_RES_DEMAND;
56626 END IF;
56627 -- osfm job details
56628 IF v_mat_sup_enabled = SYS_YES THEN
56629 LOAD_JOB_DETAILS;
56630 END IF;
56631 END LOAD_RESOURCE_DEMAND;
56632
56633 PROCEDURE LOAD_ITEM_CST
56634 IS
56635 BEGIN
56636 LOAD_ITEM_CUSTOMERS;
56637 END LOAD_ITEM_CST;
56638
56639 PROCEDURE LOAD_CAL_ASSIGNMENTS
56640 IS
56641 BEGIN
56642 -- calendar assignment
56643 IF v_cal_assignment_enabled = SYS_YES THEN
56644 LOAD_CALENDAR_ASSIGNMENTS;
56645 END IF;
56646 END LOAD_CAL_ASSIGNMENTS;
56647
56648 PROCEDURE LOAD_IRO_SUPPLY_DEMAND
56649 IS
56650 BEGIN
56651 IF v_iro_enabled = SYS_YES THEN
56652 MSC_CL_RPO_PRE_PROCESS.LOAD_IRO_SUPPLY;
56653 MSC_CL_RPO_PRE_PROCESS.LOAD_IRO_DEMAND;
56654 END IF;
56655 END LOAD_IRO_SUPPLY_DEMAND;
56656
56657 PROCEDURE LOAD_ERO_SUPPLY_DEMAND
56658 IS
56659 BEGIN
56660 IF v_ero_enabled = SYS_YES THEN
56661 MSC_CL_RPO_PRE_PROCESS.LOAD_ERO_SUPPLY;
56662 MSC_CL_RPO_PRE_PROCESS.LOAD_ERO_DEMAND;
56663 END IF;
56664 END LOAD_ERO_SUPPLY_DEMAND;
56665
56666 PROCEDURE LOAD_SALES_CHNL
56667 IS
56668 BEGIN
56669 IF v_sales_channel_enabled = SYS_YES THEN
56670 LOAD_SALES_CHANNEL;
56671 END IF;
56672 END LOAD_SALES_CHNL;
56673
56674 PROCEDURE LOAD_FISCAL
56675 IS
56676 BEGIN
56677 IF v_fiscal_calendar_enabled = SYS_YES THEN
56678 LOAD_FISCAL_CALENDAR;
56679 END IF;
56680 END LOAD_FISCAL;
56681
56682 PROCEDURE LOAD_CMRO
56683 IS
56684 BEGIN
56685 IF v_CMRO_enabled = SYS_YES THEN
56686
56687 LOAD_VISITS;
56688 LOAD_MILESTONES;
56689 LOAD_WBS;
56690 LOAD_WOATTRIBUTES;
56691 LOAD_WO_TASK_HIERARCHY;
56692 LOAD_WO_OPERATION_REL;
56693 END IF;
56694 END LOAD_CMRO;
56695
56696
56697 ---------------------- Added for the bug fix 2191021 -------------------------------------
56698 PROCEDURE LOAD_ITEM_ABC_CLASSES
56699 IS
56700
56701 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
56702 lb_rowid_abc RowidTab;
56703
56704 lv_sql_stmt VARCHAR2(5000);
56705 lv_return NUMBER;
56706 lv_error_text VARCHAR2(250);
56707
56708 CURSOR c1 IS
56709 SELECT max(ROWID)
56710 FROM msc_st_system_items
56711 WHERE ABC_CLASS_ID IS NULL
56712 AND ABC_CLASS_NAME IS NOT NULL
56713 AND process_flag = G_VALID
56714 AND sr_instance_code = v_instance_code
56715 GROUP BY ABC_CLASS_NAME, organization_code, sr_instance_code, company_name;
56716
56717 BEGIN
56718 IF(v_install_msc) THEN
56719 -- update ABC_CLASS_ID where it exists in the planning system
56720 v_sql_stmt := 1;
56721 lv_sql_stmt :=
56722 ' UPDATE msc_st_system_items msi'
56723 ||' SET abc_class_id = (SELECT local_id from MSC_LOCAL_ID_MISC mac '
56724 ||' WHERE mac.char1 = msi.sr_instance_code'
56725 ||' AND mac.char3 = msi.organization_code '
56726 ||' AND mac.char4 = msi.abc_class_name '
56727 ||' AND mac.ENTITY_NAME = ''ABC_CLASS_ID'''
56728 ||' AND NVL(mac.char2,'||''''||NULL_CHAR||''''||') '
56729 ||' = NVL(msi.company_name,'||''''||NULL_CHAR||''''||')) '
56730 ||' WHERE process_flag = '||G_VALID
56731 ||' AND sr_instance_code = :v_instance_code'
56732 ||' AND abc_class_name is not null ';
56733
56734
56735 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
56736
56737 EXECUTE IMMEDIATE lv_sql_stmt
56738 USING v_instance_code;
56739
56740 OPEN c1;
56741 FETCH c1 BULK COLLECT INTO lb_rowid_abc ;
56742
56743 IF c1%ROWCOUNT > 0 THEN
56744
56745 FORALL j IN lb_rowid_abc.FIRST..lb_rowid_abc.LAST
56746 UPDATE msc_st_system_items msi
56747 SET abc_class_id = MSC_ST_ABC_CLASS_ID_S.nextval
56748 WHERE rowid = lb_rowid_abc(j);
56749
56750
56751 FORALL j IN lb_rowid_abc.FIRST..lb_rowid_abc.LAST
56752 INSERT INTO msc_local_id_misc
56753 (local_id,
56754 st_transaction_id,
56755 instance_id,
56756 entity_name,
56757 data_source_type,
56758 char1,
56759 char2,
56760 char3,
56761 char4,
56762 SOURCE_ABC_CLASS_ID,
56763 last_update_date,
56764 last_updated_by,
56765 creation_date,
56766 created_by )
56767 SELECT
56768 abc_class_id,
56769 st_transaction_id,
56770 v_instance_id,
56771 'ABC_CLASS_ID',
56772 data_source_type,
56773 sr_instance_code,
56774 company_name,
56775 organization_code,
56776 ABC_CLASS_NAME,
56777 SOURCE_ABC_CLASS_ID,
56778 v_current_date,
56779 v_current_user,
56780 v_current_date,
56781 v_current_user
56782 FROM msc_st_system_items
56783 WHERE rowid = lb_rowid_abc(j);
56784
56785 END IF;
56786 CLOSE c1;
56787
56788 -- update ABC_CLASS_ID for ABC_CLASS_NAME for which we have just populated the local id
56789 v_sql_stmt := 2;
56790 lv_sql_stmt :=
56791 ' UPDATE msc_st_system_items msi'
56792 ||' SET abc_class_id = (SELECT local_id from MSC_LOCAL_ID_MISC mac '
56793 ||' WHERE mac.char1 = msi.sr_instance_code'
56794 ||' AND mac.char3 = msi.organization_code '
56795 ||' AND mac.char4 = msi.abc_class_name '
56796 ||' AND mac.ENTITY_NAME = ''ABC_CLASS_ID'''
56797 ||' AND NVL(mac.char2,'||''''||NULL_CHAR||''''||') '
56798 ||' = NVL(msi.company_name,'||''''||NULL_CHAR||''''||')) '
56799 ||' WHERE process_flag = '||G_VALID
56800 ||' AND sr_instance_code = :v_instance_code'
56801 ||' AND abc_class_id IS NULL'
56802 ||' AND abc_class_name is not null ';
56803
56804
56805 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
56806
56807 EXECUTE IMMEDIATE lv_sql_stmt
56808 USING v_instance_code;
56809
56810 v_sql_stmt := 3;
56811 lv_sql_stmt :=
56812 ' INSERT INTO MSC_ABC_CLASSES '
56813 ||' ( ABC_CLASS_ID, '
56814 ||' ABC_CLASS_NAME, '
56815 ||' ORGANIZATION_ID, '
56816 ||' SR_INSTANCE_ID, '
56817 ||' LAST_UPDATE_DATE, '
56818 ||' LAST_UPDATED_BY, '
56819 ||' CREATION_DATE, '
56820 ||' CREATED_BY) '
56821 ||' SELECT '
56822 ||' msi.abc_class_id,'
56823 ||' msi.abc_class_name,'
56824 ||' msi.organization_id,'
56825 || v_instance_id ||','
56826 ||' :v_current_date ,'
56827 ||' :v_current_user ,'
56828 ||' :v_current_date ,'
56829 ||' :v_current_user'
56830 ||' FROM (SELECT distinct '
56831 ||' msi.abc_class_id,'
56832 ||' msi.abc_class_name,'
56833 ||' msi.organization_id,'
56834 || v_instance_id
56835 ||' FROM MSC_ST_SYSTEM_ITEMS msi'
56836 ||' WHERE sr_instance_code = :v_instance_code'
56837 ||' AND process_flag = '||G_VALID
56838 ||' AND msi.abc_class_id is not null'
56839 ||' AND msi.abc_class_name is not null'
56840 ||' AND NOT EXISTS'
56841 ||' ( SELECT 1 FROM MSC_ABC_CLASSES abc'
56842 ||' WHERE abc.abc_class_id = msi.abc_class_id'
56843 ||' AND abc.abc_class_name = msi.abc_class_name'
56844 ||' AND abc.organization_id = msi.organization_id'
56845 ||' AND abc.sr_instance_id = ' ||v_instance_id ||'))msi';
56846
56847
56848 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
56849
56850
56851 EXECUTE IMMEDIATE lv_sql_stmt
56852 USING v_current_date,
56853 v_current_user,
56854 v_current_date,
56855 v_current_user,
56856 v_instance_code;
56857
56858 /* -- Set the process flag as Valid and populate instance_id
56859 lv_return :=
56860 MSC_ST_UTIL.SET_PROCESS_FLAG(p_table_name => 'MSC_ST_SYSTEM_ITEMS',
56861 p_instance_id => v_instance_id,
56862 p_instance_code => v_instance_code,
56863 p_process_flag => G_VALID,
56864 p_error_text => lv_error_text,
56865 p_debug => v_debug);
56866
56867 IF lv_return <> 0 THEN
56868 msc_st_util.log_message(lv_error_text);
56869 END IF;
56870 */
56871
56872 lv_sql_stmt :=
56873 'UPDATE msc_st_system_items msi'
56874 ||' SET product_family_id = (SELECT local_id'
56875 ||' FROM msc_local_id_item mli'
56876 ||' WHERE mli.char1 = msi.sr_instance_code '
56877 ||' AND NVL(mli.char2, '||''''||NULL_CHAR||''''||')='
56878 ||' NVL(msi.company_name,'||''''||NULL_CHAR||''''||')'
56879 ||' AND mli.char4 = msi.product_family_item_name'
56880 ||' AND mli.entity_name = ''SR_INVENTORY_ITEM_ID'' '
56881 ||' AND mli.instance_id = :v_instance_id'
56882 ||' AND rownum < 2)'
56883 ||' WHERE sr_instance_code = :v_instance_code'
56884 ||' AND product_family_item_name is not null '
56885 ||' AND process_flag = '||G_VALID;
56886
56887
56888 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
56889
56890 EXECUTE IMMEDIATE lv_sql_stmt
56891 USING v_instance_id,
56892 v_instance_code;
56893
56894 lv_sql_stmt :=
56895 'UPDATE msc_st_system_items msi'
56896 ||' SET BASE_ITEM_ID = (SELECT local_id'
56897 ||' FROM msc_local_id_item mli'
56898 ||' WHERE mli.char1 = msi.sr_instance_code '
56899 ||' AND NVL(mli.char2, '||''''||NULL_CHAR||''''||')='
56900 ||' NVL(msi.company_name,'||''''||NULL_CHAR||''''||')'
56901 ||' AND mli.char4 = msi.BASE_ITEM_NAME'
56902 ||' AND mli.entity_name = ''SR_INVENTORY_ITEM_ID'' '
56903 ||' AND mli.instance_id = :v_instance_id'
56904 ||' AND rownum < 2)'
56905 ||' WHERE sr_instance_code = :v_instance_code'
56906 ||' AND base_item_name is not null '
56907 ||' AND process_flag = '||G_VALID;
56908
56909
56910 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
56911
56912 EXECUTE IMMEDIATE lv_sql_stmt
56913 USING v_instance_id,
56914 v_instance_code;
56915
56916
56917 COMMIT;
56918
56919 END IF; --v_install_msc
56920
56921 EXCEPTION
56922 WHEN OTHERS THEN
56923 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,substr('MSC_CL_PRE_PROCESS.LOAD_ITEM_ABC_CLASSES'||SQLERRM,1,240));
56924
56925 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_FATAL_ERR, 'Error_Stack...');
56926 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_FATAL_ERR, DBMS_UTILITY.FORMAT_ERROR_STACK );
56927 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_FATAL_ERR, 'Error_Backtrace...' );
56928 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_FATAL_ERR, DBMS_UTILITY.FORMAT_ERROR_BACKTRACE );
56929
56930 RAISE;
56931
56932 END LOAD_ITEM_ABC_CLASSES;
56933 ---------------------- Till here added for the bug fix 2191021 -------------------------------------
56934
56935
56936 ----=========DP specific local procdure=======-------
56937 PROCEDURE LOAD_LEVEL_VALUE(p_batch_id NUMBER)
56938 IS
56939 lv_sql_stmt VARCHAR2(4000);
56940 BEGIN
56941 IF (v_level_value_enabled = SYS_YES) AND (v_install_msd) THEN
56942 lv_sql_stmt := ' DECLARE errbuf varchar2(250);'
56943 ||' retcode number ;'
56944 ||' BEGIN '
56945 ||' MSD_CL_PRE_PROCESS.LOAD_LEVEL_VALUE'
56946 ||' (ERRBUF => errbuf ,'
56947 ||' RETCODE => retcode ,'
56948 ||' p_instance_code => :v_instance_code,'
56949 ||' p_instance_id => :v_instance_id,'
56950 ||' p_batch_id => :lv_batch_id);'
56951 ||' IF ( retcode = '||G_WARNING||') THEN'
56952 ||' MSC_CL_PRE_PROCESS.v_flag := '||SYS_YES||';'
56953 ||' END IF;'
56954 ||' END ;';
56955
56956
56957 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
56958 EXECUTE IMMEDIATE lv_sql_stmt
56959 USING v_instance_code,
56960 v_instance_id,
56961 p_batch_id ;
56962 END IF ;
56963
56964 EXCEPTION
56965 WHEN OTHERS THEN
56966 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,substr('MSC_CL_PRE_PROCESS.LOAD_LEVEL_VALUE'||SQLERRM,1,240));
56967
56968 END ;
56969
56970 PROCEDURE LOAD_LEVEL_ASSOCIATION(p_batch_id NUMBER)
56971 IS
56972 lv_sql_stmt VARCHAR2(4000);
56973 BEGIN
56974 IF (v_level_assoc_enabled = SYS_YES) AND (v_install_msd) THEN
56975 lv_sql_stmt := ' DECLARE errbuf varchar2(250);'
56976 ||' retcode number ;'
56977 ||' BEGIN '
56978 ||' MSD_CL_PRE_PROCESS.LOAD_LEVEL_ASSOC'
56979 ||' (ERRBUF => errbuf ,'
56980 ||' RETCODE => retcode ,'
56981 ||' p_instance_code => :v_instance_code,'
56982 ||' p_instance_id => :v_instance_id,'
56983 ||' p_batch_id => :lv_batch_id);'
56984 ||' IF ( retcode = '||G_WARNING||') THEN'
56985 ||' MSC_CL_PRE_PROCESS.v_flag := '||SYS_YES||';'
56986 ||' END IF;'
56987 ||' END ;';
56988
56989
56990 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
56991 EXECUTE IMMEDIATE lv_sql_stmt
56992 USING v_instance_code,
56993 v_instance_id,
56994 p_batch_id ;
56995 END IF ;
56996
56997 EXCEPTION
56998 WHEN OTHERS THEN
56999 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,substr('MSC_CL_PRE_PROCESS.LOAD_LEVEL_ASSOCIATION'||SQLERRM,1,240));
57000
57001 END ;
57002
57003 PROCEDURE LOAD_BOOKING_DATA (p_batch_id NUMBER )
57004 IS
57005 lv_sql_stmt VARCHAR2(4000);
57006 BEGIN
57007 IF (v_booking_enabled = SYS_YES) AND (v_install_msd) THEN
57008 lv_sql_stmt := ' DECLARE errbuf varchar2(250);'
57009 ||' retcode number ;'
57010 ||' BEGIN '
57011 ||' MSD_CL_PRE_PROCESS.LOAD_BOOKING_DATA'
57012 ||' (ERRBUF => errbuf ,'
57013 ||' RETCODE => retcode ,'
57014 ||' p_instance_code => :v_instance_code,'
57015 ||' p_instance_id => :v_instance_id,'
57016 ||' p_batch_id => :lv_batch_id);'
57017 ||' IF ( retcode = '||G_WARNING||') THEN'
57018 ||' MSC_CL_PRE_PROCESS.v_flag := '||SYS_YES||';'
57019 ||' END IF;'
57020 ||' END ;';
57021
57022
57023 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
57024 EXECUTE IMMEDIATE lv_sql_stmt
57025 USING v_instance_code,
57026 v_instance_id,
57027 p_batch_id ;
57028 END IF ;
57029
57030 EXCEPTION
57031 WHEN OTHERS THEN
57032 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,substr('MSC_CL_PRE_PROCESS.LOAD_BOOKING_DATA'||SQLERRM,1,240));
57033
57034 END ;
57035
57036 PROCEDURE LOAD_SHIPMENT_DATA (p_batch_id NUMBER )
57037 IS
57038 lv_sql_stmt VARCHAR2(4000);
57039 BEGIN
57040 IF (v_shipment_enabled = SYS_YES) AND (v_install_msd) THEN
57041 lv_sql_stmt := ' DECLARE errbuf varchar2(250);'
57042 ||' retcode number ;'
57043 ||' BEGIN '
57044 ||' MSD_CL_PRE_PROCESS.LOAD_SHIPMENT_DATA'
57045 ||' (ERRBUF => errbuf ,'
57046 ||' RETCODE => retcode ,'
57047 ||' p_instance_code => :v_instance_code,'
57048 ||' p_instance_id => :v_instance_id,'
57049 ||' p_batch_id => :lv_batch_id);'
57050 ||' IF ( retcode = '||G_WARNING||') THEN'
57051 ||' MSC_CL_PRE_PROCESS.v_flag := '||SYS_YES||';'
57052 ||' END IF;'
57053 ||' END ;';
57054
57055
57056 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
57057 EXECUTE IMMEDIATE lv_sql_stmt
57058 USING v_instance_code,
57059 v_instance_id,
57060 p_batch_id ;
57061 END IF ;
57062
57063 EXCEPTION
57064 WHEN OTHERS THEN
57065 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,substr('MSC_CL_PRE_PROCESS.LOAD_SHIPMENT_DATA'||SQLERRM,1,240));
57066
57067 END ;
57068
57069 PROCEDURE LOAD_MFG_FORECAST (p_batch_id NUMBER )
57070 IS
57071 lv_sql_stmt VARCHAR2(4000);
57072 BEGIN
57073 IF (v_mfg_fct_enabled = SYS_YES) AND (v_install_msd) THEN
57074 lv_sql_stmt := ' DECLARE errbuf varchar2(250);'
57075 ||' retcode number ;'
57076 ||' BEGIN '
57077 ||' MSD_CL_PRE_PROCESS.LOAD_MFG_FORECAST'
57078 ||' (ERRBUF => errbuf ,'
57079 ||' RETCODE => retcode ,'
57080 ||' p_instance_code => :v_instance_code,'
57081 ||' p_instance_id => :v_instance_id,'
57082 ||' p_batch_id => :lv_batch_id);'
57083 ||' IF ( retcode = '||G_WARNING||') THEN'
57084 ||' MSC_CL_PRE_PROCESS.v_flag := '||SYS_YES||';'
57085 ||' END IF;'
57086 ||' END ;';
57087
57088
57089 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
57090 EXECUTE IMMEDIATE lv_sql_stmt
57091 USING v_instance_code,
57092 v_instance_id,
57093 p_batch_id ;
57094 END IF ;
57095
57096 EXCEPTION
57097 WHEN OTHERS THEN
57098 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,substr('MSC_CL_PRE_PROCESS.LOAD_MFG_FORECAST'||SQLERRM,1,240));
57099
57100 END ;
57101
57102 PROCEDURE LOAD_PRICE_LIST (p_batch_id NUMBER )
57103 IS
57104 lv_sql_stmt VARCHAR2(4000);
57105 BEGIN
57106 IF (v_list_price_enabled = SYS_YES) AND (v_install_msd) THEN
57107 lv_sql_stmt := ' DECLARE errbuf varchar2(250);'
57108 ||' retcode number ;'
57109 ||' BEGIN '
57110 ||' MSD_CL_PRE_PROCESS.LOAD_PRICE_LIST'
57111 ||' (ERRBUF => errbuf ,'
57112 ||' RETCODE => retcode ,'
57113 ||' p_instance_code => :v_instance_code,'
57114 ||' p_instance_id => :v_instance_id,'
57115 ||' p_batch_id => :lv_batch_id);'
57116 ||' IF ( retcode = '||G_WARNING||') THEN'
57117 ||' MSC_CL_PRE_PROCESS.v_flag := '||SYS_YES||';'
57118 ||' END IF;'
57119 ||' END ;';
57120
57121
57122 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
57123 EXECUTE IMMEDIATE lv_sql_stmt
57124 USING v_instance_code,
57125 v_instance_id,
57126 p_batch_id ;
57127 END IF ;
57128
57129 EXCEPTION
57130 WHEN OTHERS THEN
57131 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,substr('MSC_CL_PRE_PROCESS.LOAD_PRICE_LIST'||SQLERRM,1,240));
57132
57133 END ;
57134 /*
57135 PROCEDURE LOAD_ITEM_LIST_PRICE(p_batch_id NUMBER )
57136 IS
57137 lv_sql_stmt VARCHAR2(4000);
57138 BEGIN
57139 IF (v_list_price_enabled = SYS_YES) AND (v_install_msd) THEN
57140 lv_sql_stmt := ' DECLARE errbuf varchar2(250);'
57141 ||' retcode number ;'
57142 ||' BEGIN '
57143 ||' MSD_CL_PRE_PROCESS.LOAD_ITEM_LIST_PRICE'
57144 ||' (ERRBUF => errbuf ,'
57145 ||' RETCODE => retcode ,'
57146 ||' p_instance_code => :v_instance_code,'
57147 ||' p_instance_id => :v_instance_id,'
57148 ||' p_batch_id => :lv_batch_id);'
57149 ||' END ;';
57150
57151
57152 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
57153 EXECUTE IMMEDIATE lv_sql_stmt
57154 USING v_instance_code,
57155 v_instance_id,
57156 p_batch_id ;
57157 END IF ;
57158
57159 EXCEPTION
57160 WHEN OTHERS THEN
57161 msc_st_util.log_message(substr('MSC_CL_PRE_PROCESS.LOAD_ITEM_LIST_PRICE'||SQLERRM,1,240));
57162
57163 END ;
57164 */
57165
57166 PROCEDURE LOAD_CS_DATA (p_batch_id NUMBER )
57167 IS
57168 lv_sql_stmt VARCHAR2(4000);
57169 BEGIN
57170 IF (v_cs_data_enabled = SYS_YES) AND (v_install_msd) THEN
57171 lv_sql_stmt := ' DECLARE errbuf varchar2(250);'
57172 ||' retcode number ;'
57173 ||' BEGIN '
57174 ||' MSD_CL_PRE_PROCESS.LOAD_CS_DATA'
57175 ||' (ERRBUF => errbuf ,'
57176 ||' RETCODE => retcode ,'
57177 ||' p_instance_code => :v_instance_code,'
57178 ||' p_instance_id => :v_instance_id,'
57179 ||' p_batch_id => :lv_batch_id);'
57180 ||' IF ( retcode = '||G_WARNING||') THEN'
57181 ||' MSC_CL_PRE_PROCESS.v_flag := '||SYS_YES||';'
57182 ||' END IF;'
57183 ||' END ;';
57184
57185
57186 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
57187 EXECUTE IMMEDIATE lv_sql_stmt
57188 USING v_instance_code,
57189 v_instance_id,
57190 p_batch_id ;
57191 END IF ;
57192
57193 EXCEPTION
57194 WHEN OTHERS THEN
57195 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,substr('MSC_CL_PRE_PROCESS.LOAD_CS_DATA'||SQLERRM,1,240));
57196
57197 END ;
57198
57199 PROCEDURE LOAD_CURR_CONV (p_batch_id NUMBER )
57200 IS
57201 lv_sql_stmt VARCHAR2(4000);
57202 BEGIN
57203 IF (v_curr_conv_enabled = SYS_YES) AND (v_install_msd) THEN
57204 lv_sql_stmt := ' DECLARE errbuf varchar2(250);'
57205 ||' retcode number ;'
57206 ||' BEGIN '
57207 ||' MSD_CL_PRE_PROCESS.LOAD_CURRENCY_CONV'
57208 ||' (ERRBUF => errbuf ,'
57209 ||' RETCODE => retcode ,'
57210 ||' p_instance_code => :v_instance_code,'
57211 ||' p_instance_id => :v_instance_id,'
57212 ||' p_batch_id => :lv_batch_id);'
57213 ||' IF ( retcode = '||G_WARNING||') THEN'
57214 ||' MSC_CL_PRE_PROCESS.v_flag := '||SYS_YES||';'
57215 ||' END IF;'
57216 ||' END ;';
57217
57218
57219 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
57220
57221 EXECUTE IMMEDIATE lv_sql_stmt
57222 USING v_instance_code,
57223 v_instance_id,
57224 p_batch_id ;
57225 END IF ;
57226
57227 EXCEPTION
57228 WHEN OTHERS THEN
57229 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,substr('MSC_CL_PRE_PROCESS.LOAD_CURR_CONV'||SQLERRM,1,240));
57230
57231 END ;
57232
57233 PROCEDURE LOAD_UOM_CONV (p_batch_id NUMBER )
57234 IS
57235 lv_sql_stmt VARCHAR2(4000);
57236 BEGIN
57237 IF (v_uom_conv_enabled = SYS_YES) AND (v_install_msd) THEN
57238 lv_sql_stmt := ' DECLARE errbuf varchar2(250);'
57239 ||' retcode number ;'
57240 ||' BEGIN '
57241 ||' MSD_CL_PRE_PROCESS.LOAD_UOM_CONV'
57242 ||' (ERRBUF => errbuf ,'
57243 ||' RETCODE => retcode ,'
57244 ||' p_instance_code => :v_instance_code,'
57245 ||' p_instance_id => :v_instance_id,'
57246 ||' p_batch_id => :lv_batch_id);'
57247 ||' IF ( retcode = '||G_WARNING||') THEN'
57248 ||' MSC_CL_PRE_PROCESS.v_flag := '||SYS_YES||';'
57249 ||' END IF;'
57250 ||' END ;';
57251
57252
57253 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
57254
57255 EXECUTE IMMEDIATE lv_sql_stmt
57256 USING v_instance_code,
57257 v_instance_id,
57258 p_batch_id ;
57259 END IF ;
57260
57261 EXCEPTION
57262 WHEN OTHERS THEN
57263 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,substr('MSC_CL_PRE_PROCESS.LOAD_UOM_CONV'||SQLERRM,1,240));
57264
57265 END ;
57266
57267 PROCEDURE LOAD_FISCAL_TIME
57268 IS
57269 lv_sql_stmt VARCHAR2(4000);
57270 BEGIN
57271 IF (v_fiscal_cal_enabled = SYS_YES ) AND (v_install_msd) THEN
57272 lv_sql_stmt := ' DECLARE errbuf varchar2(250);'
57273 ||' retcode number ;'
57274 ||' BEGIN '
57275 ||' MSD_CL_PRE_PROCESS.LOAD_FISCAL_TIME'
57276 ||' (ERRBUF => errbuf ,'
57277 ||' RETCODE => retcode ,'
57278 ||' p_instance_code => :v_instance_code,'
57279 ||' p_instance_id => :v_instance_id );'
57280 ||' IF ( retcode = '||G_WARNING||') THEN'
57281 ||' MSC_CL_PRE_PROCESS.v_flag := '||SYS_YES||';'
57282 ||' END IF;'
57283 ||' END ;';
57284
57285
57286 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
57287
57288 EXECUTE IMMEDIATE lv_sql_stmt
57289 USING v_instance_code,
57290 v_instance_id ;
57291 END IF ;
57292
57293 EXCEPTION
57294 WHEN OTHERS THEN
57295 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,substr('MSC_CL_PRE_PROCESS.LOAD_FISCAL_TIME'||SQLERRM,1,240));
57296
57297 END ;
57298
57299
57300 PROCEDURE LOAD_COMPOSITE_TIME
57301 IS
57302 lv_sql_stmt VARCHAR2(4000);
57303 BEGIN
57304 IF (v_comp_cal_enabled = SYS_YES ) AND (v_install_msd) THEN
57305 lv_sql_stmt := ' DECLARE errbuf varchar2(250);'
57306 ||' retcode number ;'
57307 ||' BEGIN '
57308 ||' MSD_CL_PRE_PROCESS.LOAD_COMPOSITE_TIME'
57309 ||' (ERRBUF => errbuf ,'
57310 ||' RETCODE => retcode ,'
57311 ||' p_instance_code => :v_instance_code,'
57312 ||' p_instance_id => :v_instance_id );'
57313 ||' IF ( retcode = '||G_WARNING||') THEN'
57314 ||' MSC_CL_PRE_PROCESS.v_flag := '||SYS_YES||';'
57315 ||' END IF;'
57316 ||' END ;';
57317
57318
57319 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
57320
57321 EXECUTE IMMEDIATE lv_sql_stmt
57322 USING v_instance_code,
57323 v_instance_id ;
57324 END IF ;
57325
57326 EXCEPTION
57327 WHEN OTHERS THEN
57328 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,substr('MSC_CL_PRE_PROCESS.LOAD_COMPOSITE_TIME'||SQLERRM,1,240));
57329
57330 END ;
57331
57332
57333 PROCEDURE LOAD_SETUP_PARAMETER
57334 IS
57335 lv_sql_stmt VARCHAR2(4000);
57336 BEGIN
57337 IF (v_setup_enabled = SYS_YES ) AND (v_install_msd) THEN
57338 lv_sql_stmt := ' DECLARE errbuf varchar2(250);'
57339 ||' retcode number ;'
57340 ||' BEGIN '
57341 ||' MSD_CL_PRE_PROCESS.LOAD_SETUP_PARAMETER'
57342 ||' (ERRBUF => errbuf ,'
57343 ||' RETCODE => retcode ,'
57344 ||' p_instance_code => :v_instance_code,'
57345 ||' p_instance_id => :v_instance_id );'
57346 ||' IF ( retcode = '||G_WARNING||') THEN'
57347 ||' MSC_CL_PRE_PROCESS.v_flag := '||SYS_YES||';'
57348 ||' END IF;'
57349 ||' END ;';
57350
57351
57352 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
57353
57354 EXECUTE IMMEDIATE lv_sql_stmt
57355 USING v_instance_code,
57356 v_instance_id ;
57357 END IF ;
57358
57359 EXCEPTION
57360 WHEN OTHERS THEN
57361 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,substr('MSC_CL_PRE_PROCESS.LOAD_SETUP_PARAMETER'||SQLERRM,1,240));
57362
57363 END ;
57364
57365 PROCEDURE LOAD_MFG_TIME
57366 IS
57367 lv_sql_stmt VARCHAR2(4000);
57368
57369 CURSOR c1 IS
57370 SELECT calendar_code
57371 FROM msc_st_calendars
57372 WHERE process_flag = G_VALID
57373 AND sr_instance_id = v_instance_id;
57374
57375 BEGIN
57376 IF(v_install_msd) THEN
57377 FOR rec1 IN c1
57378 LOOP
57379
57380 lv_sql_stmt := ' DECLARE errbuf varchar2(250);'
57381 ||' retcode number ;'
57382 ||' BEGIN '
57383 ||' MSD_CL_PRE_PROCESS.LOAD_MFG_TIME'
57384 ||' (ERRBUF => errbuf ,'
57385 ||' RETCODE => retcode ,'
57386 ||' p_calendar_code => :v_calendar_code,'
57387 ||' p_instance_id => :v_instance_id );'
57388 ||' IF ( retcode = '||G_WARNING||') THEN '
57389 ||' update msc_apps_instances'
57390 ||' set dbs_ver = '||SYS_YES
57391 ||' where instance_id='||v_instance_id||';'
57392 ||' END IF;'
57393 ||' END ;';
57394
57395
57396 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
57397
57398 EXECUTE IMMEDIATE lv_sql_stmt
57399 USING rec1.calendar_code,
57400 v_instance_id ;
57401 END LOOP ;
57402 END IF ; -- v_install_msd
57403
57404 EXCEPTION
57405 WHEN OTHERS THEN
57406 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,substr('MSC_CL_PRE_PROCESS.LOAD_MFG_TIME'||SQLERRM,1,240));
57407
57408 END ;
57409
57410 -- Load Profiles
57411
57412 PROCEDURE LOAD_PROFILES IS
57413
57414 lv_bom_explosion NUMBER;
57415 lv_lbj_copy_routing NUMBER;
57416 lv_error_text VARCHAR2(250);
57417 lv_where_str VARCHAR2(5000);
57418 lv_message_text VARCHAR2(5000);
57419 lv_return NUMBER;
57420 lv_transaction_id NUMBER;
57421 lv_sql_stmt VARCHAR2(5000);
57422
57423 ex_logging_err EXCEPTION;
57424
57425
57426
57427 BEGIN
57428
57429 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
57430 (p_app_short_name => 'MSC',
57431 p_error_code => 'MSC_PP_DUP_REC_FOR_XML',
57432 p_message_text => lv_message_text,
57433 p_error_text => lv_error_text);
57434
57435 IF lv_return <> 0 THEN
57436 RAISE ex_logging_err;
57437 END IF;
57438
57439 --Duplicate records check for the records whose source is XML
57440
57441 UPDATE msc_st_apps_instances mai1
57442 SET process_flag = G_ERROR_FLG,
57443 error_text = lv_message_text
57444 WHERE message_id < (SELECT MAX(message_id)
57445 FROM msc_st_apps_instances mai2
57446 WHERE mai2.sr_instance_code = mai1.sr_instance_code
57447 AND mai2.process_flag = G_IN_PROCESS
57448 AND NVL(mai2.message_id,NULL_VALUE) <>NULL_VALUE)
57449 AND mai1.process_flag = G_IN_PROCESS
57450 AND mai1.sr_instance_code = v_instance_code
57451 AND NVL(mai1.message_id,NULL_VALUE) <> NULL_VALUE;
57452
57453
57454 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
57455 (p_app_short_name => 'MSC',
57456 p_error_code => 'MSC_PP_DUP_REC_FOR_BATCH_LOAD',
57457 p_message_text => lv_message_text,
57458 p_error_text => lv_error_text);
57459
57460 IF lv_return <> 0 THEN
57461 RAISE ex_logging_err;
57462 END IF;
57463
57464 --Duplicate records check for the records whose source is other than XML
57465 --Different SQL is used because in XML we can identify the latest records
57466 --whereas in batch load we cannot.
57467
57468 UPDATE msc_st_apps_instances mai1
57469 SET process_flag = G_ERROR_FLG,
57470 error_text = lv_message_text
57471 WHERE EXISTS( SELECT 1
57472 FROM msc_st_apps_instances mai2
57473 WHERE mai2.sr_instance_code = mai1.sr_instance_code
57474 AND mai2.process_flag = G_IN_PROCESS
57475 AND NVL(mai2.message_id,NULL_VALUE) = NULL_VALUE
57476 GROUP BY sr_instance_code HAVING COUNT(*) > 1)
57477 AND mai1.process_flag = G_IN_PROCESS
57478 AND mai1.sr_instance_code = v_instance_code
57479 AND NVL(mai1.message_id,NULL_VALUE) = NULL_VALUE;
57480
57481
57482 SELECT msc_st_apps_instances_s.NEXTVAL
57483 INTO lv_transaction_id
57484 FROM dual;
57485
57486
57487 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Refresh ID: '||v_refresh_id);
57488
57489
57490 --Update the transaction_id and the who columns
57491
57492 lv_sql_stmt :=
57493 'UPDATE msc_st_apps_instances '
57494 ||' SET st_transaction_id = :lv_transaction_id,'
57495 ||' refresh_id = '||v_refresh_id ||','
57496 ||' last_update_date = :v_current_date,'
57497 ||' last_updated_by = :v_current_user,'
57498 ||' creation_date = :v_current_date,'
57499 ||' created_by = :v_current_user'
57500 ||' WHERE sr_instance_code = :v_instance_code';
57501
57502
57503 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
57504
57505 EXECUTE IMMEDIATE lv_sql_stmt
57506 USING lv_transaction_id,
57507 v_current_date,
57508 v_current_user,
57509 v_current_date,
57510 v_current_user,
57511 v_instance_code;
57512
57513
57514 lv_sql_stmt :=
57515 'UPDATE msc_st_apps_instances '
57516 ||' SET wsm_create_lbj_copy_routing = 2'
57517 ||' WHERE sr_instance_code = :v_instance_code'
57518 ||' AND process_flag = '||G_IN_PROCESS
57519 ||' AND wsm_create_lbj_copy_routing NOT IN (1,2)';
57520
57521
57522 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
57523
57524 EXECUTE IMMEDIATE lv_sql_stmt
57525 USING v_instance_code;
57526
57527 -- set the message
57528 lv_return := MSC_ST_UTIL.GET_ERROR_MESSAGE
57529 (p_app_short_name => 'MSC',
57530 p_error_code => 'MSC_PP_INVALID_VALUE',
57531 p_message_text => lv_message_text,
57532 p_error_text => lv_error_text,
57533 p_token1 => 'COLUMN_NAME',
57534 p_token_value1 => 'MSC_ORG_FOR_BOM_EXPLOSION');
57535
57536 IF lv_return <> 0 THEN
57537 RAISE ex_logging_err;
57538 END IF;
57539
57540 -- derive validation_org_id
57541
57542 lv_sql_stmt :=
57543 'UPDATE msc_st_apps_instances mai'
57544 ||' SET validation_org_id'
57545 ||' = (SELECT local_id'
57546 ||' FROM msc_local_id_setup '
57547 ||' WHERE char1 = sr_instance_code'
57548 ||' AND char3 = msc_org_for_bom_explosion'
57549 ||' AND number1 = '|| G_ORGANIZATION
57550 ||' AND entity_name = ''SR_TP_ID'' )'
57551 ||' WHERE sr_instance_code = :v_instance_code'
57552 ||' AND NVL(validation_org_id,'||NULL_VALUE||') = '||NULL_VALUE
57553 ||' AND process_flag = '||G_IN_PROCESS;
57554
57555
57556 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
57557
57558 EXECUTE IMMEDIATE lv_sql_stmt
57559 USING v_instance_code;
57560
57561 -- error out the record if validation_org_id is not a valid organization_id
57562
57563 lv_sql_stmt :=
57564 'UPDATE msc_st_apps_instances mai'
57565 ||' SET process_flag = '||G_ERROR_FLG||','
57566 ||' error_text = '||''''||lv_message_text||''''
57567 ||' WHERE NVL(validation_org_id,'||NULL_VALUE||') = '||NULL_VALUE
57568 ||' AND NVL(msc_org_for_bom_explosion,'||''''||NULL_CHAR||''''||')'
57569 ||' <> '||''''||NULL_CHAR||''''
57570 ||' AND sr_instance_code = :v_instance_code'
57571 ||' AND process_flag = '||G_IN_PROCESS ;
57572
57573
57574 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
57575
57576 EXECUTE IMMEDIATE lv_sql_stmt
57577 USING v_instance_code;
57578
57579 lv_return := MSC_ST_UTIL.SET_PROCESS_FLAG
57580 (p_table_name => 'MSC_ST_APPS_INSTANCES',
57581 p_instance_id => v_instance_id,
57582 p_instance_code => v_instance_code,
57583 p_process_flag => G_VALID,
57584 p_debug => v_debug,
57585 p_error_text => lv_error_text);
57586
57587 IF lv_return <> 0 THEN
57588 RAISE ex_logging_err;
57589 END IF;
57590
57591
57592 lv_sql_stmt :=
57593 'UPDATE msc_apps_instances mai'
57594 ||' SET (validation_org_id, lbj_details) = (SELECT validation_org_id, wsm_create_lbj_copy_routing'
57595 ||' FROM msc_st_apps_instances msai'
57596 ||' WHERE msai.sr_instance_code = mai.instance_code'
57597 ||' AND msai.sr_instance_id = mai.instance_id'
57598 ||' AND msai.process_flag =' || G_VALID ||')'
57599 ||' WHERE instance_code = :v_instance_code';
57600
57601
57602
57603 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_DEBUG_1,lv_sql_stmt);
57604
57605 EXECUTE IMMEDIATE lv_sql_stmt USING v_instance_code;
57606
57607 COMMIT;
57608
57609 EXCEPTION
57610 WHEN OTHERS THEN
57611 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,substr('MSC_CL_PRE_PROCESS.LOAD_PROFILES'||SQLERRM,1,240));
57612
57613 END LOAD_PROFILES;
57614
57615
57616
57617
57618
57619 --============= End Load Procedures=============
57620
57621
57622 FUNCTION SET_ST_STATUS( ERRBUF OUT NOCOPY VARCHAR2,
57623 RETCODE OUT NOCOPY NUMBER,
57624 p_instance_id IN NUMBER,
57625 p_st_status IN NUMBER)
57626 RETURN BOOLEAN
57627 IS
57628
57629 lv_staging_table_status NUMBER;
57630
57631 BEGIN
57632
57633 ---=================== PRE-PROCESSING ===========================
57634
57635 IF p_st_status= G_ST_PRE_PROCESSING THEN
57636
57637 SELECT mai.ST_STATUS
57638 INTO lv_staging_table_status
57639 FROM MSC_APPS_INSTANCES mai
57640 WHERE mai.INSTANCE_ID= p_instance_id
57641 FOR UPDATE;
57642
57643 IF lv_staging_table_status= G_ST_PULLING THEN
57644 FND_MESSAGE.SET_NAME('MSC', 'MSC_ST_ERROR_PULLING');
57645 ERRBUF:= FND_MESSAGE.GET;
57646
57647 RETCODE := G_ERROR;
57648 RETURN FALSE;
57649
57650 ELSIF lv_staging_table_status= G_ST_COLLECTING THEN
57651 FND_MESSAGE.SET_NAME('MSC', 'MSC_ST_ERROR_LOADING');
57652 ERRBUF:= FND_MESSAGE.GET;
57653
57654 RETCODE := G_ERROR;
57655 RETURN FALSE;
57656
57657 ELSIF lv_staging_table_status= G_ST_PURGING THEN
57658
57659 FND_MESSAGE.SET_NAME('MSC', 'MSC_ST_ERROR_PURGING');
57660 ERRBUF:= FND_MESSAGE.GET;
57661
57662 RETCODE := G_ERROR;
57663 RETURN FALSE;
57664
57665 ELSIF lv_staging_table_status= G_ST_PRE_PROCESSING THEN
57666
57667 FND_MESSAGE.SET_NAME('MSC', 'MSC_ST_ERROR_PRE_PROCESSING');
57668 ERRBUF:= FND_MESSAGE.GET;
57669
57670 RETCODE := G_ERROR;
57671 RETURN FALSE;
57672
57673 ELSE
57674 RETCODE := G_SUCCESS;
57675
57676 UPDATE MSC_APPS_INSTANCES
57677 SET ST_STATUS= G_ST_PRE_PROCESSING,
57678 LCID= MSC_COLLECTION_S.NEXTVAL,
57679 LAST_UPDATE_DATE= v_current_date,
57680 LAST_UPDATED_BY= v_current_user,
57681 REQUEST_ID= FND_GLOBAL.CONC_REQUEST_ID
57682 WHERE INSTANCE_ID= p_instance_id;
57683
57684 SELECT MSC_COLLECTION_S.CURRVAL
57685 INTO v_last_collection_id
57686 FROM DUAL;
57687
57688 RETURN TRUE;
57689
57690 END IF;
57691
57692 ---===================== READY ====================
57693 ELSIF p_st_status= G_ST_READY THEN
57694
57695 UPDATE MSC_APPS_INSTANCES
57696 SET ST_STATUS= G_ST_READY,
57697 LAST_UPDATE_DATE= v_current_date,
57698 LAST_UPDATED_BY= v_current_user,
57699 REQUEST_ID= FND_GLOBAL.CONC_REQUEST_ID
57700 WHERE INSTANCE_ID= p_instance_id;
57701
57702 RETCODE:= G_SUCCESS;
57703 RETURN TRUE;
57704
57705 END IF;
57706
57707 END SET_ST_STATUS;
57708
57709 -- ============= LAUNCH WORKER ==============
57710
57711 PROCEDURE LAUNCH_WORKER( ERRBUF OUT NOCOPY VARCHAR2,
57712 RETCODE OUT NOCOPY NUMBER,
57713 p_monitor_request_id IN NUMBER,
57714 p_instance_id IN NUMBER,
57715 p_lcid IN NUMBER,
57716 p_timeout IN NUMBER,
57717 p_batch_size IN NUMBER DEFAULT 1000,
57718 p_uom_class_enabled IN NUMBER DEFAULT SYS_NO,
57719 p_item_cat_enabled IN NUMBER DEFAULT SYS_NO,
57720 p_item_enabled IN NUMBER DEFAULT SYS_NO,
57721 p_sup_cap_enabled IN NUMBER DEFAULT SYS_NO,
57722 p_safety_stk_enabled IN NUMBER DEFAULT SYS_NO,
57723 p_ship_mthd_enabled IN NUMBER DEFAULT SYS_NO,
57724 p_sourcing_enabled IN NUMBER DEFAULT SYS_NO,
57725 p_bom_enabled IN NUMBER DEFAULT SYS_NO,
57726 p_rtg_enabled IN NUMBER DEFAULT SYS_NO,
57727 p_resources_enabled IN NUMBER DEFAULT SYS_NO,
57728 p_mat_sup_enabled IN NUMBER DEFAULT SYS_NO,
57729 p_mat_dmd_enabled IN NUMBER DEFAULT SYS_NO,
57730 p_reserve_enabled IN NUMBER DEFAULT SYS_NO,
57731 p_res_dmd_enabled IN NUMBER DEFAULT SYS_NO,
57732 p_item_cst_enabled IN NUMBER DEFAULT SYS_NO,
57733 p_fiscal_cal_enabled IN NUMBER DEFAULT SYS_NO,
57734 p_comp_cal_enabled IN NUMBER DEFAULT SYS_NO,
57735 p_setup_enabled IN NUMBER DEFAULT SYS_NO,
57736 p_item_rollup IN NUMBER DEFAULT SYS_YES,
57737 p_level_value_enabled IN NUMBER DEFAULT SYS_NO,
57738 p_level_assoc_enabled IN NUMBER DEFAULT SYS_NO,
57739 p_booking_enabled IN NUMBER DEFAULT SYS_NO,
57740 p_shipment_enabled IN NUMBER DEFAULT SYS_NO,
57741 p_mfg_fct_enabled IN NUMBER DEFAULT SYS_NO,
57742 p_list_price_enabled IN NUMBER DEFAULT SYS_NO,
57743 p_cs_data_enabled IN NUMBER DEFAULT SYS_NO,
57744 p_curr_conv_enabled IN NUMBER DEFAULT SYS_NO,
57745 p_uom_conv_enabled IN NUMBER DEFAULT SYS_NO,
57746 p_comp_users_enabled IN NUMBER DEFAULT SYS_NO,
57747 p_item_substitute_enabled IN NUMBER DEFAULT SYS_NO,
57748 p_cal_assignment_enabled IN NUMBER DEFAULT SYS_NO,
57749 p_iro_enabled IN NUMBER DEFAULT SYS_NO,
57750 p_ero_enabled IN NUMBER DEFAULT SYS_NO,
57751 p_sales_channel_enabled IN NUMBER DEFAULT SYS_NO, -- added for bug # 7704614
57752 p_fiscal_calendar_enabled IN NUMBER DEFAULT SYS_NO,
57753 p_CMRO_enabled IN NUMBER DEFAULT SYS_NO, --- CMRO Proj bug 9135694
57754 p_request_id IN NUMBER DEFAULT -1 )
57755
57756 IS
57757
57758 ----- TASK CONTROL --------------------------------------------------
57759
57760 lv_task_number NUMBER; -- NEGATIVE: Unknown Error Occurs
57761 -- 99 : All Task Are Done (TASK_ALL_COMPLETED)
57762 -- POSITIVE: The Task Number
57763
57764 lv_task_status NUMBER; -- ::OK : THE TASK IS Done in MSC
57765 -- OTHERS: THE TASK Fails
57766
57767 lv_message VARCHAR2(240):='';
57768 lv_batch_id NUMBER;
57769 lv_process_time NUMBER;
57770
57771 EX_PROCESS_TIME_OUT EXCEPTION;
57772
57773 ------ PIPE CONTROL ----------------------------------------------
57774
57775 lv_pipe_ret_code NUMBER; -- The return value of Sending/Receiving Pipe Messages
57776
57777 EX_PIPE_RCV EXCEPTION;
57778 EX_PIPE_SND EXCEPTION;
57779 BEGIN
57780 msc_util.print_trace_file_name(FND_GLOBAL.CONC_REQUEST_ID);
57781 -- ===== Switch on/ off debug based on MRP: Debug Profile
57782
57783 v_debug := FND_PROFILE.VALUE('MRP_DEBUG') = 'Y';
57784
57785 -- bug 3304390
57786 -- IF FND_PROFILE.VALUE('MRP_TRACE') = 'Y' THEN
57787 -- dbms_session.set_sql_trace(true);
57788 -- END IF;
57789
57790 ---========Initialize the global variables ========
57791
57792 v_batch_size := p_batch_size;
57793 v_res_dmd_enabled := p_res_dmd_enabled;
57794 v_mat_dmd_enabled := p_mat_dmd_enabled;
57795 v_reserve_enabled := p_reserve_enabled;
57796 v_mat_sup_enabled := p_mat_sup_enabled;
57797 v_rtg_enabled := p_rtg_enabled;
57798 v_bom_enabled := p_bom_enabled;
57799 v_resources_enabled := p_resources_enabled;
57800 v_sourcing_enabled := p_sourcing_enabled;
57801 v_item_cat_enabled := p_item_cat_enabled;
57802 v_uom_class_enabled := p_uom_class_enabled;
57803 v_sup_cap_enabled := p_sup_cap_enabled;
57804 v_safety_stk_enabled := p_safety_stk_enabled;
57805 v_item_enabled := p_item_enabled;
57806 v_ship_mthd_enabled := p_ship_mthd_enabled;
57807 v_item_cst_enabled := p_item_cst_enabled;
57808 v_comp_users_enabled := p_comp_users_enabled;
57809 V_item_substitute_enabled := p_item_substitute_enabled;
57810 v_cal_assignment_enabled := p_cal_assignment_enabled;
57811 v_iro_enabled := p_iro_enabled;
57812 v_ero_enabled := p_ero_enabled;
57813 v_sales_channel_enabled := p_sales_channel_enabled;-- added for bug # 7704614
57814 v_fiscal_calendar_enabled := p_fiscal_calendar_enabled;
57815 v_CMRO_enabled := p_CMRO_enabled;
57816 v_request_id := p_request_id;
57817
57818
57819 ---=========DP variables===========================
57820
57821 v_fiscal_cal_enabled := p_fiscal_cal_enabled;
57822 v_comp_cal_enabled := p_comp_cal_enabled;
57823 v_setup_enabled := p_setup_enabled;
57824 v_item_rollup := p_item_rollup;
57825 v_level_value_enabled := p_level_value_enabled;
57826 v_level_assoc_enabled := p_level_assoc_enabled;
57827 v_booking_enabled := p_booking_enabled ;
57828 v_shipment_enabled := p_shipment_enabled;
57829 v_mfg_fct_enabled := p_mfg_fct_enabled;
57830 v_list_price_enabled := p_list_price_enabled;
57831 v_cs_data_enabled := p_cs_data_enabled;
57832 v_curr_conv_enabled := p_curr_conv_enabled;
57833 v_uom_conv_enabled := p_uom_conv_enabled;
57834
57835
57836
57837 v_monitor_request_id := p_monitor_request_id;
57838
57839 PBS := TO_NUMBER( FND_PROFILE.VALUE('MRP_PURGE_BATCH_SIZE'));
57840
57841 IF fnd_global.conc_request_id > 0 THEN
57842 v_cp_enabled:= SYS_YES;
57843 ELSE
57844 v_cp_enabled:= SYS_NO;
57845 END IF;
57846
57847 INITIALIZE( p_instance_id);
57848
57849 v_last_collection_id:= p_lcid;
57850
57851 LOOP
57852
57853 EXIT WHEN is_monitor_status_running <> SYS_YES;
57854
57855 EXIT WHEN is_request_status_running <> SYS_YES;
57856
57857 -- ============= Check the execution time ==============
57858
57859 select (SYSDATE- START_TIME) into lv_process_time from dual;
57860 IF lv_process_time > p_timeout/1440.0 THEN Raise EX_PROCESS_TIME_OUT;
57861 END IF;
57862
57863 -- ============= Get the Task from Task Que ==============
57864
57865 lv_pipe_ret_code := DBMS_PIPE.RECEIVE_MESSAGE( v_pipe_task_que, PIPE_TIME_OUT);
57866
57867 IF lv_pipe_ret_code<>0 THEN
57868
57869 IF lv_pipe_ret_code<> 1 THEN Raise EX_PIPE_RCV; END IF;
57870
57871 ELSE
57872
57873 IF DBMS_PIPE.next_item_type = 0 then
57874
57875 dbms_lock.sleep(2); -- sleep for 2 seconds and then check again
57876
57877 ELSE
57878
57879 DBMS_PIPE.UNPACK_MESSAGE(lv_message);
57880 lv_task_number := get_task_num (lv_message);
57881
57882 IF lv_task_number< 0 or lv_task_number = TASK_ALL_COMPLETED then
57883 EXIT ;
57884 ELSE
57885
57886 -- ============= Execute the Task =============
57887
57888 lv_task_status := FAIL;
57889
57890 lv_batch_id := get_batch_id(lv_message);
57891 EXECUTE_TASK( lv_task_status, lv_task_number, lv_batch_id );
57892
57893 IF lv_task_status <> OK THEN
57894 DBMS_PIPE.PACK_MESSAGE( -lv_task_number);
57895 ELSE
57896 DBMS_PIPE.PACK_MESSAGE( lv_task_number);
57897 END IF;
57898
57899 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_wm)<>0 THEN
57900 RAISE EX_PIPE_SND;
57901 END IF;
57902
57903 IF lv_task_status <> OK THEN
57904 DBMS_LOCK.SLEEP( 2);
57905 END IF;
57906
57907 END IF; -- lv_task_number
57908
57909 END IF; -- no messages. Waiting for dependent tasks to come
57910
57911 END IF; -- lv_pipe_ret_code
57912
57913 END LOOP;
57914
57915 IF lv_task_number = TASK_ALL_COMPLETED THEN
57916 COMMIT;
57917
57918 DBMS_PIPE.PACK_MESSAGE( SYS_YES);
57919
57920 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_status)<>0 THEN
57921 RAISE EX_PIPE_SND;
57922 END IF;
57923
57924 FND_MESSAGE.SET_NAME('MSC', 'MSC_PP_SUCCEED');
57925 ERRBUF:= FND_MESSAGE.GET;
57926
57927 IF v_flag=SYS_YES THEN
57928 RETCODE:= G_WARNING;
57929 ELSE
57930 RETCODE := G_SUCCESS;
57931 END IF;
57932
57933 ELSE -- unknown error occurs
57934
57935 ROLLBACK;
57936
57937 DBMS_PIPE.PACK_MESSAGE( SYS_YES);
57938
57939 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_status)<>0 THEN
57940 RAISE EX_PIPE_SND;
57941 END IF;
57942
57943 FND_MESSAGE.SET_NAME('MSC', 'MSC_PP_FAIL');
57944 ERRBUF:= FND_MESSAGE.GET;
57945
57946 RETCODE := G_ERROR;
57947
57948 END IF;
57949
57950 EXCEPTION
57951
57952 WHEN EX_PIPE_RCV THEN
57953 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_FATAL_ERR,dbms_utility.format_error_stack);
57954
57955 ROLLBACK;
57956
57957 FND_MESSAGE.SET_NAME('MSC', 'MSC_MSG_RCV_FAIL');
57958 FND_MESSAGE.SET_TOKEN('PIPE', v_pipe_mw);
57959 ERRBUF:= FND_MESSAGE.GET;
57960 RETCODE := G_ERROR;
57961 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS, ERRBUF);
57962
57963 -- send a message of 'unresolvable error' to monitor
57964 DBMS_PIPE.PACK_MESSAGE( UNRESOVLABLE_ERROR);
57965
57966 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_wm)<>0 THEN
57967 FND_MESSAGE.SET_NAME('MSC', 'MSC_MSG_SEND_FAIL');
57968 FND_MESSAGE.SET_TOKEN('PIPE', v_pipe_wm);
57969 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
57970 END IF;
57971
57972 WHEN EX_PIPE_SND THEN
57973 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_FATAL_ERR,dbms_utility.format_error_stack);
57974
57975 ROLLBACK;
57976
57977 FND_MESSAGE.SET_NAME('MSC', 'MSC_MSG_SEND_FAIL');
57978 FND_MESSAGE.SET_TOKEN('PIPE', v_pipe_wm);
57979 ERRBUF:= FND_MESSAGE.GET;
57980 RETCODE := G_ERROR;
57981 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,ERRBUF);
57982
57983 -- send a message of 'unresolavable error' to monitor
57984 DBMS_PIPE.PACK_MESSAGE( UNRESOVLABLE_ERROR);
57985
57986 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_wm)<>0 THEN
57987 FND_MESSAGE.SET_NAME('MSC', 'MSC_MSG_SEND_FAIL');
57988 FND_MESSAGE.SET_TOKEN('PIPE', v_pipe_wm);
57989 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
57990 END IF;
57991
57992 WHEN EX_PROCESS_TIME_OUT THEN
57993 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_FATAL_ERR,dbms_utility.format_error_stack);
57994
57995 ROLLBACK;
57996
57997 FND_MESSAGE.SET_NAME('MSC', 'MSC_TIMEOUT');
57998 ERRBUF:= FND_MESSAGE.GET;
57999 RETCODE := G_ERROR;
58000 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS, ERRBUF);
58001
58002 -- send a message of 'unresolavable error' to monitor
58003 DBMS_PIPE.PACK_MESSAGE( UNRESOVLABLE_ERROR);
58004
58005 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_wm)<>0 THEN
58006 FND_MESSAGE.SET_NAME('MSC', 'MSC_MSG_SEND_FAIL');
58007 FND_MESSAGE.SET_TOKEN('PIPE', v_pipe_wm);
58008 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
58009 END IF;
58010
58011 WHEN OTHERS THEN
58012 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_FATAL_ERR,dbms_utility.format_error_stack);
58013 ROLLBACK;
58014
58015 ERRBUF := SQLERRM;
58016 RETCODE := G_ERROR;
58017
58018 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS, ERRBUF);
58019
58020 -- send a message of 'unresolavable error' to monitor
58021 DBMS_PIPE.PACK_MESSAGE( UNRESOVLABLE_ERROR);
58022
58023 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_wm)<>0 THEN
58024 FND_MESSAGE.SET_NAME('MSC', 'MSC_MSG_SEND_FAIL');
58025 FND_MESSAGE.SET_TOKEN('PIPE', v_pipe_wm);
58026 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
58027 END IF;
58028
58029 -- send a message of 'the worker ends its process' to monitor
58030 DBMS_PIPE.PACK_MESSAGE( SYS_YES);
58031
58032 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_status)<>0 THEN
58033 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS, 'FAIL TO SEND MESSAGE');
58034 END IF;
58035
58036 END LAUNCH_WORKER;
58037
58038 -- ===============================================================
58039
58040 PROCEDURE LAUNCH_MONITOR( ERRBUF OUT NOCOPY VARCHAR2,
58041 RETCODE OUT NOCOPY NUMBER,
58042 p_instance_id IN NUMBER,
58043 p_timeout IN NUMBER DEFAULT 60,
58044 p_batch_size IN NUMBER DEFAULT 1000,
58045 p_total_worker_num IN NUMBER DEFAULT 3,
58046 p_cal_enabled IN NUMBER DEFAULT SYS_NO,
58047 p_dmd_class_enabled IN NUMBER DEFAULT SYS_NO,
58048 p_tp_enabled IN NUMBER DEFAULT SYS_NO,
58049 p_ctg_enabled IN NUMBER DEFAULT SYS_NO,
58050 p_item_cat_enabled IN NUMBER DEFAULT SYS_NO,
58051 p_uom_enabled IN NUMBER DEFAULT SYS_NO,
58052 p_uom_class_enabled IN NUMBER DEFAULT SYS_NO,
58053 p_desig_enabled IN NUMBER DEFAULT SYS_NO,
58054 p_project_enabled IN NUMBER DEFAULT SYS_NO,
58055 p_item_enabled IN NUMBER DEFAULT SYS_NO,
58056 p_sup_cap_enabled IN NUMBER DEFAULT SYS_NO,
58057 p_safety_stk_enabled IN NUMBER DEFAULT SYS_NO,
58058 p_ship_mthd_enabled IN NUMBER DEFAULT SYS_NO,
58059 p_sourcing_enabled IN NUMBER DEFAULT SYS_NO,
58060 p_bom_enabled IN NUMBER DEFAULT SYS_NO,
58061 p_rtg_enabled IN NUMBER DEFAULT SYS_NO,
58062 p_resources_enabled IN NUMBER DEFAULT SYS_NO,
58063 p_mat_sup_enabled IN NUMBER DEFAULT SYS_NO,
58064 p_mat_dmd_enabled IN NUMBER DEFAULT SYS_NO,
58065 p_reserve_enabled IN NUMBER DEFAULT SYS_NO,
58066 p_res_dmd_enabled IN NUMBER DEFAULT SYS_NO,
58067 p_item_cst_enabled IN NUMBER DEFAULT SYS_NO,
58068 p_parent_request_id IN NUMBER DEFAULT -1,
58069 p_fiscal_cal_enabled IN NUMBER DEFAULT SYS_NO,
58070 p_setup_enabled IN NUMBER DEFAULT SYS_NO,
58071 p_link_dummy IN VARCHAR2 DEFAULT NULL,
58072 p_item_rollup IN NUMBER DEFAULT SYS_YES,
58073 p_level_value_enabled IN NUMBER DEFAULT SYS_NO,
58074 p_level_assoc_enabled IN NUMBER DEFAULT SYS_NO,
58075 p_booking_enabled IN NUMBER DEFAULT SYS_NO,
58076 p_shipment_enabled IN NUMBER DEFAULT SYS_NO,
58077 p_mfg_fct_enabled IN NUMBER DEFAULT SYS_NO,
58078 p_list_price_enabled IN NUMBER DEFAULT SYS_NO,
58079 p_cs_data_enabled IN NUMBER DEFAULT SYS_NO,
58080 p_cs_dummy IN VARCHAR2 DEFAULT NULL,
58081 p_cs_refresh IN NUMBER DEFAULT SYS_NO,
58082 p_curr_conv_enabled IN NUMBER DEFAULT SYS_NO,
58083 p_uom_conv_enabled IN NUMBER DEFAULT SYS_NO ,
58084 p_calling_module IN NUMBER DEFAULT G_APS,
58085 p_comp_users_enabled IN NUMBER DEFAULT SYS_NO,
58086 p_item_substitute_enabled IN NUMBER DEFAULT SYS_NO,
58087 p_planners_enabled IN NUMBER DEFAULT SYS_NO,
58088 p_comp_cal_enabled IN NUMBER DEFAULT SYS_NO,
58089 p_profile_enabled IN NUMBER DEFAULT SYS_NO,
58090 p_cal_assignment_enabled IN NUMBER DEFAULT SYS_NO,
58091 p_iro_enabled IN NUMBER DEFAULT SYS_NO,
58092 p_ero_enabled IN NUMBER DEFAULT SYS_NO,
58093 p_sales_channel_enabled IN NUMBER DEFAULT SYS_NO, -- added for bug # 7704614
58094 p_fiscal_calendar_enabled IN NUMBER DEFAULT SYS_NO,
58095 p_CMRO_enabled IN NUMBER DEFAULT SYS_NO)
58096
58097
58098 IS
58099
58100 lc_i PLS_INTEGER;
58101 lv_batch_id PLS_INTEGER := 0;
58102 lv_task_number PLS_INTEGER := 0;
58103 lv_message VARCHAR2(240):= '';
58104 lv_task_not_completed PLS_INTEGER := 0;
58105
58106 lv_process_time PLS_INTEGER := 0;
58107
58108 EX_PIPE_RCV EXCEPTION;
58109 EX_PIPE_SND EXCEPTION;
58110 EX_PROCESS_TIME_OUT EXCEPTION;
58111 EX_SECOND_PASS EXCEPTION;
58112
58113 lv_pipe_ret_code PLS_INTEGER := 0;
58114
58115 lv_check_point PLS_INTEGER := 0;
58116
58117 lvs_request_id NumTblTyp := NumTblTyp(0);
58118
58119 lv_total_item_batches PLS_INTEGER := 0;
58120 lv_total_supply_batches PLS_INTEGER := 0;
58121 lv_total_demand_batches PLS_INTEGER := 0;
58122 lv_total_lvalue_batches PLS_INTEGER := 0;
58123
58124 lv_item_batches_completed PLS_INTEGER := 0;
58125 lv_supply_batches_completed PLS_INTEGER := 0;
58126 lv_demand_batches_completed PLS_INTEGER := 0;
58127 lv_lvalue_batches_completed PLS_INTEGER := 0;
58128 lv_pipe_status PLS_INTEGER := 0;
58129
58130
58131
58132
58133 lv_worker_committed PLS_INTEGER := 0;
58134
58135 lv_start_time DATE;
58136
58137 lv_collection_plan_exists PLS_INTEGER := 0;
58138 lv_is_build_over NUMBER;
58139 lv_monitor_id PLS_INTEGER;
58140
58141 lv_plan_per_profile NUMBER:=nvl(fnd_profile.value('MSD_PLANNING_PERCENTAGE'), G_NO_PLAN_PERCENTAGE);
58142 lv_retval BOOLEAN;
58143 lv_dummy1 VARCHAR2(32) := '';
58144 lv_dummy2 VARCHAR2(32) := '';
58145 lv_count PLS_INTEGER; --8725891
58146
58147
58148 CURSOR Warn_Flag IS
58149 SELECT dbs_ver
58150 FROM MSC_APPS_INSTANCES
58151 WHERE instance_id = p_instance_id;
58152
58153
58154 BEGIN
58155 msc_util.print_trace_file_name(FND_GLOBAL.CONC_REQUEST_ID);
58156 lv_retval := FND_INSTALLATION.GET_APP_INFO(
58157 'MSD', lv_dummy1,lv_dummy2, v_applsys_schema);
58158
58159 IF (lv_dummy1 = 'I' OR lv_dummy1 = 'S')THEN
58160 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Oracle Demand Planning Installed');
58161 v_install_msd := TRUE ;
58162 END IF;
58163
58164
58165 --=====set the value for sub-request============
58166 v_req_data := nvl(fnd_conc_global.request_data,G_NEW_REQUEST);
58167
58168 --IF program resumes after completing the last activity(ie., planning
58169 --ODS load) then exit the legacy pre-processor. Whenever a child request
58170 --is submitted, parent exits to PAUSE mode so that the parent does'nt
58171 --consume any resources.
58172
58173
58174 IF v_req_data = G_DP_BOM_DATA THEN
58175
58176 OPEN Warn_Flag;
58177 FETCH Warn_Flag INTO v_warning_flag;
58178 CLOSE Warn_Flag;
58179
58180 IF v_warning_flag=SYS_YES THEN
58181 RETCODE:= G_WARNING;
58182 ELSE
58183 RETCODE := G_SUCCESS;
58184 END IF;
58185
58186 RETURN;
58187 END IF;
58188
58189
58190 IF ((v_req_data=G_ODS_REQ_DATA) AND v_install_msd AND (lv_plan_per_profile=G_EXCLUDE_OPTION_CLASS) AND ( p_bom_enabled = SYS_YES) ) THEN
58191
58192 lv_monitor_id := fnd_request.submit_request('MSC','MSDBCP',NULL,NULL,TRUE,p_instance_id);
58193
58194 IF lv_monitor_id <> 0 THEN
58195 fnd_conc_global.set_req_globals(conc_status => 'PAUSED',
58196 request_data => to_char(G_DP_BOM_DATA)) ;
58197
58198 commit;
58199
58200 ELSE
58201
58202 FND_MESSAGE.SET_NAME('MSC', 'MSC_DP_BOM_PROCESSING_FAIL');
58203 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS, FND_MESSAGE.GET);
58204 RETCODE := G_WARNING;
58205
58206 commit;
58207
58208 END IF;
58209
58210 RETURN;
58211
58212 ELSE
58213
58214 IF v_req_data=G_ODS_REQ_DATA THEN
58215
58216 OPEN Warn_Flag;
58217 FETCH Warn_Flag INTO v_warning_flag;
58218 CLOSE Warn_Flag;
58219
58220 IF v_warning_flag=SYS_YES THEN
58221 RETCODE:= G_WARNING;
58222 ELSE
58223 RETCODE := G_SUCCESS;
58224 END IF;
58225
58226 RETURN;
58227 END IF;
58228
58229 END IF;
58230
58231
58232 -- ===== Switch on/ off debug based on MRP: Debug Profile
58233
58234 -- v_debug := FND_PROFILE.VALUE('MRP_DEBUG') = 'Y';
58235
58236 -- bug 3304390
58237 -- IF FND_PROFILE.VALUE('MRP_TRACE') = 'Y' THEN
58238 -- dbms_session.set_sql_trace(true);
58239 -- END IF;
58240
58241 -- Print the parameters coming in
58242 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'p_instance_id : '||p_instance_id);
58243 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'p_batch_size : '||p_batch_size);
58244 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'p_total_worker_num : '||p_total_worker_num);
58245 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Calendars : '||p_cal_enabled);
58246 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Trading Partners : '||p_tp_enabled);
58247 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Demand Class : '||p_dmd_class_enabled);
58248 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Cat Set : '||p_ctg_enabled);
58249 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Product Categories : '||p_item_cat_enabled);
58250 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'UOM : '||p_uom_enabled);
58251 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'UOM Conversions : '||p_uom_class_enabled);
58252 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Designators : '||p_desig_enabled);
58253 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Projects and Tasks : '||p_project_enabled);
58254 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Items : '||p_item_enabled);
58255 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Shipping Method : '||p_ship_mthd_enabled);
58256 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Supplier : '||p_sup_cap_enabled);
58257 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Safety Stocks: '||p_safety_stk_enabled);
58258 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Sourcing Rules : '||p_sourcing_enabled);
58259 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'BOM : '||p_bom_enabled);
58260 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Routings : '||p_rtg_enabled );
58261 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Resources : '||p_resources_enabled );
58262 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Material Supplies : '||p_mat_sup_enabled );
58263 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Material Demands : '||p_mat_dmd_enabled );
58264 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Reservations : '||p_reserve_enabled );
58265 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Resource Demands : '||p_res_dmd_enabled);
58266 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Customer Items : '||p_item_cst_enabled);
58267 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'p_parent_request_id : '||p_parent_request_id);
58268 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'p_comp_users_enabled : '||p_comp_users_enabled);
58269 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Item Substitutes : '||p_item_substitute_enabled);
58270 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Planners : '||p_planners_enabled);
58271 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Profils : '||p_profile_enabled);
58272 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Calendar Assignments : '||p_cal_assignment_enabled);
58273 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'IRO : '||p_iro_enabled);
58274 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'ERO : '||p_ero_enabled);
58275 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Sales Channel : '||p_sales_channel_enabled); -- bug # 7704614
58276 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Fiscal Calendar : '||p_fiscal_calendar_enabled);
58277 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'CMRO : '||p_CMRO_enabled);
58278
58279 -- DP Variables
58280 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Fiscal Calendars : '||p_fiscal_cal_enabled);
58281 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'p_comp_cal_enabled : '||p_comp_cal_enabled);
58282 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'p_setup_enabled : '||p_setup_enabled);
58283 --Bug Fix 2813465 To enable the Item Rollup whenever Categories are loaded via self service loads.
58284 --MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'p_item_rollup : '||p_item_rollup);
58285 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'p_level_value_enabled : '||p_level_value_enabled);
58286 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'p_level_assoc_enabled : '||p_level_assoc_enabled);
58287 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'p_booking_enabled : '||p_booking_enabled);
58288 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'p_shipment_enabled : '||p_shipment_enabled);
58289 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'p_mfg_fct_enabled : '||p_mfg_fct_enabled);
58290 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'p_list_price_enabled : '||p_list_price_enabled);
58291 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'p_cs_data_enabled : '||p_cs_data_enabled);
58292 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'p_cs_refresh : ' ||p_cs_refresh);
58293 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'p_curr_conv_enabled : '||p_curr_conv_enabled);
58294 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'p_uom_conv_enabled : '||p_uom_conv_enabled);
58295
58296
58297
58298
58299 ---========Get the new refresh ID =================
58300 IF v_req_data = G_NEW_REQUEST THEN
58301 UPDATE MSC_APPS_INSTANCES mai
58302 SET LRID= msc_cl_refresh_s.nextval, mai.DBS_VER= SYS_NO
58303 WHERE mai.INSTANCE_ID = p_instance_id;
58304 commit;
58305 END IF;
58306
58307
58308
58309
58310 ---========Initialize the global variables ========
58311
58312 v_res_dmd_enabled := p_res_dmd_enabled;
58313 v_mat_dmd_enabled := p_mat_dmd_enabled;
58314 v_reserve_enabled := p_reserve_enabled;
58315 v_mat_sup_enabled := p_mat_sup_enabled;
58316 v_rtg_enabled := p_rtg_enabled;
58317 v_bom_enabled := p_bom_enabled;
58318 v_resources_enabled := p_resources_enabled;
58319 v_sourcing_enabled := p_sourcing_enabled;
58320 v_ctg_enabled := p_ctg_enabled;
58321 v_sup_cap_enabled := p_sup_cap_enabled;
58322 v_safety_stk_enabled := p_safety_stk_enabled;
58323 v_item_enabled := p_item_enabled;
58324 v_tp_enabled := p_tp_enabled ;
58325 v_dmd_class_enabled := p_dmd_class_enabled ;
58326 v_uom_enabled := p_uom_enabled;
58327 v_desig_enabled := p_desig_enabled;
58328 v_project_enabled := p_project_enabled;
58329 v_cal_enabled := p_cal_enabled;
58330 v_item_cat_enabled := p_item_cat_enabled ;
58331 v_uom_class_enabled := p_uom_class_enabled ;
58332 v_ship_mthd_enabled := p_ship_mthd_enabled ;
58333 v_item_cst_enabled := p_item_cst_enabled;
58334 v_parent_request_id := p_parent_request_id;
58335 v_comp_users_enabled := p_comp_users_enabled;
58336 v_item_substitute_enabled := p_item_substitute_enabled;
58337 v_planners_enabled := p_planners_enabled;
58338 v_profile_enabled := p_profile_enabled;
58339 v_cal_assignment_enabled := p_cal_assignment_enabled;
58340 v_sales_channel_enabled := p_sales_channel_enabled; -- added for bug # 7704614
58341 v_fiscal_calendar_enabled := p_fiscal_calendar_enabled;
58342 v_CMRO_enabled := p_CMRO_enabled;
58343
58344 ---DP variables
58345 v_fiscal_cal_enabled := p_fiscal_cal_enabled;
58346 v_comp_cal_enabled := p_comp_cal_enabled;
58347 v_setup_enabled := p_setup_enabled;
58348 v_item_rollup := p_item_cat_enabled; --Bug Fix 2813465 To enable the Item Rollup whenever Categories are loaded via self service loads.
58349 v_level_value_enabled := p_level_value_enabled;
58350 v_level_assoc_enabled := p_level_assoc_enabled;
58351 v_booking_enabled := p_booking_enabled ;
58352 v_shipment_enabled := p_shipment_enabled;
58353 v_mfg_fct_enabled := p_mfg_fct_enabled;
58354 v_list_price_enabled := p_list_price_enabled;
58355 v_cs_data_enabled := p_cs_data_enabled;
58356 v_cs_refresh := p_cs_refresh;
58357 v_curr_conv_enabled := p_curr_conv_enabled;
58358 v_uom_conv_enabled := p_uom_conv_enabled;
58359 v_iro_enabled := p_iro_enabled;
58360 v_ero_enabled := p_ero_enabled;
58361
58362
58363
58364 v_batch_size := p_batch_size;
58365
58366 INITIALIZE( p_instance_id);
58367
58368 -- Initializing v_request_id with the p_parent_request_id if
58369 -- OA upload else with current request id of the pre process
58370 -- monitor using fnd_global.conc_request_id.
58371 IF nvl(p_parent_request_id, -1) < 1 THEN
58372 v_request_id := -(fnd_global.conc_request_id);
58373 ELSE
58374 v_request_id := v_parent_request_id;
58375 END IF;
58376
58377 -- for L-flow Initialize the parameters
58378 prec.purge_ods_flag := SYS_NO;
58379 prec.app_supp_cap_flag := SYS_NO;
58380 prec.atp_rules_flag := SYS_NO;
58381 prec.bom_flag := SYS_NO;
58382 prec.bor_flag := SYS_NO;
58383 prec.calendar_flag := SYS_NO;
58384 prec.demand_class_flag := SYS_NO;
58385 prec.forecast_flag := SYS_NO;
58386 prec.item_flag := SYS_NO;
58387 prec.kpi_bis_flag := SYS_NO;
58388 prec.mds_flag := SYS_NO;
58389 prec.mps_flag := SYS_NO;
58390 prec.oh_flag := SYS_NO;
58391 prec.parameter_flag := SYS_NO;
58392 prec.planner_flag := SYS_NO;
58393 prec.item_subst_flag := SYS_NO;
58394 prec.project_flag := SYS_NO;
58395 prec.po_flag := SYS_NO;
58396 prec.reserves_flag := SYS_NO;
58397 prec.resource_nra_flag := SYS_NO;
58398 prec.saf_stock_flag := SYS_NO;
58399 prec.sales_order_flag := SYS_NO;
58400 prec.source_hist_flag := SYS_NO;
58401 prec.sourcing_rule_flag := SYS_NO;
58402 prec.sub_inventory_flag := SYS_NO;
58403 prec.tp_customer_flag := SYS_NO;
58404 prec.tp_vendor_flag := SYS_NO;
58405 prec.unit_number_flag := SYS_NO;
58406 prec.uom_flag := SYS_NO;
58407 prec.user_supply_demand_flag := SYS_NO;
58408 prec.wip_flag := SYS_NO;
58409 prec.sales_channel_flag := SYS_NO;
58410 prec.fiscal_calendar_flag := SYS_NO;
58411 prec.CMRO_flag := SYS_NO;
58412 prec.user_company_flag := G_COMP_USR_NO;
58413
58414
58415 -- end of changes for L flow
58416
58417 IF fnd_global.conc_request_id > 0 THEN
58418 v_cp_enabled:= SYS_YES;
58419 ELSE
58420 v_cp_enabled:= SYS_NO;
58421 END IF;
58422
58423 lv_check_point:= 1;
58424 IF v_req_data = G_NEW_REQUEST THEN
58425
58426 -- OA upload changes, status is already set in JCP for OA i.e. nvl(v_parent_request_id, -1) >0
58427 IF nvl(v_parent_request_id, -1) < 1 THEN
58428 IF SET_ST_STATUS( ERRBUF, RETCODE, p_instance_id, G_ST_PRE_PROCESSING) THEN
58429 COMMIT;
58430 lv_check_point:= 2;
58431 ELSE
58432 ROLLBACK;
58433 RETURN;
58434 END IF;
58435 END IF;
58436
58437 /*IF NOT SNAPSHOT_TABLES then --8725891
58438 ROLLBACK;
58439 RETURN;
58440 END IF;*/
58441
58442 CREATE_INDEXES;
58443 END IF;
58444
58445
58446 --=========== call the main tasks here===================
58447
58448 IF v_req_data IN (G_NEW_REQUEST,G_CAL_REQ_DATA) THEN
58449
58450 -------------- Get current ERROR_ID from MSC_ERRORS ---
58451 IF (nvl(v_parent_request_id,-1) < 1) THEN
58452 SELECT max(ERROR_ID) INTO v_error_no_begin FROM MSC_ERRORS;
58453 END IF;
58454
58455
58456 -- initiaize global variables
58457 v_total_worker_num := p_total_worker_num;
58458 -- calendar
58459 IF p_cal_enabled = SYS_YES and v_req_data = G_NEW_REQUEST THEN
58460 --8725891
58461 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_CALENDARS');
58462 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_WORKDAY_PATTERNS');
58463 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_CALENDAR_SHIFTS');
58464 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_SHIFT_TIMES');
58465 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_SHIFT_EXCEPTIONS');
58466 lv_count:= SET_IN_PROCESS (p_table_name => 'MSC_ST_CALENDAR_EXCEPTIONS');
58467
58468 LOAD_CALENDAR;
58469 ELSE
58470 v_cal_build := False;
58471 END IF;
58472
58473 IF v_cal_build THEN
58474 RETURN;
58475 ELSE
58476 --8725891
58477 IF NOT SNAPSHOT_TABLES then
58478 ROLLBACK;
58479 RETURN;
58480 END IF;
58481
58482 END IF;
58483
58484 IF (p_cal_enabled = SYS_YES) THEN
58485 LOAD_MFG_TIME ;
58486 END IF;
58487
58488
58489 -- unit of measures
58490 IF p_uom_enabled = SYS_YES THEN
58491 LOAD_UOM;
58492 END IF;
58493 -- demand class
58494
58495 IF p_dmd_class_enabled = SYS_YES THEN
58496 LOAD_DEMAND_CLASS;
58497 END IF;
58498
58499 -- trading partner
58500 IF p_tp_enabled = SYS_YES THEN
58501 LOAD_TRADING_PARTNERS;
58502 END IF;
58503
58504 -- Profile Values
58505
58506 IF p_profile_enabled = SYS_YES THEN
58507 LOAD_PROFILES;
58508 END IF;
58509
58510 -- Planners
58511
58512 IF p_planners_enabled = SYS_YES THEN
58513 LOAD_PLANNERS;
58514 END IF;
58515
58516
58517 -- category sets
58518 IF p_ctg_enabled = SYS_YES THEN
58519 LOAD_CATEGORY_SET;
58520 END IF;
58521 -- unit of measures
58522 -- IF p_uom_enabled = SYS_YES THEN
58523 -- LOAD_UOM;
58524 -- END IF;
58525 -- designators
58526 IF p_desig_enabled = SYS_YES THEN
58527 LOAD_DESIGNATOR;
58528 END IF;
58529 -- project and tasks
58530 IF p_project_enabled = SYS_YES THEN
58531 LOAD_PROJ_TASK;
58532 END IF;
58533
58534 -- DP Setup Parameters
58535 IF v_setup_enabled = SYS_YES THEN
58536 LOAD_SETUP_PARAMETER;
58537 END IF ;
58538
58539 -- process items/ supply / demands records and error out duplicate records for batch
58540 check_duplicates(ERRBUF, RETCODE);
58541 IF RETCODE = G_ERROR THEN
58542 ROLLBACK;
58543 RETURN;
58544 END IF;
58545
58546 -- fix for bug 2788719
58547 IF is_bis_periods_load_reqd = SYS_YES THEN
58548 prec.kpi_bis_flag:=SYS_YES;
58549 END IF;
58550
58551 --- Purge the existing pipes so that new pipes would be created
58552 DBMS_PIPE.PURGE( v_pipe_task_que);
58553 DBMS_PIPE.PURGE( v_pipe_wm);
58554 DBMS_PIPE.PURGE( v_pipe_mw);
58555 DBMS_PIPE.PURGE( v_pipe_status);
58556
58557 -- ============ Lauch the Workers here ===============
58558
58559 lvs_request_id.EXTEND( p_total_worker_num);
58560
58561 IF v_cp_enabled= SYS_YES THEN
58562
58563 FOR lc_i IN 1..p_total_worker_num LOOP
58564 lvs_request_id(lc_i) := FND_REQUEST.SUBMIT_REQUEST(
58565 'MSC',
58566 'MSCPPW', /* launch worker procedure called */
58567 NULL, -- description
58568 NULL, -- start date
58569 FALSE, -- TRUE,
58570 FND_GLOBAL.CONC_REQUEST_ID,
58571 p_instance_id,
58572 v_last_collection_id,
58573 p_timeout,
58574 p_batch_size,
58575 p_uom_class_enabled,
58576 p_item_cat_enabled,
58577 p_item_enabled,
58578 p_sup_cap_enabled,
58579 p_safety_stk_enabled,
58580 p_ship_mthd_enabled,
58581 p_sourcing_enabled,
58582 p_bom_enabled,
58583 p_rtg_enabled,
58584 p_resources_enabled,
58585 p_mat_sup_enabled,
58586 p_mat_dmd_enabled,
58587 p_reserve_enabled,
58588 p_res_dmd_enabled,
58589 p_item_cst_enabled,
58590 p_fiscal_cal_enabled,
58591 p_comp_cal_enabled,
58592 p_setup_enabled,
58593 v_item_rollup, --Bug Fix 2813465 To enable the Item Rollup whenever Categories are loaded via self service loads.
58594 v_level_value_enabled,
58595 p_level_assoc_enabled,
58596 p_booking_enabled,
58597 p_shipment_enabled,
58598 p_mfg_fct_enabled,
58599 p_list_price_enabled,
58600 p_cs_data_enabled,
58601 p_curr_conv_enabled,
58602 p_uom_conv_enabled,
58603 p_comp_users_enabled,
58604 p_item_substitute_enabled,
58605 p_cal_assignment_enabled,
58606 p_iro_enabled,
58607 p_ero_enabled,
58608 p_sales_channel_enabled,
58609 p_fiscal_calendar_enabled,
58610 p_CMRO_enabled,
58611 v_request_id);
58612
58613
58614 COMMIT;
58615
58616 IF lvs_request_id(lc_i)= 0 THEN
58617
58618 ---- If the request_id=0 then
58619 ---- 1. Restore the status of the staging table.
58620 ---- 2. Send termination messages to the other launched workers.
58621 ---- 3. Return.
58622
58623 ROLLBACK;
58624
58625 IF SET_ST_STATUS( ERRBUF, RETCODE, p_instance_id, G_ST_READY) THEN
58626 COMMIT;
58627 END IF;
58628
58629 FOR lc_i IN 1..p_total_worker_num LOOP
58630
58631 DBMS_PIPE.PACK_MESSAGE( '-1');
58632
58633 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
58634 RAISE EX_PIPE_SND;
58635 END IF;
58636
58637 END LOOP;
58638
58639 FND_MESSAGE.SET_NAME('MSC', 'MSC_PP_LAUNCH_WORKER_FAIL');
58640 ERRBUF:= FND_MESSAGE.GET;
58641 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_FATAL_ERR,ERRBUF);
58642 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_FATAL_ERR,dbms_utility.format_error_stack);
58643 RETCODE := G_ERROR;
58644
58645 COMMIT;
58646 RETURN;
58647 ELSE
58648 FND_MESSAGE.SET_NAME('MSC', 'MSC_PP_WORKER_REQUEST_ID');
58649 FND_MESSAGE.SET_TOKEN('REQUEST_ID', lvs_request_id(lc_i));
58650 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
58651 --MSC_UTIL.print_trace_file_name(lvs_request_id(lc_i));
58652 END IF;
58653
58654 END LOOP;
58655
58656 ELSE -- CP not enabled
58657
58658 COMMIT;
58659
58660 END IF; -- CP enabled
58661
58662
58663
58664
58665 -- ============ Send Tasks to Task Que 'v_pipe_task_que' =============
58666
58667 lv_message := to_char(TASK_BIS_PERIODS);
58668 DBMS_PIPE.PACK_MESSAGE(lv_message );
58669 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
58670 RAISE EX_PIPE_SND;
58671 END IF;
58672 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_BIS_PERIODS: '||lv_message);
58673 lv_task_not_completed := lv_task_not_completed + 1;
58674
58675
58676 IF v_item_enabled = SYS_YES THEN
58677
58678 BEGIN
58679
58680 DECLARE
58681 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
58682 lb_rowid RowidTab;
58683 lb_batch NumTblTyp := NumTblTyp(0);
58684 lv_batch_id PLS_INTEGER;
58685 lv_batch_start PLS_INTEGER;
58686 lv_batch_last PLS_INTEGER;
58687 cursor c2 is SELECT rowid FROM MSC_ST_SYSTEM_ITEMS
58688 WHERE PROCESS_FLAG IN (G_IN_PROCESS,G_ERROR_FLG)
58689 AND NVL(batch_id,NULL_VALUE) = NULL_VALUE
58690 AND sr_instance_code = v_instance_code;
58691
58692 BEGIN
58693
58694 OPEN c2;
58695 FETCH c2 BULK COLLECT INTO lb_rowid ;
58696
58697 IF c2%ROWCOUNT > 0 THEN
58698
58699 SELECT msc_st_batch_id_s.NEXTVAL INTO lv_batch_id FROM dual;
58700 lv_batch_start := lv_batch_id;
58701 lb_batch.extend(lb_rowid.count);
58702
58703 FOR j IN lb_rowid.FIRST..lb_rowid.LAST LOOP
58704
58705 lb_batch(j):= lv_batch_id;
58706 IF MOD(j,v_batch_size) = 0 THEN
58707 SELECT msc_st_batch_id_s.NEXTVAL INTO lv_batch_id FROM dual;
58708 END IF;
58709
58710 END LOOP;
58711
58712 lv_batch_last := lv_batch_id;
58713
58714 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
58715 UPDATE MSC_ST_SYSTEM_ITEMS
58716 SET batch_id = lb_batch(j)
58717 WHERE rowid = lb_rowid(j);
58718
58719 commit;
58720
58721 CREATE_INDEXES('ITEM');
58722 -- send out the batches to the workers' task Pipe
58723
58724 FOR j in lv_batch_start..lv_batch_last LOOP
58725 lv_message := to_char(TASK_ITEM)||','||to_char(j);
58726 DBMS_PIPE.PACK_MESSAGE(lv_message );
58727 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
58728 RAISE EX_PIPE_SND;
58729 END IF;
58730 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_ITEM: '||lv_message);
58731 lv_total_item_batches := lv_total_item_batches + 1;
58732 lv_task_not_completed := lv_task_not_completed + 1;
58733 END LOOP;
58734
58735 ELSE
58736 lv_message := to_char(TASK_ITEM)||','||to_char(0);
58737 DBMS_PIPE.PACK_MESSAGE(lv_message );
58738 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
58739 RAISE EX_PIPE_SND;
58740 END IF;
58741 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_ITEM: '||lv_message);
58742 lv_total_item_batches := lv_total_item_batches + 1;
58743 lv_task_not_completed := lv_task_not_completed + 1;
58744
58745
58746 END IF;
58747
58748 CLOSE c2;
58749 EXCEPTION
58750 when others then
58751 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Error in Item Batch ID generation: ' || SQLERRM);
58752 lv_message := to_char(TASK_ITEM)||','||to_char(0);
58753 DBMS_PIPE.PACK_MESSAGE(lv_message );
58754 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
58755 RAISE EX_PIPE_SND;
58756 END IF;
58757 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_ITEM: '||lv_message);
58758 lv_total_item_batches := lv_total_item_batches + 1;
58759 lv_task_not_completed := lv_task_not_completed + 1;
58760 END;
58761
58762 END;
58763
58764 ELSE
58765 -- kludge to launch the dependent tasks even if
58766 -- item is not enabled for processing
58767
58768 lv_message := to_char(TASK_ITEM)||','||to_char(0);
58769 DBMS_PIPE.PACK_MESSAGE(lv_message );
58770 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
58771 RAISE EX_PIPE_SND;
58772 END IF;
58773 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_ITEM: '||lv_message);
58774 lv_total_item_batches := lv_total_item_batches + 1;
58775 lv_task_not_completed := lv_task_not_completed + 1;
58776 END IF;
58777
58778 DBMS_LOCK.SLEEP( 5); -- initial estimated sleep time
58779
58780 LOOP
58781
58782 EXIT WHEN is_request_status_running <> SYS_YES;
58783
58784 EXIT WHEN is_worker_status_valid(lvs_request_id) <> SYS_YES;
58785
58786 lv_pipe_ret_code:= DBMS_PIPE.RECEIVE_MESSAGE( v_pipe_wm, PIPE_TIME_OUT);
58787
58788 IF lv_pipe_ret_code=0 THEN
58789 IF DBMS_PIPE.next_item_type <> 0 then
58790
58791 DBMS_PIPE.UNPACK_MESSAGE( lv_task_number );
58792
58793 IF lv_task_number>0 THEN -- If it's ok, the value is the task number
58794 lv_task_not_completed := lv_task_not_completed -1;
58795
58796 -- ======= Add the dependent Tasks to the task queue ==========
58797
58798 IF lv_task_number= TASK_ITEM THEN
58799 -- check whether all the item batches are completed
58800 -- if yes then put the dependent tasks in the task pipe
58801
58802 lv_item_batches_completed := lv_item_batches_completed + 1;
58803
58804 IF lv_item_batches_completed = lv_total_item_batches THEN
58805 /* Doing the piece dealing with items commented in Load_Items for the bug fix 2191021 */
58806 IF v_item_enabled = SYS_YES THEN
58807 LOAD_ITEM_ABC_CLASSES;
58808 END IF;
58809
58810 IF p_comp_users_enabled = SYS_YES AND v_MSC_CONFIGURATION IN(2,3) THEN
58811 lv_message := to_char(TASK_COMPANY_USERS);
58812 DBMS_PIPE.PACK_MESSAGE(lv_message);
58813 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
58814 RAISE EX_PIPE_SND;
58815 END IF;
58816 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_COMPANY_USERS: '||lv_message);
58817 lv_task_not_completed := lv_task_not_completed + 1;
58818 END IF;
58819
58820 IF p_uom_class_enabled = SYS_YES THEN
58821 lv_message := to_char(TASK_UOM_CONV);
58822 DBMS_PIPE.PACK_MESSAGE(lv_message);
58823 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
58824 RAISE EX_PIPE_SND;
58825 END IF;
58826 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_UOM_CONV: '||lv_message);
58827 lv_task_not_completed := lv_task_not_completed + 1;
58828 END IF;
58829
58830 IF p_item_cst_enabled = SYS_YES AND v_sce_installed THEN
58831 lv_message := to_char(TASK_ITEM_CST);
58832 DBMS_PIPE.PACK_MESSAGE(lv_message);
58833 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
58834 RAISE EX_PIPE_SND;
58835 END IF;
58836 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_ITEM_CST: '||lv_message);
58837 lv_task_not_completed := lv_task_not_completed + 1;
58838 END IF;
58839
58840
58841 lv_message := to_char(TASK_SUPPLIER_CAPACITY);
58842 DBMS_PIPE.PACK_MESSAGE(lv_message);
58843 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
58844 RAISE EX_PIPE_SND;
58845 END IF;
58846 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_SUPPLIER_CAPACITY: '||lv_message);
58847 lv_task_not_completed := lv_task_not_completed + 1;
58848
58849 lv_message := to_char(TASK_CAL_ASSIGNMENTS);
58850 DBMS_PIPE.PACK_MESSAGE(lv_message);
58851 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
58852 RAISE EX_PIPE_SND;
58853 END IF;
58854 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_CAL_ASSIGNMENTS: '||lv_message);
58855 lv_task_not_completed := lv_task_not_completed + 1;
58856
58857 lv_message := to_char(TASK_SALES_CHANNEL);
58858 DBMS_PIPE.PACK_MESSAGE(lv_message);
58859 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
58860 RAISE EX_PIPE_SND;
58861 END IF;
58862 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_SALES_CHANNEL: '||lv_message);
58863 lv_task_not_completed := lv_task_not_completed + 1;
58864
58865 lv_message := to_char(TASK_FISCAL_CALENDAR);
58866 DBMS_PIPE.PACK_MESSAGE(lv_message);
58867 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
58868 RAISE EX_PIPE_SND;
58869 END IF;
58870 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_FISCAL_CALENDAR: '||lv_message);
58871 lv_task_not_completed := lv_task_not_completed + 1;
58872
58873 lv_message := to_char(TASK_CMRO);
58874 DBMS_PIPE.PACK_MESSAGE(lv_message);
58875 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
58876 RAISE EX_PIPE_SND;
58877 END IF;
58878 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_CMRO: '||lv_message);
58879 lv_task_not_completed := lv_task_not_completed + 1;
58880
58881
58882
58883 lv_message := to_char(TASK_SAFETY_STOCK);
58884 DBMS_PIPE.PACK_MESSAGE(lv_message);
58885 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
58886 RAISE EX_PIPE_SND;
58887 END IF;
58888 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_SAFETY_STOCK: '||lv_message);
58889 lv_task_not_completed := lv_task_not_completed + 1;
58890
58891
58892 lv_message := to_char(TASK_CATEGORIES_SOURCING);
58893 DBMS_PIPE.PACK_MESSAGE(lv_message);
58894 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
58895 RAISE EX_PIPE_SND;
58896 END IF;
58897 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_CATEGORIES_SOURCING: '||lv_message);
58898 lv_task_not_completed := lv_task_not_completed + 1;
58899
58900 lv_message := to_char(TASK_DEPT_RESOURCES);
58901 DBMS_PIPE.PACK_MESSAGE(lv_message);
58902 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
58903 RAISE EX_PIPE_SND;
58904 END IF;
58905 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_DEPT_RESOURCES: '||lv_message);
58906 lv_task_not_completed := lv_task_not_completed + 1;
58907
58908 lv_message := to_char(TASK_ITEM_SUBSTITUTE);
58909 DBMS_PIPE.PACK_MESSAGE(lv_message);
58910 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
58911 RAISE EX_PIPE_SND;
58912 END IF;
58913 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_ITEM_SUBSTITUTE: '||lv_message);
58914 lv_task_not_completed := lv_task_not_completed + 1;
58915
58916
58917 IF p_fiscal_cal_enabled = SYS_YES THEN
58918 lv_message := to_char(TASK_FISCAL_TIME);
58919 DBMS_PIPE.PACK_MESSAGE(lv_message);
58920 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
58921 RAISE EX_PIPE_SND;
58922 END IF;
58923 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_FISCAL_TIME: '||lv_message);
58924 lv_task_not_completed := lv_task_not_completed + 1;
58925 END IF;
58926
58927
58928 IF p_comp_cal_enabled = SYS_YES THEN
58929 lv_message := to_char(TASK_COMPOSITE_TIME);
58930 DBMS_PIPE.PACK_MESSAGE(lv_message);
58931 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
58932 RAISE EX_PIPE_SND;
58933 END IF;
58934 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_COMPOSITE_TIME: '||lv_message);
58935 lv_task_not_completed := lv_task_not_completed + 1;
58936 END IF;
58937
58938
58939
58940 IF p_mat_sup_enabled = SYS_YES THEN
58941 -- divide material supply into batches and put each batch
58942 -- in the task pipe so that these can be picked up by the workers
58943 BEGIN
58944
58945 DECLARE
58946 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
58947 lb_rowid RowidTab;
58948 lb_batch NumTblTyp := NumTblTyp(0);
58949 lv_batch_id PLS_INTEGER;
58950 lv_batch_start PLS_INTEGER;
58951 lv_batch_last PLS_INTEGER;
58952 cursor c2 is SELECT rowid FROM msc_st_supplies
58953 WHERE PROCESS_FLAG IN(G_IN_PROCESS,G_ERROR_FLG)
58954 AND ORDER_TYPE IN(1,2,5,8,11,12,18,73,74,87,81)
58955 AND NVL(batch_id,NULL_VALUE) = NULL_VALUE
58956 AND sr_instance_code = v_instance_code;
58957 BEGIN
58958
58959 OPEN c2;
58960 FETCH c2 BULK COLLECT INTO lb_rowid ;
58961
58962 IF c2%ROWCOUNT > 0 THEN
58963
58964 SELECT msc_st_batch_id_s.NEXTVAL INTO lv_batch_id FROM dual;
58965 lv_batch_start := lv_batch_id;
58966 lb_batch.extend(lb_rowid.count);
58967
58968 FOR j IN lb_rowid.FIRST..lb_rowid.LAST LOOP
58969
58970 lb_batch(j):= lv_batch_id;
58971 IF MOD(j,v_batch_size) = 0 THEN
58972 SELECT msc_st_batch_id_s.NEXTVAL INTO lv_batch_id FROM dual;
58973 END IF;
58974
58975 END LOOP;
58976
58977 lv_batch_last := lv_batch_id;
58978
58979 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
58980 UPDATE msc_st_supplies
58981 SET batch_id = lb_batch(j)
58982 WHERE rowid = lb_rowid(j);
58983
58984 commit;
58985
58986 -- send out the batches to the workers' task Pipe
58987
58988 FOR j in lv_batch_start..lv_batch_last LOOP
58989 lv_message := to_char(TASK_MATERIAL_SUPPLY)||','||to_char(j);
58990 DBMS_PIPE.PACK_MESSAGE(lv_message);
58991 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
58992 RAISE EX_PIPE_SND;
58993 END IF;
58994 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_MATERIAL_SUPPLY: '||lv_message);
58995 lv_total_supply_batches := lv_total_supply_batches + 1;
58996 lv_task_not_completed := lv_task_not_completed + 1;
58997 END LOOP;
58998
58999 CREATE_INDEXES('SUPPLY');
59000
59001 END IF;
59002
59003 CLOSE c2;
59004 EXCEPTION
59005 when others then
59006 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_WARNING,'Error in Supplies Batch ID generation: ' || SQLERRM);
59007 END;
59008
59009 END;
59010
59011 END IF;
59012
59013
59014 IF p_mat_dmd_enabled = SYS_YES THEN
59015 -- divide material demand into batches and put each batch
59016 -- in the task pipe so that these can be picked up by the workers
59017 BEGIN
59018
59019 DECLARE
59020 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
59021 lb_rowid RowidTab;
59022 lb_batch NumTblTyp := NumTblTyp(0);
59023 lv_batch_id PLS_INTEGER;
59024 lv_batch_start PLS_INTEGER;
59025 lv_batch_last PLS_INTEGER;
59026 cursor c2 is SELECT rowid FROM msc_st_demands
59027 WHERE PROCESS_FLAG IN (G_IN_PROCESS,G_ERROR_FLG)
59028 AND origination_type IN (7,8,29)
59029 AND NVL(batch_id,NULL_VALUE) = NULL_VALUE
59030 AND sr_instance_code = v_instance_code;
59031
59032 BEGIN
59033
59034 OPEN c2;
59035 FETCH c2 BULK COLLECT INTO lb_rowid ;
59036
59037 IF c2%ROWCOUNT > 0 THEN
59038
59039 SELECT msc_st_batch_id_s.NEXTVAL INTO lv_batch_id FROM dual;
59040 lv_batch_start := lv_batch_id;
59041 lb_batch.extend(lb_rowid.count);
59042
59043 FOR j IN lb_rowid.FIRST..lb_rowid.LAST LOOP
59044
59045 lb_batch(j):= lv_batch_id;
59046 IF MOD(j,v_batch_size) = 0 THEN
59047 SELECT msc_st_batch_id_s.NEXTVAL INTO lv_batch_id FROM dual;
59048 END IF;
59049
59050 END LOOP;
59051
59052 lv_batch_last := lv_batch_id;
59053
59054 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
59055 UPDATE msc_st_demands
59056 SET batch_id = lb_batch(j)
59057 WHERE rowid = lb_rowid(j);
59058
59059 commit;
59060
59061 -- send out the batches to the workers' task Pipe
59062
59063 FOR j in lv_batch_start..lv_batch_last LOOP
59064 lv_message := to_char(TASK_MATERIAL_DEMAND)||','||to_char(j);
59065 DBMS_PIPE.PACK_MESSAGE(lv_message);
59066 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
59067 RAISE EX_PIPE_SND;
59068 END IF;
59069 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_MATERIAL_DEMAND: '||lv_message);
59070 lv_total_demand_batches := lv_total_demand_batches + 1;
59071 lv_task_not_completed := lv_task_not_completed + 1;
59072 END LOOP;
59073
59074 CREATE_INDEXES('DEMAND');
59075
59076 END IF;
59077
59078 CLOSE c2;
59079 EXCEPTION
59080 when others then
59081 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Error in Demands Batch ID generation: ' || SQLERRM);
59082 END;
59083
59084 END;
59085
59086
59087
59088
59089
59090 END IF; -- Demand is not enabled
59091
59092 END IF; -- all items batches completed
59093
59094 ELSIF lv_task_number= TASK_ITEM_SUBSTITUTE THEN
59095
59096 IF p_mat_dmd_enabled = SYS_YES THEN
59097
59098 -- divide sales order demand into batches and put each batch
59099 -- in the task pipe so that these can be picked up by the workers
59100 BEGIN
59101
59102 DECLARE
59103 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
59104 lb_rowid RowidTab;
59105 lb_batch NumTblTyp := NumTblTyp(0);
59106 lv_batch_id PLS_INTEGER;
59107 lv_batch_start PLS_INTEGER;
59108 lv_batch_last PLS_INTEGER;
59109 cursor c2 is SELECT rowid FROM msc_st_sales_orders
59110 WHERE PROCESS_FLAG IN (G_IN_PROCESS,G_ERROR_FLG)
59111 AND NVL(batch_id,NULL_VALUE) = NULL_VALUE
59112 AND sr_instance_code = v_instance_code;
59113
59114 BEGIN
59115
59116 OPEN c2;
59117 FETCH c2 BULK COLLECT INTO lb_rowid ;
59118
59119 IF c2%ROWCOUNT > 0 THEN
59120
59121 SELECT msc_st_batch_id_s.NEXTVAL INTO lv_batch_id FROM dual;
59122 lv_batch_start := lv_batch_id;
59123 lb_batch.extend(lb_rowid.count);
59124
59125 FOR j IN lb_rowid.FIRST..lb_rowid.LAST LOOP
59126
59127 lb_batch(j):= lv_batch_id;
59128 IF MOD(j,v_batch_size) = 0 THEN
59129 SELECT msc_st_batch_id_s.NEXTVAL INTO lv_batch_id FROM dual;
59130 END IF;
59131
59132 END LOOP;
59133
59134 lv_batch_last := lv_batch_id;
59135
59136 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
59137 UPDATE msc_st_sales_orders
59138 SET batch_id = lb_batch(j)
59139 WHERE rowid = lb_rowid(j);
59140
59141 commit;
59142
59143 -- send out the batches to the workers' task Pipe
59144
59145 FOR j in lv_batch_start..lv_batch_last LOOP
59146 lv_message := to_char(TASK_SO_DEMAND)||','||to_char(j);
59147 DBMS_PIPE.PACK_MESSAGE(lv_message);
59148 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
59149 RAISE EX_PIPE_SND;
59150 END IF;
59151 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_SO_DEMAND: '||lv_message);
59152 lv_total_demand_batches := lv_total_demand_batches + 1;
59153 lv_task_not_completed := lv_task_not_completed + 1;
59154 END LOOP;
59155
59156 CREATE_INDEXES('SO');
59157 ELSE
59158 lv_message := to_char(TASK_SO_DEMAND)||','||to_char(0);
59159 DBMS_PIPE.PACK_MESSAGE(lv_message );
59160 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
59161 RAISE EX_PIPE_SND;
59162 END IF;
59163 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_SO_DEMAND: '||lv_message);
59164 lv_total_demand_batches := lv_total_demand_batches + 1;
59165 lv_task_not_completed := lv_task_not_completed + 1;
59166 END IF;
59167
59168 CLOSE c2;
59169 EXCEPTION
59170 when others then
59171 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Error in Sales Order Demands Batch ID generation: ' || SQLERRM);
59172 lv_message := to_char(TASK_SO_DEMAND)||','||to_char(0);
59173 DBMS_PIPE.PACK_MESSAGE(lv_message );
59174 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
59175 RAISE EX_PIPE_SND;
59176 END IF;
59177 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_SO_DEMAND: '||lv_message);
59178 lv_total_demand_batches := lv_total_demand_batches + 1;
59179 lv_task_not_completed := lv_task_not_completed + 1;
59180
59181 END;
59182
59183 END;
59184
59185 ELSE -- demand is not enabled
59186 -- kludge to launch the dependent tasks even if
59187 -- demand is not enabled for processing
59188
59189 lv_message := to_char(TASK_SO_DEMAND)||','||to_char(0);
59190 DBMS_PIPE.PACK_MESSAGE(lv_message );
59191 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
59192 RAISE EX_PIPE_SND;
59193 END IF;
59194 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_SO_DEMAND: '||lv_message);
59195 lv_total_demand_batches := lv_total_demand_batches + 1;
59196 lv_task_not_completed := lv_task_not_completed + 1;
59197
59198 END IF; -- Demand is not enabled
59199
59200 /* ELSIF lv_task_number= TASK_SO_DEMAND THEN
59201
59202 lv_demand_batches_completed := lv_demand_batches_completed + 1;
59203
59204 IF lv_demand_batches_completed = lv_total_demand_batches THEN
59205
59206 lv_message := to_char(TASK_RESERVATION);
59207 DBMS_PIPE.PACK_MESSAGE(lv_message);
59208 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
59209 RAISE EX_PIPE_SND;
59210 END IF;
59211 LOG_MESSAGE('TASK_RESERVATION: '||lv_message);
59212
59213 lv_task_not_completed := lv_task_not_completed + 1;
59214 END IF; -- all SO batches completed
59215 */ -- task_reservation has been shifted to monitor
59216
59217 ELSIF lv_task_number= TASK_DEPT_RESOURCES THEN
59218
59219 lv_message := to_char(TASK_BOM_ROUTING);
59220 DBMS_PIPE.PACK_MESSAGE(lv_message);
59221 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
59222 RAISE EX_PIPE_SND;
59223 END IF;
59224 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_BOM_ROUTING: '||lv_message);
59225
59226 lv_task_not_completed := lv_task_not_completed + 1;
59227
59228
59229
59230 ELSIF lv_task_number= TASK_BOM_ROUTING THEN
59231
59232 lv_message := to_char(TASK_RESOURCE_DEMAND);
59233 DBMS_PIPE.PACK_MESSAGE(lv_message);
59234 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
59235 RAISE EX_PIPE_SND;
59236 END IF;
59237 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_RESOURCE_DEMAND: '||lv_message);
59238
59239 lv_task_not_completed := lv_task_not_completed + 1;
59240
59241 lv_message := to_char(TASK_IRO);
59242 DBMS_PIPE.PACK_MESSAGE(lv_message);
59243 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
59244 RAISE EX_PIPE_SND;
59245 END IF;
59246
59247 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_IRO: '||lv_message);
59248 lv_task_not_completed := lv_task_not_completed + 1;
59249
59250 lv_message := to_char(TASK_ERO);
59251 DBMS_PIPE.PACK_MESSAGE(lv_message);
59252 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
59253 RAISE EX_PIPE_SND;
59254 END IF;
59255 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_ERO: '||lv_message);
59256 lv_task_not_completed := lv_task_not_completed + 1;
59257
59258
59259
59260 -- END IF; -- lv_task_number= TASK_ITEM/ lv_task_number= TASK_DEPT_RESOURCES
59261
59262 ELSIF lv_task_number= TASK_CATEGORIES_SOURCING THEN
59263
59264 IF p_level_value_enabled = SYS_YES THEN
59265 -- divide level values into batches and put each batch
59266 -- in the task pipe so that these can be picked up by the workers
59267 BEGIN
59268
59269 DECLARE
59270 TYPE RowidTab IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
59271 lb_rowid RowidTab;
59272 lb_batch NumTblTyp := NumTblTyp(0);
59273 lv_batch_id PLS_INTEGER;
59274 lv_batch_start PLS_INTEGER;
59275 lv_batch_last PLS_INTEGER;
59276
59277 cursor c2 is SELECT rowid FROM msd_st_level_values
59278 WHERE PROCESS_FLAG IN(G_IN_PROCESS,G_ERROR_FLG)
59279 AND NVL(batch_id,NULL_VALUE) = NULL_VALUE
59280 AND sr_instance_code = v_instance_code;
59281
59282 BEGIN
59283
59284 OPEN c2;
59285 FETCH c2 BULK COLLECT INTO lb_rowid ;
59286
59287 IF c2%ROWCOUNT > 0 THEN
59288
59289 SELECT msc_st_batch_id_s.NEXTVAL INTO lv_batch_id FROM dual;
59290 lv_batch_start := lv_batch_id;
59291 lb_batch.extend(lb_rowid.count);
59292
59293 FOR j IN lb_rowid.FIRST..lb_rowid.LAST LOOP
59294
59295 lb_batch(j):= lv_batch_id;
59296 IF MOD(j,v_batch_size) = 0 THEN
59297 SELECT msc_st_batch_id_s.NEXTVAL INTO lv_batch_id FROM dual;
59298 END IF;
59299
59300 END LOOP;
59301
59302 lv_batch_last := lv_batch_id;
59303
59304 FORALL j IN lb_rowid.FIRST..lb_rowid.LAST
59305 UPDATE msd_st_level_values
59306 SET batch_id = lb_batch(j)
59307 WHERE rowid = lb_rowid(j);
59308
59309 commit;
59310
59311 -- send out the batches to the workers' task Pipe
59312
59313 FOR j in lv_batch_start..lv_batch_last LOOP
59314 lv_message := to_char(TASK_LEVEL_VALUE)||','||to_char(j);
59315 DBMS_PIPE.PACK_MESSAGE(lv_message);
59316 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
59317 RAISE EX_PIPE_SND;
59318 END IF;
59319 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_SO_DEMAND: '||lv_message);
59320 lv_total_lvalue_batches := lv_total_lvalue_batches + 1;
59321 lv_task_not_completed := lv_task_not_completed + 1;
59322 END LOOP;
59323 -- CREATE_INDEXES('LEVEL_VALUE');
59324 ELSE
59325 lv_message := to_char(TASK_LEVEL_VALUE)||','||to_char(0);
59326 DBMS_PIPE.PACK_MESSAGE(lv_message );
59327 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
59328 RAISE EX_PIPE_SND;
59329 END IF;
59330 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_LEVEL_VALUE: '||lv_message);
59331 lv_total_lvalue_batches := lv_total_lvalue_batches + 1;
59332 lv_task_not_completed := lv_task_not_completed + 1;
59333 END IF;
59334
59335 CLOSE c2;
59336
59337 EXCEPTION
59338 when others then
59339 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'Error in Batch ID generation: ' || SQLERRM);
59340 lv_message := to_char(TASK_LEVEL_VALUE)||','||to_char(0);
59341 DBMS_PIPE.PACK_MESSAGE(lv_message );
59342 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
59343 RAISE EX_PIPE_SND;
59344 END IF;
59345 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_LEVEL_VALUE: '||lv_message);
59346 lv_total_lvalue_batches := lv_total_lvalue_batches + 1;
59347 lv_task_not_completed := lv_task_not_completed + 1;
59348
59349 END;
59350 END ;
59351
59352 ELSE -- level_value is not enabled
59353 -- kludge to launch the dependent tasks even if
59354 -- level_value is not enabled for processing
59355
59356 lv_message := to_char(TASK_LEVEL_VALUE)||','||to_char(0);
59357 DBMS_PIPE.PACK_MESSAGE(lv_message );
59358 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
59359 RAISE EX_PIPE_SND;
59360 END IF;
59361 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'TASK_LEVEL_VALUE: '||lv_message);
59362 lv_total_lvalue_batches := lv_total_lvalue_batches + 1;
59363 lv_task_not_completed := lv_task_not_completed + 1;
59364
59365 END IF; -- Level Value is not enabled
59366
59367 ELSIF lv_task_number= TASK_LEVEL_VALUE THEN
59368 lv_lvalue_batches_completed := lv_lvalue_batches_completed+1 ;
59369
59370 IF lv_lvalue_batches_completed = lv_total_lvalue_batches THEN
59371
59372
59373 IF v_level_assoc_enabled = SYS_YES THEN
59374 DIVIDE_BATCHES (p_table_name => 'MSD_ST_LEVEL_ASSOCIATIONS' ,
59375 p_task_name => TASK_LEVEL_ASSOCIATION,
59376 p_task_not_completed =>lv_task_not_completed,
59377 p_pipe_status => lv_pipe_status );
59378 IF(lv_pipe_status = 1) THEN
59379 RAISE EX_PIPE_SND;
59380 END IF;
59381 END IF;
59382
59383
59384 IF v_booking_enabled = SYS_YES THEN
59385 DIVIDE_BATCHES (p_table_name => 'MSD_ST_BOOKING_DATA' ,
59386 p_task_name => TASK_BOOKING_DATA,
59387 p_task_not_completed =>lv_task_not_completed,
59388 p_pipe_status => lv_pipe_status );
59389 IF(lv_pipe_status = 1) THEN
59390 RAISE EX_PIPE_SND;
59391 END IF;
59392
59393 END IF;
59394
59395 IF v_shipment_enabled = SYS_YES THEN
59396 DIVIDE_BATCHES (p_table_name => 'MSD_ST_SHIPMENT_DATA' ,
59397 p_task_name => TASK_SHIPMENT_DATA,
59398 p_task_not_completed =>lv_task_not_completed,
59399 p_pipe_status => lv_pipe_status );
59400 IF(lv_pipe_status = 1) THEN
59401 RAISE EX_PIPE_SND;
59402 END IF;
59403 END IF;
59404
59405 IF v_mfg_fct_enabled = SYS_YES THEN
59406 DIVIDE_BATCHES (p_table_name => 'MSD_ST_MFG_FORECAST' ,
59407 p_task_name => TASK_MFG_FORECAST,
59408 p_task_not_completed =>lv_task_not_completed,
59409 p_pipe_status => lv_pipe_status );
59410 IF(lv_pipe_status = 1) THEN
59411 RAISE EX_PIPE_SND;
59412 END IF;
59413 END IF;
59414
59415 IF v_list_price_enabled = SYS_YES THEN
59416 DIVIDE_BATCHES (p_table_name => 'MSD_ST_PRICE_LIST' ,
59417 p_task_name => TASK_PRICE_LIST,
59418 p_task_not_completed =>lv_task_not_completed,
59419 p_pipe_status => lv_pipe_status );
59420
59421 IF(lv_pipe_status = 1) THEN
59422 RAISE EX_PIPE_SND;
59423 END IF;
59424 /*
59425 DIVIDE_BATCHES (p_table_name => 'MSD_ST_ITEM_LIST_PRICE' ,
59426 p_task_name => TASK_ITEM_LIST_PRICE,
59427 p_task_not_completed =>lv_task_not_completed,
59428 p_pipe_status => lv_pipe_status );
59429
59430 IF(lv_pipe_status = 1) THEN
59431 RAISE EX_PIPE_SND;
59432 END IF;
59433 */
59434 END IF;
59435
59436 IF v_cs_data_enabled = SYS_YES THEN
59437 DIVIDE_BATCHES (p_table_name => 'MSD_ST_CS_DATA' ,
59438 p_task_name => TASK_CS_DATA,
59439 p_task_not_completed =>lv_task_not_completed,
59440 p_pipe_status => lv_pipe_status );
59441
59442 IF(lv_pipe_status = 1) THEN
59443 RAISE EX_PIPE_SND;
59444 END IF;
59445
59446 END IF;
59447
59448 IF v_curr_conv_enabled = SYS_YES THEN
59449 DIVIDE_BATCHES (p_table_name => 'MSD_ST_CURRENCY_CONVERSIONS' ,
59450 p_task_name => TASK_CURR_CONV,
59451 p_task_not_completed =>lv_task_not_completed,
59452 p_pipe_status => lv_pipe_status );
59453 IF(lv_pipe_status = 1) THEN
59454 RAISE EX_PIPE_SND;
59455 END IF;
59456
59457 END IF;
59458
59459 IF v_uom_conv_enabled = SYS_YES THEN
59460 DIVIDE_BATCHES (p_table_name => 'MSD_ST_UOM_CONVERSIONS' ,
59461 p_task_name => TASK_DP_UOM_CONV,
59462 p_task_not_completed =>lv_task_not_completed,
59463 p_pipe_status => lv_pipe_status );
59464 IF(lv_pipe_status = 1) THEN
59465 RAISE EX_PIPE_SND;
59466 END IF;
59467 END IF; --v_dp_uom_conv_enabled
59468
59469 END IF; -- all level value batch completed
59470
59471 END IF ; --lv_task_number = TASK_ITEM
59472
59473
59474 IF lv_task_not_completed= 0 THEN
59475 EXIT;
59476 END IF;
59477
59478 ELSE -- lv_task_number is not greater than 0
59479
59480 EXIT;
59481
59482 /* not required since worker always send unresolvable errors
59483 ** even if we enable this how do we get the batch id ?
59484 EXIT WHEN lv_task_number= UNRESOVLABLE_ERROR;
59485 lv_message := to_char (-lv_task_number);
59486 DBMS_PIPE.PACK_MESSAGE(lv_message); -- resend the task to the task que
59487 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
59488 RAISE EX_PIPE_SND;
59489 END IF;
59490 */
59491
59492 END IF; -- lv_task_number > 0
59493
59494 END IF; -- DBMS_PIPE.next_item_type <> 0
59495
59496 ELSIF lv_pipe_ret_code <> 1 THEN -- not time out, either 2 (record too big for buffer) or 3 (interuppted)
59497
59498 RAISE EX_PIPE_RCV;
59499
59500 END IF;
59501
59502 -- ============= Check the execution time ==============
59503
59504 select (SYSDATE- START_TIME) into lv_process_time from dual;
59505
59506 IF lv_process_time > p_timeout/1440.0 THEN Raise EX_PROCESS_TIME_OUT; END IF;
59507
59508 END LOOP;
59509
59510 lv_check_point:= 3;
59511
59512 if p_reserve_enabled =SYS_YES then
59513 LOAD_RESERVATION;
59514 end if ;
59515
59516 IF lv_task_not_completed > 0 THEN
59517
59518 DBMS_PIPE.PURGE( v_pipe_task_que);
59519
59520 lv_task_number:= -1;
59521
59522 ROLLBACK;
59523
59524 FND_MESSAGE.SET_NAME('MSC', 'MSC_PP_FAIL');
59525 ERRBUF:= FND_MESSAGE.GET;
59526 RETCODE := G_ERROR;
59527 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS, ERRBUF);
59528
59529 ELSE
59530
59531 lv_task_number:= TASK_ALL_COMPLETED;
59532
59533 UPDATE MSC_APPS_INSTANCES mai
59534 SET LAST_UPDATE_DATE= v_current_date,
59535 LAST_UPDATED_BY= v_current_user,
59536 REQUEST_ID= FND_GLOBAL.CONC_REQUEST_ID
59537 WHERE mai.INSTANCE_ID= v_instance_id;
59538
59539 FND_MESSAGE.SET_NAME('MSC', 'MSC_PP_SUCCEED');
59540 ERRBUF:= FND_MESSAGE.GET;
59541 RETCODE := G_SUCCESS;
59542 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS, ERRBUF);
59543
59544 FINAL;
59545
59546 END IF;
59547
59548 IF SET_ST_STATUS( ERRBUF, RETCODE, p_instance_id, G_ST_READY) THEN
59549 NULL;
59550 END IF;
59551
59552 FOR lc_i IN 1..p_total_worker_num LOOP
59553
59554 lv_message := to_char(lv_task_number);
59555 DBMS_PIPE.PACK_MESSAGE( lv_message);
59556 IF DBMS_PIPE.SEND_MESSAGE( v_pipe_task_que)<>0 THEN
59557 RAISE EX_PIPE_SND;
59558 END IF;
59559 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,'v_pipe_task_que: '||lv_message);
59560
59561 END LOOP;
59562
59563 lv_worker_committed:= 0;
59564
59565 lv_start_time:= SYSDATE;
59566
59567 LOOP
59568
59569 lv_pipe_ret_code:= DBMS_PIPE.RECEIVE_MESSAGE( v_pipe_status, PIPE_TIME_OUT);
59570
59571 IF lv_pipe_ret_code=0 THEN
59572
59573 lv_worker_committed:= lv_worker_committed+1;
59574
59575 EXIT WHEN lv_worker_committed= p_total_worker_num;
59576
59577 ELSIF lv_pipe_ret_code<> 1 THEN
59578 RAISE EX_PIPE_RCV; -- If the error is not time-out error
59579 END IF;
59580
59581 -- WHY ?
59582 -- SELECT (SYSDATE- lv_start_time) INTO lv_process_time FROM dual;
59583 -- EXIT WHEN lv_process_time > 10.0/1440.0; -- wait for 10 minutes
59584
59585 END LOOP;
59586
59587 IF lv_worker_committed<> p_total_worker_num THEN
59588
59589 FND_MESSAGE.SET_NAME('MSC', 'MSC_PP_FAIL_TO_COMMIT');
59590 ERRBUF:= FND_MESSAGE.GET;
59591 RETCODE := G_ERROR;
59592
59593 END IF;
59594
59595 IF RETCODE= G_ERROR THEN RETURN; END IF;
59596
59597 -- send error/ warning emails for the errors/ warnings encountered
59598 -- during pre processing
59599 -- SEND_ERROR ;
59600
59601 -- get current ERROR_ID from MSC_ERRORS
59602 IF (nvl(v_parent_request_id,-1) < 1) THEN
59603 select max(ERROR_ID) into v_error_no_end from MSC_ERRORS;
59604 END IF;
59605
59606 -- write summary of errors and warning encountered into log
59607 WRITE_ERROR_SUMM_LOG(nvl(v_parent_request_id,-1));
59608
59609 DROP_INDEXES;
59610
59611 END IF; --Handling of New Request and calendar sub-request completes
59612
59613 LAUNCH_DELETE_DUPLICATES(ERRBUF =>ERRBUF , RETCODE => RETCODE) ;
59614
59615 LAUNCH_DP_PULL(ERRBUF =>ERRBUF , RETCODE => RETCODE) ;
59616
59617 IF ( ( nvl(RETCODE,-1) <> G_WARNING) AND ( nvl(RETCODE,-1) <> G_ERROR) ) THEN
59618
59619 OPEN Warn_Flag;
59620 FETCH Warn_Flag INTO v_warning_flag;
59621 CLOSE Warn_Flag;
59622
59623 IF v_warning_flag=SYS_YES THEN
59624 RETCODE:= G_WARNING;
59625 ELSE
59626 RETCODE := G_SUCCESS;
59627 END IF;
59628
59629 END IF;
59630
59631 --Exit the program if Level Values is submitted as a child request and then
59632 --resume the processing when the processing of Level values is completed.
59633 IF nvl(fnd_conc_global.request_data,G_NEW_REQUEST) = G_DP_LV_REQ_DATA THEN
59634 RETURN;
59635 END IF;
59636
59637 -- OA Self Service load changes
59638 -- If request id is not -1 or null then pre-processor is called from OA
59639 -- launch ODS load if this instance of pre-processor is called from OA
59640 -- bug# 2383498 - always launch ODS load for DP
59641 -- IF ((nvl(v_parent_request_id,-1) > 0) OR (p_calling_module = G_DP AND v_bom_enabled = SYS_YES)) THEN
59642 IF ((nvl(v_parent_request_id,-1) > 0) OR (p_calling_module = G_DP)) THEN
59643 lv_monitor_id := fnd_request.submit_request('MSC',
59644 'MSCPDC',
59645 NULL,
59646 NULL,
59647 TRUE,
59648 v_instance_id,
59649 p_timeout,
59650 p_total_worker_num,
59651 p_resources_enabled,
59652 SYS_NO,
59653 SYS_NO);
59654
59655
59656 IF lv_monitor_id <> 0 THEN
59657 fnd_conc_global.set_req_globals(conc_status => 'PAUSED',
59658 request_data => to_char(G_ODS_REQ_DATA)) ;
59659 FND_MESSAGE.SET_NAME('MSC', 'MSC_PP_WORKER_REQUEST_ID');
59660 FND_MESSAGE.SET_TOKEN('REQUEST_ID', lv_monitor_id);
59661 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,FND_MESSAGE.GET);
59662 END IF;
59663
59664 commit;
59665
59666 END IF;
59667
59668 EXCEPTION -- LAUNCH_MONITOR
59669
59670 WHEN EX_PIPE_RCV THEN
59671 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_FATAL_ERR,dbms_utility.format_error_stack);
59672 ROLLBACK;
59673
59674 IF lv_check_point> 1 THEN
59675 IF SET_ST_STATUS( ERRBUF, RETCODE, p_instance_id, G_ST_READY) THEN
59676 NULL;
59677 END IF;
59678 DROP_INDEXES;
59679 END IF;
59680
59681 RETCODE := G_ERROR;
59682 FND_MESSAGE.SET_NAME('MSC', 'MSC_MSG_RCV_FAIL');
59683 FND_MESSAGE.SET_TOKEN('PIPE', v_pipe_wm);
59684 ERRBUF:= FND_MESSAGE.GET;
59685 RETCODE := G_ERROR;
59686 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_FATAL_ERR, ERRBUF);
59687
59688 IF lv_check_point < 3 THEN
59689 FND_MESSAGE.SET_NAME('MSC', 'MSC_PP_FAIL');
59690 ERRBUF:= FND_MESSAGE.GET;
59691 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,ERRBUF);
59692 END IF;
59693
59694 COMMIT;
59695
59696 WHEN EX_PIPE_SND THEN
59697 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_FATAL_ERR,dbms_utility.format_error_stack);
59698 ROLLBACK;
59699
59700 IF lv_check_point> 1 THEN
59701 IF SET_ST_STATUS( ERRBUF, RETCODE, p_instance_id, G_ST_READY) THEN
59702 NULL;
59703 END IF;
59704 DROP_INDEXES;
59705 END IF;
59706
59707 FND_MESSAGE.SET_NAME('MSC', 'MSC_MSG_SEND_FAIL');
59708 FND_MESSAGE.SET_TOKEN('PIPE', v_pipe_wm);
59709 ERRBUF:= FND_MESSAGE.GET;
59710 RETCODE := G_ERROR;
59711 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_FATAL_ERR,ERRBUF);
59712
59713 IF lv_check_point < 3 THEN
59714 FND_MESSAGE.SET_NAME('MSC', 'MSC_PP_FAIL');
59715 ERRBUF:= FND_MESSAGE.GET;
59716 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS,ERRBUF);
59717 END IF;
59718
59719 COMMIT;
59720
59721 WHEN EX_PROCESS_TIME_OUT THEN
59722 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_FATAL_ERR,dbms_utility.format_error_stack);
59723 ROLLBACK;
59724
59725 IF lv_check_point> 1 THEN
59726 IF SET_ST_STATUS( ERRBUF, RETCODE, p_instance_id, G_ST_READY) THEN
59727 NULL;
59728 END IF;
59729 DROP_INDEXES;
59730 END IF;
59731
59732 FND_MESSAGE.SET_NAME('MSC', 'MSC_TIMEOUT');
59733 ERRBUF:= FND_MESSAGE.GET;
59734 RETCODE := G_ERROR;
59735 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_FATAL_ERR,ERRBUF);
59736
59737 IF lv_check_point < 3 THEN
59738 FND_MESSAGE.SET_NAME('MSC', 'MSC_PP_FAIL');
59739 ERRBUF:= FND_MESSAGE.GET;
59740 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS, ERRBUF);
59741 END IF;
59742
59743 COMMIT;
59744
59745
59746 WHEN others THEN
59747 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_FATAL_ERR,dbms_utility.format_error_stack);
59748 ROLLBACK;
59749
59750 IF lv_check_point> 1 THEN
59751 IF SET_ST_STATUS( ERRBUF, RETCODE, p_instance_id, G_ST_READY) THEN
59752 NULL;
59753 END IF;
59754 END IF;
59755
59756 ERRBUF := SQLERRM;
59757 RETCODE := G_ERROR;
59758 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_FATAL_ERR,ERRBUF);
59759
59760 IF lv_check_point < 3 THEN
59761 FND_MESSAGE.SET_NAME('MSC', 'MSC_PP_FAIL');
59762 ERRBUF:= FND_MESSAGE.GET;
59763 MSC_UTIL.LOG_MSG(MSC_UTIL.G_LVL_STATUS, ERRBUF);
59764 END IF;
59765
59766 COMMIT;
59767
59768 END LAUNCH_MONITOR;
59769
59770 END MSC_CL_PRE_PROCESS;