View previous topic :: View next topic
|
Author |
Message |
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
we are trying to read a VB file to load the data into a VARCHAR field in a table programmatically but the read command is reading more data than expected i.e when i display after read i am able to see second record is also getting appended to first and says file status 04 |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
What does the FD look like? What does the READ statement look like? Psychic day was yesterday, so you've got to give us more information about what you are doing. |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
FD looks like
Code: |
FD TEST-FILE
RECORDING MODE IS V
BLOCK CONTAINS 0 RECORDS
RECORD CONTAINS 22 TO 1510 CHARACTERS.
RECORD IS VARYING IN SIZE FROM 22 TO 1510 CHARACTERS
DEPENDING ON DATALEN.
DATA RECORD IS TEST1-RECORD.
|
Copybooks
Code: |
01 TEST1-RECORD.
* 05 FILLER PIC X(4).
05 DELETE-BYTE PIC X(1).
05 ACT-NO PIC X(11).
05 RCD-TYP PIC X(2).
05 USR-ID PIC X(8).
05 FILLER PIC X(1492).
01 TEST2-RECORD.
05 FILLER PIC X(4).
05 VAR-DATA PIC X(1510).
|
Read para
Code: |
INITIALIZE TEST1-RECORD TEST2-RECORD.
READ TEST-FILE
AT END MOVE 'Y' TO WS-EOF
END-READ.
|
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Why INITIALIZE? This is not needed.
Your TEST2-RECORD is 1514 bytes long -- why, when you declare 1510 bytes is the maximum?
Unless you use reference modification based on DATALEN, any processing you do of TEST1-RECORD or TEST2-RECORD will use 1514 bytes -- if your record is 22 bytes long, then you retrieve 1492 bytes of the next record (or two records, or 68 records) from the buffer and probably reprocess a number of the records since the second read will return the second record from the buffer.
If you want variable length records, you need to have different length 01 records in your FD, or an OCCURS DEPENDING on in the FD 01 record, or use reference modification to only take the bytes associated with the current record from the FD 01 since the buffer is returned which will be a physical block, not necessarily a single record. |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Hi Robert,
Code: |
01 MTGKACT1-RECORD.
* 05 FILLER PIC X(4).
05 DELETE-BYTE PIC X(1).
05 ACT-NO PIC X(11).
05 RCD-TYP PIC X(2).
05 USR-ID PIC X(8).
|
Code: |
01 MTGKACT2-RECORD.
* 05 FILLER PIC X(4).
05 VAR-DATA PIC X(1510).
|
I tried with this copybook still it reads more data.
Thanks |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
I tried with this copybook still it reads more data. |
I don't know what this means. COBOL reads a single record each time. However, with variable length files that are blocked, it is very easy to access more than just the current record.
In your FD, add this:
Code: |
01 TEST3-RECORD.
05 TEST3-BYTES OCCURS 22 TO 1510
DEPENDING ON DATALEN. |
and use TEST3-RECORD in your program instead of TEST1-RECORD or TEST2-RECORD. |
|
Back to top |
|
|
ashutosh.pr
New User
Joined: 13 Apr 2007 Posts: 36 Location: Pune
|
|
|
|
Hi Prem,
I was facing a similar issue. You can try changing the record description in the file section to a variable length field as suggested by Robert.
i.e Do not read a VB file into a fixed record structure. The size of the variable field should be similar to the the VB file record structure ( varying FROM and TO should be the same.
You can refer to this thread:
ibmmainframes.com/viewtopic.php?t=43940&highlight=
Please let us know if this works for you because it worked for me.
Thanks,
Ashutosh |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Prem,
Your FD s/b:
Code: |
FD TEST-FILE
RECORDING MODE IS V
RECORD IS VARYING IN SIZE FROM 22 TO 1510 CHARACTERS
DEPENDING ON DATALEN. |
You need at least 1 rec description that's large enough to contain the largest rec (i.e. 1510).
To get an idea of what's going on, run a read test of a few recs and display DATALEN after each READ.
You don't have to supply a variable data length 01 in the FD. As an example, you can rewrite a variable rec, after you've updated the fixed portion of the rec, by using the same DEPENDING ON clause that you used on the I/P. Each rec will vary with the value of DATALEN, in spite of the fact that the FD 01 is defined as PIC X(1510).
A lot of what you can and can't do depends on what you're trying to accomplish.
BTW, you only define the rec len as 1514 in the JCL LRECL, use 1510 for the pgm. |
|
Back to top |
|
|
ajit167413
New User
Joined: 30 Sep 2009 Posts: 1 Location: Chennai
|
|
|
|
Can you please reply like how did you solve this issue... |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Good luck there, Ajit. Too many posters here simply take the information and run. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
or simply run from the information. |
|
Back to top |
|
|
|