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: 

How to save a layout in ALV grid.

Former Member
0 Kudos
8,715

hi all,

Im using class concept to display ALV grid. If there is a change in the ALV grid layout that has to be saved in a variant. Which all methods i hve to use for this. Please help.

15 REPLIES 15

Former Member
0 Kudos
537

there is an icon save,,where you select the layout.press then and follow the steps...

Former Member
0 Kudos
537

hi Anu,

you can use the FM REUSE_ALV_VARIANT_SAVE for saving ALV variants.

You can create a parameter in the selection screen, while displaying the ALV with this variant - you just need to populate the IT_VARIANT ( type DISVARIANT) with your prog name and the variant name.

Once you have done that ( along with I_DEFAULT = 'X" and I_SAVE = 'X") , users will be able to save the variants from the ALV menu itself.

Hope this will help.

Regards,

Nitin.

0 Kudos
537

Im using class concept for displaying ALV. not the FM.

please let me know if there is any method for doing the same. PLease help me with some sample code

0 Kudos
537

Hi,

. Managing variants

You can manage display variants by using parameters, u201Cis_variantu201D and u201Ci_saveu201D of u201Cset_table_for_first_displayu201D. Here are options for variant handling. <structure_name> is the variant-defining structure of type u201CDISVARIANTu201D. The field u201Creportu201D in this structure should contain the value of u201Csy-repid.u201D

Mode is_variant i_save

Change current display variant SPACE SPACE

Select and change current display variant <structure_name> SPACE

Select, change and save current display variant <structure_name> u2018Uu2019: Only user-specific

u2018Xu2019: Only global

u2018 Au2019: Both

Regards,

Nagaraj

0 Kudos
537

Hi nagaraj,

what is these u201ci, u201Cis_variantu, u2018Uu2019: , .u201D

Former Member
0 Kudos
537

You can use Display variant

sujeet2918
Active Contributor
0 Kudos
537

Hi Anu,

what you want exactly?

you want to save layout variant or want to call all User saved Variant from selection Screen?

Please tel me so that i can guide you.

Regards,

Sujeet

0 Kudos
537

Yes i want to do both. ie want to save layout variant and want to call all User saved Variant from selection Screen. Could u please help me out.

raymond_giuseppi
Active Contributor
0 Kudos
537

Look at [ALV Gird Control (BC-SRV-ALE)|http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVALV/BCSRVALV.pdf]

Variant and layout related methods are

- [set_table_for_first_display|https://www.sdn.sap.com/irj/scn/advancedsearch?cat=sdn_all&query=set_table_for_first_displayi_saveis_variant&adv=false&sortby=cm_rnd_rankvalue] - Initial dispay of grid

- get_variant - to read a saved layout

- [get_frontend_layout|https://www.sdn.sap.com/irj/scn/advancedsearch?query=get_frontend_layout&cat=sdn_all] - to read current layout

- set_frontend_layout - to change current layout

- refresh_table_display - to redisplay grid (if you change the layout)

- save_variant_dark - give a name to the layout, there wont be any dialog more when saving layout asking fo a name

And function modules (for OO, and not for REUSE which use other structures)

- LVC_VARIANT_DEFAULT_GET

- LVC_VARIANT_EXISTENCE_CHECK

- [LVC_VARIANT_F4|https://www.sdn.sap.com/irj/scn/advancedsearch?query=lvc_variant_f4&cat=sdn_all]

- [LVC_VARIANT_SAVE|https://www.sdn.sap.com/irj/scn/advancedsearch?cat=sdn_all&query=lvc_variant_save&adv=false&sortby=cm_rnd_rankvalue]

- LVC_VARIANT_SELECT

Solution

- Use [set_table_for_first_display|https://www.sdn.sap.com/irj/scn/advancedsearch?cat=sdn_all&query=set_table_for_first_displayi_saveis_variant&adv=false&sortby=cm_rnd_rankvalue], parameters i_save and is_variant to allow/check variant maintenance and save by users (use ii_default if you want to provide the defult variant if none is passed as parameter)

- Use [get_frontend_layout|https://www.sdn.sap.com/irj/scn/advancedsearch?query=get_frontend_layout&cat=sdn_all] and [LVC_VARIANT_SAVE|https://www.sdn.sap.com/irj/scn/advancedsearch?cat=sdn_all&query=lvc_variant_save&adv=false&sortby=cm_rnd_rankvalue] to manage variant in your program as specified in your first post.

- Use [LVC_VARIANT_F4|https://www.sdn.sap.com/irj/scn/advancedsearch?query=lvc_variant_f4&cat=sdn_all] in the selection-screen at value-request on field variant.

Click on the links to find sample at sdn.

Regards

Former Member
0 Kudos
537

use GET_FRONTEND_LAYOUT and SET_FRONTEND_LAYOUT methods of class CL_GUI_ALV_GRID

Former Member
0 Kudos
537

Hi,

Use following piece of code:

DATA : l_layout TYPE disvariant.

l_layout-report = sy-repid.

l_layouth-zebra = 'X'.

CALL METHOD gr_alvgrid->set_table_for_first_display

EXPORTING

I_BUFFER_ACTIVE =

I_BYPASSING_BUFFER =

I_CONSISTENCY_CHECK =

i_structure_name = 'ZQM01'

is_variant = l_layout

i_save = 'A'

I_DEFAULT = 'X'

is_layout = gs_layout

IS_PRINT =

IT_SPECIAL_GROUPS =

IT_TOOLBAR_EXCLUDING =

IT_HYPERLINK =

IT_ALV_GRAPHICS =

IT_EXCEPT_QINFO =

CHANGING

it_outtab = gt_list[]

it_fieldcatalog = gt_fieldcat

IT_SORT =

IT_FILTER =

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4

.

IF sy-subrc 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Regards,

Nitin.

Former Member
0 Kudos
537

HI.

use this code.

Declare variable:

data: it_fieldcat type slis_t_fieldcat_alv,

layout type slis_layout_alv,

wa_fieldcat like line of it_fieldcat.

parameter : pa_vari like disvariant-variant.

"layout variant

create search help for already existing layout variant.

**For layout variant

at selection-screen on value-request for pa_vari.

perform alv_variant_f4 changing pa_vari.

**For layout variant.

if pa_vari is not initial.

v_variant-variant = pa_vari.

endif.

Pass variant to ALV

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

is_variant = v_variant

i_callback_program = sy-repid

is_layout = layout

it_fieldcat = it_fieldcat

i_callback_user_command = 'USER_COMMAND'"c_user_command

i_save = 'A'

tables

t_outtab = it_report3[]

exceptions

program_error = 1.

clear:v_variant.

endform. " alv_report

Create form for lauout

form alv_variant_f4 changing pa_vari.

data: v_nof4 type c.

clear v_nof4.

loop at screen.

if screen-name = 'PA_VARI'.

if screen-input = 0.

v_nof4 = 'X'.

endif.

endif.

endloop.

**for layout variant

v_variant-report = sy-repid.

v_variant-username = sy-uname.

call function 'REUSE_ALV_VARIANT_F4'

exporting

is_variant = v_variant

i_save = 'A'

importing

es_variant = v_variant

exceptions

others = 1.

if sy-subrc = 0 and v_nof4 eq space.

pa_vari = v_variant-variant.

endif.

endform. " ALV_VARIANT_F4

Regards.

Jay

Former Member
0 Kudos
537

Hello,

This will help you.

[;

Thanks,

Jayant

0 Kudos
537

If you want to save the layout is_variant and i_save fields are mandatory.

Try below code

DATA : ls_variant TYPE disvariant.

ls_variant-report = sy-repid.

CALL METHOD gr_alvgrid->set_table_for_first_display

EXPORTING

is_variant = ls_variant

i_save = 'A'

.

Close the thread if it solves your problem