SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software SAP ABAP Programming and HANA Database Tutorials
Development resources, articles, tutorials, code samples and tools and downloads for ASP.Net, SQL Server, R Script, Windows, Windows Phone, AWS, SAP HANA and ABAP, like SAP UI5, Screen Personas, etc.

Install SAP Free

SAP Smartforms Tutorial - Table Calculations using Sum Total

Within this SAP Smartforms tutorial, I will share ABAP codes with SAP Smartforms developers showing how to use Table Calculations using Sum - Total function in Smartform document.

Before going details with the Smartform table calculations, I want to note that the samples are created and executed on SAP Netweaver 7.01 ABAP Trial version. Please check the SAP Netweaver 7.01 ABAP trial version installation guide for details.

As the data source of the sample Smartform document, I will use the ZCARS ABAP table. The SAP Smartforms output will list the rows in ZCARS ABAP table.
So I create a new SAP Smartforms report using ABAP transaction code smartforms with Smart Form name ZSSF_CARS_LIST.

In the Initialization phase of the Smart Form output, copy and paste following ABAP code which reads all rows from ZCARS ABAP table into internal table GT_ZCARS.
The ABAP internal table data will be displayed in the Smartform table control later in this Smartforms tutorial.
Go to Form > Global Settings > Global Definitions screen. Click on Initialization tab.


Please note that in the output parameters list we should place the GT_ZCARS global variable. I prefer to use GT_ZCARS also in the input parameters list.
Here is the screenshot how Smartform developers can manage initialization section of this example output.


Of course, we have not yet defined the global variable GT_ZCARS. If you try to activate Samrtform, it will fail because of the undefined internal table.
Let's define global variables that are required in this example SAP Smartforms tutorial.
Go to Form > Global Settings > Global Definitions screen. Click on Global Data tab.
Create the following global variables in the Global Data table as follows.

Variable NameType AssignmentAssociated TypeDefault Value


ABAP developers will realize that I used a custom type GTY_N10 in the Global Data declarations type.
We have to define this data type in the SAP Smartform document before we can use it.
Go to Form > Global Settings > Global Definitions screen. Click on Types tab.
Type the followin ABAP code for type declaration.

 BEGIN OF gty_N10,
  N10(10) TYPE N,
 END OF gty_N10.


Now we are ready to create SAP Smartforms Table control. Right click on Main window and choose Create > Table from context menu.

The data of the table is from ABAP internal table we have defined in Global Data tab and populated in Initialization tab. Let's assing the data source GT_ZCARS to SAP Smartforms table as seen in the below screenshot.
Go to the Data tab of the Table control, mark Internal Table checkbox. With data loop in internal table GT_ZCARS into GS_ZCARS structure or work area.


You will notice in the above screenshot that I added the CATEGORY field as sort criteria and mark the Event on Sort Begin and Event on Sort End checkboxes. These checkmarks will cause Smartform to create events and additional event lines just before and after the Main Area of the Smartform table.


Let's now create line types for table rows. I define two line types; one for displaying item rows and the second is for displaying category sum and overall total line.


And here is the details of table line types when you click Table Painter buton.


Now we can configure Table Calculations tab to display sum of numeric values listed on table using SUM Total operation.


The first line in Table Calculations is for auto numbering rows in the table display. ABAP developers can find the details about CNT Number Calculation example in SAP Smartforms Table in this target Smartform tutorial.

The second and third lines in Table Calculations manage the category subtotals and report total respectively.

Operation Field Name Target Field Name Time Reset For Field Name
CNT Number GV_COUNTER B Before Loop S Sort Criterion CATEGORY
SUM Total GV_N GV_TOTAL-N10 A After Loop

The above Table Calculations configuration will work as follows :
After each row displayed in the table, the global variable GV_N is summed into GV_CategorySubTotal-N10 variable value. The GV_CategorySubTotal-N10 value will be reset to its original value with Category field sort criterion. This means GV_CategorySubTotal-N10 will sum GV_N values from each row within same category. When the category changes, and a new category items begin listing on the table GV_CategorySubTotal-N10 will be set to 0, the initial value. So to display Category Subtotals, we will display GV_CategorySubTotal-N10 just before it is reset to initial value in the Category Event on Sort End line.


Just before printing the GV_CATEGORYSUBTOTAL-N10 value on the Smartform Text control within the event line cell, I remove preceeding zeros from the global variable.

* Remove preceeding zeros

For the GV_TOTAL value which will display overall sum of the table row field, the third table calculation line will help Smartform developers. Note that this SUM calculation is same as previous calculation with exception this does not have a reset criteria. This means the sum operation will work for all table rows. The GV_N field variable calculated during table row display will be summed into target field GV_TOTAL-N10 till the end of all table rows. The GV_TOTAL-N10 total value can be easily displayed in SAP Smartforms table using the Table Footer section as follows.


After you activate SAP Smartform and run Smartform output, a similar report shown below will be displayed.


SAP Resources

SAP Tutorial

SAP Forums

SAP Tools

SAP Transaction Codes Table

Meetup Sunumu 1 meetup

Related Articles and Tutorials(http://www.kodyaz.com/articles/sap-smartforms-tutorial-table-calculations-using-sum-total.aspx)
Change Output Condition Records
SAPScript Transaction Codes
Email Spool Request using SAPOffice - Spool to PDF
How to Debug SmartForms - Debugging SAP SmartForm in ABAP ?
SAP Invoice Output Determination Analysis for Not Created Output Message
SAP Smartforms - How to Call Smartform within ABAP Program
SAP Smartforms Table for Sales Order and Invoice Outputs
SAP Smartforms Tutorial - How to Create Smartform
SAP Smartforms Tutorial - Create Smartforms Example
SAP Smartforms Tutorial - Table Calculations using Count
SAP Smartforms Tutorial - Table Calculations using Sum Total
Adobe Forms Table Header is Missing After Second Page
Free Adobe LiveCycle Designer Download
Message no XS826: Cannot process message; no node determined for 76550052
Complex Conditions in SAP Smartform with AND/OR
How to Spell Numbers using ABAP Spell_Amount Function Module
Convert Smartform to PDF in Print Preview Mode
Delete Entries in NAST Table using RSCLNAST ABAP Program
How to Export IDOC as Excel and Save as Local File from WE02 Transaction
Export SAP Spool Requests as PDF using SP01 Transaction
How to Find Output Determination Procedure for a Billing Document
Export SAP Data to Fixed Length Text File
How to Disable Word Editor in SAP Smartform Text
Import and Export SO10 Standard Text using RSTXSCRP ABAP Program
Move Minus Sign from Right to Left of Negative Number in SAP Smartform
Print SAP Outputs From Two Printers at the Same Time
Get Proforma Invoice from Commercial Invoice in ABAP
SAP Invoice Output ZZZZ is not Defined
SAP Output Management - Create New SAP Output Type
SAP Purchase Order Tables, Transaction Codes and Output
Graphics White Background Displayed Grey on SAP Smartform Output
SE63 Smartform Translation and Export using SLXT Program
Window MAIN does not fit onto page PAGE (height)
SAP Smartforms Table Parameter in Form Routine
Trigger Output Re-Determination for Billing Documents
VF31 SAP Transaction to Reprocess Billing Output Messages
Web DynPro Tutorial - Display Spool Requests using Web DynPro Table

Copyright © 2004 - 2020 Eralper YILMAZ. All rights reserved.
Community Server by Telligent Systems