Additional Blogs by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
thomas_weiss
Active Participant


SAP NetWeaver Enhancement Package 2 for SAP NetWeaver 7, which is delivered with Enhancement Package 5 of SAP ERP, brings a whole series of new ABAP Language features that make application development easier and more powerful.

In this weblog I will present the new ABAP Language features, enhancements that we think make an already strong language even better. These include the following:

  • A new data type, DECFLOAT, that combines the advantages of the classic data types p and f.

  • Secondary indexes for internal tables make for a high performing access by non-primary key fields

  • Embedded expressions, so that you can write compact statements with expressions at operand positions, as you can in C or Java

  • The new string templates for more efficient and comfortable string processing New ways to comfortably process strings,

  • Resumable exceptions,

  • code completion in the ABAP editor

  • the source-code based editing option for global classes

  • nested enhancements in the Enhancement Framework.

  • And many other new features and extensions


Let me now present you the new features and the problems they solve in some more detail.

The New Decfloat Data Type


The Situation Before


Before SAP NetWeaver Enhancement Package 2 you had the choice between type p (packed) and type f (floating point number). The trouble with type p was that it calculated exactly, but its range was limited. If you needed a larger range, you needed to use the floating point number data type.

In principle type f was not so bad for business programming insofar as it had a large range. Unfortunately it calculated in binary mode and sometimes this could lead to inappropriate, that is, incorrect results:

  • The decimal rounding and moving of decimal place could cause errors

  • The results of calculations could depend on database and platform.


For example let us have a look at the following calculation:
DATA float TYPE f.  
float = 805 / 1000.


The result of this is under some conditions 8.0500000000000005E-01 which, of course is not correct.

What Is New With SAP NetWeaver Enhancement Package 2

The new decfloat ("decimal floating point number”) data type combines the advantages of both data types f and p while avoiding their respective drawbacks. It calculates as exactly as p on a larger range than f. It comes two you in two flavors:

  • Decfloat16: 8 bytes, 16 digitsexponent -383 to +384 (range 1E-383 through 9.999999999999999E+384 )

  • Decfloat34: 16 bytes, 34 digits, exponent -6143 to +6144 (range 1E-6143 through 9.999999999999999999999999999999999E+6144)


It is based on the standard IEEE-754r.

You’ll probably want to know when to use this new data type and under which conditions you could still use the classic data types: To sum up the situation as it is with the new decfloat data type, let me just say: If operands and result of a calculation are whole number and the domain of p is not sufficient, use decfloat. The same applies to situations in which you need a fixed number of decimal places and the domain of p is not sufficient. In general, f is no longer recommended for business calculations. If you still want to use type f you should use the new keyword EXACT that forces an exception if the rounding leads to an incorrect result as I show in the example.


Secondary Keys for Internal Tables


The Situation Before


Before SAP NetWeaver Enhancement Package 2 you had only one (primary) key for an internal table which could be either unique or non-unique.

 

Optimizing the key by choosing a SORTED and or HASHED key speeded up only one access path. For all other ways to access the data from an internal table that used other criteria than those specified in the primary key you had only the standard access, which meant a full table scan. Unfortunately such a full table scan could be terribly slow: The time needed for such an access increased linearly with the number of rows as shown in the figure:



 

What Is New With SAP NetWeaver Enhancement Package 2


As of SAP NetWeaver Enhancement Package 2 you can now define additional secondary keys for an internal table. In fact, you can use up to 15 secondary keys for one internal table. These secondary keys come in different flavors:

SORTED UNIQUE KEY

SORTED NON-UNIQUE KEY

HASHED UNIQUE KEY.

In contrast to reading data from the database there is no optimizer which chooses the best key for a particular search operation, but you have to define yourself in the relevant statement (LOOP, READ …) which key should be used by the system.

Of course, every secondary key has to be created and updated by the system. To keep the update costs low, all non-unique secondary keys have a so-called lazy update behavior. This means the secondary index is only updated when the next access that reads data is performed. In contrast, unique secondary keys are updated each time the table is changed.

This means for you that you should be restrictive in using secondary unique keys. In general, as already mentioned each secondary key needs memory and has its creation and update costs. Given this, it is a good rule to use secondary indexes for tables that are seldom updated and often read.

The figure shows you how in a simple example how to use and how to take advantage of the new secondary key


Embedded Expressions


The Situation Before


Before SAP NetWeaver Enhancement Package 2 arithmetic and binary expressions were only allowed in COMPUTE statements, and logical expressions were only allowed in control statements (IF, WHILE, …). Embedded functions and functional methods as operands were only allowed in a limited number of cases.

All these restrictions meant for you as a developer that your code got more and more complex and unreadable because you needed to use auxiliary variables.

Instead of using an embedded expression EM in a statement T you had to

  • define an auxiliary variable AU

  • Add a calculation in an additional statement that moved the result of the calculation in the auxiliary variable AU , and

  • use this auxiliary variable in the final statement T. Resorting to this necessary strategy often increases the number of lines of code, and it makes many statements difficult to understand or debug, because you always have to search for the line in which the relevant auxiliary variables are filled.


What Is New With SAP NetWeaver Enhancement Package 2


In general, expressions can be used as operands

  • Arithmetic, binary, and string expressions

  • Many new embedded functions (in particular, string functions)

  • Chained method calls are now possible


You can make your code leaner and more elegant by using "in-place” expressions.

Let us have a look at some examples that show you to which large extent the new expressions in ABAP make your life easier:


String Processing


The Situation Before


Before SAP NetWeaver Enhancement Package 2 string processing in ABAP meant a lot of work, you could even say it was to some extent quite painful. Surely, there were some basic statements like

FIND SUBSTRING|REGEX, REPLACE SUBSTRING|REGEX, CONCATENATE, SPLIT, ...

There were the logical existence operators like

CS, NS, CA, NA, CP, NP

And a few embedded functions such as

strlen(...), charlen(...), ...

You had access to a substring by offset and length

... text+off(len) ...

On the whole you could say, string processing was possible, but it was no fun.

What Is New With SAP NetWeaver Enhancement Package 2


With SAP NetWeaver Enhancement Package 2 you have quite a lot of options to comfortably and efficiently process strings in ABAP. There is a new operator for concatenation (operator &&), and there are a great deal of new embedded string functions like distance, condense, concat_lines_of, escape, find, find_end, find_any_of, find_any_not_of, insert, repeat, replace, reverse, segment, shift_left, shift_right, substring, substring_after substring_from, substring_before, substring_to, to_upper, to_lower, to_mixed, from_mixed, translate. There are also new predicate functions for strings such as

contains, contains_any_of, contains_any_not_of

In addition, the new string templates are a tremendous help to all those of us who need to create, process and/or format strings. A character string template can create a character string from literal text, embedded expressions, and control characters in a character string expression. Let us have a look at an example that shows how easy formatting of complex strings is with these new string expressions:


Resumable Exceptions


The Situation Before


Before SAP NetWeaver Enhancement Package 2 it was not possible to recover from the situation that caused an exception and to then continue in the context in which the exception was raised. When the exception was propagated along the call stack the context of the original exception was destroyed and was not available after the exception was caught and handled in another context somewhere up in the call stack. It was also not possible just to write a log that something had gone wrong and then continue the original task. Raising an exception and propagating it deleted the context in which the exception was raised and in this way stopped the original flow of control.

What Is New With SAP NetWeaver Enhancement Package 2


It is now possible to resume processing in the context in which an exception was raised, exactly in the line after the line in which the exception was raised. If the CATCH statement has the addition BEFORE UNWIND the context of the exception is kept and can be accessed when the CATCH statement is processed. It is only after the CATCH block is processed that the context of the exception is deleted.

You can resume the exception at the position where it was raised if a number of conditions are fulfilled:

  • The context is not deleted (CATCH BEFORE UNWIND)

  • The exception is raised with the addition RESUMABLE

  • The exception is declared in the interface of the method/function module as RAISING RESUMABLE


Using resumable exceptions lets you, for example, raise an exception and just write an entry in a log file in case something goes wrong. In the example in the next figure we repair the error and resume processing after the exception.

 

 


Nested Enhancements


The Situation Before


As of SAP NetWeaver 7.00 you can enhance SAP objects using the new Enhancement Framework. To do so you could either implement implicit or explicit Enhancement Points. But it was not possible to enhance an enhancement such as, for example, a source code plug-in. It was not possible to add an enhancement to IS specific code that was itself a source code plug-in.

What is New With SAP NetWeaver Enhancement Package 2


As of SAP NetWeaver Enhancement Package 2 you can create nested enhancements. You can either create explicit enhancement points and sections in enhancement implementations and implement them or you can use implicit enhancement points in source plug-ins. There are now implicit enhancement points at the beginning and end of every enhancement implementation.



There are quite a number of use cases for nested enhancements. Customers can add enhancements into IS specific code. Customers or partners can enhance Add-ons of lower layers that are realized in enhancements. If a customer himself needs several layers of enhancements he can, for example add the enhancements that are needed in the whole company in one layer and then add additional enhancements on top of this layer to create functionality that is only needed by specific country departments.

Code Completion and the Source-Code Based Editor in the Class Builder


Before SAP NetWeaver Enhancement Package 2


As of SAP NetWeaver 7.00 there was a limited code completion that was mainly restricted to key words.

In the Class Builder you could only work in the classic form-based mode. It was not possible to see the whole code of a class, that is the code of all methods, on one page. The next figure shows you what was possible before SAP NetWeaver Enhancement Package 2.


What Is New With SAP NetWeaver Enhancement Package 2


EHP2 brings you a code completion capability that is similar to what you may have encountered in state-of-the-art editors of other programming languages.

The example in the next figure shows you the code completion for a function module:



With the new source-code based editing capability in the Class Builder you can toggle between the classic form-based view and a new code-based view:


And Even More Features in SAP NetWeaver Enhancement Package 2


There are a lot more new features and enhancements in theABAP language in EHP2. I will just mention a few of them here.

You can now use a dynamic WHERE clause for internal tables. This way you can avoid the expensive dynamic creation of programs. The syntax for those dynamic where clauses is just the same as what you are used to in Open SQL.



With boxed components you can store structures on the heap. This means that storing boxed components works like the storage of strings and internal tables. The memory is allocated when it is needed, that is, when the components are filled with values. Before this point, there is only a very low memory consumption. In fact, before a boxed component is filled with data, the initial data consumption is only the space needed for the address of the data space where the values of the boxed component are to be stored. The access to boxed components works just like the access to any other data object. But remember: Boxed components are deep data objects.



 

There is now a RETRY-Statement for exceptions. If this statement is processed in the CATCH block of an exception the whole TRY block is processed again.



 

With the new UML functionality you can easily present class diagrams (function modules are shown as classes). The diagrams reflect inheritance, interface composition, dependencies, friendship, exceptions, and events. And the whole is configurable. This means you can choose which detail level you want to see from a lightweight diagram to a full blown view with all details.



You want to create classifications of your own of development objects, where the classification is based on new metadata you can define as you like? No Problem, just use the new Classification Tool .



 

And there are many more features I can only mention here in this weblog:

Locators, streams, a new splitter control for the classic SAP GUI, short strings, an ABAP method call in Simple Transformations, 12 hour time format, basXML, a service class to create UUID, enhancements for Shared Objects, pragmas, new methods of the RTTC, a new background RFC, and a local data queue.

Summary


I hope this weblog has convinced you that SAP continues to invest heavily in ABAP. You probably have some ideas about

  • how you can increase the performance of your applications by using secondary indexes for internal tables

  • how you can make your calculations more exact and efficient by using the new decfloat data type, and

  • how easily you can, for example, create dynamic HTML pages using the new string templates.


Of course, this weblog cannot give you more than a first impression of these new features. But we wanted to give you some idea of what is new in the ABAP language, the Enhancement Framework and the ABAP Workbench with SAP NetWeaver Enhancement Package 2 and of how you can develop more efficiently by using these new features.

32 Comments