DBA Data[Home] [Help]

PACKAGE BODY: APPS.CSE_IFA_TRANS_PKG

Source


1 PACKAGE BODY CSE_IFA_TRANS_PKG AS
2 -- $Header: CSEIFATB.pls 120.0 2005/05/24 17:40:48 appldev noship $
3 
4 l_debug VARCHAR2(1) := NVL(FND_PROFILE.VALUE('CSE_DEBUG_OPTION'),'N');
5 
6 --===========================================================================
7 -- | PROCEDURE                                                                 |
8 -- |                                                                           |
9 -- |      TRANSFER_FA_DISTRIBUTION                                             |
10 -- |                                                                           |
11 -- | DESCRIPTION                                                               |
12 -- |                                                                           |
13 -- |      This procedure transfers units from a distribution of an asset to    |
14 -- |      another within the same asset. If the destination distribution does  |
15 -- |      not exist, it will be created during the transfer.                   |
16 -- |                                                                           |
17 -- |      If the transfer is successful, P_RETURN_STATUS will be set to        |
18 -- |      FND_API.G_RET_STS_SUCCESS and P_ERROR_MSG will be NULL. Otherwise,   |
19 -- |      P_RETURN_STATUS will be set to FND_API.G_RET_STS_ERROR and           |
20 -- |      P_ERROR_MSG will contain the error description.                      |
21 -- |                                                                           |
22 -- |      The new from distribution id and new to distribution id will be      |
23 -- |      returned after the transfer is completed successfully.               |
24 -- |                                                                           |
25 -- +===========================================================================
26 
27 PROCEDURE transfer_fa_distribution
28     (p_asset_id              IN NUMBER,
29      p_book_type_code        IN VARCHAR2,
30      p_units                 IN NUMBER,
31      p_from_location_id      IN NUMBER,
32      p_from_expense_ccid     IN NUMBER,
33      p_from_employee_id      IN NUMBER ,
34      p_to_location_id        IN NUMBER,
35      p_to_expense_ccid       IN NUMBER,
36      p_to_employee_id        IN NUMBER ,
37      x_new_from_dist_id      OUT NOCOPY NUMBER,
38      x_new_to_dist_id        OUT NOCOPY NUMBER,
39      x_return_status         OUT NOCOPY VARCHAR2,
40      x_error_msg             OUT NOCOPY VARCHAR2
41     ) IS
42 l_from_units       NUMBER;
43 l_seq_num          NUMBER;
44 l_user_id          NUMBER := fnd_global.user_id;
45 l_login_id         NUMBER := fnd_global.login_id;
46 l_status           VARCHAR2(10) := FND_API.G_RET_STS_ERROR;
47 l_msg_count        NUMBER := 0;
48 l_msg_data         VARCHAR2(1024) := NULL;
49 l_new_from_dist_id NUMBER;
50 l_new_to_dist_id   NUMBER;
51 l_fnd_msg_count    NUMBER := 0;
52 l_temp_str         VARCHAR2(1024) := NULL;
53 MOD_DIST_FAIL      EXCEPTION;
54 l_api_name         VARCHAR2(100) := 'CSE_IFA_TRANS_PKG.transfer_fa_distribution';
55 l_msg_index        NUMBER ;
56 BEGIN
57 
58   cse_util_pkg.write_log('Performing FA distribution transfer.');
59 
60   l_from_units := -p_units;
61 
62   -- Select sequence number
63   select fa_mass_external_transfers_s.nextval
64   into l_seq_num
65   from dual;
66 
67   -- Insert the FROM record into the FA_MASS_EXTERNAL_TRANSFERS interface table
68 
69   cse_util_pkg.write_log('Inserting record with MASS_EXTERNAL_TRANSFER_ID ' ||
70                     l_seq_num);
71 
72   INSERT INTO fa_mass_external_transfers(batch_name,
73                                          mass_external_transfer_id,
74                                          transaction_reference_num,
75                                          transaction_type,
76                                          from_asset_id,
77                                          book_type_code,
78                                          transaction_status,
79                                          from_location_id,
80                                          from_gl_ccid,
81                                          from_employee_id,
82                                          transfer_units,
83                                          created_by,
84                                          creation_date,
85                                          last_updated_by,
86                                          last_update_login,
87                                          last_updated_date,
88                                          last_update_date)
89   VALUES('FA_MODIFY_DISTS',
90          l_seq_num,
91          1,
92          'TRANSFER',
93          p_asset_id,
94          p_book_type_code,
95          'POST',
96          p_from_location_id,
97          p_from_expense_ccid,
98          p_from_employee_id,
99          l_from_units,
100          l_user_id,
101          sysdate,
102          l_user_id,
103          l_login_id,
104          sysdate,
105          sysdate);
106 
107   -- Select sequence number
108   select fa_mass_external_transfers_s.nextval
109   into l_seq_num
110   from dual;
111 
112   -- Insert the TO record into the FA_MASS_EXTERNAL_TRANSFERS interface table
113 
114   cse_util_pkg.write_log('Inserting record with MASS_EXTERNAL_TRANSFER_ID ' ||
115                     l_seq_num);
116 
117   INSERT INTO fa_mass_external_transfers(batch_name,
118                                          mass_external_transfer_id,
119                                          transaction_reference_num,
120                                          transaction_type,
121                                          from_asset_id,
122                                          book_type_code,
123                                          transaction_status,
124                                          to_location_id,
125                                          to_gl_ccid,
126                                          to_employee_id,
127                                          transfer_units,
128                                          created_by,
129                                          creation_date,
130                                          last_updated_by,
131                                          last_update_login,
132                                          last_updated_date,
133                                          last_update_date)
134   VALUES('FA_MODIFY_DISTS',
135          l_seq_num,
136          1,
137          'TRANSFER',
138          p_asset_id,
139          p_book_type_code,
140          'POST',
141          p_to_location_id,
142          p_to_expense_ccid,
143          p_to_employee_id,
144          p_units,
145          l_user_id,
146          sysdate,
147          l_user_id,
148          l_login_id,
149          sysdate,
150          sysdate);
151 
152   -- Process the records
153 
154   fa_modify_distributions_pkg.modify_distributions(
155                        p_api_version => 1.0,
156                        p_init_msg_list => FND_API.G_TRUE,
157                        p_commit => FND_API.G_FALSE,
158                        p_validation_level => FND_API.G_VALID_LEVEL_NONE,
159                        p_debug_flag => 'NO',
160                        x_return_status => l_status,
161                        x_msg_count => l_msg_count,
162                        x_msg_data => l_msg_data);
163 
164   cse_util_pkg.write_log('Status from MODIFY_DISTRIBUTIONS: ' || l_status);
165  if (l_status <> FND_API.G_RET_STS_SUCCESS)
166  then
167      if (l_msg_count > 0)
168      then
169        l_msg_index := 1;
170        x_error_msg :=l_msg_data;
171        WHILE l_msg_count > 0
172        LOOP
173 	  x_error_msg :=FND_MSG_PUB.GET(l_msg_index,
174           FND_API.G_FALSE)||x_error_msg ;
175 	      l_msg_index := l_msg_index + 1;
176           l_Msg_Count := l_Msg_Count - 1;
177        END LOOP;
178      end if ;
179 
180      x_return_status := FND_API.G_RET_STS_ERROR;
181      x_new_from_dist_id := NULL;
182      x_new_to_dist_id := NULL;
183       cse_util_pkg.write_log('Error : '||x_error_msg);
184      raise MOD_DIST_FAIL;
185   else
186      -- Find out the new from distribution id
187      cse_util_pkg.write_log(' Find OUT NOCOPY the new from distribution id...');
188 
189     begin
190      SELECT distribution_id
191      INTO l_new_from_dist_id
192      FROM fa_distribution_history
193      WHERE asset_id = p_asset_id AND
194            book_type_code = p_book_type_code AND
195            location_id = p_from_location_id AND
196            code_combination_id = p_from_expense_ccid AND
197            nvl(assigned_to, -1) = nvl(p_from_employee_id, -1) AND
198            date_ineffective is null;
199     exception
200      when NO_DATA_FOUND then
201         l_new_from_dist_id := NULL;
202     end;
203 
204      cse_util_pkg.write_log(' new from distribution id: ' || l_new_from_dist_id);
205 
206      -- Find out the new to distribution id
207 
208      cse_util_pkg.write_log(' Find OUT NOCOPY the new to distribution id...');
209 
210      SELECT distribution_id
211      INTO l_new_to_dist_id
212      FROM fa_distribution_history
213      WHERE asset_id = p_asset_id AND
214            book_type_code = p_book_type_code AND
215            location_id = p_to_location_id AND
216            code_combination_id = p_to_expense_ccid AND
217            nvl(assigned_to, -1) = nvl(p_to_employee_id, -1) AND
218            date_ineffective is null;
219 
220      x_return_status := FND_API.G_RET_STS_SUCCESS;
221      x_error_msg := NULL;
222      x_new_from_dist_id := l_new_from_dist_id;
223      x_new_to_dist_id := l_new_to_dist_id;
224 
225      cse_util_pkg.write_log(' new to distribution id: ' || l_new_to_dist_id);
226 
227   end if;
228 
229 EXCEPTION
230 
231   WHEN MOD_DIST_FAIL THEN
232      x_return_status := FND_API.G_RET_STS_ERROR;
233      fnd_message.set_name('CSE','CSE_UNEXP_SQL_ERROR');
234      fnd_message.set_token('API_NAME',l_api_name);
235      x_new_from_dist_id := NULL;
236      x_new_to_dist_id := NULL;
237 
238   WHEN OTHERS THEN
239      x_return_status := FND_API.G_RET_STS_ERROR;
240      x_error_msg := sqlerrm;
241      x_new_from_dist_id := NULL;
242      x_new_to_dist_id := NULL;
243 
244 END transfer_fa_distribution;
245 
246 
247 -- ===========================================================================+
248 -- | PROCEDURE                                                                 |
249 -- |                                                                           |
250 -- |      ADJUST_FA_DISTRIBUTION                                               |
251 -- |                                                                           |
252 -- | DESCRIPTION                                                               |
253 -- |                                                                           |
254 -- |      This procedure adjusts the units of an existing distribution in an   |
255 -- |      asset and adjusts the total units of the asset accordingly.          |
256 -- |                                                                           |
257 -- |      For unit increase, P_UNITS must be positive. For unit decrease,      |
258 -- |      P_UNITS must be negative.                                            |
259 -- |                                                                           |
260 -- |      If the adjustment is successful, P_RETURN_STATUS will be set to      |
261 -- |      FND_API.G_RET_STS_SUCCESS and P_ERROR_MSG will be NULL. Otherwise,   |
262 -- |      P_RETURN_STATUS will be set to FND_API.G_RET_STS_ERROR and           |
263 -- |      P_ERROR_MSG will contain the error description.                      |
264 -- |                                                                           |
265 -- |      The new distribution id of the adjusted distribution will be         |
266 -- |      returned after the adjustment is completed successfully.             |
267 -- |                                                                           |
268 -- +===========================================================================
269 
270 PROCEDURE adjust_fa_distribution
271     (p_asset_id              IN NUMBER,
272      p_book_type_code        IN VARCHAR2,
273      p_units                 IN NUMBER,
274      p_location_id           IN NUMBER,
275      p_expense_ccid          IN NUMBER,
276      p_employee_id           IN NUMBER ,
277      x_new_dist_id           OUT NOCOPY NUMBER,
278      x_return_status         OUT NOCOPY VARCHAR2,
279      x_error_msg             OUT NOCOPY VARCHAR2
280     ) IS
281 l_from_units       NUMBER;
282 l_seq_num          NUMBER;
283 l_user_id          NUMBER := fnd_global.user_id;
284 l_login_id         NUMBER := fnd_global.login_id;
285 l_status           VARCHAR2(10) := FND_API.G_RET_STS_ERROR;
286 l_msg_count        NUMBER := 0;
287 l_msg_data         VARCHAR2(1024) := NULL;
288 l_temp_dist_id     NUMBER;
289 l_new_dist_id      NUMBER;
290 l_new_from_dist_id NUMBER;
291 l_new_to_dist_id   NUMBER;
292 l_fnd_msg_count    NUMBER := 0;
293 l_temp_str         VARCHAR2(1024) := NULL;
294 l_location_id      NUMBER;
295 l_expense_ccid     NUMBER;
296 l_employee_id      NUMBER;
297 l_update_status    VARCHAR2(10);
298 l_update_err_msg   VARCHAR2(1024);
299 NO_DIST_EXISTS     EXCEPTION;
300 UPDATE_FAIL        EXCEPTION;
301 MOD_DIST_FAIL      EXCEPTION;
302 l_api_name         VARCHAR2(100) := 'CSE_IFA_TRANS_PKG.adjust_fa_distribution' ;
303 l_msg_index        NUMBER ;
304 CURSOR c_dist1 IS
305      SELECT distribution_id
306      FROM fa_distribution_history
307      WHERE asset_id = p_asset_id AND
308            book_type_code = p_book_type_code AND
309            location_id = p_location_id AND
310            code_combination_id = p_expense_ccid AND
311            nvl(assigned_to, -1) = nvl(p_employee_id, -1) AND
312            date_ineffective is null;
313 CURSOR c_dist2 IS
314      SELECT distribution_id
315      FROM fa_distribution_history
316      WHERE asset_id = p_asset_id AND
317            book_type_code = p_book_type_code AND
318            date_ineffective is null;
319 BEGIN
320 
321   cse_util_pkg.write_log('Performing FA distribution unit adjustment.');
322 
323   -- Determine if the distribution exists or not
324 
325   open c_dist1;
326   fetch c_dist1 into l_temp_dist_id;
327 
328   if (c_dist1%NOTFOUND) then -- Distribution does not exist
329     close c_dist1;
330     if (p_units < 0) then
331       cse_util_pkg.write_log('FA distribution does not exist for negative unit adjustment.');
332       raise NO_DIST_EXISTS;
333     end if;
334 
335     -- Pick an existing distribution to do an adjustment first and then a transfer
336     open c_dist2;
337     fetch c_dist2 into l_temp_dist_id;
338     if (c_dist2%NOTFOUND) then -- No valid distribution for the asset
339 
340       close c_dist2;
341       cse_util_pkg.write_log('No FA distribution exists for the asset to do unit adjustment.');
342       raise NO_DIST_EXISTS;
343 
344     else
345 
346       close c_dist2;
347 
348       cse_util_pkg.write_log('Need to create a new distribution during unit adjustment.');
349       cse_util_pkg.write_log('A unit adjustment will first be done followed by a transfer.');
350 
351       -- First perform a unit adjustment
352 
353       select location_id,
354              code_combination_id,
355              assigned_to
356       into l_location_id,
357            l_expense_ccid,
358            l_employee_id
359       from fa_distribution_history
360       where distribution_id = l_temp_dist_id;
361 
362       select fa_mass_external_transfers_s.nextval
363       into l_seq_num
364       from dual;
365 
366       cse_util_pkg.write_log('Inserting record with MASS_EXTERNAL_TRANSFER_ID ' ||
367                         l_seq_num);
368 
369       INSERT INTO fa_mass_external_transfers(batch_name,
370                                              mass_external_transfer_id,
374                                              book_type_code,
371                                              transaction_reference_num,
372                                              transaction_type,
373                                              from_asset_id,
375                                              transaction_status,
376                                              to_location_id,
377                                              to_gl_ccid,
378                                              to_employee_id,
379                                              transfer_units,
380                                              created_by,
381                                              creation_date,
382                                              last_updated_by,
383                                              last_update_login,
384                                              last_updated_date,
385                                              last_update_date)
386       VALUES('FA_MODIFY_DISTS',
387              l_seq_num,
388              1,
389              'UNIT ADJUSTMENT',
390              p_asset_id,
391              p_book_type_code,
392              'POST',
393              l_location_id,
394              l_expense_ccid,
395              l_employee_id,
396              p_units,
397              l_user_id,
398              sysdate,
399              l_user_id,
400              l_login_id,
401              sysdate,
402              sysdate);
403 
404       -- Then perform a transfer
405 
406       l_from_units := -p_units;
407 
408       -- Select sequence number
409       select fa_mass_external_transfers_s.nextval
410       into l_seq_num
411       from dual;
412 
413       -- Insert the FROM record into the FA_MASS_EXTERNAL_TRANSFERS interface table
414 
415       cse_util_pkg.write_log('Inserting record with MASS_EXTERNAL_TRANSFER_ID ' ||
416                         l_seq_num);
417 
418       INSERT INTO fa_mass_external_transfers(batch_name,
419                                              mass_external_transfer_id,
420                                              transaction_reference_num,
421                                              transaction_type,
422                                              from_asset_id,
423                                              book_type_code,
424                                              transaction_status,
425                                              from_location_id,
426                                              from_gl_ccid,
427                                              from_employee_id,
428                                              transfer_units,
429                                              created_by,
430                                              creation_date,
431                                              last_updated_by,
432                                              last_update_login,
433                                              last_updated_date,
434                                              last_update_date)
435       VALUES('FA_MODIFY_DISTS',
436              l_seq_num,
437              2,
438              'TRANSFER',
439              p_asset_id,
440              p_book_type_code,
441              'POST',
442              l_location_id,
443              l_expense_ccid,
444              l_employee_id,
445              l_from_units,
446              l_user_id,
447              sysdate,
448              l_user_id,
449              l_login_id,
450              sysdate,
451              sysdate);
452 
453       -- Select sequence number
454       select fa_mass_external_transfers_s.nextval
455       into l_seq_num
456       from dual;
457 
458       -- Insert the TO record into the FA_MASS_EXTERNAL_TRANSFERS interface table
459 
460       cse_util_pkg.write_log('Inserting record with MASS_EXTERNAL_TRANSFER_ID ' ||
461                         l_seq_num);
462 
463       INSERT INTO fa_mass_external_transfers(batch_name,
464                                              mass_external_transfer_id,
465                                              transaction_reference_num,
466                                              transaction_type,
467                                              from_asset_id,
468                                              book_type_code,
469                                              transaction_status,
470                                              to_location_id,
471                                              to_gl_ccid,
472                                              to_employee_id,
473                                              transfer_units,
474                                              created_by,
475                                              creation_date,
476                                              last_updated_by,
477                                              last_update_login,
478                                              last_updated_date,
479                                              last_update_date)
480       VALUES('FA_MODIFY_DISTS',
481              l_seq_num,
482              2,
483              'TRANSFER',
484              p_asset_id,
485              p_book_type_code,
486              'POST',
487              p_location_id,
488              p_expense_ccid,
489              p_employee_id,
490              p_units,
491              l_user_id,
492              sysdate,
496              sysdate);
493              l_user_id,
494              l_login_id,
495              sysdate,
497 
498       -- Process the records
499 
500       fa_modify_distributions_pkg.modify_distributions(
501                        p_api_version => 1.0,
502                        p_init_msg_list => FND_API.G_TRUE,
503                        p_commit => FND_API.G_FALSE,
504                        p_validation_level => FND_API.G_VALID_LEVEL_NONE,
505                        p_debug_flag => 'NO',
506                        x_return_status => l_status,
507                        x_msg_count => l_msg_count,
508                        x_msg_data => l_msg_data);
509 
510       cse_util_pkg.write_log('Status from MODIFY_DISTRIBUTIONS: ' || l_status);
511 
512       if (l_status <> FND_API.G_RET_STS_SUCCESS)
513       then
514          if (l_msg_count > 0)
515          then
516            l_msg_index := 1;
517            x_error_msg :=l_msg_data;
518            WHILE l_msg_count > 0
519            LOOP
520 	      x_error_msg :=FND_MSG_PUB.GET(l_msg_index,
521               FND_API.G_FALSE)||x_error_msg ;
522 	      l_msg_index := l_msg_index + 1;
523               l_Msg_Count := l_Msg_Count - 1;
524            END LOOP;
525          end if ;
526 
527      x_return_status := FND_API.G_RET_STS_ERROR;
528      x_new_dist_id := NULL;
529       cse_util_pkg.write_log('Error : '||x_error_msg);
530      raise MOD_DIST_FAIL;
531 
532     else
533          -- Find out the new id for the temp distribution
534 
535          SELECT distribution_id
536          INTO l_new_dist_id
537          FROM fa_distribution_history
538          WHERE asset_id = p_asset_id AND
539                book_type_code = p_book_type_code AND
540                location_id = l_location_id AND
541                code_combination_id = l_expense_ccid AND
542                nvl(assigned_to, -1) = nvl(l_employee_id, -1) AND
543                date_ineffective is null;
544 
545 
546          -- Find out the new distribution id
547 
548          SELECT distribution_id
549          INTO l_new_dist_id
550          FROM fa_distribution_history
551          WHERE asset_id = p_asset_id AND
552                book_type_code = p_book_type_code AND
553                location_id = p_location_id AND
554                code_combination_id = p_expense_ccid AND
555                nvl(assigned_to, -1) = nvl(p_employee_id, -1) AND
556                date_ineffective is null;
557 
558          x_return_status := FND_API.G_RET_STS_SUCCESS;
559          x_error_msg := NULL;
560          x_new_dist_id := l_new_dist_id;
561 
562       end if;
563 
564     end if; -- End picking a random distribution
565 
566   else -- Distribution exists
567     close c_dist1;
568 
569     -- Select sequence number
570 
571     select fa_mass_external_transfers_s.nextval
572     into l_seq_num
573     from dual;
574 
575     -- Insert the record into the FA_MASS_EXTERNAL_TRANSFERS interface table
576 
577     cse_util_pkg.write_log('Distribution exists. Inserting record with MASS_EXTERNAL_TRANSFER_ID ' || l_seq_num);
578 
579     if (p_units < 0) then -- Subtracting
580 
581       INSERT INTO fa_mass_external_transfers(batch_name,
582                                              mass_external_transfer_id,
583                                              transaction_reference_num,
584                                              transaction_type,
585                                              from_asset_id,
586                                              book_type_code,
587                                              transaction_status,
588                                              from_location_id,
589                                              from_gl_ccid,
590                                              from_employee_id,
591                                              transfer_units,
592                                              created_by,
593                                              creation_date,
594                                              last_updated_by,
595                                              last_update_login,
596                                              last_updated_date,
597                                              last_update_date)
598       VALUES('FA_MODIFY_DISTS',
599              l_seq_num,
600              1,
601              'UNIT ADJUSTMENT',
602              p_asset_id,
603              p_book_type_code,
604              'POST',
605              p_location_id,
606              p_expense_ccid,
607              p_employee_id,
608              p_units,
609              l_user_id,
610              sysdate,
611              l_user_id,
612              l_login_id,
613              sysdate,
614              sysdate);
615 
616     elsif (p_units > 0) then -- Adding
617 
618       INSERT INTO fa_mass_external_transfers(batch_name,
619                                              mass_external_transfer_id,
620                                              transaction_reference_num,
621                                              transaction_type,
622                                              from_asset_id,
623                                              book_type_code,
624                                              transaction_status,
625                                              to_location_id,
626                                              to_gl_ccid,
627                                              to_employee_id,
628                                              transfer_units,
629                                              created_by,
630                                              creation_date,
631                                              last_updated_by,
632                                              last_update_login,
633                                              last_updated_date,
634                                              last_update_date)
635       VALUES('FA_MODIFY_DISTS',
636              l_seq_num,
637              1,
638              'UNIT ADJUSTMENT',
639              p_asset_id,
640              p_book_type_code,
641              'POST',
642              p_location_id,
643              p_expense_ccid,
644              p_employee_id,
645              p_units,
646              l_user_id,
647              sysdate,
648              l_user_id,
649              l_login_id,
650              sysdate,
651              sysdate);
652 
653     end if;
654 
655     -- Process the records
656 
657     fa_modify_distributions_pkg.modify_distributions(
658                          p_api_version => 1.0,
659                          p_init_msg_list => FND_API.G_TRUE,
660                          p_commit => FND_API.G_FALSE,
661                          p_validation_level => FND_API.G_VALID_LEVEL_NONE,
662                          p_debug_flag => 'NO',
663                          x_return_status => l_status,
664                          x_msg_count => l_msg_count,
665                          x_msg_data => l_msg_data);
666 
667     cse_util_pkg.write_log('Status from MODIFY_DISTRIBUTIONS: ' || l_status);
668 
669     if (l_status <> FND_API.G_RET_STS_SUCCESS)
670     then
671          if (l_msg_count > 0)
672          then
673            l_msg_index := 1;
674            x_error_msg :=l_msg_data;
675            WHILE l_msg_count > 0
676            LOOP
677 	      x_error_msg :=FND_MSG_PUB.GET(l_msg_index,
678               FND_API.G_FALSE)||x_error_msg ;
679 	      l_msg_index := l_msg_index + 1;
680               l_Msg_Count := l_Msg_Count - 1;
681            END LOOP;
682          end if ;
683      x_return_status := FND_API.G_RET_STS_ERROR;
684      x_new_dist_id := NULL;
685      cse_util_pkg.write_log('Error : '||x_error_msg);
686      raise MOD_DIST_FAIL;
687 
688     else
689        -- Find out the new distribution id
690       begin
691        SELECT distribution_id
692        INTO l_new_dist_id
693        FROM fa_distribution_history
694        WHERE asset_id = p_asset_id AND
695              book_type_code = p_book_type_code AND
696              location_id = p_location_id AND
697              code_combination_id = p_expense_ccid AND
698              nvl(assigned_to, -1) = nvl(p_employee_id, -1) AND
699              date_ineffective is null;
700       exception
701        when NO_DATA_FOUND then
702           l_new_dist_id := NULL;
703       end;
704 
705        x_return_status := FND_API.G_RET_STS_SUCCESS;
706        x_error_msg := NULL;
707        x_new_dist_id := l_new_dist_id;
708 
709     end if;
710 
711   end if; -- Check if distribution exists
712 
713 EXCEPTION
714 
715   WHEN NO_DIST_EXISTS THEN
716      x_return_status := FND_API.G_RET_STS_ERROR;
717      fnd_message.set_name('CSE', 'CSE_NO_FA_DIST_FOR_ADJ');
718      x_error_msg := fnd_message.get;
719      x_new_dist_id := NULL;
720 
721   WHEN UPDATE_FAIL THEN
722      x_return_status := FND_API.G_RET_STS_ERROR;
723      x_error_msg := l_update_err_msg;
724      x_new_dist_id := NULL;
725 
726   WHEN MOD_DIST_FAIL THEN
727      x_return_status := FND_API.G_RET_STS_ERROR;
728      fnd_message.set_name('CSE','CSE_UNEXP_SQL_ERROR');
729      fnd_message.set_token('API_NAME',l_api_name);
730      x_error_msg := fnd_message.get;
731      x_new_dist_id := NULL;
732 
733   WHEN OTHERS THEN
734      x_return_status := FND_API.G_RET_STS_ERROR;
735      x_error_msg := sqlerrm;
736      x_new_dist_id := NULL;
737 
738 END adjust_fa_distribution;
739 
740 END CSE_IFA_TRANS_PKG;