[IDCAMS ? ] Copy from dataset only if target empty

In this Mainframe Forum - You can post your queries on JCL, OS/390 JCL, MVS JCL, z/OS JCL, JES2 & JES3

Moderators: Frank Yaeger, DikDude, Moderator Group

User avatar
strahd
Member
Posts: 11
Joined: Tue Nov 22, 2011 2:26 pm
Location: Italy

[IDCAMS ? ] Copy from dataset only if target empty

Post by strahd » Fri Dec 09, 2011 12:58 pm

Hello!
I need to prepare a JCL step that copy a dataset into a new dataset but ONLY if this new dataset not already exist.

So I thinking about something like that:

Code: Select all

//COPYDS   EXEC  PGM=IDCAMS                              
//*                                                      
//SORTIN   DD DSN=source,DISP=SHR           
//*                                                      
//SORTOUT  DD DSN=dest,DISP=(MOD,CATLG), 
//           SPACE=(CYL,(1,1),RLSE)                      
//                                                      
//SYSOUT   DD SYSOUT=*                                   
//SYSPRINT DD SYSOUT=*                                   
//SYSIN    DD *                                          
   PRINT INDATASET(dest) -               
         DUMP  COUNT(001)                                
   IF LASTCC > 00   THEN -                               
     IF LASTCC < 13 THEN DO                              
       SET MAXCC=0                                       
       REPRO INFILE&#40;SORTIN&#41; -                            
          OUTFILE&#40;SORTOUT&#41;               
     END                                                 
/*                                                       
Using OUTFILE I receave an error in open method
If I use OUTDASET instead I receave an erro because the dataset in not allocated...

So my questions are:
1) Is There better way to know if dataset exist and not empty?
2) How I can use DD statement with IDCAMS?
3) Is IDCAMS the right program?

Thank's!!

Bye
Domenico L.

Counting postage stamps' teeth [F.D.A.]

DikDude
Moderator
Posts: 1001
Joined: Fri Jul 22, 2011 8:39 am
Location: usa

Post by DikDude » Sat Dec 10, 2011 12:17 pm

You mention 2 completely different situations (exists and is empty or does not exist).

There would be different ways to do what you want depending on the actual situation. Or are there maybe even more variables?
Last edited by DikDude on Sun Dec 11, 2011 10:28 am, edited 1 time in total.
Have a good one

User avatar
strahd
Member
Posts: 11
Joined: Tue Nov 22, 2011 2:26 pm
Location: Italy

Post by strahd » Sun Dec 11, 2011 5:54 am

Hi Dikduke,

well, at this moment the situation is that the dataset does not exist.

I looking for a solution for an empty dataset because if I use the MOD disposition to make the test the dataset will be created :D
Domenico L.

Counting postage stamps' teeth [F.D.A.]

DikDude
Moderator
Posts: 1001
Joined: Fri Jul 22, 2011 8:39 am
Location: usa

Post by DikDude » Sun Dec 11, 2011 10:38 am

Which sounds like the "copy a dataset into a new dataset but ONLY if this new dataset not already exist. " condition (which i did not properly mention earlier. . . )

I believe i need more complete info about what is desired. If the "output" dataset already exists, why not simpy delete it and write a new file with only the current data? Keep in mind that there is no business requirement to get this all into one step. You could use mod,delete to unconditionallly make sure the target does not exist, then copy the new data into a new dataset.

I believe what is actuallly needed can be rather straightforward, but i don't believe i understand exactly what this is yet.

Maybe it will help if you post why the different conditions might exist and why a particular action should be taken for each.
Have a good one

User avatar
strahd
Member
Posts: 11
Joined: Tue Nov 22, 2011 2:26 pm
Location: Italy

Post by strahd » Sun Dec 11, 2011 6:06 pm

No, I can't replace the output dataset.

The last day of the month I need to copy a gdg dataset, generated by another application, (calling for examples ANAG) and copy into our dataset.

For examples ANAG(0) -> my.anag.d201111

Ok, this is easy to do.

But I've many dataset to copy from different applications (and different competence center!), and when I release the jcl will be the Operators team to manage any possible abends.
Even abends genereted from successors jcl of this one.

So, I would write a jcl that can be re-executed from the operator without problem about existing dataset.

The complete scenario is more complex but for now it's enough for me understand how verify the "not exists" condition. :)

Bye
Domenico L.

Counting postage stamps' teeth [F.D.A.]

DikDude
Moderator
Posts: 1001
Joined: Fri Jul 22, 2011 8:39 am
Location: usa

Post by DikDude » Mon Dec 12, 2011 9:46 am

No, I can't replace the output dataset.
So far this has not been explained. . .
So, I would write a jcl that can be re-executed from the operator without problem about existing dataset.
A concern i have is that this is exactly what will happen
The complete scenario is more complex but for now it's enough for me understand how verify the "not exists" condition.
I believe this may cause more long-term issues than dealing with the entire requirement up front. You have decided on a course of action and want to pursue this ignoring alternatives that may be more suitable.

To determine if a data set exists (rather than is empty) just run an idcams listcat and look at the output. If you have someone available who knows rexx, you can do something similar using rexx.
Last edited by DikDude on Tue Dec 13, 2011 1:28 am, edited 1 time in total.
Have a good one

User avatar
strahd
Member
Posts: 11
Joined: Tue Nov 22, 2011 2:26 pm
Location: Italy

Post by strahd » Mon Dec 12, 2011 1:11 pm

Thank's for the reply.

Well, the Competence Center called ANAG create each day a GDG dataset called ANAG.RT

My competence center the last day of the month must duplicate this dataset in own dataset called FG.ANAGRT.D%YYYYMM.

Often my Comptence's montly plan ended 2 o 3 day after the last day of the month.

If the jcl was re-executed (for any reason) the first or second day (of the new month) the own previously dataset will be replaced with a new verision and we absolutly don't want that.

An examples:

2011-10-31: journal app ANAG generate ANAG.RT(+1) referred to 2011-10-31
2011-10-31: montly app FG copy ANAG.RT(0) into FG.ANAGRT.D201110 referred to 2011-10-31
2011-11-01: journal app ANAG generate ANAG.RT(+1) referred to 2011-11-01
2011-11-02: journal app ANAG generate ANAG.RT(+1) referred to 2011-11-02
2011-11-02: montly app FG (re-executed for some reason) copy ANAG.RT(0) into FG.ANAGRT.D201110 referred to to 2011-11-02

I'd like to prevent this situation; I wish to create a jcl which can do something like that:

2011-11-02: montly app FG (re-executed for some reason) if FG.ANAGRT.D201110 not exist then copy....

I know that this way is not the best solution, but is a good approximation.
It's nice to have a jcl which can search into GDG dataset looking for the right version (refferred to the last day of the month), but I suppose this is too hard to write, especially for me....

Unfourtunatly I can't use rexx due to internal policy.... :-(

Bye
Domenico L.

Counting postage stamps' teeth [F.D.A.]

Anuj Dhawan
Moderator
Posts: 1625
Joined: Sat Aug 09, 2008 9:02 am
Location: Mumbai, India

Post by Anuj Dhawan » Mon Dec 12, 2011 2:35 pm

strahd,

What exactly are you looking for - every next reply from you does not match up with your previous reply.

This
I need to prepare a JCL step that copy a dataset into a new dataset but ONLY if this new dataset not already exist.
from your first post is easy to implement but your latest post is confusing.

May be you can use two steps - first will check for the "new dataset not already exist" and then you execute second step based on the RC from first step to copy file to the file-name you desire.
Regards,
Anuj

User avatar
strahd
Member
Posts: 11
Joined: Tue Nov 22, 2011 2:26 pm
Location: Italy

Post by strahd » Mon Dec 12, 2011 3:08 pm

Hi,
Strahd wrote:I need to prepare a JCL step that copy a dataset into a new dataset but ONLY if this new dataset not already exist.
This is what I need.

But I can't delete the dataset!

I can't use Rexx.

I wish to do this copy with a single step (I wish not I must) because there are many dataset to copy in the same way: 1 step - 1 dataset is better than 2 step - 1 dataset

I try to write a jcl using idcams but I encountred some problem:
  • Using OUTFILE I receave an error in open method
  • If I use OUTDASET instead I receave an error because the dataset in not allocated...
Anuj Dhawan wrote:May be you can use two steps - first will check for the "new dataset not already exist" and then you execute second step based on the RC from first step to copy file to the file-name you desire.
Ok it's a solution, may you post an exmaple code, please?
Domenico L.

Counting postage stamps' teeth [F.D.A.]

DikDude
Moderator
Posts: 1001
Joined: Fri Jul 22, 2011 8:39 am
Location: usa

Post by DikDude » Tue Dec 13, 2011 1:24 am

But I can't delete the dataset!
Which diety dictated this? I suspect if you implement a process that always works this would not matter. . .
Ok it's a solution, may you post an exmaple code, please?
Huh :?
To determine if a data set exists (rather than is empty) just run an idcams listcat and look at the output.
Whch part of this do you not understand?

It is rather doubtful that someone here will do your work for you for free. . .

When a job has been rerun for some reason, which of the created files should be used? Or should both be used?

Possibly you will talk with your project lead or someone else knowledgable to make sure the proper issue is being addressed. Thios appears to just be going around in circles . . .
Last edited by DikDude on Tue Dec 13, 2011 10:08 pm, edited 1 time in total.
Have a good one

User avatar
strahd
Member
Posts: 11
Joined: Tue Nov 22, 2011 2:26 pm
Location: Italy

Post by strahd » Tue Dec 13, 2011 3:56 pm

I suppose, this is a forum which aim to help the mainframe users and programmers.

So, if you are able to aid and if you want help write an answer, otherwise simply no reply.
Domenico L.

Counting postage stamps' teeth [F.D.A.]

DikDude
Moderator
Posts: 1001
Joined: Fri Jul 22, 2011 8:39 am
Location: usa

Post by DikDude » Tue Dec 13, 2011 10:20 pm

I suppose, this is a forum which aim to help the mainframe users and programmers.
Yes, it is - especially those who are willing to help themself - rather than whine around in circles.
if you want help write an answer, otherwise simply no reply.
How utterly childish . . . :(

If you post something useful (which has not been yet done), there are several here who could/would help. You continue to post nothing useful and lead many of us to believe you have no clear requirement to accomplish. You know you want something, but have not described this well at all. Possibly because you do not yet understand what you are looking for.

You have made up some "rules" you insist must be followed (from what you have posted so far, they do not need to be followed) and you have made no business case for your insistence.. You need to explain (clearly for once) what is the actual processing requirement - not the way you intend to implement. Indeed, one of the great uses for forums is so you can learn alternative ways to do what is needed rather than being stuck on something questionable in the first place. . .
Last edited by DikDude on Wed Dec 14, 2011 2:22 am, edited 1 time in total.
Have a good one

MrSpock
Active Member
Posts: 273
Joined: Wed Jun 27, 2007 5:37 pm

Post by MrSpock » Wed Dec 14, 2011 2:04 am

I've been a bit puzzled by this topic as well. Working in the EDI area for many years. I'm used to dealing with datasets that are created/maintained by another team. My usual process for a similar requirement would be to use an IDCAMS/LISTCAT to check if the target dataset is cataloged or not. Then, based on the Return-Code of the first step, I'd use a SORT step to check for an empty dataset condition for the source dataset. Based on the Return-Code of both events, I'd then have a final step that would again use SORT to perform the final copy when both the criteria are met (target file does not exist, and the source dataset contains data).

User avatar
strahd
Member
Posts: 11
Joined: Tue Nov 22, 2011 2:26 pm
Location: Italy

Post by strahd » Wed Dec 14, 2011 3:36 am

Thank's MrSpock,
I solved in a similar ways idcams/listcat and sort + cond, tomorrow (for me) I post the code.

Well at the beginnig of this thread I ask if is possible to do that in a single step.

Trying with idcams / listcat + allocate + repro I've got error with the allocate statement but I don't understand why. (tomorrow I post the code :-) )

Bye
Domenico L.

Counting postage stamps' teeth [F.D.A.]

User avatar
strahd
Member
Posts: 11
Joined: Tue Nov 22, 2011 2:26 pm
Location: Italy

Post by strahd » Wed Dec 14, 2011 7:57 pm

hi,

this is a solution

Code: Select all

//*--------------------------------------------------------
//* VERIFICA CONGRUENZA DATI DI CARTOLARIZZAZION           
//**                                                       
//TEST1    EXEC  PGM=IDCAMS                                
//*                                                        
//SYSOUT   DD SYSOUT=*                                     
//SYSPRINT DD SYSOUT=*                                     
//SYSIN    DD *                                            
   LISTCAT ENTRIES&#40;TESTDS.RAPPO.TRAIL1&#41;                   
   IF LASTCC = 00   THEN SET MAXCC=00                      
   ELSE IF LASTCC < 13 THEN DO                             
             SET MAXCC=02                                  
           END                                             
        ELSE SET MAXCC=99                                  
/*                                                         
//*--------------------------------------------------------
//* VERIFICA CONGRUENZA DATI DI CARTOLARIZZAZION           
//**                                                       
//COPIA1   EXEC  PGM=SORT,COND=&#40;02,NE,TEST1&#41;               
//*                                                        
//SORTIN   DD DSN=TESTDS.RAPPO.TRAIL,DISP=SHR             
//*                                                        
//SORTOUT  DD DSN=TESTDS.RAPPO.TRAIL1,DISP=&#40;NEW,CATLG&#41;,   
//            SPACE=&#40;CYL,&#40;1,1&#41;,RLSE&#41;,DCB=*.SORTIN          
//*                                                        
//SYSOUT   DD SYSOUT=*                                     
//SYSPRINT DD SYSOUT=*                                     
//SYSIN    DD *                                            
 SORT FIELDS=COPY                                          
 END                                                       
/*                                                         
//*--------------------------------------------------------
this the code tha doesn't work :-(

Code: Select all

//COPIA    EXEC  PGM=IDCAMS,COND=&#40;88,NE,TEST1&#41;              
//*                                                         
//RAPPIN   DD DSN=*.DEFINE.RAPPIN,DISP=SHR                  
//SYSOUT   DD SYSOUT=*                                      
//SYSPRINT DD SYSOUT=*                                      
//*DELETE TESTDS.RAPPO.TRAIL2                              
//*LISTDATA STATUS FILE&#40;SORTOUT&#41;                            
//*LISTCAT ENTRIES&#40;TESTDS.RAPPO.TRAIL2&#41;                    
//*PRINT INDATASET&#40;&DS1&#41; DUMP  COUNT&#40;001&#41;                   
//*    ALLOC DSNAME&#40;RAPPO.TRAIL2&#41; NEW CATALOG -             
//*    SPACE&#40;1,1&#41; RECFM&#40;F,B&#41;                                
//*PRINT INDATASET&#40;TESTDS.RAPPO.TRAIL2&#41; DUMP  COUNT&#40;001&#41;   
//SYSIN    DD *                                             
   PRINT INDATASET&#40;TESTDS.RAPPO.TRAIL2&#41; DUMP  COUNT&#40;001&#41;   
   IF LASTCC > 00   THEN -                                  
     IF LASTCC < 13 THEN DO                                 
       SET MAXCC=0                                          
       ALLOC DSNAME&#40;TESTDS.RAPPO.TRAIL2&#41; NEW CATALOG -             
       SPACE&#40;1,1&#41; RECFM&#40;F,B&#41;                                
       REPRO INFILE&#40;RAPPIN&#41; -                               
          OUTDATASET&#40;TESTDS.RAPPO.TRAIL2&#41;                  
     END                                                    
/*                                                          
Maybe I don't understand yet the right use of the Alloc instruction...
Domenico L.

Counting postage stamps' teeth [F.D.A.]

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others