ABAP Rounding function

Source: Internet
Author: User

ABAP Rounding function

There are a number of function methods for processing data in ABAP , involving rounding of two (and possibly more):ROUND and hr_nz_rounding_decimals

The former is located in the basis function development package Szme inside, in the standard for the calculation of units of measurement;

The latter is mainly used in the HR module, located in the PB43 development Package, processing the master data in the HR module.



hr_nz_rounding_decimals The function can enter a numeric value directly and then enter a decimal point to be preserved in the conv_dec parameter to output.

The ROUND function is somewhat flexible and can be controlled up or down by the sign parameter (' + ', '-').

For example:

Enter 88.54350, if sign = ' + ', retain 2 decimal places, will get: 88.55000; if sign = '-', you will get: 88.54000

Input-88.54350, if sign = ' + ', retains 2 decimal places, will get:-88.54000; if sign = '-', you will get:-88.55000

To view an example:

01020304050607080910111213141516171819202122232425262728293031323334353637383940 DATA : dat  TYPE p DECIMALS 9 VALUE ‘12.5445‘ ,        dat1 TYPE p DECIMALS 9 .   DATAdat2 TYPE p DECIMALS 9 VALUE ‘12.540‘. * 方法一 CALL FUNCTION ‘HR_NZ_ROUNDING_DECIMALS‘  EXPORTING    value_in                 = dat     conv_dec                 = 2" 设置保留几位小数   IMPORTING    value_out                = dat1   EXCEPTIONS    no_rounding_required     = 1     decimals_greater_than_10 = 2     rounding_error           = 3     OTHERS= 4.  WRITE: /‘方法一(保留2位小数):‘. WRITE: / dat, ‘ => ‘ ,dat1. WRITE: / ‘----------------------------------------------------‘. * 方法二 CALL FUNCTION ‘ROUND‘  EXPORTING    decimals      = 0" 保留多少位小数     input         = dat2     sign          = ‘+‘" + 向上取舍 - 向下取舍 (负数也一样)   IMPORTING    output        = dat1" 输出返回结果   EXCEPTIONS    input_invalid = 1     overflow      = 2     type_invalid  = 3     OTHERS= 4.  WRITE: /‘方法二(保留0位小数):‘. WRITE: / dat2, ‘ => ‘ ,dat1. WRITE: / ‘----------------------------------------------------‘.

ABAP Rounding function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.