Enterprise Resource Planning Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
nivedithaa
Participant
60,994
Introduction:

I got the requirement  from the Client to display three ALV's in a Report. Here I am writing a blog which I tried to implement it in my Local System.

ALV Report:

ALV stands for ABAP List Viewer. ALV gives us a standard List format and user interface to all our ABAP reports. ALV is created by a set of standard function modules provided by SAP.

Below is the code is used to display three ALV's in a Report:

Step 1: Go to Tcode SE38:

Step 2: Give the program name as required and click on create button a pop up should be displayed, where we need to provide the title as required and type as “ Executable Program â€ť, then click on Save button and select your required Package and save it.

Here we need to write the source code.


SOURCE CODE:




*&---------------------------------------------------------------------*
*& Include ZR_MULTIPLE_ALV_TOP
*&---------------------------------------------------------------------*
CLASS lcl_report DEFINITION DEFERRED.

TABLES : sflight,
scarr,
sflights.

**DATA DECLARATIONS
DATA: lo_salv TYPE REF TO cl_salv_table, " ALV Reference
gt_sflight TYPE STANDARD TABLE OF sflight,
gt_scarr TYPE STANDARD TABLE OF scarr,
gv_message TYPE REF TO cx_salv_msg, "Exception Class
gt_sflights TYPE STANDARD TABLE OF sflights,
lo_report TYPE REF TO lcl_report,
lo_container TYPE REF TO cl_gui_custom_container. "Custom Container

**SELECTION SCREEN
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-000.
SELECT-OPTIONS s_flight FOR sflight-carrid.
SELECTION-SCREEN END OF BLOCK b1.
===============================================================================
*&---------------------------------------------------------------------*
*& Include ZR_MULTIPLE_ALV_I01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*


CLASS lcl_report DEFINITION.
PUBLIC SECTION.
* Methods to Fetch Data and Display Output
METHODS: get_data, "Data Selection
display_output, "Display Output
display_alv "Display ALV
IMPORTING
container_name TYPE c
CHANGING
i_data TYPE STANDARD TABLE.

* Method to Set PF-Status
METHODS: set_pf_status
CHANGING
co_salv TYPE REF TO cl_salv_table. " Default Pf Status

ENDCLASS. "lcl_report DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_report IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_report IMPLEMENTATION.

* Data selection
METHOD get_data.
SELECT * INTO TABLE gt_sflight
FROM sflight UP TO 10 ROWS WHERE carrid IN s_flight .

SELECT * INTO TABLE gt_scarr
FROM scarr UP TO 10 ROWS WHERE carrid IN s_flight .

SELECT * INTO TABLE gt_sflights
FROM sflights UP TO 10 ROWS WHERE carrid IN s_flight .
ENDMETHOD. "get_data

* Display ALV
METHOD display_alv.

* Instantiate the container
CREATE OBJECT lo_container
EXPORTING
container_name = container_name
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6.
IF sy-subrc <> 0.
* Raise exception
ENDIF.

* Call Factory method which will give back the ALV object reference.
TRY.
CALL METHOD cl_salv_table=>factory
EXPORTING
r_container = lo_container "****Pass container object to cl_salv_table***
IMPORTING
r_salv_table = lo_salv
CHANGING
t_table = i_data.
CATCH cx_salv_msg INTO gv_message .
ENDTRY.

* Set PF status
CALL METHOD set_pf_status
CHANGING
co_salv = lo_salv.

* Display the ALV
lo_salv->display( ).
ENDMETHOD. "display_ALV

* Display Output
METHOD display_output.

* Call ALV display method and pass the Container name and internal table
***Display ALV1***
display_alv(
EXPORTING
container_name = 'CONTAINER1'
CHANGING
i_data = gt_sflight ).

**Display ALV2***
display_alv(
EXPORTING
container_name = 'CONTAINER2'
CHANGING
i_data = gt_scarr ).

***Display ALV3***
display_alv(
EXPORTING
container_name = 'CONTAINER3'
CHANGING
i_data = gt_sflights ).
ENDMETHOD. "display_ALV

************************************************************************
* Method Implementation
************************************************************************
* Setting the PF-Status
METHOD set_pf_status.
DATA: lo_functions TYPE REF TO cl_salv_functions_list.
* Default functions
lo_functions = co_salv->get_functions( ).
lo_functions->set_all( abap_true ).
ENDMETHOD. "set_pf_status
ENDCLASS. "lcl_report IMPLEMENTATION
MODULE status_9000 OUTPUT.
SET PF-STATUS 'ZSTATUS'.
SET TITLEBAR 'TITLE'.
ENDMODULE. " STATUS_0100 OUTPUT
===========================================================================
*&---------------------------------------------------------------------*
*& Include ZR_MULTIPLE_ALV_O01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.
IF sy-ucomm = 'BACK'.
LEAVE TO SCREEN 0.
ENDIF.
ENDMODULE. " USER_COMMAND_9000 INPUT

Output:

Provide the details and Click on Execute.



Conclusion:

Hope this blog will help and by following the above steps we can display the Standard Multiple ALV's in a Report..

Thanks for reading…

 

 
5 Comments