0% found this document useful (0 votes)
57 views

Developing_Applications_with_the_SAP®_Cloud_Application_Programming

This E-Bite provides a comprehensive guide on using the SAP Cloud Application Programming Model to develop business applications on the SAP Cloud Platform. It covers the setup, technical foundations, and development processes for both Node.js and Java applications, along with best practices for extending SAP S/4HANA systems. The document aims to simplify development by focusing on business needs while managing technical complexities.

Uploaded by

Dambu R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Developing_Applications_with_the_SAP®_Cloud_Application_Programming

This E-Bite provides a comprehensive guide on using the SAP Cloud Application Programming Model to develop business applications on the SAP Cloud Platform. It covers the setup, technical foundations, and development processes for both Node.js and Java applications, along with best practices for extending SAP S/4HANA systems. The document aims to simplify development by focusing on business needs while managing technical complexities.

Uploaded by

Dambu R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

& PRESS

SAP PRESS E-Bites

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 Creating a Full-Stack Node.js Business Application Using


the SAP Cloud Application Programming Model . . . . . . . . . . . . . . . . . . 45
4.1 Setting Up t he Local Envi ronment for Development . . . . . . . . . 45
4.2 Creating a Project Using CDS Comma nds . . . . . . . . . . . . . . . . . . . 47

4
What You'll Learn

4.3 Creating a Data Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50


4.4 Creating a Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
4.5 Implementing Custom Logic Using Node.js Functions . . . . . . . 54
4.6 Instal ling SQLite............................................ 55
4.7 Running and Testing the Service Locally................... . . 56
4.8 Deploying the Application to SAP Cloud Platform . . . . . . . . . . . 62
S Creating a Full-Stack Java Business Application Using the
SAP Cloud Application Programming Model . . . . . . . . . . . . . . . . . . . . . . 68
5.1 Accessing and Configu ring SAP Business Application
Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
5.2 Creating a Project Using a CDS Archetype . . . . . . . . . . . . . . . . . . . 74
5.3 Creating a Data Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
5.4 Creating a Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
5.5 Running and Testing the Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
5.6 Deploying the Application to SAP Cloud Platform . . . . . . . . . . . 87
6 Extending SAP S/4HANA Using the SAP Cloud Application
Programming Model and SAP Cloud SOK . . . . . . . . . . . . . . . . . . . . . . . . . 90
6.1 Example Use Case. . ......... . .............................. 91
6.2 Creating a Basic Application Using the SAP Cloud
Application Programming Model . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
6.3 Implementing the SAP S/4HANA Mock Server . . . . . . . . . . . . . . . 96
6.4 Enhancing Applications with SAP S/4HANA Data....... . .... 103
6.5 Building a User Interface Using SAP Fiori Elements . . . . . . . . . . 110
7 Best Practices and Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
7.1 Best Practices for CDS Data Models . . . . . . . . . . . . . . . . . . . . . . . . . 113
7.2 Key Points of Focus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
8 What's Next? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119

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.

1.1 SAP Cloud Platform, Cloud Foundry Environment


SAP Cloud Platform is a well-known platform-as-a-service (PaaS) offering
from SAP. If you're planning to build innovative solutions to leverage new
technologies like blockchain, machine learning, artificial intelligence (AI),
Internet of Things (IoT), analytics, etc., SAP Cloud Platform is one of the best
development platforms available. SAP Cloud Platform also provides many
out-of-the-box integration options and built-in software development kits
(SDKs) to integrate with SAP S/4HANA, SAP SuccessFactors, SAP Ariba, and
other SAP and non-SAP systems . Thus, SAP Cloud Platform is the best plat-
form for building applications that connect to these systems.

SAP Cloud Platform comes in three flavors or environments - Neo, Cloud


Foundry, and ABAP. These environments provide flexibility when choosing
the right technologies, runtime, and services for your needs.

6
1 Introduction

Although choosing the right environment depends on many factors, the


Cloud Foundry environment should be your de facto first choice. Cloud
Foundry is an open-source PaaS that enables you to use multiple program-
ming languages, such as Java, Node.js, Python, or Go, and even offers bring-
your-own-language (BYOL) options. You can also choose your own infra-
structure-as-a-service (IaaS) provider, for instance, Microsoft Azure, Ama-
zon Web Services (AWS), Alibaba Cloud, or Google Cloud Platform.

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.

1.2 SAP Cloud Application Programming Model

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.

What Is the SAP Cloud Application Programming Model?


The SAP Cloud Application Programming Model is not a specific product
but rather is a framework - a set of tools, languages, and libraries. SAP's own
technologies, like the SAP Web IDE, core data services (CDS), and SAP HANA,
can be used alongside open-source technologies like Node.js or Java. You'll
be able to efficiently and rapidly build enterprise services and business
applications in a full-stack development approach. Using the SAP Cloud
Application Programming Model is considered a golden path of best prac-
tices provided by SAP, allowing you to focus on your business domain while

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.

SAP Web IDE


SAP
Web IDE
SAP Fiori + Other
l
+
Loca l
CDS Service SDKs
l Plat f orm
Services

Loca l SAP HANA + Other


l
Infrastructure

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.

How the SAP Cloud Application Programming Model


Simplifies Development
To see how the SAP Cloud Application Programming model simplifies
development, Jet's first understand the common pain points when develop-
ing an enterprise application for the cloud. Let's assume we're building an e-
commerce application to be hosted in SAP Cloud Platform or another PaaS.
Apart from focusing on the business requirements for this application,
you'll also need to put effort into addressing many non-functional require-
ments, for example, the following:
• The application should explicitly declare and isolate dependencies. For
example, let's say you've built the application with an SQLite database. If
you deploy the application in SAP Cloud Platform with an SAP HANA
database, no code changes will be required. The database configuration
and declaration are isolated from the main code of the appication.
• Building, testing, deploying, and running the application should operate
seamlessly, \<\Tith minimal manual effort required for these activities.
• The application should have proper logging implemented.
• The application should be properly modularized to support a microser-
vice architecture.
• The application should support a RESTful architecture and provide ser-
vices in OData format.
• The application should support multi-tenancy.

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.

Two Flavors of the SAP Cloud Application Programming Model


The SAP Cloud Application Programming Model framework is available in
t\<VO flavors - Node.js and Java. Both flavors are in sync in terms of features
and characteristics. However, their internal technical implementation is
different.
The implementation of a business application is similar for both Node.js
and Java flavors. The major difference is in writing custom logic. The pro-
gramming model provides the option to write custom logic. For Node.js,
you'll need to write in JavaScript, while for Java, you'll write using Java
classes.
In this E-Bite, we'll discuss both flavors of the SAP Cloud Application Pro-
gramming Model. In Section 4, we'll cover how you can build a full-stack
Node.js business application using the SAP Cloud Application Program-
ming Model. In Section 5, you'll learn how to build a full -stack Java business
application using the SAP Cloud Application Programming Model.

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.

2.1 Accessing the SAP Cloud Platform Cloud Foundry


Trial Account
SAP offers a trial account for SAP Cloud Platform for all three environments
free of charge. Anyone can register and get started.
Follow these steps to get your own trial account:
1. Go to https://www.sap.com and click on the user icon, as shown in Figure
2.1.

~ SAP Software Solutions I Bvs r X + - 0 x

hi\ ID -

Figure 2.1 Logon Button

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

~ SAP Software Solutions I Busi,.. X + - = x

© a https:/twww.sap.co1n/index.html# ... e '(:r Ill\ ID -

Tell us about yourself Log On

E-mail address *

First name* Last name *


J l
I Country/Region
Company •
~-----~
I United States ~ 1 Log On

r Phone• +) XXX-XXX-X... I [ Relationship t... "'-' ]


Forgot password?

I Create password • iI Confirm password *

Figure 2.2 Registration Form

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

You might also like