Skip to Content

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.

/wp-content/uploads/2014/10/1_565734.png

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)

/wp-content/uploads/2014/10/2_565781.png

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:

/wp-content/uploads/2014/10/5_565830.png

In Imported Achieves it will be like:

/wp-content/uploads/2014/10/6_565838.png

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

To report this post you need to login first.

9 Comments

You must be Logged on to comment or reply to a post.

  1. 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 🙂

    (0) 
  2. Sathish Venkataraman

    Hi,

    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?

    Thanks

    (0) 

Leave a Reply