Question
· Jul 29

Is it possible to control the order of methods?

Hi, 
I have a code that copy a method to another class for analysis purpose.

I also want this method to appear first in the source code to easily use it in VSCode with the classmethod debug button and not search it in the numerous method of the modified class.
Is there a way to do such a thing?
I tried the placeAfter keyword but I can't find a way to make it really work as I want. Is their other ways to control the order of methods?

Product version: IRIS 2025.2
Discussion (2)3
Log in or sign up to continue

There are 2 options:

1. access the raw code for classes is stored in ^oddDEF global. all class methods are store in this format: ^oddDEF(className,"m",methodName,11)=sequence
where the sequence is 1,2,3...
If you are going to manually manipulate this don't forget to compile: do $system.OBJ.Compile("className","ckr")

2. using SQL:
SELECT ID,Name,SequenceNumber FROM %Dictionary.MethodDefinition where parent='className' order by SequenceNumber
I'm not sure if you need to compile after an UPDATE to this table (but its easy test).

Thank you!
I tried an SQL update first but I got an error :

<Insert/Update operations not supported on this table.>

For the global solution it work fine for me but only if the new method asn't been compiled before

So first add the method then change the global value and finaly compile.

          // Clone the source method and insert it as the first method in the imported class
          if (debug) { write "adding methodname classmethod to "_className,!}
          set clonedMethod = method.%ConstructClone()
          set tSC = classDefinition.Methods.Insert(clonedMethod)
          if ($$$ISERR(tSC)) { quit }
          set tSC = classDefinition.%Save()
          if ($$$ISERR(tSC)) { quit }
 
          // we set the method in first position
          set ^oddDEF(className,"m",methodName,11)=1
 
          // we recompile the class
          set tSC =  $system.OBJ.Compile(classDefinition.Name, "cbk")


If you need to move an already existing methods I suppose that removing it and compiling before should  work fine but is a naive solution(in my case I don't need it).