0
votes

I have an integer number in SAPDB but it has to be store as NUMERIC for some reason and numeric values are stored as string in SAP DB.

Thus OData service returns 0000000001 instead of 1.

SO the question is how can I remove leading zero in XML View. The problem is that I can not use Javascript for formatting when I use XML View.

The only solution that I found is to use a code like this:

<Text text="{path:'ZId', type:'sap.ui.model.odata.type.ODataType', oConstraints:{isDigitSequence: true}}" />

But I don't know why it does not remove the leading zeros while it has been said in its references:

if true, the value is handled as a sequence of digits; while formatting leading zeros are removed from the value and while parsing the value is enhanced with leading zeros (if a maxLength constraint is given) or leading zeros are removed from the value (if no maxLength constraint is given); this constraint is supported since 1.35.0. To make this type behave as ABAP type NUMC, use oConstraints.isDigitSequence=true together with oConstraints.maxLength.

The references that I found some related data were in the following links:

https://archive.sap.com/discussions/thread/3681816

https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.model.odata.type.String.html

https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.model.type.Integer.html

https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.core.format.NumberFormat.html

2

2 Answers

9
votes

You are neither using the correct type implementation nor the correct binding syntax for setting the constraints. Please check the documentation:

<Text text="{
    path : 'ZId', 
    type : 'sap.ui.model.odata.type.String', 
    constraints: { 
         isDigitSequence : true,
         maxLength : 10
    }
}"/>
-1
votes

Try this code for leading the zeros:

<ObjectNumber number="{= parseFloat(${ZId}) }"/>

or

<Text text="{= parseFloat(${ZId}) }"/>