Question
· Jul 16, 2019

Debugging ClassMethod with output parameters

I am fairly new to Cache and ObjectScript. I have a new task I have created with a corresponding method that I am trying to debug in Studio (2013). 

My ClassMethod looks like this

ClassMethod DoMyWork(Output pWorkCount as %Integer,  pInput1 As %Integer = 30)

{

/* Does some work here and increments pWorkCount */

}

When I try to debug this using studio, I  browse to my method but I am not certain what to put in here for the input parameter 'pWorkCount'.

I tried to execute the class in the terminal window but I am not sure how to enter debug mode using the terminal window. 

Thanks.

Discussion (3)0
Log in or sign up to continue

To call the method from the terminal use the following code (note that you have to initialise the variable and indicate that you are passing the value by reference by using the '.' before the relevant parameter):

set var="" do ##class(classname).DoMyWork(.var, 0) write var

Therefore in your method, the value you assign to pWorkCount will be returned to var. You don't need to return the variable, it will be automatically returned as the variable has been passed by reference.

The dot before variable name (.var) in the method call indicates that the variable is being passed by reference (by default values are passed by value), therefore I believe the "Output" keyword is optional (but it does make it clear in the method signature how the value is being passed).

I hope this makes sense; this depends on understanding the difference between passing by reference and value.  

To start debugging in Studio, you first have to set your method as a debug-target : right-click on the method header and choose 'Set DoMyWork as debug target'.

Then set a breakpoint  anywhere in the method you want to start debugging (click on F9  to toggle breakpoints)

Then start the debugger in the menu  or Ctrl-F5.

If you want to call your method with some predefined arguments, it is better to create another method that will call ..DoMyWork(.arg1, arg2) and use this method as your debug-target, or  better, in the debug menu, click on debug-target and add proper arguments in the classmethod.

If you wish to debug in terminal, you need to use the command Break with some options :

USER> Break "S+" Do ##class(MyPackage.MyClass).DoMyWork(.arg1)

^
<BREAK>zDoMyWork+1^...
USER 2d1> 
 

Option S or L with + or - depending if you want to debug instruction by instruction (S) or Line by line (L), debug into methods (+) or execute them(-).

Use G (or Goto) to go step by step, Use Break "C" to clear debugging.

More info on Break : https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GCOS_debug