On my System Power / AS400, i'm using embedded sql in an RPGLE Program to write a Subfile. On a large selection the initial fetch is to slow. When i scroll the speed is good. Even though i only select 19 rows and fetch 1 row at a time.
Why ?
sqlCmd =
' select ...
offset ? rows +
fetch first '+%CHAR(maxRecnum +1)+' rows only +
) as fuse +
order by rownumber asc +
';
exec sql PREPARE S1 FROM :sqlCMD;
exec sql DECLARE getS1 scroll CURSOR FOR S1;
exec sql OPEN getS1 USING :xy;
OU SQLCODE <> 0 or Recnum1 > maxRecnum +1;
exec sql
fetch getS1
into
:rownumberH
,:Spalte1 :NullIDx_SyvWerte
,:Spalte2 :NullIDx_SyvWerte
,:Spalte3 :NULLIDXW
,:Spalte5 :NullIDx_SyvWerte
,:Spalte6 :NullIDx_SyvWerte
,:Spalte7 :NullIDx_SyvWerte
,:Spalte8 :NullIDx_SyvWerte
,:Spalte9 :NullIDx_SyvWerte
,:Spalte10 :NullIDx_SyvWerte
,:Spalte11 :NullIDx_SyvWerte
,:KYH :NullIDx_SyvWerte
,:FUNKTH :NullIDx_SyvWerte
,:WERTH :NULLIDXH
,:UntermenueKY :NullIDx_SyvWerte
,:KYALTH :NullIDx_SyvWerte
,:SpalteK :NullIDx_SyvWerte
,:MASKH :NullIDx_SyvWerte
,:POSH :NullIDx_SyvWerte
,:WertLaengH :NullIDx_SyvWerte
,:Menu :NullIDx_SyvWerte
,:sMenuLastChgDate :NullIDx_SyvWerte
,:sMenuLastChgTime :NullIDx_SyvWerte
,:sMenuLastCrtDate :NullIDx_SyvWerte
,:sMenuLastCrtTime :NullIDx_SyvWerte
,:WertVergleich :nullIDxWert
,:VarianteAusgelaufen :NullIDx_SyvWerte
,:DatAus
,:id_YSYVH :NullIDx_SyvWerte
,:SbH :NullIDx_SyvWerte
,:LgH :NullIDx_SyvWerte
;
If sqlcode <> 0 or Recnum1 > maxRecnum;
leave;
ENDIF;
Edit: After the first 19 rows are shown. The Cursor is closed again. Then when you scroll the Cursor is opened again. So it seems like the Problem is with the Fetch.
order by rownumber asc-- How is thisrownumbercomputed? Seems like the logic may not be trivial for the engine to process.