‎2008 Apr 17 5:45 AM
hi,
i am ramarao i have a doubt please help me
what is the difference b/w macros and subroutines?
‎2008 Apr 17 5:52 AM
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 (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.
do reward if helpful
‎2008 Apr 17 5:52 AM
Hi Vinay,
Please check the following refernces for ur query :
http://sap.ittoolbox.com/documents/popular-q-and-a/macro-vs-subroutine-1594
Ref : http://www.techinterviews.com/?p=198
What is the difference between macro and subroutine?- Macros can only be used in the program the are defined in and only after the definition are expanded at compilation / generation. Subroutines (FORM) can be called from both the program the are defined in and other programs . 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 (Ive 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.
Reward if helpul,
Regards,
Esha Raj
‎2008 Apr 17 9:39 PM
main differences are:
1)we cannot call MACRO from one report to other..but we can call SUBROUTINE which are exteranl subroutines from one report to other.
2)MACRO cannot be debugging..but SUBROUTINE can debug.
3)MACRO doesn't have any parameters within decleration..but subroutine may have using,changing and table parameters.
4)MACRO's can be nested..but subroutines cannot be nested.
5)you have limit up to 9 times to call a MACRO within one program...but there is no limit for subroutine.
Reward if it useful.
Dara.
‎2008 Apr 18 5:50 AM
hi,
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.
A MACRO is more or less an abbreviation for some lines of code that are used more than once or twice.
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.
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 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.
A FORM is a local subroutine (which can be 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.
reward points if helpful,
shylaja
‎2008 Apr 18 8:29 AM
Hi,
check this link...
http://www.saptechnical.com/Tips/ABAP/GlobalMacros/Define.htm
http://www.sap-img.com/abap/abap-faq-2.htm
Regards,
kavitha..