How to get data from a dynamic node in Webdynpro ABAP ?
Hi,
I have come across many scn threads which refer to “How to read / get data from a dynamic node” .
Here I would like to demonstrate, the steps to read the data from a node ( either static / dynamic node ) in Webdynpro ABAP.
I have divided the task into 3 methods
- GET_NODE_INFO( ) – Get node information from node name
- GET_NODE_DATA_TYPE( ) – Get node data type & attribute list by using node reference ( if_wd_context_node )
- GET_DATA( ) – Get data of any given node reference
All you need to do is … just create these 3 methods as is and start using for reading data from a given node ( either static node / dynamic node )
Now, let us look into the code of each method as below
GET_NODE_INFO( )
Parameters:
Parameter | Type | Ref To | Optional | Associated Type | Description |
---|---|---|---|---|---|
ID_NODE_NAME | Importing | STRING | Node Name | ||
IO_PARENT_NODE | Importing | Checked | Yes | IF_WD_CONTEXT_NODE | Parent Node Reference |
EO_NODE_INFO | Exporting | Checked | IF_WD_CONTEXT_NODE_INFO | Node info reference | |
ED_ERROR_MESSAGE | Exporting | STRING | error message | ||
EO_NODE | Exporting | Checked | IF_WD_CONTEXT_NODE | Node reference |
Logic:
GET_NODE_INFO |
---|
METHOD get_node_info . DATA: lo_node_info TYPE REF TO if_wd_context_node_info, TRY. “============================================= “============================================= eo_node_info = eo_node->get_node_info( ). CATCH cx_root INTO lx_root. ENDMETHOD. |
———————————————————-
GET_NODE_DATA_TYPE( )
Parameters:
Parameter | Type | Ref To | Optional | Associated Type | Description |
---|---|---|---|---|---|
IO_NODE_INFO | Importing | Checked | IF_WD_CONTEXT_NODE_INFO | Node info Reference | |
ED_ERROR_MESSAGE | Exporting | STRING | Error message | ||
EO_DATA | Exporting | Checked | DATA | Node data type ref | |
ET_FCAT | Exporting | LVC_T_FCAT | Attributes/fields list |
Logic:
GET_NODE_DATA_TYPE |
---|
METHOD GET_NODE_DATA_TYPE . DATA: IF io_node_info IS NOT BOUND. ENDIF. “============================================= LOOP AT lt_attr INTO ls_attr. ENDLOOP. cl_alv_table_create=>create_dynamic_table( IF sy-subrc <> 0. ” if node is multiple ( 0..n / 1..n ) return table type CREATE DATA eo_data LIKE LINE OF <lt_table>. ENDIF. |
———————————————————-
GET_DATA( )
Parameters:
Parameter | Type | Ref To | Optional | Associated Type | Description |
---|---|---|---|---|---|
IO_NODE | Importing | Checked | IF_WD_CONTEXT_NODE | Node reference | |
ED_ERROR_MESSAGE | Exporting | STRING | Error message | ||
EO_DATA | Exporting | Checked | DATA | Data | |
ET_FCAT | Exporting | LVC_T_FCAT | Fields |
Logic:
GET_DATA |
---|
METHOD GET_DATA . DATA lv_count TYPE i. FIELD-SYMBOLS: <lt_data> TYPE STANDARD TABLE, TRY. IF io_node IS NOT BOUND. ” Get node data type and attribute list wd_this->get_node_data_type( ” Return if any error or data type is not bound RETURN. ASSIGN eo_data->* TO <lt_data>. ” get the no. of elements available in context node ” do for each element ” collect index value ” Create a blank line and get the ref into <ls_dat> ” Loop over each field/attribute and get the data ASSIGN COMPONENT ls_fcat-fieldname IF <lv_value> IS ASSIGNED. io_node->get_attribute( ENDLOOP. ENDDO. CATCH cx_root INTO lx_root. |
—————————————————-
Example:
Scenario: Let us say we need to read data from a node “NODE_DYN”.
Example |
---|
————————– ” Data declarations DATA: lo_data TYPE REF TO data. FIELD-SYMBOLS: <lt_data> TYPE STANDARD TABLE.
” Get node information wd_this->get_node_info(
” Get the data from context node
wd_this->get_data( ” assign data into dynamic table
ASSIGN lo_data->* to <lt_data>. ————————– |
The internal table <lt_data> contains the data of our node “NODE_DYN”
Hope this helps for those looking for reading the data of any given node ( dynamicnode / static node )
I appreciate if any comments/suggestions from you 🙂
Hi Rama,
Nice document .
Hello Ram,
We were developing a highly dynamic WebDynpro application with dynamic tabstrips and Dynaminc table with columns in each tabstrip. Your document really helped me to solve a major problem with which I was stuck for quite a while.
I just wanted to thank you.
Kirubakar Ezhilmani
Hi Kirubakar,
I am glad that it was helpful to you 🙂 and I appreciate your gesture on feedback.
Thanks and all the very best.
Regards,
Rama
Hi Rama,
While creating the method get_node_info, it is throwing an error in the logic that
the field eo_node cant be change.
eo_node = lo_parent_node->get_child_node( name = lv_node_name ).
Please correct me if I am doing anything wrong here.
Thanks,
Puneet
i will try this ...nice doc u created