Page 1 of 1

Create a dataset if it doesn't exist before copying a member

PostPosted: Wed Oct 23, 2013 7:27 pm
by NoSleep319
I'm copying a member from one library to another 'temp' library before I modify it, but I can only do this if the second location is already created...This is the rexx code I'm workin with:

ADDRESS ISPEXEC
"LMINIT DATAID("DDI") DATASET('"FROMPDS"') ENQ(SHRW)"
"LMINIT DATAID("DDO") DATASET('"TOPDS"') ENQ(SHRW)"
"LMCOPY FROMID("DDI") FROMMEM("M1") TODATAID("DDO") REPLACE"

How would I go about verifying whether 'xxxx.REXXTEMP' exists, and creating if it doesn't?

Here's the dataset information if it helps with a creation statement:

Data Set Name . . . . : xxxx.REXXTEMP

General Data Current Allocation
Management class . . : MCPDS Allocated cylinders : 10
Storage class . . . : SCDFAULT Allocated extents . : 1
Volume serial . . . : DSM561
Device type . . . . : 3390
Data class . . . . . : DEFAULT
Organization . . . : PO Current Utilization
Record format . . . : VB Used cylinders . . : 1
Record length . . . : 255 Used extents . . . : 1
Block size . . . . : 27998
1st extent cylinders: 10
Secondary cylinders : 0 Dates
Data set name type : PDS Creation date . . . : 2013/10/22
Referenced date . . : 2013/10/22
Expiration date . . : 2050/12/25

Also, it seems to start erroring when I use all cylinders allocated, but when I clear the members out that have been moved, I noticed the Current Utilization doesn't change back to 1...is there a delayed response, or how do the cylinders work in regards to storage space?

Re: Create a dataset if it doesn't exist before copying a me

PostPosted: Wed Oct 23, 2013 7:31 pm
by NicC
You can do a listdsi to see if the dataset exists. If it does then allocate with a DSIP of SHR and if it does not exist allocate it with all the required parameters for a new dataset.

Re: Create a dataset if it doesn't exist before copying a me

PostPosted: Wed Oct 23, 2013 8:09 pm
by Peter_Mann
you can use TSO services to check if the dataset and member for that fact exists ....

SET &SYSIN=&SYSDSN('userid.CATLIST.SYSIN')
IF &SYSIN ¬= OK THEN DO
ATTR F80 RECFM(F) LRECL(80) BLKSIZE(80)
ALLOC F(SYSIN) DA('userid.CATLIST.SYSIN') NEW SP(1) TRA US(F80)
END
ELSE DO

Re: Create a dataset if it doesn't exist before copying a me

PostPosted: Wed Oct 23, 2013 8:14 pm
by Peter_Mann
One other thing that occured to me, LMINIT will set a return code you can interegate
from the LMINIT
ADDRESS ISPEXEC
"LMINIT DATAID("DDI") DATASET('"FROMPDS"') ENQ(SHRW)"
If rc ¬= 0 Then /* Return codes */
Do /* 8 - Data set or file not */
End /* allocated */
Else /* - DDname not found */
/* - Data set or file */
/* organization not supported */
/* 12 - Invalid parameter value */
/* 16 - Truncation or translation */
/* error in accessing dialog */
/* variables */
/* 20 - Severe error */
this may be better that my previous suggestion

Re: Create a dataset if it doesn't exist before copying a me

PostPosted: Wed Oct 23, 2013 8:35 pm
by NoSleep319
ok, what if I have the dataset saved in a variable? I have MY = USERID(), then TOPDS = MY".REXXTEMP"
How do I transition that into the ALLOC example you gave me? I tried the following:

SET &SYSIN=&SYSDSN(&TOPDS)                         
IF &SYSIN ¬= OK THEN                               
  DO                                               
    ATTR F80 RECFM(F) LRECL(80) BLKSIZE(80)       
    ALLOC F(SYSIN) DA(&TOPDS) NEW SP(1) TRA US(F80)
  END                                             
ELSE DO                                           


I getting an invalid expression error

Re: Create a dataset if it doesn't exist before copying a me

PostPosted: Wed Oct 23, 2013 9:14 pm
by Peter_Mann
if you have the dataset stored in a variable you'll need to use ispf services VGET ?
you'll need to test different options, but I belive your missing the single quotes around the dsn is adding your ID on top of the fully qualtified dataset you've provided.
you can also trace the rexx to see exactly what dataset is being allocated

Re: Create a dataset if it doesn't exist before copying a me

PostPosted: Thu Oct 24, 2013 1:20 am
by Pedro
I getting an invalid expression error


I think you are mixing languages. You seem to have CLIST statements in your rexx exec.

Re: Create a dataset if it doesn't exist before copying a me

PostPosted: Thu Oct 24, 2013 1:31 am
by Akatsukami
Pedro wrote:
I getting an invalid expression error


I think you are mixing languages. You seem to have CLIST statements in your rexx exec.

Yes; the equivalent Rexx would be:
sysin = sysdsn(topds)
if (sysin¬="OK") then
do
  "ATTR F80 RECFM(F) LRECL(80) BLKSIZE(80)"
  "ALLOC F(SYSIN) DA("topds") NEW SP(1) TRA US(F80)"
end
else do
  :       

Note, incidentally, that an unblocked data set with LRECL=80 is horribly wasteful of DASD; I'd make it fixed blocked and leave off the BLKSIZE parameter; under z/OS it's unnecessary.

Re: Create a dataset if it doesn't exist before copying a me

PostPosted: Thu Oct 24, 2013 1:42 am
by Peter_Mann
'I think you are mixing languages. You seem to have CLIST statements in your rexx exec."

that's my bad, I overlooked the ADDRESS ISPEXEC in the OP's post.