cancel
Showing results for 
Search instead for 
Did you mean: 

hoe to Dynamically assign text to the lable

Former Member
0 Kudos

Hi Gurus,

I want assign text dynamically to the lable but it's giving run time error lable for property not set of the lable.

Please provide me the sample cod

Regards,

Rahul.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Thanks a lot nithya your inputs really helped a lot..!

Reagards,

Rahul

mohammed_anzys
Contributor
0 Kudos

Hi

As nithya pointed out , you should dynamically set the label text.An one import thing is that ..You should set the label for field.Else it will throw error.

Thanks

Anzy

Former Member
0 Kudos

Hi Rahul,

Have a context attribute 'TEXT' of string/char type that will hold the value of the label text. Bind this attribute to the text property of your label element. In the context itself, give a default value for the attribute, so that it will be set initially. Then, whenever you want to change the label text, write the following code in the event handler:

method onactionchange_label.

data: label_text type string,

lr_element type ref to if_wd_context_element.

label_text = 'New text'.

lr_element = wd_context->get_element( ).

lr_element->set_attribute(

exporting

name = 'TEXT'

value = label_text

).

end method.

You will get the error while compiling if the text property is left blank. If it is bound to the context, you will not get the error. For the above code, the context attribute TEXT is not under any node. It is directly defined in the context. If you have your attribute in a node, change accordingly using the code wizard.

Hope this helps. <b>Please award points if it solved your problem.</b>

Regards

Nithya

Former Member
0 Kudos

Hi Nithya,

The lable which i am trying to create will be created dynamically there will be the multiple lables for multiple input fields which would be determined based on the user selection so i think your solution will not work @ that time.

Please suggest another solution.

Regards,

Rahul

Former Member
0 Kudos

Hi Rahul,

If I understand you correctly, you will be creating the label element itself dynamically and not the label text alone.

If you want to create the label element, in your <b>wddomodifyview</b> method, do the following:

data: lr_label type ref to cl_wd_label,

lr_trans_container type ref to cl_wd_transparent_container.

lr_trans_container ?= view->get_root_element( ).

lr_label = cl_wd_label=>new_label( text = 'your text' ).

lr_trans_container->add_child( lr_label ).

The method get_root_element will return you a reference to the rootuielement container, if you want to place your label directly under the root. Else if you need it in a group or any other container, you need to get that reference and add child.

Like this, you can create any number of labels you want. In every label, there is a property "label_for". Set this to the input field IDs for which the labels have been created. Check the class cl_wd_label for the method to set this property.

Hope this satisfies your requirement. If you want anything else, please explain in a bit more detail.

Regards

Nithya