Entering content frameBackground documentationTotaling and Counting  Locate the document in its SAP Library structure

Totaling

Whenever you create a list in the Query Painter, all numeric fields are automatically totaled. These totals are displayed at the end of the list. All numeric fields are also placed in the Totaling fields toolbar. To undo totaling for specific fields, select the fields from the toolbar and drag them to the trash or drag the trash to them or to the corresponding total in your list layout.

If sort fields have been defined for your list, subtotals are automatically displayed at the end of each control level. If you want to undo subtotaling for a specific sort level, select the trash can and drag it to the appropriate subtotal on the list layout display. To suppress all subtotaling functions, deselect the field Display totals in the Output Options for Control Levels.

If you are totaling a particular field, the total is output in the same column as the field, that is with the same output length. For this reason, the output length may be too short for the total and cause overflow. ABAP identifies these overflows by placing an asterisk in front of the affected value when it is output.

To avoid overflows like this when outputting totals, you can simply increase the output length of the field.

If you total fields containing values in different currencies, the totals are created according to currency.

Currency-specific summation also applies when you specify the output of the currency amount field without a unit. Then, several currencies (without a currency) appear in the totals lines. For this reason, you should always output currency amounts with a currency.

The same applies to quantity fields. If you specify summation for a quantity field, this is performed according to the units involved and results in a distribution in the totals lines.

Counting

In contrast to totals, counting fields are not automatically displayed. To count a field, proceed as follows:

  1. Choose Tools ® Counting fields on/off.
  2. The Counting fields toolbar is not switched on in the standard.

  3. Drag the field you want to count to the Counting fields toolbar.

The number of times this field appears is displayed at the end of the list. If sort fields have been defined for your list, preliminary counts are automatically displayed at the end of each control level. To suppress these preliminary counts, deselect the field Display count in the Output Options for Control Levels.

Finally, the options Total and Counter should be compared one more time.

The Total option causes the grand total of a specified numeric field to be calculated. This means that each time the field is read in a dataset, the field’s value is added to the sum total. The grand total is displayed at the end of the basic list. With control levels, you can also display subtotals. A subtotal contains all values of a field that are assigned to a particular control level, that is a particular sort string.

The Counter option causes the counter number for a particular field to be increased by 1 every time that this field is found within the data set currently being read. The resulting counter total is displayed in much the same manner as a grand total at the end of the basic list. Just as with totals, counter subtotals can be displayed for individual control levels. These counter subtotals show how many values have been assigned to a particular control level.

Example

You want to create a list that displays information about the airline ticket sales of a specific airline over a certain period of time. In addition, you want to display how many flights per flight connection are planned.

Proceed as follows:

  1. First, create a QuickView with logical database F1S as its data source. Further information can be found under Creating QuickViews.
  1. Select the following fields in the upper left-hand window in the Query Painter. Airline ID, Flight code, Departure airport, Departure city, Arrival airport, Destination (city), Flight date, Airplane type, Maximum occupancy, Occupied seats, and Current total of revenues.
  1. Use the trash can to delete all sum totals except for the sum total for the field Current total of revenues.
  1. Drag the fields Airline ID and Flight code to the Sort Fields toolbar.
  1. Hide the control level text for Flight code by clicking on it and undoing its field selection in the Output Options for Control Levels.
  1. Drag the Airline ID field to the trash, since it is displayed in the control level text.
  1. Click on the control level text for Airline ID and change it to Airline.
  1. Switch on the Counting fields toolbar and drag the field Flight date to it.
  1. Choose Node assignment. The fields in the first line of the list have been taken from different levels of your logical database hierarchy.

This graphic is explained in the accompanying text

This means that the list is displayed as follows:

This graphic is explained in the accompanying text

The fields Departure city, Destination (city) etc. have to be displayed for each connection, even though appropriate positioning of the fields could make this unnecessary. Organize your fields in such a manner that only fields highlighted in red are found in the first line. Further information can be found under Positioning and Sizing and in The Hierarchy Display.

  1. Change the texts for subtotals and preliminary counter totals by clicking on them.
  1. Insert separators (using the icon in the toolbox) and add additional slashes before and after list lines as you deem necessary. Further information can be found under List Line Output Options
  1. Execute your QuickView. Enter an airline and a time period on the selection screen.

A list similar to the following might appear:

This graphic is explained in the accompanying text

Leaving content frame