Display ALV report output in the SAME Selection Screen

By | October 23, 2008 | Tricks | 84,564 | 29

Shows the way to display the report output in the same selection screen using Docking Container and SLAV 2D Table display with minimal coding

Preface

I was searching for the option to display the report output on the same selection-screen from quite a long time. SDN Forum thread How can i display output in the same selection screen reminded me again to research on this topic.

After a lot of analysis (and of course Trials-&-Errors), I found the solution which requires minimal development. Before giving the solution, check out how it looks-

When we start running the report, it will be a normal Selection Screen:

After executing the report, our output will overlay on the Selection Screen. And it will look like this:

Doesn’t it look good ?

Journey to find the solution:

After reading the problem in the thread, suddenly I got a strike: Why not to create a Docking Container and place the ALV inside it..!!

I have started with placing the docking container in the INITIALIZATION event and the code to generate the ALV in the START-OF-SELECTION event. In this try, I got the docking container on the selection screen but no ALV inside of that docking container. Than I realize that I missed on of the basics of report programming – as soon as control goes to INITALIZATION all memory allocation will be destroyed and global data will be initialized. That’s why I was not getting the ALV in the docking container. Selection screen was looking like this:

So, I moved the ALV logic in the INITALIZATION event. After this try, I got the Docking container with the empty ALV – ALV with the field catalog but no Data. Here again, I have the same problem – all my data allocation got destroyed as soon as control come to INITALIZATION event. To overcome this I used the ABAP local memory. I exported my output table and imported back it into the INITALIZATION to initialize my ALV. Selection-screen was looking like this:

Code Snippet to generate ALV on Selection Screen

Here is the code which will generate the output as shown in the second picture.

*&---------------------------------------------------------------------*
*& Generates the ALV on the Selection Screen itself
*&
*&---------------------------------------------------------------------*
REPORT  zalv_on_sel_screen.
*
*----------------------------------------------------------------------*
*  Local class for report
*----------------------------------------------------------------------*
CLASS lcl_report DEFINITION.
*
  PUBLIC SECTION.
*
    DATAt_data   TYPE STANDARD TABLE OF sflight,  " Output dat
          r_carrid TYPE RANGE OF sflight-carrid.    " Select Option
*
    METHODS:
      get_data,
*
      generate_output.
*
ENDCLASS.                    "lcl_report DEFINITION
*
DATAlo_report TYPE REF TO lcl_report.
*
DATAw_carrid TYPE sflight-carrid.
*
** Selection Screen
SELECTION-SCREENBEGIN OF BLOCK blk1 WITH FRAME TITLE aaa.
SELECT-OPTIONSs_carrid FOR w_carrid.
SELECTION-SCREENEND   OF BLOCK blk1.
*
** Initialization
INITIALIZATION.
  aaa 'Selection Criteria'.
* object for the report
  CREATE OBJECT lo_report.
* generate output
  lo_report->generate_output).
*
** Start of Selection
START-OF-SELECTION.
* Get data
  lo_report->r_carrid s_carrid[].
  lo_report->get_data).
*
*----------------------------------------------------------------------*
* Local Class Implementation
*----------------------------------------------------------------------*
CLASS lcl_report IMPLEMENTATION.
*
  METHOD get_data.
*
*   data selection
    SELECT FROM sflight
           INTO  TABLE me->t_data
           WHERE carrid IN s_carrid.
    IF sy-dbcnt IS INITIAL.
      MESSAGE s398(00WITH 'No data selected'.
    ENDIF.
*
*   export to memory
    EXPORT data me->t_data TO MEMORY ID sy-cprog.
*
  ENDMETHOD.                    "get_data
*
  METHOD generate_output.
*
*   local data
    DATAlo_dock TYPE REF TO cl_gui_docking_container,
          lo_cont TYPE REF TO cl_gui_container,
          lo_alv  TYPE REF TO cl_salv_table.
*
*   import output table from the memory and free afterwards
    IMPORT data me->t_data FROM MEMORY ID sy-cprog.
    FREE MEMORY ID sy-cprog.
*
*   Only if there is some data
    CHECK me->t_data IS NOT INITIAL.
*
*   Create a docking control at bottom
    CHECK lo_dock IS INITIAL.
    CREATE OBJECT lo_dock
      EXPORTING
        repid sy-cprog
        dynnr sy-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'.
    ENDIF.
*
*   Create a SALV for output
    CHECK lo_alv IS INITIAL.
    TRY.
*       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
          EXPORTING
            list_display   if_salv_c_bool_sap=>false
            r_container    lo_cont
            container_name 'DOCK_CONT'
          IMPORTING
            r_salv_table   lo_alv
          CHANGING
            t_table        me->t_data.
      CATCH cx_salv_msg .
    ENDTRY.
*
*   Pf status
    DATAlo_functions TYPE REF TO cl_salv_functions_list.
    lo_functions lo_alv->get_functions).
    lo_functions->set_defaultabap_true ).
*
*   output display
    lo_alv->display).
*
  ENDMETHOD.                    "generate_output
*
ENDCLASS.                    "lcl_report IMPLEMENTATION

Summary

Steps to create an ALV on the Selection Screen, in summary :

  • Create docking container in the INITALIZATION event
  • Create ALV on that Docking container
  • After selecting all the data, export output table to ABAP memory
  • Before generating the output, import the output table from the memroy

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{274 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 274 articles.

Load comments

29 Comments

  • good awesome work

  • Anonymous

    too good!!!!!!!!

  • Anonymous

    Wondful! Thanks a lot for sharing! 🙂

  • when i run this code i face error cl_salv_table is unknown so ans me for remove this

  • Hello Ketau,


    when i run this code i face error cl_salv_table is unknown so ans me for remove this

    This CL_SALV_TABLE only avliable from the ECC 5.0. If you are in the lower version than you can try it with the CL_GUI_ALV_GRID.
    I will update this post, once I will do it.

    Regards,
    Naimesh Patel

  • Venkat

    Hey i need to display two alv grids in a single screen . can u give me any suggestions?? is there any way of doing it without using Object oriented methodology ?

  • Anonymous

    Hi,
    I’m using CL_SALV_TABLE for the first time and I trying to find out if there is an event like the SUBTOTAL_TEXT. I have a list wherein I need to calculate the percentage on the sum of two columns, suppose the total of A is 4 and the B is 6 I need to have the total on column C to be 66.67%
    Thanks in Advance.
    Zala Maswanganye

  • Hi naimesh…
    I wanna show an ALV display, after pressing back i m exporting a field to ABAP MEMORY using EXPORT , and i m checking it in INITIALIZATION event..but when i leave the program and go to SE38 & again execute , i want that memory to be refreshed..Also pgm is having selction screen so from selection screen i may not execute but press EXIT and go to SE38….my pbm is this exported field value is retained (obviously as its ABAP memory) when i import in INITIALIZATION..is there any other way out ?

  • Hello Nilesh,

    I wanna show an ALV display, after pressing back i m exporting a field to ABAP MEMORY using EXPORT , and i m checking it in INITIALIZATION event..but when i leave the program and go to SE38 & again execute , i want that memory to be refreshed..Also pgm is having selction screen so from selection screen i may not execute but press EXIT and go to SE38….my pbm is this exported field value is retained (obviously as its ABAP memory) when i import in INITIALIZATION..is there any other way out ?
    We need to FREE the memory id. See the method GENERATE_OUTPUT and specially very first two lines in the given example. Here I do the IMPORT and just after that I refresh the memory using FREE MEMORY ID… If you have this statement than it would not come back when you run next time.

    Regards,
    Naimesh Patel

  • Anonymous

    Hello Naimesh,
    Thanks, this is really useful.
    However I just have one question: Can you only use the standard pf status in this alv? If not, how do I add a button to it? I tried setting the pfStatus but it says it's not supported if the ALV isn't on fullscreen.
    Regards,
    Marie Quirke

  • Hello Marie Quirke,

    You asked:
    Can you only use the standard pf status in this alv? If not, how do I add a button to it? I tried setting the pfStatus but it says it's not supported if the ALV isn't on fullscreen.

    We can add our own defined buttons as we add the ALV created with the CL_GUI_ALV_GRID. To add your own button, Check the program SALV_DEMO_TABLE_FUNCTIONS and Subroutine D0100_PBO.

    We can use the method ADD_FUNCTION of reference LO_FUNCTION.

    Regards,
    Naimesh Patel

  • Anonymous

    Too easy Naimesh! That's perfect.
    Thanks a million for your help, and the speedy response.
    Regards,
    Marie

  • Anonymous

    I wanted to display the customer information so ichanged other variable and work area accordingly.
    But when i execute it i dont get the alv display with the customer inforamtion.

  • Anonymous

    I want to create alv grid control report for custimmized two tables (input one table amd output another).
    plz send this report for that mail id:yumkumarbe@gmail.com

  • Anonymous

    plz help me any one
    oo-alv grid for custamized report for two or more tables.
    send this id: yumkumarbe@gmail.com

  • Anonymous

    gR8

  • Anonymous

    Hi,

    The coding is simply awesome. but is it going work in 4.7E version?

    Santosh.

  • Anonymous

    can we generate spool request in dat??

  • i have a requirement that i have to dispaly the selection screen and header data and when we clicks the header to display the item data in the same page…

  • in the blocked display we want to display the data

  • Anonymous

    great work………..!

  • Anonymous

    Hi,

    have you seen this?:

    http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/505b9716-2143-2e10-419d-8e0ca1c1de1f

    Best regards.

  • Wow .. People are simply being copy-cats…! I am very much disappointed…

    Regards,
    Naimesh Patel

  • Anonymous

    Hi Maimesh Patel,

    I have published an article.They have said me that it is some what similar to your work with modifications and asked me to notify you.

  • Anonymous

    Hi,

    I was not aware of this blog befor posting. Also I am new to ABAP. Am undergoing training. I was working with similar scenario. So i have posted.

  • Anonymous

    Hi Mr.Patel,
    I want to learn RFC function module. Pl. possible pl. send the basic step.
    my mail address is rabindrapaul20@gmail.com

    Rabindra Paul
    india

  • Wow, Good learning. Thanks Naimesh

  • Thanks for the share!
    Nancy.R

  • shiva

    Hi Naimesh,

    Can you please share the code how we will show the Dynamic selection screen.

    Here you go for my qiestion.

    I have two radio buttons in the selection screen .

    1.Sales Order
    2.Purchase order

    If i select Sales Order Number my selection screen should call a selection screen with Sales Order Number
    If i select Purchase Order my selection screen should load with Purchase Order Number.

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.