Using variables
A variable is a placeholder for a value in the Java code.
This section provides the following information about using variables
in transformation code:
Using generated business object variables and attributes
This section provides information about generating business
object variables for the source and destination business objects.
When you add a business object to the map, Map Designer Express automatically
generates the following:
- An instance name
The instance name that Map Designer Express generates
is a system-declared local variable that you can use to refer to
this business object
in the mapping code. It is prefixed with the letters Obj, which is followed by the name of the business object definition.
Example: If you add Customer to the map, its instance name is ObjCustomer. Map Designer Express generates
an instance name for both the source
and destination business
objects.
When you write code in Activity Editor, you use the instance
name to refer to the business object and its attributes.
- An index for the business object within
a business object array (if the business object is multiple-cardinality)
The business object index represents the order of this source
or destination business object. The index number of the first source
and destination business objects in a map is zero. Additional business
objects take the next available index number, such as 1, 2, 3, and
so on.
When the map is executed, the index number represents the position
of the business object in the array that is passed into the map
(source business objects) or returned by the map (destination business
objects).
Map Designer Express displays
this information in the following locations:
- In the Business Objects tab of the Map Properties dialog
Right-click the title bar of the business object window and select
Properties from the Context menu. The Map Properties dialog appear
with the Business Objects tab displaying and the selected business
object highlighted in the list. This tab displays both the instance
name and its index within the business object array (if the business
object is multiple cardinality).
- In the Table tab--in the business
object pane
- In the Diagram tab--in the
title bar of the business
object window in the following format:
The title bar displays the instance name for the business object.
Note:
You can specify whether
Map Designer Express displays
the names of the variables for the source and destination business
objects with the option
Defining Map: show business object instance name. By default, this option is enabled and
Map Designer Express displays
these variable names (
ObjBusObj) in both the Table and Diagram tabs. When the option
is disabled,
Map Designer Express only
displays the names of the source and destination business objects.
You can change the setting of this option on the General tab of
the
Preferences dialog. For more information,
see
Specifying General Preferences.
Steps for modifying business object variables
You can modify these business
object variables from the Business Objects tab of the Map Properties dialog (see Figure 88).
Figure 88. Business Objects Tab of the Map Properties Dialog
To change the business object type of the source or destination
business object in the map in the Map Properties dialog, perform
the following steps:
- Open the map.
- Display the Business Objects tab of the Map Properties dialog
in any of the following ways:
For information on other ways to display the Map Properties dialog,
see Specifying map property information..
- Select the business object type you want to change.
- Click the Change push- button under Business Object Type.
- Select the new type.
- Click OK to close the Select Business Object dialog.
- Click OK to close the Map Properties dialog.
Note:
Invalid transformation rules will be deleted.
Referencing business object attributes
Use the business object variables that Map Designer Express generates
to reference business objects and their attributes, as follows:
- To reference attributes in a source or destination business
object, use the business object name followed by the attribute name,
with a period (.) as a separator:
Example:
ObjBusObjName.AttrName
- To reference attributes in a child
business object, use the child business object name and the child
attribute name.
Example: The following example sets the
value of the OrigHireDate attribute in ObjPsft_Employee to the HireDate attribute of EmployeeHR_Misc, which is a child of ObjEmployee:
ObjPsft_Employee.set("OrigHireDate",
ObjEmployee.getString("EmployeeHR_Misc.HireDate"));
- If the child business object has a cardinality
of n (meaning there can be more than one instance of the child associated
with the parent), you must supply an index number for the child business
object.
Example: The following example sets the
value of the TimeZone attribute of Address, which is a multiple-cardinality child of ObjCustomer:
ObjCustomer.set("Address[0].TimeZone",
ObjSAP_Customer.getString("TimeZone"));
Creating temporary variables
Map Designer Express lets
you create temporary variables that can be accessed in transformation
steps throughout the map; that is; temporary variables are global
to the map. For example, you can calculate a value in one transformation step,
store it in a temporary variable, and reference the variable in
another transformation step. This is especially useful if a certain
calculation is performed repeatedly; you can perform the calculation
once, store the result in a temporary variable, and retrieve the
value as needed (for example, with a Move transformation).
Steps for creating temporary business object variables
Temporary variables are defined within a temporary business
object. Perform the following steps to create a temporary business
object variable:
- Select Add Business Object from the Edit
menu.
Result: The General tab of the Add Business
Object Properties dialog box appears.
For information on other ways to display the Add Business Object
dialog, see Steps for specifying business objects from the Add Business Object
dialog.
- Click the Temporary tab. This is where you define the temporary
variables. Figure 89 shows the
Temporary tab of the Add Business Object dialog. In the Name field
appears the temporary business object's name, which Map Designer Express has
generated. The first generated name is ObjTemporary. This field is read-only.
Figure 89. Temporary tab of the Add Business Object dialog
-
Click in the Attribute field.
Result: A new row appears in the variables
table. Enter the name of the temporary variable.
Note:
Do not create two temporary
variables with the same name.
-
Click the Type field and select the
temporary variable's data type from the pull-down list.
Note:
To be compatible with the InterChange Server Express data
type scheme, all temporary variables have an internal type String.
The data type specified in the Add Business Object dialog will affect
only how the variable is initialized. If you want to write custom
Java code to assign values to the temporary variable, the value
has to be converted to a String first.
- Repeat steps 3 and 4 for each of the temporary variables you
need in the map.
- Click the Add Temporary Business Object button.
- You can either define another temporary business object or click
Done to finish.
Steps for using temporary business object variables in transformation
steps
Use the temporary variable in a transformation step in
this way:
- In the Diagram tab:
- Click the row header (left-most) column of the temporary attribute.
- Copy the variable value to an attribute by holding the Ctrl key and dragging the variable onto the attribute.
- In the Activity Editor Java tab, use the variable name in the
transformation step for an attribute.
Important:
Because a temporary variable is a global variable, you
must explicitly initialize a temporary variable to
null when using the
Map
Instance Reuse option. Otherwise, the value of the temporary variable
from a previous execution of the map instance can incorrectly be
used as the value of the temporary variable in subsequent executions
of the same map. When you do
not use the
Map Instance Reuse option, the
InterChange Server Express system
automatically initializes temporary variables between separate invocations
of the map.
Result: Once Map Designer Express creates
the temporary business object, this business object appears in the
Table and Diagram tabs with the map's other business objects,
as follows:
- In the Table tab:
- The business object pane adds a new area
for the temporary business object. Right-click the name of the temporary
business object to open a Context menu with options to edit and
delete this business object.
- The temporary business object and its attributes appear in the
combo boxes of the Source Attribute and Dest. Attribute columns in the attribute transformation table.
- In the Diagram tab, the map
workspace adds a new business object window for the temporary business
object.
This Temporary business object window has many of the same characteristics
as a business object window. Variables you create appear in the
variables table just like attributes in a business object. This
business object window provides a Rule and Comment column where
you can add the temporary variable's transformation code
and comment, respectively.
You can right-click in the title bar of the Temporary business
object window to get a Context menu that provides options to edit
and delete this business object, as well as its properties. Specify
a value for the variable in one of the following ways:
- To enter code that returns the value of the variable, double-click
in the Rule column, select the appropriate transformation rule,
and click Edit Code to enter the code in Activity Editor.
- To copy a value from a business object attribute to a variable,
hold down the Ctrl key and drag the attribute onto the variable name. You can
also split and join attributes into a variable.
Note:
A temporary business object also appears in the
Business Object tab of the
Map Properties
dialog.
Declaring variables
Tips: Keep the following tips in
mind when declaring variables:
- When creating a variable local to the current attribute (not
visible to all other attributes), declare it at the top of the current
attribute's transformation step (in Activity Editor).
- When creating a variable
global to the current map (visible
to all attributes), declare it in the Map Local Declaration block section of the General tab in the Map
Properties dialog. When writing code to assign values to these variables,
do this at the top of Activity Editor in the first attribute of
the destination object (as specified by the execution order).
