DBA Data[Home] [Help]

PACKAGE BODY: APPS.IGC_MSGS_PKG

Source


1 PACKAGE BODY IGC_MSGS_PKG AS
2 /* $Header: IGCBMSGB.pls 120.4.12000000.1 2007/08/20 12:10:13 mbremkum ship $ */
3 
4 -- Private Global Variables :
5 
6 g_pkg_name         CONSTANT VARCHAR2(30) := 'IGC_MSGS_PKG';
7 g_filename         VARCHAR2(255) := NULL;
8 g_dirpath          VARCHAR2(255) := NULL;
9 g_file_ptr         UTL_FILE.FILE_TYPE;
10 
11 PROCEDURE Initialize_Debug (
12    p_profile_name     IN VARCHAR2,
13    p_product          IN VARCHAR2,
14    p_sub_component    IN VARCHAR2,
15    p_filename_value   IN VARCHAR2 := NULL,
16    x_Return_Status   OUT NOCOPY VARCHAR2
17 );
18 
19 
20 -- Procedure that adds the appropriate message to the Token array that will be added
21 -- to the error stack so that the user can see any messages generated from the process
22 -- being run.
23 --
24 -- Parameters :
25 --
26 -- p_tokname        ==> Token name of the error message
27 -- p_tokval         ==> Value of the token to be added.
28 --
29 
30 PROCEDURE message_token(
31    p_tokname           IN VARCHAR2,
32    p_tokval            IN VARCHAR2
33 ) IS
34 
35 BEGIN
36 
37    IF (g_no_msg_tokens IS NULL) THEN
38       g_no_msg_tokens := 1;
39    ELSE
40       g_no_msg_tokens := g_no_msg_tokens + 1;
41    END IF;
42 
43    g_msg_tok_names (g_no_msg_tokens) := p_tokname;
44    g_msg_tok_val (g_no_msg_tokens)   := p_tokval;
45 
46 END message_token;
47 
48 
49 --
50 -- Procedure that sets/adds the appropriate message to the error stack so that the
51 -- user can see any messages generated from the process being run.
52 --
53 -- Parameters :
54 --
55 -- p_appname        ==> Application name used for message
56 -- p_msgname        ==> Message to be added onto message stack
57 --
58 
59 PROCEDURE add_message(
60    p_appname           IN VARCHAR2,
61    p_msgname           IN VARCHAR2
62 ) IS
63 
64 i  BINARY_INTEGER;
65 
66 BEGIN
67 
68    IF ((p_appname IS NOT NULL) and (p_msgname IS NOT NULL)) THEN
69 
70       FND_MESSAGE.SET_NAME (p_appname, p_msgname);
71 
72       IF (g_no_msg_tokens IS NOT NULL) THEN
73 
74          FOR i IN 1..g_no_msg_tokens LOOP
75             FND_MESSAGE.SET_TOKEN (g_msg_tok_names(i), g_msg_tok_val(i));
76          END LOOP;
77 
78       END IF;
79 
80       FND_MSG_PUB.ADD;
81 
82     END IF;
83 
84     -- Clear Message Token stack
85 
86     g_no_msg_tokens := 0;
87 
88 END add_message;
89 
90 --
91 -- Procedure that initializes the debug file and updates the appropriate variables that
92 -- are required for the next call to the Put_Debug_Msg.  These variables should be
93 -- defined as globals in the callers packages.
94 --
95 -- Parameters :
96 --
97 -- p_profile_name      ==> Profile option used to get directory location for debug
98 -- p_product           ==> Product string (IGC, GMS, etc.)
99 -- p_sub_component     ==> Sub Component name to the product (CC, CBC, etc.)
100 -- p_filename_value    ==> If NULL then build here otherwise use callers filename.
101 -- x_Return_Status     ==> Status of procedure returned to caller
102 --
103 
104 PROCEDURE Initialize_Debug (
105    p_profile_name     IN VARCHAR2,
106    p_product          IN VARCHAR2,
107    p_sub_component    IN VARCHAR2,
108    p_filename_value   IN VARCHAR2 := NULL,
109    x_Return_Status   OUT NOCOPY VARCHAR2
110 ) IS
111 
112    l_api_name             CONSTANT VARCHAR2(30)   := 'Initialize_Debug';
113 
114 BEGIN
115 
116    x_return_status := FND_API.G_RET_STS_SUCCESS;
117 
118    IF ( (p_filename_value IS NULL) AND
119         ((p_product IS NULL) OR
120          (p_sub_component IS NULL)) ) THEN
121 
122       x_return_status := FND_API.G_RET_STS_ERROR;
123       --g_debug_mode    := FALSE;
124       IGC_MSGS_PKG.add_message (p_appname => 'IGC',
125                                 p_msgname => 'IGC_DEBUG_NO_PROD_COMP'
126                                );
127 
128    ELSE
129 
130 -- ----------------------------------------------------------------------
131 -- Build the filename and directory location that is to be used for the
132 -- debug output.
133 -- ----------------------------------------------------------------------
134       IF (p_filename_value IS NULL) THEN
135          g_filename := LTRIM (RTRIM (p_product)) || '_' || LTRIM (RTRIM (p_sub_component)) ||
136                        '_' || USERENV ('SESSIONID') || '.dbg';
137       ELSE
138          g_filename := p_filename_value;
139       END IF;
140       g_dirpath  := FND_PROFILE.VALUE (p_profile_name);
141 
142 -- ----------------------------------------------------------------------
143 -- Since the directory location for the debug output for UTL_FILE has
144 -- not been setup from the user the utility will not work properly.
145 -- Set the global Debug mode flag to false and return with error message
146 -- added.
147 -- ----------------------------------------------------------------------
148       IF (g_dirpath IS NULL) THEN
149 
150          x_return_status := FND_API.G_RET_STS_ERROR;
151          --g_debug_mode    := FALSE;
152          IGC_MSGS_PKG.add_message (p_appname => 'IGC',
153                                    p_msgname => 'IGC_DEBUG_NO_PROFILE_PATH'
154                                   );
155 
156       ELSE
157 
158 -- ----------------------------------------------------------------------
159 -- Make sure that the file is not open currently.  If it is close the
160 -- file before reopening.
161 -- ----------------------------------------------------------------------
162          IF (UTL_FILE.IS_OPEN ( g_file_ptr )) THEN
163             UTL_FILE.FCLOSE ( g_file_ptr );
164          END IF;
165 
166 -- ----------------------------------------------------------------------
167 -- Assign the global pointer to be used for the debug output.
168 -- ----------------------------------------------------------------------
169          g_file_ptr := UTL_FILE.FOPEN ( g_dirpath, g_filename, 'a' );
170 
171       END IF;
172 
173    END IF;
174 
175    RETURN;
176 
177 -- ----------------------------------------------------------------------
178 -- Exception section for the Initialize_Debug procedure.
179 -- ----------------------------------------------------------------------
180 EXCEPTION
181   WHEN UTL_FILE.INVALID_PATH THEN
182       x_return_status := FND_API.G_RET_STS_ERROR;
183       --g_debug_mode    := FALSE;
184       IGC_MSGS_PKG.add_message (p_appname => 'IGC',
185                                 p_msgname => 'IGC_DEBUG_INVALID_PATH'
186                                );
187       RETURN;
188 
189    WHEN UTL_FILE.WRITE_ERROR THEN
190       x_return_status := FND_API.G_RET_STS_ERROR;
191       --g_debug_mode    := FALSE;
192       IGC_MSGS_PKG.add_message (p_appname => 'IGC',
193                                 p_msgname => 'IGC_DEBUG_WRITE_ERROR'
194                                );
195       RETURN;
196 
197    WHEN UTL_FILE.INVALID_FILEHANDLE  THEN
198       x_return_status := FND_API.G_RET_STS_ERROR;
199       --g_debug_mode    := FALSE;
200       IGC_MSGS_PKG.add_message (p_appname => 'IGC',
201                                 p_msgname => 'IGC_DEBUG_FILEHANDLE'
202                                );
203       RETURN;
204 
205    WHEN OTHERS THEN
206       x_return_status := FND_API.G_RET_STS_ERROR;
207       --g_debug_mode    := FALSE;
208       IF (FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )) THEN
209          FND_MSG_PUB.Add_Exc_Msg ( g_pkg_name, l_api_name );
210       END IF;
211       RETURN;
212 
213 END Initialize_Debug;
214 
215 --
216 -- Procedure that outputs debug message to debug file that has been initialized and
217 -- created.
218 --
219 -- Parameters :
220 --
221 -- p_debug_message     ==> Message to be output to debug file.
222 -- p_profile_log_name  ==> Profile option used to get directory location for debug
223 -- p_prod              ==> Product string (IGC, GMS, etc.)
224 -- p_sub_comp          ==> Sub Component name to the product (CC, CBC, etc.)
225 -- p_filename_val      ==> If NULL then build in initialize otherwise use the callers value.
226 -- x_Return_Status     ==> Status of procedure returned to caller
227 
228 PROCEDURE Put_Debug_Msg (
229    p_debug_message        IN VARCHAR2,
230    p_profile_log_name     IN VARCHAR2,
231    p_prod                 IN VARCHAR2,
232    p_sub_comp             IN VARCHAR2,
233    p_filename_val         IN VARCHAR2 := NULL,
234    x_Return_Status       OUT NOCOPY VARCHAR2
235 ) IS
236 
237    l_dir_loc        VARCHAR2(255);
238    l_filename       VARCHAR2(255);
239    l_file_ptr       UTL_FILE.FILE_TYPE;
240    l_Return_Status  VARCHAR2(1);
241    l_debug_mode     BOOLEAN;
242 
243    l_api_name       CONSTANT VARCHAR2(30)   := 'Put_Debug_Msg';
244 
245 BEGIN
246 
247    x_return_status := FND_API.G_RET_STS_SUCCESS;
248 
249 -- -----------------------------------------------------------------------
250 -- Make sure that Debug is actually turned on from the call to the main
251 -- procedure and that there is a designated directory path for the file.
252 -- Commenting the IF as calling procedures should check and then make
253 -- a call to this procedure.19 Nov 2002
254 -- -----------------------------------------------------------------------
255 --   IF (g_debug_mode) THEN
256 
257 -- -----------------------------------------------------------------------
258 -- Ensure that there is content to the message that is to be placed into
259 -- the Debug file.
260 -- -----------------------------------------------------------------------
261       IF (p_debug_message IS NOT NULL) THEN
262 
263 -- -----------------------------------------------------------------------
264 -- Make sure that the initialize routine has been called.  The file should
265 -- be open, file name build and it is not null.  If either of these cases
266 -- is TRUE then the Initialize routine should be called.
267 -- -----------------------------------------------------------------------
268          IF ( ( NOT UTL_FILE.IS_OPEN (g_file_ptr) ) OR
269               ( g_filename IS NULL ) OR
270               ( g_dirpath  IS NULL )) THEN
271 
272             Initialize_Debug (p_profile_name  => p_profile_log_name,
273                               p_product       => p_prod,
274                               p_sub_component => p_sub_comp,
275                               p_filename_value => p_filename_val,
276                               x_Return_Status => l_return_status
277                              );
278 
279             IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
280                RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
281             END IF;
282 
283          END IF;
284 
285 -- -----------------------------------------------------------------------
286 -- Output Debug message to file and flush the output.
287 -- -----------------------------------------------------------------------
288             UTL_FILE.PUT_LINE ( g_file_ptr, p_debug_message );
289             UTL_FILE.FFLUSH ( g_file_ptr );
290 
291       END IF;
292 
293  --  END IF;
294 
295    RETURN;
296 
297 -- ----------------------------------------------------------------------
298 -- Exception section for the Put_Debug_Msg procedure.
299 -- ----------------------------------------------------------------------
300 EXCEPTION
301   WHEN UTL_FILE.INVALID_PATH THEN
302       x_return_status := FND_API.G_RET_STS_ERROR;
303       --g_debug_mode := FALSE;
304       IGC_MSGS_PKG.add_message (p_appname => 'IGC',
305                                 p_msgname => 'IGC_DEBUG_INVALID_PATH'
306                                );
307       RETURN;
308 
309    WHEN UTL_FILE.WRITE_ERROR THEN
310       x_return_status := FND_API.G_RET_STS_ERROR;
311       --g_debug_mode := FALSE;
312       IGC_MSGS_PKG.add_message (p_appname => 'IGC',
313                                 p_msgname => 'IGC_DEBUG_WRITE_ERROR'
314                                );
315       RETURN;
316 
317    WHEN UTL_FILE.INVALID_FILEHANDLE  THEN
318       x_return_status := FND_API.G_RET_STS_ERROR;
319       --g_debug_mode := FALSE;
320       IGC_MSGS_PKG.add_message (p_appname => 'IGC',
321                                 p_msgname => 'IGC_DEBUG_FILEHANDLE'
322                                );
323       RETURN;
324 
325    WHEN OTHERS THEN
326       x_return_status := FND_API.G_RET_STS_ERROR;
327       --g_debug_mode := FALSE;
328       IF (FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )) THEN
329          FND_MSG_PUB.Add_Exc_Msg ( g_pkg_name, l_api_name );
330       END IF;
331       RETURN ;
332 
333 END Put_Debug_Msg;
334 
335 
336 END IGC_MSGS_PKG;
337