473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Overpunch Character Conversion

benchpolo
142 100+
The code below does not seem to work when the value is '0000004000' it is returning a value of 4.00 instead of 40.00. Can someone please advise how to convert '0000004000' to 40.00.

Thanks.

Code:

Expand|Select|Wrap|Line Numbers
  1. DECLARE @i int
  2.     , @temp char(1), @tmp varchar(1), @a varchar(1)
  3.     , @ebcdic char(2)
  4.     , @result VARCHAR(255) , @result1 numeric(22,2) 
  5.  
  6. SET @i=1 
  7. SET @result=''
  8. set @a ='0'
  9.  
  10. WHILE (@i<=LEN(@s)) 
  11. BEGIN
  12.  
  13. SET @temp=SUBSTRING(@s,@i,1) 
  14. SET @tmp=SUBSTRING(@s,@i,1) 
  15.  
  16. SET @ebcdic=CASE @temp
  17.  
  18. --POSITIVE    
  19.     WHEN '{' THEN '0'
  20.     WHEN 'A' THEN '1'
  21.     WHEN 'B' THEN '2'  
  22.     WHEN 'C' THEN '3'  
  23.     WHEN 'D' THEN '4'  
  24.     WHEN 'E' THEN '5' 
  25.     WHEN 'F' THEN '6'
  26.     WHEN 'G' THEN '7'
  27.     WHEN 'H' THEN '8'
  28.     WHEN 'I' THEN '9'
  29.  
  30. --NEGATIVE
  31.  
  32.     WHEN '}' THEN '0' 
  33.     WHEN 'J' THEN '1'
  34.     WHEN 'K' THEN '2'  
  35.     WHEN 'L' THEN '3'  
  36.     WHEN 'M' THEN '4'  
  37.     WHEN 'N' THEN '5' 
  38.     WHEN 'O' THEN '6'
  39.     WHEN 'P' THEN '7'
  40.     WHEN 'Q' THEN '8'
  41.     WHEN 'R' THEN '9'
  42.     ELSE ' '
  43.  
  44. END
  45.  
  46. SET @a =CASE @tmp
  47. --NEGATIVE
  48.     WHEN '}' THEN '1' 
  49.     WHEN 'J' THEN '1'
  50.     WHEN 'K' THEN '1'  
  51.     WHEN 'L' THEN '1'  
  52.     WHEN 'M' THEN '1'  
  53.     WHEN 'N' THEN '1' 
  54.     WHEN 'O' THEN '1'
  55.     WHEN 'P' THEN '1'
  56.     WHEN 'Q' THEN '1'
  57.     WHEN 'R' THEN '1'
  58.     ELSE '0'
  59.  
  60. END
  61.  
  62. IF @ebcdic=''
  63.  
  64. SET @ebcdic=CASE
  65.  
  66. WHEN ASCII(@temp) BETWEEN 129 AND 137 THEN CHAR(ASCII(@temp)-32)   
  67. WHEN ASCII(@temp) BETWEEN 145 AND 153 THEN CHAR(ASCII(@temp)-39)     
  68. WHEN ASCII(@temp) BETWEEN 162 AND 169 THEN CHAR(ASCII(@temp)-47)    
  69. WHEN ASCII(@temp) BETWEEN 193 AND 201 THEN CHAR(ASCII(@temp)-128)   
  70. WHEN ASCII(@temp) BETWEEN 209 AND 217 THEN CHAR(ASCII(@temp)-135)
  71. WHEN ASCII(@temp) BETWEEN 226 AND 233 THEN CHAR(ASCII(@temp)-143)  
  72. WHEN ASCII(@temp) BETWEEN 240 AND 249 THEN CHAR(ASCII(@temp)-192)
  73.  
  74. ELSE ''
  75.  
  76. END
  77. SET @result=@result+@ebcdic 
  78. SET @i=@i+1 
  79. END
  80.  
  81. set @result1 = convert(numeric,(case when @a ='1' then '-' else '+' end + substring( @s, 1,len(@s)-1) + ltrim(rtrim(@result)))) 
  82. RETURN @result1/100
  83. END
Jun 9 '11 #1
8 6632
ck9663
2,878 Expert 2GB
What does your code trying to do? It would easier for us to recommend either a fix or a new technique.

Good Luck!!!


~~ CK
Jun 9 '11 #2
benchpolo
142 100+
It is trying to convert an overpunch character on the data that we receive for positive or negative .. so if 000000400} is received the function will convert it to -40.00 bec. of "}" character. Our vendor somehow decided to provide overpunch characters on the negative value and not on the zero positive value.

Sure, I'm always open for new suggestion.
Thanks
Jun 9 '11 #3
ck9663
2,878 Expert 2GB
Is the "}" character fixed for negative values? Are there any other character used? If it's positive, do they put in any other character identifier? Could you post some sample (maybe 10?) rows of positive and negative numbers and how it will be converted to?


~~ CK
Jun 9 '11 #4
benchpolo
142 100+
It is a total of 10 length and the last digit is always and overpunch..

000000400}
000000400{
000000500A
000000500J
000000600C
000000600L
000000310E
000000311N
000000222I
000000222R

Thanks.
Jun 9 '11 #5
benchpolo
142 100+
but when the value is not an overpunch such as 0000004000 it should be as is like 40.00
Jun 9 '11 #6
ck9663
2,878 Expert 2GB
So, based on the sample you posted, what would be the equivalent converted value? Are those all positives and only the first one as negative?


~~ CK
Jun 10 '11 #7
benchpolo
142 100+
THe negatives are okay because they are being converted throught the posted sql function script. It is when it encounters a zero "0" if its zero then it should take the as is value since the vendor does not provide the "{" overpunch value. So if the value of the field has an overpunch character at the end then convert it accordingly else take the value as is.. make sense?
Thanks ck!
Jun 10 '11 #8
ck9663
2,878 Expert 2GB
It looks to me like a straight-forward string manipulation. If I understand it right, you don't need a character by character parsing, just parse the rightmost. Try this script. It is based on your sample data.

Expand|Select|Wrap|Line Numbers
  1.  
  2. select
  3. yourvalue, 
  4. parsed =
  5.       substring(yourvalue, 1, len(yourvalue)-1) + 
  6.       case
  7.          when right(yourvalue,1) in ('{','}','0') then '0'         
  8.          when right(yourvalue,1) between 'A' and 'I' then cast(ascii(right(yourvalue,1))-64 as char(1))
  9.          when right(yourvalue,1) between 'J' and 'R' then cast(ascii(right(yourvalue,1))-73 as char(1))
  10.          else ''
  11.       end,
  12. factor =  
  13.       case
  14.          when right(yourvalue,1) in ('{','0') or right(yourvalue,1) between 'A' and 'I' then 1
  15.          when right(yourvalue,1) in ('}') or right(yourvalue,1) between 'J' and 'R' then -1
  16.       end,
  17. converted = 
  18.    (cast(
  19.          substring(yourvalue, 1, len(yourvalue)-1) + 
  20.          case
  21.             when right(yourvalue,1) in ('{','}','0') then '0'         
  22.             when right(yourvalue,1) between 'A' and 'I' then cast(ascii(right(yourvalue,1))-64 as char(1))
  23.             when right(yourvalue,1) between 'J' and 'R' then cast(ascii(right(yourvalue,1))-73 as char(1))
  24.             else ''
  25.          end
  26.         as int) *
  27.       case
  28.          when right(yourvalue,1) in ('{','0') or right(yourvalue,1) between 'A' and 'I' then 1
  29.          when right(yourvalue,1) in ('}') or right(yourvalue,1) between 'J' and 'R' then -1
  30.       end) / 100.00    
  31. from
  32. (
  33.    select yourvalue = '000000400}' 
  34.    union all
  35.    select '000000400{'
  36.    union all
  37.    select '000000500A'
  38.    union all
  39.    select '000000500J'
  40.    union all
  41.    select '000000600C'
  42.    union all
  43.    select '000000600L'
  44.    union all
  45.    select '000000310E'
  46.    union all
  47.    select '000000311N'
  48.    union all
  49.    select '000000222I'
  50.    union all
  51.    select '000000222R'
  52.    union all
  53.    select '0000004000'
  54. ) yourdata
  55.  
The "union all" sub-query was created just to create a sample data set. The four columns will show the value based on your sample data; the parsed value with the overpunch character converted, just so you can check if the letter-to-number conversion is correct; the sign converter (positive or negative); and the converted-to-integer value...

If you're going to convert this into a function, the only portion you need is the formula for the "converted" column.


Good Luck!!!

~~ CK
Jun 10 '11 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Rudolf Horbas | last post by:
Hi all, in a string from a form post, I sometimes get characters like ő (&otilde;) as raw data (not masked). ( "Å‘", if Your mail program supports this). It appears that Mozilla converts the...
2
by: Kamal | last post by:
PHP 4.3.4 on Apache 2.0.48 on Linux Red Hat 8.0 Kernel 2.4.18-14smp with Oracle 9iR2. I have this code: <html> <body> <?php
3
by: Scott | last post by:
I am using DB2 Connect on HP-UX 11i to read data from an AS400 using SQL. DB2 Connect is converting a vertical bar (¦) character to this: ª. Please see the example below. I have tried changing the...
5
by: Kasper Hansen | last post by:
I need to search through a binary file to find a specific string and then replace it with another string. However the System.Text.Encoding.ASCII.GetString method i originally used seems to do some...
4
by: Ernie Otero | last post by:
Does anyone know where I can find a function to convert numeric data to overpunch format? I've looked around but I can't seem to find any. Ernie
4
by: Lucky | last post by:
Hi Guys!!! i'm newbie to asp.net 2.0. i've got a problem. i've a textfield on my webpage and if i insert " can't " or " test - test " value into it and post it back the " ' " and " - " get...
0
by: saul.baizman | last post by:
Here's a brief description of the problem. My organization has a client who cuts and pastes information from Microsoft Word documents into web-based forms, whose contents is then displayed on a...
2
by: DaveP | last post by:
hi i want to convert say letter A to its Ascii Value and back to its Character Value.. im cant Seem To Find how to do this Tks DaveP
9
by: =?Utf-8?B?UGhhbmlkaGFy?= | last post by:
Hi, I'm developing a Winform application in C#( .net 2.0). I've a dialog box where user can input text and that text would be sent across to other machine using sockets. When the user enters...
1
by: amollokhande1 | last post by:
Hi All, I want to build an application that will convert the english characters into other languages like Chinees, Japanies etc using VB.net. I am looking for use of Double byte character set for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.