View previous topic :: View next topic
|
Author |
Message |
sudhakarraju
New User
Joined: 05 May 2005 Posts: 31
|
|
|
|
How do we convert Binary data into text using a COBOL program. Do we have any utility programs than can also do this conversion on Mainframe.
I am attaching the Binary file (File to be converted) and the Text file (File after conversion). |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Many people here are not allowed to download attachments, not to mention that binary data may be changed by using a text attachment, so your post is pretty much useless. Please post the binary and text data again, using BBcode (the Code button) which can be reviewed by everyone.
Finally, when you say "binary" what do you mean? Is the data
- binary numbers?
- floating point numbers?
- packed decimal numbers?
- non-display characters?
- non-EBCDIC data?
All of these are possible interpretations of "binary" and have very different formatting requirements. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Suggest you post the attached data using BBCode - not everyone can download them, so chances of getting good help reduces. When you say binary, did you mean COBOL COMP fields? |
|
Back to top |
|
|
sudhakarraju
New User
Joined: 05 May 2005 Posts: 31
|
|
|
|
Please find the data below. I am also displaying the hex version of the data.
Code: |
Binary Data
L nL
D232239D
33319453
Text Data
<claim><
48988964
C33194EC |
|
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
When posting, use hex-notation for the entire value. Then, there's no question and everyone can read it.
EG: '%' is a X'6C' in EBCDIC, whereas it is X'25' in ASCII.
We're assuming you're dealing with EBCDIC....
Bill |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Do you need the Binary-Data converted to 16-Bytes?
X'D3233321293495D3'
converted to a 16-Byte value of -
C'D3233321293495D3'?
Bill |
|
Back to top |
|
|
sudhakarraju
New User
Joined: 05 May 2005 Posts: 31
|
|
|
|
I need X'D3233321293495D3' converted to X'4C83938189946E4C'. |
|
Back to top |
|
|
sudhakarraju
New User
Joined: 05 May 2005 Posts: 31
|
|
|
|
If the Binary data in a text file and I FTP the file on to mainframe as Binary, the data gets converted into a readable text format. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Give this a try (not tested) -
Code: |
03 WS-FROM-FIELD PIC X(008).
03 WS-TO-FIELD PIC X(008)
*
MOVE X'D3233321293495D3' TO WS-FROM-FIELD.
MOVE WS-FROM-FIELD TO WS-TO-FIELD.
*
INSPECT WS-TO-FIELD CONVERTING X'D3233321293495'
TO X'4C83938189946E'.
|
After the INSPECT, WS-TO-FIELD will equal X'4C83938189946E4C'.
Bill |
|
Back to top |
|
|
sudhakarraju
New User
Joined: 05 May 2005 Posts: 31
|
|
|
|
Bill,
Your code will only convert the first few bytes of the file. I have a much larger file to deal with and the whole file needs to converted from Binary to Text.
Raju |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Well then, you need to expound upon my posting as you posted 8-Bytes to be converted.
Bill |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
I suspect that each byte will need to be converted individually rather than the "whole field" in one statement . . . |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Dick (et al),
I thought about that, because then other standalone characters, not associated with the "FROM" value, would be converted errorneously.
Here's an alternative (RECORD AREA is merely an example) -
Code: |
03 WS-FROM-VALUE PIC X(008).
03 WS-TO-VALUE PIC X(008).
03 WS-RECORD-AREA PIC X(500).
*
MOVE X'D3233321293495D3' TO WS-FROM-VALUE.
MOVE X'4C83938189946E4C' TO WS-TO-VALUE.
*
INSPECT WS-RECORD-AREA REPLACING WS-FROM-VALUE
BY WS-TO-VALUE.
|
Bill |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
And maybe I've missed something here, but I haven't seen anything posted yet that indicates what the rules are for the translation process? |
|
Back to top |
|
|
|