Modularity: event and subroutine
ABAP / 4 module unit
ABAP / 4 has three module units:
Event: Events Subroutine: Subplit Function Module: Function Module
event
Table 17.1 ABAP / 4 Events
Category Events Driver Initialization At Selection-ScreenStart-of-SelectionGetend-of-Selection User AT Line-Selection AT PFN AT User-Command Program Top-of-Page End-of -Page
Subroutine
Define subroutine statements
FORM S [Tables T1 T2 ...]]]
[USING U1 Value (u2) ...]
CHANGING C1 Value (C2) ...].
---
ENDFORM.
Here:
S is the subroutine names T1, T2, U1, U2, C1, and C2 are parameters (Parameter) TABLES allows the inner table as a parameter transmission value cannot be used after TABLES THE VALUE Addition Can Be Applied to any variables passed via using or Changing. --- code represents any number of lines
Precautions:
l All clauses are optional
l The order of the clauses cannot be reversed
l The maximum of each clause can only appear once, but the parameters after the clause can have multiple
l Between the parameters separated by spaces
l Tables parameters can only be inner table, can't be a database table
l A subroutine can call another subroutine
l Support recursive, a subroutine can call itself, or call the subroutine that calls it.
The definition of the L subroutine cannot nested, that is, another subroutine cannot be defined within a subroutine.
Call the statement of the subroutine
Perform a) s
b) n of s1 s2 s3 ...
[TABLES T1 T2 ...]]]]
[Using U1 U2 ...]]]]]
[CHANGING C1 C2 ...].
Here:
S, S1, S2, S3, is a subroutine name n is numerical variables a) and b) can only use tables, use, and changing, and changing, and changing. In b) is the Nth program
You can use the following statement to exit the subroutine at any time:
EXIT If you do not exit the subroutine, execute the subroutine, execute the next statement after Perform;
Global variables and local variables
Variables defined in the subroutine with Tables or DATA statements are called global variables.
Variables defined in the subroutine with local, data or statics are called local variables.
Tables defined always global variables, in the subroutine, use local to define local variables in replace TABLES. Variables defined with local can not be used in the called subroutine, and variables defined with DATA or STATICs cannot be used. Local variables defined using Statics are not released at the end of the subroutine, can still be used by itself, and this variable initializes when the subroutine is called (allocated memory and genus), when calling Keep the value after the last call. The local variable defined using the DATA is different, and it is initialized when the call is called.
Understand the function group
The function group is a program that contains a functional module. R / 3 presets more than 5,000 function groups, with a total of more than 30,000 functional modules. The identifier of the function group consists of 4 characters, and the identifier of the custom function group must begin with Y or Z. Creating a function module's transaction code is SE37-Function Builder (SAP Menu-Tools-ABAP Work Bench-overview), the transaction code for the function library is SE84-Information System (SAP Menu-Tools-Abap Work Bench-Development). SE84 can see all information.
Function module is similar to the subroutine, with statement
Function FNAME
ENDFUNCTION
definition. Statement
Call function 'f'
[exporting p1 = v1 ...]
[importing p2 = v2 ...]
[Changing P3 = V3 ...]]]]
[TABLES P4 = IT ...]]]]
[Exceptions X1 = n [tahers = n]].
Here:
F is the function module name P1 to P4 is the parameter names V1 to V3 defined in the function module interface, which is the variable or string name IT defined in the calling program is an internal table N any integer defined in the calling program, and cannot be variables. X1 is an exception name thrown in the function module
transfer.