COBOL

COBOL

COBOL

COBOL is responsible for the efficient, reliable, secure, and unseen day-to-day operations of the world's economy.

 View Only
  • 1.  variable length reads of a byte-stream

    Posted Thu October 27, 2016 05:23 PM

    Is it possible in Enterprise COBOL to read a z/OS UNIX byte-stream file (just a regular UNIX file, really) in chunks of varying lengths?  By this I mean I want to read, for example, the first 10 bytes, and then based on the value of those 10 bytes I may want to read a different number of bytes.

    I tried by declaring the FD with RECORDING MODE U and RECORD IS VARYING DEPENDING ON x.  But it doesn't matter what I set 'x' to (or if I set it at all), it always reads the maximum size (the size of the largest 01 level record under the FD) and returns that length in 'x'.

    Thanks, Frank.

    fswarbrick


  • 2.  Re: variable length reads of a byte-stream

    Posted Fri October 28, 2016 12:27 PM

    No. For a READ, x will be populated by the amount of data, as you have discovered. Prior value of x is irrelevant for READ, new value set on each successful completion.

    For WRITE, the value in x will be used to control the amount of data written. x will remain unchanged during that process.

    How do you establish which lengths you want for any given READ? If this is for a task rather than just interest, you're going to have to read great big chunks and then process the chunks for the lengths you need.

    I'd do it with a couple of ODOs but probably 99.99% would go for reference-modification :-)

     

     

    BillWoodger


  • 3.  Re: variable length reads of a byte-stream

    Posted Fri October 28, 2016 12:33 PM

    We already do it "the hard way".  I just thought it could be simplified if I could read in only the amount it took me to determine the length of the next chunk to read.  Certainly you can do this in other languages like C that are more naturally byte-stream oriented.  I guess it was too much to hope for that I could do it in COBOL.

    fswarbrick


  • 4.  Re: variable length reads of a byte-stream

    Posted Fri October 28, 2016 12:36 PM

    What's hard about the hard way?

    There is a penalty if you only want 10 bytes and you get 500,000.

    Other languages may do it, but they don't conform to the 1985 COBOL Standard :-)

    You could call a C function from our COBOL program.

    BillWoodger