0% found this document useful (0 votes)
41 views

Reports

Uploaded by

Laksh Mhr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Reports

Uploaded by

Laksh Mhr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

REPORTS IN SAP ABAP REPORT:

Report is the combination of given inputs to the selection-screen retrieving the data from data base
based on the given input & display the output in a predefined format.

Types of reports:

 Classical reports
 Interactive reports
 ALV reports

a) Classical report

A report with single input screen (selection screen) and single output screen (list screen) is called
Classical report.

It’s nothing but to display the entire information in a single list.

Events in Classical Reports: - All the ABAP programs are developed using events because ABAP is
“EVENT DRIVEN PROGRAMMING LANGUAGE” i.e., the entire ABAP program execution is based on order
of events.

 LOAD-OF-PROGRAM
 INITIALIZATION
 AT SELECTION-SCREEN OUTPUT
 AT SELECTION-SCREEN ON FIELD
 AT SELECTION-SCREEN ON VALUE REQUEST
 AT SELECTION-SCREEN ON HELP REQUEST
 AT SELECTION-SCREEN
 START OF SELECTION
 END OF SELECTION
 TOP-OF-PAGE
 END-OF-PAGE

Load of program:

This event is used to load the program into the memory for execution.

This is internal event, which we cannot see.

Initialization:

It’s an event which is triggered before displaying the selection-screen.

It’s used to provide the default values to the selection-screen.

At selection-screen output:

It’s an event which is triggered at the selection-screen based on the user action.
This is used to modify the selection-screen.

At selection-screen on field:

It’s an event which is triggered at the selection-screen based on particular input field.

This is used to validate the particular input field.

At selection-screen on value-request:

It’s an event which is triggered at the time of click on F4 button. This is used to provide the list of
possible values to the input variables.

At selection-screen on help-request:

It’s an event which is triggered at the time of click on F1 button. This is used to provide the help
document to the input variable

At selection-screen:

It’s an event which is triggered after provide the input to the screen & before leaving the selection-
screen.

This is used to validate the given input.

Start-of-selection: It’s an event which is triggered after leaving the selection-screen & before display
the output. This is used to fetch the data from data base & place into internal table.

End-of-selection:

It’s an event which is triggered after completion of the logic.

This is used to display the output.

Top-of-page: It’s an event which is triggered of the top of each page.

It’s used to display the header information.

End-of-page: It’s an event which is triggered of the end of each page.

It’s used to display the footer information.


Create a Program using events in classical report:
*&---------------------------------------------------------------------*
*& Report ZCLASSICAL_R1
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zclassical_r1.

DATA: gt_Vbak TYPE TABLE OF vbak,


gs_Vbak TYPE vbak.
DATA: gv_vkorg TYPE vkorg.
PARAMETERS: p_vkorg TYPE vkorg.

INITIALIZATION.
p_vkorg = 1710.

AT SELECTION-SCREEN.
SELECT SINGLE vkorg INTO gv_Vkorg FROM vbak WHERE vkorg = p_vkorg.
IF sy-subrc NE 0.
MESSAGE 'Please provide correct value of sales organization' TYPE 'E'.
ENDIF.

AT SELECTION-SCREEN OUTPUT.
** AT SELECTION-SCREEN ON FIELD.
** AT SELECTION-SCREEN ON VALUE-REQUEST FOR FIELD.
** AT SELECTION-SCREEN ON HELP-REQUEST FOR FIELD.
START-OF-SELECTION.
SELECT * FROM Vbak INTO TABLE gt_vbak WHERE vkorg = p_vkorg.

END-OF-SELECTION.
LOOP AT gt_vbak INTO gs_Vbak.
WRITE:/ gs_Vbak-vbeln,
gs_Vbak-erdat,
gs_Vbak-ernam,
gs_Vbak-auart,
gs_Vbak-vkorg.
HIDE gs_Vbak-vbeln.
ENDLOOP.

TOP-OF-PAGE.
ULINE.
WRITE: 'Sales order' , ' created date' , 'created by' , 'Sales order type
', 'Sales organization'.
ULINE.

END-OF-PAGE.
ULINE.
WRITE: 'continue' , sy-pagno.
ULINE.
OUTPUT
b) Interactive Report

It’s nothing but to display the summarized information in the first list & detailed information in the
secondary list.

The first list is called basic list and the number is 0.

The remaining lists are called secondary lists and the number starts from 1 to 20.

So, there are total 21 lists. We can view multiple lists simultaneously.

The current list index number is stored in SY-LSIND.

If you select any line, then the selected line data is stored in SY-LISEL.

Events in Interactive report

1. At line selection

2. At user-command.

3. Top-of-page during line-selection.

4. At PF <Function Key>

At line selection:

It’s an event which is triggered at the time of user clicks on any record of any list. To know the
selected contents, we have two Key words.

HIDE

GET CURSOR

Hide is a key word which is used to hide the data temporarily memory is called as HIDE area for
further processing.

We use the HIDE statement with in the LOOP……END LOOP, so that the hide key word will hide the
values into hide area.

Functionality of HIDE: Whenever the user double clicks on any list line, the event at line selection
will be triggered.

The system automatically identifies the line number where the user has double clicked and reads
the corresponding record into hide variable.

GET-CURSOR: Get-cursor technique writes the field name as well as field value which is clicked by
the user.

Syntax: GET CURSOR Field <V_fname>value<v_fname>.


At user-command:

It’s an event which is triggered at the time of user clicks on any menu item.

Top-of-page during line-selection:

It’s an event which is triggered at the top of each secondary list.

At PF <Functional Key> : It’s an event which is triggered at the time of user clicks on F1 to F12
function keys.

ALV (ABAP List Viewer) Report

ALV Reports are mainly used to display the data in the form of either Grid or List Format with good
look and feel.

The advantages of ALV Reports are:

1. Good Look and Feel

2. Pre defined options given by SAP like Asc, Desc, Filtering, Downloading, Changing Layout, sending
Mail.... etc.

FUNCTION MODULES FOR DEVELOPING ALV REPORTS:

REUSE_ALV_GRID_DISPLAY--Display ALV data in GRID format

REUSE_ALV_LIST_DISPLAY--Display ALV data in LIST format

REUSE_ALV_COMMENTARY_WRITE--Display TOP-OF-PAGE, LOGO, END-OF-LIST.


REUSE_ALV_FIELDCATELOG_MERGE--Generate field catalog automatically
REUSE_ALV_EVENTS_GET--Display ALV Events

REUSE_ALV_HIERSEQ_LIST_DISPLAY--Display hierarchical ALV

REUSE_ALV_BLOCKED_LIST_DISPLAY--Display blocked

ALV LIST OF ALV's

ALV with structure

ALV with field catalog

ALV with layout options

ALV with field catalog merge

Interactive ALV Interactive

ALV by calling a transaction

Hierarchical ALV
Blocked ALV

ALV with Structures:

Develop a material master report which displays all the fields.

STEPS:

Declare an internal table and work area for table.

Write an select statements to fetch the data.

Call function module REUSE_ALV_GRID_DISPLAY and specify the below parameters.

Structure name, Program name, Internal table name


Program using ALV with Structures:

Click on Create.
Select Local Object.

Source Code:
*&---------------------------------------------------------------------*
*& Report ZALV
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZALV.

data: it_mara type TABLE OF mara.


SELECT * from mara into TABLE it_mara.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
I_STRUCTURE_NAME = 'mara'
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
* IT_FIELDCAT =
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* O_PREVIOUS_SRAL_HANDLER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = it_mara
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
With list display

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'


EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = sy-cprog
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
I_STRUCTURE_NAME = 'mara'
* IS_LAYOUT =
* IT_FIELDCAT =
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IR_SALV_LIST_ADAPTER =
* IT_EXCEPT_QINFO =
* I_SUPPRESS_EMPTY_DATA = ABAP_FALSE
* IO_SALV_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = it_mara
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

Output
ALV WITH FIELD CATALOG:

Field Catalog:

It is an internal table which contains the list of the fields along with the field properties to be displayed
in ALV Report

The properties/options are:

1. COL_POS = 1

2. FIELD NAME--> Specifies the name of the field

3. TABLE NAME--> Specifies the name of the internal table

4. SEL TEXT_S--> Specifies short

5. SEL TEXT_S--> Specifies long

6. SEL TEXT_S--> Specifies medium

7. DO_SUM ='X'--> For grand totals

8. SUBTOT ='X'--> Sub totals to be calculated

9. EDIT ='X'--> Field can be editable

10. EMPHASIZE ='CXYZ' --> Specifies the color to the fields C--> Indicates color X--> Color Numbers Y-->
Background color---- 1 on BG color 0 off BG color Z--> Font color---1 On Font color 0 Off Font color

11. REFERENCE TABLENAME REFERENCE FIELDNAME -->To copy all the properties from data dictionary
to a field catalog field.

12. KEY --> Specify the key field

13. HOTSPOT --> For selection

14. NO_OUT --> Field will not be displayed in output

Generation of Field catalog:

It is generated using 2 ways.

1) Manually

2) Automatically by using FM
Program using ALV with MANUAL FIELD CATALOG
For single field

*&---------------------------------------------------------------------*
*& Report ZALV_WITH_FIELD_CAT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZALV_WITH_FIELD_CAT.

**field catolog for single record

type-pools slis.
data : gt_vbak type table of vbak,
gt_Fcat type slis_t_fieldcat_alv,
gs_fcat type slis_fieldcat_alv.

select * from vbak into table gt_vbak.

gs_fcat-col_pos = 1.
gs_fcat-fieldname = 'VBELN'.
gs_fcat-seltext_m = 'sales order'.
append gs_fcat to gt_fcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
IT_FIELDCAT = gt_fcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* O_PREVIOUS_SRAL_HANDLER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = gt_vbak
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

OUTPUT
***field catalog for multiple records
TYPE-POOLS slis.
DATA : gt_vbak TYPE TABLE OF vbak,
gt_Fcat TYPE slis_t_fieldcat_alv,
gs_fcat TYPE slis_fieldcat_alv.
SELECT * FROM vbak INTO TABLE gt_vbak.
gs_fcat-col_pos = 1.
gs_fcat-fieldname = 'VBELN'.
gs_fcat-seltext_m = 'sales order'.
gs_Fcat-key = 'X '.
* it will show different color ******
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
gs_fcat-col_pos = 2.
gs_fcat-fieldname = 'ERDAT'.
gs_fcat-seltext_m = 'CREATED DATE'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
gs_fcat-col_pos = 3.
gs_fcat-fieldname = 'ERNAM'.
gs_fcat-seltext_m = 'CREATED BY'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
gs_fcat-col_pos = 4.
gs_fcat-fieldname = 'AUART'.
gs_fcat-seltext_m = 'SO DOC TYPE'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
gs_fcat-col_pos = 5.
gs_fcat-fieldname = 'VKORG'.
gs_fcat-seltext_m = 'sales organization'.
APPEND gs_fcat TO gt_fcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
i_callback_program = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
it_fieldcat = gt_fcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* O_PREVIOUS_SRAL_HANDLER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = gt_vbak
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
Output
Program using ALV with FIELD CATALOG MERGE.
*&---------------------------------------------------------------------*
*& Report ZALV6
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZALV6.
DATA: GT_EKKO TYPE TABLE OF EKKO,
GT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
GS_FCAT TYPE SLIS_FIELDCAT_ALV.

SELECT * FROM EKKO INTO TABLE GT_EKKO.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'


EXPORTING
I_PROGRAM_NAME = SY-REPID
* I_INTERNAL_TABNAME =
I_STRUCTURE_NAME = 'EKKO'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_INCLNAME =
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
CHANGING
ct_fieldcat = GT_FCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

LOOP AT GT_FCAT INTO GS_FCAT.


CASE GS_FCAT-FIELDNAME.
WHEN 'EBELN'.
GS_FCAT-NO_OUT = ' '.
WHEN 'BUKRS'.
GS_FCAT-NO_OUT = ' '.
WHEN OTHERS.
GS_FCAT-NO_OUT = 'X'.
ENDCASE.
MODIFY GT_FCAT FROM GS_FCAT.
ENDLOOP.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
IT_FIELDCAT = gt_fcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* O_PREVIOUS_SRAL_HANDLER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = gt_ekko
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
Output

ALV with LAYOUT

Layout:

It is a structure or work area which is used to decorate or embellish the output of ALV report. Layout
contains the few properties to decorate the ALV output.

The properties are,

1. ZEBRA ='X'. Displays ALV with different colors

2. COLWIDTH-OPTIMIZE='X'. Each column in ALV o/p displayed with maximum length, to display the
entire data.

3. EDIT='X'. All the columns are displayed in editable mode.

4. NO_VLINE ='X'. Vertical lines will not be displayed

5. NO_HLINE ='X'. Horizontal lines will not be displayed.


Program using ALV with Layout
*&---------------------------------------------------------------------*
*& Report ZALV7
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZALV7.
DATA: gt_mara TYPE TABLE OF mara,
gt_layout TYPE slis_layout_alv.
SELECT * from mara into TABLE gt_mara.
gt_layout-zebra = 'X'.
gt_layout-colwidth_optimize = 'X'.
gt_layout-no_vline = 'X'.
gt_layout-no_hline = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
I_STRUCTURE_NAME = 'MARA'
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
IS_LAYOUT = GT_LAYOUT
* IT_FIELDCAT =
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* O_PREVIOUS_SRAL_HANDLER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = GT_MARA
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

OUTPUT
ALV with GRAND TOTALS:

The totals can be calculated in two ways By clicking on ∑ALV output field. By programmatically setting
the option DO_SUM='X', for a currency/quantity field in FCAT.

Program using ALV with GRAND TOTALS


*&---------------------------------------------------------------------*
*& Report ZAL_WITH_GRAND_TOTAL1
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zal_with_grand_total1.
TYPE-POOLS slis.
DATA : gt_vbak TYPE TABLE OF vbak,
gt_Fcat TYPE slis_t_fieldcat_alv,
gs_fcat TYPE slis_fieldcat_alv.
SELECT * FROM vbak INTO TABLE gt_vbak.
gs_fcat-col_pos = 1.
gs_fcat-fieldname = 'VBELN'.
gs_fcat-seltext_m = 'sales order'.
gs_Fcat-key = 'X '.
* it will show different color ******
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
gs_fcat-col_pos = 2.
gs_fcat-fieldname = 'ERDAT'.
gs_fcat-seltext_m = 'CREATED DATE'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
gs_fcat-col_pos = 3.
gs_fcat-fieldname = 'ERNAM'.
gs_fcat-seltext_m = 'CREATED BY'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
gs_fcat-col_pos = 4.
gs_fcat-fieldname = 'AUART'.
gs_fcat-seltext_m = 'SO DOC TYPE'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
gs_fcat-col_pos = 5.
gs_fcat-fieldname = 'VKORG'.
gs_fcat-seltext_m = 'sales organization'.
APPEND gs_fcat TO gt_fcat.
gs_fcat-col_pos = 6.
gs_fcat-fieldname = 'NETWR'.
gs_fcat-seltext_m = 'sales order price'.
gs_fcat-do_sum = 'X'.
APPEND gs_fcat TO gt_fcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
i_callback_program = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
it_fieldcat = gt_fcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* O_PREVIOUS_SRAL_HANDLER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = gt_vbak
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
Output

You might also like