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.

Coding the SCRIPT Method 5.2

call another method to look at the system state and see if you have found the bug.

In this example, the bug is that our variable has changed, and this stage will end

with you finding that variable.

Now, by a combination of looking and moving, you’ve found the place where the

bug resides, and it’s time for the act stage. What you usually do here when manually

debugging is change the variable value to the correct value, and press (F8) to

see if changing that variable has fixed the problem so that the rest of the program

executes correctly. If so, th en you know you need to concentrate on fixing the

part of the program that messes up the variable value.

To do this via the Script Wizard, choose Change Variable Value 폷 Simple Variable

or Change Variable Value 폷 Table. For this example, use the former, and

you’ll get the code shown in Listing 5.4.

*TRY.

CALL METHOD CL_TPDA_SCRIPT_DATA_DESCR=>CHANGE_VALUE

EXPORTING

P_NEW_VALUE =

* p_offset = -1

* p_length = -1

P_VARNAME =

.

* CATCH cx_tpda_varname .

* CATCH cx_tpda_scr_auth .

*ENDTRY.

Listing 5.4 Programatically Changing a Variable Value in the Debugger

Naturally, this is just the reverse of reading a variable value, with the same sort of

error handling in case a bogus variable value is passed in. After you’ve changed

your variable value, return control to the normal debugger with the ME->BREAK( )

command. Hopefully, changing the variable value solved the problem. If not,

then at least you have eliminated one possible cause of the error—but it is time to

go back to the drawing board and change your script to look for something else.

In any event, once back in the re al debugger, you press the actual (F8) button,

which will bring the program (and hence the debugging session) to a natural end.

Throughout all of the first three stages there is also the log stage. When going

through a debugger manually, you sometimes take screenshots of some variable

values at a given point in the program an d print them out, email them to a colleague,

or write them down on the ever -popular piece of paper. (Downloading

213

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

Saved successfully!

Ooh no, something went wrong!