cancel
Showing results for 
Search instead for 
Did you mean: 

Creating Dynamic Node and Table

Former Member
0 Kudos

Dear all,

I have to display the report as given Below

Vendor 1 Vandor 2 ......... Vendor N

mat1

Mat2

Mat3

In above report the number of column is not going to be fixed . so I have to create the Node Dynamically

and display the table by using that node . How to do this. Please give your suggestion.

Regards,

Raghvendra.

Accepted Solutions (1)

Accepted Solutions (1)

former_member402443
Contributor
0 Kudos

Hi Raghvendra,

you can use the class - CL_WD_DYNAMIC_TOOL to create dynamic node and tables.

Hey you can go thru the WDA Component - DEMODYNAMIC in the SWDP_DEMO PACKAGE of your sap system.

Thanks and regards,

Manoj Kumar

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Here is a document where I use the cl_wd_dynamic_tool API to create a dynamic node for any table structure.

https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/bf20e84f-0901-0010-fe9e-91d10001...

The main difference in your case is it doesn't sound like you will have a source DDic structure since you don't know how many columns of Vendors you might possibly need. That gets more complicated because now you can't use the CREATE_NODEINFO_FROM_STRUCT method.

Here is some example code where I have to build the context completely dynamic becuase I am reading my structure from MDM at runtime. There is some extra processing in here that you don't need - I only had it because I am dealing with MDM. However the approach for creating an RTTI based description of the structure and then generating the node with add_new_child_node remains the same.

****ALV
      data:
         rootnode_info type ref to if_wd_context_node_info,
         dyn_node type ref to if_wd_context_node,
         dyn_node_info type ref to if_wd_context_node_info,
         tabname_node type ref to if_wd_context_node,
         current_tablename type string,
         tablename type string,
         struct_type type ref to cl_abap_structdescr,
          table_type  type ref to cl_abap_tabledescr,
          comp_tab    type cl_abap_structdescr=>component_table,
          comp        like line of comp_tab,
          my_table    type ref to data,
          my_row      type ref to data.
      field-symbols: <table> type table,
                     <row> type data,
                     <f>   type any,
                     <wa_string>     type string,
                     <wa_date_time>  type mdm_cdt_date_time,
                     <wa_integer>    type mdm_gdt_integervalue.



      rootnode_info = wd_context->get_node_info( ).

* create subnode_info
      try.
          rootnode_info->remove_child_node( 'MDM_DATA' ).
        catch cx_wd_context.
      endtry.

      field-symbols <wa_detail> like line of field_details.
      field-symbols <wa_result> like line of result_set.
      field-symbols <wa_pair>   type mdm_name_value_pair.
      read table result_set assigning <wa_result> index 1.
      loop at field_details assigning <wa_detail>.
* build a structure description from the list of single fields
        if strlen( <wa_detail>-field_code ) > 30.
          comp-name = <wa_detail>-field_code+0(30).
        else.
          comp-name = <wa_detail>-field_code.
        endif.
        if <wa_result> is assigned.
          read table <wa_result>-name_value_pairs assigning <wa_pair>
                        with key code = <wa_detail>-field_code.
          if sy-subrc = 0.
            case <wa_pair>-type.
              when `MDM_CDT_DATE_TIME`.
                comp-type ?= cl_abap_datadescr=>describe_by_name( 'TZNTSTMPL' ).
              when `MDM_GDT_INTEGERVALUE`.
                if <wa_detail>-field_lookup_table is not initial.
                  comp-type ?= cl_abap_datadescr=>describe_by_name( 'STRING' ).
                else.
                  comp-type ?= cl_abap_datadescr=>describe_by_name( 'INT4' ).
                endif.
              when others.
                comp-type ?= cl_abap_datadescr=>describe_by_name( <wa_pair>-type ).
            endcase.
          else.
            comp-type ?= cl_abap_datadescr=>describe_by_name( 'STRING' ).
          endif.
        else.
          comp-type ?= cl_abap_datadescr=>describe_by_name( 'STRING' ).
        endif.
        append comp to comp_tab.
      endloop.

      struct_type = cl_abap_structdescr=>create( comp_tab ).
      dyn_node_info = rootnode_info->add_new_child_node(
         name                   = 'MDM_DATA'
         is_mandatory           = abap_false
         is_mandatory_selection = abap_false
         static_element_rtti    = struct_type
         is_multiple            = abap_true
         is_static              = abap_false ).

*  get instance of new node
      dyn_node = wd_context->get_child_node( name = 'MDM_DATA' ).


****Process Table Data
      data content_string type string.
      data l_tabix type sytabix.
      table_type = cl_abap_tabledescr=>create( p_line_type = struct_type ).
      create data my_table type handle table_type.
      assign my_table->* to <table>.
      loop at result_set assigning <wa_result>.
        create data my_row type handle struct_type.
        assign my_row->* to <row>.
        loop at field_details assigning <wa_detail>.
          l_tabix = sy-tabix.
          read table <wa_result>-name_value_pairs assigning <wa_pair>
                                  with key code = <wa_detail>-field_code.
*        loop at <wa_result>-name_value_pairs assigning <wa_pair>.
          if sy-subrc = 0 and <wa_pair>-value is not initial.
            assign component l_tabix of structure <row> to <f>.
*            READ TABLE field_details ASSIGNING <wa_detail> INDEX sy-tabix.
            case <wa_pair>-type.
              when 'STRING'.
                assign <wa_pair>-value->* to <wa_string>.

                if <wa_string> is assigned.
                  move <wa_string> to <f>.
                endif.
              when 'MDM_CDT_DATE_TIME'.
                assign <wa_pair>-value->* to <wa_date_time>.
                if <wa_date_time> is assigned.
                  move <wa_date_time>-content to <f>.
                endif.

              when 'MDM_GDT_INTEGERVALUE'.
                assign <wa_pair>-value->* to <wa_integer>.
                if <wa_integer> is assigned.
                  if <wa_detail>-field_lookup_table is not initial.
                    content_string = wd_assist->perform_value_lookup(
                        i_lookup_table = <wa_detail>-field_lookup_table
                        i_lookup_key   = <wa_integer> ).
                    move content_string to <f>.
                  else.
                    move <wa_integer> to <f>.
                  endif.
                endif.
            endcase.
          endif.
        endloop.
        append <row> to <table>.
      endloop.
      dyn_node->bind_table( <table> ).

* Connect to the component Usage of the ALV
      data: l_ref_cmp_usage type ref to if_wd_component_usage.
      l_ref_cmp_usage =   wd_this->wd_cpuse_alv( ).
      if l_ref_cmp_usage->has_active_component( ) is initial.
        l_ref_cmp_usage->create_component( ).
      endif.

* Through the interface controller of the ALV Component set the DATA node dynamically
      data: l_ref_interfacecontroller type ref to iwci_salv_wd_table .
      l_ref_interfacecontroller =   wd_this->wd_cpifc_alv( ).
      l_ref_interfacecontroller->set_data(
        r_node_data = dyn_node  ).

      data alv_model type ref to cl_salv_wd_config_table.
      alv_model = l_ref_interfacecontroller->get_model( ).
      data columns type salv_wd_t_column_ref.
      field-symbols <wa_column> like line of columns.
      columns = alv_model->if_salv_wd_column_settings~get_columns( ).
      data column_id type string.
      data header type ref to cl_salv_wd_column_header.
      data l_text type string.
      loop at field_details assigning <wa_detail>.
* build a structure description from the list of single fields
        if strlen( <wa_detail>-field_code ) > 30.
          column_id = <wa_detail>-field_code+0(30).
        else.
          column_id = <wa_detail>-field_code.
        endif.
        translate column_id to upper case.
        read table columns assigning <wa_column> with table key id = column_id.
        if sy-subrc = 0.
          header = <wa_column>-r_column->get_header( ).
          header->set_ddic_binding_field( if_salv_wd_c_column_settings=>ddic_bind_none ).
*      if <wa_detail>-field_lookup_table is initial.
          header->set_text( <wa_detail>-field_name1 ).
*      else.
*        l_text = wd_assist->read_table_desc_for_lookup( <wa_detail>-field_lookup_table ).
*        header->set_text( l_text ).
*      endif.
        endif.
      endloop.
    catch cx_root into o_except.
      data: l_current_controller type ref to if_wd_controller,
            l_message_manager    type ref to if_wd_message_manager.
      l_current_controller ?= wd_this->wd_get_api( ).
      l_message_manager = l_current_controller->get_message_manager( ).
      l_message_manager->report_exception(
          message_object           = o_except ).
  endtry.

Answers (1)

Answers (1)

former_member226203
Active Contributor
0 Kudos

chk this blog:

/people/sap.user72/blog/2005/05/23/accessing-dynamic-nodes-in-webdynpro

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>

> chk this blog:

> /people/sap.user72/blog/2005/05/23/accessing-dynamic-nodes-in-webdynpro

You linked to a blog on Web Dynpro Java for a Web Dynpro ABAP related question. The concepts may be similar, but for most cases you probably are most helpful to people if you answer with Web Dynpro ABAP related topics.