Literals, Symbols and Variables

Data can be expressed as a literal, a symbol or a variable. There are two types of literal data: numeric and string.

Numeric Literals

A numeric literal consists of a series of digits representing an amount. It can contain any number of digits to the left of the decimal point and up to 9 digits to the right. The unary minus sign specifies a negative value. For example, -3.4, -17000000 and -14.3375.

String Literals

A string literal consists of a set of ASCII characters enclosed in single or double quotes, or backslashes. If the string includes single quotation marks (apostrophes), it must be delimited by double quotes, and vice versa. For example:

"Mr. Wilson's report"
'Test of the "GOTO" statement'

String size is only limited by the available workspace on the system.

The following are examples of valid string literals:

"ABC%123#*4AB"
'"1Q2Z"....'
"A 'literal' string"
'COMPLETED'
' '
\Yet another string literal\

Symbols

A symbol is an identifier which is assigned a value which can be any DataBasic expression. Symbols are most commonly used to give meaningful names to literal values and can also be used to define macros. The value assigned to a symbol is set once (usually at the start of the program or subroutine); once given a value, a symbol cannot be changed.

Using a symbol, where appropriate, instead of a literal value or variable has the following advantages:

To define a symbol, use the EQUATE or the $DEFINE statement. For example:

EQU LIT TO "A 'literal' string" EQUATE MAX.COUNT TO 10

The EQUATE or $DEFINE statement must appear before the symbol is used in the program.

When you compile your program, all occurrences of each symbol are replaced with the corresponding value: a literal value, the name of a variable, a reference to an array element or a DataBasic expression. For example, if your code contains the following statement:

EQUATE VAR TO T.CODE<N>

when the code is compiled, all occurrences of VAR are replaced with T.CODE<N>. The value of N is determined at run time.

Predefined Symbols

The following predefined symbols are available:

Symbol

Value

Description

@ACCOUNT

SYSTEM(19)

Account name.

@AM or @FM

CHAR(254)

Attribute/field mark.

@DATE

DATE()

System date.

@FALSE

0 (zero)

Boolean false.

@IM

CHAR(255)

Segment/item mark.

@LEVEL

SYSTEM(16)

PERFORM level.

@LOGNAME

SYSTEM(50)

User-id.

@LPTRHIGH

SYSTEM(3)

Current page length as defined by the TERM command.

@LPTRWIDE

SYSTEM(2)

Current page width as defined by the TERM command.

@SM or @SVM

CHAR(252)

Subvalue mark.

@TIME

TIME()

System time.

@TM

CHAR(251)

Start of buffer/text mark.

@TRUE

1

Boolean true.

@USER

SYSTEM(19)

Account name.

@USER.NO

SYSTEM(18)

Port number.

@USERNO

SYSTEM(18)

Port number.

@VM

CHAR(253)

Value mark.

@WHO

SYSTEM(19)

Account name.

Note

The symbol @SM represents a subvalue mark, not a segment mark. This is for compatibility with other MultiValue systems.

Variables

A variable is a named data location which is assigned a value. The value assigned to the variable may change throughout the execution of the program. Over 1,000,000 variables can be defined in a program or subroutine (the number is dependent on the available workspace).

Variables can hold the following types of data: numbers, strings, dimensioned and dynamic arrays, references to open files (file variables), references to open connections (session handles), and references to select lists and indexes (list variables).

Arrays

An array is a multi-element variable that provides a set of locations, each capable of storing a different data value. DataBasic provides two types of array: dimensioned arrays, which must be declared before use with the DIMENSION statement; and dynamic arrays, which are string variables, divided into elements by special characters.

For more details, see Introducing Arrays.

COMMON Variables

Variables used within your program are normally local to the program module. To share data between program modules, you can use common variables and arrays, declared with the COMMON statement. Using common variables in main programs and external subroutines is more efficient than passing values in argument lists.

The names used for common variables are local to the module (program or subroutine) that declares them. The same common variables can be referred to by different names in different modules. However, this is not recommended - it is best to place common variable declarations in an item that is included in every module (using the INCLUDE statement).

Common variables are stored in local or named COMMON sections. Each DataBasic program has a local common section that is shared between just the program and its subroutines - if you run another program (for instance, with the PERFORM statement), local common variables are not available to the new program. Named common sections, once initiated, persist for the duration of a logon session and are accessible to other programs, including those run with the PERFORM statement, Embedded Basic subroutines and RealWeb subroutines.