View previous topic :: View next topic
|
Author |
Message |
chennai
New User
Joined: 12 Jun 2008 Posts: 26 Location: chennai
|
|
|
|
Hi all,
I have variable file I am reading this in the program and depending on the length of each record I have to place that in another file of variable size, please let me know if any one is aware how to find the length of each record in variable file apart from reading byte by byte and calculating(using perform).
is there any function ? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
There is no function I know of to do, but if you read the Language Reference manual for a bit you can find (emphasis added by me):
Quote: |
5.2.5.3 Format 3
Format 3 is used to specify variable-length records.
___ Format 3 ___________________________________________________________
| |
| >>__RECORD__ ____ __VARYING__ ____ __ ______ ________________________> |
| |_IS_| |_IN_| |_SIZE_| |
| |
| >__ _____________________ __ _______________ __ ____________ ________> |
| |_ ______ __integer-6_| |_TO__integer-7_| |_CHARACTERS_| |
| |_FROM_| |
| |
| >__ ________________________________ _______________________________>< |
| |_DEPENDING__ ____ __data-name-1_| |
| |_ON_| |
| |
|________________________________________________________________________|
integer-6
Specifies the minimum number of bytes to be contained in any record of the file. If integer-6 is not specified, the minimum number of bytes to be contained in any record of the file is equal to the least number of bytes described for a record in that file.
integer-7
Specifies the maximum number of bytes in any record of the file. If integer-7 is not specified, the maximum number of bytes to be contained in any record of the file is equal to the greatest number of bytes described for a record in that file.
The number of bytes associated with a record description is determined by the sum of the number of bytes in all elementary data items (excluding redefinitions and renamings), plus any implicit FILLER due to synchronization. If a table is specified:
* The minimum number of table elements described in the record is used in the summation above to determine the minimum number of bytes associated with the record description.
* The maximum number of table elements described in the record is used in the summation above to determine the maximum number of bytes associated with the record description.
If data-name-1 is specified:
* Data-name-1 must be an elementary unsigned integer.
* Data-name-1 cannot be a windowed date field.
* The number of bytes in the record must be placed into the data item referenced by data-name-1 before any RELEASE, REWRITE, or WRITE statement is executed for the file.
* The execution of a DELETE, RELEASE, REWRITE, START, or WRITE statement or the unsuccessful execution of a READ or RETURN statement does not alter the content of the data item referenced by data-name-1.
* After the successful execution of a READ or RETURN statement for the file, the contents of the data item referenced by data-name-1 indicate the number of bytes in the record just read. |
|
|
Back to top |
|
|
gcicchet
Senior Member
Joined: 28 Jul 2006 Posts: 1702 Location: Australia
|
|
|
|
Hi,
doesn't the RDW tell the length of each record ?
or have I misunderstood something ?
Gerry |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hi Gerry,
Quote: |
doesn't the RDW tell the length of each record |
Yes, but it is not returned to the cobol program as data unless specified. COBOL programs typically "know" how to process by a "record type" or "occurs depending on". |
|
Back to top |
|
|
gcicchet
Senior Member
Joined: 28 Jul 2006 Posts: 1702 Location: Australia
|
|
|
|
Hi,
thanks Dick
Gerry |
|
Back to top |
|
|
ridgewalker58
New User
Joined: 26 Sep 2008 Posts: 51 Location: New York
|
|
|
|
I don't have a compiler, so you will have to fix the SYNTAX where there are errors. This is the basic idea.
** Also please see the "similar note" about the RDW that is hidden when you read a SEQUENTIAL file (but not with a VSAM file) that I have included below.
Code: |
FD INPUT-FILE1
RECORD IS VARYING
FROM 100 TO 2000 CHARACTERS
DEPENDING ON WS-INPUT-LENGTH
BLOCK CONTAINS 0 RECORDS.
01 INPUT-REC1 PIC X(100).
01 INPUT-REC2 PIC X(2000).
FD OUTPUT-FILE1
RECORDING MODE IS V
RECORD CONTAINS 100 TO 2000 CHARACTERS
DEPENDING ON WS-INPUT-LENGTH
BLOCK CONTAINS 0 RECORDS.
01 OUTPUT-REC1 PIC X(01) OCCURS
100 TO 2000 DEPENDING ON WS-INPUT-LENGTH.
WORKING-STORAGE SECTION.
01 WS-INPUT-LENGTH PIC 9(004) VALUE ZERO.
PROCEDURE DIVISION.
READ INPUT-FILE1.
*** this next instruction may not be necessary
MOVE WS-INPUT-LENGTH TO WS-INPUT-LENGTH.
MOVE INPUT-REC2 TO OUTPUT-REC1.
WRITE OUTPUT-REC1. |
*** couldn't possibly be necessary. . .
**** on a similar note - Reading records from a VSAM file will not give you the RDW. Reading records from a Sequential file, the RDW is in 4 bytes that preceed the 01 input-rec1 layout.
The layout of this RDW for the sequential file is:
LLBB/then the 01 record description
LL is a pic 9(04) comp. field
BB is a non used 2 bytes
In the past we used to be able to define one of our 01 record descriptions
as a table 01 INPUT-REC1.
05 INPUT-FIELD1 OCCURS 2 TIMES.
10 INPUT-LL1 PIC 9(04) COMP.
10 INPUT-BB1 PIC X(02).
-- and then reference the INPUT-LL1 field with a SUBSCRIPT value of ZERO. and beware of unexpected happenings.
**** SUGGESTION -- USE THE VARYING THAT MR. SAMPLE provided |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
It is not so much the varying as it is the data-name-1. . . |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
*** this next instruction may not be necessary
MOVE WS-INPUT-LENGTH TO WS-INPUT-LENGTH. |
The comment is correct -- this statement is not needed.
Furthermore, the RECORD VARIABLE field is set, if specified, for both VSAM and sequential files (which I've verified by testing) whereas the RDW trick is not guaranteed to work since it depends on things that IBM could change, and it definitely doesn't work for VSAM files which don't have an RDW per se. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Code: |
MOVE INPUT-REC2 TO OUTPUT-REC1. [quote]This should use reference modification -- if the reocrd is 107 bytes you do NOT want to move 2000 bytes from the buffer into the output record -- no telling what you'll have show up on the output file.[/quote] |
|
|
Back to top |
|
|
ridgewalker58
New User
Joined: 26 Sep 2008 Posts: 51 Location: New York
|
|
|
|
Robert, I am sorry that I don't have a compiler to test this out -- BUT, I believe that if you SET the OUTPUT-REC1 depending on field to the value of the input record, then the MOVE INPUT-REC2 TO OUTPUT-REC1 will only move the number of bytes in the ws-input-length field.
thank you |
|
Back to top |
|
|
chennai
New User
Joined: 12 Jun 2008 Posts: 26 Location: chennai
|
|
|
|
Hi ...Thanks a lot for your solution ..Now I am pretty clear of variable files..thanks..once again |
|
Back to top |
|
|
|