Developing_Applications_with_the_SAP®_Cloud_Application_Programming
Developing_Applications_with_the_SAP®_Cloud_Application_Programming
Raja Gupta
~ Rheinwerk
Publishing
Raja Gupta
Developing Applications
with the SAP®Cloud
Application Programming
Model
~ Rheinwerk
t"
What You'll Learn
In this E-Bite, you'll learn how to use the SAP Cloud Application Program-
m ing Model to develop business applications for SAP Cloud Platform. You'll
start with the basics: learn to set up your system and understand the tech-
nical foundations that underpin the programming model. Then, you'll dive
into the steps to develop both Node.js and Java business applications,
before learning how to extend your SAP S/4HANA system using both the
programming model and SAP Cloud SOK. To help guide application devel-
opment, you'll finish with some key best practices.
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.1 SAP Cloud Platform, Cloud Foundry Environment . . .... .. .. . 6
1.2 SAP Cloud Applicat ion Programm i ng Model ..... . ... .. .. .. . . 7
2 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.1 Accessing the SAP Cloud Platform Cloud Foundry
Tria l Account.. ... .. .. . . . ... ... .. .. ... ... ... .. .... .. .. ... ... 11
2.2 Accessing and Configuring the SAP Web IDE Trial Version . . . 15
2.3 Creating a Hel lo World OData Service....................... 16
3 Technical Foundation of the SAP Cloud Application
Programming Model . . ...... ........... ...... .......... ...... . 23
3.1 Node Package Manager and NPM Registry . ......... .. ... . . . 23
3.2 Core Data Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.3 Core Schema Not ation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.4 Definition Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.5 Query Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.6 SAP CDS Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.7 Associations and Compositions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
4
What You'll Learn
s
1 Introduction
Let's begin our development journey by learning about a remarkably inter-
esting and powerful technology that has revolutionized the way we
develop, test, run, and deploy applications in SAP Cloud Platform-the SAP
Cloud Application Programming Model.
In this E-Bite, you'll learn how the SAP Cloud Application Programming
Model has changed the development paradigm for SAP Cloud Platform.
We'll start with a basic service implementation and end by building an end-
to-end enterprise application using the programming model.
In this first section, \.ve'll lay the foundations and fundamentals to help you
understand the SAP Cloud Application Programming Model. We'll provide
an overview of the SAP Cloud Platform, Cloud Foundry environment and
the SAP Cloud Application Programming Model. You'll also learn the basic
concepts behind how the SAP Cloud Application Programming Model
works and learn why and when it should be used.
6
1 Introduction
Further Resources
SAP is a found ing platinum-level member of the Cloud Foundry Foundation,
which governs the development of Cloud Foundry software and the ecosystem.
Currently, SAP Cloud Platform, Cloud Foundry environment is available in many
SAP data centers and regions. To learn more, go to http://cloudplatform.
sap.com.
In this section, we'll introduce you to the SAP Cloud Application Program-
ming Model. You'll learn how this model can help you focus on your busi-
ness domain and help you develop full -stack, end-to-end applications. In
this section, we'll also explore the languages and tools the SAP Cloud Appli-
cation Programming Model provides.
7
1 Introduction
relieving you from the tedious tasks common to most cloud-based applica-
tions.
Figure 1.1 shows the major building blocks of the SAP Cloud Application Pro-
gramming Model.
Figure 1.1 Major Building Blocks of the SAP Cloud Appl ication Programming Model
Let's unpack these building blocks. The SAP Cloud Application Program-
ming Model is based on core data services (CDS). CDS is a definition lan-
guage for developing data models and service definitions to create database
artifacts in a database- and language-agnostic way. The CDS compiler con-
verts your declarative statements in CDS into the runtime artifacts needed
for your target environment. For example, a CDS view for database artifacts
takes an input from a configuration file to identify the database (for exam-
ple, SQLite or SAP HANA) and automatically converts CDS views to database
tables and so on.
Further, CDS enables you to easily declare services on top of your database
model by writing just a few Jines in a declarative way. Based on the configu-
ration provided, the SAP Cloud Application Programming Model automati-
cally converts these statements into a Java-based or Node.js-based OData
service. In Section 3.2, you'll learn more about using CDS.
8
1 Introduction
The SAP Cloud Application Programming Model works quite smoothly with
the SAP Web IDE, SAP Fiori, and SAP HANA. Dedicated features are included
fo r extending SAP S/4HANA and for integration with SAP Cloud SDK. In Sec-
tion 6, you'll learn more about SAP S/4HANA extensibility and the pro-
gramming model's integration with SAP Cloud SDK.
Note
These technologies involve no lock-in. The SAP Cloud Application Programming
Model can be used without the SAP Web IDE, SAP Fiori, or SAP HANA.
9
1 Introduction
You'll likely need to consider many other points when developing your
cloud application. The main goal of the SAP Cloud Application Program-
ming Model is to relieve you of several non-functional, often time-consum-
ing, tasks. By using declarative approaches like CDS and the tools and ser-
vices recommended by the programming model, you can focus on the
business problem to solve and let the framework take care of technical dis-
cipline and various tedious technical tasks, thus significantly reducing
development time and time-to-market. Moreover, you can be confident
that your application follows coding guidelines and supports multi-ten-
ancy, modularization, logging, extensibility, etc. In further sections, we'll
elaborate more on how the SAP Cloud Application Programming Model
helps you to achieve all these benefits.
10
2 Getting Started
2 Getting Started
In the previous section, we introduced you to the SAP Cloud Application
Programming Model. Now, let's get hands-on and build a Hello World
OData service using it. SAP provides trial versions of both SAP Cloud Plat-
form and the SAP Web IDE. In our example in this section, we'll use the SAP
Web IDE to build our Hello World application and use SAP Cloud Platform,
Cloud Foundry environment to deploy and run it.
hi\ ID -
2. Figure 2.2 shows the registration and logon form. If you registered earlier,
log on using your existing credentials. For first-time users, fill out the
form and click on the Submit button.
11
2 Getting Started
E-mail address *
3. After submitting the form, a message will be sent to your email ID with an
activation link. Open the email and click on that link to activate your trial
account.
4. Once the account is activated, go to the SAP Cloud Platform trial page
(https://account.hanatrial.ondemand.com) and log on. Accept the terms
and conditions and verify your phone number. You'll then be prompted
to select a region. In our example, we selected Europe (Frankfurt) as our
region, as shown in Figure 2.3.
5. Now, a global account, subaccount, organization, and space will be cre-
ated for you on SAP Cloud Platform, as shown in Figure 2.4. Click on Con-
tinue.
12