Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Include leading zeros in alphanumeric variable

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Include leading zeros in alphanumeric variable
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    Post subject:
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    Post subject:
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    Post subject: Reply to: how to include leading zeros in a alphanumeric var
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    Post subject:
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    Post subject: Reply to: how to include leading zeros in a alphanumeric var
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: 7935
Location: Bellevue, IA

PostPosted: Mon Dec 29, 2008 6:33 pm    Post subject:
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

Site Director


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

PostPosted: Mon Dec 29, 2008 9:52 pm    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Wed Dec 31, 2008 8:17 am    Post subject: Reply to: how to include leading zeros in a alphanumeric var
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. How to move a long alphanumeric data ... lind sh COBOL Programming 8 Mon Dec 05, 2016 7:51 pm
This topic is locked: you cannot edit posts or make replies. How to pass the previous month date i... Suganya87 DFSORT/ICETOOL 5 Mon Oct 31, 2016 4:13 pm
No new posts Format to pipe delimited with variabl... pshongal SYNCSORT 6 Wed Sep 14, 2016 2:48 pm
This topic is locked: you cannot edit posts or make replies. Alphanumeric to Numeric move on UNIX mistah kurtz COBOL Programming 16 Wed Jul 27, 2016 8:47 pm
No new posts Variable for cursor names ravikumar15 DB2 5 Sun Jul 17, 2016 7:08 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us