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

Function Module

Former Member
0 Likes
677

Can onyone explain me or give me some links regarding Function Module. I am confused on why exaclty does the exceptions tab is for.

Sehjal.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
627

A function module is nothing but a reusable piece of code that can be called from within your code. It takes in some inputs and returns some outputs and probably changes somethings as well. But you want to know when something goes wrong in the code. How will the function module relay that to you? It can send that information as a return parameter(BAPIs and some function modules are examples of this) or it can raise the exceptions that you can trap and do something based on the exception raised. Exceptions are nothing but something unexpected that happened in the function module that is considered as unsuccessful execution of the function module. These exceptions are returned in the form of their integer values. So when you call the function module, you will assign a number to each exception. If that exception is raised in the execution of the function module, then you get a SY-SUBRC value equal to what you set it for. You can then react to it knowing which exception was raised.

Hope this helps.

7 REPLIES 7
Read only

Former Member
0 Likes
627

Hello shejal,

Basically if you are developing a custom fm or a standard fm, you can raise exceptions in the code for some error.

And you have to define those exceptions in the exceptions tab of the fm.

When you execute the fm, it will return that exception and based on that exception, it is up to you to decide what to do.

Hope this helps. If it is not clear, let me know. I will try to paste some documentation.

Thanks,

Message was edited by: Naren Somen

Read only

0 Likes
627

Thanks Naren,

It kinds of help me in brief but if have some documentation i think it be lot more useful for me.

Shejal.

Read only

ferry_lianto
Active Contributor
0 Likes
627

Hello Shejal,

Please check this online document.

http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCABA/BCABA.pdf

Hope this will help.

Regards,

Ferry Lianto

Please reward points if helpful as a way to say thanks.

Read only

Puneet_Gupta
Contributor
0 Likes
627

Hi Shejal,

The Exception tab is normally used to return the different possible errors that may occur during the data processing with the fucntion.

Eg. suppose in the function module you are selecting data and performing a mathematical calculation.

in the Exception tab define 2 exceptions :

NO_DATA

DIVIDE_BY_ZERO

select .... from .... into... where...

if sy-subrc ne 0.

RAISE NO_DATA

endif.

if b ne 0.

c = a / b.

else.

RAISE DIVIDE_BY_ZERO.

endif.

in this case if the 1st exception is encountered the function will return a sy-subrc value of 1 and if the 2nd exception happend the Function will return a sy-subrc of 2.

Hope this helps

thanks,

Puneet

based on the sequence number of no_data in the exception tab, the function module will return corresponding subrc

Read only

0 Likes
627

hi Shejal,

<b>Function Module</b>

Function modules are special external

subroutines stored in a central library.

SAP has provided a good number of pre

defined function modules and also we can

create our own function modules.

We can call any of these function

modules from ABAP/4 programs.

FMs are stored in central library and Subroutines are confined to a particular program.

FMs return values while Subroutines can’t return.

FMs can raise and handle exceptions while Subroutines can’t.

There is a difference in passing parameters to the function modules.

Declaring data as common parts is not possible for function modules.

The calling program and the called function module have different work areas in ABAP/4 dictionary tables.

<b>Table Parameters</b>

FM’s can import internal tables and work areas from the main program and the changes are reflected back. This is also done through “Call by Reference” procedure.

<b>Exceptions</b>

FM’s can raise and handle exceptions. Exceptions are such situations where error cant be dealt by the program logic, say like trying to access network resources when the network is not there.

Regards,

Santosh

Read only

0 Likes
627

I think i got it thanks all for the links and brief explanantion.

Shejal.

Read only

Former Member
0 Likes
628

A function module is nothing but a reusable piece of code that can be called from within your code. It takes in some inputs and returns some outputs and probably changes somethings as well. But you want to know when something goes wrong in the code. How will the function module relay that to you? It can send that information as a return parameter(BAPIs and some function modules are examples of this) or it can raise the exceptions that you can trap and do something based on the exception raised. Exceptions are nothing but something unexpected that happened in the function module that is considered as unsuccessful execution of the function module. These exceptions are returned in the form of their integer values. So when you call the function module, you will assign a number to each exception. If that exception is raised in the execution of the function module, then you get a SY-SUBRC value equal to what you set it for. You can then react to it knowing which exception was raised.

Hope this helps.