EXECUTE PREPARED

Use the EXECUTE PREPARED command to execute SELECT, UPDATE, INSERT or DELETE statements.

Use the SET PARAMETER(*LIST) command to pass a working list of bind values to the prepared statement. The prepared (UPDATE, INSERT or DELETE) statement is executed for each record in the working list.

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

If a prepared SQL statement starts with INSERT and ends with VALUES(*CALC) or VALUES(*ALL) then special parsing of the SQL statement is done. The *CALC option means that a binding parameter for column is calculated and the statement is modified. The *ALL option means that a binding parameter for each column is calculated and all other columns in the table are included using a default value.

Syntax:

Command

Keyword

Value

Developer notes

EXECUTE

PREPARED

statement

Required. Execute SELECT, UPDATE, INSERT or DELETE statement.

*SQLPARAMETER

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

 

Example

SET PARAMETER(*SQL) #WRKLST(TXT)

SET PARAMETER(*LIST) #WRKLST(column,column,column)

EXECUTE PREPARED(*SQLPARAMETER)

GET OBJECT(*PARAMETERLISTROW)

 

SET PARAMETER(*LIST) #WRKLST(NAME,ID)

EXECUTE PREPARED(UPDATE EMPLOYEE SET NAME=? WHERE ID=?)

GET OBJECT(*PARAMETERLISTROW)

 

SET PARAMETER(*LIST) #WRKLST(ID)

EXECUTE PREPARED(DELETE FROM EMPLOYEE WHERE ID=?)

GET OBJECT(*PARAMETERLISTROW)

 

SET PARAMETER(*LIST) #WRKLST(ID,NAME,AGE)

EXECUTE PREPARED("INSERT INTO EMPLOYEE(ID,NAME,AGE) VALUES(?,?,?)")

GET OBJECT(*PARAMETERLISTROW)

 

SET PARAMETER(*LIST) #WRKLST(ID,NAME,AGE)

EXECUTE PREPARED("INSERT INTO EMPLOYEE(ID,NAME,AGE) VALUES(*CALC)")

GET OBJECT(*PARAMETERLISTROW)

 

SET PARAMETER(*LIST) #WRKLST(ID,NAME,AGE)

EXECUTE PREPARED("INSERT INTO EMPLOYEE(ID,NAME,AGE) VALUES(*ALL)")

GET OBJECT(*PARAMETERLISTROW)