cancel
Showing results for 
Search instead for 
Did you mean: 

How to return a large number of messages in an OData service?

0 Kudos
1,952

We are using an OData service to call BAPI_SALESORDER_SIMULATE. For very large orders (1000+ lines) many messages can be returned in the parameter table MESSAGETABLE. We would like to return these messages to the consumer/caller of the service but how can we do that for so many messages?

Since there is no UPDATE_DEEP_ENTITY (PUT) we are using CREATE_DEEP_ENTITY (POST).

We have looked into the following options:

A) We return the messages in the http-header parameter sap-messages. This doesn't work as apparently there is a limit to what this parameter can contain.

B) Someone suggested using a Complex Type - but apparently there is a 1:1 relationship between this and the entity which in this case is SalesOrder. Which means we cannot return more than one message.

C) Then we wanted to create a seperate entity for messages and return this in the response body. But it looks like it is not possible to return any entities that wasn't in the request to begin with.

Am I wrong about the conclusions of A, B and C - maybe I have missed or misunderstood something?

If I am correct that the problem cannot be solved using neither A, B nor C, how can this problem then be solved?

Our solution/workaround for now is that when more than 100 messages are returned from the BAPI we simply return a single message to the requestor saying "too many messages. cannot be displayed" (or something like that).

Thanks in advance.

View Entire Topic
Ankit_Maskara
Product and Topic Expert
Product and Topic Expert

The approach C should be modified a bit as under.

1. Model as below. Here have a three level navigation. Dummy Entity to Sales Order to Message Table. The underlined properties denote key fields in below JSON model.

{
"DummyKey": "XXXXXX",
"SalesOrders": [{
"DummyKey": "XXXXXX",
"SalesOrderID": "1",
"Attribute1": "<value 1>",
"Messages": [{
"DummyKey": "XXXXXX",
"SalesOrderID": "1",
"MessageId": "1",
"MessageType": "E",
"MessageText": "This is an error message for Sales Order 1"
},
{
"DummyKey": "XXXXXX",
"SalesOrderID": "1",
"MessageId": "2",
"MessageType": "E",
"MessageText": "This is an another error message for Sales Order 1"
}
]
}]
}
0 Kudos

Hi Ankit,

Thank you for the detailed example. Now it shouldn't be possible for me to do anything wrong 🙂

Thanks

Michael

BODHISATTWA__20
Participant
0 Kudos

ankit.maskara3

Hi I am applying your logic .
But how do we deal with Status Error COde?

If we need to return the error Messages as separate entity , The status code has to be 200.

Ankit_Maskara
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Bodhisattwa,

If you want to follow above approach then it assumes that the HTTP call will be successful and the Deep Create will return a 200 code. Then only the payload can be returned whose structure was mentioned in my previous answer.

Else, you can return a single message in HTTP header and set the status code suitably to some error like 500.

Thanks and Regards.