Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Restful ABAP Programming model to open Fiori application

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how to use Restful ABAP Programming model to open Fiori applications". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Jerry's blog collection for developing Fiori applications through CDS view + Smart Template.

ABAP is constantly evolving, and now we have a new programming model: the Restful ABAP Programming model, or RAP model for short. The model defines a set of architecture that application developers can use to efficiently develop end-to-end applications. This kind of application has the inherent characteristics of Restful and can make full use of the powerful computing power of HANA platform to support cloud environment and Fiori UX.

Three pillars of the RAP model:

Business Service

Core Data Service

Behavior Definition

Next, follow Jerry to learn about this new step of Fiori application development through the Restful ABAP Programming model through a practical example.

Jerry still uses the classic SFLIGHT model used in traditional ABAP On-Premises programming training materials as the underlying database storage.

(1) first create a database table ZTRAVEL_JERRY: (if you want to copy this source code, click "read the original text" at the end of the article)

EndUserText.label: 'Database table for travel data XXX'@AbapCatalog.enhancementCategory: # NOT_EXTENSIBLE@AbapCatalog.tableCategory: # TRANSPARENT@AbapCatalog.deliveryClass: # A@AbapCatalog.dataMaintenance: # LIMITEDdefine table ztravel_jerry {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: 'ztravel_jerry.currency_code' booking_fee: / dmo/booking_fee; @ Semantics.amount.currencyCode:' ztravel_jerry.currency_code' total_price: / dmo/total_price; currency_code: / dmo/currency_code; description: / dmo/description; created_by: syuname; created_at: timestampl Last_changed_by: syuname; last_changed_at: timestampl;}

Because we can't manually insert data into this table with the transaction code SE16 in ABAP Development Tools, I create an ABAP class and insert three pieces of data into the table with ABAP code.

Press F9 to execute the ABAP class and see that three pieces of data have been successfully inserted:

(2) our ultimate goal is to create a Fiori application that supports adding, deleting, modifying and querying this table, and one of the three pillars of the Restful ABAP Programming model is Core Data Service, so we must first have CDS view based on the database table ZTRAVEL_JERRY.

So I first create a CDS view:

AbapCatalog.sqlViewName: 'ZVI_TRAVEL'@AbapCatalog.compiler.compareFilter: true@AbapCatalog.preserveKey: true@AccessControl.authorizationCheck: # CHECK@EndUserText.label:' Travel data-XXX'define root view ZI_TRAVEL_JERRY as select from ztravel_jerry as Travel / * Associations * / association [0.1] to / DMO/I_Agency as _ Agency on $projection.agency_id = _ Agency.AgencyID association [0.1] to / DMO/I_Customer as _ Customer on $projection.customer_id = _ Customer.CustomerID association [0.. 1] to I_Currency as _ Currency on $projection.currency_code = _ Currency.Currency {key travel_id Agency_id, customer_id, begin_date, end_date, @ Semantics.amount.currencyCode: 'currency_code' booking_fee, @ Semantics.amount.currencyCode:' currency_code' total_price, @ Semantics.currencyCode: true currency_code, description,/*-- Admin data-- * / @ Semantics.user.createdBy: true created_by, @ Semantics.systemDateTime.createdAt: true created_at @ Semantics.user.lastChangedBy: true last_changed_by, @ Semantics.systemDateTime.lastChangedAt: true last_changed_at, / * Public associations * / _ Agency, _ Customer, _ Currency}

Then create a projection view that selectively exposes the fields of the view.

EndUserText.label: 'Travel projection view-Processor'@AccessControl.authorizationCheck: # NOT_REQUIRED@UI: {headerInfo: {typeName:' Travel', typeNamePlural: 'Travels', title: {type: # STANDARD, value:' TravelID'} @ Search.searchable: truedefine root view entity ZC_TRAVEL_JERRY as projection on ZI_TRAVEL_JERRY {@ UI.facet: [{id: 'Travel', purpose: # STANDARD Type: # IDENTIFICATION_REFERENCE, label: 'Travel', position: 10}] @ UI: {lineItem: [{position: 10, importance: # HIGH}], identification: [{position: 10, label:' Travel ID. 99999999]'}] @ Search.defaultSearchElement: true key travel_id as TravelID, @ UI: {lineItem: [{position: 20, importance: # HIGH}], identification: [{position: 20}], selectionField: [{position: 20}]} @ Consumption.valueHelpDefinition: [{entity: {name:'/ DMO/I_Agency' Element: 'AgencyID'}}] @ ObjectModel.text.element: [' AgencyName']-meaning? @ Search.defaultSearchElement: true agency_id as AgencyID, _ Agency.Name as AgencyName, @ UI: {lineItem: [{position: 30, importance: # HIGH}], identification: [{position: 30}] SelectionField: [{position: 30}] @ Consumption.valueHelpDefinition: [{entity: {name:'/ DMO/I_Customer', element: 'CustomerID'}}] @ ObjectModel.text.element: [' CustomerName'] @ Search.defaultSearchElement: true customer_id as CustomerID, @ UI.hidden: true _ Customer.LastName as CustomerName, @ UI: {lineItem: [{position: 40, importance: # MEDIUM}] Identification: [{position: 40}]} begin_date as BeginDate, @ UI: {lineItem: [{position: 41, importance: # MEDIUM}], identification: [{position: 41}]} end_date as EndDate, @ UI: {lineItem: [{position: 50, importance: # MEDIUM}], identification: [{position: 50 Label: 'TotalPrice'}} @ Semantics.amount.currencyCode: 'CurrencyCode' total_price as TotalPrice, @ Consumption.valueHelpDefinition: [{entity: {name:' Iwithin CurrencyCurrencyThe element: 'Currency'}}] currency_code as CurrencyCode, @ UI.identification: [{position: 60, label:' Remarks'}] description as Description, @ UI.hidden: true last_changed_at as LastChangedAt}

You will notice that this projection view contains a lot of @ UI annotations, just like Fiori Elements, which acts as metadata to tell the corresponding rendering framework how these fields should be rendered on Fiori UI at runtime.

(3) now that Core Data Service, one of the three pillars, is in place, let's create a Business Service based on the projection view obtained in the previous step. Select projection view, right-click New Service Definition:

The first record of this service definition is to expose the projection view ZC_TRAVEL_JERRY through the ABAP expose keyword, and the model name is TravelProcessor:

@ EndUserText.label: 'Service Defintion for ZC_Travel_JERRY'define service ZUI_C_TRAVEL_JERRY {expose ZC_TRAVEL_JERRY as TravelProcessor; expose / DMO/I_Customer as Passenger; expose / DMO/I_Agency as TravelAgency; expose / DMO/I_Airport as Airport; expose I_Currency as Currency; expose I_Country as Country;}

Then create a Service Binding based on this Service Definition, and you can simply understand Service Binding as an instance of Service Definition:

After the Service Binding is created, click Activate to activate:

The model TravelProcessor that was previously exposed and specified with the expose keyword in Service Definition is now visible. Double-click:

Double-click will automatically open a link, a Fiori application will appear in front of us. Without one line of JavaScript web programming, we got a professional Fiori application that supports advanced search and can view the contents of the underlying database table ZTRAVEL_JERRY.

(4) so far, we have understood the first two pillars of the Restful ABAP Programming model, and there is still Behavior Definition. Since RAP's slogan is to build applications with Restful features, so far we haven't felt RAP's support for Restful, which needs to be done by Behavior Definition.

Select the CDS view you created earlier and create a new Behavior Definition:

The implementation type is specified as Managed:

We can see that some new ABAP keywords have been added to the definition of Behavior Definition. This Behavior Definition is responsible for defining the Transaction Behavior of the underlying model, that is, create,update,delete from lines 18 to 20.

Of course, add, delete, change and check the function light definition is not good, but also have to create its corresponding implementation. The name of the ABAP class that implements these behaviors has been specified as ZCL_BP_I_TRAVEL_M_JERRY. ZCL_BP_I_TRAVEL_M_JERRY in the Definition above. To do this, right-select New Behavior Implementation:

Create this special ABAP implementation class:

In this implementation class, there is no need for developers to manually write code to add, delete, modify and query the underlying database tables-since it can be called a programming model, these common functions are uniformly completed through the framework class CL_ABAP_BEHAVIOR_HANDLER, and application developers only need to define a declaration for this class.

Activate all the Behavior Definition model and its implementation created in this step, and then return to the Fiori application opened in our previous browser, refresh, and you will find that there are two more buttons, Create and Delete, which means that the application's support for creation and deletion is also available automatically.

This is the end of the content of "how to use Restful ABAP Programming model to open Fiori application". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report