7.4 Release News - Support Package 05


Overview

Here we go again, another week, another Support Package Stack also! As you remember, in the previous post we have talked about the new features of the ABAP 7.4 SP02, and today I want to continue this habit and talk about the new features of the 7.4 SP05. We are going to talk about very powerful features, like: how to make component-by-component assignments of two very different structures, how to build the content of an internal table based on another internal table, and at last what the SQL Expression are in ABAP.


Component Operator

First of all, let's check the following structure definitions: one for describing a person, and another for describing an employee. The person structure is a nested structure (structure within another structure), and the employee structure is a flat structure (contains only simple data types).

The differences between the two structures

  • the address component of the person structure is stretched into simple data types in the employee structure,
  • the date_of_birth component of the person structure is called as birth_date in the employee structure,
  • the position component of the employee structure doesn't exist in the person structure.
TYPES:
  BEGIN OF person,
    name          TYPE string,
    BEGIN OF address,
      house_number TYPE string,
      street       TYPE string,
      city         TYPE string,
      zip_code     TYPE string,
      state        TYPE string,
      country      TYPE string,
    END OF address,
    phone_number  TYPE string,
    date_of_birth TYPE d,
    email_address TYPE string,
  END OF person.

TYPES:
  BEGIN OF employee,
    name          TYPE string,
    house_number  TYPE string,
    street        TYPE string,
    city          TYPE string,
    zip_code      TYPE string,
    state         TYPE string,
    country       TYPE string,
    phone_number  TYPE string,
    birth_date    TYPE d,
    position      TYPE string,
    email_address TYPE string,
  END OF employee.

Now let's initialize a person (nested structure) using our well-known constructor operator, called VALUE.

DATA(person_john_mayer) = VALUE person(
  name    = 'John Mayer'
  address = VALUE #(
    house_number = '181'
    street       = 'Round Jetty Str.'
    city         = 'Cleveland'
    zip_code     = '34221'
    state        = 'Alabama'
    country      = 'United States'
  )
  phone_number  = '+1 303 544 5464'
  date_of_birth = '19721101'
  email_address = 'john.mayer@gmail.com'
).

To assign the content of the person_john_mayer (nested structure) into our employee_john_mayer (flat structure), there is nothing to do, than

  • using the new CORRESPONDING keyword
  • specifying the target data type (or using the # symbol), in our case the data type is the employee
  • specifying the source structure between the brackets, in our case it's the previously initialize person_john_mayer

The CORRESPONDING component operator tries to match the components by names. In this case, only the content of the name, phone_number and the email_address will be transferred to the employee_john_mayer structure (since only they match in both structures).

DATA(employee_john_mayer) = CORRESPONDING employee( person_john_mayer ).

If we want, we are able to define specific mapping rules to assign a component to another one. For example, we can match the employee's birth_date and the person's date_of_birth components using the keyword, called MAPPING.

DATA(employee_john_mayer) = CORRESPONDING employee(
  person_john_mayer MAPPING birth_date = date_of_birth
).

We can go further and map the elements of the person's address component (nested structure) directly to the employee's elements: house_number, street, city, zip_code, state, and country by specifying the different mapping rules.

DATA(employee_john_mayer) = CORRESPONDING employee(
  person_john_mayer MAPPING birth_date   = date_of_birth
                            house_number = address-house_number
                            street       = address-street
                            city         = address-city
                            zip_code     = address-zip_code
                            state        = address-state
                            country      = address-country
).

At last, we can leave some components from the assignments using the keyword, called EXCEPT (for example, if we don't want to transfer the content of the email_address component).

DATA(employee_john_mayer) = CORRESPONDING employee(
  person_john_mayer MAPPING birth_date   = date_of_birth
                            house_number = address-house_number
                            street       = address-street
                            city         = address-city
                            zip_code     = address-zip_code
                            state        = address-state
                            country      = address-country
                    EXCEPT  email_address
).


Table Comprehensions

To demonstrate the usage of the FOR ... IN itab expression, let's declare two table types people and employees, based on the previously defined types person and employee.

...
TYPES people    TYPE STANDARD TABLE OF person   WITH DEFAULT KEY.
TYPES employees TYPE STANDARD TABLE OF employee WITH DEFAULT KEY.
...

Using the VALUE operator and the type people, let's initialize an internal table for people from United States.

...
DATA(us_people) = VALUE people(
  (
    name    = 'John Mayer'
    address = VALUE #(
      house_number = '181'
      street       = 'Round Jetty Str.'
      city         = 'Cleveland'
      zip_code     = '34221'
      state        = 'Alabama'
      country      = 'United States'
    )
    phone_number  = '+1 303 544 5464'
    date_of_birth = '19721101'
    email_address = 'john.mayer@gmail.com'
  ) " first row
  (
    name    = 'Eric Dumm'
    address = VALUE #(
      house_number = '233/C'
      street       = 'Hazy Pointe Str.'
      city         = 'Essex'
      zip_code     = '34221'
      state        = 'Delaware'
      country      = 'United States'
    )
    phone_number  = '+1 635 999 5881'
    date_of_birth = '19690321'
    email_address = 'eric.dumm@gmail.com'
  ) " second row
  ...
).

Now our task is to define a new internal table for employees from Essex, with type employees.

DATA(essex_employees) = VALUE employees(

).

To initialize the internal table, essex_employees using the content of the us_people internal table (don't forget the internal tables have very different structures), we can use the brand new FOR ... IN expression, that sound like this:

DATA(essex_employees) = VALUE employees(
  FOR person IN us_people WHERE ( address-city = 'Essex' ) (
    
  )
).

At last, to solve the compatibility problem between the internal tables, we can define a CORRESPONDING expression like previously:

DATA(essex_employees) = VALUE employees(
  FOR person IN us_people WHERE ( address-city = 'Essex' ) (
    CORRESPONDING employee(
      person MAPPING birth_date   = date_of_birth
                     house_number = address-house_number
                     street       = address-street
                     city         = address-city
                     zip_code     = address-zip_code
                     state        = address-state
                     country      = address-country
             EXCEPT  email_address
    )
  )
).


SQL Expressions

From 7.4 SP05, we can specify SQL Expressions in a comma-separated SELECT list. It means, that from now on, we are able to define our expression directly in the SELECT statement (no need for SELECT ... ENDSELECT or LOOPs). Expressions like this is executed by the database system and the results passed to the application server back.

SELECT carrid  AS airline_id,
       connid  AS connection_id,
       fldate  AS flight_date,
       cast( seatsocc   AS fltp ) / cast( seatsmax   AS fltp ) AS economy_occupied_ratio,
       cast( seatsocc_b AS fltp ) / cast( seatsmax_b AS fltp ) AS business_occupied_ratio,
       cast( seatsocc_f AS fltp ) / cast( seatsmax_f AS fltp ) AS first_occupied_ratio,
  FROM sflight
  INTO CORRESPONDING FIELDS OF TABLE @DATA(flight_occupancies) UP TO 100 ROWS.


Summary

I reckon, this support package gives us very powerful features, that makes much faster and high-quality our ABAP developments. I believe that we can live and develop without these features, but if we have the chance to work on 7.4 based ABAP system, then it would be a huge waste to not use them!

Do you have any experiences with these new features? If yes, then share with us below!

Now, go and try it out! If you don't have any access to any 7.4 based SAP system, then I recommend to watch my colleague's setup guide.

Stay tuned, keep reading! If you want to get notification about the newest posts, follow me or subscribe to our newsletter!

If you liked it, please share it! Thanks!

blog comments powered by Disqus