• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Quick And Handy RPG Output

    March 12, 2014 Ted Holt

    Are you one of those people who thrive on complexity? Do you love bureaucracy and paperwork? If so, you’re reading the wrong newsletter. I like everything to be as simple as possible. Today I have a simple routine that is a time-saver for me. I hope you find it useful.

    My little routine lets me print anything with minimal effort. I can print character variables, numeric variables, data structures, the results of expressions, and anything else that can be assigned to a character variable. I developed it because I needed a quick way to add output to RPG programs without the effort of writing DDS and O specs.

    I used various names for this and similar routines, but the name I finally settled on is writeln, pronounced “write line.” If you know anything about Pascal (the programming language, not the scientist), you know that I took the name from Pascal’s primary stream output procedure.

    Here’s the source code.

    Fqsysprt   o    f  132        printer usropn
    
    D writeln         pr
    D  inString                    132a   const
    
    P writeln         b
    D                 pi
    D  inString                    132a   const
       // locals
    D ReportLine      ds           132
     /free
         ReportLine = inString;
         write qsysprt ReportLine;
     /end-free
    P                 e
    

    There’s not much to it, huh? Use any program-described printer file you like. I used QSYSPRT for illustration.

    Writeln prints anything you throw at it, within reason. Here are some examples:

    1. Print a character variable.

    if ErrorMessage <> *blanks;
        writeln(ErrorMessage);
    endif;
    

    2. Print a character literal.

    writeln('** End **');
    

    3. Print a numeric value.

    writeln('valuelen=' + %char(vallen));
    

    4. Print an expression.

    writeln(%trim(zSqlData.SerialNbr)          + Sep +
            FmtDate(zSqlData.InstallDate)      + Sep +
            %trimr(zSqlData.PartNbr)           + Sep +
            FmtStr(zSqlData.PartDesc)          + Sep +
            FmtDate(zSqlData.EntryDate)        + Sep +
            %trim(zSqlData.Model)              + Sep +
            FmtStr(zSqlData.CompanyName)       + Sep +
            FmtStr(zSqlData.CompanyCityState)  + Sep +
            FmtZip(zSqlData.CompanyZip));             
    

    Why has writeln been helpful?

    1. It’s quick. I don’t have to write DDS or O specs.

    2. It’s easily discarded. I might use writeln during development or debugging, then delete it from the program or subordinate it to a disabled compiler directive before installing into production. Since I have so little time invested in the calls to my routine, I don’t feel as if I’ve wasted time.

    3. It’s easily replaced. I sometimes use writeln while developing in order to concentrate on the logic of a program. When I have the logic working the way I want it to, I turn my attention to formatting, which means my DDS tends to come out the way I want it without a lot of experimentation and revision.

    4. It’s good for free-format output. I’ve even used this routine to build CSV files.

    That should be enough to get you going, and hopefully enough to whet your appetite.



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    DRV Tech

    Get More Out of Your IBM i

    With soaring costs, operational data is more critical than ever. IBM shops need faster, easier ways to distribute IBM applications-based data to users more efficiently, no matter where they are.

    The Problem:

    For Users, IBM Data Can Be Difficult to Get To

    IBM Applications generate reports as spooled files, originally designed to be printed. Often those reports are packed together with so much data it makes them difficult to read. Add to that hardcopy is a pain to distribute. User-friendly formats like Excel and PDF are better, offering sorting, searching, and easy portability but getting IBM reports into these formats can be tricky without the right tools.

    The Solution:

    IBM i Reports can easily be converted to easy to read and share formats like Excel and PDF and Delivered by Email

    Converting IBM i, iSeries, and AS400 reports into Excel and PDF is now a lot easier with SpoolFlex software by DRV Tech.  If you or your users are still doing this manually, think how much time is wasted dragging and reformatting to make a report readable. How much time would be saved if they were automatically formatted correctly and delivered to one or multiple recipients.

    SpoolFlex converts spooled files to Excel and PDF, automatically emailing them, and saving copies to network shared folders. SpoolFlex converts complex reports to Excel, removing unwanted headers, splitting large reports out for individual recipients, and delivering to users whether they are at the office or working from home.

    Watch our 2-minute video and see DRV’s powerful SpoolFlex software can solve your file conversion challenges.

    Watch Video

    DRV Tech

    www.drvtech.com

    866.378.3366

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    BCD:  View our Webinar: How Prototypes Help Your Web Development Projects Succeed
    System i Developer:  Upgrade your skills at the RPG & DB2 Summit in Dallas, March 18-20.
    Northeast User Groups Conference:  24th Annual Conference, April 7 - 9, Framingham, MA

    More IT Jungle Resources:

    System i PTF Guide: Weekly PTF Updates
    IBM i Events Calendar: National Conferences, Local Events, and Webinars
    Breaking News: News Hot Off The Press
    TPM @ EnterpriseTech: High Performance Computing Industry News From ITJ EIC Timothy Prickett Morgan

    Moving Apps To The Cloud Saves Money, Users Say Systems Of Engagement

    One thought on “Quick And Handy RPG Output”

    • Ted Holt says:
      February 20, 2020 at 9:42 pm

      Free-form version of writeln:

      dcl-f qsysprt printer(132);

      dcl-proc writeln;
      dcl-pi *n;
      inString varchar(132) const;
      end-pi;

      dcl-ds ReportLine len(132) end-ds;

      ReportLine = inString;
      write qsysprt ReportLine;

      end-proc writeln;

      Reply

    Leave a Reply Cancel reply

Volume 14, Number 6 -- March 12, 2014
THIS ISSUE SPONSORED BY:

SEQUEL Software
WorksRight Software
Northeast User Groups Conference

Table of Contents

  • Who Needs Custom Perspectives In RSE?
  • Quick And Handy RPG Output
  • What Should I Monitor For On My IBM i Partition?

Content archive

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

Recent Posts

  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24
  • Big Blue Raises IBM i License Transfer Fees, Other Prices
  • Keep The IBM i Youth Movement Going With More Training, Better Tools
  • Remain Begins Migrating DevOps Tools To VS Code
  • IBM Readies LTO-10 Tape Drives And Libraries
  • IBM i PTF Guide, Volume 27, Number 23

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