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: 

raise exception when the user entered value is not present

Former Member
0 Kudos

Hello Abap experts,

To raise an exception in the function module when the imported variable value is not presnt in the table.

import variable: cust_name.

how to define a exception for this raise it in the code. any examples and suggestions.

Thanks,

BWer

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

In the exceptions tab of the function module, enter something like CUST_NAME_NOT_FOUND. In the source code of the function module. When checking against the database, raise the exception.



If sy-subrc <> 0.
raise CUST_NAME_NOT_FOUND.
endif.

Regards,

Rich Heilman

2 REPLIES 2

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

In the exceptions tab of the function module, enter something like CUST_NAME_NOT_FOUND. In the source code of the function module. When checking against the database, raise the exception.



If sy-subrc <> 0.
raise CUST_NAME_NOT_FOUND.
endif.

Regards,

Rich Heilman

0 Kudos

Here is the F1 help on RAISE.

<i>

RAISE

Basic form 1

RAISE except.

Effect

This statement is only effective in function modules and methods.

It triggers the exception except.

If the exception is to be handled by the caller of the function module or method ( CALL FUNCTION or CALL METHOD ), the system passes control straight back to the caller. EXPORT parameters of a function module or method are not filled. The EXPORTING, CHANGING, and RETURNING parameters of a function module or method are only filled with the current values if they were defined to be passed by reference. reference).If they are defined to be passed by value, they are not filled.

If the exception is not handled by the caller, the program terminates with an appropriate error message.

Example

Let there be a function module STRING_SPLIT containing the following code (see also the example in the documentation of the CALL FUNCTION statement):</i>

<b>FUNCTION-POOL CSTR.

FUNCTION STRING_SPLIT.

...

IF STRING NA DELIMITER.

RAISE NOT_FOUND.

ENDIF.

...

ENDFUNCTION.</b>

The calling program might then contain the following:

<b>PROGRAM EXAMPLE.

...

CALL FUNCTION 'STRING_SPLIT'

  • ...

EXCEPTIONS

NOT_FOUND = 7.

IF SY-SUBRC = 7.

WRITE / 'There is a problem.'.

ELSE.

...

ENDIF.</b>

<i>

If the NOT_FOUND exception is raised in a RAISE statement in the function module STRING_SPLIT, the system exits the function module and returns control to the calling program. The return code, which you should evaluate directly after the CALL FUNCTION statement, now contains the value 7.

Note

Runtime errors:

RAISE_EXCEPTION: The caller did not handle the exception that was triggered.

Related

MESSAGE ... RAISING

Additional help

Creating Function Modules

</i>

Regards,

Rich Heilman