Enterprise Resource Planning Blogs by Members
Gain new perspectives and knowledge about enterprise resource planning in blog posts from community members. Share your own comments and ERP insights today!
cancel
Showing results for 
Search instead for 
Did you mean: 
nivedithaa
Explorer
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
Sandra_Rossi
Active Contributor
0 Kudos
Thanks. Maybe you can post the code of the dynpro 9000 too, or even to share the full solution in a Git repository (like GitHub, GitLab, or other, and using abapGit to transfer the example to the repository) 👍
ascm
Explorer
Another way:

data(container_split) = new cl_gui_splitter_container( parent = cl_gui_container=>default_screen
rows = 1
columns = 2
no_autodef_progid_dynnr = 'X' ).

data(container_splitter_right) = new cl_gui_easy_splitter_container( parent = container_split>get_container( row = 1 column = 2 )
sash_position = 50
orientation = cl_gui_easy_splitter_container=>orientation_vertical ).

 

Now create the ALV's an assign them to the diffrent container.

The last output ist "write: ''. Without you see nothing!

 

matt
Active Contributor
0 Kudos
This was my approach also. It was especially useful as when I needed to suppress one ALV, I could do it without wasting any screen real estate.
former_member800450
Discoverer
0 Kudos
DATAgt_flights TYPE TABLE OF sflight,
gs_flight  TYPE sflight,
ok_code    TYPE sy-ucomm.

DATA go_container TYPE REF TO cl_gui_custom_container.
DATA go_alv TYPE REF TO cl_gui_alv_grid.

DATA gs_variant TYPE disvariant.
DATA gv_save TYPE LENGTH 1.

SELECT-OPTIONSso_car FOR gs_flight-carrid,
so_con FOR gs_flight-connid.

PARAMETERS pa_lv TYPE disvariant-variant.

START-OF-SELECTION.

SELECT INTO CORRESPONDING FIELDS OF TABLE gt_flights
FROM sflight
WHERE carrid IN so_car
AND connid IN so_con.

END-OF-SELECTION.

CALL SCREEN 100.

*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'G100'.
SET TITLEBAR 'T100'.
ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.

CASE ok_code.
WHEN 'BACK'.
PERFORM free_control.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
PERFORM free_control.
LEAVE PROGRAM.

ENDCASE.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module CLEAR_CODE OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE clear_code OUTPUT.

CLEAR ok_code.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module INIT_ALV OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE init_alv OUTPUT.

IF go_container IS INITIAL.
CREATE OBJECT go_container
EXPORTING
container_name 'CONTROL_AREA'
EXCEPTIONS
OTHERS         1.
IF sy-subrc <> 0.
MESSAGE 'Control error' TYPE 'E'.
ENDIF.


CREATE OBJECT go_alv
EXPORTING
i_parent go_container.
IF sy-subrc <> 0.
MESSAGE 'Control error' TYPE 'E'.
ENDIF.

gs_variant-report sy-cprog.
gs_variant-variant pa_lv.

gv_save 'X'.

CALL METHOD go_alv->set_table_for_first_display
EXPORTING
*       i_buffer_active               =
*       i_bypassing_buffer            =
*       i_consistency_check           =
i_structure_name              'SFLIGHT'
is_variant                    gs_variant
i_save                        gv_save
*       i_default                     = 'X'
*       is_layout                     =
*       is_print                      =
*       it_special_groups             =
*       it_toolbar_excluding          =
*       it_hyperlink                  =
*       it_alv_graphics               =
*       it_except_qinfo               =
*       ir_salv_adapter               =
CHANGING
it_outtab                     gt_flights
*       it_fieldcatalog               =
*       it_sort                       =
*       it_filter                     =
EXCEPTIONS
invalid_parameter_combination 1
program_error                 2
too_many_lines                3
OTHERS                        4.
IF sy-subrc <> 0.
*  Implement suitable error handling here
ENDIF.



ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Form FREE_CONTROL
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM free_control .
CALL METHOD go_container->free
EXCEPTIONS
cntl_error        1
cntl_system_error 2
OTHERS            3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

CALL METHOD go_alv->free
EXCEPTIONS
cntl_error        1
cntl_system_error 2
OTHERS            3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

FREE go_containergo_alv.

ENDFORM.

 

alv create
former_member800450
Discoverer
0 Kudos
TABLES ZSTUDENT_11_1zstdclass_11.

SELECT-OPTIONS s_id FOR ZSTUDENT_11_1.
SELECT-OPTIONS s_name FOR ZSTUDENT_11_1-name.

SELECT-OPTIONS s_class FOR zstdclass_11-class.

DATA gt_data TYPE ZTCLASS_99.
DATA gs_data TYPE ZSCLASS.

START-OF-SELECTION.

SELECT a~id a~name b~class b~grade
FROM zstudent_11_1 AS a INNER JOIN zstdclass_99 AS b
ON a~id b~id
INTO CORRESPONDING FIELDS OF TABLE gt_data
WHERE
a~id IN s_id
AND a~name IN s_name
AND b~class IN s_class.

loop at gt_data into gs_Data.
write / GS_DATA-idGS_DATA-nameGS_DATA-classGS_DATA-GRADE.

ENDLOOP.
Labels in this area