Home » Developer & Programmer » Forms » Labeling columns dynamically (merged)
Labeling columns dynamically (merged) [message #241144] Mon, 28 May 2007 08:10 Go to next message
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?

Re: USING THE VALUE OF A STRING VARIABLE AS AN ITEM NAME INSTEAD OF GETTING THE LITERAL STRING VALUE [message #241210 is a reply to message #241144] Mon, 28 May 2007 20:05 Go to previous messageGo to next message
wency
Messages: 450
Registered: April 2006
Location: Philippines
Senior Member

Don't forget to put dot(.) between block name and item name, convert number to char when you concatenate it. This code works for me.
declare
  x varchar2(10);
  y varchar2(10);
  z varchar2(10);
  p number:=0;

begin

  x := 'clm_usr';
  y := 'iss_cd';
  z := 'iss_cdz' || to_char(p);


  SET_ITEM_PROPERTY(''||x|| '.' ||y||'', PROMPT_TEXT, z); 

end;
Re: USING THE VALUE OF A STRING VARIABLE AS AN ITEM NAME INSTEAD OF GETTING THE LITERAL STRING VALUE [message #241365 is a reply to message #241144] Tue, 29 May 2007 06:27 Go to previous messageGo to next message
jtc103
Messages: 19
Registered: May 2007
Junior Member
Hi Wency,

Thanks for replying. That's the same result I get. What would be the label that your sample code displays? Is it iss_cdz0? What I really want to get is the value stored IN iss_cdz0. Because in my code sample, instead of getting labels on what's stored in col1, col2 and col3, what I am getting is labels "col1", "col2" and "col3".
LABELING COLUMNS DYNAMICALLY - MAYBE BETTER EXPLAINED... [message #241373 is a reply to message #241144] Tue, 29 May 2007 06:50 Go to previous messageGo to next message
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 #241592 is a reply to message #241144] Wed, 30 May 2007 02:16 Go to previous messageGo to next message
imen_mr2004
Messages: 22
Registered: October 2006
Location: tunisia
Junior Member

try this code with the rest of ur code
v_new_string := v_string1||to_char(v_counter);
Re: Labeling columns dynamically (merged) [message #241593 is a reply to message #241144] Wed, 30 May 2007 02:20 Go to previous messageGo to next message
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 Go to previous messageGo to next message
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 Go to previous messageGo to next message
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 #241910 is a reply to message #241144] Thu, 31 May 2007 00:26 Go to previous messageGo to next message
wency
Messages: 450
Registered: April 2006
Location: Philippines
Senior Member

using name_in, copy, or default_value for global still do nothing
Re: Labeling columns dynamically (merged) [message #241957 is a reply to message #241144] Thu, 31 May 2007 03:44 Go to previous messageGo to next message
hemavb
Messages: 103
Registered: May 2007
Location: Dubai , UAE
Senior Member
Has your issue been solved yet?

If not just send me a copy of your existing form.. cause i still cant get how and what u do and what u wanna do.

[Updated on: Thu, 31 May 2007 03:52]

Report message to a moderator

Re: Labeling columns dynamically (merged) [message #280845 is a reply to message #241144] Thu, 15 November 2007 00:42 Go to previous message
wency
Messages: 450
Registered: April 2006
Location: Philippines
Senior Member

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

Previous Topic: Poblem In Call and Run Form
Next Topic: NO. of records
Goto Forum:
  


Current Time: Sun Nov 03 08:11:04 CST 2024