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.