Tips and Techniques: Displaying the Console

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

If you've ever tried to read a 5250 device as a series of text lines scrolled up the screen like an old teletype machine or TRS-80 computer, then you've witnessed the console or "terminal" mode as it's called on the iSeries. Spotting the text that is displayed on the console is sort of like experiencing a Big Foot sighting. It happens quickly, and nobody really believes you saw it; in fact, you often don't believe it yourself.

Just to give you a frame of reference, Figure 1 illustrates the command line that appears at the bottom of the console window.


http://www.mcpressonline.com/articles/images/2002/Tips%20and%20Techniques11160500.jpg

Figure 1: This command line appears at the bottom of the console/terminal mode window. (Click image to enlarge.)

A good example of displaying the console is when you run a CGI program from command entry. The HTML often races up the screen and then returns you to the command entry screen--no HTML is visible at that point, of course. Did it really appear, or were you seeing things?

It would be great if IBM offered a DSPCONS or DSPTERM or similar command that would display the console. But they don't.

One of the biggest requests lately with regard to the console has been to be able to stop the console's seemingly endless ability to scroll text on the screen and return to command entry without stopping--a "wait a minute" command, if you will.

Well, once again, it's RPG IV to the rescue...well, the C runtime being used by RPG IV anyway.

The C runtime function getchar() waits on the console or terminal for the end user to press Enter. Fortunately, this C function also displays the current content of the console, allowing you to use the function keys identified in Figure 1 as well as the PageUp/PageDown keys.

The prototype for getchar is remarkably easy:

     D GetChar         PR            10U 0 ExtProc('getchar')

Note that there are no parameters for getchar(), and the return value, which returns the character typed in by the end user, is ignored for our purposes.

Once the prototype is created, you can write a simple little RPG IV program named DSPCONS (or whatever) and compile it. Here's an example:

 H BNDDIR('QC2LE')  DFTACTGRP(*NO)                           
 H OPTION(*SRCSTMT) ACTGRP(*NEW)                             
 D GetChar         PR            10U 0 ExtProc('getchar')    
 C                   callp     GetChar                       
 C                   EVAL      *INLR = *ON                   
 C                   return                                  

This program is named DSPCONS. If we call this program from command entry, the console is displayed, and we can scroll through it and see all the data that's been posted to the console.

And the best part is it waits until we press Enter before returning! Pretty cool, huh?

Bob Cozzi is a programmer/consultant, writer/author, and software developer of the RPG xTools, a popular add-on subprocedure library for RPG IV. His book The Modern RPG Language has been the most widely used RPG programming book for nearly two decades. He, along with others, speaks at and runs the highly-popular RPG World conference for RPG programmers.

BOB COZZI

Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.


MC Press books written by Robert Cozzi available now on the MC Press Bookstore.

RPG TnT RPG TnT
Get this jam-packed resource of quick, easy-to-implement RPG tips!
List Price $65.00

Now On Sale

The Modern RPG IV Language The Modern RPG IV Language
Cozzi on everything RPG! What more could you want?
List Price $99.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: