Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programming Tip 1

Status
Not open for further replies.

RedMage1967

Programmer
Mar 13, 2003
200
US
I found this article on the web a couple of months ago. It really has helped me in finding program errors.

LET THE DEBUGGER SHOW YOU WHERE THE USER'S PROGRAM HAS FAILED.
When a user calls to let you know that one of your RPG programs has just crashed and that there's an error message on their screen (or in a message queue for batch jobs) that's awaiting a response, don't be too hasty in having them respond. If your program has a debugging view that shows you the statements and if the program isn't optimized, here's a handy diagnostic technique. With the error message still unanswered, first determine the qualified job name (job name, user and job number) of the problem job and the program with the failure. You can use various commands such as WrkActJob or WrkUsrJob to find this information (to find the program in error, examine the call stack looking for the last user-written program). Next, from your command line, start a service job with the command StrSrvJob specifiying the qualified job name of the problem job as the job to service. This lets you enter debug commands for that job. After starting the service job, enter the StrDbg command specifying the problem program you identified and press Enter. Voila! The debugger displys the program in error and is positioned to the line of code that precipated the error. How's that for ease? You can then explore the situation in the debugger and solve the user's problem more quickly. You'll also know right where to go to fix the bug! When finished debugging, end your debugging session with EndDbg and end the service job with EndSrvJob. The user can also respond to the message now! RedMage1967
IBM Certifed - RPG IV Progammer
 
I have a CL program that I have written to make this easier. I have the command STRBTCHDBG and ENDBTCHDBG helps quite a bit for any batch debugging. If you would like I should be able to post the code or email me privately for the code. mnwills AT taylorcorp DOT com iSeriesCodePoet
IBM iSeries (AS/400) Programmer
[pc2]
Want to have all your bookmarks in one spot?
 
I would guess your command prompts the user for the qualified job name and the program to debug, right? RedMage1967
IBM Certifed - RPG IV Progammer
 
I hear that. You gave me a good idea. Started coding a command to do the same thing. RedMage1967
IBM Certifed - RPG IV Progammer
 
RedMage1967:

You get a star from me. Great tip.

iSeriesCodePoet:

I'd like that code you wrote to combine the two commands into one. This is ideal for us since we always compile our programs with DBGVIEW(*LIST) and we don't optimize. I'll e-mail you privately. Thanks again.
"When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for here you have been, and there you will always long to return."

--Leonardo da Vinci

 
Okay... it isn't perfect, but like I said, I quickly tossed it together.

Code:
Starting the debug:
             PGM        PARM(&JOBNAME &USER &JOBNUM &PGMNAME) 
                                                              
             DCL        VAR(&JOBNAME) TYPE(*CHAR) LEN(10)     
             DCL        VAR(&USER)    TYPE(*CHAR) LEN(10)     
             DCL        VAR(&JOBNUM)  TYPE(*CHAR) LEN(6)      
             DCL        VAR(&PGMNAME) TYPE(*CHAR) LEN(10)     
                                                              
             ENDBTCHDBG                                       
             MONMSG     MSGID(CPF0000)                        
                                                              
 REDO:       STRSRVJOB  JOB(&JOBNUM/&USER/&JOBNAME)           
    /*       MONMSG     MSGID(CPF0000)                */      
                                                              
 REDO2:      STRDBG     PGM(&PGMNAME) UPDPROD(*YES)           
    /*       MONMSG     MSGID(CPF0000)                */      
                                                              
             ENDPGM                                           

The command (STRBTCHDBG):
             CMD        PROMPT(STRBTCHDBG)                        
                                                                
             PARM       KWD(JOBNAM) TYPE(*CHAR) LEN(10) MIN(1) +
                          PROMPT('JOB NAME:')                   
             PARM       KWD(USER) TYPE(*CHAR) LEN(10) MIN(1) +  
                          PROMPT('USER NAME:')                  
             PARM       KWD(JOBNUM) TYPE(*CHAR) LEN(6) MIN(1) + 
                          PROMPT('JOB NUMBER:')                 
             PARM       KWD(DBGPGM) TYPE(*CHAR) LEN(10) MIN(1) +
                          PROMPT('DEBUG PROGRAM NAME:')         


Ending Debug:
             PGM                                    
                                                    
             ENDDBG                                 
             MONMSG     MSGID(CPF0000)              
                                                    
             ENDSRVJOB                              
             MONMSG     MSGID(CPF0000)              
                                                    
             ENDPGM                                 

The Command (ENDBTCHDBG):
             CMD        PROMPT(ENDBTCHDBG)
iSeriesCodePoet
IBM iSeries (AS/400) Programmer
[pc2]
Want to have all your bookmarks in one spot?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top