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
 

 

Scan/Sort Members from PDS using REXX

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX
View previous topic :: :: View next topic  
Author Message
saithvis2

New User


Joined: 23 Dec 2005
Posts: 61
Location: Providence , US

PostPosted: Tue Aug 08, 2006 10:17 pm    Post subject: Scan/Sort Members from PDS using REXX
Reply with quote

Hi All,

I am facing problem with the rexx which have written for this problem ,

Problem:
I have a flat file which has 2 rows , first consists of number of members in
a particular PDS and the second row consists of the name of that PDS.

Now , My REXX code will read the flat file and will first check for the existence of that pds using LISTCAT , if the pds exists it will create 2 diff pds 's one for cobolsor and other one for copylib using the same name .

Now it scans the PDS and if the name starts with 'FWG0' it puts them in copylib pds else puts them in cobolsor pds which have been created in previous step.


MY REXX Code is :

Code:

/* REXX */                                           
"EXECIO * DISKR INFILE(STEM INPUT."                   
PDSNAME = STRIP(INPUT.2)                             
CALL OUTTRAP "LISTC."                                 
"LISTCAT ENTRIES('"PDSNAME"')"                       
IF RC \= 0 THEN DO                                   
   SAY "ERROR: DATA SET DOES NOT EXIST"               
   EXIT 12                                             
END                                                   
CALL OUTTRAP "OFF"                                   
PDSNAMEPGM = SUBSTR(PDSNAME,1,20)||'.COBOLSOR'       
PDSNAMECPY = SUBSTR(PDSNAME,1,20)||'.COPYLIB'         
"ALLOCATE DA('"PDSNAMEPGM"') LIKE('"PDSNAME"') NEW"   
IF RC > 0 THEN DO                                     
   SAY "ERROR: FAILURE TO ALLOCATE DATASET" PDSNAMEPGM
   EXIT 8                                             
END                                                   
"ALLOCATE DA('"PDSNAMECPY"') LIKE('"PDSNAME"') NEW"   
IF RC > 0 THEN DO                                     
   SAY "ERROR: FAILURE TO ALLOCATE DATASET" PDSNAMECPY
   EXIT 8                                             
END                                                   
CALL OUTTRAP "TRAP."                                   
"LISTD'"||PDSNAME||"'MEMBERS"                         
CALL OUTTRAP "OFF"                                     
I = 1                                                 
MEM_FOUND = "FALSE"                                     
DO UNTIL MEM_FOUND = "TRUE"                           
   SAY TRAP.I                                         
   IF TRAP.I = "--MEMBERS--" THEN DO                   
      I = I + 1                                         
      MEM_FOUND = "TRUE"                               
   END                                                 
   ELSE DO                                             
      I = I + 1                                         
   END                                                 
END                                                   
J = 0                                                 
DO UNTIL I = TRAP.0                                         
   IF SUBSTR(STRIP(TRAP.I),1,4) = 'FWG0' THEN DO           
      X = STRIP(TRAP.I)                                     
  /*  "ALLOC F(MYINDD) DS('"DSNAME"("X")') SHR REUSE"       
      "ALLOC F(MYOUTDD) DS('"PDSNAMECPY"("X")') SHR REUSE" 
      "EXECIO * DISKR MYINDD (FINIS"                       
      "EXECIO * DISKW MYOUTDD (FINIS"                       
      "FREE F(MYINDD) F(MYOUTDD)"   */                     
   END                                                     
   ELSE DO                                                 
      X = STRIP( TRAP.I)                                     
   /* "ALLOC F(MYINDD) DS('"DSNAME"("X")') SHR REUSE"       
      "ALLOC F(MYOUTDD) DS('"PDSNAMEPGM"("X")') SHR REUSE"   
      "EXECIO * DISKR MYINDD (FINIS"                       
      "EXECIO * DISKW MYOUTDD (FINIS"                       
      "FREE F(MYINDD) F(MYOUTDD)"  */                       
   END                                                     
   I = I + 1                                               
   J = J + 1                               
END                                         
IF J = INPUT.1 THEN DO                     
   SAY 'SUCCESS'                           
END                                       
ELSE DO                                   
   SAY "ERROR: INCOSISTENT DATA MOVEMENT"   
   EXIT 12                                 
END


This Rexx is causing problem at 2 places :

1:
When executing this portion of the code
Code:

CALL OUTTRAP "TRAP."         
"LISTD'"||PDSNAME||"'MEMBERS"
CALL OUTTRAP "OFF"

it gives the problem as :

Code:

 33 *-* "LISTD'"||PDSNAME||"'MEMBERS"
       +++ RC(-3) +++   


2: When the following code is uncommented out
Code:

/*  "ALLOC F(MYINDD) DS('"DSNAME"("X")') SHR REUSE"       
      "ALLOC F(MYOUTDD) DS('"PDSNAMECPY"("X")') SHR REUSE" 
      "EXECIO * DISKR MYINDD (FINIS"                       
      "EXECIO * DISKW MYOUTDD (FINIS"                       
      "FREE F(MYINDD) F(MYOUTDD)"   */                     


, it causes the problem as given below :

Code:

 57 +++  "ALLOC F(MYINDD) DS('"DSNAME"("X                   
     4 +++ PDSNAME = STRIP(INPUT.2)                             
Error running GO, line 57: Invalid hexadecimal or binary string                 


Can some please help me out in the same .
Thanks in advance.

Regards,
Vishal
Back to top
View user's profile Send private message

superk

Moderator Team Head


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

PostPosted: Tue Aug 08, 2006 11:48 pm    Post subject: Re: Scan/Sort Members from PDS using REXX
Reply with quote

This section of code:
Code:

CALL OUTTRAP "TRAP."                                   
"LISTD'"||PDSNAME||"'MEMBERS"                         
CALL OUTTRAP "OFF"


needs some blanks, thus:

Code:

CALL OUTTRAP "TRAP."                                   
"LISTD  '"||PDSNAME||"'  MEMBERS"                         
CALL OUTTRAP "OFF"


As far as using 'X' for a variable name, since it is the REXX representation for hexadecimal, that seems to be why there's a problem. Simple solution - use another variable, or use something like "_X" or "#X".
Back to top
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2360
Location: Israel

PostPosted: Tue Aug 08, 2006 11:49 pm    Post subject:
Reply with quote

Rgearding your first issue: LISTD is not a TSO command. You probably need LISTDS.

For the second issue: Dont use X as a variable name. The fine manual says that every X followed by a single or double quotation mark is considered to be hexadecimal string. Try something more meaninfull (what's wrong with MEMNAME?)

If I may add: To check is a dataset is cataloged, you better use the TSO external function LISTDSI.

Unless the length of PDSNAME is pre-known, you might want to verify that the last character is not '.', to avoid two consecutive dots.

The first member in the output of LISTDS will always be in line 7. You can remove the first DO UNTIL.

Look in google for an article named "To address ot not to address". You will see that sometimes it's good to add "ADDRESS TSO" before each statement.

Good luck.

O.
Back to top
View user's profile Send private message
saithvis2

New User


Joined: 23 Dec 2005
Posts: 61
Location: Providence , US

PostPosted: Fri Aug 18, 2006 6:50 pm    Post subject: Re: Scan/Sort Members from PDS using REXX
Reply with quote

Hi Ofer/Superk


Thanks alot for solving my problem yet again .
The modified rexx is given as below:
Code:

                                                             
                                                                     
                                                                     
                                             
/* REXX */
CALL PARMREAD
CALL CHECKINPDS
PDSNAMEPGM = SUBSTR(PDSNAME,1,20)||'.COBOLSOR'
PDSNAMECPY = SUBSTR(PDSNAME,1,20)||'.COPYLIB'
AUDITFILE  = SUBSTR(PDSNAME,1,20)||'.AUDIT.SEQ'
PDSEXIST   = 'N'
CPYEXIST   = 'N'
CALL CHECKOUTPDS
CALL LISTMEMBERS
I          = 7
J          = 0
AUDITCNT   = 1
CALL MOVEMEMBERS
IF AUDITCNT > 1 THEN DO
  "EXECIO * DISKW AUD (STEM AUDIT."
END
IF J \= NOPGMS THEN DO
   SAY "ERROR: INCONSISTENT DATA MOVEMENT"
   EXIT 04
END

PARMREAD:
  "EXECIO * DISKR INFILE(STEM INPUT."
  NOPGMS  = STRIP(INPUT.1)
  PDSNAME = STRIP(INPUT.2)
  RETURN

CHECKINPDS:
  CALL OUTTRAP "LISTC."
  "LISTCAT ENTRIES('"PDSNAME"')"
  IF RC \= 0 THEN DO
     SAY "ERROR " RC " WHEN TRYING TO ACCESS CATALOG FOR " PDSNAME
     EXIT 08
  END
  CALL OUTTRAP "OFF"
  RETURN

CHECKOUTPDS:
  CALL OUTTRAP "LISTC."
  "LISTCAT ENTRIES('"PDSNAMEPGM"')"
  IF RC = 0 THEN DO
     PDSEXIST = 'Y'
  END
  ELSE DO
     "ALLOCATE DA('"PDSNAMEPGM"') LIKE('"PDSNAME"') NEW"
     IF RC > 0 THEN DO
        SAY "ERROR " RC " FAILURE TO ALLOCATE DATASET " PDSNAMEPGM
        EXIT 8
     END
  END
  "LISTCAT ENTRIES('"PDSNAMECPY"')"
  IF RC = 0 THEN DO
     CPYEXIST = 'Y'
  END
  ELSE DO
     "ALLOCATE DA('"PDSNAMECPY"') LIKE('"PDSNAME"') NEW"
     IF RC > 0 THEN DO
        SAY "ERROR " RC " FAILURE TO ALLOCATE DATASET " PDSNAMECPY
        EXIT 8
     END
  END
  CALL OUTTRAP "OFF"
  RETURN

LISTMEMBERS:
  CALL OUTTRAP "TRAP."
  "LISTDS '"||PDSNAME||"' MEMBERS"
  CALL OUTTRAP "OFF"
  RETURN

MOVEMEMBERS:
  DO UNTIL I > TRAP.0
     IF SUBSTR(STRIP(TRAP.I),1,4) = 'FWG0' THEN DO
        MEMNAME = STRIP(TRAP.I)
        IF CPYEXIST = 'Y' THEN DO
           CALL LISTCPYMEM
           CALL AUDITTRAIL
        END
        CALL CPYCOPYBOOK
     END
     ELSE DO
        MEMNAME = STRIP(TRAP.I)
        IF PDSEXIST = 'Y' THEN DO
           CALL LISTPDSMEM
           CALL AUDITTRAIL
        END
        CALL CPYPROGRAM
     END
     I = I + 1
     J = J + 1
  END
  RETURN

LISTCPYMEM:
  CALL OUTTRAP "CPY."
  TEMPVAR = PDSNAMECPY||"("||MEMNAME||")"
  "LISTDS '"||TEMPVAR||"' MEMBERS"
  CALL OUTTRAP "OFF"
  RETURN

LISTPDSMEM:
  CALL OUTTRAP "CPY."
  TEMPVAR = PDSNAMEPGM||"("||MEMNAME||")"
  "LISTDS '"||TEMPVAR||"' MEMBERS"
  CALL OUTTRAP "OFF"
  RETURN

AUDITTRAIL:
  L      = 7
  K      = CPY.0
  DT     = DATE('USA')
  AUDFND = 'N'
  CALL AUDCHKMEM
  IF AUDFND = 'Y' THEN DO
     AUDIT.AUDITCNT = DT||" "||MEMNAME||" ADDED FROM "||PDSNAME
     AUDITCNT       = AUDITCNT + 1
  END
  RETURN

AUDCHKMEM:
  DO UNTIL L > CPY.0
     IF MEMNAME = STRIP(CPY.L) THEN DO
        AUDFND  = 'Y'
        L       = L + CPY.0
     END
     L          = L + 1
  END
  RETURN

CPYCOPYBOOK:
  "ALLOC F(MYINDD) DS('"PDSNAME"("MEMNAME")') SHR REUSE"
  "ALLOC F(MYOUTDD) DS('"PDSNAMECPY"("MEMNAME")') SHR REUSE"
  "EXECIO * DISKR MYINDD (FINIS"
  "EXECIO * DISKW MYOUTDD (FINIS"
  "FREE F(MYINDD) F(MYOUTDD)"
  RETURN

CPYPROGRAM:
  "ALLOC F(MYINDD) DS('"PDSNAME"("MEMNAME")') SHR REUSE"
  "ALLOC F(MYOUTDD) DS('"PDSNAMEPGM"("MEMNAME")') SHR REUSE"
  "EXECIO * DISKR MYINDD (FINIS"
  "EXECIO * DISKW MYOUTDD (FINIS"
  "FREE F(MYINDD) F(MYOUTDD)"
  RETURN




Regards,
Vishal
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 -> CLIST & REXX All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Need help on If condition continuatio... ashok_uddaraju CLIST & REXX 4 Fri May 19, 2017 8:55 am
No new posts How to change 'K' or 'M' use Sort vice_versa DFSORT/ICETOOL 5 Thu May 18, 2017 7:11 am
No new posts Adding big TEXT lines to each record ... bshkris SYNCSORT 4 Sat May 06, 2017 1:40 am
This topic is locked: you cannot edit posts or make replies. SORT trick needed bshkris SYNCSORT 6 Tue May 02, 2017 4:35 am
No new posts Running an REXX EXEC implicitly sho7hills CLIST & REXX 3 Thu Apr 20, 2017 8:14 am


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