Sei sulla pagina 1di 5

3/8/2019 ALV with totals and sub totals in SAP ABAP - ALV Reports | Sapnuts.

com

You are here → /  Sapnuts.com /  Courses /  SAP ABAP /  ALV Reports /  ALV with totals and sub totals in SAP ABAP

ALV with totals and sub totals in SAP Search Sapnuts Search

ABAP
Last Updated: December 3rd 2016 by Ashok Kumar Reddy

Working with totals and subtotals in SAP ALV reports using SAP ABAP, display
totals and subtotals in ALV report

A+ A-

To calculate totals and sub-totals in ALV we need to sort the internal table in ascending order and we need
to set SUBTOT = 'X' of SORT in ALV.

Layout:
Layout is a structure which is used to decorate or embellish the output of ALV Report.

Requirement: Display list of sales order for sales order range with
totals and subtotals of price
Input screen

Learn SAP Courses online, SAP Certi cation


mock exams and SAP tutorials

SAP ABAP Tutorials, SAP ABAP Online


Training, SAP Webdynpro for ABAP,
Webdynpro for ABAP tutorials, Webdynpro for
ABAP online training, SAP Work ow training,
SAP Online Training, SAP Certi cation, SAP
Training, SAP mock exams, SAP Exams, SAP
Output screen (with totals and subtotals). ERP, SAP Interview questions, SAP ABAP
interview Questions

SAP ABAP Course Content

SAP Introduction

SAP ABAP Consultant

System Landscape and Introduction to


ABAP/4

Data Dictionary

Internal Tables and Work Areas

Select Statements types

Selection Screen Design using SAP


ABAP

Modularization techniques in SAP


https://www.sapnuts.com/courses/core-abap/alv-reports/alv-totals-subtotals.html 1/5
3/8/2019 ALV with totals and sub totals in SAP ABAP - ALV Reports | Sapnuts.com

ABAP

Classical Reports in SAP ABAP

Interactive Reporting in SAP ABAP

Menu painter in SAP

ALV Reports

Sapscripts

Smartforms

Batch Data Communication

Open SQL Statements in SAP ABAP

SAP memory and ABAP memory

Performance Tuning in SAP ABAP

Control break statements in sap abap


Please follow previous lesson steps to create a eldcatlog in ALV, in addition to that we will be adding
additional properties hotspot, editable to output elds using layout options.
Enhancements in SAP
The below code is used to display totals and subtotals in ALV.

BADI in SAP
DATA : I_SORT TYPE SLIS_T_SORTINFO_ALV .
DATA : WA_SORT LIKE LINE OF I_SORT .
WA_SORT-FIELDNAME = 'VBELN '. SD and MM ows in SAP
WA_SORT-UP = 'X'.
WA_SORT-SUBTOT = 'X '. Dialog Module Pool Programming

APPEND WA_SORT TO I_SORT .


String Operations and eld symbols

Full referance code for displaying totals and subtotals in ALV SAP ABAP real-time scenarios

MM Basics for ABAP Consultants

SD Basics for ABAP Consultants

Register for Premium SAP


Training

Training will be provided through


online platform ex: gotomeetings

Name *

Name

Email *

Email

Mobile *

10 digit mobile number


Your privacy will be protected always

Select Courses *
SAP ABAP

https://www.sapnuts.com/courses/core-abap/alv-reports/alv-totals-subtotals.html 2/5
3/8/2019 ALV with totals and sub totals in SAP ABAP - ALV Reports | Sapnuts.com

Web Dynpro ABAP


REPORT ZALV_WITH_TOTALS_SUBTOT.
TYPE-POOLS SLIS .
tables : vbap. Object Oriented ABAP
TYPES : BEGIN OF TY_VBAP,
VBELN TYPE VBAP-VBELN, SAP Cross Apps (RFC,BAPI,IDOC)
POSNR TYPE VBAP-POSNR,
MATNR TYPE VBAP-MATNR,
Comments
NETWR TYPE VBAP-NETWR,
END OF TY_VBAP. Comments
DATA : I_VBAP TYPE TABLE OF TY_VBAP .
DATA : WA_VBAP TYPE TY_VBAP .

DATA : I_FCAT TYPE SLIS_T_FIELDCAT_ALV . Submit


DATA : WA_FCAT LIKE LINE OF I_FCAT .
DATA : I_SORT TYPE SLIS_T_SORTINFO_ALV .
DATA : WA_SORT LIKE LINE OF I_SORT .
select-options : s_vbeln for vbap-vbeln.
START-OF-SELECTION .
PERFORM GET_DATA .
PERFORM CREATE_FCAT.
PERFORM CALC_SUBTOT.

END-OF-SELECTION .
PERFORM DISP_ALV .
FORM GET_DATA .
SELECT VBELN POSNR MATNR NETWR FROM VBAP
INTO TABLE I_VBAP where vbeln in s_vbeln
.
ENDFORM. " GET_DATA
FORM DISP_ALV .
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 = I_FCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
IT_SORT = I_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 =
* IMPORTING

https://www.sapnuts.com/courses/core-abap/alv-reports/alv-totals-subtotals.html 3/5
3/8/2019 ALV with totals and sub totals in SAP ABAP - ALV Reports | Sapnuts.com

* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = I_VBAP
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
IF SY-SUBRC NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

ENDFORM. " DISP_ALV


FORM CREATE_FCAT .
WA_FCAT-COL_POS = '1' .
WA_FCAT-FIELDNAME = 'VBELN' .
WA_FCAT-TABNAME = 'I_VBAP' .
WA_FCAT-SELTEXT_M = 'SDNO' .
WA_FCAT-KEY = 'X' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .

WA_FCAT-COL_POS = '2' .
WA_FCAT-FIELDNAME = 'POSNR' .
WA_FCAT-TABNAME = 'I_VBAP' .
WA_FCAT-SELTEXT_M = 'ITEMNO' .
* WA_FCAT-NO_OUT = 'X' .
WA_FCAT-HOTSPOT = 'X' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .

WA_FCAT-COL_POS = '3' .
WA_FCAT-FIELDNAME = 'MATNR' .
WA_FCAT-TABNAME = 'I_VBAP' .
WA_FCAT-SELTEXT_M = 'MATERIALNO' .
* WA_FCAT-EDIT = 'X' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .

WA_FCAT-COL_POS = '4' .
WA_FCAT-FIELDNAME = 'NETWR' .
WA_FCAT-TABNAME = 'I_VBAP' .
WA_FCAT-SELTEXT_M = 'NETPRICE' .
WA_FCAT-EMPHASIZE = 'C610'.
WA_FCAT-DO_SUM = 'X' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .

ENDFORM. " CREATE_FCAT


FORM CALC_SUBTOT .
WA_SORT-FIELDNAME = 'VBELN '.
WA_SORT-UP = 'X'.
WA_SORT-SUBTOT = 'X '.
APPEND WA_SORT TO I_SORT .
ENDFORM. " CALC_SUBTOT

Learner Questions

No Questions by learners, be rst one to ask ..!!

Please Sign in to ask a question

https://www.sapnuts.com/courses/core-abap/alv-reports/alv-totals-subtotals.html 4/5
3/8/2019 ALV with totals and sub totals in SAP ABAP - ALV Reports | Sapnuts.com

Was this lesson helpful to you? Yes No 51 People out of 57 think this lesson helpful

Lesson Navigation
ALV Report with layout SAP ABAP ←Previous Chapter Next Chapter → Events in ALV reports
? Support About Feedback Privacy Terms & Conditions Report Abuse © SURAPU TECHNOLOGY SERVICES PVT LTD Google Twitter Facebook Version: V.2.0

https://www.sapnuts.com/courses/core-abap/alv-reports/alv-totals-subtotals.html 5/5