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

Diff betn FM & Subroutine

Former Member
0 Kudos

What is the differnce betwn subroutine and function module?

6 REPLIES 6

che_eky
Active Contributor
0 Kudos

Easy!

CALL FUNCTION <function name>

and

PERFORM <subroutine>

Former Member
0 Kudos

subroutines cann't call remotely

cann't test individually

cann't handle exceptions and return values.

and we'll pass values in the way of using, changing and tables but in case of FM we use import export tables like that

subroutines use ABAP memory but FM use SAP memory

if u call FM the whole Function group is come into sap temporary memory.

Madhavi

andreas_mann3
Active Contributor
0 Kudos

fm's and functions(in a class) are like enclosed in a capsule and called from many other programs

subroutines are only created for one or some (external perform) programs.

A.

Former Member
0 Kudos

Hi Khanna,

This description below might help u out...

Function modules are procedures that are defined in special ABAP programs only, so-called function groups, but can be called from all ABAP programs. Function groups act as containers for function modules that logically belong together. You create function groups and function modules in the ABAP Workbench using the Function Builder.

Function modules allow you to encapsulate and reuse global functions in the SAP System. They are managed in a central function library. The SAP System contains several predefined functions modules that can be called from any ABAP program. Function modules also play an important role during updating and in interaction between different SAP systems, or between SAP systems and remote systems through remote communications.

Unlike subroutines ,you do not define function modules in the source code of your program. Instead, you use the Function Builder. The actual ABAP interface definition remains hidden from the programmer. You can define the input parameters of a function module as optional. You can also assign default values to them. Function modules also support exception handling. This allows you to catch certain errors while the function module is running. You can test function modules without having to include them in a program using the Function Builder.

The Function Builder also has a release process for function modules. This ensures that incompatible changes cannot be made to any function modules that have already been released. This applies particularly to the interface. Programs that use a released function module will not cease to work if the function module is changed.

A subroutine is a block of code introduced by FORM and concluded by ENDFORM.

FORM <subr> [USING ... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ]

[CHANGING... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ].

...

ENDFORM.

<subr> is the name of the subroutine. The optional additions USING and CHANGING define the parameter interface. Like any other processing block, subroutines cannot be nested. You should therefore place your subroutine definitions at the end of the program, especially for executable programs (type 1). In this way, you eliminate the risk of accidentally ending an event block in the wrong place by inserting a FORM...ENDFORM block.

Reward if helpful.

Thankyou,

Regards.

Former Member
0 Kudos

Hi,

Function modules are procedures that are defined in special ABAP programs only, so-called function groups, but can be called from all ABAP programs. Function groups act as containers for function modules that logically belong together. You create function groups and function modules in the ABAP Workbench using the Function Builder.

Function modules allow you to encapsulate and reuse global functions in the SAP System. They are managed in a central function library. The SAP System contains several predefined functions modules that can be called from any ABAP program. Function modules also play an important role during updating and in interaction between different SAP systems, or between SAP systems and remote systems through remote communications.

Unlike subroutines, you do not define function modules in the source code of your program. Instead, you use the Function Builder. The actual ABAP interface definition remains hidden from the programmer. You can define the input parameters of a function module as optional. You can also assign default values to them. Function modules also support exception handling. This allows you to catch certain errors while the function module is running. You can test function modules without having to include them in a program using the Function Builder.

The Function Builder also has a release process for function modules. This ensures that incompatible changes cannot be made to any function modules that have already been released. This applies particularly to the interface. Programs that use a released function module will not cease to work if the function module is changed.

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.

Regards,

Renjith Michael.

Former Member
0 Kudos

subroutines:

  • doesn't return values to calling ptogram

*cannot handle exceptions

*subroutines cannot be executed standalone.

function module

*returns the values to calling program

*can handle exceptions

*can be executed standalone.