compare numeric and alphanumeric values ?



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

compare numeric and alphanumeric values ?

Postby mathew28 » Mon Jan 11, 2010 10:31 am

I have a numeric value var1 9(7) = 0334454
and another alphanumeric value var2 x(7) = 334454. I need to compare var1 = var2. Though both the values are same, the condn if var1 == var2 fails. To make it work, i moved the alphanumeric var2 to a temp numeric variable var3 9(7) (MOVE var2 TO var3). The value is getting moved as 3344540. So, still 0334454 is not equal to 3344540.

Is there a solution to remove the leading zeros in var1 ? OR Is there a solution to right justify the value in the temp variable var3 ? Please help....
mathew28
 
Posts: 30
Joined: Tue Oct 20, 2009 11:06 am
Has thanked: 0 time
Been thanked: 0 time

Re: compare numeric and alphanumeric values ?

Postby dick scherrer » Mon Jan 11, 2010 11:09 am

Hello,

If you know the value in var2 will always be valid, you could use NUMVAL for the move to the temp numeric.

http://publibz.boulder.ibm.com/cgi-bin/ ... r40/7.1.32

If the value in var2 is ever non-numeric, it will abend.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: compare numeric and alphanumeric values ?

Postby mathew28 » Mon Jan 11, 2010 2:59 pm

Thanks very much dick for the timely help !!
mathew28
 
Posts: 30
Joined: Tue Oct 20, 2009 11:06 am
Has thanked: 0 time
Been thanked: 0 time

Re: compare numeric and alphanumeric values ?

Postby dick scherrer » Tue Jan 12, 2010 12:24 am

You're welcome - good luck :)

d
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post