Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Diffrence between STOP , RETURN , EXIT

Former Member
0 Kudos

Hi all ,

Can some one plz tell me the diffrence between <b>STOP,RETURN , EXIT .</b>

It will be of great help if you explain <b>with a simple example</b> ..

1 ACCEPTED SOLUTION

Former Member

<b>STOP</b>

Syntax

STOP.

Effect

The statement STOP is only to be used in executable programs and in the following event blocks:

AT SELECTION-SCREEN (without additions)

START-OF-SELECTION

GET

You leave these event blocks via STOP, and the runtime environment triggers the event END-OF-SELECTION.

Note

The statement STOP is forbidden in methods and, since Release 6.10, leads to an uncatchable exception during the processing of screens called with CALL SCREEN and in programs not called with SUBMIT.

Example

Ending the event blocks GET sbook after max postings have been issued, and branching to END-OF-SELECTION.

NODES: sflight, sbook. 
DATA: bookings TYPE i, 
      max TYPE i VALUE 100. 
GET sflight. 
  WRITE: / sflight-carrid, sflight-connid, sflight-fldate. 
GET sbook. 
  bookings = bookings + 1. 
  WRITE: / sbook-bookid, sbook-customid. 
  IF bookings = max. 
    STOP. 
  ENDIF. 
END-OF-SELECTION. 
  ULINE. 
  WRITE: / 'First', bookings, 'bookings'.

<b>

RETURN</b>

Syntax

RETURN.

Effect

This statement immediately ends the current processing block. It can appear in any area of a processing block and ends this block regardless of which statement block or control structure the statement is in.

After leaving the processing block, the runtime environment, except for the reporting event blockSTART-OF-SELECTION, follows the schema in Leave processing blocks.

After you end the reporting event block START-OF-SELECTIONwith RETURN, the runtime environment does not trigger any further reporting events, rather, it calls the list processor directly to display the basic list.

Example

Leave the subprogram show_list with

RETURN, if one of the required formal parameters structure or data_tab is initial.


FORM show_list USING structure TYPE c 
                     data_tab  TYPE ANY TABLE. 
  DATA alv_list TYPE REF TO cl_gui_alv_grid. 
  IF structure IS INITIAL OR 
     data_tab  IS INITIAL. 
    RETURN. 
  ENDIF. 
  CREATE OBJECT alv_list 
         EXPORTING i_parent = cl_gui_container=>screen0. 
  CALL METHOD alv_list->set_table_for_first_display 
    EXPORTING i_structure_name = structure 
    CHANGING  it_outtab        = data_tab. 
  CALL SCREEN 100. 
ENDFORM.

<b>EXIT</b> - loop

Syntax

EXIT.

Effect

If the EXIT statement is listed within a loop, it leaves the loop by ending the current loop process. Program execution is continued after the closing statement in the loop.

Note

Outside of a loop, the EXIT statement leaves the current processing block (see EXIT - Processing block). We recommend that you use EXIT within loops only.

Example

Leaving a loop with EXIT if the loop index sy-index is greater than a number limit.

DATA limit TYPE i VALUE 10. 
DO. 
  IF sy-index > limit. 
    EXIT. 
  ENDIF. 
  WRITE / sy-index. 
ENDDO.

4 REPLIES 4

Former Member
0 Kudos

Hi Dipankar,

Refer this thread for the details. It expains along with the examples:

/thread/439616 [original link is broken]

Tnaks

Vijay

<b>PLZ Reward points if helpful</b>

Former Member

<b>STOP</b>

Syntax

STOP.

Effect

The statement STOP is only to be used in executable programs and in the following event blocks:

AT SELECTION-SCREEN (without additions)

START-OF-SELECTION

GET

You leave these event blocks via STOP, and the runtime environment triggers the event END-OF-SELECTION.

Note

The statement STOP is forbidden in methods and, since Release 6.10, leads to an uncatchable exception during the processing of screens called with CALL SCREEN and in programs not called with SUBMIT.

Example

Ending the event blocks GET sbook after max postings have been issued, and branching to END-OF-SELECTION.

NODES: sflight, sbook. 
DATA: bookings TYPE i, 
      max TYPE i VALUE 100. 
GET sflight. 
  WRITE: / sflight-carrid, sflight-connid, sflight-fldate. 
GET sbook. 
  bookings = bookings + 1. 
  WRITE: / sbook-bookid, sbook-customid. 
  IF bookings = max. 
    STOP. 
  ENDIF. 
END-OF-SELECTION. 
  ULINE. 
  WRITE: / 'First', bookings, 'bookings'.

<b>

RETURN</b>

Syntax

RETURN.

Effect

This statement immediately ends the current processing block. It can appear in any area of a processing block and ends this block regardless of which statement block or control structure the statement is in.

After leaving the processing block, the runtime environment, except for the reporting event blockSTART-OF-SELECTION, follows the schema in Leave processing blocks.

After you end the reporting event block START-OF-SELECTIONwith RETURN, the runtime environment does not trigger any further reporting events, rather, it calls the list processor directly to display the basic list.

Example

Leave the subprogram show_list with

RETURN, if one of the required formal parameters structure or data_tab is initial.


FORM show_list USING structure TYPE c 
                     data_tab  TYPE ANY TABLE. 
  DATA alv_list TYPE REF TO cl_gui_alv_grid. 
  IF structure IS INITIAL OR 
     data_tab  IS INITIAL. 
    RETURN. 
  ENDIF. 
  CREATE OBJECT alv_list 
         EXPORTING i_parent = cl_gui_container=>screen0. 
  CALL METHOD alv_list->set_table_for_first_display 
    EXPORTING i_structure_name = structure 
    CHANGING  it_outtab        = data_tab. 
  CALL SCREEN 100. 
ENDFORM.

<b>EXIT</b> - loop

Syntax

EXIT.

Effect

If the EXIT statement is listed within a loop, it leaves the loop by ending the current loop process. Program execution is continued after the closing statement in the loop.

Note

Outside of a loop, the EXIT statement leaves the current processing block (see EXIT - Processing block). We recommend that you use EXIT within loops only.

Example

Leaving a loop with EXIT if the loop index sy-index is greater than a number limit.

DATA limit TYPE i VALUE 10. 
DO. 
  IF sy-index > limit. 
    EXIT. 
  ENDIF. 
  WRITE / sy-index. 
ENDDO.

harimanjesh_an
Active Participant
0 Kudos

hi debroy,

<b>RETURN :</b>

Unconditionally exits a processing block, that is, an event block, a dialog module or a procedure (function module, method, subroutine).

During report processing, that is, during the event blocks START-OF-SELECTION, GET, and END-OF-SELECTION, the system automatically goes to the basic list display.

<b>EXIT :</b>

Exits the current loop processing in loop structures such as:

DO ... ENDDO

WHILE ... ENDWHILE

LOOP ... ENDLOOP

SELECT ... ENDSELECT

Outside loop structures, the system exits the current processing block (event block, dialog module, procedure). During report processing, that is, during the event blocks START-OF-SELECTION, GET, END-OF-SELECTION, the system goes to the basic list display.

SAP recommends that you use EXIT only in loops. To exit processing blocks, use the statement RETURN.

<b>Example</b>

DATA: SAP_COUNT TYPE I,

WA_T100 TYPE T100.

SELECT * FROM T100 INTO WA_T100 WHERE SPRSL = SY-LANGU AND

ARBGB = 'DS'.

WRITE / WA_T100-TEXT.

IF WA_T100-TEXT CS 'SAP'.

ADD 1 TO SAP_COUNT.

IF SAP_COUNT = 3.

EXIT.

ENDIF.

ENDIF.

ENDSELECT.

<b>STOP :</b>

This statement terminates a processing block in an excutable program of type 1.

The statement is only intended for use in the INITIALIZATION, AT SELECTION-SCREEN, START-OF-SELECTION, and GET events. During the execution of type 1 programs, it terminates the processing of the associated event blocks and triggers the sending of the selection screen during the event INITIALIZATION, and - in all other cases - triggers the event END-OF-SELECTION of the runtime environment. In all other processing blocks or if END-OF-SELECTION is not desired, you must use RETURN or EXIT.

<b>The STOP statement is not allowed in ABAP Objects.</b>

<b>Note :</b>

Unlike CHECK and EXIT, RETURN is context-independent. This means that the current processing block is exited, irrespective of whether RETURN occurs within or outside loops. If you want to leave a processing block, you should therefore always use RETURN instead of CHECK or EXIT.

Reward me if useful........

Harimanjesh AN