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 Name||Type Assignment||Associated Type||Default Value|
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.
Now Smartform developer can create Program Lines object and Text object within a table line cell in the Main Area of the table.
Place the following code in the Program Lines.
WRITE GV_COUNTER TO GV_ORDERNO.
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.
We will now print the GV_ORDERNO string variable in the table cell using Text object.
After all is completed, activate Smartform then execute Smartform with F8.
The final output will be as follows :
I hope ABAP developers will like this SAP Smartforms tutorial which focus how to deal with table calculations.