cancel
Showing results for 
Search instead for 
Did you mean: 

Gateway Service with Custom BAPI for POST

mike_reader3
Active Participant
0 Kudos

All,

I have created a GW Service with READ, QUERY and POST. READ & QUERY are using SAP delivered BAPIs, for POST I wrote a custom BAPI so I could include the commit.

When READ or QUERY fails (ie cannot find a record with the given params), I get a message back from the service, which is great ... the issue is around POST.  If the object fails to create in the POST custom BAPI (say an equipment), technically the POST was successful, but the equipment failed to create, so I would like to not return a status_code 201 and status_reason Created.

What am I missing here?

Thanks, Mike

Accepted Solutions (1)

Accepted Solutions (1)

mike_reader3
Active Participant
0 Kudos

To clarify a bit more ... perhaps I don't need to change the status_code 201 and status_reason Created ... but if the equipment fails to create how do I let the user know if POST does not return any params and the status says it is okay?

kammaje_cis
Active Contributor
0 Kudos

You can raise an exception in the Gateway data provider class and pass the message. Message should be available at the client.

/IWBEP/CX_MGW_BUSI_EXCEPTION - SAP NetWeaver Gateway Foundation (SAP_GWFND) - SAP Library

mike_reader3
Active Participant
0 Kudos

If I raise this exception in my custom BAPI, then I assume I would have to do the try/catch in the app itself?

-Mike

kammaje_cis
Active Contributor
0 Kudos

You do not have to catch it. Try it.

mike_reader3
Active Participant
0 Kudos

So I tried a test with the NW GW Client and this is what I got back ... doesn't seem right:

<?xml version="1.0" encoding="utf-8" ?>

- <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">

<code>SY/530</code>

<message xml:lang="en">RFC call ended with "Communication Failure" exception (An exception with the type /IWBEP/CX_MGW_BUSI_EXCEPTION occurred, but was neither handled locally, nor declared in a RAISING clause).</message>

- <innererror>

<transactionid>533C172709FD09F0E1008000AC110A43</transactionid>

- <errordetails>

- <errordetail>

<code>/IWBEP/CX_SD_GEN_DPC_TECH</code>

<message>RFC call ended with "Communication Failure" exception (An exception with the type /IWBEP/CX_MGW_BUSI_EXCEPTION occurred, but was neither handled locally, nor declared in a RAISING clause).</message>

<propertyref />

<severity>error</severity>

</errordetail>

</errordetails>

</innererror>

</error>

kammaje_cis
Active Contributor
0 Kudos

This is the key to this error. "but was neither handled locally, nor declared in a RAISING clause".

Put this exception in the raising clause of your custom method.

mike_reader3
Active Participant
0 Kudos

I am actually using a Function Module, not a method, when I tried to add it got this message:

During RFCs or update, no exception classes can be used.

So I guess I need to do the work with a class/method rather then FM.

-Mike

kammaje_cis
Active Contributor
0 Kudos

What I would do is capture error message from RFC and raise the exception after executing the RFC. (not inside RFC)

mike_reader3
Active Participant
0 Kudos

Okay, I was with you until that last comment.

I have the custom RFC BAPI mapped to the Create (POST) method of my GW Service.  The POST method does not (appear to) return any parameters, how would I capture the the error message in the RFC and raise the exception (where?).  I am looking at the classes that are generated by the service builder, perhaps somewhere in there?

-Mike

kammaje_cis
Active Contributor
0 Kudos

When you raise this particular exception from *DPC_EXT class, Gateway framework will catch it and send the message in the exception to the client.

mike_reader3
Active Participant
0 Kudos

Ok that makes sense, while I was in the *DPC_EXT class and found where they call the RFC.

Thanks for your help.

Answers (0)