on 11-22-2007 2:47 PM
Hi Fellas,
Is there a way we can define a field-symbols as a class attribute ? My requirement is that i am dynamically constructing a structure at runtime in my model class and binding the component of this structure to my view fields. I am able to create the structure which is basically ref to cl_abap_structdescr and the problem is when i am binding to the model attribute, i need this to be a structure so that i can address the components as "//model/structure.component".
Please let me know how we can define a field-symbol as a class attribute.
Cheers,
Ram.
you can't have field symbol, but you achieve the same with below Type:
ROW_REF Instance Attribute Public Type Ref To DATA
Raja T
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Raja,
But how can we address the components (since at runtime i am assigning a structure) to this attribute. Through debugging, i could see that my required components are perfectly inside it but i am able to access them using '->' operator and not through '-'. In this case (i.e. if i want to address a class' attribute than a component of a structure), how can i bind the component to say my inputField's value
Is there any reserved operator like '.' (period) which we use in data binding (//model/dataref.attribute ??)
I feel again its back to square one...same issue what you were having
But certain, answer is there in your previous post itself, in the link which you refered: This is the code shippet..
<%
data: descriptor type ref to CL_ABAP_STRUCTDESCR.
descriptor ?= CL_ABAP_STRUCTDESCR=>describe_by_data( model->isflight ).
data: flddescr type DDFIELDS.
flddescr = descriptor->GET_DDIC_FIELD_LIST( ).
field-symbols: <wa_field> like line of flddescr.
data: label type ref to cl_htmlb_label.
data: input type ref to CL_HTMLB_INPUTFIELD.
data: binding_string type string,
label_string type string,
input_string type string.
"Loop through each field in the structure Definition
loop at flddescr assigning <Wa_field>.
clear label.
clear input.
concatenate '//model/isflight.'
<wa_field>-FIELDNAME
into binding_string.
create object input.
input->_value = binding_string.
input_string = input->IF_BSP_BEE~RENDER_TO_STRING( page_context ).
%>
<%= input_string %>
<b>*Reward each useful answer</b>
Raja T
Hi Raja,
So, my class attribute whose type is 'TYPE REF TO DATA' can actually be accessed as a structure during the runtime binding.
As in the example, the 'isflight' is the model attribute of mine which holds the dynamically created structure.
descriptor ?= CL_ABAP_STRUCTDESCR=>describe_by_data( model->isflight ).
So, you mean to say that on my view page it would be perfect if i follow the outlined procedure to extract the structure fields and bind them to my inputFields. Please correct me if i have got something wrong.
Thanks,
Ram.
Hi Ram,
Field-Symbol as class attribute is not possible. Your way to do this by REF TO DATA is the correct way for that.
By default data binding is only possible like this:
Simple field attribute
value=//<model>/<field name>
Structure attribute
value=//<model>/<structure name>.<field name>
Table attribute
value=//<model>/<table name>[<line index].<field name>
If you want to bind to your data reference you have to implement your own getter and setter methods. Read this <a href="http://help.sap.com/saphelp_nw70/helpdata/en/fb/fbb84c20df274aa52a0b0833769057/frameset.htm">http://help.sap.com/saphelp_nw70/helpdata/en/fb/fbb84c20df274aa52a0b0833769057/frameset.htm</a> for further information. In addition to that, you have to implement your own GET_M_S_xxx to return metadata of your structure. By doing all this it is possible to implement a completely dynamic data binding. In the view it looks like the regular Structure attribute: value=//<model>/<data-ref name>.<field name>
Regards,
Thilo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Thilo,
Thanks for your reply. I could understand that i cannot directly refer my dynamic class attribute and instead use the 'set' & 'get' methods. Instead, i could immediately see that having an Internal Table as a class attribute and filling it up during Model Initialization stage could solve my requirement. (//model/table[index].value). So, this approach came handy.
Thanks everyone,
Ram.
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.