what is new in abap

18
What Is New in ABAP Language, ABAP Workbench, and Enhancement Framework With SAP NetWeaver 7.0 EhP2 Posted by Thomas Weiss in thomas.weiss on Apr 14, 2010 11:49:05 PM 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 digits exponent -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.

Upload: maxblank

Post on 25-Apr-2017

247 views

Category:

Documents


2 download

TRANSCRIPT

What Is New in ABAP Language, ABAP Workbench, and Enhancement Framework With SAP NetWeaver 7.0 EhP2 Posted by Thomas Weiss in thomas.weiss on Apr 14, 2010 11:49:05 PM

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 digits exponent -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.

TRY. COMPUTE EXACT result = 3 * ( 1 / 3 ). CATCH cx_sy_conversion_rounding

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.

5205 Views Average User Rating (9 ratings)

Comments

31 Comments

Timo JohnApr 15, 2010 12:47 AM

but it's not on the system I have to work on )-:

Thanks for nice POST!

Like (0)

Adam SzigetiApr 15, 2010 1:39 AM

I love these new stuff, thanks for the post!

Will we be able to express embedded selections, like

SELECT field1 field2 (SELECT field3 FROM table2 WHERE field4 = table1-field5

FROM table1

WHERE field6 = (SELECT field7 FROM table3)

?

Or at least use operands within the SELECT, like

SELECT (TRANSFORM field1 TO UPPERCASE)

FROM table1

?

Regards,

Ádá,

Like (0)

o

Adam SzigetiApr 15, 2010 1:43 AM (in response to Adam Szigeti)

I mean TRANSLATE field1 TO UPPER CASE, sorry

Ádám

Like (0)

David LeesApr 15, 2010 1:40 AM

Thank-you for this, very well presented/lovely blog.

Like (0)

Peter InotaiApr 15, 2010 3:03 AM

Hi Thomas,

Do you have any info about SAP ERP Ehp5 release schedule? I couldn't find anything in Marketplace, I guess it's still in ramp-up phase.

Thanks,

Peter

Like (0)

o

Markus KleinApr 16, 2010 2:16 PM (in response to Peter Inotai)

Well, unfortunately the ramp-up of EHP5 hasnt yet started :(

Like (0)

Peter InotaiApr 19, 2010 12:46 AM (in response to Markus Klein)

Hi Markus,

Thanks a lot for the info.

Do you have some source of official statement about this schedule? Because this is also what I found some forums, but nothing in

OSS note or Marketplace.

Unfortunately it also means, that there is no chance to try out this feature in the near future :(

Peter

Like (0)

o

Thomas WeissApr 21, 2010 1:18 AM (in response to Peter Inotai)

NetWeaver 7 EhP2

is available with PPM 5.0 that is in Ramp Up since the 19th of April and

will be available with EhP5 for ERP (Ramp Up planned for July this year).

Like (0)

Peter InotaiApr 21, 2010 1:22 AM (in response to Thomas Weiss)

Hi Thomas,

Thanks for the info.

Best regards,

Peter

Like (0)

Rajesh SalechaApr 15, 2010 4:00 AM

Nice to know such great amount of enhancements....

hope to use them soon...

Raj

Like (0)

Markus TheilenApr 15, 2010 5:13 AM

Hi!

Thank you for this compact overview of the new and exciting features!

Nice one to see generated UML diagrams, but will there also be a way to export the behind-lying model in XMI or another XML dialect ? So that one can

use this information in other UML tools like MagicDraw ?

Cheers, Markus

Like (0)

o

Thomas WeissApr 15, 2010 6:42 AM (in response to Markus Theilen)

There is a button in the tool to execute plug-ins. Using this button you can export the underlying model in XMI.

We have tested it for Altova UModel, Eclipse UML2 PlugIn and StarUML.

Like (0)

Markus TheilenApr 15, 2010 5:21 AM

Hi!

Nice and compact overview about the new features in EHP 2!

Will there also be a way to export the model behind the UML diagrams as XMI or another XML language ? This would be cool for further work in other UML

tools like MagicDraw.

Cheers, Markus

Like (0)

Peter InotaiApr 15, 2010 8:41 AM

Hi Thomas,

I believe classification tool is also available already with BASIS SP. At least in our system with SAPKB70019 the package check in SE80 is also available,

which is also classification tool based.

Is there any new functionality in Ehp2?

Peter

Like (0)

Zdenek StastnyApr 16, 2010 3:15 AM

Hi Thomas,

my company is now under upgrade of Enhancement Package 4 for SAP ERP and our dev system says now in System -> Status:

SAP_ABA 701 0005 SAPKA70105

SAP_BASIS 701 0005 SAPKB70105

So I think all these new features should work for us. But I tried to define a secondary index over an internal table as follows:

data spfli_tab type SORTED TABLE OF spfli

with NON-UNIQUE key cityfrom cityto

with UNIQUE hashed key dbtab_key

components carrid connid.

and it can't be activated. The error is:

>> The Dictionary structure "SPFLI" does not have a component called "WITH".

Doble click on the message navigates me to the second WITH word. Please what do I do wrong or do I understand incorrectly that we should have this in

our system?

Like (0)

o

Peter InotaiApr 16, 2010 4:43 AM (in response to Zdenek Stastny)

You need ERP Ehp5, Ehp4 is not enough:

"SAP NetWeaver Enhancement Package 2 for SAP NetWeaver 7, which is delivered with Enhancement Package 5 of SAP ERP".

I guess the BASIS patch level will look something like this then: SAPKB7020x.

Peter

Like (0)

Suresh DattiApr 16, 2010 7:24 AM

I like the seocndary indices for itabs & the embedded expressions. pretty cool.

Like (0)

Harald BoeingApr 17, 2010 2:52 AM

Thanks a lot for giving this nice update; I think lots of these like embedded expressions are features that are long overdue. Especially considering the fact

that lots of us will keep working on older systems, sigh...

In your section "Resumable Exceptions" you have sample coding (first if statement) that looks like we actually also get proper boolean support. Is that

true? I.e. can we now stop writing expressions like "if flag = abap_true" or did I even miss something and that was introduced already a while ago?

One comment though on the code completion. I think the keyword here really is "similar". Proper code completion really should also show the

documentation, though probably that would mean that it's empty in most cases (but might be an incentive to start proper documentation). JavaDoc is a

good example in my opinion.

Cheers, harald

Like (0)

o

Thomas WeissApr 19, 2010 2:03 AM (in response to Harald Boeing)

Unfortunately what you took for proper boolean support was actually a slip of pen in my figure. I have corrected it now the you referred to is

now: IF cl_helper=>get_filename_from_user(user_filename, ...)= ….

Thank you for looking so carefully at the figure. Up to now nobody had realized that there was something wrong.

Like (0)

Harald BoeingApr 19, 2010 1:21 PM (in response to Thomas Weiss)

Thomas, thanks a lot for the quick response. I got carried away hoping that this might be a "hidden bonus feature", but kind of

suspected that this doesn't exist (especially since the "Official ABAP Programming Guidelines" only reference ABAP_BOOL).

Please check also the WHILE statement in that example as the syntax seems odd...

Like (0)

Thomas WeissApr 20, 2010 7:11 AM (in response to Harald Boeing)

Again, thank you. It seems I also forgot some dots in the while statement. I have changed the figure accordingly.

Like (0)

Harald BoeingApr 17, 2010 3:01 AM

Completely forgot to ask in my previous post: What about the pretty printer. Are there any plans to create a true pretty printer? This would make writing and

reading programs so much easier. It's pretty awkward having to properly indent multiline statements and even worse to read coding from somebody who

had no consistent styling at all...

Cheers, harald

Like (0)

Phani R MullapudiApr 23, 2010 4:37 PM

Finally, we have the ability to hide Navigation panel in Interactive Adobe forms in WebDynPro-ABAP. WE wanted this feature desperately 10months back

in our project.

I even wrote to SAP requesting a way to do this.

Like (0)

Tony ShearsbyMay 6, 2010 12:52 AM

Hi Thomas, this was a first rate blog to summarise the new features inEhP2.

I think it's great (as you point out) to see SAP still 100% behind supporting ABAP, and also to see the incremental improvements to the programming

language to keep up to date without delivering too much to confuse experienced ABAPers.

It's not easy to illustrate the new features, but you have done it very clearly and concisely.

Many thanks indeed,

Tony.

Like (0)

Dirk BreuerMay 11, 2010 4:49 AM

Very good blog. I would like more of these

Like (0)

Sascha MinkMay 19, 2010 3:25 AM

Nice features but i'm still missing the "instance of" operator.

Looks like SAP is investing a lot in ABAP (again?).

Like (0)

Simon RotherhamJun 8, 2010 6:14 AM

A Good overview of the new features. Will be passing this on to the rest of my team.

Like (0)

christian GoerkeJun 24, 2010 4:08 AM

First I have to say thanks for the great posting.

I have read something about a new splitter control for the SAP-GUI.

Do you have any information about it?

Thanks

Christian

Like (0)

Marcos TavaresDec 20, 2010 9:28 AM

Hi...

Sorry... but how look my version netweaver?

Like (0)

Fabio PagotiFeb 6, 2011 8:12 AM

Wow!! Code completion!! Finally! The list only lacks of an editable ALV using SALV classes.

Like (0)

Martin PrinzSep 26, 2012 11:32 AM

Hi!

very nice article - is there something similar for EhP3 too?

thx,

Martin