Replicating Data using Replication Tasks

Objective

After completing this lesson, you will be able to replicate data using replication tasks

Replication Tasks

Now that you’re familiar with the basic process for replication, let’s implement replication in a more sustainable way.

Setting up and maintaining replication is possible by executing SQL statements in the SQL Console. But this approach means that the objects that are created in the database will be owned by your user ID and this can lead to problems when others need to take over the objects. Also, transportation of the database objects isn’t possible.

Best practice is to develop the objects using source files and then build/deploy to generate the database artifacts in an HDI container.

The Replication Task

To manage replications, you create a .hdbreptask file to define the metadata of the replication. The metadata describes the:

  • Remote source

    Name of the Remote Source object used to access the source data.

  • Remote source object

    Name of the table, view, or file you want to access.

  • Target table

    Name of the table where the replicated data will be stored

  • Replication behavior

    You could choose to replicate all data only once. This is usually referred to as an initial load. This is useful if you wanted a snapshot of your data. You could also choose real-time replication without initial load if you only need future data. Then, you could also want to replicate changes in the structure of the table.

The following options are available:

  • No data transfer

    If you just want a copy of the source data structure, but without the source data. This is equivalent to a CREATE TABLE <...(new table)> like <...(existing table)>statement.

  • Initial load only

    If you just want a copy of the current data but no replication of future data. This is called a snapshot.

  • Initial + real-time

    Most probably, you want current data and future changes.

  • Initial + real-time with structure

    The same as the previous option, but it will also replicate the changes in the source table structure. Only works for tables.

  • Real time

    You could only need future data but no current data.

  • Real-time only with structure

    Same as the previous option but with replication of the table structure.

Once built/deployed, the replication task generates the different objects needed in the SAP HANA database. These include:

  • A virtual table
  • A target table
  • A start procedure (.START_REPLICATION) to set up the replication
  • A second procedure (.RS_SP) to execute individual subscription commands

You need to call the main start procedure to create the remote subscription, triggers, and so on. The Replication Task only executes an initial load.

The second procedure can be called for maintenance or to execute single commands such as Reset, Drop, or any other subscription steps.

Project Setup

If your target is an on-premise SAP HANA database, use the Web IDE for SAP HANA.

If your target is an SAP HANA Cloud database, use the SAP Business Application Studio.

For both tools, you first need to set up a project and a HDB module to manage your development objects.

To access the remote sources, the following steps are needed:

  • Create and then add a user-provided service (UPS) as a resource in your mta.yaml file.
  • Add privileges in a .hdbgrants file.

You can create the user-provided service directly in SAP Business Application Studio as shown in the following screen capture:

Note

The schema name is entered automatically as you enter the user name. But you can change it to another schema, or even not specify any schema at all.

If your target is an on-premise database, you can create the User-Provided Service in XSA Cockpit:

Note

Be careful to add the "hana" tag if it's not provided by the template.

The template doesn’t provide any schema parameter, but you could also specify a specific schema name.

The .hdbgrants file must include the required authorizations for both object owner and application user as shown in the following example:

Launch the video below to learn how to set up the project in Business Application Studio:

Launch the video below to learn how to set up the project in SAP Web IDE, if your target is an on-premise database:

Replication Task Creation

Once your project is correctly set up, you can create the replication task using the form-based editor:

The steps are as follows:

  • Connect to the remote source
  • Choose the desired source object
  • Choose replication behavior property
  • Build/Deploy
  • In the Database Explorer, execute the generated start procedure.
  • Modify the source data
  • Check the target table

Launch the video below to learn how to create a replication task:

Log in to track your progress & complete quizzes