ABAP 数字处理相关内容备注

it2022-05-05  113

ABAP 数学函数ABS  -Absolute value of the argument arg SIGN - +/- sign of the argument arg:        -1, if the value of arg is negative;         0, if the value of arg is 0;         1, if the value of arg is positive. CEIL     - Smallest integer number that is not smaller than the value of the argument arg. FLOOR - Largest integer number that is not larger than the value of the argument arg. TRUNC - Value of the integer part of the argument arg FRAC   - Value of the decimal places of the argument arg

DATA: I TYPE I,   P TYPE P DECIMALS 2,   M TYPE F VALUE '-3.5',   D TYPE P DECIMALS 1.

P = ABS( M ). " 3,5 I = P. " 4 - business rounding I = M. " -4 I = CEIL( P ). " 4 - next largest whole number I = CEIL( M ). " -3 I = FLOOR( P ). " 3 - next smallest whole number I = FLOOR( M ). " -4 I = TRUNC( P ). " 3 - integer part I = TRUNC( M ). " -3 D = FRAC( P ). " 0.5 - decimal part D = FRAC( M ). " -0.5

FM: ROUND 进行四舍五入DATA: x TYPE p DECIMALS 4 VALUE '1.2345',      y TYPE p DECIMALS 2,      z TYPE p DECIMALS 3.

WRITE:/ 'Original: ', x.z = x.WRITE:/ 'Direct Assign:', z.

CALL FUNCTION 'ROUND'  EXPORTING    decimals = 3    input    = x    sign     = '+' "sign = +/-/space.  IMPORTING    output   = y.

WRITE:/ 'FM Round:', y.

WRITE 语句控制小数点位置,  -n表示小数点向右移n位后再自动四舍五入. DATA: X TYPE P DECIMALS 2 VALUE '12493.97'.WRITE: /X ROUND -2,   "output: 1,249,397.00       /X ROUND  0,           "output: 12,493,97       /X ROUND  2,           "output: 124.94       /X ROUND  5,           "output: 0.12

ALV 货币输出, 指定参照货币,小数点位列以及 Round和SignNOTE: currency, decimal, round三个作用在同一个字段上时要注意运算顺序, 具体我现在也记不得了lr_column ?= lr_columns->get_column( 'DMBTR').lr_column->set_medium_text( 'Amt in Loc Curr'(448) ).lr_column->set_long_text( 'Amount in Local Curr'(449) ).lr_column->set_output_length( '13' ).lr_column->set_currency_column( 'L_WAERS' ). "/set_currency( 'USD' )lr_column->set_decimals_column( 'LOC_DEC' ). "/set_decimals( 2 )lr_column->set_round( lv_round ).lr_column->set_sign( abap_true ).lr_column->set_zero( abap_false ).

QUAN DEC类型 与 P类型 转换 转换公式 (n+1)/2 比如QUAN DEC定义为13位,其中3位小数 则ABAP的对应P型应该定义为 (13+1)/2 = 7data: p(7) type p decimals 3.

转载于:https://www.cnblogs.com/vibratea/archive/2010/09/16/1827830.html


最新回复(0)