Sie sind auf Seite 1von 35

Java Debugging using the VMC Debugger

Version September 2016

Luis Rivera Gallego


Senior Support Engineer CRM
GSC Spain

1
DEBUGGING USING VMC DEBUGGER ..................................................................................................... 2
GENERAL STEPS ..................................................................................................................................... 2
STEPS TO CREATE OUR JAVA BREAKPOINT AND HIT IT IN THE VMC DEBUGGER ........................................................... 4
Setting ABAP breakpoints .................................................................................................................... 5
Setting Java breakpoint and exit the VMCJDB session ........................................................................ 5
Start debugging session and hit breakpoint ........................................................................................ 6
NAVIGATE THROUGH THE CODE AND CHECK VALUES OF VARIABLES ......................................................................... 8
SAMPLE DEBUGGING SESSION ............................................................................................................. 10
STEPS TO CREATE OUR JAVA BREAKPOINT AND HIT IT IN THE VMC DEBUGGER ......................................................... 10
Setting ABAP breakpoints .................................................................................................................. 10
Setting Java breakpoint and exit the VMCJDB session ...................................................................... 11
Start debugging session and hit breakpoint ...................................................................................... 15
NAVIGATE THROUGH THE CODE AND CHECK VALUES OF VARIABLES ....................................................................... 24
Checking content of an object (dump) ............................................................................................... 24
Example navigation inside a method and back ( step, stepup).......................................................... 27
Checking value of an expression (dump) ........................................................................................... 31
Execution stepping over calls (next)................................................................................................... 33

Debugging using VMC Debugger

This document contains the steps to debug java coding using the Virtual Machine Container
Debugger. The steps can be used to debug the standard code as well as the customer code.

A chapter with general steps and another one with a sample session will be displayed with
almost the same subchapters in both, so that you can quickly check in the sample session the
details that you do not understand from the general steps chapter.

General steps

To start the VMC Debugger, use transaction VMCJDB. Commands can be used in the debugger
for several purposes , for example, set breakpoints, check values of variables or navigate
through the code. These commands can be executed either by writing them in the command
line or, whenever possible, by double-clicking on the list of commands or variables.

Example
If you are already debugging the code and want the debugger to go to the next line (similar to
F6 in ABAP) double-click on the command next, on the list of commands above

2
Or write the command next in the command line below

You can check all the available commands by double-clicking on command help

3
The general steps can be divided in the following way:

 Steps to create our Java breakpoint and hit it in the VMC debugger
 Navigate through the code and check values of variables in the VMC debugger

Steps to create our Java breakpoint and hit it in the VMC debugger

The steps can be divided in 3 blocks:

 Setting ABAP breakpoints


 Setting Java breakpoint and exit the VMCJDB session
 Start debugging session and hit breakpoint

4
Setting ABAP breakpoints

The function modules that invoke the VMC normally start with SPC* (eg. SPC_CREATE_ITEMS) .
A session ABAP breakpoint or an external ABAP breakpoint must be set in a statement where
one of those function modules is called. The function module (VMC call) where the ABAP
breakpoint is set, does not need to be the same VMC call where the java breakpoint will be hit,
it can be the same one or another one that will be executed previously. This is because the
ABAP breakpoint is just used as a pre-step for the connection to the VMC debugger.

Alternatively, instead of setting breakpoints, if a pricing functionality has to be debugged, user


parameter PRC_RFC = X can be set. Just before all the VMC calls for pricing, there is an ABAP
statement:
break_rfc.
and the ABAP debugger will stop in that statement
However, if user parameter PRC_RFC is set instead of adding the breakpoint directly in the
ABAP debugger- and the issue is reproduced in the CRM Web UI, an external breakpoint
might have to be added where we are sure the program will stop. This breakpoint is needed
just to launch the ABAP debugger. Once the program hits the external breakpoint, the
debugger will stop in the statements before the pricing calls (statements “break_rfc”)
A good breakpoint could be in BADI CRM_COND_COM_BADI, as this is always called before the
calls to pricing.
In summary, the steps regarding ABAP breakpoints are normally as in the table below

Usual Steps for pricing session


Sales order reproduced in Set user parameter PRC_RFC = X
SAPGUI
Sales order reproduced in Set user parameter PRC_RFC = X
CRM Web UI
Set external breakpoint in BADI CRM_COND_COM_BADI
(depending on the version this external breakpoint might not
be necessary)

Setting Java breakpoint and exit the VMCJDB session

 Execute transaction VMCJDB

 There are several options to set the breakpoint. We can choose any of them:

a) Using command dbsources to display the java code

This is the most suitable way if you want to check first the java source code where you
want to set the breakpoint. Steps:

- Launch command: dbsources


(command dbsources can be added on the command line or double-click on

5
"dbsources" on the list of available commands that can be seen at the top of the
screen)
- All the list of Java source files located in the database can be seen
- Double-click on the source file where the breakpoint needs to be set
- Double-click on the line where we want to set the breakpoint.

To confirm that our breakpoint has been added, we can check the list of breakpoints if
we scroll down below the source code, where we see “Breakpoints”
We can remove a breakpoint by double-clicking on the breakpoint in that list.

b) Execute Command in the command line


stop in <class>.<method>
E.g.
stop in com.sap.taxes.taxCall.ExternalTaxCalculationRFC.calculateTaxes

c) Execute Command in the command line


stop at <class>.<line>
E.g.
stop at com.sap.taxes.taxCall.ExternalTaxCalculationRFC:13

 After the breakpoint has been set, we exit our session in VMCJDB

Start debugging session and hit breakpoint

It is assumed, that pricing functionality has to be debugged and PRC_RFC = X has been set, so
the ABAP debugger will stop in all the VMC calls to pricing ( one statement before). The steps
for debugging will be the following:

 Start reproducing the problem in your application, e.g. creating a sales order
 If the program stops before a pricing call ( statement break_rfc) but you are in a user
step where you do not expect the java coding you want to debug to be executed yet,
execute F8 in the ABAP Debugger, so the VMC Debugger is not connected yet.
 When you are in the user step where you expect that the java coding will be executed,
and the first ABAP breakpoint ( statement break_rfc) is hit , press F6

6
 In the statement that calls the VMC , “CALL FUNCTION SPC..” press F5 ( step into)
 A pop-up appears with information about the port:
Java debugging back end on <host> is waiting for port <portnumber>
Don´t press OK yet.

 Launch transaction VMCJDB.


 a command like
attach <port> appears
where <port> is the port number that has been displayed in the previous pop-up
Double-click in the command attach <port>

 A call stack should be displayed in VMC Debugger, which is a confirmation that the
debugger is attached to that port
 Click OK in the pop-up.
 The control goes to the VMC debugger. Command cont can be executed to continue
( it works as F8 in ABAP debugger) or execute other commands
 The program can now jump from ABAP debugger to VMC debugger and vice versa.
If the control goes back to ABAP and you are not interested in ABAP debugging, hit F8
several times in the ABAP session until the java breakpoint is hit.
 The breakpoint is finally hit.
The arrow indicates the current statement in the program flow
Instructions in VMC debugger can now be used to see values of variables,etc.

7
Navigate through the code and check values of variables

Navigation

The commands that are used to navigate in the debugger are the following:

Command Like ABAP


step execute current line
step up execute until the current method returns to F7
its caller
stepi execute current instruction F5
next step one line (step OVER calls) F6

cont continue execution from breakpoint F8

Checking value of variables and objects

Primitive data types and strings. Command print


The command used to check the value of a variable of a primitive data type or string is
print <variable>
Alternatively, double-click on the variable, if it is visible on the screen

It is also possible to check the value of an expression whose result is a primitive data type of
string using
print <expression>

Objects . Command dump

8
The command used to check the value of an object reference variable is.
dump <object_reference>
Alternatively, double-click on the object reference, if it is visible on the screen.

It is also possible to check the value of an expression whose result is an object with the
command
dump <expression>

9
Sample debugging session

In the sample debugging session we will go inside the java coding of a standard value formula.

Steps to create our Java breakpoint and hit it in the VMC debugger

Setting ABAP breakpoints

Set user parameter PRC_RFC to value X

Transaction SU3

As the issue will be reproduced in CRM Web UI, a breakpoint is also set in one of the active
implementations of BADI CRM_COND_COM_BADI

10
Setting Java breakpoint and exit the VMCJDB session

Firstly, check the Java class for the formula to be debugged.

In this example, we want to debug standard value formula 2.


Check in transaction /n/SAPCND/UEASS that it corresponds to formula NETVALUE that is
implemented in class
com.sap.spe.pricing.transactiondata.userexit.value.NetValue

Execute transaction VMCJDB

Command dbsources will be used to display the java code and set the breakpoint. Double-click
in dbsources on the first screen

11
Search for the file that contains the class
com.sap.spe.pricing.transactiondata.userexit.value.NetValue

The file names have slash character “/” as separator, so search for string
com/sap/spe/pricing/transactiondata/userexit/value/NetValue

The file is found

12
After clicking on the file name in the pop-up, the cursor will be placed on the file name on the
list of files. Double-click

The source code of the class is shown


There is only one line of code in the value formula method. Double-click the line to set a
breakpoint in it.

13
The breakpoint has been added in that line. The list of breakpoints can be checked by scrolling
down below the source code, where “Breakpoints” can be seen.

14
Start debugging session and hit breakpoint

In this case, an order is initially opened, which already contains pricing and goes to the item
detail. In that user step the coding of our formula will not be executed, so there will be no
attempt to jump into the VMC calls.
Afterwards, when going to change mode in the order, there will be a jump into the VMC calls.

Open the order and go to item detail

The external breakpoint in BADI CRM_COND_COM_BADI is hit first.


Continue with F8, as this breakpoint was only needed to launch the ABAP debugger

15
The commands that are displayed may also depend on whether the order has been opened
before or not.
Jump several times with F8 (The java breakpoint does not have to be hit yet)

Now we are on item level.


As the calculation trace has also been switched ( user parameter PRC_CALC_ TRACE = X) go to
link Details of subtotal “Net value for item” to check that this subtotal was calculated using the
formula where the breakpoint had been set.
Notice that the value returned by the formula is 20 EUR

16
The value formula number 2 is triggered , and it returns a value of 20 EUR

Go back to the item level and click on the pencil to go to change mode

17
The statements break_rfc before the VMC calls for pricing will be hit again.
There is a VMC call to remove the old pricing session. Click F8 to continue

There is a VMC call to create the new pricing document


Statement break_rfc is hit
We want to jump into the VMC call ( with F5), so that we can connect the VMC Debugger to
the Java Virtual Machine that processes the pricing session.

Click F6 to go to the next statement

18
Now we have the statement of the VMC call. Click F5

19
A pop-up appears with information about the port where the VMC Debugger must be attached
to be able to debug the pricing session (port 8002)
Don´t press OK yet.

Start VMCJDB

Double Click on command


attach 8002
( sample port seen in the previous pop-up)

A call stack in VMC Debugger can be seen, which is a confirmation that the debugger is already
attached to port 8002

20
Click OK in the pop-up

Double-Click on cont ( works as F8 in ABAP debugger)

21
The program can now jump from ABAP debugger to VMC debugger and vice versa.
As the Java breakpoint is not hit in the execution of the command SPC_CREATE_DOCUMENT
that has been used to connect the VMC debugger, when clicking on cont in the VMC Debugger,
the control will go back to the ABAP Debugger

In the ABAP Debugger an indication can be seen that the breakpoints have been reloaded
successfully

Click F8

22
Click F8 several times in ABAP , until the java breakpoint is found

Finally the Java breakpoint is hit.


See the arrow indicating the current statement in the program flow

23
Navigate through the code and check values of variables

Checking content of an object (dump)

Double click on pricingItem

The content of object pricingItem is shown

24
PricingItem contains many other objects inside, rather than strings or primitive type variables,
Click on these objects to access the business relevant information.
For example click on _pricingDocument , and the following screen is displayed
Here you can see for example variable
_performCalcTrace true  Indicates that the calculation trace will be executed

Alternatively, the content of object pricingItem can be seen by executing command


dump pricingItem
from the command line

25
In the same screen where the content of object pricingItem is displayed, the Java coding can
still be seen by scrolling down.

26
Example navigation inside a method and back ( step, stepup)

Double click on step


A statement will be executed but without jumping over calls

So the debugger goes inside method getNetValueAsBigDecimal for the object pricingItem
( implemented in class PricingItem )
Double click on step again

27
The object that will be returned is given, which is m_netValue
Double click on m_netValue

28
See the values of intCompact and scale
intCompact 20000000000
scale 9
 Means the value is 20
(the value that is shown in the calculation trace as result of the formula)

Click stepup

29
Click on stepup again

30
Returning to the formula method

Checking value of an expression (dump)

The expression pricingItem.getNetValueAsBigDecimal() will return an object, the content of


the returned object can be checked by using the dump command

Add command in the command line

dump pricingItem.getNetValueAsBigDecimal()

31
32
The same object that was displayed before, by stepping into the method execution, is
displayed now.

Execution stepping over calls (next)

Coding is still in the value formula, click on Next


It will go to the next statement , but stepping over calls

Being already in the last statement of the value formula, it will go out from the formula to its
calling method

33
It goes to the calling method
Click on Cont

It goes back to ABAP debugger


Then click on F8 and go back to the CRM Web UI user interface

34
35

Das könnte Ihnen auch gefallen