uk/tips/abap-inline-
declarations.htm
The easiest way to describe this is to show you a very simple before
after ABAP code example. Pre 7.40 you would declare a work area and
read data into it somthing like this
Using the new method you would simply just using the folowing code:
READ TABLE it_ekko INDEX 1 INTO DATA(wa_ekko_new).
Hopefully the above example gives you an idea of how this new
functionality can streamline your ABAP code and make it more readable.
Also gives you the basics so you can have a play yourself. Now onto the
@DATA statement....
select ebeln ebelp statu aedat matnr menge meins netpr peinh
up to 10 rows
from ekpo
into CORRESPONDING FIELDS OF TABLE it_ekko.
Using the new @DATA statement you could essentially replace all this
with the following ABAP code, which automatically create an internal
table with the correct field structure and drops the selected values into
it. AS well as the @DATA note the ,'s after each field in the SELECT.
select ebeln, ebelp, statu, aedat, matnr, menge, meins,
netpr, peinh
up to 10 rows
from ekpo
into TABLE @DATA(it_ekko_new).
This is more like it and if you combine the two examples together you
get quite a neat and efficient looking section of code. It essentially
removes all the ABAP declaration lines of code without adding much at
all to SELECT and READ statements.
select ebeln, ebelp, statu, aedat, matnr, menge, meins,
netpr, peinh
up to 10 rows
from ekpo
into TABLE @DATA(it_ekko_new).
Inline declarations are a new way of declaring variables and field symbols at operand
positions.
Data Declarations
In ABAP you have many operand positions, where the value of the operand is changed by
the statement. The most typical of these “write positions” is the left hand side lhs of an
assignment.
lhs = rhs.
But of course there are more. The data objects you can use at these write positions are
either writable formal parameters of the procedure you are working in or variables declared
with DATA in front of the statement.
In many cases the variables filled by a statement are helper variables that you only need
close to the statement. For each of these helper variables you had to write a data
declaration with the DATAstatement and of course it was your task to give the variable an
adequate type.
Well, the operand type of most write positions is statically fixed and well known to the
compiler. And this is why ABAP can offer inline data declarations with Release 7.40. The
ingredients are so called declaration positions (write positions with fully known operand
type) and the new declaration operator DATA(…).
Let’s look at some examples.
Field Symbols
For field symbols there is the new declaration operator FIELD-SYMBOL(…) that you can
use at exactly three declaration positions.
ASSIGN … TO FIELD-SYMBOL(<fs>).
LOOP AT itab ASSIGNING FIELD-SYMBOL(<line>).
…
ENDLOOP.
READ TABLE itab ASSIGNING FIELD-SYMBOL(<line>) …
I guess it is clear to you what happens here.
Outlook
In my upcoming blogs I will make use of inline declarations when introducing other new
features. Be prepared for code like this:
TYPES t_itab TYPE TABLE OF i WITH EMPTY KEY.
DATA(itab) = VALUE t_itab( ( 1 ) ( 2 ) ( 3 ) ).
Yes, this is ABAP 7.40 …