View previous topic :: View next topic
|
Author |
Message |
abdulrafi
Active User
Joined: 14 Sep 2009 Posts: 184 Location: Coimbatore
|
|
|
|
Hi,
I need a help. I need to delete all the records in a PS file. This needs to be done once in a day. The PS file has a header record which has the date field. So I am able to compare that date with that of the current date. But am not sure how to delete all rows of the file and make it afresh. Can I know if this could be done by anyway automatically in JCL or COBOL?
Thanks
Abdul Rafi |
|
Back to top |
|
|
Gnanas N
Active Member
Joined: 06 Sep 2007 Posts: 792 Location: Chennai, India
|
|
|
|
The better way would be, Delete and Re-create the file.
Possibly, I'm missing something? |
|
Back to top |
|
|
abdulrafi
Active User
Joined: 14 Sep 2009 Posts: 184 Location: Coimbatore
|
|
|
|
I cannot do that because the logic is inside the program to refresh the file. i need to refresh teh file based upon a condition. |
|
Back to top |
|
|
Gnanas N
Active Member
Joined: 06 Sep 2007 Posts: 792 Location: Chennai, India
|
|
|
|
I guess, if you use DISP=OLD or SHR for that file in JCL and OPEN the file in OUTPUT mode in the program, all the records will be deleted.
And, not sure if this is a good approach here. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
abdulrafi wrote: |
I need a help. I need to delete all the records in a PS file. ...Can I know if this could be done by anyway automatically in JCL or COBOL? |
Your post is in COBOL part of the Forum, so let's talk about COBOL first.
PS, a loosely used name for QSAM files, does not have anything as such from COBOL per se that you can delete record from it. Which means if you're thinking of something like "DELETE ws-record", that won't work with COBOL for a sequential file (PS). Perhaps you can mark them with some 'indicator' so that program treat them as deleted but a 'physical delete' is not possible. (And it is not feasible to update records in an unordered Sequential file. Okay, I've not verified it, so I might need a correction here.)
You also used the word JCL, so are you looking forward to a "utility driven solution" as well? |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Through JCL use a copy with DUMMY file and have DISP=OLD for output |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Gnanas N wrote: |
I guess, if you use DISP=OLD or SHR for that file in JCL and OPEN the file in OUTPUT mode in the program, all the records will be deleted. |
Yes, if you don't issue a WRITE and close it after an OPEN OUTPUT. But what if next time you need data in the file!? |
|
Back to top |
|
|
Gnanas N
Active Member
Joined: 06 Sep 2007 Posts: 792 Location: Chennai, India
|
|
|
|
Hi Anuj,
Anuj Dhawan wrote: |
Gnanas N wrote: |
I guess, if you use DISP=OLD or SHR for that file in JCL and OPEN the file in OUTPUT mode in the program, all the records will be deleted. |
Yes, if you don't issue a WRITE and close it after an OPEN OUTPUT. But what if next time you need data in the file!? |
WRITE(s) can be done after an OPEN OUTPUT, in this case, No? |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
Anuj Dhawan wrote: |
Gnanas N wrote: |
I guess, if you use DISP=OLD or SHR for that file in JCL and OPEN the file in OUTPUT mode in the program, all the records will be deleted. |
Yes, if you don't issue a WRITE and close it after an OPEN OUTPUT. But what if next time you need data in the file!? |
Then the statement "I need to delete all the records in a PS file" is wrong. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
But am not sure how to delete all rows of the file and make it afresh. |
What you ask for in your post cannot be done. It cannot be done because FILES DO NOT HAVE ROWS. They have records. Data bases have rows, but a file is not a data base and a data base is not a file.
Assuming you need to keep the header record, the logic in COBOL is not hard:
Code: |
Use DISP=OLD in your JCL for the file
Open the file for input
Read the first record into WORKING-STORAGE
If the file is to be cleared
Close the file
Open the file for output
Write the header record from WORKING-STORAGE
Close the file (or write other records, then close the file)
Endif
|
|
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Akatsukami wrote: |
Anuj Dhawan wrote: |
Gnanas N wrote: |
I guess, if you use DISP=OLD or SHR for that file in JCL and OPEN the file in OUTPUT mode in the program, all the records will be deleted. |
Yes, if you don't issue a WRITE and close it after an OPEN OUTPUT. But what if next time you need data in the file!? |
Then the statement "I need to delete all the records in a PS file" is wrong. |
In fact, deleting data from QSAM file, as a requirement itself, is questionable (wrong).
Possibly, one can write a new file with required records, but deleting - where did the idea coin from? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
Possibly, one can write a new file with required records, but deleting - where did the idea coin from? |
Anuj, you know that is the requirement! |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
LOL - as Ed enquired in another thread, "What's in the briefcase?" And the answer was, " "The Requirement". |
|
Back to top |
|
|
abdulrafi
Active User
Joined: 14 Sep 2009 Posts: 184 Location: Coimbatore
|
|
|
|
Hi Robert,
You can given me a code logic. Also you have mentioned that it keeps the header record, but i do not need anything to be present in the file. Even if i move spaces into the file, it means that there is atleast one record which has spaces in it.
My requirement was to delete all the records in the file so that when i read the file it has to show me EOF(end-of-file). |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
Open the file for output with DISP=OLD specified in the JCL.
Close the file.
All records previously in the file will be gone. |
|
Back to top |
|
|
|