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

Need to delete all records of the PS file


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

Active User


Joined: 14 Sep 2009
Posts: 184
Location: Coimbatore

PostPosted: Thu Mar 21, 2013 11:15 am
Reply with quote

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

Active Member


Joined: 06 Sep 2007
Posts: 792
Location: Chennai, India

PostPosted: Thu Mar 21, 2013 11:20 am
Reply with quote

The better way would be, Delete and Re-create the file.

Possibly, I'm missing something?
Back to top
View user's profile Send private message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 184
Location: Coimbatore

PostPosted: Thu Mar 21, 2013 11:37 am
Reply with quote

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

Active Member


Joined: 06 Sep 2007
Posts: 792
Location: Chennai, India

PostPosted: Thu Mar 21, 2013 11:48 am
Reply with quote

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

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Thu Mar 21, 2013 11:53 am
Reply with quote

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

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Thu Mar 21, 2013 12:07 pm
Reply with quote

Through JCL use a copy with DUMMY file and have DISP=OLD for output
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Thu Mar 21, 2013 12:16 pm
Reply with quote

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!? icon_smile.gif
Back to top
View user's profile Send private message
Gnanas N

Active Member


Joined: 06 Sep 2007
Posts: 792
Location: Chennai, India

PostPosted: Thu Mar 21, 2013 12:24 pm
Reply with quote

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!? icon_smile.gif

WRITE(s) can be done after an OPEN OUTPUT, in this case, No?
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Thu Mar 21, 2013 4:00 pm
Reply with quote

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!? icon_smile.gif

Then the statement "I need to delete all the records in a PS file" is wrong.
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: Thu Mar 21, 2013 5:13 pm
Reply with quote

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

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Thu Mar 21, 2013 6:35 pm
Reply with quote

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!? icon_smile.gif

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

Global Moderator


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

PostPosted: Thu Mar 21, 2013 6:41 pm
Reply with quote

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! icon_biggrin.gif
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Thu Mar 21, 2013 6:52 pm
Reply with quote

LOL - as Ed enquired in another thread, "What's in the briefcase?" And the answer was, " "The Requirement".
Back to top
View user's profile Send private message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 184
Location: Coimbatore

PostPosted: Thu Mar 21, 2013 7:44 pm
Reply with quote

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

Global Moderator


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

PostPosted: Thu Mar 21, 2013 8:18 pm
Reply with quote

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
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 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 DELETE SPUFI DB2 1
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
Search our Forums:

Back to Top