Page 1 of 1

Problem while reading VB file

PostPosted: Thu Dec 05, 2013 6:00 pm
by sange-sherin
Hi,

My input file is VB and Record length -32700 and Block size - 32760.
And i am getting input file from external source with different size (means some times it might be filled upto 90cols alone or sometimes it might be filled up to 1000cols alone).properties of file will be same.

When i read the first record (suppose this file is having records up to 100cols) , it reads with the second record also.

for example:
INPUT file:

 ****** ***************************** Top of Data ********************
 000001 bossart   522377114      44851         Heath Consultant's Inc.
 000002 bossart                                                       
 ****** **************************** Bottom of Data ******************


When it reads:
the first record is : "bossart 522377114 44851 Heath Consultant's Inc. bossart "

can anyone please explain me why its happen? and help me provide the solution?

Re: Problem while reading VB file

PostPosted: Thu Dec 05, 2013 6:44 pm
by BillyBoyo
Yes, you are picking up data from the next record because you have not defined the 01(s) under the FD so that they don't.

Show the FD and the 01(s) and your READ statement(s).

Re: Problem while reading VB file

PostPosted: Thu Dec 05, 2013 6:59 pm
by sange-sherin
Hi,

Please find the code below:

FD  DATA-FILE                                 
    RECORDING MODE IS V                       
    RECORD IS VARYING FROM 1 TO 32696.                         
01  INPUT-REC                   PIC X(32696).

........................
......................
...............................
READ DATA-FILE                           
    AT END MOVE 'Y' TO WF-DATA-FILE-EOF 
END-READ.                               

Re: Problem while reading VB file

PostPosted: Thu Dec 05, 2013 7:53 pm
by dick scherrer
Hello,

How are the variable lengths determined within the records?

How does the code determine between different record types (some probably being different lengths)?

Re: Problem while reading VB file

PostPosted: Thu Dec 05, 2013 8:32 pm
by Robert Sample
You are telling COBOL to read 32696 bytes for each and every READ statement. If that is 1 record or 300 records does not matter -- COBOL is going to read 32696 bytes. You would be wise to include the record length indicator (DEPENDING ON <variable-name>) in your RECORD VARYING clause and to use OCCURS DEPENDING ON for INPUT-REC.

Re: Problem while reading VB file

PostPosted: Fri Dec 06, 2013 1:02 pm
by sange-sherin
Hi,

sorry, I am not able to get your point.

I have declared my code like below:

 FD  DATA-FILE                                 
     RECORDING MODE IS V                       
     RECORD IS VARYING FROM 1 TO 32696         
      DEPENDING ON WS-LENGTH.                   
 01  INPUT-REC                   PIC X(32696). 


even though i am facing the same problem.

Can you please explain the problem from the base since i am very new to cobol.

Re: Problem while reading VB file

PostPosted: Fri Dec 06, 2013 4:05 pm
by NicC
From the programming guide (which you have referred to, of course):
When you specify a READ INTO statement for a format-V file, the record size read for that file is used in the MOVE statement generated by the compiler. Consequently, you might not get the result you expect if the record just read does not correspond to the level-01 record description. All other rules of the MOVE statement apply. For example, when you specify a MOVE statement for a format-V record read in by the READ statement, the size of the record moved corresponds to its level-01 record description.

Re: Problem while reading VB file

PostPosted: Fri Dec 06, 2013 4:21 pm
by Robert Sample
Using RECORD IS VARYING identifies the file to COBOL as variable. The actual number of bytes read, however, depend upon the length of the 01's declared under the FD. You only have 1 01 and it is fixed at 32696 bytes -- so your program will be passed 32696 bytes every time your READ statement is executed. If the first record read with the READ statement is not 32696 bytes long, COBOL will continue to read from the file until your program has 32696 bytes in INPUT-REC -- because you told COBOL that is what you want. You need multiple 01's defined under the FD or your 01 INPUT-REC needs OCCURS DEPENDING ON to make the file reads variable length.

Reading and writing variable-length files in COBOL is NOT a task for a rank beginner -- it requires that you have some experience with COBOL already.

Re: Problem while reading VB file

PostPosted: Fri Dec 06, 2013 4:31 pm
by sange-sherin
Hi Robert ,

I understand the problem. Thank you.