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

Exceptions in FM

Former Member
0 Likes
1,068

in function module how to use exceptions tab, i have to do the authority check on some field by using the execeptions,

and that field i am not using any where in my function module.

please let me know its urgent

thanks&regards

chaithu.p

Edited by: Alvaro Tejada Galindo on Apr 11, 2008 4:57 PM

5 REPLIES 5
Read only

Former Member
0 Likes
748

Declare exceptions in the exceptions tab ...

say : NO_AUTHORITY ..

and in the FM :

check the field for authority ...

if authority fails ..

raise the exception...

RAISE NO_AUTHORITY.

Read only

Former Member
0 Likes
748

Hi,

U can Catch the Exception Value using sy-subrc

Exceptions throws value like 1,2,3 etc

use sy-subrc statement to catch those values and use for authority Check

if sy-subrc ne 0.

RAISE <VARIABLE>.

endif.

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Apr 11, 2008 4:58 PM

Read only

Former Member
0 Likes
748

Hi,

Your question is not very clear. Are you writing a function module or calling one?

If you are calling one map each exception to a number, if the exception is raised by the function module the return code SY-SUBRC will be set to this number and you can code to handle this.

If you are writing a function module when an error is reached issue an error message and include the RAISING option with the name of your exception.

Regards,

Nick

Read only

Former Member
0 Likes
748

Hi,

In FM exceptions you can define your exceptions with numbers.

when the exception araised the Sy-subrc will consist the Number that you are already defined in the Function module.

Check the following Example :

CALL FUNCTION 'READ_SPFLI_INTO_TABLE'

EXPORTING

ID = CARRIER

IMPORTING

ITAB = JTAB

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2.

CASE SY-SUBRC.

WHEN 1.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO.

WHEN 2.

MESSAGE E702(AT).

ENDCASE.

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Apr 11, 2008 4:59 PM

Read only

Former Member
0 Likes
748

In the Exception tab of FM interface, define your exception "PERMISSION_FAILURE" (any name and it's short text)

Let's say you are checking the authorization for transaction then in the source code you have to write something like this:

CALL 'AUTH_CHECK_TCODE'
       ID 'TCODE' FIELD objectname.
  if sy-subrc ne 0.
     message e059 with objectname raising *permission_failure.*
  endif.

Whil calling the FM from your program then it would be something like:

call function ' '

importing

exporting

exceptions

permission_failure = 1 (It will automatically come when you call function by clicking PATTERNs button)

other = 2.