• 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:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) Email

    Tags:

    Sponsored by
    i-Rays

    i‑Rays learns how your IBM i behaves; not just how it performs. Detect deviations hours before incidents form and eliminate alert fatigue with true behavioral observability.

    Traditional monitoring tells you when something breaks. i‑Rays tells you why it’s about to break. By baselining behavioral patterns across jobs, subsystems, and queues, i‑Rays highlights the most likely root cause long before users feel the impact. It’s proactive, noise‑free, and built for mission‑critical IBM i environments.

    Request a Demo

    Share this:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) 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

    Who Needs Custom Perspectives In RSE? What Should I Monitor For On My IBM i Partition?

    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 ReplyCancel 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

  • IBM Goes GA With Power Autonomous Operations
  • IBM Wheels And Deals To Sell Power Systems, Storage, and Software
  • Guru: When RNF0722 Won’t Let Your Legendary RPG Program Compile
  • A Read-Only MCP Server For Db2 for i
  • IBM i PTF Guide, Volume 28, Number 35
  • Please Take The IBM i Marketplace Survey So We Know What You Know
  • IBM’s Bob AI Assistant Can Now Live In Your Datacenter
  • Start Where the Data Lives: Best Practices for Taking IBM i Into AI
  • Guru: A Modernization Experiment Using IBM Bob 2.0
  • How Are IBM i Shops Using AI? Fortra and COMMON Want to Know

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