[Home] [Help]
PACKAGE BODY: APPS.INV_PURGE_PUB
Source
1 PACKAGE BODY inv_purge_pub AS
2 /* $Header: INVTXPGB.pls 115.11 2004/04/29 11:08:55 gbhagra ship $ */
3
4 /**
5 * Global constant holding the package name
6 **/
7 g_pkg_name CONSTANT VARCHAR2(30) := 'INV_PURGE_PUB';
8 g_version_printed BOOLEAN := FALSE;
9 g_user_name fnd_user.user_name%TYPE := fnd_global.user_name;
10
11 /**
12 * This Procedure is used to print the Debug Messages to log file.
13 * @param p_message Debug Message
14 * @param p_module Module
15 * @param p_level Debug Level
16 **/
17 PROCEDURE print_debug(p_message IN VARCHAR2, p_module IN VARCHAR2, p_level IN NUMBER) IS
18 BEGIN
19 IF NOT g_version_printed THEN
20 inv_log_util.TRACE('$Header: INVTXPGB.pls 115.11 2004/04/29 11:08:55 gbhagra ship $', g_pkg_name || '.' || p_module, 1);
21 g_version_printed := TRUE;
22 END IF;
23
24 inv_log_util.TRACE(g_user_name || ': ' || p_message, g_pkg_name || '.' || p_module, p_level);
25 EXCEPTION
26 WHEN OTHERS THEN
27 NULL;
28 END print_debug;
29
30 PROCEDURE purge_transactions(
31 x_errbuf OUT NOCOPY VARCHAR2
32 , x_retcode OUT NOCOPY NUMBER
33 , p_purge_date IN VARCHAR2
34 , p_orgid IN NUMBER
35 , p_purge_name IN VARCHAR2
36 ) IS
37 l_tempvar NUMBER;
38 l_login_id NUMBER := fnd_profile.VALUE('LOGIN_ID');
39 l_user_id NUMBER := fnd_profile.VALUE('USER_ID');
40 l_batch_size NUMBER := 1000;
41 l_more BOOLEAN := TRUE;
42 l_count NUMBER;
43 l_total_count NUMBER;
44 l_ret BOOLEAN;
45 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
46 --l_errbuf VARCHAR2(20); Commented out as part of Bug# 3542452
47 --l_retcode NUMBER; Commented out as part of Bug# 3542452
48 l_purge_date DATE;
49 l_proc CONSTANT VARCHAR2(30) := 'PURGE_TRANSACTIONS';
50 BEGIN
51 SAVEPOINT purge_savepoint;
52
53 IF (l_debug = 1) THEN
54 print_debug(
55 'The input parameters are: '
56 || fnd_global.local_chr(10)
57 || ' OrgId: '
58 || p_orgid
59 || fnd_global.local_chr(10)
60 || ', Date: '
61 || p_purge_date
62 || fnd_global.local_chr(10)
63 , l_proc
64 , 9
65 );
66 END IF;
67
68 -- validate the Organization passed to ensure that it has no OPEN
69 -- accounting periods for the date specified
70 BEGIN
71 SELECT 1
72 INTO l_tempvar
73 FROM org_acct_periods
74 WHERE organization_id = p_orgid
75 AND period_start_date <= inv_le_timezone_pub.get_le_day_for_inv_org(fnd_date.canonical_to_date(p_purge_date), p_orgid)
76 AND schedule_close_date >= inv_le_timezone_pub.get_le_day_for_inv_org(fnd_date.canonical_to_date(p_purge_date), p_orgid)
77 AND open_flag = 'N';
78 EXCEPTION
79 WHEN NO_DATA_FOUND THEN
80 fnd_msg_pub.initialize;
81 fnd_message.set_name('INV','INV_NO_CLOSED_PERIOD');
82 fnd_msg_pub.add;
83 fnd_file.put_line(fnd_file.LOG,substrb(fnd_msg_pub.get(p_encoded =>FND_API.G_FALSE),1,250));
84 RETURN;
85 END;
86
87 -- If a valid purge_name is specified, insert a record into mtl_purge_headers
88 -- to serve as an audit-trail.
89 IF (p_purge_name IS NOT NULL) THEN
90 INSERT INTO mtl_purge_header
91 (
92 purge_id
93 , last_update_date
94 , last_updated_by
95 , last_update_login
96 , creation_date
97 , created_by
98 , purge_date
99 , purge_name
100 , organization_id
101 )
102 VALUES (
103 mtl_material_transactions_s.NEXTVAL
104 , SYSDATE
105 , l_user_id
106 , l_login_id
107 , SYSDATE
108 , l_user_id
109 , fnd_date.canonical_to_date(p_purge_date)
110 , p_purge_name
111 , p_orgid
112 );
113 END IF;
114
115 /* Bug: 3145486*/
116 l_purge_date := fnd_date.canonical_to_date(p_purge_date) + 1 -(1 /(24 * 3600));
117
118 /* Bug# 3542452 */
119 inv_txn_purge_main.txn_purge_main(x_errbuf, x_retcode, p_orgid, l_purge_date);
120
121 -- Commented out as part of Bug# 3542452
122 /*IF l_retcode = 2 THEN
123 fnd_file.put_line(fnd_file.LOG, 'Error from INV_TXN_PURGE_MAIN.TXN_PURGE_MAIN');
124 l_ret := fnd_concurrent.set_completion_status('ERROR', 'Error');
125 x_retcode := 2;
126 x_errbuf := 'Error';
127 END IF;
128
129 l_ret := fnd_concurrent.set_completion_status('NORMAL', 'Success');
130 x_retcode := 0;
131 x_errbuf := 'Success';*/
132 EXCEPTION
133 WHEN OTHERS THEN
134 IF (l_debug = 1) THEN
135 print_debug('Error :' || SUBSTR(SQLERRM, 1, 100), l_proc, 1);
136 END IF;
137
138 ROLLBACK TO purge_savepoint;
139 -- Commented out as part of Bug# 3542452
140 --l_ret := fnd_concurrent.set_completion_status('ERROR', 'Error');
141 --x_errbuf := 'Error';
142 x_retcode := 2;
143 fnd_message.set_name('INV', 'INV_PURGE_TXN_ERR');
144 x_errbuf := fnd_message.get;
145 END purge_transactions;
146 END inv_purge_pub;