INTO Clause

As indicated above, host variables are used to store the result of an SQL query. The resulting value is put INTO the variable.

Syntax

SELECT database-field(s)
INTO :host-variable

where

database-field(s) is one or more variables defined in Working-Storage.

host-variable is the name of a COBOL variable.

Example

The select1.sqb program contains the following code:

EXEC SQL
   SELECT
       C_FIRST_NAME, C_LAST_NAME,
       C_BIRTHDAY, C_INFO
   INTO 
       :C-FIRST-NAME, :C-LAST-NAME, :C-BIRTHDAY, :C-INFO
   FROM CUSTOMER
       ...
END-EXEC.

This series of statements instructs the program to place the values for these fields INTO the corresponding COBOL variables, which are C-FIRST-NAME, C-LAST-NAME, etc., so that COBOL statements can refer to them. The semicolon in the code indicates that these are COBOL (host) variables.

Note: In this example, there is a one-to-one match between variables declared in Working-Storage and the columns in the table. The program select2.sqb provides an example where the values to INTO a group item rather than individual fields.