IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Contest for the experts


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
kingofmainframes
Warnings : 2

New User


Joined: 09 Apr 2006
Posts: 20
Location: Chennai

PostPosted: Tue Apr 11, 2006 9:22 pm
Reply with quote

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? icon_biggrin.gif
Back to top
View user's profile Send private message
martin9

Active User


Joined: 01 Mar 2006
Posts: 290
Location: Basel, Switzerland

PostPosted: Tue Apr 11, 2006 9:32 pm
Reply with quote

hy kingofmainframes,

TRUE

martin9
Back to top
View user's profile Send private message
stalin.i@gmail.com

New User


Joined: 18 Apr 2005
Posts: 8
Location: chennai

PostPosted: Tue Apr 11, 2006 9:42 pm
Reply with quote

Hi King,

TRUE icon_biggrin.gif
Back to top
View user's profile Send private message
kingofmainframes
Warnings : 2

New User


Joined: 09 Apr 2006
Posts: 20
Location: Chennai

PostPosted: Tue Apr 11, 2006 9:46 pm
Reply with quote

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
View user's profile Send private message
martin9

Active User


Joined: 01 Mar 2006
Posts: 290
Location: Basel, Switzerland

PostPosted: Tue Apr 11, 2006 10:37 pm
Reply with quote

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 icon_smile.gif
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Tue Apr 11, 2006 11:21 pm
Reply with quote

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
View user's profile Send private message
kingofmainframes
Warnings : 2

New User


Joined: 09 Apr 2006
Posts: 20
Location: Chennai

PostPosted: Wed Apr 12, 2006 11:14 pm
Reply with quote

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. icon_biggrin.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts REXX contest CLIST & REXX 2
No new posts Help Required from experts - Natural ... Java & MQSeries 2
This topic is locked: you cannot edit posts or make replies. CICS experts required in a Global IT ... Mainframe Jobs 0
This topic is locked: you cannot edit posts or make replies. PL/1 experts required in a Global IT ... Mainframe Jobs 0
No new posts Java , j2EE Openings for Bangalore it... Mainframe Jobs 0
Search our Forums:

Back to Top