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
 

 

Delete all the records in a VSAM file in Cobol pgm

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL & VSAM
View previous topic :: :: View next topic  
Author Message
annujp

New User


Joined: 31 Aug 2005
Posts: 39
Location: St Paul,MN

PostPosted: Thu Oct 11, 2007 12:40 am    Post subject: Delete all the records in a VSAM file in Cobol pgm
Reply with quote

Hi

My requirement is;for a particular run of the program (characterised by a specific month) i need a vsam file that is used in the program to be flushed of all the data. The file is a yearly file so at the start of the year i need to start with a fresh file. I want to do this in the cobol pgm.

I used the following code
IF MONTH = '02'
OPEN OUTPUT VSAM-FILE
CLOSE VSAM-FILE
END-IF

The logic behind writing this is when you open a file in output mode and close it immediately, all the records in the file are deleted.
But here i get a VSAM Status code of '37' for the OPEN Output(wrong mode of opening) and a status code '42' for the CLOSE (closing a file that is not open). My JCL has a DISP=SHR for this VSAM file.

Is there anyway i can do this in a cobol program?
I need to delete all the records in a vsam file. Also what should be the disp parameter i should give in my JCL?

Anitha
Back to top
View user's profile Send private message

dick scherrer

Site Director


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

PostPosted: Thu Oct 11, 2007 1:08 am    Post subject:
Reply with quote

Hello,

Rather than COBOL, you might just do an IDCAMS DELETE/DEFINE as the first job of a new year's processing.

You may need to read the records in order to delete them in a program (i'm not certain on this one - never tried to do it), but delete/define works rather quickly an dwe use it frequently.
Back to top
View user's profile Send private message
annujp

New User


Joined: 31 Aug 2005
Posts: 39
Location: St Paul,MN

PostPosted: Thu Oct 11, 2007 2:50 am    Post subject:
Reply with quote

Hi
My issue is that i want to use the same JCL throughout the year. If i were to do an IDCAMS repro for the new year processing, then i would have to use a separate JCL for that, right?
Is there any way to check for the current month (or date) in a JCL and execute a step accordingly?

I checked with reading a VSAM opened in I-O mode and then closing it, it does not delete the records in the file.

Thanks
Anitha
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Thu Oct 11, 2007 3:00 am    Post subject:
Reply with quote

Hello,

You could do it all in one jcl - add a step that runs first that sets a contition code for the first run of the year and test the condition code in the idcams step and then continue with the run.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Thu Oct 11, 2007 3:06 am    Post subject:
Reply with quote

Programmaticly, a second select/fd/DD could be used, couldn't it? The VSAM file might need a REUSE parm....You are closer to a manual than I am, look it up....
Back to top
View user's profile Send private message
annujp

New User


Joined: 31 Aug 2005
Posts: 39
Location: St Paul,MN

PostPosted: Thu Oct 11, 2007 3:09 am    Post subject:
Reply with quote

Yeah i am trying to do that. But the step that will run just once a year has to be determined by the date(say month = 01). How do i get the step to run when the month = 01?
I searched the forums and came up with this
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/IEA1E241/2.2.2
I tried using it in my JCL like this

Code:

//  IF &MON EQ 1                                                     
//  THEN                                                               
//step  EXEC PGM=IDCAMS                                             
//INDD1  DD DSN=input dataset,disp=shr             
//OUTDD1   DD DSN=output vsam,DISP=SHR           
//SYSIN     DD DSN=parm dataset(repro),DISP=SHR                                           
//  ENDIF                                                             
//*


But i got a JCL error
Code:
4 IEFC016I ERROR IN IF STATEMENT


I am sorry to keep repeating the same thing over and over again.

Thanks
Anitha
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Thu Oct 11, 2007 3:19 am    Post subject:
Reply with quote

Flying a bit blind, but either some sort of JCL "optional" for the output DD or a additional step prior that opens the file for output on the selected date....you can't shr the output DD, can you?
Then again, there is dynamic allocation from the cobol batch program on the needed date.....
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Thu Oct 11, 2007 3:57 am    Post subject:
Reply with quote

Hello,

Quote:
I am sorry to keep repeating the same thing over and over again.
Not to worry icon_smile.gif

How did you choose &MON? This link is to the JCL manual available via "Manuals" at the top of the page:
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/iea2b650/17.1.4.5?SHELF=&DT=20040712170508&CASE= &MON does not appear to be in the list of valid keywords.

If you use a small bit of COBOL code as your first step, it can check the date internally (no need even for a pram) and set a RETURN-CODE accordingly. It appears you already have everything but this one bit of code to do what you need.

Let us know if anything needs clarification.
Back to top
View user's profile Send private message
annujp

New User


Joined: 31 Aug 2005
Posts: 39
Location: St Paul,MN

PostPosted: Thu Oct 11, 2007 4:19 am    Post subject:
Reply with quote

Thanks a lot for the prompt replies.
So the best approach would be to write a small cobol program that will check for the current date. If the current date satisfies the condition for flushing the data, i will set a specific return code.
In the JCL, i will execute the IDCAMS step to repro a blank file only if it is the desired return code.

To do this i use the following piece of code,right?

Code:
MOVE 99 TO RETURN-CODE

Thanks
Anitha
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Thu Oct 11, 2007 4:22 am    Post subject:
Reply with quote

Sounds like a plan...
Good thinking....
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Thu Oct 11, 2007 6:07 am    Post subject:
Reply with quote

Hello,

Quote:
To do this i use the following piece of code,right?
Yup, that should do what you need.

I'd suggest creating a copy of the data in this vsam file before running this job (whether it empties the file or just is a "regular" run).
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Sat Oct 13, 2007 5:28 pm    Post subject:
Reply with quote

So why do you want to waste resource on writing a program that will probably use much more resource deleting records individually than by using the very utility IDCAMS to do the same thing in a fraction of the time.

If your shop uses a scheduling package you can set up for the IDCAMS step to be included automatically on the date that you want it to be included in.

Dare I ask who's idea it was to do this programatically rather than easily ?
Back to top
View user's profile Send private message
annujp

New User


Joined: 31 Aug 2005
Posts: 39
Location: St Paul,MN

PostPosted: Sun Oct 14, 2007 5:54 am    Post subject:
Reply with quote

expat wrote:
So why do you want to waste resource on writing a program that will probably use much more resource deleting records individually than by using the very utility IDCAMS to do the same thing in a fraction of the time.

If your shop uses a scheduling package you can set up for the IDCAMS step to be included automatically on the date that you want it to be included in.

Dare I ask who's idea it was to do this programatically rather than easily ?


The conclusion was not to write a cobol program to delete the records but to write a program which will set a particular return code. There will be a check in the program say

IF WS-MONTH = '01'
MOVE '99' TO RETURN-CODE
END-IF.

The variable WS-MONTH is populated by extracting the current date in the program.

In the job that is scheduled to run monthly, this program will be the first step executed. There will be an IF condition after this checking if the return code of the program step is 99. If the return code is 99, the IDCAMS step to delete and define is executed.

This was the best approach because we did not want to schedule a separate job to run only once a year which will delete and define the VSAM file.

Expat, please advise if you think there is a better approach to this issue.

Thanks
Anitha
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Sun Oct 14, 2007 7:01 am    Post subject:
Reply with quote

Hello Anitha,

Just a reminder - it would be good to backup the file icon_smile.gif
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Sun Oct 14, 2007 10:46 pm    Post subject:
Reply with quote

So how long does it take to schedule one job ? 10 minutes max ?

How long to code and test the program. How long will it take to delete perhaps millions of records ? IDCAMS will take seconds with no development or maintenance overheads. What if the requirement changes ? then it's back to the program again.

All I'm asking is why you do not want to follow the easiest option for efficiency ?
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Sun Oct 14, 2007 10:57 pm    Post subject:
Reply with quote

Hi Expat,

Quote:
How long will it take to delete perhaps millions of records
Not an issue. . . There is no plan to delete the data in code (never has been from my end).

The use of COBOL is to check the date and set RETURN-CODE accordingly.

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

New User


Joined: 31 Aug 2005
Posts: 39
Location: St Paul,MN

PostPosted: Mon Oct 15, 2007 3:09 am    Post subject:
Reply with quote

Yeah thats wat i plan to do.
I dont delete any records in the cobol program. All the program does is to set the return code after checking for the month part of the current date. Based on the return code the steps to delete and define the VSAM using IDCAMS is run.

Dick, as per your suggestion i will be doing a backup of the VSAM file before the delete and define.

Thanks
Anitha
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Mon Oct 15, 2007 4:12 am    Post subject:
Reply with quote

You're welcome icon_smile.gif

We're here if there are questions.
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 -> JCL & VSAM All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Removing Duplicates based on certain ... chandracdac DFSORT/ICETOOL 4 Fri Dec 09, 2016 4:40 am
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


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