Top-Level Code Units Report

The Top-Level Code Units report provides a detailed overview of the Top-Level Code Units present in the source code.

What is a Top-Level Code Unit?

A Code Unit, as the name suggests, is the most atomic, standalone executable element. In most cases, these are statements, but they also include script files as well because those are executed as a single element.

Some Code Units can be nested inside other Code Units. When there is no other Code Unit above it in a hierarchy of Units, it's called a Top-Level Code Unit.

What is an out-of-scope Code Unit?

Out-of-scope Top-Level Code Units are Code Units that are out of the conversion scope of SnowConvert. Because of this, these code units are not considered when calculating the conversion rate. Each of these code units will not have a conversion rate (it will appear as N/A).

If the input code includes only out-of-scope Code Units, then the Lines of Code conversion rate of the entire migration will be 0%.

The following CREATE TRIGGER is considered an out-of-scope Code Unit.

CREATE OR REPLACE TRIGGER my_trigger
    AFTER 
    UPDATE
    ON my_table
    FOR EACH ROW
BEGIN
   NULL;
END;

Examples of Top-Level Code Units

In the following section, we can see some examples of Top-Level Code Units.

Queries

In the following example, we have here a single SELECT statement. This statement is a single Top-Level Code Unit.

SELECT * FROM table1;

In this example, we have a nested SELECT statement nested inside another SELECT statement. The entire query counts as a single Top-Level Code Unit.

SELECT * FROM (SELECT * FROM table1);

Objects

Objects created with a DDL count as a single Top-Level Code Unit, even if it contains other Code Units inside it.

The following statement creates a view with a query. In this case, the entire CREATE VIEW counts as a single Top-Level Code Unit.

CREATE VIEW view1 AS SELECT * FROM table1;

The following CREATE PROCEDURE statement counts as a single Top-Level Code Unit even if it contains multiple statements inside it.

CREATE PROCEDURE procedure1
AS
BEGIN
    DELETE FROM table1;
END;

Commands

Independent commands in an SQL file are considered Top-Level Code Units.

A COMMIT statement counts as a single Top-Level Code Unit.

COMMIT;

Package Bodies in Oracle

A package can define multiple elements inside its body. The package body is considered the Top-Level Code Unit because those elements cannot be created individually without creating the entire package body. Elements or code units inside a package body will not count as Top-Level Code Units.

The following code will be reported as a single CREATE PACKAGE BODY Code Unit.

CREATE PACKAGE package_body1 IS
    FUNCTION function1
    RETURN VARCHAR
    IS
    BEGIN
        RETURN 'HELLO'';
    END;
END;

Teradata Script files

Teradata Script files like BTEQ or TPUMP are executed as standalone code units. Because of this, the entire file is considered a single Top-Level Code Unit. Other possible code units inside these files will not count as Top-Level Code Units.

The following BTEQ script file will be reported as a single BTEQ Top-Level Code Unit.

script_file.btq
.LOGON e/fml,notebook
.COMPILE FILE = example.spl;
COMMIT;
CALL samplesp1 (8888, pAmount);
.LOGOFF

Transact SQL batches with GOTO

Each statement of Transact-SQL can be executed independently. In most cases, each of these statements is considered a Top-Level Code Unit. However, when there is a batch that contains a GOTO statement to a label inside the same batch, the statements of the batch cannot be executed independently without ensuring that they work properly. Because of this, statements that are in a batch with a GOTO statement will not count as Top-Level Code Units, only the batch.

The following code example will be reported as a single GOTO/LABEL Code Unit:

DECLARE @Counter int;  
SET @Counter = 1;  
WHILE @Counter < 10  
BEGIN   
    SELECT @Counter  
    SET @Counter = @Counter + 1  
    IF @Counter = 4 GOTO Branch_One
    IF @Counter = 5 GOTO Branch_Two  
END  
Branch_One:  
    SELECT 'Jumping To Branch One.'  
    GOTO Branch_Three;
Branch_Two:  
    SELECT 'Jumping To Branch Two.'  
Branch_Three:  
    SELECT 'Jumping To Branch Three.';
GO

How is the Code Unit methodology represented in other reports?

The Code Unit methodology is also represented in other reports. This section explains how these values are shown or are related to other reports.

Issues Report

Issues Report

Each row of the Issues Report has some information about the Code Unit that is being impacted by the issue. The columns related to Code Units are the following:

  • Code Unit Database: This is the Database of the Top-Level Code Unit where the issue was found. It only applies to Code Units that are objects.

  • Code Unit Schema: This is the Schema of the Top-Level Code Unit where the issue was found. It only applies to Code Units that are objects.

  • Code Unit Package: This is the Package of the Top-Level Code Unit where the issue was found. It only applies to Code Units that are objects.

  • Code Unit Name: This is the name Top-Level Code Unit where the issue was found. It only applies to named Code Units like objects. This name is not qualified by database, schema, or package.

  • Code Unit ID: This is the ID of the Top-Level Code Unit where the issue was found. This name has the name qualified and will add a number for code units with repeated names.

  • Code Unit: This is the type of the Top-Level Code Unit where the issue was found.

  • Code Unit Size: This is the size of the Top-Level Code Unit where the issue was found.

Object References Report and Missing Objects Report

Object References ReportMissing Objects Report

Each row of the Object References report has information about the Top-Level Code Unit that was referencing another element. These referenced elements may not be Top-Level, so those other values may not be included in the Top-Level Code Units report.

Similarly to the Object References report, the Missing Objects Report has information about the Top-Level Code Unit that was referencing an element that could not be found in the code.

  • Caller Code Unit: This is the type of the Top-Level Code Unit that is referencing another element.

  • Caller Code Unit Database: This is the database of the Top-Level Code Unit that is referencing another element.

  • Caller Code Unit Schema: This is the schema of the Top-Level Code Unit that is referencing another element.

  • Caller Code Unit Name: This is the name of the Top-Level Code Unit that is referencing another element.

  • Caller Code Unit Full Name: This is the full name of the Top-Level Code Unit that is referencing another element.

Information in the Top-Level Code Units Report

ColumnDescription

Partition Key

The unique identifier of the conversion.

File Type

The type of the file that the Code Unit is in. (SQL, BTEQ, etc...)