Rational Developer for System z


Create the sample COBOL application

This lesson describes how to create a sample COBOL application that accesses the data in the USERID.FRIENDZ database table.
This lesson assumes that you know how to allocate a data set in an MVS™ subproject.
To create the COBOL application, you need to create a DCLGEN copy library for the USERID.FRIENDZ table:
  1. 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.
  2. Name the new data set USERID.RDZDB2.JCL and click Finish. The new data set appears under your MVS subproject name.
  3. To add a member to this data set, select the data set and select New > Create Member from the pop-up menu.
  4. Name the member RDZDCLS and click Finish.
  5. 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.
  6. Double-click member name RDZDCLS to open it in the System z LPEX Editor.
  7. 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
    /* 
  8. 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.
  9. 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.
  10. Open the copy member in an edit session to familiarize yourself with the declarations.
  11. 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.
  12. Replace DB2SUBSYSTEMNAME with your DB2 subsystem name and USERID with your schema name.

Feedback