Manipulating SQL Data

If you want to execute an SELECT, UPDATE, INSERT, or DELETE statement you must use an EXECSQL PREPARE, EXECUTE, or EXECUTE IMMEDIATE statement.

For example:

SQLSTMT= ,
'SELECT FIRSTNME, MIDINIT, LASTNAME' ,
'  FROM EMP WHERE EMPNO >= ? WITH UR'

ADDRESS DSNREXX "EXECSQL PREPARE S1 FROM :SQLSTMT" 

IF SQLCODE \= "0" THEN DO
    SAY "PREPARE  FAILED "
    CALL DBERROR
END 

ADDRESS DSNREXX "EXECSQL DECLARE C1 CURSOR FOR S1"
HVEMPNO = '000200'   
ADDRESS DSNREXX "EXECSQL OPEN C1 USING :HVEMPNO"

IF SQLCODE \= "0" THEN DO
    SAY "OPEN FAILED "
    CALL DBERROR
END

 ADDRESS DSNREXX
       "EXECSQL FETCH C1 INTO :HV1, :HV2 :IV2,  :HV3"
  
  If SQLCODE = 0 Then Do  
      SAY "FETCH =  " HV1 " " IV2 " " HV3
     END
ADDRESS DSNREXX "EXECSQL CLOSE C1"