This tutorial shows how to execute DB2 statements from within a DSNREXX procedure. This is done by creating a JCL project
and then associating it with an XA resource, enabling you to run a DSNREXX procedure using sample JCL provided with
Enterprise Developer.
Prerequisites
To complete this tutorial, you need the following software in addition to
Enterprise Developer:
- IBM's DB2 Database for Linux, UNIX, and Windows (LUW). See
Additional Software Requirements for more information. You can download a version of DB2 to use in the tutorial from IBM's website -
click here.
- Windows Software Development Kit (SDK) installed for your version of Windows. You can download the Windows 10 SDK from the
Windows Dev Center website -
click here.
Note: You need to ensure that you use 32-bit versions for the following tools and utilities:
- ODBC Data Source Administrator (32-bit) or ODBC Data Sources (32-bit), depending on your version of Windows.
- Enterprise Developer command prompt (32-bit).
- The LIB environment variable should contain the path to your Windows SDK LIB directory (x86) containing
odbc32.lib.
Installing DB2
For the purposes of this tutorial you can install a copy of DB2 Express-C. The following points can help you install DB2 for
use in this tutorial:
- When prompted in the installation setup, select the typical installation type.
- You do not need to save your settings in a response file, but this may be useful when using DB2 in the future.
- Use the default installation directory.
- Leave the default settings when you select the IBM SSH server installation folder and startup option.
- Always secure your DB2 administration server with a strong password.
- You do not need to configure the DB2 instances, use the default instance configuration.
Creating a DB2 LUW sample database
If you do not already have a sample database you will need to create one. You can create a sample database by running the
db2sampl utility. The utility is part of the DB2 installation:
- Start an
Enterprise Developer command prompt (32-bit) by clicking
Run as administrator.
- Type
db2sampl -sql
- To verify that the database can be connected to, start a DB2 Command Window.
- Type
DB2 CONNECT TO SAMPLE USER
user-id USING
password
You are presented with database connection information, for example:
Database Connection Information
Database server = DB2/NT64 11.1.0
SQL authorization ID = user-id
Local database alias = SAMPLE
Note: See the DB2 LUW documentation for more information on how to create or catalog the SAMPLE database. Click
Start, and type
DB2 Information Center. Choose
DB2 Information Center, and search for "Create Sample database" or "Catalog database" as required.
Catalog the sample database as an ODBC data source
If your sample database has not been cataloged as an ODBC data source, then perform the following steps:
- From your Windows desktop, click
Start or use the shortcut keys
Ctrl+Esc. In the search field, type
ODBC.
- In the search results list, select
ODBC Data Source Administrator (32-bit) or
ODBC Data Sources (32-bit), depending on your version of Windows.
This opens the 32-bit version of the
ODBC Data Source Administrator tool.
- Click
System DSN tab.
- Click
Add.
This opens the
Create New Data Source dialog box.
- Click
IBM DB2 ODBC DRIVER.
- Click
Finish.
This opens the
ODBC IBM DB2 Driver - Add dialog box.
- In the
Data source name field, type
SAMPLE
- In the
Database alias list, select the
SAMPLE database.
- Optionally, in the
Description field, type a description for your data source.
- Click
OK.
- On
System DSN tab, click
SAMPLE, and then click
Configure.
- Specify the user ID and password to connect to the database, then click
Connect.
- Click
OK twice.
Create an ODBC XA switch module
If you have not already created the ODBC XA switch module, perform the following steps:
Note: To build the ODBC XA switch module, you must have the Windows Software Development Kit (SDK) installed for your version of
Windows. Before building the switch module, ensure that your LIB environment variable contains the path to your Windows SDK
LIB directory containing
odbc32.lib.
- Start an
Enterprise Developer command prompt (32-bit) by clicking
Run as administrator.
- Change to the
%ProgramFiles(x86)%\Micro Focus\Enterprise Developer\src\enterpriseserver\xa
directory.
- Enter
build odbc
Note: Make a note of the switch module name created, it is used in subsequent steps.
Create a working directory for your project
- Create the working directory on your machine, for example
C:\Users\Public\REXXSAMPLE
- Create a
REXX subdirectory.
Create an MSS project
- In Visual Studio, click
.
- In the
Create a new project dialog box, select
COBOL from the
Language drop-down list.
- Select
Mainframe Subsystem Application.
- Click
Next.
- Specify
REXXJCL as the project name.
- In the
Location field, specify the working directory, for example
C:\Users\Public\REXXSAMPLE
- Ensure that
Place solution and project in the same directory is checked.
- Click
Create.
Add a JCL file to run DSNREXX
You can use the IKJEFT01 or IRXJCL utility to run REXX exec statements. The following JCL jobstream runs the REXX script named
Test1:
- In Solution Explorer, right-click your project.
- Click
.
This opens the
Add New Item - REXXJCL dialog box.
- Expand
.
- Click
JCL File.
- In the
Name field, type
Test1.jcl.
- Click
Add.
- In the
Test1.jcl file, paste the following code:
//REXXTEST JOB 'TEST DSNREXX SUPPORT',CLASS=A,MSGCLASS=A
//*
//* Test the REXX engine using IKJEFT01
//*
//STEP10 EXEC PGM=IKJEFT01
//SYSEXEC DD DSN=USER.TEST.EXEC,DISP=SHR
//SYSTSIN DD *
Test1
//SYSPRINT DD SYSOUT=*
//SYSTSPRT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//*
//* Test the REXX engine using IRXJCL
//*
//STEP20 EXEC PGM=IRXJCL,PARM='Test1'
//SYSEXEC DD DSN=USER.TEST.EXEC,DISP=SHR
//SYSTSPRT DD SYSOUT=*
//SYSTSIN DD DUMMY
- Click
.
Create an MSS-enabled
Enterprise Server
Now you want to create an
enterprise server region with Mainframe Subsystem (MSS) for JCL use:
- In Solution Explorer, right-click your project.
- Click
.
This opens the
Create New Enterprise Server dialog box.
Note: If you are prompted with an
Enterprise Server Sign On dialog box, click
OK without specifying any sign-on details. This is a standard security dialog box.
- In the
Name field, type
REXX32
- Click
Browse next to the
Template field.
- Click
JCLTemplate.
- Click
Open.
- Click
OK.
Add an XA resource for REXX procedures pointing to the DB2 LUW SAMPLE database
Now that the
enterprise server region is created, you need to set up an XA resource:
- In Server Explorer, right-click
Micro Focus Servers.
- Click
Administration.
This opens the
Enterprise Server Common Web Administration (ESCWA) interface in your default Web browser.
- In
ESCWA, click
Native.
- In the navigation pane, click
.
- Click
REXX32
- Click
.
- Click
* New.
This opens the
XA Resource Configuration dialog box.
- In the
ID field, type
DB2T
- In the
Name field, type
REXXPROC
- In the
Module field, type the location and name of the ODBC XA switch module created in the earlier steps, for example:
C:\Program Files (x86)\Micro Focus\Enterprise Developer\src\enterpriseserver\xa\ESODBCXA.dll
Note: When specifying the location and name of the ODBC XA switch module, do not enter an environment variable such as
%ProgramFiles(x86)%. Ensure that you use an expanded path.
- In the
Open string field, type
DSN=SAMPLE
Where
SAMPLE is the
Data source name specified in the
ODBC Data Source Administrator.
- You may need to add the ID and PASSWORD if connecting to a remote database. See
Generic one-phase commit for ODBC xa_open string for more information.
- Click
Save.
See
To define an XA resource (XAR) for an enterprise server region for more information.
Configure the program paths for data set catalog
You need to specify the JES program paths so that
Enterprise Server automatically finds the application files that it needs to run:
- In Windows File Explorer, in the
C:\Users\Public\REXXSAMPLE directory, create a subdirectory named
Test1.
- In
ESCWA, click
.
- In the
JES Program Path field, leave the default value unchanged, $IDE_LOADLIB.
- In the
System Catalog field, type
C:\Users\Public\REXXSAMPLE\Test1\catalog.dat
- In the
Default Allocated Dataset Location field, type
C:\Users\Public\REXXSAMPLE\Test1
- In the
System Procedure Library field, leave the default value unchanged, SYS1.PROCLIB
- Click
Apply.
Start the
enterprise server region
- In Server Explorer, expand
Micro Focus Servers and then
localhost.
- Right-click
REXX32, and then click
Start.
Note: The
Enterprise Server Sign On dialog box might prompt you to provide connection details for the server. This is a standard security dialog box. Click
OK without specifying any sign-on details. Also, if prompted to disable password recovery, click
No.
- If you receive a Windows Security Alert for the MF Communications Process, click
Allow access.
Alternatively:
- In
ESCWA, click
.
- Click
Start.
Catalog the directories that have the REXX procedures
You need to specify the catalog file that holds details of the data sets required by the JCL job that run in an
enterprise server region. To do this you need to create a Dynamic PDS. See
Dynamic PDSs for more information.
- In Server Explorer, right-click
REXX32 under
localhost.
- Click
Show Catalog.
- Click
(Add data set entry).
The
New Catalog dialog box is displayed.
- In the
DS Name field, type
USER.TEST.EXEC
- In the
Physical File field, type
C:\Users\Public\REXXSAMPLE\REXX
- From the
DS Org field, select
PO.
- From the
RECFM field, select
LSEQ.
- Check
Dynamic PDS.
- In the
PDS Extensions field, type
rex
- Click
Create.
Copy the REXX script from the samples directory
- Copy the
Test1.rex file, from the
%PUBLIC%\Documents\Micro Focus\Enterprise Developer\Samples\Mainframe\SQL\OpenESQL\DSNREXX\Test1\Scripts sample directory to the
C:\Users\Public\REXXSAMPLE\REXX directory.
To run the JCL job
- In Solution Explorer, expand the project to show the
Test1.jcl file.
- Right-click the
Test1.jcl file, and then click
Submit JCL.
View the spool output
You can check the result of submitting the JCL job by viewing the spool:
- In the
REXX32 Spool tool window, click the
Refresh button.
- Click
REXXTEST.
This provides more information on the job submitted.
- Expand the
SYSTSPRT Display area.
- In
DD Entries, click the
SYSTSPRT entries under the DD Name column to see the output in the
SYSTSPRT Display area.
The following message or similar is displayed for STEP10:
DROPPING REXTEST1 TABLE
INSERTING DATA
PREPARING S1
FETCHING DATA
TEST PASSED -33329.3333
INSERTING DATA USING INSQLDA
PREPARING S3
FETCHING DATA USING OUTSQLDA
TEST PASSED -33329.3333
In this tutorial, you learned how to execute a DSNREXX procedure containing DB2 statements from JCL. You cataloged an ODBC
connection and built an ODBC XA switch module. You created a sample mainframe subsystem project, added a JCL script to call
a DSNREXX script, created an Enterprise Server region, and defined an XA resource to use your ODBC connection. You set up
the region's program paths and created a dynamic PDS catalog file. After running the JCL, you viewed the DSNREXX output from
the Enterprise Server spool for the job.