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

subroutine & FM

Former Member
0 Likes
1,278

Hi All,

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

Thanks in Advance!

Kiran

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,226

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

10 REPLIES 10
Read only

Former Member
0 Likes
1,226

<b>SUBROUTINE</b>

PERFORM GET_DATA.

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

ENDFORM.

<b>FM</b>

COMMIT_WORK

GUI_DOWNLOAD

GUI_UPLOAD

FM can be used in different programs.

Subroutine can be used only in a single program

Read only

Former Member
0 Likes
1,227

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

Read only

Former Member
0 Likes
1,226

Hi,

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,

regards,

nazeer

Read only

Former Member
0 Likes
1,226

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

Read only

varma_narayana
Active Contributor
0 Likes
1,226

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

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.

<b>Reward if helpful</b>

Read only

former_member404244
Active Contributor
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
1,226

Hi,

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>

Regards,

Sesh

Read only

Former Member
0 Likes
1,226

Hi,

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.

Regards,

Priyanka.

Read only

Former Member
0 Likes
1,226

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.

Regards...

Arun.

Reward points if useful.

Read only

Former Member
0 Likes
1,226

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.