Example 2

This example demonstrates what happens when you use REXX member selection at the same time as other REXX procedure statements. In this scenario, you are attempting to print members in a data set and to tally a value in those members at the same time.

The first member (MEM1) contains 5 records:


The second member (MEM2) contains 4 records:


The Print Utility REXX member selection default is set to 'P', and the following procedure is supplied.

/* rexx */
if substr(inrec,1,3) = 'AAA'  /* If cols 1-3 in current rec contain 'AAA' */
then x = tally(4,3,Z,'total')   /* then add up the value in columns 4-6 */
if substr(inrec,4,3) = '333'  /* If cols 4-6 contain '333' */
then RETURN DROP MEMBER   /* then drop member from print processing */
if substr(inrec,4,3) = '003'  /* If cols 4-6 contain '003' */
then RETURN PROCESS MEMBER  /* then process (print) member */

The tally for “total” includes the first record from MEM1, even though MEM1 is dropped from the print process. The second and third records don't satisfy the 'AAA' requirement and so aren't tallied, and the subsequent records won't be processed because the decision to drop has been made while processing the third record.)

The tally for “total” also includes the first three records in MEM2. The fourth record is not processed by the REXX proc because the decision to print has been made while processing the third record. The end result of this print action is that MEM1 is dropped, MEM2 is printed, and the tally for “total” equals 117. (111 + 1 + 2 + 3).