Get Example source ABAP code based on a different SAP table
• rescale ABAP_FUNCTION • round ABAP_FUNCTION • val round function • val rescale function • mode round function • mode rescale function • dec round function • dec rescale function • prec round function • prec rescale function
ABAP_NUMFUNC > - round>, rescale>
ABAP_SYNTAX ... round$|rescale( val = arg ... ) ...>
What does it do? The built-in> rounding functions expect a decimal floating point number> as a main argument val> and additional arguments that describe how this floating point number is handled. The type of the return value of a rounding function is always decfloat34 >. Within an arithmetic expression, the argument for the decimal floating point number can either be an arithmetic expression or a function. The other arguments must always be specified as numeric data objects. ITOC
Latest notes: The class CL_ABAP_MATH>> includes the method NORMALIZE> for normalizing a decimal floating point object. The mantissa does not have any closing zeros in a normalized floating point number. NON_V5_HINTS ABAP_HINT_END
Rounding Function The rounding function round> can be implemented in operand positions> using the following syntax:
What does it do? This function rounds a decimal floating point number specified as an argument for the parameter val>. A data object specified for arg> is converted to the data type decfloat34> before the function is executed, if necessary. Either the parameter dec> or the parameter prec> must be given a value, and rounding must be to either a particular number of decimal places or to a precision>:
If the parameter dec> is given a value, the input value is rounded to the number of decimal places specified in n> and returned. n> expects data objects of the type i> whose value must not be less than -6144. If a negative value is specified, the corresponding pre-decimal place is rounded.
If the parameter prec> is given a value, the value entered is rounded to the precision> specified in n > and returned. n> expects data objects of the type i> whose value must be greater than 0. A rounding can reduce scaling> and precision> but cannot increase them. If dec> is specified, the mantissa of the return value does not contain any zeros after the place where the rounding applies. If prec> is specified, the input value is returned unchanged if the specified precision is greater than or equal to the input value. The optional parameter mode> determines the rounding type. For m> it is only possible to specify values that exist as ROUND_...> constants in class CL_ABAP_MATH>>. The following table shows the possible rounding rules. If mode> is not given a value, commercial rounding is used. Constant>Rounding rule> ROUND_HALF_UP>The value is rounded down to the nearest rounded value. If the value falls exactly halfway between two rounded values, it is rounded away from zero (commercial rounding). ROUND_HALF_DOWN>The value is rounded down to the nearest rounded value. If the value falls exactly halfway between two round values, it is rounded towards zero. ROUND_HALF_EVEN>The value is rounded down to the nearest rounded value. If the value falls exactly halfway between two rounded values, it is rounded to the value whose last place is an even number. ROUND_UP>The value is always rounded away from zero or towards the greater absolute value. ROUND_DOWN>The value is always rounded from zero or towards the lesser absolute value. ROUND_CEILING>The value is always rounded in a positive direction or towards the greater value. ROUND_FLOOR>The value is always rounded in a positive direction or towards the greater value.
ABAP_EXAMPLE_VX5 The following tables show the results of commercial rounding of the decimal floating point number 1234.56789> (scaling 5, precision 9) with different values for dec> and prec>. The shown results shown are created by executing the class CL_DEMO_ROUND_AND_RESCALE>>. dec>Result>Scaling>Precision> -5>0E+5>-5>1> -4>0E+4>-4>1> -3>1E+3>-3>1> -2>1.2E+3>-2>2> -1>1.23E+3>-1>3> 0>1235>0>4> 1>1234.6>1>5> 2>1234.57>2>6> 3>1234.568>3>7> 4>1234.5679>4>8> 5>1234.56789>5>9> 6>1234.56789>5>9> prec>Result>Scaling>Precision> 1>1E+3>-3>1> 2>1.2E+3>-2>2> 3>1.23E+3>-1>3> 4>1235>0>4> 5>1234.6>1>5> 6>1234.57>2>6> 7>1234.568>3>7> 8>1234.5679>4>8> 9>1234.56789>5>9> 10>1234.56789>5>9> ABAP_EXAMPLE_END
ABAP_EXAMPLE_ABEXA Rounding Function round>> ABAP_EXAMPLE_END
Rescaling Function The rescaling function rescale> can be implemented in operand positions> using the following syntax:
What does it do? This function changes the scaling> of a decimal floating point number specified as an argument for the parameter val >. A data object specified for arg> is converted to the data type decfloat34> before the function is executed, if necessary. Either the parameter dec> or the parameter prec> must be given a value, where either the scaling> or the precision> is set:
If the parameter dec> is given a value, the input value is returned using the scaling> specified in n >. n> expects data objects of the type i >, whose value must not be less than -6144. If the scaling would produce more than 34 places in the mantissa of the return value, a catchable exception is raised.
If the parameter prec> is given a value, the value entered is returned with the precision> specified in n> and appropriate scaling>. n> expects data objects of the type i>, whose value must be greater than 0 and less than 34. A rescaling can both reduce and increase scaling > and precision>. An increase adds zeros on the right. The input value is rounded if required. The optional parameter mod > can be used to specify the rounding rule, as described under the function round>. The default is commercial rounding.
ABAP_EXAMPLES The following tables shows the results for rescaling of the decimal floating point number 1234.56789> (scaling 5, precision 9) with various values for dec> and prec>, if commercial rounding is used. The results shown are generated by executing the class CL_DEMO_ROUND_AND_RESCALE>>. dec>Result>Scaling>Precision> -5>0E+5>-5>1> -4>0E+4>-4>1> -3>1E+3>-3>1> -2>1.2E+3>-2>2> -1>1.23E+3>-1>3> 0> 1235>0>4> 1>1234.6>1>5> 2>1234.57>2>6> 3>1234.568>3>7> 4>1234.5679>4>8> 5>1234.56789>5>9> 6>1234.567890>6>10> 7>1234.5678900>7>11> 8>1234.56789000>8>12> prec>Result>Scaling>Precision> 1> 1E+3>-3>1> 2> 1.2E+3>