ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

[API] QSPGETSP: Get print Content of Spoolfile problems

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [API] QSPGETSP: Get print Content of Spoolfile problems

    Hello,

    I'd like to search in a spoolfile and therefore I read the spoolfile into a userspace object.

    But my result "WorkString" (bold formated) is either blank or has some mysterious content.
    I cannot recognize any error so far, but that is my first meeting with this api.
    The spoolfile is a *SCS file.
    UsrSpc-Object looks fine so far.
    I appreciate any help
    Kind regards,

    Sascha


    Code:
        
         PGetSplfData      B                   Export
         DGetSplfData      PI
         D Handle                        10i 0 value
         D
         D* - Userspace erstellen
         DCreate_UserSpace...
         D                 PR                    ExtPgm('QUSCRTUS')
         D UserSpace                     20a     Const
         D ExternalAttribute...
         D                               10A     Const
         D InitialSize                   10i 0   Const
         D InitialValue                   1a     Const
         D PublicAuthority...
         D                               10a     Const
         D Text                          50a     Const
         D Replace                       10a     Const
         D Error                                 Like(ErrorCode)
    
         D*- Userspace auf "Automatisch erweiterbar" setzen
         D AutoExtendUsrSpc...
         D                 PR                  ExtPgm('QUSCUSAT')
         D
         D   RtnLib                      10A
         D   UsrSplc                     20A   const
         D   Attrib                   65535A   const options(*varsize)
         D   Error                    32767A   options(*varsize)
    
         D KEY_AUTO_EXT    C                   const(3)
         D AutoExt         DS                  qualified
         D   NbrRec                      10I 0 inz(1)
         D   Key                         10I 0 inz(KEY_AUTO_EXT)
         D   Len                         10I 0 inz(%size(AutoExt.Data))
         D   Data                         1A   inz(*ON)
    
         D* - Zeiger des Userspaces ermitteln
         DRetrieve_UserSpace_Pointer...
         D                 PR                    ExtPgm('QUSPTRUS')
         D UserSpace                     20a     Const
         D Pointer                         *
    
         D* - Spoolfile in einen Userspace laden
         D PutSplfInUsrSpc...
         D                 PR                  ExtPgm('QSPGETSP')
         D
         D   Handle                      10I 0 const
         D   Space                       20A   const
         D   Format                       8A   const
         D   BufNo                       10I 0 const
         D   WaitFor                     10A   const
         D   ErrorCode                32767A   options(*varsize)
    
         D ErrorCode       ds
         D  bytesProv                    10i 0 inz(0)
         D  bytesAvail                   10i 0 inz(0)
    
         D UsrSpc                        10A
         D UsrSpcLib                     10A
         D RtnUsrSpcLib                  10A
    
         D* Header für QSPGETSP (Laden Splf in UsrSpc)
         D p_UsrSpc        S               *
         D dsGSH           DS                  based(p_UsrSpc) qualified
         D  dsGSH_UsrAra                 64A
         D  dsGSH_HdrSize                10I 0
         D  dsGSH_StrLvl                  4A
         D  dsGSH_SplfLvl                 6A
         D  dsGSH_Format                  8A
         D  dsGSH_CompInd                 1A
         D  dsGSH_Reserv1                 1A
         D  dsGSH_SpcUsed                10I 0
         D  FstBufferOffset...
         D                               10I 0
         D  dsGSH_ReqBufs                10I 0
         D  RetBuffers                   10I 0
         D  dsGSH_PDSize                 10I 0
         D  dsGSH_NPages                 10I 0
         D  dsGSH_NFPage                 10I 0
         D  dsGSH_OFPage                 10I 0                                      Offset of 1st page
         D  dsGSH_Reserv2                 8A
    
         D p_Buffer        S               *
         D dsBuffer        DS                  based(p_Buffer)
         D                                     qualified
         D LenBuffInfo                   10i 0
         D BuffOrdinal                   10i 0
         D GenInfoOffset                 10i 0
         D GenInfoSize                   10i 0
         D PageDataOffset                10i 0
         D PageDataSize                  10i 0
         D PageCount                     10i 0
         D PageEntrySize                 10i 0
         D PrtDataOffset                 10i 0
         D PrtDataSize                   10i 0
    
         D p_GeneralInfo   S               *
         D dsGeneralInfo   DS                  based(p_GeneralInfo)
         D                                     qualified
         D NonBlankLinesBuffer...
         D                               10i 0
         D NonBlankLines1stPage...
         D                               10i 0
         D ErrInfoNumBuffer...
         D                               10i 0
         D ErrInfoOffset                 10i 0
         D PrtDataSize                   10i 0
         D State                         10A
         D LastPageConinues...
         D                                1A
         D AdvPrtFuncFile                 1A
         D LACCmdArrInBuf                 1A
         D AnyBuffHadLAC                  1A
         D ErrInfoLAC                     1A
         D ErrInfo                        1A
         D ZeroPages                      1A
         D LoadFont                       1A
         D IPDSData                       1A
         D Reserved                       5A
         D*
         D i               S             10i 0
         D p_Data          S               *
         D WorkString      S           5000A    Varying
         D TestStr         S           5000A    Varying
         D*
          /free
           UsrSpc = 'IT013';
           UsrSpcLib = 'REISBIB'       ;
           //Create UsrSpc:
    
           Create_Userspace( UsrSpc + UsrSpcLib
                           : *BLANKS
                           : 4096
                           : *BLANKS
                           : '*CHANGE'
                           : *BLANKS
                           : '*YES'
                           : ErrorCode   );
    
           //Auto-extend usrspc
           AutoExtendUsrSpc(RtnUsrSpcLib
                          : UsrSpc + UsrSpcLib
                          : AutoExt
                          : ErrorCode);
    
           //Read Splf into UsrSpc:
           PutSplfInUsrSpc(Handle
                           : Usrspc + UsrSpcLib
                           : 'SPFR0200'
                           : -1
                           : '*WAIT'
                           : ErrorCode);
    
           //Get Pointer for Userspace:
            Retrieve_UserSpace_Pointer( UsrSpc + UsrSpcLib :
                                       p_UsrSpc);
    
            p_Buffer = p_UsrSpc + dsGSH.FstBufferOffset;
    
            for i = 1 to dsGSH.RetBuffers;
              // p_GeneralInfo = P_UsrSpc + dsBuffer.GenInfoOffset;
    
               p_Data = P_Buffer + dsBuffer.PrtDataOffset ;
    
               [B]Workstring =  %Str(p_Data : dsBuffer.PrtDataSize);[/B]
               p_Buffer = p_Buffer + dsBuffer.LenBuffInfo;
    
            ENDFOR;
            return    ;
          /end-free
         P                 E

  • #2
    Re: [API] QSPGETSP: Get print Content of Spoolfile problems

    interesting, but is the data not in a table instead of reading the report. Seems backwards.

    Now if you really want to read the spool file, id just copy the spool to a flat file and then read through that.
    Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

    Comment


    • #3
      Re: [API] QSPGETSP: Get print Content of Spoolfile problems

      I don't see where you open the spooled file. You need to use the Open Spooled File (QSPOPNSP) API to open it before you can get anything from it with QSPGETSP. You need to read the documentation more carefully for QSPGETSP if you want to be successful with it.
      Tom

      There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

      Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

      Comment


      • #4
        Re: [API] QSPGETSP: Get print Content of Spoolfile problems

        Found this out in the bowls of the internet.. Started by our very own Tommy Holden and modified by jean-paul lamontre
        Make your required modifications and let us know if this works!!!

        PHP Code:

             H OPTION
        (*NODEBUGIO:*SRCSTMTDFTACTGRP(*NOACTGRP(*NEW)                   
                                                                                         
             
        FQSYSPRT   O    F  132        PRINTER OFLIND(Over)                          
             
        FSPOOLFILE IF   E             DISK    usropn rename(SPOOLFILE:SPOOLREC)     
             
        FHRQAPVR505UF A E           K DISK    rename(HRQAPVR505:VOUCHREC)           
                                                                                         
              
        // List Spooled Files API                                                  
             
        D listSplF        PR                  ExtPgm('QUSLSPL')                     
             
        D  UserSpaceName...                                                         
             
        D                               20a   Const                                 
             
        D  APIFormat                     8a   Const                                 
             
        D  UserName                     10a   Const                                 
             
        D  OutQName                     20a   Const                                 
             
        D  FormType                     10a   Const                                 
             
        D  UserSpecData                 10a   Const                                 
             
        D  APIErrorCode              32766a   Options(*varsize)                     
                                                                                         
              
        // List spool files return DS definition and basing pointer                
             
        D s0300Ptr        s               *                                         
             
        D SPLF0300        ds                  Qualified Based(S0300PTR)             
             
        D  jobName                      10a                                         
             D  userName                     10a                                         
             D  jobNumber                     6a                                         
             D  splName                      10a                                         
             D  splNumber                    10i 0                                       
             D  splStatus                    10i 0                                       
             D  createDate                    7a                                         
             D  createTime                    6a                                         
             D  splSchedule                   1a                                         
             D  splSysName                   10a                                         
             D  userData                     10a                                         
             D  formType                     10a                                         
             D  outQ                         10a                                         
             D  outQLib                      10a                                         
             D  ASP                          10i 0                                       
             D  splSize                      10i 0                                       
             D  splSizeMult                  10i 0                                       
             D  totalPages                   10i 0                                       
             D  copies                       10i 0                                       
             D  priority                      1a                                         
             D  reserved                      3a                                         
                                                                                         
              
        // Spool Status                                                            
             
        D cPrtReady       c                   Const(1)                              
             
        D cPrtOpened      c                   Const(2)                              
             
        D cPrtClosed      c                   Const(3)                              
             
        D cPrtSaved       c                   Const(4)                              
             
        D cPrtWriting     c                   Const(5)                              
             
        D cPrtHeld        c                   Const(6)                              
             
        D cPrtMSGW        c                   Const(7)                              
             
        D cPrtPending     c                   Const(8)                              
             
        D cPrtPrinting    c                   Const(9)                              
             
        D cPrtFinished    c                   Const(10)                             
             
        D cPrtSending     c                   Const(11)                             
             
        D cPrtDeferred    c                   Const(12)                             
                                                                                         
                
                                                                                         
              
        // Delete User Space API Procedure                                         
             
        D DltUsrSpc       PR                  ExtPgm('QUSDLTUS')                    
             
        D  CUSQualUSName...                                                         
             
        D                               20a   Const                                 
             
        D  ErrorCode                 32766a   options(*varsize)                     
                                                                                         
              
        // Create User Space API                                                   
             
        D CrtUsrSpc       PR                  ExtPgm('QUSCRTUS')                    
             
        D  CUSQualUSName...                                                         
             
        D                               20a   CONST                                 
             
        D  CUSExtAttribut...                                                        
             
        D                               10a   CONST                                 
             
        D  CUSInitSize                  10i 0 CONST                                 
             
        D  CUSInitValue                  1a   CONST                                 
             
        D  CUSPublicAuth                10a   CONST                                 
             
        D  CUSDescription...                                                        
             
        D                               50a   CONST                                 
             
        D  CUSReplace                   10a   CONST                                 
             
        D  ErrorCode                 32766a   options(*varsize)                     
                                                                                         
              
        // Change User Space API                                                   
             
        D ChgUsrSpc       PR                  ExtPgm('QUSCUSAT')                    
             
        D  RtnLib                       10a                                         
             D  CUSQualUSName                20a   
        CONST                                 
             
        D  CUSAttributes             32766a   Options(*Varsize)                     
             
        D  ErrorCode                 32766a   Options(*VarSize)                     
                                                                                         
              
        // Get User Space Pointer API                                              
             
        D UserSpacePntr   PR                  ExtPgm('QUSPTRUS')                    
             
        D  CUSQualUSName                20a   CONST                                 
             
        D  CUSPointer                     *                                         
                                                                                         
              
        // Update User Space API                                                   
             
        D UpdUsrSpc       PR                  ExtPgm('QUSCHGUS')                    
             
        D  CUSQualUSName                20a   Const                                 
             
        D  Start                        10i 0 Const                                 
             
        D  DataLength                   10i 0 Const                                 
             
        D  Data                      32767a   Options(*Varsize) Const               
             
        D  ForceASP                      1a   Const                                 
             
        D  ErrorCode                 32766a   Options(*VarSize)                     
                                                                                         
              
        // User Space Header DS                                                    
             
        D USHeader        ds                  Based(CUSPointerQualified           
             D  userArea                     64a                                         
             D  hdrSize                      10i 0                                       
             D  strLvl                        4a                                         
             D  format                        8a                                         
             D  APIUsed                      10a                                         
             D  crtDate                      13a                                         
             D  infoStatus                    1a                                         
             D  sizeOfUS                     10i 0                                       
             D  offsetToInp                  10i 0                                       
             D  sizeOfInp                    10i 0                                       
             D  offsetToHdr                  10i 0                                       
             D  sizeOfHdr                    10i 0                                       
             D  offsetToDtl                  10i 0                                       
             D  sizeOfDtl                    10i 0                                       
             D  numberOfEnt                  10i 0                                       
             D  entrySize                    10i 0                                       
             D  CCSID                        10i 0                                       
             D  country                       2a                                         
             D  langID                        3a                                         
             D  subsetInd                     1a                                         
             D                               42a                                         
                                                                                         
              
        // User Space Attributes DS                                                
             
        D AttributeDS     DS                  Qualified                             
             D  nbrAttrToChg                 10i 0 Inz
        (1)                                
             
        D  key                          10i 0 Inz(3)                                
             
        D  dataLen                      10i 0 Inz(1)                                
             
        D  autoExtend                    1a   Inz('1')                              
                                                                                         
              
        // ReSend Message API Procedure                                            
             
        D sendMsg         PR                  ExtPgm('QMHRSNEM')                    
             
        D  msgKey                        4a   const                                 
             
        D  errorCode                 32766a   options(*varsize)                     
             
        D  toStkEntry                32766a   options(*varsize: *nopass)            
             
        D  toStkEntryLn                 10i 0 const options(*nopass)                
             
        D  format                        8a   const options(*nopass)                
             
        D  fromEntry                      *   const options(*nopass)                
             
        D  fromCounter                  10i 0 const options(*nopass)                
                                                                                         
              
        // Run system command                                                      
             
        D RunCmd          PR                  EXTPGM('QCMDEXC')                     
             
        D  cmd                        1024A   OPTIONS(*VARSIZE) CONST               
             
        D  cmdLen                       15P 5 CONST                                 
                                                                                         
              
        // Error Code DS For API Calls                                             
             
        D ErrorDS         ds                                                        
             D  dsEC1                        10i 0 inz
        (0)                                
             
        D  dsEC2                        10i 0 inz(0)                                
                                                                                         
              
        // Program Stack DS For API Calls                                          
             
        D StackDS         ds                                                        
             D  dsRS_StkCnt                  10i 0 inz
        (2)                                
             
        D  dsRS_StkQual                 20a   inz('*NONE     *NONE')                
             
        D  dsRS_IDLen                   10i 0 inz(7)                                
             
        D  dsRS_StkID                    7a   inz('*')                              
                                                                                         
             
        D i               s             10u 0                                       
             D x               s             10u 0                                       
             D numOfVouchers   s             10u 0                                       
             D currentVoucher  s             10u 0                                       
             D lastVoucher     s             10u 0                                       
             D currentID       s             10u 0                                       
             D sysCommand      s           1024a                                         
             D printLine       s            132a                                         
             D userID          s             10a   inz
        (*User)                            
             
        D currentDate     s               d                                         
             D cLSTSPLF        c                   
        Const('LSTSPLF   QTEMP')              
             
        D DOInvoiceQ      c                   Const('DOINVOICE QUSRSYS   ')         
             
        D voucherStr      c                   Const('VOUCHER:')                     
                                                                                         
             
        D*--------------------------------------------------                        
             
        DProcedure namereturnRunID                                              
             D
        Purpose:        Return unique run ID                                     
             D
        Returns:        Unique ID for this run                                   
             D
        *--------------------------------------------------                        
             
        D returnRunID     PR            10U 0                                       
                                                                                         
                                                                                         
              
        /FREE                                                                      
               
        // Setup                                                                  
                                     
               
        numOfVouchers = *zero;                                                    
               
        currentDate = %date();                                                    
               
        currentID returnRunID();                                                
                                                                                         
               
        // Clear the database file                                                
               
        sysCommand 'CLRPFM FILE(MYLIB/SPOOLFILE)';                            
               
        RunCmd(sysCommand:%len(sysCommand));                                      
                                                                                         
               
        // Print report headings                                                  
               
        except Heading;                                                           
                                                                                         
               
        // Delete the user space if it already exists                             
               
        monitor;                                                                  
                  
        DltUsrSpc(cLSTSPLF:ErrorDS);                                           
               
        on-error;                                                                 
               
        endmon;                                                                   
                                                                                         
               
        // Create user space in temporary  holding to hold list of                
               // spool files in the DOINVOICE output queue                              
               
        monitor;                                                                  
                  
        CrtUsrSpc(cLSTSPLF:                                                    
                            
        'USRSPC':                                                    
                            
        1024:                                                        
                            
        x'00':                                                       
                            
        '*ALL':                                                      
                            
        'List Spool':                                                
                            
        '*NO':                                                       
                            
        ErrorDS);                                                    
               
        on-error;                                                                 
                  
        sendMsg( *blanks:                                                      
                           
        ErrorDS:                                                      
                           
        StackDS:                                                      
                           %
        size(StackDS):                                               
                           
        'RSNM0100':                                                   
                           *
        NULL:                                                        
                           
        );                                                          
               
        endmon;                                                                   
                                                                                         
               
        // Call API to create a list of spool files in the user space             
               // All spool files from DOINVOICE will be listed                          
               
        monitor;                                                                  
                  
        listSplFcLSTSPLF:'SPLF0300':'*ALL':                                  
                            
        DOInvoiceQ:                                                  
                            
        '*ALL':                                                      
                            
        '*ALL':                                                      
                            
        ErrorDS );                                                   
               
        on-error;                                                                 
                  
        sendMsg( *blanks:                                                      
                           
        ErrorDS:                                                      
                           
        StackDS:                                                      
                           %
        size(StackDS):                                               
                           
        'RSNM0100':                                                   
                           *
        NULL:                                                        
                           
        );                                                          
               
        endmon;                                                                   
                                                                                         
               
        // Get pointer to the user space                                          
               
        UserSpacePntr(cLSTSPLF:CUSPointer);                                       
                                                                                         
               
        // If any spool files exist then copy each spool file                     
               // to the work table                                                      
               
        if USHeader.numberOfEnt <> *zero;                                         
                  
        // Load spool file data ds with entries from user space                
                  
        s0300Ptr CUSPointer USHeader.offsetToDtl;                          
                                                                                         
                  
        // Add each spool file into the database file                          
                  
        for 1 to USHeader.numberOfEnt;                                     
                     
        sysCommand =                                                        
                        
        'CPYSPLF FILE(' + %trim(SPLF0300.splName) + ') ' +               
                        
        'TOFILE(MYLIB/SPOOLFILE) ' +                                   
                        
        'JOB(' SPLF0300.jobNumber '/' +                              
                             %
        trim(SPLF0300.userName) + '/' +                            
                             %
        trim(SPLF0300.jobName) + ') ' +                            
                             
        'SPLNBR(' + %char(SPLF0300.splNumber) + ') ' +              
                             
        'MBROPT(*ADD)';                                             
                     
        RunCmd(sysCommand:%len(sysCommand));                                
                                                                                         
                     
        // Next user space entry                                            
                     
        s0300Ptr s0300Ptr USHeader.EntrySize;                           
                  endfor;                                                                
                                                                                         
               endif;                                                                    
                                                                                         
               
        // Read through the work file and extract the voucher numbers             
               // List the numbers on the report                                         
               
        lastVoucher = *zero;                                                      
                                                                                         
               if 
        NOT %open(SPOOLFILE);                                                  
                  
        open(ESPOOLFILE;                                                     
               endif;                                                                    
               
        setll *start SPOOLFILE;                                                   
               
        read(ESPOOLREC;                                                         
               
        dow NOT %EOF(SPOOLFILE);                                                  
                  
        // Check the line to see if it is the voucher number listing           
                  // If so, then store the voucher number in the database                
                  // and print it on the report                                          
                  
        if %subst(SPOOLTEXT:1:8) = voucherStr;                                 
                     
        currentVoucher = %dec(%subst(SPOOLTEXT:10:10):10:0);                
                     if 
        currentVoucher <> lastVoucher;                                   
                        
        printLine = %subst(SPOOLTEXT:10:10);                             
                        
        except Body;                                                     
                        
        numOfVouchers += 1;                                              
                        
        chain(E) (currentVoucher:currentDateHRQAPVR505;                
                        if %
        found(HRQAPVR505);                                           
                           
        runID currentID;                                            
                           
        voucher currentVoucher;                                     
                           
        procDate currentDate;                                       
                           
        update(EVOUCHREC;                                           
                        else;                                                            
                           
        runID currentID;                                            
                           
        voucher currentVoucher;                                     
                           
        procDate currentDate;                                       
                           
        write(EVOUCHREC;                                            
                        endif;                                                           
                     endif;                                                              
                     
        lastVoucher currentVoucher;                                       
                  endif;                                                                 
                  
        read(ESPOOLREC;                                                      
               
        enddo;                                                                    
                                                                                         
               
        // Exit                                                                   
               
        exsr Terminate;                                                           
                                                                                         
               
        //**************************************************                      
               // SubR: Terminate()                                                      
               // Exit the program                                                       
               //**************************************************                      
               
        begsr Terminate;                                                          
                  
        except Totals;                                                         
                  
        except Footer;                                                         
                  *
        INLR=*On;                                                             
                  return;                                                                
               
        endsr;                                                                    
                                                                                         
              /
        END-FREE                                                                  
                                                                                         
              
        // Output. ----------------------------------------------------            
             
        OQSYSPRT   E            Printer        1                                    
                                                                                         
             O          E            Heading        1                                    
                                                                                         
             O                                            9 
        'SPOOLPROC'                  
             
        O                                           50 'Process Spool Files - '     
             
        O                                           73 'List AP Voucher Numbers'    
             
        O          E            Heading        1  1                                 
             O                       userID              10                              
                                                                                         
             O          E            Heading        1  1                                 
             O                                           12 
        'AP Voucher #'               
                                                                                         
             
        O          E            Heading        1                                    
             O                                           20 
        '===================='       
                                                                                         
             
        O          E            Body           1                                    
             O                       printLine                                           
                                                                                         
             O          E            Totals         1  1                                 
             O                                           15 
        'TOTAL VOUCHERS:'            
             
        O                       numOfVouchers Z                                     
                                                                                         
             O          E            Footer         1  1                                 
             O                                           21 
        '*** END OF REPORT ***'      
                                                                                         
             
        P*--------------------------------------------------                        
             
        PProcedure namereturnRunID                                              
             P
        Purpose:        Return unique run ID                                     
             P
        Returns:        Unique ID for this run                                   
             P
        *--------------------------------------------------                        
             
        P returnRunID     B                                                         
             D returnRunID     PI            10U 0                                       
                                                                                         
                                                                                         
             D
        Local fields                                                             
             D maxID           S             10U 0                                       
             D indMaxID        S              5i 0                                       
                                                                                         
              
        Get the highest runID already in the table                               
             C
        /EXEC SQL                                                                  
             C
        +  SELECT MAX(RUNID)                                                       
             
        C+     INTO :maxID :indMaxID                                                
             C
        +     FROM HRZNCUSOBJ/HRQAPVR505                                           
             C
        /END-EXEC                                                                  
                                                                                         
              
        /FREE                                                                      
                                                                                         
               
        // Add one to the highest to create the new run ID                        
                
        RETURN maxID 1;                                                        
                                                                                         
              /
        END-FREE                                                                  
             P returnRunID     E 
        Attached Files
        All my answers were extracted from the "Big Dummy's Guide to the As400"
        and I take no responsibility for any of them.

        www.code400.com

        Comment


        • #5
          Re: [API] QSPGETSP: Get print Content of Spoolfile problems

          Don't forget to thank Tommy and to post your finished code to help someone else down the road.
          If you don't I will send off a letter to Angela Merkel!
          I'm here to chew bubble gum and kick @#%@#%@#%.....and I'm all outta bubble gum !
          Yes I'm talking to you squirrel nuts.

          Comment

          Working...
          X