Return to the SQL Tips
Subfile page up & down using embedded SQL
Message from Karen L Hodge/MIS/Genesyson Wed, 13 Oct 2004 13:39:47 -0400 ----- To: rpg400-l@midrange.com Subject: Re: subfile page up & down using embedded SQL FETCH statement positioning keywords: Keyword Positions cursor Next On the next row after the current row Prior On the row before the current row First On the first row Last On the last row Before Before the first row (used to reset the cursor position to the beginning without retrieving any data) After After the last row (used to reset the cursor position to the end) Current On the current row (no change in position) Relative n n < -1 positions to nth row before current N = -1 Same as Prior keyword N = 0 Same as Current keyword N = 1 Same as Next keyword N > 1 Positions to nth row after current "no row" condition on a Fetch : SQLState = '02000') Note: Changing the value of a host variable has no effect on the cursor until the cursor is closed and reopened. By closing & reopening a curson, you can use the same cursor to retrieve different sets of rows in the same program execution. Basic logic for sequentially processing all rows of an SQL cursor: Open cursor If error Handle error Quite Endif While more rows and no error Fetch next row If normal return condition Process current row Else if 'no row' condition Do nothing(end lood) Else if other warning condition Handle warning(continue or end loop) Else Handle error(end loop) Endif Endwhile Close cursor If error Handle error endif Roll back example: FETCH RELATIVE -20 FROM MYCSR INTO :empiem
[report a broken link by clicking here]