For one PRODUCE statement to print multiple rows, the program must set the associated variables before executing the PRODUCE statement. In this program, a table is defined in working data to contain the address information for three customers. The same names are used in the detail definition to format the labels. Since PRODUCE automatically moves the values in the same‑name working data variables to the detail fields, the program must assign the values to the working data variables. The following segment assumes a variable was defined in working data named IDX to index through the repeating group.
SET IDX = 0
FOR EACH CUSTOMER
ORDERED BY CUSTOMER.NAME
ADD 1 TO IDX
SET L‑NAME(IDX) = CUSTOMER.CUSTNAM
SET L‑ADD(IDX) = CUSTOMER.ADDRESS
SET L‑CTYST(IDX) =
$STRING(CUSTOMER.CITY, CUSTOMER,STATE,
CUSTOMER.ZIP)
IF IDX = 3
PRODUCE CUSTLBL
SET IDX = 0
ENDIF
ENDFOR
As long as complete sets of three are available, the PRODUCE statement executes in the FOR construct. The index, IDX, is reset to zero and the assignment of the label information continues. When there are no more rows, the FOR construct terminates. This could result in one or two unprinted labels. To handle this, a simple IF construct tests the value of IDX after the FOR statement. If it is not zero, then some labels remain to print. The statements in the IF construct blank out the extra labels (to avoid reprinting a label from the last set) and PRODUCE the last labels.
IF IDX NOT = 0
SET IDX = IDX + 1
LOOP VARYING IDX FROM IDX BY 1 THRU 3
MOVE $SPACES TO L‑NAME(IDX)
L‑ADD(IDX)
L‑CTYST(IDX)
ENDLOOP
PRODUCE CUSTLBLS
ENDIF
A subprocedure might be necessary to allow the computer operator to align the label sheet properly at the beginning of the run. You can use the following subprocedure before the FOR construct with the DO statement:
<<ALIGN>> PROCEDURE
LOOP 5 TIMES
LOOP VARYING IDX FROM 1 BY 1 THRU 3
MOVE STAR‑LIT TO L‑NAME(IDX)
L‑ADD(IDX)
L‑CTYST(IDX)
ENDLOOP
PRODUCE CUSTLBLS
ENDLOOP
ENDPROC
STAR‑LIT is a literal value defined in working data. This value consists of a string of 30 asterisks that aligns the sheet.
|
Copyright © 2015 CA Technologies.
All rights reserved.
|
|