Try OpenEdge Now
skip to main content
Programming Interfaces
Input/Output Processes : Creating Reports : Redirecting output : Directing output to a file
 
Directing output to a file
To direct output to a file, use the OUTPUT TO statement followed by the name of the destination file enclosed in quotes. The destination can include the path, or just the filename. If you do not provide a path, the AVM writes the file to the current directory. If the file does not exist, the AVM creates it. If the file does exist, the AVM overwrites its contents.
The i-10-09.p code example is simply the report from the last exercise, removed from the interface code.
i-10-09.p
/*1*/ OUTPUT TO "tut-temp.txt".
  FOR EACH Customer
        NO-LOCK WHERE Customer.Balance >= (Customer.CreditLimit * .85)
        WITH STREAM-IO:
        DISPLAY Customer.Name FORMAT "x(20)" Customer.Contact FORMAT "x(15)"
          Customer.Balance Customer.CreditLimit WITH NO-BOX STREAM-IO.
        FOR EACH Order NO-LOCK WHERE Order.CustNum = Customer.CustNum
          WITH STREAM-IO:
          DISPLAY Order.OrderNum Order.OrderDate Order.ShipDate
            Order.PromiseDate SKIP(1) WITH 2 COLUMNS STREAM-IO.

          FOR EACH OrderLine NO-LOCK
            WHERE OrderLine.OrderNum = Order.OrderNum WITH STREAM-IO:
            FIND Item NO-LOCK WHERE Item.ItemNum = OrderLine.ItemNum.
            DISPLAY OrderLine.Qty OrderLine.ItemNum
              Item.ItemName FORMAT "x(13)"
              Item.Price LABEL "Unit Price"
              Item.Price * Qty (TOTAL) LABEL "Price"
                FORMAT "$zzz,zz9.99 CR"
              WITH NO-BOX STREAM-IO.
          END. /* FOR EACH OrderLine */
        END. /* FOR EACH Order */
      END. /* FOR EACH Customer */
/*2*/ OUTPUT CLOSE.
You can see from the highlighted points that the OUTPUT TO and OUTPUT CLOSE statements control the stream. Also note that the STREAM-IO option must appear in each output frame phrase.
Try running i-10-09.p and then opening tut-temp.txt in the procedure editor. The following figure shows that the content of the file matches what the interface showed in the last exercise: