View previous topic :: View next topic
|
Author |
Message |
Vivek Anand
New User
Joined: 04 Jun 2013 Posts: 19 Location: India
|
|
|
|
Hi All,
I have a requirement to execute DB2 commands & SQL statements in REXX. Below is the code snippet
/* REXX */
ADDRESS TSO
'SUBCOM DSNREXX'
IF RC THEN
S_RC = RXSUBCOM('ADD','DSNREXX','DSNREXX')
ADDRESS DSNREXX
'CONNECT' ITD2
'-DISPLAY DATABASE(NGA01D0) SPACENAM(NGA01T0)'
EXIT
The program runs fine until the CONNECT statement. However the DISPLAY DATABASE statement issues a RC(-1). I am unable to figure out the reason for this.
Could any one help me with this. |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
You do show return code checking of the connect. How do you know that it connected OK? |
|
Back to top |
|
|
Vivek Anand
New User
Joined: 04 Jun 2013 Posts: 19 Location: India
|
|
|
|
Nic Clouston wrote: |
You do show return code checking of the connect. How do you know that it connected OK? |
The CONNECT statement gave a RC = 0. So I presumed this was successful. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Remove SUBCOM and CONNECT from your code and try this:
Code: |
/* rexx */
Queue "-DISPLAY DATABASE(NGA01D0) SPACENAM(NGA01T0)"
Queue "END"
Address TSO "DSN SYSTEM(ITD2)" |
If ITD2 is not your system name but a variable containing your system name, then:
Code: |
Address TSO "DSN SYSTEM("ITD2")" |
If you have not changed your default Address, then this is enough:
Code: |
"DSN SYSTEM("ITD2")" |
|
|
Back to top |
|
|
Vivek Anand
New User
Joined: 04 Jun 2013 Posts: 19 Location: India
|
|
|
|
Marso wrote: |
Remove SUBCOM and CONNECT from your code and try this:
Code: |
/* rexx */
Queue "-DISPLAY DATABASE(NGA01D0) SPACENAM(NGA01T0)"
Queue "END"
Address TSO "DSN SYSTEM(ITD2)" |
If ITD2 is not your system name but a variable containing your system name, then:
Code: |
Address TSO "DSN SYSTEM("ITD2")" |
If you have not changed your default Address, then this is enough:
Code: |
"DSN SYSTEM("ITD2")" |
|
Hi Marso,
Thanks a lot, this works. Will I also be able to run SQL queries using the same process? I tried but could not figure out the correct syntax. Could you advice please. |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Well, without seeing what syntax you used how can wee tell what you have done wrong? Are you using the syntax in the manual? Have you read the entire SQL/Rexx section of the manual? |
|
Back to top |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
-DISPLAY is a DB2 command, not an SQL statement. If you look at Marso's example, you will see that it places a DB2 command on the stack and then executes the "DSN" command. The "DSN" command starts up the DB2 command processor, and it automatically picks up the stacked command from the queue and runs it. The second stacked command, "END" shuts down the command processor.
DSNREXX is used to execute SQL statements, not DB2 commands. |
|
Back to top |
|
|
Vivek Anand
New User
Joined: 04 Jun 2013 Posts: 19 Location: India
|
|
|
|
don.leahy wrote: |
-DISPLAY is a DB2 command, not an SQL statement. If you look at Marso's example, you will see that it places a DB2 command on the stack and then executes the "DSN" command. The "DSN" command starts up the DB2 command processor, and it automatically picks up the stacked command from the queue and runs it. The second stacked command, "END" shuts down the command processor.
DSNREXX is used to execute SQL statements, not DB2 commands. |
Hi,
Thanks for clarifying. Will look for other means to execute SQL statements. |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
You seem to have been doing it correctly for SQL statements but you have to use a different method for DB2 command,s as shown above, because they are NOT SQL. |
|
Back to top |
|
|
|