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: 

Using EXCEPTIONS in functions.

former_member204025
Participant
0 Kudos

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.

1 ACCEPTED SOLUTION

venkat_o
Active Contributor
0 Kudos

Hi, Try this way. <li>Create function module with RAISE statement.


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.
<li>Call this function module in the program.

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.
Thanks Venkat.O

5 REPLIES 5

former_member156446
Active Contributor
0 Kudos

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.

0 Kudos

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

Clemenss
Active Contributor
0 Kudos

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

venkat_o
Active Contributor
0 Kudos

Hi, Try this way. <li>Create function module with RAISE statement.


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.
<li>Call this function module in the program.

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.
Thanks Venkat.O

0 Kudos

Hi guys!

I tried -and read- with your suggestions and it worked!! Thank you for teach me!

Have a very nice day!

Gaby