Wednesday, October 2, 2013

&& | { [ ] } | ... Extended Expressions in ABAP 702

As per 7.0 EhP2 (702), you can use so-called ‘Extended Expressions’ when coding ABAP.

Nice nerdy topic today.

Even though this enables a more compact way of coding ABAP, and (sometimes) improves readability, it seems not to have been embraced by many. This of course makes perfect sense as we were able to do perfect ABAP coding without these new ‘tools’.



Why?

Usage of extended expressions enables cleaner coding. You can now for instance use calculations and method calls in logical expressions (basically calculate inside an if-statement or use the result of a methodcall inside an if statement).

Usage of extended expressions also allows more intuitive string operations such as
v1 = ‘abc’ && ‘def’


instead of
CONCATENATE ‘abc’ ‘def’ into v1.


 

Where to start?

The easiest way to find out the features as delivered by 702 is to start report (SE38) demo_expressions in your development system.

This transaction allows you to browse and even debug examples of the new features.

I would recommend to use the ‘Single View’, no Selection and ‘Small Window’ (unless you are blind).
F8 runs the report, and brings you to the index where you can select the different features.

Clicking one of the options shows you the details of the expression, for instance 6. Chained Method Call…

This might look like abracadabra, but the best is yet to come. In the top of the window are a few links, one of which is ‘Debug’. Click this and you will immediately get an insight into how the expression can be used in real life.


Nicely done and very useful. I would recommend all ABAP programmers to take a look at the new features when an upgrade to 702 has been done.


So, what do we get?


Some of the most popular new statements would be:

&& for concatenation

For instance: s1 = `abc` && `def`.

Use of ‘Chained method calls’, where you can call several methods in a single statement

For instance: i2 = 4 + lcl=>mref( in = 1 + 2 )->imref( 3 )->ai.

Use of calculations and method calls inside expressions.

For instance: MOVE-CORRESPONDING lcl=>mstr( str1 ) TO str2.

Use of String Templates

For instance: s1 = |A value: { sqrt( 9 ) / 2 }. Another value: { lcl=>mi( 2 ) }.|.

Use of built-in Localization

For instance: d1 = 20130110. s1 = |{ d1 country = 'US ' }| results in 10/01/2013

Use of built-in string operations

Such as SUBSTRING, SEGMENT, REPEAT, CONDENSE, TRANSLATE, BOOLC.

No comments:

Post a Comment