If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Bad Arithmetic Conversion

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-24-10, 11:49
rcanter rcanter is offline
Registered User
 
Join Date: Feb 2010
Posts: 6
Question Bad Arithmetic Conversion

I am hoping this is the correct forum for this. I am running DB2 and SQL in IMS.
When I submit my job, I get an error: Bad Arithmetic Conversion on this line
check = check + (substr(SUM,Ndx,1) *, wgtFactor.Ndx)

HTML Code:
FULL = substr(pattern,1,10) || "0000001"                     
FULL = translate(FULL,"11","&*")                              
SUM = translate(FULL,,                                   
"12345678123457923456789","ABCDEFGHJKLMNPRSTUVWXYZ")                
wgtFactor.1 = 8                                                     
wgtFactor.2 = 7                                                     
wgtFactor.3 = 6                                                     
wgtFactor.4 = 5                                                     
wgtFactor.5 = 4                                                     
wgtFactor.6 = 3                                                     
wgtFactor.7 = 2                                                     
wgtFactor.8 = 10                                                    
wgtFactor.9 = 0                                                     
wgtFactor.10 = 9                                                    
wgtFactor.11 = 8                                                    
wgtFactor.12 = 7                                                    
wgtFactor.13 = 6                                                    
wgtFactor.14 = 5                                                    
wgtFactor.15 = 4                                                    
wgtFactor.16 = 3                                                    
wgtFactor.17 = 2                                                    
check = 0                                                        
do Ndx = 1 to 17                                                 
    check = check + (substr(SUM,Ndx,1) *,   wgtFactor.Ndx)                                               
end                                                                 
Digit = check // 11                                         
if Digit = 10 then                                             
    Digit = "X"                                                
FULL = substr(FULL,1,8) || Digit || substr(FULL,10,8) 
Reply With Quote
  #2 (permalink)  
Old 02-24-10, 12:27
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
translate(FULL,,
"12345678123457923456789","ABCDEFGHJKLMNPRSTUVWXYZ ")

12345678123457923456789
ABCDEFGHJKLMNPRSTUVWXYZ

Has to be same number of characters. If not extra characters translated to spaces, which is not the digits.

Lenny
Reply With Quote
  #3 (permalink)  
Old 02-24-10, 12:58
rcanter rcanter is offline
Registered User
 
Join Date: Feb 2010
Posts: 6
translate(FULL,, "12345678123457923456789","ABCDEFGHJKLMNPRSTUVWXYZ ")


Both have 23 characters.
Reply With Quote
  #4 (permalink)  
Old 02-24-10, 13:48
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
It looks like you have unnecessary commas all over the place. Not to mention the fact that you shouldn't multiply integers by strings.
Reply With Quote
  #5 (permalink)  
Old 02-24-10, 14:26
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Quote:
Originally Posted by n_i View Post
It looks like you have unnecessary commas all over the place. Not to mention the fact that you shouldn't multiply integers by strings.
There are not a DB2 code (I think).
But translate command working for any languages in the same way...

Lenny
Reply With Quote
  #6 (permalink)  
Old 02-24-10, 14:27
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Quote:
Originally Posted by rcanter View Post
translate(FULL,, "12345678123457923456789","ABCDEFGHJKLMNPRSTUVWXYZ ")


Both have 23 characters.
Extra comma, anyway...
Reply With Quote
  #7 (permalink)  
Old 02-24-10, 16:05
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Lightbulb

You lost the letter "I" (for examle), also you did non convert the special characters and lower case letters, so if you will try to do following:

Code:
select translate('IIIIIIabcd',                                   
'12345678123457923456789','ABCDEFGHJKLMNPRSTUVWXYZ')  "Translated"
from sysibm.sysdummy1;
you'll get the result:

Quote:
Translated
IIIIIIabcd
So if in pattern you have "I", or lower case letters you'll have an Arithmetic exception....

Lenny

Last edited by Lenny77; 02-24-10 at 16:10.
Reply With Quote
  #8 (permalink)  
Old 02-24-10, 16:34
rcanter rcanter is offline
Registered User
 
Join Date: Feb 2010
Posts: 6
I have tried removing the comma and still getting same error. Besides, the comma is telling it to continue on the next line (statement not finished).

There are specific letters missing for a reason. And lowercase doesn't concern me. Both of those are convered in other storage procedures that this job calls.

Last edited by rcanter; 02-24-10 at 16:48.
Reply With Quote
  #9 (permalink)  
Old 02-24-10, 16:59
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Question

Quote:
Originally Posted by rcanter View Post
I have tried removing the comma and still getting same error. Besides, the comma is telling it to continue on the next line (statement not finished).

There are specific letters missing for a reason. And lowercase doesn't concern me. Both of those are convered in other storage procedures that this job calls.
Code:
check = check + (substr(SUM,Ndx,1) *,   wgtFactor.Ndx)
What for this comma ?
Reply With Quote
  #10 (permalink)  
Old 02-24-10, 17:00
rcanter rcanter is offline
Registered User
 
Join Date: Feb 2010
Posts: 6
the wgtFactor.Ndx) is on the next line. The , specifies that.
Reply With Quote
  #11 (permalink)  
Old 02-24-10, 17:04
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Quote:
Originally Posted by rcanter View Post
the wgtFactor.Ndx) is on the next line. The , specifies that.
This is really not good:
Code:
Digit = "X"
Reply With Quote
  #12 (permalink)  
Old 02-24-10, 17:04
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,194
1) What is the contents of pattern?
Are there any character other than alphanumeric or '&*' in pattern?
What is the result of "say pattern"?
(I guessed you are using REXX.)

2) Is the comma not extra?
Code:
    check = check + (substr(SUM,Ndx,1) *,   wgtFactor.Ndx)
If the line was splitted into two lines, it would be correct.
Code:
    check = check + (substr(SUM,Ndx,1) *,
                     wgtFactor.Ndx)
Reply With Quote
  #13 (permalink)  
Old 02-24-10, 17:07
rcanter rcanter is offline
Registered User
 
Join Date: Feb 2010
Posts: 6
The contents of pattern will be a number, letter or &. There are a few exceptions that will not be used, such as I, O and Q.
The line is split with the comma being at the end the way you have it in second set of code.
Reply With Quote
  #14 (permalink)  
Old 02-24-10, 17:25
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,194
Quote:
The contents of pattern will be a number, letter or &.
How did you confirmed that?
(If you convinced that from your program logic/code, it may include bugs.)
What are the result of "say pattern" and "say FULL"?
Don't these include blanks?
Reply With Quote
  #15 (permalink)  
Old 02-24-10, 17:28
rcanter rcanter is offline
Registered User
 
Join Date: Feb 2010
Posts: 6
No blanks. The data is drawn from a database that I upload. Pattern has the first 10 char's of full, which has 17.
I think I am gonna try to display my results somehow to see the data.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On