/Copy #SQLCLI
/Copy #SQLCLIX
d Handles ds
d EnvHandle 10I 0
d ConHandle 10I 0
d StmtHandle 10I 0
d pHandles s * Inz(%addr(Handles))
d SQLStmt s 256a
d SQLStmtLen s 10I 0
d #SQLStmBeg c Const('SELECT * FROM UCG.CUSTMAST ')
d CustMastR e ds ExtName(CUSTMAST)
d CustNumber s 10
d SQLRC s 10i 0
d ActDtaLen s 10i 0
* Set clean-up procedure
c CallB 'CEERTX'
c Parm pSQLCleanu
c Parm pHandles
c Parm *Omit
* Call SQLSetup to initialize everything.
c Eval SQLRC = SQLSetup(pHandles)
c CallP ChkSQLRC('SQLSetup': SQLRC)
* Build statement and execute. Select all customers whose
* last name contains 'BER'.
c eval SQLStmt = #SQLStmBeg +
c 'WHERE CSTLNM LIKE ''%BER%'''
c ' ' CheckR SQLStmt SQLStmtLen
c Eval SQLRC =
c SQLExecDir(StmtHandle: SQLStmt: SQLStmtLen)
c CallP ChkSQLRC('ExecDir': SQLRC)
* Bind customer number field (CSTNBR) to column 1 of result table.
* Note, CSTNBR is a 7.0 packed field.
c Eval SQLRC =
c SQLBindCol(StmtHandle: 1: #SQLDec:
c %addr(CSTNBR):
c (%len(CSTNBR) * 256) +
c %decpos(CSTNBR):
c %addr(ActDtaLen))
c CallP ChkSQLRC('BindCol': SQLRC)
* Bind last name field (CSTLNM) to column 2 of result table.
c Eval SQLRC =
c SQLBindCol(StmtHandle: 2: #SQLChar:
c %addr(CSTLNM): %size(CSTLNM):
c %addr(ActDtaLen))
c CallP ChkSQLRC('BindCol': SQLRC)
* Bind first name field (CSTFNM) to column 3 of result table.
c Eval SQLRC =
c SQLBindCol(StmtHandle: 3: #SQLChar:
c %addr(CSTFNM): %size(CSTFNM):
c %addr(ActDtaLen))
c CallP ChkSQLRC('BindCol': SQLRC)
* Do a "fetch-loop" to fetch all the matching records from
* the result table.
c DoU SQLRC <> #SQLOK or CSTLNM = 'q'
c Eval SQLRC = SQLFetch(StmtHandle)
c CallP ChkSQLRC('Fetch': SQLRC)
c CSTNBR Dsply
c CSTFNM Dsply CSTLNM
c EndDo
* Call SQLCleanup to deallocate resources
c CallP SQLCleanup(pHandles)
c MoveL '1' *INLR
c Return