LEAVE (ABAP Keyword)

LEAVE is a keyword used in SAP ABAP programming.
This tutorial covers its introduction & syntax details.

LEAVE

Effect
Leave processing.

LEAVE PROGRAM.

Effect
Leaves the current program and continues processing after CALL TRANSACTION , CALL DIALOG or SUBMIT prog AND RETURN .
If
you use LEAVE TO TRANSACTION , SUBMIT prog or start the program via the
transaction menu or a transaction code, you branch to the transaction
selection screen.

Note
LEAVE PROGRAM always leaves the current program – there is never any processing after LEAVE PROGRAM !

LEAVE TO TRANSACTION

Basic form 2
LEAVE TO TRANSACTION tcod.

Addition

… AND SKIP FIRST SCREEN

Effect
Terminates the current processing and starts the (new) transaction tcod .

Examples
Start Transaction SM02 :

LEAVE TO TRANSACTION ‘SM02’.

Restart current transaction:

LEAVE TO TRANSACTION SY-TCODE.

Addition
… AND SKIP FIRST SCREEN

Effect
Processes
the first screen of the transaction in the background. If possible, the
fields on this screen are filled with values from the SAP memory .
Therefore, you should set the desired values with SET PARAMETER . If an
error occurs when processing the initial screen (due to incorrect or
imcomplete parameter values), this is reported and you must correct or
complete the input manually on this screen.

LEAVE TO SCREEN

Basic form 3
LEAVE TO SCREEN scr.

Effect
Leaves the current screen and processes the screen scr .

If
scr = 0, processing in CALL mode continues after the CALL SCREEN
statement. Otherwise, you branch to the transaction selection screen.
Related SET SCREEN , LEAVE SCREEN

LEAVE SCREEN

Basic form 4
LEAVE SCREEN.

Effect
Leaves the current screen and processes the next screen.

If
the next screen has the number 0 (either defined statically or set
dynamically by SET SCREEN 0 ), processing in CALL mode continues after
the CALL SCREEN statement. Otherwise, you branch to the transaction
selection screen.

Note
If the next screen is specified
dynamically, you can use the short form “LEAVE TO SCREEN scr. ” instead
of a combination of the ” SET SCREEN scr. ” and ” LEAVE SCREEN. ”
commands.
Related SET SCREEN , LEAVE TO SCREEN

LEAVE TO LIST-PROCESSING

Basic form 5
LEAVE TO LIST-PROCESSING.

Addition

… AND RETURN TO SCREEN scr.

Effect
Switches
from “dialog processing” (module pool, screens) of the current
transaction to “list processing”. You can then use all the usual list
layout commands ( WRITE , SKIP , …).
After leaving the current
screen, the list formatted in this way is displayed implicitly or
explicitly by LEAVE SCREEN . Here, all list programming options are
possible, e.g. line selection, F keys , windows.
LEAVE LIST-PROCESSING continues with “Processing Before Output” ( PBO ) of the screen which controls the list processing.

Note
After
switching to list processing mode with SET PF-STATUS … , you are
recommended to define a GUI (Graphical User Interface) of type List or
List in dialog box .

Addition
… AND RETURN TO SCREEN scr.

Effect
LEAVE LIST-PROCESSING continues with “Processing Before Output” ( PBO ) of the screen scr.

Note
Using
LEAVE LIST-PROCESSING to leave list processing explicitly is only
necessary in exceptional cases; normally, the standard F keys (F3 Back
and F15 Exit ) are sufficient.

LEAVE LIST-PROCESSING

Basic form
LEAVE LIST-PROCESSING.

Effect
Returns from list processing and re-processes the return screen (LEAVE TO LIST-PROCESSING) .

Note
LEAVE LIST-PROCESSING is not required if you use the standard F keys in list processing (F3 Back and F15 Exit ).

LEAVE

Basic form 7
LEAVE.

Effect
Leaves the ” CALL mode ” (introduced by: CALL TRANSACTION , CALL DIALOG , LEAVE TO LIST-PROCESSING

Effect of LEAVE after
CALL TRANSACTION tcod :
Return from the called transaction tcod . Processing continues after ” CALL TRANSACTION … “.
CALL DIALOG dial :
Return
from the called dialog module dial . The IMPORT objects of the calling
program are passed. Processing continues after ” CALL DIALOG … “.
SUBMIT prog AND RETURN :
Return from the called program prog . Processing continues after the call to ” SUBMIT prog … “.
LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN scr :
Return from list processing. The screen scr is reprocessed.

Note
LEAVE is not required if you use standard F keys in the list processing (F3 Back and F15 Exit ).