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

catch exception using message

Former Member
0 Likes
5,571

hi, i do not know what are the message below meant for. if i can catch or handle the exception, do i need to have the message statement? in this way, i do not have to specifically write when sy-subrc = 1 then do what, = 2 do what, =3 do what and so on in the calling program? assuming in the FM there are raise keyword for each exception.

call function

exporting

importing

exceptions

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

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,249

By using the EXCEPTIONS section, you are merely catching the errors, not reporting about them. So if require to catch the exception as well as report the error to the user, then you would use some message here.

If you do not require a message to the user, you can simply delete that part.

Regards,

RIch Heilman

Message was edited by:

Rich Heilman

9 REPLIES 9
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,250

By using the EXCEPTIONS section, you are merely catching the errors, not reporting about them. So if require to catch the exception as well as report the error to the user, then you would use some message here.

If you do not require a message to the user, you can simply delete that part.

Regards,

RIch Heilman

Message was edited by:

Rich Heilman

Read only

0 Likes
2,249

hi,

thank you very much. allow me to clarify this. what you all mean by this message meant for reporting? i still not really clear.

thanks

Read only

0 Likes
2,249

If an exception is raise inside the function module and you are not defining the execeptions in the calling program, then you will get an ABAP runtime exception. In order to handle the error gracefully, you need to define the exceptions in the function call and then handle them. So if you have two exceptions, the first one being ERROR and the second OTHER, then you would set them like so.

EXCEPTIONS
         ERROR  = 1
         OTHER  = 2.

So now, if either is raised in the function module, you know the SY-SUBRC value will be set to either 1 or 2. Next you can handle them if you need.

CASE SY-SUBRC.
    when '1'.
    message e001(00) with 'There was some error'.

    when '2'.
    message e001(00) with 'I have no idea what the problem is'.
endcase.

Regards,

RIch Heilman

Read only

Former Member
0 Likes
2,249

the messages which are displayed below when you call a function module, are those generated when you raise exceptions in the function module... so uncomment them so that the exceptions are raised....

if you want additional exceptions to be handled in the program... give the messages in your report...

Read only

Former Member
0 Likes
2,249

You can interpret messages with these system variables by using FM

MESSAGE_GET_TEXT.

Regards,

Ashish

Read only

Former Member
0 Likes
2,249

Hi,

you don't have to have the message statment to catch the excepction.

To catch the exception and avoid a Dump (if an exception occurs) you should declare the EXCEPTIONS statment em the FM Declaration. With this declaration

the exception is controled, the message statmente after is use only if you want to inform the user/program about the specific error.

Regards,

Read only

francisco_asensio
Participant
0 Likes
2,249

Hi,

You are right. If you are going to handle the exception ,aybe you do not need to show the message.

This message is not really necesary, it is only writed by default when you Call a funtion using get partner.

Regards,

Read only

Former Member
0 Likes
2,249

Hi,

Exceptions are situations that occur while an ABAP program is being executed, in which normal continuation of the program does not make any sense.

it is not needed to write messages.

Regards,

Sruthi

Read only

Former Member
0 Likes
2,249

Hi el,

There are two ABAP statements for raising exceptions. They can only be used in function modules:

RAISE exc.

MESSAGE.....RAISING exc.

The effect of these statements depends on whether the calling program handles the 'exc' exception or not. The calling program handles an exception If the name of the 'exc' exception or OTHERS is specified after the EXCEPTION option of the CALL FUNCTION statement.

If the calling program does not handle the exception

The RAISEstatement terminates the program and switches to debugging mode.

The MESSAGE..... RAISING statement displays the specified message. Processing is continued in relation to the message type.

If the calling program handles the exception, both statements return control to the program. No values are transferred. The MESSAGE..... RAISING statement does not display a message. Instead, it fills the system fields sy-msgid, sy-msgty, sy-msgno , and SY-MSGV1 to SY-MSGV4.

hope this helps u a bit,

all the best,

regards,

sampath

  • mark helpful answers