Additional Blogs by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
Javier-Martin
Product and Topic Expert
Product and Topic Expert

     My previous posts provided an introduction to SAP Sybase Replication Server and how it fits into heterogeneous replication systems. In this post, I would like to begin discussing specific customization and problem solving techniques that can be very useful in many data replication scenarios for both heterogeneous and non-heterogeneous systems through the internal use of SAP Sybase Replication Server function strings.

      Functions strings customization allows you to change default behavior when applying commands to a replicate database, a couple of typical use cases could be:

  • Example 1: Default behaviour for an insert is to perform that insert in the replicate database, but it could also be executed with other extra commands.
  • Example 2:  Modify deletes in a table to perform the delete in the corresponding table and also insert the deleted row in a historical table.

     Customization is especially interesting in heterogeneous replication because you can use specific DBMS syntax to bulid your commands.

Concepts

     Function strings can be defined as templates internally used by SAP Sybase Replication Server to generate the syntax used when applying changes at each replicate database. When talking about function strings we have to define three important concepts:

    • Functions: represent dataserver actions. For example:
        • rs_insert in the function used when inserting rows in replicate database,
        • rs_delete is used when deleteing rows, and
        • rs_update when updating
    • Function instance: is a combination of a Replication Server function and a row coming from the primary database log.
    • Function string: is the specific language template for executing a Replication Server function.

     By default, Replication Server has system functions for common dataserver actions. In case of rs_insert, rs_delete and rs_update, they are internally generated with the default behavior for each replication definition you create. For example, these are default rs_insert, rs_delete and rs_update function strings created for a table called test that has two columns (id int and c char):

     - rs_insert:

               insert test (id, c) values (?id!new?, ?c!new?)

     - rs_update:

               update test set id=?id!new?, c=?c!new? where id=?id!old?

     - rs_delete:

               delete from test where id=?id!old?

How Replication Server uses functions and function strings

The following diagram shows how function and function strings internally work:

  1. Client inserts data in table test.
  2. Rep Agent forwards change to primary Replication Server in a proprietary format called LTL (Log Transfer Language).
  3. Primary Replication Server forwards rs_insert function instance with values from log record.
  4. Replicate Replication Server (the one that manages the connection to the replicate DB) retrieves function string from RSSD and uses it as template to construct the language to send to replicate database.
  5. Replicate Replication Server sends command to replicate database.

Customization

Replication Server includes commands to create new function string clases, create function strings, alter function strings, etc. For example, function strings can be customized to:

  • Generate third-party syntax.
  • Call a stored procedure instead of performing an insert.
  • Discard certain primary changes, like deletes.
  • Call stored procedures, extended stored procedures, or Java classes.

The following how-to-video shows how you can change default function string behavior with an interesting use case:

Note: set video resolution to HD

     Knowing how function strings work in SAP Sybase Replication Server and how you can customize behavior, you can go further and think about Replication Server in terms of database event capture and change default behavior when applying changes to replicate database, or further, be able to run any specific replicate DBMS command or stored procedure.

More details in SAP Sybase documentation:

   

Other/Related Posts:

5 Comments