Show TOC

Calculations on Items of a Sort LevelLocate this document in the navigation structure

Prerequisites

You created a table node and use the Data tab to read your internal table.

Context

You want to calculate a total, the average value, or the number of items for all values of a sort level.

Procedure


  1. On the Data tab enter a sort criterion and mark Event on Sort Begin and Event on Sort End.

  2. Go to the Calculations tab.

  3. In the Operation column select the desired operation.

  4. If you selected Total or Average Value as operation, in the Field Name enter a field (usually a field of the work area) that you want to use to execute the operation.

    Example

    You want to calculate the total of all prices of an airline. Read the data from the internal table FT_SFLIGHT with line structure SFLIGHT line by line into the work area WA_SFLIGHT. To sum up the price, enter WA_SFLIGHT-PRICE as Field Name.

  5. As Target Field Name enter a field with the same data type as the field from the last step. This can be a field from the global definitions or from the form interface.

  6. As calculation event specify After Loop or Before Loop.

    Note

    For the operations Total or Average Value use After Loop. It is not possible to use the event Before Loop to display a total of the table items to come, because the calculation event refers to one loop pass only and not to the entire loop.

  7. To initialize the target field before table output, mark the checkbox in the Initialization column.

  8. To initialize the target field after each sort level, mark Sort Criterion in the Reset column and in the next column enter the name of the sort criterion at whose sort level beginning you want to initialize the field.

    Caution

    To enable SAP Smart Forms to execute the initialization, you must mark Event on Sort Begin on the Data tab.

  9. If the target field refers to a currency or quality field, you must assign the correct currency or unit to this field before displaying it; this is then valid for the entire table output. To do this, create a program lines node. If the reference field is stored in a different table, refer to Displaying Fields That Refer to Currencies or Quantities.

Results

You display the result of your calculation in the event node at the end of the sort level. When you use the Number operation to consecutively number the items of the sort level, display the target field within the main area.