Documentation View

We are hiring and constantly growing! Have a look through our vacancies to find the right role for you!

ABAPSELECT_AVG_AS - SELECT AVG AS

ABAPSELECT_AVG_AS - SELECT AVG AS

SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up   ABAP Short Reference  
This documentation is copyright by SAP AG.
SAP E-Book

- AVG, AS

... AVG( $[DISTINCT$] col AS dtype ) ...

Effect

Aggregate function AVG in with a data type dtype specified. The data type determines the result type in which the average value is returned. The data type of col must be numeric and have one of the types INT1, INT2, INT4, INT8, DEC, CURR, QUAN, or FLTP. The addition AS cannot yet be used for all types for decimal floating point numbers.

The data type dtype can have the built-in numeric type DEC, CURR, QUAN, DECFLOAT16, DECFLOAT34, or FLTP. The data type FLTP, however, can only be specified for operands of type FLTP. The data type dtype can be specified as follows:

  • DEC( len,decimals )
  • CURR( len,decimals )
  • QUAN( len,decimals )
  • D16N for DECFLOAT16
  • D34N for DECFLOAT34
  • FLTP

Length and decimal places must be specified with len and decimals. Literals or host constants of the ABAP type b, s, i, or int8 can be specified for len and decimals. The value range of the data type dtype must cover the value range of the operand type:

  • If col is an integer type, a type dtype of type DEC, CURR, QUAN must have at least as many integer digits as is required by the value range of the respective integer type, that is, 3 for INT1, 5 for INT2, 10 for INT4, and 19 for INT8. There is no restriction on the number of decimal places.
  • If col has type DEC, CURR, QUAN, a type dtype of type DEC, CURR, QUAN must have at least as many integer digits and decimal places.
  • If col has type FLTP, this type must also be specified for dtype.

The data types DECFLOAT16 and DECFLOAT34 can be used for all allowed data types of col except FLTP. If the average value cannot be represented exactly in the data type dtype, the result is rounded commercially.

Notes

  • The addition AS to AVG bridges the gap for average values where the default result type FLTP cannot be cast to other numeric data types with CAST.
  • Since average values usually have decimal places, integer types are not supported for dtype. If necessary, the type DEC can be used without decimal places.
  • An aggregate expression AVG cannot be applied to operands with the data type INT8 without using the addition AS. The addition AS can also be used to form average values for columns with data type INT8. However, for the types DF16_..., DF34_..., AVG is only possible without the addition AS.
  • The actual calculation of the average value depending on the involved data types is platform dependent. This can lead to platform-dependent underflows, overflows and corresponding exceptions during the calculation. To prevent exceptions, the total of the values for which the average value is calculated should be within the value range of dtype.
  • If FLTP is specified explicitly for operands of type FLTP, this ensures that the result of AVG actually has this type at each operand position, which cannot be guaranteed otherwise.
  • If used, D16N or D34N force the strict mode of the syntax check from Release .

Example

Application of the aggregate function AVG to a column of the DDIC database table DEMO_EXPRESSIONS. The program DEMO_SQL_AVG executes this access to the table and represents the result.






ROGBILLS - Synchronize billing plans   Fill RESBD Structure from EBP Component Structure  
This documentation is copyright by SAP AG.

Length: 6017 Date: 20230206 Time: 110524     sap01-206 ( 102 ms )