Get Started with ABAP Programming on SAP BTP

Analyzing a Business Object

Objectives
After completing this lesson, you will be able to:

After completing this lesson, you will be able to:

  • Analyze a Business Object

Analyzing an RAP Business Object

In the RESTful ABAP Programming model (RAP), a business object defines a particular entity, such as a flight connection. Its definition has two parts; a CDS view, which defines the structure of the object or, in other words, the fields that it contains, and a behavior definition, which describes what you can do with the business object. The behavior definition specifies which of the create, update, and delete operations are allowed. It can also contain validations; these check that the data is correct when you create or update a record and determinations, which fill fields of the business object based on the existing data. They can also contain actions, which modify the data outside of the normal scope of the standard create, update, and delete operations. Approving a purchase order or cancelling a flight are activities that you would implement as an action.

RAP business objects are commonly used in generated Fiori Elements apps or Web APIs. However, you can also access them from ABAP coding using Entity Manipulation Language (EML). This is a set of ABAP statements that allows you to create, read, update, and delete data using business objects. When you create a Fiori app based on a business object, you will often need to add code to the generated app, and you use EML in this context to access the application's data.

In this unit, you will create a class that modifies airline data. The view entity contains the fields AirlineID for the airline code, Name for the airline name, and CurrencyCode for its local currency.

Behavior Definition and Implementation

A validation is a check that the RAP runtime performs when data is changed. Here, the validation is performed when a new record is created (but not if an existing record is changed), and it is performed only if the CurrencyCode field is changed.

Validations are defined in the behavior definition. For each validation, there is a corresponding method.

How To Analyze A Business Object

Steps

  1. Open the CDS view entity /DMO/I_CarriersLockSingleton_S.

    1. Press Ctrl + Shift + A.

    2. Type /DMO/I_CarriersLockSingleton_S into the filter field.

    3. Double-click the line that begins with the letter D and contains the name /DMO/I_CarriersLockSingleton_S

  2. Show how to use the where-used list to navigate to the behavior definition.

    1. Place the cursor anywhere in the CDS view entity and press Ctrl + Shift + G.

    2. Double-click the line that begins with the letter B and contains the name /DMO/I_CarriersLockSingleton_S.

  3. Show how to navigate from the behavior definition to its implementation.

    1. In line 1 - managed implementation in class /dmo/bp_i_carrierslocksingle_s unique;, place the cursor on /dmo/bp_i_carrierslocksingle_s and press F3.

    2. Switch to the tab Local Types and show the code of method validateCurrencyCode.

Composite Business Objects

Many business objects contain more than one entity; these are called composite business objects. Composite business objects are hierarchical - there is a parent or root entity and a subordinate entity, called the child entity. The parent and child entities are linked by key values. For example, you could have an entity travel that describes a complete trip. The trip consists of one or more flight bookings, each of which belongs to the trip.

Each entity is represented by its own CDS view entity. However, there is only one behavior definition for the whole business object and this can contain multiple behavior definitions - one for each entity in the object.

You can use a single EML statement to address parent and child entities simultaneously.

Each entity is represented by its own CDS view entity. However, there is only one behavior definition for the whole business object and this can contain multiple behavior definitions, one for each entity in the object.

When you address a business object using EML, you need the name of the business object and then the name of the entity or entities that you want to read or modify. The name of the business object is the name of the behavior definition repository object. The name of the entity is the name after define behavior for. If the entity has an alias, you use that name. Attempting to use the entity name instead of the alias name causes a syntax error.

Save progress to your learning plan by logging in or creating an account