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 OO using cl_gui_alv_grid

Former Member
0 Likes
2,045

Hello all,

I'm totally new to OOP so I hope anyone can help me.

I'm using the code below for displaying a layout entered on de selection screen.

*Data declaration

Data: gr_variant TYPE REF TO cl_gui_alv_grid,

gs_variant type disvariant.

*Set layout functions ALV

gr_variant = gr_table->get_variant( ).

gr_variant->get_variant( gs_variant ).

gr_variant->SAVE_VARIANT( save ).

When I'm trying to activate the program it tells me that "get_variant" doesn't exists....

When I double click on "cl_gui_alv_grid" I can find method "Get_variant".

Whats wrong?

knd rgds,

Patrick

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,471

hi,

Please check the attached code:

DATA:alv_grid TYPE REF TO

cl_gui_alv_grid.

CREATE OBJECT ALV_GRID

EXPORTING

I_PARENT = G_CUS_CONTAINER.

MOVE GS_VARIANT TO LS_VARIANT.

CALL METHOD ALV_GRID->GET_VARIANT

IMPORTING

ES_VARIANT = LS_VARIANT

  • E_SAVE =

6 REPLIES 6
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,471

Hello Pat,

I think you missed this stmt:

CREATE OBJECT gr_variant.

Plz try this & hope this will help.

BR,

Suhas

Read only

Former Member
0 Likes
1,471

Hello Suhas,

Thx for the quick reply.

I'm changing an existing program and for other ALV settings they didn't use "Create object". See below code:

*&- ALV grid data definition

DATA: gr_table TYPE REF TO cl_salv_table,

gr_functions TYPE REF TO cl_salv_functions,

gr_display TYPE REF TO cl_salv_display_settings,

gs_layout TYPE salv_s_layout_key,

gr_layout TYPE REF TO cl_salv_layout.

----


IF NOT gt_sbr IS INITIAL.

cl_salv_table=>factory( IMPORTING r_salv_table = gr_table

CHANGING t_table = gt_sbr ).

  • Set ALV functions

gr_functions = gr_table->get_functions( ).

gr_functions->set_all( abap_true ).

  • Set display functions ALV

gr_display = gr_table->get_display_settings( ).

gr_display->set_striped_pattern( cl_salv_display_settings=>true ).

gr_display->set_list_header( lv_header_text ).

  • Set layout functions ALV

gr_layout = gr_table->get_layout( ).

gs_layout-report = sy-repid.

gr_layout->set_key( gs_layout ).

gr_layout->set_save_restriction( cl_salv_layout=>restrict_none ).

*&- Output ALV

gr_table->display( ).

ELSE.

MESSAGE text-t01 TYPE 'I'.

ENDIF.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,471

Hello Pat,

If you see the stmt


cl_salv_table=>factory( IMPORTING r_salv_table = gr_table
CHANGING t_table = gt_sbr ).

The method FACTORY of the class CL_SALV_TABLE is used to "Get New Instance for ALV Table Object".

Inside this method there is a stmt


  create object r_salv_table
    exporting
      display_object = l_display_object
      r_container    = r_container
      container_name = container_name.

So the methos FACTORY creates an instance of CL_SALV_TABLE. But for CL_GUI_ALV_GRID you have to do this in the code.

Hope this helps.

BR,

Suhas

Read only

Former Member
0 Likes
1,472

hi,

Please check the attached code:

DATA:alv_grid TYPE REF TO

cl_gui_alv_grid.

CREATE OBJECT ALV_GRID

EXPORTING

I_PARENT = G_CUS_CONTAINER.

MOVE GS_VARIANT TO LS_VARIANT.

CALL METHOD ALV_GRID->GET_VARIANT

IMPORTING

ES_VARIANT = LS_VARIANT

  • E_SAVE =

Read only

0 Likes
1,471

Ok, as said before I'm totally new to OOP so what is G_CUS_CONTAINER?

LS_VARIANT is the same as GS_VARIANT?

Read only

Former Member
0 Likes
1,471

It took some time to uderstand but I do now so thanks!