Summary:
See also: Variables, Data Types, Expressions, Literals.
The operators listed in this section can appear in Expressions. Expressions with several operators are evaluated according to their precedence, from highest to lowest, as indicated in the left-most (P) column. Use parentheses to instruct the runtime system to perform the expression evaluation in a different way than the default order of precedence.
The following list describes the precedence order of operators. The P column defines the precedence, from highest(14) to lowest(1). The A column defines the direction of associativity (L=Left, R=Right, N=None). Some operators have the same precedence.
P | Operator | A | Description | Example |
---|---|---|---|---|
14 | . (period) |
L | Membership | myrecord.member1 |
14 | variable[ ] |
L | Array index or character subscripts | myarray[2,x,y] |
14 | function( ) |
N | Function call | 1 + myfunc(10,"abc") |
13 | UNITS |
L | Single-qualifier interval | (integer) UNITS DAY |
12 | + |
R | Unary plus | + number |
12 | - |
R | Unary minus | - number |
11 | ** |
L | Exponentiation | x ** 5 |
11 | MOD |
L | Modulus | x MOD 2 |
10 | * |
L | Multiplication | x * y |
10 | / |
L | Division | x / y |
9 | + |
L | Addition | x + y |
9 | - |
L | Subtraction | x - y |
8 | || |
L | Concatenation | "Amount:" || amount |
7 | LIKE |
R | String comparison | mystring LIKE "A%" |
7 | MATCHES |
R | String comparison | mystring MATCHES "A*" |
6 | < |
L | Less than | var < 100 |
6 | <= |
L | Less then or equal to | var <= 100 |
6 | > |
L | Greater than | var > 100 |
6 | >= |
L | Greater than or equal to | var >= 100 |
6 | == |
L | Equals | var == 100 |
6 | <> or != |
L | Not equal to | var <> 100 |
5 | IS NULL |
L | Test for NULL | var IS NULL |
4 | NOT |
L | Logical inverse | NOT ( a = b ) |
3 | AND |
L | Logical intersection | expr1 AND expr2 |
2 | OR |
L | Logical union | expr1 OR expr2 |
1 | ASCII( ) |
R | ASCII Character | ASCII(32) |
1 | CLIPPED |
R | Delete trailing blanks | DISPLAY string CLIPPED |
1 | COLUMN (reports) |
R | Begin line mode display | PRINT COLUMN 32, "a" |
1 | (integer) SPACES |
R | Insert blank spaces | DISPLAY "a" (5) SPACES |
1 | LSTR(string) |
R | Load localized string | DISPLAY LSTR("str123") |
1 | SFMT(string [,p[...]]) |
R | Parameter replacement | DISPLAY SFMT("%1",123) |
1 | SQLSTATE |
R | SQL State Code | IF SQLSTATE="IX000" |
1 | SQLERRMESSAGE |
R | SQL Error Message | DISPLAY SQLERRMESSAGE |
1 | USING |
R | Format character string | TODAY USING "yy/mm/dd" |
1 | := |
L | Assignment | var := "abc" |
The following operators are related to SQL syntax and not part of the language:
The following operators are only available in the FORMAT section of report routines:
See the Report Definition for more details.
Parentheses are typically used to associate a set of values or expressions to override the default order of precedence.
( expr operator expr [...] )
01
MAIN02
DEFINE n INTEGER03
LET n = ( ( 3 + 2 ) * 2 )04
IF n=10 AND ( n<=0 OR n>=20 ) THEN05
DISPLAY "OK"06
END IF07
END MAIN
The period membership operator specifies that its right-hand operand is a member of the set whose name is its left-hand operand.
setname.element
01
MAIN02
DEFINE rec RECORD03
n INTEGER,04
c CHAR(10)05
END RECORD06
LET rec.n = 1234506
LET rec.c = "abcdef"07
END MAIN
The := assignment operator sets a value to the left-hand operand, which must be a variable.
variable := value
01
MAIN02
DEFINE var1, var2 INTEGER03
-- 1. Evaluates 2*504
-- 2. Sets var2 to 1005
-- 3. Then affects var1 with 1006
LET var1 = var2:=2*507
END MAIN
The IS NULL operator is provided to test whether a value is NULL.
IS NULL
01
MAIN02
DEFINE n INTEGER03
LET n = 25704
IF n IS NULL THEN05
DISPLAY "Something is wrong here"06
END IF07
END MAIN
The == operator evaluates if two expressions or two records are identical.
expr == expr
record1.* == record2.*
When comparing expressions using the first syntax, the result of the operator is FALSE when one of the operands is NULL.
When comparing two records using the second syntax, the runtime system compares all corresponding members of the records. If a pair of members are different, the result of the operator is FALSE. When two corresponding members are NULL, they are considered as equal.
01
MAIN02
IF 256==257 THEN03
DISPLAY "Something is wrong here"04
END IF05
END MAIN
The != operator evaluates if two expressions or two records are different.
expr != expr
record1.* != record2.*
When comparing expressions with the first syntax, the result of the operator is FALSE when one of the operands is NULL.
When comparing two records with the second syntax, the runtime system compares all corresponding members of the records. If one pair of members are different, the result of the operator is TRUE. When two corresponding members are NULL, they are considered as equal.
01
MAIN02
IF 256 != 257 THEN03
DISPLAY "This seems to be true"04
END IF05
END MAIN
The < operator is provided to test whether a value or expression is lower than another .
expr < expr
The <= operator is provided to test whether a value or expression is lower than or equal to another .
expr <= expr
The > operator is provided to test whether a value or expression is greater than another .
expr > expr
The >= operator is provided to test whether a value or expression is greater than or equal to another .
expr >= expr
The NOT operator is a typical logical NOT used to invert a Boolean expression.
NOT boolexpr
01
MAIN02
IF NOT ( 256 != 257 ) THEN03
DISPLAY "Something is wrong here"04
END IF05
END MAIN
The AND operator is the logical intersection operator.
boolexpr AND boolexpr
01
MAIN02
IF 256!=257 AND 256=257 THEN03
DISPLAY "Sure?"04
END IF05
END MAIN
The OR operator is the logical union operator.
boolexpr OR boolexpr
01
MAIN02
IF TRUE OR FALSE THEN03
DISPLAY "Must be true!"04
END IF05
END MAIN
The SQLSTATE operator returns the ANSI SQLSTATE code if an SQL error occurred.
SQLSTATE
01
MAIN02
DATABASE stores03
WHENEVER ERROR CONTINUE04
SELECT foo FROM bar05
DISPLAY SQLSTATE06
END MAIN
The SQLERRMESSAGE operator returns the error message if an SQL error occurred.
SQLERRMESSAGE
01
MAIN02
DATABASE stores03
WHENEVER ERROR CONTINUE04
SELECT foo FROM bar05
DISPLAY SQLERRMESSAGE06
END MAIN
The ASCII operator returns the character corresponding to the ASCII code passed as a parameter.
ASCII intexpr
01
MAIN02
DISPLAY ASCII 65, ASCII 66, ASCII 703
END MAIN
The LIKE operator returns TRUE if a string matches a given mask.
charexpr [NOT] LIKE "mask"
[
ESCAPE "ec" ]
01
MAIN02
IF "abcdef" LIKE "a%e_" THEN03
DISPLAY "yes"04
END IF05
END MAIN
The MATCHES operator returns TRUE if a string matches a given mask.
charexpr [NOT] MATCHES "mask"
[
ESCAPE "ec" ]
01
MAIN02
IF "abcdef" NOT MATCHES "b*[a-z]" THEN03
DISPLAY "yes"04
END IF05
END MAIN
The || operator is the concatenation operator that produces a string expression.
expr || expr
01
MAIN02
DISPLAY "Length: " || length( "ab" || "cdef" )03
END MAIN
The , operator appends a value to a string.
charexpr , expr
01
MAIN02
DISPLAY "Today:", TODAY, " and a number: ", 12345.6703
END MAIN
The [] operator is provided to extract a sub-string from a character variable.
charvar [ start [, end ] ]
01
MAIN02
DEFINE s CHAR(10)03
LET s = "abcdef"04
DISPLAY s[3,4]05
END MAIN
The USING operator converts datetime and numeric values into a string with a formatting mask.
expr USING "format"
Character |
Description |
* | Fills with asterisks any position that would otherwise be blank. |
& | Fills with zeros any position that would otherwise be blank. |
# | This does not change any blank positions in the display. |
< | Causes left alignment. |
, (comma) | Defines the position of the comma (not displayed if no digits on left). |
. (period) | Defines the position of the period (only one can be used). |
- | Displays a minus sign for negative numbers. |
+ | Displays a plus sign for positive numbers. |
$ | This is the placeholder for the front specification of DBMONEY or DBFORMAT. |
( | Displayed as left parentheses for negative numbers (accounting parentheses). |
) | Displayed as right parentheses for negative numbers (accounting parentheses). |
Character |
Description |
dd | Day of the month as a 2-digit integer. |
ddd | Day of the week as a 3-letter abbreviation. |
mm | Month as a 2-digit integer. |
mmm | Month as a 3-letter abbreviation. |
yy | Year, as a 2-digits integer representing the 2 trailing digits. |
yyyy | Year as a 4-digit number |
01
MAIN02
DEFINE d DECIMAL(12,2)03
LET d = -12345678.9104
DISPLAY d USING "$-##,###,##&.&&"05
DISPLAY TODAY USING "yyyy-mm-dd"06
END MAIN
The CLIPPED operator removes trailing blanks of a string expression.
charexpr CLIPPED
01
MAIN02
DISPLAY "Some text " CLIPPED03
END MAIN
The SPACES operator returns a character string with blanks.
intexpr SPACES
01
MAIN02
DISPLAY 20 SPACES || "xxx"03
END MAIN
The LSTR operator returns a Localized String corresponding to the identifier passed as parameter.
LSTR(strexpr)
01
MAIN02
DISPLAY LSTR ("str"||123) -- loads string 'str123'03
END MAIN
The SFMT operator returns string after replacing the parameter.
SFMT( strexpr [ , param [...] ]
)
The SFMT() operator can be used with parameters that will be automatically set in the string at the position defined by parameter place holders. The parameters used with the SFMT() operator can be any valid expression. Numeric and date/time expressions are evaluated to strings according to the current format settings (DBDATE, DBMONEY).
A place holder is a special marker in the string that is defined by the percent character followed by the parameter number. For example, %4 represents the parameter #4. You are allowed to use the same parameter place holder several times in the string. If you want to use the percent sign in the string, you must escape it with %%.
01
MAIN02
DEFINE n INTEGER03
LET n = 23404
DISPLAY SFMT("Order #%1 has been %2.",n,"deleted")05
END MAIN
The + operator adds a number to another.
numexpr + numexpr
01
MAIN02
DISPLAY 100 + 20003
END MAIN
The - operator subtracts a number from another.
numexpr - numexpr
01
MAIN02
DISPLAY 100 - 20003
END MAIN
The * operator multiplies a number with another.
numexpr * numexpr
01
MAIN02
DISPLAY 100 * 20003
END MAIN
The / operator divides a number by another.
numexpr / numexpr
01
MAIN02
DISPLAY 100 / 20003
END MAIN
The ** operator returns a value calculated by raising the left-hand operand to a power corresponding to the integer part of the right-hand operand.
numexpr ** intexpr
01
MAIN02
DISPLAY 2 ** 803
END MAIN
The MOD operator returns the integer remainder from the division of the integer part of two numbers.
intexpr MOD intexpr
01
MAIN02
DISPLAY 256 MOD 1603
DISPLAY 26.51 MOD 2.704
END MAIN
The CURRENT operator returns the current date and time according to the qualifier.
CURRENT qual1 TO qual2[(scale)]
01
MAIN02
DISPLAY CURRENT YEAR TO FRACTION(4)03
DISPLAY CURRENT HOUR TO SECOND04
END MAIN
The EXTEND operator adjusts a date time value according to the qualifier.
EXTEND ( dtexpr, qual1 TO qual2[(scale)]
)
01
MAIN02
DISPLAY EXTEND ( TODAY, YEAR TO FRACTION(4) )03
END MAIN
The DATE operator converts a character expression, an integer or a datetime to a date value.
DATE [(dtexpr)]
01
MAIN02
DISPLAY DATE ( 34000 )03
DISPLAY DATE ( "12/04/1978" )04
DISPLAY DATE ( CURRENT )05
END MAIN
The TIME operator converts the time-of-day portion of its datetime operand to a character string.
TIME [(dtexpr)]
01
MAIN02
DISPLAY TIME ( CURRENT )03
END MAIN
The TODAY operator returns the current calendar date.
TODAY
01
MAIN02
DISPLAY TODAY03
END MAIN
The YEAR operator extracts the year of a date time expression.
YEAR ( dtexpr )
01
MAIN02
DISPLAY YEAR ( TODAY )03
DISPLAY YEAR ( CURRENT )04
END MAIN
The MONTH operator extracts the month of a date time expression.
MONTH ( dtexpr )
01
MAIN02
DISPLAY MONTH ( TODAY )03
DISPLAY MONTH ( CURRENT )04
END MAIN
The DAY operator extracts the day of the month of a date time expression.
DAY ( dtexpr )
01
MAIN02
DISPLAY DAY ( TODAY )03
DISPLAY DAY ( CURRENT )04
END MAIN
The WEEKDAY operator extracts the day of the week of a date time expression.
WEEKDAY ( dtexpr )
01
MAIN02
DISPLAY WEEKDAY ( TODAY )03
DISPLAY WEEKDAY ( CURRENT )04
END MAIN
The MDY operator builds a date value with 3 integers representing the month, day and year.
MDY ( intexpr1, intexpr2, intexpr3 )
01
MAIN02
DISPLAY MDY ( 12, 3+2, 1998 )03
END MAIN
The UNITS operator converts an integer expression to an interval value.
intexpr UNITS qual[(scale)]
01
MAIN02
DEFINE d DATE03
LET d = TODAY + 20004
DISPLAY (d - TODAY) UNITS DAY05
END MAIN
The GET_FLDBUF operator returns as character strings the current values of the specified fields.
GET_FLDBUF ( [group.]field [,...] )
01
...02
LET v = GET_FLDBUF( customer.custname )03
CALL GET_FLDBUF( customer.* ) RETURNING rec_customer.*04
...
The INFIELD operator returns TRUE if its operand is the identifier of the current screen field.
INFIELD ( [group.]field )
01
...02
INPUT ...03
IF INFIELD( customer.custname ) THEN04
MESSAGE "The current field is customer's name."05
...
The FIELD_TOUCHED operator returns TRUE if the value of a screen field has changed since the beginning of the interactive instruction.
FIELD_TOUCHED ( [group.]field
[,...] )
01
...02
INPUT ...03
IF FIELD_TOUCHED( customer.custname ) THEN04
MESSAGE "Customer name was changed."05
...