Example 3:

This example is an ISPF edit macro, which invokes the LMMLIST service to loop through all of the members of the data set being edited. This macro starts with the ISREDIT MACRO statement, which takes a parameter of a macro name. The data ID and member name are retrieved using the ISREDIT DATAID and ISREDIT MEMBER statements respectively. LMOPEN opens the data set so that LMMLIST can use it. The member name variable is blanked, so that the LMMLIST service starts at the first member in the data set. LMMLIST is called within a loop, which stops when LMMLIST returns a non-zero return code, either because all members have already been listed, or because an error occurred. If the LMMLIST service returns successfully, the EDIT service is called with the member name and the edit macro which was an input parameter. After the loop completes, the member list is freed with the OPTIONS(FREE) parameter of the LMMLIST service, and the data set is closed with the LMCLOSE service. This example is shipped with ISPF as 'ISP.SISPSAMP(ISRMBRS)'.

/*REXX****************************************************************/
/*   ISPF edit macro to process all members of partitioned data set, */
/*   running a second, user-specified, ISPF edit macro against each  */
/*   member.                                                         */
/*                                                                   */
/*   To run:                                                         */
/*    Enter "ISRMBRS macname" on the command line, where macname is  */
/*    the macro you want run against each member.                    */
/*********************************************************************/

'ISREDIT MACRO (NESTMAC)'

/*********************************************************************/
/* Get dataid for data set and issue LMOPEN                          */
/*********************************************************************/
'ISREDIT (DATA1) = DATAID'
'ISREDIT (CURMEM) = MEMBER'
Address ispexec 'LMOPEN DATAID('data1') OPTION(INPUT)'
member = ' '
lmrc = 0

/*********************************************************************/
/* Loop through all members in the PDS, issuing the EDIT service for */
/* each.  The macro specified on the ISRMBRS invocation is passed as */
/* an initial macro on the EDIT service call.                        */
/*********************************************************************/
Do While lmrc = 0
  Address ispexec 'LMMLIST DATAID('data1') OPTION(LIST),
                  MEMBER(MEMBER) STATS(NO)'
  lmrc = rc
  If lmrc = 0 & member /= curmem Then
    do
      Say 'Processing member' member
      Address ispexec 'EDIT DATAID('data1') MEMBER('member')
                      MACRO('nestmac')'
    end
End

/*********************************************************************/
/* Free the member list and close the dataid for the PDS.            */
/*********************************************************************/
Address ispexec 'LMMLIST DATAID('data1') OPTION(FREE)'
Address ispexec 'LMCLOSE DATAID('data1')'

Exit 0