View previous topic :: View next topic
|
Author |
Message |
pshongal
New User
Joined: 14 Jun 2012 Posts: 96 Location: India
|
|
|
|
I would like to delete multiple rows in the DB2 table using REXX. I have given GU interface to enter a/c#s. Rexx pgm should delete those from DB. I have below rexx pgm. It ends normally when executed, row is not deleting.
Code:
/*REXX*/
START:
/*
USER = SYSVAR('SYSUID')
"ISPEXEC DISPLAY PANEL(DELEMSCR)"
Message = ' '
If RC ¬= 0 Then
Do
exit
End
If RG = 'E1' Then
SSID = 'DB2D'
Else
SSID = 'DB2T'
ADDRESS TSO "SUBCOM DSNREXX"
IF RC THEN
S_RC = RXSUBCOM('ADD','DSNREXX','DSNREXX')
ADDRESS DSNREXX "CONNECT "SSID
QUERYSQL = "DELETE FROM VMUSHE.REL_AD_USE WHERE "||,
"table_name = '"||AC1||"'"||" AND ab_c = NULL"
SAY 'DELETING 'AC1
SAY QUERYSQL
ADDRESS DSNREXX "EXECSQL EXECUTE S1 FROM QUERYSQL"
IF SQLCODE = 0 THEN DO
SAY 'ACCT DELETED SUCCESSFULLY'
END
EXIT |
|
Back to top |
|
|
Naish
New User
Joined: 07 Dec 2006 Posts: 82 Location: UK
|
|
|
|
I am not a REXX guy. But, I feel you missed COMMITTING it...
Also, why did you post again??? |
|
Back to top |
|
|
pshongal
New User
Joined: 14 Jun 2012 Posts: 96 Location: India
|
|
|
|
@Naish-
[Also, why did you post again???]
Since moderator had put my query in DB2 forum, I had to post again...
[/quote] |
|
Back to top |
|
|
Naish
New User
Joined: 07 Dec 2006 Posts: 82 Location: UK
|
|
|
|
If you had problems, you may have questioned it on that very post.
Let the moderator reply now...
Also, did you try what was pointed out to you? |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
pshongal wrote: |
@Naish-
[Also, why did you post again???]
Since moderator had put my query in DB2 forum, I had to post again...
|
Ah, so your mind is too fragile to handle reading a different forum. |
|
Back to top |
|
|
pshongal
New User
Joined: 14 Jun 2012 Posts: 96 Location: India
|
|
|
|
Hi Naish,
I changed it as below...still no luck..
/*REXX*/
CLEAR
START:
CNT = 0
USER = SYSVAR('SYSUID')
"ISPEXEC DISPLAY PANEL(DELEMSCR)"
Message = ' '
If RC ¬= 0 Then
Do
exit
End
If RG = 'E1' Then
SSID = 'DB2D'
Else
SSID = 'DB2T'
ADDRESS TSO "SUBCOM DSNREXX"
IF RC THEN
S_RC = RXSUBCOM('ADD','DSNREXX','DSNREXX')
ADDRESS DSNREXX "CONNECT "SSID
QUERYSQL = "DELETE FROM table_name"||,
"ac_num = '"||AC1||"'"||" AND abc = NULL"
rexxvar="COMMIT"
SAY 'DELETING 'AC1
SAY QUERYSQL
ADDRESS DSNREXX "EXECSQL PREPARE S1 FROM :QUERYSQL"
ADDRESS DSNREXX "EXECSQL EXECUTE S1"
IF SQLCODE = 0 THEN DO
ADDRESS DSNREXX "EXECSQL rexxvar"
SAY 'ACCT DELETED SUCCESSFULLY'
ADDRESS DSNREXX "DISCONNECT"
END
EXIT |
|
Back to top |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
I looked up "no luck" in the messages and codes manual and couldn't get a hit.
You need to display the SQLCODE to start to figure out what happened.
Did you consider using "EXECUTE IMMEDIATE" for your DELETE statement? |
|
Back to top |
|
|
pshongal
New User
Joined: 14 Jun 2012 Posts: 96 Location: India
|
|
|
|
I tried EXECUTE IMMEDIATE, still not working. I displayed RC, it is -1. Does it mean my query is wrong? Below are my program displays
DELETING 3777478550900
DELETE FROM table_name WHERE ac_num = '3777478550900'
RC -1 |
|
Back to top |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
-1 is the RC. You need to look at the SQLCODE. After every EXECSQL statement.
The query looks okay, but from your code it is not clear if you are even connected to DB2. How do you know that the CONNECT worked?
Until you provide this information it is pointless to speculate. |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
What does your trace show? and please use the code tags to make the program readable. I am not going to struggle through it in the unformatted mess that it is currently displayed - I do not have time. |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
pshongal wrote: |
I tried EXECUTE IMMEDIATE, still not working. I displayed RC, it is -1. Does it mean my query is wrong? Below are my program displays
DELETING 3777478550900
DELETE FROM table_name WHERE ac_num = '3777478550900'
RC -1 |
Yes; RC = -1 from DSNREXX invariably means the SQL passed to it is incorrect.
The apparent use of table_name is due to sloppy editing on your part, yes? |
|
Back to top |
|
|
pshongal
New User
Joined: 14 Jun 2012 Posts: 96 Location: India
|
|
|
|
@Akatsukami
Yes..right.
I will use trace and try to find where its going wrong. |
|
Back to top |
|
|
pshongal
New User
Joined: 14 Jun 2012 Posts: 96 Location: India
|
|
|
|
I tried with TRACE,
When it comes to execute statement ADDRESS DSNREXX "EXECSQL EXECUTE S1" RC is -1 and sqlcode is -104 and sqlstate: 42601. |
|
Back to top |
|
|
Gnanas N
Active Member
Joined: 06 Sep 2007 Posts: 792 Location: Chennai, India
|
|
|
|
Please check the explanation and programmer response for the SQLCODE -104
Code: |
QUERYSQL = "DELETE FROM table_name"||,
"ac_num = '"||AC1||"'"||" AND abc = NULL" |
Here, " AND abc = NULL" shouldn't be "AND abc IS NULL"? |
|
Back to top |
|
|
pshongal
New User
Joined: 14 Jun 2012 Posts: 96 Location: India
|
|
|
|
Hi Gnana Sekaran.
I infact removed that condition itself.
Code:
QUERYSQL = "DELETE FROM table_name WHERE"||,
"ac_num = '"||AC1||"';"
Still same result. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
what is the datatype of column ac_num? |
|
Back to top |
|
|
pshongal
New User
Joined: 14 Jun 2012 Posts: 96 Location: India
|
|
|
|
Hi dbzTHEdinosauer, its CHAR |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
char(?) and are the numbers left or right justified and are they padded with spaces, zeros or what? |
|
Back to top |
|
|
pshongal
New User
Joined: 14 Jun 2012 Posts: 96 Location: India
|
|
|
|
Hi dbzTHEdinosauer,
CHAR(28), Its left justified and padded with spaces. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
ILLEGAL SYMBOL "token". SOME SYMBOLS THAT MIGHT BE LEGAL ARE: token-list
that is the message returned with an sqlcode -104.
you need to call dsntiar for that.
here are a couple of links:
calling dsntiar from rexx by don leahy
you may want to look into "RXSQLCA"
here is one from PRINO
without the info, we are just guessing - no we are wasting time. |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
pshongal wrote: |
Hi Gnana Sekaran.
I infact removed that condition itself.
Code:
QUERYSQL = "DELETE FROM table_name WHERE"||,
"ac_num = '"||AC1||"';"
Still same result. |
So, what you're passing to DSNREXX is
Code: |
DELETE FROM table_name WHEREac_num = 'AC1'; |
and you're puzzled as to why it doesn't work? |
|
Back to top |
|
|
pshongal
New User
Joined: 14 Jun 2012 Posts: 96 Location: India
|
|
|
|
Hi Akatsukami,
Thats right. |
|
Back to top |
|
|
Stefan
Active User
Joined: 12 Jan 2006 Posts: 110 Location: Germany
|
|
|
|
Code: |
QUERYSQL = "DELETE FROM table_name WHERE"||,
"ac_num = '"||AC1||"';"
|
I assume the -104 comes from the table name concatenated with the word "WHERE".
So put in a blank or remove the silly || as in
Code: |
QUERYSQL = "DELETE FROM table_name WHERE",
"ac_num = '"||AC1||"';"
|
|
|
Back to top |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
Long thread for such a simple problem. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
About your problem:- In addition to displaying the SQLCODE, you should as well display the SQLERRMC value.
It will tell you which token is erroneous. About your code:- The SUBCOM to CONNECT commands should be issued before displaying the panel.
If there is a problem connecting to DB2, why let the user loose time in filling the panel. - That will not work:
Quote: |
rexxvar="COMMIT"
ADDRESS DSNREXX "EXECSQL rexxvar" |
This is nice if you are paid by the line:
Quote: |
If RC ¬= 0 Then
Do
exit
End |
If not, you could just write "If RC ¬= 0 Then Exit"
About your post:- Use COPY/PASTE or double-check yourself!
"WHERE" is missing from these lines:
Quote: |
QUERYSQL = "DELETE FROM table_name"||,
"ac_num = '"||AC1||"'"||" AND abc = NULL" |
Learn to use BBCODE ! |
|
Back to top |
|
|
|