前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >matinal:SAP ABAP 函数EVAL_FORMULA的使用

matinal:SAP ABAP 函数EVAL_FORMULA的使用

作者头像
matinal
发布2023-11-10 08:37:46
2710
发布2023-11-10 08:37:46
举报
文章被收录于专栏:SAP Technical
代码语言: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.
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-11-09,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档