LppEdd
LppEdd

Reputation: 21134

RPG embedded SQL - Fetching and updating rows

I want to fecth rows and update them in RPG (free). Using old style opcodes I'd do that:

READE %KDS(KEY) FILE;
processRecord();
UPDATE FILE;

Problems come with SQL opcodes:

EXEC SQL FETCH MYCURSOR INTO :VAR;
processRecord();
????

Using EXEC SQL UPDATE FILE... SET... WHERE KEY... return an SQLCOD error.
Is there a particular technique?

Upvotes: 0

Views: 1013

Answers (1)

LppEdd
LppEdd

Reputation: 21134

By reading "Programming in RPG IV", I found an answer.

EXEC SQL DECLARE MYCURSOR CURSOR FOR *SELECT STATEMENT* FOR UPDATE OF *FIELDS*;
EXEC SQL OPEN MYCURSOR;
EXEC SQL FETCH MYCURSOS INTO :VARIABLE;
EXEC SQL UPDATE FILE SET *FIELDS* WHERE CURRENT OF MYCURSOR;
EXEC SQL CLOSE MYCURSOR;

That's it, pretty straightforward!

Upvotes: 5

Related Questions