Debug the SPCall Program and Stored Procedure - Multi-project Data Name

Provides step-by-step instructions to associate and start the JCLSPMDN enterprise server region, set debug properties and breakpoints, debug the SPCall and SP1 stored procedure, view the JCL execution results, and stop the JCLSPMDN enterprise server region.

Associate the JCLSPMDN Region with the SPCall Project

  1. In the Visual Studio Server Explorer, expand Micro Focus Servers > Default.
  2. Right-click JCLSPMDN; then select Associate With Project > SPCall from the context menu.

Start the JCLSPMDN Region

  1. On the Server Explorer list, right-click JCLSPMDN; then select Start from the context menu.
  2. If you are using SQL Server authentication, check Server is secured; then provide your Username and Password.

    If you are using Windows authentication, skip this step.

  3. Click OK.

Configure SQL Server Debug Properties

  1. In Visual Studio, click View > SQL Server Object Explorer.
  2. Expand SQL Server.
  3. In the list of SQL Server instances, expand your SQL Server instance.
    Note: If your SQL Server instance is not listed:
    1. On the SQL Server Object Explorer, right-click SQL Server; then select Add SQL Server from the context menu.
    2. On the Connect to Server dialog box, type . (dot) into the Server name field; then click Connect.
    3. Repeat this step.
  4. Expand Databases; then check the resulting list to ensure that SQLCLR_Test is listed.
  5. Right-click your SQL Server instance; then select Application Debugging to turn it on. When Application Debugging is on, a check mark Check Mark appears to its left.
  6. Right-click your SQL Server instance again; then select Allow SQL/CLR Debugging to turn it on.
  7. If prompted, click Yes.

Set Breakpoints

Set a breakpoint in SPCall and in SP1 in preparation for debugging the application.

  1. In the Solution Explorer, double-click SPCall.cbl to open it in the COBOL editor.
  2. In the COBOL editor, scroll to:
    move "SP1" to progname
    exec sql
        call :progname (:countval INOUT)
    end-exec
  3. In the leftmost column on the exec sql line, click to set a breakpoint.
  4. From the Solution Explorer, open SP1.cbl.
  5. Scroll to:
    set progname to "A"
    call progname using by reference lscountval
    and set a breakpoint.

Debug the Program and Stored Procedure

In this section, you use Enterprise Developer to debug the native COBOL program and the SQL CLR stored procedure.

  1. From the Visual Studio main menu, click DEBUG > Start Debugging. This builds the project and puts the debugger in a wait state.
  2. In the Solution Explorer, right-click the SPCall.jcl file; then select Submit JCL from the context menu.

    The JCL script calls the SPCall program and stops on the first statement in the program. Press F5 to continue to the breakpoint you set in the SPCall.cbl file.

  3. Click DEBUG > Attach to Process.
  4. On the Attach to Process dialog box, click Select.
  5. On the Select Code Type dialog box, click Debug these code types; then check the following boxes:
    • Managed (.NET 4.x) or .NET (4.5, v4.0) depending on your version of Visual Studio.
    • T-SQL
  6. Click OK.
  7. On the Attach to Process dialog box, check Show processes for all users.
  8. On the Available Processes list, select the sqlservr.exe entry that has the NT Service\MSSQLServer User Name. If you are using a SQL Server named instance, the User Name to select will have the format NT Service\MSSQL$<instanceName>.
  9. Click Attach.
    Note: If a prompt appears, click Attach to clear it.
  10. Click DEBUG > Step Into.

    The debugger steps into the managed SQL CLR stored procedure code. This demonstrates debugging in a mixed native/.NET environment.

  11. To continue debugging, press F10; when the debugger reaches another breakpoint, press F10 again.
  12. Press F5 to run the program to its completion.
  13. Click Stop Debugging Stop Debugging to stop the Debugger.

View JCL Execution Results

  1. In Server Explorer, right-click on the JCLSPMDN region and select Show Spool.
  2. Click the Refresh button in the JCLSPMDN Spool tool window.
  3. In the DD Entries, click the DD Name SYSOUT.
  4. Expand the SYSOUT Display section in the tool window.

    This shows the output from the SQL CLR Stored Procedure.

    The correct output is 0000000025.

Stop the JCLSPMDN Enterprise Server Region

  • On the Server Explorer, right-click JCLSPMDN; then select Stop from the context menu.

This concludes the tutorial.