DATA : LV_FORMULA TYPE CHAR100,
LV_VALUE TYPE F,
LV_RESULT TYPE CHAR100,
LV_RETCODE LIKE SY-SUBRC,
LV_MESSAGE TYPE MSGTXT,
LV_CALC_AMT TYPE P DECIMALS 2.
* Input Value
LV_FORMULA = '(10*5)/10+i'.
CONDENSE LV_FORMULA.
REPLACE ALL OCCURRENCES OF 'i' IN LV_FORMULA WITH '1'.
* Check Fomula
CALL FUNCTION 'CHECK_FORMULA'
EXPORTING
FORMULA = LV_FORMULA
IMPORTING
SUBRC = LV_RETCODE
MESSAGE = LV_MESSAGE
EXCEPTIONS
ERROR_IN_FORMULA = 1
MISSING_PARAMETER = 2
OTHERS = 3.
CHECK LV_RETCODE IS INITIAL AND SY-SUBRC EQ 0.
* Eval Fomula
CALL FUNCTION 'EVAL_FORMULA'
EXPORTING
FORMULA = LV_FORMULA
IMPORTING
VALUE = LV_VALUE
EXCEPTIONS
DIVISION_BY_ZERO = 1
EXP_ERROR = 2
FORMULA_TABLE_NOT_VALID = 3
INVALID_EXPRESSION = 4
INVALID_VALUE = 5
LOG_ERROR = 6
PARAMETER_ERROR = 7
SQRT_ERROR = 8
UNITS_NOT_VALID = 9
MISSING_PARAMETER = 10
OTHERS = 11.
* Write
LV_CALC_AMT = LV_VALUE.
WRITE: LV_CALC_AMT TO LV_RESULT STYLE CL_ABAP_FORMAT=>O_SIMPLE.
CONDENSE LV_RESULT.
WRITE : LV_RESULT.
공유 감사합니다~~