cancel
Showing results for 
Search instead for 
Did you mean: 

Create dynamic table of dynamic node

Former Member
0 Kudos

Hi together,

i create and bind a dynamic node in COMPONENTCONTROLLER.

Now i want to create data table for this node in VIEWCONTROLLER. Binding and showing the

data is no problem, i'm trying to create a table/structure of this node, but i don't find any solution!?

Found similar topics hear, but nothing that sounds like my solution..

Accepted Solutions (0)

Answers (2)

Answers (2)

abhimanyu_lagishetti7
Active Contributor
0 Kudos

create dynamic table using

DATA: lt_fieldcat TYPE lvc_t_fcat,

la_fieldcat TYPE lvc_s_fcat,

lo_table TYPE REF TO data.

FIELD-SYMBOLS: <f_tab> TYPE ANY TABLE,

<f_line> TYPE ANY,

<f_field> TYPE ANY.

la_fieldcat-fieldname = 'KSTAR'.

la_fieldcat-datatype = 'CHAR'.

la_fieldcat-outputlen = 10.

APPEND la_fieldcat TO lt_fieldcat.

cl_alv_table_create=>create_dynamic_table( EXPORTING it_fieldcatalog = lt_fieldcat IMPORTING ep_table = lo_table ).

ASSIGN lo_table->* TO <f_tab>.

Abhi

Former Member
0 Kudos

I know how to create a dynamic table, but i need the structure of my node!

I want to to create a dynamic table with structure of dynamic node..

uday_gubbala2
Active Contributor
0 Kudos

Hi Christopher,

Please try going through my code below. I have an input field on my screen where the user enters a table name of his choice. I would need to fetch and display the data from the database in the underlying table below.

I hope that this would help serve your cause.

I have a context node by name INPUT which has just 1 attribute TABLE_NAME of type STRING which am using to hold the table name entered by the user. The user enters a table name and presses on a pushbutton. I dont have any code within my buttons action handler. Within the WDDOMODIFYVIEW am just checking if the TABLE_NAME attribute is not blank & then going ahead with the dynamic node & table creation.

Regards,

Uday

Coding from WDDOMODIFYVIEW:

method WDDOMODIFYVIEW .
  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.
  field-symbols: <lt_data> type any table.

  wd_node_info = wd_context->get_node_info( ).
  wd_node = wd_context->get_child_node( name = 'INPUT' ).
  wd_node->get_attribute( exporting name  = 'TABLE_NAME'
                          importing value = lv_tablename ).

" If TABLE_NAME is not equal to '' then it must be having the table name entered by the user
" Please keep in mind that am not validating the name entered by the user as of now in here..

  check lv_tablename NE ''.

  create data lt_db_data type table of (lv_tablename).
  assign lt_db_data->* to <lt_data>.

" Creating the node with structure same as the tablename entered by user
"  for binding to the table ui element dynamically

  CALL METHOD WD_NODE_INFO->ADD_NEW_CHILD_NODE
    EXPORTING
      STATIC_ELEMENT_TYPE          = lv_tablename
      NAME                         = 'MY_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 = 'MY_NODE' ).

" Fetch data from the table name entered by the user
  select * from (lv_tablename) into corresponding fields of table <lt_data> up to 20 rows.
  wd_node->bind_table( new_items = <lt_data> ).

  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_DYNAMIC_TOOL=>CREATE_TABLE_FROM_NODE
    EXPORTING
      UI_PARENT = lr_container
      TABLE_ID  = 'MY_TABLE'
      NODE      = wd_node
    RECEIVING
      TABLE     = lr_table.

  cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_table ).

  lr_table->bind_data_source( path = 'MY_NODE' ).
endmethod.

Former Member
0 Kudos

Just another point of view, hope this helps:



  DATA im_typename TYPE string . 
  DATA objects TYPE REF TO data .
  DATA data_type TYPE REF TO cl_abap_datadescr .
  DATA tabletype type ref to cl_abap_tabledescr .

  data_type ?= cl_abap_datadescr=>describe_by_name( im_typename ) .

  tabletype = cl_abap_tabledescr=>create( p_line_type  = data_type ) .

  create data objects type handle tabletype .

You pass the name of the type of the node in im_typename, for example 'string' . 'objects' is the internal dynamic table.

Former Member
0 Kudos

To create a dynamic structure, use the method static create of cl_abap_structdescr . You just need to provide the list of your components, of type cl_abap_structdescr=>abap_components .

Former Member
0 Kudos

Hi,

Do you want to create a dynamic node from the dynamic table/structure?

Regards,

Lekha.