Exploring the Architecture

Objectives

After completing this lesson, you will be able to:

  • Create a database table
  • Generate the development objects for an OData UI service

Creation of the Data Model

Example Data Model

The data model in this example is very simple - there is a single database table that contains details of flight connections - an airline, flight number, details of the departure airport and the destination.

Note

Not included in the figure are additional fields that the runtime needs in order to manage concurrency control. We will look at these a little later on.

Creating a Database Table

First, let's see how to create a database table.

Defining Basic Table Attributes

We will now see how to define basic table attributes.

Adding Table Definition

The following video show how to add table definition.

If you do not use a built-in ABAP Dictionary type to specify the type of a table column, use a data element instead. Data elements are ABAP Dictionary objects that define the type of a single field such as UUID, or airline code. Data elements contain not only a technical type description but also semantic information such as field labels. If you use data elements to define the types of the table columns, the system can use the field labels automatically on the generated user interface.

The data element in the Data Element figure describes the airline field. It is a character field with length 3; the system will use the field labels automatically on the generated UI.

To create a new data element, choose FileNewOther, then type data element into the Filter Text field. Enter a package name and the name of the data element, then choose Next. Select a transport request and choose Finish.

You must then specify a data type for the data element. This should be a domain - the example re-uses the existing domain /DMO/CITY. Note that both data elements use the same domain. This means that if someone subsequently changes the length of the domain, the change applies to all data elements that use it.

Finally, you enter short, medium, and long field labels, and a label that is used for column headings. Later on, when you generate the Fiori Elements app, the system will use these texts automatically.

Each table that you define must have a primary key. This is a sequence of fields at the beginning of the table description that identifies each entry in the table uniquely.

The first field in the table (and therefore also the first field in the key definition) must be the client field, and this must have the data type abap.clnt. Furthermore, it is convenient for our example to use a UUID for the unique key. If you use the data element sysuuid_x16 to specify the type of this field, you can let the runtime assign the UUID automatically when you create a new record.

For traceability reasons it is recommended to store some administrative information with the data, like, for example, the user that created or changed the data and timestamps for the creation and the last change. The database table that you create should contain the fields displayed in the figure.

Note

These fields are mandatory for the generator we are going to use later. For that generator to work properly the fields also have be defined with the data types listed here.

Especially fieldslocal_last_changed_at and last_changed_at are not only administrative fields. In the ABAP RESTful application programming model they are also used for concurrency control.

Because RESTful applications are stateless, data consistency cannot be ensured by exclusive locks alone. The ABAP RESTful application programming model uses a mixture of exclusive locks and ETags to avoid data inconsistencies. An ETag is a field that changes its value whenever a data set is updated. By comparing the value of the ETag field, the framework can ensure that a data set has not been changed since it was read the last time. Timestamps of the last change make perfect ETag fields.

When you activate a database table in ADT, the system creates the corresponding physical table in the database. Once you have done this, you will be able to generate the additional objects that you need for your app automatically.

How to Create Data Elements

Steps

  1. Create a new data element called z##_city_from.

    1. Choose FileNewOther.

    2. Type Data e into the filter field. The system reduces the hit list to Data Element.

    3. Double-click Data Element.

    4. Ensure that your package is set to ZS4D400_##. Enter the name Z##_CITY_FROM and a description. Choose Next.

    5. Select your transport request and choose Finish.

  2. Use the domain /dmo/city to specify the type of the data element.

    1. In the Type Name field, enter /dmo/city.

  3. For each of the texts (short, medium, long, heading), enter a suitable text.

    1. Enter Departure in the Short field.

    2. Enter Departure City in the Medium field.

    3. Enter Departure City in the Long field.

    4. Enter Departure in the Heading field.

  4. Activate the data element.

    1. Choose Ctrl + F3.

How to Create a Database Table

Copy a Database Table

In the exercises of this unit, you will create an OData UI service. This UI service will form the basis for an application that allows you to change the price of flights. Firstly, you create a dedicated package for the required development objects. Then you copy a database table and fill it with data.

Template:

  • /LRN/S4D400_APT (Database Table)
  • /LRN/CL_S4D400_APT_COPY (global Class)

Solution:

  • /LRN/S4D400AFLGT (Database Table)
  • /LRN/CL_S4D400_APS_COPY (global Class)

Task 1: Create Subpackage

Create a new subpackage under your own package ZS4D400_## (where ## stands for your group number).

The subpackage should have the following attributes:

AttributeValue
NameZS4D400_##_RAP, where ## stands for your group number
DescriptionObjects for OData UI Service
Add to Favorite PackagesChecked
SuperpackageZS4D400_##, , where ## stands for your group number
Package TypeDevelopment
Software ComponentZLOCAL
Application ComponentCA
Transport Layer 

Steps

  1. Create a sub package under your own package ZS4D400_## (where ## stands for your group number).

    1. In the Project Explorer, right-click on your ABAP package ZS4D400_## and choose NewABAP Package.

    2. Enter the package name ZS4D400_##_RAP where ## stands for your group number.

    3. Enter the description Objects for OData UI Service.

    4. Mark the checkbox Add to favorite packages

    5. Ensure that the field Superpackage contains the name of your already existing package.

    6. Ensure that the Package Type is set to Development.

    7. Choose Next.

    8. Ensure that the Software Component is set to ZLOCAL.

    9. Enter the Application component CA.

    10. Ensure that the Transport Layer is empty.

    11. Choose Next.

    12. Confirm the transport request and choose Finish.

Task 2: Copy Database Table

Under the new package, create a copy of the database table /LRN/S4D400_APT. Name the new database table Z##AFLGT, where ## stands for your group number.

Steps

  1. Copy database table /LRN/S4D400_APT to your own package ZS4D400_##_RAP, where ## stands for your group number.

    1. Open the definition of the database table /LRN/S4D400_APT .

    2. Link the Project Explorer view with the editor.

    3. In the Project Explorer view, right-click database table /LRN/S4D400_APT to open the context menu.

    4. From the context menu, choose Duplicate ....

    5. Enter the name of your package ZS4D400_##_RAP in the Package field. In the Name field, enter the name Z##AFLGT, where ## stands for your group number.

    6. Adjust the description and choose Next.

    7. Confirm the transport request and choose Finish.

  2. Activate the database table definition.

    1. Choose Ctrl + F3.

Task 3: Fill Database Table

In your own package, create a copy global class /LRN/CL_S4D400_APT_COPY (suggested name: ZCL_##_COPY. In this copy, change the value of constant table name to the name of your own database table. Then execute the class as a console app. This will fill your database table with data.

Steps

  1. Copy the class /LRN/CL_S4D400_APT_COPY to a class in your own package ZS4D400_##.

    1. Open the source code of the global class /LRN/CL_S4D400_APT_COPY.

    2. If necessary, link the Project Explorer view with the editor.

    3. In the Project Explorer view, right-click the class /LRN/CL_S4D400_APT_COPY to open the context menu.

    4. From the context menu, choose Duplicate ....

    5. Enter the name of your package in the Package field. In the Name field, enter the name ZCL_##_COPY, where ## stands for your group number.

    6. Adjust the description and choose Next.

    7. Confirm the transport request and choose Finish.

  2. In the copy, adjust the source code of the method IF_OO_ADT_CLASSRUN~MAIN. Change the value of the constant table_name to the name of your own database table.

    1. If you named your table as suggested above, all you have to do is replace ## with your group number.

  3. Activate and execute the class as a console app.

    1. Press Ctrl + F3 to activate the class.

    2. Press F9 to run the class.

    3. Check the Console view. The last output should read: <...> was filled with data. If the output reads <...> is not a table of the right type. make sure a database table of that name exists, is active, and is an exact copy of the template table.

The Object Generator

Generating Additional Objects

We have just defined a database table to hold our data, but the app that we are going to create needs more objects than just this table. We can generate these objects using a wizard in ADT.

The generated objects contain all of the information that is necessary to provide a working app with create, read, update, and delete capability. Later on, we will also adjust and extend some of these objects to change the appearance of the user interface and to implement some checks and calculations.

Watch this video to learn how to generate additional objects.

How to Generate the Additional Objects

Preview of the OData UI Service

Publish and Preview the Service

Using your database table and the object generator, you can generate all of the objects that you need to get a working Fiori Elements app. The only manual step is to publish the service.

You must publish the service before you can test the app. To do so, open the service binding and choose Publish. Once you have done this, the entity that you created (in this case, Connection) appears in the list of entities. Mark it and choose Preview to test the app.

Test the App

When you choose Preview, a browser window opens and you can create a new flight connection. However, the app does not implement any checks other than type checks (for example, only digits are allowed in the Flight Number field).

Generate and Preview an OData UI Service

In this exercise, you generate the repository objects for an OData UI Service and preview the service as an SAP Fiori app.

Template:

  • none

Solution:

  • The generated development objects in package /LRN/S4D400_EXERCISE_RAP.

Prerequisites

You completed the previous exercises. You created the database table Z##AFLGT (where ## is your group number) and the database table contains data.

Task 1: Use the Generator

Use the object generator ABAP RESTful Application Programming ModelOData UI Service to generate the following development objects in your sub package ZS4D400_##_RAP:

Object TypeObject Name
CDS View Entity (model)Z##_R_Flight (Alias name: Flight)
Implementation ClassZBP_##_Flight
Draft TableZ##DFLGT
CDS View Entity (projection)Z##_C_Flight
Service DefinitionZ##_Flight
Service BindingZ##_UI_Flight_O4 (Binding Type: OData V4 - UI)

Steps

  1. Start the object generator for your database table Z##AFLGT(where ## is your group number).

    1. In the Project Explorer, expand the following path: Favorite PackagesZS4D400_##ZS4D400_##_RAPDictionaryDatabase Tables (where ## is your group number). Alternatively, open the defintion of database table Z##AFLGT and, if necessary, link the Project Explorer view with the editor.

    2. In the Project Explorer view, right-click database table Z##AFLGT to open the context menu.

    3. From the context menu, choose Generate ABAP Repository Object ....

  2. In the dialog box, select the generator.

    1. On the left-hand side of the dialog box, choose ABAP RESTful Application Programming ModelOData UI Service.

    2. Choose Next to navigate to the next step.

  3. Ensure that the development objects are created in your sub package ZS4D400_##_RAP.

    1. When the window reads Enter Package at the top, ensure that the field Package contains ZS4D400_##_RAP

    2. Choose Next to navigate to the next step.

  4. Configure the generator with the data from the table.

    Do not choose Next before you have entered all data.
    1. On the left-hand side of the dialog box, choose General. In the right-hand pane, enter Maintain Flights as a description for your service.

    2. On the left-hand side of the dialog box, choose Data Model. In the right-hand pane, enter the Data Definition NameZ##_R_Flight and Alias NameFlight.

    3. On the left-hand side of the dialog box, choose Behavior. In the right-hand pane, enter the Implementation ClassZBP_##_FLIGHT and the Draft Table NameZ##DFLGT.

    4. On the left-hand side of the dialog box, choose Service Projection. In the right-hand pane, enter the NameZ##_C_Flight.

    5. On the left-hand side of the dialog box, choose Service Definition. In the right-hand pane, enter the NameZ##_FLIGHT.

    6. On the left-hand side of the dialog box, click Service Binding. In the right-hand pane, enter the NameZ##_UI_FLIGHT_O4 and ensure the Binding Type is set to OData V4 - UI.

    7. After you entered all data choose Next

  5. Preview the generator output and generate the objects.

    1. Check the list of repository objects that are displayed.

    2. When you are sure you have entered all names correctly choose Next.

    3. Confirm the transport request and choose Finish.

  6. Analyze the generator output in the Project Explorer.

    1. In the Project Explorer view on the left-hand side, place the cursor on your sub package ZS4D400_##_RAP and press F5 to reload the content of the package.

    2. Expand all sub nodes of the package to see the names of the generated development objects.

Task 2: Preview the App

Publish the OData UI Service and preview the result as an SAP Fiori app.

Steps

  1. Publish the local service endpoint if needed.

    1. Open the Service Binding that was generated earlier.

    2. In the Services section on the left-hand side, check the status of the service. If field Local Service Endpoint contains the value Unpublished, the service is not yet published.

    3. To publish the service, choose Publish in the center of the view.

  2. Preview the OData UI service as an SAP Fiori app.

    1. In the Service Version Details section on the right-hand side, choose Flight and then Preview ....

    2. A browser window opens with a SAP Fiori app.

  3. Display the list of flights.

    1. Choose Go to display the list of flights that are stored in your database table Z##AFLGT.

  4. For one of the flights, navigate to the details view.

    1. Choose one of the list entries to navigate to the Object Page with details of that flight.

  5. For this flight, switch to change mode.

    1. Choose Edit.

  6. Enter some text in the field Flight Price , for example a and a long text in the field Currency Code (at least 6 characters), for example abcdef.

  7. Enter a negative price and abc as currency code.

Log in to track your progress & complete quizzes