Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Remove a column in SALV

Former Member
0 Kudos

Hi,

I am using SALV for display.

In this I am using the factory method as below :-

Data :   ref_docking_hdr       TYPE REF TO cl_gui_docking_container,

            ref_hdr         TYPE REF TO cl_salv_table.

          cl_salv_table=>factory(
          EXPORTING
            r_container    = ref_docking_hdr
          IMPORTING
            r_salv_table   ref_hdr
          CHANGING
            t_table        = t_header ).

t_header is pointing to some structure which is being used in some other programs as weel. This structure is enhanceed with the new field which is of type table.

So I am getting the dump when the display method is being called. I need to remove that column.

I tried to get the columns

   Get column definition
    l_ref_columns = ref_hdr->get_columns( ).

But the method REMOVE_COLUMN is protected for CL_SALV_COLUMNS.  So kindly suggest how can I remove the column.

Thanks in advance.

Regards,

Saurabh

8 REPLIES 8

Former Member

Use the method Get_Column to retrieve the object of type cl_salv_column for your problem.  The method SET_TECHNICAL suppresses the column from being displayed.

See whether this is enough.

Patsy

Former Member
0 Kudos

Hi,

You can use this way:

DATA: ls_column  TYPE salv_s_column_ref,

           lo_column  TYPE REF TO cl_salv_column.

LOOP AT l_ref_columns INTO ls_column.

  lo_column = ls_column-r_column.

  CASE ls_column-columnname.

    WHEN 'XYZ'.

      lo_column->set_visible( abap_false ).

  ENDCASE.

ENDLOOP.

Former Member
0 Kudos

The above answer are correct for hiding a column from display on screen. However, you say that "t_header is pointing to some structure which is being used in some other programs as weel. This structure is enhanceed with the new field which is of type table." which means that your table is a based on a deep structure with a nested table as column. I can't even get the factor method to compile for a table fitting this description never mind getting a dump when the display method is called but whatever the reason for that  difference if you table contains a column that is a table I think you will need to remove that column completely rather than just hide it from display.


The quickest way to do that would be to create a local structure type that is the same as the line type of t_header minus the offending column. Then create a local table using this type and copy the data from  t_header to the local table and pass this local table to cl_salv_table=>factory.

0 Kudos

Sorry I got distracted halfway through. I wanted to add if you don't want to manually create a local version of this table that has this column taken out you could do it dynmaically which would be more robust to future changes in the structure of  t_header. Adding the following code into your routine should do the trick


data: lr_table    TYPE REF TO  cl_abap_tabledescr,
       lr_old_str  TYPE REF TO  cl_abap_structdescr,
       lr_new_str  TYPE REF TO  cl_abap_structdescr,
       lt_comp TYPE cl_abap_structdescr=>component_table,
       lr_new_tab  TYPE REF TO  cl_abap_tabledescr,
       lr_local TYPE REF TO data.
FIELD-SYMBOLS: <lt_local> TYPE STANDARD TABLE,
                <ls_local> TYPE ANY.


lr_table ?= cl_abap_tabledescr=>DESCRIBE_BY_DATA( t_header ).
lr_old_str ?= lr_table->GET_TABLE_LINE_TYPE( ).
lt_comp = lr_old_str->GET_COMPONENTS( ).

*replace COL with name of column that has type talbe
delete lt_comp where name = 'COL'.
lr_new_str = cl_abap_structdescr=>create( lt_comp ).
lr_new_tab = cl_abap_tabledescr=>create(
                   p_line_type  = lr_new_str
                   p_table_kind = cl_abap_tabledescr=>tablekind_std
                   p_unique     = abap_false ).
CREATE DATA lr_local TYPE HANDLE lr_new_tab.
ASSIGN lr_local->* TO <lt_local>. "INTERNAL TABLE.



data: ls_header like LINE OF t_header.


loop at t_header into ls_header.
   APPEND INITIAL LINE TO <lt_local> ASSIGNING <ls_local>.
   MOVE-CORRESPONDING ls_header to <ls_local>.
ENDLOOP.


cl_salv_table=>factory(
EXPORTING
   r_container    = ref_docking_hdr
IMPORTING
   r_salv_table   ref_hdr
CHANGING
   t_table        = <lt_local> ).

ref_hdr->display( ).

0 Kudos

Hi Jamie,

Thanks for this piece of code

Regards

Abhi

0 Kudos

Hi Jamie,

Thanks for the reply.

I still have one issue.

The T_header table is as below

TYPES: BEGIN OF TY_HEADER.

   INCLUDE TYPE XYZ.

   TYPES:  kbetr1  TYPE konv-kbetr,

****

****

****

   END OF tp_debit_item.

So , the code above is not not getting thye fields of the Include XYZ structure. The col which I want to delete is also in this structure of not able to delete.

Please suggest.

Thanks.

Regards,

Saurabh

0 Kudos

Then you can just expnad the inlcude as well as per below. <text removed. Don't ask for points>

lr_table ?= cl_abap_tabledescr=>DESCRIBE_BY_DATA( t_header ).
lr_old_str ?= lr_table->GET_TABLE_LINE_TYPE( ).
lt_comp = lr_old_str->GET_COMPONENTS( ).

data: ls_incld type abap_componentdescr,
       lr_incld type ref to cl_abap_structdescr,
       lt_comp2 TYPE cl_abap_structdescr=>component_table.
*If there are multiple includes you'll have to make sure you
*are gettting the right one
READ TABLE lt_comp WITH TABLE KEY name = 'INCLUDE'
into ls_incld.
lr_incld ?= ls_incld-type.
delete lt_comp where name = 'INCLUDE'.
lt_comp2 = lr_incld->GET_COMPONENTS( ).
*Again the name of you col should go here
delete lt_comp2 where name = 'COL'.
APPEND LINES OF lt_comp2 to lt_comp.

lr_new_str = cl_abap_structdescr=>create( lt_comp ).
lr_new_tab = cl_abap_tabledescr=>create(
                   p_line_type  = lr_new_str
                   p_table_kind = cl_abap_tabledescr=>tablekind_std
                   p_unique     = abap_false ).
CREATE DATA lr_local TYPE HANDLE lr_new_tab.
ASSIGN lr_local->* TO <lt_local>. "INTERNAL TABLE.

Message was edited by: Matthew Billingham

Former Member
0 Kudos

Hi,

One question:- Did you write your program first and then the structure in question was enhanced or the other way round? In latter case, can you elaborate reason for using this structure? If it has extra columns then it shouldn't have used.

I don't think you can achieve your objective as you are dealing with nested tables. I suggest create a flat structure and assign it as type for your internal table/work area.

Regards

Abhi