Goal 1 – Create SAP Fiori Bar Chart using CDS and without any HTML/JS Coding.
There are 6 parts to be done.- Create CDS View
- Expose CDS View as OData
- Generate/Activate the OData Service
- Apply the UI Annotations to the CDS View
- Create the Fiori App in Web IDE
- Add Cards in the Fiori App
Step 1 – Create CDS View and fetch data from the database table.
@AbapCatalog.sqlViewName: ‘ZTM_FNS_SQL’@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: ‘CDS View to for Fiori App’
// CDS View for List Report (Bar Chart).
define view ZTM_FNS
as select from t001k
{
key bukrs as com_code,
key count(*) as tot_plants
}
group by
bukrs
Step 2 – Expose the CDS View as OData
@OData.publish: true
Step 3 – Activate the OData in SAP Backend using t-code /N/IWFND/MAINT_SERVICE
Hit Add Service

Once it is activated, the OData will be listed in the Service Catalog in t-code /N/IWFND/MAINT_SERVICE.
Your OData Service name will be the CDS name followed by _CDS.


Let us test the Entity Set using URI – /sap/opu/odata/sap/ZTM_FNS_CDS/ZTM_FNS


If you are not familiar with SAP OData Concepts, please take the Tutorial Series and Free Video Course on SAP OData Services.
Step 4 – Apply the UI Annotations to the CDS View
@UI.lineItem is generously used.
@UI.lineItem: [{
position: 10,
label: ‘Company Code ‘}]
Position is determined in the multiple of 10s. Example 10, 20, 30 etc, 10 being the first position.If we use one CDS View to build 2 Cards (two different charts, ex bar chart and donut chart in the same page), then we need Qualifier. It helps the Fiori to identify the Cards. One for Bar Chart and another for Donut Chart. Qualifier helps the UI to differentiate the Cards.
The UI Annotation is enhanced with the Qualifier ‘Q1’. It can be any name. You can also name your Qualifier as ‘SAPYard’. 😊
@UI.lineItem: [{
position: 10,
label: ‘Company Code’, qualifier:
‘Q1’}]
TOT_PLANTS in our CDS View is a measure. The measures (numbers) are indicated in UI.lineItem type #AS_DATAPOINT.Now, let us enhance the UI annotation for TOT_PLANTS field.
@UI.lineItem: [{
position: 20,
label: ‘Total Plants in CC’, qualifier:
‘Q1’, type:
#AS_DATAPOINT }
]
When you specify a field as DATAPOINT, you need to specify
the UI.dataPoint Properties before the #AS_DATAPOINT type is mentioned.@UI.dataPoint:
{
title: ‘Number of Plants in CC’,
criticalityCalculation: {
improvementDirection: #TARGET,
toleranceRangeLowValue: 8,
deviationRangeHighValue: 10
}
}
The CriticalityCalculation helps in coloring the bar. With the above values, if the toleranceRangeLowValue is 8 to 10, then Green. If deviationRangeHighValue is 10 or more, it will be Red. If it is below 8, it will be Yellow.
The CDS should look like this now.

Note: When
we write the UI Annotations in CDS Views, it generates the Annotation
file behind the scene which will be used by Fiori App. The Annotation
file has the suffix _VAN. (We will see its usage in the next part below)
If your CDS View name is ZMATMAS, then you OData Service
will be ZMATMAS_CDS and you
Annotation file will be ZMATMAS_CDS_VAN.
Hope this is clear. 😊
Also Read – Step by Step SAPUI5 Tutorials
Step 5 – Create Fiori App in WebIDE









Give the backend userid and password. Check below, there is
no output shown. Why?

Also Read – Step by Step ABAP on HANA Tutorials
Step 6 – Add Card in Fiori App
Right Click on Project -> New – Card



Selection Variant is for Selection Screen.
PresentationVariant is for initial default presentation.
DataPoint is for Measures (number). We will use these properties in next exercise.
In the Card Properties, we need to select Add OData Select. It will enable the OData URI options like $select, $top etc.
List Type = Extended or Condensed
List Flavor = Bar
Sort By = com_code
Sort Order = Ascending
Hit next.






Because we defined the criticalityCalculation in our CDS View. Just check the code again. You can play around with the numbers and get your colors.

Also Read – Virtual Data Model – Embedded Analytics
Now, let us add a Donut Chart at the right on the same SAP Fiori App.Goal 2 – Create SAP Fiori Donut Chart using CDS and without any HTML/JS Coding.

- Create CDS View
- Expose CDS View as OData
- Generate/Activate the OData Service
- Apply the UI Annotations to the CDS View
- Create the Fiori App in Web IDE
- Add Cards in the Fiori App
Step 1 – Update the CDS View which was created above.
For Charts, the UI Annotation has to be at the Top level. We can have multiple charts in the same UI. They must be identified/differentiated using Qualifiers.
// Donut Chart Annotation
@UI.chart: [{
qualifier: ‘Q2’,
title: ‘Plant Count’,
chartType: #DONUT,
dimensions: [‘com_code’],
measures: [‘tot_plants’],
dimensionAttributes: [{ dimension: ‘com_code’, role: #CATEGORY }],
measureAttributes: [{ measure: ‘tot_plants’, role: #AXIS_1, asDataPoint: true }]
}]
@UI.chart: [{
qualifier: ‘Q2’,
title: ‘Plant Count’,
chartType: #DONUT,
dimensions: [‘com_code’],
measures: [‘tot_plants’],
dimensionAttributes: [{ dimension: ‘com_code’, role: #CATEGORY }],
measureAttributes: [{ measure: ‘tot_plants’, role: #AXIS_1, asDataPoint: true }]
}]

For Dimension Attributes the role can be Category or Series.


measureAttributes: [{
measure: ‘tot_plants’, role: #AXIS_1, asDataPoint: true }]
Note: When we create bar charts, we need to specify X axis and Y axis. But when we create donut charts, we need to specify the dimensions and measures.This is how the CDS will look now.

The only step left is to add the new Card to the Fiori App.
6. Add New Card for Donut Chart in the Fiori App
We will do the same thing. Right Click -> New –> Card.



Cancel the wizard and open the manifest file in code editor.


“card01”: {
“model”: “ZTM_FNS_CDS”,
“template”: “sap.ovp.cards.charts.analytical”,
“settings”: {
“title”: “{{card01_title}}”,
“subTitle”: “{{card01_subTitle}}”,
“entitySet”: “ZTM_FNS”,
“chartAnnotationPath”: “com.sap.vocabularies.UI.v1.Chart#Q2”,
“dataPointAnnotationPath”: “com.sap.vocabularies.UI.v1.DataPoint#Q2”,
“identificationAnnotationPath”: “com.sap.vocabularies.UI.v1.Identification#Q2”,
“navigation”: “dataPointNav”
}
}
Let us test it now.“model”: “ZTM_FNS_CDS”,
“template”: “sap.ovp.cards.charts.analytical”,
“settings”: {
“title”: “{{card01_title}}”,
“subTitle”: “{{card01_subTitle}}”,
“entitySet”: “ZTM_FNS”,
“chartAnnotationPath”: “com.sap.vocabularies.UI.v1.Chart#Q2”,
“dataPointAnnotationPath”: “com.sap.vocabularies.UI.v1.DataPoint#Q2”,
“identificationAnnotationPath”: “com.sap.vocabularies.UI.v1.Identification#Q2”,
“navigation”: “dataPointNav”
}
}

Also Check – S/4HANA Technical Overview for Beginners
The card title and sub title descriptions are not correct. Reason being we did not add the values in i18n.



Không có nhận xét nào:
Đăng nhận xét