Re: Help with RPGLE SQL FETCH NEXT

Daniel Gross <[email protected]> Tue, 10 Feb 2026 15:35:04 +0100
Newsgroups gmane.comp.lang.as400.rpg
Message-ID <[email protected]>
Hi Gio,

with only that much code, I can only give some ideas. 

a) is there an ORDER BY clause? If not, every execution of the statement can generate an other sequences of rows. 

b) is the cursor open during calls? And is the cursor INSENSITIVE? If not, new rows can show up in the next fetch, disturbing the sequence you might assume. 

c) OFFSET is generally a bad idea for pagination 
  -> https://use-the-index-luke.com/no-offset

Can you send the whole SQL statement and especially the cursor definition?

HTH 
Daniel


> Am 10.02.2026 um 15:25 schrieb gio.cot via RPG400-L <[email protected]>:
> 
> Hi all
> 
> I have a problem with a Web Service,  invoked via server windows to display
> a item inventory grid. I try to explain: the RPGLE SQL program that return a
> Json file, is setted for return 60 rows for time ; in RPGLE we have coded :
> 
> ' OFFSET  ( ' + %char(PagNum) + ' - 1) * 60  ROWS '
> 
>                     ' FETCH NEXT 60 ROWS ONLY '               
> 
>                    ' with NC '
> 
>                    ' FOR READ ONLY ';   
> 
> it happeds that after the fetch from the cursor , the RPGLE program, for
> some required rules , skip some row, and so the Json file doesn.'t contains
> 60 rows but 51 or 52 .. etc etc.
> 
> my questioni s : how can force (if its possible) the fetch cycle to fill the
> json file with the 60 rows, also if i need to read from my cursor more than
> 60 rows ??
> 
> 
> 
> I hope my explanation was clear
> 
> Thanks in advance
> 
> Gio
> 
> --
> This is the RPG programming on IBM i (RPG400-L) mailing list
> To post a message email: [email protected]
> To subscribe, unsubscribe, or change list options,
> visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
> or email: [email protected]
> Before posting, please take a moment to review the archives
> at https://archive.midrange.com/rpg400-l.
> 
> Please contact [email protected] for any subscription related questions.
> 
-- 
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: [email protected]
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: [email protected]
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact [email protected] for any subscription related questions.