Dynamic LOV
Dynamic LOV
http://balakaarthik.blogspot.com/2009/01/dynamic-record-group.html
Dynamic Record Group
LOV (List of Values)
LOV is nothing but a form item which is used to provide list of values to a text field.
Each LOV contains a Record Group which provides the data to the LOV
Record Group
A record groups contains the query which is used to populate the values to the LOV.
To alter a list of values(LOV) of a text field, we should change the query of the record group
which is attached to the corresponding LOV or we should create a new record group and attach
it to the existing LOV.
Note : We cant create a new LOV. But we can attach a exsiting LOV to a form field.
declare
rg_id RECORDGROUP ;
err number;
lv_id lov;
begin
rg_id:=find_group('LOV4'); -- LOV4 is the name of the existing LOV
if not id_null(rg_id) then
err:=populate_group_with_query(rg_id,
'select deptno from dept where dname=''SALES''');
end if;
lv_id:=find_lov('LOV4');
set_lov_property(lv_id,group_name,rg_id);
end;
declare
rg_id recordgroup;
pg_num number;
lv_id lov;
begin
rg_id:=find_group('MYGROUP'); -- MYGROUP is the Group Name
if id_null(rg_id) then
rg_id:=create_group_from_query('MYGROUP','SELECT 100 deptno FROM dual');
end if;
pg_num:=populate_group(rg_id);
lv_id:=find_lov('LOV4');
set_lov_property(lv_id,group_name,rg_id);
end;
Posted by Kaarthik
Labels: Apps Technical
No comments:
Post a Comment
http://shivakumarkura.blogspot.com/2012/08/dynamic-lov-in-oracle-forms-10g.html
AUG
30
dynamic lov in oracle forms 10g and changing record group at run
time with example
Form builder help .
Open up the property pallete of an LOV. Click on the record group property and press F1.
there you will find lots of code and example check once its usefull.
declare
Return_LOV Boolean;
BEGIN
if :ALERTBLCK.COUNTRY = 'india' THEN -- ALERTBLCK is a block COUNTRY is a text field
Return_LOV := SHOW_LOV('LOV45');
ELSE IF :ALERTBLCK.COUNTRY = 'us' THEN
Return_LOV := SHOW_LOV('LOV47');
ELSE
:ALERTBLCK.DEPARTMENTS := 'NOLOV' ; -- DEPARTMENTS is test field
END IF ;
end if ;
end;
------------------------------------------------------------------------------------------------------------
declare
rg_id RECORDGROUP ;
err number;
lv_id lov;
the_val VARCHAR2(50) ;
gc_id GroupColumn ;
the_Rowcount NUMBER ;
V_COUNT NUMBER ;
sel_row NUMBER;
begin
rg_id:=find_group('INDIALOV'); -- LOV4 is the name of the existing LOV
err:=populate_group_with_query(rg_id,
'select dept_name from pst_departments where branch_num in (
select pst_branch_no from pst_business_areas where county_name
='''||:ALERTBLCK.COUNTRY||''')');
:ALERTBLCK.AGE := err ;
end if;
end if ;
END IF ;
:ALERTBLCK.DEPARTMENTS := 'NO LOV';
------------------------------------------------------------------------------------------------------------
Declare
LB$Ok Boolean ;
LC$Lov Varchar2(30) := Get_Item_Property(:system.trigger_item, LOV_NAME) ;
Begin
If LC$Lov Is not null Then
LB$Ok := Show_Lov(LC$Lov);
If LB$Ok Then
-- get returned values --
:BL.TXT1 := :LOV.RETURN1 ;
End if ;
End if ;
End;
PROCEDURE Populate_LOV
(
PC$SQL_Order IN VARCHAR2,
PC$NumLOV IN VARCHAR2,
PC$Title IN VARCHAR2,
PC$TargetItem IN VARCHAR2 default null,
PB$Display IN BOOLEAN Default false
)
IS
Tableau PKG_COLLECT.TAB_VAR ;
LC$Req Varchar2(4000) ;
LN$Pos Pls_integer := 0 ;
LN$Width Pls_Integer;
rg_name VARCHAR2(40) := 'RG_LOV';
lv_name VARCHAR2(40) := 'LV_LOV';
rg_id RecordGroup;
errcode NUMBER;
LB$Ret Boolean ;
LN$Cpt Pls_integer ;
c number;
d number;
col_cnt integer;
rec_tab dbms_sql.desc_tab2;
col_num number;
BEGIN
-----------------------------
-- Verify if query is OK --
-----------------------------
--
rg_name := rg_name || PC$NumLOV ;
lv_name := lv_name || PC$NumLOV ;
Begin
c := dbms_sql.open_cursor;
LC$Req := Replace( PC$SQL_Order, ';', ',' ) ;
dbms_sql.parse(c,LC$Req, 1);
d := dbms_sql.execute(c);
Exception
When others Then
dbms_sql.close_cursor(c);
Set_Alert_Property( 'AL_ERREUR', TITLE, 'Query control' ) ;
Set_Alert_Property( 'AL_ERREUR', ALERT_MESSAGE_TEXT, 'Incorrect query' ) ;
LN$Cpt := Show_Alert( 'AL_ERREUR' ) ;
Raise form_trigger_failure ;
End ;
dbms_sql.describe_columns2(c, col_cnt, rec_tab);
dbms_sql.close_cursor(c);
-- Controle of columns --
LB$Ret := TRUE ;
For i IN rec_tab.first .. rec_tab.last Loop
If rec_tab(i).col_type IN (8,23,24,113,114) Then
Set_Alert_Property( 'AL_ERREUR', TITLE, 'Query control' ) ;
Set_Alert_Property( 'AL_ERREUR', ALERT_MESSAGE_TEXT, rec_tab(i).col_name || ' ' || 'Type
not allowed' ) ;
LN$Cpt := Show_Alert( 'AL_ERREUR' ) ;
LB$Ret := FALSE ;
End if ;
End loop ;
If not LB$Ret Then
Raise form_trigger_failure ;
End if ;
If col_cnt < 1 or col_cnt > 9 Then
Set_Alert_Property( 'AL_ERREUR', TITLE, 'Query control' ) ;
Set_Alert_Property( 'AL_ERREUR', ALERT_MESSAGE_TEXT, 'Column number must be
between 1 and 9' ) ;
LN$Cpt := Show_Alert( 'AL_ERREUR' ) ;
Raise form_trigger_failure ;
End if ;
-- Test of query --
rg_id := Find_Group( rg_name );
IF Not Id_Null(rg_id) THEN
Delete_group( rg_id ) ;
End if;
Begin
rg_id := Create_Group_From_Query( rg_name, LC$Req ) ;
errcode := Populate_Group( rg_id );
Exception
When others Then
Set_Alert_Property( 'AL_ERREUR', TITLE, 'Query failure' ) ;
Set_Alert_Property( 'AL_ERREUR', ALERT_MESSAGE_TEXT, LC$Req ) ;
LN$Pos := Show_Alert( 'AL_ERREUR' ) ;
Raise form_trigger_failure ;
End ;
If Errcode <> 0 Then
Set_Alert_Property( 'AL_ERREUR', TITLE, 'Query failure' ) ;
Set_Alert_Property( 'AL_ERREUR', ALERT_MESSAGE_TEXT, LC$Req ) ;
LN$Pos := Show_Alert( 'AL_ERREUR' ) ;
Raise form_trigger_failure ;
End if ;
----------------------------
-- Display of control LOV --
----------------------------
Set_Lov_Property( lv_name, GROUP_NAME, rg_name ) ;
Set_Lov_Property( lv_name, TITLE, PC$Title ) ;
-- Update title and column width --
For i IN rec_tab.first..rec_tab.last Loop
-- Title --
Set_Lov_Column_Property( lv_name, i, TITLE, rec_tab(i).col_name ) ;
-- Width --
LN$Pos := 30 ;
If rec_tab(i).col_type IN (1,96) Then
If rec_tab(i).col_max_len > 30 Then
LN$Pos := 30 ;
Else
LN$Pos := rec_tab(i).col_max_len ;
End if ;
Elsif rec_tab(i).col_type = 2 Then
If rec_tab(i).col_precision = 0 Then
LN$Pos := 10 ;
Else
LN$Pos := rec_tab(i).col_precision ;
End if ;
Elsif rec_tab(i).col_type = 12 Then
LN$Pos := 12 ;
Elsif rec_tab(i).col_type IN (112,113) Then
LN$Pos := 30 ;
End if ;
LN$Pos := LN$Pos * 7 ;
LN$Width := LN$Width + LN$Pos;
Set_Lov_Column_Property( lv_name, i, WIDTH, LN$Pos ) ;
End loop ;
-- Display LOV ? --
If PB$Display Then
LB$Ret := Show_Lov(lov_name) ;
End if ;
END;
FUNCTION Build_Select_line
(
PC$Ligne IN Varchar2,
PC$Table IN OUT PKG_COLLECT.TAB_VAR
)RETURN Varchar2
IS
LN$Pos Pls_integer := 1 ;
LN$I Pls_integer := 1 ;
LC$Col Varchar2(256) ;
LC$Ligne Varchar2(4000) := PC$Ligne ;
LC$Retour Varchar2(4000) ;
LC$End Varchar2(4000);
LN$Deb Pls_integer ;
BEGIN
LN$Pos :=Instr( Upper(LC$Ligne), 'SELECT' ) ;
If LN$Pos > 0 Then
LC$Ligne := Substr( LC$Ligne, LN$Pos +7, 4000 ) ;
End if ;
LN$Pos :=Instr( Upper(LC$Ligne), 'FROM' ) ;
If LN$Pos > 0 Then
LC$End := Substr( LC$Ligne, LN$Pos, 4000 ) ;
LC$Ligne := Trim( Substr( LC$Ligne, 1, LN$Pos - 1 ) ) ;
End if ;
Loop
LN$Pos := Instr( LC$Ligne, ',' ) ;
Exit when LN$Pos = 0 ;
LC$Col := Substr( LC$Ligne, 1, LN$Pos - 1 ) ;
-- Suppression of alias --
LN$Deb := Instr( LC$Col, '"' ) ;
If LN$Deb > 0 Then
LC$Col := Substr( LC$Col, 1, LN$Deb - 1 ) ;
End if ;
-- Add column to collection --
PC$Table(LN$I) := Trim( LC$Col ) ;
-- Last column --
If LC$Ligne is not null Then
LC$Col := LC$Ligne ;
-- Suppression of alias --
LN$Deb := Instr( LC$Col, '"' ) ;
If LN$Deb > 0 Then
LC$Col := Substr( LC$Col, 1, LN$Deb - 1 ) ;
End if ;
-- Add column to collection --
PC$Table(LN$I) := Trim( LC$Col ) ;
END;
------------------------------------------------------------------------------------------------------------
Adding a list elements at run time
--set serverout on ;
declare
cursor cur1 is select dept_name from pst_departments where branch_num in (
select pst_branch_no from pst_business_areas where county_name =:ALERTBLCK.COUNTRY) ;
var pst_departments%rowtype ;
i number :=1 ;
BEGIN
loop
Add_List_Element('LISTITEM', i, var.dept_name, var.dept_name);
i := i+1;
-- dbms_output.put_line(var.dept_name);
end loop ;
-- END;
------------------------------------------------------------------------------------------------------------
http://docs.oracle.com/html/B10602_01/index.htm
http://balakaarthik.blogspot.com/2009/01/dynamic-record-group.html
http://dbdeveloper.narod.ru/97521f.html
http://fdtool.free.fr/articles/index_en/
View comments
1.
Regards
Sridevi Koduru (Senior Oracle Apps Trainer Oracleappstechnical.com)
LinkedIn profile - https://in.linkedin.com/in/sridevi-koduru-9b876a8b
Please Contact for One to One Online Training on Oracle Apps Technical, Financials, SCM, SQL, PL/SQL,
D2K at [email protected] | +91 - 9581017828.
Reply