**-----------------------------------------------------------------------**
      * AUTHOR: Credit for this tool should be given to
      *         - Gary Guthrie, author of the MI version of the retrieval itself
      *         - Carsten Flensburg, who wrote the RPG IV version of the tool
      * and me, - Antonio Fernandez-Vicenti, that only "dressed" the RPG version
      *           to read from a list of Object descriptions, extract the info
      *           and write to an output file.
      * Good luck to all users !
     **-----------------------------------------------------------------------**
      *
      * QRYOBJD, the input file, can be built using 
      *     DSPOBJD   /*ALL  *QRYDFN  to a file, e.g.  QTEMP/QRYOBJD
      *
      * QRYDFNF, the output file, should have the following external definition:
      *      
      *      R  REG
      *         QRYNAM        10
      *         QRYLIB        10
      *         TEXTO         50
      *         TIP1           1
      *         TIP2           1
      *         OUTFIL        10 
      *         OUTLIB        10 
      *         REC         2562        
      *
      * The program will read QRYOBJD file. 
      * For each record, it will search the Query definition, 
      *    and write a REG record with the following data:
      *
      *         QRYNAM   : Query's Name
      *         QRYLIB   : Library where the Query is
      *         TEXTO    : Text of the Query...
      *      ...(it is taken from the QRYOBJD record, not from the Query itself)
      *         TIP1     : stands for type of output:
      *                    1=Display  2=Printer  3=File
      *         TIP2     : stands for type of Query:  
      *                    1=Detail   2=Summary
      *         OUTFIL   : Name of Output File (or blank)
      *         OUTLIB   : Name of Library of the Output file
      *         REC      : its 2562 bytes have the following structure:
      *
      *                    pos. 1-2    : a binary field which tells how many  
      *                                  Input files come after
      *                    pos. 3-2562 : an array of 32x80 bytes (32 is the 
      *                                     maximum number of input files)
      *                                  For each possible input file, 80 bytes
      *                                  are provided.
      *                                  They include the file's Name, Library, 
      *                                  Member and record, and some more data  
      *
      *  Note: If you built a Query to output to a file, and give it a name and 
      *        library, and later on you change your mind and change the Query 
      *        to output to Display or Print, the output's file and library are
      *        still present, and it will show in OUTFIL, OUTLIB above, even 
      *        though the Query is now instructed to output to Display/Printer.
      *
      *        Field TIP1 above should help to "disregard" the unwanted file.
      *
      *
      *  COMPILATION:
      *        When compiling the program you should provide        
      *        the following parameters
      *
      *             DFTACTGRP(*NO)
      *             BNDDIR(QC2LE)
      *
      *  which were present in the original program as keywords in the H spec
      *  but I had to eliminate (we are stil at rel 4.1 ...)
      *  and give as parameters in the compilation.
      *
     **-- Header:  -----------------------------------------------------------**
     H
     **-- File  :  -----------------------------------------------------------**
     FQRYOBJD   IP   E             DISK
     FQRYDFNF   O    E             DISK
     **-- MI functions:  -----------------------------------------------------**
     D rslvsp          Pr              *   ProcPtr  ExtProc( 'rslvsp' )
     D  ObjTyp                        2a   Value
     D  ObjNam                         *   Value  Options( *String )
     D  ObjLib                         *   Value  Options( *String )
     D  AutReq                        2a   Value
     **
     D setsppfp        Pr              *   ExtProc( 'setsppfp' )
     D   Object                        *   Value  ProcPtr
     **
     D setsppo         Pr              *   ExtProc( 'setsppo' )
     D   SpcPtr                        *   Value
     D   Offset                      10i 0 Value
     **
     D MemCpy          Pr              *   ExtProc( 'memcpy' )
     D  pOutMem                        *   Value
     D  pInpMem                        *   Value
     D  iMemSiz                      10u 0 Value
     **-- Query outfile specification:  --------------------------------------**
     D QiOutFil        Ds
     D  OfDtaLen                     10i 0 Inz
     D  OfFilNam                     10a
     D                                5i 0 Inz
     D  OfLibNam                     10a
     D                                5i 0
     D  OfMbrNam                     10a
     D                                5i 0
     D  OfDtaOpt                      1a
     D                                3a
     D  OfFilAut                     10a
     **-- Query inputfile(s) specification:  ---------------------------------**
     D QiInpFil        Ds
     D  IfNbrFil                      5i 0 Inz
     D  IfFilInf                     80a   Dim( 32 )
     D                                5i 0 Overlay( IfFilInf:  1 )
     D  IfFilNam                     10a   Overlay( IfFilInf:  3 )
     D                                5i 0 Overlay( IfFilInf: 13 )
     D  IfLibNam                     10a   Overlay( IfFilInf: 15 )
     D                                5i 0 Overlay( IfFilInf: 25 )
     D  IfMbrNam                     10a   Overlay( IfFilInf: 27 )
     D                                5i 0 Overlay( IfFilInf: 37 )
     D  IfRcdNam                     10a   Overlay( IfFilInf: 39 )
     D                                5i 0 Overlay( IfFilInf: 49 )
     D  IfFilId                       4a   Overlay( IfFilInf: 51 )
     D                                5i 0 Overlay( IfFilInf: 55 )
     D  IfRcdId                      13a   Overlay( IfFilInf: 57 )
     D                               11a   Overlay( IfFilInf: 70 )
     **-- Query printed output specifications:  ------------------------------**
     D QiOutWtr        Ds
     D  OwDtaLen                     10i 0 Inz
     D  OwWtrNam                     10a
     D                               26a
     D  OwPprLen                      5i 0
     D  OwPprWdt                      5i 0
     D                                5i 0
     D                                5i 0
     D                                5i 0
     D  OwFrmTyp                     10a
     D                               12a
     D  OwPrtLin1                     5i 0
     D  OwPrtLinLst                   5i 0
     D  OwPrtLinDst                   5i 0
     D  Ow1                           5i 0
     D  Ow2                           5i 0
     **
     D QiRptHdr        Ds
     D  RhHdrLen                     10i 0 Inz
     D                               10i 0
     D                               10i 0
     D  RhNbrLin                      5i 0
     D  RhLinLen                      5i 0
     D  RhDta                       320a
     **
     D QiPagHdr        Ds
     D  PhHdrLen                     10i 0 Inz
     D                               10i 0
     D                               10i 0
     D  PhNbrLin                      5i 0
     D  PhLinLen                      5i 0
     D  PhDta                       240a
     **
     D QiPagTrl        Ds
     D  PtTrlLen                     10i 0 Inz
     D                               10i 0
     D                               10i 0
     D  PtNbrLin                      5i 0
     D  PtLinLen                      5i 0
     D  PtDta                        80a
     **-- Query selection criterias:  ----------------------------------------**
     D QiSelCriHdr     Ds
     D  ScTotLen                     10i 0 Inz
     D                               10i 0
     D                               10i 0
     D                               10i 0
     D  ScNbrCri                      5i 0
     **
     D QiSelCriDtl     Ds
     D  ScCriLen                      5i 0 Inz
     D                               10i 0
     D                               10i 0
     D  ScCriRelN                    10i 0
     D  ScCriRel                      1a   Overlay( ScCriRelN: 4 )
     D  ScCriArg1                    14a
     D  ScCriOpr                      2a
     D  ScCriArg2Lin                  5i 0
     D  ScCriArg2Dta               4096a
     **
     D QiSelCriArg2    Ds                  Based( pArg2 )
     D  ScCriArg2Len                  5i 0
     D  ScCriArg2                   512a
     ** Formatted selection criterias:
     D SelCri          Ds
     D SelTxt                        55a   Dim( 256 )
     D  SelRel                        3a   Overlay( SelTxt:  1 )
     D  SelArg1                      14a   Overlay( SelTxt:  5 )
     D  SelOpr                        5a   Overlay( SelTxt: 20 )
     D  SelArg2                      30a   Overlay( SelTxt: 26 )
     **
     D Opr             Ds
     D Opr1                          14a   Inz('INLKNKNSNSNTBT')
     D Opr2                          35a   Inz('LIST LIKE NLIKENLISTISNOTRANGE')
     D OprMnm                         2a   Dim( 7 ) Overlay( Opr1 )
     D OprTxt                         5a   Dim( 7 ) Overlay( Opr2 )
     **-- Global variables:  -------------------------------------------------**
     D pQryObj         s               *   ProcPtr
     D pQryTpl         s               *
     D QryTpl          s          32767a   Based( pQryTpl )
     **
     D Int             s             10i 0
     D Idx             s              5i 0
     D Lin             s              5i 0
     D OutOpt          s              1a
     D OutOut          s              2a
      *
     **-- Parameters:  -------------------------------------------------------**
     D PxQryNam        s             10a
     D PxQryLib        s             10a
     **
     **
     **-- Mainline:  ---------------------------------------------------------**
     **
     C                   move      ODOBNM        QRYNAM
     C                   move      ODOBNM        PxQryNam
     C                   move      ODLBNM        QRYLIB
     C                   move      ODLBNM        PxQryLib
     C                   move      ODOBTX        TEXTO

     C                   Eval      pQryObj =  rslvsp( x'1911'
     C                                              : %TrimR( PxQryNam )
     C                                              : %TrimR( PxQryLib )
     C                                              : x'0000'
     C                                              )
     **
     c                   Eval      pQryTpl  = setsppfp( pQryObj )
     **
     c                   Eval      pQryTpl  = setsppo( pQryTpl: 260 )
     C                   CallP     MemCpy( %Addr( OutOut )
     C                                   : pQryTpl
     C                                   : %Size( OutOut )
     C                                   )
     C                   movel     outout        outopt
     C                   movel     outout        TIP1
     C                   move      outout        TIP2
     C                   move      *blanks       OUTFIL
     C                   move      *blanks       OUTLIB

     C                   If        OutOpt   = '3'
     C                   Eval      OfFilNam = '*DFT'
     C                   Eval      OfLibNam = '*PRV'
     C                   Eval      OfDtaLen = 25
     C                   EndIf
     **
     c                   Eval      pQryTpl  = setsppo( pQryTpl: 380 )
     C                   CallP     MemCpy( %Addr( Int )
     C                                   : pQryTpl
     C                                   : %Size( Int )
     C                                   )
     **
     C                   If        Int      > 0
     c                   Eval      pQryTpl  = setsppo( pQryTpl: Int )
     C                   CallP     MemCpy( %Addr( QiOutFil )
     C                                   : pQryTpl
     C                                   : %Size( QiOutFil )
     C                                   )
     c                   move      OfFilNam      OUTFIL
     c                   move      OfLibNam      OUTLIB
     C                   EndIf
     **
     C                   Eval      pQryTpl  = setsppo( pQryTpl: 558 )
     C                   CallP     MemCpy( %Addr( IfNbrFil )
     C                                   : pQryTpl
     C                                   : %Size( IfNbrFil )
     C                                   )
     **
     C                   Eval      pQryTpl  = setsppo( pQryTpl: 560 )
     **
     C     1             do        32            Idx
     C                   move      *blanks       IfFilInf(Idx)
     C                   Enddo
     C     1             do        IfNbrFil      Idx
     C                   CallP     MemCpy( %Addr( IfFilInf( Idx ))
     C                                   : pQryTpl
     C                                   : %Size( IfFilInf )
     C                                   )
     **
     C                   Eval      pQryTpl  = pQryTpl + %Size( IfFilInf )
     C                   Enddo
     c                   move      *blanks       rec
     c                   Eval      rec = QiInpFil
     **
     C                   WRITE     REG
     **