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