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.

Advertising

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)
Advertising

ABAP - Predicative Method Call

Category - ABAP

Due to the OO concept, own methods are usually used for complex queries. This article is about comparing the result from such methods.

05/14/2021

ABAP - Performance for the SELECT

Category - ABAP

In this article we will look at a few special cases with the SELECT and examine the performance of these constructs. We'll show you the current alternatives and give you little tips while reading.

04/02/2021

ABAP - Check objects (Instances)

Category - ABAP

In this article we will show you how you can analyze instances and react to them correctly, for example if you hand them over during processing and want to react individually.

03/19/2021

ABAP - Loops

Category - ABAP

With New ABAP, new loops and possibilities for restricting table contents were created. We'll take a closer look at these new commands in this article.

02/19/2021

ABAP - Comparison

Category - ABAP

Today we'll look at comparisons and comparison operators in terms of the new commands and their current usage. What has changed so far and what should still be done?

02/12/2021