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.

Testing and Troubleshooting 1.3

by regression tests and second to move toward making sure that every single line

of code gets test coverage.

1.3.2 Debugging

One of the best features in the ABAP Workbench is the debugger, and Chapter 5

will take a quick look at the latest fe atures that have crept into the debugger

recently that you may be unaware of. For the moment, though, the focus is on

ABAP in Eclipse, so you may be wonder ing what relevance debugging has in a

pure development environment. This comes back to unit tests again: if you have

an error, then you want to debug the program to see what is going wrong.

There is bad news and good (though weird) news here. The bad news is that, as of

the time of writing, the debugger in ABAP in Eclipse cannot do everything that

the debugger in a real SAP system can do, though of course as time goes by those

gaps are being plugged. Now, the good news—though when I tell you what the

good news is you might think “That can’t be true, he must be on drugs”—the

good news is that it is possible to change source code while it is in the process of

being debugged.

In the next example, you will put an obvious error in your code and then debug

it to see what’s wrong. In the UK, we use the phrase “h ow many beans make

five,” to which the answer is, shockingly, five. In your program, you want to add

monsters until you get five, but you’ve missed one and so only end up with four,

which is a clear error (Listing 1.15).

CLASS lcl_how_many_monsters DEFINITION.

PUBLIC SECTION.

METHODS how_many_make_five RETURNING VALUE(rd_how_many) TYPE i.

ENDCLASS. "How Many Monsters Definition

CLASS lcl_how_many_monsters IMPLEMENTATION.

METHOD how_many_make_five.

DO 100 TIMES.

ADD 1 TO rd_how_many.

IF rd_how_many = 4.

RETURN.

ENDIF.

ENDDO.

ENDMETHOD.

ENDCLASS. "How Many Monsters implementation

DATA: ld_how_many TYPE i,

67

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

Saved successfully!

Ooh no, something went wrong!