View previous topic :: View next topic
|
Author |
Message |
beruoist
New User
Joined: 14 Nov 2007 Posts: 70 Location: mumbai
|
|
|
|
Hi
I have account information like below
/1237879 ---> this is alphanumeric
account is a 12 byte field..
now when i have to do a look up in the database for this account there should be leading zeros like below
00001237879
Please tell me how i will do this ? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
what is the datatype of the account column in your table? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
since you have an alphanumeric field, the data is normally left justified.
you can use the intrinsic function NUMVAL to convert the alphanumeric to numeric.
define the numeric field as S9(12). you should have a sign, since no db2 numeric datatypes are without sign.
MOVE NUMVAL(alpha-field) to numeric-field.
or
COMPUTE numeric-field = NUMVAL(alpha-field) |
|
Back to top |
|
|
beruoist
New User
Joined: 14 Nov 2007 Posts: 70 Location: mumbai
|
|
|
|
Thanx for the response.
Database var is X(12) only.And the database we are using is adabas.
I tried to use inspect,but it is not working.I will try to work it out as you suggested.
By the way if we have to do it byte by byte..how we will accomplish it.
Can you please help. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
again, pic x(12) normally gets left justified. so, there are no leading zeros. or in this case spaces that could be converted to zeros with the
inspect verb.
not knowing what your source is for the account number.......................
which would be sorta helpful here.....
numval the PIC X(12) alpha numeric to an unsigned numeric PIC 9(12).
redefine this pic 9(12) as pic x(12) and use it as the key for your database access after the numval.
byte for byte is not necessary. |
|
Back to top |
|
|
beruoist
New User
Joined: 14 Nov 2007 Posts: 70 Location: mumbai
|
|
|
|
well, thanx for reply.
NUMVAL worked for me.I don't know why INSPECT was not working to replace the leading space by zero.
i redefined the accnt part of the key to 9(12) from X(12).and then later on used a NUMVAL. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
I don't know why INSPECT was not working to replace the leading space by zero. |
Because alphanumeric fields frequently are left justified, so there may not have been any leading spaces for your INSPECT to replace -- they could have been trailing spaces. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
What became of the slash ('/') in the "input" or was the slash just a typo?
In the data you posted, there is no "leading" space(s), so the INSPECT could not work. |
|
Back to top |
|
|
beruoist
New User
Joined: 14 Nov 2007 Posts: 70 Location: mumbai
|
|
|
|
Hey Dick,
'/' is not a typo.when we have a account in the field the first field is '/'.So just to identify the account is in that place.we break up the VAR and check for slash..then take the account seperately and do the check for the valid accnt etc etc.
I got the inspect point.
I have applied it using NUMVAL.however i had applied a numeric check before it,so that a system abend will not occur,if a non numeric value is provided in the field by mistake.
thanks everyone for ur inputs. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
You're welcome - thanks for the follow-up
d |
|
Back to top |
|
|
|