Calculating and Printing Subtotals
Use
You want to print subtotals in accordance with a value in a different column. This column is then called the
sort criterion.
If you do not want to calculate totals for different currencies or quantity units, use the Calculations tab of the table node (see:
The solution described here refers to
printing old tables. However, it can easily be adapted for the new table node type.
Form
Prerequisites
You are printing a table using the table or loop node.
Procedure
We assume that you are already printing an internal table
T_SFLIGHT of type TABLE OF SFLIGHT . Now we want to print the table sorted by airline and include a subtotal of the price after each airline.The facts explained above result in the following form logic:
Form logic for calculating a subtotal according to a criterion
Navigation Tree |
Node Attributes/Contents/Conditions | |||
|
Loop :internal table T_SFLIGHT INTO GS_SFLIGHT Sort criteria: | |||
|
|
CARRID Beginning of sort level | |||
|
|
Output parameters: GT_SUBTOTAL , GS_SUBTOTAL . Program lines: REFRESH GT_SUBTOTAL. CLEAR GS_SUBTOTAL. | |||
|
|
&GS_SFLIGHT-PRICE& | |||
|
|
Input parameter : GS_SFLIGHTOutput parameter : GT_SUBTOTAL Program lines : data: ls_sflight type sflight. ls_sflight-price = gs_sflight-price. collect ls_sflight into gt_subtotal. | |||
|
|
&GS_SFLIGHT-CURRENCY& | |||
|
|
CARRID End of sort level | |||
|
|
Loop :internal table GT_SUBTOTAL INTO GS_SUBTOTAL | |||
|
|
&GS_SUBTOTAL-PRICE& | |||
|
|
&GS_SUBTOTAL-CURRENCY& | |||
Result
The subtotal (for each airline carrier) is printed before a break in the sort level.