Monday, 28 July 2014

COBOL STOP RUN statement - The most common way to terminate a program!



One of the fundamental concepts in COBOL is the STOP RUN statement, which is used to terminate the execution of a program and return control to the operating system. In this article, we will explore the COBOL STOP RUN statement in depth, including its syntax, usage, and the tasks it performs before terminating the program's execution.

Introduction - COBOL STOP RUN Statement.

The STOP RUN statement in COBOL is used to terminate the execution of a program and return control to the operating system. It is typically used at the end of a program to signal that the program has completed its processing and that resources, such as memory, should be freed.

When the STOP RUN statement in COBOL is executed, the COBOL runtime system performs a series of clean-up tasks, such as closing any open files, releasing allocated memory, and returning control to the operating system. The operating system then releases any resources that were allocated to the program, such as memory and file handles.

The STOP RUN statement in COBOL is a simple and straightforward way to terminate a program, and it is the most common way to do so. It does not require any additional parameters or arguments, and it can be used in any part of the program, as long as it is the last statement in the procedure division.

It's also important to note that, In addition to the STOP RUN statement, there are other ways to terminate a program execution such as using the EXIT PROGRAM statement or the GOBACK statement. However, the STOP RUN statement is the most common way to terminate a COBOL program and is often used as the final statement in a program's procedure division.


COBOL STOP RUN Statement - Syntax.

The STOP RUN verb must be the last statement in the procedure division. If it is not, the program will terminate abnormally and an error message will be displayed.

Additionally, there are other ways to stop a program execution such as using the EXIT PROGRAM statement or the GOBACK statement. However, the STOP RUN verb is the most common way to terminate a COBOL program.

The syntax of the COBOL STOP RUN verb is as follows:

     STOP RUN

COBOL STOP RUN Verb - Example.

In the following example, the COBOL STOP RUN verb is used at the end of the core business logic within the procedure division. When the STOP RUN statement in COBOL is executed, the processing of the program is terminated. 

000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID.    DEMOCL04.
000300 AUTHOR.        TOPICTRICK.
000400 DATE-WRITTEN.  01-JAN-2023.
000500 DATE-COMPILED. 01-APR-2023.
....
....
....

016800 PROCEDURE DIVISION.
016900 0000-CORE-BUSINESS-LOGIC.
017000    PERFORM A000-INIT-VALS
017100    PERFORM B000-OPEN-FILE
017200    PERFORM C000-PRNT-HDRS
017300    PERFORM D000-PROC-RECD
017400    PERFORM X000-CLSE-FILE
017500 STOP RUN.


COBOL STOP RUN VS COBOL GOBACK Statement - Difference.


The STOP RUN and GOBACK statements are both used to terminate the execution of a COBOL program, but they are used in different situations and have slightly different effects.

  • The STOP RUN statement in COBOL is used to terminate the execution of a program and return control to the operating system. It is typically used at the end of a program to signal that the program has completed its processing and that resources, such as memory, should be freed. When the STOP RUN statement is executed, the COBOL runtime system performs a series of clean-up tasks, such as closing any open files, releasing allocated memory, and returning control to the operating system.
  • The GOBACK statement in COBOL is used to return control to the calling program or to the operating system. It is typically used to return from a called program or a subroutine. When the GOBACK statement in COBOL is executed, the COBOL runtime system performs a similar clean-up tasks as the STOP RUN statement, such as closing any open files, releasing allocated memory, and returning control to the calling program or to the operating system.

In summary, the STOP RUN statement is used to terminate the execution of a program and return control to the operating system, while the GOBACK statement is used to return control to the calling program or to the operating system. Both statements perform similar clean-up tasks. The choice of using one over the other depends on the program's flow and design.

Conclusion.

In summary, the STOP RUN statement in COBOL is a fundamental concept that is used to terminate the execution of a program and return control to the operating system. It is typically used at the end of a program to signal that the program has completed its processing and that resources, such as memory, should be freed. The statement is simple and straightforward, and it does not require any additional parameters or arguments. 

Do check out COBOL LEVEL 88 Condition.


Subscribe to Topictrick & Don't forget to press THE BELL ICON to never miss any updates. Also, Please visit mention the link below to stay connected with Topictrick and the Mainframe forum on - 

► Youtube
► Facebook 
► Reddit

Thank you for your support. 
Mainframe Forum™
Created with Artisteer

No comments:

Post a Comment