Format of an ASCII file and comp-3 format 
Author Message
 Format of an ASCII file and comp-3 format

I am trying to read in a database written by a COBOL program with a
C program.  The difficulty I am having is that the file that is written
seems to be gibberish.  This makes me wonder if COBOL is writing some
formatting information that is messing up the ASCII characters.  Are
there any leading bits I need to strip off?  Which ones?  If
there are any docs on this on the net I would really appreciate it.

I also need to know how to read in data written in comp-3 format.
What is the algorithm for that?

I'm sorry if these are basic questions...I'm a C programmer
not a COBOL one and I'm sure it shows.

Thanks for any help!

-Evan Reynolds




Sun, 09 May 1999 03:00:00 GMT  
 Format of an ASCII file and comp-3 format

Quote:

>I am trying to read in a database written by a COBOL program with a
>C program.  The difficulty I am having is that the file that is written
>seems to be gibberish.  This makes me wonder if COBOL is writing some
>formatting information that is messing up the ASCII characters.  Are
>there any leading bits I need to strip off?  Which ones?  If
>there are any docs on this on the net I would really appreciate it.
>I also need to know how to read in data written in comp-3 format.
>What is the algorithm for that?
>I'm sorry if these are basic questions...I'm a C programmer
>not a COBOL one and I'm sure it shows.
>Thanks for any help!
>-Evan Reynolds


"comp-3" data is a signed or unsigned fixed-point decimal format whose
exact encoding depends upon (1) the hardware platform, (2) the
compiler.  you need to provide more information before someone
knowledgeable can answer your question.  there is no coresponding
standard C data type, so you will need to use a conversion routine.


Sun, 09 May 1999 03:00:00 GMT  
 Format of an ASCII file and comp-3 format

  (snip)
: I also need to know how to read in data written in comp-3 format.
: What is the algorithm for that?
  (snip)
 ---------------------------------

 Comp-3 contains two digits per byte, except for the rightmost byte,
which contains 1 digit and a sign (each digit is made up of 4 binary
bits).

 For instance, if you defined an item as   pic S9(5) comp-3, then
the definition would be:

     99999S   (9's are digit positions and S is the sign).

 If you did not specify a sign in the picture, the sign value would
always be positive.

 If the definition is  pic 9(6) comp-3, then the def. is:

     9999999S  (notice that the number of 9's is always odd, in this
                case, one more than in the pic)

 One caution: If the data was created by a program compiled by a
              different compiler, make sure that the same sign values
              are created/recognized by both programs.



Sun, 09 May 1999 03:00:00 GMT  
 Format of an ASCII file and comp-3 format

Quote:

>Date: 20 Nov 1996 19:20:13 GMT

>I am trying to read in a database written by a COBOL program with a
>C program.  The difficulty I am having is that the file that is written
>seems to be gibberish.  This makes me wonder if COBOL is writing some
>formatting information that is messing up the ASCII characters.  Are
>there any leading bits I need to strip off?  Which ones?  If
>there are any docs on this on the net I would really appreciate it.

>I also need to know how to read in data written in comp-3 format.
>What is the algorithm for that?

>I'm sorry if these are basic questions...I'm a C programmer
>not a COBOL one and I'm sure it shows.

>Thanks for any help!

>-Evan Reynolds

Evan,
Comp-3 or packed decimal isn't Ascii to begin with - it's BCD with a sign
field that occupies the rightmost nibble of the first byte.  Packed
decimal fields will usually occupy an integer number of btyes and will be
signed. Each byte can be broken into two nibbles of 4 bits each.  A nibble
represents either a digit from 0-9 or a sign flag, C is positive, D is
negative and F is assumed positive.  PD fields contain no decimals, they
are implied and not actual.  If I had to tackle this problem  I would
treat the PD field as an array of chars and union the char with a byte
that used 2 bit field operators that addressed 4 bits each and take the
appropriate action based on whether the nibble contained a number or a
flag.

InstrJCC



Mon, 10 May 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. ASCII to COMP-3 format

2. Converting quickbasic2 .dat file to ascii format

3. HELP.....ASCII file format > Clarion4

4. Formatting ASCII text files

5. Problems with ASCII format text files

6. ASCII format text files

7. ASCII File format

8. UNIX format ASCII file

9. problem with reading ascii/formatted file

10. Q. How to mix ascii and binary format data in one file with FORTRAN

11. Problem with ASCII form of the PPM graphic file format in tcl

12. ASCII Import & Date Formats

 

 
Powered by phpBB® Forum Software