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

Delete all the records in a VSAM file in Cobol pgm


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
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
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

Moderator Emeritus


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

PostPosted: Thu Oct 11, 2007 1:08 am
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
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

Moderator Emeritus


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

PostPosted: Thu Oct 11, 2007 3:00 am
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: 3156
Location: Tucson AZ

PostPosted: Thu Oct 11, 2007 3:06 am
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
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: 2146
Location: At my coffee table

PostPosted: Thu Oct 11, 2007 3:19 am
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

Moderator Emeritus


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

PostPosted: Thu Oct 11, 2007 3:57 am
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
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: 2146
Location: At my coffee table

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

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

Moderator Emeritus


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

PostPosted: Thu Oct 11, 2007 6:07 am
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: 8797
Location: Welsh Wales

PostPosted: Sat Oct 13, 2007 5:28 pm
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
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

Moderator Emeritus


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

PostPosted: Sun Oct 14, 2007 7:01 am
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: 8797
Location: Welsh Wales

PostPosted: Sun Oct 14, 2007 10:46 pm
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

Moderator Emeritus


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

PostPosted: Sun Oct 14, 2007 10:57 pm
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
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

Moderator Emeritus


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

PostPosted: Mon Oct 15, 2007 4:12 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 1
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts DELETE SPUFI DB2 1
Search our Forums:

Back to Top