IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Generic Cobol program to read/write files of unknown LRECL


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Vidhya Kalyanasundaram

New User


Joined: 19 Jul 2007
Posts: 30
Location: chennai

PostPosted: Tue Apr 24, 2012 9:11 pm
Reply with quote

Hi All,

We are trying to create a generic cobol program which would read a PS file of any length and create an output PS of length(Input lrecl + 24). To read the file of any different length, we tried using "RECORD CONTAINS 0 CHARACTERS" and defining the 01 level with Maximum possible Input file length as shown below. It seems to work fine and the file is opened successfully for any given LRECL.

Code:
FD  I-FILE
    RECORDING MODE IS F
    BLOCK  CONTAINS    0 RECORDS
    RECORD CONTAINS 0 CHARACTERS.

01  I-DATE-FILE                  PIC X(20000).


But, I am are not sure how to make the output to create record dynamically(Input lrecl + 24) . I tried the following format in FD section of Output file.

Code:
FD  O-FILE
    RECORDING MODE IS V
    BLOCK  CONTAINS    0 RECORDS
    RECORD IS VARYING FROM 1 TO 20024
               DEPENDING ON WS-OFILE-LENGTH.
01  O-DATA-REC                   PIC X(20024).


In the job, the Input Lrecl + 24 bytes was coded in DCB - LRECL parm and RECFM as VB.
But got error in Opening the Output file (File Status 39- An OPEN statement was unsuccessful because of a conflict between the fixed file attributes and the attributes specified for the file in the program) when tested with an Input of Lrecl 1200.

Any help regarding this is much appreciated
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Apr 24, 2012 9:19 pm
Reply with quote

Hello,

You would need to dynamically allocate the output file.

If you proceed with the variable file definition, the output will have to be variable. . .
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Apr 24, 2012 9:20 pm
Reply with quote

Add on:

Why does someone believe you need to create this?

From what i've seen, what you want to do can be done with your sort product or some other utility?
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Tue Apr 24, 2012 9:24 pm
Reply with quote

Whilst I'm not a COBOL programmer (or haven't been in recent decades icon_smile.gif), remember that a variable-length logical record will have a record descriptor word that is included in the LRECL, but is not editable by the user-written code. The RECORD IS VARYING FROM 1 TO 20024 clause would, I think, be appropriate for LRECL=20028 (20,024 bytes of data and 4 bytes for the RDW).
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Apr 24, 2012 9:27 pm
Reply with quote

I used to work with a system that allowed for any length record. However, the file handling routine could not be written in COBOL but had to be written in Assembler. COBOL is just not designed to handle files unless the record length is known AT COMPILE TIME, period. Either give up on your idea, or plan on using Assembler (for example) to handle all the file processing.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Apr 24, 2012 10:28 pm
Reply with quote

What are you trying to do, as there may be a better solution than the "Generic" Cobol program?

You want to extend all records on different datasets by 24 bytes? Whereabouts is the extension? Is it in a "fixed" part of the record or somehow you are extending the variable part?
Back to top
View user's profile Send private message
Jose Mateo

Active User


Joined: 29 Oct 2010
Posts: 121
Location: Puerto Rico

PostPosted: Wed Apr 25, 2012 1:47 am
Reply with quote

Good afternoon to all!

You are reading a fixed length file but the length is allocated at run time and your block size is taken from the JCL. On your FD for the output you should specify ' RECORD IS VARYING IN SIZE FROM 1 TO 2002 DEPENDING ON WS-OFILE-LENGTH.'
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Apr 25, 2012 1:56 am
Reply with quote

Hello,

Quote:
On your FD for the output you should specify ' RECORD IS VARYING IN SIZE FROM 1 TO 2002 DEPENDING ON WS-OFILE-LENGTH.'

Not if the output file is supposed to be fixed length. . . icon_confused.gif
Back to top
View user's profile Send private message
Jose Mateo

Active User


Joined: 29 Oct 2010
Posts: 121
Location: Puerto Rico

PostPosted: Wed Apr 25, 2012 2:54 am
Reply with quote

Mr. Scherrer,

The output is variable depending on what he moves to WS-OFILE-LENGTH. But he wants to set WS-OFILE-LENGTH to the same length as the input then he's has a problem which I don't have a answer to.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Apr 25, 2012 3:01 am
Reply with quote

Hi Jose,

Quote:
then he's has a problem which I don't have a answer to.
Yup, we don't either in vanilla COBOL icon_smile.gif

The way several of us have done this is using assembler. Personally, i'd think that this late in IT history, whatever is needed can be done without writing assembler (frowned on at many places because there are few people still practicing assembler). If something generic was wanted, it should not be too difficult to write a "driver" that would take the specifics of the copy and generate sort (or other utility?) control statements to do what is needed.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Apr 25, 2012 3:28 am
Reply with quote

Assembler would be the wise language to use for such an endevor.

For ease of maintenance, define a fixed-length DCB and a variable-length DCB in the program.

DCB keywords can use register notation (for example), LRECL=(Rx), BLKSIZE=(Rx), etc.

You pass the values for these registers in a parmlist from the Caller, as binary fullwords.

You can use a default DDNAME defined to the given DCB, such as FXDFILE or VARFILE and these would be the DDNAME(s) in the JCL.

This is just part of it, but this can get you on your way....
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 2
No new posts Using API Gateway from CICS program CICS 0
No new posts Error to read log with rexx CLIST & REXX 11
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts Write line by line from two files DFSORT/ICETOOL 7
Search our Forums:

Back to Top