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.

2

New Language Features in ABAP 7.4

CHECK sy-subrc = 0.

ld_start_point = sy-tabix.

LOOP AT mt_marc INTO ls_marc

USING KEY sort FROM ld_start_point.

IF ls_marc-matnr GT ld_matnr.

EXIT."From Inner Loop

ENDIF.

CHECK ls_marc-matnr = ld_matnr.

APPEND ls_marc TO et_marc.

ENDLOOP.

SORT et_marc BY matnr werks.

ENDIF.

Listing 2.45 Looping Through a HASHED Table with a Secondary SORTED Index

At this point, the code defining MT_MARC (Listing 2.44) should be clear: depending

on what key you choose, the table can act as a HASHED table or as a SORTED table.

2.6.2 Table Work Areas

Some time back, SAP decreed that header lines in internal tables were the work of

the devil. This was because the use of header lines led to the existence of two data

objects in your program with the exact same name, and this was viewed as confusing.

For example, it wouldn’t be uncommon to find a program in which you

had an ITAB variable that referred to the internal table as a whole and also a work

area called ITAB that referred to the current line of the table being processed.

Clearly, that is wrong from an academic point of view—but in real life ABAP programmers

were so used to the idea of th e header line that it was a hard habit to

shake. This was especially true because you had to explicitly declare a variable to

act as the header line. For example:

DATA: ls_itab LIKE LINE OF itab.

The good news is that now you can avoid having to make that extra variable declaration

and still have two differently named variables, one for the table and one

for the work area. In release 7.4, the syntax for reading into a work area and looping

through a table is as shown in Listing 2.46.

READ TABLE lt_monsters WITH KEY monster_number = ld_monster_

number INTO DATA(ls_monsters).

LOOP AT lt_monsters INTO DATA(ls_monsters).

Listing 2.46 Reading Into a Work Area and Looping Through a Table

112

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

Saved successfully!

Ooh no, something went wrong!