Skip to main content
InterSystems IRIS for Health 2024.3
AskMe (beta)

Scanning for Deprecated Code

The class %SYSTEM.CodeScannerOpens in a new tab enables you to quickly find code that refers to deprecated classes and deprecated class members. Specifically, this class provides the ScanDocuments class query, which returns a result set that contains the following three 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.

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  
    }
}

See Also

FeedbackOpens in a new tab