Takes you through each step in the process of generating a COBOL wrapper for a SQL CLR stored procedure.
- Requirements
- Before attempting this tutorial, you must first complete the following SQL CLR Integration tutorials to ensure you have an
established SQL Server database named SQLCLR_Test and a connection to that database:
- Tutorial: Enable SQL CLR Integration
- Tutorial: Create a Sample Database
- Tutorial: Create and Configure a Database Project
- Add COBOL Source to the Project
- We provide a sample COBOL program,
GETHIRE.cbl, that receives an employee number, and returns the employee's first name, last name, and hire date. In this phase, you add
this COBOL program and its required copybook,
EMP.cpy, to your
SQL Server Database Project.
- From the Solution Explorer, right-click the
SQLCLRTutorial COBOL project, and click
Add >
Existing Item.
- Browse to the
%PUBLIC%\Documents\Micro Focus\Enterprise Developer\Samples\sql\sqlclr directory.
- From the
Objects of type drop-down list, click
COBOL Files (*.cbl, *.cpy, *.cob).
- Select the
GETHIRE.cbl and
EMP.cpy files; then click
Add.
- Create a Stored Procedure Definition File and Skeleton COBOL File
- You need to create a stored procedure definition file (.spd file) that contains the stored procedure definition from which to generate the COBOL wrapper program.
- From the Solution Explorer, right-click the
SQLCLRTutorial COBOL project, and click
Add >
New Item.
- Under
Installed Templates, click
COBOL.
- In the center pane, click
Stored Procedure Definition.
- In the
Name field, type
SQLCLRStoredProc.spd; then click
Add.
This adds an empty
SQLCLRStoredProc.spd file to the project and opens it in Visual Studio. It also generates a skeleton COBOL file named
SQLCLRStoredProc.mssp.cbl and adds it to the project.
- Define the Stored Procedure and Generate the COBOL Wrapper
- These two steps are done automatically in one phase.
- Cut the following Stored Procedure definition code from this tutorial and paste it into the empty
SQLCLRStoredProc.spd file open in Visual Studio:
CREATE PROCEDURE TEST.GETHIRE
( IN EMPNO CHAR (6)
,OUT FIRST_NAME VARCHAR (12)
,OUT LAST_NAME VARCHAR (16)
,OUT HIRE_DATE DATE
,OUT OT_SQLCODE INTEGER
)
RESULT SETS 0
PARAMETER STYLE GENERAL
;
- Save the
SQLCLRStoredProc.spd file. This automatically generates the COBOL wrapper code, saving it to the
SQLCLRStoredProc.mssp.cbl file.
- In the Solution Explorer, double-click
SQLCLRStoredProc.mssp.cbl to see the generated COBOL wrapper code.
- Save and close the
SQLCLRStoredProc.spd and
SQLCLRStoredProc.mssp.cbl files.
Note: As an alternative, you could also generate the code for the
.spd file using the HCOSS Generate SPD File tool, add the resulting file to the project, and generate the COBOL wrapper program
using the
SPDFileCodeGenerator custom tool available from the context menu associated with the
.spd file.
- Publish the COBOL Wrapper Application
-
- From the Solution Explorer, right-click the
SQLCLRTutorial.Publish project, and click
Publish.
- Execute the Stored Procedure
-
- In Visual Studio, open the SQL Server Object Explorer.
- Expand the
SQLCLR_Test.dbo data connection.
- Expand
Stored Procedures.
- Right-click
GETHIRE, and select
Execute.
- Provide the following Values for the corresponding Names:
Name
|
Value
|
@lkEMPNO
|
000200
|
@lkFIRST_NAME
|
<NULL>
|
@lkLAST_NAME
|
<NULL>
|
@lkHIRE_DATE
|
<NULL>
|
@lkOT_SQLCODE
|
0
|
- Click
OK. The data appears in the
Output window:
Running [dbo].[GETHIRE] ( @lkEMPNO = 000200, @lkFIRST_NAME = <NULL>, @lkLAST_NAME = <NULL>, @lkHIRE_DATE = <NULL>, @lkOT_SQLCODE = 0 ).
No rows affected.
(0 row(s) returned)
@lkFIRST_NAME = DAVID
@lkLAST_NAME = BROWN
@lkHIRE_DATE = 1966-03-03
@lkOT_SQLCODE = 0
@RETURN_VALUE =
Finished running [dbo].[GETHIRE].
This completes the tutorial.