Sunteți pe pagina 1din 2

Modularization Techniques

There are two kinds of processing blocks, those that are called from outside a program by the ABAP runtime system, and those that can be called by ABAP statements in ABAP programs. Processing blocks that are called using the ABAP runtime system: Event blocks Dialog modules Processing blocks that are called from ABAP programs: Subroutines Function modules Methods The processing blocks that you call from ABAP programs are called procedures. Modularization makes ABAP programs easier to read and maintain, as well as avoiding redundancy, increasing the reusability of source code, and encapsulating data.

Source Code Modules They are not used to modularize tasks and functions. You should use
procedures for this purpose. ABAP contains two kinds of source code modules: Local modules are called macros, and cross-program modules are called include programs.

Macros to reuse the same set of statements more than once in a program can only use a macro within
the program in which it is defined DEFINE <macro>. <statements> END-OF-DEFINITION. You must specify complete statements between DEFINE and END-OF-DEFINITION. These statements can contain up to nine placeholders (&1, &2, ..., &9). You must define the macro before the point in the program at which you want to use it.

Include Programs are global R/3 Repository objects. They are solely for modularizing source
code, and have no parameter interface. Include programs allow you to use the same source code in different programs. For example, this can be useful if you have lengthy data declarations that you want to use in different programs. To use an include program in another program, enter the statement INCLUDE <incl>.

Procedures contain a set of statements, and are called from other ABAP programs. You can call procedures in the program in which they are defined, or from external programs. Procedures have an interface for passing data, and can also contain local data. ABAP contains the following kinds of procedures: Subroutines Subroutines are principally for local modularization, that is, they are generally called from the program in which they are defined. A subroutine is a block of code introduced by FORM and concluded by ENDFORM. FORM <subr> [USING ... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ] [CHANGING... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ]. ... ENDFORM. <subr> is the name of the subroutine. The optional additions USING and CHANGING define the parameter interface.

You should therefore place your subroutine definitions at the end of the program, especially for executable programs (type 1). In this way, you eliminate the risk of accidentally ending an event block in the wrong place by inserting a FORM...ENDFORM block. The USING and CHANGING additions in the FORM statement define the formal parameters of a subroutine. When you call a subroutine, you must fill all formal parameters with the values from the actual parameters. At the end of the subroutine, the formal parameters are passed back to the corresponding actual parameters. Function Modules Function modules are for global modularization, that is, they are always called from a different program. Methods describe the functions and behavior of classes and their instances in ABAP Objects. Methods must be defined in classes.

S-ar putea să vă placă și