4/21/2021 0 Comments Rpg Code Example
Imagine that you want to reduce the expiration date of all the items in warehouse 24s inventory by one day.Dont get me wrongIm not saying that you should change the way your programs interact with every single data interactionbut some of them could probably have their performance, readability, and reliability improved by SQL.SQL statements can be placed in detail calculations, in total calculations, and in RPG subroutines.
For instance, when you place an SQL statement inside an RPG IF statement, the SQL statement will be executed if the condition of the RPG IF statement is met. Both uppercase and lowercase letters are acceptable in SQL statements. The SQL statement may start in position 17 and continue through position 80. Whats really needed is the plus sign () in each line other than the EXEC SQL line. You can write the whole statement on the same line (assuming it fits between positions 17 and 80), but that will hamper readability and future maintainability of the code. Anyway, the code looks simple enough, doesnt it Well, youll see that its even simpler in free format. For embedded SQL statements, that means that you can do without the END SQL directive. You also know that a free-format statement can span multiple lines without any special indication. For SQL statements, this means no more plus sign in each line of the statement. Finally, you can simply write EXEC SQL as if it were an ordinary RPG operation code. The only requirement is that you write the words EXEC and SQL on the same line. Putting all of that together, heres the same simple SELECT in free format. Theres only one small flaw in these two examples: they dont actually work While in interactive SQL or the i Navigator, you have a way to see the output. In other words, you need something to get data in and out, thus allowing you to perform, for instance, surgical updates or deletes over massive amounts of data. The easiest way to establish this two-way communication is by using host variables. I didnt mention this before, but the SELECT SQL instruction has another optional clause, which only makes sense when youre using the instruction in a programming environment. Youre not simply querying the database with a SELECT statement; instead, the SELECT statement is part of a stored procedure or an embedded statement, like the case at hand. These variables must be compatible with the data types of the respective columns in the SELECT clause. In other words, if column1 is a string, then host-variable1 should, ideally, be a string. After this code is executed, WTotReg is going to hold the total number of records of table InvMst.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |