matinal:SAP ABAP 函数EVAL_FORMULA的使用

2023-11-10 08:37:46 浏览数 (1)

代码语言:javascript复制
DATA : PROG(20)   VALUE ‘ZTEST_FORMULA_1′,
FORME(15) VALUE ‘GET_EVAL_VALUES’,
FORMC(16) VALUE ‘GET_CHECK_VALUES’,
FUNC(30),
MESS(80),
POSITION(2),
RC LIKE SY-SUBRC,
UNIT LIKE T006D-MSSIE,
RESULT TYPE i.
DATA : FORMEL1(50)  VALUE ‘TFKT:10*A   5* B   3**C’,
FORMEL2(50)  VALUE ‘10*A   5* B   3**C’,
FORMEL3(50)  VALUE ‘TFKT:TCFORMULA1(A,B,C)’.
“PERFORM FORMEL USING FORMEL1.”Error!!!!
PERFORM FORMEL USING FORMEL2.
PERFORM FORMEL USING FORMEL3.
*———————————————————————–
*  Formel     Formula Check and Manipulate
*———————————————————————–
FORM FORMEL USING FORMEL.
CALL FUNCTION ‘CHECK_FORMULA’
EXPORTING
FORMULA           = FORMEL
PROGRAM           = PROG
ROUTINE           = FORMC
UNIT_OF_MEASURE   = UNIT
IMPORTING
FUNCNAME          = FUNC
MESSAGE           = MESS
POS               = POSITION
SUBRC             = RC.
IF RC IS INITIAL.
CALL FUNCTION ‘EVAL_FORMULA’
EXPORTING
FORMULA            = FORMEL
PROGRAM            = PROG
ROUTINE            = FORME
UNIT_OF_MEASURE    = UNIT
IMPORTING
VALUE              = RESULT
EXCEPTIONS
DIVISION_BY_ZERO   = 1
EXP_ERROR          = 2
INVALID_EXPRESSION = 3
INVALID_VALUE      = 4
LOG_ERROR          = 5
PARAMETER_ERROR    = 6
SQRT_ERROR         = 7
UNITS_NOT_VALID    = 8
FORMULA_TABLE_NOT_VALID = 9.
IF sy-subrc <> 0.
WRITE : / FORMEL,‘Error!!!’.
else.
WRITE : / FORMEL,RESULT,UNIT.
ENDIF.
ELSE.
WRITE : / FORMEL,
/ FUNC,
/ MESS,
/ POSITION,
/ RC.
ENDIF.
ENDFORM.
*———————————————————————–
*  GET_EVAL_VALUES    For Real-parameter ==> Formal Parameters
*———————————————————————–
FORM GET_EVAL_VALUES  USING    PARM
CHANGING WERT
SUBRC.
CASE PARM.
WHEN ‘A’.
WERT  = 3.
SUBRC = 0.
WHEN ‘B’.
WERT  = 2.
SUBRC = 0.
WHEN ‘C’.
WERT  = 2.
SUBRC = 0.
WHEN OTHERS.
SUBRC = 1.
ENDCASE.
ENDFORM.
*———————————————————————–
*  GET_CHECK_VALUES    Bypass  Formal Parameters
*———————————————————————–
FORM GET_CHECK_VALUES USING PARM
CHANGING SUBRC.
CASE PARM.
WHEN ‘A’.
SUBRC = 0.
WHEN ‘B’.
SUBRC = 0.
WHEN ‘C’.
SUBRC = 0.
WHEN OTHERS.
SUBRC = 1.
ENDCASE.
ENDFORM.

0 人点赞