Labeling columns dynamically (merged) [message #241144] |
Mon, 28 May 2007 08:10 |
jtc103
Messages: 19 Registered: May 2007
|
Junior Member |
|
|
I am trying to create labels for my generic columns by using a for loop but when I try to set the item property, I get the literal string instead of the value.
Here's my statement:
col_1 := 'A1000';
col_2 := 'A2000';
col_3 := 'B1000';
col_4 := 'B2000';
...so on
v_string1 := 'col_';
v_string2 := 'det_col_';
v_counter := 1;
FOR v_counter IN 1..29 LOOP
v_new_string := v_string1||v_counter;
SET_ITEM_PROPERTY(''||v_string2||v_counter||'', PROMPT_TEXT, v_new_string);
END LOOP;
Now the columns get named col1, col2, col3...etc instead of the value in col1, col2, col3 (A1000, A2000, A3000)...
How can I pass the column name and not the literal string value to the SET ITEM PROPERTY by passing a variable in the prompt text parameter?
|
|
|
|
|
LABELING COLUMNS DYNAMICALLY - MAYBE BETTER EXPLAINED... [message #241373 is a reply to message #241144] |
Tue, 29 May 2007 06:50 |
jtc103
Messages: 19 Registered: May 2007
|
Junior Member |
|
|
I have generic-named columns that I populate dynamically through FROM CLAUSE. I have a total of 29 generic columns named col1, col2, col3 and based on specific selection, the columns I actually access change (depending on which table I need to read).
Right now, I can label these columns by using SET ITEM PROPERTY. So right now I have 29 SET ITEM PROPERTY statements:
I have a few IF statements that assigns column names to my v_coln variables:
IF..A
v_col1 := 'A1000';
v_col2 := 'A2000';
v_col3 := 'A3000';
v_col4 := 'A4000';
v_col5 := 'A5000';
...
v_col29 := 'A29000';
END IF;
IF..B
v_col1 := 'B1000';
v_col2 := 'B2000';
v_col3 := 'B3000';
v_col4 := 'B4000';
v_col5 := 'B5000';
...
v_col29 := 'B29000';
END IF;
SET_ITEM_PROPERTY('blk_details.det_col1', PROMPT_TEXT, v_col1);
SET_ITEM_PROPERTY('blk_details.det_col2', PROMPT_TEXT, v_col2);
SET_ITEM_PROPERTY('blk_details.det_col3', PROMPT_TEXT, v_col3);
SET_ITEM_PROPERTY('blk_details.det_col4', PROMPT_TEXT, v_col4);
SET_ITEM_PROPERTY('blk_details.det_col5', PROMPT_TEXT, v_col5);
SET_ITEM_PROPERTY('blk_details.det_col6', PROMPT_TEXT, v_col6);
SET_ITEM_PROPERTY('blk_details.det_col7', PROMPT_TEXT, v_col7);
SET_ITEM_PROPERTY('blk_details.det_col8', PROMPT_TEXT, v_col8);
....
SET_ITEM_PROPERTY('blk_details.det_col29', PROMPT_TEXT, v_col29);
what I am trying to do is create a loop instead that will loop 29 times and print whatever is IN v_coln (where n is the column number).
I tried this:
v_counter INTEGER := 1;
v_string1 VARCHAR2(10) := 'v_col';
v_string2 VARCHAR2(20) := 'blk_details.det_col';
v_new_string VARCHAR2(30);
FOR v_counter IN 1..29 LOOP
v_new_string := v_string1||v_counter;
SET_ITEM_PROPERTY(''||v_string2||v_counter||'', PROMPT_TEXT, v_new_string);
END LOOP;
But that doesn't work. What my labels get named are: "v_col1", "v_col2", "v_col2"...etc...
What I really want is to name then dynamically the same as the actual column names, so, depending on their selection, it could be A1000, A2000, A3000....or B1000, B2000, B3000...
|
|
|
|
Re: Labeling columns dynamically (merged) [message #241593 is a reply to message #241144] |
Wed, 30 May 2007 02:20 |
imen_mr2004
Messages: 22 Registered: October 2006 Location: tunisia
|
Junior Member |
|
|
i will explain to u why u hav got this result:
v_string1 := 'col_'; is char
and
v_new_string := v_string1||v_counter;
so v_new_string will hav this value: 'col_1' whitch is also considered as to char and not a variable
|
|
|
Re: Labeling columns dynamically (merged) [message #241875 is a reply to message #241144] |
Wed, 30 May 2007 15:17 |
hemavb
Messages: 103 Registered: May 2007 Location: Dubai , UAE
|
Senior Member |
|
|
jtc103,
Your code:
v_counter INTEGER := 1;
v_string1 VARCHAR2(10) := 'v_col';
v_string2 VARCHAR2(20) := 'blk_details.det_col';
v_new_string VARCHAR2(30);
FOR v_counter IN 1..29 LOOP
v_new_string := v_string1||v_counter;
SET_ITEM_PROPERTY(''||v_string2||v_counter||'', PROMPT_TEXT, v_new_string);
END LOOP;
-----
end result is that the variable v_new_string stores V_COL1, V_COL2, V_COL3 and so on...as a result that is what gets assigned to your prompt/labels. It stores the name of the variable, not its value.
Before i suggest something i need some more info...
do you store the labels in a table or do you define them at runtime?
If you store them in a table it will be easier, if not then it may get a lil difficult.
Lemme know and i'll give you a solution.
|
|
|
Re: Labeling columns dynamically (merged) [message #241896 is a reply to message #241875] |
Wed, 30 May 2007 21:17 |
jtc103
Messages: 19 Registered: May 2007
|
Junior Member |
|
|
Hi hemavb,
Thanks for the reply. I store the values of v_col1-v_col29 through variables because I also use them as my item names (I use the FROM CLAUSE). Based on specific selections by user, my program then looks up specific view and populates the detail block (dynamically through the query data source name).
Thanks for the help.
|
|
|
|
|
Re: Labeling columns dynamically (merged) [message #280845 is a reply to message #241144] |
Thu, 15 November 2007 00:42 |
|
Declare
itm1 varchar2(20);
itm2 varchar2(20);
x number:=0;
y number:=0;
Begin
x := 5;
y := 1;
message(:blockco.item1);
message(:blockco.item1);
itm1 := 'blockco.item' || to_char(x);
itm2 := 'blockco.item' || to_char(y);
copy(name_in(itm1), itm2);
message(:blockco.item1);
message(:blockco.item1);
End;
If I can change dynamically the value, you can also do another thing using name_in function.
[Updated on: Thu, 15 November 2007 00:45] Report message to a moderator
|
|
|