Quantcast
Channel: SAPUI5 Developer Center
Viewing all articles
Browse latest Browse all 789

Step by Step to create CDS view through SmartTemplate + WebIDE

$
0
0

1. Create CDS view based on sample database table spfli and scarr

 

Create two CDS views in ABAP development studio. The source code for both are listed below. You just need to copy them into studio and click activate button.

 

@AbapCatalog.sqlViewName: 'zjerrySQL0309'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'test 20160309'
@ObjectModel: {   createEnabled,    deleteEnabled,   updateEnabled
}
define view Zjerrytest20160309
as select from spfli association [0..1] to scarr as _scarr
on _scarr.carrid = spfli.carrid {       key spfli.carrid,       key _scarr.carrname,       key spfli.connid,       spfli.cityfrom,       spfli.cityto
}
@AbapCatalog.sqlViewName: 'z20160316'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'test odata publish '
@OData.publish: true
@ObjectModel: {   type: #CONSUMPTION,   compositionRoot,   semanticKey: ['Actor'],   createEnabled,    deleteEnabled,   updateEnabled
}
define view Zjerrytest20160316 as select from Zjerrytest20160309 {    @UI.lineItem : [{position:10}]    key Zjerrytest20160309.carrid as Jerryid,    @UI.lineItem : [{position:20}]    key Zjerrytest20160309.carrname as name,    @UI.lineItem : [{position:30}]    key Zjerrytest20160309.cityfrom as startLocation,    @UI.lineItem : [{position:40}]    key Zjerrytest20160309.cityto as target,    @UI.lineItem : [{position:50}]    key Zjerrytest20160309.connid
}

Once activated, there is a hint in studio to tell you the automatically published OData service name, and then tcode for service registration.

clipboard1.png

2. Use tcode /IWFND/MAINT_SERVICE to finish OData service registration

 

clipboard2.png

Specify System Alias = LOCAL and search using the CDS name you get from step1, select the search result and click "Add Selected Services":

clipboard3.png

Once added, click "SAP Gateway Client" to test whether the OData service works:

clipboard4.png

Make sure the metadata request returns 200 success code.

clipboard5.png

3. Create UI5 application using Wizard in WebIDE


Open WebIDE, File->New->Project from Template, choose Smart Template Application and next:

clipboard6.png

clipboard7.png

Select the destination for your backend where CDS view is created, and locate your OData service created just now:

clipboard8.png

The annotation file is automatically identified, just click Next button:

clipboard11.png

Choose OData Collection from drop down list and click Finish button:

clipboard12.png

Once created, the project looks like below. Choose Component.js and click Run button in WebIDE Toolbar:

clipboard13.png

From rendered application you could see the table is now filled with data fetched from CDS view:

clipboard14.png



Viewing all articles
Browse latest Browse all 789

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>