×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

ON CALL exception

ON CALL exception

ON CALL exception

(OP)
Hi,

First of all, let me admit that its been a long time since I have written a plain COBOL call.
However I still do remember the syntax and everything, so when this happened it really puzzled me.

I have written a new COBOL Batch Module, lets say PROGA
PROGA is calling PROGB as follows:

CODE --> COBOL

Call PROGB using inPROGB outPROGB                 
   on exception                                         
   move 'Fejl - Call PROGB'     to logLocation        
   string 'Program ' PROGB ' not found'               
     delimited by size            into logDescription   
   end-string                                           
   perform errorExit                                    
end-call 

The thing is PROGB has not even been written till now.
So I expected the program to fail here, but it went ahead without doing anything to the next statements.
What I fopun even stranger was that when I removed the On exception condition, The program did abend as expected saying that the module PROGB is not found.

CODE --> COBOL

Call PROGB using inPROGB outPROGB                 
end-call 

What is that I am overlooking for the ON exception condition not getting executed?

RE: ON CALL exception

Hi Rajesh,
I must admit I've never used the ON EXCEPTION statement as I've always passed return codes between programs and allowed the Operating System to sort out any errors where the program doesn't exist. To my mind, if somebody has gone to the trouble of including exception handling of this type in their operating system, then I might as well use it smile

But, your statement, as you've coded it on this forum looks ok to me. I would therefore check:
  • Is your code in the program the same as you have coded here?
  • When executed, does it definitely NOT pass through your error handling?
I would though give serious consideration to removing the ON EXCEPTION condition and letting the operating system do its job.

Marc

RE: ON CALL exception

(OP)
Hi Marc,

First of all, yes my code does handle the return codes as you suggested:

CODE --> COBOL

Call PROGB using inPROGB outPROGB                     
   on exception                                             
   move 'Fejl - Call PROGB'     to logLocation            
   string 'Program ' PROGB ' not found'                   
     delimited by size            into logDescription       
   end-string                                               
   perform errorExit                                        
end-call                                                    
                                                            
evaluate rtkd                     in outPROGB              
   when 0                                                   
      continue 
   when 4
      BLAH ... BLAH                                              
   when other                                               
      move 'Error Calling Program PROGB'                  
                                  to logDescription         
   perform errorExit                                        
end-evaluate 


To answer your Questions:
• Is your code in the program the same as you have coded here?
YES :)
• When executed, does it definitely NOT pass through your error handling?
NO :(
The problem is right now I am not even bothered about the error handling at all.
My main concern is why PROGA doesn't fails. I find it very strange and confusing.

I find that the ON CALL EXCEPTION statement helps with relevant information when the Job fails, to populate the log with the relevant information.

RE: ON CALL exception

When runniing this with the non-existent PROGB, what value is in "rtkd" in outPROGB?

"My main concern is why PROGA doesn't fails"
Possibly because the exception was handled?

RE: ON CALL exception

(OP)
Hi PAPADBA,

  • When runniing this with the non-existent PROGB, what value is in "rtkd" in outPROGB?
I am not sure what you meant to ask here, how will the rtkd in outPROGB be set if the PROGB itself is not written. If you are trying to cross check that there is another Load in the library by name PROGB, I assure you there is not, because when I call PROGB without the exception clause PROGA does fail saying thatthere is no load for PROGA.

  • Possibly because the exception was handled?
Again, if the exception was handled shouldnt it go to the next statement?


CODE --> COBOL

Call PROGB using inPROGB outPROGB                     
   on exception                                             
   move 'Fejl - Call PROGB'     to logLocation               string 'Program ' PROGB ' not found'                   
     delimited by size            into logDescription       
   end-string                                               
   perform errorExit                                        
end-call 

RE: ON CALL exception

My bad - i meant to ask what is placed in outPROGB before the call? And after the call (regardless of whether it works or not (i realize it will to catch the "after" when it abends<g>). Just trying to see as much as we can see.

"Again, if the exception was handled shouldnt it go to the next statement?"
I don't know. I searched the biggest source repositories on these systems and did not find a single bit of code that specifies this.

Time permitting, i'll see if i can run a test over the weekend. If i don't post something by Sat afternoon, do post a reminder.


RE: ON CALL exception

It sounds like what you are saying is that you expected the ON EXCEPTION clause to be executed but was not. But you are not clear about what evidence there is to show that the ON EXCEPTION clause statements were not executed. It sounds to me like they were executed, they simply did not do what you thought they would do. You say "I expected the program to fail here..." but why would the program fail unless there is something to be executed in paragraph errorExit that would cause a failure. Perhaps if you posted the contents of errorExit, it might be clearer.

Does paragraph errorExit terminate with a GOBACK, STOP RUN or EXIT PROGRAM statement? If not, then execution would simply continue with the statements following the CALL statement. If in fact you wish the program to truly ABEND, you would have to program something in paragraph errorExit to explicitly cause that to happen. After 12 years away from an IBM mainframe environment, I don't remember the name, but I do know there is a specific IBM subroutine call that can be invoked to explicitly force an abend. You would have to ask your systems people or you could try an internet search for it.

Code what you mean,
and mean what you code!
But by all means post your code!

Razalas

RE: ON CALL exception

The exception hadling works as expected. The best is to try it on a simplest example:

CODE

IDENTIFICATION DIVISION.              
       PROGRAM-ID. CALLEDTEST.               
       ENVIRONMENT DIVISION.                 
       CONFIGURATION SECTION.                
       SOURCE-COMPUTER. IBM-AS400.           
       OBJECT-COMPUTER. IBM-AS400.           
       DATA DIVISION.                        
       WORKING-STORAGE SECTION.              
                                             
       PROCEDURE DIVISION.                   
       MAIN-PARA.                            
           DISPLAY "HELLO FROM 'CALLEDTEST'."
           GOBACK                            
           . 

CODE

IDENTIFICATION DIVISION.           
       PROGRAM-ID. CALLERTEST.            
       ENVIRONMENT DIVISION.              
       CONFIGURATION SECTION.             
       SOURCE-COMPUTER. IBM-AS400.        
       OBJECT-COMPUTER. IBM-AS400.        
       DATA DIVISION.                     
       WORKING-STORAGE SECTION.           
       01 CALLED-PGM  PIC X(10).          
                                          
       PROCEDURE DIVISION.                
       MAIN-PARA.                         
           MOVE "NOEXIST" TO CALLED-PGM   
           PERFORM CALL-PGM               
           MOVE "CALLEDTEST" TO CALLED-PGM
           PERFORM CALL-PGM               
           GOBACK                                             
           .                                                  
                                                              
       CALL-PGM.                                              
           CALL CALLED-PGM                                    
             ON EXCEPTION                                     
                DISPLAY "CALL OF '" CALLED-PGM "' FAILED !"   
             NOT ON EXCEPTION                                 
                DISPLAY "CALL OF '" CALLED-PGM "' SUCCESSFUL."
           END-CALL
           . 

Output:

CODE

> CALL CALLERTEST                  
  CALL OF 'NOEXIST   ' FAILED !    
  HELLO FROM 'CALLEDTEST'.         
  CALL OF 'CALLEDTEST' SUCCESSFUL. 

After calling NOEXIST I see in joblog the message Cannot resolve to object NOEXIST. Type and Subtype X'0201' Authority X'0000', but - because the exception was handled - the program doesn't failed and it contines with next statements, which is calling of CALLEDTEST.

When I remove the exception handling from the caller, i.e. I change the source to

CODE

CALL-PGM.                                              
           CALL CALLED-PGM                                    
      *      ON EXCEPTION                                     
      *         DISPLAY "CALL OF '" CALLED-PGM "' FAILED !"   
      *      NOT ON EXCEPTION                                 
      *         DISPLAY "CALL OF '" CALLED-PGM "' SUCCESSFUL."
           END-CALL                                           
           . 

then - because the exception was unhandled - the execution of caller breaks on statement

CODE

16     001400     CALL CALLED-PGM 
with error Cannot resolve to object NOEXIST. Type and Subtype X'0201' Authority X'0000'. In this case next statements will not be ececuted, i.e. CALLEDTEST will never be called.

RE: ON CALL exception

Your last post is really stating that the on exception is working as expected. Nothing wrong with it unless you expected something else to happen.

So if on this program the exception handling works, and it doesn't on your original sample then I would say the difference in behaviour is related to different compile/link options being used.

Regards

Frederico Fonseca
SysSoft Integrated Ltd
www.syssoft-int.com

FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

RE: ON CALL exception

The OP didn't say what happens in the error errorExit paragraph, which is coded on exception

CODE

Call PROGB using inPROGB outPROGB                     
   on exception
     ...                                             
     perform errorExit                                        
end-call 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close