File_5-1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

DataStoreOperations

Introduction:

As integration scenarios are becoming more and more complicated,


developers might come across a situation where a message payload of
one interface after successfully being processed might be again
required to be reused in the same interface or any other interface. To
handle such requirements, SAP CPI has introduced new feature
‘DataStoreOperations’ under which various controls can be used in the
iflows for storing/fetching/deleting the message payload of an
interface.

From the palette menu, select the DataStoreOperations to find the


different controls Delete/Get/Select/Write.

Write operation:
Note:
When retrieving a message body from a data store operation,
only XML is supported.

Create an iflow ‘zflow’ as below. To keep it simple I am just passing an


xml file (with two records)

In the ‘Write’ control step, select ‘Global’ for the parameter ‘Visibility’
so that the message stored is visible to other iflows.

Body:

<?xml version="1.0" encoding="UTF-8"?>

<Emp_Details>

<Emp1>

<Name>jack</Name>

<Salary>1000</Salary>

<Location>UK</Location>

</Emp1>

<Emp2>
<Name>will</Name>

<Salary>2000</Salary>

<Location>SA</Location>

</Emp2>

</Emp_Details>

Once the iflow is deployed, we can go to path Overview->Manage Data


Stores, and check that a new data store has been created in the tenant.
GET operation:

Fetch a specific message from the data store.

1. Create a new iflow ‘zflow1’ as below. In this scenario, pass a


different xml file (with one record). The content modifier will pass
the incoming payload as-is to the ‘GET’ operation.
2. In the ‘GET’ operation step, provide the data store name that was
created in the tenant by the ‘Write’ operation.
On deploying the iflow, we can check in the logs of the message monitor
that the GET operation has received a payload of a single record from
Content modifier, but after fetching the message payload (with 2
records) from the data store, it has sent out the fetched payload to the
receiver.
Select operation:

Fetch messages in bulk from the data store.


You can also specify the number of messages you fetch in each
poll.
1. We create a new iflow ‘zflow_select’ as below with similar steps
as in previous section and use the ‘Select’ operation from the
control’s palette.

1. Here I have selected that two messages have to be polled from the
data store to be sent to the receiver.
2. On deploying the iflow, we can observe the results in message
processing log as below-

On observing the data store, we could find out that the Select operation
by default selects the first two messages that were initially added to the
data store.
Delete operation

1. I created a new iflow ‘zflow_del’ as below with same steps as


provided in previous sections and added a ‘Delete’ operation from
the control palette.

1. The value for the parameter ‘Visibility’ is Global, so that the iflow
will look for the given data store ‘TestDSN’ at the tenant level.
3. On deploying the iflow, we could check that the message relating
to the Entry ID specified in the iflow has got deleted and now only
2 entries are available.

Persist Messages
Store a message so that you can access the stored message and
analyze it at a later point in time.
Retrieve Persisted payload in SAP CPI
SAP CPI has an option to store a message at a specific point in the
message processing using Persist. The persisted message can be
retrieved later and use accordingly.
The logical storage location used by the Persist step is the message store.
Physically, the message store uses the same tenant database as the data
store. The overall disk space limit is 32GB.
Since the persisted messages was not part of CPI monitoring view, the
payload has retrieve using OData API. The data can be retrieved using
the message id, which persisted in the DB.
To retrieve payload, a custom integration flow can build as below.
1- https://625c71d4trial.it-cpitrial05.cfapps.us10-
001.hana.ondemand.com/api/v1/MessageProcessingLogs('A
GMRGHYF5uvUVEnxkB-61x66buhT')/MessageStoreEntries
2- Extract this value from output

3- https://625c71d4trial.it-cpitrial05.cfapps.us10-
001.hana.ondemand.com/api/v1/MessageStoreEntries('
3632356337316434747269616c2f6d657373616765737
46f72652f6d6573736167652f41474d52474859463575
765556456e786b422d3631783636627568542f506572
73697374352f33373033653133632d396232312d3461
65622d393062312d373566366439626533303566')/$va
lue
Global Variable: Write Variable in CPI
There are scenarios where you might want to use a variable stored
in one iflow and call it from another process in CPI or to query
OData based on the last successful run from another Iflow. Write
Variables is one such functionality provided by SAP in CPI/HCI.

Scenario: Save the last Successful run date of my IFLOW1 and


check the last successful run in my next IFLOW2

I have used a very simple iflow to explain the procedure. The


same can be used when you need to query other systems based
on the variable stored in another iflow.

In IFlow1: add step Write Variables:


In Flow2: Add Step Content Modifier with below properties:
Creation of a variable:
In our IFlow, we have to include a ‘Write Variables’ shape
to do this. Using simple camel expression as shown below,
we can store values in variables.
Reading Variable value

To read the values stored in variables, all we need to do is


reference the variables as shown below. This can be done
in Message Exchange Properties as well.
Variables have Local scope by default. This means that
they are visible and accessible to only one IFlow.

But what if we wanted to read this value, or possibly even


modify this value from another IFlow? In that case, we will
have to use a Global variable. Like the name suggests, the
scope of this variable is not confined to just one IFlow. This
variable can be read and modified by iflow.

When can something like this be useful? As an example,


suppose the value written by one IFlow is to be used by
another for its processing.
Since Global variables are not limited to one IFlow, when
we look at these variables under Manage Stores, they
have no value mentioned for IFlow Ids.

Deleting a variable

Variables can be deleted from ‘Manage Variable’ screen


under Operations view of your CI tenant by clicking on the
delete icon on the right side of the variable tile.
Retain Period of a variable

The period for which the value of a variable is stored is


400 days from Last Modification date of that variable.
Number Ranges

Now we are going to hop on to the next topic: Number


Ranges. We already know it is a mode of data persistence,
but what exactly does it do and what makes it different?

Number ranges act as sequences which can be used for


marking messages, among other applications. Suppose
that in a particular integration scenario, all messages to
the destination system must have a unique sequence
number. This is where a number range can be of use.

Creating Number Ranges

Before use, Number ranges have to be created by


specifying the following:
• Name: Give a unique name that will be used to
reference this Number Range.
• Description: Not mandatory, but generally a good
practice to include this information to avoid any
confusion in the future.
• Minimum value: A non-negative integer value with
maximum 14 characters. Cannot enter
string/characters here.
• Minimum value: A non-negative integer value with
maximum 14 characters. Cannot enter
string/characters here.
• Field Length: The length of the sequence number
returned by this number range.
• Rotate: If the maximum value is reached, the first
value is picked as the next number in sequence.
Using Number Ranges

Number ranges can be used by referencing them in


Message Headers/Exchange properties.
With every deploy will generate next number.

Deleting a Number Range


Number Ranges can be deleted by clicking on Undeploy
Button on ‘Manage Number Ranges’ screen under
Operations View of your CI tenant.

Retain Period of a Number Range

Number ranges do not have a fixed period. They are


retained until undeployed.

You might also like