This is the second post in this series. Here is the previous blog post: [Get to Know RAP: Introduction]

This blog post also follows up with a video that walks you through the tutorial that I will be going over.

Introduction

As mentioned in the previous blog post our goal is to develop a Fiori app using the ABAP RESTful Application Programming Model. We will be using steps spanning across all 3 layers (Data Modeling and Behavior, Business ServiceService Consumption).

We will start from the Data Modeling and Behavior and work our way up. Since our overall goal is to create a completely new transactional app for a Fiori Elements UI following the greenfield approach, we will create everything from scratch. With most new developments, you will always rely on the managed approach since the entire administration of the object is taken over for you by the RAP Framework.

To begin, I will be following along the Develop a Fiori App Using the ABAP RESTful Application Programming Model (Managed Scenario) group tutorials to develop a travel booking SAP Fiori application. For this blog post I will provide you my takeaway on creating table persistence and generating data for it.

Data Model and Business Object

As we previously mentioned before the data model consists of the entities involved in a business scenario, such as TRAVEL and BOOKING, and how they relate to each other. The ABAP RESTful Programming Model uses CDS to organize and define the data model. CDS entities are the fundamental building blocks for your application.

The travel business object consists of three entities that are structured in a hierarchy tree. Every entity in the BO-composition tree is modeled with a CDS view entity. The business entities we are going to work on in our present scenarios are:

  • Travel: The root entity defines general travel data, like the agency ID or customer ID, the status of the travel booking and the price of the travel.
  • Booking: The booking entity defines flight and booking data, the customer data, the customer ID for whom the flight is booked and Travel ID to which the booking belongs.
  • BookingSupplement: The booking supplement entity presents additional bookable supplement for a certain booking. These are meals and beverages for the flights.

Editable Entities of the Business Object

 

Creating Table Persistence

An overview of the typical development workflow in RAP is shown below. The development of our app will also look like this.

 

In this exercise we will first create a database table to store the travel data. We will also re-use from the already existing demo content from the ABAP Flight Reference Scenario (AgencyCustomer and Flight), as well as a few more.

📝 Note: In the ABAP Flight Reference Scenario for the persistent database tables, we use the prefix A_ to indicate the active persistence. For detailed information, see Naming Conventions for Development Objects.

Before we begin, it is important to know the prerequisites:

Prerequisites

Create ABAP Package

The first thing that needed to be done was to create an ABAP package, this is quite simple. Simply just log into the SAP system. From there, I select the option to create new package. The system prompts me to provide a name and description for the package. Don’t forget to check Add to favorite packages so that you can access it easily. You don’t have to go looking for it in ZLOCAL where you might run into the risk of you accidentally choosing someone else’s package.

 

ABAP Package

It is important to ensure that the package you are creating doesn’t already exist in ZLOCAL. This is because the trial version of the ABAP environment is shared and there are many packages available. So, make sure you have a unique name and make sure to add a number that is currently free. I had this issue at first when I was creating my package for the first time, I then found out it was already taken by someone else.

For this tutorial I decided to go with the suffix 234 for the various objects that I’m going to create. After providing the package name and description, I save the package, and it’s ready to use. Overall, this step is straightforward and easy to follow.

Database Table

Moving on from creating the package, I then went and created a database table to store the travel data that was provided for us in the tutorial. The tutorial will provide you the steps on creating the table. When creating the database table, it important to add in your suffix to the code sample. It took me a while to realize why my code was not activating, only to find out it was because the suffix was not added to the code.  I would like to provide you some code explanation, so you are familiar with the steps.

The table that I  created will open in the editor and the client field will be added automatically because it is a client-specific table.

 

@EndUserText.label : 'Database table for travel data 000'
@AbapCatalog.enhancementCategory : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table ztravel_000 {
  key client      : abap.clnt not null;
  key mykey       : sysuuid_x16 not null;
  travel_id       : /dmo/travel_id;
  agency_id       : /dmo/agency_id;
  customer_id     : /dmo/customer_id;
  begin_date      : /dmo/begin_date;
  end_date        : /dmo/end_date;
  @Semantics.amount.currencyCode : 'ztravel_000.currency_code'
  booking_fee     : /dmo/booking_fee;
  @Semantics.amount.currencyCode : 'ztravel_000.currency_code'
  total_price     : /dmo/total_price;
  currency_code   : /dmo/currency_code;
  description     : /dmo/description;
  overall_status  : /dmo/overall_status;
  created_by      : syuname;
  created_at      : timestampl;
  last_changed_by : syuname;
  last_changed_at : timestampl;

}   
*Don’t forget to replace all the 000 with your custom number

 

Code Explanation:

 

  • The table now consists of the key fields, client and mykey. It also includes table fields, such as human-readable TRAVEL_ID, the AGENCY_ID, the CUSTOMER_ID, the TOTAL_PRICE, and the OVERALL_STATUS

 

  • Some of the objects have /DMO. This is because they belong to the ABAP Flight Reference Scenario examples. If you are using the trial, it is already pre-installed for you.

 

  • We have some standard administration data, such as CREATED_BY, CREATED_AT

 

  • The table field CURRENCY_CODE is specified as the reference field for the amount fields BOOKING_FEE and TOTAL_PRICE using @Semantics.amount.currencyCode

 

 

Create ABAP class

The travel list report currently has no data, so we will create an ABAP class to fill the database table with some demo data.

 

We will replace the code and paste in the code snippet we have been provided. I would like to provide you some code explanation, so you are familiar with the steps.

CLASS zcl_generate_travel_data_000 DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
    INTERFACES if_oo_adt_classrun.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.



CLASS zcl_generate_travel_data_000 IMPLEMENTATION.
  METHOD if_oo_adt_classrun~main.

    DATA itab TYPE TABLE OF ztravel_000.

*   fill internal travel table (itab)
    itab = VALUE #(
      ( mykey = '02D5290E594C1EDA93815057FD946624' travel_id = '00000022' agency_id = '070001' customer_id = '000077' begin_date = '20190624' end_date = '20190628' booking_fee = '60.00' total_price =  '750.00' currency_code = 'USD'
        description = 'mv' overall_status = 'A' created_by = 'MUSTERMANN' created_at = '20190612133945.5960060' last_changed_by = 'MUSTERFRAU' last_changed_at = '20190702105400.3647680' )
      ( mykey = '02D5290E594C1EDA93815C50CD7AE62A' travel_id = '00000106' agency_id = '070005' customer_id = '000005' begin_date = '20190613' end_date = '20190716' booking_fee = '17.00' total_price = '650.00' currency_code = 'AFN'
        description = 'Enter your comments here' overall_status = 'A' created_by = 'MUSTERMANN' created_at = '20190613111129.2391370' last_changed_by = 'MUSTERMANN' last_changed_at = '20190711140753.1472620' )
      ( mykey = '02D5290E594C1EDA93858EED2DA2EB0B' travel_id = '00000103' agency_id = '070010' customer_id = '000011' begin_date = '20190610' end_date = '20190714' booking_fee = '17.00' total_price = '800.00' currency_code = 'AFN'
        description = 'Enter your comments here' overall_status = 'X' created_by = 'MUSTERFRAU' created_at = '20190613105654.4296640' last_changed_by = 'MUSTERFRAU' last_changed_at = '20190613111041.2251330' )
    ).

*   delete existing entries in the database table
    DELETE FROM ztravel_000.

*   insert the new table entries
    INSERT ztravel_000 FROM TABLE @itab.

*   output the result as a console message
    out->write( |{ sy-dbcnt } travel entries inserted successfully!| ).

  ENDMETHOD.
ENDCLASS.

 

Code Explanation

  • Adding the interfaces if_oo_adt_classrun will allow us to utilize ADT Eclipse. This will allow you to print out any value in the console. This is helpful because it will print out our console message and confirms if everything is correct

 

  • We then clean the table by deleting any existing entries

 

  • We then insert the new table entries we got in our ITAB

 

  • We then output the result as a console message

 

Now we can review the data. Also, you can see a success message is written to the console.

What’s Next:

In this blog post, I created a package and then within the package I created some persistence. I created a database table, and also wrote a class that allowed us to manipulate that table. In the next blog post I will define and expose a CDS-Based Travel Data Model and providing some key takeaways from the tutorial.

Previous Blog Post:

Get to Know RAP: Introduction

 

Sara Sampaio

Sara Sampaio

Author Since: March 10, 2022

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x