码迷,mamicode.com
首页 > 其他好文 > 详细

ABAP Help Document(16):9.1数字类型数据运算

时间:2021-04-23 12:07:40      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:mat   abap   span   判断   har   roc   into   nal   str   

9.Processing Internal Data

9.1Numerical Calculations

          类CL_ABAP_MATH,浮点数;CL_ABAP_RANDOM,获取随机数;

示例:

"算术运算statements
"[COMPUTE] [EXACT] result = arith_exp | string_exp | bit_exp.
"[COMPUTE] [EXACT] 同时,可省略
"arith_exp
*  [+|-] operand1
*  [{+|-|*|/|DIV|MOD|**} [+|-] operand2
*  [{+|-|*|/|DIV|MOD|**} [+|-] operand3
"string_exp
*{|string_template|}|{operand1 && operand2 [&&operand3]}
"bit_exp
*[BIT-NOT] operand1
*[{BIT-AND|BIT-OR|BIT-XOR} [BIT-NOT] operand2
*[{BIT-AND|BIT-OR|BIT-XOR} [BIT-NOT] operand3
FORM f_numerical_cal.
  DATA:lv_num TYPE decfloat34.
  DATA:lv_char TYPE C LENGTH 10.
  DATA:lo_exec TYPE REF TO cx_sy_conversion_rounding.
  TRY.
    DO 10 TIMES.
      "判断是否有conversion rounding
      COMPUTE EXACT lv_num = 3 / sy-index.
      WRITE:/ lv_num COLOR COL_POSITIVE INTENSIFIED OFF.
    ENDDO.
  CATCH cx_sy_conversion_rounding INTO lo_exec.
      WRITE:/ lv_num COLOR COL_NEGATIVE INTENSIFIED OFF.
  ENDTRY.

  "ADD operand TO result.
  ADD lv_num TO lv_char.
  WRITE:/ lv_char.
  "SUBTRACT dobj1 FROM dobj2.
  "相当于dobj2 = dobj2 - dobj1.
  SUBTRACT lv_num FROM lv_char.
  WRITE:/ lv_char.
  "MULTIPLY dobj1 BY dobj2.
  "dobj1 = dobj1 * dobj2
  MULTIPLY lv_num BY lv_num.
  WRITE:/ lv_num.
  "DIVIDE dobj1 BY dobj2.
  "dobj1 = dobj1 / dobj2
  DIVIDE lv_num BY lv_num.
  WRITE:/ lv_num.
ENDFORM.

ABAP Help Document(16):9.1数字类型数据运算

标签:mat   abap   span   判断   har   roc   into   nal   str   

原文地址:https://www.cnblogs.com/tangToms/p/14691190.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!