TSO-ISPF JCL COBOL VSAM DB2 CICS Tools Articles Job Portal Forum Quiz Interview Q&A

Rexx ISREDIT MACRO Examples


Rexx ISREDIT MACRO Examples:

Then following edit macro comments out all lines in a section of COBOL program, section name is passed as a parameter. The edit macro can be invoked from ISPF editor as.

"COMMENT 1000-initialize"

Here comment is the name of the edit macro and 1000-initialize is the section to be commented.

Example 1:

/*******************************REXX**********************************/
"ISREDIT MACRO (PARM1)"
"ISREDIT F 8 ALL" PARM1 /* find the section name at the 8th column*/

CALL ERR_ROUTINE
"ISREDIT LABEL .ZCSR = .A"
/* put the label on the first line of the Section */
CALL ERR_ROUTINE
"ISREDIT (X Y) = CURSOR"
CALL ERR_ROUTINE
X = X + 1
"ISREDIT CURSOR = (X) (Y)"
CALL ERR_ROUTINE
"ISREDIT FIND SECTION NEXT"
IF RC = 4 THEN /*IF IT IS THE LAST SECTION*/
DO
    "ISREDIT CHANGE ALL ' ' '*' 7 .A .ZLAST"
    EXIT
END

ISREDIT (X Y) = CURSOR"
CALL ERR_ROUTINE
X = X - 1
"ISREDIT CURSOR = (X) (Y)"
CALL ERR_ROUTINE

"ISREDIT LABEL .ZCSR = .B"
/* put label on the last line of the section */
CALL ERR_ROUTINE
"ISREDIT CHANGE ALL ' ' '*' 7 .A .B"
CALL ERR_ROUTINE "ISREDIT SAVE"
CALL ERR_ROUTINE
EXIT

ERR_ROUTINE: PROCEDURE EXPOSE RC
IF RC > 0 THEN DO
    SAY "MACRO ERROR!"
    "ISREDIT CANCEL"/* Undo the changes */
    EXIT
END

This edit macro can also be called from a REXX program using an ISPXEC EDIT command.


Example 2:

Write a program to receive a PDS name as input. The program must call a MACRO for each member in the PDS and change the occurrences of CTS to Cognizant. The program must throw error messages in the following conditions.

  • If the dataset name is stated without quotes.

  • If dataset is not found.

  • If dataset contains no members.

/*******************************REXX***********************************/
/* This is the main program which gets the data set name from user    */
/* and validate the dataset and the value will pass to macro program  */
/**********************************************************************/
SAY "ENTER THE NAME OF THE PDS (WITH QOUTES): "
PULL PDSNAME DSN = PDSNAME
MACNAME = "ELTMYMAC"

IF POS("'",DSN) = 0 &	SYSVAR(SYSPREF) <> '' THEN , /* IF NO QUOTES	*/
    DSN = SYSVAR(SYSPREF) || '.' || DSN /* AND PREF NOT NULL, ADD IT	*/
ELSE DSN = STRIP(TRANSLATE(DSN,"","'")) /* REMOVE QUOTES IF USED	*/

CHKLIB = SYSDSN("'"DSN"'")	/* SEE IF DATA SET EXISTS	*/

IF  CHKLIB <> 'OK' THEN DO	/* DATA SET NOT FOUND       */
    SAY 'ERROR -' DSN 'NOT FOUND. CHECK NAME AND QUOTES.' /* ISSUE MSG*/
    EXIT 12	   /* EXIT RC=12	*/
END

JUNK = OUTTRAP('MBR.')	             /* CAPTURE OUTPUT TO MBR. STEM */
"LISTD '" || DSN || "' MEMBERS"      /* ISSUE LISTD CMD AGAINST PDS */
JUNK = OUTTRAP('OFF')	       /* STOP CAPTURING OUTPUT */
DO I = 1 TO MBR.0	           /* LOOP TO GET PAST VOL INFO	*/
    IF MBR.I = "--MEMBERS--" THEN LEAVE     /* IF MEMBER SECTION, EXIT LOOP*/
END
IF I = MBR.0 THEN DO	      /* NO MEMBERS IN PDS	*/
    SAY 'ERROR - NO MEMBERS FOUND IN' DSN'.' /* ISSUE ERROR MSG	*/
    EXIT 12		  /* EXIT RC=12		*/
END

SAY 'PROCESSING' MBR.0 - I 'MEMBERS ...'
DO J = I+1 TO MBR.0	   /* LOOP TO EXECUTE EDIT MACRO */
    PARSE VAR MBR.J MACMEM .	/* GET RID OF ALIAS INFO */
    ADDRESS ISPEXEC "EDIT DATASET('" || DSN || "(" || MACMEM || ")')" ,
                      "MACRO("MACNAME")"
END
SAY 'PROCESSING COMPLETE!'
EXIT 0


MACRO:
/****************************REXX MACRO**************************/
/* THIS MACRO IS USED TO CHANGE OCCURENCES OF CTS TO COGNIZANT */
/***************************************************************/
'ISREDIT MACRO'
ADDRESS ISREDIT

/* CHANGE OCCURRENCES OF CTS TO COGNIZANT */
NM = 'CTS'
FULLNM	= 'COGNIZANT'
"ISREDIT C ALL " NM FULLNM

"ISREDIT SAVE "
"ISREDIT END "

Explanation:

  • The code identifies the members of a dataset and invokes a macro to edit each of the members in a dataset.

  • The macro changes all occurrences of CTS to COGNIZANT in the member and saves the changes.

  • Proper comments must be used wherever applicable for better understanding of the code.

  • Proper comments must be used for better understanding.

  • Indentation must be appropriate for better readability.


Test Your Understanding:

  1. What are the editor assigned labels used in a Macro?

  2. How can a Macro be executed?

  3. How can parameters be passed to a Macro?


If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!

Are you looking for Job Change? Job Portal