Page 1 of 2

Dynamically allocating fields in Working Storage or in FD

PostPosted: Tue Jan 31, 2012 6:57 pm
by sriram1695
Hi All,

I'm trying to write a COBOL program which takes a file that contains Record Description/Layout, as one of its input and writes the data to the output file according to the layout specified in the input file.

I do not want to use the COPY statement to get the Record Description into my program because the input file is going to have different record description according to the user.
So my program is going to be generic, getting the layout and data to be written from the user.

Is there a way how I can dynamically read the input file and add those entries to the working storage or to the FD entry.

The program works fine with the use of COPY statement. But everytime the layout changes I'll have to recompile the source code.

I'm relatively new to COBOL and any help or suggestions would be appreciated.

Thank You,
Sriram

Re: Dynamically allocating fields in Working Storage or in F

PostPosted: Tue Jan 31, 2012 8:54 pm
by BillyBoyo
So, you want to take a Cobol record layout as data into your program.

You want to read a file which has that particular record on it.

You want to produce output in the format of the record layout.

You don't know Cobol.

Is that about it?

Do you have FileAid or FIleManager at your site? If yes, take a sticky label, write "my programme" on it, stick it over the appropriate option on the screen and then "demo" your program.

If you do not have anything which does this already, your management is going to be upset that they have poured so much money into providing a cheap replacement, and then given the work to someone who has not the experience to do it.

Getting the files "dynamically" from "the user" is not really the problem. The problem is the need for your program to do everything the compiler does for the Data Division. That is not a trivial task.

Re: Dynamically allocating fields in Working Storage or in F

PostPosted: Tue Jan 31, 2012 9:03 pm
by Akatsukami
sriram1695 wrote:I do not want to use the COPY statement to get the Record Description into my program because the input file is going to have different record description according to the user.

Nu? Have you though about the amount of effort needed to recreate a large chunk of the compiler-- as Mr. Boyo indicates, not a trivial task for an experienced developer, let alone a rank newbie -- versus writing, say, a dozen copybooks and passing a parameter indicates which is to be used?
The program works fine with the use of COPY statement. But everytime the layout changes I'll have to recompile the source code.

This. my child, has been true for the past half-century.

Re: Dynamically allocating fields in Working Storage or in F

PostPosted: Tue Jan 31, 2012 9:29 pm
by sriram1695
Hey Billy,

Thanx for the reply.. The data/record that I'm gonna read is a comma delimited file. So what I'm trying to do is, read the comma delimited file, unstring the fields and write them into a new file in the layout that's specified in the input file. But like I said the layout is not gonna be the same.. Could you suggest some ways of doing this?

If you do not have anything which does this already, your management is going to be upset that they have poured so much money into providing a cheap replacement, and then given the work to someone who has not the experience to do it.


And my company doesn't pay me for doing this :)
I'm doing this out of my interest to learn COBOL.

Thanks,
Sriram.

Re: Dynamically allocating fields in Working Storage or in F

PostPosted: Tue Jan 31, 2012 9:32 pm
by enrico-sorichetti
in what format are You going to provide the layout ?

Re: Dynamically allocating fields in Working Storage or in F

PostPosted: Tue Jan 31, 2012 9:38 pm
by sriram1695
enrico-sorichetti wrote:in what format are You going to provide the layout ?


The layout is going to be in a seperate file. Its going to be a standard COBOL record description format. Like one below.

01 SAMPLE-REC.
     02 FIELD-1   PIC XXX.
     02 FIELD-2   PIC X(3).
     02 FILLER   PIC X(10).

Re: Dynamically allocating fields in Working Storage or in F

PostPosted: Tue Jan 31, 2012 9:42 pm
by enrico-sorichetti
what experience do You have in writing scanners and parser ( compiler construction basics ) ?
the problem is not the coding... but the logic
to get a better COBOL knowledge a less ambitious project might yield better results

Re: Dynamically allocating fields in Working Storage or in F

PostPosted: Tue Jan 31, 2012 10:00 pm
by sriram1695
enrico-sorichetti wrote:what experience do You have in writing scanners and parser ( compiler construction basics ) ?
the problem is not the coding... but the logic
to get a better COBOL knowledge a less ambitious project might yield better results


Thanks for the response. I wasn't able to come up with a better logic for this requirement.
I guess this is not easily possible then..

Re: Dynamically allocating fields in Working Storage or in F

PostPosted: Tue Jan 31, 2012 10:09 pm
by enrico-sorichetti
but even if You were provided the mappings in a simple format
... something along the lines of
position, lenght, format/picture/mask
both for input and output

while easyly implementable in assembler, doing it in cobol would certainly be a pain in the *** ;)

Re: Dynamically allocating fields in Working Storage or in F

PostPosted: Tue Jan 31, 2012 10:35 pm
by BillyBoyo
If you really want to go ahead with this as an exercise, look at a Cobol output listing. Make sure you have the Data Division Map (compiler option MAP). This will give you everything except the number of decimal places. Leave those to start with.

So, make yourself a dataset of a compile listing containing the record-layouts that you are interested in. Use the full map data (not the embedded stuff) to provide a record-layout for your data.

You can search for how to open a dataset dynamically.

Are you bearing in mind that some datasets may consist of multiple record-types with different layouts? You'll need a bit of code for that, if such is one of the datasets you are interested in.