Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
Showing results for 
Search instead for 
Did you mean: 

Inspired by the Ruby on Rails Active Record, I started to work on an idea to replicate the concept of Active Record in SAPUI5. This post it to present that idea to community and get feedback. So comments are welcome.

I published entire project at Github and pull requests are very welcome as well.

Note: I spend some time thinking if it’s fits better here or on ABAP Development community. Then I decide to write two posts. If you want to see the project from ABAP perspective, check this blog, otherwise keep reading.


Imagine that you need to retrieve some records for a given sales order type from VBAK table. Later in the program you need to retrieve a set of materials from MARA table. Then some company code details from T001 table. Then deliveries from LIKP table. If you are using SAP Gateway, you need to create a service or entity type for each one of those requests.

In order to avoid to create a new SAP Gateway service or entity type/set for simple retrieval records from SAP tables, the ABAP Active Record give direct access into the SAP tables in a very simple way.

It’s not the goal of this project to replace all programming at back-end, but avoid create new SAP Gateway objects just for some “incidental” table access.

How It Works

Suppose you need to retrieve all prices for flights of Lufthansa (LH) and connection 2402 from SFLIGHT table.

First, in SAPUI5 code create ABAP Active Record object:

var oARModel = new abapActiveRecord.ARModel();

Then, retrieve a data set (JSON) from ABAP Stack, choosing table, fields and filter

var oFlightsTable = oARModel.aarGetEntitySet('SFLIGHT', ["CARRID", "CONNID", "FLDATE", "PRICE"], {carrid: "LH", connid: "2402"});


Here is the JSON Model returned by aarGetEntitySet method call above:

{"SFLIGHT":[ {"CARRID":"LH","CONNID":"00002402","FLDATE":"08/21/1997","PRICE":"555,00"},



{"CARRID":"LH","CONNID":"00002402","FLDATE":"08/30/1997","PRICE":"485,00"} ]}

Repeat the same procedure for any other SAP table (SPFLI, MAKT, BKPF, T001W etc.). No auto-generate code is necessary. Just call proper methods with proper parameters.

CRUD Methods

It’s also allowed to execute the CRUD (Create, Read, Update and Delete) methods.


Create a record on SFLIGHT table:

oARModel.aarCreate('SFLIGHT', {carrid: "LH", connid: "2402", fldate: "20160119", price: "500.00"});


Retrieve a set of records:

var oFlightsTable = oARModel.aarGetEntitySet('SFLIGHT', ["CARRID", "CONNID", "FLDATE", "PRICE"], {carrid: "LH", connid: "2402"});

The JSON model will be like bellow:


"{"SFLIGHT":[{"CARRID":"LH","CONNID":"00002402","FLDATE":"08/21/1997","PRICE":"555,00"}, ... ]}"

Read Simple Value (SELECT SINGLE)

Read a single value from a specific record at table SFLIGHT (select single):

var value = oARModel.aarGetEntity("SFLIGHT", "PRICE", { carrid: sap.ui.getCore().byId("carrid").getValue(), connid: sap.ui.getCore().byId("connid").getValue(),fldate: sap.ui.getCore().byId("fldate").getValue() });

Return the actual value of field PRICE in to variable value , "500.00".


Update a record on table SFLIGHT:

oARModel.aarUpdate("SFLIGHT", {carrid: "LH", connid: "2402", fldate: "20160119", price: "350.00"});

New value of PRICE: "350.00".


Delete a record on table SFLIGHT:

oARModel.aarDelete('SFLIGHT', {carrid: "LH", connid: "2402", fldate: "20160119"});

Under the Hood

In the SAPUI5 side, I extended sap.ui.model.odata.ODataModel class and implemented methods for basic CRUD operations and return data in JSON format.

Those methods basically will parse all parameters in the CRUD methods above and create batch calls to be submitted to SAP Gateway.

The second main responsibility is “translate” the return from SAP Gateway:











To JSON format:

{"SFLIGHT":[ {"CARRID":"LH","CONNID":"00002402","FLDATE":"08/21/1997","PRICE":"555,00"}, {"CARRID":"LH","CONNID":"00002402","FLDATE":"08/22/1997","PRICE":"590,00"}, {"CARRID":"LH","CONNID":"00002402","FLDATE":"08/25/1997","PRICE":"490,00"}, {"CARRID":"LH","CONNID":"00002402","FLDATE":"08/30/1997","PRICE":"485,00"} ]}


You can find installation instructions in this guide.


I started this project to share my idea and the initial proof of concept. I’m not consider ready to be used in production and improvements are needed. However, in the pure open source spirit, I decided to share my idea and receive feedback from the community.

Labels in this area