Friday, August 10, 2007

Embedded SQL - RPGIV/RPGLE - One more gotcha

One thing that got neglected on the earlier gotchas is an important one, it's about organizing your SQL statements.

Since adding SQL seems fairly straightforward, one might be tempted to miss one key thing, the order of the SQL statements is important.

The SQL commands are actually compiled prior to the program as a whole. The SQL pre-compiler works top to bottom. This means that your order must follow this pattern:

PREPARE - optional, but must be first if included
DECLARE
OPEN
FETCH
CLOSE

Get them out of order and even if the compile works, unexpected results will occur.

Searches leading to tojosan.com indicate a strong interest in more embedded SQL examples. There are a couple posts already on this site, here, and here.

Expect more SQL posts in the near future and thanks for visiting.
Drop me a line if there are specific things you are interested in seeing articles on.
tojosan - gmail.com

No comments: