14.01.2020 Views

ABAP_to_the_Future

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

4

ABAP Test Cockpit

Figure 4.25 Error Message for Dodgy Statements after SELECT

Did you notice that the error for reading the first record was still reported, even

though the dodgy statement was in a totally different subroutine to the SELECT

statement? This is a new innovation SA P has made in which the Code Inspector

becomes clever enough to look across “modularization” units, such as FORM routines,

methods, and the like, to hunt for errors. (The next error check you’ll see is

an even better example of this.)

4.3.6 SELECTs in Loops across Different Routines (14/9/3)

When you want to retrieve lots of records from the database, the way to go is to

get them all at once, because you should always try to minimize traffic between

the application server and the database. Inother words, the last thing you want to

be doing is retrieving the records one at a time. That is what’s happening in Listing

4.8.

LOOP AT lt_monsters INTO ls_monsters.

WRITE:/ ls_monsters-monster_number,

ls_monsters-hat_size.

SELECT SINGLE *

FROM ztvc_monstr_beds

INTO CORRESPONDING FIELDS OF gs_beds

WHERE monster_number EQ ls_monsters-monster_number.

ENDLOOP.

Listing 4.8 Retrieving Records One at a Time

The preceding code is no problem, because it would automatically raise an error

in the Code Inspector. However, now take a look at Listing 4.9.

LOOP AT lt_monsters INTO ls_monsters.

WRITE:/ ls_monsters-monster_number,

ls_monsters-hat_size.

200

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

Saved successfully!

Ooh no, something went wrong!