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

To create multiple members in the same PDS through REXX


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
kabyab

New User


Joined: 31 Aug 2005
Posts: 34
Location: Pune, India

PostPosted: Thu Aug 21, 2008 5:16 pm
Reply with quote

I have to write a REXX to automate a process where in 240 JCLs have to be submitted one after the other sequentially with different JOB Names and Cycle Nos (cycle nos starting from C001 till C240).
The Input to the REXX would be the first Cycle number (i.e. 001), it has to be passed to the REXX which creates the JCL and then increments the Cycle number by one to create the second JCL (Each JCL is a different members in the PDS mentioned below) and so on.
I am a total Newbee to REXX. This is my first REXX assignment. So I have gone through some books and materials and so far have been able to write REXX to submit a JCL and allocate a PDS member.

As a sample I have written the following REXX (took help from some online resources) wherein, it takes a JCL as input and tries to list down the Dataset names after "DSN=" string in the output pds ABC.DEF.KLM(RXXOP001).

Code:

/* REXX exec to find a report all datasets */                           
                                                                       
SAY "enter the input member name:"                                     
pull input                                                             
SAY "enter the output member name:"                                     
pull output                                                             
"Alloc F(in) DS("input") shr"                                           
"Execio * diskr in (finis stem in."                                     
"Free F(in)"                                                           
j=0                                                                     
do i=1 to in.0                                                         
   if pos("DSN=",in.i)=0 then iterate                                   
   parse value in.i with ddn ."DSN="dsn                                 
   parse value dsn with dataset",".                                     
   j=j+1                                                               
   out.j=dataset                                                       
   end                                                                 
/**Create an output PDS ABC.DEF.KLM with member RXXOP001 **/                 
"Alloc f(out) ds("output") space(100 50) tracks",                       
"dir(10) dsorg(po) recfm(f,b) lrecl(80) blksize(27920)",               
"retpd(60)"                                                             
"Execio * Diskw out (finis stem out."                                   
"Free F(out)"                                                           






The input and output dataset names are to be supplied when asked on screen. The requirement is such that each time I run the REXX it should create separate members in the same pds ABC.DEF.KLM as

RXXOP001
RXXOP002
RXXOP003
RXXOP004
and so on till
RXXOP240

My problem : I can create ABC.DEF.KLM(RXXOP001) one member inside the pds ABC.DEF.KLM. But if I try to run the same REXX a second time to create a second member RXXOP002 in the same PDS ABC.DEF.KLM, it throws me an error.

My Query: Is it possible to create multiple members in a PDS by executing the same REXX more than once? If yes, then how?
What changes need to be done to my REXX to bring out the desired results?

I did search through some posts which are similar but still didn't find a proper answer to my query. May be I have not referred to the correct posts.
I would appreciate if someone can help in this. Please let me know if any clarification is required.

Thanks.
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Thu Aug 21, 2008 6:27 pm
Reply with quote

The variable output is entered as the entire PDS and member name, i.e.

>enter the output member name:
'ABC.DEF.KLM(RXXOP001)'

correct? The logic where you create a whole new PDS each time doesn't make sense. Is that the error you're getting?
Back to top
View user's profile Send private message
kabyab

New User


Joined: 31 Aug 2005
Posts: 34
Location: Pune, India

PostPosted: Thu Aug 21, 2008 7:31 pm
Reply with quote

Hi Kevin,

Thanks so much for pointing it out. icon_smile.gif

I have changed the code as below; I have run with only
Code:

 "Alloc f(out) ds("output")"         


and it successfully created a separate member in the same PDS.

I have tried to modify the code to first check if the dataset is present then just add member and if not present then allocate new dataset and create member. I got stuck in this approach. I suppose my If Else condition check is not proper. Still it is going after creating new dataset (Else part) and causing an error message to appear.

The code segment
Code:

RETCODE = SYSDSN("output")                                 
Say retcode                                                 


gives output as OK for found and MEMBER NOT FOUND for not found so I tried the following check


Code:

RETCODE = SYSDSN("output")                                 
Say retcode                                                 
if retcode = OK then do                                     
   say "copying results in new member in existing dataset" 
   "Alloc f(out) ds("output")"                             
   end                                                     
else do                                                     
   say "Allocating new dataset and member"                 
   "Alloc f(out) ds("output") space(100 50) tracks",       
   "dir(10) dsorg(po) recfm(f,b) lrecl(80) blksize(27920)",
   "retpd(60)"                                             
   end                                                     
"Execio * Diskw out (finis stem out."                       
"Free F(out)"                                               


How should I check?
I cannot check for MEMBER NOT FOUND as the second member is anyway not present irrespective of if the PDS is present or not. So the control travels to the ELSE part. Is there a way to check if the PDS is present or not and not check for the member?
Then I can safely check for the PDS presence and then ask my REXX code to create a PDS if not present else create just the member. icon_smile.gif

Thanks.[/code]
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1193
Location: Dublin, Ireland

PostPosted: Thu Aug 21, 2008 8:40 pm
Reply with quote

Variable named output contains the fully-qualified dsn and member?
You can parse or substring this to get the dsn in a separate variable and use that in the RETCODE=SYSDSN( ) check. You could also specify the DSN and member name as separate parms and concatenate where you need the full string.

If the dsn doesn't exist, create it. Once that's checked/done, allocate the DSN(member) and write it.

Regards,
Garry.
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Thu Aug 21, 2008 9:09 pm
Reply with quote

SYSDSN("'"output"'") is only going to return one of three values:

OK (both dataset & member exist)
MEMBER NOT FOUND (dataset exists but member doesn't)
DATASET NOT FOUND (dataset doesn't exist)

Only the last value would require you to allocate an entirely new PDS with the NEW CATALOG disposition.
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Thu Aug 21, 2008 9:27 pm
Reply with quote

Code:

RETCODE = SYSDSN("'"output"'")                                 
Say retcode     
if retcode = "DATASET NOT FOUND" then do
   say "Allocating new dataset"                 
     "Alloc f(out) ds('"output"') new catalog reu space(100 50) tracks",       
       "dir(10) dsorg(po) recfm(f,b) lrecl(80) blksize(27920)",
       "retpd(60)"                                             
   end                                 
say "copying results in new member in existing dataset" 
"Alloc f(out) ds('"output"')" shr reu"                                                   
"Execio * Diskw out (finis stem out."                       
"Free F(out)"
Back to top
View user's profile Send private message
kabyab

New User


Joined: 31 Aug 2005
Posts: 34
Location: Pune, India

PostPosted: Fri Aug 22, 2008 12:43 pm
Reply with quote

Thanks Kevin and Garry for your inputs.
I am able to create the members but still there is a doubt as given below.

I have modified the code as below.
Code:

***************************** Top of Data ********************
/* REXX exec to report all datasets */                         
                                                               
SAY "enter the input member name:"                             
pull input                                                     
SAY "enter the output member name:"                             
pull output                                                     
"Alloc F(in) DS("input") shr"                                   
"Execio * diskr in (finis stem in."                             
"Free F(in)"                                                   
j=0                                                             
do i=1 to in.0                                                 
   if pos("DSN=",in.i)=0 then iterate                           
   parse value in.i with ddn ."DSN="dsn                         
   parse value dsn with dataset",".                             
   j=j+1                                                       
   out.j=dataset                                               
   end                                                         
/**Create an output PDS ABC.DEF.KLM with member RXXOP001 **/   
RETCODE = SYSDSN("output")                                     
Say retcode                                                     
if retcode = "DATASET NOT FOUND" then do                       
   say "Allocating new dataset"                                 
   "Alloc f(out) ds("output") new catalog space(100 50) track",
   "dir(10) dsorg(po) recfm(f,b) lrecl(80) blksize(27920)",     
   "retpd(60)"                                                 
   end                                                         
say "copying results in new member in existing dataset"         
"Alloc f(out) ds("output") shr reu"                             
"Execio * Diskw out (finis stem out."                           
"Free F(out)"                                                   
**************************** Bottom of Data ******************


Running it the first time screenshot:

Code:

enter the input member name: 'ABC.DEF.KLM.SAMPLE.INPUT'   
                                                             
enter the output member name: 'ABC.DEF.KLM.SAMPLE.OP5(MEM1)'
                                                             
DATASET NOT FOUND                                             
Allocating new dataset                                       
copying results in new member in existing dataset             
***                                                           


Running it for second time screenshot:
Code:

enter the input member name: 'ABC.DEF.KLM.SAMPLE.INPUT'           
                                                                     
enter the output member name: 'ABC.DEF.KLM.SAMPLE.OP5(MEM2)'       
                                                                     
DATASET NOT FOUND                                                     
Allocating new dataset                                               
DATA SET ABC.DEF.KLM.SAMPLE.OP5 NOT ALLOCATED+                   
IGD01007I EXPIRATION AND RETENTION DATES ARE IGNORED FOR DISK DATASETS
IGD17101I DATA SET ABC.DEF.KLM.SAMPLE.OP5                         
NOT DEFINED BECAUSE DUPLICATE NAME EXISTS IN CATALOG                 
RETURN CODE IS 8 REASON CODE IS 38 IGG0CLEH                           
copying results in new member in existing dataset                     
***                                                                   


I am getting the required output MEM1 and MEM2 but why is it still getting return code as DATASET NOT FOUND? i.e.
Why is it again going into the IF statement if dataset is already existing?

Also I need to know from Kevin why he has mentioned " ' "output" ' " with those extra quotes and what is wrong if I use "output" ? Kevin, how does these extra quotes help us in the coding? I know they muct be having some significance that I may not be knowing at this stage.

Thanks.
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Fri Aug 22, 2008 12:58 pm
Reply with quote

Because they fully qualify your dataset, without them - depending on your ISPF settings - the dataset name will have a prefix equal to your userid.
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1193
Location: Dublin, Ireland

PostPosted: Fri Aug 22, 2008 12:59 pm
Reply with quote

The First time through you are issuing
RETCODE = SYSDSN("ABC.DEF.KLM.SAMPLE.OP5(MEM1)")
and get DATASET NOT FOUND

You then create the dataset (with the member name).

Next time, you issue
RETCODE = SYSDSN("ABC.DEF.KLM.SAMPLE.OP5(MEM2)")

and get DATASET NOT FOUND - because "ABC.DEF.KLM.SAMPLE.OP5" already exists from last time.

What I was getting at was that you should issue

RETCODE= SYSDSN("ABC.DEF.KLM.SAMPLE.OP5")

then,
if DATASET NOT FOUND then signal write
alloc dataset as new - without member name
free
write:
alloc for "ABC.DEF.KLM.SAMPLE.OP5(MEM#)"
execio
free

Regards,
Garry.
Back to top
View user's profile Send private message
kabyab

New User


Joined: 31 Aug 2005
Posts: 34
Location: Pune, India

PostPosted: Fri Aug 22, 2008 1:41 pm
Reply with quote

Thanks so much to both Kevin and Gary. I have finally been able to get my desired output. Here is the code that I have used. icon_biggrin.gif

Code:

***************************** Top of Data *********************
/* REXX exec to report all datasets */                                 
                                                                       
SAY "enter the input member name:"                                     
pull input                                                             
"Alloc F(in) DS("input") shr"                                           
"Execio * diskr in (finis stem in."                                     
"Free F(in)"                                                           
j=0                                                                     
do i=1 to in.0                                                         
   if pos("DSN=",in.i)=0 then iterate                                   
   parse value in.i with ddn ."DSN="dsn                                 
   parse value dsn with dataset",".                                     
   j=j+1                                                               
   out.j=dataset                                                       
   end                                                                 
/**Create an output PDS ABC.DEF.KLM with member RXXOP001 **/           
SAY "enter the output dataset name and member name:"                   
pull output                                                             
parse upper value output with dsname ."("tempmem                       
parse value tempmem with member .")"                                   
say "o/p dsname = " dsname                                             
say "o/p member = " member                                             
RETCODE = SYSDSN("'"dsname"'")                                         
Say "Returncode = "retcode                                             
if RETCODE = "DATASET NOT FOUND" then do                               
   say "Allocating new dataset "dsname                                 
   "Alloc f(out) ds('"dsname"') new catalog space(100 50) track",       
   "dir(10) dsorg(po) recfm(f,b) lrecl(80) blksize(27920)",             
   "retpd(60)"                                                         
   end                                                                 
say "copying results in member "member " in existing dataset " dsname   
"Alloc f(out) ds('"output"') shr reu"                                   
"Execio * Diskw out (finis stem out."                                   
"Free F(out)"                                                           
**************************** Bottom of Data ******************
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1193
Location: Dublin, Ireland

PostPosted: Fri Aug 22, 2008 1:47 pm
Reply with quote

Glad to have been of help.

Garry.
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 -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Compile Several JCL JOB Through one r... CLIST & REXX 4
No new posts Running REXX through JOB CLIST & REXX 13
No new posts Error to read log with rexx CLIST & REXX 11
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts isfline didnt work in rexx at z/OS ve... CLIST & REXX 7
Search our Forums:

Back to Top