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