COBOL-DB2 SAMPLE PROGRAM:
DB2T1 - COBOL - DB2 Program
IDENTIFICATION DIVISION.
PROGRAM-ID. DB2T1.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-VARIABLES.
05 WS-SQLCODE PIC S9(03) VALUE ZEROS
SIGN LEADING SEPARATE CHARACTER.
05 WS-EMP-ID PIC X(05) VALUE SPACES.
05 WS-EMP-NAME PIC X(10) VALUE SPACES.
05 WS-EMP-SAL PIC S9(05)V99 COMP-3.
05 WS-DEPT-ID PIC X(04) VALUE SPACES.
05 WS-DEPT-NAME PIC X(10) VALUE SPACES.
EXEC SQL
INCLUDE SQLCA
END-EXEC.
******************************************************************
* DCLGEN TABLE(Z57658.TAB_DEPT) *
* LIBRARY(Z57658.SOURCE.COPY(TABDEPT)) *
* LANGUAGE(COBOL) *
* QUOTE *
* ... IS THE DCLGEN COMMAND THAT MADE THE FOLLOWING STATEMENTS *
******************************************************************
EXEC SQL DECLARE Z57658.TAB_DEPT TABLE
( DEPT_ID CHAR(4) NOT NULL,
DEPT_NAME CHAR(10) NOT NULL
) END-EXEC.
******************************************************************
* COBOL DECLARATION FOR TABLE Z57658.TAB_DEPT *
******************************************************************
01 DCLTAB-DEPT.
10 DEPT-ID PIC X(4).
10 DEPT-NAME PIC X(10).
******************************************************************
* THE NUMBER OF COLUMNS DESCRIBED BY THIS DECLARATION IS 2 *
******************************************************************
PROCEDURE DIVISION.
MOVE 'D001' TO WS-DEPT-ID
DISPLAY ' INPUT DEPT ' WS-DEPT-ID
INITIALIZE DCLTAB-DEPT.
EXEC SQL
SELECT DEPT_ID,
DEPT_NAME
INTO :DEPT-ID,
:DEPT-NAME
FROM Z57658.TAB_DEPT
WHERE DEPT_ID = :WS-DEPT-ID
END-EXEC.
MOVE SQLCODE TO WS-SQLCODE
IF SQLCODE = ZERO
DISPLAY ' DEPT-ID : ' DEPT-ID
DISPLAY ' DEPT-NAME : ' DEPT-NAME
ELSE
DISPLAY ' ERROR IN SQL QUERY ' WS-SQLCODE
END-IF.
STOP RUN.
COBOL-DB2 Program compilation JCL:
//Z57658SA JOB (3P10),'COB DB2 COMP LNKJCL',
// CLASS=A,
// MSGCLASS=Q,
// NOTIFY=Z57658
//*
//PLIB JCLLIB ORDER=Z57658.SOURCE.DB2.PROCLIB
//*
//COMLINK EXEC PROC=DSNHICOB,MEM=DB2T1
//PC.DBRMLIB DD DSN=Z57658.SOURCE.DB2.DBRMLIB(&MEM),DISP=SHR
//PC.SYSIN DD DSN=Z57658.SOURCE.DB2.COBOL(&MEM),DISP=SHR
//PC.SYSLIB DD DSN=Z57658.SOURCE.DB2.SRCLIB(&MEM),DISP=SHR
//LKED.SYSLMOD DD DSN=Z57658.SOURCE.DB2.LOADLIB(&MEM),
// DISP=SHR
//*
DSNHICOB CATLOG PROCEDURE TO COMPILE AND LINK COBOL-DB2 Program:
DSNHICOB:
//********************************************************************
//* DSNHICOB - DB2 precompile, IBM COBOL compile, pre-link, *
//* and link edit a DB2 SQL program. *
//********************************************************************
//DSNHICOB PROC WSPC=500,MEM=TEMPNAME,USER=DSNC10.DBCG
//********************************************************************
//* Precompile the IBM COBOL program *
//********************************************************************
//PC EXEC PGM=DSNHPC,PARM='HOST(IBMCOB)'
//DBRMLIB DD DISP=SHR,
// DSN=&USER..DBRMLIB.DATA(&MEM)
//STEPLIB DD DISP=SHR,DSN=DSNC10.DBCG.SDSNEXIT
// DD DISP=SHR,DSN=DSNC10.SDSNLOAD
//SYSCIN DD DSN=&&DSNHOUT,DISP=(MOD,PASS),UNIT=3390,
// SPACE=(800,(&WSPC,&WSPC))
//SYSLIB DD DISP=SHR,DSN=&USER..SRCLIB.DATA
//SYSPRINT DD SYSOUT=*
//SYSTERM DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSUT1 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT2 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//********************************************************************
//* Compile the IBM COBOL program if the precompile *
//* return code is 4 or less. *
//********************************************************************
//COB EXEC PGM=IGYCRCTL,
// PARM=(NOSEQUENCE,QUOTE,RENT,'PGMNAME(LONGUPPER)'),
// COND=(4,LT,PC)
//*STEPLIB DD DSN=IGY610.SIGYCOMP,DISP=SHR
//STEPLIB DD DSN=IGY420.SIGYCOMP,DISP=SHR
//SYSPRINT DD SYSOUT=*
//SYSTERM DD SYSOUT=*
//SYSLIN DD DSN=&&LOADSET,DISP=(MOD,PASS),UNIT=3390,
// SPACE=(800,(&WSPC,&WSPC))
//SYSIN DD DSN=&&DSNHOUT,DISP=(OLD,DELETE)
//SYSUT1 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT2 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT3 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT4 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT5 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT6 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT7 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT8 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT9 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT10 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT11 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT12 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT13 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT14 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT15 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSMDECK DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//********************************************************************
//* Linkedit if the precompile and compile *
//* return codes are 4 or less. *
//********************************************************************
//LKED EXEC PGM=IEWL,PARM='MAP',
// COND=((4,LT,PC),(4,LT,COB))
//SYSLIB DD DISP=SHR,DSN=CEE.SCEELKED
// DD DISP=SHR,DSN=DSNC10.SDSNLOAD
//* DD DISP=SHR,DSN=IMSVS.RESLIB
// DD DISP=SHR,DSN=DFH530.CICS.SDFHLOAD
// DD DISP=SHR,DSN=ISP.SISPLOAD
// DD DISP=SHR,DSN=GDDM.SADMMOD
//SYSLIN DD DSN=&&LOADSET,DISP=(OLD,DELETE)
// DD DDNAME=SYSIN
//SYSLMOD DD DISP=SHR,
// DSN=&USER..RUNLIB.LOAD(&MEM)
//SYSPRINT DD SYSOUT=*
//SYSUT1 DD SPACE=(1024,(50,50)),UNIT=3390
//*DSNHICOB PEND Remove * for use as an instream procedure
//*
JCL TO BIND PLAN:
//Z57658SA JOB (3P10),'BIND PLAN JCL',
// CLASS=A,
// MSGCLASS=Q,
// NOTIFY=Z57658
//*
//BINDPC EXEC PGM=IKJEFT01,DYNAMNBR=999
//STEPLIB DD DSN=DSNC10.SDSNLOAD,DISP=SHR
// DD DSN=DSNC10.DBCG.SDSNEXIT,DISP=SHR
// DD DSN=DSNC10.DBCG.RUNLIB.LOAD,DISP=SHR
//DBRMLIB DD DSN=Z57658.SOURCE.DB2.DBRMLIB,DISP=SHR
//SYSTSPRT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSTSIN DD *
DSN SYSTEM(DBCG)
BIND PLAN(DB2T1PL1) -
MEMBER(DB2T1) -
ISOLATION(CS) -
ENCODING(EBCDIC) -
OWNER(Z57658) -
VALIDATE(BIND) -
ACTION(REPLACE)
/*
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
GRANT EXECUTE ON PLAN DB2T1PL1 TO PUBLIC;
//*
JCL TO EXECUTE COBOL-DB2 PROGRAM:
//Z57658SA JOB (3P10),'COBL DB2 RUN JCL',
// CLASS=A,
// MSGCLASS=Q,
// NOTIFY=Z57658
//*
//RUNSTEP EXEC PGM=IKJEFT01,DYNAMNBR=20
//STEPLIB DD DSN=DSNC10.SDSNLOAD,DISP=SHR
// DD DSN=DSNC10.DBCG.RUNLIB.LOAD,DISP=SHR
// DD DSN=Z57658.SOURCE.DB2.LOADLIB,DISP=SHR
//SYSTSPRT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSTSIN DD *
DSN SYSTEM(DBCG)
RUN PROGRAM(DB2T1) PLAN(DB2T1PL1)
//*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
DB2T1 - COBOL - DB2 Program
IDENTIFICATION DIVISION.
PROGRAM-ID. DB2T1.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-VARIABLES.
05 WS-SQLCODE PIC S9(03) VALUE ZEROS
SIGN LEADING SEPARATE CHARACTER.
05 WS-EMP-ID PIC X(05) VALUE SPACES.
05 WS-EMP-NAME PIC X(10) VALUE SPACES.
05 WS-EMP-SAL PIC S9(05)V99 COMP-3.
05 WS-DEPT-ID PIC X(04) VALUE SPACES.
05 WS-DEPT-NAME PIC X(10) VALUE SPACES.
EXEC SQL
INCLUDE SQLCA
END-EXEC.
******************************************************************
* DCLGEN TABLE(Z57658.TAB_DEPT) *
* LIBRARY(Z57658.SOURCE.COPY(TABDEPT)) *
* LANGUAGE(COBOL) *
* QUOTE *
* ... IS THE DCLGEN COMMAND THAT MADE THE FOLLOWING STATEMENTS *
******************************************************************
EXEC SQL DECLARE Z57658.TAB_DEPT TABLE
( DEPT_ID CHAR(4) NOT NULL,
DEPT_NAME CHAR(10) NOT NULL
) END-EXEC.
******************************************************************
* COBOL DECLARATION FOR TABLE Z57658.TAB_DEPT *
******************************************************************
01 DCLTAB-DEPT.
10 DEPT-ID PIC X(4).
10 DEPT-NAME PIC X(10).
******************************************************************
* THE NUMBER OF COLUMNS DESCRIBED BY THIS DECLARATION IS 2 *
******************************************************************
PROCEDURE DIVISION.
MOVE 'D001' TO WS-DEPT-ID
DISPLAY ' INPUT DEPT ' WS-DEPT-ID
INITIALIZE DCLTAB-DEPT.
EXEC SQL
SELECT DEPT_ID,
DEPT_NAME
INTO :DEPT-ID,
:DEPT-NAME
FROM Z57658.TAB_DEPT
WHERE DEPT_ID = :WS-DEPT-ID
END-EXEC.
MOVE SQLCODE TO WS-SQLCODE
IF SQLCODE = ZERO
DISPLAY ' DEPT-ID : ' DEPT-ID
DISPLAY ' DEPT-NAME : ' DEPT-NAME
ELSE
DISPLAY ' ERROR IN SQL QUERY ' WS-SQLCODE
END-IF.
STOP RUN.
COBOL-DB2 Program compilation JCL:
//Z57658SA JOB (3P10),'COB DB2 COMP LNKJCL',
// CLASS=A,
// MSGCLASS=Q,
// NOTIFY=Z57658
//*
//PLIB JCLLIB ORDER=Z57658.SOURCE.DB2.PROCLIB
//*
//COMLINK EXEC PROC=DSNHICOB,MEM=DB2T1
//PC.DBRMLIB DD DSN=Z57658.SOURCE.DB2.DBRMLIB(&MEM),DISP=SHR
//PC.SYSIN DD DSN=Z57658.SOURCE.DB2.COBOL(&MEM),DISP=SHR
//PC.SYSLIB DD DSN=Z57658.SOURCE.DB2.SRCLIB(&MEM),DISP=SHR
//LKED.SYSLMOD DD DSN=Z57658.SOURCE.DB2.LOADLIB(&MEM),
// DISP=SHR
//*
DSNHICOB CATLOG PROCEDURE TO COMPILE AND LINK COBOL-DB2 Program:
DSNHICOB:
//********************************************************************
//* DSNHICOB - DB2 precompile, IBM COBOL compile, pre-link, *
//* and link edit a DB2 SQL program. *
//********************************************************************
//DSNHICOB PROC WSPC=500,MEM=TEMPNAME,USER=DSNC10.DBCG
//********************************************************************
//* Precompile the IBM COBOL program *
//********************************************************************
//PC EXEC PGM=DSNHPC,PARM='HOST(IBMCOB)'
//DBRMLIB DD DISP=SHR,
// DSN=&USER..DBRMLIB.DATA(&MEM)
//STEPLIB DD DISP=SHR,DSN=DSNC10.DBCG.SDSNEXIT
// DD DISP=SHR,DSN=DSNC10.SDSNLOAD
//SYSCIN DD DSN=&&DSNHOUT,DISP=(MOD,PASS),UNIT=3390,
// SPACE=(800,(&WSPC,&WSPC))
//SYSLIB DD DISP=SHR,DSN=&USER..SRCLIB.DATA
//SYSPRINT DD SYSOUT=*
//SYSTERM DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSUT1 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT2 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//********************************************************************
//* Compile the IBM COBOL program if the precompile *
//* return code is 4 or less. *
//********************************************************************
//COB EXEC PGM=IGYCRCTL,
// PARM=(NOSEQUENCE,QUOTE,RENT,'PGMNAME(LONGUPPER)'),
// COND=(4,LT,PC)
//*STEPLIB DD DSN=IGY610.SIGYCOMP,DISP=SHR
//STEPLIB DD DSN=IGY420.SIGYCOMP,DISP=SHR
//SYSPRINT DD SYSOUT=*
//SYSTERM DD SYSOUT=*
//SYSLIN DD DSN=&&LOADSET,DISP=(MOD,PASS),UNIT=3390,
// SPACE=(800,(&WSPC,&WSPC))
//SYSIN DD DSN=&&DSNHOUT,DISP=(OLD,DELETE)
//SYSUT1 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT2 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT3 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT4 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT5 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT6 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT7 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT8 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT9 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT10 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT11 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT12 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT13 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT14 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSUT15 DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//SYSMDECK DD SPACE=(800,(&WSPC,&WSPC),,,ROUND),UNIT=3390
//********************************************************************
//* Linkedit if the precompile and compile *
//* return codes are 4 or less. *
//********************************************************************
//LKED EXEC PGM=IEWL,PARM='MAP',
// COND=((4,LT,PC),(4,LT,COB))
//SYSLIB DD DISP=SHR,DSN=CEE.SCEELKED
// DD DISP=SHR,DSN=DSNC10.SDSNLOAD
//* DD DISP=SHR,DSN=IMSVS.RESLIB
// DD DISP=SHR,DSN=DFH530.CICS.SDFHLOAD
// DD DISP=SHR,DSN=ISP.SISPLOAD
// DD DISP=SHR,DSN=GDDM.SADMMOD
//SYSLIN DD DSN=&&LOADSET,DISP=(OLD,DELETE)
// DD DDNAME=SYSIN
//SYSLMOD DD DISP=SHR,
// DSN=&USER..RUNLIB.LOAD(&MEM)
//SYSPRINT DD SYSOUT=*
//SYSUT1 DD SPACE=(1024,(50,50)),UNIT=3390
//*DSNHICOB PEND Remove * for use as an instream procedure
//*
JCL TO BIND PLAN:
//Z57658SA JOB (3P10),'BIND PLAN JCL',
// CLASS=A,
// MSGCLASS=Q,
// NOTIFY=Z57658
//*
//BINDPC EXEC PGM=IKJEFT01,DYNAMNBR=999
//STEPLIB DD DSN=DSNC10.SDSNLOAD,DISP=SHR
// DD DSN=DSNC10.DBCG.SDSNEXIT,DISP=SHR
// DD DSN=DSNC10.DBCG.RUNLIB.LOAD,DISP=SHR
//DBRMLIB DD DSN=Z57658.SOURCE.DB2.DBRMLIB,DISP=SHR
//SYSTSPRT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSTSIN DD *
DSN SYSTEM(DBCG)
BIND PLAN(DB2T1PL1) -
MEMBER(DB2T1) -
ISOLATION(CS) -
ENCODING(EBCDIC) -
OWNER(Z57658) -
VALIDATE(BIND) -
ACTION(REPLACE)
/*
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
GRANT EXECUTE ON PLAN DB2T1PL1 TO PUBLIC;
//*
JCL TO EXECUTE COBOL-DB2 PROGRAM:
//Z57658SA JOB (3P10),'COBL DB2 RUN JCL',
// CLASS=A,
// MSGCLASS=Q,
// NOTIFY=Z57658
//*
//RUNSTEP EXEC PGM=IKJEFT01,DYNAMNBR=20
//STEPLIB DD DSN=DSNC10.SDSNLOAD,DISP=SHR
// DD DSN=DSNC10.DBCG.RUNLIB.LOAD,DISP=SHR
// DD DSN=Z57658.SOURCE.DB2.LOADLIB,DISP=SHR
//SYSTSPRT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSTSIN DD *
DSN SYSTEM(DBCG)
RUN PROGRAM(DB2T1) PLAN(DB2T1PL1)
//*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
No comments:
Post a Comment