SAP Function EVAL_FORMULA - Analysis of a syntactically correct formula

Parameter Reference Type Length Default Optional Text
DEGREES 0 SPACE X Operators for angle function specified in GRAD
FORMULA 0 Formula to be calculated
NO_EXISTENCE_CHECK 0 SPACE X 'X' if existence of program/routine is not to be checked
PROGRAM 0 SPACE X Program for value assignment to a variable
ROUTINE 0 SPACE X Routine for value assignment to a variable
UNIT_OF_MEASURE 0 SPACE X Unit of measurement for calculated value

Parameter Reference Type Length Text
VALUE 0 calculated value of the formula

Exception Text
DIVISION_BY_ZERO Division by zero
EXP_ERROR Invalid argument for exponential function
FORMULA_TABLE_NOT_VALID Invalid formula set
INVALID_EXPRESSION Syntax errors
INVALID_VALUE Invalid Value
LOG_ERROR Invalid argument for logarithmic function
MISSING_PARAMETER Program or Routines Missing for Variables
PARAMETER_ERROR Invalid parameter
SQRT_ERROR Invalid argument for root function
UNITS_NOT_VALID Invalid unit of measure

Functionality
The function module EVAL_FORMULA evaluates Literal or Variableformulas. It accepts:

  • arithmetic formulas (with floating point result of type FLOAT)

  • logical formulas (with result TRUE or FALSE)

  • conditions of the form IF THEN


  • ,,ELSE

    • expressions with fields of structure SY

    • Example:
      FORMEL = COS(A**2+B**2)
      FORMEL = IF X>0 THEN SIN(X) ELSE SIN(-X)
      FORMEL = SY-TZONE / 2.324
      Functions
      The FM supports the following functions:
      ABS,,absolute value
      NOT,,negation
      SIN,,sine function
      COS,,cosine function
      TAN,,tangent function
      LOG,,logarithm to base e (natural logarithm)
      EXP,,exponential function to base e
      SQRT,,square root function
      ROUND,,round to a whole number
      TRUNC,,truncate, the whole number part of a real number
      MOD,,modulus function
      DIV,,whole number part of a division
      Operators
      The operators are classified into 6 priority groups. Group 0 has thelowest priority, group 6 the highest.
      The operators are:
      group 0:
      AND,,logical AND
      OR,,logical OR
      group 1:
      =,,equals
      <>, ><,,not equal to
      <,,less than
      >,,greater than
      <=, =<,,less than or equal to
      >,,greater than
      =>, >=,,greater than or equal to
      group 2:
      +,,positive value (of an expression)
      -,,negative value (of an expression)
      +,,addition
      -,,subtraction
      group 3:
      *,,multiplication
      /,,division
      group 4:
      **,,exponential
      group 5:
      ABS,,absolute value
      NOT,,negation (of a logical expression)
      group 6:
      all other functions.
      User-defined formulas
      The FM also evaluates user-defined functions, which are defined in atable.

      Description
      The parameter VALUE contains the function evaluation result.

      Description
      Enter the angle function operators in GRAD.

      Description
      The parameter FORMULA contains the formula to be evaluated.

      Description
      The parameter PROGRAM specifies a user-specific program which assignsvalues to the variables in the formula.

      Description
      The parameter ROUTINE specifies a user-specific routine which assignsvalues to variables in the formula.

      Description
      The parameter UNIT_OF_MEASURE determine the measurement unit of thevalue which the formula calculates.