代码摘至程序RSCALC10,部分修改.
REPORT ZDEMO_FORMULA.
DATA:
RETCODE TYPE SY-SUBRC,
FUNCNAME(30) TYPE C,
MESSAGE(70) TYPE C,
POS TYPE I,
C TYPE I.
PARAMETERS FORMEL type formel.
PERFORM. MIN.
FORM. MIN.
*check formula
CALL FUNCTION 'CHECK_FORMULA'
EXPORTING FORMULA = FORMEL
IMPORTING SUBRC = RETCODE
FUNCNAME = FUNCNAME
MESSAGE = MESSAGE
POS = POS
EXCEPTIONS
ERROR_IN_FORMULA = 1
MISSING_PARAMETER = 2
THERS = 3.
IF SY-SUBRC EQ 0."formula is ok
* IF RETCODE IS INITIAL.
* work out formula
CALL FUNCTION 'EVAL_FORMULA'
EXPORTING FORMULA = FORMEL
IMPORTING VALUE = C
EXCEPTIONS OTHERS = 1.
IF SY-SUBRC EQ 0.
WRITE: / 'successful!'.
write: / .
write: / 'c:', 20 C.
ELSE.
WRITE: / 'error!'.
write: / .
WRITE: / 'sy-subrc:', 20 SY-SUBRC.
ENDIF.
* ELSE.
* WRITE: / FUNCNAME, MESSAGE, POS.
* ENDIF.
ELSE.
WRITE: / 'CHECK_FORMULA',20 'error!'.
ENDIF.
ENDFORM.