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: 

Hiding empty columns in ALV

former_member457420
Participant
0 Kudos

Hi all,

I want to hide some columns in ALV which are empty on display when calling

cl_gui_alv_grid->set_table_for_first_display

That is to say the internaltable will contain empty columns.

I know that using the "no_out" attribute of field catalog we can hide columns.

But the question is how to find these columns which are empty - should I have to loop through the itab to find it out OR

Can we set it in ALV LAYOUT or field catalog attributes so that it wont display empty columns.

any help is appreciated....

Thanks

P

Edited by: pazzuzu on Mar 12, 2010 5:14 PM

1 ACCEPTED SOLUTION

kesavadas_thekkillath
Active Contributor
0 Kudos

Im not sure about this,

you can try

like get all the fields of the internal table.

There are some classes available for this.

Then loop for each field name like for ex.

loop at it_fldname into wa.

read table it_data with key <wa-fieldnames> ne space transporting no fields. " i know not equal to is not possible here ( its just an idea).

if sy-subrc = 0.

column contains data

endif.

endloop.

8 REPLIES 8

kesavadas_thekkillath
Active Contributor
0 Kudos

Im not sure about this,

you can try

like get all the fields of the internal table.

There are some classes available for this.

Then loop for each field name like for ex.

loop at it_fldname into wa.

read table it_data with key <wa-fieldnames> ne space transporting no fields. " i know not equal to is not possible here ( its just an idea).

if sy-subrc = 0.

column contains data

endif.

endloop.

0 Kudos

Thanks keshav...Any more ideas

so using ALV properties is it not possible to hide empty columns?

0 Kudos

hi pazzuzu,

i think your question has the answer in it:

you have to first which columns are empty from your itab only and then accordingly dynamically compose your fieldcat using either the no-out property or not filling that field in the fieldcat itself.

thanks

Sachin Soni

0 Kudos

hi, do u have any more doubts on this ???

0 Kudos

no NOT any more...

Thanks all....

0 Kudos

how to find these columns which are empty

Please let me know how you got the solution ?

0 Kudos

Hi,

If i understood your question correctly,

The you can try this



TYPE-POOLS:slis,abap.

TYPES:BEGIN OF ty,
      f1 TYPE c,
      f2 TYPE c,
      f3 TYPE c,
      f4 TYPE c,
      END OF ty.

DATA:it TYPE TABLE OF ty,
     wa TYPE ty,
     wa_field TYPE slis_fieldcat_alv,
     i_fieldcat TYPE TABLE OF slis_fieldcat_alv,
     i_details TYPE abap_compdescr_tab,
     wa_comp TYPE abap_compdescr,
     ref_descr TYPE REF TO cl_abap_structdescr,
     lv_field TYPE abap_compname.

FIELD-SYMBOLS:<fs>,
              <fs1>.

ref_descr ?= cl_abap_typedescr=>describe_by_data( wa ).
i_details[] = ref_descr->components[].

wa-f1 = 'A'.
wa-f3 = 'C'.
APPEND wa TO it.
wa-f1 = 'X'.
wa-f3 = 'Y'.
APPEND wa TO it.

if it[] is not initial.
LOOP AT i_details INTO wa_comp.
  ASSIGN wa_comp-name TO <fs>.
  SORT it BY (<fs>) DESCENDING.
  CONCATENATE 'WA' '-' <fs> INTO lv_field .
  ASSIGN (lv_field) TO <fs1>.
    READ TABLE it INTO wa INDEX 1 transporting (<fs>).
  IF sy-subrc = 0 AND <fs1> IS NOT INITIAL.
    wa_field-fieldname = wa_comp-name.
    wa_field-seltext_m = wa_comp-name.
    APPEND wa_field TO i_fieldcat.
  ENDIF.
ENDLOOP.


CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    i_callback_program = sy-repid
    it_fieldcat        = i_fieldcat[]
  TABLES
    t_outtab           = it[].
endif.
 

0 Kudos

Hi keshav,

I didnt try it in code but that looks more or less like it...