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 set default layout for ALV display?

Former Member
0 Kudos

Hi experts,

I'm using reuse_alv_grid_display. I defined a layout and saved it. How can I manage if I want my alv to use this layout as a default and display the list with this layout?

1 ACCEPTED SOLUTION

sreejithmohanm
Employee
Employee
0 Kudos

Hi,

You can hide the particular fields that you do not want to show in your initial layout. You can use the property 'no_out' of the field catalog to achieve this. In program you can write two subroutines, one for creating the field catalog for visible fields and one for hidden fields as follows,

*---- Move hidden fields -


FORM move_field_h USING field text.

gs_slis_fcat-fieldname = field.

gs_slis_fcat-no_out = 'X'.

gs_slis_fcat-seltext_l = text.

APPEND gs_slis_fcat TO gt_slis_fcat.

CLEAR gs_slis_fcat.

ENDFORM.

*---- Move Visible Fields -


FORM move_field USING field text.

gs_slis_fcat-fieldname = field.

gs_slis_fcat-seltext_l = text.

APPEND gs_slis_fcat TO gt_slis_fcat.

CLEAR : gs_slis_fcat.

ENDFORM.

-


And also you can create variants for the ALV display and can provide it as an input parameter to the user.

ALV allows users to save the layout variants.

DATA : LS_VARIANT TYPE DISVARIANT.

PARAMETER : p_var1 TYPE disvariant.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_var1.

PERFORM get_f4variant.

FORM get_f4variant .

DATA: l_variant_help TYPE disvariant,

l_variant TYPE disvariant,

l_exit TYPE c. " User-Exit while F4-Help

l_variant-report = sy-repid.

clear ls_variant.

CALL FUNCTION 'REUSE_ALV_VARIANT_F4'

EXPORTING

is_variant = l_variant

i_save = 'A'

IMPORTING

e_exit = l_exit

es_variant = l_variant_help.

IF l_exit = space.

p_var1 = l_variant_help-variant.

ls_variant-report = sy-repid.

ls_variant-variant = l_variant_help-variant.

ENDIF.

ENDFORM.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = sy-cprog

i_callback_pf_status_set = 'PF-STATUS'

i_callback_user_command = 'USER_COMMAND'

is_layout = gs_slis_layo

i_default = ' '

i_save = 'X'

is_variant = ls_variant

it_fieldcat = gt_slis_fcat

it_sort = gt_sort

  • i_grid_title = text

it_events = gt_events

TABLES

t_outtab = p_it_tab

EXCEPTIONS

program_error = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

Hence, you can make a defualt layout by hiding the unnecessary fields.

The end user if they require they can make their own layout and save it.

This is available in the search help of the parameter.

Select it if required and the ALV will be shown as per the layout variant.

Hope this helps.

BR,

Sreejith

5 REPLIES 5

former_member262988
Active Contributor
0 Kudos

hi,

declare S_LAYOUT TYPE SLIS_LAYOUT_ALV .

now build layout in one of the perform statement as

FORM LAYOUT .

*&&..Set Variant

S_VARIANT-USERNAME = SY-UNAME.

S_VARIANT-REPORT = V_REPID .

V_SAVE = C_A .

*&&..Layout

S_LAYOUT-ZEBRA = C_X .

S_LAYOUT-NO_HLINE = C_X .

S_LAYOUT-COLWIDTH_OPTIMIZE = C_X .

ENDFORM.

and pass this s_layout to reuse_alv_grid_display fm

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_BACKGROUND_ID = 'SIWB_WALLPAPER'

I_CALLBACK_PROGRAM = SY-REPID

  • i_callback_user_command = 'USER_COMMAND'

IS_LAYOUT = S_LAYOUT

IT_FIELDCAT = T_FIELDCAT

IT_SORT = T_SORT[]

I_SAVE = V_SAVE

IS_VARIANT = S_VARIANT

IT_EVENTS = T_EVENTS

TABLES

T_OUTTAB = T_FINAL

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

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

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

ENDIF.

0 Kudos

Am I wrong? I'm using like this:

DATA: gs_layout TYPE slis_layout_alv.

...

gs_layout = 'TEST'.

...

Then I pass:

... is_layout = gs_layout in the function call

Former Member
0 Kudos

Hi,

Save ur layout as default layout (settings->layout->layout management). Then ALV automatically selects it as default layout to display if u have not mentioned any other layout name.

No extra coding is required for it.

Regards,

Joy.

0 Kudos

Dear Joyit,

I want to make it in the program code, is it possible to set the default layout to use during the list display somehow in the program code?

sreejithmohanm
Employee
Employee
0 Kudos

Hi,

You can hide the particular fields that you do not want to show in your initial layout. You can use the property 'no_out' of the field catalog to achieve this. In program you can write two subroutines, one for creating the field catalog for visible fields and one for hidden fields as follows,

*---- Move hidden fields -


FORM move_field_h USING field text.

gs_slis_fcat-fieldname = field.

gs_slis_fcat-no_out = 'X'.

gs_slis_fcat-seltext_l = text.

APPEND gs_slis_fcat TO gt_slis_fcat.

CLEAR gs_slis_fcat.

ENDFORM.

*---- Move Visible Fields -


FORM move_field USING field text.

gs_slis_fcat-fieldname = field.

gs_slis_fcat-seltext_l = text.

APPEND gs_slis_fcat TO gt_slis_fcat.

CLEAR : gs_slis_fcat.

ENDFORM.

-


And also you can create variants for the ALV display and can provide it as an input parameter to the user.

ALV allows users to save the layout variants.

DATA : LS_VARIANT TYPE DISVARIANT.

PARAMETER : p_var1 TYPE disvariant.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_var1.

PERFORM get_f4variant.

FORM get_f4variant .

DATA: l_variant_help TYPE disvariant,

l_variant TYPE disvariant,

l_exit TYPE c. " User-Exit while F4-Help

l_variant-report = sy-repid.

clear ls_variant.

CALL FUNCTION 'REUSE_ALV_VARIANT_F4'

EXPORTING

is_variant = l_variant

i_save = 'A'

IMPORTING

e_exit = l_exit

es_variant = l_variant_help.

IF l_exit = space.

p_var1 = l_variant_help-variant.

ls_variant-report = sy-repid.

ls_variant-variant = l_variant_help-variant.

ENDIF.

ENDFORM.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = sy-cprog

i_callback_pf_status_set = 'PF-STATUS'

i_callback_user_command = 'USER_COMMAND'

is_layout = gs_slis_layo

i_default = ' '

i_save = 'X'

is_variant = ls_variant

it_fieldcat = gt_slis_fcat

it_sort = gt_sort

  • i_grid_title = text

it_events = gt_events

TABLES

t_outtab = p_it_tab

EXCEPTIONS

program_error = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

Hence, you can make a defualt layout by hiding the unnecessary fields.

The end user if they require they can make their own layout and save it.

This is available in the search help of the parameter.

Select it if required and the ALV will be shown as per the layout variant.

Hope this helps.

BR,

Sreejith