on 09-17-2009 10:41 AM
Hi,
I have created a node dynamically based on some fieldcatalog in one of the method in my webdynpro for Abap.
Now in another method i want to read the contents of that dynamically created node.
Can somebody help me in this regards pl.
HI,
When you have created the node there itself, you have to move it to some global variable. declare a vairable in component controller attributes. And use it where ever required.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Soumya,
Thats exactly what I was referring to. When you try to use any of the GET_STATIC* methods you would end up in an error saying that the respective attribute does not exist. You would have to repeatedly call the normal GET_ATTRIBUTE method for different attributes. Try put the calls to this method inside a loop & specify the index while trying to read the attribute.
Regards,
Uday
Hi,
FIELD-SYMBOLS :
<lt_table> TYPE STANDARD TABLE. " Field symbol for detail node
*wd_comp_controller->gt_data_table type ref to data.
* Get the node ref
lr_node = wd_comp_controller->lr_node.
* Assign the ref of table
IF wd_comp_controller->gt_data_table IS NOT INITIAL.
ASSIGN wd_comp_controller->gt_data_table->* TO <lt_table>.
ENDIF. "if wd_comp_controller->gt_data_table is not initial.
IF lr_node IS NOT INITIAL.
CALL METHOD lr_node->get_static_attributes_table
IMPORTING
table = <lt_table>.
Regards,
Lekha.
Edited by: Lekha on Sep 17, 2009 4:03 PM
Hi Lekha,
Here is my code.
METHOD1:
Next, validate which fields you will use as ALV columns *******
DATA: ls_component TYPE cl_abap_structdescr=>component,
lr_type TYPE REF TO cl_abap_datadescr,
lt_components TYPE cl_abap_structdescr=>component_table.
*in place of CHAR20, we need to place the data-element of the field to get
*the heading to the ALV grid columns i.e. lt_fieldcatlog-dd_roll
*(field for dataelement in fieldcatalog)
LOOP AT lt_fieldcatlog INTO ls_fieldcatlog.
lr_type ?= cl_abap_typedescr=>describe_by_name( p_name = 'CHAR20' ).
ls_component-name = ls_fieldcatlog-fieldname.
ls_component-type = lr_type .
APPEND ls_component TO lt_components.
ENDLOOP.
Next, create a new structure and assign it to a new dynamic context node *******
DATA: lr_root_info TYPE REF TO if_wd_context_node_info ,
lr_node_info TYPE REF TO if_wd_context_node_info,
lr_structdescr TYPE REF TO cl_abap_structdescr.
CALL METHOD cl_abap_structdescr=>create
EXPORTING
p_components = lt_components
RECEIVING
p_result = lr_structdescr.
Get context node info
lr_root_info = wd_context->get_node_info( ).
Generate new node with the dynamic structure
CALL METHOD lr_root_info->add_new_child_node
EXPORTING
name = 'LEGACY'
is_initialize_lead_selection = abap_false
static_element_rtti = lr_structdescr
is_static = abap_false
RECEIVING
child_node_info = lr_node_info.
get instance of new node
dyn_node = wd_context->get_child_node( name = 'LEGACY' ).
ASSIGN lt_legacy->* TO <tab>.
dyn_node->bind_table( <tab> ).
*instantiate alv component
DATA: l_ref_cmp_usage TYPE REF TO if_wd_component_usage.
l_ref_cmp_usage = wd_this->wd_cpuse_legacytable( ).
IF l_ref_cmp_usage->has_active_component( ) IS INITIAL.
l_ref_cmp_usage->create_component( ).
ENDIF.
last, GET reference to model *******
DATA: lo_interfacecontroller TYPE REF TO iwci_salv_wd_table.
lo_interfacecontroller = wd_this->wd_cpifc_legacytable( ).
lo_interfacecontroller->set_data( dyn_node ).
ENDIF.
METHOD2:
"Now create the internal table dynamically.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_fcatlog
IMPORTING
ep_table = lt_legacy.
ASSIGN lt_legacy->* to <fs_legacy>.
dyn_node = wd_context->get_child_node( name = 'LEGACY ' ).
dyn_node->get_static_attributes_table( IMPORTING table = <fs_legacy> ).
hi ,
I have also did the same reading in my earlier WD ABAP req .
reading dynamic node is not different , u do it in the same way as ordinary context nodes
DATA : lv_node3 type string value 'DYN'.
* get instance of new node
DATA: dyn_node3 TYPE REF TO if_wd_context_node.
dyn_node3 = wd_context->get_child_node( name = lv_node3 ).
* get element via lead selection
lo_el_cn_comments = dyn_node3->get_element( ).
* get single attribute
lo_el_cn_comments->get_attribute(
EXPORTING
name = 'COMMENTS'
IMPORTING
value = lv_comment ).
here 'DYN' is the name of the dynamic node I have created in yet anothe r view , do let me know if u need any assistance
regards,
amit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Soumya,
You can read the attributes of a dynamically created node using the GET_ATTRIBUTE method. You cannot use the GET_STATIC_ATTRIBUTES or GET_STATIC_ATTRIBUTES_REF or GET_STATIC_ATTRIBUTES_TABLE to fetch a number of attributes at a single shot as it would result in an error. You can use these methods to only read attributes which you have created statically (i.e. at design time).
Regards,
Uday
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Soumya
I guess if you write the same normal code that is used to read 'normal' non dynamic nodes, it should be fine.
like
"say `DATASOURCE` is the dynamically created node
wd_context->get_attribute( EXPORTING name = `DATASOURCE`
IMPORTING value = valule ).
Shouldn't throw any syntax error I believe.
Pushpraj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.