REXX AND THE CORRESPONDING JCL TO CONNECT TO DB2 IN BATCH The following piece of rexx code can be used to connect with the DB2 database. REXX Code for Connecting with DB2
QUERY = “SELECT EMP_NUM”, ADDRESS TSO “SUBCOM DSNREXX” /* HOST CMD ENV AVAILABLE ? */ IF RC THEN S_RC = RXSUBCOM(‘ADD’,’DSNREXX’,’DSNREXX’) ADDRESS DSNREXX “CONNECT” SUBSYS IF SQLCODE 0 THEN COUTPUT SQLCA ADDRESS DSNREXX “EXECSQL DECLARE C1 CURSOR FOR S1” IF SQLCODE 0 THEN CALL SQLCA ADDRESS DSNREXX “EXECSQL PREPARE S1 FROM :QUERY” IF SQLCODE 0 THEN CALL SQLCA ADDRESS DSNREXX “EXECSQL DESCRIBE S1 INTO :OUTPUT” IF SQLCODE 0 THEN CALL SQLCA ADDRESS DSNREXX “EXECSQL OPEN C1” IF SQLCODE 0 THEN CALL SQLCA ADDRESS DSNREXX “EXECSQL FETCH C1 USING DESCRIPTOR :OUTPUT” SAY ” > COLUMN NUMBER: ” I SAY ” COLUMN NAME: ” OUTPUT.I.SQLNAME SAY ” COLUMN TYPE: ” OUTPUT.I.SQLTYPE SAY ” COLUMN VALUE: ” OUTPUT.I.SQLDATA
JCL for connecting REXX with DB2 ; ; ; ;
//REXXJCL JOB (XXXXXXXX,,,,,XXXX),’ ‘,CLASS=T, // MSGCLASS=Y,NOTIFY=&SYSUID //STEP1 EXEC PGM=IKJEFT01,PARM=’REXXDB2’ //STEPLIB DD DISP=SHR,DSN=XXXDB2.YYYT.SDSNEXIT // DD DISP=SHR,DSN=XXXDB2.YYYT.SDSNLOAD //SYSEXEC DD DSN=USERID.ABC.REXXLIB,DISP=SHR