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

COMP to Char


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

PostPosted: Mon Jul 26, 2010 4:35 pm
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: 2146
Location: At my coffee table

PostPosted: Mon Jul 26, 2010 5:29 pm
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

Moderator Emeritus


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

PostPosted: Mon Jul 26, 2010 8:06 pm
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
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Jul 30, 2010 12:09 am
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
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Jul 30, 2010 4:38 am
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
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
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Aug 05, 2010 1:28 am
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Aug 05, 2010 4:39 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Exclude rows with > than x occurre... DFSORT/ICETOOL 6
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Converting ASCII values to COMP-3 (ZD... JCL & VSAM 2
No new posts Interviewers are surprised with my an... Mainframe Interview Questions 6
Search our Forums:

Back to Top