cancel
Showing results for 
Search instead for 
Did you mean: 

Entity Type in combination with "BAPIRET2"

Former Member
0 Kudos

hello!

I just started using sap netweaver gateway and I am a complete beginner, so please take it slow on me (I am very thankful for useful links).

in transaction SEGW I have a question how I can build a smart solution for creating an entity type which is used to handle my business logic in the backend (erp) and also passing something like a bapiret2 to the frontend (SAP UI5) whether it has passed or failed.

here is a simple example:

I have a small Z table with personnel number (PERSNR), first name, last name and I'm passing via my odata channel the ID (PA0032-WAUSW) and create an entry in this Z table.

So actually I want to tell my frontend something like "Entry created" or "no ID found". How do I model this? My first and I guess wrong thought was to create an entity which has the fields of my Z table + the ID + the BAPIRET2 structure.

I am somehow a bit confused...maybe you can help me clear up my mind?

Thank you very much,

BR,

Dominik

Accepted Solutions (1)

Accepted Solutions (1)

kammaje_cis
Active Contributor
0 Kudos

Hi Domonik,

You cannot return BAPIRET2 kind of messages here. But you can return a HTTP status code and message. Following links can be helpfull.

http://scn.sap.com/thread/3343754

http://help.sap.com/saphelp_nw74/helpdata/en/81/2dfe50645c741ae10000000a423f68/content.htm?frameset=...

Thanks

Krishna

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

I am new to Odata service. I have created one Odata service for Create operation and it is returning success code 201 that means Create operation performed successfully. But in the BAPI for create operation we are getting some return messages like "Created successfully''. But in the Odata service I am not able to get those success return messages.

The messages are stored in some internal output table IT_RETURN that is of type BAPIRET2 in SAP system.

Can anybody help me that how to fetch the return messages in Odata service.

With Regards

Neha Pandey

former_member190756
Active Contributor
0 Kudos

Hi Neha,

in this blog is described how you can return Info and Warning messages:

http://scn.sap.com/thread/3470565

Best regards,

Steffen

Former Member
0 Kudos

Hi Dominik,

You have to start thinking a bit differently when using Gateway - but not that much.

Firstly, keep it simple. Why do you need a "message" to tell you that something worked? You expect it to work! In that case, the service will return the proper http response status code (because there is no exception). If you want to give your user a message, do it on the client (UI) side when the response code is received. Don't waste network bandwidth with a redundant message.

On the other hand, if something goes wrong, you probably should send a message. Even if you don't send a message you must raise an exception to enable the Gateway OData processor to detect and return an error response code. 

And be assured, if you send something that can't be understood, Gateway will give you back no end of messages

Regards

Ron.

Former Member
0 Kudos

hello Ron!

thanks for your input - yes, it is true, I need to reconsider some "work routines" do you have any helpful links aswell for your example of how to raise a "non standard" exception and pass it via the odata channel to the frontend?

BR,

dominik

kammaje_cis
Active Contributor
0 Kudos

Here is a a sample code on how to raise exceptions in the Gateway Context.

http://help.sap.com/saphelp_nw74/helpdata/en/f2/a126519eff236ee10000000a445394/content.htm

Former Member
0 Kudos

Hello Krishna!

Thanks for the example which actually works really fine

Unfortunately it doesn't fit exactly my business case because I actually don't really send a "Bad Request" (http 400).

I actually want a http 200 status request AND an error message on the frontend which actually comes from the backend (ABAP method). Something like "The entered values are not correct!"

---edit---

I have found the API for /IWEBP/IF_MESSAGE_CONTAINER with method ADD_MESSAGE_FROM_BAPI which seems to work. The only problem is that in the output XML from the Gateway Test I can't find anything. Do I have to do something apart from adding the message?

kammaje_cis
Active Contributor
0 Kudos

Hi Dominik,

You cannot send a Success HTTP Status code as well as an error message. That does not sound logical for me.

You can ignore the HTTP status code right? . Moreover, in the link I mentioned, I see a HTTP status code through which I believe you can influence the Status Code.

In rest protocol,

Successful POST need to return 201 and return the Entity Created. - No message allowed

Successful PUT - 200, and No Content to be returned.

Only failures can return messages.

Thanks

Krishna