06-29-2007 4:44 PM
06-29-2007 4:48 PM
Subroutine is a Coding part which is called from some program or same program. It is generally used for Modularisation.
Function Modules are defined coding which are created for a general use and have specific purpose, they are much more customizable. You can handle data retreival based on condition and raise exception on error.
Regards
Vijai
Reward if useful
06-29-2007 4:48 PM
Subroutine is a Coding part which is called from some program or same program. It is generally used for Modularisation.
Function Modules are defined coding which are created for a general use and have specific purpose, they are much more customizable. You can handle data retreival based on condition and raise exception on error.
Regards
Vijai
Reward if useful
06-29-2007 4:59 PM
Hi
Both subroutines and FMs are reusable modularization units. To distinguish we generally say that subroutines 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.
06-29-2007 5:06 PM
06-29-2007 10:33 PM
Suroutines Vs Function modules:
1) There is no exception facility
2) We cant call subroutines from outside world as we call RFC function module
3) Function modules specially designed to update the data - as we use in BAPI's
4) FM can be executed by its own.
regards,
Dj
reward for all useful answers.
06-29-2007 10:50 PM
Hi,
One of the technical differece would be we cannot have EXCEPTIONS for subroutine's where as FM's can have EXCEPTIONS.
Another difference would be Subroutine's cannot have OPTIONAL parameters where as FM's can have.
In contrast to normal subroutines function modules have uniquely defined interface. Declaring data as common parts is not possible for function modules. Function modules are stored in a central library.
Function modules are procedures that are defined in function groups (special ABAP programs with type F) and can be called from any ABAP program.
Function groups act as containers for function modules that logically belong together.
Function modules allow you to encapsulate and reuse global functions in the R/3 System.
Unlike subroutines, you do not define function modules in the source code of your program. Instead, you use the Function Builder.
Subroutines are procedures that you can define in any ABAP program and also call from any program. Subroutines are normally called internally, that is, they contain sections of code or algorithms that are used frequently locally.
As mentioned, 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.
Subroutines are loacl to a progarm.. It cant be extended to other program.
But Function Modules are similar to subroutines but are global in view and can be used in many program.
Subroutine have three types.
pass by value, pass by reference and pass by value and reference similar to pointers but not exactly the same.
Function modules are used in BDC , BAPI etc..
Also there are standard FMs which can be used.
http://help.sap.com/saphelp_nw2004s/helpdata/en/c5/aa575926ad11d2954d0000e8353423/content.htm
http://www.sapbrainsonline.com/FAQs/TECHNICAL/SAP_ABAP_MODULARIZATION_FAQ.html
Regards,
Srilatha.