1 PACKAGE BODY JG_JOURNAL_ALLOCATIONS_PKG AS
2 /* $Header: jgzztajb.pls 120.5 2006/06/06 12:38:35 vgadde ship $ */
3
4 /* ---------------------------------------------------------------------
5 | PRIVATE PROCEDURE |
6 | get_source_and_category |
7 | DESCRIPTION |
8 | Get the translated values for je_source and categories |
9 | CALLED BY |
10 | Main |
11 --------------------------------------------------------------------- */
12 PROCEDURE get_source_and_category IS
13 BEGIN
14 JG_UTILITY_PKG.log( '> JG_JOURNAL_ALLOCATIONS_PKG.get_source_and_category');
15 SELECT cat.user_je_category_name,
16 src.user_je_source_name,
17 usr.user_conversion_type
18 INTO JG_JOURNAL_ALLOCATIONS_PKG.G_user_je_category_name,
19 JG_JOURNAL_ALLOCATIONS_PKG.G_user_je_source_name,
20 JG_JOURNAL_ALLOCATIONS_PKG.G_translated_user
21 FROM GL_JE_SOURCES src,
22 GL_JE_CATEGORIES cat,
23 GL_DAILY_CONVERSION_TYPES usr
24 WHERE src.je_source_name = JG_JOURNAL_ALLOCATIONS_PKG.G_destn_journal_source AND
25 cat.je_category_name = JG_JOURNAL_ALLOCATIONS_PKG.G_destn_journal_category AND
26 usr.conversion_type = 'User';
27 JG_UTILITY_PKG.log( '< JG_JOURNAL_ALLOCATIONS_PKG.get_source_and_category');
28 END get_source_and_category;
29
30 /* ---------------------------------------------------------------------
31 | PRIVATE PROCEDURE |
32 | get_set_of_books_name |
33 | DESCRIPTION |
34 | Get the name of the set of books based on the id |
35 | CALLED BY |
36 | Main |
37 --------------------------------------------------------------------- */
38 PROCEDURE get_set_of_books_name IS
39 BEGIN
40 JG_UTILITY_PKG.log( '> JG_JOURNAL_ALLOCATIONS_PKG.get_set_of_books_name');
41 SELECT name
42 INTO JG_JOURNAL_ALLOCATIONS_PKG.G_set_of_books_name -- for report displaying purposes
43 FROM gl_sets_of_books
44 WHERE set_of_books_id = JG_JOURNAL_ALLOCATIONS_PKG.G_set_of_books_id;
45 JG_UTILITY_PKG.log( '< JG_JOURNAL_ALLOCATIONS_PKG.get_set_of_books_name');
46 END get_set_of_books_name;
47
48 /* ---------------------------------------------------------------------
49 | PRIVATE PROCEDURE |
50 | set_parameters |
51 | DESCRIPTION |
52 | Sets the concurrent programs parameter values to package |
53 | Global variables |
54 | CALLED BY |
55 | Main |
56 ----------------------------------------------------------------------- */
57 PROCEDURE set_parameters (p_set_of_books_id IN NUMBER,
58 p_chart_of_accounts_id IN NUMBER,
59 p_functional_currency IN VARCHAR2,
60 p_period_set_name IN VARCHAR2,
61 p_rule_set_id IN NUMBER,
62 p_period_name IN VARCHAR2,
63 p_currency_code IN VARCHAR2,
64 p_amount_type IN VARCHAR2,
65 p_balance_type IN VARCHAR2,
66 p_balance_type_id IN NUMBER,
67 p_balance_segment_value IN VARCHAR2,
68 p_destn_set_of_books_id IN NUMBER,
69 p_destn_period_name IN VARCHAR2,
70 p_destn_journal_source IN VARCHAR2,
71 p_destn_journal_category IN VARCHAR2,
72 p_destn_segment_method IN VARCHAR2,
73 p_destn_cost_center_grouping IN VARCHAR2,
74 p_error_handling IN VARCHAR2,
75 p_validate_only IN VARCHAR2,
76 p_run_journal_import IN VARCHAR2,
77 p_destn_summary_level IN VARCHAR2,
78 p_import_desc_flexfields IN VARCHAR2,
79 p_post_errors_to_suspense IN VARCHAR2,
80 p_debug_flag IN VARCHAR2) IS
81 l_ext_precision NUMBER;
82 l_min_acct_unit NUMBER;
83 BEGIN
84 JG_UTILITY_PKG.log( '> JG_JOURNAL_ALLOCATIONS_PKG.set_parameters');
85 JG_JOURNAL_ALLOCATIONS_PKG.G_set_of_books_id := p_set_of_books_id;
86 JG_JOURNAL_ALLOCATIONS_PKG.G_chart_of_accounts_id := p_chart_of_accounts_id;
87 JG_JOURNAL_ALLOCATIONS_PKG.G_functional_currency := p_functional_currency;
88 JG_JOURNAL_ALLOCATIONS_PKG.G_period_set_name := p_period_set_name;
89 JG_JOURNAL_ALLOCATIONS_PKG.G_rule_set_id := p_rule_set_id;
90 JG_JOURNAL_ALLOCATIONS_PKG.G_period_name := p_period_name;
91 JG_JOURNAL_ALLOCATIONS_PKG.G_currency_code := p_currency_code;
92 JG_JOURNAL_ALLOCATIONS_PKG.G_amount_type := p_amount_type;
93 JG_JOURNAL_ALLOCATIONS_PKG.G_balance_type := p_balance_type;
94 JG_JOURNAL_ALLOCATIONS_PKG.G_balance_type_id := p_balance_type_id;
95 JG_JOURNAL_ALLOCATIONS_PKG.G_balance_segment_value := p_balance_segment_value;
96 JG_JOURNAL_ALLOCATIONS_PKG.G_destn_set_of_books_id := p_destn_set_of_books_id;
97 JG_JOURNAL_ALLOCATIONS_PKG.G_destn_period_name := p_destn_period_name;
98 JG_JOURNAL_ALLOCATIONS_PKG.G_destn_journal_source := p_destn_journal_source;
99 JG_JOURNAL_ALLOCATIONS_PKG.G_destn_journal_category := p_destn_journal_category;
100 JG_JOURNAL_ALLOCATIONS_PKG.G_destn_segment_method := p_destn_segment_method;
101 JG_JOURNAL_ALLOCATIONS_PKG.G_destn_cost_center_grouping := p_destn_cost_center_grouping;
102 JG_JOURNAL_ALLOCATIONS_PKG.G_error_handling := p_error_handling;
103 JG_JOURNAL_ALLOCATIONS_PKG.G_validate_only := p_validate_only;
104 JG_JOURNAL_ALLOCATIONS_PKG.G_run_journal_import := p_run_journal_import;
105 JG_JOURNAL_ALLOCATIONS_PKG.G_destn_summary_level := p_destn_summary_level;
106 JG_JOURNAL_ALLOCATIONS_PKG.G_import_desc_flexfields := p_import_desc_flexfields;
107 JG_JOURNAL_ALLOCATIONS_PKG.G_post_errors_to_suspense := p_post_errors_to_suspense;
108 JG_JOURNAL_ALLOCATIONS_PKG.G_debug_flag := p_debug_flag;
109 --
110 -- Then initialize all the other variables
111 --
112 JG_JOURNAL_ALLOCATIONS_PKG.G_JG_appln_short_name := 'JG';
113 JG_JOURNAL_ALLOCATIONS_PKG.G_GL_appln_short_name := 'SQLGL';
114 JG_JOURNAL_ALLOCATIONS_PKG.G_GL_application_id := 101;
115 JG_JOURNAL_ALLOCATIONS_PKG.G_GL_acct_flex_code := 'GL#';
116 JG_JOURNAL_ALLOCATIONS_PKG.G_request_id := FND_GLOBAL.CONC_REQUEST_ID;
117 JG_JOURNAL_ALLOCATIONS_PKG.G_progr_appl_id := FND_GLOBAL.PROG_APPL_ID;
118 JG_JOURNAL_ALLOCATIONS_PKG.G_conc_progr_id := FND_GLOBAL.CONC_PROGRAM_ID;
119 JG_JOURNAL_ALLOCATIONS_PKG.G_user_id := FND_GLOBAL.USER_ID;
120 JG_JOURNAL_ALLOCATIONS_PKG.G_login_id := FND_GLOBAL.LOGIN_ID;
121 --
122 -- Get Functional Currency Format Mask
123 -- Bug 3482467 (2638803), changed G_func_currency_format_mask from 15 to 18
124 JG_JOURNAL_ALLOCATIONS_PKG.G_func_currency_format_mask :=
125 FND_CURRENCY.GET_FORMAT_MASK(JG_JOURNAL_ALLOCATIONS_PKG.G_functional_currency,18);
126 FND_CURRENCY.GET_INFO(JG_JOURNAL_ALLOCATIONS_PKG.G_functional_currency
127 ,JG_JOURNAL_ALLOCATIONS_PKG.G_func_currency_precision
128 ,l_ext_precision
129 ,l_min_acct_unit);
130
131 --
132 -- Set the unallocation request id to NULL
133 --
134 JG_JOURNAL_ALLOCATIONS_PKG.G_unalloc_request_id := NULL;
135
136 -- Initialize acct flex segments info array
137 JG_JOURNAL_ALLOCATIONS_PKG.G_acct_flex_segmt_arr.DELETE;
138
139 -- Initialize allocated lines array
140 JG_CREATE_JOURNALS_PKG.alloc_lines_arr.DELETE;
141 JG_CREATE_JOURNALS_PKG.i := 0; -- num of rows in array
142
143 -- Initialize zero fill array
144 JG_JOURNAL_ALLOCATIONS_PKG.G_zero_fill_arr.DELETE;
145
146 -- Set to program status to SUCCESS
147 JG_JOURNAL_ALLOCATIONS_PKG.G_retcode := 0;
148
149 JG_CREATE_JOURNALS_PKG.G_total_offset_accted_dr_amt := 0;
150 JG_CREATE_JOURNALS_PKG.G_total_offset_accted_cr_amt := 0;
151 JG_CREATE_JOURNALS_PKG.G_total_offset_entered_dr_amt := 0;
152 JG_CREATE_JOURNALS_PKG.G_total_offset_entered_cr_amt := 0;
153
154 JG_CREATE_JOURNALS_PKG.G_total_alloc_accted_cr_amt := 0;
155 JG_CREATE_JOURNALS_PKG.G_total_alloc_accted_dr_amt := 0;
156
157 JG_ALLOCATE_JOURNALS_PKG.G_last_journal_qry_rec.offset_account := NULL;
158 JG_ALLOCATE_JOURNALS_PKG.G_last_journal_qry_rec.cc_range_id := NULL;
159
160 JG_CREATE_JOURNALS_PKG.G_Journal_Name := NULL;
161 JG_CREATE_JOURNALS_PKG.G_Journal_Description := NULL;
162 JG_CREATE_JOURNALS_PKG.G_Batch_Name := NULL;
163
164 JG_UTILITY_PKG.log( '< JG_JOURNAL_ALLOCATIONS_PKG.set_parameters');
165 END set_parameters;
166
167 /* ---------------------------------------------------------------------
168 | PRIVATE FUNCTION |
169 | valid_rule_set |
170 | DESCRIPTION |
171 | This function performs a number of validation checks on the |
172 | selected rule set prior to looping through each source journal |
173 | line. Here is a list of the checks performed: |
174 | 1) Checks that account ranges within separate cost center ranges|
175 | do not overlap. This could lead to multiple allocations |
176 | of the same source journal line. |
177 | 2) Checks that at least one allocation rule line exists for |
178 | each account range |
179 | 3) If allocation lines exist, it checks they add up to 100% if |
180 | partial allocation has not been set for the rule |
181 | 4) If allocation lines exist, it checks they do not add up to |
182 | greater than 100% if partial allocation has been set for the |
183 | rule |
184 | 5) Checks that there is an offset account defined at the account|
185 | range level if the total number of offsets at the rule line |
186 | level does not equal the total number of rule lines. |
187 | 6) Informs whether or not there is at least one offset account |
188 | defined at the account range level |
189 | CALLED BY |
190 | JG_JOURNAL_ALLOCATIONS_PKG.main |
191 | RETURNS |
192 | TRUE if valid rule set, FALSE otherwise. Error |
193 | Message Code returned if FALSE. |
194 --------------------------------------------------------------------- */
195 FUNCTION valid_rule_set(p_err_msg_code IN OUT NOCOPY VARCHAR2
196 ,p_acct_rnge_offset IN OUT NOCOPY BOOLEAN) RETURN BOOLEAN IS
197 CURSOR c_rule_set IS
198 SELECT rs.partial_allocation partial_allocation
199 , ccr.cc_range_low cc_range_low
200 , ccr.cc_range_high cc_range_high
201 , acr.account_range_low account_range_low
202 , acr.account_range_high account_range_high
203 , acr.offset_account acc_range_offset_acct
204 , acr.account_range_id account_range_id
205 , SUM(rl.allocation_percent) total_percent
206 , COUNT(*) total_num_of_lines
207 , SUM(DECODE(rl.offset_account, NULL, 0, 1)) total_num_of_offsets
208 FROM jg_zz_ta_rule_lines rl
209 , jg_zz_ta_account_ranges acr
210 , jg_zz_ta_cc_ranges ccr
211 , jg_zz_ta_rule_sets rs
212 WHERE rs.rule_set_id = ccr.rule_set_id
213 AND ccr.cc_range_id = acr.cc_range_id
214 AND acr.account_range_id = rl.account_range_id (+)
215 AND rs.rule_set_id = JG_JOURNAL_ALLOCATIONS_PKG.G_rule_set_id
216 GROUP BY rs.partial_allocation
217 , ccr.cc_range_low
218 , ccr.cc_range_high
219 , acr.account_range_low
220 , acr.account_range_high
221 , acr.offset_account
222 , acr.account_range_id;
223 TYPE ACCOUNT_RANGE_LINE IS RECORD(cc_range_low jg_zz_ta_cc_ranges.cc_range_low%TYPE
224 ,cc_range_high jg_zz_ta_cc_ranges.cc_range_high%TYPE
225 ,account_range_low jg_zz_ta_account_ranges.account_range_low%TYPE
226 ,account_range_high jg_zz_ta_account_ranges.account_range_high%TYPE);
227 TYPE ACCOUNT_RANGE_TABLE IS TABLE OF ACCOUNT_RANGE_LINE INDEX BY BINARY_INTEGER;
228 l_acct_range_arr ACCOUNT_RANGE_TABLE;
229 arr_count BINARY_INTEGER; --:= 0; Default values not allowed in Init. -- running count of number of account ranges
230 BEGIN
231 JG_UTILITY_PKG.log( '> JG_JOURNAL_ALLOCATIONS_PKG.valid_rule_set');
232 p_acct_rnge_offset := FALSE;
233 FOR c_rs_rec IN c_rule_set LOOP
234 --
235 -- No sum means that no allocation lines exist 2)
236 --
237 IF c_rs_rec.total_percent IS NULL THEN
238 p_err_msg_code := 'JG_ZZ_MISSING_ALLOC_PERC_RULE';
239 RETURN FALSE;
240 --
241 -- check if missing any offset account numbers when there is no offset at the account range 5)
242 --
243 ELSIF c_rs_rec.total_num_of_lines <> c_rs_rec.total_num_of_offsets AND c_rs_rec.acc_range_offset_acct IS NULL THEN
244 p_err_msg_code := 'JG_ZZ_MISSING_OFFSET_ACCOUNT';
245 RETURN FALSE;
246 --
247 -- check if no partial allocation that total percent = 100% 3)
248 --
249 ELSIF c_rs_rec.total_percent <> 100 AND c_rs_rec.partial_allocation = 'N' THEN
250 p_err_msg_code := 'JG_ZZ_INVALID_ALLOC_PERC_TOTAL';
251 RETURN FALSE;
252 --
253 -- check if partial allocation that percent is not greater than 100% 4)
254 --
255 ELSIF c_rs_rec.total_percent > 100 AND c_rs_rec.partial_allocation = 'Y' THEN
256 p_err_msg_code := 'JG_ZZ_GRTR_THAN_100_ALLOC_PERC';
257 RETURN FALSE;
258 --
259 -- check if have an offset account at the account range level 6)
260 --
261 ELSIF c_rs_rec.acc_range_offset_acct IS NOT NULL THEN
262 p_acct_rnge_offset := TRUE;
263 END IF;
264 --
265 -- Check that account ranges within separate cost center ranges do not overlap 1)
266 --
267 arr_count := 0;
268 FOR i IN 1..arr_count LOOP
269 IF ((c_rs_rec.cc_range_low BETWEEN l_acct_range_arr(i).cc_range_low AND l_acct_range_arr(i).cc_range_high) OR
270 (c_rs_rec.cc_range_high BETWEEN l_acct_range_arr(i).cc_range_low AND l_acct_range_arr(i).cc_range_high)) AND
271 ((c_rs_rec.account_range_low BETWEEN l_acct_range_arr(i).account_range_low AND l_acct_range_arr(i).account_range_high) OR
272 (c_rs_rec.account_range_high BETWEEN l_acct_range_arr(i).account_range_low AND l_acct_range_arr(i).account_range_high)) THEN
273 p_err_msg_code := 'JG_ZZ_INVALID_OVRLAPPING_RNGES';
274 RETURN FALSE;
275 END IF;
276 END LOOP;
277 arr_count := arr_count + 1;
278 l_acct_range_arr(arr_count).cc_range_low := c_rs_rec.cc_range_low;
279 l_acct_range_arr(arr_count).cc_range_high := c_rs_rec.cc_range_high;
280 l_acct_range_arr(arr_count).account_range_low := c_rs_rec.account_range_low;
281 l_acct_range_arr(arr_count).account_range_high := c_rs_rec.account_range_high;
282 END LOOP;
283 p_err_msg_code := NULL;
284 JG_UTILITY_PKG.log( '< JG_JOURNAL_ALLOCATIONS_PKG.valid_rule_set');
285 RETURN TRUE;
286 -- Bug 1064357: The following line should be at before the return line
287 -- JG_UTILITY_PKG.log( '< JG_JOURNAL_ALLOCATIONS_PKG.valid_rule_set');
288 END valid_rule_set;
289
290 /* ---------------------------------------------------------------------
291 | PRIVATE PROCEDURE |
292 | Get_Segments_Info |
293 | DESCRIPTION |
294 | Gets flexfield structure and the segments information for the |
295 | flex code passed in. |
296 | CALLED BY |
297 | Main |
298 --------------------------------------------------------------------- */
299 PROCEDURE get_segments_info IS
300 l_segment_type fnd_flex_key_api.segment_type;
301 l_vset fnd_vset.valueset_r;
302 l_fmt fnd_vset.valueset_dr;
303 BEGIN
304 JG_UTILITY_PKG.log( '> JG_JOURNAL_ALLOCATIONS_PKG.get_segments_info');
305 --
306 -- Below info required if the zero-fill option is used for the segment method
307 -- and we also need the value set id for the cost center and account number to determine
308 -- their format types: char, number etc. Value Set Id determined from the results below.
309 --
310 JG_JOURNAL_ALLOCATIONS_PKG.G_flexfield_type :=
311 FND_FLEX_KEY_API.find_flexfield(JG_JOURNAL_ALLOCATIONS_PKG.G_GL_appln_short_name,
312 JG_JOURNAL_ALLOCATIONS_PKG.G_GL_acct_flex_code);
313 JG_JOURNAL_ALLOCATIONS_PKG.G_structure_type :=
314 FND_FLEX_KEY_API.find_structure(JG_JOURNAL_ALLOCATIONS_PKG.G_flexfield_type ,
315 JG_JOURNAL_ALLOCATIONS_PKG.G_chart_of_accounts_id);
316 FND_FLEX_KEY_API.get_segments(JG_JOURNAL_ALLOCATIONS_PKG.G_flexfield_type,
317 JG_JOURNAL_ALLOCATIONS_PKG.G_structure_type,
318 TRUE,
319 JG_JOURNAL_ALLOCATIONS_PKG.G_num_of_segments,
320 JG_JOURNAL_ALLOCATIONS_PKG.G_segment_list);
321
322 --
323 -- Get the cc segment data
324 --
325 IF NOT (FND_FLEX_APIS.get_qualifier_segnum(JG_JOURNAL_ALLOCATIONS_PKG.G_GL_application_id,
326 JG_JOURNAL_ALLOCATIONS_PKG.G_GL_acct_flex_code,
327 JG_JOURNAL_ALLOCATIONS_PKG.G_chart_of_accounts_id,
328 'FA_COST_CTR',
329 JG_JOURNAL_ALLOCATIONS_PKG.G_cc_segment_num) ) THEN
330 --
331 -- No error as it is possible to define a chart of accounts without a
332 -- cost center segment.
333 --
334 JG_JOURNAL_ALLOCATIONS_PKG.G_cc_segment_num := NULL;
335 JG_JOURNAL_ALLOCATIONS_PKG.G_cc_seg_num_string := ', NULL cost_center ';
336 END IF;
337
338 --
339 -- Get the account segment data
340 --
341 IF NOT FND_FLEX_APIS.get_qualifier_segnum(JG_JOURNAL_ALLOCATIONS_PKG.G_GL_application_id,
342 JG_JOURNAL_ALLOCATIONS_PKG.G_GL_acct_flex_code,
343 JG_JOURNAL_ALLOCATIONS_PKG.G_chart_of_accounts_id,
344 'GL_ACCOUNT',
345 JG_JOURNAL_ALLOCATIONS_PKG.G_acct_segment_num) THEN
346 FND_MESSAGE.SET_NAME(JG_JOURNAL_ALLOCATIONS_PKG.G_JG_appln_short_name, 'JG_ZZ_NO_NATURAL_ACCT_SEG');
347 RAISE APP_EXCEPTION.application_exception;
348 END IF;
349
350 --
351 -- Get the balancing segment data
352 --
353 IF NOT FND_FLEX_APIS.get_qualifier_segnum(JG_JOURNAL_ALLOCATIONS_PKG.G_GL_application_id,
354 JG_JOURNAL_ALLOCATIONS_PKG.G_GL_acct_flex_code,
355 JG_JOURNAL_ALLOCATIONS_PKG.G_chart_of_accounts_id,
356 'GL_BALANCING',
357 JG_JOURNAL_ALLOCATIONS_PKG.G_bal_segment_num) THEN
358 FND_MESSAGE.SET_NAME(JG_JOURNAL_ALLOCATIONS_PKG.G_JG_appln_short_name, 'JG_ZZ_NO_BALANCING_SEGMENT');
359 RAISE APP_EXCEPTION.application_exception;
360 END IF;
361
362 --
363 -- consider each segment separately
364 --
365 FOR j IN 1..JG_JOURNAL_ALLOCATIONS_PKG.G_num_of_segments LOOP
366
367 IF (NOT fnd_flex_apis.get_segment_info(x_application_id => JG_JOURNAL_ALLOCATIONS_PKG.G_GL_application_id,
368 x_id_flex_code => JG_JOURNAL_ALLOCATIONS_PKG.G_GL_acct_flex_code,
369 x_id_flex_num => JG_JOURNAL_ALLOCATIONS_PKG.G_chart_of_accounts_id,
370 x_seg_num => j,
371 x_appcol_name => G_acct_flex_segmt_arr(j).segment_col_name,
372 x_seg_name => G_acct_flex_segmt_arr(j).segment_name,
373 x_prompt => G_acct_flex_segmt_arr(j).segment_prompt,
374 x_value_set_name => G_acct_flex_segmt_arr(j).segment_vset_name)) THEN
375 FND_MESSAGE.set_name(JG_JOURNAL_ALLOCATIONS_PKG.G_JG_appln_short_name, 'JG_ZZ_MISSING_SEGMENT_INFO');
376 FND_MESSAGE.set_token('SEGMENT_NUM', TO_CHAR(j));
377 RAISE APP_EXCEPTION.application_exception;
378 ELSE
379 --
380 -- Determine the format type of the value set associated with the segment. If it is numeric, then
381 -- the low and high range values should be converted to numeric also before
382 -- comparing against each journal line cost center
383 --
384 l_segment_type := FND_FLEX_KEY_API.find_segment(JG_JOURNAL_ALLOCATIONS_PKG.G_flexfield_type,
385 JG_JOURNAL_ALLOCATIONS_PKG.G_structure_type,
386 G_acct_flex_segmt_arr(j).segment_name);
387 G_acct_flex_segmt_arr(j).segment_vset_id := l_segment_type.value_set_id;
388 FND_VSET.get_valueset(G_acct_flex_segmt_arr(j).segment_vset_id,
389 l_vset,
390 l_fmt); -- format type stored in here
391 G_acct_flex_segmt_arr(j).segment_vset_fmt_type := l_fmt.format_type;
392
393 --
394 -- Need to store cc segment number string to substitute into the dynamic select string
395 --
396 IF j = JG_JOURNAL_ALLOCATIONS_PKG.G_cc_segment_num THEN
397 JG_JOURNAL_ALLOCATIONS_PKG.G_cc_seg_num_string := ', jlv.' || G_acct_flex_segmt_arr(j).segment_col_name || ' cost_center ';
398 JG_UTILITY_PKG.debug(JG_JOURNAL_ALLOCATIONS_PKG.G_cc_seg_num_string);
399 ELSIF j = JG_JOURNAL_ALLOCATIONS_PKG.G_acct_segment_num THEN
400 JG_JOURNAL_ALLOCATIONS_PKG.G_acc_seg_num_string :=
401 ', jlv.' || G_acct_flex_segmt_arr(j).segment_col_name || ' account_number ';
402 JG_JOURNAL_ALLOCATIONS_PKG.G_acct_key_element :=
403 to_number( substr( G_acct_flex_segmt_arr(j).segment_col_name, 8));
404 JG_UTILITY_PKG.debug( 'acct_key_element = ' || to_char(JG_JOURNAL_ALLOCATIONS_PKG.G_acct_key_element));
405 JG_UTILITY_PKG.debug(JG_JOURNAL_ALLOCATIONS_PKG.G_acc_seg_num_string);
406 ELSIF j = JG_JOURNAL_ALLOCATIONS_PKG.G_bal_segment_num THEN
407 JG_JOURNAL_ALLOCATIONS_PKG.G_bal_key_element := to_number(substr(G_acct_flex_segmt_arr(j).segment_col_name,8));
408 JG_UTILITY_PKG.debug( 'l_bal_key_element = ' || to_char(JG_JOURNAL_ALLOCATIONS_PKG.G_bal_key_element));
409 END IF;
410
411 END IF;
412
413 END LOOP;
414
415 JG_UTILITY_PKG.log('< JG_JOURNAL_ALLOCATIONS_PKG.get_segments_info');
416 END get_segments_info;
417
418 /* ---------------------------------------------------------------------
419 | PRIVATE FUNCTION |
420 | validate_have_zero_fills |
421 | DESCRIPTION |
422 | Checks whether the given set of books allows zero-filled|
423 | values for all account segments other than the account |
424 | number and the balancing segment. Stores the valid |
425 | zero strings in an array for later reference. |
426 | CALLED BY |
427 | Validate_Segment_Method |
428 | RETURNS |
429 | TRUE if valid. |
430 --------------------------------------------------------------------- */
431 FUNCTION validate_have_zero_fills RETURN BOOLEAN IS
432 -- l_zero_string VARCHAR2(25) := RPAD('0', 25, '0'); Default values not allowed in init.
433 l_zero_value VARCHAR2(25);
434 l_found BOOLEAN;
435 l_row NUMBER;
436 l_vset fnd_vset.valueset_r;
437 l_fmt fnd_vset.valueset_dr;
438 l_value fnd_vset.value_dr;
439 BEGIN
440 JG_UTILITY_PKG.log('> JG_JOURNAL_ALLOCATIONS_PKG.validate_have_zero_fills');
441 --
442 -- consider each segment separately
443 --
444 FOR j IN 1..JG_JOURNAL_ALLOCATIONS_PKG.G_num_of_segments LOOP
445 --
446 -- Initialize array values to NULL
447 --
448 JG_JOURNAL_ALLOCATIONS_PKG.G_zero_fill_arr(j).zero_string := NULL;
449 JG_JOURNAL_ALLOCATIONS_PKG.G_zero_fill_arr(j).segment_col_name := NULL;
450 --
451 -- Don't substitute in zeros for either the natural account segment
452 -- or the balancing segment
453 --
454 IF j NOT IN (JG_JOURNAL_ALLOCATIONS_PKG.G_acct_segment_num,JG_JOURNAL_ALLOCATIONS_PKG.G_bal_segment_num) THEN
455
456 --
457 -- Need to retrieve the valueset record structure for the current segment as we cannot store
458 -- PLSQL tables of composite structures such as this one. Consequently, the table
459 -- G_acct_flex_segmt_arr in Get_Segments_Info doesn't hold the valueset record.
460 --
461 FND_VSET.get_valueset(G_acct_flex_segmt_arr(j).segment_vset_id,
462 l_vset,
463 l_fmt); -- format type stored in here
464
465 JG_UTILITY_PKG.debug( 'segment position num = '||TO_CHAR(j));
466 JG_UTILITY_PKG.debug( 'max size = '||TO_CHAR(l_fmt.max_size));
467 FOR k IN REVERSE 1..l_fmt.max_size LOOP
468 l_zero_value := SUBSTR(RPAD('0', 25, '0'), 1, k); --l_zero_string replaced
469 FND_VSET.get_value_init(l_vset, TRUE);
470 FND_VSET.get_value(l_vset, l_row, l_found, l_value);
471 WHILE l_found LOOP
472 IF l_zero_value = l_value.value THEN
473 JG_JOURNAL_ALLOCATIONS_PKG.G_zero_fill_arr(j).zero_string := l_value.value;
474 JG_JOURNAL_ALLOCATIONS_PKG.G_zero_fill_arr(j).segment_col_name := G_acct_flex_segmt_arr(j).segment_col_name;
475 GOTO value_found;
476 ELSE
477 FND_VSET.get_value(l_vset, l_row, l_found, l_value);
478 END IF;
479 END LOOP;
480 FND_VSET.get_value_end(l_vset);
481 END LOOP;
482 FND_MESSAGE.SET_NAME(JG_JOURNAL_ALLOCATIONS_PKG.G_JG_appln_short_name, 'JG_ZZ_ZERO_FILL_INVALID');
483 RETURN FALSE;
484 <<value_found>>
485 JG_UTILITY_PKG.debug('value found for segment position num '|| TO_CHAR(j));
486
487 END IF; -- Check for natural acct or balancing segment position
488 END LOOP; -- loop round for next segment
489 JG_UTILITY_PKG.log( '< JG_JOURNAL_ALLOCATIONS_PKG.validate_have_zero_fills');
490 RETURN TRUE;
491 END validate_have_zero_fills;
492
493 /* ---------------------------------------------------------------------
494 | PRIVATE FUNCTION |
495 | run_journal_import |
496 | DESCRIPTION |
497 | Runs the concurrent request to execute 'Journal Import'. |
498 | CALLED BY |
499 | Main |
500 | RETURNS |
501 | TRUE if successfully completes |
502 --------------------------------------------------------------------- */
503 FUNCTION run_journal_import RETURN BOOLEAN IS
504 l_num_of_copies NUMBER(5);
505 l_print_style VARCHAR2(50);
506 l_printer VARCHAR2(50);
507 l_save_output_flag VARCHAR2(3);
508 l_save_output_bool BOOLEAN;
509 l_ji_request_id NUMBER;
510 l_interface_run_id NUMBER;
511 l_group_id NUMBER;
512 l_summary_journal_flag VARCHAR2(1);
513 l_journal_import_finished BOOLEAN;
514 l_phase VARCHAR2(200);
515 l_status VARCHAR2(200);
516 l_dev_phase VARCHAR2(200);
517 l_dev_status VARCHAR2(200);
518 l_message VARCHAR2(500);
519 --
520 -- Kai 5.1.1999, we need to replace this mask with FND_DATE based dynamic mack for R115.
521 --
522 -- l_date_mask VARCHAR2(40) DEFAULT 'YYYY/MM/DD'; Default vlaues not allowed in Init.
523 BEGIN
524 JG_UTILITY_PKG.log('> JG_JOURNAL_ALLOCATIONS_PKG.run_journal_import');
525 --
526 -- Get print options from the original Allocation request
527 --
528 IF NOT FND_CONCURRENT.GET_REQUEST_PRINT_OPTIONS( JG_JOURNAL_ALLOCATIONS_PKG.G_request_id,
529 l_num_of_copies,
530 l_print_style,
531 l_printer,
532 l_save_output_flag) THEN
533 FND_MESSAGE.SET_NAME(JG_JOURNAL_ALLOCATIONS_PKG.G_JG_appln_short_name, 'JG_ZZ_NO_PRINT_OPTIONS_FOUND');
534 RETURN FALSE;
535 ELSE
536 IF l_save_output_flag = 'Y' THEN
537 l_save_output_bool := TRUE;
538 ELSE
539 l_save_output_bool := FALSE;
540 END IF;
541 --
542 -- Set print options
543 --
544 IF NOT FND_REQUEST.SET_PRINT_OPTIONS( l_printer,
545 l_print_style,
546 l_num_of_copies,
547 l_save_output_bool) THEN
548 FND_MESSAGE.SET_NAME(JG_JOURNAL_ALLOCATIONS_PKG.G_JG_appln_short_name, 'JG_ZZ_SET_PRINT_OPTIONS_FAILED' );
549 RETURN FALSE;
550 END IF;
551 END IF;
552 --
553 -- Get Unique Interface Run Id
554 --
555 l_interface_run_id := GL_INTERFACE_CONTROL_PKG.Get_Unique_Run_Id;
556
557 --
558 -- Get Interface Group Id
559 --
560 SELECT MAX(group_id)
561 INTO l_group_id
562 FROM gl_interface_groups_v
563 WHERE set_of_books_id = JG_JOURNAL_ALLOCATIONS_PKG.G_destn_set_of_books_id
564 AND user_je_source_name = JG_JOURNAL_ALLOCATIONS_PKG.G_destn_journal_source;
565
566 --
567 -- Populate GL_Interface_Control table
568 --
569 GL_INTERFACE_CONTROL_PKG.Insert_Row(--JG_JOURNAL_ALLOCATIONS_PKG.G_destn_set_of_books_id, Removed, ledger Arch. changes in package
570 l_interface_run_id,
571 JG_JOURNAL_ALLOCATIONS_PKG.G_destn_journal_source,
572 JG_JOURNAL_ALLOCATIONS_PKG.G_destn_set_of_books_id,
573 l_group_id,
574 NULL);
575 IF (JG_JOURNAL_ALLOCATIONS_PKG.G_destn_summary_level = 'D') THEN -- Detail
576 l_summary_journal_flag := 'N';
577 ELSE
578 l_summary_journal_flag := 'Y';
579 END IF;
580
581 --
582 -- Submit Journal Import Concurrent Request
583 --
584 l_ji_request_id := FND_REQUEST.Submit_Request(
585 application => JG_JOURNAL_ALLOCATIONS_PKG.G_GL_appln_short_name,
586 program => 'GLLEZL',
587 description => null,
588 start_time => null,
589 sub_request=>FALSE,
590 argument1 => l_interface_run_id,
591 argument2 => fnd_profile.value('GL_ACCESS_SET_ID'),
592 argument3 => JG_JOURNAL_ALLOCATIONS_PKG.G_post_errors_to_suspense,
593 argument4 => to_char(JG_JOURNAL_ALLOCATIONS_PKG.G_GL_start_date,'YYYY/MM/DD'),
594 argument5 => to_char(JG_JOURNAL_ALLOCATIONS_PKG.G_GL_end_date,'YYYY/MM/DD'),
595 argument6 => l_summary_journal_flag,
596 argument7 => JG_JOURNAL_ALLOCATIONS_PKG.G_import_desc_flexfields,
597 argument8 => 'Y');
598
599 COMMIT;
600 IF (l_ji_request_id = 0) THEN
601 FND_MESSAGE.Set_Name(JG_JOURNAL_ALLOCATIONS_PKG.G_JG_appln_short_name,'JG_ZZ_JOURNAL_IMPORT_FAILED');
602 RETURN FALSE;
603 END IF;
604
605 --
606 -- If running journal import in Summary Mode, then JI gives the lines the description 'Journal Import Created'
607 -- by default. The below code overwrites this default description for all lines with the journal header
608 -- descriptions.
609 --
610 IF JG_JOURNAL_ALLOCATIONS_PKG.G_destn_summary_level = 'S' AND JG_JOURNAL_ALLOCATIONS_PKG.G_destn_cost_center_grouping = 'Y' THEN
611 l_journal_import_finished := FND_CONCURRENT.WAIT_FOR_REQUEST(l_ji_request_id
612 ,10
613 ,0
614 ,l_phase
615 ,l_status
616 ,l_dev_phase
617 ,l_dev_status
618 ,l_message);
619 IF l_journal_import_finished THEN
620 JG_UTILITY_PKG.debug('journal import finished = true');
621 ELSE
622 JG_UTILITY_PKG.debug('journal import finished = false');
623 END IF;
624 JG_UTILITY_PKG.debug('phase = '||l_phase);
625 JG_UTILITY_PKG.debug('status = '||l_status);
626 JG_UTILITY_PKG.debug('dev phase = '||l_dev_phase);
627 JG_UTILITY_PKG.debug('dev status = '||l_dev_status);
628 JG_UTILITY_PKG.debug('message = '||l_message);
629 IF l_dev_phase = 'COMPLETE' AND l_dev_status = 'NORMAL' THEN
630 BEGIN
631 APPS_DDL.apps_ddl('UPDATE gl_je_lines l '||
632 'SET l.description = (SELECT h.description '||
633 'FROM gl_je_headers h '||
634 'WHERE h.je_header_id = l.je_header_id) '||
635 'WHERE l.je_header_id IN (SELECT h.je_header_id '||
636 'FROM gl_je_headers h '||
637 ', gl_je_batches b '||
638 'WHERE b.je_batch_id = h.je_batch_id '||
639 'AND b.name LIKE '''||TO_CHAR(JG_JOURNAL_ALLOCATIONS_PKG.G_Request_Id)||'%'''||
640 ' AND b.default_period_name = '''||JG_JOURNAL_ALLOCATIONS_PKG.G_destn_period_name||
641 ''' AND b.ledger_id = '||TO_CHAR(JG_JOURNAL_ALLOCATIONS_PKG.G_destn_set_of_books_id)||')');
642 -- GC Ledger Architecture change
643 EXCEPTION
644 -- Do nothing if there is an error in updating the lines
645 WHEN OTHERS THEN
646 JG_UTILITY_PKG.debug('Error in Update statement after journal import run');
647 NULL;
648 END;
649 END IF;
650 END IF;
651
652
653 JG_UTILITY_PKG.log('< JG_JOURNAL_ALLOCATIONS_PKG.run_journal_import');
654 RETURN TRUE;
655 EXCEPTION WHEN OTHERS THEN
656 FND_MESSAGE.Set_Name(JG_JOURNAL_ALLOCATIONS_PKG.G_JG_appln_short_name,'JG_ZZ_JOURNAL_IMPORT_FAILED');
657 JG_UTILITY_PKG.log('< JG_JOURNAL_ALLOCATIONS_PKG.run_journal_import');
658 RETURN FALSE;
659 END run_journal_import;
660
661 /* ------------------------------------------------------------------------------
662 | PUBLIC PROCEDURE |
663 | main |
664 | DESCRIPTION |
665 | Creates journal allocation lines in the GL_Interface table |
666 | based on posted fiscal journal lines that meet the parameter |
667 | criteria passed in and have not already been allocated. |
668 | Once a line has been allocated, a record of this entry is kept |
669 | in the table jg_zz_ta_allocated_lines to resolve the latter. |
670 | Parameters also affect the composition of the destination |
671 | analytical account lines. |
672 | The user can choose whether or not to run the Journal Import |
673 | after creating the allocations. The original journal lines |
674 | are split into one or more destination lines based on the |
675 | percentages defined under the rule set chosen by the user. |
676 | 'Define Journal Allocations' form allows the user to set up |
677 | these rule sets. For a particular rule set, allocation splits |
678 | are dependent on both the cost center and the natural account |
679 | number of the fiscal journal line. |
680 | Aswell as the destination accounts being dependent on the rule |
681 | set chosen, they are dependent on the segment method parameter. |
682 | Segment method 'Journal Account' implies that all destination |
683 | Accounting Flexfield segments other than the natural account |
684 | segment are taken from the fiscal journal account segments. |
685 | Segment method 'Zero Filled' implies that all destination |
686 | Accounting Flexfield segments other than the natural account |
687 | and the balancing segment are filled with zeros if zeros are |
688 | valid values for each of the remaining segments. |
689 | OUTPUT |
690 | As a result of running this procedure, it will generate a |
691 | report that will display all fiscal journal lines that have |
692 | been allocated alongwith the allocated line details. Any errors |
693 | occurring in creating the allocations will be displayed in the |
694 | same report.
695 | In addition, the allocations will be inserted into the |
696 | GL_Interface table ready for Journal Import (if running in |
697 | non-validation mode), a record will be kept of those fiscal |
698 | lines that have been allocated and it will run Journal Import |
699 | if the user chose to do so. |
700 --------------------------------------------------------------------------------*/
701 PROCEDURE main(errbuf IN OUT NOCOPY VARCHAR2,
702 retcode IN OUT NOCOPY VARCHAR2,
703 p_set_of_books_id IN NUMBER,
704 p_chart_of_accounts_id IN NUMBER,
705 p_functional_currency IN VARCHAR2,
706 p_period_set_name IN VARCHAR2,
707 p_rule_set_id IN NUMBER,
708 p_period_name IN VARCHAR2,
709 p_currency_code IN VARCHAR2,
710 p_amount_type IN VARCHAR2,
711 p_balance_type IN VARCHAR2,
712 p_balance_type_id IN NUMBER,
713 p_balance_segment_value IN VARCHAR2,
714 p_destn_set_of_books_id IN NUMBER,
715 p_destn_period_name IN VARCHAR2,
716 p_destn_journal_source IN VARCHAR2,
717 p_destn_journal_category IN VARCHAR2,
718 p_destn_segment_method IN VARCHAR2,
719 p_destn_cost_center_grouping IN VARCHAR2,
720 p_error_handling IN VARCHAR2,
721 p_validate_only IN VARCHAR2,
722 p_run_journal_import IN VARCHAR2,
723 p_destn_summary_level IN VARCHAR2,
724 p_import_desc_flexfields IN VARCHAR2,
725 p_post_errors_to_suspense IN VARCHAR2,
726 p_debug_flag IN VARCHAR2) IS
727
728 l_err_msg_code VARCHAR2(50);
729 l_acct_rnge_offset BOOLEAN;
730
731 BEGIN
732 JG_UTILITY_PKG.log('> JG_JOURNAL_ALLOCATIONS_PKG.main');
733
734 -- Bug 1064357: Session mode must be set
735 FND_FLEX_KEY_API.set_session_mode('customer_data');
736
737 JG_UTILITY_PKG.debug(TO_CHAR(SYSDATE, 'HH24:MI:SS'));
738 --
739 -- Determine whether to output debug messages to log file
740 --
741 IF (p_debug_flag = 'Y') THEN
742 JG_UTILITY_PKG.enable_debug;
743 -- APPS_DDL.apps_ddl('ALTER SESSION SET SQL_TRACE TRUE');
744 END IF;
745 --
746 -- Initialize the parameter globals
747 --
748 JG_JOURNAL_ALLOCATIONS_PKG.set_parameters( p_set_of_books_id,
749 p_chart_of_accounts_id,
750 p_functional_currency,
751 p_period_set_name,
752 p_rule_set_id,
753 p_period_name,
754 p_currency_code,
755 p_amount_type,
756 p_balance_type,
757 p_balance_type_id,
758 p_balance_segment_value,
759 p_destn_set_of_books_id,
760 p_destn_period_name,
761 p_destn_journal_source,
762 p_destn_journal_category,
763 p_destn_segment_method,
764 p_destn_cost_center_grouping,
765 p_error_handling,
766 p_validate_only,
767 p_run_journal_import,
768 p_destn_summary_level,
769 p_import_desc_flexfields,
770 p_post_errors_to_suspense,
771 p_debug_flag);
772
773 --
774 -- Perform a number of validation checks on the rule set. If any errors found,
775 -- then the program should be aborted
776 --
777 IF NOT JG_JOURNAL_ALLOCATIONS_PKG.valid_rule_set(l_err_msg_code, l_acct_rnge_offset) THEN
778 FND_MESSAGE.set_name(JG_JOURNAL_ALLOCATIONS_PKG.G_JG_appln_short_name, l_err_msg_code);
779 RAISE APP_EXCEPTION.application_exception;
780 END IF;
781
782 IF (JG_JOURNAL_ALLOCATIONS_PKG.G_validate_only = 'N') THEN
783 --
784 -- Get the translated meanings from source and category for gl_interface
785 --
786 JG_JOURNAL_ALLOCATIONS_PKG.get_source_and_category;
787 --
788 -- Get Period Name's start and end dates for gl_interface
789 --
790 GL_INFO.gl_get_period_dates(JG_JOURNAL_ALLOCATIONS_PKG.G_destn_set_of_books_id,
791 JG_JOURNAL_ALLOCATIONS_PKG.G_destn_period_name,
792 JG_JOURNAL_ALLOCATIONS_PKG.G_GL_start_date,
793 JG_JOURNAL_ALLOCATIONS_PKG.G_GL_end_date,
794 errbuf);
795 IF (errbuf IS NOT NULL) THEN
796 RAISE APP_EXCEPTION.application_exception;
797 END IF;
798 END IF;
799 --
800 -- Get set of books name from source set of books id for reporting purposes
801 --
802 JG_JOURNAL_ALLOCATIONS_PKG.get_set_of_books_name;
803 --
804 -- Get all the segment info of the acct key flexfield
805 --
806 JG_JOURNAL_ALLOCATIONS_PKG.get_segments_info;
807
808 --
809 -- Check that zero fills are valid values for segments if chosen segment method.
810 -- Offset acct range totals are also zero-filled, so check for these also.
811 --
812 IF (JG_JOURNAL_ALLOCATIONS_PKG.G_destn_segment_method = 'ZF' OR l_acct_rnge_offset) THEN
813 IF (NOT JG_JOURNAL_ALLOCATIONS_PKG.validate_have_zero_fills) THEN
814 RAISE APP_EXCEPTION.application_exception;
815 END IF;
816 END IF;
817
818 JG_UTILITY_PKG.debug(TO_CHAR(SYSDATE, 'HH24:MI:SS'));
819
820 --
821 -- Call the next package, to allocate
822 --
823 JG_ALLOCATE_JOURNALS_PKG.allocate;
824 --
825 -- Submit the journal import if at least one allocation and not in validation mode
826 --
827 JG_UTILITY_PKG.debug(TO_CHAR(SYSDATE, 'HH24:MI:SS'));
828
829 IF (JG_JOURNAL_ALLOCATIONS_PKG.G_run_journal_import = 'Y' AND
830 JG_CREATE_JOURNALS_PKG.i <> 0 AND
831 JG_JOURNAL_ALLOCATIONS_PKG.G_Validate_Only = 'N') THEN
832 IF NOT JG_JOURNAL_ALLOCATIONS_PKG.run_journal_import THEN
833 RAISE APP_EXCEPTION.application_exception;
834 END IF;
835 END IF;
836 retcode := JG_JOURNAL_ALLOCATIONS_PKG.G_retcode;
837 JG_UTILITY_PKG.debug( 'retcode = '||retcode);
838 JG_UTILITY_PKG.log('< JG_JOURNAL_ALLOCATIONS_PKG.main');
839 EXCEPTION
840 WHEN APP_EXCEPTION.application_exception THEN
841 JG_UTILITY_PKG.log('< Application_Exception clause');
842 JG_JOURNAL_ALLOCATIONS_PKG.G_retcode := '2';
843 retcode := JG_JOURNAL_ALLOCATIONS_PKG.G_retcode;
844 IF JG_JOURNAL_ALLOCATIONS_PKG.G_errbuf IS NULL THEN
845 errbuf := FND_MESSAGE.get;
846 ELSIF retcode = '2' THEN -- error
847 errbuf := JG_JOURNAL_ALLOCATIONS_PKG.G_errbuf;
848 END IF;
849 JG_UTILITY_PKG.log(errbuf);
850 ROLLBACK;
851 WHEN OTHERS THEN
852 JG_UTILITY_PKG.log('< Others Exception clause');
853 JG_JOURNAL_ALLOCATIONS_PKG.G_retcode := '2';
854 retcode := JG_JOURNAL_ALLOCATIONS_PKG.G_retcode;
855 ROLLBACK;
856 RAISE;
857 END main;
858
859 /* ------------------------------------------------------------------------------
860 | PUBLIC PROCEDURE |
861 | main |
862 | DESCRIPTION |
863 | Unallocates the allocated lines |
864 --------------------------------------------------------------------------------*/
865 PROCEDURE main(errbuf IN OUT NOCOPY VARCHAR2,
866 retcode IN OUT NOCOPY VARCHAR2,
867 p_chart_of_accounts_id IN NUMBER,
868 p_functional_currency IN VARCHAR2,
869 p_request_id IN NUMBER,
870 p_debug_flag IN VARCHAR2) IS
871 l_ext_precision NUMBER;
872 l_min_acct_unit NUMBER;
873 BEGIN
874 JG_UTILITY_PKG.log('> JG_JOURNAL_ALLOCATIONS_PKG.main');
875
876 -- Bug 1064357: Session mode must be set
877 FND_FLEX_KEY_API.set_session_mode('customer_data');
878
879 --
880 -- Determine the debug
881 --
882 IF p_debug_flag = 'Y' THEN
883 JG_UTILITY_PKG.enable_debug;
884 END IF;
885 --
886 -- Set the Global variables
887 --
888 JG_JOURNAL_ALLOCATIONS_PKG.G_JG_appln_short_name := 'JG';
889 JG_JOURNAL_ALLOCATIONS_PKG.G_GL_appln_short_name := 'SQLGL';
890 JG_JOURNAL_ALLOCATIONS_PKG.G_GL_application_id := 101;
891 JG_JOURNAL_ALLOCATIONS_PKG.G_GL_acct_flex_code := 'GL#';
892 JG_JOURNAL_ALLOCATIONS_PKG.G_request_id := FND_GLOBAL.CONC_REQUEST_ID;
893 JG_JOURNAL_ALLOCATIONS_PKG.G_progr_appl_id := FND_GLOBAL.PROG_APPL_ID;
894 JG_JOURNAL_ALLOCATIONS_PKG.G_conc_progr_id := FND_GLOBAL.CONC_PROGRAM_ID;
895 JG_JOURNAL_ALLOCATIONS_PKG.G_user_id := FND_GLOBAL.USER_ID;
896 JG_JOURNAL_ALLOCATIONS_PKG.G_login_id := FND_GLOBAL.LOGIN_ID;
897 JG_JOURNAL_ALLOCATIONS_PKG.G_validate_only := 'N';
898 JG_JOURNAL_ALLOCATIONS_PKG.G_functional_currency := p_functional_currency;
899 JG_JOURNAL_ALLOCATIONS_PKG.G_chart_of_accounts_id := p_chart_of_accounts_id;
900 --
901 -- Initialized to segment1 and segment2 for unallocation process
902 -- the cost center and account segment numbers are not required for unallocation
903 --
904 JG_JOURNAL_ALLOCATIONS_PKG.G_cc_seg_num_string := ', SEGMENT1';
905 JG_JOURNAL_ALLOCATIONS_PKG.G_acc_seg_num_string := ', SEGMENT2';
906 --
907 -- Unallocation can only fail in the table locking, set to Error out NOCOPY
908 --
909 JG_JOURNAL_ALLOCATIONS_PKG.G_error_handling := 'E';
910 --
911 -- Initialize retcode to 0 for successful completion
912 --
913 JG_JOURNAL_ALLOCATIONS_PKG.G_retcode := 0;
914
915 JG_ALLOCATE_JOURNALS_PKG.G_last_journal_qry_rec.offset_account := NULL;
916 --
917 -- Get Functional Currency Format Mask and precision
918 -- Bug 3482467 (2638803) , changed G_func_currency_format_mask from 15 to 18
919 JG_JOURNAL_ALLOCATIONS_PKG.G_func_currency_format_mask :=
920 FND_CURRENCY.Get_Format_Mask(JG_JOURNAL_ALLOCATIONS_PKG.G_functional_currency,18);
921 FND_CURRENCY.get_info(JG_JOURNAL_ALLOCATIONS_PKG.G_functional_currency,
922 JG_JOURNAL_ALLOCATIONS_PKG.G_func_currency_precision,
923 l_ext_precision,
924 l_min_acct_unit);
925 JG_UTILITY_PKG.debug( 'func curr format mask = '||JG_JOURNAL_ALLOCATIONS_PKG.G_func_currency_format_mask);
926 JG_UTILITY_PKG.debug( 'func curr precision = '||JG_JOURNAL_ALLOCATIONS_PKG.G_func_currency_precision);
927 --
928 -- Initialize the parameter globals
929 --
930 JG_JOURNAL_ALLOCATIONS_PKG.G_unalloc_request_id := p_request_id;
931 --
932 -- Call the next package, to allocate
933 --
934 JG_ALLOCATE_JOURNALS_PKG.allocate;
935
936 retcode := JG_JOURNAL_ALLOCATIONS_PKG.G_retcode;
937
938 JG_UTILITY_PKG.debug('retcode = '||retcode);
939 JG_UTILITY_PKG.log('< JG_JOURNAL_ALLOCATIONS_PKG.main');
940 EXCEPTION
941 WHEN APP_EXCEPTION.application_exception THEN
942 JG_JOURNAL_ALLOCATIONS_PKG.G_retcode := '2';
943 retcode := JG_JOURNAL_ALLOCATIONS_PKG.G_retcode;
944 IF JG_JOURNAL_ALLOCATIONS_PKG.G_errbuf IS NULL THEN
945 errbuf := FND_MESSAGE.get;
946 ELSIF retcode = '2' THEN -- error
947 errbuf := JG_JOURNAL_ALLOCATIONS_PKG.G_errbuf;
948 END IF;
949 JG_UTILITY_PKG.log(errbuf);
950 ROLLBACK;
951 WHEN OTHERS THEN
952 JG_JOURNAL_ALLOCATIONS_PKG.G_retcode := '2';
953 retcode := JG_JOURNAL_ALLOCATIONS_PKG.G_retcode;
954 ROLLBACK;
955 RAISE;
956 END main;
957 END JG_JOURNAL_ALLOCATIONS_PKG;