Thanks every one, I figured out what was needed. I am pasting my code just in case someone can benefit from it.
Thanks.
ADDRESS DSNREXX
CONNECT DB2SYS
SQLSTMT = "SELECT NAME,COLTYPE FROM SYSIBM.SYSCOLUMNS
WHERE TBNAME = '"||TNAME||"'"
"EXECSQL DECLARE C1 CURSOR FOR S1"
"EXECSQL PREPARE S1 FROM :SQLSTMT"
"EXECSQL OPEN C1"
"EXECSQL FETCH C1 INTO :COLUMN,:CTYPE"
I=1
DO WHILE (SQLCODE = 0)
IF CTYPE <> 'CHAR' THEN COLUMN='CHAR('||COLUMN||')'
IF FIRSTTIME='TRUE' THEN
DO
SELSTMT=SELSTMT||COLUMN||COMAAPPEND
FIRSTTIME='FALSE'
SELVAL.I="SELECT "||COLUMN||COMAAPPEND
/* SAY "SELVAL="SELVAL.I */ I=I+1
END
ELSE
DO
/* SELSTMT=SELSTMT||','||COLUMN||COMAAPPEND */
SELSTMT=SELSTMT||',STRIP('||COLUMN||')'||COMAAPPEND
SELVAL.I=',STRIP('||COLUMN||')'||COMAAPPEND
I=I+1
/* SAY "SELVAL.="SELVAL.I */
END
"EXECSQL FETCH C1 INTO :COLUMN,:CTYPE"
END
SELSTMT=SELSTMT||" FROM "||SCHEMA||"."||TNAME
"EXECSQL CLOSE C1"
S_RC = RXSUBCOM(DELETE,DSNREXX,DSNREXX)
I am feting all columns of a given table to make a SELECT statement that has comma appended after every column so that it can generated a comma separated list of data.
Dont forget to switch your DSN environment if you need something like write output to a file.
ADDRESS TSO
OUTDSN="'FQ1.KA.FILE1.SQL'"