Re: cobol and binary data written by C

From: Lew Pitcher (lpitcher_at_sympatico.ca)
Date: 05/10/04


Date: Sun, 09 May 2004 20:26:43 -0400


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

LX-i wrote:
| Joe Wright wrote:
|
|> hpy_awad@yahoo.com wrote:
|>
|>> can cobol read binary data written by fprintf (C function) ?
|>
|>
|> I'm not up on what COBOL can do but, fprintf() writes text data, not
|> binary data.
|
|
| COBOL can read and write both text and binary data - the key is, you've
| got to know the structure of the file. You can have variable-length
| records, so you could have one record with 10 characters, and another
| with 20K.
|
| I've never had experience interchanging data between the two languages,
| so I can't tell you the best way to do that, or any problems that may
| arise.

I /have/ had experience exchanging data between COBOL and C programs, both
through file transfer and by program call.

In general, COBOL 'records' are equivalent to C 'structures', and with
recognition of the rules each language uses to format data, a program written
in one language can read data written by the other. Some things to watch for...

1) COBOL strings are implicitly length delimited. C strings are explicitly
delimited by the \0 character. C programs must know the implicit length of the
string variable and use memcpy() to extract or populate string data.

2) COBOL recognizes a variety of fixed-point formats, including COMP-3 (IBM
'packed' BCD format). C does not recognize this variety of formats, especially
COMP-3. Some caution (and programming) will be required to pass fixed point
values between the two languages.

3) COBOL recognizes an implicit decimal point in it's fixed-point formats. C
does not recognize any decimal point in it's equivalent integer formats. Some
caution (and programming) will be required to pass fixed point values between
the two languages.

4) COBOL records have different padding rules than C structures. A common
padding pragma will have to be found between the two.

- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAnsxDagVFX4UWr64RAmv3AJ40gp1cOfBnMSB/ZS6I/Wg6NldlMwCeJMRd
z/84sqQmiO/hrYHdIjD1PDQ=
=pvR1
-----END PGP SIGNATURE-----



Relevant Pages

  • Re: cobol and binary data written by C
    ... |>> can cobol read binary data written by fprintf? ... |> I'm not up on what COBOL can do but, fprintfwrites text data, not ... COBOL recognizes a variety of fixed-point formats, ... values between the two languages. ...
    (comp.lang.cobol)
  • Re: cobol data format!!! urgent!!!
    ... which implies 559 is not an ISO standard. ... importation into COBOL programs on grounds of portability. ... formats are virtually useless *within* the COBOL program, ... that neither went their own way nor went with IEEE. ...
    (comp.lang.cobol)
  • Re: Packed Fields
    ... Pete, ... COBOL supports several different formats for numeric data, ... data stored in it is server integers "packed" by a Cobol program. ... * To join/leave the list, search archives, change list settings, * ...
    (comp.sys.hp.mpe)
  • Re: VB6 connecting to ISAM Dat files
    ... I've followed your links but I think they are for other types of COBOL db. ... COBOL for UNIX (several special formats) ... All except Siber claims to have ODBC drivers/adapters, ... Microsoft and other companies have used the first letters to id ...
    (microsoft.public.vb.general.discussion)
  • Re: Cobol convert program Job Request
    ... microfocus files. ... Microfocus Cobol can write several different formats of INDEXED ... put them some place if anyone wanted to write a test program to see if ...
    (comp.lang.cobol)