H ActGrp(*CALLER) H DftActGrp(*NO) D OpenCursor PR n D FetchCursor PR n D CloseCursor PR n D MyAry e ds extname(iim) dim(10) qualified D rows s 5i 0 inz(%elem(MyAry)) D RowsRetrieved s 5i 0 D SqlErr5LastRow C Const( 100 ) /free *inlr=*on; if not OpenCursor(); // perform error routine to alert the troops // ... Else; Dow FetchCursor(); // putting the fetchcursor on the do loop allows the user of // iter, and thus iter will not perform an infinite loop // normal processing here... EndDo; CloseCursor(); EndIf; return; /end-free P OpenCursor B D OpenCursor PI like(ReturnVar) D ReturnVar s n C/EXEC SQL C+ Set Option C+ Naming = *Sys, C+ Commit = *None, C+ UsrPrf = *User, C+ DynUsrPrf = *User, C+ Datfmt = *iso, C+ CloSqlCsr = *EndMod C/END-EXEC C/EXEC SQL C+ Declare C1 cursor for C+ Select * C+ from iim C+ for fetch only C/END-EXEC C/EXEC SQL C+ Open C1 C/END-EXEC /free Select; When SqlStt='00000'; return *on; Other; return *off; EndSl; /end-free P OpenCursor E /eject P FetchCursor B D FetchCursor PI like(ReturnVar) D ReturnVar s n C/EXEC SQL C+ Fetch Next C+ From C1 C+ For :rows Rows C+ into :MyAry C/END-EXEC /free Select; When sqlstt='00000'; // row was received, normal // Was last row received? If SqlErrD( 5 ) = SqlErr5LastRow; dsply 'End'; ENDIF; ReturnVar=*on; When sqlstt='02000'; // same as %eof, sooner or later this is normal If SqlErrD( 5 ) = SqlErr5LastRow; dsply 'End2'; ENDIF; ReturnVar=*off; Other; // alert the troops! ReturnVar=*off; EndSl; // Number of rows Retrieved RowsRetrieved = SqlErrD( 3 ); return ReturnVar; /end-free P FetchCursor E /eject P CloseCursor B D CloseCursor PI like(ReturnVar) D ReturnVar s n C/EXEC SQL C+ Close C1 C/END-EXEC /free Select; When sqlstt='00000'; // cursor was closed, normal ReturnVar=*on; Other; // alert the troops! ReturnVar=*off; EndSl; return ReturnVar; /end-free P CloseCursor E