Try OpenEdge Now
skip to main content
Programming Interfaces
External Program Interfaces : Named Pipes : Windows named pipes : Coding the ABL program
 
Coding the ABL program
The ABL program:
*Assumes that the C program creates and connects the named pipe
*Refers to the named pipe using the name the C program specifies
*Uses the INPUT FROM statement to read the named pipe
*Uses the OUTPUT TO statements to write the named pipe
*Uses the INPUT CLOSE and OUTPUT CLOSE statements to close the named pipe
The i-ablpip.p ABL program demonstrates reading and writing a Windows named pipe, custpipe.
i-pipex1
/* i-ablpip.p */
/* Reads and writes a Windows named pipe */

/* 1. Define buttons */
DEFINE BUTTON bWrite LABEL "Write to Pipe".
DEFINE BUTTON bRead LABEL "Read from Pipe".
DEFINE BUTTON bQuit LABEL "Quit".

/* 2. Define form */
FORM SKIP(5)
SPACE(5) bWrite SPACE(5) bRead SPACE(5) SKIP(1)
SPACE(18) bQuit SKIP(5)
WITH FRAME f TITLE "Pipe Test".

/* 3. Define write trigger */
ON CHOOSE OF bWrite IN FRAME f DO:
OUTPUT TO \\.\pipe\custpipe APPEND.
FOR EACH Customer NO-LOCK:
DISPLAY Customer.Name.
END.
OUTPUT CLOSE.
END.

/* 4. Define read trigger */
ON CHOOSE OF bRead IN FRAME f DO:
DEFINE VARIABLE ix AS INTEGER NO-UNDO.

INPUT FROM \\.\pipe\custpipe.
SET ix.
INPUT CLOSE.
FIND Customer NO-LOCK WHERE Customer.CustNum = ix.
DISPLAY Customer WITH 2 COLUMNS FRAME y OVERLAY TITLE "Customer Info".
END.

/* 5. Define quit trigger */
ON CHOOSE OF bQuit IN FRAME f DO:
APPLY "window-close" TO CURRENT-WINDOW.
END.

/* 6. Enable all objects, then wait on a close event */
ENABLE ALL WITH FRAME f.
WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW.
The i-ablpip.p program:
1. Defines three buttons, labeled "Write to Pipe," "Read from Pipe," and "Quit."
2. Defines a form to contain the buttons.
3. Defines a trigger for the Write to Pipe button. The trigger redirects output to named pipe custpipe, displays (to named pipe custpipe) the name of each Customer in the sports2000 database, and closes the named pipe.
In an OUTPUT TO statement, \\. means the current machine. To communicate with remote machine "pcdev68," for example, use \\pcdev68. This follows Uniform Naming Conventions (UNC).
The OUTPUT TO statement uses the APPEND option, which causes ABL to open the named pipe without first creating it. This is necessary because ABL cannot create named pipes.
4. Defines a trigger for the Read to Pipe button. The trigger defines an integer data item, reads named pipe custpipe, assigns the value read (a customer number) to the integer data item, closes the named pipe, retrieves the row of the customer table with the specified customer number, and displays the columns of the row.
The INPUT FROM statement assumes that the pipe exists and that another process writes to it. The INPUT FROM statement blocks until the other process writes to the named pipe.
5. Defines a trigger for the Quit button.
6. Enables all objects in the frame and waits on a close event.