Was this helpful?
Examples of the Using Clause
The following examples show the use of the using clause and the getoper function. Read your host language companion guide for information about how to modify and or place values in the SQLDA.
This example demonstrates the use of the SQLDA to insert data into a form. It is the dynamic equivalent of the statement:
exec frs putform :form_var (age = :i4_var,
  comment = :c100_var:indicator_var);
Example:
exec sql include sqlda;
 declare the constants "int=30" and "char=20"
/* Assume that form has no more than 10 fields */
allocate an SQLDA with 10 elements;
 sqlda.sqln = 10; /* Number of allocated vars */
sqlda.sqld = 2; /* Number of vars used */
/* 4-byte integer to put into field "age" */
sqlda.sqlvar(1).sqltype = int;
sqlda.sqlvar(1).sqllen = 4;
sqlda.sqlvar(1).sqldata = address(i4_var);
sqlda.sqlvar(1).sqlind = null;
sqlda.sqlvar(1).sqlname = 'age';
 /* 100-byte nullable character 
** to put into field "comment"
*/
sqlda.sqlvar(2).sqltype = -char;
sqlda.sqlvar(2).sqllen = 100;
sqlda.sqlvar(2).sqldata = address(c100_var);
sqlda.sqlvar(2).sqlind = address(indicator_var);
sqlda.sqlvar(2).sqlname = 'comment';
 i4_var = 1234;
c100_var = 'This is a comment.';
null_indicator = 0;               /* Not null */
exec frs putform :form_var using descriptor sqlda;
This second example demonstrates a simple routine that displays a form, gets values, performs calculations on the values and puts them back into the form. The form is dynamically specified. This example assumes that there are no table fields on the form.
exec sql include sqlda;
 exec frs prompt ('Enter form name:', :form_var);
exec frs forminit :form_var;
 allocate an sqlda;
 exec frs describe form :form_var into sqlda;
 /* Allocate variables, retaining field names */
allocate_result_variables(sqlda);
 exec frs display :form_var;
 exec frs activate menuitem 'Calc';
exec frs begin;
     exec frs validate;
     exec frs getform :form_var using descriptor sqlda;
     perform_calculations(sqlda);
     exec frs putform :form_var using descriptor sqlda;
exec frs end;
 exec frs activate menuitem 'End';
exec frs begin;
     exec frs breakdisplay;
exec frs end;
 exec frs finalize;
This third example demonstrates the modification of the sqlname field to include the getoper function to retrieve the query operator of a field displayed in query mode. The fragment shown here assumes that the SQLDA has been included and allocated in the program. This example corresponds to the following hard-coded statement:
exec frs getform :form_var (:op_var = getoper(sal),
   :f8_var:indicator_var = sal);
...
Example:
/* 4-byte integer query operator of field "sal" */
sqlda.sqlvar(1).sqltype = int;
sqlda.sqlvar(1).sqllen = 4;
sqlda.sqlvar(1).sqldata = address(op_var);
sqlda.sqlvar(1).sqlind = null;
sqlda.sqlvar(1).sqlname = 'getoper(sal)';
 /* 8-byte nullable floating-point from "sal" */
sqlda.sqlvar(2).sqltype = -float;
sqlda.sqlvar(2).sqllen = 8;
sqlda.sqlvar(2).sqldata = address(f8_var);
sqlda.sqlvar(2).sqlind = address(indicator_var);
sqlda.sqlvar(2).sqlname = 'sal';
 exec frs getform :form_var using descriptor sqlda;
Last modified date: 11/28/2023