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: 

How to use Exceptions for a function module

Former Member
0 Kudos

Hi folks,

I have created a new function module.Its working fine, but i am not aware of using exceptions for a function module. I hav just declared an exception in the 'exception' tab. Could any body explain me how to use that in my FM source code....Thanks...

7 REPLIES 7

JozsefSzikszai
Active Contributor
0 Kudos

hi,

roughly like this:

IF ... some condition (for example sy-subrc NE 0 after a DB selection)

RAISE name_of_exception ==> FM will stop, return to calling program with the exception.

ENDIF.

It also could used with MESSAGE:

MESSAGE .... RAISING name_of_exception.

hope this helps

ec

Former Member
0 Kudos

Hi Shyam,

Have a look at this,

START-OF-SELECTION.

gd_file = p_infile.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = gd_file

has_field_separator = 'X' "file is TAB delimited

TABLES

data_tab = it_record

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

OTHERS = 17.

IF sy-subrc NE 0.

write: 'Error ', sy-subrc, 'returned from GUI_UPLOAD FM'.

skip.

endif.

Regards,

Sai

Former Member
0 Kudos

look at standard FM's U'll get a better idea ..

Ex ... GUI_UPLOAD ..

Former Member
0 Kudos

Hi,

We need to handle exceptions for function modules in code only with help of RAISING keyword in MESSAGE.

e.g

IF DOCUMENT_NUMBER IS INITIAL.
  MESSAGE E054 RAISING DOCUMENT_NUMBER_INVALID.
  ENDIF.

SELECT SINGLE * FROM EDIDC WHERE DOCNUM EQ DOCUMENT_NUMBER.
  IF SY-SUBRC EQ 0.
    MOVE EDIDC TO IDOC_CONTROL.
  ELSE.
  MESSAGE E062 WITH DOCUMENT_NUMBER RAISING DOCUMENT_NOT_EXIST.
  ENDIF.

hope this helps you.

<removed_by_moderator>

thanks,

dhanashri.

Edited by: Julius Bussche on Jul 16, 2008 9:17 AM

Former Member
0 Kudos

Shyam,

Please find the below given example.

FM exception tab having the message "INVALID_SALESORG".

Source code:

if i_vkorg[] is initial.

raise invalid_salesorg.

endif.

Regards,

Suresh Kumar.

former_member787646
Contributor
0 Kudos

Hi

Say you have an exception named "NO_REC_FOUND" in the function module.

In the source code of the FM we can handle the exception as follows.

SELECT COUNT(*) FROM <TABLE> INTO <VAR> WHERE <COND>.

IF <VAR> EQ 0.

RAISE NO_REC_FOUND.

ENDIF.

IN the program where you are calling the FM the code looks like the following. Here we have to handle the exception on our own.

CALL FUNCTION 'XYZ'

EXPORTING

.......

........

TABLES

.......

........

EXCEPTIONS

NO_REC_FOUND = 1

OTHERS = 2

.

IF sy-subrc = 1.

Message 'No Records Found' TYPE 'E'.

ENDIF.

Hope this would help you.

Murthy