您的位置:首页 > 其它

Macro VS Subroutine(ABAP)

2006-07-19 11:25 316 查看
Modularization technique
1.     Source code modules(expanded at compilation:编译时展开,没有压栈弹栈操作,系统开销小!)
a.     MacrosMacros are a text substitute for the translation phase,相当于字符替换
b.     Include Programs
2.     Procedures(expanded at runtime: 运行时展开,编译时和主程序是两个部分,运行时,将要调用的程序压栈,然后弹栈调用。)
a.     Subroutine
b.     Function Modules
c.     Methods
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.
Notes: that means Macro is expanded at complication but subroutines are 'expanded' at runtime.
 
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 are 'expanded' at runtime.
 
Functions are just like FORMs, but are intended to be called external.
 
Some differences between FUNCTIONs and FORMs:
The name of a FORM must be unique within the program (two programs can have different FORMs with the same name). A FORM is intended to be called internal (from within the program, however by a 'trick' you can call them external).
 
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.
 
In general:
A MACRO is more or less an abbreviation for some lines of code that are used more than once or twice.
A FORM is a local subroutine (which can be called external).
A FUNCTION is (more or less) a subroutine that is called external.
 
Since debugging a MACRO is not really possible, prevent the use of them (I've never used them, but seen them in action). If the subroutine is used only local (called internal) use a FORM. If the subroutine is called external (used by more than one program) use a FUNCTION.
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息