Preparing a Scroll Cursor
/free
   IF %parms >= 1 and orderby > *blanks                        ;
      OrderString = %trim(orderBy)                             ;
   ELSE                                                        ;
      OrderString = dftorder                                   ;
   ENDIF                                                       ;

   IF %parms > 1 and SelectOnly > *blanks                      ;
      SelectString = %trim(SelectOnly)                         ;
   ELSE                                                        ;
      SelectString = dftSelect                                 ;
   ENDIF                                                       ;

   QRYstring = %trim(SelectString) + ' ' + %trim(OrderString)  ;

   //  Declare the SQL cursor to hold the data
   //  Open the SQL cusror
   EXEC SQL PREPARE selStmt FROM :QRYstring                    ;
   EXEC SQL DECLARE XFCursor SCROLL CURSOR FOR selStmt         ;
   EXEC SQL OPEN XFCursor                                      ;
   IF SQLSTT = SQLSTTOK                                        ;
      erroroccurred = *OFF                                     ;
   ELSE                                                        ;
      erroroccurred = *ON                                      ;
   ENDIF                                                       ;
   RETURN erroroccurred                                        ;
/end-free