EXECUTE QUERY

If you want to run a SELECT query on a remote database and you are expecting a result set to be returned, then you would typically use the EXECUTE QUERY command.

The result set is read directly into the working list argument.

If no working list argument is used, then the Result Set is stored for later access by the READ command.

If you want to use a very large SELECT statement then you have the option of preparing the statement using the SET PARAMETER(*SQL) command, then using the EXECUTE QUERY(*SQLPARAMETER) command.

Syntax:

Command

Keyword

Value

Developer notes

EXECUTE

QUERY

statement

Required. Execute SELECT statement.

*SQLPARAMETER

Execute previously prepared SQL statement using the PARAMETER(*SQL) keyword on the SET command.

 

Example

SET PARAMETER(*SQL) #WRKLST(TXT)

EXECUTE QUERY(*SQLPARAMETER) #WRKLST(ID,NAME,AGE)

 

EXECUTE QUERY(SELECT EMPLOYEE_ID,EMPLOYEE_NAME,EMPLOYEE_AGE FROM EMPLOYEE) #WRKLST(ID,NAME,AGE)

 

EXECUTE QUERY(SELECT EMPLOYEE_ID,EMPLOYEE_NAME,EMPLOYEE_AGE FROM EMPLOYEE)

READ #WRKLST(ID,NAME,AGE)