5. Embedded QUEL for Ada : Ada Variables and Data Types : Variable Usage : Simple Variables
 
Share this page                  
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 any scalar-valued variable, constant or enumerated literal.
2. If the variable is used to receive data from Ingres, it cannot be a variable declared with the constant clause, a formal parameter that does not specify the outmode, a number declaration, or an enumerated literal.
3. A string variable (a 1-dimensional array of characters) is referenced as a simple variable.
The following program fragment demonstrates a typical message-handling routine that uses two scalar-valued variables, "buffer" and "seconds":
## procedure Msg (buffer: String; seconds: Integer) is
## begin
## message buffer
## sleep seconds
## end Msg;
A special case of a scalar type is the enumerated type. The preprocessor treats all enumerated literals and any variables declared with an enumerated type as integers. When an enumerated literal is used in an EQUEL statement, only the ordinal position of the value in relation to the original enumerated list is relevant. When assigning from an enumerated literal, the preprocessor generates the following:
enumerated_type_name'pos(enumerated_literal)
When assigning from or into an enumerated variable, the preprocessor passes the object by address and assumes that the value being assigned from or into the variable will not raise a runtime constraint error. In order to relax the restriction imposed by the preprocessor on enumerated literal assignments (of enumerated types that have included representation clauses to modify their values), you should assign the literal to a variable of the same enumerated type before using it in an embedded statement. For example, the following enumerated type declares the states of a table field row, and the variable of that type will always receive one of those values:
## type Table_Field_States is
## (UNDEFINED, NEWROW, UNCHANGED, CHANGED, DELETED);
## tbstate: Table_Field_States := UNDEFINED;
## ename: String(1..20);
...

## getrow empform employee 
##    (ename = name, tbstate = _state);

case tbstate is
    when UNDEFINED =>
    ...

end case;
Another example retrieves the value TRUE (an enumerated literal of type boolean) into a variable when a database qualification is successful:
## found: Boolean;
## qual: String(1..100);
..

## retrieve (found = TRUE) where qual;

if (not found) then 
...

end if;