Application Development and Automation 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: 
Read only

Function modules

Former Member
0 Likes
801

How we can handle the Errors in the FM

7 REPLIES 7
Read only

Former Member
0 Likes
768

HI,

Exceptions

Within a function module, you can address all exceptions using the names you defined in the interface. Exceptions can be handled either by the system or by the calling program. You decide this when you call the function, by assigning a numeric value to the exceptions that you want to handle yourself. For further information, see Calling Function Modules From Your Programs.

Exceptions must be explicitly triggered.

There are two ABAP statements that may only be used in function modules that you can use to trigger exceptions:

Syntax

RAISE <Exception>.

MESSAGE..... RAISING <Exception>.

The effect of these statements depends on whether you handle the exception in the calling program or let the system process it.

If you trigger the exception in the RAISE statement and the calling program is to handle it, the function module processing is terminated, and the numeric value assigned to the exception is placed in the system field SY-SUBRC. Further processing then takes place in the calling program.

If the calling program fails to handle the exception, the system triggers a runtime error.

If you use the MESSAGE... RAISING statement, the processing is similar if you want to handle the exception in the calling program. If you want the system to handle the exception, there is no runtime error generated in this case. Instead, processing continues, and the system displays a message with the defined type. To do this, you must specify the MESSAGE-ID in the first statement of the include program L<fgrp>TOP. The MESSAGE... RAISING statement also enters values in the following system fields:

SY-MSGID (message ID)

SY-MSGTY (message type)

SY-MSGNO (message number)

SY-MSGV1 to SY-MSGV4 (contents of the fields <f1> to <f4> that are included in the message).

Read only

Former Member
0 Likes
768

Raise exceptions to catch errors in FM's.

Using sy-subrc check the exceptions raised by FM and display.

Read only

Former Member
0 Likes
768

Hi,

Can you please stop posting all of these interview type questions. Try to use the search function instead as these questions have been asked over and over and over before.

Gareth.

Read only

Former Member
0 Likes
768

Hi,

You as such cannot handle errors in FM's, coz the problem is that in case some errors come up during validations, they would pop up on ur screen and stop the execution of your prog. The best way is to get all your fields that you wanna upload validated before you pass these values to the FM.Try using a BAPI..It woud help. Let me know your application. I would help you find a BAPI for it.

Thanks

NAyan

Read only

Former Member
0 Likes
768

hi do like this.. in the source code of the fm..

and write the no_data in the exceptions tab..

select matnr from mara into v_matnr where matnr in i_matnr.

if sy-subrc ne 0.

raise no_data .

endif.

regards,

venkat

Read only

Former Member
0 Likes
768

HI,

Exceptions in Function Modules and Methods

To enable error situations in procedures to be handled by the caller, exceptions have been defined in the interface of function modules and methods. For global procedures, the exceptions were defined in the ABAP Workbench. For local methods, they were defined with the EXCEPTIONS addition of the METHODSstatement. Exceptions defined in this way can be raised within the procedure with the RAISEstatements and with the RAISING addition of the MESSAGEstatement.

Exceptions that are defined like this in the interface are handled using the EXCEPTIONS additions of the corresponding CALL statements. These exceptions cannot be forwarded in the call hierarchy. Not handling them leads to a runtime error.

By using the predefined exception ERROR_MESSAGE after the EXCEPTIONS addition of a procedure call, messages of type E and A sent with the MESSAGE statement can also be handled as exceptions.

The principle of these self-defined exceptions is explained in:

Creating Function Modules

Calling Function Modules

Since the class-based approach here is much more sophisticated and flexible, it is the preferred approach for new developments. The EXCEPTIONS and RAISING additions are mutually exclusive in the interface of a procedure

check url

http://help.sap.com/saphelp_nw04s/helpdata/en/9e/d58167116711d5b2f40050dadfb92b/frameset.htm

Regards,

Points if helpful,

Phani.chennakeshavula

Read only

Former Member
0 Likes
768

Hi,

CALL FUNCTION 'CSAI_BOM_CREATE'
     EXPORTING
       ecsin                    = wa_csin
       estkob                   = wa_stkob
       estzub                   = wa_stzub
       fl_no_change_doc         = space
       fl_commit_and_wait       = space
       fl_no_commit_work        = 'X'
       fl_ale                   = space
       fl_default_values        = space
     TABLES
       t_stpob                  = i_stpob
    EXCEPTIONS
      error                    = 1 
      OTHERS                   = 2.

**** Exceptions catches the error message
If sy-subrc = 1 , then it is Error
If sy-subrc = 2 , then other Errors,
These can be formatted in a single message by using the below FM


    CALL FUNCTION 'FORMAT_MESSAGE'
      EXPORTING
        id        = sy-msgid
        lang      = '-D'
        no        = sy-msgno
        v1        = sy-msgv1
        v2        = sy-msgv2
        v3        = sy-msgv3
        v4        = sy-msgv4
      IMPORTING
        msg       = v_msg
      EXCEPTIONS
        not_found = 1
        OTHERS    = 2.