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 & Function Module

Former Member
0 Likes
2,493

HI Experts,

Plz give me similarities & Diffrences between External Subroutine & Function Modules.

thanks.

Khan

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,671

Subroutines - u cant return any value where as u can do the same with FMs, exception handling doesnt exist in Subroutines and they cannot be called outside teh program

5 REPLIES 5
Read only

Former Member
0 Likes
1,672

Subroutines - u cant return any value where as u can do the same with FMs, exception handling doesnt exist in Subroutines and they cannot be called outside teh program

Read only

0 Likes
1,671

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. The R/3 System contains a wide range of predefined function modules that you can call from any ABAP program. Function modules also play an important role in database updates and in remote communications between R/3 Systems or between an R/3 System and a non-SAP system.

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.

Subroutines are principally for local modularization, that is, they are generally called from the program in which they are defined. You can use subroutines to write functions that are used repeatedly within a program. You can define subroutines in any ABAP program

Regards,

JLN

Read only

Former Member
0 Likes
1,671

External Subroutines are better for documentational purposes. You can have all the subroutines related to the program into single include program.

Another difference is that they are compiled with the program so they share the same memory, so there's no context change while calling a subroutine. It does save system time.

Also, you can access all the global variables of the program in External subroutine but you can not access them in Function module unless they are passed as a parameter.

Which one to use depends on the case you are dealing with.

For example, if you are developing functionality to convert ouptut in PDF format then it is better to create a function module so that all the programs across all packages can use that functionality.

if you are developing functionality which will be used by a defined set of programs(which are handling same kind of data) then it's better to use External subroutines, where you can defined common data in External subroutines program.

In External subroutine perform statement is in one program and form routine is in another program.It is used for Reusability purpose.

Check this Link,

http://help.sap.com/saphelp_erp2004/helpdata/en/9f/db999535c111d1829f0000e829fbfe/frameset.htm

************************************************

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

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

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.

Read only

Former Member
0 Likes
1,671

SUBROUTINES

The process of breaking down a large program into smaller modules is supported by ABAP/4 through subroutine, also called forms.

FUNCTION MODULES

Function modules are special external subroutines stored in a central library. The R/3 system provides numerous predefined function modules that you can call from your ABAP/4 programs, and plus you can create your own function modules.

Thanks and Regards,

Dharani Kumar G

Read only

1,671

The main four differences of SUBROUTINE ----------v----------FUNCTION MODULE

1) Subroutines are local that means we can access them within the server itself but with regards to function module they are global and can be accessed within and also outside the server.

2) We can't test the subroutines independently without calling it but function modules can be tested independently.

3) Can't handle errors in subroutines , can handle the errors through exceptions in function module.

4) Subroutines are defined in ABAP-editor and function modules are defined in function builder SE37.