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

difference between sub routine and function module

Former Member
4 REPLIES 4
Read only

Former Member
0 Likes
1,187

hi,

Subroutines:

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.

Function Modules:

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. 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 R/3 System. They are stored in a central library.

Unlike subroutines, you do not define function modules in the source code of your program. Instead, you use the Function Builder.

Read only

Former Member
0 Likes
1,187

The name of a FORM must be unique within the program (two programs can have different FORMs with the same name). A FORM is intended to be called internal (from within the program, however by a 'trick' you can call them external).

The name of a FUNCTION has to be unique throughout the system. A FUNCTION is intended to be called external (and is thus shared by 'many' programs).

The latter is more important for programmers and maintenance. Since a FUNCTION is called external, it is important to keep the interface (parameters) the same. The interface of a FORM (which is intended to be called internal) is check when debugging a program (but it is only checked within the program that is debugged). So if the interface of a FORM is changed, but the call to the FORM (perform) is not, the debugger will notice this and issue an error message.

In general:

A FORM is a local subroutine (which can be called external).

A FUNCTION is (more or less) a subroutine that is called external.

If the subroutine is used only local (called internal) use a FORM. If the subroutine is called external (used by more than one program) use a FUNCTION.

I hope it helps.

Best Regards,

Vibha

Please mark all the helpful answers

Read only

Former Member
0 Likes
1,187

subroutines r used only with in the program where we define and write the code. but function modules r created seperately in function builder(se37) and called with a program.

subroutine is valid in only in the program where we write. but in the case of function module can be called in any program.

Read only

Former Member
0 Likes
1,187

Hi sravanthiaksha krishna ,

These r the differences between sub routine and function module:

1) We CANNOT handle exceptions in subroutines whereas exceptions can be handled in function-module.

2) Function modules return a value whereas subroutines do not return a value

3) Function modules can also be called from a remote system whereas subroutines cannot be called from a remote system.

4) Function modules will be stored in function group

cheers!

gyanaraj

****Pls reward points if u find this helpful