Sie sind auf Seite 1von 10

ABAP - Event and Subroutine

Content
Know the types of modularization units available in ABAP/4 Understand ABAP/4 events Use the initialization, start-of-selection, and endof-selection events Define internal and external subroutines Define global, local, and static variables and table work areas Understand the effect of exit, check, and stop within events and subroutines

Type of Modularization
ABAP/4 offers three types of modularization units:
Events Subroutines Function modules

Events
Driver
Initialization at selection-screen start-of-selection end-of-selection

Program
top-of-page end-of-page

Start-of-selection
Not include in the program: If the first statement doesnot belong to any events, will be automatically inserted before first statement. Example: report ztx1703 no standard page heading. parameters p1(8). write: / 'p1 =', p1. initialization. p1 = 'Init'. end-of-selection. write: /(14) sy-uline, / 'End of program'. top-of-page. write: / 'This is My Title'. skip.

Leaving an event
You can exit out of an event at any time using the following statements:
Exit Check Stop

Subroutines
A subroutine is a reusable section of code. It is like a mini-program that can be called from another point in your program. Use FORM.ENDFORM to define a subroutine To call subroutine: use PERFORM statement Example:
1 report ztx1706. 2 3 write: / 'Before call 1'. 4 perform sub1. 5 write: / 'Before call 2'. 6 perform sub1. 7 write: / 'After calls'. 8 9 form sub1. 10 write: / 'Inside sub1'. 11 endform.

Syntax for define subroutine


form s [tables t1 t2 ...] [using u1 value(u2) ...] [changing c1 value(c2) ...].
---

endform. where:
s is the name of the subroutine. t1, t2, u1, u2, c1, and c2 are parameters. tables allows internal tables to be passed as parameters. The value addition cannot be used after tables. The value addition can be applied to any variables passed via using or changing. --- represents any number of lines of code.

Exit subroutine
Exit Check Stop
In subroutines
check and exit immediately leave the subroutine and processing continues with the next executable statement following perform. stop immediately leaves the subroutine and goes directly to the end-of-selection event.

check, exit, and stop do not set the value of sy-subrc. If you want to set it, assign a numeric value to it before leaving.

Global and Local Variable


A global variable is one that is defined outside of a subroutine by using the tables or data statement. A local variable is a variable that is defined inside a subroutine

Das könnte Ihnen auch gefallen