14.01.2020 Views

ABAP_to_the_Future

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2

New Language Features in ABAP 7.4

END OF ls_european_monsters.

DATA: BEGIN OF ls_us_monsters,

laboratory TYPE string,

t_result TYPE STANDARD TABLE OF l_typ_us_monsters,

END OF ls_us_monsters.

ls_european_monsters-laboratory = 'SECRET LABORATORY 51'.

ls_type_iban_codes-monster_name = 'FRED'.

ls_type_iban_codes- monster_iban_code =

'AL47212110090000000235698741'.

APPEND ls_type_iban_codes TO ls_european_monsters-t_result.

MOVE-CORRESPONDING ls_european_monsters TO ls_us_monsters.

Listing 2.54 Attempt at MOVE-CORRESPONDING

What do you think happens? In fact, in the US monster structure the results table

gets the LOCKBOX field filled with the IBAN code from the European equivalent,

because they have the same name.

Usually, this is not what you want. For identical tables, you can always get around

this using LT_ONE[] = LT_TWO[] , which changes the first table into an identical

copy of the second table. However, this doesn’t work in ca ses where, say, you

have a database table with 10 fields and aninternal table with those 10 fields plus

five more fields with text descriptions or calculated fields. Instead, you would

need to read the database table into one internal table with just the 10 fields, and

loop through this first internal table, moving the corresponding elements to some

sort of second output table, where you fi ll in extra data, such as names for sales

offices and the like and calculated fields.

Thus, instead of the code shown in Listing 2.55 you would use the code shown in

Listing 2.56.

LOOP AT lt_european_monsters ASSIGNING <ls_european_monsters>.

APPEND INITIAL LINE TO lt_us_monsters

ASSIGNING <ls_us_monsters>.

MOVE-CORRESPONDING <ls_european_monsters> TO <ls_us_monsters>.

ENDLOOP.

Listing 2.55 Copying between Internal Tables with Different Structures before 7.4

MOVE-CORRESPONDING lt_european_monsters TO lt_us_monsters.

Listing 2.56 Copying between Internal Tables with Different Structures in 7.4

118

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!