cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass decimal data to Netweaver OData service from JSON input

ansonabraham
Participant
0 Kudos

Hi,

I have a POST service and I am trying to send some some data to the webservice using JSON format. In my input, only the decimal fields are not getting passed to the service. The Edm type of those fields is Decimal (13,3).

My JSON input is as follows:

"Item":[{"Field1":"xxxxx",    "Field2":"yyyy",   "DecimalField1":"1.000",         "DecimalField2":"2.000""DecimalField3":"3.000"}]


Please tell me whether I need to change the format of the decimal fields in the input.

Accepted Solutions (1)

Accepted Solutions (1)

kammaje_cis
Active Contributor
0 Kudos

Anson,

In such cases, I would simply implement Read/Query (just hard code values in DPC_EXT) and see how property value appears in json response body.

Regards

Krishna

ansonabraham
Participant
0 Kudos

Hi Krishna,

I have followed your instructions and I am able to get the desired output when I hard-coded the values in DPC_EXT. But the problem happens when I use the CREATE_DEEP_ENTITY method. Inside this method, the decimal field values present in the input JSON strucutre are not passed from the front end. I have an association defined in my service to connect the headerset and itemset and I am calling the service in below format.

/sap/opu/odata/sap/servicename/HeaderSet/

Whether the webservice call pattern have any issue ?

kammaje_cis
Active Contributor
0 Kudos

Ok. So the content of the deep entity is not getting passed is it?

Carefully check the technical name of the property and name of the internal table's column (in CREATE_DEEP_ENTITY). There might be a mismatch.

Answers (3)

Answers (3)

Hvshal4u
Active Participant
0 Kudos

You can try using like below:

"Item":[{"Field1":"xxxxx",    "Field2":"yyyy",   "DecimalField1":"1.000",        "DecimalField2":"2.000M""DecimalField3":"3.000M"}]


Regards,

Vishal

JyotiD
Active Participant
0 Kudos

Hi Anson,

As mentioned by Krishna it is always good practice to implement read in case of dilemma.

Coming on your question there is no need to change the format of input fields, it looks fine passing the values in this way.

One thing to be noted is if your precision is 13 and scale is 3, and you are passing values in below format, gateway framework will automatically change them according to scale.

Input          Gateway

"2"               "2.000"

"2.16"          "2.160"

"2.1665"       "2.167"

Overflow will happen if value is exceeding from 13 digit before decimal.

Try keeping breakpoints in create method and check where the values are truncated.

Regards,

Tarun

AshwinDutt
Active Contributor
0 Kudos

Hello Anson,

The format which you are sending is correct.

In my service i have a similar property Price with Edm.Decimal where Precision is 13 & Scale is 2.

In payload i send it as below which works fine for me during POST operation.

{

....

"Price":"1.00",

.....

}

If at all you have defined a local structure in DPC_EXT class to read the payload, then check if the field names and their order is same as the one defined in MPC/MPC_EXT class.

If ABAP filed names differ then values come initial.

Regards,

Ashwin