cobol上的外部存储过程db2

时间:2017-11-09 07:31:32

标签: stored-procedures db2 cobol zos

我会问关于在cobol z / os上调用外部存储过程 这是我的代码,存储过程代码

  *----------------------------------------------------------------*
   IDENTIFICATION DIVISION.
  *----------------------------------------------------------------*

   PROGRAM-ID.    SPROC02.
   AUTHOR.        AESANJA.
   DATE-WRITTEN.  19 OKT 2017.
   DATE-COMPILED.

   DATA DIVISION.
   WORKING-STORAGE SECTION.
  *************************************************************
  *INCLUDE SQLCA ITU SQL COMMUNICATION AREA                   *
  *SETIAP SELESAI MENJALANKAN SQL STATEMENT DAN SELESAI       *
  *NILAI AKAN BERUBAH                                         *
  *************************************************************
        EXEC SQL
             INCLUDE SQLCA
        END-EXEC.
  *************************************************************
  *INCLUDE DCLGEN NYA YANG DIGUNAKAN UNTUK AKSES DATABASE     *
  *MEMUNGKIKAN PROGRAM MELIHAT STRUKTUR TABLE DARI DATABASE   *
  *************************************************************
        EXEC SQL
             INCLUDE DAAVACDC
        END-EXEC.
  ************************************************************
   01 SP-SQLCODE                            PIC  9(9).
   01 SP-SQLSTATE                           PIC  9(9).
   LINKAGE SECTION.
   01 BRANCH                             PIC  X(07).
   01 ACCTNO                             PIC  X(11).
   01 AVAILABLE                          PIC  X(01).
   01 ADDTS                              PIC  X(26).
   01 ADDUSER                            PIC  X(08).
   01 ADDPROGRAM                         PIC  X(08).
   01 UPDTS                              PIC  X(26).
   01 UPDUSER                            PIC  X(08).
   01 UPDPROGRAM                         PIC  X(08).
   01 OUTCODE                            PIC S9(09) USAGE BINARY.
   PROCEDURE DIVISION USING BRANCH    ,
                            ACCTNO    ,
                            AVAILABLE ,
                            ADDTS     ,
                            ADDUSER   ,
                            ADDPROGRAM,
                            UPDTS     ,
                            UPDUSER   ,
                            UPDPROGRAM,
                            OUTCODE.
   MAIN-PROC.
       EXEC SQL
            SELECT *
            INTO :BRANCH    ,
                 :ACCTNO    ,
                 :AVAILABLE ,
                 :ADDTS     ,
                 :ADDUSER   ,
                 :ADDPROGRAM,
                 :UPDTS     ,
                 :UPDUSER   ,
                 :UPDPROGRAM
            FROM DAVACV0
            WHERE AVAC_BRANCH  = :BRANCH
              AND AVAC_ACCT_NO = :ACCTNO
       END-EXEC.
       MOVE SQLCODE TO OUTCODE.
   MAIN-PROC-RETURN.
       GOBACK.

然后这是我的JCL来预编译,编译,链接和绑定存储过程

//SPROCJCL JOB (999),CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1),NOTIFY=&SYSUID,  JOB09854
//         REGION=4M
//JOBLIB DD DSN=DB2DEV.DSNUAT2.SDSNEXIT,DISP=SHR
//       DD DSN=DB2DEV.SDSNLOAD,DISP=SHR
//*--------------------------------------------------------------------*
//STEP01 EXEC DSN2HCOB,MEM=TEMPNAME,USER='CISUSER',
//   PARM.PC='HOST(IBMCOB),APOST,APOSTSQL,SOURCE,XREF',
//   PARM.COB=('OBJECT,APOST,MAP,XREF,NONUM,OFF,FLAG(I,E),TRUNC(BIN)', X
//             'RENT,RES,LIB,NODYNAM'),
//   PARM.LKED='RENT,REUS,LIST,XREF,LET,AMODE=31'
//*PLACE THE DCLGEN DSN
//PC.SYSLIB DD DSN=LCM.MNI.BCA.P.COPY,DISP=SHR
//*PLACE LOAD DBRMLIB
//PC.DBRMLIB DD DSN=IBS.BCA.DEV.DBRMLIB(SPROC02),DISP=SHR
//*PLACE THE SOURCE CODE OF STORED PROCEDURE
//PC.SYSIN DD DSN=AESANJA.LEARN.DB2(SPROC02),DISP=SHR
//*--------------------------------------------------------------------*
//*COPY BOOK OF THE DATA
//COB.SYSLIB DD DSN=LCM.MNI.BCA.P.COPY,DISP=SHR
//*--------------------------------------------------------------------*
//LKED.SYSLIB DD DSN=SYS1.CEE.SCEELKED,DISP=SHR
//            DD DSN=DB2DEV.SDSNLOAD,DISP=SHR
//LKED.SYSLMOD DD DSN=AESANJA.LEARN.LOAD(SPROC02),DISP=SHR
//LKED.SYSIN DD *
      INCLUDE SYSLIB(DSNALI)
      MODE AMODE(31) RMODE(ANY)
//*--------------------------------------------------------------------*
//SQLBIND  PROC
//BIND     EXEC PGM=IKJEFT01,DYNAMNBR=20
//DBRMLIB  DD   DSN=IBS.BCA.DEV.DBRMLIB,DISP=SHR
//STEPLIB  DD   DSN=DB2DEV.SDSNLOAD,DISP=SHR
//SYSTSPRT DD   SYSOUT=*
//SYSPRINT DD   SYSOUT=*
//SYSUDUMP DD   SYSOUT=*
//SYSOUT   DD   SYSOUT=*
//SYSIN    DD   DUMMY
//SYSTSIN  DD   DDNAME=SYSTSIN
//         PEND
//STEP2 EXEC SQLBIND
//****************************************************************
//* UBAH XXXXXXXX MENJADI NAMA PROGRAM
//****************************************************************
//BIND.SYSTSIN DD *
  DSN SYSTEM(DSN1)
  BIND PACKAGE(DPB_COLLID) -
       MEMBER(SPROC02)     -
       ACT(REP) ISO(UR) ENCODING(EBCDIC) -
       OWNER(CISUSER)
  END
  DSN SYSTEM(DSN1)
  BIND PLAN(SPROC02)              -
       OWNER(CISUSER)              -
       PKLIST(DPB_COLLID.SPROC02) -
       RETAIN                      -
       DYNAMICRULES(BIND)          -
       VALIDATE(BIND)              -
       ISOLATION(CS)               -
       ACQUIRE(USE)                -
       RELEASE(COMMIT)             -
       EXPLAIN(YES)
  END

然后我的JCL用于在系统表中定义存储过程

//CREASTPR JOB ,,CLASS=A,MSGCLASS=X,MSGLEVEL=(1,1),TIME=1440,           JOB15600
//         NOTIFY=&SYSUID,REGION=4M
//**********************************************************************
//* CREATE STORED PROCEDURE                                            *
//**********************************************************************
//JOBLIB   DD DSN=DB2DEV.SDSNLOAD,DISP=SHR
//         DD DSN=AESANJA.LEARN.LOAD,DISP=SHR
//STEP1   EXEC PGM=IKJEFT01,DYNAMNBR=20
//SYSTSPRT DD SYSOUT=*
//SYSTSIN  DD *
 DSN SYSTEM(DSN1)
 RUN  PROGRAM(DSNTIAD) PLAN(DSNTIAD) -
      LIB('DSNBCA.RUNLIB.LOAD')
//SYSPRINT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSIN    DD *
  SET CURRENT SQLID='CISUSER';
   CREATE PROCEDURE CISUSER.SP02KE02
   (INOUT BRANCH          DECIMAL(7) ,
    INOUT ACCTNO          DECIMAL(11),
    OUT   AVAILABLE       CHAR(1)    ,
    OUT   ADDTS           TIMESTAMP  ,
    OUT   ADDUSER         CHAR(8)    ,
    OUT   ADDPROGRAM      CHAR(8)    ,
    OUT   UPDTS           TIMESTAMP  ,
    OUT   UPDUSER         CHAR(8)    ,
    OUT   UPDPROGRAM      CHAR(8)    ,
    OUT   OUTCODE         INTEGER    )
      LANGUAGE COBOL
      DETERMINISTIC
      READS SQL DATA
      EXTERNAL NAME 'SPROC02'
      COLLID DPB_COLLID
      ASUTIME NO LIMIT
      PARAMETER STYLE GENERAL
      STAY RESIDENT NO
      RUN OPTIONS 'MSGFILE(OUTFILE),RPTSTG(ON),RPTOPTS(ON)'
      WLM ENVIRONMENT ENV1DB2
      PROGRAM TYPE MAIN
      SECURITY DB2
      RESULT SETS 2
      COMMIT ON RETURN YES;

之后,这是我的主程序代码,它将调用存储过程

   *----------------------------------------------------------------*
   IDENTIFICATION DIVISION.
  *----------------------------------------------------------------*

   PROGRAM-ID.    COBA12.
   AUTHOR.        AESANJA.
   DATE-WRITTEN.  19 OKT 2017.
   DATE-COMPILED.

   DATA DIVISION.
   WORKING-STORAGE SECTION.
  *************************************************************
  *INCLUDE SQLCA ITU SQL COMMUNICATION AREA                   *
  *SETIAP SELESAI MENJALANKAN SQL STATEMENT DAN SELESAI       *
  *NILAI AKAN BERUBAH                                         *
  *************************************************************
   EXEC SQL
       INCLUDE SQLCA
   END-EXEC.
  *************************************************************
  *INCLUDE DCLGEN NYA YANG DIGUNAKAN UNTUK AKSES DATABASE     *
  *MEMUNGKIKAN PROGRAM MELIHAT STRUKTUR TABLE DARI DATABASE   *
  *************************************************************
   EXEC SQL
       INCLUDE DAAVACDC
   END-EXEC.
   77 SQLRETCODE PIC 9(9).
   01 WS-SQL-STORAGE.
      05 AVAC-BRANCH-NO PIC X(7).
      05 SQL-STATEMENT.
         49 SQL-STATEMENT-LEN PIC S9(4) COMP VALUE +320.
         49 SQL-STATEMENT-TEXT PIC X(320).
   01 BRANCH                             PIC  X(07).
   01 ACCTNO                             PIC  X(11).
   01 AVAILABLE                          PIC  X(01).
   01 ADDTS                              PIC  X(26).
   01 ADDUSER                            PIC  X(08).
   01 ADDPROGRAM                         PIC  X(08).
   01 UPDTS                              PIC  X(26).
   01 UPDUSER                            PIC  X(08).
   01 UPDPROGRAM                         PIC  X(08).
   01 OUTCODE                            PIC S9(9) USAGE COMP.
   PROCEDURE DIVISION.
   MAIN-PROC.
       MOVE 1 TO BRANCH.
       MOVE 3913 TO ACCTNO.
       EXEC SQL CALL CISUSER.SP02KE04(:BRANCH    ,
                                      :ACCTNO    ,
                                      :AVAILABLE ,
                                      :ADDTS     ,
                                      :ADDUSER   ,
                                      :ADDPROGRAM,
                                      :UPDTS     ,
                                      :UPDUSER   ,
                                      :UPDPROGRAM,
                                      :OUTCODE   )
       END-EXEC.
       DISPLAY "SP-DA-AVAC-BRANCH      " BRANCH.
       DISPLAY "SP-DA-AVAC-ACCT-NO     " ACCTNO.
       DISPLAY "SP-DA-AVAC-AVAILABLE   " AVAILABLE.
       DISPLAY "SP-DA-AVAC-ADD-TS      " ADDTS.
       DISPLAY "SP-DA-AVAC-ADD-USER    " ADDUSER.
       DISPLAY "SP-DA-AVAC-ADD-PROGRAM " ADDPROGRAM.
       DISPLAY "SP-DA-AVAC-UPD-TS      " UPDTS.
       DISPLAY "SP-DA-AVAC-UPD-USER    " UPDUSER.
       DISPLAY "OUT-CODE               " OUTCODE.

停止运行。

我预编译,编译,使用此

链接我的程序
//EXECUTE JOB (123),CLASS=A,MSGCLASS=A,NOTIFY=&SYSUID,MSGLEVEL=(1,1)
//*
//* -------------------------------------------------------------------
//* --- Cobol Compile - Batch or CICS                               ---
//* -------------------------------------------------------------------
//*
//* ---------------------------------------------------------- *//
//*    SCAN CODE FOR CICS, DB2 OR DLI .....                    *//
//* ---------------------------------------------------------- *//
//*
//DB2SCAN  EXEC PGM=IRXJCL,COND=(4,LT),
//            PARM='PSSRCSCN COBA12'
//*
//SYSTSPRT DD  SYSOUT=*
//SYSEXEC  DD  DISP=SHR,DSN=CCCLCM.V600.BCA.CLIST
//SYSTSIN  DD  SYSOUT=*
//CBLSRC   DD  DSN=AESANJA.LEARN.DB2(COBA12),DISP=SHR
//CBLSRCO  DD DISP=(,PASS),DSN=&&SRCFULL,
//         SPACE=(CYL,(10,10),RLSE),
//         DCB=(DSORG=PS,RECFM=FB,LRECL=80,BLKSIZE=0)
//DB2OPTS  DD *
  CBL SQL("HOST(IBMCOB),APOST,APOSTSQL")
  CBL SQL("DATE(ISO),TIME(ISO),LEVEL(DB2CIS)")
/*
//FILEOT   DD  DISP=(,PASS),DSN=&&TMPLNK,
//         SPACE=(TRK,(15,15)),UNIT=SYSDA,
//         DCB=(RECFM=FB,LRECL=80,BLKSIZE=3120)
//*
//* ---------------------------------------------------------- *//
//*    COBOL COMPILE                                           *//
//*                                                            *//
//* ---------------------------------------------------------- *//
//COMPILE  EXEC PGM=IGYCRCTL,REGION=0M,
//   PARM=('DATA(31)','FLAG(I,E)',APOST,MAP,LIST,
//         'SIZE(24000K)',NOADV)
//STEPLIB  DD   DSN=ECOB.V4R2M0.SIGYCOMP,DISP=SHR
//         DD   DSN=DB2DEV.DSNUAT2.SDSNEXIT,DISP=SHR
//         DD   DSN=DB2DEV.SDSNLOAD,DISP=SHR
//         DD   DSN=CICSTS53.CICS.SDFHLOAD,DISP=SHR
//         DD   DSN=WMQ.V701.TLIB.SCSQLOAD,DISP=SHR
//SYSIN    DD   DATA
/*
//         DD   DSN=&&SRCFULL,DISP=(OLD,DELETE,DELETE)
//*
//SYSLIB   DD   DISP=SHR,DSN=LCM.DEFAULT.EMPTY.COPYLIB
//         DD   DISP=SHR,DSN=LCM.MNI.BCA.P.COPY
//         DD   DISP=SHR,DSN=LCM.DEFAULT.EMPTY.COPYLIB
//         DD   DISP=SHR,DSN=LCM.MNI.BCA.P.ONLCOPY
//         DD   DSN=WMQ.V701.TLIB.SCSQCOBC,DISP=SHR
//         DD   DISP=SHR,DSN=LCM.GGLM.GL312.P.COPY
//         DD   DISP=SHR,DSN=LCM.GGLM.P.COPY
//         DD   DISP=SHR,DSN=LCM.ATM.CMS.P.COPY
//         DD   DISP=SHR,DSN=LCM.ATM.L24.P.COPY
//         DD   DISP=SHR,DSN=ATMD.CARD.SOURCE
//         DD   DISP=SHR,DSN=ATMD.MNI.SOURCE
//         DD   DISP=SHR,DSN=EBSD.BCA.PROD.COPY
//         DD   DISP=SHR,DSN=EBSD.BCA.PROD.ONLCOPY
//         DD   DISP=SHR,DSN=IBS.UND.PROD.COPY
//         DD   DISP=SHR,DSN=LCM.KUX.P.COPY
//         DD   DISP=SHR,DSN=LCM.KUX.P.ONLCOPY
//*        DD   DISP=SHR,DSN=CARDD.LA10.COPYLIB.CX2091
//* REQUEST BY SGT 15 MAY 2015
//         DD   DISP=SHR,DSN=LCM.CARD.P.SCPYB
//         DD   DISP=SHR,DSN=LCM.CARD.P.SCPYC
//*             STLH CUT OFF CRD  11 JUL '13
//* LHM MEN+KAN DD   DISP=SHR,DSN=LCM.CARD.P.SCPYC 07 OCT 2013
//DBRMLIB  DD   DISP=SHR,DSN=IBS.BCA.DEV.DBRMLIB(COBA12)
//SYSLIN   DD   DISP=(,PASS),DSN=&&TMPOBJ,
//         UNIT=3390,SPACE=(TRK,(25,25)),
//         DCB=(RECFM=FB,LRECL=80,BLKSIZE=3120)
//SYSPRINT DD   SYSOUT=*
//*
//SYSUT1   DD   UNIT=3390,SPACE=(CYL,(15,5))
//SYSUT2   DD   UNIT=3390,SPACE=(CYL,(15,5))
//SYSUT3   DD   UNIT=3390,SPACE=(CYL,(15,5))
//SYSUT4   DD   UNIT=3390,SPACE=(CYL,(15,5))
//SYSUT5   DD   UNIT=3390,SPACE=(CYL,(15,5))
//SYSUT6   DD   UNIT=3390,SPACE=(CYL,(15,5))
//SYSUT7   DD   UNIT=3390,SPACE=(CYL,(15,5))
//*
//*-------------------------------------------------------------------*
//*   LINKEDIT                                                        *
//*-------------------------------------------------------------------*
//LINK     IF   COMPILE.RC LE 4 THEN
//LINKEDIT EXEC PGM=HEWL,
//         PARM=(LIST,XREF,LET,'AC=0','SIZE=(512K,100K)',
//         'AMODE(31)','RMODE(ANY)',CALL)
//SYSUT1   DD   UNIT=3390,SPACE=(TRK,(15,5))
//SYSLMOD  DD   DSN=AESANJA.LEARN.LOAD(COBA12),DISP=SHR
//* SYSLIB   DD   DISP=(SHR,PASS),DSN=&&TMPOBJ
//SYSLIB   DD   DISP=SHR,DSN=AESANJA.LEARN.LOAD
//         DD   DSN=LCM.MNI.BCA.P.LOAD,DISP=SHR
//         DD   DSN=FISD.MILL30.LOAD,DISP=SHR
//         DD   DSN=FISD.MILL30.GL312.LOAD,DISP=SHR
//         DD   DSN=ATMD.BASE24.L24R512.PROD.CICSLOAD,DISP=SHR
//*        DD   DSN=WMQ.V701.TLIB.SCSQLOAD,DISP=SHR
//         DD   DSN=IMS.OTX.SDFSRESL,DISP=SHR
//         DD DISP=SHR,DSN=SYS1.CEE.SCEELKED
//           DD DISP=SHR,DSN=DB2DEV.SDSNLOAD
//           DD DISP=SHR,DSN=SYS1.LINKLIB
//CSQSTUB  DD   DSN=WMQ.V701.TLIB.SCSQLOAD,DISP=SHR
//CSQSTUB  DD   DSN=WMQ.V701.TLIB.SCSQLOAD,DISP=SHR
//TSTLIB   DD   DSN=AESANJA.LEARN.LOAD,DISP=SHR
//SYSPRINT DD SYSOUT=*
//OBJECT   DD   DISP=(SHR,PASS),DSN=&&TMPOBJ
//SYSLIN   DD   DISP=(SHR,PASS),DSN=&&TMPLNK
//         DD   *
/*
//LINK      ENDIF
//*

// *

Finnaly我绑定了我的程序

//BIND     JOB REGION=4M,NOTIFY=&SYSUID,MSGLEVEL=(1,1)                  JOB15655
//SQLBIND  PROC
//BIND     EXEC PGM=IKJEFT01,DYNAMNBR=20
//DBRMLIB  DD   DSN=IBS.BCA.DEV.DBRMLIB,DISP=SHR
//STEPLIB  DD   DSN=DB2DEV.SDSNLOAD,DISP=SHR
//SYSTSPRT DD   SYSOUT=*
//SYSPRINT DD   SYSOUT=*
//SYSUDUMP DD   SYSOUT=*
//SYSOUT   DD   SYSOUT=*
//SYSIN    DD   DUMMY
//SYSTSIN  DD   DDNAME=SYSTSIN
//         PEND
//STEP2 EXEC SQLBIND
//****************************************************************
//* UBAH XXXXXXXX MENJADI NAMA PROGRAM
//****************************************************************
//BIND.SYSTSIN DD *
  DSN SYSTEM(DSN1)
  BIND PACKAGE(DPB_COLLID) -
       OWNER(CISUSER)      -
       MEMBER(COBA12)    -
       DYNAMICRULES(BIND)  -
       VALIDATE(BIND)      -
       ISOLATION(CS)       -
       RELEASE(COMMIT)     -
       EXPLAIN(YES)
  END
  DSN SYSTEM(DSN1)
  BIND PLAN(COBA13)              -
       OWNER(CISUSER)              -
       PKLIST(DPB_COLLID.COBA12) -
       RETAIN                      -
       DYNAMICRULES(BIND)          -
       VALIDATE(BIND)              -
       ISOLATION(CS)               -
       ACQUIRE(USE)                -
       RELEASE(COMMIT)             -
       EXPLAIN(YES)
  END

/ *

然后我运行我的程序 使用这个

//DB200001  JOB CLASS=A,MSGCLASS=A,NOTIFY=&SYSUID,MSGLEVEL=(1,1),       JOB22858
//     REGION=4M,TIME=1440
//*-----------------------------------------------------------
//CICCODE2 EXEC PGM=IKJEFT01
//STEPLIB  DD DSN=AESANJA.LEARN.LOAD,DISP=SHR
//         DD DSN=LCM.MNI.BCA.P.DB2LOAD,DISP=SHR
//         DD DSN=LCM.MNI.BCA.P.LOAD,DISP=SHR
//         DD DSN=DB2DEV.SDSNLOAD,DISP=SHR
//SYSTSPRT DD SYSOUT=A
//SYSUDUMP DD SYSOUT=A
//SYSABOUT DD SYSOUT=*
//SYSDBOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSERROR DD SYSOUT=*
//SYSOUT   DD SYSOUT=A
//SYSOUD   DD SYSOUT=*
//SYSTSIN  DD *
DSN SYSTEM(DSN1) RETRY(0) TEST(0)
RUN PROGRAM(COBA12) PLAN(COBA12) -
  LIB('AESANJA.LEARN.LOAD')

一切都很顺利,我得到了返回代码4进行编译,并在另一个工作上获得了0返回代码 然后coba12程序的显示没有显示我想要的其他数据

********************************* TOP OF DATA ************************************************************************************* 
SP-DA-AVAC-BRANCH      1                                                                                                            
SP-DA-AVAC-ACCT-NO     3913                                                                                                         
SP-DA-AVAC-AVAILABLE                                                                                                                
SP-DA-AVAC-ADD-TS                                                                                                                   
SP-DA-AVAC-ADD-USER                                                                                                                 
SP-DA-AVAC-ADD-PROGRAM                                                                                                              
SP-DA-AVAC-UPD-TS                                                                                                                   
SP-DA-AVAC-UPD-USER                                                                                                                 
OUT-CODE               000000000                                                                                                    
******************************** BOTTOM OF DATA *********************************************************************************** 

在此之前我尝试在存储过程代码'sproc02'上显示一些内容 但它没有出现在假脱机sysout上,是不是我的存储过程没有被调用 或者我做错了jcl / flow 换句话说,它不会返回任何结果 我非常感谢你的回答,谢谢你:)

1 个答案:

答案 0 :(得分:0)

import matplotlib.pyplot as plt
import numpy as np

X, Y = [], []
X = np.zeros((10, 4096))
Y = np.zeros((10, 4096))

n=0
m=0
for line in open('data_set2.txt', 'r'):
  values = [float(s) for s in line.split()]
  X[n,0] = values[0]-1566518691968
  for m in range(4096):
      Y[n,m]=values[m+1]

  n=n+1
plt.plot(Y[1,0:4095])
plt.show()



b = (X[1:]-X[:-1])[:-1]
c = (X[:-1]-X[1:])[1:]
minima = np.where(np.bitwise_and(b<0, c<0))[0]+1
maxima = np.where(np.bitwise_and(b>0, c>0))[0]+1
all_peaks = np.where((b*c)>0)[0]+1
del b,c

print(minima)
print(maxima)
print(all_peaks)