---
parser: v2
auto_validation: true
primary_tag: products>sap-btp--abap-environment
tags: [  tutorial>beginner, topic>abap-development, software-product>sap-business-technology-platform, software-product>sap-s-4hana-cloud ]
time: 20
author_name: Merve Temel
author_profile: https://github.com/mervey45
slug: abap-environment-rap100-generate-ui-service
canonical_url: https://developers.sap.com/tutorials/abap-environment-rap100-generate-ui-service
---

# Create Database Table and Generate UI Service
<!-- description --> Create a database table and generate UI services with SAP BTP ABAP environment.
 
## Prerequisites
- You need to have access to an SAP BTP, ABAP environment, or SAP S/4HANA Cloud, ABAP environment or SAP S/4HANA (release 2022 or higher) system. 
  For example, you can create a free [trial user](abap-environment-trial-onboarding) on SAP BTP, ABAP environment.
- You have downloaded and installed the [latest ABAP Development Tools (ADT)] (https://tools.hana.ondemand.com/#abap) on the latest Eclipse© platform.
- You have created an [ABAP Cloud Project](abap-environment-create-abap-cloud-project).
- Your system has the ABAP flight reference scenario. If your system hasn't this scenario. You can download it [here](https://github.com/SAP-samples/abap-platform-refscen-flight). The trial systems have the flight scenario included.
- You have read and understood the tutorial [Get to Know the ABAP RESTful Application Programming Model](https://developers.sap.com/tutorials/abap-environment-restful-programming-model.html).

## You will learn  
  - How to create an ABAP package
  - How to create a database table
  - How to create a data generator class
  - How to generate transactional UI services
  - How to preview the travel app

## Intro
In this exercise, you will create an ABAP package and database table. In your database table you will define all important fields. To fill all your database table fields, you will create an ABAP class and run it. With the transactional UI services you will be able to define all your UI services in one step. This includes the data model, projection view, service definition and service binding. Afterwards you will check your Travel application with the SAP Fiori elements preview.


---

### Create Package

Create your exercise package. This ABAP package will contain all the artefacts you will be creating in the different exercises of this tutorial.

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

 2. Maintain the required information (`###` is your group ID):

    - Name: `ZRAP100_###`
    - Description: RAP100 Package `###`
    Select the box Add to favorites package

    Click **Next >**.

 3. Select a transport request, maintained a description (e.g. `RAP100 Package ###`), and click **Finish**.

      ![package](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/p.png)


 
### Create database table


Create a database table![table](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/adt_tabl.png) 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.

 1. Right-click on your ABAP package **`ZRAP100_###`** and select **New** > **Other ABAP Repository Object** from the context menu.

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

 3. Maintain the required information (`###` is your group ID) and click **Next >**.
    - Name: **`ZRAP100_ATRAV###`**
    - Description: **Travel data**                  

    ![table](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/p2.png)

 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 occurrences of the placeholder **`###`** with your group ID using the **Replace All** function (CTRL+F).

   ```ABAP
   @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; 
   }    
   ```

 6. Save ![save icon](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/adt_save.png) and activate ![activate icon](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/adt_activate.png) the changes.


### Generate transactional UI service


Create your OData v4 based UI service with 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.

 1. Right-click your database table ![table](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/adt_tabl.png) **`ZRAP100_ATRAV###`**  and select **Generate ABAP Repository Objects** from the context menu.  

 2. Maintain the required information  (`###` is your group ID) and click **Next >**:
    - Description: **`Travel App ###`**
    - Generator: **`ABAP RESTful Application Programming Model: UI Service`**

    ![class](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/generate.png)

    | **Generator: Cloud System**                                                   |  **Generator: On Premise System**      |   
    |:----------------------------------------------------------------------------- |:-------------------------------------- |
    |1. Select **OData UI Service** and click **Next >**.  ![table](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/newgenerator2.png) |1. Provide a description, select **ABAP RESTful Application Programming Model: UI Service** and click **Next >**. ![table](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/generatorxx1.png) |                       
    |2. Click **Next >**. ![table](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/newgenerator3.png)    |    | 
        

 3. 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 artifacts will be generated.

    >**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**                  | CDS Entity Name: **`ZRAP100_R_TRAVELTP_###`**                 |
    |                                        |                                 | CDS Entity Name Alias: **`Travel`**                           |  
    |                                        | **Behavior**                    | Implementation Behavior Class: **`ZRAP100_BP_TRAVELTP_###`**  |
    |                                        |                                 | Draft Table Name: **`ZRAP100_DTRAV###`**                      |  
    | **Service Projection**                 | **Service Projection Entity**   | CDS Entity Name: **`ZRAP100_C_TRAVELTP_###`**                 |
    |                                        | **Service Projection Behavior** | Behavior Implementation Class: **`ZRAP100_BP_C_TRAVELTP_###`**|   
    | **Business Service**                   |                                 |                                                               |
    |                                        | **Service Definition**          | Service Definition Name: **`ZRAP100_UI_TRAVEL_###`**          |
    |                                        | **Service Binding**             | Service Binding Name: **`ZRAP100_UI_TRAVEL_O4_###`**          |
    |                                        |                                 | Binding Type: **`OData V4 - UI`**                             |

    ![class](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/new0x.png)                     
 

 4. Go to the **Project Explorer**, select your package ![package](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/adt_package.png) **`ZRAP100_###`**, refresh it by pressing **F5**, and check all generated ABAP repository objects

    ![class](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/newx.png)

    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_I_TRAVEL_###`**

      ![class](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/tb2.png)

    **BO Projection `ZRAP100_C_TRAVEL_###`**

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

      ![class](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/tb3.png)

    **Business Service**

      ![class](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/tb4.png)


### Create data generator class

Create an ABAP class![class](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/adt_class.png) to generate demo **travel** data.

  1. Right-click your ABAP package **`ZRAP100_###`** and select **New** > **ABAP Class** from the context menu.

  2. Maintain the required information (`###` is your group ID) and click **Next >**.
      - Name: **`ZCL_RAP100_GEN_DATA_###`**
      - Description: **Generate demo data**      

      ![class](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/demo.png)

  3. Select a transport request and click **Finish** to create the class.

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

   ```ABAP
   CLASS zcl_rap100_gen_data_### DEFINITION
   PUBLIC
     FINAL
     CREATE PUBLIC .

     PUBLIC SECTION.

       INTERFACES if_oo_adt_classrun.
     PROTECTED SECTION.
     PRIVATE SECTION.
   ENDCLASS.

   CLASS zcl_rap100_gen_data_### IMPLEMENTATION.

     METHOD if_oo_adt_classrun~main.
       DATA:
         group_id   TYPE string VALUE '###',
         attachment TYPE /dmo/attachment,
         file_name  TYPE /dmo/filename,
         mime_type  TYPE /dmo/mime_type.

   *   clear data
       DELETE FROM zrap100_atrav###.
       DELETE FROM zrap100_dtrav###.

       "insert travel demo data
       INSERT zrap100_atrav###  FROM (
           SELECT
             FROM /dmo/travel AS travel
             FIELDS
               travel~travel_id        AS travel_id,
               travel~agency_id        AS agency_id,
               travel~customer_id      AS customer_id,
               travel~begin_date       AS begin_date,
               travel~end_date         AS end_date,
               travel~booking_fee      AS booking_fee,
               travel~total_price      AS total_price,
               travel~currency_code    AS currency_code,
               travel~description      AS description,
               CASE travel~status    "[N(New) | P(Planned) | B(Booked) | X(Cancelled)]
                 WHEN 'N' THEN 'O'
                 WHEN 'P' THEN 'O'
                 WHEN 'B' THEN 'A'
                 ELSE 'X'
               END                     AS overall_status,
               @attachment             AS attachment,
               @mime_type              AS mime_type,
               @file_name              AS file_name,
               travel~createdby        AS created_by,
               travel~createdat        AS created_at,
               travel~lastchangedby    AS last_changed_by,
               travel~lastchangedat    AS last_changed_at,
               travel~lastchangedat    AS local_last_changed_at
               ORDER BY travel_id UP TO 10 ROWS
         ).
       COMMIT WORK.
       out->write( |[RAP100] Demo data generated for table ZRAP100_ATRAV{ group_id }. | ).
     ENDMETHOD.
   ENDCLASS.
   ```

  5. Save ![save icon](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/adt_save.png) and activate ![activate icon](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/adt_activate.png) the changes.

  6. Run your console application. For that, select your ABAP class ![class](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/adt_class.png) **`ZCL_RAP100_GEN_DATA_###`**, select the run button > **Run As** > **ABAP Application (Console) F9** or press **F9**. A message will be displayed **ABAP Console**.

      ![class](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/p4.png)  

  7. Open your database table ![table](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/adt_tabl.png) **`ZRAP100_ATRAV###`** and press **F8** to start the data preview and display the filled database entries, i.e. **travel** data.

      ![class](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/p5.png)   


### Preview travel app

>**Hint:** In **SAP S/4HANA on premise or private cloud systems** publishing the local service endpoint of your OData V4 service binding does not work from within ADT. Therefore you have to publish the service binding locally using transaction `/IWFND/V4_ADMIN` in these systems.


Publish the local service endpoint of your service binding ![service binding](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/adt_srvb.png) and start the **Fiori elements App Preview**.


 1. Open your service binding ![service binding](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/adt_srvb.png) **`ZRAP100_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](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/p8.png)

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

 4. Check your result.

     ![class](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/p9x.png)


### Preview the Travel App in SAP S/4HANA on premise (optional)

>**Hint:** In **SAP S/4HANA on premise or private cloud systems** publishing the local service endpoint of your OData V4 service binding does not work from within ADT. Therefore you have to publish the service binding locally using transaction `/IWFND/V4_ADMIN` in these systems.

 1. In the menu click on the button **Run ABAP Development Object as ABAP Application in SAPGUI** or press `Alt+F8`.

     ![onprem](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/onprem.png)

 2. Type `/iwfnd/v4_admin` as a search string and double-click on the entry `/IWFND/V4_ADMIN` (Transaction).

     ![onprem](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/onprem2.png)

 3. Click the button **Publish Service Groups** to get a list of service groups that can be published.

     ![onprem](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/onprem3.png)

 4. Enter following values to search for the service group of your service and press the button **Get Service Groups**:

    - System Alias: LOCAL
    - Service Group ID: `Z*###*`

     ![onprem](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/onprem4.png)  

 5. Select the entry `ZRAP100_UI_TRAVELTP_O4_###` from the list and press the button **Publish Service Groups**.

     ![onprem](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/onprem5.png)

 6. In the following popup enter a meaningful description such as `Travel App ###`.

     ![onprem](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/onprem6.png)

 7. You are now asked to provide a customizing request. Choose an existing customizing request or create a new one and choose a meaningful description.

     ![onprem](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/onprem7.png)

 8. Confirm the success message and press **Enter**.

     ![onprem](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/onprem8.png)

 9. Navigate back to your service binding in the project explorer. Right click on it and choose **Refresh**.
 
     ![onprem](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-environment-rap100-generate-ui-service/onprem9.png)


10. Check that your service bindings is now publish and choose the entity **Travel** and press the button **Preview**.


### Test yourself




---
