How to Create Dynamic Node with attribute
*----------------------------------------------------------------
* add node to context
*----------------------------------------------------------------
data:
LO_PARENT_NODE_INFO type ref to IF_WD_CONTEXT_NODE_INFO,
LO_CHILD_NODE_INFO type ref to IF_WD_CONTEXT_NODE_INFO,
LV_STRUCT_NAME type STRING,
LT_CHILD_NODE_MAP type WDR_CONTEXT_CHILD_INFO_MAP.
* get context node info
LO_PARENT_NODE_INFO = WD_CONTEXT->GET_NODE_INFO( ).
* get all child node of context
LT_CHILD_NODE_MAP = LO_PARENT_NODE_INFO->GET_CHILD_NODES( ).
* check node name exist or not which we want to create
* if node name exist then first remove then create
read table LT_CHILD_NODE_MAP transporting no fields
with table key NAME = `TEST_DYNAMIC`.
if SY-SUBRC = 0.
" REMOVE_CHILD_NODE
LO_PARENT_NODE_INFO->REMOVE_CHILD_NODE( `TEST_DYNAMIC` ).
endif.
* add child node with property you want
call method LO_PARENT_NODE_INFO->ADD_NEW_CHILD_NODE
exporting
* supply_method =
* supply_object =
* dispose_method =
* dispose_object =
STATIC_ELEMENT_TYPE = LV_STRUCT_NAME
NAME = `TEST_DYNAMIC`
* 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_TRUE
* static_element_rtti = lv_struct_name
IS_STATIC = ABAP_FALSE
* attributes =
receiving
CHILD_NODE_INFO = LO_CHILD_NODE_INFO.
*-----------------------------------------------------------
* add attribute to the node
*-----------------------------------------------------------
data LT_ATT type STRING_TABLE.
data LR_ATTRIBUTE type WDR_CONTEXT_ATTRIBUTE_INFO.
* get all attribute of the node
LT_ATT = LO_CHILD_NODE_INFO->GET_ATTRIBUTE_NAMES( ).
LR_ATTRIBUTE-NAME = 'TEST_ATTRIBUTE'.
LR_ATTRIBUTE-TYPE_NAME ='CHAR40'.
* check attribut name is exist or not
* if attribute name exist then first remove attribute
* then add to node
read table LT_ATT transporting no fields
with key TABLE_LINE = 'TEST_ATTRIBUTE'.
if SY-SUBRC ne 0.
call method LO_CHILD_NODE_INFO->ADD_ATTRIBUTE
exporting
ATTRIBUTE_INFO = LR_ATTRIBUTE.
clear LR_ATTRIBUTE.
endif.
Comments
Post a Comment