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.

Internal Tables 2.6

a traditional READ TABLE xyz INTO ls_abc when the read failed. An example of this

is shown in Listing 2.50.

zcl_bc_output( |{ ld_monster_name }’s Monster Number is { lt_monsters[

monster_name = ld_monster_name ]-monster_number OPTIONAL }| ).

zcl_bc_output( |{ ld_monster_name }’s Monster Number is { lt_monsters[

monster_name = ld_monster_name ]-monster_number DEFAULT ‘999999’ }| ).

Listing 2.50 OPTIONAL

The addition DEFAULT fills in a hard-coded value wh en the read fails. Then, you

can check if the read failed by comparing the result with that hard-coded value in

the same way you would if SY-SUBRC was 4 when checking if a traditional read on

an internal table succeeded.

2.6.4 CORRESPONDING for Normal Internal Tables

You no doubt use the ABAP keyword MOVE-CORRESPONDING a lot, moving variable

values from one structure to another.

Warning: Houston, We Have a Problem

In some standard SAP documentation, you are advised never to use MOVE-CORRESPOND-

ING at all, most likely to avoid the problem of moving strings into number fields, highlighted

at the start of this section. However, if you do use it, then the functionality discussed

here should be of help to you.

New in 7.4 is a constructor operator called CORRESPONDING without the word MOVE

in front. This operator takes moving data between two internal tables to a whole

new level. Say that you have two internal tables full of monster-related data, but

they are defined with a different set of columns. What you want to do is copy

over the fields with the same names from one table to the other, with two exceptions:

왘 You do not want to copy the EVILNESS value from one table to the other, even

though both tables have an EVILNESS column.

왘 You want to copy the column named MOST_PEASANTS_SCARED from one table

into a similar column called PEOPLE_SCARED in the second table.

Prior to 7.4, you would declare a bunch of helper variables to store the work areas

of the two tables, and then loop through the first table, moving everything from

115

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

Saved successfully!

Ooh no, something went wrong!