cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Context node, Dynamic Structure

Former Member
0 Kudos

Hello All,

I am trying to create a dynamic context node and I have implemented the following code.


Data :
rootnode_info TYPE REF TO if_wd_context_node_info,
dyn_node TYPE REF TO if_wd_context_node,
tabname_node TYPE REF TO if_wd_context_node.
rootnode_info = wd_context->get_node_info( ).

cl_wd_dynamic_tool=>create_nodeinfo_from_struct(
parent_info = rootnode_info
node_name = 'DYN_NODE'
structure_name = ' '                        <----------------------------------------------------
is_multiple = abap_true ).

The code works if i give a structure name within the Single codes marked above. This structure should be defined in SE11 (Global structure).

My problem is that if i have defined the structure in my program locally, i get a dump stating that my structure does not exist.

The issue is I am generating an internal table at run time using field catalogs and i do not have (and cannot have) a corresponding structure in the data dictionary. I need to have a dynamic context node defined at runtime with the structure of this internal table which i generate.

Please Help.

Regards, and Thanks in Advance

Mz

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

OK everyone,

I think i almost got it. I need to give my fieldname above.

Then when i give the name of the first field in my internal table and execute the program, i am getting a dump at the statement


struct_type = cl_abap_structdescr=>create( comp_tab ).

Component Name '100517' of the Component 1 Contains an Invalid Character

The value '100517' is the value of the first field and first row of my populated internal table.

Any idea what could be the issue?

Best Regards,

Mz

Former Member
0 Kudos

The value '100517' is the value of the first field and first row of my populated internal table.
I dont think the attribute name can start with a numeric value, it has to start with a character. something like a1000517. Radhika.

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

Can you brief the scenario ?

Former Member
0 Kudos

Thanks Radhika,

Now i understand that the values in comp_tab make up the attributes of my context....

Thanks a lot.

Your replies have hit the Nail on its Head. Issue solved and output obtained. Full points Awarded

Former Member
0 Kudos

Hello Radhika,

Thanks for the speedy response.

I was trying out your code and i think that it could solve my issue.

Just one doubt.


LOOP AT wd_this->it_selmdls INTO wd_this->wa_selmdls.
      comp-name = wd_this->wa_selmdls-ca_mdlno. <---------------------------------------------------------
      comp-type ?= cl_abap_datadescr=>describe_by_name( 'STRING' ).
      APPEND comp TO comp_tab.
    ENDIF.
  ENDLOOP.

Here i am a bit confused as to what ca_mdlno is.

If i were to user <FS_INT_TAB> and <FS_WA> instead of wd_this->it_selmdls and wd_this->wa_selmdls, how would my code be.

Thanks in Advance,

Mz

Former Member
0 Kudos

In my scenario 'ca_mdlno' had an id, i was using the this id as the name of my attribute as it used to be unique. You can pass the name that you want to give to your attribute in 'comp-name'. It is not necessary that you pass values from the workarea. Hope i am clear.Let me know incase you still need any clarifications. Radhika

Former Member
0 Kudos

Check the below code

DATA: node_info TYPE REF TO if_wd_context_node_info,
        struct_type  TYPE REF TO cl_abap_structdescr,
        comp_tab TYPE cl_abap_structdescr=>component_table,
        comp LIKE LINE OF comp_tab,

" here wd_this->it_selmdls is my internal table based on which im creating my structure
  LOOP AT wd_this->it_selmdls INTO wd_this->wa_selmdls.
      comp-name = wd_this->wa_selmdls-ca_mdlno.
      comp-type ?= cl_abap_datadescr=>describe_by_name( 'STRING' ).
      APPEND comp TO comp_tab.
    ENDIF.
  ENDLOOP.

* Create structure 
  struct_type = cl_abap_structdescr=>create( comp_tab ).

* Create Node
  node_info = wd_context->get_node_info( ).
  node_info = node_info->add_new_child_node(
    name                         = 'MY_NODE'
    is_mandatory                 = abap_true
    is_multiple                  = abap_true
    static_element_rtti          = struct_type
    is_static                    = abap_false
       ).
Radhika.