cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with Create/Update/Post of OData service

kell_vagtholm1
Explorer
0 Kudos

Hi Experts

I created a service and got my GetEntitySet and GetEntity created and tested using the Gateway Client interface.

Now I want to create and test my Create/Update/Delete methods.

In Gateway Client I want to create a POST HTTP request, but I haven't been able to find any information on the format of the request and how to code my method in ABAP.

Please anyone if you will please enlighten me on this

Tried to read a lot of other posts on the forums, but haven't been able to figure out what the format should be.

Best regards.

Kell Vagtholm

When I use this code in my POST HTTP request:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<atom:content type="application/xml">
  <m:properties>
   <d:Username>KVA</d:Username>
   <d:Lunchdate>2013-08-29T00:00:00</d:Lunchdate>
   <d:Creaby>KVA</d:Creaby>
   <d:Creadate>2013-08-29T00:00:00</d:Creadate>
   <d:Idx>2</d:Idx>
   <d:Noof>01</d:Noof>
  </m:properties>
</atom:content>
</atom:entry>

I get an error message back:

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

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

  <code>005056A509B11ED1B9BF9F46AA8E82ED</code>

  <message xml:lang="en">In the context of Data Services an unknown internal server error occured</message>

  </error>

Using ?sap-ds-debug=true gives me this error information:
Header 1

Value '00000000' violates facet information 'nullable=false'

Exception /IWCOR/CX_DS_EDM_FACET_ERROR occured in Class /IWCOR/CL_DS_EDM_DATE_TIME Method /IWCOR/IF_DS_EDM_SIMPLE_TYPE~TO_STRING and Line 18

1 method /IWCOR/IF_DS_EDM_SIMPLE_TYPE~TO_STRING. 2     DATA: 3       l_dsedx_date TYPE d, 4       l_dsedx_time TYPE t, 5       l_dsedx_days TYPE i, 6       l_dsedx_seconds TYPE p LENGTH 10 DECIMALS 0, 7       l_dsedx_milliseconds TYPE n LENGTH 3, 8       l_dsedx_length TYPE i, 9       l_dsedx_offset TYPE i. 10     FIELD-SYMBOLS: 11       <dsedx_p> TYPE p. 12  13     dsedx_initialize_descriptor io_element_descriptor lo_descriptor iv_value. 14  15     IF iv_kind = kind_json. 16       dsedx_format_datetime_json rv_value iv_value id_facets lo_descriptor. 17     ELSE. 
18       dsedx_format_datetime rv_value iv_value id_facets lo_descriptor. 
19       IF iv_kind = kind_uri. 20         to_uri_literal rv_value. 21       ENDIF. 22     ENDIF. 23 endmethod. 
Parameter has invalid value: Parameter IV_VALUE has invalid value 00000000.

Exception CX_PARAMETER_INVALID_RANGE occured in Class /IWCOR/CL_DS_EDM_DATE_TIME Method /IWCOR/IF_DS_EDM_SIMPLE_TYPE~TO_STRING and Line 18

1 method /IWCOR/IF_DS_EDM_SIMPLE_TYPE~TO_STRING. 2     DATA: 3       l_dsedx_date TYPE d, 4       l_dsedx_time TYPE t, 5       l_dsedx_days TYPE i, 6       l_dsedx_seconds TYPE p LENGTH 10 DECIMALS 0, 7       l_dsedx_milliseconds TYPE n LENGTH 3, 8       l_dsedx_length TYPE i, 9       l_dsedx_offset TYPE i. 10     FIELD-SYMBOLS: 11       <dsedx_p> TYPE p. 12  13     dsedx_initialize_descriptor io_element_descriptor lo_descriptor iv_value. 14  15     IF iv_kind = kind_json. 16       dsedx_format_datetime_json rv_value iv_value id_facets lo_descriptor. 17     ELSE. 
18       dsedx_format_datetime rv_value iv_value id_facets lo_descriptor. 
19       IF iv_kind = kind_uri. 20         to_uri_literal rv_value. 21       ENDIF. 22     ENDIF. 23 endmethod. 
An exception with the type CX_PARAMETER_INVALID_RANGE occurred, but was neither handled locally, nor declared in a RAISING clause

Exception CX_SY_NO_HANDLER occured in Class /IWFND/CL_SODATA_POST_PROC Method ABAP_KEY_TO_EDM and Line 1

1 METHOD abap_key_to_edm. 
2  3   DATA: lr_key     TYPE REF TO /iwfnd/if_mgw_core_types=>key_s, 4         lo_type    TYPE REF TO /iwcor/if_ds_edm_simple_type, 5         ls_key     TYPE /iwcor/if_ds_uri=>key_predicate_s, 6         lr_facets  TYPE REF TO /iwcor/if_ds_edm_element=>facets_s. 7  8   FIELD-SYMBOLS: <value>  TYPE data. 9  10   LOOP AT it_key REFERENCE INTO lr_key. 
In the context of Data Services an unknown internal server error occured

Exception /IWCOR/CX_DS_INTERNAL_ERROR occured in Program SAPMHTTP Include  and Line -0

What does it mean?

Accepted Solutions (1)

Accepted Solutions (1)

kammaje_cis
Active Contributor

Hi Kell,

Your Post request body is right. There is no problem with that.

Problem seems to be with your date time values and their formats.

I would suggest you to go to your entity, mark all non-key parameters as nullable, Regenerate the runtime artefacts, Clear the cache and try again.

Logic behind this suggestion:  Whenever there is a problem with formats like this, the conversion results in a null for that property. With the property marked as not nullable (default) it might throw an error like this.

Keep an eye on my blog http://scn.sap.com/community/netweaver-gateway/blog/2013/08/09/frequent-problems-encountered-in-netw... for other issues.

Thanks

Krishna

kell_vagtholm1
Explorer
0 Kudos

Hi Krishna

Thanks for your response.

I thought that the post request body was ok - nice to get it confirmed.

When I check my service with GET $metadata i get this:

..

<Property Name="Creadate" Type="Edm.DateTime" Nullable="false" sap:label="Date" sap:sortable="false" sap:filterable="false" />

..

In the service builder my date fields are set to Nullable! (see attached photo)? I tried to delete the field and create it again - and after [Generate Runtime Objects] it still appear with Nullable="false" in $metadata.

Should the meatadata not hold property Updatable="false" and Deletable="false"?

Is there some way I can refresh the cache - that must be the problem.

Best regards,

Kell Vagtholm

Message was edited by: Kell Vagtholm  Sorry - just read your post and found the cache transactions Thanks. But that did not solve the problem!

former_member184867
Active Contributor
0 Kudos

Hi Kell,

In this case for property 'Createdate'   it should be Nullable = 'true'.

I think the class generation is not happening correctly. it would be good if you delete the generated classes and then regenerate the runtime classes once again.

Updatable="true" and Deletable="true" in your case. So it does not appear in the  metadata document.Only the attributes with value equals to 'false' appear in metadata document.

Regards,

Atanu


kell_vagtholm1
Explorer
0 Kudos

Exactly - as i listed my metadata does not correspond with my property settings for the field creadate.

The metadata should list  Updatable="false", Deletable="false", sap:sortable="false", and sap:filterable="false".

Which leads me to the question why not sap:updatable and sap:deletable?

How do I delete the auto generated classes? Think it will be easier to start all over and generate a new service from scratch. And check the metadata along the way before I do the ABAP coding.

Best regards,

Kell Vagtholm

kammaje_cis
Active Contributor
0 Kudos

Hope you ran both the transactions in right systems. (/IWBEP/* in BEP system and the other one in Hub or FND system).

Now when you see your metadata do you see them as nullable = true for the date field?

kell_vagtholm1
Explorer
0 Kudos

Hi Krishna

I did run transactions on both systems, but still my metadata does not correspond with the properties.

I found two notes related to GW and metadata or regenration of objects, and asked our basis people to install them.

I hope when they are installed I can try and regenrate my service and it is ok then.

I will come back here with a response.

Thanks.

Best regards,

Kell Vagtholm

kell_vagtholm1
Explorer
0 Kudos

Hi Krishna

I created a small example in a PDF document while trying to test the properties.

Is there some way I can post this PDF to you so you can see it? (It is 8 pages with screen dumps - tried to insert it here but it looks bad.)

Best regards,

Kell Vagtholm

Former Member
0 Kudos

Hi Kell,

I think you will find the error is due to the fact that your POST body does not specify all of the properties, especially the key which is incomplete. The GW framework won't make these up.

I also have to say the key structure isn't great .  Why not simply assign a guid key to the entity? The other properities can then be secondary indexes used for filtering.

Regards

RS

kell_vagtholm1
Explorer
0 Kudos

Hi Ron

Thanks for answer.

Do I have to specify all keys in the POST?

I thought that only the 'creatable' properties were supposed to be specified. My backend will take care of the rest. I only send what is absolutely the minimum in order to create my table entry in backend.

What if I discard some of the keys so that only my lunchdate and username is key? and omit the others as keys.

Would that help? I really only need those properties in backend in order to see when the records was created and by whom.

Best regards,

Kell Vagtholm

Former Member
0 Kudos

Hi Kell,

You can pretty much ignore the CRUD related fields because they do nothing in the backend. You can create a value in any property regardless of it being set to 'Createable'.

When you POST an entity, the server needs to know what the key (URI) of this resource is going to be unless it is a server-assigned address (in this case it is not, if it were a GUID, it would be). Not sending all key property values is breaking the rule and causing it to break during parsing. If you have values like 'userid', then yes the backend could use sy-uname and you don't need to send it, but you do need to have the property in the content list even if it is empty. The additional problem with date-time is that GW doesn't like properties of this type to be nulled unless it is set to 'is-nullable' (and why would you specify a key value that is going to be a null?).

The only time you don't need to send all properties is when you update with a PATCH operation.

Regards

Ron.

kell_vagtholm1
Explorer
0 Kudos

Hi Ron

This leads me back to the initial problem:

When I add all properties to my POST i get this error:

Value '00000000' violates facet information 'nullable=false'

Exception /IWCOR/CX_DS_EDM_FACET_ERROR occured in Class /IWCOR/CL_DS_EDM_DATE_TIME Method /IWCOR/IF_DS_EDM_SIMPLE_TYPE~TO_STRING and Line 18

From this request:

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

<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">

<atom:content type="application/xml">

  <m:properties>

   <d:Creadate>2013-08-29T12:00:00</d:Creadate>

   <d:Creaby>KVA</d:Creaby>

   <d:Lunchdate>2013-08-29T12:00:00</d:Lunchdate>

   <d:Username>KVA</d:Username>

   <d:Firstname>Kell</d:Firstname>

   <d:Lastname>Vagtholm</d:Lastname>

   <d:Idx>2</d:Idx>

   <d:Noof>01</d:Noof>

  </m:properties>

</atom:content>

</atom:entry>

All my properties have blank flag at the nullable.

Best regards,

Kell Vagtholm

Message was edited by: Kell Vagtholm I just created a variant - a new entity set where I don't have the first two fields and only my LUNCHDATE is a key. I created the methods and checked the service with GET and GET$metadata - all seems ok, When I post with all fields specified I get the same error - that my date (key field) is set to nullable="false". I just don't get it!? Best regards, Kell Vagtholm

Former Member
0 Kudos

Hi Kell,

This was nagging away at the back of my mind as it seemed to be a familiar issue, I've now figured out what is wrong.

There is nothing wrong with the latest POST body, the problem is in your ABAP.

In the create_entity method, there is an export parameter called er_entity. You must place the created properties back into this structure, as GW will then return this feed to the poster along with a success http status. If you fail to do this, and there is a non-nullable date, you get exactly the error you are having.

The problem is that the parser cannot parse the "output" because it's empty, the input is fine!  

regards

Ron.

kell_vagtholm1
Explorer
0 Kudos

Thanks!

It was exactly the case. My post was ok - but since I didn't write any code to the method it never returned anything.

When I created the ABAP code everything worked as it should.

Best regards,

Kell Vagtholm

Answers (1)

Answers (1)

ruben_rollano
Participant
0 Kudos

Thank you Krishna, a lot of time later it solve also my problem XD.