Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Find the length of each record in variable file

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

New User


Joined: 12 Jun 2008
Posts: 26
Location: chennai

PostPosted: Sat Oct 25, 2008 1:33 pm    Post subject: Find the length of each record in variable file
Reply with quote

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

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8201
Location: Dubuque, Iowa, USA

PostPosted: Sat Oct 25, 2008 5:43 pm    Post subject:
Reply with quote

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

Senior Member


Joined: 28 Jul 2006
Posts: 1703
Location: Australia

PostPosted: Mon Oct 27, 2008 3:47 am    Post subject:
Reply with quote

Hi,

doesn't the RDW tell the length of each record ?

or have I misunderstood something ?



Gerry
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Mon Oct 27, 2008 4:53 am    Post subject:
Reply with quote

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

Senior Member


Joined: 28 Jul 2006
Posts: 1703
Location: Australia

PostPosted: Mon Oct 27, 2008 5:03 am    Post subject:
Reply with quote

Hi,

thanks Dick


Gerry
Back to top
View user's profile Send private message
ridgewalker58

New User


Joined: 26 Sep 2008
Posts: 51
Location: New York

PostPosted: Mon Oct 27, 2008 8:39 pm    Post subject:
Reply with quote

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

Site Director


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

PostPosted: Mon Oct 27, 2008 8:59 pm    Post subject:
Reply with quote

Hello,

It is not so much the varying as it is the data-name-1. . .
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8201
Location: Dubuque, Iowa, USA

PostPosted: Mon Oct 27, 2008 9:24 pm    Post subject:
Reply with quote

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

Global Moderator


Joined: 06 Jun 2008
Posts: 8201
Location: Dubuque, Iowa, USA

PostPosted: Mon Oct 27, 2008 9:27 pm    Post subject:
Reply with quote

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

New User


Joined: 26 Sep 2008
Posts: 51
Location: New York

PostPosted: Mon Oct 27, 2008 10:00 pm    Post subject:
Reply with quote

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

New User


Joined: 12 Jun 2008
Posts: 26
Location: chennai

PostPosted: Wed Oct 29, 2008 3:17 pm    Post subject:
Reply with quote

Hi ...Thanks a lot for your solution ..Now I am pretty clear of variable files..thanks..once again
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 Moving a COMP-3 Variable to a Numeric... ajayachander COBOL Programming 2 Thu Dec 14, 2017 5:46 pm
No new posts ISSUE IN copying Sequential file reco... thesumitk JCL & VSAM 2 Wed Dec 13, 2017 3:07 pm
No new posts query to fetch record which has only ... maxsubrat DB2 12 Mon Dec 11, 2017 5:03 pm
No new posts File Tailoring -- Temporary dataset i... samzee71 CLIST & REXX 3 Fri Dec 01, 2017 3:12 am
No new posts Rexx - File tailoring samzee71 CLIST & REXX 10 Thu Nov 30, 2017 10:47 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us