Creating a PL/B Automation Component


 

A PL/B Automation Component can be any PL/B program that runs under the PLBWIN command. No special coding is required. In this example, we will create a component that will read an AAM file.

 

The program starts by opening or preparing the AAM file.

 

PhoneFile

Afile

 

Name

Dim

20

Phone

Dim

20

Key

Dim

23

 

 

 

 

Trap

DoPrep If IO

 

Open

PhoneFile,"TestPhone"

 

Trapclr

IO

 

The DoPrep function just creates a sample file.

 

DoPrep

 

 

 

Prep

PhoneFile, "TestPhone.txt":
"TestPhone.aam":
"1-20","40",Share

 

Write

PhoneFile;"Sam Smith ":

"555-1234"

 

Write

PhoneFile;"Fred Jones ":

"555-9988"

 

Write

PhoneFile;"Tom Smith ":

"555-1334"

 

Return

 

 

The program then registers an event to indicate a read request and an event to allow component termination. It then goes into a loop waiting for events.

 

 

EventReg

*Client,1,DoRead,ARG1=Name

 

EventReg

*Client, 2, DoExit

 

Loop

 

 

EventWait

 

 

Repeat

 

 

The DoRead function will start to read the AAM file and send each record back as an event. When the OVER flag is set an event indicating no more record will be sent. Since ARG1 was assigned to Name during the EventReg statement, Name will contain the name to search for.

 

DoRead

 

 

 

Pack

Key,"01F",Name

 

Read

PhoneFile,Key;Name,Phone

 

Loop

 

 

  Break

If Over

 

  EventSend

*Client,1,ARG1=Name,ARG2=Phone

 

   ReadKG

PhoneFile;Name,Phone

 

Repeat

 

 

EventSend

*Client,2

 

Return

 

 

The DoExit function will just stop.

 

DoExit

 

 

 

Close

PhoneFile

 

Stop

 

 

The entire program follows:

 

PhoneFile

Afile

 

Name

Dim

20

Phone

Dim

20

Key

Dim

23

 

 

 

 

Trap

DoPrep If IO

 

Open

PhoneFile,"TestPhone"

 

Trapclr

IO

 

EventReg

*Client,1,DoRead,ARG1=Name

 

EventReg

*Client,2,DoExit

 

Loop

 

 

EventWait

 

 

Repeat

 

 

Stop

 

 

 

 

DoPrep

 

 

 

Prep

PhoneFile,"TestPhone.txt":

"TestPhone.aam":

"1-20","40",Share

 

Write

PhoneFile;"Sam Smith ":

"555-1234"

 

Write

PhoneFile;"Fred Jones ":

"555-9988"

 

Write

PhoneFile;"Tom Smith ":

"555-1334"

 

Return

 

 

 

 

DoRead

 

 

 

Pack

Key,"01F",Name

 

Read

PhoneFile,Key;Name,Phone

 

Loop

 

 

  Break

If Over

 

  EventSend

*Client,1,ARG1=Name,ARG2=Phone

 

  ReadKG

PhoneFile;Name,Phone

 

Repeat

 

 

EventSend

*Client,2

 

Return

 

 

 

 

 

 

 

DoExit

 

 

 

Close

PhoneFile

 

Stop

 

 

 

See Also: Automation



Compiler and Runtime Options EVENTREG and EVENTSEND Using PL/B as a Client