View previous topic :: View next topic |
Author |
Message |
Nabanita Das Beginner
Joined: 09 Nov 2005 Posts: 33 Topics: 10
|
Posted: Thu Nov 10, 2005 11:12 pm Post subject: PRocessing difference |
|
|
Can anyone please explain how these 2 logics process differetnly?
Requirement was like following:
First record is a header record . So we need to skip that record and start processing from the next record till the end of the file FILE1
Logic 1:
perform Read-file1
perform untill (sw-eof-file1) or fatal-error
perform read-file1
perform process-para
end-perform
Logic 2:
Perform read-file1 2 times
perform until (sw-eof-file1) or fiatal-error
perform process-para
perform read-file1
end-perform
Please explain as I got different output for the above two logics.
Thanks and Regards,
Nabanita |
|
Back to top |
|
 |
Ravi Beginner
Joined: 27 Jun 2005 Posts: 88 Topics: 2
|
Posted: Thu Nov 10, 2005 11:33 pm Post subject: |
|
|
Nabanita Das,
You need add a IF NOT EOF logic before processing process-para in your logic 1.
logic 2 is fine but probably better to have a eof check before reading 2nd time.
Hope this helps.
Code: |
Logic 1:
---------
perform Read-file1
perform untill (sw-eof-file1) or fatal-error
perform read-file1
if not eof file1 then
perform process-para
end-perform
|
|
|
Back to top |
|
 |
Nabanita Das Beginner
Joined: 09 Nov 2005 Posts: 33 Topics: 10
|
Posted: Fri Nov 11, 2005 12:04 am Post subject: |
|
|
Would you please explain how the logic you suggested is going to make difference? I tried it and it worked fine but I want to understand it more clearly. I may be very dumb ,sorry.
Thanks |
|
Back to top |
|
 |
Phantom Data Mgmt Moderator

Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
Posted: Fri Nov 11, 2005 12:58 am Post subject: |
|
|
Nabanita Das,
As Ravi mentioned, you need to introduce a EOF check before invoking your Process-Para. This is essential because, assume you have only 1 record (the rule applies for 'n' records also. where n > 1).
As per your first logic
1. you have already read the header - outside the loop.
2. End of File is not set now.
3. So, the control gets into the loop and reads the input file again. This time there are no more records and hence EOF if set.
4. But without verifying the EOF condition, you invoke the process-para. But the FD record contains junk value and you do some operation using this junk data. (It might probably be the last record you read successfully - which is the header. So instead of skipping the header you actually process it).
This is true for any number of records. If you have 1 header followed by 4 data records, your EOF is set on the 5th iteration (6th read) but even after the EOF condition Process-para is invoked - once.
Bottomline is, you need to check for EOF condition everytime before you go to the record processing area.
Hope I am clear. Pls let me know if you need more information.
Thanks,
Phantom |
|
Back to top |
|
 |
Nabanita Das Beginner
Joined: 09 Nov 2005 Posts: 33 Topics: 10
|
Posted: Fri Nov 11, 2005 3:24 am Post subject: |
|
|
Thanks, Phantom. This is the kind of explanation I was looking for. |
|
Back to top |
|
 |
|
|