Problem while reading VB file



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Problem while reading VB file

Postby sange-sherin » Thu Dec 05, 2013 6:00 pm

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?
sange-sherin
 
Posts: 25
Joined: Thu Nov 21, 2013 6:56 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Problem while reading VB file

Postby BillyBoyo » Thu Dec 05, 2013 6:44 pm

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).
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Problem while reading VB file

Postby sange-sherin » Thu Dec 05, 2013 6:59 pm

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.                               
sange-sherin
 
Posts: 25
Joined: Thu Nov 21, 2013 6:56 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Problem while reading VB file

Postby dick scherrer » Thu Dec 05, 2013 7:53 pm

Hello,

How are the variable lengths determined within the records?

How does the code determine between different record types (some probably being different lengths)?
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Problem while reading VB file

Postby Robert Sample » Thu Dec 05, 2013 8:32 pm

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.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Problem while reading VB file

Postby sange-sherin » Fri Dec 06, 2013 1:02 pm

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.
sange-sherin
 
Posts: 25
Joined: Thu Nov 21, 2013 6:56 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Problem while reading VB file

Postby NicC » Fri Dec 06, 2013 4:05 pm

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.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: Problem while reading VB file

Postby Robert Sample » Fri Dec 06, 2013 4:21 pm

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.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Problem while reading VB file

Postby sange-sherin » Fri Dec 06, 2013 4:31 pm

Hi Robert ,

I understand the problem. Thank you.
sange-sherin
 
Posts: 25
Joined: Thu Nov 21, 2013 6:56 pm
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post