DBA Data[Home] [Help]

PACKAGE BODY: APPS.FA_DEPRN_ROLLBACK_PKG

Source


1 PACKAGE BODY FA_DEPRN_ROLLBACK_PKG AS
2 /* $Header: FAXDRB.pls 120.30 2005/10/05 15:22:41 bridgway ship $ */
3 
4 g_log_level_rec  fa_api_types.log_level_rec_type;
5 
6 PROCEDURE do_rollback(
7       errbuf                  OUT NOCOPY     VARCHAR2,
8       retcode                 OUT NOCOPY     NUMBER,
9       p_book_type_code   IN   VARCHAR2,
10       p_period_name      IN    VARCHAR2) IS
11 
12    l_trx_approval     BOOLEAN;
13    l_request_id       NUMBER;
14    l_period_counter   number;
15 
16    l_asset_hdr_rec    fa_api_types.asset_hdr_rec_type;
17 
18    l_msg_count        NUMBER := 0;
19    l_msg_data         VARCHAR2(2000) := NULL;
20    l_return_status    varchar2(1);
21 
22    cursor c_assets is
23    select asset_id
24      from fa_deprn_summary
25     where book_type_code = p_book_type_code
26       and period_counter = l_period_counter;
27 
28    faxdrb_err         EXCEPTION;
29 
30 
31 BEGIN
32 
33    if (not g_log_level_rec.initialized) then
34       if (NOT fa_util_pub.get_log_level_rec (
35                 x_log_level_rec =>  g_log_level_rec
36       )) then
37          raise faxdrb_err;
38       end if;
39    end if;
40 
41 
42    -- changing the call for the rollback segment to use
43    -- dynamic sql as using the variable name doesn't work
44    -- correctly.  It interprets it as a literal.
45 
46    -- Initialize server message stack
47    FA_SRVR_MSG.Init_Server_Message;
48    -- Initialize debug message stack
49    FA_DEBUG_PKG.Initialize;
50 
51 
52    /*====================================================================
53     Get transaction approval and lock the book.
54    ======================================================================*/
55 
56    l_request_id := fnd_global.conc_request_id;
57    IF NOT FA_BEGIN_MASS_TRX_PKG.faxbmt(
58              X_book          => p_book_type_code,
59              X_request_id    => l_request_id,
60              X_result        => l_trx_approval,
61              p_log_level_rec => g_log_level_rec) THEN
62       RAISE faxdrb_err;
63    END IF;
64 
65    IF NOT l_trx_approval THEN
66       -- Transaction was not approved.
67       fa_srvr_msg.add_message(
68          calling_fn => 'fa_deprn_rollback_pkg.do_rollback',
69          name       => 'FA_TRXAPP_LOCK_FAILED',
70          token1     => 'BOOK',
71          value1     => p_book_type_code,
72          p_log_level_rec => g_log_level_rec);
73       RAISE faxdrb_err ;
74    END IF;
75 
76    -- Commit the change made to fa_book_controls table to lock the book.
77    COMMIT WORK;
78 
79    l_asset_hdr_rec.book_type_code := p_book_type_code;
80 
81    if not fa_cache_pkg.fazcbc (p_book_type_code,
82                                p_log_level_rec => g_log_level_rec) then
83       raise faxdrb_err;
84    end if;
85 
86    l_period_counter := fa_cache_pkg.fazcbc_record.last_period_counter + 1;
87 
88    for c_rec in c_assets loop
89 
90       l_asset_hdr_rec.asset_id := c_rec.asset_id;
91 
92 
93       -- loop through the assets in the book calling api for each
94       FA_DEPRN_ROLLBACK_PUB.do_rollback
95          (p_api_version             => 1.0,
96           p_init_msg_list           => FND_API.G_FALSE,
97           p_commit                  => FND_API.G_FALSE,
98           p_validation_level        => FND_API.G_VALID_LEVEL_FULL,
99           x_return_status           => l_return_status,
100           x_msg_count               => l_msg_count,
101           x_msg_data                => l_msg_data,
102           p_calling_fn              => null,
103           px_asset_hdr_rec          => l_asset_hdr_rec);
104 
105       if (l_return_status <> FND_API.G_RET_STS_SUCCESS) then
106          raise faxdrb_err ;
107       end if;
108 
109    end loop;
110 
111 
112    -- reset deprn_run to indicate that depreciation has been
113    -- rolled back
114 
115    if (g_log_level_rec.statement_level) then
116       fa_debug_pkg.add('Updating FA_DEPRN_PERIODS',
117                        'DEPRN_RUN',
118                        'NULL',
119                        p_log_level_rec => g_log_level_rec);
120    end if;
121 
122    update fa_deprn_periods_mrc_v
123       set deprn_run          = null
124     where book_type_code     = p_book_type_code
125       and period_counter     = l_period_counter
126       and period_close_date is null
127       and deprn_run          = 'Y';
128 
129    update fa_deprn_periods
130       set deprn_run          = null
131     where book_type_code     = p_book_type_code
132       and period_counter     = l_period_counter
133       and period_close_date is null
134       and deprn_run          = 'Y';
135 
136 
137    /*=================================================================
138      End mass transaction and unlock the book.
139      ===================================================================*/
140    IF NOT FA_BEGIN_MASS_TRX_PKG.faxemt(
141              X_book          => p_book_type_code,
142              X_request_id    => l_request_id,
143              p_log_level_rec => g_log_level_rec) THEN
144       FA_SRVR_MSG.Add_Message(
145          CALLING_FN => 'fa_deprn_rollback_pkg.do_rollback',
146           p_log_level_rec => g_log_level_rec);
147    END IF;
148 
149    -- Commit all deletes and updates done to rollback deprn
150    COMMIT;
151 
152    -- Dump Debug messages when run in debug mode to log file
153 
154    if (g_log_level_rec.statement_level) then
155       fa_debug_pkg.Write_Debug_Log;
156    end if;
157 
158    fa_srvr_msg.add_message(
159       calling_fn => 'fa_deprn_rollback_pkg.do_rollback',
160       name       => 'FA_SHARED_END_SUCCESS',
161       token1     => 'PROGRAM',
162       value1     => 'FADRB',
163       p_log_level_rec => g_log_level_rec);
164 
165    FND_MSG_PUB.Count_And_Get(
166       p_count         => l_msg_count,
167       p_data          => l_msg_data);
168 
169    fa_srvr_msg.Write_Msg_Log(l_msg_count, l_msg_data);
170 
171    -- return success to concurrent manager
172    retcode := 0;
173 
174 EXCEPTION
175    WHEN faxdrb_err THEN
176       ROLLBACK WORK;
177 
178       IF l_trx_approval THEN
179          IF NOT FA_BEGIN_MASS_TRX_PKG.faxemt(
180                    X_book          => p_book_type_code,
181                    X_request_id    => l_request_id,
182                    p_log_level_rec => g_log_level_rec) THEN
183             FA_SRVR_MSG.Add_Message(
184                CALLING_FN => 'fa_deprn_rollback_pkg.do_rollback',
185                p_log_level_rec => g_log_level_rec);
186          END IF;
187       END IF;
188 
189       if (g_log_level_rec.statement_level) then
190          fa_debug_pkg.Write_Debug_Log;
191       end if;
192 
193       FND_MSG_PUB.Count_And_Get(
194          p_count         => l_msg_count,
195          p_data          => l_msg_data);
196 
197       fa_srvr_msg.Write_Msg_Log(l_msg_count, l_msg_data);
198 
199       -- return failure to concurrent manager
200       retcode := 2;
201 
202    WHEN OTHERS THEN
203       ROLLBACK WORK;
204 
205       IF l_trx_approval THEN
206          IF NOT FA_BEGIN_MASS_TRX_PKG.faxemt(
207                    X_book          => p_book_type_code,
208                    X_request_id    => l_request_id,
209                    p_log_level_rec => g_log_level_rec) THEN
210             FA_SRVR_MSG.Add_Message(
211                CALLING_FN => 'fa_deprn_rollback_pkg.do_rollback',
212                p_log_level_rec => g_log_level_rec);
213          END IF;
214       END IF;
215 
216       fa_srvr_msg.add_sql_error (calling_fn => 'fa_deprn_rollback_pkg.do_rollback'
217             ,p_log_level_rec => g_log_level_rec);
218       fa_srvr_msg.add_message(
219          calling_fn => 'fa_deprn_rollback_pkg.do_rollback',
220          name       => 'FA_SHARED_END_WITH_ERROR',
221          token1     => 'PROGRAM',
222          value1     => 'FADRB',
223          p_log_level_rec => g_log_level_rec);
224 
225       if (g_log_level_rec.statement_level) then
226          fa_debug_pkg.Write_Debug_Log;
227       end if;
228 
229       FND_MSG_PUB.Count_And_Get(
230          p_count         => l_msg_count,
231          p_data          => l_msg_data);
232 
233       fa_srvr_msg.Write_Msg_Log(l_msg_count, l_msg_data);
234 
235       -- return failure to concurrent manager
236       retcode := 2;
237 
238 END do_rollback;
239 
240 END FA_DEPRN_ROLLBACK_PKG;