Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos
1,745

Let’s use GenAI capabilities of Joule to create a CAP Service with SAP Build Code.

In this blog you will learn to create:

  • Data Model
  • Sample Data
  • Application Logic.

Perquisites:

Go to Lobby of SAP Build, the central entry point for all SAP Build products.

Build an application

From the Build lobby, create a new project by clicking “Create” button.

Select Build an Application followed by SAP Build Code and Full-Stack Application.

Enter you Project Name and Select your Dev Space. Click on Create.

BuildanApplication.pngprojectCreation.png

Create Data Entities with Joule

Click on the project in the Lobby. From SAP Business Application Studio, Click on AI assistant Joule and click on Open Guide. Click on the drag and drop – Data Model and Service Creation and Click on Open Joule.

JouleScreen1.pngimage.png

Let’s create three entities- Customers, Purchases and Redemptions using Joule. Enter below prompt to generate entities and Accept the code.

JouleAccept.png

Design a customer loyalty program application. Define 3 data entities: Customers, Purchases and Redemptions. Each customer must have the following fields: name, email, 7-digit customer number, total purchase value, total reward points, total redeemed reward points. All fields for each customer should be integer except name and email that will be stored as string. Purchases should include the following fields: purchase value, reward points and selected product. All fields in Purchases must be integer except selected product. Redemptions must have 1 field in integer: redeemed amount. Each purchase and redemption will be associated to a customer.

Enhance Sample Data with Joule

From Storyboard select Open Editor and Sample Data.

sampledatefromjoule.png

Select Customers data entity and Click on Enhance button. Now let’s enhance customers sample data by entering below prompt:

Enhance my sample data with meaningful data. Any phone numbers must be 10 digits. All customer numbers must be 7 digits and one customer must use the customer number 1200547. No fields may be empty. Total purchase value must be smaller than 10000 und unround. Total reward points and total redeemed reward points both must be unround and different and always sum to one-tenth of the total purchase value for each customer.

you can observe that Customer name, email address and Purchases are created with new sample data. 

Create Backend Logic with Joule

Now let's add backend logic to our app, when Customer makes a purchase our logic will automatically add bonus points and later redeem these points.

From Storyboard, Select Services -> Click on Purchases entity and Select Graphical Modeler and Add Logic. Leave the default values and Click on Add Logic from Add Application Logic.

GraphicalModlelor.png

AddLogic.png

From Purchase - logic -> Standard Event - select Create checkbox and Open Code Editor will be enabled and Select Create Application Logic.

standardEvent_create.png

Let's use below prompt to add our backend application logic and click on Generate button and Accept the code.

Reward points of each purchase will be the one tenth of the purchase value. Each purchase value will be added to the total purchase value of the related customer. Each reward points will be added to the total reward points of the related customer.

JouleApplicationLogic.png

Add External Data Resource 

Go to Storyboard and Click on Service Center, here we will S4/HANA for product related data. From SAP System select BTP destination s4-Product and click on Add to CAP.

Add a CAP project.png

externalresource.png

Now, go to services.cds tab and click on Add Entity and drop the entity. Select s4_product.A_ProductBasicText from the Search - "Select a base type for new projection".

addEntity.png

Create Fiori Elements UIs

Now let's add Fiori UI Elements to display the data.

From Storyboard, Click on "+" from UI Application.

UI Application.png

Add Display name and Description and click Next.

UIName.png

Select Template-Based Responsive Application  as UI Application type and List Report Page for Template.

Template.png

listreport.png

Select Purchases as the Main entity to complete the UI Element creation.

MainEntity.png

Deployment

Let deploy the application to CloudFoundry. Go to Task Explorer and click on the play icon next to Enable Discovery and Deploy option. A new page will be ptompted to sign to CloudFoundry to generate your SSO passcode, copy the authentication code and paste to sign in followed by selecting Organization and Space and Click Apply.

deploy.png

Deploy.png

Upon successful deployment, in the terminal window you will find Project OverviewURL. Open the url in a browser to explore the UIs in the launchpad that were created.

UIScreen.png

Happy low coding\no code with Joule!