• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • The Nearly Forgotten DSPLY Operation

    September 10, 2014 Paul Tuohy

    I am sometimes asked strange questions at conferences. A recent example is: “Which operation code do you use most in RPG?” After overcoming my initial reaction of wondering what the questioner was smoking (and where I could get some), I gave the question some thought. And the answer is: The DSPLY operation.

    Now, before you start to wonder what I am smoking (and where you can get some), let me explain. Firstly, the DSPLY operation will never see its way into production code, I only use it in test programs (more in a minute). Secondly, and what a lot of programmers have missed, the DSPLY operation can be used to input data as well displaying data. This means that I can avoid the necessity of display files for simple test programs.

    So, let’s talk about the DSPLY operation and how I use it.

    The DSPLY Operation

    The DSPLY operation may be used to communicate with a message queue. The operation can display a message or display a message and accept a response. The message may be a literal or may identify a message ID. The operation has the following format:

    DSPLY{(E)} {message {message-queue {response}}}
    

    The major restriction of the DSPLY operation is that the combined message and response may not exceed 52 characters.

    Full details may be found in the RPG Reference manual.

    Making Use Of DSPLY

    Nearly every program I write consists mainly of subprocedures. I try to keep my subprocedures simple, so they do one thing. This means, for the most part, that my testing consists of testing subprocedures, which is a simple process, pass parameters and check whether or not the correct values are returned.

    Therefore, a simple test program will prompt for parameters, call the subprocedure, and display the returned values.

    Let’s take a simple example. The next piece of code shows a subprocedure that accepts a single character field (Y or N) and returns a corresponding word (Yes, No, or ??? for an unidentified parameter value).

         p get_Word        b
         d                 pi             3a
         d  wordIn                        1a   const
    
         d wordOut         s              3a   inz('???')
    
          /free
           if (wordIn = 'Y');
              wordOut = 'Yes';
           elseIf (wordIn = 'N');
              wordOut = 'No';
           endIf;
           return wordOut;
          /end-Free
         p                 e
    

    Now let’s look at how the test program made use of the DSPLY operation program to get_Word() subprocedure.

          h dftActGrp(*no)
    
         d forChar         s              1a
         d showWord        s              3a
    
          /free
           doU (forChar = 'E');
              dsply 'Enter Character (E/Y/N/?)' '*EXT' forChar;
              if (forChar <> 'E');
                 showWord = get_Word(forChar);
                 dsply showWord;
              endIf;
           endDo;
          *inLR = *on;
          /end-Free   
    

    The logic of the program is very simple:

    • The program loops until the value of forChar is ‘E’.
    • Use the DSPLY operation to prompt for the character value (forChar). A value of ‘ ‘ could be specified for the message queue as opposed to “*EXT’.
    • Call the subprocedure to be tested.
    • Use the DSPLY operation to display the result of the call.

    Calling the test program and performing a test result in the interaction is shown here:

    DSPLY  Enter Character (E/Y/N/?)
    Y
    DSPLY  Yes
    DSPLY  Enter Character (E/Y/N/?)    Y
    N
    DSPLY  No
    DSPLY  Enter Character (E/Y/N/?)    N
    X
    DSPLY  ???
    DSPLY  Enter Character (E/Y/N/?)    X
    E
    

    There are a couple of points worth noting:

    • When the DSPLY operation with the response field is displayed, the current value of the response field is displayed. When the DSPLY is to the *EXT message queue, pressing enter means that the current value is retained. This means that you do not have to re-key values every time.
    • There is a caveat to using the DSPLY operation with the ‘*EXT’ message queue. If both the message and the response operands are displayed, the contents of both are displayed and the program waits for a response. But, when only the message operand is displayed, the program does not wait for a response unless a display file with the parameter RSTDSP (*NO) specified was used to display a format at the workstation. This means that the program will stop after every DSPLY operation if you call the program from within PDM but will only stop on DSPLY operations that require a response, if called from a “normal” command line.

    The 52-Character Problem

    A lot of the time, 52 characters is just not enough. In which case, you may find the subprocedure shown below to be of some use. The dsplyLong() subprocedure takes up to 5,200 characters of data and display them in 52-character chunks. Adjust the size of the parameter to suit your needs.

         p dsplyLong       b
         d                 pi
         d  longDataIn                 5200a   varying const
    
         d                 ds
         d  longData                   5200a
         d  show                         52a   dim(100) overlay(longData)
    
         d i               s             10i 0
         d times           s             10i 0
    
          /free
           longData = longDataIn;
           times = (%len(%trimR(longDataIn)) / %len(show(1)));
           if (%rem(%len(%trimR(longDataIn)): %len(show(1))) > 0);
              times += 1;
           endIf;
           for i = 1 to times;
              dsply show(i);
           endFor;
          /end-Free
         p                 e
    

    Lots Of Test Programs

    I have hundreds of little test programs like these on my system. Whenever I need to change a subprocedure, I have a test program to hand to check my changes.

    Although DSPLY may not be the most elegant operation code in existence and may not be up to production standards, it definitely does the job for me when it comes to simple interfacing and saves me the hassle of defining more complex interfaces for simply promoting for parameters and showing results.

    Alternatively, you may want to make use of the QUILNGTX API to display long text. You can find a description of how to do that in my article A Better Way to Display Quick 5250 Messages in RPG.

    Paul Tuohy is CEO of ComCon, an iSeries consulting company, and is one of the co-founders of System i Developer, which hosts the RPG & DB2 Summit conferences. He is an award-winning speaker who also speaks regularly at COMMON conferences, and is the author of “Re-engineering RPG Legacy Applications,” “The Programmers Guide to iSeries Navigator,” and the self-study course called “iSeries Navigator for Programmers.” Send your questions or comments for Paul to Ted Holt via the IT Jungle Contact page.

    RELATED STORY

    A Better Way to Display Quick 5250 Messages in RPG



                         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
    Rocket Software

    Software built on TRUST. Delivered with LOVE.

    For over 35 years, Rocket Software’s solutions have empowered businesses to modernize their infrastructure, unlock data value, and drive transformation – all while ensuring modernization without disruption.

    Learn More

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    Profound Logic Software:  October 1 Webinar: "See What i Can Do with Mobile Applications"
    System i Developer:  Upgrade your skills at the RPG & DB2 Summit in Minneapolis, Sept 30 - Oct 2.
    COMMON:  Join us at the COMMON 2014 Fall Conference & Expo in Indianapolis, Oct 27-29

    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

    JD Edwards Gets 57 New Mobile Apps Actifio Takes Unique Storage Approach to the Cloud

    Leave a Reply Cancel reply

Volume 14, Number 20 -- September 10, 2014
THIS ISSUE SPONSORED BY:

CCSS
ProData Computer Services
WorksRight Software

Table of Contents

  • The Nearly Forgotten DSPLY Operation
  • DB2 for i 7.2 Features and Fun: Part 3
  • Admin Alert: Importing IBM i Spooled Files Into Excel

Content archive

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

Recent Posts

  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20
  • POWERUp 2025 –Your Source For IBM i 7.6 Information
  • Maxava Consulting Services Does More Than HA/DR Project Management – A Lot More
  • Guru: Creating An SQL Stored Procedure That Returns A Result Set
  • As I See It: At Any Cost
  • IBM i PTF Guide, Volume 27, Number 19

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