Showing posts with label Rexx. Show all posts
Showing posts with label Rexx. Show all posts

Friday, January 17, 2020

REXX: Setting dataset profile using REXX MACRO

/* REXX */                            
ADDRESS ISREDIT                       
"MACRO (PARM)"                        
PARM = TRANSLATE(PARM)                
IF PARM = "COBOL" ! PARM = "" THEN    
DO                                    
   "HI COBOL"                         
   "STATS ON"                         
   "CAPS OFF"                         
END                                   
IF PARM = "REXX" THEN                 
DO                                    
   "HI REXX"                          
   "STATS ON"                         
   "CAPS OFF"                         
END                                   
IF PARM = "JCL" THEN                  
DO                                    
   "HI JCL"                           
   "STATS ON"                         
   "CAPS OFF"                         
END     
EXIT               

Save this REXX macro as SETPROF.

Examples:

To set the profile for JCL :  TSO SETPROF JCL
To set the profile for REXX : TSO SETPROF REXX
To set the profile for COBOL : TSO SETPROF (or) TSO SETPROF COBOL

Executing this macro without any parameters would set the profile for COBOL. 

Thursday, August 25, 2016

REXX: LMINIT, LMOPEN, LMMLIST, LMCLOSE, LMFREE

We shall read all member names using LISTDS "Dataset" Members. But however, I felt that this technique requires some logic to ignore certain statements before we could really get hold of the member name.

So,how to read all members of a Dataset without having any additional logical overhead?

It is possible via LMMLIST. We will go through the steps briefly in this post.

Step 1: LMINIT

LMINIT generates a DataId for the dataset.

REXX can be executed in foreground or background. When we execute from background, the DDNAMES are already allocated. In Foreground, we have to allocate the DDNames. This DDName can be provided in the LMINIT or we shall directly provide the Dataset Name. When we are providing DDname, we should use the keyword DDNAME. When we are providing the dataset, we should use the keyword DATASET.

In our example, we are using DATASET.

Dataset = "DATASET('"Your-Dataset"')"            
address "ISPEXEC"                                       
"LMINIT" Dataset "DATAID(DataId) ENQ(SHR)"

Step 2: LMOPEN

LMOPEN opens dataset associated with DataId generated using the LMINIT step.
Option INPUT means its only read only.
Option OUTPUT means its for writing the dataset. When opened with OUTPUT option, then it is necessary to have a matching LMCLOSE. If LMCLOSE is not issued for the DataID, then the DataID is not released until ISPF terminates.

"LMOPEN DATAID("DataID") OPTION(INPUT)"   

Step 3:

DO FOREVER
  "LMMLIST DATAID("DataId") OPTION(LIST) MEMBER(Member) STATS(NO)"      IF RC = 8 THEN LEAVE
   SAY MEMBER
END 

This step displays you all the member names.

Step 4:
"LMCLOSE DATAID("DATAID")" 

Close the DataID.

Step 5:
"LMFREE DATAID("DATAID")"   

Free the DataID.

Incase of questions, please drop your questions in the comments.

Sunday, August 21, 2016

REXX: Left and Right Function is to beautify

Left and Right function...

Normally every programmer uses Left and Right function to strip the characters from left of a string or Right of a string.

For example:

String="hello"
Result=left(String,4)

This would REXX procedure would return Result as "hell".

REXX is normally used to automate routine manual tasks or generating codes. In order to keep the readability of the code in place, it is necessary we use the right functions to give us a standard alignment throughout the generated source.

The function Left and Right helps us a lot in the regard.

For example: Our task is to give a rating to every country in the world.

Country1="India"
Country2="USA"
Country3="Germany"

Rating1="1"
Rating2="2"
Rating3="3"

Statement1=left(Country1,20)!!left(Rating1,4)
Statement2=left(Country2,20)!!left(Rating2,4)
Statement3=left(Country3,20)!!left(Rating3,4)

This would result in a proper alignment.

Result would be...

India               1   
USA                 2   
Germany             3   

Featured Post

REXX Skeleton: Submitting jobs through Rexx

Submitting jobs through REXX and reading the spool through REXX gives us immense potential to automate many manual activities in mainframes....