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

Raising Exception

Former Member
0 Likes
959

Hi all,

I am raising exception in Function Module but catch in my Report. So can any body tell me how to do it?

Any Help will be rewarded.

Sachin

Hi all,

I am raising exception in Function Module but catch in my Report. So can any body tell me how to do it?

Any Help will be rewarded.

Sachin

6 REPLIES 6
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
915

Hi,

When you call the FM use the addition

EXCEPTIONS after the IMPORTING parameters and then assing a number to that exception.

If an exception is raised then the number you assigned will be stored in SY-SUBRC.

Example:

CALL FUNCTION 'CATS_UPDATE_DATA_FROM_OFFLINE'

EXPORTING

profile = im_profile

pernr = im_pernr

language = language

text_format = im_text_format

catsrecords = im_catsrecords

longtexts = im_longtexts

IMPORTING

processedrecords = ex_processedrecords

messages = ex_messages

EXCEPTIONS

no_enqueue_pernr = 1

OTHERS = 2.

check sy-subrc here.

If you are using a class based exception then call the FM in a TRY CATCH ENDTRY block.

TRY.

  • CALL FM

CATCH <exception_name>.

ENDTRY.

Regards,

Sesh

Read only

0 Likes
915

In my Function Module under Exception i defined Exception <b>E01</b> and raise exception when there is no row found using SY-SUBRC.

And in my report i want to show error text.

CALL FUNCTION 'Z_FM_TEST1'

EXPORTING

MAT_TYPE = MAT_TYPE

TABLES

TAB_MARA = MARATABLE

EXCEPTIONS

E01 = 1

OTHERS = 2

.

IF SY-SUBRC = 1.

MESSAGE e0001(E01).

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

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

ENDIF.

<b>How to do it</b>

Sachin

Read only

Former Member
0 Likes
915

Every exception will be assigned a number starting from 1 in the order they have been defined in the Function Module. After you call the function module, if an exception has been raised the number of the same will be assigned to sy-subrc. You can use this to handle exceptions. If no exception has been raised, then the value of sy-subrc will be 0 after the function module has been called.

Please mark points if the solution was useful.

Regards,

Manoj

Read only

0 Likes
915

catch it with SY-SUBRC

Read only

Former Member
0 Likes
915

Sample code to display whether year is a leap year or not....

PARAMETERS:

P_YEAR TYPE I. " year

DATA:

W_RESULT TYPE C.

CALL FUNCTION 'ZFUNC'

EXPORTING

YEAR = P_YEAR

IMPORTING

RESULT = W_RESULT

EXCEPTIONS

NEGATIVE_NUMBER = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

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

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

WRITE ' error '(001).

ENDIF.

IF W_RESULT EQ 0.

WRITE: ' leap year'(002).

ELSE.

WRITE: ' Not a leap year'(003).

ENDIF.

Here while you are developing a Function Module, in the exceptions tab, remember to display the exception numbers.

Regards,

Pavan

Read only

Former Member
0 Likes
915

Short Text with message will not be displayed.

you can add your text with message only statically.