Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
horst_keller
Product and Topic Expert
Product and Topic Expert


Release news for a support package? Yes. My last blog ABAP Language News for Release 7.40 was about 7.40, SP02.  SP02 came with kernel release 740. 7.40, SP05 is a bundled support package that comes with a new kernel release 741.  And a new kernel release means new ABAP language features.

Read this blog where I cover the most important language news for SP05 to learn why it makes sense to get 7.40, SP05 as soon as possible!

Internal Tables

MOVE-CORRESPONDING for Internal Tables

You can use MOVE-CORRESPONDING not only for structures but also for internal tables now. Components of the same name are are assigned row by row. New additions EXPANDING NESTED TABLES and KEEPING TARGET LINES allow to resolve tabular components of structures and to append lines instead of overwriting existing lines.


Example

MOVE-CORRESPONDING itab1 TO itab2 EXPANDING NESTED TABLES

                                  KEEPING TARGET LINES.

More About

http://help.sap.com/abapdocu_740/en/index.htm?file=abapmove-corresponding.htm

Expressions and Functions

LET Expressions in Constructor Expressions

New LET expressions as sub expressions of constructor expressions allow you to define local variables or field symbols as auxiliary fields of constructor expressions.

Example

LET expression in a table construction using the VALUE operator.

cl_demo_output=>new( )->write(

  VALUE text( LET it = `be` IN

                 ( |To { it } is to do|          )

                 ( |To { it }, or not to { it }| )

                 ( |To do is to { it }|          )

                 ( |Do { it } do { it } do|      ) ) )->display( ).

More About

http://help.sap.com/abapdocu_740/en/index.htm?file=abaplet.htm

CORRESPONDING Operator

The new constructor operator CORRESPONDING allows to execute  a "MOVE-CORRESPONDING" for structures or internal tables at operand positions. Besides assigning components of the same name you can define your own mapping rules.

Example

struct2 = CORRESPONDING #( struct1 MAPPING b4 = a3 ).

More About

http://help.sap.com/abapdocu_740/en/index.htm?file=abenconstructor_expr_corresponding.htm

Table Comprehensions


A new FOR sub expression for constructor expressions with operators NEW and VALUE allows to read existing internal tables and to construct new tabular contents from the lines read.

Example

Construction of an internal table itab2 from lines and columns of an internal table itab1. You can of course also use the CORRESPONDING operator to construct the lines.

DATA(itab2) = VALUE t_itab2( FOR wa IN itab1 WHERE ( col1 < 30 )

                             ( col1 = wa-col2 col2 = wa-col3 ) ).

More About

http://help.sap.com/abapdocu_740/en/index.htm?file=abentable_comprehensions.htm

Meshes

This one is a little bit tricky. Meshes are special structures whose components are internal tables, which can be linked to

each other using associations. Associations are evaluated by specifying mesh paths in suitable expressions and statements.The full power of meshes will become more clear in the monent when associations will be supported by Open SQL for database views (CDS views, see below) in the future.


Example

A mesh flights is declared from a mesh type t_flights. In t_flights you have tabular components as so called mesh nodes that are linked by associations. A structured data object root  is constructed to serve as the start line for the following LOOP over a mesh path. The results are lines from sflight that are found by following the mesh path evaluating the associations between its mesh nodes.

TYPES:
  t_scarr   TYPE SORTED TABLE OF scarr
            WITH UNIQUE KEY carrid,
  t_spfli   TYPE SORTED TABLE OF spfli
            WITH UNIQUE KEY carrid connid,
  t_sflight TYPE SORTED TABLE OF sflight
            WITH UNIQUE KEY carrid connid fldate.

TYPES:
  BEGIN OF MESH t_flights,
    scarr   TYPE t_scarr
      ASSOCIATION to_spfli TO spfli
               ON carrid = carrid USING KEY primary_key,
    spfli   TYPE t_spfli
      ASSOCIATION to_sflight TO sflight
               ON carrid = carrid AND
                  connid = connid USING KEY primary_key,
    sflight TYPE t_sflight,
  END OF MESH t_flights.

DATA:
  flights TYPE t_flights.


...

DATA(root) = flights-scarr[ carrname = 'United Airlines' ].

LOOP AT
  flights-scarr\to_spfli[ root ]\to_sflight[ ]
    INTO DATA(wa).
  ...
ENDLOOP.


More About

http://help.sap.com/abapdocu_740/en/index.htm?file=abenabap_meshes.htm

Open SQL

New Syntax

From 7.40, SP05

  • Lists in Open SQL statements can and should be separated by a comma.
  • Host variables in Open SQL statements can and should be escaped by a @.

Only then you will be able to use other new functions that are based on a new SQL parser in the ABAP kernel.

Example

SELECT carrid, connid, fldate

       FROM sflight

       INTO CORRESPONDING FIELDS OF TABLE @sflight_tab

       WHERE carrid = @carrier AND

             connid = @connection

       ORDER BY carrid, connid.

More About

http://help.sap.com/abapdocu_740/en/index.htm?file=ABENNEWS-740_SP05-OPEN_SQL.htm

SQL Expressions

Yo can use SQL expressions in a column list behind SELECT. The result of such an expression is calculated on the database (code push down!) and written into the respective columns of the result set. Operands can be data base columns or host variables.

Possible expressions are

  • elementary values
  • arithmetic expressions
  • arithmetic functions abs, ceil, floor, div, mod
  • castings with cast
  • string concatenations with &&
  • coalesce
  • case

Expressions can be mixed and proritized with parentheses.

Examples

SELECT id, num1, num2,

       cast( num1 AS fltp ) / cast( num2 AS fltp ) AS ratio,

       div( num1, num2 ) AS div,

       mod( num1, num2 ) AS mod,

       @offset + abs( num1 - num2 ) AS sum

       FROM demo_expressions

       INTO CORRESPONDING FIELDS OF TABLE @results

       ORDER BY SUM DESCENDING.

SELECT id, CASE char1

             WHEN 'aaaaa' THEN ( char1 && char2 )

             WHEN 'xxxxx' THEN ( char2 && char1 )

             ELSE @else

           END AS text

       FROM demo_expressions

       INTO CORRESPONDING FIELDS OF TABLE @results.

More About

http://help.sap.com/abapdocu_740/en/index.htm?file=ABAPSQL_EXPR.htm

CDS Views

The new CDS (Core Data Services) enable you to define Views of the ABAP Dictionary with a DDL (Data Definition Language) in ADT. This DDL encompasses the DDL of SQL and enhances it with the possibility to define annotations and associations. CDS-Views in the Dictionary are not bound to a specific database platform. They provide another way of database independent code push down.You can acces CDS-Views with Open SQL.

Example

Definitiion of a simple view based on only one database table. Of course, you can join as you like ...

@AbapCatalog.sqlViewName: 'BPA_VW'
define view
business_partner as
  select from snwd_bpa
         { key bp_id, company_name, bp_role }

You can access the view in ABAP programs e.g. as follows:

SELECT * FROM business_partner INTO TABLE itab ...

More About

http://help.sap.com/abapdocu_740/en/index.htm?file=ABENCDS.htm

See also the dedicated blog http://scn.sap.com/community/abap/eclipse/blog/2014/02/04/new-data-modeling-features-in-abap-for-han... by christiaanedward.swanepoel.

ABAP Managed Database Procedures

ABAP Managed Database Procedures (AMDP) are a class based framework for maintaining and calling stored procedures as so called AMDP procedures from ABAP. An AMDP procedure is implemented in its native DB-language in an AMDP method of an AMDP class. Currently, the only database that suports AMDP is SAP's HANA database.


An AMDP class must implement a specific tag interface. Currently, there is only one namely IF_AMDP_MARKER_HDB. An AMDP class can be maintained in ADT only. An AMDP method looks from its declaration like a normal ABAP method and can be used like that. Only when implementing the method, you denote the database and the DB language. You also must denote the entities to be used. The following is an example for using the language SQLScript of the HANA database:

CLASS cl_demo_amdp DEFINITION PUBLIC.
  PUBLIC SECTION.
    INTERFACES if_amdp_marker_hdb .
    METHODS increase_price
      IMPORTING
        VALUE(clnt) TYPE sy-mandt
        VALUE(inc)  TYPE sflight-price .
ENDCLASS.

CLASS cl_demo_amdp IMPLEMENTATION.
  METHOD increase_price BY DATABASE PROCEDURE FOR HDB
                        LANGUAGE SQLSCRIPT
                        USING sflight.
    update sflight set price = price + :inc
                   where mandt = :clnt;
  ENDMETHOD.
ENDCLASS.

Please note that a simple example as the above one is only to show the syntax. Implementing functionality in an AMDP method means the usage of Native SQL. And for the usage of Native SQL the same holds as before: Stay open as long as possible! It makes absolutely no sense to push down statements to the database that you can also express in Open SQL, because those are pushed down by the Native SQL Interface in exactly the same way or even better!


You use AMDP as a convenient way of programming and handling Native SQL in ABAP only if you really gain something from it. And for that, simple examples are not too easy to find, especially since Open SQL is empowered by new features now (see above).

Example

A simple example of a database functionality that is not readily available in Open SQL is the predefined currency conversion of HANA. An AMDP method that uses this conversion might look as follows:

METHOD convert BY DATABASE PROCEDURE FOR HDB

                           LANGUAGE SQLSCRIPT

                           USING demo_prices.

  PRICES = select * from DEMO_PRICES;

  PRICES =

    CE_CONVERSION (

      :PRICES,

      [ family             = 'currency',

        method             = 'ERP',

        steps              = 'shift,convert,shift_back',

        target_unit        = :TO_CURRENCY,

        client             = :MANDT,

        source_unit_column = "CURRENCY",

        reference_date     = :DATE,

        output_unit_column = "CURRENCY",

        error_handling     = 'keep unconverted' ],

      [ amount AS amount ] );

   replace DEMO_PRICES select * from :PRICES;

ENDMETHOD.

An alternative implementation for databases other than the SAP HANA database must then be provided, e.g. as follows:

METHOD abap_convert.

  DATA prices TYPE STANDARD TABLE OF demo_prices.

  SELECT *

         FROM demo_prices

         INTO TABLE prices.

  LOOP AT prices ASSIGNING FIELD-SYMBOL(<price>).

    CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'

      EXPORTING

        client           = mandt

        date             = date

        foreign_amount   = <price>-amount

        foreign_currency = <price>-currency

        local_currency   = to_currency

      IMPORTING

        local_amount     = <price>-amount

      EXCEPTIONS

        OTHERS           = 4.

    IF sy-subrc <> 0.

      CONTINUE.

    ENDIF.

    <price>-currency = to_currency.

  ENDLOOP.

  MODIFY demo_prices FROM table prices.

ENDMETHOD.

ABAP code calling these methods could look as follows:

IF cl_db_sys=>is_in_memory_db = abap_true.

    NEW cl_demo_sqlscript_curr_conv(

      )->convert(

           EXPORTING

             to_currency      = to_upper( currency )

             mandt            = sy-mandt

             date             = sy-datlo ).

ELSE.

   NEW cl_demo_sqlscript_curr_conv(

     )->abap_convert(

          EXPORTING

            to_currency      = to_upper( currency )

            mandt            = sy-mandt

            date             = sy-datlo ).

ENDIF.

More About

http://help.sap.com/abapdocu_740/en/index.htm?file=ABENAMDP.htm

Further Information

For a complete overview of all ABAP Language News for Release 7.40, SP05 see

If you are especially interested in ABAP for HANA, also have a look at jens.weiler blog New ABAP for HANA features in SAP NW 7.4 SP5. The ABAP Keyword Documentation summarizes the respective ABAP language features under http://help.sap.com/abapdocu_740/en/index.htm?file=ABENABAP_HANA.htm.

Outlook

The next bundled release will be 7.40, SP08 with kernel release 742. Expect some nice features from that one too. I'm already very busy documenting them.

90 Comments
Labels in this area