Hallo dino,

ich hab ein Programm eingefügt, welches die Select-Kriterien
aus einem Query/400 - Objekt ausliest und in eine Outfile schreibt.
( funktioniert nur bis Systemwert QSECURITY <= 30 ).

Gruß
Michael
Code:
      * Author:
      *      Michael Steibert
      * Description:
      *      Auslesen Select-Kriterien aus Query/400-Objekt
      *       - erstelle Outfile in QTEMP (APPEND)
      *       - lese Query-Objekt (*QRYDFN) aus Parameterübergabe
      *       - Ausgabe Select-Kriterien
      * Compile it with:
     D*B      CRTSQLRPGI GETSELECT
     D*B+        COMMIT(*NONE)
     D*B+        OBJTYPE(*PGM)
     D*B+        DATFMT(*ISO)
     D*B+        DBGVIEW(*SOURCE)
     H BndDir('QC2LE') DftActGrp(*No) ActGrp(*Caller)
      * Entry Parm
     D getSelectCrit   PR                  extpgm('GETSELECT')
     D QueryLib                      10A   CONST
     D QueryName                     10A   CONST
      *
      * resolve System Pointer
     D rslvsp          Pr              *   ProcPtr  ExtProc( 'rslvsp' )
     D  ObjTyp                        2a   Value
     D  ObjNam                         *   Value  Options( *String )
     D  ObjLib                         *   Value  Options( *String )
     D  AutReq                        2a   Value
      *
      * set Space Pointer from Systempointer
     D setsppfp        Pr              *   ExtProc( 'setsppfp' )
     D   Object                        *   Value  ProcPtr
      *
      * set Spacepointer offset
     D setsppo         Pr              *   ExtProc( 'setsppo' )
     D   SpcPtr                        *   Value
     D   Offset                      10i 0 Value
      *
      *  copy memory from address to address
     D MemCpy          Pr              *   ExtProc( 'memcpy' )
     D  pOutMem                        *   Value
     D  pInpMem                        *   Value
     D  iMemSiz                      10u 0 Value
     **
     d createOutfile   pr
     d insertOutfile   pr
     **
     d getSelectCrit   pi
     D QueryLib                      10A   CONST
     D QueryName                     10A   CONST
     **
     ** object pointer
     D pQryObject      s               *   ProcPtr
     D pQryTemplate    s               *
     D QryTemplate     s          32767a   Based( pQryTemplate )
     **
     ** selection criteria
     D SelCriHeader    Ds                  inz qualified
     D  TotLen                       10i 0 Inz
     D                               10i 0 Inz
     D                               10i 0 Inz
     D                               10i 0 Inz
     D  NbrCri                        5i 0 Inz
     D SelCriDetail    Ds                  inz qualified
     D  Len                           5i 0 Inz
     D                               10i 0 Inz
     D                               10i 0 Inz
     D Operater                      10i 0 Inz
     D logicOperation                 1a   Overlay( Operater: 4 )
     D  Arg1                         14a
     D  CompOpr                       2a
     D  Arg2Lin                       5i 0 Inz
     D  Arg2Len                       5i 0 Inz
     D  Arg2Dta                    4096a
     **
     ** work variables
     d offset          s              5i 0
     D i               s             10i 0
     **
      /free
           createOutfile();
           pQryObject  =
            rslvsp( x'1911'
                  : %TrimR( QueryName )
                  : %TrimR( QueryLib  )
                  : x'0000'
                  );
           pQryTemplate = setsppfp( pQryObject );
           pQryTemplate  = setsppo( pQryTemplate: 94 ) ;
           MemCpy( %Addr( offset )
                 : pQryTemplate
                 : %Size( offset )
                 ) ;
           pQryTemplate  = setsppo( pQryTemplate: offset ) ;
           MemCpy( %Addr( SelCriHeader )
                 : pQryTemplate
                 : %Size( SelCriHeader )
                 ) ;
           offset  = offset + %Size( SelCriHeader ) ;
           for i = 1 to SelCriHeader.NbrCri  ;
              pQryTemplate  = setsppo( pQryTemplate: offset ) ;
              MemCpy( %Addr( SelCriDetail )
                    : pQryTemplate
                    : 34
                    ) ;
              MemCpy( %Addr( SelCriDetail )
                    : pQryTemplate
                    : SelCriDetail.Len
                    ) ;
              insertOutfile();
              offset = offset + SelCriDetail.Len ;
             endfor;
           return;
      /end-free
     /*-------------------------------------------------------------*/
     P createOutfile   b
     d createOutfile   pi
     c/exec sql
     c+     create table qtemp/selects
     c+      ( qrylib  CHAR(10)  ccsid 273 not null default '',
     c+        qryobj  CHAR(10)  ccsid 273 not null default '',
     c+        logoper CHAR(03)  ccsid 273 not null default '',
     c+        arg1    CHAR(14)  ccsid 273 not null default '',
     c+        opr     CHAR(02)  ccsid 273 not null default '',
     c+        arg2    CHAR(256) ccsid 273 not null default '' )
     c/end-exec
      /free
           return;
      /end-free
     P createOutfile   e
     /*-------------------------------------------------------------*/
     P insertOutfile   b
     d insertOutfile   pi
     d logicOperation  s              3a
     d arg2            s            256a
      /free
          if  SelCriDetail.logicOperation = x'40';
              logicOperation = 'AND';
          elseif SelCriDetail.logicOperation = x'80';
              logicOperation = 'OR';
          else;
              logicOperation = '';
          endif;
          arg2 =  %subst(  SelCriDetail.Arg2Dta : 1
                         : SelCriDetail.Arg2Len ) ;
      /end-free
     c/exec sql
     c+     insert into qtemp/selects
     c+           (qrylib, qryobj, logoper, arg1, opr, arg2)
     c+     VALUES(:QueryLib,
     c+            :QueryName,
     c+            :logicOperation,
     c+            :SelCriDetail.Arg1,
     c+            :SelCriDetail.CompOpr,
     c+            :Arg2 )
     c/end-exec
      /free
           return;
      /end-free
     P insertOutfile   e
     /*-------------------------------------------------------------*/