Skip to Content
0

Does method CL_GUI_ALV_GRID->SET_VARIANT work?

Oct 14, 2016 at 08:56 AM

200

avatar image

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?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Raymond Giuseppi
Oct 14, 2016 at 11:15 AM
3

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded

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.

1
Alberto RADICATI Oct 17, 2016 at 07:56 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded