Directives
REPEAT DATA TO ... ON ... Repeat/Duplicate output
  The REPEAT DATA directives are a +PxPlus Exclusive
Formats
1. Replicate output sent to one file on another REPEAT DATA TO file1 ON file2 ,ERR=stmtref
2. Terminate replication REPEAT DATA TO file1 END ,ERR=stmtref
3. Define a control file for auto-replication REPEAT DATA CONTROL FILE ctrlfile$ ,ERR=stmtref
4. Define an error handler for replication REPEAT DATA ERROR_HANDLER errhdlr$ ,ERR=stmtref

Where:

file1 The file number whose output commands will be replicated. (Primary)
file2 The file number that will receive the replicated output commands. (Replicated)
ctrlfile$ A string containing the name of a file that defines the auto-replication rules for data files.
errhdlr$ A string containing the name of an error handler that will be called to process any errors that occur during the replication process.
stmtref Program line number or statement label to which to transfer control.
   
Description The REPEAT DATA directive is used to control the automatic replication of all PRINT, WRITE, INSERT, UPDATE or REMOVE directives sent to one file (the primary file) to another file (the replicated file)..

The purpose of this directive is to allow programs to create mirror copies of reports and/or data files without having to issue identical PRINT or WRITE statements to two separate files. While data replication is active, all output directives to the primary file will be sent to the replicated file.

When repeating the output, the system will internally process the directive twice -- once for the primary file and again for the replicated file.

Note that auto-increment/decrement options will only be done once.

A unique error handler can be specified to trap any errors that might occur during the replication process. If no error handler is present, normal error processing will occur with the value in LFA indicating the file on which the error occurred.

   
Format 1 Replicate output sent to one file on another

REPEAT DATA TO file1 ON file2 ,ERR=stmtref

This format initiates the replication of all PRINT, WRITE, INSERT, UPDATE or REMOVE directives sent to file1 on file2. Once the directive is executed, all subsequent output directives to file1 will also be sent to file2.

Both files must be open at the time the directive is executed.



*Note* The system will check to see if the file you are repeating data for itself is the target of data replication. If a looping condition exists within the data replication (file1 repeats file 2 and file2 repeats file 1) an error #89 "File access denied -- I/O operation pending" will be generated.


Format 2 Terminate replication

REPEAT DATA TO file1 END ,ERR=stmtref

This format terminates the replication of the output going to file1.

   
Format 3 Define a control file for auto-replication

REPEAT DATA CONTROL FILE ctrlfile$ ,ERR=stmtref

This directive format defines the control file that the system will check to see if automatic replication is desired. If the pathname of a file being updated matches an entry in this control file, the system will initiate replication automatically. The pathname check is performed whenever the first output operation is done to a file.

This directive format can only be used when the Data Mirroring (SQL Mirror) module is enabled within PxPlus.

For additional information on the format of this file, refer to the Data Mirroring documentation.

   
Format 4 Define an error handler for replication

REPEAT DATA ERROR_HANDLER errhdlr$ ,ERR=stmtref

This format defines an error handler that will be invoked whenever an error occurs while attempting to replicate an output directive, at which point the program defined by errhdlr$ will be called with the following information:

Arg Type Contents Description
1 String Directive$ This string will contain the type of operation being performed (WRITE, INSERT, UPDATE, PRINT, REMOVE, PURGE)
2 Number ERR This argument will have the error condition that was detected during the replication operation.
3 Number PrimFileno This will contain the primary file number.
4 Number ReplFileno This will contain the replication file number (or -1 if the error occurs during the OPEN).
5 String RepPath$ This will contain the pathname for the replication data file

The error handler is intended to allow the application to log the problem encountered and to take the necessary corrective action. Generally, it should EXIT in order to resume execution of the original program.

If the Error handler exits with an error itself (EXIT nnn), the application will have the original error code reported and the standard program exception logic processing will apply.

   
Examples In the following example, the printed report will be sent both to the viewer and to a PDF file. All PRINT directives will send output to both files.

0010 BEGIN
0020 OPEN (1)"*viewer*"
0030 OPEN (2)"*pdf*;file=\junk.pdf"
0040 REPEAT DATA TO 1 ON 2
0050 PRINT (1)'FONT'("Courier New",1),'DF',
0060 WHILE 1
0070 READ DATA COMPANY$,CUSTNO$,NAME$,ADDR$,OWES,END=*BREAK
0080 IF LINESLEFT<1 OR COMPANY$<>CURCOMP$ THEN GOSUB NEWPAGE
0090 PRINT (1)CUSTNO$,@(10),NAME$,@(40),ADDR$,@(70),OWES:"-$###,##0.00"
0100 LINESLEFT--
0110 WEND
0120 END
0130 !
0140 NEWPAGE:
0150 IF PAGENO<>0 THEN PRINT (1)'FF',
0160 PAGENO++
0170 PRINT (1)"Page:",PAGENO:"###0",@(30),"Client list for "+COMPANY$
0180 PRINT (1)
0190 PRINT (1)"Client",@(10),"Name",@(40),"Address",@(70),"Balance"
0200 PRINT (1)"------",@(10),DIM(20,"-"),@(40),DIM(20,"-"),@(70),"------------"
0210 PRINT (1)
0220 LET LINESLEFT=50
0230 LET CURCOMP$=COMPANY$
0240 RETURN
0500 DATA "ABC","000047","Cyclops Car Dealer","6675 Cherry",3.12
0510 DATA "ABC","000122","Global Undergarments","823 Maple Lodge Court",99.54
0520 DATA "ABC","000192","The Hungry Incorporated","5582 2nd Avenue",.55
0530 DATA "ABC","000295","The Hungry Magazine","8576 Major Mackenzie",71.74
0540 DATA "ABC","000310","New Dimensions Company","8052 Center Avenue",5.93
0550 DATA "ABC","000332","Cyclops Computing","7723 Fantasy Island",7.61
0560 DATA "DEF","000355","Kitty Kay Undergarments","2124 Major Mackenzie",4.55
0570 DATA "DEF","000385","New Age Importers","1743 Allstate Parkway",73.84
0580 DATA "DEF","000461","SOTA Golf club","4377 Major Mackenzie",63.66
0590 DATA "DEF","000555","Mike was here","8450 Buga-Buga Drive",11.43

File replication can be cascaded for output to multiple files. For example, the logic in NEWPAGE could be changed to produce one PDF file for each company:

0140 NEWPAGE:
0150 IF PAGENO<>0 THEN PRINT (1)'FF',
0160 CLOSE (3)
0170 OPEN (3)"*pdf*;file=\"+COMPANY$+".pdf"
0180 PRINT (3)'FONT'("Courier New",1),'DF', ! Set font
0190 REPEAT DATA TO 2 ON 3
0200 PAGENO++
0210 PRINT (1)"Page:",PAGENO:"###0",@(30),"Client list for "+COMPANY$
0220 PRINT (1)
0230 PRINT (1)"Client",@(10),"Name",@(40),"Address",@(70),"Balance"
0240 PRINT (1)"------",@(10),DIM(20,"-"),@(40),DIM(20,"-"),@(70),"------------"
0250 PRINT (1)
0260 LET LINESLEFT=50
0270 LET CURCOMP$=COMPANY$
0280 RETURN