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.
Showing results for 
Search instead for 
Did you mean: 

subroutine & FM

Former Member
0 Kudos

Hi All,

Can anybody tell me about the main difference between subroutine and a function module???

Thanks in Advance!



Former Member
0 Kudos

function modules are mainlu useful n case of global declaration. and function modules return values whee as subroutines doex not.


Active Contributor
0 Kudos



select * FROM ..........






FM can be used in different programs.

Subroutine can be used only in a single program

Former Member
0 Kudos

function modules are mainlu useful n case of global declaration. and function modules return values whee as subroutines doex not.

Active Contributor
0 Kudos


Sunroutines and function modules does the same work..

Subroutines are with in a program and Function modules are global across SAP..

you can call FM in any program but Subroutine you can call with in a program..

they can both return values.

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.

Subroutines are defined locally in the program and FMs are globally defined in SAP system.

You cant upload data or remotely access data using Subroutines, its possible in FM

rewads if useful,



Former Member
0 Kudos

Subroutine can be used in the same program and it is not global.

FM can be used by any number of programs and are global.

You can create your own FMs too and use existing FMs which are defined for different puposes

Active Contributor
0 Kudos

Hi Kiran..

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


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.

<b>Reward if helpful</b>

0 Kudos


Subroutine <b>cannot have OPTIONAL</b> parameters.

Subroutine is <b>not a seperate reposiotry</b> object.(<b>No TADIR entry</b> for routines)

Subroutine <b>cannot be Remote</b> enabled.

Subroutine <b>cannot have Exceptions</b>

You can create as many subroutines as you want in a Function group but you can create only <b>99 Function modules.</b>



Former Member
0 Kudos


Sub routine is local with in the program... Ofcourse there are ways to access subroutines from other programs...

Function Modules are global throughout the system... And one more advantage is we can make function module remote enable to access data from ohter clients/systems.

Returning values means for a subroutine or a function module u will exporting some values and based on that values the subroutine or fm will perform some logic, based on that logic the values which u have send may change so they will be returned to ur program.

for ex: to a function module u have exported a and b values and importing c in the function module

c = a + b. So here it will return the sum of a and b through c.

That is what is called as returning the values.



Former Member
0 Kudos

Hi kiran,

Differences between subroutine and FM r as follows:

<b>Function</b> : Stored in the central library and has a global presence.

<b>Subroutine</b> : It is confined to a particular program.

<b>Function</b> : It can return values.

<b>Subroutine</b> : It cannot return values.

<b>Function</b> : Can handle exceptions.

<b>Subroutine</b> : Can't handle exceptions.

<b>Function</b> : The way the parameters are passed will differ from that subroutine.



Reward points if useful.

Former Member
0 Kudos

Compared to Subroutines, FMs have a well defined Interface and exception handling mechanism. All the global data within a Function group can be accessed by all the FMs in that group.