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:ย 

Does method CL_GUI_ALV_GRID->SET_VARIANT work?

AlbertoR
Participant
0 Kudos

Dear fellow ABAP developers,

I am using CL_GUI_ALV_GRID to create an editable ALV grid.

Now, I have been asked to set a specific ALV variant (created by us before delivering this report) once the user clicks a button that I added to the toolbar.
I know there is standard functionality to do so (through the usual button for Chosing/Chaging/Saving/Managing Layouts), but the fact is that the button will not only set the different layout, but also set some filters (which I successfully achieved already).

I have seen that method CL_GUI_ALV_GRID->SET_VARIANT exists. I tried to use it, to achieve my result, but calling the method did not work: the layout of the ALV grid stayed the same as before.

In order to be sure 100% to use a correct disvariant structure, I selected (using "INTO CORRESPONDING FIELDS) from table LTDX. Still, no result. I checked the code and actually the method is only changing value of m_cl_variant->ms_variant.
This is a public attribute of class CL_ALV_VARIANT, which is the type of object m_cl_variant. Unluckily, this object is private, so I cannot try to do to much with that. ๐Ÿ˜ž

Since nothing else was performed by that method, I tried also to call method CL_GUI_ALV_GRID->REFRESH_TABLE_DISPLAY afterwards, but still no results. I tried both a soft and a hard refresh.

In the end, I managed to do what I wanted by deleting and recreating the entire grid. But I feel this is not correct and it might raise other kind of issues.

So, does anybody know how to use method CL_GUI_ALV_GRID->SET_VARIANT?

1 ACCEPTED SOLUTION

raymond_giuseppi
Active Contributor

Did you also call grid->refresh_table_display, also consider refreshing layout/field catalog before setting variant.

    call method grid->set_frontend_fieldcatalog
      exporting it_fieldcatalog = gt_fieldcat.
    call method grid->set_frontend_layout
      exporting is_layout = g_layout.
    call method grid->set_variant
      exporting is_variant = g_variant.
    call method grid->refresh_table_display
      exporting
        is_stable      = stable
        i_soft_refresh = 'X'.

Regards,

Raymond

3 REPLIES 3

raymond_giuseppi
Active Contributor

Did you also call grid->refresh_table_display, also consider refreshing layout/field catalog before setting variant.

    call method grid->set_frontend_fieldcatalog
      exporting it_fieldcatalog = gt_fieldcat.
    call method grid->set_frontend_layout
      exporting is_layout = g_layout.
    call method grid->set_variant
      exporting is_variant = g_variant.
    call method grid->refresh_table_display
      exporting
        is_stable      = stable
        i_soft_refresh = 'X'.

Regards,

Raymond

And also method SET_FILTER_CRITERIA.

The characteristics of the ALV layout variant (field catalog, filter, general attributes) can be loaded and retrieved via CL_ALV_VARIANT for instance.

I guess it would work even without using SET_VARIANT. It just gives a name to the current ALV layout variant, so I guess it's useful only in case the user wants to save the layout under that variant name.

AlbertoR
Participant
0 Kudos

Hi, Raymond and Sandra, thank you very much for your answers.
I tried the above, but it did not work, unluckily.

I don't know why: perhaps I make something wrong somewhere else in my code.
Unluckily I cannot spend further time on this single aspect of the project, so even if I really would like to make things much more beautiful I will have to stuck to the "ugly but works" way, which is deleting and re-creating the ALV grid object each time.

If I'll have some time later I will come back to this and try to test further, but for the time being I surrender ๐Ÿ˜ž

Once more, thank you for your help!

Kind regards,

Alberto