Reading VB input file ,all the records at same time



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

Reading VB input file ,all the records at same time

Postby rekhamf » Tue Apr 10, 2012 1:53 am

Hi ,

I have 1136 variable block input file which has 2000 records .I need to read all the records at same time instead of reading one by one .

And in the input file, i have field-1 (column-1) which can be repeated 2 to 3 times in file with same value .
I need to move the same field-1 value to working storage field of line 1

eg :
input file
11111111111111123467dfdfjhjlfjhlkgjlkjlhk*
111111111111111sdjfdlkdlkgfggkggggggggg*
222222222222222eeeeeeeeeeeeeeeeerrfddf*
22222222222222dfmgfdmgggggggggggggfgf*
11111111111111sdfdsgfggggggggggggggggg*


while writing to output it should be written in 2 lines (one with 1111111111111111 and another with 2222222222222) : i need to increase the length of output file also

11111111111111123467dfdfjhjlfjhlkgjlkjlhk*111111111111111sdjfdlkdlkgfggkggggggggg*11111111111111sdfdsgfggggggggggggggggg*
222222222222222eeeeeeeeeeeeeeeeerrfddf*22222222222222dfmgfdmgggggggggggggfgf*



It would be great help if some one help me on this .
rekhamf
 
Posts: 33
Joined: Mon Nov 28, 2011 5:09 am
Has thanked: 0 time
Been thanked: 0 time

Re: Reading VB input file ,all the records at same time

Postby Akatsukami » Tue Apr 10, 2012 2:00 am

Why do you need to read all the records at once? Why cannot the data set be sorted on the key and read sequentially (since what comes out looks nothing like what goes in, so it makes no sense to claim that "the order of the records must be preserved" or similar yivshish).
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Reading VB input file ,all the records at same time

Postby BillyBoyo » Tue Apr 10, 2012 2:18 am

I'd also ask why you want to do that. And add that, in Cobol, you can't do it anyway.

If ever a file is not in the order we want to process it, we sort it (almost without exception).

If you think of what a Sort would give you, all the records you need together would be together, does that help you?

Splitting records into two, no problem. Writing longer records than you read, no problem.

Come back and let us know how things look after the file is sorted.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Reading VB input file ,all the records at same time

Postby rekhamf » Tue Apr 10, 2012 2:34 am

Hi ,

I can do sort on field-1 on asc order then i need to read this file .Since the file is VB ,the record in first line is till 654 and from 655 it should start the second line record.The second line record length is 700,,, not all 1132 utilized in the input file .so i need to calculate the length also for each line and need to append the records which has same values....

If I'm reading the file
READ READ  INPUT-FILE                 
    AT END                           
       SET  EOF-INPUT-Y TO TRUE   
END-READ


How i can hold the previous field1 value and then read the second record and check 2nd value with 1st value and then write to output file ?

eg :
input file
11111111111111123467dfdfjhjlfjhlkgjlkjlhk*
111111111111111sdjfdlkdlkgfggkggggggggg*
222222222222222eeeeeeeeeeeeeeeeerrfddf*
22222222222222dfmgfdmgggggggggggggfgf*
11111111111111sdfdsgfggggggggggggggggg*


while writing to output it should be written in 2 lines (one with 1111111111111111 and another with 2222222222222) : i need to increase the length of output file also

11111111111111123467dfdfjhjlfjhlkgjlkjlhk*111111111111111sdjfdlkdlkgfggkggggggggg*11111111111111sdfdsgfggggggggggggggggg*
222222222222222eeeeeeeeeeeeeeeeerrfddf*22222222222222dfmgfdmgggggggggggggfgf*
rekhamf
 
Posts: 33
Joined: Mon Nov 28, 2011 5:09 am
Has thanked: 0 time
Been thanked: 0 time

Re: Reading VB input file ,all the records at same time

Postby gokulNmf » Tue Apr 10, 2012 12:53 pm

hi Rekha,
Let me take the field-1 what you have mentioned as key field.

Regarding the file length:
First the output file size has to be decided before coding the program.

case1:
If the number of records for each key filed is fixed then you can use the resize function in icetool.

case2:
If the number of records for each key field is not fixed (that is unpredictable) then as per your request we can have the maximum possible value as length(i.e., sum on length of the maximum prossible no of records for each key field).
Then you can sort the input file on key fields either asc or desc and at ever break of the key field in the input file you can add all the records read till then and write into the output file.

If the output should also be an VB then used ODO for populating the output fields in the cobol program.

Hope my understanding of your requirement is correct.
Cheers,
Gokul
User avatar
gokulNmf
 
Posts: 118
Joined: Sat Mar 28, 2009 6:41 pm
Location: India
Has thanked: 2 times
Been thanked: 0 time

Re: Reading VB input file ,all the records at same time

Postby rekhamf » Tue Apr 10, 2012 5:43 pm

Hi Gokul,

i can have number of records with same field-1 till 999 .and also each row length is different , though i mentioned VB length as 1132, but in file each row end in column either in 654 , 700 like that ,,So i need to read the first row and get the field-1 value then read second record then get field-1 value then compare,it its same , i need to append the second row in first row at the end
so i need to check like this in code

if first time
move input-data to output-data(1:ws-length ) ,, ws-length is length of each field
if curr-field = prev-field
and not first time
compute ws-length1 = ws-length1 + ws-length
move input-data to output-data(ws-length1)
else
continue ( read the next record)

like this ...
rekhamf
 
Posts: 33
Joined: Mon Nov 28, 2011 5:09 am
Has thanked: 0 time
Been thanked: 0 time

Re: Reading VB input file ,all the records at same time

Postby BillyBoyo » Tue Apr 10, 2012 6:41 pm

So, you have a simple "one behind" processing. The current record tells you whether to write out the stored information or to add to the stored information. Remember that at end-of-file you need to write out the last record.

You store your data in Working-Storage, along the lines that you have mentioned.

To output longer records, you just have to define them appropriately in the FD, nothing special.

To write two records for the accumulated data, set up the key, add the variable-length data. Write. Do it twice, with the second key and data being different.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Reading VB input file ,all the records at same time

Postby rekhamf » Tue Apr 10, 2012 7:05 pm

Hi Bill,
I just showed here the logic how i need to get the data .Can you please give me some sample code reg how i can append the data and the go for next if the key is not matching?
rekhamf
 
Posts: 33
Joined: Mon Nov 28, 2011 5:09 am
Has thanked: 0 time
Been thanked: 0 time

Re: Reading VB input file ,all the records at same time

Postby enrico-sorichetti » Tue Apr 10, 2012 7:42 pm

the application design and/or the requirement description is/are pretty poor
what if the sum of the lengths of the records with the same key is greater than the maximum DM allowed record length ( 32k ) ?
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 3003
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Reading VB input file ,all the records at same time

Postby gokulNmf » Tue Apr 10, 2012 8:08 pm

Hi rekha,
just a small math:
U can have 999 records for a key, and each record at max can be 1136, so the maximum possible output record length will be 1134864.

As enrico mentioned this is more than allowable file length of 32k lrecl, first u need some tech advice for declaring the file as large format dataset.

Below is the sample code as what i told:

step1: sort the file on key field.

step2: at each key-break(cobol pgm)
First Time read:
read the input file
move input record key to Previous-read-Key
move inpuit record to output record

From second time read to end of file:
move input record key key to current-read-key
if Previous-read-Key = current-read-key then
output record = output record + current_record
else
write output record to output file
move key to Previous-read-Key
end
at end of file
write the output record to output file.

Hope this helps you!
Cheers,
Gokul
User avatar
gokulNmf
 
Posts: 118
Joined: Sat Mar 28, 2009 6:41 pm
Location: India
Has thanked: 2 times
Been thanked: 0 time

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post