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
 

 

Generic Cobol program to read/write files of unknown LRECL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Generic Cobol program to read/write files of unknown LRECL
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

Site Director


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

PostPosted: Tue Apr 24, 2012 9:19 pm    Post subject:
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

Site Director


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

PostPosted: Tue Apr 24, 2012 9:20 pm    Post subject:
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: 1738
Location: Bloomington, IL

PostPosted: Tue Apr 24, 2012 9:24 pm    Post subject:
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: 7913
Location: Bellevue, IA

PostPosted: Tue Apr 24, 2012 9:27 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7231

PostPosted: Tue Apr 24, 2012 10:28 pm    Post subject: Reply to: Generic Cobol program to read/write files of unkno
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: 110
Location: Puerto Rico

PostPosted: Wed Apr 25, 2012 1:47 am    Post subject:
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

Site Director


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

PostPosted: Wed Apr 25, 2012 1:56 am    Post subject:
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: 110
Location: Puerto Rico

PostPosted: Wed Apr 25, 2012 2:54 am    Post subject:
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

Site Director


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

PostPosted: Wed Apr 25, 2012 3:01 am    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Apr 25, 2012 3:28 am    Post subject: Reply to: Generic Cobol program to read/write files of unkno
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts I can not compile my program PL1 V3.R... Miguel Fernandez PL/I & Assembler 13 Tue Dec 06, 2016 8:30 pm
No new posts High CPU consumption Job using IAM fi... aswinir JCL & VSAM 8 Thu Dec 01, 2016 8:28 pm
No new posts IMS BMP program causes 878 system abend Artemk IMS DB/DC 7 Tue Nov 22, 2016 8:26 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm


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