MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

If statement for numeric field in the way of alphanumeric

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
chandhroo
Beginner


Joined: 02 Dec 2002
Posts: 36
Topics: 13

PostPosted: Fri Feb 14, 2003 11:53 am    Post subject: If statement for numeric field in the way of alphanumeric Reply with quote

Hi,
I have field like below.

03 BUSINESS-CODE PIC 999.

and if statement

IF BUSINESS-CODE ='111'
statement1
ELSE
statement2
END-IF.


Above code works fine. There is no any redifne statement for alphanumeric, generally we will check numeric fields without quote. I don't know how it works, could anyone of explain how?

Thanks
Chandru
Back to top
View user's profile Send private message
CaptBill
Beginner


Joined: 02 Dec 2002
Posts: 100
Topics: 2
Location: Pasadena, California, USA

PostPosted: Fri Feb 14, 2003 12:30 pm    Post subject: Reply with quote

What you have there is an example of poor coding practice. Mad

It works (but it's still poor) because the bit configuration for a numeric literal is the same as the same literal treated as alphanumeric. Numeric fields should be checked using numeric literals. Removing the single quotes will make it a numeric literal.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
chandhroo
Beginner


Joined: 02 Dec 2002
Posts: 36
Topics: 13

PostPosted: Fri Feb 14, 2003 1:02 pm    Post subject: Reply with quote

CaptBill,
Currently im working with programs which are develped about decade before. Actually I was thinking that numeric variable should be validated without code and it will give compilation error if we give quote. I wonder what will happen if we check
IF BUSINESS-CODE ='AAA'
Will it be a compilation error or run time error?

--Chandru
Back to top
View user's profile Send private message
CaptBill
Beginner


Joined: 02 Dec 2002
Posts: 100
Topics: 2
Location: Pasadena, California, USA

PostPosted: Fri Feb 14, 2003 3:04 pm    Post subject: Reply with quote

There are at least three ways to learn something. One is by reading about it. One is by hearing about it. One is by doing it.

I will assume you have checked the manuals and consulted with coworkers. Why not put that code in a program and compile it to see what happens? Then if no compile error, run the program and see what happens. This is called "TESTING". It also educates you and is the third way to learn something..

BTW, as a general rule of programming, code those things which are used in arithmetic operations as numeric either as packed, zoned, binary or other numeric data representation. Define all other data items as character.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group