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

Modularization

Former Member
0 Likes
1,190

Hi experts,

can any one explain me the main differences between subroutines and function modules?

Thanks in advances.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,149

Hi,

FM are created in Function Builder (SE37) and belong to a program of type Function Group. A FM has a parameter interface that includes EXCEPTIONS tab that can be used to declare exceptions that can be thrown by the FM. This can be checked using SY-SUBRC field after the FM call. Since they are defined in SE37, they are global and can be called by any program or FM in the same system or can also be called by a remote system, if declared as RFC enabled. Also, only FM can be used for updating database using UPDATE TASK.

Subroutines are defined as part of a program of type Executable, Module Pool, Include, Subroutine Pool and Function Group. They also have parameter interface that consists of USING CHANGING and TABLES (Obsolete) additions. They are not global, though they can be called from other programs or FM in the same system by supplying the program name to which belong in parentheses. They cannot be used for remote calls or updating database using UPDATE TASK.

Functionality-wise they do the same job i.e. they are called by a clling program with some parameters and they may or may not return a result.

The main differences between a function module and subroutine.

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.

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.

Regards,

Mahesh

9 REPLIES 9
Read only

prasanth_kasturi
Active Contributor
0 Likes
1,149

hi,

Subroutienes cannot be executed alone where as fms can

subroutienes use program memory but fm use seperate memory space

regards

prasanth

Read only

Former Member
0 Likes
1,149

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. 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

Thanks

Virkanth

Read only

Former Member
0 Likes
1,150

Hi,

FM are created in Function Builder (SE37) and belong to a program of type Function Group. A FM has a parameter interface that includes EXCEPTIONS tab that can be used to declare exceptions that can be thrown by the FM. This can be checked using SY-SUBRC field after the FM call. Since they are defined in SE37, they are global and can be called by any program or FM in the same system or can also be called by a remote system, if declared as RFC enabled. Also, only FM can be used for updating database using UPDATE TASK.

Subroutines are defined as part of a program of type Executable, Module Pool, Include, Subroutine Pool and Function Group. They also have parameter interface that consists of USING CHANGING and TABLES (Obsolete) additions. They are not global, though they can be called from other programs or FM in the same system by supplying the program name to which belong in parentheses. They cannot be used for remote calls or updating database using UPDATE TASK.

Functionality-wise they do the same job i.e. they are called by a clling program with some parameters and they may or may not return a result.

The main differences between a function module and subroutine.

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.

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.

Regards,

Mahesh

Read only

Former Member
0 Likes
1,149

check this

https://www.sdn.sap.com/irj/sdn/directforumsearch?threadid=&q=differencesbetweensubroutinesandfunction+modules%3F&objID=&dateRange=last90days&numResults=15

Read only

Former Member
0 Likes
1,149

hi,

Please search forums first ... Here are the related threads

Read only

Former Member
0 Likes
1,149

Hi,

1. FM are Global . Any program can use it.

where else for subroutines, we have to use the INCLUDE.

2. Most important -

FMs can be tested thru se37

whereas for testing subroutines, we have to write some abap code.

3. FMS have WELL DEFINED interface, and it can be documented for each parameter.

Whereas subroutines do not have such great facility.

4. FMs can be update task, RFC etc.

whereas subroutines are much limited.

Thanks

Vikranth

Read only

former_member195383
Active Contributor
0 Likes
1,149

suppose u have one program..that program can use any function module which is existing...But it can use a subroutine...which is defined either inside this program or inside the include, which this program is having...

Reward points...if the abv ans is helpful

Read only

Former Member
0 Likes
1,149

Hi,

Subroutines are dependent i.e they cannot exist without a program whereas FM are independent.

Subroutines doesn't return any values while FMs return values.

we use using, changing in case of subroutines while we use import export incase of FM.

Declaring data as common parts is not possible for function modules

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

Thanks and regards.