DBA Data[Home] [Help]

PACKAGE BODY: APPS.GMF_COPY_RSRC_COST

Source


1 PACKAGE BODY gmf_copy_rsrc_cost AS
2 /* $Header: gmfcprcb.pls 120.8 2010/09/03 11:48:26 smukalla ship $ */
3 
4    PROCEDURE end_copy
5    (
6 	pi_errstat	      IN          VARCHAR2,
7 	pi_errmsg	      IN          VARCHAR2
8 	);
9 
10    /*****************************************************************************************************************
11    * PROCEDURE                                                                                                      *
12    *    copy_rsrc_cost                                                                                              *
13    *                                                                                                                *
14    * DESCRIPTION                                                                                                    *
15    *    Copy Resource Costs Procedure                                                                               *
19    * INPUT PARAMETERS                                                                                               *
16    *    Copies costs from the one set of orgn/cost calendar/period/cost method                                      *
17    *    to another for the resource class specified on the form.                                                    *
18    *                                                                                                                *
20    *    From and To orgn/calendar/period/cost method                                                                *
21    *    pi_resource_class Costs for all Resources that are belong to this                                           *
22    *    resouce class will be copied to the target period                                                           *
23    *                                                                                                                *
24    * OUTPUT PARAMETERS                                                                                              *
25    *    po_errbuf      Completion message to the Concurrent Manager                                                 *
26    *    po_retcode     Return code to the Concurrent Manager                                                        *
27    *                                                                                                                *
28    * HISTORY                                                                                                        *
29    *    11-Oct-1999 Rajesh Seshadri                                                                                 *
30    *    21-Nov-2000 Uday Moogala - Bug# 1419482 Copy Cost Enhancement.                                              *
31    *       1. Copy to all periods option :                                                                          *
32    *          Copy item/burden cost from one costing period to all the subsequent                                   *
33    *          open/frozen costing periods in the same calendar or                                                   *
34    *          to all the open/frozen periods if it is a different calendar.                                         *
35    *       For more details refer to DLD : GMF_CC_11i+_dld.rtf                                                      *
36    *    30-OCT-2002    RajaSekhar    Bug#2641405 Added NOCOPY hint.                                                 *
37    *    09-Jan-2003    Anoop         Bug#3345313 Added the if condition to check the if resource class is not null. *
38    *    23-Aug-2010    Uday Phadtare Bug 9946768.  Added to_char to :pi_legal_entity_id_to in the dynamic sql.      *
39    *****************************************************************************************************************/
40 
41    PROCEDURE copy_rsrc_cost
42    (
43 	po_errbuf		               OUT NOCOPY  VARCHAR2,
44 	po_retcode		               OUT NOCOPY  VARCHAR2,
45    pi_legal_entity_id_from	   IN             cm_rsrc_dtl.legal_entity_id%TYPE,
46 	pi_organization_id_from	   IN             cm_rsrc_dtl.organization_id%TYPE,
47 	pi_calendar_code_from	   IN             cm_rsrc_dtl.calendar_code%TYPE,
48 	pi_period_code_from	      IN             cm_rsrc_dtl.period_code%TYPE,
49 	pi_cost_type_id_from	      IN             cm_rsrc_dtl.cost_type_id%TYPE,
50    pi_legal_entity_id_to	   IN             cm_rsrc_dtl.legal_entity_id%TYPE,
51 	pi_organization_id_to		IN             cm_rsrc_dtl.organization_id%TYPE,
52 	pi_calendar_code_to	      IN             cm_rsrc_dtl.calendar_code%TYPE,
53 	pi_period_code_to	         IN             cm_rsrc_dtl.period_code%TYPE,
54 	pi_cost_type_id_to	      IN             cm_rsrc_dtl.cost_type_id%TYPE,
55 	pi_resource_class	         IN             cr_rsrc_mst.resource_class%TYPE,
56    pi_all_periods_from        IN             cm_cmpt_dtl.period_code%TYPE,
57    pi_all_periods_to          IN             cm_cmpt_dtl.period_code%TYPE,
58    pi_all_organization_flag   IN             NUMBER
59 	)
60    IS
61 
62       /*************************
63       * PL/SQL Typ Definitions *
64       *************************/
65 
66       TYPE rectyp_rsrc_dtl IS RECORD   (
67 		                                 resources	         cm_rsrc_dtl.resources%TYPE,
68 		                                 nominal_cost	      cm_rsrc_dtl.nominal_cost%TYPE,
69 		                                 usage_uom	         cm_rsrc_dtl.usage_uom%TYPE
70 	                                    );
71 
72 	   TYPE curtyp_rsrc IS REF CURSOR ;
73 
74 	   TYPE curtyp_orgn IS REF CURSOR ;
75 
76 	   TYPE curtyp_periods IS REF CURSOR ;
77 
78       /******************
79       * Local Variables *
80       ******************/
81 
82       rec_rsrc_dtl	         rectyp_rsrc_dtl ;
83 	   cv_rsrc_dtl	            curtyp_rsrc ;
84 	   cv_orgn		            curtyp_orgn ;
85 	   cv_periods	            curtyp_periods ;
86 
87 
88 	   l_sql_rsrc	            VARCHAR2(2000) ;
89 	   l_sql_orgn	            VARCHAR2(2000) ;
90 	   l_sql_periods	         VARCHAR2(2000) ;
91       l_from_range	         cr_rsrc_mst.resources%TYPE ;
92 	   l_to_range	            cr_rsrc_mst.resources%TYPE ;
93 	   l_organization_id_to	   cm_rsrc_dtl.organization_id%TYPE;
94       pi_period_id_to         cm_rsrc_dtl.period_id%TYPE ;
95       l_period_id_from        cm_rsrc_dtl.period_id%TYPE ;
96 	   l_period_id_to          cm_rsrc_dtl.period_id%TYPE ;
97       l_legal_entity_id_to    cm_rsrc_dtl.legal_entity_id%TYPE;
98       l_cost_Type_id_to       cm_rsrc_dtl.cost_Type_id%TYPE;
99       l_user_id               NUMBER := FND_GLOBAL.USER_ID;
100 	   l_num_src_rows          NUMBER;	-- num cost rows in source period
101 	   l_ins_rows              NUMBER;	-- num rows inserted
102 	   l_upd_rows              NUMBER;	-- num rows updated
103 	   l_routine	            VARCHAR2(41) := 'copy_rsrc_cost' ;
104 	   e_no_cost_rows	         EXCEPTION;
105 
106    BEGIN
107 
111 
108       /****************************************************
109       * Uncomment the call below to write to a local FILE *
110       ****************************************************/
112       ---FND_FILE.PUT_NAMES('gmfcprc.log','gmfcprc.out','/sqlcom/log/dom1151');
113 
114 
115 	   gmf_util.msg_log( 'GMF_CPRC_START' );
116 	   gmf_util.msg_log( 'GMF_CPRC_SRCPARAM', nvl(TO_CHAR(pi_organization_id_from), ' '), nvl(pi_calendar_code_from, ' '), nvl(pi_period_code_from, ' '), nvl(TO_CHAR(pi_cost_type_id_from), ' '), nvl(pi_resource_class, ' '));
117 	   gmf_util.msg_log( 'GMF_CPRC_TGTPARAM', nvl(TO_CHAR(pi_organization_id_to), ' '), nvl(pi_calendar_code_to, ' '), nvl(pi_period_code_to, ' '), nvl(TO_CHAR(pi_cost_type_id_to), ' '));
118 
119       IF ((pi_period_code_to IS NULL) AND ((pi_all_periods_from IS NOT NULL) OR (pi_all_periods_to IS NOT NULL))) THEN
120          gmf_util.msg_log('GMF_CPRC_PERIODS_RANGE', nvl(pi_all_periods_from, ' '), nvl(pi_all_periods_to, ' '), nvl(pi_calendar_code_to, ' ')) ;
121       END IF ;
122 
123 	   l_ins_rows := 0;
124 	   l_upd_rows := 0;
125 
126       BEGIN
127          SELECT         period_id
128          INTO           l_period_id_from
129          FROM           cm_cldr_mst_v
130          WHERE          legal_entity_id = pi_legal_entity_id_from
131          AND            calendar_code = pi_calendar_code_from
132          AND            period_code = pi_period_code_from
133          AND            cost_type_id = pi_cost_type_id_from;
134       EXCEPTION
135          WHEN OTHERS THEN
136             l_period_id_from := NULL;
137       END;
138 
139       IF (l_period_id_from IS NULL) THEN
140 		   gmf_util.msg_log ('GMF_CP_NO_ROWS');
141 		   RAISE e_no_cost_rows;
142       END IF;
143       IF (pi_period_code_to IS NOT NULL) THEN
144          BEGIN
145             SELECT         period_id
146             INTO           pi_period_id_to
147             FROM           cm_cldr_mst_v
148             WHERE          legal_entity_id = pi_legal_entity_id_to
149             AND            calendar_code = pi_calendar_code_to
150             AND            period_code = pi_period_code_to
151             AND            cost_type_id = pi_cost_type_id_to;
152          EXCEPTION
153             WHEN OTHERS THEN
154                pi_period_id_to := NULL;
155          END;
156 
157          IF (pi_period_id_to IS NULL) THEN
158             gmf_util.msg_log ('GMF_CP_NO_ROWS');
159             RAISE e_no_cost_rows;
160          END IF;
161         END IF;
162 
163       --jboppana has to uncomment after testing
164 	   --l_num_src_rows := do_costs_exist( pi_organization_id_from, l_period_id_from, pi_resource_class);
165 
166 	   IF (l_num_src_rows <= 0) THEN
167 		   gmf_util.msg_log ('GMF_CP_NO_ROWS');
168 		   RAISE e_no_cost_rows;
169 	   END IF;
170 
171       l_sql_rsrc :=  '' ;
172 	   l_sql_rsrc :=  ' SELECT ' ||
173 		                        'd.resources, ' ||
174                               'd.nominal_cost, ' ||
175                               'd.usage_uom ' ||
176 	                  ' FROM ' ||
177 		                        'cm_rsrc_dtl d, ' ||
178 		                        'cr_rsrc_mst m ' ||
179 	                  ' WHERE ' ||
180                               'd.legal_entity_id = :b_legal_entity_id AND '||
181                         		'nvl(d.organization_id,0) = nvl(:b_organization_id,0) AND ' ||
182                         		'd.period_id = :b_period_id AND ' ||
183                         		'd.delete_mark = 0 AND ' ||
184                         		'd.resources = m.resources AND ' ||
185                         		'm.delete_mark = 0 ' ;
186 
187 
188 	   IF (pi_resource_class IS NOT NULL)  THEN
189 
190 		   l_sql_rsrc := l_sql_rsrc || ' AND m.resource_class = nvl(:b_resource_class, m.resources) '  ;
191 
192       END IF 	;
193 
194 	   l_sql_rsrc := l_sql_rsrc || ' ORDER BY ' || ' d.resources' ;
195 
196 	   gmf_util.trace( 'Resource Query : ' || l_sql_rsrc, 1 ) ;
197 
198       /**************************************************************************
199       * Build SQL to get target Orgs when from/to orgns are not null.           *
200       * IF (pi_all_orgn_from IS NOT NULL) AND (pi_all_orgn_to IS NOT NULL) THEN *
201       **************************************************************************/
202 
203       IF (pi_all_organization_flag = 0) THEN
204 
205          l_sql_orgn :=  '' ;
206 		   l_sql_orgn :=  'SELECT :pi_organization_id_to FROM  dual ' ;
207       ELSE
208          -- Bug 9946768. Added to_char to :pi_legal_entity_id_to
209          l_sql_orgn := '' ;
210           l_sql_orgn :=
211    		' SELECT ' ||
212    			'hoi.organization_id ' ||
213    		' FROM ' ||
214    			'hr_organization_information hoi , mtl_parameters mp ' ||
215    		' WHERE ' ||
216    			'hoi.org_information2   = to_char(:pi_legal_entity_id_to) '||
217                 ' AND hoi.org_information_context = ''Accounting Information'' '||
218                 ' AND hoi.organization_id = mp.organization_id '||
219                 ' AND mp.process_enabled_flag = ''Y'' ' ;
220 
221           IF ( (pi_calendar_code_from = pi_calendar_code_to) AND
222 		     (pi_period_code_to IS NOT NULL) AND
223 		     (l_period_id_from = pi_period_id_to)
224 		      ) THEN
225    		    l_sql_orgn := l_sql_orgn  ||' AND nvl(hoi.organization_id,0) <> nvl(:pi_organization_id_from,0) ' ;
226           END IF ;
227          l_sql_orgn := l_sql_orgn || ' ORDER BY hoi.organization_id ' ;
228       END IF ;
229 
230 
231 
232       IF (pi_period_code_to IS NOT NULL) THEN
233          l_sql_periods :=  'SELECT :pi_legal_entity_id_to, :pi_period_id_to FROM dual ' ;
234         ELSE
235          l_sql_periods :=  '' ;
236          l_sql_periods :=  'SELECT DISTINCT ' ||
240                            'WHERE ' ||
237                                     'c3.legal_entity_id, c3.period_id ' ||
238                            'FROM ' ||
239                                     'cm_cldr_mst_v c3, cm_cldr_mst_v c2, cm_cldr_mst_v c1 ' ||
241                                     'c3.legal_entity_id = :pi_legal_entity_id_to AND '||
242                                     'c1.calendar_code = :pi_calendar_code_to AND ' ||
243                                     'c1.period_code   = :pi_all_periods_from AND ' ||
244                                     'c2.calendar_code = :pi_calendar_code_to AND ' ||
245                                     'c2.period_code   = :pi_all_periods_to   AND ' ||
246                                     'c3.calendar_code = :pi_calendar_code_to AND ' ||
247                                     'c3.cost_Type_id = :pi_cost_type_id_to AND ' ||
248                                     'c2.legal_entity_id = c3.legal_entity_id AND ' ||
249                                     'c1.legal_entity_id = c2.legal_entity_id AND ' ||
250                                     'c3.start_date >=   c1.start_date AND ' ||
251                                     'c3.end_date <= c2.end_date AND ' ||
252                                     'c3.period_status <> ''C''';
253 
254          IF (pi_calendar_code_from = pi_calendar_code_to) THEN
255 
256             l_sql_periods := l_sql_periods || ' AND c3.period_code <> :pi_period_code_from ';
257 
258          END IF ;
259 
260 	   END IF;
261 
262    	gmf_util.trace( 'Periods Query : ' || l_sql_periods, 1 ) ;
263    	gmf_util.trace( 'Orgn Query : ' || l_sql_orgn, 1 ) ;
264 
265       /*********************************************************************************
266       * Do not pass the l_from_range and l_to_range if resource class is not specified *
267       *********************************************************************************/
268       IF pi_resource_class is not null then
269 
270          OPEN cv_rsrc_dtl FOR l_sql_rsrc USING pi_legal_entity_id_from,pi_organization_id_from, l_period_id_from, pi_resource_class;
271 
272       ELSE
273 
274          OPEN cv_rsrc_dtl FOR l_sql_rsrc USING pi_legal_entity_id_from,pi_organization_id_from, l_period_id_from;
275 
276       END IF;
277 
278    	LOOP
279 
280          FETCH cv_rsrc_dtl INTO rec_rsrc_dtl ;
281    		EXIT WHEN cv_rsrc_dtl%NOTFOUND ;
282 
283          IF (pi_period_code_to IS NOT NULL) THEN
284            OPEN cv_periods FOR l_sql_periods USING pi_legal_entity_id_to, pi_period_id_to;
285    	   ELSIF (pi_calendar_code_from = pi_calendar_code_to) THEN
286    	      OPEN cv_periods FOR l_sql_periods USING pi_legal_entity_id_to, pi_calendar_code_to, pi_all_periods_from, pi_calendar_code_to, pi_all_periods_to, pi_calendar_code_to, pi_cost_type_id_to, pi_period_code_from;
287          ELSE
288    	      OPEN cv_periods FOR l_sql_periods USING pi_legal_entity_id_to, pi_calendar_code_to, pi_all_periods_from, pi_calendar_code_to, pi_all_periods_to, pi_calendar_code_to, pi_cost_type_id_to;
289    	   END IF;
290 
291    		LOOP
292 
293    			FETCH cv_periods INTO l_legal_entity_id_to, l_period_id_to;
294    			EXIT WHEN cv_periods%NOTFOUND ;
295 
296             IF (pi_all_organization_flag = 0) THEN
297                  OPEN cv_orgn FOR l_sql_orgn USING pi_organization_id_to;
298 	          ELSIF ((pi_calendar_code_from = pi_calendar_code_to) AND
299 		                    (pi_period_id_to IS NOT NULL) AND
300 		                    (l_period_id_from = pi_period_id_to)) THEN
301 	                OPEN cv_orgn FOR l_sql_orgn
302 	                     USING  pi_legal_entity_id_to,
303 	                     pi_organization_id_from;
304 	           ELSE
305 	             OPEN cv_orgn FOR l_sql_orgn
306 	                   USING  pi_legal_entity_id_to;
307               END IF;
308             LOOP
309 
310    				FETCH cv_orgn INTO l_organization_id_to ;
311    				EXIT WHEN cv_orgn%NOTFOUND ;
312 
313    				gmf_util.trace( 'Values : ' || rec_rsrc_dtl.resources || ' - ' || rec_rsrc_dtl.usage_uom || ' - ' || to_char(rec_rsrc_dtl.nominal_cost), 1 );
314                gmf_util.msg_log('GMF_CPRC_ORGPRD', nvl(TO_CHAR(l_organization_id_to), ' '), nvl(TO_CHAR(l_period_id_to),' '));
315 
316    				UPDATE      cm_rsrc_dtl
317    				SET         usage_uom         = rec_rsrc_dtl.usage_uom,
318    					         nominal_cost     = rec_rsrc_dtl.nominal_cost,
319    					         rollover_ind     = 0,	----unset the rollover_ind in target period
320    					         last_update_date = SYSDATE,
321    					         last_updated_by  = l_user_id,
322    					         trans_cnt        = 1,
323    					         delete_mark      = 0
324    				WHERE       legal_entity_id = l_legal_entity_id_to
325                AND         nvl(organization_id,0) = nvl(l_organization_id_to,0)
326                AND         period_id = l_period_id_to
327                AND         resources = rec_rsrc_dtl.resources;
328 
329    				IF SQL%ROWCOUNT > 0 THEN
330 
331                   l_upd_rows := l_upd_rows + SQL%ROWCOUNT;
332                   gmf_util.trace( 'Updated ' || TO_CHAR(SQL%ROWCOUNT) || ' rows', 1 );
333 
334                ELSE
335 
336    			      INSERT INTO    cm_rsrc_dtl
337                   (
338                   legal_entity_id,
339                   organization_id,
340                   resources,
341                   period_id,
342                   cost_type_id,
343                   usage_uom,
344                   nominal_cost,
345                   rollover_ind,
346                   creation_date,
347                   created_by,
348                   last_update_date,
349                   last_updated_by,
350                   trans_cnt,
351                   delete_mark
352    					)
353    					VALUES
354                   (
355                   l_legal_entity_id_to,
356                   l_organization_id_to,
360                   rec_rsrc_dtl.usage_uom,
357                   rec_rsrc_dtl.resources,
358                   l_period_id_to,
359                   pi_cost_type_id_to,
361                   rec_rsrc_dtl.nominal_cost,
362                   0,	----unset the rollover_ind in the target period
363                   SYSDATE,
364                   l_user_id,
365                   SYSDATE,
366                   l_user_id,
367                   1,
368                   0
369    					);
370 
371    					l_ins_rows := l_ins_rows + SQL%ROWCOUNT;
372                   gmf_util.trace( 'Inserted ' || TO_CHAR(SQL%ROWCOUNT) || ' rows', 1 );
373 
374                END IF;
375    	      END LOOP;	-- end of cursor for loop for Orgs
376    		END LOOP;	-- end of cursor for loop for periods
377    	END LOOP;	-- end of cursor for loop for resources
378 
379    	gmf_util.msg_log( 'GMF_CP_ROWS_SELECTED', TO_CHAR(l_ins_rows + l_upd_rows) );
380    	gmf_util.msg_log( 'GMF_CP_ROWS_UPDINS', TO_CHAR(l_upd_rows), TO_CHAR(l_ins_rows) );
381       gmf_util.log;
382    	gmf_util.msg_log( 'GMF_CPRC_END' );
383 
384       po_retcode := 0;
385    	po_errbuf := NULL;
386    	end_copy('NORMAL', NULL);
387    	COMMIT;
388 
389    EXCEPTION
390 	   WHEN e_no_cost_rows THEN
391 
392 		   po_retcode := 0;
393 		   po_errbuf := NULL;
394 		   end_copy( 'NORMAL', NULL );
395 
396 	   WHEN utl_file.invalid_path THEN
397 
398    		po_retcode := 3;
399    		po_errbuf := 'Invalid path - '||to_char(SQLCODE) || ' ' || SQLERRM;
400    		end_copy ('ERROR', NULL);
401 
402 	   WHEN utl_file.invalid_mode then
403 
404    		po_retcode := 3;
405    		po_errbuf := 'Invalid Mode - '||to_char(SQLCODE) || ' ' || SQLERRM;
406    		end_copy ('ERROR', NULL);
407 
408 	   WHEN utl_file.invalid_filehandle then
409 
410    		po_retcode := 3;
411    		po_errbuf := 'Invalid filehandle - '||to_char(SQLCODE) || ' ' || SQLERRM;
412    		end_copy ('ERROR', NULL);
413 
414 	   WHEN utl_file.invalid_operation then
415 
416    		po_retcode := 3;
417    		po_errbuf := 'Invalid operation - '||to_char(SQLCODE) || ' ' || SQLERRM;
418    		end_copy ('ERROR', NULL);
419 
420 	   WHEN utl_file.write_error then
421 
422    		po_retcode := 3;
423    		po_errbuf := 'Write error - '||to_char(SQLCODE) || ' ' || SQLERRM;
424    		end_copy ('ERROR', NULL);
425 
426 	   WHEN others THEN
427 
428    		po_retcode := 3;
429    		po_errbuf := to_char(SQLCODE) || ' ' || SQLERRM;
430    		end_copy ('ERROR', NULL);
431    END copy_rsrc_cost;
432 
433    /**************************************************************************************
434    * FUNCTION                                                                            *
435    *    do_costs_exist                                                                   *
436    *                                                                                     *
437    *   DESCRIPTION                                                                       *
438    *     Verifies if there exists any resource costs for the parameters passed           *
439    *                                                                                     *
440    *   INPUT PARAMETERS
441    *    pi_legal_entity_id   Legal Entity                                                              *
442    *    pi_organization_id   Organization                                                *
443    *    pi_calendar_code     Cost Calendar                                               *
444    *    pi_period_code       Cost Period                                                 *
445    *    pi_cost_type_id      Cost Method                                                 *
446    *    pi_resource_class    Resource Class                                              *
447    *                                                                                     *
448    *   HISTORY                                                                           *
449    *     11-Oct-1999 Rajesh Seshadri                                                     *
450    *     09-Jan-2004 Anoop Baddam BUG#3345313.                                           *
451    *     Modified the cursor cur_num_cost_rows.                                          *
452    *     Added the condition "p_resource_class IS NULL" to the where clause              *
453    *     that checks if there are any costs even if the resource class is not specified. *
454    **************************************************************************************/
455 
456    FUNCTION do_costs_exist
457    (
458    pi_legal_entity_id      IN             cm_rsrc_dtl.legal_entity_id%TYPE,
459 	pi_organization_id	   IN             cm_rsrc_dtl.organization_id%TYPE,
460 	pi_period_id		      IN             cm_rsrc_dtl.period_id%TYPE,
461 	pi_resource_class	      IN             cr_rsrc_mst.resource_class%TYPE
462 	)
463    RETURN NUMBER
464    IS
465 	 CURSOR cur_num_cost_rows
466       (
467       p_legal_entity_id          IN       cm_rsrc_dtl.legal_entity_id%TYPE,
468 		p_organization_id		      IN       cm_rsrc_dtl.organization_id%TYPE,
469 		p_period_id		            IN       cm_rsrc_dtl.period_id%TYPE,
470 		p_resource_class	         IN       cr_rsrc_mst.resource_class%TYPE
471 		)
472       IS
473 		SELECT      COUNT(1)
474 		FROM        cm_rsrc_dtl d,
475 			         cr_rsrc_mst m
476 		WHERE       d.legal_entity_id = p_legal_entity_id
477       AND         nvl(d.organization_id,0)	= nvl(p_organization_id,0)
478       AND         d.period_id = p_period_id
479       AND         d.delete_mark = 0
480       AND         d.resources	= m.resources
481       AND         (
482                   p_resource_class IS NULL
483                   OR m.resource_class	= p_resource_class
484                   )
485       AND         m.delete_mark		= 0;
486 
487 	   l_num_rows NUMBER := 0;
488 	   l_routine	VARCHAR2(41) := 'do_costs_exist' ;
489 
490    BEGIN
491 
492       OPEN cur_num_cost_rows( pi_legal_entity_id,pi_organization_id, pi_period_id, pi_resource_class );
493       FETCH cur_num_cost_rows INTO l_num_rows;
494       CLOSE cur_num_cost_rows;
495 
496 	   RETURN l_num_rows;
497 
498    END do_costs_exist;
499 
500 /**************************************************************************************
501    * FUNCTION                                                                            *
502    *    do_costs_exist                                                                  *
503    *                                                                                     *
504    *   DESCRIPTION                                                                       *
505    *     Verifies if there exists any resource costs for the parameters passed           *
506    *                                                                                     *
507    *   INPUT PARAMETERS
508    *    pi_legal_entity_id   Legal Entity                                                              *
509    *                                             *
510    *    pi_period_id      Cost Period                                                 *
511    *    pi_cost_type_id      Cost Method                                                 *
512    *    pi_resource_class    Resource Class                                              *
513    *                                                                                     *
514    *
515    **************************************************************************************/
516 
517    FUNCTION do_costs_exist
518    (
519    pi_legal_entity_id      IN             cm_rsrc_dtl.legal_entity_id%TYPE,
520    pi_period_id		      IN             cm_rsrc_dtl.period_id%TYPE,
521 	pi_resource_class	      IN             cr_rsrc_mst.resource_class%TYPE
522 	)
523    RETURN NUMBER
524    IS
525 	 CURSOR cur_num_cost_rows
526       (
527       p_legal_entity_id          IN       cm_rsrc_dtl.legal_entity_id%TYPE,
528       p_period_id		            IN       cm_rsrc_dtl.period_id%TYPE,
529 		p_resource_class	         IN       cr_rsrc_mst.resource_class%TYPE
530 		)
531       IS
532 		SELECT      COUNT(1)
533 		FROM        cm_rsrc_dtl d,
534 			         cr_rsrc_mst m
535 		WHERE       d.legal_entity_id = p_legal_entity_id
536       AND         d.organization_id IN (SELECT a.organization_id FROM  hr_organization_information a, mtl_parameters b
537   					   		                 where a.organization_id = b.organization_id
538 							                      and b.process_enabled_flag = 'Y' and
539 							                          a.org_information2 = p_legal_entity_id
540                                             and a.org_information_context = 'Accounting Information' )
541 
542       AND         d.period_id = p_period_id
543       AND         d.delete_mark = 0
544       AND         d.resources	= m.resources
545       AND         (
546                   p_resource_class IS NULL
547                   OR m.resource_class	= p_resource_class
548                   )
549       AND         m.delete_mark		= 0;
550 
551 	   l_num_rows NUMBER := 0;
552 	   l_routine	VARCHAR2(41) := 'do_costs_exist' ;
553 
554    BEGIN
555 
556       OPEN cur_num_cost_rows( pi_legal_entity_id, pi_period_id, pi_resource_class );
557       FETCH cur_num_cost_rows INTO l_num_rows;
558       CLOSE cur_num_cost_rows;
559 
560 	   RETURN l_num_rows;
561 
562    END do_costs_exist;
563 
564 
565 
566 
567 
568    /*****************************************************************************
569    * PROCEDURE                                                                  *
570    *     end_copy                                                               *
571    *                                                                            *
572    *   DESCRIPTION                                                              *
573    *     Sets the concurrent manager completion status                          *
574    *                                                                            *
575    *   INPUT PARAMETERS                                                         *
576    *     pi_errstat - Completion status, must be one of 'NORMAL', 'WARNING', or *
577    *    'ERROR'                                                                 *
578    *     pi_errmsg - Completion message to be passed back                       *
579    *                                                                            *
580    *   HISTORY                                                                  *
581    *     11-Oct-1999 Rajesh Seshadri                                            *
582    *                                                                            *
583    *****************************************************************************/
584 
585    PROCEDURE end_copy
586    (
587 	pi_errstat        IN          VARCHAR2,
588 	pi_errmsg         IN          VARCHAR2
589 	)
590    IS
591 	   l_retval BOOLEAN;
592    BEGIN
593 
594       l_retval := fnd_concurrent.set_completion_status(pi_errstat,pi_errmsg);
595 
596    END end_copy;
597 
598 END gmf_copy_rsrc_cost;