View previous topic :: View next topic
|
Author |
Message |
kingofmainframes Warnings : 2 New User
Joined: 09 Apr 2006 Posts: 20 Location: Chennai
|
|
|
|
I have declared two variables like this.
77 A PIC 9(4).
77 B PIC X(6).
I am moving the following values.
MOVE 9999 TO A.
MOVE 9999 TO B.
IF A = B
DISPLAY 'TRUE'
ELSE
DISPLAY 'FALSE'
END-IF
What will be displayed after executing the IF-LOOP? |
|
Back to top |
|
|
martin9
Active User
Joined: 01 Mar 2006 Posts: 290 Location: Basel, Switzerland
|
|
|
|
hy kingofmainframes,
TRUE
martin9 |
|
Back to top |
|
|
stalin.i@gmail.com
New User
Joined: 18 Apr 2005 Posts: 8 Location: chennai
|
|
|
|
Hi King,
TRUE |
|
Back to top |
|
|
kingofmainframes Warnings : 2 New User
Joined: 09 Apr 2006 Posts: 20 Location: Chennai
|
|
|
|
Hello Martin , Stalin
Do you notice field B is defined with X(6) so it will effectively contain two blanks at end. whereas A will contain only "9999" ?
A = "9999"
B = "9999 " |
|
Back to top |
|
|
martin9
Active User
Joined: 01 Mar 2006 Posts: 290 Location: Basel, Switzerland
|
|
|
|
hy kingofmainframes,
hex value is x'F9F9F9F9' for A
and x'F9F9F9F94040' for B.
therefore A is only 4 bytes,
testing will end after fourth byte.
but why do you test this not yourself?
with a simple program you can test all
field comparisons very easily....
martin9 |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
kingofmainframes,
To be correct. With cobol option OPTIMIZE(STD), the generated code is:
MOVE 9999 TO A.
MOVE 9999 TO B.
DISPLAY 'TRUE'
The compiler doesn't generate the "IF" test. The only possable condition is "TRUE" so thats what it generates.
martin9,
If your post is correct then.
Quote: |
77 A PIC 9(4).
77 B PIC X(6).
I am moving the following values.
MOVE 9999 TO A.
MOVE 99999 TO B.
IF A = B
DISPLAY 'TRUE'
ELSE
DISPLAY 'FALSE'
END-IF |
would test "TRUE" , but it tests "FALSE" |
|
Back to top |
|
|
kingofmainframes Warnings : 2 New User
Joined: 09 Apr 2006 Posts: 20 Location: Chennai
|
|
|
|
Martin,
Thanks for your response. will get back to you soon.
DavidatK,
I got your point. Still why would the compiler option OPTIMIZE(STD) generate such a code?.
MOVE 9999 TO A.
MOVE 9999 TO B.
DISPLAY 'TRUE'
ok. In case if I code the program as follows, what will be the outcome of the test.
I have declared two variables like this.
77 A PIC 9(4).
77 B PIC X(6).
01 FILE01-REC
02 C PIC 9(4) COMP-3.
02 D PIC 9(6) COMP-3.
I am moving the following values.
READ FILE01 INTO FILE01-REC.
MOVE C TO A.
MOVE D TO B.
IF A = B
DISPLAY 'TRUE'
ELSE
DISPLAY 'FALSE'
END-IF
Assume C and D has 9999 as value. |
|
Back to top |
|
|
|