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.

Recent Code Inspector Enhancements 4.3

numbers. Each of these numbers corresponds to the support stack in which the

functionality was added, and the order of the numbers indicates whether we’re

talking about SAP NetWeaver 7.02, SAP NetWeaver 7.31, or SAP NetWeaver 7.4.

So, for example, “12/5/2” means that the check becomes available in SAP

NetWeaver 7.02 SP 12/SAP NetWeaver 7.31 SP 5/SAP NetWeaver 7.4 SP 2. The

checks are sorted by the order in which they become available—oldest first.

4.3.1 Unsecure FOR ALL ENTRIES (12/5/2)

As you’ve probably experienced yourself, there’s a bug in SAP that’s particularly

annoying to programmers: If you us e an empty internal table in a FOR ALL

ENTRIES database query, then instead of returning noth ing, a full table scan

occurs. This is counter intuitive. If I gave you an empty list and then said “bring

me everything on this list,” you would give me nothing rather than trying to get

everything in the world to give to me. Nonetheless, this is how the ABAP system

responds. For a long time, SAP used the common software vendor trick of saying

that if you document a bug then it is no longer a bug. Although they still have not

fixed this, there is now a static code check to alert you to cases in which you have

forgotten to check for an empty table.

Listing 4.2 shows an example which has not tested if a table is empty before performing

a FOR ALL ENTRIES selection.

DATA: lt_monsters TYPE STANDARD TABLE OF ztvc_monsters,

lt_selections TYPE RANGE OF zde_monster_number.

SELECT *

FROM ztvc_monsters

INTO CORRESPONDING FIELDS OF TABLE lt_monsters

FOR ALL ENTRIES IN lt_selections

WHERE monster_number = lt_selections-low.

Listing 4.2 No Empty Table Check

In order to fix this problem and do a proper static code check, you have to make

sure that the requisite check is active in your default Code Inspector variant. To

do this, select the Unsecure use of FOR ALL ENTRIES checkbox, as shown in Figure

4.16.

As you can see in Figure 4.17, this problem is now picked up by the Code Inspector.

Make a little change to your program, as in Listing 4.3, in order to check

whether or not the internal table of selection criteria is empty.

193

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

Saved successfully!

Ooh no, something went wrong!