DBA Data[Home] [Help]

PACKAGE BODY: APPS.CONVERT_TEST

Source


1 PACKAGE BODY CONVERT_TEST AS
2 /* $Header: WMSCGUGB.pls 120.1 2005/06/15 14:31:58 appldev  $*/
3 
4 PROCEDURE INVMSISB(
5 		    l_organization_id 	IN  	NUMBER,
6 		   USER_NAME           IN      VARCHAR2,
7 		    PASSWORD            IN      VARCHAR2,
8 		    x_return_status	  	OUT NOCOPY 	VARCHAR2,
9 		    x_msg_count       	OUT NOCOPY 	NUMBER,
10 		    x_msg_data        	OUT NOCOPY 	VARCHAR2) AS
11 
12 
13    -- --------------------------------------------------------
14    -- Subinventories that do not have a default cost group yet
15    -- --------------------------------------------------------
16 
17 
18    cursor subinventory_cursor is
19    select
20      rowid
21    , secondary_inventory_name
22    , material_account
23    , material_overhead_account
24    , resource_account
25    , overhead_account
26    , outside_processing_account
27    , expense_account
28    , encumbrance_account
29 
30     from mtl_secondary_inventories
31    where (
32 	  default_cost_group_id is null AND
33           organization_id = l_organization_id
34          );
35 --  l_organization_id 		number; */
36 
37    l_secondary_inventory_name   varchar2(10);
38 
39    l_material_account           number;
40    l_material_overhead_account  number;
41    l_resource_account           number;
42    l_overhead_account           number;
43    l_outside_processing_account number;
44    l_expense_account            number;
45    l_encumbrance_account        number;
46 
47    l_return_status		varchar2(1);
48    l_msg_count                  number;
49    l_msg_data                   varchar2(240);
50 
51    l_cost_group_id              number;
52    l_cost_group_id_tbl 		cstpcgut.cost_group_tbl;
53    l_count			number;
54 
55    l_return_err			varchar2(280);
56 
57    l_rowid_info                 VARCHAR2(2000);
58    l_table_name                 VARCHAR2(300);
59    l_procedure_name             VARCHAR2(200):= 'upgrade subinventory data INVMSISB';
60 
61 begin
62    l_table_name := 'MTL_SECONDARY_INVENTORIES';
63    for c1 in subinventory_cursor
64 
65      loop
66 
67 
68 --	/*
69 --       Load cursor output into local variables
70 --
71 --	  l_organization_id 	     := c1.organization_id;
72 --	*/
73 
74       l_rowid_info                   := c1.ROWID;
75       	l_secondary_inventory_name   := c1.secondary_inventory_name;
76 
77    	l_material_account           := c1.material_account;
78    	l_material_overhead_account  := c1.material_overhead_account;
79    	l_resource_account           := c1.resource_account;
80    	l_overhead_account           := c1.overhead_account;
81    	l_outside_processing_account := c1.outside_processing_account;
82    	l_expense_account            := c1.expense_account;
83    	l_encumbrance_account        := c1.encumbrance_account;
84 
85         /*
86 	dbms_output.put_line('Org:' || to_char(l_organization_id));
87 	dbms_output.put_line('Sub:' || l_secondary_inventory_name);
88 
89 	dbms_output.put_line('MA:'  || to_char(l_material_account));
90 	dbms_output.put_line('MOA:' || to_char(l_material_overhead_account));
91 	dbms_output.put_line('RA:'  || to_char(l_resource_account));
92 	dbms_output.put_line('OA:'  || to_char(l_overhead_account));
93 	dbms_output.put_line('OPA:' || to_char(l_outside_processing_account));
94 	dbms_output.put_line('EA:'  || to_char(l_expense_account));
95 	dbms_output.put_line('EnA:' || to_char(l_encumbrance_account));
96         */
97 
98 	/*
99         ** See if there is there a cost group with matching accounts
100         */
101         cstpcgut.get_cost_group(
102 	  x_return_status     		=> l_return_status
103         , x_msg_count         		=> l_msg_count
104         , x_msg_data          		=> l_msg_data
105         , x_cost_group_id_tbl 		=> l_cost_group_id_tbl
106         , x_count             		=> l_count
107    	, p_material_account         	=> l_material_account
108    	, p_material_overhead_account  	=> l_material_overhead_account
109    	, p_resource_account           	=> l_resource_account
110    	, p_overhead_account           	=> l_overhead_account
111    	, p_outside_processing_account 	=> l_outside_processing_account
112    	, p_expense_account            	=> l_expense_account
113    	, p_encumbrance_account        	=> l_encumbrance_account
114         , p_organization_id		=> l_organization_id  --NULL
115         , p_cost_group_type_id          => 3);
116 
117 	IF l_return_status = fnd_api.g_ret_sts_error THEN
118          	RAISE fnd_api.g_exc_error;
119     	END IF ;
120 
121     	IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
122 		/*
123 		dbms_output.put_line('Org:' || to_char(l_organization_id));
124 		dbms_output.put_line('Sub:' || l_secondary_inventory_name);
125 
126 		dbms_output.put_line('MA:'  || to_char(l_material_account));
127 		dbms_output.put_line('MOA:' || to_char(l_material_overhead_account));
128 		dbms_output.put_line('RA:'  || to_char(l_resource_account));
129 		dbms_output.put_line('OA:'  || to_char(l_overhead_account));
130 		dbms_output.put_line('OPA:' || to_char(l_outside_processing_account));
131 		dbms_output.put_line('EA:'  || to_char(l_expense_account));
132 		dbms_output.put_line('EnA:' || to_char(l_encumbrance_account));
133 		*/
134          	RAISE fnd_api.g_exc_unexpected_error;
135     	END IF;
136 
137         /*
138         ** If there is a cost group matching accounts use it else create
139         ** a new one
140         */
141         if (l_count > 0) then
142 	  l_cost_group_id := l_cost_group_id_tbl(1);
143         else
144           cstpcgut.create_cost_group(
145 	    x_return_status     		=> l_return_status
146           , x_msg_count         		=> l_msg_count
147           , x_msg_data          		=> l_msg_data
148           , x_cost_group_id 			=> l_cost_group_id
149           , p_cost_group             		=> NULL
150    	  , p_material_account         		=> l_material_account
151    	  , p_material_overhead_account  	=> l_resource_account
152    	  , p_resource_account           	=> l_resource_account
153    	  , p_overhead_account           	=> l_overhead_account
154    	  , p_outside_processing_account 	=> l_outside_processing_account
155    	  , p_expense_account            	=> l_expense_account
156    	  , p_encumbrance_account        	=> l_encumbrance_account
157           , p_organization_id			=> l_organization_id  -- NULL
158           , p_cost_group_type_id          	=> 3);
159 
160 	  IF l_return_status = fnd_api.g_ret_sts_error THEN
161          	RAISE fnd_api.g_exc_error;
162     	  END IF ;
163 
164     	  IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
165          	RAISE fnd_api.g_exc_unexpected_error;
166     	  END IF;
167         end if;
168 
169         /*
170         ** Stamp default cost group on subinventory record
171         */
172         update mtl_secondary_inventories
173         set default_cost_group_id = l_cost_group_id
174         where organization_id     	= l_organization_id
175         and   secondary_inventory_name 	= l_secondary_inventory_name;
176 
177      end loop;
178 
179      IF(subinventory_cursor%isopen) THEN CLOSE subinventory_cursor; END IF;
180    COMMIT;
181 
182 EXCEPTION
183 
184      when fnd_api.g_exc_error THEN
185 
186 	rollback;
187 	 IF(subinventory_cursor%isopen) THEN CLOSE subinventory_cursor; END IF;
188             x_return_status := fnd_api.g_ret_sts_error ;
189       --  Get message count and data
190       fnd_msg_pub.count_and_get
191           (  p_count  => l_msg_count
192            , p_data   => l_msg_data
193             );
194 
195       l_msg_data := replace(l_msg_data,chr(0),' ');
196 
197       l_return_err := 'mtl_secondary_inventories default cost group upgrade:'|| l_msg_data;
198       INS_ERROR(   p_table_name  => l_table_name,
199 		   p_ROWID       => l_rowid_info,
200 		   p_org_id      => l_organization_id,
201 		   p_error_msg   => l_msg_data,
202 		   p_proc_name   => l_procedure_name);
203 
204       raise_application_error(-20000,l_return_err);
205 
206      when fnd_api.g_exc_unexpected_error THEN
207 
208 	rollback;
209 	 IF(subinventory_cursor%isopen) THEN CLOSE subinventory_cursor; END IF;
210 	     x_return_status := fnd_api.g_ret_sts_error ;
211 
212       --  Get message count and data
213       fnd_msg_pub.count_and_get
214           (  p_count  => l_msg_count
215            , p_data   => l_msg_data
216             );
217 
218       l_msg_data := replace(l_msg_data,chr(0),' ');
219 
220       l_return_err := 'mtl_secondary_inventories default cost group upgrade:'|| l_msg_data;
221       INS_ERROR(  p_table_name  => l_table_name,
222 		   p_ROWID       => l_rowid_info,
223 		   p_org_id      => l_organization_id,
224 		   p_error_msg   => l_msg_data,
225 		   p_proc_name   => l_procedure_name);
226       raise_application_error(-20000,l_return_err);
227 
228      when others then
229 	rollback;
230 	 IF(subinventory_cursor%isopen) THEN CLOSE subinventory_cursor; END IF;
231       x_return_status := fnd_api.g_ret_sts_error ;
232       l_return_err := 'mtl_secondary_inventories default cost group upgrade:'||
233 	substrb(sqlerrm,1,55);
234         INS_ERROR(p_table_name  => l_table_name,
235 		   p_ROWID       => l_rowid_info,
236 		   p_org_id      => l_organization_id,
237 		   p_error_msg   => l_msg_data,
238 		   p_proc_name   => l_procedure_name);
239       raise_application_error(-20000,l_return_err);
240 
241 end INVMSISB;
242 
243 
244 PROCEDURE INVMPSSB(
245 		  l_organization_id   IN  	NUMBER,
246                   USER_NAME           IN        VARCHAR2,
247 		  PASSWORD            IN        VARCHAR2,
248 		  x_return_status     OUT NOCOPY 	VARCHAR2,
249 		  x_msg_count         OUT NOCOPY 	NUMBER,
250 		  x_msg_data          OUT NOCOPY 	VARCHAR2) AS
251 
252 /*
253 declare
254 
255   */
256 
257    type period_summary_tbl is table of mtl_period_summary%rowtype
258    index by binary_integer;
259 
260    /*
261    ** --------------------------------------------------------
262    ** Org cursor
263    ** --------------------------------------------------------
264    */
265    cursor group_cursor is
266       SELECT
267 --      ROWID,
268       acct_period_id
269    , inventory_type
270    , cost_group_id
271    , sum(inventory_value) inventory_value
272    from mtl_period_summary
273    where organization_id = l_organization_id
274    group by
275      acct_period_id
276    , organization_id
277    , inventory_type
278    , cost_group_id;
279 
280    /*
281    ** --------------------------------------------------------
282    ** Period summary records that do not have a default cost group yet
283    ** --------------------------------------------------------
284    */
285    cursor mps_cursor
286    is
287    select
288      rowid
289    , secondary_inventory
290    from mtl_period_summary
291    where
292         (
293          cost_group_id is null AND
294          organization_id = l_organization_id
295         );
296 
297    l_rowid                      varchar2(100);
298 
299 /*  l_organization_id 		number; */
300 
301    l_secondary_inventory        varchar2(10);
302 
303    l_return_status		varchar2(1);
304    l_msg_count                  number;
305    l_msg_data                   varchar2(240);
306 
307    l_cost_group_id              number;
308 
309    l_return_err			varchar2(280);
310 
311    l_counter			integer;
312 
313    l_date                       DATE;
314    l_user_id                    NUMBER;
315    l_request_id                 NUMBER;
316    l_login_id                   NUMBER;
317    l_prog_appl_id               NUMBER;
318    l_program_id                 NUMBER;
319 
320    l_ps_tbl			period_summary_tbl;
321    l_rowid_info                 VARCHAR2(2000);
322    l_table_name                 VARCHAR2(300);
323    l_procedure_name             VARCHAR2(200):= 'upgrade subinventory data INVMPSSB';
324 
325 
326 begin
327    -- Stamp cost group
328 
329    l_table_name := 'mtl_period_summary';
330    for c1 in mps_cursor
331    loop
332 	/*
333         ** Load cursor output into local variables
334         */
335         l_rowid  		:= c1.rowid;
336         l_rowid_info            := l_rowid;
337 /*      l_organization_id       := c1.organization_id; */
338 
339       	l_secondary_inventory   := c1.secondary_inventory;
340 
341         if (l_secondary_inventory is not null) then
342 		l_cost_group_id := inv_sub_cg_util.get_cg_from_sub(
343                                      x_return_status    => l_return_status
344                                    , x_msg_count        => l_msg_count
345                                    , x_msg_data         => l_msg_data
346                                    , p_organization_id  => l_organization_id
347                                    , p_subinventory     => l_secondary_inventory);
348 
349                 if (l_cost_group_id > 0) then
350                         update mtl_period_summary
351                         set cost_group_id = l_cost_group_id
352                         where rowid = l_rowid;
353                 end if;
354 	else
355 		l_cost_group_id := inv_sub_cg_util.get_cg_from_org(
356                                      x_return_status    => l_return_status
357                                    , x_msg_count        => l_msg_count
358                                    , x_msg_data         => l_msg_data
359                                    , p_organization_id  => l_organization_id);
360 
361                 if (l_cost_group_id > 0) then
362                         update mtl_period_summary
363                         set cost_group_id = l_cost_group_id
364                         where rowid = l_rowid;
365                 end if;
366 	end if;
367    end loop;
368 
369    l_counter := 0;
370 
371    l_table_name := 'mtl_period_summary';
372 
373    for c2 in group_cursor
374    loop
375       l_counter := l_counter + 1;
376 
377 --        l_rowid_info                            :=c2.ROWID;
378         l_ps_tbl(l_counter).acct_period_id      := c2.acct_period_id;
379         l_ps_tbl(l_counter).organization_id     := l_organization_id; /*c2.organization_id;*/
380         l_ps_tbl(l_counter).inventory_type      := c2.inventory_type;
381         l_ps_tbl(l_counter).cost_group_id       := c2.cost_group_id;
382         l_ps_tbl(l_counter).inventory_value     := c2.inventory_value;
383    end loop;
384 
385    /*
386    ** Delete data. It will be reloaded from memory in just a second
387    */
388    delete mtl_period_summary WHERE organization_id = l_organization_id;
389 
390    select sysdate into l_date from dual;
391 
392    l_user_id  := fnd_global.user_id;
393    l_login_id := fnd_global.login_id;
394 
395    IF l_login_id = -1 THEN
396       l_login_id := fnd_global.conc_login_id;
397    END IF;
398 
399    l_request_id 	:= fnd_global.conc_request_id;
400    l_prog_appl_id 	:= fnd_global.prog_appl_id;
401    l_program_id 	:= fnd_global.conc_program_id;
402 
403    /*
404    ** Reload grouped data into table
405    */
406    for i in 1..l_counter
407    loop
408 	/*
409 	** Reload grouped data from memory
410 	*/
411 
412 	insert into mtl_period_summary(
413 	  ACCT_PERIOD_ID
414         , ORGANIZATION_ID
415  	, INVENTORY_TYPE
416         , SECONDARY_INVENTORY
417         , LAST_UPDATE_DATE
418         , LAST_UPDATED_BY
419         , CREATION_DATE
420         , CREATED_BY
421         , LAST_UPDATE_LOGIN
422         , INVENTORY_VALUE
423         , REQUEST_ID
424         , PROGRAM_APPLICATION_ID
425         , PROGRAM_ID
426         , PROGRAM_UPDATE_DATE
427         , COST_GROUP_ID)
428 	values(
429           l_ps_tbl(i).acct_period_id
430         , l_ps_tbl(i).organization_id
431         , l_ps_tbl(i).inventory_type
432         , NULL
433         , l_date
434         , l_user_id
435         , l_date
436         , l_user_id
437         , l_login_id
438         , l_ps_tbl(i).inventory_value
439         , l_request_id
440         , l_prog_appl_id
441         , l_program_id
442         , l_date
443         , l_ps_tbl(i).cost_group_id);
444    end loop;
445 
446    IF(group_cursor%isopen) THEN CLOSE group_cursor; END IF;
447    IF(mps_cursor%isopen) THEN CLOSE mps_cursor; END IF;
448    COMMIT;
449 exception
450 
451      when fnd_api.g_exc_error THEN
452 	rollback;
453 
454 	IF(group_cursor%isopen) THEN CLOSE group_cursor; END IF;
455         IF(mps_cursor%isopen) THEN CLOSE mps_cursor; END IF;
456          x_return_status := fnd_api.g_ret_sts_error ;
457       --  Get message count and data
458       fnd_msg_pub.count_and_get
459           (  p_count  => l_msg_count
460            , p_data   => l_msg_data
461             );
462 
463       l_msg_data := replace(l_msg_data,chr(0),' ');
464 
465       l_return_err := 'mtl_period_summary cost group upgrade:'||l_msg_data;
466 
467       INS_ERROR(  p_table_name  => l_table_name,
468 		   p_ROWID       => l_rowid_info,
469 		   p_org_id      => l_organization_id,
470 		   p_error_msg   => l_msg_data,
471 		   p_proc_name   => l_procedure_name);
472 
473 
474       raise_application_error(-20000,l_return_err);
475 
476      when fnd_api.g_exc_unexpected_error THEN
477 
478 	rollback;
479 
480 	IF(group_cursor%isopen) THEN CLOSE group_cursor; END IF;
481         IF(mps_cursor%isopen) THEN CLOSE mps_cursor; END IF;
482 
483             x_return_status := fnd_api.g_ret_sts_error ;
484       --  Get message count and data
485       fnd_msg_pub.count_and_get
486           (  p_count  => l_msg_count
487            , p_data   => l_msg_data
488             );
489 
490       l_msg_data := replace(l_msg_data,chr(0),' ');
491 
492       l_return_err := 'mtl_period_summary cost group upgrade:'||l_msg_data;
493 
494       INS_ERROR(  p_table_name  => l_table_name,
495 		   p_ROWID       => l_rowid_info,
496 		   p_org_id      => l_organization_id,
497 		   p_error_msg   => l_msg_data,
498 		   p_proc_name   => l_procedure_name);
499 
500       raise_application_error(-20000,l_return_err);
501 
502      when others then
503 	rollback;
504 
505 	IF(group_cursor%isopen) THEN CLOSE group_cursor; END IF;
506         IF(mps_cursor%isopen) THEN CLOSE mps_cursor; END IF;
507 
508              x_return_status := fnd_api.g_ret_sts_error ;
509         /*
510         dbms_output.put_line('Org:' || to_char(l_organization_id));
511         dbms_output.put_line('Sub:' || l_secondary_inventory);
512 	  */
513 
514 
515 	  INS_ERROR(  p_table_name  => l_table_name,
516 		   p_ROWID       => l_rowid_info,
517 		   p_org_id      => l_organization_id,
518 		   p_error_msg   => l_msg_data,
519 		   p_proc_name   => l_procedure_name);
520 
521       l_return_err := 'mtl_period_summary cost group upgrade:'||
522                               substrb(sqlerrm,1,55);
523       raise_application_error(-20000,l_return_err);
524 
525 end INVMPSSB;
526 
527 
528 
529 
530 
531 
532 
533 -- $Header: WMSCGUGB.pls 120.1 2005/06/15 14:31:58 appldev  $
534 
535 
536 
537 
538 PROCEDURE INVMPSB(
539 		  l_organization_id   IN  	NUMBER,
540 		  USER_NAME           IN        VARCHAR2,
541 		  PASSWORD            IN        VARCHAR2,
542 		  x_return_status     OUT NOCOPY 	VARCHAR2,
543 		  x_msg_count         OUT NOCOPY 	NUMBER,
544 		  x_msg_data          OUT NOCOPY 	VARCHAR2) AS
545 
546 --/*
547 --declare
548 --  /*
549 --   ** --------------------------------------------------------
550 --   ** Organizations that do not have a default cost group yet
551 --   ** --------------------------------------------------------
552 --   */
553 --  */
554 
555    cursor org_cursor is
556       select
557 	ROWID
558    , material_account
559    , material_overhead_account
560    , resource_account
561    , overhead_account
562    , outside_processing_account
563    , expense_account
564    , encumbrance_account
565    from mtl_parameters
566    where (
567           default_cost_group_id is null and
568           organization_id = l_organization_id
569          );
570 
571 --/*   l_organization_id 		number; */
572 
573    l_material_account           number;
574    l_material_overhead_account  number;
575    l_resource_account           number;
576    l_overhead_account           number;
577    l_outside_processing_account number;
578    l_expense_account            number;
579    l_encumbrance_account        number;
580 
581    l_return_status		varchar2(1);
582    l_msg_count                  number;
583    l_msg_data                   varchar2(540);
584 
585    l_cost_group_id              number;
586    l_cost_group_id_tbl 		cstpcgut.cost_group_tbl;
587    l_count			number;
588 
589    l_return_err			varchar2(280);
590 
591    l_rowid_info                 VARCHAR2(2000);
592    l_table_name                 VARCHAR2(300);
593    l_procedure_name             VARCHAR2(200):= 'upgrade subinventory data INVMPSB';
594 
595 begin
596 
597    l_table_name := 'mtl_parameters';
598 
599    for c1 in org_cursor
600    loop
601 ---/*
602 --        ** Load cursor output into local variables
603 --        */
604       --/*   	l_organization_id 	     := c1.organization_id; */
605 
606        l_rowid_info                  :=c1.ROWID;
607 
608    	l_material_account           := c1.material_account;
609    	l_material_overhead_account  := c1.material_overhead_account;
610    	l_resource_account           := c1.resource_account;
611    	l_overhead_account           := c1.overhead_account;
612    	l_outside_processing_account := c1.outside_processing_account;
613    	l_expense_account            := c1.expense_account;
614    	l_encumbrance_account        := c1.encumbrance_account;
615 
616         /*
617 	dbms_output.put_line('Org:' || to_char(l_organization_id));
618 
619 	dbms_output.put_line('MA:'  || to_char(l_material_account));
620 	dbms_output.put_line('MOA:' || to_char(l_material_overhead_account));
621 	dbms_output.put_line('RA:'  || to_char(l_resource_account));
622 	dbms_output.put_line('OA:'  || to_char(l_overhead_account));
623 	dbms_output.put_line('OPA:' || to_char(l_outside_processing_account));
624 	dbms_output.put_line('EA:'  || to_char(l_expense_account));
625 	dbms_output.put_line('EnA:' || to_char(l_encumbrance_account));
626         */
627 
628 
629 --      ** See if there is there a cost group with matching accounts
630 --        dbms_output.put_line('before get cost group');
631         cstpcgut.get_cost_group(
632 	  x_return_status     		=> l_return_status
633         , x_msg_count         		=> l_msg_count
634         , x_msg_data          		=> l_msg_data
635         , x_cost_group_id_tbl 		=> l_cost_group_id_tbl
636         , x_count             		=> l_count
637    	, p_material_account         	=> l_material_account
638    	, p_material_overhead_account  	=> l_material_overhead_account
639    	, p_resource_account           	=> l_resource_account
640    	, p_overhead_account           	=> l_overhead_account
641    	, p_outside_processing_account 	=> l_outside_processing_account
642    	, p_expense_account            	=> l_expense_account
643    	, p_encumbrance_account        	=> l_encumbrance_account
644         , p_organization_id		=> l_organization_id   --NULL
645         , p_cost_group_type_id          => 3);
646 
647 	IF l_return_status = fnd_api.g_ret_sts_error THEN
648          	RAISE fnd_api.g_exc_error;
649     	END IF ;
650 
651     	IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
652 		/*
653 		dbms_output.put_line('Org:' || to_char(l_organization_id));
654 
655 		dbms_output.put_line('MA:'  || to_char(l_material_account));
656 		dbms_output.put_line('MOA:' || to_char(l_material_overhead_account));
657 		dbms_output.put_line('RA:'  || to_char(l_resource_account));
658 		dbms_output.put_line('OA:'  || to_char(l_overhead_account));
659 		dbms_output.put_line('OPA:' || to_char(l_outside_processing_account));
660 		dbms_output.put_line('EA:'  || to_char(l_expense_account));
661 		dbms_output.put_line('EnA:' || to_char(l_encumbrance_account));
662 		*/
663          	RAISE fnd_api.g_exc_unexpected_error;
664     	END IF;
665 
666 
667 --        ** If there's a cost group matching accounts use it else create
668 --        ** a new one
669 --        dbms_output.put_line('before create cost group');
670         if (l_count > 0) then
671 	  l_cost_group_id := l_cost_group_id_tbl(1);
672         else
673           cstpcgut.create_cost_group(
674 	    x_return_status     		=> l_return_status
675           , x_msg_count         		=> l_msg_count
676           , x_msg_data          		=> l_msg_data
677           , x_cost_group_id 			=> l_cost_group_id
678           , p_cost_group             		=> NULL
679    	  , p_material_account         		=> l_material_account
680    	  , p_material_overhead_account  	=> l_resource_account
681    	  , p_resource_account           	=> l_resource_account
682    	  , p_overhead_account           	=> l_overhead_account
683    	  , p_outside_processing_account 	=> l_outside_processing_account
684    	  , p_expense_account            	=> l_expense_account
685    	  , p_encumbrance_account        	=> l_encumbrance_account
686           , p_organization_id			=> l_organization_id  --NULL
687           , p_cost_group_type_id          	=> 3);
688 
689 --	  dbms_output.put_line('after create cost group');
690 	  IF l_return_status = fnd_api.g_ret_sts_error THEN
691          	RAISE fnd_api.g_exc_error;
692     	  END IF ;
693 
694     	  IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
695          	RAISE fnd_api.g_exc_unexpected_error;
696     	  END IF;
697         end if;
698 
699 
700 --        ** Stamp default cost group on org record
701 
702 --        dbms_output.put_line('before insert ');
703 --	dbms_output.put_line('cost gr is is' || To_char(l_cost_group_id) );
704         update mtl_parameters
705         set default_cost_group_id = l_cost_group_id
706         where organization_id = l_organization_id;
707 --	dbms_output.put_line('after insert');
708    end loop;
709 
710    IF(org_cursor%isopen) THEN CLOSE org_cursor; END IF;
711 
712    COMMIT;
713 exception
714 
715      when fnd_api.g_exc_error THEN
716 	rollback;
717 
718 	IF(org_cursor%isopen) THEN CLOSE org_cursor; END IF;
719          x_return_status := fnd_api.g_ret_sts_error ;
723            , p_data   => l_msg_data
720       --  Get message count and data
721       fnd_msg_pub.count_and_get
722           (  p_count  => l_msg_count
724             );
725 
726       l_msg_data := replace(l_msg_data,chr(0),' ');
727 
728       INS_ERROR(  p_table_name  => l_table_name,
729 		   p_ROWID       => l_rowid_info,
730 		   p_org_id      => l_organization_id,
731 		   p_error_msg   => Substr(l_msg_data,1,240),
732 		   p_proc_name   => l_procedure_name);
733 
734 --      l_return_err := 'mtl_parameters default cost group upgrade:'|| l_msg_data;
735 
736       raise_application_error(-20000,l_return_err);
737 
738      when fnd_api.g_exc_unexpected_error THEN
739 
740 	rollback;
741 
742 	IF(org_cursor%isopen) THEN CLOSE org_cursor; END IF;
743 
744          x_return_status := fnd_api.g_ret_sts_error ;
745 
746 
747       --  Get message count and data
748       fnd_msg_pub.count_and_get
749           (  p_count  => l_msg_count
750            , p_data   => l_msg_data
751             );
752 
753       l_msg_data := replace(l_msg_data,chr(0),' ');
754 
755   --    l_return_err := 'mtl_parameters default cost group upgrade:'||l_msg_data;
756 
757       INS_ERROR(  p_table_name  => l_table_name,
758 		   p_ROWID       => l_rowid_info,
759 		   p_org_id      => l_organization_id,
760 		   p_error_msg   => Substr(l_msg_data,1,240),
761 		   p_proc_name   => l_procedure_name);
762 
763       raise_application_error(-20000,l_return_err);
764 
765      when others then
766 	rollback;
767 
768 	IF(org_cursor%isopen) THEN CLOSE org_cursor; END IF;
769 
770          x_return_status := fnd_api.g_ret_sts_error ;
771     --  l_return_err := 'mtl_parameters default cost group upgrade:'||
772  --	substrb(sqlerrm,1,55);
773 
774 
775       INS_ERROR(  p_table_name  => l_table_name,
776 		   p_ROWID       => l_rowid_info,
777 		   p_org_id      => l_organization_id,
778 		   p_error_msg   => Substr(l_msg_data,1,240),
779 		  p_proc_name   => l_procedure_name);
780 
781       raise_application_error(-20000,l_return_err);
782 
783 end INVMPSB;
784 
785 
786 
787 
788 PROCEDURE INVMOQSB (
789 		    l_organization_id 	IN  	NUMBER,
790 		    USER_NAME           IN      VARCHAR2,
791 		    PASSWORD            IN      VARCHAR2,
792 		    x_return_status	OUT NOCOPY 	VARCHAR2,
793 		    x_msg_count       	OUT NOCOPY 	NUMBER,
794 		    x_msg_data        	OUT NOCOPY 	VARCHAR2) AS
795 
796 --/*
797 --declare
798 --   /*
799 --   ** --------------------------------------------------------
800 --   ** Org cursor
801 --   ** --------------------------------------------------------
802 --   */
803 --   cursor mp_cursor is
804 --   select organization_id
805 --   from mtl_parameters;
806 
807 --   /*
808 --   ** --------------------------------------------------------
809 --   ** On hand records that do not have a default cost group yet
810 --   ** --------------------------------------------------------
811 --   */
812 
813 
814 --  */
815 
816    cursor moq_cursor(
817      l_organization_id number)
818    is
819    select
820      rowid
821    , subinventory_code
822    , locator_id
823    , project_id
824    , task_id
825    from mtl_onhand_quantities
826    where organization_id = l_organization_id
827    and  cost_group_id is null;
828 
829 --/*
830 --   l_organization_id 		number;
831 --  */
832 
833    l_rowid                      varchar2(100);
834    l_subinventory_code          varchar2(10);
835    l_locator_id			number;
836    l_project_id			number;
837    l_task_id			number;
838 
839    v_project_id			number;
840    v_task_id			number;
841 
842    l_return_status		varchar2(1);
843    l_msg_count                  number;
844    l_msg_data                   varchar2(240);
845 
846    l_cost_group_id              number;
847 
848    l_return_err			varchar2(280);
849 
850     l_rowid_info                 VARCHAR2(2000);
851    l_table_name                 VARCHAR2(300);
852    l_procedure_name             VARCHAR2(200):= 'upgrade subinventory data INVMOQSB';
853    l_cost_method                NUMBER := null ;
854    l_org_cost_group_id          NUMBER := NULL;
855 
856 begin
857 
858 --/*
859 -- for c2 in mp_cursor
860 -- loop
861 --   l_organization_id := c2.organization_id;
862 --  */
863 
864    l_table_name           := 'mtl_onhand_quantities';
865 
866    for c1 in moq_cursor(l_organization_id)
867    loop
868 	/*
869         ** Load cursor output into local variables
870         */
871         l_rowid  		:= c1.rowid;
872         l_rowid_info            := l_rowid;
873 
874      	l_subinventory_code   	:= c1.subinventory_code;
875         l_locator_id		:= c1.locator_id;
876         l_project_id		:= c1.project_id;
877         l_task_id		:= c1.task_id;
878 
879 	v_project_id 	:= 0;
880 	v_task_id 	:= 0;
881 
882 	/*
883 	** Check if the locator is tied to a project
887            (l_task_id is null)    then
884 	*/
885         if (l_locator_id > 0)     and
886            (l_project_id is null) and
888                 begin
889 			select
890 			  to_number(nvl(segment19,'0'))
891 			, to_number(nvl(segment20,'0'))
892 			into
893 			  v_project_id
894 			, v_task_id
895 			from mtl_item_locations
896 			where organization_id       = l_organization_id
897 			and   inventory_location_id = l_locator_id;
898 		exception
899 			when NO_DATA_FOUND then
900 				v_project_id := 0;
901 				v_task_id    := 0;
902 		end;
903 	end if;
904 
905 	/*
906 	** If locator tied to project stamp cost group of project for a
907 	** average costed org. For a standard costed org should stamp
908 	** the cost grp id of the sub level along with project id and task id
909 	** Else stamp cost group of subinventory for a standard costed
910 	** org and for the org level for a average costed org
911 
912 	*/
913 	if (v_project_id > 0) THEN
914 	   -- should come here only if it is a project enabled org
915 	   IF ( l_cost_method IS NULL ) THEN
916 	      SELECT NVL(primary_cost_method,1) INTO l_cost_method
917 		FROM mtl_parameters WHERE
918 		organization_id = l_organization_id ;
919 	   END IF;
920 	   IF ( l_cost_method = 2 ) THEN  /*average costing org */
921                 begin
922 			select costing_group_id
923 			into l_cost_group_id
924 			from pjm_project_parameters
925 			where project_id      = v_project_id
926                 	and   organization_id = l_organization_id;
927 
928 		exception
929 			when NO_DATA_FOUND then
930 				l_cost_group_id := 1;
931 		end;
932 	    ELSE /* standard costing */
933 			   l_cost_group_id := inv_sub_cg_util.get_cg_from_sub(
934 				     x_return_status	=> l_return_status
935                 		   , x_msg_count        => l_msg_count
936 				   , x_msg_data		=> l_msg_data
937 				   , p_organization_id  => l_organization_id
938 				, p_subinventory	=> l_subinventory_code);
939 	   END IF;
940 
941 	   update mtl_onhand_quantities
942 	     set
943 	        cost_group_id = l_cost_group_id
944 	      , project_id    = v_project_id
945 	      , task_id       = v_task_id
946 	  where rowid = l_rowid;
947 
948 	else
949 			   IF ( l_cost_method IS NULL ) THEN
950 			      SELECT NVL(primary_cost_method,1) INTO l_cost_method
951 				FROM mtl_parameters WHERE
952 				organization_id = l_organization_id ;
953 			   END IF;
954 			   IF ( l_cost_method = 2 ) THEN  /*average costing org */
955 			         IF ( l_org_cost_group_id IS NULL ) then
956 				   select nvl(default_cost_group_id,0)
957 				   into l_org_cost_group_id
958 				   from mtl_parameters
959 				     where organization_id = l_organization_id;
960 				   l_cost_group_id := l_org_cost_group_id ;
961 				  ELSE
962 				    l_cost_group_id := l_org_cost_group_id ;
963 				  END IF;
964 			    ELSE /* standard costing */
965 			      l_cost_group_id := inv_sub_cg_util.get_cg_from_sub(
966 				     x_return_status	=> l_return_status
967                 		   , x_msg_count        => l_msg_count
968 				   , x_msg_data		=> l_msg_data
969 				   , p_organization_id  => l_organization_id
970 				, p_subinventory	=> l_subinventory_code);
971 			    END IF;
972 
973 		if (l_cost_group_id > 0) then
974 			update mtl_onhand_quantities
975 			set cost_group_id = l_cost_group_id
976 			where rowid = l_rowid;
977 
978 		end if;
979 	end if;
980    end loop;
981 
982    IF(moq_cursor%isopen) THEN CLOSE moq_cursor; END IF;
983    commit;
984 
985 /*
986  end loop;
987  */
988 
989 exception
990 
991      when fnd_api.g_exc_error THEN
992 	rollback;
993 
994 	 IF(moq_cursor%isopen) THEN CLOSE moq_cursor; END IF;
995 
996         x_return_status := fnd_api.g_ret_sts_error ;
997       --  Get message count and data
998       fnd_msg_pub.count_and_get
999           (  p_count  => l_msg_count
1000            , p_data   => l_msg_data
1001             );
1002 
1003       l_msg_data := replace(l_msg_data,chr(0),' ');
1004 
1005 
1006       l_return_err := 'mtl_onhand_quantities cost group upgrade:'|| l_msg_data;
1007 
1008       INS_ERROR(  p_table_name  => l_table_name,
1009 		   p_ROWID       => l_rowid_info,
1010 		   p_org_id      => l_organization_id,
1011 		   p_error_msg   => l_msg_data,
1012 		  p_proc_name   => l_procedure_name);
1013 
1014       raise_application_error(-20000,l_return_err);
1015 
1016      when fnd_api.g_exc_unexpected_error THEN
1017 
1018 	rollback;
1019 
1020 	 IF(moq_cursor%isopen) THEN CLOSE moq_cursor; END IF;
1021             x_return_status := fnd_api.g_ret_sts_error ;
1022       --  Get message count and data
1023       fnd_msg_pub.count_and_get
1024           (  p_count  => l_msg_count
1025            , p_data   => l_msg_data
1026             );
1027 
1028       l_msg_data := replace(l_msg_data,chr(0),' ');
1029 
1030       l_return_err := 'mtl_onhand_quantities cost group upgrade:'|| l_msg_data;
1031 
1032 
1033       INS_ERROR(  p_table_name  => l_table_name,
1034 		   p_ROWID       => l_rowid_info,
1038       raise_application_error(-20000,l_return_err);
1035 		   p_org_id      => l_organization_id,
1036 		   p_error_msg   => l_msg_data,
1037 		   p_proc_name   => l_procedure_name);
1039 
1040      when others then
1041 	rollback;
1042 
1043 	 IF(moq_cursor%isopen) THEN CLOSE moq_cursor; END IF;
1044 
1045           x_return_status := fnd_api.g_ret_sts_error ;
1046 	/*
1047         dbms_output.put_line('Org:' || to_char(l_organization_id));
1048         dbms_output.put_line('Sub:' || l_subinventory_code);
1049         dbms_output.put_line('Loc:' || to_char(l_locator_id));
1050         dbms_output.put_line('Project:' || to_char(v_project_id));
1051         dbms_output.put_line('Task:' || to_char(v_task_id));
1052         */
1053 
1054 
1055        INS_ERROR(  p_table_name  => l_table_name,
1056 		   p_ROWID       => l_rowid_info,
1057 		   p_org_id      => l_organization_id,
1058 		   p_error_msg   => l_msg_data,
1059 		   p_proc_name   => l_procedure_name);
1060       l_return_err := 'mtl_onhand_quantities cost group upgrade:'||
1061                               substr(sqlerrm,1,55);
1062       raise_application_error(-20000,l_return_err);
1063 
1064 end INVMOQSB;
1065 
1066 
1067 PROCEDURE INVMMTSB (
1068 		    l_organization_id 	IN  	NUMBER,
1069 		    USER_NAME           IN      VARCHAR2,
1070 		    PASSWORD            IN      VARCHAR2,
1071 		    x_return_status	OUT NOCOPY 	VARCHAR2,
1072 		    x_msg_count       	OUT NOCOPY 	NUMBER,
1073 		    x_msg_data        	OUT NOCOPY 	VARCHAR2) AS
1074 
1075 /* */
1076 --declare
1077 --   /*
1078 --   ** --------------------------------------------------------
1079 --   ** Org cursor
1080 --   ** --------------------------------------------------------
1081 --   */
1082 --   cursor mp_cursor is
1083 --   select organization_id
1084 --   from mtl_parameters;
1085 
1086 --   /*
1087 --   ** --------------------------------------------------------
1088 --   ** Transaction records that do not have a default cost group yet
1089 --   ** --------------------------------------------------------
1090 --   */
1091 --  */
1092 
1093    cursor mmt_cursor(
1094      l_organization_id number)
1095    is
1096       select
1097 	ROWID
1098    , transaction_id
1099    , subinventory_code
1100    , transfer_organization_id
1101    , transfer_subinventory
1102    , project_id
1103    , to_project_id
1104    , cost_group_id
1105    , transfer_cost_group_id
1106    , transfer_transaction_id
1107    , transaction_action_id
1108    , shipment_number
1109    , inventory_item_id
1110    from mtl_material_transactions
1111    where organization_id = l_organization_id;
1112 
1113 --   /*
1114 --   ** ---------------------------
1115 --   ** Intransit shipment records
1116 --   ** ---------------------------
1117 --   */
1118    cursor ms_cursor(
1119      l_shipment_number 	 varchar2,
1120      l_organization_id   number,
1121      l_inventory_item_id number)
1122    is
1123    select
1124      ms.rowid
1125    , ms.intransit_owning_org_id
1126    from mtl_supply 		  ms,
1127         rcv_shipment_headers 	  rsh
1128    where rsh.shipment_num         = l_shipment_number
1129    and   ms.shipment_header_id    = rsh.shipment_header_id
1130    and   ms.supply_type_code      = 'SHIPMENT'
1131    and   ms.intransit_owning_org_id is not null
1132    and   ms.item_id               = l_inventory_item_id
1133    and   ms.from_organization_id  = l_organization_id
1134    and   ms.cost_group_id is null;
1135 
1136 --/*
1137 --   l_organization_id 		number;
1138 --  */
1139 
1140    l_transaction_id             number;
1141    l_subinventory_code          varchar2(10);
1142    l_transfer_organization_id	number;
1143    l_transfer_subinventory      varchar2(10);
1144    l_project_id 		number;
1145    l_to_project_id 		number;
1146    l_cost_group_id		number;
1147    l_transfer_cost_group_id	number;
1148    l_transfer_transaction_id    number;
1149    l_transaction_action_id	number;
1150    l_shipment_number		varchar2(30);
1151    l_inventory_item_id		number;
1152 
1153    l_return_status		varchar2(1);
1154    l_msg_count                  number;
1155    l_msg_data                   varchar2(240);
1156 
1157    l_return_err			varchar2(280);
1158 
1159    l_ms_rowid			varchar2(100);
1160    l_intransit_owning_org_id	number;
1161    l_ms_cost_group_id		number;
1162 
1163    l_cost_group_update		boolean;
1164    l_transfer_cost_group_update boolean;
1165    l_date 			varchar2(100);
1166 
1167    l_rowid_info                 VARCHAR2(2000);
1168    l_table_name                 VARCHAR2(300);
1169    l_procedure_name             VARCHAR2(200):= 'upgrade subinventory data INVMMTSB';
1170 begin
1171 
1172 --/*
1173 -- for c2 in mp_cursor
1174 -- loop
1175 --   l_organization_id := c2.organization_id;
1176 
1177 --  */
1178 
1179    -- dbms_output.put_line('Org:' || l_organization_id);
1180 
1181 
1182    for c1 in mmt_cursor(l_organization_id)
1183    loop
1184 	/*
1185       ** Load cursor output into local variables
1186 
1187 	*/
1188 
1189 	 l_table_name := 'mtl_material_transactions';
1190 
1191 	l_rowid_info               :=c1.ROWID;
1192         l_transaction_id  	   := c1.transaction_id;
1196         l_project_id 		   := c1.project_id;
1193       	l_subinventory_code   	   := c1.subinventory_code;
1194    	l_transfer_organization_id := c1.transfer_organization_id;
1195    	l_transfer_subinventory    := c1.transfer_subinventory;
1197         l_to_project_id            := c1.to_project_id;
1198    	l_cost_group_id		   := c1.cost_group_id;
1199    	l_transfer_cost_group_id   := c1.transfer_cost_group_id;
1200         l_transfer_transaction_id  := c1.transfer_transaction_id;
1201         l_transaction_action_id	   := c1.transaction_action_id;
1202         l_shipment_number	   := c1.shipment_number;
1203         l_inventory_item_id	   := c1.inventory_item_id;
1204 
1205         l_cost_group_update	     := FALSE;
1206         l_transfer_cost_group_update := FALSE;
1207 
1208 	/*
1209 	** If cost group is null and is not a project transcation,
1210         ** stamp default cost group of subinventory
1211 	*/
1212 	if (l_cost_group_id is null and l_project_id is null) then
1213 		l_cost_group_id := inv_sub_cg_util.get_cg_from_sub(
1214 				     x_return_status	=> l_return_status
1215                 		   , x_msg_count        => l_msg_count
1216 				   , x_msg_data		=> l_msg_data
1217 				   , p_organization_id  => l_organization_id
1218 			  	   , p_subinventory	=> l_subinventory_code);
1219 
1220 		if (l_cost_group_id > 0) then
1221         		l_cost_group_update	     := TRUE;
1222 		end if;
1223 	end if;
1224 
1225 	/*
1226 	** If its a transfer transaction and is not a project transaction
1227         ** stamp default cost group of transfer subinventory
1228 	*/
1229 
1230         if (l_transfer_transaction_id > 0) 	 and
1231 	   (l_transfer_cost_group_id is null) 	 and
1232 	   (l_transfer_organization_id > 0) 	 and
1233 	   (l_transfer_subinventory is not null) and
1234 	   (l_to_project_id is null) then
1235 		l_transfer_cost_group_id := inv_sub_cg_util.get_cg_from_sub(
1236 				     x_return_status	=> l_return_status
1237                 		   , x_msg_count        => l_msg_count
1238 				   , x_msg_data		=> l_msg_data
1239 				   , p_organization_id  => l_transfer_organization_id
1240 			  	   , p_subinventory	=> l_transfer_subinventory);
1241 
1242 		if (l_transfer_cost_group_id > 0) then
1243         		l_transfer_cost_group_update := TRUE;
1244 		end if;
1245 	end if;
1246 
1247         if (l_cost_group_update	         = TRUE) and
1248            (l_transfer_cost_group_update = TRUE) then
1249 	        update mtl_material_transactions
1250 		set
1251                   cost_group_id          = l_cost_group_id
1252 		, transfer_cost_group_id = l_transfer_cost_group_id
1253 		where transaction_id = l_transaction_id;
1254         elsif (l_cost_group_update	    = TRUE) then
1255 	        update mtl_material_transactions
1256 		set cost_group_id = l_cost_group_id
1257 		where transaction_id = l_transaction_id;
1258 	elsif (l_transfer_cost_group_update = TRUE) then
1259 	        update mtl_material_transactions
1260 		set transfer_cost_group_id = l_transfer_cost_group_id
1261 		where transaction_id = l_transaction_id;
1262         end if;
1263 
1264         /*
1265         ** If intransit shipment(action_id =21), we have to update
1266         ** corresponding record in MTL_SUPPLY too
1267         */
1268 
1269         if (l_transaction_action_id = 21) and
1270 	  (l_shipment_number is not null) THEN
1271 
1272 	        l_table_name := 'mmt_supply';
1273 
1274 		for c3 in ms_cursor(l_shipment_number,
1275                                     l_organization_id,
1276                                     l_inventory_item_id)
1277                 loop
1278 			--
1279         		-- Load cursor output into local variables
1280         		--
1281 		        l_ms_rowid	          := c3.rowid;
1282 
1283 			l_rowid_info              := l_ms_rowid;
1284 			l_intransit_owning_org_id := c3.intransit_owning_org_id;
1285 
1286 			--
1287 			-- If orgs match use cost group of from sub
1288 			-- Else use cost group of intransit owning org
1289 			--
1290 			if l_intransit_owning_org_id = l_organization_id then
1291 			   l_ms_cost_group_id := inv_sub_cg_util.get_cg_from_sub(
1292 				     x_return_status	=> l_return_status
1293                 		   , x_msg_count        => l_msg_count
1294 				   , x_msg_data		=> l_msg_data
1295 				   , p_organization_id  => l_organization_id
1296 			  	   , p_subinventory	=> l_subinventory_code);
1297 			else
1298 			   l_ms_cost_group_id := inv_sub_cg_util.get_cg_from_org(
1299 				     x_return_status	=> l_return_status
1300                 		   , x_msg_count        => l_msg_count
1301 				   , x_msg_data		=> l_msg_data
1302 				   , p_organization_id  => l_intransit_owning_org_id);
1303 			end if;
1304 
1305 			if (l_ms_cost_group_id > 0) then
1306 				update mtl_supply
1307 				set cost_group_id = l_ms_cost_group_id
1308 				where rowid = l_ms_rowid;
1309 			end if;
1310  		end loop;
1311 	end if;
1312 
1313    end loop;
1314 
1315    -- To log time and organization
1316    -- create table mmt_summary(MSG VARCHAR2(1000))
1317    -- and uncomment next 6 lines
1318 /*
1319    select to_char(sysdate, 'DD-MON-YY HH24:MI:SS')
1320    into l_date from dual;
1321 
1322    insert into mmt_summary values('Org ' ||
1323    				  to_char(l_organization_id) ||
1324                                    ':' || l_date);
1325 
1326      commit;
1327 
1328      IF(mmt_cursor%isopen) THEN CLOSE mmt_cursor; END IF;
1329       IF(ms_cursor%isopen) THEN CLOSE ms_cursor; END IF;
1330 */
1331 
1332 /*
1333  end loop;
1334   */
1335 
1336 exception
1337 
1338      when fnd_api.g_exc_error THEN
1339 	rollback;
1340 
1341       IF(mmt_cursor%isopen) THEN CLOSE mmt_cursor; END IF;
1342       IF(ms_cursor%isopen) THEN CLOSE ms_cursor; END IF;
1343 
1344 	    x_return_status := fnd_api.g_ret_sts_error ;
1345 
1346       --  Get message count and data
1347       fnd_msg_pub.count_and_get
1348           (  p_count  => l_msg_count
1349            , p_data   => l_msg_data
1350             );
1351 
1352       l_msg_data := replace(l_msg_data,chr(0),' ');
1353 
1354       l_return_err := 'mtl_material_transactions cost group upgrade:'|| l_msg_data;
1355 
1356 
1357       INS_ERROR(  p_table_name  => l_table_name,
1358 		   p_ROWID       => l_rowid_info,
1359 		   p_org_id      => l_organization_id,
1360 		   p_error_msg   => l_msg_data,
1361 		  p_proc_name   => l_procedure_name);
1362 
1363       raise_application_error(-20000,l_return_err);
1364 
1365      when fnd_api.g_exc_unexpected_error THEN
1366 
1367 	rollback;
1368 
1369       IF(mmt_cursor%isopen) THEN CLOSE mmt_cursor; END IF;
1370       IF(ms_cursor%isopen) THEN CLOSE ms_cursor; END IF;
1371 
1372 	     x_return_status := fnd_api.g_ret_sts_error ;
1373       --  Get message count and data
1374       fnd_msg_pub.count_and_get
1375           (  p_count  => l_msg_count
1376            , p_data   => l_msg_data
1377             );
1378 
1379       l_msg_data := replace(l_msg_data,chr(0),' ');
1380 
1381       l_return_err := 'mtl_material_transactions cost group upgrade:'|| l_msg_data;
1382 
1383 
1384 
1385       INS_ERROR(  p_table_name  => l_table_name,
1386 		   p_ROWID       => l_rowid_info,
1387 		   p_org_id      => l_organization_id,
1388 		   p_error_msg   => l_msg_data,
1389 		  p_proc_name   => l_procedure_name);
1390 
1391       raise_application_error(-20000,l_return_err);
1392 
1393      when others then
1394 	rollback;
1395 
1396       IF(mmt_cursor%isopen) THEN CLOSE mmt_cursor; END IF;
1397       IF(ms_cursor%isopen) THEN CLOSE ms_cursor; END IF;
1398 
1399          x_return_status := fnd_api.g_ret_sts_error ;
1400         /*
1401         dbms_output.put_line('TID:' || to_char(l_transaction_id));
1402         dbms_output.put_line('Org:' || to_char(l_organization_id));
1403         dbms_output.put_line('Sub:' || l_subinventory_code);
1404         */
1405 
1406 
1407 	INS_ERROR(  p_table_name  => l_table_name,
1408 		   p_ROWID       => l_rowid_info,
1409 		   p_org_id      => l_organization_id,
1410 		   p_error_msg   => l_msg_data,
1411 		   p_proc_name   => l_procedure_name);
1412       l_return_err := 'mtl_material_transactions cost group upgrade:'||
1413                               substr(sqlerrm,1,55);
1414       raise_application_error(-20000,l_return_err);
1415 
1416 
1417 end INVMMTSB;
1418 
1419 PROCEDURE INS_ERROR (
1420 		      p_table_name         IN   VARCHAR2,
1421 		      p_ROWID   	   IN  	VARCHAR2,
1422 		      p_org_id             IN   NUMBER,
1423 		      p_error_msg	   IN   VARCHAR2,
1424                       p_proc_name          IN   VARCHAR2
1425 		    )  AS
1426 
1427 l_msg VARCHAR2(300);
1428 BEGIN
1429 l_msg := p_error_msg || ' sql error: ' ||substr(sqlerrm,1,500) ;
1430    INSERT INTO COST_UPGR_ERROR_TABLE ( table_name, rowid_value, org_id,
1431 				      error_mesg, proc_name)
1432      VALUES ( p_table_name, p_rowid, p_org_id, substr(l_msg,1,800), p_proc_name);
1433 commit;
1434 
1435 END ins_error;
1436 
1437 
1438 PROCEDURE LAUNCH_UPGRADE IS
1439 org_id NUMBER;
1440 user_name varchar2(100);
1441 password  varchar2(100);
1442 return_status	VARCHAR2(1);
1443 msg_count       NUMBER;
1444 msg_data        VARCHAR2(240);
1445 cursor oid_cursor is select organization_id
1446    from mtl_parameters ;
1447 
1448 BEGIN
1449 
1450 
1451 for c in oid_cursor
1452 loop
1453   BEGIN
1454    org_id := c.organization_id;
1455 
1456   convert_test.invmsisb( org_id,
1457                         user_name,
1458                         password,
1459                         return_status,
1460                         msg_count,
1461                         msg_data
1462                        );
1463  if ( return_status = fnd_api.g_ret_sts_error ) then GOTO continue_loop ; end if;
1464  convert_test.invmpsb( org_id,
1465                         user_name,
1466                         password,
1467                         return_status,
1468                         msg_count,
1469                         msg_data
1470                        );
1471  if ( return_status = fnd_api.g_ret_sts_error ) then GOTO continue_loop ; end if;
1472 convert_test.invmoqsb( org_id,
1473                         user_name,
1474                         password,
1475                         return_status,
1476                         msg_count,
1477                         msg_data
1478                        );
1479 if ( return_status = fnd_api.g_ret_sts_error ) then GOTO continue_loop; end if;
1480 
1481   convert_test.invmpssb( org_id,
1482                         user_name,
1483                         password,
1484                         return_status,
1485                         msg_count,
1486                         msg_data
1487                        );
1488 if ( return_status = fnd_api.g_ret_sts_error ) then GOTO continue_loop; end if;
1489 convert_test.invmmtsb( org_id,
1490                         user_name,
1491                         password,
1492                         return_status,
1493                         msg_count,
1494                         msg_data
1495                        );
1496 <<continue_loop>>
1497 NULL;
1498   EXCEPTION
1499     WHEN OTHERS THEN NULL;
1500   END ;
1501 end loop;
1502 
1503 IF ( oid_cursor%isopen) THEN CLOSE oid_cursor ; END IF;
1504 
1505 
1506 
1507 END LAUNCH_UPGRADE ;
1508 
1509 
1510 
1511 
1512 END CONVERT_TEST;