Application Development 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: 

Difference between....

Former Member
0 Kudos

Hi SDNers,

What is the exact difference between Function module, (internal ) sub routine and external sub routine.

Thanks in advance.

Senthil kumar

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Function Module:

These are for Global modularizaiton. Name of a FM is unique within SAP.

Can be independently tested

Can be Remote enabled.

Can have exceptions

Subroutine:

These are for Local modularizaiton. Name of a subroutine is unique within a PROGRAM.

Cannot be independently tested

Cannot be remote enabled

Cannot have exceptions.

6 REPLIES 6

Former Member
0 Kudos

hi,

Here is the notes of differences bet. FM and Subroutines.

Hi Function modules are for modularization urpose. You can the Function Module in any program. That is available all over in the SAP system.

Where as subroutine is program specific. Once you create a subroutine in one program then you can use that in that program and related programs like includes in the program or you have to call the subroutine specifically using the main program name.

Finally subroutines are for program modularization. Not for generic use.

FM's are for generic use. Not program dependent.

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.

<b>Here is the notes of differences bet. internal Subroutines and external subroutines[/b

Subroutines are program modules, which can be called from other ABAP/4 programs or within the same program.

types of subroutines:

<b>Internal Subroutines</b>: The source code of the internal subroutines will be in the same ABAP/4 program as the calling procedure (internal call).

<b>External Subroutines</b>: The source code of the external subroutines will be in an ABAP/4 program other than the calling procedure.

It is possible to create an ABAP/4 program, which contains only Subroutines

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

thanks,

reward points if helpful....

Message was edited by:

Velmurugan

Message was edited by:

Velmurugan

Former Member
0 Kudos

Hi,

Function Module:

These are for Global modularizaiton. Name of a FM is unique within SAP.

Can be independently tested

Can be Remote enabled.

Can have exceptions

Subroutine:

These are for Local modularizaiton. Name of a subroutine is unique within a PROGRAM.

Cannot be independently tested

Cannot be remote enabled

Cannot have exceptions.

Former Member
0 Kudos

Hi,

There are differeneces when you should use FM and Sub routines

1. FM -


When your code can be generalised and reused in many programs

2. Subroutines --- When your logic is common inside a program and need to access it many times and not relevant outside that code.

Former Member
0 Kudos

Hi,

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.

Function module's are independent of all the objects i.e., they can be called any where in any of the objects. The main purpose of function module is code reusability. If you need the same functionality in many programs, you will write the code only once and use in many programs.

Subroutines are local to the objects in which they are defined i.e., subroutines can be accessed in the program or includes within the function group in which they are defined.

There is one difference between calling a function module and subroutine. When function module is called within a loop the time taken for that will be more, whereas if you call a subroutine within a loop the time taken for that will be nill.

So compared to performance wise subroutine will be executed within no time. For this you can see the SAP example programs.

Go to SE38 -> Click on Environment menu -> Examples -> Performance Examples -> ABAP Objects

double click on 'Methods Vs Subroutines' and click on Measure runtime button on the application toolbar.

again double click on 'Methods Vs Function Modules' and clik on Measure runtime button on application toolbar.

Now you can find the difference between executing a Function module and Subroutine

<b>And i am here giving link which it clearly given concepts by quest and anws</b>

IMP link

http://www.sapbrainsonline.com/FAQs/TECHNICAL/SAP_ABAP_MODULARIZATION_FAQ.html

<b>Reward with points if helpful.</b>

Regards,

Vijay

hymavathi_oruganti
Active Contributor
0 Kudos

hi ,

The main difference we can speak in one line is

Fuction modules are for <b>global modularization</b> and subroutines are for <b>local modularization.</b>

Former Member
0 Kudos

Hi Senthil,

Internal subroutine: Here the source code will be in the same ABAP/4 program.

Ext subroutine: source code will be in the ABAP/4 program other than the calling procedure..

In contrast to FM ,subroutines have uniquely defined interface.

subroutines do not return values nor exceptions..

subroutines cannot be tested independently...

FM are stored in the central library..