IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Read sequential file ignoring headers


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
AjmalMohammed

New User


Joined: 02 Jun 2010
Posts: 10
Location: My Cubicle, Hyderabad, India

PostPosted: Tue Jun 22, 2010 3:36 pm
Reply with quote

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
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Tue Jun 22, 2010 3:47 pm
Reply with quote

What happened when you tried.

What else have you tried, what were the results.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Jun 22, 2010 3:50 pm
Reply with quote

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
View user's profile Send private message
AjmalMohammed

New User


Joined: 02 Jun 2010
Posts: 10
Location: My Cubicle, Hyderabad, India

PostPosted: Tue Jun 22, 2010 4:09 pm
Reply with quote

Rookie mistake. After advancing is not allowed for a read statement. Thank you.
Back to top
View user's profile Send private message
picus_mf
Warnings : 1

New User


Joined: 09 Jun 2006
Posts: 52

PostPosted: Tue Jun 22, 2010 4:48 pm
Reply with quote

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
View user's profile Send private message
Ketan Varhade

Active User


Joined: 29 Jun 2009
Posts: 197
Location: Mumbai

PostPosted: Tue Jun 22, 2010 4:51 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Jun 22, 2010 8:51 pm
Reply with quote

Hello,

There is no good reason to make an extra pass of the file to remove some of the records. . . icon_sad.gif

The only reason to make such a suggestion is because one is selling hardware.
Back to top
View user's profile Send private message
Pons

New User


Joined: 25 May 2007
Posts: 61
Location: Coimbatore

PostPosted: Wed Jun 23, 2010 12:27 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Jun 23, 2010 12:56 am
Reply with quote

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. . . icon_sad.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Jun 23, 2010 1:09 am
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jun 23, 2010 2:41 am
Reply with quote

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
View user's profile Send private message
AjmalMohammed

New User


Joined: 02 Jun 2010
Posts: 10
Location: My Cubicle, Hyderabad, India

PostPosted: Thu Jun 24, 2010 12:14 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Jun 24, 2010 7:49 pm
Reply with quote

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
View user's profile Send private message
AjmalMohammed

New User


Joined: 02 Jun 2010
Posts: 10
Location: My Cubicle, Hyderabad, India

PostPosted: Fri Jun 25, 2010 11:54 am
Reply with quote

Thank you Mr. Dick Scherrer, i'll keep that in mind.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Jun 25, 2010 7:23 pm
Reply with quote

You're welcome - good luck icon_smile.gif

d
Back to top
View user's profile Send private message
sriraj1122

New User


Joined: 18 Dec 2008
Posts: 15
Location: Hyderabad

PostPosted: Sat Jun 26, 2010 5:10 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Sat Jun 26, 2010 7:25 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Error to read log with rexx CLIST & REXX 11
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top