Previous Topic: SELECT Statement—Request Data from a TableNext Topic: Description of Host Variables


The ADDRESS SQL Environment and Host Variables

Issued through ADDRESS SQL statements, SQL commands such as SELECT and FETCH create stem REXX variables. For example, suppose that you have this statement:

ADDRESS SQL
  "SELECT NAME FROM MYTABLE"

The statement shown above generates these stem REXX variables:

Using the ADDRESS SQL statement above, you could write the following REXX code to display the retrieved NAME column information on your terminal, or to display error messages if the SELECT statement fails:

ADDRESS SQL
"SELECT NAME FROM MYTABLE"
IF SQLCODE ¬= 0 THEN
  DO
    SAY "ADDRESS SQL HOST COMMAND RET CODE =" SQLCODE
    DO WHILE QUEUED() <> 0
      PULL MESSAGES
      SAY  MESSAGES
    END
    RETURN
  END
SAY "Number of Variables Created =" NAME.0
DO I = 1 TO NAME.0
  SAY NAME.I
END