DTRHELP.HLB  —  Value Expressions, Arithmetic Expressions
       An arithmetic expression consists of value expressions and
       arithmetic operators. The value expressions must all be numeric.
       You can use an arithmetic expression anywhere the syntax of a DEC
       DATATRIEVE statement allows a value expression.

       DEC DATATRIEVE provides four arithmetic operators. These are +
       (addition), - (subtraction or negation), * (multiplication), and
       / (division).

       You do not have to use spaces to separate arithmetic operators
       from value expressions, except in one case: if a DEC DATATRIEVE
       name precedes a minus sign, you must put a space before the minus
       sign. Otherwise, DEC DATATRIEVE interprets the minus sign as a
       hyphen and converts it to an underscore:

       DTR> DECLARE X PIC 99.
       DTR> X = 8
       DTR> PRINT X-1
       "X_1" is undefined or used out of context
       DTR> PRINT 1-X
         -7

       DTR>

       You can use parentheses to control the order in which DEC
       DATATRIEVE performs arithmetic operations. DEC DATATRIEVE
       follows the normal rules of precedence when evaluating arithmetic
       expressions:

       1. DEC DATATRIEVE first evaluates any value expressions in
          parentheses.

       2. DEC DATATRIEVE then performs multiplications and divisions
          from left to right in the arithmetic expression.

       3. Finally, DEC DATATRIEVE performs additions and subtractions
          from left to right in the arithmetic expression.

       The following examples show how DEC DATATRIEVE evaluates
       arithmetic expressions:

       DTR> PRINT (6 * 7) + 5
         47

       DTR> PRINT 6 * (7 + 5)
         72

       DTR> PRINT 6 + 7 * 5
         41

       DTR> PRINT 12 - 6 * 2
          0
       DTR> PRINT 5 + 10 / 2
          10

       DTR>

       DEC DATATRIEVE performs arithmetic operations on relational
       databases null values according to SQL/Services[TM] standards.
       For example: an arithmetic or string operation generates null
       when one of the operands is null.

       DTR> FOR X IN EMPLOYEE_MANAGER_TABLE PRINT  EMP_ID

        EMP_ID

             10
             15
             30
           NULL
           NULL

       DTR> FOR X IN EMPLOYEE_MANAGER_TABLE PRINT  EMP_ID + 1000

            1010
            1015
            1030
            NULL
            NULL
       DTR>
Close Help