Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Regarding difference between Subroutines and Function modules

Former Member
0 Likes
1,073

Hello evrybody,

Whether both subroutines and functional modules are client dependent.

What is the technical difference between subroutines and function modules

with regards,

chandrika

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
889

Hi chandrika,

The subroutines are basically modularized code of a report or a module pool program or even a function module.

But these subroutines are restricted to be used for that report or module pool program/function modules.So subroutines are program specific and so client dependent.You can alway have an include with subroutines written and u can use this include in different program, may it be a module pool program or a report.

Function modules are also client dependent and they when excuted for different clients will yield different results since they refer to client dependent tables in the system.

Although they may have interface same as subrotines like importing exporting changing and tables....

They can be independently used in any program.

So both they are reusable.

Please let me know for further clarifications.

6 REPLIES 6
Read only

Former Member
0 Likes
890

Hi chandrika,

The subroutines are basically modularized code of a report or a module pool program or even a function module.

But these subroutines are restricted to be used for that report or module pool program/function modules.So subroutines are program specific and so client dependent.You can alway have an include with subroutines written and u can use this include in different program, may it be a module pool program or a report.

Function modules are also client dependent and they when excuted for different clients will yield different results since they refer to client dependent tables in the system.

Although they may have interface same as subrotines like importing exporting changing and tables....

They can be independently used in any program.

So both they are reusable.

Please let me know for further clarifications.

Read only

0 Likes
889

Hi Chandrika,

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,

Srinivas

Read only

0 Likes
889

Dear Srinivas,

My purpose of declaring client dependency was to emphasize on the reasult they output.I completely agree that the piece of code u write is client independent but not the results.And the point that u mentioned that subroutines are not entirely program denpendent is not convincing, as the subroutines which u write as you have mentioned to suit your purpose is also an incude( right ) which i had mentioned in the earlier context; and has to be included in your program before use.

Thanks Bye

Read only

Former Member
0 Likes
889

hi chandrica,

following r the major differences between subroutine and function modules :

1.Functions can handle exceptions but subroutine cannot.

2.function module can be tested independently whereas subroutine cannot.

3.FM returns value whereas subroutine may or may not return values.

4.FM globally called anywhere in ABAP program whereas subroutine always called before defining the subroutines.

regards

rajdeep singh flora

Read only

Former Member
0 Likes
889

Hi chandrika

A good design always looks for modularization and reuse of code. Subroutines and function modules are used for this purpose.

In normal scenario, Subroutines are defined and used locally in a program. Although, you can use subroutines of other programs also, as well as you can define subroutines in a subroutine-pool and use in in many programs.

But main motive of subroutines is modularization of code so that it is easy to understand and maintain.

Function module is the bigger scenario for reuse of code. Main motive is to create the functionality once at database level and use it again and again. Also, it makes the code more reliable, if we know that function module is correct, we just need to use it correctly.

Regards

Ashish Jain

Read only

Former Member
0 Likes
889

Function Modules can be remote enable, which is not possible in subroutines.