Pages

Saturday, June 14, 2014

REXX - Count records in PDS in Mainframe



This REXX code is to count the record in the PDS in Mainframe, just copy paste it into the pds and execute it



/*Rexx                                                                */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Runs ICETOOL to count records                                      */
/* */
/*                                                                    */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* get dataset name                                                   */
/*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ */
/*                                                                    */

TRACE o
X = MSG("Off")

arg count_dsn
if length(search_dsn)=0 then do
   say "Dataset name required"
   say "Enter dataset name or press enter to quit"
   pull count_dsn
   if length(count_dsn)=0 then exit
   end

count_dsn = strip(count_dsn,b,"'")

/*                                                                    */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* check dsorg of dataset and determine type of record count          */
/* to perform.                                                        */
/*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ */
/*                                                                    */

x = LISTDSI("'"count_dsn"'" directory smsinfo)

Select
When SYSDSORG = PO Then
   Do
   Say "Sorry, this function does not work for libraries"
   Exit 4
   End
When SYSUNIT ^= 3390 Then
   Do
   Say "Sorry, this function only works for files on disk"
   Exit 4
   End
When SYSDSORG = VS Then Call VCount
OTHERWISE
   Call DCount


Exit Return_Code

/*                                                                    */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*                                                                    */
/*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ */
/*                                 */
DCOUNT:

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Count DD                        */
/*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _*/
/*                                 */

"FREE  da('"count_dsn"')"

"ALLOC File(countdd) da('"count_dsn"') shr"

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Toolin                          */
/*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _*/
/*                                 */

  toolin = 'ttlu.BASE.cntl(icecount)'

"FREE FILE(TOOLIN)"
"FREE  da('"TOOLIN"')"

"ALLOC  F(toolIN) da('"TOOLIN"')"

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Toolmsg                         */
/*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _*/
/*                                 */

  tmsgdsn = 'TTLU.']]SYSVAR("SYSUID")]]'.toolmsg'

"FREE FILE(TOOLMSG)"
"FREE  da('"TMSGDSN"')"


"DELETE '"tmsgdsn"'"
"ALLOC F(toolmsg) DA('"tmsgdsn"')
 NEW CYLINDERS CATALOG SPACE(1,1)
 UNIT(SYSDA)
 BLKSIZE(0) RECFM(F,B,A) LRECL(133)"

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* DFSMsg                          */
/*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _*/
/*                                 */

dmsgdsn = 'TTLU.']]SYSVAR("SYSUID")]]'.dfsmsg'

"FREE FILE(DFSMSG)"
"FREE  da('"DMSGDSN"')"

"DELETE '"dMsgdsn"'"
"ALLOC F(dfsmsg) DA('"dMsgdsn"')
 NEW CYLINDERS CATALOG SPACE(1,1)
 UNIT(SYSDA)
 BLKSIZE(0) RECFM(F,B,A) LRECL(133)"

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Run                             */
/*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _*/
/*                                 */

/* "ICETOOL"     */

ADDRESS LINKMVS ICETOOL
Retcd = RC
If Retcd ^= 0 Then Say 'Return code is ' RC

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Free datasets                   */
/*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _*/
/*                                 */
Address TSO

  "FREE FILE(toolin)"
  "FREE FILE(toolmsg)"
  "FREE FILE(dfsmsg)"

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Dig out the record count from   */
/* the Toolmsg file                */
/*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _*/
/*                                 */

  "FREE FILE(INDD)"
  "ALLOC FILE(INDD) DA('"tmsgdsn"') SHR",

  eof = 'no'                            /* initialize end-of-file  */
  hit_count=0
  x t_count=0

"EXECIO * DISKR Indd (STEM Irec." /* READ A LINE             */

DO x = 1 TO Irec.0

/*      Say 'Checking line ' Irec.x  */

        If substr(Irec.x,2,22) = 'ICE628I 0 RECORD COUNT' Then
           Do
           Count = substr(Irec.x,27,15)
           If count = 000000000000000 Then
              Count = 0
           Else
           Count = strip(substr(Irec.x,27,15),l,'0')

Say 'The Record Count for dataset ' Count_dsn ' = ' count

        "FREE FILE(indd)"
        "FREE FILE(toolin)"
        "FREE FILE(toolmsg)"
        "FREE FILE(dfsmsg)"
        "FREE FILE(Countdd)"
           Exit
           End
     End
  End
        "FREE FILE(indd)"
        "FREE FILE(toolin)"
        "FREE FILE(toolmsg)"
        "FREE FILE(dfsmsg)"
        "FREE FILE(Countdd)"
Return
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* VCOUNT                                                             */
/*                                                                    */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
VCount:

X = OUTTRAP(Irec.)
ADDRESS TSO
"LISTC ENT('"Count_DSN"') ALL"

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* Analyze outtrap & extract the   */
/* relevant parameters             */
/*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _*/
/*                                 */


DO x = 1 TO Irec.0

/* Say "Rec number is " x                     */
/* Say "Record being checked is " Irec.x      */

   If substr(Irec.x,8,9) = 'REC-TOTAL' Then
      Do
      Count  = strip(substr(Irec.x,17,15),l,'-')
      Say 'The Record Count for dataset ' Count_dsn ' = ' count
      Exit 0
      End
End


Return

REXX Basics

What is REXX?

•REstructered eXtended eXecutor language
•Developed by M.F.Cowlishaw of IBM U.K.
•Introduced in 1983
•Highly versatile programming language
•Can  be intermixed with commands to different host environments

Setting up to Execute REXX Programs on TSO/ISPF

This is what you can do so that you will be able to execute your REXX program on MVS TSO/ISPF.

There are several ways that this can be done. 

1. The simpliest of them all, dumb way. 

If you do it this way, you can’t create and use REXX external subroutines. 
Briefly: no setup is done. 
You just put your REXX program in a PDS member or even in a sequential file. 
Then execute it this way from the command line of any ISPF panel: 

TSO EXEC 'the-name-of-the-PDS(member-name)' EXEC

2. The "Ideal way" from the point of view of the person executing the program. 
not so ideal for the technical support personnel.

Your REXX program is a member in a PDS that everyone has read access to. 
This PDS name is specified in the TSO Logon Procedure that is executed everytime you and everyone logs on. 
This is a part of it.

//TSOSTEP EXEC PGM=IKJEFT01
//SYSTSPRT DD TERM=TS 
//SYSEXEC DD DSN=the-name-of-the-pds,DISP=SHR
// DD DSN=name-of-another-pds,DISP=SHR


3. You wait till you get into ISPF. Then you type in the following in option 6, or on the ISPF panel command line, preceded by the word TSO:


ALTLIB DEACTIVATE APPL(EXEC) 
ALTLIB ACTIVATE APPL(EXEC) DA('name-of-your-REXX-PDS')

You have to do this on both halves of a split screen and every time you log on. 
A suggested way of doing this is to put the above command in a CLIST or REXX program, then execute the program. 
This example shows a CLIST.

ALTLIB DEACTIVATE APPL(EXEC) 
ALTLIB ACTIVATE APPL(EXEC) DA('name-of-your-REXX-PDS') 
This example shows a REXX program.

/* REXX */ 
"ALTLIB DEACTIVATE APPL(EXEC)" 
"ALTLIB ACTIVATE APPL(EXEC) DA('name-of-your-REXX-PDS')"

REXX - HELLO WORLD

Let try out our first REXX module and enjoy.

/* REXX */
SAY 'HELLO WORLD'

Put this in a PDS member (ideally, create one like Letmetry.REXX.EXEC).

Now, there are various ways by which you can invoke a REXX program.


1. From ISPF main panel, run the command

TSO EX 'Letmetry.REXX.EXEC(HELLO)' EX


2. From READY Prompt, run the command,

EX 'Letmetry.REXX.EXEC(HELLO)' EX



3. Using 3.4, browse to the PDS Letmetry.REXX.EXEC.
Before the member HELLO, enter EX and press enter.



4. You can also run the REXX program through a JCL. The following is the JCL step that you need.


//REXXBTCH EXEC PGM=IKJEFT01
//SYSEXEC DD DSN=MYHQL.REXX.EXEC,DISP=SHR
//SYSTSPRT DD SYSOUT=*
//SYSTSIN DD *
%HELLO
/*

The above are the manual ways. Below are the advanced methods which needs special privileges

IF you have added the PDS to SYSEXEC then we can execute even by below commands. This needs admin access, Just execute this once and using the below methods you can easily execute them

/* rexx */
/* Rexx lib */
DSNAME = 'BNKSPS.TSO.CMD'
DDNAME = 'SYSPROC'
 /* To get all DSNs already associated to SYSPROC    */
ADDRESS ISPEXEC "QBASELIB" DDNAME "ID(DSLIST)"
 /* ADDRESS ISPEXEC "GETPROF DSLIST" */
say DSLIST;
 /* to allocate DSNs already allocated to SYSPROC plus my DSN */
"ALLOC F("DDNAME") DA("DSLIST",'"DSNAME"') SHR REUSE"
RETURN


1. You just need to execute command from ISPF,

TSO HELLO


2. From READY prompt, just enter


HELLO