28
Sun, Apr
1 New Articles

RPG Academy: Debug Done Right - A Step-by-Step Debug Session, Part 2

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

Let's continue our debug session where we left off and learn a few more debug tips and tricks!

Written by Rafael Victoria-Pereira

In order to get the most out of this TechTip, you'll need to read or re-read Part 1 of this TechTip and follow the instructions it contains, because this one will continue exactly where the last one ended.

After pressing F12 and getting back to the command line (yup, that's the last instruction of the previous TechTip) and assuming you didn't issue an ENDDBG command, you can still see the Display Module screen again. Simply type DSPMODSRC. The Display Module Source command does exactly what its name suggests. It's a good way to see if you're still in debug mode, because it works only in that mode. If you run this command and get a "command not allowed"-like error message, you know that your debug was terminated. I know quite a few programmers who didn't know that this command existed and were used to terminating the debug session and starting a new one, losing all their breakpoints and watches, just to get to the Display Module screen!

Let's execute TST_DTEOPS again and see what happens. The execution stopped before reaching the first line of code! Why? Well, because there's a watch on W_DayNbr, and the variable is initialized in the definition line. In other words, the variable's contents changed since the last time the watch was triggered, so the initialization process caused by the INZ keyword in the variable definition triggered the watch, which forced execution to stop.

Press F10 to advance a few steps, until the first line of code - the one that assigns '2014-11-16' to W_Date - is executed; press F10 again to run that statement. Now place the cursor over W_Date and press F23. The debugger will prompt you for the new value for W_Date; type today's date and press Enter. Alternatively, you can type Eval W_Date = '<today's date>' and press Enter. Note that because of the W_Date definition, you must enclose the date in apostrophes, like the assignment statement in line 18 and the conditional breakpoint in Figure 3 of the previous TechTip.

Press F12 to resume execution. You'll see that, of the two breakpoints that you defined in lines 21 and 24, only the latter is triggered. No, there's nothing wrong with the debugger - just like the watch, both breakpoints are still active. So, what's going on? Remember that the breakpoint in line 21 is conditional. It will be triggered only if W_Date is equal to '2014-11-16'. You changed that variable's content to the current date, so when the debugger evaluated the condition associated with the breakpoint and determined that it was false, it decided the breakpoint shouldn't be triggered.

Feel free to play around a bit with the debugger, exploring the function keys available in the Display Module screen, as I didn't cover all of them. When you're done, return to the command line and type ENDDBG, followed by Enter. This will end your debug session, freeing up the resources allocated to the ILE debugger. Table 1 summarizes the new debug commands mentioned In this and the previous TechTip.

A Debug Commands Summary

Command

Abbreviation

What It Does

BREAK <line number>

BR <line number>

Inserts/removes an unconditional breakpoint in line <line number>.

BREAK <line number> WHEN <condition>

BR <line number> WHEN <condition>

Inserts a conditional breakpoint in line <line number> that will be triggered only when the condition is satisfied.

EVAL <variable name>

EV <variable name>

Displays the content of the <variable name> variable. Positioning the cursor over the variable and pressing F11 does the same thing.

EVAL <variable name> = <new value>

EV <variable name> = <new value>

Assigns the value <new value> to the <variable name> variable. Positioning the cursor over the variable, pressing F23, typing the new value, and pressing Enter does the same thing.

STEP <number of statements>

ST <number of statements>

Allows you to run one or more statements of the source code being debugged. Pressing F10 <number of statements> times does the same thing.

STEP <number of statements> INTO

ST <number of statements> INT

Allows you to run one or more statements of the source code being debugged and drills down into the procedure, function, or program being executed, if possible. Pressing F20 accomplishes the same thing. The object to debug must have been compiled with debug view for this to work.

 

The "Debug Done Right" subseries has thus far provided you with the tools and knowledge to perform more efficient and pleasant (if debugging can ever be pleasant) debug sessions. However, the ILE debugger, just like the Interactive Source Debugger, has its quirks and can be hard to master. Don't be discouraged by your initial attempts. After a few tries, you'll get the hang of it and you'll never want to go back!

The remainder of this subseries will move to other interesting uses of the ILE debugger, such as debugging service programs, OPM and CL programs, and even batch jobs! Stay tuned for the next TechTips of this RPG Academy subseries.

Rafael Victoria-Pereira

Rafael Victória-Pereira has more than 20 years of IBM i experience as a programmer, analyst, and manager. Over that period, he has been an active voice in the IBM i community, encouraging and helping programmers transition to ILE and free-format RPG. Rafael has written more than 100 technical articles about topics ranging from interfaces (the topic for his first book, Flexible Input, Dazzling Output with IBM i) to modern RPG and SQL in his popular RPG Academy and SQL 101 series on mcpressonline.com and in his books Evolve Your RPG Coding and SQL for IBM i: A Database Modernization Guide. Rafael writes in an easy-to-read, practical style that is highly popular with his audience of IBM technology professionals.

Rafael is the Deputy IT Director - Infrastructures and Services at the Luis Simões Group in Portugal. His areas of expertise include programming in the IBM i native languages (RPG, CL, and DB2 SQL) and in "modern" programming languages, such as Java, C#, and Python, as well as project management and consultancy.


MC Press books written by Rafael Victória-Pereira available now on the MC Press Bookstore.

Evolve Your RPG Coding: Move from OPM to ILE...and Beyond Evolve Your RPG Coding: Move from OPM to ILE...and Beyond
Transition to modern RPG programming with this step-by-step guide through ILE and free-format RPG, SQL, and modernization techniques.
List Price $79.95

Now On Sale

Flexible Input, Dazzling Output with IBM i Flexible Input, Dazzling Output with IBM i
Uncover easier, more flexible ways to get data into your system, plus some methods for exporting and presenting the vital business data it contains.
List Price $79.95

Now On Sale

SQL for IBM i: A Database Modernization Guide SQL for IBM i: A Database Modernization Guide
Learn how to use SQL’s capabilities to modernize and enhance your IBM i database.
List Price $79.95

Now On Sale

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: