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
Development resources, articles, tutorials, code samples, tools and downloads for SAP HANA and ABAP, HANA Database, SQLScript, SAP UI5, Screen Personas, Web Dynpro, Workflow


SAP Smartforms Tutorial - Table Calculations using Count


In this SAP Smartforms tutorial, I want to show how can SAP Smart Forms developers can use Table Calculations using Count function.

Assume that you have a SAP Smartform sample report listing a list of SAP Smartform documents created on your ABAP development system. In this Smartform tutorial, We will add a new column and which will be an auto number field, numbering the table rows beginning from 1, 2, and goes on incrementing by 1.





Define the following global variables in the Global Data tab in Global Definitions screen on your SAP Smartform.
The first global variable GV_COUNTER is the numeric variable that will be used in the table calculations with count function. The second global variable GV_ORDERNO is the string variable to display as text value on the Sort Order column.

Variable NameType AssignmentAssociated TypeDefault Value
GV_COUNTERTYPEINTEGER1
GV_ORDERNOTYPECHAR3

After the global variables are defined, now ABAP developers can go to Smartform table screen Calculations tab as seen in the below screenshot. Choose the CNT Number Operation from the dropdown list. Possible operation types are ; AVG Mean Value, CNT Number and SUM Total operations.
Target Field Name will be GV_COUNTER numeric global variable we have already defined.
In the Time column, I'll choose A After Loop. After Loop option will assign the new value to the counter right after each table row is processed by Smartform.
With GV_COUNTER default value equal to 1, the first data row will have counter value 1 in the table cell. Then After Loop option selection will increase the counter by 1. So the next table row will have 2 in the counter cell.
The possible Time options are A After Loop, B Before Loop, R Before Sorting, T After Sorting.
If when the GV_COUNTER default value is 1, we choose Before Loop option, then before printing the first data row the counter value will be increased by 1 so the table cell will display 2 for the first row.

sap-smartforms-tutorial-table-calculations-count-number

Now Smartform developer can create Program Lines object and Text object within a table line cell in the Main Area of the table.

sap-smartforms-tutorial-table-calculations-for-count-code-text

Place the following code in the Program Lines.

CLEAR GV_ORDERNO.
WRITE GV_COUNTER TO GV_ORDERNO.
Code

This code will convert the numeric GV_COUNTER variable to string value and writes to GV_ORDERNO global variable.
In the Input Parameters windows add GV_ORDERNO and GV_COUNTER to the table.
In the Output Parameters windows add GV_ORDERNO.

smarforms-table-calculations-code-data-type-conversion

We will now print the GV_ORDERNO string variable in the table cell using Text object.

display-global-variable-using-text-in-smartform

After all is completed, activate Smartform then execute Smartform with F8.
The final output will be as follows :

sap-smartforms-tutorial-table-calculations-counter-after-loop

I hope ABAP developers will like this SAP Smartforms tutorial which focus how to deal with table calculations.



SAP HANA and ABAP

Install SAP Free
CRM Companies List
Web Based CRM Software


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.