View previous topic :: View next topic
|
Author |
Message |
arindambanerjee
New User
Joined: 30 Jun 2007 Posts: 39 Location: India
|
|
|
|
Hi All,
I don't know if this is the right forum to discuss this, because the answer can be through JCL as well. Apologies if it is so.
I have a sequential file, and I need to delete the n the record (n will be any number depending on situation). I need to do all the operations on this file itself. I cannot copy it into a new file and again take a copy into this file. The scenario is same as if I opened the file in edit mode and deleting the nth record.
How can this be done?Please can we discuss about all the possibilities. |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
It can't be done the way you've described. Editing the dataset is the only real option. |
|
Back to top |
|
|
arindambanerjee
New User
Joined: 30 Jun 2007 Posts: 39 Location: India
|
|
|
|
IF this cannot be done at all like that then what are the other options available.
But, my interviewer told me that it can be done. I am confused!!! |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
TSO edit will allow you to make such a change. However, batch programs must copy the file and remove the record that way. The COBOL DELETE statement in the COBOL Language Reference manual says this:
Quote: |
The DELETE statement removes a record from an indexed or relative file |
Note that sequential files are not included.
Interviewers can be wrong, by the way. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Arin,
This most probably isn't what he had in mind, but some PS files are designed to "logically" delete records.
A field in the rec is designated as the delete indicator. If it's set the program ignores it and goes on to the next rec.
At some point in the system the file is copied and the indicated recs are dropped. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
because the answer can be through JCL as well. |
Sorry, but JCL does not delete records - in sequential files or any other. . .
I suspect that there has been a certain lack of communication between you and the interviewer. That or the interviewer does not know that there is no "delete" for a sequential record.
An interviewing technique that is sometimes (unfortunately) used is a "trick" question that is not looking for any technical answer, but rather to see how the applicant handles the trick question. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
I remember that we were able to specify the same file name for SORTIN and SORTOUT when sorting a file (I know - it s/b saved 1st). So it's possible to "delete" recs by OMITting them; don't know if a rec can be "deleted" by identifying its position in the file.
In either case, the file is being re-written. But it lOOks like the rec was deleted.
That's a long way to go to trick an interviewee. |
|
Back to top |
|
|
arindambanerjee
New User
Joined: 30 Jun 2007 Posts: 39 Location: India
|
|
|
|
Actually I was also looking into this, and I came out with a solution. Can you please suggest if this is correct.
Open the file in I/O mode.
Put a counter.
If the counter <>n it will rewrite the record
else it will not.
will it work with the help of COBOL program with this logic? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Code like that can be written and executed, but it will not delete anything. |
|
Back to top |
|
|
arindambanerjee
New User
Joined: 30 Jun 2007 Posts: 39 Location: India
|
|
|
|
Won't it skip that record? I mean when the counter is satisfied it will not rewrite. For the next read again the counter will not be satisfied and it will continue rewriting. Won't it work this way? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
I mean when the counter is satisfied it will not rewrite |
Correct. . . However, bypassing the re-write does not delete the record from the file.
It is still in the file - because there is no way to physically delete a record from a sequential file. . . |
|
Back to top |
|
|
|