on 06-04-2007 5:42 PM
I use dynamic context binding (see code below to show and edit the ALV table.
'DB_TABLE' is a tranparent table. It works fine.
But now this table should be expanded with additional fields which are only known at runtime and could be different from case to case.
How can I get these fields in the context dynamically?
DATA:
rootnode_info TYPE REF TO if_wd_context_node_info,
dyn_node TYPE REF TO if_wd_context_node,
tablename TYPE string.
rootnode_info = wd_context->get_node_info( ).
tablename = 'DB_TABLE'.
cl_wd_dynamic_tool=>create_nodeinfo_from_struct(
parent_info = rootnode_info
node_name = tablename
structure_name = tablename
is_multiple = abap_true ).
DATA:
stru_tab TYPE REF TO data.
FIELD-SYMBOLS: <tab> TYPE table.
CREATE DATA stru_tab TYPE TABLE OF (tablename).
ASSIGN stru_tab->* TO <tab>.
SELECT * FROM (tablename) INTO CORRESPONDING FIELDS OF TABLE <tab>.
dyn_node = wd_context->get_child_node( name = tablename ).
dyn_node->bind_table( <tab> ).
You should create a structure dynamically and use this as the context structure. See the coding below, where a structure is created, which contains CARRID and CONNID.
DATA: node_info type ref to if_wd_context_node_info,
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,
<flight> type sflight.
* build a structure description from the list of single fields
comp-name = 'CARRID'.
comp-type ?= cl_abap_datadescr=>describe_by_name( 'S_CARR_ID' ).
APPEND comp TO comp_tab.
comp-name = 'CONNID'.
comp-type ?= cl_abap_datadescr=>describe_by_name( 'S_CONN_ID' ).
APPEND comp TO comp_tab.
* note this structure contains the fields "CONNID" and "CARRID"
struct_type = cl_abap_structdescr=>create( comp_tab ).
* now the nodeinfo is created
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
).
* fill new node;
data: l_node type ref to if_wd_context_node,
l_flight type STANDARD TABLE OF sflight.
*
l_node = wd_context->get_child_node( 'MY_NODE' ).
l_flight = wd_assist->get_flights( ).
*
* if you could create a local data type, would be fine, but if you have to do it dynamically ...
struct_type = node_info->GET_STATIC_ATTRIBUTES_TYPE( ).
* create tabledescriptor from structdescription (standard table, no keys)
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 l_flight assigning <flight>.
create data my_row type handle struct_type.
assign my_row->* to <row>.
move-corresponding <flight> to <row>.
append <row> to <table>.
endloop.
l_node->bind_table( <table> ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
79 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.