You are on page 1of 67

Core Data Services for ABAP Renzo

Colle
Visit to download the full and correct content document:
https://ebookmass.com/product/core-data-services-for-abap-renzo-colle/
Renzo Colle, Ralf Dentzer, Jan Hrastnik

Core Data Services for ABAP®

3rd edition 2024, updated and revised


Imprint

This e-book is a publication many contributed to,


specifically:
Editor Megan Fuerst
Acquisitions Editor Hareem Shafi
Copyeditor Julie McNamee
Cover Design Bastian Illerhaus
Photo Credit Unsplash: li-zhang-K-DwbsTXliY
Production E-Book Kelly O’Callaghan
Typesetting E-Book Satz-Pro (Germany)
We hope that you liked this e-book. Please share your
feedback with us and read the Service Pages to find out how
to contact us.

Library of Congress Cataloging-in-Publication Control


Number:2023945756

ISBN 978-1-4932-2376-3 (print)


ISBN 978-1-4932-2377-0 (e-book)
ISBN 978-1-4932-2378-7 (print and e-book)

© 2024 by Rheinwerk Publishing Inc., Boston (MA)


3rd edition 2024, updated and revised
Notes on Usage

This e-book is protected by copyright. By purchasing this


e-book, you have agreed to accept and adhere to the
copyrights. You are entitled to use this e-book for personal
purposes. You may print and copy it, too, but also only for
personal use. Sharing an electronic or printed copy with
others, however, is not permitted, neither as a whole nor in
parts. Of course, making them available on the internet or in
a company network is illegal as well.

For detailed and legally binding usage conditions, please


refer to the section Legal Notes.

This e-book copy contains a digital watermark, a


signature that indicates which person may use this copy:
Notes on the Screen
Presentation

You are reading this e-book in a file format (EPUB or Mobi)


that makes the book content adaptable to the display
options of your reading device and to your personal needs.
That’s a great thing; but unfortunately not every device
displays the content in the same way and the rendering of
features such as pictures and tables or hyphenation can
lead to difficulties. This e-book was optimized for the
presentation on as many common reading devices as
possible.

If you want to zoom in on a figure (especially in iBooks on


the iPad), tap the respective figure once. By tapping once
again, you return to the previous screen. You can find more
recommendations on the customization of the screen layout
on the Service Pages.
Table of Contents

Notes on Usage
Table of Contents

Preface

1 Modeling Your First CDS


Views
1.1 Define the Data Model of the
Application
1.2 Implement the Data Model of the
Application
1.2.1 Create Database Tables
1.2.2 Create a CDS View
1.2.3 Edit a CDS View
1.2.4 Create a Hierarchy of CDS Views
1.3 Summary
2 Fundamentals of CDS Data
Modeling
2.1 Overview of CDS Models
2.2 Overview of CDS View Syntax
2.3 Key Fields
2.4 Cast Operations
2.5 Typed Literals
2.6 Simple Types
2.7 Case Statements
2.8 Session Variables
2.9 Client Handling
2.10 Select Distinct Statements
2.11 Union Views
2.11.1 Union Definitions
2.11.2 Union and Union All Logic
2.12 Intersect and Except Statements
2.13 Joins
2.14 SQL Aggregation Functions
2.15 Projection Fields
2.16 Parameters
2.17 Reference Fields
2.18 Conversion Functions for Currencies
and Quantity Units
2.19 Provider Contracts
2.20 Entity Buffer Definitions
2.21 Summary

3 Associations
3.1 Define Associations
3.2 Expose Associations
3.3 Model Compositional Relations
3.4 Model M:N Relations
3.5 Project Associations
3.6 Use Associations in CDS Views
3.6.1 Define Path Expressions
3.6.2 Implicit Joins
3.6.3 Cardinality Changes Resulting from Path
Expressions
3.6.4 Restrictions for Defining Path Expressions
3.7 Use Associations in ABAP Code
3.8 Summary

4 Annotations
4.1 Annotation Definitions
4.1.1 Syntax Overview
4.1.2 Annotation Names
4.1.3 Annotation Types and Values
4.1.4 Enumeration Values
4.1.5 Annotation Default Values
4.1.6 Annotation Scopes
4.2 Effects of Annotations
4.3 Propagation Logic for Annotations
4.3.1 Propagation Logic within Simple Type
Hierarchies
4.3.2 Propagation Logic of Element Annotations
4.3.3 Consistency Aspects
4.4 Metadata Extensions
4.5 Active Annotations
4.6 Summary

5 Access Controls
5.1 Fundamentals of Access Controls
5.2 Mode of Action of Access Controls
5.3 Implementation Patterns for Access
Controls
5.3.1 Implement Access Controls with Path
Expressions
5.3.2 Inherit Implementation of Access Controls
5.3.3 Implement Access Controls without Using
Authorization Objects
5.3.4 Implement Access Controls for Analytical
Queries
5.3.5 Implement Access Controls for Transactional
Applications
5.3.6 Implement Access Controls on the Field
Level
5.3.7 Change Access Controls of SAP-Delivered
CDS Models
5.3.8 Block Standard Data Selections from CDS
Models
5.3.9 Decouple Access Controls from User Input
5.3.10 Map CDS Fields onto Fields of Authorization
Objects Using Indirection
5.4 Test Access Controls
5.5 Summary

6 Business Services
6.1 Projection Views
6.2 Service Definitions
6.3 Service Bindings
6.3.1 OData UI Services
6.3.2 OData Web API Services
6.3.3 InA UI Services
6.3.4 SQL Web API Services
6.4 Testing Business Services
6.4.1 Use OData Service URLs
6.4.2 Use UI Previews
6.5 Summary

7 Native SAP HANA


Functions in CDS
7.1 Implementation of a CDS Table
Function
7.2 Application Scenarios
7.3 Improve Performance and Avoid
Errors
7.4 Summary

8 Modeling Application Data


8.1 Application Architecture in SAP
S/4HANA
8.2 Field Labels
8.2.1 Determination of a Field Label
8.2.2 Length of a Field Label
8.3 Field Semantics
8.3.1 Quantities and Amounts
8.3.2 Aggregation Behavior
8.3.3 System Times
8.3.4 Text and Languages
8.3.5 Information for the Fiscal Year
8.4 Foreign Key Relations
8.5 Text Relations
8.6 Composition Relations
8.7 Time-Dependent Data
8.8 Summary

9 The Virtual Data Model of


SAP S/4HANA
9.1 Why a Virtual Data Model?
9.2 SAP Object Types and Object Node
Types
9.3 Categories of CDS Entities in the
Virtual Data Model
9.3.1 Basic Interface Views
9.3.2 Composite Interface Views
9.3.3 Consumption Views
9.3.4 Other Types of VDMs
9.4 Naming in the Virtual Data Model
9.5 Basic Interface View for the Sales
Order
9.5.1 View Annotations
9.5.2 Structure of the Sales Order View
9.5.3 Specialization
9.5.4 Element Annotations
9.6 Tips for Finding Virtual Data Model
Views
9.6.1 SAP Business Accelerator Hub and View
Browser App
9.6.2 Search in ABAP Development Tools
9.6.3 Search Views with Specific Annotations
9.6.4 ABAP Where-Used List
9.7 Summary

10 Modeling Analytical
Applications
10.1 Analytics in SAP S/4HANA
10.2 Analytical Views
10.2.1 First Analytical Cube View
10.2.2 Test Environment for Analytical Views
10.2.3 Analytical Cube Views
10.2.4 Analytical Dimension Views
10.2.5 Analytical Model in the Test Environment
10.2.6 Consistency of the Analytical Model
10.3 Analytical Queries
10.3.1 Definition of an Analytical Query
10.3.2 Initial Layout of a Query
10.3.3 Filter, Select Options, Parameters
10.3.4 Calculation of Measures
10.3.5 Restricted Measures
10.3.6 Exception Aggregation
10.3.7 Currencies and Conversion
10.3.8 Analytical Query Selecting from Dimension
Views
10.4 Analytical Infrastructure
10.5 Summary

11 Modeling Transactional
Applications
11.1 Transactional Applications
11.2 Transactional Infrastructure in SAP
S/4HANA
11.3 Transactional Object Models
11.3.1 Object Models
11.3.2 Access Controls
11.4 Behavior Definitions
11.4.1 Create Behavior Definition
11.4.2 Behavior Pool and Handler Implementation
11.4.3 Consumption via EML
11.4.4 Static Field Control
11.4.5 Numbering
11.4.6 Exclusive Locks
11.4.7 Authorization Checks
11.4.8 Authorization Contexts and Privileged
Access
11.4.9 Associations
11.4.10 Actions
11.4.11 Functions
11.4.12 Data Determinations and Validations
11.4.13 Dynamic Feature Control
11.4.14 Mappings
11.4.15 Calculated Fields
11.4.16 Prechecks
11.4.17 HTTP ETags
11.4.18 Draft
11.4.19 Side Effects
11.4.20 Change Documents
11.4.21 Events
11.5 Transactional Projection Object
Models
11.5.1 Projection Object Models
11.5.2 Access Control
11.5.3 Denormalized Fields
11.5.4 Localized Elements
11.5.5 Calculated Fields/Virtual Elements
11.6 Define Interface Behavior Definition
11.6.1 Create Interface Behavior Definition
11.6.2 Static Feature Control
11.6.3 Operations
11.6.4 Draft, ETag, and Side Effects
11.6.5 Events
11.6.6 Consumption via EML
11.6.7 Release for Consumption
11.7 Define Projection Behavior
Definition
11.7.1 Create Projection Behavior Definition
11.7.2 Actions and Functions
11.7.3 Prechecks
11.7.4 Augmentation
11.7.5 Side Effects
11.7.6 Events
11.7.7 Consumption via EML
11.8 Runtime Orchestration
11.8.1 Interaction Phase Operation Flow
11.8.2 Save Phase Operation Flow
11.8.3 Runtime Component Overview
11.8.4 Consumption via OData
11.9 SAP Fiori and OData Consumption
11.9.1 OData Service for Web API Consumption
11.9.2 OData Service for UI Consumption
11.10 SAP Event Mesh and Local Event
Handlers
11.10.1 Local Event Handler
11.10.2 SAP Event Mesh
11.11 Summary

12 Hierarchies in CDS
12.1 Hierarchy Categories and Basics
12.2 Annotation-Based Parent-Child
Hierarchies
12.2.1 Example of a Parent-Child Hierarchy
12.2.2 Determination of a Hierarchy
12.2.3 Test a Hierarchy
12.3 CDS Hierarchies
12.3.1 Data for an Example of a Reporting Line
Hierarchy
12.3.2 Define the CDS Hierarchy
12.3.3 Hierarchy Attributes
12.3.4 Visualization of a Hierarchy
12.3.5 Hierarchy with an Orphaned Node
12.3.6 Hierarchy with Multiple Parent Nodes
12.3.7 Hierarchy with Cycles
12.3.8 Further Options for Defining Hierarchies
12.3.9 CDS Hierarchies in ABAP SQL
12.3.10 OData Service for CDS Hierarchies
12.4 Summary

13 CDS-Based Search
Functionality
13.1 Modeling Value Helps
13.1.1 Modeling Elementary Value Helps
13.1.2 Integrating Value Help CDS Views
13.1.3 Collective Value Helps
13.1.4 Exposing Value Helps in OData Services
13.1.5 Using Value Helps
13.2 Free-Text Search Functionality in
OData Services
13.3 Enterprise Search Functionality
13.3.1 Define Enterprise Search Models
13.3.2 Adapt Enterprise Search Models from SAP
13.4 Summary

14 Lifecycle and Stability


14.1 Stability Contracts
14.2 Lifecycle of Development Objects
14.3 Deprecation of Development
Objects
14.4 Use of CDS Models and Supported
Capabilities
14.5 Summary

15 Extensions of CDS Views


and Other Entities
15.1 Solution Variants and ABAP
Language Versions
15.2 Stable CDS Extensions
15.2.1 Stable Extensions of CDS Views
15.2.2 Example: Stable Extension Points
15.2.3 Example: Extension with Custom Fields
15.2.4 CDS Extensions in Product Variants
15.3 Extensions of Transactional Models
15.3.1 Add Fields to an Entity
15.3.2 Add Application Logic
15.3.3 Extend Action and Function Parameters and
Results
15.3.4 Extend Behavior
15.3.5 Add Composition Child Entity
15.4 Summary
16 Automated Testing
16.1 Test Logic of Data Selections
16.1.1 Fundamentals of the Test Double
Framework
16.1.2 Test Sample Overview
16.1.3 Test Implementations of CDS Views
16.1.4 Test ABAP Logic with SQL Accesses to CDS
Views
16.1.5 Test Code Generation Functions
16.2 Test Logic of Transactional
Applications
16.2.1 Test Behavior Handler
16.2.2 Test Events and Event Payloads
16.2.3 Test Event Handler
16.2.4 Tests via EML Interface
16.3 Summary

17 Troubleshooting
17.1 Performance Aspects
17.1.1 Static View Complexity
17.1.2 Calculated Fields
17.1.3 CDS Models in ABAP Code
17.1.4 Performance Tests
17.1.5 Analysis Tools
17.2 Pitfalls
17.2.1 Null Values
17.2.2 Data Types
17.2.3 Decimal Shift Logic for Amounts
17.3 Troubleshoot Implementations of
CDS Models
17.3.1 Syntax Checks
17.3.2 Consistency Checks of Frameworks
17.4 Troubleshoot Activation Issues
17.4.1 Online Activation
17.4.2 Mass Checks and Repairs
17.5 Examine ABAP RESTful Application
Programming Model Applications
17.6 Summary

A CDS Annotation Reference


B Migration to the ABAP
RESTful Application
Programming Model
C The Authors
Index
Service Pages
Legal Notes
Preface

ABAP's core data services (CDS) technology forms the basis


of the ABAP platform’s modern programming model and is
therefore an important part of SAP’s current technology
strategy. Among other things, as an extension of SQL, this
technology allows users to leverage the features of the SAP
HANA database. ABAP CDS and its annotations can be used
to enhance the model with information that can be optimally
integrated into analytical applications and web interfaces
for cloud applications or user interfaces (UIs) via OData as a
model-based protocol. CDS also serves as a foundation for
the new ABAP RESTful application programming model.
Therefore, CDS and the programming model based on it
form the basis of SAP Fiori applications, which embody the
new standards for the modern user experience (UX) of SAP
applications.

SAP S/4HANA, the next generation business suite, is also


based on CDS in the form of the virtual data model (VDM).
In this book, we describe the use of CDS from the
perspective of SAP S/4HANA and its overall architecture.
Therefore, we not only describe the technical aspects of
CDS but also the motivation behind the applied approaches.
We use examples from application development and
supplement them with recommendations for the successful
implementation of your own projects, which go far beyond
discussing purely functional aspects.
We cover the most important aspects and functions of ABAP
CDS, which are used in concrete use cases in the SAP
S/4HANA environment (up to date for release SAP S/4HANA
2023). For a technical description of all CDS functions, you
can refer to the SAP standard documentation. This book also
provides the relevant basis (in the respective version of the
ABAP platform) for the applicable syntax and scope of
functions supported.
The CDS-based programming model is relatively new and is
therefore still subject to changes and significant further
enhancements and features. Especially in the field of
transactional applications and the ABAP RESTful application
programming model, the development of the programming
model is still evolving. Particularly in this area, we expect
the implementation to become more efficient and the range
of features and functions to be extended significantly in the
future. You should always consider this evolution when
implementing your own projects.

With this book, we aim to give you an overview of the CDS-


based programming model and possible use cases. The
knowledge we provide will enable you to define CDS models
based on the basic rules and recommendations that the SAP
standard development follows, to use them in a reasonable
way in your applications, and to enhance the SAP S/4HANA
standard applications. By the time you’ve finished the book,
you should have developed comprehensive knowledge of
the underlying concepts, learned how SAP uses these
concepts in SAP S/4HANA, and gained a practical
understanding of how these concepts can be applied when
building your own applications.
The book is primarily aimed at ABAP developers who want
to develop or enhance ABAP-based applications for use in
OData application programming interfaces (APIs), in
analytics or in SAP Fiori UIs. Basic knowledge of ABAP
development and SQL is required. However, if you’re a
newcomer to the ABAP and SQL world, the book will help
you create your first applications and services with the help
of CDS models. You can very quickly develop appealing
analytical applications and interfaces, as well as purely
reading applications, without writing ABAP code yourself.

Still, to enter the transactional world with the ABAP RESTful


application programming model, using ABAP as a
programming language for business logic is a prerequisite;
in addition, a lot of model-driven infrastructure support is
available. We’ll only deal with these topics on a very basic
level in the context of this book. We also won’t go into
detailed discussions regarding the SAP Fiori UI and will only
use simple examples to show how you can easily create an
OData service and an SAP Fiori UI based on your CDS
models. However, you can also deepen your knowledge by
studying the relevant literature or SAP documentation in
parallel.

In the third edition of this book, the newest developments


and features of the ABAP platform are reflected and
included. With this, the structuring of the book was also
reworked. The chapter on transactional applications
(Chapter 11) has been enhanced significantly to cover the
newest features of the ABAP RESTful application
programming model (e.g., business events) and much more.
We have provided a completely new chapter for the
software lifecycle and stability of CDS and ABAP RESTful
application programming model artifacts; based on this,
we’ve reworked the complete chapter on extensions of
applications. The other chapters have all been updated
accordingly, especially the chapter for test automation and
troubleshooting, which has been enhanced to also cover
transactional applications. Further, all CDS-based examples
are now based on CDS view entities (CDS V2), the new
generation of CDS views discussed and explained in the
previous editions.

The descriptions and examples refer to the current state of


the art (up to date for release SAP S/4HANA 2023, but also
the related SAP S/4HANA Cloud, public edition). Most of the
concepts and basics also work in general for ABAP cloud-
based applications independent of SAP S/4HANA. We’ve
created them to the best of our knowledge but can’t
completely exclude errors. If in doubt, consult the official
SAP documentation.

We use ABAP in Eclipse (ABAP Development Tools [ADT]) as


our development environment. English is the default
development language for development objects or
comments in source code. All texts relevant for the end user
can be translated, of course, and thus any application can
also be localized.

Structure of the Book


This section provides a rough overview of the chapter
structure and the content of the individual chapters. The
first four chapters should be read sequentially as a
foundation because all other concepts and chapters are
based on them. You can then jump back and forth between
the individual chapters according to your needs and
interests.

Chapter 1 shows you how to define your first simple CDS


views quickly. In addition to the essential parts of a CDS
view, we’ll also briefly introduce the most important
development tools.

Chapter 2 provides the fundamentals and technical basics


of CDS data models. For this purpose, we present the
relevant CDS artifacts from the developer’s point of view,
including their components, using modeling examples.

In Chapter 3, we explain the basics, definition, and usage


of associations in CDS models via ABAP implementation and
special association types, such as compositions.

In Chapter 4, we explain the basics of CDS annotations and


their propagation logic using examples. CDS annotations
enrich the data models with semantic information. This
information is interpreted by CDS consumers and controls,
and then influence, for example, the presentation on the UI
or the aggregation behavior of an analytical application.

In Chapter 5, we deal with the authorizations for accessing


the data exposed by the CDS models. Access controls using
the CDS data control language (DCL) enable you to restrict
the selection results of CDS views according to the user’s
authorizations via classic ABAP authorization objects. We
explain the basics of CDS access controls and demonstrate
their concrete use.

In Chapter 6, you get an insight into the modeling and


definition of business services based on a special view type,
projection views, service definitions, and service bindings
focusing on OData protocol–based bindings. Business
services allow you to expose your CDS models to external
consumers.

In Chapter 7, we examine CDS table functions, which


enable you to integrate native SAP HANA functions into the
CDS view stack using SQLScript. We illustrate the modeling
of CDS table functions and highlight their special features.

Chapter 8 provides an overview of the application


architecture in SAP S/4HANA and the positioning of CDS
within this architecture. Using examples, we show how
important aspects of application data are modeled with
CDS, such as field labels, field semantics, foreign key
relationships, language-dependent texts, entity
compositions, and time-dependent data.

In Chapter 9, we explain the virtual data model (VDM) of


SAP S/4HANA, which is formed by selected CDS views that
meet centrally defined quality and modeling aspects. The
modeling rules used are presented schematically via
examples. The explanations are intended to help you
understand the CDS models delivered by SAP and enable
you to use them purposefully in your own developments.

In Chapter 10, we focus on analytical applications. We


briefly discuss the SAP S/4HANA architecture for embedded
analytics and explain how CDS views can be used for this.
The analytical model used is based on a consistent network
of interlinked analytical CDS views and exposed via
analytical queries. We use examples to show you the
relationships between these CDS views and their special
features and analytical calculations.
In Chapter 11, we then deal with transactional
applications. In addition to modeling and executing read
accesses, CDS also is the basic data model for enabling
transactional processing. The integration of a transactional
runtime based on the ABAP RESTful application
programming model and the special aspects of transactional
applications, such as locking, authorizations, feature control,
business logic (e.g., actions, determinations, and
validations), and business events are explained using
appropriate examples. In addition, the draft concept is
introduced and explained in detail.

In Chapter 12, we introduce two options for the flexible


modeling in CDS of hierarchical structured data with
concrete examples. The hierarchical models are interpreted
directly by the underlying infrastructure (e.g., in analytical
applications) or can be used as powerful functions for
navigation or aggregation of these hierarchies in your ABAP
implementations.

Chapter 13 shows you that CDS can also be used as a


basis for modeling value helps and free-text searches. You’ll
learn how the value helps and search functions can be
integrated and used in certain use cases, for example, for
OData exposure.

Chapter 14 addresses the question of lifecycle and stability


of CDS and ABAP RESTful application programming model
artifacts as well as if and how these can be changed within
an upgrade or hot fix. Stability contracts provide security for
developers and consumers of these artifacts. A defined
lifecycle controls the release of these artifacts as well as
their deprecation and replacing successors.
Chapter 15 provides an overview of the possibilities for
modification-free enhancements by customers and partners.
In SAP S/4HANA Cloud, public edition, special tailored apps
support an experienced user with special authorizations—
the key user—in performing necessary enhancements.
These enhancements must be kept stable from a lifecycle
perspective to ensure smooth software. This requires special
preparations during application development and adherence
to stability contracts. Further developer extensibility is
explained by using CDS view extensions.

Chapter 16 introduces the creation of automated tests for


your CDS models as well as the transactional runtime and
its implementations. The test double framework presented
here allows you to exchange the data sources of CDS views
as well as certain parts of the behavior implementation and
thus to decouple the test execution from the actual
persistent data or productive application logic. We explain
test automation with the test double frameworks using
examples.

In Chapter 17, we recommend practical ways for


troubleshooting to find and correct errors and problems in
the context of CDS and the ABAP RESTful application
programming model. We describe the tools relevant for
troubleshooting and explain how to use them. In addition,
we illustrate some pitfalls that you may come across when
developing your CDS models.
An overview of the CDS annotations presented in this book
is included in Appendix A as a quick reference. For an
overview of all available CDS annotations, refer to the SAP
documentation.
In Appendix B, you can find an overview of how to migrate
an application based on the ABAP programming model for
SAP Fiori (that was the basic for transactional applications in
the first edition of this book) to the ABAP RESTful application
programming model.

In addition to screenshots and code examples, this book


also contains several text boxes to supplement the topics:

[+] Tip

Boxes marked with this icon provide recommendations or


offer tips from professional experience.

[»] Note

This icon indicates that additional information is provided.

[ ! ] Warning
With this icon, we have marked warnings and common
pitfalls.

Acknowledgments
We would like to thank our colleagues Christoph Glania,
Irena Kofman, Roland Lucius, Horst Schnörer, Stefan
Unnebrink, and Felix Wente for taking the time to discuss
and review the contents of the book. Your comments and
suggestions have contributed significantly to the success of
the book. In particular, we would like to thank our families
and friends, whose support has given us the necessary
freedom to create the book.

Now, we wish you much fun reading and much success


implementing your development projects with ABAP CDS
and the ABAP RESTful application programming model.

Renzo Colle, Ralf Dentzer, and Jan Hrastnik


1 Modeling Your First CDS Views

This chapter provides you with a quick introduction to data


modeling with core data services (CDS). In particular, you get an
overview of the processes and tools that are relevant to a CDS
developer.

Using CDS models, you can capture the data retrieval logic of your
application in such a way that it can be executed directly in the
database system. This chapter explains how to develop and analyze
such CDS models.
Currently, CDS views represent the most important design-time
artifacts within the range of supported CDS model types. They allow
you to flexibly transform the fixed design of database tables into
suitable data models, on top of which you can then efficiently build
your applications.

You define your CDS views in syntax similar to the structured query
language (SQL) that you use for selecting data from database tables
via the ABAP SQL interface (ABAP SQL). From this CDS view model, a
corresponding database view gets generated on the SAP HANA
database by the ABAP infrastructure. This generated database view is
executed when selecting data from the CDS view in ABAP.

When implementing CDS models, you may leverage a plurality of


specialized development tools that are integrated into the ABAP in
Eclipse environment—the ABAP Development Tools (ADT). In this
chapter, you’ll learn about the most important development and
analysis tools via a sample reference application.

Note that this chapter doesn’t focus on the details of the CDS
implementation. You’ll learn more about the detailed aspects of the
CDS models in subsequent chapters. Instead, we focus on presenting
the processes and procedures as well as the available tools, which
you’ll apply during your development activities.
In Section 1.1, we’re looking at the design of the data model of your
application. Based on the model of the database tables, we then run
through the individual, practically executable steps for creating and
changing CDS views in Section 1.2. In this context, you’ll also learn
how to use CDS views as basic building blocks for defining other CDS
views as well as learn how to use CDS views as data sources in your
ABAP logic. That is, you’ll learn how to select data from the modeled
CDS views by leveraging the ABAP SQL syntax.

As part of the maintenance processes presented, we provide


additional information about functions for examining CDS models to
help you analyze them in your future projects.

1.1 Define the Data Model of the


Application
The most important step in the development of CDS models is
defining the fundamental data model of the application. In this design
phase, the main aim is to identify and name the different data
sources, that is, the corresponding fundamental entities that your
application will be based on. Furthermore, the identified entities
should also be correlated to one another based on their semantic
relationships.

[+] Elaborate on the Fundamental Design


Before you start implementing your CDS models, you should take
time to work out the fundamental data model of your application
carefully and to clarify all open questions. Your evaluations should
consider all levels, beginning with the persistency layer up to the
end users’ application user interface (UI). With a little exercise, the
subsequent transfer of the finalized data model to a CDS-based
implementation will become an easy task.
If, however, you immediately start with the implementation of the
actual functions, changes to the already implemented CDS models
will very likely be required in the course of your development
activities. Such adjustments of the already developed CDS models
may become very time-consuming due to limited refactoring
support.

For demonstration purposes, we use a simplified model of a sales


order as our sample reference data model, which is referred to in
many discussions in subsequent chapters. Figure 1.1 gives you an
overview of its most important aspects. You’ll create parts of the
reference data model in the course of this chapter. You can find the
complete implementation of the database tables and CDS views in
the code snippets, which you can download from the book’s website
at www.sap-press.com/5642.
The main object—sales order—represents a hierarchically structured
document that is composed of the following entities: sales order
header, sales order item, and sales order schedule line. The header
entity of the sales order is also related to the sales organization and
the customer. The entity sales order item is related to the object
product, which consists of the corresponding header entity (product
header) and its related entity product text.

Figure 1.1 Reference Data Model of the Sales Order


The cardinalities, which are maintained at the illustrated
relationships, describe the number of related data records respective
to the data records of the source entities. On this instance level, a
single sales order document consists of one header to which multiple
items can be assigned (maximum cardinality: *). Each individual data
record of an item can be related to several records of the schedule
line (maximum cardinality: *).

For each sales order header data record, a maximum of one sales
organization and one customer data record can be assigned
(maximum cardinality: 1). A sales order item data record can have a
maximum of one product assigned, that is, one product header
(maximum cardinality: 1). For each product header data record, a
large number of multilingual texts can be stored as data records of
the entity product text (maximum cardinality: *).

The minimum cardinalities, which are specified with the value 0 in


Figure 1.1, reflect the technical consistency constraints of the
reference application.

[»] Objects and Header Entities

In this chapter, we’ll no longer distinguish between the overall


object sales order and the entity sales order header; instead, we’ll
simply refer to the sales order in both cases. In the majority of
cases, sales order refers to the entity sales order header. The same
applies for the entity product header, which will represent the
object product. In this chapter, it’s also only referred to as product.

Table 1.1 shows a summary of the objects and entities of the sample
reference application and provides an overview of how the entities of
the reference data model are mapped onto the underlying database
tables. Furthermore, the table lists the basic CDS views that
represent the data model of the application in CDS. Note that these
are sample tables and CDS views that you must create locally in your
system if you want to use them.
Object Entity Database Basic CDS View
Table

Sales order Sales order ZSALESORDER ZI_SalesOrder


(header)

Sales order ZSALESORDERITEM ZI_SalesOrderItem


item

Sales order ZSALESORDERSLINE ZI_SalesOrderScheduleLine


schedule
line

Sales Sales ZSALESORG ZI_SalesOrganization


organization organization

Customer Customer ZCUSTOMER ZI_Customer

Product Product ZPRODUCT ZI_Product

Product text ZPRODUCTTEXT ZI_ProductText

Table 1.1 Reference Data Model with Associated Database Tables and CDS Views

In general, we use names for all CDS models and their components
with spellings and prefixes based on the specifications of the virtual
data model (VDM), which most of the CDS models delivered by SAP
adhere to. SAP’s VDM will be explained in more detail in Chapter 9.

The CDS models of the reference data model are created in the local
namespace. For the sake of simplicity, they are prefixed with the
letter Z.

[ ! ] Use Your Customer Namespace

When you create CDS models, you must always define them in your
own namespace to avoid naming conflicts with the models
delivered by SAP. Merely adding the prefix Z for local developments
might not be sufficient for avoiding name clashes.
1.2 Implement the Data Model of the
Application
We now want to implement an extract from the reference data
model. First, we create the database tables for sales order item
ZSALESORDERITEM and for product ZPRODUCT in Section 1.2.1. Based on
database table ZPRODUCT, in Section 1.2.2, we then define CDS
view ZI_Product, which will represent the product. In Section 1.2.3,
we’ll show you how you can maintain this CDS view and how the
maintenance steps get reflected in its activation states. We
conclude this chapter by defining a hierarchy of CDS view models
in Section 1.2.4 in which we first create CDS view
ZI_SalesOrderItem as a representative of the sales order item
similar to CDS view ZI_Product. We capture the semantic
relationship of these two CDS views by means of CDS association
_Product.

[»] CDS Associations

Associations are an important and integral part of the CDS


syntax (see Chapter 3). Using CDS associations, you document
the relationship between the CDS models, essentially creating
an entity relationship model (ERM). An ERM describes a
semantic data model based on entities, their relationships, and
their properties. It’s the basis of many development projects.
Apart from enriching the CDS models with semantic
information, CDS associations can also be used for
implementing CDS models and parts thereof, as well as for data
accesses at runtime. We’ll show you this later in Section 1.2.4
and in Chapter 3.
Then, we create another CDS view, ZC_SalesOrderItemWithProduct,
which represents an example of a use case-specific consumption
view based on the fundamental data model of the application. It
selects data from the basic CDS view of the sales order item and
enriches this data with the data fetched from the basic CDS view
of the product by using a join. Figure 1.2 illustrates these
correlations.

Figure 1.2 Excerpt from the Implementation of the Reference Application Data
Model

Finally, we show you how you can analyze CDS models and
present the corresponding tools provided by the CDS
infrastructure.

We’ll take a closer look at each step in the following sections.

1.2.1 Create Database Tables


Often, the database tables of an application already exist. For
example, the productive CDS views of the sales order, which are
delivered with SAP S/4HANA, use database table VBAK, which was
already defined in the past. Therefore, we’ll only deal with the
definition of database tables in this section.

You can create and access database tables in the ABAP


Workbench via Transaction SE11. Alternatively, you can use the
corresponding functionality of the ADT environment, which
provides a source code editor for database tables within the
ABAP perspective. In this section, we’ll use ADT to create two
database tables.

To create the database table, choose File • New • Other… from


the main menu. Alternatively, you can call the same function
from the context menu of the project tree of the ABAP
development system in the Project Explorer view by choosing
New • Other…. In the selection screen that appears, choose
ABAP • Dictionary • Database Table. You can restrict the
object selection by entering the filter “Database Table”. The
result of this filtering is shown in Figure 1.3. You confirm your
selection by choosing Next >.

Figure 1.3 Selecting the Creation of a Database Table

The selected function opens a dialog box for creating database


tables. The dialog box guides you through two steps:
1. A modal window appears, in which you enter the ABAP project
of the development system, the package, the name of the
database table, and its description. The example shown in
Figure 1.4 uses local package TEST_CDS_REFERENCE_APPLICATION for
creating database table ZPRODUCT with description Product. Note
that if you want to follow this example, you can also use local
package $TMP instead of the aforementioned package. Choose
Next > to confirm your entries.
Figure 1.4 First Dialog Step When Creating a Database Table

2. Select a transport request that records your changes.


Because you’re only defining local objects for the reference
model, you can close the dialog box by clicking Finish.

This opens the source code-based editor for database tables.


Enter the same data as depicted in Figure 1.5; that is, in addition
to key field client, you define another key field product and three
further fields—product_type, authorization_group, and
creation_date_time—and then specify their types with data
elements matnr, mtart, begru, and timestampl, respectively.

Figure 1.5 Table Definition ZPRODUCT before Saving

You can now activate your table definition ZPRODUCT by choosing


Edit • Activate from the main menu, by using the key
combination (Ctrl)+(F3), or by clicking the corresponding icon
below the main menu bar. After the activation is completed,
you’ve successfully created a transparent database table for the
application data of the product with maintenance options and
without enhancement options.

Figure 1.6 shows the corresponding presentation of table ZPRODUCT


in the ABAP Workbench.

Figure 1.6 Table ZPRODUCT in the ABAP Workbench

Now, create the table of entity sales order item ZSALESORDERITEM in


the same way as you’ve just created the table of entity product
ZPRODUCT. Transfer the data from Listing 1.1 for use in defining this
database table.
@EndUserText.label : 'Sales Order Item'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #ALLOWED
define table zsalesorderitem {
key client : abap.clnt not null;
key salesorder : vbeln not null;
key salesorderitem : posnr not null;
product : matnr;
@Semantics.quantity.unitOfMeasure :
'zsalesorderitem.orderquantityunit'
orderquantity : kwmeng;
orderquantityunit : vrkme;
@Semantics.amount.currencyCode :
'zsalesorderitem.transactioncurrency'
netamount : netwr_ap;
transactioncurrency : waerk;
creationdate : erdat;
@AbapCatalog.anonymizedWhenDelivered : false
createdbyuser : ernam;
creationdatetime : creation_date_time;
@AbapCatalog.anonymizedWhenDelivered : false
lastchangedbyuser : aename;
lastchangedatetime : last_changed_date_time;
}
Listing 1.1 Definition of Database Table ZSALESORDERITEM

[+] Simplify the Design of Tables

When you define the design of your application tables, ensure


that the database tables to be created correspond to the
entities of your data model. In particular, don’t distribute data
of a single entity across multiple tables. Otherwise, the
consumers of your data model need to apply additional joins
when selecting data from the entity.

In addition, align the names of the database table fields with


the names used externally (e.g., in OData services) to avoid
unnecessary as well as potentially incorrect mappings.

1.2.2 Create a CDS View


CDS models are developed in the ADT environment.

[»] ABAP Workbench Restrictions

The ABAP Workbench provides only a rudimentary visualization


option for CDS models without the essential features required
for developing CDS models. Therefore, you should always work
with the ADT environment when dealing with CDS models.

When creating a CDS model, you can proceed in the same way as
when creating database tables. Choose File • New • Other…
from the main menu. In the dialog box that appears (see
Figure 1.7), choose ABAP • Core Data Services • Data
Definition. You can restrict the object selection by entering the
filter “Data Definition”. Confirm your selection by choosing Next
>.
Figure 1.7 Selecting the Creation of a CDS Data Model

The chosen function launches a specific dialog box for creating


CDS data models, which guides you through several steps. First,
a modal window appears in which you can enter the ABAP project
of the development system (Project), the package (Package),
the name of the CDS model (Name), its description
(Description), and the optional name of an object, which is
referenced by the CDS model (Referenced Object). Enter the
package “TEST_CDS_REFERENCE_APPLICATION”, the name
“ZI_Product”, the description “Product”, and the referenced
object “ZProduct”, as shown in Figure 1.8.

Figure 1.8 First Dialog Step When Creating a CDS Data Model
The entered name will become the name of your data definition
language source (DDLS) transport object, as well as the proposed
name for your CDS model.

[ ! ] DDLS Transport Object and CDS Model


The DDLS transport object and the CDS model are two different
design-time artifacts. The transport object (the DDLS) contains
the definition of a CDS model. A DDLS transport object could
theoretically contain several CDS model definitions. However,
this isn’t supported by the ABAP infrastructure.

For some types of CDS models, the names of these two design-
time artifacts—the DDLS transport object and the CDS model—
can differ from each other. However, we recommend that you
always define these two names in such a way that the DDLS
name corresponds to the name of the CDS model in uppercase
letters. Otherwise, you must map both names for later
analyses.

Choose Next > to confirm your entries.


In the next step, you can select the transport request, which
records your changes. In our example, you can skip this step by
choosing Next >.
In the last step, you can select a predefined template that will
support you when creating a new CDS model (see Figure 1.9).
Another random document with
no related content on Scribd:
and Iowa have since come into the Union, and they solemnly
repudiated and excluded slavery from those States forever.”
Charles Sumner on the Fallibility of Judicial
Tribunals.

Let me here say that I hold judges, and especially the Supreme
Court of the country, in much respect; but I am too familiar with the
history of Judicial proceedings to regard them with any superstitious
reverence. Judges are but men and in all ages have shown a full share
of frailty. Alas! alas! the worst crimes of history have been
perpetrated under their sanction. The blood of martyrs and of
patriots, crying from the ground, summons them to judgment.
It was a judicial tribunal which condemned Socrates to drink the
fatal hemlock, and which pushed the Saviour barefoot over the
pavements of Jerusalem, bending beneath his cross. It was a judicial
tribunal which, against the testimony and entreaties of her father,
surrendered the fair Virginia as a slave; which arrested the teachings
of the great apostle to the Gentiles, and sent him in bonds from
Judea to Rome; which, in the name of the old religion, adjured the
saints and fathers of the Christian Church to death, in all its most
dreadful forms; and which afterwards in the name of the new
religion, enforced the tortures of the Inquisition, amidst the shrieks
and agonies of its victims, while it compelled Galileo to declare, in
solemn denial of the great truth he had disclosed, that the earth did
not move round the sun.
It was a judicial tribunal which, in France, during the long reign of
her monarchs, lent itself to be the instrument of every tyranny, as
during the brief reign of terror it did not hesitate to stand forth the
unpitying accessory of the unpitying guillotine. Ay, sir, it was a
judicial tribunal in England, surrounded by all the forms of law,
which sanctioned every despotic caprice of Henry the eighth, from
the unjust divorce of his queen to the beheading of Sir Thomas
Moore; which lighted the fires of persecution, that glowed at Oxford
and Smithfield, over the cinders of Latimer, Ridley, and John
Rodgers; which, after elaborate argument, upheld the fatal tyranny
of ship money against the patriotic resistance of Hampden; which, in
defiance of justice and humanity, sent Sydney and Russell to the
block; which persistently enforced the laws of conformity that our
Puritan Fathers persistently refused to obey; and which afterwards,
with Jeffries on the bench, crimsoned the pages of English history
with massacre and murder, even with the blood of innocent women.
Ay, sir, and it was a judicial tribunal in our country, surrounded by
all the forms of law, which hung witches at Salem, which affirmed
the constitutionality of the Stamp Act, while it admonished “jurors
and the people” to obey; and which now, in our day, has lent its
sanction to the unutterable atrocity of the Fugitive Slave Law.
Galusha A. Grow’s Speech on the Homestead
Bill.

In the House of Representatives, March 30, 1852. “Man’s Right to


the Soil.”

But even if the Government could derive any revenue from the
actual sale of public lands, it is neither just nor sound policy to hold
them for that purpose. Aware, however, that it is a poor place, under
a one hour rule, to attempt to discuss any of the natural rights of
men, for, surrounded by the authority of ages, it becomes necessary,
without the time to do it, first to brush away the dust that has
gathered upon their errors. Yet it is well sometimes to go back of the
authority of books and treatises, composed by authors reared and
educated under monarchical institutions, and whose opinions and
habits of thought consequently were more or less shaped and
moulded by such influences, and examine, by the light of reason and
nature, the true foundation of government and the inherent rights of
men.
The fundamental rights of man may be summed up in two words—
Life and Happiness. The first is the gift of the Creator, and may be
bestowed at his pleasure; but it is not consistent with his character
for benevolence, that it should be bestowed for any other purpose
than to be enjoyed, and that we call happiness. Therefore, whatever
nature has provided for preserving the one, or promoting the other,
belongs alike to the whole race. And as the means for sustaining life
are derived almost entirely from the soil, every person has a right to
so much of the earth’s surface as is necessary for his support. To
whatever unoccupied portion of it, therefore, he shall apply his labor
for that purpose, from that time forth it becomes appropriated to his
own exclusive use; and whatever improvements he may make by his
industry become his property, and subject to his disposal.
The only true foundation of any right to property is man’s labor.
That is property, and that alone which the labor of man has made
such. What right, then, can the Government have in the soil of a wild
and uncultivated wilderness as a source of revenue, to which not a
day nor hour’s labor has been applied, to make it more productive,
and answer the end for which it was created, the support and
happiness of the race?
It is said by the great expounder of the common law in his
commentaries, that “there is no foundation in nature or natural law,
why a set of words upon parchment should convey the dominion of
land.” The use and occupancy alone gives to man, in the language of
the commentaries, “an exclusive right to retain, in a permanent
manner, that specific land which before belonged generally to
everybody, but particularly to nobody.” * * *
It may be said, true, such would be man’s right to the soil in a state
of nature; but when he entered into society, he gave up part of his
natural rights, in order to enjoy the advantages of an organized
community. This is a doctrine, I am aware, of the books and treatises
on society and government; but it is a doctrine of despotism, and
belongs not to enlightened statesmen in a liberal age. It is the excuse
of the despot in encroaching upon the rights of the subject. He
admits the encroachment, but claims that the citizen gave up part of
his natural rights when he entered into society; and who is to judge
what ones he relinquished but the ruling power? It was not necessary
that any of man’s natural rights should be yielded to the state in the
formation of society. He yielded no right, but the right to do wrong,
and that he never had by nature. All that he yielded in entering into
organized society, was a portion of his unrestrained liberty, which
was, that he would submit his conduct, that before was subject to the
control of no living being, to the tribunals to be established by the
state, and with a tacit consent that society, or the Government, might
regulate the mode and manner of the exercise of his rights. Why
should he consent to be deprived of them? It is upon this ground that
we justify resistance to tyrants. Whenever the ruling power so far
encroaches upon the natural rights of men that an appeal to arms
becomes preferable to submission, they appeal from human to divine
laws, and plead the natural rights of man in their justification. That
government, and that alone, is just, which enforces and defends all of
man’s natural rights, and protects him against the wrongs of his
fellow-men. But it may be said, although such might be the natural
rights of men, yet the Government has a right to these lands, and
may use them as a source of revenue, under the doctrine of eminent
domain. * * *
What is there in the constitution of things giving to one individual
the sole and exclusive right to any of the bounties provided by nature
for the benefit and support of the whole race, because, perchance, he
was the first to look upon a mere fragment of creation? By the same
process of reasoning, he who should first discover the source or
mouth of a river, would be entitled to a monopoly of the waters that
flow in the channel, or he who should first look upon one of the rills
or fountains of the earth might prevent fainting man from quenching
there his thirst, unless his right was first secured by parchment.
Why has the claim to monopolize any of the gifts of God to man
been confined, by legal codes, to the soil alone? Is there any other
reason than that it is a right which, having its origin in feudal times—
under a system that regarded man but as an appendage of the soil
that he tilled, and whose life, liberty and happiness, were but means
of increasing the pleasures, pampering the passions and appetites of
his liege lord—and, having once found a place in the books, it has
been retained by the reverence which man is wont to pay to the past,
and to time-honored precedents? The human mind is so constituted
that it is prone to regard as right what has come down to us approved
by long usage, and hallowed by gray age. It is a claim that had its
origin with the kindred idea that royal blood flows only in the veins
of an exclusive few, whose souls are more ethereal, because born
amid the glitter of courts, and cradled amid the pomp of lords and
courtiers, and, therefore, they are to be installed as rulers and law-
givers of the race. Most of the evils that afflict society have had their
origin in violence and wrong enacted into law by the experience of
the past, and retained by the prejudices of the present.
Is it not time to sweep from the statute book its still lingering relics
of feudalism; and to blot out the principles engrafted upon it by the
narrow-minded policy of other times, and adapt the legislation of the
country to the spirit of the age, and to the true ideas of man’s rights
and relations to his Government? If a man has a right on earth, he
has a right to land enough to rear a habitation on. If he has a right to
live, he has a right to the free use of whatever nature has provided for
his sustenance—air to breathe, water to drink, and land enough to
cultivate for his subsistence; for these are the necessary and
indispensable means for the enjoyment of his inalienable rights of
“life, liberty and the pursuit of happiness.” And is it for a
Government that claims to dispense equal and exact justice to all
classes of men, and that has laid down correct principles in its great
chart of human rights, to violate those principles and its solemn
declarations in its legislative enactments?
The struggle between capital and labor is an unequal one at best. It
is a struggle between the bones and sinews of men, and dollars and
cents. And in that struggle, is it for the government to stretch forth
its arm to aid the strong against the weak? Shall it continue, by its
legislation, to elevate and enrich idleness on the wail and woe of
industry?
If the rule be correct as applied to governments as well as
individuals, that whatever a person permits another to do, having the
right and means to prevent it, he does himself, then indeed is the
government responsible for all the evils that may result from
speculation and land monopoly in the public domain. For it is not
denied that Congress has the power to make any regulations for the
disposal of these lands, not injurious to the general welfare. Now,
when a new tract is surveyed, and you open the land office and
expose it to sale, the man with the most money is the largest
purchaser. The most desirable and available locations are seized
upon by the capitalists of the country, who seek that kind of
investment. The settler who chances not to have a pre-emption right,
or to be there at the time of sale, when he comes to seek a home for
himself and his family, must pay the speculator three or four
hundred per cent. on his investment, or encounter the trials and
hardships of a still more remote border life. And thus, under the
operation of laws that are called equal and just, you take from the
settler three or four dollars per acre, and put it in the pocket of the
speculator—thus, by the operation of law, abstracting so much of his
hard earnings for the benefit of capital; for not an hour’s labor has
been applied to the land since it was sold by the government, nor is it
more valuable to the settler. Has not the laborer a right to complain
of legislation that compels him to endure greater toils and hardships,
or contribute a portion of his earnings for the benefit of the
capitalist? But not upon the capitalist or the speculator is it proper
that the blame should fall. Man must seek a livelihood and do
business under the laws of the country; and whatever rights he may
acquire under the laws, though they may be wrong, yet the well-
being of society requires that they be respected and faithfully
observed. If a person engage in a business legalized and regulated by
the law, and uses no fraud or deception in its pursuit, and evils result
to the community, let them apply the remedy to the proper source—
that is to the law-making power. The laws and the law-makers are
responsible for whatever evils necessarily grow out of their
enactments.
While the public lands are exposed to indiscriminate sale, as they
have been since the organization of the government, it opens the
door to the wildest system of land monopoly. It requires no lengthy
dissertation to portray its evils. In the Old World its history is written
in sighs and tears. Under its influence, you behold in England, the
proudest and most splendid aristocracy, side by side with the most
abject and destitute people; vast manors hemmed in by hedges as a
sporting-ground for her nobility, while men are dying beside the
enclosure for the want of land to till. Thirty thousand proprietors
hold the title deeds to the soil of Great Britain, while in Ireland alone
there are two and a half millions of tenants who own no part of the
land they cultivate, nor can they ever acquire a title to a foot of it, yet
they pay annually from their hard earnings twenty millions of dollars
to absentee landlords for the privilege of dying on their soil. Under
its blighting influence you behold industry in rags and patience in
despair. Such are some of the fruits of land monopoly in the Old
World; and, shall we plant its seeds in the virgin soil of the
New? * * *
If you would raise fallen man from his degradation, elevate the
servile from their grovelling pursuits to the rights and dignity of
men, you must first place within their reach the means for satisfying
their pressing physical wants, so that religion can exert its influence
on the soul, and soothe the weary pilgrim in his pathway to the tomb.
It is in vain you talk of the goodness and benevolence of an
Omniscient Ruler to him, whose life from the cradle to the grave is
one continued scene of pain, misery and want. Talk not of free
agency to him whose only freedom is to choose his own method to
die. In such cases, there might, perhaps, be some feeble conceptions
of religion and its duties—of the infinite, everlasting, and pure; but
unless there be a more than common intellect, they would be like the
dim shadows that float in the twilight. * * *
Riches, it is true, are not necessary to man’s real enjoyment; but
the means to prevent starvation are. Nor is a splendid palace
necessary to his real happiness; but a shelter against the storm and
winter’s blast is.
If you would lead the erring back from the paths of vice and crime
to virtue and honor, give him a home—give him a hearth-stone, and
he will surround it with household gods. If you would make men
wiser and better, relieve the almshouse, close the doors of the
penitentiary, and break in pieces the gallows, purify the influences of
the domestic fireside. For that is the school in which human
character is formed, and there its destiny is shaped. There the soul
receives its first impress, and man his first lesson, and they go with
him for weal or woe through life. For purifying the sentiments,
elevating the thoughts, and developing the noblest impulses of man’s
nature, the influences of a moral fireside and agricultural life are the
noblest and the best. * * *
It was said by Lord Chatham, in his appeal to the House of
Commons, in 1775, to withdraw the British troops from Boston, that
“trade, indeed, increases the glory and wealth of a country; but its
true strength and stamina are to be looked for in the cultivators of
the land. In the simplicity of their lives is found the simpleness of
virtue, the integrity and courage of freedom. These true, genuine
sons of the soil are invincible.”
The history of American prowess has recorded these words as
prophetic: man, in defence of his hearth-stone and fireside, is
invincible against a world of mercenaries. In battling for his home
and all that is dear to him on earth, he is never conquered save with
his life. In such a struggle every pass becomes a Thermopylæ, every
plain a Marathon. With an independent yeomanry scattered over our
vast domain, the “young eagle” may bid defiance to the world in
arms. Even though a foe should devastate our seaboard, lay in ashes
its cities, they have made not one single advance towards conquering
the country; for from the interior comes its hardy yeomanry, with
their hearts of oak and nerves of steel, to expel the invader. Their
hearts are the citadel of a nation’s power—their arms the bulwarks of
liberty.

Every consideration of policy, then, both as to revenue for the


general government, and increased taxation for the new States, as
well as a means for removing the causes of pauperism and crime in
the old, demands that the public lands be granted in limited
quantities to the actual settler. Every consideration of justice and
humanity calls upon us to restore man to his natural rights in the
soil. * * *
In a new country the first and most important labor, as it is the
most difficult to be performed, is to subdue the forest, and to convert
the lair of the wild beast into a home for civilized man. This is the
labor of the pioneer settler. His achievements, if not equally brilliant
with those of the plumed warrior, are equally, if not more, lasting;
his life, if not at times exposed to so great a hazard, is still one of
equal danger and death. It is a life of toil and adventure, spent upon
one continued battle-field, unlike that, however, on which martial
hosts contend, for there the struggle is short and expected, and the
victim strikes not alone, while the highest meed of ambition crowns
the victor. Not so with the hardy pioneer. He is oft called upon to
meet death in a struggle with fearful odds, while no herald will tell to
the world of the unequal combat. Startled at the midnight hour by
the war-whoop, he wakes from his dreams to behold his cottage in
flames; the sharer of his joys and sorrows, with perhaps a tender
infant, hurled, with rude hands, to the distant council-fire. Still he
presses on into the wilderness, snatching new areas from the wild
beast, and bequeathing them a legacy to civilized man. And all he
asks of his country and his Government is, to protect him against the
cupidity of soulless capital and the iron grasp of the speculator. Upon
his wild battle-field these are the only foes that his own stern heart
and right arm cannot vanquish.
Lincoln and Douglas.

The Last Joint Debate, at Alton, October 15, 1858.[85]

SENATOR DOUGLAS’S SPEECH.

Ladies and Gentlemen: It is now nearly four months since the


canvass between Mr. Lincoln and myself commenced. On the 16th of
June the Republican Convention assembled at Springfield and
nominated Mr. Lincoln as their candidate for the United States
Senate, and he, on that occasion, delivered a speech in which he laid
down what he understood to be the Republican creed and the
platform on which he proposed to stand during the contest. The
principal points in that speech of Mr. Lincoln’s were: First, that this
Government could not endure permanently divided into free and
slave States, as our fathers made it; that they must all become free or
all become slave; all become one thing or all become the other,
otherwise this Union could not continue to exist. I give you his
opinions almost in the identical language he used. His second
proposition was a crusade against the Supreme Court of the United
States because of the Dred Scot decision; urging as an especial
reason for his opposition to that decision that it deprived the negroes
of the rights and benefits of that clause in the Constitution of the
United States which guaranties to the citizens of each State all the
rights, privileges, and immunities of the citizens of the several States.
On the 10th of July I returned home, and delivered a speech to the
people of Chicago, in which I announced it to be my purpose to
appeal to the people of Illinois to sustain the course I had pursued in
Congress. In that speech I joined issue with Mr. Lincoln on the
points which he had presented. Thus there was an issue clear and
distinct made up between us on these two propositions laid down in
the speech of Mr. Lincoln at Springfield, and controverted by me in
my reply to him at Chicago. On the next day, the 11th of July, Mr.
Lincoln replied to me at Chicago, explaining at some length, and
reaffirming the positions which he had taken in his Springfield
speech. In that Chicago speech he even went further than he had
before, and uttered sentiments in regard to the negro being on an
equality with the white man. He adopted in support of this position
the argument which Lovejoy and Codding, and other Abolition
lecturers had made familiar in the northern and central portions of
the State, to wit: that the Declaration of Independence having
declared all men free and equal, by Divine law, also that negro
equality was an inalienable right, of which they could not be
deprived. He insisted, in that speech, that the Declaration of
Independence included the negro in the clause, asserting that all
men were created equal, and went so far as to say that if one man
was allowed to take the position, that it did not include the negro,
others might take the position that it did not include other men. He
said that all these distinctions between this man and that man, this
race and the other race, must be discarded, and we must all stand by
the Declaration of Independence, declaring that all men were created
equal.
The issue thus being made up between Mr. Lincoln and myself on
three points, we went before the people of the State. During the
following seven weeks, between the Chicago speeches and our first
meeting at Ottawa, he and I addressed large assemblages of the
people in many of the central counties. In my speeches I confined
myself closely to those three positions which he had taken,
controverting his proposition that this Union could not exist as our
fathers made it, divided into free and Slave States, controverting his
proposition of a crusade against the Supreme Court because of the
Dred Scott decision, and controverting his proposition that the
Declaration of Independence included and meant the negroes as well
as the white men when it declared all men to be created equal. I
supposed at that time that these propositions constituted a distinct
issue between us, and that the opposite positions we had taken upon
them we would be willing to be held to in every part of the State. I
never intended to waver one hair’s breadth from that issue either in
the north or the south, or wherever I should address the people of
Illinois. I hold that when the time arrives that I cannot proclaim my
political creed in the same terms not only in the northern but the
southern part of Illinois, not only in the Northern but the Southern
States, and wherever the American flag waves over American soil,
that then there must be something wrong in that creed. So long as we
live under a common Constitution, so long as we live in a
confederacy of sovereign and equal States, joined together as one for
certain purposes, that any political creed is radically wrong which
cannot be proclaimed in every State, and every section of that Union,
alike. I took up Mr. Lincoln’s three propositions in my several
speeches, analyzed them, and pointed out what I believed to be the
radical errors contained in them. First, in regard to his doctrine that
this Government was in violation of the law of God, which says that a
house divided against itself cannot stand, I repudiated it as a slander
upon the immortal framers of our Constitution. I then said, I have
often repeated, and now again assert, that in my opinion our
Government can endure forever, divided into free and slave States as
our fathers made it,—each State having the right to prohibit, abolish
or sustain slavery, just as it pleases. This Government was made
upon the great basis of the sovereignty of the States, the right of each
State to regulate its own domestic institutions to suit itself, and that
right was conferred with the understanding and expectation that
inasmuch as each locality had separate interests, each locality must
have different and distinct local and domestic institutions,
corresponding to its wants and interests. Our fathers knew when
they made the Government, that the laws and institutions which
were well adapted to the green mountains of Vermont, were unsuited
to the rice plantations of South Carolina. They knew then, as well as
we know now, that the laws and institutions which would be well
adapted to the beautiful prairies of Illinois would not be suited to the
mining regions of California. They knew that in a Republic as broad
as this, having such a variety of soil, climate and interest, there must
necessarily be a corresponding variety of local laws—the policy and
institutions of each State adapted to its condition and wants. For this
reason this Union was established on the right of each State to do as
it pleased on the question of slavery, and every other question; and
the various States were not allowed to complain of, much less
interfere with the policy, of their neighbors.
Suppose the doctrine advocated by Mr. Lincoln and the
Abolitionists of this day had prevailed when the Constitution was
made, what would have been the result? Imagine for a moment that
Mr. Lincoln had been a member of the Convention that framed the
Constitution of the United States, and that when its members were
about to sign that wonderful document, he had arisen in that
Convention as he did at Springfield this summer, and addressing
himself to the President, had said, “A house divided against itself
cannot stand; this Government, divided into free and slave States,
cannot endure, they must all be free or all be slave, they must all be
one thing or all be the other, otherwise, it is a violation of the law of
God, and cannot continue to exist;”—suppose Mr. Lincoln had
convinced that body of sages that that doctrine was sound, what
would have been the result? Remember that the Union was then
composed of thirteen States, twelve of which were slaveholding and
one free. Do you think that the one free State would have outvoted
the twelve slaveholding States, and thus have secured the abolition of
slavery? On the other hand, would not the twelve slaveholding States
have outvoted the one free State, and thus have fastened slavery, by a
Constitutional provision, on every foot of the American Republic
forever? You see that if this Abolition doctrine of Mr. Lincoln had
prevailed when the Government was made, it would have established
slavery as a permanent institution, in all the States, whether they
wanted it or not, and the question for us to determine in Illinois now
as one of the free States is, whether or not we are willing, having
become the majority section, to enforce a doctrine on the minority,
which we would have resisted with our hearts’ blood had it been
attempted on us when we were in a minority. How has the South lost
her power as the majority section in this Union, and how have the
free States gained it, except under the operation of that principle
which declares the right of the people of each State and each
Territory to form and regulate their domestic institutions in their
own way. It was under that principle that slavery was abolished in
New Hampshire, Rhode Island, Connecticut, New York, New Jersey,
and Pennsylvania; it was under that principle that one-half of the
slaveholding States became free; it was under that principle that the
number of free States increased until from being one out of twelve
States, we have grown to be the majority of States of the whole
Union, with the power to control the House of Representatives and
Senate, and the power, consequently, to elect a President by
Northern votes without the aid of a Southern State. Having obtained
this power under the operation of that great principle, are you now
prepared to abandon the principle and declare that merely because
we have the power you will wage a war against the Southern States
and their institutions until you force them to abolish slavery
everywhere.
After having pressed these arguments home on Mr. Lincoln for
seven weeks, publishing a number of my speeches, we met at Ottawa
in joint discussion, and he then began to crawfish a little, and let
himself down. I there propounded certain questions to him. Amongst
others, I asked him whether he would vote for the admission of any
more slave States in the event the people wanted them. He would not
answer. I then told him that if he did not answer the question there I
would renew it at Freeport, and would then trot him down into Egypt
and again put it to him. Well, at Freeport, knowing that the next joint
discussion took place in Egypt, and being in dread of it, he did
answer my question in regard to no more slave States in a mode
which he hoped would be satisfactory to me, and accomplish the
object he had in view. I will show you what his answer was. After
saying that he was not pledged to the Republican doctrine of “no
more slave States,” he declared:
“I state to you freely, frankly, that I should be exceedingly sorry to ever be put in
the position of having to pass upon that question. I should be exceedingly glad to
know that there never would be another slave State admitted into this Union.”
Here permit me to remark, that I do not think the people will ever
force him into a position against his will. He went on to say:
“But I must add in regard to this, that if slavery shall be kept out of the Territory
during the territorial existence of any one given Territory, and then the people
should, having a fair chance and a clear field when they come to adopt a
Constitution, if they should do the extraordinary thing of adopting a slave
Constitution, uninfluenced by the actual presence of the institution among them, I
see no alternative, if we own the country, but we must admit it into the Union.”
That answer Mr. Lincoln supposed would satisfy the old line
Whigs, composed of Kentuckians and Virginians down in the
southern part of the State. Now what does it amount to? I desired to
know whether he would vote to allow Kansas to come into the Union
with slavery or not, as her people desired. He would not answer; but
in a roundabout way said that if slavery should be kept out of a
Territory during the whole of its territorial existence, and then the
people, when they adopted a State Constitution, asked admission as
a slave State, he supposed he would have to let the State come in. The
case I put to him was an entirely different one. I desired to know
whether he would vote to admit a State if Congress had not
prohibited slavery in it during its territorial existence, as Congress
never pretended to do under Clay’s Compromise measures of 1850.
He would not answer, and I have not yet been able to get an answer
from him. I have asked him whether he would vote to admit
Nebraska if her people asked to come in as a State with a
Constitution recognizing slavery, and he refused to answer. I have
put the question to him with reference to New Mexico, and he has
not uttered a word in answer. I have enumerated the Territories, one
after another, putting the same question to him with reference to
each, and he has not said, and will not say, whether, if elected to
Congress, he will vote to admit any Territory now in existence with
such a Constitution as her people may adopt. He invents a case
which does not exist, and cannot exist under this Government, and
answers it; but he will not answer the question I put to him in
connection with any of the Territories now in existence. The contract
we entered into with Texas when she entered the Union obliges us to
allow four States to be formed out of the old State, and admitted with
or without slavery as the respective inhabitants of each may
determine. I have asked Mr. Lincoln three times in our joint
discussions whether he would vote to redeem that pledge, and he has
never yet answered. He is as silent as the grave on the subject. He
would rather answer as to a state of the case which will never arise
than commit himself by telling what he would do in a case which
would come up for his action soon after his election to Congress.
Why can he not say whether he is willing to allow the people of each
State to have slavery or not as they please, and to come into the
Union when they have the requisite population as a slave or a free
State as they decide? I have no trouble in answering the questions. I
have said every where, and now repeat it to you, that if the people of
Kansas want a slave State they have a right, under the Constitution of
the United States, to form such a State, and I will let them come into
the Union with slavery or without, as they determine. If the people of
any other Territory desire slavery, let them have it. If they do not
want it, let them prohibit it. It is their business, not mine. It is none
of our business in Illinois whether Kansas is a free State or a slave
State. It is none of your business in Missouri whether Kansas shall
adopt slavery or reject it. It is the business of her people and none of
yours. The people of Kansas have as much right to decide that
question for themselves as you have in Missouri to decide it for
yourselves, or we in Illinois to decide it for ourselves.
And here I may repeat what I have said in every speech I have
made in Illinois, that I fought the Lecompton Constitution to its
death, not because of the slavery clause in it, but because it was not
the act and deed of the people of Kansas. I said then in Congress, and
I say now, that if the people of Kansas want a slave State, they have a
right to have it. If they wanted the Lecompton Constitution, they had
a right to have it. I was opposed to that Constitution because I did
not believe that it was the act and deed of the people, but on the
contrary, the act of a small, pitiful minority acting in the name of the
majority. When at last it was determined to send that Constitution
back to the people, and accordingly, in August last, the question of
admission under it was submitted to a popular vote, the citizens
rejected it by nearly ten to one, thus showing conclusively, that I was
right when I said that the Lecompton Constitution was not the act
and the deed of the people of Kansas, and did not embody their will.
I hold that there is no power on earth, under our system of
Government, which has the right to force a Constitution upon an
unwilling people. Suppose that there had been a majority of ten to
one in favor of slavery in Kansas, and suppose there had been an
Abolition President, and an Abolition Administration, and by some
means the Abolitionists succeeded in forcing an Abolition
Constitution on those slaveholding people, would the people of the
South have submitted to that act for one instant? Well, if you of the
South would not have submitted to it a day, how can you, as fair,
honorable and honest men, insist on putting a slave Constitution on
a people who desire a free State? Your safety and ours depend upon
both of us acting in good faith, and living up to that great principle
which asserts the right of every people to form and regulate their
domestic institutions to suit themselves, subject only to the
Constitution of the United States.
Most of the men who denounced my course on the Lecompton
question, objected to it not because I was not right, but because they
thought it expedient at that time, for the sake of keeping the party
together, to do wrong. I never knew the Democratic party to violate
any one of its principles out of policy or expediency, that it did not
pay the debt with sorrow. There is no safety or success for our party
unless we always do right, and trust the consequences to God and the
people. I chose not to depart from principle for the sake of
expediency in the Lecompton question, and I never intend to do it on
that or any other question.
But I am told that I would have been all right if I had only voted for
the English bill after Lecompton was killed. You know a general
pardon was granted to all political offenders on the Lecompton
question, provided they would only vote for the English bill. I did not
accept the benefits of that pardon, for the reason that I had been
right in the course I had pursued, and hence did not require any
forgiveness. Let us see how the result has been worked out. English
brought in his bill referring the Lecompton Constitution back to the
people, with the provision that if it was rejected Kansas should be
kept out of the Union until she had the full ratio of population
required for a member of Congress, thus in effect declaring that if the
people of Kansas would only consent to come into the Union under
the Lecompton Constitution, and have a slave State when they did
not want it, they should be admitted with a population of 35,000, but
that if they were so obstinate as to insist upon having just such a
Constitution as they thought best, and to desire admission as a free
State, then they should be kept out until they had 93,420
inhabitants. I then said, and I now repeat to you, that whenever
Kansas has people enough for a slave State she has people enough for
a free State. I was and am willing to adopt the rule that no State shall
ever come into the Union until she has the full ratio of population for
a member of Congress, provided that rule is made uniform. I made
that proposition in the Senate last winter, but a majority of the
Senators would not agree to it; and I then said to them if you will not
adopt the general rule I will not consent to make an exception of
Kansas.
I hold that it is a violation of the fundamental principles of this
Government to throw the weight of federal power into the scale,
either in favor of the free or the slave States. Equality among all the
States of this Union is a fundamental principle in our political
system. We have no more right to throw the weight of the Federal
Government into the scale in favor of the slaveholding than the free
States, and last of all should our friends in the South consent for a
moment that Congress should withhold its powers either way when
they know that there is a majority against them in both Houses of
Congress.
Fellow-citizens, how have the supporters of the English bill stood
up to their pledges not to admit Kansas until she obtained a
population of 93,420 in the event she rejected the Lecompton
Constitution? How? The newspapers inform us that English himself,
whilst conducting his canvass for re-election, and in order to secure
it, pledged himself to his constituents that if returned he would
disregard his own bill and vote to admit Kansas into the Union with
such population as she might have when she made application. We
are informed that every Democratic candidate for Congress in all the
States where elections have recently been held, was pledged against
the English bill, with perhaps one or two exceptions. Now, if I had
only done as these anti-Lecompton men who voted for the English
bill in Congress, pledging themselves to refuse to admit Kansas if she
refused to become a slave State until she had a population of 93,420,
and then return to their people, forfeited their pledge, and made a
new pledge to admit Kansas at any time she applied, without regard
to population, I would have had no trouble. You saw the whole power
and patronage of the Federal Government wielded in Indiana, Ohio
and Pennsylvania to re-elect anti-Lecompton men to Congress who
voted against Lecompton, then voted for the English bill, and then
denounced the English bill, and pledged themselves to their people
to disregard it. My sin consists in not having given a pledge, and then
in not having afterward forfeited it. For that reason, in this State,
every postmaster, every route agent, every collector of the ports, and
every federal office-holder, forfeits his head the moment he
expresses a preference for the Democratic candidates against Lincoln
and his Abolition associates. A Democratic Administration which we
helped to bring into power, deems it consistent with its fidelity to
principle and its regard to duty, to wield its power in this State in
behalf of the Republican Abolition candidates in every county and
every Congressional District against the Democratic party. All I have
to say in reference to the matter is, that if that Administration have
not regard enough for principle, if they are not sufficiently attached
to the creed of the Democratic party to bury forever their personal
hostilities in order to succeed in carrying out our glorious principles,
I have. I have no personal difficulty with Mr. Buchanan or his
cabinet. He chose to make certain recommendations to Congress, as
he had a right to do, on the Lecompton question. I could not vote in
favor of them. I had as much right to judge for myself how I should
vote as he had how he should recommend. He undertook to say to
me, if you do not vote as I tell you, I will take off the heads of your
friends. I replied to him, You did not elect me, I represent Illinois
and I am accountable to Illinois, as my constituency, and to God, but
not to the President or to any other power on earth.
And now this warfare is made on me because I would not
surrender my convictions of duty, because I would not abandon my
constituency, and receive the orders of the executive authorities how
I should vote in the Senate of the United States. I hold that an
attempt to control the Senate on the part of the Executive is
subversive of the principles of our Constitution. The Executive
department is independent of the Senate, and the Senate is
independent of the President. In matters of legislation the President
has a veto on the action of the Senate, and in appointments and
treaties the Senate has a veto on the President. He has no more right
to tell me how I shall vote on his appointments than I have to tell
him whether he shall veto or approve a bill that the Senate has
passed. Whenever you recognize the right of the Executive to say to a
Senator, “Do this, or I will take off the heads of your friends,” you
convert this Government from a republic into a despotism.
Whenever you recognize the right of a President to say to a member
of Congress, “Vote as I tell you, or I will bring a power to bear against
you at home which will crush you,” you destroy the independence of
the representative, and convert him into a tool of Executive power. I
resisted this invasion of the constitutional rights of a Senator, and I
intend to resist it as long as I have a voice to speak, or a vote to give.
Yet, Mr. Buchanan cannot provoke me to abandon one iota of
Democratic principles out of revenge or hostility to his course. I
stand by the platform of the Democratic party, and by its
organization, and support its nominees. If there are any who choose
to bolt, the fact only shows that they are not as good Democrats as I
am.
My friends, there never was a time when it was as important for
the Democratic party, for all national men, to rally and stand
together as it is to-day. We find all sectional men giving up past

You might also like