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

7092

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)



And further ...

Are you satisfied with the content of the article? We post new content in the ABAP area every Tuesday and Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.


ABAP - XCO Logging

Category - ABAP

The XCO classes are part of the ABAP Cloud APIs and offer numerous functions that aren't always easy to understand. In this article, we'll take a detailed look at the logging object.

12/16/2025

ABAP - The right Key

Category - ABAP

What about the use of internal tables? Is it still just TYPE TABLE in ABAP, and the table is fully defined?

11/14/2025

ABAP - XCO Regular Expressions

Category - ABAP

Let's take a look at the XCO classes for regular expressions and how you can easily use them to execute REGEX against text and input in ABAP Cloud. We'll also compare them with classic ABAP.

11/07/2025

ABAP - Escape

Category - ABAP

In this article, let's take a closer look at different escape variants that you need for ABAP development and system security.

10/07/2025

ABAP - Date and Time

Category - ABAP

In this article, let's take a closer look at the data types for dates and times in ABAP. Have any changes been made between the various releases, and what should you still use today?

10/03/2025