Professional Documents
Culture Documents
T H E R E A R E D I F F. M O D U L A R IZ AT IO N T E C H N IQU ES
Macros Subroutine-Perform Function Module. Include Methods--- Oops
MACROS: Macros can only be used in the program the are defined in and only after the definition. Macros can take max 9 parameters. Macros are expanded at compilation / generation. SUBROUTINES: Subroutines (FORM) can be called from both the program the are defined in and other programs ('perform ' of 'perform in program '). Subroutines can take any amount of parameters.
SUBROUTINES: The name of a SUBROUTINE must be unique within the program (two programs can have different SUBROUTINEs with the same name). A SUBROUTINE is intended to be called internal (from within the program, however by a 'trick' you can call them external). FUNCTION MODULE: The name of a FUNCTION has to be unique throughout the system. A FUNCTION is intended to be called external (and is thus shared by 'many' programs). The latter is more important for programmers and maintenance. Since a FUNCTION is called external, it is important to keep the interface (parameters) the same. The interface of a FORM (which is intended to be called internal) is check when debugging a program (but it is only checked within the program that is debugged). So if the interface of a FORM is changed, but the call to the FORM (perform ) is not, the debugger will notice this and issue an error message.
Function Module :Function Modules are stored in the central library and can be called from any program. Even the function modules(RFC enabled) can be called from non-SAP systems. Include:Include programs allow you to use the same source code in different programs. They are mainly used for modularizing source code and have no parameter interface.
DEMO PROGRAM-1
Program Name: ZPW_MACRO1 DEFINE print. write:/ 'Hello Macro'. END-OF-DEFINITION. WRITE:/ 'Before Using Macro'. print.
OutPut :
DEMO PROGRAM-2
Program Name: DEFINE print. write:/ 'Hello', &1, &2. END-OF-DEFINITION. WRITE:/ 'Before Using Macro'. print 'ABAP' 'Macros'.
Output:
Other than readability and meaning fulness macros also offer Performance Advantage.(Prog. Name:ZPW_MACRO4). We cant call this macro from another program,But you can call global macros from another program. http://saptechnical.com/Tips/ABAP/GlobalMacros/Define.htm
Most Popular Example of System Macros or Standard global macros is BREAK. Which is defined in table TRMAC
Program Name:zpw_macro7,8,9,10
Cons: Macros can't be debugged. Hence, complex code should not be written inside macros
CONS: An include program cannot run independently, but must be built into other programs.
program. In the syntax check, the contents of the include program are also analyzed. Include programs are not
loaded at runtime, but are expanded when the program is generated. Once the program has been generated, the
load version contains static versions of all of its includes. If you subsequently change an include program, the programs that use it are automatically regenerated.(PROG. NAME:ZPW_INCULDE)