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

Byte conversion Algorithm


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
seahawk789

New User


Joined: 22 Feb 2010
Posts: 56
Location: Cochin

PostPosted: Tue Dec 11, 2012 12:09 am
Reply with quote

Hi All,

I am need of developing a conversion algorithm that will convert a 3 byte numeric value to 2 byte alphanumeric/alphabetic/numeric value and viceversa. Any one of you had a similar requirement ?

For eg.

001 - 01
002 - 02
003 - 03
...
...
...
099 - 99
100 - A1
...
270 - AA

etc...

Something of this sort. Can you please help me out. Also Iam not suppossed to hard code these mapped values with the cobol module nor I can store these values in any lookup file.
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: Tue Dec 11, 2012 12:37 am
Reply with quote

You have not been nearly clear enough for anyone to help you. When you say " 2 byte alphanumeric/alphabetic/numeric value" do you mean a 2-byte displayable alphanumeric value? ANY 2-byte alphanumeric value? Something else you have not explained?

Since there are 1000 three-byte numbers (000 to 999), what mapping are you planning on using to go from them to " 2 byte alphanumeric/alphabetic/numeric value"s?

Who assigned this "requirement" anyway -- it sounds more like a homework assignment than an actual work requirement?
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: Tue Dec 11, 2012 12:37 am
Reply with quote

Hello,

What if you simply moved the 3-byte numeric to a 2-byte packed-decimal or binary field?
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Tue Dec 11, 2012 1:17 am
Reply with quote

I frankly can't think of any algorithm that will give 100 -> A1 and 270 -> AA. Nonetheless, I recommend that you adopt this Rexx fragment to COBOL:
Code:
base36 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
netctr   = substr(base36,netctr36%36+1,1) ||,
           substr(base36,netctr36//36+1,1)   
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Tue Dec 11, 2012 4:52 am
Reply with quote

Do you need the 3-Byte numeric value (assuming display-numeric) to be represented as a 2-Byte Packed-Unsigned (BCD) value?

For example: 500 (X'F5F0F0') converted to X'0500' or 999 (X'F9F9F9') converted to X'0999'?

A value of 1000 would require a 4-Byte display-numeric sending field.

Dick's suggestion of moving the 3-Byte value to a PL2 or XL2 (S9(03) COMP-3 or S9(04) COMP) seems to be the simplest method.

Please advise....
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Dec 11, 2012 6:00 am
Reply with quote

You want, in human-readable form, a two character "sequence number" which can represent zero to 999?

What is it that you can't "hard code"? You'll need some data defined for the mapping, unless you only want the solution by calculation (which is going to be more difficult).

I also don't understand the attempt you've made so far.

As Mr A. has suggested, if you go for 0-Z, just done in the way we do counting normally, you have a simple solution. Unless you come up with a really good reason to calculate it, rather than defining a table with those values in, I think you should have enough already.
Back to top
View user's profile Send private message
seahawk789

New User


Joined: 22 Feb 2010
Posts: 56
Location: Cochin

PostPosted: Tue Dec 11, 2012 7:09 pm
Reply with quote

Folks.. I got the answer.

For converting these 3 bytes to 2 bytes its enough that we convert it to a base 36 variable.

for eg.

the base 36 equalant of decimal 100 is 2S. like wise it can be extended upto 999.
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 Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
No new posts 10 byte RBA conversion DB2 2
No new posts 10 byte RBA conversion -non applicati... JCL & VSAM 1
No new posts file manager is doing string conversion IBM Tools 3
No new posts Dataset size increase on adding 1 byt... DFSORT/ICETOOL 8
Search our Forums:

Back to Top