Using exceptions in Function Modules in SAP

What are exception in Function Modules ? Using exception in Function Modules to raise error messages, exception handling in Function modules

+ -

Exceptions: Exceptions are used to catch certain type of errors in Function Modules.

Whenever an exception is raised, it will be caught in system variable SY-SUBRC.

Continuation to the previous lesson Creating and using of Function Modules in SAP ABAP , we add an exception for no input.

In the previous example, we are getting material details for a material input, now we add an exception to check whether the input is provided or not.

Go to 'Exceptions' tab and add NO_MATNR under Exception and short text.

exceptions in function module

Write below code under Source Code .

raise exception in function module

Save, Activate and execute

Function Module exceptions

A popup will open, just click on 'Save' without giving any value.

exception messages in sap

Now you can see NO_MATNR exception.

raise exception in sap fm

Using Function module exceptions in SE38 program.

When ever an exception is raised, it will be stored in system variable SY-SUBRC .

Function exceptions

REPORT  ZSAPN_GET_MATERIAL.

DATA : WA_MARA TYPE MARA .
PARAMETERS : P_MATNR TYPE MARA-MATNR .

START-OF-SELECTION.

  CALL FUNCTION 'ZSAPN_GET_MATERIAL'
    EXPORTING
      IM_MATNR      = P_MATNR
    IMPORTING
      EX_MARA       = WA_MARA
    EXCEPTIONS
      NO_MATNR      = 1
      OTHERS        = 2.
  IF SY-SUBRC = 1.
* Implement suitable error handling here
    MESSAGE 'Please enter a material no' TYPE 'E'.
  ENDIF.

  WRITE : WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MEINS, WA_MARA-MBRSH . "Display result

Excute the program without giving any input, we will get an error message.

exceptions in sap programs

raise exception in se38 program

Learner Questions


No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question

    Was this lesson helpful to you? Yes No 72 People out of 75 think this lesson helpful


    Lesson Navigation

    ←Previous Chapter
    Next Chapter →