Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Need to delete all records of the PS file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Thu Mar 21, 2013 11:15 am    Post subject: Need to delete all records of the PS file
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: 785
Location: Chennai, India

PostPosted: Thu Mar 21, 2013 11:20 am    Post subject:
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: 135
Location: Coimbatore

PostPosted: Thu Mar 21, 2013 11:37 am    Post subject:
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: 785
Location: Chennai, India

PostPosted: Thu Mar 21, 2013 11:48 am    Post subject:
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

Senior Member


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

PostPosted: Thu Mar 21, 2013 11:53 am    Post subject: Re: Need to delete all records of the PS file
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

Moderator


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

PostPosted: Thu Mar 21, 2013 12:07 pm    Post subject:
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

Senior Member


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

PostPosted: Thu Mar 21, 2013 12:16 pm    Post subject:
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: 785
Location: Chennai, India

PostPosted: Thu Mar 21, 2013 12:24 pm    Post subject:
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: 1738
Location: Bloomington, IL

PostPosted: Thu Mar 21, 2013 4:00 pm    Post subject:
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: 7904
Location: Bellevue, IA

PostPosted: Thu Mar 21, 2013 5:13 pm    Post subject:
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

Senior Member


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

PostPosted: Thu Mar 21, 2013 6:35 pm    Post subject:
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: 7904
Location: Bellevue, IA

PostPosted: Thu Mar 21, 2013 6:41 pm    Post subject:
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

Senior Member


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

PostPosted: Thu Mar 21, 2013 6:52 pm    Post subject:
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: 135
Location: Coimbatore

PostPosted: Thu Mar 21, 2013 7:44 pm    Post subject:
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: 7904
Location: Bellevue, IA

PostPosted: Thu Mar 21, 2013 8:18 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts JCL to delete component in a package sundaram.naveen Compuware & Other Tools 14 Tue Nov 29, 2016 6:21 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us