Takes you through each step in the process of generating a COBOL wrapper for a SQL CLR stored procedure.
Prerequisites
- Review the
Assumptions and
Before you begin sections in the
Tutorials: SQL Server COBOL Stored Procedures topic to ensure that your environment is set up properly.
- Before attempting this tutorial, you must first work through
Tutorial: Prepare the SQL Server COBOL Environment.
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
.
- From the
Solution Explorer, right-click the
SQLServerSP 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
SQLServerSP COBOL project, and click
Add >
New Item.
- In the left pane, click
COBOL.
- In the center pane, click
Stored Procedure Definition.
- In the
Name field, type
SQLServerSPDef.spd; then click
Add.
This adds an empty
SQLServerSPDef.spd file to the project and opens it in Visual Studio. It also generates a skeleton COBOL file named
SQLServerSPDef.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
SQLServerSPDef.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
SQLServerSPDef.spd file. This automatically generates the COBOL wrapper code, saving it to the
SQLServerSPDef.mssp.cbl file.
- In the
Solution Explorer, double-click
SQLServerSPDef.mssp.cbl to see the generated COBOL wrapper code.
- Save and close the
SQLServerSPDef.spd and
SQLServerSPDef.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
SQLServerSP.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.