• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ASCII TO EBCDIC conversion preserving COMP-3

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I need to convert an ASCII file to an EBCDIC file (mainframe compatible). The conversion is possible. But I want to maintain the packed decimal requirement also. The mainframe file has COMP-3 fields. i.e computational. Comp-3 fields (packed decimal) are compressed while converting from ASCII to EBCDIC. I tried using oracle �convert�,unix �iconv� and �dd� I don�t know whether they support Comp-3 format or not. Give a solution to convert such that packed decimals are not disturbed in Java.

For example -- '1234' is x'F1F2F3F4' as a string, of length four bytes. The packed decimal representation is x'0123C4', only three bytes long; net saving 1 byte of memory and disk storage.

Thanks,
S.R.K.Vivek Raju
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I posted code to do EBCDIC to ASCII in another thread.
https://coderanch.com/t/411222/java/java/Packed-decimal-conversion-Java

What ASCII data would you convert to packed decimal? Do you have a record layout defining the fields byte-by-byte as character or packed that could be used to convert ASCII to EBCDIC?
For example if bytes 3-8 are numberic (ie hold only numeric digits) then it would be an easy exercise to convert those 6 bytes to a packed decimal field.
If the field is signed, where/what would the sign be? A leading + or -?
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In continuation to the Vivek's post...And answer to the quetion-In ASCII file with some amount and score fields is to be converted into EBCDIC such that the signed amount fields and score fields are packed. I tried using "dd" command in unix. The file was converted from ASCII to EBCDIC on a byte-by-byte basis. The amount files in my ASCII file are assorted i.e they are not in sequence. Do i need to split the file and process the non COMP-3 fields using the normal ASCII to EBCDIC conversion method. In that case what about the conversion of COMP-3 fields(amount and score fields in ASCII file)?? Can anybody provide a solution at the earliest???
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you can layout the fields in an ASCII record, I have some methods that will convert them to different formats in EBCDIC. I'll need definitions what a COMP-3 field looks like in hex. For example a 3 byte packed decimal field looks like: dd dd ds - where d is a decimal digit and s is the sign
 
Stream Candy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have some values that might be stored in a flat file as ASCII or stored in a DB as number. They are utlimately numbers. For Example

INPUT FORMAT:
RefLevelField NamePictureTypeStartEndLength
292XYZ-SCORES999ZD1571604

INPUT VALUE:-044

This is to be comverted into the following packed decimal format

OUTPUT FORMAT:
RefLevelField NamePictureTypeStartEndLength
112XYZ-SCORES999PD1571582

EXPECTED OUTPUT:�(

Please see if you can provide some inputs. Thanks
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Stream Candy", please check your private messages regarding an administrative matter.
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Steam Candy: I don't understand any of what you have entered. It looks like COBOL or some other language.
I need what the data looks like in hexadecimal on the input side and on the output side to be able to convert it.
For example if the input (ASCII) is character data such as "1234" (4 bytes of Unicode characters) and the output is to be packed decimal, it would be 0x01234F (shown as 3 bytes in hex).

Here's code to convert a String to packed decimal:

[ July 30, 2008: Message edited by: Norm Radder ]
 
Stream Candy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Norm. The code posted by you converts the ASCII to packed decimals in HEX format. We are looking for a code which would convert ASCII to packed decimal in EBCDIC format.

For instance if we have ASCII
-144 the output should be i(
[ July 31, 2008: Message edited by: Stream Candy ]
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Everything on a computer is held in bytes.
Can you explain what "packed decimal in EBCDIC format" looks like?

For instance if we have ASCII
-144 the output should be i(



What does the above mean? Was data lost in the posting?
[ July 31, 2008: Message edited by: Norm Radder ]
 
Stream Candy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nothing was lost.

ASCII packed decimal in EBCDIC
-144 i(

By packed decimal in EBCDIC format i mean that the output file consists of compressed fields but not in HEX. Everything is more or less in symbolic form(like @!^( etc...).In the above tabular representation alphabet "i" and the opening bracket "(" are clubbed together to depict the input -144.
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Everything is stored in a computer in bytes. There are many ways to describe what those bytes represent. You can display the contents of each byte in binary, in hex or in integer(range of 0 to 255). For some character sets such as ASCII you can also display the contents of some bytes as an ASCII character.
The same is true for EBCDIC, some bytes can be displayed as characters.

Now the value -144:
when stored as EBCDIC characters it is 4EF1F4F4 in hex. (4 bytes)
When stored as ASCII characters it is 2D313434 in hex. (4 bytes)
If it is converted to packed decimal format it is 144D in hex. (2 bytes).

alphabet "i" and the opening bracket "(" are clubbed together to depict the input -144.



I suspect that this clubbed together value you show is the character representation of a hex value. I bet that not all numeric values will be something that you can display. ie the hex won't map to a displayable character.
The reason you had to edit your previous post was because there was a hidden hex value in what you had originally posted and the format program for this site took that char to mean move to a new line.
[ July 31, 2008: Message edited by: Norm Radder ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic