on 04-06-2009 1:00 PM
Hi All,
I am new for abap dynpro.
How can i create a dynamic alv table in abap dynpro withoud ddic structure??
My requirement is as follows:
I have a table having some field e.g MATNR WERKS NETWR.
I want to pivot data werks and to display in webdynpro alv.
Thnx:
N. N. Tiwari
You can use the RTTI to build up a dynamic structure in memory:
Something like this - where both the data and its structure and meta data all come from an external source (which happens to be MDM in this case):
****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.
* DATA: int TYPE i VALUE 258.
* DATA: buffer TYPE xstring,
* text_buffer TYPE string,
* conv TYPE REF TO cl_abap_conv_out_ce.
* conv = cl_abap_conv_out_ce=>create(
* encoding = 'UTF-8'
* endian = 'L' ).
*
* CALL METHOD conv->write( data = <wa_string> ).
* buffer = conv->get_buffer( ).
*
* DATA: convin TYPE REF TO cl_abap_conv_in_ce.
* CALL METHOD cl_abap_conv_in_ce=>create
* EXPORTING
* input = buffer
* RECEIVING
* conv = convin.
*
* CALL METHOD convin->read
* IMPORTING
* data = text_buffer.
*
* MOVE text_buffer TO <f>.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi
Refer this link u will get idea:
This link for Blog Expert Thomas gave video seccion about the ALV.
/people/thomas.jung/blog/2006/06/20/web-dynpro-abap-demonstration-videos
Regards
Vivekananthan.S
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.