midrange.com code scratchpad
Name:
SQL template
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
08/28/2008 05:59:36 pm
IP:
Logged
Description:
The user was to lazy to give a description
Code:
  1.      H ActGrp(*CALLER)
  2.      H DftActGrp(*NO)
  3.  
  4.      D OpenCursor      PR              n
  5.      D FetchCursor     PR              n
  6.      D CloseCursor     PR              n
  7.  
  8.      D MyLib           s             10a
  9.      D MyFile          s             10a
  10.  
  11.       /free
  12.        *inlr=*on;
  13.        if not OpenCursor();
  14.          // perform error routine to alert the troops
  15.          // ...
  16.        Else;
  17.          Dow FetchCursor();
  18.            // putting the fetchcursor on the do loop allows the user of
  19.            // iter, and thus iter will not perform an infinite loop
  20.            // normal processing here...
  21.          EndDo;
  22.          CloseCursor();
  23.        EndIf;
  24.        return;
  25.       /end-free
  26.  
  27.      P OpenCursor      B
  28.      D OpenCursor      PI                  like(ReturnVar)
  29.      D ReturnVar       s               n
  30.  
  31.      C/EXEC SQL
  32.      C+ Set Option
  33.      C+     Naming    = *Sys,
  34.      C+     Commit    = *None,
  35.      C+     UsrPrf    = *User,
  36.      C+     DynUsrPrf = *User,
  37.      C+     Datfmt    = *iso,
  38.      C+     CloSqlCsr = *EndMod
  39.      C/END-EXEC
  40.  
  41.      C/EXEC SQL
  42.      C+ Declare C1 cursor for
  43.      C+  Select System_Table_Schema as library,
  44.      C+         System_Table_Name   as file
  45.      C+  from qsys2/systables
  46.      C/END-EXEC
  47.  
  48.      C/EXEC SQL
  49.      C+ Open C1
  50.      C/END-EXEC
  51.  
  52.       /free
  53.        Select;
  54.          When SqlStt='00000';
  55.            return *on;
  56.          Other;
  57.            return *off;
  58.        EndSl;
  59.       /end-free
  60.      P OpenCursor      E
  61.  
  62.       /eject
  63.      P FetchCursor     B
  64.      D FetchCursor     PI                  like(ReturnVar)
  65.      D ReturnVar       s               n
  66.      C/EXEC SQL
  67.      C+ Fetch C1 into :MyLib, :MyFile
  68.      C/END-EXEC
  69.       /free
  70.        Select;
  71.          When sqlstt='00000';
  72.            // row was received, normal
  73.            ReturnVar=*on;
  74.          When sqlstt='02000';
  75.            // same as %eof, sooner or later this is normal
  76.            ReturnVar=*off;
  77.          Other;
  78.            // alert the troops!
  79.            ReturnVar=*off;
  80.        EndSl;
  81.        return ReturnVar;
  82.       /end-free
  83.      P FetchCursor     E
  84.  
  85.       /eject
  86.      P CloseCursor     B
  87.      D CloseCursor     PI                  like(ReturnVar)
  88.      D ReturnVar       s               n
  89.      C/EXEC SQL
  90.      C+ Close C1
  91.      C/END-EXEC
  92.       /free
  93.        Select;
  94.          When sqlstt='00000';
  95.            // cursor was closed, normal
  96.            ReturnVar=*on;
  97.          Other;
  98.            // alert the troops!
  99.            ReturnVar=*off;
  100.        EndSl;
  101.        return ReturnVar;
  102.       /end-free
  103.      P CloseCursor     E 
© 2004-2019 by midrange.com generated in 0.006s valid xhtml & css