Skip to main content

Using the Code Scanner

The class %SYSTEM.CodeScannerOpens in a new tab enables you to quickly find code that refers to deprecated classes and deprecated class members. It also provides an way to find any system code that was changed after installation (such as the installation of patch ad hocs).

ScanDocuments Query

The ScanDocuments class query returns a result set that contains the following fields:

  • Document identifies the class or routine that contains the reference. For example:

    ResearchXForms.BasicDemo.cls
    
  • Location identifies the location of the reference, within the given class or routine. For example:

    ClassMethod CreateOne Implementation+4
    
  • Message explains what is deprecated. For example:

    Class '%Library.FileBinaryStream' is deprecated.
    

By default, the query scans only classes and routines in the default routine database for the current namespace, although you can pass a parameter to include mapped code. Also, the query ignores classes and routines that have names starting with %, as well as any classes that are marked as deprecated.

The query is projected to SQL as the %SYSTEM.ScanDocuments stored procedure.

ScanDocument Query

The ScanDocument class query takes one argument document, which is the name of a class, MAC routine, or INT routine. This argument includes the file extension, for example: MyPkg.MyClass.cls

This query returns a result set that contains the following fields:

  • Location indicates the line number or class keyword describing where the deprecated reference is, within the given code item.

  • Message string describing the deprecated reference.

Example

For example, you could write code as follows:

ClassMethod Check()
{
    set stmt = ##class(%SQL.Statement).%New()
    set status = stmt.%PrepareClassQuery("%SYSTEM.CodeScanner","ScanDocuments")
    if $$$ISERR(status) {quit}
    set rset = stmt.%Execute()
    if rset.%SQLCODE<0 {quit}

    while rset.%Next() {
        set Document=rset.%Get("Document")
        set Location=rset.%Get("Location")
        set Message=rset.%Get("Message")
        write !, Document_" "_Location_" "_Message  
    }
}

The following shows example output:

ResearchXForms.BasicDemo.cls Property BinStream Type Class '%Library.GlobalBinaryStream' is deprecated.
ResearchXForms.BasicDemo.cls Property CharStream1 Type Class '%Library.GlobalCharacterStream' is deprecated.
ResearchXForms.BasicDemo.cls Property CharStream2 Type Class '%Library.GlobalCharacterStream' is deprecated.
ResearchXForms.BasicDemo.cls Property CharStream3 Type Class '%Library.GlobalCharacterStream' is deprecated.
ResearchXForms.BasicDemo.cls ClassMethod CreateOne Implementation+4 Class '%Library.FileBinaryStream' is deprecated.
ResearchXForms.BasicDemo.cls ClassMethod RoundTripBin Implementation+1 Class '%Library.FileBinaryStream' is deprecated.

Scanning Mapped Code

By default, the query scans only classes and routines in the default routine database for the current namespace. To include classes and routines from mapped databases, specify the query argument as 1, by passing that argument when executing the class query. For example:

ClassMethod Check()
{
    set stmt = ##class(%SQL.Statement).%New()
    set status = stmt.%PrepareClassQuery("%SYSTEM.CodeScanner","ScanDocuments")
    if $$$ISERR(status) {quit}
    set rset = stmt.%Execute(1)
    if rset.%SQLCODE<0 {quit}

    while rset.%Next() {
        set Document=rset.%Get("Document")
        set Location=rset.%Get("Location")
        set Message=rset.%Get("Message")
        write !, Document_" "_Location_" "_Message  
    }
}

ModifiedSystemDocuments Query

%SYSTEM.CodeScannerOpens in a new tab also provides the ModifiedSystemDocuments query, which enables you to identify any system code that was changed after installation (such as the installation of patch ad hocs). To run this query, you must hold the %Admin_Manage:USE privilege.

For example:

 set x = ##class(%SQL.Statement).%New() 
 do x.%PrepareClassQuery("%SYSTEM.CodeScanner","ModifiedSystemDocuments") 
 do x.%Execute().%Display()

This displays a report listing all the routines and classes that were modified after installation. For each modified document, the utility reports the corresponding modification timestamp. When a document was modified by some ad‑hoc patches, the number of the last applicable patch is also included.

See Also

FeedbackOpens in a new tab