cancel
Showing results for 
Search instead for 
Did you mean: 

Formatting decimal accondingly unit of measure - Fiori Elements

alessandraarm
Explorer

Hello guys!

We have a requirement to display a quantity field formatting the decimals accordingly unit of measure configuration in a report built using Fiori Elements, like the COOISPI:

COOISPI transaction:

In this transaction the decimals of the target quantity are formatted using the unit of measure configuration, the unit HL has 3 decimals and the UoM PC doesn't have decimals.

In the list reports built using Fiori Elements, the quantity column is always with 3 decimals like the domain of this field:

In the CDS we are using the annotations below:

      @EndUserText.label: 'ProducedQuantity'
      @Semantics.quantity.unitOfMeasure: 'UnitMeasure'
      a.ProducedQuantity as ProducedQuantity,
      @UI.lineItem: [{position: 110}]
      @EndUserText.label: 'UnitMeasure'
      @Semantics.unitOfMeasure: true
      a.UnitMeasure

Is there a way to format the decimals in the column quantity based on the unit of measure configuration in Fiori Elements?

Best regards,

Alessandra

View Entire Topic
jorgecarvalhoaw
Explorer

Hi Alessandra,

probably too late for you, but it might help someone now or in the future. I've opened an SAP ticket for the same issue and I'll share SAP response when I info on this.
However I got this info from another SAP customer that got this info from SAP:

"Dear Customer,

I was able to reproduce the issue with the 3 decimals for PCE and I was able to analyse it.

In the UI5 version 1.96 we are using the feature of unit and currency code lists as documented in the section "Currency and Unit Customizing in OData V2" of

Currency and Unit Customizing in OData V2

.
That means UI5 is using these code lists to render a different number of decimal places depending on the used unit or currency. If no codelists are available we are using 3 decimals by default (which was a requirement from stakeholders).
Usually these code lists are exposed automatically when using CDS Views. Unfortunately your backend system uses ABAP Basis 7.50 in which this automatism is not yet included. A downport of that feature to that release is not possible. With 7.56 or higher, the unit and currency code lists are automatically exposed if a property is annotated as a unit.

There are several options that could be done:
1) If it is planned to upgrade/update soon to 7.56 you will get that automatism and your application will display no decimals for unit PCE as expected if the customizing in the backend has 0 decimals for PCE.

2) You can help yourself by enhancing your service in a way that it also includes the unit customizing.
That means the service should contain an additional entity type and set for units (see entity type and entity set "SAP__UnitOfMeasure" in the documentation above). The values of the service shall reflect the unit customizing in the corresponding backend system, for example:
<EntityType Name="MyUnitsOfMeasure" sap:content-version="1">
<Key>
<PropertyRef Name="UnitCode"/>
</Key>
<Property Name="UnitCode" Type="Edm.String" Nullable="false" MaxLength="3" sap:label="Internal UoM" sap:semantics="unit-of-measure"/>
<Property Name="ISOCode" Type="Edm.String" Nullable="false" MaxLength="3" sap:label="ISO Code"/>
<Property Name="ExternalCode" Type="Edm.String" Nullable="false" MaxLength="3" sap:label="Commercial"/>
<Property Name="Text" Type="Edm.String" Nullable="false" MaxLength="30" sap:label="UoM Text"/>
<Property Name="DecimalPlaces" Type="Edm.Int16" sap:label="Decimal Places"/>
</EntityType>
...
<EntitySet Name="MyUnitsOfMeasure" EntityType="MyService.MyUnitsOfMeasure" sap:creatable="false" sap:updatable="false" sap:deletable="false" sap:pageable="false" sap:content-version="1"/>

Additionally to that some annotations have to be provided that the client is using this customizing.
The entity container has to be annotated with com.sap.vocabularies.CodeList.v1.UnitsOfMeasure, for example:
<Annotation Term="com.sap.vocabularies.CodeList.v1.UnitsOfMeasure">
<Record>
<PropertyValue Property="Url" String="./$metadata"/>
<PropertyValue Property="CollectionPath" String="MyUnitsOfMeasure"/>
</Record>
</Annotation>
It is important that Url has the value "./$metadata", that means the metadata document for the unit customizing service is the same as for the data service you are currently using.

The unit code of the entity type has to be annotated with following annotation which describes which property of the entity type shall be used for which purposes:
<Annotations xmlns="http://docs.oasis-open.org/odata/ns/edm" Target="MyService.MyUnitsOfMeasure/UnitCode">

<Annotation Term="com.sap.vocabularies.Common.v1.Text" Path="Text" />
<Annotation Term="com.sap.vocabularies.Common.v1.UnitSpecificScale" Path="DecimalPlaces" />
<Annotation Term="com.sap.vocabularies.CodeList.v1.StandardCode" PropertyPath="ISOCode" />
<Annotation Term="com.sap.vocabularies.CodeList.v1.ExternalCode" PropertyPath="ExternalCode" />
</Annotations>
And finally if there are alternate keys following annotation is needed:
<Annotations xmlns="" Target="MyService.MyUnitsOfMeasure">
<Annotation Term="Org.OData.Core.V1.AlternateKeys">
<Collection>
<Record>
<PropertyValue Property="Key">
<Collection>
<Record>
<PropertyValue Property="Name" PropertyPath="ExternalCode" />
<PropertyValue Property="Alias" String="ExternalCode" />
<Record>
</Collection>
</PropertyValue>
<Record>
</Collection>
</Annotation>
</Annotations>

With that enhancement you will get again 0 decimals for PCE in your application.

3) Instead of using a default of 3 decimals for units we could maybe provide a fix which uses instead of 3 decimals the scale of the corresponding metadata document. There are ongoing discussions whether this could be done because it was a requirement from other stakeholders.

..."

Option 2 was chosen and it worked well.

asimchandra
Explorer

This really helped me. Thanks a lot!