In this recipe, we will see how we can sort a given table within the Smart Form and calculate totals based on a particular field as the sort criterion. In this recipe, we will use an example of employees and their allowances and amounts.
For this recipe, we define a structure in the database ZST9_EMPLOYEES comprising three fields PERNR, ALLOWANCE, and AMOUNT. We define a table type also based on this structure, as shown in the following screenshot:
A table EMPLOYEE_TABLE (based on the defined dictionary table type) is included in the TABLES tab of the Smart Form interface, and a corresponding work area WA_EMPLOYEE in the global definition.
A table is then created on the Smart Form layout. The loop of the table is shown as follows:
Appropriate texts are created within the cells in order to print the employee number, allowance, and amount values passed. A program is then created and the Smart Form is called. A tabular output is generated.
In this recipe, we will see how sorting along with totaling may be so that the total of each employee's allowance is printed at the end of each employee's details.
For subtotaling and sorting, proceed as follows:
PERNR
as the field name.The settings we did in the Smart Form will output the subtotal of the allowances of each employee as shown. At the end of each employee, the total allowances are calculated and printed.
The entries made on the Calculation tab of the table totals all the amounts of a particular PERNR field (the SORT
criterion) and stores in the SUBTOTAL variable. The output will then be generated at the EVENT
on SORT
end. After that, we clear the old value of SUBTOTAL so that the value of the next employee may be calculated.
18.222.118.90