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 to Char

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

New User


Joined: 19 Jul 2010
Posts: 2
Location: Bangalore

PostPosted: Mon Jul 26, 2010 12:00 pm    Post subject: COMP to Char
Reply with quote

Explain the output.

WORKING-STORAGE SECTION.

01 HEX-91-VALUE PIC 9(4) COMP VALUE 145.
01 HEX-91X REDEFINES HEX-91-VALUE.
15 FILLER PIC X(1).
15 HEX-91 PIC X(1).

PROCEDURE DIVISION.

DISPLAY "HEX-91-VALUE " HEX-91-VALUE
DISPLAY "HEX-91 " HEX-91

Output we got:

HEX-91-VALUE 0145
HEX-91 j
[/Search]
Back to top
View user's profile Send private message

Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Mon Jul 26, 2010 12:20 pm    Post subject:
Reply with quote

Hi Mahesh,

Why dont you start with "What u understood so far ?"
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7907
Location: Bellevue, IA

PostPosted: Mon Jul 26, 2010 4:35 pm    Post subject:
Reply with quote

There is a link to manuals at the top of the page. Click on it, find the COBOL Programming Guide manual, and locate section 1.3.4.7 of this manual. You will find out how COMP variables are stored internally. Then go the COBOL Language Reference manual and read Appendix 3.1 on the EBCDIC collating sequence. This should allow you to explain the output yourself.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Mon Jul 26, 2010 5:29 pm    Post subject:
Reply with quote

koulmahesh wrote:
Explain the output.
What is to explain?
Decimal 145 is hex 91 is the EBCDIC lower case 'j'......
You call yourself an SSE with "COBOL/JCL/VSAM/DB2/REXX/ASSEMBLER" skills and you don't see this?
I'd suggest you look to the Support Forum for Mainframe Beginners and Students for further help.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Jul 26, 2010 8:06 pm    Post subject:
Reply with quote

Hello and welcome to the forum,

Quote:
Explain the output.
First a number was displayed (145). Then a character was displayed (j). . . Keep in mind that the character might not have been a displayable value and would have appeared to be a space. . .

Possibly you are asking for something else?
Back to top
View user's profile Send private message
koulmahesh

New User


Joined: 19 Jul 2010
Posts: 2
Location: Bangalore

PostPosted: Thu Jul 29, 2010 11:25 am    Post subject:
Reply with quote

Hey .. cool .. icon_smile.gif

Thanks friends..
Back to top
View user's profile Send private message
saurabh39
Warnings : 1

Active User


Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

PostPosted: Thu Jul 29, 2010 11:52 pm    Post subject: Reply to: COMP to Char
Reply with quote

One question though.......how will display different value when we are referring to same memory location?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7907
Location: Bellevue, IA

PostPosted: Fri Jul 30, 2010 12:09 am    Post subject:
Reply with quote

Tushar, the different values displayed depend upon how you look at the data. For example, if you have
Code:
05  DATA-X PIC X(03) VALUE 'pr('.
05  DATA-N REDEFINES DATA-X
           PIC S9(05) COMP-3.
you have defined the same 3 bytes of memory in two different ways. If you display DATA-X you will see 'pr(' on your output. If you display DATA-N you will see -97994 (technically, 9799M will be the displayed value). 3 bytes with very different values depending upon how you display them.
Back to top
View user's profile Send private message
saurabh39
Warnings : 1

Active User


Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

PostPosted: Fri Jul 30, 2010 12:58 am    Post subject: Reply to: COMP to Char
Reply with quote

@Robert - Thanks for Quick Clarification.

But One more Clarification required- I understand the hex value for p & r is 97,99 and for left parenthesis 4D, so the value will be 97994D, since D is negative it will be -97994. Till this point I am clear, But you said it will be displayed as 9799M, but M is D4, but we are storing as 4D which is (, so the value as per my understanding should be 9997(.

AM I Nissing something here?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jul 30, 2010 3:06 am    Post subject:
Reply with quote

zoned decimal definitons:

Code:

value of
last byte
======

DEC VAL
+0   {    
+1   A
+2   B
+3   C
+4   D
+5   E
+6   F
+7   G
+8   H
+9   I
-0   }
-1   J
-2   K
-3   L
-4   M
-5   N
-6   O
-7   P
-8   Q


M = -4
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7907
Location: Bellevue, IA

PostPosted: Fri Jul 30, 2010 4:38 am    Post subject:
Reply with quote

COBOL won't directly display a COMP-3 or COMP value. They are converted to USAGE DISPLAY as part of the DISPLAY statement. However, in doing so COBOL does not do anything with the sign, so X'97994D' is converted to 'F9F7F9F9D4' when displayed.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jul 30, 2010 5:11 am    Post subject:
Reply with quote

thx for the post Robert.
I thought about the effect of posting my little chart,
without explanatory comments;
it would just confuse the TS.
your comment has avoided that.
Back to top
View user's profile Send private message
saurabh39
Warnings : 1

Active User


Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

PostPosted: Fri Jul 30, 2010 12:51 pm    Post subject: Reply to: COMP to Char
Reply with quote

@Roberts - Thanks for the comment...Now I am clear about it.
Back to top
View user's profile Send private message
saurabh39
Warnings : 1

Active User


Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

PostPosted: Thu Aug 05, 2010 12:47 am    Post subject: Reply to: COMP to Char
Reply with quote

One more question..........1234 will be represented as 4D2...which is fine...but -1234 is represented as FB2E. I checked one of the old topic...and dick replied zero minus 4D2 will give FB2E...which indeed is correct......but i did not get why i need to subtract with zero...my understanding was negative number will be stored as two complement.....so why should it 4D2..be subtracted from zero instead of binary equivalent of 4D2 being subracted from its two complement.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7907
Location: Bellevue, IA

PostPosted: Thu Aug 05, 2010 1:28 am    Post subject:
Reply with quote

Dick gave a shortcut method. Technically, what you do is flip each bit of the value (zero becomes one, one becomes zero) so the zero becomes F, 4 (0100 in binary) becomes B (1011 in binary), D (1101 in binary) becomes 2 (0010 in binary) and 1 (0010) becomes D (1101). However, you then add 1 to the value so the D becomes E (1110) (again, for technical reasons beyond the scope of a post). Hence 04D2 becomes FB2E.
Back to top
View user's profile Send private message
saurabh39
Warnings : 1

Active User


Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

PostPosted: Thu Aug 05, 2010 11:29 am    Post subject: Reply to: COMP to Char
Reply with quote

Thanks again Robert. The mistake I was doing - I was trying to find out complement of 4D2, instead of 04D2 as a result I was not getting intended result.

Just to rephrase, you first found out one complement of a number and then added one, which is another way of finding two's complement.

But your quote -


Quote:
(again, for technical reasons beyond the scope of a post).


confused me, What information are you withholding icon_biggrin.gif and terming as beyond the scope.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7907
Location: Bellevue, IA

PostPosted: Thu Aug 05, 2010 4:39 pm    Post subject:
Reply with quote

Basically, the negative values should be ones' complement; however, since two's complement allows addition and subtraction to proceed without requiring looking at the signs of the numbers, IBM used it for their negatives. Also, one's complement allows for two representations of the value zero while two's complement does not -- which can cause problems as you can imagine. But you do have to remember to add that 1 after flipping all the bits.

I didn't intend to withhold information -- but we don't need to discuss AND gates to talk about how COBOL IF logic works. There's a lot of background to most of these questions that is noise (that is, adds to the length of the answer without increasing the clarity of the answer). Anytime you want more of the background, though, I'll provide as much as I can.
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 Comparing Decimal and CHAR columns rakesh17684 DB2 7 Thu Oct 20, 2016 2:33 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