cancel
Showing results for 
Search instead for 
Did you mean: 

how can i change the column label text in a alv table display

Former Member
0 Kudos
840

how can i change the column label text in a alv table display??

A similar kinda of question was posted previuosly where the requirement was the label text was needed and following below code was given as solution :

<i>* declare column, settings, header object

DATA: lr_column TYPE REF TO cl_salv_wd_column.

DATA: lr_column_settings TYPE REF TO if_salv_wd_column_settings.

DATA: lr_column_header type ref to CL_SALV_WD_COLUMN_HEADER.

  • get column by specifying column name.

lr_column = lr_column_settings->get_column( 'COLUMN_NAME1' ).

  • set Header Text as null

lr_column_header = lr_column->get_header( ).

lr_column_header->set_text( ' ' ).</i>

My specific requirement is i have an input field on the screen and i want reflect that value as the column label for one of the column in the alv table. I have used he above code with slight modification in the MODIFYVIEW method of the view since it is a process after input. The component gets activated without any errors but while run time i get an error stating

<i>"The following error text was processed in the system CDV : Access via 'NULL' object reference not possible."</i>

i have checked in debugging and the error occured at the statement :

<i>lr_column = lr_column_settings->get_column( 'CURRENT_YEAR' ).</i>Please can you provide me an alternative for my requirement or correct me if i have done it wrong.

Thanks,

Suri

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Suri,

I presume what you tried to do for your requriement was :

1) Get the text from the input field in ALV

2) Use the above specified code to set label in WDDOMODIFY

I guess the reason why you are getting the error is because the reference gets flushed .. so you may call/perform same steps to set label of column on hitting Enter Key in the table cell.. this should work although I haven't tried this ..

Regards,

Anoop

Former Member
0 Kudos

No Anup that does not work. Thanks for trying.

Former Member
0 Kudos

I found it myself how to do it. The error says that it is not able to find the reference object i.e it is asking us to refer to the table. The following piece of code will solve this problem. Have to implement this in WDDOMODIFYVIEW method of the view. This thing works comrades enjoy...

DATA : lr_cmp_usage TYPE REF TO if_wd_component_usage,

lr_if_controller TYPE REF TO iwci_salv_wd_table,

lr_cmdl TYPE REF TO cl_salv_wd_config_table,

lr_col TYPE REF TO cl_salv_wd_column.

DATA : node_year TYPE REF TO if_wd_context_node,

elem_year TYPE REF TO if_wd_context_element,

stru_year TYPE if_alv_layout=>element_importing,

item_year LIKE stru_year-i_current_year,

lf_string TYPE char(x),

DATA: lr_column TYPE REF TO cl_salv_wd_column.

DATA: lr_column_header TYPE REF TO cl_salv_wd_column_header.

DATA: lr_column_settings TYPE REF TO if_salv_wd_column_settings.

  • Get the entered value from the input field of the screen

node_year = wd_context->get_child_node( name = 'IMPORTING_NODE' ).

elem_year = node_year->get_element( ).

elem_year->get_attribute(

EXPORTING

name = 'IMPORT_NODE-PARAMETER'

IMPORTING

value = L_IMPORT_PARAM ).

WRITE L_IMPORT_PARAM TO lf_string.

  • Get the reference of the table

lr_cmp_usage = wd_this->wd_cpuse_alv( ).

IF lr_cmp_usage->has_active_component( ) IS INITIAL.

lr_cmp_usage->create_component( ).

ENDIF.

lr_if_controller = wd_this->wd_cpifc_alv( ).

lr_column_settings = lr_if_controller->get_model( ).

  • get column by specifying column name.

IF lr_column_settings IS BOUND.

lr_column = lr_column_settings->get_column( 'COLUMN_NAME').

  • set Header Text as null

lr_column_header = lr_column->get_header( ).

lr_column_header->set_text( lf_string ).

endif.