This is a test message to test the length of the message box.
Login
ABAP Corresponding and Value
Created by Software-Heroes

ABAP - Corresponding and Value

The two expressions focus primarily on creating structures and moving data content in the context of tables. We want to show you today the two statements and which commands they replace.

Today we want to bring you the two commands Corresponding and Value a little bit closer. As in the last article, the terms are so-called constructor expressions, if you do not know what that means, then you can read this in our last article.

 

Corresponding

The new command replaces the Move-Corresponding, as you have probably already thought. A new type can be defined directly at the transfer. The command has also some defined additions that will make your life a lot easier.

Here's an example of how easy the new command works:


" Easy Move
DATA(ls_t001) = CORRESPONDING t001( ls_data ).

 

For a simple move no complex use is necessary, here the command can simply be written down "flat".

It looks different, if you want to merge several structures, here you need an addition, otherwise the previously mapped values will be deleted from your target structure. This is the so-called base for moving the data. In the following example, we combine three structures into one target structure:


" Move with Base
ls_data = CORRESPONDING #( ls_t001 ).
ls_data = CORRESPONDING #( BASE( ls_data ) ls_bkpf ).
ls_data = CORRESPONDING #( BASE( ls_data ) ls_skb1 ).

 

The addition transfers the already filled fields from ls_data and then adds them to the fields of the additional structure, in this case company code and G/L account.

Another, very interesting, addition is the mapping for fields that do not fit by name. Previously you had to use a Move-Corresponding and then map all deviant fields. This can now be done after the "Mapping" command.


" Move with Mapping
ls_data = CORRESPONDING #( ls_t001 MAPPING company_code = bukrs description = butxt ).

 

The assignment is in principle "target field = source field from the structure". Here, any number of fields can be added, which should be additionally mapped.

 

Value

The "Value" command is used primarily to create structures and tables. The use of inserts, updates or appends is very flexible, saves space in the coding and above all, it saves initialization effort, because the structure is only generated by the Value statement. Between the parentheses of the Value the assignment of the required fields takes place. You just have to fill in the fields you need, the rest will be filled up with initial values.

Here are some examples for the command:


" Fill a Range
DATA lt_bukrs TYPE RANGE OF t001-bukrs.

APPEND VALUE #( sign = 'I' option = 'EQ' low = 'A001' ) TO lt_bukrs.
APPEND VALUE #( sign = 'I' option = 'EQ' low = 'A002' ) TO lt_bukrs.
APPEND VALUE #( sign = 'I' option = 'EQ' low = 'A003' ) TO lt_bukrs.

" Create a structure
DATA(ls_t001) = VALUE t001( bukrs = 'A001' butxt = 'Value-Test' land1 = 'EN' ).

" Create table
TYPES tt_data TYPE STANDARD TABLE OF char25 WITH EMPTY KEY.

DATA(lt_data) = VALUE tt_data( ( '123' ) ( '456' ) ( '789' ) ).

 

Hint: Important when defining the table and using a self-defined table type is the definition of the key. In this case, we have defined an "empty key" to have a key. Without adding the key definition, the code can not be generated and the error message "A value of the generic type TT_DATA can not be constructed."

 

Conclusion

Today's featured functions again provide a lot of flexibility in development and shorten the effort of writing in some places. We hope you like the two new keywords as well as we do and we hope you enjoy using them.

 

Source:
SAP Documentation Corresponding
SAP Documentation Value


Included topics:
New ABAPCorrespondingValue
Comments (0)

ABAP Deep Dive - VALUE

Category - ABAP

In this article we want to look at the value statement again in all its forms and how you can use it in your daily work.

11/11/2022

ABAP - Common Table Expression (CTE)

Category - ABAP

In this article we want to take a look at the general table expression WITH and how you can use it in everyday life.

10/28/2022

ABAP Deep Dive - CORRESPONDING

Category - ABAP

In this article, a little more about the new Corresponding Statement and how to use it in detail. Let's take a look at the additional features.

09/16/2022

ABAP - Step

Category - ABAP

Today a new addition for the loops and how you can use it. With Step you have the possibility to skip steps in a loop.

09/02/2022

ABAP - Text, String, Template

Category - ABAP

How do I use character strings in modern ABAP development and how do they behave together with inline declarations. We also look at errors that can happen with it.

01/14/2022