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: 

exception handling in function module

Former Member
0 Kudos

Hi experts,

when we write the function module in the report program like "CONVERT_TO_LOCAL_CURRENCY" if anything goes wrong in this FM the program goes to dump. So how to handling this exceptions.

if sy-subrc ne 0 then i need to continue with the next statement. will i need to use continue statement.

Please expllain with some example

8 REPLIES 8

shaik_sajid
Active Contributor
0 Kudos

hi

after the function modue

CONVERT_TO_LOCAL_CURRENCY

if sy-subrc ne 0.

******write your logic to handle.
else.
******write your logic what it should do if successful.

endif.

whether sy-subrc is 0 or not, if you want to continue with the next statement,then do as follows

CONVERT_TO_LOCAL_CURRENCY

if sy-subrc ne 0.
"no need to code anything
endif.
***you can have your next statements here and there is no need to use continue statement

regards

Sajid

Edited by: shaik sajid on Jul 13, 2009 9:12 AM

former_member156446
Active Contributor
0 Kudos
CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
* CLIENT = SY-MANDT
date = itab-date_of_export
foreign_amount = dl_kwert
foreign_currency = itab-waers
local_currency = c_usd
IMPORTING
local_amount = itab-value_of_goods
EXCEPTIONS  " un-comment these sections
no_rate_found = 1
overflow = 2
no_factors_found = 3
no_spread_found = 4
derived_2_times = 5
OTHERS = 6.
IF sy-subrc NE 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO  " this is display the system message automatically when ever exp are hit
 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

I355602
Advisor
Advisor
0 Kudos

Hi,

Go in debugging mode and when you reach the FM press F6, after then you will get a value for sy-subrc.

Say if it is 2, the code like:-


CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'.

IF sy-subrc NE 0 AND sy-subrc NE 2.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSEIF sy-subrc = 2.
  "no code
ENDIF.

Hope this will help you out.

Regards,

Tarun

Former Member
0 Kudos

hi ,

You can use CASE sy-subrc statement ...

Check any standard FM and see how error is handled in them

thanks

former_member555112
Active Contributor
0 Kudos

Hi,

The program will dump only if something incorrect is passed to the parameters of the FM.

In that case there is no way to avoid the dump.

If you want to handle the exceptions then handle them as they are coded when you call the FM via PATTERN in your editor.

Regards,

Ankur Parab

Former Member
0 Kudos

hi ,

You can use CASE sy-subrc statement ...

when 1.

do this ..

when 2

when 0

Check any standard FM and see how error is handled in them

Also wht is the DUMP message

thanks

Former Member
0 Kudos

hi,

This is very simple, there are two ways to do say.....

1. As this is std FM so when use call this FM there is some code under EXCEPTION just uncomment those code .....your problem will automatically will be solved.

OR

2.If you want to add your own functionality then simply use te case or if-else to check the value of sy-subrc.

As stated by you just write

if sy-subrc ne 0

your code..
endif.

Hope this will help you.

pooja

Former Member
0 Kudos

hello,

CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'

EXPORTING

  • CLIENT = SY-MANDT

date = itab-date_of_export

foreign_amount = dl_kwert

foreign_currency = itab-waers

local_currency = c_usd

IMPORTING

local_amount = itab-value_of_goods

EXCEPTIONS " un-comment these sections

no_rate_found = 1

overflow = 2

no_factors_found = 3

no_spread_found = 4

derived_2_times = 5

OTHERS = 6.

IF sy-subrc NE 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO " this is display the system message automatically when ever exp are hit

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

here you can use the case statement like:

case sy-subrc.

when 1.

    • write your code what you want to do if no rate found

when 2.

    • what do you want to do in case of overflow.

*similarly handle all the cases of exceptons

endcase.

hope it helps

regards

geeta gupta