Active3 years, 1 month ago
When working with embedded SQL in RPG, you often end up with a cursor and a
dow
-loop for processing all rows in your result. The condition in the loop is somehow dependent on SQLCOD
and/or SQLSTT
, some globally available variables in an SQLRPGLE-program?Here 1st parameter is the source string from which we want to extract some part of string. 2nd parameter is the starting position from where we will start the extraction of string. 3rd parameter is the length to extract. Example -%SUBST Built-In Functions in rpgle. Below example extract year, month, day etc. From the timestamp. ILE RPG now supports “fully-free” RPG, which allows RPG code anywhere on a source line, from column 1 to the end of the line. The first line of any source file that contains fully-free code must contain the special.FREE directive in column 1 of the first source line.FREE cannot be coded anywhere but the first line.
But what is the correct way of checking these values? Some suggest
SQLCOD = 0
others not (SQLCOD = +100 or SQLSTT = '02000')
. One fails on all warnings, the other does not fail on some errors, so I'm not content.To illustrate what I do with some code:
I'm looking for the correct return statement here, that will make me go through all rows if no error occurs and lets me leave when an error occurs. Bonus points for some decent way to check for errors.
Free Format Rpg Examples
kratenkokratenko5,51944 gold badges3030 silver badges5252 bronze badges
3 Answers
SQLSTATE is better, and recommended by IBM.
From IBM's InfoCenter SQL Messages and Codes Reference: SQLCODE and SQLSTATE concepts
SQLSTATE is the preferred standard return code.
SQLSTATE is 5 characters, with the first two bytes identifying a class of conditions.
- '00' = Unqualified Successful Completion
- '01' = Warning
- '02' = No Data
Anything else is an error. Walkie talkie software. I generally only check for '00'.
Simple. Easy. More portable.
Using SQLCODE often involves lists of codes which are, IMHO, less than developer friendly.
Example:
Personally, I generally include definitions and code like this:
Then after any SQL operation, I generally check
WarrenTWarrenT
The best practice is to process the SQLCODEs you expect (as part of the expected processing) and to add exception code to handle the ones you don't. One implementation:
With this type of implementation you have to intentionally leave the loop; whether you've filled a subfile page, loaded the highest element in an array or hit an error. I'm not sure there is a single, generic implementation that will handle all circumstances. Sometimes you might want to leave the read loop if you have a record lock and sometimes you want to issue a message and try again (for example).
The goal of the Time Trial mode is to make as much money as possible; a 5% of the total money earned will be transformed into shells. Insaniquarium deluxe free full download. Each piece cost doubles the previous one, with the first shell starting at $100.
Buck CalabroBuck Calabro
I did some more searching on the topic and found something on IBM's site (quote):
Which would lead me to an
sql_found()
like this:That should take care of the End of Data condition and fail on all errors. I'm not sure if there are some warnings that I should take care of (don't want to get trapped in an endless loop, if there is a warning that leads to not reading).
kratenkokratenko5,51944 gold badges3030 silver badges5252 bronze badges