26
Fri, Apr
1 New Articles

HOT TIPS: Programming (16 Tips)

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

Programming

Free Tools!

The QUSRTOOL library has many unique programs and commands to provide tools which are otherwise not a part of your operating system. QUSRTOOL is not supported as a normal part of the operating system. You cannot call software support and report a bug. To order the QUSRTOOL update or report a bug in one of the tools, have your System Engineer send a note to QUSRTOOL on RCHASA04.

- Tim Johnston

Dynamic Source Member Manipulation

Source physical files may be processed in RPG like a normal database file. This allows a simple method of creating your own tools to provide documentation or even manipulate members. For instance, prior to running FMTDTA the sort specs could be updated with run-time options.

Decimal data errors from "fields" with leading blanks can be avoided by defining them as character and doing a MOVE into the same size numeric field. In RPG, this performs the near equivalent of a "fix decimal data error" compiler option.

- Douglas Handy

A Better DSPPFM

Here's a way that I can view data in a physical file instantly. An alternative to DSPPFM with some attractive benefits is the RUNQRY command. On any command line, type the following:

RUNQRY *NONE libname/filename

A formatted display of the file contents appears. If you prompt RUNQRY command, other parameters allow for record selection and spooling to *PRINT.

- Cynthy Johnson

Formatted Record Dumps

Here's a way to get a formatted dump of records in a physical or logical file:

On any command line type the following:

CPYF LIBNAME/FILENAME TOFILE(*PRINT)

All records in the PF or LF are printed in CHAR format.

CPYF LIBNAME/FILENAME TOFILE(*PRINT) OUTFMT(*HEX)

All records in the PF or LF are printed in CHAR and HEX.

But wait....there's more!!! If you specify a LOGICAL file name, the records are printed in their logical access path order! I use this to help check for duplicate keys. All the select/option parameters of CPYF apply, so you don't have to print all records if the file is very large.

- Cynthy Johnson

What's This Program's Name?

Don't hard-code program names. A CL program can obtain its own name via the following code fragment:

 DCL VAR(&SENDER) TYPE(*CHAR) LEN(80) DCL VAR(&PGM) TYPE(*CHAR) LEN(10) DCL VAR(&MSGKEY) TYPE(*CHAR) LEN(4) SNDPGMMSG MSG(' ') TOPGMQ(*SAME) MSGTYPE(*INFO) + KEYVAR(&MSGKEY) RCVMSG PGMQ(*SAME) MSGTYPE(*INFO) SENDER(&SENDER) + RMV(*YES) MSGKEY(&MSGKEY) CHGVAR VAR(&PGM) VALUE(%SST(&SENDER 56 10)) 

RPG programs can obtain their names from the program status data structure:

 ....1....+....2....+....3....+....4....+....5....+....6....+ I SDS I *PROGRAM PGM -or- I 1 10 PGM ....1....+....2....+....3....+....4....+....5....+....6....+ 

- Bryan Leaman

QRYF User Tool

If you have trouble figuring out OPNQRYF string structure, a command in QUSRTOOL called QRYF can help. This command makes the select criteria easier. If you still want to use OPNQRYF instead, run QRYF and after it has run, check the job log. The log will show you the OPNQRYF command structure QRYF created for you. QRYF creates a SNDPGMMSG with the correct OPNQRYF structure inside of it. It's a great way to learn OPNQRYF.

- Dean Hoffman

Two Queries are Better Than One

To improve performance of Query/400 where large files (over 100,000 records) are joined, use paired queries. The first query selects records and uses a database file for output (the choice of "data in file" option is important here). The second query uses the file created by the first query and sorts it, using either a printer or another database file for output. Our query performance improved three to one using this method.

- Debbie DeDuck

Don't Use LDA to Pass Parameters

When submitting a program for processing in batch, pass any data as parameters to the program CALL instead of using the *LDA. This allows you to determine what options were selected for the job by looking at the job log. It also minimizes the possibility of overwriting data in the *LDA written out by third-party software and it eliminates the need to retrieve the information from the *LDA in the batch CL. For example:

SBMJOB CMD(CALL PGM(BPGM01) PARM(&PARM1 &PARM2 ...))

- William MacKenzie Picou

Search Indexes Galore

The Start Search Index (STRSCHIDX) command which supports keyword searches is available for specific areas of interest:

 Search Index Library Name Utilities QPDA QHPW1 Query QQRYLIB QHQU1 RPG QRPG QHRG1 Office Vision QOFC QHWP1 RJE Comm. QRJE QHRJE 

(Be sure you have authority and that the library is included in your library list.)

- Charles S. O'Rourke, III

Manuals at Your Fingertips

Copy Chapter 7 of the System Programming Reference Summary (Error Messages That Can Be Monitored) from the CD-ROM to a DOS file. Then upload to a source member on the AS/400. The next time you need to know what message to monitor for, use the SEU browse and scan facility to check.

I'll never understand why IBM didn't include this as part of the command prompter or help text!

- Brian Coyle

Subfiles with Pizzazz

While subfiles can be very powerful in how they handle information, in some circumstances they are very limiting. For example, consider a screen design that would display multiple customers and their invoices. This could possibly be done with a fold but the information would be redundant from line to line for a single customer.

The trick that I use is to make a subfile with one field that is as long as is necessary. I format this field in an RPG program before writing it to the subfile. This way I have one line with all the pertinent customer information and underneath it one line for every invoice. But there is one trick that will make this screen look even better.

When I am formatting the subfile line in the RPG program I stick hexadecimal bytes in between the fields depending on what screen attribute would be best, such as color, underline, or reverse image.

This method allows you to use the power of a subfile with the enhancements of selected screen attributes to create a first class screen presentation.

- Rick Romanek

Create Your Own QTEMP

Create a library (SCRATCH) for submitting queries to batch. Users can create queries in this library and then submit them for batch processing. This library is cleared via a nightly/weekly processing routine. Queries can now be submitted instead of running in QTEMP interactively. Temporary queries can be cleaned up automatically.

Use this library for all temporary objects such as DFUs and as a work area for restores.

- Kevin Heiman

Shared Spool Files

If you need to run several programs, each of which creates a report, and want them all in a single print file, you need to override or change your printer file to use a shared access path. If you are using the default printer file QSYSPRT, you could do this with the command OVRPRTF FILE(QSYSPRT) SHARE(*YES). Then you must open the printer file and keep it open. This can be done with a very small RPG program which contains a dummy printer output (99N99 EXCPT), and then executes a RETRN without setting on LR. You will need a dummy MOVE *ON *INLR also, or the RPG will not compile.

Simply call the RPG program at the start of your job, and then execute a RCLRSC at the end (or condition the initial RPG program with an *ENTRY parameter which causes it to actually set LR on when you wish to end printer continuation mode). The main thing is having a shared access path, which remains open during the time you wish to have all printer output directed to the shared spool file entry.

- Kathreen Kruse

INDARA in Display and Printer Files

Use INDARA in display and printer files. This will help you to avoid recompiling display or printer files when you change indicator numbers or move an indicator in the source file. There is no change needed for the RPG program.

- Greg Prior

Query/400 Run-time Record Selection

You can specify record selection at run-time for exisiting Query/400 programs. Simply do:

RUNQRY QRY(query name) RCDSLT(*YES)

When executed, this command presents the Query/400 record selection panel with the previously defined criteria, allowing you to modify or add selection criteria. After the desired changes are made, press Enter to run the query program.

- Eugene Arencibia

One Source File Only

Use a single source file for all of the source for a library or a development project. This keeps you from needing to jump around in different files with PDM.

- Greg Prior

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$

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: