Dynamically allocating fields in Working Storage or in FD



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Dynamically allocating fields in Working Storage or in FD

Postby sriram1695 » Tue Jan 31, 2012 6:57 pm

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
sriram1695
 
Posts: 6
Joined: Sat Dec 10, 2011 1:09 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Dynamically allocating fields in Working Storage or in FD

 

Re: Dynamically allocating fields in Working Storage or in F

Postby BillyBoyo » Tue Jan 31, 2012 8:54 pm

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.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Dynamically allocating fields in Working Storage or in F

Postby Akatsukami » Tue Jan 31, 2012 9:03 pm

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.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1053
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Dynamically allocating fields in Working Storage or in F

Postby sriram1695 » Tue Jan 31, 2012 9:29 pm

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.
sriram1695
 
Posts: 6
Joined: Sat Dec 10, 2011 1:09 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Dynamically allocating fields in Working Storage or in F

Postby enrico-sorichetti » Tue Jan 31, 2012 9:32 pm

in what format are You going to provide the layout ?
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2643
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 130 times

Re: Dynamically allocating fields in Working Storage or in F

Postby sriram1695 » Tue Jan 31, 2012 9:38 pm

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).
sriram1695
 
Posts: 6
Joined: Sat Dec 10, 2011 1:09 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Dynamically allocating fields in Working Storage or in F

Postby enrico-sorichetti » Tue Jan 31, 2012 9:42 pm

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
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2643
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 130 times

Re: Dynamically allocating fields in Working Storage or in F

Postby sriram1695 » Tue Jan 31, 2012 10:00 pm

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..
sriram1695
 
Posts: 6
Joined: Sat Dec 10, 2011 1:09 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Dynamically allocating fields in Working Storage or in F

Postby enrico-sorichetti » Tue Jan 31, 2012 10:09 pm

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 *** ;)
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2643
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 130 times

Re: Dynamically allocating fields in Working Storage or in F

Postby BillyBoyo » Tue Jan 31, 2012 10:35 pm

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.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post