cancel
Showing results for 
Search instead for 
Did you mean: 

How to create Node, Attributes and Table Dynamically?

Former Member
0 Kudos

Hi All,

How to create node and attributes dynamically, and with this node i want to create table dynamically?? Any related code please?

Thanks

Venkat.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

hi venkat , below is the sample piece of code to create node dynamically .

Create Node & attribute dynamicly

METHOD wddoinit .
           DATA: lr_node TYPE REF TO if_wd_context_node,
                      lr_node_info TYPE REF TO if_wd_context_node_info,
                      lr_child_node_info TYPE REF TO if_wd_context_node_info.
                      lr_node_info = wd_context->get_node_info( ).
* creatind node using structure 
                      lr_child_node_info = lr_node_info->add_new_child_node( name = 'STUDENT'
                      is_singleton = abap_true
                      is_multiple = abap_true
                      is_mandatory = abap_true
                      static_element_type = 'YSTR_PERSON' )." structure name 

                    lr_node = wd_context->get_child_node( 'STUDENT' ).
* filling internal table 
          DATA ls_data TYPE ystr_person.
                    ls_data-firstname = 'Antonia Maria'.
                    ls_data-lastname = 'Keller'.
                    ls_data-dateofbirth = '19800306'.
                   append ls_data to lt_data 
                  lr_node->bind_table(  lt_data ).
ENDMETHOD.

Regards

Chinnaiya P

Former Member
0 Kudos

Hi Chinnaiya,

Thanks for ur reply,

You are creating node of type using some structure.. and filling internal table.

Suppose i want to create node STUDENT with attributes NAME,CLASS and MARKS dynamically.

and using this NODE and attributes i want to create table also dynamically. Then i enter data in those columns and save data. can u help in this?

Thanks,

Venkat.

gill367
Active Contributor
0 Kudos

HI

I guess you are asking the same thing in some other post also .

use the code as mentioned there also.


data: wd_node_info type ref to if_wd_context_node_info,
wd_node type ref to if_wd_context_node,
lr_container type ref to cl_wd_uielement_container,
lv_tablename type string,
lt_db_data type ref to data,
lr_table type ref to cl_wd_table,
ls_attribute type wdr_context_attribute_info.

field-symbols: <lt_data> type any table.
wd_node_info = wd_context->get_node_info( ).

CALL METHOD WD_NODE_INFO->ADD_NEW_CHILD_NODE
EXPORTING
*STATIC_ELEMENT_TYPE = 'ZDEALER'
NAME = 'NODE'
IS_MULTIPLE = ABAP_TRUE
IS_INITIALIZE_LEAD_SELECTION = ABAP_FALSE
RECEIVING
CHILD_NODE_INFO = wd_node_info.

wd_node = wd_context->get_child_node( name = 'NODE' ).
wd_node_info = WD_node->GET_NODE_INFO( ).

data dyn_attr_info type wdr_context_attribute_info.

DYN_ATTR_INFO-NAME = 'X1'. "Attribute Name
DYN_ATTR_INFO-TYPE_NAME = 'STRING' ." Data Element(CHAR20) ( Type Of Attribute )
DYN_ATTR_INFO-NODE_INFO = wd_node_info.

CALL METHOD wd_node_info->ADD_ATTRIBUTE
EXPORTING
ATTRIBUTE_INFO = DYN_ATTR_INFO.

DYN_ATTR_INFO-NAME = 'X2'. "Attribute Name
DYN_ATTR_INFO-TYPE_NAME = 'STRING' ." Data Element(CHAR20) ( Type Of Attribute )
DYN_ATTR_INFO-NODE_INFO = wd_node_info.

CALL METHOD wd_node_info->ADD_ATTRIBUTE
EXPORTING
ATTRIBUTE_INFO = DYN_ATTR_INFO.

lr_container ?= view->get_root_element( ).
cl_wd_matrix_layout=>new_matrix_layout( container = lr_container ).

" Creating internal table with the same structure as our dynamic context node
CALL METHOD CL_WD_table=>new_table
EXPORTING
bind_data_source = 'NODE'
ID = 'TABLE'

RECEIVING
control = lr_table.




cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_table ).
*lr_table->bind_data_source( path = 'NODE' ).

data lr_table_col type ref to cl_wd_table_column.
data lr_table_col1 type ref to cl_wd_table_column.
data lr_text_view type ref to cl_wd_text_view.
data lr_input_field type ref to cl_wd_input_field.
DATA lr_column_name_header TYPE REF TO cl_wd_caption.


lr_input_field = cl_wd_input_field=>new_input_field(
bind_value = 'NODE.X1' ID = 'INP' ).
LR_TABLE_COL = cl_wd_table_column=>new_table_column( id = 'COL1' ).
lr_table->add_column( the_column = lr_table_col ).
lr_column_name_header ?= cl_wd_caption=>new_caption( text = 'X1').
lr_table_col->set_table_cell_editor(
THE_TABLE_CELL_EDITOR = lr_input_field ).
lr_table_col->set_header( lr_column_name_header ).


lr_text_view = cl_wd_text_view=>new_text_view(
bind_text = 'NODE.X2' ID = 'TXT' ).
LR_TABLE_COL1 = cl_wd_table_column=>new_table_column( id = 'COL2' ).
lr_table->add_column( lr_table_col1 ).
lr_column_name_header ?= cl_wd_caption=>new_caption( text = 'X2').
lr_table_col1->set_table_cell_editor(
THE_TABLE_CELL_EDITOR = lr_text_view ).
lr_table_col1->set_header( lr_column_name_header ).

lr_container->add_child( lr_table ).

cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_table ).

thanks

sarbjeet singh

Former Member
0 Kudos

Hi venkat , refer the code below for your

method WDDOINIT .
DATA: node_info type ref to if_wd_context_node_info,
      comp_tab    TYPE cl_abap_structdescr=>component_table,
      comp        LIKE LINE OF comp_tab,
      struct_type TYPE REF TO cl_abap_structdescr,
      table_type  TYPE REF TO cl_abap_tabledescr,
      my_table    TYPE REF TO data,
      my_wa      TYPE REF TO data.
FIELD-SYMBOLS: <dyn_table> TYPE table,
               <wa> TYPE data, 
*populating  the coloum names to create internal table 
    comp-name = 'NAME'.
    comp-type ?= cl_abap_datadescr=>describe_by_name(  'ZNAME'  )." data element name 
    APPEND comp TO comp_tab.

    comp-name = 'MARK'.
    comp-type ?= cl_abap_datadescr=>describe_by_name(  'ZMARK'  )." data element name 
    APPEND comp TO comp_tab.
 " creating structure with the coloumn 
  struct_type = cl_abap_structdescr=>create( comp_tab ).
* creatind node using dynamic structure  
                      lr_child_node_info = lr_node_info->add_new_child_node( name = 'STUDENT'
                      is_singleton = abap_true
                      is_multiple = abap_true
                      is_mandatory = abap_true
                      static_element_type =   struct_type )." dynamic structure name 

get the attributes from the node 
 struct_type = node_info->GET_STATIC_ATTRIBUTES_TYPE( ).
 table_type = cl_abap_tabledescr=>create( p_line_type = struct_type )."table  type 
  CREATE DATA my_table TYPE HANDLE table_type.
  ASSIGN my_table->* TO <dyn_table >."now you can populate the dynamic internal table 
endmethod.

method WDDOMODIFYVIEW .
  data: l_root type ref to cl_wd_uielement_container,
        l_node type ref to if_wd_context_node.

  if first_time = abap_true.
    l_root ?= view->GET_ROOT_ELEMENT( ).
    l_node = wd_context->get_child_node( 'STUDENT' )."node name

    cl_wd_dynamic_tool=>create_table_from_node(
    ui_parent = l_root
    table_id = 'MY_TABLE'" table name 
    node = l_node ).
  endif.
endmethod.

Regards

Chinnaiya P