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
 

 

Binary conversion to Decimal - Number of bytes required.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL & VSAM
View previous topic :: :: View next topic  
Author Message
mushreyas

New User


Joined: 18 Jul 2008
Posts: 59
Location: Bangalore

PostPosted: Wed Sep 21, 2011 8:55 pm    Post subject: Binary conversion to Decimal - Number of bytes required.
Reply with quote

Hi,

I have a question regarding the number of bytes required when we convert a signed binary data into Zoned Decimal format.

1> S9(4) USAGE COMP occupies 2 bytes but when converted to Decimal format will it occupy 4 bytes or 5 bytes.
2> S9(9) USAGE COMP occupies 4 bytes but when converted to Decimal format will it occupy 9 bytes or 10 bytes.
3> S9(18) USAGE COMP occupies 8 bytes but when converted to Decimal format will it occupy 18 byes or 19 bytes.
Back to top
View user's profile Send private message

Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1712
Location: UK

PostPosted: Wed Sep 21, 2011 8:57 pm    Post subject:
Reply with quote

What are we talking about here? COBOL? JCL? SYNCSORT? plain old binary to decimal conversion? or what?

Now I see that this has been moved to another section of the forum but we still need to know the context.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Sep 21, 2011 9:12 pm    Post subject:
Reply with quote

why don't you look here and see if you get an idea.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Wed Sep 21, 2011 9:15 pm    Post subject:
Reply with quote

Your question cannot be answered completely accurately unless you specify what you are using for compiler option TRUNC. In general, you will not go wrong by using 5 bytes for a zoned decimal conversion of the 2-byte binary (COMP) value and 10 bytes for a zoned decimal conversion of the 4-byte binary (COMP) value.

There is a link to Manuals at the top of this page. Click on it, find the COBOL Application Programing Guide, and read up on the TRUNC compiler option. Once you've done so, hopefully you can answer the PIC S9(18) COMP question yourself.
Back to top
View user's profile Send private message
mushreyas

New User


Joined: 18 Jul 2008
Posts: 59
Location: Bangalore

PostPosted: Wed Sep 21, 2011 9:38 pm    Post subject: Reply to: Binary conversion to Decimal - Number of bytes req
Reply with quote

My requirement is to convert these signed binary data to decimal format using SYNCSORT.
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: Wed Sep 21, 2011 9:43 pm    Post subject:
Reply with quote

Hello,

OK, so follow Robert's guidance and use the appropriate lengths.

The lengths of the converted fields is not "language" dependent. . . So the target length in a COBOL program would be the same as the Zoned Decimal length specified in the sort control.
Back to top
View user's profile Send private message
mushreyas

New User


Joined: 18 Jul 2008
Posts: 59
Location: Bangalore

PostPosted: Thu Sep 22, 2011 9:30 pm    Post subject: Reply to: Binary conversion to Decimal - Number of bytes req
Reply with quote

I tried what Robert suggested but the last byte of the data was coming wrong. Below is the example

Input Data : 1 (Binary)

Sort Card

Code:
SORT FIELDS=COPY
 INREC =(1,2,BI,ZD,LENGTH=5)

Output was 0000A instead of 00001.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Thu Sep 22, 2011 9:37 pm    Post subject: Reply to: Binary conversion to Decimal - Number of bytes req
Reply with quote

Your input is signed. Your output (zoned decimal) is signed. Your output in hex looks like this

Code:
F0F0F0F0C1


Which is +ve one.
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: Thu Sep 22, 2011 10:53 pm    Post subject:
Reply with quote

Hello,

Quote:
but the last byte of the data was coming wrong.
The last byte is what the sort was told to do.

To get rid of the sign, use ZDF. From the manual:
Quote:
ZDF produces the same numerical value as ZD, but uses an F for a positive sign and D for the sign of a negative value.
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Fri Sep 23, 2011 4:00 pm    Post subject: Re: Reply to: Binary conversion to Decimal - Number of bytes
Reply with quote

mushreyas wrote:
Code:
SORT FIELDS=COPY
 INREC =(1,2,BI,ZD,LENGTH=5)
Output was 0000A instead of 00001.
It's the correct output. Do you want the output in "readable" format to some MBA-graduate. For a(n) zOS Aplication Developer, that's already readable, as Bill explains. Follow what Dick has suggested, "it'll be +1":

Code:
A
C
1
vs
Code:
1
F
1
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Fri Sep 23, 2011 6:42 pm    Post subject: Reply to: Binary conversion to Decimal - Number of bytes req
Reply with quote

Quote:
My requirement is to convert these signed binary data to decimal format using SYNCSORT.


the tale of the traveling topic icon_biggrin.gif
moved where it belongs
Back to top
View user's profile Send private message
mushreyas

New User


Joined: 18 Jul 2008
Posts: 59
Location: Bangalore

PostPosted: Sun Sep 25, 2011 10:07 am    Post subject: Reply to: Binary conversion to Decimal - Number of bytes req
Reply with quote

Thank you all for your help. I will try the solution recommended by Dick. However i have tried the below sort card and it worked.

Code:
SORT FIELDS=COPY
INREC =(1,2,BI,EDIT(TTTTT),LENGTH=5)
       
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Sun Sep 25, 2011 1:57 pm    Post subject:
Reply with quote

Shre,

Remember that you originally showed us Cobol-style signed-binary fields. Since you took the trouble to show us signed fields. we have assumed your fields can contain negative values.

Therefore, your solution should allow for a differentiation between positive and negative numbers.

Dick showed you how to do that without the positive numbers seeming to contain a letter of the alphabet in the right-most positiion, with an amendment to the particular sort card that your provided to us.

If your fields can contain negative values, so should your test data. You should be able to identify from the results, those that are negative and those that are positive.

There are a number of solutions to your requirement. Have a look at your Sort manual and see what other datatypes you can use with BI.

Lastly, is the above really your working sort card? "INREC =(" looks wrong. Did you re-type, introducing a typo, rather than use copy-paste?
Back to top
View user's profile Send private message
mushreyas

New User


Joined: 18 Jul 2008
Posts: 59
Location: Bangalore

PostPosted: Sun Sep 25, 2011 5:23 pm    Post subject: Reply to: Binary conversion to Decimal - Number of bytes req
Reply with quote

Hi Bill,

Its actually a typo error. It should be "INREC FIELDS=".
Thanks for your clear information.
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 -> JCL & VSAM All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts Conversion of a VB file to FB. isssal DFSORT/ICETOOL 1 Mon Oct 31, 2016 10:23 pm
No new posts Comparing Decimal and CHAR columns rakesh17684 DB2 7 Thu Oct 20, 2016 2:33 am
No new posts EBCDIC to ASCII conversion using OCOPY mistah kurtz All Other Mainframe Topics 5 Tue Sep 06, 2016 2:26 pm
No new posts Sequence number add in SORT pshongal SYNCSORT 3 Fri Sep 02, 2016 3:32 pm


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