%Library.Routine
stream class %Library.Routine extends %Library.CharacterStream, %Library.AbstractStream
The %Routine class provides a way to create and manipulate routines stored within a database.The %Routine class provides a stream interface (see %AbstractStream) that allows you to read existing routines as well as create new one programmatically.
%Routine includes methods to save and compile modified routines.
For example, the following code creates, saves, and compiles a simple ObjectScript routine (note that lines of code start with a space character):
Set routine = ##class(%Routine).%New("MyRoutine.MAC") ; Write lines of code to the routine Do routine.WriteLine("MyRoutine") Do routine.WriteLine("Tag()") Do routine.WriteLine(" Write ""This is my routine"",!") Do routine.WriteLine(" Quit") ; save the routine Do routine.Save() ; compile the routine Do routine.Compile()
Property Inventory
- Generated
- IsModified
- LanguageMode
- Locked
- Name
- Namespace
- RoutineName
- RoutineType
- RoutineVersion
- TimeStamp
- UpToDate
Method Inventory
- %ExistsId()
- %IsModified()
- %ObjectModified()
- CheckProtect()
- CheckSyntax()
- Clear()
- Compile()
- CompileAll()
- CompileAllNamespaces()
- CompileList()
- CompileSelected()
- Delete()
- DeleteStream()
- Exists()
- Flush()
- GetCurrentTimeStamp()
- GetDate()
- GetObjectVersion()
- GetRoutineGlobals()
- LanguageModeGet()
- LanguageModeSet()
- LastModifiedGet()
- LineTerminatorGet()
- Lock()
- LockRoutine()
- MoveToEnd()
- NameGet()
- NamespaceGet()
- OpenStream()
- Read()
- ReadLine()
- Rewind()
- RoutineExists()
- RoutineListClose()
- RoutineListExecute()
- RoutineListFetch()
- RoutineListFetchRows()
- RoutineNameSet()
- RoutinesSortByFieldClose()
- RoutinesSortByFieldExecute()
- RoutinesSortByFieldFetch()
- RoutinesSortByFieldFetchRows()
- Save()
- SaveStream()
- SizeGet()
- Unlock()
- UpToDateGet()
- Write()
- WriteLine()
Properties
This is for backwards compatibility only.
For MAC routines it will be true if the generated pcode from compiling this MAC is up to date and false if recompiling this MAC would generate different pcode, so either the MAC has changed or the pcode has changed.
Methods
Returns %Boolean TRUE is it exists, FALSE if it does not.
Source - source (INT) code; either a single line stored in a variable, or an array where: array(0)=#lines, array(1-n)=source
Errors (byref) - Returned array of errors detected by compiler
LanguageMode - language mode, 0-10 (optional, default 0)
Returns a %Status value indicating success or failure.
For information on qSpec, see System Flags and Qualifiers.
This method will compile all routines in the current namespace.
Flags Bit string of options to method.
Bit 0 - Suppress syntax error display.
Bit 1 - Suppress output to principal device.
IO Already open device to send the output to. For example, "c:\a.out"
Count (by ref) Number of routines compiled.
Errors (by ref) Number of routines with syntax errors.
MultiCompile - If true then use multiple jobs to do the compile, if not specified use the default /multicompile qualifier setting
Journal - If true then journal the compile, if false disable journaling for compile, if not specified use the default /journal qualifier setting
KeepSource - If true (default) then keep INT code from compiling a MAC, if false then do not save INT code
This method will compile all routines in all namespaces. This will not compile routines in SYSTEM defined namespaces.
Flags Bit string of options to method.
Bit 0 - Suppress syntax error display.
Bit 1 - Suppress output to principal device.
IO Already open device to send the output to. For example, "c:\a.out"
Count (by ref) Number of routines compiled.
Errors (by ref) Number of routines with syntax errors.
MultiCompile - If true (default) then use multiple jobs to do the compile
Journal - If true (default) then journal the compile, if false disable journaling for compile
KeepSource - If true (default) then keep INT code from compiling a MAC, if false then do not save INT code
Mask Selection mask of which routines to compile. This mask is passed to %Library.Routine.RoutineList() and must be in a format it understands.
Flags Bit string of options to method.
Bit 0 - Suppress syntax error display.
Bit 1 - Suppress output to principal device.
IO Already open device to send the output to. For example, "c:\a.out"
Count (by ref) Number of routines compiled.
Errors (by ref) Number of routines with syntax errors.
MultiCompile - If true then use multiple jobs to do the compile, if not specified use the default /multicompile qualifier setting
Journal - If true then journal the compile, if false disable journaling for compile, if not specified use the default /journal qualifier setting
KeepSource - If true (default) then keep INT code from compiling a MAC, if false then do not save INT code
- 0 - Delete entire routine, for a MAC routine this will delete MAC, INT, OBJ. For an INT routine it will delete INT and OBJ, for a INC routine it will only delete the INC, for a BAS routine it will delete the BAS and the OBJ code.
- 1 - Delete just the named routine, for example for a MAC routine it will only delete the MAC and it will leave the INT and OBJ if present.
- 2 - Delete all the source code but leave any OBJ code.
If name consists of a routine name and an extension, such as INT, MAC, etc. then it will check for this specific routine. If it just contains the routine name it will check if either MAC, INT, or BAS exists.
Write ##class(%Routine).Exists("Test.MAC") Write ##class(%Routine).Exists("Test")
Returns Names="ROUTINE,rBACKUP,rINC,rINCSAVE,rINDEX,rMAC,rMACSAVE,rMAP,rOBJ,oddDEF"
Here is some documentation on the format of the routine globals.
ROUTINE - Native .INT COS code, generated from .MAC, or generated from classes. When compiled generates .OBJ code.
ROUTINE(Name,0)=timestamp when last saved
ROUTINE(Name,0,0)=# lines in routine
ROUTINE(Name,0,1...x) = Source Lines in routine
ROUTINE(Name,0,"GENERATED")= 0/1 whether routine is generated or native
ROUTINE(Name,0,"INC",IncludeFileName1)=Timestamp when last include file last saved
ROUTINE(Name,0,"INC",IncludeFileName2)=Timestamp when last include file last saved
ROUTINE(Name,0,"SIZE")=# bytes in routine
ROUTINE(Name,0,"LANG")=language mode
ROUTINE(Name,"MAC")=Timestamp of .MAC code when last saved if generated
rBACKUP(Name,Type,version) - backup of ^ROUTINE, created by the command Merge ^rBACKUP(rtn,type,nextverersion)=^ROUTINE(rtn) where type="INT/MVI/BAS"
rINC - Native .INT or macro code, compiled into .MAC when included with #include directive
rINC(Name,0)=timestamp when last saved
rINC(Name,0,0)=# lines in include file
rINC(Name,0,1...x) = Source Lines in include file
rINC(Name,0,"SIZE")=# bytes in include file
rINC("ZZ","P") - Meta data used for precompiling include files
rINCSAVE - Backup of ^rINC, created by the command Merge ^rINCSAVE(rtn,nextver)=^rINC(rtn,0)
rINDEX - Index of .OBJ, .INT, and .MAC routines
rINDEX(Name,"OBJ/MAC/INC")=$lb(Time compiled,Size)
rINDEX(Name,"INT")=$lb(Time compiled,Size,Generated 0/1)
rMAC - Native .MAC Macro code which when compiled generates .INT code
rMAC(Name,0)=Timestamp when last saved
rMAC(Name,0,0)=#lines in routine
rMAC(Name,0,1...x) = Source Lines in routine
rMAC(Name,0,"SIZE")=# bytes in routine
rMACSAVE(Name,Type,version) - backup of ^rMAC, created by the command Merge ^rMACSAVE(rtn,nextver)=^rMAC(rtn,0)
rMAP - Debug map used by the debugger and for error trapping
rMAP(Name,"INT","MAC",offsets)=$lb(debuginfo)
rMAP(Name,"MAC","INT",offsets)=$lb(debuginfo)
rOBJ - Compiled .INT code
rOBJ(Name,"INT")=timestamp of .INT code when compiled
rOBJ(Name,0...n)=Compiled object code
oddDEF - Source code for classes
oddDEF($zcvt(Name,"U"),....)=source code from class. Note that all of the other odd* nodes are meta data describing the class, and can be recreated by compiling the class. The rINDEXCLASS and rINDEXSQL nodes also get recreated when compiling the class.
Returns a %Status value indicating success or failure.
You must call Rewind() if you want to read a stream from the beginning again. Calling Read() after Write() implicitly ends the Write() operation and rewinds to the start of the stream.
Returns a string up to len characters long. The byref argument sc will return a %Status if any error occurred during the read.
While 'stream.AtEnd { Write stream.ReadLine(,.sc,.eol) If $$$ISERR(sc) { Write "ERROR" Quit } If eol { Write ! } }
Returns a %Status value indicating success or failure.
Note that a write operation immediately following a read or rewind will clear out the existing data in the stream.
Returns a %Status value indicating success or failure.
Returns a %Status value indicating success or failure.
Queries
Nsp1 and RouName1 specify the first routine.
Nsp2 and RouName2 specify the second routine.
Nsp1 and RouName2 can be either an explicit or an implied namespace.
spec may contain both * and ? as wildcards. It may also
consist of more than one, comma-delimited selections.
For example:
"*.MAC"
"A*.MAC"
"A?.MAC"
"A*.MAC,B*.MAC"
dir specifies the direction to search in, 1 is forwards
and -1 is backwards.
type is 1 to include OBJ files
in the search and the default, 0 will just include INT, MAC, INC, BAS.
nsp is the namespace to list from. If omitted, the query returns the routines from the current
namespace. nsp can be either an explicit or an implied namespace.
Spec may contain both * and ? as wildcards. It may also
consist of more than one, comma-delimited selections.
For example:
"*.MAC"
"A*.MAC"
"A?.MAC"
"A*.MAC,B*.MAC"
The Type is 1 to include OBJ files in the search and the default, 0 will just include INT, MAC, INC, BAS.
OrderBy is one of:
- Date - Date/Time the file was saved (the default)
- Size - Size of the file
- Type - Type of the file ie. INT, MAC, INC, BAS
nsp is the namespace to list from. If omitted, the query returns the routines from the current namespace. nsp can be either an explicit or an implied namespace.
Inherited Members
Inherited Properties
Inherited Methods
- %AddToSaveSet()
- %CheckUnique()
- %ClassIsLatestVersion()
- %ClassName()
- %ConstructClone()
- %Delete()
- %DeleteExtent()
- %DeleteId()
- %DispatchClassMethod()
- %DispatchGetModified()
- %DispatchGetProperty()
- %DispatchMethod()
- %DispatchSetModified()
- %DispatchSetMultidimProperty()
- %DispatchSetProperty()
- %Exists()
- %Extends()
- %GetParameter()
- %GetSwizzleObject()
- %Id()
- %IsA()
- %IsNull()
- %KillExtent()
- %LOBPrefetch()
- %LocationSet()
- %LockStream()
- %New()
- %NormalizeObject()
- %ObjectIsNull()
- %ObjectSize()
- %Oid()
- %Open()
- %OpenId()
- %OriginalNamespace()
- %PackageName()
- %ReleaseLock()
- %Reload()
- %RemoveFromSaveSet()
- %RollBack()
- %Save()
- %SerializeObject()
- %SetModified()
- %UnlockStream()
- %ValidateObject()
- CopyFrom()
- CopyFromAndSave()
- DeleteAttribute()
- FindAt()
- GetAttribute()
- GetAttributeList()
- GetStreamId()
- InputFromDevice()
- IsCharacter()
- IsDefinedAttribute()
- IsNull()
- LineTerminatorSet()
- MoveTo()
- NextAttribute()
- OutputToDevice()
- OutputToDeviceAt()
- ReadLineIntoStream()
- ReadSQL()
- SerializeToSyncSet()
- SetAttribute()
- SetAttributeList()
- StreamOIDIsNull()
- SyncStreamIn()