Skip to Content
author's profile photo Former Member
Former Member

Hiding/Remove a coloumn in ALV Rep

Hi,

I have developed an ALV report using classes.

Output internal table is dynamically created using method

cl_alv_table_create=>create_dynamic_table and its perfectly working fine.

Now i have to hide/remove the coloumns which doesnt have any values. I am aware of NO_OUT in fieldcatalog, but how can i check whether the coloumn has value or not as my table is being dynamically build.

I cannot use loop at where field <> space as i cant specify the field dynamically in the where clause.

Any hint is really appreciated.

Thanks.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Aug 29, 2006 at 08:44 PM

    Please see the example program, it will show you want you need to do.

    Remember when using the following statement, you can use the column index or the field name explicitly.

    assign component <b>index</b> of structure  <dyn_wa> to <fs>.

    report zrich_0001.
    
    type-pools: slis.
    
    field-symbols: <dyn_table> type standard table,
                   <dyn_wa>.
    
    data: alv_fldcat type slis_t_fieldcat_alv,
          it_fldcat type lvc_t_fcat.
    
    data: p_flds(5) type c value 5.
    
    start-of-selection.
    
    * build the dynamic internal table
      perform build_dyn_itab.
    
    * write 5 records to the alv grid
      do 5 times.
        perform build_report.
      enddo.
    
    * call the alv grid.
      perform call_alv.
    
    
    ************************************************************************
    *  Build_dyn_itab
    ************************************************************************
    form build_dyn_itab.
    
      data: new_table type ref to data,
            new_line  type ref to data,
            wa_it_fldcat type lvc_s_fcat.
    
    * Create fields .
      do p_flds times.
        clear wa_it_fldcat.
        wa_it_fldcat-fieldname = sy-index.
        wa_it_fldcat-datatype = 'CHAR'.
        wa_it_fldcat-intlen = 5.
        append wa_it_fldcat to it_fldcat .
      enddo.
    
    * Create dynamic internal table and assign to FS
      call method cl_alv_table_create=>create_dynamic_table
                   exporting
                      it_fieldcatalog = it_fldcat
                   importing
                      ep_table        = new_table.
    
      assign new_table->* to <dyn_table>.
    
    * Create dynamic work area and assign to FS
      create data new_line like line of <dyn_table>.
      assign new_line->* to <dyn_wa>.
    
    endform.
    
    *********************************************************************
    *      Form  build_report
    *********************************************************************
    form build_report.
    
      data: fieldname(20) type c.
      data: fieldvalue(5) type c.
      field-symbols: <fs1>.
    
      do p_flds times.
    
    * Don't put any values for third column.
        check sy-index <> 3.
    
    * Set up fieldvalue
        fieldvalue = sy-index.
        assign component  sy-index  of structure <dyn_wa> to <fs1>.
        <fs1> =  fieldvalue.
    
      enddo.
    
    * Append to the dynamic internal table
      append <dyn_wa> to <dyn_table>.
    
    
    endform.
    
    ************************************************************************
    *  CALL_ALV
    ************************************************************************
    form call_alv.
    
      data: wa_cat like line of alv_fldcat.
      data: index type i.
    
      field-symbols: <fs>.
      data: counter type i.
    
    
      do p_flds times.
    
    * Find out if the are values for this column
        index = sy-index.
        counter = 0.
        loop at <dyn_table> into <dyn_wa>.
          assign component index of structure  <dyn_wa> to <fs>.
          if sy-subrc  = 0.
            counter = counter + <fs>.
          endif.
        endloop.
    
        clear wa_cat.
    
        wa_cat-fieldname = sy-index.
        wa_cat-seltext_s = sy-index.
        wa_cat-outputlen = '5'.
    
    * If column value is 0, don't show it.
        if counter = 0.
          wa_cat-no_out = 'X'.
        endif.
    
        append wa_cat to alv_fldcat.
    
    
      enddo.
    
    
    * Call ABAP List Viewer (ALV)
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                it_fieldcat = alv_fldcat
           tables
                t_outtab    = <dyn_table>.
    
    endform.
    
    

    Regards,

    Rich Heilman

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.