Get Example source ABAP code based on a different SAP table
• AVG, AS ABAP_OSQL_AGG_EXP • DEC AVG, AS • CURR AVG, AS • QUAN AVG, AS • D16N AVG, AS • D34N AVG, AS • FLTP AVG, AS
ABAP_SQLAGG > - AVG>, AS>
ABAP_SYNTAX ... AVG( $[DISTINCT$] col> AS dtype ) ...>
What does it do? Aggregate function AVG>> in AB_SQL 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.
Latest 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. NON_V5_HINTS
If used, D16N> or D34N> force the ABAP_STRICT_777 strict mode of the syntax check from ABAP_RELEASE ABAP_777 / . ABAP_HINT_END
ABAP_EXAMPLE_VX5 Application of the aggregate function AVG> to a column of the DDIC database table DEMO_EXPRESSIONS>. The class CL_DEMO_SQL_AVG>> implements this access to the table and can be executed to show the result. ABEXA 00585 ABAP_EXAMPLE_END