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

What is the difference between subroutine and function module?

Former Member
0 Likes
421

What is the difference between subroutine and function module?

3 REPLIES 3
Read only

Former Member
0 Likes
400

Hi,

There is a difference between a Subroutine and Function Module.

1. Subroutines have no Exceptions Parameters.

FM have Exceptions parameters to catch the exceptions.

2. Subroutines can be accessed locally i.e. local Modularization Unit.

FM have Global Access i.e. they are Global Modularization Unit.

3. Subroutines can not be tested independently.

FM can be tested independently.

4. Subroutines Explicitly wont return any values.

FM explicitly returns values.

5. Subroutines is not remote Enables.

FM can be made Remote Enables and can be called from non-SAP systems.

6. Optional parameters cannot be in Subroutines.

FM can be defined with optional Parameters.

Thanks,

Samantak.

<b>Rewards points for useful answers.</b>

Read only

Former Member
0 Likes
400

Hi,

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.

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.

Thanks,

Reward If Helpful.

Read only

Former Member
0 Likes
400

check the thread from sdn: