‎2006 Sep 08 8:16 AM
Dear all ,
Could you please State the Diff between Subroutines & Function Modules as a Defintion. I woiuld like to know with Difference. I know that both can be maintained Globally. But i need the Actual Difference between those.
Thanks,
Satya
‎2006 Sep 08 8:18 AM
subroutines are which we define
function modules are already defined
‎2006 Sep 08 8:18 AM
hi,
subroutine - same like copying the part.
when we call a subroutine that rountine is simply copied to the called area.control is still with the program
function module - control will be passed to the function.
after execution the control is given back to the program.
for any clarifiaction pls mail me.
pls reward points, if this helped u.
regards,
anversha.
anversha.shahul@wipro.com
‎2006 Sep 08 8:18 AM
subroutines are which we define
function modules are already defined
‎2006 Sep 08 8:20 AM
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. They are stored in a central library,Unlike subroutines, you do not define function modules in the source code of your program.
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. If you want a function to be reusable throughout the system, use a function module
‎2006 Sep 08 8:23 AM
Function Modules in SAP are nothing but global Subroutines. Subroutine is a generic term given to all
reusable program codes. Subroutines can be defined locally also.
e.g.
Form xyz.
...
Endform
Regards.
‎2006 Sep 08 8:23 AM
Ok .......... apart from the above there is one very imp. deff. ..
In function modules you can define and raise expection which you can not do with subroutine...
‎2006 Sep 08 8:25 AM
Hello,
FM - (predefined) the FM takes the control of the program and gives it back when it is excecuted.
SR - (self-defined) the program has the control and only the subroutine is copied to the area frm where it was called.
hit back,
Shehryar
‎2006 Sep 08 8:29 AM
‎2006 Sep 08 8:26 AM
Hi,
I was looking at the responses given here for your question. I am sorry but I have to disagree with Karthik here. Client dependency or client independent does not come into picture in this discussion at all. Any piece of code(subroutines, function modules or programs etc) is client independent, which means if you write a piece of code in one client, then that is visible and can be executed from anywhere. Whether they work on client independent tables or client dependent tables, is up to the purpose of the code. There is no restriction that you cannot select data from client independent tables in sub routines or function modules.
Also, another point made by Karthik that subroutines are specific to a program is not entirely true. If the subroutine logic and the parameters suit your purpose, you can always call a subroutine of another program in your program, even though it is rarely used.
The intended purpose of subroutines is to provide more modularization and readability, but added advantage is that it can also be used for reusability.
The intended purpose of function modules is more for reusability and encapsulation. So if you want to encapsulate certain reusable logic and provide a standard interface to the outside world. Please note that the primary stress here is on reusability and encapsulation and not on modularization, whereas in subroutines that is the primary purpose, but has the others as secondary benefits.
A function module exists as an independent executable piece of code, but a subroutine can only be executed within a main program. So the context in which they are executed during runtime are different.
If these answers give you enough insight into the two constructs, please rewarad and close the post.
Regards,
Ram
Pls reward points if useful
‎2006 Sep 08 9:41 AM
hi,
FMs have fixed interface definition, i.e. we can not use an export parameter for reading value from caller or we can not use import paramter for outputing value to the caller. whereas, subroutine's interface definition is not fixed, we can do whatever we wish with the paramters of the subroutine.
Regards,
VINNY