Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

COBOL program for unknown Input file length
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
ParagChouguley

Active User


Joined: 03 Feb 2007
Posts: 175
Location: PUNE(INDIA)

PostPosted: Fri Feb 27, 2009 4:04 pm    Post subject: COBOL program for unknown Input file length
Reply with quote

Can one write a cobol program which accepts FB input file but length of that file is unknown or varies?
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7904
Location: Bellevue, IA

PostPosted: Fri Feb 27, 2009 4:30 pm    Post subject:
Reply with quote

COBOL can work only with files whose record length can be determined at compile time, since the FD has to provide the record length in the associated 01 level. So the answer to your question is no, one cannot write such a COBOL program.

I've seen this done in the past by using an Assembler subroutine that handles all file activity; Assembler programs don't have to know the length of the file record until the file is opened.
Back to top
View user's profile Send private message
ParagChouguley

Active User


Joined: 03 Feb 2007
Posts: 175
Location: PUNE(INDIA)

PostPosted: Fri Feb 27, 2009 6:18 pm    Post subject:
Reply with quote

Hi Robert,
Thanks for your responce on this. So is there any way to achive this requirement along with COBOL. I mean some other application writing this varying length data to fixed length file which goes as input to COBOL program. or something like that!
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7904
Location: Bellevue, IA

PostPosted: Fri Feb 27, 2009 6:20 pm    Post subject:
Reply with quote

Not with COBOL. COBOL has to know, at compile time, how long the FD record is and that cannot be changed. Unless you want to include a COBOL compile as part of your production job stream to change the length every time a new one is needed ... NOT a recommended practice!
Back to top
View user's profile Send private message
PeD

Active User


Joined: 26 Nov 2005
Posts: 456
Location: Belgium

PostPosted: Fri Feb 27, 2009 6:57 pm    Post subject:
Reply with quote

Robert,

( this is true in PL/I ).
Are you sure you cannot specify a FD record without length and allocate dynamically the file via i.e. BPXWDYN and so allocate a file when its length is not known at compile time.

I repeat in PL/I it is feasable easily.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7904
Location: Bellevue, IA

PostPosted: Fri Feb 27, 2009 7:10 pm    Post subject:
Reply with quote

Okay, the file is allocated via BPXWDYN. How does COBOL open the file? What does COBOL use for the READ? There no FD so the READ verb isn't going to be usable ...
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Fri Feb 27, 2009 7:33 pm    Post subject:
Reply with quote

Have you looked at Requesting undefined format?
With an undefined format, you will have to do your own de-blocking, but that sould be a simple process.
Back to top
View user's profile Send private message
Douglas Wilder

Active User


Joined: 28 Nov 2006
Posts: 305
Location: Deerfield IL

PostPosted: Fri Feb 27, 2009 9:03 pm    Post subject:
Reply with quote

I have used a COBOL program for a sort exit 15 for this purpose.
Sort does the reading and writing of the files, without you having to specify the record length in your COBOL program, just a maximum record length.
Back to top
View user's profile Send private message
superk

Moderator Team Head


Joined: 26 Apr 2004
Posts: 4648
Location: Raleigh, NC, USA

PostPosted: Sat Feb 28, 2009 1:07 am    Post subject: Reply to: COBOL program for unknown Input file length
Reply with quote

Just to add my piddly little thoughts. I could swear that we already hashed this whole concept out in a few previous topics, and came to the consensus in the end that this just can't be done in COBOL alone.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7904
Location: Bellevue, IA

PostPosted: Sat Feb 28, 2009 1:38 am    Post subject:
Reply with quote

Kevin, I think you're right -- it seems like deja vu all over again! Maybe this topic needs to be added to the FAQ list of no-no topics?
Back to top
View user's profile Send private message
superk

Moderator Team Head


Joined: 26 Apr 2004
Posts: 4648
Location: Raleigh, NC, USA

PostPosted: Sat Feb 28, 2009 1:50 am    Post subject: Reply to: COBOL program for unknown Input file length
Reply with quote

Maybe, right below the "reading a file backwards" topic.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Sat Feb 28, 2009 5:31 am    Post subject: Re: Reply to: COBOL program for unknown Input file length
Reply with quote

superk wrote:
I could swear that we already hashed this whole concept out in a few previous topics, and came to the consensus in the end that this just can't be done in COBOL alone.
I am sorry Kevin, but I do think it is possible, undefined format kind of leaves the format and deblocking to the reader.... Grin....
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7904
Location: Bellevue, IA

PostPosted: Sat Feb 28, 2009 6:23 am    Post subject:
Reply with quote

William -- the original request was for an FB file, which conflicts with the undefined format.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Sat Feb 28, 2009 5:46 pm    Post subject:
Reply with quote

Robert Sample wrote:
William -- the original request was for an FB file, which conflicts with the undefined format.
It is recommended that you not use format U to update or extend a file that was written with a different record format. If you use format U to update a file that was written with a different format, the RECFM value in the data-set label could be changed or the data set could contain records written in different formats.
But reading seems to be ok.......
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7904
Location: Bellevue, IA

PostPosted: Sat Feb 28, 2009 6:59 pm    Post subject:
Reply with quote

I still foresee difficulty ... RECFM U has a block descriptor word to tell how long each block is. RECFM FB has no block descriptor word ... so either the first 4 bytes of the block become a nonsensical BDW, or the system generates one based on the block read (which would be pretty unique in my experience) ... but assuming I get some time today, I'll try a COBOL program to read an FB file as U and see what it says.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Sat Feb 28, 2009 7:16 pm    Post subject:
Reply with quote

Back in the olden days, DASD & tape used inter-block gaps to determine the size of the block. The hardware would read the block and hand it to the channel and (as far as I know) would not care if the block was FB, VB or U.
Back to top
View user's profile Send private message
jasorn

Active User


Joined: 12 Jul 2006
Posts: 153
Location: USA

PostPosted: Sun Mar 01, 2009 8:59 pm    Post subject: Reply to: COBOL program for unknown Input file length
Reply with quote

It's not only possible in COBOL to FB input file when the lrecl isn't known at compile time, it's pretty easy. The way I do this is:

1. code
Code:

RECORD CONTAINS 0

In the FD statement.

e.g.
Code:

FD  IN-FILE                     
    RECORDING MODE IS F               
    RECORD CONTAINS 0                 
    LABEL RECORD STANDARD.           
01  IN-FILE-REC          PIC X(3000).


2. Make the PIC clause on the FD statement at least as long as the longest you'll need.
3. Pass the lrecl via linkage to the program that's going to read the file.
4. When the file is read, read it into a working storage variable using reference modification. I make the working storage variable the same length as the longest lrecl I expect is possible for this program. The read looks something like this:
Code:

READ IN-FILE INTO WS-IN-FILE-REC(1:LRECL-PASSED-FROM-LINKAGE)

Then your program just has to be smart enough to figure out what to do with the different input lengths.

I haven't found any nice way to accomplish the same with the output file and still use FB.

Edit: Maybe this one.
Back to top
View user's profile Send private message
Douglas Wilder

Active User


Joined: 28 Nov 2006
Posts: 305
Location: Deerfield IL

PostPosted: Mon Mar 02, 2009 10:16 pm    Post subject:
Reply with quote

Thank you that is very great!
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Mon Mar 02, 2009 10:53 pm    Post subject: Re: Reply to: COBOL program for unknown Input file length
Reply with quote

jasorn wrote:
It's not only possible in COBOL to FB input file when the lrecl isn't known at compile time, it's pretty easy.
Good call, even easier than I thought.....
The RECORD CONTAINS 0 CHARACTERS clause can be specified for input QSAM files containing fixed-length records; the record size is determined at run time from the DD statement parameters or the data set label. If, at run time, the actual record is larger than the 01 record description, then only the 01 record length is available. If the actual record is shorter, then only the actual record length can be referred to. Otherwise, uninitialized data or an addressing exception can be produced.
Back to top
View user's profile Send private message
jasorn

Active User


Joined: 12 Jul 2006
Posts: 153
Location: USA

PostPosted: Tue Mar 03, 2009 4:47 am    Post subject: Re: Reply to: COBOL program for unknown Input file length
Reply with quote

CICS Guy wrote:
Good call, even easier than I thought.....

Yeah it's pretty easy but not very many mainframers I meet think it's even possible without calling some sort of dynamic allocation program. I've used this for quite a while to write many generic utility programs and it's really a time saver.

Coupled with the process I wrote to parse out a copybook and load the field names, start and stop positions, etc into an array and this is very powerful indeed. Nearly magical.

But it's not without pitfalls, you have some extra or different type of validation to consider when using this method. The comments should be aplenty if this kind of thing is used in production. I recommend erroring on the side of not using in production unless options are weighed carefully, it's well documented and tested very well.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts High CPU consumption Job using IAM fi... aswinir JCL & VSAM 8 Thu Dec 01, 2016 8:28 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts IMS BMP program causes 878 system abend Artemk IMS DB/DC 7 Tue Nov 22, 2016 8:26 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us