• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • How to Cancel a Job

    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

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    Midrange Dynamics North America

    Accelerate Change & Integration on IBM i

    Good change management unites IBM i and open systems development for productive collaboration. Developers work with their preferred tools and IDEs. Ultimate version control and traceability mean fast bug fixes and less stress. Rollback to a stable version in seconds.

    Change management gives managers, operations teams, and auditors the visibility they need, and developers can focus on what they like best: building great applications.

    Learn More

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    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!

    Storage Vendor GST Resells Bull Unix Servers in the States i5 Memory and Disk Prices Need to Come Down

    Leave a Reply Cancel reply

Volume 6, Number 11 -- March 15, 2006
THIS ISSUE SPONSORED BY:

WorksRight Software
iTera
Profound Logic Software

Table of Contents

  • How to Cancel a Job
  • iSeries Security Journal Receiver Management, Part 2
  • Admin Alert: Two Tricks for Better Printer Control

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • With Power11, Power Systems “Go To Eleven”
  • With Subscription Price, IBM i P20 And P30 Tiers Get Bigger Bundles
  • Izzi Buys CNX, Eyes Valence Port To System Z
  • IBM i Shops “Attacking” Security Concerns, Study Shows
  • IBM i PTF Guide, Volume 27, Number 26
  • Liam Allan Shares What’s Coming Next With Code For IBM i
  • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
  • VS Code Will Be The Heart Of The Modern IBM i Platform
  • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
  • IBM i PTF Guide, Volume 27, Number 25

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle