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: 

Suppress SAP Message and Fetch message from memory

Former Member
0 Kudos
1,350

HI Folks,

I got a problem where my callee FM has a SAP message (ie. Message e(XXXX) xxxx).

How can I suprress it, and then later on fetch the message from memory?

Thanks,

Charlie

1 ACCEPTED SOLUTION

Former Member
0 Kudos
511

It doesn't matter...The other exception should have caught everything already. However I did try your suggestion and it does not work.

Furthermore, I cannot change FM anyway. So it won't make a difference because I have no authority to make any modification to the FM.

I appreciate your suggestions but I think this is a dead end.

However, I remember there is a function module in SAP that initialize text, then any message text message executed afterwards would go into a buffer. Another FM can retrieve it.

I don't remember those FM, and thats why I am posting here to see if anyone else have used it or know those fm.

18 REPLIES 18

former_member181995
Active Contributor
0 Kudos
511

By passing correct data to FM you can avoid the message.Check where-used-list for function module for sample coding.

Former Member
0 Kudos
511

normally you can code exception condition others = <some number> to supress the error message from the Function module call, then later you can check sy-subrc and give the message as you wish

so

call function xxxxx

exporting

importing

exceptions

e1 = 1

e2 = 2

others = 9.

0 Kudos
511

That won't work because too many program is using the function module, and I cannot change the calling fm. So I have to find a way to suppress that message. So no can do on your suggestion, though its a good one.

0 Kudos
511

Hi Charlie

If you are allowed to copy that FM and then handle the message part inside that new copied one.

I had a similer problem with one of the standard FM and as per the requirement user was asking for customize message so I copied that FM and pass all the message to log table and then in code i read that log table to customize the message for my code.

Neha

0 Kudos
511

can you explain again. i assume you are using a function module ( SAP or custom ), and there you are getting an SAP message back from the call.

What I asked you to change you call statment to code for exceptions Others = ....

I did nto ask you to change the calling FM, vbut rather the code in which you are calling the FM.

0 Kudos
511

I would never get an exception from the fm, because the message statement insdie the fm would have already stopped the program.

0 Kudos
511

Here is my scenario:

FM:

FUNCTION xxx

MESSAGE e002(xxx).

ENDFUNCTION.

Calling program:

CALL FUNCTION xxx

...

EXCEPTIONS

other = 1.

The message e002 statement will stop the program. I would like to suppress it, and fetch from memory later. I don't have to option of changing the FM and perfer not to make another copy.

Former Member
0 Kudos
511

Hi,

You can catch the error message when calling the function module..

CALL FUNCTION 'xxxxx'
          ......
      EXCEPTIONS
        error_message = 1.   " This will catch the error message.

Thanks

naren

0 Kudos
511

That actually won't work because in the calling FM. It has a message statement with typ 'E'. like:

MESSAGE e002(xxx).

Even if I call it with following

CALL FUNCTION 'xxx'

EXCEPTIONS

other = 1.

It will never come out of the FM because it already errored out to screen at the message statement. I did try that but didn't work.

Former Member
0 Kudos
511

Hi,

Please see my reply..

also from help..

If the error_message addition is specified after EXCEPTIONS, all MESSAGE statements that are executed during the processing of the function module and do not have the RAISING addition are affected as follows: 

Messages of the type S, I, or W are not sent but are noted in the log background processing. 


Messages of the type E and A trigger the exception error_message and set sy-subrc to n_error. The message class, message type, message number, and the contents of possible placeholders for the MESSAGE statement are in the fields sy-msgid, sy-msgno, sy-msgty, and sy-msgv1, ... , sy-msgv4. 

Thanks

naren

Former Member
0 Kudos
511

I understand, but here is the problem:

If the fm has exception defined, and the message had the statement with raising, then your suggestion would work: For example:

MESSAGE e002(xx) raising other.

But my calling fm does not have exception defined and the message statement is:

MESSAGE e002(xxx)

without the raising part.

So it stops and does not return.

Former Member
0 Kudos
511

Hi,

Please try it...I have used it in the past to suppress error message...and standard sap help says...that will catch the error messages raised without raising..

If the error_message addition is specified after EXCEPTIONS, all MESSAGE statements that are

executed during the processing of the function module and

do not have the RAISING addition

are affected as follows:

Thanks

Naren

Former Member
0 Kudos
511

I did try it, here is my test FM:

FUNCTION Z_CY_TEST_MG.

*"----


""Local Interface:

*" EXCEPTIONS

*" OTHER

*"----


MESSAGE e002(zq).

ENDFUNCTION.

And the calling program:

&----


*& Report Z_CY_TEST_MG

*&

&----


*&

*&

&----


REPORT Z_CY_TEST_MG.

CALL FUNCTION 'Z_CY_TEST_MG'

EXCEPTIONS

other = 1.

if sy-subrc = 1.

write: / 'error caught'.

endif.

If I have the statement "MESSAGE e002(zq) raising other", then its fine. But if I have it with out raising, then the message statements stop the program..

Former Member
0 Kudos
511

Hi,

Looks like you didn't the try the way I have mentioned..

REPORT Z_CY_TEST_MG.


CALL FUNCTION 'Z_CY_TEST_MG'
EXCEPTIONS
error_message = 1          " added this code..
other = 2.

if sy-subrc = 1.

write: / 'error caught'.
endif.

Thanks

Naren

Former Member
0 Kudos
512

It doesn't matter...The other exception should have caught everything already. However I did try your suggestion and it does not work.

Furthermore, I cannot change FM anyway. So it won't make a difference because I have no authority to make any modification to the FM.

I appreciate your suggestions but I think this is a dead end.

However, I remember there is a function module in SAP that initialize text, then any message text message executed afterwards would go into a buffer. Another FM can retrieve it.

I don't remember those FM, and thats why I am posting here to see if anyone else have used it or know those fm.

0 Kudos
511

This worked for me

Function module


FUNCTION Z_TEST.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"----------------------------------------------------------------------

message e398(00) with 'Error message'.



ENDFUNCTION.

program


REPORT  ztest.
CALL FUNCTION 'Z_TEST'
  EXCEPTIONS
    ERROR_MESSAGE = 9.

IF sy-subrc NE 0.

  WRITE : / 'xx'.

ENDIF.

output displayed


XX.

Former Member
0 Kudos
511

Hi,

It should work...and not sure what you are missing...

check the code in the FM SD_RFC_SALES_ITEM_MAINTAIN...it is calling the function module SD_SALES_ITEM_MAINTAIN and it is catching the error messages raised inside...

probably try creating a new function module and call the existing function module and inside the new function module..catch the error_message exception...

Thanks

Naren

Former Member
0 Kudos
511

Thanks MxG...for you quick test :-)..

Regards

Naren