Step 5: code your application to use the user object

What you have done so far In the previous steps, you defined the GIVE_RAISE remote stored procedure as an external function for the u_trans_database standard class user object. You then specified u_trans_database as the default global variable type for SQLCA. These steps give your PowerBuilder application access to the properties and functions encapsulated in the user object.

What you do now You now need to write code that uses the user object to perform the necessary processing.

In your application script, you can use PowerScript dot notation to call the stored procedure functions you defined for the user object, just as you do when using SQLCA for all other PowerBuilder objects. The dot notation syntax is:

object.function ( arguments )

For example, you can call the GIVE_RAISE stored procedure with code similar to the following:

SQLCA.give_raise(salary)

StepsTo code your application to use the user object:

  1. Open the object or control for which you want to write a script.

  2. Select the event for which you want to write the script.

    For instructions on using the Script view, see the PowerBuilder Users Guide.

  3. Write code that uses the user object to do the necessary processing for your application.

    Here is a simple code example that connects to an Oracle database, calls the GIVE_RAISE stored procedure to calculate the raise, displays a message box with the new salary, and disconnects from the database:

    // Set Transaction object connection properties.
    
    SQLCA.DBMS="OR7"
    
    SQLCA.LogID="scott"
    
    SQLCA.LogPass="xxyyzz"
    
    SQLCA.ServerName="@t:oracle:testdb"
    
    SQLCA.DBParm="sqlcache=24,pbdbms=1"
    
    
    
    // Connect to the Oracle database.
    
    CONNECT USING SQLCA ;
    
    
    
    // Check for errors.
    
    IF SQLCA.sqlcode <> 0 THEN
    
          MessageBox ("Connect Error",SQLCA.SQLErrText)
    
          return
    
    END IF
    
    
    
    // Set 20,000 as the current salary.
    
    DOUBLE val = 20000
    
    DOUBLE rv
    
    
    
    // Call the GIVE_RAISE stored procedure to
    
    // calculate the raise.
    
    // Use dot notation to call the stored procedure
    
    rv = SQLCA.give_raise(val)
    
    
    
    // Display a message box with the new salary.
    
    MessageBox("The new salary is",string(rv))
    
    
    
    // Disconnect from the Oracle database.
    
    DISCONNECT USING SQLCA;
    
  4. Compile the script to save your changes.

NoteUsing error checking An actual script would include error checking after the CONNECT statement, DISCONNECT statement, and call to the GIVE_RAISE procedure. For details, see “Error handling after a SQL statement”.