View previous topic :: View next topic
|
Author |
Message |
lanand_hps
New User
Joined: 05 Dec 2007 Posts: 82 Location: chennai
|
|
|
|
Hi,
I'm using a variable length file of length 73 (maximum length).
My file definition is
FD PRNI RECORDING MODE IS V
RECORD IS VARYING IN SIZE TO 073
CHARACTERS DEPENDING ON WS-REC-LENGTH.
My input record is
AAA001233 (remaining spaces)
BBB001233asdfzcvadsfqwerasdfasdfa
In my READ statement in the program, after the first read, the display of the record is like
AAA001233 BBBB001233 ...
asdf...
Second record is getting appeded to the first record. I want the spaces after the data to be kept as such. (i.e., i want the record to be AAA001233 with spaces after the first read)
Please comment. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
What are you displaying? Where does the data come from? What does WS-REC-LENGTH look like after the read? |
|
Back to top |
|
|
lanand_hps
New User
Joined: 05 Dec 2007 Posts: 82 Location: chennai
|
|
|
|
I'm displaying the record read(working storage variable).
The data is in the variable length file.
WS-REC-LENGTH is the length of the record without spaces. (9 in this case for the first record) |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Do not display the entire record read -- only display the characters read (use reference modification to limit the display). The behavior you're describing is not normal for a WORKING-STORAGE field. If you displayed the FILE SECTION 01 I could believe it, but I've never heard of COBOL moving data beyond the record delimiter into WORKING-STORAGE variables.
As you said, the data is in the variable length file, but my question was ... where did the variable length file come from? Was it sent via FTP from another site? Was it built by an application? What kind of application -- DB2, VSAM, CICS, batch, etc? What language is the application written in?
COBOL does not, in and of itself, remove trailing space from any file. So if you're seeing a record length of 9 in WS-REC-LENGTH after the read, something is getting rid of the trailing spaces -- most likely FTP or an application program. COBOL is showing you what it sees in the file. |
|
Back to top |
|
|
lanand_hps
New User
Joined: 05 Dec 2007 Posts: 82 Location: chennai
|
|
|
|
Thanks for clarification Robert. The input is produced by a mainframe batch job.
I wrote a test program to understand how a variable length file is processed.
FD INFILE RECORDING MODE IS V
RECORD IS VARYING IN SIZE
TO 046 CHARACTERS.
01 WS-INREC PIC X(46).
0000-MAINLINE.
OPEN INPUT INFILE.
READ INFILE.
DISPLAY WS-INREC
CLOSE INFILE.
0000-EXIT.
I created an input file with 6 records as
HEADER
DETAIL1
DETAIL2
AJMALN
KARTHIK
TRAILER
When i tested the program, the output for a single read statement is
HEADER DETAIL1 DETAIL2 AJMALN KART
I do not understand why.
Please comment. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Your code post (even though not in BBCODE format) does explain the mystery. Note that you read the file but do not display only the length of data read -- you display the entire 46-byte WS-INREC, which is the FILE SECTION 01 as I mentioned in my earlier post. You said
Quote: |
I'm displaying the record read(working storage variable). |
but you're actually not displaying a WORKING-STORAGE field, you're displaying the FILE SECTION field -- which is a buffer and contains the entire block of data read; if you display past the end of the record you will see the next record (and possibly next several records if short enough).
Add a WORKING-STORAGE variable called WS-FILE-LENGTH and change your FD to read
Code: |
RECORD IS VARYING IN SIZE
TO 046 CHARACTERS
DEPENDING ON WS-FILE-LENGTH. |
, then change your DISPLAY to
Code: |
DISPLAY WS-INREC (1 : WS-FILE-LENGTH). |
and you should only see the single record of data.
Key point to know: even if you call it WS-INREC, the FILE SECTION 01 is not WORKING-STORAGE -- it is a file buffer and has different rules than a WORKING-STORAGE field. |
|
Back to top |
|
|
|