View previous topic :: View next topic
|
Author |
Message |
seahawk789
New User
Joined: 22 Feb 2010 Posts: 56 Location: Cochin
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
What if you simply moved the 3-byte numeric to a 2-byte packed-decimal or binary field? |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
seahawk789
New User
Joined: 22 Feb 2010 Posts: 56 Location: Cochin
|
|
|
|
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 |
|
|
|