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!
cancel
Showing results for 
Search instead for 
Did you mean: 
furlan
Participant

We in ABAP world used to have everything handy. Access some information in any table, SELECT and done. Update? Done. Use some global class, done. It's not even necessary any "require" or "include" command. It's there. Just use it!

However, in my very first days working with SAPUI5 I saw that the life is not so easy outside of ABAP stack. Thinking in how I could make the UI5 developer easy, I started to working in the ABAP Active Record project. It's a open source project project shared in Github to replicate the Active Record that I know from Ruby on Rails. The objective of this project is to provide a way to UI5 devs access SAP tables at ABAP stack in a very easy way.

This blog is to give an ABAP perspective to community. You can find more information on my blog at SAPUI5 community. Please check there how to use and how it works in SAPUI5.

Note: It's already in my future road map to use ABAPGit.

SAP Gateway

It’s only necessary to create one generic service at SAP Gateway that will respond all requests for any table!

There are two entity types: request and result, with their entity sets.

  • request is responsible to receive all information about database operation, like table name, fields to be selected and filter conditions.
  • result is responsible to process all information entered using resquest calls and execute desired operation.


The whole transation is executed using batch processing.var oFlightsTable = oARModel.aarGetEntitySet('SFLIGHT', ["CARRID", "CONNID", "FLDATE", "PRICE"], {carrid: "LH", connid: "2402"});For example, for the aarGetEntitySet method call above, it’s necessary follow requests:

  • first request (POST method) call to pass operation and SAP Table name;
  • 4 request (PUT method) calls to pass all 4 fields to be retrieved;
  • 2 request (PUT method) calls to pass 2 filter conditions and
  • last result (GET method) call to retrieve all information from database selection.

It’s necessary 8 requests in total for this example called in the same transaction (batch).

Here is the return of result entity set method:

<model>SFLIGHT</model>

<field>CARRID</field>

<value>LH</value>

<model>SFLIGHT</model>

<field>CONNID</field>

<value>2402</value>

<model>SFLIGHT</model>

<field>FLDATE</field>

<value>08/21/1997</value>

...

ABAP

In ABAP side, I implement proper methods for very dynamic Open SQL calls. For more information, you check the ABAP methods implementation.

Here is the list of methods implemented in ABAP in order to process database retrieval:

  • REQUESTSET_CREATE_ENTITY

Called in the begginig of all transactions. It’s responsible to define the table name and operation.

  • REQUESTSET_UPDATE_ENTITY

Receive all parameters to build dynamic database operation.

  • RESULTSET_CREATE_ENTITY

Used in aarCreate method (PUT) and execute INSERT SQL command.

  • RESULTSET_DELETE_ENTITY

Used in aarDelete method (DELETE) and execute DELETE SQL command.

  • RESULTSET_GET_ENTITY

Used in aarGetSingleValue method (GET) and execute SELECT SINGLE SQL command.

  • RESULTSET_GET_ENTITYSET

Used in aarGetEntitySet method (GET) and execute SELECT SQL command.

  • RESULTSET_UPDATE_ENTITY

Used in aarUpdate method (PUT) and execute UPDATE SQL command.

Sequence Calls

Just as an example, here is the sequence of calls necessary to retrieve a set of records for SFLIGHT table:var oFlightsTable = oARModel.aarGetEntitySet('SFLIGHT', ["CARRID", "CONNID", "FLDATE", "PRICE"], {carrid: "LH", connid: "2402"});All calls bellow are result of a batch request from SAPUI5.

  1. Call REQUESTSET_CREATE_ENTITY to start the processing and define some parameters.
  2. For each field in the list (i.e. ["CARRID", "CONNID", "FLDATE", "PRICE"]) callsREQUESTSET_UPDATE_ENTITY and store all values in an internal table.
  3. For each property in the object (i.e. {carrid: "LH", connid: "2402"}) callsREQUESTSET_UPDATE_ENTITY and store all filters to be used in WHERE clause in an internal table.
  4. At the end of processing, call RESULTSET_GET_ENTITYSET to execute the dynamic SELECT command and return the entityset with a list of all fields.

Here is the list on parameters internal table for the method call above:

Filter Internal Table

Based on that parameters dynamic select is called like bellow:

* --- all dynamic retrieve

TRY.

  SELECT (it_fields) INTO TABLE <dyn_table> FROM (me->ddic_table) WHERE (it_where).

CATCH cx_root.

  RAISE EXCEPTION TYPE /iwbep/cx_mgw_tech_exception.

ENDTRY.

Feedback

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.

6 Comments
Labels in this area