‎2008 Feb 24 7:36 AM
HI ALL,
Could anybody please tell me the difference between macro and subroutine?
‎2008 Feb 24 8:36 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.
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.
Reward Points if found helpfull..
Cheers,
Chandra Sekhar.
‎2008 Feb 24 8:10 AM
Macro:it is a code substitute. at run time if n micors are used in program it will replace the macro with actual code at every place while in subroutines only one copy of code is created at ru time between differnt calls to same routine.
It is dificult to manage Macro than the SubRoutine.
complicated code can be written in SubRoutine than macro.
‎2008 Feb 24 8:36 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.
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.
Reward Points if found helpfull..
Cheers,
Chandra Sekhar.
‎2008 Feb 24 8:47 AM
-MACRO is reusable statement .
-
DEFINE macro
Call wherever needed.
See the example code :
DATA: RESULT TYPE I,
N1 TYPE I VALUE 5,
N2 TYPE I VALUE 6.
DEFINE OPERATION.
RESULT = &1 &2 &3.
OUTPUT &1 &2 &3 RESULT.
END-OF-DEFINITION.
DEFINE OUTPUT.
WRITE: / 'The result of &1 &2 &3 is', &4.
END-OF-DEFINITION.
OPERATION 4 + 3.
OPERATION 2 ** 7.
OPERATION N2 - N1.
The produces the following output:
The result of 4 + 3 is 7
The result of 2 ** 7 is 128
The result of N2 - N1 is 1
-
SUBROUTINE :
It is also reussablethe name of the subroutine. The optional additions USING and CHANGING define the parameter interface. Like any other processing block, subroutines cannot be nested. You should therefore place your subroutine definitions at the end of the program, especially for executable programs.
syn:
Calling :
PERFORM TEST
WRITE: / fd1,fd2,fd3.
Defining:
FORM TEST
fd1 = 300
WRITE: /fd1 ,fd2
ENDFORM.
Sub types:
Internal subroutines:
Internal subroutines in the sense ..subroutines which are defined and used in a same program.
External subroutines:
External in the sense if you create a sub routine in one program and youre calling this subroutine in another program ..then this is external subroutine
Thx