2007 Jul 23 12:22 PM
Hi all,
I am raising exception in Function Module but catch in my Report. So can any body tell me how to do it?
Any Help will be rewarded.
Sachin
Hi all,
I am raising exception in Function Module but catch in my Report. So can any body tell me how to do it?
Any Help will be rewarded.
Sachin
2007 Jul 23 12:25 PM
Hi,
When you call the FM use the addition
EXCEPTIONS after the IMPORTING parameters and then assing a number to that exception.
If an exception is raised then the number you assigned will be stored in SY-SUBRC.
Example:
CALL FUNCTION 'CATS_UPDATE_DATA_FROM_OFFLINE'
EXPORTING
profile = im_profile
pernr = im_pernr
language = language
text_format = im_text_format
catsrecords = im_catsrecords
longtexts = im_longtexts
IMPORTING
processedrecords = ex_processedrecords
messages = ex_messages
EXCEPTIONS
no_enqueue_pernr = 1
OTHERS = 2.
check sy-subrc here.
If you are using a class based exception then call the FM in a TRY CATCH ENDTRY block.
TRY.
CALL FM
CATCH <exception_name>.
ENDTRY.
Regards,
Sesh
2007 Jul 23 1:50 PM
In my Function Module under Exception i defined Exception <b>E01</b> 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.
<b>How to do it</b>
Sachin
2007 Jul 23 12:26 PM
Every exception will be assigned a number starting from 1 in the order they have been defined in the Function Module. After you call the function module, if an exception has been raised the number of the same will be assigned to sy-subrc. You can use this to handle exceptions. If no exception has been raised, then the value of sy-subrc will be 0 after the function module has been called.
Please mark points if the solution was useful.
Regards,
Manoj
2007 Jul 23 12:31 PM
2007 Jul 23 12:31 PM
Sample code to display whether year is a leap year or not....
PARAMETERS:
P_YEAR TYPE I. " year
DATA:
W_RESULT TYPE C.
CALL FUNCTION 'ZFUNC'
EXPORTING
YEAR = P_YEAR
IMPORTING
RESULT = W_RESULT
EXCEPTIONS
NEGATIVE_NUMBER = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
WRITE ' error '(001).
ENDIF.
IF W_RESULT EQ 0.
WRITE: ' leap year'(002).
ELSE.
WRITE: ' Not a leap year'(003).
ENDIF.
Here while you are developing a Function Module, in the exceptions tab, remember to display the exception numbers.
Regards,
Pavan
2007 Aug 23 9:57 AM
Short Text with message will not be displayed.
you can add your text with message only statically.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |