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

Subroutines

Former Member
0 Likes
1,227

In interview ince i had faced the following question.Please reply me for this:

What is the difference between Subroutine and Function Module???

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,203

Hi

Subroutines are attatched with program,

so if you use it in the same program its called internal subroutine which is called directly using perform

If you want to call subroutine which is present in diff. program, called EXTRENAL subroutine, you have to specify the Program name also in perform

Function module are present across the clients.

8 REPLIES 8
Read only

Former Member
0 Likes
1,203

Hi,

Subroutine is a reusable piece of code which is used insdie a single program.

e.g.

anything between FORM ....ENDFORM

Function Module is a reusable piece of code which can be used across different programs.

e.g

CALL FM 'COMMIT_WORK'.

Best regards,

Prashant

Read only

Former Member
0 Likes
1,203

A subroutine cant be accessed by all the programmes while FM can be accessed by all the programs...

A subroutine doesnt have exceptions while a FM can have exceptions

Read only

Former Member
0 Likes
1,203

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,Unlike subroutines, you do not define function modules in the source code of your program.

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

reward points if it helps

Kishi.

Read only

Former Member
0 Likes
1,203

Hi Reema,

Subroutines are program modules, which can be called from other ABAP/4 programs or within the same program. Mainly its used for Modularisation of Programs

<u>Internal Subroutin</u>es: The source code of the internal subroutines will be in the same ABAP/4 program as the calling procedure (internal call).

<u>External Subroutines</u>: The source code of the external subroutines will be in an ABAP/4 program other than the calling procedure.

In contrast to normal subroutines function modules have uniquely defined interface. Declaring data as common parts is not possible for function modules. Function modules are stored in a central library.

Regards

Avi..

Read only

Former Member
0 Likes
1,203

Hi,

In contrast to normal subroutines function modules have uniquely defined interface. Declaring data as common parts is not possible for function modules. Function modules are stored in a central library.

Regards

Sudheer

Read only

Former Member
0 Likes
1,204

Hi

Subroutines are attatched with program,

so if you use it in the same program its called internal subroutine which is called directly using perform

If you want to call subroutine which is present in diff. program, called EXTRENAL subroutine, you have to specify the Program name also in perform

Function module are present across the clients.

Read only

Former Member
0 Likes
1,203

Hi,,

check if the following info is useful to you

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.

Function module ::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. 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

Read only

Former Member
0 Likes
1,203

Main thing is u can test the function module independently but not the subroutines.

Both these function modules and subroutines are similar to methods in OOPS.

The function modules are global calls where u can call the function modules from any program.

Whereas the subroutines called with in the program but we can make dynamic subroutines calls from other programs also.

Regards

Santhosh

Message was edited by:

santhosh ds