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
EXPORTING I_PARENT = O_PARENT_GRID.
DATA:G_HANDLER TYPE REF TO LCL_EVENT_HANDLER.
CREATE OBJECT G_HANDLER.
SET HANDLER G_HANDLER->TOP_OF_PAGE FOR 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.

26 Comments

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

    Cheers,
    Abdul Hakim

    (0) 
      1. Surya Chaganti
        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,
        Surya

        (0) 
        1. Arvind kumar
          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.
          (0) 
    1. Lakshmi K
      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.

      Thanks.

      (0) 
  2. ravi kiran
    Hi Vijay,
       i have tried executing the code given by you. it is showing the ALV grid but the top_of_page is blank. please suggest solution.
    (0) 
    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.

      FORM DISPLAY.
      * Creating html control
      *  IF O_HTML_CNTRL IS INITIAL.
      *    CREATE OBJECT O_HTML_CNTRL
      *         EXPORTING
      *              PARENT    = O_PARENT_TOP.
      *  ENDIF.
      *  CALL METHOD O_DYNDOC_ID->MERGE_DOCUMENT.
      *  O_DYNDOC_ID->HTML_CONTROL = O_HTML_CNTRL.
      * Display document

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

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

      Regards
      Vijay

      (0) 
    2. rocky robo
      hi

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

      i can see only records with header or footer.

      please provide withthe solution.

      thanx
      rocky

      (0) 
  3. Ravi Gupta
    Hi,

    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 ?

    (0) 
    1. Vijay Dudla Post author
      Increase the Row height
      Old code..
      CALL METHOD O_SPLITTER->SET_ROW_HEIGHT
          EXPORTING
          ID = 1
          HEIGHT = 5.
      New code
      CALL METHOD O_SPLITTER->SET_ROW_HEIGHT
          EXPORTING
          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).
      (0) 
    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.
      endmethod.

      set the handler before calling the display method.

      (0) 
      1. Aadhi Aadhi

        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.

        (0) 
  4. stefano roma
    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..
    Why?
    Thanks in advance
    (0) 
  5. Lakshan Wickramasinghe
    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

    Tnx
    Kosa.

    (0) 
  6. 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)…

    Sincerely,

    Stéphane

    (0) 
  7. VijayaLakshmi Krishnaswamy
    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.
    Regards,
    Viji.
    (0) 
  8. Danish Nadeem
    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.

    thanks,
    hasan

    (0) 

Leave a Reply