Application Development and Automation 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: 
Read only

ALV variant

Former Member
0 Likes
2,424

Hi,

I've got a problem with ALV Variant. How do i fetch the fieldcat (FM) for the particular display variant

e.g

variant_1

display: field1,field2, field3,field4, field5

variant_2

display: field2,field4,field6

my question is, how do i get the field for the alv layout so that i can assign to the REUSE_ALV_GRID_DISPLAY to supress the respective field.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,751

Fill in parameter IS_VARIANT of the funciton module REUSE_ALV_GRID_DISPLAY with the variant name of the variant you want to display.

If several you can put a parameter on the front screen that yuo can do an F4 on to select the variant like this:

DATA: GX_VARIANT LIKE DISVARIANT,
      G_VARIANT LIKE DISVARIANT,
      G_SAVE.

PARAMETERS: P_VARI  LIKE DISVARIANT-VARIANT.


AT SELECTION-SCREEN.
  G_SAVE = 'A'.

  CLEAR G_VARIANT.
  G_VARIANT-REPORT = sy-repid.

 GX_VARIANT = G_VARIANT.

  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
    EXPORTING
      I_SAVE     = G_SAVE
    CHANGING
      CS_VARIANT = GX_VARIANT
    EXCEPTIONS
      NOT_FOUND  = 2.

  IF SY-SUBRC = 0.
    P_VARI = GX_VARIANT-VARIANT.
  ENDIF.

Then you fill parameter IS_VARIANT in the function module with GX_VARIANT.

See if that works.

Regards

Larissa Maryniuk

Hi,

I've got a problem with ALV Variant. How do i fetch the fieldcat (FM) for the particular display variant

e.g

variant_1

display: field1,field2, field3,field4, field5

variant_2

display: field2,field4,field6

my question is, how do i get the field for the alv layout so that i can assign to the REUSE_ALV_GRID_DISPLAY to supress the respective field.

5 REPLIES 5
Read only

Former Member
0 Likes
1,752

Fill in parameter IS_VARIANT of the funciton module REUSE_ALV_GRID_DISPLAY with the variant name of the variant you want to display.

If several you can put a parameter on the front screen that yuo can do an F4 on to select the variant like this:

DATA: GX_VARIANT LIKE DISVARIANT,
      G_VARIANT LIKE DISVARIANT,
      G_SAVE.

PARAMETERS: P_VARI  LIKE DISVARIANT-VARIANT.


AT SELECTION-SCREEN.
  G_SAVE = 'A'.

  CLEAR G_VARIANT.
  G_VARIANT-REPORT = sy-repid.

 GX_VARIANT = G_VARIANT.

  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
    EXPORTING
      I_SAVE     = G_SAVE
    CHANGING
      CS_VARIANT = GX_VARIANT
    EXCEPTIONS
      NOT_FOUND  = 2.

  IF SY-SUBRC = 0.
    P_VARI = GX_VARIANT-VARIANT.
  ENDIF.

Then you fill parameter IS_VARIANT in the function module with GX_VARIANT.

See if that works.

Regards

Larissa Maryniuk

Read only

shishupalreddy
Active Contributor
0 Likes
1,751

Hello

Check this

PARAMETERS : p_layout LIKE disvariant-variant.

DATA : s_variant LIKE disvariant.

INITIALIZATION.

v_report = sy-repid.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_layout.

PERFORM alv_f4 USING v_report CHANGING p_layout.

&----


*& Form alv_f4

&----


  • F4 for ALV Layout Selection

----


FORM alv_f4 USING p_report

CHANGING p_layout.

s_variant-report = p_report.

CALL FUNCTION 'REUSE_ALV_VARIANT_F4'

EXPORTING

is_variant = s_variant

i_save = 'A'

IMPORTING

es_variant = s_variant

EXCEPTIONS

not_found = 2.

IF sy-subrc = 2.

MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno

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

ELSE.

p_layout = s_variant-variant.

ENDIF.

ENDFORM. " alv_f4

IF p_layout IS INITIAL.

s_variant-variant = '/DEFAULT'.

ELSE.

s_variant-variant = p_layout.

ENDIF.

s_variant-report = v_report.

IF sy-batch = 'X' AND NOT p_layout IS INITIAL.

s_variant-variant = p_layout.

g_r_layo-cwidth_opt = 'X'.

ENDIF.

Final method where we will pass variant

CALL METHOD g_r_grid->set_table_for_first_display

EXPORTING

i_buffer_active = g_c_set

is_variant = s_variant

is_layout = g_r_layo

i_save = 'A'

i_default = g_c_set

CHANGING

it_outtab = t_itab_alv

it_fieldcatalog = g_t_fieldcat.

Regards

Read only

Former Member
0 Likes
1,751

Hello lawrence,

Try this:-

For creating variant you first have to declare like this:

DATA : s_variant TYPE disvariant.

PARAMETER : s_var TYPE disvariant-variant.

Then in initialization event you have to write:

INITIALIZATION.

s_variant-report = sy-repid.

&----


      • TO GET THE DEFAULT VARIANT FOR LAYOUT DISPLAY************

&----


CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'

EXPORTING

i_save = 'A'

CHANGING

cs_variant = s_variant

EXCEPTIONS

wrong_input = 1

not_found = 2

program_error = 3

OTHERS = 4.

IF sy-subrc = 0. " IF DEFAULT VARIANT FOUND

s_var = s_variant-variant. " PASS THE DEFAULT VARIANT RECEIVED TO THE SELECTION SCREEN FIELD

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

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

ENDIF.

Then you can do like this to have an f4 of variants created and to check their existence:

&----


***********TO GET THE LIST OF POSSIBLE VARIANT ENTRIES WHEN THE USER PRESSES F4 BUTTON*********

&----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_var.

CALL FUNCTION 'REUSE_ALV_VARIANT_F4'

EXPORTING

is_variant = s_variant

  • I_TABNAME_HEADER =

  • I_TABNAME_ITEM =

  • IT_DEFAULT_FIELDCAT =

i_save = 'A'

  • I_DISPLAY_VIA_GRID = ' '

IMPORTING

  • E_EXIT =

es_variant = s_variant

EXCEPTIONS

not_found = 1

program_error = 2

OTHERS = 3.

********TO GET THE SELECTED VARIANT FROM THE LIST IN THE SELECTION FIELD******************* .

IF sy-subrc = 0.

s_var = s_variant-variant.

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

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

ENDIF.

&----


********TO CHECK IF THE VARIANT GIVEN EXIST IN THE VASIANT LIST OR NOT************

&----


AT SELECTION-SCREEN.

s_variant-variant = s_var.

CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'

EXPORTING

i_save = 'A'

CHANGING

cs_variant = s_variant

EXCEPTIONS

wrong_input = 1

not_found = 2

program_error = 3

OTHERS = 4.

IF sy-subrc 0.

&----


*********IF VARIANT DOES NOT EXIST ,GIVE WARNING MESSAGE*********************

&----


MESSAGE w000(zgg_msg).

CLEAR s_variant.

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

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

ENDIF.

Read only

Former Member
0 Likes
1,751

Hello

Sorry im not able to write in proper manner.

Read this its working.

Edited by: Vandana Singh on Jun 9, 2009 3:19 PM

Read only

Former Member
0 Likes
1,751

Hi Lawrence,

For the very first time, when you execute the program, there will not be any layout variant. These Layout variants will come in to picuture only when you have selected few fields and saved them as the layput variant.

The functionality can be achieved once you pass I_SAVE = 'A' in the FM of List/Grid. If you pass this, you will get two more icons beside the change layout icon in the menu bar. You can select the layout you wanted, also you can save the layout.

Now, in your selection screen you can also, create a variable of DISVARIANT-VARIANT and take the variant name as input from the user.

Declare one more variable of type DISVARIANT and pass the program name along with the above variable. Use this variable in the IS_VARIANT parameter in the FM of List/Grid.

Simply:

p_var type disvariant-variant.
w_var type disvariant.

w_var-report = sy-repid.
w_var-variant = p_var.

Pass w_var to IS_VARIANT of the List/Grid FM

This should solve your problem

Thanks,

Babu Kilari