Skip to Content
0
Jul 10, 2007 at 02:23 PM

dynamic context attributes and ALV problem

35 Views

I have a little problem with my dynamic context attributes. I would like make a dynamic context attributes from an internal table (now from a demo internal table, later from an imported itab). This internal table type is not from DDIC.

I have a static node in my context, MTX. In this static context I have got a static attribute (name "STATIC" ). I can build the context attributes dynamic from the iternal table colums, and I can bind to my demo table.

But in run time, i can't see the dynamic attributes data in the ALV, only the static attribute data.

I hope, you can help me.

Here is the code:

method WDDOINIT .

******************************************************

*Demo internal table

TYPES: BEGIN OF mtxprototype,

STATIC TYPE STRING,

aa TYPE STRING,

bb TYPE i,

cc TYPE c LENGTH 20,

dd(2),

ee(230),

END OF mtxprototype.

DATA:

mtxtable TYPE TABLE OF mtxprototype,

wa_mtxtable TYPE mtxprototype.

*"----


Set up demo internal table -


wa_mtxtable-bb = 2.

APPEND wa_mtxtable TO mtxtable.

wa_mtxtable-aa = 'baba'.

APPEND wa_mtxtable TO mtxtable.

wa_mtxtable-aa = 'a'.

APPEND wa_mtxtable TO mtxtable.

wa_mtxtable-aa = 'dada'.

wa_mtxtable-bb = 1.

APPEND wa_mtxtable TO mtxtable.

wa_mtxtable-STATIC = 'Statikus string adat'.

wa_mtxtable-CC = 'lenght 20'.

APPEND wa_mtxtable TO mtxtable.

*"----


Data declaration -


DATA: lr_node_info TYPE REF TO if_wd_context_node_info, "To get node info

lr_table_type TYPE REF TO cl_abap_tabledescr, "To get table and stuct descriptor

lr_line_type TYPE REF TO cl_abap_structdescr,

lt_components TYPE cl_abap_structdescr=>component_table, "To get component table

ls_components_line LIKE LINE OF lt_components, "One line of component table

lr_elem_type TYPE REF TO cl_abap_elemdescr,

ls_attribute TYPE wdr_context_attribute_info "To create dynamic node in the context

.

*"----


Get node info -


lr_node_info ?= wd_context->get_node_info( ).

lr_node_info = lr_node_info->get_child_node( 'MTX' ).

*"- Get descriptor reference to actual table and line structure -

lr_table_type ?= cl_abap_tabledescr=>describe_by_data( mtxtable ).

lr_line_type ?= lr_table_type->get_table_line_type( ).

*"----


Get components table -


lt_components = lr_line_type->get_components( ).

*"----- Get datadescr ref from lt_components table -


LOOP AT lt_components INTO ls_components_line WHERE name NE 'STATIC'.

ls_attribute-name = ls_components_line-name.

lr_elem_type ?= ls_components_line-type.

ls_attribute-type_name = lr_elem_type->absolute_name. "Get absolute type

ls_attribute-rtti = lr_elem_type.

lr_node_info->add_attribute( "Add attribute

EXPORTING

attribute_info = ls_attribute ).

ENDLOOP.

*"---- Bind internal table to the context node -


DATA: mtx_node TYPE REF TO if_wd_context_node.

mtx_node = wd_context->get_child_node( name = 'MTX' ). "Get node

mtx_node->bind_table(

NEW_ITEMS = mtxtable ).