Newsletters Subscriptions Forums Media Kit About Us Contact Search Home

mgo
OS/400 Edition
Volume 3, Number 74 -- November 5, 2003

Am I Debugging You?


Hey, Ted:

I would like to execute a section of code in a CL program only if I'm in debug mode. Is there a way for my CL program to know whether the job is running in debug? Also, is there a way for a CL program to know whether production files are allowed to be updated during a debugging section?

--Joe


Your first requirement is easy to handle. Use the Change Debug (CHGDBG) command, specifying *SAME for all parameters. If the command fails, the program is not running in debug mode. Here's an example:

dcl  &true          *lgl     value('1')      
dcl  &false         *lgl     value('0')      
                                             
dcl  &debugging     *lgl                     
                                             
chgvar    &debugging   &true                 
chgdbg                                       
monmsg cpf0000 exec(chgvar &debugging &false)
                                             
if &debugging do                             
   dspmodsrc                                 
enddo                                        
                                             
call   somepgm

If the Start Debug (STRDBG) command was issued, placing the job in debug mode, the program runs the Display Module Source (DSPMODSRC) command, allowing the programmer to set break points before program SOMEPGM runs.

Your second question is a little more difficult. There is an API that can tell whether the debugging session permits files in production libraries to be changed. It is an ILE API, which means you can only use it in CL modules, not in OPM CL programs. Moreover, it has a quirk you should be aware. (More about the quirk in a minute.)

The API has the name QteRetrieveDebugAttribute. It can tell you whether production files may be updated, whether the debugging session is for the current job or another job, and whether OPM programs may be debugged with the ILE debugger. Here is a snippet from a CL module that calls this API to retrieve two of those values:

dcl &Attr      *char 10                            
dcl &UpdProd   *char 10                            
dcl &OPMSrc    *char 10                            
dcl &Err       *char  8 value(x'0000000000000000') 
dcl &Debug     *char  1 value('1')                 
                                                   
CHGVAR VAR(&ATTR) VALUE('*UPDPROD')                
CALLPRC PRC('QteRetrieveDebugAttribute') +         
          PARM(&ATTR &UPDPROD &ERR)                
MONMSG MSGID(CPF9541) +                            
         EXEC(CHGVAR VAR(&DEBUG) VALUE('0'))       
                                                   
IF (&Debug *eq '1') do                             
   CHGVAR VAR(&ATTR) VALUE('*OPMSRC ')                
   CALLPRC PRC('QteRetrieveDebugAttribute') +         
             PARM(&ATTR &OPMSRC &ERR)                 
enddo                                              

The first parameter specifies the attribute you wish to retrieve. In your case, the attribute is *UPDPROD. The retrieved attribute comes back in the second parameter. The returned value will be *YES (production files may be updated) or *NO.

If the job is not in debug mode, the API returns error CPF9541. This is where the quirk shows itself. I have discovered that QteRetrieveDebugAttribute also returns this message if the job is in debug mode, but the current program is not selected for debug.

To learn more about QteRetrieveDebugAttribute, go to IBM's iSeries Information Center.

--Ted


Sponsored By
PROFOUND LOGIC SOFTWARE

RPGsp users don't settle for less!

Why settle for a tool that's just an application builder, or just a server, or just a designer, or just a green-screen converter?

You need an integrated Web development tool that can do all of the above. And you need the best!

RPGsp has what you need. Don't settle for less.

Free trial and information at www.RPGsp.com



THIS ISSUE
SPONSORED BY:

WorksRight Software
Profound Logic Software


BACK ISSUES

TABLE OF
CONTENTS

Display Two Subfiles At Once

Am I Debugging You?

Reader Feedback and Insights: Why Online Forums Suffer


Editors
Howard Arner
Joe Hertvik
Ted Holt
David Morris

Managing Editor
Shannon Pastore

Publisher and
Advertising Director:

Jenny Thomas

Advertising Sales Representative
Kim Reed

Contact the Editors
Do you have a gripe, inside dope or an opinion?
Email the editors:
editors@itjungle.com

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.