View previous topic :: View next topic
|
Author |
Message |
Markandeyulu
New User
Joined: 27 May 2010 Posts: 10 Location: Chennai
|
|
|
|
Hi,
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:
Code: |
05 :XXXX PIC X(04).
05 :XXXXX PIC X(20).
05 :Date.
10 : -9SCOMP-DATE-N PIC 9(08).
05 :-TERMINATION-DATE PIC 9(08).
05 :XXXXX PIC X(20).
05 : PRODUCT- COUNT PIC 9(04).
05 :-PRODUCT-ARRAY OCCURS 10 TIMES.
10 :in-PRODUCT-ID PIC X(15).
10 :in-PRODUCT-NAME PIC X(100).
10 :in-PRODUCT-VERSION PIC 9(15).
10 :in-PRODUCT-VENDOR-NAME PIC X(50).
10 :PROGRAM-ARRAY-COUNT PIC 9(04).
10 :PROGRAM-ARRAY OCCURS 10 TIMES.
15 :PROGRAM-ID PIC X(15).
15 :PROGRAM-NAME PIC X(100).
15 :PROGRAM-VERSION PIC 9(15).
15 :PROGRAM-VENDOR-NAME PIC X(50).
05 FILLER PIC X(96).
|
Where as the output file is of length 1100, with the key size of 16 which contains only few fields and its lay out is like:
Code: |
05 :-KEY.
10 : XXXX PIC X(04).
10 : XXXXX PIC X(04).
10 :EFFECTIVE-DATE.
15 : 9SCOMP-EFFECTIVE-DATE-N PIC 9(08).
05 :TERMINATION-DATE PIC 9(08).
05 :out-PRODUCT-ARRAY OCCURS 10 TIMES.
10 :out-PRODUCT-ID PIC X(15).
10 :out-PRODUCT-NAME PIC X(60).
05 FILLER PIC X(326). |
My code logic:
Code: |
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
ELSE
MOVE 11 TO SUB
END-IF
END-PERFORM |
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. |
|
Back to top |
|
|
Markandeyulu
New User
Joined: 27 May 2010 Posts: 10 Location: Chennai
|
|
|
|
This is my first post in the forums. Please let me know if i have missed something.
Thanks in advance. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
this is a technical forum, not a chat room,
Your initial post was edited to get rid of the useless and annoying colors
and to use the code tags |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Quote: |
Code: |
IF PRODUCT-ID(SUB) > SPACES
MOVE in-PRODUCT-ID(SUB) TO out-PRODUCT-ID(SUB) |
|
Is 'PRODUCT-ID' the same as 'in-PRODUCT-ID'?
Have you verified that the three PRODUCT-IDs of the 125th record are actually SPACES or less? And how did you verify that?
What is the recfm, lrecl and blocksize of the input file? |
|
Back to top |
|
|
Markandeyulu
New User
Joined: 27 May 2010 Posts: 10 Location: Chennai
|
|
|
|
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 |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Markandeyulu wrote: |
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. |
Quote: |
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? |
|
Back to top |
|
|
Markandeyulu
New User
Joined: 27 May 2010 Posts: 10 Location: Chennai
|
|
|
|
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. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Some observations:
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. |
|
Back to top |
|
|
Markandeyulu
New User
Joined: 27 May 2010 Posts: 10 Location: Chennai
|
|
|
|
Thank you very much Robert, that really helped me. |
|
Back to top |
|
|
|