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-OOPS

Former Member
0 Likes
941

Hi all,

I am new to oops concept...

I want to display ALV using object method..

So is that necessary to take custom container on screen for displaying ALV by OOPS method?

Thanks in advance...

1 ACCEPTED SOLUTION
Read only

former_member402443
Contributor
0 Likes
813

Hi Dhwani shah,

You are asking that is it necessary to take custom container on screen for displaying ALV by OOPS method.

It all depends on the class you are using .

If you are using the class *cl_gui_alv_grid* then you have to create a screen that containing the custom container.

If you are using the class *cl_salv_table* then don't need to define any custom container for getting the ALV grid.

Here I am copying the Example of both the classes .

Now its all depends upon you which class you prefer to use.

Example 1 : *cl_gui_alv_grid*

*-- Global data definitions for ALV

*--- ALV Grid instance reference

DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid .

*--- Name of the custom control added on the screen

DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV' .

*--- Custom container instance reference

DATA gr_ccontainer TYPE REF TO cl_gui_custom_container .

*--- Field catalog table

DATA gt_fieldcat TYPE lvc_t_fcat .

*--- Layout structure

DATA gs_layout TYPE lvc_s_layo .

*--- Internal table holding list data

DATA BEGIN OF gt_list OCCURS 0 .

INCLUDE STRUCTURE SFLIGHT .

*--In further sections, some additional fields will added here

*--for some functionality

DATA END OF gt_list .

DATA :gt_sflight like standard TABLE OF gt_list.

START-OF-SELECTION.

CALL SCREEN '0400'.

&----


*& Module STATUS_0400 OUTPUT

&----


  • text

----


MODULE STATUS_0400 OUTPUT.

SET PF-STATUS 'ZMNU'.

perform display_alv.

ENDMODULE. " STATUS_0400 OUTPUT

&----


*& Module USER_COMMAND_0400 INPUT

&----


  • text

----


MODULE USER_COMMAND_0400 INPUT.

CASE SY-UCOMM.

WHEN 'BACK' OR 'EXIT' OR 'RW'.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " USER_COMMAND_0400 INPUT

&----


*& Form display_alv

&----


  • text

----


form display_alv.

SELECT * FROM SFLIGHT INTO TABLE GT_SFLIGHT UP TO 30 ROWS.

IF gr_alvgrid IS INITIAL .

*----Creating custom container instance

CREATE OBJECT gr_ccontainer

EXPORTING

container_name = gc_custom_control_name

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5

others = 6 .

IF sy-subrc <> 0.

  • --Exception handling

ENDIF.

*----Creating ALV Grid instance

CREATE OBJECT gr_alvgrid

EXPORTING

i_parent = gr_ccontainer

EXCEPTIONS

error_cntl_create = 1

error_cntl_init = 2

error_cntl_link = 3

error_dp_create = 4

others = 5 .

IF sy-subrc <> 0.

  • *--Exception handling

ENDIF.

*----Preparing field catalog.

PERFORM prepare_field_catalog CHANGING gt_fieldcat .

*----Preparing layout structure

PERFORM prepare_layout CHANGING gs_layout .

*----Here will be additional preparations

*--e.g. initial sorting criteria, initial filtering criteria, excluding

*--functions

CALL METHOD gr_alvgrid->set_table_for_first_display

EXPORTING

  • I_STRUCTURE_NAME = 'SFLIGHT'

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

is_layout = gs_layout

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • IT_TOOLBAR_EXCLUDING =

  • IT_HYPERLINK =

CHANGING

it_outtab = gt_sflight[]

it_fieldcatalog = gt_fieldcat

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4 .

IF sy-subrc <> 0.

  • --Exception handling

ENDIF.

ELSE .

CALL METHOD gr_alvgrid->refresh_table_display

  • EXPORTING

  • IS_STABLE =

  • I_SOFT_REFRESH =

EXCEPTIONS

finished = 1

OTHERS = 2 .

IF sy-subrc <> 0.

*--Exception handling

ENDIF.

ENDIF .

endform. "display_alv

&----


*& Form prepare_field_catalog

&----


  • text

----


  • -->PT_FIELDCATtext

----


FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat .

*---Preparing field catalog manually

*DATA ls_fcat type lvc_s_fcat .

*ls_fcat-fieldname = 'CARRID' .

*ls_fcat-inttype = 'C' .

*ls_fcat-outputlen = '3' .

*ls_fcat-coltext = 'Carrier ID' .

*ls_fcat-seltext = 'Carrier ID' .

*ls_fcat-drdn_hndl = '1' .

*APPEND ls_fcat to pt_fieldcat .

*CLEAR ls_fcat .

*ls_fcat-fieldname = 'CONNID' .

*ls_fcat-ref_table = 'SFLIGHT' .

*ls_fcat-ref_table = 'CONNID' .

*ls_fcat-outputlen = '3' .

*ls_fcat-coltext = 'Connection ID' .

*ls_fcat-seltext = 'Connection ID' .

*APPEND ls_fcat to pt_fieldcat .

*---Preparing field catalog semi-automatically

DATA ls_fcat type lvc_s_fcat .

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

i_structure_name = 'SFLIGHT'

CHANGING

ct_fieldcat = pt_fieldcat[]

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

IF sy-subrc <> 0.

*--Exception handling

ENDIF.

LOOP AT pt_fieldcat INTO ls_fcat .

CASE ls_fcat-fieldname .

WHEN 'CARRID' .

ls_fcat-outputlen = '10' .

ls_fcat-coltext = 'Airline Carrier ID' .

ls_fcat-drdn_hndl = '1' .

MODIFY pt_fieldcat FROM ls_fcat .

WHEN 'PAYMENTSUM' .

ls_fcat-no_out = 'X' .

MODIFY pt_fieldcat FROM ls_fcat .

ENDCASE .

ENDLOOP .

ENDFORM . "prepare_field_catalog

&----


*& Form prepare_layout

&----


  • text

----


  • -->PS_LAYOUT text

----


FORM prepare_layout CHANGING ps_layout TYPE lvc_s_layo.

ps_layout-zebra = 'X' .

ps_layout-grid_title = 'Flights' .

ps_layout-smalltitle = 'X' .

ENDFORM. " prepare_layout

Example 2: cl_salv_table

data: gt_outtab type table of sflight.

data: toolbar type ref to cl_salv_functions_list .

data: gr_table type ref to cl_salv_table.

data: lr_aggregations type ref to cl_salv_aggregations.

data: lr_groups type ref to cl_salv_sorts .

select * from sflight into corresponding fields of table gt_outtab.

call method cl_salv_table=>factory

importing

r_salv_table = gr_table

changing

t_table = gt_outtab.

lr_aggregations = gr_table->get_aggregations( ).

toolbar = gr_table->get_functions( ) .

toolbar->set_all(

value = if_salv_c_bool_sap=>true

).

lr_aggregations->clear( ).

lr_groups = gr_table->get_sorts( ) .

lr_groups->clear( ).

try.

lr_groups->add_sort(

columnname = 'CARRID'

position = 8

subtotal = abap_true

sequence = if_salv_c_sort=>sort_up ).

catch cx_salv_not_found cx_salv_data_error cx_salv_existing.

endtry.

try.

lr_aggregations->add_aggregation( columnname = 'SEATSMAX' ).

catch cx_salv_not_found cx_salv_data_error cx_salv_existing.

endtry.

gr_table->display( ).

Reward points, if useful.

Regards,

Manoj Kumar

7 REPLIES 7
Read only

Former Member
0 Likes
813

hi,

take a look at this document:

[https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/acdefb13-0701-0010-f1a2-8eeefa7d3780]

Read only

0 Likes
813

hi

thanks.

I have this document so i am asking that is it necessary to take screen for ALV oops.

Because when we display ALV in simple method ( without ALV) we dont need Screen so....

Read only

Former Member
0 Likes
813

Hai Dhwani shah ,

yaa its necessary to take custom container on screen for displaying ALV by OOPS

Follow this example its give brief idea about ALV-OOPS

REPORT YSU_REPORT_ALV_OOP .

TABLES:VBAK,VBAP,LIKP,VTTP,VBRK.

SELECT-OPTIONS:S_VBELN FOR VBAK-VBELN,

S_ERDAT FOR VBAK-ERDAT.

PARAMETERS:P_KUNNR like VBAK-KUNNR.

DATA:WA TYPE YSUSTR_ALVOOP,

ITAB TYPE YSUSTR_ALVOOP2.

DATA:IDENTITY TYPE REF TO CL_GUI_CUSTOM_CONTAINER,

GRID TYPE REF TO CL_GUI_ALV_GRID,

L_IDENTITY TYPE REF TO CL_GUI_CUSTOM_CONTAINER,

L_TREE TYPE REF TO CL_GUI_ALV_TREE_SIMPLE,

L_LIST TYPE SLIS_T_LISTHEADER,

L_LOGO TYPE SDYDO_VALUE.

CLASS CL_LC DEFINITION.

PUBLIC SECTION.

METHODS DC FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID IMPORTING E_ROW

E_COLUMN.

ENDCLASS.

CLASS CL_LC IMPLEMENTATION.

METHOD DC .

DATA:WA1 TYPE YSUSTR_ALVOOP.

*DATA:WA1 TYPE YSU_L.

READ TABLE ITAB INDEX E_ROW-INDEX INTO WA1.

SET PARAMETER ID 'AVN' FIELD WA1-VBELN.

CALL TRANSACTION 'VA02' AND SKIP FIRST SCREEN.

ENDMETHOD.

ENDCLASS.

DATA:OBJ_CL_LC TYPE REF TO CL_LC.

START-OF-SELECTION.

PERFORM SELECT_DATA.

IF SY-SUBRC = 0.

CALL SCREEN 100.

ELSE.

MESSAGE I000(0) WITH 'NO DATA FOUND'.

*write:/ 'Sss' ,SY-SUBRC.

ENDIF.

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE STATUS_0100 OUTPUT.

  • SET PF-STATUS 'xxxxxxxx'.

  • SET TITLEBAR 'xxx'.

IF IDENTITY IS INITIAL.

CREATE OBJECT IDENTITY

EXPORTING

CONTAINER_NAME = 'ALVCONTROL'.

CREATE OBJECT GRID

EXPORTING

I_PARENT = IDENTITY.

CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

I_STRUCTURE_NAME = 'YSU_L'

CHANGING

IT_OUTTAB = ITAB.

ENDIF.

CALL METHOD GRID->REFRESH_TABLE_DISPLAY.

CREATE OBJECT OBJ_CL_LC.

SET HANDLER OBJ_CL_LC->DC FOR GRID.

IF L_IDENTITY IS INITIAL.

CREATE OBJECT L_IDENTITY

EXPORTING

CONTAINER_NAME = 'LOGO'.

CREATE OBJECT L_TREE

EXPORTING

I_PARENT = L_IDENTITY .

PERFORM LOGOSUB USING L_LOGO.

CALL METHOD L_TREE->CREATE_REPORT_HEADER

EXPORTING

IT_LIST_COMMENTARY = L_LIST

I_LOGO = L_LOGO.

ENDIF.

ENDMODULE." STATUS_0100 OUTPUT

FORM LOGOSUB USING P_LOGO.

P_LOGO = 'SU_LOGO'.

ENDFORM.

FORM SELECT_DATA.

SELECT VBAPVBELN VBAPKWMENG VBAP~NETWR INTO TABLE ITAB FROM VBAK

INNER JOIN VBAP ON VBAKVBELN = VBAPVBELN WHERE VBAK~KUNNR = P_KUNNR

AND VBAKVBELN IN S_VBELN AND VBAKERDAT IN S_ERDAT.

ENDFORM.

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE USER_COMMAND_0100 INPUT.

CASE SY-UCOMM.

WHEN 'EXIT'.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

give some reward point if it helps.

regards,

surya.

Read only

former_member402443
Contributor
0 Likes
814

Hi Dhwani shah,

You are asking that is it necessary to take custom container on screen for displaying ALV by OOPS method.

It all depends on the class you are using .

If you are using the class *cl_gui_alv_grid* then you have to create a screen that containing the custom container.

If you are using the class *cl_salv_table* then don't need to define any custom container for getting the ALV grid.

Here I am copying the Example of both the classes .

Now its all depends upon you which class you prefer to use.

Example 1 : *cl_gui_alv_grid*

*-- Global data definitions for ALV

*--- ALV Grid instance reference

DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid .

*--- Name of the custom control added on the screen

DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV' .

*--- Custom container instance reference

DATA gr_ccontainer TYPE REF TO cl_gui_custom_container .

*--- Field catalog table

DATA gt_fieldcat TYPE lvc_t_fcat .

*--- Layout structure

DATA gs_layout TYPE lvc_s_layo .

*--- Internal table holding list data

DATA BEGIN OF gt_list OCCURS 0 .

INCLUDE STRUCTURE SFLIGHT .

*--In further sections, some additional fields will added here

*--for some functionality

DATA END OF gt_list .

DATA :gt_sflight like standard TABLE OF gt_list.

START-OF-SELECTION.

CALL SCREEN '0400'.

&----


*& Module STATUS_0400 OUTPUT

&----


  • text

----


MODULE STATUS_0400 OUTPUT.

SET PF-STATUS 'ZMNU'.

perform display_alv.

ENDMODULE. " STATUS_0400 OUTPUT

&----


*& Module USER_COMMAND_0400 INPUT

&----


  • text

----


MODULE USER_COMMAND_0400 INPUT.

CASE SY-UCOMM.

WHEN 'BACK' OR 'EXIT' OR 'RW'.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " USER_COMMAND_0400 INPUT

&----


*& Form display_alv

&----


  • text

----


form display_alv.

SELECT * FROM SFLIGHT INTO TABLE GT_SFLIGHT UP TO 30 ROWS.

IF gr_alvgrid IS INITIAL .

*----Creating custom container instance

CREATE OBJECT gr_ccontainer

EXPORTING

container_name = gc_custom_control_name

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5

others = 6 .

IF sy-subrc <> 0.

  • --Exception handling

ENDIF.

*----Creating ALV Grid instance

CREATE OBJECT gr_alvgrid

EXPORTING

i_parent = gr_ccontainer

EXCEPTIONS

error_cntl_create = 1

error_cntl_init = 2

error_cntl_link = 3

error_dp_create = 4

others = 5 .

IF sy-subrc <> 0.

  • *--Exception handling

ENDIF.

*----Preparing field catalog.

PERFORM prepare_field_catalog CHANGING gt_fieldcat .

*----Preparing layout structure

PERFORM prepare_layout CHANGING gs_layout .

*----Here will be additional preparations

*--e.g. initial sorting criteria, initial filtering criteria, excluding

*--functions

CALL METHOD gr_alvgrid->set_table_for_first_display

EXPORTING

  • I_STRUCTURE_NAME = 'SFLIGHT'

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

is_layout = gs_layout

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • IT_TOOLBAR_EXCLUDING =

  • IT_HYPERLINK =

CHANGING

it_outtab = gt_sflight[]

it_fieldcatalog = gt_fieldcat

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4 .

IF sy-subrc <> 0.

  • --Exception handling

ENDIF.

ELSE .

CALL METHOD gr_alvgrid->refresh_table_display

  • EXPORTING

  • IS_STABLE =

  • I_SOFT_REFRESH =

EXCEPTIONS

finished = 1

OTHERS = 2 .

IF sy-subrc <> 0.

*--Exception handling

ENDIF.

ENDIF .

endform. "display_alv

&----


*& Form prepare_field_catalog

&----


  • text

----


  • -->PT_FIELDCATtext

----


FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat .

*---Preparing field catalog manually

*DATA ls_fcat type lvc_s_fcat .

*ls_fcat-fieldname = 'CARRID' .

*ls_fcat-inttype = 'C' .

*ls_fcat-outputlen = '3' .

*ls_fcat-coltext = 'Carrier ID' .

*ls_fcat-seltext = 'Carrier ID' .

*ls_fcat-drdn_hndl = '1' .

*APPEND ls_fcat to pt_fieldcat .

*CLEAR ls_fcat .

*ls_fcat-fieldname = 'CONNID' .

*ls_fcat-ref_table = 'SFLIGHT' .

*ls_fcat-ref_table = 'CONNID' .

*ls_fcat-outputlen = '3' .

*ls_fcat-coltext = 'Connection ID' .

*ls_fcat-seltext = 'Connection ID' .

*APPEND ls_fcat to pt_fieldcat .

*---Preparing field catalog semi-automatically

DATA ls_fcat type lvc_s_fcat .

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

i_structure_name = 'SFLIGHT'

CHANGING

ct_fieldcat = pt_fieldcat[]

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

IF sy-subrc <> 0.

*--Exception handling

ENDIF.

LOOP AT pt_fieldcat INTO ls_fcat .

CASE ls_fcat-fieldname .

WHEN 'CARRID' .

ls_fcat-outputlen = '10' .

ls_fcat-coltext = 'Airline Carrier ID' .

ls_fcat-drdn_hndl = '1' .

MODIFY pt_fieldcat FROM ls_fcat .

WHEN 'PAYMENTSUM' .

ls_fcat-no_out = 'X' .

MODIFY pt_fieldcat FROM ls_fcat .

ENDCASE .

ENDLOOP .

ENDFORM . "prepare_field_catalog

&----


*& Form prepare_layout

&----


  • text

----


  • -->PS_LAYOUT text

----


FORM prepare_layout CHANGING ps_layout TYPE lvc_s_layo.

ps_layout-zebra = 'X' .

ps_layout-grid_title = 'Flights' .

ps_layout-smalltitle = 'X' .

ENDFORM. " prepare_layout

Example 2: cl_salv_table

data: gt_outtab type table of sflight.

data: toolbar type ref to cl_salv_functions_list .

data: gr_table type ref to cl_salv_table.

data: lr_aggregations type ref to cl_salv_aggregations.

data: lr_groups type ref to cl_salv_sorts .

select * from sflight into corresponding fields of table gt_outtab.

call method cl_salv_table=>factory

importing

r_salv_table = gr_table

changing

t_table = gt_outtab.

lr_aggregations = gr_table->get_aggregations( ).

toolbar = gr_table->get_functions( ) .

toolbar->set_all(

value = if_salv_c_bool_sap=>true

).

lr_aggregations->clear( ).

lr_groups = gr_table->get_sorts( ) .

lr_groups->clear( ).

try.

lr_groups->add_sort(

columnname = 'CARRID'

position = 8

subtotal = abap_true

sequence = if_salv_c_sort=>sort_up ).

catch cx_salv_not_found cx_salv_data_error cx_salv_existing.

endtry.

try.

lr_aggregations->add_aggregation( columnname = 'SEATSMAX' ).

catch cx_salv_not_found cx_salv_data_error cx_salv_existing.

endtry.

gr_table->display( ).

Reward points, if useful.

Regards,

Manoj Kumar

Read only

0 Likes
813

hi,

thanks a lot...

But can u explain ur second example ...?

If u can than it would b great help...

Read only

0 Likes
813

Hi Dhwani shah ,

In Second Example I am using the cl_salv_table grid.

In this first i am creating a instance (object) of class using

FACTORY -> Creates an instance of the ALV table object.

Then I am refering variable for l_salv_functions_list for displaying the common function on the ALV grid.

cl_salv_aggregations for aggregations on some field

cl_salv_sorts -> to sort the grid on the basis on some field.

In the lr_aggregations->add_aggregation( columnname = 'SEATSMAX' ) i am passing the fieldname on which i want the subtotal.

The lr_groups->add_sort(

columnname = 'CARRID'

position = 8

subtotal = abap_true

sequence = if_salv_c_sort=>sort_up )

sorts the grid based on the carried id.

Finally gr_table->display( ), display the alv grid on the screen.

As you more and more on this class in the Tcode SE24 ,

you will get better idea of using this class.

Regards,

Manoj Kumar

Read only

Former Member
0 Likes
813

Hi,

No it is not neccesary.

you can use cl_salv_table for ALV Grid display:

Example Code:

*&----


*

*& Report ZSB_TEST007

*&

*&----


*

REPORT zsb_test007.

DATA: gt_outtab TYPE TABLE OF sflight.

DATA: gr_table TYPE REF TO cl_salv_table.

DATA: gr_functions TYPE REF TO cl_salv_functions_list,

lr_functions TYPE REF TO cl_salv_functions,

lr_events TYPE REF TO cl_salv_events_table.

DATA: name TYPE string.

DATA: lr_columns TYPE REF TO cl_salv_columns,

lr_column TYPE REF TO cl_salv_column_table,

oref TYPE REF TO cx_root.

CONSTANTS: gc_true TYPE sap_bool VALUE 'X'.

*----


*

  • CLASS lcl_handle_events DEFINITION

*----


*

  • §5.1 define a local class for handling events of cl_salv_table

*----


*

CLASS lcl_handle_events DEFINITION.

PUBLIC SECTION.

METHODS:

on_user_command FOR EVENT added_function OF cl_salv_events

IMPORTING e_salv_function.

ENDCLASS. "lcl_handle_events DEFINITION

*----


*

  • CLASS lcl_handle_events IMPLEMENTATION

*----


*

*

*----


*

CLASS lcl_handle_events IMPLEMENTATION.

METHOD on_user_command.

PERFORM show_function USING e_salv_function text-i08.

ENDMETHOD. "on_user_command

ENDCLASS. "lcl_handle_events IMPLEMENTATION

*START OF SELECTION.

START-OF-SELECTION.

PERFORM select_data.

*END OF SELECTION

END-OF-SELECTION.

PERFORM display_data.

*&----


*

*& Form show_function

*&----


*

  • text

*----


*

  • -->U_FUNCTION text

  • -->U_TEXT text

*----


*

FORM show_function USING

u_function TYPE salv_de_function

u_text TYPE string.

  • DATA: l_string TYPE string.

*

  • CONCATENATE u_text u_function INTO l_string SEPARATED BY space.

*

  • MESSAGE l_string TYPE 'I'.

DATA : code(4) type c.

MESSAGE 'YOU WANT TO CREATE MATERIAL' TYPE 'I'.

IF sy-ucomm = 'ENTR'.

CALL TRANSACTION 'MM01'.

endif.

if sy-ucomm = 'WB_EXEC'.

LEAVE program.

ENDIF.

ENDFORM. "show_function

*&----


*

*& Form select_data

*&----


*

  • text

*----


*

FORM select_data.

SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE gt_outtab.

ENDFORM. "select_data

*&----


*

*& Form display_data

*&----


*

  • text

*----


*

FORM display_data.

DATA: gr_events TYPE REF TO lcl_handle_events.

TRY.

*... Create Instance

CALL METHOD cl_salv_table=>factory

IMPORTING

r_salv_table = gr_table

CHANGING

t_table = gt_outtab.

CREATE OBJECT gr_functions.

lr_functions = gr_table->get_functions( ).

lr_functions->set_all( gc_true ).

lr_columns = gr_table->get_columns( ).

lr_columns->set_optimize( gc_true ).

*... Set Aggregation Functions

  • name = 'SET_SUBTOTALS'.

  • gr_functions = gr_table->get_functions( ).

  • gr_functions->set_subtotals( 'X' ).

CALL METHOD gr_table->set_screen_status

EXPORTING

report = sy-repid

pfstatus = 'ZPFOOPS'

set_functions = gr_table->c_functions_all.

CATCH cx_salv_msg INTO oref.

ENDTRY.

TRY.

CALL METHOD lr_functions->add_function(

EXPORTING

name = 'MYFUNC'

  • ICON =

text = 'ADDED'

tooltip = 'JUSTFUNCTION'

position = if_salv_c_function_position=>right_of_salv_functions )

.

CATCH cx_salv_existing INTO oref.

CATCH cx_salv_wrong_call INTO oref.

ENDTRY.

lr_events = gr_table->get_event( ).

CREATE OBJECT gr_events.

*... §6.1 register to the event USER_COMMAND

SET HANDLER gr_events->on_user_command FOR lr_events.

gr_table->display( ).

ENDFORM. "display_data

Regards,

Sachin Bhatnagar