• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Reading Spool Files in RPG

    October 18, 2002 Timothy Prickett Morgan

    Hey, Ted:

    I have a problem similar to the one you solved in the February 27, 2002, issue of Midrange Guru. I wish to copy a spooled file that has been produced by a package, run an RPG program to modify the output, and build a new spooled file. In that example, you specified CTLCHAR(*FCFC) in the Copy Spooled File (CPYSPLF) command in order to use first-character form control characters. Can an RPG program interpret those characters and generate a new spool file with the same spacing?

    — Joe

    If you only want to modify the lines and reprint them, consider updating the disk file and using the Copy File (CPYF) command with CTLCHAR(*FCFC), as in the technique to which you referred.

    However, if you want to take more liberties with the new report, making an RPG program generate a fresh report is a good idea. It’s not difficult to make the RPG program read the first-character forms control characters and skip or space accordingly when it writes to a printer file. However, there’s an easier method that I have used several times.

    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:

    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.

    — Ted

    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
    

    Sponsored By
    ADVANCED SYSTEMS CONCEPTS

    SEQUEL meets all your iSeries and AS/400 data access needs in a single, integrated solution:

    • Windows, Web or host user interfaces

    • Convert AS/400 data into PC file formats

    • E-mail or FTP query results, reports and spool files
    • Run-time prompted queries and reports for end users

    • IF-THEN-ELSE logic in queries and reports

    • Report, form and label formatting second to none

    • Easily convert date fields, character-to-numeric, numeric-to-character and other data manipulation

    • SORT or JOIN using a calculated field

    • Quick summarization of data with Tabling function

    • Run multiple SEQUEL requests as one with the SEQUEL Scripting function

    • OLAP Business Intelligence at a fraction of the cost of comparable solutions

    Take 6 minutes to view a SEQUEL ViewPoint ScreenCam movie to see how simple Windows-based AS/400 and iSeries data access can be! In just a few short minutes, you can find out ways to make your job easier and improve data access throughout your organization. Download the ViewPoint movie here .

    For more information or a FREE trial of SEQUEL, call 847/605-1311 or visit Advanced Systems Concepts.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: mgo_rc, Volume 2, Number 80 -- October 18, 2002

    Sponsored by
    FalconStor

    Simplify Secure Offsite Data Protection for IBM Power with FalconStor Habanero™

    IBM i teams are under growing pressure to ensure data is protected, recoverable, and compliant—without adding complexity or disrupting stable environments.

    FalconStor Habanero™ provides secure, fully managed offsite data protection purpose-built for IBM Power. It integrates directly with existing IBM i backup tools and processes, enabling reliable offsite copies without new infrastructure, workflow changes, or added operational overhead.

    By delivering and managing the service end-to-end, FalconStor helps organizations strengthen cyber resilience, improve disaster recovery readiness, and meet compliance requirements with confidence. Offsite copies are securely maintained and available when needed, supporting recovery, audits, and business continuity.

    FalconStor Habanero offers a straightforward way to modernize offsite data protection for IBM i: focused on simplicity, reliability, and resilience.

    Learn More

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Reader Feedback and Insights: Another Compression Utility Hex Dump of an IFS File

    Leave a Reply Cancel reply

MGO Volume: 2 Issue: 80

This Issue Sponsored By

    Table of Contents

    • Reader Feedback and Insights: Another Compression Utility
    • Reading Spool Files in RPG
    • Hex Dump of an IFS File

    Content archive

    • The Four Hundred
    • Four Hundred Stuff
    • Four Hundred Guru

    Recent Posts

    • IBM Gets Bob 1.0 Off The Ground
    • You Store The Crown Jewels In A Safe, Not In A Bucket
    • More Power Systems Withdrawals, And Some From Red Hat, Too
    • Price Increases Are Here, Or Pending, And For Sure For Memory
    • IBM i PTF Guide, Volume 28, Number 9
    • After A Few Short Years, VS Code Passes Rational Developer for i
    • Why Logical Replication Has Become The New Standard for IBM i HA/DR
    • Guru: Managing The Lifecycle Of Your Service Programs – Updates Without Chaos
    • IT Spending Forecast Keeps Going Up And Up, But It Won’t Go Away
    • IBM i PTF Guide, Volume 28, Number 8

    Subscribe

    To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

    Pages

    • About Us
    • Contact
    • Contributors
    • Four Hundred Monitor
    • IBM i PTF Guide
    • Media Kit
    • Subscribe

    Search

    Copyright © 2025 IT Jungle