ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Reading Spool Files in RPG

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

  • Reading Spool Files in RPG

    Rather than CTLCHAR(*FCFC), use CTLCHAR(*PRTCTL). Doing so puts a four-byte prefix on each record of the disk file. The first three bytes contain either blanks or a skip-before entry. The fourth byte contains either a blank or a space-before entry.

    In the following example, the printer skips to line 5 before printing the first line. It double-spaces before printing the second line and single-spaces before printing the third line:
    full article on http://www.itjungle.com/mgo/mgo101802-story01.html


    005 12/25/2002 My Report Page 1
    2Blah blah blah
    1More blah blah blah

    In the RPG program, use the PRTCTL keyword on the printer file's F spec. This lets you use a data structure, rather than hard-coded skipping and spacing entries, to control the spacing of the output.

    The good thing about this technique is that it's easy to copy the skipping and spacing control characters from the spooled file image to the print control data structure.

    Here's an example. It reads a disk file that was loaded by CPYSPLF and builds a duplicate report.

    PHP Code:
    Fspoolfile if   f  136        disk                      
    Fqsysprt   o    f  132        printer oflind
    (*inof)     
    F                                     prtctl(prtctlds)  
     
    D prtctlds        ds            15                      
    D  pSpaceBefore           1      3                      
    D  pSpaceAfter            4      6                      
    D  pSkipBefore            7      9                      
    D  pSkipAfter            10     12                      
    D  pLineNbr              13     15                      
                                                            
    D outputdata      s            132                      
                                                            
    Ispoolfile ns  01                                       
    I                                  1    3  sSkipBefore  
    I                                  4    4  sSpaceBefore 
    I                                  5  136  inputdata    
                                                            
    C                   read      spoolfile                  
    C                   dow       not 
    %eof(spoolfile)        
    C                   eval      outputdata inputdata     
    C                   
    if        sSkipBefore <> *blanks     
    C                   
    eval      pSkipBefore sSkipBefore  
    C                   
    else                                 
    C                   eval      pSkipBefore = *blanks      
    C                   
    endif                                
    C                   if        sSpaceBefore <> *blanks    
    C                   
    eval      %subst(pSpaceBefore:3:1) = 
    C                                 sSpaceBefore           
    C                   
    else                                 
    C                   eval      pSpaceBefore = *blanks     
    C                   
    endif                                
    C                   except    lineout                    
    C                   read      spoolfile                  
    C                   enddo                                
    C                   
    eval      *inlr = *on                
    C                                              
    Oqsysprt   e            lineout                
    O                       outputdata         132 
    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
Working...
X