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

Exception message from FM

Former Member
0 Likes
3,136

Hi all,

In my Function Module under Exception i defined Exception E01 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.

How to do it

Sachin

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,456

Ya you can do that ... immediately after calling the FM ...do this way

CALL FUNCTION 'Z_FM_TEST1'

EXPORTING

MAT_TYPE = MAT_TYPE

TABLES

TAB_MARA = MARATABLE

EXCEPTIONS

E01 = 1

OTHERS = 2

.

IF SY-SUBRC = 1.

<b>MESSAGE e001 with 'E01 Exception raised'.</b> " 001 has to be 3 character length

ENDIF.

7 REPLIES 7
Read only

Former Member
0 Likes
1,456

hi Sachin,

Inside the FM try coding in this way ..


if sy-subrc <> 0.
  raise E01.
endif.

Read only

0 Likes
1,456

Hi Santosh,

I did it in this way only. but i am not been able to catch that exception in my REPORT where i am calling that FM.

I also catched that exception and <b>print that Error text</b> that i gave in Exception short text.

Is it possible?

and if so, please tell me how to do it?

Any Help will be rewarded.

Sachin.

Read only

0 Likes
1,456

first of all put a break point and check whether the raise statement is executing or not ? if it is executing then sy-subrc must be 1.

in the message write

if sy-subrc = 1.

message '<same text as in the exception>' type 'E'.

endif.

or you can go through the message class also(se91).

if sy-subrc = 1.

message e001(zspd).

endif.

just dbl click on the zspd and give the text(message text) there and save it.

regards

shiba dutta

Read only

Former Member
0 Likes
1,456

i am not enough sure what you want but you can try like this in fm source code.

select * from mara into corresponding fields of table tab_mara where mtart = mat_type.

if tab_mara[] is initial.

raise e01.

endif.

regards

shiba dutta

Read only

Former Member
0 Likes
1,457

Ya you can do that ... immediately after calling the FM ...do this way

CALL FUNCTION 'Z_FM_TEST1'

EXPORTING

MAT_TYPE = MAT_TYPE

TABLES

TAB_MARA = MARATABLE

EXCEPTIONS

E01 = 1

OTHERS = 2

.

IF SY-SUBRC = 1.

<b>MESSAGE e001 with 'E01 Exception raised'.</b> " 001 has to be 3 character length

ENDIF.

Read only

Former Member
0 Likes
1,456

Hi,

define an exception and short text to it.

then after the select query fire the exception.

see the sample code..

function z73390_fdivide.

*"----


""Local interface:

*" IMPORTING

*" REFERENCE(NUMBER1) TYPE I DEFAULT 0

*" REFERENCE(NUMBER2) TYPE I DEFAULT 0

*" EXPORTING

*" REFERENCE(ANS) TYPE P

*" EXCEPTIONS

*" ZERODIVIDEERROR

*"----


if number2 eq 0.

message e000(zgem) with 'Divide by Zero' raising zerodivideerror.

endif.

ans = number1 / number2.

Regards,

Niyaz

endfunction.

Read only

Former Member
0 Likes
1,456

hi sachin


if sy-subrc = 1.
message e001 (message class) raising <EXCEPTION NAME>.
endif

regards

ravish

plz reward if useful