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: 

errors in function modules

Former Member
0 Kudos
71

how to handle errore in function modlues

1 ACCEPTED SOLUTION

marcelo_ramos
Active Contributor
0 Kudos
54

Hi,

<b>Here is an exemple.</b>

FUNCTION FM_EXEMPLE.

*"----


*" TABLES

*" TI_EX STRUCTURE ZRTEROU OPTIONAL

*" EXCEPTIONS

*" NOT_FOUND

*"----


IF TI_EX[] IS INITIAL.

RAISE not_found.

ENDIF.

ENDFUNCTION.

<b>The Calling.</b>

CALL FUNCTION 'FM_EXEMPLE'

TABLES

ti_ex = <table>

EXCEPTIONS

not_found = 1

OTHERS = 2.

CASE sy-subrc.

WHEN 1.

...

WHEN 2.

...

ENDCASE.

3 REPLIES 3

Former Member
0 Kudos
54

Hi,

You can use the Exceptions to handle the errors

There are two ABAP statements for raising exceptions. They can only be used in function modules:

RAISE <except>.

and

MESSAGE..... RAISING <except>.

The effect of these statements depends on whether the calling program handles the exception or not. If the name <except> of the exception or OTHERS occurs in the EXCEPTIONS addition of the CALL FUNCTION statement, the exception is handled by the calling program.

If the calling program does not handle the exception

The RAISE statement terminates the program and switches to debugging mode.

The MESSAGE ..... RAISING statement display the specified message. How the processing continues depends on the message type.

If the calling program handles the exception, both statements return control to the program. No values are transferred. The MESSAGE ..... RAISING statement does not display a message. Instead, it fills the system fields SY-MSGID, SY-MSGTY, SY-MSGNO, and SY-MSGV1 to SY-MSGV4.

Regards

Sudheer

Former Member
0 Kudos
54

Hi, you can define exception and throw the exception with the command 'RAISE'.

marcelo_ramos
Active Contributor
0 Kudos
55

Hi,

<b>Here is an exemple.</b>

FUNCTION FM_EXEMPLE.

*"----


*" TABLES

*" TI_EX STRUCTURE ZRTEROU OPTIONAL

*" EXCEPTIONS

*" NOT_FOUND

*"----


IF TI_EX[] IS INITIAL.

RAISE not_found.

ENDIF.

ENDFUNCTION.

<b>The Calling.</b>

CALL FUNCTION 'FM_EXEMPLE'

TABLES

ti_ex = <table>

EXCEPTIONS

not_found = 1

OTHERS = 2.

CASE sy-subrc.

WHEN 1.

...

WHEN 2.

...

ENDCASE.