Defining a service class for PowerBuilder components

StepsTo create and register a service class for PowerBuilder components:

  1. In the PBL that contains the DataWindow object for the server component, define one or more PowerBuilder custom class user objects.

  2. In each custom class user object, define one or more user-defined events. The event signatures must match one of these (all these events return a long):

    The arguments are the same as those documented for the similarly named DataWindow events in the DataWindow Reference, with the exception of the additional DataStore argument, which gives the user object access to the Web DataWindow data.

  3. In the event script, use return codes to specify whether the server component should cancel the event.

    The return codes are also the same as those documented in the DataWindow Reference. Any of the service classes that implements the event can specify that the event be canceled.

  4. Register the service classes for the component.

    There are two ways to make the user object available as a service class:

NoteUsing server component methods with the DTC If you are using the Web DataWindow DTC or the JSP Target object model, you can use methods of the server component by using the Component property. For example:

webDW.connectToComponent();
webDW.Component.SetServerServiceClasses
		("uo_updatestart");

Example

Suppose that you want to check that data did not exceed a budgeted total before it was updated in the database. You might set up a service class that implements the UpdateStart event.

In the custom class user object in PowerBuilder, select Insert>Event and declare a new event called UpdateStart that returns a long and has one argument of type DataStore called ds:

UpdateStart (DataStore ds) returns long

This script for the UpdateStart event has a DataStore that retrieves data from a budget table and compares it to the component’s data:

DataStore ds_budget
double darray[], total
long ll_upper
integer i

ds_budget = CREATE datastore
ds_budget.DataObject = "d_budget"
ds_budget.SetTransObject(...)
ds_budget.Retrieve( )

// Get data to be validateddarray[] = ds.Object.expenses.Primary
// Add up values in darray
ll_upper = UpperBound(darray)

FOR i = 1 to ll_upper
		total = total + darray[i]
NEXT
IF ds_budget.Object.cf_expense_total < total THEN
		RETURN 1
END IF