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: 

problems with SET_VARIANT of class CL_GUI_ALV_GRID

Former Member
0 Kudos

Hello mates,

I am using methods of class CL_GUI_ALV_GRID  to display a list. First the program  displays documents header data but our  customer could chose some rows, press  a buttom and see position information. As the information is different, output structures are different too.

After watching the information , they could press the same buttom and recover the header information.

To change between  two outputs I use REFRESH_TABLE_DISPLAY.  There isn´t any problem until here.

The customer could create or chose an output layout in header data list , after, press the buttom  to see   position information  and  then  come   back to header data. In these cases (when they have chosen a layout ) they  want to see the header list (in this case ) with the layout that they have choosen in previous step.   I try to get this using SET_VARIANT method  (after getting in previous steps the layout with GET_VARIANT), but I haven´t got anything.

This is the part of the code where I call to this method

    REFRESH gt_fieldcat.
   
PERFORM build_fieldcatalog USING ld_estructura.* refrescar el layout
   
CALL METHOD grid1->set_frontend_layout
     
EXPORTING
        is_layout
= ge_layout.

   
CALL METHOD grid1->set_variant
     
EXPORTING
        is_variant
= ls_variant
        i_save    
= 'A'.

* refrescar el catalogo de campos
   
CALL METHOD grid1->set_frontend_fieldcatalog
     
EXPORTING
        it_fieldcatalog
= gt_fieldcat.

* refrecar el informe
   
CALL METHOD grid1->refresh_table_display
     
EXPORTING
        is_stable     
= ls_stable
        i_soft_refresh
= space.

(in this call I have tried with different options but without any satisfactory result )

thanks for your help

Itziar

8 REPLIES 8

Former Member
0 Kudos

Hi,

No sure to get what you're trying to achieve...Is the mthod set_frontend_fieldcatalog not enough (with a previous call to get_frontend_fieldcatalog) ?

Otherwise did you check your ls_variant structure (Is the program name correctly mentionned,..)?

Kr,

Manu.

Former Member
0 Kudos

Hi,

What you need to do is to create a handle for your variant.

Check this wiki.

http://wiki.sdn.sap.com/wiki/display/Snippets/Create+unique+handle+for+ALV+layout+%28variant%29

Also, see similar threads discussed below.

http://scn.sap.com/thread/2092877

http://scn.sap.com/thread/2134329

Thanks,

Shambu

0 Kudos

Hi Shambu,

I  have  implemented what you suggested,
Well it can be interesting but It isn´t that I need. Or perhaps i used it in a wrong way.
I have observed that with this  code,  depending on the output list, the program could show different output variants. This is useful.
But I need something else.

As i have said,  users could change between header data and position data. What they want is:
They execute the program and a list is shown.  Then they choose a variant pushing the buttom "choose layout" (or they create anew variant) , "zvar1"  for example. 

Then they decide that they need to see position data of some of some  rows, so they push a buttom called  "change to position data" and the list is refreshed  and a new report is displayed, with a new structure .

After that user could choose  some rows  and  push the buttom "change to header data" . The list is refreshed again  and header data are shown . 
In this moment, the user  want to see the list with "zvar1" without going to the buttom "Choose  layout " to select the variant.

To do  this i have used the method SET_VARIANT before refreshing  the list. But it doesn´t work as i supposed. I do something similar with method set_filter_criteria and everything is ok.

I don´t know if you understand me.

Thanks for your help,

Itziar

0 Kudos

You are using the same instance (grid1) for the 2 display, then you should save and restore the layout data when leaving/calling the display.

In the PAI or in event raised by a grid, use the following methods to get/save the current data relative to layout

- GET_FRONTEND_LAYOUT

- GET_FRONTEND_FIELDCATALOG

- GET_VARIANT

- GET_SORT_CRITERIA

- GET_FILTER_CRITERIA

In the PBO or during the call of a refresh method, set those data back using

- SET_FRONTEND_LAYOUT

- SET_FRONTEND_FIELDCATALOG

- SET_VARIANT

(etc.)

(NB: The user wont need to save his variant to get back to previous display.

Regards,

Raymond

0 Kudos

Hi Raymond,

I don’t  have problems with  set_sort_criteria. This instrution is working properly but i don’t get the same with set_variant. Have you ever used this instrution? Perhaps i’m not using it properly or it doesn’t work as it is supposed. Well it seems that this method is new because it doesn´t appear in the documentation of this class in help.sap.com

Best regards,

Itziar

0 Kudos

I don't test much this variant, as its sole purpose seems to pre-populate the variant name/handle and save option for user variant dialogs, but has no effect on immediate display of screen.

Usually when switching between different displays I use GET/SET with SORT_CRITERIA, FILTER_CRITERIA, FRONTEND_FIELDCATALOG and  FRONTEND_LAYOUT. (as well as current top cell ids)

Regards,

Raymond

Former Member
0 Kudos

hey,


After  many wrong  test , I think   I got part of  I wanted. The solution is simple, once find it ,of course.

Before calling SET instructions I call to  LVC_VARIANT_SELECT function. With this simple instruction  my problem is solved.

With this  instruction and using the code that Shambu suggested  me,  I think I will get more than  our users want it .

   CALL FUNCTION 'LVC_VARIANT_SELECT'
      EXPORTING
        i_dialog            = space
        i_user_specific     = lv_user_specific
        it_default_fieldcat = Gt_fieldcat
      IMPORTING
        et_fieldcat         = Gt_fieldcat
        et_sort             = Gt_sort
        et_filter           = Gt_filter
      CHANGING
        cs_variant          = Gs_variant
      EXCEPTIONS
        wrong_input         = 1
        fc_not_complete     = 2
        not_found           = 3
        program_error       = 4
        data_missing        = 5
        OTHERS              = 6.
  IF sy-subrc = 0.
* refrescar el layout
    CALL METHOD grid1->set_frontend_layout
      EXPORTING
        is_layout = ge_layout.

* refrescar el catalogo de campos
    CALL METHOD grid1->set_frontend_fieldcatalog
      EXPORTING
        it_fieldcatalog = gt_fieldcat.

    if not gs_variant is INITIAL.
    CALL METHOD grid1->set_variant
      EXPORTING
        is_variant = gs_variant
        i_save     = 'A'.
   endif.


    CALL METHOD grid1->set_sort_criteria
      EXPORTING
        it_sort = gt_sort.



*
    CALL METHOD grid1->set_filter_criteria
      EXPORTING
        it_filter = gt_filter.

* refrecar el informe
    CALL METHOD grid1->refresh_table_display
      EXPORTING
        is_stable      = ls_stable
        i_soft_refresh = SPACE
.
ENDIF.

Thanks, everyone, for your help

Itziar

0 Kudos

Hi Itziar,

I had a tad different requirement to meet. The user didn't want to go back and forth, nor did they want a radio button to use particular layout and then re run with a different radio button to get the different layout.

Using the pointer in this thread, I could achieve the 'toggle' behaviour. I thought I should put it here for the benefit of fellow members.

What I did was this: The report computed the report and then merged the output in a large internal table that had fields of each of the individual layouts. Next, I used the REUSE_ALV_GRID_DISPLAY to display the layout. The FM has its benefits. The developer has to put very little effort to render the report, the output is optimised for the screen size, etc.

Coming to details, I had used the callback i_callback_pf_status_set of the aforesaid FM, to set up the custom GUI Status. That allowed me to have custom buttons. I put two custom buttons to toggle the output. I also used the callback i_callback_user_command of the FM to get the control on user actions. So, when a user would click the custom button, I would get the control. The code for user_commond is here:

FORM user_command USING r_ucomm     TYPE syucomm            "#EC CALLED

                         ls_selfield TYPE slis_selfield.     "#EC NEEDED


DATA: lit_cat    TYPE slis_t_fieldcat_alv,

         lt_cat     TYPE lvc_t_fcat,

         lit_sort   TYPE slis_t_sortinfo_alv,

         lt_filter  TYPE lvc_t_filt.

   DATA: ls_variant TYPE disvariant,

         ls_layout  TYPE lvc_s_layo,

         v_curmod        TYPE numc1.

   DATA: lo_grid    TYPE REF TO cl_gui_alv_grid.

   ls_variant-report = sy-repid.

   CASE r_ucomm.

     WHEN 'WBS'.                                        "First custom button

       ls_variant-variant = '/WBSELEM'.

       v_curmod = c_wbselem.

     WHEN 'MO'.                                          "Second custom button

       ls_variant-variant = '/MAINORD'.

       v_curmod = c_mainord.

     WHEN OTHERS.

       RETURN.

   ENDCASE.

   PERFORM prepare_layout USING    v_curmod

                          CHANGING lit_cat lit_sort.

   CLEAR: sy-subrc.

   CALL FUNCTION 'LVC_TRANSFER_FROM_SLIS'                     "To convert the SLIS based catalog to LVC based one

     EXPORTING

       it_fieldcat_alv = lit_cat

     IMPORTING

       et_fieldcat_lvc = lt_cat

     TABLES

       it_data         = lt_output

     EXCEPTIONS

       it_data_missing = 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.

   CLEAR: sy-subrc.

   CALL FUNCTION 'LVC_VARIANT_SELECT'                    "To setup the variant

     EXPORTING

       i_dialog            = ' '

       i_user_specific     = ' '

       i_default           = ' '

       it_default_fieldcat = lt_cat

     IMPORTING

       es_layout           = ls_layout

       et_filter           = lt_filter

     TABLES

       it_data             = lt_output

     CHANGING

       cs_variant          = ls_variant

     EXCEPTIONS

       wrong_input         = 1

       fc_not_complete     = 2

       not_found           = 3

       program_error       = 4

       data_missing        = 5

       OTHERS              = 6.

   IF sy-subrc <> 0.

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

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

   ENDIF.

   CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'                    "To get the reference of grid

     IMPORTING

       e_grid = lo_grid.

   lo_grid->set_frontend_fieldcatalog( EXPORTING it_fieldcatalog = lt_cat ).     "Setup the new catalog

 

   lo_grid->set_filter_criteria( EXPORTING it_filter = lt_filter ).                          "Setup the new filter

   ls_selfield-refresh = 'X'.                                                                            "To refresh the frontend display


ENDFORM.                    "USER_COMMAND

I got a good help from http://scn.sap.com/thread/3186847 regarding converting the SLIS format to LVC.