This lesson describes how to create a sample COBOL application
that accesses the data in the USERID.FRIENDZ database
table.
To create the COBOL application, you need to create a DCLGEN
copy library for the USERID.FRIENDZ table:
- From the z/OS Projects or Enterprise
Projects view,
select your MVS subproject (created
at the beginning of this tutorial) and select New > Allocate
Partitioned Data Set from the pop-up menu.
- Name the new data set USERID.RDZDB2.JCL
and click Finish. The new
data set appears under your MVS subproject
name.
- To add a member to this data set, select the data set and
select New > Create Member from the pop-up
menu.
- Name the member RDZDCLS and click Finish.
- Allocate a data set called USERID.COBOL.COPYLIB using
the same method you used to allocate USERID.RDZDB2.JCL.
The proper data set attributes of USERID.COBOL.COPYLIB will
be applied by selecting Category: SOURCE and Type:
COBOL.
- Double-click member name RDZDCLS to
open it in the System z LPEX Editor.
- Copy and paste the following JCL segment into the edit
session:
//***********************************
//DCLGEN EXEC PGM=IKJEFT01
//SYSPRINT DD SYSOUT=*
//SYSTSPRT DD SYSOUT=*
//SYSTSIN DD *
DSN SYSTEM(DB2SUBSYSTEMNAME)
DCLGEN TABLE (USERID.FRIENDZ) LIBRARY ('USERID.COBOL.COPYLIB(RDZDCLS)') -
LANGUAGE (COBOL) STRUCTURE (FRIENDZRECORD) APOST
/*
- To use this JCL segment, append it to your own JOB card.
You may need a JOBLIB card to point to the DB2® data sets immediately following your JOB
card. You need to replace USERID in the JCL segment
with your high-level qualifier. You need to replace DB2SUBSYSTEMNAME with
your DB2 subsystem name.
- To submit the JCL stream, click Submit from
the pop-up menu. The copy member USERID.COBOL.COPYLIB(RDZDCLS) should
be created. You can find the copy member in the z/OS Projects or Enterprise
Projects view after you
have refreshed the data set USERID.COBOL.COPYLIB.
- Open the copy member in an edit session to familiarize
yourself with the declarations.
- Allocate a partitioned data set named USERID.RDZDB2.COBOL with
member RDZDB2 and copy and paste or retype the
following COBOL program into the member. This program
gets a value out of the FRIENDZ table.
IDENTIFICATION DIVISION.
PROGRAM-ID. RDZDB2.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 TEMP PIC X(6).
01 TEMP2 PIC X(6).
EXEC SQL INCLUDE SQLDA END-EXEC.
EXEC SQL INCLUDE SQLCA END-EXEC.
COPY RDZDCLS.
LINKAGE SECTION.
PROCEDURE DIVISION.
* EXEC SQL CONNECT TO DB2SUBSYSTEMNAME END-EXEC.
MOVE 'TYRONE ' TO FNAME.
EXEC SQL
SELECT FNAME, LNAME, PHONE, EMAIL
INTO :FNAME,
:LNAME,
:PHONE,
:EMAIL
FROM USERID.FRIENDZ
WHERE FNAME = :FNAME
END-EXEC.
DISPLAY "FIRSTNAME:".
DISPLAY FNAME.
DISPLAY "LASTNAME:".
DISPLAY LNAME.
DISPLAY "PHONE:".
DISPLAY PHONE.
DISPLAY "EMAIL:".
DISPLAY EMAIL.
GOBACK.
- Replace DB2SUBSYSTEMNAME with your DB2 subsystem name and USERID with
your schema name.