29
Fri, Nov
0 New Articles

Word Wrap: Green-Screen Pagination

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

I must admit, I haven't written any new 5250 green-screen applications for a while. Most of my work has entailed doing Web browser-based applications and, of course, the infamous file maintenance applications.

But recently, I needed to create a new application for a handheld scanner that uses a Telnet emulator. The screen is small, and most applications that run on it have been designed to work with the 40-column by 12-row screen dimensions.

When I ran the application, I discovered that if a message is sent to the device, either by an application or by the system, particularly an inquiry message, all bets are off. The end user has to manually scroll the screen to see the message. Of course, the end users' skill in using iSeries/i5 applications is virtually nonexistent, so it's a challenge for them to continue working when a message is sent.

I remembered that back in the days of Q38 I designed the first windowed 5250 application using DDS. One of the biggest problems was word wrapping/pagination, i.e., the ability to adjust the output of a text field so that the breaks in the text appear on the space between the words, rather than at a fixed location.

I had written a word-wrap routine, and thought I could locate it and use it for this particular problem. So I fired up my old AS/400 Model 400 that I keep on OS/400 V3R7 (mostly because I can't afford to upgrade it) and began searching for my old code.

As the system was IPLing, I began flipping through the OS/400 V4R2 DDS manual, and just for the heck of it, I looked up "word wrap" in the index. To my astonishment, I found it!

The WRDWRAP keyword automatically paginates an input field. I thought that would be a showstopper, but by definition, a Both field is also an Input field, so I could simply create a field as Both (i.e., input and output) on my display file and then use the "protect" attribute to make it output-only. Fortunately, this worked.

I also knew IBM had added the Continued Field keyword a long time ago, and I thought that if I could use that, I could effectively create a little text box within a window that might fit on my 40-by-12 devices.

Continued Fields

A continued field is a long text field that is wrapped to multiple lines. You provide the field's overall length and the "line size." Then the system wraps the field over multiple lines, each to the length you've specified.

To create a continued field, use the CNTFLD keyword as follows:

A            MSGTEXT      320A  B  1  2 CNTFLD(40)

In this example, the field named MSGTEXT is 320 positions long. The CNTFLD keyword indicates that 40 characters per line are allowed. This means the MSGTEXT field will occupy 8 lines (320/40) of 40 characters each.

Word Wrap

The bad news is that CNTFLD alone will give you little more that what we already had, positional wrap. As you type, the text will wrap to the field, based on the line length and character position, not based on the content of the field itself. This provides somewhat unpleasant looking data.

Enter WRDWRAP. This keyword will cause the wrapping of the text in the continued field to be at the location of a space (i.e., between words). This provides a much more attractive look to the data.

Remember, WRDWRAP may be used only on an input-capable field, so the field must be "I" (input only) or "B" (input/output or "Both"); output-only fields are not supported by WRDWRAP.

To use the WRDWRAP keyword, simply specify it at the record format level or on the specific field itself, as follows:

A            MSGTEXT      320A  B  1  2 CNTFLD(40)
A                                       WRDWRAP

In the example, the MSGTEXT field will now be word wrapped while typing or when text is output to the field. This is exactly what I needed.

Of course, my requirement was to have output-only text. To accomplish this, I had to add the DSPATR(PR) keyword as follows:

A            MSGTEXT      320A  B  1  2 CNTFLD(40)
A                                       DSPATR(PR)
A                                       WRDWRAP 

This causes the field to be output only, but it still fulfills the requirements of WRDWRAP by being both input- and output-capable.

There is one thing still missing, however. The output is underlined. This isn't what I wanted (but you may want an underlined appearance).

To get rid of the underline, I simply added the CHGINPDFT keyword to the field itself:

A            MSGTEXT      320A  B  1  2 CHGINPDFT 
A                                       CNTFLD(40)
A                                       DSPATR(PR)
A                                       WRDWRAP 

Ah, perfection! Now, I have an output field that paginates within the dimensions of the device limitations. Next, all I have to do is put this inside a window.

When I create a window, I often omit the border because the 5250 emulators today use a nice drop shadow box as the default border for windows. A window with periods and colons as a border was interesting in 1987 but is just ugly today.

Here's the window definition:

A          R MSGREC
A                                      WINDOW(*DFT 10 40 *NOMSGLIN)
A                                      USRRSTDSP

The *DFT parameter on the WINDOW keyword causes the window to be located relative to the cursor location. This isn't good enough for what I needed, so adding an absolute location was required. And don't ask me what USRRSTDSP does; I just use it now in place of all the PUTOVR and OVRATR keywords, which I never fully understood anyway, and it seems to work OK.

CL Break Handler

Designing an output window and word wrapping was only half the battle. Next was remembering how to code a break message handler. Fortunately, I'm still good friends with Greg Veal, so I called him up for the answer. He suggested I look in his book CL Programming for the AS/400. Within two minutes, I located and was able to review how to create a simple break message handling program.

A break handler is a program that is called when a break message (such as an inquiry message) is sent to the display. Instead of breaking in on the device, the break handling program is called and passed just enough information to be useful.

The break handler is passed to the Message Queue and Message Queue Library names, along with the so-called "message key." Each message delivered to a message queue has a unique key associated with it. You can retrieve, remove, and reply to a message by its message key.

These three pieces of information are passed to your break handling program as three separate parameters:

Parameter
Attributes
Definition
MSGQ
Char(10)
The name of the message queue whose message called this break-handling program
MSGQLIB
Char(10)
The message queue's library name
MSGKEY
Char(4)
The unique message key for the message that called this break-handling program

In CL, you might code these parameters as follows:

 MYBRKHDLER: PGM       PARM(&MSGQ &MSGQLIB &MSGKEY)
             DCL        VAR(&MSGQ) TYPE(*CHAR) LEN(10)
             DCL        VAR(&MSGQLIB) TYPE(*CHAR) LEN(10)
             DCL        VAR(&MSGKEY) TYPE(*CHAR) LEN(4)

Once your break-handling program is called, you can do anything you want, but it would be good to do something with the message that evoked the program.

To receive the actual message, use the RCVMSG command as follows:

 RCVMSG     MSGQ(&MSGQLIB/&MSGQ) MSGKEY(&MSGKEY) +
              RMV(*NO) MSG(&MSGTEXT) RTNTYPE(&MSGTYPE)

The &MSGTEXT variable is the field we've specified on our display file (in the window). The &MSGTYPE variable is 2-byte code that indicates the type of message that is being received.

Once we receive the message, we can display its text in our continued/word-wrapped field within the window on the handheld device, thereby avoiding the scrolling screen problem we were encountering

Figure 1contains the full DDS source for the word-wrap text in a window display file named MSGWINDOW. Note the extra "dummy" format that is used to avoid having the system clear the screen as the window pops up. This is useful on regular displays because it provides that overlapping look and feel people are used to.

A                                      INDARA
A          DUMMY                     KEEP ASSUME PUTOVR
 88N88                           1  2' '
A          MSGREC
A                                      WINDOW(*DFT 10 40 *NOMSGLIN)
A                                      USRRSTDSP
A                                      CA03(03)b
A                                      CA13(13)
A                                      CA11(11) 
A                                      CA12(12)
A            MSGTEXT      320A  B  1  1CHGINPDFT 
A                                      CNTFLD(40) 
A                                      WRDWRAP
A                                      DSPATR(PR)
A                                  9  2'Reply->' 
A            REPLY         30A  B  9 10CHECK(LC) 
A                                 10  3'F3=Exit'
A                                      COLOR(TRQ)
A                                 10 15'F11=Remove'
A                                      COLOR(TRQ)
A                                 10 30'F12=Cancel'
A                                      COLOR(TRQ)

Figure 1: This is the display file DDS for the pop-up window.

Listed in Figure 2 is some example CL source for a break-handling program that pops up the message window. In addition, the program reacts to standard DSPMSG-like function keys including F3, F11, F12, and F13, performing the same type of function.

 RTKMSGPGM:  PGM       PARM(&MSGQ &MSGQLIB &MSGKEY)
             DCL        VAR(&MSGQ) TYPE(*CHAR) LEN(10)
             DCL        VAR(&MSGQLIB) TYPE(*CHAR) LEN(10)
             DCL        VAR(&MSGKEY) TYPE(*CHAR) LEN(4)
             DCL        VAR(&MSGTYPE) TYPE(*CHAR) LEN(2)
             DCL        VAR(&JOBTYPE) TYPE(*CHAR) LEN(1)

             DCLF       FILE(MSGWINDOW)

             RCVMSG     MSGQ(&MSGQLIB/&MSGQ) MSGKEY(&MSGKEY) +
                          RMV(*NO) MSG(&MSGTEXT) RTNTYPE(&MSGTYPE)
             RTVJOBA    TYPE(&JOBTYPE)
             IF         COND(&JOBTYPE *EQ '1') THEN(DO)
               IF         COND(&MSGTYPE *EQ '05'  *OR  +
                               &MSGTYPE *EQ '04') THEN(DO)
                 SNDRCVF    RCDFMT(MSGREC)
                    IF         COND(&IN03 *EQ '1' *OR +
                                    &IN12 *EQ '1') THEN(DO)
                      GOTO ENDPGM
                    ENDDO
                    IF         COND(&IN13 *EQ '1') THEN(DO)
                      CLRMSGQ    MSGQ(&MSGQLIB/&MSGQ) CLEAR(*KEEPUNANS)
                    ENDDO
                    IF         COND(&IN11 *EQ '1') THEN(DO)
                      RMVMSG     MSGQ(&MSGQLIB/&MSGQ) MSGKEY(&MSGKEY)
                    ENDDO
                 IF         COND(&REPLY *NE ' ') THEN(DO)
                    SNDRPY     MSGKEY(&MSGKEY) MSGQ(&MSGQLIB/&MSGQ) +
                                 RPY(&REPLY)
                 ENDDO
               ENDDO
             ENDDO
 ENDPGM:     ENDPGM

Figure 2: This break-handling program pops up the message window.

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.

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

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

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

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • 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

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

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