× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Rob

I do code my SQL programs this way (embedding SQL functions is
sub-procedures).  I was just thinking the technique would be useful in
WDSC if I ever ran across a monstrosity written by someone else.  :)

Bob

-----Original Message-----
Sent: Monday, July 18, 2005 1:55 PM
To: RPG programming on the AS400 / iSeries

I am sure you could.  However why not just do something like:


     ...
     D InitSql         PR
     D DeclareC1       PR                  like(sqlstt)
     D OpenC1          PR                  like(sqlstt)
     D FetchC1         PR                  like(sqlstt)
     D CloseC1         PR                  like(sqlstt)
     D ErrorHandler    PR
     D  Procedure                    10a   const
     D SRCPFUNLCK      PI                        *ENTRY PLIST
     D SourceFile      ds                  qualified
     D  File                         10a
     D  Library                      10a
     D  LockState                     7a   inz('*EXCL')
      /UNDEFINE DSpec

      /free
       InitSql();
       Select;
       When DeclareC1()<>*all'0';
         ErrorHandler('DeclareC1');
       When OpenC1()<>*all'0';
         ErrorHandler('OpenC1');
       Other;
         Dow FetchC1()=*all'0';
           callp LockFile(SourceFile.File:SourceFile.Library:
                          SourceFile.LockState);
         EndDo;
         Select;
         When SqlStt='02000';
           // End of cursor (normally).  Ok.
         Other;
           ErrorHandler('FetchC1');
         EndSl;
         CloseC1();
       EndSl;
       *inlr=*on;
       return;
      /end-free



      /eject
     P InitSql         B
     D InitSql         PI
      /free
       // Traditionally SqlStt and SqlCod are not set by 'Set Option'
       // or 'Declare cursor' statements
       SqlStt=*all'0';  // Initially comes in as all blanks
       SqlCod=*zeros;  // Initially set to some ridiculously high
number. 
It's
                       // a conversion of blanks to a binary number
thing.
      /end-free
     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
      /free
       return;
      /end-free
     P InitSql         E


      /eject
     P DeclareC1       B
     D DeclareC1       PI                  like(sqlstt)
     C/EXEC SQL
     C+ Declare C1 Cursor for
     C+ Select SYSTEM_TABLE_SCHEMA, SYSTEM_TABLE_NAME
     C+ From QSYS2/SysTables
     C+ Where file_type='S'
     C+ Order by SYSTEM_TABLE_SCHEMA, SYSTEM_TABLE_NAME
     C/END-EXEC
      /free
       // Using sqlstt as a return value on a Declare Cursor is rather 
silly
       // since Declare does not set it.  And that's why I had to add
the 
       // SqlStt=*all'0' in my InitSql procedure.  Otherwise it was
coming 
up blanks.
       return sqlstt;
      /end-free
     P DeclareC1       E



...


Rob Berendt

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.