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 copy members in a data set and to tally a value in those members at the same time.

The first member (MEM1) contains 5 records:

AAA111BBB456CCC789
AAB222BBB456CCC789
AAC333BBB456CCC789
AAA444BBB456CCC789
AAA555BBB456CCC789

The second member (MEM2) contains 4 records:

AAA001BBB456CCC789
AAA002BBB456CCC789
AAA003BBB456CCC789
AAA004BBB456CCC789

The Copy 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 copy processing */
if substr(inrec,4,3) == '003'  /* If cols 4-6 contain '003' */
then RETURN PROCESS MEMBER    /* then process (copy) member */
return 

The tally for "total" includes the first record from MEM1, even though MEM1 is dropped from the copy 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 copy has been made while processing the third record.

The end result of this copy action is that MEM1 is dropped, MEM2 is copied, and the tally for "total" equals 117. (111 + 1 + 2 + 3).

Related topics