cancel
Showing results for 
Search instead for 
Did you mean: 

DyNAMIC INTERNAL TABLE CREATION FROM NODE STRUCTURE

Former Member
0 Kudos

Hi Experts ,

I am creating node dynamically & adding the attributes dynamically to this node at runtime .

i want to create the internal table having structure as that of node dynamically created . How to do this ?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi,

its easy ..recently I have done this ...plz check the below code .

DATA: LR_ROOT_INFO TYPE REF TO IF_WD_CONTEXT_NODE_INFO,

LR_FLIGHTS_INFO TYPE REF TO IF_WD_CONTEXT_NODE_INFO,

LS_ATTRIBUTE TYPE WDR_CONTEXT_ATTRIBUTE_INFO,

LR_STRUCTDESCR TYPE REF TO CL_ABAP_STRUCTDESCR ,

LS_COMPONENT TYPE CL_ABAP_STRUCTDESCR=>COMPONENT,

LT_COMPONENTS TYPE CL_ABAP_STRUCTDESCR=>COMPONENT_TABLE,

LR_TYPE TYPE REF TO CL_ABAP_DATADESCR .

*CREATE A STRUCURE WITH REQUIRED FILEDS(ATTRIBUTES) AND

*GIVE THIS NAME WHEN CREATING NODE

*SO THAT NODE WILL GET THE ATTRIBUTES .

LR_TYPE ?= cl_abap_TYPEdescr=>describe_by_name( p_name = 'S_CARR_ID' ).

LS_COMPONENT-NAME = 'CARRID'.

LS_COMPONENT-TYPE = LR_TYPE .

APPEND LS_COMPONENT TO LT_COMPONENTS.

LR_TYPE ?= cl_abap_TYPEdescr=>describe_by_name( p_name = 'S_CONN_ID' ).

LS_COMPONENT-NAME = 'CONNID'.

LS_COMPONENT-TYPE = LR_TYPE .

APPEND LS_COMPONENT TO LT_COMPONENTS.

CALL METHOD cl_abap_structdescr=>create

EXPORTING

p_components = LT_COMPONENTS

receiving

p_result = LR_STRUCTDESCR .

Structure is created with the fields (attributes) .then create a node by giving this structure

  • Get the meta data information of the root context node

LR_ROOT_INFO = WD_CONTEXT->GET_NODE_INFO( ).

  • Create node with name FLIGHTS

*

CALL METHOD LR_ROOT_INFO->ADD_NEW_CHILD_NODE

EXPORTING

NAME = 'FLIGHTS'

STATIC_ELEMENT_RTTI = LR_STRUCTDESCR " STRUCTURE CREATED EARLIER

RECEIVING

CHILD_NODE_INFO = LR_FLIGHTS_INFO

.

Node is also created .

*instantiate the dynamic node .

*get refernce for dynamic node created

data:

node_dyn_node type ref to if_wd_context_node,

LO_EL type ref to if_wd_context_element.

DATA : LV_CARRID TYPE SFLIGHT-CARRID .

  • navigate from <CONTEXT> to <DYNAMIC_NODE> via lead selection

node_dyn_NODE = wd_context->get_child_node( name = 'FLIGHTS' ).

*There are no elements in the Node, use the code to create an element

                              • below code to create the internal table having structure as that of node dynamically created **************

data: lr_data type ref to data.

field-symbols:<fs> type any.

create data lr_data type handle lr_structdescr.

assign lr_data->* to <fs>.

NODE_DYN_NODE->bind_element( exporting new_item = <fs> ).

CALL METHOD NODE_DYN_NODE->GET_STATIC_ATTRIBUTES

  • EXPORTING

  • INDEX = USE_LEAD_SELECTION

IMPORTING

STATIC_ATTRIBUTES = <fs>

.

hope this isuseful..

plz check and let me know.

reagrds

Arjun

Answers (2)

Answers (2)

Former Member
0 Kudos

hi,

is ur question solved ?

Former Member
0 Kudos

Thanks Arjun

code provided is really helped me

Former Member
0 Kudos

Hi,

Please check the other thread of yours on the same task.

Please close the thread and then open a new thread when the query is same to avoid silimar posts.

Regards,

Lekha.