SAP ABAP SYNTAX FOR COMPUTE

Basic form

COMPUTE n = arithexp.

Effect

Evaluates the arithmetic expression arithexp and places the result in the field n .

Allows use of the four basic calculation types + , - , * and / , the whole number division operators DIV (quotient) and MOD (remainder), the exponentiation operator ** (exponentiation " X ** Y means X to the power of Y ) as well as the functions listed below.

When evaluating mixed expressions, functions have priority. Then comes exponentiation, followed by the "point operations" * , / , DIV and MOD , and finally + and - . Any combination of parentheses is also allowed.

The fields involved are usually of type I , F or P , but there are exceptions to this rule (see below).


You can omit the key word COMPUTE .
Built-in functions
  • Functions for all number types
ABS Amount (absolute value) |x| of x SIGN Sign (preceding sign) of x;
 
                            1        x > 0
 
               SIGN( x ) =  0   if   x = 0
 
                           -1        x <>
CEIL Smallest whole number value not less than x FLOOR Greatest whole number value not greater than x TRUNC Whole number part of x FRAC Decimal part of x
  • Floating point functions
ACOS Arc cosine(x) in the range [-pi/2, pi/2], x from [-1, 1] ASIN Arc cosine(x) in the range [0, pi], x aus [-1, 1] ATAN Arc tangent(x) in the range [-pi/2, pi/2] (pi = 3.1415926535897932) COS Cosine of an angle specified in the arc SIN Sine of an angle specified in the arc TAN Tangent of an angle specified in the arc COSH Hyperbola cosine SINH Hyperbola sine TANH Hyperbola tangent EXP Exponential function for base e = 2.7182818284590452 LOG Natural logarithm (i.e. base e) of a positive number LOG10 Logarithm of x for base 10, x > 0 SQRT Square root of a non-negative number
String functions

STRLEN Length of a string up to the last non-blank character (i.e. the occupied length )
Function expressions consist of three parts:
Function identifier directly followed by an opening parenthesis Argument Closing parenthesis
All parts of an expression, particularly any parts of a function expression, must be separated from each other by at least one blank.

Example

The following statements, especially the arithmetic expressions, are syntactically correct:
 
DATA: I1 TYPE I, I2 TYPE I, I3 TYPE I,
      F1 TYPE F, F2 TYPE F,
      WORD1(10), WORD2(20).
...
F1 = ( I1 + EXP( F2 ) ) * I2 / SIN( 3 - I3 ).
COMPUTE F1 = SQRT( SQRT( ( I1 + I2 ) * I3 ) + F2 ).
I1 = STRLEN( WORD1 ) + STRLEN( WORD2 ).

No comments :

Post a Comment