24
Wed, Jul
0 New Articles

Practical RDPi: Filters for Fun (and Productivity)

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

Some jobs are too tricky to leave to your computer unsupervised, but RDPi has tools that speed up even the most tedious of programming tasks.

 

A computer will do exactly what you tell it to do, no matter how much that request might defy common sense. A perfect example of that truism is the ubiquitous and sometimes dangerous "find and replace." You can tell any decent source-editing tool to replace all instances of the field name CUSNAM with CUSNME and it will dutifully do exactly that, and thanks to the cryptic nature of field names in RPG, the chances are that the execution will be flawless. However, use find and replace enough and you will eventually run into a situation where the editor replaces things you really didn't want replaced. This article shows you how to combine a couple of features of Rational Developer for Power Systems Software for IBM i (RDPi) to create a semi-automated find and replace mechanism.

Do What I Mean, Not What I Say!

At the end of the day, programming boils down to telling a computer to execute an intricate series of very specific steps. Having a six-year-old, I can attest to the similarities between a very powerful but very literal computer and a grade-schooler jazzed on strawberry donuts (it's that time of year here in Illinois, but I digress). Attention to the smallest detail is critically important: even if you tell a first-grader to put on clothes and carefully specify both outer clothes and underwear, but forget to precisely identify the order of said apparel, you are liable to end up with a child who either will be sent home to change or will start a new fashion trend for rap singers. The same holds true for a computer—in this case, the find and replace function.

 

Let me show you an example.

 

070710PlutaFigure1

Figure 1: This simple program retrieves the address information from an order. (Click images to enlarge.)

 

In Figure 1, you see a simple program that takes an order number and then chains out to the customer order history file to get the address information for the customer. It mostly involves a couple of moves, but also a little formatting. There are other ways to do this, such as using qualified data structures and EVAL-CORR, but this example suffices for today's purpose.

 

The business problem is that the CUORDHST file is being changed. Rather than being the customer order history file, it is going to be a more generic order history file, ORDHIST. In keeping with the file rename, all fields in the file will be renamed, and rather than having the prefix CH, they will instead start with OH. The field CHNAME, for example, will become OHNAME. This seems relatively straightforward, and a simple find and replace of CH to OH ought to work; that is, until you look at line 002000. Your CHAIN operation will be transformed into OHAIN, which won't compile. Interestingly, this isn't the worst problem. Since this won't compile, you'll find the problem right away. Other more subtle errors can be introduced, from changes in text literals to changes in comments. The point is that a fully automatic find and replace function isn't always perfect.

Semi-Auto vs. Fully Automatic

How do we get around the problem? RDPi provides a way of inserting yourself into the flow of find and replace. It consist of two separate techniques that, combined, make for a very productive large-scale replacement mechanism. The first part is fairly common to most text editors: you can do one change at a time.

 

070710PlutaFigure2

Figure 2: The Find and Replace dialog provides buttons to change one instance at a time.

 

Figure 2 shows the Find and Replace dialog. You can see the buttons Next, Previous, and Replace, which allow you to move through the source file one change at a time (as opposed to the Replace All button, which replaces every occurrence of the Find string). This is a somewhat primitive but functional alternative, and it's what most editors provide. However, the problem is that often (in larger programs especially) the lines are some distance apart and it's not always clear which lines you need to change. So you have to go through the tedious task of hitting Next, jumping to the next section of code, determining if this line needs to change, and then moving on to the next occurrence.

 

Wouldn't it be nice if you could filter the view so that you saw only lines eligible for change? As you might guess, RDPi provides just such a technique. If you click on the All button (not Replace All!), you'll see the results in Figure 3.

 

070710PlutaFigure3

Figure 3: Hitting the All button filters the view to show only lines containing the Find text.

 

This is pretty significant. While the example I showed today is obviously trivial, imagine one of those 27,000-line programs that has been converted twice (first from S/38, then to ILE RPG). You could easily see every line that might need to be changed and then spin through them. This is a standard RDPi filter view, with the plus signs (+) on the left of the source allowing you to expand or contract sections of the code as needed to get context. In fact, the filter is so standard that you don't need to go into the Find and Replace dialog to get it. Figure 4 shows how to execute the same filter using the standard right-click Context menu in the source.

 

070710PlutaFigure4

Figure 4: You can use the Context menu to filter by selected text as well.

 

To filter the source, first select the text you want to filter by. This is really easy for fields and files and the like; you can usually just double-click on the name and RDPi is smart enough to isolate it from its surroundings. But even if you can't—as in this case, where you want to filter the first two characters of a field name—just use the standard keyboard or mouse controls to mark the text you want to filter by. Then, just right-click in the source to bring up the Context menu and choose menu option Selected, sub-menu option Filter Selection. You will see the same filtered view you saw using the All button, although without the Find and Replace dialog.

 

One last point: You may notice a difference between your screen and the one in the article. In Figure 4, you'll see that the Filter selection sub-option has the text "Alt-F" to the right, which indicates that the command has a shortcut, Alt-F. Yours probably doesn't have that, because I created the shortcut myself. I used the Preferences menu to add my own User Action that binds the Alt-F key to the filter selection action. Now, I can just mark some text and then hit Alt-F to filter the source. That's just a little trick that I'll cover in more detail in the next installment of "Practical RDPi."

 

Joe Pluta

Joe Pluta is the founder and chief architect of Pluta Brothers Design, Inc. He has been extending the IBM midrange since the days of the IBM System/3. Joe uses WebSphere extensively, especially as the base for PSC/400, the only product that can move your legacy systems to the Web using simple green-screen commands. He has written several books, including Developing Web 2.0 Applications with EGL for IBM i, E-Deployment: The Fastest Path to the Web, Eclipse: Step by Step, and WDSC: Step by Step. Joe performs onsite mentoring and speaks at user groups around the country. You can reach him at This email address is being protected from spambots. You need JavaScript enabled to view it..


MC Press books written by Joe Pluta available now on the MC Press Bookstore.

Developing Web 2.0 Applications with EGL for IBM i Developing Web 2.0 Applications with EGL for IBM i
Joe Pluta introduces you to EGL Rich UI and IBM’s Rational Developer for the IBM i platform.
List Price $39.95

Now On Sale

WDSC: Step by Step WDSC: Step by Step
Discover incredibly powerful WDSC with this easy-to-understand yet thorough introduction.
List Price $74.95

Now On Sale

Eclipse: Step by Step Eclipse: Step by Step
Quickly get up to speed and productivity using Eclipse.
List Price $59.00

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: