View previous topic :: View next topic |
Author |
Message |
chandhroo Beginner
Joined: 02 Dec 2002 Posts: 36 Topics: 13
|
Posted: Fri Feb 14, 2003 11:53 am Post subject: If statement for numeric field in the way of alphanumeric |
|
|
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 |
|
|
CaptBill Beginner
Joined: 02 Dec 2002 Posts: 100 Topics: 2 Location: Pasadena, California, USA
|
Posted: Fri Feb 14, 2003 12:30 pm Post subject: |
|
|
What you have there is an example of poor coding practice.
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 |
|
|
chandhroo Beginner
Joined: 02 Dec 2002 Posts: 36 Topics: 13
|
Posted: Fri Feb 14, 2003 1:02 pm Post subject: |
|
|
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 |
|
|
CaptBill Beginner
Joined: 02 Dec 2002 Posts: 100 Topics: 2 Location: Pasadena, California, USA
|
Posted: Fri Feb 14, 2003 3:04 pm Post subject: |
|
|
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 |
|
|
|
|