


Dynamic SQL statements can be parameterized with host variables; e.g., the values of the INSERT statement are to be entered at the terminal.
For dynamic execution of parameterized SQL statements, the ADABAS precompiler offers a procedure which consists of two steps:
- Preparation of the SQL statement to be executed dynamically by means of the PREPARE statement. In this phase, it will be stipulated how many host variables are to be inserted at which positions within the SQL statement. The positions intended for the host variables are identified by a '?'.
- Execution of the prepared SQL statement by means of the EXECUTE statement. The SQL statement to be executed will be identified by a name which has been given to it during the preparation. In this phase, the statement receives the actual host variable values. Host variables are assigned to the position indicators one to one. Once prepared, an SQL statement can be executed with EXECUTE as often as desired, whereby the host variables may vary for every specification.
Example:

The following example shows how a result table can be processed by means of a cursor. The first step is to prepare the SELECT statement. The second step is to open the result table whereby host variables are assigned to the position indicators. For this reason, the SELECT statement can only be executed at this point in time. The FETCH statement is also executed dynamically according to the procedure described above.
Example:



