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: 

ALV grid display-my columns are multiplying.

Former Member
0 Kudos

I have been searching for the solution for my small problem..So I hope this question hasn`t been asked before.

I have an ALV grid in a pop up display using 'REUSE_ALV_GRID_DISPLAY'.

I have an input field on my screen that helps me display only certain keys on my alv grid.

When I input for example key 2 it shows all the correct products for that key 2.

When I try to enter another key....it shows the correct products but each column is duplicated. So each time I input something and hit 'Show' each column in that table is duplicated again.

Tried REFRESH, CLEAR my internal table....but I haven`t been able to make it work.

Did this happen to anybody ?

Newbie Ilinca

my input module for that screen:

when 'SHOW'.

select col1 col2....

into corresponding fields of table it_display

from ztable

where col1 = ztable2-col1.

CLEAR ls_fieldcatlog.

ls_fieldcatlog-row_pos = '1'.

ls_fieldcatlog-col_pos = '1'.

ls_fieldcatlog-fieldname = 'COL1'.

ls_fieldcatlog-tabname = 'IT_DISPLAY'.

ls_fieldcatlog-seltext_m = 'Infotype'.

APPEND ls_fieldcatlog TO lt_fieldcatlog.

CLEAR ls_fieldcatlog.

ls_fieldcatlog-row_pos = '1'.

ls_fieldcatlog-col_pos = '2'.

ls_fieldcatlog-fieldname = 'COL2'.

ls_fieldcatlog-tabname = 'IT_DISPLAY'.

ls_fieldcatlog-seltext_m = 'Infotype'.

APPEND ls_fieldcatlog TO lt_fieldcatlog.

...

noloyo-zebra = 'X'.

noloyo-colwidth_optimize = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = sy-repid

i_grid_title = 'INFOTYPE DETAILS'

is_layout = noloyo

it_fieldcat = lt_fieldcatlog

i_screen_start_column = 10

i_screen_start_line = 20

i_screen_end_column = 100

i_screen_end_line = 40

TABLES

t_outtab = it_display

EXCEPTIONS

program_error = 1

OTHERS = 2.

AND MY DECL:

TYPES: BEGIN OF type_com,

col1TYPE ztable-col1,

col2TYPE ztable-col2,

....

END OF type_com.

DATA : it_display TYPE STANDARD TABLE OF type_com.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Follow the below code...

when 'SHOW'.

select col1 col2....

into corresponding fields of table it_display

from ztable

where col1 = ztable2-col1.

referesh ls_fieldcatlog[].

CLEAR ls_fieldcatlog.

ls_fieldcatlog-row_pos = '1'.

ls_fieldcatlog-col_pos = '1'.

ls_fieldcatlog-fieldname = 'COL1'.

ls_fieldcatlog-tabname = 'IT_DISPLAY'.

ls_fieldcatlog-seltext_m = 'Infotype'.

APPEND ls_fieldcatlog TO lt_fieldcatlog.

CLEAR ls_fieldcatlog.

ls_fieldcatlog-row_pos = '1'.

ls_fieldcatlog-col_pos = '2'.

ls_fieldcatlog-fieldname = 'COL2'.

ls_fieldcatlog-tabname = 'IT_DISPLAY'.

ls_fieldcatlog-seltext_m = 'Infotype'.

APPEND ls_fieldcatlog TO lt_fieldcatlog.

...

clear ls_fieldcatlog.

noloyo-zebra = 'X'.

noloyo-colwidth_optimize = 'X'.

Ram.

8 REPLIES 8

Dorian
Participant
0 Kudos

It sounds as though the field catalog is not being refreshed; each time you execute 'SHOW' function you are adding a column to the field catalog. To check this, put a break-point before teh APPEND statement and look at the field catalog internal table.

Can I also suggest that you use the new ALV class CL_SALV_TABLE rather than the function module - one of the benefits of the class is that you don't have to manipulate the field catalog. All you do is create an instance of the class via FACTORY method, then call DISPLAY method to output the data. Click "Class documentation" in the class builder for full details.

Regards,

D.

Former Member

Hi,

thats a common issue..

you just need to add this line of code before u are populating your fieldcat.

CODE***

If lt_fieldcatlog is Initial.

      • Fieldcat code****

Endif.

*****

right now, the fieldcat is getting appended repeatidly.

Thanks

Raghav M

Former Member
0 Kudos

Hi,

Please debug and check if your data is being duplicated in teh internal table being passed to fieldcatalog or teh Internal table which contains fieldcatalog.

Ideally Refresh fieldcatalog, just before populating it.

Former Member
0 Kudos

Hi,

Follow the below code...

when 'SHOW'.

select col1 col2....

into corresponding fields of table it_display

from ztable

where col1 = ztable2-col1.

referesh ls_fieldcatlog[].

CLEAR ls_fieldcatlog.

ls_fieldcatlog-row_pos = '1'.

ls_fieldcatlog-col_pos = '1'.

ls_fieldcatlog-fieldname = 'COL1'.

ls_fieldcatlog-tabname = 'IT_DISPLAY'.

ls_fieldcatlog-seltext_m = 'Infotype'.

APPEND ls_fieldcatlog TO lt_fieldcatlog.

CLEAR ls_fieldcatlog.

ls_fieldcatlog-row_pos = '1'.

ls_fieldcatlog-col_pos = '2'.

ls_fieldcatlog-fieldname = 'COL2'.

ls_fieldcatlog-tabname = 'IT_DISPLAY'.

ls_fieldcatlog-seltext_m = 'Infotype'.

APPEND ls_fieldcatlog TO lt_fieldcatlog.

...

clear ls_fieldcatlog.

noloyo-zebra = 'X'.

noloyo-colwidth_optimize = 'X'.

Ram.

former_member212713
Contributor

Hi ilinktrinel;

Please try to below code

first way;


refresh lt_fieldcatlog. "add only this row
CLEAR ls_fieldcatlog.
ls_fieldcatlog-row_pos = '1'.
ls_fieldcatlog-col_pos = '1'.
ls_fieldcatlog-fieldname = 'COL1'.
ls_fieldcatlog-tabname = 'IT_DISPLAY'.
ls_fieldcatlog-seltext_m = 'Infotype'.
APPEND ls_fieldcatlog TO lt_fieldcatlog.
CLEAR ls_fieldcatlog.
ls_fieldcatlog-row_pos = '1'.
ls_fieldcatlog-col_pos = '2'.
ls_fieldcatlog-fieldname = 'COL2'.
ls_fieldcatlog-tabname = 'IT_DISPLAY'.
ls_fieldcatlog-seltext_m = 'Infotype'.

second way;


if lt_fieldcatlog is initial. "add this row
CLEAR ls_fieldcatlog.
ls_fieldcatlog-row_pos = '1'.
ls_fieldcatlog-col_pos = '1'.
ls_fieldcatlog-fieldname = 'COL1'.
ls_fieldcatlog-tabname = 'IT_DISPLAY'.
ls_fieldcatlog-seltext_m = 'Infotype'.
APPEND ls_fieldcatlog TO lt_fieldcatlog.
CLEAR ls_fieldcatlog.
ls_fieldcatlog-row_pos = '1'.
ls_fieldcatlog-col_pos = '2'.
ls_fieldcatlog-fieldname = 'COL2'.
ls_fieldcatlog-tabname = 'IT_DISPLAY'.
ls_fieldcatlog-seltext_m = 'Infotype'.
...
endif. "add this row

Best regards.

koolspy_ultimate
Active Contributor

USE this


if lt_fieldcatlog is initial. 
your code
endif. 

0 Kudos

ok thank you so much for helping me out.

former_member331934
Participant
0 Kudos

Thank you experts. I also had a similar problem. I was trying to make a module program that shows ALV.

In 1st time of clicking show button the number of columns were 5 in my ALV,

clicking back and 2nd time of clicking show button the number of columns were 10,

clicking back and 3rd time of clicking show button the number of columns were 15 and so on...

Writing Refresh before fieldcatalog solved the problem easily.

thanks..