This article, by Karl Kessler and published in SAP Insider, goes into the latest enhancements in the ABAP world. There is a health warning on this – it is quite technical.
Some of the most significant innovations in SAP NetWeaver 7.5 — the latest iteration of SAP’s well-known technology and integration platform — are in the ABAP programming model. This article looks at a set of particularly useful features available with ABAP 7.5, including new ABAP language features for enabling more concise code and enhancements that further optimise ABAP application development for SAP HANA, such as new features for developing SAP Fiori front ends based on core data services (CDS) and a new tool for debugging ABAP-managed database procedures (AMDPs).
SAP NetWeaver 7.5 — unveiled in October 2015 at SAP TechEd in Las Vegas — is the latest iteration of SAP’s well-known technology and integration platform for SAP environments. It is the logical continuation of the widely adopted SAP NetWeaver 7.4, and serves as the on-premise foundation for SAP Business Suite (as of the planned enhancement package 8 for SAP ERP 6.0) and the on-premise edition of SAP Business Suite 4 SAP HANA (SAP S/4HANA). Its enhancements include support for emerging technologies such as the Internet of Things (IoT), expanded support for SAP HANA, enhanced integration with cloud-based and mobile environments, support for Java 8, and a new, common ABAP codeline for delivering the same innovations across on-premise and on-demand editions of solutions such as SAP S/4HANA.
Some of the most significant innovations in SAP NetWeaver 7.5 are in this new codeline, especially in the ABAP programming model within SAP NetWeaver Application Server (SAP NetWeaver AS) ABAP. This article focuses on a set of particularly useful features included with ABAP 7.5, including new ABAP language features for enabling more concise code and enhancements that further optimise ABAP application development for SAP HANA, such as new features for developing SAP Fiori front ends based on core data services (CDS) and a new tool for debugging ABAP-managed database procedures (AMDPs).
The ABAP language has always evolved to keep pace with changing requirements for modern development languages — for example, past releases added object-orientation and Open SQL features that work closely with ABAP internal tables.
To meet the need for simplicity in modern applications designed for complex requirements, SAP NetWeaver 7.4 introduced several innovations for ABAP, including enhancements that make it easy to write very compact ABAP code using expressions. Let’s look at how this might work. The left side of Figure 1 shows a procedural code excerpt that defines a work area called wa1 and an internal table it1 that contains multiple line items, just like the work area. Two lines are then added to the internal table with the INSERT statement. Next, the field symbol is used to loop over the internal table to create a second internal table called it2. Finally, a record is read from internal table it1, which has key field a set to 3, assigning the field symbol that is used as a parameter to a method call.
Figure 1 — ABAP expressions enable compact, concise procedural code
The right side of Figure 1 shows how this procedural code can be very compactly written using ABAP expressions. First, the internal table is initialised with the VALUE operator. Next, the second internal table is created with the VALUE operator implicitly looping over it1. Finally, an object reference class1 is created with a NEW operator and the method do_something is invoked using the b field of internal table it1 at key field a set to 3. This example shows how ABAP 7.4 is far more compact compared to the more verbose style of previous releases. With ABAP 7.5, these expressions have been extended further. ABAP 7.5 includes support for type inference, where the type of a variable is determined based on the logic evaluation of the expression — see the DATA(it1) declaration shown on the right in Figure 1, which declares a variable it1 whose type is determined by the evaluation of the VALUE tt1(…) expression. It also supports type inspection operators, such as INSTANCE OF and CASE TYPE OF, which can be used to query the type information of a variable during runtime.
In addition to new features for expressions, ABAP 7.5 includes several other ABAP language enhancements. It introduces a new data type (INT8) that enables eight-byte integers, which helps in big data scenarios by extending the number range significantly. It also enables T100 error messages to be raised using class-based exceptions, which makes it easier to handle exceptions on a higher level. And “test seams” are a new feature that help make unit testing easier by enabling the replacement of a block of production code by a block of test code when unit tests are executed (when test runs depend on existing database records, for example).
CDS1 is a feature of the Eclipse-based ABAP development tools for SAP NetWeaver (known as ABAP in Eclipse). It is an infrastructure for defining and consuming data models — represented in ABAP as CDS views, which provide access to the data represented in the model — on the SAP HANA database rather than on the ABAP server. Introduced with SAP NetWeaver 7.4 SPS 05, CDS includes a variety of features to support modern development, including support for SAPUI5 (SAP’s interpretation of the HTML5 standard) to enable the development of responsive and elegant SAP Fiori applications.
SAP NetWeaver 7.5 builds on these capabilities with several new enhancements for CDS. You can now use associations, which define the relationships between CDS views and other tables and views they reference, when extending SAP standard CDS views. You can also embed table functions into CDS views that call ABAP-managed database functions that return fields and table values for SAP HANA-specific breakout scenarios (similar to ABAP-managed database procedures for managing procedures in ABAP that execute in SAP HANA). Another new feature is the data control language (DCL), which allows you to add authorisation checks that reflect your transaction PFCG role profiles when accessing CDS data.
To better understand the potential of CDS in ABAP 7.5, and to see how easy it is to build attractive SAP Fiori user interfaces on top of CDS, let’s walk through a simple, practical example that highlights two particularly useful new features: an intuitive graphical modeling tool and the ability to easily expose CDS views as services for consumption by SAPUI5. We will build a simple sales order application using the SAP Web IDE, a browser-based development environment available with SAP HANA Cloud Platform for rapidly developing SAP Fiori applications.2 Sales orders are common SAP objects that consist of sales order headers and positions (order line items typically represented by a product or quantity); business partners, such as customers who have posted the sales order; and invoices that will be sent to the customer once the sales order is fulfilled.
First, we’ll look at the CDS data model that we’ll use for the example SAP Fiori application. To access the CDS view, launch ABAP in Eclipse and log on to an ABAP 7.5 back-end system (H74 in the example). On the left side, displayed in the Eclipse project explorer (see Figure 2), is the usual ABAP project structure, which contains your favorite ABAP packages and their associated data definitions based on CDS. On the right side is the DDL editor, where you can see the source code for the sales order CDS view (ZDDLS_DEMO_EPM_I_SALESORDER). Comments preceded with the @ symbol are CDS annotations, which provide semantics and interpretation — for example, field labels for the user interface that are used to quickly prototype screens. Here, we’ll focus on the CDS view itself.
Figure 2 — A CDS view displayed in the DDL editor
The CDS view is based on a left outer join between the sales order table (snwd_so) and the business partner table (snwd_bpa). Next, you see the list of associations, prefixed with an underscore to distinguish them from value-oriented fields: business partner (_Customer); the contact person (_CustomerContact); the invoice (_Invoice); and the sales order items (_Item). Then you see a list of result columns that make up the view, such as sales order ID and key; customer ID; gross, net, and tax amount of the order, including the currency; sales order status; and creation and change date. Press the F8 key to display the results of this view in the data browser (Figure 3).
Figure 3 — The result set generated by the example CDS view
From the data browser, you can follow the associations (see Figure 4) to their related entities, such as business partner or sales order items, for testing and analysis purposes. You can also display the contents of the table or view referred to by an association, such as the related sales order items (Figure 5) or customer (Figure 6).
Figure 4 — Following CDS associations in the data browser
Figure 5 — The contents of the associated sales order items table
Figure 6 — The contents of the associated customer information table
SAP NetWeaver 7.5 also includes a new CDS graphical modeler tool that shows a graphical representation of the CDS view, the underlying base table, and associations (see Figure 7), to enable a quick and easy understanding of the view and its relationships to other views.
Figure 7 — The CDS graphical modeler provides a graphical rendering of CDS view implementations
To use the CDS when we build our simple SAP Fiori application with the SAP Web IDE, we need to expose the CDS view as a service using the OData protocol3 so that SAPUI5 can consume the CDS data. To enable these OData services with ABAP 7.4, you had to create complex SAP Gateway implementations using transaction SEGW. ABAP 7.5 provides a much easier way: We simply specify the annotation @OData.publish: true in the source code using the DDL editor. The corresponding OData service is automatically generated for SAP Gateway and can be inspected in the technical properties by pressing the F2 key (see Figure 8). Clicking on the OData-Service link included in the technical properties displays an XML document describing the SAP Gateway service (see Figure 9). We will use this service when building our SAP Fiori application based on SAPUI5 using the SAP Web IDE.
Figure 8 — The generated SAP Gateway service displayed in the CDS technical properties
Figure 9 — The XML document describing the generated SAP Gateway service
The SAP Web IDE is SAP’s web-based development environment for SAPUI5-based development, and it is particularly well suited to quickly developing SAP Fiori applications. Available via SAP HANA Cloud Platform,4 it uses a multi-tabbed editor environment with a project navigation tree on the left, a workspace tab on the right, and menus and sidebar tools (see Figure 10).
Figure 10 — The SAP Web IDE development environment
To create our simple SAP Fiori application, we’ll use the SAP Web IDE project wizard (see Figure 11). This wizard offers many different UI templates for SAP Fiori development. For our simple example, we’ll use the SAP Fiori Master Detail Application template, which creates an SAP Fiori application that displays data from an OData service in a master-detail pattern (see Figure 12). The screenshot on the right of the template selection screen previews the layout of the application based on the selected template, where the master section (the white bar on the left) contains a list of records and the detail section on the right provides information for a selected record.
Figure 11 — Launching the SAP Web IDE project wizard
Figure 12 — The SAP Web IDE project wizard template selection screen
First, we specify a project name (kk100 in the example), which serves as a container for all the required SAPUI5 artifacts (see Figure 13). Next, we specify a connection to a back-end system (see Figure 14). We use the same back end that was visible in ABAP in Eclipse (H74 in the example). After logon, the system responds with the list of available OData services that can provide the source data for our application, and we select the sales order CDS from the list (see Figure 15). The system expands the display to include the top-level OData artifacts for the chosen service, but we can disregard these for our purposes here.
Figure 13 — Specify a project name for the application
Figure 14 — Specify a connection the ABAP backend system
Figure 15 — Select the CDS service to provide the source data for the application
Next, we start to populate the master section of the template (see Figure 16). We choose the OData collection zdev201_sales_order, which corresponds to our CDS view, and we assign the other master fields, such as sales order ID, gross amount, and transaction currency (see Figure 17). Then we populate the detail section with fields for the delivery status of the order, net amount, and tax amount, including currency, and we specify the navigation section using the OData navigation property to_Customer along with the value fields BP_ID (business partner ID), BP_ROLE (business partner role), and COMPANY_NAME (see Figure 18). The template offers 1:1 associations from the CDS view, meaning you can pick and choose fields from any master records referenced in the associations available with the view.
Figure 16 — Select the OData collection to use for populating the template
Figure 17 — Populate the master section of the template
Figure 18 — Populate the detail and navigation sections of the template
With all of the fields specified, we can generate the project, which creates an SAPUI5 project outline in the SAP Web IDE project navigation tree, with all the required artefacts (see Figure 19). To load the completed master detail application, select the Run menu item, which previews the application in a browser (see Figure 20). As specified by our template selections, the application contains sales order ID and gross amount in the master section on the left, and net and tax amount plus delivery status, represented by the character “D” under the amount, in the detail section on the right. Clicking on the navigation icon ( ) in the detail section displays the business partner information (see Figure 21).
Figure 19 — The source code for the generated project
Figure 20 — The master detail application previewed in an browser
Figure 21 — Using the navigation icon to display the business partner information
When it comes to creating an SAP Fiori application, the biggest improvement in SAP NetWeaver 7.5 is the ability to easily expose OData services without the need to develop complex SAP Gateway implementations. In addition, more sophisticated templates (called smart templates) have been added to the SAP Web IDE that come with many pre-built interaction capabilities such as sorting, searching, and grouping, similar to the extensive functionality included with the ABAP List Viewer. All of this is also possible with SAP NetWeaver 7.4 and SAPUI5, but you would have to manually implement most of the functionality.
A very useful ABAP feature introduced in SAP NetWeaver 7.5 is Eclipse debugging support for AMDPs — a SQLScript-based framework introduced in SAP NetWeaver 7.4 (SPS 05) that allows developers to manage database procedures in ABAP just like standard ABAP classes while they execute in the SAP HANA database. AMDPs are represented by ABAP classes that implement the AMDP interface.
AMDP debugging was supported in SAP NetWeaver 7.4 SPS 05, but you had to work with two debuggers in parallel — the ABAP debugger for setting breakpoints on the ABAP level and the SQLScript debugger of the SAP HANA studio for setting breakpoints on the SAP HANA level — which is very cumbersome. In ABAP 7.5, you can debug the SQLScript code contained in AMDPs directly within the source code editor of ABAP in Eclipse as if it were ABAP code. Let’s take a look at an example to see how this works.
Figure 22 shows a list of ABAP classes representing AMDPs in the project explorer of ABAP in Eclipse. The source code editor displays the implementation of the ZCL_DEV201_CUSTOMER_INFO_201 class, with the SQLScript code marked in yellow. (The background color can be customized in your Eclipse font and color preferences.) By double-clicking on a source line, you can set a breakpoint (in the example, we set it at line 61 so that execution stops at the first SQL command), which is marked with a green circle. Now you can test the class by pressing the F8 key, which takes you to the test environment (Figure 23).
Figure 22 — Setting a breakpoint in the ABAP in Eclipse source code editor
Figure 23 — The debugger test environment
The test environment shows the outline of the ZCL_DEV201_CUSTOMER_INFO_201 class, including its interfaces, attributes, and methods. Here, we invoke the GET_CUSTOMER_INFO method, which displays basic information, such as the customer’s ID and name, and an aggregate of the gross amount of open orders, which requires some calculations carried out in the method GET_CURR_CONV_RELEVANT_ITEMS. Invoking this method displays a prompt for input parameters for the client and customer ID to identify a particular customer (see Figure 24). After specifying this information, switch back to the debug perspective in Eclipse and run the method by pressing the F8 key again.
Figure 24 — Specify the input parameters for the method
The Eclipse debugger halts in the SQLScript code at the location of the set breakpoint (see Figure 25).
Figure 25 — Hitting the set breakpoint
Now you can single step through the code, examine the variables and tables referenced in the method (see Figure 26), and then resume execution of the method until it returns its results (see Figure 27) — in the example, the record corresponding to the key (the customer ID in this example). You can then drill down into the details of this record and view the fields, for example, in order to display the customer name and the aggregated gross amount (see Figure 28).
Figure 26 — Examining the variables and tables referenced in the method
Figure 27 — Executing the method results in the location of a single record entry
Figure 28 — Drilling down into the details of the found record
Despite the comfort provided by this new debugging feature, bear in mind that AMDPs are encapsulations of SAP HANA-specific code. SAP’s recommendation is always to write portable ABAP code to ensure portability across database platforms, which is facilitated by CDS principles, and to only use AMDPs where absolutely necessary, such as in analytical scenarios where you also leverage other SAP HANA-only frameworks, such as geospatial and application function library frameworks. AMDPs are seamlessly managed on the ABAP layer, however, so when you do need to use them, you do not need to leave the ABAP level during design and runtime — and debugging.
SAP NetWeaver 7.5 includes many new features for developers that demonstrate the continued strength of the ABAP stack. The ability to write more concise code combined with state-of-the-art development tools that support SAPUI5 and SAP HANA makes it easy to build innovative applications with responsive SAP Fiori interfaces that can run on any device. A traditional development infrastructure facilitates easy-to-configure developer workplaces in widespread SAP solution landscapes, enabling effective application development for modern business needs.
Neil ran his first SAP transformation programme in his early twenties. He spent the next 16 years working both client side and for various consultancies running numerous SAP programmes. After successfully completing over 15 full lifecycles he took a senior leadership/board position and his work moved onto creating the same success for others.