Display ALV Grid on List Generated by WRITE

By | January 18, 2017 | Tricks | 7,519 | 8

Ever wondered how to generate the ALV Grid on the list generated by WRITE statement. Lets see today how we can do that.


Many years ago I wrote an article (I used to refer them as Post, that time) on how to display the ALV on the selection screen. The idea on displaying the ALV on selection screen is simple – Get the data, create the docking container and display that on the selection screen generated by the program. Read more on that at Display ALV report output in the SAME Selection Screen

For this new way, I was researching how to apply the similar concept on the List generated by the WRITE. I should be fare here – I didn’t thought of working on this until, reader Kousik Mishra raised the question on how to achieve it.

The output is something similar to this:



I will skip the journey as I referred to the earlier post and fast forward to come to the point. The key here is to display the output on the screen generated by the list. When we use the WRITE statement, system uses the specific screen to display that list. The screen is 0120 of the program SAPMSSY0. So, while generating the docking container, I have used that to display the ALV grid.

Code Lines

Here is the complete code:

*& Generates the ALV on the List generated by WRITE
*& Author: Naimesh Patel
REPORT  zalv_grid_on_list_screen NO STANDARD PAGE HEADING.
*  Local class for report
    DATA: t_data   TYPE STANDARD TABLE OF sflight,  " Output data
          r_carrid TYPE RANGE OF sflight-carrid.    " Select Option
ENDCLASS.                    "lcl_report DEFINITION
DATA: o_report TYPE REF TO lcl_report.
DATA: v_carrid TYPE sflight-carrid.
** Selection Screen
SELECT-OPTIONS:   s_carrid FOR v_carrid.
** Initialization
  aaa = 'Selection Criteria'.
** Start of Selection
* object for the report
  CREATE OBJECT o_report.
* Get data
  o_report->r_carrid = s_carrid[].
  o_report->get_data( ).
* generate output
  o_report->write_list( ).
  o_report->generate_alv( ).
* Local Class Implementation
  METHOD get_data.
*   data selection
    SELECT * FROM sflight
           INTO  TABLE me->t_data
           WHERE carrid IN s_carrid.
  ENDMETHOD.                    "get_data
  METHOD write_list.
    WRITE: / 'This list is generated using the Good Old fashioned WRITE'.
    WRITE: / ' --- Total number of records', lines( t_data ).
  METHOD generate_alv.
*   local data
    DATA: lo_dock TYPE REF TO cl_gui_docking_container,
          lo_cont TYPE REF TO cl_gui_container,
          lo_alv  TYPE REF TO cl_salv_table.
    DATA: lv_repid TYPE sy-repid,
          lv_dynnr TYPE sy-dynnr.
    lv_repid = 'SAPMSSY0'.
    lv_dynnr = '0120'.
*   Create a docking control at bottom
    CHECK lo_dock IS INITIAL.
    CREATE OBJECT lo_dock
        repid = lv_repid
        dynnr = lv_dynnr
        ratio = 80
        side  = cl_gui_docking_container=>dock_at_bottom
        name  = 'DOCK_CONT'.
    IF sy-subrc <> 0.
      MESSAGE 'Error in the Docking control' TYPE 'S'.
*   Create a SALV for output
    CHECK lo_alv IS INITIAL.
*       Narrow Casting: To initialize custom container from
*       docking container
        lo_cont ?= lo_dock.
*       SALV Table Display on the Docking container
        CALL METHOD cl_salv_table=>factory
            list_display   = if_salv_c_bool_sap=>false
            r_container    = lo_cont
            container_name = 'DOCK_CONT'
            r_salv_table   = lo_alv
            t_table        = me->t_data.
      CATCH cx_salv_msg .
*   Pf status
    DATA: lo_functions TYPE REF TO cl_salv_functions_list.
    lo_functions = lo_alv->get_functions( ).
    lo_functions->set_default( abap_true ).
*   output display
    lo_alv->display( ).
  ENDMETHOD.                    "generate_ALV
ENDCLASS.                    "lcl_report IMPLEMENTATION

Output with ALV functions applied

Just to make sure all other functions on ALV also works



What do think about this?

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{273 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 273 articles.

Load comments



    This is another good approach to display ALVs. Additional functions such as clicking on header, highlighted texts in header etc can be achieved…

  • Kousik Misra

    Thanks a lot Naimesh. Such a quick response..
    Now i will try the same way and will let you know if i face any issue.

  • Steve Oldner

    Pretty interesting. So this is a container on the write screen? Wonder if field cat changes and events would work here also?

  • Kousik Misra

    Whoa!…everything is working fine now. Thanks a lot Naimesh.

  • @ Steve – Yes they would all work as they are on top of the “legal parent” – Docking container :)

    @ Mohit – Correct. You can either use that as Top of the page, or use the ALV to display certain logs for predefined formatted output (not created by SAPSCript but still using the old WRITE)

    @ Kousik – You welcome!

  • rizu yadav

    Hi Nimesh,

    Your blogs are awesome continuously helping beginners as well as experienced a lot before going through ur articles OOPS concepts are night mare for me but now i feel quite comfortable your way of explaining concepts are very descriptive, logical and you put lot of efforts and research into it and it shows.

    *Requesting you to please come with more and more blogs covering different different SAP ABAP concepts frequently

    Thanks & Br
    Rizu Yadav

  • Wow.. this is interesting. Never thought of this approach earlier. Thanks for the share.


  • rupesh

    Hi Naimesh,

    I have a requirement (Intercative Report) in that output i have to display the header and Item and when the user will select in any header row it will be display corresponding item details in the same screen down side.

    What i try. I have created the report in that it is displaying the both header and corresponding item details but in one shot there is no interactive.

    Thank & Regards,
    Rupesh Chouhan.

Comments on this Post are now closed. If you have something important to share, you can always contact me.

You seem to be new here. Subscribe to stay connected.