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: 

regarding funtion module

Former Member
0 Kudos

I would like to know the difference between the function module and sub-routines.

In whats scenario we use them .

how sub-routine varies precisely from function module , if so what are the advantages of fun. module over sub-routine.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi raj,

here's your answer, hope it satisifes you

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

FM

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

SUBROUTINES

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.

<REMOVED BY MODERATOR>

Rohan malik

Edited by: Alvaro Tejada Galindo on Feb 12, 2008 11:47 AM

5 REPLIES 5

Former Member
0 Kudos

The main difference between a function module and a normal ABAP/4 subroutine is as follows:

Function is stored in central library and has global presence while subroutines are confined to a particular program. Subroutine cannot return values while functions can return values. Unlike functions, subroutine cannot handle exceptions. And last but not least, the difference in the way the parameters are passed to functions.

Declaring data as common parts is not possible for function modules. The calling program and the called function module have separate work in ABAP/4 Dictionary tables.

You use the ABAP/4 Workbench to call, create, and maintain function modules.

You can combine several function modules to form a function group in the function library. Since you can define global data that can be accessed from all function modules of one function group, it is reasonable to include function modules that operate with the same data, for example internal table for sales module can be grouped, in one function group.

Former Member
0 Kudos

hi raj,

here's your answer, hope it satisifes you

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

FM

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

SUBROUTINES

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.

<REMOVED BY MODERATOR>

Rohan malik

Edited by: Alvaro Tejada Galindo on Feb 12, 2008 11:47 AM

Former Member
0 Kudos

hi

good

The main difference is ,

-> U can handle Exceptions in FM wheras in Subroutines its not possible.

-> FM's are stored in Global class and have Global Presence, Subroutines may or may not have global presence( as in case of external subroutines).

-> FM's can be executed dircetly and tested whereas Subroutines cannot be executed Independently even in external subroutines.

thanks

mrutyun^

Former Member
0 Kudos

Hi,


In contrast to the normal subroutines function modules have uniquely defined interface.
Sub routines do not return values.
Sub routines do not return exceptions.
Sub routines cannot B tested independently.
Declaring data as common parts not possible for function modules. Function modules r stored in the an central library.

Thanks,

Sriram Ponna.

Former Member
0 Kudos

Sub routines :

1. Sub routines doesn't return any values.

2. Sub routines in one R/3 can't be accessed by another R/3 systems.

3. Sub routines for local programs and current client only.

Function modules :

1. Function modules are global for all programd and all clients.

2. Function modules are accessed by same R/3 another R/3 and non R/3 systems also.

3. Function modules should return a value(more than one also)

4. Function modules are used at Module pool programs, BDCs, Scripts and smart forms.