Skip to content

Latest commit

 

History

History
453 lines (306 loc) · 25.5 KB

README.md

File metadata and controls

453 lines (306 loc) · 25.5 KB

Home - RAP100

Exercise 1: Create Database Table and Generate UI Service

Introduction

In this exercise, you will create a transactional UI service along with the underlying RAP business object.

First you will create an ABAP package, a database table, and an ABAP class to fill the database table with demo data. Then you will use an ADT wizard to generate all the needed development RAP artefacts of your UI service on top of the database table. This includes the CDS data model, behavior definition, service definition, and service binding. Afterwards you will publish and check your Travel application with the SAP Fiori elements preview.

Reminder:
Don't forget to replace all occurences of the placeholder ### with your group ID in the exercise steps below.
You can use the ADT function Replace All (Ctrl+F) for the purpose.
If you don't have a group ID yet, then check the section Getting Started - Group ID.

Exercise 1.1: Create Package

^Top of page

Create your exercise packagepackage.
This ABAP package will contain all the artefacts you will be creating in the different exercises of this hands-on session.

Click to expand!
  1. In ADT, go to the Project Explorer, right-click on the package ZLOCAL, and select New > ABAP Package from the context menu.

    table
  2. Maintain the required information (### is your group ID, please choose a suitable combination of numbers and characters, e.g. 088 or ZT1):

    • Name: ZRAP100_###
    • Description: RAP100 Package ###
    • Select the box Add to favorites package
    • Superpackage: ZLOCAL

    Click Next >.

    table
  3. Select a transport request, maintain a description (e.g. RAP100 Package ###), and click Finish.

    table

Exercise 1.2: Create database table

^Top of page

Create a database tabletable to store the Travel data.
A Travel entity defines general travel data, such as the agency ID or customer ID, overall status of the travel booking, and the price of travel.

Click to expand!
  1. Right-click on your ABAP package ZRAP100_### and select New > Other ABAP Repository Object from the context menu.

    table
  2. Search for database table, select it, and click Next >.

    table
  3. Maintain the required information (### is your group ID) and click Next >.

    • Name: ZRAP100_ATRAV###
    • Description: Travel data
    table
  4. Select a transport request, and click Finish to create the database table.

  5. Replace the default code with the code snippet provided below and replace all occurences of the placeholder ### with your group ID using the Replace All function (Ctrl+F).

    Hint: Hover the code snippet and choose the Copy raw contents icon table appearing in the upper-right corner to copy it.

    @EndUserText.label : 'Travel data'
    @AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
    @AbapCatalog.tableCategory : #TRANSPARENT
    @AbapCatalog.deliveryClass : #A
    @AbapCatalog.dataMaintenance : #RESTRICTED
    define table zrap100_atrav### {
      key client            : abap.clnt not null;
      key travel_id         : /dmo/travel_id not null;
      agency_id             : /dmo/agency_id;
      customer_id           : /dmo/customer_id;
      begin_date            : /dmo/begin_date;
      end_date              : /dmo/end_date;
      @Semantics.amount.currencyCode : 'zrap100_atrav###.currency_code'
      booking_fee           : /dmo/booking_fee;
      @Semantics.amount.currencyCode : 'zrap100_atrav###.currency_code'
      total_price           : /dmo/total_price;
      currency_code         : /dmo/currency_code;
      description           : /dmo/description;
      overall_status        : /dmo/overall_status;
      attachment            : /dmo/attachment;
      mime_type             : /dmo/mime_type;
      file_name             : /dmo/filename;
      created_by            : abp_creation_user;
      created_at            : abp_creation_tstmpl;
      local_last_changed_by : abp_locinst_lastchange_user;
      local_last_changed_at : abp_locinst_lastchange_tstmpl;
      last_changed_at       : abp_lastchange_tstmpl; 
    }
    table
  6. Save save icon and activate activate icon the changes.

Exercise 1.3: Create data generator class

^Top of page

Create an ABAP classclass to generate demo travel data.

Click to expand!
  1. Right-click your ABAP package ZRAP100_### and select New > ABAP Class from the context menu.

    table
  2. Maintain the required information (### is your group ID) and click Next >.

    • Name: ZCL_RAP100_GEN_DATA_###
    • Description: Generate demo data
    table
  3. Select a transport request and click Finish to create the class.

  4. Replace the default source code with the code snippet provided in the source code document ZRAP100_GEN_DATA_### linked below and replace all occurences of the placeholder ### with your group ID using the Replace All function (Ctrl+F).

    You can use the ABAP Pretty Printer (ABAP Formatter) function using by pressing Shift+F1 to format the source code. You will be requested to configure it, if this is the first time you use it on the system.

    Hint: Open the document in a new tab. In the document editor, use the Copy raw contents icon table in the toolbar to copy the full source code.

    document Source code document: class iconClass ZRAP100_GEN_DATA_###

  5. Save save icon and activate activate icon the changes.

  6. Run your console application.

    For that, select your ABAP class classZCL_RAP100_GEN_DATA_###, select the run button > Run As > ABAP Application (Console) F9 or press F9.

    table

    A message will be displayed ABAP Console.

    table
  7. Open your database table tableZRAP100_ATRAV### and press F8 to start the data preview and display the filled database entries, i.e. travel data.

    class

Exercise 1.4: Generate the transactional UI service

^Top of page

Create your OData v4 based UI services and the RAP business object (BO) with all the needed ABAP artefacts - e.g. CDS view entities, behavior definition and implementation - using the built-in ADT generator.
The generated business service will be transactional, draft-enabled, and enriched with UI semantics for the generation of the Fiori elements app.

Click to expand!
  1. Right-click your database table tableZRAP100_ATRAV### and select Generate ABAP Repository Objects from the context menu.

    table ___________________________________________________________________________________________________________________________________________________
    Generator: Cloud System Generator: On Premise System
    1. Select OData UI Service and click Next >. table 1. Provide a description, select ABAP RESTful Application Programmind Model: UI Service and click Next >. table
    2. Click Next >. table
    3. Enter a description. table
  2. Maintain the required information on the Configure Generator dialog to provide the name of your data model and generate them.

    For that, navigate through the wizard tree (Business Objects, Data Model, etc...), maintain the artefact names provided in the table below, and press Next >.

    Verify the maintained entries and press Next > to confirm. The needed artefacts will be generated.

    Info about Naming Conventions
    The main aspects of the naming conventions of SAP S/4HANA's Virtual Data Model (VDM) are used in this exercise.
    More information on VDM can be found on the SAP Help portal: Here.

    Attention
    Please make sure to replace all the name proposals in the wizard with the names provided below.
    Doing this is important to ensure the correctness of the code snippets provided in the following exercises.

    RAP Layer Artefacts Artefact Names
    Business Object
    Data Model Data Definition Name: ZRAP100_R_TravelTP_###
    Alias Name: Travel
    Behavior Implementation Class: ZRAP100_BP_TravelTP_###
    Draft Table Name: ZRAP100_DTRAV###
    Service Projection (BO Projection) Name: ZRAP100_C_TravelTP_###
    Business Services
    Service Definition Name: ZRAP100_UI_Travel_###
    Service Binding Name: ZRAP100_UI_Travel_O4_###
    Binding Type: OData V4 - UI
    table table table
  3. Go to the Project Explorer, select your package packageZRAP100_###, refresh it by pressing F5, and check all generated ABAP repository objects

    table

Below is a brief explanation of the generated artefacts for the different RAP layers: Base BO, BO Projection, and Business Service.


Base Business Object (BO) ZRAP100_R_TRAVEL_###

Object Name Description
ddls iconZRAP100_R_TravelTP_### (aka Base BO view): This data definition defines the data model of the root entity Travel which is the only node of our business object).
bdef iconZRAP100_R_TravelTP_### (aka _Base BO behavior): This behavior definition contains the definition of the standard transactional behavior of the base Travel BO entity. It is a managed and draft-enabled implementation.
tabl iconZRAP100_DTRAV### (aka Draft table): This database table is used to temporary store the data from draft travel instances at runtime. It is managed by the RAP framework.
class iconZRAP100_BP_TRAVELTP_### (aka Behavior pool): This ABAP class which provides the implementation of the behavior defined in the behavior definition ZRAP100_R_TravelTP_### of the base Travel BO.

BO Projection ZRAP100_C_TRAVEL_###

The BO projection represents the consumption specific view on the BO data model and behavior.

Object Name Description
ddls iconZRAP100_C_TravelTP_### (aka BO projection view): This data definition is used to define the projected data model of the root entity Travel relevant for the present scenario. Currently almost all fields of the underlying base BO view are exposed and the definition of metadata extension is allowed using the view annotations @Metadata.allowExtensions: true.
bdef iconZRAP100_C_TravelTP_### (aka BO behavior projection): This behavior definition exposes the part of the underlying base Travel BO entity which is relevant for the present scenario with the keyword use. Currently all standard CUD operations are exposed.
ddlx iconZRAP100_C_TravelTP_### This metadata extension is used to annotate view ZRAP100_C_TRAVEL_### and its elements with UI semantics via CDS annotations.

Business Service

Object Name Description
srvd iconZRAP100_UI_TRAVEL_### A service definition is used to define the relevant entity sets for our service and also to provide local aliases if needed. Only the Travel entity set is exposed in the present scenario.
srvb iconZRAP100_UI_TRAVEL_O4_### This service binding is used to expose the generated service definition as OData V4 based UI service. Other binding types (protocols and scenarios) are supported in the service binding wizard.

Exercise 1.5: Publish and Preview the Travel App

^Top of page

Publish the local service endpoint of your service binding service binding and start the Fiori elements App Preview.

Exercise 1.5.1: Publish and Preview the Travel App on SAP BTP, ABAP environment or SAP S/4HANA, Public Cloud Edition

Publish the local service endpoint of your service binding in the Service Binding editor and start the Fiori elements App Preview.

Click to expand!
  1. Open your service binding service bindingZRAP100_UI_TRAVEL_O4_### and click Publish.

  2. Double-click on the entity Travel in the Entity Set and Association section to open the Fiori elements App Preview.

    class

  3. Click the button on the Travel app Go to load the data.

  4. Check your result.

    class

Summary

^Top of page

Now that you've...

  • created an ABAP package,
  • created a database table and fill it with demo data,
  • created a transactional UI service,
  • published a local service point, and started the Fiori elements App Preview in ADT,

you can continue with the next exercise - Exercise 2: Enhance the BO Data Model and Enable OData Streams.