Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

COMP-4 usage

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Ambili S

Active User


Joined: 06 Sep 2007
Posts: 112
Location: India

PostPosted: Tue Sep 28, 2010 3:00 pm    Post subject: COMP-4 usage
Reply with quote

I have a declaration as shown below.

05 B PICTURE 99 USAGE DISPLAY VALUE 8.
05 C REDEFINES B PICTURE S99 USAGE COMPUTATIONAL-4.
05 A PICTURE S99 USAGE COMPUTATIONAL-4.


ADD C TO A .

The below explanation says the output is -48 , but couldn't make out how.

The value -48 is added to A (because C has USAGE COMPUTATIONAL-4)
because the bit configuration (truncated to 2 decimal digits) in the storage area has the binary value -48.

I couldn't understand how the output -48 was obtained.
Could somebody please explain.
Back to top
View user's profile Send private message

pawaria

New User


Joined: 06 Apr 2006
Posts: 7
Location: Noida

PostPosted: Tue Sep 28, 2010 3:26 pm    Post subject: Reply to: COMP-4 usage
Reply with quote

First initialized the COMP-4 variable and then see what results you get..
Back to top
View user's profile Send private message
Ambili S

Active User


Joined: 06 Sep 2007
Posts: 112
Location: India

PostPosted: Tue Sep 28, 2010 3:30 pm    Post subject:
Reply with quote

i don't have access to mainframe , i came across this in a manual. Could not understand how the output was -48 , hence posted it in forum.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8057
Location: East Dubuque, Illinois, USA

PostPosted: Tue Sep 28, 2010 4:26 pm    Post subject:
Reply with quote

The internal representation of B is x'F0F8'. When this is redefined as a binary (COMP-4) variable, the value is -3848. Note: although you did not specify, TRUNC(BIN) is not the compiler option or the results would be different. Since TRUNC(BIN) is not specified, the value of C is truncated to match the picture size, so -3848 becomes -48.
Back to top
View user's profile Send private message
Ambili S

Active User


Joined: 06 Sep 2007
Posts: 112
Location: India

PostPosted: Tue Sep 28, 2010 5:50 pm    Post subject:
Reply with quote

Hi Robert , the bit configuration for B , which has value '8' would be
1111 0000 1111 1000 (F0F8) but in comp-4 how is it -3848 ?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8057
Location: East Dubuque, Illinois, USA

PostPosted: Tue Sep 28, 2010 7:10 pm    Post subject:
Reply with quote

Binary numbers are stored as two's complement values so the first bit indicates the sign (0 is positive, 1 is negative) while the rest are the value. 1111 0000 1111 1000 is converted to a decimal value by flipping each bit (giving 0000 1111 0000 0111) and adding 1 (giving 0000 1111 0000 1000). This is 15 times 256 or 3,840 plus 8, which is 3848 -- and since the first bit was a 1, the value is -3848.
Back to top
View user's profile Send private message
Ambili S

Active User


Joined: 06 Sep 2007
Posts: 112
Location: India

PostPosted: Wed Sep 29, 2010 11:14 am    Post subject:
Reply with quote

Thanks Robert , that was really helpful.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1228
Location: Israel

PostPosted: Wed Sep 29, 2010 2:19 pm    Post subject: Reply to: COMP-4 usage
Reply with quote

You can also check by yourself by using the windows calculator (CALC.EXE)

1. Set Calc in Scientific mode
2. Set display in Dec mode (radiobutton or F6)
3. Enter 3848 then "+/-" to make it -3848
4. Set display in Hex mode (radiobutton or F5)
5. Set format to Word (radiobutton or F3)
You will then see F0F8

To make the calculation, you can use the following method:
1. Set Calc in Scientific mode
2. Set display in Hex mode (radiobutton or F5)
3. Set format to Dword (radiobutton or F2)
4. Calculate 10000 - F0F8 =. Result shows F08
5. Set display in Dec mode (radiobutton or F6)
You will then see 3848. It doesn't show, but you know that it's a negative number.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Need inputs on Space requirement and... ashek15 IMS DB/DC 0 Sat Apr 01, 2017 8:26 am
No new posts Protection Exception while move 0 to ... Kevin Vaz CICS 10 Tue Oct 18, 2016 4:19 pm
No new posts How can we create a flat file in JAVA... rakesh.v18 Java & MQSeries 7 Fri Sep 23, 2016 10:46 pm
No new posts Need help to populate date in COMP-3 ... chetanambi DFSORT/ICETOOL 3 Tue Jun 21, 2016 12:25 pm
No new posts comparing comp-3 and unpacked numbers juares castro COBOL Programming 3 Mon May 30, 2016 6:46 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us