IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Include leading zeros in alphanumeric variable


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
beruoist

New User


Joined: 14 Nov 2007
Posts: 70
Location: mumbai

PostPosted: Mon Dec 29, 2008 3:54 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Dec 29, 2008 4:46 pm
Reply with quote

what is the datatype of the account column in your table?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Dec 29, 2008 5:00 pm
Reply with quote

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
View user's profile Send private message
beruoist

New User


Joined: 14 Nov 2007
Posts: 70
Location: mumbai

PostPosted: Mon Dec 29, 2008 5:10 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Dec 29, 2008 5:32 pm
Reply with quote

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
View user's profile Send private message
beruoist

New User


Joined: 14 Nov 2007
Posts: 70
Location: mumbai

PostPosted: Mon Dec 29, 2008 6:18 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon Dec 29, 2008 6:33 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Dec 29, 2008 9:52 pm
Reply with quote

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
View user's profile Send private message
beruoist

New User


Joined: 14 Nov 2007
Posts: 70
Location: mumbai

PostPosted: Wed Dec 31, 2008 8:14 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Dec 31, 2008 8:17 am
Reply with quote

You're welcome - thanks for the follow-up icon_smile.gif

d
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Keep leading zero(s) after convert fl... SYNCSORT 7
No new posts Remove leading zeroes SYNCSORT 4
No new posts leading spaces can be removed in trai... DFSORT/ICETOOL 1
Search our Forums:

Back to Top