View previous topic :: View next topic
|
Author |
Message |
AjmalMohammed
New User
Joined: 02 Jun 2010 Posts: 10 Location: My Cubicle, Hyderabad, India
|
|
|
|
Hello,
I need to read records from a sequential file which contains headers in the beginning and then the records.
How can i code the FD for such files?
Headers can be in the following way :
Code: |
ANNUAL EMPLOYEE SAL REPORT
-------------------------------------
Emp ID Emp Name Emp Salary Bonus
---------- --------------- -------------- ---------
A10001 John Dorian $4,800.00 15% |
Will 'READ AFTER ADVANCING 4 LINES' work for the above case?
Thank you. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
What happened when you tried.
What else have you tried, what were the results. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
There is a link to manuals at the top of the page. I recommend you click on it, find the COBOL Language Reference and Programming Guide manuals, and read them. Pay particular attention to the statement(s) which allow AFTER ADVANCING -- or you can do a search (use the flashlight at the top of the page) to make it easier. |
|
Back to top |
|
|
AjmalMohammed
New User
Joined: 02 Jun 2010 Posts: 10 Location: My Cubicle, Hyderabad, India
|
|
|
|
Rookie mistake. After advancing is not allowed for a read statement. Thank you. |
|
Back to top |
|
|
picus_mf Warnings : 1 New User
Joined: 09 Jun 2006 Posts: 52
|
|
|
|
You can have a IF statement with reference modification like below if your header does not start from 1st byte.
IF REC(1:1) = SPACE
then go to read-next-record |
|
Back to top |
|
|
Ketan Varhade
Active User
Joined: 29 Jun 2009 Posts: 197 Location: Mumbai
|
|
|
|
Hi,
read the file with the maximum LREC, you can remove the header part using the SORt utilities such as DF sort and Syncsort, if the header has fixed format, You can also do this is the SRC code, but the constrain is that the header declaration should have a fixed format,
I hope this help |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
There is no good reason to make an extra pass of the file to remove some of the records. . .
The only reason to make such a suggestion is because one is selling hardware. |
|
Back to top |
|
|
Pons
New User
Joined: 25 May 2007 Posts: 61 Location: Coimbatore
|
|
|
|
I don't have an experience with advancing statement. But i have two suggestions.
1. Using sort in JCL we can skip the first 4 lines (Header) and copy to the another PS and use that one in the program.
2. Initial itself do an FOR loop four times and read the file, from the 5th record onwards do your process....
Not sure this is the correct way. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Using sort in JCL we can skip the first 4 lines (Header) and copy to the another PS and use that one in the program. |
Sorry, but NO. . .
To repeat:
Quote: |
There is no good reason to make an extra pass of the file to remove some of the records. . . |
Why would it be appropriate to completely copy the entire file so that some records can be "skipped". . . That is complete nonsense.
This is a "how to do this in cobol" question (answer, bypass the unwanted records).
It is not a question about how many system resources can be wasted. . . |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
After you open the file, why not just do 4 READ statements to get past the header? That's what I would do -- documenting why the extra READ statements are in the code, of course. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
or if the headers repeat:
Code: |
ANNUAL EMPLOYEE SAL REPORT
-------------------------------------
Emp ID Emp Name Emp Salary Bonus
---------- --------------- -------------- ---------
A10001 John Dorian $4,800.00 15%
|
either multiply redefine your input record work-area
or use reference modification:
Code: |
read-a-record
IF input-file-status = '00'
then
IF input-record-work-area(1:10) = spaces
or
input-record-work-area(3:6) = 'Emp ID'
or
input-record-work-area(2:6) = '------'
then
go to read-a-record
else
perform process-record
go to read-a-record
end-if
end-if |
|
|
Back to top |
|
|
AjmalMohammed
New User
Joined: 02 Jun 2010 Posts: 10 Location: My Cubicle, Hyderabad, India
|
|
|
|
Hello,
Thank you to everyone for the replies.
Mr. Dick Brenholtz and Mr. Robert, that was how i originally intended to do it but then my code would become very requirement specific. I am looking for a more generalized solution. I remember reading something about doing so when i was browsing through the forum a few days back, tried searching but have been unsuccessful so far. But thank you anyway. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
If you want a "generalized" solution, you must define the generalized rules. . .
There has not yet been a "generalized solution" that will "do what i meant".
Suggest you pay close attention to this from Robert's signature:
Quote: |
The first rule of code reuse is that the code needs to be worth re-using. |
Trying to implement several requirements with generic code may lead to more time required than simply writing the code once and cloning it for other requirements. This also means less impact of there needs to be a change to the common code or if some of the requirements "grow" to more than a generic solution.
And no matter which direction you choose - there is still no good reason to copy the entire file to "skip" the headers. . . |
|
Back to top |
|
|
AjmalMohammed
New User
Joined: 02 Jun 2010 Posts: 10 Location: My Cubicle, Hyderabad, India
|
|
|
|
Thank you Mr. Dick Scherrer, i'll keep that in mind. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
You're welcome - good luck
d |
|
Back to top |
|
|
sriraj1122
New User
Joined: 18 Dec 2008 Posts: 15 Location: Hyderabad
|
|
|
|
probably you can do in this way.
Read the first record and if the record is read succsefully then set a counter variable to 1 and in the successive reads increment counter.
So if the counter > 4 then go to the logic u want to perform. otherwise proceed with the next read. Hope this wld help. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
A generic solution, in general, takes 5 to 10 times longer than the specific solution and hence costs proportionally more. Unless there is a really good reason to have generic code (such as your company selling the software to multiple locations), it is rarely worth the additional cost. Coding up the READ statement and copying it three times would take, maybe, 2 minutes. If the header count changes later, the time to add (or remove) READ statements will again be on the order of minutes. Recouping just the cost of the time you've worried about a generic solution would probably require a couple hundred changes already -- and you haven't even coded a single line of "generic" code. |
|
Back to top |
|
|
|