Let me keep this brief. I am writing a small utility in Rexx for my project. I want my rexx-script to talk to DB2, and query a few tables. Here's my code -
/* REXX */
SUBCOM DSNREXX
S_RC = RXSUBCOM('ADD','DSNREXX','DSNREXX')
address DSNREXX "CONNECT DB8G"
sqlstmt = "SELECT NAME
FROM SYSIBM.SYSTABLES
FETCH FIRST 10 ROWS ONLY"
address dsnrexx
"EXECSQL DECLARE C1 CURSOR FOR S1"
"EXECSQL PREPARE S1 FROM :sqlstmt"
"EXECSQL OPEN C1"
say 'Open SQLCODE : ' SQLCODE
sqln = SQLDA.SQLD
say 'sqln = ' sqln
hdrs = ""
do while sqlcode <> 100
address dsnrexx
"EXECSQL FETCH C1 USING DESCRIPTOR :SQLDA"
do indx = 1 to sqln
hdrs = hdrs SQLDA.indx.sqlname
end
say hdrs
cols = ""
do indx = 1 to sqln
cols = cols SQLDA.indx.sqldata
end
say cols
end
"EXECSQL CLOSE C1"
"DISCONNECT"
SUBCOM DSNREXX
S_RC = RXSUBCOM('ADD','DSNREXX','DSNREXX')
address DSNREXX "CONNECT DB8G"
sqlstmt = "SELECT NAME
FROM SYSIBM.SYSTABLES
FETCH FIRST 10 ROWS ONLY"
address dsnrexx
"EXECSQL DECLARE C1 CURSOR FOR S1"
"EXECSQL PREPARE S1 FROM :sqlstmt"
"EXECSQL OPEN C1"
say 'Open SQLCODE : ' SQLCODE
sqln = SQLDA.SQLD
say 'sqln = ' sqln
hdrs = ""
do while sqlcode <> 100
address dsnrexx
"EXECSQL FETCH C1 USING DESCRIPTOR :SQLDA"
do indx = 1 to sqln
hdrs = hdrs SQLDA.indx.sqlname
end
say hdrs
cols = ""
do indx = 1 to sqln
cols = cols SQLDA.indx.sqldata
end
say cols
end
"EXECSQL CLOSE C1"
"DISCONNECT"
However, I am not getting the output in a proper format. It seems, somehow, the SQLDA Descriptor is not being recongnised. I know, its something silly, but couldn't figure out. Here's some sample output that I am getting -
EMP-DEP SQLDA.2.SQLDATA SQLDA.3.SQLDATA SQLDA.4.SQLDATA SQLDA.5.SQLDATA
SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQLNA
E SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQLN
ME SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQL
AME
DEPT3360 SQLDA.2.SQLDATA SQLDA.3.SQLDATA SQLDA.4.SQLDATA SQLDA.5.SQLDATA
SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQLNA
E SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQLN
ME SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQL
AME SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQ
NAME
EMPLDUMM SQLDA.2.SQLDATA SQLDA.3.SQLDATA SQLDA.4.SQLDATA SQLDA.5.SQLDATA
SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQLNA
E SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQLN
ME SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQL
AME SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQ
NAME SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.S
LNAME
SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQLNA
E SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQLN
ME SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQL
AME
DEPT3360 SQLDA.2.SQLDATA SQLDA.3.SQLDATA SQLDA.4.SQLDATA SQLDA.5.SQLDATA
SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQLNA
E SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQLN
ME SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQL
AME SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQ
NAME
EMPLDUMM SQLDA.2.SQLDATA SQLDA.3.SQLDATA SQLDA.4.SQLDATA SQLDA.5.SQLDATA
SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQLNA
E SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQLN
ME SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQL
AME SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.SQ
NAME SQLDA.1.SQLNAME SQLDA.2.SQLNAME SQLDA.3.SQLNAME SQLDA.4.SQLNAME SQLDA.5.S
LNAME