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

COMP-4 usage


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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
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: 8697
Location: Dubuque, Iowa, USA

PostPosted: Tue Sep 28, 2010 4:26 pm
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
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: 8697
Location: Dubuque, Iowa, USA

PostPosted: Tue Sep 28, 2010 7:10 pm
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
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: 1353
Location: Israel

PostPosted: Wed Sep 29, 2010 2:19 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts STEM usage in REXX CLIST & REXX 14
No new posts Converting ASCII values to COMP-3 (ZD... JCL & VSAM 2
No new posts z/OS Modules Usage report using SMF 42 DFSORT/ICETOOL 2
No new posts Interviewers are surprised with my an... Mainframe Interview Questions 6
Search our Forums:

Back to Top