Skip to Content
avatar image
Former Member

Using an event of different class in another class

How to use the top_of_page event of cl_gui_alv_grid class in user defined class in se24?

I have already declared an method that acts an event handler of top_of_page event of cl_gui_alv_grid(By going into properties and selecting event handler for).After this, I dont know how to raise this.

Any help will be appreciated.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • Feb 21, 2017 at 06:52 PM

    An event is generally always triggered by the class which declares it (CL_GUI_ALV_GRID in our case). Your handler method will be automatically triggered when the event is raised. But TOP_OF_PAGE is triggered only when the ALV grid is run in background - that will generate an ABAP print list. I doubt it's your goal.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Sandra,

      Thanks for your reply.

      What I am trying to achieve is I have created an event handler method for top_of_page event of cl_gui_alv_grid class in se24. Now, I want to trigger this event handler method of mine so as to display top of page in alv. I have already used set handler method in my report program for this, but still It is not displaying top of page in output.

  • Feb 22, 2017 at 12:43 PM

    TOP_OF_PAGE is triggered only when the ALV grid is run in background, to add lines at the top of each page.

    As your goal is to display some text above the ALV, you should create both a splitter container of 2 rows and an HTML container in the top row, and the ALV in the bottom row. Of course, that would be much simplier to use CL_SALV_TABLE or REUSE_ALV_GRID_DISPLAY, but then you'd also have to adapt your existing code... By the way, if your ALV is displayed inside a dynpro custom container, that would be simpler to add text fields in the dynpro, above the custom container.

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 22, 2017 at 09:39 PM


    interesting fact here is that the using splitter container TOP-OF-PAGE is can print Page heading in the foreground not called while printing or background spool.

    Event TOP-OF-PAGE without split container printed in the spool cannot be displayed in the foreground.

    for foreground you can refer the following steps.

    step 1. Create event handler Method in the local class.

    methods: top_of_page FOR EVENT top_of_page OF cl_gui_alv_grid IMPORTING e_dyndoc_id table_index,         
    print_top_of_page FOR EVENT print_top_of_page OF cl_gui_alv_grid IMPORTING table_index.<br>

    step 2. Implement the methods.

     METHOD top_of_page.
        DATA: text TYPE sdydo_text_element,
              background_id TYPE sdydo_key VALUE 'ALV_BACKGROUND'.
        text = 'Top of Page header'.
        CALL METHOD o_doc->add_text >>>>TYPE REF TO cl_dd_document
            text         = text
            sap_color    = cl_dd_document=>list_positive
            sap_fontsize = cl_dd_document=>large.
        o_doc->new_line( ).
        text = 'Line1'.
        CALL METHOD o_doc->add_text
            text = text.
        CREATE OBJECT oref_html >>>TYPE REF TO cl_gui_html_viewer,
            parent             = container1
            cntl_error         = 1
            cntl_install_error = 2
            dp_install_error   = 3
            dp_error           = 4
            OTHERS             = 5.
        o_doc->html_control = oref_html.
            document = o_doc
            bottom   = space.
        CALL METHOD o_doc->merge_document.
        CALL METHOD o_doc->set_document_background
            picture_id = background_id.
        CALL METHOD oref_doc->display_document
            reuse_control      = 'X'
            parent             = container1
            html_display_error = 1
            OTHERS             = 2.
      ENDMETHOD.                    "create_top_of_page
      METHOD print_top_of_page.
        WRITE:/40 'This is the header of my report' COLOR 5 INTENSIFIED OFF.
        WRITE:/40 'this is the second line of the header of report'.

    step 3. split container and register the Method

     CREATE OBJECT o_container
            container_name              = 'CONTAINER NAME'
            repid                       = 'Report name'
            dynnr                       = 'screen number'.
        CREATE OBJECT o_splitter
            parent            = o_container
            rows              = 2
            columns           = 1.
        CALL METHOD o_splitter->get_container
            row       = 1
            column    = 1
            container = container1.
        CALL METHOD o_splitter->set_row_height
            id                = 1
            height            = 20
            cntl_error        = 1
            cntl_system_error = 2
            OTHERS            = 3.
        CALL METHOD o_splitter->get_container
            row       = 2
            column    = 1
            container = container2.
     *** linking alv grid with container
        CREATE OBJECT o_alv
            i_parent          = container2
            error_cntl_create = 1
            error_cntl_init   = 2
            error_cntl_link   = 3
            error_dp_create   = 4
            OTHERS            = 5.
        CALL METHOD o_alv->set_table_for_first_display
            is_layout                     = layout
            it_outtab                     = i_data
            it_fieldcatalog               = i_fcatalog.
     SET HANDLER local_ref->top_of_page FOR o_alv.
     SET HANDLER local_ref->print_top_of_page FOR o_alv.
       CREATE OBJECT o_doc  >>>>TYPE REF TO cl_dd_document
            style = 'ALV_GRID'.
        CALL METHOD o_doc->initialize_document.
        CALL METHOD o_alv->list_processing_events
            i_event_name = 'TOP_OF_PAGE'
            i_dyndoc_id  = o_doc.

    thank you!!

    Add comment
    10|10000 characters needed characters exceeded