‎2008 Jun 12 6:28 AM
Hi,
1. Whether we can call a subroutine inside a function module...
2.what is the difference between function module and subroutine
‎2008 Jun 12 6:36 AM
hi,
Function modules are special external subroutines(program type F)
Function modzules are classified in function groups and stored in the Function Library. Function groups act as containers for function modules that logically belong together.
Function modules allow us to encapsulate and reuse global functions in the R/3 System.
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.
The R/3 System provides numerous predefined function modules that we can call from your ABAP/4 programs. We can also create your own function modules using Function Builder. (Transaction Code SE 37)
Subroutines are principally for local modularization while Function modules are for global modularization, that is, they are always called from a different program.
Subroutines are defined in ABAP programs while Function modules are defined within function groups
Function modules have clearly defined data interfaces to the calling program.
We can test function modules in a stand-alone mode independent of the calling program.
regards,
sreelakshmi
‎2008 Jun 12 6:36 AM
hi,
Function modules are special external subroutines(program type F)
Function modzules are classified in function groups and stored in the Function Library. Function groups act as containers for function modules that logically belong together.
Function modules allow us to encapsulate and reuse global functions in the R/3 System.
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.
The R/3 System provides numerous predefined function modules that we can call from your ABAP/4 programs. We can also create your own function modules using Function Builder. (Transaction Code SE 37)
Subroutines are principally for local modularization while Function modules are for global modularization, that is, they are always called from a different program.
Subroutines are defined in ABAP programs while Function modules are defined within function groups
Function modules have clearly defined data interfaces to the calling program.
We can test function modules in a stand-alone mode independent of the calling program.
regards,
sreelakshmi
‎2008 Jun 12 6:42 AM
You can call subroutine inside function module. To do this subroutine must be defined in the same function pool as function module calling subroutine.
Difference:
Function module is global subprogram.
Subroutine is local subprogram. So you can call it from program where it was defined.
‎2008 Jun 12 7:08 AM
Hi,
Yes we can a subroutine in function module.
Subroutines
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.
Function Modules
Function modules are for global modularization, that is, they are always called from a different program. Function modules contain functions that are used in the same form by
many different programs. They are important in the R/3 System for encapsulating processing logic and making it reusable. Function modules must be defined in a function
group, and can be called from any program.
If you only want to call a subroutine from a single function module, it is best to define them in the same include program as the function module itself, directly
after the ENDFUNCTION statement. These subroutines can be called from all function modules in the function group, but for clarity, they should only be called from the function module that precedes them.
Plz reward if useful.
Dhanashri.
‎2008 Jun 12 7:23 AM
1. Yes we can call a subroutine inside a Function Module. Either you can define that subroutine in a separate INCLUDE fine in the Function Group, or In the same include of Function module after ENDFUNCTION statement.
2.Subroutine are program specific. They are declared and used inside a single Program. But Function Modules can be called from any Program.Subroutines are not Repository Object, their name and details are not maintained anywhere, where as Function Modules are repository object, they are maintained as independent object. You can not test a subroutine separately, bit you can test a function module separately.
‎2008 Jun 12 7:36 AM
hi
SubRoutine
Program module that can be called by any program.
You use subroutines to avoid having to write frequently used program components more than once. Data can be passed explicitly from and to 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.
There are two types of subroutine:
internal subroutines
external subroutines
internal subroutines are called internally in the program.
external subroutines are called from other programs.
Defining Subroutines
A subroutine is a block of code introduced by FORM and concluded by ENDFORM.
FORM <subr> [USING ... VALUE(<pi>[)] TYPE <t>
[CHANGING... VALUE(<pi>[)] TYPE <t>.
...
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.
Calling Subroutines
You call subroutines using the statement
PERFORM... http://USING ... <pi>...
http://CHANGING. <pi>... .
Subroutines can call other subroutines (nested calls) and may also call themselves (recursive calls). Once a subroutine has finished running, the calling program carries on processing after the PERFORM statement. You can use the USING and CHANGING additions to supply values to the parameter interface of the subroutine.
the variables declared inside the program are local to that routine.
Function Modules
Function modules are external subroutines written in ABAP. Developed in the Function Builder, they are managed in a central function library, and can therefore be called from any ABAP program. This helps to avoid redundant code and makes the programming process more effective.
In contrast to FORM routines, function modules have the same standard interface.
Overview of Function Modules
Function modules are ABAP routines that are stored in a central function library. They are not application-specific, and available systemwide. The ABAP Workbench comes with a large number of standard function modules.
Like form routines, function modules encapsulate program code, and provide an interface for data exchange.
However, there are significant differences between function modules and form routines:
Function modules must belong to a pool called a function group.
They possess a fixed interface for data exchange. This makes it easier for you to pass input and output parameters to and from the function module.
For example, you can assign default values to the input parameters. The interface also supports exception handling. This allows you to catch errors and pass them back to the calling program for handling.
They use their own memory area. The calling program and the function module cannot exchange data using a shared memory area - they must use the function module interface. This avoids unpleasant side effects such as accidentally overwriting data.
You call a function module by its name (which must be unique) in a CALL FUNCTION statement.
The Function Builder allows you to develop, test, and document new function modules. You can also use it to display information about existing function modules:
Administration
Specifies information like the development class a function belongs to, the person responsible for the module, a short description of the module.
Import
Contains a list of the formal parameters that are used to pass data to a function module. For further information, refer to Displaying Information about Interface Parameters
Export
Contains a list of the formal parameters that are used to receive data from a function module. For further information, refer to Displaying Information about Interface Parameters
Changing
Contains a list of the formal parameters that are used both to pass data to and receive data from a function module. For further information, refer to Displaying Information about Interface Parameters
Tables
Specifies the tables that are to be passed to a function module. Table parameters are always passed by reference. For further information, refer to Displaying Information about Interface Parameters
Exceptions
Shows how the function module reacts to exceptions. For further information, refer to Displaying Information about Interface Parameters
Documentation
Provides information about the interface and exceptions
Source code
Program code of the function module
Global data
The global data used by the function module.
Main program
Program code of the main program.
Function modules play an important role in the modularization of applications. You can use them to encapsulate a particular function or group of related functions.
Modularization allows you to avoid redundancy. It also makes your programs easier to read and understand.
Modularized programs are easier to maintain and keep up-to-date.
The modularization principle:
Function Groups
The Function Builder administers function modules that logically belong together in function groups. Function groups are containers for function modules. They can also contain global data declarations and subroutines that are available to all of the function modules in the group.
For each function group <fgrp> there is a main program, generated by the system, called SAPL<fgrp>.
The main program contains INCLUDE statements for the following programs:
L<fgrp>TOP. This contains the global data for the function group.
L<fgrp>UXX. These includes contain the function modules themselves. The numbering XX indicates the chronological order in which the function modules were created. This includes L<fgrp>U01 and L<fgrp>U02 contain the first two function modules in the function group.
L<fgrp>F01, L<fgrp>F02... These includes can be used to write subroutines (forms) that can be called as internal forms by all function modules in the group.
Displaying a Function Group
To display a function group, choose Goto -> Function groups->Display group. A dialog box appears in which you can enter the name of the function group.
Cheers
Snehi Chouhan