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: 

TOP OF PAGE with CL_GUI_ALV_GRID

Former Member
0 Kudos

Hi all,

how can I set a top-of-page in an alv built with standar class cl_gui_alv_grid?

thanks

enzo

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Enzo,

Refer sample code:

----


  • CLASS v_lcl_event_receiver DEFINITION

----


CLASS lcl_event_receiver DEFINITION.

PUBLIC SECTION.

METHODS:

handle_print_top_of_page FOR EVENT print_top_of_page OF

cl_gui_alv_grid,

handle_top_of_page FOR EVENT top_of_page OF

cl_gui_alv_grid,

ENDCLASS. "o_lcl_event_receiver DEFINITION

data: o_event_receiver TYPE REF TO lcl_event_receiver,

o_html TYPE REF TO cl_dd_document.

----


  • CLASS LCL_EVENT_RECEIVER IMPLEMENTATION

----


CLASS lcl_event_receiver IMPLEMENTATION.

*-- Top of Page

METHOD handle_print_top_of_page.

ENDMETHOD. "handle_print_top_of_page

METHOD handle_top_of_page.

ENDMETHOD. "handle_top_of_page

ENDCLASS. "lcl_event_receiver IMPLEMENTATION

*--Get the containers of the splitter control

o_container_top = o_split->top_left_container.

o_container_bot = o_split->bottom_right_container.

ENDIF.

CREATE OBJECT o_alvgrid

EXPORTING

i_parent = o_container_bot.

*-- Print Top of Page

PERFORM f0041_top_of_page.

FORM f0041_top_of_page.

*

DATA: lws_text TYPE sdydo_text_element.

IF cl_gui_alv_grid=>offline( ) IS INITIAL.

*-- Object for HTML top container

CREATE OBJECT o_html

EXPORTING style = 'ALV_GRID'

background_color = 35.

*-- Top of Page

CALL METHOD o_alvgrid->list_processing_events

EXPORTING

i_event_name = 'TOP_OF_PAGE'

i_dyndoc_id = o_html.

*

*-- Total Record Text

CALL METHOD o_html->add_text

EXPORTING

text = text-049

sap_emphasis = text-051.

*

CALL METHOD o_html->add_gap

EXPORTING

width = 8.

**-- Total record Value

lws_text = cnt_total.

CALL METHOD o_html->add_text

EXPORTING

text = lws_text

sap_emphasis = text-051.

CLEAR lws_text.

CALL METHOD o_html->new_line

EXPORTING

repeat = 1.

*-- Display Report Header

CALL METHOD o_html->display_document

EXPORTING

parent = o_container_top.

ENDIF.

ENDFORM. " f0041_top_of_page

Hope this should solve your issue.

Manish

8 REPLIES 8

Former Member
0 Kudos

Hi

U have to use the event TOP_OF_PAGE

Max

Former Member
0 Kudos

Hi Enzo,

Refer sample code:

----


  • CLASS v_lcl_event_receiver DEFINITION

----


CLASS lcl_event_receiver DEFINITION.

PUBLIC SECTION.

METHODS:

handle_print_top_of_page FOR EVENT print_top_of_page OF

cl_gui_alv_grid,

handle_top_of_page FOR EVENT top_of_page OF

cl_gui_alv_grid,

ENDCLASS. "o_lcl_event_receiver DEFINITION

data: o_event_receiver TYPE REF TO lcl_event_receiver,

o_html TYPE REF TO cl_dd_document.

----


  • CLASS LCL_EVENT_RECEIVER IMPLEMENTATION

----


CLASS lcl_event_receiver IMPLEMENTATION.

*-- Top of Page

METHOD handle_print_top_of_page.

ENDMETHOD. "handle_print_top_of_page

METHOD handle_top_of_page.

ENDMETHOD. "handle_top_of_page

ENDCLASS. "lcl_event_receiver IMPLEMENTATION

<b>Rest find link below:</b>

https://www.sdn.sap.com/irj/sdn/collaboration

Reward points if this Helps.

Manish

0 Kudos

Hi all,

thanks for your answer.

I know the top_of_page event, but it doesn't work, or better, I don't know use it.

I create my event handler class and I register the event top_of_page with set_handler... but it doesn't work.

What do I forgot?

ù

it's my code


*---------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION .
  PUBLIC SECTION.
   METHODS: handle_top_of_page FOR EVENT top_of_page OF cl_gui_alv_grid.

ENDCLASS.                    "lcl_event_handler DEFINITION


*---------------------------------------------------------------------*
*       CLASS lcl_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
  METHOD handle_top_of_page.
    write: 'hello'.
  ENDMETHOD.                    "handle_top_of_page
ENDCLASS.                    "lcl_event_handler IMPLEMENTATION

Former Member
0 Kudos

HI Enzo,

Have you code for Event handle after calling List:

*-- Display Report

CALL METHOD o_alvgrid->set_table_for_first_display

EXPORTING

is_variant = w_variant

i_save = 'A'

is_layout = p_layout

CHANGING

it_outtab = p_output[]

it_fieldcatalog = p_fieldcat[]

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

IF sy-subrc <> 0.

MESSAGE i000(zo_spa) WITH text-077. " Error in Displaying

LEAVE LIST-PROCESSING.

ENDIF.

<b>**-- Create Event object

CREATE OBJECT o_event_receiver.

SET HANDLER o_event_receiver->handle_print_top_of_page

FOR o_alvgrid.</b>

manish

0 Kudos

HI Manish,

I have written all this line of code.

is there any particulare field of layout structure I have to fill?

0 Kudos

Hi Enzo

I believe the problem is in the code of your method:

CLASS lcl_event_handler IMPLEMENTATION.
  METHOD handle_top_of_page.
    write: 'hello'.
  ENDMETHOD.                    "handle_top_of_page
ENDCLASS.                    "lcl_event_handler

The GRID is like a module pool and you can't use a write statament, I believe you have to fill some structure of the event parameter.

The event has the parameter E_DYNDOC_ID (like interface CL_DD_DOCUMENT).

This interface have the method ADD_TEXT probably you have to use it:

*-------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*-------------------------------------------------------*
*
*-------------------------------------------------------*
CLASS lcl_event_handler DEFINITION .
  PUBLIC SECTION.
   METHODS: handle_top_of_page 
               FOR EVENT top_of_page OF cl_gui_alv_grid
                     importing E_DYNDOC_ID.
 
ENDCLASS.                    "lcl_event_handler DEFINITION
 
 
*-------------------------------------------------------*
*       CLASS lcl_event_handler IMPLEMENTATION
*-------------------------------------------------------*
*
*-------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
  METHOD handle_top_of_page.
    CALL METHOD E_DYNDOC_ID->ADD_TEXT
                  EXPORTING TEXT = 'HELLO'.
  ENDMETHOD.                    "handle_top_of_page
ENDCLASS.                    "lcl_event_handler IMPLEMENTATION

Max

0 Kudos

Hi max,

I have tried also with the event parameter, but nothing

Former Member
0 Kudos

Hi Enzo,

Refer sample code:

----


  • CLASS v_lcl_event_receiver DEFINITION

----


CLASS lcl_event_receiver DEFINITION.

PUBLIC SECTION.

METHODS:

handle_print_top_of_page FOR EVENT print_top_of_page OF

cl_gui_alv_grid,

handle_top_of_page FOR EVENT top_of_page OF

cl_gui_alv_grid,

ENDCLASS. "o_lcl_event_receiver DEFINITION

data: o_event_receiver TYPE REF TO lcl_event_receiver,

o_html TYPE REF TO cl_dd_document.

----


  • CLASS LCL_EVENT_RECEIVER IMPLEMENTATION

----


CLASS lcl_event_receiver IMPLEMENTATION.

*-- Top of Page

METHOD handle_print_top_of_page.

ENDMETHOD. "handle_print_top_of_page

METHOD handle_top_of_page.

ENDMETHOD. "handle_top_of_page

ENDCLASS. "lcl_event_receiver IMPLEMENTATION

*--Get the containers of the splitter control

o_container_top = o_split->top_left_container.

o_container_bot = o_split->bottom_right_container.

ENDIF.

CREATE OBJECT o_alvgrid

EXPORTING

i_parent = o_container_bot.

*-- Print Top of Page

PERFORM f0041_top_of_page.

FORM f0041_top_of_page.

*

DATA: lws_text TYPE sdydo_text_element.

IF cl_gui_alv_grid=>offline( ) IS INITIAL.

*-- Object for HTML top container

CREATE OBJECT o_html

EXPORTING style = 'ALV_GRID'

background_color = 35.

*-- Top of Page

CALL METHOD o_alvgrid->list_processing_events

EXPORTING

i_event_name = 'TOP_OF_PAGE'

i_dyndoc_id = o_html.

*

*-- Total Record Text

CALL METHOD o_html->add_text

EXPORTING

text = text-049

sap_emphasis = text-051.

*

CALL METHOD o_html->add_gap

EXPORTING

width = 8.

**-- Total record Value

lws_text = cnt_total.

CALL METHOD o_html->add_text

EXPORTING

text = lws_text

sap_emphasis = text-051.

CLEAR lws_text.

CALL METHOD o_html->new_line

EXPORTING

repeat = 1.

*-- Display Report Header

CALL METHOD o_html->display_document

EXPORTING

parent = o_container_top.

ENDIF.

ENDFORM. " f0041_top_of_page

Hope this should solve your issue.

Manish