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

Defining the data record of a variable file


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
amrita.chatterjee

New User


Joined: 27 Apr 2006
Posts: 48
Location: Bangalore, India

PostPosted: Mon May 28, 2007 10:20 am
Reply with quote

HI,
For a cobol module, the output file is VB file only. So in the File Section I have defined the file as below.
FD OUT-MAST-FILE
BLOCK CONTAINS 0 RECORDS
LABEL RECORDS ARE STANDARD
RECORDING MODE IS V,
RECORD IS VARYING IN SIZE FROM 1 TO 18000 CHARACTERS
DATA RECORD IS MAST-REC.
Now I have give data record description also.
So I have defined as below.
01 MAST-REC PIC X(18000) VARYING IN SIZE.
But in the compilation time it is giving Error.
The Error msg is given below.
"VARYING" was invalid. Scanning was resumed at the next area "A" item, level-number, or the start of the next clause.

Can somebody help me in this Error.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


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

PostPosted: Mon May 28, 2007 12:26 pm
Reply with quote

Quote:
01 MAST-REC PIC X(18000) VARYING IN SIZE.
is invalid, you need to use OCCURS DEPENDONG ON instead.
Back to top
View user's profile Send private message
pingte

Active User


Joined: 03 Dec 2005
Posts: 120
Location: india

PostPosted: Mon May 28, 2007 2:51 pm
Reply with quote

[/code]
01 MAST-REC.
05 WS-X OCCURS 1 TO 999 TIMES DEPENDING ON WS-LENGTH.

[/code]

hope this structure will be suitable for variable length file.
Move the record length to WS-LENGTH variable b4 writing to file.
(length can be counted using INSPECT)
Back to top
View user's profile Send private message
amrita.chatterjee

New User


Joined: 27 Apr 2006
Posts: 48
Location: Bangalore, India

PostPosted: Mon May 28, 2007 2:55 pm
Reply with quote

Thanks for the reply..I'll Try this..
Back to top
View user's profile Send private message
amrita.chatterjee

New User


Joined: 27 Apr 2006
Posts: 48
Location: Bangalore, India

PostPosted: Mon May 28, 2007 4:26 pm
Reply with quote

FD OUT-MAST-FILE
BLOCK CONTAINS 0 RECORDS
LABEL RECORDS ARE STANDARD
RECORDING MODE IS V,
RECORD IS VARYING IN SIZE FROM 1 TO 27990 CHARACTERS
DATA RECORD IS MAST-REC.

01 MAST-REC.
05 WS-X OCCURS 1 TO 18000 TIMES DEPENDING ON WS-STRT
.

but this is also giving error.
Please find the error msg.
A "PICTURE" clause was not found for elementary item "WS-X". "PICTURE X(1)" was assumed.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


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

PostPosted: Mon May 28, 2007 5:07 pm
Reply with quote

Then put the PICTURE X(1) after the WS-X and before the OCCURS.
Back to top
View user's profile Send private message
amrita.chatterjee

New User


Joined: 27 Apr 2006
Posts: 48
Location: Bangalore, India

PostPosted: Mon May 28, 2007 5:16 pm
Reply with quote

But WS-X is not X(1). That MAST-REC is varying from 1 thru 18000. So I Think, I should not mention X(1) as a picture clause of WS-X.
Please Suggest..
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Mon May 28, 2007 5:18 pm
Reply with quote

Hello,

Where did you get the info that says your file is from 1 to 18000?

What field in the record determines how long the record is?

How do you know the file is variable length?

I believe your information is either incomplete or just incorrect.
Back to top
View user's profile Send private message
amrita.chatterjee

New User


Joined: 27 Apr 2006
Posts: 48
Location: Bangalore, India

PostPosted: Mon May 28, 2007 5:26 pm
Reply with quote

In my first post only I have mention that the output file is a variable length file. The Record can vary from 1 thru 18000. I think u have not read my first post.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Mon May 28, 2007 5:37 pm
Reply with quote

Hello,

Yes, i have read you post - and yes you "mentioned" that this is a variable length file - and yes, your info is either incomplete or wrong.

I repeat, what direction were you given that tells you to create a variable length file? You have not posted that info. If you try to use a WS field for the number of occurs, how will another program that reads the file know how long each particular record is?

If you post the directions you were given that describe the file content, we will be able to help with the COBOL definition.
Back to top
View user's profile Send private message
amrita.chatterjee

New User


Joined: 27 Apr 2006
Posts: 48
Location: Bangalore, India

PostPosted: Mon May 28, 2007 5:48 pm
Reply with quote

Please don't get confuse..
1. I have to create a output file
2. No program will read this file.

I'm writing one module in which this output file will be generating.

In the File Control Section I have defined the file as below.

FD OUT-MAST-FILE
BLOCK CONTAINS 0 RECORDS
LABEL RECORDS ARE STANDARD
RECORDING MODE IS V,
RECORD IS VARYING IN SIZE FROM 1 TO 18000 CHARACTERS
DATA RECORD IS MAST-REC.


Now i have to define the data record MAST-REC.

I want to define the data record also as variable length means 18000 varying.

For that reason only, I have asked how i can define the data record with varying clause.

Now i hope, my requirement is clear to you.
Back to top
View user's profile Send private message
somnath

New User


Joined: 21 Mar 2005
Posts: 18
Location: India

PostPosted: Mon May 28, 2007 5:57 pm
Reply with quote

Try this.

FD OUT-MAST-FILE
RECORDING MODE IS V
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS.
01 DATA-RECORD.
05 DATA-RECORD-AREA.
10 DATA-RECORD-CHAR
OCCURS 0 TO 18000 TIMES
DEPENDING ON DATA-RECORD-LENGTH
PIC X(01).

Define DATA-RECORD-LENGTH as
01 DATA-RECORD-LENGTH PIC S9(04) COMP.
Back to top
View user's profile Send private message
amrita.chatterjee

New User


Joined: 27 Apr 2006
Posts: 48
Location: Bangalore, India

PostPosted: Mon May 28, 2007 6:14 pm
Reply with quote

Hi Somnath,

This is working fine. Thanks a lott.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Mon May 28, 2007 9:25 pm
Reply with quote

Hello,

I am curious about creating a file that no other program will read?

What kind of data will be put into this file and if nothing is going to read it, why create it?

If something later does need to read the file, how would it know how long each record is with the depending-on field not in the record?

Strange requirement. . . icon_confused.gif
Back to top
View user's profile Send private message
pingte

Active User


Joined: 03 Dec 2005
Posts: 120
Location: india

PostPosted: Tue May 29, 2007 11:26 am
Reply with quote

FYI...
Usually a variable length file will be created, so that you can provide it as an i/p to downsteam application. The length will be stored in RDW of the file which is first 4 bytes. This can be read by the next application.

RDW:-
For a mainframe file with variable length records each record is preceded by a four byte Record Descriptor Word (RDW) and a possible four byte Block Descriptor Word (BDW). The first two bytes of the RDW (and possible BDW) contains a binary value that is the length of the record (or possible block). The second two bytes of the RDW (and possible BDW) usually contain binary zeroes (or x'00').
Back to top
View user's profile Send private message
SREELAKSHMINARAYANAN

New User


Joined: 27 Jul 2006
Posts: 7

PostPosted: Tue May 29, 2007 11:41 am
Reply with quote

How to get that four byte Record Descriptor Word (RDW) in Cobol PGM
Back to top
View user's profile Send private message
pingte

Active User


Joined: 03 Dec 2005
Posts: 120
Location: india

PostPosted: Tue May 29, 2007 12:31 pm
Reply with quote

suppose i/p file name is IN-FILE
Code:

FILE SECTION.
FD IN-FILE
RECORD IS VARYING DEPENDING ON REC-LENGTH.

WORKING STORAGE SECTION.
01 REC-LENGTH PIC 9(5) COMP.
** 200 IS CONSIDERED AS MAX LENGTH OF FILE**
01 SAVED-RECORD PIC X(200).

PROCEDURE DIVISION.
*** USE RECORD LENGTH TO ACCESS RIGHT LENGTH TO DATA***
READ IN-FILE
MOVE IN-FILE (1:REC-LENGTH) TO SAVED-RECORD

hope this helps.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Tue May 29, 2007 7:58 pm
Reply with quote

Hello,

Quote:
Usually a variable length file will be created, so that you can provide it as an i/p to downsteam application. The length will be stored in RDW of the file which is first 4 bytes. This can be read by the next application.


A rather big no!

Files should be defined as vb when there will actually be records of different lengths. Also, when a normal COBOL program reads a variable length file, it does not use the RDW.
Back to top
View user's profile Send private message
pingte

Active User


Joined: 03 Dec 2005
Posts: 120
Location: india

PostPosted: Wed May 30, 2007 7:53 am
Reply with quote

in our application we do provide VB files as i/p to downstream application. And when i mean VB file.. it is implied that records will be of variable length, else a Fixed length file could have been used.

i hope this point is pretty clear.

N how does a normal cobol program knows the length of record while reading a VB file?
Mr moderator can u plz Xplain.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Wed May 30, 2007 8:33 am
Reply with quote

Hello,

A "normal cobol program" usually does not know or use the byte-count of the length (RDW). The i/o routine "knows" about the file and handles it outside of the COBOL code.

Typically, a VB file is defined with either multiple record layouts of different lengths (usually identified by a "record type") or a record definition that contains an ODO (occurs dependiong on) whose length is known by the "occurs depending on" field-name. Actually, some complex VB files contain both multiple record layouts as well as one or more ODO arrays.

In none of these cases is there a need for the RDW to be used in the COBOL code.

If you want to use certain utilities (like sort) you must allow for the RDW, but not in your COBOL code.

If you don't understand, we will try to help.
Back to top
View user's profile Send private message
pingte

Active User


Joined: 03 Dec 2005
Posts: 120
Location: india

PostPosted: Wed May 30, 2007 8:41 am
Reply with quote

Thanks got ur point..
i hope the code i have posted above is correct...

In sort when we convert a VB file to FB file, does the RDW come into play
Back to top
View user's profile Send private message
getpiyoosh

New User


Joined: 27 Mar 2006
Posts: 1
Location: pune

PostPosted: Fri Jun 01, 2007 4:16 pm
Reply with quote

Hi,
could you please tell me , what will be the read clause ?
I would appreciate If I could get the exact syntax.
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 Unable to interpret a hex value to De... COBOL Programming 4
No new posts Copy only TEXT or String from a record SYNCSORT 4
No new posts db2 vs static data COBOL Programming 1
No new posts REXX/CMS How to place command console... CLIST & REXX 4
No new posts combine multiple unique records into ... DFSORT/ICETOOL 2
Search our Forums:

Back to Top