10-02-2009 9:42 PM
Hi all!
I would like to use excepions in function modules, could you please explain to me how should I use it? If I pass an internal table if there is some error, I would like to have exceptions instead of get a dump.
Please let me know.
Thank you!
Gabriela.
10-04-2009 5:24 AM
Hi,
Try this way.
<li>Create function module with RAISE statement.
<li>Call this function module in the program.
FUNCTION zget_marc_data.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(WERKS) TYPE MARC-WERKS
*" TABLES
*" IT_MARC STRUCTURE MARC
*" EXCEPTIONS
*" NO_DATA
*"----------------------------------------------------------------------
SELECT * FROM marc INTO TABLE it_marc WHERE werks = werks.
IF sy-subrc NE 0.
RAISE no_data.
ENDIF.
ENDFUNCTION.
Thanks
Venkat.O
REPORT ztest_notepad.
DATA: it_marc TYPE TABLE OF marc.
CALL FUNCTION 'ZGET_MARC_DATA'
EXPORTING
werks = 'X000'
TABLES
it_marc = it_marc
EXCEPTIONS
no_data = 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.
ENDIF.
10-02-2009 9:51 PM
For an example look at FM : AUTHORITY_CHECK_TCODE
look in the exceptions tab.. ok and not_ok are present..
in the source code based on some conditions they use Raise OK statement to raise the exception.
__________
if you are calling an FM just un-comment the exception section, which you get when u hit pattern and have call that FM in ur code.
10-02-2009 11:14 PM
in the exception tab:
add the exceptions... like READ_ERROR_EXCEP, or some other what ever you wish.
and in source code when the fail occurs.
use RAISE exceptionname.
like:
RAISE READ_ERROR_EXCEP.
hope this helps
10-03-2009 12:47 AM
Please look here: [ABAP: Using EXCEPTIONS in functions.|http://www.google.cn/search?hl=zh-CN&q=ABAP%3AUsingEXCEPTIONSinfunctions.+++&btnG=Google%E6%90%9C%E7%B4%A2&aq=f&oq=]
Regards,
Clemens
10-04-2009 5:24 AM
Hi,
Try this way.
<li>Create function module with RAISE statement.
<li>Call this function module in the program.
FUNCTION zget_marc_data.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(WERKS) TYPE MARC-WERKS
*" TABLES
*" IT_MARC STRUCTURE MARC
*" EXCEPTIONS
*" NO_DATA
*"----------------------------------------------------------------------
SELECT * FROM marc INTO TABLE it_marc WHERE werks = werks.
IF sy-subrc NE 0.
RAISE no_data.
ENDIF.
ENDFUNCTION.
Thanks
Venkat.O
REPORT ztest_notepad.
DATA: it_marc TYPE TABLE OF marc.
CALL FUNCTION 'ZGET_MARC_DATA'
EXPORTING
werks = 'X000'
TABLES
it_marc = it_marc
EXCEPTIONS
no_data = 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.
ENDIF.
10-04-2009 1:23 PM
Hi guys!
I tried -and read- with your suggestions and it worked!! Thank you for teach me!
Have a very nice day!
Gaby