37. Writing ISPF edit macros

Consider the following situation: When editing a dataset in ISPF-edit, you want to execute the RXS program myrxs. Myrxs exists on the ISPRLIB library in the TSO session.

Writing in the command line:

==> tso rxs myrxs

and pressing enter, the program myrxs is executed


==> rxs |myrxs

and pressing enter, the program myrxs is executed too. Execution this way opens the following possibilities in myrxs:

In the program you may read the queue edit_screen. This queue contains all lines in the edit dataset on the screen - in the state as currently seen on the screen. COBOL line numbers are ignored; linie-numbers in col 73-80 are ignored if record-length is 80.

The following special situations exists:

Format and blocksize for the stdout dataset will be copied from the dataset underlying the edit session

Due to an oddity in REXX (that is in fact, an oddity in EBCDIC) the | above is to be replaced by an ! when using a keyboard from a nordic country, France, Germany, Austria and Italy



Example 37.1: myrxs contains:

)action in='edit_screen'

)&      start=1

if start = 1 then do

xx = change('yrsa', 'hugo', unit.1, 'first')


if xx <> unit.1 then start = 0 /* if a change has occured */


else do




If command ==> rxs |myrxs is fired, the first occurence of the string 'yrsa' is changed to 'hugo'. The changed dataset is written to <userid>.rxs.data


Example 37.2: myrxs contains:

)action in='edit_screen'

)&      func='sql'   



If the edit screen contains some SQL, writing ==> rxs |myrxs will execute this SQL. If the execution creates output, the rows will be shown in a new edit screen.


Example 37.3

)action in='ourqualif.ourdsn' /* a partitioned dataset */

)&      out='q1'

   mbr = unit.1

"edit dataset('ourqualif.ourdsn("mbr")') macro(mymacro)"

)action in='q1'

)&      address='ispexec'





ISPF macro 'mymacro' is executed on all members in dataset 'ourqualif.ourdsn'.

'Mymacro' could be:

/* REXX */

address isredit


"change 'yrsa' 'hugo' first"


Resulting in a change of 'yrsa' to 'hugo' in first occurence in each member.'Mymacro' must be a member on a dataset allocated to SYSPROC in the ISPF session.


Example 37.4

)action in='edit_screen'

)&      cnt=0

if pos(' IF ', unit.1) > 0 then do

  cnt = cnt + 1

  cnt unit.1


if pos('END-IF', unit.1) > 0 then do

cnt = cnt - 1

cnt unit.1


if pos('SECTION', unit.1) > 0 then do




This coding will trace any un-balance in IF / END-IF in a COBOL program.