🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.cobol
Article #1

Re: C libraries/methods for dealing with Cobol's 'occurs depending on' record

#1
From: Scott McKellar
Date: Fri, 13 Oct 1995 14:10
90 lines
3919 bytes
In Article<45gihq$7ip@solutions.solon.com>, <norman@gencredits.com> write:
: In article <45e0i8$sn@solutions.solon.com>,
:    harttj@belmont.edu (Timothy J. Hart) wrote:
: >I am on a fact finding mission for my boss, and have no interest in 
: >pursuing any language wars.
: >
: >Our shop uses C exclusively, but we communicate with many IBM 
: >mainfraims & other systems where COBOL is a standard. I 
: >am investigating methods for dealing with COBOL's 'occurs depending 
: >on' record format.
: >
: >We have already considered using pointers & run-time allocation:
: >typedef struct
: >{
: >    unsigned long rec1Count,
: >                  rec2Count,
: >                  rec3Count;
: >    rec1Ptr       rec1;
: >    rec2Ptr       rec2;
: >    rec3Ptr       rec3;
: >}Record;
: >
: >foo()
: >{
: >     Record theRec;
: >
: >     //read record counts.
: >     theRec.rec1 = alloc( theRec.rec1Count* sizeof( rec1 ) );
: >     //etc...
: >
: >}
: 
: 	Why malloc() wouldn't calloc() be better? Just having fun..
: 
: >
: >Just wondering if anyone using C in the mainfraim world had a 
: >better/more elegant solution
: >
: >Tim
: 
: FORMAT:
: 	OCCURS integer-1 TO integer-2 TIMES DEPENDING ON data-name-1
: 
: The above format states that at run time there is a variable number of 
items 
: in this array. There will be at most/least integer-2 items available at 
run 
: time. For all pratical purposes you can view the array as a fixed array 
since 
: memory is allocated no matter what. So looking at the following example:
:
[ snip ] 
: 
: norman@gencredits.com	People generally fear what they dont understand.
: Norman E. Gottschalk III
: Manager of MIS
: General American Credits, Inc.

The first respondent was evidently thinking about how variable-arrays
are represented in memory.  And he's right: the space is allocated
statically for the maximum size, even if not all of it is used.

However, I suspect that you need to read files written from the COBOL
world.  In that case you should be aware that the record lengths really
can vary, depending on how the file format is defined.  

In the IBM mainframe world, a four-byte 'record descriptor word' is 
prepended to each logical record of a variable-length file.  The first 
two bytes represent the length of the physical record.  I think that 
the length so recorded includes the length of the record descriptor word
itself.  I don't know if it's big-endian or little-endian.  The next two
bytes are generally not useful.  There are further complications in the
way the records are blocked.  I will not try to explain it all because I
am not qualified to do so; I wish merely to alert you to the
possibilities.

Nevertheless, the maximum record length is not necessarily 32K; it is
defined in the DCB (D-something Control Block) which defines the file
format.  If you know the maximum from the DCB, your C program can 
allocate a buffer accordingly and know that everything will fit.

If you wrote your C for the IBM mainframe environment, the library
routines would handle this nastiness for you.  Otherwise, if you can't
find some kind of data-porting package, you'll probably have to roll
your own.  Good luck.

Scott McKellar
Southwestern Bell Telephone
St. Louis, MO
(314) 235-3595		jm407a@multi.sbc.com
Technical Details
Message-ID: <45ls0f$2c5@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <45e0i8$sn@solutions.solon.com> <45gihq$7ip@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: jm407a@multi.sbc.com (Scott McKellar)
Newsgroups: comp.lang.cobol,comp.lang.c.moderated,comp.lang.c
Subject: Re: C libraries/methods for dealing with Cobol's 'occurs depending on' record
Followup-To: comp.lang.cobol
Date: 13 Oct 1995 09:10:23 -0500
Organization: Digital Solutions
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <45ls0f$2c5@solutions.solon.com>
References: <45e0i8$sn@solutions.solon.com>  <45gihq$7ip@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com