How to abend job intentionally
Asked Answered
T

5

5

Is it possible to abend your job intentionally through COBOL program. suppose I have an Input file having Header,Detail and Trailer records. I will write a COBOL pgm which reads this file.If no Detail records are found in this file then I want to abend my job by giving some Abend Message and some Abend Code.Is it Possible?

Tret answered 2/7, 2010 at 6:25 Comment(0)
A
9

Do you want to ABEND your program or just set a RETURN-CODE?

I suspect setting a RETURN-CODE, writing a message and then terminating the program via a STOP RUN or GOBACK is all that you really want to do. Causing an actual ABEND may not be necessary.

In an IBM batch environment, the RETURN-CODE set by your program becomes the RC for the JCL job step the program was run under. This is typically what you want to set and test for.

The RETURN-CODE is set by MOVEing a numeric value to it. For example:

         DISPLAY 'No Detail Records found in file.'
         MOVE 16 TO RETURN-CODE
         GOBACK.
            

You may also issue a program dump from a program run under Language Environment (IBM Mainframe option) using the CEE3DMP--Generate dump utility.

In older IBM Mainframe COBOL programs, you might see calls to the ILBOABN0 routine. This call abended your program and issued a dump. This routine is now depreciated in favour of the technique outlined above.

Finally, really old programs might have code in them to generate abends. This can be done in any number of ways, but division by zero was often a favourite:

        DIVIDE SOME-NUMBER BY ZERO GIVING SOME-NUMBER.
        

Works every time!

Personally, I recommend setting the RETURN-CODE over calling ILBOABN0 or data-exception tehcniques.

Note: The RETURN-CODE special-register is not part of the COBOL-85 standard. It is available as an IBM extention to the language. You may need to resort to a different mechanism if you are working in a non-IBM compatible environment.

Attenborough answered 2/7, 2010 at 17:51 Comment(0)
D
3

see the following link on how to set the return code passed back to a JCL job step as well as force an Abened code. http://www.tek-tips.com/viewthread.cfm?qid=1058302&page=22

Dachshund answered 2/7, 2010 at 12:52 Comment(1)
ILBOABN0 (mentioned on the linked page) is now deprecated. And an external link is not an answer, you should summarize it here. Besides being just more pleasant, linked to sites tend to not always stay around, especially ones like this. Google for "tek-tips.com" and you'll find mentions of at least two outage periods that people were complaining about.Maynord
M
2

First, you should check what is accepted by your own shop's/site's working standards. Most teams will already have an accepted way to deliberately abend a program for a 'logic' reason. One company I worked at has a very simple program called SYSABND2, which I believe is written in assembler, which is called just to abend the program.

That said, to ABEND (not just set return code), you should call module CEE3ABD (or previous version ILBOABN0, which is now deprecated).

For details, see:

Maynord answered 10/9, 2013 at 21:52 Comment(0)
H
0

One method for doing an abnormal end of run is to output a message to the user terminal or to the operator at a mainframe computer centre and possibly to a printer if necessary, all depending on the type of computer the program is to be run on. In cobol it is possible to use DISPLAY UPON .. and use an identifier for the terminal, operator console, or printer as defined in an entry in the SPECIAL-NAMES section of the ENVIRONMENT DIVISION. An example may be similar to this using the correct device names for your case OPERATOR-CONSOLE IS OUT-OP2 in special-names with DISPLAY "RUN ERROR - NO DETAIL RECORDS, ABORTING" UPON OUT-OP2 and DISPLAY "REPORT TO OPERATIONS MANAGER" UPON OUT-OP2 and STOP RUN. in procedure division. A reference to the circumstance would need to be included in any job or macro and operating instructions.

Hogg answered 29/12, 2010 at 15:50 Comment(0)
G
0

Yes, it is possible to abend your job intentionally through COBOL program by simply calling one module which doesn't exist. It will give S806 abend code.

Gladiate answered 10/2, 2017 at 11:44 Comment(1)
What if the program does not use dynamic CALLs? How will that produce an S806?Dogear

© 2022 - 2024 — McMap. All rights reserved.