View previous topic :: View next topic
|
Author |
Message |
abin
Active User
Joined: 14 Aug 2006 Posts: 198
|
|
|
|
Hi,
Can any body please explain the following.
Below is definition
Code: |
01 WS-B.
05 WS-B1 PIC 9(002) VALUE ZEROES.
05 WS-B2 PIC 9(006) VALUE ZEROES. |
I have a check as follows.
This check comes to true.
But when I give
it comes as false. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
WS-B in hex is 'F0F0F0F0F0F0F0F0'
when you compare it to 0, that would be a literal 'F040404040404040'
when you compare it to zeroes, that would be a literal 'F0F0F0F0F0F0F0F0'
(you can always look at the object listing generated at compile time to see what is actually being compared.
The compares work at advertised (by ibm). |
|
Back to top |
|
|
abin
Active User
Joined: 14 Aug 2006 Posts: 198
|
|
|
|
Hi Dick,
But then what about following combination.
Code: |
01 WS-B PIC 9(008) VALUE ZEROES.
IF WS-B > 0 |
Here if is turning FALSE. Problem comes when the variable is a group variable. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
abin wrote: |
Hi Dick,
But then what about following combination.
Code: |
01 WS-B PIC 9(008) VALUE ZEROES.
IF WS-B > 0 |
Here if is turning FALSE. Problem comes when the variable is a group variable. |
A group variable is always considered as being ALPHANUMERIC! |
|
Back to top |
|
|
abin
Active User
Joined: 14 Aug 2006 Posts: 198
|
|
|
|
Gotcha
Quote: |
A structure variable is treated as an alphanumeric variable. It has an implied PICTURE of X(nn), where nn is equal to the length of the structure variable |
I am trying to compare the group variable with numeric constant zero.
But again the group variable contains zeroes. It is a comparison of zeroes against zeroes right?. Then I should get FALSE in
Code: |
01 WS-B.
05 WS-B1 PIC 9(002) VALUE ZEROES.
05 WS-B2 PIC 9(006) VALUE ZEROES.
IF WS-B > 0 |
|
|
Back to top |
|
|
Douglas Wilder
Active User
Joined: 28 Nov 2006 Posts: 305 Location: Deerfield IL
|
|
|
|
A group variable is always considered as being ALPHANUMERIC.
Back to the first reply:
If WS-B in hex is 'F0F0F0F0F0F0F0F0'
When you compare it to 0, that would be a literal 'F040404040404040'
IF 'F0F0F0F0F0F0F0F0' > 'F040404040404040' = TRUE
When you compare it to zeroes, that would be a literal 'F0F0F0F0F0F0F0F0'
IF 'F0F0F0F0F0F0F0F0' > 'F0F0F0F0F0F0F0F0' = False they are equal.
If you want a numeric compare do not use a group item. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
The following WS-B is NOT an A/N var. Any var w/a PIC is an elementary
item.
Craq Giegerich wrote: |
abin wrote: |
Hi Dick,
But then what about following combination.
Code: |
01 WS-B PIC 9(008) VALUE ZEROES.
IF WS-B > 0 |
Here if is turning FALSE. Problem comes when the variable is a group variable. |
A group variable is always considered as being ALPHANUMERIC! |
|
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
mmwife wrote: |
The following WS-B is NOT an A/N var. Any var w/a PIC is an elementary
item.
Here if is turning FALSE. Problem comes when the variable is a group variable. |
A group variable is always considered as being ALPHANUMERIC!
And ws-b = 0 so it is not > 0. |
|
Back to top |
|
|
abin
Active User
Joined: 14 Aug 2006 Posts: 198
|
|
|
|
Thanks guys...... you all made the puzzle clear for me. |
|
Back to top |
|
|
roopannamdhari Warnings : 1 New User
Joined: 14 Sep 2006 Posts: 71 Location: Bangalore
|
|
|
|
Hi,
how can we say that the variable ws-b internally stored in hex formate.
Thanks |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
Hex is not a format - it s numbering system - base 16.
A format is something like packed decimal: dd dd dd ds, where d=digit (0-9), and s=sign (F or C or D). |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Craig,
My point was that:
01 WS-B PIC 9(008) VALUE ZEROES.
is not a Group Variable. In spite of the fact that it is an 01 level, it's an elementary variable because it contains a PIC clause.
The fact that it tested false has nothing to do with WS-B being a group item; it's a numeric elementary item and it tested false because it contained numeric zeros which are NOT greater than a numeric 0. |
|
Back to top |
|
|
Max Payne
New User
Joined: 13 Dec 2007 Posts: 10 Location: Shanghai
|
|
|
|
Very easy.
in your program, WS-B is 6 bytes, Alphanumeric type.
If it is compared with 0, in fact, it is
WS-B > "0bbbbb" (X'F04040404040')
If it is compared with zero, it is WS-B > "000000" (X'F0F0F0F0F0F0'.) |
|
Back to top |
|
|
|