on 05-17-2007 6:27 AM
Hi All,
I want to create nodes, its sub-nodes and its attribute dynamically. Actually I want to pass number of nodes to be created thru a select query. So node should be created dynamically and later I need to create subnodes also as per query.
So can anyone help? Urgent help would be appreciated.
Thanks alot for ur time!!!
Cheers,
Darshna.
Hi Darshna,
Please refer the WD component NET310_DYN_D1A and NET310_DYN_D1.
Best regards,
Suresh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Darshna,
Sample code:
DATA: lr_root_info TYPE REF TO if_wd_context_node_info,
lr_flights_info TYPE REF TO if_wd_context_node_info.
* get meta data info of root context node
lr_root_info = wd_context->get_node_info( ).
**********************************************************************************
* 1) Define node and all attributes in one step
**********************************************************************************
* create node with name 'FLIGHTS' of DDIC type SFIGHT
* this will also create attributes for all fields of structure SFLIGHT!
* IS_STATIC = ABAP_FALSE: This node can be deleted at runtime
* Cardinality: 1:1
* Selection Cardinality: 0:n
CALL METHOD lr_root_info->add_new_child_node
EXPORTING
STATIC_ELEMENT_TYPE = 'SFLIGHT'
name = 'FLIGHTS'
IS_MANDATORY = ABAP_TRUE
IS_MANDATORY_SELECTION = ABAP_FALSE
IS_MULTIPLE = ABAP_FALSE
IS_MULTIPLE_SELECTION = ABAP_TRUE
IS_SINGLETON = ABAP_TRUE
IS_INITIALIZE_LEAD_SELECTION = ABAP_TRUE
* STATIC_ELEMENT_RTTI =
IS_STATIC = ABAP_FALSE
receiving
child_node_info = lr_flights_info.
**-------------------- Another code*******************
DATA: lr_root_info TYPE REF TO if_wd_context_node_info,
lr_flights_info TYPE REF TO if_wd_context_node_info,
lr_bookings_info TYPE REF TO if_wd_context_node_info,
lv_attribute TYPE wdr_context_attribute_info.
* get meta data info of root context node
lr_root_info = wd_context->get_node_info( ).
**********************************************************************************
* 1) First define node then define attribute by attribute
**********************************************************************************
* create node with name 'FLIGHTS' (without attributes)
CALL METHOD lr_root_info->add_new_child_node
EXPORTING
name = 'FLIGHTS'
is_mandatory = abap_true
is_mandatory_selection = abap_false
is_multiple = abap_false
is_multiple_selection = abap_false
is_singleton = abap_true
is_initialize_lead_selection = abap_true
is_static = abap_false
RECEIVING
child_node_info = lr_flights_info.
* define attribute CARRID
lv_attribute-name = 'CARRID'.
lv_attribute-type_name = 'S_CARR_ID'.
lv_attribute-value_help_mode = '0'.
CALL METHOD lr_flights_info->add_attribute
EXPORTING
attribute_info = lv_attribute.
* define attribute CONNID
lv_attribute-name = 'CONNID'.
lv_attribute-type_name = 'S_CONN_ID'.
lv_attribute-value_help_mode = '0'.
CALL METHOD lr_flights_info->add_attribute
EXPORTING
attribute_info = lv_attribute.
* define attribute fldate
lv_attribute-name = 'FLDATE'.
lv_attribute-type_name = 'S_DATE'.
CALL METHOD lr_flights_info->add_attribute
EXPORTING
attribute_info = lv_attribute.
Best regards,
Suresh
Hi try this out. That will create node and attributes dynamically
*to create a dynamic node
DATA: node_info TYPE REF TO if_wd_context_node_info,
struct_type TYPE REF TO cl_abap_structdescr,
table_type TYPE REF TO cl_abap_tabledescr,
comp_tab TYPE cl_abap_structdescr=>component_table,
comp LIKE LINE OF comp_tab,
my_table TYPE REF TO data,
my_row TYPE REF TO data.
FIELD-SYMBOLS: <table> TYPE table,
<row> TYPE data,
<flight> TYPE sflight.
build a structure description from the list of single fields
comp-name = 'CARRID'.
comp-type ?= cl_abap_datadescr=>describe_by_name( 'S_CARRID' ).
APPEND comp TO comp_tab.
comp-name = 'CONNID'.
comp-type ?= cl_abap_datadescr=>describe_by_name( 'S_CONN_ID' ).
APPEND comp TO comp_tab.
struct_type = cl_abap_structdescr=>create( comp_tab ).
create node info
node_info = wd_context->get_node_info( ).
node_info = node_info->add_new_child_node(
name = 'DYN_NODE'
is_mandatory = abap_true
is_multiple = abap_true
static_element_rtti = struct_type
is_static = abap_false
).
fill new node;
DATA: lr_node TYPE REF TO if_wd_context_node,
lt_flight TYPE STANDARD TABLE OF sflight.
*
lr_node = wd_context->get_child_node( 'DYN_NODE' ).
SELECT * FROM sflight INTO TABLE lt_flight.
struct_type = node_info->get_static_attributes_type( ).
create tabledescripton
table_type = cl_abap_tabledescr=>create( p_line_type = struct_type ).
CREATE DATA my_table TYPE HANDLE table_type.
ASSIGN my_table->* TO <table>.
LOOP AT lt_flight ASSIGNING <flight>.
CREATE DATA my_row TYPE HANDLE struct_type.
ASSIGN my_row->* TO <row>.
MOVE-CORRESPONDING <flight> TO <row>.
APPEND <row> TO <table>.
ENDLOOP.
*bind the table
lr_node->bind_table( <table> ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.