DBA Data[Home] [Help]

PACKAGE BODY: APPS.PV_MSG_PUB

Source


1 PACKAGE BODY PV_MSG_PUB AS
2 /* $Header: pvxpmsgb.pls 115.7 2002/12/26 06:11:39 anubhavk ship $ */
3 
4 --  Constants used as tokens for unexpected error messages.
5 
6     G_PKG_NAME	CONSTANT    VARCHAR2(15):=  'PV_MSG_PUB';
7 
8 --  API message table type
9 --
10 --  	PL/SQL table of VARCHAR2(2000)
11 --	This is the datatype of the API message list
12 
13 TYPE Msg_Tbl_Type IS TABLE OF VARCHAR2(2000)
14  INDEX BY BINARY_INTEGER;
15 
16 --  Global message table variable.
17 --  this variable is global to the FND_MSG_PUB package only.
18 
19     G_msg_tbl	    		Msg_Tbl_Type;
20 
21 --  Global variable holding the message count.
22 
23     G_msg_count   		NUMBER      	:= 0;
24 
25 --  Index used by the Get function to keep track of the last fetched
26 --  message.
27 
28     G_msg_index			NUMBER		:= 0;
29 
30 --  Procedure	Initialize
31 --
32 --  Usage	Used by API callers and developers to intialize the
33 --		global message table.
34 --  Desc	Clears the G_msg_tbl and resets all its global
35 --		variables. Except for the message level threshold.
36 --
37 
38 PROCEDURE Initialize
39 IS
40 BEGIN
41 
42 G_msg_tbl.DELETE;
43 G_msg_count := 0;
44 G_msg_index := 0;
45 
46 END;
47 
48 --  FUNCTION	Count_Msg
49 --
50 --  Usage	Used by API callers and developers to find the count
51 --		of messages in the  message list.
52 --  Desc	Returns the value of G_msg_count
53 --
54 --  Parameters	None
55 --
56 --  Return	NUMBER
57 
58 FUNCTION    Count_Msg 	RETURN NUMBER
59 IS
60 BEGIN
61 
62     RETURN G_msg_Count;
63 
64 END Count_Msg;
65 
66 --  PROCEDURE	Count_And_Get
67 --
68 
69 PROCEDURE    Count_And_Get
70 (   p_encoded		    IN	VARCHAR2    := FND_API.G_TRUE	    ,
71     p_count		    OUT NOCOPY NUMBER				    ,
72     p_data		    OUT NOCOPY VARCHAR2
73 )
74 IS
75 l_msg_count	NUMBER;
76 
77 BEGIN
78 
79     l_msg_count :=  Count_Msg;
80 
81     IF l_msg_count > 0 THEN
82 
83 	FOR I IN 1..G_msg_tbl.COUNT LOOP
84 
85           p_data := p_data || ' ' || Get ( p_msg_index =>  I   ,
86 	                                     p_encoded   =>  p_encoded   );
87 
88           if length(p_data) > 1500 then
89              exit;
90           end if;
91 
92 	END LOOP;
93 
94 
95     END IF;
96 
97     p_count := l_msg_count ;
98 
99 END Count_And_Get;
100 
101 --  PROCEDURE 	Add
102 --
103 --  Usage	Used to add messages to the global message table.
104 --
105 --  Desc	Reads a message off the message dictionary stack and
106 --  	    	writes it in an encoded format to the global PL/SQL
107 --		message table.
108 --  	    	The message is appended at the bottom of the message
109 --    	    	table.
110 --
111 
112 PROCEDURE Add
113 IS
114 BEGIN
115 
116     --	Increment message count
117 
118     G_msg_count := G_msg_count + 1;
119 
120     --	Write message.
121 
122     G_msg_tbl(G_msg_count) := PV_MESSAGE.GET_ENCODED;
123 
124 END; -- Add
125 
126 --  PROCEDURE 	Delete_Msg
127 --
128 --  Usage	Used to delete a specific message from the message
129 --		list, or clear the whole message list.
130 --
131 --  Desc	If instructed to delete a specific message, the
132 --		message is removed from the message table and the
133 --		table is compressed by moving the messages coming
134 --		after the deleted messages up one entry in the message
135 --		table.
136 --		If there is no entry found the Delete procedure does
137 --		nothing, and  no exception is raised.
138 --		If delete is passed no parameters it deletes the whole
139 --		message table.
140 --
141 --  Prameters	p_msg_index	IN NUMBER := FND_API.G_MISS_NUM  Optional
142 --		    holds the index of the message to be deleted.
143 --
144 
145 PROCEDURE Delete_Msg
146 (   p_msg_index IN    NUMBER	:=  NULL
147 )
148 IS
149 l_msg_index	NUMBER;
150 BEGIN
151 
152     IF p_msg_index IS NULL THEN
153 
154 	--  Delete the whole table.
155 
156 	G_msg_tbl.DELETE;
157 	G_msg_count := 0;
158 	G_msg_index := 0;
159 
160     ELSE
161 
162 	--  Check if entry exists
163 
164 	IF G_msg_tbl.EXISTS(p_msg_index) THEN
165 
166 	    IF p_msg_index <= G_msg_count THEN
167 
168 		--  Move all messages up 1 entry.
169 
170 		FOR I IN p_msg_index..G_msg_count-1 LOOP
171 
172 		    G_msg_tbl( I ) := G_msg_tbl( I + 1 );
173 
174 		END LOOP;
175 
176 		--  Delete the last message table entry.
177 
178 		G_msg_tbl.DELETE(G_msg_count)	;
179 		G_msg_count := G_msg_count - 1	;
180 
181 	    END IF;
182 
183 	END IF;
184 
185     END IF;
186 
187 END Delete_Msg;
188 
189 --  PROCEDURE 	Get
190 --
191 
192 PROCEDURE    Get
193 (   p_msg_index	    IN	NUMBER	    := G_NEXT		,
194     p_encoded	    IN	VARCHAR2    := FND_API.G_TRUE	,
195     p_data	    OUT NOCOPY VARCHAR2			,
196     p_msg_index_out OUT NOCOPY NUMBER
197 )
198 IS
199 l_msg_index NUMBER := G_msg_index;
200 BEGIN
201 
202     IF p_msg_index = G_NEXT THEN
203 	G_msg_index := G_msg_index + 1;
204     ELSIF p_msg_index = G_FIRST THEN
205 	G_msg_index := 1;
206     ELSIF p_msg_index = G_PREVIOUS THEN
207 	G_msg_index := G_msg_index - 1;
208     ELSIF p_msg_index = G_LAST THEN
209 	G_msg_index := G_msg_count ;
210     ELSE
211 	G_msg_index := p_msg_index ;
212     END IF;
213 
214     IF FND_API.To_Boolean( p_encoded ) THEN
215 
216 	p_data := G_msg_tbl( G_msg_index );
217 
218     ELSE
219 
220         PV_MESSAGE.SET_ENCODED ( G_msg_tbl( G_msg_index ) );
221 	p_data := PV_MESSAGE.GET;
222 
223     END IF;
224 
225     p_msg_index_out	:=  G_msg_index		    ;
226 
227 EXCEPTION
228 
229     WHEN NO_DATA_FOUND THEN
230 
231 	--  No more messages, revert G_msg_index and return NULL;
232 
233 	G_msg_index := l_msg_index;
234 
235 	p_data		:=  NULL;
236 	p_msg_index_out	:=  NULL;
237 
238 END Get;
239 
240 --  FUNCTION	Get
241 --
242 
243 FUNCTION    Get
244 (   p_msg_index	    IN NUMBER	:= G_NEXT	    ,
245     p_encoded	    IN VARCHAR2	:= FND_API.G_TRUE
246 )
247 RETURN VARCHAR2
248 IS
249     l_data	    VARCHAR2(2000)  ;
250     l_msg_index_out NUMBER	    ;
251 BEGIN
252 
253     Get
254     (	p_msg_index	    ,
255 	p_encoded	    ,
256 	l_data		    ,
257 	l_msg_index_out
258     );
259 
260     RETURN l_data ;
261 
262 END Get;
263 
264 --  PROCEDURE	Reset
265 --
266 --  Usage	Used to reset the message table index used in reading
267 --		messages to point to the top of the message table or
268 --		the botom of the message table.
269 --
270 --  Desc	Sets G_msg_index to 0 or G_msg_count+1 depending on
271 --		the reset mode.
272 --
273 --  Parameters	p_mode	IN NUMBER := G_FIRST	Optional
274 --		    possible values are :
275 --			G_FIRST	resets index to the begining of msg tbl
276 --			G_LAST  resets index to the end of msg tbl
277 --
278 
279 PROCEDURE Reset ( p_mode    IN NUMBER := G_FIRST )
280 IS
281 l_procedure_name    CONSTANT VARCHAR2(15):='Reset';
282 BEGIN
283 
284     IF p_mode = G_FIRST THEN
285 
286 	G_msg_index := 0;
287 
288     ELSIF p_mode = G_LAST THEN
289 
290 	G_msg_index := G_msg_count + 1 ;
291 
292     ELSE
293 
294 	--  Invalid mode.
295 
296 	FND_MSG_PUB.Add_Exc_Msg
297     	(   p_pkg_name		=>  G_PKG_NAME			,
298     	    p_procedure_name	=>  l_procedure_name		,
299     	    p_error_text	=>  'Invalid p_mode: '||p_mode
300 	);
301 
302 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
303 
304     END IF;
305 
306 END Reset;
307 
308 --  FUNCTION 	Check_Msg_Level
309 --
310 --  Usage   	Used by API developers to check if the level of the
311 --  	    	message they want to write to the message table is
312 --  	    	higher or equal to the message level threshold or not.
313 --  	    	If the function returns TRUE the developer should go
314 --  	    	ahead and write the message to the message table else
315 --  	    	he/she should skip writing this message.
316 --  Desc    	Accepts a message level as input fetches the value of
317 --  	    	the message threshold profile option and compares it
318 --  	    	to the input level.
319 --  Return  	TRUE if the level is equal to or higher than the
320 --  	    	threshold. Otherwise, it returns FALSE.
321 --
322 
323 FUNCTION Check_Msg_Level
324 (   p_message_level IN NUMBER := G_MSG_LVL_SUCCESS
325 ) RETURN BOOLEAN
326 IS
327 BEGIN
328 
329     IF G_msg_level_threshold = FND_API.G_MISS_NUM THEN
330 
331     	--  Read the Profile option value.
332 
333     	G_msg_level_threshold :=
334     	TO_NUMBER ( FND_PROFILE.VALUE('FND_AS_MSG_LEVEL_THRESHOLD') );
335 
336     	IF G_msg_level_threshold IS NULL THEN
337 
338        	    G_msg_level_threshold := G_MSG_LVL_SUCCESS;
339 
340     	END IF;
341 
342     END IF;
343 
344     RETURN p_message_level >= G_msg_level_threshold ;
345 
346 END; -- Check_Msg_Level
347 
348 PROCEDURE Build_Exc_Msg
349 ( p_pkg_name	    IN VARCHAR2 :=FND_API.G_MISS_CHAR    ,
350   p_procedure_name  IN VARCHAR2 :=FND_API.G_MISS_CHAR    ,
351   p_error_text	    IN VARCHAR2 :=FND_API.G_MISS_CHAR
352 )
353 IS
354 l_error_text	VARCHAR2(240)	:=  p_error_text ;
355 BEGIN
356 
357     -- If p_error_text is missing use SQLERRM.
358 
359     IF p_error_text = FND_API.G_MISS_CHAR THEN
360 
361 	l_error_text := SUBSTR (SQLERRM , 1 , 240);
362 
363     END IF;
364 
365     PV_MESSAGE.SET_NAME('FND','FND_AS_UNEXPECTED_ERROR');
366 
367     IF p_pkg_name <> FND_API.G_MISS_CHAR THEN
368     	PV_MESSAGE.SET_TOKEN('PKG_NAME',p_pkg_name);
369     END IF;
370 
371     IF p_procedure_name <> FND_API.G_MISS_CHAR THEN
372     	PV_MESSAGE.SET_TOKEN('PROCEDURE_NAME',p_procedure_name);
373     END IF;
374 
375     IF l_error_text <> FND_API.G_MISS_CHAR THEN
376     	PV_MESSAGE.SET_TOKEN('ERROR_TEXT',l_error_text);
377     END IF;
378 
379 END; -- Build_Exc_Msg
380 
381 PROCEDURE Add_Exc_Msg
382 (   p_pkg_name		IN VARCHAR2 :=FND_API.G_MISS_CHAR   ,
383     p_procedure_name	IN VARCHAR2 :=FND_API.G_MISS_CHAR   ,
384     p_error_text	IN VARCHAR2 :=FND_API.G_MISS_CHAR
385 )
386 IS
387 BEGIN
388 
389     Build_Exc_Msg
390     (	p_pkg_name	    ,
391 	p_procedure_name    ,
392 	p_error_text
393     );
394 
395     Add;
396 
397 END Add_Exc_Msg ;
398 
399 --  PROCEDURE	Dump_Msg
400 --
401 
402 PROCEDURE    Dump_Msg
403 (   p_msg_index		IN NUMBER )
404 IS
405 BEGIN
406 
407     null;
408     -- dbms_output.put_line('Dumping Message number : '||p_msg_index);
409 
410     -- dbms_output.put_line('DATA = '||G_msg_tbl(p_msg_index));
411 
412 END Dump_Msg;
413 
414 --  PROCEDURE	Dump_List
415 --
416 
417 PROCEDURE    Dump_List
418 (   p_messages	IN BOOLEAN  :=	FALSE
419 )
420 IS
421 BEGIN
422 
423     -- dbms_output.put_line('Dumping Message List :');
424     -- dbms_output.put_line('G_msg_tbl.COUNT = '||G_msg_tbl.COUNT);
425     -- dbms_output.put_line('G_msg_count = '||G_msg_count);
426     -- dbms_output.put_line('G_msg_index = '||G_msg_index);
427 
428     IF p_messages THEN
429 
430 	FOR I IN 1..G_msg_tbl.COUNT LOOP
431 
432 	    dump_Msg (I);
433 
434 	END LOOP;
435 
436     END IF;
437 
438 END Dump_List;
439 
440 END PV_MSG_PUB ;