DBA Data[Home] [Help]

PACKAGE BODY: APPS.FA_MODIFY_DISTRIBUTIONS_PKG

Source


1 PACKAGE BODY FA_MODIFY_DISTRIBUTIONS_PKG as
2 /* $Header: FAMDSTB.pls 120.4 2002/12/20 01:13:11 glchen ship $ */
3 
4   PROCEDURE modify_distributions(
5         P_api_version      IN  NUMBER,
6         P_init_msg_list    IN  VARCHAR2,
7         P_commit           IN  VARCHAR2,
8         P_validation_level IN  NUMBER,
9         P_debug_flag       IN  VARCHAR2,
10         X_return_status    OUT NOCOPY VARCHAR2,
11         X_msg_count        OUT NOCOPY NUMBER,
12         X_msg_data         OUT NOCOPY VARCHAR2
13   ) IS
14 
15     G_PKG_NAME          CONSTANT VARCHAR2(30) := 'FA_MODIFY_DISTRIBUTIONS_PKG';
16     l_api_name          CONSTANT VARCHAR2(30) := 'Modify_Distributions';
17     l_api_version       CONSTANT NUMBER := 1.0;
18 
19     l_met_c_open                BOOLEAN      := FALSE;
20     l_last_fetch                BOOLEAN      := FALSE;
21     l_assignments_completed     BOOLEAN      := FALSE;
22 
23     l_book_type_code            VARCHAR2(15) := NULL;
24     l_asset_id                  NUMBER       := 0;
25     l_trx_reference_num         NUMBER       := -1;
26     l_trx_type                  VARCHAR2(15) := NULL;
27 
28     l_return_status             VARCHAR2(10) := FND_API.G_RET_STS_ERROR;
29     l_transaction_status        VARCHAR2(20) := 'ERRORED';
30 
31     CURSOR MET_C IS
32         SELECT   MET.rowid row_id, MET.*
33         FROM     fa_mass_external_transfers MET
34         WHERE    MET.batch_name = 'FA_MODIFY_DISTS'
35         AND      MET.transaction_status = 'POST'
36         AND      MET.transaction_type in ('UNIT ADJUSTMENT', 'TRANSFER')
37         ORDER BY MET.BOOK_TYPE_CODE,
38                  MET.FROM_ASSET_ID,
39                  MET.TRANSACTION_REFERENCE_NUM,
40                  MET.TRANSACTION_TYPE;
41 
42     METInfo MET_C%ROWTYPE;
43 
44   BEGIN
45 
46 --- int_debug.enable;
47 --- int_debug.print('Entered modify_distributions ');
48 
49     X_return_status := FND_API.G_RET_STS_SUCCESS;
50 
51     -- Standard start of API savepoint.
52     ---SAVEPOINT Modify_Dist_PUB;
53 
54     -- Standard call to check for call compatibility.
55     IF NOT FND_API.Compatible_API_Call(l_api_version, p_api_version,
56            l_api_name, G_PKG_NAME)
57     THEN
58        X_return_status := FND_API.G_RET_STS_ERROR;
59        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
60     END IF;
61 
62 
63     -- Initialize message list if p_init_msg_list is set to TRUE.
64     IF FND_API.To_Boolean(p_init_msg_list) THEN
65        -- Initialize error message stack.
66        FA_SRVR_MSG.Init_Server_Message;
67 
68        -- Initialize debug message stack.
69        FA_DEBUG_PKG.Initialize;
70     END IF;
71 
72     -- Override FA:PRINT_DEBUG profile option.
73     IF (p_debug_flag = 'YES') THEN
74        FA_DEBUG_PKG.Set_Debug_Flag;
75     END IF;
76 
77     g_asgn_count := 0;
78     asgn_table.delete;
79     l_book_type_code    := NULL;
80     l_asset_id          := 0;
81     l_trx_reference_num := -1;
82     l_trx_type          := NULL;
83 
84     OPEN  MET_C;
85     l_met_c_open := TRUE;
86 
87     LOOP  -- begin for each row in fa_mass_external_transfers
88 
89     FETCH MET_C
90     INTO  METInfo;
91 
92     if (MET_C%NOTFOUND) then
93 
94         CLOSE MET_C;
95         l_met_c_open := FALSE;
96 
97         l_last_fetch := TRUE;
98         l_assignments_completed := TRUE;
99 
100     elsif ((l_book_type_code <> METInfo.book_type_code) OR
101            (l_asset_id <> METInfo.from_asset_id) OR
102            (l_trx_reference_num <> METInfo.transaction_reference_num) OR
103            (l_trx_type <> METInfo.transaction_type)) then
104 
105         l_last_fetch            := FALSE;
106         l_assignments_completed := TRUE;
107 
108     else
109 
110         l_last_fetch            := FALSE;
111         l_assignments_completed := FALSE;
112 
113     end if;
114 
115     if ((l_assignments_completed = TRUE) AND (g_asgn_count > 0)) then
116 
117          -- process transaction type
118 
119          if (l_trx_type = 'UNIT ADJUSTMENT') then
120 
121 --- int_debug.print('Calling process_unit_adjustment ');
122 
123               l_return_status := process_unit_adjustment(
124                          p_api_version      => p_api_version,
125                          p_init_msg_list    => p_init_msg_list,
126                          p_commit           => p_commit,
127                          p_validation_level => p_validation_level,
128                          p_debug_flag       => p_debug_flag,
129                          x_return_status    => x_return_status,
130                          x_msg_count        => x_msg_count,
131                          x_msg_data         => x_msg_data,
132                          book_type_code     => l_book_type_code,
133                          asset_id           => l_asset_id);
134 
135          elsif (l_trx_type = 'TRANSFER') then
136 
137 --- int_debug.print('Calling process_transfer ');
138               l_return_status := process_transfer(
139                          p_api_version      => p_api_version,
140                          p_init_msg_list    => p_init_msg_list,
141                          p_commit           => p_commit,
142                          p_validation_level => p_validation_level,
143                          p_debug_flag       => p_debug_flag,
144                          x_return_status    => x_return_status,
145                          x_msg_count        => x_msg_count,
146                          x_msg_data         => x_msg_data,
147                          book_type_code     => l_book_type_code,
148                          asset_id           => l_asset_id);
149 
150          end if;
151 
152          if (l_return_status = FND_API.G_RET_STS_SUCCESS) then
153              l_transaction_status := 'POSTED';
154          else
155              l_transaction_status := 'ERRORED';
156              X_return_status := FND_API.G_RET_STS_ERROR;
157          end if;
158 
159          FOR i IN asgn_table.FIRST .. asgn_table.LAST LOOP
160 
161              UPDATE fa_mass_external_transfers MET
162              SET    MET.transaction_status = l_transaction_status
163              WHERE  MET.rowid = asgn_table(i).row_id
164              AND    MET.transaction_status = 'POST';
165 
166          END LOOP;
167 
168          IF FND_API.To_Boolean(p_commit) THEN
169            COMMIT WORK;
170          END IF;
171 
172          g_asgn_count := 0;
173          asgn_table.delete;
174          FA_LOAD_TBL_PKG.g_dist_count := 0;
175 
176     end if;
177 
178     if (l_last_fetch = FALSE) then
179 
180         if (METInfo.last_update_login is NULL) then
181             METInfo.last_update_login := METInfo.last_updated_by;
182         end if;
183 
184         insert_dist_table( row_id            =>  METInfo.row_id,
185                            asset_id          =>  METInfo.from_asset_id,
186                            transfer_units    =>  METInfo.transfer_units,
187                            transaction_date_entered
188                                              =>
189                               METInfo.transaction_date_entered,
190                            from_dist_id      =>  METInfo.from_distribution_id,
191                            from_location_id  =>  METInfo.from_location_id,
192                            from_assigned_to  =>  METInfo.from_employee_id,
193                            from_ccid         =>  METInfo.from_gl_ccid,
194                            to_dist_id        =>  METInfo.to_distribution_id,
195                            to_location_id    =>  METInfo.to_location_id,
196                            to_assigned_to    =>  METInfo.to_employee_id,
197                            to_ccid           =>  METInfo.to_gl_ccid,
198                            attribute1        =>  METInfo.attribute1,
199                            attribute2        =>  METInfo.attribute2,
200                            attribute3        =>  METInfo.attribute3,
201                            attribute4        =>  METInfo.attribute4,
202                            attribute5        =>  METInfo.attribute5,
203                            attribute6        =>  METInfo.attribute6,
204                            attribute7        =>  METInfo.attribute7,
205                            attribute8        =>  METInfo.attribute8,
206                            attribute9        =>  METInfo.attribute9,
207                            attribute10       =>  METInfo.attribute10,
208                            attribute11       =>  METInfo.attribute11,
209                            attribute12       =>  METInfo.attribute12,
210                            attribute13       =>  METInfo.attribute13,
211                            attribute14       =>  METInfo.attribute14,
212                            attribute15       =>  METInfo.attribute15,
213                            attribute_category_code
214                                        =>  METInfo.attribute_category_code,
215                            post_batch_id     =>  METInfo.post_batch_id,
216                            last_updated_by   =>  METInfo.last_updated_by,
217                            last_update_date  =>  METInfo.last_update_date,
218                            last_update_login =>  METInfo.last_update_login);
219 
220         l_book_type_code    := METInfo.book_type_code;
221         l_asset_id          := METInfo.from_asset_id;
222         l_trx_reference_num := METInfo.transaction_reference_num;
223         l_trx_type          := METInfo.transaction_type;
224 
225     end if;
226 
227     if (l_last_fetch = TRUE) then
228 
229         EXIT; -- exit loop for each row in fa_mass_external_transfers
230 
231     end if;
232 
233     END LOOP; -- end for each row in fa_mass_external_transfers
234 
235   EXCEPTION
236 
237       when others then
238 
239           X_return_status := FND_API.G_RET_STS_ERROR;
240 
241           if (l_met_c_open = TRUE) then
242               CLOSE MET_C;
243               l_met_c_open := FALSE;
244           end if;
245 
246   END modify_distributions;
247 
248   PROCEDURE insert_dist_table(
249         row_id            IN  ROWID,
250         asset_id          IN  NUMBER,
251         transfer_units    IN  NUMBER,
252         transaction_date_entered
253                           IN  DATE,
254         from_dist_id      IN  NUMBER,
255         from_location_id  IN  NUMBER,
256         from_assigned_to  IN  NUMBER,
257         from_ccid         IN  NUMBER,
258         to_dist_id        IN  NUMBER,
259         to_location_id    IN  NUMBER,
260         to_assigned_to    IN  NUMBER,
261         to_ccid           IN  NUMBER,
262         attribute1        IN  VARCHAR2,
263         attribute2        IN  VARCHAR2,
264         attribute3        IN  VARCHAR2,
265         attribute4        IN  VARCHAR2,
266         attribute5        IN  VARCHAR2,
267         attribute6        IN  VARCHAR2,
268         attribute7        IN  VARCHAR2,
269         attribute8        IN  VARCHAR2,
270         attribute9        IN  VARCHAR2,
271         attribute10       IN  VARCHAR2,
272         attribute11       IN  VARCHAR2,
273         attribute12       IN  VARCHAR2,
274         attribute13       IN  VARCHAR2,
275         attribute14       IN  VARCHAR2,
276         attribute15       IN  VARCHAR2,
277         attribute_category_code IN  VARCHAR2,
278         post_batch_id     IN  NUMBER,
279         last_updated_by   IN  NUMBER,
280         last_update_date IN  DATE,
281         last_update_login IN  NUMBER
282   ) IS
283 
284     X_row_id              ROWID := NULL;
285     X_asset_id            NUMBER;
286     X_dist_id             NUMBER;
287     X_new_dist_id         NUMBER := NULL;
288     X_location_id         NUMBER;
289     X_assigned_to         NUMBER;
290     X_ccid                NUMBER;
291     X_record_status       NUMBER;
292     x_units               NUMBER;
293 
294     CURSOR DH_C IS
295         SELECT DH.rowid row_id, DH.*
296         FROM   fa_distribution_history DH
297         WHERE  DH.asset_id = X_asset_id
298         AND    DH.distribution_id = NVL(X_dist_id, DH.distribution_id)
299         AND    DH.location_id = NVL(X_location_id, DH.location_id)
300         AND    DH.code_combination_id = NVL(X_ccid, DH.code_combination_id)
301         AND    NVL(DH.assigned_to, -1) = NVL(X_assigned_to, -1)
302         AND    DH.date_ineffective IS NULL;
303 
304     DHInfo DH_C%ROWTYPE;
305 
306   BEGIN
307 
308     if (transfer_units = 0) then
309 
310         UPDATE fa_mass_external_transfers MET
311         SET    MET.transaction_status = 'IGNORED'
312         WHERE  MET.rowid = row_id;
313 
314         return;
315 
316     end if;
317 
318     if ((transfer_units < 0) AND
319         ((from_dist_id is NOT NULL) OR
320          ((from_ccid is NOT NULL) AND (from_location_id is NOT NULL))
321         )
322        ) then
323 
324         X_asset_id    := asset_id;
325 
326         if ((from_ccid is NOT NULL) AND (from_location_id is NOT NULL)) then
327             X_dist_id := NULL;
328             X_location_id := from_location_id;
329             X_ccid        := from_ccid;
330             X_assigned_to := from_assigned_to;
331         else
332             X_dist_id := from_dist_id;
333             X_location_id := NULL;
334             X_ccid := NULL;
335             X_assigned_to := to_assigned_to;
336         end if;
337 
338 
339         OPEN  DH_C;
340         FETCH DH_C
341         INTO  DHInfo;
342 
343         if (DH_C%NOTFOUND) then
344             DHInfo.row_id := X_row_id;
345             DHInfo.distribution_id := NULL;
346             DHInfo.units_assigned := transfer_units;
347             DHInfo.code_combination_id := from_ccid;
348             DHInfo.location_id := from_location_id;
349             DHInfo.assigned_to := from_assigned_to;
350             DHInfo.transaction_header_id_in := NULL;
351         end if;
352 
353         CLOSE DH_C;
354 
355         FA_LOAD_TBL_PKG.load_dist_table(
356             p_row_id            => DHInfo.row_id,
357             p_dist_id           => DHInfo.distribution_id,
358             p_asset_id          => asset_id,
359             p_units             => DHInfo.units_assigned,
360             p_date_effective    => sysdate,
361             p_ccid              => DHInfo.code_combination_id,
362             p_location_id       => DHInfo.location_id,
363             p_th_id_in          => DHINfo.transaction_header_id_in,
364             p_assigned_to       => DHInfo.assigned_to,
365             p_trans_units       => transfer_units,
366             p_record_status     => 'UPDATE');
367 
368         load_asgn_table(
369             p_row_id            => row_id,
370             p_dist_id           => DHInfo.distribution_id,
371             p_asset_id          => asset_id,
372             p_units             => DHInfo.units_assigned,
373             p_transaction_date_entered
374                                 => transaction_date_entered,
375             p_date_effective    => sysdate,
376             p_ccid              => DHInfo.code_combination_id,
377             p_location_id       => DHInfo.location_id,
378             p_th_id_in          => DHINfo.transaction_header_id_in,
379             p_assigned_to       => DHInfo.assigned_to,
380             p_trans_units       => transfer_units,
381             p_record_status     => 'UPDATE',
382             p_attribute1        => attribute1,
383             p_attribute2        => attribute2,
384             p_attribute3        => attribute3,
385             p_attribute4        => attribute4,
386             p_attribute5        => attribute5,
387             p_attribute6        => attribute6,
388             p_attribute7        => attribute7,
389             p_attribute8        => attribute8,
390             p_attribute9        => attribute9,
391             p_attribute10       => attribute10,
392             p_attribute11       => attribute11,
393             p_attribute12       => attribute12,
394             p_attribute13       => attribute13,
395             p_attribute14       => attribute14,
396             p_attribute15       => attribute15,
397             p_attribute_category_code => attribute_category_code,
398             p_last_updated_by   => last_updated_by,
399             p_last_update_date  => last_update_date,
400             p_last_update_login => last_update_login);
401 
402     end if;
403 
404     if ((transfer_units > 0) AND
405         ((to_dist_id is NOT NULL) OR
406          ((to_ccid is NOT NULL) AND (to_location_id is NOT NULL))
407         )
408        ) then
409 
410         X_asset_id    := asset_id;
411 
412         if ((to_ccid is NOT NULL) AND (to_location_id is NOT NULL)) then
413             X_dist_id := NULL;
414             X_location_id := to_location_id;
415             X_assigned_to := to_assigned_to;
416             X_ccid        := to_ccid;
417         else
418             X_dist_id := to_dist_id;
419             X_location_id := NULL;
420             X_ccid := NULL;
421             X_assigned_to := to_assigned_to;
422         end if;
423 
424         OPEN  DH_C;
425         FETCH DH_C
426         INTO  DHINfo;
427 
428         if (DH_C%NOTFOUND) then
429             DHInfo.row_id := X_row_id;
430             DHInfo.distribution_id := NULL;
431             DHInfo.units_assigned := transfer_units;
432             DHInfo.code_combination_id := to_ccid;
433             DHInfo.location_id := to_location_id;
434             DHInfo.assigned_to := to_assigned_to;
435             DHInfo.transaction_header_id_in := NULL;
436         end if;
437 
438         CLOSE DH_C;
439 
440         if (DHInfo.distribution_id is NULL) then
441 
442             x_units := transfer_units;
443 
444             FA_LOAD_TBL_PKG.load_dist_table(
445                 p_row_id            => X_row_id,
446                 p_dist_id           => X_new_dist_id,
447                 p_asset_id          => asset_id,
448                 p_units             => x_units,
449                 p_date_effective    => sysdate,
450                 p_ccid              => to_ccid,
451                 p_location_id       => to_location_id,
452                 p_th_id_in          => NULL,
453                 p_assigned_to       => to_assigned_to,
454                 p_trans_units       => transfer_units,
455                 p_record_status     => 'INSERT');
456 
457             load_asgn_table(
458                 p_row_id            => row_id,
459                 p_dist_id           => X_new_dist_id,
460                 p_asset_id          => asset_id,
461                 p_units             => x_units,
462                 p_transaction_date_entered
463                                     => transaction_date_entered,
464                 p_date_effective    => sysdate,
465                 p_ccid              => to_ccid,
466                 p_location_id       => to_location_id,
467                 p_th_id_in          => NULL,
468                 p_assigned_to       => to_assigned_to,
469                 p_trans_units       => transfer_units,
470                 p_record_status     => 'INSERT',
471                 p_attribute1        => attribute1,
472                 p_attribute2        => attribute2,
473                 p_attribute3        => attribute3,
474                 p_attribute4        => attribute4,
475                 p_attribute5        => attribute5,
476                 p_attribute6        => attribute6,
477                 p_attribute7        => attribute7,
478                 p_attribute8        => attribute8,
479                 p_attribute9        => attribute9,
480                 p_attribute10       => attribute10,
481                 p_attribute11       => attribute11,
482                 p_attribute12       => attribute12,
483                 p_attribute13       => attribute13,
484                 p_attribute14       => attribute14,
485                 p_attribute15       => attribute15,
486                 p_attribute_category_code => attribute_category_code,
487                 p_last_updated_by   => last_updated_by,
488                 p_last_update_date => last_update_date,
489                 p_last_update_login => last_update_login);
490 
491         else
492 
493             FA_LOAD_TBL_PKG.load_dist_table(
494                 p_row_id            => DHInfo.row_id,
495                 p_dist_id           => DHInfo.distribution_id,
496                 p_asset_id          => asset_id,
497                 p_units             => DHInfo.units_assigned,
498                 p_date_effective    => sysdate,
499                 p_ccid              => DHInfo.code_combination_id,
500                 p_location_id       => DHInfo.location_id,
501                 p_th_id_in          => DHInfo.transaction_header_id_in,
502                 p_assigned_to       => DHInfo.assigned_to,
503                 p_trans_units       => transfer_units,
504                 p_record_status     => 'UPDATE');
505 
506             load_asgn_table(
507                 p_row_id            => row_id,
508                 p_dist_id           => DHInfo.distribution_id,
509                 p_asset_id          => asset_id,
510                 p_units             => DHInfo.units_assigned,
511                 p_transaction_date_entered
512                                     => transaction_date_entered,
513                 p_date_effective    => sysdate,
514                 p_ccid              => DHInfo.code_combination_id,
515                 p_location_id       => DHInfo.location_id,
516                 p_th_id_in          => DHInfo.transaction_header_id_in,
517                 p_assigned_to       => DHInfo.assigned_to,
518                 p_trans_units       => transfer_units,
519                 p_record_status     => 'UPDATE',
520                 p_attribute1        => attribute1,
521                 p_attribute2        => attribute2,
522                 p_attribute3        => attribute3,
523                 p_attribute4        => attribute4,
524                 p_attribute5        => attribute5,
525                 p_attribute6        => attribute6,
526                 p_attribute7        => attribute7,
527                 p_attribute8        => attribute8,
528                 p_attribute9        => attribute9,
529                 p_attribute10       => attribute10,
530                 p_attribute11       => attribute11,
531                 p_attribute12       => attribute12,
532                 p_attribute13       => attribute13,
533                 p_attribute14       => attribute14,
534                 p_attribute15       => attribute15,
535                 p_attribute_category_code => attribute_category_code,
536                 p_last_updated_by   => last_updated_by,
537                 p_last_update_date  => last_update_date,
538                 p_last_update_login => last_update_login);
539 
540         end if;
541 
542     end if;
543 
544     if (((transfer_units < 0) AND ((from_dist_id is NULL) AND
545                  ((from_ccid is NULL) OR (from_location_id is NULL)))) OR
546         ((transfer_units > 0) AND ((to_dist_id is NULL) AND
547                  ((to_ccid is NULL) OR (to_location_id is NULL))))
548        ) then
549 
550         UPDATE fa_mass_external_transfers MET
551         SET    MET.transaction_status = 'ERRORED'
552         WHERE  MET.rowid = row_id;
553 
554     end if;
555 
556   EXCEPTION
557 
558       when others then
559         UPDATE fa_mass_external_transfers MET
560         SET    MET.transaction_status = 'ERRORED'
561         WHERE  MET.rowid = row_id;
562 
563   END insert_dist_table;
564 
565 
566 /* Procedure    load_asgn_table
567 
568        Usage    Called by client to load all distributions in the
569         global table asgn_line_tbl before calling the API
570 */
571 
572   PROCEDURE load_asgn_table
573          (p_row_id            IN ROWID default null,
574           p_dist_id           IN number default null,
575           p_asset_id          IN number default null,
576           p_units             IN number,
577           p_transaction_date_entered
578                               IN date,
579           p_date_effective    IN date,
580           p_ccid              IN number,
581           p_location_id       IN number,
582           p_th_id_in          IN number,
583           p_assigned_to       IN number,
584           p_trans_units       IN number,
585           p_record_status     IN varchar2,
586           p_attribute1        IN varchar2,
587           p_attribute2        IN varchar2,
588           p_attribute3        IN varchar2,
589           p_attribute4        IN varchar2,
590           p_attribute5        IN varchar2,
591           p_attribute6        IN varchar2,
592           p_attribute7        IN varchar2,
593           p_attribute8        IN varchar2,
594           p_attribute9        IN varchar2,
595           p_attribute10       IN varchar2,
596           p_attribute11       IN varchar2,
597           p_attribute12       IN varchar2,
598           p_attribute13       IN varchar2,
599           p_attribute14       IN varchar2,
600           p_attribute15       IN varchar2,
601           p_attribute_category_code
602                               IN varchar2,
603           p_last_updated_by   IN  NUMBER,
604           p_last_update_date  IN  DATE,
605           p_last_update_login IN  NUMBER
606   ) IS
607   BEGIN
608        if (g_asgn_count=0) then   /* initialize the table */
609            asgn_table.delete;
610        end if;
611 
612        g_asgn_count := g_asgn_count + 1;
613 
614        asgn_table(g_asgn_count).row_id := p_row_id;
615        asgn_table(g_asgn_count).dist_id := p_dist_id;
616        asgn_table(g_asgn_count).asset_id := p_asset_id;
617        asgn_table(g_asgn_count).units := p_units;
618        asgn_table(g_asgn_count).transaction_date_entered :=
619           p_transaction_date_entered;
620        asgn_table(g_asgn_count).ccid := p_ccid;
621        asgn_table(g_asgn_count).location_id := p_location_id;
622        asgn_table(g_asgn_count).th_id_in := p_th_id_in;
623        asgn_table(g_asgn_count).assigned_to := p_assigned_to;
624        asgn_table(g_asgn_count).trans_units := p_trans_units;
625        asgn_table(g_asgn_count).attribute1 := p_attribute1;
626        asgn_table(g_asgn_count).attribute2 := p_attribute2;
627        asgn_table(g_asgn_count).attribute3 := p_attribute3;
628        asgn_table(g_asgn_count).attribute4 := p_attribute4;
629        asgn_table(g_asgn_count).attribute5 := p_attribute5;
630        asgn_table(g_asgn_count).attribute6 := p_attribute6;
631        asgn_table(g_asgn_count).attribute7 := p_attribute7;
632        asgn_table(g_asgn_count).attribute8 := p_attribute8;
633        asgn_table(g_asgn_count).attribute9 := p_attribute9;
634        asgn_table(g_asgn_count).attribute10 := p_attribute10;
635        asgn_table(g_asgn_count).attribute11 := p_attribute11;
636        asgn_table(g_asgn_count).attribute12 := p_attribute12;
637        asgn_table(g_asgn_count).attribute13 := p_attribute13;
638        asgn_table(g_asgn_count).attribute14 := p_attribute14;
639        asgn_table(g_asgn_count).attribute15 := p_attribute15;
640        asgn_table(g_asgn_count).attribute_category_code :=
641                                                  p_attribute_category_code;
642        asgn_table(g_asgn_count).record_status := p_record_status;
643        asgn_table(g_asgn_count).last_updated_by := p_last_updated_by;
644        asgn_table(g_asgn_count).last_update_date := p_last_update_date;
645        asgn_table(g_asgn_count).last_update_login := p_last_update_login;
646 
647   END load_asgn_table;
648 
649   FUNCTION process_unit_adjustment(
650         p_api_version      IN NUMBER,
651         p_init_msg_list    IN VARCHAR2,
652         p_commit           IN VARCHAR2,
653         p_validation_level IN NUMBER,
654         p_debug_flag       IN VARCHAR2,
655         x_return_status    OUT NOCOPY VARCHAR2,
656         x_msg_count        OUT NOCOPY NUMBER,
657         x_msg_data         OUT NOCOPY VARCHAR2,
658         book_type_code     IN VARCHAR2,
659         asset_id           IN NUMBER
660   ) RETURN VARCHAR2
661   IS
662 
663       h_return_status    VARCHAR2(10) := FND_API.G_RET_STS_ERROR;
664       h_msg_count        NUMBER := 0;
665       h_msg_data         VARCHAR2(512) := NULL;
666 
667       X_asset_id NUMBER;
668 
669       CURSOR ADD_C IS
670           SELECT   AD.*
671           FROM     fa_additions_b AD
672           WHERE    AD.asset_id = X_asset_id;
673 
674       ADDInfo ADD_C%ROWTYPE;
675 
676       X_lease_id NUMBER;
677 
678       CURSOR LEA_C IS
679           SELECT   LEA.rowid row_id, LEA.*
680           FROM     fa_leases LEA
681           WHERE    LEA.lease_id = X_lease_id;
682 
683       LEAInfo LEA_C%ROWTYPE;
684 
685       l_th_row_id                   ROWID          := NULL;
686       l_Transaction_Header_Id      NUMBER(15)     := NULL;
687       l_Transaction_Date_Entered   DATE;
688       l_Max_Transaction_Date       DATE;
689       l_Current_PC                   NUMBER(15);
690       l_Calendar_Period_Open_Date  DATE;
691       l_Calendar_Period_Close_Date DATE;
692       l_FY_Start_Date               DATE;
693       l_FY_End_Date                   DATE;
694       l_total_trans_units          NUMBER;
695       l_new_current_units          NUMBER;
696       l_return_status              VARCHAR2(15) := FND_API.G_RET_STS_ERROR;
697 
698   BEGIN
699 
700       -- check that book_type_code is 'CORPORATE' book
701       l_return_status := check_if_corp_book(book_type_code => book_type_code);
702 
703       if (l_return_status <> FND_API.G_RET_STS_SUCCESS) then
704 
705           h_return_status := FND_API.G_RET_STS_ERROR;
706           return(h_return_status);
707 
708       end if;
709 
710       X_asset_id := asset_id;
711 
712       OPEN  ADD_C;
713       FETCH ADD_C
714       INTO  ADDInfo;
715 
716       if (ADD_C%NOTFOUND) then
717 
718         CLOSE ADD_C;
719 
720         h_return_status := FND_API.G_RET_STS_ERROR;
721         return(h_return_status);
722 
723       end if;
724 
725       CLOSE ADD_C;
726 
727       --- CHECK UNITS and DIST_ID
728       l_total_trans_units := 0;
729 
730       FOR i IN asgn_table.FIRST .. asgn_table.LAST LOOP
731 
732           l_return_status := check_location_ccid(
733                                      p_location_id => asgn_table(i).location_id,
734                                      p_ccid_id     => asgn_table(i).ccid);
735 
736           if (l_return_status <> FND_API.G_RET_STS_SUCCESS) then
737 
738               h_return_status := FND_API.G_RET_STS_ERROR;
739               return(h_return_status);
740 
741           end if;
742 
743           if ((asgn_table(i).dist_id is NULL) OR
744               (asgn_table(i).units + asgn_table(i).trans_units < 0)) then
745 
746               h_return_status := FND_API.G_RET_STS_ERROR;
747               return(h_return_status);
748 
749           end if;
750 
751           l_total_trans_units := l_total_trans_units+asgn_table(i).trans_units;
752 
753       END LOOP;
754 
755       l_new_current_units := l_total_trans_units + ADDInfo.Current_Units;
756 
757       if (l_new_current_units < 1) then
758 
759           h_return_status := FND_API.G_RET_STS_ERROR;
760           return(h_return_status);
761 
762       end if;
763 
764       --- Get rest of information
765       get_header_info(
766             X_Asset_Id                   => asset_id,
767             X_Book_Type_Code             => book_type_code,
768             X_Transaction_Header_Id      => l_Transaction_Header_Id,
769             X_Transaction_Date_Entered   => l_Transaction_Date_Entered,
770             X_Max_Transaction_Date       => l_Max_Transaction_Date,
771             X_Current_PC                 => l_Current_PC,
772             X_Calendar_Period_Open_Date  => l_Calendar_Period_Open_Date,
773             X_Calendar_Period_Close_Date => l_Calendar_Period_Close_Date,
774             X_FY_Start_Date              => l_FY_Start_Date,
775             X_FY_End_Date                => l_FY_End_Date,
776             X_return_status              => l_return_status
777       );
778 
779       if (l_return_status <> FND_API.G_RET_STS_SUCCESS) then
780 
781           h_return_status := FND_API.G_RET_STS_ERROR;
782           return(h_return_status);
783 
784       end if;
785 
786       X_lease_id := ADDInfo.lease_id;
787 
788       if (X_lease_id is NOT NULL) then
789 
790           OPEN  LEA_C;
791           FETCH LEA_C
792           INTO  LEAInfo;
793 
794           if (LEA_C%NOTFOUND) then
795 
796             CLOSE LEA_C;
797 
798             h_return_status := FND_API.G_RET_STS_ERROR;
799             return(h_return_status);
800 
801           end if;
802 
803           CLOSE LEA_C;
804 
805       end if;
806 
807       FA_TRANS_API_PUB.Do_Unit_Adjustment(
808             -- Standard Parameters --
809             p_api_version           => p_api_version,   ----1.0,
810             p_init_msg_list         => p_init_msg_list, ----FND_API.G_TRUE,
811             p_commit                => p_commit,        ----FND_API.G_TRUE,
812             p_validation_level      => p_validation_level,
813                                                  ----FND_API.G_VALID_LEVEL_FULL,
814             x_return_status         => h_return_status,
815             x_msg_count             => h_msg_count,
816             x_msg_data              => h_msg_data,
817             p_calling_fn            =>
818                'fa_modify_distributions_pkg.process_unit_adjustment',
819             -- API Options --
820             p_debug_flag            => p_debug_flag,    ----'NO',
821             -- Out Parameters --
822             x_transaction_header_id => l_transaction_header_id,
823             -- Transaction Info --
824             p_transaction_date_entered =>
825                nvl(asgn_table(1).transaction_date_entered,
826                    l_Transaction_Date_Entered),
827             p_transaction_name      => NULL,
828             p_mass_reference_id     => NULL,
829             p_calling_interface     => 'FA_MODIFY_DISTS',
830             p_last_update_date      => asgn_table(1).last_update_date,
831             p_created_by            => asgn_table(1).last_updated_by,
832             p_creation_date         => asgn_table(1).last_update_date,
833             p_last_updated_by       => asgn_table(1).last_updated_by,
834             p_last_update_login     => asgn_table(1).last_update_login,
835             p_attribute1            => asgn_table(1).attribute1,
836             p_attribute2            => asgn_table(1).attribute2,
837             p_attribute3            => asgn_table(1).attribute3,
838             p_attribute4            => asgn_table(1).attribute4,
839             p_attribute5            => asgn_table(1).attribute5,
840             p_attribute6            => asgn_table(1).attribute6,
841             p_attribute7            => asgn_table(1).attribute7,
842             p_attribute8            => asgn_table(1).attribute8,
843             p_attribute9            => asgn_table(1).attribute9,
844             p_attribute10           => asgn_table(1).attribute10,
845             p_attribute11           => asgn_table(1).attribute11,
846             p_attribute12           => asgn_table(1).attribute12,
847             p_attribute13           => asgn_table(1).attribute13,
848             p_attribute14           => asgn_table(1).attribute14,
849             p_attribute15           => asgn_table(1).attribute15,
850             p_attribute_category_code
851                                     =>
852                asgn_table(1).attribute_category_code,
853             -- Asset Header Info --
854             p_asset_id              => ADDInfo.Asset_Id,
855             p_book_type_code        => book_type_code
856       );
857 
858       x_return_status := h_return_status;
859       x_msg_count     := h_msg_count;
860       x_msg_data      := h_msg_data;
861 
862       if (h_return_status <> FND_API.G_RET_STS_SUCCESS) then
863             h_return_status := FND_API.G_RET_STS_ERROR;
864       end if;
865 
866       return(h_return_status);
867 
868   EXCEPTION
869 
870       when others then
871           h_return_status := FND_API.G_RET_STS_ERROR;
872           x_return_status := h_return_status;
873           x_msg_count     := h_msg_count;
874           x_msg_data      := h_msg_data;
875 
876           return(h_return_status);
877   END;
878 
879   FUNCTION process_transfer(
880         p_api_version      IN NUMBER,
881         p_init_msg_list    IN VARCHAR2,
882         p_commit           IN VARCHAR2,
883         p_validation_level IN NUMBER,
884         p_debug_flag       IN VARCHAR2,
885         x_return_status    OUT NOCOPY VARCHAR2,
886         x_msg_count        OUT NOCOPY NUMBER,
887         x_msg_data         OUT NOCOPY VARCHAR2,
888         book_type_code     IN VARCHAR2,
889         asset_id           IN NUMBER
890   ) RETURN VARCHAR2
891   IS
892 
893       h_return_status    VARCHAR2(10) := FND_API.G_RET_STS_ERROR;
894       h_msg_count        NUMBER := 0;
895       h_msg_data         VARCHAR2(512) := NULL;
896 
897       X_asset_id NUMBER;
898 
899       CURSOR ADD_C IS
900           SELECT   AD.*
901           FROM     fa_additions_b AD
902           WHERE    AD.asset_id = X_asset_id;
903 
904       ADDInfo ADD_C%ROWTYPE;
905 
906       l_row_id                     ROWID := NULL;
907       l_Transaction_Header_Id      NUMBER(15);
908       l_Transaction_Date_Entered   DATE;
909       l_Max_Transaction_Date       DATE;
910       l_Current_PC                   NUMBER(15);
911       l_Calendar_Period_Open_Date  DATE;
912       l_Calendar_Period_Close_Date DATE;
913       l_FY_Start_Date               DATE;
914       l_FY_End_Date                   DATE;
915       l_total_trans_units          NUMBER;
916       l_return_status              VARCHAR2(15) := FND_API.G_RET_STS_ERROR;
917       l_count                      number := 0;
918       l_txn_type_code              varchar2(20);
919       l_book                       varchar2(15);
920       l_asset                      number;
921 
922   BEGIN
923 
924 --- int_debug.print('Entered process_transfer ');
925 
926       -- check that book_type_code is 'CORPORATE' book
927       l_return_status := check_if_corp_book(book_type_code => book_type_code);
928 
929       if (l_return_status <> FND_API.G_RET_STS_SUCCESS) then
930 
931           h_return_status := FND_API.G_RET_STS_ERROR;
932           return(h_return_status);
933 
934       end if;
935 
936       X_asset_id := asset_id;
937 
938       OPEN  ADD_C;
939       FETCH ADD_C
940       INTO  ADDInfo;
941 
942       if (ADD_C%NOTFOUND) then
943 
944         CLOSE ADD_C;
945 
946         h_return_status := FND_API.G_RET_STS_ERROR;
947         return(h_return_status);
948 
949       end if;
950 
951       CLOSE ADD_C;
952 
953       --- CHECK UNITS and DIST_ID
954       l_total_trans_units := 0;
955 
956 --- int_debug.print('Entered checking table ');
957 
958       FOR i IN asgn_table.FIRST .. asgn_table.LAST LOOP
959 
960           l_return_status := check_location_ccid(
961                                      p_location_id => asgn_table(i).location_id,
962                                      p_ccid_id     => asgn_table(i).ccid);
963 
964           if (l_return_status <> FND_API.G_RET_STS_SUCCESS) then
965 
966               h_return_status := FND_API.G_RET_STS_ERROR;
967               return(h_return_status);
968 
969           end if;
970 
971           if ((asgn_table(i).trans_units < 0) AND
972                                            (asgn_table(i).dist_id is NULL)) then
973 
974 --- int_debug.print('trans_units < 0 and dist_id is NULL');
975 
976               h_return_status := FND_API.G_RET_STS_ERROR;
977               return(h_return_status);
978           end if;
979 
980           if (asgn_table(i).units + asgn_table(i).trans_units < 0) then
981 
982 --- int_debug.print('units + trans_units < 0');
983 
984               h_return_status := FND_API.G_RET_STS_ERROR;
985               return(h_return_status);
986           end if;
987 
988           l_total_trans_units := l_total_trans_units+asgn_table(i).trans_units;
989 
990       END LOOP;
991 
992       if (l_total_trans_units <> 0) then
993 
994 --- int_debug.print('l_total_trans_units <> 0');
995 
996           h_return_status := FND_API.G_RET_STS_ERROR;
997           return(h_return_status);
998       end if;
999 
1000 --- int_debug.print('Entered get_header_info ');
1001 
1002       --- Get rest of information
1003       get_header_info(
1004             X_Asset_Id                   => asset_id,
1005             X_Book_Type_Code             => book_type_code,
1006             X_Transaction_Header_Id      => l_Transaction_Header_Id,
1007             X_Transaction_Date_Entered   => l_Transaction_Date_Entered,
1008             X_Max_Transaction_Date       => l_Max_Transaction_Date,
1009             X_Current_PC                 => l_Current_PC,
1010             X_Calendar_Period_Open_Date  => l_Calendar_Period_Open_Date,
1011             X_Calendar_Period_Close_Date => l_Calendar_Period_Close_Date,
1012             X_FY_Start_Date              => l_FY_Start_Date,
1013             X_FY_End_Date                => l_FY_End_Date,
1014             X_return_status              => l_return_status
1015       );
1016 
1017       if (l_return_status <> FND_API.G_RET_STS_SUCCESS) then
1018           h_return_status := FND_API.G_RET_STS_ERROR;
1019           return(h_return_status);
1020       end if;
1021 
1022       -- fix for 2219293
1023       -- set txn_type_code based on the period of asset addition
1024       l_book := book_type_code; -- need to copy to local var
1025       l_asset := asset_id;
1026 
1027       select count(1)
1028       into l_count
1029       from    fa_deprn_summary ds
1030       where   ds.book_type_code = l_book
1031       and     ds.asset_id     = l_asset
1032       and     ds.deprn_source_code = 'BOOKS'
1033       and     ds.period_counter = l_current_pc - 1;
1034 
1035       if l_count <> 0 then  -- period of addition
1036         l_txn_type_code := 'TRANSFER IN/VOID';
1037       else
1038         l_txn_type_code := 'TRANSFER';
1039       end if;
1040 
1041 --- int_debug.print('Calling Transfer_Asset');
1042 
1043       FA_TRANS_API_PUB.Do_Transfer(
1044          -- Standard Parameters --
1045          p_api_version           => p_api_version,   ----1.0,
1046          p_init_msg_list         => p_init_msg_list, ----FND_API.G_TRUE,
1047          p_commit                => p_commit,        ----FND_API.G_TRUE,
1048          p_validation_level      => p_validation_level,
1049                                                  ----FND_API.G_VALID_LEVEL_FULL,
1050          x_return_status         => h_return_status,
1051          x_msg_count             => h_msg_count,
1052          x_msg_data              => h_msg_data,
1053          p_calling_fn            =>
1054             'fa_modify_distributions_pkg.process_transfer',
1055          -- API Options --
1056          p_debug_flag            => p_debug_flag,    ----'NO',
1057          -- Out Parameters --
1058          x_transaction_header_id => l_Transaction_Header_Id,
1059          -- Transaction Info --
1060          p_transaction_date_entered
1061                                  => nvl(asgn_table(1).transaction_date_entered,
1062                                         l_Transaction_Date_Entered),
1063          p_transaction_name      => NULL,
1064          p_mass_reference_id     => NULL,
1065          p_calling_interface     => 'FA_MODIFY_DISTS',
1066          p_last_update_date      => asgn_table(1).last_update_date,
1067          p_last_updated_by       => asgn_table(1).last_updated_by,
1068          p_created_by            => asgn_table(1).last_updated_by,
1069          p_creation_date         => asgn_table(1).last_update_date,
1070          p_last_update_login     => asgn_table(1).last_update_login,
1071          p_attribute1            => asgn_table(1).attribute1,
1072          p_attribute2            => asgn_table(1).attribute2,
1073          p_attribute3            => asgn_table(1).attribute3,
1074          p_attribute4            => asgn_table(1).attribute4,
1075          p_attribute5            => asgn_table(1).attribute5,
1076          p_attribute6            => asgn_table(1).attribute6,
1077          p_attribute7            => asgn_table(1).attribute7,
1078          p_attribute8            => asgn_table(1).attribute8,
1079          p_attribute9            => asgn_table(1).attribute9,
1080          p_attribute10           => asgn_table(1).attribute10,
1081          p_attribute11           => asgn_table(1).attribute11,
1082          p_attribute12           => asgn_table(1).attribute12,
1083          p_attribute13           => asgn_table(1).attribute13,
1084          p_attribute14           => asgn_table(1).attribute14,
1085          p_attribute15           => asgn_table(1).attribute15,
1086          p_attribute_category_code
1087                                  => asgn_table(1).attribute_category_code,
1088          -- Asset Header Info --
1089          p_asset_id              => asset_id,
1090          p_book_type_code        => book_type_code
1091       );
1092 
1093       x_return_status := h_return_status;
1094       x_msg_count     := h_msg_count;
1095       x_msg_data      := h_msg_data;
1096 
1097       if (h_return_status <> FND_API.G_RET_STS_SUCCESS) then
1098           h_return_status := FND_API.G_RET_STS_ERROR;
1099       end if;
1100 
1101       return(h_return_status);
1102 
1103   EXCEPTION
1104       when others then
1105           h_return_status := FND_API.G_RET_STS_ERROR;
1106           x_return_status := h_return_status;
1107           x_msg_count     := h_msg_count;
1108           x_msg_data      := h_msg_data;
1109 
1110           return(h_return_status);
1111   END;
1112 
1113  PROCEDURE get_header_info(
1114             X_Asset_Id                   IN NUMBER,
1115             X_Book_Type_Code             IN VARCHAR2,
1116             X_Transaction_Header_Id      OUT NOCOPY NUMBER,
1117             X_Transaction_Date_Entered   OUT NOCOPY DATE,
1118             X_Max_Transaction_Date       OUT NOCOPY DATE,
1119             X_Current_PC                 OUT NOCOPY NUMBER,
1120             X_Calendar_Period_Open_Date  OUT NOCOPY DATE,
1121             X_Calendar_Period_Close_Date OUT NOCOPY DATE,
1122             X_FY_Start_Date              OUT NOCOPY DATE,
1123             X_FY_End_Date                OUT NOCOPY DATE,
1124             X_return_status              OUT NOCOPY VARCHAR2
1125   ) IS
1126 
1127   Lv_Fiscal_Year      Number(4);
1128   Lv_Fiscal_Year_Name Varchar2(30);
1129 
1130   BEGIN
1131 
1132       -------------------------------------------------
1133       select fa_transaction_headers_s.nextval
1134       into   X_Transaction_Header_Id
1135       from   sys.dual;
1136       -------------------------------------------------
1137       select greatest(calendar_period_open_date,
1138              least(sysdate, calendar_period_close_date)),
1139              calendar_period_open_date,
1140              calendar_period_close_date,
1141              period_counter
1142       into   X_Transaction_Date_Entered,
1143              X_Calendar_Period_Open_Date,
1144              X_Calendar_Period_Close_Date,
1145              X_Current_PC
1146       from   fa_deprn_periods
1147       where  book_type_code = X_Book_Type_Code
1148       and    period_close_date is null;
1149       -------------------------------------------------
1150       select fiscal_year_name, current_fiscal_year
1151       into   lv_fiscal_year_name, lv_fiscal_year
1152       from   fa_book_controls
1153       where  book_type_code = X_Book_Type_Code;
1154       -------------------------------------------------
1155       select start_date, end_date
1156       into   X_FY_Start_Date, X_FY_End_Date
1157       from   fa_fiscal_year
1158       where  fiscal_year = lv_fiscal_year
1159       and    fiscal_year_name = lv_fiscal_year_name;
1160       -------------------------------------------------
1161       select max(transaction_date_entered)
1162       into   X_Max_Transaction_Date
1163       from   fa_transaction_headers
1164       where  asset_id = X_Asset_Id
1165       and    book_type_code = X_Book_Type_Code;
1166       -------------------------------------------------
1167 
1168       X_return_status := FND_API.G_RET_STS_SUCCESS;
1169 
1170   EXCEPTION
1171     when others then
1172           X_return_status := FND_API.G_RET_STS_ERROR;
1173 
1174   END get_header_info;
1175 
1176   FUNCTION check_if_corp_book(
1177         book_type_code IN VARCHAR2
1178   ) RETURN VARCHAR2
1179   IS
1180 
1181     X_corp_book_type_code VARCHAR2(15) := NULL;
1182 
1183     CURSOR Chk_Book_Class_C IS
1184         SELECT count(*)
1185         FROM   fa_book_controls BC
1186         WHERE  BC.book_type_code = X_corp_book_type_code
1187         AND    BC.book_class = 'CORPORATE'
1188         AND    rownum <= 1;
1189 
1190     l_book_class     NUMBER       := 0;
1191     l_return_status  VARCHAR2(15) := FND_API.G_RET_STS_ERROR;
1192     l_cbc_c_open     BOOLEAN      := FALSE;
1193 
1194   BEGIN
1195 
1196       if book_type_code is NOT NULL then
1197 
1198            l_book_class := 0;
1199            X_corp_book_type_code := book_type_code;
1200 
1201            OPEN  Chk_Book_Class_C;
1202 
1203            FETCH Chk_Book_Class_C
1204            INTO  l_book_class;
1205 
1206            if (Chk_Book_Class_C%NOTFOUND) then
1207 
1208              CLOSE Chk_Book_Class_C;
1209 
1210              l_return_status := FND_API.G_RET_STS_ERROR;
1211              return(l_return_status);
1212 
1213            end if;
1214 
1215            CLOSE Chk_Book_Class_C;
1216 
1217 
1218            if (l_book_class = 1) then
1219                l_return_status := FND_API.G_RET_STS_SUCCESS;
1220                return(l_return_status);
1221            else
1222                l_return_status := FND_API.G_RET_STS_ERROR;
1223                return(l_return_status);
1224            end if;
1225 
1226       else
1227            l_return_status := FND_API.G_RET_STS_ERROR;
1228            return(l_return_status);
1229       end if;
1230 
1231   EXCEPTION
1232 
1233       when others then
1234 
1235           if (l_cbc_c_open = TRUE) then
1236               CLOSE Chk_Book_Class_C;
1237               l_cbc_c_open := FALSE;
1238           end if;
1239 
1240           l_return_status := FND_API.G_RET_STS_ERROR;
1241           return(l_return_status);
1242 
1243 
1244   END check_if_corp_book;
1245 
1246   FUNCTION check_location_ccid(
1247         p_location_id IN NUMBER,
1248         p_ccid_id IN NUMBER
1249   ) RETURN VARCHAR2
1250   IS
1251 
1252     X_location_id NUMBER := NULL;
1253     X_ccid_id     NUMBER := NULL;
1254 
1255     CURSOR Chk_Location_C IS
1256         SELECT count(*)
1257         FROM   fa_locations loc
1258         WHERE  loc.location_id = NVL(X_location_id, -1)
1259         AND    loc.enabled_flag = 'Y'
1260         AND    rownum <= 1;
1261 
1262     CURSOR validate_ccid IS
1263         SELECT  count(*)
1264         FROM    gl_code_combinations glcc
1265         WHERE   glcc.code_combination_id = NVL(X_ccid_id, -1)
1266         AND     glcc.enabled_flag = 'Y'
1267         AND     nvl(glcc.end_date_active, sysdate) >= sysdate
1268         AND     rownum <= 1;
1269 
1270     l_loc_out       NUMBER       := 0;
1271     l_ccid_out      NUMBER       := 0;
1272     l_return_status VARCHAR2(15) := FND_API.G_RET_STS_ERROR;
1273     l_cl_c_open     BOOLEAN      := FALSE;
1274     l_cc_c_open     BOOLEAN      := FALSE;
1275 
1276 
1277     CURSOR Chk_Ccid_C IS
1278         SELECT  count(*)
1279         FROM    gl_code_combinations glcc
1280         WHERE   glcc.code_combination_id = NVL(X_ccid_id, -1)
1281         AND     glcc.enabled_flag = 'Y'
1282         AND     nvl(glcc.end_date_active, sysdate) >= sysdate
1283         AND     rownum <= 1;
1284 
1285   BEGIN
1286 
1287        l_loc_out     := 0;
1288        X_location_id := p_location_id;
1289 
1290        OPEN  Chk_Location_C;
1291        FETCH Chk_Location_C INTO l_loc_out;
1292 
1293        if (Chk_Location_C%NOTFOUND) then
1294            l_return_status := FND_API.G_RET_STS_ERROR;
1295        end if;
1296 
1297        CLOSE Chk_Location_C;
1298        l_cl_c_open := TRUE;
1299 
1300        if (l_loc_out = 1) then
1301            l_return_status := FND_API.G_RET_STS_SUCCESS;
1302        else
1303            l_return_status := FND_API.G_RET_STS_ERROR;
1304            return(l_return_status);
1305        end if;
1306 
1307        l_ccid_out    := 0;
1308        X_ccid_id     := p_ccid_id;
1309 
1310        OPEN  Chk_Ccid_C;
1311        FETCH Chk_Ccid_C INTO l_ccid_out;
1312 
1313        if (Chk_Ccid_C%NOTFOUND) then
1314            l_return_status := FND_API.G_RET_STS_ERROR;
1315        end if;
1316 
1317        CLOSE Chk_Ccid_C;
1318        l_cc_c_open := TRUE;
1319 
1320        if (l_ccid_out = 1) then
1321            l_return_status := FND_API.G_RET_STS_SUCCESS;
1322            return(l_return_status);
1323        else
1324            l_return_status := FND_API.G_RET_STS_ERROR;
1325            return(l_return_status);
1326        end if;
1327 
1328   EXCEPTION
1329 
1330       when others then
1331 
1332           if (l_cl_c_open = TRUE) then
1333               CLOSE Chk_Location_C;
1334               l_cl_c_open := FALSE;
1335           end if;
1336 
1337           if (l_cc_c_open = TRUE) then
1338               CLOSE Chk_Ccid_C;
1339               l_cc_c_open := FALSE;
1340           end if;
1341 
1342           l_return_status := FND_API.G_RET_STS_ERROR;
1343           return(l_return_status);
1344 
1345 
1346   END check_location_ccid;
1347 
1348 
1349 END FA_MODIFY_DISTRIBUTIONS_PKG;