Skip to Content
Author's profile photo Former Member

How to use Global Variable in SAP PI Mapping

What is Global Variable?

The variable which is accessible to whole program i.e. having global scope throughout a program is called as Global Variable. Here in PI we are actually referencing a definition w.r.t to JAVA as the base of our SAP PI graphical mapping is JAVA only.

What is the need of Global Variables in SAP PI mapping?

There are the cases where we need to pass\share some information or values in PI mapping among all the UDFs. Suppose for e.g. we have multiple UDFs in one graphical mapping which executes in one sequence. One UDF sets some parameters or variables based on any conditions that will be used by another UDF for sending alerts or for some internal validation in PI. These kinds of requirements can be solved by using Global Variables whose scope will be throughout the mapping or all mappings (the Information of deciding scope will be shared below)

How to define GLOBAL VARIABLE in Sap PI Mapping?

There are two ways to define a global variable in SAP PI Mapping.

Method 1: In the Mapping itself (as shown in below screenshot)

We have one ICON in the Message Mapping (Edit Java Sections) which allows us to declare Global Variables which are having scope to the same message mapping in which it is defined. All the UDFs which are created in that mapping can use those variables.


Now when you click on the ICON /wp-content/uploads/2014/10/3_565735.png you will be getting a window where you can declare global variables and can initialize with a default value (as shown below)


Three variables are defined and are initialized as you see in the screenshot. Now these variuables can be used in UDFs.

Set it in one UDF like /wp-content/uploads/2014/10/2__565782.png and use it in aother as  /wp-content/uploads/2014/10/4_565829.png

Method 2:

In second options we will be creating a JAVA Mapping which will be imported in SWCV as Imported Archives and this allows us to use a Global Variable throughout all the mappings defined in the SWCV. So in this case the scope of our variable is increased to mappings not limited to UDFs.

The only thing we need to take care of that we need to initialize the global variables everytime when you are using it in UDF otherwise it will read the old values set by any other mapping or UDF. Also you need to import class name in import section of UDF and use variable as <ClassName>.<VariableName>

The Code is:


In Imported Achieves it will be like:


In Import Section of UDF, import your class like /wp-content/uploads/2014/10/7_565839.png

In UDF set variable like this: /wp-content/uploads/2014/10/8_565840.png

and use it like this  /wp-content/uploads/2014/10/9_565853.png

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Nice doc, with all relavent information in one page 🙂

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks Ashutosh 🙂

      Author's profile photo Former Member
      Former Member

      Well documented. Learnt a new thing today.   🙂

      Author's profile photo Former Member
      Former Member

      Gud one.. Nice blog..:)

      Author's profile photo Gaurang Joshi
      Gaurang Joshi

      Nicely documented Ashutosh.

      Author's profile photo Ramachandra Motati
      Ramachandra Motati

      Very good

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks Ram 🙂

      Author's profile photo Suresh Pal
      Suresh Pal

      HI Ashu
      I try to implement this by using second method.For which i have imported a archived file into ESR then add package name to import. the whole scenario is implement without any error.but at run time i m getting Exception NoClassDefFoundError.As Archived class in not available to Function Library class. Please help me to resolve it.

      Thanks 🙂

      Author's profile photo Former Member
      Former Member


      I have a sync scenario where I need use a value from request in my response message mapping. I need to use this value to filter out the response (source message) and map it to response(target). Can you guys guide me on how to achieve this?


      Author's profile photo Suresh Pal
      Suresh Pal


      You can try the links below for reference to solve your purpose.


      Hope it will Help.



      Author's profile photo Pavlo Astashonok
      Pavlo Astashonok

      I tried the first scenario through the dedicated button, but I have no such button on my message mappings as on the screenshots above. Is it the limitation of my version?

      I have SAP PO 7.40 SP08 Java Single Stack