• 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
    Fresche Solutions

    ON-DEMAND SESSION

    Protecting Your IBM i Systems from Ransomware and Other Cyber Threats

    Zero-day attacks and ransomware threats are on the rise and data that resides on IBM i is not immune. Now is the time to learn how to defend it.

    Join Marcel Sarrasin, CPO, Fresche and Pauline Brazil Ayala, VP of Operations, Trinity Guard as they introduce you to TGSuite, the next generation of IBM i security tools and dive into IFS and network security to help you learn how to configure the defenses on your system and guard your valuable data.

    In the session, Pauline and Marcel will discuss:

    • What a secure system looks like in 2022
    • Cybersecurity and auditing, data-level reporting and job activity monitoring
    • Advanced exit point security – knowing and managing who has access to your IBM i
    • Setting up alerts on critical security events as they happen
    • Managing all your LPARs from one centralized web console

    Watch Now!

    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

  • Guild Mortgage Takes The 20-Year Option For Modernization
  • IBM i Licensing, Part 3: Can The Hardware Bundle Be Cheaper Than A Smartphone?
  • Guru: The Finer Points of Exit Points
  • Big Blue Tweaks IBM i Pricing Ahead Of Subscription Model
  • We Still Want IBM i On The Impending Power E1050
  • DRV Brings More Automation to IBM i Message Monitoring
  • Managed Cloud Saves Money By Cutting System And People Overprovisioning
  • Multiple Security Vulnerabilities Patched on IBM i
  • Four Hundred Monitor, June 22
  • IBM i PTF Guide, Volume 24, Number 25

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 © 2022 IT Jungle

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.