Here a simple RPG program which declares an SQL query and retrieves the number of rows: // In our case, the information we need is DB2_NUMBER_ROWS which, after the OPEN of a cursor, holds the number of rows of the result set. Here the detailed documentation from IBM. The GET DIAGNOSTICS statement returns a lot of information about the last executed SQL statement. The count can be obtained by setting the result of a COUNT(*) in a variable against a statement with the same query as the cursor defined above.īut a more effective solution exists, and that saves us from writing two statements that are almost equal… To fetch the data, we need to define an SQL cursor and load all the fetched rows in a DS array, then managing the positioning page by page. Here we see how the total number of elements already appears, while the rows are displayed 10 at a time. Just think of applications built for the Web, where a list is shown in groups of elements and buttons allow jumping from one page to another, like this: Sometimes we may need to know in advance the number of records you are about to fetch from the database and show to the user. Last Updated on 14 October 2019 by Roberto De Pedrini
0 Comments
Leave a Reply. |