|
|
Customer
Database, Cursor Processing COBOL, Embedded SQL & Sequential Processing http://www.simotime.com |
| When technology complements business | Copyright © 1987-2010 SimoTime Enterprises All Rights Reserved |
The technique of retrieving data with SQL one row at a time is referred to as cursor processing. This example will show how to process a data base sequentially by key using cursor processing. In the world of programming there are many ways to solve a problem. This suite of programs is provided as a COBOL programming example of one of the possible solutions.
The following is the Windows Command file (CUQCP1E1.CMD) that is required to run as a job on a PC using Micro Focus Net Express.
@echo OFF
rem * *******************************************************************
rem * This program is provided by: *
rem * SimoTime Enterprises, LLC *
rem * (C) Copyright 1987-2010 All Rights Reserved *
rem * Web Site URL: http://www.simotime.com *
rem * e-mail: helpdesk@simotime.com *
rem * *******************************************************************
rem *
rem * Text - COBOL with embedded SQL for Cursor Processing
rem * Author - SimoTime Enterprises
rem * Date - November 11, 2003
rem * Version - 08.07.25
rem *
rem * This set of programs illustrate the use of embedded SQL in a COBOL
rem * program that fetches one row at a time from the CUST data base. A
rem * sequential file containing one record for each row is created.
rem *
rem * This technique provides for the use of a single COBOL source
rem * program that will run on ZOS, Windows or Unix.
rem *
rem * This set of programs will run on a Personal Computer with Windows
rem * and Micro Focus Net Express or Mainframe Express.
rem *
rem * ************
rem * * CUQCP1E1 *
rem * ********cmd*
rem * *
rem * *
rem * ************ ************ ************
rem * * CUSTRDB1 *-----* CUQCP1C1 *-----* CUSTSEQ1 *
rem * ********rdb* ********cbl* *******rseq*
rem * *
rem * *
rem * ************
rem * * EOJ *
rem * ************
rem *
echo *
echo * The SQL Server must be started prior to executing this command.
echo *
set CmdName=CUQCP1E1
call ezPROD01
call SimoNOTE "*******************************************************%CmdName%"
call SimoNOTE "Starting JobName %CmdName%"
set CUSTSEQ1=%DataLib1%\Dyn1\SIMOTIME.DATA.CUSTSEQ1.DAT
run CUQCP1C1
if errorlevel = 1 set JobStatus=0001
if not "%JobStatus%" == "0000" goto :EojNOK
:EojAOK
call SimoNOTE "Finished JobName %CmdName%"
goto :End
:EojNOK
call SimoNOTE "ABENDING JobName %CmdName%"
call SimoNOTE "ABENDING Message JobStatus %JobStatus%"
goto :End
:End
if not "%1" == "nopause" pause
rem * End-of-Command-File...
The following is the mainframe JCL (CUQCP1J1.JCL) that is required to run as a job on the mainframe or as a Mainframe Express project on the PC.
//CUQCP1J1 JOB SIMOTIME,ACCOUNT,CLASS=1,MSGCLASS=0,NOTIFY=CSIP1
//* *******************************************************************
//* This program is provided by: *
//* SimoTime Enterprises, LLC *
//* (C) Copyright 1987-2010 All Rights Reserved *
//* Web Site URL: http://www.simotime.com *
//* e-mail: helpdesk@simotime.com *
//* *******************************************************************
//*
//* TEXT - Execute COBOL program, use CURSOR Processing of a Table.
//* AUTHOR - SimoTime Enterprises
//* DATE - January 01, 1989
//*
//* This set of programs illustrate the use of a COBOL program with
//* embedded SQL syntax. This program will FETCH one row at a time
//* using Cursor Processing.
//*
//* This set of programs will run on a mainframe under ZOS or on
//* a personal computer running Windows and Mainframe Express (MFE)
//* by Micro Focus.
//*
//* ************
//* * CUQCP1J1 *
//* ********jcl*
//* *
//* *
//* ************
//* * IKJEFT01 *
//* ********dbm*
//* *
//* *
//* ************ ************ ************
//* * CUSTRDB1 *-----* CUQCP1C1 *-----* CUSTSEQ1T *
//* ********rdb* ********cbl* *******rseq*
//* *
//* *
//* ************
//* * EOJ *
//* ************
//*
/* *******************************************************************
//* Step 1 of 2 Delete any previously created file...
//*
//SEQ1DELT EXEC PGM=IEFBR14
//CUSTSEQ1 DD DSN=SIMOTIME.DATA.CUSTSEQ1,DISP=(MOD,DELETE,DELETE),
// STORCLAS=MFI,
// SPACE=(TRK,5),
// DCB=(RECFM=FB,LRECL=512,BLKSIZE=5120,DSORG=PS)
//* *******************************************************************
//* Step 2 of 2 Start the relational data base step.
//*
//FETCH EXEC PGM=IKJEFT01
//CUSTSEQ1 DD DSN=SIMOTIME.DATA.CUSTSEQ1,DISP=(NEW,CATLG,DELETE),
// STORCLAS=MFI,
// SPACE=(TRK,5),
// DCB=(RECFM=FB,LRECL=512,BLKSIZE=5120,DSORG=PS)
//SYSPRINT DD SYSOUT=*
//SYSTSPRT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSTSIN DD *
DSN SYSTEM (XDB1)
RUN PROG (CUQCP1C1)
END
//
The following (CUQCP1C1.CBL) is a sample of the COBOL demonstration program that processes a table one row at a time. The program uses the SQL FETCH statement to sequentially access the rows in the table.
IDENTIFICATION DIVISION.
PROGRAM-ID. CUQCP1C1.
AUTHOR. SIMOTIME ENTERPRISES.
*****************************************************************
* Copyright (C) 1987-2010 SimoTime Enterprises, LLC. *
* *
* All rights reserved. Unpublished, all rights reserved under *
* copyright law and international treaty. Use of a copyright *
* notice is precautionary only and does not imply publication *
* or disclosure. *
* *
* Permission to use, copy, modify and distribute this software *
* for any commercial purpose requires a fee to be paid to *
* SimoTime Enterprises. Once the fee is received by SimoTime *
* the latest version of the software will be delivered and a *
* license will be granted for use within an enterprise, *
* provided the SimoTime copyright notice appear on all copies *
* of the software. The SimoTime name or Logo may not be used *
* in any advertising or publicity pertaining to the use of the *
* software without the written permission of SimoTime *
* Enterprises. *
* *
* Permission to use, copy and modify this software for a *
* non-commercial purpose and without fee is hereby granted, *
* provided the SimoTime copyright notice appear on all copies *
* of the software. The SimoTime name or Logo may not be used *
* in any advertising or publicity pertaining to the use of the *
* software without the written permission of SimoTime *
* Enterprises. *
* *
* SimoTime Enterprises makes no warranty or representations *
* about the suitability of the software for any purpose. It is *
* provided "AS IS" without any express or implied warranty, *
* including the implied warranties of merchantability, fitness *
* for a particular purpose and non-infringement. SimoTime *
* Enterprises shall not be liable for any direct, indirect, *
* special or consequential damages resulting from the loss of *
* use, data or projects, whether in an action of contract or *
* tort, arising out of or in connection with the use or *
* performance of this software *
* *
* SimoTime Enterprises *
* 15 Carnoustie Drive *
* Novato, CA 94949-5849 *
* 415.883.6565 *
* *
* RESTRICTED RIGHTS LEGEND *
* Use, duplication, or disclosure by the Government is subject *
* to restrictions as set forth in subparagraph (c)(1)(ii) of *
* the Rights in Technical Data and Computer Software clause at *
* DFARS 52.227-7013 or subparagraphs (c)(1) and (2) of *
* Commercial Computer Software - Restricted Rights at 48 *
* CFR 52.227-19, as applicable. Contact SimoTime Enterprises, *
* 15 Carnoustie Drive, Novato, CA 94949-5849. *
*****************************************************************
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
*****************************************************************
SELECT CUSTSEQ1-FILE
ASSIGN to CUSTSEQ1
ORGANIZATION is SEQUENTIAL
ACCESS MODE is SEQUENTIAL
FILE STATUS is CUSTSEQ1-STATUS.
*****************************************************************
DATA DIVISION.
FILE SECTION.
FD CUSTSEQ1-FILE.
COPY CUSTSQ01.
WORKING-STORAGE SECTION.
*****************************************************************
* Data-structure for Title and Copyright...
* ------------------------------------------------------------
01 SIM-TITLE.
05 T1 pic X(11) value '* CUQCP1C1 '.
05 T2 pic X(34) value 'Cursor Processing, Customer RDB '.
05 T3 pic X(10) value ' v08.07.24'.
05 T4 pic X(24) value ' http://www.simotime.com'.
01 SIM-COPYRIGHT.
05 C1 pic X(11) value '* CUQCP1C1 '.
05 C2 pic X(20) value 'Copyright 1987-2010 '.
05 C3 pic X(28) value ' SimoTime Enterprises, LLC '.
05 C4 pic X(20) value ' All Rights Reserved'.
01 SIM-THANKS-01.
05 C1 pic X(11) value '* CUQCP1C1 '.
05 C2 pic X(32) value 'Thank you for using this sample '.
05 C3 pic X(32) value 'by SimoTime Enterprises, LLC '.
05 C4 pic X(04) value ' '.
01 SIM-THANKS-02.
05 C1 pic X(11) value '* CUQCP1C1 '.
05 C2 pic X(32) value 'Please send comments or suggesti'.
05 C3 pic X(32) value 'ons to helpdesk@simotime.com '.
05 C4 pic X(04) value ' '.
01 CUSTSEQ1-STATUS.
05 CUSTSEQ1-STAT1 pic X.
05 CUSTSEQ1-STAT2 pic X.
01 IO-STATUS.
05 IO-STAT1 pic X.
05 IO-STAT2 pic X.
01 TWO-BYTES.
05 TWO-BYTES-LEFT pic X.
05 TWO-BYTES-RIGHT pic X.
01 TWO-BYTES-BINARY redefines TWO-BYTES pic 9(4) comp.
01 END-OF-FILE pic X(3) value 'NO '.
01 APPL-RESULT pic S9(9) comp.
88 APPL-AOK value 0.
88 APPL-EOF value 16.
*****************************************************************
* Buffer used for posting messages to the console.
* ------------------------------------------------------------
01 MESSAGE-BUFFER.
05 MESSAGE-HEADER pic X(11) value '* CUQCP1C1 '.
05 MESSAGE-TEXT pic X(245).
01 DISPLAY-LINE-01.
05 filler pic X(8) value 'Cust #: '.
05 DISPLAY-NUMBER pic X(12) value SPACES.
05 filler pic X(3) value ' - '.
05 DISPLAY-DESCRIPTION pic X(48) value SPACES.
01 FETCH-SUMMARY.
05 filler pic X(19) value 'Data Base FETCH... '.
05 FETCH-COUNT pic 9(7) value 0.
01 CUSTRDB1-EOF pic X value 'N'.
*****************************************************************
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
EXEC SQL
INCLUDE CUSTCQ01
END-EXEC.
EXEC SQL DECLARE CUSTRDB1Cursor Cursor for
SELECT CUQ1_NUMBER,
CUQ1_STATUS,
CUQ1_LAST_NAME,
CUQ1_FIRST_NAME,
CUQ1_MID_NAME,
CUQ1_ADDRESS_1,
CUQ1_ADDRESS_2,
CUQ1_CITY,
CUQ1_STATE,
CUQ1_POSTAL_CODE,
CUQ1_PHONE_HOME,
CUQ1_PHONE_WORK,
CUQ1_PHONE_CELL,
CUQ1_LADATE,
CUQ1_LATIME,
CUQ1_TOKEN
FROM CUSTRDB1
END-EXEC
EXEC SQL INCLUDE
SQLCA
END-EXEC.
*****************************************************************
PROCEDURE DIVISION.
perform Z-POST-COPYRIGHT
perform CUSTRDB1-OPEN-CURSOR
perform CUSTSEQ1-OPEN.
perform until CUSTRDB1-EOF not = 'N'
perform CUSTRDB1-FETCH
if CUSTRDB1-EOF = 'N'
move CUQ1-RECORD to CUS1-RECORD
perform CUSTSEQ1-WRITE
end-if
end-perform
perform CUSTSEQ1-CLOSE.
perform CUSTRDB1-CLOSE-CURSOR
move FETCH-SUMMARY to MESSAGE-TEXT
perform Z-POST-MESSAGE
perform Z-THANK-YOU.
GOBACK.
*****************************************************************
CUSTRDB1-OPEN-CURSOR.
EXEC SQL OPEN CUSTRDB1Cursor END-EXEC
evaluate SQLCODE
when 0 move 0 to RETURN-CODE
when +100
move 'Y' to CUSTRDB1-EOF
display '* Finished: End-of-File' upon console
when OTHER
move 'A' to CUSTRDB1-EOF
add 16 to ZERO giving RETURN-CODE
display '* ABENDING: '
SQLCODE
' Error OPEN CUSTRDB1Cursor'
upon console
perform Z-POST-SQL-MESSAGE
end-evaluate
exit.
*---------------------------------------------------------------*
CUSTRDB1-FETCH.
EXEC SQL FETCH CUSTRDB1Cursor
INTO :CUQ1-NUMBER,
:CUQ1-STATUS,
:CUQ1-LAST-NAME,
:CUQ1-FIRST-NAME,
:CUQ1-MID-NAME,
:CUQ1-ADDRESS-1,
:CUQ1-ADDRESS-2,
:CUQ1-CITY,
:CUQ1-STATE,
:CUQ1-POSTAL-CODE,
:CUQ1-PHONE-HOME,
:CUQ1-PHONE-WORK,
:CUQ1-PHONE-CELL,
:CUQ1-LADATE,
:CUQ1-LATIME,
:CUQ1-TOKEN
END-EXEC
evaluate SQLCODE
when 0 move 0 to RETURN-CODE
add 1 to FETCH-COUNT
when +100
move 'Y' to CUSTRDB1-EOF
display '* Finished: End-of-File' upon console
when OTHER
move 'A' to CUSTRDB1-EOF
add 16 to ZERO giving RETURN-CODE
display '* ABENDING: I/O Error' upon console
end-evaluate
exit.
*---------------------------------------------------------------*
CUSTRDB1-CLOSE-CURSOR.
EXEC SQL CLOSE CUSTRDB1Cursor END-EXEC
exit.
*****************************************************************
CUSTSEQ1-GET.
read CUSTSEQ1-FILE
if CUSTSEQ1-STATUS = '00'
subtract APPL-RESULT from APPL-RESULT
else
if CUSTSEQ1-STATUS = '10'
add 16 to ZERO giving APPL-RESULT
else
add 12 to ZERO giving APPL-RESULT
end-if
end-if
if APPL-AOK
CONTINUE
else
if APPL-EOF
move 'YES' to END-OF-FILE
end-if
end-if
exit.
*---------------------------------------------------------------*
CUSTSEQ1-WRITE.
write CUS1-RECORD
if CUSTSEQ1-STATUS = '00'
subtract APPL-RESULT from APPL-RESULT
else
if CUSTSEQ1-STATUS = '10'
add 16 to ZERO giving APPL-RESULT
else
add 12 to ZERO giving APPL-RESULT
end-if
end-if
if APPL-AOK
CONTINUE
else
if APPL-EOF
move 'YES' to END-OF-FILE
else
move 'ITADDC01 CUSTSEQ1-FAILURE-WRITE...'
to MESSAGE-TEXT
move CUSTSEQ1-STATUS to IO-STATUS
perform Z-POST-MESSAGE
perform Z-DISPLAY-IO-STATUS
perform Z-ABEND-PROGRAM
end-if
end-if
exit.
*---------------------------------------------------------------*
CUSTSEQ1-REWRITE.
REWRITE CUS1-RECORD
if CUSTSEQ1-STATUS = '00'
subtract APPL-RESULT from APPL-RESULT
else
if CUSTSEQ1-STATUS = '10'
add 16 to ZERO giving APPL-RESULT
else
add 12 to ZERO giving APPL-RESULT
end-if
end-if
if APPL-AOK
CONTINUE
else
if APPL-EOF
move 'YES' to END-OF-FILE
else
move 'ITADDC01 CUSTSEQ1-FAILURE-REWRITE...'
to MESSAGE-TEXT
move CUSTSEQ1-STATUS to IO-STATUS
perform Z-POST-MESSAGE
perform Z-DISPLAY-IO-STATUS
perform Z-ABEND-PROGRAM
end-if
end-if
exit.
*---------------------------------------------------------------*
CUSTSEQ1-OPEN.
add 8 to ZERO giving APPL-RESULT.
open OUTPUT CUSTSEQ1-FILE
if CUSTSEQ1-STATUS = '35'
move 'ITADDC01 CUSTSEQ1-FAILURE-OPEN-IO...'
to MESSAGE-TEXT
perform Z-POST-MESSAGE
move CUSTSEQ1-STATUS to IO-STATUS
perform Z-DISPLAY-IO-STATUS
move 'ITADDC01 CUSTSEQ1-ATTEMPT-OPEN-OUTPUT...'
to MESSAGE-TEXT
perform Z-POST-MESSAGE
open output CUSTSEQ1-FILE
end-if
if CUSTSEQ1-STATUS = '00'
subtract APPL-RESULT from APPL-RESULT
else
add 12 to ZERO giving APPL-RESULT
end-if
if APPL-AOK
CONTINUE
else
move 'ITADDC01 CUSTSEQ1-FAILURE-OPEN...'
to MESSAGE-TEXT
move CUSTSEQ1-STATUS to IO-STATUS
perform Z-POST-MESSAGE
perform Z-DISPLAY-IO-STATUS
perform Z-ABEND-PROGRAM
end-if
exit.
*---------------------------------------------------------------*
CUSTSEQ1-CLOSE.
add 8 to ZERO giving APPL-RESULT.
close CUSTSEQ1-FILE
if CUSTSEQ1-STATUS = '00'
subtract APPL-RESULT from APPL-RESULT
else
add 12 to ZERO giving APPL-RESULT
end-if
if APPL-AOK
CONTINUE
else
move 'ITADDC01 CUSTSEQ1-FAILURE-CLOSE...'
to MESSAGE-TEXT
move CUSTSEQ1-STATUS to IO-STATUS
perform Z-POST-MESSAGE
perform Z-DISPLAY-IO-STATUS
perform Z-ABEND-PROGRAM
end-if
exit.
*****************************************************************
* The following Z-Routines perform administrative tasks *
* for this program. *
*****************************************************************
Z-ABEND-PROGRAM.
if MESSAGE-TEXT not = SPACES
perform Z-POST-MESSAGE
end-if
move 'ITADDC01 PROGRAM-IS-ABENDING...' to MESSAGE-TEXT
perform Z-POST-MESSAGE
add 12 to ZERO giving RETURN-CODE
GOBACK.
* exit.
*****************************************************************
* Display the file status bytes. This routine will display as *
* two digits if the full two byte file status is numeric. If *
* second byte is non-numeric then it will be treated as a *
* binary number. *
*****************************************************************
Z-DISPLAY-IO-STATUS.
if IO-STATUS not NUMERIC
or IO-STAT1 = '9'
subtract TWO-BYTES-BINARY from TWO-BYTES-BINARY
move IO-STAT2 to TWO-BYTES-RIGHT
display '* ITADDC01 FILE-STATUS-' IO-STAT1 '/'
TWO-BYTES-BINARY upon console
else
display '* ITADDC01 FILE-STATUS-' IO-STATUS upon console
end-if
exit.
*****************************************************************
Z-POST-COPYRIGHT.
display SIM-TITLE upon console
display SIM-COPYRIGHT upon console
exit.
*****************************************************************
Z-POST-MESSAGE.
if MESSAGE-BUFFER(81:176) = SPACES
display MESSAGE-BUFFER(1:80) upon console
else
display MESSAGE-BUFFER upon console
end-if
move SPACES to MESSAGE-TEXT
exit.
*****************************************************************
Z-POST-SQL-MESSAGE.
move 'ABENDING: ' to MESSAGE-TEXT
if SQLERRML > 0
and SQLERRML < 71
move SQLERRMC(1:SQLERRML) to MESSAGE-TEXT(11:SQLERRML)
else
move SQLERRMC(1:SQLERRML) to MESSAGE-TEXT(11:70)
end-if
perform Z-POST-MESSAGE
exit.
*****************************************************************
Z-THANK-YOU.
display SIM-THANKS-01 upon console
display SIM-THANKS-02 upon console
exit.
*****************************************************************
* This example is provided by SimoTime Enterprises *
* Our e-mail address is: helpdesk@simotime.com *
* Also, visit our Web Site at http://www.simotime.com *
*****************************************************************
The purpose of this program is to provide examples using embedded SQL in a COBOL program to create, manipulate and delete a relational data base table for customer data.
Permission to use, copy, modify and distribute this software for any commercial purpose requires a fee to be paid to SimoTime Enterprises. Once the fee is received by SimoTime the latest version of the software will be delivered and a license will be granted for use within an enterprise, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Enterprises.
Permission to use, copy, modify and distribute this software for a non-commercial purpose and without fee is hereby granted, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Enterprises.
SimoTime Enterprises makes no warranty or representations about the suitability of the software for any purpose. It is provided "AS IS" without any express or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Enterprises shall not be liable for any direct, indirect, special or consequential damages resulting from the loss of use, data or projects, whether in an action of contract or tort, arising out of or in connection with the use or performance of this software.
You may download this example at http://www.simotime.com/sim4dzip.htm#ZipsforSQL or view the complete list of SimoTime Examples at http://www.simotime.com/sim4dzip.htm.
Note: You must be attached to the Internet to download a Z-Pack or view the list.
Check out The SQL Connection for more examples of mainframe Relational Data Base management and accessing techniques with sample code.
The example for Create a Table uses embedded SQL in a COBOL program to create a data base for the item information.
The example for Insert a Row uses embedded SQL in a COBOL program to insert data into a table of an existing data base.
The example for Update Table Information uses embedded SQL in a COBOL program to update data in an existing row or insert data into a new row using a unique primary key.
The example for Delete a Table uses embedded SQL in a COBOL program to delete a data base for the item information.
This item will provide a link to an ASCII or EBCDIC translation table. A column for decimal, hexadecimal and binary is also included.
Check out The VSAM - QSAM Connection for more examples of mainframe VSAM and QSAM accessing techniques and sample code.
This document provides a quick summary of the File Status Key for VSAM data sets and QSAM files.
Check out The SimoTime Library for a wide range of topics for Programmers, Project Managers and Software Developers.
To review all the information available on this site start at The SimoTime Home Page .
If you have any questions, suggestions or comments please call or send an e-mail to: helpdesk@simotime.com
We appreciate your comments and feedback.
Founded in 1987, SimoTime Enterprises is a privately owned company. We specialize in the creation and deployment of business applications using new or existing technologies and services. We have a team of individuals that understand the broad range of technologies being used in today's environments. This includes the smallest thin client using the Internet and the very large mainframe systems. There is more to making the Internet work for your company's business than just having a nice looking WEB site. It is about combining the latest technologies and existing technologies with practical business experience. It's about the business of doing business and looking good in the process. Quite often, to reach larger markets or provide a higher level of service to existing customers it requires the newer Internet technologies to work in a complementary manner with existing corporate mainframe systems. Whether you want to use the Internet to expand into new market segments or as a delivery vehicle for existing business functions simply give us a call or check the web site at http://www.simotime.com
| Return-to-Top |
| Copyright © 1987-2010 SimoTime Enterprises All Rights Reserved |
| When technology complements business |