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

BAPI error handling

ronaldo_aparecido
Contributor
0 Likes
3,691

Hi Gurus.

Iam work with BAPI : BAPI_CONTRACT_CHANGE and

if I put a wrong code purposely imposed, the error message appears:

The tax code entered is not defined in the company's country.

the problem is that this message is displayed on the first screen. I want him to put this message in t_return which is the return table like other error messages.

How can I do this?

Thanks

13 REPLIES 13
Read only

Former Member
0 Likes
2,258

When you do that what does t_return have in it?

Neal

Read only

0 Likes
2,258

In this moment I dont can see the table because the error message in screen.

Read only

0 Likes
2,258

Have you built out your BAPI call in code and test run it?

Neal

Read only

0 Likes
2,258

Yes, the BAPI RUns Correctly.

Read only

0 Likes
2,258

So, you send that error through you BAPI and the message is not returmed.  I'm guessing the message is not a hard error, then.

There are configuration points to convert some messages from warnings to errors.  Have you looked for one of those?

Neal

Read only

0 Likes
2,258

Hi

Can you please put a break point at statement message to check if some exit is throwing this errror or SAP standard code if SAP standard then raise a ticket to SAP. As correctly mentioned by Suhas such kind of behaviour of BAPI is not normal

Nabheet

Read only

0 Likes
2,258

Or to put this more simple - does his error message ID start with letter Z ?

Read only

reinis_dzenis
Explorer
0 Likes
2,258

To catch such errors you should use ERROR_MESSAGE exception when calling given BAPI.

And afterwards you can retrieve specific error message ID from SY variable.

That would look something like this:


CALL FUNCTION 'BAPI_CONTRACT_CHANGE'

   EXPORTING

     purchasingdocument = lv_purch_doc

   TABLES

     return             = lt_return[]

   EXCEPTIONS

     error_message      = 1.

IF sy-subrc = 1.

   ls_return-type        = sy-msgty.

   ls_return-id          = sy-msgid.

   ls_return-number      = sy-msgno.

   ls_return-message_v1  = sy-msgv1.

   ls_return-message_v2  = sy-msgv2.

   ls_return-message_v3  = sy-msgv3.

   ls_return-message_v4  = sy-msgv4.

   INSERT ls_return INTO TABLE lt_return.

ENDIF.

(in given example online error is getting caught and immediately added to BAPI return table for further processing)

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,258


Reinis Dzenis wrote:



in given example online error is getting caught and immediately added to BAPI return table for further processing

But the point is a (well-designed)BAPI should not raise any message. I am not sure why the OP is facing this error.

If it is due to the BAPI & not due to an custom code i'll suggest to raise a message with SAP.

BR,

Suhas

Read only

0 Likes
2,258

Thanks Reinis But How know what row (item) have problem?

Thanks

Read only

0 Likes
2,258

BAPI's most often receive EDI.  Amazingly enough, it is not that uncommon for EDI to send some real trash.  Exceptions have to be handled...

Neal

Read only

0 Likes
2,258

Unfortunately you can't know that using given approach. It only goes as far as catches given error instead of outputting it to screen (and terminating your process).

As Suhas pointed out above, normally there shouldn't be such "unhandled errors" in SAP standard BAPI. Therefore, if you need as well to have proper reference to input item which caused the problem, your only option would be to open OSS incident and complain there about improper behavior of given standard BAPI.

One final work-a-round would be before actual posting, to call BAPI several times in TEST mode (if such is available for given BAPI) - once per each item. That could allow you to identify and filter out problematic item before you call BAPI with all items in productive mode. Yet this is by far not elegant approach and rather last resort work-a-round in case OSS would fail to fix given BAPI in reasonable time.

Read only

0 Likes
2,258

Point well made! Indeed such approach would be more common to reusing some other SAP standard function modules rather than BAPI.