29
Fri, Nov
0 New Articles

Modifying a Subfile: Change Is Good, Part 1

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

Subfiles aren't just for displaying data. They're also extremely useful for modifying the data in your data files. As a matter of fact, some of the most powerful subfile programs you'll write are ones that contain update, add, and delete capabilities.

Written by Kevin Vandever

 

Editor's Note: This article is an excerpt from the book Subfiles in Free-Format RPG.

 

In this article, you'll learn one way to modify data files using subfiles. This technique lets you update, add, and delete from a name file, which I'll call "Name Master File Maintenance." You can use this program as a template for any name-type master file, such as a customer, salesperson, or vendor file. The program will introduce two DDS keywords, an RPG operation code, and a familiar RPG operation with a new use.

SFLNXTCHG, READC, AFLRCDNBR…And CHAIN and UPDATE, Too

The Subfile Next Change (SFLNXTCHG) keyword is used to mark subfile records as changed. There are times when your program will modify the contents or attributes of a subfile record before displaying the subfile back to the user. If you want IBM i to recognize those changes, use SFLNXTCHG. For instance, let's say the user types some information into a subfile record. To determine its validity, your program interrogates the information. If the information is incorrect, you might want to display an error message and highlight the incorrect field.

 

Using the SFLNXTCHG keyword, you can mark a subfile record as changed so that no matter what the user does when the subfile is redisplayed on the screen, the program recognizes the record as changed and tries to revalidate it. Without SFLNXTCHG, you could still warn the user something is wrong, but if he or she chooses to ignore the incorrect record, your program has no knowledge that it needs to be revalidated.

 

You do not need SFLNXTCHG for IBM i to recognize that a user has made a change to a subfile record. The system will mark the subfile record as changed whenever a user changes the data in that record. However, if you want to change data in a subfile record from within your program and mark that record as changed, you need to use SFLNXTCHG in your subfile record format and condition it on an indicator.

 

The SFLRCDNBR (Subfile Record Number) keyword lets IBM i know which page of data to display. If you have a subfile with 10 pages of data and you want to display record 38 of that subfile, SFLRCDNBR enables you to display the page containing that record. You'll learn more about each of these keywords in the upcoming program.

 

The last thing I'll introduce at this point that's related to subfiles is the READC operation code. READC reads changed records from a subfile. It reads both records that have been changed by the user and those that are changed in the program and marked as changed by setting on the indicator-conditioning SFLNXTCHG keyword.

 

The DDS for the subfile (SFL1) and subfile control (SF1CTL) record formats in the Name Master Maintenance program (SFL004DF) look much like those of a self-extending subfile—because that's what it is. In the code in Figure 1, notice that I have no ROLLDN keyword defined in the subfile control record format—IBM i will take care of the rolling down for me. Because SFLSIZ is greater than SFLPAG, the subfile will be allowed to expand if the user wants it to. The OS will handle the paging down, except when new records are added to the subfile. In that case, it will be done by the program.

 

A         R SFL1                     SFL

 

A*

 

A 74                                 SFLNXTCHG

 

A           DBIDNM   R       H     REFFLD(PFR/DBIDNM *LIBL/SFL001PF)

 

A           OPTION         1A B 10 3VALUES(' ' '2' '4' '5')

 

A           DBLNAM   R       O 10 7REFFLD(PFR/DBLNAM *LIBL/SFL001PF)

 

A           DBFNAM   R       O 10 31REFFLD(PFR/DBFNAM *LIBL/SFL001PF)

 

A           DBMINI   R       O 10 55REFFLD(PFR/DBMINI *LIBL/SFL001PF)

 

A           DBNNAM   R       O 10 60REFFLD(PFR/DBNNAM *LIBL/SFL001PF)

 

A         R SF1CTL                   SFLCTL(SFL1)

 

A*

 

A                                     CF06

 

A                                     SFLSIZ(0013)

 

A                                     SFLPAG(0012)

 

A                                    ROLLUP

 

A                                     OVERLAY

 

A N32                                 SFLDSP

 

A N31                                 SFLDSPCTL

 

A 31                                 SFLCLR

 

A 90                                  SFLEND(*MORE)

 

A           RRN1           4S 0H     SFLRCDNBR

 

A                                 9 7'Last Name'

 

A                                     DSPATR(HI)

 

A                                 9 31'First Name'

 

A                                      DSPATR(HI)

 

A                                 9 55'MI'

 

A                                     DSPATR(HI)

 

A                                 9 60'Nick Name'

 

A                                     DSPATR(HI)

 

A                                  1 2'SFL004RG'

 

A                                 1 71DATE

 

A                                     EDTCDE(Y)

 

A                                 2 71TIME

 

A                                 1 24'Subfile Program with Update     '

 

A                                      DSPATR(HI)

 

A                                 4 2'Position to Last Name . . .'

 

A           PTNAME       20A B 4 30CHECK(LC)

 

A                                 9 2'Opt'

 

A                                     DSPATR(HI)

 

A                                  6 2'Type options, press Enter.'

 

A                                     COLOR(BLU)

 

A                                 7 4'2=Change'

 

A                                     COLOR(BLU)

 

A                                 7 19'4=Delete'

 

A                                     COLOR(BLU)

 

A                                 7 34'5=Display'

 

A                                     COLOR(BLU)

Figure 1: Subfile control and record formats for the Name Master Maintenance program

 

Notice the SFLNXTCHG and SFLRCDNBR keywords in the code, entered in the subfile record format (SFL). SFLNXTCHG is used in the subfile record format (SFL1) and conditioned with indicator 74. This is the indicator I will manipulate in my RPG program to mark subfile records that have been changed not by the user, but by my program. IBM i marks user changes automatically.

 

Keyword SFLRCDNBR is used with the relative record number field (RRN1) in the subfile control record (SFLCTL). When you implement SFLRCDNBR, the OS will determine on which page the current relative record number sits and cause your program to display that page. Because I want the user to return to where he or she left off when making a change to a particular subfile record, this will be important.

 

The other thing you'll notice about the DDS is that it now has something other than output or hidden fields defined in the subfile record format. This program defines a field as "B" for both input and output that allows users to select specific options. Each option corresponds to a specific action to perform in the program. The VALUES keyword tells IBM i the valid options that can be entered. Any other options give a warning error. Now, instead of simply displaying data in the subfile, users have the chance to do something with this data.

 

Figure 2 shows the screen this DDS will produce. Users have a couple of different options from which to choose. They can scroll through the data or establish a position to somewhere else in the subfile. If the desired data is on the page a user is looking at, he or she can press 2 to edit the record, 5 to display it, or 4 to delete it.

 

061114Vandever5104 part01 fig01

 

Figure 2: Sample update subfile screen

 

This brings me to the last new thing about this DDS, which is the second subfile. Yes, you can code multiple subfiles in a display file. However, only 24 of your subfiles can be active at one time, and only 12 can be displayed on a single screen. This second subfile, which is very basic and introduces nothing new, is of the load-all nature. I use it to display a confirmation screen before a user deletes records from the data file. Figure 3 shows the DDS code for this second subfile.

 

A         R SFL2                     SFL

 

A*

 

A           DBIDNM   R       H     REFFLD(PFR/DBIDNM *LIBL/SFL001PF)

 

A           DBLNAM   R       O 7 3REFFLD(PFR/DBLNAM *LIBL/SFL001PF)

 

A           DBFNAM   R       O 7 29REFFLD(PFR/DBFNAM *LIBL/SFL001PF)

 

A*

 

A*

 

A         R SF2CTL                   SFLCTL(SFL2)

 

A*

 

A                                     SFLSIZ(0016)

 

A                                     SFLPAG(0015)

 

A                                    SFLDSP

 

A 41                                 SFLCLR

 

A N41                                 SFLDSPCTL

 

A N41                                 SFLEND(*MORE)

 

A                                     OVERLAY

 

A           RRN2           4S 0H

 

A                                  3 3'Press Enter to confirm your choice-

 

A                                     s for Delete.'

 

A                                     COLOR(BLU)

 

A                                 4 3'Press F12=Cancel to return to chan-

 

A                                      ge your choices.'

 

A                                     COLOR(BLU)

 

A                                 6 3'Last Name'

 

A                                     DSPATR(HI)

 

A                                 6 29'First Name'

 

A                                     DSPATR(HI)

 

A                                 1 28'Confirm Delete of Records'

 

A                                     DSPATR(HI)

Figure 3: Subfile control and record formats for delete confirmation

 

You've now seen the DDS and sample screen used to let a user update, add, and delete from a name file. In Part 2, we will move on to the RPG code. See you then!

 

 

Kevin Vandever

Kevin Vandever began his information technology career in 1984. Once a young, promising RPG programmer and consultant, he cranked out code, spoke at conferences, wrote articles, penned columns, and published the occasional book. Then, he moved into management. Now Kevin reviews code, approves conferences, and occasionally reads articles, columns, and books. His days are filled with words and phrases like “budgets,” “status,” “deadlines,” and “resource constraints” and no longer with technically charged words and phrases such as “loop,” “pointer,” “compile,” and “Who needs to test?” But no matter how far into management he’s gone, Kevin still finds time to interject into every single technical discussion—no matter what the technology, language, or system—the point that the issue could probably be solved using subfiles in RPG. Kevin blogs at kevinvandever.com and can be followed on Twitter at @kevinvandever.


MC Press books written by Kevin Vandever available now on the MC Press Bookstore.

Subfiles in Free-Format RPG Subfiles in Free-Format RPG
Become a subfile master with the concepts, styles, examples, and advanced techniques you’ll find in this book.
List Price $79.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: