Try OpenEdge Now
skip to main content
BPM Events User's Guide
The rule language : Predefined rule actions : println(): Printing values to a file : Printing values in a file
Printing values in a file
In order to redirect the output to a text file, use the following sequence of statements:
*Open a file. Give the full path of the file. If the file does not exist, then it will be created. The openFile function can take a second argument: if true, then the file is opened in append mode. If false or absent, then the file is opened in rewrite mode (all previous content is lost). The syntax is:
val <file_identifier> = openFile(<file_path>);
val <file_identifier> = openFile(<file_path>, <append_flag>);
*Print one or more lines in the file, using:
*Close the file, using:
You may also flush the file: <file_identifier>.flush(). This flushing has the same semantics as in Java and guarantees that the file contents are fully printed from any memory buffer. For example:
rule abc
activated by EVT_A of BP Server::W_COMPLETED{WORKSTEPNAME : "DoTask",
then {
val myfile = openFile("C:\\temp\\test.log");
myfile.println("hello from abc rule");
In case the output of several rules (or of several activations of the same rule) requires writing to the same file, then a global file variable should be used. Indeed, opening and closing the file should only be done once, otherwise the file would be rewritten from the beginning each time. A variable that is global to a module must be declared and used as follows:
*declare a global file variable immediately after the module declaration statement,
*use println() on this variable in any rule that needs to write on the file, and
*close the file in a final rule or in the finalize{} section.
For example:
application BP_3_test_suites
module InfopadTest
val outputFile = openFile("e:\\BP_test_suites\\rules\\InfopadTest.out");
group Group1
{  rule Rule1
  activated by event1 of Infopad::remove
      outputFile.println(" ");
      outputFile.println("Rule1 activated.");
      schedule("InfopadCheckRemoval1", NOW + 10*SEC, type: "Message", value: "Scheduling");
initialize {
    outputFile.println(" ");
    outputFile.println("*** Start of InfopadTest");
    outputFile.println("*** Defining Static Infopads.");
    infoPad1 :=
        new infopad<cell{strSlot:string, intSlot:int,
}finalize {
    outputFile.println("*** InfopadTest done");
    outputFile.println(" ");
Note: Global values like the outputFile value above, are not recoverable because they are transient objects. Only infopads are recoverable. In order to avoid recovery problems, it is preferable to store any global value in an infopad. This is described in Recovery of global variables and file handling.