on 12-15-2008 4:04 PM
Hi,
how can I display another header name in a dynamic alv?
In the example below the header name is in ls_ui_tnbchr-atnam. This is the id and the technical name and the application runs fine. But I want that the localized description ls_ui_tnbchr-atbez is shown instead. The problem is that this field has spaces and this is an illegal character when creating the structure.
Has anybody an idea what I can do?
Thanks, Susanne
DATA:
BEGIN OF row_struct,
material TYPE string,
description TYPE string,
END OF row_struct.
* Dynamic Fields
DATA:
field_name TYPE string,
lr_rtti_struc TYPE REF TO cl_abap_structdescr,
lt_comp TYPE cl_abap_structdescr=>component_table,
ls_comp LIKE LINE OF lt_comp,
wa_dyn LIKE row_struct.
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( wa_dyn ).
lt_comp = lr_rtti_struc->get_components( ).
LOOP AT lt_ui_tnbchr INTO ls_ui_tnbchr.
TRANSLATE ls_ui_tnbchr-atnam TO UPPER CASE.
ls_comp-name = ls_ui_tnbchr-atnam.
ls_comp-type = cl_abap_elemdescr=>get_string( ).
APPEND ls_comp TO lt_comp.
ENDLOOP.
* Create structure using dynamic fields, now we have dyna structure 'lr_rtti_struc'
CALL METHOD cl_abap_structdescr=>create
EXPORTING
p_components = lt_comp
RECEIVING
p_result = lr_rtti_struc.
Edited by: Susanne Steib on Dec 15, 2008 5:06 PM
Edited by: Susanne Steib on Dec 15, 2008 5:06 PM
Following is an example code to change the header of a dynamic alv structure.
DATA: l_ref_cmp_usage TYPE REF TO if_wd_component_usage ,
l_ref_interfacecontroller TYPE REF TO iwci_salv_wd_table ,
lr_node TYPE REF TO if_wd_context_node ,
lr_elem_data TYPE REF TO if_wd_context_element,
lr_salv_wd_table TYPE REF TO iwci_salv_wd_table,
lr_config TYPE REF TO cl_salv_wd_config_table.
lr_table_settings TYPE REF TO if_salv_wd_table_settings,
lr_field_settings TYPE REF TO if_salv_wd_field_settings,
lr_table_obj type ref to cl_salv_wd_config_table .
lr_column_settings TYPE REF TO if_salv_wd_column_settings.
lt_columns TYPE salv_wd_t_column_ref ,
ls_column TYPE salv_wd_s_column_ref,
ls_col TYPE salv_wd_s_column_ref,
lr_column TYPE REF TO cl_salv_wd_column,
lr_field TYPE REF TO cl_salv_wd_field,
lr_header TYPE REF TO cl_salv_wd_column_header,
lv_text TYPE string,
lv_header TYPE string.
DATA : lr_link TYPE REF TO cl_salv_wd_uie_link_to_action .
DATA : lr_elem TYPE REF TO if_wd_context_element,
lr_elem_1 TYPE REF TO if_wd_context_element ,
lt_elem TYPE wdr_context_element_set.
lr_node = wd_context->get_child_node( 'DATA' ).
l_ref_cmp_usage = wd_this->wd_cpuse_alv_main( ).
IF l_ref_cmp_usage->has_active_component( ) IS INITIAL.
l_ref_cmp_usage->create_component( ).
ENDIF.
l_ref_interfacecontroller = wd_this->wd_cpifc_alv_main( ).
l_ref_interfacecontroller->set_data( lr_node ).
lr_salv_wd_table = wd_this->wd_cpifc_alv_main( ).
lr_config = lr_salv_wd_table->get_model( ).
lr_table_settings ?= lr_config.
lr_field_settings ?= lr_config.
lr_table_settings->set_visible_row_count( '13' ).
lr_table_settings->set_read_only( abap_true ).
lr_table_settings->set_design( cl_wd_table=>e_design-alternating ).
lr_table_settings->set_scrollable_col_count( 12 ) .
lr_column_settings ?= lr_config.
lt_columns = lr_column_settings->get_columns( ).
LOOP AT lt_columns INTO ls_column .
CASE ls_column-id .
WHEN 'DOCNR' .
lr_column = ls_column-r_column .
lr_column->delete_header( ).
lr_header = lr_column->create_header( ).
CLEAR lv_header .
CONCATENATE ls_metal-matnr '(KG)' INTO lv_header SEPARATED BY space.
lr_header->set_text( lv_header ).
endloop.
Trick is to get the columns and set the header based on the column id. I use this approach for both type of alv's ( Dynamic or static ).
Regards
Rohit Chowdhary
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, that works
Susanne
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
94 | |
11 | |
11 | |
10 | |
9 | |
8 | |
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.