Exceptions in function module.... for beginner......
I am new to ABAP.
Can anybody please tell, how to use the exceptions in function module ?
and if any exception happens, then how to link some messages to that exceptions?
I will also like to know, how to create those messages ?
<b>Can anybody please illustrate with help of example, so that a beginner will be able to understand. ?</b>
<b>eg,</b> i am adding two numbers in function module, and if any one passing number is negative, then i need to raise exception with message please do not enter -ve numbers for addition.
your help will be surely, rewarded with points.
waiting for reply.
Regards & Thanks
There are two ABAP statements for raising exceptions. They can only be used in function modules:
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.
Source Code of READ_SPFLI_INTO_TABLE
The entire source code of READ_SPFLI_INTO_TABLE looks like this:
*" VALUE(ID) LIKE SPFLI-CARRID DEFAULT 'LH '
*" VALUE(ITAB) TYPE SPFLI_TAB
SELECT * FROM SPFLI INTO TABLE ITAB WHERE CARRID = ID.
IF SY-SUBRC NE 0.
MESSAGE E007(AT) RAISING NOT_FOUND.
The function module reads all of the data from the database table SPFLI where the key field CARRID is equal to the import parameter ID and places the entries that it finds into the internal table SPFLI_TAB. If it cannot find any entries, the exception NOT_FOUND is triggered using MESSAGE...RAISING. Otherwise, the table is passed to the caller as an exporting parameter.
Also check these links