‎2008 Jul 19 5:42 PM
hi All,
I am very new to ABAP.
I got a requirement to modify already existing program like , I need to display 5 columns in the ALV Grid basing on a condition i.e., there will be a checkbox on the selection screen. When the cehckbox is checked, hten i should display the 5 columns o n the ALV Grid.
The existing program has a code which is calling the ALV_GRID_DISPLAY function module and the parameters passed are the program and then the structure in se11. The structure contains 30 fields and in the ALV grid , all the 30 fields are displayed.
Now, I need to write the code to add my 5 fields to the already existing ALV Grid display.
when i asked my frnds, they told me to add the 5 fields in the structure taht the program is already using. But , there is a problem. Even though the checkbox is not checked, the empty 5 columns are displayed on the grid as they are already added in the structure. But, we want the 5 columns only when the checkbox on the selction screen is checked.
Please help me out in provding me the code. The program is not using any fieldcatalog. Do i need to addit?
How can i proceedfurther? I am already stuck with it. Please help me out as it is a v urgent requirement.
Regards,
Mohan.
Edited by: Julius Bussche on Jul 19, 2008 8:43 PM
‎2008 Jul 19 7:39 PM
Hi,
Follow these steps:
1. Add ur 5 fields in the structure (in DDIC level)
2. Instead of passing the structure name directly to the FM REUSE_ALV_GRID_DISPLAY pass it to FM REUSE_ALV_FIELDCATALOG_MERGE
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = < ur structure name>
CHANGING
ct_fieldcat = fieldcat[].
3. As in ur case if the check box is checked only then u need to display ur 5 fields..so to do that u need to modify the filed v=catalog table returned by the above FM like:
if check_box = 'X'.
loop at fieldcat into w_cat.
if w_cat-fieldname = 'MYFLD1' or
w_cat-fieldname = 'MYFLD2' or
w_cat-fieldname = 'MYFLD3' or
w_cat-fieldname = 'MYFLD4' or
w_cat-fieldname = 'MYFLD5'.
w_cat-no_out = 'X'.
modify fieldcat from w_cat transporting no_out index sy-tabix.
ENDIF.
endloop.
endif.
4. pass this field catalog table to Fm REUSE_ALV_GRID_DISPLAY instead of the structure name.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_STRUCTURE_NAME = << Comment out this parameter
I_CALLBACK_PROGRAM = g_REPID
iS_LAYOUT = is_layout
it_SORT = It_SORT
it_fieldcat = fieldcat[]
I_SAVE = 'A' "
IS_VARIANT = VARIANT
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
I_GRID_TITLE = 'Special ALV'
TABLES
t_outtab = t_daten.
Hope it will solve ur problem
Regards,
JOy.
‎2008 Jul 19 7:39 PM
Hi,
Follow these steps:
1. Add ur 5 fields in the structure (in DDIC level)
2. Instead of passing the structure name directly to the FM REUSE_ALV_GRID_DISPLAY pass it to FM REUSE_ALV_FIELDCATALOG_MERGE
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = < ur structure name>
CHANGING
ct_fieldcat = fieldcat[].
3. As in ur case if the check box is checked only then u need to display ur 5 fields..so to do that u need to modify the filed v=catalog table returned by the above FM like:
if check_box = 'X'.
loop at fieldcat into w_cat.
if w_cat-fieldname = 'MYFLD1' or
w_cat-fieldname = 'MYFLD2' or
w_cat-fieldname = 'MYFLD3' or
w_cat-fieldname = 'MYFLD4' or
w_cat-fieldname = 'MYFLD5'.
w_cat-no_out = 'X'.
modify fieldcat from w_cat transporting no_out index sy-tabix.
ENDIF.
endloop.
endif.
4. pass this field catalog table to Fm REUSE_ALV_GRID_DISPLAY instead of the structure name.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_STRUCTURE_NAME = << Comment out this parameter
I_CALLBACK_PROGRAM = g_REPID
iS_LAYOUT = is_layout
it_SORT = It_SORT
it_fieldcat = fieldcat[]
I_SAVE = 'A' "
IS_VARIANT = VARIANT
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
I_GRID_TITLE = 'Special ALV'
TABLES
t_outtab = t_daten.
Hope it will solve ur problem
Regards,
JOy.
‎2008 Jul 19 9:46 PM
Welcome to SDN!
I edited your subject title. Please see [the rules|https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/rulesofEngagement] for the reason why I did this.
Cheers,
Julius
‎2008 Jul 20 5:08 AM
hi,
If you want to display only few coloumns, then you have to append your field catlog without using
FM 'REUSE_ALV_FIELDCATLOG_MERGE'.
Since your fieldcatlog is just like a internal table, so you can append it according to your needs. you
have to individualy specify what are your coloumn names, what are their position etc.. once you have
appended it, then pass it in your FM 'REUSE_ALV_GRID_DISPLAY'
‎2008 Jul 20 9:53 AM
I thank everybody for helping me out in this regard.
I will definitely try it out and get back if i have any other queries.
Regards,
Mohan