1 PACKAGE BODY fnd_flex_descval AS
2 /* $Header: AFFFDVLB.pls 120.2.12010000.1 2008/07/25 14:13:56 appldev ship $ */
3
4 --
5 -- PRIVATE CONSTANTS
6 --
7
8 --
9 -- PRIVATE FUNCTIONS
10 --
11
12 FUNCTION init_all(p_resp_appl_id IN NUMBER,
13 p_resp_id IN NUMBER,
14 p_user_id IN NUMBER,
15 x_resp_appl_id OUT nocopy NUMBER,
16 x_resp_id OUT nocopy NUMBER,
17 x_user_id OUT nocopy NUMBER)
18 RETURN BOOLEAN;
19
20 PROCEDURE clear_all_but_error;
21
22 PROCEDURE set_stati(v_stat IN NUMBER);
23
24 FUNCTION return_status
25 RETURN BOOLEAN;
26
27 PROCEDURE add_column_value(column_name IN VARCHAR2,
28 column_value IN VARCHAR2,
29 column_type IN VARCHAR2);
30
31 FUNCTION check_api_mode(values_or_ids IN VARCHAR2)
32 RETURN VARCHAR2;
33
34 FUNCTION get_default_context(p_application_short_name IN VARCHAR2,
35 p_descriptive_flexfield_name IN VARCHAR2)
36 RETURN VARCHAR2;
37
38
39 /* ------------------------------------------------------------------------ */
40 /* The following functions use ROWID and so were not released. The */
41 /* FND_FLEX_SERVER4.descval_engine() supports this functionality and was */
42 /* tested, but these cover functions were not. */
43 /* ------------------------------------------------------------------------ */
44
45 /* ------------------------------------------------------------------------ */
46 /* LOAD_DESC(): */
47 /* Retrieves the descriptive flexfield information in an existing row */
48 /* specified by row_id. If data_field is not null, the descriptive */
49 /* flexfield data is read from that column rather than the individual */
50 /* segment columns. If interface_table is not null, the row is */
51 /* retrieved from that table rather than the table upon which the */
52 /* descriptive flexfield is defined. Note that it is an error if the */
53 /* interface table does not contain segment and context value columns */
54 /* of the same names as those in the table upon which the descriptive */
55 /* flexfield is defined. Also note it is an error if the specified */
56 /* row does not exist, or if the specified data column does not exist */
57 /* in the appropriate table. */
58 /* */
59 /* Load_desc() is designed to retrieve existing valid data. It does */
60 /* not return an error for values that are disabled, expired, or not */
61 /* allowed to be seen by the current user due to value security rules. */
62 /* */
63 /* Returns TRUE if all segments of the descriptive flexfield are */
64 /* valid. Otherwise returns FALSE and sets the validation status */
65 /* codes to indicate the detailed nature of the error. */
66 /* If this function returns TRUE, the segment information for the */
67 /* most recently validated flexfield can be retrieved using the data */
68 /* retrieval functions. If the function returns FALSE, the segment */
69 /* data will be null, but the error message can be read. */
70 /* ------------------------------------------------------------------------ */
71
72 FUNCTION load_desc(appl_short_name IN VARCHAR2,
73 desc_flex_name IN VARCHAR2,
74 row_id IN ROWID,
75 data_field IN VARCHAR2 DEFAULT NULL,
76 interface_table IN VARCHAR2 DEFAULT NULL)
77 RETURN BOOLEAN;
78
79
80 /* ------------------------------------------------------------------------ */
81 /* CHECK_DESC(): */
82 /* Checks that the descriptive flexfield information in an existing */
83 /* row is valid. This function is designed to be used to verify that */
84 /* newly inserted descriptive flexfield information is correct. It */
85 /* will indicate an error if any of the values are invalid, disabled, */
86 /* expired or not available for the current user because of value */
87 /* security rules. */
88 /* */
89 /* Returns TRUE if all segments of the descriptive flexfield are */
90 /* valid. otherwise returns FALSE and sets the validation status */
91 /* codes to indicate the detailed nature of the error. */
92 /* If this function returns TRUE, the segment information for the */
93 /* most recently validated flexfield can be retrieved using the data */
94 /* retrieval functions. If the function returns FALSE, the segment */
95 /* data will be null, but the error message can be read. */
96 /* */
97 /* ARGUMENTS: */
98 /* =========== */
99 /* The descriptive flexfield is identified by appl_short_name and */
100 /* desc_flex_name. Row_id specifies the row that is to be checked. */
101 /* Ordinarily the row is in the table upon which the descriptive */
102 /* flexfield is defined. If data_field is not null, the descriptive */
103 /* flexfield information in the form of concatenated segment ids is */
104 /* read from that column rather than from the individual segment */
105 /* columns. If interface_table is not null, the row is retrieved from */
106 /* that table rather than from the table upon which the descriptive */
107 /* flexfield is defined. This allows the use of this function with */
108 /* an interface table where the descriptive flexfield information is */
109 /* validated on the interface table before being inserted into the */
110 /* production table. The interface table must contain segment and */
111 /* context value columns with the same names as those in the table */
112 /* upon which the descriptive flexfield is defined. Also note it is */
113 /* an error if the specified row does not exist, or if the specified */
114 /* data column does not exist in the appropriate table. */
115 /* The validation date is used to check whether the values are */
116 /* active for that date. The resp_appl_id, and resp_id arguments */
117 /* identify the user for the purposes of value security rules. */
118 /* If these are not specified the values from FND_GLOBAL will */
119 /* be used. The FND_GLOBAL values are set by the form or by */
120 /* the concurrent program that starts this database session. */
121 /* The enabled_activation flag is for internal use only. It is not */
122 /* supported outside of the Application Object Library. */
123 /* ------------------------------------------------------------------------ */
124
125 FUNCTION check_desc(appl_short_name IN VARCHAR2,
126 desc_flex_name IN VARCHAR2,
127 row_id IN ROWID,
128 data_field IN VARCHAR2 DEFAULT NULL,
129 interface_table IN VARCHAR2 DEFAULT NULL,
130 validation_date IN DATE DEFAULT SYSDATE,
131 enabled_activation IN BOOLEAN DEFAULT TRUE,
132 resp_appl_id IN NUMBER DEFAULT NULL,
133 resp_id IN NUMBER DEFAULT NULL)
134 RETURN BOOLEAN;
135
136 /* ------------------------------------------------------------------------ */
137
138 -- PRIVATE GLOBAL VARIABLES
139 --
140
141 nvalidated NUMBER;
142 value_vals FND_FLEX_SERVER1.ValueArray;
143 value_svals FND_FLEX_SERVER1.ValueArray;
144 value_ids FND_FLEX_SERVER1.ValueIdArray;
145 value_descs FND_FLEX_SERVER1.ValueDescArray;
146 value_desclens FND_FLEX_SERVER1.NumberArray;
147 seg_cols FND_FLEX_SERVER1.TabColArray;
148 seg_coltypes FND_FLEX_SERVER1.CharArray;
149 segtypes FND_FLEX_SERVER1.SegFormats;
150 disp_segs FND_FLEX_SERVER1.DisplayedSegs;
151 delim VARCHAR2(1);
152 err_segn NUMBER;
153 err_msg VARCHAR2(2000);
154 err_text VARCHAR2(2000);
155 segcodes VARCHAR2(31);
156
157 -- Return statuses
158 --
159 sta_valid BOOLEAN;
160 sta_secured BOOLEAN;
161 sta_value_err BOOLEAN;
162 sta_unsupported_err BOOLEAN;
163 sta_serious_err BOOLEAN;
164
165 -- Segment column names and values input
166 --
167 g_coldef FND_FLEX_SERVER1.ColumnDefinitions;
168
169 /* ----------------------------------------------------------------------- */
170 /* THIS PACKAGE IS STILL UNDER DEVELOPMENT */
171 /* The functions herein are not be supported in any way and will */
172 /* change without notice. */
173 /* ----------------------------------------------------------------------- */
174
175 /* ------------------------------------------------------------------------ */
176 /* SEE PACKAGE SPECIFICATION FOR DESCRIPTION OF PUBLIC FUNCTIONS. */
177 /* ------------------------------------------------------------------------ */
178
179 FUNCTION load_desc(appl_short_name IN VARCHAR2,
180 desc_flex_name IN VARCHAR2,
181 row_id IN ROWID,
182 data_field IN VARCHAR2 DEFAULT NULL,
183 interface_table IN VARCHAR2 DEFAULT NULL)
184 RETURN BOOLEAN IS
185 resp_apid NUMBER;
186 uresp_id NUMBER;
187 userid NUMBER;
188 valid_stat NUMBER;
189
190 dummy_coldef FND_FLEX_SERVER1.ColumnDefinitions;
191
192 BEGIN
193
194 -- Initialize everything including all global variables and set user
195 -- Isvalid is initialized to FALSE, serious_error initialized to TRUE.
196 --
197 if(init_all(NULL, NULL, NULL, resp_apid, uresp_id, userid)) then
198 FND_FLEX_SERVER4.descval_engine(user_apid => resp_apid,
199 user_resp => uresp_id,
200 userid => userid,
201 flex_app_sname => appl_short_name,
202 desc_flex_name => desc_flex_name,
203 val_date => NULL,
204 invoking_mode => 'L',
205 allow_nulls => FALSE,
206 update_table => FALSE,
207 ignore_active => FALSE,
208 concat_segs => NULL,
209 vals_not_ids => FALSE,
210 use_column_def => FALSE,
211 column_def => dummy_coldef,
212 rowid_in => row_id,
213 alt_tbl_name => interface_table,
214 data_field_name => data_field,
215 nvalidated => nvalidated,
216 displayed_vals => value_vals,
217 stored_vals => value_svals,
218 segment_ids => value_ids,
219 descriptions => value_descs,
220 desc_lengths => value_desclens,
221 seg_colnames => seg_cols,
222 seg_coltypes => seg_coltypes,
223 segment_types => segtypes,
224 displayed_segs => disp_segs,
225 seg_delimiter => delim,
226 v_status => valid_stat,
227 seg_codes => segcodes,
228 err_segnum => err_segn);
229 set_stati(valid_stat);
230 end if;
231 return(return_status);
232
233 EXCEPTION
234 WHEN OTHERS then
235 FND_MESSAGE.set_name('FND', 'FLEX-SSV EXCEPTION');
236 FND_MESSAGE.set_token('MSG', 'load_desc() exception: ' || SQLERRM);
237 err_msg := FND_MESSAGE.get_encoded;
238 return(FALSE);
239
240 END load_desc;
241
242 /* ------------------------------------------------------------------------ */
243
244 FUNCTION check_desc(appl_short_name IN VARCHAR2,
245 desc_flex_name IN VARCHAR2,
246 row_id IN ROWID,
247 data_field IN VARCHAR2 DEFAULT NULL,
248 interface_table IN VARCHAR2 DEFAULT NULL,
249 validation_date IN DATE DEFAULT SYSDATE,
250 enabled_activation IN BOOLEAN DEFAULT TRUE,
251 resp_appl_id IN NUMBER DEFAULT NULL,
252 resp_id IN NUMBER DEFAULT NULL)
253 RETURN BOOLEAN IS
254 resp_apid NUMBER;
255 uresp_id NUMBER;
256 userid NUMBER;
257 valid_stat NUMBER;
258
259 dummy_coldef FND_FLEX_SERVER1.ColumnDefinitions;
260
261 BEGIN
262
263 -- Initialize everything including all global variables and set user
264 -- Isvalid is initialized to FALSE, serious_error initialized to TRUE.
265 --
266 if(init_all(resp_appl_id, resp_id, NULL,
267 resp_apid, uresp_id, userid)) then
268 FND_FLEX_SERVER4.descval_engine(user_apid => resp_apid,
269 user_resp => uresp_id,
270 userid => userid,
271 flex_app_sname => appl_short_name,
272 desc_flex_name => desc_flex_name,
273 val_date => validation_date,
274 invoking_mode => 'C',
275 allow_nulls => FALSE,
276 update_table => FALSE,
277 ignore_active => (not enabled_activation),
278 concat_segs => NULL,
279 vals_not_ids => FALSE,
280 use_column_def => FALSE,
281 column_def => dummy_coldef,
282 rowid_in => row_id,
283 alt_tbl_name => interface_table,
284 data_field_name => data_field,
285 nvalidated => nvalidated,
286 displayed_vals => value_vals,
287 stored_vals => value_svals,
288 segment_ids => value_ids,
289 descriptions => value_descs,
290 desc_lengths => value_desclens,
291 seg_colnames => seg_cols,
295 seg_delimiter => delim,
292 seg_coltypes => seg_coltypes,
293 segment_types => segtypes,
294 displayed_segs => disp_segs,
296 v_status => valid_stat,
297 seg_codes => segcodes,
298 err_segnum => err_segn);
299 set_stati(valid_stat);
300 end if;
301 return(return_status);
302
303 EXCEPTION
304 WHEN OTHERS then
305 FND_MESSAGE.set_name('FND', 'FLEX-SSV EXCEPTION');
306 FND_MESSAGE.set_token('MSG', 'check_desc() exception: ' || SQLERRM);
307 err_msg := FND_MESSAGE.get_encoded;
308 return(FALSE);
309
310 END check_desc;
311
312 /* ------------------------------------------------------------------------ */
313
314 FUNCTION val_desc(appl_short_name IN VARCHAR2,
315 desc_flex_name IN VARCHAR2,
316 concat_segments IN VARCHAR2,
317 values_or_ids IN VARCHAR2 DEFAULT 'I',
318 validation_date IN DATE DEFAULT SYSDATE,
319 enabled_activation IN BOOLEAN DEFAULT TRUE,
320 resp_appl_id IN NUMBER DEFAULT NULL,
321 resp_id IN NUMBER DEFAULT NULL)
322 RETURN BOOLEAN IS
323 resp_apid NUMBER;
324 uresp_id NUMBER;
325 userid NUMBER;
326 valid_stat NUMBER;
327
328 api_mode VARCHAR2(1);
329
330 dummy_coldef FND_FLEX_SERVER1.ColumnDefinitions;
331
332 BEGIN
333
334 api_mode := check_api_mode(values_or_ids);
335
336 -- Initialize everything including all global variables and set user
337 -- Isvalid is initialized to FALSE, serious_error initialized to TRUE.
338 --
339
340 if(init_all(resp_appl_id, resp_id, NULL,
341 resp_apid, uresp_id, userid)) then
342 FND_FLEX_SERVER4.descval_engine(user_apid => resp_apid,
343 user_resp => uresp_id,
344 userid => userid,
345 flex_app_sname => appl_short_name,
346 desc_flex_name => desc_flex_name,
347 val_date => validation_date,
348 invoking_mode => api_mode,
349 allow_nulls => FALSE,
350 update_table => FALSE,
351 ignore_active => (not enabled_activation),
352 concat_segs => concat_segments,
353 vals_not_ids => (values_or_ids = 'V'),
354 use_column_def => FALSE,
355 column_def => dummy_coldef,
356 rowid_in => NULL,
357 alt_tbl_name => NULL,
358 data_field_name => NULL,
359 nvalidated => nvalidated,
360 displayed_vals => value_vals,
361 stored_vals => value_svals,
362 segment_ids => value_ids,
363 descriptions => value_descs,
364 desc_lengths => value_desclens,
365 seg_colnames => seg_cols,
366 seg_coltypes => seg_coltypes,
367 segment_types => segtypes,
368 displayed_segs => disp_segs,
369 seg_delimiter => delim,
370 v_status => valid_stat,
371 seg_codes => segcodes,
372 err_segnum => err_segn);
373 set_stati(valid_stat);
374 end if;
375 return(return_status);
376
377 EXCEPTION
378 WHEN OTHERS then
379 FND_MESSAGE.set_name('FND', 'FLEX-SSV EXCEPTION');
380 FND_MESSAGE.set_token('MSG', 'val_desc() exception: ' || SQLERRM);
381 err_msg := FND_MESSAGE.get_encoded;
382 return(FALSE);
383
384 END val_desc;
385
386 /* ------------------------------------------------------------------------ */
387
388 FUNCTION validate_desccols(appl_short_name IN VARCHAR2,
389 desc_flex_name IN VARCHAR2,
390 values_or_ids IN VARCHAR2 DEFAULT 'I',
391 validation_date IN DATE DEFAULT SYSDATE,
392 enabled_activation IN BOOLEAN DEFAULT TRUE,
393 resp_appl_id IN NUMBER DEFAULT NULL,
394 resp_id IN NUMBER DEFAULT NULL)
395 RETURN BOOLEAN IS
396 resp_apid NUMBER;
397 uresp_id NUMBER;
398 userid NUMBER;
399 valid_stat NUMBER;
400 api_mode VARCHAR2(1);
401 l_default_context_value VARCHAR2(2000);
402
403 BEGIN
407 if (g_coldef.context_value is null) then
404
405 api_mode := check_api_mode(values_or_ids);
406
408 l_default_context_value := get_default_context(appl_short_name,
409 desc_flex_name);
410
411 g_coldef.context_value := SUBSTRB(l_default_context_value, 1, 30);
412
413 end if;
414
415 -- Initialize everything including all global variables and set user
416 -- Isvalid is initialized to FALSE, serious_error initialized to TRUE.
417 --
418 if(init_all(resp_appl_id, resp_id, NULL,
419 resp_apid, uresp_id, userid)) then
420
421 FND_FLEX_SERVER4.descval_engine(user_apid => resp_apid,
422 user_resp => uresp_id,
423 userid => userid,
424 flex_app_sname => appl_short_name,
425 desc_flex_name => desc_flex_name,
426 val_date => validation_date,
427 invoking_mode => api_mode,
428 allow_nulls => FALSE,
429 update_table => FALSE,
430 ignore_active => (not enabled_activation),
431 concat_segs => NULL,
432 vals_not_ids => (values_or_ids = 'V'),
433 use_column_def => TRUE,
434 column_def => g_coldef,
435 rowid_in => NULL,
436 alt_tbl_name => NULL,
437 data_field_name => NULL,
438 nvalidated => nvalidated,
439 displayed_vals => value_vals,
440 stored_vals => value_svals,
441 segment_ids => value_ids,
442 descriptions => value_descs,
443 desc_lengths => value_desclens,
444 seg_colnames => seg_cols,
445 seg_coltypes => seg_coltypes,
446 segment_types => segtypes,
447 displayed_segs => disp_segs,
448 seg_delimiter => delim,
449 v_status => valid_stat,
450 seg_codes => segcodes,
451 err_segnum => err_segn);
452 set_stati(valid_stat);
453
454 end if;
455 return(return_status);
456
457 EXCEPTION
458 WHEN OTHERS then
459 FND_MESSAGE.set_name('FND', 'FLEX-SSV EXCEPTION');
460 FND_MESSAGE.set_token('MSG', 'validate_desccols() exception: '||SQLERRM);
461 err_msg := FND_MESSAGE.get_encoded;
462 return(FALSE);
463
464 END validate_desccols;
465
466 /* ------------------------------------------------------------------------ */
467
468 PROCEDURE set_context_value(context_value IN VARCHAR2) IS
469 BEGIN
470 g_coldef.context_value := SUBSTRB(context_value, 1, 80);
471 g_coldef.context_value_set := TRUE;
472 END set_context_value;
473
474 /* ------------------------------------------------------------------------ */
475
476 PROCEDURE set_column_value(column_name IN VARCHAR2,
477 column_value IN VARCHAR2) IS
478 BEGIN
479 add_column_value(column_name, column_value, 'V');
480 END set_column_value;
481
482 /* ------------------------------------------------------------------------ */
483 /* Sets number column value converting the number to the character */
484 /* representation appropriate for flexfields. */
485 /* ------------------------------------------------------------------------ */
486
487 PROCEDURE set_column_value(column_name IN VARCHAR2,
488 column_value IN NUMBER) IS
489 BEGIN
490 add_column_value(column_name, to_char(column_value), 'N');
491 END set_column_value;
492
493 /* ------------------------------------------------------------------------ */
494 /* Sets date column value converting the date to the character */
495 /* representation appropriate for flexfields. */
496 /* ------------------------------------------------------------------------ */
497
498 PROCEDURE set_column_value(column_name IN VARCHAR2,
499 column_value IN DATE) IS
500 BEGIN
501 add_column_value(column_name,
502 to_char(column_value, FND_FLEX_SERVER1.DATETIME_FMT), 'D');
503 END set_column_value;
504
505 /* ------------------------------------------------------------------------ */
506 /* Clears all defined column values. Column values are also cleared */
507 /* after validation by val_desc() or validate_desccols(). */
508 /* ------------------------------------------------------------------------ */
509
510 PROCEDURE clear_column_values IS
511 BEGIN
512 FND_FLEX_SERVER4.init_coldef(g_coldef);
513 END clear_column_values;
514
518 /* related to the user not leaving enough room in destination */
515 /* ------------------------------------------------------------------------ */
516 /* Functions for getting more details about the most recently */
517 /* validated combination. These typically do not trap errors */
519 /* strings to store the result. */
520 /* ------------------------------------------------------------------------ */
521
522 FUNCTION is_valid RETURN BOOLEAN IS
523 BEGIN
524 return(sta_valid);
525 END is_valid;
526
527 FUNCTION is_secured RETURN BOOLEAN IS
528 BEGIN
529 return(sta_secured);
530 END is_secured;
531
532 FUNCTION value_error RETURN BOOLEAN IS
533 BEGIN
534 return(sta_value_err);
535 END value_error;
536
537 FUNCTION unsupported_error RETURN BOOLEAN IS
538 BEGIN
539 return(sta_unsupported_err);
540 END unsupported_error;
541
542 FUNCTION serious_error RETURN BOOLEAN IS
543 BEGIN
544 return(sta_serious_err);
545 END serious_error;
546
547 FUNCTION error_segment RETURN NUMBER IS
548 BEGIN
549 return(err_segn);
550 END error_segment;
551
552 FUNCTION error_message RETURN VARCHAR2 IS
553 BEGIN
554 if((err_text is null) and (err_msg is not null)) then
555 FND_MESSAGE.set_encoded(err_msg);
556 err_text := FND_MESSAGE.get;
557 end if;
558 return(err_text);
559 END error_message;
560
561 FUNCTION encoded_error_message RETURN VARCHAR2 IS
562 BEGIN
563 return(err_msg);
564 END encoded_error_message;
565
566
567 FUNCTION segment_delimiter RETURN VARCHAR2 IS
568 BEGIN
569 return(delim);
570 END segment_delimiter;
571
572
573 FUNCTION concatenated_values RETURN VARCHAR2 IS
574 BEGIN
575 IF (sta_valid) THEN
576 return(FND_FLEX_SERVER.concatenate_values(nvalidated, value_vals,
577 disp_segs, delim));
578 ELSE
579 raise_application_error
580 (-20001, ('Developer Error: DVL.concatenated_values should not ' ||
581 'be called if validation fails.'));
582 END IF;
583 END concatenated_values;
584
585
586 FUNCTION concatenated_ids RETURN VARCHAR2 IS
587 BEGIN
588 IF (sta_valid) THEN
589 return(FND_FLEX_SERVER.concatenate_ids(nvalidated, value_ids, delim));
590 ELSE
591 raise_application_error
592 (-20001, ('Developer Error: DVL.concatenated_ids should not ' ||
593 'be called if validation fails.'));
594 END IF;
595 END concatenated_ids;
596
597
598 FUNCTION concatenated_descriptions RETURN VARCHAR2 IS
599 BEGIN
600 IF (sta_valid) THEN
601 return(FND_FLEX_SERVER.concatenate_descriptions(nvalidated,
602 value_descs, disp_segs, value_desclens, delim));
603 ELSE
604 raise_application_error
605 (-20001, ('Developer Error: DVL.concatenated_descriptions should not '||
606 'be called if validation fails.'));
607 END IF;
608 END concatenated_descriptions;
609
610
611 FUNCTION segment_count RETURN NUMBER IS
612 BEGIN
613 return(nvalidated);
614 END segment_count;
615
616
617 FUNCTION segment_value(segnum IN NUMBER) RETURN VARCHAR2 IS
618 BEGIN
619 if(segnum between 1 and nvalidated) then
620 return(value_vals(segnum));
621 end if;
622 return(NULL);
623 END segment_value;
624
625
626 FUNCTION segment_id(segnum IN NUMBER) RETURN VARCHAR2 IS
627 BEGIN
628 if(segnum between 1 and nvalidated) then
629 return(value_ids(segnum));
630 end if;
631 return(NULL);
632 END segment_id;
633
634
635 FUNCTION segment_description(segnum IN NUMBER) RETURN VARCHAR2 IS
636 BEGIN
637 if(segnum between 1 and nvalidated) then
638 return(value_descs(segnum));
639 end if;
640 return(NULL);
641 END segment_description;
642
643
644 FUNCTION segment_concat_desc_length(segnum IN NUMBER) RETURN NUMBER IS
645 BEGIN
646 if(segnum between 1 and nvalidated) then
647 return(value_desclens(segnum));
648 end if;
649 return(0);
650 END segment_concat_desc_length;
651
652
653 FUNCTION segment_displayed(segnum IN NUMBER) RETURN BOOLEAN IS
654 BEGIN
655 if(segnum between 1 and disp_segs.n_segflags) then
656 return(disp_segs.segflags(segnum));
657 end if;
658 return(FALSE);
659 END segment_displayed;
660
661
662 FUNCTION segment_valid(segnum IN NUMBER) RETURN BOOLEAN IS
663 BEGIN
664 if((segcodes is not null) and (segnum between 1 and LENGTH(segcodes))) then
665 return(SUBSTR(segcodes, segnum, 1) = FND_FLEX_SERVER1.FF_VVALID);
666 end if;
667 return(FALSE);
668 END segment_valid;
669
670
671 FUNCTION segment_column_name(segnum IN NUMBER) RETURN VARCHAR2 IS
672 BEGIN
673 if(segnum between 1 and nvalidated) then
674 return(seg_cols(segnum));
675 end if;
676 return(NULL);
677 END segment_column_name;
678
679 -- Returns segment column type as 'VARCHAR2', 'NUMBER' or 'DATE'
680 -- or returns NULL if unknown type of segment index out of range.
681 --
685 if(segnum between 1 and nvalidated) then
682 FUNCTION segment_column_type(segnum IN NUMBER) RETURN VARCHAR2 IS
683 type_code VARCHAR2(1);
684 BEGIN
686 type_code := seg_coltypes(segnum);
687 if(type_code = 'V') then
688 return('VARCHAR2');
689 elsif(type_code = 'N') then
690 return('NUMBER');
691 elsif(type_code = 'D') then
692 return('DATE');
693 else
694 return(NULL);
695 end if;
696 end if;
697 return(NULL);
698 END segment_column_type;
699
700
701 /* ------------------------------------------------------------------------ */
702 /* PRIVATE FUNCTIONS */
703 /* ------------------------------------------------------------------------ */
704
705 /* ------------------------------------------------------------------------ */
706 /* Initializes global variables, status, and determines user. */
707 /* Returns TRUE on success or FALSE and sets error message on failure. */
708 /* ------------------------------------------------------------------------ */
709
710 FUNCTION init_all(p_resp_appl_id IN NUMBER,
711 p_resp_id IN NUMBER,
712 p_user_id IN NUMBER,
713 x_resp_appl_id OUT nocopy NUMBER,
714 x_resp_id OUT nocopy NUMBER,
715 x_user_id OUT nocopy NUMBER)
716 RETURN BOOLEAN
717 IS
718 BEGIN
719 --
720 -- Initialize messages, debugging, and number of sql strings
721 --
722 if(FND_FLEX_SERVER1.init_globals = FALSE) then
723 return(FALSE);
724 end if;
725
726 --
727 -- Default security settings, if null.
728 --
729 x_resp_appl_id := Nvl(p_resp_appl_id, fnd_global.resp_appl_id());
730 x_resp_id := Nvl(p_resp_id, fnd_global.resp_id());
731 x_user_id := Nvl(p_user_id, fnd_global.user_id());
732
733 --
734 -- Initialize status codes
735 --
736 sta_valid := FALSE;
737 sta_secured := FALSE;
738 sta_value_err := FALSE;
739 sta_unsupported_err := FALSE;
740 sta_serious_err := TRUE;
741
742
743 --
744 -- Initialize other globals
745 --
746 err_segn := NULL;
747 err_msg := NULL;
748 err_text := NULL;
749 clear_all_but_error;
750
751 return(TRUE);
752
753 EXCEPTION
754 WHEN OTHERS then
755 FND_MESSAGE.set_name('FND', 'FLEX-SSV EXCEPTION');
756 FND_MESSAGE.set_token('MSG','init_all() exception: ' || SQLERRM);
757 return(FALSE);
758 END init_all;
759
760 /* ------------------------------------------------------------------------ */
761 /* Clears all output variables except for the status codes and */
762 /* error messages. Does not clear input column definitions. */
763 /* ------------------------------------------------------------------------ */
764
765 PROCEDURE clear_all_but_error IS
766 BEGIN
767
768 -- Setting array counts to 0 initializes arrays
769 --
770 nvalidated := 0;
771 segtypes.nsegs := 0;
772 disp_segs.n_segflags := 0;
773 delim := NULL;
774 segcodes := NULL;
775
776 END clear_all_but_error;
777
778 /* ------------------------------------------------------------------------ */
779 /* Set status flags and clears input arguments. */
780 /* Secured also set if any segment is secured and there is some */
781 /* other error. */
782 /* ------------------------------------------------------------------------ */
783
784 PROCEDURE set_stati(v_stat IN NUMBER) IS
785 BEGIN
786 sta_valid := (v_stat = FND_FLEX_SERVER1.VV_VALID);
787 sta_secured := ((v_stat = FND_FLEX_SERVER1.VV_SECURED) or
788 (INSTR(segcodes, FND_FLEX_SERVER1.FF_VSECURED) > 0));
789 sta_value_err := (v_stat = FND_FLEX_SERVER1.VV_VALUES);
790 sta_unsupported_err := (v_stat = FND_FLEX_SERVER1.VV_UNSUPPORTED);
791 sta_serious_err := (v_stat = FND_FLEX_SERVER1.VV_ERROR);
792
793 -- Clear column definitions
794 --
795 FND_FLEX_SERVER4.init_coldef(g_coldef);
796
797 END set_stati;
798
799 /* ------------------------------------------------------------------------ */
800 /* Gets message and erase all but error if not valid. */
801 /* ------------------------------------------------------------------------ */
802
803 FUNCTION return_status RETURN BOOLEAN IS
804 BEGIN
805 if(not sta_valid) then
806 err_msg := FND_MESSAGE.get_encoded;
807 clear_all_but_error;
808 end if;
809 return(sta_valid);
810 END return_status;
811
812 /* ------------------------------------------------------------------------ */
813 /* Converts column type code to a name such as VARCHAR2 etc. */
814 /* ------------------------------------------------------------------------ */
815
816 -- FUNCTION column_type_name(type_code IN VARCHAR2) RETURN VARCHAR2 IS
817 -- BEGIN
818 -- if(type_code = 'V') then
819 -- return('VARCHAR2');
820 -- else if(type_code = 'C') then
821 -- return('CHAR');
822 -- else if(type_code = 'N') then
823 -- return('NUMBER');
824 -- else if(type_code = 'D') then
828 -- end if;
825 -- return('DATE');
826 -- else
827 -- return(NULL);
829 -- return(NULL);
830 -- END column_type_name;
831
832 /* ------------------------------------------------------------------------ */
833 /* Internal function for setting column value and data type. */
834 /* ------------------------------------------------------------------------ */
835
836 PROCEDURE add_column_value(column_name IN VARCHAR2,
837 column_value IN VARCHAR2,
838 column_type IN VARCHAR2) IS
839 n NUMBER;
840 ndefined NUMBER;
841 colname VARCHAR2(30);
842
843 BEGIN
844 -- Initialize column count if necessary
845 --
846 if(g_coldef.colvals.ncolumns is null) then
847 ndefined := 0;
848 else
849 ndefined := g_coldef.colvals.ncolumns;
850 end if;
851
852 -- Get the column name
853 --
854 colname := UPPER(SUBSTRB(column_name, 1, 30));
855
856 -- Redefine value if column already defined.
857 --
858 for i in 1..ndefined loop
859 if(g_coldef.colvals.column_names(i) = colname) then
860 n := i;
861 exit;
862 end if;
863 end loop;
864
865 -- If column not already defined, add a new one.
866 --
867 if(n is null) then
868 ndefined := ndefined + 1;
869 n := ndefined;
870 end if;
871
872 -- Set the column value
873 --
874 g_coldef.colvals.column_names(n) := colname;
875 g_coldef.colvals.column_values(n) := SUBSTRB(column_value, 1, 1000);
876 g_coldef.colvals.column_types(n) := SUBSTRB(column_type, 1, 1);
877 g_coldef.colvals.ncolumns := ndefined;
878
879 END add_column_value;
880
881 /* ------------------------------------------------------------------------ */
882 /* Added for Bug 2221725 - need to default IDs as well as Values. */
883 /* */
884 /* Previously we always passed invoking_mode => 'V' to the descval_engine. */
885 /* Now we will pass invoking_mode => api_mode which is set by this function */
886 /* based on the value for values_or_ids which is passed by the code calling */
887 /* this api. Checks for invoking mode = 'D' have been added to the engine */
888 /* in AFFFSV4B.pls and AFFFSV1B.pls. When invoking_mode = 'D' and the */
889 /* segment is null we will temporarily switch to "values" mode and get the */
890 /* default value. This will allow the user to retrieve the defaulted ID if */
891 /* descval_engine returns success. */
892 /* */
893 /* Note: no change had to be made to logic involving values_or_ids as */
894 /* we always pass vals_not_ids => (values_or_ids = 'V') to descval_engine, */
895 /* which means vals_not_ids will be FALSE if values_or_ids = 'I' or 'D'. */
896 /* ------------------------------------------------------------------------ */
897
898 FUNCTION check_api_mode(values_or_ids IN VARCHAR2)
899 RETURN VARCHAR2
900 IS
901 l_api_mode VARCHAR2(1);
902 BEGIN
903 IF values_or_ids = 'D' then
904 l_api_mode := 'D';
905 ELSE
906 l_api_mode := 'V';
907 END IF;
908
909 RETURN (l_api_mode);
910
911 END check_api_mode;
912
913 FUNCTION get_default_context(p_application_short_name IN VARCHAR2,
914 p_descriptive_flexfield_name IN VARCHAR2)
915 RETURN VARCHAR2
916 IS
917 l_default_context_value fnd_descriptive_flexs_vl.default_context_value%TYPE;
918 BEGIN
919 SELECT fdfv.default_context_value
920 INTO l_default_context_value
921 FROM fnd_application fa,
922 fnd_descriptive_flexs_vl fdfv
923 WHERE fa.application_short_name = p_application_short_name
924 AND fdfv.application_id = fa.application_id
925 AND fdfv.descriptive_flexfield_name = p_descriptive_flexfield_name;
926
927 RETURN (l_default_context_value);
928
929 EXCEPTION
930 WHEN OTHERS THEN
931 raise_application_error
932 (-20005, 'DVLB.get_default_context() failed. SQLERRM: ' || Sqlerrm,
933 TRUE);
934 END get_default_context;
935
936 END fnd_flex_descval;