In Web Dynpro dynamic programming one of the basic requirements is to create context nodes dynamically. Here are a few code samples how it can be done.
CASE 1
If the attributes are only from one database structure then we can simply pass the structure to create the context node as shown below.
DATA: lr_rootnode_info TYPE REF TO if_wd_context_node_info,
lr_node_info TYPE REF TO if_wd_context_node_info,
lr_node TYPE REF TO if_wd_context_node.
lr_rootnode_info = wd_context->get_node_info( ).
CALL METHOD lr_rootnode_info->add_new_child_node
EXPORTING
static_element_type = 'SFLIGHT'
name = 'FLIGHT'
RECEIVING
child_node_info = lr_node_info.
lr_node = wd_context->get_child_node( name = 'FLIGHT' ).
The variable lr_node is used to set the context node with values.
In method ADD_NEW_CHILD_NODE, there are a few other parameters as well. They are used for the following purpose:
Parameter | Use | Associated Type | Default Value |
SUPPLY_METHOD | Mention the name of the Supply method to populate the context node attributes | String | |
SUPPLY_OBJECT | Instance of Supply Method | Object | |
DISPOSE_METHOD | Name of dispose method | String | |
DISPOSE_OBJECT | Instance of Dispose Method | Object | |
NAME | Name of the context node. This is a mandatory parameter. | String | |
IS_MANDATORY | If it is true there must be at least one entry. | ABAP_BOOL | ABAP_FALSE |
IS_MANDATORY_SELECTION | If it is true at least one entry must be selected. | ABAP_BOOL | ABAP_FALSE |
IS_MULTIPLE | If it is true the context node can contain more than one entry. | ABAP_BOOL | ABAP_TRUE |
IS_MULTIPLE_SELECTION | If it is true multiple entries can be selected. | ABAP_BOOL | ABAP_TRUE |
IS_SINGLETON | If it is true then the Node Only Exist for Lead Selection of Parent | ABAP_BOOL | ABAP_FALSE |
IS_INITIALIZE_LEAD_SELECTION | If it is true then Lead Selection Always Defined | ABAP_BOOL | ABAP_TRUE |
IS_STATIC | If it is true context node can’t be changed dynamically | ABAP_BOOL | ABAP_TRUE |
IS_RANGE_NODE | ABAP_BOOL |
Depending on the requirement this parameters are set accordingly.
CASE 2
Context node can be defined using random attribute structure also. For that we use the importing parameter ATTRIBUTES. Here is a sample code.
data:
lt_attributes type wdr_context_attr_info_map,
attribute like line of lt_attributes,
lr_node_info type ref to if_wd_context_node_info.
attribute-name = 'TEXT'.
attribute-type_name = 'STRING'.
insert attribute into table lt_attributes.
attribute-name = 'EXPANDED'.
attribute-type_name = 'WDY_BOOLEAN'.
insert attribute into table lt_attributes.
lr_node_info = wd_context->get_node_info( ).
lr_node_info->add_new_child_node(
supply_method = 'S_STATIC_NODE'
supply_object = me
name = 'STATIC_NODE'
is_mandatory = abap_false
is_mandatory_selection = abap_false
is_multiple = abap_true
is_multiple_selection = abap_true
is_singleton = abap_false
is_initialize_lead_selection = abap_false
is_static = abap_false
attributes = lt_attributes ).
Here, the supply method parameter is passed. We need to create method S_STATIC_NODE in the methods tab of the view of type Supply Function.
Another Example: Here unlike previous case the Type Name of the attributes are not maintained.
data: l_node_info type ref to if_wd_context_node_info,
l_attribute type wdr_context_attribute_info,
l_attributes type wdr_context_attr_info_map,
l_node type ref to if_wd_context_node.
l_attribute-name = 'INPUT'.
l_attribute-rtti ?= cl_abap_typedescr=>describe_by_name( 'STRING' ).
insert l_attribute into table l_attributes.
l_attribute-name = 'INPUT2'.
l_attribute-rtti ?= cl_abap_typedescr=>describe_by_name( 'SFLIGHT-CARRID' ).
insert l_attribute into table l_attributes.
l_node_info = wd_context->get_node_info( ).
l_node_info = l_node_info->add_new_child_node(
name = 'NEW'
is_multiple = abap_false
is_mandatory = abap_true
attributes = l_attributes ).
CASE 3
Apart from these two import parameters to specify the context node structure there is another import parameter to create context node called static_element_rtti. This parameter is used when context node attributes are determined at runtime. Here is a simple example:
data: node_info type ref to if_wd_context_node_info,
comp_tab type cl_abap_structdescr=>component_table,
struct_type type ref to cl_abap_structdescr.
comp like line of comp_tab.
* build a structure description from the list of single fields
comp-name = 'CARRID'.
comp-type ?= cl_abap_datadescr=>describe_by_name( 'S_CARR_ID' ).
append comp to comp_tab.
comp-name = 'CONNID'.
comp-type ?= cl_abap_datadescr=>describe_by_name( 'S_CONN_ID' ).
append comp to comp_tab.
* not this structure contains the fields "CONNID" and "CARRID"
struct_type = cl_abap_structdescr=>create( comp_tab ).
* now the nodeinfo is created
node_info = wd_context->get_node_info( ).
node_info = node_info->add_new_child_node(
name = 'MY_NODE'
is_mandatory = abap_true
is_multiple = abap_true
static_element_rtti = struct_type
is_static = abap_false
).
Few more examples to show how the parameter is populated:
Example 1
data:
lt_scarr type standard table of scar,
struct_type type ref to cl_abap_structdescr.
cl_salv_wd_test_data=>select_data_from_ddic(
exporting
ddic_table = 'SCARR'
changing
t_table = lt_scarr ).
struct_type ?= cl_abap_typedescr=>describe_by_data( ls_scarr ).
Example 2
data:
lr_locator type ref to cl_dpr_ui_log_locator,
lt_components_attr type abap_component_tab,
struct_type type ref to cl_abap_structdescr.
* Initialize
lr_locator = cl_dpr_ui_log_locator=>get_instance( ).
* Get ALV data structure
lt_components_attr = lr_locator->get_alv_structure( ).
struct_type = lr_locator->get_alv_structure_ref( lt_components_attr ).
There are many such examples. Keep exploring and keep learning. :smile:
Case4
Here we will create a context node where attributes are added dynamically
data:
lr_node_info type ref to if_wd_context_node_info,
attribute type wdr_context_attribute_info,
lr_parent_node_info type ref to if_wd_context_node_info,
lr_item_node_info type ref to if_wd_context_node_info.
lr_parent_node_info = wd_context->get_node_info( ).
lr_item_node_info = lr_parent_node_info->add_new_child_node( name = 'ITEM' is_static = abap_false ).
attribute-name = 'ITEM'.
attribute-type_name = 'STRING'.
lr_item_node_info->add_attribute( attribute ).
Here is a brief document on how context nodes can be created dynamically.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
9 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 |