‎2007 Sep 12 9:43 PM
What is the difference between subroutine and function module?
‎2007 Sep 13 5:08 AM
Hi,
There is a difference between a Subroutine and Function Module.
1. Subroutines have no Exceptions Parameters.
FM have Exceptions parameters to catch the exceptions.
2. Subroutines can be accessed locally i.e. local Modularization Unit.
FM have Global Access i.e. they are Global Modularization Unit.
3. Subroutines can not be tested independently.
FM can be tested independently.
4. Subroutines Explicitly wont return any values.
FM explicitly returns values.
5. Subroutines is not remote Enables.
FM can be made Remote Enables and can be called from non-SAP systems.
6. Optional parameters cannot be in Subroutines.
FM can be defined with optional Parameters.
Thanks,
Samantak.
<b>Rewards points for useful answers.</b>
‎2007 Sep 13 5:14 AM
Hi,
they can both return values.
FMs are mainly used when a routine is to be performed by many programs.
Subroutines (forms) are generally only executed within one program.
You can perform routines from other programs, but it's not often done.
both forms and FMs are reusable modularization units.
To distinguish we generally say that forms are used for internal modularization and
FMs are used for external modularization.
To decide on which to implement, consider whether you need the content to be used just for a limited program
or wheteher it can be called from many independent programs.
For the first purpose it is better to implement a form whereas for the second we implement an FM.
However, ABAP does not isolate the usage context.
That is; you can call a form from another program within whose code the form is not actually implemented.
However, this requires attention since the form may utilize global variables.
The same issue holds for FMs.
FMs are encapsulated in function groups and function groups may have global variables that can be globally
used by all FMs inside it.
Thanks,
Reward If Helpful.
‎2007 Sep 13 5:17 AM