Skip to Content
Author's profile photo Merina Acharya

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’ve 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:

I have added additional steps to check whether my variable has any value or not.

 

 

Below are the details in the properties tab, in case I wanted to save the currentDate:

Note: Tick the GobalScope option in properties.

In Flow2: Add Step ContentModifier with below properties:

Note: Save it as Global Variable, else this property would not have any value assigned to it.

In the second Content Modifier, I’ve used the property in my output file:

Deploy iFlow1 first and then iFlow2.

Output for iFlow1:

Output of iFlow2 with the last run date of iFlow1:

Write Variable can also be used in the same iFlow as local variable- save it as a property or header and use it anywhere in your iFlow.

Assigned tags

      10 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Moya Watson
      Moya Watson

      Thanks for sharing the tip, Merina!

      Author's profile photo Gayathri Narayana
      Gayathri Narayana

      very well described! thanks.

      Author's profile photo Nishant Bhatia
      Nishant Bhatia

      Thanks for your work.. keep writing.. 🙂

      Author's profile photo Pravesh Shukla
      Pravesh Shukla

      Hi Merina,

      Nice Blog!

      I have one question ,that is it good practise to use Write Variables at the beginning of i flow, as we have to store LastSuccessFull run but if in case due to some reasons i flow fails, then what?

      As per my understanding it should come before the end message event.

      Make sense?

       

      Regards,

      Pravesh Shukla

      Author's profile photo Merina Acharya
      Merina Acharya
      Blog Post Author

      HI Pravesh,

       

      Yeah you are right, but ive used it here only as an example to show how this functionality works.

       

      Regards,

      Merina

      Author's profile photo Anurag Garg
      Anurag Garg

      HI Merina,

       

      I have a scenario like above but what if SFTP connection fails intermittently. Then write variable is working though scenario failed to push files through SFTP.

       

      Please reply, how can we handle such scenarios.

       

      Many Thanks,

      Anurag

      Author's profile photo Merina Acharya
      Merina Acharya
      Blog Post Author

      Hi Anurag,

       

      This can be handled by adding an  exception where you can reset the last run time.

       

      Regards,

      Merina

      Author's profile photo Sudeep Menakuru
      Sudeep Menakuru

      Hello Team,

      In order to store the Last Run Date which will be further used in the same process but in different execution, why should we define the variable as Global?

      Also in order to do the Delta query using SF adapter, we need to store a date with specific format ending with "Z", how simple we can achieve that?

      Author's profile photo Sankara Bhatta
      Sankara Bhatta

      Hi Acharya,

       

      Nice Blog !!

      I have a JSON payload coming to my i flow having different purchase requsiiton items. something like below

      [

      {

      PRitem: 001

      ...

      ...

      .....

      ....

      Plant : 123

      Plant_dumy : 1234

      },

      PRitem: 002

      ..

      ...

      ...

      Plant : abc

      Plant_dumy : abcd

      }

      ]

       

      I want to store the values of plant and plant_dummy for each item and use them in another iflow. something like

      pritem plant plant_dummy

      001      123      1234

      002      abc       abcd

       

      basically my question can we store a table like data in one iflow and access it another iflow.

       

      thanks

      Author's profile photo Christopher Linke
      Christopher Linke

      You can we update a value in a variable? When I tried to update a value it gives me the error

      com.sap.esb.datastore.DuplicateEntryException: An entry with id G_msgLogDetail does already exist in data store sap_global_store