fhg
Volume 6, Number 11 -- March 15, 2006

How to Cancel a Job

Published: March 15, 2006

Hey, Ted:

I have what I hope is a simple question. A CL program that runs in batch mode calls an RPG program, passing parameters to it. If the RPG program finds a certain error, it sets one of those parameters to a certain value, sets on the LR indicator, and ends. At this point, the CL program ends, but the message that it generates gives the caller the impression that the job ran OK. How do I make the program end abnormally?

--Mike


That's a good, basic question, Mike, and I understand why you bring it up. This phenomenon drove me nuts when I first started programming a System/38. In the first issue of Four Hundred Guru this year, I mentioned that I would try to devote more attention to the fundamentals. This is one of those fundamentals that everybody should know, and you'll be glad to know that this is an easy problem to solve.

First, let's recreate the problem for the benefit of all readers. Here's CL program D600C.

PGM                                        
DCL        VAR(&STATUS) TYPE(*CHAR) LEN(1) 
CALL       PGM(D600R) PARM(&STATUS)
IF         COND(&STATUS *NE ' ') THEN(RETURN)
CALL       PGM(D610R)
CALL       PGM(D620R)
ENDPGM

RPG program D600R does some sort of verification on the SOMECODE field. If SOMECODE does not have an appropriate value, D600R sets the STATUS parameter to X and shuts down immediately.

C     *entry        plist                                       
C                   parm                    status            1 
C                                                               
C                   eval      Status = ' '                      
C                                                               
C                   if        Somecode < 'A' or Somecode > 'E'  
C                   eval      status = 'X'                      
C                   eval      *inlr = *on                       
C                   return                                      
C                   endif

And what does the user see? Something like this:

Job 123456/JSMITH/SOMEJOB completed normally on 03/08/06 at 10:26:43.

Poor user. He thinks everything is hunky dory. The solution is to make the CL program tell the operating system that something went wrong. Fortunately, that is an easy thing for CL to do. Here is the revised CL program D600C.

PGM                                               
DCL        VAR(&STATUS) TYPE(*CHAR) LEN(1)        
CALL       PGM(D600R) PARM(&STATUS)             
IF         COND(&STATUS *NE ' ') THEN(SNDPGMMSG + 
             MSGID(CPF9898) MSGF(QCPFMSG) +       
             MSGDTA('Program ended abnormally') + 
             MSGTYPE(*ESCAPE))                    
CALL       PGM(D610R)
CALL       PGM(D620R)
ENDPGM

If the status code does not have a blank value, D600C knows that something went wrong during the execution of D600R. D600C sends an escape message. The user sees the following message.

Job 123456/JSMITH/SOMEJOB ended abnormally.

To learn more about escape messages, see the links to previously published articles below.

--Ted


RELATED STORIES:

Proper CL Error-Handling

Sending Escape Messages from RPG

Programming with Assertions



Sponsored By
WORKSRIGHT SOFTWARE

Do you need area code information?
Do you need ZIP Code information?
Do you need ZIP+4 information?
Do you need city name information?
Do you need county information?
Do you need a nearest dealer locator system?

We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

Just call us and we'll arrange for 30 days FREE use of either
ZIP/CITY or PER/ZIP4.

WorksRight Software, Inc.
Phone: 601-856-8337
Fax: 601-856-9432
E-mail: software@worksright.com
Web site: www.worksright.com



Senior Technical Editor: Ted Holt
Technical Editors: Howard Arner, Joe Hertvik, Shannon O'Donnell, Kevin Vandever
Contributing Technical Editors: Joel Cochran, Wayne O. Evans, Raymond Everhart,
Bruce Guetzkow, Brian Kelly, Marc Logemann, David Morris
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

Sponsored Links

BCD:  Try WebSmart - the easiest and most complete iSeries Web development tool
COMMON:  Join us at the Spring 2006 conference, March 26-30, in Minneapolis, Minnesota
ProData Computer Services:  Use Server Proven DBU-on-demand for $10 a day anytime, anywhere!

 


 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement