Was this helpful?
Variable Usage
BASIC variables declared to EQUEL can substitute for most elements of EQUEL statements that are not keywords. Of course, the variable and its data type must make sense in the context of the element. To use a BASIC variable in an EQUEL statement, just use its name. To refer to an element, such as a database column, with the same name as a variable, dereference the element with the EQUEL dereferencing indicator (#). As an example of variable usage, the following retrieve statement uses the variables "namevar" and "numvar" to receive data, and the variable "idnovar" as an expression in the where clause:
##   retrieve (namevar = e.name, numvar = e.num)
##             where e.idno = idnovar;
You must verify that the statement using the variable is in the scope of the variable's declaration. Various rules and restrictions apply to the use of BASIC variables in EQUEL statements. The sections below describe the usage syntax of different categories of variables and provide examples of such use.
Simple Variables
A simple scalar-valued variable (integer, floating-point or character string) is referred to by the syntax:
simplename
Syntax Notes:
1. If the variable is used to send data to Ingres, it can be a scalar-valued variable or constant.
2. If the variable is used to receive data from Ingres, it cannot be a variable declared as a constant.
3. The reference to an uninitialized BASIC dynamic string variable in an embedded statement that assigns the value of that string to Ingres results in a runtime error because an uninitialized dynamic string points at a zero address. This restriction does not apply to the retrieval of data into an uninitialized dynamic string variable.
The following program fragment demonstrates a typical message-handling routine that uses two scalar-valued variables, "buffer" and "seconds":
##   sub Msg (string buffer, integer seconds)
##        message buffer
##        sleep seconds
##   end sub
Array Variables
An array variable is referred to by the syntax:
arrayname(subscript{,subscript})
Syntax Notes:
1. The variable must be subscripted, because only scalar-valued elements (integers, floating-point and character strings) are legal EQUEL values.
2. When the array is declared, the array bounds specification is not parsed by the EQUEL preprocessor. Consequently, illegal bounds values will be accepted. Also, when an array is referenced, the subscript is not parsed, allowing illegal subscripts to be used. The preprocessor only confirms that an array subscript is used for an array variable. You must make sure that the subscript is legal and that the correct number of indices are used.
Record Components
The syntax EQUEL uses to refer to a record component is the same as in BASIC:
record::component{::component}
Syntax Notes:
1. The last record component denoted by the above reference must be a scalar value (integer, floating-point or character string). There can be any combination of arrays and records, but the last object referenced must be a scalar value. Thus, all the following references are legal:
! Assume correct declarations for "employee", "person"
! and other records.
    employee::sal                ! Component of a record
    person(3)::pname             ! Component of an element of an array
    rec1::mem1::mem2::age        ! Deeply nested componentAll record components must be fully qualified when referenced. Elliptical references, such as references that omit group names, are not allowed.
The example below uses the array of records "emprec" to load values into the tablefield "emptable" in form "empform."
##     record Employee_Rec
##                    string      ename = 20
##                    word     eage
##                    integer      eidno
##                    string      ehired = 25
##                    string      edept = 10
##                       real      esalary
##     end record

##     declare Employee_Rec emprec(100)
     declare integer i

     . . .

     for i = 1 to 100
##               loadtable empform emptable
##          (ename = emprec(i)::ename, 
##           eage = emprec(i)::eage, eidno = emprec(i)::eidno,
##           ehired = emprec(i)::ehired,
##           edept = emprec(i)::edept, 
##           esalary = emprec(i)::esalary)
     next i
Using Indicator Variables
The syntax for referring to an indicator variable is the same as for a simple variable, except that an indicator variable is always associated with a host variable:
host_variable:indicator_variable
Syntax Note:
The indicator variable can be a simple variable, an array element or a record member that yields a 2-byte integer (the word subtype). For example:
declare word ind_var, ind_arr(5)
var_1:ind_var
var_2:ind_arr(2)
Last modified date: 08/28/2024