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: 

Using an event of different class in another class

Former Member
0 Kudos

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.

4 REPLIES 4

Sandra_Rossi
Active Contributor
0 Kudos

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.

0 Kudos

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.

Sandra_Rossi
Active Contributor
0 Kudos

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.

Chintu6august
Contributor
0 Kudos

Hello,

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
      EXPORTING
        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
      EXPORTING
        text = text.
 
    CREATE OBJECT oref_html >>>TYPE REF TO cl_gui_html_viewer,
      EXPORTING
        parent             = container1
      EXCEPTIONS
        cntl_error         = 1
        cntl_install_error = 2
        dp_install_error   = 3
        dp_error           = 4
        OTHERS             = 5.

    o_doc->html_control = oref_html.
 
    CALL FUNCTION 'REUSE_ALV_GRID_COMMENTARY_SET'
      EXPORTING
        document = o_doc
        bottom   = space.
 
    CALL METHOD o_doc->merge_document.
 
    CALL METHOD o_doc->set_document_background
      EXPORTING
        picture_id = background_id.
 
    CALL METHOD oref_doc->display_document
      EXPORTING
        reuse_control      = 'X'
        parent             = container1
      EXCEPTIONS
        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'.
  ENDMETHOD.  

step 3. split container and register the Method

 CREATE OBJECT o_container
      EXPORTING
        container_name              = 'CONTAINER NAME'
        repid                       = 'Report name'
        dynnr                       = 'screen number'.
 
 
    CREATE OBJECT o_splitter
      EXPORTING
        parent            = o_container
        rows              = 2
        columns           = 1.
 
    CALL METHOD o_splitter->get_container
      EXPORTING
        row       = 1
        column    = 1
      RECEIVING
        container = container1.
 
    CALL METHOD o_splitter->set_row_height
      EXPORTING
        id                = 1
        height            = 20
      EXCEPTIONS
        cntl_error        = 1
        cntl_system_error = 2
        OTHERS            = 3.

    CALL METHOD o_splitter->get_container
      EXPORTING
        row       = 2
        column    = 1
      RECEIVING
        container = container2.
 
 *** linking alv grid with container
    CREATE OBJECT o_alv
      EXPORTING
        i_parent          = container2
      EXCEPTIONS
        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
      EXPORTING
        is_layout                     = layout
      CHANGING
        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
      EXPORTING
        style = 'ALV_GRID'.
    CALL METHOD o_doc->initialize_document.
    CALL METHOD o_alv->list_processing_events
      EXPORTING
        i_event_name = 'TOP_OF_PAGE'
        i_dyndoc_id  = o_doc.

thank you!!