When we are testing a COBOL code, we came thru an unexpected result, which driven us to the confusion. The problem is in a simple COBOL logic which reformats the input file accordingly and writes the required fields to the output file.
The input file is of length 20000, which contains 10 occurrences of Product information. And each product has 10 occurrences of program information. The layout will be like:
PERFORM UNTIL SUB > 10
IF PRODUCT-ID(SUB) > SPACES
MOVE in-PRODUCT-ID(SUB) TO out-PRODUCT-ID(SUB)
MOVE in-PRODUCT-NAME(SUB) TO out-PRODUCT-NAME(SUB)
ADD 1 TO SUB
MOVE 11 TO SUB
Now the problem is:
In the input file which has about 3000 records, one record (assume it to be the 1st record) have 3 product occurrences (Let us assume them as 141, 142, 143) and rest of the records got only 1 product occurrence say 140.
When we ran the job, every 125th record came as the problematic record. (I.e. even though the record got only one product, in the output it shoots 3 products. There is no problem with the first product occurrence. it is same as that in the input file, but the second and third products are taking the same secondd and third occurrence as of the first record.)
After including the INITIALIZE step before the perform statement, the problem was solved. But I didn’t understand one thing: If the problem is with the initialization, why only every 125th record is problematic, why not all the records.
Please let me know if I am not clear and do me the needful.
Sorry, I missed to edit the code perfectly before submitting the query.
Yes, the 'PRODUCT-ID' and the 'in-PRODUCT-ID' are same, i forgot to edit it in the first line.
The first product-id of the 125th record is not space, whereas the second and third product-ids are spaces, I verified that by opening the file in the file manager. The problem is every 125th output record i.e.(125th, 250th, 375th, 500th...) are the problematic records.
when i debugged the logic, I observed that the values in every 125th output records are not initialized. They are displayed with the first records 3 products before writing. So when it is checking the logic, the first product-id is not spaces so it is writing the first product correctly. and the second product-id is spaces so it is coming out of the loop. But as i mentioned that the values in every 125th record are not initialized they are displaying the same 2nd and 3rd products of the first record.
The RECFM is FB, LRECL is 20000, and BLKSIZE is 20000 for the input file
The RECFM is FB, LRECL is 1100, and BLKSIZE is 27500 for the output file
Joined: 18 Jul 2007 Posts: 2150 Location: At my coffee table
The first product-id of the 125th record is not space, whereas the second and third product-ids are spaces, I verified that by opening the file in the file manager.
when i debugged the logic, I observed that the values in every 125th output records are not initialized. They are displayed with the first records 3 products before writing.....
But as i mentioned that the values in every 125th record are not initialized they are displaying the same 2nd and 3rd products of the first record.
How do you explain these opposite statements?
Or does the first refer to input and the second refer to your output?
Or are you saying that the input (every 125th record) is bad? Shouldn't the solution be in the program that created that input?
What i tried to say is:
In the input file, the 125th record has only one product occurrence.
But the same record in the output file is displayed with three product occurrences.
The input file doesn't have any problem, I hope there is no problem with the program that creates input file, but i will check that program again will let u know regarding this. Thanks for your suggestion.
Joined: 06 Jun 2008 Posts: 8165 Location: East Dubuque, Illinois, USA
1. you have 25 records per block and the default for QSAM is 5 buffers per file -- which is 125 records before you start reusing buffers. Off-topic note: adding buffers will usually speed up the program (frequently cutting elapsed run times by 75%).
2. although you did not include the READ statement, I expect that your code is NOT doing a READ INTO, just a READ.
3. why are you using the IF statement to move the occurrences? Working in the buffers, you need to move ALL 10 occurrences to get rid of any data in the buffers from the last record in the buffer at that location.