Skip to Content

Using EXCEPTIONS in functions.

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 04, 2009 at 04:24 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 02, 2009 at 11:47 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 02, 2009 at 08: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.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.