Skip to Content

I have noticed that there are many open threads regarding a single topic within the ABAP Development therefore I decided to gather them all up and write a blog with the solution.

This Blog explains how to trigger the TOP_OF_PAGE event in an ALV Report using CL_GUI_ALV_GRID class. I developed a small report and implemented the TOP_OF_PAGE event of CL_GUI_ALV_GRID class, TOP_OF_PAGE event uses the object of class CL_DD_DOCUMENT. In this class there are methods ADD_TEXT, ADD_PICTURE, and ADD_GAP which are useful to to show the contenet in the TOP_OF_PAGE. One important thing is to split the screen into two parts using the splitter container and then use the first part to TOP_OF_PAGE and the second one to show the Grid data. Here is the Simple Report with the Steps. 1.Create the Screen 100, and place the Custom Control in the Screen and Name it as CONTROL. 2.Using the PBO Module set the PF-status and Title Bar

3.Split the Container and Assign the first part to TOP_OF_PAGE and second part to ALV GRID.

4.Have a local class inside the report to Handle the TOP_OF_PAGE event.
Create the Event Handler Object and Set the handler to trigger the TOP_OF_PAGE event. CREATE OBJECT G_GRID
5. Use of methods ADD_TEXT, ADD_PICTURE, ADD_GAP, etc. ADD_TEXT is used to add the text and also you can specify the color,font size,font type. So many friends asked in the forum I want to place the text right aligned instead of left this also can be done with the combination of ADD_TEXT and ADD_GAP, but this is not possible with the ALV FM’s. ADD_PICTURE is used to Add the Logo in the Top of page.Incase of ALV Grid(using FM) the Logo always on Right side.But here you can place where you want. ADD_GAP is used to add the Gap,It can take the paramter width, with that parameter you can maintain the gap between two texts. NEW_LINE is add the New line where ever required. 6.Check the sample output of the Report.
image 7. The complete coding

To report this post you need to login first.


You must be Logged on to comment or reply to a post.

  1. Abdul Hakim
    Hi Vijay,
    Nice work.I too already asked this question in our forum and i have solved it successfully with your solution.Thanks a lot..keep going..
    Congrats for getting 10k man!!!

    Abdul Hakim

      1. Former Member
        Hi Vijay,

        Nice meeting you…This blog is very helpful to everyone…I have an issue in printing the HTML TOP_OF_PAGE in foreground….
        I’m using the FM REUSE_ALV_GRID_DISPLAY and to that passing form routine to i_callback_html_top_of_page exporting parameter…
        And now in my sub-routine i’ve used CL_DD_DOCUMENT class and the methods which you have mentioned like ADD_TEXT and ADD_GAP….. I’m able to display the Header as required, but now the problem is when ever we are trying to print or export to excel the header(TOP_OF_PAGE) is missing….
        Please help me out with some solution.

        Thanks in advance,

        Best Regards,

        1. Former Member
          This is a nice blog…I was able to create top of page info perfectly but the user asked he wanted to see the info in a spread sheet also. I am trying to see how can I achieve this. Anyway thanks Vijay atleast I could get this far using classes. Earlier I always used to rely on the reuse_alv_grid..FM when I needed the top of page.
    1. Former Member
      Hey Vijay,

      Nice to see you here in this forum. We worked together in the very first project of yours. Gimme your contact details and I will get in touch with you.


    1. Vijay Dudla Post author
      Hi Ravikiran,

      Sorry for the delay in reply. Yesterday there is some problem with SDN blogs system. So i am not able to give any reply to you. I checked your business card also to send the mail.
      Any way here is the solution for you…

      in the form DISPLAY you comment the mentioned code.
      I guess there is some problem with your I.E, it is not able to display the html portion. You remove the commented code and check it will work.

      * Creating html control
      *         EXPORTING
      *              PARENT    = O_PARENT_TOP.
      *  ENDIF.
      * Display document

            REUSE_CONTROL      = ‘X’
            PARENT             = O_PARENT_TOP
            HTML_DISPLAY_ERROR = 1.
        IF SY-SUBRC NE 0.
        MESSAGE I999 WITH ‘Error in displaying top-of-page'(036).
      ENDFORM.                    ” display

      we can display the TOP_OF_PAGE with out html control also. If you have any issues let me know.


    2. Former Member

      it not working by commenting html portion as intructions by you.

      i can see only records with header or footer.

      please provide withthe solution.


  2. Former Member

    I used your code….its working fine ..the prob is that top of page is not coming as you have shown here…I have to drag it to bring it to proper shape …then only I am able to see all the content in the top of page ( image and text ) …can you please suggest some solution ?

    1. Vijay Dudla Post author
      Increase the Row height
      Old code..
          ID = 1
          HEIGHT = 5.
      New code
          ID = 1
          HEIGHT = 10.
      If it is not sufficient then try to increase some more height for First Row(on First Row we are showing the top of page).
    1. Vijay Dudla Post author
      For this you need to use another event which is print_top_of_list. in this you can use commentry write function or you can use normal write statements.

        print_top_of_page    for event print_top_of_page
                               of cl_gui_alv_grid.
      method print_top_of_page .
      “here you can call the Function commentry write
      “or you can write write statements also.

      set the handler before calling the display method.

      1. Former Member

        Hi Vijay,

        I have an issue in displaying Logo in OO ALV Grid.

        I’m calling CL_DD_AREA->ADD_PICTURE to display the Logo in TOP_OF_PAGE.

        When I gave the name(PICTURE_ID) as ‘ENJOYSAP_LOGO’, it displayed the Logo in my ALV but when I searched with the same name in SE78, I couldn’t find it there. Instead the name in SE78 for this Logo was ‘ENJOY’.

        If I pass the name as ‘ENJOY’ to the ADD_PICTURE method its not displaying the Logo.

        Later I found the same name ‘ENJOYSAP_LOGO’ in OAER Transaction(with inputs as Class name = ‘PICTURES’, Class type = ‘OT’).

        Is there any relation between SE78 & OAER transactions?

        I have some Custom Logos in SE78 which I want to display in my ALV Top_of_Page.

        When I gave the same Logo name that is showing in SE78, its not displaying it in my ALV report.

        Can we show the Logos in SE78 in our ALV report?

        Thanks & Regards,

        Adithya M.

  3. Former Member
    Hi Vijay,
    i have tried executing the code given by you. it is showing the ALV grid but in the top_of_page there is not a Logo (ENJOYSAP_LOGO).
    I see only text rows but not sap logo..
    Thanks in advance
  4. Former Member
    I used your code. its working fine.

    Top_Of_Page i displayed selected items Qty & Value.

    My Prob is i need to change that Qty & Value when i clicking ALV Check boxes. (triggering Single click event).that mean Top_of_Page content change frequently……

    [Single Click event is perfect, i showed that detail using Layout-Title.]

    How do i do that… Pls Help


  5. Stéphane THOME
    Hi all,

    For Stefano and others, if it can help. Be sure to check that the picture is loaded in the BDS (Business Document Services) via transaction OAOR (and not SE78 for forms graphics)…



  6. Former Member
    Hi Vijay,
    Nice to see the Blog. Looking for more posts from your side.
    I executed your program online, its working fine.
    When tried to run in background. its giving dump.
    Would like to know, for which objects I have to check SY-BATCH NE ‘X’.
    One more Question, diff between events TOP_OF_PAGE and PRINT_TOP_OF_PAGE.
  7. Former Member
    Dear Vijay,

    Thanks for great blog.

    Although by below query is not related to this but kindly reply to the below mentioned issue –

    Can we have DMS images saved thru CV01N directly in ALV without icon or how can we take these images into smartforms.



Leave a Reply