Skip to Content

What to return from GetEntity if requested record is not found?


In my implementation of the GetEntity method I select the requested record from the database according to the key values passed to the method.

In case the requested record could not be selected because it doesn't exist, I simply return the empty (initial) er_entity.

This works in most cases and leads to an error like this:

       "errordetails" : [


           "code" : "/IWBEP/CX_MGW_BUSI_EXCEPTION",

           "message" : "Resource not found for segment 'ContractVersion'",

           "propertyref" : "",

           "severity" : "error",

           "target" : ""



In case my entity has fields of type Edm.DateTime which are mapped to ABAP type TIMESTAMP then I will receive an error like this:

   "error" : {

     "code" : "0050569259751EE4BA9710043F8A5115",

     "message" : {

       "lang" : "en",

       "value" : "In the context of Data Services an unknown internal server error occurred"


In the Gateway error log the error info is "Invalid format (return structure): Property Name 'ChDateTime',  Property Value '0 '"

So what shell be done if the requested entity is not found?

Should I manually raise an exception in the getEntity method?

Any other proposals or best practice?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 17, 2015 at 04:17 PM

    Hello Frank,

    IMO don't need to do any exception handling when no data found and GW result is initial. its fine if GW returns null response when no data found.

    Since the error is pointing to the Property Date field, please have a look at the below which explains handling of Date and Time fields of the GW model.

    Above will help to fix the Date and Time related issues.

    There are many others discussions in the forum for Date and Time handling. So please check for other threads.

    Coming to the error ' Resource not found for segment 'ContractVersion ' i suspect that your URL is pointing to a resource which is not defined in your GW Model.

    Please note the properties which we use in URL are case sensitive.

    Please share the URL which your are using for which error Resource not found for segment 'ContractVersion is encountered.

    When this error is found ? after Get_Entity method is executed ? or its a 400 bad request encountered at the initial stage of firing GET service ?



    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 19, 2015 at 04:36 AM

    Hello Frank,

    This seems to be fairly simple.

    1. Close the GW client.

    2. Go to the Date Property in your entity type.

    3. Check the nullable checkbox for the property.

    4. As a safety measure, do this for all properties except the key properties.

    5. Regenerate the runtime artifacts.

    6. Clear the cache using transaction /IWFND/CACHE_CLEANUP.

    7. Run the service again.

    Hope this helps.



    Add comment
    10|10000 characters needed characters exceeded

    • My OData service is accessed by a web appliction built with SAPUI5.

      The keys of the entity which is to be displayed on a "details page" are passed as navigation parameters in the hash:


      This parameters are taken to build the query string for the ContractVersion entity.

      So it is possible that the user manipulates the URL with a datetime value that doesn't exist in the backend database.

      So the case that an entity is requested which doesn't exist can but should not happen. In case it happens I expect the gateway to return a meaningful error message. Since this - in my oppinion - wrong behavior only happens when in a $batch operation, it doesn't make sense to me.

      Btw: The CHDATETIME field is not the only key in this table. CONTRACTID is also a key field.

      For now I think I have to live with it, but maybe I'll open an OSS report for this later.