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
 

 

Spaces getting truncated in Variable Length file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
lanand_hps

New User


Joined: 05 Dec 2007
Posts: 82
Location: chennai

PostPosted: Sun Dec 14, 2008 3:27 pm    Post subject: Spaces getting truncated in Variable Length file
Reply with quote

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
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8057
Location: East Dubuque, Illinois, USA

PostPosted: Sun Dec 14, 2008 4:45 pm    Post subject:
Reply with quote

What are you displaying? Where does the data come from? What does WS-REC-LENGTH look like after the read?
Back to top
View user's profile Send private message
lanand_hps

New User


Joined: 05 Dec 2007
Posts: 82
Location: chennai

PostPosted: Sun Dec 14, 2008 4:50 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8057
Location: East Dubuque, Illinois, USA

PostPosted: Sun Dec 14, 2008 7:23 pm    Post subject:
Reply with quote

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
View user's profile Send private message
lanand_hps

New User


Joined: 05 Dec 2007
Posts: 82
Location: chennai

PostPosted: Mon Dec 15, 2008 4:00 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8057
Location: East Dubuque, Illinois, USA

PostPosted: Mon Dec 15, 2008 6:33 pm    Post subject:
Reply with quote

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
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 Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm
No new posts Getting error while opening a variabl... apandey1 COBOL Programming 5 Fri May 05, 2017 12:22 pm
No new posts Issue with NDM process to transmit ES... chetanambi All Other Mainframe Topics 6 Wed May 03, 2017 10:52 am
No new posts File processing vishwakotin Mainframe Interview Questions 9 Fri Apr 28, 2017 11:38 am
No new posts Occurrence of various strings within ... TS70363 JCL & VSAM 1 Thu Apr 27, 2017 8:18 pm


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